@llamaindex/workflow-debugger 0.1.5 → 0.1.6
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/app.js +1 -1
- package/package.json +3 -3
package/dist/app.js
CHANGED
|
@@ -281,4 +281,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
281
281
|
`)}`,this.#p();const f=new Range;let g=Math.sumPrecise(d.map(m=>m.length));for(const{firstChild:m}of this.editorDiv.childNodes)if(m.nodeType===Node.TEXT_NODE){const v=m.nodeValue.length;if(g<=v){f.setStart(m,g),f.setEnd(m,g);break}g-=v}a.removeAllRanges(),a.addRange(f)}#p(){if(this.editorDiv.replaceChildren(),!!this.#t)for(const e of this.#t.split(`
|
|
282
282
|
`)){const n=document.createElement("div");n.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(n)}}#u(){return this.#t.replaceAll(" "," ")}static#f(e){return e.replaceAll(" "," ")}get contentDiv(){return this.editorDiv}static async deserialize(e,n,r){let i=null;if(e instanceof lF){const{data:{defaultAppearanceData:{fontSize:o,fontColor:l},rect:u,rotation:d,id:p,popupRef:f},textContent:g,textPosition:m,parent:{page:{pageNumber:v}}}=e;if(!g||g.length===0)return null;i=e={annotationType:Le.FREETEXT,color:Array.from(l),fontSize:o,value:g.join(`
|
|
283
283
|
`),position:m,pageIndex:v-1,rect:u.slice(0),rotation:d,id:p,deleted:!1,popupRef:f}}const a=await super.deserialize(e,n,r);return a.#a=e.fontSize,a.#e=Ce.makeHexColor(...e.color),a.#t=Ft.#f(e.value),a.annotationElementId=e.id||null,a._initialData=i,a}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const n=Ft._internalPadding*this.parentScale,r=this.getRect(n,n),i=Ne._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:this.#e),a={annotationType:Le.FREETEXT,color:i,fontSize:this.#a,value:this.#u(),pageIndex:this.pageIndex,rect:r,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?(a.isCopy=!0,a):this.annotationElementId&&!this.#o(a)?null:(a.id=this.annotationElementId,a)}#o(e){const{value:n,fontSize:r,color:i,pageIndex:a}=this._initialData;return this._hasBeenMoved||e.value!==n||e.fontSize!==r||e.color.some((o,l)=>o!==i[l])||e.pageIndex!==a}renderAnnotationElement(e){const n=super.renderAnnotationElement(e);if(this.deleted)return n;const{style:r}=n;r.fontSize=`calc(${this.#a}px * var(--total-scale-factor))`,r.color=this.#e,n.replaceChildren();for(const a of this.#t.split(`
|
|
284
|
-
`)){const o=document.createElement("div");o.append(a?document.createTextNode(a):document.createElement("br")),n.append(o)}const i=Ft._internalPadding*this.parentScale;return e.updateEdited({rect:this.getRect(i,i),popupContent:this.#t}),n}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}}class ye{static PRECISION=1e-4;toSVGPath(){Qe("Abstract method `toSVGPath` must be implemented.")}get box(){Qe("Abstract getter `box` must be implemented.")}serialize(e,n){Qe("Abstract method `serialize` must be implemented.")}static _rescale(e,n,r,i,a,o){o||=new Float32Array(e.length);for(let l=0,u=e.length;l<u;l+=2)o[l]=n+e[l]*i,o[l+1]=r+e[l+1]*a;return o}static _rescaleAndSwap(e,n,r,i,a,o){o||=new Float32Array(e.length);for(let l=0,u=e.length;l<u;l+=2)o[l]=n+e[l+1]*i,o[l+1]=r+e[l]*a;return o}static _translate(e,n,r,i){i||=new Float32Array(e.length);for(let a=0,o=e.length;a<o;a+=2)i[a]=n+e[a],i[a+1]=r+e[a+1];return i}static svgRound(e){return Math.round(e*1e4)}static _normalizePoint(e,n,r,i,a){switch(a){case 90:return[1-n/r,e/i];case 180:return[1-e/r,1-n/i];case 270:return[n/r,1-e/i];default:return[e/r,n/i]}}static _normalizePagePoint(e,n,r){switch(r){case 90:return[1-n,e];case 180:return[1-e,1-n];case 270:return[n,1-e];default:return[e,n]}}static createBezierPoints(e,n,r,i,a,o){return[(e+5*r)/6,(n+5*i)/6,(5*r+a)/6,(5*i+o)/6,(r+a)/2,(i+o)/2]}}class Sa{#e;#t=[];#n;#r;#a=[];#i=new Float32Array(18);#l;#s;#d;#c;#p;#u;#f=[];static#o=8;static#h=2;static#m=Sa.#o+Sa.#h;constructor({x:e,y:n},r,i,a,o,l=0){this.#e=r,this.#u=a*i,this.#r=o,this.#i.set([NaN,NaN,NaN,NaN,e,n],6),this.#n=l,this.#c=Sa.#o*i,this.#d=Sa.#m*i,this.#p=i,this.#f.push(e,n)}isEmpty(){return isNaN(this.#i[8])}#g(){const e=this.#i.subarray(4,6),n=this.#i.subarray(16,18),[r,i,a,o]=this.#e;return[(this.#l+(e[0]-n[0])/2-r)/a,(this.#s+(e[1]-n[1])/2-i)/o,(this.#l+(n[0]-e[0])/2-r)/a,(this.#s+(n[1]-e[1])/2-i)/o]}add({x:e,y:n}){this.#l=e,this.#s=n;const[r,i,a,o]=this.#e;let[l,u,d,p]=this.#i.subarray(8,12);const f=e-d,g=n-p,m=Math.hypot(f,g);if(m<this.#d)return!1;const v=m-this.#c,b=v/m,E=b*f,S=b*g;let _=l,w=u;l=d,u=p,d+=E,p+=S,this.#f?.push(e,n);const A=-S/v,R=E/v,C=A*this.#u,T=R*this.#u;return this.#i.set(this.#i.subarray(2,8),0),this.#i.set([d+C,p+T],4),this.#i.set(this.#i.subarray(14,18),12),this.#i.set([d-C,p-T],16),isNaN(this.#i[6])?(this.#a.length===0&&(this.#i.set([l+C,u+T],2),this.#a.push(NaN,NaN,NaN,NaN,(l+C-r)/a,(u+T-i)/o),this.#i.set([l-C,u-T],14),this.#t.push(NaN,NaN,NaN,NaN,(l-C-r)/a,(u-T-i)/o)),this.#i.set([_,w,l,u,d,p],6),!this.isEmpty()):(this.#i.set([_,w,l,u,d,p],6),Math.abs(Math.atan2(w-u,_-l)-Math.atan2(S,E))<Math.PI/2?([l,u,d,p]=this.#i.subarray(2,6),this.#a.push(NaN,NaN,NaN,NaN,((l+d)/2-r)/a,((u+p)/2-i)/o),[l,u,_,w]=this.#i.subarray(14,18),this.#t.push(NaN,NaN,NaN,NaN,((_+l)/2-r)/a,((w+u)/2-i)/o),!0):([_,w,l,u,d,p]=this.#i.subarray(0,6),this.#a.push(((_+5*l)/6-r)/a,((w+5*u)/6-i)/o,((5*l+d)/6-r)/a,((5*u+p)/6-i)/o,((l+d)/2-r)/a,((u+p)/2-i)/o),[d,p,l,u,_,w]=this.#i.subarray(12,18),this.#t.push(((_+5*l)/6-r)/a,((w+5*u)/6-i)/o,((5*l+d)/6-r)/a,((5*u+p)/6-i)/o,((l+d)/2-r)/a,((u+p)/2-i)/o),!0))}toSVGPath(){if(this.isEmpty())return"";const e=this.#a,n=this.#t;if(isNaN(this.#i[6])&&!this.isEmpty())return this.#b();const r=[];r.push(`M${e[4]} ${e[5]}`);for(let i=6;i<e.length;i+=6)isNaN(e[i])?r.push(`L${e[i+4]} ${e[i+5]}`):r.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);this.#v(r);for(let i=n.length-6;i>=6;i-=6)isNaN(n[i])?r.push(`L${n[i+4]} ${n[i+5]}`):r.push(`C${n[i]} ${n[i+1]} ${n[i+2]} ${n[i+3]} ${n[i+4]} ${n[i+5]}`);return this.#y(r),r.join(" ")}#b(){const[e,n,r,i]=this.#e,[a,o,l,u]=this.#g();return`M${(this.#i[2]-e)/r} ${(this.#i[3]-n)/i} L${(this.#i[4]-e)/r} ${(this.#i[5]-n)/i} L${a} ${o} L${l} ${u} L${(this.#i[16]-e)/r} ${(this.#i[17]-n)/i} L${(this.#i[14]-e)/r} ${(this.#i[15]-n)/i} Z`}#y(e){const n=this.#t;e.push(`L${n[4]} ${n[5]} Z`)}#v(e){const[n,r,i,a]=this.#e,o=this.#i.subarray(4,6),l=this.#i.subarray(16,18),[u,d,p,f]=this.#g();e.push(`L${(o[0]-n)/i} ${(o[1]-r)/a} L${u} ${d} L${p} ${f} L${(l[0]-n)/i} ${(l[1]-r)/a}`)}newFreeDrawOutline(e,n,r,i,a,o){return new fF(e,n,r,i,a,o)}getOutlines(){const e=this.#a,n=this.#t,r=this.#i,[i,a,o,l]=this.#e,u=new Float32Array((this.#f?.length??0)+2);for(let f=0,g=u.length-2;f<g;f+=2)u[f]=(this.#f[f]-i)/o,u[f+1]=(this.#f[f+1]-a)/l;if(u[u.length-2]=(this.#l-i)/o,u[u.length-1]=(this.#s-a)/l,isNaN(r[6])&&!this.isEmpty())return this.#w(u);const d=new Float32Array(this.#a.length+24+this.#t.length);let p=e.length;for(let f=0;f<p;f+=2){if(isNaN(e[f])){d[f]=d[f+1]=NaN;continue}d[f]=e[f],d[f+1]=e[f+1]}p=this.#_(d,p);for(let f=n.length-6;f>=6;f-=6)for(let g=0;g<6;g+=2){if(isNaN(n[f+g])){d[p]=d[p+1]=NaN,p+=2;continue}d[p]=n[f+g],d[p+1]=n[f+g+1],p+=2}return this.#x(d,p),this.newFreeDrawOutline(d,u,this.#e,this.#p,this.#n,this.#r)}#w(e){const n=this.#i,[r,i,a,o]=this.#e,[l,u,d,p]=this.#g(),f=new Float32Array(36);return f.set([NaN,NaN,NaN,NaN,(n[2]-r)/a,(n[3]-i)/o,NaN,NaN,NaN,NaN,(n[4]-r)/a,(n[5]-i)/o,NaN,NaN,NaN,NaN,l,u,NaN,NaN,NaN,NaN,d,p,NaN,NaN,NaN,NaN,(n[16]-r)/a,(n[17]-i)/o,NaN,NaN,NaN,NaN,(n[14]-r)/a,(n[15]-i)/o],0),this.newFreeDrawOutline(f,e,this.#e,this.#p,this.#n,this.#r)}#x(e,n){const r=this.#t;return e.set([NaN,NaN,NaN,NaN,r[4],r[5]],n),n+=6}#_(e,n){const r=this.#i.subarray(4,6),i=this.#i.subarray(16,18),[a,o,l,u]=this.#e,[d,p,f,g]=this.#g();return e.set([NaN,NaN,NaN,NaN,(r[0]-a)/l,(r[1]-o)/u,NaN,NaN,NaN,NaN,d,p,NaN,NaN,NaN,NaN,f,g,NaN,NaN,NaN,NaN,(i[0]-a)/l,(i[1]-o)/u],n),n+=24}}class fF extends ye{#e;#t=new Float32Array(4);#n;#r;#a;#i;#l;constructor(e,n,r,i,a,o){super(),this.#l=e,this.#a=n,this.#e=r,this.#i=i,this.#n=a,this.#r=o,this.lastPoint=[NaN,NaN],this.#s(o);const[l,u,d,p]=this.#t;for(let f=0,g=e.length;f<g;f+=2)e[f]=(e[f]-l)/d,e[f+1]=(e[f+1]-u)/p;for(let f=0,g=n.length;f<g;f+=2)n[f]=(n[f]-l)/d,n[f+1]=(n[f+1]-u)/p}toSVGPath(){const e=[`M${this.#l[4]} ${this.#l[5]}`];for(let n=6,r=this.#l.length;n<r;n+=6){if(isNaN(this.#l[n])){e.push(`L${this.#l[n+4]} ${this.#l[n+5]}`);continue}e.push(`C${this.#l[n]} ${this.#l[n+1]} ${this.#l[n+2]} ${this.#l[n+3]} ${this.#l[n+4]} ${this.#l[n+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,n,r,i],a){const o=r-e,l=i-n;let u,d;switch(a){case 0:u=ye._rescale(this.#l,e,i,o,-l),d=ye._rescale(this.#a,e,i,o,-l);break;case 90:u=ye._rescaleAndSwap(this.#l,e,n,o,l),d=ye._rescaleAndSwap(this.#a,e,n,o,l);break;case 180:u=ye._rescale(this.#l,r,n,-o,l),d=ye._rescale(this.#a,r,n,-o,l);break;case 270:u=ye._rescaleAndSwap(this.#l,r,i,-o,-l),d=ye._rescaleAndSwap(this.#a,r,i,-o,-l);break}return{outline:Array.from(u),points:[Array.from(d)]}}#s(e){const n=this.#l;let r=n[4],i=n[5];const a=[r,i,r,i];let o=r,l=i;const u=e?Math.max:Math.min;for(let p=6,f=n.length;p<f;p+=6){const g=n[p+4],m=n[p+5];if(isNaN(n[p]))Ce.pointBoundingBox(g,m,a),l<m?(o=g,l=m):l===m&&(o=u(o,g));else{const v=[1/0,1/0,-1/0,-1/0];Ce.bezierBoundingBox(r,i,...n.slice(p,p+6),v),Ce.rectBoundingBox(...v,a),l<v[3]?(o=v[2],l=v[3]):l===v[3]&&(o=u(o,v[2]))}r=g,i=m}const d=this.#t;d[0]=a[0]-this.#n,d[1]=a[1]-this.#n,d[2]=a[2]-a[0]+2*this.#n,d[3]=a[3]-a[1]+2*this.#n,this.lastPoint=[o,l]}get box(){return this.#t}newOutliner(e,n,r,i,a,o=0){return new Sa(e,n,r,i,a,o)}getNewOutline(e,n){const[r,i,a,o]=this.#t,[l,u,d,p]=this.#e,f=a*d,g=o*p,m=r*d+l,v=i*p+u,b=this.newOutliner({x:this.#a[0]*f+m,y:this.#a[1]*g+v},this.#e,this.#i,e,this.#r,n??this.#n);for(let E=2;E<this.#a.length;E+=2)b.add({x:this.#a[E]*f+m,y:this.#a[E+1]*g+v});return b.getOutlines()}}class vw{#e;#t;#n=[];#r=[];constructor(e,n=0,r=0,i=!0){const a=[1/0,1/0,-1/0,-1/0],o=10**-4;for(const{x:m,y:v,width:b,height:E}of e){const S=Math.floor((m-n)/o)*o,_=Math.ceil((m+b+n)/o)*o,w=Math.floor((v-n)/o)*o,A=Math.ceil((v+E+n)/o)*o,R=[S,w,A,!0],C=[_,w,A,!1];this.#n.push(R,C),Ce.rectBoundingBox(S,w,_,A,a)}const l=a[2]-a[0]+2*r,u=a[3]-a[1]+2*r,d=a[0]-r,p=a[1]-r,f=this.#n.at(i?-1:-2),g=[f[0],f[2]];for(const m of this.#n){const[v,b,E]=m;m[0]=(v-d)/l,m[1]=(b-p)/u,m[2]=(E-p)/u}this.#e=new Float32Array([d,p,l,u]),this.#t=g}getOutlines(){this.#n.sort((n,r)=>n[0]-r[0]||n[1]-r[1]||n[2]-r[2]);const e=[];for(const n of this.#n)n[3]?(e.push(...this.#d(n)),this.#l(n)):(this.#s(n),e.push(...this.#d(n)));return this.#a(e)}#a(e){const n=[],r=new Set;for(const o of e){const[l,u,d]=o;n.push([l,u,o],[l,d,o])}n.sort((o,l)=>o[1]-l[1]||o[0]-l[0]);for(let o=0,l=n.length;o<l;o+=2){const u=n[o][2],d=n[o+1][2];u.push(d),d.push(u),r.add(u),r.add(d)}const i=[];let a;for(;r.size>0;){const o=r.values().next().value;let[l,u,d,p,f]=o;r.delete(o);let g=l,m=u;for(a=[l,d],i.push(a);;){let v;if(r.has(p))v=p;else if(r.has(f))v=f;else break;r.delete(v),[l,u,d,p,f]=v,g!==l&&(a.push(g,m,l,m===u?u:d),g=l),m=m===u?d:u}a.push(g,m)}return new Qte(i,this.#e,this.#t)}#i(e){const n=this.#r;let r=0,i=n.length-1;for(;r<=i;){const a=r+i>>1,o=n[a][0];if(o===e)return a;o<e?r=a+1:i=a-1}return i+1}#l([,e,n]){const r=this.#i(e);this.#r.splice(r,0,[e,n])}#s([,e,n]){const r=this.#i(e);for(let i=r;i<this.#r.length;i++){const[a,o]=this.#r[i];if(a!==e)break;if(a===e&&o===n){this.#r.splice(i,1);return}}for(let i=r-1;i>=0;i--){const[a,o]=this.#r[i];if(a!==e)break;if(a===e&&o===n){this.#r.splice(i,1);return}}}#d(e){const[n,r,i]=e,a=[[n,r,i]],o=this.#i(i);for(let l=0;l<o;l++){const[u,d]=this.#r[l];for(let p=0,f=a.length;p<f;p++){const[,g,m]=a[p];if(!(d<=g||m<=u)){if(g>=u){if(m>d)a[p][1]=d;else{if(f===1)return[];a.splice(p,1),p--,f--}continue}a[p][2]=u,m>d&&a.push([n,d,m])}}}return a}}class Qte extends ye{#e;#t;constructor(e,n,r){super(),this.#t=e,this.#e=n,this.lastPoint=r}toSVGPath(){const e=[];for(const n of this.#t){let[r,i]=n;e.push(`M${r} ${i}`);for(let a=2;a<n.length;a+=2){const o=n[a],l=n[a+1];o===r?(e.push(`V${l}`),i=l):l===i&&(e.push(`H${o}`),r=o)}e.push("Z")}return e.join(" ")}serialize([e,n,r,i],a){const o=[],l=r-e,u=i-n;for(const d of this.#t){const p=new Array(d.length);for(let f=0;f<d.length;f+=2)p[f]=e+d[f]*l,p[f+1]=i-d[f+1]*u;o.push(p)}return o}get box(){return this.#e}get classNamesForOutlining(){return["highlightOutline"]}}class Ew extends Sa{newFreeDrawOutline(e,n,r,i,a,o){return new Jte(e,n,r,i,a,o)}}class Jte extends fF{newOutliner(e,n,r,i,a,o=0){return new Ew(e,n,r,i,a,o)}}class Nn{#e=null;#t=null;#n;#r=null;#a=!1;#i=!1;#l=null;#s;#d=null;#c=null;#p;static#u=null;static get _keyboardManager(){return $e(this,"_keyboardManager",new Zl([[["Escape","mac+Escape"],Nn.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],Nn.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],Nn.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],Nn.prototype._moveToPrevious],[["Home","mac+Home"],Nn.prototype._moveToBeginning],[["End","mac+End"],Nn.prototype._moveToEnd]]))}constructor({editor:e=null,uiManager:n=null}){e?(this.#i=!1,this.#p=ze.HIGHLIGHT_COLOR,this.#l=e):(this.#i=!0,this.#p=ze.HIGHLIGHT_DEFAULT_COLOR),this.#c=e?._uiManager||n,this.#s=this.#c._eventBus,this.#n=e?.color||this.#c?.highlightColors.values().next().value||"#FFFF98",Nn.#u||=Object.freeze({blue:"pdfjs-editor-colorpicker-blue",green:"pdfjs-editor-colorpicker-green",pink:"pdfjs-editor-colorpicker-pink",red:"pdfjs-editor-colorpicker-red",yellow:"pdfjs-editor-colorpicker-yellow"})}renderButton(){const e=this.#e=document.createElement("button");e.className="colorPicker",e.tabIndex="0",e.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),e.setAttribute("aria-haspopup",!0);const n=this.#c._signal;e.addEventListener("click",this.#m.bind(this),{signal:n}),e.addEventListener("keydown",this.#h.bind(this),{signal:n});const r=this.#t=document.createElement("span");return r.className="swatch",r.setAttribute("aria-hidden",!0),r.style.backgroundColor=this.#n,e.append(r),e}renderMainDropdown(){const e=this.#r=this.#f();return e.setAttribute("aria-orientation","horizontal"),e.setAttribute("aria-labelledby","highlightColorPickerLabel"),e}#f(){const e=document.createElement("div"),n=this.#c._signal;e.addEventListener("contextmenu",Xn,{signal:n}),e.className="dropdown",e.role="listbox",e.setAttribute("aria-multiselectable",!1),e.setAttribute("aria-orientation","vertical"),e.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[r,i]of this.#c.highlightColors){const a=document.createElement("button");a.tabIndex="0",a.role="option",a.setAttribute("data-color",i),a.title=r,a.setAttribute("data-l10n-id",Nn.#u[r]);const o=document.createElement("span");a.append(o),o.className="swatch",o.style.backgroundColor=i,a.setAttribute("aria-selected",i===this.#n),a.addEventListener("click",this.#o.bind(this,i),{signal:n}),e.append(a)}return e.addEventListener("keydown",this.#h.bind(this),{signal:n}),e}#o(e,n){n.stopPropagation(),this.#s.dispatch("switchannotationeditorparams",{source:this,type:this.#p,value:e})}_colorSelectFromKeyboard(e){if(e.target===this.#e){this.#m(e);return}const n=e.target.getAttribute("data-color");n&&this.#o(n,e)}_moveToNext(e){if(!this.#b){this.#m(e);return}if(e.target===this.#e){this.#r.firstChild?.focus();return}e.target.nextSibling?.focus()}_moveToPrevious(e){if(e.target===this.#r?.firstChild||e.target===this.#e){this.#b&&this._hideDropdownFromKeyboard();return}this.#b||this.#m(e),e.target.previousSibling?.focus()}_moveToBeginning(e){if(!this.#b){this.#m(e);return}this.#r.firstChild?.focus()}_moveToEnd(e){if(!this.#b){this.#m(e);return}this.#r.lastChild?.focus()}#h(e){Nn._keyboardManager.exec(this,e)}#m(e){if(this.#b){this.hideDropdown();return}if(this.#a=e.detail===0,this.#d||(this.#d=new AbortController,window.addEventListener("pointerdown",this.#g.bind(this),{signal:this.#c.combinedSignal(this.#d)})),this.#r){this.#r.classList.remove("hidden");return}const n=this.#r=this.#f();this.#e.append(n)}#g(e){this.#r?.contains(e.target)||this.hideDropdown()}hideDropdown(){this.#r?.classList.add("hidden"),this.#d?.abort(),this.#d=null}get#b(){return this.#r&&!this.#r.classList.contains("hidden")}_hideDropdownFromKeyboard(){if(!this.#i){if(!this.#b){this.#l?.unselect();return}this.hideDropdown(),this.#e.focus({preventScroll:!0,focusVisible:this.#a})}}updateColor(e){if(this.#t&&(this.#t.style.backgroundColor=e),!this.#r)return;const n=this.#c.highlightColors.values();for(const r of this.#r.children)r.setAttribute("aria-selected",n.next().value===e)}destroy(){this.#e?.remove(),this.#e=null,this.#t=null,this.#r?.remove(),this.#r=null}}class At extends Ne{#e=null;#t=0;#n;#r=null;#a=null;#i=null;#l=null;#s=0;#d=null;#c=null;#p=null;#u=!1;#f=null;#o;#h=null;#m="";#g;#b="";static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type="highlight";static _editorType=Le.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId="";static get _keyboardManager(){const e=At.prototype;return $e(this,"_keyboardManager",new Zl([[["ArrowLeft","mac+ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],e._moveCaret,{args:[3]}]]))}constructor(e){super({...e,name:"highlightEditor"}),this.color=e.color||At._defaultColor,this.#g=e.thickness||At._defaultThickness,this.#o=e.opacity||At._defaultOpacity,this.#n=e.boxes||null,this.#b=e.methodOfCreation||"",this.#m=e.text||"",this._isDraggable=!1,this.defaultL10nId="pdfjs-editor-highlight-editor",e.highlightId>-1?(this.#u=!0,this.#v(e),this.#k()):this.#n&&(this.#e=e.anchorNode,this.#t=e.anchorOffset,this.#l=e.focusNode,this.#s=e.focusOffset,this.#y(),this.#k(),this.rotate(this.rotation))}get telemetryInitialData(){return{action:"added",type:this.#u?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:this.#g,methodOfCreation:this.#b}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get("color").size}}#y(){const e=new vw(this.#n,.001);this.#c=e.getOutlines(),[this.x,this.y,this.width,this.height]=this.#c.box;const n=new vw(this.#n,.0025,.001,this._uiManager.direction==="ltr");this.#i=n.getOutlines();const{lastPoint:r}=this.#i;this.#f=[(r[0]-this.x)/this.width,(r[1]-this.y)/this.height]}#v({highlightOutlines:e,highlightId:n,clipPathId:r}){this.#c=e;const i=1.5;if(this.#i=e.getNewOutline(this.#g/2+i,.0025),n>=0)this.#p=n,this.#r=r,this.parent.drawLayer.finalizeDraw(n,{bbox:e.box,path:{d:e.toSVGPath()}}),this.#h=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#i.box,path:{d:this.#i.toSVGPath()}},!0);else if(this.parent){const p=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#p,{bbox:At.#S(this.#c.box,(p-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(this.#h,{bbox:At.#S(this.#i.box,p),path:{d:this.#i.toSVGPath()}})}const[a,o,l,u]=e.box;switch(this.rotation){case 0:this.x=a,this.y=o,this.width=l,this.height=u;break;case 90:{const[p,f]=this.parentDimensions;this.x=o,this.y=1-a,this.width=l*f/p,this.height=u*p/f;break}case 180:this.x=1-a,this.y=1-o,this.width=l,this.height=u;break;case 270:{const[p,f]=this.parentDimensions;this.x=1-o,this.y=a,this.width=l*f/p,this.height=u*p/f;break}}const{lastPoint:d}=this.#i;this.#f=[(d[0]-a)/l,(d[1]-o)/u]}static initialize(e,n){Ne.initialize(e,n),At._defaultColor||=n.highlightColors?.values().next().value||"#fff066"}static updateDefaultParams(e,n){switch(e){case ze.HIGHLIGHT_DEFAULT_COLOR:At._defaultColor=n;break;case ze.HIGHLIGHT_THICKNESS:At._defaultThickness=n;break}}translateInPage(e,n){}get toolbarPosition(){return this.#f}updateParams(e,n){switch(e){case ze.HIGHLIGHT_COLOR:this.#w(n);break;case ze.HIGHLIGHT_THICKNESS:this.#x(n);break}}static get defaultPropertiesToUpdate(){return[[ze.HIGHLIGHT_DEFAULT_COLOR,At._defaultColor],[ze.HIGHLIGHT_THICKNESS,At._defaultThickness]]}get propertiesToUpdate(){return[[ze.HIGHLIGHT_COLOR,this.color||At._defaultColor],[ze.HIGHLIGHT_THICKNESS,this.#g||At._defaultThickness],[ze.HIGHLIGHT_FREE,this.#u]]}#w(e){const n=(a,o)=>{this.color=a,this.#o=o,this.parent?.drawLayer.updateProperties(this.#p,{root:{fill:a,"fill-opacity":o}}),this.#a?.updateColor(a)},r=this.color,i=this.#o;this.addCommands({cmd:n.bind(this,e,At._defaultOpacity),undo:n.bind(this,r,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ze.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)}#x(e){const n=this.#g,r=i=>{this.#g=i,this.#_(i)};this.addCommands({cmd:r.bind(this,e),undo:r.bind(this,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ze.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(this.#a=new Nn({editor:this}),e.addColorPicker(this.#a)),e):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(this.#I())}getBaseTranslation(){return[0,0]}getRect(e,n){return super.getRect(e,n,this.#I())}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){this.#C(),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#k(),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){let n=!1;this.parent&&!e?this.#C():e&&(this.#k(e),n=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(e),this.show(this._isVisible),n&&this.select()}#_(e){if(!this.#u)return;this.#v({highlightOutlines:this.#c.getNewOutline(e/2)}),this.fixAndSetPosition();const[n,r]=this.parentDimensions;this.setDims(this.width*n,this.height*r)}#C(){this.#p===null||!this.parent||(this.parent.drawLayer.remove(this.#p),this.#p=null,this.parent.drawLayer.remove(this.#h),this.#h=null)}#k(e=this.parent){this.#p===null&&({id:this.#p,clipPathId:this.#r}=e.drawLayer.draw({bbox:this.#c.box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":this.#o},rootClass:{highlight:!0,free:this.#u},path:{d:this.#c.toSVGPath()}},!1,!0),this.#h=e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#u},bbox:this.#i.box,path:{d:this.#i.toSVGPath()}},this.#u),this.#d&&(this.#d.style.clipPath=this.#r))}static#S([e,n,r,i],a){switch(a){case 90:return[1-n-i,e,i,r];case 180:return[1-e-r,1-n-i,r,i];case 270:return[n,1-e-r,i,r]}return[e,n,r,i]}rotate(e){const{drawLayer:n}=this.parent;let r;this.#u?(e=(e-this.rotation+360)%360,r=At.#S(this.#c.box,e)):r=At.#S([this.x,this.y,this.width,this.height],e),n.updateProperties(this.#p,{bbox:r,root:{"data-main-rotation":e}}),n.updateProperties(this.#h,{bbox:At.#S(this.#i.box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();this.#m&&(e.setAttribute("aria-label",this.#m),e.setAttribute("role","mark")),this.#u?e.classList.add("free"):this.div.addEventListener("keydown",this.#R.bind(this),{signal:this._uiManager._signal});const n=this.#d=document.createElement("div");e.append(n),n.setAttribute("aria-hidden","true"),n.className="internal",n.style.clipPath=this.#r;const[r,i]=this.parentDimensions;return this.setDims(this.width*r,this.height*i),zP(this,this.#d,["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#h,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#h,{rootClass:{hovered:!1}})}#R(e){At._keyboardManager.exec(this,e)}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:this.#T(!0);break;case 1:case 3:this.#T(!1);break}}#T(e){if(!this.#e)return;const n=window.getSelection();e?n.setPosition(this.#e,this.#t):n.setPosition(this.#l,this.#s)}select(){super.select(),this.#h&&this.parent?.drawLayer.updateProperties(this.#h,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect(),this.#h&&(this.parent?.drawLayer.updateProperties(this.#h,{rootClass:{selected:!1}}),this.#u||this.#T(!1))}get _mustFixPosition(){return!this.#u}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(this.#p,{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(this.#h,{rootClass:{hidden:!e}}))}#I(){return this.#u?this.rotation:0}#O(){if(this.#u)return null;const[e,n]=this.pageDimensions,[r,i]=this.pageTranslation,a=this.#n,o=new Float32Array(a.length*8);let l=0;for(const{x:u,y:d,width:p,height:f}of a){const g=u*e+r,m=(1-d)*n+i;o[l]=o[l+4]=g,o[l+1]=o[l+3]=m,o[l+2]=o[l+6]=g+p*e,o[l+5]=o[l+7]=m-f*n,l+=8}return o}#L(e){return this.#c.serialize(e,this.#I())}static startHighlighting(e,n,{target:r,x:i,y:a}){const{x:o,y:l,width:u,height:d}=r.getBoundingClientRect(),p=new AbortController,f=e.combinedSignal(p),g=m=>{p.abort(),this.#A(e,m)};window.addEventListener("blur",g,{signal:f}),window.addEventListener("pointerup",g,{signal:f}),window.addEventListener("pointerdown",_t,{capture:!0,passive:!1,signal:f}),window.addEventListener("contextmenu",Xn,{signal:f}),r.addEventListener("pointermove",this.#$.bind(this,e),{signal:f}),this._freeHighlight=new Ew({x:i,y:a},[o,l,u,d],e.scale,this._defaultThickness/2,n,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static#$(e,n){this._freeHighlight.add(n)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#A(e,n){this._freeHighlight.isEmpty()?e.drawLayer.remove(this._freeHighlightId):e.createAndAddNewEditor(n,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""}static async deserialize(e,n,r){let i=null;if(e instanceof uF){const{data:{quadPoints:v,rect:b,rotation:E,id:S,color:_,opacity:w,popupRef:A},parent:{page:{pageNumber:R}}}=e;i=e={annotationType:Le.HIGHLIGHT,color:Array.from(_),opacity:w,quadPoints:v,boxes:null,pageIndex:R-1,rect:b.slice(0),rotation:E,id:S,deleted:!1,popupRef:A}}else if(e instanceof FS){const{data:{inkLists:v,rect:b,rotation:E,id:S,color:_,borderStyle:{rawWidth:w},popupRef:A},parent:{page:{pageNumber:R}}}=e;i=e={annotationType:Le.HIGHLIGHT,color:Array.from(_),thickness:w,inkLists:v,boxes:null,pageIndex:R-1,rect:b.slice(0),rotation:E,id:S,deleted:!1,popupRef:A}}const{color:a,quadPoints:o,inkLists:l,opacity:u}=e,d=await super.deserialize(e,n,r);d.color=Ce.makeHexColor(...a),d.#o=u||1,l&&(d.#g=e.thickness),d.annotationElementId=e.id||null,d._initialData=i;const[p,f]=d.pageDimensions,[g,m]=d.pageTranslation;if(o){const v=d.#n=[];for(let b=0;b<o.length;b+=8)v.push({x:(o[b]-g)/p,y:1-(o[b+1]-m)/f,width:(o[b+2]-o[b])/p,height:(o[b+1]-o[b+5])/f});d.#y(),d.#k(),d.rotate(d.rotation)}else if(l){d.#u=!0;const v=l[0],b={x:v[0]-g,y:f-(v[1]-m)},E=new Ew(b,[0,0,p,f],1,d.#g/2,!0,.001);for(let w=0,A=v.length;w<A;w+=2)b.x=v[w]-g,b.y=f-(v[w+1]-m),E.add(b);const{id:S,clipPathId:_}=n.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:d.color,"fill-opacity":d._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:E.toSVGPath()}},!0,!0);d.#v({highlightOutlines:E.getOutlines(),highlightId:S,clipPathId:_}),d.#k(),d.rotate(d.parentRotation)}return d}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();const n=this.getRect(0,0),r=Ne._colorManager.convert(this.color),i={annotationType:Le.HIGHLIGHT,color:r,opacity:this.#o,thickness:this.#g,quadPoints:this.#O(),outlines:this.#L(n),pageIndex:this.pageIndex,rect:n,rotation:this.#I(),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!this.#E(i)?null:(i.id=this.annotationElementId,i)}#E(e){const{color:n}=this._initialData;return e.color.some((r,i)=>r!==n[i])}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}}class hF{#e=Object.create(null);updateProperty(e,n){this[e]=n,this.updateSVGProperty(e,n)}updateProperties(e){if(e)for(const[n,r]of Object.entries(e))n.startsWith("_")||this.updateProperty(n,r)}updateSVGProperty(e,n){this.#e[e]=n}toSVGProperties(){const e=this.#e;return this.#e=Object.create(null),{root:e}}reset(){this.#e=Object.create(null)}updateAll(e=this){this.updateProperties(e)}clone(){Qe("Not implemented")}}class Ie extends Ne{#e=null;#t;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#n=null;static#r=null;static#a=null;static#i=NaN;static#l=null;static#s=null;static#d=NaN;static _INNER_MARGIN=3;constructor(e){super(e),this.#t=e.mustBeCommitted||!1,this._addOutlines(e)}_addOutlines(e){e.drawOutlines&&(this.#c(e),this.#f())}#c({drawOutlines:e,drawId:n,drawingOptions:r}){this.#e=e,this._drawingOptions||=r,n>=0?(this._drawId=n,this.parent.drawLayer.finalizeDraw(n,e.defaultProperties)):this._drawId=this.#p(e,this.parent),this.#m(e.box)}#p(e,n){const{id:r}=n.drawLayer.draw(Ie._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return r}static _mergeSVGProperties(e,n){const r=new Set(Object.keys(e));for(const[i,a]of Object.entries(n))r.has(i)?Object.assign(e[i],a):e[i]=a;return e}static getDefaultDrawingOptions(e){Qe("Not implemented")}static get typesMap(){Qe("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,n){const r=this.typesMap.get(e);r&&this._defaultDrawingOptions.updateProperty(r,n),this._currentParent&&(Ie.#n.updateProperty(r,n),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,n){const r=this.constructor.typesMap.get(e);r&&this._updateProperty(e,r,n)}static get defaultPropertiesToUpdate(){const e=[],n=this._defaultDrawingOptions;for(const[r,i]of this.typesMap)e.push([r,n[i]]);return e}get propertiesToUpdate(){const e=[],{_drawingOptions:n}=this;for(const[r,i]of this.constructor.typesMap)e.push([r,n[i]]);return e}_updateProperty(e,n,r){const i=this._drawingOptions,a=i[n],o=l=>{i.updateProperty(n,l);const u=this.#e.updateProperty(n,l);u&&this.#m(u),this.parent?.drawLayer.updateProperties(this._drawId,i.toSVGProperties())};this.addCommands({cmd:o.bind(this,r),undo:o.bind(this,a),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,Ie._mergeSVGProperties(this.#e.getPathResizingSVGProperties(this.#h()),{bbox:this.#g()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,Ie._mergeSVGProperties(this.#e.getPathResizedSVGProperties(this.#h()),{bbox:this.#g()}))}_onTranslating(e,n){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#g()})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,Ie._mergeSVGProperties(this.#e.getPathTranslatedSVGProperties(this.#h(),this.parentDimensions),{bbox:this.#g()}))}_onStartDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit(),this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,this.#t&&(this.#t=!1,this.commit(),this.parent.setSelected(this),e&&this.isOnScreen&&this.div.focus())}remove(){this.#u(),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#f(),this.#m(this.#e.box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){let n=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),this.#u()):e&&(this._uiManager.addShouldRescale(this),this.#f(e),n=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(e),n&&this.select()}#u(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())}#f(e=this.parent){if(!(this._drawId!==null&&this.parent===e)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,e.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=this.#p(this.#e,e)}}#o([e,n,r,i]){const{parentDimensions:[a,o],rotation:l}=this;switch(l){case 90:return[n,1-e,r*(o/a),i*(a/o)];case 180:return[1-e,1-n,r,i];case 270:return[1-n,e,r*(o/a),i*(a/o)];default:return[e,n,r,i]}}#h(){const{x:e,y:n,width:r,height:i,parentDimensions:[a,o],rotation:l}=this;switch(l){case 90:return[1-n,e,r*(a/o),i*(o/a)];case 180:return[1-e,1-n,r,i];case 270:return[n,1-e,r*(a/o),i*(o/a)];default:return[e,n,r,i]}}#m(e){if([this.x,this.y,this.width,this.height]=this.#o(e),this.div){this.fixAndSetPosition();const[n,r]=this.parentDimensions;this.setDims(this.width*n,this.height*r)}this._onResized()}#g(){const{x:e,y:n,width:r,height:i,rotation:a,parentRotation:o,parentDimensions:[l,u]}=this;switch((a*4+o)/90){case 1:return[1-n-i,e,i,r];case 2:return[1-e-r,1-n-i,r,i];case 3:return[n,1-e-r,i,r];case 4:return[e,n-r*(l/u),i*(u/l),r*(l/u)];case 5:return[1-n,e,r*(l/u),i*(u/l)];case 6:return[1-e-i*(u/l),1-n,i*(u/l),r*(l/u)];case 7:return[n-r*(l/u),1-e-i*(u/l),r*(l/u),i*(u/l)];case 8:return[e-r,n-i,r,i];case 9:return[1-n,e-r,i,r];case 10:return[1-e,1-n,r,i];case 11:return[n-i,1-e,i,r];case 12:return[e-i*(u/l),n,i*(u/l),r*(l/u)];case 13:return[1-n-r*(l/u),e-i*(u/l),r*(l/u),i*(u/l)];case 14:return[1-e,1-n-r*(l/u),i*(u/l),r*(l/u)];case 15:return[n,1-e,r*(l/u),i*(u/l)];default:return[e,n,r,i]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,Ie._mergeSVGProperties({bbox:this.#g()},this.#e.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#m(this.#e.updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;let e,n;this._isCopy&&(e=this.x,n=this.y);const r=super.render();r.classList.add("draw");const i=document.createElement("div");r.append(i),i.setAttribute("aria-hidden","true"),i.className="internal";const[a,o]=this.parentDimensions;return this.setDims(this.width*a,this.height*o),this._uiManager.addShouldRescale(this),this.disableEditing(),this._isCopy&&this._moveAfterPaste(e,n),r}static createDrawerInstance(e,n,r,i,a){Qe("Not implemented")}static startDrawing(e,n,r,i){const{target:a,offsetX:o,offsetY:l,pointerId:u,pointerType:d}=i;if(Ie.#l&&Ie.#l!==d)return;const{viewport:{rotation:p}}=e,{width:f,height:g}=a.getBoundingClientRect(),m=Ie.#r=new AbortController,v=e.combinedSignal(m);if(Ie.#i||=u,Ie.#l??=d,window.addEventListener("pointerup",b=>{Ie.#i===b.pointerId?this._endDraw(b):Ie.#s?.delete(b.pointerId)},{signal:v}),window.addEventListener("pointercancel",b=>{Ie.#i===b.pointerId?this._currentParent.endDrawingSession():Ie.#s?.delete(b.pointerId)},{signal:v}),window.addEventListener("pointerdown",b=>{Ie.#l===b.pointerType&&((Ie.#s||=new Set).add(b.pointerId),Ie.#n.isCancellable()&&(Ie.#n.removeLastElement(),Ie.#n.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:v}),window.addEventListener("contextmenu",Xn,{signal:v}),a.addEventListener("pointermove",this._drawMove.bind(this),{signal:v}),a.addEventListener("touchmove",b=>{b.timeStamp===Ie.#d&&_t(b)},{signal:v}),e.toggleDrawing(),n._editorUndoBar?.hide(),Ie.#n){e.drawLayer.updateProperties(this._currentDrawId,Ie.#n.startNew(o,l,f,g,p));return}n.updateUIForDefaultProperties(this),Ie.#n=this.createDrawerInstance(o,l,f,g,p),Ie.#a=this.getDefaultDrawingOptions(),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(Ie.#a.toSVGProperties(),Ie.#n.defaultSVGProperties),!0,!1)}static _drawMove(e){if(Ie.#d=-1,!Ie.#n)return;const{offsetX:n,offsetY:r,pointerId:i}=e;if(Ie.#i===i){if(Ie.#s?.size>=1){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,Ie.#n.add(n,r)),Ie.#d=e.timeStamp,_t(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,Ie.#n=null,Ie.#a=null,Ie.#l=null,Ie.#d=NaN),Ie.#r&&(Ie.#r.abort(),Ie.#r=null,Ie.#i=NaN,Ie.#s=null)}static _endDraw(e){const n=this._currentParent;if(n){if(n.toggleDrawing(!0),this._cleanup(!1),e?.target===n.div&&n.drawLayer.updateProperties(this._currentDrawId,Ie.#n.end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const r=Ie.#n,i=this._currentDrawId,a=r.getLastElement();n.addCommands({cmd:()=>{n.drawLayer.updateProperties(i,r.setLastElement(a))},undo:()=>{n.drawLayer.updateProperties(i,r.removeLastElement())},mustExec:!1,type:ze.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const n=this._currentParent;if(!n)return null;if(n.toggleDrawing(!0),n.cleanUndoStack(ze.DRAW_STEP),!Ie.#n.isEmpty()){const{pageDimensions:[r,i],scale:a}=n,o=n.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:Ie.#n.getOutlines(r*a,i*a,a,this._INNER_MARGIN),drawingOptions:Ie.#a,mustBeCommitted:!e});return this._cleanup(!0),o}return n.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(e){}static deserializeDraw(e,n,r,i,a,o){Qe("Not implemented")}static async deserialize(e,n,r){const{rawDims:{pageWidth:i,pageHeight:a,pageX:o,pageY:l}}=n.viewport,u=this.deserializeDraw(o,l,i,a,this._INNER_MARGIN,e),d=await super.deserialize(e,n,r);return d.createDrawingOptions(e),d.#c({drawOutlines:u}),d.#f(),d.onScaleChanging(),d.rotate(),d}serializeDraw(e){const[n,r]=this.pageTranslation,[i,a]=this.pageDimensions;return this.#e.serialize([n,r,i,a],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}}class ene{#e=new Float64Array(6);#t;#n;#r;#a;#i;#l="";#s=0;#d=new tc;#c;#p;constructor(e,n,r,i,a,o){this.#c=r,this.#p=i,this.#r=a,this.#a=o,[e,n]=this.#u(e,n);const l=this.#t=[NaN,NaN,NaN,NaN,e,n];this.#i=[e,n],this.#n=[{line:l,points:this.#i}],this.#e.set(l,0)}updateProperty(e,n){e==="stroke-width"&&(this.#a=n)}#u(e,n){return ye._normalizePoint(e,n,this.#c,this.#p,this.#r)}isEmpty(){return!this.#n||this.#n.length===0}isCancellable(){return this.#i.length<=10}add(e,n){[e,n]=this.#u(e,n);const[r,i,a,o]=this.#e.subarray(2,6),l=e-a,u=n-o;return Math.hypot(this.#c*l,this.#p*u)<=2?null:(this.#i.push(e,n),isNaN(r)?(this.#e.set([a,o,e,n],2),this.#t.push(NaN,NaN,NaN,NaN,e,n),{path:{d:this.toSVGPath()}}):(isNaN(this.#e[0])&&this.#t.splice(6,6),this.#e.set([r,i,a,o,e,n],0),this.#t.push(...ye.createBezierPoints(r,i,a,o,e,n)),{path:{d:this.toSVGPath()}}))}end(e,n){const r=this.add(e,n);return r||(this.#i.length===2?{path:{d:this.toSVGPath()}}:null)}startNew(e,n,r,i,a){this.#c=r,this.#p=i,this.#r=a,[e,n]=this.#u(e,n);const o=this.#t=[NaN,NaN,NaN,NaN,e,n];this.#i=[e,n];const l=this.#n.at(-1);return l&&(l.line=new Float32Array(l.line),l.points=new Float32Array(l.points)),this.#n.push({line:o,points:this.#i}),this.#e.set(o,0),this.#s=0,this.toSVGPath(),null}getLastElement(){return this.#n.at(-1)}setLastElement(e){return this.#n?(this.#n.push(e),this.#t=e.line,this.#i=e.points,this.#s=0,{path:{d:this.toSVGPath()}}):this.#d.setLastElement(e)}removeLastElement(){if(!this.#n)return this.#d.removeLastElement();this.#n.pop(),this.#l="";for(let e=0,n=this.#n.length;e<n;e++){const{line:r,points:i}=this.#n[e];this.#t=r,this.#i=i,this.#s=0,this.toSVGPath()}return{path:{d:this.#l}}}toSVGPath(){const e=ye.svgRound(this.#t[4]),n=ye.svgRound(this.#t[5]);if(this.#i.length===2)return this.#l=`${this.#l} M ${e} ${n} Z`,this.#l;if(this.#i.length<=6){const i=this.#l.lastIndexOf("M");this.#l=`${this.#l.slice(0,i)} M ${e} ${n}`,this.#s=6}if(this.#i.length===4){const i=ye.svgRound(this.#t[10]),a=ye.svgRound(this.#t[11]);return this.#l=`${this.#l} L ${i} ${a}`,this.#s=12,this.#l}const r=[];this.#s===0&&(r.push(`M ${e} ${n}`),this.#s=6);for(let i=this.#s,a=this.#t.length;i<a;i+=6){const[o,l,u,d,p,f]=this.#t.slice(i,i+6).map(ye.svgRound);r.push(`C${o} ${l} ${u} ${d} ${p} ${f}`)}return this.#l+=r.join(" "),this.#s=this.#t.length,this.#l}getOutlines(e,n,r,i){const a=this.#n.at(-1);return a.line=new Float32Array(a.line),a.points=new Float32Array(a.points),this.#d.build(this.#n,e,n,r,this.#r,this.#a,i),this.#e=null,this.#t=null,this.#n=null,this.#l=null,this.#d}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}class tc extends ye{#e;#t=0;#n;#r;#a;#i;#l;#s;#d;build(e,n,r,i,a,o,l){this.#a=n,this.#i=r,this.#l=i,this.#s=a,this.#d=o,this.#n=l??0,this.#r=e,this.#u()}get thickness(){return this.#d}setLastElement(e){return this.#r.push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return this.#r.pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:n}of this.#r){if(e.push(`M${ye.svgRound(n[4])} ${ye.svgRound(n[5])}`),n.length===6){e.push("Z");continue}if(n.length===12&&isNaN(n[6])){e.push(`L${ye.svgRound(n[10])} ${ye.svgRound(n[11])}`);continue}for(let r=6,i=n.length;r<i;r+=6){const[a,o,l,u,d,p]=n.subarray(r,r+6).map(ye.svgRound);e.push(`C${a} ${o} ${l} ${u} ${d} ${p}`)}}return e.join("")}serialize([e,n,r,i],a){const o=[],l=[],[u,d,p,f]=this.#p();let g,m,v,b,E,S,_,w,A;switch(this.#s){case 0:A=ye._rescale,g=e,m=n+i,v=r,b=-i,E=e+u*r,S=n+(1-d-f)*i,_=e+(u+p)*r,w=n+(1-d)*i;break;case 90:A=ye._rescaleAndSwap,g=e,m=n,v=r,b=i,E=e+d*r,S=n+u*i,_=e+(d+f)*r,w=n+(u+p)*i;break;case 180:A=ye._rescale,g=e+r,m=n,v=-r,b=i,E=e+(1-u-p)*r,S=n+d*i,_=e+(1-u)*r,w=n+(d+f)*i;break;case 270:A=ye._rescaleAndSwap,g=e+r,m=n+i,v=-r,b=-i,E=e+(1-d-f)*r,S=n+(1-u-p)*i,_=e+(1-d)*r,w=n+(1-u)*i;break}for(const{line:R,points:C}of this.#r)o.push(A(R,g,m,v,b,a?new Array(R.length):null)),l.push(A(C,g,m,v,b,a?new Array(C.length):null));return{lines:o,points:l,rect:[E,S,_,w]}}static deserialize(e,n,r,i,a,{paths:{lines:o,points:l},rotation:u,thickness:d}){const p=[];let f,g,m,v,b;switch(u){case 0:b=ye._rescale,f=-e/r,g=n/i+1,m=1/r,v=-1/i;break;case 90:b=ye._rescaleAndSwap,f=-n/i,g=-e/r,m=1/i,v=1/r;break;case 180:b=ye._rescale,f=e/r+1,g=-n/i,m=-1/r,v=1/i;break;case 270:b=ye._rescaleAndSwap,f=n/i+1,g=e/r+1,m=-1/i,v=-1/r;break}if(!o){o=[];for(const S of l){const _=S.length;if(_===2){o.push(new Float32Array([NaN,NaN,NaN,NaN,S[0],S[1]]));continue}if(_===4){o.push(new Float32Array([NaN,NaN,NaN,NaN,S[0],S[1],NaN,NaN,NaN,NaN,S[2],S[3]]));continue}const w=new Float32Array(3*(_-2));o.push(w);let[A,R,C,T]=S.subarray(0,4);w.set([NaN,NaN,NaN,NaN,A,R],0);for(let O=4;O<_;O+=2){const L=S[O],z=S[O+1];w.set(ye.createBezierPoints(A,R,C,T,L,z),(O-2)*3),[A,R,C,T]=[C,T,L,z]}}}for(let S=0,_=o.length;S<_;S++)p.push({line:b(o[S].map(w=>w??NaN),f,g,m,v),points:b(l[S].map(w=>w??NaN),f,g,m,v)});const E=new this.prototype.constructor;return E.build(p,r,i,1,u,d,a),E}#c(e=this.#d){const n=this.#n+e/2*this.#l;return this.#s%180===0?[n/this.#a,n/this.#i]:[n/this.#i,n/this.#a]}#p(){const[e,n,r,i]=this.#e,[a,o]=this.#c(0);return[e+a,n+o,r-2*a,i-2*o]}#u(){const e=this.#e=new Float32Array([1/0,1/0,-1/0,-1/0]);for(const{line:i}of this.#r){if(i.length<=12){for(let l=4,u=i.length;l<u;l+=6)Ce.pointBoundingBox(i[l],i[l+1],e);continue}let a=i[4],o=i[5];for(let l=6,u=i.length;l<u;l+=6){const[d,p,f,g,m,v]=i.subarray(l,l+6);Ce.bezierBoundingBox(a,o,d,p,f,g,m,v,e),a=m,o=v}}const[n,r]=this.#c();e[0]=rn(e[0]-n,0,1),e[1]=rn(e[1]-r,0,1),e[2]=rn(e[2]+n,0,1),e[3]=rn(e[3]+r,0,1),e[2]-=e[0],e[3]-=e[1]}get box(){return this.#e}updateProperty(e,n){return e==="stroke-width"?this.#f(n):null}#f(e){const[n,r]=this.#c();this.#d=e;const[i,a]=this.#c(),[o,l]=[i-n,a-r],u=this.#e;return u[0]-=o,u[1]-=l,u[2]+=2*o,u[3]+=2*l,u}updateParentDimensions([e,n],r){const[i,a]=this.#c();this.#a=e,this.#i=n,this.#l=r;const[o,l]=this.#c(),u=o-i,d=l-a,p=this.#e;return p[0]-=u,p[1]-=d,p[2]+=2*u,p[3]+=2*d,p}updateRotation(e){return this.#t=e,{path:{transform:this.rotationTransform}}}get viewBox(){return this.#e.map(ye.svgRound).join(" ")}get defaultProperties(){const[e,n]=this.#e;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${ye.svgRound(e)} ${ye.svgRound(n)}`}}}get rotationTransform(){const[,,e,n]=this.#e;let r=0,i=0,a=0,o=0,l=0,u=0;switch(this.#t){case 90:i=n/e,a=-e/n,l=e;break;case 180:r=-1,o=-1,l=e,u=n;break;case 270:i=-n/e,a=e/n,u=n;break;default:return""}return`matrix(${r} ${i} ${a} ${o} ${ye.svgRound(l)} ${ye.svgRound(u)})`}getPathResizingSVGProperties([e,n,r,i]){const[a,o]=this.#c(),[l,u,d,p]=this.#e;if(Math.abs(d-a)<=ye.PRECISION||Math.abs(p-o)<=ye.PRECISION){const b=e+r/2-(l+d/2),E=n+i/2-(u+p/2);return{path:{"transform-origin":`${ye.svgRound(e)} ${ye.svgRound(n)}`,transform:`${this.rotationTransform} translate(${b} ${E})`}}}const f=(r-2*a)/(d-2*a),g=(i-2*o)/(p-2*o),m=d/r,v=p/i;return{path:{"transform-origin":`${ye.svgRound(l)} ${ye.svgRound(u)}`,transform:`${this.rotationTransform} scale(${m} ${v}) translate(${ye.svgRound(a)} ${ye.svgRound(o)}) scale(${f} ${g}) translate(${ye.svgRound(-a)} ${ye.svgRound(-o)})`}}}getPathResizedSVGProperties([e,n,r,i]){const[a,o]=this.#c(),l=this.#e,[u,d,p,f]=l;if(l[0]=e,l[1]=n,l[2]=r,l[3]=i,Math.abs(p-a)<=ye.PRECISION||Math.abs(f-o)<=ye.PRECISION){const E=e+r/2-(u+p/2),S=n+i/2-(d+f/2);for(const{line:_,points:w}of this.#r)ye._translate(_,E,S,_),ye._translate(w,E,S,w);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${ye.svgRound(e)} ${ye.svgRound(n)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const g=(r-2*a)/(p-2*a),m=(i-2*o)/(f-2*o),v=-g*(u+a)+e+a,b=-m*(d+o)+n+o;if(g!==1||m!==1||v!==0||b!==0)for(const{line:E,points:S}of this.#r)ye._rescale(E,v,b,g,m,E),ye._rescale(S,v,b,g,m,S);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${ye.svgRound(e)} ${ye.svgRound(n)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,n],r){const[i,a]=r,o=this.#e,l=e-o[0],u=n-o[1];if(this.#a===i&&this.#i===a)for(const{line:d,points:p}of this.#r)ye._translate(d,l,u,d),ye._translate(p,l,u,p);else{const d=this.#a/i,p=this.#i/a;this.#a=i,this.#i=a;for(const{line:f,points:g}of this.#r)ye._rescale(f,l,u,d,p,f),ye._rescale(g,l,u,d,p,g);o[2]*=d,o[3]*=p}return o[0]=e,o[1]=n,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${ye.svgRound(e)} ${ye.svgRound(n)}`}}}get defaultSVGProperties(){const e=this.#e;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${ye.svgRound(e[0])} ${ye.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}}class lp extends hF{constructor(e){super(),this._viewParameters=e,super.updateProperties({fill:"none",stroke:Ne._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(e,n){e==="stroke-width"&&(n??=this["stroke-width"],n*=this._viewParameters.realScale),super.updateSVGProperty(e,n)}clone(){const e=new lp(this._viewParameters);return e.updateAll(this),e}}class US extends Ie{static _type="ink";static _editorType=Le.INK;static _defaultDrawingOptions=null;constructor(e){super({...e,name:"inkEditor"}),this._willKeepAspectRatio=!0,this.defaultL10nId="pdfjs-editor-ink-editor"}static initialize(e,n){Ne.initialize(e,n),this._defaultDrawingOptions=new lp(n.viewParameters)}static getDefaultDrawingOptions(e){const n=this._defaultDrawingOptions.clone();return n.updateProperties(e),n}static get supportMultipleDrawings(){return!0}static get typesMap(){return $e(this,"typesMap",new Map([[ze.INK_THICKNESS,"stroke-width"],[ze.INK_COLOR,"stroke"],[ze.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,n,r,i,a){return new ene(e,n,r,i,a,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(e,n,r,i,a,o){return tc.deserialize(e,n,r,i,a,o)}static async deserialize(e,n,r){let i=null;if(e instanceof FS){const{data:{inkLists:o,rect:l,rotation:u,id:d,color:p,opacity:f,borderStyle:{rawWidth:g},popupRef:m},parent:{page:{pageNumber:v}}}=e;i=e={annotationType:Le.INK,color:Array.from(p),thickness:g,opacity:f,paths:{points:o},boxes:null,pageIndex:v-1,rect:l.slice(0),rotation:u,id:d,deleted:!1,popupRef:m}}const a=await super.deserialize(e,n,r);return a.annotationElementId=e.id||null,a._initialData=i,a}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:e,_drawingOptions:n,parent:r}=this;n.updateSVGProperty("stroke-width"),r.drawLayer.updateProperties(e,n.toSVGProperties())}static onScaleChangingWhenDrawing(){const e=this._currentParent;e&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:e,thickness:n,opacity:r}){this._drawingOptions=US.getDefaultDrawingOptions({stroke:Ce.makeHexColor(...e),"stroke-width":n,"stroke-opacity":r})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:n,points:r,rect:i}=this.serializeDraw(e),{_drawingOptions:{stroke:a,"stroke-opacity":o,"stroke-width":l}}=this,u={annotationType:Le.INK,color:Ne._colorManager.convert(a),opacity:o,thickness:l,paths:{lines:n,points:r},pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?(u.isCopy=!0,u):this.annotationElementId&&!this.#e(u)?null:(u.id=this.annotationElementId,u)}#e(e){const{color:n,thickness:r,opacity:i,pageIndex:a}=this._initialData;return this._hasBeenMoved||this._hasBeenResized||e.color.some((o,l)=>o!==n[l])||e.thickness!==r||e.opacity!==i||e.pageIndex!==a}renderAnnotationElement(e){const{points:n,rect:r}=this.serializeDraw(!1);return e.updateEdited({rect:r,thickness:this._drawingOptions["stroke-width"],points:n}),null}}class ww extends tc{toSVGPath(){let e=super.toSVGPath();return e.endsWith("Z")||(e+="Z"),e}}const zu=8,nl=3;class Ea{static#e={maxDim:512,sigmaSFactor:.02,sigmaR:25,kernelSize:16};static#t(e,n,r,i){return r-=e,i-=n,r===0?i>0?0:4:r===1?i+6:2-i}static#n=new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]);static#r(e,n,r,i,a,o,l){const u=this.#t(r,i,a,o);for(let d=0;d<8;d++){const p=(-d+u-l+16)%8,f=this.#n[2*p],g=this.#n[2*p+1];if(e[(r+f)*n+(i+g)]!==0)return p}return-1}static#a(e,n,r,i,a,o,l){const u=this.#t(r,i,a,o);for(let d=0;d<8;d++){const p=(d+u+l+16)%8,f=this.#n[2*p],g=this.#n[2*p+1];if(e[(r+f)*n+(i+g)]!==0)return p}return-1}static#i(e,n,r,i){const a=e.length,o=new Int32Array(a);for(let p=0;p<a;p++)o[p]=e[p]<=i?1:0;for(let p=1;p<r-1;p++)o[p*n]=o[p*n+n-1]=0;for(let p=0;p<n;p++)o[p]=o[n*r-1-p]=0;let l=1,u;const d=[];for(let p=1;p<r-1;p++){u=1;for(let f=1;f<n-1;f++){const g=p*n+f,m=o[g];if(m===0)continue;let v=p,b=f;if(m===1&&o[g-1]===0)l+=1,b-=1;else if(m>=1&&o[g+1]===0)l+=1,b+=1,m>1&&(u=m);else{m!==1&&(u=Math.abs(m));continue}const E=[f,p],S=b===f+1,_={isHole:S,points:E,id:l,parent:0};d.push(_);let w;for(const $ of d)if($.id===u){w=$;break}w?w.isHole?_.parent=S?w.parent:u:_.parent=S?u:w.parent:_.parent=S?u:0;const A=this.#r(o,n,p,f,v,b,0);if(A===-1){o[g]=-l,o[g]!==1&&(u=Math.abs(o[g]));continue}let R=this.#n[2*A],C=this.#n[2*A+1];const T=p+R,O=f+C;v=T,b=O;let L=p,z=f;for(;;){const $=this.#a(o,n,L,z,v,b,1);R=this.#n[2*$],C=this.#n[2*$+1];const G=L+R,W=z+C;E.push(W,G);const P=L*n+z;if(o[P+1]===0?o[P]=-l:o[P]===1&&(o[P]=l),G===p&&W===f&&L===T&&z===O){o[g]!==1&&(u=Math.abs(o[g]));break}else v=L,b=z,L=G,z=W}}}return d}static#l(e,n,r,i){if(r-n<=4){for(let T=n;T<r-2;T+=2)i.push(e[T],e[T+1]);return}const a=e[n],o=e[n+1],l=e[r-4]-a,u=e[r-3]-o,d=Math.hypot(l,u),p=l/d,f=u/d,g=p*o-f*a,m=u/l,v=1/d,b=Math.atan(m),E=Math.cos(b),S=Math.sin(b),_=v*(Math.abs(E)+Math.abs(S)),w=v*(1-_+_**2),A=Math.max(Math.atan(Math.abs(S+E)*w),Math.atan(Math.abs(S-E)*w));let R=0,C=n;for(let T=n+2;T<r-2;T+=2){const O=Math.abs(g-p*e[T+1]+f*e[T]);O>R&&(C=T,R=O)}R>(d*A)**2?(this.#l(e,n,C+2,i),this.#l(e,C,r,i)):i.push(a,o)}static#s(e){const n=[],r=e.length;return this.#l(e,0,r,n),n.push(e[r-2],e[r-1]),n.length<=4?null:n}static#d(e,n,r,i,a,o){const l=new Float32Array(o**2),u=-2*i**2,d=o>>1;for(let b=0;b<o;b++){const E=(b-d)**2;for(let S=0;S<o;S++)l[b*o+S]=Math.exp((E+(S-d)**2)/u)}const p=new Float32Array(256),f=-2*a**2;for(let b=0;b<256;b++)p[b]=Math.exp(b**2/f);const g=e.length,m=new Uint8Array(g),v=new Uint32Array(256);for(let b=0;b<r;b++)for(let E=0;E<n;E++){const S=b*n+E,_=e[S];let w=0,A=0;for(let C=0;C<o;C++){const T=b+C-d;if(!(T<0||T>=r))for(let O=0;O<o;O++){const L=E+O-d;if(L<0||L>=n)continue;const z=e[T*n+L],$=l[C*o+O]*p[Math.abs(z-_)];w+=z*$,A+=$}}const R=m[S]=Math.round(w/A);v[R]++}return[m,v]}static#c(e){const n=new Uint32Array(256);for(const r of e)n[r]++;return n}static#p(e){const n=e.length,r=new Uint8ClampedArray(n>>2);let i=-1/0,a=1/0;for(let l=0,u=r.length;l<u;l++){if(e[(l<<2)+3]===0){i=r[l]=255;continue}const p=r[l]=e[l<<2];p>i&&(i=p),p<a&&(a=p)}const o=255/(i-a);for(let l=0;l<n;l++)r[l]=(r[l]-a)*o;return r}static#u(e){let n,r=-1/0,i=-1/0;const a=e.findIndex(u=>u!==0);let o=a,l=a;for(n=a;n<256;n++){const u=e[n];u>r&&(n-o>i&&(i=n-o,l=n-1),r=u,o=n)}for(n=l-1;n>=0&&!(e[n]>e[n+1]);n--);return n}static#f(e){const n=e,{width:r,height:i}=e,{maxDim:a}=this.#e;let o=r,l=i;if(r>a||i>a){let g=r,m=i,v=Math.log2(Math.max(r,i)/a);const b=Math.floor(v);v=v===b?b-1:b;for(let S=0;S<v;S++){o=Math.ceil(g/2),l=Math.ceil(m/2);const _=new OffscreenCanvas(o,l);_.getContext("2d").drawImage(e,0,0,g,m,0,0,o,l),g=o,m=l,e!==n&&e.close(),e=_.transferToImageBitmap()}const E=Math.min(a/o,a/l);o=Math.round(o*E),l=Math.round(l*E)}const d=new OffscreenCanvas(o,l).getContext("2d",{willReadFrequently:!0});d.filter="grayscale(1)",d.drawImage(e,0,0,e.width,e.height,0,0,o,l);const p=d.getImageData(0,0,o,l).data;return[this.#p(p),o,l]}static extractContoursFromText(e,{fontFamily:n,fontStyle:r,fontWeight:i},a,o,l,u){let d=new OffscreenCanvas(1,1),p=d.getContext("2d",{alpha:!1});const f=200,g=p.font=`${r} ${i} ${f}px ${n}`,{actualBoundingBoxLeft:m,actualBoundingBoxRight:v,actualBoundingBoxAscent:b,actualBoundingBoxDescent:E,fontBoundingBoxAscent:S,fontBoundingBoxDescent:_,width:w}=p.measureText(e),A=1.5,R=Math.ceil(Math.max(Math.abs(m)+Math.abs(v)||0,w)*A),C=Math.ceil(Math.max(Math.abs(b)+Math.abs(E)||f,Math.abs(S)+Math.abs(_)||f)*A);d=new OffscreenCanvas(R,C),p=d.getContext("2d",{alpha:!0,willReadFrequently:!0}),p.font=g,p.filter="grayscale(1)",p.fillStyle="white",p.fillRect(0,0,R,C),p.fillStyle="black",p.fillText(e,R*(A-1)/2,C*(3-A)/2);const T=this.#p(p.getImageData(0,0,R,C).data),O=this.#c(T),L=this.#u(O),z=this.#i(T,R,C,L);return this.processDrawnLines({lines:{curves:z,width:R,height:C},pageWidth:a,pageHeight:o,rotation:l,innerMargin:u,mustSmooth:!0,areContours:!0})}static process(e,n,r,i,a){const[o,l,u]=this.#f(e),[d,p]=this.#d(o,l,u,Math.hypot(l,u)*this.#e.sigmaSFactor,this.#e.sigmaR,this.#e.kernelSize),f=this.#u(p),g=this.#i(d,l,u,f);return this.processDrawnLines({lines:{curves:g,width:l,height:u},pageWidth:n,pageHeight:r,rotation:i,innerMargin:a,mustSmooth:!0,areContours:!0})}static processDrawnLines({lines:e,pageWidth:n,pageHeight:r,rotation:i,innerMargin:a,mustSmooth:o,areContours:l}){i%180!==0&&([n,r]=[r,n]);const{curves:u,width:d,height:p}=e,f=e.thickness??0,g=[],m=Math.min(n/d,r/p),v=m/n,b=m/r,E=[];for(const{points:_}of u){const w=o?this.#s(_):_;if(!w)continue;E.push(w);const A=w.length,R=new Float32Array(A),C=new Float32Array(3*(A===2?2:A-2));if(g.push({line:C,points:R}),A===2){R[0]=w[0]*v,R[1]=w[1]*b,C.set([NaN,NaN,NaN,NaN,R[0],R[1]],0);continue}let[T,O,L,z]=w;T*=v,O*=b,L*=v,z*=b,R.set([T,O,L,z],0),C.set([NaN,NaN,NaN,NaN,T,O],0);for(let $=4;$<A;$+=2){const G=R[$]=w[$]*v,W=R[$+1]=w[$+1]*b;C.set(ye.createBezierPoints(T,O,L,z,G,W),($-2)*3),[T,O,L,z]=[L,z,G,W]}}if(g.length===0)return null;const S=l?new ww:new tc;return S.build(g,n,r,1,i,l?0:f,a),{outline:S,newCurves:E,areContours:l,thickness:f,width:d,height:p}}static async compressSignature({outlines:e,areContours:n,thickness:r,width:i,height:a}){let o=1/0,l=-1/0,u=0;for(const w of e){u+=w.length;for(let A=2,R=w.length;A<R;A++){const C=w[A]-w[A-2];o=Math.min(o,C),l=Math.max(l,C)}}let d;o>=-128&&l<=127?d=Int8Array:o>=-32768&&l<=32767?d=Int16Array:d=Int32Array;const p=e.length,f=zu+nl*p,g=new Uint32Array(f);let m=0;g[m++]=f*Uint32Array.BYTES_PER_ELEMENT+(u-2*p)*d.BYTES_PER_ELEMENT,g[m++]=0,g[m++]=i,g[m++]=a,g[m++]=n?0:1,g[m++]=Math.max(0,Math.floor(r??0)),g[m++]=p,g[m++]=d.BYTES_PER_ELEMENT;for(const w of e)g[m++]=w.length-2,g[m++]=w[0],g[m++]=w[1];const v=new CompressionStream("deflate-raw"),b=v.writable.getWriter();await b.ready,b.write(g);const E=d.prototype.constructor;for(const w of e){const A=new E(w.length-2);for(let R=2,C=w.length;R<C;R++)A[R-2]=w[R]-w[R-2];b.write(A)}b.close();const S=await new Response(v.readable).arrayBuffer(),_=new Uint8Array(S);return FP(_)}static async decompressSignature(e){try{const n=Nee(e),{readable:r,writable:i}=new DecompressionStream("deflate-raw"),a=i.getWriter();await a.ready,a.write(n).then(async()=>{await a.ready,await a.close()}).catch(()=>{});let o=null,l=0;for await(const w of r)o||=new Uint8Array(new Uint32Array(w.buffer,0,4)[0]),o.set(w,l),l+=w.length;const u=new Uint32Array(o.buffer,0,o.length>>2),d=u[1];if(d!==0)throw new Error(`Invalid version: ${d}`);const p=u[2],f=u[3],g=u[4]===0,m=u[5],v=u[6],b=u[7],E=[],S=(zu+nl*v)*Uint32Array.BYTES_PER_ELEMENT;let _;switch(b){case Int8Array.BYTES_PER_ELEMENT:_=new Int8Array(o.buffer,S);break;case Int16Array.BYTES_PER_ELEMENT:_=new Int16Array(o.buffer,S);break;case Int32Array.BYTES_PER_ELEMENT:_=new Int32Array(o.buffer,S);break}l=0;for(let w=0;w<v;w++){const A=u[nl*w+zu],R=new Float32Array(A+2);E.push(R);for(let C=0;C<nl-1;C++)R[C]=u[nl*w+zu+C+1];for(let C=0;C<A;C++)R[C+2]=R[C]+_[l++]}return{areContours:g,thickness:m,outlines:E,width:p,height:f}}catch(n){return Me(`decompressSignature: ${n}`),null}}}class $S extends hF{constructor(){super(),super.updateProperties({fill:Ne._defaultLineColor,"stroke-width":0})}clone(){const e=new $S;return e.updateAll(this),e}}class zS extends lp{constructor(e){super(e),super.updateProperties({stroke:Ne._defaultLineColor,"stroke-width":1})}clone(){const e=new zS(this._viewParameters);return e.updateAll(this),e}}class Cr extends Ie{#e=!1;#t=null;#n=null;#r=null;static _type="signature";static _editorType=Le.SIGNATURE;static _defaultDrawingOptions=null;constructor(e){super({...e,mustBeCommitted:!0,name:"signatureEditor"}),this._willKeepAspectRatio=!0,this.#n=e.signatureData||null,this.#t=null,this.defaultL10nId="pdfjs-editor-signature-editor1"}static initialize(e,n){Ne.initialize(e,n),this._defaultDrawingOptions=new $S,this._defaultDrawnSignatureOptions=new zS(n.viewParameters)}static getDefaultDrawingOptions(e){const n=this._defaultDrawingOptions.clone();return n.updateProperties(e),n}static get supportMultipleDrawings(){return!1}static get typesMap(){return $e(this,"typesMap",new Map)}static get isDrawer(){return!1}get telemetryFinalData(){return{type:"signature",hasDescription:!!this.#t}}static computeTelemetryFinalData(e){const n=e.get("hasDescription");return{hasAltText:n.get(!0)??0,hasNoAltText:n.get(!1)??0}}get isResizable(){return!0}onScaleChanging(){this._drawId!==null&&super.onScaleChanging()}render(){if(this.div)return this.div;let e,n;const{_isCopy:r}=this;if(r&&(this._isCopy=!1,e=this.x,n=this.y),super.render(),this._drawId===null)if(this.#n){const{lines:i,mustSmooth:a,areContours:o,description:l,uuid:u,heightInPage:d}=this.#n,{rawDims:{pageWidth:p,pageHeight:f},rotation:g}=this.parent.viewport,m=Ea.processDrawnLines({lines:i,pageWidth:p,pageHeight:f,rotation:g,innerMargin:Cr._INNER_MARGIN,mustSmooth:a,areContours:o});this.addSignature(m,d,l,u)}else this.div.setAttribute("data-l10n-args",JSON.stringify({description:""})),this.div.hidden=!0,this._uiManager.getSignature(this);return r&&(this._isCopy=!0,this._moveAfterPaste(e,n)),this.div}setUuid(e){this.#r=e,this.addEditToolbar()}getUuid(){return this.#r}get description(){return this.#t}set description(e){this.#t=e,super.addEditToolbar().then(n=>{n?.updateEditSignatureButton(e)})}getSignaturePreview(){const{newCurves:e,areContours:n,thickness:r,width:i,height:a}=this.#n,o=Math.max(i,a),l=Ea.processDrawnLines({lines:{curves:e.map(u=>({points:u})),thickness:r,width:i,height:a},pageWidth:o,pageHeight:o,rotation:0,innerMargin:0,mustSmooth:!1,areContours:n});return{areContours:n,outline:l.outline}}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.signatureManager&&this.#t!==null&&(await e.addEditSignatureButton(this._uiManager.signatureManager,this.#r,this.#t),e.show()),e):null}addSignature(e,n,r,i){const{x:a,y:o}=this,{outline:l}=this.#n=e;this.#e=l instanceof ww,this.#t=r,this.div.setAttribute("data-l10n-args",JSON.stringify({description:r}));let u;this.#e?u=Cr.getDefaultDrawingOptions():(u=Cr._defaultDrawnSignatureOptions.clone(),u.updateProperties({"stroke-width":l.thickness})),this._addOutlines({drawOutlines:l,drawingOptions:u});const[d,p]=this.parentDimensions,[,f]=this.pageDimensions;let g=n/f;g=g>=1?.5:g,this.width*=g/this.height,this.width>=1&&(g*=.9/this.width,this.width=.9),this.height=g,this.setDims(d*this.width,p*this.height),this.x=a,this.y=o,this.center(),this._onResized(),this.onScaleChanging(),this.rotate(),this._uiManager.addToAnnotationStorage(this),this.setUuid(i),this._reportTelemetry({action:"pdfjs.signature.inserted",data:{hasBeenSaved:!!i,hasDescription:!!r}}),this.div.hidden=!1}getFromImage(e){const{rawDims:{pageWidth:n,pageHeight:r},rotation:i}=this.parent.viewport;return Ea.process(e,n,r,i,Cr._INNER_MARGIN)}getFromText(e,n){const{rawDims:{pageWidth:r,pageHeight:i},rotation:a}=this.parent.viewport;return Ea.extractContoursFromText(e,n,r,i,a,Cr._INNER_MARGIN)}getDrawnSignature(e){const{rawDims:{pageWidth:n,pageHeight:r},rotation:i}=this.parent.viewport;return Ea.processDrawnLines({lines:e,pageWidth:n,pageHeight:r,rotation:i,innerMargin:Cr._INNER_MARGIN,mustSmooth:!1,areContours:!1})}createDrawingOptions({areContours:e,thickness:n}){e?this._drawingOptions=Cr.getDefaultDrawingOptions():(this._drawingOptions=Cr._defaultDrawnSignatureOptions.clone(),this._drawingOptions.updateProperties({"stroke-width":n}))}serialize(e=!1){if(this.isEmpty())return null;const{lines:n,points:r,rect:i}=this.serializeDraw(e),{_drawingOptions:{"stroke-width":a}}=this,o={annotationType:Le.SIGNATURE,isSignature:!0,areContours:this.#e,color:[0,0,0],thickness:this.#e?0:a,pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?(o.paths={lines:n,points:r},o.uuid=this.#r,o.isCopy=!0):o.lines=n,this.#t&&(o.accessibilityData={type:"Figure",alt:this.#t}),o}static deserializeDraw(e,n,r,i,a,o){return o.areContours?ww.deserialize(e,n,r,i,a,o):tc.deserialize(e,n,r,i,a,o)}static async deserialize(e,n,r){const i=await super.deserialize(e,n,r);return i.#e=e.areContours,i.#t=e.accessibilityData?.alt||"",i.#r=e.uuid,i}}class tne extends Ne{#e=null;#t=null;#n=null;#r=null;#a=null;#i="";#l=null;#s=!1;#d=null;#c=!1;#p=!1;static _type="stamp";static _editorType=Le.STAMP;constructor(e){super({...e,name:"stampEditor"}),this.#r=e.bitmapUrl,this.#a=e.bitmapFile,this.defaultL10nId="pdfjs-editor-stamp-editor"}static initialize(e,n){Ne.initialize(e,n)}static isHandlingMimeForPasting(e){return wd.includes(e)}static paste(e,n){n.pasteEditor({mode:Le.STAMP},{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){return{type:"stamp",hasAltText:!!this.altTextData?.altText}}static computeTelemetryFinalData(e){const n=e.get("hasAltText");return{hasAltText:n.get(!0)??0,hasNoAltText:n.get(!1)??0}}#u(e,n=!1){if(!e){this.remove();return}this.#e=e.bitmap,n||(this.#t=e.id,this.#c=e.isSvg),e.file&&(this.#i=e.file.name),this.#h()}#f(){if(this.#n=null,this._uiManager.enableWaiting(!1),!!this.#l){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#e){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#e){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}}async mlGuessAltText(e=null,n=!0){if(this.hasAltTextData())return null;const{mlManager:r}=this._uiManager;if(!r)throw new Error("No ML.");if(!await r.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:i,width:a,height:o}=e||this.copyCanvas(null,null,!0).imageData,l=await r.guess({name:"altText",request:{data:i,width:a,height:o,channels:i.length/(a*o)}});if(!l)throw new Error("No response from the AI service.");if(l.error)throw new Error("Error from the AI service.");if(l.cancel)return null;if(!l.output)throw new Error("No valid response from the AI service.");const u=l.output;return await this.setGuessedAltText(u),n&&!this.hasAltTextData()&&(this.altTextData={alt:u,decorative:!1}),u}#o(){if(this.#t){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(this.#t).then(r=>this.#u(r,!0)).finally(()=>this.#f());return}if(this.#r){const r=this.#r;this.#r=null,this._uiManager.enableWaiting(!0),this.#n=this._uiManager.imageManager.getFromUrl(r).then(i=>this.#u(i)).finally(()=>this.#f());return}if(this.#a){const r=this.#a;this.#a=null,this._uiManager.enableWaiting(!0),this.#n=this._uiManager.imageManager.getFromFile(r).then(i=>this.#u(i)).finally(()=>this.#f());return}const e=document.createElement("input");e.type="file",e.accept=wd.join(",");const n=this._uiManager._signal;this.#n=new Promise(r=>{e.addEventListener("change",async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const i=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),this.#u(i)}r()},{signal:n}),e.addEventListener("cancel",()=>{this.remove(),r()},{signal:n})}).finally(()=>this.#f()),e.click()}remove(){this.#t&&(this.#e=null,this._uiManager.imageManager.deleteId(this.#t),this.#l?.remove(),this.#l=null,this.#d&&(clearTimeout(this.#d),this.#d=null)),super.remove()}rebuild(){if(!this.parent){this.#t&&this.#o();return}super.rebuild(),this.div!==null&&(this.#t&&this.#l===null&&this.#o(),this.isAttachedToDOM||this.parent.add(this))}onceAdded(e){this._isDraggable=!0,e&&this.div.focus()}isEmpty(){return!(this.#n||this.#e||this.#r||this.#a||this.#t||this.#s)}get isResizable(){return!0}render(){if(this.div)return this.div;let e,n;return this._isCopy&&(e=this.x,n=this.y),super.render(),this.div.hidden=!0,this.addAltTextButton(),this.#s||(this.#e?this.#h():this.#o()),this._isCopy&&this._moveAfterPaste(e,n),this._uiManager.addShouldRescale(this),this.div}setCanvas(e,n){const{id:r,bitmap:i}=this._uiManager.imageManager.getFromCanvas(e,n);n.remove(),r&&this._uiManager.imageManager.isValidId(r)&&(this.#t=r,i&&(this.#e=i),this.#s=!1,this.#h())}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;this.#d!==null&&clearTimeout(this.#d);const e=200;this.#d=setTimeout(()=>{this.#d=null,this.#g()},e)}#h(){const{div:e}=this;let{width:n,height:r}=this.#e;const[i,a]=this.pageDimensions,o=.75;if(this.width)n=this.width*i,r=this.height*a;else if(n>o*i||r>o*a){const p=Math.min(o*i/n,o*a/r);n*=p,r*=p}const[l,u]=this.parentDimensions;this.setDims(n*l/i,r*u/a),this._uiManager.enableWaiting(!1);const d=this.#l=document.createElement("canvas");d.setAttribute("role","img"),this.addContainer(d),this.width=n/i,this.height=r/a,this._initialOptions?.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),this.#g(),this.#p||(this.parent.addUndoableEditor(this),this.#p=!0),this._reportTelemetry({action:"inserted_image"}),this.#i&&this.div.setAttribute("aria-description",this.#i)}copyCanvas(e,n,r=!1){e||(e=224);const{width:i,height:a}=this.#e,o=new fr;let l=this.#e,u=i,d=a,p=null;if(n){if(i>n||a>n){const C=Math.min(n/i,n/a);u=Math.floor(i*C),d=Math.floor(a*C)}p=document.createElement("canvas");const g=p.width=Math.ceil(u*o.sx),m=p.height=Math.ceil(d*o.sy);this.#c||(l=this.#m(g,m));const v=p.getContext("2d");v.filter=this._uiManager.hcmFilter;let b="white",E="#cfcfd8";this._uiManager.hcmFilter!=="none"?E="black":window.matchMedia?.("(prefers-color-scheme: dark)").matches&&(b="#8f8f9d",E="#42414d");const S=15,_=S*o.sx,w=S*o.sy,A=new OffscreenCanvas(_*2,w*2),R=A.getContext("2d");R.fillStyle=b,R.fillRect(0,0,_*2,w*2),R.fillStyle=E,R.fillRect(0,0,_,w),R.fillRect(_,w,_,w),v.fillStyle=v.createPattern(A,"repeat"),v.fillRect(0,0,g,m),v.drawImage(l,0,0,l.width,l.height,0,0,g,m)}let f=null;if(r){let g,m;if(o.symmetric&&l.width<e&&l.height<e)g=l.width,m=l.height;else if(l=this.#e,i>e||a>e){const E=Math.min(e/i,e/a);g=Math.floor(i*E),m=Math.floor(a*E),this.#c||(l=this.#m(g,m))}const b=new OffscreenCanvas(g,m).getContext("2d",{willReadFrequently:!0});b.drawImage(l,0,0,l.width,l.height,0,0,g,m),f={width:g,height:m,data:b.getImageData(0,0,g,m).data}}return{canvas:p,width:u,height:d,imageData:f}}#m(e,n){const{width:r,height:i}=this.#e;let a=r,o=i,l=this.#e;for(;a>2*e||o>2*n;){const u=a,d=o;a>2*e&&(a=a>=16384?Math.floor(a/2)-1:Math.ceil(a/2)),o>2*n&&(o=o>=16384?Math.floor(o/2)-1:Math.ceil(o/2));const p=new OffscreenCanvas(a,o);p.getContext("2d").drawImage(l,0,0,u,d,0,0,a,o),l=p.transferToImageBitmap()}return l}#g(){const[e,n]=this.parentDimensions,{width:r,height:i}=this,a=new fr,o=Math.ceil(r*e*a.sx),l=Math.ceil(i*n*a.sy),u=this.#l;if(!u||u.width===o&&u.height===l)return;u.width=o,u.height=l;const d=this.#c?this.#e:this.#m(o,l),p=u.getContext("2d");p.filter=this._uiManager.hcmFilter,p.drawImage(d,0,0,d.width,d.height,0,0,o,l)}#b(e){if(e){if(this.#c){const i=this._uiManager.imageManager.getSvgUrl(this.#t);if(i)return i}const n=document.createElement("canvas");return{width:n.width,height:n.height}=this.#e,n.getContext("2d").drawImage(this.#e,0,0),n.toDataURL()}if(this.#c){const[n,r]=this.pageDimensions,i=Math.round(this.width*n*Ba.PDF_TO_CSS_UNITS),a=Math.round(this.height*r*Ba.PDF_TO_CSS_UNITS),o=new OffscreenCanvas(i,a);return o.getContext("2d").drawImage(this.#e,0,0,this.#e.width,this.#e.height,0,0,i,a),o.transferToImageBitmap()}return structuredClone(this.#e)}static async deserialize(e,n,r){let i=null,a=!1;if(e instanceof dF){const{data:{rect:b,rotation:E,id:S,structParent:_,popupRef:w},container:A,parent:{page:{pageNumber:R}},canvas:C}=e;let T,O;C?(delete e.canvas,{id:T,bitmap:O}=r.imageManager.getFromCanvas(A.id,C),C.remove()):(a=!0,e._hasNoCanvas=!0);const L=(await n._structTree.getAriaAttributes(`${AS}${S}`))?.get("aria-label")||"";i=e={annotationType:Le.STAMP,bitmapId:T,bitmap:O,pageIndex:R-1,rect:b.slice(0),rotation:E,id:S,deleted:!1,accessibilityData:{decorative:!1,altText:L},isSvg:!1,structParent:_,popupRef:w}}const o=await super.deserialize(e,n,r),{rect:l,bitmap:u,bitmapUrl:d,bitmapId:p,isSvg:f,accessibilityData:g}=e;a?(r.addMissingCanvas(e.id,o),o.#s=!0):p&&r.imageManager.isValidId(p)?(o.#t=p,u&&(o.#e=u)):o.#r=d,o.#c=f;const[m,v]=o.pageDimensions;return o.width=(l[2]-l[0])/m,o.height=(l[3]-l[1])/v,o.annotationElementId=e.id||null,g&&(o.altTextData=g),o._initialData=i,o.#p=!!i,o}serialize(e=!1,n=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const r={annotationType:Le.STAMP,bitmapId:this.#t,pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:this.#c,structTreeParentId:this._structTreeParentId};if(e)return r.bitmapUrl=this.#b(!0),r.accessibilityData=this.serializeAltText(!0),r.isCopy=!0,r;const{decorative:i,altText:a}=this.serializeAltText(!1);if(!i&&a&&(r.accessibilityData={type:"Figure",alt:a}),this.annotationElementId){const l=this.#y(r);if(l.isSame)return null;l.isSameAltText?delete r.accessibilityData:r.accessibilityData.structParent=this._initialData.structParent??-1}if(r.id=this.annotationElementId,n===null)return r;n.stamps||=new Map;const o=this.#c?(r.rect[2]-r.rect[0])*(r.rect[3]-r.rect[1]):null;if(!n.stamps.has(this.#t))n.stamps.set(this.#t,{area:o,serialized:r}),r.bitmap=this.#b(!1);else if(this.#c){const l=n.stamps.get(this.#t);o>l.area&&(l.area=o,l.serialized.bitmap.close(),l.serialized.bitmap=this.#b(!1))}return r}#y(e){const{pageIndex:n,accessibilityData:{altText:r}}=this._initialData,i=e.pageIndex===n,a=(e.accessibilityData?.alt||"")===r;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&i&&a,isSameAltText:a}}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}}class kr{#e;#t=!1;#n=null;#r=null;#a=null;#i=new Map;#l=!1;#s=!1;#d=!1;#c=null;#p=null;#u=null;#f=null;#o;static _initialized=!1;static#h=new Map([Ft,US,tne,At,Cr].map(e=>[e._editorType,e]));constructor({uiManager:e,pageIndex:n,div:r,structTreeLayer:i,accessibilityManager:a,annotationLayer:o,drawLayer:l,textLayer:u,viewport:d,l10n:p}){const f=[...kr.#h.values()];if(!kr._initialized){kr._initialized=!0;for(const g of f)g.initialize(p,e)}e.registerEditorTypes(f),this.#o=e,this.pageIndex=n,this.div=r,this.#e=a,this.#n=o,this.viewport=d,this.#u=u,this.drawLayer=l,this._structTree=i,this.#o.addLayer(this)}get isEmpty(){return this.#i.size===0}get isInvisible(){return this.isEmpty&&this.#o.getMode()===Le.NONE}updateToolbar(e){this.#o.updateToolbar(e)}updateMode(e=this.#o.getMode()){switch(this.#v(),e){case Le.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case Le.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case Le.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:n}=this.div;for(const r of kr.#h.values())n.toggle(`${r._type}Editing`,e===r._editorType);this.div.hidden=!1}hasTextLayer(e){return e===this.#u?.div}setEditingState(e){this.#o.setEditingState(e)}addCommands(e){this.#o.addCommands(e)}cleanUndoStack(e){this.#o.cleanUndoStack(e)}toggleDrawing(e=!1){this.div.classList.toggle("drawing",!e)}togglePointerEvents(e=!1){this.div.classList.toggle("disabled",!e)}toggleAnnotationLayerPointerEvents(e=!1){this.#n?.div.classList.toggle("disabled",!e)}async enable(){this.#d=!0,this.div.tabIndex=0,this.togglePointerEvents(!0);const e=new Set;for(const r of this.#i.values())r.enableEditing(),r.show(!0),r.annotationElementId&&(this.#o.removeChangedExistingAnnotation(r),e.add(r.annotationElementId));if(!this.#n){this.#d=!1;return}const n=this.#n.getEditableAnnotations();for(const r of n){if(r.hide(),this.#o.isDeletedAnnotationElement(r.data.id)||e.has(r.data.id))continue;const i=await this.deserialize(r);i&&(this.addOrRebuild(i),i.enableEditing())}this.#d=!1}disable(){this.#s=!0,this.div.tabIndex=-1,this.togglePointerEvents(!1);const e=new Map,n=new Map;for(const i of this.#i.values())if(i.disableEditing(),!!i.annotationElementId){if(i.serialize()!==null){e.set(i.annotationElementId,i);continue}else n.set(i.annotationElementId,i);this.getEditableAnnotation(i.annotationElementId)?.show(),i.remove()}if(this.#n){const i=this.#n.getEditableAnnotations();for(const a of i){const{id:o}=a.data;if(this.#o.isDeletedAnnotationElement(o))continue;let l=n.get(o);if(l){l.resetAnnotationElement(a),l.show(!1),a.show();continue}l=e.get(o),l&&(this.#o.addChangedExistingAnnotation(l),l.renderAnnotationElement(a)&&l.show(!1)),a.show()}}this.#v(),this.isEmpty&&(this.div.hidden=!0);const{classList:r}=this.div;for(const i of kr.#h.values())r.remove(`${i._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),this.#s=!1}getEditableAnnotation(e){return this.#n?.getEditableAnnotation(e)||null}setActiveEditor(e){this.#o.getActive()!==e&&this.#o.setActiveEditor(e)}enableTextSelection(){if(this.div.tabIndex=-1,this.#u?.div&&!this.#f){this.#f=new AbortController;const e=this.#o.combinedSignal(this.#f);this.#u.div.addEventListener("pointerdown",this.#m.bind(this),{signal:e}),this.#u.div.classList.add("highlighting")}}disableTextSelection(){this.div.tabIndex=0,this.#u?.div&&this.#f&&(this.#f.abort(),this.#f=null,this.#u.div.classList.remove("highlighting"))}#m(e){this.#o.unselectAll();const{target:n}=e;if(n===this.#u.div||(n.getAttribute("role")==="img"||n.classList.contains("endOfContent"))&&this.#u.div.contains(n)){const{isMac:r}=Gt.platform;if(e.button!==0||e.ctrlKey&&r)return;this.#o.showAllEditors("highlight",!0,!0),this.#u.div.classList.add("free"),this.toggleDrawing(),At.startHighlighting(this,this.#o.direction==="ltr",{target:this.#u.div,x:e.x,y:e.y}),this.#u.div.addEventListener("pointerup",()=>{this.#u.div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:this.#o._signal}),e.preventDefault()}}enableClick(){if(this.#r)return;this.#r=new AbortController;const e=this.#o.combinedSignal(this.#r);this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:e});const n=this.pointerup.bind(this);this.div.addEventListener("pointerup",n,{signal:e}),this.div.addEventListener("pointercancel",n,{signal:e})}disableClick(){this.#r?.abort(),this.#r=null}attach(e){this.#i.set(e.id,e);const{annotationElementId:n}=e;n&&this.#o.isDeletedAnnotationElement(n)&&this.#o.removeDeletedAnnotationElement(e)}detach(e){this.#i.delete(e.id),this.#e?.removePointerInTextLayer(e.contentDiv),!this.#s&&e.annotationElementId&&this.#o.addDeletedAnnotationElement(e)}remove(e){this.detach(e),this.#o.removeEditor(e),e.div.remove(),e.isAttachedToDOM=!1}changeParent(e){e.parent!==this&&(e.parent&&e.annotationElementId&&(this.#o.addDeletedAnnotationElement(e.annotationElementId),Ne.deleteAnnotationElement(e),e.annotationElementId=null),this.attach(e),e.parent?.detach(e),e.setParent(this),e.div&&e.isAttachedToDOM&&(e.div.remove(),this.div.append(e.div)))}add(e){if(!(e.parent===this&&e.isAttachedToDOM)){if(this.changeParent(e),this.#o.addEditor(e),this.attach(e),!e.isAttachedToDOM){const n=e.render();this.div.append(n),e.isAttachedToDOM=!0}e.fixAndSetPosition(),e.onceAdded(!this.#d),this.#o.addToAnnotationStorage(e),e._reportTelemetry(e.telemetryInitialData)}}moveEditorInDOM(e){if(!e.isAttachedToDOM)return;const{activeElement:n}=document;e.div.contains(n)&&!this.#a&&(e._focusEventsAllowed=!1,this.#a=setTimeout(()=>{this.#a=null,e.div.contains(document.activeElement)?e._focusEventsAllowed=!0:(e.div.addEventListener("focusin",()=>{e._focusEventsAllowed=!0},{once:!0,signal:this.#o._signal}),n.focus())},0)),e._structTreeParentId=this.#e?.moveElementInDOM(this.div,e.div,e.contentDiv,!0)}addOrRebuild(e){e.needsToBeRebuilt()?(e.parent||=this,e.rebuild(),e.show()):this.add(e)}addUndoableEditor(e){const n=()=>e._uiManager.rebuild(e),r=()=>{e.remove()};this.addCommands({cmd:n,undo:r,mustExec:!1})}getNextId(){return this.#o.getId()}get#g(){return kr.#h.get(this.#o.getMode())}combinedSignal(e){return this.#o.combinedSignal(e)}#b(e){const n=this.#g;return n?new n.prototype.constructor(e):null}canCreateNewEmptyEditor(){return this.#g?.canCreateNewEmptyEditor()}async pasteEditor(e,n){this.updateToolbar(e),await this.#o.updateMode(e.mode);const{offsetX:r,offsetY:i}=this.#y(),a=this.getNextId(),o=this.#b({parent:this,id:a,x:r,y:i,uiManager:this.#o,isCentered:!0,...n});o&&this.add(o)}async deserialize(e){return await kr.#h.get(e.annotationType??e.annotationEditorType)?.deserialize(e,this,this.#o)||null}createAndAddNewEditor(e,n,r={}){const i=this.getNextId(),a=this.#b({parent:this,id:i,x:e.offsetX,y:e.offsetY,uiManager:this.#o,isCentered:n,...r});return a&&this.add(a),a}#y(){const{x:e,y:n,width:r,height:i}=this.div.getBoundingClientRect(),a=Math.max(0,e),o=Math.max(0,n),l=Math.min(window.innerWidth,e+r),u=Math.min(window.innerHeight,n+i),d=(a+l)/2-e,p=(o+u)/2-n,[f,g]=this.viewport.rotation%180===0?[d,p]:[p,d];return{offsetX:f,offsetY:g}}addNewEditor(e={}){this.createAndAddNewEditor(this.#y(),!0,e)}setSelected(e){this.#o.setSelected(e)}toggleSelected(e){this.#o.toggleSelected(e)}unselect(e){this.#o.unselect(e)}pointerup(e){const{isMac:n}=Gt.platform;if(e.button!==0||e.ctrlKey&&n||e.target!==this.div||!this.#l||(this.#l=!1,this.#g?.isDrawer&&this.#g.supportMultipleDrawings))return;if(!this.#t){this.#t=!0;return}const r=this.#o.getMode();if(r===Le.STAMP||r===Le.SIGNATURE){this.#o.unselectAll();return}this.createAndAddNewEditor(e,!1)}pointerdown(e){if(this.#o.getMode()===Le.HIGHLIGHT&&this.enableTextSelection(),this.#l){this.#l=!1;return}const{isMac:n}=Gt.platform;if(e.button!==0||e.ctrlKey&&n||e.target!==this.div)return;if(this.#l=!0,this.#g?.isDrawer){this.startDrawingSession(e);return}const r=this.#o.getActive();this.#t=!r||r.isEmpty()}startDrawingSession(e){if(this.div.focus({preventScroll:!0}),this.#c){this.#g.startDrawing(this,this.#o,!1,e);return}this.#o.setCurrentDrawingSession(this),this.#c=new AbortController;const n=this.#o.combinedSignal(this.#c);this.div.addEventListener("blur",({relatedTarget:r})=>{r&&!this.div.contains(r)&&(this.#p=null,this.commitOrRemove())},{signal:n}),this.#g.startDrawing(this,this.#o,!1,e)}pause(e){if(e){const{activeElement:n}=document;this.div.contains(n)&&(this.#p=n);return}this.#p&&setTimeout(()=>{this.#p?.focus(),this.#p=null},0)}endDrawingSession(e=!1){return this.#c?(this.#o.setCurrentDrawingSession(null),this.#c.abort(),this.#c=null,this.#p=null,this.#g.endDrawing(e)):null}findNewParent(e,n,r){const i=this.#o.findParent(n,r);return i===null||i===this?!1:(i.changeParent(e),!0)}commitOrRemove(){return this.#c?(this.endDrawingSession(),!0):!1}onScaleChanging(){this.#c&&this.#g.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove(),this.#o.getActive()?.parent===this&&(this.#o.commitOrRemove(),this.#o.setActiveEditor(null)),this.#a&&(clearTimeout(this.#a),this.#a=null);for(const e of this.#i.values())this.#e?.removePointerInTextLayer(e.contentDiv),e.setParent(null),e.isAttachedToDOM=!1,e.div.remove();this.div=null,this.#i.clear(),this.#o.removeLayer(this)}#v(){for(const e of this.#i.values())e.isEmpty()&&e.remove()}render({viewport:e}){this.viewport=e,Vi(this.div,e);for(const n of this.#o.getEditors(this.pageIndex))this.add(n),n.rebuild();this.updateMode()}update({viewport:e}){this.#o.commitOrRemove(),this.#v();const n=this.viewport.rotation,r=e.rotation;if(this.viewport=e,Vi(this.div,{rotation:r}),n!==r)for(const i of this.#i.values())i.rotate(r)}get pageDimensions(){const{pageWidth:e,pageHeight:n}=this.viewport.rawDims;return[e,n]}get scale(){return this.#o.viewParameters.realScale}}class jt{#e=null;#t=new Map;#n=new Map;static#r=0;constructor({pageIndex:e}){this.pageIndex=e}setParent(e){if(!this.#e){this.#e=e;return}if(this.#e!==e){if(this.#t.size>0)for(const n of this.#t.values())n.remove(),e.append(n);this.#e=e}}static get _svgFactory(){return $e(this,"_svgFactory",new Ll)}static#a(e,[n,r,i,a]){const{style:o}=e;o.top=`${100*r}%`,o.left=`${100*n}%`,o.width=`${100*i}%`,o.height=`${100*a}%`}#i(){const e=jt._svgFactory.create(1,1,!0);return this.#e.append(e),e.setAttribute("aria-hidden",!0),e}#l(e,n){const r=jt._svgFactory.createElement("clipPath");e.append(r);const i=`clip_${n}`;r.setAttribute("id",i),r.setAttribute("clipPathUnits","objectBoundingBox");const a=jt._svgFactory.createElement("use");return r.append(a),a.setAttribute("href",`#${n}`),a.classList.add("clip"),i}#s(e,n){for(const[r,i]of Object.entries(n))i===null?e.removeAttribute(r):e.setAttribute(r,i)}draw(e,n=!1,r=!1){const i=jt.#r++,a=this.#i(),o=jt._svgFactory.createElement("defs");a.append(o);const l=jt._svgFactory.createElement("path");o.append(l);const u=`path_p${this.pageIndex}_${i}`;l.setAttribute("id",u),l.setAttribute("vector-effect","non-scaling-stroke"),n&&this.#n.set(i,l);const d=r?this.#l(o,u):null,p=jt._svgFactory.createElement("use");return a.append(p),p.setAttribute("href",`#${u}`),this.updateProperties(a,e),this.#t.set(i,a),{id:i,clipPathId:`url(#${d})`}}drawOutline(e,n){const r=jt.#r++,i=this.#i(),a=jt._svgFactory.createElement("defs");i.append(a);const o=jt._svgFactory.createElement("path");a.append(o);const l=`path_p${this.pageIndex}_${r}`;o.setAttribute("id",l),o.setAttribute("vector-effect","non-scaling-stroke");let u;if(n){const f=jt._svgFactory.createElement("mask");a.append(f),u=`mask_p${this.pageIndex}_${r}`,f.setAttribute("id",u),f.setAttribute("maskUnits","objectBoundingBox");const g=jt._svgFactory.createElement("rect");f.append(g),g.setAttribute("width","1"),g.setAttribute("height","1"),g.setAttribute("fill","white");const m=jt._svgFactory.createElement("use");f.append(m),m.setAttribute("href",`#${l}`),m.setAttribute("stroke","none"),m.setAttribute("fill","black"),m.setAttribute("fill-rule","nonzero"),m.classList.add("mask")}const d=jt._svgFactory.createElement("use");i.append(d),d.setAttribute("href",`#${l}`),u&&d.setAttribute("mask",`url(#${u})`);const p=d.cloneNode();return i.append(p),d.classList.add("mainOutline"),p.classList.add("secondaryOutline"),this.updateProperties(i,e),this.#t.set(r,i),r}finalizeDraw(e,n){this.#n.delete(e),this.updateProperties(e,n)}updateProperties(e,n){if(!n)return;const{root:r,bbox:i,rootClass:a,path:o}=n,l=typeof e=="number"?this.#t.get(e):e;if(l){if(r&&this.#s(l,r),i&&jt.#a(l,i),a){const{classList:u}=l;for(const[d,p]of Object.entries(a))u.toggle(d,p)}if(o){const d=l.firstChild.firstChild;this.#s(d,o)}}}updateParent(e,n){if(n===this)return;const r=this.#t.get(e);r&&(n.#e.append(r),this.#t.delete(e),n.#t.set(e,r))}remove(e){this.#n.delete(e),this.#e!==null&&(this.#t.get(e).remove(),this.#t.delete(e))}destroy(){this.#e=null;for(const e of this.#t.values())e.remove();this.#t.clear(),this.#n.clear()}}globalThis._pdfjsTestingUtils={HighlightOutliner:vw};globalThis.pdfjsLib={AbortException:si,AnnotationEditorLayer:kr,AnnotationEditorParamsType:ze,AnnotationEditorType:Le,AnnotationEditorUIManager:li,AnnotationLayer:BS,AnnotationMode:Lr,AnnotationType:xt,build:aF,ColorPicker:Nn,createValidAbsoluteUrl:wS,DOMSVGFactory:Ll,DrawLayer:jt,FeatureTest:Gt,fetchData:us,getDocument:LS,getFilenameFromUrl:BP,getPdfFilenameFromUrl:UP,getUuid:xS,getXfaPageViewport:$P,GlobalWorkerOptions:Hi,ImageKind:fl,InvalidPDFException:Ed,isDataScheme:Kl,isPdfFile:op,isValidExplicitDest:GP,MathClamp:rn,noContextMenu:Xn,normalizeUnicode:PP,OPS:Rl,OutputScale:fr,PasswordResponses:DP,PDFDataRangeTransport:MS,PDFDateString:_S,PDFWorker:es,PermissionFlag:LP,PixelsPerInch:Ba,RenderingCancelledException:ap,ResponseException:kl,setLayerDimensions:Vi,shadow:$e,SignatureExtractor:Ea,stopEvent:_t,SupportedImageMimeTypes:wd,TextLayer:Nl,TouchManager:Ql,updateUrlHash:SS,Util:Ce,VerbosityLevel:Wl,version:Ol,XfaLayer:PS};const nne=Object.freeze(Object.defineProperty({__proto__:null,AbortException:si,AnnotationEditorLayer:kr,AnnotationEditorParamsType:ze,AnnotationEditorType:Le,AnnotationEditorUIManager:li,AnnotationLayer:BS,AnnotationMode:Lr,AnnotationType:xt,ColorPicker:Nn,DOMSVGFactory:Ll,DrawLayer:jt,FeatureTest:Gt,GlobalWorkerOptions:Hi,ImageKind:fl,InvalidPDFException:Ed,MathClamp:rn,OPS:Rl,OutputScale:fr,PDFDataRangeTransport:MS,PDFDateString:_S,PDFWorker:es,PasswordResponses:DP,PermissionFlag:LP,PixelsPerInch:Ba,RenderingCancelledException:ap,ResponseException:kl,SignatureExtractor:Ea,SupportedImageMimeTypes:wd,TextLayer:Nl,TouchManager:Ql,Util:Ce,VerbosityLevel:Wl,XfaLayer:PS,build:aF,createValidAbsoluteUrl:wS,fetchData:us,getDocument:LS,getFilenameFromUrl:BP,getPdfFilenameFromUrl:UP,getUuid:xS,getXfaPageViewport:$P,isDataScheme:Kl,isPdfFile:op,isValidExplicitDest:GP,noContextMenu:Xn,normalizeUnicode:PP,setLayerDimensions:Vi,shadow:$e,stopEvent:_t,updateUrlHash:SS,version:Ol},Symbol.toStringTag,{value:"Module"})),rne=["onCopy","onCut","onPaste"],ine=["onCompositionEnd","onCompositionStart","onCompositionUpdate"],ane=["onFocus","onBlur"],one=["onInput","onInvalid","onReset","onSubmit"],sne=["onLoad","onError"],lne=["onKeyDown","onKeyPress","onKeyUp"],cne=["onAbort","onCanPlay","onCanPlayThrough","onDurationChange","onEmptied","onEncrypted","onEnded","onError","onLoadedData","onLoadedMetadata","onLoadStart","onPause","onPlay","onPlaying","onProgress","onRateChange","onSeeked","onSeeking","onStalled","onSuspend","onTimeUpdate","onVolumeChange","onWaiting"],une=["onClick","onContextMenu","onDoubleClick","onMouseDown","onMouseEnter","onMouseLeave","onMouseMove","onMouseOut","onMouseOver","onMouseUp"],dne=["onDrag","onDragEnd","onDragEnter","onDragExit","onDragLeave","onDragOver","onDragStart","onDrop"],pne=["onSelect"],fne=["onTouchCancel","onTouchEnd","onTouchMove","onTouchStart"],hne=["onPointerDown","onPointerMove","onPointerUp","onPointerCancel","onGotPointerCapture","onLostPointerCapture","onPointerEnter","onPointerLeave","onPointerOver","onPointerOut"],gne=["onScroll"],mne=["onWheel"],bne=["onAnimationStart","onAnimationEnd","onAnimationIteration"],yne=["onTransitionEnd"],vne=["onToggle"],Ene=["onChange"],wne=[...rne,...ine,...ane,...one,...sne,...lne,...cne,...une,...dne,...pne,...fne,...hne,...gne,...mne,...bne,...yne,...Ene,...vne];function gF(t,e){const n={};for(const r of wne){const i=t[r];i&&(e?n[r]=a=>i(a,e(r)):n[r]=i)}return n}function nc(t){let e=!1;return{promise:new Promise((r,i)=>{t.then(a=>!e&&r(a)).catch(a=>!e&&i(a))}),cancel(){e=!0}}}var Sne="Invariant failed";function Je(t,e){if(!t)throw new Error(Sne)}var OE,N1;function xne(){if(N1)return OE;N1=1;var t=function(){};return OE=t,OE}var Ane=xne();const an=Dl(Ane);var I1=Object.prototype.hasOwnProperty;function O1(t,e,n){for(n of t.keys())if(zo(n,e))return n}function zo(t,e){var n,r,i;if(t===e)return!0;if(t&&e&&(n=t.constructor)===e.constructor){if(n===Date)return t.getTime()===e.getTime();if(n===RegExp)return t.toString()===e.toString();if(n===Array){if((r=t.length)===e.length)for(;r--&&zo(t[r],e[r]););return r===-1}if(n===Set){if(t.size!==e.size)return!1;for(r of t)if(i=r,i&&typeof i=="object"&&(i=O1(e,i),!i)||!e.has(i))return!1;return!0}if(n===Map){if(t.size!==e.size)return!1;for(r of t)if(i=r[0],i&&typeof i=="object"&&(i=O1(e,i),!i)||!zo(r[1],e.get(i)))return!1;return!0}if(n===ArrayBuffer)t=new Uint8Array(t),e=new Uint8Array(e);else if(n===DataView){if((r=t.byteLength)===e.byteLength)for(;r--&&t.getInt8(r)===e.getInt8(r););return r===-1}if(ArrayBuffer.isView(t)){if((r=t.byteLength)===e.byteLength)for(;r--&&t[r]===e[r];);return r===-1}if(!n||typeof t=="object"){r=0;for(n in t)if(I1.call(t,n)&&++r&&!I1.call(e,n)||!(n in e)||!zo(t[n],e[n]))return!1;return Object.keys(e).length===r}}return t!==t&&e!==e}const mF=k.createContext(null);function jo({children:t,type:e}){return N.jsx("div",{className:`react-pdf__message react-pdf__message--${e}`,children:t})}const _ne="noopener noreferrer nofollow";class Tne{constructor(){this.externalLinkEnabled=!0,this.externalLinkRel=void 0,this.externalLinkTarget=void 0,this.isInPresentationMode=!1,this.pdfDocument=void 0,this.pdfViewer=void 0}setDocument(e){this.pdfDocument=e}setViewer(e){this.pdfViewer=e}setExternalLinkRel(e){this.externalLinkRel=e}setExternalLinkTarget(e){this.externalLinkTarget=e}setHistory(){}get pagesCount(){return this.pdfDocument?this.pdfDocument.numPages:0}get page(){return Je(this.pdfViewer),this.pdfViewer.currentPageNumber||0}set page(e){Je(this.pdfViewer),this.pdfViewer.currentPageNumber=e}get rotation(){return 0}set rotation(e){}goToDestination(e){return new Promise(n=>{Je(this.pdfDocument),Je(e),typeof e=="string"?this.pdfDocument.getDestination(e).then(n):Array.isArray(e)?n(e):e.then(n)}).then(n=>{Je(Array.isArray(n));const r=n[0];new Promise(i=>{Je(this.pdfDocument),r instanceof Object?this.pdfDocument.getPageIndex(r).then(a=>{i(a)}).catch(()=>{Je(!1)}):typeof r=="number"?i(r):Je(!1)}).then(i=>{const a=i+1;Je(this.pdfViewer),Je(a>=1&&a<=this.pagesCount),this.pdfViewer.scrollPageIntoView({dest:n,pageIndex:i,pageNumber:a})})})}navigateTo(e){this.goToDestination(e)}goToPage(e){const n=e-1;Je(this.pdfViewer),Je(e>=1&&e<=this.pagesCount),this.pdfViewer.scrollPageIntoView({pageIndex:n,pageNumber:e})}addLinkAttributes(e,n,r){e.href=n,e.rel=this.externalLinkRel||_ne,e.target=r?"_blank":this.externalLinkTarget||""}getDestinationHash(){return"#"}getAnchorUrl(){return"#"}setHash(){}executeNamedAction(){}cachePageRef(){}isPageVisible(){return!0}isPageCached(){return!0}executeSetOCGState(){}}const L1={NEED_PASSWORD:1,INCORRECT_PASSWORD:2},cp=typeof window<"u",bF=cp&&window.location.protocol==="file:";function Cne(t){return typeof t<"u"}function ya(t){return Cne(t)&&t!==null}function Rne(t){return typeof t=="string"}function kne(t){return t instanceof ArrayBuffer}function Nne(t){return Je(cp),t instanceof Blob}function Sw(t){return Rne(t)&&/^data:/.test(t)}function D1(t){Je(Sw(t));const[e="",n=""]=t.split(",");return e.split(";").indexOf("base64")!==-1?atob(n):unescape(n)}function Ine(){return cp&&window.devicePixelRatio||1}const yF="On Chromium based browsers, you can use --allow-file-access-from-files flag for debugging purposes.";function M1(){an(!bF,`Loading PDF as base64 strings/URLs may not work on protocols other than HTTP/HTTPS. ${yF}`)}function One(){an(!bF,`Loading PDF.js worker may not work on protocols other than HTTP/HTTPS. ${yF}`)}function $a(t){t?.cancel&&t.cancel()}function xw(t,e){return Object.defineProperty(t,"width",{get(){return this.view[2]*e},configurable:!0}),Object.defineProperty(t,"height",{get(){return this.view[3]*e},configurable:!0}),Object.defineProperty(t,"originalWidth",{get(){return this.view[2]},configurable:!0}),Object.defineProperty(t,"originalHeight",{get(){return this.view[3]},configurable:!0}),t}function Lne(t){return t.name==="RenderingCancelledException"}function Dne(t){return new Promise((e,n)=>{const r=new FileReader;r.onload=()=>{if(!r.result)return n(new Error("Error while reading a file."));e(r.result)},r.onerror=i=>{if(!i.target)return n(new Error("Error while reading a file."));const{error:a}=i.target;if(!a)return n(new Error("Error while reading a file."));switch(a.code){case a.NOT_FOUND_ERR:return n(new Error("Error while reading a file: File not found."));case a.SECURITY_ERR:return n(new Error("Error while reading a file: Security error."));case a.ABORT_ERR:return n(new Error("Error while reading a file: Aborted."));default:return n(new Error("Error while reading a file."))}},r.readAsArrayBuffer(t)})}function Mne(t,e){switch(e.type){case"RESOLVE":return{value:e.value,error:void 0};case"REJECT":return{value:!1,error:e.error};case"RESET":return{value:void 0,error:void 0};default:return t}}function ts(){return k.useReducer(Mne,{value:void 0,error:void 0})}var P1=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]]);return n};const{PDFDataRangeTransport:Pne}=nne,Fne=(t,e)=>{switch(e){case L1.NEED_PASSWORD:{const n=prompt("Enter the password to open this PDF file.");t(n);break}case L1.INCORRECT_PASSWORD:{const n=prompt("Invalid password. Please try again.");t(n);break}}};function F1(t){return typeof t=="object"&&t!==null&&("data"in t||"range"in t||"url"in t)}const Bne=k.forwardRef(function(e,n){var{children:r,className:i,error:a="Failed to load PDF file.",externalLinkRel:o,externalLinkTarget:l,file:u,inputRef:d,imageResourcesPath:p,loading:f="Loading PDF…",noData:g="No PDF file specified.",onItemClick:m,onLoadError:v,onLoadProgress:b,onLoadSuccess:E,onPassword:S=Fne,onSourceError:_,onSourceSuccess:w,options:A,renderMode:R,rotate:C,scale:T}=e,O=P1(e,["children","className","error","externalLinkRel","externalLinkTarget","file","inputRef","imageResourcesPath","loading","noData","onItemClick","onLoadError","onLoadProgress","onLoadSuccess","onPassword","onSourceError","onSourceSuccess","options","renderMode","rotate","scale"]);const[L,z]=ts(),{value:$,error:G}=L,[W,P]=ts(),{value:j,error:B}=W,F=k.useRef(new Tne),D=k.useRef([]),q=k.useRef(void 0),K=k.useRef(void 0);u&&u!==q.current&&F1(u)&&(an(!zo(u,q.current),`File prop passed to <Document /> changed, but it's equal to previous one. This might result in unnecessary reloads. Consider memoizing the value passed to "file" prop.`),q.current=u),A&&A!==K.current&&(an(!zo(A,K.current),`Options prop passed to <Document /> changed, but it's equal to previous one. This might result in unnecessary reloads. Consider memoizing the value passed to "options" prop.`),K.current=A);const U=k.useRef({scrollPageIntoView:he=>{const{dest:xe,pageNumber:Ae,pageIndex:Pe=Ae-1}=he;if(m){m({dest:xe,pageIndex:Pe,pageNumber:Ae});return}const Fe=D.current[Pe];if(Fe){Fe.scrollIntoView();return}an(!1,`An internal link leading to page ${Ae} was clicked, but neither <Document> was provided with onItemClick nor it was able to find the page within itself. Either provide onItemClick to <Document> and handle navigating by yourself or ensure that all pages are rendered within <Document>.`)}});k.useImperativeHandle(n,()=>({linkService:F,pages:D,viewer:U}),[]);function H(){w&&w()}function V(){G&&(an(!1,G.toString()),_&&_(G))}function Z(){z({type:"RESET"})}k.useEffect(Z,[u,z]);const te=k.useCallback(async()=>{if(!u)return null;if(typeof u=="string")return Sw(u)?{data:D1(u)}:(M1(),{url:u});if(u instanceof Pne)return{range:u};if(kne(u))return{data:u};if(cp&&Nne(u))return{data:await Dne(u)};if(Je(typeof u=="object"),Je(F1(u)),"url"in u&&typeof u.url=="string"){if(Sw(u.url)){const{url:he}=u,xe=P1(u,["url"]),Ae=D1(he);return Object.assign({data:Ae},xe)}M1()}return u},[u]);k.useEffect(()=>{const he=nc(te());return he.promise.then(xe=>{z({type:"RESOLVE",value:xe})}).catch(xe=>{z({type:"REJECT",error:xe})}),()=>{$a(he)}},[te,z]),k.useEffect(()=>{if(!(typeof $>"u")){if($===!1){V();return}H()}},[$]);function re(){j&&(E&&E(j),D.current=new Array(j.numPages),F.current.setDocument(j))}function X(){B&&(an(!1,B.toString()),v&&v(B))}k.useEffect(function(){P({type:"RESET"})},[P,$]),k.useEffect(function(){if(!$)return;const xe=A?Object.assign(Object.assign({},$),A):$,Ae=LS(xe);b&&(Ae.onProgress=b),S&&(Ae.onPassword=S);const Pe=Ae,Fe=Pe.promise.then(Ct=>{P({type:"RESOLVE",value:Ct})}).catch(Ct=>{Pe.destroyed||P({type:"REJECT",error:Ct})});return()=>{Fe.finally(()=>Pe.destroy())}},[A,P,$]),k.useEffect(()=>{if(!(typeof j>"u")){if(j===!1){X();return}re()}},[j]),k.useEffect(function(){F.current.setViewer(U.current),F.current.setExternalLinkRel(o),F.current.setExternalLinkTarget(l)},[o,l]);const ee=k.useCallback((he,xe)=>{D.current[he]=xe},[]),ae=k.useCallback(he=>{delete D.current[he]},[]),se=k.useMemo(()=>({imageResourcesPath:p,linkService:F.current,onItemClick:m,pdf:j,registerPage:ee,renderMode:R,rotate:C,scale:T,unregisterPage:ae}),[p,m,j,ee,R,C,T,ae]),pe=k.useMemo(()=>gF(O,()=>j),[O,j]);function ce(){return N.jsx(mF.Provider,{value:se,children:r})}function le(){return u?j==null?N.jsx(jo,{type:"loading",children:typeof f=="function"?f():f}):j===!1?N.jsx(jo,{type:"error",children:typeof a=="function"?a():a}):ce():N.jsx(jo,{type:"no-data",children:typeof g=="function"?g():g})}return N.jsx("div",Object.assign({className:ns("react-pdf__Document",i),ref:d},pe,{children:le()}))});function vF(){return k.useContext(mF)}function EF(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=t.filter(Boolean);if(n.length<=1){var r=n[0];return r||null}return function(a){for(var o=0,l=n;o<l.length;o++){var u=l[o];typeof u=="function"?u(a):u&&(u.current=a)}}}const wF=k.createContext(null),SF={Document:null,DocumentFragment:null,Part:"group",Sect:"group",Div:"group",Aside:"note",NonStruct:"none",P:null,H:"heading",Title:null,FENote:"note",Sub:"group",Lbl:null,Span:null,Em:null,Strong:null,Link:"link",Annot:"note",Form:"form",Ruby:null,RB:null,RT:null,RP:null,Warichu:null,WT:null,WP:null,L:"list",LI:"listitem",LBody:null,Table:"table",TR:"row",TH:"columnheader",TD:"cell",THead:"columnheader",TBody:null,TFoot:null,Caption:null,Figure:"figure",Formula:null,Artifact:null},Une=/^H(\d+)$/;function $ne(t){return t in SF}function up(t){return"children"in t}function xF(t){return up(t)?t.children.length===1&&0 in t.children&&"id"in t.children[0]:!1}function zne(t){const e={};if(up(t)){const{role:n}=t,r=n.match(Une);if(r)e.role="heading",e["aria-level"]=Number(r[1]);else if($ne(n)){const i=SF[n];i&&(e.role=i)}}return e}function AF(t){const e={};if(up(t)){if(t.alt!==void 0&&(e["aria-label"]=t.alt),t.lang!==void 0&&(e.lang=t.lang),xF(t)){const[n]=t.children;if(n){const r=AF(n);return Object.assign(Object.assign({},e),r)}}}else"id"in t&&(e["aria-owns"]=t.id);return e}function jne(t){return t?Object.assign(Object.assign({},zne(t)),AF(t)):null}function _F({className:t,node:e}){const n=k.useMemo(()=>jne(e),[e]),r=k.useMemo(()=>!up(e)||xF(e)?null:e.children.map((i,a)=>N.jsx(_F,{node:i},a)),[e]);return N.jsx("span",Object.assign({className:t},n,{children:r}))}function dp(){return k.useContext(wF)}function Hne(){const t=dp();Je(t);const{onGetStructTreeError:e,onGetStructTreeSuccess:n}=t,[r,i]=ts(),{value:a,error:o}=r,{customTextRenderer:l,page:u}=t;function d(){a&&n&&n(a)}function p(){o&&(an(!1,o.toString()),e&&e(o))}return k.useEffect(function(){i({type:"RESET"})},[i,u]),k.useEffect(function(){if(l||!u)return;const g=nc(u.getStructTree()),m=g;return g.promise.then(v=>{i({type:"RESOLVE",value:v})}).catch(v=>{i({type:"REJECT",error:v})}),()=>$a(m)},[l,u,i]),k.useEffect(()=>{if(a!==void 0){if(a===!1){p();return}d()}},[a]),a?N.jsx(_F,{className:"react-pdf__Page__structTree structTree",node:a}):null}const B1=Lr;function Gne(t){const e=dp();Je(e);const n=Object.assign(Object.assign({},e),t),{_className:r,canvasBackground:i,devicePixelRatio:a=Ine(),onRenderError:o,onRenderSuccess:l,page:u,renderForms:d,renderTextLayer:p,rotate:f,scale:g}=n,{canvasRef:m}=t;Je(u);const v=k.useRef(null);function b(){u&&l&&l(xw(u,g))}function E(A){Lne(A)||(an(!1,A.toString()),o&&o(A))}const S=k.useMemo(()=>u.getViewport({scale:g*a,rotation:f}),[a,u,f,g]),_=k.useMemo(()=>u.getViewport({scale:g,rotation:f}),[u,f,g]);k.useEffect(function(){if(!u)return;u.cleanup();const{current:R}=v;if(!R)return;R.width=S.width,R.height=S.height,R.style.width=`${Math.floor(_.width)}px`,R.style.height=`${Math.floor(_.height)}px`,R.style.visibility="hidden";const C={annotationMode:d?B1.ENABLE_FORMS:B1.ENABLE,canvasContext:R.getContext("2d",{alpha:!1}),viewport:S};i&&(C.background=i);const T=u.render(C),O=T;return T.promise.then(()=>{R.style.visibility="",b()}).catch(E),()=>$a(O)},[i,u,d,S,_]);const w=k.useCallback(()=>{const{current:A}=v;A&&(A.width=0,A.height=0)},[]);return k.useEffect(()=>w,[w]),N.jsx("canvas",{className:`${r}__canvas`,dir:"ltr",ref:EF(m,v),style:{display:"block",userSelect:"none"},children:p?N.jsx(Hne,{}):null})}function qne(t){return"str"in t}function Vne(){const t=dp();Je(t);const{customTextRenderer:e,onGetTextError:n,onGetTextSuccess:r,onRenderTextLayerError:i,onRenderTextLayerSuccess:a,page:o,pageIndex:l,pageNumber:u,rotate:d,scale:p}=t;Je(o);const[f,g]=ts(),{value:m,error:v}=f,b=k.useRef(null);an(Number.parseInt(window.getComputedStyle(document.body).getPropertyValue("--react-pdf-text-layer"),10)===1,"TextLayer styles not found. Read more: https://github.com/wojtekmaj/react-pdf#support-for-text-layer");function E(){m&&r&&r(m)}function S(){v&&(an(!1,v.toString()),n&&n(v))}k.useEffect(function(){g({type:"RESET"})},[o,g]),k.useEffect(function(){if(!o)return;const O=nc(o.getTextContent()),L=O;return O.promise.then(z=>{g({type:"RESOLVE",value:z})}).catch(z=>{g({type:"REJECT",error:z})}),()=>$a(L)},[o,g]),k.useEffect(()=>{if(m!==void 0){if(m===!1){S();return}E()}},[m]);const _=k.useCallback(()=>{a&&a()},[a]),w=k.useCallback(T=>{an(!1,T.toString()),i&&i(T)},[i]);function A(){const T=b.current;T&&T.classList.add("selecting")}function R(){const T=b.current;T&&T.classList.remove("selecting")}const C=k.useMemo(()=>o.getViewport({scale:p,rotation:d}),[o,d,p]);return k.useLayoutEffect(function(){if(!o||!m)return;const{current:O}=b;if(!O)return;O.innerHTML="";const L=o.streamTextContent({includeMarkedContent:!0}),z={container:O,textContentSource:L,viewport:C},$=new Nl(z),G=$;return $.render().then(()=>{const W=document.createElement("div");W.className="endOfContent",O.append(W);const P=O.querySelectorAll('[role="presentation"]');if(e){let j=0;m.items.forEach((B,F)=>{if(!qne(B))return;const D=P[j];if(!D)return;const q=e(Object.assign({pageIndex:l,pageNumber:u,itemIndex:F},B));D.innerHTML=q,j+=B.str&&B.hasEOL?2:1})}_()}).catch(w),()=>$a(G)},[e,w,_,o,l,u,m,C]),N.jsx("div",{className:ns("react-pdf__Page__textContent","textLayer"),onMouseUp:R,onMouseDown:A,ref:b})}function Wne(){const t=vF(),e=dp();Je(e);const n=Object.assign(Object.assign({},t),e),{imageResourcesPath:r,linkService:i,onGetAnnotationsError:a,onGetAnnotationsSuccess:o,onRenderAnnotationLayerError:l,onRenderAnnotationLayerSuccess:u,page:d,pdf:p,renderForms:f,rotate:g,scale:m=1}=n;Je(p),Je(d),Je(i);const[v,b]=ts(),{value:E,error:S}=v,_=k.useRef(null);an(Number.parseInt(window.getComputedStyle(document.body).getPropertyValue("--react-pdf-annotation-layer"),10)===1,"AnnotationLayer styles not found. Read more: https://github.com/wojtekmaj/react-pdf#support-for-annotations");function w(){E&&o&&o(E)}function A(){S&&(an(!1,S.toString()),a&&a(S))}k.useEffect(function(){b({type:"RESET"})},[b,d]),k.useEffect(function(){if(!d)return;const L=nc(d.getAnnotations()),z=L;return L.promise.then($=>{b({type:"RESOLVE",value:$})}).catch($=>{b({type:"REJECT",error:$})}),()=>{$a(z)}},[b,d]),k.useEffect(()=>{if(E!==void 0){if(E===!1){A();return}w()}},[E]);function R(){u&&u()}function C(O){an(!1,`${O}`),l&&l(O)}const T=k.useMemo(()=>d.getViewport({scale:m,rotation:g}),[d,g,m]);return k.useEffect(function(){if(!p||!d||!i||!E)return;const{current:L}=_;if(!L)return;const z=T.clone({dontFlip:!0}),$={accessibilityManager:null,annotationCanvasMap:null,annotationEditorUIManager:null,div:L,l10n:null,page:d,structTreeLayer:null,viewport:z},G={annotations:E,annotationStorage:p.annotationStorage,div:L,imageResourcesPath:r,linkService:i,page:d,renderForms:f,viewport:z};L.innerHTML="";try{new BS($).render(G),R()}catch(W){C(W)}return()=>{}},[E,r,i,d,p,f,T]),N.jsx("div",{className:ns("react-pdf__Page__annotations","annotationLayer"),ref:_})}var Yne=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]]);return n};const U1=1;function Xne(t){const e=vF(),n=Object.assign(Object.assign({},e),t),{_className:r="react-pdf__Page",_enableRegisterUnregisterPage:i=!0,canvasBackground:a,canvasRef:o,children:l,className:u,customRenderer:d,customTextRenderer:p,devicePixelRatio:f,error:g="Failed to load the page.",height:m,inputRef:v,loading:b="Loading page…",noData:E="No page specified.",onGetAnnotationsError:S,onGetAnnotationsSuccess:_,onGetStructTreeError:w,onGetStructTreeSuccess:A,onGetTextError:R,onGetTextSuccess:C,onLoadError:T,onLoadSuccess:O,onRenderAnnotationLayerError:L,onRenderAnnotationLayerSuccess:z,onRenderError:$,onRenderSuccess:G,onRenderTextLayerError:W,onRenderTextLayerSuccess:P,pageIndex:j,pageNumber:B,pdf:F,registerPage:D,renderAnnotationLayer:q=!0,renderForms:K=!1,renderMode:U="canvas",renderTextLayer:H=!0,rotate:V,scale:Z=U1,unregisterPage:te,width:re}=n,X=Yne(n,["_className","_enableRegisterUnregisterPage","canvasBackground","canvasRef","children","className","customRenderer","customTextRenderer","devicePixelRatio","error","height","inputRef","loading","noData","onGetAnnotationsError","onGetAnnotationsSuccess","onGetStructTreeError","onGetStructTreeSuccess","onGetTextError","onGetTextSuccess","onLoadError","onLoadSuccess","onRenderAnnotationLayerError","onRenderAnnotationLayerSuccess","onRenderError","onRenderSuccess","onRenderTextLayerError","onRenderTextLayerSuccess","pageIndex","pageNumber","pdf","registerPage","renderAnnotationLayer","renderForms","renderMode","renderTextLayer","rotate","scale","unregisterPage","width"]),[ee,ae]=ts(),{value:se,error:pe}=ee,ce=k.useRef(null);Je(F);const le=ya(B)?B-1:j??null,he=B??(ya(j)?j+1:null),xe=V??(se?se.rotate:null),Ae=k.useMemo(()=>{if(!se)return null;let He=1;const qe=Z??U1;if(re||m){const kt=se.getViewport({scale:1,rotation:xe});re?He=re/kt.width:m&&(He=m/kt.height)}return qe*He},[m,se,xe,Z,re]);k.useEffect(function(){return()=>{ya(le)&&i&&te&&te(le)}},[i,F,le,te]);function Pe(){if(O){if(!se||!Ae)return;O(xw(se,Ae))}if(i&&D){if(!ya(le)||!ce.current)return;D(le,ce.current)}}function Fe(){pe&&(an(!1,pe.toString()),T&&T(pe))}k.useEffect(function(){ae({type:"RESET"})},[ae,F,le]),k.useEffect(function(){if(!F||!he)return;const qe=nc(F.getPage(he)),kt=qe;return qe.promise.then(Bt=>{ae({type:"RESOLVE",value:Bt})}).catch(Bt=>{ae({type:"REJECT",error:Bt})}),()=>$a(kt)},[ae,F,he]),k.useEffect(()=>{if(se!==void 0){if(se===!1){Fe();return}Pe()}},[se,Ae]);const Ct=k.useMemo(()=>se&&ya(le)&&he&&ya(xe)&&ya(Ae)?{_className:r,canvasBackground:a,customTextRenderer:p,devicePixelRatio:f,onGetAnnotationsError:S,onGetAnnotationsSuccess:_,onGetStructTreeError:w,onGetStructTreeSuccess:A,onGetTextError:R,onGetTextSuccess:C,onRenderAnnotationLayerError:L,onRenderAnnotationLayerSuccess:z,onRenderError:$,onRenderSuccess:G,onRenderTextLayerError:W,onRenderTextLayerSuccess:P,page:se,pageIndex:le,pageNumber:he,renderForms:K,renderTextLayer:H,rotate:xe,scale:Ae}:null,[r,a,p,f,S,_,w,A,R,C,L,z,$,G,W,P,se,le,he,K,H,xe,Ae]),vt=k.useMemo(()=>gF(X,()=>se&&(Ae?xw(se,Ae):void 0)),[X,se,Ae]),et=`${le}@${Ae}/${xe}`;function wt(){switch(U){case"custom":return Je(d),N.jsx(d,{},`${et}_custom`);case"none":return null;case"canvas":default:return N.jsx(Gne,{canvasRef:o},`${et}_canvas`)}}function Xt(){return H?N.jsx(Vne,{},`${et}_text`):null}function Kt(){return q?N.jsx(Wne,{},`${et}_annotations`):null}function ft(){return N.jsxs(wF.Provider,{value:Ct,children:[wt(),Xt(),Kt(),l]})}function Rt(){return he?F===null||se===void 0||se===null?N.jsx(jo,{type:"loading",children:typeof b=="function"?b():b}):F===!1||se===!1?N.jsx(jo,{type:"error",children:typeof g=="function"?g():g}):ft():N.jsx(jo,{type:"no-data",children:typeof E=="function"?E():E})}return N.jsx("div",Object.assign({className:ns(r,u),"data-page-number":he,ref:EF(v,ce),style:{"--scale-round-x":"1px","--scale-round-y":"1px","--scale-factor":"1","--user-unit":`${Ae}`,"--total-scale-factor":"calc(var(--scale-factor) * var(--user-unit))",backgroundColor:a||"white",position:"relative",minWidth:"min-content",minHeight:"min-content"}},vt,{children:Rt()}))}One();Hi.workerSrc="pdf.worker.mjs";typeof window<"u"&&(Hi.workerSrc=`//unpkg.com/pdfjs-dist@${Ol}/build/pdf.worker.min.mjs`);Gw(()=>Promise.resolve().then(()=>tre),[]);Gw(()=>Promise.resolve().then(()=>nre),void 0);var Kne={cMapUrl:`https://unpkg.com/pdfjs-dist@${Ol}/cmaps/`,wasmUrl:`https://unpkg.com/pdfjs-dist@${Ol}/wasm/`},Zne=10*1024*1024,$1="document.pdf",Qne=({fileName:t,url:e,onDownload:n,onRemove:r,highlight:i,toolbarClassName:a})=>{var o;const[l,u]=k.useState(),[d,p]=k.useState(1),[f,g]=k.useState(1),[m,v]=k.useState(null),[b,E]=k.useState(!1),[S,_]=k.useState(0),[w,A]=k.useState(!0),R=k.useRef(null),C=k.useRef({}),T=k.useRef(!1),[O,L]=k.useState({}),[z,$]=k.useState(!1),G=[{id:"highlight",x:i?.x||0,y:i?.y||0,width:i?.width||0,height:i?.height||0,color:"rgba(255, 215, 0, 0.25)"}];function W({numPages:H}){u(H),_(0),A(!0)}function P(){_(H=>{const V=H+1;return V===l&&A(!1),V})}k.useEffect(()=>{if(!i||!l)return;C.current[i.page]&&(D(i.page),$(!0))},[i,l]);const j=H=>{const V=H.getViewport({scale:1});if(L(Z=>Wt(je({},Z),{[H.pageNumber]:{width:V.width,height:V.height}})),!T.current&&H.pageNumber===1&&R.current){const te=R.current.clientHeight/V.height;g(te),T.current=!0}},B=()=>{z&&$(!1)};k.useEffect(()=>{const H=()=>{if(!R.current)return;const Z=R.current.getBoundingClientRect(),te=Z.top+Z.height/2;let re=1,X=1/0;Object.entries(C.current).forEach(([ee,ae])=>{if(ae){const se=ae.getBoundingClientRect(),pe=se.top+se.height/2,ce=Math.abs(pe-te);ce<X&&(X=ce,re=parseInt(ee))}}),p(re)},V=R.current;if(V)return V.addEventListener("scroll",H),()=>V.removeEventListener("scroll",H)},[l]);const F=k.useRef(null);k.useEffect(()=>F.current===e?void 0:(F.current=e,(async()=>{E(!0);const Z=await(await fetch(e)).blob();v(new File([Z],$1,{type:"application/pdf"})),E(!1)})(),()=>{v(null)}),[e]);const D=H=>{const V=C.current[H];V&&R.current&&V.scrollIntoView({behavior:"instant",block:"center"})};k.useEffect(()=>{const H=R.current;if(!H)return;const V=Z=>{Z.key==="ArrowLeft"?(Z.preventDefault(),d>1&&D(d-1)):Z.key==="ArrowRight"?(Z.preventDefault(),d<(l||1)&&D(d+1)):Z.key==="="||Z.key==="+"?(Z.preventDefault(),g(te=>Math.min(te+.25,3))):Z.key==="-"&&(Z.preventDefault(),g(te=>Math.max(te-.25,.5)))};return H.addEventListener("keydown",V),H.tabIndex=0,()=>{H.removeEventListener("keydown",V)}},[d,l]);const q=()=>{if(n)n();else if(m){const H=URL.createObjectURL(m),V=document.createElement("a");V.href=H,V.download=m.name,document.body.appendChild(V),V.click(),document.body.removeChild(V),URL.revokeObjectURL(H)}else window.open(e,"_blank")},K=()=>{p(1),D(1)},U=()=>{var H;document.fullscreenElement?document.exitFullscreen():(H=R.current)==null||H.requestFullscreen()};return b?N.jsx("div",{className:"relative h-full flex items-center justify-center bg-gray-50",children:N.jsxs("div",{className:"text-center",children:[N.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900 mx-auto mb-2"}),N.jsx("p",{className:"text-gray-600",children:"Loading PDF..."})]})}):N.jsxs("div",{className:"relative h-full flex flex-col",children:[w&&m&&m.size>Zne&&N.jsx(Jne,{renderedPages:S,numPages:l}),l&&N.jsxs(N.Fragment,{children:[N.jsx(WH,{fileName:(o=t??m?.name)!=null?o:$1,currentPage:d,totalPages:l,scale:f,onPageChange:D,onScaleChange:g,onDownload:q,onRemove:r,onReset:K,onFullscreen:U,className:a}),N.jsx("div",{className:"h-3 bg-[#F3F3F3]"})]}),N.jsx("div",{ref:R,className:"overflow-auto h-full bg-[#F3F3F3] rounded-lg flex-1 min-h-0",children:N.jsx(Bne,{file:m,onLoadSuccess:W,loading:b,options:Kne,children:Array.from(new Array(l),(H,V)=>N.jsx("div",{ref:Z=>{C.current[V+1]=Z},className:"mb-4 flex justify-center",children:N.jsxs("div",{className:"relative inline-block",children:[N.jsx(Xne,{pageNumber:V+1,scale:f,renderTextLayer:!0,renderAnnotationLayer:!0,onLoadSuccess:j,onClick:B,onRenderSuccess:P}),i&&z&&i.page===V+1&&O[V+1]&&N.jsx(VH,{boundingBoxes:G,zoom:f,containerWidth:O[V+1].width,containerHeight:O[V+1].height})]})},`page_${V+1}`))})})]})};function Jne({renderedPages:t,numPages:e}){return N.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-50 bg-opacity-90 z-50",children:N.jsxs("div",{className:"bg-white shadow-lg rounded-2xl p-6 w-80 text-center",children:[N.jsx("div",{className:"flex justify-center mb-4",children:N.jsx("div",{className:"animate-spin rounded-full h-10 w-10 border-4 border-primary border-t-transparent"})}),N.jsx("h2",{className:"text-lg font-semibold text-gray-800 mb-2",children:"Rendering PDF…"}),N.jsxs("p",{className:"text-sm text-gray-600 mb-3",children:["Page ",t," of ",e]}),N.jsx("div",{className:"w-full bg-gray-200 rounded-full h-2.5 mb-4",children:N.jsx("div",{className:"bg-primary h-2.5 rounded-full transition-all duration-300",style:{width:e&&e>0?`${Math.round(t/e*100)}%`:"0%"}})}),N.jsx("p",{className:"text-xs text-gray-500",children:"Large PDFs or those with heavy images may take longer to render."})]})})}const ere=Object.freeze(Object.defineProperty({__proto__:null,PdfPreviewImpl:Qne},Symbol.toStringTag,{value:"Module"})),tre=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),nre=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));
|
|
284
|
+
`)){const o=document.createElement("div");o.append(a?document.createTextNode(a):document.createElement("br")),n.append(o)}const i=Ft._internalPadding*this.parentScale;return e.updateEdited({rect:this.getRect(i,i),popupContent:this.#t}),n}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}}class ye{static PRECISION=1e-4;toSVGPath(){Qe("Abstract method `toSVGPath` must be implemented.")}get box(){Qe("Abstract getter `box` must be implemented.")}serialize(e,n){Qe("Abstract method `serialize` must be implemented.")}static _rescale(e,n,r,i,a,o){o||=new Float32Array(e.length);for(let l=0,u=e.length;l<u;l+=2)o[l]=n+e[l]*i,o[l+1]=r+e[l+1]*a;return o}static _rescaleAndSwap(e,n,r,i,a,o){o||=new Float32Array(e.length);for(let l=0,u=e.length;l<u;l+=2)o[l]=n+e[l+1]*i,o[l+1]=r+e[l]*a;return o}static _translate(e,n,r,i){i||=new Float32Array(e.length);for(let a=0,o=e.length;a<o;a+=2)i[a]=n+e[a],i[a+1]=r+e[a+1];return i}static svgRound(e){return Math.round(e*1e4)}static _normalizePoint(e,n,r,i,a){switch(a){case 90:return[1-n/r,e/i];case 180:return[1-e/r,1-n/i];case 270:return[n/r,1-e/i];default:return[e/r,n/i]}}static _normalizePagePoint(e,n,r){switch(r){case 90:return[1-n,e];case 180:return[1-e,1-n];case 270:return[n,1-e];default:return[e,n]}}static createBezierPoints(e,n,r,i,a,o){return[(e+5*r)/6,(n+5*i)/6,(5*r+a)/6,(5*i+o)/6,(r+a)/2,(i+o)/2]}}class Sa{#e;#t=[];#n;#r;#a=[];#i=new Float32Array(18);#l;#s;#d;#c;#p;#u;#f=[];static#o=8;static#h=2;static#m=Sa.#o+Sa.#h;constructor({x:e,y:n},r,i,a,o,l=0){this.#e=r,this.#u=a*i,this.#r=o,this.#i.set([NaN,NaN,NaN,NaN,e,n],6),this.#n=l,this.#c=Sa.#o*i,this.#d=Sa.#m*i,this.#p=i,this.#f.push(e,n)}isEmpty(){return isNaN(this.#i[8])}#g(){const e=this.#i.subarray(4,6),n=this.#i.subarray(16,18),[r,i,a,o]=this.#e;return[(this.#l+(e[0]-n[0])/2-r)/a,(this.#s+(e[1]-n[1])/2-i)/o,(this.#l+(n[0]-e[0])/2-r)/a,(this.#s+(n[1]-e[1])/2-i)/o]}add({x:e,y:n}){this.#l=e,this.#s=n;const[r,i,a,o]=this.#e;let[l,u,d,p]=this.#i.subarray(8,12);const f=e-d,g=n-p,m=Math.hypot(f,g);if(m<this.#d)return!1;const v=m-this.#c,b=v/m,E=b*f,S=b*g;let _=l,w=u;l=d,u=p,d+=E,p+=S,this.#f?.push(e,n);const A=-S/v,R=E/v,C=A*this.#u,T=R*this.#u;return this.#i.set(this.#i.subarray(2,8),0),this.#i.set([d+C,p+T],4),this.#i.set(this.#i.subarray(14,18),12),this.#i.set([d-C,p-T],16),isNaN(this.#i[6])?(this.#a.length===0&&(this.#i.set([l+C,u+T],2),this.#a.push(NaN,NaN,NaN,NaN,(l+C-r)/a,(u+T-i)/o),this.#i.set([l-C,u-T],14),this.#t.push(NaN,NaN,NaN,NaN,(l-C-r)/a,(u-T-i)/o)),this.#i.set([_,w,l,u,d,p],6),!this.isEmpty()):(this.#i.set([_,w,l,u,d,p],6),Math.abs(Math.atan2(w-u,_-l)-Math.atan2(S,E))<Math.PI/2?([l,u,d,p]=this.#i.subarray(2,6),this.#a.push(NaN,NaN,NaN,NaN,((l+d)/2-r)/a,((u+p)/2-i)/o),[l,u,_,w]=this.#i.subarray(14,18),this.#t.push(NaN,NaN,NaN,NaN,((_+l)/2-r)/a,((w+u)/2-i)/o),!0):([_,w,l,u,d,p]=this.#i.subarray(0,6),this.#a.push(((_+5*l)/6-r)/a,((w+5*u)/6-i)/o,((5*l+d)/6-r)/a,((5*u+p)/6-i)/o,((l+d)/2-r)/a,((u+p)/2-i)/o),[d,p,l,u,_,w]=this.#i.subarray(12,18),this.#t.push(((_+5*l)/6-r)/a,((w+5*u)/6-i)/o,((5*l+d)/6-r)/a,((5*u+p)/6-i)/o,((l+d)/2-r)/a,((u+p)/2-i)/o),!0))}toSVGPath(){if(this.isEmpty())return"";const e=this.#a,n=this.#t;if(isNaN(this.#i[6])&&!this.isEmpty())return this.#b();const r=[];r.push(`M${e[4]} ${e[5]}`);for(let i=6;i<e.length;i+=6)isNaN(e[i])?r.push(`L${e[i+4]} ${e[i+5]}`):r.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);this.#v(r);for(let i=n.length-6;i>=6;i-=6)isNaN(n[i])?r.push(`L${n[i+4]} ${n[i+5]}`):r.push(`C${n[i]} ${n[i+1]} ${n[i+2]} ${n[i+3]} ${n[i+4]} ${n[i+5]}`);return this.#y(r),r.join(" ")}#b(){const[e,n,r,i]=this.#e,[a,o,l,u]=this.#g();return`M${(this.#i[2]-e)/r} ${(this.#i[3]-n)/i} L${(this.#i[4]-e)/r} ${(this.#i[5]-n)/i} L${a} ${o} L${l} ${u} L${(this.#i[16]-e)/r} ${(this.#i[17]-n)/i} L${(this.#i[14]-e)/r} ${(this.#i[15]-n)/i} Z`}#y(e){const n=this.#t;e.push(`L${n[4]} ${n[5]} Z`)}#v(e){const[n,r,i,a]=this.#e,o=this.#i.subarray(4,6),l=this.#i.subarray(16,18),[u,d,p,f]=this.#g();e.push(`L${(o[0]-n)/i} ${(o[1]-r)/a} L${u} ${d} L${p} ${f} L${(l[0]-n)/i} ${(l[1]-r)/a}`)}newFreeDrawOutline(e,n,r,i,a,o){return new fF(e,n,r,i,a,o)}getOutlines(){const e=this.#a,n=this.#t,r=this.#i,[i,a,o,l]=this.#e,u=new Float32Array((this.#f?.length??0)+2);for(let f=0,g=u.length-2;f<g;f+=2)u[f]=(this.#f[f]-i)/o,u[f+1]=(this.#f[f+1]-a)/l;if(u[u.length-2]=(this.#l-i)/o,u[u.length-1]=(this.#s-a)/l,isNaN(r[6])&&!this.isEmpty())return this.#w(u);const d=new Float32Array(this.#a.length+24+this.#t.length);let p=e.length;for(let f=0;f<p;f+=2){if(isNaN(e[f])){d[f]=d[f+1]=NaN;continue}d[f]=e[f],d[f+1]=e[f+1]}p=this.#_(d,p);for(let f=n.length-6;f>=6;f-=6)for(let g=0;g<6;g+=2){if(isNaN(n[f+g])){d[p]=d[p+1]=NaN,p+=2;continue}d[p]=n[f+g],d[p+1]=n[f+g+1],p+=2}return this.#x(d,p),this.newFreeDrawOutline(d,u,this.#e,this.#p,this.#n,this.#r)}#w(e){const n=this.#i,[r,i,a,o]=this.#e,[l,u,d,p]=this.#g(),f=new Float32Array(36);return f.set([NaN,NaN,NaN,NaN,(n[2]-r)/a,(n[3]-i)/o,NaN,NaN,NaN,NaN,(n[4]-r)/a,(n[5]-i)/o,NaN,NaN,NaN,NaN,l,u,NaN,NaN,NaN,NaN,d,p,NaN,NaN,NaN,NaN,(n[16]-r)/a,(n[17]-i)/o,NaN,NaN,NaN,NaN,(n[14]-r)/a,(n[15]-i)/o],0),this.newFreeDrawOutline(f,e,this.#e,this.#p,this.#n,this.#r)}#x(e,n){const r=this.#t;return e.set([NaN,NaN,NaN,NaN,r[4],r[5]],n),n+=6}#_(e,n){const r=this.#i.subarray(4,6),i=this.#i.subarray(16,18),[a,o,l,u]=this.#e,[d,p,f,g]=this.#g();return e.set([NaN,NaN,NaN,NaN,(r[0]-a)/l,(r[1]-o)/u,NaN,NaN,NaN,NaN,d,p,NaN,NaN,NaN,NaN,f,g,NaN,NaN,NaN,NaN,(i[0]-a)/l,(i[1]-o)/u],n),n+=24}}class fF extends ye{#e;#t=new Float32Array(4);#n;#r;#a;#i;#l;constructor(e,n,r,i,a,o){super(),this.#l=e,this.#a=n,this.#e=r,this.#i=i,this.#n=a,this.#r=o,this.lastPoint=[NaN,NaN],this.#s(o);const[l,u,d,p]=this.#t;for(let f=0,g=e.length;f<g;f+=2)e[f]=(e[f]-l)/d,e[f+1]=(e[f+1]-u)/p;for(let f=0,g=n.length;f<g;f+=2)n[f]=(n[f]-l)/d,n[f+1]=(n[f+1]-u)/p}toSVGPath(){const e=[`M${this.#l[4]} ${this.#l[5]}`];for(let n=6,r=this.#l.length;n<r;n+=6){if(isNaN(this.#l[n])){e.push(`L${this.#l[n+4]} ${this.#l[n+5]}`);continue}e.push(`C${this.#l[n]} ${this.#l[n+1]} ${this.#l[n+2]} ${this.#l[n+3]} ${this.#l[n+4]} ${this.#l[n+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,n,r,i],a){const o=r-e,l=i-n;let u,d;switch(a){case 0:u=ye._rescale(this.#l,e,i,o,-l),d=ye._rescale(this.#a,e,i,o,-l);break;case 90:u=ye._rescaleAndSwap(this.#l,e,n,o,l),d=ye._rescaleAndSwap(this.#a,e,n,o,l);break;case 180:u=ye._rescale(this.#l,r,n,-o,l),d=ye._rescale(this.#a,r,n,-o,l);break;case 270:u=ye._rescaleAndSwap(this.#l,r,i,-o,-l),d=ye._rescaleAndSwap(this.#a,r,i,-o,-l);break}return{outline:Array.from(u),points:[Array.from(d)]}}#s(e){const n=this.#l;let r=n[4],i=n[5];const a=[r,i,r,i];let o=r,l=i;const u=e?Math.max:Math.min;for(let p=6,f=n.length;p<f;p+=6){const g=n[p+4],m=n[p+5];if(isNaN(n[p]))Ce.pointBoundingBox(g,m,a),l<m?(o=g,l=m):l===m&&(o=u(o,g));else{const v=[1/0,1/0,-1/0,-1/0];Ce.bezierBoundingBox(r,i,...n.slice(p,p+6),v),Ce.rectBoundingBox(...v,a),l<v[3]?(o=v[2],l=v[3]):l===v[3]&&(o=u(o,v[2]))}r=g,i=m}const d=this.#t;d[0]=a[0]-this.#n,d[1]=a[1]-this.#n,d[2]=a[2]-a[0]+2*this.#n,d[3]=a[3]-a[1]+2*this.#n,this.lastPoint=[o,l]}get box(){return this.#t}newOutliner(e,n,r,i,a,o=0){return new Sa(e,n,r,i,a,o)}getNewOutline(e,n){const[r,i,a,o]=this.#t,[l,u,d,p]=this.#e,f=a*d,g=o*p,m=r*d+l,v=i*p+u,b=this.newOutliner({x:this.#a[0]*f+m,y:this.#a[1]*g+v},this.#e,this.#i,e,this.#r,n??this.#n);for(let E=2;E<this.#a.length;E+=2)b.add({x:this.#a[E]*f+m,y:this.#a[E+1]*g+v});return b.getOutlines()}}class vw{#e;#t;#n=[];#r=[];constructor(e,n=0,r=0,i=!0){const a=[1/0,1/0,-1/0,-1/0],o=10**-4;for(const{x:m,y:v,width:b,height:E}of e){const S=Math.floor((m-n)/o)*o,_=Math.ceil((m+b+n)/o)*o,w=Math.floor((v-n)/o)*o,A=Math.ceil((v+E+n)/o)*o,R=[S,w,A,!0],C=[_,w,A,!1];this.#n.push(R,C),Ce.rectBoundingBox(S,w,_,A,a)}const l=a[2]-a[0]+2*r,u=a[3]-a[1]+2*r,d=a[0]-r,p=a[1]-r,f=this.#n.at(i?-1:-2),g=[f[0],f[2]];for(const m of this.#n){const[v,b,E]=m;m[0]=(v-d)/l,m[1]=(b-p)/u,m[2]=(E-p)/u}this.#e=new Float32Array([d,p,l,u]),this.#t=g}getOutlines(){this.#n.sort((n,r)=>n[0]-r[0]||n[1]-r[1]||n[2]-r[2]);const e=[];for(const n of this.#n)n[3]?(e.push(...this.#d(n)),this.#l(n)):(this.#s(n),e.push(...this.#d(n)));return this.#a(e)}#a(e){const n=[],r=new Set;for(const o of e){const[l,u,d]=o;n.push([l,u,o],[l,d,o])}n.sort((o,l)=>o[1]-l[1]||o[0]-l[0]);for(let o=0,l=n.length;o<l;o+=2){const u=n[o][2],d=n[o+1][2];u.push(d),d.push(u),r.add(u),r.add(d)}const i=[];let a;for(;r.size>0;){const o=r.values().next().value;let[l,u,d,p,f]=o;r.delete(o);let g=l,m=u;for(a=[l,d],i.push(a);;){let v;if(r.has(p))v=p;else if(r.has(f))v=f;else break;r.delete(v),[l,u,d,p,f]=v,g!==l&&(a.push(g,m,l,m===u?u:d),g=l),m=m===u?d:u}a.push(g,m)}return new Qte(i,this.#e,this.#t)}#i(e){const n=this.#r;let r=0,i=n.length-1;for(;r<=i;){const a=r+i>>1,o=n[a][0];if(o===e)return a;o<e?r=a+1:i=a-1}return i+1}#l([,e,n]){const r=this.#i(e);this.#r.splice(r,0,[e,n])}#s([,e,n]){const r=this.#i(e);for(let i=r;i<this.#r.length;i++){const[a,o]=this.#r[i];if(a!==e)break;if(a===e&&o===n){this.#r.splice(i,1);return}}for(let i=r-1;i>=0;i--){const[a,o]=this.#r[i];if(a!==e)break;if(a===e&&o===n){this.#r.splice(i,1);return}}}#d(e){const[n,r,i]=e,a=[[n,r,i]],o=this.#i(i);for(let l=0;l<o;l++){const[u,d]=this.#r[l];for(let p=0,f=a.length;p<f;p++){const[,g,m]=a[p];if(!(d<=g||m<=u)){if(g>=u){if(m>d)a[p][1]=d;else{if(f===1)return[];a.splice(p,1),p--,f--}continue}a[p][2]=u,m>d&&a.push([n,d,m])}}}return a}}class Qte extends ye{#e;#t;constructor(e,n,r){super(),this.#t=e,this.#e=n,this.lastPoint=r}toSVGPath(){const e=[];for(const n of this.#t){let[r,i]=n;e.push(`M${r} ${i}`);for(let a=2;a<n.length;a+=2){const o=n[a],l=n[a+1];o===r?(e.push(`V${l}`),i=l):l===i&&(e.push(`H${o}`),r=o)}e.push("Z")}return e.join(" ")}serialize([e,n,r,i],a){const o=[],l=r-e,u=i-n;for(const d of this.#t){const p=new Array(d.length);for(let f=0;f<d.length;f+=2)p[f]=e+d[f]*l,p[f+1]=i-d[f+1]*u;o.push(p)}return o}get box(){return this.#e}get classNamesForOutlining(){return["highlightOutline"]}}class Ew extends Sa{newFreeDrawOutline(e,n,r,i,a,o){return new Jte(e,n,r,i,a,o)}}class Jte extends fF{newOutliner(e,n,r,i,a,o=0){return new Ew(e,n,r,i,a,o)}}class Nn{#e=null;#t=null;#n;#r=null;#a=!1;#i=!1;#l=null;#s;#d=null;#c=null;#p;static#u=null;static get _keyboardManager(){return $e(this,"_keyboardManager",new Zl([[["Escape","mac+Escape"],Nn.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],Nn.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],Nn.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],Nn.prototype._moveToPrevious],[["Home","mac+Home"],Nn.prototype._moveToBeginning],[["End","mac+End"],Nn.prototype._moveToEnd]]))}constructor({editor:e=null,uiManager:n=null}){e?(this.#i=!1,this.#p=ze.HIGHLIGHT_COLOR,this.#l=e):(this.#i=!0,this.#p=ze.HIGHLIGHT_DEFAULT_COLOR),this.#c=e?._uiManager||n,this.#s=this.#c._eventBus,this.#n=e?.color||this.#c?.highlightColors.values().next().value||"#FFFF98",Nn.#u||=Object.freeze({blue:"pdfjs-editor-colorpicker-blue",green:"pdfjs-editor-colorpicker-green",pink:"pdfjs-editor-colorpicker-pink",red:"pdfjs-editor-colorpicker-red",yellow:"pdfjs-editor-colorpicker-yellow"})}renderButton(){const e=this.#e=document.createElement("button");e.className="colorPicker",e.tabIndex="0",e.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),e.setAttribute("aria-haspopup",!0);const n=this.#c._signal;e.addEventListener("click",this.#m.bind(this),{signal:n}),e.addEventListener("keydown",this.#h.bind(this),{signal:n});const r=this.#t=document.createElement("span");return r.className="swatch",r.setAttribute("aria-hidden",!0),r.style.backgroundColor=this.#n,e.append(r),e}renderMainDropdown(){const e=this.#r=this.#f();return e.setAttribute("aria-orientation","horizontal"),e.setAttribute("aria-labelledby","highlightColorPickerLabel"),e}#f(){const e=document.createElement("div"),n=this.#c._signal;e.addEventListener("contextmenu",Xn,{signal:n}),e.className="dropdown",e.role="listbox",e.setAttribute("aria-multiselectable",!1),e.setAttribute("aria-orientation","vertical"),e.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[r,i]of this.#c.highlightColors){const a=document.createElement("button");a.tabIndex="0",a.role="option",a.setAttribute("data-color",i),a.title=r,a.setAttribute("data-l10n-id",Nn.#u[r]);const o=document.createElement("span");a.append(o),o.className="swatch",o.style.backgroundColor=i,a.setAttribute("aria-selected",i===this.#n),a.addEventListener("click",this.#o.bind(this,i),{signal:n}),e.append(a)}return e.addEventListener("keydown",this.#h.bind(this),{signal:n}),e}#o(e,n){n.stopPropagation(),this.#s.dispatch("switchannotationeditorparams",{source:this,type:this.#p,value:e})}_colorSelectFromKeyboard(e){if(e.target===this.#e){this.#m(e);return}const n=e.target.getAttribute("data-color");n&&this.#o(n,e)}_moveToNext(e){if(!this.#b){this.#m(e);return}if(e.target===this.#e){this.#r.firstChild?.focus();return}e.target.nextSibling?.focus()}_moveToPrevious(e){if(e.target===this.#r?.firstChild||e.target===this.#e){this.#b&&this._hideDropdownFromKeyboard();return}this.#b||this.#m(e),e.target.previousSibling?.focus()}_moveToBeginning(e){if(!this.#b){this.#m(e);return}this.#r.firstChild?.focus()}_moveToEnd(e){if(!this.#b){this.#m(e);return}this.#r.lastChild?.focus()}#h(e){Nn._keyboardManager.exec(this,e)}#m(e){if(this.#b){this.hideDropdown();return}if(this.#a=e.detail===0,this.#d||(this.#d=new AbortController,window.addEventListener("pointerdown",this.#g.bind(this),{signal:this.#c.combinedSignal(this.#d)})),this.#r){this.#r.classList.remove("hidden");return}const n=this.#r=this.#f();this.#e.append(n)}#g(e){this.#r?.contains(e.target)||this.hideDropdown()}hideDropdown(){this.#r?.classList.add("hidden"),this.#d?.abort(),this.#d=null}get#b(){return this.#r&&!this.#r.classList.contains("hidden")}_hideDropdownFromKeyboard(){if(!this.#i){if(!this.#b){this.#l?.unselect();return}this.hideDropdown(),this.#e.focus({preventScroll:!0,focusVisible:this.#a})}}updateColor(e){if(this.#t&&(this.#t.style.backgroundColor=e),!this.#r)return;const n=this.#c.highlightColors.values();for(const r of this.#r.children)r.setAttribute("aria-selected",n.next().value===e)}destroy(){this.#e?.remove(),this.#e=null,this.#t=null,this.#r?.remove(),this.#r=null}}class At extends Ne{#e=null;#t=0;#n;#r=null;#a=null;#i=null;#l=null;#s=0;#d=null;#c=null;#p=null;#u=!1;#f=null;#o;#h=null;#m="";#g;#b="";static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type="highlight";static _editorType=Le.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId="";static get _keyboardManager(){const e=At.prototype;return $e(this,"_keyboardManager",new Zl([[["ArrowLeft","mac+ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],e._moveCaret,{args:[3]}]]))}constructor(e){super({...e,name:"highlightEditor"}),this.color=e.color||At._defaultColor,this.#g=e.thickness||At._defaultThickness,this.#o=e.opacity||At._defaultOpacity,this.#n=e.boxes||null,this.#b=e.methodOfCreation||"",this.#m=e.text||"",this._isDraggable=!1,this.defaultL10nId="pdfjs-editor-highlight-editor",e.highlightId>-1?(this.#u=!0,this.#v(e),this.#k()):this.#n&&(this.#e=e.anchorNode,this.#t=e.anchorOffset,this.#l=e.focusNode,this.#s=e.focusOffset,this.#y(),this.#k(),this.rotate(this.rotation))}get telemetryInitialData(){return{action:"added",type:this.#u?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:this.#g,methodOfCreation:this.#b}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get("color").size}}#y(){const e=new vw(this.#n,.001);this.#c=e.getOutlines(),[this.x,this.y,this.width,this.height]=this.#c.box;const n=new vw(this.#n,.0025,.001,this._uiManager.direction==="ltr");this.#i=n.getOutlines();const{lastPoint:r}=this.#i;this.#f=[(r[0]-this.x)/this.width,(r[1]-this.y)/this.height]}#v({highlightOutlines:e,highlightId:n,clipPathId:r}){this.#c=e;const i=1.5;if(this.#i=e.getNewOutline(this.#g/2+i,.0025),n>=0)this.#p=n,this.#r=r,this.parent.drawLayer.finalizeDraw(n,{bbox:e.box,path:{d:e.toSVGPath()}}),this.#h=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#i.box,path:{d:this.#i.toSVGPath()}},!0);else if(this.parent){const p=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#p,{bbox:At.#S(this.#c.box,(p-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(this.#h,{bbox:At.#S(this.#i.box,p),path:{d:this.#i.toSVGPath()}})}const[a,o,l,u]=e.box;switch(this.rotation){case 0:this.x=a,this.y=o,this.width=l,this.height=u;break;case 90:{const[p,f]=this.parentDimensions;this.x=o,this.y=1-a,this.width=l*f/p,this.height=u*p/f;break}case 180:this.x=1-a,this.y=1-o,this.width=l,this.height=u;break;case 270:{const[p,f]=this.parentDimensions;this.x=1-o,this.y=a,this.width=l*f/p,this.height=u*p/f;break}}const{lastPoint:d}=this.#i;this.#f=[(d[0]-a)/l,(d[1]-o)/u]}static initialize(e,n){Ne.initialize(e,n),At._defaultColor||=n.highlightColors?.values().next().value||"#fff066"}static updateDefaultParams(e,n){switch(e){case ze.HIGHLIGHT_DEFAULT_COLOR:At._defaultColor=n;break;case ze.HIGHLIGHT_THICKNESS:At._defaultThickness=n;break}}translateInPage(e,n){}get toolbarPosition(){return this.#f}updateParams(e,n){switch(e){case ze.HIGHLIGHT_COLOR:this.#w(n);break;case ze.HIGHLIGHT_THICKNESS:this.#x(n);break}}static get defaultPropertiesToUpdate(){return[[ze.HIGHLIGHT_DEFAULT_COLOR,At._defaultColor],[ze.HIGHLIGHT_THICKNESS,At._defaultThickness]]}get propertiesToUpdate(){return[[ze.HIGHLIGHT_COLOR,this.color||At._defaultColor],[ze.HIGHLIGHT_THICKNESS,this.#g||At._defaultThickness],[ze.HIGHLIGHT_FREE,this.#u]]}#w(e){const n=(a,o)=>{this.color=a,this.#o=o,this.parent?.drawLayer.updateProperties(this.#p,{root:{fill:a,"fill-opacity":o}}),this.#a?.updateColor(a)},r=this.color,i=this.#o;this.addCommands({cmd:n.bind(this,e,At._defaultOpacity),undo:n.bind(this,r,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ze.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)}#x(e){const n=this.#g,r=i=>{this.#g=i,this.#_(i)};this.addCommands({cmd:r.bind(this,e),undo:r.bind(this,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ze.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(this.#a=new Nn({editor:this}),e.addColorPicker(this.#a)),e):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(this.#I())}getBaseTranslation(){return[0,0]}getRect(e,n){return super.getRect(e,n,this.#I())}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){this.#C(),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#k(),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){let n=!1;this.parent&&!e?this.#C():e&&(this.#k(e),n=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(e),this.show(this._isVisible),n&&this.select()}#_(e){if(!this.#u)return;this.#v({highlightOutlines:this.#c.getNewOutline(e/2)}),this.fixAndSetPosition();const[n,r]=this.parentDimensions;this.setDims(this.width*n,this.height*r)}#C(){this.#p===null||!this.parent||(this.parent.drawLayer.remove(this.#p),this.#p=null,this.parent.drawLayer.remove(this.#h),this.#h=null)}#k(e=this.parent){this.#p===null&&({id:this.#p,clipPathId:this.#r}=e.drawLayer.draw({bbox:this.#c.box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":this.#o},rootClass:{highlight:!0,free:this.#u},path:{d:this.#c.toSVGPath()}},!1,!0),this.#h=e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#u},bbox:this.#i.box,path:{d:this.#i.toSVGPath()}},this.#u),this.#d&&(this.#d.style.clipPath=this.#r))}static#S([e,n,r,i],a){switch(a){case 90:return[1-n-i,e,i,r];case 180:return[1-e-r,1-n-i,r,i];case 270:return[n,1-e-r,i,r]}return[e,n,r,i]}rotate(e){const{drawLayer:n}=this.parent;let r;this.#u?(e=(e-this.rotation+360)%360,r=At.#S(this.#c.box,e)):r=At.#S([this.x,this.y,this.width,this.height],e),n.updateProperties(this.#p,{bbox:r,root:{"data-main-rotation":e}}),n.updateProperties(this.#h,{bbox:At.#S(this.#i.box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();this.#m&&(e.setAttribute("aria-label",this.#m),e.setAttribute("role","mark")),this.#u?e.classList.add("free"):this.div.addEventListener("keydown",this.#R.bind(this),{signal:this._uiManager._signal});const n=this.#d=document.createElement("div");e.append(n),n.setAttribute("aria-hidden","true"),n.className="internal",n.style.clipPath=this.#r;const[r,i]=this.parentDimensions;return this.setDims(this.width*r,this.height*i),zP(this,this.#d,["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#h,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#h,{rootClass:{hovered:!1}})}#R(e){At._keyboardManager.exec(this,e)}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:this.#T(!0);break;case 1:case 3:this.#T(!1);break}}#T(e){if(!this.#e)return;const n=window.getSelection();e?n.setPosition(this.#e,this.#t):n.setPosition(this.#l,this.#s)}select(){super.select(),this.#h&&this.parent?.drawLayer.updateProperties(this.#h,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect(),this.#h&&(this.parent?.drawLayer.updateProperties(this.#h,{rootClass:{selected:!1}}),this.#u||this.#T(!1))}get _mustFixPosition(){return!this.#u}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(this.#p,{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(this.#h,{rootClass:{hidden:!e}}))}#I(){return this.#u?this.rotation:0}#O(){if(this.#u)return null;const[e,n]=this.pageDimensions,[r,i]=this.pageTranslation,a=this.#n,o=new Float32Array(a.length*8);let l=0;for(const{x:u,y:d,width:p,height:f}of a){const g=u*e+r,m=(1-d)*n+i;o[l]=o[l+4]=g,o[l+1]=o[l+3]=m,o[l+2]=o[l+6]=g+p*e,o[l+5]=o[l+7]=m-f*n,l+=8}return o}#L(e){return this.#c.serialize(e,this.#I())}static startHighlighting(e,n,{target:r,x:i,y:a}){const{x:o,y:l,width:u,height:d}=r.getBoundingClientRect(),p=new AbortController,f=e.combinedSignal(p),g=m=>{p.abort(),this.#A(e,m)};window.addEventListener("blur",g,{signal:f}),window.addEventListener("pointerup",g,{signal:f}),window.addEventListener("pointerdown",_t,{capture:!0,passive:!1,signal:f}),window.addEventListener("contextmenu",Xn,{signal:f}),r.addEventListener("pointermove",this.#$.bind(this,e),{signal:f}),this._freeHighlight=new Ew({x:i,y:a},[o,l,u,d],e.scale,this._defaultThickness/2,n,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static#$(e,n){this._freeHighlight.add(n)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#A(e,n){this._freeHighlight.isEmpty()?e.drawLayer.remove(this._freeHighlightId):e.createAndAddNewEditor(n,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""}static async deserialize(e,n,r){let i=null;if(e instanceof uF){const{data:{quadPoints:v,rect:b,rotation:E,id:S,color:_,opacity:w,popupRef:A},parent:{page:{pageNumber:R}}}=e;i=e={annotationType:Le.HIGHLIGHT,color:Array.from(_),opacity:w,quadPoints:v,boxes:null,pageIndex:R-1,rect:b.slice(0),rotation:E,id:S,deleted:!1,popupRef:A}}else if(e instanceof FS){const{data:{inkLists:v,rect:b,rotation:E,id:S,color:_,borderStyle:{rawWidth:w},popupRef:A},parent:{page:{pageNumber:R}}}=e;i=e={annotationType:Le.HIGHLIGHT,color:Array.from(_),thickness:w,inkLists:v,boxes:null,pageIndex:R-1,rect:b.slice(0),rotation:E,id:S,deleted:!1,popupRef:A}}const{color:a,quadPoints:o,inkLists:l,opacity:u}=e,d=await super.deserialize(e,n,r);d.color=Ce.makeHexColor(...a),d.#o=u||1,l&&(d.#g=e.thickness),d.annotationElementId=e.id||null,d._initialData=i;const[p,f]=d.pageDimensions,[g,m]=d.pageTranslation;if(o){const v=d.#n=[];for(let b=0;b<o.length;b+=8)v.push({x:(o[b]-g)/p,y:1-(o[b+1]-m)/f,width:(o[b+2]-o[b])/p,height:(o[b+1]-o[b+5])/f});d.#y(),d.#k(),d.rotate(d.rotation)}else if(l){d.#u=!0;const v=l[0],b={x:v[0]-g,y:f-(v[1]-m)},E=new Ew(b,[0,0,p,f],1,d.#g/2,!0,.001);for(let w=0,A=v.length;w<A;w+=2)b.x=v[w]-g,b.y=f-(v[w+1]-m),E.add(b);const{id:S,clipPathId:_}=n.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:d.color,"fill-opacity":d._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:E.toSVGPath()}},!0,!0);d.#v({highlightOutlines:E.getOutlines(),highlightId:S,clipPathId:_}),d.#k(),d.rotate(d.parentRotation)}return d}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();const n=this.getRect(0,0),r=Ne._colorManager.convert(this.color),i={annotationType:Le.HIGHLIGHT,color:r,opacity:this.#o,thickness:this.#g,quadPoints:this.#O(),outlines:this.#L(n),pageIndex:this.pageIndex,rect:n,rotation:this.#I(),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!this.#E(i)?null:(i.id=this.annotationElementId,i)}#E(e){const{color:n}=this._initialData;return e.color.some((r,i)=>r!==n[i])}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}}class hF{#e=Object.create(null);updateProperty(e,n){this[e]=n,this.updateSVGProperty(e,n)}updateProperties(e){if(e)for(const[n,r]of Object.entries(e))n.startsWith("_")||this.updateProperty(n,r)}updateSVGProperty(e,n){this.#e[e]=n}toSVGProperties(){const e=this.#e;return this.#e=Object.create(null),{root:e}}reset(){this.#e=Object.create(null)}updateAll(e=this){this.updateProperties(e)}clone(){Qe("Not implemented")}}class Ie extends Ne{#e=null;#t;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#n=null;static#r=null;static#a=null;static#i=NaN;static#l=null;static#s=null;static#d=NaN;static _INNER_MARGIN=3;constructor(e){super(e),this.#t=e.mustBeCommitted||!1,this._addOutlines(e)}_addOutlines(e){e.drawOutlines&&(this.#c(e),this.#f())}#c({drawOutlines:e,drawId:n,drawingOptions:r}){this.#e=e,this._drawingOptions||=r,n>=0?(this._drawId=n,this.parent.drawLayer.finalizeDraw(n,e.defaultProperties)):this._drawId=this.#p(e,this.parent),this.#m(e.box)}#p(e,n){const{id:r}=n.drawLayer.draw(Ie._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return r}static _mergeSVGProperties(e,n){const r=new Set(Object.keys(e));for(const[i,a]of Object.entries(n))r.has(i)?Object.assign(e[i],a):e[i]=a;return e}static getDefaultDrawingOptions(e){Qe("Not implemented")}static get typesMap(){Qe("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,n){const r=this.typesMap.get(e);r&&this._defaultDrawingOptions.updateProperty(r,n),this._currentParent&&(Ie.#n.updateProperty(r,n),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,n){const r=this.constructor.typesMap.get(e);r&&this._updateProperty(e,r,n)}static get defaultPropertiesToUpdate(){const e=[],n=this._defaultDrawingOptions;for(const[r,i]of this.typesMap)e.push([r,n[i]]);return e}get propertiesToUpdate(){const e=[],{_drawingOptions:n}=this;for(const[r,i]of this.constructor.typesMap)e.push([r,n[i]]);return e}_updateProperty(e,n,r){const i=this._drawingOptions,a=i[n],o=l=>{i.updateProperty(n,l);const u=this.#e.updateProperty(n,l);u&&this.#m(u),this.parent?.drawLayer.updateProperties(this._drawId,i.toSVGProperties())};this.addCommands({cmd:o.bind(this,r),undo:o.bind(this,a),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,Ie._mergeSVGProperties(this.#e.getPathResizingSVGProperties(this.#h()),{bbox:this.#g()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,Ie._mergeSVGProperties(this.#e.getPathResizedSVGProperties(this.#h()),{bbox:this.#g()}))}_onTranslating(e,n){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#g()})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,Ie._mergeSVGProperties(this.#e.getPathTranslatedSVGProperties(this.#h(),this.parentDimensions),{bbox:this.#g()}))}_onStartDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit(),this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,this.#t&&(this.#t=!1,this.commit(),this.parent.setSelected(this),e&&this.isOnScreen&&this.div.focus())}remove(){this.#u(),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#f(),this.#m(this.#e.box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){let n=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),this.#u()):e&&(this._uiManager.addShouldRescale(this),this.#f(e),n=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(e),n&&this.select()}#u(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())}#f(e=this.parent){if(!(this._drawId!==null&&this.parent===e)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,e.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=this.#p(this.#e,e)}}#o([e,n,r,i]){const{parentDimensions:[a,o],rotation:l}=this;switch(l){case 90:return[n,1-e,r*(o/a),i*(a/o)];case 180:return[1-e,1-n,r,i];case 270:return[1-n,e,r*(o/a),i*(a/o)];default:return[e,n,r,i]}}#h(){const{x:e,y:n,width:r,height:i,parentDimensions:[a,o],rotation:l}=this;switch(l){case 90:return[1-n,e,r*(a/o),i*(o/a)];case 180:return[1-e,1-n,r,i];case 270:return[n,1-e,r*(a/o),i*(o/a)];default:return[e,n,r,i]}}#m(e){if([this.x,this.y,this.width,this.height]=this.#o(e),this.div){this.fixAndSetPosition();const[n,r]=this.parentDimensions;this.setDims(this.width*n,this.height*r)}this._onResized()}#g(){const{x:e,y:n,width:r,height:i,rotation:a,parentRotation:o,parentDimensions:[l,u]}=this;switch((a*4+o)/90){case 1:return[1-n-i,e,i,r];case 2:return[1-e-r,1-n-i,r,i];case 3:return[n,1-e-r,i,r];case 4:return[e,n-r*(l/u),i*(u/l),r*(l/u)];case 5:return[1-n,e,r*(l/u),i*(u/l)];case 6:return[1-e-i*(u/l),1-n,i*(u/l),r*(l/u)];case 7:return[n-r*(l/u),1-e-i*(u/l),r*(l/u),i*(u/l)];case 8:return[e-r,n-i,r,i];case 9:return[1-n,e-r,i,r];case 10:return[1-e,1-n,r,i];case 11:return[n-i,1-e,i,r];case 12:return[e-i*(u/l),n,i*(u/l),r*(l/u)];case 13:return[1-n-r*(l/u),e-i*(u/l),r*(l/u),i*(u/l)];case 14:return[1-e,1-n-r*(l/u),i*(u/l),r*(l/u)];case 15:return[n,1-e,r*(l/u),i*(u/l)];default:return[e,n,r,i]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,Ie._mergeSVGProperties({bbox:this.#g()},this.#e.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#m(this.#e.updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;let e,n;this._isCopy&&(e=this.x,n=this.y);const r=super.render();r.classList.add("draw");const i=document.createElement("div");r.append(i),i.setAttribute("aria-hidden","true"),i.className="internal";const[a,o]=this.parentDimensions;return this.setDims(this.width*a,this.height*o),this._uiManager.addShouldRescale(this),this.disableEditing(),this._isCopy&&this._moveAfterPaste(e,n),r}static createDrawerInstance(e,n,r,i,a){Qe("Not implemented")}static startDrawing(e,n,r,i){const{target:a,offsetX:o,offsetY:l,pointerId:u,pointerType:d}=i;if(Ie.#l&&Ie.#l!==d)return;const{viewport:{rotation:p}}=e,{width:f,height:g}=a.getBoundingClientRect(),m=Ie.#r=new AbortController,v=e.combinedSignal(m);if(Ie.#i||=u,Ie.#l??=d,window.addEventListener("pointerup",b=>{Ie.#i===b.pointerId?this._endDraw(b):Ie.#s?.delete(b.pointerId)},{signal:v}),window.addEventListener("pointercancel",b=>{Ie.#i===b.pointerId?this._currentParent.endDrawingSession():Ie.#s?.delete(b.pointerId)},{signal:v}),window.addEventListener("pointerdown",b=>{Ie.#l===b.pointerType&&((Ie.#s||=new Set).add(b.pointerId),Ie.#n.isCancellable()&&(Ie.#n.removeLastElement(),Ie.#n.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:v}),window.addEventListener("contextmenu",Xn,{signal:v}),a.addEventListener("pointermove",this._drawMove.bind(this),{signal:v}),a.addEventListener("touchmove",b=>{b.timeStamp===Ie.#d&&_t(b)},{signal:v}),e.toggleDrawing(),n._editorUndoBar?.hide(),Ie.#n){e.drawLayer.updateProperties(this._currentDrawId,Ie.#n.startNew(o,l,f,g,p));return}n.updateUIForDefaultProperties(this),Ie.#n=this.createDrawerInstance(o,l,f,g,p),Ie.#a=this.getDefaultDrawingOptions(),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(Ie.#a.toSVGProperties(),Ie.#n.defaultSVGProperties),!0,!1)}static _drawMove(e){if(Ie.#d=-1,!Ie.#n)return;const{offsetX:n,offsetY:r,pointerId:i}=e;if(Ie.#i===i){if(Ie.#s?.size>=1){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,Ie.#n.add(n,r)),Ie.#d=e.timeStamp,_t(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,Ie.#n=null,Ie.#a=null,Ie.#l=null,Ie.#d=NaN),Ie.#r&&(Ie.#r.abort(),Ie.#r=null,Ie.#i=NaN,Ie.#s=null)}static _endDraw(e){const n=this._currentParent;if(n){if(n.toggleDrawing(!0),this._cleanup(!1),e?.target===n.div&&n.drawLayer.updateProperties(this._currentDrawId,Ie.#n.end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const r=Ie.#n,i=this._currentDrawId,a=r.getLastElement();n.addCommands({cmd:()=>{n.drawLayer.updateProperties(i,r.setLastElement(a))},undo:()=>{n.drawLayer.updateProperties(i,r.removeLastElement())},mustExec:!1,type:ze.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const n=this._currentParent;if(!n)return null;if(n.toggleDrawing(!0),n.cleanUndoStack(ze.DRAW_STEP),!Ie.#n.isEmpty()){const{pageDimensions:[r,i],scale:a}=n,o=n.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:Ie.#n.getOutlines(r*a,i*a,a,this._INNER_MARGIN),drawingOptions:Ie.#a,mustBeCommitted:!e});return this._cleanup(!0),o}return n.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(e){}static deserializeDraw(e,n,r,i,a,o){Qe("Not implemented")}static async deserialize(e,n,r){const{rawDims:{pageWidth:i,pageHeight:a,pageX:o,pageY:l}}=n.viewport,u=this.deserializeDraw(o,l,i,a,this._INNER_MARGIN,e),d=await super.deserialize(e,n,r);return d.createDrawingOptions(e),d.#c({drawOutlines:u}),d.#f(),d.onScaleChanging(),d.rotate(),d}serializeDraw(e){const[n,r]=this.pageTranslation,[i,a]=this.pageDimensions;return this.#e.serialize([n,r,i,a],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}}class ene{#e=new Float64Array(6);#t;#n;#r;#a;#i;#l="";#s=0;#d=new tc;#c;#p;constructor(e,n,r,i,a,o){this.#c=r,this.#p=i,this.#r=a,this.#a=o,[e,n]=this.#u(e,n);const l=this.#t=[NaN,NaN,NaN,NaN,e,n];this.#i=[e,n],this.#n=[{line:l,points:this.#i}],this.#e.set(l,0)}updateProperty(e,n){e==="stroke-width"&&(this.#a=n)}#u(e,n){return ye._normalizePoint(e,n,this.#c,this.#p,this.#r)}isEmpty(){return!this.#n||this.#n.length===0}isCancellable(){return this.#i.length<=10}add(e,n){[e,n]=this.#u(e,n);const[r,i,a,o]=this.#e.subarray(2,6),l=e-a,u=n-o;return Math.hypot(this.#c*l,this.#p*u)<=2?null:(this.#i.push(e,n),isNaN(r)?(this.#e.set([a,o,e,n],2),this.#t.push(NaN,NaN,NaN,NaN,e,n),{path:{d:this.toSVGPath()}}):(isNaN(this.#e[0])&&this.#t.splice(6,6),this.#e.set([r,i,a,o,e,n],0),this.#t.push(...ye.createBezierPoints(r,i,a,o,e,n)),{path:{d:this.toSVGPath()}}))}end(e,n){const r=this.add(e,n);return r||(this.#i.length===2?{path:{d:this.toSVGPath()}}:null)}startNew(e,n,r,i,a){this.#c=r,this.#p=i,this.#r=a,[e,n]=this.#u(e,n);const o=this.#t=[NaN,NaN,NaN,NaN,e,n];this.#i=[e,n];const l=this.#n.at(-1);return l&&(l.line=new Float32Array(l.line),l.points=new Float32Array(l.points)),this.#n.push({line:o,points:this.#i}),this.#e.set(o,0),this.#s=0,this.toSVGPath(),null}getLastElement(){return this.#n.at(-1)}setLastElement(e){return this.#n?(this.#n.push(e),this.#t=e.line,this.#i=e.points,this.#s=0,{path:{d:this.toSVGPath()}}):this.#d.setLastElement(e)}removeLastElement(){if(!this.#n)return this.#d.removeLastElement();this.#n.pop(),this.#l="";for(let e=0,n=this.#n.length;e<n;e++){const{line:r,points:i}=this.#n[e];this.#t=r,this.#i=i,this.#s=0,this.toSVGPath()}return{path:{d:this.#l}}}toSVGPath(){const e=ye.svgRound(this.#t[4]),n=ye.svgRound(this.#t[5]);if(this.#i.length===2)return this.#l=`${this.#l} M ${e} ${n} Z`,this.#l;if(this.#i.length<=6){const i=this.#l.lastIndexOf("M");this.#l=`${this.#l.slice(0,i)} M ${e} ${n}`,this.#s=6}if(this.#i.length===4){const i=ye.svgRound(this.#t[10]),a=ye.svgRound(this.#t[11]);return this.#l=`${this.#l} L ${i} ${a}`,this.#s=12,this.#l}const r=[];this.#s===0&&(r.push(`M ${e} ${n}`),this.#s=6);for(let i=this.#s,a=this.#t.length;i<a;i+=6){const[o,l,u,d,p,f]=this.#t.slice(i,i+6).map(ye.svgRound);r.push(`C${o} ${l} ${u} ${d} ${p} ${f}`)}return this.#l+=r.join(" "),this.#s=this.#t.length,this.#l}getOutlines(e,n,r,i){const a=this.#n.at(-1);return a.line=new Float32Array(a.line),a.points=new Float32Array(a.points),this.#d.build(this.#n,e,n,r,this.#r,this.#a,i),this.#e=null,this.#t=null,this.#n=null,this.#l=null,this.#d}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}class tc extends ye{#e;#t=0;#n;#r;#a;#i;#l;#s;#d;build(e,n,r,i,a,o,l){this.#a=n,this.#i=r,this.#l=i,this.#s=a,this.#d=o,this.#n=l??0,this.#r=e,this.#u()}get thickness(){return this.#d}setLastElement(e){return this.#r.push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return this.#r.pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:n}of this.#r){if(e.push(`M${ye.svgRound(n[4])} ${ye.svgRound(n[5])}`),n.length===6){e.push("Z");continue}if(n.length===12&&isNaN(n[6])){e.push(`L${ye.svgRound(n[10])} ${ye.svgRound(n[11])}`);continue}for(let r=6,i=n.length;r<i;r+=6){const[a,o,l,u,d,p]=n.subarray(r,r+6).map(ye.svgRound);e.push(`C${a} ${o} ${l} ${u} ${d} ${p}`)}}return e.join("")}serialize([e,n,r,i],a){const o=[],l=[],[u,d,p,f]=this.#p();let g,m,v,b,E,S,_,w,A;switch(this.#s){case 0:A=ye._rescale,g=e,m=n+i,v=r,b=-i,E=e+u*r,S=n+(1-d-f)*i,_=e+(u+p)*r,w=n+(1-d)*i;break;case 90:A=ye._rescaleAndSwap,g=e,m=n,v=r,b=i,E=e+d*r,S=n+u*i,_=e+(d+f)*r,w=n+(u+p)*i;break;case 180:A=ye._rescale,g=e+r,m=n,v=-r,b=i,E=e+(1-u-p)*r,S=n+d*i,_=e+(1-u)*r,w=n+(d+f)*i;break;case 270:A=ye._rescaleAndSwap,g=e+r,m=n+i,v=-r,b=-i,E=e+(1-d-f)*r,S=n+(1-u-p)*i,_=e+(1-d)*r,w=n+(1-u)*i;break}for(const{line:R,points:C}of this.#r)o.push(A(R,g,m,v,b,a?new Array(R.length):null)),l.push(A(C,g,m,v,b,a?new Array(C.length):null));return{lines:o,points:l,rect:[E,S,_,w]}}static deserialize(e,n,r,i,a,{paths:{lines:o,points:l},rotation:u,thickness:d}){const p=[];let f,g,m,v,b;switch(u){case 0:b=ye._rescale,f=-e/r,g=n/i+1,m=1/r,v=-1/i;break;case 90:b=ye._rescaleAndSwap,f=-n/i,g=-e/r,m=1/i,v=1/r;break;case 180:b=ye._rescale,f=e/r+1,g=-n/i,m=-1/r,v=1/i;break;case 270:b=ye._rescaleAndSwap,f=n/i+1,g=e/r+1,m=-1/i,v=-1/r;break}if(!o){o=[];for(const S of l){const _=S.length;if(_===2){o.push(new Float32Array([NaN,NaN,NaN,NaN,S[0],S[1]]));continue}if(_===4){o.push(new Float32Array([NaN,NaN,NaN,NaN,S[0],S[1],NaN,NaN,NaN,NaN,S[2],S[3]]));continue}const w=new Float32Array(3*(_-2));o.push(w);let[A,R,C,T]=S.subarray(0,4);w.set([NaN,NaN,NaN,NaN,A,R],0);for(let O=4;O<_;O+=2){const L=S[O],z=S[O+1];w.set(ye.createBezierPoints(A,R,C,T,L,z),(O-2)*3),[A,R,C,T]=[C,T,L,z]}}}for(let S=0,_=o.length;S<_;S++)p.push({line:b(o[S].map(w=>w??NaN),f,g,m,v),points:b(l[S].map(w=>w??NaN),f,g,m,v)});const E=new this.prototype.constructor;return E.build(p,r,i,1,u,d,a),E}#c(e=this.#d){const n=this.#n+e/2*this.#l;return this.#s%180===0?[n/this.#a,n/this.#i]:[n/this.#i,n/this.#a]}#p(){const[e,n,r,i]=this.#e,[a,o]=this.#c(0);return[e+a,n+o,r-2*a,i-2*o]}#u(){const e=this.#e=new Float32Array([1/0,1/0,-1/0,-1/0]);for(const{line:i}of this.#r){if(i.length<=12){for(let l=4,u=i.length;l<u;l+=6)Ce.pointBoundingBox(i[l],i[l+1],e);continue}let a=i[4],o=i[5];for(let l=6,u=i.length;l<u;l+=6){const[d,p,f,g,m,v]=i.subarray(l,l+6);Ce.bezierBoundingBox(a,o,d,p,f,g,m,v,e),a=m,o=v}}const[n,r]=this.#c();e[0]=rn(e[0]-n,0,1),e[1]=rn(e[1]-r,0,1),e[2]=rn(e[2]+n,0,1),e[3]=rn(e[3]+r,0,1),e[2]-=e[0],e[3]-=e[1]}get box(){return this.#e}updateProperty(e,n){return e==="stroke-width"?this.#f(n):null}#f(e){const[n,r]=this.#c();this.#d=e;const[i,a]=this.#c(),[o,l]=[i-n,a-r],u=this.#e;return u[0]-=o,u[1]-=l,u[2]+=2*o,u[3]+=2*l,u}updateParentDimensions([e,n],r){const[i,a]=this.#c();this.#a=e,this.#i=n,this.#l=r;const[o,l]=this.#c(),u=o-i,d=l-a,p=this.#e;return p[0]-=u,p[1]-=d,p[2]+=2*u,p[3]+=2*d,p}updateRotation(e){return this.#t=e,{path:{transform:this.rotationTransform}}}get viewBox(){return this.#e.map(ye.svgRound).join(" ")}get defaultProperties(){const[e,n]=this.#e;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${ye.svgRound(e)} ${ye.svgRound(n)}`}}}get rotationTransform(){const[,,e,n]=this.#e;let r=0,i=0,a=0,o=0,l=0,u=0;switch(this.#t){case 90:i=n/e,a=-e/n,l=e;break;case 180:r=-1,o=-1,l=e,u=n;break;case 270:i=-n/e,a=e/n,u=n;break;default:return""}return`matrix(${r} ${i} ${a} ${o} ${ye.svgRound(l)} ${ye.svgRound(u)})`}getPathResizingSVGProperties([e,n,r,i]){const[a,o]=this.#c(),[l,u,d,p]=this.#e;if(Math.abs(d-a)<=ye.PRECISION||Math.abs(p-o)<=ye.PRECISION){const b=e+r/2-(l+d/2),E=n+i/2-(u+p/2);return{path:{"transform-origin":`${ye.svgRound(e)} ${ye.svgRound(n)}`,transform:`${this.rotationTransform} translate(${b} ${E})`}}}const f=(r-2*a)/(d-2*a),g=(i-2*o)/(p-2*o),m=d/r,v=p/i;return{path:{"transform-origin":`${ye.svgRound(l)} ${ye.svgRound(u)}`,transform:`${this.rotationTransform} scale(${m} ${v}) translate(${ye.svgRound(a)} ${ye.svgRound(o)}) scale(${f} ${g}) translate(${ye.svgRound(-a)} ${ye.svgRound(-o)})`}}}getPathResizedSVGProperties([e,n,r,i]){const[a,o]=this.#c(),l=this.#e,[u,d,p,f]=l;if(l[0]=e,l[1]=n,l[2]=r,l[3]=i,Math.abs(p-a)<=ye.PRECISION||Math.abs(f-o)<=ye.PRECISION){const E=e+r/2-(u+p/2),S=n+i/2-(d+f/2);for(const{line:_,points:w}of this.#r)ye._translate(_,E,S,_),ye._translate(w,E,S,w);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${ye.svgRound(e)} ${ye.svgRound(n)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const g=(r-2*a)/(p-2*a),m=(i-2*o)/(f-2*o),v=-g*(u+a)+e+a,b=-m*(d+o)+n+o;if(g!==1||m!==1||v!==0||b!==0)for(const{line:E,points:S}of this.#r)ye._rescale(E,v,b,g,m,E),ye._rescale(S,v,b,g,m,S);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${ye.svgRound(e)} ${ye.svgRound(n)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,n],r){const[i,a]=r,o=this.#e,l=e-o[0],u=n-o[1];if(this.#a===i&&this.#i===a)for(const{line:d,points:p}of this.#r)ye._translate(d,l,u,d),ye._translate(p,l,u,p);else{const d=this.#a/i,p=this.#i/a;this.#a=i,this.#i=a;for(const{line:f,points:g}of this.#r)ye._rescale(f,l,u,d,p,f),ye._rescale(g,l,u,d,p,g);o[2]*=d,o[3]*=p}return o[0]=e,o[1]=n,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${ye.svgRound(e)} ${ye.svgRound(n)}`}}}get defaultSVGProperties(){const e=this.#e;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${ye.svgRound(e[0])} ${ye.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}}class lp extends hF{constructor(e){super(),this._viewParameters=e,super.updateProperties({fill:"none",stroke:Ne._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(e,n){e==="stroke-width"&&(n??=this["stroke-width"],n*=this._viewParameters.realScale),super.updateSVGProperty(e,n)}clone(){const e=new lp(this._viewParameters);return e.updateAll(this),e}}class US extends Ie{static _type="ink";static _editorType=Le.INK;static _defaultDrawingOptions=null;constructor(e){super({...e,name:"inkEditor"}),this._willKeepAspectRatio=!0,this.defaultL10nId="pdfjs-editor-ink-editor"}static initialize(e,n){Ne.initialize(e,n),this._defaultDrawingOptions=new lp(n.viewParameters)}static getDefaultDrawingOptions(e){const n=this._defaultDrawingOptions.clone();return n.updateProperties(e),n}static get supportMultipleDrawings(){return!0}static get typesMap(){return $e(this,"typesMap",new Map([[ze.INK_THICKNESS,"stroke-width"],[ze.INK_COLOR,"stroke"],[ze.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,n,r,i,a){return new ene(e,n,r,i,a,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(e,n,r,i,a,o){return tc.deserialize(e,n,r,i,a,o)}static async deserialize(e,n,r){let i=null;if(e instanceof FS){const{data:{inkLists:o,rect:l,rotation:u,id:d,color:p,opacity:f,borderStyle:{rawWidth:g},popupRef:m},parent:{page:{pageNumber:v}}}=e;i=e={annotationType:Le.INK,color:Array.from(p),thickness:g,opacity:f,paths:{points:o},boxes:null,pageIndex:v-1,rect:l.slice(0),rotation:u,id:d,deleted:!1,popupRef:m}}const a=await super.deserialize(e,n,r);return a.annotationElementId=e.id||null,a._initialData=i,a}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:e,_drawingOptions:n,parent:r}=this;n.updateSVGProperty("stroke-width"),r.drawLayer.updateProperties(e,n.toSVGProperties())}static onScaleChangingWhenDrawing(){const e=this._currentParent;e&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:e,thickness:n,opacity:r}){this._drawingOptions=US.getDefaultDrawingOptions({stroke:Ce.makeHexColor(...e),"stroke-width":n,"stroke-opacity":r})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:n,points:r,rect:i}=this.serializeDraw(e),{_drawingOptions:{stroke:a,"stroke-opacity":o,"stroke-width":l}}=this,u={annotationType:Le.INK,color:Ne._colorManager.convert(a),opacity:o,thickness:l,paths:{lines:n,points:r},pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?(u.isCopy=!0,u):this.annotationElementId&&!this.#e(u)?null:(u.id=this.annotationElementId,u)}#e(e){const{color:n,thickness:r,opacity:i,pageIndex:a}=this._initialData;return this._hasBeenMoved||this._hasBeenResized||e.color.some((o,l)=>o!==n[l])||e.thickness!==r||e.opacity!==i||e.pageIndex!==a}renderAnnotationElement(e){const{points:n,rect:r}=this.serializeDraw(!1);return e.updateEdited({rect:r,thickness:this._drawingOptions["stroke-width"],points:n}),null}}class ww extends tc{toSVGPath(){let e=super.toSVGPath();return e.endsWith("Z")||(e+="Z"),e}}const zu=8,nl=3;class Ea{static#e={maxDim:512,sigmaSFactor:.02,sigmaR:25,kernelSize:16};static#t(e,n,r,i){return r-=e,i-=n,r===0?i>0?0:4:r===1?i+6:2-i}static#n=new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]);static#r(e,n,r,i,a,o,l){const u=this.#t(r,i,a,o);for(let d=0;d<8;d++){const p=(-d+u-l+16)%8,f=this.#n[2*p],g=this.#n[2*p+1];if(e[(r+f)*n+(i+g)]!==0)return p}return-1}static#a(e,n,r,i,a,o,l){const u=this.#t(r,i,a,o);for(let d=0;d<8;d++){const p=(d+u+l+16)%8,f=this.#n[2*p],g=this.#n[2*p+1];if(e[(r+f)*n+(i+g)]!==0)return p}return-1}static#i(e,n,r,i){const a=e.length,o=new Int32Array(a);for(let p=0;p<a;p++)o[p]=e[p]<=i?1:0;for(let p=1;p<r-1;p++)o[p*n]=o[p*n+n-1]=0;for(let p=0;p<n;p++)o[p]=o[n*r-1-p]=0;let l=1,u;const d=[];for(let p=1;p<r-1;p++){u=1;for(let f=1;f<n-1;f++){const g=p*n+f,m=o[g];if(m===0)continue;let v=p,b=f;if(m===1&&o[g-1]===0)l+=1,b-=1;else if(m>=1&&o[g+1]===0)l+=1,b+=1,m>1&&(u=m);else{m!==1&&(u=Math.abs(m));continue}const E=[f,p],S=b===f+1,_={isHole:S,points:E,id:l,parent:0};d.push(_);let w;for(const $ of d)if($.id===u){w=$;break}w?w.isHole?_.parent=S?w.parent:u:_.parent=S?u:w.parent:_.parent=S?u:0;const A=this.#r(o,n,p,f,v,b,0);if(A===-1){o[g]=-l,o[g]!==1&&(u=Math.abs(o[g]));continue}let R=this.#n[2*A],C=this.#n[2*A+1];const T=p+R,O=f+C;v=T,b=O;let L=p,z=f;for(;;){const $=this.#a(o,n,L,z,v,b,1);R=this.#n[2*$],C=this.#n[2*$+1];const G=L+R,W=z+C;E.push(W,G);const P=L*n+z;if(o[P+1]===0?o[P]=-l:o[P]===1&&(o[P]=l),G===p&&W===f&&L===T&&z===O){o[g]!==1&&(u=Math.abs(o[g]));break}else v=L,b=z,L=G,z=W}}}return d}static#l(e,n,r,i){if(r-n<=4){for(let T=n;T<r-2;T+=2)i.push(e[T],e[T+1]);return}const a=e[n],o=e[n+1],l=e[r-4]-a,u=e[r-3]-o,d=Math.hypot(l,u),p=l/d,f=u/d,g=p*o-f*a,m=u/l,v=1/d,b=Math.atan(m),E=Math.cos(b),S=Math.sin(b),_=v*(Math.abs(E)+Math.abs(S)),w=v*(1-_+_**2),A=Math.max(Math.atan(Math.abs(S+E)*w),Math.atan(Math.abs(S-E)*w));let R=0,C=n;for(let T=n+2;T<r-2;T+=2){const O=Math.abs(g-p*e[T+1]+f*e[T]);O>R&&(C=T,R=O)}R>(d*A)**2?(this.#l(e,n,C+2,i),this.#l(e,C,r,i)):i.push(a,o)}static#s(e){const n=[],r=e.length;return this.#l(e,0,r,n),n.push(e[r-2],e[r-1]),n.length<=4?null:n}static#d(e,n,r,i,a,o){const l=new Float32Array(o**2),u=-2*i**2,d=o>>1;for(let b=0;b<o;b++){const E=(b-d)**2;for(let S=0;S<o;S++)l[b*o+S]=Math.exp((E+(S-d)**2)/u)}const p=new Float32Array(256),f=-2*a**2;for(let b=0;b<256;b++)p[b]=Math.exp(b**2/f);const g=e.length,m=new Uint8Array(g),v=new Uint32Array(256);for(let b=0;b<r;b++)for(let E=0;E<n;E++){const S=b*n+E,_=e[S];let w=0,A=0;for(let C=0;C<o;C++){const T=b+C-d;if(!(T<0||T>=r))for(let O=0;O<o;O++){const L=E+O-d;if(L<0||L>=n)continue;const z=e[T*n+L],$=l[C*o+O]*p[Math.abs(z-_)];w+=z*$,A+=$}}const R=m[S]=Math.round(w/A);v[R]++}return[m,v]}static#c(e){const n=new Uint32Array(256);for(const r of e)n[r]++;return n}static#p(e){const n=e.length,r=new Uint8ClampedArray(n>>2);let i=-1/0,a=1/0;for(let l=0,u=r.length;l<u;l++){if(e[(l<<2)+3]===0){i=r[l]=255;continue}const p=r[l]=e[l<<2];p>i&&(i=p),p<a&&(a=p)}const o=255/(i-a);for(let l=0;l<n;l++)r[l]=(r[l]-a)*o;return r}static#u(e){let n,r=-1/0,i=-1/0;const a=e.findIndex(u=>u!==0);let o=a,l=a;for(n=a;n<256;n++){const u=e[n];u>r&&(n-o>i&&(i=n-o,l=n-1),r=u,o=n)}for(n=l-1;n>=0&&!(e[n]>e[n+1]);n--);return n}static#f(e){const n=e,{width:r,height:i}=e,{maxDim:a}=this.#e;let o=r,l=i;if(r>a||i>a){let g=r,m=i,v=Math.log2(Math.max(r,i)/a);const b=Math.floor(v);v=v===b?b-1:b;for(let S=0;S<v;S++){o=Math.ceil(g/2),l=Math.ceil(m/2);const _=new OffscreenCanvas(o,l);_.getContext("2d").drawImage(e,0,0,g,m,0,0,o,l),g=o,m=l,e!==n&&e.close(),e=_.transferToImageBitmap()}const E=Math.min(a/o,a/l);o=Math.round(o*E),l=Math.round(l*E)}const d=new OffscreenCanvas(o,l).getContext("2d",{willReadFrequently:!0});d.filter="grayscale(1)",d.drawImage(e,0,0,e.width,e.height,0,0,o,l);const p=d.getImageData(0,0,o,l).data;return[this.#p(p),o,l]}static extractContoursFromText(e,{fontFamily:n,fontStyle:r,fontWeight:i},a,o,l,u){let d=new OffscreenCanvas(1,1),p=d.getContext("2d",{alpha:!1});const f=200,g=p.font=`${r} ${i} ${f}px ${n}`,{actualBoundingBoxLeft:m,actualBoundingBoxRight:v,actualBoundingBoxAscent:b,actualBoundingBoxDescent:E,fontBoundingBoxAscent:S,fontBoundingBoxDescent:_,width:w}=p.measureText(e),A=1.5,R=Math.ceil(Math.max(Math.abs(m)+Math.abs(v)||0,w)*A),C=Math.ceil(Math.max(Math.abs(b)+Math.abs(E)||f,Math.abs(S)+Math.abs(_)||f)*A);d=new OffscreenCanvas(R,C),p=d.getContext("2d",{alpha:!0,willReadFrequently:!0}),p.font=g,p.filter="grayscale(1)",p.fillStyle="white",p.fillRect(0,0,R,C),p.fillStyle="black",p.fillText(e,R*(A-1)/2,C*(3-A)/2);const T=this.#p(p.getImageData(0,0,R,C).data),O=this.#c(T),L=this.#u(O),z=this.#i(T,R,C,L);return this.processDrawnLines({lines:{curves:z,width:R,height:C},pageWidth:a,pageHeight:o,rotation:l,innerMargin:u,mustSmooth:!0,areContours:!0})}static process(e,n,r,i,a){const[o,l,u]=this.#f(e),[d,p]=this.#d(o,l,u,Math.hypot(l,u)*this.#e.sigmaSFactor,this.#e.sigmaR,this.#e.kernelSize),f=this.#u(p),g=this.#i(d,l,u,f);return this.processDrawnLines({lines:{curves:g,width:l,height:u},pageWidth:n,pageHeight:r,rotation:i,innerMargin:a,mustSmooth:!0,areContours:!0})}static processDrawnLines({lines:e,pageWidth:n,pageHeight:r,rotation:i,innerMargin:a,mustSmooth:o,areContours:l}){i%180!==0&&([n,r]=[r,n]);const{curves:u,width:d,height:p}=e,f=e.thickness??0,g=[],m=Math.min(n/d,r/p),v=m/n,b=m/r,E=[];for(const{points:_}of u){const w=o?this.#s(_):_;if(!w)continue;E.push(w);const A=w.length,R=new Float32Array(A),C=new Float32Array(3*(A===2?2:A-2));if(g.push({line:C,points:R}),A===2){R[0]=w[0]*v,R[1]=w[1]*b,C.set([NaN,NaN,NaN,NaN,R[0],R[1]],0);continue}let[T,O,L,z]=w;T*=v,O*=b,L*=v,z*=b,R.set([T,O,L,z],0),C.set([NaN,NaN,NaN,NaN,T,O],0);for(let $=4;$<A;$+=2){const G=R[$]=w[$]*v,W=R[$+1]=w[$+1]*b;C.set(ye.createBezierPoints(T,O,L,z,G,W),($-2)*3),[T,O,L,z]=[L,z,G,W]}}if(g.length===0)return null;const S=l?new ww:new tc;return S.build(g,n,r,1,i,l?0:f,a),{outline:S,newCurves:E,areContours:l,thickness:f,width:d,height:p}}static async compressSignature({outlines:e,areContours:n,thickness:r,width:i,height:a}){let o=1/0,l=-1/0,u=0;for(const w of e){u+=w.length;for(let A=2,R=w.length;A<R;A++){const C=w[A]-w[A-2];o=Math.min(o,C),l=Math.max(l,C)}}let d;o>=-128&&l<=127?d=Int8Array:o>=-32768&&l<=32767?d=Int16Array:d=Int32Array;const p=e.length,f=zu+nl*p,g=new Uint32Array(f);let m=0;g[m++]=f*Uint32Array.BYTES_PER_ELEMENT+(u-2*p)*d.BYTES_PER_ELEMENT,g[m++]=0,g[m++]=i,g[m++]=a,g[m++]=n?0:1,g[m++]=Math.max(0,Math.floor(r??0)),g[m++]=p,g[m++]=d.BYTES_PER_ELEMENT;for(const w of e)g[m++]=w.length-2,g[m++]=w[0],g[m++]=w[1];const v=new CompressionStream("deflate-raw"),b=v.writable.getWriter();await b.ready,b.write(g);const E=d.prototype.constructor;for(const w of e){const A=new E(w.length-2);for(let R=2,C=w.length;R<C;R++)A[R-2]=w[R]-w[R-2];b.write(A)}b.close();const S=await new Response(v.readable).arrayBuffer(),_=new Uint8Array(S);return FP(_)}static async decompressSignature(e){try{const n=Nee(e),{readable:r,writable:i}=new DecompressionStream("deflate-raw"),a=i.getWriter();await a.ready,a.write(n).then(async()=>{await a.ready,await a.close()}).catch(()=>{});let o=null,l=0;for await(const w of r)o||=new Uint8Array(new Uint32Array(w.buffer,0,4)[0]),o.set(w,l),l+=w.length;const u=new Uint32Array(o.buffer,0,o.length>>2),d=u[1];if(d!==0)throw new Error(`Invalid version: ${d}`);const p=u[2],f=u[3],g=u[4]===0,m=u[5],v=u[6],b=u[7],E=[],S=(zu+nl*v)*Uint32Array.BYTES_PER_ELEMENT;let _;switch(b){case Int8Array.BYTES_PER_ELEMENT:_=new Int8Array(o.buffer,S);break;case Int16Array.BYTES_PER_ELEMENT:_=new Int16Array(o.buffer,S);break;case Int32Array.BYTES_PER_ELEMENT:_=new Int32Array(o.buffer,S);break}l=0;for(let w=0;w<v;w++){const A=u[nl*w+zu],R=new Float32Array(A+2);E.push(R);for(let C=0;C<nl-1;C++)R[C]=u[nl*w+zu+C+1];for(let C=0;C<A;C++)R[C+2]=R[C]+_[l++]}return{areContours:g,thickness:m,outlines:E,width:p,height:f}}catch(n){return Me(`decompressSignature: ${n}`),null}}}class $S extends hF{constructor(){super(),super.updateProperties({fill:Ne._defaultLineColor,"stroke-width":0})}clone(){const e=new $S;return e.updateAll(this),e}}class zS extends lp{constructor(e){super(e),super.updateProperties({stroke:Ne._defaultLineColor,"stroke-width":1})}clone(){const e=new zS(this._viewParameters);return e.updateAll(this),e}}class Cr extends Ie{#e=!1;#t=null;#n=null;#r=null;static _type="signature";static _editorType=Le.SIGNATURE;static _defaultDrawingOptions=null;constructor(e){super({...e,mustBeCommitted:!0,name:"signatureEditor"}),this._willKeepAspectRatio=!0,this.#n=e.signatureData||null,this.#t=null,this.defaultL10nId="pdfjs-editor-signature-editor1"}static initialize(e,n){Ne.initialize(e,n),this._defaultDrawingOptions=new $S,this._defaultDrawnSignatureOptions=new zS(n.viewParameters)}static getDefaultDrawingOptions(e){const n=this._defaultDrawingOptions.clone();return n.updateProperties(e),n}static get supportMultipleDrawings(){return!1}static get typesMap(){return $e(this,"typesMap",new Map)}static get isDrawer(){return!1}get telemetryFinalData(){return{type:"signature",hasDescription:!!this.#t}}static computeTelemetryFinalData(e){const n=e.get("hasDescription");return{hasAltText:n.get(!0)??0,hasNoAltText:n.get(!1)??0}}get isResizable(){return!0}onScaleChanging(){this._drawId!==null&&super.onScaleChanging()}render(){if(this.div)return this.div;let e,n;const{_isCopy:r}=this;if(r&&(this._isCopy=!1,e=this.x,n=this.y),super.render(),this._drawId===null)if(this.#n){const{lines:i,mustSmooth:a,areContours:o,description:l,uuid:u,heightInPage:d}=this.#n,{rawDims:{pageWidth:p,pageHeight:f},rotation:g}=this.parent.viewport,m=Ea.processDrawnLines({lines:i,pageWidth:p,pageHeight:f,rotation:g,innerMargin:Cr._INNER_MARGIN,mustSmooth:a,areContours:o});this.addSignature(m,d,l,u)}else this.div.setAttribute("data-l10n-args",JSON.stringify({description:""})),this.div.hidden=!0,this._uiManager.getSignature(this);return r&&(this._isCopy=!0,this._moveAfterPaste(e,n)),this.div}setUuid(e){this.#r=e,this.addEditToolbar()}getUuid(){return this.#r}get description(){return this.#t}set description(e){this.#t=e,super.addEditToolbar().then(n=>{n?.updateEditSignatureButton(e)})}getSignaturePreview(){const{newCurves:e,areContours:n,thickness:r,width:i,height:a}=this.#n,o=Math.max(i,a),l=Ea.processDrawnLines({lines:{curves:e.map(u=>({points:u})),thickness:r,width:i,height:a},pageWidth:o,pageHeight:o,rotation:0,innerMargin:0,mustSmooth:!1,areContours:n});return{areContours:n,outline:l.outline}}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.signatureManager&&this.#t!==null&&(await e.addEditSignatureButton(this._uiManager.signatureManager,this.#r,this.#t),e.show()),e):null}addSignature(e,n,r,i){const{x:a,y:o}=this,{outline:l}=this.#n=e;this.#e=l instanceof ww,this.#t=r,this.div.setAttribute("data-l10n-args",JSON.stringify({description:r}));let u;this.#e?u=Cr.getDefaultDrawingOptions():(u=Cr._defaultDrawnSignatureOptions.clone(),u.updateProperties({"stroke-width":l.thickness})),this._addOutlines({drawOutlines:l,drawingOptions:u});const[d,p]=this.parentDimensions,[,f]=this.pageDimensions;let g=n/f;g=g>=1?.5:g,this.width*=g/this.height,this.width>=1&&(g*=.9/this.width,this.width=.9),this.height=g,this.setDims(d*this.width,p*this.height),this.x=a,this.y=o,this.center(),this._onResized(),this.onScaleChanging(),this.rotate(),this._uiManager.addToAnnotationStorage(this),this.setUuid(i),this._reportTelemetry({action:"pdfjs.signature.inserted",data:{hasBeenSaved:!!i,hasDescription:!!r}}),this.div.hidden=!1}getFromImage(e){const{rawDims:{pageWidth:n,pageHeight:r},rotation:i}=this.parent.viewport;return Ea.process(e,n,r,i,Cr._INNER_MARGIN)}getFromText(e,n){const{rawDims:{pageWidth:r,pageHeight:i},rotation:a}=this.parent.viewport;return Ea.extractContoursFromText(e,n,r,i,a,Cr._INNER_MARGIN)}getDrawnSignature(e){const{rawDims:{pageWidth:n,pageHeight:r},rotation:i}=this.parent.viewport;return Ea.processDrawnLines({lines:e,pageWidth:n,pageHeight:r,rotation:i,innerMargin:Cr._INNER_MARGIN,mustSmooth:!1,areContours:!1})}createDrawingOptions({areContours:e,thickness:n}){e?this._drawingOptions=Cr.getDefaultDrawingOptions():(this._drawingOptions=Cr._defaultDrawnSignatureOptions.clone(),this._drawingOptions.updateProperties({"stroke-width":n}))}serialize(e=!1){if(this.isEmpty())return null;const{lines:n,points:r,rect:i}=this.serializeDraw(e),{_drawingOptions:{"stroke-width":a}}=this,o={annotationType:Le.SIGNATURE,isSignature:!0,areContours:this.#e,color:[0,0,0],thickness:this.#e?0:a,pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?(o.paths={lines:n,points:r},o.uuid=this.#r,o.isCopy=!0):o.lines=n,this.#t&&(o.accessibilityData={type:"Figure",alt:this.#t}),o}static deserializeDraw(e,n,r,i,a,o){return o.areContours?ww.deserialize(e,n,r,i,a,o):tc.deserialize(e,n,r,i,a,o)}static async deserialize(e,n,r){const i=await super.deserialize(e,n,r);return i.#e=e.areContours,i.#t=e.accessibilityData?.alt||"",i.#r=e.uuid,i}}class tne extends Ne{#e=null;#t=null;#n=null;#r=null;#a=null;#i="";#l=null;#s=!1;#d=null;#c=!1;#p=!1;static _type="stamp";static _editorType=Le.STAMP;constructor(e){super({...e,name:"stampEditor"}),this.#r=e.bitmapUrl,this.#a=e.bitmapFile,this.defaultL10nId="pdfjs-editor-stamp-editor"}static initialize(e,n){Ne.initialize(e,n)}static isHandlingMimeForPasting(e){return wd.includes(e)}static paste(e,n){n.pasteEditor({mode:Le.STAMP},{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){return{type:"stamp",hasAltText:!!this.altTextData?.altText}}static computeTelemetryFinalData(e){const n=e.get("hasAltText");return{hasAltText:n.get(!0)??0,hasNoAltText:n.get(!1)??0}}#u(e,n=!1){if(!e){this.remove();return}this.#e=e.bitmap,n||(this.#t=e.id,this.#c=e.isSvg),e.file&&(this.#i=e.file.name),this.#h()}#f(){if(this.#n=null,this._uiManager.enableWaiting(!1),!!this.#l){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#e){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#e){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}}async mlGuessAltText(e=null,n=!0){if(this.hasAltTextData())return null;const{mlManager:r}=this._uiManager;if(!r)throw new Error("No ML.");if(!await r.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:i,width:a,height:o}=e||this.copyCanvas(null,null,!0).imageData,l=await r.guess({name:"altText",request:{data:i,width:a,height:o,channels:i.length/(a*o)}});if(!l)throw new Error("No response from the AI service.");if(l.error)throw new Error("Error from the AI service.");if(l.cancel)return null;if(!l.output)throw new Error("No valid response from the AI service.");const u=l.output;return await this.setGuessedAltText(u),n&&!this.hasAltTextData()&&(this.altTextData={alt:u,decorative:!1}),u}#o(){if(this.#t){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(this.#t).then(r=>this.#u(r,!0)).finally(()=>this.#f());return}if(this.#r){const r=this.#r;this.#r=null,this._uiManager.enableWaiting(!0),this.#n=this._uiManager.imageManager.getFromUrl(r).then(i=>this.#u(i)).finally(()=>this.#f());return}if(this.#a){const r=this.#a;this.#a=null,this._uiManager.enableWaiting(!0),this.#n=this._uiManager.imageManager.getFromFile(r).then(i=>this.#u(i)).finally(()=>this.#f());return}const e=document.createElement("input");e.type="file",e.accept=wd.join(",");const n=this._uiManager._signal;this.#n=new Promise(r=>{e.addEventListener("change",async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const i=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),this.#u(i)}r()},{signal:n}),e.addEventListener("cancel",()=>{this.remove(),r()},{signal:n})}).finally(()=>this.#f()),e.click()}remove(){this.#t&&(this.#e=null,this._uiManager.imageManager.deleteId(this.#t),this.#l?.remove(),this.#l=null,this.#d&&(clearTimeout(this.#d),this.#d=null)),super.remove()}rebuild(){if(!this.parent){this.#t&&this.#o();return}super.rebuild(),this.div!==null&&(this.#t&&this.#l===null&&this.#o(),this.isAttachedToDOM||this.parent.add(this))}onceAdded(e){this._isDraggable=!0,e&&this.div.focus()}isEmpty(){return!(this.#n||this.#e||this.#r||this.#a||this.#t||this.#s)}get isResizable(){return!0}render(){if(this.div)return this.div;let e,n;return this._isCopy&&(e=this.x,n=this.y),super.render(),this.div.hidden=!0,this.addAltTextButton(),this.#s||(this.#e?this.#h():this.#o()),this._isCopy&&this._moveAfterPaste(e,n),this._uiManager.addShouldRescale(this),this.div}setCanvas(e,n){const{id:r,bitmap:i}=this._uiManager.imageManager.getFromCanvas(e,n);n.remove(),r&&this._uiManager.imageManager.isValidId(r)&&(this.#t=r,i&&(this.#e=i),this.#s=!1,this.#h())}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;this.#d!==null&&clearTimeout(this.#d);const e=200;this.#d=setTimeout(()=>{this.#d=null,this.#g()},e)}#h(){const{div:e}=this;let{width:n,height:r}=this.#e;const[i,a]=this.pageDimensions,o=.75;if(this.width)n=this.width*i,r=this.height*a;else if(n>o*i||r>o*a){const p=Math.min(o*i/n,o*a/r);n*=p,r*=p}const[l,u]=this.parentDimensions;this.setDims(n*l/i,r*u/a),this._uiManager.enableWaiting(!1);const d=this.#l=document.createElement("canvas");d.setAttribute("role","img"),this.addContainer(d),this.width=n/i,this.height=r/a,this._initialOptions?.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),this.#g(),this.#p||(this.parent.addUndoableEditor(this),this.#p=!0),this._reportTelemetry({action:"inserted_image"}),this.#i&&this.div.setAttribute("aria-description",this.#i)}copyCanvas(e,n,r=!1){e||(e=224);const{width:i,height:a}=this.#e,o=new fr;let l=this.#e,u=i,d=a,p=null;if(n){if(i>n||a>n){const C=Math.min(n/i,n/a);u=Math.floor(i*C),d=Math.floor(a*C)}p=document.createElement("canvas");const g=p.width=Math.ceil(u*o.sx),m=p.height=Math.ceil(d*o.sy);this.#c||(l=this.#m(g,m));const v=p.getContext("2d");v.filter=this._uiManager.hcmFilter;let b="white",E="#cfcfd8";this._uiManager.hcmFilter!=="none"?E="black":window.matchMedia?.("(prefers-color-scheme: dark)").matches&&(b="#8f8f9d",E="#42414d");const S=15,_=S*o.sx,w=S*o.sy,A=new OffscreenCanvas(_*2,w*2),R=A.getContext("2d");R.fillStyle=b,R.fillRect(0,0,_*2,w*2),R.fillStyle=E,R.fillRect(0,0,_,w),R.fillRect(_,w,_,w),v.fillStyle=v.createPattern(A,"repeat"),v.fillRect(0,0,g,m),v.drawImage(l,0,0,l.width,l.height,0,0,g,m)}let f=null;if(r){let g,m;if(o.symmetric&&l.width<e&&l.height<e)g=l.width,m=l.height;else if(l=this.#e,i>e||a>e){const E=Math.min(e/i,e/a);g=Math.floor(i*E),m=Math.floor(a*E),this.#c||(l=this.#m(g,m))}const b=new OffscreenCanvas(g,m).getContext("2d",{willReadFrequently:!0});b.drawImage(l,0,0,l.width,l.height,0,0,g,m),f={width:g,height:m,data:b.getImageData(0,0,g,m).data}}return{canvas:p,width:u,height:d,imageData:f}}#m(e,n){const{width:r,height:i}=this.#e;let a=r,o=i,l=this.#e;for(;a>2*e||o>2*n;){const u=a,d=o;a>2*e&&(a=a>=16384?Math.floor(a/2)-1:Math.ceil(a/2)),o>2*n&&(o=o>=16384?Math.floor(o/2)-1:Math.ceil(o/2));const p=new OffscreenCanvas(a,o);p.getContext("2d").drawImage(l,0,0,u,d,0,0,a,o),l=p.transferToImageBitmap()}return l}#g(){const[e,n]=this.parentDimensions,{width:r,height:i}=this,a=new fr,o=Math.ceil(r*e*a.sx),l=Math.ceil(i*n*a.sy),u=this.#l;if(!u||u.width===o&&u.height===l)return;u.width=o,u.height=l;const d=this.#c?this.#e:this.#m(o,l),p=u.getContext("2d");p.filter=this._uiManager.hcmFilter,p.drawImage(d,0,0,d.width,d.height,0,0,o,l)}#b(e){if(e){if(this.#c){const i=this._uiManager.imageManager.getSvgUrl(this.#t);if(i)return i}const n=document.createElement("canvas");return{width:n.width,height:n.height}=this.#e,n.getContext("2d").drawImage(this.#e,0,0),n.toDataURL()}if(this.#c){const[n,r]=this.pageDimensions,i=Math.round(this.width*n*Ba.PDF_TO_CSS_UNITS),a=Math.round(this.height*r*Ba.PDF_TO_CSS_UNITS),o=new OffscreenCanvas(i,a);return o.getContext("2d").drawImage(this.#e,0,0,this.#e.width,this.#e.height,0,0,i,a),o.transferToImageBitmap()}return structuredClone(this.#e)}static async deserialize(e,n,r){let i=null,a=!1;if(e instanceof dF){const{data:{rect:b,rotation:E,id:S,structParent:_,popupRef:w},container:A,parent:{page:{pageNumber:R}},canvas:C}=e;let T,O;C?(delete e.canvas,{id:T,bitmap:O}=r.imageManager.getFromCanvas(A.id,C),C.remove()):(a=!0,e._hasNoCanvas=!0);const L=(await n._structTree.getAriaAttributes(`${AS}${S}`))?.get("aria-label")||"";i=e={annotationType:Le.STAMP,bitmapId:T,bitmap:O,pageIndex:R-1,rect:b.slice(0),rotation:E,id:S,deleted:!1,accessibilityData:{decorative:!1,altText:L},isSvg:!1,structParent:_,popupRef:w}}const o=await super.deserialize(e,n,r),{rect:l,bitmap:u,bitmapUrl:d,bitmapId:p,isSvg:f,accessibilityData:g}=e;a?(r.addMissingCanvas(e.id,o),o.#s=!0):p&&r.imageManager.isValidId(p)?(o.#t=p,u&&(o.#e=u)):o.#r=d,o.#c=f;const[m,v]=o.pageDimensions;return o.width=(l[2]-l[0])/m,o.height=(l[3]-l[1])/v,o.annotationElementId=e.id||null,g&&(o.altTextData=g),o._initialData=i,o.#p=!!i,o}serialize(e=!1,n=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const r={annotationType:Le.STAMP,bitmapId:this.#t,pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:this.#c,structTreeParentId:this._structTreeParentId};if(e)return r.bitmapUrl=this.#b(!0),r.accessibilityData=this.serializeAltText(!0),r.isCopy=!0,r;const{decorative:i,altText:a}=this.serializeAltText(!1);if(!i&&a&&(r.accessibilityData={type:"Figure",alt:a}),this.annotationElementId){const l=this.#y(r);if(l.isSame)return null;l.isSameAltText?delete r.accessibilityData:r.accessibilityData.structParent=this._initialData.structParent??-1}if(r.id=this.annotationElementId,n===null)return r;n.stamps||=new Map;const o=this.#c?(r.rect[2]-r.rect[0])*(r.rect[3]-r.rect[1]):null;if(!n.stamps.has(this.#t))n.stamps.set(this.#t,{area:o,serialized:r}),r.bitmap=this.#b(!1);else if(this.#c){const l=n.stamps.get(this.#t);o>l.area&&(l.area=o,l.serialized.bitmap.close(),l.serialized.bitmap=this.#b(!1))}return r}#y(e){const{pageIndex:n,accessibilityData:{altText:r}}=this._initialData,i=e.pageIndex===n,a=(e.accessibilityData?.alt||"")===r;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&i&&a,isSameAltText:a}}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}}class kr{#e;#t=!1;#n=null;#r=null;#a=null;#i=new Map;#l=!1;#s=!1;#d=!1;#c=null;#p=null;#u=null;#f=null;#o;static _initialized=!1;static#h=new Map([Ft,US,tne,At,Cr].map(e=>[e._editorType,e]));constructor({uiManager:e,pageIndex:n,div:r,structTreeLayer:i,accessibilityManager:a,annotationLayer:o,drawLayer:l,textLayer:u,viewport:d,l10n:p}){const f=[...kr.#h.values()];if(!kr._initialized){kr._initialized=!0;for(const g of f)g.initialize(p,e)}e.registerEditorTypes(f),this.#o=e,this.pageIndex=n,this.div=r,this.#e=a,this.#n=o,this.viewport=d,this.#u=u,this.drawLayer=l,this._structTree=i,this.#o.addLayer(this)}get isEmpty(){return this.#i.size===0}get isInvisible(){return this.isEmpty&&this.#o.getMode()===Le.NONE}updateToolbar(e){this.#o.updateToolbar(e)}updateMode(e=this.#o.getMode()){switch(this.#v(),e){case Le.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case Le.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case Le.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:n}=this.div;for(const r of kr.#h.values())n.toggle(`${r._type}Editing`,e===r._editorType);this.div.hidden=!1}hasTextLayer(e){return e===this.#u?.div}setEditingState(e){this.#o.setEditingState(e)}addCommands(e){this.#o.addCommands(e)}cleanUndoStack(e){this.#o.cleanUndoStack(e)}toggleDrawing(e=!1){this.div.classList.toggle("drawing",!e)}togglePointerEvents(e=!1){this.div.classList.toggle("disabled",!e)}toggleAnnotationLayerPointerEvents(e=!1){this.#n?.div.classList.toggle("disabled",!e)}async enable(){this.#d=!0,this.div.tabIndex=0,this.togglePointerEvents(!0);const e=new Set;for(const r of this.#i.values())r.enableEditing(),r.show(!0),r.annotationElementId&&(this.#o.removeChangedExistingAnnotation(r),e.add(r.annotationElementId));if(!this.#n){this.#d=!1;return}const n=this.#n.getEditableAnnotations();for(const r of n){if(r.hide(),this.#o.isDeletedAnnotationElement(r.data.id)||e.has(r.data.id))continue;const i=await this.deserialize(r);i&&(this.addOrRebuild(i),i.enableEditing())}this.#d=!1}disable(){this.#s=!0,this.div.tabIndex=-1,this.togglePointerEvents(!1);const e=new Map,n=new Map;for(const i of this.#i.values())if(i.disableEditing(),!!i.annotationElementId){if(i.serialize()!==null){e.set(i.annotationElementId,i);continue}else n.set(i.annotationElementId,i);this.getEditableAnnotation(i.annotationElementId)?.show(),i.remove()}if(this.#n){const i=this.#n.getEditableAnnotations();for(const a of i){const{id:o}=a.data;if(this.#o.isDeletedAnnotationElement(o))continue;let l=n.get(o);if(l){l.resetAnnotationElement(a),l.show(!1),a.show();continue}l=e.get(o),l&&(this.#o.addChangedExistingAnnotation(l),l.renderAnnotationElement(a)&&l.show(!1)),a.show()}}this.#v(),this.isEmpty&&(this.div.hidden=!0);const{classList:r}=this.div;for(const i of kr.#h.values())r.remove(`${i._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),this.#s=!1}getEditableAnnotation(e){return this.#n?.getEditableAnnotation(e)||null}setActiveEditor(e){this.#o.getActive()!==e&&this.#o.setActiveEditor(e)}enableTextSelection(){if(this.div.tabIndex=-1,this.#u?.div&&!this.#f){this.#f=new AbortController;const e=this.#o.combinedSignal(this.#f);this.#u.div.addEventListener("pointerdown",this.#m.bind(this),{signal:e}),this.#u.div.classList.add("highlighting")}}disableTextSelection(){this.div.tabIndex=0,this.#u?.div&&this.#f&&(this.#f.abort(),this.#f=null,this.#u.div.classList.remove("highlighting"))}#m(e){this.#o.unselectAll();const{target:n}=e;if(n===this.#u.div||(n.getAttribute("role")==="img"||n.classList.contains("endOfContent"))&&this.#u.div.contains(n)){const{isMac:r}=Gt.platform;if(e.button!==0||e.ctrlKey&&r)return;this.#o.showAllEditors("highlight",!0,!0),this.#u.div.classList.add("free"),this.toggleDrawing(),At.startHighlighting(this,this.#o.direction==="ltr",{target:this.#u.div,x:e.x,y:e.y}),this.#u.div.addEventListener("pointerup",()=>{this.#u.div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:this.#o._signal}),e.preventDefault()}}enableClick(){if(this.#r)return;this.#r=new AbortController;const e=this.#o.combinedSignal(this.#r);this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:e});const n=this.pointerup.bind(this);this.div.addEventListener("pointerup",n,{signal:e}),this.div.addEventListener("pointercancel",n,{signal:e})}disableClick(){this.#r?.abort(),this.#r=null}attach(e){this.#i.set(e.id,e);const{annotationElementId:n}=e;n&&this.#o.isDeletedAnnotationElement(n)&&this.#o.removeDeletedAnnotationElement(e)}detach(e){this.#i.delete(e.id),this.#e?.removePointerInTextLayer(e.contentDiv),!this.#s&&e.annotationElementId&&this.#o.addDeletedAnnotationElement(e)}remove(e){this.detach(e),this.#o.removeEditor(e),e.div.remove(),e.isAttachedToDOM=!1}changeParent(e){e.parent!==this&&(e.parent&&e.annotationElementId&&(this.#o.addDeletedAnnotationElement(e.annotationElementId),Ne.deleteAnnotationElement(e),e.annotationElementId=null),this.attach(e),e.parent?.detach(e),e.setParent(this),e.div&&e.isAttachedToDOM&&(e.div.remove(),this.div.append(e.div)))}add(e){if(!(e.parent===this&&e.isAttachedToDOM)){if(this.changeParent(e),this.#o.addEditor(e),this.attach(e),!e.isAttachedToDOM){const n=e.render();this.div.append(n),e.isAttachedToDOM=!0}e.fixAndSetPosition(),e.onceAdded(!this.#d),this.#o.addToAnnotationStorage(e),e._reportTelemetry(e.telemetryInitialData)}}moveEditorInDOM(e){if(!e.isAttachedToDOM)return;const{activeElement:n}=document;e.div.contains(n)&&!this.#a&&(e._focusEventsAllowed=!1,this.#a=setTimeout(()=>{this.#a=null,e.div.contains(document.activeElement)?e._focusEventsAllowed=!0:(e.div.addEventListener("focusin",()=>{e._focusEventsAllowed=!0},{once:!0,signal:this.#o._signal}),n.focus())},0)),e._structTreeParentId=this.#e?.moveElementInDOM(this.div,e.div,e.contentDiv,!0)}addOrRebuild(e){e.needsToBeRebuilt()?(e.parent||=this,e.rebuild(),e.show()):this.add(e)}addUndoableEditor(e){const n=()=>e._uiManager.rebuild(e),r=()=>{e.remove()};this.addCommands({cmd:n,undo:r,mustExec:!1})}getNextId(){return this.#o.getId()}get#g(){return kr.#h.get(this.#o.getMode())}combinedSignal(e){return this.#o.combinedSignal(e)}#b(e){const n=this.#g;return n?new n.prototype.constructor(e):null}canCreateNewEmptyEditor(){return this.#g?.canCreateNewEmptyEditor()}async pasteEditor(e,n){this.updateToolbar(e),await this.#o.updateMode(e.mode);const{offsetX:r,offsetY:i}=this.#y(),a=this.getNextId(),o=this.#b({parent:this,id:a,x:r,y:i,uiManager:this.#o,isCentered:!0,...n});o&&this.add(o)}async deserialize(e){return await kr.#h.get(e.annotationType??e.annotationEditorType)?.deserialize(e,this,this.#o)||null}createAndAddNewEditor(e,n,r={}){const i=this.getNextId(),a=this.#b({parent:this,id:i,x:e.offsetX,y:e.offsetY,uiManager:this.#o,isCentered:n,...r});return a&&this.add(a),a}#y(){const{x:e,y:n,width:r,height:i}=this.div.getBoundingClientRect(),a=Math.max(0,e),o=Math.max(0,n),l=Math.min(window.innerWidth,e+r),u=Math.min(window.innerHeight,n+i),d=(a+l)/2-e,p=(o+u)/2-n,[f,g]=this.viewport.rotation%180===0?[d,p]:[p,d];return{offsetX:f,offsetY:g}}addNewEditor(e={}){this.createAndAddNewEditor(this.#y(),!0,e)}setSelected(e){this.#o.setSelected(e)}toggleSelected(e){this.#o.toggleSelected(e)}unselect(e){this.#o.unselect(e)}pointerup(e){const{isMac:n}=Gt.platform;if(e.button!==0||e.ctrlKey&&n||e.target!==this.div||!this.#l||(this.#l=!1,this.#g?.isDrawer&&this.#g.supportMultipleDrawings))return;if(!this.#t){this.#t=!0;return}const r=this.#o.getMode();if(r===Le.STAMP||r===Le.SIGNATURE){this.#o.unselectAll();return}this.createAndAddNewEditor(e,!1)}pointerdown(e){if(this.#o.getMode()===Le.HIGHLIGHT&&this.enableTextSelection(),this.#l){this.#l=!1;return}const{isMac:n}=Gt.platform;if(e.button!==0||e.ctrlKey&&n||e.target!==this.div)return;if(this.#l=!0,this.#g?.isDrawer){this.startDrawingSession(e);return}const r=this.#o.getActive();this.#t=!r||r.isEmpty()}startDrawingSession(e){if(this.div.focus({preventScroll:!0}),this.#c){this.#g.startDrawing(this,this.#o,!1,e);return}this.#o.setCurrentDrawingSession(this),this.#c=new AbortController;const n=this.#o.combinedSignal(this.#c);this.div.addEventListener("blur",({relatedTarget:r})=>{r&&!this.div.contains(r)&&(this.#p=null,this.commitOrRemove())},{signal:n}),this.#g.startDrawing(this,this.#o,!1,e)}pause(e){if(e){const{activeElement:n}=document;this.div.contains(n)&&(this.#p=n);return}this.#p&&setTimeout(()=>{this.#p?.focus(),this.#p=null},0)}endDrawingSession(e=!1){return this.#c?(this.#o.setCurrentDrawingSession(null),this.#c.abort(),this.#c=null,this.#p=null,this.#g.endDrawing(e)):null}findNewParent(e,n,r){const i=this.#o.findParent(n,r);return i===null||i===this?!1:(i.changeParent(e),!0)}commitOrRemove(){return this.#c?(this.endDrawingSession(),!0):!1}onScaleChanging(){this.#c&&this.#g.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove(),this.#o.getActive()?.parent===this&&(this.#o.commitOrRemove(),this.#o.setActiveEditor(null)),this.#a&&(clearTimeout(this.#a),this.#a=null);for(const e of this.#i.values())this.#e?.removePointerInTextLayer(e.contentDiv),e.setParent(null),e.isAttachedToDOM=!1,e.div.remove();this.div=null,this.#i.clear(),this.#o.removeLayer(this)}#v(){for(const e of this.#i.values())e.isEmpty()&&e.remove()}render({viewport:e}){this.viewport=e,Vi(this.div,e);for(const n of this.#o.getEditors(this.pageIndex))this.add(n),n.rebuild();this.updateMode()}update({viewport:e}){this.#o.commitOrRemove(),this.#v();const n=this.viewport.rotation,r=e.rotation;if(this.viewport=e,Vi(this.div,{rotation:r}),n!==r)for(const i of this.#i.values())i.rotate(r)}get pageDimensions(){const{pageWidth:e,pageHeight:n}=this.viewport.rawDims;return[e,n]}get scale(){return this.#o.viewParameters.realScale}}class jt{#e=null;#t=new Map;#n=new Map;static#r=0;constructor({pageIndex:e}){this.pageIndex=e}setParent(e){if(!this.#e){this.#e=e;return}if(this.#e!==e){if(this.#t.size>0)for(const n of this.#t.values())n.remove(),e.append(n);this.#e=e}}static get _svgFactory(){return $e(this,"_svgFactory",new Ll)}static#a(e,[n,r,i,a]){const{style:o}=e;o.top=`${100*r}%`,o.left=`${100*n}%`,o.width=`${100*i}%`,o.height=`${100*a}%`}#i(){const e=jt._svgFactory.create(1,1,!0);return this.#e.append(e),e.setAttribute("aria-hidden",!0),e}#l(e,n){const r=jt._svgFactory.createElement("clipPath");e.append(r);const i=`clip_${n}`;r.setAttribute("id",i),r.setAttribute("clipPathUnits","objectBoundingBox");const a=jt._svgFactory.createElement("use");return r.append(a),a.setAttribute("href",`#${n}`),a.classList.add("clip"),i}#s(e,n){for(const[r,i]of Object.entries(n))i===null?e.removeAttribute(r):e.setAttribute(r,i)}draw(e,n=!1,r=!1){const i=jt.#r++,a=this.#i(),o=jt._svgFactory.createElement("defs");a.append(o);const l=jt._svgFactory.createElement("path");o.append(l);const u=`path_p${this.pageIndex}_${i}`;l.setAttribute("id",u),l.setAttribute("vector-effect","non-scaling-stroke"),n&&this.#n.set(i,l);const d=r?this.#l(o,u):null,p=jt._svgFactory.createElement("use");return a.append(p),p.setAttribute("href",`#${u}`),this.updateProperties(a,e),this.#t.set(i,a),{id:i,clipPathId:`url(#${d})`}}drawOutline(e,n){const r=jt.#r++,i=this.#i(),a=jt._svgFactory.createElement("defs");i.append(a);const o=jt._svgFactory.createElement("path");a.append(o);const l=`path_p${this.pageIndex}_${r}`;o.setAttribute("id",l),o.setAttribute("vector-effect","non-scaling-stroke");let u;if(n){const f=jt._svgFactory.createElement("mask");a.append(f),u=`mask_p${this.pageIndex}_${r}`,f.setAttribute("id",u),f.setAttribute("maskUnits","objectBoundingBox");const g=jt._svgFactory.createElement("rect");f.append(g),g.setAttribute("width","1"),g.setAttribute("height","1"),g.setAttribute("fill","white");const m=jt._svgFactory.createElement("use");f.append(m),m.setAttribute("href",`#${l}`),m.setAttribute("stroke","none"),m.setAttribute("fill","black"),m.setAttribute("fill-rule","nonzero"),m.classList.add("mask")}const d=jt._svgFactory.createElement("use");i.append(d),d.setAttribute("href",`#${l}`),u&&d.setAttribute("mask",`url(#${u})`);const p=d.cloneNode();return i.append(p),d.classList.add("mainOutline"),p.classList.add("secondaryOutline"),this.updateProperties(i,e),this.#t.set(r,i),r}finalizeDraw(e,n){this.#n.delete(e),this.updateProperties(e,n)}updateProperties(e,n){if(!n)return;const{root:r,bbox:i,rootClass:a,path:o}=n,l=typeof e=="number"?this.#t.get(e):e;if(l){if(r&&this.#s(l,r),i&&jt.#a(l,i),a){const{classList:u}=l;for(const[d,p]of Object.entries(a))u.toggle(d,p)}if(o){const d=l.firstChild.firstChild;this.#s(d,o)}}}updateParent(e,n){if(n===this)return;const r=this.#t.get(e);r&&(n.#e.append(r),this.#t.delete(e),n.#t.set(e,r))}remove(e){this.#n.delete(e),this.#e!==null&&(this.#t.get(e).remove(),this.#t.delete(e))}destroy(){this.#e=null;for(const e of this.#t.values())e.remove();this.#t.clear(),this.#n.clear()}}globalThis._pdfjsTestingUtils={HighlightOutliner:vw};globalThis.pdfjsLib={AbortException:si,AnnotationEditorLayer:kr,AnnotationEditorParamsType:ze,AnnotationEditorType:Le,AnnotationEditorUIManager:li,AnnotationLayer:BS,AnnotationMode:Lr,AnnotationType:xt,build:aF,ColorPicker:Nn,createValidAbsoluteUrl:wS,DOMSVGFactory:Ll,DrawLayer:jt,FeatureTest:Gt,fetchData:us,getDocument:LS,getFilenameFromUrl:BP,getPdfFilenameFromUrl:UP,getUuid:xS,getXfaPageViewport:$P,GlobalWorkerOptions:Hi,ImageKind:fl,InvalidPDFException:Ed,isDataScheme:Kl,isPdfFile:op,isValidExplicitDest:GP,MathClamp:rn,noContextMenu:Xn,normalizeUnicode:PP,OPS:Rl,OutputScale:fr,PasswordResponses:DP,PDFDataRangeTransport:MS,PDFDateString:_S,PDFWorker:es,PermissionFlag:LP,PixelsPerInch:Ba,RenderingCancelledException:ap,ResponseException:kl,setLayerDimensions:Vi,shadow:$e,SignatureExtractor:Ea,stopEvent:_t,SupportedImageMimeTypes:wd,TextLayer:Nl,TouchManager:Ql,updateUrlHash:SS,Util:Ce,VerbosityLevel:Wl,version:Ol,XfaLayer:PS};const nne=Object.freeze(Object.defineProperty({__proto__:null,AbortException:si,AnnotationEditorLayer:kr,AnnotationEditorParamsType:ze,AnnotationEditorType:Le,AnnotationEditorUIManager:li,AnnotationLayer:BS,AnnotationMode:Lr,AnnotationType:xt,ColorPicker:Nn,DOMSVGFactory:Ll,DrawLayer:jt,FeatureTest:Gt,GlobalWorkerOptions:Hi,ImageKind:fl,InvalidPDFException:Ed,MathClamp:rn,OPS:Rl,OutputScale:fr,PDFDataRangeTransport:MS,PDFDateString:_S,PDFWorker:es,PasswordResponses:DP,PermissionFlag:LP,PixelsPerInch:Ba,RenderingCancelledException:ap,ResponseException:kl,SignatureExtractor:Ea,SupportedImageMimeTypes:wd,TextLayer:Nl,TouchManager:Ql,Util:Ce,VerbosityLevel:Wl,XfaLayer:PS,build:aF,createValidAbsoluteUrl:wS,fetchData:us,getDocument:LS,getFilenameFromUrl:BP,getPdfFilenameFromUrl:UP,getUuid:xS,getXfaPageViewport:$P,isDataScheme:Kl,isPdfFile:op,isValidExplicitDest:GP,noContextMenu:Xn,normalizeUnicode:PP,setLayerDimensions:Vi,shadow:$e,stopEvent:_t,updateUrlHash:SS,version:Ol},Symbol.toStringTag,{value:"Module"})),rne=["onCopy","onCut","onPaste"],ine=["onCompositionEnd","onCompositionStart","onCompositionUpdate"],ane=["onFocus","onBlur"],one=["onInput","onInvalid","onReset","onSubmit"],sne=["onLoad","onError"],lne=["onKeyDown","onKeyPress","onKeyUp"],cne=["onAbort","onCanPlay","onCanPlayThrough","onDurationChange","onEmptied","onEncrypted","onEnded","onError","onLoadedData","onLoadedMetadata","onLoadStart","onPause","onPlay","onPlaying","onProgress","onRateChange","onSeeked","onSeeking","onStalled","onSuspend","onTimeUpdate","onVolumeChange","onWaiting"],une=["onClick","onContextMenu","onDoubleClick","onMouseDown","onMouseEnter","onMouseLeave","onMouseMove","onMouseOut","onMouseOver","onMouseUp"],dne=["onDrag","onDragEnd","onDragEnter","onDragExit","onDragLeave","onDragOver","onDragStart","onDrop"],pne=["onSelect"],fne=["onTouchCancel","onTouchEnd","onTouchMove","onTouchStart"],hne=["onPointerDown","onPointerMove","onPointerUp","onPointerCancel","onGotPointerCapture","onLostPointerCapture","onPointerEnter","onPointerLeave","onPointerOver","onPointerOut"],gne=["onScroll"],mne=["onWheel"],bne=["onAnimationStart","onAnimationEnd","onAnimationIteration"],yne=["onTransitionEnd"],vne=["onToggle"],Ene=["onChange"],wne=[...rne,...ine,...ane,...one,...sne,...lne,...cne,...une,...dne,...pne,...fne,...hne,...gne,...mne,...bne,...yne,...Ene,...vne];function gF(t,e){const n={};for(const r of wne){const i=t[r];i&&(e?n[r]=a=>i(a,e(r)):n[r]=i)}return n}function nc(t){let e=!1;return{promise:new Promise((r,i)=>{t.then(a=>!e&&r(a)).catch(a=>!e&&i(a))}),cancel(){e=!0}}}var Sne="Invariant failed";function Je(t,e){if(!t)throw new Error(Sne)}var OE,N1;function xne(){if(N1)return OE;N1=1;var t=function(){};return OE=t,OE}var Ane=xne();const an=Dl(Ane);var I1=Object.prototype.hasOwnProperty;function O1(t,e,n){for(n of t.keys())if(zo(n,e))return n}function zo(t,e){var n,r,i;if(t===e)return!0;if(t&&e&&(n=t.constructor)===e.constructor){if(n===Date)return t.getTime()===e.getTime();if(n===RegExp)return t.toString()===e.toString();if(n===Array){if((r=t.length)===e.length)for(;r--&&zo(t[r],e[r]););return r===-1}if(n===Set){if(t.size!==e.size)return!1;for(r of t)if(i=r,i&&typeof i=="object"&&(i=O1(e,i),!i)||!e.has(i))return!1;return!0}if(n===Map){if(t.size!==e.size)return!1;for(r of t)if(i=r[0],i&&typeof i=="object"&&(i=O1(e,i),!i)||!zo(r[1],e.get(i)))return!1;return!0}if(n===ArrayBuffer)t=new Uint8Array(t),e=new Uint8Array(e);else if(n===DataView){if((r=t.byteLength)===e.byteLength)for(;r--&&t.getInt8(r)===e.getInt8(r););return r===-1}if(ArrayBuffer.isView(t)){if((r=t.byteLength)===e.byteLength)for(;r--&&t[r]===e[r];);return r===-1}if(!n||typeof t=="object"){r=0;for(n in t)if(I1.call(t,n)&&++r&&!I1.call(e,n)||!(n in e)||!zo(t[n],e[n]))return!1;return Object.keys(e).length===r}}return t!==t&&e!==e}const mF=k.createContext(null);function jo({children:t,type:e}){return N.jsx("div",{className:`react-pdf__message react-pdf__message--${e}`,children:t})}const _ne="noopener noreferrer nofollow";class Tne{constructor(){this.externalLinkEnabled=!0,this.externalLinkRel=void 0,this.externalLinkTarget=void 0,this.isInPresentationMode=!1,this.pdfDocument=void 0,this.pdfViewer=void 0}setDocument(e){this.pdfDocument=e}setViewer(e){this.pdfViewer=e}setExternalLinkRel(e){this.externalLinkRel=e}setExternalLinkTarget(e){this.externalLinkTarget=e}setHistory(){}get pagesCount(){return this.pdfDocument?this.pdfDocument.numPages:0}get page(){return Je(this.pdfViewer),this.pdfViewer.currentPageNumber||0}set page(e){Je(this.pdfViewer),this.pdfViewer.currentPageNumber=e}get rotation(){return 0}set rotation(e){}goToDestination(e){return new Promise(n=>{Je(this.pdfDocument),Je(e),typeof e=="string"?this.pdfDocument.getDestination(e).then(n):Array.isArray(e)?n(e):e.then(n)}).then(n=>{Je(Array.isArray(n));const r=n[0];new Promise(i=>{Je(this.pdfDocument),r instanceof Object?this.pdfDocument.getPageIndex(r).then(a=>{i(a)}).catch(()=>{Je(!1)}):typeof r=="number"?i(r):Je(!1)}).then(i=>{const a=i+1;Je(this.pdfViewer),Je(a>=1&&a<=this.pagesCount),this.pdfViewer.scrollPageIntoView({dest:n,pageIndex:i,pageNumber:a})})})}navigateTo(e){this.goToDestination(e)}goToPage(e){const n=e-1;Je(this.pdfViewer),Je(e>=1&&e<=this.pagesCount),this.pdfViewer.scrollPageIntoView({pageIndex:n,pageNumber:e})}addLinkAttributes(e,n,r){e.href=n,e.rel=this.externalLinkRel||_ne,e.target=r?"_blank":this.externalLinkTarget||""}getDestinationHash(){return"#"}getAnchorUrl(){return"#"}setHash(){}executeNamedAction(){}cachePageRef(){}isPageVisible(){return!0}isPageCached(){return!0}executeSetOCGState(){}}const L1={NEED_PASSWORD:1,INCORRECT_PASSWORD:2},cp=typeof window<"u",bF=cp&&window.location.protocol==="file:";function Cne(t){return typeof t<"u"}function ya(t){return Cne(t)&&t!==null}function Rne(t){return typeof t=="string"}function kne(t){return t instanceof ArrayBuffer}function Nne(t){return Je(cp),t instanceof Blob}function Sw(t){return Rne(t)&&/^data:/.test(t)}function D1(t){Je(Sw(t));const[e="",n=""]=t.split(",");return e.split(";").indexOf("base64")!==-1?atob(n):unescape(n)}function Ine(){return cp&&window.devicePixelRatio||1}const yF="On Chromium based browsers, you can use --allow-file-access-from-files flag for debugging purposes.";function M1(){an(!bF,`Loading PDF as base64 strings/URLs may not work on protocols other than HTTP/HTTPS. ${yF}`)}function One(){an(!bF,`Loading PDF.js worker may not work on protocols other than HTTP/HTTPS. ${yF}`)}function $a(t){t?.cancel&&t.cancel()}function xw(t,e){return Object.defineProperty(t,"width",{get(){return this.view[2]*e},configurable:!0}),Object.defineProperty(t,"height",{get(){return this.view[3]*e},configurable:!0}),Object.defineProperty(t,"originalWidth",{get(){return this.view[2]},configurable:!0}),Object.defineProperty(t,"originalHeight",{get(){return this.view[3]},configurable:!0}),t}function Lne(t){return t.name==="RenderingCancelledException"}function Dne(t){return new Promise((e,n)=>{const r=new FileReader;r.onload=()=>{if(!r.result)return n(new Error("Error while reading a file."));e(r.result)},r.onerror=i=>{if(!i.target)return n(new Error("Error while reading a file."));const{error:a}=i.target;if(!a)return n(new Error("Error while reading a file."));switch(a.code){case a.NOT_FOUND_ERR:return n(new Error("Error while reading a file: File not found."));case a.SECURITY_ERR:return n(new Error("Error while reading a file: Security error."));case a.ABORT_ERR:return n(new Error("Error while reading a file: Aborted."));default:return n(new Error("Error while reading a file."))}},r.readAsArrayBuffer(t)})}function Mne(t,e){switch(e.type){case"RESOLVE":return{value:e.value,error:void 0};case"REJECT":return{value:!1,error:e.error};case"RESET":return{value:void 0,error:void 0};default:return t}}function ts(){return k.useReducer(Mne,{value:void 0,error:void 0})}var P1=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]]);return n};const{PDFDataRangeTransport:Pne}=nne,Fne=(t,e)=>{switch(e){case L1.NEED_PASSWORD:{const n=prompt("Enter the password to open this PDF file.");t(n);break}case L1.INCORRECT_PASSWORD:{const n=prompt("Invalid password. Please try again.");t(n);break}}};function F1(t){return typeof t=="object"&&t!==null&&("data"in t||"range"in t||"url"in t)}const Bne=k.forwardRef(function(e,n){var{children:r,className:i,error:a="Failed to load PDF file.",externalLinkRel:o,externalLinkTarget:l,file:u,inputRef:d,imageResourcesPath:p,loading:f="Loading PDF…",noData:g="No PDF file specified.",onItemClick:m,onLoadError:v,onLoadProgress:b,onLoadSuccess:E,onPassword:S=Fne,onSourceError:_,onSourceSuccess:w,options:A,renderMode:R,rotate:C,scale:T}=e,O=P1(e,["children","className","error","externalLinkRel","externalLinkTarget","file","inputRef","imageResourcesPath","loading","noData","onItemClick","onLoadError","onLoadProgress","onLoadSuccess","onPassword","onSourceError","onSourceSuccess","options","renderMode","rotate","scale"]);const[L,z]=ts(),{value:$,error:G}=L,[W,P]=ts(),{value:j,error:B}=W,F=k.useRef(new Tne),D=k.useRef([]),q=k.useRef(void 0),K=k.useRef(void 0);u&&u!==q.current&&F1(u)&&(an(!zo(u,q.current),`File prop passed to <Document /> changed, but it's equal to previous one. This might result in unnecessary reloads. Consider memoizing the value passed to "file" prop.`),q.current=u),A&&A!==K.current&&(an(!zo(A,K.current),`Options prop passed to <Document /> changed, but it's equal to previous one. This might result in unnecessary reloads. Consider memoizing the value passed to "options" prop.`),K.current=A);const U=k.useRef({scrollPageIntoView:he=>{const{dest:xe,pageNumber:Ae,pageIndex:Pe=Ae-1}=he;if(m){m({dest:xe,pageIndex:Pe,pageNumber:Ae});return}const Fe=D.current[Pe];if(Fe){Fe.scrollIntoView();return}an(!1,`An internal link leading to page ${Ae} was clicked, but neither <Document> was provided with onItemClick nor it was able to find the page within itself. Either provide onItemClick to <Document> and handle navigating by yourself or ensure that all pages are rendered within <Document>.`)}});k.useImperativeHandle(n,()=>({linkService:F,pages:D,viewer:U}),[]);function H(){w&&w()}function V(){G&&(an(!1,G.toString()),_&&_(G))}function Z(){z({type:"RESET"})}k.useEffect(Z,[u,z]);const te=k.useCallback(async()=>{if(!u)return null;if(typeof u=="string")return Sw(u)?{data:D1(u)}:(M1(),{url:u});if(u instanceof Pne)return{range:u};if(kne(u))return{data:u};if(cp&&Nne(u))return{data:await Dne(u)};if(Je(typeof u=="object"),Je(F1(u)),"url"in u&&typeof u.url=="string"){if(Sw(u.url)){const{url:he}=u,xe=P1(u,["url"]),Ae=D1(he);return Object.assign({data:Ae},xe)}M1()}return u},[u]);k.useEffect(()=>{const he=nc(te());return he.promise.then(xe=>{z({type:"RESOLVE",value:xe})}).catch(xe=>{z({type:"REJECT",error:xe})}),()=>{$a(he)}},[te,z]),k.useEffect(()=>{if(!(typeof $>"u")){if($===!1){V();return}H()}},[$]);function re(){j&&(E&&E(j),D.current=new Array(j.numPages),F.current.setDocument(j))}function X(){B&&(an(!1,B.toString()),v&&v(B))}k.useEffect(function(){P({type:"RESET"})},[P,$]),k.useEffect(function(){if(!$)return;const xe=A?Object.assign(Object.assign({},$),A):$,Ae=LS(xe);b&&(Ae.onProgress=b),S&&(Ae.onPassword=S);const Pe=Ae,Fe=Pe.promise.then(Ct=>{P({type:"RESOLVE",value:Ct})}).catch(Ct=>{Pe.destroyed||P({type:"REJECT",error:Ct})});return()=>{Fe.finally(()=>Pe.destroy())}},[A,P,$]),k.useEffect(()=>{if(!(typeof j>"u")){if(j===!1){X();return}re()}},[j]),k.useEffect(function(){F.current.setViewer(U.current),F.current.setExternalLinkRel(o),F.current.setExternalLinkTarget(l)},[o,l]);const ee=k.useCallback((he,xe)=>{D.current[he]=xe},[]),ae=k.useCallback(he=>{delete D.current[he]},[]),se=k.useMemo(()=>({imageResourcesPath:p,linkService:F.current,onItemClick:m,pdf:j,registerPage:ee,renderMode:R,rotate:C,scale:T,unregisterPage:ae}),[p,m,j,ee,R,C,T,ae]),pe=k.useMemo(()=>gF(O,()=>j),[O,j]);function ce(){return N.jsx(mF.Provider,{value:se,children:r})}function le(){return u?j==null?N.jsx(jo,{type:"loading",children:typeof f=="function"?f():f}):j===!1?N.jsx(jo,{type:"error",children:typeof a=="function"?a():a}):ce():N.jsx(jo,{type:"no-data",children:typeof g=="function"?g():g})}return N.jsx("div",Object.assign({className:ns("react-pdf__Document",i),ref:d},pe,{children:le()}))});function vF(){return k.useContext(mF)}function EF(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=t.filter(Boolean);if(n.length<=1){var r=n[0];return r||null}return function(a){for(var o=0,l=n;o<l.length;o++){var u=l[o];typeof u=="function"?u(a):u&&(u.current=a)}}}const wF=k.createContext(null),SF={Document:null,DocumentFragment:null,Part:"group",Sect:"group",Div:"group",Aside:"note",NonStruct:"none",P:null,H:"heading",Title:null,FENote:"note",Sub:"group",Lbl:null,Span:null,Em:null,Strong:null,Link:"link",Annot:"note",Form:"form",Ruby:null,RB:null,RT:null,RP:null,Warichu:null,WT:null,WP:null,L:"list",LI:"listitem",LBody:null,Table:"table",TR:"row",TH:"columnheader",TD:"cell",THead:"columnheader",TBody:null,TFoot:null,Caption:null,Figure:"figure",Formula:null,Artifact:null},Une=/^H(\d+)$/;function $ne(t){return t in SF}function up(t){return"children"in t}function xF(t){return up(t)?t.children.length===1&&0 in t.children&&"id"in t.children[0]:!1}function zne(t){const e={};if(up(t)){const{role:n}=t,r=n.match(Une);if(r)e.role="heading",e["aria-level"]=Number(r[1]);else if($ne(n)){const i=SF[n];i&&(e.role=i)}}return e}function AF(t){const e={};if(up(t)){if(t.alt!==void 0&&(e["aria-label"]=t.alt),t.lang!==void 0&&(e.lang=t.lang),xF(t)){const[n]=t.children;if(n){const r=AF(n);return Object.assign(Object.assign({},e),r)}}}else"id"in t&&(e["aria-owns"]=t.id);return e}function jne(t){return t?Object.assign(Object.assign({},zne(t)),AF(t)):null}function _F({className:t,node:e}){const n=k.useMemo(()=>jne(e),[e]),r=k.useMemo(()=>!up(e)||xF(e)?null:e.children.map((i,a)=>N.jsx(_F,{node:i},a)),[e]);return N.jsx("span",Object.assign({className:t},n,{children:r}))}function dp(){return k.useContext(wF)}function Hne(){const t=dp();Je(t);const{onGetStructTreeError:e,onGetStructTreeSuccess:n}=t,[r,i]=ts(),{value:a,error:o}=r,{customTextRenderer:l,page:u}=t;function d(){a&&n&&n(a)}function p(){o&&(an(!1,o.toString()),e&&e(o))}return k.useEffect(function(){i({type:"RESET"})},[i,u]),k.useEffect(function(){if(l||!u)return;const g=nc(u.getStructTree()),m=g;return g.promise.then(v=>{i({type:"RESOLVE",value:v})}).catch(v=>{i({type:"REJECT",error:v})}),()=>$a(m)},[l,u,i]),k.useEffect(()=>{if(a!==void 0){if(a===!1){p();return}d()}},[a]),a?N.jsx(_F,{className:"react-pdf__Page__structTree structTree",node:a}):null}const B1=Lr;function Gne(t){const e=dp();Je(e);const n=Object.assign(Object.assign({},e),t),{_className:r,canvasBackground:i,devicePixelRatio:a=Ine(),onRenderError:o,onRenderSuccess:l,page:u,renderForms:d,renderTextLayer:p,rotate:f,scale:g}=n,{canvasRef:m}=t;Je(u);const v=k.useRef(null);function b(){u&&l&&l(xw(u,g))}function E(A){Lne(A)||(an(!1,A.toString()),o&&o(A))}const S=k.useMemo(()=>u.getViewport({scale:g*a,rotation:f}),[a,u,f,g]),_=k.useMemo(()=>u.getViewport({scale:g,rotation:f}),[u,f,g]);k.useEffect(function(){if(!u)return;u.cleanup();const{current:R}=v;if(!R)return;R.width=S.width,R.height=S.height,R.style.width=`${Math.floor(_.width)}px`,R.style.height=`${Math.floor(_.height)}px`,R.style.visibility="hidden";const C={annotationMode:d?B1.ENABLE_FORMS:B1.ENABLE,canvasContext:R.getContext("2d",{alpha:!1}),viewport:S};i&&(C.background=i);const T=u.render(C),O=T;return T.promise.then(()=>{R.style.visibility="",b()}).catch(E),()=>$a(O)},[i,u,d,S,_]);const w=k.useCallback(()=>{const{current:A}=v;A&&(A.width=0,A.height=0)},[]);return k.useEffect(()=>w,[w]),N.jsx("canvas",{className:`${r}__canvas`,dir:"ltr",ref:EF(m,v),style:{display:"block",userSelect:"none"},children:p?N.jsx(Hne,{}):null})}function qne(t){return"str"in t}function Vne(){const t=dp();Je(t);const{customTextRenderer:e,onGetTextError:n,onGetTextSuccess:r,onRenderTextLayerError:i,onRenderTextLayerSuccess:a,page:o,pageIndex:l,pageNumber:u,rotate:d,scale:p}=t;Je(o);const[f,g]=ts(),{value:m,error:v}=f,b=k.useRef(null);an(Number.parseInt(window.getComputedStyle(document.body).getPropertyValue("--react-pdf-text-layer"),10)===1,"TextLayer styles not found. Read more: https://github.com/wojtekmaj/react-pdf#support-for-text-layer");function E(){m&&r&&r(m)}function S(){v&&(an(!1,v.toString()),n&&n(v))}k.useEffect(function(){g({type:"RESET"})},[o,g]),k.useEffect(function(){if(!o)return;const O=nc(o.getTextContent()),L=O;return O.promise.then(z=>{g({type:"RESOLVE",value:z})}).catch(z=>{g({type:"REJECT",error:z})}),()=>$a(L)},[o,g]),k.useEffect(()=>{if(m!==void 0){if(m===!1){S();return}E()}},[m]);const _=k.useCallback(()=>{a&&a()},[a]),w=k.useCallback(T=>{an(!1,T.toString()),i&&i(T)},[i]);function A(){const T=b.current;T&&T.classList.add("selecting")}function R(){const T=b.current;T&&T.classList.remove("selecting")}const C=k.useMemo(()=>o.getViewport({scale:p,rotation:d}),[o,d,p]);return k.useLayoutEffect(function(){if(!o||!m)return;const{current:O}=b;if(!O)return;O.innerHTML="";const L=o.streamTextContent({includeMarkedContent:!0}),z={container:O,textContentSource:L,viewport:C},$=new Nl(z),G=$;return $.render().then(()=>{const W=document.createElement("div");W.className="endOfContent",O.append(W);const P=O.querySelectorAll('[role="presentation"]');if(e){let j=0;m.items.forEach((B,F)=>{if(!qne(B))return;const D=P[j];if(!D)return;const q=e(Object.assign({pageIndex:l,pageNumber:u,itemIndex:F},B));D.innerHTML=q,j+=B.str&&B.hasEOL?2:1})}_()}).catch(w),()=>$a(G)},[e,w,_,o,l,u,m,C]),N.jsx("div",{className:ns("react-pdf__Page__textContent","textLayer"),onMouseUp:R,onMouseDown:A,ref:b})}function Wne(){const t=vF(),e=dp();Je(e);const n=Object.assign(Object.assign({},t),e),{imageResourcesPath:r,linkService:i,onGetAnnotationsError:a,onGetAnnotationsSuccess:o,onRenderAnnotationLayerError:l,onRenderAnnotationLayerSuccess:u,page:d,pdf:p,renderForms:f,rotate:g,scale:m=1}=n;Je(p),Je(d),Je(i);const[v,b]=ts(),{value:E,error:S}=v,_=k.useRef(null);an(Number.parseInt(window.getComputedStyle(document.body).getPropertyValue("--react-pdf-annotation-layer"),10)===1,"AnnotationLayer styles not found. Read more: https://github.com/wojtekmaj/react-pdf#support-for-annotations");function w(){E&&o&&o(E)}function A(){S&&(an(!1,S.toString()),a&&a(S))}k.useEffect(function(){b({type:"RESET"})},[b,d]),k.useEffect(function(){if(!d)return;const L=nc(d.getAnnotations()),z=L;return L.promise.then($=>{b({type:"RESOLVE",value:$})}).catch($=>{b({type:"REJECT",error:$})}),()=>{$a(z)}},[b,d]),k.useEffect(()=>{if(E!==void 0){if(E===!1){A();return}w()}},[E]);function R(){u&&u()}function C(O){an(!1,`${O}`),l&&l(O)}const T=k.useMemo(()=>d.getViewport({scale:m,rotation:g}),[d,g,m]);return k.useEffect(function(){if(!p||!d||!i||!E)return;const{current:L}=_;if(!L)return;const z=T.clone({dontFlip:!0}),$={accessibilityManager:null,annotationCanvasMap:null,annotationEditorUIManager:null,div:L,l10n:null,page:d,structTreeLayer:null,viewport:z},G={annotations:E,annotationStorage:p.annotationStorage,div:L,imageResourcesPath:r,linkService:i,page:d,renderForms:f,viewport:z};L.innerHTML="";try{new BS($).render(G),R()}catch(W){C(W)}return()=>{}},[E,r,i,d,p,f,T]),N.jsx("div",{className:ns("react-pdf__Page__annotations","annotationLayer"),ref:_})}var Yne=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]]);return n};const U1=1;function Xne(t){const e=vF(),n=Object.assign(Object.assign({},e),t),{_className:r="react-pdf__Page",_enableRegisterUnregisterPage:i=!0,canvasBackground:a,canvasRef:o,children:l,className:u,customRenderer:d,customTextRenderer:p,devicePixelRatio:f,error:g="Failed to load the page.",height:m,inputRef:v,loading:b="Loading page…",noData:E="No page specified.",onGetAnnotationsError:S,onGetAnnotationsSuccess:_,onGetStructTreeError:w,onGetStructTreeSuccess:A,onGetTextError:R,onGetTextSuccess:C,onLoadError:T,onLoadSuccess:O,onRenderAnnotationLayerError:L,onRenderAnnotationLayerSuccess:z,onRenderError:$,onRenderSuccess:G,onRenderTextLayerError:W,onRenderTextLayerSuccess:P,pageIndex:j,pageNumber:B,pdf:F,registerPage:D,renderAnnotationLayer:q=!0,renderForms:K=!1,renderMode:U="canvas",renderTextLayer:H=!0,rotate:V,scale:Z=U1,unregisterPage:te,width:re}=n,X=Yne(n,["_className","_enableRegisterUnregisterPage","canvasBackground","canvasRef","children","className","customRenderer","customTextRenderer","devicePixelRatio","error","height","inputRef","loading","noData","onGetAnnotationsError","onGetAnnotationsSuccess","onGetStructTreeError","onGetStructTreeSuccess","onGetTextError","onGetTextSuccess","onLoadError","onLoadSuccess","onRenderAnnotationLayerError","onRenderAnnotationLayerSuccess","onRenderError","onRenderSuccess","onRenderTextLayerError","onRenderTextLayerSuccess","pageIndex","pageNumber","pdf","registerPage","renderAnnotationLayer","renderForms","renderMode","renderTextLayer","rotate","scale","unregisterPage","width"]),[ee,ae]=ts(),{value:se,error:pe}=ee,ce=k.useRef(null);Je(F);const le=ya(B)?B-1:j??null,he=B??(ya(j)?j+1:null),xe=V??(se?se.rotate:null),Ae=k.useMemo(()=>{if(!se)return null;let He=1;const qe=Z??U1;if(re||m){const kt=se.getViewport({scale:1,rotation:xe});re?He=re/kt.width:m&&(He=m/kt.height)}return qe*He},[m,se,xe,Z,re]);k.useEffect(function(){return()=>{ya(le)&&i&&te&&te(le)}},[i,F,le,te]);function Pe(){if(O){if(!se||!Ae)return;O(xw(se,Ae))}if(i&&D){if(!ya(le)||!ce.current)return;D(le,ce.current)}}function Fe(){pe&&(an(!1,pe.toString()),T&&T(pe))}k.useEffect(function(){ae({type:"RESET"})},[ae,F,le]),k.useEffect(function(){if(!F||!he)return;const qe=nc(F.getPage(he)),kt=qe;return qe.promise.then(Bt=>{ae({type:"RESOLVE",value:Bt})}).catch(Bt=>{ae({type:"REJECT",error:Bt})}),()=>$a(kt)},[ae,F,he]),k.useEffect(()=>{if(se!==void 0){if(se===!1){Fe();return}Pe()}},[se,Ae]);const Ct=k.useMemo(()=>se&&ya(le)&&he&&ya(xe)&&ya(Ae)?{_className:r,canvasBackground:a,customTextRenderer:p,devicePixelRatio:f,onGetAnnotationsError:S,onGetAnnotationsSuccess:_,onGetStructTreeError:w,onGetStructTreeSuccess:A,onGetTextError:R,onGetTextSuccess:C,onRenderAnnotationLayerError:L,onRenderAnnotationLayerSuccess:z,onRenderError:$,onRenderSuccess:G,onRenderTextLayerError:W,onRenderTextLayerSuccess:P,page:se,pageIndex:le,pageNumber:he,renderForms:K,renderTextLayer:H,rotate:xe,scale:Ae}:null,[r,a,p,f,S,_,w,A,R,C,L,z,$,G,W,P,se,le,he,K,H,xe,Ae]),vt=k.useMemo(()=>gF(X,()=>se&&(Ae?xw(se,Ae):void 0)),[X,se,Ae]),et=`${le}@${Ae}/${xe}`;function wt(){switch(U){case"custom":return Je(d),N.jsx(d,{},`${et}_custom`);case"none":return null;case"canvas":default:return N.jsx(Gne,{canvasRef:o},`${et}_canvas`)}}function Xt(){return H?N.jsx(Vne,{},`${et}_text`):null}function Kt(){return q?N.jsx(Wne,{},`${et}_annotations`):null}function ft(){return N.jsxs(wF.Provider,{value:Ct,children:[wt(),Xt(),Kt(),l]})}function Rt(){return he?F===null||se===void 0||se===null?N.jsx(jo,{type:"loading",children:typeof b=="function"?b():b}):F===!1||se===!1?N.jsx(jo,{type:"error",children:typeof g=="function"?g():g}):ft():N.jsx(jo,{type:"no-data",children:typeof E=="function"?E():E})}return N.jsx("div",Object.assign({className:ns(r,u),"data-page-number":he,ref:EF(v,ce),style:{"--scale-round-x":"1px","--scale-round-y":"1px","--scale-factor":"1","--user-unit":`${Ae}`,"--total-scale-factor":"calc(var(--scale-factor) * var(--user-unit))",backgroundColor:a||"white",position:"relative",minWidth:"min-content",minHeight:"min-content"}},vt,{children:Rt()}))}One();Hi.workerSrc="pdf.worker.mjs";typeof window<"u"&&(Hi.workerSrc=`//unpkg.com/pdfjs-dist@${Ol}/build/pdf.worker.min.mjs`);Gw(()=>Promise.resolve().then(()=>tre),[]);Gw(()=>Promise.resolve().then(()=>nre),void 0);var Kne={cMapUrl:`https://unpkg.com/pdfjs-dist@${Ol}/cmaps/`,wasmUrl:`https://unpkg.com/pdfjs-dist@${Ol}/wasm/`},Zne=10*1024*1024,$1="document.pdf",Qne=({fileName:t,url:e,onDownload:n,onRemove:r,highlight:i,toolbarClassName:a})=>{var o;const[l,u]=k.useState(),[d,p]=k.useState(1),[f,g]=k.useState(1),[m,v]=k.useState(null),[b,E]=k.useState(!1),[S,_]=k.useState(0),[w,A]=k.useState(!0),R=k.useRef(null),C=k.useRef({}),T=k.useRef(!1),[O,L]=k.useState({}),[z,$]=k.useState(!1),G=[{id:"highlight",x:i?.x||0,y:i?.y||0,width:i?.width||0,height:i?.height||0,color:"rgba(255, 215, 0, 0.25)"}];function W({numPages:H}){u(H),_(0),A(!0)}function P(){_(H=>{const V=H+1;return V===l&&A(!1),V})}k.useEffect(()=>{if(!i||!l)return;C.current[i.page]&&(D(i.page),$(!0))},[i,l]);const j=H=>{const V=H.getViewport({scale:1});if(L(Z=>Wt(je({},Z),{[H.pageNumber]:{width:V.width,height:V.height}})),!T.current&&H.pageNumber===1&&R.current){const X=(R.current.clientWidth-16)/V.width;g(X),T.current=!0}},B=()=>{z&&$(!1)};k.useEffect(()=>{const H=()=>{if(!R.current)return;const Z=R.current.getBoundingClientRect(),te=Z.top+Z.height/2;let re=1,X=1/0;Object.entries(C.current).forEach(([ee,ae])=>{if(ae){const se=ae.getBoundingClientRect(),pe=se.top+se.height/2,ce=Math.abs(pe-te);ce<X&&(X=ce,re=parseInt(ee))}}),p(re)},V=R.current;if(V)return V.addEventListener("scroll",H),()=>V.removeEventListener("scroll",H)},[l]);const F=k.useRef(null);k.useEffect(()=>F.current===e?void 0:(F.current=e,(async()=>{E(!0);const Z=await(await fetch(e)).blob();v(new File([Z],$1,{type:"application/pdf"})),E(!1)})(),()=>{v(null)}),[e]);const D=H=>{const V=C.current[H];V&&R.current&&V.scrollIntoView({behavior:"instant",block:"center"})};k.useEffect(()=>{const H=R.current;if(!H)return;const V=Z=>{Z.key==="ArrowLeft"?(Z.preventDefault(),d>1&&D(d-1)):Z.key==="ArrowRight"?(Z.preventDefault(),d<(l||1)&&D(d+1)):Z.key==="="||Z.key==="+"?(Z.preventDefault(),g(te=>Math.min(te+.25,3))):Z.key==="-"&&(Z.preventDefault(),g(te=>Math.max(te-.25,.5)))};return H.addEventListener("keydown",V),H.tabIndex=0,()=>{H.removeEventListener("keydown",V)}},[d,l]);const q=()=>{if(n)n();else if(m){const H=URL.createObjectURL(m),V=document.createElement("a");V.href=H,V.download=m.name,document.body.appendChild(V),V.click(),document.body.removeChild(V),URL.revokeObjectURL(H)}else window.open(e,"_blank")},K=()=>{p(1),D(1)},U=()=>{var H;document.fullscreenElement?document.exitFullscreen():(H=R.current)==null||H.requestFullscreen()};return b?N.jsx("div",{className:"relative h-full flex items-center justify-center bg-gray-50",children:N.jsxs("div",{className:"text-center",children:[N.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900 mx-auto mb-2"}),N.jsx("p",{className:"text-gray-600",children:"Loading PDF..."})]})}):N.jsxs("div",{className:"relative h-full flex flex-col",children:[w&&m&&m.size>Zne&&N.jsx(Jne,{renderedPages:S,numPages:l}),l&&N.jsxs(N.Fragment,{children:[N.jsx(WH,{fileName:(o=t??m?.name)!=null?o:$1,currentPage:d,totalPages:l,scale:f,onPageChange:D,onScaleChange:g,onDownload:q,onRemove:r,onReset:K,onFullscreen:U,className:a}),N.jsx("div",{className:"h-3 bg-[#F3F3F3]"})]}),N.jsx("div",{ref:R,className:"overflow-auto h-full bg-[#F3F3F3] rounded-lg flex-1 min-h-0",children:N.jsx(Bne,{file:m,onLoadSuccess:W,loading:b,options:Kne,children:Array.from(new Array(l),(H,V)=>N.jsx("div",{ref:Z=>{C.current[V+1]=Z},className:"mb-4 flex justify-center",children:N.jsxs("div",{className:"relative inline-block",children:[N.jsx(Xne,{pageNumber:V+1,scale:f,renderTextLayer:!0,renderAnnotationLayer:!0,onLoadSuccess:j,onClick:B,onRenderSuccess:P}),i&&z&&i.page===V+1&&O[V+1]&&N.jsx(VH,{boundingBoxes:G,zoom:f,containerWidth:O[V+1].width,containerHeight:O[V+1].height})]})},`page_${V+1}`))})})]})};function Jne({renderedPages:t,numPages:e}){return N.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-50 bg-opacity-90 z-50",children:N.jsxs("div",{className:"bg-white shadow-lg rounded-2xl p-6 w-80 text-center",children:[N.jsx("div",{className:"flex justify-center mb-4",children:N.jsx("div",{className:"animate-spin rounded-full h-10 w-10 border-4 border-primary border-t-transparent"})}),N.jsx("h2",{className:"text-lg font-semibold text-gray-800 mb-2",children:"Rendering PDF…"}),N.jsxs("p",{className:"text-sm text-gray-600 mb-3",children:["Page ",t," of ",e]}),N.jsx("div",{className:"w-full bg-gray-200 rounded-full h-2.5 mb-4",children:N.jsx("div",{className:"bg-primary h-2.5 rounded-full transition-all duration-300",style:{width:e&&e>0?`${Math.round(t/e*100)}%`:"0%"}})}),N.jsx("p",{className:"text-xs text-gray-500",children:"Large PDFs or those with heavy images may take longer to render."})]})})}const ere=Object.freeze(Object.defineProperty({__proto__:null,PdfPreviewImpl:Qne},Symbol.toStringTag,{value:"Module"})),tre=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),nre=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@llamaindex/workflow-debugger",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/*"
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"react": "^18.3.1",
|
|
16
16
|
"react-dom": "^18.3.1",
|
|
17
17
|
"react-syntax-highlighter": "^15.6.6",
|
|
18
|
-
"@llamaindex/ui": "2.1.
|
|
18
|
+
"@llamaindex/ui": "2.1.7",
|
|
19
19
|
"@llamaindex/workflows-client": "1.5.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"typescript": "~5.8.3",
|
|
37
37
|
"typescript-eslint": "^8.44.0",
|
|
38
38
|
"vite": "^7.1.7",
|
|
39
|
-
"@llamaindex/ui": "2.1.
|
|
39
|
+
"@llamaindex/ui": "2.1.7",
|
|
40
40
|
"@llamaindex/workflows-client": "1.5.0"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|