@component-hook/pdf-canvas 1.4.3 → 1.4.4-alpha.0

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.
@@ -9,4 +9,4 @@ var ii=G=>{throw TypeError(G)};var hs=(G,x,B)=>x.has(G)||ii("Cannot "+B);var vt=
9
9
  `)}`,this.#u();const d=new Range;let u=l.reduce((f,p)=>f+p.length,0);for(const{firstChild:f}of this.editorDiv.childNodes)if(f.nodeType===Node.TEXT_NODE){const p=f.nodeValue.length;if(u<=p){d.setStart(f,u),d.setEnd(f,u);break}u-=p}n.removeAllRanges(),n.addRange(d)}#u(){if(this.editorDiv.replaceChildren(),!!this.#e)for(const t of this.#e.split(`
10
10
  `)){const e=document.createElement("div");e.append(t?document.createTextNode(t):document.createElement("br")),this.editorDiv.append(e)}}#d(){return this.#e.replaceAll(" "," ")}static#f(t){return t.replaceAll(" "," ")}get contentDiv(){return this.editorDiv}static async deserialize(t,e,s){let i=null;if(t instanceof Qs){const{data:{defaultAppearanceData:{fontSize:r,fontColor:a},rect:o,rotation:l,id:h,popupRef:d},textContent:u,textPosition:f,parent:{page:{pageNumber:p}}}=t;if(!u||u.length===0)return null;i=t={annotationType:L.FREETEXT,color:Array.from(a),fontSize:r,value:u.join(`
