diff --git a/HJGL_DS/FineUIPro.Web/HJGL/DataIn/DrawingRecognitionContent.aspx.cs b/HJGL_DS/FineUIPro.Web/HJGL/DataIn/DrawingRecognitionContent.aspx.cs index 4870883..0d034cf 100644 --- a/HJGL_DS/FineUIPro.Web/HJGL/DataIn/DrawingRecognitionContent.aspx.cs +++ b/HJGL_DS/FineUIPro.Web/HJGL/DataIn/DrawingRecognitionContent.aspx.cs @@ -358,24 +358,6 @@ namespace FineUIPro.Web.HJGL.DataIn dtIsoInfo.Columns.Add("insulation_thickness_mm"); dtIsoInfo.Columns.Add("post_weld_heat_treatment"); dtIsoInfo.Columns.Add("radiographic_examination"); - - // 遍历并提取数据 - foreach (JObject item in jArray) - { - var row = dt.NewRow(); - row["id"] = item.Value("id"); - row["pipe_no"] = item.Value("pipe_no"); - row["drawing_number"] = item.Value("drawing_number"); - row["seq_no"] = item.Value("seq_no"); - row["category"] = item.Value("category"); - row["description"] = item.Value("description"); - row["spec"] = item.Value("spec"); - row["qty"] = item.Value("qty"); - row["page_no"] = item.Value("page_no"); - row["remark"] = item.Value("remark"); - dt.Rows.Add(row); - } - foreach (JObject item in jArrayOther) { var row = dtOther.NewRow(); @@ -387,6 +369,30 @@ namespace FineUIPro.Web.HJGL.DataIn dtOther.Rows.Add(row); } + // 遍历并提取数据 + foreach (JObject item in jArray) + { + var row = dt.NewRow(); + row["id"] = item.Value("id"); + row["pipe_no"] = item.Value("pipe_no"); + row["drawing_number"] = item.Value("drawing_number"); + + row["seq_no"] = item.Value("seq_no"); + row["category"] = item.Value("category"); + row["description"] = item.Value("description"); + row["spec"] = item.Value("spec"); + row["qty"] = item.Value("qty"); + row["page_no"] = item.Value("page_no"); + row["remark"] = item.Value("remark"); + if (string.IsNullOrEmpty(row["drawing_number"].ToString())) + { + var rowOther = dtOther.Select("page= " + row["page_no"].ToString()).FirstOrDefault(); + row["drawing_number"] = rowOther["text"]; + } + dt.Rows.Add(row); + } + + foreach (JObject item in jArrayIsoInfo) { diff --git a/HJGL_DS/FineUIPro.Web/HJGL/DataIn/ocrz-app.js b/HJGL_DS/FineUIPro.Web/HJGL/DataIn/ocrz-app.js index 3d26278..a54517c 100644 --- a/HJGL_DS/FineUIPro.Web/HJGL/DataIn/ocrz-app.js +++ b/HJGL_DS/FineUIPro.Web/HJGL/DataIn/ocrz-app.js @@ -74,7 +74,7 @@ ${v}`:`[${v}]`}function u({row:d,column:h}){if(!d._flags)return{};const p=h.prop `),position:m,pageIndex:g-1,rect:u.slice(0),rotation:d,id:h,deleted:!1,popupRef:p}}const r=await super.deserialize(n,s,a);return q(r,ko,n.fontSize),q(r,Ir,$t.makeHexColor(...n.color)),q(r,xo,oe(i=Kn,Ol,p_).call(i,n.value)),r.annotationElementId=n.id||null,r._initialData=o,r}serialize(n=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const s=Kn._internalPadding*this.parentScale,a=this.getRect(s,s),o=as._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:y(this,Ir)),r={annotationType:rn.FREETEXT,color:o,fontSize:y(this,ko),value:oe(this,Cs,ZR).call(this),pageIndex:this.pageIndex,rect:a,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return n?r:this.annotationElementId&&!oe(this,Cs,QR).call(this,r)?null:(r.id=this.annotationElementId,r)}renderAnnotationElement(n){const s=super.renderAnnotationElement(n);if(this.deleted)return s;const{style:a}=s;a.fontSize=`calc(${y(this,ko)}px * var(--scale-factor))`,a.color=y(this,Ir),s.replaceChildren();for(const r of y(this,xo).split(` `)){const i=document.createElement("div");i.append(r?document.createTextNode(r):document.createElement("br")),s.append(i)}const o=Kn._internalPadding*this.parentScale;return n.updateEdited({rect:this.getRect(o,o),popupContent:y(this,xo)}),s}resetAnnotationElement(n){super.resetAnnotationElement(n),n.resetEdited()}};Ir=new WeakMap,xo=new WeakMap,Bm=new WeakMap,$d=new WeakMap,ko=new WeakMap,Cs=new WeakSet,YR=function(n){const s=o=>{this.editorDiv.style.fontSize=`calc(${o}px * var(--scale-factor))`,this.translate(0,-(o-y(this,ko))*this.parentScale),q(this,ko,o),oe(this,Cs,e4).call(this)},a=y(this,ko);this.addCommands({cmd:s.bind(this,n),undo:s.bind(this,a),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:gn.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})},XR=function(n){const s=o=>{q(this,Ir,this.editorDiv.style.color=o)},a=y(this,Ir);this.addCommands({cmd:s.bind(this,n),undo:s.bind(this,a),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:gn.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})},JR=function(){var a;const n=[];this.editorDiv.normalize();let s=null;for(const o of this.editorDiv.childNodes)(s==null?void 0:s.nodeType)===Node.TEXT_NODE&&o.nodeName==="BR"||(n.push(oe(a=Kn,Ol,t4).call(a,o)),s=o);return n.join(` `)},e4=function(){const[n,s]=this.parentDimensions;let a;if(this.isAttachedToDOM)a=this.div.getBoundingClientRect();else{const{currentLayer:o,div:r}=this,i=r.style.display,l=r.classList.contains("hidden");r.classList.remove("hidden"),r.style.display="hidden",o.div.append(this.div),a=r.getBoundingClientRect(),r.remove(),r.style.display=i,r.classList.toggle("hidden",l)}this.rotation%180===this.parentRotation%180?(this.width=a.width/n,this.height=a.height/s):(this.width=a.height/n,this.height=a.width/s),this.fixAndSetPosition()},Ol=new WeakSet,t4=function(n){return(n.nodeType===Node.TEXT_NODE?n.nodeValue:n.innerText).replaceAll(cb,"")},n4=function(){if(this.editorDiv.replaceChildren(),!!y(this,xo))for(const n of y(this,xo).split(` -`)){const s=document.createElement("div");s.append(n?document.createTextNode(n):document.createElement("br")),this.editorDiv.append(s)}},ZR=function(){return y(this,xo).replaceAll(" "," ")},p_=function(n){return n.replaceAll(" "," ")},QR=function(n){const{value:s,fontSize:a,color:o,pageIndex:r}=this._initialData;return this._hasBeenMoved||n.value!==s||n.fontSize!==a||n.color.some((i,l)=>i!==o[l])||n.pageIndex!==r},se(Kn,Ol),Wt(Kn,"_freeTextDefaultContent",""),Wt(Kn,"_internalPadding",0),Wt(Kn,"_defaultColor",null),Wt(Kn,"_defaultFontSize",10),Wt(Kn,"_type","freetext"),Wt(Kn,"_editorType",rn.FREETEXT);let ww=Kn;class At{toSVGPath(){Vn("Abstract method `toSVGPath` must be implemented.")}get box(){Vn("Abstract getter `box` must be implemented.")}serialize(t,n){Vn("Abstract method `serialize` must be implemented.")}static _rescale(t,n,s,a,o,r){r||(r=new Float32Array(t.length));for(let i=0,l=t.length;i=6;a-=6)isNaN(n[a])?s.push(`L${n[a+4]} ${n[a+5]}`):s.push(`C${n[a]} ${n[a+1]} ${n[a+2]} ${n[a+3]} ${n[a+4]} ${n[a+5]}`);return oe(this,Rs,tI).call(this,s),s.join(" ")}newFreeDrawOutline(t,n,s,a,o,r){return new tR(t,n,s,a,o,r)}getOutlines(){var d;const t=y(this,Ci),n=y(this,Or),s=y(this,hn),[a,o,r,i]=y(this,Eo),l=new Float32Array((((d=y(this,Wc))==null?void 0:d.length)??0)+2);for(let h=0,p=l.length-2;h=6;h-=6)for(let p=0;p<6;p+=2){if(isNaN(n[h+p])){c[u]=c[u+1]=NaN,u+=2;continue}c[u]=n[h+p],c[u+1]=n[h+p+1],u+=2}return oe(this,Rs,aI).call(this,c,u),this.newFreeDrawOutline(c,l,y(this,Eo),y(this,t0),y(this,Qh),y(this,e0))}};Eo=new WeakMap,Or=new WeakMap,Qh=new WeakMap,e0=new WeakMap,Ci=new WeakMap,hn=new WeakMap,Dd=new WeakMap,Fd=new WeakMap,Vm=new WeakMap,zm=new WeakMap,t0=new WeakMap,n0=new WeakMap,Wc=new WeakMap,Hm=new WeakMap,Mb=new WeakMap,Pb=new WeakMap,Rs=new WeakSet,v2=function(){const t=y(this,hn).subarray(4,6),n=y(this,hn).subarray(16,18),[s,a,o,r]=y(this,Eo);return[(y(this,Dd)+(t[0]-n[0])/2-s)/o,(y(this,Fd)+(t[1]-n[1])/2-a)/r,(y(this,Dd)+(n[0]-t[0])/2-s)/o,(y(this,Fd)+(n[1]-t[1])/2-a)/r]},eI=function(){const[t,n,s,a]=y(this,Eo),[o,r,i,l]=oe(this,Rs,v2).call(this);return`M${(y(this,hn)[2]-t)/s} ${(y(this,hn)[3]-n)/a} L${(y(this,hn)[4]-t)/s} ${(y(this,hn)[5]-n)/a} L${o} ${r} L${i} ${l} L${(y(this,hn)[16]-t)/s} ${(y(this,hn)[17]-n)/a} L${(y(this,hn)[14]-t)/s} ${(y(this,hn)[15]-n)/a} Z`},tI=function(t){const n=y(this,Or);t.push(`L${n[4]} ${n[5]} Z`)},nI=function(t){const[n,s,a,o]=y(this,Eo),r=y(this,hn).subarray(4,6),i=y(this,hn).subarray(16,18),[l,c,u,d]=oe(this,Rs,v2).call(this);t.push(`L${(r[0]-n)/a} ${(r[1]-s)/o} L${l} ${c} L${u} ${d} L${(i[0]-n)/a} ${(i[1]-s)/o}`)},sI=function(t){const n=y(this,hn),[s,a,o,r]=y(this,Eo),[i,l,c,u]=oe(this,Rs,v2).call(this),d=new Float32Array(36);return d.set([NaN,NaN,NaN,NaN,(n[2]-s)/o,(n[3]-a)/r,NaN,NaN,NaN,NaN,(n[4]-s)/o,(n[5]-a)/r,NaN,NaN,NaN,NaN,i,l,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,(n[16]-s)/o,(n[17]-a)/r,NaN,NaN,NaN,NaN,(n[14]-s)/o,(n[15]-a)/r],0),this.newFreeDrawOutline(d,t,y(this,Eo),y(this,t0),y(this,Qh),y(this,e0))},aI=function(t,n){const s=y(this,Or);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],n),n+=6},oI=function(t,n){const s=y(this,hn).subarray(4,6),a=y(this,hn).subarray(16,18),[o,r,i,l]=y(this,Eo),[c,u,d,h]=oe(this,Rs,v2).call(this);return t.set([NaN,NaN,NaN,NaN,(s[0]-o)/i,(s[1]-r)/l,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,d,h,NaN,NaN,NaN,NaN,(a[0]-o)/i,(a[1]-r)/l],n),n+=24},se(Ll,Hm,8),se(Ll,Mb,2),se(Ll,Pb,y(Ll,Hm)+y(Ll,Mb));let ub=Ll;class tR extends At{constructor(n,s,a,o,r,i){super();se(this,Rb);se(this,s0);se(this,Bd,new Float32Array(4));se(this,Nl);se(this,Wm);se(this,Ao);se(this,jm);se(this,ps);q(this,ps,n),q(this,Ao,s),q(this,s0,a),q(this,jm,o),q(this,Nl,r),q(this,Wm,i),this.lastPoint=[NaN,NaN],oe(this,Rb,rI).call(this,i);const[l,c,u,d]=y(this,Bd);for(let h=0,p=n.length;hn[0]-s[0]||n[1]-s[1]||n[2]-s[2]);const t=[];for(const n of y(this,jc))n[3]?(t.push(...oe(this,Da,v_).call(this,n)),oe(this,Da,lI).call(this,n)):(oe(this,Da,cI).call(this,n),t.push(...oe(this,Da,v_).call(this,n)));return oe(this,Da,iI).call(this,t)}}Km=new WeakMap,Um=new WeakMap,jc=new WeakMap,Lr=new WeakMap,Da=new WeakSet,iI=function(t){const n=[],s=new Set;for(const r of t){const[i,l,c]=r;n.push([i,l,r],[i,c,r])}n.sort((r,i)=>r[1]-i[1]||r[0]-i[0]);for(let r=0,i=n.length;r0;){const r=s.values().next().value;let[i,l,c,u,d]=r;s.delete(r);let h=i,p=l;for(o=[i,c],a.push(o);;){let v;if(s.has(u))v=u;else if(s.has(d))v=d;else break;s.delete(v),[i,l,c,u,d]=v,h!==i&&(o.push(h,p,i,p===l?l:c),h=i),p=p===l?c:l}o.push(h,p)}return new N4e(a,y(this,Km),y(this,Um))},s4=function(t){const n=y(this,Lr);let s=0,a=n.length-1;for(;s<=a;){const o=s+a>>1,r=n[o][0];if(r===t)return o;r=0;a--){const[o,r]=y(this,Lr)[a];if(o!==t)break;if(o===t&&r===n){y(this,Lr).splice(a,1);return}}},v_=function(t){const[n,s,a]=t,o=[[n,s,a]],r=oe(this,Da,s4).call(this,a);for(let i=0;i=l){if(p>c)o[u][1]=c;else{if(d===1)return[];o.splice(u,1),u--,d--}continue}o[u][2]=l,p>c&&o.push([n,c,p])}}}return o};class N4e extends At{constructor(n,s,a){super();se(this,qm);se(this,a0);q(this,a0,n),q(this,qm,s),this.lastPoint=a}toSVGPath(){const n=[];for(const s of y(this,a0)){let[a,o]=s;n.push(`M${a} ${o}`);for(let r=2;r-1?(q(this,Zs,!0),oe(this,an,a4).call(this,n),oe(this,an,rf).call(this)):y(this,$l)&&(q(this,l0,n.anchorNode),q(this,Zm,n.anchorOffset),q(this,Qm,n.focusNode),q(this,e2,n.focusOffset),oe(this,an,y_).call(this),oe(this,an,rf).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const n=xn.prototype;return fn(this,"_keyboardManager",new Ev([[["ArrowLeft","mac+ArrowLeft"],n._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],n._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],n._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],n._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:y(this,Zs)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:y(this,Yo),methodOfCreation:y(this,t2)}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(n){return{numberOfColors:n.get("color").size}}static initialize(n,s){var a;as.initialize(n,s),xn._defaultColor||(xn._defaultColor=((a=s.highlightColors)==null?void 0:a.values().next().value)||"#fff066")}static updateDefaultParams(n,s){switch(n){case gn.HIGHLIGHT_DEFAULT_COLOR:xn._defaultColor=s;break;case gn.HIGHLIGHT_THICKNESS:xn._defaultThickness=s;break}}translateInPage(n,s){}get toolbarPosition(){return y(this,u0)}updateParams(n,s){switch(n){case gn.HIGHLIGHT_COLOR:oe(this,an,dI).call(this,s);break;case gn.HIGHLIGHT_THICKNESS:oe(this,an,fI).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[gn.HIGHLIGHT_DEFAULT_COLOR,xn._defaultColor],[gn.HIGHLIGHT_THICKNESS,xn._defaultThickness]]}get propertiesToUpdate(){return[[gn.HIGHLIGHT_COLOR,this.color||xn._defaultColor],[gn.HIGHLIGHT_THICKNESS,y(this,Yo)||xn._defaultThickness],[gn.HIGHLIGHT_FREE,y(this,Zs)]]}async addEditToolbar(){const n=await super.addEditToolbar();return n?(this._uiManager.highlightColors&&(q(this,c0,new db({editor:this})),n.addColorPicker(y(this,c0))),n):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(oe(this,an,m2).call(this))}getBaseTranslation(){return[0,0]}getRect(n,s){return super.getRect(n,s,oe(this,an,m2).call(this))}onceAdded(n){this.annotationElementId||this.parent.addUndoableEditor(this),n&&this.div.focus()}remove(){oe(this,an,w_).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(oe(this,an,rf).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(n){var a;let s=!1;this.parent&&!n?oe(this,an,w_).call(this):n&&(oe(this,an,rf).call(this,n),s=!this.parent&&((a=this.div)==null?void 0:a.classList.contains("selectedEditor"))),super.setParent(n),this.show(this._isVisible),s&&this.select()}rotate(n){var o,r,i;const{drawLayer:s}=this.parent;let a;y(this,Zs)?(n=(n-this.rotation+360)%360,a=oe(o=xn,Xo,M0).call(o,y(this,Go).box,n)):a=oe(r=xn,Xo,M0).call(r,[this.x,this.y,this.width,this.height],n),s.updateProperties(y(this,To),{bbox:a,root:{"data-main-rotation":n}}),s.updateProperties(y(this,wa),{bbox:oe(i=xn,Xo,M0).call(i,y(this,ao).box,n),root:{"data-main-rotation":n}})}render(){if(this.div)return this.div;const n=super.render();y(this,d0)&&(n.setAttribute("aria-label",y(this,d0)),n.setAttribute("role","mark")),y(this,Zs)?n.classList.add("free"):this.div.addEventListener("keydown",oe(this,an,pI).bind(this),{signal:this._uiManager._signal});const s=q(this,Hd,document.createElement("div"));n.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=y(this,zd);const[a,o]=this.parentDimensions;return this.setDims(this.width*a,this.height*o),tb(this,y(this,Hd),["pointerover","pointerleave"]),this.enableEditing(),n}pointerover(){var n;this.isSelected||(n=this.parent)==null||n.drawLayer.updateProperties(y(this,wa),{rootClass:{hovered:!0}})}pointerleave(){var n;this.isSelected||(n=this.parent)==null||n.drawLayer.updateProperties(y(this,wa),{rootClass:{hovered:!1}})}_moveCaret(n){switch(this.parent.unselect(this),n){case 0:case 2:oe(this,an,o4).call(this,!0);break;case 1:case 3:oe(this,an,o4).call(this,!1);break}}select(){var n;super.select(),y(this,wa)&&((n=this.parent)==null||n.drawLayer.updateProperties(y(this,wa),{rootClass:{hovered:!1,selected:!0}}))}unselect(){var n;super.unselect(),y(this,wa)&&((n=this.parent)==null||n.drawLayer.updateProperties(y(this,wa),{rootClass:{selected:!1}}),y(this,Zs)||oe(this,an,o4).call(this,!1))}get _mustFixPosition(){return!y(this,Zs)}show(n=this._isVisible){super.show(n),this.parent&&(this.parent.drawLayer.updateProperties(y(this,To),{rootClass:{hidden:!n}}),this.parent.drawLayer.updateProperties(y(this,wa),{rootClass:{hidden:!n}}))}static startHighlighting(n,s,{target:a,x:o,y:r}){const{x:i,y:l,width:c,height:u}=a.getBoundingClientRect(),d=new AbortController,h=n.combinedSignal(d),p=v=>{d.abort(),oe(this,Xo,bI).call(this,n,v)};window.addEventListener("blur",p,{signal:h}),window.addEventListener("pointerup",p,{signal:h}),window.addEventListener("pointerdown",go,{capture:!0,passive:!1,signal:h}),window.addEventListener("contextmenu",xr,{signal:h}),a.addEventListener("pointermove",oe(this,Xo,gI).bind(this,n),{signal:h}),this._freeHighlight=new Cw({x:o,y:r},[i,l,c,u],n.scale,this._defaultThickness/2,s,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=n.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 async deserialize(n,s,a){var m,g,b,_;let o=null;if(n instanceof QP){const{data:{quadPoints:w,rect:C,rotation:x,id:k,color:T,opacity:R,popupRef:I},parent:{page:{pageNumber:M}}}=n;o=n={annotationType:rn.HIGHLIGHT,color:Array.from(T),opacity:R,quadPoints:w,boxes:null,pageIndex:M-1,rect:C.slice(0),rotation:x,id:k,deleted:!1,popupRef:I}}else if(n instanceof yw){const{data:{inkLists:w,rect:C,rotation:x,id:k,color:T,borderStyle:{rawWidth:R},popupRef:I},parent:{page:{pageNumber:M}}}=n;o=n={annotationType:rn.HIGHLIGHT,color:Array.from(T),thickness:R,inkLists:w,boxes:null,pageIndex:M-1,rect:C.slice(0),rotation:x,id:k,deleted:!1,popupRef:I}}const{color:r,quadPoints:i,inkLists:l,opacity:c}=n,u=await super.deserialize(n,s,a);u.color=$t.makeHexColor(...r),q(u,Dl,c||1),l&&q(u,Yo,n.thickness),u.annotationElementId=n.id||null,u._initialData=o;const[d,h]=u.pageDimensions,[p,v]=u.pageTranslation;if(i){const w=q(u,$l,[]);for(let C=0;C=0)q(this,To,s),q(this,zd,a),this.parent.drawLayer.finalizeDraw(s,{bbox:n.box,path:{d:n.toSVGPath()}}),q(this,wa,this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:y(this,ao).box,path:{d:y(this,ao).toSVGPath()}},!0));else if(this.parent){const p=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(y(this,To),{bbox:oe(d=xn,Xo,M0).call(d,y(this,Go).box,(p-this.rotation+360)%360),path:{d:n.toSVGPath()}}),this.parent.drawLayer.updateProperties(y(this,wa),{bbox:oe(h=xn,Xo,M0).call(h,y(this,ao).box,p),path:{d:y(this,ao).toSVGPath()}})}const[r,i,l,c]=n.box;switch(this.rotation){case 0:this.x=r,this.y=i,this.width=l,this.height=c;break;case 90:{const[p,v]=this.parentDimensions;this.x=i,this.y=1-r,this.width=l*v/p,this.height=c*p/v;break}case 180:this.x=1-r,this.y=1-i,this.width=l,this.height=c;break;case 270:{const[p,v]=this.parentDimensions;this.x=1-i,this.y=r,this.width=l*v/p,this.height=c*p/v;break}}const{lastPoint:u}=y(this,ao);q(this,u0,[(u[0]-r)/l,(u[1]-i)/c])},dI=function(n){const s=(r,i)=>{var l,c;this.color=r,q(this,Dl,i),(l=this.parent)==null||l.drawLayer.updateProperties(y(this,To),{root:{fill:r,"fill-opacity":i}}),(c=y(this,c0))==null||c.updateColor(r)},a=this.color,o=y(this,Dl);this.addCommands({cmd:s.bind(this,n,xn._defaultOpacity),undo:s.bind(this,a,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:gn.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(n)},!0)},fI=function(n){const s=y(this,Yo),a=o=>{q(this,Yo,o),oe(this,an,hI).call(this,o)};this.addCommands({cmd:a.bind(this,n),undo:a.bind(this,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:gn.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:n},!0)},hI=function(n){if(!y(this,Zs))return;oe(this,an,a4).call(this,{highlightOutlines:y(this,Go).getNewOutline(n/2)}),this.fixAndSetPosition();const[s,a]=this.parentDimensions;this.setDims(this.width*s,this.height*a)},w_=function(){y(this,To)===null||!this.parent||(this.parent.drawLayer.remove(y(this,To)),q(this,To,null),this.parent.drawLayer.remove(y(this,wa)),q(this,wa,null))},rf=function(n=this.parent){y(this,To)===null&&({id:za(this,To)._,clipPathId:za(this,zd)._}=n.drawLayer.draw({bbox:y(this,Go).box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":y(this,Dl)},rootClass:{highlight:!0,free:y(this,Zs)},path:{d:y(this,Go).toSVGPath()}},!1,!0),q(this,wa,n.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:y(this,Zs)},bbox:y(this,ao).box,path:{d:y(this,ao).toSVGPath()}},y(this,Zs))),y(this,Hd)&&(y(this,Hd).style.clipPath=y(this,zd)))},Xo=new WeakSet,M0=function([n,s,a,o],r){switch(r){case 90:return[1-s-o,n,o,a];case 180:return[1-n-a,1-s-o,a,o];case 270:return[s,1-n-a,o,a]}return[n,s,a,o]},pI=function(n){xn._keyboardManager.exec(this,n)},o4=function(n){if(!y(this,l0))return;const s=window.getSelection();n?s.setPosition(y(this,l0),y(this,Zm)):s.setPosition(y(this,Qm),y(this,e2))},m2=function(){return y(this,Zs)?this.rotation:0},vI=function(){if(y(this,Zs))return null;const[n,s]=this.pageDimensions,[a,o]=this.pageTranslation,r=y(this,$l),i=new Float32Array(r.length*8);let l=0;for(const{x:c,y:u,width:d,height:h}of r){const p=c*n+a,v=(1-u)*s+o;i[l]=i[l+4]=p,i[l+1]=i[l+3]=v,i[l+2]=i[l+6]=p+d*n,i[l+5]=i[l+7]=v-h*s,l+=8}return i},mI=function(n){return y(this,Go).serialize(n,oe(this,an,m2).call(this))},gI=function(n,s){this._freeHighlight.add(s)&&n.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},bI=function(n,s){this._freeHighlight.isEmpty()?n.drawLayer.remove(this._freeHighlightId):n.createAndAddNewEditor(s,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""},yI=function(n){const{color:s}=this._initialData;return n.color.some((a,o)=>a!==s[o])},se(xn,Xo),Wt(xn,"_defaultColor",null),Wt(xn,"_defaultOpacity",1),Wt(xn,"_defaultThickness",12),Wt(xn,"_type","highlight"),Wt(xn,"_editorType",rn.HIGHLIGHT),Wt(xn,"_freeHighlightId",-1),Wt(xn,"_freeHighlight",null),Wt(xn,"_freeHighlightClipId","");let fb=xn;class D4e{constructor(){se(this,Wd,Object.create(null))}updateProperty(t,n){this[t]=n,this.updateSVGProperty(t,n)}updateProperties(t){if(t)for(const[n,s]of Object.entries(t))this.updateProperty(n,s)}updateSVGProperty(t,n){y(this,Wd)[t]=n}toSVGProperties(){const t=y(this,Wd);return q(this,Wd,Object.create(null)),{root:t}}reset(){q(this,Wd,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){Vn("Not implemented")}}Wd=new WeakMap;const Rt=class Rt extends as{constructor(n){super(n);se(this,yn);se(this,Mo,null);se(this,f0);Wt(this,"_drawId",null);q(this,f0,n.mustBeCommitted||!1),n.drawOutlines&&(oe(this,yn,__).call(this,n),oe(this,yn,g2).call(this))}static _mergeSVGProperties(n,s){const a=new Set(Object.keys(n));for(const[o,r]of Object.entries(s))a.has(o)?Object.assign(n[o],r):n[o]=r;return n}static getDefaultDrawingOptions(n){Vn("Not implemented")}static get typesMap(){Vn("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(n,s){const a=this.typesMap.get(n);a&&this._defaultDrawingOptions.updateProperty(a,s),this._currentParent&&(y(Rt,zs).updateProperty(a,s),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(n,s){const a=this.constructor.typesMap.get(n);a&&this._updateProperty(n,a,s)}static get defaultPropertiesToUpdate(){const n=[],s=this._defaultDrawingOptions;for(const[a,o]of this.typesMap)n.push([a,s[o]]);return n}get propertiesToUpdate(){const n=[],{_drawingOptions:s}=this;for(const[a,o]of this.constructor.typesMap)n.push([a,s[o]]);return n}_updateProperty(n,s,a){const o=this._drawingOptions,r=o[s],i=l=>{var u;o.updateProperty(s,l);const c=y(this,Mo).updateProperty(s,l);c&&oe(this,yn,b2).call(this,c),(u=this.parent)==null||u.drawLayer.updateProperties(this._drawId,o.toSVGProperties())};this.addCommands({cmd:i.bind(this,a),undo:i.bind(this,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:n,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){var n;(n=this.parent)==null||n.drawLayer.updateProperties(this._drawId,Rt._mergeSVGProperties(y(this,Mo).getPathResizingSVGProperties(oe(this,yn,r4).call(this)),{bbox:oe(this,yn,P0).call(this)}))}_onResized(){var n;(n=this.parent)==null||n.drawLayer.updateProperties(this._drawId,Rt._mergeSVGProperties(y(this,Mo).getPathResizedSVGProperties(oe(this,yn,r4).call(this)),{bbox:oe(this,yn,P0).call(this)}))}_onTranslating(n,s){var a;(a=this.parent)==null||a.drawLayer.updateProperties(this._drawId,{bbox:oe(this,yn,P0).call(this,n,s)})}_onTranslated(){var n;(n=this.parent)==null||n.drawLayer.updateProperties(this._drawId,Rt._mergeSVGProperties(y(this,Mo).getPathTranslatedSVGProperties(oe(this,yn,r4).call(this),this.parentDimensions),{bbox:oe(this,yn,P0).call(this)}))}_onStartDragging(){var n;(n=this.parent)==null||n.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){var n;(n=this.parent)==null||n.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(n){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,y(this,f0)&&(q(this,f0,!1),this.commit(),this.parent.setSelected(this),n&&this.isOnScreen&&this.div.focus())}remove(){oe(this,yn,S_).call(this),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(oe(this,yn,g2).call(this),oe(this,yn,b2).call(this,y(this,Mo).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(n){var a;let s=!1;this.parent&&!n?(this._uiManager.removeShouldRescale(this),oe(this,yn,S_).call(this)):n&&(this._uiManager.addShouldRescale(this),oe(this,yn,g2).call(this,n),s=!this.parent&&((a=this.div)==null?void 0:a.classList.contains("selectedEditor"))),super.setParent(n),s&&this.select()}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,Rt._mergeSVGProperties({bbox:oe(this,yn,P0).call(this)},y(this,Mo).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&oe(this,yn,b2).call(this,y(this,Mo).updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;const n=super.render();n.classList.add("draw");const s=document.createElement("div");n.append(s),s.setAttribute("aria-hidden","true"),s.className="internal";const[a,o]=this.parentDimensions;return this.setDims(this.width*a,this.height*o),this._uiManager.addShouldRescale(this),this.disableEditing(),n}static createDrawerInstance(n,s,a,o,r){Vn("Not implemented")}static startDrawing(n,s,a,o){var g;const{target:r,offsetX:i,offsetY:l,pointerId:c,pointerType:u}=o;if(y(Rt,qc)&&y(Rt,qc)!==u)return;const{viewport:{rotation:d}}=n,{width:h,height:p}=r.getBoundingClientRect(),v=q(Rt,jd,new AbortController),m=n.combinedSignal(v);if(y(Rt,Uc)||q(Rt,Uc,c),y(Rt,qc)??q(Rt,qc,u),window.addEventListener("pointerup",b=>{var _;y(Rt,Uc)===b.pointerId?this._endDraw(b):(_=y(Rt,Gc))==null||_.delete(b.pointerId)},{signal:m}),window.addEventListener("pointercancel",b=>{var _;y(Rt,Uc)===b.pointerId?this._currentParent.endDrawingSession():(_=y(Rt,Gc))==null||_.delete(b.pointerId)},{signal:m}),window.addEventListener("pointerdown",b=>{y(Rt,qc)===b.pointerType&&((y(Rt,Gc)||q(Rt,Gc,new Set)).add(b.pointerId),y(Rt,zs).isCancellable()&&(y(Rt,zs).removeLastElement(),y(Rt,zs).isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:m}),window.addEventListener("contextmenu",xr,{signal:m}),r.addEventListener("pointermove",this._drawMove.bind(this),{signal:m}),r.addEventListener("touchmove",b=>{b.timeStamp===y(Rt,Ud)&&go(b)},{signal:m}),n.toggleDrawing(),(g=s._editorUndoBar)==null||g.hide(),y(Rt,zs)){n.drawLayer.updateProperties(this._currentDrawId,y(Rt,zs).startNew(i,l,h,p,d));return}s.updateUIForDefaultProperties(this),q(Rt,zs,this.createDrawerInstance(i,l,h,p,d)),q(Rt,Kd,this.getDefaultDrawingOptions()),this._currentParent=n,{id:this._currentDrawId}=n.drawLayer.draw(this._mergeSVGProperties(y(Rt,Kd).toSVGProperties(),y(Rt,zs).defaultSVGProperties),!0,!1)}static _drawMove(n){var r;if(q(Rt,Ud,-1),!y(Rt,zs))return;const{offsetX:s,offsetY:a,pointerId:o}=n;if(y(Rt,Uc)===o){if(((r=y(Rt,Gc))==null?void 0:r.size)>=1){this._endDraw(n);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,y(Rt,zs).add(s,a)),q(Rt,Ud,n.timeStamp),go(n)}}static _cleanup(n){n&&(this._currentDrawId=-1,this._currentParent=null,q(Rt,zs,null),q(Rt,Kd,null),q(Rt,qc,null),q(Rt,Ud,NaN)),y(Rt,jd)&&(y(Rt,jd).abort(),q(Rt,jd,null),q(Rt,Uc,NaN),q(Rt,Gc,null))}static _endDraw(n){const s=this._currentParent;if(s){if(s.toggleDrawing(!0),this._cleanup(!1),n&&s.drawLayer.updateProperties(this._currentDrawId,y(Rt,zs).end(n.offsetX,n.offsetY)),this.supportMultipleDrawings){const a=y(Rt,zs),o=this._currentDrawId,r=a.getLastElement();s.addCommands({cmd:()=>{s.drawLayer.updateProperties(o,a.setLastElement(r))},undo:()=>{s.drawLayer.updateProperties(o,a.removeLastElement())},mustExec:!1,type:gn.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(n){const s=this._currentParent;if(!s)return null;if(s.toggleDrawing(!0),s.cleanUndoStack(gn.DRAW_STEP),!y(Rt,zs).isEmpty()){const{pageDimensions:[a,o],scale:r}=s,i=s.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:y(Rt,zs).getOutlines(a*r,o*r,r,this._INNER_MARGIN),drawingOptions:y(Rt,Kd),mustBeCommitted:!n});return this._cleanup(!0),i}return s.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(n){}static deserializeDraw(n,s,a,o,r,i){Vn("Not implemented")}static async deserialize(n,s,a){var d,h;const{rawDims:{pageWidth:o,pageHeight:r,pageX:i,pageY:l}}=s.viewport,c=this.deserializeDraw(i,l,o,r,this._INNER_MARGIN,n),u=await super.deserialize(n,s,a);return u.createDrawingOptions(n),oe(d=u,yn,__).call(d,{drawOutlines:c}),oe(h=u,yn,g2).call(h),u.onScaleChanging(),u.rotate(),u}serializeDraw(n){const[s,a]=this.pageTranslation,[o,r]=this.pageDimensions;return y(this,Mo).serialize([s,a,o,r],n)}renderAnnotationElement(n){return n.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};Mo=new WeakMap,f0=new WeakMap,zs=new WeakMap,jd=new WeakMap,Kd=new WeakMap,Uc=new WeakMap,qc=new WeakMap,Gc=new WeakMap,Ud=new WeakMap,yn=new WeakSet,__=function({drawOutlines:n,drawId:s,drawingOptions:a}){q(this,Mo,n),this._drawingOptions||(this._drawingOptions=a),s>=0?(this._drawId=s,this.parent.drawLayer.finalizeDraw(s,n.defaultProperties)):this._drawId=oe(this,yn,C_).call(this,n,this.parent),oe(this,yn,b2).call(this,n.box)},C_=function(n,s){const{id:a}=s.drawLayer.draw(Rt._mergeSVGProperties(this._drawingOptions.toSVGProperties(),n.defaultSVGProperties),!1,!1);return a},S_=function(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())},g2=function(n=this.parent){if(!(this._drawId!==null&&this.parent===n)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,n.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=oe(this,yn,C_).call(this,y(this,Mo),n)}},wI=function([n,s,a,o]){const{parentDimensions:[r,i],rotation:l}=this;switch(l){case 90:return[s,1-n,a*(i/r),o*(r/i)];case 180:return[1-n,1-s,a,o];case 270:return[1-s,n,a*(i/r),o*(r/i)];default:return[n,s,a,o]}},r4=function(){const{x:n,y:s,width:a,height:o,parentDimensions:[r,i],rotation:l}=this;switch(l){case 90:return[1-s,n,a*(r/i),o*(i/r)];case 180:return[1-n,1-s,a,o];case 270:return[s,1-n,a*(r/i),o*(i/r)];default:return[n,s,a,o]}},b2=function(n){if([this.x,this.y,this.width,this.height]=oe(this,yn,wI).call(this,n),this.div){this.fixAndSetPosition();const[s,a]=this.parentDimensions;this.setDims(this.width*s,this.height*a)}this._onResized()},P0=function(){const{x:n,y:s,width:a,height:o,rotation:r,parentRotation:i,parentDimensions:[l,c]}=this;switch((r*4+i)/90){case 1:return[1-s-o,n,o,a];case 2:return[1-n-a,1-s-o,a,o];case 3:return[s,1-n-a,o,a];case 4:return[n,s-a*(l/c),o*(c/l),a*(l/c)];case 5:return[1-s,n,a*(l/c),o*(c/l)];case 6:return[1-n-o*(c/l),1-s,o*(c/l),a*(l/c)];case 7:return[s-a*(l/c),1-n-o*(c/l),a*(l/c),o*(c/l)];case 8:return[n-a,s-o,a,o];case 9:return[1-s,n-a,o,a];case 10:return[1-n,1-s,a,o];case 11:return[s-o,1-n,o,a];case 12:return[n-o*(c/l),s,o*(c/l),a*(l/c)];case 13:return[1-s-a*(l/c),n-o*(c/l),a*(l/c),o*(c/l)];case 14:return[1-n,1-s-a*(l/c),o*(c/l),a*(l/c)];case 15:return[s,1-n,a*(l/c),o*(c/l)];default:return[n,s,a,o]}},Wt(Rt,"_currentDrawId",-1),Wt(Rt,"_currentParent",null),se(Rt,zs,null),se(Rt,jd,null),se(Rt,Kd,null),se(Rt,Uc,NaN),se(Rt,qc,null),se(Rt,Gc,null),se(Rt,Ud,NaN),Wt(Rt,"_INNER_MARGIN",3);let Sw=Rt;class F4e{constructor(t,n,s,a,o,r){se(this,p0);se(this,Si,new Float64Array(6));se(this,Hs);se(this,Ws);se(this,qd);se(this,h0);se(this,Fa);se(this,Qs,"");se(this,Jo,0);se(this,Gd,new hb);se(this,Yd);se(this,Xd);q(this,Yd,s),q(this,Xd,a),q(this,qd,o),q(this,h0,r),[t,n]=oe(this,p0,i4).call(this,t,n);const i=q(this,Hs,[NaN,NaN,NaN,NaN,t,n]);q(this,Fa,[t,n]),q(this,Ws,[{line:i,points:y(this,Fa)}]),y(this,Si).set(i,0)}updateProperty(t,n){t==="stroke-width"&&q(this,h0,n)}isEmpty(){return!y(this,Ws)||y(this,Ws).length===0}isCancellable(){return y(this,Fa).length<=10}add(t,n){[t,n]=oe(this,p0,i4).call(this,t,n);const[s,a,o,r]=y(this,Si).subarray(2,6),i=t-o,l=n-r;return Math.hypot(y(this,Yd)*i,y(this,Xd)*l)<=2?null:(y(this,Fa).push(t,n),isNaN(s)?(y(this,Si).set([o,r,t,n],2),y(this,Hs).push(NaN,NaN,NaN,NaN,t,n),{path:{d:this.toSVGPath()}}):(isNaN(y(this,Si)[0])&&y(this,Hs).splice(6,6),y(this,Si).set([s,a,o,r,t,n],0),y(this,Hs).push(...At.createBezierPoints(s,a,o,r,t,n)),{path:{d:this.toSVGPath()}}))}end(t,n){const s=this.add(t,n);return s||(y(this,Fa).length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,n,s,a,o){q(this,Yd,s),q(this,Xd,a),q(this,qd,o),[t,n]=oe(this,p0,i4).call(this,t,n);const r=q(this,Hs,[NaN,NaN,NaN,NaN,t,n]);q(this,Fa,[t,n]);const i=y(this,Ws).at(-1);return i&&(i.line=new Float32Array(i.line),i.points=new Float32Array(i.points)),y(this,Ws).push({line:r,points:y(this,Fa)}),y(this,Si).set(r,0),q(this,Jo,0),this.toSVGPath(),null}getLastElement(){return y(this,Ws).at(-1)}setLastElement(t){return y(this,Ws)?(y(this,Ws).push(t),q(this,Hs,t.line),q(this,Fa,t.points),q(this,Jo,0),{path:{d:this.toSVGPath()}}):y(this,Gd).setLastElement(t)}removeLastElement(){if(!y(this,Ws))return y(this,Gd).removeLastElement();y(this,Ws).pop(),q(this,Qs,"");for(let t=0,n=y(this,Ws).length;tC??NaN),h,p,v,m),points:g(l[_].map(C=>C??NaN),h,p,v,m)});const b=new Ow;return b.build(d,a,o,1,c,u,r),b}get box(){return y(this,Ba)}updateProperty(n,s){return n==="stroke-width"?oe(this,ea,SI).call(this,s):null}updateParentDimensions([n,s],a){const[o,r]=oe(this,ea,Kl).call(this);q(this,xi,n),q(this,ki,s),q(this,v0,a);const[i,l]=oe(this,ea,Kl).call(this),c=i-o,u=l-r,d=y(this,Ba);return d[0]-=c,d[1]-=u,d[2]+=2*c,d[3]+=2*u,d}updateRotation(n){return q(this,n2,n),{path:{transform:this.rotationTransform}}}get viewBox(){return y(this,Ba).map(At.svgRound).join(" ")}get defaultProperties(){const[n,s]=y(this,Ba);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${At.svgRound(n)} ${At.svgRound(s)}`}}}get rotationTransform(){const[,,n,s]=y(this,Ba);let a=0,o=0,r=0,i=0,l=0,c=0;switch(y(this,n2)){case 90:o=s/n,r=-n/s,l=n;break;case 180:a=-1,i=-1,l=n,c=s;break;case 270:o=-s/n,r=n/s,c=s;break;default:return""}return`matrix(${a} ${o} ${r} ${i} ${At.svgRound(l)} ${At.svgRound(c)})`}getPathResizingSVGProperties([n,s,a,o]){const[r,i]=oe(this,ea,Kl).call(this),[l,c,u,d]=y(this,Ba);if(Math.abs(u-r)<=At.PRECISION||Math.abs(d-i)<=At.PRECISION){const g=n+a/2-(l+u/2),b=s+o/2-(c+d/2);return{path:{"transform-origin":`${At.svgRound(n)} ${At.svgRound(s)}`,transform:`${this.rotationTransform} translate(${g} ${b})`}}}const h=(a-2*r)/(u-2*r),p=(o-2*i)/(d-2*i),v=u/a,m=d/o;return{path:{"transform-origin":`${At.svgRound(l)} ${At.svgRound(c)}`,transform:`${this.rotationTransform} scale(${v} ${m}) translate(${At.svgRound(r)} ${At.svgRound(i)}) scale(${h} ${p}) translate(${At.svgRound(-r)} ${At.svgRound(-i)})`}}}getPathResizedSVGProperties([n,s,a,o]){const[r,i]=oe(this,ea,Kl).call(this),l=y(this,Ba),[c,u,d,h]=l;if(l[0]=n,l[1]=s,l[2]=a,l[3]=o,Math.abs(d-r)<=At.PRECISION||Math.abs(h-i)<=At.PRECISION){const b=n+a/2-(c+d/2),_=s+o/2-(u+h/2);for(const{line:w,points:C}of y(this,Po))At._translate(w,b,_,w),At._translate(C,b,_,C);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${At.svgRound(n)} ${At.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const p=(a-2*r)/(d-2*r),v=(o-2*i)/(h-2*i),m=-p*(c+r)+n+r,g=-v*(u+i)+s+i;if(p!==1||v!==1||m!==0||g!==0)for(const{line:b,points:_}of y(this,Po))At._rescale(b,m,g,p,v,b),At._rescale(_,m,g,p,v,_);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${At.svgRound(n)} ${At.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([n,s],a){const[o,r]=a,i=y(this,Ba),l=n-i[0],c=s-i[1];if(y(this,xi)===o&&y(this,ki)===r)for(const{line:u,points:d}of y(this,Po))At._translate(u,l,c,u),At._translate(d,l,c,d);else{const u=y(this,xi)/o,d=y(this,ki)/r;q(this,xi,o),q(this,ki,r);for(const{line:h,points:p}of y(this,Po))At._rescale(h,l,c,u,d,h),At._rescale(p,l,c,u,d,p);i[2]*=u,i[3]*=d}return i[0]=n,i[1]=s,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${At.svgRound(n)} ${At.svgRound(s)}`}}}get defaultSVGProperties(){const n=y(this,Ba);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${At.svgRound(n[0])} ${At.svgRound(n[1])}`,transform:this.rotationTransform||null},bbox:n}}};Ba=new WeakMap,n2=new WeakMap,s2=new WeakMap,Po=new WeakMap,xi=new WeakMap,ki=new WeakMap,v0=new WeakMap,m0=new WeakMap,g0=new WeakMap,ea=new WeakSet,Kl=function(n=y(this,g0)){const s=y(this,s2)+n/2*y(this,v0);return y(this,m0)%180===0?[s/y(this,xi),s/y(this,ki)]:[s/y(this,ki),s/y(this,xi)]},_I=function(){const[n,s,a,o]=y(this,Ba),[r,i]=oe(this,ea,Kl).call(this,0);return[n+r,s+i,a-2*r,o-2*i]},CI=function(){const n=q(this,Ba,new Float32Array([1/0,1/0,-1/0,-1/0]));for(const{line:o}of y(this,Po)){if(o.length<=12){for(let l=4,c=o.length;li!==s[l])||n.thickness!==a||n.opacity!==o||n.pageIndex!==r},Wt(y0,"_type","ink"),Wt(y0,"_editorType",rn.INK),Wt(y0,"_defaultDrawingOptions",null);let kw=y0;const a2=class a2 extends as{constructor(n){super({...n,name:"stampEditor"});se(this,_n);se(this,rs,null);se(this,ta,null);se(this,Yc,null);se(this,Fl,null);se(this,Xc,null);se(this,w0,"");se(this,Ei,null);se(this,Ai,null);se(this,Ro,!1);se(this,_0,!1);q(this,Fl,n.bitmapUrl),q(this,Xc,n.bitmapFile)}static initialize(n,s){as.initialize(n,s)}static get supportedTypes(){return fn(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return fn(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(n){return this.supportedTypes.includes(n)}static paste(n,s){s.pasteEditor(rn.STAMP,{bitmapFile:n.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){var n;return{type:"stamp",hasAltText:!!((n=this.altTextData)!=null&&n.altText)}}static computeTelemetryFinalData(n){const s=n.get("hasAltText");return{hasAltText:s.get(!0)??0,hasNoAltText:s.get(!1)??0}}async mlGuessAltText(n=null,s=!0){if(this.hasAltTextData())return null;const{mlManager:a}=this._uiManager;if(!a)throw new Error("No ML.");if(!await a.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:o,width:r,height:i}=n||this.copyCanvas(null,null,!0).imageData,l=await a.guess({name:"altText",request:{data:o,width:r,height:i,channels:o.length/(r*i)}});if(!l)throw new Error("No response from the AI service.");if(l.error)throw new Error("Error from the AI service.");if(l.cancel)return null;if(!l.output)throw new Error("No valid response from the AI service.");const c=l.output;return await this.setGuessedAltText(c),s&&!this.hasAltTextData()&&(this.altTextData={alt:c,decorative:!1}),c}remove(){var n;y(this,ta)&&(q(this,rs,null),this._uiManager.imageManager.deleteId(y(this,ta)),(n=y(this,Ei))==null||n.remove(),q(this,Ei,null),y(this,Ai)&&(clearTimeout(y(this,Ai)),q(this,Ai,null))),super.remove()}rebuild(){if(!this.parent){y(this,ta)&&oe(this,_n,l4).call(this);return}super.rebuild(),this.div!==null&&(y(this,ta)&&y(this,Ei)===null&&oe(this,_n,l4).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(n){this._isDraggable=!0,n&&this.div.focus()}isEmpty(){return!(y(this,Yc)||y(this,rs)||y(this,Fl)||y(this,Xc)||y(this,ta))}get isResizable(){return!0}render(){if(this.div)return this.div;let n,s;if(this.width&&(n=this.x,s=this.y),super.render(),this.div.hidden=!0,this.div.setAttribute("role","figure"),this.addAltTextButton(),y(this,rs)?oe(this,_n,x_).call(this):oe(this,_n,l4).call(this),this.width&&!this.annotationElementId){const[a,o]=this.parentDimensions;this.setAt(n*a,s*o,this.width*a,this.height*o)}return this._uiManager.addShouldRescale(this),this.div}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;y(this,Ai)!==null&&clearTimeout(y(this,Ai)),q(this,Ai,setTimeout(()=>{q(this,Ai,null),oe(this,_n,k_).call(this)},200))}copyCanvas(n,s,a=!1){var p;n||(n=224);const{width:o,height:r}=y(this,rs),i=new sw;let l=y(this,rs),c=o,u=r,d=null;if(s){if(o>s||r>s){const R=Math.min(s/o,s/r);c=Math.floor(o*R),u=Math.floor(r*R)}d=document.createElement("canvas");const v=d.width=Math.ceil(c*i.sx),m=d.height=Math.ceil(u*i.sy);y(this,Ro)||(l=oe(this,_n,c4).call(this,v,m));const g=d.getContext("2d");g.filter=this._uiManager.hcmFilter;let b="white",_="#cfcfd8";this._uiManager.hcmFilter!=="none"?_="black":(p=window.matchMedia)!=null&&p.call(window,"(prefers-color-scheme: dark)").matches&&(b="#8f8f9d",_="#42414d");const w=15,C=w*i.sx,x=w*i.sy,k=new OffscreenCanvas(C*2,x*2),T=k.getContext("2d");T.fillStyle=b,T.fillRect(0,0,C*2,x*2),T.fillStyle=_,T.fillRect(0,0,C,x),T.fillRect(C,x,C,x),g.fillStyle=g.createPattern(k,"repeat"),g.fillRect(0,0,v,m),g.drawImage(l,0,0,l.width,l.height,0,0,v,m)}let h=null;if(a){let v,m;if(i.symmetric&&l.widthn||r>n){const _=Math.min(n/o,n/r);v=Math.floor(o*_),m=Math.floor(r*_),y(this,Ro)||(l=oe(this,_n,c4).call(this,v,m))}const b=new OffscreenCanvas(v,m).getContext("2d",{willReadFrequently:!0});b.drawImage(l,0,0,l.width,l.height,0,0,v,m),h={width:v,height:m,data:b.getImageData(0,0,v,m).data}}return{canvas:d,width:c,height:u,imageData:h}}getImageForAltText(){return y(this,Ei)}static async deserialize(n,s,a){var m;let o=null;if(n instanceof eR){const{data:{rect:g,rotation:b,id:_,structParent:w,popupRef:C},container:x,parent:{page:{pageNumber:k}}}=n,T=x.querySelector("canvas"),R=a.imageManager.getFromCanvas(x.id,T);T.remove();const I=((m=await s._structTree.getAriaAttributes(`${Z8}${_}`))==null?void 0:m.get("aria-label"))||"";o=n={annotationType:rn.STAMP,bitmapId:R.id,bitmap:R.bitmap,pageIndex:k-1,rect:g.slice(0),rotation:b,id:_,deleted:!1,accessibilityData:{decorative:!1,altText:I},isSvg:!1,structParent:w,popupRef:C}}const r=await super.deserialize(n,s,a),{rect:i,bitmap:l,bitmapUrl:c,bitmapId:u,isSvg:d,accessibilityData:h}=n;u&&a.imageManager.isValidId(u)?(q(r,ta,u),l&&q(r,rs,l)):q(r,Fl,c),q(r,Ro,d);const[p,v]=r.pageDimensions;return r.width=(i[2]-i[0])/p,r.height=(i[3]-i[1])/v,r.annotationElementId=n.id||null,h&&(r.altTextData=h),r._initialData=o,q(r,_0,!!o),r}serialize(n=!1,s=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const a={annotationType:rn.STAMP,bitmapId:y(this,ta),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:y(this,Ro),structTreeParentId:this._structTreeParentId};if(n)return a.bitmapUrl=oe(this,_n,u4).call(this,!0),a.accessibilityData=this.serializeAltText(!0),a;const{decorative:o,altText:r}=this.serializeAltText(!1);if(!o&&r&&(a.accessibilityData={type:"Figure",alt:r}),this.annotationElementId){const l=oe(this,_n,kI).call(this,a);if(l.isSame)return null;l.isSameAltText?delete a.accessibilityData:a.accessibilityData.structParent=this._initialData.structParent??-1}if(a.id=this.annotationElementId,s===null)return a;s.stamps||(s.stamps=new Map);const i=y(this,Ro)?(a.rect[2]-a.rect[0])*(a.rect[3]-a.rect[1]):null;if(!s.stamps.has(y(this,ta)))s.stamps.set(y(this,ta),{area:i,serialized:a}),a.bitmap=oe(this,_n,u4).call(this,!1);else if(y(this,Ro)){const l=s.stamps.get(y(this,ta));i>l.area&&(l.area=i,l.serialized.bitmap.close(),l.serialized.bitmap=oe(this,_n,u4).call(this,!1))}return a}renderAnnotationElement(n){return n.updateEdited({rect:this.getRect(0,0)}),null}};rs=new WeakMap,ta=new WeakMap,Yc=new WeakMap,Fl=new WeakMap,Xc=new WeakMap,w0=new WeakMap,Ei=new WeakMap,Ai=new WeakMap,Ro=new WeakMap,_0=new WeakMap,_n=new WeakSet,y2=function(n,s=!1){if(!n){this.remove();return}q(this,rs,n.bitmap),s||(q(this,ta,n.id),q(this,Ro,n.isSvg)),n.file&&q(this,w0,n.file.name),oe(this,_n,x_).call(this)},w2=function(){if(q(this,Yc,null),this._uiManager.enableWaiting(!1),!!y(this,Ei)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&y(this,rs)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&y(this,rs)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},l4=function(){if(y(this,ta)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(y(this,ta)).then(a=>oe(this,_n,y2).call(this,a,!0)).finally(()=>oe(this,_n,w2).call(this));return}if(y(this,Fl)){const a=y(this,Fl);q(this,Fl,null),this._uiManager.enableWaiting(!0),q(this,Yc,this._uiManager.imageManager.getFromUrl(a).then(o=>oe(this,_n,y2).call(this,o)).finally(()=>oe(this,_n,w2).call(this)));return}if(y(this,Xc)){const a=y(this,Xc);q(this,Xc,null),this._uiManager.enableWaiting(!0),q(this,Yc,this._uiManager.imageManager.getFromFile(a).then(o=>oe(this,_n,y2).call(this,o)).finally(()=>oe(this,_n,w2).call(this)));return}const n=document.createElement("input");n.type="file",n.accept=a2.supportedTypesStr;const s=this._uiManager._signal;q(this,Yc,new Promise(a=>{n.addEventListener("change",async()=>{if(!n.files||n.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const o=await this._uiManager.imageManager.getFromFile(n.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),oe(this,_n,y2).call(this,o)}a()},{signal:s}),n.addEventListener("cancel",()=>{this.remove(),a()},{signal:s})}).finally(()=>oe(this,_n,w2).call(this))),n.click()},x_=function(){var d;const{div:n}=this;let{width:s,height:a}=y(this,rs);const[o,r]=this.pageDimensions,i=.75;if(this.width)s=this.width*o,a=this.height*r;else if(s>i*o||a>i*r){const h=Math.min(i*o/s,i*r/a);s*=h,a*=h}const[l,c]=this.parentDimensions;this.setDims(s*l/o,a*c/r),this._uiManager.enableWaiting(!1);const u=q(this,Ei,document.createElement("canvas"));u.setAttribute("role","img"),this.addContainer(u),this.width=s/o,this.height=a/r,(d=this._initialOptions)!=null&&d.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(n.hidden=!1),oe(this,_n,k_).call(this),y(this,_0)||(this.parent.addUndoableEditor(this),q(this,_0,!0)),this._reportTelemetry({action:"inserted_image"}),y(this,w0)&&u.setAttribute("aria-label",y(this,w0))},c4=function(n,s){const{width:a,height:o}=y(this,rs);let r=a,i=o,l=y(this,rs);for(;r>2*n||i>2*s;){const c=r,u=i;r>2*n&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2)),i>2*s&&(i=i>=16384?Math.floor(i/2)-1:Math.ceil(i/2));const d=new OffscreenCanvas(r,i);d.getContext("2d").drawImage(l,0,0,c,u,0,0,r,i),l=d.transferToImageBitmap()}return l},k_=function(){const[n,s]=this.parentDimensions,{width:a,height:o}=this,r=new sw,i=Math.ceil(a*n*r.sx),l=Math.ceil(o*s*r.sy),c=y(this,Ei);if(!c||c.width===i&&c.height===l)return;c.width=i,c.height=l;const u=y(this,Ro)?y(this,rs):oe(this,_n,c4).call(this,i,l),d=c.getContext("2d");d.filter=this._uiManager.hcmFilter,d.drawImage(u,0,0,u.width,u.height,0,0,i,l)},u4=function(n){if(n){if(y(this,Ro)){const o=this._uiManager.imageManager.getSvgUrl(y(this,ta));if(o)return o}const s=document.createElement("canvas");return{width:s.width,height:s.height}=y(this,rs),s.getContext("2d").drawImage(y(this,rs),0,0),s.toDataURL()}if(y(this,Ro)){const[s,a]=this.pageDimensions,o=Math.round(this.width*s*_c.PDF_TO_CSS_UNITS),r=Math.round(this.height*a*_c.PDF_TO_CSS_UNITS),i=new OffscreenCanvas(o,r);return i.getContext("2d").drawImage(y(this,rs),0,0,y(this,rs).width,y(this,rs).height,0,0,o,r),i.transferToImageBitmap()}return structuredClone(y(this,rs))},kI=function(n){var i;const{pageIndex:s,accessibilityData:{altText:a}}=this._initialData,o=n.pageIndex===s,r=(((i=n.accessibilityData)==null?void 0:i.alt)||"")===a;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&o&&r,isSameAltText:r}},Wt(a2,"_type","stamp"),Wt(a2,"_editorType",rn.STAMP);let Ew=a2;const Fr=class Fr{constructor({uiManager:t,pageIndex:n,div:s,structTreeLayer:a,accessibilityManager:o,annotationLayer:r,drawLayer:i,textLayer:l,viewport:c,l10n:u}){se(this,ts);se(this,Jd);se(this,C0,!1);se(this,Ti,null);se(this,Jc,null);se(this,Bl,null);se(this,Zo,new Map);se(this,Zc,!1);se(this,S0,!1);se(this,Zd,!1);se(this,Dr,null);se(this,Vl,null);se(this,_a,null);se(this,zl,null);se(this,Lt);const d=[...y(Fr,Qc).values()];if(!Fr._initialized){Fr._initialized=!0;for(const h of d)h.initialize(u,t)}t.registerEditorTypes(d),q(this,Lt,t),this.pageIndex=n,this.div=s,q(this,Jd,o),q(this,Ti,r),this.viewport=c,q(this,_a,l),this.drawLayer=i,this._structTree=a,y(this,Lt).addLayer(this)}get isEmpty(){return y(this,Zo).size===0}get isInvisible(){return this.isEmpty&&y(this,Lt).getMode()===rn.NONE}updateToolbar(t){y(this,Lt).updateToolbar(t)}updateMode(t=y(this,Lt).getMode()){switch(oe(this,ts,d4).call(this),t){case rn.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case rn.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case rn.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:n}=this.div;for(const s of y(Fr,Qc).values())n.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var n;return t===((n=y(this,_a))==null?void 0:n.div)}setEditingState(t){y(this,Lt).setEditingState(t)}addCommands(t){y(this,Lt).addCommands(t)}cleanUndoStack(t){y(this,Lt).cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){var n;(n=y(this,Ti))==null||n.div.classList.toggle("disabled",!t)}async enable(){q(this,Zd,!0),this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of y(this,Zo).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(y(this,Lt).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!y(this,Ti)){q(this,Zd,!1);return}const n=y(this,Ti).getEditableAnnotations();for(const s of n){if(s.hide(),y(this,Lt).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const a=await this.deserialize(s);a&&(this.addOrRebuild(a),a.enableEditing())}q(this,Zd,!1)}disable(){var a;q(this,S0,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,n=new Map;for(const o of y(this,Zo).values())if(o.disableEditing(),!!o.annotationElementId){if(o.serialize()!==null){t.set(o.annotationElementId,o);continue}else n.set(o.annotationElementId,o);(a=this.getEditableAnnotation(o.annotationElementId))==null||a.show(),o.remove()}if(y(this,Ti)){const o=y(this,Ti).getEditableAnnotations();for(const r of o){const{id:i}=r.data;if(y(this,Lt).isDeletedAnnotationElement(i))continue;let l=n.get(i);if(l){l.resetAnnotationElement(r),l.show(!1),r.show();continue}l=t.get(i),l&&(y(this,Lt).addChangedExistingAnnotation(l),l.renderAnnotationElement(r)&&l.show(!1)),r.show()}}oe(this,ts,d4).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const o of y(Fr,Qc).values())s.remove(`${o._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),q(this,S0,!1)}getEditableAnnotation(t){var n;return((n=y(this,Ti))==null?void 0:n.getEditableAnnotation(t))||null}setActiveEditor(t){y(this,Lt).getActive()!==t&&y(this,Lt).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=y(this,_a))!=null&&t.div&&!y(this,zl)){q(this,zl,new AbortController);const n=y(this,Lt).combinedSignal(y(this,zl));y(this,_a).div.addEventListener("pointerdown",oe(this,ts,EI).bind(this),{signal:n}),y(this,_a).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=y(this,_a))!=null&&t.div&&y(this,zl)&&(y(this,zl).abort(),q(this,zl,null),y(this,_a).div.classList.remove("highlighting"))}enableClick(){if(y(this,Jc))return;q(this,Jc,new AbortController);const t=y(this,Lt).combinedSignal(y(this,Jc));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const n=this.pointerup.bind(this);this.div.addEventListener("pointerup",n,{signal:t}),this.div.addEventListener("pointercancel",n,{signal:t})}disableClick(){var t;(t=y(this,Jc))==null||t.abort(),q(this,Jc,null)}attach(t){y(this,Zo).set(t.id,t);const{annotationElementId:n}=t;n&&y(this,Lt).isDeletedAnnotationElement(n)&&y(this,Lt).removeDeletedAnnotationElement(t)}detach(t){var n;y(this,Zo).delete(t.id),(n=y(this,Jd))==null||n.removePointerInTextLayer(t.contentDiv),!y(this,S0)&&t.annotationElementId&&y(this,Lt).addDeletedAnnotationElement(t)}remove(t){this.detach(t),y(this,Lt).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){var n;t.parent!==this&&(t.parent&&t.annotationElementId&&(y(this,Lt).addDeletedAnnotationElement(t.annotationElementId),as.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(n=t.parent)==null||n.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),y(this,Lt).addEditor(t),this.attach(t),!t.isAttachedToDOM){const n=t.render();this.div.append(n),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!y(this,Zd)),y(this,Lt).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:n}=document;t.div.contains(n)&&!y(this,Bl)&&(t._focusEventsAllowed=!1,q(this,Bl,setTimeout(()=>{q(this,Bl,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:y(this,Lt)._signal}),n.focus())},0))),t._structTreeParentId=(s=y(this,Jd))==null?void 0:s.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||(t.parent=this),t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const n=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:n,undo:s,mustExec:!1})}getNextId(){return y(this,Lt).getId()}combinedSignal(t){return y(this,Lt).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=y(this,ts,Ri))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,n){y(this,Lt).updateToolbar(t),y(this,Lt).updateMode(t);const{offsetX:s,offsetY:a}=oe(this,ts,A_).call(this),o=this.getNextId(),r=oe(this,ts,E_).call(this,{parent:this,id:o,x:s,y:a,uiManager:y(this,Lt),isCentered:!0,...n});r&&this.add(r)}async deserialize(t){var n;return await((n=y(Fr,Qc).get(t.annotationType??t.annotationEditorType))==null?void 0:n.deserialize(t,this,y(this,Lt)))||null}createAndAddNewEditor(t,n,s={}){const a=this.getNextId(),o=oe(this,ts,E_).call(this,{parent:this,id:a,x:t.offsetX,y:t.offsetY,uiManager:y(this,Lt),isCentered:n,...s});return o&&this.add(o),o}addNewEditor(){this.createAndAddNewEditor(oe(this,ts,A_).call(this),!0)}setSelected(t){y(this,Lt).setSelected(t)}toggleSelected(t){y(this,Lt).toggleSelected(t)}unselect(t){y(this,Lt).unselect(t)}pointerup(t){var s;const{isMac:n}=La.platform;if(!(t.button!==0||t.ctrlKey&&n)&&t.target===this.div&&y(this,Zc)&&(q(this,Zc,!1),!((s=y(this,ts,Ri))!=null&&s.isDrawer&&y(this,ts,Ri).supportMultipleDrawings))){if(!y(this,C0)){q(this,C0,!0);return}if(y(this,Lt).getMode()===rn.STAMP){y(this,Lt).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){var a;if(y(this,Lt).getMode()===rn.HIGHLIGHT&&this.enableTextSelection(),y(this,Zc)){q(this,Zc,!1);return}const{isMac:n}=La.platform;if(t.button!==0||t.ctrlKey&&n||t.target!==this.div)return;if(q(this,Zc,!0),(a=y(this,ts,Ri))!=null&&a.isDrawer){this.startDrawingSession(t);return}const s=y(this,Lt).getActive();q(this,C0,!s||s.isEmpty())}startDrawingSession(t){if(this.div.focus(),y(this,Dr)){y(this,ts,Ri).startDrawing(this,y(this,Lt),!1,t);return}y(this,Lt).setCurrentDrawingSession(this),q(this,Dr,new AbortController);const n=y(this,Lt).combinedSignal(y(this,Dr));this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(q(this,Vl,null),this.commitOrRemove())},{signal:n}),y(this,ts,Ri).startDrawing(this,y(this,Lt),!1,t)}pause(t){if(t){const{activeElement:n}=document;this.div.contains(n)&&q(this,Vl,n);return}y(this,Vl)&&setTimeout(()=>{var n;(n=y(this,Vl))==null||n.focus(),q(this,Vl,null)},0)}endDrawingSession(t=!1){return y(this,Dr)?(y(this,Lt).setCurrentDrawingSession(null),y(this,Dr).abort(),q(this,Dr,null),q(this,Vl,null),y(this,ts,Ri).endDrawing(t)):null}findNewParent(t,n,s){const a=y(this,Lt).findParent(n,s);return a===null||a===this?!1:(a.changeParent(t),!0)}commitOrRemove(){return y(this,Dr)?(this.endDrawingSession(),!0):!1}onScaleChanging(){y(this,Dr)&&y(this,ts,Ri).onScaleChangingWhenDrawing(this)}destroy(){var t,n;this.commitOrRemove(),((t=y(this,Lt).getActive())==null?void 0:t.parent)===this&&(y(this,Lt).commitOrRemove(),y(this,Lt).setActiveEditor(null)),y(this,Bl)&&(clearTimeout(y(this,Bl)),q(this,Bl,null));for(const s of y(this,Zo).values())(n=y(this,Jd))==null||n.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,y(this,Zo).clear(),y(this,Lt).removeLayer(this)}render({viewport:t}){this.viewport=t,Wu(this.div,t);for(const n of y(this,Lt).getEditors(this.pageIndex))this.add(n),n.rebuild();this.updateMode()}update({viewport:t}){y(this,Lt).commitOrRemove(),oe(this,ts,d4).call(this);const n=this.viewport.rotation,s=t.rotation;if(this.viewport=t,Wu(this.div,{rotation:s}),n!==s)for(const a of y(this,Zo).values())a.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:n}=this.viewport.rawDims;return[t,n]}get scale(){return y(this,Lt).viewParameters.realScale}};Jd=new WeakMap,C0=new WeakMap,Ti=new WeakMap,Jc=new WeakMap,Bl=new WeakMap,Zo=new WeakMap,Zc=new WeakMap,S0=new WeakMap,Zd=new WeakMap,Dr=new WeakMap,Vl=new WeakMap,_a=new WeakMap,zl=new WeakMap,Lt=new WeakMap,Qc=new WeakMap,ts=new WeakSet,EI=function(t){y(this,Lt).unselectAll();const{target:n}=t;if(n===y(this,_a).div||(n.getAttribute("role")==="img"||n.classList.contains("endOfContent"))&&y(this,_a).div.contains(n)){const{isMac:s}=La.platform;if(t.button!==0||t.ctrlKey&&s)return;y(this,Lt).showAllEditors("highlight",!0,!0),y(this,_a).div.classList.add("free"),this.toggleDrawing(),fb.startHighlighting(this,y(this,Lt).direction==="ltr",{target:y(this,_a).div,x:t.x,y:t.y}),y(this,_a).div.addEventListener("pointerup",()=>{y(this,_a).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:y(this,Lt)._signal}),t.preventDefault()}},Ri=function(){return y(Fr,Qc).get(y(this,Lt).getMode())},E_=function(t){const n=y(this,ts,Ri);return n?new n.prototype.constructor(t):null},A_=function(){const{x:t,y:n,width:s,height:a}=this.div.getBoundingClientRect(),o=Math.max(0,t),r=Math.max(0,n),i=Math.min(window.innerWidth,t+s),l=Math.min(window.innerHeight,n+a),c=(o+i)/2-t,u=(r+l)/2-n,[d,h]=this.viewport.rotation%180===0?[c,u]:[u,c];return{offsetX:d,offsetY:h}},d4=function(){for(const t of y(this,Zo).values())t.isEmpty()&&t.remove()},Wt(Fr,"_initialized",!1),se(Fr,Qc,new Map([ww,kw,Ew,fb].map(t=>[t._editorType,t])));let Aw=Fr;const Ca=class Ca{constructor({pageIndex:t}){se(this,Mi);se(this,Br,null);se(this,o2,0);se(this,Va,new Map);se(this,Qd,new Map);this.pageIndex=t}setParent(t){if(!y(this,Br)){q(this,Br,t);return}if(y(this,Br)!==t){if(y(this,Va).size>0)for(const n of y(this,Va).values())n.remove(),t.append(n);q(this,Br,t)}}static get _svgFactory(){return fn(this,"_svgFactory",new gw)}draw(t,n=!1,s=!1){const a=za(this,o2)._++,o=oe(this,Mi,T_).call(this),r=Ca._svgFactory.createElement("defs");o.append(r);const i=Ca._svgFactory.createElement("path");r.append(i);const l=`path_p${this.pageIndex}_${a}`;i.setAttribute("id",l),i.setAttribute("vector-effect","non-scaling-stroke"),n&&y(this,Qd).set(a,i);const c=s?oe(this,Mi,TI).call(this,r,l):null,u=Ca._svgFactory.createElement("use");return o.append(u),u.setAttribute("href",`#${l}`),this.updateProperties(o,t),y(this,Va).set(a,o),{id:a,clipPathId:`url(#${c})`}}drawOutline(t,n){const s=za(this,o2)._++,a=oe(this,Mi,T_).call(this),o=Ca._svgFactory.createElement("defs");a.append(o);const r=Ca._svgFactory.createElement("path");o.append(r);const i=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",i),r.setAttribute("vector-effect","non-scaling-stroke");let l;if(n){const d=Ca._svgFactory.createElement("mask");o.append(d),l=`mask_p${this.pageIndex}_${s}`,d.setAttribute("id",l),d.setAttribute("maskUnits","objectBoundingBox");const h=Ca._svgFactory.createElement("rect");d.append(h),h.setAttribute("width","1"),h.setAttribute("height","1"),h.setAttribute("fill","white");const p=Ca._svgFactory.createElement("use");d.append(p),p.setAttribute("href",`#${i}`),p.setAttribute("stroke","none"),p.setAttribute("fill","black"),p.setAttribute("fill-rule","nonzero"),p.classList.add("mask")}const c=Ca._svgFactory.createElement("use");a.append(c),c.setAttribute("href",`#${i}`),l&&c.setAttribute("mask",`url(#${l})`);const u=c.cloneNode();return a.append(u),c.classList.add("mainOutline"),u.classList.add("secondaryOutline"),this.updateProperties(a,t),y(this,Va).set(s,a),s}finalizeDraw(t,n){y(this,Qd).delete(t),this.updateProperties(t,n)}updateProperties(t,n){var l;if(!n)return;const{root:s,bbox:a,rootClass:o,path:r}=n,i=typeof t=="number"?y(this,Va).get(t):t;if(i){if(s&&oe(this,Mi,M_).call(this,i,s),a&&oe(l=Ca,Ob,AI).call(l,i,a),o){const{classList:c}=i;for(const[u,d]of Object.entries(o))c.toggle(u,d)}if(r){const u=i.firstChild.firstChild;oe(this,Mi,M_).call(this,u,r)}}}updateParent(t,n){if(n===this)return;const s=y(this,Va).get(t);s&&(y(n,Br).append(s),y(this,Va).delete(t),y(n,Va).set(t,s))}remove(t){y(this,Qd).delete(t),y(this,Br)!==null&&(y(this,Va).get(t).remove(),y(this,Va).delete(t))}destroy(){q(this,Br,null);for(const t of y(this,Va).values())t.remove();y(this,Va).clear(),y(this,Qd).clear()}};Br=new WeakMap,o2=new WeakMap,Va=new WeakMap,Qd=new WeakMap,Ob=new WeakSet,AI=function(t,[n,s,a,o]){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*n}%`,r.width=`${100*a}%`,r.height=`${100*o}%`},Mi=new WeakSet,T_=function(){const t=Ca._svgFactory.create(1,1,!0);return y(this,Br).append(t),t.setAttribute("aria-hidden",!0),t},TI=function(t,n){const s=Ca._svgFactory.createElement("clipPath");t.append(s);const a=`clip_${n}`;s.setAttribute("id",a),s.setAttribute("clipPathUnits","objectBoundingBox");const o=Ca._svgFactory.createElement("use");return s.append(o),o.setAttribute("href",`#${n}`),o.classList.add("clip"),a},M_=function(t,n){for(const[s,a]of Object.entries(n))a===null?t.removeAttribute(s):t.setAttribute(s,a)},se(Ca,Ob);let Tw=Ca;globalThis.pdfjsTestingUtils={HighlightOutliner:_w},Jt.AbortException,Jt.AnnotationEditorLayer,Jt.AnnotationEditorParamsType,Jt.AnnotationEditorType,Jt.AnnotationEditorUIManager,Jt.AnnotationLayer,Jt.AnnotationMode,Jt.ColorPicker,Jt.DOMSVGFactory,Jt.DrawLayer,Jt.FeatureTest;var B4e=Jt.GlobalWorkerOptions;Jt.ImageKind,Jt.InvalidPDFException,Jt.MissingPDFException,Jt.OPS,Jt.OutputScale,Jt.PDFDataRangeTransport,Jt.PDFDateString,Jt.PDFWorker,Jt.PasswordResponses,Jt.PermissionFlag,Jt.PixelsPerInch,Jt.RenderingCancelledException,Jt.TextLayer,Jt.TouchManager,Jt.UnexpectedResponseException,Jt.Util,Jt.VerbosityLevel,Jt.XfaLayer,Jt.build,Jt.createValidAbsoluteUrl,Jt.fetchData;var V4e=Jt.getDocument;Jt.getFilenameFromUrl,Jt.getPdfFilenameFromUrl,Jt.getXfaPageViewport,Jt.isDataScheme,Jt.isPdfFile,Jt.noContextMenu,Jt.normalizeUnicode,Jt.setLayerDimensions,Jt.shadow,Jt.stopEvent,Jt.version;const z4e=""+new URL("assets/pdf.worker.min-yatZIOMy.mjs",document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href,H4e={class:"manual-wrap"},W4e={class:"sidebar"},j4e={class:"es-text",style:{display:"none"}},K4e={class:"sb-section"},U4e={class:"sb-title"},q4e={key:0,class:"sb-section"},G4e={class:"sb-title"},Y4e={class:"region-type-btns"},X4e=["onClick"],J4e={class:"rt-badge"},Z4e={key:1,class:"sb-section sb-regions"},Q4e={class:"sb-title"},eye={class:"region-list"},tye=["onClick"],nye={class:"ri-top"},sye={class:"ri-badge"},aye={class:"ri-label"},oye={class:"ri-page"},rye={class:"ri-status"},iye={key:0,class:"ri-tokens"},lye={key:0,class:"ri-preview"},cye={key:2,class:"sb-section sb-actions"},uye={key:0,class:"vl-progress-wrap"},dye={class:"vl-progress-label"},fye={key:0},hye={key:1,class:"vl-done"},pye={key:3,class:"sb-section sb-export"},vye={class:"sb-title"},mye={style:{display:"flex",gap:"8px"}},gye={class:"sb-footer"},bye={class:"viewer"},yye={key:0,class:"viewer-nav"},wye={class:"el-button-group"},_ye={class:"nav-label"},Cye={class:"nav-type-indicator"},Sye={class:"el-button-group el-button-group--small"},xye={class:"zoom-bar"},kye={class:"zoom-pct"},Eye={key:1,class:"viewer-empty"},Aye={class:"img-inner"},Tye={key:0,class:"page-loading"},Mye=["data-mode"],Pye={key:0,class:"result-panel"},Rye={class:"rp-header"},Iye={class:"rp-title"},Oye={key:0,class:"rp-tokens"},Lye={class:"rp-text"},Nye=[{path:"/",redirect:"/Auto"},{path:"/Auto",component:B1e},{path:"/Manual",component:il({__name:"ManualOCR",setup(e){B4e.workerSrc=z4e;const t=rP(),n="http://localhost:8000",s=[{key:"A",label:"材料区域",color:"#2563eb"},{key:"B",label:"图纸信息",color:"#d97706"},{key:"C",label:"其他",color:"#059669"}],a=Ee=>{var ge;return((ge=s.find(_e=>_e.key===Ee))==null?void 0:ge.color)??"#6b7280"},o=Ee=>{var ge;return((ge=s.find(_e=>_e.key===Ee))==null?void 0:ge.label)??Ee},r=F("file"),i=F(null),l=F(""),c=F(!1),u=F(""),d=F(0),h=F(0),p=F(!1),v=pn(null),m=F(!1);let g=null;const b=F("A"),_=F([]),w=F(null),C=F(!1),x=F(""),k=F(!1),T=F(0),R=F(0),I=F(null),M=F(null),$=F(null),O=F(null),B=[.25,.5,.75,1,1.25,1.5,2,3],U=F(1);function J(){const Ee=B.find(ge=>ge>U.value+.01);Ee&&(U.value=Ee)}function Y(){const Ee=[...B].reverse().find(ge=>ger.value==="file"?!!i.value:l.value.startsWith("http")),ce=E(()=>_.value.filter(Ee=>Ee.status==="pending").length),Z=E(()=>_.value.filter(Ee=>Ee.type==="A"&&Ee.status==="pending").length),H=E(()=>_.value.filter(Ee=>Ee.status==="done")),te=E(()=>_.value.find(Ee=>Ee.id===w.value)||null),de=E(()=>T.value>0?Math.round(R.value/T.value*100):0);let be=null;St(async()=>{try{const _e=await(await fetch(`${n}/api/manual/engine-info`)).json();L.value=_e.status==="ready"?"ready":"error",V.value=_e.error||_e.engine||""}catch(ge){L.value="error",V.value=ge.message}const Ee=document.getElementById("hdpdfurl2");if(Ee&&Ee.value&&Ee.value.trim()&&(l.value=Ee.value.trim(),r.value="url",await Se()),Ee){let ge=Ee.value;be=setInterval(async()=>{const _e=Ee.value?Ee.value.trim():"";_e&&_e!==ge&&(ge=_e,l.value=_e,r.value="url",await Se())},2e3)}});async function Ce(Ee){i.value=Ee.raw,await Se(),O.value&&O.value.clearFiles()}async function Se(){c.value=!0;try{let Ee,ge=null;if(r.value==="file"){ge=await i.value.arrayBuffer();const Oe=new FormData;Oe.append("file",i.value),Ee=await fetch(`${n}/api/manual/upload`,{method:"POST",body:Oe})}else Ee=await fetch(`${n}/api/manual/upload-url`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:l.value.trim()})});if(!Ee.ok){const Oe=await Ee.json().catch(()=>({}));throw new Error(Oe.detail||`HTTP ${Ee.status}`)}const _e=await Ee.json();if(u.value&&fetch(`${n}/api/manual/session/${u.value}`,{method:"DELETE"}).catch(()=>{}),u.value=_e.session_id,d.value=_e.total_pages,h.value=0,_.value=[],w.value=null,p.value=!0,U.value=1,!ge){const Oe=await fetch(`${n}/api/manual/pdf/${_e.session_id}`);if(!Oe.ok)throw new Error(`获取 PDF 字节失败 HTTP ${Oe.status}`);ge=await Oe.arrayBuffer()}await Ve(ge),Ys.success(`PDF 加载成功,共 ${_e.total_pages} 页`)}catch(Ee){Ys.error(`加载失败:${Ee.message}`)}finally{c.value=!1}}function Ne(Ee){Ee<0||Ee>=d.value||(h.value=Ee)}me(h,Ee=>{at(),$e(Ee)}),me(ae,Ee=>{Ee==="draw"&&M.value&&(M.value.style.cursor="")}),me(U,()=>{p.value&&v.value&&$e(h.value)});async function Ve(Ee){try{const ge=V4e({data:Ee,cMapUrl:"/pdfjs-cmaps/",cMapPacked:!0});v.value=await ge.promise,$e(0)}catch(ge){Ys.error(`PDF.js 加载失败:${ge.message}`)}}async function $e(Ee){if(v.value){g&&(g.cancel(),g=null),m.value=!0;try{const ge=await v.value.getPage(Ee+1),_e=window.devicePixelRatio||1,Oe=ge.getViewport({scale:U.value*_e}),Fe=$.value;Fe.width=Oe.width,Fe.height=Oe.height,Fe.style.width=Oe.width/_e+"px",Fe.style.height=Oe.height/_e+"px";const xt=Fe.getContext("2d");g=ge.render({canvasContext:xt,viewport:Oe}),await g.promise,g=null,Ie()}catch(ge){(ge==null?void 0:ge.name)!=="RenderingCancelledException"&&Ys.error(`页面渲染失败:${ge.message}`)}finally{m.value=!1}}}let we=null;function Ie(){const Ee=$.value,ge=M.value;if(!Ee||!ge)return;const _e=Ee.offsetWidth,Oe=Ee.offsetHeight;_e===0||Oe===0||((ge.width!==_e||ge.height!==Oe)&&(ge.width=_e,ge.height=Oe),ut(),we||(we=new ResizeObserver(()=>Ie())),we.disconnect(),we.observe(Ee))}window.addEventListener("resize",()=>{p.value&&Ie()});function Pe(Ee){const ge=M.value.getBoundingClientRect();return{x:Ee.clientX-ge.left,y:Ee.clientY-ge.top}}function We(Ee){fe.value&&(I.value.scrollLeft=ne.value-Ee.clientX,I.value.scrollTop=pe.value-Ee.clientY)}function Ze(){fe.value&&(fe.value=!1,M.value&&(M.value.style.cursor=""),window.removeEventListener("mousemove",We),window.removeEventListener("mouseup",Ze))}function rt(Ee){if(!z.value)return;const{x:ge,y:_e}=Pe(Ee);K.value=ge,ee.value=_e,ut()}function De(Ee){if(!z.value)return;const{x:ge,y:_e}=Pe(Ee);z.value=!1,window.removeEventListener("mousemove",rt),window.removeEventListener("mouseup",De);const Oe=M.value,Fe=Oe.width,xt=Oe.height,Ft=nf=>Math.max(0,Math.min(Fe,nf)),bn=nf=>Math.max(0,Math.min(xt,nf)),Sn=Ft(ge),Et=bn(_e),js=Ft(G.value),zn=bn(Q.value),Hl=Math.min(js,Sn),eu=Math.min(zn,Et),ef=Math.abs(Sn-js),tf=Math.abs(Et-zn);ef>8&&tf>8&&_.value.push({id:crypto.randomUUID(),type:b.value,page:h.value,xr:Hl/Fe,yr:eu/xt,wr:ef/Fe,hr:tf/xt,cx:Hl,cy:eu,cw:ef,ch:tf,status:"pending",text:"",boxes:[],tokens:null,rows:[],parts1:{}}),at(),ut()}function Ke(Ee){Ee.preventDefault();const{x:ge,y:_e}=Pe(Ee);ae.value==="draw"?(z.value=!0,G.value=ge,Q.value=_e,K.value=ge,ee.value=_e,window.addEventListener("mousemove",rt),window.addEventListener("mouseup",De)):ae.value==="pan"&&(fe.value=!0,ne.value=Ee.clientX+I.value.scrollLeft,pe.value=Ee.clientY+I.value.scrollTop,M.value.style.cursor="grabbing",window.addEventListener("mousemove",We),window.addEventListener("mouseup",Ze))}function tt(Ee){}function Vt(Ee){}function qt(){}function at(){z.value=!1,G.value=0,Q.value=0,K.value=0,ee.value=0}function ut(){const Ee=M.value;if(!Ee)return;const ge=Ee.getContext("2d");ge.clearRect(0,0,Ee.width,Ee.height);const _e=Ee.width,Oe=Ee.height;for(const Fe of _.value){if(Fe.page!==h.value)continue;const xt=Fe.xr*_e,Ft=Fe.yr*Oe,bn=Fe.wr*_e,Sn=Fe.hr*Oe,Et=a(Fe.type),js=Fe.id===w.value;ge.strokeStyle=Et,ge.lineWidth=js?3:2,ge.setLineDash(Fe.status==="pending"?[5,3]:[]),ge.strokeRect(xt,Ft,bn,Sn),ge.fillStyle=Et+"18",ge.fillRect(xt,Ft,bn,Sn);const zn=`${Fe.type} ${o(Fe.type)}`;ge.font="bold 12px sans-serif";const Hl=ge.measureText(zn).width+10;ge.fillStyle=Et,ge.fillRect(xt,Ft-18,Hl,18),ge.fillStyle="#fff",ge.fillText(zn,xt+5,Ft-4)}if(z.value){const Fe=Math.min(G.value,K.value),xt=Math.min(Q.value,ee.value),Ft=Math.abs(K.value-G.value),bn=Math.abs(ee.value-Q.value),Sn=a(b.value);ge.strokeStyle=Sn,ge.lineWidth=2,ge.setLineDash([4,3]),ge.strokeRect(Fe,xt,Ft,bn),ge.fillStyle=Sn+"15",ge.fillRect(Fe,xt,Ft,bn)}}function Tt(Ee){w.value=Ee.id,Ee.page!==h.value?Ne(Ee.page):ut()}function xe(Ee){_.value=_.value.filter(ge=>ge.id!==Ee),w.value===Ee&&(w.value=null),ut()}function qe(){_.value=[],w.value=null,ut()}async function ye(){var Oe;const Ee=_.value.find(Fe=>Fe.type==="A");if(!Ee)return;_.value.filter(Fe=>Fe.type==="A"&&Fe.status==="pending").forEach(Fe=>{Fe.status="recognizing"}),k.value=!0,T.value=d.value,R.value=0;const ge=Math.max(800,Math.round(3500*Math.ceil(d.value/10)/d.value)),_e=setInterval(()=>{R.value({}));throw new Error(Sn.detail||`HTTP ${Fe.status}`)}const xt=await Fe.json();R.value=T.value;const Ft=(Oe=xt.usage)!=null&&Oe.total_tokens?Math.round(xt.usage.total_tokens/(xt.total_pages||1)):null;for(const Sn of xt.results){let Et=_.value.find(zn=>zn.type==="A"&&zn.page===Sn.page_index);Et||(Et={id:crypto.randomUUID(),type:"A",page:Sn.page_index,xr:Ee.xr,yr:Ee.yr,wr:Ee.wr,hr:Ee.hr,cx:Ee.cx,cy:Ee.cy,cw:Ee.cw,ch:Ee.ch,status:"pending",text:"",boxes:[],tokens:null,rows:[]},_.value.push(Et));const js=Sn.rows||[];Et.rows=js,Et.tokens=Ft,Et.text=js.length?js.map(zn=>[zn.seq_no??"",zn.category??"",zn.description??"",zn.nominal_dia_mm??"",zn.qty??""].filter(eu=>eu!=="").join(" | ")).join(` +`)){const s=document.createElement("div");s.append(n?document.createTextNode(n):document.createElement("br")),this.editorDiv.append(s)}},ZR=function(){return y(this,xo).replaceAll(" "," ")},p_=function(n){return n.replaceAll(" "," ")},QR=function(n){const{value:s,fontSize:a,color:o,pageIndex:r}=this._initialData;return this._hasBeenMoved||n.value!==s||n.fontSize!==a||n.color.some((i,l)=>i!==o[l])||n.pageIndex!==r},se(Kn,Ol),Wt(Kn,"_freeTextDefaultContent",""),Wt(Kn,"_internalPadding",0),Wt(Kn,"_defaultColor",null),Wt(Kn,"_defaultFontSize",10),Wt(Kn,"_type","freetext"),Wt(Kn,"_editorType",rn.FREETEXT);let ww=Kn;class At{toSVGPath(){Vn("Abstract method `toSVGPath` must be implemented.")}get box(){Vn("Abstract getter `box` must be implemented.")}serialize(t,n){Vn("Abstract method `serialize` must be implemented.")}static _rescale(t,n,s,a,o,r){r||(r=new Float32Array(t.length));for(let i=0,l=t.length;i=6;a-=6)isNaN(n[a])?s.push(`L${n[a+4]} ${n[a+5]}`):s.push(`C${n[a]} ${n[a+1]} ${n[a+2]} ${n[a+3]} ${n[a+4]} ${n[a+5]}`);return oe(this,Rs,tI).call(this,s),s.join(" ")}newFreeDrawOutline(t,n,s,a,o,r){return new tR(t,n,s,a,o,r)}getOutlines(){var d;const t=y(this,Ci),n=y(this,Or),s=y(this,hn),[a,o,r,i]=y(this,Eo),l=new Float32Array((((d=y(this,Wc))==null?void 0:d.length)??0)+2);for(let h=0,p=l.length-2;h=6;h-=6)for(let p=0;p<6;p+=2){if(isNaN(n[h+p])){c[u]=c[u+1]=NaN,u+=2;continue}c[u]=n[h+p],c[u+1]=n[h+p+1],u+=2}return oe(this,Rs,aI).call(this,c,u),this.newFreeDrawOutline(c,l,y(this,Eo),y(this,t0),y(this,Qh),y(this,e0))}};Eo=new WeakMap,Or=new WeakMap,Qh=new WeakMap,e0=new WeakMap,Ci=new WeakMap,hn=new WeakMap,Dd=new WeakMap,Fd=new WeakMap,Vm=new WeakMap,zm=new WeakMap,t0=new WeakMap,n0=new WeakMap,Wc=new WeakMap,Hm=new WeakMap,Mb=new WeakMap,Pb=new WeakMap,Rs=new WeakSet,v2=function(){const t=y(this,hn).subarray(4,6),n=y(this,hn).subarray(16,18),[s,a,o,r]=y(this,Eo);return[(y(this,Dd)+(t[0]-n[0])/2-s)/o,(y(this,Fd)+(t[1]-n[1])/2-a)/r,(y(this,Dd)+(n[0]-t[0])/2-s)/o,(y(this,Fd)+(n[1]-t[1])/2-a)/r]},eI=function(){const[t,n,s,a]=y(this,Eo),[o,r,i,l]=oe(this,Rs,v2).call(this);return`M${(y(this,hn)[2]-t)/s} ${(y(this,hn)[3]-n)/a} L${(y(this,hn)[4]-t)/s} ${(y(this,hn)[5]-n)/a} L${o} ${r} L${i} ${l} L${(y(this,hn)[16]-t)/s} ${(y(this,hn)[17]-n)/a} L${(y(this,hn)[14]-t)/s} ${(y(this,hn)[15]-n)/a} Z`},tI=function(t){const n=y(this,Or);t.push(`L${n[4]} ${n[5]} Z`)},nI=function(t){const[n,s,a,o]=y(this,Eo),r=y(this,hn).subarray(4,6),i=y(this,hn).subarray(16,18),[l,c,u,d]=oe(this,Rs,v2).call(this);t.push(`L${(r[0]-n)/a} ${(r[1]-s)/o} L${l} ${c} L${u} ${d} L${(i[0]-n)/a} ${(i[1]-s)/o}`)},sI=function(t){const n=y(this,hn),[s,a,o,r]=y(this,Eo),[i,l,c,u]=oe(this,Rs,v2).call(this),d=new Float32Array(36);return d.set([NaN,NaN,NaN,NaN,(n[2]-s)/o,(n[3]-a)/r,NaN,NaN,NaN,NaN,(n[4]-s)/o,(n[5]-a)/r,NaN,NaN,NaN,NaN,i,l,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,(n[16]-s)/o,(n[17]-a)/r,NaN,NaN,NaN,NaN,(n[14]-s)/o,(n[15]-a)/r],0),this.newFreeDrawOutline(d,t,y(this,Eo),y(this,t0),y(this,Qh),y(this,e0))},aI=function(t,n){const s=y(this,Or);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],n),n+=6},oI=function(t,n){const s=y(this,hn).subarray(4,6),a=y(this,hn).subarray(16,18),[o,r,i,l]=y(this,Eo),[c,u,d,h]=oe(this,Rs,v2).call(this);return t.set([NaN,NaN,NaN,NaN,(s[0]-o)/i,(s[1]-r)/l,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,d,h,NaN,NaN,NaN,NaN,(a[0]-o)/i,(a[1]-r)/l],n),n+=24},se(Ll,Hm,8),se(Ll,Mb,2),se(Ll,Pb,y(Ll,Hm)+y(Ll,Mb));let ub=Ll;class tR extends At{constructor(n,s,a,o,r,i){super();se(this,Rb);se(this,s0);se(this,Bd,new Float32Array(4));se(this,Nl);se(this,Wm);se(this,Ao);se(this,jm);se(this,ps);q(this,ps,n),q(this,Ao,s),q(this,s0,a),q(this,jm,o),q(this,Nl,r),q(this,Wm,i),this.lastPoint=[NaN,NaN],oe(this,Rb,rI).call(this,i);const[l,c,u,d]=y(this,Bd);for(let h=0,p=n.length;hn[0]-s[0]||n[1]-s[1]||n[2]-s[2]);const t=[];for(const n of y(this,jc))n[3]?(t.push(...oe(this,Da,v_).call(this,n)),oe(this,Da,lI).call(this,n)):(oe(this,Da,cI).call(this,n),t.push(...oe(this,Da,v_).call(this,n)));return oe(this,Da,iI).call(this,t)}}Km=new WeakMap,Um=new WeakMap,jc=new WeakMap,Lr=new WeakMap,Da=new WeakSet,iI=function(t){const n=[],s=new Set;for(const r of t){const[i,l,c]=r;n.push([i,l,r],[i,c,r])}n.sort((r,i)=>r[1]-i[1]||r[0]-i[0]);for(let r=0,i=n.length;r0;){const r=s.values().next().value;let[i,l,c,u,d]=r;s.delete(r);let h=i,p=l;for(o=[i,c],a.push(o);;){let v;if(s.has(u))v=u;else if(s.has(d))v=d;else break;s.delete(v),[i,l,c,u,d]=v,h!==i&&(o.push(h,p,i,p===l?l:c),h=i),p=p===l?c:l}o.push(h,p)}return new N4e(a,y(this,Km),y(this,Um))},s4=function(t){const n=y(this,Lr);let s=0,a=n.length-1;for(;s<=a;){const o=s+a>>1,r=n[o][0];if(r===t)return o;r=0;a--){const[o,r]=y(this,Lr)[a];if(o!==t)break;if(o===t&&r===n){y(this,Lr).splice(a,1);return}}},v_=function(t){const[n,s,a]=t,o=[[n,s,a]],r=oe(this,Da,s4).call(this,a);for(let i=0;i=l){if(p>c)o[u][1]=c;else{if(d===1)return[];o.splice(u,1),u--,d--}continue}o[u][2]=l,p>c&&o.push([n,c,p])}}}return o};class N4e extends At{constructor(n,s,a){super();se(this,qm);se(this,a0);q(this,a0,n),q(this,qm,s),this.lastPoint=a}toSVGPath(){const n=[];for(const s of y(this,a0)){let[a,o]=s;n.push(`M${a} ${o}`);for(let r=2;r-1?(q(this,Zs,!0),oe(this,an,a4).call(this,n),oe(this,an,rf).call(this)):y(this,$l)&&(q(this,l0,n.anchorNode),q(this,Zm,n.anchorOffset),q(this,Qm,n.focusNode),q(this,e2,n.focusOffset),oe(this,an,y_).call(this),oe(this,an,rf).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const n=xn.prototype;return fn(this,"_keyboardManager",new Ev([[["ArrowLeft","mac+ArrowLeft"],n._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],n._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],n._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],n._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:y(this,Zs)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:y(this,Yo),methodOfCreation:y(this,t2)}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(n){return{numberOfColors:n.get("color").size}}static initialize(n,s){var a;as.initialize(n,s),xn._defaultColor||(xn._defaultColor=((a=s.highlightColors)==null?void 0:a.values().next().value)||"#fff066")}static updateDefaultParams(n,s){switch(n){case gn.HIGHLIGHT_DEFAULT_COLOR:xn._defaultColor=s;break;case gn.HIGHLIGHT_THICKNESS:xn._defaultThickness=s;break}}translateInPage(n,s){}get toolbarPosition(){return y(this,u0)}updateParams(n,s){switch(n){case gn.HIGHLIGHT_COLOR:oe(this,an,dI).call(this,s);break;case gn.HIGHLIGHT_THICKNESS:oe(this,an,fI).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[gn.HIGHLIGHT_DEFAULT_COLOR,xn._defaultColor],[gn.HIGHLIGHT_THICKNESS,xn._defaultThickness]]}get propertiesToUpdate(){return[[gn.HIGHLIGHT_COLOR,this.color||xn._defaultColor],[gn.HIGHLIGHT_THICKNESS,y(this,Yo)||xn._defaultThickness],[gn.HIGHLIGHT_FREE,y(this,Zs)]]}async addEditToolbar(){const n=await super.addEditToolbar();return n?(this._uiManager.highlightColors&&(q(this,c0,new db({editor:this})),n.addColorPicker(y(this,c0))),n):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(oe(this,an,m2).call(this))}getBaseTranslation(){return[0,0]}getRect(n,s){return super.getRect(n,s,oe(this,an,m2).call(this))}onceAdded(n){this.annotationElementId||this.parent.addUndoableEditor(this),n&&this.div.focus()}remove(){oe(this,an,w_).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(oe(this,an,rf).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(n){var a;let s=!1;this.parent&&!n?oe(this,an,w_).call(this):n&&(oe(this,an,rf).call(this,n),s=!this.parent&&((a=this.div)==null?void 0:a.classList.contains("selectedEditor"))),super.setParent(n),this.show(this._isVisible),s&&this.select()}rotate(n){var o,r,i;const{drawLayer:s}=this.parent;let a;y(this,Zs)?(n=(n-this.rotation+360)%360,a=oe(o=xn,Xo,M0).call(o,y(this,Go).box,n)):a=oe(r=xn,Xo,M0).call(r,[this.x,this.y,this.width,this.height],n),s.updateProperties(y(this,To),{bbox:a,root:{"data-main-rotation":n}}),s.updateProperties(y(this,wa),{bbox:oe(i=xn,Xo,M0).call(i,y(this,ao).box,n),root:{"data-main-rotation":n}})}render(){if(this.div)return this.div;const n=super.render();y(this,d0)&&(n.setAttribute("aria-label",y(this,d0)),n.setAttribute("role","mark")),y(this,Zs)?n.classList.add("free"):this.div.addEventListener("keydown",oe(this,an,pI).bind(this),{signal:this._uiManager._signal});const s=q(this,Hd,document.createElement("div"));n.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=y(this,zd);const[a,o]=this.parentDimensions;return this.setDims(this.width*a,this.height*o),tb(this,y(this,Hd),["pointerover","pointerleave"]),this.enableEditing(),n}pointerover(){var n;this.isSelected||(n=this.parent)==null||n.drawLayer.updateProperties(y(this,wa),{rootClass:{hovered:!0}})}pointerleave(){var n;this.isSelected||(n=this.parent)==null||n.drawLayer.updateProperties(y(this,wa),{rootClass:{hovered:!1}})}_moveCaret(n){switch(this.parent.unselect(this),n){case 0:case 2:oe(this,an,o4).call(this,!0);break;case 1:case 3:oe(this,an,o4).call(this,!1);break}}select(){var n;super.select(),y(this,wa)&&((n=this.parent)==null||n.drawLayer.updateProperties(y(this,wa),{rootClass:{hovered:!1,selected:!0}}))}unselect(){var n;super.unselect(),y(this,wa)&&((n=this.parent)==null||n.drawLayer.updateProperties(y(this,wa),{rootClass:{selected:!1}}),y(this,Zs)||oe(this,an,o4).call(this,!1))}get _mustFixPosition(){return!y(this,Zs)}show(n=this._isVisible){super.show(n),this.parent&&(this.parent.drawLayer.updateProperties(y(this,To),{rootClass:{hidden:!n}}),this.parent.drawLayer.updateProperties(y(this,wa),{rootClass:{hidden:!n}}))}static startHighlighting(n,s,{target:a,x:o,y:r}){const{x:i,y:l,width:c,height:u}=a.getBoundingClientRect(),d=new AbortController,h=n.combinedSignal(d),p=v=>{d.abort(),oe(this,Xo,bI).call(this,n,v)};window.addEventListener("blur",p,{signal:h}),window.addEventListener("pointerup",p,{signal:h}),window.addEventListener("pointerdown",go,{capture:!0,passive:!1,signal:h}),window.addEventListener("contextmenu",xr,{signal:h}),a.addEventListener("pointermove",oe(this,Xo,gI).bind(this,n),{signal:h}),this._freeHighlight=new Cw({x:o,y:r},[i,l,c,u],n.scale,this._defaultThickness/2,s,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=n.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 async deserialize(n,s,a){var m,g,b,_;let o=null;if(n instanceof QP){const{data:{quadPoints:w,rect:C,rotation:x,id:k,color:T,opacity:R,popupRef:I},parent:{page:{pageNumber:M}}}=n;o=n={annotationType:rn.HIGHLIGHT,color:Array.from(T),opacity:R,quadPoints:w,boxes:null,pageIndex:M-1,rect:C.slice(0),rotation:x,id:k,deleted:!1,popupRef:I}}else if(n instanceof yw){const{data:{inkLists:w,rect:C,rotation:x,id:k,color:T,borderStyle:{rawWidth:R},popupRef:I},parent:{page:{pageNumber:M}}}=n;o=n={annotationType:rn.HIGHLIGHT,color:Array.from(T),thickness:R,inkLists:w,boxes:null,pageIndex:M-1,rect:C.slice(0),rotation:x,id:k,deleted:!1,popupRef:I}}const{color:r,quadPoints:i,inkLists:l,opacity:c}=n,u=await super.deserialize(n,s,a);u.color=$t.makeHexColor(...r),q(u,Dl,c||1),l&&q(u,Yo,n.thickness),u.annotationElementId=n.id||null,u._initialData=o;const[d,h]=u.pageDimensions,[p,v]=u.pageTranslation;if(i){const w=q(u,$l,[]);for(let C=0;C=0)q(this,To,s),q(this,zd,a),this.parent.drawLayer.finalizeDraw(s,{bbox:n.box,path:{d:n.toSVGPath()}}),q(this,wa,this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:y(this,ao).box,path:{d:y(this,ao).toSVGPath()}},!0));else if(this.parent){const p=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(y(this,To),{bbox:oe(d=xn,Xo,M0).call(d,y(this,Go).box,(p-this.rotation+360)%360),path:{d:n.toSVGPath()}}),this.parent.drawLayer.updateProperties(y(this,wa),{bbox:oe(h=xn,Xo,M0).call(h,y(this,ao).box,p),path:{d:y(this,ao).toSVGPath()}})}const[r,i,l,c]=n.box;switch(this.rotation){case 0:this.x=r,this.y=i,this.width=l,this.height=c;break;case 90:{const[p,v]=this.parentDimensions;this.x=i,this.y=1-r,this.width=l*v/p,this.height=c*p/v;break}case 180:this.x=1-r,this.y=1-i,this.width=l,this.height=c;break;case 270:{const[p,v]=this.parentDimensions;this.x=1-i,this.y=r,this.width=l*v/p,this.height=c*p/v;break}}const{lastPoint:u}=y(this,ao);q(this,u0,[(u[0]-r)/l,(u[1]-i)/c])},dI=function(n){const s=(r,i)=>{var l,c;this.color=r,q(this,Dl,i),(l=this.parent)==null||l.drawLayer.updateProperties(y(this,To),{root:{fill:r,"fill-opacity":i}}),(c=y(this,c0))==null||c.updateColor(r)},a=this.color,o=y(this,Dl);this.addCommands({cmd:s.bind(this,n,xn._defaultOpacity),undo:s.bind(this,a,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:gn.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(n)},!0)},fI=function(n){const s=y(this,Yo),a=o=>{q(this,Yo,o),oe(this,an,hI).call(this,o)};this.addCommands({cmd:a.bind(this,n),undo:a.bind(this,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:gn.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:n},!0)},hI=function(n){if(!y(this,Zs))return;oe(this,an,a4).call(this,{highlightOutlines:y(this,Go).getNewOutline(n/2)}),this.fixAndSetPosition();const[s,a]=this.parentDimensions;this.setDims(this.width*s,this.height*a)},w_=function(){y(this,To)===null||!this.parent||(this.parent.drawLayer.remove(y(this,To)),q(this,To,null),this.parent.drawLayer.remove(y(this,wa)),q(this,wa,null))},rf=function(n=this.parent){y(this,To)===null&&({id:za(this,To)._,clipPathId:za(this,zd)._}=n.drawLayer.draw({bbox:y(this,Go).box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":y(this,Dl)},rootClass:{highlight:!0,free:y(this,Zs)},path:{d:y(this,Go).toSVGPath()}},!1,!0),q(this,wa,n.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:y(this,Zs)},bbox:y(this,ao).box,path:{d:y(this,ao).toSVGPath()}},y(this,Zs))),y(this,Hd)&&(y(this,Hd).style.clipPath=y(this,zd)))},Xo=new WeakSet,M0=function([n,s,a,o],r){switch(r){case 90:return[1-s-o,n,o,a];case 180:return[1-n-a,1-s-o,a,o];case 270:return[s,1-n-a,o,a]}return[n,s,a,o]},pI=function(n){xn._keyboardManager.exec(this,n)},o4=function(n){if(!y(this,l0))return;const s=window.getSelection();n?s.setPosition(y(this,l0),y(this,Zm)):s.setPosition(y(this,Qm),y(this,e2))},m2=function(){return y(this,Zs)?this.rotation:0},vI=function(){if(y(this,Zs))return null;const[n,s]=this.pageDimensions,[a,o]=this.pageTranslation,r=y(this,$l),i=new Float32Array(r.length*8);let l=0;for(const{x:c,y:u,width:d,height:h}of r){const p=c*n+a,v=(1-u)*s+o;i[l]=i[l+4]=p,i[l+1]=i[l+3]=v,i[l+2]=i[l+6]=p+d*n,i[l+5]=i[l+7]=v-h*s,l+=8}return i},mI=function(n){return y(this,Go).serialize(n,oe(this,an,m2).call(this))},gI=function(n,s){this._freeHighlight.add(s)&&n.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},bI=function(n,s){this._freeHighlight.isEmpty()?n.drawLayer.remove(this._freeHighlightId):n.createAndAddNewEditor(s,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""},yI=function(n){const{color:s}=this._initialData;return n.color.some((a,o)=>a!==s[o])},se(xn,Xo),Wt(xn,"_defaultColor",null),Wt(xn,"_defaultOpacity",1),Wt(xn,"_defaultThickness",12),Wt(xn,"_type","highlight"),Wt(xn,"_editorType",rn.HIGHLIGHT),Wt(xn,"_freeHighlightId",-1),Wt(xn,"_freeHighlight",null),Wt(xn,"_freeHighlightClipId","");let fb=xn;class D4e{constructor(){se(this,Wd,Object.create(null))}updateProperty(t,n){this[t]=n,this.updateSVGProperty(t,n)}updateProperties(t){if(t)for(const[n,s]of Object.entries(t))this.updateProperty(n,s)}updateSVGProperty(t,n){y(this,Wd)[t]=n}toSVGProperties(){const t=y(this,Wd);return q(this,Wd,Object.create(null)),{root:t}}reset(){q(this,Wd,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){Vn("Not implemented")}}Wd=new WeakMap;const Rt=class Rt extends as{constructor(n){super(n);se(this,yn);se(this,Mo,null);se(this,f0);Wt(this,"_drawId",null);q(this,f0,n.mustBeCommitted||!1),n.drawOutlines&&(oe(this,yn,__).call(this,n),oe(this,yn,g2).call(this))}static _mergeSVGProperties(n,s){const a=new Set(Object.keys(n));for(const[o,r]of Object.entries(s))a.has(o)?Object.assign(n[o],r):n[o]=r;return n}static getDefaultDrawingOptions(n){Vn("Not implemented")}static get typesMap(){Vn("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(n,s){const a=this.typesMap.get(n);a&&this._defaultDrawingOptions.updateProperty(a,s),this._currentParent&&(y(Rt,zs).updateProperty(a,s),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(n,s){const a=this.constructor.typesMap.get(n);a&&this._updateProperty(n,a,s)}static get defaultPropertiesToUpdate(){const n=[],s=this._defaultDrawingOptions;for(const[a,o]of this.typesMap)n.push([a,s[o]]);return n}get propertiesToUpdate(){const n=[],{_drawingOptions:s}=this;for(const[a,o]of this.constructor.typesMap)n.push([a,s[o]]);return n}_updateProperty(n,s,a){const o=this._drawingOptions,r=o[s],i=l=>{var u;o.updateProperty(s,l);const c=y(this,Mo).updateProperty(s,l);c&&oe(this,yn,b2).call(this,c),(u=this.parent)==null||u.drawLayer.updateProperties(this._drawId,o.toSVGProperties())};this.addCommands({cmd:i.bind(this,a),undo:i.bind(this,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:n,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){var n;(n=this.parent)==null||n.drawLayer.updateProperties(this._drawId,Rt._mergeSVGProperties(y(this,Mo).getPathResizingSVGProperties(oe(this,yn,r4).call(this)),{bbox:oe(this,yn,P0).call(this)}))}_onResized(){var n;(n=this.parent)==null||n.drawLayer.updateProperties(this._drawId,Rt._mergeSVGProperties(y(this,Mo).getPathResizedSVGProperties(oe(this,yn,r4).call(this)),{bbox:oe(this,yn,P0).call(this)}))}_onTranslating(n,s){var a;(a=this.parent)==null||a.drawLayer.updateProperties(this._drawId,{bbox:oe(this,yn,P0).call(this,n,s)})}_onTranslated(){var n;(n=this.parent)==null||n.drawLayer.updateProperties(this._drawId,Rt._mergeSVGProperties(y(this,Mo).getPathTranslatedSVGProperties(oe(this,yn,r4).call(this),this.parentDimensions),{bbox:oe(this,yn,P0).call(this)}))}_onStartDragging(){var n;(n=this.parent)==null||n.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){var n;(n=this.parent)==null||n.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(n){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,y(this,f0)&&(q(this,f0,!1),this.commit(),this.parent.setSelected(this),n&&this.isOnScreen&&this.div.focus())}remove(){oe(this,yn,S_).call(this),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(oe(this,yn,g2).call(this),oe(this,yn,b2).call(this,y(this,Mo).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(n){var a;let s=!1;this.parent&&!n?(this._uiManager.removeShouldRescale(this),oe(this,yn,S_).call(this)):n&&(this._uiManager.addShouldRescale(this),oe(this,yn,g2).call(this,n),s=!this.parent&&((a=this.div)==null?void 0:a.classList.contains("selectedEditor"))),super.setParent(n),s&&this.select()}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,Rt._mergeSVGProperties({bbox:oe(this,yn,P0).call(this)},y(this,Mo).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&oe(this,yn,b2).call(this,y(this,Mo).updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;const n=super.render();n.classList.add("draw");const s=document.createElement("div");n.append(s),s.setAttribute("aria-hidden","true"),s.className="internal";const[a,o]=this.parentDimensions;return this.setDims(this.width*a,this.height*o),this._uiManager.addShouldRescale(this),this.disableEditing(),n}static createDrawerInstance(n,s,a,o,r){Vn("Not implemented")}static startDrawing(n,s,a,o){var g;const{target:r,offsetX:i,offsetY:l,pointerId:c,pointerType:u}=o;if(y(Rt,qc)&&y(Rt,qc)!==u)return;const{viewport:{rotation:d}}=n,{width:h,height:p}=r.getBoundingClientRect(),v=q(Rt,jd,new AbortController),m=n.combinedSignal(v);if(y(Rt,Uc)||q(Rt,Uc,c),y(Rt,qc)??q(Rt,qc,u),window.addEventListener("pointerup",b=>{var _;y(Rt,Uc)===b.pointerId?this._endDraw(b):(_=y(Rt,Gc))==null||_.delete(b.pointerId)},{signal:m}),window.addEventListener("pointercancel",b=>{var _;y(Rt,Uc)===b.pointerId?this._currentParent.endDrawingSession():(_=y(Rt,Gc))==null||_.delete(b.pointerId)},{signal:m}),window.addEventListener("pointerdown",b=>{y(Rt,qc)===b.pointerType&&((y(Rt,Gc)||q(Rt,Gc,new Set)).add(b.pointerId),y(Rt,zs).isCancellable()&&(y(Rt,zs).removeLastElement(),y(Rt,zs).isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:m}),window.addEventListener("contextmenu",xr,{signal:m}),r.addEventListener("pointermove",this._drawMove.bind(this),{signal:m}),r.addEventListener("touchmove",b=>{b.timeStamp===y(Rt,Ud)&&go(b)},{signal:m}),n.toggleDrawing(),(g=s._editorUndoBar)==null||g.hide(),y(Rt,zs)){n.drawLayer.updateProperties(this._currentDrawId,y(Rt,zs).startNew(i,l,h,p,d));return}s.updateUIForDefaultProperties(this),q(Rt,zs,this.createDrawerInstance(i,l,h,p,d)),q(Rt,Kd,this.getDefaultDrawingOptions()),this._currentParent=n,{id:this._currentDrawId}=n.drawLayer.draw(this._mergeSVGProperties(y(Rt,Kd).toSVGProperties(),y(Rt,zs).defaultSVGProperties),!0,!1)}static _drawMove(n){var r;if(q(Rt,Ud,-1),!y(Rt,zs))return;const{offsetX:s,offsetY:a,pointerId:o}=n;if(y(Rt,Uc)===o){if(((r=y(Rt,Gc))==null?void 0:r.size)>=1){this._endDraw(n);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,y(Rt,zs).add(s,a)),q(Rt,Ud,n.timeStamp),go(n)}}static _cleanup(n){n&&(this._currentDrawId=-1,this._currentParent=null,q(Rt,zs,null),q(Rt,Kd,null),q(Rt,qc,null),q(Rt,Ud,NaN)),y(Rt,jd)&&(y(Rt,jd).abort(),q(Rt,jd,null),q(Rt,Uc,NaN),q(Rt,Gc,null))}static _endDraw(n){const s=this._currentParent;if(s){if(s.toggleDrawing(!0),this._cleanup(!1),n&&s.drawLayer.updateProperties(this._currentDrawId,y(Rt,zs).end(n.offsetX,n.offsetY)),this.supportMultipleDrawings){const a=y(Rt,zs),o=this._currentDrawId,r=a.getLastElement();s.addCommands({cmd:()=>{s.drawLayer.updateProperties(o,a.setLastElement(r))},undo:()=>{s.drawLayer.updateProperties(o,a.removeLastElement())},mustExec:!1,type:gn.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(n){const s=this._currentParent;if(!s)return null;if(s.toggleDrawing(!0),s.cleanUndoStack(gn.DRAW_STEP),!y(Rt,zs).isEmpty()){const{pageDimensions:[a,o],scale:r}=s,i=s.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:y(Rt,zs).getOutlines(a*r,o*r,r,this._INNER_MARGIN),drawingOptions:y(Rt,Kd),mustBeCommitted:!n});return this._cleanup(!0),i}return s.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(n){}static deserializeDraw(n,s,a,o,r,i){Vn("Not implemented")}static async deserialize(n,s,a){var d,h;const{rawDims:{pageWidth:o,pageHeight:r,pageX:i,pageY:l}}=s.viewport,c=this.deserializeDraw(i,l,o,r,this._INNER_MARGIN,n),u=await super.deserialize(n,s,a);return u.createDrawingOptions(n),oe(d=u,yn,__).call(d,{drawOutlines:c}),oe(h=u,yn,g2).call(h),u.onScaleChanging(),u.rotate(),u}serializeDraw(n){const[s,a]=this.pageTranslation,[o,r]=this.pageDimensions;return y(this,Mo).serialize([s,a,o,r],n)}renderAnnotationElement(n){return n.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};Mo=new WeakMap,f0=new WeakMap,zs=new WeakMap,jd=new WeakMap,Kd=new WeakMap,Uc=new WeakMap,qc=new WeakMap,Gc=new WeakMap,Ud=new WeakMap,yn=new WeakSet,__=function({drawOutlines:n,drawId:s,drawingOptions:a}){q(this,Mo,n),this._drawingOptions||(this._drawingOptions=a),s>=0?(this._drawId=s,this.parent.drawLayer.finalizeDraw(s,n.defaultProperties)):this._drawId=oe(this,yn,C_).call(this,n,this.parent),oe(this,yn,b2).call(this,n.box)},C_=function(n,s){const{id:a}=s.drawLayer.draw(Rt._mergeSVGProperties(this._drawingOptions.toSVGProperties(),n.defaultSVGProperties),!1,!1);return a},S_=function(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())},g2=function(n=this.parent){if(!(this._drawId!==null&&this.parent===n)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,n.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=oe(this,yn,C_).call(this,y(this,Mo),n)}},wI=function([n,s,a,o]){const{parentDimensions:[r,i],rotation:l}=this;switch(l){case 90:return[s,1-n,a*(i/r),o*(r/i)];case 180:return[1-n,1-s,a,o];case 270:return[1-s,n,a*(i/r),o*(r/i)];default:return[n,s,a,o]}},r4=function(){const{x:n,y:s,width:a,height:o,parentDimensions:[r,i],rotation:l}=this;switch(l){case 90:return[1-s,n,a*(r/i),o*(i/r)];case 180:return[1-n,1-s,a,o];case 270:return[s,1-n,a*(r/i),o*(i/r)];default:return[n,s,a,o]}},b2=function(n){if([this.x,this.y,this.width,this.height]=oe(this,yn,wI).call(this,n),this.div){this.fixAndSetPosition();const[s,a]=this.parentDimensions;this.setDims(this.width*s,this.height*a)}this._onResized()},P0=function(){const{x:n,y:s,width:a,height:o,rotation:r,parentRotation:i,parentDimensions:[l,c]}=this;switch((r*4+i)/90){case 1:return[1-s-o,n,o,a];case 2:return[1-n-a,1-s-o,a,o];case 3:return[s,1-n-a,o,a];case 4:return[n,s-a*(l/c),o*(c/l),a*(l/c)];case 5:return[1-s,n,a*(l/c),o*(c/l)];case 6:return[1-n-o*(c/l),1-s,o*(c/l),a*(l/c)];case 7:return[s-a*(l/c),1-n-o*(c/l),a*(l/c),o*(c/l)];case 8:return[n-a,s-o,a,o];case 9:return[1-s,n-a,o,a];case 10:return[1-n,1-s,a,o];case 11:return[s-o,1-n,o,a];case 12:return[n-o*(c/l),s,o*(c/l),a*(l/c)];case 13:return[1-s-a*(l/c),n-o*(c/l),a*(l/c),o*(c/l)];case 14:return[1-n,1-s-a*(l/c),o*(c/l),a*(l/c)];case 15:return[s,1-n,a*(l/c),o*(c/l)];default:return[n,s,a,o]}},Wt(Rt,"_currentDrawId",-1),Wt(Rt,"_currentParent",null),se(Rt,zs,null),se(Rt,jd,null),se(Rt,Kd,null),se(Rt,Uc,NaN),se(Rt,qc,null),se(Rt,Gc,null),se(Rt,Ud,NaN),Wt(Rt,"_INNER_MARGIN",3);let Sw=Rt;class F4e{constructor(t,n,s,a,o,r){se(this,p0);se(this,Si,new Float64Array(6));se(this,Hs);se(this,Ws);se(this,qd);se(this,h0);se(this,Fa);se(this,Qs,"");se(this,Jo,0);se(this,Gd,new hb);se(this,Yd);se(this,Xd);q(this,Yd,s),q(this,Xd,a),q(this,qd,o),q(this,h0,r),[t,n]=oe(this,p0,i4).call(this,t,n);const i=q(this,Hs,[NaN,NaN,NaN,NaN,t,n]);q(this,Fa,[t,n]),q(this,Ws,[{line:i,points:y(this,Fa)}]),y(this,Si).set(i,0)}updateProperty(t,n){t==="stroke-width"&&q(this,h0,n)}isEmpty(){return!y(this,Ws)||y(this,Ws).length===0}isCancellable(){return y(this,Fa).length<=10}add(t,n){[t,n]=oe(this,p0,i4).call(this,t,n);const[s,a,o,r]=y(this,Si).subarray(2,6),i=t-o,l=n-r;return Math.hypot(y(this,Yd)*i,y(this,Xd)*l)<=2?null:(y(this,Fa).push(t,n),isNaN(s)?(y(this,Si).set([o,r,t,n],2),y(this,Hs).push(NaN,NaN,NaN,NaN,t,n),{path:{d:this.toSVGPath()}}):(isNaN(y(this,Si)[0])&&y(this,Hs).splice(6,6),y(this,Si).set([s,a,o,r,t,n],0),y(this,Hs).push(...At.createBezierPoints(s,a,o,r,t,n)),{path:{d:this.toSVGPath()}}))}end(t,n){const s=this.add(t,n);return s||(y(this,Fa).length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,n,s,a,o){q(this,Yd,s),q(this,Xd,a),q(this,qd,o),[t,n]=oe(this,p0,i4).call(this,t,n);const r=q(this,Hs,[NaN,NaN,NaN,NaN,t,n]);q(this,Fa,[t,n]);const i=y(this,Ws).at(-1);return i&&(i.line=new Float32Array(i.line),i.points=new Float32Array(i.points)),y(this,Ws).push({line:r,points:y(this,Fa)}),y(this,Si).set(r,0),q(this,Jo,0),this.toSVGPath(),null}getLastElement(){return y(this,Ws).at(-1)}setLastElement(t){return y(this,Ws)?(y(this,Ws).push(t),q(this,Hs,t.line),q(this,Fa,t.points),q(this,Jo,0),{path:{d:this.toSVGPath()}}):y(this,Gd).setLastElement(t)}removeLastElement(){if(!y(this,Ws))return y(this,Gd).removeLastElement();y(this,Ws).pop(),q(this,Qs,"");for(let t=0,n=y(this,Ws).length;tC??NaN),h,p,v,m),points:g(l[_].map(C=>C??NaN),h,p,v,m)});const b=new Ow;return b.build(d,a,o,1,c,u,r),b}get box(){return y(this,Ba)}updateProperty(n,s){return n==="stroke-width"?oe(this,ea,SI).call(this,s):null}updateParentDimensions([n,s],a){const[o,r]=oe(this,ea,Kl).call(this);q(this,xi,n),q(this,ki,s),q(this,v0,a);const[i,l]=oe(this,ea,Kl).call(this),c=i-o,u=l-r,d=y(this,Ba);return d[0]-=c,d[1]-=u,d[2]+=2*c,d[3]+=2*u,d}updateRotation(n){return q(this,n2,n),{path:{transform:this.rotationTransform}}}get viewBox(){return y(this,Ba).map(At.svgRound).join(" ")}get defaultProperties(){const[n,s]=y(this,Ba);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${At.svgRound(n)} ${At.svgRound(s)}`}}}get rotationTransform(){const[,,n,s]=y(this,Ba);let a=0,o=0,r=0,i=0,l=0,c=0;switch(y(this,n2)){case 90:o=s/n,r=-n/s,l=n;break;case 180:a=-1,i=-1,l=n,c=s;break;case 270:o=-s/n,r=n/s,c=s;break;default:return""}return`matrix(${a} ${o} ${r} ${i} ${At.svgRound(l)} ${At.svgRound(c)})`}getPathResizingSVGProperties([n,s,a,o]){const[r,i]=oe(this,ea,Kl).call(this),[l,c,u,d]=y(this,Ba);if(Math.abs(u-r)<=At.PRECISION||Math.abs(d-i)<=At.PRECISION){const g=n+a/2-(l+u/2),b=s+o/2-(c+d/2);return{path:{"transform-origin":`${At.svgRound(n)} ${At.svgRound(s)}`,transform:`${this.rotationTransform} translate(${g} ${b})`}}}const h=(a-2*r)/(u-2*r),p=(o-2*i)/(d-2*i),v=u/a,m=d/o;return{path:{"transform-origin":`${At.svgRound(l)} ${At.svgRound(c)}`,transform:`${this.rotationTransform} scale(${v} ${m}) translate(${At.svgRound(r)} ${At.svgRound(i)}) scale(${h} ${p}) translate(${At.svgRound(-r)} ${At.svgRound(-i)})`}}}getPathResizedSVGProperties([n,s,a,o]){const[r,i]=oe(this,ea,Kl).call(this),l=y(this,Ba),[c,u,d,h]=l;if(l[0]=n,l[1]=s,l[2]=a,l[3]=o,Math.abs(d-r)<=At.PRECISION||Math.abs(h-i)<=At.PRECISION){const b=n+a/2-(c+d/2),_=s+o/2-(u+h/2);for(const{line:w,points:C}of y(this,Po))At._translate(w,b,_,w),At._translate(C,b,_,C);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${At.svgRound(n)} ${At.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const p=(a-2*r)/(d-2*r),v=(o-2*i)/(h-2*i),m=-p*(c+r)+n+r,g=-v*(u+i)+s+i;if(p!==1||v!==1||m!==0||g!==0)for(const{line:b,points:_}of y(this,Po))At._rescale(b,m,g,p,v,b),At._rescale(_,m,g,p,v,_);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${At.svgRound(n)} ${At.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([n,s],a){const[o,r]=a,i=y(this,Ba),l=n-i[0],c=s-i[1];if(y(this,xi)===o&&y(this,ki)===r)for(const{line:u,points:d}of y(this,Po))At._translate(u,l,c,u),At._translate(d,l,c,d);else{const u=y(this,xi)/o,d=y(this,ki)/r;q(this,xi,o),q(this,ki,r);for(const{line:h,points:p}of y(this,Po))At._rescale(h,l,c,u,d,h),At._rescale(p,l,c,u,d,p);i[2]*=u,i[3]*=d}return i[0]=n,i[1]=s,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${At.svgRound(n)} ${At.svgRound(s)}`}}}get defaultSVGProperties(){const n=y(this,Ba);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${At.svgRound(n[0])} ${At.svgRound(n[1])}`,transform:this.rotationTransform||null},bbox:n}}};Ba=new WeakMap,n2=new WeakMap,s2=new WeakMap,Po=new WeakMap,xi=new WeakMap,ki=new WeakMap,v0=new WeakMap,m0=new WeakMap,g0=new WeakMap,ea=new WeakSet,Kl=function(n=y(this,g0)){const s=y(this,s2)+n/2*y(this,v0);return y(this,m0)%180===0?[s/y(this,xi),s/y(this,ki)]:[s/y(this,ki),s/y(this,xi)]},_I=function(){const[n,s,a,o]=y(this,Ba),[r,i]=oe(this,ea,Kl).call(this,0);return[n+r,s+i,a-2*r,o-2*i]},CI=function(){const n=q(this,Ba,new Float32Array([1/0,1/0,-1/0,-1/0]));for(const{line:o}of y(this,Po)){if(o.length<=12){for(let l=4,c=o.length;li!==s[l])||n.thickness!==a||n.opacity!==o||n.pageIndex!==r},Wt(y0,"_type","ink"),Wt(y0,"_editorType",rn.INK),Wt(y0,"_defaultDrawingOptions",null);let kw=y0;const a2=class a2 extends as{constructor(n){super({...n,name:"stampEditor"});se(this,_n);se(this,rs,null);se(this,ta,null);se(this,Yc,null);se(this,Fl,null);se(this,Xc,null);se(this,w0,"");se(this,Ei,null);se(this,Ai,null);se(this,Ro,!1);se(this,_0,!1);q(this,Fl,n.bitmapUrl),q(this,Xc,n.bitmapFile)}static initialize(n,s){as.initialize(n,s)}static get supportedTypes(){return fn(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return fn(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(n){return this.supportedTypes.includes(n)}static paste(n,s){s.pasteEditor(rn.STAMP,{bitmapFile:n.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){var n;return{type:"stamp",hasAltText:!!((n=this.altTextData)!=null&&n.altText)}}static computeTelemetryFinalData(n){const s=n.get("hasAltText");return{hasAltText:s.get(!0)??0,hasNoAltText:s.get(!1)??0}}async mlGuessAltText(n=null,s=!0){if(this.hasAltTextData())return null;const{mlManager:a}=this._uiManager;if(!a)throw new Error("No ML.");if(!await a.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:o,width:r,height:i}=n||this.copyCanvas(null,null,!0).imageData,l=await a.guess({name:"altText",request:{data:o,width:r,height:i,channels:o.length/(r*i)}});if(!l)throw new Error("No response from the AI service.");if(l.error)throw new Error("Error from the AI service.");if(l.cancel)return null;if(!l.output)throw new Error("No valid response from the AI service.");const c=l.output;return await this.setGuessedAltText(c),s&&!this.hasAltTextData()&&(this.altTextData={alt:c,decorative:!1}),c}remove(){var n;y(this,ta)&&(q(this,rs,null),this._uiManager.imageManager.deleteId(y(this,ta)),(n=y(this,Ei))==null||n.remove(),q(this,Ei,null),y(this,Ai)&&(clearTimeout(y(this,Ai)),q(this,Ai,null))),super.remove()}rebuild(){if(!this.parent){y(this,ta)&&oe(this,_n,l4).call(this);return}super.rebuild(),this.div!==null&&(y(this,ta)&&y(this,Ei)===null&&oe(this,_n,l4).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(n){this._isDraggable=!0,n&&this.div.focus()}isEmpty(){return!(y(this,Yc)||y(this,rs)||y(this,Fl)||y(this,Xc)||y(this,ta))}get isResizable(){return!0}render(){if(this.div)return this.div;let n,s;if(this.width&&(n=this.x,s=this.y),super.render(),this.div.hidden=!0,this.div.setAttribute("role","figure"),this.addAltTextButton(),y(this,rs)?oe(this,_n,x_).call(this):oe(this,_n,l4).call(this),this.width&&!this.annotationElementId){const[a,o]=this.parentDimensions;this.setAt(n*a,s*o,this.width*a,this.height*o)}return this._uiManager.addShouldRescale(this),this.div}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;y(this,Ai)!==null&&clearTimeout(y(this,Ai)),q(this,Ai,setTimeout(()=>{q(this,Ai,null),oe(this,_n,k_).call(this)},200))}copyCanvas(n,s,a=!1){var p;n||(n=224);const{width:o,height:r}=y(this,rs),i=new sw;let l=y(this,rs),c=o,u=r,d=null;if(s){if(o>s||r>s){const R=Math.min(s/o,s/r);c=Math.floor(o*R),u=Math.floor(r*R)}d=document.createElement("canvas");const v=d.width=Math.ceil(c*i.sx),m=d.height=Math.ceil(u*i.sy);y(this,Ro)||(l=oe(this,_n,c4).call(this,v,m));const g=d.getContext("2d");g.filter=this._uiManager.hcmFilter;let b="white",_="#cfcfd8";this._uiManager.hcmFilter!=="none"?_="black":(p=window.matchMedia)!=null&&p.call(window,"(prefers-color-scheme: dark)").matches&&(b="#8f8f9d",_="#42414d");const w=15,C=w*i.sx,x=w*i.sy,k=new OffscreenCanvas(C*2,x*2),T=k.getContext("2d");T.fillStyle=b,T.fillRect(0,0,C*2,x*2),T.fillStyle=_,T.fillRect(0,0,C,x),T.fillRect(C,x,C,x),g.fillStyle=g.createPattern(k,"repeat"),g.fillRect(0,0,v,m),g.drawImage(l,0,0,l.width,l.height,0,0,v,m)}let h=null;if(a){let v,m;if(i.symmetric&&l.widthn||r>n){const _=Math.min(n/o,n/r);v=Math.floor(o*_),m=Math.floor(r*_),y(this,Ro)||(l=oe(this,_n,c4).call(this,v,m))}const b=new OffscreenCanvas(v,m).getContext("2d",{willReadFrequently:!0});b.drawImage(l,0,0,l.width,l.height,0,0,v,m),h={width:v,height:m,data:b.getImageData(0,0,v,m).data}}return{canvas:d,width:c,height:u,imageData:h}}getImageForAltText(){return y(this,Ei)}static async deserialize(n,s,a){var m;let o=null;if(n instanceof eR){const{data:{rect:g,rotation:b,id:_,structParent:w,popupRef:C},container:x,parent:{page:{pageNumber:k}}}=n,T=x.querySelector("canvas"),R=a.imageManager.getFromCanvas(x.id,T);T.remove();const I=((m=await s._structTree.getAriaAttributes(`${Z8}${_}`))==null?void 0:m.get("aria-label"))||"";o=n={annotationType:rn.STAMP,bitmapId:R.id,bitmap:R.bitmap,pageIndex:k-1,rect:g.slice(0),rotation:b,id:_,deleted:!1,accessibilityData:{decorative:!1,altText:I},isSvg:!1,structParent:w,popupRef:C}}const r=await super.deserialize(n,s,a),{rect:i,bitmap:l,bitmapUrl:c,bitmapId:u,isSvg:d,accessibilityData:h}=n;u&&a.imageManager.isValidId(u)?(q(r,ta,u),l&&q(r,rs,l)):q(r,Fl,c),q(r,Ro,d);const[p,v]=r.pageDimensions;return r.width=(i[2]-i[0])/p,r.height=(i[3]-i[1])/v,r.annotationElementId=n.id||null,h&&(r.altTextData=h),r._initialData=o,q(r,_0,!!o),r}serialize(n=!1,s=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const a={annotationType:rn.STAMP,bitmapId:y(this,ta),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:y(this,Ro),structTreeParentId:this._structTreeParentId};if(n)return a.bitmapUrl=oe(this,_n,u4).call(this,!0),a.accessibilityData=this.serializeAltText(!0),a;const{decorative:o,altText:r}=this.serializeAltText(!1);if(!o&&r&&(a.accessibilityData={type:"Figure",alt:r}),this.annotationElementId){const l=oe(this,_n,kI).call(this,a);if(l.isSame)return null;l.isSameAltText?delete a.accessibilityData:a.accessibilityData.structParent=this._initialData.structParent??-1}if(a.id=this.annotationElementId,s===null)return a;s.stamps||(s.stamps=new Map);const i=y(this,Ro)?(a.rect[2]-a.rect[0])*(a.rect[3]-a.rect[1]):null;if(!s.stamps.has(y(this,ta)))s.stamps.set(y(this,ta),{area:i,serialized:a}),a.bitmap=oe(this,_n,u4).call(this,!1);else if(y(this,Ro)){const l=s.stamps.get(y(this,ta));i>l.area&&(l.area=i,l.serialized.bitmap.close(),l.serialized.bitmap=oe(this,_n,u4).call(this,!1))}return a}renderAnnotationElement(n){return n.updateEdited({rect:this.getRect(0,0)}),null}};rs=new WeakMap,ta=new WeakMap,Yc=new WeakMap,Fl=new WeakMap,Xc=new WeakMap,w0=new WeakMap,Ei=new WeakMap,Ai=new WeakMap,Ro=new WeakMap,_0=new WeakMap,_n=new WeakSet,y2=function(n,s=!1){if(!n){this.remove();return}q(this,rs,n.bitmap),s||(q(this,ta,n.id),q(this,Ro,n.isSvg)),n.file&&q(this,w0,n.file.name),oe(this,_n,x_).call(this)},w2=function(){if(q(this,Yc,null),this._uiManager.enableWaiting(!1),!!y(this,Ei)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&y(this,rs)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&y(this,rs)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},l4=function(){if(y(this,ta)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(y(this,ta)).then(a=>oe(this,_n,y2).call(this,a,!0)).finally(()=>oe(this,_n,w2).call(this));return}if(y(this,Fl)){const a=y(this,Fl);q(this,Fl,null),this._uiManager.enableWaiting(!0),q(this,Yc,this._uiManager.imageManager.getFromUrl(a).then(o=>oe(this,_n,y2).call(this,o)).finally(()=>oe(this,_n,w2).call(this)));return}if(y(this,Xc)){const a=y(this,Xc);q(this,Xc,null),this._uiManager.enableWaiting(!0),q(this,Yc,this._uiManager.imageManager.getFromFile(a).then(o=>oe(this,_n,y2).call(this,o)).finally(()=>oe(this,_n,w2).call(this)));return}const n=document.createElement("input");n.type="file",n.accept=a2.supportedTypesStr;const s=this._uiManager._signal;q(this,Yc,new Promise(a=>{n.addEventListener("change",async()=>{if(!n.files||n.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const o=await this._uiManager.imageManager.getFromFile(n.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),oe(this,_n,y2).call(this,o)}a()},{signal:s}),n.addEventListener("cancel",()=>{this.remove(),a()},{signal:s})}).finally(()=>oe(this,_n,w2).call(this))),n.click()},x_=function(){var d;const{div:n}=this;let{width:s,height:a}=y(this,rs);const[o,r]=this.pageDimensions,i=.75;if(this.width)s=this.width*o,a=this.height*r;else if(s>i*o||a>i*r){const h=Math.min(i*o/s,i*r/a);s*=h,a*=h}const[l,c]=this.parentDimensions;this.setDims(s*l/o,a*c/r),this._uiManager.enableWaiting(!1);const u=q(this,Ei,document.createElement("canvas"));u.setAttribute("role","img"),this.addContainer(u),this.width=s/o,this.height=a/r,(d=this._initialOptions)!=null&&d.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(n.hidden=!1),oe(this,_n,k_).call(this),y(this,_0)||(this.parent.addUndoableEditor(this),q(this,_0,!0)),this._reportTelemetry({action:"inserted_image"}),y(this,w0)&&u.setAttribute("aria-label",y(this,w0))},c4=function(n,s){const{width:a,height:o}=y(this,rs);let r=a,i=o,l=y(this,rs);for(;r>2*n||i>2*s;){const c=r,u=i;r>2*n&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2)),i>2*s&&(i=i>=16384?Math.floor(i/2)-1:Math.ceil(i/2));const d=new OffscreenCanvas(r,i);d.getContext("2d").drawImage(l,0,0,c,u,0,0,r,i),l=d.transferToImageBitmap()}return l},k_=function(){const[n,s]=this.parentDimensions,{width:a,height:o}=this,r=new sw,i=Math.ceil(a*n*r.sx),l=Math.ceil(o*s*r.sy),c=y(this,Ei);if(!c||c.width===i&&c.height===l)return;c.width=i,c.height=l;const u=y(this,Ro)?y(this,rs):oe(this,_n,c4).call(this,i,l),d=c.getContext("2d");d.filter=this._uiManager.hcmFilter,d.drawImage(u,0,0,u.width,u.height,0,0,i,l)},u4=function(n){if(n){if(y(this,Ro)){const o=this._uiManager.imageManager.getSvgUrl(y(this,ta));if(o)return o}const s=document.createElement("canvas");return{width:s.width,height:s.height}=y(this,rs),s.getContext("2d").drawImage(y(this,rs),0,0),s.toDataURL()}if(y(this,Ro)){const[s,a]=this.pageDimensions,o=Math.round(this.width*s*_c.PDF_TO_CSS_UNITS),r=Math.round(this.height*a*_c.PDF_TO_CSS_UNITS),i=new OffscreenCanvas(o,r);return i.getContext("2d").drawImage(y(this,rs),0,0,y(this,rs).width,y(this,rs).height,0,0,o,r),i.transferToImageBitmap()}return structuredClone(y(this,rs))},kI=function(n){var i;const{pageIndex:s,accessibilityData:{altText:a}}=this._initialData,o=n.pageIndex===s,r=(((i=n.accessibilityData)==null?void 0:i.alt)||"")===a;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&o&&r,isSameAltText:r}},Wt(a2,"_type","stamp"),Wt(a2,"_editorType",rn.STAMP);let Ew=a2;const Fr=class Fr{constructor({uiManager:t,pageIndex:n,div:s,structTreeLayer:a,accessibilityManager:o,annotationLayer:r,drawLayer:i,textLayer:l,viewport:c,l10n:u}){se(this,ts);se(this,Jd);se(this,C0,!1);se(this,Ti,null);se(this,Jc,null);se(this,Bl,null);se(this,Zo,new Map);se(this,Zc,!1);se(this,S0,!1);se(this,Zd,!1);se(this,Dr,null);se(this,Vl,null);se(this,_a,null);se(this,zl,null);se(this,Lt);const d=[...y(Fr,Qc).values()];if(!Fr._initialized){Fr._initialized=!0;for(const h of d)h.initialize(u,t)}t.registerEditorTypes(d),q(this,Lt,t),this.pageIndex=n,this.div=s,q(this,Jd,o),q(this,Ti,r),this.viewport=c,q(this,_a,l),this.drawLayer=i,this._structTree=a,y(this,Lt).addLayer(this)}get isEmpty(){return y(this,Zo).size===0}get isInvisible(){return this.isEmpty&&y(this,Lt).getMode()===rn.NONE}updateToolbar(t){y(this,Lt).updateToolbar(t)}updateMode(t=y(this,Lt).getMode()){switch(oe(this,ts,d4).call(this),t){case rn.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case rn.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case rn.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:n}=this.div;for(const s of y(Fr,Qc).values())n.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var n;return t===((n=y(this,_a))==null?void 0:n.div)}setEditingState(t){y(this,Lt).setEditingState(t)}addCommands(t){y(this,Lt).addCommands(t)}cleanUndoStack(t){y(this,Lt).cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){var n;(n=y(this,Ti))==null||n.div.classList.toggle("disabled",!t)}async enable(){q(this,Zd,!0),this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of y(this,Zo).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(y(this,Lt).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!y(this,Ti)){q(this,Zd,!1);return}const n=y(this,Ti).getEditableAnnotations();for(const s of n){if(s.hide(),y(this,Lt).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const a=await this.deserialize(s);a&&(this.addOrRebuild(a),a.enableEditing())}q(this,Zd,!1)}disable(){var a;q(this,S0,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,n=new Map;for(const o of y(this,Zo).values())if(o.disableEditing(),!!o.annotationElementId){if(o.serialize()!==null){t.set(o.annotationElementId,o);continue}else n.set(o.annotationElementId,o);(a=this.getEditableAnnotation(o.annotationElementId))==null||a.show(),o.remove()}if(y(this,Ti)){const o=y(this,Ti).getEditableAnnotations();for(const r of o){const{id:i}=r.data;if(y(this,Lt).isDeletedAnnotationElement(i))continue;let l=n.get(i);if(l){l.resetAnnotationElement(r),l.show(!1),r.show();continue}l=t.get(i),l&&(y(this,Lt).addChangedExistingAnnotation(l),l.renderAnnotationElement(r)&&l.show(!1)),r.show()}}oe(this,ts,d4).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const o of y(Fr,Qc).values())s.remove(`${o._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),q(this,S0,!1)}getEditableAnnotation(t){var n;return((n=y(this,Ti))==null?void 0:n.getEditableAnnotation(t))||null}setActiveEditor(t){y(this,Lt).getActive()!==t&&y(this,Lt).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=y(this,_a))!=null&&t.div&&!y(this,zl)){q(this,zl,new AbortController);const n=y(this,Lt).combinedSignal(y(this,zl));y(this,_a).div.addEventListener("pointerdown",oe(this,ts,EI).bind(this),{signal:n}),y(this,_a).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=y(this,_a))!=null&&t.div&&y(this,zl)&&(y(this,zl).abort(),q(this,zl,null),y(this,_a).div.classList.remove("highlighting"))}enableClick(){if(y(this,Jc))return;q(this,Jc,new AbortController);const t=y(this,Lt).combinedSignal(y(this,Jc));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const n=this.pointerup.bind(this);this.div.addEventListener("pointerup",n,{signal:t}),this.div.addEventListener("pointercancel",n,{signal:t})}disableClick(){var t;(t=y(this,Jc))==null||t.abort(),q(this,Jc,null)}attach(t){y(this,Zo).set(t.id,t);const{annotationElementId:n}=t;n&&y(this,Lt).isDeletedAnnotationElement(n)&&y(this,Lt).removeDeletedAnnotationElement(t)}detach(t){var n;y(this,Zo).delete(t.id),(n=y(this,Jd))==null||n.removePointerInTextLayer(t.contentDiv),!y(this,S0)&&t.annotationElementId&&y(this,Lt).addDeletedAnnotationElement(t)}remove(t){this.detach(t),y(this,Lt).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){var n;t.parent!==this&&(t.parent&&t.annotationElementId&&(y(this,Lt).addDeletedAnnotationElement(t.annotationElementId),as.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(n=t.parent)==null||n.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),y(this,Lt).addEditor(t),this.attach(t),!t.isAttachedToDOM){const n=t.render();this.div.append(n),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!y(this,Zd)),y(this,Lt).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:n}=document;t.div.contains(n)&&!y(this,Bl)&&(t._focusEventsAllowed=!1,q(this,Bl,setTimeout(()=>{q(this,Bl,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:y(this,Lt)._signal}),n.focus())},0))),t._structTreeParentId=(s=y(this,Jd))==null?void 0:s.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||(t.parent=this),t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const n=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:n,undo:s,mustExec:!1})}getNextId(){return y(this,Lt).getId()}combinedSignal(t){return y(this,Lt).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=y(this,ts,Ri))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,n){y(this,Lt).updateToolbar(t),y(this,Lt).updateMode(t);const{offsetX:s,offsetY:a}=oe(this,ts,A_).call(this),o=this.getNextId(),r=oe(this,ts,E_).call(this,{parent:this,id:o,x:s,y:a,uiManager:y(this,Lt),isCentered:!0,...n});r&&this.add(r)}async deserialize(t){var n;return await((n=y(Fr,Qc).get(t.annotationType??t.annotationEditorType))==null?void 0:n.deserialize(t,this,y(this,Lt)))||null}createAndAddNewEditor(t,n,s={}){const a=this.getNextId(),o=oe(this,ts,E_).call(this,{parent:this,id:a,x:t.offsetX,y:t.offsetY,uiManager:y(this,Lt),isCentered:n,...s});return o&&this.add(o),o}addNewEditor(){this.createAndAddNewEditor(oe(this,ts,A_).call(this),!0)}setSelected(t){y(this,Lt).setSelected(t)}toggleSelected(t){y(this,Lt).toggleSelected(t)}unselect(t){y(this,Lt).unselect(t)}pointerup(t){var s;const{isMac:n}=La.platform;if(!(t.button!==0||t.ctrlKey&&n)&&t.target===this.div&&y(this,Zc)&&(q(this,Zc,!1),!((s=y(this,ts,Ri))!=null&&s.isDrawer&&y(this,ts,Ri).supportMultipleDrawings))){if(!y(this,C0)){q(this,C0,!0);return}if(y(this,Lt).getMode()===rn.STAMP){y(this,Lt).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){var a;if(y(this,Lt).getMode()===rn.HIGHLIGHT&&this.enableTextSelection(),y(this,Zc)){q(this,Zc,!1);return}const{isMac:n}=La.platform;if(t.button!==0||t.ctrlKey&&n||t.target!==this.div)return;if(q(this,Zc,!0),(a=y(this,ts,Ri))!=null&&a.isDrawer){this.startDrawingSession(t);return}const s=y(this,Lt).getActive();q(this,C0,!s||s.isEmpty())}startDrawingSession(t){if(this.div.focus(),y(this,Dr)){y(this,ts,Ri).startDrawing(this,y(this,Lt),!1,t);return}y(this,Lt).setCurrentDrawingSession(this),q(this,Dr,new AbortController);const n=y(this,Lt).combinedSignal(y(this,Dr));this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(q(this,Vl,null),this.commitOrRemove())},{signal:n}),y(this,ts,Ri).startDrawing(this,y(this,Lt),!1,t)}pause(t){if(t){const{activeElement:n}=document;this.div.contains(n)&&q(this,Vl,n);return}y(this,Vl)&&setTimeout(()=>{var n;(n=y(this,Vl))==null||n.focus(),q(this,Vl,null)},0)}endDrawingSession(t=!1){return y(this,Dr)?(y(this,Lt).setCurrentDrawingSession(null),y(this,Dr).abort(),q(this,Dr,null),q(this,Vl,null),y(this,ts,Ri).endDrawing(t)):null}findNewParent(t,n,s){const a=y(this,Lt).findParent(n,s);return a===null||a===this?!1:(a.changeParent(t),!0)}commitOrRemove(){return y(this,Dr)?(this.endDrawingSession(),!0):!1}onScaleChanging(){y(this,Dr)&&y(this,ts,Ri).onScaleChangingWhenDrawing(this)}destroy(){var t,n;this.commitOrRemove(),((t=y(this,Lt).getActive())==null?void 0:t.parent)===this&&(y(this,Lt).commitOrRemove(),y(this,Lt).setActiveEditor(null)),y(this,Bl)&&(clearTimeout(y(this,Bl)),q(this,Bl,null));for(const s of y(this,Zo).values())(n=y(this,Jd))==null||n.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,y(this,Zo).clear(),y(this,Lt).removeLayer(this)}render({viewport:t}){this.viewport=t,Wu(this.div,t);for(const n of y(this,Lt).getEditors(this.pageIndex))this.add(n),n.rebuild();this.updateMode()}update({viewport:t}){y(this,Lt).commitOrRemove(),oe(this,ts,d4).call(this);const n=this.viewport.rotation,s=t.rotation;if(this.viewport=t,Wu(this.div,{rotation:s}),n!==s)for(const a of y(this,Zo).values())a.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:n}=this.viewport.rawDims;return[t,n]}get scale(){return y(this,Lt).viewParameters.realScale}};Jd=new WeakMap,C0=new WeakMap,Ti=new WeakMap,Jc=new WeakMap,Bl=new WeakMap,Zo=new WeakMap,Zc=new WeakMap,S0=new WeakMap,Zd=new WeakMap,Dr=new WeakMap,Vl=new WeakMap,_a=new WeakMap,zl=new WeakMap,Lt=new WeakMap,Qc=new WeakMap,ts=new WeakSet,EI=function(t){y(this,Lt).unselectAll();const{target:n}=t;if(n===y(this,_a).div||(n.getAttribute("role")==="img"||n.classList.contains("endOfContent"))&&y(this,_a).div.contains(n)){const{isMac:s}=La.platform;if(t.button!==0||t.ctrlKey&&s)return;y(this,Lt).showAllEditors("highlight",!0,!0),y(this,_a).div.classList.add("free"),this.toggleDrawing(),fb.startHighlighting(this,y(this,Lt).direction==="ltr",{target:y(this,_a).div,x:t.x,y:t.y}),y(this,_a).div.addEventListener("pointerup",()=>{y(this,_a).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:y(this,Lt)._signal}),t.preventDefault()}},Ri=function(){return y(Fr,Qc).get(y(this,Lt).getMode())},E_=function(t){const n=y(this,ts,Ri);return n?new n.prototype.constructor(t):null},A_=function(){const{x:t,y:n,width:s,height:a}=this.div.getBoundingClientRect(),o=Math.max(0,t),r=Math.max(0,n),i=Math.min(window.innerWidth,t+s),l=Math.min(window.innerHeight,n+a),c=(o+i)/2-t,u=(r+l)/2-n,[d,h]=this.viewport.rotation%180===0?[c,u]:[u,c];return{offsetX:d,offsetY:h}},d4=function(){for(const t of y(this,Zo).values())t.isEmpty()&&t.remove()},Wt(Fr,"_initialized",!1),se(Fr,Qc,new Map([ww,kw,Ew,fb].map(t=>[t._editorType,t])));let Aw=Fr;const Ca=class Ca{constructor({pageIndex:t}){se(this,Mi);se(this,Br,null);se(this,o2,0);se(this,Va,new Map);se(this,Qd,new Map);this.pageIndex=t}setParent(t){if(!y(this,Br)){q(this,Br,t);return}if(y(this,Br)!==t){if(y(this,Va).size>0)for(const n of y(this,Va).values())n.remove(),t.append(n);q(this,Br,t)}}static get _svgFactory(){return fn(this,"_svgFactory",new gw)}draw(t,n=!1,s=!1){const a=za(this,o2)._++,o=oe(this,Mi,T_).call(this),r=Ca._svgFactory.createElement("defs");o.append(r);const i=Ca._svgFactory.createElement("path");r.append(i);const l=`path_p${this.pageIndex}_${a}`;i.setAttribute("id",l),i.setAttribute("vector-effect","non-scaling-stroke"),n&&y(this,Qd).set(a,i);const c=s?oe(this,Mi,TI).call(this,r,l):null,u=Ca._svgFactory.createElement("use");return o.append(u),u.setAttribute("href",`#${l}`),this.updateProperties(o,t),y(this,Va).set(a,o),{id:a,clipPathId:`url(#${c})`}}drawOutline(t,n){const s=za(this,o2)._++,a=oe(this,Mi,T_).call(this),o=Ca._svgFactory.createElement("defs");a.append(o);const r=Ca._svgFactory.createElement("path");o.append(r);const i=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",i),r.setAttribute("vector-effect","non-scaling-stroke");let l;if(n){const d=Ca._svgFactory.createElement("mask");o.append(d),l=`mask_p${this.pageIndex}_${s}`,d.setAttribute("id",l),d.setAttribute("maskUnits","objectBoundingBox");const h=Ca._svgFactory.createElement("rect");d.append(h),h.setAttribute("width","1"),h.setAttribute("height","1"),h.setAttribute("fill","white");const p=Ca._svgFactory.createElement("use");d.append(p),p.setAttribute("href",`#${i}`),p.setAttribute("stroke","none"),p.setAttribute("fill","black"),p.setAttribute("fill-rule","nonzero"),p.classList.add("mask")}const c=Ca._svgFactory.createElement("use");a.append(c),c.setAttribute("href",`#${i}`),l&&c.setAttribute("mask",`url(#${l})`);const u=c.cloneNode();return a.append(u),c.classList.add("mainOutline"),u.classList.add("secondaryOutline"),this.updateProperties(a,t),y(this,Va).set(s,a),s}finalizeDraw(t,n){y(this,Qd).delete(t),this.updateProperties(t,n)}updateProperties(t,n){var l;if(!n)return;const{root:s,bbox:a,rootClass:o,path:r}=n,i=typeof t=="number"?y(this,Va).get(t):t;if(i){if(s&&oe(this,Mi,M_).call(this,i,s),a&&oe(l=Ca,Ob,AI).call(l,i,a),o){const{classList:c}=i;for(const[u,d]of Object.entries(o))c.toggle(u,d)}if(r){const u=i.firstChild.firstChild;oe(this,Mi,M_).call(this,u,r)}}}updateParent(t,n){if(n===this)return;const s=y(this,Va).get(t);s&&(y(n,Br).append(s),y(this,Va).delete(t),y(n,Va).set(t,s))}remove(t){y(this,Qd).delete(t),y(this,Br)!==null&&(y(this,Va).get(t).remove(),y(this,Va).delete(t))}destroy(){q(this,Br,null);for(const t of y(this,Va).values())t.remove();y(this,Va).clear(),y(this,Qd).clear()}};Br=new WeakMap,o2=new WeakMap,Va=new WeakMap,Qd=new WeakMap,Ob=new WeakSet,AI=function(t,[n,s,a,o]){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*n}%`,r.width=`${100*a}%`,r.height=`${100*o}%`},Mi=new WeakSet,T_=function(){const t=Ca._svgFactory.create(1,1,!0);return y(this,Br).append(t),t.setAttribute("aria-hidden",!0),t},TI=function(t,n){const s=Ca._svgFactory.createElement("clipPath");t.append(s);const a=`clip_${n}`;s.setAttribute("id",a),s.setAttribute("clipPathUnits","objectBoundingBox");const o=Ca._svgFactory.createElement("use");return s.append(o),o.setAttribute("href",`#${n}`),o.classList.add("clip"),a},M_=function(t,n){for(const[s,a]of Object.entries(n))a===null?t.removeAttribute(s):t.setAttribute(s,a)},se(Ca,Ob);let Tw=Ca;globalThis.pdfjsTestingUtils={HighlightOutliner:_w},Jt.AbortException,Jt.AnnotationEditorLayer,Jt.AnnotationEditorParamsType,Jt.AnnotationEditorType,Jt.AnnotationEditorUIManager,Jt.AnnotationLayer,Jt.AnnotationMode,Jt.ColorPicker,Jt.DOMSVGFactory,Jt.DrawLayer,Jt.FeatureTest;var B4e=Jt.GlobalWorkerOptions;Jt.ImageKind,Jt.InvalidPDFException,Jt.MissingPDFException,Jt.OPS,Jt.OutputScale,Jt.PDFDataRangeTransport,Jt.PDFDateString,Jt.PDFWorker,Jt.PasswordResponses,Jt.PermissionFlag,Jt.PixelsPerInch,Jt.RenderingCancelledException,Jt.TextLayer,Jt.TouchManager,Jt.UnexpectedResponseException,Jt.Util,Jt.VerbosityLevel,Jt.XfaLayer,Jt.build,Jt.createValidAbsoluteUrl,Jt.fetchData;var V4e=Jt.getDocument;Jt.getFilenameFromUrl,Jt.getPdfFilenameFromUrl,Jt.getXfaPageViewport,Jt.isDataScheme,Jt.isPdfFile,Jt.noContextMenu,Jt.normalizeUnicode,Jt.setLayerDimensions,Jt.shadow,Jt.stopEvent,Jt.version;const z4e=""+new URL("assets/pdf.worker.min-yatZIOMy.mjs",document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href,H4e={class:"manual-wrap"},W4e={class:"sidebar"},j4e={class:"es-text",style:{display:"none"}},K4e={class:"sb-section"},U4e={class:"sb-title"},q4e={key:0,class:"sb-section"},G4e={class:"sb-title"},Y4e={class:"region-type-btns"},X4e=["onClick"],J4e={class:"rt-badge"},Z4e={key:1,class:"sb-section sb-regions"},Q4e={class:"sb-title"},eye={class:"region-list"},tye=["onClick"],nye={class:"ri-top"},sye={class:"ri-badge"},aye={class:"ri-label"},oye={class:"ri-page"},rye={class:"ri-status"},iye={key:0,class:"ri-tokens"},lye={key:0,class:"ri-preview"},cye={key:2,class:"sb-section sb-actions"},uye={key:0,class:"vl-progress-wrap"},dye={class:"vl-progress-label"},fye={key:0},hye={key:1,class:"vl-done"},pye={key:3,class:"sb-section sb-export"},vye={class:"sb-title"},mye={style:{display:"flex",gap:"8px"}},gye={class:"sb-footer"},bye={class:"viewer"},yye={key:0,class:"viewer-nav"},wye={class:"el-button-group"},_ye={class:"nav-label"},Cye={class:"nav-type-indicator"},Sye={class:"el-button-group el-button-group--small"},xye={class:"zoom-bar"},kye={class:"zoom-pct"},Eye={key:1,class:"viewer-empty"},Aye={class:"img-inner"},Tye={key:0,class:"page-loading"},Mye=["data-mode"],Pye={key:0,class:"result-panel"},Rye={class:"rp-header"},Iye={class:"rp-title"},Oye={key:0,class:"rp-tokens"},Lye={class:"rp-text"},Nye=[{path:"/",redirect:"/Manual"},{path:"/Auto",component:B1e},{path:"/Manual",component:il({__name:"ManualOCR",setup(e){B4e.workerSrc=z4e;const t=rP(),n="http://localhost:8000",s=[{key:"A",label:"材料区域",color:"#2563eb"},{key:"B",label:"图纸信息",color:"#d97706"},{key:"C",label:"其他",color:"#059669"}],a=Ee=>{var ge;return((ge=s.find(_e=>_e.key===Ee))==null?void 0:ge.color)??"#6b7280"},o=Ee=>{var ge;return((ge=s.find(_e=>_e.key===Ee))==null?void 0:ge.label)??Ee},r=F("file"),i=F(null),l=F(""),c=F(!1),u=F(""),d=F(0),h=F(0),p=F(!1),v=pn(null),m=F(!1);let g=null;const b=F("A"),_=F([]),w=F(null),C=F(!1),x=F(""),k=F(!1),T=F(0),R=F(0),I=F(null),M=F(null),$=F(null),O=F(null),B=[.25,.5,.75,1,1.25,1.5,2,3],U=F(1);function J(){const Ee=B.find(ge=>ge>U.value+.01);Ee&&(U.value=Ee)}function Y(){const Ee=[...B].reverse().find(ge=>ger.value==="file"?!!i.value:l.value.startsWith("http")),ce=E(()=>_.value.filter(Ee=>Ee.status==="pending").length),Z=E(()=>_.value.filter(Ee=>Ee.type==="A"&&Ee.status==="pending").length),H=E(()=>_.value.filter(Ee=>Ee.status==="done")),te=E(()=>_.value.find(Ee=>Ee.id===w.value)||null),de=E(()=>T.value>0?Math.round(R.value/T.value*100):0);let be=null;St(async()=>{try{const _e=await(await fetch(`${n}/api/manual/engine-info`)).json();L.value=_e.status==="ready"?"ready":"error",V.value=_e.error||_e.engine||""}catch(ge){L.value="error",V.value=ge.message}const Ee=document.getElementById("hdpdfurl2");if(Ee&&Ee.value&&Ee.value.trim()&&(l.value=Ee.value.trim(),r.value="url",await Se()),Ee){let ge=Ee.value;be=setInterval(async()=>{const _e=Ee.value?Ee.value.trim():"";_e&&_e!==ge&&(ge=_e,l.value=_e,r.value="url",await Se())},2e3)}});async function Ce(Ee){i.value=Ee.raw,await Se(),O.value&&O.value.clearFiles()}async function Se(){c.value=!0;try{let Ee,ge=null;if(r.value==="file"){ge=await i.value.arrayBuffer();const Oe=new FormData;Oe.append("file",i.value),Ee=await fetch(`${n}/api/manual/upload`,{method:"POST",body:Oe})}else Ee=await fetch(`${n}/api/manual/upload-url`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:l.value.trim()})});if(!Ee.ok){const Oe=await Ee.json().catch(()=>({}));throw new Error(Oe.detail||`HTTP ${Ee.status}`)}const _e=await Ee.json();if(u.value&&fetch(`${n}/api/manual/session/${u.value}`,{method:"DELETE"}).catch(()=>{}),u.value=_e.session_id,d.value=_e.total_pages,h.value=0,_.value=[],w.value=null,p.value=!0,U.value=1,!ge){const Oe=await fetch(`${n}/api/manual/pdf/${_e.session_id}`);if(!Oe.ok)throw new Error(`获取 PDF 字节失败 HTTP ${Oe.status}`);ge=await Oe.arrayBuffer()}await Ve(ge),Ys.success(`PDF 加载成功,共 ${_e.total_pages} 页`)}catch(Ee){Ys.error(`加载失败:${Ee.message}`)}finally{c.value=!1}}function Ne(Ee){Ee<0||Ee>=d.value||(h.value=Ee)}me(h,Ee=>{at(),$e(Ee)}),me(ae,Ee=>{Ee==="draw"&&M.value&&(M.value.style.cursor="")}),me(U,()=>{p.value&&v.value&&$e(h.value)});async function Ve(Ee){try{const ge=V4e({data:Ee,cMapUrl:"/pdfjs-cmaps/",cMapPacked:!0});v.value=await ge.promise,$e(0)}catch(ge){Ys.error(`PDF.js 加载失败:${ge.message}`)}}async function $e(Ee){if(v.value){g&&(g.cancel(),g=null),m.value=!0;try{const ge=await v.value.getPage(Ee+1),_e=window.devicePixelRatio||1,Oe=ge.getViewport({scale:U.value*_e}),Fe=$.value;Fe.width=Oe.width,Fe.height=Oe.height,Fe.style.width=Oe.width/_e+"px",Fe.style.height=Oe.height/_e+"px";const xt=Fe.getContext("2d");g=ge.render({canvasContext:xt,viewport:Oe}),await g.promise,g=null,Ie()}catch(ge){(ge==null?void 0:ge.name)!=="RenderingCancelledException"&&Ys.error(`页面渲染失败:${ge.message}`)}finally{m.value=!1}}}let we=null;function Ie(){const Ee=$.value,ge=M.value;if(!Ee||!ge)return;const _e=Ee.offsetWidth,Oe=Ee.offsetHeight;_e===0||Oe===0||((ge.width!==_e||ge.height!==Oe)&&(ge.width=_e,ge.height=Oe),ut(),we||(we=new ResizeObserver(()=>Ie())),we.disconnect(),we.observe(Ee))}window.addEventListener("resize",()=>{p.value&&Ie()});function Pe(Ee){const ge=M.value.getBoundingClientRect();return{x:Ee.clientX-ge.left,y:Ee.clientY-ge.top}}function We(Ee){fe.value&&(I.value.scrollLeft=ne.value-Ee.clientX,I.value.scrollTop=pe.value-Ee.clientY)}function Ze(){fe.value&&(fe.value=!1,M.value&&(M.value.style.cursor=""),window.removeEventListener("mousemove",We),window.removeEventListener("mouseup",Ze))}function rt(Ee){if(!z.value)return;const{x:ge,y:_e}=Pe(Ee);K.value=ge,ee.value=_e,ut()}function De(Ee){if(!z.value)return;const{x:ge,y:_e}=Pe(Ee);z.value=!1,window.removeEventListener("mousemove",rt),window.removeEventListener("mouseup",De);const Oe=M.value,Fe=Oe.width,xt=Oe.height,Ft=nf=>Math.max(0,Math.min(Fe,nf)),bn=nf=>Math.max(0,Math.min(xt,nf)),Sn=Ft(ge),Et=bn(_e),js=Ft(G.value),zn=bn(Q.value),Hl=Math.min(js,Sn),eu=Math.min(zn,Et),ef=Math.abs(Sn-js),tf=Math.abs(Et-zn);ef>8&&tf>8&&_.value.push({id:crypto.randomUUID(),type:b.value,page:h.value,xr:Hl/Fe,yr:eu/xt,wr:ef/Fe,hr:tf/xt,cx:Hl,cy:eu,cw:ef,ch:tf,status:"pending",text:"",boxes:[],tokens:null,rows:[],parts1:{}}),at(),ut()}function Ke(Ee){Ee.preventDefault();const{x:ge,y:_e}=Pe(Ee);ae.value==="draw"?(z.value=!0,G.value=ge,Q.value=_e,K.value=ge,ee.value=_e,window.addEventListener("mousemove",rt),window.addEventListener("mouseup",De)):ae.value==="pan"&&(fe.value=!0,ne.value=Ee.clientX+I.value.scrollLeft,pe.value=Ee.clientY+I.value.scrollTop,M.value.style.cursor="grabbing",window.addEventListener("mousemove",We),window.addEventListener("mouseup",Ze))}function tt(Ee){}function Vt(Ee){}function qt(){}function at(){z.value=!1,G.value=0,Q.value=0,K.value=0,ee.value=0}function ut(){const Ee=M.value;if(!Ee)return;const ge=Ee.getContext("2d");ge.clearRect(0,0,Ee.width,Ee.height);const _e=Ee.width,Oe=Ee.height;for(const Fe of _.value){if(Fe.page!==h.value)continue;const xt=Fe.xr*_e,Ft=Fe.yr*Oe,bn=Fe.wr*_e,Sn=Fe.hr*Oe,Et=a(Fe.type),js=Fe.id===w.value;ge.strokeStyle=Et,ge.lineWidth=js?3:2,ge.setLineDash(Fe.status==="pending"?[5,3]:[]),ge.strokeRect(xt,Ft,bn,Sn),ge.fillStyle=Et+"18",ge.fillRect(xt,Ft,bn,Sn);const zn=`${Fe.type} ${o(Fe.type)}`;ge.font="bold 12px sans-serif";const Hl=ge.measureText(zn).width+10;ge.fillStyle=Et,ge.fillRect(xt,Ft-18,Hl,18),ge.fillStyle="#fff",ge.fillText(zn,xt+5,Ft-4)}if(z.value){const Fe=Math.min(G.value,K.value),xt=Math.min(Q.value,ee.value),Ft=Math.abs(K.value-G.value),bn=Math.abs(ee.value-Q.value),Sn=a(b.value);ge.strokeStyle=Sn,ge.lineWidth=2,ge.setLineDash([4,3]),ge.strokeRect(Fe,xt,Ft,bn),ge.fillStyle=Sn+"15",ge.fillRect(Fe,xt,Ft,bn)}}function Tt(Ee){w.value=Ee.id,Ee.page!==h.value?Ne(Ee.page):ut()}function xe(Ee){_.value=_.value.filter(ge=>ge.id!==Ee),w.value===Ee&&(w.value=null),ut()}function qe(){_.value=[],w.value=null,ut()}async function ye(){var Oe;const Ee=_.value.find(Fe=>Fe.type==="A");if(!Ee)return;_.value.filter(Fe=>Fe.type==="A"&&Fe.status==="pending").forEach(Fe=>{Fe.status="recognizing"}),k.value=!0,T.value=d.value,R.value=0;const ge=Math.max(800,Math.round(3500*Math.ceil(d.value/10)/d.value)),_e=setInterval(()=>{R.value({}));throw new Error(Sn.detail||`HTTP ${Fe.status}`)}const xt=await Fe.json();R.value=T.value;const Ft=(Oe=xt.usage)!=null&&Oe.total_tokens?Math.round(xt.usage.total_tokens/(xt.total_pages||1)):null;for(const Sn of xt.results){let Et=_.value.find(zn=>zn.type==="A"&&zn.page===Sn.page_index);Et||(Et={id:crypto.randomUUID(),type:"A",page:Sn.page_index,xr:Ee.xr,yr:Ee.yr,wr:Ee.wr,hr:Ee.hr,cx:Ee.cx,cy:Ee.cy,cw:Ee.cw,ch:Ee.ch,status:"pending",text:"",boxes:[],tokens:null,rows:[]},_.value.push(Et));const js=Sn.rows||[];Et.rows=js,Et.tokens=Ft,Et.text=js.length?js.map(zn=>[zn.seq_no??"",zn.category??"",zn.description??"",zn.nominal_dia_mm??"",zn.qty??""].filter(eu=>eu!=="").join(" | ")).join(` `):"(该页无材料明细行)",Et.status=Sn._validation_failed?"error":"done"}const bn=xt.results.filter(Sn=>Sn._validation_failed).length;bn>0?Ys.warning(`VL 识别完成,${xt.total_pages} 页中 ${bn} 页校验未通过(内容可能为空)`):Ys.success(`VL 识别完成,共 ${xt.total_pages} 页`)}catch(Fe){clearInterval(_e),_.value.filter(xt=>xt.type==="A").forEach(xt=>{xt.status==="recognizing"&&(xt.status="error")}),Ys.error(`VL 识别失败:${Fe.message}`)}finally{k.value=!1}}function Ye(Ee){return!Ee||typeof Ee!="object"?"":Object.entries({pipeline_id:"管段号",operation_pressure_mpa:"操作压力(MPa)",operation_temp_c:"操作温度(℃)",design_pressure_mpa:"设计压力(MPa)",design_temp_c:"设计温度(℃)",test_pressure_mpa:"试验压力(MPa)",hydraulic_test_pressure:"水压/气密",pipe_diameter_dn:"管径DN",pipe_spec_grade:"管道等级",heat_insulation:"隔热要求",insulation_thickness_mm:"保温厚度(mm)",post_weld_heat_treatment:"焊后热处理",radiographic_examination:"射线探伤"}).map(([_e,Oe])=>{const Fe=Ee[_e];return Fe!=null&&Fe!==""?`${Oe}: ${Fe}`:null}).filter(Boolean).join(` `)}async function Ct(){var ge;const Ee=_.value.find(_e=>_e.type==="B");if(Ee){_.value.filter(_e=>_e.type==="B"&&_e.status==="pending").forEach(_e=>{_e.status="recognizing"});try{const _e=await fetch(`${n}/api/manual/ocr-all-pages-vl-b`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({session_id:u.value,x_ratio:Ee.xr,y_ratio:Ee.yr,w_ratio:Ee.wr,h_ratio:Ee.hr,concurrency:5})});if(!_e.ok){const xt=await _e.json().catch(()=>({}));throw new Error(xt.detail||`HTTP ${_e.status}`)}const Oe=await _e.json(),Fe=(ge=Oe.usage)!=null&&ge.total_tokens?Math.round(Oe.usage.total_tokens/(Oe.total_pages||1)):null;for(const xt of Oe.results){let Ft=_.value.find(zn=>zn.type==="B"&&zn.page===xt.page_index);Ft||(Ft={id:crypto.randomUUID(),type:"B",page:xt.page_index,xr:Ee.xr,yr:Ee.yr,wr:Ee.wr,hr:Ee.hr,cx:Ee.cx,cy:Ee.cy,cw:Ee.cw,ch:Ee.ch,status:"pending",text:"",boxes:[],tokens:null,parts1:{}},_.value.push(Ft));const{page_index:bn,parse_error:Sn,error:Et,...js}=xt;Ft.parts1=Sn||Et?{}:js,Ft.text=Ye(Ft.parts1),Ft.tokens=Fe,Ft.status=Sn||!Ft.text?"error":"done"}}catch(_e){_.value.filter(Oe=>Oe.type==="B"&&Oe.status==="recognizing").forEach(Oe=>{Oe.status="error"}),Ys.error(`管线号 VL 识别失败:${_e.message}`)}}}function Zt(){var Ee,ge,_e,Oe,Fe;for(const xt of _.value.filter(Ft=>Ft.type==="B"&&Ft.status==="done")){const Ft=((ge=(Ee=xt.parts1)==null?void 0:Ee.pipeline_id)==null?void 0:ge.trim())||((Oe=(_e=xt.text)==null?void 0:_e.split(` `)[0])==null?void 0:Oe.replace(/^管段号[::]\s*/,"").trim())||"";if(!Ft)continue;const bn=_.value.find(Sn=>Sn.type==="A"&&Sn.page===xt.page);(Fe=bn==null?void 0:bn.rows)!=null&&Fe.length&&(bn.rows=bn.rows.map(Sn=>({...Sn,pipe_no:Ft})))}}async function Cn(){const Ee=_.value.find(ge=>ge.type==="C");if(Ee){_.value.filter(ge=>ge.type==="C"&&ge.status==="pending").forEach(ge=>{ge.status="recognizing"});try{const ge=await fetch(`${n}/api/manual/ocr-all-pages-vl-c`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({session_id:u.value,x_ratio:Ee.xr,y_ratio:Ee.yr,w_ratio:Ee.wr,h_ratio:Ee.hr,concurrency:5})});if(!ge.ok){const Oe=await ge.json().catch(()=>({}));throw new Error(Oe.detail||`HTTP ${ge.status}`)}const _e=await ge.json();for(const Oe of _e.results){let Fe=_.value.find(xt=>xt.type==="C"&&xt.page===Oe.page_index);Fe||(Fe={id:crypto.randomUUID(),type:"C",page:Oe.page_index,xr:Ee.xr,yr:Ee.yr,wr:Ee.wr,hr:Ee.hr,cx:Ee.cx,cy:Ee.cy,cw:Ee.cw,ch:Ee.ch,status:"pending",text:"",boxes:[],tokens:null},_.value.push(Fe)),Fe.text=Oe.text||"",Fe.status=Oe.parse_error?"error":"done"}}catch(ge){_.value.filter(_e=>_e.type==="C"&&_e.status==="recognizing").forEach(_e=>{_e.status="error"}),Ys.error(`C 区域 VL 识别失败:${ge.message}`)}}}async function kn(){if(!_.value.filter(xt=>xt.status==="pending").length)return;const ge=Z.value>0,_e=_.value.some(xt=>xt.type==="B"),Oe=_.value.some(xt=>xt.type==="C"),Fe=[];ge&&Fe.push(ye()),_e&&Fe.push(Ct()),Oe&&Fe.push(Cn()),Fe.length&&await Promise.all(Fe),ge&&_e&&Zt(),Ys.success("全部识别完成"),await ze(),await Be()}async function Be(){const Ee=H.value;if(Ee.length)try{const ge=await fetch(`${n}/api/manual/export`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({regions:Ee.map(Fe=>({id:Fe.id,region_type:Fe.type,page_index:Fe.page,text:Fe.text,boxes:Fe.boxes||[],rows:Fe.rows||[],parts1:Fe.parts1||{}})),format:"json"})});if(!ge.ok)return;const _e=await ge.text(),Oe=document.getElementById("resultdata");Oe&&(Oe.value=_e)}catch{}}async function nt(Ee){const ge=H.value;if(ge.length){x.value=Ee;try{const _e=await fetch(`${n}/api/manual/export`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({regions:ge.map(Ft=>({id:Ft.id,region_type:Ft.type,page_index:Ft.page,text:Ft.text,boxes:Ft.boxes||[],rows:Ft.rows||[],parts1:Ft.parts1||{}})),format:Ee})});if(!_e.ok){const Ft=await _e.json().catch(()=>({}));throw new Error(Ft.detail||`HTTP ${_e.status}`)}const Oe=await _e.blob(),Fe=URL.createObjectURL(Oe),xt=document.createElement("a");xt.href=Fe,xt.download=Ee==="excel"?"manual_ocr_result.xlsx":"manual_ocr_result.json",xt.click(),URL.revokeObjectURL(Fe),Ys.success("导出成功")}catch(_e){Ys.error(`导出失败:${_e.message}`)}finally{x.value=""}}}async function vt(Ee){try{await navigator.clipboard.writeText(Ee),Ys.success("已复制")}catch{Ys.warning("请手动复制")}}return uu(()=>{be&&clearInterval(be),we&&we.disconnect(),window.removeEventListener("mousemove",rt),window.removeEventListener("mouseup",De),window.removeEventListener("mousemove",We),window.removeEventListener("mouseup",Ze),u.value&&fetch(`${n}/api/manual/session/${u.value}`,{method:"DELETE"}).catch(()=>{})}),(Ee,ge)=>{const _e=Ge("el-icon"),Oe=Ge("el-upload"),Fe=Ge("el-tab-pane"),xt=Ge("el-input"),Ft=Ge("el-tabs"),bn=Ge("el-tag"),Sn=Ge("el-progress");return S(),P("div",H4e,[A("div",W4e,[A("div",{class:D(["engine-badge","es-"+L.value])},[ge[17]||(ge[17]=A("span",{class:"es-dot"},null,-1)),A("span",j4e,[ge[16]||(ge[16]=Ue(" OCR  ",-1)),L.value==="loading"?(S(),P(He,{key:0},[Ue("引擎加载中…")],64)):L.value==="ready"?(S(),P(He,{key:1},[Ue("引擎就绪")],64)):(S(),P(He,{key:2},[Ue("引擎异常")],64))])],2),A("div",K4e,[A("div",U4e,[j(_e,null,{default:X(()=>[j(f(Sg))]),_:1}),ge[18]||(ge[18]=Ue(" 加载 PDF ",-1))]),j(Ft,{modelValue:r.value,"onUpdate:modelValue":ge[2]||(ge[2]=Et=>r.value=Et),class:"src-tabs",size:"small"},{default:X(()=>[j(Fe,{label:"本地文件",name:"file"},{default:X(()=>[j(Oe,{ref_key:"uploadRef",ref:O,"auto-upload":!1,accept:".pdf","show-file-list":!1,"on-change":Ce},{default:X(()=>[A("div",{class:D(["el-button el-button--small el-button--plain",{"is-loading":c.value&&r.value==="file"}]),style:{width:"100%",cursor:"pointer"}},[c.value&&r.value==="file"?(S(),le(_e,{key:0,class:"is-loading"},{default:X(()=>[j(f(Ns))]),_:1})):(S(),le(_e,{key:1},{default:X(()=>[j(f(d9))]),_:1})),Ue(" "+ve(i.value?i.value.name:"选择 PDF(自动加载)…"),1)],2)]),_:1},512)]),_:1}),j(Fe,{label:"网络 URL",name:"url"},{default:X(()=>[j(xt,{modelValue:l.value,"onUpdate:modelValue":ge[0]||(ge[0]=Et=>l.value=Et),placeholder:"https://…/file.pdf",clearable:"",size:"small"},null,8,["modelValue"]),A("div",{class:D(["el-button el-button--primary el-button--small",{"is-loading":c.value,"is-disabled":!he.value}]),style:{width:"100%","margin-top":"6px",cursor:"pointer"},onClick:ge[1]||(ge[1]=Et=>!c.value&&he.value&&Se())},[c.value?(S(),le(_e,{key:0,class:"is-loading"},{default:X(()=>[j(f(Ns))]),_:1})):(S(),le(_e,{key:1},{default:X(()=>[j(f(Wy))]),_:1})),ge[19]||(ge[19]=Ue(" 加载 / 渲染 ",-1))],2)]),_:1})]),_:1},8,["modelValue"])]),p.value?(S(),P("div",q4e,[A("div",G4e,[j(_e,null,{default:X(()=>[j(f(_g))]),_:1}),ge[20]||(ge[20]=Ue(" 当前区域类型 ",-1)),ge[21]||(ge[21]=A("span",{class:"sb-hint"},"拖拽在右侧图像上框选",-1))]),A("div",Y4e,[(S(),P(He,null,yt(s,Et=>A("div",{key:Et.key,class:D(["rt-btn",{active:b.value===Et.key}]),style:et({"--rt-color":Et.color}),onClick:js=>b.value=Et.key},[A("span",J4e,ve(Et.key),1),Ue(" "+ve(Et.label),1)],14,X4e)),64))])])):ie("",!0),_.value.length?(S(),P("div",Z4e,[A("div",Q4e,[j(_e,null,{default:X(()=>[j(f(Zx))]),_:1}),Ue(" 已标注区域 ("+ve(_.value.length)+") ",1),A("div",{class:"el-button el-button--link el-button--danger el-button--small",style:{cursor:"pointer"},onClick:qe},"清空")]),A("div",eye,[(S(!0),P(He,null,yt(_.value,Et=>(S(),P("div",{key:Et.id,class:D(["region-item",{active:w.value===Et.id}]),style:et({"--rt-color":a(Et.type)}),onClick:js=>Tt(Et)},[A("div",nye,[A("span",sye,ve(Et.type),1),A("span",aye,ve(o(Et.type)),1),A("span",oye,"P"+ve(Et.page+1),1),j(_e,{class:"ri-del",onClick:it(js=>xe(Et.id),["stop"])},{default:X(()=>[j(f(Ua))]),_:1},8,["onClick"])]),A("div",rye,[Et.status==="pending"?(S(),le(bn,{key:0,size:"small",type:"info"},{default:X(()=>[...ge[22]||(ge[22]=[Ue("待识别",-1)])]),_:1})):Et.status==="recognizing"?(S(),le(bn,{key:1,size:"small",type:"warning"},{default:X(()=>[...ge[23]||(ge[23]=[Ue("识别中…",-1)])]),_:1})):Et.status==="done"?(S(),P(He,{key:2},[j(bn,{size:"small",type:"success"},{default:X(()=>[...ge[24]||(ge[24]=[Ue("已完成",-1)])]),_:1}),Et.tokens?(S(),P("span",iye,ve(Et.tokens)+"tk",1)):ie("",!0)],64)):Et.status==="error"?(S(),le(bn,{key:3,size:"small",type:"danger"},{default:X(()=>[...ge[25]||(ge[25]=[Ue("失败",-1)])]),_:1})):ie("",!0)]),Et.text?(S(),P("pre",lye,ve(Et.text.slice(0,120))+ve(Et.text.length>120?"…":""),1)):ie("",!0)],14,tye))),128))])])):ie("",!0),p.value&&_.value.length?(S(),P("div",cye,[A("div",{class:D(["el-button el-button--primary el-button--small",{"is-loading":C.value||k.value,"is-disabled":ce.value===0||k.value}]),style:{width:"100%",cursor:"pointer"},onClick:ge[3]||(ge[3]=Et=>!(C.value||k.value)&&ce.value>0&&kn())},[C.value||k.value?(S(),le(_e,{key:0,class:"is-loading"},{default:X(()=>[j(f(Ns))]),_:1})):(S(),le(_e,{key:1},{default:X(()=>[j(f(Yx))]),_:1})),Ue(" 识别所有未处理区域 ("+ve(ce.value)+") ",1)],2),j(gs,{name:"vl-fade"},{default:X(()=>[k.value||R.value>0&&R.value===T.value?(S(),P("div",uye,[A("div",dye,[k.value?(S(),P("span",fye,[ge[26]||(ge[26]=A("span",{class:"vl-spin"},"⟳",-1)),Ue(" VL 识别中… "+ve(R.value)+" / "+ve(T.value)+" 页 ",1)])):(S(),P("span",hye,"✓ 完成 "+ve(T.value)+" 页",1))]),j(Sn,{percentage:de.value,striped:k.value,"striped-flow":k.value,duration:8,"stroke-width":6,"show-text":!1,status:k.value?"":"success",style:{"margin-top":"4px"}},null,8,["percentage","striped","striped-flow","status"])])):ie("",!0)]),_:1})])):ie("",!0),H.value.length?(S(),P("div",pye,[A("div",vye,[j(_e,null,{default:X(()=>[j(f(Ji))]),_:1}),ge[27]||(ge[27]=Ue(" 导出结果 ",-1))]),A("div",mye,[A("div",{class:D(["el-button el-button--small",{"is-loading":x.value==="excel"}]),style:{flex:"1",cursor:"pointer"},onClick:ge[4]||(ge[4]=Et=>nt("excel"))},[x.value==="excel"?(S(),le(_e,{key:0,class:"is-loading"},{default:X(()=>[j(f(Ns))]),_:1})):(S(),le(_e,{key:1},{default:X(()=>[j(f(Xx))]),_:1})),ge[28]||(ge[28]=Ue(" Excel ",-1))],2),A("div",{class:D(["el-button el-button--small",{"is-loading":x.value==="json"}]),style:{flex:"1",cursor:"pointer"},onClick:ge[5]||(ge[5]=Et=>nt("json"))},[x.value==="json"?(S(),le(_e,{key:0,class:"is-loading"},{default:X(()=>[j(f(Ns))]),_:1})):(S(),le(_e,{key:1},{default:X(()=>[j(f(Cg))]),_:1})),ge[29]||(ge[29]=Ue(" JSON ",-1))],2)])])):ie("",!0),A("div",gye,[A("div",{class:"el-button el-button--plain el-button--small",style:{width:"100%",cursor:"pointer"},onClick:ge[6]||(ge[6]=Et=>f(t).push("/"))},[j(_e,null,{default:X(()=>[j(f(No))]),_:1}),ge[30]||(ge[30]=Ue(" 返回主页 ",-1))])])]),A("div",bye,[p.value?(S(),P("div",yye,[A("div",wye,[A("div",{class:D(["el-button el-button--small",{"is-disabled":h.value===0}]),style:{cursor:"pointer"},onClick:ge[7]||(ge[7]=Et=>h.value!==0&&Ne(h.value-1))},[j(_e,null,{default:X(()=>[j(f(No))]),_:1})],2),A("div",{class:D(["el-button el-button--small",{"is-disabled":h.value===d.value-1}]),style:{cursor:"pointer"},onClick:ge[8]||(ge[8]=Et=>h.value!==d.value-1&&Ne(h.value+1))},[j(_e,null,{default:X(()=>[j(f(Ls))]),_:1})],2)]),A("span",_ye,"第 "+ve(h.value+1)+" / "+ve(d.value)+" 页",1),A("div",Cye,[A("span",{class:"nt-dot",style:et({background:a(b.value)})},null,4),Ue(" "+ve(b.value)+" — "+ve(o(b.value)),1)]),A("div",Sye,[A("div",{class:D(["el-button el-button--small",{"el-button--primary":ae.value==="draw"}]),style:{cursor:"pointer"},onClick:ge[9]||(ge[9]=Et=>ae.value="draw")},[j(_e,null,{default:X(()=>[j(f(_g))]),_:1}),ge[31]||(ge[31]=Ue(" 框选 ",-1))],2),A("div",{class:D(["el-button el-button--small",{"el-button--primary":ae.value==="pan"}]),style:{cursor:"pointer"},onClick:ge[10]||(ge[10]=Et=>ae.value="pan")},[j(_e,null,{default:X(()=>[j(f(a9))]),_:1}),ge[32]||(ge[32]=Ue(" 拖动 ",-1))],2)]),A("div",xye,[A("div",{class:D(["el-button el-button--small el-button--plain",{"is-disabled":U.value<=.25}]),style:{cursor:"pointer"},onClick:ge[11]||(ge[11]=Et=>U.value>.25&&Y())},[j(_e,null,{default:X(()=>[j(f(jy))]),_:1})],2),A("span",kye,ve(Math.round(U.value*100))+"%",1),A("div",{class:D(["el-button el-button--small el-button--plain",{"is-disabled":U.value>=3}]),style:{cursor:"pointer"},onClick:ge[12]||(ge[12]=Et=>U.value<3&&J())},[j(_e,null,{default:X(()=>[j(f(kg))]),_:1})],2),A("div",{class:"el-button el-button--small el-button--plain",title:"适应宽度",style:{cursor:"pointer"},onClick:ge[13]||(ge[13]=Et=>N())},[j(_e,null,{default:X(()=>[j(f(By))]),_:1})])])])):ie("",!0),p.value?ie("",!0):(S(),P("div",Eye,[j(_e,{size:"64",style:{color:"#d1d5db"}},{default:X(()=>[j(f(Cg))]),_:1}),ge[33]||(ge[33]=A("p",null,"请在左侧加载 PDF 文件",-1))])),gt(A("div",{class:"img-wrap",ref_key:"wrapRef",ref:I},[A("div",Aye,[A("canvas",{ref_key:"pdfCanvasRef",ref:$,class:"pdf-canvas"},null,512),m.value?(S(),P("div",Tye,[j(_e,{class:"spin"},{default:X(()=>[j(f(Ns))]),_:1}),ge[34]||(ge[34]=Ue(" 渲染页面中… ",-1))])):ie("",!0),A("canvas",{ref_key:"canvasRef",ref:M,class:"overlay-canvas","data-mode":ae.value,onMousedown:Ke,onMousemove:tt,onMouseup:Vt,onMouseleave:qt},null,40,Mye)])],512),[[zt,p.value]]),j(gs,{name:"fade"},{default:X(()=>[te.value&&te.value.text?(S(),P("div",Pye,[A("div",Rye,[A("span",{class:"rp-badge",style:et({background:a(te.value.type)})},ve(te.value.type),5),A("span",Iye,ve(o(te.value.type))+" — 第 "+ve(te.value.page+1)+" 页",1),te.value.tokens?(S(),P("span",Oye,ve(te.value.tokens)+" tokens",1)):ie("",!0),A("div",{class:"el-button el-button--link el-button--small",style:{cursor:"pointer"},onClick:ge[14]||(ge[14]=Et=>vt(te.value.text))},"复制"),A("div",{class:"el-button el-button--link el-button--small",style:{cursor:"pointer"},onClick:ge[15]||(ge[15]=Et=>w.value=null)},"×")]),A("pre",Lye,ve(te.value.text),1)])):ie("",!0)]),_:1})])])}}},[["__scopeId","data-v-37c37641"]])}],$ye=Mge({history:lge(),routes:Nye}),pb=JS(S2e);pb.use(L8),pb.use($ye);for(const[e,t]of Object.entries(aJ))pb.component(e,t);pb.mount("#app")})();