@yuuichi/openlist-assets 4.2.6-ym.10 → 4.2.6-ym.12

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 es={d:(c,t)=>{for(var e in t)es.o(t,e)&&!es.o(c,e)&&Object.defineProperty(c,
9
9
  `)}`,this.#u();let d=new Range,u=h.reduce(((p,g)=>p+g.length),0);for(let{firstChild:p}of this.editorDiv.childNodes)if(p.nodeType===Node.TEXT_NODE){let g=p.nodeValue.length;if(u<=g){d.setStart(p,u),d.setEnd(p,u);break}u-=g}n.removeAllRanges(),n.addRange(d)}#u(){if(this.editorDiv.replaceChildren(),this.#e)for(let t of this.#e.split(`
10
10
  `)){let e=document.createElement("div");e.append(t?document.createTextNode(t):document.createElement("br")),this.editorDiv.append(e)}}#d(){return this.#e.replaceAll("\xA0"," ")}static#p(t){return t.replaceAll(" ","\xA0")}get contentDiv(){return this.editorDiv}static async deserialize(t,e,s){let i=null;if(t instanceof Re){let{data:{defaultAppearanceData:{fontSize:r,fontColor:a},rect:o,rotation:h,id:l,popupRef:d},textContent:u,textPosition:p,parent:{page:{pageNumber:g}}}=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:p,pageIndex:g-1,rect:o.slice(0),rotation:h,id:l,deleted:!1,popupRef:d}}let n=await super.deserialize(t,e,s);return n.#r=t.fontSize,n.#t=C.makeHexColor(...t.color),n.#e=c.#p(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();let e=c._internalPadding*this.parentScale,s=this.getRect(e,e),i=U._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){let{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){let e=super.renderAnnotationElement(t);if(this.deleted)return e;let{style:s}=e;s.fontSize=`calc(${this.#r}px * var(--scale-factor))`,s.color=this.#t,e.replaceChildren();for(let n of this.#e.split(`
12
- `)){let r=document.createElement("div");r.append(n?document.createTextNode(n):document.createElement("br")),e.append(r)}let i=c._internalPadding*this.parentScale;return t.updateEdited({rect:this.getRect(i,i),popupContent:this.#e}),e}resetAnnotationElement(t){super.resetAnnotationElement(t),t.resetEdited()}},S=class{static PRECISION=1e-4;toSVGPath(){z("Abstract method `toSVGPath` must be implemented.")}get box(){z("Abstract getter `box` must be implemented.")}serialize(t,e){z("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(1e4*t)}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]}},De=class c{#t;#e=[];#s;#i;#r=[];#n=new Float32Array(18);#h;#o;#c;#l;#u;#d;#p=[];static#a=8;static#g=2;static#m=c.#a+c.#g;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.#l=c.#a*i,this.#c=c.#m*i,this.#u=i,this.#p.push(t,e)}isEmpty(){return isNaN(this.#n[8])}#f(){let t=this.#n.subarray(4,6),e=this.#n.subarray(16,18),[s,i,n,r]=this.#t;return[(this.#h+(t[0]-e[0])/2-s)/n,(this.#o+(t[1]-e[1])/2-i)/r,(this.#h+(e[0]-t[0])/2-s)/n,(this.#o+(e[1]-t[1])/2-i)/r]}add({x:t,y:e}){this.#h=t,this.#o=e;let[s,i,n,r]=this.#t,[a,o,h,l]=this.#n.subarray(8,12),d=t-h,u=e-l,p=Math.hypot(d,u);if(p<this.#c)return!1;let g=p-this.#l,f=g/p,m=f*d,b=f*u,v=a,A=o;a=h,o=l,h+=m,l+=b,this.#p?.push(t,e);let y=m/g,w=-b/g*this.#d,x=y*this.#d;return this.#n.set(this.#n.subarray(2,8),0),this.#n.set([h+w,l+x],4),this.#n.set(this.#n.subarray(14,18),12),this.#n.set([h-w,l-x],16),isNaN(this.#n[6])?(this.#r.length===0&&(this.#n.set([a+w,o+x],2),this.#r.push(NaN,NaN,NaN,NaN,(a+w-s)/n,(o+x-i)/r),this.#n.set([a-w,o-x],14),this.#e.push(NaN,NaN,NaN,NaN,(a-w-s)/n,(o-x-i)/r)),this.#n.set([v,A,a,o,h,l],6),!this.isEmpty()):(this.#n.set([v,A,a,o,h,l],6),Math.abs(Math.atan2(A-o,v-a)-Math.atan2(b,m))<Math.PI/2?([a,o,h,l]=this.#n.subarray(2,6),this.#r.push(NaN,NaN,NaN,NaN,((a+h)/2-s)/n,((o+l)/2-i)/r),[a,o,v,A]=this.#n.subarray(14,18),this.#e.push(NaN,NaN,NaN,NaN,((v+a)/2-s)/n,((A+o)/2-i)/r),!0):([v,A,a,o,h,l]=this.#n.subarray(0,6),this.#r.push(((v+5*a)/6-s)/n,((A+5*o)/6-i)/r,((5*a+h)/6-s)/n,((5*o+l)/6-i)/r,((a+h)/2-s)/n,((o+l)/2-i)/r),[h,l,a,o,v,A]=this.#n.subarray(12,18),this.#e.push(((v+5*a)/6-s)/n,((A+5*o)/6-i)/r,((5*a+h)/6-s)/n,((5*o+l)/6-i)/r,((a+h)/2-s)/n,((o+l)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";let t=this.#r,e=this.#e;if(isNaN(this.#n[6])&&!this.isEmpty())return this.#b();let 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.#v(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.#w(s),s.join(" ")}#b(){let[t,e,s,i]=this.#t,[n,r,a,o]=this.#f();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`}#w(t){let e=this.#e;t.push(`L${e[4]} ${e[5]} Z`)}#v(t){let[e,s,i,n]=this.#t,r=this.#n.subarray(4,6),a=this.#n.subarray(16,18),[o,h,l,d]=this.#f();t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${o} ${h} L${l} ${d} L${(a[0]-e)/i} ${(a[1]-s)/n}`)}newFreeDrawOutline(t,e,s,i,n,r){return new Fe(t,e,s,i,n,r)}getOutlines(){let t=this.#r,e=this.#e,s=this.#n,[i,n,r,a]=this.#t,o=new Float32Array((this.#p?.length??0)+2);for(let d=0,u=o.length-2;d<u;d+=2)o[d]=(this.#p[d]-i)/r,o[d+1]=(this.#p[d+1]-n)/a;if(o[o.length-2]=(this.#h-i)/r,o[o.length-1]=(this.#o-n)/a,isNaN(s[6])&&!this.isEmpty())return this.#y(o);let h=new Float32Array(this.#r.length+24+this.#e.length),l=t.length;for(let d=0;d<l;d+=2)isNaN(t[d])?h[d]=h[d+1]=NaN:(h[d]=t[d],h[d+1]=t[d+1]);l=this.#E(h,l);for(let d=e.length-6;d>=6;d-=6)for(let u=0;u<6;u+=2)isNaN(e[d+u])?(h[l]=h[l+1]=NaN,l+=2):(h[l]=e[d+u],h[l+1]=e[d+u+1],l+=2);return this.#x(h,l),this.newFreeDrawOutline(h,o,this.#t,this.#u,this.#s,this.#i)}#y(t){let e=this.#n,[s,i,n,r]=this.#t,[a,o,h,l]=this.#f(),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,h,l,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)}#x(t,e){let s=this.#e;return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+6}#E(t,e){let s=this.#n.subarray(4,6),i=this.#n.subarray(16,18),[n,r,a,o]=this.#t,[h,l,d,u]=this.#f();return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/a,(s[1]-r)/o,NaN,NaN,NaN,NaN,h,l,NaN,NaN,NaN,NaN,d,u,NaN,NaN,NaN,NaN,(i[0]-n)/a,(i[1]-r)/o],e),e+24}},Fe=class extends S{#t;#e=new Float32Array(4);#s;#i;#r;#n;#h;constructor(t,e,s,i,n,r){super(),this.#h=t,this.#r=e,this.#t=s,this.#n=i,this.#s=n,this.#i=r,this.lastPoint=[NaN,NaN],this.#o(r);let[a,o,h,l]=this.#e;for(let d=0,u=t.length;d<u;d+=2)t[d]=(t[d]-a)/h,t[d+1]=(t[d+1]-o)/l;for(let d=0,u=e.length;d<u;d+=2)e[d]=(e[d]-a)/h,e[d+1]=(e[d+1]-o)/l}toSVGPath(){let t=[`M${this.#h[4]} ${this.#h[5]}`];for(let e=6,s=this.#h.length;e<s;e+=6)isNaN(this.#h[e])?t.push(`L${this.#h[e+4]} ${this.#h[e+5]}`):t.push(`C${this.#h[e]} ${this.#h[e+1]} ${this.#h[e+2]} ${this.#h[e+3]} ${this.#h[e+4]} ${this.#h[e+5]}`);return t.push("Z"),t.join(" ")}serialize([t,e,s,i],n){let r=s-t,a=i-e,o,h;switch(n){case 0:o=S._rescale(this.#h,t,i,r,-a),h=S._rescale(this.#r,t,i,r,-a);break;case 90:o=S._rescaleAndSwap(this.#h,t,e,r,a),h=S._rescaleAndSwap(this.#r,t,e,r,a);break;case 180:o=S._rescale(this.#h,s,e,-r,a),h=S._rescale(this.#r,s,e,-r,a);break;case 270:o=S._rescaleAndSwap(this.#h,s,i,-r,-a),h=S._rescaleAndSwap(this.#r,s,i,-r,-a)}return{outline:Array.from(o),points:[Array.from(h)]}}#o(t){let e=this.#h,s=e[4],i=e[5],n=s,r=i,a=s,o=i,h=s,l=i,d=t?Math.max:Math.min;for(let p=6,g=e.length;p<g;p+=6){if(isNaN(e[p]))n=Math.min(n,e[p+4]),r=Math.min(r,e[p+5]),a=Math.max(a,e[p+4]),o=Math.max(o,e[p+5]),l<e[p+5]?(h=e[p+4],l=e[p+5]):l===e[p+5]&&(h=d(h,e[p+4]));else{let f=C.bezierBoundingBox(s,i,...e.slice(p,p+6));n=Math.min(n,f[0]),r=Math.min(r,f[1]),a=Math.max(a,f[2]),o=Math.max(o,f[3]),l<f[3]?(h=f[2],l=f[3]):l===f[3]&&(h=d(h,f[2]))}s=e[p+4],i=e[p+5]}let 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=[h,l]}get box(){return this.#e}newOutliner(t,e,s,i,n,r=0){return new De(t,e,s,i,n,r)}getNewOutline(t,e){let[s,i,n,r]=this.#e,[a,o,h,l]=this.#t,d=n*h,u=r*l,p=s*h+a,g=i*l+o,f=this.newOutliner({x:this.#r[0]*d+p,y:this.#r[1]*u+g},this.#t,this.#n,t,this.#i,e??this.#s);for(let m=2;m<this.#r.length;m+=2)f.add({x:this.#r[m]*d+p,y:this.#r[m+1]*u+g});return f.getOutlines()}},Qt=class{#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,h=10**-4;for(let{x:m,y:b,width:v,height:A}of t){let y=Math.floor((m-e)/h)*h,w=Math.ceil((m+v+e)/h)*h,x=Math.floor((b-e)/h)*h,_=Math.ceil((b+A+e)/h)*h,E=[y,x,_,!0],M=[w,x,_,!1];this.#s.push(E,M),n=Math.min(n,y),r=Math.max(r,w),a=Math.min(a,x),o=Math.max(o,_)}let l=r-n+2*s,d=o-a+2*s,u=n-s,p=a-s,g=this.#s.at(i?-1:-2),f=[g[0],g[2]];for(let m of this.#s){let[b,v,A]=m;m[0]=(b-u)/l,m[1]=(v-p)/d,m[2]=(A-p)/d}this.#t=new Float32Array([u,p,l,d]),this.#e=f}getOutlines(){this.#s.sort(((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]));let t=[];for(let e of this.#s)e[3]?(t.push(...this.#c(e)),this.#h(e)):(this.#o(e),t.push(...this.#c(e)));return this.#r(t)}#r(t){let e=[],s=new Set;for(let r of t){let[a,o,h]=r;e.push([a,o,r],[a,h,r])}e.sort(((r,a)=>r[1]-a[1]||r[0]-a[0]));for(let r=0,a=e.length;r<a;r+=2){let o=e[r][2],h=e[r+1][2];o.push(h),h.push(o),s.add(o),s.add(h)}let i=[],n;for(;s.size>0;){let r=s.values().next().value,[a,o,h,l,d]=r;s.delete(r);let u=a,p=o;for(n=[a,h],i.push(n);;){let g;if(s.has(l))g=l;else{if(!s.has(d))break;g=d}s.delete(g),[a,o,h,l,d]=g,u!==a&&(n.push(u,p,a,p===o?o:h),u=a),p=p===o?h:o}n.push(u,p)}return new li(i,this.#t,this.#e)}#n(t){let e=this.#i,s=0,i=e.length-1;for(;s<=i;){let n=s+i>>1,r=e[n][0];if(r===t)return n;r<t?s=n+1:i=n-1}return i+1}#h([,t,e]){let s=this.#n(t);this.#i.splice(s,0,[t,e])}#o([,t,e]){let s=this.#n(t);for(let i=s;i<this.#i.length;i++){let[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--){let[n,r]=this.#i[i];if(n!==t)break;if(n===t&&r===e){this.#i.splice(i,1);return}}}#c(t){let[e,s,i]=t,n=[[e,s,i]],r=this.#n(i);for(let a=0;a<r;a++){let[o,h]=this.#i[a];for(let l=0,d=n.length;l<d;l++){let[,u,p]=n[l];if(!(h<=u||p<=o))if(u>=o)if(p>h)n[l][1]=h;else{if(d===1)return[];n.splice(l,1),l--,d--}else n[l][2]=o,p>h&&n.push([e,h,p])}}return n}},li=class extends S{#t;#e;constructor(t,e,s){super(),this.#e=t,this.#t=e,this.lastPoint=s}toSVGPath(){let t=[];for(let e of this.#e){let[s,i]=e;t.push(`M${s} ${i}`);for(let n=2;n<e.length;n+=2){let 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){let r=[],a=s-t,o=i-e;for(let h of this.#e){let l=new Array(h.length);for(let d=0;d<h.length;d+=2)l[d]=t+h[d]*a,l[d+1]=i-h[d+1]*o;r.push(l)}return r}get box(){return this.#t}get classNamesForOutlining(){return["highlightOutline"]}},Jt=class extends De{newFreeDrawOutline(t,e,s,i,n,r){return new ci(t,e,s,i,n,r)}},ci=class extends Fe{newOutliner(t,e,s,i,n,r=0){return new Jt(t,e,s,i,n,r)}},Ne=class c{#t=null;#e=null;#s;#i=null;#r=!1;#n=!1;#h=null;#o;#c=null;#l=null;#u;static#d=null;static get _keyboardManager(){return N(this,"_keyboardManager",new Ct([[["Escape","mac+Escape"],c.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],c.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],c.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],c.prototype._moveToPrevious],[["Home","mac+Home"],c.prototype._moveToBeginning],[["End","mac+End"],c.prototype._moveToEnd]]))}constructor({editor:t=null,uiManager:e=null}){t?(this.#n=!1,this.#u=B.HIGHLIGHT_COLOR,this.#h=t):(this.#n=!0,this.#u=B.HIGHLIGHT_DEFAULT_COLOR),this.#l=t?._uiManager||e,this.#o=this.#l._eventBus,this.#s=t?.color||this.#l?.highlightColors.values().next().value||"#FFFF98",c.#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(){let 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);let e=this.#l._signal;t.addEventListener("click",this.#m.bind(this),{signal:e}),t.addEventListener("keydown",this.#g.bind(this),{signal:e});let 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(){let t=this.#i=this.#p();return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}#p(){let t=document.createElement("div"),e=this.#l._signal;t.addEventListener("contextmenu",ot,{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(let[s,i]of this.#l.highlightColors){let n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",c.#d[s]);let 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.#g.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}let e=t.target.getAttribute("data-color");e&&this.#a(e,t)}_moveToNext(t){this.#b?t.target!==this.#t?t.target.nextSibling?.focus():this.#i.firstChild?.focus():this.#m(t)}_moveToPrevious(t){t.target!==this.#i?.firstChild&&t.target!==this.#t?(this.#b||this.#m(t),t.target.previousSibling?.focus()):this.#b&&this._hideDropdownFromKeyboard()}_moveToBeginning(t){this.#b?this.#i.firstChild?.focus():this.#m(t)}_moveToEnd(t){this.#b?this.#i.lastChild?.focus():this.#m(t)}#g(t){c._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.#f.bind(this),{signal:this.#l.combinedSignal(this.#c)})),this.#i){this.#i.classList.remove("hidden");return}let e=this.#i=this.#p();this.#t.append(e)}#f(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(){this.#n||(this.#b?(this.hideDropdown(),this.#t.focus({preventScroll:!0,focusVisible:this.#r})):this.#h?.unselect())}updateColor(t){if(this.#e&&(this.#e.style.backgroundColor=t),!this.#i)return;let e=this.#l.highlightColors.values();for(let 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}},Oe=class c extends U{#t=null;#e=0;#s;#i=null;#r=null;#n=null;#h=null;#o=0;#c=null;#l=null;#u=null;#d=!1;#p=null;#a;#g=null;#m="";#f;#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(){let t=c.prototype;return N(this,"_keyboardManager",new Ct([[["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||c._defaultColor,this.#f=t.thickness||c._defaultThickness,this.#a=t.opacity||c._defaultOpacity,this.#s=t.boxes||null,this.#b=t.methodOfCreation||"",this.#m=t.text||"",this._isDraggable=!1,t.highlightId>-1?(this.#d=!0,this.#v(t),this.#T()):this.#s&&(this.#t=t.anchorNode,this.#e=t.anchorOffset,this.#h=t.focusNode,this.#o=t.focusOffset,this.#w(),this.#T(),this.rotate(this.rotation))}get telemetryInitialData(){return{action:"added",type:this.#d?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:this.#f,methodOfCreation:this.#b}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(t){return{numberOfColors:t.get("color").size}}#w(){let t=new Qt(this.#s,.001);this.#l=t.getOutlines(),[this.x,this.y,this.width,this.height]=this.#l.box;let e=new Qt(this.#s,.0025,.001,this._uiManager.direction==="ltr");this.#n=e.getOutlines();let{lastPoint:s}=this.#n;this.#p=[(s[0]-this.x)/this.width,(s[1]-this.y)/this.height]}#v({highlightOutlines:t,highlightId:e,clipPathId:s}){if(this.#l=t,this.#n=t.getNewOutline(this.#f/2+1.5,.0025),e>=0)this.#u=e,this.#i=s,this.parent.drawLayer.finalizeDraw(e,{bbox:t.box,path:{d:t.toSVGPath()}}),this.#g=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#n.box,path:{d:this.#n.toSVGPath()}},!0);else if(this.parent){let h=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#u,{bbox:c.#_(this.#l.box,(h-this.rotation+360)%360),path:{d:t.toSVGPath()}}),this.parent.drawLayer.updateProperties(this.#g,{bbox:c.#_(this.#n.box,h),path:{d:this.#n.toSVGPath()}})}let[i,n,r,a]=t.box;switch(this.rotation){case 0:this.x=i,this.y=n,this.width=r,this.height=a;break;case 90:{let[h,l]=this.parentDimensions;this.x=n,this.y=1-i,this.width=r*l/h,this.height=a*h/l;break}case 180:this.x=1-i,this.y=1-n,this.width=r,this.height=a;break;case 270:{let[h,l]=this.parentDimensions;this.x=1-n,this.y=i,this.width=r*l/h,this.height=a*h/l;break}}let{lastPoint:o}=this.#n;this.#p=[(o[0]-i)/r,(o[1]-n)/a]}static initialize(t,e){U.initialize(t,e),c._defaultColor||=e.highlightColors?.values().next().value||"#fff066"}static updateDefaultParams(t,e){switch(t){case B.HIGHLIGHT_DEFAULT_COLOR:c._defaultColor=e;break;case B.HIGHLIGHT_THICKNESS:c._defaultThickness=e}}translateInPage(t,e){}get toolbarPosition(){return this.#p}updateParams(t,e){switch(t){case B.HIGHLIGHT_COLOR:this.#y(e);break;case B.HIGHLIGHT_THICKNESS:this.#x(e)}}static get defaultPropertiesToUpdate(){return[[B.HIGHLIGHT_DEFAULT_COLOR,c._defaultColor],[B.HIGHLIGHT_THICKNESS,c._defaultThickness]]}get propertiesToUpdate(){return[[B.HIGHLIGHT_COLOR,this.color||c._defaultColor],[B.HIGHLIGHT_THICKNESS,this.#f||c._defaultThickness],[B.HIGHLIGHT_FREE,this.#d]]}#y(t){let 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,c._defaultOpacity),undo:e.bind(this,s,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:B.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(t)},!0)}#x(t){let e=this.#f,s=i=>{this.#f=i,this.#E(i)};this.addCommands({cmd:s.bind(this,t),undo:s.bind(this,e),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:B.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:t},!0)}async addEditToolbar(){let t=await super.addEditToolbar();return t?(this._uiManager.highlightColors&&(this.#r=new Ne({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.#P())}getBaseTranslation(){return[0,0]}getRect(t,e){return super.getRect(t,e,this.#P())}onceAdded(t){this.annotationElementId||this.parent.addUndoableEditor(this),t&&this.div.focus()}remove(){this.#M(),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#T(),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){let e=!1;this.parent&&!t?this.#M():t&&(this.#T(t),e=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(t),this.show(this._isVisible),e&&this.select()}#E(t){if(!this.#d)return;this.#v({highlightOutlines:this.#l.getNewOutline(t/2)}),this.fixAndSetPosition();let[e,s]=this.parentDimensions;this.setDims(this.width*e,this.height*s)}#M(){this.#u!==null&&this.parent&&(this.parent.drawLayer.remove(this.#u),this.#u=null,this.parent.drawLayer.remove(this.#g),this.#g=null)}#T(t=this.parent){this.#u===null&&({id:this.#u,clipPathId:this.#i}=t.drawLayer.draw({bbox:this.#l.box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":this.#a},rootClass:{highlight:!0,free:this.#d},path:{d:this.#l.toSVGPath()}},!1,!0),this.#g=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){let{drawLayer:e}=this.parent,s;this.#d?(t=(t-this.rotation+360)%360,s=c.#_(this.#l.box,t)):s=c.#_([this.x,this.y,this.width,this.height],t),e.updateProperties(this.#u,{bbox:s,root:{"data-main-rotation":t}}),e.updateProperties(this.#g,{bbox:c.#_(this.#n.box,t),root:{"data-main-rotation":t}})}render(){if(this.div)return this.div;let 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.#k.bind(this),{signal:this._uiManager._signal});let e=this.#c=document.createElement("div");t.append(e),e.setAttribute("aria-hidden","true"),e.className="internal",e.style.clipPath=this.#i;let[s,i]=this.parentDimensions;return this.setDims(this.width*s,this.height*i),ce(this,this.#c,["pointerover","pointerleave"]),this.enableEditing(),t}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#g,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#g,{rootClass:{hovered:!1}})}#k(t){c._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)}}#C(t){if(!this.#t)return;let e=window.getSelection();t?e.setPosition(this.#t,this.#e):e.setPosition(this.#h,this.#o)}select(){super.select(),this.#g&&this.parent?.drawLayer.updateProperties(this.#g,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect(),this.#g&&(this.parent?.drawLayer.updateProperties(this.#g,{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.#g,{rootClass:{hidden:!t}}))}#P(){return this.#d?this.rotation:0}#D(){if(this.#d)return null;let[t,e]=this.pageDimensions,[s,i]=this.pageTranslation,n=this.#s,r=new Float32Array(8*n.length),a=0;for(let{x:o,y:h,width:l,height:d}of n){let u=o*t+s,p=(1-h)*e+i;r[a]=r[a+4]=u,r[a+1]=r[a+3]=p,r[a+2]=r[a+6]=u+l*t,r[a+5]=r[a+7]=p-d*e,a+=8}return r}#N(t){return this.#l.serialize(t,this.#P())}static startHighlighting(t,e,{target:s,x:i,y:n}){let{x:r,y:a,width:o,height:h}=s.getBoundingClientRect(),l=new AbortController,d=t.combinedSignal(l),u=p=>{l.abort(),this.#A(t,p)};window.addEventListener("blur",u,{signal:d}),window.addEventListener("pointerup",u,{signal:d}),window.addEventListener("pointerdown",it,{capture:!0,passive:!1,signal:d}),window.addEventListener("contextmenu",ot,{signal:d}),s.addEventListener("pointermove",this.#S.bind(this,t),{signal:d}),this._freeHighlight=new Jt({x:i,y:n},[r,a,o,h],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#S(t,e){this._freeHighlight.add(e)&&t.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#A(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 Ie){let{data:{quadPoints:g,rect:f,rotation:m,id:b,color:v,opacity:A,popupRef:y},parent:{page:{pageNumber:w}}}=t;i=t={annotationType:L.HIGHLIGHT,color:Array.from(v),opacity:A,quadPoints:g,boxes:null,pageIndex:w-1,rect:f.slice(0),rotation:m,id:b,deleted:!1,popupRef:y}}else if(t instanceof Kt){let{data:{inkLists:g,rect:f,rotation:m,id:b,color:v,borderStyle:{rawWidth:A},popupRef:y},parent:{page:{pageNumber:w}}}=t;i=t={annotationType:L.HIGHLIGHT,color:Array.from(v),thickness:A,inkLists:g,boxes:null,pageIndex:w-1,rect:f.slice(0),rotation:m,id:b,deleted:!1,popupRef:y}}let{color:n,quadPoints:r,inkLists:a,opacity:o}=t,h=await super.deserialize(t,e,s);h.color=C.makeHexColor(...n),h.#a=o||1,a&&(h.#f=t.thickness),h.annotationElementId=t.id||null,h._initialData=i;let[l,d]=h.pageDimensions,[u,p]=h.pageTranslation;if(r){let g=h.#s=[];for(let f=0;f<r.length;f+=8)g.push({x:(r[f]-u)/l,y:1-(r[f+1]-p)/d,width:(r[f+2]-r[f])/l,height:(r[f+1]-r[f+5])/d});h.#w(),h.#T(),h.rotate(h.rotation)}else if(a){h.#d=!0;let g=a[0],f={x:g[0]-u,y:d-(g[1]-p)},m=new Jt(f,[0,0,l,d],1,h.#f/2,!0,.001);for(let A=0,y=g.length;A<y;A+=2)f.x=g[A]-u,f.y=d-(g[A+1]-p),m.add(f);let{id:b,clipPathId:v}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:h.color,"fill-opacity":h._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:m.toSVGPath()}},!0,!0);h.#v({highlightOutlines:m.getOutlines(),highlightId:b,clipPathId:v}),h.#T()}return h}serialize(t=!1){if(this.isEmpty()||t)return null;if(this.deleted)return this.serializeDeleted();let e=this.getRect(0,0),s=U._colorManager.convert(this.color),i={annotationType:L.HIGHLIGHT,color:s,opacity:this.#a,thickness:this.#f,quadPoints:this.#D(),outlines:this.#N(e),pageIndex:this.pageIndex,rect:e,rotation:this.#P(),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!this.#L(i)?null:(i.id=this.annotationElementId,i)}#L(t){let{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}},di=class{#t=Object.create(null);updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(let[e,s]of Object.entries(t))this.updateProperty(e,s)}updateSVGProperty(t,e){this.#t[t]=e}toSVGProperties(){let t=this.#t;return this.#t=Object.create(null),{root:t}}reset(){this.#t=Object.create(null)}updateAll(t=this){this.updateProperties(t)}clone(){z("Not implemented")}},ui=class c extends U{#t=null;#e;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#s=null;static#i=null;static#r=null;static#n=NaN;static#h=null;static#o=null;static#c=NaN;static _INNER_MARGIN=3;constructor(t){super(t),this.#e=t.mustBeCommitted||!1,t.drawOutlines&&(this.#l(t),this.#p())}#l({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){let{id:s}=e.drawLayer.draw(c._mergeSVGProperties(this._drawingOptions.toSVGProperties(),t.defaultSVGProperties),!1,!1);return s}static _mergeSVGProperties(t,e){let s=new Set(Object.keys(t));for(let[i,n]of Object.entries(e))s.has(i)?Object.assign(t[i],n):t[i]=n;return t}static getDefaultDrawingOptions(t){z("Not implemented")}static get typesMap(){z("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(t,e){let s=this.typesMap.get(t);s&&this._defaultDrawingOptions.updateProperty(s,e),this._currentParent&&(c.#s.updateProperty(s,e),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(t,e){let s=this.constructor.typesMap.get(t);s&&this._updateProperty(t,s,e)}static get defaultPropertiesToUpdate(){let t=[],e=this._defaultDrawingOptions;for(let[s,i]of this.typesMap)t.push([s,e[i]]);return t}get propertiesToUpdate(){let t=[],{_drawingOptions:e}=this;for(let[s,i]of this.constructor.typesMap)t.push([s,e[i]]);return t}_updateProperty(t,e,s){let i=this._drawingOptions,n=i[e],r=a=>{i.updateProperty(e,a);let 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,c._mergeSVGProperties(this.#t.getPathResizingSVGProperties(this.#g()),{bbox:this.#f()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,c._mergeSVGProperties(this.#t.getPathResizedSVGProperties(this.#g()),{bbox:this.#f()}))}_onTranslating(t,e){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#f(t,e)})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,c._mergeSVGProperties(this.#t.getPathTranslatedSVGProperties(this.#g(),this.parentDimensions),{bbox:this.#f()}))}_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.#p(),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.#p(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())}#p(t=this.parent){(this._drawId===null||this.parent!==t)&&(this._drawId===null?(this._drawingOptions.updateAll(),this._drawId=this.#u(this.#t,t)):this.parent.drawLayer.updateParent(this._drawId,t.drawLayer))}#a([t,e,s,i]){let{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]}}#g(){let{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();let[e,s]=this.parentDimensions;this.setDims(this.width*e,this.height*s)}this._onResized()}#f(){let{x:t,y:e,width:s,height:i,rotation:n,parentRotation:r,parentDimensions:[a,o]}=this;switch((4*n+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,c._mergeSVGProperties({bbox:this.#f()},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;let t=super.render();t.classList.add("draw");let e=document.createElement("div");t.append(e),e.setAttribute("aria-hidden","true"),e.className="internal";let[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){z("Not implemented")}static startDrawing(t,e,s,i){let{target:n,offsetX:r,offsetY:a,pointerId:o,pointerType:h}=i;if(c.#h&&c.#h!==h)return;let{viewport:{rotation:l}}=t,{width:d,height:u}=n.getBoundingClientRect(),p=c.#i=new AbortController,g=t.combinedSignal(p);c.#n||=o,c.#h??=h,window.addEventListener("pointerup",(f=>{c.#n===f.pointerId?this._endDraw(f):c.#o?.delete(f.pointerId)}),{signal:g}),window.addEventListener("pointercancel",(f=>{c.#n===f.pointerId?this._currentParent.endDrawingSession():c.#o?.delete(f.pointerId)}),{signal:g}),window.addEventListener("pointerdown",(f=>{c.#h===f.pointerType&&((c.#o||=new Set).add(f.pointerId),c.#s.isCancellable()&&(c.#s.removeLastElement(),c.#s.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))}),{capture:!0,passive:!1,signal:g}),window.addEventListener("contextmenu",ot,{signal:g}),n.addEventListener("pointermove",this._drawMove.bind(this),{signal:g}),n.addEventListener("touchmove",(f=>{f.timeStamp===c.#c&&it(f)}),{signal:g}),t.toggleDrawing(),e._editorUndoBar?.hide(),c.#s?t.drawLayer.updateProperties(this._currentDrawId,c.#s.startNew(r,a,d,u,l)):(e.updateUIForDefaultProperties(this),c.#s=this.createDrawerInstance(r,a,d,u,l),c.#r=this.getDefaultDrawingOptions(),this._currentParent=t,{id:this._currentDrawId}=t.drawLayer.draw(this._mergeSVGProperties(c.#r.toSVGProperties(),c.#s.defaultSVGProperties),!0,!1))}static _drawMove(t){if(c.#c=-1,!c.#s)return;let{offsetX:e,offsetY:s,pointerId:i}=t;c.#n===i&&(c.#o?.size>=1?this._endDraw(t):(this._currentParent.drawLayer.updateProperties(this._currentDrawId,c.#s.add(e,s)),c.#c=t.timeStamp,it(t)))}static _cleanup(t){t&&(this._currentDrawId=-1,this._currentParent=null,c.#s=null,c.#r=null,c.#h=null,c.#c=NaN),c.#i&&(c.#i.abort(),c.#i=null,c.#n=NaN,c.#o=null)}static _endDraw(t){let e=this._currentParent;if(e)if(e.toggleDrawing(!0),this._cleanup(!1),t&&e.drawLayer.updateProperties(this._currentDrawId,c.#s.end(t.offsetX,t.offsetY)),this.supportMultipleDrawings){let s=c.#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:B.DRAW_STEP})}else this.endDrawing(!1)}static endDrawing(t){let e=this._currentParent;if(!e)return null;if(e.toggleDrawing(!0),e.cleanUndoStack(B.DRAW_STEP),!c.#s.isEmpty()){let{pageDimensions:[s,i],scale:n}=e,r=e.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:c.#s.getOutlines(s*n,i*n,n,this._INNER_MARGIN),drawingOptions:c.#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){z("Not implemented")}static async deserialize(t,e,s){let{rawDims:{pageWidth:i,pageHeight:n,pageX:r,pageY:a}}=e.viewport,o=this.deserializeDraw(r,a,i,n,this._INNER_MARGIN,t),h=await super.deserialize(t,e,s);return h.createDrawingOptions(t),h.#l({drawOutlines:o}),h.#p(),h.onScaleChanging(),h.rotate(),h}serializeDraw(t){let[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}},pi=class{#t=new Float64Array(6);#e;#s;#i;#r;#n;#h="";#o=0;#c=new Be;#l;#u;constructor(t,e,s,i,n,r){this.#l=s,this.#u=i,this.#i=n,this.#r=r,[t,e]=this.#d(t,e);let 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 S._normalizePoint(t,e,this.#l,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);let[s,i,n,r]=this.#t.subarray(2,6),a=t-n,o=e-r;return Math.hypot(this.#l*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(...S.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){return this.add(t,e)||(this.#n.length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){this.#l=s,this.#u=i,this.#i=n,[t,e]=this.#d(t,e);let r=this.#e=[NaN,NaN,NaN,NaN,t,e];this.#n=[t,e];let 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.#h="";for(let t=0,e=this.#s.length;t<e;t++){let{line:s,points:i}=this.#s[t];this.#e=s,this.#n=i,this.#o=0,this.toSVGPath()}return{path:{d:this.#h}}}toSVGPath(){let t=S.svgRound(this.#e[4]),e=S.svgRound(this.#e[5]);if(this.#n.length===2)return this.#h=`${this.#h} M ${t} ${e} Z`,this.#h;if(this.#n.length<=6){let i=this.#h.lastIndexOf("M");this.#h=`${this.#h.slice(0,i)} M ${t} ${e}`,this.#o=6}if(this.#n.length===4){let i=S.svgRound(this.#e[10]),n=S.svgRound(this.#e[11]);return this.#h=`${this.#h} L ${i} ${n}`,this.#o=12,this.#h}let 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){let[r,a,o,h,l,d]=this.#e.slice(i,i+6).map(S.svgRound);s.push(`C${r} ${a} ${o} ${h} ${l} ${d}`)}return this.#h+=s.join(" "),this.#o=this.#e.length,this.#h}getOutlines(t,e,s,i){let 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.#h=null,this.#c}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}},Be=class c extends S{#t;#e=0;#s;#i;#r;#n;#h;#o;#c;build(t,e,s,i,n,r,a){this.#r=e,this.#n=s,this.#h=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(){let t=[];for(let{line:e}of this.#i)if(t.push(`M${S.svgRound(e[4])} ${S.svgRound(e[5])}`),e.length!==6)if(e.length!==12)for(let s=6,i=e.length;s<i;s+=6){let[n,r,a,o,h,l]=e.subarray(s,s+6).map(S.svgRound);t.push(`C${n} ${r} ${a} ${o} ${h} ${l}`)}else t.push(`L${S.svgRound(e[10])} ${S.svgRound(e[11])}`);else t.push("Z");return t.join("")}serialize([t,e,s,i],n){let r=[],a=[],[o,h,l,d]=this.#u(),u,p,g,f,m,b,v,A,y;switch(this.#o){case 0:y=S._rescale,u=t,p=e+i,g=s,f=-i,m=t+o*s,b=e+(1-h-d)*i,v=t+(o+l)*s,A=e+(1-h)*i;break;case 90:y=S._rescaleAndSwap,u=t,p=e,g=s,f=i,m=t+h*s,b=e+o*i,v=t+(h+d)*s,A=e+(o+l)*i;break;case 180:y=S._rescale,u=t+s,p=e,g=-s,f=i,m=t+(1-o-l)*s,b=e+h*i,v=t+(1-o)*s,A=e+(h+d)*i;break;case 270:y=S._rescaleAndSwap,u=t+s,p=e+i,g=-s,f=-i,m=t+(1-h-d)*s,b=e+(1-o-l)*i,v=t+(1-h)*s,A=e+(1-o)*i}for(let{line:w,points:x}of this.#i)r.push(y(w,u,p,g,f,n?new Array(w.length):null)),a.push(y(x,u,p,g,f,n?new Array(x.length):null));return{lines:r,points:a,rect:[m,b,v,A]}}static deserialize(t,e,s,i,n,{paths:{lines:r,points:a},rotation:o,thickness:h}){let l=[],d,u,p,g,f;switch(o){case 0:f=S._rescale,d=-t/s,u=e/i+1,p=1/s,g=-1/i;break;case 90:f=S._rescaleAndSwap,d=-e/i,u=-t/s,p=1/i,g=1/s;break;case 180:f=S._rescale,d=t/s+1,u=-e/i,p=-1/s,g=1/i;break;case 270:f=S._rescaleAndSwap,d=e/i+1,u=t/s+1,p=-1/i,g=-1/s}if(!r){r=[];for(let b of a){let v=b.length;if(v===2){r.push(new Float32Array([NaN,NaN,NaN,NaN,b[0],b[1]]));continue}if(v===4){r.push(new Float32Array([NaN,NaN,NaN,NaN,b[0],b[1],NaN,NaN,NaN,NaN,b[2],b[3]]));continue}let A=new Float32Array(3*(v-2));r.push(A);let[y,w,x,_]=b.subarray(0,4);A.set([NaN,NaN,NaN,NaN,y,w],0);for(let E=4;E<v;E+=2){let M=b[E],T=b[E+1];A.set(S.createBezierPoints(y,w,x,_,M,T),3*(E-2)),[y,w,x,_]=[x,_,M,T]}}}for(let b=0,v=r.length;b<v;b++)l.push({line:f(r[b].map((A=>A??NaN)),d,u,p,g),points:f(a[b].map((A=>A??NaN)),d,u,p,g)});let m=new c;return m.build(l,s,i,1,o,h,n),m}#l(t=this.#c){let e=this.#s+t/2*this.#h;return this.#o%180==0?[e/this.#r,e/this.#n]:[e/this.#n,e/this.#r]}#u(){let[t,e,s,i]=this.#t,[n,r]=this.#l(0);return[t+n,e+r,s-2*n,i-2*r]}#d(){let t=this.#t=new Float32Array([1/0,1/0,-1/0,-1/0]);for(let{line:i}of this.#i){if(i.length<=12){for(let a=4,o=i.length;a<o;a+=6){let[h,l]=i.subarray(a,a+2);t[0]=Math.min(t[0],h),t[1]=Math.min(t[1],l),t[2]=Math.max(t[2],h),t[3]=Math.max(t[3],l)}continue}let n=i[4],r=i[5];for(let a=6,o=i.length;a<o;a+=6){let[h,l,d,u,p,g]=i.subarray(a,a+6);C.bezierBoundingBox(n,r,h,l,d,u,p,g,t),n=p,r=g}}let[e,s]=this.#l();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.#p(e):null}#p(t){let[e,s]=this.#l();this.#c=t;let[i,n]=this.#l(),[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){let[i,n]=this.#l();this.#r=t,this.#n=e,this.#h=s;let[r,a]=this.#l(),o=r-i,h=a-n,l=this.#t;return l[0]-=o,l[1]-=h,l[2]+=2*o,l[3]+=2*h,l}updateRotation(t){return this.#e=t,{path:{transform:this.rotationTransform}}}get viewBox(){return this.#t.map(S.svgRound).join(" ")}get defaultProperties(){let[t,e]=this.#t;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${S.svgRound(t)} ${S.svgRound(e)}`}}}get rotationTransform(){let[,,t,e]=this.#t,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} ${S.svgRound(a)} ${S.svgRound(o)})`}getPathResizingSVGProperties([t,e,s,i]){let[n,r]=this.#l(),[a,o,h,l]=this.#t;if(Math.abs(h-n)<=S.PRECISION||Math.abs(l-r)<=S.PRECISION){let f=t+s/2-(a+h/2),m=e+i/2-(o+l/2);return{path:{"transform-origin":`${S.svgRound(t)} ${S.svgRound(e)}`,transform:`${this.rotationTransform} translate(${f} ${m})`}}}let d=(s-2*n)/(h-2*n),u=(i-2*r)/(l-2*r),p=h/s,g=l/i;return{path:{"transform-origin":`${S.svgRound(a)} ${S.svgRound(o)}`,transform:`${this.rotationTransform} scale(${p} ${g}) translate(${S.svgRound(n)} ${S.svgRound(r)}) scale(${d} ${u}) translate(${S.svgRound(-n)} ${S.svgRound(-r)})`}}}getPathResizedSVGProperties([t,e,s,i]){let[n,r]=this.#l(),a=this.#t,[o,h,l,d]=a;if(a[0]=t,a[1]=e,a[2]=s,a[3]=i,Math.abs(l-n)<=S.PRECISION||Math.abs(d-r)<=S.PRECISION){let m=t+s/2-(o+l/2),b=e+i/2-(h+d/2);for(let{line:v,points:A}of this.#i)S._translate(v,m,b,v),S._translate(A,m,b,A);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${S.svgRound(t)} ${S.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}let u=(s-2*n)/(l-2*n),p=(i-2*r)/(d-2*r),g=-u*(o+n)+t+n,f=-p*(h+r)+e+r;if(u!==1||p!==1||g!==0||f!==0)for(let{line:m,points:b}of this.#i)S._rescale(m,g,f,u,p,m),S._rescale(b,g,f,u,p,b);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${S.svgRound(t)} ${S.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([t,e],s){let[i,n]=s,r=this.#t,a=t-r[0],o=e-r[1];if(this.#r===i&&this.#n===n)for(let{line:h,points:l}of this.#i)S._translate(h,a,o,h),S._translate(l,a,o,l);else{let h=this.#r/i,l=this.#n/n;this.#r=i,this.#n=n;for(let{line:d,points:u}of this.#i)S._rescale(d,a,o,h,l,d),S._rescale(u,a,o,h,l,u);r[2]*=h,r[3]*=l}return r[0]=t,r[1]=e,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${S.svgRound(t)} ${S.svgRound(e)}`}}}get defaultSVGProperties(){let t=this.#t;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${S.svgRound(t[0])} ${S.svgRound(t[1])}`,transform:this.rotationTransform||null},bbox:t}}},gi=class c extends di{#t;constructor(t){super(),this.#t=t,super.updateProperties({fill:"none",stroke:U._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(){let t=new c(this.#t);return t.updateAll(this),t}},fi=class c extends ui{static _type="ink";static _editorType=L.INK;static _defaultDrawingOptions=null;constructor(t){super({...t,name:"inkEditor"}),this._willKeepAspectRatio=!0}static initialize(t,e){U.initialize(t,e),this._defaultDrawingOptions=new gi(e.viewParameters)}static getDefaultDrawingOptions(t){let e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!0}static get typesMap(){return N(this,"typesMap",new Map([[B.INK_THICKNESS,"stroke-width"],[B.INK_COLOR,"stroke"],[B.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(t,e,s,i,n){return new pi(t,e,s,i,n,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(t,e,s,i,n,r){return Be.deserialize(t,e,s,i,n,r)}static async deserialize(t,e,s){let i=null;if(t instanceof Kt){let{data:{inkLists:r,rect:a,rotation:o,id:h,color:l,opacity:d,borderStyle:{rawWidth:u},popupRef:p},parent:{page:{pageNumber:g}}}=t;i=t={annotationType:L.INK,color:Array.from(l),thickness:u,opacity:d,paths:{points:r},boxes:null,pageIndex:g-1,rect:a.slice(0),rotation:o,id:h,deleted:!1,popupRef:p}}let n=await super.deserialize(t,e,s);return n.annotationElementId=t.id||null,n._initialData=i,n}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();let{_drawId:t,_drawingOptions:e,parent:s}=this;e.updateSVGProperty("stroke-width"),s.drawLayer.updateProperties(t,e.toSVGProperties())}static onScaleChangingWhenDrawing(){let 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=c.getDefaultDrawingOptions({stroke:C.makeHexColor(...t),"stroke-width":e,"stroke-opacity":s})}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let{lines:e,points:s,rect:i}=this.serializeDraw(t),{_drawingOptions:{stroke:n,"stroke-opacity":r,"stroke-width":a}}=this,o={annotationType:L.INK,color:U._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){let{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){let{points:e,rect:s}=this.serializeDraw(!1);return t.updateEdited({rect:s,thickness:this._drawingOptions["stroke-width"],points:e}),null}},mi=class c extends U{#t=null;#e=null;#s=null;#i=null;#r=null;#n="";#h=null;#o=null;#c=!1;#l=!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){U.initialize(t,e)}static get supportedTypes(){return N(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map((t=>`image/${t}`)))}static get supportedTypesStr(){return N(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){let e=t.get("hasAltText");return{hasAltText:e.get(!0)??0,hasNoAltText:e.get(!1)??0}}#u(t,e=!1){t?(this.#t=t.bitmap,e||(this.#e=t.id,this.#c=t.isSvg),t.file&&(this.#n=t.file.name),this.#a()):this.remove()}#d(){if(this.#s=null,this._uiManager.enableWaiting(!1),this.#h)if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#t)this._editToolbar.hide(),this._uiManager.editAltText(this,!0);else{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;let{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.");let{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.");let o=a.output;return await this.setGuessedAltText(o),e&&!this.hasAltTextData()&&(this.altTextData={alt:o,decorative:!1}),o}#p(){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){let 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){let 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}let t=document.createElement("input");t.type="file",t.accept=c.supportedTypesStr;let e=this._uiManager._signal;this.#s=new Promise((s=>{t.addEventListener("change",(async()=>{if(t.files&&t.files.length!==0){this._uiManager.enableWaiting(!0);let 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)}else this.remove();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.#h?.remove(),this.#h=null,this.#o&&(clearTimeout(this.#o),this.#o=null)),super.remove()}rebuild(){this.parent?(super.rebuild(),this.div!==null&&(this.#e&&this.#h===null&&this.#p(),this.isAttachedToDOM||this.parent.add(this))):this.#e&&this.#p()}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.#p(),this.width&&!this.annotationElementId){let[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(){this.parent&&(this.#o!==null&&clearTimeout(this.#o),this.#o=setTimeout((()=>{this.#o=null,this.#m()}),200))}#a(){let{div:t}=this,{width:e,height:s}=this.#t,[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){let l=Math.min(r*i/e,r*n/s);e*=l,s*=l}let[a,o]=this.parentDimensions;this.setDims(e*a/i,s*o/n),this._uiManager.enableWaiting(!1);let h=this.#h=document.createElement("canvas");h.setAttribute("role","img"),this.addContainer(h),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.#l||(this.parent.addUndoableEditor(this),this.#l=!0),this._reportTelemetry({action:"inserted_image"}),this.#n&&h.setAttribute("aria-label",this.#n)}copyCanvas(t,e,s=!1){t||(t=224);let{width:i,height:n}=this.#t,r=new Vt,a=this.#t,o=i,h=n,l=null;if(e){if(i>e||n>e){let x=Math.min(e/i,e/n);o=Math.floor(i*x),h=Math.floor(n*x)}l=document.createElement("canvas");let u=l.width=Math.ceil(o*r.sx),p=l.height=Math.ceil(h*r.sy);this.#c||(a=this.#g(u,p));let g=l.getContext("2d");g.filter=this._uiManager.hcmFilter;let f="white",m="#cfcfd8";this._uiManager.hcmFilter!=="none"?m="black":window.matchMedia?.("(prefers-color-scheme: dark)").matches&&(f="#8f8f9d",m="#42414d");let b=15,v=b*r.sx,A=b*r.sy,y=new OffscreenCanvas(2*v,2*A),w=y.getContext("2d");w.fillStyle=f,w.fillRect(0,0,2*v,2*A),w.fillStyle=m,w.fillRect(0,0,v,A),w.fillRect(v,A,v,A),g.fillStyle=g.createPattern(y,"repeat"),g.fillRect(0,0,u,p),g.drawImage(a,0,0,a.width,a.height,0,0,u,p)}let d=null;if(s){let u,p;if(r.symmetric&&a.width<t&&a.height<t)u=a.width,p=a.height;else if(a=this.#t,i>t||n>t){let f=Math.min(t/i,t/n);u=Math.floor(i*f),p=Math.floor(n*f),this.#c||(a=this.#g(u,p))}let g=new OffscreenCanvas(u,p).getContext("2d",{willReadFrequently:!0});g.drawImage(a,0,0,a.width,a.height,0,0,u,p),d={width:u,height:p,data:g.getImageData(0,0,u,p).data}}return{canvas:l,width:o,height:h,imageData:d}}#g(t,e){let{width:s,height:i}=this.#t,n=s,r=i,a=this.#t;for(;n>2*t||r>2*e;){let o=n,h=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));let l=new OffscreenCanvas(n,r);l.getContext("2d").drawImage(a,0,0,o,h,0,0,n,r),a=l.transferToImageBitmap()}return a}#m(){let[t,e]=this.parentDimensions,{width:s,height:i}=this,n=new Vt,r=Math.ceil(s*t*n.sx),a=Math.ceil(i*e*n.sy),o=this.#h;if(!o||o.width===r&&o.height===a)return;o.width=r,o.height=a;let h=this.#c?this.#t:this.#g(r,a),l=o.getContext("2d");l.filter=this._uiManager.hcmFilter,l.drawImage(h,0,0,h.width,h.height,0,0,r,a)}getImageForAltText(){return this.#h}#f(t){if(t){if(this.#c){let s=this._uiManager.imageManager.getSvgUrl(this.#e);if(s)return s}let 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){let[e,s]=this.pageDimensions,i=Math.round(this.width*e*At.PDF_TO_CSS_UNITS),n=Math.round(this.height*s*At.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 Le){let{data:{rect:g,rotation:f,id:m,structParent:b,popupRef:v},container:A,parent:{page:{pageNumber:y}}}=t,w=A.querySelector("canvas"),x=s.imageManager.getFromCanvas(A.id,w);w.remove();let _=(await e._structTree.getAriaAttributes(`${yi}${m}`))?.get("aria-label")||"";i=t={annotationType:L.STAMP,bitmapId:x.id,bitmap:x.bitmap,pageIndex:y-1,rect:g.slice(0),rotation:f,id:m,deleted:!1,accessibilityData:{decorative:!1,altText:_},isSvg:!1,structParent:b,popupRef:v}}let n=await super.deserialize(t,e,s),{rect:r,bitmap:a,bitmapUrl:o,bitmapId:h,isSvg:l,accessibilityData:d}=t;h&&s.imageManager.isValidId(h)?(n.#e=h,a&&(n.#t=a)):n.#i=o,n.#c=l;let[u,p]=n.pageDimensions;return n.width=(r[2]-r[0])/u,n.height=(r[3]-r[1])/p,n.annotationElementId=t.id||null,d&&(n.altTextData=d),n._initialData=i,n.#l=!!i,n}serialize(t=!1,e=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let 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.#f(!0),s.accessibilityData=this.serializeAltText(!0),s;let{decorative:i,altText:n}=this.serializeAltText(!1);if(!i&&n&&(s.accessibilityData={type:"Figure",alt:n}),this.annotationElementId){let 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;let r=this.#c?(s.rect[2]-s.rect[0])*(s.rect[3]-s.rect[1]):null;if(e.stamps.has(this.#e)){if(this.#c){let a=e.stamps.get(this.#e);r>a.area&&(a.area=r,a.serialized.bitmap.close(),a.serialized.bitmap=this.#f(!1))}}else e.stamps.set(this.#e,{area:r,serialized:s}),s.bitmap=this.#f(!1);return s}#b(t){let{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}},bi=class c{#t;#e=!1;#s=null;#i=null;#r=null;#n=new Map;#h=!1;#o=!1;#c=!1;#l=null;#u=null;#d=null;#p=null;#a;static _initialized=!1;static#g=new Map([hi,fi,mi,Oe].map((t=>[t._editorType,t])));constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:a,textLayer:o,viewport:h,l10n:l}){let d=[...c.#g.values()];if(!c._initialized){c._initialized=!0;for(let u of d)u.initialize(l,t)}t.registerEditorTypes(d),this.#a=t,this.pageIndex=e,this.div=s,this.#t=n,this.#s=r,this.viewport=h,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.#v(),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);let{classList:e}=this.div;for(let s of c.#g.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);let t=new Set;for(let 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}let e=this.#s.getEditableAnnotations();for(let s of e){if(s.hide(),this.#a.isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;let 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);let t=new Map,e=new Map;for(let i of this.#n.values())i.disableEditing(),i.annotationElementId&&(i.serialize()===null?(e.set(i.annotationElementId,i),this.getEditableAnnotation(i.annotationElementId)?.show(),i.remove()):t.set(i.annotationElementId,i));if(this.#s){let i=this.#s.getEditableAnnotations();for(let n of i){let{id:r}=n.data;if(this.#a.isDeletedAnnotationElement(r))continue;let a=e.get(r);a?(a.resetAnnotationElement(n),a.show(!1),n.show()):(a=t.get(r),a&&(this.#a.addChangedExistingAnnotation(a),a.renderAnnotationElement(n)&&a.show(!1)),n.show())}}this.#v(),this.isEmpty&&(this.div.hidden=!0);let{classList:s}=this.div;for(let i of c.#g.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.#p){this.#p=new AbortController;let t=this.#a.combinedSignal(this.#p);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.#p&&(this.#p.abort(),this.#p=null,this.#d.div.classList.remove("highlighting"))}#m(t){this.#a.unselectAll();let{target:e}=t;if(e===this.#d.div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&this.#d.div.contains(e)){let{isMac:s}=K.platform;if(t.button!==0||t.ctrlKey&&s)return;this.#a.showAllEditors("highlight",!0,!0),this.#d.div.classList.add("free"),this.toggleDrawing(),Oe.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;let t=this.#a.combinedSignal(this.#i);this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});let 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);let{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),U.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){let 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;let{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){this.addCommands({cmd:()=>t._uiManager.rebuild(t),undo:()=>{t.remove()},mustExec:!1})}getNextId(){return this.#a.getId()}get#f(){return c.#g.get(this.#a.getMode())}combinedSignal(t){return this.#a.combinedSignal(t)}#b(t){let e=this.#f;return e?new e.prototype.constructor(t):null}canCreateNewEmptyEditor(){return this.#f?.canCreateNewEmptyEditor()}pasteEditor(t,e){this.#a.updateToolbar(t),this.#a.updateMode(t);let{offsetX:s,offsetY:i}=this.#w(),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 c.#g.get(t.annotationType??t.annotationEditorType)?.deserialize(t,this,this.#a)||null}createAndAddNewEditor(t,e,s={}){let 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}#w(){let{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),a=(n+Math.min(window.innerWidth,t+s))/2-t,o=(r+Math.min(window.innerHeight,e+i))/2-e,[h,l]=this.viewport.rotation%180==0?[a,o]:[o,a];return{offsetX:h,offsetY:l}}addNewEditor(){this.createAndAddNewEditor(this.#w(),!0)}setSelected(t){this.#a.setSelected(t)}toggleSelected(t){this.#a.toggleSelected(t)}unselect(t){this.#a.unselect(t)}pointerup(t){let{isMac:e}=K.platform;!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&this.#h&&(this.#h=!1,this.#f?.isDrawer&&this.#f.supportMultipleDrawings||(this.#e?this.#a.getMode()!==L.STAMP?this.createAndAddNewEditor(t,!1):this.#a.unselectAll():this.#e=!0))}pointerdown(t){if(this.#a.getMode()===L.HIGHLIGHT&&this.enableTextSelection(),this.#h){this.#h=!1;return}let{isMac:e}=K.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(this.#h=!0,this.#f?.isDrawer){this.startDrawingSession(t);return}let s=this.#a.getActive();this.#e=!s||s.isEmpty()}startDrawingSession(t){if(this.div.focus(),this.#l){this.#f.startDrawing(this,this.#a,!1,t);return}this.#a.setCurrentDrawingSession(this),this.#l=new AbortController;let e=this.#a.combinedSignal(this.#l);this.div.addEventListener("blur",(({relatedTarget:s})=>{s&&!this.div.contains(s)&&(this.#u=null,this.commitOrRemove())}),{signal:e}),this.#f.startDrawing(this,this.#a,!1,t)}pause(t){if(t){let{activeElement:e}=document;this.div.contains(e)&&(this.#u=e)}else this.#u&&setTimeout((()=>{this.#u?.focus(),this.#u=null}),0)}endDrawingSession(t=!1){return this.#l?(this.#a.setCurrentDrawingSession(null),this.#l.abort(),this.#l=null,this.#u=null,this.#f.endDrawing(t)):null}findNewParent(t,e,s){let i=this.#a.findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return this.#l?(this.endDrawingSession(),!0):!1}onScaleChanging(){this.#l&&this.#f.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(let 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)}#v(){for(let t of this.#n.values())t.isEmpty()&&t.remove()}render({viewport:t}){this.viewport=t,Et(this.div,t);for(let e of this.#a.getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){this.#a.commitOrRemove(),this.#v();let e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,Et(this.div,{rotation:s}),e!==s)for(let i of this.#n.values())i.rotate(s)}get pageDimensions(){let{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return this.#a.viewParameters.realScale}},vi=class c{#t=null;#e=0;#s=new Map;#i=new Map;constructor({pageIndex:t}){this.pageIndex=t}setParent(t){if(this.#t){if(this.#t!==t){if(this.#s.size>0)for(let e of this.#s.values())e.remove(),t.append(e);this.#t=t}}else this.#t=t}static get _svgFactory(){return N(this,"_svgFactory",new Xt)}static#r(t,[e,s,i,n]){let{style:r}=t;r.top=100*s+"%",r.left=100*e+"%",r.width=100*i+"%",r.height=100*n+"%"}#n(){let t=c._svgFactory.create(1,1,!0);return this.#t.append(t),t.setAttribute("aria-hidden",!0),t}#h(t,e){let s=c._svgFactory.createElement("clipPath");t.append(s);let i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");let n=c._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i}#o(t,e){for(let[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)}draw(t,e=!1,s=!1){let i=this.#e++,n=this.#n(),r=c._svgFactory.createElement("defs");n.append(r);let a=c._svgFactory.createElement("path");r.append(a);let o=`path_p${this.pageIndex}_${i}`;a.setAttribute("id",o),a.setAttribute("vector-effect","non-scaling-stroke"),e&&this.#i.set(i,a);let h=s?this.#h(r,o):null,l=c._svgFactory.createElement("use");return n.append(l),l.setAttribute("href",`#${o}`),this.updateProperties(n,t),this.#s.set(i,n),{id:i,clipPathId:`url(#${h})`}}drawOutline(t,e){let s=this.#e++,i=this.#n(),n=c._svgFactory.createElement("defs");i.append(n);let r=c._svgFactory.createElement("path");n.append(r);let a=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",a),r.setAttribute("vector-effect","non-scaling-stroke");let o;if(e){let d=c._svgFactory.createElement("mask");n.append(d),o=`mask_p${this.pageIndex}_${s}`,d.setAttribute("id",o),d.setAttribute("maskUnits","objectBoundingBox");let u=c._svgFactory.createElement("rect");d.append(u),u.setAttribute("width","1"),u.setAttribute("height","1"),u.setAttribute("fill","white");let p=c._svgFactory.createElement("use");d.append(p),p.setAttribute("href",`#${a}`),p.setAttribute("stroke","none"),p.setAttribute("fill","black"),p.setAttribute("fill-rule","nonzero"),p.classList.add("mask")}let h=c._svgFactory.createElement("use");i.append(h),h.setAttribute("href",`#${a}`),o&&h.setAttribute("mask",`url(#${o})`);let l=h.cloneNode();return i.append(l),h.classList.add("mainOutline"),l.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;let{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&&c.#r(a,i),n){let{classList:o}=a;for(let[h,l]of Object.entries(n))o.toggle(h,l)}if(r){let o=a.firstChild.firstChild;this.#o(o,r)}}}updateParent(t,e){if(e===this)return;let 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(let t of this.#s.values())t.remove();this.#s.clear(),this.#i.clear()}};globalThis.pdfjsTestingUtils={HighlightOutliner:Qt};var fr=R.AbortException,mr=R.AnnotationEditorLayer,br=R.AnnotationEditorParamsType,vr=R.AnnotationEditorType,Ar=R.AnnotationEditorUIManager,wr=R.AnnotationLayer,yr=R.AnnotationMode,_r=R.ColorPicker,xr=R.DOMSVGFactory,Sr=R.DrawLayer,Er=R.FeatureTest,Ji=R.GlobalWorkerOptions,Cr=R.ImageKind,Mr=R.InvalidPDFException,kr=R.MissingPDFException,Tr=R.OPS,Rr=R.OutputScale,Zi=R.PDFDataRangeTransport,Pr=R.PDFDateString,Ir=R.PDFWorker,Lr=R.PasswordResponses,Dr=R.PermissionFlag,Fr=R.PixelsPerInch,tn=R.RenderingCancelledException,Nr=R.TextLayer,Or=R.TouchManager,Br=R.UnexpectedResponseException,$r=R.Util,Hr=R.VerbosityLevel,zr=R.XfaLayer,jr=R.build,Vr=R.createValidAbsoluteUrl,Gr=R.fetchData,en=R.getDocument,Ur=R.getFilenameFromUrl,Wr=R.getPdfFilenameFromUrl,qr=R.getXfaPageViewport,Xr=R.isDataScheme,Yr=R.isPdfFile,Kr=R.noContextMenu,Qr=R.normalizeUnicode,Jr=R.setLayerDimensions,Zr=R.shadow,ta=R.stopEvent,ea=R.version;import{E as qe}from"./store-BsSRYN7v.js";var rr="4.2.6-ym.10",ar=window.__YM_PDFJS_BASE__||`https://cdn.jsdelivr.net/npm/@yuuichi/openlist-assets@${rr}/dist/assets/pdfjs/`,xi=ar;Ji.workerSrc=`${xi}pdf.worker.min.mjs`;var ra=1<<20,or=12<<20;function ct(c,t={},e=[]){let s=document.createElement(c);for(let[i,n]of Object.entries(t))i==="class"?s.className=n:i==="style"?Object.assign(s.style,n):i.startsWith("on")&&typeof n=="function"?s.addEventListener(i.slice(2),n):n!=null&&s.setAttribute(i,n);for(let i of[].concat(e))i!=null&&s.appendChild(typeof i=="string"?document.createTextNode(i):i);return s}function hr(){let c=ct("div",{class:"ym-pdfjs-viewer",style:{display:"flex","flex-direction":"column",width:"100%",height:"100%",minHeight:"60vh",background:"var(--chakra-colors-chakra-subtle-bg, #525659)"}}),t=ct("input",{type:"number",min:"1",value:"1",style:{width:"56px","text-align":"center"},"aria-label":"Page number"}),e=ct("span",{},["/ -"]),s=ct("span",{},["100%"]),i=ct("div",{style:{marginLeft:"auto",opacity:".75","font-size":"12px"}},[""]),n=ct("div",{style:{flex:"1",overflow:"auto",position:"relative",display:"flex","justify-content":"center",padding:"12px"}}),r=ct("canvas",{style:{"box-shadow":"0 2px 12px rgba(0,0,0,.4)",background:"#fff"}}),a=ct("div",{style:{display:"flex","align-items":"center",gap:"8px",padding:"6px 10px",background:"var(--chakra-colors-chakra-body-bg, #2d3748)",color:"var(--chakra-colors-chakra-body-text, #e2e8f0)","border-bottom":"1px solid rgba(128,128,128,.3)",position:"sticky",top:"0","z-index":"2"}},[o("\u2039","Previous page",()=>g(h.page-1)),t,e,o("\u203A","Next page",()=>g(h.page+1)),ct("span",{style:{width:"1px",height:"20px",background:"rgba(128,128,128,.4)"}}),o("\u2212","Zoom out",()=>f(h.scale/1.25)),s,o("+","Zoom in",()=>f(h.scale*1.25)),o("Fit","Fit width",()=>m()),i]);function o(w,x,_){return ct("button",{type:"button",title:x,"aria-label":x,onClick:_,style:{minWidth:"32px",height:"28px",padding:"0 8px",cursor:"pointer",border:"1px solid rgba(128,128,128,.4)","border-radius":"6px",background:"transparent",color:"inherit"}},[w])}c.appendChild(a),c.appendChild(n),n.appendChild(r);let h={doc:null,page:1,scale:1.2,numPages:0,renderTask:null,pendingPage:null,fit:!0,bytes:0,destroyed:!1};function l(w){i.textContent=w}function d(w,x){let _=new Map,E=new Zi(x,new Uint8Array(0)),M=async(T,P)=>{let O=`${T}-${P}`;if(_.has(O))return _.get(O);let $=(async()=>{let F;for(let j=0;j<3;j++)try{let V=await fetch(w,{headers:{Range:`bytes=${T}-${P-1}`},credentials:"omit",referrerPolicy:"no-referrer",redirect:"follow"});if(V.status!==206)throw new Error(`Range HTTP ${V.status}`);let k=new Uint8Array(await V.arrayBuffer());h.destroyed||(h.bytes+=k.byteLength,l(`${(h.bytes/1048576).toFixed(1)} MB loaded`)),E.onDataRange(T,k);return}catch(V){F=V,await new Promise(k=>setTimeout(k,300*(j+1)))}throw F})();return _.set(O,$),$.finally(()=>_.delete(O)),$};return E.requestRange=(T,P)=>{M(T,P)},E.requestDataRange=E.requestRange,E}async function u(){try{let w=qe&&qe.raw_url;if(!w){l("No source URL");return}let x=new URL(w,location.href).href;l("Connecting\u2026");let _=Number(qe&&qe.size)||0,E={isEvalSupported:!1,disableAutoFetch:!0,disableStream:!0,cMapUrl:`${xi}cmaps/`,cMapPacked:!0,standardFontDataUrl:`${xi}standard_fonts/`};_>0?E.range=d(x,_):E.url=x;let M=en(E);h.doc=await M.promise,h.numPages=h.doc.numPages,e.textContent=`/ ${h.numPages}`,t.max=String(h.numPages),await p(1)}catch(w){console.error("[ym-pdfjs]",w),l(`Failed to load PDF: ${w&&w.message?w.message:w}`)}}async function p(w,{rebuildScale:x=!1}={}){if(!h.doc)return;w=Math.min(Math.max(1,w|0),h.numPages),h.page=w,t.value=String(w);let _=await h.doc.getPage(w),E=_.getViewport({scale:1});if(h.fit||x){let F=(n.clientWidth-32)/E.width;h.scale=Math.max(.4,Math.min(4,F)),h.fit=!0}let M=Math.min(window.devicePixelRatio||1,2),T=_.getViewport({scale:h.scale*M});if(r.width=Math.floor(T.width),r.height=Math.floor(T.height),r.style.width=`${Math.floor(T.width/M)}px`,r.style.height=`${Math.floor(T.height/M)}px`,s.textContent=`${Math.round(h.scale*100)}%`,h.renderTask)try{h.renderTask.cancel()}catch{}let P=r.getContext("2d"),O=_.render({canvasContext:P,viewport:T});h.renderTask=O;try{l(`Page ${w}/${h.numPages} \xB7 ${(h.bytes/1048576).toFixed(1)} MB loaded`),await O.promise,h.bytes<or&&h.doc.getPage(Math.min(h.numPages,w+1)).catch(()=>{})}catch($){if(!($ instanceof tn))throw $}}function g(w){p(w)}function f(w){h.fit=!1,h.scale=Math.max(.4,Math.min(6,w)),p(h.page)}function m(){h.fit=!0,p(h.page,{rebuildScale:!0})}t.addEventListener("change",()=>g(Number(t.value)||1)),t.addEventListener("keydown",w=>{w.key==="Enter"&&g(Number(t.value)||1)}),n.addEventListener("wheel",w=>{(w.ctrlKey||w.metaKey)&&(w.preventDefault(),f(h.scale*(w.deltaY<0?1.1:1/1.1)))},{passive:!1});let b,v=()=>{clearTimeout(b),b=setTimeout(()=>{h.fit&&p(h.page,{rebuildScale:!0})},150)};window.addEventListener("resize",v);let A=new MutationObserver(()=>{c.isConnected||y()});A.observe(document.body,{childList:!0,subtree:!0});function y(){if(!h.destroyed){h.destroyed=!0,A.disconnect(),window.removeEventListener("resize",v);try{h.renderTask?.cancel()}catch{}h.doc?.destroy().catch(()=>{})}}return u(),c}var aa=hr;export{aa as default};
12
+ `)){let r=document.createElement("div");r.append(n?document.createTextNode(n):document.createElement("br")),e.append(r)}let i=c._internalPadding*this.parentScale;return t.updateEdited({rect:this.getRect(i,i),popupContent:this.#e}),e}resetAnnotationElement(t){super.resetAnnotationElement(t),t.resetEdited()}},S=class{static PRECISION=1e-4;toSVGPath(){z("Abstract method `toSVGPath` must be implemented.")}get box(){z("Abstract getter `box` must be implemented.")}serialize(t,e){z("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(1e4*t)}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]}},De=class c{#t;#e=[];#s;#i;#r=[];#n=new Float32Array(18);#h;#o;#c;#l;#u;#d;#p=[];static#a=8;static#g=2;static#m=c.#a+c.#g;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.#l=c.#a*i,this.#c=c.#m*i,this.#u=i,this.#p.push(t,e)}isEmpty(){return isNaN(this.#n[8])}#f(){let t=this.#n.subarray(4,6),e=this.#n.subarray(16,18),[s,i,n,r]=this.#t;return[(this.#h+(t[0]-e[0])/2-s)/n,(this.#o+(t[1]-e[1])/2-i)/r,(this.#h+(e[0]-t[0])/2-s)/n,(this.#o+(e[1]-t[1])/2-i)/r]}add({x:t,y:e}){this.#h=t,this.#o=e;let[s,i,n,r]=this.#t,[a,o,h,l]=this.#n.subarray(8,12),d=t-h,u=e-l,p=Math.hypot(d,u);if(p<this.#c)return!1;let g=p-this.#l,f=g/p,m=f*d,b=f*u,v=a,A=o;a=h,o=l,h+=m,l+=b,this.#p?.push(t,e);let y=m/g,w=-b/g*this.#d,x=y*this.#d;return this.#n.set(this.#n.subarray(2,8),0),this.#n.set([h+w,l+x],4),this.#n.set(this.#n.subarray(14,18),12),this.#n.set([h-w,l-x],16),isNaN(this.#n[6])?(this.#r.length===0&&(this.#n.set([a+w,o+x],2),this.#r.push(NaN,NaN,NaN,NaN,(a+w-s)/n,(o+x-i)/r),this.#n.set([a-w,o-x],14),this.#e.push(NaN,NaN,NaN,NaN,(a-w-s)/n,(o-x-i)/r)),this.#n.set([v,A,a,o,h,l],6),!this.isEmpty()):(this.#n.set([v,A,a,o,h,l],6),Math.abs(Math.atan2(A-o,v-a)-Math.atan2(b,m))<Math.PI/2?([a,o,h,l]=this.#n.subarray(2,6),this.#r.push(NaN,NaN,NaN,NaN,((a+h)/2-s)/n,((o+l)/2-i)/r),[a,o,v,A]=this.#n.subarray(14,18),this.#e.push(NaN,NaN,NaN,NaN,((v+a)/2-s)/n,((A+o)/2-i)/r),!0):([v,A,a,o,h,l]=this.#n.subarray(0,6),this.#r.push(((v+5*a)/6-s)/n,((A+5*o)/6-i)/r,((5*a+h)/6-s)/n,((5*o+l)/6-i)/r,((a+h)/2-s)/n,((o+l)/2-i)/r),[h,l,a,o,v,A]=this.#n.subarray(12,18),this.#e.push(((v+5*a)/6-s)/n,((A+5*o)/6-i)/r,((5*a+h)/6-s)/n,((5*o+l)/6-i)/r,((a+h)/2-s)/n,((o+l)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";let t=this.#r,e=this.#e;if(isNaN(this.#n[6])&&!this.isEmpty())return this.#b();let 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.#v(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.#w(s),s.join(" ")}#b(){let[t,e,s,i]=this.#t,[n,r,a,o]=this.#f();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`}#w(t){let e=this.#e;t.push(`L${e[4]} ${e[5]} Z`)}#v(t){let[e,s,i,n]=this.#t,r=this.#n.subarray(4,6),a=this.#n.subarray(16,18),[o,h,l,d]=this.#f();t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${o} ${h} L${l} ${d} L${(a[0]-e)/i} ${(a[1]-s)/n}`)}newFreeDrawOutline(t,e,s,i,n,r){return new Fe(t,e,s,i,n,r)}getOutlines(){let t=this.#r,e=this.#e,s=this.#n,[i,n,r,a]=this.#t,o=new Float32Array((this.#p?.length??0)+2);for(let d=0,u=o.length-2;d<u;d+=2)o[d]=(this.#p[d]-i)/r,o[d+1]=(this.#p[d+1]-n)/a;if(o[o.length-2]=(this.#h-i)/r,o[o.length-1]=(this.#o-n)/a,isNaN(s[6])&&!this.isEmpty())return this.#y(o);let h=new Float32Array(this.#r.length+24+this.#e.length),l=t.length;for(let d=0;d<l;d+=2)isNaN(t[d])?h[d]=h[d+1]=NaN:(h[d]=t[d],h[d+1]=t[d+1]);l=this.#E(h,l);for(let d=e.length-6;d>=6;d-=6)for(let u=0;u<6;u+=2)isNaN(e[d+u])?(h[l]=h[l+1]=NaN,l+=2):(h[l]=e[d+u],h[l+1]=e[d+u+1],l+=2);return this.#x(h,l),this.newFreeDrawOutline(h,o,this.#t,this.#u,this.#s,this.#i)}#y(t){let e=this.#n,[s,i,n,r]=this.#t,[a,o,h,l]=this.#f(),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,h,l,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)}#x(t,e){let s=this.#e;return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+6}#E(t,e){let s=this.#n.subarray(4,6),i=this.#n.subarray(16,18),[n,r,a,o]=this.#t,[h,l,d,u]=this.#f();return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/a,(s[1]-r)/o,NaN,NaN,NaN,NaN,h,l,NaN,NaN,NaN,NaN,d,u,NaN,NaN,NaN,NaN,(i[0]-n)/a,(i[1]-r)/o],e),e+24}},Fe=class extends S{#t;#e=new Float32Array(4);#s;#i;#r;#n;#h;constructor(t,e,s,i,n,r){super(),this.#h=t,this.#r=e,this.#t=s,this.#n=i,this.#s=n,this.#i=r,this.lastPoint=[NaN,NaN],this.#o(r);let[a,o,h,l]=this.#e;for(let d=0,u=t.length;d<u;d+=2)t[d]=(t[d]-a)/h,t[d+1]=(t[d+1]-o)/l;for(let d=0,u=e.length;d<u;d+=2)e[d]=(e[d]-a)/h,e[d+1]=(e[d+1]-o)/l}toSVGPath(){let t=[`M${this.#h[4]} ${this.#h[5]}`];for(let e=6,s=this.#h.length;e<s;e+=6)isNaN(this.#h[e])?t.push(`L${this.#h[e+4]} ${this.#h[e+5]}`):t.push(`C${this.#h[e]} ${this.#h[e+1]} ${this.#h[e+2]} ${this.#h[e+3]} ${this.#h[e+4]} ${this.#h[e+5]}`);return t.push("Z"),t.join(" ")}serialize([t,e,s,i],n){let r=s-t,a=i-e,o,h;switch(n){case 0:o=S._rescale(this.#h,t,i,r,-a),h=S._rescale(this.#r,t,i,r,-a);break;case 90:o=S._rescaleAndSwap(this.#h,t,e,r,a),h=S._rescaleAndSwap(this.#r,t,e,r,a);break;case 180:o=S._rescale(this.#h,s,e,-r,a),h=S._rescale(this.#r,s,e,-r,a);break;case 270:o=S._rescaleAndSwap(this.#h,s,i,-r,-a),h=S._rescaleAndSwap(this.#r,s,i,-r,-a)}return{outline:Array.from(o),points:[Array.from(h)]}}#o(t){let e=this.#h,s=e[4],i=e[5],n=s,r=i,a=s,o=i,h=s,l=i,d=t?Math.max:Math.min;for(let p=6,g=e.length;p<g;p+=6){if(isNaN(e[p]))n=Math.min(n,e[p+4]),r=Math.min(r,e[p+5]),a=Math.max(a,e[p+4]),o=Math.max(o,e[p+5]),l<e[p+5]?(h=e[p+4],l=e[p+5]):l===e[p+5]&&(h=d(h,e[p+4]));else{let f=C.bezierBoundingBox(s,i,...e.slice(p,p+6));n=Math.min(n,f[0]),r=Math.min(r,f[1]),a=Math.max(a,f[2]),o=Math.max(o,f[3]),l<f[3]?(h=f[2],l=f[3]):l===f[3]&&(h=d(h,f[2]))}s=e[p+4],i=e[p+5]}let 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=[h,l]}get box(){return this.#e}newOutliner(t,e,s,i,n,r=0){return new De(t,e,s,i,n,r)}getNewOutline(t,e){let[s,i,n,r]=this.#e,[a,o,h,l]=this.#t,d=n*h,u=r*l,p=s*h+a,g=i*l+o,f=this.newOutliner({x:this.#r[0]*d+p,y:this.#r[1]*u+g},this.#t,this.#n,t,this.#i,e??this.#s);for(let m=2;m<this.#r.length;m+=2)f.add({x:this.#r[m]*d+p,y:this.#r[m+1]*u+g});return f.getOutlines()}},Qt=class{#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,h=10**-4;for(let{x:m,y:b,width:v,height:A}of t){let y=Math.floor((m-e)/h)*h,w=Math.ceil((m+v+e)/h)*h,x=Math.floor((b-e)/h)*h,_=Math.ceil((b+A+e)/h)*h,E=[y,x,_,!0],M=[w,x,_,!1];this.#s.push(E,M),n=Math.min(n,y),r=Math.max(r,w),a=Math.min(a,x),o=Math.max(o,_)}let l=r-n+2*s,d=o-a+2*s,u=n-s,p=a-s,g=this.#s.at(i?-1:-2),f=[g[0],g[2]];for(let m of this.#s){let[b,v,A]=m;m[0]=(b-u)/l,m[1]=(v-p)/d,m[2]=(A-p)/d}this.#t=new Float32Array([u,p,l,d]),this.#e=f}getOutlines(){this.#s.sort(((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]));let t=[];for(let e of this.#s)e[3]?(t.push(...this.#c(e)),this.#h(e)):(this.#o(e),t.push(...this.#c(e)));return this.#r(t)}#r(t){let e=[],s=new Set;for(let r of t){let[a,o,h]=r;e.push([a,o,r],[a,h,r])}e.sort(((r,a)=>r[1]-a[1]||r[0]-a[0]));for(let r=0,a=e.length;r<a;r+=2){let o=e[r][2],h=e[r+1][2];o.push(h),h.push(o),s.add(o),s.add(h)}let i=[],n;for(;s.size>0;){let r=s.values().next().value,[a,o,h,l,d]=r;s.delete(r);let u=a,p=o;for(n=[a,h],i.push(n);;){let g;if(s.has(l))g=l;else{if(!s.has(d))break;g=d}s.delete(g),[a,o,h,l,d]=g,u!==a&&(n.push(u,p,a,p===o?o:h),u=a),p=p===o?h:o}n.push(u,p)}return new li(i,this.#t,this.#e)}#n(t){let e=this.#i,s=0,i=e.length-1;for(;s<=i;){let n=s+i>>1,r=e[n][0];if(r===t)return n;r<t?s=n+1:i=n-1}return i+1}#h([,t,e]){let s=this.#n(t);this.#i.splice(s,0,[t,e])}#o([,t,e]){let s=this.#n(t);for(let i=s;i<this.#i.length;i++){let[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--){let[n,r]=this.#i[i];if(n!==t)break;if(n===t&&r===e){this.#i.splice(i,1);return}}}#c(t){let[e,s,i]=t,n=[[e,s,i]],r=this.#n(i);for(let a=0;a<r;a++){let[o,h]=this.#i[a];for(let l=0,d=n.length;l<d;l++){let[,u,p]=n[l];if(!(h<=u||p<=o))if(u>=o)if(p>h)n[l][1]=h;else{if(d===1)return[];n.splice(l,1),l--,d--}else n[l][2]=o,p>h&&n.push([e,h,p])}}return n}},li=class extends S{#t;#e;constructor(t,e,s){super(),this.#e=t,this.#t=e,this.lastPoint=s}toSVGPath(){let t=[];for(let e of this.#e){let[s,i]=e;t.push(`M${s} ${i}`);for(let n=2;n<e.length;n+=2){let 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){let r=[],a=s-t,o=i-e;for(let h of this.#e){let l=new Array(h.length);for(let d=0;d<h.length;d+=2)l[d]=t+h[d]*a,l[d+1]=i-h[d+1]*o;r.push(l)}return r}get box(){return this.#t}get classNamesForOutlining(){return["highlightOutline"]}},Jt=class extends De{newFreeDrawOutline(t,e,s,i,n,r){return new ci(t,e,s,i,n,r)}},ci=class extends Fe{newOutliner(t,e,s,i,n,r=0){return new Jt(t,e,s,i,n,r)}},Ne=class c{#t=null;#e=null;#s;#i=null;#r=!1;#n=!1;#h=null;#o;#c=null;#l=null;#u;static#d=null;static get _keyboardManager(){return N(this,"_keyboardManager",new Ct([[["Escape","mac+Escape"],c.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],c.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],c.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],c.prototype._moveToPrevious],[["Home","mac+Home"],c.prototype._moveToBeginning],[["End","mac+End"],c.prototype._moveToEnd]]))}constructor({editor:t=null,uiManager:e=null}){t?(this.#n=!1,this.#u=B.HIGHLIGHT_COLOR,this.#h=t):(this.#n=!0,this.#u=B.HIGHLIGHT_DEFAULT_COLOR),this.#l=t?._uiManager||e,this.#o=this.#l._eventBus,this.#s=t?.color||this.#l?.highlightColors.values().next().value||"#FFFF98",c.#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(){let 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);let e=this.#l._signal;t.addEventListener("click",this.#m.bind(this),{signal:e}),t.addEventListener("keydown",this.#g.bind(this),{signal:e});let 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(){let t=this.#i=this.#p();return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}#p(){let t=document.createElement("div"),e=this.#l._signal;t.addEventListener("contextmenu",ot,{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(let[s,i]of this.#l.highlightColors){let n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",c.#d[s]);let 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.#g.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}let e=t.target.getAttribute("data-color");e&&this.#a(e,t)}_moveToNext(t){this.#b?t.target!==this.#t?t.target.nextSibling?.focus():this.#i.firstChild?.focus():this.#m(t)}_moveToPrevious(t){t.target!==this.#i?.firstChild&&t.target!==this.#t?(this.#b||this.#m(t),t.target.previousSibling?.focus()):this.#b&&this._hideDropdownFromKeyboard()}_moveToBeginning(t){this.#b?this.#i.firstChild?.focus():this.#m(t)}_moveToEnd(t){this.#b?this.#i.lastChild?.focus():this.#m(t)}#g(t){c._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.#f.bind(this),{signal:this.#l.combinedSignal(this.#c)})),this.#i){this.#i.classList.remove("hidden");return}let e=this.#i=this.#p();this.#t.append(e)}#f(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(){this.#n||(this.#b?(this.hideDropdown(),this.#t.focus({preventScroll:!0,focusVisible:this.#r})):this.#h?.unselect())}updateColor(t){if(this.#e&&(this.#e.style.backgroundColor=t),!this.#i)return;let e=this.#l.highlightColors.values();for(let 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}},Oe=class c extends U{#t=null;#e=0;#s;#i=null;#r=null;#n=null;#h=null;#o=0;#c=null;#l=null;#u=null;#d=!1;#p=null;#a;#g=null;#m="";#f;#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(){let t=c.prototype;return N(this,"_keyboardManager",new Ct([[["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||c._defaultColor,this.#f=t.thickness||c._defaultThickness,this.#a=t.opacity||c._defaultOpacity,this.#s=t.boxes||null,this.#b=t.methodOfCreation||"",this.#m=t.text||"",this._isDraggable=!1,t.highlightId>-1?(this.#d=!0,this.#v(t),this.#T()):this.#s&&(this.#t=t.anchorNode,this.#e=t.anchorOffset,this.#h=t.focusNode,this.#o=t.focusOffset,this.#w(),this.#T(),this.rotate(this.rotation))}get telemetryInitialData(){return{action:"added",type:this.#d?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:this.#f,methodOfCreation:this.#b}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(t){return{numberOfColors:t.get("color").size}}#w(){let t=new Qt(this.#s,.001);this.#l=t.getOutlines(),[this.x,this.y,this.width,this.height]=this.#l.box;let e=new Qt(this.#s,.0025,.001,this._uiManager.direction==="ltr");this.#n=e.getOutlines();let{lastPoint:s}=this.#n;this.#p=[(s[0]-this.x)/this.width,(s[1]-this.y)/this.height]}#v({highlightOutlines:t,highlightId:e,clipPathId:s}){if(this.#l=t,this.#n=t.getNewOutline(this.#f/2+1.5,.0025),e>=0)this.#u=e,this.#i=s,this.parent.drawLayer.finalizeDraw(e,{bbox:t.box,path:{d:t.toSVGPath()}}),this.#g=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#n.box,path:{d:this.#n.toSVGPath()}},!0);else if(this.parent){let h=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#u,{bbox:c.#_(this.#l.box,(h-this.rotation+360)%360),path:{d:t.toSVGPath()}}),this.parent.drawLayer.updateProperties(this.#g,{bbox:c.#_(this.#n.box,h),path:{d:this.#n.toSVGPath()}})}let[i,n,r,a]=t.box;switch(this.rotation){case 0:this.x=i,this.y=n,this.width=r,this.height=a;break;case 90:{let[h,l]=this.parentDimensions;this.x=n,this.y=1-i,this.width=r*l/h,this.height=a*h/l;break}case 180:this.x=1-i,this.y=1-n,this.width=r,this.height=a;break;case 270:{let[h,l]=this.parentDimensions;this.x=1-n,this.y=i,this.width=r*l/h,this.height=a*h/l;break}}let{lastPoint:o}=this.#n;this.#p=[(o[0]-i)/r,(o[1]-n)/a]}static initialize(t,e){U.initialize(t,e),c._defaultColor||=e.highlightColors?.values().next().value||"#fff066"}static updateDefaultParams(t,e){switch(t){case B.HIGHLIGHT_DEFAULT_COLOR:c._defaultColor=e;break;case B.HIGHLIGHT_THICKNESS:c._defaultThickness=e}}translateInPage(t,e){}get toolbarPosition(){return this.#p}updateParams(t,e){switch(t){case B.HIGHLIGHT_COLOR:this.#y(e);break;case B.HIGHLIGHT_THICKNESS:this.#x(e)}}static get defaultPropertiesToUpdate(){return[[B.HIGHLIGHT_DEFAULT_COLOR,c._defaultColor],[B.HIGHLIGHT_THICKNESS,c._defaultThickness]]}get propertiesToUpdate(){return[[B.HIGHLIGHT_COLOR,this.color||c._defaultColor],[B.HIGHLIGHT_THICKNESS,this.#f||c._defaultThickness],[B.HIGHLIGHT_FREE,this.#d]]}#y(t){let 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,c._defaultOpacity),undo:e.bind(this,s,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:B.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(t)},!0)}#x(t){let e=this.#f,s=i=>{this.#f=i,this.#E(i)};this.addCommands({cmd:s.bind(this,t),undo:s.bind(this,e),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:B.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:t},!0)}async addEditToolbar(){let t=await super.addEditToolbar();return t?(this._uiManager.highlightColors&&(this.#r=new Ne({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.#P())}getBaseTranslation(){return[0,0]}getRect(t,e){return super.getRect(t,e,this.#P())}onceAdded(t){this.annotationElementId||this.parent.addUndoableEditor(this),t&&this.div.focus()}remove(){this.#M(),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#T(),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){let e=!1;this.parent&&!t?this.#M():t&&(this.#T(t),e=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(t),this.show(this._isVisible),e&&this.select()}#E(t){if(!this.#d)return;this.#v({highlightOutlines:this.#l.getNewOutline(t/2)}),this.fixAndSetPosition();let[e,s]=this.parentDimensions;this.setDims(this.width*e,this.height*s)}#M(){this.#u!==null&&this.parent&&(this.parent.drawLayer.remove(this.#u),this.#u=null,this.parent.drawLayer.remove(this.#g),this.#g=null)}#T(t=this.parent){this.#u===null&&({id:this.#u,clipPathId:this.#i}=t.drawLayer.draw({bbox:this.#l.box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":this.#a},rootClass:{highlight:!0,free:this.#d},path:{d:this.#l.toSVGPath()}},!1,!0),this.#g=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){let{drawLayer:e}=this.parent,s;this.#d?(t=(t-this.rotation+360)%360,s=c.#_(this.#l.box,t)):s=c.#_([this.x,this.y,this.width,this.height],t),e.updateProperties(this.#u,{bbox:s,root:{"data-main-rotation":t}}),e.updateProperties(this.#g,{bbox:c.#_(this.#n.box,t),root:{"data-main-rotation":t}})}render(){if(this.div)return this.div;let 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.#k.bind(this),{signal:this._uiManager._signal});let e=this.#c=document.createElement("div");t.append(e),e.setAttribute("aria-hidden","true"),e.className="internal",e.style.clipPath=this.#i;let[s,i]=this.parentDimensions;return this.setDims(this.width*s,this.height*i),ce(this,this.#c,["pointerover","pointerleave"]),this.enableEditing(),t}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#g,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#g,{rootClass:{hovered:!1}})}#k(t){c._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)}}#C(t){if(!this.#t)return;let e=window.getSelection();t?e.setPosition(this.#t,this.#e):e.setPosition(this.#h,this.#o)}select(){super.select(),this.#g&&this.parent?.drawLayer.updateProperties(this.#g,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect(),this.#g&&(this.parent?.drawLayer.updateProperties(this.#g,{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.#g,{rootClass:{hidden:!t}}))}#P(){return this.#d?this.rotation:0}#D(){if(this.#d)return null;let[t,e]=this.pageDimensions,[s,i]=this.pageTranslation,n=this.#s,r=new Float32Array(8*n.length),a=0;for(let{x:o,y:h,width:l,height:d}of n){let u=o*t+s,p=(1-h)*e+i;r[a]=r[a+4]=u,r[a+1]=r[a+3]=p,r[a+2]=r[a+6]=u+l*t,r[a+5]=r[a+7]=p-d*e,a+=8}return r}#N(t){return this.#l.serialize(t,this.#P())}static startHighlighting(t,e,{target:s,x:i,y:n}){let{x:r,y:a,width:o,height:h}=s.getBoundingClientRect(),l=new AbortController,d=t.combinedSignal(l),u=p=>{l.abort(),this.#A(t,p)};window.addEventListener("blur",u,{signal:d}),window.addEventListener("pointerup",u,{signal:d}),window.addEventListener("pointerdown",it,{capture:!0,passive:!1,signal:d}),window.addEventListener("contextmenu",ot,{signal:d}),s.addEventListener("pointermove",this.#S.bind(this,t),{signal:d}),this._freeHighlight=new Jt({x:i,y:n},[r,a,o,h],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#S(t,e){this._freeHighlight.add(e)&&t.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#A(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 Ie){let{data:{quadPoints:g,rect:f,rotation:m,id:b,color:v,opacity:A,popupRef:y},parent:{page:{pageNumber:w}}}=t;i=t={annotationType:L.HIGHLIGHT,color:Array.from(v),opacity:A,quadPoints:g,boxes:null,pageIndex:w-1,rect:f.slice(0),rotation:m,id:b,deleted:!1,popupRef:y}}else if(t instanceof Kt){let{data:{inkLists:g,rect:f,rotation:m,id:b,color:v,borderStyle:{rawWidth:A},popupRef:y},parent:{page:{pageNumber:w}}}=t;i=t={annotationType:L.HIGHLIGHT,color:Array.from(v),thickness:A,inkLists:g,boxes:null,pageIndex:w-1,rect:f.slice(0),rotation:m,id:b,deleted:!1,popupRef:y}}let{color:n,quadPoints:r,inkLists:a,opacity:o}=t,h=await super.deserialize(t,e,s);h.color=C.makeHexColor(...n),h.#a=o||1,a&&(h.#f=t.thickness),h.annotationElementId=t.id||null,h._initialData=i;let[l,d]=h.pageDimensions,[u,p]=h.pageTranslation;if(r){let g=h.#s=[];for(let f=0;f<r.length;f+=8)g.push({x:(r[f]-u)/l,y:1-(r[f+1]-p)/d,width:(r[f+2]-r[f])/l,height:(r[f+1]-r[f+5])/d});h.#w(),h.#T(),h.rotate(h.rotation)}else if(a){h.#d=!0;let g=a[0],f={x:g[0]-u,y:d-(g[1]-p)},m=new Jt(f,[0,0,l,d],1,h.#f/2,!0,.001);for(let A=0,y=g.length;A<y;A+=2)f.x=g[A]-u,f.y=d-(g[A+1]-p),m.add(f);let{id:b,clipPathId:v}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:h.color,"fill-opacity":h._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:m.toSVGPath()}},!0,!0);h.#v({highlightOutlines:m.getOutlines(),highlightId:b,clipPathId:v}),h.#T()}return h}serialize(t=!1){if(this.isEmpty()||t)return null;if(this.deleted)return this.serializeDeleted();let e=this.getRect(0,0),s=U._colorManager.convert(this.color),i={annotationType:L.HIGHLIGHT,color:s,opacity:this.#a,thickness:this.#f,quadPoints:this.#D(),outlines:this.#N(e),pageIndex:this.pageIndex,rect:e,rotation:this.#P(),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!this.#L(i)?null:(i.id=this.annotationElementId,i)}#L(t){let{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}},di=class{#t=Object.create(null);updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(let[e,s]of Object.entries(t))this.updateProperty(e,s)}updateSVGProperty(t,e){this.#t[t]=e}toSVGProperties(){let t=this.#t;return this.#t=Object.create(null),{root:t}}reset(){this.#t=Object.create(null)}updateAll(t=this){this.updateProperties(t)}clone(){z("Not implemented")}},ui=class c extends U{#t=null;#e;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#s=null;static#i=null;static#r=null;static#n=NaN;static#h=null;static#o=null;static#c=NaN;static _INNER_MARGIN=3;constructor(t){super(t),this.#e=t.mustBeCommitted||!1,t.drawOutlines&&(this.#l(t),this.#p())}#l({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){let{id:s}=e.drawLayer.draw(c._mergeSVGProperties(this._drawingOptions.toSVGProperties(),t.defaultSVGProperties),!1,!1);return s}static _mergeSVGProperties(t,e){let s=new Set(Object.keys(t));for(let[i,n]of Object.entries(e))s.has(i)?Object.assign(t[i],n):t[i]=n;return t}static getDefaultDrawingOptions(t){z("Not implemented")}static get typesMap(){z("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(t,e){let s=this.typesMap.get(t);s&&this._defaultDrawingOptions.updateProperty(s,e),this._currentParent&&(c.#s.updateProperty(s,e),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(t,e){let s=this.constructor.typesMap.get(t);s&&this._updateProperty(t,s,e)}static get defaultPropertiesToUpdate(){let t=[],e=this._defaultDrawingOptions;for(let[s,i]of this.typesMap)t.push([s,e[i]]);return t}get propertiesToUpdate(){let t=[],{_drawingOptions:e}=this;for(let[s,i]of this.constructor.typesMap)t.push([s,e[i]]);return t}_updateProperty(t,e,s){let i=this._drawingOptions,n=i[e],r=a=>{i.updateProperty(e,a);let 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,c._mergeSVGProperties(this.#t.getPathResizingSVGProperties(this.#g()),{bbox:this.#f()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,c._mergeSVGProperties(this.#t.getPathResizedSVGProperties(this.#g()),{bbox:this.#f()}))}_onTranslating(t,e){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#f(t,e)})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,c._mergeSVGProperties(this.#t.getPathTranslatedSVGProperties(this.#g(),this.parentDimensions),{bbox:this.#f()}))}_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.#p(),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.#p(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())}#p(t=this.parent){(this._drawId===null||this.parent!==t)&&(this._drawId===null?(this._drawingOptions.updateAll(),this._drawId=this.#u(this.#t,t)):this.parent.drawLayer.updateParent(this._drawId,t.drawLayer))}#a([t,e,s,i]){let{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]}}#g(){let{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();let[e,s]=this.parentDimensions;this.setDims(this.width*e,this.height*s)}this._onResized()}#f(){let{x:t,y:e,width:s,height:i,rotation:n,parentRotation:r,parentDimensions:[a,o]}=this;switch((4*n+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,c._mergeSVGProperties({bbox:this.#f()},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;let t=super.render();t.classList.add("draw");let e=document.createElement("div");t.append(e),e.setAttribute("aria-hidden","true"),e.className="internal";let[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){z("Not implemented")}static startDrawing(t,e,s,i){let{target:n,offsetX:r,offsetY:a,pointerId:o,pointerType:h}=i;if(c.#h&&c.#h!==h)return;let{viewport:{rotation:l}}=t,{width:d,height:u}=n.getBoundingClientRect(),p=c.#i=new AbortController,g=t.combinedSignal(p);c.#n||=o,c.#h??=h,window.addEventListener("pointerup",(f=>{c.#n===f.pointerId?this._endDraw(f):c.#o?.delete(f.pointerId)}),{signal:g}),window.addEventListener("pointercancel",(f=>{c.#n===f.pointerId?this._currentParent.endDrawingSession():c.#o?.delete(f.pointerId)}),{signal:g}),window.addEventListener("pointerdown",(f=>{c.#h===f.pointerType&&((c.#o||=new Set).add(f.pointerId),c.#s.isCancellable()&&(c.#s.removeLastElement(),c.#s.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))}),{capture:!0,passive:!1,signal:g}),window.addEventListener("contextmenu",ot,{signal:g}),n.addEventListener("pointermove",this._drawMove.bind(this),{signal:g}),n.addEventListener("touchmove",(f=>{f.timeStamp===c.#c&&it(f)}),{signal:g}),t.toggleDrawing(),e._editorUndoBar?.hide(),c.#s?t.drawLayer.updateProperties(this._currentDrawId,c.#s.startNew(r,a,d,u,l)):(e.updateUIForDefaultProperties(this),c.#s=this.createDrawerInstance(r,a,d,u,l),c.#r=this.getDefaultDrawingOptions(),this._currentParent=t,{id:this._currentDrawId}=t.drawLayer.draw(this._mergeSVGProperties(c.#r.toSVGProperties(),c.#s.defaultSVGProperties),!0,!1))}static _drawMove(t){if(c.#c=-1,!c.#s)return;let{offsetX:e,offsetY:s,pointerId:i}=t;c.#n===i&&(c.#o?.size>=1?this._endDraw(t):(this._currentParent.drawLayer.updateProperties(this._currentDrawId,c.#s.add(e,s)),c.#c=t.timeStamp,it(t)))}static _cleanup(t){t&&(this._currentDrawId=-1,this._currentParent=null,c.#s=null,c.#r=null,c.#h=null,c.#c=NaN),c.#i&&(c.#i.abort(),c.#i=null,c.#n=NaN,c.#o=null)}static _endDraw(t){let e=this._currentParent;if(e)if(e.toggleDrawing(!0),this._cleanup(!1),t&&e.drawLayer.updateProperties(this._currentDrawId,c.#s.end(t.offsetX,t.offsetY)),this.supportMultipleDrawings){let s=c.#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:B.DRAW_STEP})}else this.endDrawing(!1)}static endDrawing(t){let e=this._currentParent;if(!e)return null;if(e.toggleDrawing(!0),e.cleanUndoStack(B.DRAW_STEP),!c.#s.isEmpty()){let{pageDimensions:[s,i],scale:n}=e,r=e.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:c.#s.getOutlines(s*n,i*n,n,this._INNER_MARGIN),drawingOptions:c.#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){z("Not implemented")}static async deserialize(t,e,s){let{rawDims:{pageWidth:i,pageHeight:n,pageX:r,pageY:a}}=e.viewport,o=this.deserializeDraw(r,a,i,n,this._INNER_MARGIN,t),h=await super.deserialize(t,e,s);return h.createDrawingOptions(t),h.#l({drawOutlines:o}),h.#p(),h.onScaleChanging(),h.rotate(),h}serializeDraw(t){let[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}},pi=class{#t=new Float64Array(6);#e;#s;#i;#r;#n;#h="";#o=0;#c=new Be;#l;#u;constructor(t,e,s,i,n,r){this.#l=s,this.#u=i,this.#i=n,this.#r=r,[t,e]=this.#d(t,e);let 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 S._normalizePoint(t,e,this.#l,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);let[s,i,n,r]=this.#t.subarray(2,6),a=t-n,o=e-r;return Math.hypot(this.#l*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(...S.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){return this.add(t,e)||(this.#n.length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){this.#l=s,this.#u=i,this.#i=n,[t,e]=this.#d(t,e);let r=this.#e=[NaN,NaN,NaN,NaN,t,e];this.#n=[t,e];let 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.#h="";for(let t=0,e=this.#s.length;t<e;t++){let{line:s,points:i}=this.#s[t];this.#e=s,this.#n=i,this.#o=0,this.toSVGPath()}return{path:{d:this.#h}}}toSVGPath(){let t=S.svgRound(this.#e[4]),e=S.svgRound(this.#e[5]);if(this.#n.length===2)return this.#h=`${this.#h} M ${t} ${e} Z`,this.#h;if(this.#n.length<=6){let i=this.#h.lastIndexOf("M");this.#h=`${this.#h.slice(0,i)} M ${t} ${e}`,this.#o=6}if(this.#n.length===4){let i=S.svgRound(this.#e[10]),n=S.svgRound(this.#e[11]);return this.#h=`${this.#h} L ${i} ${n}`,this.#o=12,this.#h}let 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){let[r,a,o,h,l,d]=this.#e.slice(i,i+6).map(S.svgRound);s.push(`C${r} ${a} ${o} ${h} ${l} ${d}`)}return this.#h+=s.join(" "),this.#o=this.#e.length,this.#h}getOutlines(t,e,s,i){let 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.#h=null,this.#c}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}},Be=class c extends S{#t;#e=0;#s;#i;#r;#n;#h;#o;#c;build(t,e,s,i,n,r,a){this.#r=e,this.#n=s,this.#h=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(){let t=[];for(let{line:e}of this.#i)if(t.push(`M${S.svgRound(e[4])} ${S.svgRound(e[5])}`),e.length!==6)if(e.length!==12)for(let s=6,i=e.length;s<i;s+=6){let[n,r,a,o,h,l]=e.subarray(s,s+6).map(S.svgRound);t.push(`C${n} ${r} ${a} ${o} ${h} ${l}`)}else t.push(`L${S.svgRound(e[10])} ${S.svgRound(e[11])}`);else t.push("Z");return t.join("")}serialize([t,e,s,i],n){let r=[],a=[],[o,h,l,d]=this.#u(),u,p,g,f,m,b,v,A,y;switch(this.#o){case 0:y=S._rescale,u=t,p=e+i,g=s,f=-i,m=t+o*s,b=e+(1-h-d)*i,v=t+(o+l)*s,A=e+(1-h)*i;break;case 90:y=S._rescaleAndSwap,u=t,p=e,g=s,f=i,m=t+h*s,b=e+o*i,v=t+(h+d)*s,A=e+(o+l)*i;break;case 180:y=S._rescale,u=t+s,p=e,g=-s,f=i,m=t+(1-o-l)*s,b=e+h*i,v=t+(1-o)*s,A=e+(h+d)*i;break;case 270:y=S._rescaleAndSwap,u=t+s,p=e+i,g=-s,f=-i,m=t+(1-h-d)*s,b=e+(1-o-l)*i,v=t+(1-h)*s,A=e+(1-o)*i}for(let{line:w,points:x}of this.#i)r.push(y(w,u,p,g,f,n?new Array(w.length):null)),a.push(y(x,u,p,g,f,n?new Array(x.length):null));return{lines:r,points:a,rect:[m,b,v,A]}}static deserialize(t,e,s,i,n,{paths:{lines:r,points:a},rotation:o,thickness:h}){let l=[],d,u,p,g,f;switch(o){case 0:f=S._rescale,d=-t/s,u=e/i+1,p=1/s,g=-1/i;break;case 90:f=S._rescaleAndSwap,d=-e/i,u=-t/s,p=1/i,g=1/s;break;case 180:f=S._rescale,d=t/s+1,u=-e/i,p=-1/s,g=1/i;break;case 270:f=S._rescaleAndSwap,d=e/i+1,u=t/s+1,p=-1/i,g=-1/s}if(!r){r=[];for(let b of a){let v=b.length;if(v===2){r.push(new Float32Array([NaN,NaN,NaN,NaN,b[0],b[1]]));continue}if(v===4){r.push(new Float32Array([NaN,NaN,NaN,NaN,b[0],b[1],NaN,NaN,NaN,NaN,b[2],b[3]]));continue}let A=new Float32Array(3*(v-2));r.push(A);let[y,w,x,_]=b.subarray(0,4);A.set([NaN,NaN,NaN,NaN,y,w],0);for(let E=4;E<v;E+=2){let M=b[E],T=b[E+1];A.set(S.createBezierPoints(y,w,x,_,M,T),3*(E-2)),[y,w,x,_]=[x,_,M,T]}}}for(let b=0,v=r.length;b<v;b++)l.push({line:f(r[b].map((A=>A??NaN)),d,u,p,g),points:f(a[b].map((A=>A??NaN)),d,u,p,g)});let m=new c;return m.build(l,s,i,1,o,h,n),m}#l(t=this.#c){let e=this.#s+t/2*this.#h;return this.#o%180==0?[e/this.#r,e/this.#n]:[e/this.#n,e/this.#r]}#u(){let[t,e,s,i]=this.#t,[n,r]=this.#l(0);return[t+n,e+r,s-2*n,i-2*r]}#d(){let t=this.#t=new Float32Array([1/0,1/0,-1/0,-1/0]);for(let{line:i}of this.#i){if(i.length<=12){for(let a=4,o=i.length;a<o;a+=6){let[h,l]=i.subarray(a,a+2);t[0]=Math.min(t[0],h),t[1]=Math.min(t[1],l),t[2]=Math.max(t[2],h),t[3]=Math.max(t[3],l)}continue}let n=i[4],r=i[5];for(let a=6,o=i.length;a<o;a+=6){let[h,l,d,u,p,g]=i.subarray(a,a+6);C.bezierBoundingBox(n,r,h,l,d,u,p,g,t),n=p,r=g}}let[e,s]=this.#l();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.#p(e):null}#p(t){let[e,s]=this.#l();this.#c=t;let[i,n]=this.#l(),[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){let[i,n]=this.#l();this.#r=t,this.#n=e,this.#h=s;let[r,a]=this.#l(),o=r-i,h=a-n,l=this.#t;return l[0]-=o,l[1]-=h,l[2]+=2*o,l[3]+=2*h,l}updateRotation(t){return this.#e=t,{path:{transform:this.rotationTransform}}}get viewBox(){return this.#t.map(S.svgRound).join(" ")}get defaultProperties(){let[t,e]=this.#t;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${S.svgRound(t)} ${S.svgRound(e)}`}}}get rotationTransform(){let[,,t,e]=this.#t,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} ${S.svgRound(a)} ${S.svgRound(o)})`}getPathResizingSVGProperties([t,e,s,i]){let[n,r]=this.#l(),[a,o,h,l]=this.#t;if(Math.abs(h-n)<=S.PRECISION||Math.abs(l-r)<=S.PRECISION){let f=t+s/2-(a+h/2),m=e+i/2-(o+l/2);return{path:{"transform-origin":`${S.svgRound(t)} ${S.svgRound(e)}`,transform:`${this.rotationTransform} translate(${f} ${m})`}}}let d=(s-2*n)/(h-2*n),u=(i-2*r)/(l-2*r),p=h/s,g=l/i;return{path:{"transform-origin":`${S.svgRound(a)} ${S.svgRound(o)}`,transform:`${this.rotationTransform} scale(${p} ${g}) translate(${S.svgRound(n)} ${S.svgRound(r)}) scale(${d} ${u}) translate(${S.svgRound(-n)} ${S.svgRound(-r)})`}}}getPathResizedSVGProperties([t,e,s,i]){let[n,r]=this.#l(),a=this.#t,[o,h,l,d]=a;if(a[0]=t,a[1]=e,a[2]=s,a[3]=i,Math.abs(l-n)<=S.PRECISION||Math.abs(d-r)<=S.PRECISION){let m=t+s/2-(o+l/2),b=e+i/2-(h+d/2);for(let{line:v,points:A}of this.#i)S._translate(v,m,b,v),S._translate(A,m,b,A);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${S.svgRound(t)} ${S.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}let u=(s-2*n)/(l-2*n),p=(i-2*r)/(d-2*r),g=-u*(o+n)+t+n,f=-p*(h+r)+e+r;if(u!==1||p!==1||g!==0||f!==0)for(let{line:m,points:b}of this.#i)S._rescale(m,g,f,u,p,m),S._rescale(b,g,f,u,p,b);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${S.svgRound(t)} ${S.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([t,e],s){let[i,n]=s,r=this.#t,a=t-r[0],o=e-r[1];if(this.#r===i&&this.#n===n)for(let{line:h,points:l}of this.#i)S._translate(h,a,o,h),S._translate(l,a,o,l);else{let h=this.#r/i,l=this.#n/n;this.#r=i,this.#n=n;for(let{line:d,points:u}of this.#i)S._rescale(d,a,o,h,l,d),S._rescale(u,a,o,h,l,u);r[2]*=h,r[3]*=l}return r[0]=t,r[1]=e,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${S.svgRound(t)} ${S.svgRound(e)}`}}}get defaultSVGProperties(){let t=this.#t;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${S.svgRound(t[0])} ${S.svgRound(t[1])}`,transform:this.rotationTransform||null},bbox:t}}},gi=class c extends di{#t;constructor(t){super(),this.#t=t,super.updateProperties({fill:"none",stroke:U._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(){let t=new c(this.#t);return t.updateAll(this),t}},fi=class c extends ui{static _type="ink";static _editorType=L.INK;static _defaultDrawingOptions=null;constructor(t){super({...t,name:"inkEditor"}),this._willKeepAspectRatio=!0}static initialize(t,e){U.initialize(t,e),this._defaultDrawingOptions=new gi(e.viewParameters)}static getDefaultDrawingOptions(t){let e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!0}static get typesMap(){return N(this,"typesMap",new Map([[B.INK_THICKNESS,"stroke-width"],[B.INK_COLOR,"stroke"],[B.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(t,e,s,i,n){return new pi(t,e,s,i,n,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(t,e,s,i,n,r){return Be.deserialize(t,e,s,i,n,r)}static async deserialize(t,e,s){let i=null;if(t instanceof Kt){let{data:{inkLists:r,rect:a,rotation:o,id:h,color:l,opacity:d,borderStyle:{rawWidth:u},popupRef:p},parent:{page:{pageNumber:g}}}=t;i=t={annotationType:L.INK,color:Array.from(l),thickness:u,opacity:d,paths:{points:r},boxes:null,pageIndex:g-1,rect:a.slice(0),rotation:o,id:h,deleted:!1,popupRef:p}}let n=await super.deserialize(t,e,s);return n.annotationElementId=t.id||null,n._initialData=i,n}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();let{_drawId:t,_drawingOptions:e,parent:s}=this;e.updateSVGProperty("stroke-width"),s.drawLayer.updateProperties(t,e.toSVGProperties())}static onScaleChangingWhenDrawing(){let 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=c.getDefaultDrawingOptions({stroke:C.makeHexColor(...t),"stroke-width":e,"stroke-opacity":s})}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let{lines:e,points:s,rect:i}=this.serializeDraw(t),{_drawingOptions:{stroke:n,"stroke-opacity":r,"stroke-width":a}}=this,o={annotationType:L.INK,color:U._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){let{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){let{points:e,rect:s}=this.serializeDraw(!1);return t.updateEdited({rect:s,thickness:this._drawingOptions["stroke-width"],points:e}),null}},mi=class c extends U{#t=null;#e=null;#s=null;#i=null;#r=null;#n="";#h=null;#o=null;#c=!1;#l=!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){U.initialize(t,e)}static get supportedTypes(){return N(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map((t=>`image/${t}`)))}static get supportedTypesStr(){return N(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){let e=t.get("hasAltText");return{hasAltText:e.get(!0)??0,hasNoAltText:e.get(!1)??0}}#u(t,e=!1){t?(this.#t=t.bitmap,e||(this.#e=t.id,this.#c=t.isSvg),t.file&&(this.#n=t.file.name),this.#a()):this.remove()}#d(){if(this.#s=null,this._uiManager.enableWaiting(!1),this.#h)if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#t)this._editToolbar.hide(),this._uiManager.editAltText(this,!0);else{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;let{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.");let{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.");let o=a.output;return await this.setGuessedAltText(o),e&&!this.hasAltTextData()&&(this.altTextData={alt:o,decorative:!1}),o}#p(){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){let 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){let 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}let t=document.createElement("input");t.type="file",t.accept=c.supportedTypesStr;let e=this._uiManager._signal;this.#s=new Promise((s=>{t.addEventListener("change",(async()=>{if(t.files&&t.files.length!==0){this._uiManager.enableWaiting(!0);let 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)}else this.remove();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.#h?.remove(),this.#h=null,this.#o&&(clearTimeout(this.#o),this.#o=null)),super.remove()}rebuild(){this.parent?(super.rebuild(),this.div!==null&&(this.#e&&this.#h===null&&this.#p(),this.isAttachedToDOM||this.parent.add(this))):this.#e&&this.#p()}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.#p(),this.width&&!this.annotationElementId){let[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(){this.parent&&(this.#o!==null&&clearTimeout(this.#o),this.#o=setTimeout((()=>{this.#o=null,this.#m()}),200))}#a(){let{div:t}=this,{width:e,height:s}=this.#t,[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){let l=Math.min(r*i/e,r*n/s);e*=l,s*=l}let[a,o]=this.parentDimensions;this.setDims(e*a/i,s*o/n),this._uiManager.enableWaiting(!1);let h=this.#h=document.createElement("canvas");h.setAttribute("role","img"),this.addContainer(h),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.#l||(this.parent.addUndoableEditor(this),this.#l=!0),this._reportTelemetry({action:"inserted_image"}),this.#n&&h.setAttribute("aria-label",this.#n)}copyCanvas(t,e,s=!1){t||(t=224);let{width:i,height:n}=this.#t,r=new Vt,a=this.#t,o=i,h=n,l=null;if(e){if(i>e||n>e){let x=Math.min(e/i,e/n);o=Math.floor(i*x),h=Math.floor(n*x)}l=document.createElement("canvas");let u=l.width=Math.ceil(o*r.sx),p=l.height=Math.ceil(h*r.sy);this.#c||(a=this.#g(u,p));let g=l.getContext("2d");g.filter=this._uiManager.hcmFilter;let f="white",m="#cfcfd8";this._uiManager.hcmFilter!=="none"?m="black":window.matchMedia?.("(prefers-color-scheme: dark)").matches&&(f="#8f8f9d",m="#42414d");let b=15,v=b*r.sx,A=b*r.sy,y=new OffscreenCanvas(2*v,2*A),w=y.getContext("2d");w.fillStyle=f,w.fillRect(0,0,2*v,2*A),w.fillStyle=m,w.fillRect(0,0,v,A),w.fillRect(v,A,v,A),g.fillStyle=g.createPattern(y,"repeat"),g.fillRect(0,0,u,p),g.drawImage(a,0,0,a.width,a.height,0,0,u,p)}let d=null;if(s){let u,p;if(r.symmetric&&a.width<t&&a.height<t)u=a.width,p=a.height;else if(a=this.#t,i>t||n>t){let f=Math.min(t/i,t/n);u=Math.floor(i*f),p=Math.floor(n*f),this.#c||(a=this.#g(u,p))}let g=new OffscreenCanvas(u,p).getContext("2d",{willReadFrequently:!0});g.drawImage(a,0,0,a.width,a.height,0,0,u,p),d={width:u,height:p,data:g.getImageData(0,0,u,p).data}}return{canvas:l,width:o,height:h,imageData:d}}#g(t,e){let{width:s,height:i}=this.#t,n=s,r=i,a=this.#t;for(;n>2*t||r>2*e;){let o=n,h=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));let l=new OffscreenCanvas(n,r);l.getContext("2d").drawImage(a,0,0,o,h,0,0,n,r),a=l.transferToImageBitmap()}return a}#m(){let[t,e]=this.parentDimensions,{width:s,height:i}=this,n=new Vt,r=Math.ceil(s*t*n.sx),a=Math.ceil(i*e*n.sy),o=this.#h;if(!o||o.width===r&&o.height===a)return;o.width=r,o.height=a;let h=this.#c?this.#t:this.#g(r,a),l=o.getContext("2d");l.filter=this._uiManager.hcmFilter,l.drawImage(h,0,0,h.width,h.height,0,0,r,a)}getImageForAltText(){return this.#h}#f(t){if(t){if(this.#c){let s=this._uiManager.imageManager.getSvgUrl(this.#e);if(s)return s}let 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){let[e,s]=this.pageDimensions,i=Math.round(this.width*e*At.PDF_TO_CSS_UNITS),n=Math.round(this.height*s*At.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 Le){let{data:{rect:g,rotation:f,id:m,structParent:b,popupRef:v},container:A,parent:{page:{pageNumber:y}}}=t,w=A.querySelector("canvas"),x=s.imageManager.getFromCanvas(A.id,w);w.remove();let _=(await e._structTree.getAriaAttributes(`${yi}${m}`))?.get("aria-label")||"";i=t={annotationType:L.STAMP,bitmapId:x.id,bitmap:x.bitmap,pageIndex:y-1,rect:g.slice(0),rotation:f,id:m,deleted:!1,accessibilityData:{decorative:!1,altText:_},isSvg:!1,structParent:b,popupRef:v}}let n=await super.deserialize(t,e,s),{rect:r,bitmap:a,bitmapUrl:o,bitmapId:h,isSvg:l,accessibilityData:d}=t;h&&s.imageManager.isValidId(h)?(n.#e=h,a&&(n.#t=a)):n.#i=o,n.#c=l;let[u,p]=n.pageDimensions;return n.width=(r[2]-r[0])/u,n.height=(r[3]-r[1])/p,n.annotationElementId=t.id||null,d&&(n.altTextData=d),n._initialData=i,n.#l=!!i,n}serialize(t=!1,e=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let 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.#f(!0),s.accessibilityData=this.serializeAltText(!0),s;let{decorative:i,altText:n}=this.serializeAltText(!1);if(!i&&n&&(s.accessibilityData={type:"Figure",alt:n}),this.annotationElementId){let 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;let r=this.#c?(s.rect[2]-s.rect[0])*(s.rect[3]-s.rect[1]):null;if(e.stamps.has(this.#e)){if(this.#c){let a=e.stamps.get(this.#e);r>a.area&&(a.area=r,a.serialized.bitmap.close(),a.serialized.bitmap=this.#f(!1))}}else e.stamps.set(this.#e,{area:r,serialized:s}),s.bitmap=this.#f(!1);return s}#b(t){let{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}},bi=class c{#t;#e=!1;#s=null;#i=null;#r=null;#n=new Map;#h=!1;#o=!1;#c=!1;#l=null;#u=null;#d=null;#p=null;#a;static _initialized=!1;static#g=new Map([hi,fi,mi,Oe].map((t=>[t._editorType,t])));constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:a,textLayer:o,viewport:h,l10n:l}){let d=[...c.#g.values()];if(!c._initialized){c._initialized=!0;for(let u of d)u.initialize(l,t)}t.registerEditorTypes(d),this.#a=t,this.pageIndex=e,this.div=s,this.#t=n,this.#s=r,this.viewport=h,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.#v(),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);let{classList:e}=this.div;for(let s of c.#g.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);let t=new Set;for(let 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}let e=this.#s.getEditableAnnotations();for(let s of e){if(s.hide(),this.#a.isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;let 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);let t=new Map,e=new Map;for(let i of this.#n.values())i.disableEditing(),i.annotationElementId&&(i.serialize()===null?(e.set(i.annotationElementId,i),this.getEditableAnnotation(i.annotationElementId)?.show(),i.remove()):t.set(i.annotationElementId,i));if(this.#s){let i=this.#s.getEditableAnnotations();for(let n of i){let{id:r}=n.data;if(this.#a.isDeletedAnnotationElement(r))continue;let a=e.get(r);a?(a.resetAnnotationElement(n),a.show(!1),n.show()):(a=t.get(r),a&&(this.#a.addChangedExistingAnnotation(a),a.renderAnnotationElement(n)&&a.show(!1)),n.show())}}this.#v(),this.isEmpty&&(this.div.hidden=!0);let{classList:s}=this.div;for(let i of c.#g.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.#p){this.#p=new AbortController;let t=this.#a.combinedSignal(this.#p);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.#p&&(this.#p.abort(),this.#p=null,this.#d.div.classList.remove("highlighting"))}#m(t){this.#a.unselectAll();let{target:e}=t;if(e===this.#d.div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&this.#d.div.contains(e)){let{isMac:s}=K.platform;if(t.button!==0||t.ctrlKey&&s)return;this.#a.showAllEditors("highlight",!0,!0),this.#d.div.classList.add("free"),this.toggleDrawing(),Oe.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;let t=this.#a.combinedSignal(this.#i);this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});let 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);let{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),U.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){let 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;let{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){this.addCommands({cmd:()=>t._uiManager.rebuild(t),undo:()=>{t.remove()},mustExec:!1})}getNextId(){return this.#a.getId()}get#f(){return c.#g.get(this.#a.getMode())}combinedSignal(t){return this.#a.combinedSignal(t)}#b(t){let e=this.#f;return e?new e.prototype.constructor(t):null}canCreateNewEmptyEditor(){return this.#f?.canCreateNewEmptyEditor()}pasteEditor(t,e){this.#a.updateToolbar(t),this.#a.updateMode(t);let{offsetX:s,offsetY:i}=this.#w(),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 c.#g.get(t.annotationType??t.annotationEditorType)?.deserialize(t,this,this.#a)||null}createAndAddNewEditor(t,e,s={}){let 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}#w(){let{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),a=(n+Math.min(window.innerWidth,t+s))/2-t,o=(r+Math.min(window.innerHeight,e+i))/2-e,[h,l]=this.viewport.rotation%180==0?[a,o]:[o,a];return{offsetX:h,offsetY:l}}addNewEditor(){this.createAndAddNewEditor(this.#w(),!0)}setSelected(t){this.#a.setSelected(t)}toggleSelected(t){this.#a.toggleSelected(t)}unselect(t){this.#a.unselect(t)}pointerup(t){let{isMac:e}=K.platform;!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&this.#h&&(this.#h=!1,this.#f?.isDrawer&&this.#f.supportMultipleDrawings||(this.#e?this.#a.getMode()!==L.STAMP?this.createAndAddNewEditor(t,!1):this.#a.unselectAll():this.#e=!0))}pointerdown(t){if(this.#a.getMode()===L.HIGHLIGHT&&this.enableTextSelection(),this.#h){this.#h=!1;return}let{isMac:e}=K.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(this.#h=!0,this.#f?.isDrawer){this.startDrawingSession(t);return}let s=this.#a.getActive();this.#e=!s||s.isEmpty()}startDrawingSession(t){if(this.div.focus(),this.#l){this.#f.startDrawing(this,this.#a,!1,t);return}this.#a.setCurrentDrawingSession(this),this.#l=new AbortController;let e=this.#a.combinedSignal(this.#l);this.div.addEventListener("blur",(({relatedTarget:s})=>{s&&!this.div.contains(s)&&(this.#u=null,this.commitOrRemove())}),{signal:e}),this.#f.startDrawing(this,this.#a,!1,t)}pause(t){if(t){let{activeElement:e}=document;this.div.contains(e)&&(this.#u=e)}else this.#u&&setTimeout((()=>{this.#u?.focus(),this.#u=null}),0)}endDrawingSession(t=!1){return this.#l?(this.#a.setCurrentDrawingSession(null),this.#l.abort(),this.#l=null,this.#u=null,this.#f.endDrawing(t)):null}findNewParent(t,e,s){let i=this.#a.findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return this.#l?(this.endDrawingSession(),!0):!1}onScaleChanging(){this.#l&&this.#f.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(let 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)}#v(){for(let t of this.#n.values())t.isEmpty()&&t.remove()}render({viewport:t}){this.viewport=t,Et(this.div,t);for(let e of this.#a.getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){this.#a.commitOrRemove(),this.#v();let e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,Et(this.div,{rotation:s}),e!==s)for(let i of this.#n.values())i.rotate(s)}get pageDimensions(){let{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return this.#a.viewParameters.realScale}},vi=class c{#t=null;#e=0;#s=new Map;#i=new Map;constructor({pageIndex:t}){this.pageIndex=t}setParent(t){if(this.#t){if(this.#t!==t){if(this.#s.size>0)for(let e of this.#s.values())e.remove(),t.append(e);this.#t=t}}else this.#t=t}static get _svgFactory(){return N(this,"_svgFactory",new Xt)}static#r(t,[e,s,i,n]){let{style:r}=t;r.top=100*s+"%",r.left=100*e+"%",r.width=100*i+"%",r.height=100*n+"%"}#n(){let t=c._svgFactory.create(1,1,!0);return this.#t.append(t),t.setAttribute("aria-hidden",!0),t}#h(t,e){let s=c._svgFactory.createElement("clipPath");t.append(s);let i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");let n=c._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i}#o(t,e){for(let[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)}draw(t,e=!1,s=!1){let i=this.#e++,n=this.#n(),r=c._svgFactory.createElement("defs");n.append(r);let a=c._svgFactory.createElement("path");r.append(a);let o=`path_p${this.pageIndex}_${i}`;a.setAttribute("id",o),a.setAttribute("vector-effect","non-scaling-stroke"),e&&this.#i.set(i,a);let h=s?this.#h(r,o):null,l=c._svgFactory.createElement("use");return n.append(l),l.setAttribute("href",`#${o}`),this.updateProperties(n,t),this.#s.set(i,n),{id:i,clipPathId:`url(#${h})`}}drawOutline(t,e){let s=this.#e++,i=this.#n(),n=c._svgFactory.createElement("defs");i.append(n);let r=c._svgFactory.createElement("path");n.append(r);let a=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",a),r.setAttribute("vector-effect","non-scaling-stroke");let o;if(e){let d=c._svgFactory.createElement("mask");n.append(d),o=`mask_p${this.pageIndex}_${s}`,d.setAttribute("id",o),d.setAttribute("maskUnits","objectBoundingBox");let u=c._svgFactory.createElement("rect");d.append(u),u.setAttribute("width","1"),u.setAttribute("height","1"),u.setAttribute("fill","white");let p=c._svgFactory.createElement("use");d.append(p),p.setAttribute("href",`#${a}`),p.setAttribute("stroke","none"),p.setAttribute("fill","black"),p.setAttribute("fill-rule","nonzero"),p.classList.add("mask")}let h=c._svgFactory.createElement("use");i.append(h),h.setAttribute("href",`#${a}`),o&&h.setAttribute("mask",`url(#${o})`);let l=h.cloneNode();return i.append(l),h.classList.add("mainOutline"),l.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;let{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&&c.#r(a,i),n){let{classList:o}=a;for(let[h,l]of Object.entries(n))o.toggle(h,l)}if(r){let o=a.firstChild.firstChild;this.#o(o,r)}}}updateParent(t,e){if(e===this)return;let 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(let t of this.#s.values())t.remove();this.#s.clear(),this.#i.clear()}};globalThis.pdfjsTestingUtils={HighlightOutliner:Qt};var fr=R.AbortException,mr=R.AnnotationEditorLayer,br=R.AnnotationEditorParamsType,vr=R.AnnotationEditorType,Ar=R.AnnotationEditorUIManager,wr=R.AnnotationLayer,yr=R.AnnotationMode,_r=R.ColorPicker,xr=R.DOMSVGFactory,Sr=R.DrawLayer,Er=R.FeatureTest,Ji=R.GlobalWorkerOptions,Cr=R.ImageKind,Mr=R.InvalidPDFException,kr=R.MissingPDFException,Tr=R.OPS,Rr=R.OutputScale,Zi=R.PDFDataRangeTransport,Pr=R.PDFDateString,Ir=R.PDFWorker,Lr=R.PasswordResponses,Dr=R.PermissionFlag,Fr=R.PixelsPerInch,tn=R.RenderingCancelledException,Nr=R.TextLayer,Or=R.TouchManager,Br=R.UnexpectedResponseException,$r=R.Util,Hr=R.VerbosityLevel,zr=R.XfaLayer,jr=R.build,Vr=R.createValidAbsoluteUrl,Gr=R.fetchData,en=R.getDocument,Ur=R.getFilenameFromUrl,Wr=R.getPdfFilenameFromUrl,qr=R.getXfaPageViewport,Xr=R.isDataScheme,Yr=R.isPdfFile,Kr=R.noContextMenu,Qr=R.normalizeUnicode,Jr=R.setLayerDimensions,Zr=R.shadow,ta=R.stopEvent,ea=R.version;import{E as qe}from"./store-BsSRYN7v.js";var rr="4.2.6-ym.12",ar=window.__YM_PDFJS_BASE__||`https://cdn.jsdelivr.net/npm/@yuuichi/openlist-assets@${rr}/dist/assets/pdfjs/`,xi=ar;Ji.workerSrc=`${xi}pdf.worker.min.mjs`;var ra=1<<20,or=12<<20;function ct(c,t={},e=[]){let s=document.createElement(c);for(let[i,n]of Object.entries(t))i==="class"?s.className=n:i==="style"?Object.assign(s.style,n):i.startsWith("on")&&typeof n=="function"?s.addEventListener(i.slice(2),n):n!=null&&s.setAttribute(i,n);for(let i of[].concat(e))i!=null&&s.appendChild(typeof i=="string"?document.createTextNode(i):i);return s}function hr(){let c=ct("div",{class:"ym-pdfjs-viewer",style:{display:"flex","flex-direction":"column",width:"100%",height:"100%",minHeight:"60vh",background:"var(--chakra-colors-chakra-subtle-bg, #525659)"}}),t=ct("input",{type:"number",min:"1",value:"1",style:{width:"56px","text-align":"center"},"aria-label":"Page number"}),e=ct("span",{},["/ -"]),s=ct("span",{},["100%"]),i=ct("div",{style:{marginLeft:"auto",opacity:".75","font-size":"12px"}},[""]),n=ct("div",{style:{flex:"1",overflow:"auto",position:"relative",display:"flex","justify-content":"center",padding:"12px"}}),r=ct("canvas",{style:{"box-shadow":"0 2px 12px rgba(0,0,0,.4)",background:"#fff"}}),a=ct("div",{style:{display:"flex","align-items":"center",gap:"8px",padding:"6px 10px",background:"var(--chakra-colors-chakra-body-bg, #2d3748)",color:"var(--chakra-colors-chakra-body-text, #e2e8f0)","border-bottom":"1px solid rgba(128,128,128,.3)",position:"sticky",top:"0","z-index":"2"}},[o("\u2039","Previous page",()=>g(h.page-1)),t,e,o("\u203A","Next page",()=>g(h.page+1)),ct("span",{style:{width:"1px",height:"20px",background:"rgba(128,128,128,.4)"}}),o("\u2212","Zoom out",()=>f(h.scale/1.25)),s,o("+","Zoom in",()=>f(h.scale*1.25)),o("Fit","Fit width",()=>m()),i]);function o(w,x,_){return ct("button",{type:"button",title:x,"aria-label":x,onClick:_,style:{minWidth:"32px",height:"28px",padding:"0 8px",cursor:"pointer",border:"1px solid rgba(128,128,128,.4)","border-radius":"6px",background:"transparent",color:"inherit"}},[w])}c.appendChild(a),c.appendChild(n),n.appendChild(r);let h={doc:null,page:1,scale:1.2,numPages:0,renderTask:null,pendingPage:null,fit:!0,bytes:0,destroyed:!1};function l(w){i.textContent=w}function d(w,x){let _=new Map,E=new Zi(x,new Uint8Array(0)),M=async(T,P)=>{let O=`${T}-${P}`;if(_.has(O))return _.get(O);let $=(async()=>{let F;for(let j=0;j<3;j++)try{let V=await fetch(w,{headers:{Range:`bytes=${T}-${P-1}`},credentials:"omit",referrerPolicy:"no-referrer",redirect:"follow"});if(V.status!==206)throw new Error(`Range HTTP ${V.status}`);let k=new Uint8Array(await V.arrayBuffer());h.destroyed||(h.bytes+=k.byteLength,l(`${(h.bytes/1048576).toFixed(1)} MB loaded`)),E.onDataRange(T,k);return}catch(V){F=V,await new Promise(k=>setTimeout(k,300*(j+1)))}throw F})();return _.set(O,$),$.finally(()=>_.delete(O)),$};return E.requestRange=(T,P)=>{M(T,P)},E.requestDataRange=E.requestRange,E}async function u(){try{let w=qe&&qe.raw_url;if(!w){l("No source URL");return}let x=new URL(w,location.href).href;l("Connecting\u2026");let _=Number(qe&&qe.size)||0,E={isEvalSupported:!1,disableAutoFetch:!0,disableStream:!0,cMapUrl:`${xi}cmaps/`,cMapPacked:!0,standardFontDataUrl:`${xi}standard_fonts/`};_>0?E.range=d(x,_):E.url=x;let M=en(E);h.doc=await M.promise,h.numPages=h.doc.numPages,e.textContent=`/ ${h.numPages}`,t.max=String(h.numPages),await p(1)}catch(w){console.error("[ym-pdfjs]",w),l(`Failed to load PDF: ${w&&w.message?w.message:w}`)}}async function p(w,{rebuildScale:x=!1}={}){if(!h.doc)return;w=Math.min(Math.max(1,w|0),h.numPages),h.page=w,t.value=String(w);let _=await h.doc.getPage(w),E=_.getViewport({scale:1});if(h.fit||x){let F=(n.clientWidth-32)/E.width;h.scale=Math.max(.4,Math.min(4,F)),h.fit=!0}let M=Math.min(window.devicePixelRatio||1,2),T=_.getViewport({scale:h.scale*M});if(r.width=Math.floor(T.width),r.height=Math.floor(T.height),r.style.width=`${Math.floor(T.width/M)}px`,r.style.height=`${Math.floor(T.height/M)}px`,s.textContent=`${Math.round(h.scale*100)}%`,h.renderTask)try{h.renderTask.cancel()}catch{}let P=r.getContext("2d"),O=_.render({canvasContext:P,viewport:T});h.renderTask=O;try{l(`Page ${w}/${h.numPages} \xB7 ${(h.bytes/1048576).toFixed(1)} MB loaded`),await O.promise,h.bytes<or&&h.doc.getPage(Math.min(h.numPages,w+1)).catch(()=>{})}catch($){if(!($ instanceof tn))throw $}}function g(w){p(w)}function f(w){h.fit=!1,h.scale=Math.max(.4,Math.min(6,w)),p(h.page)}function m(){h.fit=!0,p(h.page,{rebuildScale:!0})}t.addEventListener("change",()=>g(Number(t.value)||1)),t.addEventListener("keydown",w=>{w.key==="Enter"&&g(Number(t.value)||1)}),n.addEventListener("wheel",w=>{(w.ctrlKey||w.metaKey)&&(w.preventDefault(),f(h.scale*(w.deltaY<0?1.1:1/1.1)))},{passive:!1});let b,v=()=>{clearTimeout(b),b=setTimeout(()=>{h.fit&&p(h.page,{rebuildScale:!0})},150)};window.addEventListener("resize",v);let A=new MutationObserver(()=>{c.isConnected||y()});A.observe(document.body,{childList:!0,subtree:!0});function y(){if(!h.destroyed){h.destroyed=!0,A.disconnect(),window.removeEventListener("resize",v);try{h.renderTask?.cancel()}catch{}h.doc?.destroy().catch(()=>{})}}return queueMicrotask(()=>{h.destroyed||u()}),c}var aa=hr;export{aa as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuuichi/openlist-assets",
3
- "version": "4.2.6-ym.10",
3
+ "version": "4.2.6-ym.12",
4
4
  "description": "Yuuichi OpenList patched frontend assets (mirrored via npmmirror for CN access)",
5
5
  "license": "MIT",
6
6
  "private": false,