11
11
  `),position:f,pageIndex:p-1,rect:o.slice(0),rotation:l,id:h,deleted:!1,popupRef:d}}const n=await super.deserialize(t,e,s);return n.#r=t.fontSize,n.#t=T.makeHexColor(...t.color),n.#e=J.#f(t.value),n.annotationElementId=t.id||null,n._initialData=i,n}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const e=J._internalPadding*this.parentScale,s=this.getRect(e,e),i=M._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:this.#t),n={annotationType:L.FREETEXT,color:i,fontSize:this.#r,value:this.#d(),pageIndex:this.pageIndex,rect:s,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return t?n:this.annotationElementId&&!this.#a(n)?null:(n.id=this.annotationElementId,n)}#a(t){const{value:e,fontSize:s,color:i,pageIndex:n}=this._initialData;return this._hasBeenMoved||t.value!==e||t.fontSize!==s||t.color.some((r,a)=>r!==i[a])||t.pageIndex!==n}renderAnnotationElement(t){const e=super.renderAnnotationElement(t);if(this.deleted)return e;const{style:s}=e;s.fontSize=`calc(${this.#r}px * var(--scale-factor))`,s.color=this.#t,e.replaceChildren();for(const n of this.#e.split(`
12
- `)){const r=document.createElement("div");r.append(n?document.createTextNode(n):document.createElement("br")),e.append(r)}const i=J._internalPadding*this.parentScale;return t.updateEdited({rect:this.getRect(i,i),popupContent:this.#e}),e}resetAnnotationElement(t){super.resetAnnotationElement(t),t.resetEdited()}}class E{static PRECISION=1e-4;toSVGPath(){$("Abstract method `toSVGPath` must be implemented.")}get box(){$("Abstract getter `box` must be implemented.")}serialize(t,e){$("Abstract method `serialize` must be implemented.")}static _rescale(t,e,s,i,n,r){r||=new Float32Array(t.length);for(let a=0,o=t.length;a<o;a+=2)r[a]=e+t[a]*i,r[a+1]=s+t[a+1]*n;return r}static _rescaleAndSwap(t,e,s,i,n,r){r||=new Float32Array(t.length);for(let a=0,o=t.length;a<o;a+=2)r[a]=e+t[a+1]*i,r[a+1]=s+t[a]*n;return r}static _translate(t,e,s,i){i||=new Float32Array(t.length);for(let n=0,r=t.length;n<r;n+=2)i[n]=e+t[n],i[n+1]=s+t[n+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,s,i,n){switch(n){case 90:return[1-e/s,t/i];case 180:return[1-t/s,1-e/i];case 270:return[e/s,1-t/i];default:return[t/s,e/i]}}static _normalizePagePoint(t,e,s){switch(s){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,s,i,n,r){return[(t+5*s)/6,(e+5*i)/6,(5*s+n)/6,(5*i+r)/6,(s+n)/2,(i+r)/2]}}class Ot{#t;#e=[];#s;#i;#r=[];#n=new Float32Array(18);#l;#o;#c;#h;#u;#d;#f=[];static#a=8;static#p=2;static#m=Ot.#a+Ot.#p;constructor({x:t,y:e},s,i,n,r,a=0){this.#t=s,this.#d=n*i,this.#i=r,this.#n.set([NaN,NaN,NaN,NaN,t,e],6),this.#s=a,this.#h=Ot.#a*i,this.#c=Ot.#m*i,this.#u=i,this.#f.push(t,e)}isEmpty(){return isNaN(this.#n[8])}#g(){const t=this.#n.subarray(4,6),e=this.#n.subarray(16,18),[s,i,n,r]=this.#t;return[(this.#l+(t[0]-e[0])/2-s)/n,(this.#o+(t[1]-e[1])/2-i)/r,(this.#l+(e[0]-t[0])/2-s)/n,(this.#o+(e[1]-t[1])/2-i)/r]}add({x:t,y:e}){this.#l=t,this.#o=e;const[s,i,n,r]=this.#t;let[a,o,l,h]=this.#n.subarray(8,12);const d=t-l,u=e-h,f=Math.hypot(d,u);if(f<this.#c)return!1;const p=f-this.#h,g=p/f,b=g*d,m=g*u;let A=a,y=o;a=l,o=h,l+=b,h+=m,this.#f?.push(t,e);const v=-m/p,w=b/p,S=v*this.#d,_=w*this.#d;return this.#n.set(this.#n.subarray(2,8),0),this.#n.set([l+S,h+_],4),this.#n.set(this.#n.subarray(14,18),12),this.#n.set([l-S,h-_],16),isNaN(this.#n[6])?(this.#r.length===0&&(this.#n.set([a+S,o+_],2),this.#r.push(NaN,NaN,NaN,NaN,(a+S-s)/n,(o+_-i)/r),this.#n.set([a-S,o-_],14),this.#e.push(NaN,NaN,NaN,NaN,(a-S-s)/n,(o-_-i)/r)),this.#n.set([A,y,a,o,l,h],6),!this.isEmpty()):(this.#n.set([A,y,a,o,l,h],6),Math.abs(Math.atan2(y-o,A-a)-Math.atan2(m,b))<Math.PI/2?([a,o,l,h]=this.#n.subarray(2,6),this.#r.push(NaN,NaN,NaN,NaN,((a+l)/2-s)/n,((o+h)/2-i)/r),[a,o,A,y]=this.#n.subarray(14,18),this.#e.push(NaN,NaN,NaN,NaN,((A+a)/2-s)/n,((y+o)/2-i)/r),!0):([A,y,a,o,l,h]=this.#n.subarray(0,6),this.#r.push(((A+5*a)/6-s)/n,((y+5*o)/6-i)/r,((5*a+l)/6-s)/n,((5*o+h)/6-i)/r,((a+l)/2-s)/n,((o+h)/2-i)/r),[l,h,a,o,A,y]=this.#n.subarray(12,18),this.#e.push(((A+5*a)/6-s)/n,((y+5*o)/6-i)/r,((5*a+l)/6-s)/n,((5*o+h)/6-i)/r,((a+l)/2-s)/n,((o+h)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=this.#r,e=this.#e;if(isNaN(this.#n[6])&&!this.isEmpty())return this.#b();const s=[];s.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?s.push(`L${t[i+4]} ${t[i+5]}`):s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);this.#A(s);for(let i=e.length-6;i>=6;i-=6)isNaN(e[i])?s.push(`L${e[i+4]} ${e[i+5]}`):s.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return this.#v(s),s.join(" ")}#b(){const[t,e,s,i]=this.#t,[n,r,a,o]=this.#g();return`M${(this.#n[2]-t)/s} ${(this.#n[3]-e)/i} L${(this.#n[4]-t)/s} ${(this.#n[5]-e)/i} L${n} ${r} L${a} ${o} L${(this.#n[16]-t)/s} ${(this.#n[17]-e)/i} L${(this.#n[14]-t)/s} ${(this.#n[15]-e)/i} Z`}#v(t){const e=this.#e;t.push(`L${e[4]} ${e[5]} Z`)}#A(t){const[e,s,i,n]=this.#t,r=this.#n.subarray(4,6),a=this.#n.subarray(16,18),[o,l,h,d]=this.#g();t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${o} ${l} L${h} ${d} L${(a[0]-e)/i} ${(a[1]-s)/n}`)}newFreeDrawOutline(t,e,s,i,n,r){return new ei(t,e,s,i,n,r)}getOutlines(){const t=this.#r,e=this.#e,s=this.#n,[i,n,r,a]=this.#t,o=new Float32Array((this.#f?.length??0)+2);for(let d=0,u=o.length-2;d<u;d+=2)o[d]=(this.#f[d]-i)/r,o[d+1]=(this.#f[d+1]-n)/a;if(o[o.length-2]=(this.#l-i)/r,o[o.length-1]=(this.#o-n)/a,isNaN(s[6])&&!this.isEmpty())return this.#w(o);const l=new Float32Array(this.#r.length+24+this.#e.length);let h=t.length;for(let d=0;d<h;d+=2){if(isNaN(t[d])){l[d]=l[d+1]=NaN;continue}l[d]=t[d],l[d+1]=t[d+1]}h=this.#x(l,h);for(let d=e.length-6;d>=6;d-=6)for(let u=0;u<6;u+=2){if(isNaN(e[d+u])){l[h]=l[h+1]=NaN,h+=2;continue}l[h]=e[d+u],l[h+1]=e[d+u+1],h+=2}return this.#S(l,h),this.newFreeDrawOutline(l,o,this.#t,this.#u,this.#s,this.#i)}#w(t){const e=this.#n,[s,i,n,r]=this.#t,[a,o,l,h]=this.#g(),d=new Float32Array(36);return d.set([NaN,NaN,NaN,NaN,(e[2]-s)/n,(e[3]-i)/r,NaN,NaN,NaN,NaN,(e[4]-s)/n,(e[5]-i)/r,NaN,NaN,NaN,NaN,a,o,NaN,NaN,NaN,NaN,l,h,NaN,NaN,NaN,NaN,(e[16]-s)/n,(e[17]-i)/r,NaN,NaN,NaN,NaN,(e[14]-s)/n,(e[15]-i)/r],0),this.newFreeDrawOutline(d,t,this.#t,this.#u,this.#s,this.#i)}#S(t,e){const s=this.#e;return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6}#x(t,e){const s=this.#n.subarray(4,6),i=this.#n.subarray(16,18),[n,r,a,o]=this.#t,[l,h,d,u]=this.#g();return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/a,(s[1]-r)/o,NaN,NaN,NaN,NaN,l,h,NaN,NaN,NaN,NaN,d,u,NaN,NaN,NaN,NaN,(i[0]-n)/a,(i[1]-r)/o],e),e+=24}}class ei extends E{#t;#e=new Float32Array(4);#s;#i;#r;#n;#l;constructor(t,e,s,i,n,r){super(),this.#l=t,this.#r=e,this.#t=s,this.#n=i,this.#s=n,this.#i=r,this.lastPoint=[NaN,NaN],this.#o(r);const[a,o,l,h]=this.#e;for(let d=0,u=t.length;d<u;d+=2)t[d]=(t[d]-a)/l,t[d+1]=(t[d+1]-o)/h;for(let d=0,u=e.length;d<u;d+=2)e[d]=(e[d]-a)/l,e[d+1]=(e[d+1]-o)/h}toSVGPath(){const t=[`M${this.#l[4]} ${this.#l[5]}`];for(let e=6,s=this.#l.length;e<s;e+=6){if(isNaN(this.#l[e])){t.push(`L${this.#l[e+4]} ${this.#l[e+5]}`);continue}t.push(`C${this.#l[e]} ${this.#l[e+1]} ${this.#l[e+2]} ${this.#l[e+3]} ${this.#l[e+4]} ${this.#l[e+5]}`)}return t.push("Z"),t.join(" ")}serialize([t,e,s,i],n){const r=s-t,a=i-e;let o,l;switch(n){case 0:o=E._rescale(this.#l,t,i,r,-a),l=E._rescale(this.#r,t,i,r,-a);break;case 90:o=E._rescaleAndSwap(this.#l,t,e,r,a),l=E._rescaleAndSwap(this.#r,t,e,r,a);break;case 180:o=E._rescale(this.#l,s,e,-r,a),l=E._rescale(this.#r,s,e,-r,a);break;case 270:o=E._rescaleAndSwap(this.#l,s,i,-r,-a),l=E._rescaleAndSwap(this.#r,s,i,-r,-a);break}return{outline:Array.from(o),points:[Array.from(l)]}}#o(t){const e=this.#l;let s=e[4],i=e[5],n=s,r=i,a=s,o=i,l=s,h=i;const d=t?Math.max:Math.min;for(let f=6,p=e.length;f<p;f+=6){if(isNaN(e[f]))n=Math.min(n,e[f+4]),r=Math.min(r,e[f+5]),a=Math.max(a,e[f+4]),o=Math.max(o,e[f+5]),h<e[f+5]?(l=e[f+4],h=e[f+5]):h===e[f+5]&&(l=d(l,e[f+4]));else{const g=T.bezierBoundingBox(s,i,...e.slice(f,f+6));n=Math.min(n,g[0]),r=Math.min(r,g[1]),a=Math.max(a,g[2]),o=Math.max(o,g[3]),h<g[3]?(l=g[2],h=g[3]):h===g[3]&&(l=d(l,g[2]))}s=e[f+4],i=e[f+5]}const u=this.#e;u[0]=n-this.#s,u[1]=r-this.#s,u[2]=a-n+2*this.#s,u[3]=o-r+2*this.#s,this.lastPoint=[l,h]}get box(){return this.#e}newOutliner(t,e,s,i,n,r=0){return new Ot(t,e,s,i,n,r)}getNewOutline(t,e){const[s,i,n,r]=this.#e,[a,o,l,h]=this.#t,d=n*l,u=r*h,f=s*l+a,p=i*h+o,g=this.newOutliner({x:this.#r[0]*d+f,y:this.#r[1]*u+p},this.#t,this.#n,t,this.#i,e??this.#s);for(let b=2;b<this.#r.length;b+=2)g.add({x:this.#r[b]*d+f,y:this.#r[b+1]*u+p});return g.getOutlines()}}class ns{#t;#e;#s=[];#i=[];constructor(t,e=0,s=0,i=!0){let n=1/0,r=-1/0,a=1/0,o=-1/0;const l=10**-4;for(const{x:b,y:m,width:A,height:y}of t){const v=Math.floor((b-e)/l)*l,w=Math.ceil((b+A+e)/l)*l,S=Math.floor((m-e)/l)*l,_=Math.ceil((m+y+e)/l)*l,P=[v,S,_,!0],I=[w,S,_,!1];this.#s.push(P,I),n=Math.min(n,v),r=Math.max(r,w),a=Math.min(a,S),o=Math.max(o,_)}const h=r-n+2*s,d=o-a+2*s,u=n-s,f=a-s,p=this.#s.at(i?-1:-2),g=[p[0],p[2]];for(const b of this.#s){const[m,A,y]=b;b[0]=(m-u)/h,b[1]=(A-f)/d,b[2]=(y-f)/d}this.#t=new Float32Array([u,f,h,d]),this.#e=g}getOutlines(){this.#s.sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of this.#s)e[3]?(t.push(...this.#c(e)),this.#l(e)):(this.#o(e),t.push(...this.#c(e)));return this.#r(t)}#r(t){const e=[],s=new Set;for(const r of t){const[a,o,l]=r;e.push([a,o,r],[a,l,r])}e.sort((r,a)=>r[1]-a[1]||r[0]-a[0]);for(let r=0,a=e.length;r<a;r+=2){const o=e[r][2],l=e[r+1][2];o.push(l),l.push(o),s.add(o),s.add(l)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[a,o,l,h,d]=r;s.delete(r);let u=a,f=o;for(n=[a,l],i.push(n);;){let p;if(s.has(h))p=h;else if(s.has(d))p=d;else break;s.delete(p),[a,o,l,h,d]=p,u!==a&&(n.push(u,f,a,f===o?o:l),u=a),f=f===o?l:o}n.push(u,f)}return new er(i,this.#t,this.#e)}#n(t){const e=this.#i;let s=0,i=e.length-1;for(;s<=i;){const n=s+i>>1,r=e[n][0];if(r===t)return n;r<t?s=n+1:i=n-1}return i+1}#l([,t,e]){const s=this.#n(t);this.#i.splice(s,0,[t,e])}#o([,t,e]){const s=this.#n(t);for(let i=s;i<this.#i.length;i++){const[n,r]=this.#i[i];if(n!==t)break;if(n===t&&r===e){this.#i.splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=this.#i[i];if(n!==t)break;if(n===t&&r===e){this.#i.splice(i,1);return}}}#c(t){const[e,s,i]=t,n=[[e,s,i]],r=this.#n(i);for(let a=0;a<r;a++){const[o,l]=this.#i[a];for(let h=0,d=n.length;h<d;h++){const[,u,f]=n[h];if(!(l<=u||f<=o)){if(u>=o){if(f>l)n[h][1]=l;else{if(d===1)return[];n.splice(h,1),h--,d--}continue}n[h][2]=o,f>l&&n.push([e,l,f])}}}return n}}class er extends E{#t;#e;constructor(t,e,s){super(),this.#e=t,this.#t=e,this.lastPoint=s}toSVGPath(){const t=[];for(const e of this.#e){let[s,i]=e;t.push(`M${s} ${i}`);for(let n=2;n<e.length;n+=2){const r=e[n],a=e[n+1];r===s?(t.push(`V${a}`),i=a):a===i&&(t.push(`H${r}`),s=r)}t.push("Z")}return t.join(" ")}serialize([t,e,s,i],n){const r=[],a=s-t,o=i-e;for(const l of this.#e){const h=new Array(l.length);for(let d=0;d<l.length;d+=2)h[d]=t+l[d]*a,h[d+1]=i-l[d+1]*o;r.push(h)}return r}get box(){return this.#t}get classNamesForOutlining(){return["highlightOutline"]}}class rs extends Ot{newFreeDrawOutline(t,e,s,i,n,r){return new sr(t,e,s,i,n,r)}}class sr extends ei{newOutliner(t,e,s,i,n,r=0){return new rs(t,e,s,i,n,r)}}class mt{#t=null;#e=null;#s;#i=null;#r=!1;#n=!1;#l=null;#o;#c=null;#h=null;#u;static#d=null;static get _keyboardManager(){return F(this,"_keyboardManager",new se([[["Escape","mac+Escape"],mt.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],mt.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],mt.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],mt.prototype._moveToPrevious],[["Home","mac+Home"],mt.prototype._moveToBeginning],[["End","mac+End"],mt.prototype._moveToEnd]]))}constructor({editor:t=null,uiManager:e=null}){t?(this.#n=!1,this.#u=O.HIGHLIGHT_COLOR,this.#l=t):(this.#n=!0,this.#u=O.HIGHLIGHT_DEFAULT_COLOR),this.#h=t?._uiManager||e,this.#o=this.#h._eventBus,this.#s=t?.color||this.#h?.highlightColors.values().next().value||"#FFFF98",mt.#d||=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 t=this.#t=document.createElement("button");t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);const e=this.#h._signal;t.addEventListener("click",this.#m.bind(this),{signal:e}),t.addEventListener("keydown",this.#p.bind(this),{signal:e});const s=this.#e=document.createElement("span");return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=this.#s,t.append(s),t}renderMainDropdown(){const t=this.#i=this.#f();return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}#f(){const t=document.createElement("div"),e=this.#h._signal;t.addEventListener("contextmenu",yt,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[s,i]of this.#h.highlightColors){const n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",mt.#d[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===this.#s),n.addEventListener("click",this.#a.bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",this.#p.bind(this),{signal:e}),t}#a(t,e){e.stopPropagation(),this.#o.dispatch("switchannotationeditorparams",{source:this,type:this.#u,value:t})}_colorSelectFromKeyboard(t){if(t.target===this.#t){this.#m(t);return}const e=t.target.getAttribute("data-color");e&&this.#a(e,t)}_moveToNext(t){if(!this.#b){this.#m(t);return}if(t.target===this.#t){this.#i.firstChild?.focus();return}t.target.nextSibling?.focus()}_moveToPrevious(t){if(t.target===this.#i?.firstChild||t.target===this.#t){this.#b&&this._hideDropdownFromKeyboard();return}this.#b||this.#m(t),t.target.previousSibling?.focus()}_moveToBeginning(t){if(!this.#b){this.#m(t);return}this.#i.firstChild?.focus()}_moveToEnd(t){if(!this.#b){this.#m(t);return}this.#i.lastChild?.focus()}#p(t){mt._keyboardManager.exec(this,t)}#m(t){if(this.#b){this.hideDropdown();return}if(this.#r=t.detail===0,this.#c||(this.#c=new AbortController,window.addEventListener("pointerdown",this.#g.bind(this),{signal:this.#h.combinedSignal(this.#c)})),this.#i){this.#i.classList.remove("hidden");return}const e=this.#i=this.#f();this.#t.append(e)}#g(t){this.#i?.contains(t.target)||this.hideDropdown()}hideDropdown(){this.#i?.classList.add("hidden"),this.#c?.abort(),this.#c=null}get#b(){return this.#i&&!this.#i.classList.contains("hidden")}_hideDropdownFromKeyboard(){if(!this.#n){if(!this.#b){this.#l?.unselect();return}this.hideDropdown(),this.#t.focus({preventScroll:!0,focusVisible:this.#r})}}updateColor(t){if(this.#e&&(this.#e.style.backgroundColor=t),!this.#i)return;const e=this.#h.highlightColors.values();for(const s of this.#i.children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){this.#t?.remove(),this.#t=null,this.#e=null,this.#i?.remove(),this.#i=null}}class q extends M{#t=null;#e=0;#s;#i=null;#r=null;#n=null;#l=null;#o=0;#c=null;#h=null;#u=null;#d=!1;#f=null;#a;#p=null;#m="";#g;#b="";static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type="highlight";static _editorType=L.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId="";static get _keyboardManager(){const t=q.prototype;return F(this,"_keyboardManager",new se([[["ArrowLeft","mac+ArrowLeft"],t._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],t._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],t._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],t._moveCaret,{args:[3]}]]))}constructor(t){super({...t,name:"highlightEditor"}),this.color=t.color||q._defaultColor,this.#g=t.thickness||q._defaultThickness,this.#a=t.opacity||q._defaultOpacity,this.#s=t.boxes||null,this.#b=t.methodOfCreation||"",this.#m=t.text||"",this._isDraggable=!1,t.highlightId>-1?(this.#d=!0,this.#A(t),this.#R()):this.#s&&(this.#t=t.anchorNode,this.#e=t.anchorOffset,this.#l=t.focusNode,this.#o=t.focusOffset,this.#v(),this.#R(),this.rotate(this.rotation))}get telemetryInitialData(){return{action:"added",type:this.#d?"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(t){return{numberOfColors:t.get("color").size}}#v(){const t=new ns(this.#s,.001);this.#h=t.getOutlines(),[this.x,this.y,this.width,this.height]=this.#h.box;const e=new ns(this.#s,.0025,.001,this._uiManager.direction==="ltr");this.#n=e.getOutlines();const{lastPoint:s}=this.#n;this.#f=[(s[0]-this.x)/this.width,(s[1]-this.y)/this.height]}#A({highlightOutlines:t,highlightId:e,clipPathId:s}){this.#h=t;const i=1.5;if(this.#n=t.getNewOutline(this.#g/2+i,.0025),e>=0)this.#u=e,this.#i=s,this.parent.drawLayer.finalizeDraw(e,{bbox:t.box,path:{d:t.toSVGPath()}}),this.#p=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#n.box,path:{d:this.#n.toSVGPath()}},!0);else if(this.parent){const h=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#u,{bbox:q.#_(this.#h.box,(h-this.rotation+360)%360),path:{d:t.toSVGPath()}}),this.parent.drawLayer.updateProperties(this.#p,{bbox:q.#_(this.#n.box,h),path:{d:this.#n.toSVGPath()}})}const[n,r,a,o]=t.box;switch(this.rotation){case 0:this.x=n,this.y=r,this.width=a,this.height=o;break;case 90:{const[h,d]=this.parentDimensions;this.x=r,this.y=1-n,this.width=a*d/h,this.height=o*h/d;break}case 180:this.x=1-n,this.y=1-r,this.width=a,this.height=o;break;case 270:{const[h,d]=this.parentDimensions;this.x=1-r,this.y=n,this.width=a*d/h,this.height=o*h/d;break}}const{lastPoint:l}=this.#n;this.#f=[(l[0]-n)/a,(l[1]-r)/o]}static initialize(t,e){M.initialize(t,e),q._defaultColor||=e.highlightColors?.values().next().value||"#fff066"}static updateDefaultParams(t,e){switch(t){case O.HIGHLIGHT_DEFAULT_COLOR:q._defaultColor=e;break;case O.HIGHLIGHT_THICKNESS:q._defaultThickness=e;break}}translateInPage(t,e){}get toolbarPosition(){return this.#f}updateParams(t,e){switch(t){case O.HIGHLIGHT_COLOR:this.#w(e);break;case O.HIGHLIGHT_THICKNESS:this.#S(e);break}}static get defaultPropertiesToUpdate(){return[[O.HIGHLIGHT_DEFAULT_COLOR,q._defaultColor],[O.HIGHLIGHT_THICKNESS,q._defaultThickness]]}get propertiesToUpdate(){return[[O.HIGHLIGHT_COLOR,this.color||q._defaultColor],[O.HIGHLIGHT_THICKNESS,this.#g||q._defaultThickness],[O.HIGHLIGHT_FREE,this.#d]]}#w(t){const e=(n,r)=>{this.color=n,this.#a=r,this.parent?.drawLayer.updateProperties(this.#u,{root:{fill:n,"fill-opacity":r}}),this.#r?.updateColor(n)},s=this.color,i=this.#a;this.addCommands({cmd:e.bind(this,t,q._defaultOpacity),undo:e.bind(this,s,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:O.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(t)},!0)}#S(t){const e=this.#g,s=i=>{this.#g=i,this.#x(i)};this.addCommands({cmd:s.bind(this,t),undo:s.bind(this,e),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:O.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:t},!0)}async addEditToolbar(){const t=await super.addEditToolbar();return t?(this._uiManager.highlightColors&&(this.#r=new mt({editor:this}),t.addColorPicker(this.#r)),t):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(this.#k())}getBaseTranslation(){return[0,0]}getRect(t,e){return super.getRect(t,e,this.#k())}onceAdded(t){this.annotationElementId||this.parent.addUndoableEditor(this),t&&this.div.focus()}remove(){this.#T(),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#R(),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){let e=!1;this.parent&&!t?this.#T():t&&(this.#R(t),e=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(t),this.show(this._isVisible),e&&this.select()}#x(t){if(!this.#d)return;this.#A({highlightOutlines:this.#h.getNewOutline(t/2)}),this.fixAndSetPosition();const[e,s]=this.parentDimensions;this.setDims(this.width*e,this.height*s)}#T(){this.#u===null||!this.parent||(this.parent.drawLayer.remove(this.#u),this.#u=null,this.parent.drawLayer.remove(this.#p),this.#p=null)}#R(t=this.parent){this.#u===null&&({id:this.#u,clipPathId:this.#i}=t.drawLayer.draw({bbox:this.#h.box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":this.#a},rootClass:{highlight:!0,free:this.#d},path:{d:this.#h.toSVGPath()}},!1,!0),this.#p=t.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#d},bbox:this.#n.box,path:{d:this.#n.toSVGPath()}},this.#d),this.#c&&(this.#c.style.clipPath=this.#i))}static#_([t,e,s,i],n){switch(n){case 90:return[1-e-i,t,i,s];case 180:return[1-t-s,1-e-i,s,i];case 270:return[e,1-t-s,i,s]}return[t,e,s,i]}rotate(t){const{drawLayer:e}=this.parent;let s;this.#d?(t=(t-this.rotation+360)%360,s=q.#_(this.#h.box,t)):s=q.#_([this.x,this.y,this.width,this.height],t),e.updateProperties(this.#u,{bbox:s,root:{"data-main-rotation":t}}),e.updateProperties(this.#p,{bbox:q.#_(this.#n.box,t),root:{"data-main-rotation":t}})}render(){if(this.div)return this.div;const t=super.render();this.#m&&(t.setAttribute("aria-label",this.#m),t.setAttribute("role","mark")),this.#d?t.classList.add("free"):this.div.addEventListener("keydown",this.#P.bind(this),{signal:this._uiManager._signal});const e=this.#c=document.createElement("div");t.append(e),e.setAttribute("aria-hidden","true"),e.className="internal",e.style.clipPath=this.#i;const[s,i]=this.parentDimensions;return this.setDims(this.width*s,this.height*i),ve(this,this.#c,["pointerover","pointerleave"]),this.enableEditing(),t}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#p,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#p,{rootClass:{hovered:!1}})}#P(t){q._keyboardManager.exec(this,t)}_moveCaret(t){switch(this.parent.unselect(this),t){case 0:case 2:this.#C(!0);break;case 1:case 3:this.#C(!1);break}}#C(t){if(!this.#t)return;const e=window.getSelection();t?e.setPosition(this.#t,this.#e):e.setPosition(this.#l,this.#o)}select(){super.select(),this.#p&&this.parent?.drawLayer.updateProperties(this.#p,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect(),this.#p&&(this.parent?.drawLayer.updateProperties(this.#p,{rootClass:{selected:!1}}),this.#d||this.#C(!1))}get _mustFixPosition(){return!this.#d}show(t=this._isVisible){super.show(t),this.parent&&(this.parent.drawLayer.updateProperties(this.#u,{rootClass:{hidden:!t}}),this.parent.drawLayer.updateProperties(this.#p,{rootClass:{hidden:!t}}))}#k(){return this.#d?this.rotation:0}#D(){if(this.#d)return null;const[t,e]=this.pageDimensions,[s,i]=this.pageTranslation,n=this.#s,r=new Float32Array(n.length*8);let a=0;for(const{x:o,y:l,width:h,height:d}of n){const u=o*t+s,f=(1-l)*e+i;r[a]=r[a+4]=u,r[a+1]=r[a+3]=f,r[a+2]=r[a+6]=u+h*t,r[a+5]=r[a+7]=f-d*e,a+=8}return r}#N(t){return this.#h.serialize(t,this.#k())}static startHighlighting(t,e,{target:s,x:i,y:n}){const{x:r,y:a,width:o,height:l}=s.getBoundingClientRect(),h=new AbortController,d=t.combinedSignal(h),u=f=>{h.abort(),this.#y(t,f)};window.addEventListener("blur",u,{signal:d}),window.addEventListener("pointerup",u,{signal:d}),window.addEventListener("pointerdown",ft,{capture:!0,passive:!1,signal:d}),window.addEventListener("contextmenu",yt,{signal:d}),s.addEventListener("pointermove",this.#E.bind(this,t),{signal:d}),this._freeHighlight=new rs({x:i,y:n},[r,a,o,l],t.scale,this._defaultThickness/2,e,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=t.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(t,e){this._freeHighlight.add(e)&&t.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#y(t,e){this._freeHighlight.isEmpty()?t.drawLayer.remove(this._freeHighlightId):t.createAndAddNewEditor(e,!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(t,e,s){let i=null;if(t instanceof Zs){const{data:{quadPoints:p,rect:g,rotation:b,id:m,color:A,opacity:y,popupRef:v},parent:{page:{pageNumber:w}}}=t;i=t={annotationType:L.HIGHLIGHT,color:Array.from(A),opacity:y,quadPoints:p,boxes:null,pageIndex:w-1,rect:g.slice(0),rotation:b,id:m,deleted:!1,popupRef:v}}else if(t instanceof is){const{data:{inkLists:p,rect:g,rotation:b,id:m,color:A,borderStyle:{rawWidth:y},popupRef:v},parent:{page:{pageNumber:w}}}=t;i=t={annotationType:L.HIGHLIGHT,color:Array.from(A),thickness:y,inkLists:p,boxes:null,pageIndex:w-1,rect:g.slice(0),rotation:b,id:m,deleted:!1,popupRef:v}}const{color:n,quadPoints:r,inkLists:a,opacity:o}=t,l=await super.deserialize(t,e,s);l.color=T.makeHexColor(...n),l.#a=o||1,a&&(l.#g=t.thickness),l.annotationElementId=t.id||null,l._initialData=i;const[h,d]=l.pageDimensions,[u,f]=l.pageTranslation;if(r){const p=l.#s=[];for(let g=0;g<r.length;g+=8)p.push({x:(r[g]-u)/h,y:1-(r[g+1]-f)/d,width:(r[g+2]-r[g])/h,height:(r[g+1]-r[g+5])/d});l.#v(),l.#R(),l.rotate(l.rotation)}else if(a){l.#d=!0;const p=a[0],g={x:p[0]-u,y:d-(p[1]-f)},b=new rs(g,[0,0,h,d],1,l.#g/2,!0,.001);for(let y=0,v=p.length;y<v;y+=2)g.x=p[y]-u,g.y=d-(p[y+1]-f),b.add(g);const{id:m,clipPathId:A}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:l.color,"fill-opacity":l._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:b.toSVGPath()}},!0,!0);l.#A({highlightOutlines:b.getOutlines(),highlightId:m,clipPathId:A}),l.#R()}return l}serialize(t=!1){if(this.isEmpty()||t)return null;if(this.deleted)return this.serializeDeleted();const e=this.getRect(0,0),s=M._colorManager.convert(this.color),i={annotationType:L.HIGHLIGHT,color:s,opacity:this.#a,thickness:this.#g,quadPoints:this.#D(),outlines:this.#N(e),pageIndex:this.pageIndex,rect:e,rotation:this.#k(),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!this.#L(i)?null:(i.id=this.annotationElementId,i)}#L(t){const{color:e}=this._initialData;return t.color.some((s,i)=>s!==e[i])}renderAnnotationElement(t){return t.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}}class ir{#t=Object.create(null);updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(const[e,s]of Object.entries(t))this.updateProperty(e,s)}updateSVGProperty(t,e){this.#t[t]=e}toSVGProperties(){const t=this.#t;return this.#t=Object.create(null),{root:t}}reset(){this.#t=Object.create(null)}updateAll(t=this){this.updateProperties(t)}clone(){$("Not implemented")}}class k extends M{#t=null;#e;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#s=null;static#i=null;static#r=null;static#n=NaN;static#l=null;static#o=null;static#c=NaN;static _INNER_MARGIN=3;constructor(t){super(t),this.#e=t.mustBeCommitted||!1,t.drawOutlines&&(this.#h(t),this.#f())}#h({drawOutlines:t,drawId:e,drawingOptions:s}){this.#t=t,this._drawingOptions||=s,e>=0?(this._drawId=e,this.parent.drawLayer.finalizeDraw(e,t.defaultProperties)):this._drawId=this.#u(t,this.parent),this.#m(t.box)}#u(t,e){const{id:s}=e.drawLayer.draw(k._mergeSVGProperties(this._drawingOptions.toSVGProperties(),t.defaultSVGProperties),!1,!1);return s}static _mergeSVGProperties(t,e){const s=new Set(Object.keys(t));for(const[i,n]of Object.entries(e))s.has(i)?Object.assign(t[i],n):t[i]=n;return t}static getDefaultDrawingOptions(t){$("Not implemented")}static get typesMap(){$("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(t,e){const s=this.typesMap.get(t);s&&this._defaultDrawingOptions.updateProperty(s,e),this._currentParent&&(k.#s.updateProperty(s,e),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(t,e){const s=this.constructor.typesMap.get(t);s&&this._updateProperty(t,s,e)}static get defaultPropertiesToUpdate(){const t=[],e=this._defaultDrawingOptions;for(const[s,i]of this.typesMap)t.push([s,e[i]]);return t}get propertiesToUpdate(){const t=[],{_drawingOptions:e}=this;for(const[s,i]of this.constructor.typesMap)t.push([s,e[i]]);return t}_updateProperty(t,e,s){const i=this._drawingOptions,n=i[e],r=a=>{i.updateProperty(e,a);const o=this.#t.updateProperty(e,a);o&&this.#m(o),this.parent?.drawLayer.updateProperties(this._drawId,i.toSVGProperties())};this.addCommands({cmd:r.bind(this,s),undo:r.bind(this,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:t,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,k._mergeSVGProperties(this.#t.getPathResizingSVGProperties(this.#p()),{bbox:this.#g()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,k._mergeSVGProperties(this.#t.getPathResizedSVGProperties(this.#p()),{bbox:this.#g()}))}_onTranslating(t,e){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#g(t,e)})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,k._mergeSVGProperties(this.#t.getPathTranslatedSVGProperties(this.#p(),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(t){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,this.#e&&(this.#e=!1,this.commit(),this.parent.setSelected(this),t&&this.isOnScreen&&this.div.focus())}remove(){this.#d(),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#f(),this.#m(this.#t.box),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){let e=!1;this.parent&&!t?(this._uiManager.removeShouldRescale(this),this.#d()):t&&(this._uiManager.addShouldRescale(this),this.#f(t),e=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(t),e&&this.select()}#d(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())}#f(t=this.parent){if(!(this._drawId!==null&&this.parent===t)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,t.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=this.#u(this.#t,t)}}#a([t,e,s,i]){const{parentDimensions:[n,r],rotation:a}=this;switch(a){case 90:return[e,1-t,s*(r/n),i*(n/r)];case 180:return[1-t,1-e,s,i];case 270:return[1-e,t,s*(r/n),i*(n/r)];default:return[t,e,s,i]}}#p(){const{x:t,y:e,width:s,height:i,parentDimensions:[n,r],rotation:a}=this;switch(a){case 90:return[1-e,t,s*(n/r),i*(r/n)];case 180:return[1-t,1-e,s,i];case 270:return[e,1-t,s*(n/r),i*(r/n)];default:return[t,e,s,i]}}#m(t){if([this.x,this.y,this.width,this.height]=this.#a(t),this.div){this.fixAndSetPosition();const[e,s]=this.parentDimensions;this.setDims(this.width*e,this.height*s)}this._onResized()}#g(){const{x:t,y:e,width:s,height:i,rotation:n,parentRotation:r,parentDimensions:[a,o]}=this;switch((n*4+r)/90){case 1:return[1-e-i,t,i,s];case 2:return[1-t-s,1-e-i,s,i];case 3:return[e,1-t-s,i,s];case 4:return[t,e-s*(a/o),i*(o/a),s*(a/o)];case 5:return[1-e,t,s*(a/o),i*(o/a)];case 6:return[1-t-i*(o/a),1-e,i*(o/a),s*(a/o)];case 7:return[e-s*(a/o),1-t-i*(o/a),s*(a/o),i*(o/a)];case 8:return[t-s,e-i,s,i];case 9:return[1-e,t-s,i,s];case 10:return[1-t,1-e,s,i];case 11:return[e-i,1-t,i,s];case 12:return[t-i*(o/a),e,i*(o/a),s*(a/o)];case 13:return[1-e-s*(a/o),t-i*(o/a),s*(a/o),i*(o/a)];case 14:return[1-t,1-e-s*(a/o),i*(o/a),s*(a/o)];case 15:return[e,1-t,s*(a/o),i*(o/a)];default:return[t,e,s,i]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,k._mergeSVGProperties({bbox:this.#g()},this.#t.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#m(this.#t.updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;const t=super.render();t.classList.add("draw");const e=document.createElement("div");t.append(e),e.setAttribute("aria-hidden","true"),e.className="internal";const[s,i]=this.parentDimensions;return this.setDims(this.width*s,this.height*i),this._uiManager.addShouldRescale(this),this.disableEditing(),t}static createDrawerInstance(t,e,s,i,n){$("Not implemented")}static startDrawing(t,e,s,i){const{target:n,offsetX:r,offsetY:a,pointerId:o,pointerType:l}=i;if(k.#l&&k.#l!==l)return;const{viewport:{rotation:h}}=t,{width:d,height:u}=n.getBoundingClientRect(),f=k.#i=new AbortController,p=t.combinedSignal(f);if(k.#n||=o,k.#l??=l,window.addEventListener("pointerup",g=>{k.#n===g.pointerId?this._endDraw(g):k.#o?.delete(g.pointerId)},{signal:p}),window.addEventListener("pointercancel",g=>{k.#n===g.pointerId?this._currentParent.endDrawingSession():k.#o?.delete(g.pointerId)},{signal:p}),window.addEventListener("pointerdown",g=>{k.#l===g.pointerType&&((k.#o||=new Set).add(g.pointerId),k.#s.isCancellable()&&(k.#s.removeLastElement(),k.#s.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:p}),window.addEventListener("contextmenu",yt,{signal:p}),n.addEventListener("pointermove",this._drawMove.bind(this),{signal:p}),n.addEventListener("touchmove",g=>{g.timeStamp===k.#c&&ft(g)},{signal:p}),t.toggleDrawing(),e._editorUndoBar?.hide(),k.#s){t.drawLayer.updateProperties(this._currentDrawId,k.#s.startNew(r,a,d,u,h));return}e.updateUIForDefaultProperties(this),k.#s=this.createDrawerInstance(r,a,d,u,h),k.#r=this.getDefaultDrawingOptions(),this._currentParent=t,{id:this._currentDrawId}=t.drawLayer.draw(this._mergeSVGProperties(k.#r.toSVGProperties(),k.#s.defaultSVGProperties),!0,!1)}static _drawMove(t){if(k.#c=-1,!k.#s)return;const{offsetX:e,offsetY:s,pointerId:i}=t;if(k.#n===i){if(k.#o?.size>=1){this._endDraw(t);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,k.#s.add(e,s)),k.#c=t.timeStamp,ft(t)}}static _cleanup(t){t&&(this._currentDrawId=-1,this._currentParent=null,k.#s=null,k.#r=null,k.#l=null,k.#c=NaN),k.#i&&(k.#i.abort(),k.#i=null,k.#n=NaN,k.#o=null)}static _endDraw(t){const e=this._currentParent;if(e){if(e.toggleDrawing(!0),this._cleanup(!1),t&&e.drawLayer.updateProperties(this._currentDrawId,k.#s.end(t.offsetX,t.offsetY)),this.supportMultipleDrawings){const s=k.#s,i=this._currentDrawId,n=s.getLastElement();e.addCommands({cmd:()=>{e.drawLayer.updateProperties(i,s.setLastElement(n))},undo:()=>{e.drawLayer.updateProperties(i,s.removeLastElement())},mustExec:!1,type:O.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(t){const e=this._currentParent;if(!e)return null;if(e.toggleDrawing(!0),e.cleanUndoStack(O.DRAW_STEP),!k.#s.isEmpty()){const{pageDimensions:[s,i],scale:n}=e,r=e.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:k.#s.getOutlines(s*n,i*n,n,this._INNER_MARGIN),drawingOptions:k.#r,mustBeCommitted:!t});return this._cleanup(!0),r}return e.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(t){}static deserializeDraw(t,e,s,i,n,r){$("Not implemented")}static async deserialize(t,e,s){const{rawDims:{pageWidth:i,pageHeight:n,pageX:r,pageY:a}}=e.viewport,o=this.deserializeDraw(r,a,i,n,this._INNER_MARGIN,t),l=await super.deserialize(t,e,s);return l.createDrawingOptions(t),l.#h({drawOutlines:o}),l.#f(),l.onScaleChanging(),l.rotate(),l}serializeDraw(t){const[e,s]=this.pageTranslation,[i,n]=this.pageDimensions;return this.#t.serialize([e,s,i,n],t)}renderAnnotationElement(t){return t.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}}class nr{#t=new Float64Array(6);#e;#s;#i;#r;#n;#l="";#o=0;#c=new Pe;#h;#u;constructor(t,e,s,i,n,r){this.#h=s,this.#u=i,this.#i=n,this.#r=r,[t,e]=this.#d(t,e);const a=this.#e=[NaN,NaN,NaN,NaN,t,e];this.#n=[t,e],this.#s=[{line:a,points:this.#n}],this.#t.set(a,0)}updateProperty(t,e){t==="stroke-width"&&(this.#r=e)}#d(t,e){return E._normalizePoint(t,e,this.#h,this.#u,this.#i)}isEmpty(){return!this.#s||this.#s.length===0}isCancellable(){return this.#n.length<=10}add(t,e){[t,e]=this.#d(t,e);const[s,i,n,r]=this.#t.subarray(2,6),a=t-n,o=e-r;return Math.hypot(this.#h*a,this.#u*o)<=2?null:(this.#n.push(t,e),isNaN(s)?(this.#t.set([n,r,t,e],2),this.#e.push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(this.#t[0])&&this.#e.splice(6,6),this.#t.set([s,i,n,r,t,e],0),this.#e.push(...E.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const s=this.add(t,e);return s||(this.#n.length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){this.#h=s,this.#u=i,this.#i=n,[t,e]=this.#d(t,e);const r=this.#e=[NaN,NaN,NaN,NaN,t,e];this.#n=[t,e];const a=this.#s.at(-1);return a&&(a.line=new Float32Array(a.line),a.points=new Float32Array(a.points)),this.#s.push({line:r,points:this.#n}),this.#t.set(r,0),this.#o=0,this.toSVGPath(),null}getLastElement(){return this.#s.at(-1)}setLastElement(t){return this.#s?(this.#s.push(t),this.#e=t.line,this.#n=t.points,this.#o=0,{path:{d:this.toSVGPath()}}):this.#c.setLastElement(t)}removeLastElement(){if(!this.#s)return this.#c.removeLastElement();this.#s.pop(),this.#l="";for(let t=0,e=this.#s.length;t<e;t++){const{line:s,points:i}=this.#s[t];this.#e=s,this.#n=i,this.#o=0,this.toSVGPath()}return{path:{d:this.#l}}}toSVGPath(){const t=E.svgRound(this.#e[4]),e=E.svgRound(this.#e[5]);if(this.#n.length===2)return this.#l=`${this.#l} M ${t} ${e} Z`,this.#l;if(this.#n.length<=6){const i=this.#l.lastIndexOf("M");this.#l=`${this.#l.slice(0,i)} M ${t} ${e}`,this.#o=6}if(this.#n.length===4){const i=E.svgRound(this.#e[10]),n=E.svgRound(this.#e[11]);return this.#l=`${this.#l} L ${i} ${n}`,this.#o=12,this.#l}const s=[];this.#o===0&&(s.push(`M ${t} ${e}`),this.#o=6);for(let i=this.#o,n=this.#e.length;i<n;i+=6){const[r,a,o,l,h,d]=this.#e.slice(i,i+6).map(E.svgRound);s.push(`C${r} ${a} ${o} ${l} ${h} ${d}`)}return this.#l+=s.join(" "),this.#o=this.#e.length,this.#l}getOutlines(t,e,s,i){const n=this.#s.at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),this.#c.build(this.#s,t,e,s,this.#i,this.#r,i),this.#t=null,this.#e=null,this.#s=null,this.#l=null,this.#c}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}class Pe extends E{#t;#e=0;#s;#i;#r;#n;#l;#o;#c;build(t,e,s,i,n,r,a){this.#r=e,this.#n=s,this.#l=i,this.#o=n,this.#c=r,this.#s=a??0,this.#i=t,this.#d()}setLastElement(t){return this.#i.push(t),{path:{d:this.toSVGPath()}}}removeLastElement(){return this.#i.pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const t=[];for(const{line:e}of this.#i){if(t.push(`M${E.svgRound(e[4])} ${E.svgRound(e[5])}`),e.length===6){t.push("Z");continue}if(e.length===12){t.push(`L${E.svgRound(e[10])} ${E.svgRound(e[11])}`);continue}for(let s=6,i=e.length;s<i;s+=6){const[n,r,a,o,l,h]=e.subarray(s,s+6).map(E.svgRound);t.push(`C${n} ${r} ${a} ${o} ${l} ${h}`)}}return t.join("")}serialize([t,e,s,i],n){const r=[],a=[],[o,l,h,d]=this.#u();let u,f,p,g,b,m,A,y,v;switch(this.#o){case 0:v=E._rescale,u=t,f=e+i,p=s,g=-i,b=t+o*s,m=e+(1-l-d)*i,A=t+(o+h)*s,y=e+(1-l)*i;break;case 90:v=E._rescaleAndSwap,u=t,f=e,p=s,g=i,b=t+l*s,m=e+o*i,A=t+(l+d)*s,y=e+(o+h)*i;break;case 180:v=E._rescale,u=t+s,f=e,p=-s,g=i,b=t+(1-o-h)*s,m=e+l*i,A=t+(1-o)*s,y=e+(l+d)*i;break;case 270:v=E._rescaleAndSwap,u=t+s,f=e+i,p=-s,g=-i,b=t+(1-l-d)*s,m=e+(1-o-h)*i,A=t+(1-l)*s,y=e+(1-o)*i;break}for(const{line:w,points:S}of this.#i)r.push(v(w,u,f,p,g,n?new Array(w.length):null)),a.push(v(S,u,f,p,g,n?new Array(S.length):null));return{lines:r,points:a,rect:[b,m,A,y]}}static deserialize(t,e,s,i,n,{paths:{lines:r,points:a},rotation:o,thickness:l}){const h=[];let d,u,f,p,g;switch(o){case 0:g=E._rescale,d=-t/s,u=e/i+1,f=1/s,p=-1/i;break;case 90:g=E._rescaleAndSwap,d=-e/i,u=-t/s,f=1/i,p=1/s;break;case 180:g=E._rescale,d=t/s+1,u=-e/i,f=-1/s,p=1/i;break;case 270:g=E._rescaleAndSwap,d=e/i+1,u=t/s+1,f=-1/i,p=-1/s;break}if(!r){r=[];for(const m of a){const A=m.length;if(A===2){r.push(new Float32Array([NaN,NaN,NaN,NaN,m[0],m[1]]));continue}if(A===4){r.push(new Float32Array([NaN,NaN,NaN,NaN,m[0],m[1],NaN,NaN,NaN,NaN,m[2],m[3]]));continue}const y=new Float32Array(3*(A-2));r.push(y);let[v,w,S,_]=m.subarray(0,4);y.set([NaN,NaN,NaN,NaN,v,w],0);for(let P=4;P<A;P+=2){const I=m[P],H=m[P+1];y.set(E.createBezierPoints(v,w,S,_,I,H),(P-2)*3),[v,w,S,_]=[S,_,I,H]}}}for(let m=0,A=r.length;m<A;m++)h.push({line:g(r[m].map(y=>y??NaN),d,u,f,p),points:g(a[m].map(y=>y??NaN),d,u,f,p)});const b=new Pe;return b.build(h,s,i,1,o,l,n),b}#h(t=this.#c){const e=this.#s+t/2*this.#l;return this.#o%180===0?[e/this.#r,e/this.#n]:[e/this.#n,e/this.#r]}#u(){const[t,e,s,i]=this.#t,[n,r]=this.#h(0);return[t+n,e+r,s-2*n,i-2*r]}#d(){const t=this.#t=new Float32Array([1/0,1/0,-1/0,-1/0]);for(const{line:i}of this.#i){if(i.length<=12){for(let a=4,o=i.length;a<o;a+=6){const[l,h]=i.subarray(a,a+2);t[0]=Math.min(t[0],l),t[1]=Math.min(t[1],h),t[2]=Math.max(t[2],l),t[3]=Math.max(t[3],h)}continue}let n=i[4],r=i[5];for(let a=6,o=i.length;a<o;a+=6){const[l,h,d,u,f,p]=i.subarray(a,a+6);T.bezierBoundingBox(n,r,l,h,d,u,f,p,t),n=f,r=p}}const[e,s]=this.#h();t[0]=Math.min(1,Math.max(0,t[0]-e)),t[1]=Math.min(1,Math.max(0,t[1]-s)),t[2]=Math.min(1,Math.max(0,t[2]+e)),t[3]=Math.min(1,Math.max(0,t[3]+s)),t[2]-=t[0],t[3]-=t[1]}get box(){return this.#t}updateProperty(t,e){return t==="stroke-width"?this.#f(e):null}#f(t){const[e,s]=this.#h();this.#c=t;const[i,n]=this.#h(),[r,a]=[i-e,n-s],o=this.#t;return o[0]-=r,o[1]-=a,o[2]+=2*r,o[3]+=2*a,o}updateParentDimensions([t,e],s){const[i,n]=this.#h();this.#r=t,this.#n=e,this.#l=s;const[r,a]=this.#h(),o=r-i,l=a-n,h=this.#t;return h[0]-=o,h[1]-=l,h[2]+=2*o,h[3]+=2*l,h}updateRotation(t){return this.#e=t,{path:{transform:this.rotationTransform}}}get viewBox(){return this.#t.map(E.svgRound).join(" ")}get defaultProperties(){const[t,e]=this.#t;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${E.svgRound(t)} ${E.svgRound(e)}`}}}get rotationTransform(){const[,,t,e]=this.#t;let s=0,i=0,n=0,r=0,a=0,o=0;switch(this.#e){case 90:i=e/t,n=-t/e,a=t;break;case 180:s=-1,r=-1,a=t,o=e;break;case 270:i=-e/t,n=t/e,o=e;break;default:return""}return`matrix(${s} ${i} ${n} ${r} ${E.svgRound(a)} ${E.svgRound(o)})`}getPathResizingSVGProperties([t,e,s,i]){const[n,r]=this.#h(),[a,o,l,h]=this.#t;if(Math.abs(l-n)<=E.PRECISION||Math.abs(h-r)<=E.PRECISION){const g=t+s/2-(a+l/2),b=e+i/2-(o+h/2);return{path:{"transform-origin":`${E.svgRound(t)} ${E.svgRound(e)}`,transform:`${this.rotationTransform} translate(${g} ${b})`}}}const d=(s-2*n)/(l-2*n),u=(i-2*r)/(h-2*r),f=l/s,p=h/i;return{path:{"transform-origin":`${E.svgRound(a)} ${E.svgRound(o)}`,transform:`${this.rotationTransform} scale(${f} ${p}) translate(${E.svgRound(n)} ${E.svgRound(r)}) scale(${d} ${u}) translate(${E.svgRound(-n)} ${E.svgRound(-r)})`}}}getPathResizedSVGProperties([t,e,s,i]){const[n,r]=this.#h(),a=this.#t,[o,l,h,d]=a;if(a[0]=t,a[1]=e,a[2]=s,a[3]=i,Math.abs(h-n)<=E.PRECISION||Math.abs(d-r)<=E.PRECISION){const b=t+s/2-(o+h/2),m=e+i/2-(l+d/2);for(const{line:A,points:y}of this.#i)E._translate(A,b,m,A),E._translate(y,b,m,y);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${E.svgRound(t)} ${E.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const u=(s-2*n)/(h-2*n),f=(i-2*r)/(d-2*r),p=-u*(o+n)+t+n,g=-f*(l+r)+e+r;if(u!==1||f!==1||p!==0||g!==0)for(const{line:b,points:m}of this.#i)E._rescale(b,p,g,u,f,b),E._rescale(m,p,g,u,f,m);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${E.svgRound(t)} ${E.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([t,e],s){const[i,n]=s,r=this.#t,a=t-r[0],o=e-r[1];if(this.#r===i&&this.#n===n)for(const{line:l,points:h}of this.#i)E._translate(l,a,o,l),E._translate(h,a,o,h);else{const l=this.#r/i,h=this.#n/n;this.#r=i,this.#n=n;for(const{line:d,points:u}of this.#i)E._rescale(d,a,o,l,h,d),E._rescale(u,a,o,l,h,u);r[2]*=l,r[3]*=h}return r[0]=t,r[1]=e,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${E.svgRound(t)} ${E.svgRound(e)}`}}}get defaultSVGProperties(){const t=this.#t;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${E.svgRound(t[0])} ${E.svgRound(t[1])}`,transform:this.rotationTransform||null},bbox:t}}}class as extends ir{#t;constructor(t){super(),this.#t=t,super.updateProperties({fill:"none",stroke:M._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(t,e){t==="stroke-width"&&(e??=this["stroke-width"],e*=this.#t.realScale),super.updateSVGProperty(t,e)}clone(){const t=new as(this.#t);return t.updateAll(this),t}}class os extends k{static _type="ink";static _editorType=L.INK;static _defaultDrawingOptions=null;constructor(t){super({...t,name:"inkEditor"}),this._willKeepAspectRatio=!0}static initialize(t,e){M.initialize(t,e),this._defaultDrawingOptions=new as(e.viewParameters)}static getDefaultDrawingOptions(t){const e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!0}static get typesMap(){return F(this,"typesMap",new Map([[O.INK_THICKNESS,"stroke-width"],[O.INK_COLOR,"stroke"],[O.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(t,e,s,i,n){return new nr(t,e,s,i,n,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(t,e,s,i,n,r){return Pe.deserialize(t,e,s,i,n,r)}static async deserialize(t,e,s){let i=null;if(t instanceof is){const{data:{inkLists:r,rect:a,rotation:o,id:l,color:h,opacity:d,borderStyle:{rawWidth:u},popupRef:f},parent:{page:{pageNumber:p}}}=t;i=t={annotationType:L.INK,color:Array.from(h),thickness:u,opacity:d,paths:{points:r},boxes:null,pageIndex:p-1,rect:a.slice(0),rotation:o,id:l,deleted:!1,popupRef:f}}const n=await super.deserialize(t,e,s);return n.annotationElementId=t.id||null,n._initialData=i,n}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:t,_drawingOptions:e,parent:s}=this;e.updateSVGProperty("stroke-width"),s.drawLayer.updateProperties(t,e.toSVGProperties())}static onScaleChangingWhenDrawing(){const t=this._currentParent;t&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),t.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:t,thickness:e,opacity:s}){this._drawingOptions=os.getDefaultDrawingOptions({stroke:T.makeHexColor(...t),"stroke-width":e,"stroke-opacity":s})}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:e,points:s,rect:i}=this.serializeDraw(t),{_drawingOptions:{stroke:n,"stroke-opacity":r,"stroke-width":a}}=this,o={annotationType:L.INK,color:M._colorManager.convert(n),opacity:r,thickness:a,paths:{lines:e,points:s},pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return t?o:this.annotationElementId&&!this.#t(o)?null:(o.id=this.annotationElementId,o)}#t(t){const{color:e,thickness:s,opacity:i,pageIndex:n}=this._initialData;return this._hasBeenMoved||this._hasBeenResized||t.color.some((r,a)=>r!==e[a])||t.thickness!==s||t.opacity!==i||t.pageIndex!==n}renderAnnotationElement(t){const{points:e,rect:s}=this.serializeDraw(!1);return t.updateEdited({rect:s,thickness:this._drawingOptions["stroke-width"],points:e}),null}}class ls extends M{#t=null;#e=null;#s=null;#i=null;#r=null;#n="";#l=null;#o=null;#c=!1;#h=!1;static _type="stamp";static _editorType=L.STAMP;constructor(t){super({...t,name:"stampEditor"}),this.#i=t.bitmapUrl,this.#r=t.bitmapFile}static initialize(t,e){M.initialize(t,e)}static get supportedTypes(){return F(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(e=>`image/${e}`))}static get supportedTypesStr(){return F(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(t){return this.supportedTypes.includes(t)}static paste(t,e){e.pasteEditor(L.STAMP,{bitmapFile:t.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){return{type:"stamp",hasAltText:!!this.altTextData?.altText}}static computeTelemetryFinalData(t){const e=t.get("hasAltText");return{hasAltText:e.get(!0)??0,hasNoAltText:e.get(!1)??0}}#u(t,e=!1){if(!t){this.remove();return}this.#t=t.bitmap,e||(this.#e=t.id,this.#c=t.isSvg),t.file&&(this.#n=t.file.name),this.#a()}#d(){if(this.#s=null,this._uiManager.enableWaiting(!1),!!this.#l){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#t){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#t){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(t=null,e=!0){if(this.hasAltTextData())return null;const{mlManager:s}=this._uiManager;if(!s)throw new Error("No ML.");if(!await s.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:i,width:n,height:r}=t||this.copyCanvas(null,null,!0).imageData,a=await s.guess({name:"altText",request:{data:i,width:n,height:r,channels:i.length/(n*r)}});if(!a)throw new Error("No response from the AI service.");if(a.error)throw new Error("Error from the AI service.");if(a.cancel)return null;if(!a.output)throw new Error("No valid response from the AI service.");const o=a.output;return await this.setGuessedAltText(o),e&&!this.hasAltTextData()&&(this.altTextData={alt:o,decorative:!1}),o}#f(){if(this.#e){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(this.#e).then(s=>this.#u(s,!0)).finally(()=>this.#d());return}if(this.#i){const s=this.#i;this.#i=null,this._uiManager.enableWaiting(!0),this.#s=this._uiManager.imageManager.getFromUrl(s).then(i=>this.#u(i)).finally(()=>this.#d());return}if(this.#r){const s=this.#r;this.#r=null,this._uiManager.enableWaiting(!0),this.#s=this._uiManager.imageManager.getFromFile(s).then(i=>this.#u(i)).finally(()=>this.#d());return}const t=document.createElement("input");t.type="file",t.accept=ls.supportedTypesStr;const e=this._uiManager._signal;this.#s=new Promise(s=>{t.addEventListener("change",async()=>{if(!t.files||t.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const i=await this._uiManager.imageManager.getFromFile(t.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),this.#u(i)}s()},{signal:e}),t.addEventListener("cancel",()=>{this.remove(),s()},{signal:e})}).finally(()=>this.#d()),t.click()}remove(){this.#e&&(this.#t=null,this._uiManager.imageManager.deleteId(this.#e),this.#l?.remove(),this.#l=null,this.#o&&(clearTimeout(this.#o),this.#o=null)),super.remove()}rebuild(){if(!this.parent){this.#e&&this.#f();return}super.rebuild(),this.div!==null&&(this.#e&&this.#l===null&&this.#f(),this.isAttachedToDOM||this.parent.add(this))}onceAdded(t){this._isDraggable=!0,t&&this.div.focus()}isEmpty(){return!(this.#s||this.#t||this.#i||this.#r||this.#e)}get isResizable(){return!0}render(){if(this.div)return this.div;let t,e;if(this.width&&(t=this.x,e=this.y),super.render(),this.div.hidden=!0,this.div.setAttribute("role","figure"),this.addAltTextButton(),this.#t?this.#a():this.#f(),this.width&&!this.annotationElementId){const[s,i]=this.parentDimensions;this.setAt(t*s,e*i,this.width*s,this.height*i)}return this._uiManager.addShouldRescale(this),this.div}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;this.#o!==null&&clearTimeout(this.#o);const t=200;this.#o=setTimeout(()=>{this.#o=null,this.#m()},t)}#a(){const{div:t}=this;let{width:e,height:s}=this.#t;const[i,n]=this.pageDimensions,r=.75;if(this.width)e=this.width*i,s=this.height*n;else if(e>r*i||s>r*n){const h=Math.min(r*i/e,r*n/s);e*=h,s*=h}const[a,o]=this.parentDimensions;this.setDims(e*a/i,s*o/n),this._uiManager.enableWaiting(!1);const l=this.#l=document.createElement("canvas");l.setAttribute("role","img"),this.addContainer(l),this.width=e/i,this.height=s/n,this._initialOptions?.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(t.hidden=!1),this.#m(),this.#h||(this.parent.addUndoableEditor(this),this.#h=!0),this._reportTelemetry({action:"inserted_image"}),this.#n&&l.setAttribute("aria-label",this.#n)}copyCanvas(t,e,s=!1){t||(t=224);const{width:i,height:n}=this.#t,r=new Ue;let a=this.#t,o=i,l=n,h=null;if(e){if(i>e||n>e){const S=Math.min(e/i,e/n);o=Math.floor(i*S),l=Math.floor(n*S)}h=document.createElement("canvas");const u=h.width=Math.ceil(o*r.sx),f=h.height=Math.ceil(l*r.sy);this.#c||(a=this.#p(u,f));const p=h.getContext("2d");p.filter=this._uiManager.hcmFilter;let g="white",b="#cfcfd8";this._uiManager.hcmFilter!=="none"?b="black":window.matchMedia?.("(prefers-color-scheme: dark)").matches&&(g="#8f8f9d",b="#42414d");const m=15,A=m*r.sx,y=m*r.sy,v=new OffscreenCanvas(A*2,y*2),w=v.getContext("2d");w.fillStyle=g,w.fillRect(0,0,A*2,y*2),w.fillStyle=b,w.fillRect(0,0,A,y),w.fillRect(A,y,A,y),p.fillStyle=p.createPattern(v,"repeat"),p.fillRect(0,0,u,f),p.drawImage(a,0,0,a.width,a.height,0,0,u,f)}let d=null;if(s){let u,f;if(r.symmetric&&a.width<t&&a.height<t)u=a.width,f=a.height;else if(a=this.#t,i>t||n>t){const b=Math.min(t/i,t/n);u=Math.floor(i*b),f=Math.floor(n*b),this.#c||(a=this.#p(u,f))}const g=new OffscreenCanvas(u,f).getContext("2d",{willReadFrequently:!0});g.drawImage(a,0,0,a.width,a.height,0,0,u,f),d={width:u,height:f,data:g.getImageData(0,0,u,f).data}}return{canvas:h,width:o,height:l,imageData:d}}#p(t,e){const{width:s,height:i}=this.#t;let n=s,r=i,a=this.#t;for(;n>2*t||r>2*e;){const o=n,l=r;n>2*t&&(n=n>=16384?Math.floor(n/2)-1:Math.ceil(n/2)),r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2));const h=new OffscreenCanvas(n,r);h.getContext("2d").drawImage(a,0,0,o,l,0,0,n,r),a=h.transferToImageBitmap()}return a}#m(){const[t,e]=this.parentDimensions,{width:s,height:i}=this,n=new Ue,r=Math.ceil(s*t*n.sx),a=Math.ceil(i*e*n.sy),o=this.#l;if(!o||o.width===r&&o.height===a)return;o.width=r,o.height=a;const l=this.#c?this.#t:this.#p(r,a),h=o.getContext("2d");h.filter=this._uiManager.hcmFilter,h.drawImage(l,0,0,l.width,l.height,0,0,r,a)}getImageForAltText(){return this.#l}#g(t){if(t){if(this.#c){const i=this._uiManager.imageManager.getSvgUrl(this.#e);if(i)return i}const e=document.createElement("canvas");return{width:e.width,height:e.height}=this.#t,e.getContext("2d").drawImage(this.#t,0,0),e.toDataURL()}if(this.#c){const[e,s]=this.pageDimensions,i=Math.round(this.width*e*$t.PDF_TO_CSS_UNITS),n=Math.round(this.height*s*$t.PDF_TO_CSS_UNITS),r=new OffscreenCanvas(i,n);return r.getContext("2d").drawImage(this.#t,0,0,this.#t.width,this.#t.height,0,0,i,n),r.transferToImageBitmap()}return structuredClone(this.#t)}static async deserialize(t,e,s){let i=null;if(t instanceof ti){const{data:{rect:p,rotation:g,id:b,structParent:m,popupRef:A},container:y,parent:{page:{pageNumber:v}}}=t,w=y.querySelector("canvas"),S=s.imageManager.getFromCanvas(y.id,w);w.remove();const _=(await e._structTree.getAriaAttributes(`${He}${b}`))?.get("aria-label")||"";i=t={annotationType:L.STAMP,bitmapId:S.id,bitmap:S.bitmap,pageIndex:v-1,rect:p.slice(0),rotation:g,id:b,deleted:!1,accessibilityData:{decorative:!1,altText:_},isSvg:!1,structParent:m,popupRef:A}}const n=await super.deserialize(t,e,s),{rect:r,bitmap:a,bitmapUrl:o,bitmapId:l,isSvg:h,accessibilityData:d}=t;l&&s.imageManager.isValidId(l)?(n.#e=l,a&&(n.#t=a)):n.#i=o,n.#c=h;const[u,f]=n.pageDimensions;return n.width=(r[2]-r[0])/u,n.height=(r[3]-r[1])/f,n.annotationElementId=t.id||null,d&&(n.altTextData=d),n._initialData=i,n.#h=!!i,n}serialize(t=!1,e=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const s={annotationType:L.STAMP,bitmapId:this.#e,pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:this.#c,structTreeParentId:this._structTreeParentId};if(t)return s.bitmapUrl=this.#g(!0),s.accessibilityData=this.serializeAltText(!0),s;const{decorative:i,altText:n}=this.serializeAltText(!1);if(!i&&n&&(s.accessibilityData={type:"Figure",alt:n}),this.annotationElementId){const a=this.#b(s);if(a.isSame)return null;a.isSameAltText?delete s.accessibilityData:s.accessibilityData.structParent=this._initialData.structParent??-1}if(s.id=this.annotationElementId,e===null)return s;e.stamps||=new Map;const r=this.#c?(s.rect[2]-s.rect[0])*(s.rect[3]-s.rect[1]):null;if(!e.stamps.has(this.#e))e.stamps.set(this.#e,{area:r,serialized:s}),s.bitmap=this.#g(!1);else if(this.#c){const a=e.stamps.get(this.#e);r>a.area&&(a.area=r,a.serialized.bitmap.close(),a.serialized.bitmap=this.#g(!1))}return s}#b(t){const{pageIndex:e,accessibilityData:{altText:s}}=this._initialData,i=t.pageIndex===e,n=(t.accessibilityData?.alt||"")===s;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&i&&n,isSameAltText:n}}renderAnnotationElement(t){return t.updateEdited({rect:this.getRect(0,0)}),null}}class Ct{#t;#e=!1;#s=null;#i=null;#r=null;#n=new Map;#l=!1;#o=!1;#c=!1;#h=null;#u=null;#d=null;#f=null;#a;static _initialized=!1;static#p=new Map([J,os,ls,q].map(t=>[t._editorType,t]));constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:a,textLayer:o,viewport:l,l10n:h}){const d=[...Ct.#p.values()];if(!Ct._initialized){Ct._initialized=!0;for(const u of d)u.initialize(h,t)}t.registerEditorTypes(d),this.#a=t,this.pageIndex=e,this.div=s,this.#t=n,this.#s=r,this.viewport=l,this.#d=o,this.drawLayer=a,this._structTree=i,this.#a.addLayer(this)}get isEmpty(){return this.#n.size===0}get isInvisible(){return this.isEmpty&&this.#a.getMode()===L.NONE}updateToolbar(t){this.#a.updateToolbar(t)}updateMode(t=this.#a.getMode()){switch(this.#A(),t){case L.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case L.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case L.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:e}=this.div;for(const s of Ct.#p.values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){return t===this.#d?.div}setEditingState(t){this.#a.setEditingState(t)}addCommands(t){this.#a.addCommands(t)}cleanUndoStack(t){this.#a.cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){this.#s?.div.classList.toggle("disabled",!t)}async enable(){this.#c=!0,this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of this.#n.values())s.enableEditing(),s.show(!0),s.annotationElementId&&(this.#a.removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!this.#s){this.#c=!1;return}const e=this.#s.getEditableAnnotations();for(const s of e){if(s.hide(),this.#a.isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}this.#c=!1}disable(){this.#o=!0,this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const i of this.#n.values())if(i.disableEditing(),!!i.annotationElementId){if(i.serialize()!==null){t.set(i.annotationElementId,i);continue}else e.set(i.annotationElementId,i);this.getEditableAnnotation(i.annotationElementId)?.show(),i.remove()}if(this.#s){const i=this.#s.getEditableAnnotations();for(const n of i){const{id:r}=n.data;if(this.#a.isDeletedAnnotationElement(r))continue;let a=e.get(r);if(a){a.resetAnnotationElement(n),a.show(!1),n.show();continue}a=t.get(r),a&&(this.#a.addChangedExistingAnnotation(a),a.renderAnnotationElement(n)&&a.show(!1)),n.show()}}this.#A(),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const i of Ct.#p.values())s.remove(`${i._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),this.#o=!1}getEditableAnnotation(t){return this.#s?.getEditableAnnotation(t)||null}setActiveEditor(t){this.#a.getActive()!==t&&this.#a.setActiveEditor(t)}enableTextSelection(){if(this.div.tabIndex=-1,this.#d?.div&&!this.#f){this.#f=new AbortController;const t=this.#a.combinedSignal(this.#f);this.#d.div.addEventListener("pointerdown",this.#m.bind(this),{signal:t}),this.#d.div.classList.add("highlighting")}}disableTextSelection(){this.div.tabIndex=0,this.#d?.div&&this.#f&&(this.#f.abort(),this.#f=null,this.#d.div.classList.remove("highlighting"))}#m(t){this.#a.unselectAll();const{target:e}=t;if(e===this.#d.div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&this.#d.div.contains(e)){const{isMac:s}=nt.platform;if(t.button!==0||t.ctrlKey&&s)return;this.#a.showAllEditors("highlight",!0,!0),this.#d.div.classList.add("free"),this.toggleDrawing(),q.startHighlighting(this,this.#a.direction==="ltr",{target:this.#d.div,x:t.x,y:t.y}),this.#d.div.addEventListener("pointerup",()=>{this.#d.div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:this.#a._signal}),t.preventDefault()}}enableClick(){if(this.#i)return;this.#i=new AbortController;const t=this.#a.combinedSignal(this.#i);this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){this.#i?.abort(),this.#i=null}attach(t){this.#n.set(t.id,t);const{annotationElementId:e}=t;e&&this.#a.isDeletedAnnotationElement(e)&&this.#a.removeDeletedAnnotationElement(t)}detach(t){this.#n.delete(t.id),this.#t?.removePointerInTextLayer(t.contentDiv),!this.#o&&t.annotationElementId&&this.#a.addDeletedAnnotationElement(t)}remove(t){this.detach(t),this.#a.removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){t.parent!==this&&(t.parent&&t.annotationElementId&&(this.#a.addDeletedAnnotationElement(t.annotationElementId),M.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),t.parent?.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(!(t.parent===this&&t.isAttachedToDOM)){if(this.changeParent(t),this.#a.addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!this.#c),this.#a.addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!this.#r&&(t._focusEventsAllowed=!1,this.#r=setTimeout(()=>{this.#r=null,t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this.#a._signal}),e.focus())},0)),t._structTreeParentId=this.#t?.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||=this,t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getNextId(){return this.#a.getId()}get#g(){return Ct.#p.get(this.#a.getMode())}combinedSignal(t){return this.#a.combinedSignal(t)}#b(t){const e=this.#g;return e?new e.prototype.constructor(t):null}canCreateNewEmptyEditor(){return this.#g?.canCreateNewEmptyEditor()}pasteEditor(t,e){this.#a.updateToolbar(t),this.#a.updateMode(t);const{offsetX:s,offsetY:i}=this.#v(),n=this.getNextId(),r=this.#b({parent:this,id:n,x:s,y:i,uiManager:this.#a,isCentered:!0,...e});r&&this.add(r)}async deserialize(t){return await Ct.#p.get(t.annotationType??t.annotationEditorType)?.deserialize(t,this,this.#a)||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=this.#b({parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:this.#a,isCentered:e,...s});return n&&this.add(n),n}#v(){const{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),a=Math.min(window.innerWidth,t+s),o=Math.min(window.innerHeight,e+i),l=(n+a)/2-t,h=(r+o)/2-e,[d,u]=this.viewport.rotation%180===0?[l,h]:[h,l];return{offsetX:d,offsetY:u}}addNewEditor(){this.createAndAddNewEditor(this.#v(),!0)}setSelected(t){this.#a.setSelected(t)}toggleSelected(t){this.#a.toggleSelected(t)}unselect(t){this.#a.unselect(t)}pointerup(t){const{isMac:e}=nt.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&this.#l&&(this.#l=!1,!(this.#g?.isDrawer&&this.#g.supportMultipleDrawings))){if(!this.#e){this.#e=!0;return}if(this.#a.getMode()===L.STAMP){this.#a.unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){if(this.#a.getMode()===L.HIGHLIGHT&&this.enableTextSelection(),this.#l){this.#l=!1;return}const{isMac:e}=nt.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(this.#l=!0,this.#g?.isDrawer){this.startDrawingSession(t);return}const s=this.#a.getActive();this.#e=!s||s.isEmpty()}startDrawingSession(t){if(this.div.focus(),this.#h){this.#g.startDrawing(this,this.#a,!1,t);return}this.#a.setCurrentDrawingSession(this),this.#h=new AbortController;const e=this.#a.combinedSignal(this.#h);this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(this.#u=null,this.commitOrRemove())},{signal:e}),this.#g.startDrawing(this,this.#a,!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&(this.#u=e);return}this.#u&&setTimeout(()=>{this.#u?.focus(),this.#u=null},0)}endDrawingSession(t=!1){return this.#h?(this.#a.setCurrentDrawingSession(null),this.#h.abort(),this.#h=null,this.#u=null,this.#g.endDrawing(t)):null}findNewParent(t,e,s){const i=this.#a.findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return this.#h?(this.endDrawingSession(),!0):!1}onScaleChanging(){this.#h&&this.#g.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove(),this.#a.getActive()?.parent===this&&(this.#a.commitOrRemove(),this.#a.setActiveEditor(null)),this.#r&&(clearTimeout(this.#r),this.#r=null);for(const t of this.#n.values())this.#t?.removePointerInTextLayer(t.contentDiv),t.setParent(null),t.isAttachedToDOM=!1,t.div.remove();this.div=null,this.#n.clear(),this.#a.removeLayer(this)}#A(){for(const t of this.#n.values())t.isEmpty()&&t.remove()}render({viewport:t}){this.viewport=t,Dt(this.div,t);for(const e of this.#a.getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){this.#a.commitOrRemove(),this.#A();const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,Dt(this.div,{rotation:s}),e!==s)for(const i of this.#n.values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return this.#a.viewParameters.realScale}}class at{#t=null;#e=0;#s=new Map;#i=new Map;constructor({pageIndex:t}){this.pageIndex=t}setParent(t){if(!this.#t){this.#t=t;return}if(this.#t!==t){if(this.#s.size>0)for(const e of this.#s.values())e.remove(),t.append(e);this.#t=t}}static get _svgFactory(){return F(this,"_svgFactory",new es)}static#r(t,[e,s,i,n]){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`}#n(){const t=at._svgFactory.create(1,1,!0);return this.#t.append(t),t.setAttribute("aria-hidden",!0),t}#l(t,e){const s=at._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=at._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i}#o(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)}draw(t,e=!1,s=!1){const i=this.#e++,n=this.#n(),r=at._svgFactory.createElement("defs");n.append(r);const a=at._svgFactory.createElement("path");r.append(a);const o=`path_p${this.pageIndex}_${i}`;a.setAttribute("id",o),a.setAttribute("vector-effect","non-scaling-stroke"),e&&this.#i.set(i,a);const l=s?this.#l(r,o):null,h=at._svgFactory.createElement("use");return n.append(h),h.setAttribute("href",`#${o}`),this.updateProperties(n,t),this.#s.set(i,n),{id:i,clipPathId:`url(#${l})`}}drawOutline(t,e){const s=this.#e++,i=this.#n(),n=at._svgFactory.createElement("defs");i.append(n);const r=at._svgFactory.createElement("path");n.append(r);const a=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",a),r.setAttribute("vector-effect","non-scaling-stroke");let o;if(e){const d=at._svgFactory.createElement("mask");n.append(d),o=`mask_p${this.pageIndex}_${s}`,d.setAttribute("id",o),d.setAttribute("maskUnits","objectBoundingBox");const u=at._svgFactory.createElement("rect");d.append(u),u.setAttribute("width","1"),u.setAttribute("height","1"),u.setAttribute("fill","white");const f=at._svgFactory.createElement("use");d.append(f),f.setAttribute("href",`#${a}`),f.setAttribute("stroke","none"),f.setAttribute("fill","black"),f.setAttribute("fill-rule","nonzero"),f.classList.add("mask")}const l=at._svgFactory.createElement("use");i.append(l),l.setAttribute("href",`#${a}`),o&&l.setAttribute("mask",`url(#${o})`);const h=l.cloneNode();return i.append(h),l.classList.add("mainOutline"),h.classList.add("secondaryOutline"),this.updateProperties(i,t),this.#s.set(s,i),s}finalizeDraw(t,e){this.#i.delete(t),this.updateProperties(t,e)}updateProperties(t,e){if(!e)return;const{root:s,bbox:i,rootClass:n,path:r}=e,a=typeof t=="number"?this.#s.get(t):t;if(a){if(s&&this.#o(a,s),i&&at.#r(a,i),n){const{classList:o}=a;for(const[l,h]of Object.entries(n))o.toggle(l,h)}if(r){const l=a.firstChild.firstChild;this.#o(l,r)}}}updateParent(t,e){if(e===this)return;const s=this.#s.get(t);s&&(e.#t.append(s),this.#s.delete(t),e.#s.set(t,s))}remove(t){this.#i.delete(t),this.#t!==null&&(this.#s.get(t).remove(),this.#s.delete(t))}destroy(){this.#t=null;for(const t of this.#s.values())t.remove();this.#s.clear(),this.#i.clear()}}globalThis.pdfjsTestingUtils={HighlightOutliner:ns},x.AbortException,x.AnnotationEditorLayer,x.AnnotationEditorParamsType,x.AnnotationEditorType,x.AnnotationEditorUIManager,x.AnnotationLayer,x.AnnotationMode,x.ColorPicker,x.DOMSVGFactory,x.DrawLayer,x.FeatureTest;var rr=x.GlobalWorkerOptions;x.ImageKind,x.InvalidPDFException,x.MissingPDFException,x.OPS,x.OutputScale,x.PDFDataRangeTransport,x.PDFDateString,x.PDFWorker,x.PasswordResponses,x.PermissionFlag,x.PixelsPerInch,x.RenderingCancelledException,x.TextLayer,x.TouchManager,x.UnexpectedResponseException,x.Util,x.VerbosityLevel,x.XfaLayer,x.build,x.createValidAbsoluteUrl,x.fetchData;var ar=x.getDocument;x.getFilenameFromUrl,x.getPdfFilenameFromUrl,x.getXfaPageViewport,x.isDataScheme,x.isPdfFile,x.noContextMenu,x.normalizeUnicode,x.setLayerDimensions,x.shadow,x.stopEvent;var or=x.version;function lr(c){return c.arrayBuffer?c.arrayBuffer():new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>{const i=s.result;if(!(i instanceof ArrayBuffer)){e(new Error("Failed to read file as ArrayBuffer."));return}t(i)}),s.addEventListener("error",e),s.readAsArrayBuffer(c)})}rr.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${or}/pdf.worker.min.mjs`,globalThis.addEventListener("message",async c=>{const{data:t,password:e,id:s,page:i,units:n,scale:r}=c.data,a={fonts:globalThis.fonts,createElement:y=>y==="canvas"?new OffscreenCanvas(1,1):null},o=await lr(t),l=await ar({data:o,password:e,ownerDocument:a}).promise,h=l.numPages;if(!s){globalThis.postMessage({status:"success",pages:h});return}const d=await l.getPage(i),u=d.getViewport({scale:r}),f=Math.floor(u.width*n),p=Math.floor(u.height*n),g=new OffscreenCanvas(f,p),m={canvasContext:g.getContext("2d"),viewport:u,transform:[n,0,0,n,0,0]};d.render(m).promise.then(()=>{const y=g.transferToImageBitmap();globalThis.postMessage({status:"success",pages:h,bitmap:y,width:f,height:p},[y])})})})();
12
+ `)){const r=document.createElement("div");r.append(n?document.createTextNode(n):document.createElement("br")),e.append(r)}const i=J._internalPadding*this.parentScale;return t.updateEdited({rect:this.getRect(i,i),popupContent:this.#e}),e}resetAnnotationElement(t){super.resetAnnotationElement(t),t.resetEdited()}}class E{static PRECISION=1e-4;toSVGPath(){$("Abstract method `toSVGPath` must be implemented.")}get box(){$("Abstract getter `box` must be implemented.")}serialize(t,e){$("Abstract method `serialize` must be implemented.")}static _rescale(t,e,s,i,n,r){r||=new Float32Array(t.length);for(let a=0,o=t.length;a<o;a+=2)r[a]=e+t[a]*i,r[a+1]=s+t[a+1]*n;return r}static _rescaleAndSwap(t,e,s,i,n,r){r||=new Float32Array(t.length);for(let a=0,o=t.length;a<o;a+=2)r[a]=e+t[a+1]*i,r[a+1]=s+t[a]*n;return r}static _translate(t,e,s,i){i||=new Float32Array(t.length);for(let n=0,r=t.length;n<r;n+=2)i[n]=e+t[n],i[n+1]=s+t[n+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,s,i,n){switch(n){case 90:return[1-e/s,t/i];case 180:return[1-t/s,1-e/i];case 270:return[e/s,1-t/i];default:return[t/s,e/i]}}static _normalizePagePoint(t,e,s){switch(s){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,s,i,n,r){return[(t+5*s)/6,(e+5*i)/6,(5*s+n)/6,(5*i+r)/6,(s+n)/2,(i+r)/2]}}class Ot{#t;#e=[];#s;#i;#r=[];#n=new Float32Array(18);#l;#o;#c;#h;#u;#d;#f=[];static#a=8;static#p=2;static#m=Ot.#a+Ot.#p;constructor({x:t,y:e},s,i,n,r,a=0){this.#t=s,this.#d=n*i,this.#i=r,this.#n.set([NaN,NaN,NaN,NaN,t,e],6),this.#s=a,this.#h=Ot.#a*i,this.#c=Ot.#m*i,this.#u=i,this.#f.push(t,e)}isEmpty(){return isNaN(this.#n[8])}#g(){const t=this.#n.subarray(4,6),e=this.#n.subarray(16,18),[s,i,n,r]=this.#t;return[(this.#l+(t[0]-e[0])/2-s)/n,(this.#o+(t[1]-e[1])/2-i)/r,(this.#l+(e[0]-t[0])/2-s)/n,(this.#o+(e[1]-t[1])/2-i)/r]}add({x:t,y:e}){this.#l=t,this.#o=e;const[s,i,n,r]=this.#t;let[a,o,l,h]=this.#n.subarray(8,12);const d=t-l,u=e-h,f=Math.hypot(d,u);if(f<this.#c)return!1;const p=f-this.#h,g=p/f,b=g*d,m=g*u;let A=a,y=o;a=l,o=h,l+=b,h+=m,this.#f?.push(t,e);const v=-m/p,w=b/p,S=v*this.#d,_=w*this.#d;return this.#n.set(this.#n.subarray(2,8),0),this.#n.set([l+S,h+_],4),this.#n.set(this.#n.subarray(14,18),12),this.#n.set([l-S,h-_],16),isNaN(this.#n[6])?(this.#r.length===0&&(this.#n.set([a+S,o+_],2),this.#r.push(NaN,NaN,NaN,NaN,(a+S-s)/n,(o+_-i)/r),this.#n.set([a-S,o-_],14),this.#e.push(NaN,NaN,NaN,NaN,(a-S-s)/n,(o-_-i)/r)),this.#n.set([A,y,a,o,l,h],6),!this.isEmpty()):(this.#n.set([A,y,a,o,l,h],6),Math.abs(Math.atan2(y-o,A-a)-Math.atan2(m,b))<Math.PI/2?([a,o,l,h]=this.#n.subarray(2,6),this.#r.push(NaN,NaN,NaN,NaN,((a+l)/2-s)/n,((o+h)/2-i)/r),[a,o,A,y]=this.#n.subarray(14,18),this.#e.push(NaN,NaN,NaN,NaN,((A+a)/2-s)/n,((y+o)/2-i)/r),!0):([A,y,a,o,l,h]=this.#n.subarray(0,6),this.#r.push(((A+5*a)/6-s)/n,((y+5*o)/6-i)/r,((5*a+l)/6-s)/n,((5*o+h)/6-i)/r,((a+l)/2-s)/n,((o+h)/2-i)/r),[l,h,a,o,A,y]=this.#n.subarray(12,18),this.#e.push(((A+5*a)/6-s)/n,((y+5*o)/6-i)/r,((5*a+l)/6-s)/n,((5*o+h)/6-i)/r,((a+l)/2-s)/n,((o+h)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=this.#r,e=this.#e;if(isNaN(this.#n[6])&&!this.isEmpty())return this.#b();const s=[];s.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?s.push(`L${t[i+4]} ${t[i+5]}`):s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);this.#A(s);for(let i=e.length-6;i>=6;i-=6)isNaN(e[i])?s.push(`L${e[i+4]} ${e[i+5]}`):s.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return this.#v(s),s.join(" ")}#b(){const[t,e,s,i]=this.#t,[n,r,a,o]=this.#g();return`M${(this.#n[2]-t)/s} ${(this.#n[3]-e)/i} L${(this.#n[4]-t)/s} ${(this.#n[5]-e)/i} L${n} ${r} L${a} ${o} L${(this.#n[16]-t)/s} ${(this.#n[17]-e)/i} L${(this.#n[14]-t)/s} ${(this.#n[15]-e)/i} Z`}#v(t){const e=this.#e;t.push(`L${e[4]} ${e[5]} Z`)}#A(t){const[e,s,i,n]=this.#t,r=this.#n.subarray(4,6),a=this.#n.subarray(16,18),[o,l,h,d]=this.#g();t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${o} ${l} L${h} ${d} L${(a[0]-e)/i} ${(a[1]-s)/n}`)}newFreeDrawOutline(t,e,s,i,n,r){return new ei(t,e,s,i,n,r)}getOutlines(){const t=this.#r,e=this.#e,s=this.#n,[i,n,r,a]=this.#t,o=new Float32Array((this.#f?.length??0)+2);for(let d=0,u=o.length-2;d<u;d+=2)o[d]=(this.#f[d]-i)/r,o[d+1]=(this.#f[d+1]-n)/a;if(o[o.length-2]=(this.#l-i)/r,o[o.length-1]=(this.#o-n)/a,isNaN(s[6])&&!this.isEmpty())return this.#w(o);const l=new Float32Array(this.#r.length+24+this.#e.length);let h=t.length;for(let d=0;d<h;d+=2){if(isNaN(t[d])){l[d]=l[d+1]=NaN;continue}l[d]=t[d],l[d+1]=t[d+1]}h=this.#x(l,h);for(let d=e.length-6;d>=6;d-=6)for(let u=0;u<6;u+=2){if(isNaN(e[d+u])){l[h]=l[h+1]=NaN,h+=2;continue}l[h]=e[d+u],l[h+1]=e[d+u+1],h+=2}return this.#S(l,h),this.newFreeDrawOutline(l,o,this.#t,this.#u,this.#s,this.#i)}#w(t){const e=this.#n,[s,i,n,r]=this.#t,[a,o,l,h]=this.#g(),d=new Float32Array(36);return d.set([NaN,NaN,NaN,NaN,(e[2]-s)/n,(e[3]-i)/r,NaN,NaN,NaN,NaN,(e[4]-s)/n,(e[5]-i)/r,NaN,NaN,NaN,NaN,a,o,NaN,NaN,NaN,NaN,l,h,NaN,NaN,NaN,NaN,(e[16]-s)/n,(e[17]-i)/r,NaN,NaN,NaN,NaN,(e[14]-s)/n,(e[15]-i)/r],0),this.newFreeDrawOutline(d,t,this.#t,this.#u,this.#s,this.#i)}#S(t,e){const s=this.#e;return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6}#x(t,e){const s=this.#n.subarray(4,6),i=this.#n.subarray(16,18),[n,r,a,o]=this.#t,[l,h,d,u]=this.#g();return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/a,(s[1]-r)/o,NaN,NaN,NaN,NaN,l,h,NaN,NaN,NaN,NaN,d,u,NaN,NaN,NaN,NaN,(i[0]-n)/a,(i[1]-r)/o],e),e+=24}}class ei extends E{#t;#e=new Float32Array(4);#s;#i;#r;#n;#l;constructor(t,e,s,i,n,r){super(),this.#l=t,this.#r=e,this.#t=s,this.#n=i,this.#s=n,this.#i=r,this.lastPoint=[NaN,NaN],this.#o(r);const[a,o,l,h]=this.#e;for(let d=0,u=t.length;d<u;d+=2)t[d]=(t[d]-a)/l,t[d+1]=(t[d+1]-o)/h;for(let d=0,u=e.length;d<u;d+=2)e[d]=(e[d]-a)/l,e[d+1]=(e[d+1]-o)/h}toSVGPath(){const t=[`M${this.#l[4]} ${this.#l[5]}`];for(let e=6,s=this.#l.length;e<s;e+=6){if(isNaN(this.#l[e])){t.push(`L${this.#l[e+4]} ${this.#l[e+5]}`);continue}t.push(`C${this.#l[e]} ${this.#l[e+1]} ${this.#l[e+2]} ${this.#l[e+3]} ${this.#l[e+4]} ${this.#l[e+5]}`)}return t.push("Z"),t.join(" ")}serialize([t,e,s,i],n){const r=s-t,a=i-e;let o,l;switch(n){case 0:o=E._rescale(this.#l,t,i,r,-a),l=E._rescale(this.#r,t,i,r,-a);break;case 90:o=E._rescaleAndSwap(this.#l,t,e,r,a),l=E._rescaleAndSwap(this.#r,t,e,r,a);break;case 180:o=E._rescale(this.#l,s,e,-r,a),l=E._rescale(this.#r,s,e,-r,a);break;case 270:o=E._rescaleAndSwap(this.#l,s,i,-r,-a),l=E._rescaleAndSwap(this.#r,s,i,-r,-a);break}return{outline:Array.from(o),points:[Array.from(l)]}}#o(t){const e=this.#l;let s=e[4],i=e[5],n=s,r=i,a=s,o=i,l=s,h=i;const d=t?Math.max:Math.min;for(let f=6,p=e.length;f<p;f+=6){if(isNaN(e[f]))n=Math.min(n,e[f+4]),r=Math.min(r,e[f+5]),a=Math.max(a,e[f+4]),o=Math.max(o,e[f+5]),h<e[f+5]?(l=e[f+4],h=e[f+5]):h===e[f+5]&&(l=d(l,e[f+4]));else{const g=T.bezierBoundingBox(s,i,...e.slice(f,f+6));n=Math.min(n,g[0]),r=Math.min(r,g[1]),a=Math.max(a,g[2]),o=Math.max(o,g[3]),h<g[3]?(l=g[2],h=g[3]):h===g[3]&&(l=d(l,g[2]))}s=e[f+4],i=e[f+5]}const u=this.#e;u[0]=n-this.#s,u[1]=r-this.#s,u[2]=a-n+2*this.#s,u[3]=o-r+2*this.#s,this.lastPoint=[l,h]}get box(){return this.#e}newOutliner(t,e,s,i,n,r=0){return new Ot(t,e,s,i,n,r)}getNewOutline(t,e){const[s,i,n,r]=this.#e,[a,o,l,h]=this.#t,d=n*l,u=r*h,f=s*l+a,p=i*h+o,g=this.newOutliner({x:this.#r[0]*d+f,y:this.#r[1]*u+p},this.#t,this.#n,t,this.#i,e??this.#s);for(let b=2;b<this.#r.length;b+=2)g.add({x:this.#r[b]*d+f,y:this.#r[b+1]*u+p});return g.getOutlines()}}class ns{#t;#e;#s=[];#i=[];constructor(t,e=0,s=0,i=!0){let n=1/0,r=-1/0,a=1/0,o=-1/0;const l=10**-4;for(const{x:b,y:m,width:A,height:y}of t){const v=Math.floor((b-e)/l)*l,w=Math.ceil((b+A+e)/l)*l,S=Math.floor((m-e)/l)*l,_=Math.ceil((m+y+e)/l)*l,P=[v,S,_,!0],I=[w,S,_,!1];this.#s.push(P,I),n=Math.min(n,v),r=Math.max(r,w),a=Math.min(a,S),o=Math.max(o,_)}const h=r-n+2*s,d=o-a+2*s,u=n-s,f=a-s,p=this.#s.at(i?-1:-2),g=[p[0],p[2]];for(const b of this.#s){const[m,A,y]=b;b[0]=(m-u)/h,b[1]=(A-f)/d,b[2]=(y-f)/d}this.#t=new Float32Array([u,f,h,d]),this.#e=g}getOutlines(){this.#s.sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of this.#s)e[3]?(t.push(...this.#c(e)),this.#l(e)):(this.#o(e),t.push(...this.#c(e)));return this.#r(t)}#r(t){const e=[],s=new Set;for(const r of t){const[a,o,l]=r;e.push([a,o,r],[a,l,r])}e.sort((r,a)=>r[1]-a[1]||r[0]-a[0]);for(let r=0,a=e.length;r<a;r+=2){const o=e[r][2],l=e[r+1][2];o.push(l),l.push(o),s.add(o),s.add(l)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[a,o,l,h,d]=r;s.delete(r);let u=a,f=o;for(n=[a,l],i.push(n);;){let p;if(s.has(h))p=h;else if(s.has(d))p=d;else break;s.delete(p),[a,o,l,h,d]=p,u!==a&&(n.push(u,f,a,f===o?o:l),u=a),f=f===o?l:o}n.push(u,f)}return new er(i,this.#t,this.#e)}#n(t){const e=this.#i;let s=0,i=e.length-1;for(;s<=i;){const n=s+i>>1,r=e[n][0];if(r===t)return n;r<t?s=n+1:i=n-1}return i+1}#l([,t,e]){const s=this.#n(t);this.#i.splice(s,0,[t,e])}#o([,t,e]){const s=this.#n(t);for(let i=s;i<this.#i.length;i++){const[n,r]=this.#i[i];if(n!==t)break;if(n===t&&r===e){this.#i.splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=this.#i[i];if(n!==t)break;if(n===t&&r===e){this.#i.splice(i,1);return}}}#c(t){const[e,s,i]=t,n=[[e,s,i]],r=this.#n(i);for(let a=0;a<r;a++){const[o,l]=this.#i[a];for(let h=0,d=n.length;h<d;h++){const[,u,f]=n[h];if(!(l<=u||f<=o)){if(u>=o){if(f>l)n[h][1]=l;else{if(d===1)return[];n.splice(h,1),h--,d--}continue}n[h][2]=o,f>l&&n.push([e,l,f])}}}return n}}class er extends E{#t;#e;constructor(t,e,s){super(),this.#e=t,this.#t=e,this.lastPoint=s}toSVGPath(){const t=[];for(const e of this.#e){let[s,i]=e;t.push(`M${s} ${i}`);for(let n=2;n<e.length;n+=2){const r=e[n],a=e[n+1];r===s?(t.push(`V${a}`),i=a):a===i&&(t.push(`H${r}`),s=r)}t.push("Z")}return t.join(" ")}serialize([t,e,s,i],n){const r=[],a=s-t,o=i-e;for(const l of this.#e){const h=new Array(l.length);for(let d=0;d<l.length;d+=2)h[d]=t+l[d]*a,h[d+1]=i-l[d+1]*o;r.push(h)}return r}get box(){return this.#t}get classNamesForOutlining(){return["highlightOutline"]}}class rs extends Ot{newFreeDrawOutline(t,e,s,i,n,r){return new sr(t,e,s,i,n,r)}}class sr extends ei{newOutliner(t,e,s,i,n,r=0){return new rs(t,e,s,i,n,r)}}class mt{#t=null;#e=null;#s;#i=null;#r=!1;#n=!1;#l=null;#o;#c=null;#h=null;#u;static#d=null;static get _keyboardManager(){return F(this,"_keyboardManager",new se([[["Escape","mac+Escape"],mt.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],mt.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],mt.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],mt.prototype._moveToPrevious],[["Home","mac+Home"],mt.prototype._moveToBeginning],[["End","mac+End"],mt.prototype._moveToEnd]]))}constructor({editor:t=null,uiManager:e=null}){t?(this.#n=!1,this.#u=O.HIGHLIGHT_COLOR,this.#l=t):(this.#n=!0,this.#u=O.HIGHLIGHT_DEFAULT_COLOR),this.#h=t?._uiManager||e,this.#o=this.#h._eventBus,this.#s=t?.color||this.#h?.highlightColors.values().next().value||"#FFFF98",mt.#d||=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 t=this.#t=document.createElement("button");t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);const e=this.#h._signal;t.addEventListener("click",this.#m.bind(this),{signal:e}),t.addEventListener("keydown",this.#p.bind(this),{signal:e});const s=this.#e=document.createElement("span");return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=this.#s,t.append(s),t}renderMainDropdown(){const t=this.#i=this.#f();return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}#f(){const t=document.createElement("div"),e=this.#h._signal;t.addEventListener("contextmenu",yt,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[s,i]of this.#h.highlightColors){const n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",mt.#d[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===this.#s),n.addEventListener("click",this.#a.bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",this.#p.bind(this),{signal:e}),t}#a(t,e){e.stopPropagation(),this.#o.dispatch("switchannotationeditorparams",{source:this,type:this.#u,value:t})}_colorSelectFromKeyboard(t){if(t.target===this.#t){this.#m(t);return}const e=t.target.getAttribute("data-color");e&&this.#a(e,t)}_moveToNext(t){if(!this.#b){this.#m(t);return}if(t.target===this.#t){this.#i.firstChild?.focus();return}t.target.nextSibling?.focus()}_moveToPrevious(t){if(t.target===this.#i?.firstChild||t.target===this.#t){this.#b&&this._hideDropdownFromKeyboard();return}this.#b||this.#m(t),t.target.previousSibling?.focus()}_moveToBeginning(t){if(!this.#b){this.#m(t);return}this.#i.firstChild?.focus()}_moveToEnd(t){if(!this.#b){this.#m(t);return}this.#i.lastChild?.focus()}#p(t){mt._keyboardManager.exec(this,t)}#m(t){if(this.#b){this.hideDropdown();return}if(this.#r=t.detail===0,this.#c||(this.#c=new AbortController,window.addEventListener("pointerdown",this.#g.bind(this),{signal:this.#h.combinedSignal(this.#c)})),this.#i){this.#i.classList.remove("hidden");return}const e=this.#i=this.#f();this.#t.append(e)}#g(t){this.#i?.contains(t.target)||this.hideDropdown()}hideDropdown(){this.#i?.classList.add("hidden"),this.#c?.abort(),this.#c=null}get#b(){return this.#i&&!this.#i.classList.contains("hidden")}_hideDropdownFromKeyboard(){if(!this.#n){if(!this.#b){this.#l?.unselect();return}this.hideDropdown(),this.#t.focus({preventScroll:!0,focusVisible:this.#r})}}updateColor(t){if(this.#e&&(this.#e.style.backgroundColor=t),!this.#i)return;const e=this.#h.highlightColors.values();for(const s of this.#i.children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){this.#t?.remove(),this.#t=null,this.#e=null,this.#i?.remove(),this.#i=null}}class q extends M{#t=null;#e=0;#s;#i=null;#r=null;#n=null;#l=null;#o=0;#c=null;#h=null;#u=null;#d=!1;#f=null;#a;#p=null;#m="";#g;#b="";static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type="highlight";static _editorType=L.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId="";static get _keyboardManager(){const t=q.prototype;return F(this,"_keyboardManager",new se([[["ArrowLeft","mac+ArrowLeft"],t._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],t._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],t._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],t._moveCaret,{args:[3]}]]))}constructor(t){super({...t,name:"highlightEditor"}),this.color=t.color||q._defaultColor,this.#g=t.thickness||q._defaultThickness,this.#a=t.opacity||q._defaultOpacity,this.#s=t.boxes||null,this.#b=t.methodOfCreation||"",this.#m=t.text||"",this._isDraggable=!1,t.highlightId>-1?(this.#d=!0,this.#A(t),this.#R()):this.#s&&(this.#t=t.anchorNode,this.#e=t.anchorOffset,this.#l=t.focusNode,this.#o=t.focusOffset,this.#v(),this.#R(),this.rotate(this.rotation))}get telemetryInitialData(){return{action:"added",type:this.#d?"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(t){return{numberOfColors:t.get("color").size}}#v(){const t=new ns(this.#s,.001);this.#h=t.getOutlines(),[this.x,this.y,this.width,this.height]=this.#h.box;const e=new ns(this.#s,.0025,.001,this._uiManager.direction==="ltr");this.#n=e.getOutlines();const{lastPoint:s}=this.#n;this.#f=[(s[0]-this.x)/this.width,(s[1]-this.y)/this.height]}#A({highlightOutlines:t,highlightId:e,clipPathId:s}){this.#h=t;const i=1.5;if(this.#n=t.getNewOutline(this.#g/2+i,.0025),e>=0)this.#u=e,this.#i=s,this.parent.drawLayer.finalizeDraw(e,{bbox:t.box,path:{d:t.toSVGPath()}}),this.#p=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#n.box,path:{d:this.#n.toSVGPath()}},!0);else if(this.parent){const h=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#u,{bbox:q.#_(this.#h.box,(h-this.rotation+360)%360),path:{d:t.toSVGPath()}}),this.parent.drawLayer.updateProperties(this.#p,{bbox:q.#_(this.#n.box,h),path:{d:this.#n.toSVGPath()}})}const[n,r,a,o]=t.box;switch(this.rotation){case 0:this.x=n,this.y=r,this.width=a,this.height=o;break;case 90:{const[h,d]=this.parentDimensions;this.x=r,this.y=1-n,this.width=a*d/h,this.height=o*h/d;break}case 180:this.x=1-n,this.y=1-r,this.width=a,this.height=o;break;case 270:{const[h,d]=this.parentDimensions;this.x=1-r,this.y=n,this.width=a*d/h,this.height=o*h/d;break}}const{lastPoint:l}=this.#n;this.#f=[(l[0]-n)/a,(l[1]-r)/o]}static initialize(t,e){M.initialize(t,e),q._defaultColor||=e.highlightColors?.values().next().value||"#fff066"}static updateDefaultParams(t,e){switch(t){case O.HIGHLIGHT_DEFAULT_COLOR:q._defaultColor=e;break;case O.HIGHLIGHT_THICKNESS:q._defaultThickness=e;break}}translateInPage(t,e){}get toolbarPosition(){return this.#f}updateParams(t,e){switch(t){case O.HIGHLIGHT_COLOR:this.#w(e);break;case O.HIGHLIGHT_THICKNESS:this.#S(e);break}}static get defaultPropertiesToUpdate(){return[[O.HIGHLIGHT_DEFAULT_COLOR,q._defaultColor],[O.HIGHLIGHT_THICKNESS,q._defaultThickness]]}get propertiesToUpdate(){return[[O.HIGHLIGHT_COLOR,this.color||q._defaultColor],[O.HIGHLIGHT_THICKNESS,this.#g||q._defaultThickness],[O.HIGHLIGHT_FREE,this.#d]]}#w(t){const e=(n,r)=>{this.color=n,this.#a=r,this.parent?.drawLayer.updateProperties(this.#u,{root:{fill:n,"fill-opacity":r}}),this.#r?.updateColor(n)},s=this.color,i=this.#a;this.addCommands({cmd:e.bind(this,t,q._defaultOpacity),undo:e.bind(this,s,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:O.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(t)},!0)}#S(t){const e=this.#g,s=i=>{this.#g=i,this.#x(i)};this.addCommands({cmd:s.bind(this,t),undo:s.bind(this,e),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:O.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:t},!0)}async addEditToolbar(){const t=await super.addEditToolbar();return t?(this._uiManager.highlightColors&&(this.#r=new mt({editor:this}),t.addColorPicker(this.#r)),t):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(this.#k())}getBaseTranslation(){return[0,0]}getRect(t,e){return super.getRect(t,e,this.#k())}onceAdded(t){this.annotationElementId||this.parent.addUndoableEditor(this),t&&this.div.focus()}remove(){this.#T(),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#R(),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){let e=!1;this.parent&&!t?this.#T():t&&(this.#R(t),e=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(t),this.show(this._isVisible),e&&this.select()}#x(t){if(!this.#d)return;this.#A({highlightOutlines:this.#h.getNewOutline(t/2)}),this.fixAndSetPosition();const[e,s]=this.parentDimensions;this.setDims(this.width*e,this.height*s)}#T(){this.#u===null||!this.parent||(this.parent.drawLayer.remove(this.#u),this.#u=null,this.parent.drawLayer.remove(this.#p),this.#p=null)}#R(t=this.parent){this.#u===null&&({id:this.#u,clipPathId:this.#i}=t.drawLayer.draw({bbox:this.#h.box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":this.#a},rootClass:{highlight:!0,free:this.#d},path:{d:this.#h.toSVGPath()}},!1,!0),this.#p=t.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#d},bbox:this.#n.box,path:{d:this.#n.toSVGPath()}},this.#d),this.#c&&(this.#c.style.clipPath=this.#i))}static#_([t,e,s,i],n){switch(n){case 90:return[1-e-i,t,i,s];case 180:return[1-t-s,1-e-i,s,i];case 270:return[e,1-t-s,i,s]}return[t,e,s,i]}rotate(t){const{drawLayer:e}=this.parent;let s;this.#d?(t=(t-this.rotation+360)%360,s=q.#_(this.#h.box,t)):s=q.#_([this.x,this.y,this.width,this.height],t),e.updateProperties(this.#u,{bbox:s,root:{"data-main-rotation":t}}),e.updateProperties(this.#p,{bbox:q.#_(this.#n.box,t),root:{"data-main-rotation":t}})}render(){if(this.div)return this.div;const t=super.render();this.#m&&(t.setAttribute("aria-label",this.#m),t.setAttribute("role","mark")),this.#d?t.classList.add("free"):this.div.addEventListener("keydown",this.#P.bind(this),{signal:this._uiManager._signal});const e=this.#c=document.createElement("div");t.append(e),e.setAttribute("aria-hidden","true"),e.className="internal",e.style.clipPath=this.#i;const[s,i]=this.parentDimensions;return this.setDims(this.width*s,this.height*i),ve(this,this.#c,["pointerover","pointerleave"]),this.enableEditing(),t}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#p,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#p,{rootClass:{hovered:!1}})}#P(t){q._keyboardManager.exec(this,t)}_moveCaret(t){switch(this.parent.unselect(this),t){case 0:case 2:this.#C(!0);break;case 1:case 3:this.#C(!1);break}}#C(t){if(!this.#t)return;const e=window.getSelection();t?e.setPosition(this.#t,this.#e):e.setPosition(this.#l,this.#o)}select(){super.select(),this.#p&&this.parent?.drawLayer.updateProperties(this.#p,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect(),this.#p&&(this.parent?.drawLayer.updateProperties(this.#p,{rootClass:{selected:!1}}),this.#d||this.#C(!1))}get _mustFixPosition(){return!this.#d}show(t=this._isVisible){super.show(t),this.parent&&(this.parent.drawLayer.updateProperties(this.#u,{rootClass:{hidden:!t}}),this.parent.drawLayer.updateProperties(this.#p,{rootClass:{hidden:!t}}))}#k(){return this.#d?this.rotation:0}#D(){if(this.#d)return null;const[t,e]=this.pageDimensions,[s,i]=this.pageTranslation,n=this.#s,r=new Float32Array(n.length*8);let a=0;for(const{x:o,y:l,width:h,height:d}of n){const u=o*t+s,f=(1-l)*e+i;r[a]=r[a+4]=u,r[a+1]=r[a+3]=f,r[a+2]=r[a+6]=u+h*t,r[a+5]=r[a+7]=f-d*e,a+=8}return r}#N(t){return this.#h.serialize(t,this.#k())}static startHighlighting(t,e,{target:s,x:i,y:n}){const{x:r,y:a,width:o,height:l}=s.getBoundingClientRect(),h=new AbortController,d=t.combinedSignal(h),u=f=>{h.abort(),this.#y(t,f)};window.addEventListener("blur",u,{signal:d}),window.addEventListener("pointerup",u,{signal:d}),window.addEventListener("pointerdown",ft,{capture:!0,passive:!1,signal:d}),window.addEventListener("contextmenu",yt,{signal:d}),s.addEventListener("pointermove",this.#E.bind(this,t),{signal:d}),this._freeHighlight=new rs({x:i,y:n},[r,a,o,l],t.scale,this._defaultThickness/2,e,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=t.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(t,e){this._freeHighlight.add(e)&&t.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#y(t,e){this._freeHighlight.isEmpty()?t.drawLayer.remove(this._freeHighlightId):t.createAndAddNewEditor(e,!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(t,e,s){let i=null;if(t instanceof Zs){const{data:{quadPoints:p,rect:g,rotation:b,id:m,color:A,opacity:y,popupRef:v},parent:{page:{pageNumber:w}}}=t;i=t={annotationType:L.HIGHLIGHT,color:Array.from(A),opacity:y,quadPoints:p,boxes:null,pageIndex:w-1,rect:g.slice(0),rotation:b,id:m,deleted:!1,popupRef:v}}else if(t instanceof is){const{data:{inkLists:p,rect:g,rotation:b,id:m,color:A,borderStyle:{rawWidth:y},popupRef:v},parent:{page:{pageNumber:w}}}=t;i=t={annotationType:L.HIGHLIGHT,color:Array.from(A),thickness:y,inkLists:p,boxes:null,pageIndex:w-1,rect:g.slice(0),rotation:b,id:m,deleted:!1,popupRef:v}}const{color:n,quadPoints:r,inkLists:a,opacity:o}=t,l=await super.deserialize(t,e,s);l.color=T.makeHexColor(...n),l.#a=o||1,a&&(l.#g=t.thickness),l.annotationElementId=t.id||null,l._initialData=i;const[h,d]=l.pageDimensions,[u,f]=l.pageTranslation;if(r){const p=l.#s=[];for(let g=0;g<r.length;g+=8)p.push({x:(r[g]-u)/h,y:1-(r[g+1]-f)/d,width:(r[g+2]-r[g])/h,height:(r[g+1]-r[g+5])/d});l.#v(),l.#R(),l.rotate(l.rotation)}else if(a){l.#d=!0;const p=a[0],g={x:p[0]-u,y:d-(p[1]-f)},b=new rs(g,[0,0,h,d],1,l.#g/2,!0,.001);for(let y=0,v=p.length;y<v;y+=2)g.x=p[y]-u,g.y=d-(p[y+1]-f),b.add(g);const{id:m,clipPathId:A}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:l.color,"fill-opacity":l._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:b.toSVGPath()}},!0,!0);l.#A({highlightOutlines:b.getOutlines(),highlightId:m,clipPathId:A}),l.#R()}return l}serialize(t=!1){if(this.isEmpty()||t)return null;if(this.deleted)return this.serializeDeleted();const e=this.getRect(0,0),s=M._colorManager.convert(this.color),i={annotationType:L.HIGHLIGHT,color:s,opacity:this.#a,thickness:this.#g,quadPoints:this.#D(),outlines:this.#N(e),pageIndex:this.pageIndex,rect:e,rotation:this.#k(),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!this.#L(i)?null:(i.id=this.annotationElementId,i)}#L(t){const{color:e}=this._initialData;return t.color.some((s,i)=>s!==e[i])}renderAnnotationElement(t){return t.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}}class ir{#t=Object.create(null);updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(const[e,s]of Object.entries(t))this.updateProperty(e,s)}updateSVGProperty(t,e){this.#t[t]=e}toSVGProperties(){const t=this.#t;return this.#t=Object.create(null),{root:t}}reset(){this.#t=Object.create(null)}updateAll(t=this){this.updateProperties(t)}clone(){$("Not implemented")}}class k extends M{#t=null;#e;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#s=null;static#i=null;static#r=null;static#n=NaN;static#l=null;static#o=null;static#c=NaN;static _INNER_MARGIN=3;constructor(t){super(t),this.#e=t.mustBeCommitted||!1,t.drawOutlines&&(this.#h(t),this.#f())}#h({drawOutlines:t,drawId:e,drawingOptions:s}){this.#t=t,this._drawingOptions||=s,e>=0?(this._drawId=e,this.parent.drawLayer.finalizeDraw(e,t.defaultProperties)):this._drawId=this.#u(t,this.parent),this.#m(t.box)}#u(t,e){const{id:s}=e.drawLayer.draw(k._mergeSVGProperties(this._drawingOptions.toSVGProperties(),t.defaultSVGProperties),!1,!1);return s}static _mergeSVGProperties(t,e){const s=new Set(Object.keys(t));for(const[i,n]of Object.entries(e))s.has(i)?Object.assign(t[i],n):t[i]=n;return t}static getDefaultDrawingOptions(t){$("Not implemented")}static get typesMap(){$("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(t,e){const s=this.typesMap.get(t);s&&this._defaultDrawingOptions.updateProperty(s,e),this._currentParent&&(k.#s.updateProperty(s,e),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(t,e){const s=this.constructor.typesMap.get(t);s&&this._updateProperty(t,s,e)}static get defaultPropertiesToUpdate(){const t=[],e=this._defaultDrawingOptions;for(const[s,i]of this.typesMap)t.push([s,e[i]]);return t}get propertiesToUpdate(){const t=[],{_drawingOptions:e}=this;for(const[s,i]of this.constructor.typesMap)t.push([s,e[i]]);return t}_updateProperty(t,e,s){const i=this._drawingOptions,n=i[e],r=a=>{i.updateProperty(e,a);const o=this.#t.updateProperty(e,a);o&&this.#m(o),this.parent?.drawLayer.updateProperties(this._drawId,i.toSVGProperties())};this.addCommands({cmd:r.bind(this,s),undo:r.bind(this,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:t,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,k._mergeSVGProperties(this.#t.getPathResizingSVGProperties(this.#p()),{bbox:this.#g()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,k._mergeSVGProperties(this.#t.getPathResizedSVGProperties(this.#p()),{bbox:this.#g()}))}_onTranslating(t,e){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#g(t,e)})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,k._mergeSVGProperties(this.#t.getPathTranslatedSVGProperties(this.#p(),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(t){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,this.#e&&(this.#e=!1,this.commit(),this.parent.setSelected(this),t&&this.isOnScreen&&this.div.focus())}remove(){this.#d(),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#f(),this.#m(this.#t.box),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){let e=!1;this.parent&&!t?(this._uiManager.removeShouldRescale(this),this.#d()):t&&(this._uiManager.addShouldRescale(this),this.#f(t),e=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(t),e&&this.select()}#d(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())}#f(t=this.parent){if(!(this._drawId!==null&&this.parent===t)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,t.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=this.#u(this.#t,t)}}#a([t,e,s,i]){const{parentDimensions:[n,r],rotation:a}=this;switch(a){case 90:return[e,1-t,s*(r/n),i*(n/r)];case 180:return[1-t,1-e,s,i];case 270:return[1-e,t,s*(r/n),i*(n/r)];default:return[t,e,s,i]}}#p(){const{x:t,y:e,width:s,height:i,parentDimensions:[n,r],rotation:a}=this;switch(a){case 90:return[1-e,t,s*(n/r),i*(r/n)];case 180:return[1-t,1-e,s,i];case 270:return[e,1-t,s*(n/r),i*(r/n)];default:return[t,e,s,i]}}#m(t){if([this.x,this.y,this.width,this.height]=this.#a(t),this.div){this.fixAndSetPosition();const[e,s]=this.parentDimensions;this.setDims(this.width*e,this.height*s)}this._onResized()}#g(){const{x:t,y:e,width:s,height:i,rotation:n,parentRotation:r,parentDimensions:[a,o]}=this;switch((n*4+r)/90){case 1:return[1-e-i,t,i,s];case 2:return[1-t-s,1-e-i,s,i];case 3:return[e,1-t-s,i,s];case 4:return[t,e-s*(a/o),i*(o/a),s*(a/o)];case 5:return[1-e,t,s*(a/o),i*(o/a)];case 6:return[1-t-i*(o/a),1-e,i*(o/a),s*(a/o)];case 7:return[e-s*(a/o),1-t-i*(o/a),s*(a/o),i*(o/a)];case 8:return[t-s,e-i,s,i];case 9:return[1-e,t-s,i,s];case 10:return[1-t,1-e,s,i];case 11:return[e-i,1-t,i,s];case 12:return[t-i*(o/a),e,i*(o/a),s*(a/o)];case 13:return[1-e-s*(a/o),t-i*(o/a),s*(a/o),i*(o/a)];case 14:return[1-t,1-e-s*(a/o),i*(o/a),s*(a/o)];case 15:return[e,1-t,s*(a/o),i*(o/a)];default:return[t,e,s,i]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,k._mergeSVGProperties({bbox:this.#g()},this.#t.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#m(this.#t.updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;const t=super.render();t.classList.add("draw");const e=document.createElement("div");t.append(e),e.setAttribute("aria-hidden","true"),e.className="internal";const[s,i]=this.parentDimensions;return this.setDims(this.width*s,this.height*i),this._uiManager.addShouldRescale(this),this.disableEditing(),t}static createDrawerInstance(t,e,s,i,n){$("Not implemented")}static startDrawing(t,e,s,i){const{target:n,offsetX:r,offsetY:a,pointerId:o,pointerType:l}=i;if(k.#l&&k.#l!==l)return;const{viewport:{rotation:h}}=t,{width:d,height:u}=n.getBoundingClientRect(),f=k.#i=new AbortController,p=t.combinedSignal(f);if(k.#n||=o,k.#l??=l,window.addEventListener("pointerup",g=>{k.#n===g.pointerId?this._endDraw(g):k.#o?.delete(g.pointerId)},{signal:p}),window.addEventListener("pointercancel",g=>{k.#n===g.pointerId?this._currentParent.endDrawingSession():k.#o?.delete(g.pointerId)},{signal:p}),window.addEventListener("pointerdown",g=>{k.#l===g.pointerType&&((k.#o||=new Set).add(g.pointerId),k.#s.isCancellable()&&(k.#s.removeLastElement(),k.#s.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:p}),window.addEventListener("contextmenu",yt,{signal:p}),n.addEventListener("pointermove",this._drawMove.bind(this),{signal:p}),n.addEventListener("touchmove",g=>{g.timeStamp===k.#c&&ft(g)},{signal:p}),t.toggleDrawing(),e._editorUndoBar?.hide(),k.#s){t.drawLayer.updateProperties(this._currentDrawId,k.#s.startNew(r,a,d,u,h));return}e.updateUIForDefaultProperties(this),k.#s=this.createDrawerInstance(r,a,d,u,h),k.#r=this.getDefaultDrawingOptions(),this._currentParent=t,{id:this._currentDrawId}=t.drawLayer.draw(this._mergeSVGProperties(k.#r.toSVGProperties(),k.#s.defaultSVGProperties),!0,!1)}static _drawMove(t){if(k.#c=-1,!k.#s)return;const{offsetX:e,offsetY:s,pointerId:i}=t;if(k.#n===i){if(k.#o?.size>=1){this._endDraw(t);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,k.#s.add(e,s)),k.#c=t.timeStamp,ft(t)}}static _cleanup(t){t&&(this._currentDrawId=-1,this._currentParent=null,k.#s=null,k.#r=null,k.#l=null,k.#c=NaN),k.#i&&(k.#i.abort(),k.#i=null,k.#n=NaN,k.#o=null)}static _endDraw(t){const e=this._currentParent;if(e){if(e.toggleDrawing(!0),this._cleanup(!1),t&&e.drawLayer.updateProperties(this._currentDrawId,k.#s.end(t.offsetX,t.offsetY)),this.supportMultipleDrawings){const s=k.#s,i=this._currentDrawId,n=s.getLastElement();e.addCommands({cmd:()=>{e.drawLayer.updateProperties(i,s.setLastElement(n))},undo:()=>{e.drawLayer.updateProperties(i,s.removeLastElement())},mustExec:!1,type:O.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(t){const e=this._currentParent;if(!e)return null;if(e.toggleDrawing(!0),e.cleanUndoStack(O.DRAW_STEP),!k.#s.isEmpty()){const{pageDimensions:[s,i],scale:n}=e,r=e.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:k.#s.getOutlines(s*n,i*n,n,this._INNER_MARGIN),drawingOptions:k.#r,mustBeCommitted:!t});return this._cleanup(!0),r}return e.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(t){}static deserializeDraw(t,e,s,i,n,r){$("Not implemented")}static async deserialize(t,e,s){const{rawDims:{pageWidth:i,pageHeight:n,pageX:r,pageY:a}}=e.viewport,o=this.deserializeDraw(r,a,i,n,this._INNER_MARGIN,t),l=await super.deserialize(t,e,s);return l.createDrawingOptions(t),l.#h({drawOutlines:o}),l.#f(),l.onScaleChanging(),l.rotate(),l}serializeDraw(t){const[e,s]=this.pageTranslation,[i,n]=this.pageDimensions;return this.#t.serialize([e,s,i,n],t)}renderAnnotationElement(t){return t.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}}class nr{#t=new Float64Array(6);#e;#s;#i;#r;#n;#l="";#o=0;#c=new Pe;#h;#u;constructor(t,e,s,i,n,r){this.#h=s,this.#u=i,this.#i=n,this.#r=r,[t,e]=this.#d(t,e);const a=this.#e=[NaN,NaN,NaN,NaN,t,e];this.#n=[t,e],this.#s=[{line:a,points:this.#n}],this.#t.set(a,0)}updateProperty(t,e){t==="stroke-width"&&(this.#r=e)}#d(t,e){return E._normalizePoint(t,e,this.#h,this.#u,this.#i)}isEmpty(){return!this.#s||this.#s.length===0}isCancellable(){return this.#n.length<=10}add(t,e){[t,e]=this.#d(t,e);const[s,i,n,r]=this.#t.subarray(2,6),a=t-n,o=e-r;return Math.hypot(this.#h*a,this.#u*o)<=2?null:(this.#n.push(t,e),isNaN(s)?(this.#t.set([n,r,t,e],2),this.#e.push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(this.#t[0])&&this.#e.splice(6,6),this.#t.set([s,i,n,r,t,e],0),this.#e.push(...E.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const s=this.add(t,e);return s||(this.#n.length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){this.#h=s,this.#u=i,this.#i=n,[t,e]=this.#d(t,e);const r=this.#e=[NaN,NaN,NaN,NaN,t,e];this.#n=[t,e];const a=this.#s.at(-1);return a&&(a.line=new Float32Array(a.line),a.points=new Float32Array(a.points)),this.#s.push({line:r,points:this.#n}),this.#t.set(r,0),this.#o=0,this.toSVGPath(),null}getLastElement(){return this.#s.at(-1)}setLastElement(t){return this.#s?(this.#s.push(t),this.#e=t.line,this.#n=t.points,this.#o=0,{path:{d:this.toSVGPath()}}):this.#c.setLastElement(t)}removeLastElement(){if(!this.#s)return this.#c.removeLastElement();this.#s.pop(),this.#l="";for(let t=0,e=this.#s.length;t<e;t++){const{line:s,points:i}=this.#s[t];this.#e=s,this.#n=i,this.#o=0,this.toSVGPath()}return{path:{d:this.#l}}}toSVGPath(){const t=E.svgRound(this.#e[4]),e=E.svgRound(this.#e[5]);if(this.#n.length===2)return this.#l=`${this.#l} M ${t} ${e} Z`,this.#l;if(this.#n.length<=6){const i=this.#l.lastIndexOf("M");this.#l=`${this.#l.slice(0,i)} M ${t} ${e}`,this.#o=6}if(this.#n.length===4){const i=E.svgRound(this.#e[10]),n=E.svgRound(this.#e[11]);return this.#l=`${this.#l} L ${i} ${n}`,this.#o=12,this.#l}const s=[];this.#o===0&&(s.push(`M ${t} ${e}`),this.#o=6);for(let i=this.#o,n=this.#e.length;i<n;i+=6){const[r,a,o,l,h,d]=this.#e.slice(i,i+6).map(E.svgRound);s.push(`C${r} ${a} ${o} ${l} ${h} ${d}`)}return this.#l+=s.join(" "),this.#o=this.#e.length,this.#l}getOutlines(t,e,s,i){const n=this.#s.at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),this.#c.build(this.#s,t,e,s,this.#i,this.#r,i),this.#t=null,this.#e=null,this.#s=null,this.#l=null,this.#c}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}class Pe extends E{#t;#e=0;#s;#i;#r;#n;#l;#o;#c;build(t,e,s,i,n,r,a){this.#r=e,this.#n=s,this.#l=i,this.#o=n,this.#c=r,this.#s=a??0,this.#i=t,this.#d()}setLastElement(t){return this.#i.push(t),{path:{d:this.toSVGPath()}}}removeLastElement(){return this.#i.pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const t=[];for(const{line:e}of this.#i){if(t.push(`M${E.svgRound(e[4])} ${E.svgRound(e[5])}`),e.length===6){t.push("Z");continue}if(e.length===12){t.push(`L${E.svgRound(e[10])} ${E.svgRound(e[11])}`);continue}for(let s=6,i=e.length;s<i;s+=6){const[n,r,a,o,l,h]=e.subarray(s,s+6).map(E.svgRound);t.push(`C${n} ${r} ${a} ${o} ${l} ${h}`)}}return t.join("")}serialize([t,e,s,i],n){const r=[],a=[],[o,l,h,d]=this.#u();let u,f,p,g,b,m,A,y,v;switch(this.#o){case 0:v=E._rescale,u=t,f=e+i,p=s,g=-i,b=t+o*s,m=e+(1-l-d)*i,A=t+(o+h)*s,y=e+(1-l)*i;break;case 90:v=E._rescaleAndSwap,u=t,f=e,p=s,g=i,b=t+l*s,m=e+o*i,A=t+(l+d)*s,y=e+(o+h)*i;break;case 180:v=E._rescale,u=t+s,f=e,p=-s,g=i,b=t+(1-o-h)*s,m=e+l*i,A=t+(1-o)*s,y=e+(l+d)*i;break;case 270:v=E._rescaleAndSwap,u=t+s,f=e+i,p=-s,g=-i,b=t+(1-l-d)*s,m=e+(1-o-h)*i,A=t+(1-l)*s,y=e+(1-o)*i;break}for(const{line:w,points:S}of this.#i)r.push(v(w,u,f,p,g,n?new Array(w.length):null)),a.push(v(S,u,f,p,g,n?new Array(S.length):null));return{lines:r,points:a,rect:[b,m,A,y]}}static deserialize(t,e,s,i,n,{paths:{lines:r,points:a},rotation:o,thickness:l}){const h=[];let d,u,f,p,g;switch(o){case 0:g=E._rescale,d=-t/s,u=e/i+1,f=1/s,p=-1/i;break;case 90:g=E._rescaleAndSwap,d=-e/i,u=-t/s,f=1/i,p=1/s;break;case 180:g=E._rescale,d=t/s+1,u=-e/i,f=-1/s,p=1/i;break;case 270:g=E._rescaleAndSwap,d=e/i+1,u=t/s+1,f=-1/i,p=-1/s;break}if(!r){r=[];for(const m of a){const A=m.length;if(A===2){r.push(new Float32Array([NaN,NaN,NaN,NaN,m[0],m[1]]));continue}if(A===4){r.push(new Float32Array([NaN,NaN,NaN,NaN,m[0],m[1],NaN,NaN,NaN,NaN,m[2],m[3]]));continue}const y=new Float32Array(3*(A-2));r.push(y);let[v,w,S,_]=m.subarray(0,4);y.set([NaN,NaN,NaN,NaN,v,w],0);for(let P=4;P<A;P+=2){const I=m[P],H=m[P+1];y.set(E.createBezierPoints(v,w,S,_,I,H),(P-2)*3),[v,w,S,_]=[S,_,I,H]}}}for(let m=0,A=r.length;m<A;m++)h.push({line:g(r[m].map(y=>y??NaN),d,u,f,p),points:g(a[m].map(y=>y??NaN),d,u,f,p)});const b=new Pe;return b.build(h,s,i,1,o,l,n),b}#h(t=this.#c){const e=this.#s+t/2*this.#l;return this.#o%180===0?[e/this.#r,e/this.#n]:[e/this.#n,e/this.#r]}#u(){const[t,e,s,i]=this.#t,[n,r]=this.#h(0);return[t+n,e+r,s-2*n,i-2*r]}#d(){const t=this.#t=new Float32Array([1/0,1/0,-1/0,-1/0]);for(const{line:i}of this.#i){if(i.length<=12){for(let a=4,o=i.length;a<o;a+=6){const[l,h]=i.subarray(a,a+2);t[0]=Math.min(t[0],l),t[1]=Math.min(t[1],h),t[2]=Math.max(t[2],l),t[3]=Math.max(t[3],h)}continue}let n=i[4],r=i[5];for(let a=6,o=i.length;a<o;a+=6){const[l,h,d,u,f,p]=i.subarray(a,a+6);T.bezierBoundingBox(n,r,l,h,d,u,f,p,t),n=f,r=p}}const[e,s]=this.#h();t[0]=Math.min(1,Math.max(0,t[0]-e)),t[1]=Math.min(1,Math.max(0,t[1]-s)),t[2]=Math.min(1,Math.max(0,t[2]+e)),t[3]=Math.min(1,Math.max(0,t[3]+s)),t[2]-=t[0],t[3]-=t[1]}get box(){return this.#t}updateProperty(t,e){return t==="stroke-width"?this.#f(e):null}#f(t){const[e,s]=this.#h();this.#c=t;const[i,n]=this.#h(),[r,a]=[i-e,n-s],o=this.#t;return o[0]-=r,o[1]-=a,o[2]+=2*r,o[3]+=2*a,o}updateParentDimensions([t,e],s){const[i,n]=this.#h();this.#r=t,this.#n=e,this.#l=s;const[r,a]=this.#h(),o=r-i,l=a-n,h=this.#t;return h[0]-=o,h[1]-=l,h[2]+=2*o,h[3]+=2*l,h}updateRotation(t){return this.#e=t,{path:{transform:this.rotationTransform}}}get viewBox(){return this.#t.map(E.svgRound).join(" ")}get defaultProperties(){const[t,e]=this.#t;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${E.svgRound(t)} ${E.svgRound(e)}`}}}get rotationTransform(){const[,,t,e]=this.#t;let s=0,i=0,n=0,r=0,a=0,o=0;switch(this.#e){case 90:i=e/t,n=-t/e,a=t;break;case 180:s=-1,r=-1,a=t,o=e;break;case 270:i=-e/t,n=t/e,o=e;break;default:return""}return`matrix(${s} ${i} ${n} ${r} ${E.svgRound(a)} ${E.svgRound(o)})`}getPathResizingSVGProperties([t,e,s,i]){const[n,r]=this.#h(),[a,o,l,h]=this.#t;if(Math.abs(l-n)<=E.PRECISION||Math.abs(h-r)<=E.PRECISION){const g=t+s/2-(a+l/2),b=e+i/2-(o+h/2);return{path:{"transform-origin":`${E.svgRound(t)} ${E.svgRound(e)}`,transform:`${this.rotationTransform} translate(${g} ${b})`}}}const d=(s-2*n)/(l-2*n),u=(i-2*r)/(h-2*r),f=l/s,p=h/i;return{path:{"transform-origin":`${E.svgRound(a)} ${E.svgRound(o)}`,transform:`${this.rotationTransform} scale(${f} ${p}) translate(${E.svgRound(n)} ${E.svgRound(r)}) scale(${d} ${u}) translate(${E.svgRound(-n)} ${E.svgRound(-r)})`}}}getPathResizedSVGProperties([t,e,s,i]){const[n,r]=this.#h(),a=this.#t,[o,l,h,d]=a;if(a[0]=t,a[1]=e,a[2]=s,a[3]=i,Math.abs(h-n)<=E.PRECISION||Math.abs(d-r)<=E.PRECISION){const b=t+s/2-(o+h/2),m=e+i/2-(l+d/2);for(const{line:A,points:y}of this.#i)E._translate(A,b,m,A),E._translate(y,b,m,y);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${E.svgRound(t)} ${E.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const u=(s-2*n)/(h-2*n),f=(i-2*r)/(d-2*r),p=-u*(o+n)+t+n,g=-f*(l+r)+e+r;if(u!==1||f!==1||p!==0||g!==0)for(const{line:b,points:m}of this.#i)E._rescale(b,p,g,u,f,b),E._rescale(m,p,g,u,f,m);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${E.svgRound(t)} ${E.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([t,e],s){const[i,n]=s,r=this.#t,a=t-r[0],o=e-r[1];if(this.#r===i&&this.#n===n)for(const{line:l,points:h}of this.#i)E._translate(l,a,o,l),E._translate(h,a,o,h);else{const l=this.#r/i,h=this.#n/n;this.#r=i,this.#n=n;for(const{line:d,points:u}of this.#i)E._rescale(d,a,o,l,h,d),E._rescale(u,a,o,l,h,u);r[2]*=l,r[3]*=h}return r[0]=t,r[1]=e,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${E.svgRound(t)} ${E.svgRound(e)}`}}}get defaultSVGProperties(){const t=this.#t;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${E.svgRound(t[0])} ${E.svgRound(t[1])}`,transform:this.rotationTransform||null},bbox:t}}}class as extends ir{#t;constructor(t){super(),this.#t=t,super.updateProperties({fill:"none",stroke:M._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(t,e){t==="stroke-width"&&(e??=this["stroke-width"],e*=this.#t.realScale),super.updateSVGProperty(t,e)}clone(){const t=new as(this.#t);return t.updateAll(this),t}}class os extends k{static _type="ink";static _editorType=L.INK;static _defaultDrawingOptions=null;constructor(t){super({...t,name:"inkEditor"}),this._willKeepAspectRatio=!0}static initialize(t,e){M.initialize(t,e),this._defaultDrawingOptions=new as(e.viewParameters)}static getDefaultDrawingOptions(t){const e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!0}static get typesMap(){return F(this,"typesMap",new Map([[O.INK_THICKNESS,"stroke-width"],[O.INK_COLOR,"stroke"],[O.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(t,e,s,i,n){return new nr(t,e,s,i,n,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(t,e,s,i,n,r){return Pe.deserialize(t,e,s,i,n,r)}static async deserialize(t,e,s){let i=null;if(t instanceof is){const{data:{inkLists:r,rect:a,rotation:o,id:l,color:h,opacity:d,borderStyle:{rawWidth:u},popupRef:f},parent:{page:{pageNumber:p}}}=t;i=t={annotationType:L.INK,color:Array.from(h),thickness:u,opacity:d,paths:{points:r},boxes:null,pageIndex:p-1,rect:a.slice(0),rotation:o,id:l,deleted:!1,popupRef:f}}const n=await super.deserialize(t,e,s);return n.annotationElementId=t.id||null,n._initialData=i,n}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:t,_drawingOptions:e,parent:s}=this;e.updateSVGProperty("stroke-width"),s.drawLayer.updateProperties(t,e.toSVGProperties())}static onScaleChangingWhenDrawing(){const t=this._currentParent;t&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),t.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:t,thickness:e,opacity:s}){this._drawingOptions=os.getDefaultDrawingOptions({stroke:T.makeHexColor(...t),"stroke-width":e,"stroke-opacity":s})}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:e,points:s,rect:i}=this.serializeDraw(t),{_drawingOptions:{stroke:n,"stroke-opacity":r,"stroke-width":a}}=this,o={annotationType:L.INK,color:M._colorManager.convert(n),opacity:r,thickness:a,paths:{lines:e,points:s},pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return t?o:this.annotationElementId&&!this.#t(o)?null:(o.id=this.annotationElementId,o)}#t(t){const{color:e,thickness:s,opacity:i,pageIndex:n}=this._initialData;return this._hasBeenMoved||this._hasBeenResized||t.color.some((r,a)=>r!==e[a])||t.thickness!==s||t.opacity!==i||t.pageIndex!==n}renderAnnotationElement(t){const{points:e,rect:s}=this.serializeDraw(!1);return t.updateEdited({rect:s,thickness:this._drawingOptions["stroke-width"],points:e}),null}}class ls extends M{#t=null;#e=null;#s=null;#i=null;#r=null;#n="";#l=null;#o=null;#c=!1;#h=!1;static _type="stamp";static _editorType=L.STAMP;constructor(t){super({...t,name:"stampEditor"}),this.#i=t.bitmapUrl,this.#r=t.bitmapFile}static initialize(t,e){M.initialize(t,e)}static get supportedTypes(){return F(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(e=>`image/${e}`))}static get supportedTypesStr(){return F(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(t){return this.supportedTypes.includes(t)}static paste(t,e){e.pasteEditor(L.STAMP,{bitmapFile:t.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){return{type:"stamp",hasAltText:!!this.altTextData?.altText}}static computeTelemetryFinalData(t){const e=t.get("hasAltText");return{hasAltText:e.get(!0)??0,hasNoAltText:e.get(!1)??0}}#u(t,e=!1){if(!t){this.remove();return}this.#t=t.bitmap,e||(this.#e=t.id,this.#c=t.isSvg),t.file&&(this.#n=t.file.name),this.#a()}#d(){if(this.#s=null,this._uiManager.enableWaiting(!1),!!this.#l){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#t){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#t){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(t=null,e=!0){if(this.hasAltTextData())return null;const{mlManager:s}=this._uiManager;if(!s)throw new Error("No ML.");if(!await s.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:i,width:n,height:r}=t||this.copyCanvas(null,null,!0).imageData,a=await s.guess({name:"altText",request:{data:i,width:n,height:r,channels:i.length/(n*r)}});if(!a)throw new Error("No response from the AI service.");if(a.error)throw new Error("Error from the AI service.");if(a.cancel)return null;if(!a.output)throw new Error("No valid response from the AI service.");const o=a.output;return await this.setGuessedAltText(o),e&&!this.hasAltTextData()&&(this.altTextData={alt:o,decorative:!1}),o}#f(){if(this.#e){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(this.#e).then(s=>this.#u(s,!0)).finally(()=>this.#d());return}if(this.#i){const s=this.#i;this.#i=null,this._uiManager.enableWaiting(!0),this.#s=this._uiManager.imageManager.getFromUrl(s).then(i=>this.#u(i)).finally(()=>this.#d());return}if(this.#r){const s=this.#r;this.#r=null,this._uiManager.enableWaiting(!0),this.#s=this._uiManager.imageManager.getFromFile(s).then(i=>this.#u(i)).finally(()=>this.#d());return}const t=document.createElement("input");t.type="file",t.accept=ls.supportedTypesStr;const e=this._uiManager._signal;this.#s=new Promise(s=>{t.addEventListener("change",async()=>{if(!t.files||t.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const i=await this._uiManager.imageManager.getFromFile(t.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),this.#u(i)}s()},{signal:e}),t.addEventListener("cancel",()=>{this.remove(),s()},{signal:e})}).finally(()=>this.#d()),t.click()}remove(){this.#e&&(this.#t=null,this._uiManager.imageManager.deleteId(this.#e),this.#l?.remove(),this.#l=null,this.#o&&(clearTimeout(this.#o),this.#o=null)),super.remove()}rebuild(){if(!this.parent){this.#e&&this.#f();return}super.rebuild(),this.div!==null&&(this.#e&&this.#l===null&&this.#f(),this.isAttachedToDOM||this.parent.add(this))}onceAdded(t){this._isDraggable=!0,t&&this.div.focus()}isEmpty(){return!(this.#s||this.#t||this.#i||this.#r||this.#e)}get isResizable(){return!0}render(){if(this.div)return this.div;let t,e;if(this.width&&(t=this.x,e=this.y),super.render(),this.div.hidden=!0,this.div.setAttribute("role","figure"),this.addAltTextButton(),this.#t?this.#a():this.#f(),this.width&&!this.annotationElementId){const[s,i]=this.parentDimensions;this.setAt(t*s,e*i,this.width*s,this.height*i)}return this._uiManager.addShouldRescale(this),this.div}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;this.#o!==null&&clearTimeout(this.#o);const t=200;this.#o=setTimeout(()=>{this.#o=null,this.#m()},t)}#a(){const{div:t}=this;let{width:e,height:s}=this.#t;const[i,n]=this.pageDimensions,r=.75;if(this.width)e=this.width*i,s=this.height*n;else if(e>r*i||s>r*n){const h=Math.min(r*i/e,r*n/s);e*=h,s*=h}const[a,o]=this.parentDimensions;this.setDims(e*a/i,s*o/n),this._uiManager.enableWaiting(!1);const l=this.#l=document.createElement("canvas");l.setAttribute("role","img"),this.addContainer(l),this.width=e/i,this.height=s/n,this._initialOptions?.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(t.hidden=!1),this.#m(),this.#h||(this.parent.addUndoableEditor(this),this.#h=!0),this._reportTelemetry({action:"inserted_image"}),this.#n&&l.setAttribute("aria-label",this.#n)}copyCanvas(t,e,s=!1){t||(t=224);const{width:i,height:n}=this.#t,r=new Ue;let a=this.#t,o=i,l=n,h=null;if(e){if(i>e||n>e){const S=Math.min(e/i,e/n);o=Math.floor(i*S),l=Math.floor(n*S)}h=document.createElement("canvas");const u=h.width=Math.ceil(o*r.sx),f=h.height=Math.ceil(l*r.sy);this.#c||(a=this.#p(u,f));const p=h.getContext("2d");p.filter=this._uiManager.hcmFilter;let g="white",b="#cfcfd8";this._uiManager.hcmFilter!=="none"?b="black":window.matchMedia?.("(prefers-color-scheme: dark)").matches&&(g="#8f8f9d",b="#42414d");const m=15,A=m*r.sx,y=m*r.sy,v=new OffscreenCanvas(A*2,y*2),w=v.getContext("2d");w.fillStyle=g,w.fillRect(0,0,A*2,y*2),w.fillStyle=b,w.fillRect(0,0,A,y),w.fillRect(A,y,A,y),p.fillStyle=p.createPattern(v,"repeat"),p.fillRect(0,0,u,f),p.drawImage(a,0,0,a.width,a.height,0,0,u,f)}let d=null;if(s){let u,f;if(r.symmetric&&a.width<t&&a.height<t)u=a.width,f=a.height;else if(a=this.#t,i>t||n>t){const b=Math.min(t/i,t/n);u=Math.floor(i*b),f=Math.floor(n*b),this.#c||(a=this.#p(u,f))}const g=new OffscreenCanvas(u,f).getContext("2d",{willReadFrequently:!0});g.drawImage(a,0,0,a.width,a.height,0,0,u,f),d={width:u,height:f,data:g.getImageData(0,0,u,f).data}}return{canvas:h,width:o,height:l,imageData:d}}#p(t,e){const{width:s,height:i}=this.#t;let n=s,r=i,a=this.#t;for(;n>2*t||r>2*e;){const o=n,l=r;n>2*t&&(n=n>=16384?Math.floor(n/2)-1:Math.ceil(n/2)),r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2));const h=new OffscreenCanvas(n,r);h.getContext("2d").drawImage(a,0,0,o,l,0,0,n,r),a=h.transferToImageBitmap()}return a}#m(){const[t,e]=this.parentDimensions,{width:s,height:i}=this,n=new Ue,r=Math.ceil(s*t*n.sx),a=Math.ceil(i*e*n.sy),o=this.#l;if(!o||o.width===r&&o.height===a)return;o.width=r,o.height=a;const l=this.#c?this.#t:this.#p(r,a),h=o.getContext("2d");h.filter=this._uiManager.hcmFilter,h.drawImage(l,0,0,l.width,l.height,0,0,r,a)}getImageForAltText(){return this.#l}#g(t){if(t){if(this.#c){const i=this._uiManager.imageManager.getSvgUrl(this.#e);if(i)return i}const e=document.createElement("canvas");return{width:e.width,height:e.height}=this.#t,e.getContext("2d").drawImage(this.#t,0,0),e.toDataURL()}if(this.#c){const[e,s]=this.pageDimensions,i=Math.round(this.width*e*$t.PDF_TO_CSS_UNITS),n=Math.round(this.height*s*$t.PDF_TO_CSS_UNITS),r=new OffscreenCanvas(i,n);return r.getContext("2d").drawImage(this.#t,0,0,this.#t.width,this.#t.height,0,0,i,n),r.transferToImageBitmap()}return structuredClone(this.#t)}static async deserialize(t,e,s){let i=null;if(t instanceof ti){const{data:{rect:p,rotation:g,id:b,structParent:m,popupRef:A},container:y,parent:{page:{pageNumber:v}}}=t,w=y.querySelector("canvas"),S=s.imageManager.getFromCanvas(y.id,w);w.remove();const _=(await e._structTree.getAriaAttributes(`${He}${b}`))?.get("aria-label")||"";i=t={annotationType:L.STAMP,bitmapId:S.id,bitmap:S.bitmap,pageIndex:v-1,rect:p.slice(0),rotation:g,id:b,deleted:!1,accessibilityData:{decorative:!1,altText:_},isSvg:!1,structParent:m,popupRef:A}}const n=await super.deserialize(t,e,s),{rect:r,bitmap:a,bitmapUrl:o,bitmapId:l,isSvg:h,accessibilityData:d}=t;l&&s.imageManager.isValidId(l)?(n.#e=l,a&&(n.#t=a)):n.#i=o,n.#c=h;const[u,f]=n.pageDimensions;return n.width=(r[2]-r[0])/u,n.height=(r[3]-r[1])/f,n.annotationElementId=t.id||null,d&&(n.altTextData=d),n._initialData=i,n.#h=!!i,n}serialize(t=!1,e=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const s={annotationType:L.STAMP,bitmapId:this.#e,pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:this.#c,structTreeParentId:this._structTreeParentId};if(t)return s.bitmapUrl=this.#g(!0),s.accessibilityData=this.serializeAltText(!0),s;const{decorative:i,altText:n}=this.serializeAltText(!1);if(!i&&n&&(s.accessibilityData={type:"Figure",alt:n}),this.annotationElementId){const a=this.#b(s);if(a.isSame)return null;a.isSameAltText?delete s.accessibilityData:s.accessibilityData.structParent=this._initialData.structParent??-1}if(s.id=this.annotationElementId,e===null)return s;e.stamps||=new Map;const r=this.#c?(s.rect[2]-s.rect[0])*(s.rect[3]-s.rect[1]):null;if(!e.stamps.has(this.#e))e.stamps.set(this.#e,{area:r,serialized:s}),s.bitmap=this.#g(!1);else if(this.#c){const a=e.stamps.get(this.#e);r>a.area&&(a.area=r,a.serialized.bitmap.close(),a.serialized.bitmap=this.#g(!1))}return s}#b(t){const{pageIndex:e,accessibilityData:{altText:s}}=this._initialData,i=t.pageIndex===e,n=(t.accessibilityData?.alt||"")===s;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&i&&n,isSameAltText:n}}renderAnnotationElement(t){return t.updateEdited({rect:this.getRect(0,0)}),null}}class Ct{#t;#e=!1;#s=null;#i=null;#r=null;#n=new Map;#l=!1;#o=!1;#c=!1;#h=null;#u=null;#d=null;#f=null;#a;static _initialized=!1;static#p=new Map([J,os,ls,q].map(t=>[t._editorType,t]));constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:a,textLayer:o,viewport:l,l10n:h}){const d=[...Ct.#p.values()];if(!Ct._initialized){Ct._initialized=!0;for(const u of d)u.initialize(h,t)}t.registerEditorTypes(d),this.#a=t,this.pageIndex=e,this.div=s,this.#t=n,this.#s=r,this.viewport=l,this.#d=o,this.drawLayer=a,this._structTree=i,this.#a.addLayer(this)}get isEmpty(){return this.#n.size===0}get isInvisible(){return this.isEmpty&&this.#a.getMode()===L.NONE}updateToolbar(t){this.#a.updateToolbar(t)}updateMode(t=this.#a.getMode()){switch(this.#A(),t){case L.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case L.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case L.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:e}=this.div;for(const s of Ct.#p.values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){return t===this.#d?.div}setEditingState(t){this.#a.setEditingState(t)}addCommands(t){this.#a.addCommands(t)}cleanUndoStack(t){this.#a.cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){this.#s?.div.classList.toggle("disabled",!t)}async enable(){this.#c=!0,this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of this.#n.values())s.enableEditing(),s.show(!0),s.annotationElementId&&(this.#a.removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!this.#s){this.#c=!1;return}const e=this.#s.getEditableAnnotations();for(const s of e){if(s.hide(),this.#a.isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}this.#c=!1}disable(){this.#o=!0,this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const i of this.#n.values())if(i.disableEditing(),!!i.annotationElementId){if(i.serialize()!==null){t.set(i.annotationElementId,i);continue}else e.set(i.annotationElementId,i);this.getEditableAnnotation(i.annotationElementId)?.show(),i.remove()}if(this.#s){const i=this.#s.getEditableAnnotations();for(const n of i){const{id:r}=n.data;if(this.#a.isDeletedAnnotationElement(r))continue;let a=e.get(r);if(a){a.resetAnnotationElement(n),a.show(!1),n.show();continue}a=t.get(r),a&&(this.#a.addChangedExistingAnnotation(a),a.renderAnnotationElement(n)&&a.show(!1)),n.show()}}this.#A(),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const i of Ct.#p.values())s.remove(`${i._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),this.#o=!1}getEditableAnnotation(t){return this.#s?.getEditableAnnotation(t)||null}setActiveEditor(t){this.#a.getActive()!==t&&this.#a.setActiveEditor(t)}enableTextSelection(){if(this.div.tabIndex=-1,this.#d?.div&&!this.#f){this.#f=new AbortController;const t=this.#a.combinedSignal(this.#f);this.#d.div.addEventListener("pointerdown",this.#m.bind(this),{signal:t}),this.#d.div.classList.add("highlighting")}}disableTextSelection(){this.div.tabIndex=0,this.#d?.div&&this.#f&&(this.#f.abort(),this.#f=null,this.#d.div.classList.remove("highlighting"))}#m(t){this.#a.unselectAll();const{target:e}=t;if(e===this.#d.div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&this.#d.div.contains(e)){const{isMac:s}=nt.platform;if(t.button!==0||t.ctrlKey&&s)return;this.#a.showAllEditors("highlight",!0,!0),this.#d.div.classList.add("free"),this.toggleDrawing(),q.startHighlighting(this,this.#a.direction==="ltr",{target:this.#d.div,x:t.x,y:t.y}),this.#d.div.addEventListener("pointerup",()=>{this.#d.div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:this.#a._signal}),t.preventDefault()}}enableClick(){if(this.#i)return;this.#i=new AbortController;const t=this.#a.combinedSignal(this.#i);this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){this.#i?.abort(),this.#i=null}attach(t){this.#n.set(t.id,t);const{annotationElementId:e}=t;e&&this.#a.isDeletedAnnotationElement(e)&&this.#a.removeDeletedAnnotationElement(t)}detach(t){this.#n.delete(t.id),this.#t?.removePointerInTextLayer(t.contentDiv),!this.#o&&t.annotationElementId&&this.#a.addDeletedAnnotationElement(t)}remove(t){this.detach(t),this.#a.removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){t.parent!==this&&(t.parent&&t.annotationElementId&&(this.#a.addDeletedAnnotationElement(t.annotationElementId),M.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),t.parent?.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(!(t.parent===this&&t.isAttachedToDOM)){if(this.changeParent(t),this.#a.addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!this.#c),this.#a.addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!this.#r&&(t._focusEventsAllowed=!1,this.#r=setTimeout(()=>{this.#r=null,t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this.#a._signal}),e.focus())},0)),t._structTreeParentId=this.#t?.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||=this,t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getNextId(){return this.#a.getId()}get#g(){return Ct.#p.get(this.#a.getMode())}combinedSignal(t){return this.#a.combinedSignal(t)}#b(t){const e=this.#g;return e?new e.prototype.constructor(t):null}canCreateNewEmptyEditor(){return this.#g?.canCreateNewEmptyEditor()}pasteEditor(t,e){this.#a.updateToolbar(t),this.#a.updateMode(t);const{offsetX:s,offsetY:i}=this.#v(),n=this.getNextId(),r=this.#b({parent:this,id:n,x:s,y:i,uiManager:this.#a,isCentered:!0,...e});r&&this.add(r)}async deserialize(t){return await Ct.#p.get(t.annotationType??t.annotationEditorType)?.deserialize(t,this,this.#a)||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=this.#b({parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:this.#a,isCentered:e,...s});return n&&this.add(n),n}#v(){const{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),a=Math.min(window.innerWidth,t+s),o=Math.min(window.innerHeight,e+i),l=(n+a)/2-t,h=(r+o)/2-e,[d,u]=this.viewport.rotation%180===0?[l,h]:[h,l];return{offsetX:d,offsetY:u}}addNewEditor(){this.createAndAddNewEditor(this.#v(),!0)}setSelected(t){this.#a.setSelected(t)}toggleSelected(t){this.#a.toggleSelected(t)}unselect(t){this.#a.unselect(t)}pointerup(t){const{isMac:e}=nt.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&this.#l&&(this.#l=!1,!(this.#g?.isDrawer&&this.#g.supportMultipleDrawings))){if(!this.#e){this.#e=!0;return}if(this.#a.getMode()===L.STAMP){this.#a.unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){if(this.#a.getMode()===L.HIGHLIGHT&&this.enableTextSelection(),this.#l){this.#l=!1;return}const{isMac:e}=nt.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(this.#l=!0,this.#g?.isDrawer){this.startDrawingSession(t);return}const s=this.#a.getActive();this.#e=!s||s.isEmpty()}startDrawingSession(t){if(this.div.focus(),this.#h){this.#g.startDrawing(this,this.#a,!1,t);return}this.#a.setCurrentDrawingSession(this),this.#h=new AbortController;const e=this.#a.combinedSignal(this.#h);this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(this.#u=null,this.commitOrRemove())},{signal:e}),this.#g.startDrawing(this,this.#a,!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&(this.#u=e);return}this.#u&&setTimeout(()=>{this.#u?.focus(),this.#u=null},0)}endDrawingSession(t=!1){return this.#h?(this.#a.setCurrentDrawingSession(null),this.#h.abort(),this.#h=null,this.#u=null,this.#g.endDrawing(t)):null}findNewParent(t,e,s){const i=this.#a.findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return this.#h?(this.endDrawingSession(),!0):!1}onScaleChanging(){this.#h&&this.#g.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove(),this.#a.getActive()?.parent===this&&(this.#a.commitOrRemove(),this.#a.setActiveEditor(null)),this.#r&&(clearTimeout(this.#r),this.#r=null);for(const t of this.#n.values())this.#t?.removePointerInTextLayer(t.contentDiv),t.setParent(null),t.isAttachedToDOM=!1,t.div.remove();this.div=null,this.#n.clear(),this.#a.removeLayer(this)}#A(){for(const t of this.#n.values())t.isEmpty()&&t.remove()}render({viewport:t}){this.viewport=t,Dt(this.div,t);for(const e of this.#a.getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){this.#a.commitOrRemove(),this.#A();const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,Dt(this.div,{rotation:s}),e!==s)for(const i of this.#n.values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return this.#a.viewParameters.realScale}}class at{#t=null;#e=0;#s=new Map;#i=new Map;constructor({pageIndex:t}){this.pageIndex=t}setParent(t){if(!this.#t){this.#t=t;return}if(this.#t!==t){if(this.#s.size>0)for(const e of this.#s.values())e.remove(),t.append(e);this.#t=t}}static get _svgFactory(){return F(this,"_svgFactory",new es)}static#r(t,[e,s,i,n]){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`}#n(){const t=at._svgFactory.create(1,1,!0);return this.#t.append(t),t.setAttribute("aria-hidden",!0),t}#l(t,e){const s=at._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=at._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i}#o(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)}draw(t,e=!1,s=!1){const i=this.#e++,n=this.#n(),r=at._svgFactory.createElement("defs");n.append(r);const a=at._svgFactory.createElement("path");r.append(a);const o=`path_p${this.pageIndex}_${i}`;a.setAttribute("id",o),a.setAttribute("vector-effect","non-scaling-stroke"),e&&this.#i.set(i,a);const l=s?this.#l(r,o):null,h=at._svgFactory.createElement("use");return n.append(h),h.setAttribute("href",`#${o}`),this.updateProperties(n,t),this.#s.set(i,n),{id:i,clipPathId:`url(#${l})`}}drawOutline(t,e){const s=this.#e++,i=this.#n(),n=at._svgFactory.createElement("defs");i.append(n);const r=at._svgFactory.createElement("path");n.append(r);const a=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",a),r.setAttribute("vector-effect","non-scaling-stroke");let o;if(e){const d=at._svgFactory.createElement("mask");n.append(d),o=`mask_p${this.pageIndex}_${s}`,d.setAttribute("id",o),d.setAttribute("maskUnits","objectBoundingBox");const u=at._svgFactory.createElement("rect");d.append(u),u.setAttribute("width","1"),u.setAttribute("height","1"),u.setAttribute("fill","white");const f=at._svgFactory.createElement("use");d.append(f),f.setAttribute("href",`#${a}`),f.setAttribute("stroke","none"),f.setAttribute("fill","black"),f.setAttribute("fill-rule","nonzero"),f.classList.add("mask")}const l=at._svgFactory.createElement("use");i.append(l),l.setAttribute("href",`#${a}`),o&&l.setAttribute("mask",`url(#${o})`);const h=l.cloneNode();return i.append(h),l.classList.add("mainOutline"),h.classList.add("secondaryOutline"),this.updateProperties(i,t),this.#s.set(s,i),s}finalizeDraw(t,e){this.#i.delete(t),this.updateProperties(t,e)}updateProperties(t,e){if(!e)return;const{root:s,bbox:i,rootClass:n,path:r}=e,a=typeof t=="number"?this.#s.get(t):t;if(a){if(s&&this.#o(a,s),i&&at.#r(a,i),n){const{classList:o}=a;for(const[l,h]of Object.entries(n))o.toggle(l,h)}if(r){const l=a.firstChild.firstChild;this.#o(l,r)}}}updateParent(t,e){if(e===this)return;const s=this.#s.get(t);s&&(e.#t.append(s),this.#s.delete(t),e.#s.set(t,s))}remove(t){this.#i.delete(t),this.#t!==null&&(this.#s.get(t).remove(),this.#s.delete(t))}destroy(){this.#t=null;for(const t of this.#s.values())t.remove();this.#s.clear(),this.#i.clear()}}globalThis.pdfjsTestingUtils={HighlightOutliner:ns},x.AbortException,x.AnnotationEditorLayer,x.AnnotationEditorParamsType,x.AnnotationEditorType,x.AnnotationEditorUIManager,x.AnnotationLayer,x.AnnotationMode,x.ColorPicker,x.DOMSVGFactory,x.DrawLayer,x.FeatureTest;var rr=x.GlobalWorkerOptions;x.ImageKind,x.InvalidPDFException,x.MissingPDFException,x.OPS,x.OutputScale,x.PDFDataRangeTransport,x.PDFDateString,x.PDFWorker,x.PasswordResponses,x.PermissionFlag,x.PixelsPerInch,x.RenderingCancelledException,x.TextLayer,x.TouchManager,x.UnexpectedResponseException,x.Util,x.VerbosityLevel,x.XfaLayer,x.build,x.createValidAbsoluteUrl,x.fetchData;var ar=x.getDocument;x.getFilenameFromUrl,x.getPdfFilenameFromUrl,x.getXfaPageViewport,x.isDataScheme,x.isPdfFile,x.noContextMenu,x.normalizeUnicode,x.setLayerDimensions,x.shadow,x.stopEvent;var or=x.version;function lr(c){return c.arrayBuffer?c.arrayBuffer():new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>{const i=s.result;if(!(i instanceof ArrayBuffer)){e(new Error("Failed to read file as ArrayBuffer."));return}t(i)}),s.addEventListener("error",e),s.readAsArrayBuffer(c)})}rr.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${or}/pdf.worker.min.mjs`,globalThis.addEventListener("message",async c=>{let t=null;try{const{data:e,password:s,id:i,page:n,units:r,scale:a}=c.data,o={fonts:globalThis.fonts,createElement:y=>y==="canvas"?new OffscreenCanvas(1,1):null},l=await lr(e);t=await ar({data:l,password:s,ownerDocument:o}).promise;const h=t.numPages;if(!i){globalThis.postMessage({status:"success",pages:h});return}const d=await t.getPage(n),u=d.getViewport({scale:a}),f=Math.floor(u.width*r),p=Math.floor(u.height*r),g=new OffscreenCanvas(f,p),b=g.getContext("2d");if(!b)throw new Error("Failed to get 2d context from OffscreenCanvas");const m={canvasContext:b,viewport:u,transform:[r,0,0,r,0,0]};await d.render(m).promise;const A=g.transferToImageBitmap();globalThis.postMessage({status:"success",pages:h,bitmap:A,width:f,height:p},[A])}catch(e){globalThis.postMessage({status:"error",error:`${e}`})}finally{t?.destroy()}})})();