@component-hook/pdf-canvas 1.3.1 → 1.3.2

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.
@@ -21990,32 +21990,32 @@ function Fg(a) {
21990
21990
  Fl() || (Mg.workerSrc = `https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${Og}/pdf.worker.min.mjs`);
21991
21991
  function Fl() {
21992
21992
  try {
21993
- return typeof OffscreenCanvas < "u" && typeof HTMLCanvasElement < "u" && typeof HTMLCanvasElement.prototype.transferControlToOffscreen == "function";
21993
+ return typeof OffscreenCanvas < "u" && typeof HTMLCanvasElement < "u" && typeof HTMLCanvasElement.prototype.transferControlToOffscreen == "function" && globalThis.self === window.top;
21994
21994
  } catch {
21995
21995
  return !1;
21996
21996
  }
21997
21997
  }
21998
21998
  async function Ig({ page: a, data: t, scale: e, password: s }, i) {
21999
- const n = Rg() / window.devicePixelRatio, r = await Fg(t);
21999
+ const n = Rg() / window.devicePixelRatio;
22000
22000
  if (Fl()) {
22001
- const o = new Worker(new URL(
22001
+ const r = new Worker(new URL(
22002
22002
  /* @vite-ignore */
22003
- "" + new URL("assets/pdfjs.worker-DawqtvLM.js", import.meta.url).href,
22003
+ "" + new URL("assets/pdfjs.worker-DuXj-zBo.js", import.meta.url).href,
22004
22004
  import.meta.url
22005
22005
  ), { type: "module" });
22006
- return o.postMessage({ data: r, password: s, id: i, page: a, units: n, scale: e }), await new Promise((l) => {
22007
- o.addEventListener("message", (c) => {
22008
- if (c.data.status !== "success") return;
22009
- const { bitmap: u, width: d, height: f, pages: g } = c.data;
22010
- if (u) {
22011
- const p = document.createElement("canvas"), b = p.getContext("bitmaprenderer");
22012
- p.width = d, p.height = f, b?.transferFromImageBitmap(u), l({ pages: g, canvas: p });
22006
+ return r.postMessage({ data: t, password: s, id: i, page: a, units: n, scale: e }), await new Promise((h) => {
22007
+ r.addEventListener("message", (l) => {
22008
+ if (l.data.status !== "success") return;
22009
+ const { bitmap: c, width: u, height: d, pages: f } = l.data;
22010
+ if (c) {
22011
+ const g = document.createElement("canvas"), p = g.getContext("bitmaprenderer");
22012
+ g.width = u, g.height = d, p?.transferFromImageBitmap(c), h({ pages: f, canvas: g });
22013
22013
  } else
22014
- l({ pages: g, canvas: null });
22014
+ h({ pages: f, canvas: null });
22015
22015
  });
22016
22016
  });
22017
22017
  } else {
22018
- const o = await Pg({ data: r, password: s }).promise, h = o.numPages;
22018
+ const r = await Fg(t), o = await Pg({ data: r, password: s }).promise, h = o.numPages;
22019
22019
  if (!i) return { canvas: null, pages: h };
22020
22020
  const l = await o.getPage(a), c = l.getViewport({ scale: e }), u = document.createElement("canvas"), f = {
22021
22021
  canvasContext: u.getContext("2d"),
@@ -512,4 +512,4 @@ void main() {
512
512
  `)}`,this.#d();const u=new Range;let d=l.reduce((f,g)=>f+g.length,0);for(const{firstChild:f}of this.editorDiv.childNodes)if(f.nodeType===Node.TEXT_NODE){const g=f.nodeValue.length;if(d<=g){u.setStart(f,d),u.setEnd(f,d);break}d-=g}n.removeAllRanges(),n.addRange(u)}#d(){if(this.editorDiv.replaceChildren(),!!this.#e)for(const t of this.#e.split(`
513
513
  `)){const e=document.createElement("div");e.append(t?document.createTextNode(t):document.createElement("br")),this.editorDiv.append(e)}}#u(){return this.#e.replaceAll(" "," ")}static#f(t){return t.replaceAll(" "," ")}get contentDiv(){return this.editorDiv}static async deserialize(t,e,s){let i=null;if(t instanceof El){const{data:{defaultAppearanceData:{fontSize:r,fontColor:o},rect:h,rotation:l,id:c,popupRef:u},textContent:d,textPosition:f,parent:{page:{pageNumber:g}}}=t;if(!d||d.length===0)return null;i=t={annotationType:U.FREETEXT,color:Array.from(o),fontSize:r,value:d.join(`
514
514
  `),position:f,pageIndex:g-1,rect:h.slice(0),rotation:l,id:c,deleted:!1,popupRef:u}}const n=await super.deserialize(t,e,s);return n.#r=t.fontSize,n.#t=B.makeHexColor(...t.color),n.#e=Ct.#f(t.value),n.annotationElementId=t.id||null,n._initialData=i,n}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const e=Ct._internalPadding*this.parentScale,s=this.getRect(e,e),i=H._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:this.#t),n={annotationType:U.FREETEXT,color:i,fontSize:this.#r,value:this.#u(),pageIndex:this.pageIndex,rect:s,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return t?n:this.annotationElementId&&!this.#o(n)?null:(n.id=this.annotationElementId,n)}#o(t){const{value:e,fontSize:s,color:i,pageIndex:n}=this._initialData;return this._hasBeenMoved||t.value!==e||t.fontSize!==s||t.color.some((r,o)=>r!==i[o])||t.pageIndex!==n}renderAnnotationElement(t){const e=super.renderAnnotationElement(t);if(this.deleted)return e;const{style:s}=e;s.fontSize=`calc(${this.#r}px * var(--scale-factor))`,s.color=this.#t,e.replaceChildren();for(const n of this.#e.split(`
515
- `)){const r=document.createElement("div");r.append(n?document.createTextNode(n):document.createElement("br")),e.append(r)}const i=Ct._internalPadding*this.parentScale;return t.updateEdited({rect:this.getRect(i,i),popupContent:this.#e}),e}resetAnnotationElement(t){super.resetAnnotationElement(t),t.resetEdited()}}class I{static PRECISION=1e-4;toSVGPath(){st("Abstract method `toSVGPath` must be implemented.")}get box(){st("Abstract getter `box` must be implemented.")}serialize(t,e){st("Abstract method `serialize` must be implemented.")}static _rescale(t,e,s,i,n,r){r||=new Float32Array(t.length);for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o]*i,r[o+1]=s+t[o+1]*n;return r}static _rescaleAndSwap(t,e,s,i,n,r){r||=new Float32Array(t.length);for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o+1]*i,r[o+1]=s+t[o]*n;return r}static _translate(t,e,s,i){i||=new Float32Array(t.length);for(let n=0,r=t.length;n<r;n+=2)i[n]=e+t[n],i[n+1]=s+t[n+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,s,i,n){switch(n){case 90:return[1-e/s,t/i];case 180:return[1-t/s,1-e/i];case 270:return[e/s,1-t/i];default:return[t/s,e/i]}}static _normalizePagePoint(t,e,s){switch(s){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,s,i,n,r){return[(t+5*s)/6,(e+5*i)/6,(5*s+n)/6,(5*i+r)/6,(s+n)/2,(i+r)/2]}}class ms{#t;#e=[];#s;#i;#r=[];#n=new Float32Array(18);#h;#a;#c;#l;#d;#u;#f=[];static#o=8;static#g=2;static#m=ms.#o+ms.#g;constructor({x:t,y:e},s,i,n,r,o=0){this.#t=s,this.#u=n*i,this.#i=r,this.#n.set([NaN,NaN,NaN,NaN,t,e],6),this.#s=o,this.#l=ms.#o*i,this.#c=ms.#m*i,this.#d=i,this.#f.push(t,e)}isEmpty(){return isNaN(this.#n[8])}#p(){const 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.#a+(t[1]-e[1])/2-i)/r,(this.#h+(e[0]-t[0])/2-s)/n,(this.#a+(e[1]-t[1])/2-i)/r]}add({x:t,y:e}){this.#h=t,this.#a=e;const[s,i,n,r]=this.#t;let[o,h,l,c]=this.#n.subarray(8,12);const u=t-l,d=e-c,f=Math.hypot(u,d);if(f<this.#c)return!1;const g=f-this.#l,p=g/f,b=p*u,m=p*d;let v=o,y=h;o=l,h=c,l+=b,c+=m,this.#f?.push(t,e);const _=-m/g,S=b/g,A=_*this.#u,T=S*this.#u;return this.#n.set(this.#n.subarray(2,8),0),this.#n.set([l+A,c+T],4),this.#n.set(this.#n.subarray(14,18),12),this.#n.set([l-A,c-T],16),isNaN(this.#n[6])?(this.#r.length===0&&(this.#n.set([o+A,h+T],2),this.#r.push(NaN,NaN,NaN,NaN,(o+A-s)/n,(h+T-i)/r),this.#n.set([o-A,h-T],14),this.#e.push(NaN,NaN,NaN,NaN,(o-A-s)/n,(h-T-i)/r)),this.#n.set([v,y,o,h,l,c],6),!this.isEmpty()):(this.#n.set([v,y,o,h,l,c],6),Math.abs(Math.atan2(y-h,v-o)-Math.atan2(m,b))<Math.PI/2?([o,h,l,c]=this.#n.subarray(2,6),this.#r.push(NaN,NaN,NaN,NaN,((o+l)/2-s)/n,((h+c)/2-i)/r),[o,h,v,y]=this.#n.subarray(14,18),this.#e.push(NaN,NaN,NaN,NaN,((v+o)/2-s)/n,((y+h)/2-i)/r),!0):([v,y,o,h,l,c]=this.#n.subarray(0,6),this.#r.push(((v+5*o)/6-s)/n,((y+5*h)/6-i)/r,((5*o+l)/6-s)/n,((5*h+c)/6-i)/r,((o+l)/2-s)/n,((h+c)/2-i)/r),[l,c,o,h,v,y]=this.#n.subarray(12,18),this.#e.push(((v+5*o)/6-s)/n,((y+5*h)/6-i)/r,((5*o+l)/6-s)/n,((5*h+c)/6-i)/r,((o+l)/2-s)/n,((h+c)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=this.#r,e=this.#e;if(isNaN(this.#n[6])&&!this.isEmpty())return this.#b();const s=[];s.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?s.push(`L${t[i+4]} ${t[i+5]}`):s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);this.#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.#_(s),s.join(" ")}#b(){const[t,e,s,i]=this.#t,[n,r,o,h]=this.#p();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${o} ${h} L${(this.#n[16]-t)/s} ${(this.#n[17]-e)/i} L${(this.#n[14]-t)/s} ${(this.#n[15]-e)/i} Z`}#_(t){const e=this.#e;t.push(`L${e[4]} ${e[5]} Z`)}#v(t){const[e,s,i,n]=this.#t,r=this.#n.subarray(4,6),o=this.#n.subarray(16,18),[h,l,c,u]=this.#p();t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${h} ${l} L${c} ${u} L${(o[0]-e)/i} ${(o[1]-s)/n}`)}newFreeDrawOutline(t,e,s,i,n,r){return new Ol(t,e,s,i,n,r)}getOutlines(){const t=this.#r,e=this.#e,s=this.#n,[i,n,r,o]=this.#t,h=new Float32Array((this.#f?.length??0)+2);for(let u=0,d=h.length-2;u<d;u+=2)h[u]=(this.#f[u]-i)/r,h[u+1]=(this.#f[u+1]-n)/o;if(h[h.length-2]=(this.#h-i)/r,h[h.length-1]=(this.#a-n)/o,isNaN(s[6])&&!this.isEmpty())return this.#w(h);const l=new Float32Array(this.#r.length+24+this.#e.length);let c=t.length;for(let u=0;u<c;u+=2){if(isNaN(t[u])){l[u]=l[u+1]=NaN;continue}l[u]=t[u],l[u+1]=t[u+1]}c=this.#A(l,c);for(let u=e.length-6;u>=6;u-=6)for(let d=0;d<6;d+=2){if(isNaN(e[u+d])){l[c]=l[c+1]=NaN,c+=2;continue}l[c]=e[u+d],l[c+1]=e[u+d+1],c+=2}return this.#S(l,c),this.newFreeDrawOutline(l,h,this.#t,this.#d,this.#s,this.#i)}#w(t){const e=this.#n,[s,i,n,r]=this.#t,[o,h,l,c]=this.#p(),u=new Float32Array(36);return u.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,o,h,NaN,NaN,NaN,NaN,l,c,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(u,t,this.#t,this.#d,this.#s,this.#i)}#S(t,e){const s=this.#e;return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6}#A(t,e){const s=this.#n.subarray(4,6),i=this.#n.subarray(16,18),[n,r,o,h]=this.#t,[l,c,u,d]=this.#p();return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/o,(s[1]-r)/h,NaN,NaN,NaN,NaN,l,c,NaN,NaN,NaN,NaN,u,d,NaN,NaN,NaN,NaN,(i[0]-n)/o,(i[1]-r)/h],e),e+=24}}class Ol extends I{#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.#a(r);const[o,h,l,c]=this.#e;for(let u=0,d=t.length;u<d;u+=2)t[u]=(t[u]-o)/l,t[u+1]=(t[u+1]-h)/c;for(let u=0,d=e.length;u<d;u+=2)e[u]=(e[u]-o)/l,e[u+1]=(e[u+1]-h)/c}toSVGPath(){const t=[`M${this.#h[4]} ${this.#h[5]}`];for(let e=6,s=this.#h.length;e<s;e+=6){if(isNaN(this.#h[e])){t.push(`L${this.#h[e+4]} ${this.#h[e+5]}`);continue}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){const r=s-t,o=i-e;let h,l;switch(n){case 0:h=I._rescale(this.#h,t,i,r,-o),l=I._rescale(this.#r,t,i,r,-o);break;case 90:h=I._rescaleAndSwap(this.#h,t,e,r,o),l=I._rescaleAndSwap(this.#r,t,e,r,o);break;case 180:h=I._rescale(this.#h,s,e,-r,o),l=I._rescale(this.#r,s,e,-r,o);break;case 270:h=I._rescaleAndSwap(this.#h,s,i,-r,-o),l=I._rescaleAndSwap(this.#r,s,i,-r,-o);break}return{outline:Array.from(h),points:[Array.from(l)]}}#a(t){const e=this.#h;let s=e[4],i=e[5],n=s,r=i,o=s,h=i,l=s,c=i;const u=t?Math.max:Math.min;for(let f=6,g=e.length;f<g;f+=6){if(isNaN(e[f]))n=Math.min(n,e[f+4]),r=Math.min(r,e[f+5]),o=Math.max(o,e[f+4]),h=Math.max(h,e[f+5]),c<e[f+5]?(l=e[f+4],c=e[f+5]):c===e[f+5]&&(l=u(l,e[f+4]));else{const p=B.bezierBoundingBox(s,i,...e.slice(f,f+6));n=Math.min(n,p[0]),r=Math.min(r,p[1]),o=Math.max(o,p[2]),h=Math.max(h,p[3]),c<p[3]?(l=p[2],c=p[3]):c===p[3]&&(l=u(l,p[2]))}s=e[f+4],i=e[f+5]}const d=this.#e;d[0]=n-this.#s,d[1]=r-this.#s,d[2]=o-n+2*this.#s,d[3]=h-r+2*this.#s,this.lastPoint=[l,c]}get box(){return this.#e}newOutliner(t,e,s,i,n,r=0){return new ms(t,e,s,i,n,r)}getNewOutline(t,e){const[s,i,n,r]=this.#e,[o,h,l,c]=this.#t,u=n*l,d=r*c,f=s*l+o,g=i*c+h,p=this.newOutliner({x:this.#r[0]*u+f,y:this.#r[1]*d+g},this.#t,this.#n,t,this.#i,e??this.#s);for(let b=2;b<this.#r.length;b+=2)p.add({x:this.#r[b]*u+f,y:this.#r[b+1]*d+g});return p.getOutlines()}}class xo{#t;#e;#s=[];#i=[];constructor(t,e=0,s=0,i=!0){let n=1/0,r=-1/0,o=1/0,h=-1/0;const l=10**-4;for(const{x:b,y:m,width:v,height:y}of t){const _=Math.floor((b-e)/l)*l,S=Math.ceil((b+v+e)/l)*l,A=Math.floor((m-e)/l)*l,T=Math.ceil((m+y+e)/l)*l,E=[_,A,T,!0],P=[S,A,T,!1];this.#s.push(E,P),n=Math.min(n,_),r=Math.max(r,S),o=Math.min(o,A),h=Math.max(h,T)}const c=r-n+2*s,u=h-o+2*s,d=n-s,f=o-s,g=this.#s.at(i?-1:-2),p=[g[0],g[2]];for(const b of this.#s){const[m,v,y]=b;b[0]=(m-d)/c,b[1]=(v-f)/u,b[2]=(y-f)/u}this.#t=new Float32Array([d,f,c,u]),this.#e=p}getOutlines(){this.#s.sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of this.#s)e[3]?(t.push(...this.#c(e)),this.#h(e)):(this.#a(e),t.push(...this.#c(e)));return this.#r(t)}#r(t){const e=[],s=new Set;for(const r of t){const[o,h,l]=r;e.push([o,h,r],[o,l,r])}e.sort((r,o)=>r[1]-o[1]||r[0]-o[0]);for(let r=0,o=e.length;r<o;r+=2){const h=e[r][2],l=e[r+1][2];h.push(l),l.push(h),s.add(h),s.add(l)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[o,h,l,c,u]=r;s.delete(r);let d=o,f=h;for(n=[o,l],i.push(n);;){let g;if(s.has(c))g=c;else if(s.has(u))g=u;else break;s.delete(g),[o,h,l,c,u]=g,d!==o&&(n.push(d,f,o,f===h?h:l),d=o),f=f===h?l:h}n.push(d,f)}return new bg(i,this.#t,this.#e)}#n(t){const e=this.#i;let s=0,i=e.length-1;for(;s<=i;){const n=s+i>>1,r=e[n][0];if(r===t)return n;r<t?s=n+1:i=n-1}return i+1}#h([,t,e]){const s=this.#n(t);this.#i.splice(s,0,[t,e])}#a([,t,e]){const s=this.#n(t);for(let i=s;i<this.#i.length;i++){const[n,r]=this.#i[i];if(n!==t)break;if(n===t&&r===e){this.#i.splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=this.#i[i];if(n!==t)break;if(n===t&&r===e){this.#i.splice(i,1);return}}}#c(t){const[e,s,i]=t,n=[[e,s,i]],r=this.#n(i);for(let o=0;o<r;o++){const[h,l]=this.#i[o];for(let c=0,u=n.length;c<u;c++){const[,d,f]=n[c];if(!(l<=d||f<=h)){if(d>=h){if(f>l)n[c][1]=l;else{if(u===1)return[];n.splice(c,1),c--,u--}continue}n[c][2]=h,f>l&&n.push([e,l,f])}}}return n}}class bg extends I{#t;#e;constructor(t,e,s){super(),this.#e=t,this.#t=e,this.lastPoint=s}toSVGPath(){const t=[];for(const e of this.#e){let[s,i]=e;t.push(`M${s} ${i}`);for(let n=2;n<e.length;n+=2){const r=e[n],o=e[n+1];r===s?(t.push(`V${o}`),i=o):o===i&&(t.push(`H${r}`),s=r)}t.push("Z")}return t.join(" ")}serialize([t,e,s,i],n){const r=[],o=s-t,h=i-e;for(const l of this.#e){const c=new Array(l.length);for(let u=0;u<l.length;u+=2)c[u]=t+l[u]*o,c[u+1]=i-l[u+1]*h;r.push(c)}return r}get box(){return this.#t}get classNamesForOutlining(){return["highlightOutline"]}}class So extends ms{newFreeDrawOutline(t,e,s,i,n,r){return new vg(t,e,s,i,n,r)}}class vg extends Ol{newOutliner(t,e,s,i,n,r=0){return new So(t,e,s,i,n,r)}}class ne{#t=null;#e=null;#s;#i=null;#r=!1;#n=!1;#h=null;#a;#c=null;#l=null;#d;static#u=null;static get _keyboardManager(){return $(this,"_keyboardManager",new pi([[["Escape","mac+Escape"],ne.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],ne.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],ne.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],ne.prototype._moveToPrevious],[["Home","mac+Home"],ne.prototype._moveToBeginning],[["End","mac+End"],ne.prototype._moveToEnd]]))}constructor({editor:t=null,uiManager:e=null}){t?(this.#n=!1,this.#d=q.HIGHLIGHT_COLOR,this.#h=t):(this.#n=!0,this.#d=q.HIGHLIGHT_DEFAULT_COLOR),this.#l=t?._uiManager||e,this.#a=this.#l._eventBus,this.#s=t?.color||this.#l?.highlightColors.values().next().value||"#FFFF98",ne.#u||=Object.freeze({blue:"pdfjs-editor-colorpicker-blue",green:"pdfjs-editor-colorpicker-green",pink:"pdfjs-editor-colorpicker-pink",red:"pdfjs-editor-colorpicker-red",yellow:"pdfjs-editor-colorpicker-yellow"})}renderButton(){const t=this.#t=document.createElement("button");t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);const e=this.#l._signal;t.addEventListener("click",this.#m.bind(this),{signal:e}),t.addEventListener("keydown",this.#g.bind(this),{signal:e});const s=this.#e=document.createElement("span");return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=this.#s,t.append(s),t}renderMainDropdown(){const t=this.#i=this.#f();return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}#f(){const t=document.createElement("div"),e=this.#l._signal;t.addEventListener("contextmenu",ge,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[s,i]of this.#l.highlightColors){const n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",ne.#u[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===this.#s),n.addEventListener("click",this.#o.bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",this.#g.bind(this),{signal:e}),t}#o(t,e){e.stopPropagation(),this.#a.dispatch("switchannotationeditorparams",{source:this,type:this.#d,value:t})}_colorSelectFromKeyboard(t){if(t.target===this.#t){this.#m(t);return}const e=t.target.getAttribute("data-color");e&&this.#o(e,t)}_moveToNext(t){if(!this.#b){this.#m(t);return}if(t.target===this.#t){this.#i.firstChild?.focus();return}t.target.nextSibling?.focus()}_moveToPrevious(t){if(t.target===this.#i?.firstChild||t.target===this.#t){this.#b&&this._hideDropdownFromKeyboard();return}this.#b||this.#m(t),t.target.previousSibling?.focus()}_moveToBeginning(t){if(!this.#b){this.#m(t);return}this.#i.firstChild?.focus()}_moveToEnd(t){if(!this.#b){this.#m(t);return}this.#i.lastChild?.focus()}#g(t){ne._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.#p.bind(this),{signal:this.#l.combinedSignal(this.#c)})),this.#i){this.#i.classList.remove("hidden");return}const e=this.#i=this.#f();this.#t.append(e)}#p(t){this.#i?.contains(t.target)||this.hideDropdown()}hideDropdown(){this.#i?.classList.add("hidden"),this.#c?.abort(),this.#c=null}get#b(){return this.#i&&!this.#i.classList.contains("hidden")}_hideDropdownFromKeyboard(){if(!this.#n){if(!this.#b){this.#h?.unselect();return}this.hideDropdown(),this.#t.focus({preventScroll:!0,focusVisible:this.#r})}}updateColor(t){if(this.#e&&(this.#e.style.backgroundColor=t),!this.#i)return;const e=this.#l.highlightColors.values();for(const s of this.#i.children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){this.#t?.remove(),this.#t=null,this.#e=null,this.#i?.remove(),this.#i=null}}class mt extends H{#t=null;#e=0;#s;#i=null;#r=null;#n=null;#h=null;#a=0;#c=null;#l=null;#d=null;#u=!1;#f=null;#o;#g=null;#m="";#p;#b="";static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type="highlight";static _editorType=U.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId="";static get _keyboardManager(){const t=mt.prototype;return $(this,"_keyboardManager",new pi([[["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||mt._defaultColor,this.#p=t.thickness||mt._defaultThickness,this.#o=t.opacity||mt._defaultOpacity,this.#s=t.boxes||null,this.#b=t.methodOfCreation||"",this.#m=t.text||"",this._isDraggable=!1,t.highlightId>-1?(this.#u=!0,this.#v(t),this.#M()):this.#s&&(this.#t=t.anchorNode,this.#e=t.anchorOffset,this.#h=t.focusNode,this.#a=t.focusOffset,this.#_(),this.#M(),this.rotate(this.rotation))}get telemetryInitialData(){return{action:"added",type:this.#u?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:this.#p,methodOfCreation:this.#b}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(t){return{numberOfColors:t.get("color").size}}#_(){const t=new xo(this.#s,.001);this.#l=t.getOutlines(),[this.x,this.y,this.width,this.height]=this.#l.box;const e=new xo(this.#s,.0025,.001,this._uiManager.direction==="ltr");this.#n=e.getOutlines();const{lastPoint:s}=this.#n;this.#f=[(s[0]-this.x)/this.width,(s[1]-this.y)/this.height]}#v({highlightOutlines:t,highlightId:e,clipPathId:s}){this.#l=t;const i=1.5;if(this.#n=t.getNewOutline(this.#p/2+i,.0025),e>=0)this.#d=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){const c=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#d,{bbox:mt.#x(this.#l.box,(c-this.rotation+360)%360),path:{d:t.toSVGPath()}}),this.parent.drawLayer.updateProperties(this.#g,{bbox:mt.#x(this.#n.box,c),path:{d:this.#n.toSVGPath()}})}const[n,r,o,h]=t.box;switch(this.rotation){case 0:this.x=n,this.y=r,this.width=o,this.height=h;break;case 90:{const[c,u]=this.parentDimensions;this.x=r,this.y=1-n,this.width=o*u/c,this.height=h*c/u;break}case 180:this.x=1-n,this.y=1-r,this.width=o,this.height=h;break;case 270:{const[c,u]=this.parentDimensions;this.x=1-r,this.y=n,this.width=o*u/c,this.height=h*c/u;break}}const{lastPoint:l}=this.#n;this.#f=[(l[0]-n)/o,(l[1]-r)/h]}static initialize(t,e){H.initialize(t,e),mt._defaultColor||=e.highlightColors?.values().next().value||"#fff066"}static updateDefaultParams(t,e){switch(t){case q.HIGHLIGHT_DEFAULT_COLOR:mt._defaultColor=e;break;case q.HIGHLIGHT_THICKNESS:mt._defaultThickness=e;break}}translateInPage(t,e){}get toolbarPosition(){return this.#f}updateParams(t,e){switch(t){case q.HIGHLIGHT_COLOR:this.#w(e);break;case q.HIGHLIGHT_THICKNESS:this.#S(e);break}}static get defaultPropertiesToUpdate(){return[[q.HIGHLIGHT_DEFAULT_COLOR,mt._defaultColor],[q.HIGHLIGHT_THICKNESS,mt._defaultThickness]]}get propertiesToUpdate(){return[[q.HIGHLIGHT_COLOR,this.color||mt._defaultColor],[q.HIGHLIGHT_THICKNESS,this.#p||mt._defaultThickness],[q.HIGHLIGHT_FREE,this.#u]]}#w(t){const e=(n,r)=>{this.color=n,this.#o=r,this.parent?.drawLayer.updateProperties(this.#d,{root:{fill:n,"fill-opacity":r}}),this.#r?.updateColor(n)},s=this.color,i=this.#o;this.addCommands({cmd:e.bind(this,t,mt._defaultOpacity),undo:e.bind(this,s,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:q.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(t)},!0)}#S(t){const e=this.#p,s=i=>{this.#p=i,this.#A(i)};this.addCommands({cmd:s.bind(this,t),undo:s.bind(this,e),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:q.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:t},!0)}async addEditToolbar(){const t=await super.addEditToolbar();return t?(this._uiManager.highlightColors&&(this.#r=new 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.#O())}getBaseTranslation(){return[0,0]}getRect(t,e){return super.getRect(t,e,this.#O())}onceAdded(t){this.annotationElementId||this.parent.addUndoableEditor(this),t&&this.div.focus()}remove(){this.#E(),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#M(),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){let e=!1;this.parent&&!t?this.#E():t&&(this.#M(t),e=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(t),this.show(this._isVisible),e&&this.select()}#A(t){if(!this.#u)return;this.#v({highlightOutlines:this.#l.getNewOutline(t/2)}),this.fixAndSetPosition();const[e,s]=this.parentDimensions;this.setDims(this.width*e,this.height*s)}#E(){this.#d===null||!this.parent||(this.parent.drawLayer.remove(this.#d),this.#d=null,this.parent.drawLayer.remove(this.#g),this.#g=null)}#M(t=this.parent){this.#d===null&&({id:this.#d,clipPathId:this.#i}=t.drawLayer.draw({bbox:this.#l.box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":this.#o},rootClass:{highlight:!0,free:this.#u},path:{d:this.#l.toSVGPath()}},!1,!0),this.#g=t.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#u},bbox:this.#n.box,path:{d:this.#n.toSVGPath()}},this.#u),this.#c&&(this.#c.style.clipPath=this.#i))}static#x([t,e,s,i],n){switch(n){case 90:return[1-e-i,t,i,s];case 180:return[1-t-s,1-e-i,s,i];case 270:return[e,1-t-s,i,s]}return[t,e,s,i]}rotate(t){const{drawLayer:e}=this.parent;let s;this.#u?(t=(t-this.rotation+360)%360,s=mt.#x(this.#l.box,t)):s=mt.#x([this.x,this.y,this.width,this.height],t),e.updateProperties(this.#d,{bbox:s,root:{"data-main-rotation":t}}),e.updateProperties(this.#g,{bbox:mt.#x(this.#n.box,t),root:{"data-main-rotation":t}})}render(){if(this.div)return this.div;const t=super.render();this.#m&&(t.setAttribute("aria-label",this.#m),t.setAttribute("role","mark")),this.#u?t.classList.add("free"):this.div.addEventListener("keydown",this.#k.bind(this),{signal:this._uiManager._signal});const e=this.#c=document.createElement("div");t.append(e),e.setAttribute("aria-hidden","true"),e.className="internal",e.style.clipPath=this.#i;const[s,i]=this.parentDimensions;return this.setDims(this.width*s,this.height*i),Ln(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){mt._keyboardManager.exec(this,t)}_moveCaret(t){switch(this.parent.unselect(this),t){case 0:case 2:this.#T(!0);break;case 1:case 3:this.#T(!1);break}}#T(t){if(!this.#t)return;const e=window.getSelection();t?e.setPosition(this.#t,this.#e):e.setPosition(this.#h,this.#a)}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.#u||this.#T(!1))}get _mustFixPosition(){return!this.#u}show(t=this._isVisible){super.show(t),this.parent&&(this.parent.drawLayer.updateProperties(this.#d,{rootClass:{hidden:!t}}),this.parent.drawLayer.updateProperties(this.#g,{rootClass:{hidden:!t}}))}#O(){return this.#u?this.rotation:0}#L(){if(this.#u)return null;const[t,e]=this.pageDimensions,[s,i]=this.pageTranslation,n=this.#s,r=new Float32Array(n.length*8);let o=0;for(const{x:h,y:l,width:c,height:u}of n){const d=h*t+s,f=(1-l)*e+i;r[o]=r[o+4]=d,r[o+1]=r[o+3]=f,r[o+2]=r[o+6]=d+c*t,r[o+5]=r[o+7]=f-u*e,o+=8}return r}#I(t){return this.#l.serialize(t,this.#O())}static startHighlighting(t,e,{target:s,x:i,y:n}){const{x:r,y:o,width:h,height:l}=s.getBoundingClientRect(),c=new AbortController,u=t.combinedSignal(c),d=f=>{c.abort(),this.#y(t,f)};window.addEventListener("blur",d,{signal:u}),window.addEventListener("pointerup",d,{signal:u}),window.addEventListener("pointerdown",te,{capture:!0,passive:!1,signal:u}),window.addEventListener("contextmenu",ge,{signal:u}),s.addEventListener("pointermove",this.#C.bind(this,t),{signal:u}),this._freeHighlight=new So({x:i,y:n},[r,o,h,l],t.scale,this._defaultThickness/2,e,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=t.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static#C(t,e){this._freeHighlight.add(e)&&t.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#y(t,e){this._freeHighlight.isEmpty()?t.drawLayer.remove(this._freeHighlightId):t.createAndAddNewEditor(e,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""}static async deserialize(t,e,s){let i=null;if(t instanceof Ml){const{data:{quadPoints:g,rect:p,rotation:b,id:m,color:v,opacity:y,popupRef:_},parent:{page:{pageNumber:S}}}=t;i=t={annotationType:U.HIGHLIGHT,color:Array.from(v),opacity:y,quadPoints:g,boxes:null,pageIndex:S-1,rect:p.slice(0),rotation:b,id:m,deleted:!1,popupRef:_}}else if(t instanceof wo){const{data:{inkLists:g,rect:p,rotation:b,id:m,color:v,borderStyle:{rawWidth:y},popupRef:_},parent:{page:{pageNumber:S}}}=t;i=t={annotationType:U.HIGHLIGHT,color:Array.from(v),thickness:y,inkLists:g,boxes:null,pageIndex:S-1,rect:p.slice(0),rotation:b,id:m,deleted:!1,popupRef:_}}const{color:n,quadPoints:r,inkLists:o,opacity:h}=t,l=await super.deserialize(t,e,s);l.color=B.makeHexColor(...n),l.#o=h||1,o&&(l.#p=t.thickness),l.annotationElementId=t.id||null,l._initialData=i;const[c,u]=l.pageDimensions,[d,f]=l.pageTranslation;if(r){const g=l.#s=[];for(let p=0;p<r.length;p+=8)g.push({x:(r[p]-d)/c,y:1-(r[p+1]-f)/u,width:(r[p+2]-r[p])/c,height:(r[p+1]-r[p+5])/u});l.#_(),l.#M(),l.rotate(l.rotation)}else if(o){l.#u=!0;const g=o[0],p={x:g[0]-d,y:u-(g[1]-f)},b=new So(p,[0,0,c,u],1,l.#p/2,!0,.001);for(let y=0,_=g.length;y<_;y+=2)p.x=g[y]-d,p.y=u-(g[y+1]-f),b.add(p);const{id:m,clipPathId:v}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:l.color,"fill-opacity":l._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:b.toSVGPath()}},!0,!0);l.#v({highlightOutlines:b.getOutlines(),highlightId:m,clipPathId:v}),l.#M()}return l}serialize(t=!1){if(this.isEmpty()||t)return null;if(this.deleted)return this.serializeDeleted();const e=this.getRect(0,0),s=H._colorManager.convert(this.color),i={annotationType:U.HIGHLIGHT,color:s,opacity:this.#o,thickness:this.#p,quadPoints:this.#L(),outlines:this.#I(e),pageIndex:this.pageIndex,rect:e,rotation:this.#O(),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!this.#R(i)?null:(i.id=this.annotationElementId,i)}#R(t){const{color:e}=this._initialData;return t.color.some((s,i)=>s!==e[i])}renderAnnotationElement(t){return t.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}}class yg{#t=Object.create(null);updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(const[e,s]of Object.entries(t))this.updateProperty(e,s)}updateSVGProperty(t,e){this.#t[t]=e}toSVGProperties(){const t=this.#t;return this.#t=Object.create(null),{root:t}}reset(){this.#t=Object.create(null)}updateAll(t=this){this.updateProperties(t)}clone(){st("Not implemented")}}class z extends H{#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#a=null;static#c=NaN;static _INNER_MARGIN=3;constructor(t){super(t),this.#e=t.mustBeCommitted||!1,t.drawOutlines&&(this.#l(t),this.#f())}#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.#d(t,this.parent),this.#m(t.box)}#d(t,e){const{id:s}=e.drawLayer.draw(z._mergeSVGProperties(this._drawingOptions.toSVGProperties(),t.defaultSVGProperties),!1,!1);return s}static _mergeSVGProperties(t,e){const s=new Set(Object.keys(t));for(const[i,n]of Object.entries(e))s.has(i)?Object.assign(t[i],n):t[i]=n;return t}static getDefaultDrawingOptions(t){st("Not implemented")}static get typesMap(){st("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(t,e){const s=this.typesMap.get(t);s&&this._defaultDrawingOptions.updateProperty(s,e),this._currentParent&&(z.#s.updateProperty(s,e),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(t,e){const s=this.constructor.typesMap.get(t);s&&this._updateProperty(t,s,e)}static get defaultPropertiesToUpdate(){const t=[],e=this._defaultDrawingOptions;for(const[s,i]of this.typesMap)t.push([s,e[i]]);return t}get propertiesToUpdate(){const t=[],{_drawingOptions:e}=this;for(const[s,i]of this.constructor.typesMap)t.push([s,e[i]]);return t}_updateProperty(t,e,s){const i=this._drawingOptions,n=i[e],r=o=>{i.updateProperty(e,o);const h=this.#t.updateProperty(e,o);h&&this.#m(h),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,z._mergeSVGProperties(this.#t.getPathResizingSVGProperties(this.#g()),{bbox:this.#p()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,z._mergeSVGProperties(this.#t.getPathResizedSVGProperties(this.#g()),{bbox:this.#p()}))}_onTranslating(t,e){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#p(t,e)})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,z._mergeSVGProperties(this.#t.getPathTranslatedSVGProperties(this.#g(),this.parentDimensions),{bbox:this.#p()}))}_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.#u(),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#f(),this.#m(this.#t.box),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){let e=!1;this.parent&&!t?(this._uiManager.removeShouldRescale(this),this.#u()):t&&(this._uiManager.addShouldRescale(this),this.#f(t),e=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(t),e&&this.select()}#u(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())}#f(t=this.parent){if(!(this._drawId!==null&&this.parent===t)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,t.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=this.#d(this.#t,t)}}#o([t,e,s,i]){const{parentDimensions:[n,r],rotation:o}=this;switch(o){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(){const{x:t,y:e,width:s,height:i,parentDimensions:[n,r],rotation:o}=this;switch(o){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.#o(t),this.div){this.fixAndSetPosition();const[e,s]=this.parentDimensions;this.setDims(this.width*e,this.height*s)}this._onResized()}#p(){const{x:t,y:e,width:s,height:i,rotation:n,parentRotation:r,parentDimensions:[o,h]}=this;switch((n*4+r)/90){case 1:return[1-e-i,t,i,s];case 2:return[1-t-s,1-e-i,s,i];case 3:return[e,1-t-s,i,s];case 4:return[t,e-s*(o/h),i*(h/o),s*(o/h)];case 5:return[1-e,t,s*(o/h),i*(h/o)];case 6:return[1-t-i*(h/o),1-e,i*(h/o),s*(o/h)];case 7:return[e-s*(o/h),1-t-i*(h/o),s*(o/h),i*(h/o)];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*(h/o),e,i*(h/o),s*(o/h)];case 13:return[1-e-s*(o/h),t-i*(h/o),s*(o/h),i*(h/o)];case 14:return[1-t,1-e-s*(o/h),i*(h/o),s*(o/h)];case 15:return[e,1-t,s*(o/h),i*(h/o)];default:return[t,e,s,i]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,z._mergeSVGProperties({bbox:this.#p()},this.#t.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#m(this.#t.updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;const t=super.render();t.classList.add("draw");const e=document.createElement("div");t.append(e),e.setAttribute("aria-hidden","true"),e.className="internal";const[s,i]=this.parentDimensions;return this.setDims(this.width*s,this.height*i),this._uiManager.addShouldRescale(this),this.disableEditing(),t}static createDrawerInstance(t,e,s,i,n){st("Not implemented")}static startDrawing(t,e,s,i){const{target:n,offsetX:r,offsetY:o,pointerId:h,pointerType:l}=i;if(z.#h&&z.#h!==l)return;const{viewport:{rotation:c}}=t,{width:u,height:d}=n.getBoundingClientRect(),f=z.#i=new AbortController,g=t.combinedSignal(f);if(z.#n||=h,z.#h??=l,window.addEventListener("pointerup",p=>{z.#n===p.pointerId?this._endDraw(p):z.#a?.delete(p.pointerId)},{signal:g}),window.addEventListener("pointercancel",p=>{z.#n===p.pointerId?this._currentParent.endDrawingSession():z.#a?.delete(p.pointerId)},{signal:g}),window.addEventListener("pointerdown",p=>{z.#h===p.pointerType&&((z.#a||=new Set).add(p.pointerId),z.#s.isCancellable()&&(z.#s.removeLastElement(),z.#s.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:g}),window.addEventListener("contextmenu",ge,{signal:g}),n.addEventListener("pointermove",this._drawMove.bind(this),{signal:g}),n.addEventListener("touchmove",p=>{p.timeStamp===z.#c&&te(p)},{signal:g}),t.toggleDrawing(),e._editorUndoBar?.hide(),z.#s){t.drawLayer.updateProperties(this._currentDrawId,z.#s.startNew(r,o,u,d,c));return}e.updateUIForDefaultProperties(this),z.#s=this.createDrawerInstance(r,o,u,d,c),z.#r=this.getDefaultDrawingOptions(),this._currentParent=t,{id:this._currentDrawId}=t.drawLayer.draw(this._mergeSVGProperties(z.#r.toSVGProperties(),z.#s.defaultSVGProperties),!0,!1)}static _drawMove(t){if(z.#c=-1,!z.#s)return;const{offsetX:e,offsetY:s,pointerId:i}=t;if(z.#n===i){if(z.#a?.size>=1){this._endDraw(t);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,z.#s.add(e,s)),z.#c=t.timeStamp,te(t)}}static _cleanup(t){t&&(this._currentDrawId=-1,this._currentParent=null,z.#s=null,z.#r=null,z.#h=null,z.#c=NaN),z.#i&&(z.#i.abort(),z.#i=null,z.#n=NaN,z.#a=null)}static _endDraw(t){const e=this._currentParent;if(e){if(e.toggleDrawing(!0),this._cleanup(!1),t&&e.drawLayer.updateProperties(this._currentDrawId,z.#s.end(t.offsetX,t.offsetY)),this.supportMultipleDrawings){const s=z.#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:q.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(t){const e=this._currentParent;if(!e)return null;if(e.toggleDrawing(!0),e.cleanUndoStack(q.DRAW_STEP),!z.#s.isEmpty()){const{pageDimensions:[s,i],scale:n}=e,r=e.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:z.#s.getOutlines(s*n,i*n,n,this._INNER_MARGIN),drawingOptions:z.#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){st("Not implemented")}static async deserialize(t,e,s){const{rawDims:{pageWidth:i,pageHeight:n,pageX:r,pageY:o}}=e.viewport,h=this.deserializeDraw(r,o,i,n,this._INNER_MARGIN,t),l=await super.deserialize(t,e,s);return l.createDrawingOptions(t),l.#l({drawOutlines:h}),l.#f(),l.onScaleChanging(),l.rotate(),l}serializeDraw(t){const[e,s]=this.pageTranslation,[i,n]=this.pageDimensions;return this.#t.serialize([e,s,i,n],t)}renderAnnotationElement(t){return t.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}}class _g{#t=new Float64Array(6);#e;#s;#i;#r;#n;#h="";#a=0;#c=new Gn;#l;#d;constructor(t,e,s,i,n,r){this.#l=s,this.#d=i,this.#i=n,this.#r=r,[t,e]=this.#u(t,e);const o=this.#e=[NaN,NaN,NaN,NaN,t,e];this.#n=[t,e],this.#s=[{line:o,points:this.#n}],this.#t.set(o,0)}updateProperty(t,e){t==="stroke-width"&&(this.#r=e)}#u(t,e){return I._normalizePoint(t,e,this.#l,this.#d,this.#i)}isEmpty(){return!this.#s||this.#s.length===0}isCancellable(){return this.#n.length<=10}add(t,e){[t,e]=this.#u(t,e);const[s,i,n,r]=this.#t.subarray(2,6),o=t-n,h=e-r;return Math.hypot(this.#l*o,this.#d*h)<=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(...I.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const s=this.add(t,e);return s||(this.#n.length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){this.#l=s,this.#d=i,this.#i=n,[t,e]=this.#u(t,e);const r=this.#e=[NaN,NaN,NaN,NaN,t,e];this.#n=[t,e];const o=this.#s.at(-1);return o&&(o.line=new Float32Array(o.line),o.points=new Float32Array(o.points)),this.#s.push({line:r,points:this.#n}),this.#t.set(r,0),this.#a=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.#a=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++){const{line:s,points:i}=this.#s[t];this.#e=s,this.#n=i,this.#a=0,this.toSVGPath()}return{path:{d:this.#h}}}toSVGPath(){const t=I.svgRound(this.#e[4]),e=I.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){const i=this.#h.lastIndexOf("M");this.#h=`${this.#h.slice(0,i)} M ${t} ${e}`,this.#a=6}if(this.#n.length===4){const i=I.svgRound(this.#e[10]),n=I.svgRound(this.#e[11]);return this.#h=`${this.#h} L ${i} ${n}`,this.#a=12,this.#h}const s=[];this.#a===0&&(s.push(`M ${t} ${e}`),this.#a=6);for(let i=this.#a,n=this.#e.length;i<n;i+=6){const[r,o,h,l,c,u]=this.#e.slice(i,i+6).map(I.svgRound);s.push(`C${r} ${o} ${h} ${l} ${c} ${u}`)}return this.#h+=s.join(" "),this.#a=this.#e.length,this.#h}getOutlines(t,e,s,i){const n=this.#s.at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),this.#c.build(this.#s,t,e,s,this.#i,this.#r,i),this.#t=null,this.#e=null,this.#s=null,this.#h=null,this.#c}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}class Gn extends I{#t;#e=0;#s;#i;#r;#n;#h;#a;#c;build(t,e,s,i,n,r,o){this.#r=e,this.#n=s,this.#h=i,this.#a=n,this.#c=r,this.#s=o??0,this.#i=t,this.#u()}setLastElement(t){return this.#i.push(t),{path:{d:this.toSVGPath()}}}removeLastElement(){return this.#i.pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const t=[];for(const{line:e}of this.#i){if(t.push(`M${I.svgRound(e[4])} ${I.svgRound(e[5])}`),e.length===6){t.push("Z");continue}if(e.length===12){t.push(`L${I.svgRound(e[10])} ${I.svgRound(e[11])}`);continue}for(let s=6,i=e.length;s<i;s+=6){const[n,r,o,h,l,c]=e.subarray(s,s+6).map(I.svgRound);t.push(`C${n} ${r} ${o} ${h} ${l} ${c}`)}}return t.join("")}serialize([t,e,s,i],n){const r=[],o=[],[h,l,c,u]=this.#d();let d,f,g,p,b,m,v,y,_;switch(this.#a){case 0:_=I._rescale,d=t,f=e+i,g=s,p=-i,b=t+h*s,m=e+(1-l-u)*i,v=t+(h+c)*s,y=e+(1-l)*i;break;case 90:_=I._rescaleAndSwap,d=t,f=e,g=s,p=i,b=t+l*s,m=e+h*i,v=t+(l+u)*s,y=e+(h+c)*i;break;case 180:_=I._rescale,d=t+s,f=e,g=-s,p=i,b=t+(1-h-c)*s,m=e+l*i,v=t+(1-h)*s,y=e+(l+u)*i;break;case 270:_=I._rescaleAndSwap,d=t+s,f=e+i,g=-s,p=-i,b=t+(1-l-u)*s,m=e+(1-h-c)*i,v=t+(1-l)*s,y=e+(1-h)*i;break}for(const{line:S,points:A}of this.#i)r.push(_(S,d,f,g,p,n?new Array(S.length):null)),o.push(_(A,d,f,g,p,n?new Array(A.length):null));return{lines:r,points:o,rect:[b,m,v,y]}}static deserialize(t,e,s,i,n,{paths:{lines:r,points:o},rotation:h,thickness:l}){const c=[];let u,d,f,g,p;switch(h){case 0:p=I._rescale,u=-t/s,d=e/i+1,f=1/s,g=-1/i;break;case 90:p=I._rescaleAndSwap,u=-e/i,d=-t/s,f=1/i,g=1/s;break;case 180:p=I._rescale,u=t/s+1,d=-e/i,f=-1/s,g=1/i;break;case 270:p=I._rescaleAndSwap,u=e/i+1,d=t/s+1,f=-1/i,g=-1/s;break}if(!r){r=[];for(const m of o){const v=m.length;if(v===2){r.push(new Float32Array([NaN,NaN,NaN,NaN,m[0],m[1]]));continue}if(v===4){r.push(new Float32Array([NaN,NaN,NaN,NaN,m[0],m[1],NaN,NaN,NaN,NaN,m[2],m[3]]));continue}const y=new Float32Array(3*(v-2));r.push(y);let[_,S,A,T]=m.subarray(0,4);y.set([NaN,NaN,NaN,NaN,_,S],0);for(let E=4;E<v;E+=2){const P=m[E],N=m[E+1];y.set(I.createBezierPoints(_,S,A,T,P,N),(E-2)*3),[_,S,A,T]=[A,T,P,N]}}}for(let m=0,v=r.length;m<v;m++)c.push({line:p(r[m].map(y=>y??NaN),u,d,f,g),points:p(o[m].map(y=>y??NaN),u,d,f,g)});const b=new Gn;return b.build(c,s,i,1,h,l,n),b}#l(t=this.#c){const e=this.#s+t/2*this.#h;return this.#a%180===0?[e/this.#r,e/this.#n]:[e/this.#n,e/this.#r]}#d(){const[t,e,s,i]=this.#t,[n,r]=this.#l(0);return[t+n,e+r,s-2*n,i-2*r]}#u(){const t=this.#t=new Float32Array([1/0,1/0,-1/0,-1/0]);for(const{line:i}of this.#i){if(i.length<=12){for(let o=4,h=i.length;o<h;o+=6){const[l,c]=i.subarray(o,o+2);t[0]=Math.min(t[0],l),t[1]=Math.min(t[1],c),t[2]=Math.max(t[2],l),t[3]=Math.max(t[3],c)}continue}let n=i[4],r=i[5];for(let o=6,h=i.length;o<h;o+=6){const[l,c,u,d,f,g]=i.subarray(o,o+6);B.bezierBoundingBox(n,r,l,c,u,d,f,g,t),n=f,r=g}}const[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.#f(e):null}#f(t){const[e,s]=this.#l();this.#c=t;const[i,n]=this.#l(),[r,o]=[i-e,n-s],h=this.#t;return h[0]-=r,h[1]-=o,h[2]+=2*r,h[3]+=2*o,h}updateParentDimensions([t,e],s){const[i,n]=this.#l();this.#r=t,this.#n=e,this.#h=s;const[r,o]=this.#l(),h=r-i,l=o-n,c=this.#t;return c[0]-=h,c[1]-=l,c[2]+=2*h,c[3]+=2*l,c}updateRotation(t){return this.#e=t,{path:{transform:this.rotationTransform}}}get viewBox(){return this.#t.map(I.svgRound).join(" ")}get defaultProperties(){const[t,e]=this.#t;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${I.svgRound(t)} ${I.svgRound(e)}`}}}get rotationTransform(){const[,,t,e]=this.#t;let s=0,i=0,n=0,r=0,o=0,h=0;switch(this.#e){case 90:i=e/t,n=-t/e,o=t;break;case 180:s=-1,r=-1,o=t,h=e;break;case 270:i=-e/t,n=t/e,h=e;break;default:return""}return`matrix(${s} ${i} ${n} ${r} ${I.svgRound(o)} ${I.svgRound(h)})`}getPathResizingSVGProperties([t,e,s,i]){const[n,r]=this.#l(),[o,h,l,c]=this.#t;if(Math.abs(l-n)<=I.PRECISION||Math.abs(c-r)<=I.PRECISION){const p=t+s/2-(o+l/2),b=e+i/2-(h+c/2);return{path:{"transform-origin":`${I.svgRound(t)} ${I.svgRound(e)}`,transform:`${this.rotationTransform} translate(${p} ${b})`}}}const u=(s-2*n)/(l-2*n),d=(i-2*r)/(c-2*r),f=l/s,g=c/i;return{path:{"transform-origin":`${I.svgRound(o)} ${I.svgRound(h)}`,transform:`${this.rotationTransform} scale(${f} ${g}) translate(${I.svgRound(n)} ${I.svgRound(r)}) scale(${u} ${d}) translate(${I.svgRound(-n)} ${I.svgRound(-r)})`}}}getPathResizedSVGProperties([t,e,s,i]){const[n,r]=this.#l(),o=this.#t,[h,l,c,u]=o;if(o[0]=t,o[1]=e,o[2]=s,o[3]=i,Math.abs(c-n)<=I.PRECISION||Math.abs(u-r)<=I.PRECISION){const b=t+s/2-(h+c/2),m=e+i/2-(l+u/2);for(const{line:v,points:y}of this.#i)I._translate(v,b,m,v),I._translate(y,b,m,y);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${I.svgRound(t)} ${I.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const d=(s-2*n)/(c-2*n),f=(i-2*r)/(u-2*r),g=-d*(h+n)+t+n,p=-f*(l+r)+e+r;if(d!==1||f!==1||g!==0||p!==0)for(const{line:b,points:m}of this.#i)I._rescale(b,g,p,d,f,b),I._rescale(m,g,p,d,f,m);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${I.svgRound(t)} ${I.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([t,e],s){const[i,n]=s,r=this.#t,o=t-r[0],h=e-r[1];if(this.#r===i&&this.#n===n)for(const{line:l,points:c}of this.#i)I._translate(l,o,h,l),I._translate(c,o,h,c);else{const l=this.#r/i,c=this.#n/n;this.#r=i,this.#n=n;for(const{line:u,points:d}of this.#i)I._rescale(u,o,h,l,c,u),I._rescale(d,o,h,l,c,d);r[2]*=l,r[3]*=c}return r[0]=t,r[1]=e,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${I.svgRound(t)} ${I.svgRound(e)}`}}}get defaultSVGProperties(){const t=this.#t;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${I.svgRound(t[0])} ${I.svgRound(t[1])}`,transform:this.rotationTransform||null},bbox:t}}}class Co extends yg{#t;constructor(t){super(),this.#t=t,super.updateProperties({fill:"none",stroke:H._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(t,e){t==="stroke-width"&&(e??=this["stroke-width"],e*=this.#t.realScale),super.updateSVGProperty(t,e)}clone(){const t=new Co(this.#t);return t.updateAll(this),t}}class Ao extends z{static _type="ink";static _editorType=U.INK;static _defaultDrawingOptions=null;constructor(t){super({...t,name:"inkEditor"}),this._willKeepAspectRatio=!0}static initialize(t,e){H.initialize(t,e),this._defaultDrawingOptions=new Co(e.viewParameters)}static getDefaultDrawingOptions(t){const e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!0}static get typesMap(){return $(this,"typesMap",new Map([[q.INK_THICKNESS,"stroke-width"],[q.INK_COLOR,"stroke"],[q.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(t,e,s,i,n){return new _g(t,e,s,i,n,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(t,e,s,i,n,r){return Gn.deserialize(t,e,s,i,n,r)}static async deserialize(t,e,s){let i=null;if(t instanceof wo){const{data:{inkLists:r,rect:o,rotation:h,id:l,color:c,opacity:u,borderStyle:{rawWidth:d},popupRef:f},parent:{page:{pageNumber:g}}}=t;i=t={annotationType:U.INK,color:Array.from(c),thickness:d,opacity:u,paths:{points:r},boxes:null,pageIndex:g-1,rect:o.slice(0),rotation:h,id:l,deleted:!1,popupRef:f}}const n=await super.deserialize(t,e,s);return n.annotationElementId=t.id||null,n._initialData=i,n}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:t,_drawingOptions:e,parent:s}=this;e.updateSVGProperty("stroke-width"),s.drawLayer.updateProperties(t,e.toSVGProperties())}static onScaleChangingWhenDrawing(){const t=this._currentParent;t&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),t.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:t,thickness:e,opacity:s}){this._drawingOptions=Ao.getDefaultDrawingOptions({stroke:B.makeHexColor(...t),"stroke-width":e,"stroke-opacity":s})}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:e,points:s,rect:i}=this.serializeDraw(t),{_drawingOptions:{stroke:n,"stroke-opacity":r,"stroke-width":o}}=this,h={annotationType:U.INK,color:H._colorManager.convert(n),opacity:r,thickness:o,paths:{lines:e,points:s},pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return t?h:this.annotationElementId&&!this.#t(h)?null:(h.id=this.annotationElementId,h)}#t(t){const{color:e,thickness:s,opacity:i,pageIndex:n}=this._initialData;return this._hasBeenMoved||this._hasBeenResized||t.color.some((r,o)=>r!==e[o])||t.thickness!==s||t.opacity!==i||t.pageIndex!==n}renderAnnotationElement(t){const{points:e,rect:s}=this.serializeDraw(!1);return t.updateEdited({rect:s,thickness:this._drawingOptions["stroke-width"],points:e}),null}}class To extends H{#t=null;#e=null;#s=null;#i=null;#r=null;#n="";#h=null;#a=null;#c=!1;#l=!1;static _type="stamp";static _editorType=U.STAMP;constructor(t){super({...t,name:"stampEditor"}),this.#i=t.bitmapUrl,this.#r=t.bitmapFile}static initialize(t,e){H.initialize(t,e)}static get supportedTypes(){return $(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(e=>`image/${e}`))}static get supportedTypesStr(){return $(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(t){return this.supportedTypes.includes(t)}static paste(t,e){e.pasteEditor(U.STAMP,{bitmapFile:t.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){return{type:"stamp",hasAltText:!!this.altTextData?.altText}}static computeTelemetryFinalData(t){const e=t.get("hasAltText");return{hasAltText:e.get(!0)??0,hasNoAltText:e.get(!1)??0}}#d(t,e=!1){if(!t){this.remove();return}this.#t=t.bitmap,e||(this.#e=t.id,this.#c=t.isSvg),t.file&&(this.#n=t.file.name),this.#o()}#u(){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);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#t){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}}async mlGuessAltText(t=null,e=!0){if(this.hasAltTextData())return null;const{mlManager:s}=this._uiManager;if(!s)throw new Error("No ML.");if(!await s.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:i,width:n,height:r}=t||this.copyCanvas(null,null,!0).imageData,o=await s.guess({name:"altText",request:{data:i,width:n,height:r,channels:i.length/(n*r)}});if(!o)throw new Error("No response from the AI service.");if(o.error)throw new Error("Error from the AI service.");if(o.cancel)return null;if(!o.output)throw new Error("No valid response from the AI service.");const h=o.output;return await this.setGuessedAltText(h),e&&!this.hasAltTextData()&&(this.altTextData={alt:h,decorative:!1}),h}#f(){if(this.#e){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(this.#e).then(s=>this.#d(s,!0)).finally(()=>this.#u());return}if(this.#i){const s=this.#i;this.#i=null,this._uiManager.enableWaiting(!0),this.#s=this._uiManager.imageManager.getFromUrl(s).then(i=>this.#d(i)).finally(()=>this.#u());return}if(this.#r){const s=this.#r;this.#r=null,this._uiManager.enableWaiting(!0),this.#s=this._uiManager.imageManager.getFromFile(s).then(i=>this.#d(i)).finally(()=>this.#u());return}const t=document.createElement("input");t.type="file",t.accept=To.supportedTypesStr;const e=this._uiManager._signal;this.#s=new Promise(s=>{t.addEventListener("change",async()=>{if(!t.files||t.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const i=await this._uiManager.imageManager.getFromFile(t.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),this.#d(i)}s()},{signal:e}),t.addEventListener("cancel",()=>{this.remove(),s()},{signal:e})}).finally(()=>this.#u()),t.click()}remove(){this.#e&&(this.#t=null,this._uiManager.imageManager.deleteId(this.#e),this.#h?.remove(),this.#h=null,this.#a&&(clearTimeout(this.#a),this.#a=null)),super.remove()}rebuild(){if(!this.parent){this.#e&&this.#f();return}super.rebuild(),this.div!==null&&(this.#e&&this.#h===null&&this.#f(),this.isAttachedToDOM||this.parent.add(this))}onceAdded(t){this._isDraggable=!0,t&&this.div.focus()}isEmpty(){return!(this.#s||this.#t||this.#i||this.#r||this.#e)}get isResizable(){return!0}render(){if(this.div)return this.div;let t,e;if(this.width&&(t=this.x,e=this.y),super.render(),this.div.hidden=!0,this.div.setAttribute("role","figure"),this.addAltTextButton(),this.#t?this.#o():this.#f(),this.width&&!this.annotationElementId){const[s,i]=this.parentDimensions;this.setAt(t*s,e*i,this.width*s,this.height*i)}return this._uiManager.addShouldRescale(this),this.div}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;this.#a!==null&&clearTimeout(this.#a);const t=200;this.#a=setTimeout(()=>{this.#a=null,this.#m()},t)}#o(){const{div:t}=this;let{width:e,height:s}=this.#t;const[i,n]=this.pageDimensions,r=.75;if(this.width)e=this.width*i,s=this.height*n;else if(e>r*i||s>r*n){const c=Math.min(r*i/e,r*n/s);e*=c,s*=c}const[o,h]=this.parentDimensions;this.setDims(e*o/i,s*h/n),this._uiManager.enableWaiting(!1);const l=this.#h=document.createElement("canvas");l.setAttribute("role","img"),this.addContainer(l),this.width=e/i,this.height=s/n,this._initialOptions?.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(t.hidden=!1),this.#m(),this.#l||(this.parent.addUndoableEditor(this),this.#l=!0),this._reportTelemetry({action:"inserted_image"}),this.#n&&l.setAttribute("aria-label",this.#n)}copyCanvas(t,e,s=!1){t||(t=224);const{width:i,height:n}=this.#t,r=new oo;let o=this.#t,h=i,l=n,c=null;if(e){if(i>e||n>e){const A=Math.min(e/i,e/n);h=Math.floor(i*A),l=Math.floor(n*A)}c=document.createElement("canvas");const d=c.width=Math.ceil(h*r.sx),f=c.height=Math.ceil(l*r.sy);this.#c||(o=this.#g(d,f));const g=c.getContext("2d");g.filter=this._uiManager.hcmFilter;let p="white",b="#cfcfd8";this._uiManager.hcmFilter!=="none"?b="black":window.matchMedia?.("(prefers-color-scheme: dark)").matches&&(p="#8f8f9d",b="#42414d");const m=15,v=m*r.sx,y=m*r.sy,_=new OffscreenCanvas(v*2,y*2),S=_.getContext("2d");S.fillStyle=p,S.fillRect(0,0,v*2,y*2),S.fillStyle=b,S.fillRect(0,0,v,y),S.fillRect(v,y,v,y),g.fillStyle=g.createPattern(_,"repeat"),g.fillRect(0,0,d,f),g.drawImage(o,0,0,o.width,o.height,0,0,d,f)}let u=null;if(s){let d,f;if(r.symmetric&&o.width<t&&o.height<t)d=o.width,f=o.height;else if(o=this.#t,i>t||n>t){const b=Math.min(t/i,t/n);d=Math.floor(i*b),f=Math.floor(n*b),this.#c||(o=this.#g(d,f))}const p=new OffscreenCanvas(d,f).getContext("2d",{willReadFrequently:!0});p.drawImage(o,0,0,o.width,o.height,0,0,d,f),u={width:d,height:f,data:p.getImageData(0,0,d,f).data}}return{canvas:c,width:h,height:l,imageData:u}}#g(t,e){const{width:s,height:i}=this.#t;let n=s,r=i,o=this.#t;for(;n>2*t||r>2*e;){const h=n,l=r;n>2*t&&(n=n>=16384?Math.floor(n/2)-1:Math.ceil(n/2)),r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2));const c=new OffscreenCanvas(n,r);c.getContext("2d").drawImage(o,0,0,h,l,0,0,n,r),o=c.transferToImageBitmap()}return o}#m(){const[t,e]=this.parentDimensions,{width:s,height:i}=this,n=new oo,r=Math.ceil(s*t*n.sx),o=Math.ceil(i*e*n.sy),h=this.#h;if(!h||h.width===r&&h.height===o)return;h.width=r,h.height=o;const l=this.#c?this.#t:this.#g(r,o),c=h.getContext("2d");c.filter=this._uiManager.hcmFilter,c.drawImage(l,0,0,l.width,l.height,0,0,r,o)}getImageForAltText(){return this.#h}#p(t){if(t){if(this.#c){const i=this._uiManager.imageManager.getSvgUrl(this.#e);if(i)return i}const e=document.createElement("canvas");return{width:e.width,height:e.height}=this.#t,e.getContext("2d").drawImage(this.#t,0,0),e.toDataURL()}if(this.#c){const[e,s]=this.pageDimensions,i=Math.round(this.width*e*Is.PDF_TO_CSS_UNITS),n=Math.round(this.height*s*Is.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 Pl){const{data:{rect:g,rotation:p,id:b,structParent:m,popupRef:v},container:y,parent:{page:{pageNumber:_}}}=t,S=y.querySelector("canvas"),A=s.imageManager.getFromCanvas(y.id,S);S.remove();const T=(await e._structTree.getAriaAttributes(`${so}${b}`))?.get("aria-label")||"";i=t={annotationType:U.STAMP,bitmapId:A.id,bitmap:A.bitmap,pageIndex:_-1,rect:g.slice(0),rotation:p,id:b,deleted:!1,accessibilityData:{decorative:!1,altText:T},isSvg:!1,structParent:m,popupRef:v}}const n=await super.deserialize(t,e,s),{rect:r,bitmap:o,bitmapUrl:h,bitmapId:l,isSvg:c,accessibilityData:u}=t;l&&s.imageManager.isValidId(l)?(n.#e=l,o&&(n.#t=o)):n.#i=h,n.#c=c;const[d,f]=n.pageDimensions;return n.width=(r[2]-r[0])/d,n.height=(r[3]-r[1])/f,n.annotationElementId=t.id||null,u&&(n.altTextData=u),n._initialData=i,n.#l=!!i,n}serialize(t=!1,e=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const s={annotationType:U.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.#p(!0),s.accessibilityData=this.serializeAltText(!0),s;const{decorative:i,altText:n}=this.serializeAltText(!1);if(!i&&n&&(s.accessibilityData={type:"Figure",alt:n}),this.annotationElementId){const o=this.#b(s);if(o.isSame)return null;o.isSameAltText?delete s.accessibilityData:s.accessibilityData.structParent=this._initialData.structParent??-1}if(s.id=this.annotationElementId,e===null)return s;e.stamps||=new Map;const r=this.#c?(s.rect[2]-s.rect[0])*(s.rect[3]-s.rect[1]):null;if(!e.stamps.has(this.#e))e.stamps.set(this.#e,{area:r,serialized:s}),s.bitmap=this.#p(!1);else if(this.#c){const o=e.stamps.get(this.#e);r>o.area&&(o.area=r,o.serialized.bitmap.close(),o.serialized.bitmap=this.#p(!1))}return s}#b(t){const{pageIndex:e,accessibilityData:{altText:s}}=this._initialData,i=t.pageIndex===e,n=(t.accessibilityData?.alt||"")===s;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&i&&n,isSameAltText:n}}renderAnnotationElement(t){return t.updateEdited({rect:this.getRect(0,0)}),null}}class He{#t;#e=!1;#s=null;#i=null;#r=null;#n=new Map;#h=!1;#a=!1;#c=!1;#l=null;#d=null;#u=null;#f=null;#o;static _initialized=!1;static#g=new Map([Ct,Ao,To,mt].map(t=>[t._editorType,t]));constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:o,textLayer:h,viewport:l,l10n:c}){const u=[...He.#g.values()];if(!He._initialized){He._initialized=!0;for(const d of u)d.initialize(c,t)}t.registerEditorTypes(u),this.#o=t,this.pageIndex=e,this.div=s,this.#t=n,this.#s=r,this.viewport=l,this.#u=h,this.drawLayer=o,this._structTree=i,this.#o.addLayer(this)}get isEmpty(){return this.#n.size===0}get isInvisible(){return this.isEmpty&&this.#o.getMode()===U.NONE}updateToolbar(t){this.#o.updateToolbar(t)}updateMode(t=this.#o.getMode()){switch(this.#v(),t){case U.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case U.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case U.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:e}=this.div;for(const s of He.#g.values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){return t===this.#u?.div}setEditingState(t){this.#o.setEditingState(t)}addCommands(t){this.#o.addCommands(t)}cleanUndoStack(t){this.#o.cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){this.#s?.div.classList.toggle("disabled",!t)}async enable(){this.#c=!0,this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of this.#n.values())s.enableEditing(),s.show(!0),s.annotationElementId&&(this.#o.removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!this.#s){this.#c=!1;return}const e=this.#s.getEditableAnnotations();for(const s of e){if(s.hide(),this.#o.isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}this.#c=!1}disable(){this.#a=!0,this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const i of this.#n.values())if(i.disableEditing(),!!i.annotationElementId){if(i.serialize()!==null){t.set(i.annotationElementId,i);continue}else e.set(i.annotationElementId,i);this.getEditableAnnotation(i.annotationElementId)?.show(),i.remove()}if(this.#s){const i=this.#s.getEditableAnnotations();for(const n of i){const{id:r}=n.data;if(this.#o.isDeletedAnnotationElement(r))continue;let o=e.get(r);if(o){o.resetAnnotationElement(n),o.show(!1),n.show();continue}o=t.get(r),o&&(this.#o.addChangedExistingAnnotation(o),o.renderAnnotationElement(n)&&o.show(!1)),n.show()}}this.#v(),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const i of He.#g.values())s.remove(`${i._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),this.#a=!1}getEditableAnnotation(t){return this.#s?.getEditableAnnotation(t)||null}setActiveEditor(t){this.#o.getActive()!==t&&this.#o.setActiveEditor(t)}enableTextSelection(){if(this.div.tabIndex=-1,this.#u?.div&&!this.#f){this.#f=new AbortController;const t=this.#o.combinedSignal(this.#f);this.#u.div.addEventListener("pointerdown",this.#m.bind(this),{signal:t}),this.#u.div.classList.add("highlighting")}}disableTextSelection(){this.div.tabIndex=0,this.#u?.div&&this.#f&&(this.#f.abort(),this.#f=null,this.#u.div.classList.remove("highlighting"))}#m(t){this.#o.unselectAll();const{target:e}=t;if(e===this.#u.div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&this.#u.div.contains(e)){const{isMac:s}=Bt.platform;if(t.button!==0||t.ctrlKey&&s)return;this.#o.showAllEditors("highlight",!0,!0),this.#u.div.classList.add("free"),this.toggleDrawing(),mt.startHighlighting(this,this.#o.direction==="ltr",{target:this.#u.div,x:t.x,y:t.y}),this.#u.div.addEventListener("pointerup",()=>{this.#u.div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:this.#o._signal}),t.preventDefault()}}enableClick(){if(this.#i)return;this.#i=new AbortController;const t=this.#o.combinedSignal(this.#i);this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){this.#i?.abort(),this.#i=null}attach(t){this.#n.set(t.id,t);const{annotationElementId:e}=t;e&&this.#o.isDeletedAnnotationElement(e)&&this.#o.removeDeletedAnnotationElement(t)}detach(t){this.#n.delete(t.id),this.#t?.removePointerInTextLayer(t.contentDiv),!this.#a&&t.annotationElementId&&this.#o.addDeletedAnnotationElement(t)}remove(t){this.detach(t),this.#o.removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){t.parent!==this&&(t.parent&&t.annotationElementId&&(this.#o.addDeletedAnnotationElement(t.annotationElementId),H.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.#o.addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!this.#c),this.#o.addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!this.#r&&(t._focusEventsAllowed=!1,this.#r=setTimeout(()=>{this.#r=null,t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this.#o._signal}),e.focus())},0)),t._structTreeParentId=this.#t?.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||=this,t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getNextId(){return this.#o.getId()}get#p(){return He.#g.get(this.#o.getMode())}combinedSignal(t){return this.#o.combinedSignal(t)}#b(t){const e=this.#p;return e?new e.prototype.constructor(t):null}canCreateNewEmptyEditor(){return this.#p?.canCreateNewEmptyEditor()}pasteEditor(t,e){this.#o.updateToolbar(t),this.#o.updateMode(t);const{offsetX:s,offsetY:i}=this.#_(),n=this.getNextId(),r=this.#b({parent:this,id:n,x:s,y:i,uiManager:this.#o,isCentered:!0,...e});r&&this.add(r)}async deserialize(t){return await He.#g.get(t.annotationType??t.annotationEditorType)?.deserialize(t,this,this.#o)||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=this.#b({parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:this.#o,isCentered:e,...s});return n&&this.add(n),n}#_(){const{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),o=Math.min(window.innerWidth,t+s),h=Math.min(window.innerHeight,e+i),l=(n+o)/2-t,c=(r+h)/2-e,[u,d]=this.viewport.rotation%180===0?[l,c]:[c,l];return{offsetX:u,offsetY:d}}addNewEditor(){this.createAndAddNewEditor(this.#_(),!0)}setSelected(t){this.#o.setSelected(t)}toggleSelected(t){this.#o.toggleSelected(t)}unselect(t){this.#o.unselect(t)}pointerup(t){const{isMac:e}=Bt.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&this.#h&&(this.#h=!1,!(this.#p?.isDrawer&&this.#p.supportMultipleDrawings))){if(!this.#e){this.#e=!0;return}if(this.#o.getMode()===U.STAMP){this.#o.unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){if(this.#o.getMode()===U.HIGHLIGHT&&this.enableTextSelection(),this.#h){this.#h=!1;return}const{isMac:e}=Bt.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(this.#h=!0,this.#p?.isDrawer){this.startDrawingSession(t);return}const s=this.#o.getActive();this.#e=!s||s.isEmpty()}startDrawingSession(t){if(this.div.focus(),this.#l){this.#p.startDrawing(this,this.#o,!1,t);return}this.#o.setCurrentDrawingSession(this),this.#l=new AbortController;const e=this.#o.combinedSignal(this.#l);this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(this.#d=null,this.commitOrRemove())},{signal:e}),this.#p.startDrawing(this,this.#o,!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&(this.#d=e);return}this.#d&&setTimeout(()=>{this.#d?.focus(),this.#d=null},0)}endDrawingSession(t=!1){return this.#l?(this.#o.setCurrentDrawingSession(null),this.#l.abort(),this.#l=null,this.#d=null,this.#p.endDrawing(t)):null}findNewParent(t,e,s){const i=this.#o.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.#p.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove(),this.#o.getActive()?.parent===this&&(this.#o.commitOrRemove(),this.#o.setActiveEditor(null)),this.#r&&(clearTimeout(this.#r),this.#r=null);for(const t of this.#n.values())this.#t?.removePointerInTextLayer(t.contentDiv),t.setParent(null),t.isAttachedToDOM=!1,t.div.remove();this.div=null,this.#n.clear(),this.#o.removeLayer(this)}#v(){for(const t of this.#n.values())t.isEmpty()&&t.remove()}render({viewport:t}){this.viewport=t,fs(this.div,t);for(const e of this.#o.getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){this.#o.commitOrRemove(),this.#v();const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,fs(this.div,{rotation:s}),e!==s)for(const i of this.#n.values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return this.#o.viewParameters.realScale}}class zt{#t=null;#e=0;#s=new Map;#i=new Map;constructor({pageIndex:t}){this.pageIndex=t}setParent(t){if(!this.#t){this.#t=t;return}if(this.#t!==t){if(this.#s.size>0)for(const e of this.#s.values())e.remove(),t.append(e);this.#t=t}}static get _svgFactory(){return $(this,"_svgFactory",new yo)}static#r(t,[e,s,i,n]){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`}#n(){const t=zt._svgFactory.create(1,1,!0);return this.#t.append(t),t.setAttribute("aria-hidden",!0),t}#h(t,e){const s=zt._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=zt._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i}#a(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)}draw(t,e=!1,s=!1){const i=this.#e++,n=this.#n(),r=zt._svgFactory.createElement("defs");n.append(r);const o=zt._svgFactory.createElement("path");r.append(o);const h=`path_p${this.pageIndex}_${i}`;o.setAttribute("id",h),o.setAttribute("vector-effect","non-scaling-stroke"),e&&this.#i.set(i,o);const l=s?this.#h(r,h):null,c=zt._svgFactory.createElement("use");return n.append(c),c.setAttribute("href",`#${h}`),this.updateProperties(n,t),this.#s.set(i,n),{id:i,clipPathId:`url(#${l})`}}drawOutline(t,e){const s=this.#e++,i=this.#n(),n=zt._svgFactory.createElement("defs");i.append(n);const r=zt._svgFactory.createElement("path");n.append(r);const o=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",o),r.setAttribute("vector-effect","non-scaling-stroke");let h;if(e){const u=zt._svgFactory.createElement("mask");n.append(u),h=`mask_p${this.pageIndex}_${s}`,u.setAttribute("id",h),u.setAttribute("maskUnits","objectBoundingBox");const d=zt._svgFactory.createElement("rect");u.append(d),d.setAttribute("width","1"),d.setAttribute("height","1"),d.setAttribute("fill","white");const f=zt._svgFactory.createElement("use");u.append(f),f.setAttribute("href",`#${o}`),f.setAttribute("stroke","none"),f.setAttribute("fill","black"),f.setAttribute("fill-rule","nonzero"),f.classList.add("mask")}const l=zt._svgFactory.createElement("use");i.append(l),l.setAttribute("href",`#${o}`),h&&l.setAttribute("mask",`url(#${h})`);const c=l.cloneNode();return i.append(c),l.classList.add("mainOutline"),c.classList.add("secondaryOutline"),this.updateProperties(i,t),this.#s.set(s,i),s}finalizeDraw(t,e){this.#i.delete(t),this.updateProperties(t,e)}updateProperties(t,e){if(!e)return;const{root:s,bbox:i,rootClass:n,path:r}=e,o=typeof t=="number"?this.#s.get(t):t;if(o){if(s&&this.#a(o,s),i&&zt.#r(o,i),n){const{classList:h}=o;for(const[l,c]of Object.entries(n))h.toggle(l,c)}if(r){const l=o.firstChild.firstChild;this.#a(l,r)}}}updateParent(t,e){if(e===this)return;const s=this.#s.get(t);s&&(e.#t.append(s),this.#s.delete(t),e.#s.set(t,s))}remove(t){this.#i.delete(t),this.#t!==null&&(this.#s.get(t).remove(),this.#s.delete(t))}destroy(){this.#t=null;for(const t of this.#s.values())t.remove();this.#s.clear(),this.#i.clear()}}globalThis.pdfjsTestingUtils={HighlightOutliner:xo},V.AbortException,V.AnnotationEditorLayer,V.AnnotationEditorParamsType,V.AnnotationEditorType,V.AnnotationEditorUIManager,V.AnnotationLayer,V.AnnotationMode,V.ColorPicker,V.DOMSVGFactory,V.DrawLayer,V.FeatureTest;var wg=V.GlobalWorkerOptions;V.ImageKind,V.InvalidPDFException,V.MissingPDFException,V.OPS,V.OutputScale,V.PDFDataRangeTransport,V.PDFDateString,V.PDFWorker,V.PasswordResponses,V.PermissionFlag,V.PixelsPerInch,V.RenderingCancelledException,V.TextLayer,V.TouchManager,V.UnexpectedResponseException,V.Util,V.VerbosityLevel,V.XfaLayer,V.build,V.createValidAbsoluteUrl,V.fetchData;var xg=V.getDocument;V.getFilenameFromUrl,V.getPdfFilenameFromUrl,V.getXfaPageViewport,V.isDataScheme,V.isPdfFile,V.noContextMenu,V.normalizeUnicode,V.setLayerDimensions,V.shadow,V.stopEvent;var Sg=V.version;let Dl=null;function Cg(){const a=document.createElement("div");a.style.width="1in",document.body.append(a);const t=a.offsetWidth;return a.remove(),t}function Ag(){const a=Dl??Cg();return Dl=a,a/72}function Tg(a,t=500){if(typeof a!="function")throw new TypeError("The first argument is not a function.");let e=null;return function(...s){e&&clearTimeout(e),e=setTimeout(()=>{e=null,a.apply(this,s)},t)}}function Eg(a){return a.arrayBuffer?a.arrayBuffer():new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>{const i=s.result;if(!(i instanceof ArrayBuffer)){e(new Error("Failed to read file as ArrayBuffer."));return}t(i)}),s.addEventListener("error",e),s.readAsArrayBuffer(a)})}Rl()||(wg.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${Sg}/pdf.worker.min.mjs`);function Rl(){try{return typeof OffscreenCanvas<"u"&&typeof HTMLCanvasElement<"u"&&typeof HTMLCanvasElement.prototype.transferControlToOffscreen=="function"}catch{return!1}}async function kg({page:a,data:t,scale:e,password:s},i){const n=Ag()/window.devicePixelRatio,r=await Eg(t);if(Rl()){const o=new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/pdfjs.worker-DawqtvLM.js").href:new URL("assets/pdfjs.worker-DawqtvLM.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:dt&&dt.tagName.toUpperCase()==="SCRIPT"&&dt.src||new URL("pdf-canvas.umd.js",document.baseURI).href),{type:"module"});return o.postMessage({data:r,password:s,id:i,page:a,units:n,scale:e}),await new Promise(l=>{o.addEventListener("message",c=>{if(c.data.status!=="success")return;const{bitmap:u,width:d,height:f,pages:g}=c.data;if(u){const p=document.createElement("canvas"),b=p.getContext("bitmaprenderer");p.width=d,p.height=f,b?.transferFromImageBitmap(u),l({pages:g,canvas:p})}else l({pages:g,canvas:null})})})}else{const o=await xg({data:r,password:s}).promise,h=o.numPages;if(!i)return{canvas:null,pages:h};const l=await o.getPage(a),c=l.getViewport({scale:e}),u=document.createElement("canvas"),f={canvasContext:u.getContext("2d"),viewport:c,transform:[n,0,0,n,0,0]};return u.width=Math.floor(c.width*n),u.height=Math.floor(c.height*n),l.render(f).promise.then(()=>({canvas:u,pages:h}))}}const Gt=new Map;function Mg(a){const t=new Nr(a);return Gt.set(a,t),t}function Pg(a){const t=Date.now();return{PDFId:`${a.name}-${t}`,name:a.name.replace(/.pdf/,""),updateDate:t,data:a}}async function Og({src:a},t,e){if(!a||!e)return null;const{objects:s,options:i}=await cd(a),n=s.filter(o=>o!==null),r=Eu.groupSVGElements(n,i);return n.forEach(o=>{o.stroke=e}),r.hoverCursor="pointer",r.stroke=`${e}-${t}`,r}function Dg(a,t){if(!Gt.get(a))return;const s=1/3,i=Bg(t,s);Fl(a,i,s)}async function Rg(a,t){const e=Date.now(),i={PDFId:`${a.name}-${e}`,name:a.name.replace(/.png|.jpg|.jpeg/,""),updateDate:e,data:a};return t&&Ll(t,{data:a}),{...i,pages:1}}async function Ll(a,{data:t,scale:e=.5}){if(!Gt.get(a))return;const i=URL.createObjectURL(t),n=await Mt.fromURL(i);n.scale(e),Fl(a,n,e),URL.revokeObjectURL(i)}function Fl(a,t,e){const s=Gt.get(a);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function Lg(a,t){if(!t)return;const{oCoords:e}=a;if(!e)return;const{x:s,y:i}=e.tl.touchCorner.tl,{height:n,width:r,scaleY:o,scaleX:h}=t;t.top=i-n*o/2,t.left=s-r*h/2,t.setCoords()}function Fg(a,t,e){!e||!a||(e.scale(1/t),Lg(a,e))}function Ig(a,t){if(!a)return;const e=a._cornerSize||6;a.borderScaleFactor=1/t,a.cornerSize=e*(1/t),a.touchCornerSize=e*4*(1/t),a.setCoords()}function Ng(a){const t=Gt.get(a);t&&(t.discardActiveObject(),t.renderAll())}function jg(a){const t=Gt.get(a);t&&(t.clear(),Gt.delete(a))}function Bg(a,t){return new Mt(a,{scaleX:t,scaleY:t})}function Eo(a,t){if(!t)return;const{left:e,top:s,scaleX:i,scaleY:n,width:r,height:o}=a,h=t.x*r*i,l=t.y*o*n;a.set({left:e-h,top:s-l})}function Il(a,t,e){const s=a.type;return{"application/pdf":Hg,"image/png":jl,"image/jpeg":jl}[s]?.(a,t,e)??Promise.reject(new Error(`Unsupported ${s} file type.`))}async function Hg(a,t,e){const s=Pg(a),i=await Nl({page:1,data:a,scale:.8,password:t},e);return{...s,pages:i}}function Nl(a,t){return kg(a,t).then(({canvas:e,pages:s})=>(e&&t&&Dg(t,e),s))}async function jl(a,t,e){return await Rg(a,e)}function zg(a,t){const e=Gt.get(a);if(!e)return;const s=e.getActiveObject();s&&(s instanceof Jt?s.forEachObject(i=>{i.set(t)}):s.set(t),e.renderAll())}async function Gg(a,t){const e=Gt.get(a);if(!e)return;const s=e?.getActiveObject();if(!s)return;const i=await s.clone(Wl);i instanceof Jt?i.forEachObject(n=>{e.add(n),t(e,n)}):(e.add(i),t(e,i)),Eo(i,{x:-.1,y:-.1}),e.setActiveObject(i)}function Vg(a){const t=Gt.get(a);if(!t)return;const e=t.getActiveObject();e&&(e instanceof Jt?(e.forEachObject(s=>{t.remove(s)}),t.discardActiveObject()):t.remove(e))}function Bl(a){const{id:t="",selectionOptions:e,pointerDown:s,pointerMove:i,pointerUp:n,selectionCreated:r,selectionCleared:o}=a||{};let h=null,l=null,c=1,u={...Xl};function d(){if(!t||Gt.has(t))return;const k=Mg(t);return k.on("selection:created",O=>{if(r?.(O),O.selected.length<=1)return;const j=k.getActiveObject();j&&(l=j,e?.value&&l.set(e.value),l._cornerSize=l.cornerSize,S(c))}),k.on("selection:cleared",O=>{o?.(O),T(k)}),s&&k.on("mouse:down",s),i&&k.on("mouse:move",i),n&&k.on("mouse:up",n),k}function f(k,O){return Il(k,O,t)}function g(k){return Nl(k,t)}function p({data:k,scale:O=.5}){return Ll(t,{data:k,scale:O})}async function b(k,O,j){const M=Gt.get(t);if(!M)return;const R=await Mt.fromURL(k,{},{...$n,...O});Eo(R,j),M.add(R),v(M,R),M.setActiveObject(R)}function m(k,O,j){const M=Gt.get(t);if(!M)return;const R=new kt(k,{...Gl,...O});Eo(R,j),M.add(R),v(M,R),M.setActiveObject(R)}function v(k,O){O.on("selected",j=>y({canvas:k,target:j.target})),O.on("modified",j=>y({canvas:k,target:j.target})),O.on("scaling",()=>T(k)),O.on("moving",()=>T(k)),O.on("rotating",()=>T(k)),O._cornerSize=O._cornerSize??O.cornerSize}async function y({canvas:k,target:O,stroke:j=u.stroke,uuid:M=Date.now()}){if(k.getActiveObjects().length>1||h?.stroke===`${j}-${M}`)return;const G=await Og(u,M,j);T(k),h=G,l=O,_(k,O,M),S(c,!0),G&&k.add(G)}function _(k,O,j){h&&(h.on("selected",()=>{k.remove(O),T(k)}),h.on("mouseover",()=>{y({canvas:k,target:O,stroke:u.hoverStroke,uuid:j})}),h.on("mouseout",()=>{y({canvas:k,target:O,stroke:u.stroke,uuid:j})}))}function S(k,O=!1){const j=Gt.get(t);c=k,j&&(Ig(l,k),Fg(l,k,h),!O&&j.renderAll())}function A(k){if(!k)return;u={...u,...k};const O=Gt.get(t);!h||!l||!O||y({target:l,canvas:O})}function T(k){l=null,h&&(k.remove(h),h=null)}function E(){Ng(t)}function P(){jg(t)}function N(k){zg(t,k)}function D(){return Gg(t,v)}function L(){Vg(t)}return{createCanvas:d,loadFile:f,specifyPage:g,renderImage:p,addFabric:b,addTextFabric:m,clearActive:E,deleteCanvas:P,scaleFabric:S,setCloseSvgOptions:A,setActiveFabric:N,copyActiveFabric:D,deleteActiveFabric:L}}function Xg(a){let t=0;const e=Tg(()=>{t!==window.innerWidth&&(t=window.innerWidth,a())});W.onMounted(()=>{window.addEventListener("resize",e)}),W.onBeforeUnmount(()=>{window.removeEventListener("resize",e)})}const Wg=W.defineComponent({__name:"pdf-canvas",props:{file:{},page:{default:1},canvasId:{default:"PDF-canvas"},fileZoom:{default:1},fileScale:{default:1},canvasScale:{default:1},canvasClass:{default:""},isDrop:{type:Boolean,default:!1},password:{},dropTextOptions:{},dropImageOptions:{},selectionOptions:{},closeSvgOptions:{},manualReload:{type:Boolean},onDestroy:{type:Function,default:W.onBeforeUnmount}},emits:["loaded","reload","pointerDown","pointerMove","pointerUp","selectionCreated","selectionCleared"],setup(a,{expose:t,emit:e}){const s=a,i=e,{onDestroy:n}=s,r=W.ref(null),o=`${s.canvasId}-${s.page-1}`,h=W.computed(()=>s.fileZoom*s.canvasScale),l=W.computed(()=>({...Vl,...s.selectionOptions})),{createCanvas:c,specifyPage:u,addFabric:d,addTextFabric:f,renderImage:g,clearActive:p,deleteCanvas:b,scaleFabric:m,setActiveFabric:v,setCloseSvgOptions:y,copyActiveFabric:_,deleteActiveFabric:S}=Bl({id:o,selectionOptions:l,pointerDown:D=>i("pointerDown",D),pointerMove:D=>i("pointerMove",D),pointerUp:D=>i("pointerUp",D),selectionCreated:D=>i("selectionCreated",D),selectionCleared:D=>i("selectionCleared",D)});A(),Xg(N);async function A(){const{file:D,page:L,fileScale:k}=s;globalThis.requestAnimationFrame(async()=>{if(await W.nextTick(),c(),D.data?.type.startsWith("image/")){const j=D.data;j&&g({data:j,scale:k/3}),i("loaded");return}D.data&&await u({page:L,data:D.data,scale:k,password:s.password}),i("loaded")})}function T(D){if(!s.isDrop||!D.dataTransfer)return;const{dataTransfer:L,offsetX:k,offsetY:O}=D,j=L.getData("text/plain"),M=L.getData("text/uri-list"),R=L.getData("custom/offset"),G=R?JSON.parse(R):null,at={top:O,left:k},ct={x:G?.offsetX??0,y:G?.offsetY??0};M?E(M,at,ct):j&&P(j,at,ct)}function E(D,L,k){d(D,{...s.dropImageOptions,...L},k)}function P(D,L,k){f(D,{...s.dropTextOptions,...L},k)}function N(){s.manualReload||A(),i("reload")}return W.watch([()=>s.fileScale,()=>s.page,()=>s.file,()=>s.password],N),W.watch(h,D=>m(D),{immediate:!0}),W.watch(()=>s.closeSvgOptions,y,{immediate:!0}),n(b),t({reload:A,addImage:E,addText:P,clearActive:p,deleteCanvas:b,setActiveFabric:v,copyActiveFabric:_,deleteActiveFabric:S,canvasRef:r}),(D,L)=>(W.openBlock(),W.createElementBlock("div",{style:W.normalizeStyle({transform:`scale(${h.value})`}),onDragover:L[0]||(L[0]=W.withModifiers(()=>{},["prevent"])),onDragenter:L[1]||(L[1]=W.withModifiers(()=>{},["prevent"])),onDrop:W.withModifiers(T,["stop","prevent"])},[W.createElementVNode("canvas",{id:o,ref_key:"canvasRef",ref:r,class:W.normalizeClass(a.canvasClass)},null,2)],36))}});J.default=Wg,J.loadFile=Il,J.useFabric=Bl,Object.defineProperties(J,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
515
+ `)){const r=document.createElement("div");r.append(n?document.createTextNode(n):document.createElement("br")),e.append(r)}const i=Ct._internalPadding*this.parentScale;return t.updateEdited({rect:this.getRect(i,i),popupContent:this.#e}),e}resetAnnotationElement(t){super.resetAnnotationElement(t),t.resetEdited()}}class I{static PRECISION=1e-4;toSVGPath(){st("Abstract method `toSVGPath` must be implemented.")}get box(){st("Abstract getter `box` must be implemented.")}serialize(t,e){st("Abstract method `serialize` must be implemented.")}static _rescale(t,e,s,i,n,r){r||=new Float32Array(t.length);for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o]*i,r[o+1]=s+t[o+1]*n;return r}static _rescaleAndSwap(t,e,s,i,n,r){r||=new Float32Array(t.length);for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o+1]*i,r[o+1]=s+t[o]*n;return r}static _translate(t,e,s,i){i||=new Float32Array(t.length);for(let n=0,r=t.length;n<r;n+=2)i[n]=e+t[n],i[n+1]=s+t[n+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,s,i,n){switch(n){case 90:return[1-e/s,t/i];case 180:return[1-t/s,1-e/i];case 270:return[e/s,1-t/i];default:return[t/s,e/i]}}static _normalizePagePoint(t,e,s){switch(s){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,s,i,n,r){return[(t+5*s)/6,(e+5*i)/6,(5*s+n)/6,(5*i+r)/6,(s+n)/2,(i+r)/2]}}class ms{#t;#e=[];#s;#i;#r=[];#n=new Float32Array(18);#h;#a;#c;#l;#d;#u;#f=[];static#o=8;static#g=2;static#m=ms.#o+ms.#g;constructor({x:t,y:e},s,i,n,r,o=0){this.#t=s,this.#u=n*i,this.#i=r,this.#n.set([NaN,NaN,NaN,NaN,t,e],6),this.#s=o,this.#l=ms.#o*i,this.#c=ms.#m*i,this.#d=i,this.#f.push(t,e)}isEmpty(){return isNaN(this.#n[8])}#p(){const 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.#a+(t[1]-e[1])/2-i)/r,(this.#h+(e[0]-t[0])/2-s)/n,(this.#a+(e[1]-t[1])/2-i)/r]}add({x:t,y:e}){this.#h=t,this.#a=e;const[s,i,n,r]=this.#t;let[o,h,l,c]=this.#n.subarray(8,12);const u=t-l,d=e-c,f=Math.hypot(u,d);if(f<this.#c)return!1;const g=f-this.#l,p=g/f,b=p*u,m=p*d;let v=o,y=h;o=l,h=c,l+=b,c+=m,this.#f?.push(t,e);const _=-m/g,S=b/g,A=_*this.#u,T=S*this.#u;return this.#n.set(this.#n.subarray(2,8),0),this.#n.set([l+A,c+T],4),this.#n.set(this.#n.subarray(14,18),12),this.#n.set([l-A,c-T],16),isNaN(this.#n[6])?(this.#r.length===0&&(this.#n.set([o+A,h+T],2),this.#r.push(NaN,NaN,NaN,NaN,(o+A-s)/n,(h+T-i)/r),this.#n.set([o-A,h-T],14),this.#e.push(NaN,NaN,NaN,NaN,(o-A-s)/n,(h-T-i)/r)),this.#n.set([v,y,o,h,l,c],6),!this.isEmpty()):(this.#n.set([v,y,o,h,l,c],6),Math.abs(Math.atan2(y-h,v-o)-Math.atan2(m,b))<Math.PI/2?([o,h,l,c]=this.#n.subarray(2,6),this.#r.push(NaN,NaN,NaN,NaN,((o+l)/2-s)/n,((h+c)/2-i)/r),[o,h,v,y]=this.#n.subarray(14,18),this.#e.push(NaN,NaN,NaN,NaN,((v+o)/2-s)/n,((y+h)/2-i)/r),!0):([v,y,o,h,l,c]=this.#n.subarray(0,6),this.#r.push(((v+5*o)/6-s)/n,((y+5*h)/6-i)/r,((5*o+l)/6-s)/n,((5*h+c)/6-i)/r,((o+l)/2-s)/n,((h+c)/2-i)/r),[l,c,o,h,v,y]=this.#n.subarray(12,18),this.#e.push(((v+5*o)/6-s)/n,((y+5*h)/6-i)/r,((5*o+l)/6-s)/n,((5*h+c)/6-i)/r,((o+l)/2-s)/n,((h+c)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=this.#r,e=this.#e;if(isNaN(this.#n[6])&&!this.isEmpty())return this.#b();const s=[];s.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?s.push(`L${t[i+4]} ${t[i+5]}`):s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);this.#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.#_(s),s.join(" ")}#b(){const[t,e,s,i]=this.#t,[n,r,o,h]=this.#p();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${o} ${h} L${(this.#n[16]-t)/s} ${(this.#n[17]-e)/i} L${(this.#n[14]-t)/s} ${(this.#n[15]-e)/i} Z`}#_(t){const e=this.#e;t.push(`L${e[4]} ${e[5]} Z`)}#v(t){const[e,s,i,n]=this.#t,r=this.#n.subarray(4,6),o=this.#n.subarray(16,18),[h,l,c,u]=this.#p();t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${h} ${l} L${c} ${u} L${(o[0]-e)/i} ${(o[1]-s)/n}`)}newFreeDrawOutline(t,e,s,i,n,r){return new Ol(t,e,s,i,n,r)}getOutlines(){const t=this.#r,e=this.#e,s=this.#n,[i,n,r,o]=this.#t,h=new Float32Array((this.#f?.length??0)+2);for(let u=0,d=h.length-2;u<d;u+=2)h[u]=(this.#f[u]-i)/r,h[u+1]=(this.#f[u+1]-n)/o;if(h[h.length-2]=(this.#h-i)/r,h[h.length-1]=(this.#a-n)/o,isNaN(s[6])&&!this.isEmpty())return this.#w(h);const l=new Float32Array(this.#r.length+24+this.#e.length);let c=t.length;for(let u=0;u<c;u+=2){if(isNaN(t[u])){l[u]=l[u+1]=NaN;continue}l[u]=t[u],l[u+1]=t[u+1]}c=this.#A(l,c);for(let u=e.length-6;u>=6;u-=6)for(let d=0;d<6;d+=2){if(isNaN(e[u+d])){l[c]=l[c+1]=NaN,c+=2;continue}l[c]=e[u+d],l[c+1]=e[u+d+1],c+=2}return this.#S(l,c),this.newFreeDrawOutline(l,h,this.#t,this.#d,this.#s,this.#i)}#w(t){const e=this.#n,[s,i,n,r]=this.#t,[o,h,l,c]=this.#p(),u=new Float32Array(36);return u.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,o,h,NaN,NaN,NaN,NaN,l,c,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(u,t,this.#t,this.#d,this.#s,this.#i)}#S(t,e){const s=this.#e;return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6}#A(t,e){const s=this.#n.subarray(4,6),i=this.#n.subarray(16,18),[n,r,o,h]=this.#t,[l,c,u,d]=this.#p();return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/o,(s[1]-r)/h,NaN,NaN,NaN,NaN,l,c,NaN,NaN,NaN,NaN,u,d,NaN,NaN,NaN,NaN,(i[0]-n)/o,(i[1]-r)/h],e),e+=24}}class Ol extends I{#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.#a(r);const[o,h,l,c]=this.#e;for(let u=0,d=t.length;u<d;u+=2)t[u]=(t[u]-o)/l,t[u+1]=(t[u+1]-h)/c;for(let u=0,d=e.length;u<d;u+=2)e[u]=(e[u]-o)/l,e[u+1]=(e[u+1]-h)/c}toSVGPath(){const t=[`M${this.#h[4]} ${this.#h[5]}`];for(let e=6,s=this.#h.length;e<s;e+=6){if(isNaN(this.#h[e])){t.push(`L${this.#h[e+4]} ${this.#h[e+5]}`);continue}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){const r=s-t,o=i-e;let h,l;switch(n){case 0:h=I._rescale(this.#h,t,i,r,-o),l=I._rescale(this.#r,t,i,r,-o);break;case 90:h=I._rescaleAndSwap(this.#h,t,e,r,o),l=I._rescaleAndSwap(this.#r,t,e,r,o);break;case 180:h=I._rescale(this.#h,s,e,-r,o),l=I._rescale(this.#r,s,e,-r,o);break;case 270:h=I._rescaleAndSwap(this.#h,s,i,-r,-o),l=I._rescaleAndSwap(this.#r,s,i,-r,-o);break}return{outline:Array.from(h),points:[Array.from(l)]}}#a(t){const e=this.#h;let s=e[4],i=e[5],n=s,r=i,o=s,h=i,l=s,c=i;const u=t?Math.max:Math.min;for(let f=6,g=e.length;f<g;f+=6){if(isNaN(e[f]))n=Math.min(n,e[f+4]),r=Math.min(r,e[f+5]),o=Math.max(o,e[f+4]),h=Math.max(h,e[f+5]),c<e[f+5]?(l=e[f+4],c=e[f+5]):c===e[f+5]&&(l=u(l,e[f+4]));else{const p=B.bezierBoundingBox(s,i,...e.slice(f,f+6));n=Math.min(n,p[0]),r=Math.min(r,p[1]),o=Math.max(o,p[2]),h=Math.max(h,p[3]),c<p[3]?(l=p[2],c=p[3]):c===p[3]&&(l=u(l,p[2]))}s=e[f+4],i=e[f+5]}const d=this.#e;d[0]=n-this.#s,d[1]=r-this.#s,d[2]=o-n+2*this.#s,d[3]=h-r+2*this.#s,this.lastPoint=[l,c]}get box(){return this.#e}newOutliner(t,e,s,i,n,r=0){return new ms(t,e,s,i,n,r)}getNewOutline(t,e){const[s,i,n,r]=this.#e,[o,h,l,c]=this.#t,u=n*l,d=r*c,f=s*l+o,g=i*c+h,p=this.newOutliner({x:this.#r[0]*u+f,y:this.#r[1]*d+g},this.#t,this.#n,t,this.#i,e??this.#s);for(let b=2;b<this.#r.length;b+=2)p.add({x:this.#r[b]*u+f,y:this.#r[b+1]*d+g});return p.getOutlines()}}class xo{#t;#e;#s=[];#i=[];constructor(t,e=0,s=0,i=!0){let n=1/0,r=-1/0,o=1/0,h=-1/0;const l=10**-4;for(const{x:b,y:m,width:v,height:y}of t){const _=Math.floor((b-e)/l)*l,S=Math.ceil((b+v+e)/l)*l,A=Math.floor((m-e)/l)*l,T=Math.ceil((m+y+e)/l)*l,E=[_,A,T,!0],P=[S,A,T,!1];this.#s.push(E,P),n=Math.min(n,_),r=Math.max(r,S),o=Math.min(o,A),h=Math.max(h,T)}const c=r-n+2*s,u=h-o+2*s,d=n-s,f=o-s,g=this.#s.at(i?-1:-2),p=[g[0],g[2]];for(const b of this.#s){const[m,v,y]=b;b[0]=(m-d)/c,b[1]=(v-f)/u,b[2]=(y-f)/u}this.#t=new Float32Array([d,f,c,u]),this.#e=p}getOutlines(){this.#s.sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of this.#s)e[3]?(t.push(...this.#c(e)),this.#h(e)):(this.#a(e),t.push(...this.#c(e)));return this.#r(t)}#r(t){const e=[],s=new Set;for(const r of t){const[o,h,l]=r;e.push([o,h,r],[o,l,r])}e.sort((r,o)=>r[1]-o[1]||r[0]-o[0]);for(let r=0,o=e.length;r<o;r+=2){const h=e[r][2],l=e[r+1][2];h.push(l),l.push(h),s.add(h),s.add(l)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[o,h,l,c,u]=r;s.delete(r);let d=o,f=h;for(n=[o,l],i.push(n);;){let g;if(s.has(c))g=c;else if(s.has(u))g=u;else break;s.delete(g),[o,h,l,c,u]=g,d!==o&&(n.push(d,f,o,f===h?h:l),d=o),f=f===h?l:h}n.push(d,f)}return new bg(i,this.#t,this.#e)}#n(t){const e=this.#i;let s=0,i=e.length-1;for(;s<=i;){const n=s+i>>1,r=e[n][0];if(r===t)return n;r<t?s=n+1:i=n-1}return i+1}#h([,t,e]){const s=this.#n(t);this.#i.splice(s,0,[t,e])}#a([,t,e]){const s=this.#n(t);for(let i=s;i<this.#i.length;i++){const[n,r]=this.#i[i];if(n!==t)break;if(n===t&&r===e){this.#i.splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=this.#i[i];if(n!==t)break;if(n===t&&r===e){this.#i.splice(i,1);return}}}#c(t){const[e,s,i]=t,n=[[e,s,i]],r=this.#n(i);for(let o=0;o<r;o++){const[h,l]=this.#i[o];for(let c=0,u=n.length;c<u;c++){const[,d,f]=n[c];if(!(l<=d||f<=h)){if(d>=h){if(f>l)n[c][1]=l;else{if(u===1)return[];n.splice(c,1),c--,u--}continue}n[c][2]=h,f>l&&n.push([e,l,f])}}}return n}}class bg extends I{#t;#e;constructor(t,e,s){super(),this.#e=t,this.#t=e,this.lastPoint=s}toSVGPath(){const t=[];for(const e of this.#e){let[s,i]=e;t.push(`M${s} ${i}`);for(let n=2;n<e.length;n+=2){const r=e[n],o=e[n+1];r===s?(t.push(`V${o}`),i=o):o===i&&(t.push(`H${r}`),s=r)}t.push("Z")}return t.join(" ")}serialize([t,e,s,i],n){const r=[],o=s-t,h=i-e;for(const l of this.#e){const c=new Array(l.length);for(let u=0;u<l.length;u+=2)c[u]=t+l[u]*o,c[u+1]=i-l[u+1]*h;r.push(c)}return r}get box(){return this.#t}get classNamesForOutlining(){return["highlightOutline"]}}class So extends ms{newFreeDrawOutline(t,e,s,i,n,r){return new vg(t,e,s,i,n,r)}}class vg extends Ol{newOutliner(t,e,s,i,n,r=0){return new So(t,e,s,i,n,r)}}class ne{#t=null;#e=null;#s;#i=null;#r=!1;#n=!1;#h=null;#a;#c=null;#l=null;#d;static#u=null;static get _keyboardManager(){return $(this,"_keyboardManager",new pi([[["Escape","mac+Escape"],ne.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],ne.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],ne.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],ne.prototype._moveToPrevious],[["Home","mac+Home"],ne.prototype._moveToBeginning],[["End","mac+End"],ne.prototype._moveToEnd]]))}constructor({editor:t=null,uiManager:e=null}){t?(this.#n=!1,this.#d=q.HIGHLIGHT_COLOR,this.#h=t):(this.#n=!0,this.#d=q.HIGHLIGHT_DEFAULT_COLOR),this.#l=t?._uiManager||e,this.#a=this.#l._eventBus,this.#s=t?.color||this.#l?.highlightColors.values().next().value||"#FFFF98",ne.#u||=Object.freeze({blue:"pdfjs-editor-colorpicker-blue",green:"pdfjs-editor-colorpicker-green",pink:"pdfjs-editor-colorpicker-pink",red:"pdfjs-editor-colorpicker-red",yellow:"pdfjs-editor-colorpicker-yellow"})}renderButton(){const t=this.#t=document.createElement("button");t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);const e=this.#l._signal;t.addEventListener("click",this.#m.bind(this),{signal:e}),t.addEventListener("keydown",this.#g.bind(this),{signal:e});const s=this.#e=document.createElement("span");return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=this.#s,t.append(s),t}renderMainDropdown(){const t=this.#i=this.#f();return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}#f(){const t=document.createElement("div"),e=this.#l._signal;t.addEventListener("contextmenu",ge,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[s,i]of this.#l.highlightColors){const n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",ne.#u[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===this.#s),n.addEventListener("click",this.#o.bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",this.#g.bind(this),{signal:e}),t}#o(t,e){e.stopPropagation(),this.#a.dispatch("switchannotationeditorparams",{source:this,type:this.#d,value:t})}_colorSelectFromKeyboard(t){if(t.target===this.#t){this.#m(t);return}const e=t.target.getAttribute("data-color");e&&this.#o(e,t)}_moveToNext(t){if(!this.#b){this.#m(t);return}if(t.target===this.#t){this.#i.firstChild?.focus();return}t.target.nextSibling?.focus()}_moveToPrevious(t){if(t.target===this.#i?.firstChild||t.target===this.#t){this.#b&&this._hideDropdownFromKeyboard();return}this.#b||this.#m(t),t.target.previousSibling?.focus()}_moveToBeginning(t){if(!this.#b){this.#m(t);return}this.#i.firstChild?.focus()}_moveToEnd(t){if(!this.#b){this.#m(t);return}this.#i.lastChild?.focus()}#g(t){ne._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.#p.bind(this),{signal:this.#l.combinedSignal(this.#c)})),this.#i){this.#i.classList.remove("hidden");return}const e=this.#i=this.#f();this.#t.append(e)}#p(t){this.#i?.contains(t.target)||this.hideDropdown()}hideDropdown(){this.#i?.classList.add("hidden"),this.#c?.abort(),this.#c=null}get#b(){return this.#i&&!this.#i.classList.contains("hidden")}_hideDropdownFromKeyboard(){if(!this.#n){if(!this.#b){this.#h?.unselect();return}this.hideDropdown(),this.#t.focus({preventScroll:!0,focusVisible:this.#r})}}updateColor(t){if(this.#e&&(this.#e.style.backgroundColor=t),!this.#i)return;const e=this.#l.highlightColors.values();for(const s of this.#i.children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){this.#t?.remove(),this.#t=null,this.#e=null,this.#i?.remove(),this.#i=null}}class mt extends H{#t=null;#e=0;#s;#i=null;#r=null;#n=null;#h=null;#a=0;#c=null;#l=null;#d=null;#u=!1;#f=null;#o;#g=null;#m="";#p;#b="";static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type="highlight";static _editorType=U.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId="";static get _keyboardManager(){const t=mt.prototype;return $(this,"_keyboardManager",new pi([[["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||mt._defaultColor,this.#p=t.thickness||mt._defaultThickness,this.#o=t.opacity||mt._defaultOpacity,this.#s=t.boxes||null,this.#b=t.methodOfCreation||"",this.#m=t.text||"",this._isDraggable=!1,t.highlightId>-1?(this.#u=!0,this.#v(t),this.#M()):this.#s&&(this.#t=t.anchorNode,this.#e=t.anchorOffset,this.#h=t.focusNode,this.#a=t.focusOffset,this.#_(),this.#M(),this.rotate(this.rotation))}get telemetryInitialData(){return{action:"added",type:this.#u?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:this.#p,methodOfCreation:this.#b}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(t){return{numberOfColors:t.get("color").size}}#_(){const t=new xo(this.#s,.001);this.#l=t.getOutlines(),[this.x,this.y,this.width,this.height]=this.#l.box;const e=new xo(this.#s,.0025,.001,this._uiManager.direction==="ltr");this.#n=e.getOutlines();const{lastPoint:s}=this.#n;this.#f=[(s[0]-this.x)/this.width,(s[1]-this.y)/this.height]}#v({highlightOutlines:t,highlightId:e,clipPathId:s}){this.#l=t;const i=1.5;if(this.#n=t.getNewOutline(this.#p/2+i,.0025),e>=0)this.#d=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){const c=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#d,{bbox:mt.#x(this.#l.box,(c-this.rotation+360)%360),path:{d:t.toSVGPath()}}),this.parent.drawLayer.updateProperties(this.#g,{bbox:mt.#x(this.#n.box,c),path:{d:this.#n.toSVGPath()}})}const[n,r,o,h]=t.box;switch(this.rotation){case 0:this.x=n,this.y=r,this.width=o,this.height=h;break;case 90:{const[c,u]=this.parentDimensions;this.x=r,this.y=1-n,this.width=o*u/c,this.height=h*c/u;break}case 180:this.x=1-n,this.y=1-r,this.width=o,this.height=h;break;case 270:{const[c,u]=this.parentDimensions;this.x=1-r,this.y=n,this.width=o*u/c,this.height=h*c/u;break}}const{lastPoint:l}=this.#n;this.#f=[(l[0]-n)/o,(l[1]-r)/h]}static initialize(t,e){H.initialize(t,e),mt._defaultColor||=e.highlightColors?.values().next().value||"#fff066"}static updateDefaultParams(t,e){switch(t){case q.HIGHLIGHT_DEFAULT_COLOR:mt._defaultColor=e;break;case q.HIGHLIGHT_THICKNESS:mt._defaultThickness=e;break}}translateInPage(t,e){}get toolbarPosition(){return this.#f}updateParams(t,e){switch(t){case q.HIGHLIGHT_COLOR:this.#w(e);break;case q.HIGHLIGHT_THICKNESS:this.#S(e);break}}static get defaultPropertiesToUpdate(){return[[q.HIGHLIGHT_DEFAULT_COLOR,mt._defaultColor],[q.HIGHLIGHT_THICKNESS,mt._defaultThickness]]}get propertiesToUpdate(){return[[q.HIGHLIGHT_COLOR,this.color||mt._defaultColor],[q.HIGHLIGHT_THICKNESS,this.#p||mt._defaultThickness],[q.HIGHLIGHT_FREE,this.#u]]}#w(t){const e=(n,r)=>{this.color=n,this.#o=r,this.parent?.drawLayer.updateProperties(this.#d,{root:{fill:n,"fill-opacity":r}}),this.#r?.updateColor(n)},s=this.color,i=this.#o;this.addCommands({cmd:e.bind(this,t,mt._defaultOpacity),undo:e.bind(this,s,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:q.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(t)},!0)}#S(t){const e=this.#p,s=i=>{this.#p=i,this.#A(i)};this.addCommands({cmd:s.bind(this,t),undo:s.bind(this,e),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:q.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:t},!0)}async addEditToolbar(){const t=await super.addEditToolbar();return t?(this._uiManager.highlightColors&&(this.#r=new 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.#O())}getBaseTranslation(){return[0,0]}getRect(t,e){return super.getRect(t,e,this.#O())}onceAdded(t){this.annotationElementId||this.parent.addUndoableEditor(this),t&&this.div.focus()}remove(){this.#E(),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#M(),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){let e=!1;this.parent&&!t?this.#E():t&&(this.#M(t),e=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(t),this.show(this._isVisible),e&&this.select()}#A(t){if(!this.#u)return;this.#v({highlightOutlines:this.#l.getNewOutline(t/2)}),this.fixAndSetPosition();const[e,s]=this.parentDimensions;this.setDims(this.width*e,this.height*s)}#E(){this.#d===null||!this.parent||(this.parent.drawLayer.remove(this.#d),this.#d=null,this.parent.drawLayer.remove(this.#g),this.#g=null)}#M(t=this.parent){this.#d===null&&({id:this.#d,clipPathId:this.#i}=t.drawLayer.draw({bbox:this.#l.box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":this.#o},rootClass:{highlight:!0,free:this.#u},path:{d:this.#l.toSVGPath()}},!1,!0),this.#g=t.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#u},bbox:this.#n.box,path:{d:this.#n.toSVGPath()}},this.#u),this.#c&&(this.#c.style.clipPath=this.#i))}static#x([t,e,s,i],n){switch(n){case 90:return[1-e-i,t,i,s];case 180:return[1-t-s,1-e-i,s,i];case 270:return[e,1-t-s,i,s]}return[t,e,s,i]}rotate(t){const{drawLayer:e}=this.parent;let s;this.#u?(t=(t-this.rotation+360)%360,s=mt.#x(this.#l.box,t)):s=mt.#x([this.x,this.y,this.width,this.height],t),e.updateProperties(this.#d,{bbox:s,root:{"data-main-rotation":t}}),e.updateProperties(this.#g,{bbox:mt.#x(this.#n.box,t),root:{"data-main-rotation":t}})}render(){if(this.div)return this.div;const t=super.render();this.#m&&(t.setAttribute("aria-label",this.#m),t.setAttribute("role","mark")),this.#u?t.classList.add("free"):this.div.addEventListener("keydown",this.#k.bind(this),{signal:this._uiManager._signal});const e=this.#c=document.createElement("div");t.append(e),e.setAttribute("aria-hidden","true"),e.className="internal",e.style.clipPath=this.#i;const[s,i]=this.parentDimensions;return this.setDims(this.width*s,this.height*i),Ln(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){mt._keyboardManager.exec(this,t)}_moveCaret(t){switch(this.parent.unselect(this),t){case 0:case 2:this.#T(!0);break;case 1:case 3:this.#T(!1);break}}#T(t){if(!this.#t)return;const e=window.getSelection();t?e.setPosition(this.#t,this.#e):e.setPosition(this.#h,this.#a)}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.#u||this.#T(!1))}get _mustFixPosition(){return!this.#u}show(t=this._isVisible){super.show(t),this.parent&&(this.parent.drawLayer.updateProperties(this.#d,{rootClass:{hidden:!t}}),this.parent.drawLayer.updateProperties(this.#g,{rootClass:{hidden:!t}}))}#O(){return this.#u?this.rotation:0}#L(){if(this.#u)return null;const[t,e]=this.pageDimensions,[s,i]=this.pageTranslation,n=this.#s,r=new Float32Array(n.length*8);let o=0;for(const{x:h,y:l,width:c,height:u}of n){const d=h*t+s,f=(1-l)*e+i;r[o]=r[o+4]=d,r[o+1]=r[o+3]=f,r[o+2]=r[o+6]=d+c*t,r[o+5]=r[o+7]=f-u*e,o+=8}return r}#I(t){return this.#l.serialize(t,this.#O())}static startHighlighting(t,e,{target:s,x:i,y:n}){const{x:r,y:o,width:h,height:l}=s.getBoundingClientRect(),c=new AbortController,u=t.combinedSignal(c),d=f=>{c.abort(),this.#y(t,f)};window.addEventListener("blur",d,{signal:u}),window.addEventListener("pointerup",d,{signal:u}),window.addEventListener("pointerdown",te,{capture:!0,passive:!1,signal:u}),window.addEventListener("contextmenu",ge,{signal:u}),s.addEventListener("pointermove",this.#C.bind(this,t),{signal:u}),this._freeHighlight=new So({x:i,y:n},[r,o,h,l],t.scale,this._defaultThickness/2,e,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=t.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static#C(t,e){this._freeHighlight.add(e)&&t.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#y(t,e){this._freeHighlight.isEmpty()?t.drawLayer.remove(this._freeHighlightId):t.createAndAddNewEditor(e,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""}static async deserialize(t,e,s){let i=null;if(t instanceof Ml){const{data:{quadPoints:g,rect:p,rotation:b,id:m,color:v,opacity:y,popupRef:_},parent:{page:{pageNumber:S}}}=t;i=t={annotationType:U.HIGHLIGHT,color:Array.from(v),opacity:y,quadPoints:g,boxes:null,pageIndex:S-1,rect:p.slice(0),rotation:b,id:m,deleted:!1,popupRef:_}}else if(t instanceof wo){const{data:{inkLists:g,rect:p,rotation:b,id:m,color:v,borderStyle:{rawWidth:y},popupRef:_},parent:{page:{pageNumber:S}}}=t;i=t={annotationType:U.HIGHLIGHT,color:Array.from(v),thickness:y,inkLists:g,boxes:null,pageIndex:S-1,rect:p.slice(0),rotation:b,id:m,deleted:!1,popupRef:_}}const{color:n,quadPoints:r,inkLists:o,opacity:h}=t,l=await super.deserialize(t,e,s);l.color=B.makeHexColor(...n),l.#o=h||1,o&&(l.#p=t.thickness),l.annotationElementId=t.id||null,l._initialData=i;const[c,u]=l.pageDimensions,[d,f]=l.pageTranslation;if(r){const g=l.#s=[];for(let p=0;p<r.length;p+=8)g.push({x:(r[p]-d)/c,y:1-(r[p+1]-f)/u,width:(r[p+2]-r[p])/c,height:(r[p+1]-r[p+5])/u});l.#_(),l.#M(),l.rotate(l.rotation)}else if(o){l.#u=!0;const g=o[0],p={x:g[0]-d,y:u-(g[1]-f)},b=new So(p,[0,0,c,u],1,l.#p/2,!0,.001);for(let y=0,_=g.length;y<_;y+=2)p.x=g[y]-d,p.y=u-(g[y+1]-f),b.add(p);const{id:m,clipPathId:v}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:l.color,"fill-opacity":l._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:b.toSVGPath()}},!0,!0);l.#v({highlightOutlines:b.getOutlines(),highlightId:m,clipPathId:v}),l.#M()}return l}serialize(t=!1){if(this.isEmpty()||t)return null;if(this.deleted)return this.serializeDeleted();const e=this.getRect(0,0),s=H._colorManager.convert(this.color),i={annotationType:U.HIGHLIGHT,color:s,opacity:this.#o,thickness:this.#p,quadPoints:this.#L(),outlines:this.#I(e),pageIndex:this.pageIndex,rect:e,rotation:this.#O(),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!this.#R(i)?null:(i.id=this.annotationElementId,i)}#R(t){const{color:e}=this._initialData;return t.color.some((s,i)=>s!==e[i])}renderAnnotationElement(t){return t.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}}class yg{#t=Object.create(null);updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(const[e,s]of Object.entries(t))this.updateProperty(e,s)}updateSVGProperty(t,e){this.#t[t]=e}toSVGProperties(){const t=this.#t;return this.#t=Object.create(null),{root:t}}reset(){this.#t=Object.create(null)}updateAll(t=this){this.updateProperties(t)}clone(){st("Not implemented")}}class z extends H{#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#a=null;static#c=NaN;static _INNER_MARGIN=3;constructor(t){super(t),this.#e=t.mustBeCommitted||!1,t.drawOutlines&&(this.#l(t),this.#f())}#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.#d(t,this.parent),this.#m(t.box)}#d(t,e){const{id:s}=e.drawLayer.draw(z._mergeSVGProperties(this._drawingOptions.toSVGProperties(),t.defaultSVGProperties),!1,!1);return s}static _mergeSVGProperties(t,e){const s=new Set(Object.keys(t));for(const[i,n]of Object.entries(e))s.has(i)?Object.assign(t[i],n):t[i]=n;return t}static getDefaultDrawingOptions(t){st("Not implemented")}static get typesMap(){st("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(t,e){const s=this.typesMap.get(t);s&&this._defaultDrawingOptions.updateProperty(s,e),this._currentParent&&(z.#s.updateProperty(s,e),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(t,e){const s=this.constructor.typesMap.get(t);s&&this._updateProperty(t,s,e)}static get defaultPropertiesToUpdate(){const t=[],e=this._defaultDrawingOptions;for(const[s,i]of this.typesMap)t.push([s,e[i]]);return t}get propertiesToUpdate(){const t=[],{_drawingOptions:e}=this;for(const[s,i]of this.constructor.typesMap)t.push([s,e[i]]);return t}_updateProperty(t,e,s){const i=this._drawingOptions,n=i[e],r=o=>{i.updateProperty(e,o);const h=this.#t.updateProperty(e,o);h&&this.#m(h),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,z._mergeSVGProperties(this.#t.getPathResizingSVGProperties(this.#g()),{bbox:this.#p()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,z._mergeSVGProperties(this.#t.getPathResizedSVGProperties(this.#g()),{bbox:this.#p()}))}_onTranslating(t,e){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#p(t,e)})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,z._mergeSVGProperties(this.#t.getPathTranslatedSVGProperties(this.#g(),this.parentDimensions),{bbox:this.#p()}))}_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.#u(),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#f(),this.#m(this.#t.box),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){let e=!1;this.parent&&!t?(this._uiManager.removeShouldRescale(this),this.#u()):t&&(this._uiManager.addShouldRescale(this),this.#f(t),e=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(t),e&&this.select()}#u(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())}#f(t=this.parent){if(!(this._drawId!==null&&this.parent===t)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,t.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=this.#d(this.#t,t)}}#o([t,e,s,i]){const{parentDimensions:[n,r],rotation:o}=this;switch(o){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(){const{x:t,y:e,width:s,height:i,parentDimensions:[n,r],rotation:o}=this;switch(o){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.#o(t),this.div){this.fixAndSetPosition();const[e,s]=this.parentDimensions;this.setDims(this.width*e,this.height*s)}this._onResized()}#p(){const{x:t,y:e,width:s,height:i,rotation:n,parentRotation:r,parentDimensions:[o,h]}=this;switch((n*4+r)/90){case 1:return[1-e-i,t,i,s];case 2:return[1-t-s,1-e-i,s,i];case 3:return[e,1-t-s,i,s];case 4:return[t,e-s*(o/h),i*(h/o),s*(o/h)];case 5:return[1-e,t,s*(o/h),i*(h/o)];case 6:return[1-t-i*(h/o),1-e,i*(h/o),s*(o/h)];case 7:return[e-s*(o/h),1-t-i*(h/o),s*(o/h),i*(h/o)];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*(h/o),e,i*(h/o),s*(o/h)];case 13:return[1-e-s*(o/h),t-i*(h/o),s*(o/h),i*(h/o)];case 14:return[1-t,1-e-s*(o/h),i*(h/o),s*(o/h)];case 15:return[e,1-t,s*(o/h),i*(h/o)];default:return[t,e,s,i]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,z._mergeSVGProperties({bbox:this.#p()},this.#t.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#m(this.#t.updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;const t=super.render();t.classList.add("draw");const e=document.createElement("div");t.append(e),e.setAttribute("aria-hidden","true"),e.className="internal";const[s,i]=this.parentDimensions;return this.setDims(this.width*s,this.height*i),this._uiManager.addShouldRescale(this),this.disableEditing(),t}static createDrawerInstance(t,e,s,i,n){st("Not implemented")}static startDrawing(t,e,s,i){const{target:n,offsetX:r,offsetY:o,pointerId:h,pointerType:l}=i;if(z.#h&&z.#h!==l)return;const{viewport:{rotation:c}}=t,{width:u,height:d}=n.getBoundingClientRect(),f=z.#i=new AbortController,g=t.combinedSignal(f);if(z.#n||=h,z.#h??=l,window.addEventListener("pointerup",p=>{z.#n===p.pointerId?this._endDraw(p):z.#a?.delete(p.pointerId)},{signal:g}),window.addEventListener("pointercancel",p=>{z.#n===p.pointerId?this._currentParent.endDrawingSession():z.#a?.delete(p.pointerId)},{signal:g}),window.addEventListener("pointerdown",p=>{z.#h===p.pointerType&&((z.#a||=new Set).add(p.pointerId),z.#s.isCancellable()&&(z.#s.removeLastElement(),z.#s.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:g}),window.addEventListener("contextmenu",ge,{signal:g}),n.addEventListener("pointermove",this._drawMove.bind(this),{signal:g}),n.addEventListener("touchmove",p=>{p.timeStamp===z.#c&&te(p)},{signal:g}),t.toggleDrawing(),e._editorUndoBar?.hide(),z.#s){t.drawLayer.updateProperties(this._currentDrawId,z.#s.startNew(r,o,u,d,c));return}e.updateUIForDefaultProperties(this),z.#s=this.createDrawerInstance(r,o,u,d,c),z.#r=this.getDefaultDrawingOptions(),this._currentParent=t,{id:this._currentDrawId}=t.drawLayer.draw(this._mergeSVGProperties(z.#r.toSVGProperties(),z.#s.defaultSVGProperties),!0,!1)}static _drawMove(t){if(z.#c=-1,!z.#s)return;const{offsetX:e,offsetY:s,pointerId:i}=t;if(z.#n===i){if(z.#a?.size>=1){this._endDraw(t);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,z.#s.add(e,s)),z.#c=t.timeStamp,te(t)}}static _cleanup(t){t&&(this._currentDrawId=-1,this._currentParent=null,z.#s=null,z.#r=null,z.#h=null,z.#c=NaN),z.#i&&(z.#i.abort(),z.#i=null,z.#n=NaN,z.#a=null)}static _endDraw(t){const e=this._currentParent;if(e){if(e.toggleDrawing(!0),this._cleanup(!1),t&&e.drawLayer.updateProperties(this._currentDrawId,z.#s.end(t.offsetX,t.offsetY)),this.supportMultipleDrawings){const s=z.#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:q.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(t){const e=this._currentParent;if(!e)return null;if(e.toggleDrawing(!0),e.cleanUndoStack(q.DRAW_STEP),!z.#s.isEmpty()){const{pageDimensions:[s,i],scale:n}=e,r=e.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:z.#s.getOutlines(s*n,i*n,n,this._INNER_MARGIN),drawingOptions:z.#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){st("Not implemented")}static async deserialize(t,e,s){const{rawDims:{pageWidth:i,pageHeight:n,pageX:r,pageY:o}}=e.viewport,h=this.deserializeDraw(r,o,i,n,this._INNER_MARGIN,t),l=await super.deserialize(t,e,s);return l.createDrawingOptions(t),l.#l({drawOutlines:h}),l.#f(),l.onScaleChanging(),l.rotate(),l}serializeDraw(t){const[e,s]=this.pageTranslation,[i,n]=this.pageDimensions;return this.#t.serialize([e,s,i,n],t)}renderAnnotationElement(t){return t.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}}class _g{#t=new Float64Array(6);#e;#s;#i;#r;#n;#h="";#a=0;#c=new Gn;#l;#d;constructor(t,e,s,i,n,r){this.#l=s,this.#d=i,this.#i=n,this.#r=r,[t,e]=this.#u(t,e);const o=this.#e=[NaN,NaN,NaN,NaN,t,e];this.#n=[t,e],this.#s=[{line:o,points:this.#n}],this.#t.set(o,0)}updateProperty(t,e){t==="stroke-width"&&(this.#r=e)}#u(t,e){return I._normalizePoint(t,e,this.#l,this.#d,this.#i)}isEmpty(){return!this.#s||this.#s.length===0}isCancellable(){return this.#n.length<=10}add(t,e){[t,e]=this.#u(t,e);const[s,i,n,r]=this.#t.subarray(2,6),o=t-n,h=e-r;return Math.hypot(this.#l*o,this.#d*h)<=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(...I.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const s=this.add(t,e);return s||(this.#n.length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){this.#l=s,this.#d=i,this.#i=n,[t,e]=this.#u(t,e);const r=this.#e=[NaN,NaN,NaN,NaN,t,e];this.#n=[t,e];const o=this.#s.at(-1);return o&&(o.line=new Float32Array(o.line),o.points=new Float32Array(o.points)),this.#s.push({line:r,points:this.#n}),this.#t.set(r,0),this.#a=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.#a=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++){const{line:s,points:i}=this.#s[t];this.#e=s,this.#n=i,this.#a=0,this.toSVGPath()}return{path:{d:this.#h}}}toSVGPath(){const t=I.svgRound(this.#e[4]),e=I.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){const i=this.#h.lastIndexOf("M");this.#h=`${this.#h.slice(0,i)} M ${t} ${e}`,this.#a=6}if(this.#n.length===4){const i=I.svgRound(this.#e[10]),n=I.svgRound(this.#e[11]);return this.#h=`${this.#h} L ${i} ${n}`,this.#a=12,this.#h}const s=[];this.#a===0&&(s.push(`M ${t} ${e}`),this.#a=6);for(let i=this.#a,n=this.#e.length;i<n;i+=6){const[r,o,h,l,c,u]=this.#e.slice(i,i+6).map(I.svgRound);s.push(`C${r} ${o} ${h} ${l} ${c} ${u}`)}return this.#h+=s.join(" "),this.#a=this.#e.length,this.#h}getOutlines(t,e,s,i){const n=this.#s.at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),this.#c.build(this.#s,t,e,s,this.#i,this.#r,i),this.#t=null,this.#e=null,this.#s=null,this.#h=null,this.#c}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}class Gn extends I{#t;#e=0;#s;#i;#r;#n;#h;#a;#c;build(t,e,s,i,n,r,o){this.#r=e,this.#n=s,this.#h=i,this.#a=n,this.#c=r,this.#s=o??0,this.#i=t,this.#u()}setLastElement(t){return this.#i.push(t),{path:{d:this.toSVGPath()}}}removeLastElement(){return this.#i.pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const t=[];for(const{line:e}of this.#i){if(t.push(`M${I.svgRound(e[4])} ${I.svgRound(e[5])}`),e.length===6){t.push("Z");continue}if(e.length===12){t.push(`L${I.svgRound(e[10])} ${I.svgRound(e[11])}`);continue}for(let s=6,i=e.length;s<i;s+=6){const[n,r,o,h,l,c]=e.subarray(s,s+6).map(I.svgRound);t.push(`C${n} ${r} ${o} ${h} ${l} ${c}`)}}return t.join("")}serialize([t,e,s,i],n){const r=[],o=[],[h,l,c,u]=this.#d();let d,f,g,p,b,m,v,y,_;switch(this.#a){case 0:_=I._rescale,d=t,f=e+i,g=s,p=-i,b=t+h*s,m=e+(1-l-u)*i,v=t+(h+c)*s,y=e+(1-l)*i;break;case 90:_=I._rescaleAndSwap,d=t,f=e,g=s,p=i,b=t+l*s,m=e+h*i,v=t+(l+u)*s,y=e+(h+c)*i;break;case 180:_=I._rescale,d=t+s,f=e,g=-s,p=i,b=t+(1-h-c)*s,m=e+l*i,v=t+(1-h)*s,y=e+(l+u)*i;break;case 270:_=I._rescaleAndSwap,d=t+s,f=e+i,g=-s,p=-i,b=t+(1-l-u)*s,m=e+(1-h-c)*i,v=t+(1-l)*s,y=e+(1-h)*i;break}for(const{line:S,points:A}of this.#i)r.push(_(S,d,f,g,p,n?new Array(S.length):null)),o.push(_(A,d,f,g,p,n?new Array(A.length):null));return{lines:r,points:o,rect:[b,m,v,y]}}static deserialize(t,e,s,i,n,{paths:{lines:r,points:o},rotation:h,thickness:l}){const c=[];let u,d,f,g,p;switch(h){case 0:p=I._rescale,u=-t/s,d=e/i+1,f=1/s,g=-1/i;break;case 90:p=I._rescaleAndSwap,u=-e/i,d=-t/s,f=1/i,g=1/s;break;case 180:p=I._rescale,u=t/s+1,d=-e/i,f=-1/s,g=1/i;break;case 270:p=I._rescaleAndSwap,u=e/i+1,d=t/s+1,f=-1/i,g=-1/s;break}if(!r){r=[];for(const m of o){const v=m.length;if(v===2){r.push(new Float32Array([NaN,NaN,NaN,NaN,m[0],m[1]]));continue}if(v===4){r.push(new Float32Array([NaN,NaN,NaN,NaN,m[0],m[1],NaN,NaN,NaN,NaN,m[2],m[3]]));continue}const y=new Float32Array(3*(v-2));r.push(y);let[_,S,A,T]=m.subarray(0,4);y.set([NaN,NaN,NaN,NaN,_,S],0);for(let E=4;E<v;E+=2){const P=m[E],N=m[E+1];y.set(I.createBezierPoints(_,S,A,T,P,N),(E-2)*3),[_,S,A,T]=[A,T,P,N]}}}for(let m=0,v=r.length;m<v;m++)c.push({line:p(r[m].map(y=>y??NaN),u,d,f,g),points:p(o[m].map(y=>y??NaN),u,d,f,g)});const b=new Gn;return b.build(c,s,i,1,h,l,n),b}#l(t=this.#c){const e=this.#s+t/2*this.#h;return this.#a%180===0?[e/this.#r,e/this.#n]:[e/this.#n,e/this.#r]}#d(){const[t,e,s,i]=this.#t,[n,r]=this.#l(0);return[t+n,e+r,s-2*n,i-2*r]}#u(){const t=this.#t=new Float32Array([1/0,1/0,-1/0,-1/0]);for(const{line:i}of this.#i){if(i.length<=12){for(let o=4,h=i.length;o<h;o+=6){const[l,c]=i.subarray(o,o+2);t[0]=Math.min(t[0],l),t[1]=Math.min(t[1],c),t[2]=Math.max(t[2],l),t[3]=Math.max(t[3],c)}continue}let n=i[4],r=i[5];for(let o=6,h=i.length;o<h;o+=6){const[l,c,u,d,f,g]=i.subarray(o,o+6);B.bezierBoundingBox(n,r,l,c,u,d,f,g,t),n=f,r=g}}const[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.#f(e):null}#f(t){const[e,s]=this.#l();this.#c=t;const[i,n]=this.#l(),[r,o]=[i-e,n-s],h=this.#t;return h[0]-=r,h[1]-=o,h[2]+=2*r,h[3]+=2*o,h}updateParentDimensions([t,e],s){const[i,n]=this.#l();this.#r=t,this.#n=e,this.#h=s;const[r,o]=this.#l(),h=r-i,l=o-n,c=this.#t;return c[0]-=h,c[1]-=l,c[2]+=2*h,c[3]+=2*l,c}updateRotation(t){return this.#e=t,{path:{transform:this.rotationTransform}}}get viewBox(){return this.#t.map(I.svgRound).join(" ")}get defaultProperties(){const[t,e]=this.#t;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${I.svgRound(t)} ${I.svgRound(e)}`}}}get rotationTransform(){const[,,t,e]=this.#t;let s=0,i=0,n=0,r=0,o=0,h=0;switch(this.#e){case 90:i=e/t,n=-t/e,o=t;break;case 180:s=-1,r=-1,o=t,h=e;break;case 270:i=-e/t,n=t/e,h=e;break;default:return""}return`matrix(${s} ${i} ${n} ${r} ${I.svgRound(o)} ${I.svgRound(h)})`}getPathResizingSVGProperties([t,e,s,i]){const[n,r]=this.#l(),[o,h,l,c]=this.#t;if(Math.abs(l-n)<=I.PRECISION||Math.abs(c-r)<=I.PRECISION){const p=t+s/2-(o+l/2),b=e+i/2-(h+c/2);return{path:{"transform-origin":`${I.svgRound(t)} ${I.svgRound(e)}`,transform:`${this.rotationTransform} translate(${p} ${b})`}}}const u=(s-2*n)/(l-2*n),d=(i-2*r)/(c-2*r),f=l/s,g=c/i;return{path:{"transform-origin":`${I.svgRound(o)} ${I.svgRound(h)}`,transform:`${this.rotationTransform} scale(${f} ${g}) translate(${I.svgRound(n)} ${I.svgRound(r)}) scale(${u} ${d}) translate(${I.svgRound(-n)} ${I.svgRound(-r)})`}}}getPathResizedSVGProperties([t,e,s,i]){const[n,r]=this.#l(),o=this.#t,[h,l,c,u]=o;if(o[0]=t,o[1]=e,o[2]=s,o[3]=i,Math.abs(c-n)<=I.PRECISION||Math.abs(u-r)<=I.PRECISION){const b=t+s/2-(h+c/2),m=e+i/2-(l+u/2);for(const{line:v,points:y}of this.#i)I._translate(v,b,m,v),I._translate(y,b,m,y);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${I.svgRound(t)} ${I.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const d=(s-2*n)/(c-2*n),f=(i-2*r)/(u-2*r),g=-d*(h+n)+t+n,p=-f*(l+r)+e+r;if(d!==1||f!==1||g!==0||p!==0)for(const{line:b,points:m}of this.#i)I._rescale(b,g,p,d,f,b),I._rescale(m,g,p,d,f,m);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${I.svgRound(t)} ${I.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([t,e],s){const[i,n]=s,r=this.#t,o=t-r[0],h=e-r[1];if(this.#r===i&&this.#n===n)for(const{line:l,points:c}of this.#i)I._translate(l,o,h,l),I._translate(c,o,h,c);else{const l=this.#r/i,c=this.#n/n;this.#r=i,this.#n=n;for(const{line:u,points:d}of this.#i)I._rescale(u,o,h,l,c,u),I._rescale(d,o,h,l,c,d);r[2]*=l,r[3]*=c}return r[0]=t,r[1]=e,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${I.svgRound(t)} ${I.svgRound(e)}`}}}get defaultSVGProperties(){const t=this.#t;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${I.svgRound(t[0])} ${I.svgRound(t[1])}`,transform:this.rotationTransform||null},bbox:t}}}class Co extends yg{#t;constructor(t){super(),this.#t=t,super.updateProperties({fill:"none",stroke:H._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(t,e){t==="stroke-width"&&(e??=this["stroke-width"],e*=this.#t.realScale),super.updateSVGProperty(t,e)}clone(){const t=new Co(this.#t);return t.updateAll(this),t}}class Ao extends z{static _type="ink";static _editorType=U.INK;static _defaultDrawingOptions=null;constructor(t){super({...t,name:"inkEditor"}),this._willKeepAspectRatio=!0}static initialize(t,e){H.initialize(t,e),this._defaultDrawingOptions=new Co(e.viewParameters)}static getDefaultDrawingOptions(t){const e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!0}static get typesMap(){return $(this,"typesMap",new Map([[q.INK_THICKNESS,"stroke-width"],[q.INK_COLOR,"stroke"],[q.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(t,e,s,i,n){return new _g(t,e,s,i,n,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(t,e,s,i,n,r){return Gn.deserialize(t,e,s,i,n,r)}static async deserialize(t,e,s){let i=null;if(t instanceof wo){const{data:{inkLists:r,rect:o,rotation:h,id:l,color:c,opacity:u,borderStyle:{rawWidth:d},popupRef:f},parent:{page:{pageNumber:g}}}=t;i=t={annotationType:U.INK,color:Array.from(c),thickness:d,opacity:u,paths:{points:r},boxes:null,pageIndex:g-1,rect:o.slice(0),rotation:h,id:l,deleted:!1,popupRef:f}}const n=await super.deserialize(t,e,s);return n.annotationElementId=t.id||null,n._initialData=i,n}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:t,_drawingOptions:e,parent:s}=this;e.updateSVGProperty("stroke-width"),s.drawLayer.updateProperties(t,e.toSVGProperties())}static onScaleChangingWhenDrawing(){const t=this._currentParent;t&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),t.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:t,thickness:e,opacity:s}){this._drawingOptions=Ao.getDefaultDrawingOptions({stroke:B.makeHexColor(...t),"stroke-width":e,"stroke-opacity":s})}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:e,points:s,rect:i}=this.serializeDraw(t),{_drawingOptions:{stroke:n,"stroke-opacity":r,"stroke-width":o}}=this,h={annotationType:U.INK,color:H._colorManager.convert(n),opacity:r,thickness:o,paths:{lines:e,points:s},pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return t?h:this.annotationElementId&&!this.#t(h)?null:(h.id=this.annotationElementId,h)}#t(t){const{color:e,thickness:s,opacity:i,pageIndex:n}=this._initialData;return this._hasBeenMoved||this._hasBeenResized||t.color.some((r,o)=>r!==e[o])||t.thickness!==s||t.opacity!==i||t.pageIndex!==n}renderAnnotationElement(t){const{points:e,rect:s}=this.serializeDraw(!1);return t.updateEdited({rect:s,thickness:this._drawingOptions["stroke-width"],points:e}),null}}class To extends H{#t=null;#e=null;#s=null;#i=null;#r=null;#n="";#h=null;#a=null;#c=!1;#l=!1;static _type="stamp";static _editorType=U.STAMP;constructor(t){super({...t,name:"stampEditor"}),this.#i=t.bitmapUrl,this.#r=t.bitmapFile}static initialize(t,e){H.initialize(t,e)}static get supportedTypes(){return $(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(e=>`image/${e}`))}static get supportedTypesStr(){return $(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(t){return this.supportedTypes.includes(t)}static paste(t,e){e.pasteEditor(U.STAMP,{bitmapFile:t.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){return{type:"stamp",hasAltText:!!this.altTextData?.altText}}static computeTelemetryFinalData(t){const e=t.get("hasAltText");return{hasAltText:e.get(!0)??0,hasNoAltText:e.get(!1)??0}}#d(t,e=!1){if(!t){this.remove();return}this.#t=t.bitmap,e||(this.#e=t.id,this.#c=t.isSvg),t.file&&(this.#n=t.file.name),this.#o()}#u(){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);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#t){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}}async mlGuessAltText(t=null,e=!0){if(this.hasAltTextData())return null;const{mlManager:s}=this._uiManager;if(!s)throw new Error("No ML.");if(!await s.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:i,width:n,height:r}=t||this.copyCanvas(null,null,!0).imageData,o=await s.guess({name:"altText",request:{data:i,width:n,height:r,channels:i.length/(n*r)}});if(!o)throw new Error("No response from the AI service.");if(o.error)throw new Error("Error from the AI service.");if(o.cancel)return null;if(!o.output)throw new Error("No valid response from the AI service.");const h=o.output;return await this.setGuessedAltText(h),e&&!this.hasAltTextData()&&(this.altTextData={alt:h,decorative:!1}),h}#f(){if(this.#e){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(this.#e).then(s=>this.#d(s,!0)).finally(()=>this.#u());return}if(this.#i){const s=this.#i;this.#i=null,this._uiManager.enableWaiting(!0),this.#s=this._uiManager.imageManager.getFromUrl(s).then(i=>this.#d(i)).finally(()=>this.#u());return}if(this.#r){const s=this.#r;this.#r=null,this._uiManager.enableWaiting(!0),this.#s=this._uiManager.imageManager.getFromFile(s).then(i=>this.#d(i)).finally(()=>this.#u());return}const t=document.createElement("input");t.type="file",t.accept=To.supportedTypesStr;const e=this._uiManager._signal;this.#s=new Promise(s=>{t.addEventListener("change",async()=>{if(!t.files||t.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const i=await this._uiManager.imageManager.getFromFile(t.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),this.#d(i)}s()},{signal:e}),t.addEventListener("cancel",()=>{this.remove(),s()},{signal:e})}).finally(()=>this.#u()),t.click()}remove(){this.#e&&(this.#t=null,this._uiManager.imageManager.deleteId(this.#e),this.#h?.remove(),this.#h=null,this.#a&&(clearTimeout(this.#a),this.#a=null)),super.remove()}rebuild(){if(!this.parent){this.#e&&this.#f();return}super.rebuild(),this.div!==null&&(this.#e&&this.#h===null&&this.#f(),this.isAttachedToDOM||this.parent.add(this))}onceAdded(t){this._isDraggable=!0,t&&this.div.focus()}isEmpty(){return!(this.#s||this.#t||this.#i||this.#r||this.#e)}get isResizable(){return!0}render(){if(this.div)return this.div;let t,e;if(this.width&&(t=this.x,e=this.y),super.render(),this.div.hidden=!0,this.div.setAttribute("role","figure"),this.addAltTextButton(),this.#t?this.#o():this.#f(),this.width&&!this.annotationElementId){const[s,i]=this.parentDimensions;this.setAt(t*s,e*i,this.width*s,this.height*i)}return this._uiManager.addShouldRescale(this),this.div}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;this.#a!==null&&clearTimeout(this.#a);const t=200;this.#a=setTimeout(()=>{this.#a=null,this.#m()},t)}#o(){const{div:t}=this;let{width:e,height:s}=this.#t;const[i,n]=this.pageDimensions,r=.75;if(this.width)e=this.width*i,s=this.height*n;else if(e>r*i||s>r*n){const c=Math.min(r*i/e,r*n/s);e*=c,s*=c}const[o,h]=this.parentDimensions;this.setDims(e*o/i,s*h/n),this._uiManager.enableWaiting(!1);const l=this.#h=document.createElement("canvas");l.setAttribute("role","img"),this.addContainer(l),this.width=e/i,this.height=s/n,this._initialOptions?.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(t.hidden=!1),this.#m(),this.#l||(this.parent.addUndoableEditor(this),this.#l=!0),this._reportTelemetry({action:"inserted_image"}),this.#n&&l.setAttribute("aria-label",this.#n)}copyCanvas(t,e,s=!1){t||(t=224);const{width:i,height:n}=this.#t,r=new oo;let o=this.#t,h=i,l=n,c=null;if(e){if(i>e||n>e){const A=Math.min(e/i,e/n);h=Math.floor(i*A),l=Math.floor(n*A)}c=document.createElement("canvas");const d=c.width=Math.ceil(h*r.sx),f=c.height=Math.ceil(l*r.sy);this.#c||(o=this.#g(d,f));const g=c.getContext("2d");g.filter=this._uiManager.hcmFilter;let p="white",b="#cfcfd8";this._uiManager.hcmFilter!=="none"?b="black":window.matchMedia?.("(prefers-color-scheme: dark)").matches&&(p="#8f8f9d",b="#42414d");const m=15,v=m*r.sx,y=m*r.sy,_=new OffscreenCanvas(v*2,y*2),S=_.getContext("2d");S.fillStyle=p,S.fillRect(0,0,v*2,y*2),S.fillStyle=b,S.fillRect(0,0,v,y),S.fillRect(v,y,v,y),g.fillStyle=g.createPattern(_,"repeat"),g.fillRect(0,0,d,f),g.drawImage(o,0,0,o.width,o.height,0,0,d,f)}let u=null;if(s){let d,f;if(r.symmetric&&o.width<t&&o.height<t)d=o.width,f=o.height;else if(o=this.#t,i>t||n>t){const b=Math.min(t/i,t/n);d=Math.floor(i*b),f=Math.floor(n*b),this.#c||(o=this.#g(d,f))}const p=new OffscreenCanvas(d,f).getContext("2d",{willReadFrequently:!0});p.drawImage(o,0,0,o.width,o.height,0,0,d,f),u={width:d,height:f,data:p.getImageData(0,0,d,f).data}}return{canvas:c,width:h,height:l,imageData:u}}#g(t,e){const{width:s,height:i}=this.#t;let n=s,r=i,o=this.#t;for(;n>2*t||r>2*e;){const h=n,l=r;n>2*t&&(n=n>=16384?Math.floor(n/2)-1:Math.ceil(n/2)),r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2));const c=new OffscreenCanvas(n,r);c.getContext("2d").drawImage(o,0,0,h,l,0,0,n,r),o=c.transferToImageBitmap()}return o}#m(){const[t,e]=this.parentDimensions,{width:s,height:i}=this,n=new oo,r=Math.ceil(s*t*n.sx),o=Math.ceil(i*e*n.sy),h=this.#h;if(!h||h.width===r&&h.height===o)return;h.width=r,h.height=o;const l=this.#c?this.#t:this.#g(r,o),c=h.getContext("2d");c.filter=this._uiManager.hcmFilter,c.drawImage(l,0,0,l.width,l.height,0,0,r,o)}getImageForAltText(){return this.#h}#p(t){if(t){if(this.#c){const i=this._uiManager.imageManager.getSvgUrl(this.#e);if(i)return i}const e=document.createElement("canvas");return{width:e.width,height:e.height}=this.#t,e.getContext("2d").drawImage(this.#t,0,0),e.toDataURL()}if(this.#c){const[e,s]=this.pageDimensions,i=Math.round(this.width*e*Is.PDF_TO_CSS_UNITS),n=Math.round(this.height*s*Is.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 Pl){const{data:{rect:g,rotation:p,id:b,structParent:m,popupRef:v},container:y,parent:{page:{pageNumber:_}}}=t,S=y.querySelector("canvas"),A=s.imageManager.getFromCanvas(y.id,S);S.remove();const T=(await e._structTree.getAriaAttributes(`${so}${b}`))?.get("aria-label")||"";i=t={annotationType:U.STAMP,bitmapId:A.id,bitmap:A.bitmap,pageIndex:_-1,rect:g.slice(0),rotation:p,id:b,deleted:!1,accessibilityData:{decorative:!1,altText:T},isSvg:!1,structParent:m,popupRef:v}}const n=await super.deserialize(t,e,s),{rect:r,bitmap:o,bitmapUrl:h,bitmapId:l,isSvg:c,accessibilityData:u}=t;l&&s.imageManager.isValidId(l)?(n.#e=l,o&&(n.#t=o)):n.#i=h,n.#c=c;const[d,f]=n.pageDimensions;return n.width=(r[2]-r[0])/d,n.height=(r[3]-r[1])/f,n.annotationElementId=t.id||null,u&&(n.altTextData=u),n._initialData=i,n.#l=!!i,n}serialize(t=!1,e=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const s={annotationType:U.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.#p(!0),s.accessibilityData=this.serializeAltText(!0),s;const{decorative:i,altText:n}=this.serializeAltText(!1);if(!i&&n&&(s.accessibilityData={type:"Figure",alt:n}),this.annotationElementId){const o=this.#b(s);if(o.isSame)return null;o.isSameAltText?delete s.accessibilityData:s.accessibilityData.structParent=this._initialData.structParent??-1}if(s.id=this.annotationElementId,e===null)return s;e.stamps||=new Map;const r=this.#c?(s.rect[2]-s.rect[0])*(s.rect[3]-s.rect[1]):null;if(!e.stamps.has(this.#e))e.stamps.set(this.#e,{area:r,serialized:s}),s.bitmap=this.#p(!1);else if(this.#c){const o=e.stamps.get(this.#e);r>o.area&&(o.area=r,o.serialized.bitmap.close(),o.serialized.bitmap=this.#p(!1))}return s}#b(t){const{pageIndex:e,accessibilityData:{altText:s}}=this._initialData,i=t.pageIndex===e,n=(t.accessibilityData?.alt||"")===s;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&i&&n,isSameAltText:n}}renderAnnotationElement(t){return t.updateEdited({rect:this.getRect(0,0)}),null}}class He{#t;#e=!1;#s=null;#i=null;#r=null;#n=new Map;#h=!1;#a=!1;#c=!1;#l=null;#d=null;#u=null;#f=null;#o;static _initialized=!1;static#g=new Map([Ct,Ao,To,mt].map(t=>[t._editorType,t]));constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:o,textLayer:h,viewport:l,l10n:c}){const u=[...He.#g.values()];if(!He._initialized){He._initialized=!0;for(const d of u)d.initialize(c,t)}t.registerEditorTypes(u),this.#o=t,this.pageIndex=e,this.div=s,this.#t=n,this.#s=r,this.viewport=l,this.#u=h,this.drawLayer=o,this._structTree=i,this.#o.addLayer(this)}get isEmpty(){return this.#n.size===0}get isInvisible(){return this.isEmpty&&this.#o.getMode()===U.NONE}updateToolbar(t){this.#o.updateToolbar(t)}updateMode(t=this.#o.getMode()){switch(this.#v(),t){case U.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case U.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case U.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:e}=this.div;for(const s of He.#g.values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){return t===this.#u?.div}setEditingState(t){this.#o.setEditingState(t)}addCommands(t){this.#o.addCommands(t)}cleanUndoStack(t){this.#o.cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){this.#s?.div.classList.toggle("disabled",!t)}async enable(){this.#c=!0,this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of this.#n.values())s.enableEditing(),s.show(!0),s.annotationElementId&&(this.#o.removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!this.#s){this.#c=!1;return}const e=this.#s.getEditableAnnotations();for(const s of e){if(s.hide(),this.#o.isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}this.#c=!1}disable(){this.#a=!0,this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const i of this.#n.values())if(i.disableEditing(),!!i.annotationElementId){if(i.serialize()!==null){t.set(i.annotationElementId,i);continue}else e.set(i.annotationElementId,i);this.getEditableAnnotation(i.annotationElementId)?.show(),i.remove()}if(this.#s){const i=this.#s.getEditableAnnotations();for(const n of i){const{id:r}=n.data;if(this.#o.isDeletedAnnotationElement(r))continue;let o=e.get(r);if(o){o.resetAnnotationElement(n),o.show(!1),n.show();continue}o=t.get(r),o&&(this.#o.addChangedExistingAnnotation(o),o.renderAnnotationElement(n)&&o.show(!1)),n.show()}}this.#v(),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const i of He.#g.values())s.remove(`${i._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),this.#a=!1}getEditableAnnotation(t){return this.#s?.getEditableAnnotation(t)||null}setActiveEditor(t){this.#o.getActive()!==t&&this.#o.setActiveEditor(t)}enableTextSelection(){if(this.div.tabIndex=-1,this.#u?.div&&!this.#f){this.#f=new AbortController;const t=this.#o.combinedSignal(this.#f);this.#u.div.addEventListener("pointerdown",this.#m.bind(this),{signal:t}),this.#u.div.classList.add("highlighting")}}disableTextSelection(){this.div.tabIndex=0,this.#u?.div&&this.#f&&(this.#f.abort(),this.#f=null,this.#u.div.classList.remove("highlighting"))}#m(t){this.#o.unselectAll();const{target:e}=t;if(e===this.#u.div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&this.#u.div.contains(e)){const{isMac:s}=Bt.platform;if(t.button!==0||t.ctrlKey&&s)return;this.#o.showAllEditors("highlight",!0,!0),this.#u.div.classList.add("free"),this.toggleDrawing(),mt.startHighlighting(this,this.#o.direction==="ltr",{target:this.#u.div,x:t.x,y:t.y}),this.#u.div.addEventListener("pointerup",()=>{this.#u.div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:this.#o._signal}),t.preventDefault()}}enableClick(){if(this.#i)return;this.#i=new AbortController;const t=this.#o.combinedSignal(this.#i);this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){this.#i?.abort(),this.#i=null}attach(t){this.#n.set(t.id,t);const{annotationElementId:e}=t;e&&this.#o.isDeletedAnnotationElement(e)&&this.#o.removeDeletedAnnotationElement(t)}detach(t){this.#n.delete(t.id),this.#t?.removePointerInTextLayer(t.contentDiv),!this.#a&&t.annotationElementId&&this.#o.addDeletedAnnotationElement(t)}remove(t){this.detach(t),this.#o.removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){t.parent!==this&&(t.parent&&t.annotationElementId&&(this.#o.addDeletedAnnotationElement(t.annotationElementId),H.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.#o.addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!this.#c),this.#o.addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!this.#r&&(t._focusEventsAllowed=!1,this.#r=setTimeout(()=>{this.#r=null,t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this.#o._signal}),e.focus())},0)),t._structTreeParentId=this.#t?.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||=this,t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getNextId(){return this.#o.getId()}get#p(){return He.#g.get(this.#o.getMode())}combinedSignal(t){return this.#o.combinedSignal(t)}#b(t){const e=this.#p;return e?new e.prototype.constructor(t):null}canCreateNewEmptyEditor(){return this.#p?.canCreateNewEmptyEditor()}pasteEditor(t,e){this.#o.updateToolbar(t),this.#o.updateMode(t);const{offsetX:s,offsetY:i}=this.#_(),n=this.getNextId(),r=this.#b({parent:this,id:n,x:s,y:i,uiManager:this.#o,isCentered:!0,...e});r&&this.add(r)}async deserialize(t){return await He.#g.get(t.annotationType??t.annotationEditorType)?.deserialize(t,this,this.#o)||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=this.#b({parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:this.#o,isCentered:e,...s});return n&&this.add(n),n}#_(){const{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),o=Math.min(window.innerWidth,t+s),h=Math.min(window.innerHeight,e+i),l=(n+o)/2-t,c=(r+h)/2-e,[u,d]=this.viewport.rotation%180===0?[l,c]:[c,l];return{offsetX:u,offsetY:d}}addNewEditor(){this.createAndAddNewEditor(this.#_(),!0)}setSelected(t){this.#o.setSelected(t)}toggleSelected(t){this.#o.toggleSelected(t)}unselect(t){this.#o.unselect(t)}pointerup(t){const{isMac:e}=Bt.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&this.#h&&(this.#h=!1,!(this.#p?.isDrawer&&this.#p.supportMultipleDrawings))){if(!this.#e){this.#e=!0;return}if(this.#o.getMode()===U.STAMP){this.#o.unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){if(this.#o.getMode()===U.HIGHLIGHT&&this.enableTextSelection(),this.#h){this.#h=!1;return}const{isMac:e}=Bt.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(this.#h=!0,this.#p?.isDrawer){this.startDrawingSession(t);return}const s=this.#o.getActive();this.#e=!s||s.isEmpty()}startDrawingSession(t){if(this.div.focus(),this.#l){this.#p.startDrawing(this,this.#o,!1,t);return}this.#o.setCurrentDrawingSession(this),this.#l=new AbortController;const e=this.#o.combinedSignal(this.#l);this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(this.#d=null,this.commitOrRemove())},{signal:e}),this.#p.startDrawing(this,this.#o,!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&(this.#d=e);return}this.#d&&setTimeout(()=>{this.#d?.focus(),this.#d=null},0)}endDrawingSession(t=!1){return this.#l?(this.#o.setCurrentDrawingSession(null),this.#l.abort(),this.#l=null,this.#d=null,this.#p.endDrawing(t)):null}findNewParent(t,e,s){const i=this.#o.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.#p.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove(),this.#o.getActive()?.parent===this&&(this.#o.commitOrRemove(),this.#o.setActiveEditor(null)),this.#r&&(clearTimeout(this.#r),this.#r=null);for(const t of this.#n.values())this.#t?.removePointerInTextLayer(t.contentDiv),t.setParent(null),t.isAttachedToDOM=!1,t.div.remove();this.div=null,this.#n.clear(),this.#o.removeLayer(this)}#v(){for(const t of this.#n.values())t.isEmpty()&&t.remove()}render({viewport:t}){this.viewport=t,fs(this.div,t);for(const e of this.#o.getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){this.#o.commitOrRemove(),this.#v();const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,fs(this.div,{rotation:s}),e!==s)for(const i of this.#n.values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return this.#o.viewParameters.realScale}}class zt{#t=null;#e=0;#s=new Map;#i=new Map;constructor({pageIndex:t}){this.pageIndex=t}setParent(t){if(!this.#t){this.#t=t;return}if(this.#t!==t){if(this.#s.size>0)for(const e of this.#s.values())e.remove(),t.append(e);this.#t=t}}static get _svgFactory(){return $(this,"_svgFactory",new yo)}static#r(t,[e,s,i,n]){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`}#n(){const t=zt._svgFactory.create(1,1,!0);return this.#t.append(t),t.setAttribute("aria-hidden",!0),t}#h(t,e){const s=zt._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=zt._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i}#a(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)}draw(t,e=!1,s=!1){const i=this.#e++,n=this.#n(),r=zt._svgFactory.createElement("defs");n.append(r);const o=zt._svgFactory.createElement("path");r.append(o);const h=`path_p${this.pageIndex}_${i}`;o.setAttribute("id",h),o.setAttribute("vector-effect","non-scaling-stroke"),e&&this.#i.set(i,o);const l=s?this.#h(r,h):null,c=zt._svgFactory.createElement("use");return n.append(c),c.setAttribute("href",`#${h}`),this.updateProperties(n,t),this.#s.set(i,n),{id:i,clipPathId:`url(#${l})`}}drawOutline(t,e){const s=this.#e++,i=this.#n(),n=zt._svgFactory.createElement("defs");i.append(n);const r=zt._svgFactory.createElement("path");n.append(r);const o=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",o),r.setAttribute("vector-effect","non-scaling-stroke");let h;if(e){const u=zt._svgFactory.createElement("mask");n.append(u),h=`mask_p${this.pageIndex}_${s}`,u.setAttribute("id",h),u.setAttribute("maskUnits","objectBoundingBox");const d=zt._svgFactory.createElement("rect");u.append(d),d.setAttribute("width","1"),d.setAttribute("height","1"),d.setAttribute("fill","white");const f=zt._svgFactory.createElement("use");u.append(f),f.setAttribute("href",`#${o}`),f.setAttribute("stroke","none"),f.setAttribute("fill","black"),f.setAttribute("fill-rule","nonzero"),f.classList.add("mask")}const l=zt._svgFactory.createElement("use");i.append(l),l.setAttribute("href",`#${o}`),h&&l.setAttribute("mask",`url(#${h})`);const c=l.cloneNode();return i.append(c),l.classList.add("mainOutline"),c.classList.add("secondaryOutline"),this.updateProperties(i,t),this.#s.set(s,i),s}finalizeDraw(t,e){this.#i.delete(t),this.updateProperties(t,e)}updateProperties(t,e){if(!e)return;const{root:s,bbox:i,rootClass:n,path:r}=e,o=typeof t=="number"?this.#s.get(t):t;if(o){if(s&&this.#a(o,s),i&&zt.#r(o,i),n){const{classList:h}=o;for(const[l,c]of Object.entries(n))h.toggle(l,c)}if(r){const l=o.firstChild.firstChild;this.#a(l,r)}}}updateParent(t,e){if(e===this)return;const s=this.#s.get(t);s&&(e.#t.append(s),this.#s.delete(t),e.#s.set(t,s))}remove(t){this.#i.delete(t),this.#t!==null&&(this.#s.get(t).remove(),this.#s.delete(t))}destroy(){this.#t=null;for(const t of this.#s.values())t.remove();this.#s.clear(),this.#i.clear()}}globalThis.pdfjsTestingUtils={HighlightOutliner:xo},V.AbortException,V.AnnotationEditorLayer,V.AnnotationEditorParamsType,V.AnnotationEditorType,V.AnnotationEditorUIManager,V.AnnotationLayer,V.AnnotationMode,V.ColorPicker,V.DOMSVGFactory,V.DrawLayer,V.FeatureTest;var wg=V.GlobalWorkerOptions;V.ImageKind,V.InvalidPDFException,V.MissingPDFException,V.OPS,V.OutputScale,V.PDFDataRangeTransport,V.PDFDateString,V.PDFWorker,V.PasswordResponses,V.PermissionFlag,V.PixelsPerInch,V.RenderingCancelledException,V.TextLayer,V.TouchManager,V.UnexpectedResponseException,V.Util,V.VerbosityLevel,V.XfaLayer,V.build,V.createValidAbsoluteUrl,V.fetchData;var xg=V.getDocument;V.getFilenameFromUrl,V.getPdfFilenameFromUrl,V.getXfaPageViewport,V.isDataScheme,V.isPdfFile,V.noContextMenu,V.normalizeUnicode,V.setLayerDimensions,V.shadow,V.stopEvent;var Sg=V.version;let Dl=null;function Cg(){const a=document.createElement("div");a.style.width="1in",document.body.append(a);const t=a.offsetWidth;return a.remove(),t}function Ag(){const a=Dl??Cg();return Dl=a,a/72}function Tg(a,t=500){if(typeof a!="function")throw new TypeError("The first argument is not a function.");let e=null;return function(...s){e&&clearTimeout(e),e=setTimeout(()=>{e=null,a.apply(this,s)},t)}}function Eg(a){return a.arrayBuffer?a.arrayBuffer():new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>{const i=s.result;if(!(i instanceof ArrayBuffer)){e(new Error("Failed to read file as ArrayBuffer."));return}t(i)}),s.addEventListener("error",e),s.readAsArrayBuffer(a)})}Rl()||(wg.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${Sg}/pdf.worker.min.mjs`);function Rl(){try{return typeof OffscreenCanvas<"u"&&typeof HTMLCanvasElement<"u"&&typeof HTMLCanvasElement.prototype.transferControlToOffscreen=="function"&&globalThis.self===window.top}catch{return!1}}async function kg({page:a,data:t,scale:e,password:s},i){const n=Ag()/window.devicePixelRatio;if(Rl()){const r=new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/pdfjs.worker-DuXj-zBo.js").href:new URL("assets/pdfjs.worker-DuXj-zBo.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:dt&&dt.tagName.toUpperCase()==="SCRIPT"&&dt.src||new URL("pdf-canvas.umd.js",document.baseURI).href),{type:"module"});return r.postMessage({data:t,password:s,id:i,page:a,units:n,scale:e}),await new Promise(h=>{r.addEventListener("message",l=>{if(l.data.status!=="success")return;const{bitmap:c,width:u,height:d,pages:f}=l.data;if(c){const g=document.createElement("canvas"),p=g.getContext("bitmaprenderer");g.width=u,g.height=d,p?.transferFromImageBitmap(c),h({pages:f,canvas:g})}else h({pages:f,canvas:null})})})}else{const r=await Eg(t),o=await xg({data:r,password:s}).promise,h=o.numPages;if(!i)return{canvas:null,pages:h};const l=await o.getPage(a),c=l.getViewport({scale:e}),u=document.createElement("canvas"),f={canvasContext:u.getContext("2d"),viewport:c,transform:[n,0,0,n,0,0]};return u.width=Math.floor(c.width*n),u.height=Math.floor(c.height*n),l.render(f).promise.then(()=>({canvas:u,pages:h}))}}const Gt=new Map;function Mg(a){const t=new Nr(a);return Gt.set(a,t),t}function Pg(a){const t=Date.now();return{PDFId:`${a.name}-${t}`,name:a.name.replace(/.pdf/,""),updateDate:t,data:a}}async function Og({src:a},t,e){if(!a||!e)return null;const{objects:s,options:i}=await cd(a),n=s.filter(o=>o!==null),r=Eu.groupSVGElements(n,i);return n.forEach(o=>{o.stroke=e}),r.hoverCursor="pointer",r.stroke=`${e}-${t}`,r}function Dg(a,t){if(!Gt.get(a))return;const s=1/3,i=Bg(t,s);Fl(a,i,s)}async function Rg(a,t){const e=Date.now(),i={PDFId:`${a.name}-${e}`,name:a.name.replace(/.png|.jpg|.jpeg/,""),updateDate:e,data:a};return t&&Ll(t,{data:a}),{...i,pages:1}}async function Ll(a,{data:t,scale:e=.5}){if(!Gt.get(a))return;const i=URL.createObjectURL(t),n=await Mt.fromURL(i);n.scale(e),Fl(a,n,e),URL.revokeObjectURL(i)}function Fl(a,t,e){const s=Gt.get(a);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function Lg(a,t){if(!t)return;const{oCoords:e}=a;if(!e)return;const{x:s,y:i}=e.tl.touchCorner.tl,{height:n,width:r,scaleY:o,scaleX:h}=t;t.top=i-n*o/2,t.left=s-r*h/2,t.setCoords()}function Fg(a,t,e){!e||!a||(e.scale(1/t),Lg(a,e))}function Ig(a,t){if(!a)return;const e=a._cornerSize||6;a.borderScaleFactor=1/t,a.cornerSize=e*(1/t),a.touchCornerSize=e*4*(1/t),a.setCoords()}function Ng(a){const t=Gt.get(a);t&&(t.discardActiveObject(),t.renderAll())}function jg(a){const t=Gt.get(a);t&&(t.clear(),Gt.delete(a))}function Bg(a,t){return new Mt(a,{scaleX:t,scaleY:t})}function Eo(a,t){if(!t)return;const{left:e,top:s,scaleX:i,scaleY:n,width:r,height:o}=a,h=t.x*r*i,l=t.y*o*n;a.set({left:e-h,top:s-l})}function Il(a,t,e){const s=a.type;return{"application/pdf":Hg,"image/png":jl,"image/jpeg":jl}[s]?.(a,t,e)??Promise.reject(new Error(`Unsupported ${s} file type.`))}async function Hg(a,t,e){const s=Pg(a),i=await Nl({page:1,data:a,scale:.8,password:t},e);return{...s,pages:i}}function Nl(a,t){return kg(a,t).then(({canvas:e,pages:s})=>(e&&t&&Dg(t,e),s))}async function jl(a,t,e){return await Rg(a,e)}function zg(a,t){const e=Gt.get(a);if(!e)return;const s=e.getActiveObject();s&&(s instanceof Jt?s.forEachObject(i=>{i.set(t)}):s.set(t),e.renderAll())}async function Gg(a,t){const e=Gt.get(a);if(!e)return;const s=e?.getActiveObject();if(!s)return;const i=await s.clone(Wl);i instanceof Jt?i.forEachObject(n=>{e.add(n),t(e,n)}):(e.add(i),t(e,i)),Eo(i,{x:-.1,y:-.1}),e.setActiveObject(i)}function Vg(a){const t=Gt.get(a);if(!t)return;const e=t.getActiveObject();e&&(e instanceof Jt?(e.forEachObject(s=>{t.remove(s)}),t.discardActiveObject()):t.remove(e))}function Bl(a){const{id:t="",selectionOptions:e,pointerDown:s,pointerMove:i,pointerUp:n,selectionCreated:r,selectionCleared:o}=a||{};let h=null,l=null,c=1,u={...Xl};function d(){if(!t||Gt.has(t))return;const k=Mg(t);return k.on("selection:created",O=>{if(r?.(O),O.selected.length<=1)return;const j=k.getActiveObject();j&&(l=j,e?.value&&l.set(e.value),l._cornerSize=l.cornerSize,S(c))}),k.on("selection:cleared",O=>{o?.(O),T(k)}),s&&k.on("mouse:down",s),i&&k.on("mouse:move",i),n&&k.on("mouse:up",n),k}function f(k,O){return Il(k,O,t)}function g(k){return Nl(k,t)}function p({data:k,scale:O=.5}){return Ll(t,{data:k,scale:O})}async function b(k,O,j){const M=Gt.get(t);if(!M)return;const R=await Mt.fromURL(k,{},{...$n,...O});Eo(R,j),M.add(R),v(M,R),M.setActiveObject(R)}function m(k,O,j){const M=Gt.get(t);if(!M)return;const R=new kt(k,{...Gl,...O});Eo(R,j),M.add(R),v(M,R),M.setActiveObject(R)}function v(k,O){O.on("selected",j=>y({canvas:k,target:j.target})),O.on("modified",j=>y({canvas:k,target:j.target})),O.on("scaling",()=>T(k)),O.on("moving",()=>T(k)),O.on("rotating",()=>T(k)),O._cornerSize=O._cornerSize??O.cornerSize}async function y({canvas:k,target:O,stroke:j=u.stroke,uuid:M=Date.now()}){if(k.getActiveObjects().length>1||h?.stroke===`${j}-${M}`)return;const G=await Og(u,M,j);T(k),h=G,l=O,_(k,O,M),S(c,!0),G&&k.add(G)}function _(k,O,j){h&&(h.on("selected",()=>{k.remove(O),T(k)}),h.on("mouseover",()=>{y({canvas:k,target:O,stroke:u.hoverStroke,uuid:j})}),h.on("mouseout",()=>{y({canvas:k,target:O,stroke:u.stroke,uuid:j})}))}function S(k,O=!1){const j=Gt.get(t);c=k,j&&(Ig(l,k),Fg(l,k,h),!O&&j.renderAll())}function A(k){if(!k)return;u={...u,...k};const O=Gt.get(t);!h||!l||!O||y({target:l,canvas:O})}function T(k){l=null,h&&(k.remove(h),h=null)}function E(){Ng(t)}function P(){jg(t)}function N(k){zg(t,k)}function D(){return Gg(t,v)}function L(){Vg(t)}return{createCanvas:d,loadFile:f,specifyPage:g,renderImage:p,addFabric:b,addTextFabric:m,clearActive:E,deleteCanvas:P,scaleFabric:S,setCloseSvgOptions:A,setActiveFabric:N,copyActiveFabric:D,deleteActiveFabric:L}}function Xg(a){let t=0;const e=Tg(()=>{t!==window.innerWidth&&(t=window.innerWidth,a())});W.onMounted(()=>{window.addEventListener("resize",e)}),W.onBeforeUnmount(()=>{window.removeEventListener("resize",e)})}const Wg=W.defineComponent({__name:"pdf-canvas",props:{file:{},page:{default:1},canvasId:{default:"PDF-canvas"},fileZoom:{default:1},fileScale:{default:1},canvasScale:{default:1},canvasClass:{default:""},isDrop:{type:Boolean,default:!1},password:{},dropTextOptions:{},dropImageOptions:{},selectionOptions:{},closeSvgOptions:{},manualReload:{type:Boolean},onDestroy:{type:Function,default:W.onBeforeUnmount}},emits:["loaded","reload","pointerDown","pointerMove","pointerUp","selectionCreated","selectionCleared"],setup(a,{expose:t,emit:e}){const s=a,i=e,{onDestroy:n}=s,r=W.ref(null),o=`${s.canvasId}-${s.page-1}`,h=W.computed(()=>s.fileZoom*s.canvasScale),l=W.computed(()=>({...Vl,...s.selectionOptions})),{createCanvas:c,specifyPage:u,addFabric:d,addTextFabric:f,renderImage:g,clearActive:p,deleteCanvas:b,scaleFabric:m,setActiveFabric:v,setCloseSvgOptions:y,copyActiveFabric:_,deleteActiveFabric:S}=Bl({id:o,selectionOptions:l,pointerDown:D=>i("pointerDown",D),pointerMove:D=>i("pointerMove",D),pointerUp:D=>i("pointerUp",D),selectionCreated:D=>i("selectionCreated",D),selectionCleared:D=>i("selectionCleared",D)});A(),Xg(N);async function A(){const{file:D,page:L,fileScale:k}=s;globalThis.requestAnimationFrame(async()=>{if(await W.nextTick(),c(),D.data?.type.startsWith("image/")){const j=D.data;j&&g({data:j,scale:k/3}),i("loaded");return}D.data&&await u({page:L,data:D.data,scale:k,password:s.password}),i("loaded")})}function T(D){if(!s.isDrop||!D.dataTransfer)return;const{dataTransfer:L,offsetX:k,offsetY:O}=D,j=L.getData("text/plain"),M=L.getData("text/uri-list"),R=L.getData("custom/offset"),G=R?JSON.parse(R):null,at={top:O,left:k},ct={x:G?.offsetX??0,y:G?.offsetY??0};M?E(M,at,ct):j&&P(j,at,ct)}function E(D,L,k){d(D,{...s.dropImageOptions,...L},k)}function P(D,L,k){f(D,{...s.dropTextOptions,...L},k)}function N(){s.manualReload||A(),i("reload")}return W.watch([()=>s.fileScale,()=>s.page,()=>s.file,()=>s.password],N),W.watch(h,D=>m(D),{immediate:!0}),W.watch(()=>s.closeSvgOptions,y,{immediate:!0}),n(b),t({reload:A,addImage:E,addText:P,clearActive:p,deleteCanvas:b,setActiveFabric:v,copyActiveFabric:_,deleteActiveFabric:S,canvasRef:r}),(D,L)=>(W.openBlock(),W.createElementBlock("div",{style:W.normalizeStyle({transform:`scale(${h.value})`}),onDragover:L[0]||(L[0]=W.withModifiers(()=>{},["prevent"])),onDragenter:L[1]||(L[1]=W.withModifiers(()=>{},["prevent"])),onDrop:W.withModifiers(T,["stop","prevent"])},[W.createElementVNode("canvas",{id:o,ref_key:"canvasRef",ref:r,class:W.normalizeClass(a.canvasClass)},null,2)],36))}});J.default=Wg,J.loadFile=Il,J.useFabric=Bl,Object.defineProperties(J,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@component-hook/pdf-canvas",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Rendering PDF documents onto a canvas with vue3 and react component",
5
5
  "license": "MIT",
6
6
  "type": "module",