@k2b/ui 0.57.1 → 0.58.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/browser/actions/Dropdown.js +4 -3
  2. package/dist/browser/actions/Dropdown.js.map +1 -1
  3. package/dist/browser/actions/menu-rows.js +1 -1
  4. package/dist/browser/actions/menu-rows.js.map +1 -1
  5. package/dist/browser/content/PdfPages.js +159 -44
  6. package/dist/browser/content/PdfPages.js.map +1 -1
  7. package/dist/browser/content/PdfViewer.js +59 -21
  8. package/dist/browser/content/PdfViewer.js.map +1 -1
  9. package/dist/browser/content/pdf-viewer-engine.js +1 -1
  10. package/dist/browser/layout/FloatingWindow.js +122 -75
  11. package/dist/browser/layout/FloatingWindow.js.map +1 -1
  12. package/dist/browser/layout/Panes.js +640 -212
  13. package/dist/browser/layout/Panes.js.map +1 -1
  14. package/dist/browser/layout/index.js +1 -1
  15. package/dist/browser/layout/index.js.map +1 -1
  16. package/dist/browser/layout/panes-layout.js +169 -0
  17. package/dist/browser/layout/panes-layout.js.map +1 -1
  18. package/dist/browser/layout/panes-messages.js +108 -2
  19. package/dist/browser/layout/panes-messages.js.map +1 -1
  20. package/dist/ssr/actions/Dropdown.js +4 -4
  21. package/dist/ssr/actions/Dropdown.js.map +1 -1
  22. package/dist/ssr/actions/menu-rows.js +1 -1
  23. package/dist/ssr/actions/menu-rows.js.map +1 -1
  24. package/dist/ssr/content/PdfPages.js +159 -44
  25. package/dist/ssr/content/PdfPages.js.map +1 -1
  26. package/dist/ssr/content/PdfViewer.js +40 -8
  27. package/dist/ssr/content/PdfViewer.js.map +1 -1
  28. package/dist/ssr/layout/FloatingWindow.js +37 -15
  29. package/dist/ssr/layout/FloatingWindow.js.map +1 -1
  30. package/dist/ssr/layout/Panes.js +396 -41
  31. package/dist/ssr/layout/Panes.js.map +1 -1
  32. package/dist/ssr/layout/index.js +1 -1
  33. package/dist/ssr/layout/index.js.map +1 -1
  34. package/dist/ssr/layout/panes-layout.js +169 -0
  35. package/dist/ssr/layout/panes-layout.js.map +1 -1
  36. package/dist/ssr/layout/panes-messages.js +108 -2
  37. package/dist/ssr/layout/panes-messages.js.map +1 -1
  38. package/dist/styles.css +1 -1
  39. package/dist/types/actions/Dropdown.d.ts +4 -3
  40. package/dist/types/content/PdfPages.d.ts +8 -3
  41. package/dist/types/content/PdfViewer.d.ts +12 -4
  42. package/dist/types/layout/FloatingWindow.d.ts +6 -0
  43. package/dist/types/layout/Panes.d.ts +15 -0
  44. package/dist/types/layout/index.d.ts +2 -2
  45. package/dist/types/layout/panes-layout.d.ts +51 -0
  46. package/dist/types/layout/panes-messages.d.ts +55 -0
  47. package/package.json +1 -1
@@ -54,4 +54,4 @@ fn fs_main(in : VertexOutput) -> @location(0) vec4<f32> {
54
54
  `)}`,this.#c();let h=new Range,d=Math.sumPrecise(l.map((u)=>u.length));for(let{firstChild:u}of this.editorDiv.childNodes)if(u.nodeType===Node.TEXT_NODE){let f=u.nodeValue.length;if(d<=f){h.setStart(u,d),h.setEnd(u,d);break}d-=f}r.removeAllRanges(),r.addRange(h)}#c(){if(this.editorDiv.replaceChildren(),!this.#t)return;for(let t of this.#t.split(`
55
55
  `)){let e=document.createElement("div");e.append(t?document.createTextNode(t):document.createElement("br")),this.editorDiv.append(e)}}#u(){return this.#t.replaceAll(" "," ")}static#h(t){return t.replaceAll(" "," ")}get contentDiv(){return this.editorDiv}getPDFRect(){let t=Pt._internalPadding*this.parentScale;return this.getRect(t,t)}static async deserialize(t,e,s){let i=null;if(t instanceof Lr){let{data:{defaultAppearanceData:{fontSize:n,fontColor:a},rect:o,rotation:l,id:c,popupRef:h,richText:d,contentsObj:u,creationDate:f,modificationDate:p},textContent:g,textPosition:m,parent:{page:{pageNumber:v}}}=t;if(!g?.length)return null;i=t={annotationType:K.FREETEXT,color:Array.from(a),fontSize:n,value:g.join(`
56
56
  `),position:m,pageIndex:v-1,rect:o.slice(0),rotation:l,annotationElementId:c,id:c,deleted:!1,popupRef:h,comment:u?.str||null,richText:d,creationDate:f,modificationDate:p}}let r=await super.deserialize(t,e,s);if(r.#i=t.fontSize,r.color=O.makeHexColor(...t.color),r.#t=Pt.#h(t.value),r._initialData=i,t.comment)r.setCommentData(t);return r}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let e=U._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:this.color),s=Object.assign(super.serialize(t),{color:e,fontSize:this.#i,value:this.#u()});if(this.addComment(s),t)return s.isCopy=!0,s;if(this.annotationElementId&&!this.#f(s))return null;return s.id=this.annotationElementId,s}#f(t){let{value:e,fontSize:s,color:i,pageIndex:r}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||t.value!==e||t.fontSize!==s||t.color.some((n,a)=>n!==i[a])||t.pageIndex!==r}renderAnnotationElement(t){let e=super.renderAnnotationElement(t);if(!e)return null;let{style:s}=e;s.fontSize=`calc(${this.#i}px * var(--total-scale-factor))`,s.color=this.color,e.replaceChildren();for(let i of this.#t.split(`
57
- `)){let r=document.createElement("div");r.append(i?document.createTextNode(i):document.createElement("br")),e.append(r)}return t.updateEdited({rect:this.getPDFRect(),popup:this._uiManager.hasCommentManager()||this.hasEditedComment?this.comment:{text:this.#t}}),e}resetAnnotationElement(t){super.resetAnnotationElement(t),t.resetEdited()}}class Ni{#t=Object.create(null);updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(!t)return;for(let[e,s]of Object.entries(t))if(!e.startsWith("_"))this.updateProperty(e,s)}updateSVGProperty(t,e){this.#t[t]=e}toSVGProperties(){let t=this.#t;return this.#t=Object.create(null),{root:t}}reset(){this.#t=Object.create(null)}updateAll(t=this){this.updateProperties(t)}clone(){at("Not implemented")}}class et extends U{#t=null;#e;_clipPathId=null;_colorPicker=null;_drawId=null;_drawOutlines=null;_focusDrawId=null;static _currentDrawId=-1;static _currentParent=null;static#s=null;static#i=null;static#r=null;static#n=null;static _INNER_MARGIN=3;constructor(t){super(t);this.#e=t.mustBeCommitted||!1,this._addOutlines(t)}onUpdatedColor(){this._colorPicker?.update(this.color),super.onUpdatedColor()}onUpdatedOpacity(){this._colorPicker?.updateOpacity?.(this.opacity)}_addOutlines(t){if(t.drawOutlines)this.#a(t),this.#m()}#a({drawOutlines:t,drawId:e,drawingOptions:s,clipPathId:i}){if(this._drawOutlines=t,this._drawingOptions||=s,!this.annotationElementId)this._uiManager.a11yAlert(U._l10nAlert[this.editorType]);if(e>=0)this._drawId=e,this._clipPathId=i??null,this.parent.drawLayer.finalizeDraw(e,t.defaultProperties),this.#l(this.parent);else this._drawId=this.#o(t,this.parent);this.#v(t.box)}#o(t,e){let{id:s,clipPathId:i}=e.drawLayer.draw(et._mergeSVGProperties(this._drawingOptions.toSVGProperties(),t.defaultSVGProperties),!1,this.constructor._hasClipPath);if(this.constructor._hasClipPath)this._clipPathId=i;return this.#l(e),s}#l(t){let e=this._drawOutlines.getFocusSVGProperties(this.#f);if(e)this._focusDrawId=t.drawLayer.drawOutline(e,this._drawOutlines.focusMustRemoveSelfIntersections)}#c(t=this.#f){if(this._focusDrawId===null)return;this.parent?.drawLayer.updateProperties(this._focusDrawId,this._drawOutlines.getFocusSVGProperties(t))}#u(t){if(this._focusDrawId!==null)this.parent?.drawLayer.updateProperties(this._focusDrawId,{rootClass:t})}#h(){let{parent:t,_drawId:e,_focusDrawId:s,_isVisible:i}=this;if(!t||e===null)return;let r={hidden:!i};if(t.drawLayer.updateProperties(e,{rootClass:r}),s!==null)t.drawLayer.updateProperties(s,{rootClass:r})}static _mergeSVGProperties(t,e){let s=new Set(Object.keys(t));for(let[i,r]of Object.entries(e))if(s.has(i))Object.assign(t[i],r);else t[i]=r;return t}static getDefaultDrawingOptions(t){at("Not implemented")}static get typesMap(){at("Not implemented")}static get isDrawer(){return!0}static get _hasClipPath(){return!1}static get _hasDrawClass(){return!0}static get supportMultipleDrawings(){return!1}get _drawRotation(){return this.rotation}get _opacityName(){return this.constructor.typesMap.get(this.opacityType)}get#f(){return(this.parentRotation-this._drawRotation+360)%360}static updateDefaultParams(t,e){let s=this.typesMap.get(t);if(s)this._defaultDrawingOptions.updateProperty(s,e);if(this._currentParent)et.#s.updateProperty(s,e),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties())}updateParams(t,e){let s=this.constructor.typesMap.get(t);if(s)this._updateProperty(t,s,e)}static get defaultPropertiesToUpdate(){let t=[],e=this._defaultDrawingOptions;for(let[s,i]of this.typesMap)t.push([s,e[i]]);return t}get propertiesToUpdate(){let t=[],{_drawingOptions:e}=this;for(let[s,i]of this.constructor.typesMap)t.push([s,e[i]]);return t}_updateProperty(t,e,s){let i=this._drawingOptions,r=i[e],n=(a)=>{i.updateProperty(e,a);let o=this._drawOutlines.updateProperty(e,a);if(o)this.#v(o);if(this.parent?.drawLayer.updateProperties(this._drawId,i.toSVGProperties()),t===this.colorType)this.onUpdatedColor();else if(t===this.opacityType)this.onUpdatedOpacity()};this.addCommands({cmd:n.bind(this,s),undo:n.bind(this,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:t,overwriteIfSameType:!0,keepUndo:!0})}_updateColorAndOpacity(t,e,s=this.colorAndOpacityType){let i=this.constructor.typesMap.get(this.colorType),r=this._opacityName,n=this._drawingOptions,a=n[i],o=n[r],l=(c,h)=>{n.updateProperty(i,c),n.updateProperty(r,h),this._drawOutlines.updateProperty(i,c),this._drawOutlines.updateProperty(r,h),this.parent?.drawLayer.updateProperties(this._drawId,n.toSVGProperties()),this.onUpdatedColor(),this.onUpdatedOpacity()};this.addCommands({cmd:l.bind(this,t,e),undo:l.bind(this,a,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:s,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,et._mergeSVGProperties(this._drawOutlines.getPathResizingSVGProperties(this.#g()),{bbox:this.#y()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,et._mergeSVGProperties(this._drawOutlines.getPathResizedSVGProperties(this.#g()),{bbox:this.#y()})),this.#c()}_onTranslating(t,e){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#y()})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,et._mergeSVGProperties(this._drawOutlines.getPathTranslatedSVGProperties(this.#g(),this.parentDimensions),{bbox:this.#y()}))}_onStartDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}get _mustBeDisabledOnCommit(){return!0}commit(){if(super.commit(),this._mustBeDisabledOnCommit)this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(t){if(!this.annotationElementId&&this._drawId!==null)this.parent.addUndoableEditor(this);if(this._isDraggable=!0,this.#e){if(this.#e=!1,this.commit(),this.parent.setSelected(this),t&&this.isOnScreen)this.div.focus()}}remove(){this._uiManager.removeShouldRescale(this),this.#p(),super.remove()}rebuild(){if(!this.parent)return;if(super.rebuild(),this.div===null)return;if(this.#m(),this.#v(this._drawOutlines.box),!this.isAttachedToDOM)this.parent.add(this)}setParent(t){let e=!1;if(this.parent&&!t)this._uiManager.removeShouldRescale(this),this.#p();else if(t)this._uiManager.addShouldRescale(this),this.#m(t),e=!this.parent&&this.div?.classList.contains("selectedEditor");if(super.setParent(t),this.#h(),e)this.select()}#p(){if(this._drawId===null||!this.parent)return;let{drawLayer:t}=this.parent;if(t.remove(this._drawId),this._drawId=null,this._focusDrawId!==null)t.remove(this._focusDrawId),this._focusDrawId=null;this._drawingOptions.reset()}#m(t=this.parent){if(this._drawId!==null&&this.parent===t)return;if(this._drawId!==null){let{drawLayer:e}=this.parent;if(e.updateParent(this._drawId,t.drawLayer),this._focusDrawId!==null)e.updateParent(this._focusDrawId,t.drawLayer);return}if(this._drawingOptions.updateAll(),this._drawId=this.#o(this._drawOutlines,t),this._clipPathId&&this.#t)this.#t.style.clipPath=this._clipPathId}#d([t,e,s,i]){let{parentDimensions:[r,n],_drawRotation:a}=this;switch(a){case 90:return[e,1-t,s*(n/r),i*(r/n)];case 180:return[1-t,1-e,s,i];case 270:return[1-e,t,s*(n/r),i*(r/n)];default:return[t,e,s,i]}}#g(){let{x:t,y:e,width:s,height:i,parentDimensions:[r,n],_drawRotation:a}=this;switch(a){case 90:return[1-e,t,s*(r/n),i*(n/r)];case 180:return[1-t,1-e,s,i];case 270:return[e,1-t,s*(r/n),i*(n/r)];default:return[t,e,s,i]}}#v(t){if([this.x,this.y,this.width,this.height]=this.#d(t),this.div)this.fixAndSetPosition(),this.setDims();this._onResized()}#y(t=this.parentRotation){let{x:e,y:s,width:i,height:r,_drawRotation:n,parentDimensions:[a,o]}=this;switch((n*4+t)/90){case 1:return[1-s-r,e,r,i];case 2:return[1-e-i,1-s-r,i,r];case 3:return[s,1-e-i,r,i];case 4:return[e,s-i*(a/o),r*(o/a),i*(a/o)];case 5:return[1-s,e,i*(a/o),r*(o/a)];case 6:return[1-e-r*(o/a),1-s,r*(o/a),i*(a/o)];case 7:return[s-i*(a/o),1-e-r*(o/a),i*(a/o),r*(o/a)];case 8:return[e-i,s-r,i,r];case 9:return[1-s,e-i,r,i];case 10:return[1-e,1-s,i,r];case 11:return[s-r,1-e,r,i];case 12:return[e-r*(o/a),s,r*(o/a),i*(a/o)];case 13:return[1-s-i*(a/o),e-r*(o/a),i*(a/o),r*(o/a)];case 14:return[1-e,1-s-i*(a/o),r*(o/a),i*(a/o)];case 15:return[s,1-e,i*(a/o),r*(o/a)];default:return[e,s,i,r]}}rotate(t=this.parentRotation){if(!this.parent||this._drawId===null)return;let e=(t-this._drawRotation+360)%360;this.parent.drawLayer.updateProperties(this._drawId,et._mergeSVGProperties({bbox:this.#y(t)},this._drawOutlines.updateRotation(e))),this.#c(e)}show(t=this._isVisible){super.show(t),this.#h()}select(){super.select(),this.#u({hovered:!1,selected:!0})}unselect(){super.unselect(),this.#u({selected:!1})}pointerover(){if(!this.isSelected)this.#u({hovered:!0})}pointerleave(){if(!this.isSelected)this.#u({hovered:!1})}onScaleChanging(){if(!this.parent)return;let t=this._drawOutlines.updateParentDimensions(this.parentDimensions,this.parent.scale);if(t)this.#v(t)}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;let t,e;if(this._isCopy)t=this.x,e=this.y;let s=super.render();if(this.constructor._hasDrawClass)s.classList.add("draw");let i=this.#t=document.createElement("div");if(s.append(i),i.setAttribute("aria-hidden","true"),i.className="internal",this._clipPathId)i.style.clipPath=this._clipPathId;if(fa(this,i,["pointerover","pointerleave"]),this.setDims(),this._uiManager.addShouldRescale(this),this.disableEditing(),this._isCopy)this._moveAfterPaste(t,e);return s}static createDrawerInstance(t){at("Not implemented")}static _getDrawingTarget(t,{target:e}){return e}static _getPointerCoords({offsetX:t,offsetY:e,clientX:s,clientY:i},r=null){if(!r)return[t,e];let n=s-r.clientX,a=i-r.clientY;switch(this._currentParent.viewport.rotation){case 90:[n,a]=[a,-n];break;case 180:[n,a]=[-n,-a];break;case 270:[n,a]=[-a,n];break}return[r.offsetX+n,r.offsetY+a]}static _addDrawingListeners(t,e){}static _endDrawingSession(t=!1){return this._currentParent.endDrawingSession(t)}static startDrawing(t,e,s,i){let{pointerId:r,pointerType:n}=i;if(ot.isInitializedAndDifferentPointerType(n))return;let a=this._getDrawingTarget(t,i),[o,l]=this._getPointerCoords(i),{viewport:{rotation:c}}=t,{x:h,y:d,width:u,height:f}=a.getBoundingClientRect(),p=et.#i=new AbortController,g=t.combinedSignal(p);if(ot.setPointer(n,r),window.addEventListener("pointerup",(y)=>{if(ot.isSamePointerIdOrRemove(y.pointerId))this._endDraw(y)},{signal:g}),window.addEventListener("pointercancel",(y)=>{if(ot.isSamePointerIdOrRemove(y.pointerId))this._endDrawingSession()},{signal:g}),window.addEventListener("pointerdown",(y)=>{if(!ot.isSamePointerType(y.pointerType))return;if(ot.initializeAndAddPointerId(y.pointerId),et.#s.isCancellable())if(et.#s.removeLastElement(),et.#s.isEmpty())this._endDrawingSession(!0);else this._endDraw(null)},{capture:!0,passive:!1,signal:g}),window.addEventListener("contextmenu",re,{signal:g}),a.addEventListener("pointermove",this._drawMove.bind(this),{signal:g}),a.addEventListener("touchmove",(y)=>{if(ot.isSameTimeStamp(y.timeStamp))Tt(y)},{signal:g}),this._addDrawingListeners(a,g),t.toggleDrawing(),e._editorUndoBar?.hide(),et.#s){t.drawLayer.updateProperties(this._currentDrawId,et.#s.startNew(o,l,u,f,c,i.timeStamp));return}e.updateUIForDefaultProperties(this),et.#s=this.createDrawerInstance({x:o,y:l,box:[h,d,u,f],rotation:c,parent:t,isLTR:s,timeStamp:i.timeStamp}),et.#r=this.getDefaultDrawingOptions(),this._currentParent=t;let{id:m,clipPathId:v}=t.drawLayer.draw(this._mergeSVGProperties(et.#r.toSVGProperties(),et.#s.defaultSVGProperties),!0,this._hasClipPath);this._currentDrawId=m,et.#n=this._hasClipPath?v:null}static _drawMove(t){if(ot.isSameTimeStamp(t.timeStamp),!et.#s||!ot.isSamePointerId(t.pointerId))return;if(ot.isUsingMultiplePointers()){this._endDraw(t);return}let e,s=t.getCoalescedEvents?.();if(s?.length){let i=[],r=[];for(let n of s)i.push(...this._getPointerCoords(n,t)),r.push(n.timeStamp);e=et.#s.addPoints(i,r)}else e=et.#s.add(...this._getPointerCoords(t),t.timeStamp);this._currentParent.drawLayer.updateProperties(this._currentDrawId,e),ot.setTimeStamp(t.timeStamp),Tt(t)}static _cleanup(t){if(t)this._currentDrawId=-1,this._currentParent=null,et.#s=null,et.#r=null,et.#n=null,ot.clearTimeStamp();if(et.#i)et.#i.abort(),et.#i=null,ot.clearPointerIds()}static _endDraw(t){let e=this._currentParent;if(!e)return;if(e.toggleDrawing(!0),this._cleanup(!1),e.drawLayer.updateProperties(this._currentDrawId,t?.target===e.div?et.#s.end(...this._getPointerCoords(t),t.timeStamp):et.#s.end()),this.supportMultipleDrawings){let s=et.#s,i=this._currentDrawId,r=s.getLastElement();e.addCommands({cmd:()=>{e.drawLayer.updateProperties(i,s.setLastElement(r))},undo:()=>{e.drawLayer.updateProperties(i,s.removeLastElement())},mustExec:!1,type:st.DRAW_STEP});return}this.endDrawing(!1)}static endDrawing(t){let e=this._currentParent;if(!e)return null;if(e.toggleDrawing(!0),e.cleanUndoStack(st.DRAW_STEP),!et.#s.isEmpty()){let{pageDimensions:[s,i],scale:r}=e,n=e.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,clipPathId:et.#n,drawOutlines:et.#s.getOutlines(s*r,i*r,r,this._INNER_MARGIN),drawingOptions:et.#r,mustBeCommitted:!t});return this._cleanup(!0),n}return e.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(t){}static deserializeDraw(t,e,s,i,r,n,a){at("Not implemented")}static async deserialize(t,e,s){let{rawDims:{pageWidth:i,pageHeight:r,pageX:n,pageY:a}}=e.viewport,o=this.deserializeDraw(n,a,i,r,this._INNER_MARGIN,t,s),l=await super.deserialize(t,e,s);return l.createDrawingOptions(t),l.#a({drawOutlines:o}),l.#m(),l.onScaleChanging(),l.rotate(),l}serializeDraw(t){let[e,s]=this.pageTranslation,[i,r]=this.pageDimensions;return this._drawOutlines.serialize([e,s,i,r],t)}renderAnnotationElement(t){return t.updateEdited({rect:this.getPDFRect()}),null}static canCreateNewEmptyEditor(){return!1}}class H{static PRECISION=0.0001;focusOutline=null;toSVGPath(){at("Abstract method `toSVGPath` must be implemented.")}get box(){at("Abstract getter `box` must be implemented.")}serialize(t,e){at("Abstract method `serialize` must be implemented.")}get defaultSVGProperties(){at("Abstract getter `defaultSVGProperties` must be implemented.")}get defaultProperties(){return this.defaultSVGProperties}getFocusSVGProperties(t){return null}get focusMustRemoveSelfIntersections(){return!1}updateProperty(t,e){return null}updateParentDimensions(t,e){return null}serializeQuadPoints(t,e){return null}updateRotation(t){return{}}getPathResizingSVGProperties(t){return{}}getPathResizedSVGProperties(t){return{}}getPathTranslatedSVGProperties(t,e){return{}}static _rotateBox([t,e,s,i],r){switch(r){case 90:return[1-e-i,t,i,s];case 180:return[1-t-s,1-e-i,s,i];case 270:return[e,1-t-s,i,s]}return[t,e,s,i]}static _rescale(t,e,s,i,r,n){n||=new Float32Array(t.length);for(let a=0,o=t.length;a<o;a+=2)n[a]=e+t[a]*i,n[a+1]=s+t[a+1]*r;return n}static _rescaleAndSwap(t,e,s,i,r,n){n||=new Float32Array(t.length);for(let a=0,o=t.length;a<o;a+=2)n[a]=e+t[a+1]*i,n[a+1]=s+t[a]*r;return n}static _translate(t,e,s,i){i||=new Float32Array(t.length);for(let r=0,n=t.length;r<n;r+=2)i[r]=e+t[r],i[r+1]=s+t[r+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,s,i,r,n=[]){switch(r){case 90:n[0]=1-e/s,n[1]=t/i;break;case 180:n[0]=1-t/s,n[1]=1-e/i;break;case 270:n[0]=e/s,n[1]=1-t/i;break;default:n[0]=t/s,n[1]=e/i;break}return n}static createBezierPoints(t,e,s,i,r,n,a=[]){return a.push((t+5*s)/6,(e+5*i)/6,(5*s+r)/6,(5*i+n)/6,(s+r)/2,(i+n)/2),a}}class De{#t;#e=[];#s;#i;#r=[];#n=new Float32Array(18);#a;#o;#l;#c;#u;#h;#f=[];static#p=8;static#m=2;static#d=De.#p+De.#m;constructor(t,e,s,i,r,n,a=0){this.#t=s,this.#h=r*i,this.#i=n,this.#n.set([NaN,NaN,NaN,NaN,t,e],6),this.#s=a,this.#c=De.#p*i,this.#l=De.#d*i,this.#u=i,this.#f.push(t,e)}isEmpty(){return isNaN(this.#n[8])}isCancellable(){return this.#f.length<=10}removeLastElement(){return this.#n.fill(NaN),this.#r.length=this.#e.length=this.#f.length=0,{path:{d:""}}}#g(){let t=this.#n.subarray(4,6),e=this.#n.subarray(16,18),[s,i,r,n]=this.#t;return[(this.#a+(t[0]-e[0])/2-s)/r,(this.#o+(t[1]-e[1])/2-i)/n,(this.#a+(e[0]-t[0])/2-s)/r,(this.#o+(e[1]-t[1])/2-i)/n]}add(t,e){this.#a=t,this.#o=e;let[s,i,r,n]=this.#t,[a,o,l,c]=this.#n.subarray(8,12),h=t-l,d=e-c,u=Math.hypot(h,d);if(u<this.#l)return!1;let f=u-this.#c,p=f/u,g=p*h,m=p*d,v=a,y=o;a=l,o=c,l+=g,c+=m,this.#f?.push(t,e);let b=-m/f,_=g/f,w=b*this.#h,A=_*this.#h;if(this.#n.set(this.#n.subarray(2,8),0),this.#n.set([l+w,c+A],4),this.#n.set(this.#n.subarray(14,18),12),this.#n.set([l-w,c-A],16),isNaN(this.#n[6])){if(this.#r.length===0)this.#n.set([a+w,o+A],2),this.#r.push(NaN,NaN,NaN,NaN,(a+w-s)/r,(o+A-i)/n),this.#n.set([a-w,o-A],14),this.#e.push(NaN,NaN,NaN,NaN,(a-w-s)/r,(o-A-i)/n);return this.#n.set([v,y,a,o,l,c],6),!this.isEmpty()}if(this.#n.set([v,y,a,o,l,c],6),Math.abs(Math.atan2(y-o,v-a)-Math.atan2(m,g))<Math.PI/2)return[a,o,l,c]=this.#n.subarray(2,6),this.#r.push(NaN,NaN,NaN,NaN,((a+l)/2-s)/r,((o+c)/2-i)/n),[a,o,v,y]=this.#n.subarray(14,18),this.#e.push(NaN,NaN,NaN,NaN,((v+a)/2-s)/r,((y+o)/2-i)/n),!0;return[v,y,a,o,l,c]=this.#n.subarray(0,6),this.#r.push(((v+5*a)/6-s)/r,((y+5*o)/6-i)/n,((5*a+l)/6-s)/r,((5*o+c)/6-i)/n,((a+l)/2-s)/r,((o+c)/2-i)/n),[l,c,a,o,v,y]=this.#n.subarray(12,18),this.#e.push(((v+5*a)/6-s)/r,((y+5*o)/6-i)/n,((5*a+l)/6-s)/r,((5*o+c)/6-i)/n,((a+l)/2-s)/r,((o+c)/2-i)/n),!0}toSVGPath(){if(this.isEmpty())return"";let t=this.#r,e=this.#e;if(isNaN(this.#n[6])&&!this.isEmpty())return this.#v();let s=[];s.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)if(isNaN(t[i]))s.push(`L${t[i+4]} ${t[i+5]}`);else s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);this.#b(s);for(let i=e.length-6;i>=6;i-=6)if(isNaN(e[i]))s.push(`L${e[i+4]} ${e[i+5]}`);else s.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return this.#y(s),s.join(" ")}#v(){let[t,e,s,i]=this.#t,[r,n,a,o]=this.#g();return`M${(this.#n[2]-t)/s} ${(this.#n[3]-e)/i} L${(this.#n[4]-t)/s} ${(this.#n[5]-e)/i} L${r} ${n} L${a} ${o} L${(this.#n[16]-t)/s} ${(this.#n[17]-e)/i} L${(this.#n[14]-t)/s} ${(this.#n[15]-e)/i} Z`}#y(t){let e=this.#e;t.push(`L${e[4]} ${e[5]} Z`)}#b(t){let[e,s,i,r]=this.#t,n=this.#n.subarray(4,6),a=this.#n.subarray(16,18),[o,l,c,h]=this.#g();t.push(`L${(n[0]-e)/i} ${(n[1]-s)/r} L${o} ${l} L${c} ${h} L${(a[0]-e)/i} ${(a[1]-s)/r}`)}newFreeDrawOutline(t,e,s,i,r,n){return new $r(t,e,s,i,r,n)}getOutlines(){let t=this.#r,e=this.#e,s=this.#n,[i,r,n,a]=this.#t,o=new Float32Array((this.#f?.length??0)+2);for(let h=0,d=o.length-2;h<d;h+=2)o[h]=(this.#f[h]-i)/n,o[h+1]=(this.#f[h+1]-r)/a;if(o[o.length-2]=(this.#a-i)/n,o[o.length-1]=(this.#o-r)/a,isNaN(s[6])&&!this.isEmpty())return this.#_(o);let l=new Float32Array(this.#r.length+24+this.#e.length),c=t.length;for(let h=0;h<c;h+=2){if(isNaN(t[h])){l[h]=l[h+1]=NaN;continue}l[h]=t[h],l[h+1]=t[h+1]}c=this.#S(l,c);for(let h=e.length-6;h>=6;h-=6)for(let d=0;d<6;d+=2){if(isNaN(e[h+d])){l[c]=l[c+1]=NaN,c+=2;continue}l[c]=e[h+d],l[c+1]=e[h+d+1],c+=2}return this.#A(l,c),this.newFreeDrawOutline(l,o,this.#t,this.#u,this.#s,this.#i)}#_(t){let e=this.#n,[s,i,r,n]=this.#t,[a,o,l,c]=this.#g(),h=new Float32Array(36);return h.set([NaN,NaN,NaN,NaN,(e[2]-s)/r,(e[3]-i)/n,NaN,NaN,NaN,NaN,(e[4]-s)/r,(e[5]-i)/n,NaN,NaN,NaN,NaN,a,o,NaN,NaN,NaN,NaN,l,c,NaN,NaN,NaN,NaN,(e[16]-s)/r,(e[17]-i)/n,NaN,NaN,NaN,NaN,(e[14]-s)/r,(e[15]-i)/n],0),this.newFreeDrawOutline(h,t,this.#t,this.#u,this.#s,this.#i)}#A(t,e){let s=this.#e;return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6}#S(t,e){let s=this.#n.subarray(4,6),i=this.#n.subarray(16,18),[r,n,a,o]=this.#t,[l,c,h,d]=this.#g();return t.set([NaN,NaN,NaN,NaN,(s[0]-r)/a,(s[1]-n)/o,NaN,NaN,NaN,NaN,l,c,NaN,NaN,NaN,NaN,h,d,NaN,NaN,NaN,NaN,(i[0]-r)/a,(i[1]-n)/o],e),e+=24}}class $r extends H{#t;#e=new Float32Array(4);#s;#i;#r;#n;#a;constructor(t,e,s,i,r,n){super();this.#a=t,this.#r=e,this.#t=s,this.#n=i,this.#s=r,this.#i=n,this.firstPoint=[NaN,NaN],this.lastPoint=[NaN,NaN],this.#o(n);let[a,o,l,c]=this.#e;for(let h=0,d=t.length;h<d;h+=2)t[h]=(t[h]-a)/l,t[h+1]=(t[h+1]-o)/c;for(let h=0,d=e.length;h<d;h+=2)e[h]=(e[h]-a)/l,e[h+1]=(e[h+1]-o)/c}toSVGPath(){let t=[`M${this.#a[4]} ${this.#a[5]}`];for(let e=6,s=this.#a.length;e<s;e+=6){if(isNaN(this.#a[e])){t.push(`L${this.#a[e+4]} ${this.#a[e+5]}`);continue}t.push(`C${this.#a[e]} ${this.#a[e+1]} ${this.#a[e+2]} ${this.#a[e+3]} ${this.#a[e+4]} ${this.#a[e+5]}`)}return t.push("Z"),t.join(" ")}serialize([t,e,s,i],r){let n=s-t,a=i-e,o,l;switch(r){case 0:o=H._rescale(this.#a,t,i,n,-a),l=H._rescale(this.#r,t,i,n,-a);break;case 90:o=H._rescaleAndSwap(this.#a,t,e,n,a),l=H._rescaleAndSwap(this.#r,t,e,n,a);break;case 180:o=H._rescale(this.#a,s,e,-n,a),l=H._rescale(this.#r,s,e,-n,a);break;case 270:o=H._rescaleAndSwap(this.#a,s,i,-n,-a),l=H._rescaleAndSwap(this.#r,s,i,-n,-a);break}return{outline:Array.from(o),points:[Array.from(l)]}}#o(t){let e=this.#a,s=e[4],i=e[5],r=[s,i,s,i],n=s,a=i,o=s,l=i,c=t?Math.max:Math.min,h=new Float32Array(4);for(let u=6,f=e.length;u<f;u+=6){let p=e[u+4],g=e[u+5];if(isNaN(e[u])){if(O.pointBoundingBox(p,g,r),a>g)n=p,a=g;else if(a===g)n=c(n,p);if(l<g)o=p,l=g;else if(l===g)o=c(o,p)}else{if(h.set(ce,0),O.bezierBoundingBox(s,i,...e.slice(u,u+6),h),O.rectBoundingBox(...h,r),a>h[1])n=h[0],a=h[1];else if(a===h[1])n=c(n,h[0]);if(l<h[3])o=h[2],l=h[3];else if(l===h[3])o=c(o,h[2])}s=p,i=g}let d=this.#e;d[0]=r[0]-this.#s,d[1]=r[1]-this.#s,d[2]=r[2]-r[0]+2*this.#s,d[3]=r[3]-r[1]+2*this.#s,this.firstPoint=[n,a],this.lastPoint=[o,l]}get box(){return this.#e}newOutliner(t,e,s,i,r,n,a=0){return new De(t,e,s,i,r,n,a)}updateThickness(t){let e=this.getNewOutline(t);return this.#a=e.#a,this.#r=e.#r,this.#e.set(e.#e),this.firstPoint=e.firstPoint,this.lastPoint=e.lastPoint,this.#e}getNewOutline(t,e){let[s,i,r,n]=this.#e,[a,o,l,c]=this.#t,h=r*l,d=n*c,u=s*l+a,f=i*c+o,p=this.#r,g=this.newOutliner(p[0]*h+u,p[1]*d+f,this.#t,this.#n,t,this.#i,e??this.#s);for(let m=2,v=p.length;m<v;m+=2)g.add(p[m]*h+u,p[m+1]*d+f);return g.getOutlines()}}function Bo(t){return{bbox:t.box,root:{viewBox:"0 0 1 1"},rootClass:{highlight:!0,free:t.isFree},path:{d:t.toSVGPath()}}}function jo(t,e){let{focusOutline:s}=t;return{bbox:H._rotateBox(s.box,e),root:{"data-main-rotation":e},rootClass:{highlightOutline:!0,free:t.isFree},path:{d:s.toSVGPath()}}}class Qs{#t;#e;#s;#i=[];#r=[];constructor(t,e=0,s=0,i=!0){let r=ce.slice(),n=4,a=0.0001;for(let{x:g,y:m,width:v,height:y}of t){let b=Math.floor((g-e)/0.0001)*0.0001,_=Math.ceil((g+v+e)/0.0001)*0.0001,w=Math.floor((m-e)/0.0001)*0.0001,A=Math.ceil((m+y+e)/0.0001)*0.0001,x=[b,w,A,!0],E=[_,w,A,!1];this.#i.push(x,E),O.rectBoundingBox(b,w,_,A,r)}let o=r[2]-r[0]+2*s,l=r[3]-r[1]+2*s,c=r[0]-s,h=r[1]-s,d=i?-1/0:1/0,u=1/0,f=this.#i.at(i?-1:-2),p=[f[0],f[2]];for(let g of this.#i){let[m,v,y,b]=g;if(!b&&i){if(v<u)u=v,d=m;else if(v===u)d=Math.max(d,m)}else if(b&&!i){if(v<u)u=v,d=m;else if(v===u)d=Math.min(d,m)}g[0]=(m-c)/o,g[1]=(v-h)/l,g[2]=(y-h)/l}this.#t=new Float32Array([c,h,o,l]),this.#e=[d,u],this.#s=p}getOutlines(){this.#i.sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);let t=[];for(let e of this.#i)if(e[3])t.push(...this.#c(e)),this.#o(e);else this.#l(e),t.push(...this.#c(e));return this.#n(t)}#n(t){let e=[],s=new Set;for(let r of t){let[n,a,o]=r;e.push([n,a,r],[n,o,r])}e.sort((r,n)=>r[1]-n[1]||r[0]-n[0]);for(let r=0,n=e.length;r<n;r+=2){let a=e[r][2],o=e[r+1][2];a.push(o),o.push(a),s.add(a),s.add(o)}let i=[];while(s.size>0){let r=s.values().next().value,[n,a,o,l,c]=r;s.delete(r);let h=n,d=a,u=[n,o];i.push(u);while(!0){let f;if(s.has(l))f=l;else if(s.has(c))f=c;else break;if(s.delete(f),[n,a,o,l,c]=f,h!==n)u.push(h,d,n,d===a?a:o),h=n;d=d===a?o:a}u.push(h,d)}return new Zs(i,this.#t,this.#e,this.#s)}#a(t){let e=this.#r,s=0,i=e.length-1;while(s<=i){let r=s+i>>1,n=e[r][0];if(n===t)return r;if(n<t)s=r+1;else i=r-1}return i+1}#o([,t,e]){let s=this.#a(t);this.#r.splice(s,0,[t,e])}#l([,t,e]){let s=this.#a(t);for(let i=s;i<this.#r.length;i++){let[r,n]=this.#r[i];if(r!==t)break;if(r===t&&n===e){this.#r.splice(i,1);return}}for(let i=s-1;i>=0;i--){let[r,n]=this.#r[i];if(r!==t)break;if(r===t&&n===e){this.#r.splice(i,1);return}}}#c(t){let[e,s,i]=t,r=[[e,s,i]],n=this.#a(i);for(let a=0;a<n;a++){let[o,l]=this.#r[a];for(let c=0,h=r.length;c<h;c++){let[,d,u]=r[c];if(l<=d||u<=o)continue;if(d>=o){if(u>l)r[c][1]=l;else{if(h===1)return[];r.splice(c,1),c--,h--}continue}if(r[c][2]=o,u>l)r.push([e,l,u])}}return r}}class Zs extends H{#t;#e=null;#s;constructor(t,e,s,i){super();this.#s=t,this.#t=e,this.firstPoint=s,this.lastPoint=i}static build(t,e){let s=new Qs(t,0.001).getOutlines();return s.#e=t,s.focusOutline=new Qs(t,0.0025,0.001,e).getOutlines(),s}get isFree(){return!1}get defaultSVGProperties(){return Bo(this)}getFocusSVGProperties(t){return jo(this,t)}updateRotation(t){return{root:{"data-main-rotation":t}}}serializeQuadPoints([t,e],[s,i]){let r=this.#e,n=new Float32Array(r.length*8),a=0;for(let{x:o,y:l,width:c,height:h}of r){let d=o*s+t,u=(1-l)*i+e;n[a]=n[a+4]=d,n[a+1]=n[a+3]=u,n[a+2]=n[a+6]=d+c*s,n[a+5]=n[a+7]=u-h*i,a+=8}return n}toSVGPath(){let t=[];for(let e of this.#s){let[s,i]=e;t.push(`M${s} ${i}`);for(let r=2;r<e.length;r+=2){let n=e[r],a=e[r+1];if(n===s)t.push(`V${a}`),i=a;else if(a===i)t.push(`H${n}`),s=n}t.push("Z")}return t.join(" ")}serialize([t,e,s,i],r){let n=[],a=s-t,o=i-e;for(let l of this.#s){let c=Array(l.length);for(let h=0;h<l.length;h+=2)c[h]=t+l[h]*a,c[h+1]=i-l[h+1]*o;n.push(c)}return n}get box(){return this.#t}}class Bi extends De{newFreeDrawOutline(t,e,s,i,r,n){return new Gr(t,e,s,i,r,n)}}class Ho{#t;#e;constructor(t,e,s,i,r,n,a){this.#t=new Bi(t,e,s,i,r,n,a),this.#e=r}add(t,e){return this.#t.add(t,e)?{path:{d:this.#t.toSVGPath()}}:null}addPoints(t){let e=!1;for(let s=0,i=t.length;s<i;s+=2)e=this.#t.add(t[s],t[s+1])||e;return e?{path:{d:this.#t.toSVGPath()}}:null}end(t,e){return t===void 0?null:this.add(t,e)}isEmpty(){return this.#t.isEmpty()}isCancellable(){return this.#t.isCancellable()}removeLastElement(){return this.#t.removeLastElement()}updateProperty(t,e){return null}getOutlines(){let t=this.#t.getOutlines();return t.buildFocusOutline(2*this.#e),t}get defaultSVGProperties(){return{bbox:[0,0,1,1],root:{viewBox:"0 0 1 1"},rootClass:{highlight:!0,free:!0},path:{d:this.#t.toSVGPath()}}}}class Gr extends $r{static#t=1.5;newOutliner(t,e,s,i,r,n,a=0){return new Bi(t,e,s,i,r,n,a)}get isFree(){return!0}buildFocusOutline(t){this.focusOutline=this.getNewOutline(t/2+Gr.#t,0.0025)}get defaultSVGProperties(){return Bo(this)}getFocusSVGProperties(t){return jo(this,t)}get focusMustRemoveSelfIntersections(){return!0}updateRotation(t){return{root:{"data-main-rotation":t}}}updateProperty(t,e){if(t!=="thickness")return null;let s=this.updateThickness(e/2);return this.buildFocusOutline(e),s}getPathResizedSVGProperties(){return{path:{d:this.toSVGPath()}}}}class zr extends Ni{constructor(t=null){super();super.updateProperties(t)}updateSVGProperty(t,e){if(t!=="thickness")super.updateSVGProperty(t,e)}clone(){let t=new zr;return t.updateAll(this),t}}class ie extends et{#t=null;#e=0;#s=null;#i=0;#r="";#n="";static _DEFAULT_OPACITY=1;static _DEFAULT_THICKNESS=12;static _defaultDrawingOptions=null;static _type="highlight";static _editorType=K.HIGHLIGHT;static get _keyboardManager(){let t=ie.prototype;return L(this,"_keyboardManager",new Xt([[["ArrowLeft"],t._moveCaret,{args:[0]}],[["ArrowRight"],t._moveCaret,{args:[1]}],[["ArrowUp"],t._moveCaret,{args:[2]}],[["ArrowDown"],t._moveCaret,{args:[3]}]]))}constructor(t){super({...t,name:"highlightEditor"});this.#t=t.anchorNode||null,this.#e=t.anchorOffset||0,this.#s=t.focusNode||null,this.#i=t.focusOffset||0,this.#r=t.methodOfCreation||(this._drawOutlines?.isFree?"main_toolbar":""),this.#n=t.text||"",this._isDraggable=!1,this.defaultL10nId="pdfjs-editor-highlight-editor",this.rotate()}static initialize(t,e){U.initialize(t,e),this._defaultDrawingOptions||=new zr({fill:e.highlightColors?.values().next().value||"#fff066","fill-opacity":ie._DEFAULT_OPACITY,thickness:ie._DEFAULT_THICKNESS})}static getDefaultDrawingOptions(t){let e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get typesMap(){return L(this,"typesMap",new Map([[st.HIGHLIGHT_COLOR,"fill"],[st.HIGHLIGHT_THICKNESS,"thickness"]]))}static get isDrawer(){return!1}static get _hasClipPath(){return!0}static get _hasDrawClass(){return!1}_addOutlines(t){let{boxes:e,drawOutlines:s}=t;if(!e&&!s)return;if(this._drawingOptions||=t.drawingOptions||ie.getDefaultDrawingOptions(),e)t={...t,drawOutlines:Zs.build(e,this._uiManager.direction==="ltr")};super._addOutlines(t)}get colorType(){return st.HIGHLIGHT_COLOR}get color(){return this._drawingOptions.fill}get opacity(){return this._drawingOptions["fill-opacity"]}get _opacityName(){return"fill-opacity"}get _drawRotation(){return this._drawOutlines?.isFree?this.rotation:0}get isResizable(){return!1}get _mustBeDisabledOnCommit(){return!1}get _mustFixPosition(){return!this._drawOutlines?.isFree}get telemetryInitialData(){return{action:"added",type:this._drawOutlines.isFree?"free_highlight":"highlight",color:this._uiManager.getNonHCMColorName(this.color),thickness:this._drawingOptions.thickness,methodOfCreation:this.#r}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.getNonHCMColorName(this.color)}}static computeTelemetryFinalData(t){return{numberOfColors:t.get("color").size}}translateInPage(t,e){}get toolbarPosition(){return this.#a(this._drawOutlines.focusOutline.lastPoint)}get commentButtonPosition(){return this.#a(this._drawOutlines.firstPoint)}#a([t,e]){let[s,i,r,n]=this._drawOutlines.box;return[(t-s)/r,(e-i)/n]}updateParams(t,e){switch(t){case st.HIGHLIGHT_COLOR:this._updateColorAndOpacity(e,ie._DEFAULT_OPACITY,t),this._reportTelemetry({action:"color_changed",color:this._uiManager.getNonHCMColorName(e)},!0);break;case st.HIGHLIGHT_THICKNESS:super.updateParams(t,e),this._reportTelemetry({action:"thickness_changed",thickness:e},!0);break}}get propertiesToUpdate(){let t=super.propertiesToUpdate;return t.push([st.HIGHLIGHT_FREE,this._drawOutlines.isFree]),t}get toolbarButtons(){if(this._uiManager.highlightColors)return this._colorPicker=new Qt({editor:this}),[["colorPicker",this._colorPicker]];return super.toolbarButtons}fixAndSetPosition(){return super.fixAndSetPosition(this._drawRotation)}getRect(t,e){return super.getRect(t,e,this._drawRotation)}onceAdded(t){if(!this.annotationElementId)this.parent.addUndoableEditor(this);if(t)this.div.focus()}remove(){this._reportTelemetry({action:"deleted"}),super.remove()}render(){if(this.div)return this.div;let t=super.render();if(this.#n)t.setAttribute("aria-label",this.#n),t.setAttribute("role","mark");if(this._drawOutlines.isFree)t.classList.add("free");else t.addEventListener("keydown",this.#o.bind(this),{signal:this._uiManager._signal});return this.enableEditing(),t}#o(t){ie._keyboardManager.exec(this,t)}_moveCaret(t){switch(this.parent.unselect(this),t){case 0:case 2:this.#l(!0);break;case 1:case 3:this.#l(!1);break}}#l(t){if(!this.#t)return;let e=window.getSelection();if(t)e.setPosition(this.#t,this.#e);else e.setPosition(this.#s,this.#i)}unselect(){if(super.unselect(),!this._drawOutlines.isFree)this.#l(!1)}static createDrawerInstance({x:t,y:e,box:s,parent:i,isLTR:r}){return new Ho(t,e,s,i.scale,this._defaultDrawingOptions.thickness/2,r,0.001)}static _getDrawingTarget(t,{target:e}){return e.closest(".textLayer")}static _getPointerCoords({x:t,y:e}){return[t,e]}static _addDrawingListeners(t,e){t.classList.add("free"),e.addEventListener("abort",()=>t.classList.remove("free"),{once:!0}),window.addEventListener("blur",()=>this._endDraw(null),{signal:e}),window.addEventListener("pointerdown",Tt,{capture:!0,passive:!1,signal:e})}static _endDrawingSession(t=!1){return this.endDrawing(t)}createDrawingOptions({color:t,opacity:e,thickness:s}){let{_defaultDrawingOptions:i,_DEFAULT_OPACITY:r}=ie;this._drawingOptions=ie.getDefaultDrawingOptions({fill:O.makeHexColor(...t),"fill-opacity":e||r,thickness:s||i.thickness})}static deserializeDraw(t,e,s,i,r,n,a){let{quadPoints:o}=n;if(o){let u=[];for(let f=0,p=o.length;f<p;f+=8)u.push({x:(o[f]-t)/s,y:1-(o[f+1]-e)/i,width:(o[f+2]-o[f])/s,height:(o[f+1]-o[f+5])/i});return Zs.build(u,a.direction==="ltr")}let l=n.thickness||this._defaultDrawingOptions.thickness,c=(n.inkLists||n.outlines.points)[0],h=new Bi(c[0]-t,i-(c[1]-e),[0,0,s,i],1,l/2,!0,0.001);for(let u=0,f=c.length;u<f;u+=2)h.add(c[u]-t,i-(c[u+1]-e));let d=h.getOutlines();return d.buildFocusOutline(l),d}static async deserialize(t,e,s){let i=null;if(t instanceof Br){let{data:{quadPoints:n,rect:a,rotation:o,id:l,color:c,opacity:h,popupRef:d,richText:u,contentsObj:f,creationDate:p,modificationDate:g},parent:{page:{pageNumber:m}}}=t;i=t={annotationType:K.HIGHLIGHT,color:Array.from(c),opacity:h,quadPoints:n,pageIndex:m-1,rect:a.slice(0),rotation:o,annotationElementId:l,id:l,deleted:!1,popupRef:d,richText:u,comment:f?.str||null,creationDate:p,modificationDate:g}}else if(t instanceof Li){let{data:{inkLists:n,rect:a,rotation:o,id:l,color:c,borderStyle:{rawWidth:h},popupRef:d,richText:u,contentsObj:f,creationDate:p,modificationDate:g},parent:{page:{pageNumber:m}}}=t;i=t={annotationType:K.HIGHLIGHT,color:Array.from(c),thickness:h,inkLists:n,pageIndex:m-1,rect:a.slice(0),rotation:o,annotationElementId:l,id:l,deleted:!1,popupRef:d,richText:u,comment:f?.str||null,creationDate:p,modificationDate:g}}let r=await super.deserialize(t,e,s);if(r._initialData=i,t.comment)r.setCommentData(t);return r}serialize(t=!1){if(this.isEmpty()||t)return null;if(this.deleted)return this.serializeDeleted();let e=super.serialize(t);if(Object.assign(e,{color:U._colorManager.convert(this._uiManager.getNonHCMColor(this.color)),opacity:this.opacity,thickness:this._drawingOptions.thickness,quadPoints:this._drawOutlines.serializeQuadPoints(this.pageTranslation,this.pageDimensions),outlines:this._drawOutlines.serialize(e.rect,this._drawRotation)}),this.addComment(e),this.annotationElementId&&!this.#c(e))return null;return e.id=this.annotationElementId,e}#c(t){let{color:e}=this._initialData;return this.hasEditedComment||t.color.some((s,i)=>s!==e[i])}renderAnnotationElement(t){if(this.deleted)return t.hide(),null;return t.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null}}class _e{static#t=10;static#e=5.555555555555555;static#s=100;static#i=0.001;#r;#n;#a;constructor(t,e,s){this.#r=[t,e,s],this.#n=this.#a=s}add(t,e,s){let i=this.#r,r=i.at(-1);s=s>r?s:r+_e.#i,i.push(t,e,s);let n=this.#o(s-_e.#t,!0),a=this.#l(this.#a-_e.#t);if(a>=i.length/2)i.copyWithin(0,a),i.length-=a;return n}get pendingPoints(){return this.#o(1/0,!1)}end(){return this.#o(1/0,!0)}#o(t,e){let s=this.#r,i=this.#n,r=s.at(-1),n=[],a=this.#a;for(let o=this.#l(a)+3;o<s.length;o+=3){let l=s[o-1],c=s[o+2]-l,h=Math.min(Math.ceil(c/_e.#e),_e.#s);for(let d=1;d<=h;d++){let u=d===h?s[o+2]:l+c*d/h;if(u<=a)continue;if(u>t)return n;let f=Math.min(_e.#t,u-i,r-u);if(this.#c(u-f,u+f,n),e)this.#a=u}}return n}#l(t){let e=this.#r,s=0,i=e.length/3-1;while(s<i){let r=s+i+1>>1;if(e[3*r+2]<=t)s=r;else i=r-1}return 3*s}#c(t,e,s){let i=this.#r,r=this.#l(t),n=0,a=0,o=0;for(let l=r;l<i.length-3&&i[l+2]<e;l+=3){let c=i[l],h=i[l+1],d=i[l+2],u=i[l+5],f=Math.max(d,t),p=Math.min(u,e);if(p<=f)continue;let g=p-f,m=(f+p-2*d)/(u-d);n+=g*(c+m*(i[l+3]-c)/2),a+=g*(h+m*(i[l+4]-h)/2),o+=g}if(o===0)s.push(i[r],i[r+1]);else s.push(n/o,a/o)}}function me(t,e){return`${H.svgRound(t[e])} ${H.svgRound(t[e+1])}`}function Uo(t,e,s){for(let i=s,r=e.length;i<r;i+=6)t.push(`C${me(e,i)} ${me(e,i+2)} ${me(e,i+4)}`)}function Gs(t){let e=`M${me(t,4)}`;if(t.length===6)return`${e}Z`;if(t.length===12&&isNaN(t[6]))return`${e}L${me(t,10)}`;let s=[e];return Uo(s,t,6),s.join("")}class $o{#t=new Float64Array(6);#e=new Float64Array(2);#s;#i;#r;#n=null;#a;#o;#l=1;#c=new Float64Array(2);#u="";#h=0;#f=new es;#p;#m;constructor(t,e,s,i,r,n,a){this.#p=s,this.#m=i,this.#r=r,this.#a=n,this.#i=[],this.#d(t,e,a)}#d(t,e,s){[t,e]=this.#g(t,e);let i=this.#s=[NaN,NaN,NaN,NaN,t,e];this.#o=[t,e],this.#i.push({line:i,points:this.#o}),this.#t.set(i,0),this.#h=0,this.#l=1,this.#c.set(this.#e),this.#n=s===void 0?null:new _e(t,e,s)}updateProperty(t,e){if(t==="stroke-width")this.#a=e}#g(t,e){return H._normalizePoint(t,e,this.#p,this.#m,this.#r,this.#e)}isEmpty(){return!this.#i?.length}isCancellable(){return this.#l<=5}add(t,e,s){return this.#v(t,e,s),{path:{d:this.#w()}}}addPoints(t,e){for(let s=0,i=t.length;s<i;s+=2)this.#v(t[s],t[s+1],e?.[s/2]);return{path:{d:this.#w()}}}#v(t,e,s){[t,e]=this.#g(t,e);let[i,r]=this.#c;if(!this.#y(t,e,i,r))this.#l++,this.#c.set(this.#e);if(this.#n)this.#b(this.#n.add(t,e,s));else this.#_(t,e)}#y(t,e,s,i){return Math.hypot(this.#p*(t-s),this.#m*(e-i))<=2}#b(t){for(let e=0,s=t.length;e<s;e+=2)this.#_(t[e],t[e+1])}#_(t,e){let[,,s,i,r,n]=this.#t;if(this.#y(t,e,r,n))return;if(this.#o.push(t,e),isNaN(s))this.#s.push(NaN,NaN,NaN,NaN,t,e);else{if(isNaN(this.#t[0]))this.#s.splice(6,6);H.createBezierPoints(s,i,r,n,t,e,this.#s)}this.#t.copyWithin(0,2),this.#t[4]=t,this.#t[5]=e}#A(){let t=this.#s;if(this.#o.length<6||this.#h===t.length)return;let e=[this.#u];if(this.#h===0)e.push(`M${me(t,4)}`),this.#h=6;Uo(e,t,this.#h),this.#u=e.join(""),this.#h=t.length}#S(){if(!this.#s)return;if(this.#n)this.#b(this.#n.end()),this.#n=null;if(this.#o.length<6)this.#u+=Gs(this.#s);else{let[,,t,e,s,i]=this.#t;H.createBezierPoints(t,e,s,i,s,i,this.#s),this.#A()}this.#s=this.#o=null}end(t,e,s){if(this.#s&&t!==void 0)this.#v(t,e,s);return this.#S(),{path:{d:this.#u}}}startNew(t,e,s,i,r,n){this.#p=s,this.#m=i,this.#r=r;let a=this.#i.at(-1);if(a)a.line=new Float32Array(a.line),a.points=new Float32Array(a.points);return this.#d(t,e,n),null}getLastElement(){return this.#i.at(-1)}setLastElement(t){if(!this.#i)return this.#f.setLastElement(t);return this.#i.push(t),this.#u+=Gs(t.line),{path:{d:this.#u}}}removeLastElement(){if(!this.#i)return this.#f.removeLastElement();return this.#s=this.#o=this.#n=null,this.#i.pop(),this.#u=this.#i.map(({line:t})=>Gs(t)).join(""),{path:{d:this.#u}}}#w(){this.#A();let t=[this.#u];if(this.#h===0){if(t.push(`M${me(this.#s,4)}`),this.#o.length===4)t.push(`L${me(this.#s,10)}`)}let e=this.#n?.pendingPoints;if(!e?.length)e=this.#e;for(let s=0,i=e.length;s<i;s+=2)t.push(`L${me(e,s)}`);return t.join("")}getOutlines(t,e,s,i){this.#S();let r=this.#i.at(-1);return r.line=new Float32Array(r.line),r.points=new Float32Array(r.points),this.#f.build(this.#i,t,e,s,this.#r,this.#a,i),this.#t=null,this.#s=null,this.#i=null,this.#u=null,this.#f}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}class es extends H{#t;#e=0;#s;#i;#r;#n;#a;#o;#l;build(t,e,s,i,r,n,a){this.#r=e,this.#n=s,this.#a=i,this.#o=r,this.#l=n,this.#s=a??0,this.#i=t,this.#h()}get thickness(){return this.#l}setLastElement(t){return this.#i.push(t),{path:{d:this.toSVGPath()}}}removeLastElement(){return this.#i.pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){return this.#i.map(({line:t})=>Gs(t)).join("")}serialize([t,e,s,i],r){let n=[],a=[],[o,l,c,h]=this.#u(),d,u,f,p,g,m,v,y,b;switch(this.#o){case 0:b=H._rescale,d=t,u=e+i,f=s,p=-i,g=t+o*s,m=e+(1-l-h)*i,v=t+(o+c)*s,y=e+(1-l)*i;break;case 90:b=H._rescaleAndSwap,d=t,u=e,f=s,p=i,g=t+l*s,m=e+o*i,v=t+(l+h)*s,y=e+(o+c)*i;break;case 180:b=H._rescale,d=t+s,u=e,f=-s,p=i,g=t+(1-o-c)*s,m=e+l*i,v=t+(1-o)*s,y=e+(l+h)*i;break;case 270:b=H._rescaleAndSwap,d=t+s,u=e+i,f=-s,p=-i,g=t+(1-l-h)*s,m=e+(1-o-c)*i,v=t+(1-l)*s,y=e+(1-o)*i;break}for(let{line:_,points:w}of this.#i)n.push(b(_,d,u,f,p,r?Array(_.length):null)),a.push(b(w,d,u,f,p,r?Array(w.length):null));return{lines:n,points:a,rect:[g,m,v,y]}}static deserialize(t,e,s,i,r,{paths:{lines:n,points:a},rotation:o,thickness:l}){let c=[],h,d,u,f,p;switch(o){case 0:p=H._rescale,h=-t/s,d=e/i+1,u=1/s,f=-1/i;break;case 90:p=H._rescaleAndSwap,h=-e/i,d=-t/s,u=1/i,f=1/s;break;case 180:p=H._rescale,h=t/s+1,d=-e/i,u=-1/s,f=1/i;break;case 270:p=H._rescaleAndSwap,h=e/i+1,d=t/s+1,u=-1/i,f=-1/s;break}if(!n){n=[];for(let m of a){let v=m.length;if(v===2){n.push(new Float32Array([NaN,NaN,NaN,NaN,m[0],m[1]]));continue}if(v===4){n.push(new Float32Array([NaN,NaN,NaN,NaN,m[0],m[1],NaN,NaN,NaN,NaN,m[2],m[3]]));continue}let y=new Float32Array(3*v);n.push(y);let[b,_,w,A]=m.subarray(0,4);y.set([NaN,NaN,NaN,NaN,b,_],0);for(let x=4;x<=v;x+=2){let E=Math.min(x,v-2),T=m[E],k=m[E+1];y.set(H.createBezierPoints(b,_,w,A,T,k),(x-2)*3),[b,_,w,A]=[w,A,T,k]}}}for(let m=0,v=n.length;m<v;m++)c.push({line:p(n[m].map((y)=>y??NaN),h,d,u,f),points:p(a[m].map((y)=>y??NaN),h,d,u,f)});let g=new this.prototype.constructor;return g.build(c,s,i,1,o,l,r),g}#c(t=this.#l){let e=this.#s+t/2*this.#a;return this.#o%180===0?[e/this.#r,e/this.#n]:[e/this.#n,e/this.#r]}#u(){let[t,e,s,i]=this.#t,[r,n]=this.#c(0);return[t+r,e+n,s-2*r,i-2*n]}#h(){let t=this.#t=Re.slice();for(let{line:i}of this.#i){if(i.length<=12){for(let a=4,o=i.length;a<o;a+=6)O.pointBoundingBox(i[a],i[a+1],t);continue}let r=i[4],n=i[5];for(let a=6,o=i.length;a<o;a+=6){let[l,c,h,d,u,f]=i.subarray(a,a+6);O.bezierBoundingBox(r,n,l,c,h,d,u,f,t),r=u,n=f}}let[e,s]=this.#c();t[0]=pt(t[0]-e,0,1),t[1]=pt(t[1]-s,0,1),t[2]=pt(t[2]+e,0,1),t[3]=pt(t[3]+s,0,1),t[2]-=t[0],t[3]-=t[1]}get box(){return this.#t}updateProperty(t,e){return t==="stroke-width"?this.#f(e):null}#f(t){let[e,s]=this.#c();this.#l=t;let[i,r]=this.#c(),[n,a]=[i-e,r-s],o=this.#t;return o[0]-=n,o[1]-=a,o[2]+=2*n,o[3]+=2*a,o}updateParentDimensions([t,e],s){let[i,r]=this.#c();this.#r=t,this.#n=e,this.#a=s;let[n,a]=this.#c(),o=n-i,l=a-r,c=this.#t;return c[0]-=o,c[1]-=l,c[2]+=2*o,c[3]+=2*l,c}updateRotation(t){return this.#e=t,{path:{transform:this.rotationTransform}}}get viewBox(){return this.#t.map(H.svgRound).join(" ")}get defaultProperties(){let[t,e]=this.#t;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${H.svgRound(t)} ${H.svgRound(e)}`}}}get rotationTransform(){let[,,t,e]=this.#t,s=0,i=0,r=0,n=0,a=0,o=0;switch(this.#e){case 90:i=e/t,r=-t/e,a=t;break;case 180:s=-1,n=-1,a=t,o=e;break;case 270:i=-e/t,r=t/e,o=e;break;default:return""}return`matrix(${s} ${i} ${r} ${n} ${H.svgRound(a)} ${H.svgRound(o)})`}getPathResizingSVGProperties([t,e,s,i]){let[r,n]=this.#c(),[a,o,l,c]=this.#t;if(Math.abs(l-r)<=H.PRECISION||Math.abs(c-n)<=H.PRECISION){let p=t+s/2-(a+l/2),g=e+i/2-(o+c/2);return{path:{"transform-origin":`${H.svgRound(t)} ${H.svgRound(e)}`,transform:`${this.rotationTransform} translate(${p} ${g})`}}}let h=(s-2*r)/(l-2*r),d=(i-2*n)/(c-2*n),u=l/s,f=c/i;return{path:{"transform-origin":`${H.svgRound(a)} ${H.svgRound(o)}`,transform:`${this.rotationTransform} scale(${u} ${f}) translate(${H.svgRound(r)} ${H.svgRound(n)}) scale(${h} ${d}) translate(${H.svgRound(-r)} ${H.svgRound(-n)})`}}}getPathResizedSVGProperties([t,e,s,i]){let[r,n]=this.#c(),a=this.#t,[o,l,c,h]=a;if(a[0]=t,a[1]=e,a[2]=s,a[3]=i,Math.abs(c-r)<=H.PRECISION||Math.abs(h-n)<=H.PRECISION){let g=t+s/2-(o+c/2),m=e+i/2-(l+h/2);for(let{line:v,points:y}of this.#i)H._translate(v,g,m,v),H._translate(y,g,m,y);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${H.svgRound(t)} ${H.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}let d=(s-2*r)/(c-2*r),u=(i-2*n)/(h-2*n),f=-d*(o+r)+t+r,p=-u*(l+n)+e+n;if(d!==1||u!==1||f!==0||p!==0)for(let{line:g,points:m}of this.#i)H._rescale(g,f,p,d,u,g),H._rescale(m,f,p,d,u,m);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${H.svgRound(t)} ${H.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([t,e],s){let[i,r]=s,n=this.#t,a=t-n[0],o=e-n[1];if(this.#r===i&&this.#n===r)for(let{line:l,points:c}of this.#i)H._translate(l,a,o,l),H._translate(c,a,o,c);else{let l=this.#r/i,c=this.#n/r;this.#r=i,this.#n=r;for(let{line:h,points:d}of this.#i)H._rescale(h,a,o,l,c,h),H._rescale(d,a,o,l,c,d);n[2]*=l,n[3]*=c}return n[0]=t,n[1]=e,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${H.svgRound(t)} ${H.svgRound(e)}`}}}get defaultSVGProperties(){let t=this.#t;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${H.svgRound(t[0])} ${H.svgRound(t[1])}`,transform:this.rotationTransform||null},bbox:t}}}class ji extends Ni{constructor(t){super();this._viewParameters=t,super.updateProperties({fill:"none",stroke:U._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(t,e){if(t==="stroke-width")e??=this["stroke-width"],e*=this._viewParameters.realScale;super.updateSVGProperty(t,e)}clone(){let t=new ji(this._viewParameters);return t.updateAll(this),t}}class Vr extends et{static _type="ink";static _editorType=K.INK;static _defaultDrawingOptions=null;constructor(t){super({...t,name:"inkEditor"});this._willKeepAspectRatio=!0,this.defaultL10nId="pdfjs-editor-ink-editor"}static initialize(t,e){U.initialize(t,e),this._defaultDrawingOptions=new ji(e.viewParameters)}static getDefaultDrawingOptions(t){let e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!0}static get typesMap(){return L(this,"typesMap",new Map([[st.INK_THICKNESS,"stroke-width"],[st.INK_COLOR,"stroke"],[st.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance({x:t,y:e,box:[,,s,i],rotation:r,timeStamp:n}){return new $o(t,e,s,i,r,this._defaultDrawingOptions["stroke-width"],n)}static deserializeDraw(t,e,s,i,r,n){return es.deserialize(t,e,s,i,r,n)}static async deserialize(t,e,s){let i=null;if(t instanceof Li){let{data:{inkLists:n,rect:a,rotation:o,id:l,color:c,opacity:h,borderStyle:{rawWidth:d},popupRef:u,richText:f,contentsObj:p,creationDate:g,modificationDate:m},parent:{page:{pageNumber:v}}}=t;i=t={annotationType:K.INK,color:Array.from(c),thickness:d,opacity:h,paths:{points:n},boxes:null,pageIndex:v-1,rect:a.slice(0),rotation:o,annotationElementId:l,id:l,deleted:!1,popupRef:u,richText:f,comment:p?.str||null,creationDate:g,modificationDate:m}}let r=await super.deserialize(t,e,s);if(r._initialData=i,t.comment)r.setCommentData(t);return r}get toolbarButtons(){return this._colorPicker||=new bs(this),[["colorPicker",this._colorPicker]]}get colorType(){return st.INK_COLOR}get colorAndOpacityType(){return st.INK_COLOR_AND_OPACITY}get opacityType(){return st.INK_OPACITY}updateParams(t,e){if(t===st.INK_COLOR_AND_OPACITY){this._updateColorAndOpacity(e.color,e.opacity);return}super.updateParams(t,e)}static updateDefaultParams(t,e){if(t===st.INK_COLOR_AND_OPACITY){super.updateDefaultParams(st.INK_COLOR,e.color),super.updateDefaultParams(st.INK_OPACITY,e.opacity);return}super.updateDefaultParams(t,e)}get color(){return this._drawingOptions.stroke}get opacity(){return this._drawingOptions["stroke-opacity"]}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();let{_drawId:t,_drawingOptions:e,parent:s}=this;e.updateSVGProperty("stroke-width"),s.drawLayer.updateProperties(t,e.toSVGProperties())}static onScaleChangingWhenDrawing(){let t=this._currentParent;if(!t)return;super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),t.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties())}createDrawingOptions({color:t,thickness:e,opacity:s}){this._drawingOptions=Vr.getDefaultDrawingOptions({stroke:O.makeHexColor(...t),"stroke-width":e,"stroke-opacity":s})}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let{lines:e,points:s}=this.serializeDraw(t),{_drawingOptions:{stroke:i,"stroke-opacity":r,"stroke-width":n}}=this,a=Object.assign(super.serialize(t),{color:U._colorManager.convert(i),opacity:r,thickness:n,paths:{lines:e,points:s}});if(this.addComment(a),t)return a.isCopy=!0,a;if(this.annotationElementId&&!this.#t(a))return null;return a.id=this.annotationElementId,a}#t(t){let{color:e,thickness:s,opacity:i,pageIndex:r}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized||t.color.some((n,a)=>n!==e[a])||t.thickness!==s||t.opacity!==i||t.pageIndex!==r}renderAnnotationElement(t){if(this.deleted)return t.hide(),null;let{points:e,rect:s}=this.serializeDraw(!1);return t.updateEdited({rect:s,thickness:this._drawingOptions["stroke-width"],points:e,popup:this.comment}),null}}class ti extends es{toSVGPath(){let t=super.toSVGPath();if(!t.endsWith("Z"))t+="Z";return t}}Oc();var Ls=8,ls=3;class Oe{static#t={maxDim:512,sigmaSFactor:0.02,sigmaR:25,kernelSize:16};static#e(t,e,s,i){if(s-=t,i-=e,s===0)return i>0?0:4;return s===1?i+6:2-i}static#s=new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]);static#i(t,e,s,i,r,n,a){let o=this.#e(s,i,r,n);for(let l=0;l<8;l++){let c=(-l+o-a+16)%8,h=this.#s[2*c],d=this.#s[2*c+1];if(t[(s+h)*e+(i+d)]!==0)return c}return-1}static#r(t,e,s,i,r,n,a){let o=this.#e(s,i,r,n);for(let l=0;l<8;l++){let c=(l+o+a+16)%8,h=this.#s[2*c],d=this.#s[2*c+1];if(t[(s+h)*e+(i+d)]!==0)return c}return-1}static#n(t,e,s,i){let r=t.length,n=new Int32Array(r);for(let c=0;c<r;c++)n[c]=t[c]<=i?1:0;for(let c=1;c<s-1;c++)n[c*e]=n[c*e+e-1]=0;for(let c=0;c<e;c++)n[c]=n[e*s-1-c]=0;let a=1,o,l=[];for(let c=1;c<s-1;c++){o=1;for(let h=1;h<e-1;h++){let d=c*e+h,u=n[d];if(u===0)continue;let f=c,p=h;if(u===1&&n[d-1]===0)a+=1,p-=1;else if(u>=1&&n[d+1]===0){if(a+=1,p+=1,u>1)o=u}else{if(u!==1)o=Math.abs(u);continue}let g=[h,c],m=p===h+1,v={isHole:m,points:g,id:a,parent:0};l.push(v);let y;for(let k of l)if(k.id===o){y=k;break}if(!y)v.parent=m?o:0;else if(y.isHole)v.parent=m?y.parent:o;else v.parent=m?o:y.parent;let b=this.#i(n,e,c,h,f,p,0);if(b===-1){if(n[d]=-a,n[d]!==1)o=Math.abs(n[d]);continue}let _=this.#s[2*b],w=this.#s[2*b+1],A=c+_,x=h+w;f=A,p=x;let E=c,T=h;while(!0){let k=this.#r(n,e,E,T,f,p,1);_=this.#s[2*k],w=this.#s[2*k+1];let C=E+_,R=T+w;g.push(R,C);let B=E*e+T;if(n[B+1]===0)n[B]=-a;else if(n[B]===1)n[B]=a;if(C===c&&R===h&&E===A&&T===x){if(n[d]!==1)o=Math.abs(n[d]);break}else f=E,p=T,E=C,T=R}}}return l}static#a(t,e,s,i){if(s-e<=4){for(let A=e;A<s-2;A+=2)i.push(t[A],t[A+1]);return}let r=t[e],n=t[e+1],a=t[s-4]-r,o=t[s-3]-n,l=Math.hypot(a,o),c=a/l,h=o/l,d=c*n-h*r,u=o/a,f=1/l,p=Math.atan(u),g=Math.cos(p),m=Math.sin(p),v=f*(Math.abs(g)+Math.abs(m)),y=f*(1-v+v**2),b=Math.max(Math.atan(Math.abs(m+g)*y),Math.atan(Math.abs(m-g)*y)),_=0,w=e;for(let A=e+2;A<s-2;A+=2){let x=Math.abs(d-c*t[A+1]+h*t[A]);if(x>_)w=A,_=x}if(_>(l*b)**2)this.#a(t,e,w+2,i),this.#a(t,w,s,i);else i.push(r,n)}static#o(t){let e=[],s=t.length;return this.#a(t,0,s,e),e.push(t[s-2],t[s-1]),e.length<=4?null:e}static#l(t,e,s,i,r,n){let a=new Float32Array(n**2),o=-2*i**2,l=n>>1;for(let p=0;p<n;p++){let g=(p-l)**2;for(let m=0;m<n;m++)a[p*n+m]=Math.exp((g+(m-l)**2)/o)}let c=new Float32Array(256),h=-2*r**2;for(let p=0;p<256;p++)c[p]=Math.exp(p**2/h);let d=t.length,u=new Uint8Array(d),f=new Uint32Array(256);for(let p=0;p<s;p++)for(let g=0;g<e;g++){let m=p*e+g,v=t[m],y=0,b=0;for(let w=0;w<n;w++){let A=p+w-l;if(A<0||A>=s)continue;for(let x=0;x<n;x++){let E=g+x-l;if(E<0||E>=e)continue;let T=t[A*e+E],k=a[w*n+x]*c[Math.abs(T-v)];y+=T*k,b+=k}}let _=u[m]=Math.round(y/b);f[_]++}return[u,f]}static#c(t){let e=new Uint32Array(256);for(let s of t)e[s]++;return e}static#u(t){let e=t.length,s=new Uint8ClampedArray(e>>2),i=-1/0,r=1/0;for(let a=0,o=s.length;a<o;a++){let l=s[a]=t[a<<2];i=Math.max(i,l),r=Math.min(r,l)}let n=255/(i-r);for(let a=0,o=s.length;a<o;a++)s[a]=(s[a]-r)*n;return s}static#h(t){let e,s=-1/0,i=-1/0,r=t.findIndex((o)=>o!==0),n=r,a=r;for(e=r;e<256;e++){let o=t[e];if(o>s){if(e-n>i)i=e-n,a=e-1;s=o,n=e}}for(e=a-1;e>=0;e--)if(t[e]>t[e+1])break;return e}static#f(t){let e=t,{width:s,height:i}=t,{maxDim:r}=this.#t,n=s,a=i;if(s>r||i>r){let d=s,u=i,f=Math.log2(Math.max(s,i)/r),p=Math.floor(f);f=f===p?p-1:p;for(let m=0;m<f;m++){n=Math.ceil(d/2),a=Math.ceil(u/2);let v=new OffscreenCanvas(n,a);if(v.getContext("2d").drawImage(t,0,0,d,u,0,0,n,a),d=n,u=a,t!==e)t.close();t=v.transferToImageBitmap()}let g=Math.min(r/n,r/a);n=Math.round(n*g),a=Math.round(a*g)}let l=new OffscreenCanvas(n,a).getContext("2d",{willReadFrequently:!0});l.fillStyle="white",l.fillRect(0,0,n,a),l.filter="grayscale(1)",l.drawImage(t,0,0,t.width,t.height,0,0,n,a);let c=l.getImageData(0,0,n,a).data;return[this.#u(c),n,a]}static extractContoursFromText(t,{fontFamily:e,fontStyle:s,fontWeight:i},r,n,a,o){let l=new OffscreenCanvas(1,1),c=l.getContext("2d",{alpha:!1}),h=200,d=c.font=`${s} ${i} ${h}px ${e}`,{actualBoundingBoxLeft:u,actualBoundingBoxRight:f,actualBoundingBoxAscent:p,actualBoundingBoxDescent:g,fontBoundingBoxAscent:m,fontBoundingBoxDescent:v,width:y}=c.measureText(t),b=1.5,_=Math.ceil(Math.max(Math.abs(u)+Math.abs(f)||0,y)*b),w=Math.ceil(Math.max(Math.abs(p)+Math.abs(g)||h,Math.abs(m)+Math.abs(v)||h)*b);l=new OffscreenCanvas(_,w),c=l.getContext("2d",{alpha:!0,willReadFrequently:!0}),c.font=d,c.filter="grayscale(1)",c.fillStyle="white",c.fillRect(0,0,_,w),c.fillStyle="black",c.fillText(t,_*(b-1)/2,w*(3-b)/2);let A=this.#u(c.getImageData(0,0,_,w).data),x=this.#c(A),E=this.#h(x),T=this.#n(A,_,w,E);return this.processDrawnLines({lines:{curves:T,width:_,height:w},pageWidth:r,pageHeight:n,rotation:a,innerMargin:o,mustSmooth:!0,areContours:!0})}static process(t,e,s,i,r){let[n,a,o]=this.#f(t),[l,c]=this.#l(n,a,o,Math.hypot(a,o)*this.#t.sigmaSFactor,this.#t.sigmaR,this.#t.kernelSize),h=this.#h(c),d=this.#n(l,a,o,h);return this.processDrawnLines({lines:{curves:d,width:a,height:o},pageWidth:e,pageHeight:s,rotation:i,innerMargin:r,mustSmooth:!0,areContours:!0})}static processDrawnLines({lines:t,pageWidth:e,pageHeight:s,rotation:i,innerMargin:r,mustSmooth:n,areContours:a}){if(i%180!==0)[e,s]=[s,e];let{curves:o,width:l,height:c}=t,h=t.thickness??0,d=[],u=Math.min(e/l,s/c),f=u/e,p=u/s,g=[];for(let{points:v}of o){let y=n?this.#o(v):v;if(!y)continue;g.push(y);let b=y.length,_=new Float32Array(b),w=new Float32Array(3*(b===2?2:b-2));if(d.push({line:w,points:_}),b===2){_[0]=y[0]*f,_[1]=y[1]*p,w.set([NaN,NaN,NaN,NaN,_[0],_[1]],0);continue}let[A,x,E,T]=y;A*=f,x*=p,E*=f,T*=p,_.set([A,x,E,T],0),w.set([NaN,NaN,NaN,NaN,A,x],0);for(let k=4;k<b;k+=2){let C=_[k]=y[k]*f,R=_[k+1]=y[k+1]*p;w.set(H.createBezierPoints(A,x,E,T,C,R),(k-2)*3),[A,x,E,T]=[E,T,C,R]}}if(d.length===0)return null;let m=a?new ti:new es;return m.build(d,e,s,1,i,a?0:h,r),{outline:m,newCurves:g,areContours:a,thickness:h,width:l,height:c}}static async compressSignature({outlines:t,areContours:e,thickness:s,width:i,height:r}){let n=1/0,a=-1/0,o=0;for(let v of t){o+=v.length;for(let y=2,b=v.length;y<b;y++){let _=v[y]-v[y-2];n=Math.min(n,_),a=Math.max(a,_)}}let l;if(n>=-128&&a<=127)l=Int8Array;else if(n>=-32768&&a<=32767)l=Int16Array;else l=Int32Array;let c=t.length,h=Ls+ls*c,d=new Uint32Array(h),u=0;d[u++]=h*Uint32Array.BYTES_PER_ELEMENT+(o-2*c)*l.BYTES_PER_ELEMENT,d[u++]=0,d[u++]=i,d[u++]=r,d[u++]=e?0:1,d[u++]=Math.max(0,Math.floor(s??0)),d[u++]=c,d[u++]=l.BYTES_PER_ELEMENT;for(let v of t)d[u++]=v.length-2,d[u++]=v[0],d[u++]=v[1];let f=new CompressionStream("deflate-raw"),p=f.writable.getWriter();await p.ready,p.write(d);let g=l.prototype.constructor;for(let v of t){let y=new g(v.length-2);for(let b=2,_=v.length;b<_;b++)y[b-2]=v[b]-v[b-2];p.write(y)}return p.close(),(await new Response(f.readable).bytes()).toBase64()}static async decompressSignature(t){try{let e=Uint8Array.fromBase64(t),{readable:s,writable:i}=new DecompressionStream("deflate-raw"),r=i.getWriter();await r.ready,r.write(e).then(async()=>{await r.ready,await r.close()}).catch(()=>{});let n=null,a=0;for await(let y of s)n||=new Uint8Array(new Uint32Array(y.buffer,0,4)[0]),n.set(y,a),a+=y.length;let o=new Uint32Array(n.buffer,0,n.length>>2),l=o[1];if(l!==0)throw Error(`Invalid version: ${l}`);let c=o[2],h=o[3],d=o[4]===0,u=o[5],f=o[6],p=o[7],g=[],m=(Ls+ls*f)*Uint32Array.BYTES_PER_ELEMENT,v;switch(p){case Int8Array.BYTES_PER_ELEMENT:v=new Int8Array(n.buffer,m);break;case Int16Array.BYTES_PER_ELEMENT:v=new Int16Array(n.buffer,m);break;case Int32Array.BYTES_PER_ELEMENT:v=new Int32Array(n.buffer,m);break}a=0;for(let y=0;y<f;y++){let b=o[ls*y+Ls],_=new Float32Array(b+2);g.push(_);for(let w=0;w<ls-1;w++)_[w]=o[ls*y+Ls+w+1];for(let w=0;w<b;w++)_[w+2]=_[w]+v[a++]}return{areContours:d,thickness:u,outlines:g,width:c,height:h}}catch(e){return W(`decompressSignature: ${e}`),null}}}class Wr extends Ni{constructor(){super();super.updateProperties({fill:U._defaultLineColor,"stroke-width":0})}clone(){let t=new Wr;return t.updateAll(this),t}}class Xr extends ji{constructor(t){super(t);super.updateProperties({stroke:U._defaultLineColor,"stroke-width":1})}clone(){let t=new Xr(this._viewParameters);return t.updateAll(this),t}}class oe extends et{#t=!1;#e=null;#s=null;#i=null;#r=!1;static _type="signature";static _editorType=K.SIGNATURE;static _defaultDrawingOptions=null;constructor(t){super({...t,mustBeCommitted:!0,name:"signatureEditor"});this._willKeepAspectRatio=!0,this.#s=t.signatureData||null,this.#e=null,this.defaultL10nId="pdfjs-editor-signature-editor1"}static initialize(t,e){U.initialize(t,e),this._defaultDrawingOptions=new Wr,this._defaultDrawnSignatureOptions=new Xr(e.viewParameters)}static getDefaultDrawingOptions(t){let e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!1}static get typesMap(){return L(this,"typesMap",new Map)}static get isDrawer(){return!1}get telemetryFinalData(){return{type:"signature",hasDescription:!!this.#e}}static computeTelemetryFinalData(t){let e=t.get("hasDescription");return{hasAltText:e.get(!0)??0,hasNoAltText:e.get(!1)??0}}get isResizable(){return!0}onceAdded(t){this.#r=this._drawId===null,super.onceAdded(t)}onScaleChanging(){if(this._drawId===null)return;super.onScaleChanging()}render(){if(this.div)return this.div;let t,e,{_isCopy:s}=this;if(s)this._isCopy=!1,t=this.x,e=this.y;if(super.render(),this._drawId===null)if(this.#s){let{lines:i,mustSmooth:r,areContours:n,description:a,uuid:o,heightInPage:l}=this.#s,{rawDims:{pageWidth:c,pageHeight:h},rotation:d}=this.parent.viewport,u=Oe.processDrawnLines({lines:i,pageWidth:c,pageHeight:h,rotation:d,innerMargin:oe._INNER_MARGIN,mustSmooth:r,areContours:n});this.addSignature(u,l,a,o)}else this.div.setAttribute("data-l10n-args",JSON.stringify({description:""})),this.div.hidden=!0,this._uiManager.getSignature(this);else this.div.setAttribute("data-l10n-args",JSON.stringify({description:this.#e||""}));if(s)this._isCopy=!0,this._moveAfterPaste(t,e);return this.div}setUuid(t){this.#i=t,this.addEditToolbar()}getUuid(){return this.#i}get description(){return this.#e}set description(t){if(this.#e=t,!this.div)return;this.div.setAttribute("data-l10n-args",JSON.stringify({description:t})),super.addEditToolbar().then((e)=>{e?.updateEditSignatureButton(t)})}getSignaturePreview(){let{newCurves:t,areContours:e,thickness:s,width:i,height:r}=this.#s,n=Math.max(i,r),a=Oe.processDrawnLines({lines:{curves:t.map((o)=>({points:o})),thickness:s,width:i,height:r},pageWidth:n,pageHeight:n,rotation:0,innerMargin:0,mustSmooth:!1,areContours:e});return{areContours:e,outline:a.outline}}get toolbarButtons(){return this._uiManager.signatureManager?[["editSignature",this._uiManager.signatureManager]]:super.toolbarButtons}addSignature(t,e,s,i){let{x:r,y:n}=this,{outline:a}=this.#s=t;this.#t=a instanceof ti,this.description=s;let o;if(this.#t)o=oe.getDefaultDrawingOptions();else o=oe._defaultDrawnSignatureOptions.clone(),o.updateProperties({"stroke-width":a.thickness});this._addOutlines({drawOutlines:a,drawingOptions:o});let[,l]=this.pageDimensions,c=e/l;if(c=c>=1?0.5:c,this.width*=c/this.height,this.width>=1)c*=0.9/this.width,this.width=0.9;if(this.height=c,this.setDims(),this.x=r,this.y=n,this.center(),this._onResized(),this.onScaleChanging(),this.rotate(),this._uiManager.addToAnnotationStorage(this),this.setUuid(i),this._reportTelemetry({action:"pdfjs.signature.inserted",data:{hasBeenSaved:!!i,hasDescription:!!s}}),this.div.hidden=!1,this.#r)this.#r=!1,this.parent.addUndoableEditor(this)}getFromImage(t){let{rawDims:{pageWidth:e,pageHeight:s},rotation:i}=this.parent.viewport;return Oe.process(t,e,s,i,oe._INNER_MARGIN)}getFromText(t,e){let{rawDims:{pageWidth:s,pageHeight:i},rotation:r}=this.parent.viewport;return Oe.extractContoursFromText(t,e,s,i,r,oe._INNER_MARGIN)}getDrawnSignature(t){let{rawDims:{pageWidth:e,pageHeight:s},rotation:i}=this.parent.viewport;return Oe.processDrawnLines({lines:t,pageWidth:e,pageHeight:s,rotation:i,innerMargin:oe._INNER_MARGIN,mustSmooth:!1,areContours:!1})}createDrawingOptions({areContours:t,thickness:e}){if(t)this._drawingOptions=oe.getDefaultDrawingOptions();else this._drawingOptions=oe._defaultDrawnSignatureOptions.clone(),this._drawingOptions.updateProperties({"stroke-width":e})}serialize(t=!1){if(this.isEmpty())return null;let{lines:e,points:s}=this.serializeDraw(t),{_drawingOptions:{"stroke-width":i}}=this,r=Object.assign(super.serialize(t),{isSignature:!0,areContours:this.#t,color:[0,0,0],thickness:this.#t?0:i});if(this.addComment(r),t)r.paths={lines:e,points:s},r.uuid=this.#i,r.isCopy=!0;else r.lines=e;if(this.#e)r.accessibilityData={type:"Figure",alt:this.#e};return r}static deserializeDraw(t,e,s,i,r,n){if(n.areContours)return ti.deserialize(t,e,s,i,r,n);return es.deserialize(t,e,s,i,r,n)}static async deserialize(t,e,s){let i=await super.deserialize(t,e,s);return i.#t=t.areContours,i.description=t.accessibilityData?.alt||"",i.#i=t.uuid,i}}class Go extends U{#t=null;#e=null;#s=null;#i=null;#r=null;#n="";#a=null;#o=!1;#l=null;#c=!1;#u=!1;static _type="stamp";static _editorType=K.STAMP;constructor(t){super({...t,name:"stampEditor"});this.#i=t.bitmapUrl,this.#r=t.bitmapFile,this.defaultL10nId="pdfjs-editor-stamp-editor"}static initialize(t,e){U.initialize(t,e)}static isHandlingMimeForPasting(t){return Zi.has(t)}static paste(t,e){e.pasteEditor({mode:K.STAMP},{bitmapFile:t.getAsFile()})}altTextFinish(){if(this._uiManager.useNewAltTextFlow)this.div.hidden=!1;super.altTextFinish()}get telemetryFinalData(){return{type:"stamp",hasAltText:!!this.altTextData?.altText}}static computeTelemetryFinalData(t){let e=t.get("hasAltText");return{hasAltText:e.get(!0)??0,hasNoAltText:e.get(!1)??0}}#h(t,e=!1){if(!t){this.remove();return}if(this.#t=t.bitmap,!e)this.#e=t.id,this.#c=t.isSvg;if(t.file)this.#n=t.file.name;this.#m()}#f(){if(this.#s=null,this._uiManager.enableWaiting(!1),!this.#a)return;if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#t){this.addEditToolbar().then(()=>{this._editToolbar.hide(),this._uiManager.editAltText(this,!0)});return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#t){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}async mlGuessAltText(t=null,e=!0){if(this.hasAltTextData())return null;let{mlManager:s}=this._uiManager;if(!s)throw Error("No ML.");if(!await s.isEnabledFor("altText"))throw Error("ML isn't enabled for alt text.");let{data:i,width:r,height:n}=t||this.copyCanvas(null,null,!0).imageData,a=await s.guess({name:"altText",request:{data:i,width:r,height:n,channels:i.length/(r*n)}});if(!a)throw Error("No response from the AI service.");if(a.error)throw Error("Error from the AI service.");if(a.cancel)return null;if(!a.output)throw Error("No valid response from the AI service.");let o=a.output;if(await this.setGuessedAltText(o),e&&!this.hasAltTextData())this.altTextData={alt:o,decorative:!1};return o}#p(){if(this.#e){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(this.#e).then((s)=>this.#h(s,!0)).finally(()=>this.#f());return}if(this.#i){let s=this.#i;this.#i=null,this._uiManager.enableWaiting(!0),this.#s=this._uiManager.imageManager.getFromUrl(s).then((i)=>this.#h(i)).finally(()=>this.#f());return}if(this.#r){let s=this.#r;this.#r=null,this._uiManager.enableWaiting(!0),this.#s=this._uiManager.imageManager.getFromFile(s).then((i)=>this.#h(i)).finally(()=>this.#f());return}let t=document.createElement("input");t.type="file",t.accept=Zi.keys().join(",");let e=this._uiManager._signal;this.#s=new Promise((s)=>{t.addEventListener("change",async()=>{if(!t.files||t.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);let i=await this._uiManager.imageManager.getFromFile(t.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),this.#h(i)}s()},{signal:e}),t.addEventListener("cancel",()=>{this.remove(),s()},{signal:e})}).finally(()=>this.#f()),t.click()}remove(){if(this.#e){if(this.#t=null,this._uiManager.imageManager.deleteId(this.#e),this.#a?.remove(),this.#a=null,this.#l)clearTimeout(this.#l),this.#l=null}super.remove()}rebuild(){if(!this.parent){if(this.#e)this.#p();return}if(super.rebuild(),this.div===null)return;if(this.#e&&this.#a===null)this.#p();if(!this.isAttachedToDOM)this.parent.add(this)}onceAdded(t){if(this._isDraggable=!0,t)this.div.focus()}isEmpty(){return!(this.#s||this.#t||this.#i||this.#r||this.#e||this.#o)}get toolbarButtons(){return[["altText",this.createAltText()]]}get isResizable(){return!0}render(){if(this.div)return this.div;let t,e;if(this._isCopy)t=this.x,e=this.y;if(super.render(),this.div.hidden=!0,this.createAltText(),!this.#o)if(this.#t)this.#m();else this.#p();if(this._isCopy)this._moveAfterPaste(t,e);return this._uiManager.addShouldRescale(this),this.div}setCanvas(t,e){let{id:s,bitmap:i}=this._uiManager.imageManager.getFromCanvas(t,e);if(e.remove(),s&&this._uiManager.imageManager.isValidId(s)){if(this.#e=s,i)this.#t=i;this.#o=!1,this.#m()}}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;if(this.#l!==null)clearTimeout(this.#l);let t=200;this.#l=setTimeout(()=>{this.#l=null,this.#g()},t)}#m(){let{div:t}=this,{width:e,height:s}=this.#t,[i,r]=this.pageDimensions,n=0.75;if(this.width)e=this.width*i,s=this.height*r;else if(e>0.75*i||s>0.75*r){let o=Math.min(0.75*i/e,0.75*r/s);e*=o,s*=o}this._uiManager.enableWaiting(!1);let a=this.#a=document.createElement("canvas");if(a.setAttribute("role","img"),this.addContainer(a),this.width=e/i,this.height=s/r,this.setDims(),this._initialOptions?.isCentered)this.center();else this.fixAndSetPosition();if(this._initialOptions=null,!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)t.hidden=!1;if(this.#g(),!this.#u)this.parent.addUndoableEditor(this),this.#u=!0;if(this._reportTelemetry({action:"inserted_image"}),this.#n)this.div.setAttribute("aria-description",this.#n);if(!this.annotationElementId)this._uiManager.a11yAlert(U._l10nAlert.stamp)}copyCanvas(t,e,s=!1){t||=224;let{width:i,height:r}=this.#t,n=new Kt,a=this.#t,o=i,l=r,c=null;if(e){if(i>e||r>e){let w=Math.min(e/i,e/r);o=Math.floor(i*w),l=Math.floor(r*w)}c=document.createElement("canvas");let d=c.width=Math.ceil(o*n.sx),u=c.height=Math.ceil(l*n.sy);if(!this.#c)a=this.#d(d,u);let f=c.getContext("2d");f.filter=this._uiManager.hcmFilter;let p="white",g="#cfcfd8";if(this._uiManager.hcmFilter!=="none")g="black";else if(ca.isDarkMode)p="#8f8f9d",g="#42414d";let m=15,v=m*n.sx,y=m*n.sy,b=new OffscreenCanvas(v*2,y*2),_=b.getContext("2d");_.fillStyle=p,_.fillRect(0,0,v*2,y*2),_.fillStyle=g,_.fillRect(0,0,v,y),_.fillRect(v,y,v,y),f.fillStyle=f.createPattern(b,"repeat"),f.fillRect(0,0,d,u),f.drawImage(a,0,0,a.width,a.height,0,0,d,u)}let h=null;if(s){let d,u;if(n.symmetric&&a.width<t&&a.height<t)d=a.width,u=a.height;else if(a=this.#t,i>t||r>t){let g=Math.min(t/i,t/r);if(d=Math.floor(i*g),u=Math.floor(r*g),!this.#c)a=this.#d(d,u)}let p=new OffscreenCanvas(d,u).getContext("2d",{willReadFrequently:!0});p.drawImage(a,0,0,a.width,a.height,0,0,d,u),h={width:d,height:u,data:p.getImageData(0,0,d,u).data}}return{canvas:c,width:o,height:l,imageData:h}}#d(t,e){let{width:s,height:i}=this.#t,r=s,n=i,a=this.#t;while(r>2*t||n>2*e){let o=r,l=n;if(r>2*t)r=Math.ceil(r/2);if(n>2*e)n=Math.ceil(n/2);let c=new OffscreenCanvas(r,n);c.getContext("2d").drawImage(a,0,0,o,l,0,0,r,n),a=c.transferToImageBitmap()}return a}#g(){let[t,e]=this.parentDimensions,{width:s,height:i}=this,r=new Kt,n=Math.ceil(s*t*r.sx),a=Math.ceil(i*e*r.sy),o=this.#a;if(!o||o.width===n&&o.height===a)return;o.width=n,o.height=a;let l=this.#c?this.#t:this.#d(n,a),c=o.getContext("2d");c.filter=this._uiManager.hcmFilter,c.drawImage(l,0,0,l.width,l.height,0,0,n,a)}#v(t){if(t){if(this.#c){let i=this._uiManager.imageManager.getSvgUrl(this.#e);if(i)return i}let e=document.createElement("canvas");return{width:e.width,height:e.height}=this.#t,e.getContext("2d").drawImage(this.#t,0,0),e.toDataURL()}if(this.#c){let[e,s]=this.pageDimensions,i=Math.round(this.width*e*Le.PDF_TO_CSS_UNITS),r=Math.round(this.height*s*Le.PDF_TO_CSS_UNITS),n=new OffscreenCanvas(i,r);return n.getContext("2d").drawImage(this.#t,0,0,this.#t.width,this.#t.height,0,0,i,r),n.transferToImageBitmap()}return structuredClone(this.#t)}static async deserialize(t,e,s){let i=null,r=!1;if(t instanceof jr){let{data:{rect:p,rotation:g,id:m,structParent:v,popupRef:y,richText:b,contentsObj:_,creationDate:w,modificationDate:A},container:x,parent:{page:{pageNumber:E}},canvas:T}=t,k,C;if(T)delete t.canvas,{id:k,bitmap:C}=s.imageManager.getFromCanvas(x.id,T),T.remove();else r=!0,t._hasNoCanvas=!0;let R=(await e._structTree.getAriaAttributes(`${Ye}${m}`))?.get("aria-label")||"";i=t={annotationType:K.STAMP,bitmapId:k,bitmap:C,pageIndex:E-1,rect:p.slice(0),rotation:g,annotationElementId:m,id:m,deleted:!1,accessibilityData:{decorative:!1,altText:R},isSvg:!1,structParent:v,popupRef:y,richText:b,comment:_?.str||null,creationDate:w,modificationDate:A}}let n=await super.deserialize(t,e,s),{rect:a,bitmap:o,bitmapUrl:l,bitmapId:c,isSvg:h,accessibilityData:d}=t;if(r)s.addMissingCanvas(t.id,n),n.#o=!0;else if(c&&s.imageManager.isValidId(c)){if(n.#e=c,o)n.#t=o}else n.#i=l;n.#c=h;let[u,f]=n.pageDimensions;if(n.width=(a[2]-a[0])/u,n.height=(a[3]-a[1])/f,d)n.altTextData=d;if(n._initialData=i,t.comment)n.setCommentData(t);return n.#u=!!i,n}serialize(t=!1,e=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let s=Object.assign(super.serialize(t),{bitmapId:this.#e,isSvg:this.#c});if(this.addComment(s),t)return s.bitmapUrl=this.#v(!0),s.accessibilityData=this.serializeAltText(!0),s.isCopy=!0,s;let{decorative:i,altText:r}=this.serializeAltText(!1);if(!i&&r)s.accessibilityData={type:"Figure",alt:r};if(this.annotationElementId){let a=this.#y(s);if(a.isSame)return null;if(a.isSameAltText)delete s.accessibilityData;else{let o=this._initialData.structParent??-1;if(s.accessibilityData)s.accessibilityData.structParent=o;else if(o>=0)s.accessibilityData={type:"Figure",alt:"",structParent:o}}return s.id=this.annotationElementId,delete s.bitmapId,s}if(e===null)return s;e.stamps||=new Map;let n=this.#c?(s.rect[2]-s.rect[0])*(s.rect[3]-s.rect[1]):null;if(!e.stamps.has(this.#e))e.stamps.set(this.#e,{area:n,serialized:s}),s.bitmap=this.#v(!1);else if(this.#c){let a=e.stamps.get(this.#e);if(n>a.area)a.area=n,a.serialized.bitmap.close(),a.serialized.bitmap=this.#v(!1)}return s}#y(t){let{pageIndex:e,accessibilityData:{altText:s}}=this._initialData,i=t.pageIndex===e,r=(t.accessibilityData?.alt||"")===s;return{isSame:!this.hasEditedComment&&!this._hasBeenMoved&&!this._hasBeenResized&&i&&r,isSameAltText:r}}renderAnnotationElement(t){if(this.deleted)return t.hide(),null;return t.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null}}class fe{#t;#e=!1;#s=null;#i=null;#r=null;#n=new Map;#a=!1;#o=!1;#l=!1;#c=null;#u=null;#h=null;#f=null;#p=null;#m=-1;#d;static _initialized=!1;static#g=new Map([Pt,Vr,Go,ie,oe].map((t)=>[t._editorType,t]));constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:r,annotationLayer:n,drawLayer:a,textLayer:o,viewport:l,l10n:c}){let h=[...fe.#g.values()];if(!fe._initialized){fe._initialized=!0;for(let d of h)d.initialize(c,t)}t.registerEditorTypes(h),this.#d=t,this.pageIndex=e,this.div=s,this.#t=r,this.#s=n,this.viewport=l,this.#h=o,this.drawLayer=a,this._structTree=i,this.#d.addLayer(this)}get isEmpty(){return this.#n.size===0}get isInvisible(){return this.isEmpty&&this.#d.getMode()===K.NONE}updateToolbar(t){this.#d.updateToolbar(t)}updateMode(t=this.#d.getMode()){switch(this.#S(),t){case K.NONE:this.div.classList.toggle("nonEditing",!0),this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case K.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case K.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);let{classList:e}=this.div;if(e.toggle("nonEditing",!1),t===K.POPUP)e.toggle("commentEditing",!0);else{e.toggle("commentEditing",!1);for(let s of fe.#g.values())e.toggle(`${s._type}Editing`,t===s._editorType)}this.div.hidden=!1}hasTextLayer(t){return t===this.#h?.div}setEditingState(t){this.#d.setEditingState(t)}addCommands(t){this.#d.addCommands(t)}cleanUndoStack(t){this.#d.cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){this.#s?.togglePointerEvents(t)}get#v(){return this.#n.size!==0?this.#n.values():this.#d.getEditors(this.pageIndex)}async enable(){this.#l=!0,this.div.tabIndex=0,this.togglePointerEvents(!0),this.div.classList.toggle("nonEditing",!1),this.#p?.abort(),this.#p=null;let t=new Set;for(let s of this.#v)if(s.enableEditing(),s.show(!0),s.annotationElementId)this.#d.removeChangedExistingAnnotation(s),t.add(s.annotationElementId);let e=this.#s;if(e)for(let s of e.getEditableAnnotations()){if(s.hide(),this.#d.isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;let i=await this.deserialize(s);if(!i)continue;this.addOrRebuild(i),i.enableEditing()}this.#l=!1,this.#d._eventBus.dispatch("editorsrendered",{source:this,pageNumber:this.pageIndex+1})}disable(){if(this.#o=!0,this.div.tabIndex=-1,this.togglePointerEvents(!1),this.div.classList.toggle("nonEditing",!0),this.#h&&!this.#p){this.#p=new AbortController;let i=this.#d.combinedSignal(this.#p);this.#h.div.addEventListener("pointerdown",(r)=>{let{clientX:a,clientY:o,timeStamp:l}=r,c=this.#m;if(l-c>500){this.#m=l;return}this.#m=-1;let{classList:h}=this.div;h.toggle("getElements",!0);let d=document.elementsFromPoint(a,o);if(h.toggle("getElements",!1),!this.div.contains(d[0]))return;let u,f=new RegExp(`^${qe}[0-9]+$`);for(let g of d)if(f.test(g.id)){u=g.id;break}if(!u)return;let p=this.#n.get(u);if(p?.annotationElementId===null)Tt(r),p.dblclick(r)},{signal:i,capture:!0})}let t=this.#s,e=[];if(t){let i=new Map,r=new Map;for(let n of this.#v){if(n.disableEditing(),!n.annotationElementId){e.push(n);continue}if(n.serialize()!==null){i.set(n.annotationElementId,n);continue}else r.set(n.annotationElementId,n);this.getEditableAnnotation(n.annotationElementId)?.show(),n.remove()}for(let n of t.getEditableAnnotations()){let{id:a}=n.data;if(this.#d.isDeletedAnnotationElement(a)){n.updateEdited({deleted:!0});continue}let o=r.get(a);if(o){o.resetAnnotationElement(n),o.show(!1),n.show();continue}if(o=i.get(a),o){if(this.#d.addChangedExistingAnnotation(o),o.renderAnnotationElement(n))o.show(!1)}n.show()}}if(this.#S(),this.isEmpty)this.div.hidden=!0;let{classList:s}=this.div;for(let i of fe.#g.values())s.remove(`${i._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),t?.updateFakeAnnotations(e),this.#o=!1}getEditableAnnotation(t){return this.#s?.getEditableAnnotation(t)||null}setActiveEditor(t){if(this.#d.getActive()===t)return;this.#d.setActiveEditor(t)}enableTextSelection(){if(this.div.tabIndex=-1,this.#h?.div&&!this.#f){this.#f=new AbortController;let t=this.#d.combinedSignal(this.#f);this.#h.div.addEventListener("pointerdown",this.#y.bind(this),{signal:t}),this.#h.div.classList.add("highlighting")}}disableTextSelection(){if(this.div.tabIndex=0,this.#h?.div&&this.#f)this.#f.abort(),this.#f=null,this.#h.div.classList.remove("highlighting")}#y(t){this.#d.unselectAll();let{target:e}=t;if(e===this.#h.div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent")||e.classList.contains("textLayerImages")||e.classList.contains("textLayerImagePlaceholder"))&&this.#h.div.contains(e)){let{isMac:s}=lt.platform;if(t.button!==0||t.ctrlKey&&s)return;this.#d.showAllEditors("highlight",!0,!0),ie.startDrawing(this,this.#d,this.#d.direction==="ltr",t),t.preventDefault()}}enableClick(){if(this.#i)return;this.#i=new AbortController;let t=this.#d.combinedSignal(this.#i);this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});let e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){this.#i?.abort(),this.#i=null}attach(t){this.#n.set(t.id,t);let{annotationElementId:e}=t;if(e&&this.#d.isDeletedAnnotationElement(e))this.#d.removeDeletedAnnotationElement(t)}detach(t){if(this.#n.delete(t.id),this.#t?.removePointerInTextLayer(t.contentDiv),!this.#o&&t.annotationElementId)this.#d.addDeletedAnnotationElement(t)}remove(t){this.detach(t),this.#d.removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){if(t.parent===this)return;if(t.parent&&t.annotationElementId)this.#d.addDeletedAnnotationElement(t),U.deleteAnnotationElement(t),t.annotationElementId=null;if(this.attach(t),t.parent?.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM)t.div.remove(),this.div.append(t.div)}add(t){if(t.parent===this&&t.isAttachedToDOM)return;if(this.changeParent(t),this.#d.addEditor(t),this.attach(t),!t.isAttachedToDOM){let e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!this.#l),this.#d.addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}moveEditorInDOM(t){if(!t.isAttachedToDOM)return;let{activeElement:e}=document;if(t.div.contains(e)&&!this.#r)t._focusEventsAllowed=!1,this.#r=setTimeout(()=>{if(this.#r=null,!t.div.contains(document.activeElement))t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this.#d._signal}),e.focus();else t._focusEventsAllowed=!0},0);t._structTreeParentId=this.#t?.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){if(t.needsToBeRebuilt())t.parent||=this,t.rebuild(),t.show();else this.add(t)}addUndoableEditor(t){let e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getEditorByUID(t){for(let e of this.#n.values())if(e.uid===t)return e;return null}get#b(){return fe.#g.get(this.#d.getMode())}combinedSignal(t){return this.#d.combinedSignal(t)}#_(t){let e=this.#b;return e?new e.prototype.constructor(t):null}canCreateNewEmptyEditor(){return this.#b?.canCreateNewEmptyEditor()}async pasteEditor(t,e){this.updateToolbar(t),await this.#d.updateMode(t.mode);let{offsetX:s,offsetY:i}=this.#A(),r=this.#d.getId(),n=this.#_({parent:this,id:r,x:s,y:i,uiManager:this.#d,isCentered:!0,...e});if(n)this.add(n)}async deserialize(t){return await fe.#g.get(t.annotationType??t.annotationEditorType)?.deserialize(t,this,this.#d)||null}createAndAddNewEditor(t,e,s={}){let i=this.#d.getId(),r=this.#_({parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:this.#d,isCentered:e,...s});if(r)this.add(r);return r}get boundingClientRect(){return this.div.getBoundingClientRect()}#A(){let{x:t,y:e,width:s,height:i}=this.boundingClientRect,r=Math.max(0,t),n=Math.max(0,e),a=Math.min(window.innerWidth,t+s),o=Math.min(window.innerHeight,e+i),l=(r+a)/2-t,c=(n+o)/2-e,[h,d]=this.viewport.rotation%180===0?[l,c]:[c,l];return{offsetX:h,offsetY:d}}addNewEditor(t={}){this.createAndAddNewEditor(this.#A(),!0,t)}setSelected(t){this.#d.setSelected(t)}toggleSelected(t){this.#d.toggleSelected(t)}unselect(t){this.#d.unselect(t)}pointerup(t){let{isMac:e}=lt.platform;if(t.button!==0||t.ctrlKey&&e)return;if(t.target!==this.div)return;if(!this.#a)return;if(this.#a=!1,this.#b?.isDrawer&&this.#b.supportMultipleDrawings)return;if(!this.#e){this.#e=!0;return}let s=this.#d.getMode();if(s===K.STAMP||s===K.POPUP||s===K.SIGNATURE){this.#d.unselectAll();return}this.createAndAddNewEditor(t,!1)}pointerdown(t){if(this.#d.getMode()===K.HIGHLIGHT)this.enableTextSelection();if(this.#a){this.#a=!1;return}let{isMac:e}=lt.platform;if(t.button!==0||t.ctrlKey&&e)return;if(t.target!==this.div)return;if(this.#a=!0,this.#b?.isDrawer){this.startDrawingSession(t);return}let s=this.#d.getActive();this.#e=!s||s.isEmpty()}startDrawingSession(t){if(this.div.focus({preventScroll:!0}),this.#c){this.#b.startDrawing(this,this.#d,!1,t);return}this.#d.setCurrentDrawingSession(this),this.#c=new AbortController;let e=this.#d.combinedSignal(this.#c);this.div.addEventListener("blur",({relatedTarget:s})=>{if(s&&!this.div.contains(s))this.#u=null,this.commitOrRemove()},{signal:e}),this.#b.startDrawing(this,this.#d,!1,t)}pause(t){if(t){let{activeElement:e}=document;if(this.div.contains(e))this.#u=e;return}if(this.#u)setTimeout(()=>{this.#u?.focus(),this.#u=null},0)}endDrawingSession(t=!1){if(!this.#c)return null;return this.#d.setCurrentDrawingSession(null),this.#c.abort(),this.#c=null,this.#u=null,this.#b.endDrawing(t)}findNewParent(t,e,s){let i=this.#d.findParent(e,s);if(i===null||i===this)return!1;return i.changeParent(t),!0}commitOrRemove(){if(this.#c)return this.endDrawingSession(),!0;return!1}onScaleChanging(){if(!this.#c)return;this.#b.onScaleChangingWhenDrawing(this)}destroy(){if(this.commitOrRemove(),this.#d.getActive()?.parent===this)this.#d.commitOrRemove(),this.#d.setActiveEditor(null);if(this.#r)clearTimeout(this.#r),this.#r=null;for(let t of this.#n.values())this.#t?.removePointerInTextLayer(t.contentDiv),t.setParent(null),t.isAttachedToDOM=!1,t.div.remove();this.div=null,this.#n.clear(),this.#d.removeLayer(this)}#S(){for(let t of this.#n.values())if(t.isEmpty())t.remove()}async render({viewport:t}){this.viewport=t,Ne(this.div,t);for(let e of this.#d.getEditors(this.pageIndex))this.add(e),e.rebuild();await this.#d.findClonesForPage(this),this.div.hidden=this.isEmpty,this.updateMode()}update({viewport:t}){this.#d.commitOrRemove(),this.#S();let e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,Ne(this.div,{rotation:s}),e!==s)for(let i of this.#n.values())i.rotate(s)}get pageDimensions(){let{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return this.#d.viewParameters.realScale}}vc();function Nh(t,e){if(t===e)return 0;return t.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1}function Ns(t){if(!t)return null;return t.nodeType===Node.ELEMENT_NODE?t.closest(".textLayer"):t.parentElement?.closest(".textLayer")||null}function Bh(t,e,s,i){if(t===s)return e<=i;let r=t.compareDocumentPosition(s);if(r&Node.DOCUMENT_POSITION_FOLLOWING)return!0;if(r&Node.DOCUMENT_POSITION_PRECEDING)return!1;return null}function Cn(t,e,s){if(t.nodeType!==Node.ELEMENT_NODE||!t.classList.contains("textLayer")||e!==t.childNodes.length)return{container:t,offset:e};let i=t.lastChild;if(i?.nodeType===Node.ELEMENT_NODE&&i.classList.contains("endOfContent"))i=i.previousSibling;if(!i||!s.contains(i))return null;return i.nodeType===Node.TEXT_NODE?{container:i,offset:i.textContent.length}:{container:i,offset:i.childNodes.length}}class Y{#t=null;#e=new Map;#s=null;#i=null;#r=null;#n=null;#a=new Map;static#o=0;static#l=0;static#c=null;static#u=new Set;static#h=!1;static#f=new Set;static#p=new WeakMap;constructor({filterFactory:t=null,pageColors:e=null,pageIndex:s,textLayer:i=null}){if(this.pageIndex=s,this.#i=t,this.#r=e,i){let r=Y.#p.get(i);if(r?.selectionDiv)r.selectionDiv.remove(),Y.#u.delete(r.selectionDiv);if(Y.#p.set(i,{drawLayer:this}),Y.#f.add(i),this.#s=i,this.#n=new MutationObserver((n)=>{if(!this.#t||!this.#s?.isConnected||!Y.#d())return;for(let{addedNodes:a}of n)for(let o of a)if(o.nodeType===Node.ELEMENT_NODE&&o.classList.contains("endOfContent")){Y.#v();return}}),this.#n.observe(i,{childList:!0}),Y.#c===null){Y.#c=new AbortController;let{signal:n}=Y.#c;document.addEventListener("selectionchange",Y.#v.bind(Y),{signal:n}),document.addEventListener("pointerdown",()=>{Y.#h=!0},{signal:n}),document.addEventListener("pointerup",()=>{Y.#h=!1},{signal:n}),window.addEventListener("blur",()=>{Y.#h=!1},{signal:n})}}}setParent(t){if(!this.#t){if(this.#t=t,this.#s?.isConnected&&Y.#d())Y.#v();return}if(this.#t!==t){if(this.#e.size>0)for(let e of this.#e.values())e.remove(),t.append(e);this.#t=t}}static#m(t){let e=this.#p.get(t);if(!e?.selectionDiv)return;e.selectionDiv.remove(),this.#u.delete(e.selectionDiv),e.selectionDiv=null,e.path=null}static#d(){let t=document.getSelection();return!!t&&!t.isCollapsed}static#g(){return this.#f.keys().filter((t)=>t.isConnected).toArray().sort(Nh)}static#v(){let t=document.getSelection();if(!t||t.isCollapsed){for(let n of this.#u)n.remove();this.#u.clear();return}let e=new WeakMap,s=this.#g(),i=[];for(let n=0,a=t.rangeCount;n<a;n++){let o=t.getRangeAt(n);if(o.collapsed)continue;let{startContainer:l,startOffset:c,endContainer:h,endOffset:d}=o,u=Ns(l),f=Ns(h),p=u===null,g=f===null;if(this.#h&&p!==g)return;if(t.rangeCount===1){let{anchorNode:y,anchorOffset:b,focusNode:_,focusOffset:w}=t,A=Ns(y),x=Ns(_),E=Bh(y,b,_,w);if(A&&x&&E!==null)if(E)l=y,c=b,u=A,h=_,d=w,f=x;else l=_,c=w,u=x,h=y,d=b,f=A}let m=s.filter((y)=>o.intersectsNode(y));if(m.length===0)continue;let v=!1;if(!u)u=m[0],l=u,c=0,v=!0;if(!f)f=m.at(-1),h=f,d=f.childNodes.length,v=!0;if(h.nodeType===Node.ELEMENT_NODE){if(h.classList.contains("endOfContent")){let y=h.previousSibling;if(!y)continue;h=y,d=y.nodeType===Node.TEXT_NODE?y.textContent.length:y.childNodes.length}else if(h.classList.contains("textLayer")&&h.childNodes.length===d){let y=Cn(h,d,f);if(!y)continue;h=y.container,d=y.offset}}if(l.nodeType===Node.ELEMENT_NODE){let y=Cn(l,c,u);if(!y)continue;l=y.container,c=y.offset}if(u===f&&!v&&m.includes(u)){i.push([o,u]);continue}for(let y of m){let b=y.firstChild;if(!b)continue;let _=document.createRange();if(y===u)_.setStart(l,c);else _.setStartBefore(b);if(y===f)_.setEnd(h,d);else{let w=y.lastChild;if(!w)continue;if(w.nodeType===Node.ELEMENT_NODE&&w.classList.contains("endOfContent")){let A=w.previousSibling;if(!A)continue;_.setEndAfter(A)}else _.setEndAfter(w)}if(!_.collapsed)i.push([_,y])}}let r=new Set(i.map((n)=>n[1]));for(let n of this.#f)if(!r.has(n))this.#m(n);for(let[n,a]of i){let o=Y.#p.get(a);if(!o)continue;let l=e.get(a);if(!l){let f=a.getBoundingClientRect();l=(p,g,m,v)=>({x:(p-f.x)/f.width,y:(g-f.y)/f.height,width:m/f.width,height:v/f.height}),e.set(a,l)}let c=[];for(let{x:f,y:p,width:g,height:m}of n.getClientRects()){if(g===0||m===0)continue;if({x:f,y:p,width:g,height:m}=l(f,p,g,m),g===1&&m===1)continue;c.push(`M${f} ${p} h${g} v${m} h-${g} Z`)}if(c.length===0)continue;let{drawLayer:h,selectionDiv:d,path:u}=o;if(!d){let f=`clip_selection_${Y.#l++}`;d=document.createElement("div"),d.className="selection",d.style.clipPath=`url(#${f})`;let p=h.#i?.createSelectionStyle(h.#r);if(p)for(let[v,y]of Object.entries(p))d.style.setProperty(v,y);let g=Y._svgFactory.create(1,1,!0);g.setAttribute("aria-hidden","true"),g.setAttribute("width","100%"),g.setAttribute("height","100%");let m=Y._svgFactory.createElement("clipPath");m.setAttribute("id",f),m.setAttribute("clipPathUnits","objectBoundingBox"),u=Y._svgFactory.createElement("path"),m.append(u),g.append(m),d.append(g),o.path=u,o.selectionDiv=d}if(h.#t&&d.parentNode!==h.#t)h.#t.append(d),this.#u.add(d);u.setAttribute("d",c.join(" "))}}static get _svgFactory(){return L(this,"_svgFactory",new Fi)}static#y(t,[e,s,i,r]){let{style:n}=t;n.top=`${100*s}%`,n.left=`${100*e}%`,n.width=`${100*i}%`,n.height=`${100*r}%`}#b(){let t=Y._svgFactory.create(1,1,!0);return this.#t.append(t),t.setAttribute("aria-hidden","true"),t}#_(t,e){let s=Y._svgFactory.createElement("clipPath");t.append(s);let i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");let r=Y._svgFactory.createElement("use");return s.append(r),r.setAttribute("href",`#${e}`),r.classList.add("clip"),i}#A(t,e){for(let[s,i]of Object.entries(e))if(i===null)t.removeAttribute(s);else t.setAttribute(s,i)}draw(t,e=!1,s=!1){let i=Y.#o++,r=this.#b(),n=Y._svgFactory.createElement("defs");r.append(n);let a=Y._svgFactory.createElement("path");n.append(a);let o=`path_${i}`;if(a.setAttribute("id",o),a.setAttribute("vector-effect","non-scaling-stroke"),e)this.#a.set(i,a);let l=s?this.#_(n,o):null,c=Y._svgFactory.createElement("use");return r.append(c),c.setAttribute("href",`#${o}`),this.updateProperties(r,t),this.#e.set(i,r),{id:i,clipPathId:`url(#${l})`}}drawOutline(t,e){let s=Y.#o++,i=this.#b(),r=Y._svgFactory.createElement("defs");i.append(r);let n=Y._svgFactory.createElement("path");r.append(n);let a=`path_${s}`;n.setAttribute("id",a),n.setAttribute("vector-effect","non-scaling-stroke");let o;if(e){let h=Y._svgFactory.createElement("mask");r.append(h),o=`mask_${s}`,h.setAttribute("id",o),h.setAttribute("maskUnits","objectBoundingBox");let d=Y._svgFactory.createElement("rect");h.append(d),d.setAttribute("width","1"),d.setAttribute("height","1"),d.setAttribute("fill","white");let u=Y._svgFactory.createElement("use");h.append(u),u.setAttribute("href",`#${a}`),u.setAttribute("stroke","none"),u.setAttribute("fill","black"),u.setAttribute("fill-rule","nonzero"),u.classList.add("mask")}let l=Y._svgFactory.createElement("use");if(i.append(l),l.setAttribute("href",`#${a}`),o)l.setAttribute("mask",`url(#${o})`);let c=l.cloneNode();return i.append(c),l.classList.add("mainOutline"),c.classList.add("secondaryOutline"),this.updateProperties(i,t),this.#e.set(s,i),s}finalizeDraw(t,e){this.#a.delete(t),this.updateProperties(t,e)}updateProperties(t,e){if(!e)return;let{root:s,bbox:i,rootClass:r,path:n}=e,a=typeof t==="number"?this.#e.get(t):t;if(!a)return;if(s)this.#A(a,s);if(i)Y.#y(a,i);if(r){let{classList:o}=a;for(let[l,c]of Object.entries(r))o.toggle(l,c)}if(n){let l=a.firstElementChild.firstElementChild;this.#A(l,n)}}updateParent(t,e){if(e===this)return;let s=this.#e.get(t);if(!s)return;e.#t.append(s),this.#e.delete(t),e.#e.set(t,s)}remove(t){if(this.#a.delete(t),this.#t===null)return;this.#e.get(t).remove(),this.#e.delete(t)}destroy(){this.#t=null;for(let t of this.#e.values())t.remove();if(this.#e.clear(),this.#a.clear(),this.#n?.disconnect(),this.#n=null,this.#s){if(Y.#p.get(this.#s)?.drawLayer===this){if(Y.#m(this.#s),Y.#p.delete(this.#s),Y.#f.delete(this.#s),Y.#f.size===0)Y.#c?.abort(),Y.#c=null,Y.#h=!1}this.#s=null}}}function Bs(t){return`${(t*100).toFixed(2)}%`}class ei{#t=[];#e=new Map;#s=null;#i=0;#r=0;#n=0;static#a=null;constructor(t,e,s,i){this.#i=t,this.#t=e,this.#r=s.rawDims.pageWidth,this.#n=s.rawDims.pageHeight,this.#s=i}render(){let t=document.createElement("div");t.className="textLayerImages";for(let e=0;e<this.#t.length;e+=6){let s=this.#o(this.#t.subarray(e,e+6));if(s)t.append(s)}return t.addEventListener("contextmenu",(e)=>{if(!(e.target instanceof HTMLCanvasElement))return;let s=e.target,i=this.#e.get(s);if(!i)return;let r=ei.#a?.deref();if(r===s)return;if(r)r.width=0,r.height=0;ei.#a=new WeakRef(s);let{inverseTransform:n,x1:a,y1:o,width:l,height:c}=i,h=this.#s(),d=Math.ceil(a*h.width),u=Math.ceil(o*h.height),f=Math.floor((a+l/this.#r)*h.width),p=Math.floor((o+c/this.#n)*h.height);s.width=f-d,s.height=p-u;let g=s.getContext("2d");g.setTransform(...n),g.translate(-d,-u),g.drawImage(h,0,0)}),t}#o([t,e,s,i,r,n]){let a=Math.hypot((r-t)*this.#r,(n-e)*this.#n),o=Math.hypot((s-t)*this.#r,(i-e)*this.#n);if(a<this.#i||o<this.#i)return null;let l=[(r-t)*this.#r/a,(n-e)*this.#n/a,(s-t)*this.#r/o,(i-e)*this.#n/o,0,0],c=O.inverseTransform(l),h=document.createElement("canvas");return h.className="textLayerImagePlaceholder",h.width=0,h.height=0,Object.assign(h.style,{opacity:0,position:"absolute",left:Bs(t),top:Bs(e),width:Bs(a/this.#r),height:Bs(o/this.#n),transformOrigin:"0% 0%",transform:`matrix(${l.join(",")})`}),this.#e.set(h,{inverseTransform:c,width:a,height:o,x1:t,y1:e}),h}}globalThis._pdfjsTestingUtils={HighlightOutliner:Qs};globalThis.pdfjsLib={AbortException:ve,AnnotationEditorLayer:fe,AnnotationEditorParamsType:st,AnnotationEditorType:K,AnnotationEditorUIManager:Se,AnnotationLayer:Ur,AnnotationMode:we,AnnotationType:yt,applyOpacity:qc,build:Fh,ColorPicker:Qt,createValidAbsoluteUrl:ra,CSSConstants:ha,DOMSVGFactory:Fi,DrawLayer:Y,FeatureTest:lt,fetchData:Sr,findContrastColor:Jc,getDocument:Rr,getFilenameFromUrl:th,getPdfFilenameFromUrl:eh,getRGB:Es,getRGBA:ts,getUuid:oa,GlobalWorkerOptions:Zt,ImageKind:js,InvalidPDFException:Vs,isDataScheme:Ei,isPdfFile:Er,isValidExplicitDest:oh,makeArr:Ze,makeMap:Ws,makeObj:qi,makeSet:Kc,MathClamp:pt,noContextMenu:re,normalizeUnicode:Xc,OPS:pe,OutputScale:Kt,PasswordException:zs,PasswordResponses:$c,PDFDataRangeTransport:Dr,PDFDateString:Xs,PDFWorker:Ft,PermissionFlag:Uc,PixelsPerInch:Le,RenderingCancelledException:Si,renderRichText:da,ResponseException:gs,setLayerDimensions:Ne,shadow:L,SignatureExtractor:Oe,stopEvent:Tt,SupportedImageMimeTypes:Zi,TextLayer:Lt,TextLayerImages:ei,TouchManager:Cr,updateUrlHash:na,Util:O,VerbosityLevel:bi,version:Rh,XfaLayer:Ar};var Ps={maxBytes:104857600,maxPages:2000,maxCanvasPixels:16000000,maxImageWidth:4096};var zo=(t)=>Object.assign(Error(t),{name:"PdfTooLargeError"});async function Gh(t,e,s){if(e.aborted)return null;Zt.workerSrc=new URL(s,import.meta.url).href;let i=Rr({data:new Uint8Array(t),verbosity:0,stopAtErrors:!0,enableXfa:!1,maxImageSize:Ps.maxCanvasPixels,canvasMaxAreaInBytes:Ps.maxCanvasPixels*4}),r=()=>void i.destroy();e.addEventListener("abort",r,{once:!0});let n=async()=>{e.removeEventListener("abort",r),await i.destroy()};try{let a=await i.promise;if(a.numPages>Ps.maxPages)throw zo(`PDF has more than ${Ps.maxPages} pages`);let o=[];for(let h=1;h<=a.numPages;h++){let{width:d,height:u}=(await a.getPage(h)).getViewport({scale:1});if(e.aborted)return await n(),null;o.push({width:d,height:u})}return{pages:o,draw:async(h,d,u)=>{let f=await a.getPage(h+1);if(u.aborted)return null;let p=f.getViewport({scale:d/f.getViewport({scale:1}).width}),g=document.createElement("canvas");try{g.width=Math.round(p.width),g.height=Math.round(p.height);let m=f.render({canvas:g,viewport:p}),v=()=>m.cancel();u.addEventListener("abort",v,{once:!0});try{await m.promise}finally{u.removeEventListener("abort",v)}let y=await new Promise((b,_)=>g.toBlob((w)=>w?b(w):_(Error("The page could not be drawn")),"image/png"));if(u.aborted)return null;return{url:URL.createObjectURL(y),width:g.width,height:g.height}}finally{g.width=0,g.height=0,f.cleanup()}},textLayer:async(h,d,u)=>{let f=await a.getPage(h+1);if(u.aborted)return;let p=f.getViewport({scale:1}),g=new Lt({textContentSource:f.streamTextContent(),container:d,viewport:p}),[m=0,v=0,y=0,b=0]=p.viewBox;d.style.width=`calc(var(--total-scale-factor) * ${y-m}px)`,d.style.height=`calc(var(--total-scale-factor) * ${b-v}px)`;let _=()=>g.cancel();u.addEventListener("abort",_,{once:!0});try{await g.render()}finally{u.removeEventListener("abort",_)}},close:n}}catch(a){if(await n(),e.aborted)return null;throw a}}export{Gh as openPdf};
57
+ `)){let r=document.createElement("div");r.append(i?document.createTextNode(i):document.createElement("br")),e.append(r)}return t.updateEdited({rect:this.getPDFRect(),popup:this._uiManager.hasCommentManager()||this.hasEditedComment?this.comment:{text:this.#t}}),e}resetAnnotationElement(t){super.resetAnnotationElement(t),t.resetEdited()}}class Ni{#t=Object.create(null);updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(!t)return;for(let[e,s]of Object.entries(t))if(!e.startsWith("_"))this.updateProperty(e,s)}updateSVGProperty(t,e){this.#t[t]=e}toSVGProperties(){let t=this.#t;return this.#t=Object.create(null),{root:t}}reset(){this.#t=Object.create(null)}updateAll(t=this){this.updateProperties(t)}clone(){at("Not implemented")}}class et extends U{#t=null;#e;_clipPathId=null;_colorPicker=null;_drawId=null;_drawOutlines=null;_focusDrawId=null;static _currentDrawId=-1;static _currentParent=null;static#s=null;static#i=null;static#r=null;static#n=null;static _INNER_MARGIN=3;constructor(t){super(t);this.#e=t.mustBeCommitted||!1,this._addOutlines(t)}onUpdatedColor(){this._colorPicker?.update(this.color),super.onUpdatedColor()}onUpdatedOpacity(){this._colorPicker?.updateOpacity?.(this.opacity)}_addOutlines(t){if(t.drawOutlines)this.#a(t),this.#m()}#a({drawOutlines:t,drawId:e,drawingOptions:s,clipPathId:i}){if(this._drawOutlines=t,this._drawingOptions||=s,!this.annotationElementId)this._uiManager.a11yAlert(U._l10nAlert[this.editorType]);if(e>=0)this._drawId=e,this._clipPathId=i??null,this.parent.drawLayer.finalizeDraw(e,t.defaultProperties),this.#l(this.parent);else this._drawId=this.#o(t,this.parent);this.#v(t.box)}#o(t,e){let{id:s,clipPathId:i}=e.drawLayer.draw(et._mergeSVGProperties(this._drawingOptions.toSVGProperties(),t.defaultSVGProperties),!1,this.constructor._hasClipPath);if(this.constructor._hasClipPath)this._clipPathId=i;return this.#l(e),s}#l(t){let e=this._drawOutlines.getFocusSVGProperties(this.#f);if(e)this._focusDrawId=t.drawLayer.drawOutline(e,this._drawOutlines.focusMustRemoveSelfIntersections)}#c(t=this.#f){if(this._focusDrawId===null)return;this.parent?.drawLayer.updateProperties(this._focusDrawId,this._drawOutlines.getFocusSVGProperties(t))}#u(t){if(this._focusDrawId!==null)this.parent?.drawLayer.updateProperties(this._focusDrawId,{rootClass:t})}#h(){let{parent:t,_drawId:e,_focusDrawId:s,_isVisible:i}=this;if(!t||e===null)return;let r={hidden:!i};if(t.drawLayer.updateProperties(e,{rootClass:r}),s!==null)t.drawLayer.updateProperties(s,{rootClass:r})}static _mergeSVGProperties(t,e){let s=new Set(Object.keys(t));for(let[i,r]of Object.entries(e))if(s.has(i))Object.assign(t[i],r);else t[i]=r;return t}static getDefaultDrawingOptions(t){at("Not implemented")}static get typesMap(){at("Not implemented")}static get isDrawer(){return!0}static get _hasClipPath(){return!1}static get _hasDrawClass(){return!0}static get supportMultipleDrawings(){return!1}get _drawRotation(){return this.rotation}get _opacityName(){return this.constructor.typesMap.get(this.opacityType)}get#f(){return(this.parentRotation-this._drawRotation+360)%360}static updateDefaultParams(t,e){let s=this.typesMap.get(t);if(s)this._defaultDrawingOptions.updateProperty(s,e);if(this._currentParent)et.#s.updateProperty(s,e),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties())}updateParams(t,e){let s=this.constructor.typesMap.get(t);if(s)this._updateProperty(t,s,e)}static get defaultPropertiesToUpdate(){let t=[],e=this._defaultDrawingOptions;for(let[s,i]of this.typesMap)t.push([s,e[i]]);return t}get propertiesToUpdate(){let t=[],{_drawingOptions:e}=this;for(let[s,i]of this.constructor.typesMap)t.push([s,e[i]]);return t}_updateProperty(t,e,s){let i=this._drawingOptions,r=i[e],n=(a)=>{i.updateProperty(e,a);let o=this._drawOutlines.updateProperty(e,a);if(o)this.#v(o);if(this.parent?.drawLayer.updateProperties(this._drawId,i.toSVGProperties()),t===this.colorType)this.onUpdatedColor();else if(t===this.opacityType)this.onUpdatedOpacity()};this.addCommands({cmd:n.bind(this,s),undo:n.bind(this,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:t,overwriteIfSameType:!0,keepUndo:!0})}_updateColorAndOpacity(t,e,s=this.colorAndOpacityType){let i=this.constructor.typesMap.get(this.colorType),r=this._opacityName,n=this._drawingOptions,a=n[i],o=n[r],l=(c,h)=>{n.updateProperty(i,c),n.updateProperty(r,h),this._drawOutlines.updateProperty(i,c),this._drawOutlines.updateProperty(r,h),this.parent?.drawLayer.updateProperties(this._drawId,n.toSVGProperties()),this.onUpdatedColor(),this.onUpdatedOpacity()};this.addCommands({cmd:l.bind(this,t,e),undo:l.bind(this,a,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:s,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,et._mergeSVGProperties(this._drawOutlines.getPathResizingSVGProperties(this.#g()),{bbox:this.#y()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,et._mergeSVGProperties(this._drawOutlines.getPathResizedSVGProperties(this.#g()),{bbox:this.#y()})),this.#c()}_onTranslating(t,e){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#y()})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,et._mergeSVGProperties(this._drawOutlines.getPathTranslatedSVGProperties(this.#g(),this.parentDimensions),{bbox:this.#y()}))}_onStartDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}get _mustBeDisabledOnCommit(){return!0}commit(){if(super.commit(),this._mustBeDisabledOnCommit)this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(t){if(!this.annotationElementId&&this._drawId!==null)this.parent.addUndoableEditor(this);if(this._isDraggable=!0,this.#e){if(this.#e=!1,this.commit(),this.parent.setSelected(this),t&&this.isOnScreen)this.div.focus()}}remove(){this._uiManager.removeShouldRescale(this),this.#p(),super.remove()}rebuild(){if(!this.parent)return;if(super.rebuild(),this.div===null)return;if(this.#m(),this.#v(this._drawOutlines.box),!this.isAttachedToDOM)this.parent.add(this)}setParent(t){let e=!1;if(this.parent&&!t)this._uiManager.removeShouldRescale(this),this.#p();else if(t)this._uiManager.addShouldRescale(this),this.#m(t),e=!this.parent&&this.div?.classList.contains("selectedEditor");if(super.setParent(t),this.#h(),e)this.select()}#p(){if(this._drawId===null||!this.parent)return;let{drawLayer:t}=this.parent;if(t.remove(this._drawId),this._drawId=null,this._focusDrawId!==null)t.remove(this._focusDrawId),this._focusDrawId=null;this._drawingOptions.reset()}#m(t=this.parent){if(this._drawId!==null&&this.parent===t)return;if(this._drawId!==null){let{drawLayer:e}=this.parent;if(e.updateParent(this._drawId,t.drawLayer),this._focusDrawId!==null)e.updateParent(this._focusDrawId,t.drawLayer);return}if(this._drawingOptions.updateAll(),this._drawId=this.#o(this._drawOutlines,t),this._clipPathId&&this.#t)this.#t.style.clipPath=this._clipPathId}#d([t,e,s,i]){let{parentDimensions:[r,n],_drawRotation:a}=this;switch(a){case 90:return[e,1-t,s*(n/r),i*(r/n)];case 180:return[1-t,1-e,s,i];case 270:return[1-e,t,s*(n/r),i*(r/n)];default:return[t,e,s,i]}}#g(){let{x:t,y:e,width:s,height:i,parentDimensions:[r,n],_drawRotation:a}=this;switch(a){case 90:return[1-e,t,s*(r/n),i*(n/r)];case 180:return[1-t,1-e,s,i];case 270:return[e,1-t,s*(r/n),i*(n/r)];default:return[t,e,s,i]}}#v(t){if([this.x,this.y,this.width,this.height]=this.#d(t),this.div)this.fixAndSetPosition(),this.setDims();this._onResized()}#y(t=this.parentRotation){let{x:e,y:s,width:i,height:r,_drawRotation:n,parentDimensions:[a,o]}=this;switch((n*4+t)/90){case 1:return[1-s-r,e,r,i];case 2:return[1-e-i,1-s-r,i,r];case 3:return[s,1-e-i,r,i];case 4:return[e,s-i*(a/o),r*(o/a),i*(a/o)];case 5:return[1-s,e,i*(a/o),r*(o/a)];case 6:return[1-e-r*(o/a),1-s,r*(o/a),i*(a/o)];case 7:return[s-i*(a/o),1-e-r*(o/a),i*(a/o),r*(o/a)];case 8:return[e-i,s-r,i,r];case 9:return[1-s,e-i,r,i];case 10:return[1-e,1-s,i,r];case 11:return[s-r,1-e,r,i];case 12:return[e-r*(o/a),s,r*(o/a),i*(a/o)];case 13:return[1-s-i*(a/o),e-r*(o/a),i*(a/o),r*(o/a)];case 14:return[1-e,1-s-i*(a/o),r*(o/a),i*(a/o)];case 15:return[s,1-e,i*(a/o),r*(o/a)];default:return[e,s,i,r]}}rotate(t=this.parentRotation){if(!this.parent||this._drawId===null)return;let e=(t-this._drawRotation+360)%360;this.parent.drawLayer.updateProperties(this._drawId,et._mergeSVGProperties({bbox:this.#y(t)},this._drawOutlines.updateRotation(e))),this.#c(e)}show(t=this._isVisible){super.show(t),this.#h()}select(){super.select(),this.#u({hovered:!1,selected:!0})}unselect(){super.unselect(),this.#u({selected:!1})}pointerover(){if(!this.isSelected)this.#u({hovered:!0})}pointerleave(){if(!this.isSelected)this.#u({hovered:!1})}onScaleChanging(){if(!this.parent)return;let t=this._drawOutlines.updateParentDimensions(this.parentDimensions,this.parent.scale);if(t)this.#v(t)}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;let t,e;if(this._isCopy)t=this.x,e=this.y;let s=super.render();if(this.constructor._hasDrawClass)s.classList.add("draw");let i=this.#t=document.createElement("div");if(s.append(i),i.setAttribute("aria-hidden","true"),i.className="internal",this._clipPathId)i.style.clipPath=this._clipPathId;if(fa(this,i,["pointerover","pointerleave"]),this.setDims(),this._uiManager.addShouldRescale(this),this.disableEditing(),this._isCopy)this._moveAfterPaste(t,e);return s}static createDrawerInstance(t){at("Not implemented")}static _getDrawingTarget(t,{target:e}){return e}static _getPointerCoords({offsetX:t,offsetY:e,clientX:s,clientY:i},r=null){if(!r)return[t,e];let n=s-r.clientX,a=i-r.clientY;switch(this._currentParent.viewport.rotation){case 90:[n,a]=[a,-n];break;case 180:[n,a]=[-n,-a];break;case 270:[n,a]=[-a,n];break}return[r.offsetX+n,r.offsetY+a]}static _addDrawingListeners(t,e){}static _endDrawingSession(t=!1){return this._currentParent.endDrawingSession(t)}static startDrawing(t,e,s,i){let{pointerId:r,pointerType:n}=i;if(ot.isInitializedAndDifferentPointerType(n))return;let a=this._getDrawingTarget(t,i),[o,l]=this._getPointerCoords(i),{viewport:{rotation:c}}=t,{x:h,y:d,width:u,height:f}=a.getBoundingClientRect(),p=et.#i=new AbortController,g=t.combinedSignal(p);if(ot.setPointer(n,r),window.addEventListener("pointerup",(y)=>{if(ot.isSamePointerIdOrRemove(y.pointerId))this._endDraw(y)},{signal:g}),window.addEventListener("pointercancel",(y)=>{if(ot.isSamePointerIdOrRemove(y.pointerId))this._endDrawingSession()},{signal:g}),window.addEventListener("pointerdown",(y)=>{if(!ot.isSamePointerType(y.pointerType))return;if(ot.initializeAndAddPointerId(y.pointerId),et.#s.isCancellable())if(et.#s.removeLastElement(),et.#s.isEmpty())this._endDrawingSession(!0);else this._endDraw(null)},{capture:!0,passive:!1,signal:g}),window.addEventListener("contextmenu",re,{signal:g}),a.addEventListener("pointermove",this._drawMove.bind(this),{signal:g}),a.addEventListener("touchmove",(y)=>{if(ot.isSameTimeStamp(y.timeStamp))Tt(y)},{signal:g}),this._addDrawingListeners(a,g),t.toggleDrawing(),e._editorUndoBar?.hide(),et.#s){t.drawLayer.updateProperties(this._currentDrawId,et.#s.startNew(o,l,u,f,c,i.timeStamp));return}e.updateUIForDefaultProperties(this),et.#s=this.createDrawerInstance({x:o,y:l,box:[h,d,u,f],rotation:c,parent:t,isLTR:s,timeStamp:i.timeStamp}),et.#r=this.getDefaultDrawingOptions(),this._currentParent=t;let{id:m,clipPathId:v}=t.drawLayer.draw(this._mergeSVGProperties(et.#r.toSVGProperties(),et.#s.defaultSVGProperties),!0,this._hasClipPath);this._currentDrawId=m,et.#n=this._hasClipPath?v:null}static _drawMove(t){if(ot.isSameTimeStamp(t.timeStamp),!et.#s||!ot.isSamePointerId(t.pointerId))return;if(ot.isUsingMultiplePointers()){this._endDraw(t);return}let e,s=t.getCoalescedEvents?.();if(s?.length){let i=[],r=[];for(let n of s)i.push(...this._getPointerCoords(n,t)),r.push(n.timeStamp);e=et.#s.addPoints(i,r)}else e=et.#s.add(...this._getPointerCoords(t),t.timeStamp);this._currentParent.drawLayer.updateProperties(this._currentDrawId,e),ot.setTimeStamp(t.timeStamp),Tt(t)}static _cleanup(t){if(t)this._currentDrawId=-1,this._currentParent=null,et.#s=null,et.#r=null,et.#n=null,ot.clearTimeStamp();if(et.#i)et.#i.abort(),et.#i=null,ot.clearPointerIds()}static _endDraw(t){let e=this._currentParent;if(!e)return;if(e.toggleDrawing(!0),this._cleanup(!1),e.drawLayer.updateProperties(this._currentDrawId,t?.target===e.div?et.#s.end(...this._getPointerCoords(t),t.timeStamp):et.#s.end()),this.supportMultipleDrawings){let s=et.#s,i=this._currentDrawId,r=s.getLastElement();e.addCommands({cmd:()=>{e.drawLayer.updateProperties(i,s.setLastElement(r))},undo:()=>{e.drawLayer.updateProperties(i,s.removeLastElement())},mustExec:!1,type:st.DRAW_STEP});return}this.endDrawing(!1)}static endDrawing(t){let e=this._currentParent;if(!e)return null;if(e.toggleDrawing(!0),e.cleanUndoStack(st.DRAW_STEP),!et.#s.isEmpty()){let{pageDimensions:[s,i],scale:r}=e,n=e.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,clipPathId:et.#n,drawOutlines:et.#s.getOutlines(s*r,i*r,r,this._INNER_MARGIN),drawingOptions:et.#r,mustBeCommitted:!t});return this._cleanup(!0),n}return e.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(t){}static deserializeDraw(t,e,s,i,r,n,a){at("Not implemented")}static async deserialize(t,e,s){let{rawDims:{pageWidth:i,pageHeight:r,pageX:n,pageY:a}}=e.viewport,o=this.deserializeDraw(n,a,i,r,this._INNER_MARGIN,t,s),l=await super.deserialize(t,e,s);return l.createDrawingOptions(t),l.#a({drawOutlines:o}),l.#m(),l.onScaleChanging(),l.rotate(),l}serializeDraw(t){let[e,s]=this.pageTranslation,[i,r]=this.pageDimensions;return this._drawOutlines.serialize([e,s,i,r],t)}renderAnnotationElement(t){return t.updateEdited({rect:this.getPDFRect()}),null}static canCreateNewEmptyEditor(){return!1}}class H{static PRECISION=0.0001;focusOutline=null;toSVGPath(){at("Abstract method `toSVGPath` must be implemented.")}get box(){at("Abstract getter `box` must be implemented.")}serialize(t,e){at("Abstract method `serialize` must be implemented.")}get defaultSVGProperties(){at("Abstract getter `defaultSVGProperties` must be implemented.")}get defaultProperties(){return this.defaultSVGProperties}getFocusSVGProperties(t){return null}get focusMustRemoveSelfIntersections(){return!1}updateProperty(t,e){return null}updateParentDimensions(t,e){return null}serializeQuadPoints(t,e){return null}updateRotation(t){return{}}getPathResizingSVGProperties(t){return{}}getPathResizedSVGProperties(t){return{}}getPathTranslatedSVGProperties(t,e){return{}}static _rotateBox([t,e,s,i],r){switch(r){case 90:return[1-e-i,t,i,s];case 180:return[1-t-s,1-e-i,s,i];case 270:return[e,1-t-s,i,s]}return[t,e,s,i]}static _rescale(t,e,s,i,r,n){n||=new Float32Array(t.length);for(let a=0,o=t.length;a<o;a+=2)n[a]=e+t[a]*i,n[a+1]=s+t[a+1]*r;return n}static _rescaleAndSwap(t,e,s,i,r,n){n||=new Float32Array(t.length);for(let a=0,o=t.length;a<o;a+=2)n[a]=e+t[a+1]*i,n[a+1]=s+t[a]*r;return n}static _translate(t,e,s,i){i||=new Float32Array(t.length);for(let r=0,n=t.length;r<n;r+=2)i[r]=e+t[r],i[r+1]=s+t[r+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,s,i,r,n=[]){switch(r){case 90:n[0]=1-e/s,n[1]=t/i;break;case 180:n[0]=1-t/s,n[1]=1-e/i;break;case 270:n[0]=e/s,n[1]=1-t/i;break;default:n[0]=t/s,n[1]=e/i;break}return n}static createBezierPoints(t,e,s,i,r,n,a=[]){return a.push((t+5*s)/6,(e+5*i)/6,(5*s+r)/6,(5*i+n)/6,(s+r)/2,(i+n)/2),a}}class De{#t;#e=[];#s;#i;#r=[];#n=new Float32Array(18);#a;#o;#l;#c;#u;#h;#f=[];static#p=8;static#m=2;static#d=De.#p+De.#m;constructor(t,e,s,i,r,n,a=0){this.#t=s,this.#h=r*i,this.#i=n,this.#n.set([NaN,NaN,NaN,NaN,t,e],6),this.#s=a,this.#c=De.#p*i,this.#l=De.#d*i,this.#u=i,this.#f.push(t,e)}isEmpty(){return isNaN(this.#n[8])}isCancellable(){return this.#f.length<=10}removeLastElement(){return this.#n.fill(NaN),this.#r.length=this.#e.length=this.#f.length=0,{path:{d:""}}}#g(){let t=this.#n.subarray(4,6),e=this.#n.subarray(16,18),[s,i,r,n]=this.#t;return[(this.#a+(t[0]-e[0])/2-s)/r,(this.#o+(t[1]-e[1])/2-i)/n,(this.#a+(e[0]-t[0])/2-s)/r,(this.#o+(e[1]-t[1])/2-i)/n]}add(t,e){this.#a=t,this.#o=e;let[s,i,r,n]=this.#t,[a,o,l,c]=this.#n.subarray(8,12),h=t-l,d=e-c,u=Math.hypot(h,d);if(u<this.#l)return!1;let f=u-this.#c,p=f/u,g=p*h,m=p*d,v=a,y=o;a=l,o=c,l+=g,c+=m,this.#f?.push(t,e);let b=-m/f,_=g/f,w=b*this.#h,A=_*this.#h;if(this.#n.set(this.#n.subarray(2,8),0),this.#n.set([l+w,c+A],4),this.#n.set(this.#n.subarray(14,18),12),this.#n.set([l-w,c-A],16),isNaN(this.#n[6])){if(this.#r.length===0)this.#n.set([a+w,o+A],2),this.#r.push(NaN,NaN,NaN,NaN,(a+w-s)/r,(o+A-i)/n),this.#n.set([a-w,o-A],14),this.#e.push(NaN,NaN,NaN,NaN,(a-w-s)/r,(o-A-i)/n);return this.#n.set([v,y,a,o,l,c],6),!this.isEmpty()}if(this.#n.set([v,y,a,o,l,c],6),Math.abs(Math.atan2(y-o,v-a)-Math.atan2(m,g))<Math.PI/2)return[a,o,l,c]=this.#n.subarray(2,6),this.#r.push(NaN,NaN,NaN,NaN,((a+l)/2-s)/r,((o+c)/2-i)/n),[a,o,v,y]=this.#n.subarray(14,18),this.#e.push(NaN,NaN,NaN,NaN,((v+a)/2-s)/r,((y+o)/2-i)/n),!0;return[v,y,a,o,l,c]=this.#n.subarray(0,6),this.#r.push(((v+5*a)/6-s)/r,((y+5*o)/6-i)/n,((5*a+l)/6-s)/r,((5*o+c)/6-i)/n,((a+l)/2-s)/r,((o+c)/2-i)/n),[l,c,a,o,v,y]=this.#n.subarray(12,18),this.#e.push(((v+5*a)/6-s)/r,((y+5*o)/6-i)/n,((5*a+l)/6-s)/r,((5*o+c)/6-i)/n,((a+l)/2-s)/r,((o+c)/2-i)/n),!0}toSVGPath(){if(this.isEmpty())return"";let t=this.#r,e=this.#e;if(isNaN(this.#n[6])&&!this.isEmpty())return this.#v();let s=[];s.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)if(isNaN(t[i]))s.push(`L${t[i+4]} ${t[i+5]}`);else s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);this.#b(s);for(let i=e.length-6;i>=6;i-=6)if(isNaN(e[i]))s.push(`L${e[i+4]} ${e[i+5]}`);else s.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return this.#y(s),s.join(" ")}#v(){let[t,e,s,i]=this.#t,[r,n,a,o]=this.#g();return`M${(this.#n[2]-t)/s} ${(this.#n[3]-e)/i} L${(this.#n[4]-t)/s} ${(this.#n[5]-e)/i} L${r} ${n} L${a} ${o} L${(this.#n[16]-t)/s} ${(this.#n[17]-e)/i} L${(this.#n[14]-t)/s} ${(this.#n[15]-e)/i} Z`}#y(t){let e=this.#e;t.push(`L${e[4]} ${e[5]} Z`)}#b(t){let[e,s,i,r]=this.#t,n=this.#n.subarray(4,6),a=this.#n.subarray(16,18),[o,l,c,h]=this.#g();t.push(`L${(n[0]-e)/i} ${(n[1]-s)/r} L${o} ${l} L${c} ${h} L${(a[0]-e)/i} ${(a[1]-s)/r}`)}newFreeDrawOutline(t,e,s,i,r,n){return new $r(t,e,s,i,r,n)}getOutlines(){let t=this.#r,e=this.#e,s=this.#n,[i,r,n,a]=this.#t,o=new Float32Array((this.#f?.length??0)+2);for(let h=0,d=o.length-2;h<d;h+=2)o[h]=(this.#f[h]-i)/n,o[h+1]=(this.#f[h+1]-r)/a;if(o[o.length-2]=(this.#a-i)/n,o[o.length-1]=(this.#o-r)/a,isNaN(s[6])&&!this.isEmpty())return this.#_(o);let l=new Float32Array(this.#r.length+24+this.#e.length),c=t.length;for(let h=0;h<c;h+=2){if(isNaN(t[h])){l[h]=l[h+1]=NaN;continue}l[h]=t[h],l[h+1]=t[h+1]}c=this.#S(l,c);for(let h=e.length-6;h>=6;h-=6)for(let d=0;d<6;d+=2){if(isNaN(e[h+d])){l[c]=l[c+1]=NaN,c+=2;continue}l[c]=e[h+d],l[c+1]=e[h+d+1],c+=2}return this.#A(l,c),this.newFreeDrawOutline(l,o,this.#t,this.#u,this.#s,this.#i)}#_(t){let e=this.#n,[s,i,r,n]=this.#t,[a,o,l,c]=this.#g(),h=new Float32Array(36);return h.set([NaN,NaN,NaN,NaN,(e[2]-s)/r,(e[3]-i)/n,NaN,NaN,NaN,NaN,(e[4]-s)/r,(e[5]-i)/n,NaN,NaN,NaN,NaN,a,o,NaN,NaN,NaN,NaN,l,c,NaN,NaN,NaN,NaN,(e[16]-s)/r,(e[17]-i)/n,NaN,NaN,NaN,NaN,(e[14]-s)/r,(e[15]-i)/n],0),this.newFreeDrawOutline(h,t,this.#t,this.#u,this.#s,this.#i)}#A(t,e){let s=this.#e;return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6}#S(t,e){let s=this.#n.subarray(4,6),i=this.#n.subarray(16,18),[r,n,a,o]=this.#t,[l,c,h,d]=this.#g();return t.set([NaN,NaN,NaN,NaN,(s[0]-r)/a,(s[1]-n)/o,NaN,NaN,NaN,NaN,l,c,NaN,NaN,NaN,NaN,h,d,NaN,NaN,NaN,NaN,(i[0]-r)/a,(i[1]-n)/o],e),e+=24}}class $r extends H{#t;#e=new Float32Array(4);#s;#i;#r;#n;#a;constructor(t,e,s,i,r,n){super();this.#a=t,this.#r=e,this.#t=s,this.#n=i,this.#s=r,this.#i=n,this.firstPoint=[NaN,NaN],this.lastPoint=[NaN,NaN],this.#o(n);let[a,o,l,c]=this.#e;for(let h=0,d=t.length;h<d;h+=2)t[h]=(t[h]-a)/l,t[h+1]=(t[h+1]-o)/c;for(let h=0,d=e.length;h<d;h+=2)e[h]=(e[h]-a)/l,e[h+1]=(e[h+1]-o)/c}toSVGPath(){let t=[`M${this.#a[4]} ${this.#a[5]}`];for(let e=6,s=this.#a.length;e<s;e+=6){if(isNaN(this.#a[e])){t.push(`L${this.#a[e+4]} ${this.#a[e+5]}`);continue}t.push(`C${this.#a[e]} ${this.#a[e+1]} ${this.#a[e+2]} ${this.#a[e+3]} ${this.#a[e+4]} ${this.#a[e+5]}`)}return t.push("Z"),t.join(" ")}serialize([t,e,s,i],r){let n=s-t,a=i-e,o,l;switch(r){case 0:o=H._rescale(this.#a,t,i,n,-a),l=H._rescale(this.#r,t,i,n,-a);break;case 90:o=H._rescaleAndSwap(this.#a,t,e,n,a),l=H._rescaleAndSwap(this.#r,t,e,n,a);break;case 180:o=H._rescale(this.#a,s,e,-n,a),l=H._rescale(this.#r,s,e,-n,a);break;case 270:o=H._rescaleAndSwap(this.#a,s,i,-n,-a),l=H._rescaleAndSwap(this.#r,s,i,-n,-a);break}return{outline:Array.from(o),points:[Array.from(l)]}}#o(t){let e=this.#a,s=e[4],i=e[5],r=[s,i,s,i],n=s,a=i,o=s,l=i,c=t?Math.max:Math.min,h=new Float32Array(4);for(let u=6,f=e.length;u<f;u+=6){let p=e[u+4],g=e[u+5];if(isNaN(e[u])){if(O.pointBoundingBox(p,g,r),a>g)n=p,a=g;else if(a===g)n=c(n,p);if(l<g)o=p,l=g;else if(l===g)o=c(o,p)}else{if(h.set(ce,0),O.bezierBoundingBox(s,i,...e.slice(u,u+6),h),O.rectBoundingBox(...h,r),a>h[1])n=h[0],a=h[1];else if(a===h[1])n=c(n,h[0]);if(l<h[3])o=h[2],l=h[3];else if(l===h[3])o=c(o,h[2])}s=p,i=g}let d=this.#e;d[0]=r[0]-this.#s,d[1]=r[1]-this.#s,d[2]=r[2]-r[0]+2*this.#s,d[3]=r[3]-r[1]+2*this.#s,this.firstPoint=[n,a],this.lastPoint=[o,l]}get box(){return this.#e}newOutliner(t,e,s,i,r,n,a=0){return new De(t,e,s,i,r,n,a)}updateThickness(t){let e=this.getNewOutline(t);return this.#a=e.#a,this.#r=e.#r,this.#e.set(e.#e),this.firstPoint=e.firstPoint,this.lastPoint=e.lastPoint,this.#e}getNewOutline(t,e){let[s,i,r,n]=this.#e,[a,o,l,c]=this.#t,h=r*l,d=n*c,u=s*l+a,f=i*c+o,p=this.#r,g=this.newOutliner(p[0]*h+u,p[1]*d+f,this.#t,this.#n,t,this.#i,e??this.#s);for(let m=2,v=p.length;m<v;m+=2)g.add(p[m]*h+u,p[m+1]*d+f);return g.getOutlines()}}function Bo(t){return{bbox:t.box,root:{viewBox:"0 0 1 1"},rootClass:{highlight:!0,free:t.isFree},path:{d:t.toSVGPath()}}}function jo(t,e){let{focusOutline:s}=t;return{bbox:H._rotateBox(s.box,e),root:{"data-main-rotation":e},rootClass:{highlightOutline:!0,free:t.isFree},path:{d:s.toSVGPath()}}}class Qs{#t;#e;#s;#i=[];#r=[];constructor(t,e=0,s=0,i=!0){let r=ce.slice(),n=4,a=0.0001;for(let{x:g,y:m,width:v,height:y}of t){let b=Math.floor((g-e)/0.0001)*0.0001,_=Math.ceil((g+v+e)/0.0001)*0.0001,w=Math.floor((m-e)/0.0001)*0.0001,A=Math.ceil((m+y+e)/0.0001)*0.0001,x=[b,w,A,!0],E=[_,w,A,!1];this.#i.push(x,E),O.rectBoundingBox(b,w,_,A,r)}let o=r[2]-r[0]+2*s,l=r[3]-r[1]+2*s,c=r[0]-s,h=r[1]-s,d=i?-1/0:1/0,u=1/0,f=this.#i.at(i?-1:-2),p=[f[0],f[2]];for(let g of this.#i){let[m,v,y,b]=g;if(!b&&i){if(v<u)u=v,d=m;else if(v===u)d=Math.max(d,m)}else if(b&&!i){if(v<u)u=v,d=m;else if(v===u)d=Math.min(d,m)}g[0]=(m-c)/o,g[1]=(v-h)/l,g[2]=(y-h)/l}this.#t=new Float32Array([c,h,o,l]),this.#e=[d,u],this.#s=p}getOutlines(){this.#i.sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);let t=[];for(let e of this.#i)if(e[3])t.push(...this.#c(e)),this.#o(e);else this.#l(e),t.push(...this.#c(e));return this.#n(t)}#n(t){let e=[],s=new Set;for(let r of t){let[n,a,o]=r;e.push([n,a,r],[n,o,r])}e.sort((r,n)=>r[1]-n[1]||r[0]-n[0]);for(let r=0,n=e.length;r<n;r+=2){let a=e[r][2],o=e[r+1][2];a.push(o),o.push(a),s.add(a),s.add(o)}let i=[];while(s.size>0){let r=s.values().next().value,[n,a,o,l,c]=r;s.delete(r);let h=n,d=a,u=[n,o];i.push(u);while(!0){let f;if(s.has(l))f=l;else if(s.has(c))f=c;else break;if(s.delete(f),[n,a,o,l,c]=f,h!==n)u.push(h,d,n,d===a?a:o),h=n;d=d===a?o:a}u.push(h,d)}return new Zs(i,this.#t,this.#e,this.#s)}#a(t){let e=this.#r,s=0,i=e.length-1;while(s<=i){let r=s+i>>1,n=e[r][0];if(n===t)return r;if(n<t)s=r+1;else i=r-1}return i+1}#o([,t,e]){let s=this.#a(t);this.#r.splice(s,0,[t,e])}#l([,t,e]){let s=this.#a(t);for(let i=s;i<this.#r.length;i++){let[r,n]=this.#r[i];if(r!==t)break;if(r===t&&n===e){this.#r.splice(i,1);return}}for(let i=s-1;i>=0;i--){let[r,n]=this.#r[i];if(r!==t)break;if(r===t&&n===e){this.#r.splice(i,1);return}}}#c(t){let[e,s,i]=t,r=[[e,s,i]],n=this.#a(i);for(let a=0;a<n;a++){let[o,l]=this.#r[a];for(let c=0,h=r.length;c<h;c++){let[,d,u]=r[c];if(l<=d||u<=o)continue;if(d>=o){if(u>l)r[c][1]=l;else{if(h===1)return[];r.splice(c,1),c--,h--}continue}if(r[c][2]=o,u>l)r.push([e,l,u])}}return r}}class Zs extends H{#t;#e=null;#s;constructor(t,e,s,i){super();this.#s=t,this.#t=e,this.firstPoint=s,this.lastPoint=i}static build(t,e){let s=new Qs(t,0.001).getOutlines();return s.#e=t,s.focusOutline=new Qs(t,0.0025,0.001,e).getOutlines(),s}get isFree(){return!1}get defaultSVGProperties(){return Bo(this)}getFocusSVGProperties(t){return jo(this,t)}updateRotation(t){return{root:{"data-main-rotation":t}}}serializeQuadPoints([t,e],[s,i]){let r=this.#e,n=new Float32Array(r.length*8),a=0;for(let{x:o,y:l,width:c,height:h}of r){let d=o*s+t,u=(1-l)*i+e;n[a]=n[a+4]=d,n[a+1]=n[a+3]=u,n[a+2]=n[a+6]=d+c*s,n[a+5]=n[a+7]=u-h*i,a+=8}return n}toSVGPath(){let t=[];for(let e of this.#s){let[s,i]=e;t.push(`M${s} ${i}`);for(let r=2;r<e.length;r+=2){let n=e[r],a=e[r+1];if(n===s)t.push(`V${a}`),i=a;else if(a===i)t.push(`H${n}`),s=n}t.push("Z")}return t.join(" ")}serialize([t,e,s,i],r){let n=[],a=s-t,o=i-e;for(let l of this.#s){let c=Array(l.length);for(let h=0;h<l.length;h+=2)c[h]=t+l[h]*a,c[h+1]=i-l[h+1]*o;n.push(c)}return n}get box(){return this.#t}}class Bi extends De{newFreeDrawOutline(t,e,s,i,r,n){return new Gr(t,e,s,i,r,n)}}class Ho{#t;#e;constructor(t,e,s,i,r,n,a){this.#t=new Bi(t,e,s,i,r,n,a),this.#e=r}add(t,e){return this.#t.add(t,e)?{path:{d:this.#t.toSVGPath()}}:null}addPoints(t){let e=!1;for(let s=0,i=t.length;s<i;s+=2)e=this.#t.add(t[s],t[s+1])||e;return e?{path:{d:this.#t.toSVGPath()}}:null}end(t,e){return t===void 0?null:this.add(t,e)}isEmpty(){return this.#t.isEmpty()}isCancellable(){return this.#t.isCancellable()}removeLastElement(){return this.#t.removeLastElement()}updateProperty(t,e){return null}getOutlines(){let t=this.#t.getOutlines();return t.buildFocusOutline(2*this.#e),t}get defaultSVGProperties(){return{bbox:[0,0,1,1],root:{viewBox:"0 0 1 1"},rootClass:{highlight:!0,free:!0},path:{d:this.#t.toSVGPath()}}}}class Gr extends $r{static#t=1.5;newOutliner(t,e,s,i,r,n,a=0){return new Bi(t,e,s,i,r,n,a)}get isFree(){return!0}buildFocusOutline(t){this.focusOutline=this.getNewOutline(t/2+Gr.#t,0.0025)}get defaultSVGProperties(){return Bo(this)}getFocusSVGProperties(t){return jo(this,t)}get focusMustRemoveSelfIntersections(){return!0}updateRotation(t){return{root:{"data-main-rotation":t}}}updateProperty(t,e){if(t!=="thickness")return null;let s=this.updateThickness(e/2);return this.buildFocusOutline(e),s}getPathResizedSVGProperties(){return{path:{d:this.toSVGPath()}}}}class zr extends Ni{constructor(t=null){super();super.updateProperties(t)}updateSVGProperty(t,e){if(t!=="thickness")super.updateSVGProperty(t,e)}clone(){let t=new zr;return t.updateAll(this),t}}class ie extends et{#t=null;#e=0;#s=null;#i=0;#r="";#n="";static _DEFAULT_OPACITY=1;static _DEFAULT_THICKNESS=12;static _defaultDrawingOptions=null;static _type="highlight";static _editorType=K.HIGHLIGHT;static get _keyboardManager(){let t=ie.prototype;return L(this,"_keyboardManager",new Xt([[["ArrowLeft"],t._moveCaret,{args:[0]}],[["ArrowRight"],t._moveCaret,{args:[1]}],[["ArrowUp"],t._moveCaret,{args:[2]}],[["ArrowDown"],t._moveCaret,{args:[3]}]]))}constructor(t){super({...t,name:"highlightEditor"});this.#t=t.anchorNode||null,this.#e=t.anchorOffset||0,this.#s=t.focusNode||null,this.#i=t.focusOffset||0,this.#r=t.methodOfCreation||(this._drawOutlines?.isFree?"main_toolbar":""),this.#n=t.text||"",this._isDraggable=!1,this.defaultL10nId="pdfjs-editor-highlight-editor",this.rotate()}static initialize(t,e){U.initialize(t,e),this._defaultDrawingOptions||=new zr({fill:e.highlightColors?.values().next().value||"#fff066","fill-opacity":ie._DEFAULT_OPACITY,thickness:ie._DEFAULT_THICKNESS})}static getDefaultDrawingOptions(t){let e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get typesMap(){return L(this,"typesMap",new Map([[st.HIGHLIGHT_COLOR,"fill"],[st.HIGHLIGHT_THICKNESS,"thickness"]]))}static get isDrawer(){return!1}static get _hasClipPath(){return!0}static get _hasDrawClass(){return!1}_addOutlines(t){let{boxes:e,drawOutlines:s}=t;if(!e&&!s)return;if(this._drawingOptions||=t.drawingOptions||ie.getDefaultDrawingOptions(),e)t={...t,drawOutlines:Zs.build(e,this._uiManager.direction==="ltr")};super._addOutlines(t)}get colorType(){return st.HIGHLIGHT_COLOR}get color(){return this._drawingOptions.fill}get opacity(){return this._drawingOptions["fill-opacity"]}get _opacityName(){return"fill-opacity"}get _drawRotation(){return this._drawOutlines?.isFree?this.rotation:0}get isResizable(){return!1}get _mustBeDisabledOnCommit(){return!1}get _mustFixPosition(){return!this._drawOutlines?.isFree}get telemetryInitialData(){return{action:"added",type:this._drawOutlines.isFree?"free_highlight":"highlight",color:this._uiManager.getNonHCMColorName(this.color),thickness:this._drawingOptions.thickness,methodOfCreation:this.#r}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.getNonHCMColorName(this.color)}}static computeTelemetryFinalData(t){return{numberOfColors:t.get("color").size}}translateInPage(t,e){}get toolbarPosition(){return this.#a(this._drawOutlines.focusOutline.lastPoint)}get commentButtonPosition(){return this.#a(this._drawOutlines.firstPoint)}#a([t,e]){let[s,i,r,n]=this._drawOutlines.box;return[(t-s)/r,(e-i)/n]}updateParams(t,e){switch(t){case st.HIGHLIGHT_COLOR:this._updateColorAndOpacity(e,ie._DEFAULT_OPACITY,t),this._reportTelemetry({action:"color_changed",color:this._uiManager.getNonHCMColorName(e)},!0);break;case st.HIGHLIGHT_THICKNESS:super.updateParams(t,e),this._reportTelemetry({action:"thickness_changed",thickness:e},!0);break}}get propertiesToUpdate(){let t=super.propertiesToUpdate;return t.push([st.HIGHLIGHT_FREE,this._drawOutlines.isFree]),t}get toolbarButtons(){if(this._uiManager.highlightColors)return this._colorPicker=new Qt({editor:this}),[["colorPicker",this._colorPicker]];return super.toolbarButtons}fixAndSetPosition(){return super.fixAndSetPosition(this._drawRotation)}getRect(t,e){return super.getRect(t,e,this._drawRotation)}onceAdded(t){if(!this.annotationElementId)this.parent.addUndoableEditor(this);if(t)this.div.focus()}remove(){this._reportTelemetry({action:"deleted"}),super.remove()}render(){if(this.div)return this.div;let t=super.render();if(this.#n)t.setAttribute("aria-label",this.#n),t.setAttribute("role","mark");if(this._drawOutlines.isFree)t.classList.add("free");else t.addEventListener("keydown",this.#o.bind(this),{signal:this._uiManager._signal});return this.enableEditing(),t}#o(t){ie._keyboardManager.exec(this,t)}_moveCaret(t){switch(this.parent.unselect(this),t){case 0:case 2:this.#l(!0);break;case 1:case 3:this.#l(!1);break}}#l(t){if(!this.#t)return;let e=window.getSelection();if(t)e.setPosition(this.#t,this.#e);else e.setPosition(this.#s,this.#i)}unselect(){if(super.unselect(),!this._drawOutlines.isFree)this.#l(!1)}static createDrawerInstance({x:t,y:e,box:s,parent:i,isLTR:r}){return new Ho(t,e,s,i.scale,this._defaultDrawingOptions.thickness/2,r,0.001)}static _getDrawingTarget(t,{target:e}){return e.closest(".textLayer")}static _getPointerCoords({x:t,y:e}){return[t,e]}static _addDrawingListeners(t,e){t.classList.add("free"),e.addEventListener("abort",()=>t.classList.remove("free"),{once:!0}),window.addEventListener("blur",()=>this._endDraw(null),{signal:e}),window.addEventListener("pointerdown",Tt,{capture:!0,passive:!1,signal:e})}static _endDrawingSession(t=!1){return this.endDrawing(t)}createDrawingOptions({color:t,opacity:e,thickness:s}){let{_defaultDrawingOptions:i,_DEFAULT_OPACITY:r}=ie;this._drawingOptions=ie.getDefaultDrawingOptions({fill:O.makeHexColor(...t),"fill-opacity":e||r,thickness:s||i.thickness})}static deserializeDraw(t,e,s,i,r,n,a){let{quadPoints:o}=n;if(o){let u=[];for(let f=0,p=o.length;f<p;f+=8)u.push({x:(o[f]-t)/s,y:1-(o[f+1]-e)/i,width:(o[f+2]-o[f])/s,height:(o[f+1]-o[f+5])/i});return Zs.build(u,a.direction==="ltr")}let l=n.thickness||this._defaultDrawingOptions.thickness,c=(n.inkLists||n.outlines.points)[0],h=new Bi(c[0]-t,i-(c[1]-e),[0,0,s,i],1,l/2,!0,0.001);for(let u=0,f=c.length;u<f;u+=2)h.add(c[u]-t,i-(c[u+1]-e));let d=h.getOutlines();return d.buildFocusOutline(l),d}static async deserialize(t,e,s){let i=null;if(t instanceof Br){let{data:{quadPoints:n,rect:a,rotation:o,id:l,color:c,opacity:h,popupRef:d,richText:u,contentsObj:f,creationDate:p,modificationDate:g},parent:{page:{pageNumber:m}}}=t;i=t={annotationType:K.HIGHLIGHT,color:Array.from(c),opacity:h,quadPoints:n,pageIndex:m-1,rect:a.slice(0),rotation:o,annotationElementId:l,id:l,deleted:!1,popupRef:d,richText:u,comment:f?.str||null,creationDate:p,modificationDate:g}}else if(t instanceof Li){let{data:{inkLists:n,rect:a,rotation:o,id:l,color:c,borderStyle:{rawWidth:h},popupRef:d,richText:u,contentsObj:f,creationDate:p,modificationDate:g},parent:{page:{pageNumber:m}}}=t;i=t={annotationType:K.HIGHLIGHT,color:Array.from(c),thickness:h,inkLists:n,pageIndex:m-1,rect:a.slice(0),rotation:o,annotationElementId:l,id:l,deleted:!1,popupRef:d,richText:u,comment:f?.str||null,creationDate:p,modificationDate:g}}let r=await super.deserialize(t,e,s);if(r._initialData=i,t.comment)r.setCommentData(t);return r}serialize(t=!1){if(this.isEmpty()||t)return null;if(this.deleted)return this.serializeDeleted();let e=super.serialize(t);if(Object.assign(e,{color:U._colorManager.convert(this._uiManager.getNonHCMColor(this.color)),opacity:this.opacity,thickness:this._drawingOptions.thickness,quadPoints:this._drawOutlines.serializeQuadPoints(this.pageTranslation,this.pageDimensions),outlines:this._drawOutlines.serialize(e.rect,this._drawRotation)}),this.addComment(e),this.annotationElementId&&!this.#c(e))return null;return e.id=this.annotationElementId,e}#c(t){let{color:e}=this._initialData;return this.hasEditedComment||t.color.some((s,i)=>s!==e[i])}renderAnnotationElement(t){if(this.deleted)return t.hide(),null;return t.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null}}class _e{static#t=10;static#e=5.555555555555555;static#s=100;static#i=0.001;#r;#n;#a;constructor(t,e,s){this.#r=[t,e,s],this.#n=this.#a=s}add(t,e,s){let i=this.#r,r=i.at(-1);s=s>r?s:r+_e.#i,i.push(t,e,s);let n=this.#o(s-_e.#t,!0),a=this.#l(this.#a-_e.#t);if(a>=i.length/2)i.copyWithin(0,a),i.length-=a;return n}get pendingPoints(){return this.#o(1/0,!1)}end(){return this.#o(1/0,!0)}#o(t,e){let s=this.#r,i=this.#n,r=s.at(-1),n=[],a=this.#a;for(let o=this.#l(a)+3;o<s.length;o+=3){let l=s[o-1],c=s[o+2]-l,h=Math.min(Math.ceil(c/_e.#e),_e.#s);for(let d=1;d<=h;d++){let u=d===h?s[o+2]:l+c*d/h;if(u<=a)continue;if(u>t)return n;let f=Math.min(_e.#t,u-i,r-u);if(this.#c(u-f,u+f,n),e)this.#a=u}}return n}#l(t){let e=this.#r,s=0,i=e.length/3-1;while(s<i){let r=s+i+1>>1;if(e[3*r+2]<=t)s=r;else i=r-1}return 3*s}#c(t,e,s){let i=this.#r,r=this.#l(t),n=0,a=0,o=0;for(let l=r;l<i.length-3&&i[l+2]<e;l+=3){let c=i[l],h=i[l+1],d=i[l+2],u=i[l+5],f=Math.max(d,t),p=Math.min(u,e);if(p<=f)continue;let g=p-f,m=(f+p-2*d)/(u-d);n+=g*(c+m*(i[l+3]-c)/2),a+=g*(h+m*(i[l+4]-h)/2),o+=g}if(o===0)s.push(i[r],i[r+1]);else s.push(n/o,a/o)}}function me(t,e){return`${H.svgRound(t[e])} ${H.svgRound(t[e+1])}`}function Uo(t,e,s){for(let i=s,r=e.length;i<r;i+=6)t.push(`C${me(e,i)} ${me(e,i+2)} ${me(e,i+4)}`)}function Gs(t){let e=`M${me(t,4)}`;if(t.length===6)return`${e}Z`;if(t.length===12&&isNaN(t[6]))return`${e}L${me(t,10)}`;let s=[e];return Uo(s,t,6),s.join("")}class $o{#t=new Float64Array(6);#e=new Float64Array(2);#s;#i;#r;#n=null;#a;#o;#l=1;#c=new Float64Array(2);#u="";#h=0;#f=new es;#p;#m;constructor(t,e,s,i,r,n,a){this.#p=s,this.#m=i,this.#r=r,this.#a=n,this.#i=[],this.#d(t,e,a)}#d(t,e,s){[t,e]=this.#g(t,e);let i=this.#s=[NaN,NaN,NaN,NaN,t,e];this.#o=[t,e],this.#i.push({line:i,points:this.#o}),this.#t.set(i,0),this.#h=0,this.#l=1,this.#c.set(this.#e),this.#n=s===void 0?null:new _e(t,e,s)}updateProperty(t,e){if(t==="stroke-width")this.#a=e}#g(t,e){return H._normalizePoint(t,e,this.#p,this.#m,this.#r,this.#e)}isEmpty(){return!this.#i?.length}isCancellable(){return this.#l<=5}add(t,e,s){return this.#v(t,e,s),{path:{d:this.#w()}}}addPoints(t,e){for(let s=0,i=t.length;s<i;s+=2)this.#v(t[s],t[s+1],e?.[s/2]);return{path:{d:this.#w()}}}#v(t,e,s){[t,e]=this.#g(t,e);let[i,r]=this.#c;if(!this.#y(t,e,i,r))this.#l++,this.#c.set(this.#e);if(this.#n)this.#b(this.#n.add(t,e,s));else this.#_(t,e)}#y(t,e,s,i){return Math.hypot(this.#p*(t-s),this.#m*(e-i))<=2}#b(t){for(let e=0,s=t.length;e<s;e+=2)this.#_(t[e],t[e+1])}#_(t,e){let[,,s,i,r,n]=this.#t;if(this.#y(t,e,r,n))return;if(this.#o.push(t,e),isNaN(s))this.#s.push(NaN,NaN,NaN,NaN,t,e);else{if(isNaN(this.#t[0]))this.#s.splice(6,6);H.createBezierPoints(s,i,r,n,t,e,this.#s)}this.#t.copyWithin(0,2),this.#t[4]=t,this.#t[5]=e}#A(){let t=this.#s;if(this.#o.length<6||this.#h===t.length)return;let e=[this.#u];if(this.#h===0)e.push(`M${me(t,4)}`),this.#h=6;Uo(e,t,this.#h),this.#u=e.join(""),this.#h=t.length}#S(){if(!this.#s)return;if(this.#n)this.#b(this.#n.end()),this.#n=null;if(this.#o.length<6)this.#u+=Gs(this.#s);else{let[,,t,e,s,i]=this.#t;H.createBezierPoints(t,e,s,i,s,i,this.#s),this.#A()}this.#s=this.#o=null}end(t,e,s){if(this.#s&&t!==void 0)this.#v(t,e,s);return this.#S(),{path:{d:this.#u}}}startNew(t,e,s,i,r,n){this.#p=s,this.#m=i,this.#r=r;let a=this.#i.at(-1);if(a)a.line=new Float32Array(a.line),a.points=new Float32Array(a.points);return this.#d(t,e,n),null}getLastElement(){return this.#i.at(-1)}setLastElement(t){if(!this.#i)return this.#f.setLastElement(t);return this.#i.push(t),this.#u+=Gs(t.line),{path:{d:this.#u}}}removeLastElement(){if(!this.#i)return this.#f.removeLastElement();return this.#s=this.#o=this.#n=null,this.#i.pop(),this.#u=this.#i.map(({line:t})=>Gs(t)).join(""),{path:{d:this.#u}}}#w(){this.#A();let t=[this.#u];if(this.#h===0){if(t.push(`M${me(this.#s,4)}`),this.#o.length===4)t.push(`L${me(this.#s,10)}`)}let e=this.#n?.pendingPoints;if(!e?.length)e=this.#e;for(let s=0,i=e.length;s<i;s+=2)t.push(`L${me(e,s)}`);return t.join("")}getOutlines(t,e,s,i){this.#S();let r=this.#i.at(-1);return r.line=new Float32Array(r.line),r.points=new Float32Array(r.points),this.#f.build(this.#i,t,e,s,this.#r,this.#a,i),this.#t=null,this.#s=null,this.#i=null,this.#u=null,this.#f}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}class es extends H{#t;#e=0;#s;#i;#r;#n;#a;#o;#l;build(t,e,s,i,r,n,a){this.#r=e,this.#n=s,this.#a=i,this.#o=r,this.#l=n,this.#s=a??0,this.#i=t,this.#h()}get thickness(){return this.#l}setLastElement(t){return this.#i.push(t),{path:{d:this.toSVGPath()}}}removeLastElement(){return this.#i.pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){return this.#i.map(({line:t})=>Gs(t)).join("")}serialize([t,e,s,i],r){let n=[],a=[],[o,l,c,h]=this.#u(),d,u,f,p,g,m,v,y,b;switch(this.#o){case 0:b=H._rescale,d=t,u=e+i,f=s,p=-i,g=t+o*s,m=e+(1-l-h)*i,v=t+(o+c)*s,y=e+(1-l)*i;break;case 90:b=H._rescaleAndSwap,d=t,u=e,f=s,p=i,g=t+l*s,m=e+o*i,v=t+(l+h)*s,y=e+(o+c)*i;break;case 180:b=H._rescale,d=t+s,u=e,f=-s,p=i,g=t+(1-o-c)*s,m=e+l*i,v=t+(1-o)*s,y=e+(l+h)*i;break;case 270:b=H._rescaleAndSwap,d=t+s,u=e+i,f=-s,p=-i,g=t+(1-l-h)*s,m=e+(1-o-c)*i,v=t+(1-l)*s,y=e+(1-o)*i;break}for(let{line:_,points:w}of this.#i)n.push(b(_,d,u,f,p,r?Array(_.length):null)),a.push(b(w,d,u,f,p,r?Array(w.length):null));return{lines:n,points:a,rect:[g,m,v,y]}}static deserialize(t,e,s,i,r,{paths:{lines:n,points:a},rotation:o,thickness:l}){let c=[],h,d,u,f,p;switch(o){case 0:p=H._rescale,h=-t/s,d=e/i+1,u=1/s,f=-1/i;break;case 90:p=H._rescaleAndSwap,h=-e/i,d=-t/s,u=1/i,f=1/s;break;case 180:p=H._rescale,h=t/s+1,d=-e/i,u=-1/s,f=1/i;break;case 270:p=H._rescaleAndSwap,h=e/i+1,d=t/s+1,u=-1/i,f=-1/s;break}if(!n){n=[];for(let m of a){let v=m.length;if(v===2){n.push(new Float32Array([NaN,NaN,NaN,NaN,m[0],m[1]]));continue}if(v===4){n.push(new Float32Array([NaN,NaN,NaN,NaN,m[0],m[1],NaN,NaN,NaN,NaN,m[2],m[3]]));continue}let y=new Float32Array(3*v);n.push(y);let[b,_,w,A]=m.subarray(0,4);y.set([NaN,NaN,NaN,NaN,b,_],0);for(let x=4;x<=v;x+=2){let E=Math.min(x,v-2),T=m[E],k=m[E+1];y.set(H.createBezierPoints(b,_,w,A,T,k),(x-2)*3),[b,_,w,A]=[w,A,T,k]}}}for(let m=0,v=n.length;m<v;m++)c.push({line:p(n[m].map((y)=>y??NaN),h,d,u,f),points:p(a[m].map((y)=>y??NaN),h,d,u,f)});let g=new this.prototype.constructor;return g.build(c,s,i,1,o,l,r),g}#c(t=this.#l){let e=this.#s+t/2*this.#a;return this.#o%180===0?[e/this.#r,e/this.#n]:[e/this.#n,e/this.#r]}#u(){let[t,e,s,i]=this.#t,[r,n]=this.#c(0);return[t+r,e+n,s-2*r,i-2*n]}#h(){let t=this.#t=Re.slice();for(let{line:i}of this.#i){if(i.length<=12){for(let a=4,o=i.length;a<o;a+=6)O.pointBoundingBox(i[a],i[a+1],t);continue}let r=i[4],n=i[5];for(let a=6,o=i.length;a<o;a+=6){let[l,c,h,d,u,f]=i.subarray(a,a+6);O.bezierBoundingBox(r,n,l,c,h,d,u,f,t),r=u,n=f}}let[e,s]=this.#c();t[0]=pt(t[0]-e,0,1),t[1]=pt(t[1]-s,0,1),t[2]=pt(t[2]+e,0,1),t[3]=pt(t[3]+s,0,1),t[2]-=t[0],t[3]-=t[1]}get box(){return this.#t}updateProperty(t,e){return t==="stroke-width"?this.#f(e):null}#f(t){let[e,s]=this.#c();this.#l=t;let[i,r]=this.#c(),[n,a]=[i-e,r-s],o=this.#t;return o[0]-=n,o[1]-=a,o[2]+=2*n,o[3]+=2*a,o}updateParentDimensions([t,e],s){let[i,r]=this.#c();this.#r=t,this.#n=e,this.#a=s;let[n,a]=this.#c(),o=n-i,l=a-r,c=this.#t;return c[0]-=o,c[1]-=l,c[2]+=2*o,c[3]+=2*l,c}updateRotation(t){return this.#e=t,{path:{transform:this.rotationTransform}}}get viewBox(){return this.#t.map(H.svgRound).join(" ")}get defaultProperties(){let[t,e]=this.#t;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${H.svgRound(t)} ${H.svgRound(e)}`}}}get rotationTransform(){let[,,t,e]=this.#t,s=0,i=0,r=0,n=0,a=0,o=0;switch(this.#e){case 90:i=e/t,r=-t/e,a=t;break;case 180:s=-1,n=-1,a=t,o=e;break;case 270:i=-e/t,r=t/e,o=e;break;default:return""}return`matrix(${s} ${i} ${r} ${n} ${H.svgRound(a)} ${H.svgRound(o)})`}getPathResizingSVGProperties([t,e,s,i]){let[r,n]=this.#c(),[a,o,l,c]=this.#t;if(Math.abs(l-r)<=H.PRECISION||Math.abs(c-n)<=H.PRECISION){let p=t+s/2-(a+l/2),g=e+i/2-(o+c/2);return{path:{"transform-origin":`${H.svgRound(t)} ${H.svgRound(e)}`,transform:`${this.rotationTransform} translate(${p} ${g})`}}}let h=(s-2*r)/(l-2*r),d=(i-2*n)/(c-2*n),u=l/s,f=c/i;return{path:{"transform-origin":`${H.svgRound(a)} ${H.svgRound(o)}`,transform:`${this.rotationTransform} scale(${u} ${f}) translate(${H.svgRound(r)} ${H.svgRound(n)}) scale(${h} ${d}) translate(${H.svgRound(-r)} ${H.svgRound(-n)})`}}}getPathResizedSVGProperties([t,e,s,i]){let[r,n]=this.#c(),a=this.#t,[o,l,c,h]=a;if(a[0]=t,a[1]=e,a[2]=s,a[3]=i,Math.abs(c-r)<=H.PRECISION||Math.abs(h-n)<=H.PRECISION){let g=t+s/2-(o+c/2),m=e+i/2-(l+h/2);for(let{line:v,points:y}of this.#i)H._translate(v,g,m,v),H._translate(y,g,m,y);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${H.svgRound(t)} ${H.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}let d=(s-2*r)/(c-2*r),u=(i-2*n)/(h-2*n),f=-d*(o+r)+t+r,p=-u*(l+n)+e+n;if(d!==1||u!==1||f!==0||p!==0)for(let{line:g,points:m}of this.#i)H._rescale(g,f,p,d,u,g),H._rescale(m,f,p,d,u,m);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${H.svgRound(t)} ${H.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([t,e],s){let[i,r]=s,n=this.#t,a=t-n[0],o=e-n[1];if(this.#r===i&&this.#n===r)for(let{line:l,points:c}of this.#i)H._translate(l,a,o,l),H._translate(c,a,o,c);else{let l=this.#r/i,c=this.#n/r;this.#r=i,this.#n=r;for(let{line:h,points:d}of this.#i)H._rescale(h,a,o,l,c,h),H._rescale(d,a,o,l,c,d);n[2]*=l,n[3]*=c}return n[0]=t,n[1]=e,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${H.svgRound(t)} ${H.svgRound(e)}`}}}get defaultSVGProperties(){let t=this.#t;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${H.svgRound(t[0])} ${H.svgRound(t[1])}`,transform:this.rotationTransform||null},bbox:t}}}class ji extends Ni{constructor(t){super();this._viewParameters=t,super.updateProperties({fill:"none",stroke:U._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(t,e){if(t==="stroke-width")e??=this["stroke-width"],e*=this._viewParameters.realScale;super.updateSVGProperty(t,e)}clone(){let t=new ji(this._viewParameters);return t.updateAll(this),t}}class Vr extends et{static _type="ink";static _editorType=K.INK;static _defaultDrawingOptions=null;constructor(t){super({...t,name:"inkEditor"});this._willKeepAspectRatio=!0,this.defaultL10nId="pdfjs-editor-ink-editor"}static initialize(t,e){U.initialize(t,e),this._defaultDrawingOptions=new ji(e.viewParameters)}static getDefaultDrawingOptions(t){let e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!0}static get typesMap(){return L(this,"typesMap",new Map([[st.INK_THICKNESS,"stroke-width"],[st.INK_COLOR,"stroke"],[st.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance({x:t,y:e,box:[,,s,i],rotation:r,timeStamp:n}){return new $o(t,e,s,i,r,this._defaultDrawingOptions["stroke-width"],n)}static deserializeDraw(t,e,s,i,r,n){return es.deserialize(t,e,s,i,r,n)}static async deserialize(t,e,s){let i=null;if(t instanceof Li){let{data:{inkLists:n,rect:a,rotation:o,id:l,color:c,opacity:h,borderStyle:{rawWidth:d},popupRef:u,richText:f,contentsObj:p,creationDate:g,modificationDate:m},parent:{page:{pageNumber:v}}}=t;i=t={annotationType:K.INK,color:Array.from(c),thickness:d,opacity:h,paths:{points:n},boxes:null,pageIndex:v-1,rect:a.slice(0),rotation:o,annotationElementId:l,id:l,deleted:!1,popupRef:u,richText:f,comment:p?.str||null,creationDate:g,modificationDate:m}}let r=await super.deserialize(t,e,s);if(r._initialData=i,t.comment)r.setCommentData(t);return r}get toolbarButtons(){return this._colorPicker||=new bs(this),[["colorPicker",this._colorPicker]]}get colorType(){return st.INK_COLOR}get colorAndOpacityType(){return st.INK_COLOR_AND_OPACITY}get opacityType(){return st.INK_OPACITY}updateParams(t,e){if(t===st.INK_COLOR_AND_OPACITY){this._updateColorAndOpacity(e.color,e.opacity);return}super.updateParams(t,e)}static updateDefaultParams(t,e){if(t===st.INK_COLOR_AND_OPACITY){super.updateDefaultParams(st.INK_COLOR,e.color),super.updateDefaultParams(st.INK_OPACITY,e.opacity);return}super.updateDefaultParams(t,e)}get color(){return this._drawingOptions.stroke}get opacity(){return this._drawingOptions["stroke-opacity"]}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();let{_drawId:t,_drawingOptions:e,parent:s}=this;e.updateSVGProperty("stroke-width"),s.drawLayer.updateProperties(t,e.toSVGProperties())}static onScaleChangingWhenDrawing(){let t=this._currentParent;if(!t)return;super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),t.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties())}createDrawingOptions({color:t,thickness:e,opacity:s}){this._drawingOptions=Vr.getDefaultDrawingOptions({stroke:O.makeHexColor(...t),"stroke-width":e,"stroke-opacity":s})}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let{lines:e,points:s}=this.serializeDraw(t),{_drawingOptions:{stroke:i,"stroke-opacity":r,"stroke-width":n}}=this,a=Object.assign(super.serialize(t),{color:U._colorManager.convert(i),opacity:r,thickness:n,paths:{lines:e,points:s}});if(this.addComment(a),t)return a.isCopy=!0,a;if(this.annotationElementId&&!this.#t(a))return null;return a.id=this.annotationElementId,a}#t(t){let{color:e,thickness:s,opacity:i,pageIndex:r}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized||t.color.some((n,a)=>n!==e[a])||t.thickness!==s||t.opacity!==i||t.pageIndex!==r}renderAnnotationElement(t){if(this.deleted)return t.hide(),null;let{points:e,rect:s}=this.serializeDraw(!1);return t.updateEdited({rect:s,thickness:this._drawingOptions["stroke-width"],points:e,popup:this.comment}),null}}class ti extends es{toSVGPath(){let t=super.toSVGPath();if(!t.endsWith("Z"))t+="Z";return t}}Oc();var Ls=8,ls=3;class Oe{static#t={maxDim:512,sigmaSFactor:0.02,sigmaR:25,kernelSize:16};static#e(t,e,s,i){if(s-=t,i-=e,s===0)return i>0?0:4;return s===1?i+6:2-i}static#s=new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]);static#i(t,e,s,i,r,n,a){let o=this.#e(s,i,r,n);for(let l=0;l<8;l++){let c=(-l+o-a+16)%8,h=this.#s[2*c],d=this.#s[2*c+1];if(t[(s+h)*e+(i+d)]!==0)return c}return-1}static#r(t,e,s,i,r,n,a){let o=this.#e(s,i,r,n);for(let l=0;l<8;l++){let c=(l+o+a+16)%8,h=this.#s[2*c],d=this.#s[2*c+1];if(t[(s+h)*e+(i+d)]!==0)return c}return-1}static#n(t,e,s,i){let r=t.length,n=new Int32Array(r);for(let c=0;c<r;c++)n[c]=t[c]<=i?1:0;for(let c=1;c<s-1;c++)n[c*e]=n[c*e+e-1]=0;for(let c=0;c<e;c++)n[c]=n[e*s-1-c]=0;let a=1,o,l=[];for(let c=1;c<s-1;c++){o=1;for(let h=1;h<e-1;h++){let d=c*e+h,u=n[d];if(u===0)continue;let f=c,p=h;if(u===1&&n[d-1]===0)a+=1,p-=1;else if(u>=1&&n[d+1]===0){if(a+=1,p+=1,u>1)o=u}else{if(u!==1)o=Math.abs(u);continue}let g=[h,c],m=p===h+1,v={isHole:m,points:g,id:a,parent:0};l.push(v);let y;for(let k of l)if(k.id===o){y=k;break}if(!y)v.parent=m?o:0;else if(y.isHole)v.parent=m?y.parent:o;else v.parent=m?o:y.parent;let b=this.#i(n,e,c,h,f,p,0);if(b===-1){if(n[d]=-a,n[d]!==1)o=Math.abs(n[d]);continue}let _=this.#s[2*b],w=this.#s[2*b+1],A=c+_,x=h+w;f=A,p=x;let E=c,T=h;while(!0){let k=this.#r(n,e,E,T,f,p,1);_=this.#s[2*k],w=this.#s[2*k+1];let C=E+_,R=T+w;g.push(R,C);let B=E*e+T;if(n[B+1]===0)n[B]=-a;else if(n[B]===1)n[B]=a;if(C===c&&R===h&&E===A&&T===x){if(n[d]!==1)o=Math.abs(n[d]);break}else f=E,p=T,E=C,T=R}}}return l}static#a(t,e,s,i){if(s-e<=4){for(let A=e;A<s-2;A+=2)i.push(t[A],t[A+1]);return}let r=t[e],n=t[e+1],a=t[s-4]-r,o=t[s-3]-n,l=Math.hypot(a,o),c=a/l,h=o/l,d=c*n-h*r,u=o/a,f=1/l,p=Math.atan(u),g=Math.cos(p),m=Math.sin(p),v=f*(Math.abs(g)+Math.abs(m)),y=f*(1-v+v**2),b=Math.max(Math.atan(Math.abs(m+g)*y),Math.atan(Math.abs(m-g)*y)),_=0,w=e;for(let A=e+2;A<s-2;A+=2){let x=Math.abs(d-c*t[A+1]+h*t[A]);if(x>_)w=A,_=x}if(_>(l*b)**2)this.#a(t,e,w+2,i),this.#a(t,w,s,i);else i.push(r,n)}static#o(t){let e=[],s=t.length;return this.#a(t,0,s,e),e.push(t[s-2],t[s-1]),e.length<=4?null:e}static#l(t,e,s,i,r,n){let a=new Float32Array(n**2),o=-2*i**2,l=n>>1;for(let p=0;p<n;p++){let g=(p-l)**2;for(let m=0;m<n;m++)a[p*n+m]=Math.exp((g+(m-l)**2)/o)}let c=new Float32Array(256),h=-2*r**2;for(let p=0;p<256;p++)c[p]=Math.exp(p**2/h);let d=t.length,u=new Uint8Array(d),f=new Uint32Array(256);for(let p=0;p<s;p++)for(let g=0;g<e;g++){let m=p*e+g,v=t[m],y=0,b=0;for(let w=0;w<n;w++){let A=p+w-l;if(A<0||A>=s)continue;for(let x=0;x<n;x++){let E=g+x-l;if(E<0||E>=e)continue;let T=t[A*e+E],k=a[w*n+x]*c[Math.abs(T-v)];y+=T*k,b+=k}}let _=u[m]=Math.round(y/b);f[_]++}return[u,f]}static#c(t){let e=new Uint32Array(256);for(let s of t)e[s]++;return e}static#u(t){let e=t.length,s=new Uint8ClampedArray(e>>2),i=-1/0,r=1/0;for(let a=0,o=s.length;a<o;a++){let l=s[a]=t[a<<2];i=Math.max(i,l),r=Math.min(r,l)}let n=255/(i-r);for(let a=0,o=s.length;a<o;a++)s[a]=(s[a]-r)*n;return s}static#h(t){let e,s=-1/0,i=-1/0,r=t.findIndex((o)=>o!==0),n=r,a=r;for(e=r;e<256;e++){let o=t[e];if(o>s){if(e-n>i)i=e-n,a=e-1;s=o,n=e}}for(e=a-1;e>=0;e--)if(t[e]>t[e+1])break;return e}static#f(t){let e=t,{width:s,height:i}=t,{maxDim:r}=this.#t,n=s,a=i;if(s>r||i>r){let d=s,u=i,f=Math.log2(Math.max(s,i)/r),p=Math.floor(f);f=f===p?p-1:p;for(let m=0;m<f;m++){n=Math.ceil(d/2),a=Math.ceil(u/2);let v=new OffscreenCanvas(n,a);if(v.getContext("2d").drawImage(t,0,0,d,u,0,0,n,a),d=n,u=a,t!==e)t.close();t=v.transferToImageBitmap()}let g=Math.min(r/n,r/a);n=Math.round(n*g),a=Math.round(a*g)}let l=new OffscreenCanvas(n,a).getContext("2d",{willReadFrequently:!0});l.fillStyle="white",l.fillRect(0,0,n,a),l.filter="grayscale(1)",l.drawImage(t,0,0,t.width,t.height,0,0,n,a);let c=l.getImageData(0,0,n,a).data;return[this.#u(c),n,a]}static extractContoursFromText(t,{fontFamily:e,fontStyle:s,fontWeight:i},r,n,a,o){let l=new OffscreenCanvas(1,1),c=l.getContext("2d",{alpha:!1}),h=200,d=c.font=`${s} ${i} ${h}px ${e}`,{actualBoundingBoxLeft:u,actualBoundingBoxRight:f,actualBoundingBoxAscent:p,actualBoundingBoxDescent:g,fontBoundingBoxAscent:m,fontBoundingBoxDescent:v,width:y}=c.measureText(t),b=1.5,_=Math.ceil(Math.max(Math.abs(u)+Math.abs(f)||0,y)*b),w=Math.ceil(Math.max(Math.abs(p)+Math.abs(g)||h,Math.abs(m)+Math.abs(v)||h)*b);l=new OffscreenCanvas(_,w),c=l.getContext("2d",{alpha:!0,willReadFrequently:!0}),c.font=d,c.filter="grayscale(1)",c.fillStyle="white",c.fillRect(0,0,_,w),c.fillStyle="black",c.fillText(t,_*(b-1)/2,w*(3-b)/2);let A=this.#u(c.getImageData(0,0,_,w).data),x=this.#c(A),E=this.#h(x),T=this.#n(A,_,w,E);return this.processDrawnLines({lines:{curves:T,width:_,height:w},pageWidth:r,pageHeight:n,rotation:a,innerMargin:o,mustSmooth:!0,areContours:!0})}static process(t,e,s,i,r){let[n,a,o]=this.#f(t),[l,c]=this.#l(n,a,o,Math.hypot(a,o)*this.#t.sigmaSFactor,this.#t.sigmaR,this.#t.kernelSize),h=this.#h(c),d=this.#n(l,a,o,h);return this.processDrawnLines({lines:{curves:d,width:a,height:o},pageWidth:e,pageHeight:s,rotation:i,innerMargin:r,mustSmooth:!0,areContours:!0})}static processDrawnLines({lines:t,pageWidth:e,pageHeight:s,rotation:i,innerMargin:r,mustSmooth:n,areContours:a}){if(i%180!==0)[e,s]=[s,e];let{curves:o,width:l,height:c}=t,h=t.thickness??0,d=[],u=Math.min(e/l,s/c),f=u/e,p=u/s,g=[];for(let{points:v}of o){let y=n?this.#o(v):v;if(!y)continue;g.push(y);let b=y.length,_=new Float32Array(b),w=new Float32Array(3*(b===2?2:b-2));if(d.push({line:w,points:_}),b===2){_[0]=y[0]*f,_[1]=y[1]*p,w.set([NaN,NaN,NaN,NaN,_[0],_[1]],0);continue}let[A,x,E,T]=y;A*=f,x*=p,E*=f,T*=p,_.set([A,x,E,T],0),w.set([NaN,NaN,NaN,NaN,A,x],0);for(let k=4;k<b;k+=2){let C=_[k]=y[k]*f,R=_[k+1]=y[k+1]*p;w.set(H.createBezierPoints(A,x,E,T,C,R),(k-2)*3),[A,x,E,T]=[E,T,C,R]}}if(d.length===0)return null;let m=a?new ti:new es;return m.build(d,e,s,1,i,a?0:h,r),{outline:m,newCurves:g,areContours:a,thickness:h,width:l,height:c}}static async compressSignature({outlines:t,areContours:e,thickness:s,width:i,height:r}){let n=1/0,a=-1/0,o=0;for(let v of t){o+=v.length;for(let y=2,b=v.length;y<b;y++){let _=v[y]-v[y-2];n=Math.min(n,_),a=Math.max(a,_)}}let l;if(n>=-128&&a<=127)l=Int8Array;else if(n>=-32768&&a<=32767)l=Int16Array;else l=Int32Array;let c=t.length,h=Ls+ls*c,d=new Uint32Array(h),u=0;d[u++]=h*Uint32Array.BYTES_PER_ELEMENT+(o-2*c)*l.BYTES_PER_ELEMENT,d[u++]=0,d[u++]=i,d[u++]=r,d[u++]=e?0:1,d[u++]=Math.max(0,Math.floor(s??0)),d[u++]=c,d[u++]=l.BYTES_PER_ELEMENT;for(let v of t)d[u++]=v.length-2,d[u++]=v[0],d[u++]=v[1];let f=new CompressionStream("deflate-raw"),p=f.writable.getWriter();await p.ready,p.write(d);let g=l.prototype.constructor;for(let v of t){let y=new g(v.length-2);for(let b=2,_=v.length;b<_;b++)y[b-2]=v[b]-v[b-2];p.write(y)}return p.close(),(await new Response(f.readable).bytes()).toBase64()}static async decompressSignature(t){try{let e=Uint8Array.fromBase64(t),{readable:s,writable:i}=new DecompressionStream("deflate-raw"),r=i.getWriter();await r.ready,r.write(e).then(async()=>{await r.ready,await r.close()}).catch(()=>{});let n=null,a=0;for await(let y of s)n||=new Uint8Array(new Uint32Array(y.buffer,0,4)[0]),n.set(y,a),a+=y.length;let o=new Uint32Array(n.buffer,0,n.length>>2),l=o[1];if(l!==0)throw Error(`Invalid version: ${l}`);let c=o[2],h=o[3],d=o[4]===0,u=o[5],f=o[6],p=o[7],g=[],m=(Ls+ls*f)*Uint32Array.BYTES_PER_ELEMENT,v;switch(p){case Int8Array.BYTES_PER_ELEMENT:v=new Int8Array(n.buffer,m);break;case Int16Array.BYTES_PER_ELEMENT:v=new Int16Array(n.buffer,m);break;case Int32Array.BYTES_PER_ELEMENT:v=new Int32Array(n.buffer,m);break}a=0;for(let y=0;y<f;y++){let b=o[ls*y+Ls],_=new Float32Array(b+2);g.push(_);for(let w=0;w<ls-1;w++)_[w]=o[ls*y+Ls+w+1];for(let w=0;w<b;w++)_[w+2]=_[w]+v[a++]}return{areContours:d,thickness:u,outlines:g,width:c,height:h}}catch(e){return W(`decompressSignature: ${e}`),null}}}class Wr extends Ni{constructor(){super();super.updateProperties({fill:U._defaultLineColor,"stroke-width":0})}clone(){let t=new Wr;return t.updateAll(this),t}}class Xr extends ji{constructor(t){super(t);super.updateProperties({stroke:U._defaultLineColor,"stroke-width":1})}clone(){let t=new Xr(this._viewParameters);return t.updateAll(this),t}}class oe extends et{#t=!1;#e=null;#s=null;#i=null;#r=!1;static _type="signature";static _editorType=K.SIGNATURE;static _defaultDrawingOptions=null;constructor(t){super({...t,mustBeCommitted:!0,name:"signatureEditor"});this._willKeepAspectRatio=!0,this.#s=t.signatureData||null,this.#e=null,this.defaultL10nId="pdfjs-editor-signature-editor1"}static initialize(t,e){U.initialize(t,e),this._defaultDrawingOptions=new Wr,this._defaultDrawnSignatureOptions=new Xr(e.viewParameters)}static getDefaultDrawingOptions(t){let e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!1}static get typesMap(){return L(this,"typesMap",new Map)}static get isDrawer(){return!1}get telemetryFinalData(){return{type:"signature",hasDescription:!!this.#e}}static computeTelemetryFinalData(t){let e=t.get("hasDescription");return{hasAltText:e.get(!0)??0,hasNoAltText:e.get(!1)??0}}get isResizable(){return!0}onceAdded(t){this.#r=this._drawId===null,super.onceAdded(t)}onScaleChanging(){if(this._drawId===null)return;super.onScaleChanging()}render(){if(this.div)return this.div;let t,e,{_isCopy:s}=this;if(s)this._isCopy=!1,t=this.x,e=this.y;if(super.render(),this._drawId===null)if(this.#s){let{lines:i,mustSmooth:r,areContours:n,description:a,uuid:o,heightInPage:l}=this.#s,{rawDims:{pageWidth:c,pageHeight:h},rotation:d}=this.parent.viewport,u=Oe.processDrawnLines({lines:i,pageWidth:c,pageHeight:h,rotation:d,innerMargin:oe._INNER_MARGIN,mustSmooth:r,areContours:n});this.addSignature(u,l,a,o)}else this.div.setAttribute("data-l10n-args",JSON.stringify({description:""})),this.div.hidden=!0,this._uiManager.getSignature(this);else this.div.setAttribute("data-l10n-args",JSON.stringify({description:this.#e||""}));if(s)this._isCopy=!0,this._moveAfterPaste(t,e);return this.div}setUuid(t){this.#i=t,this.addEditToolbar()}getUuid(){return this.#i}get description(){return this.#e}set description(t){if(this.#e=t,!this.div)return;this.div.setAttribute("data-l10n-args",JSON.stringify({description:t})),super.addEditToolbar().then((e)=>{e?.updateEditSignatureButton(t)})}getSignaturePreview(){let{newCurves:t,areContours:e,thickness:s,width:i,height:r}=this.#s,n=Math.max(i,r),a=Oe.processDrawnLines({lines:{curves:t.map((o)=>({points:o})),thickness:s,width:i,height:r},pageWidth:n,pageHeight:n,rotation:0,innerMargin:0,mustSmooth:!1,areContours:e});return{areContours:e,outline:a.outline}}get toolbarButtons(){return this._uiManager.signatureManager?[["editSignature",this._uiManager.signatureManager]]:super.toolbarButtons}addSignature(t,e,s,i){let{x:r,y:n}=this,{outline:a}=this.#s=t;this.#t=a instanceof ti,this.description=s;let o;if(this.#t)o=oe.getDefaultDrawingOptions();else o=oe._defaultDrawnSignatureOptions.clone(),o.updateProperties({"stroke-width":a.thickness});this._addOutlines({drawOutlines:a,drawingOptions:o});let[,l]=this.pageDimensions,c=e/l;if(c=c>=1?0.5:c,this.width*=c/this.height,this.width>=1)c*=0.9/this.width,this.width=0.9;if(this.height=c,this.setDims(),this.x=r,this.y=n,this.center(),this._onResized(),this.onScaleChanging(),this.rotate(),this._uiManager.addToAnnotationStorage(this),this.setUuid(i),this._reportTelemetry({action:"pdfjs.signature.inserted",data:{hasBeenSaved:!!i,hasDescription:!!s}}),this.div.hidden=!1,this.#r)this.#r=!1,this.parent.addUndoableEditor(this)}getFromImage(t){let{rawDims:{pageWidth:e,pageHeight:s},rotation:i}=this.parent.viewport;return Oe.process(t,e,s,i,oe._INNER_MARGIN)}getFromText(t,e){let{rawDims:{pageWidth:s,pageHeight:i},rotation:r}=this.parent.viewport;return Oe.extractContoursFromText(t,e,s,i,r,oe._INNER_MARGIN)}getDrawnSignature(t){let{rawDims:{pageWidth:e,pageHeight:s},rotation:i}=this.parent.viewport;return Oe.processDrawnLines({lines:t,pageWidth:e,pageHeight:s,rotation:i,innerMargin:oe._INNER_MARGIN,mustSmooth:!1,areContours:!1})}createDrawingOptions({areContours:t,thickness:e}){if(t)this._drawingOptions=oe.getDefaultDrawingOptions();else this._drawingOptions=oe._defaultDrawnSignatureOptions.clone(),this._drawingOptions.updateProperties({"stroke-width":e})}serialize(t=!1){if(this.isEmpty())return null;let{lines:e,points:s}=this.serializeDraw(t),{_drawingOptions:{"stroke-width":i}}=this,r=Object.assign(super.serialize(t),{isSignature:!0,areContours:this.#t,color:[0,0,0],thickness:this.#t?0:i});if(this.addComment(r),t)r.paths={lines:e,points:s},r.uuid=this.#i,r.isCopy=!0;else r.lines=e;if(this.#e)r.accessibilityData={type:"Figure",alt:this.#e};return r}static deserializeDraw(t,e,s,i,r,n){if(n.areContours)return ti.deserialize(t,e,s,i,r,n);return es.deserialize(t,e,s,i,r,n)}static async deserialize(t,e,s){let i=await super.deserialize(t,e,s);return i.#t=t.areContours,i.description=t.accessibilityData?.alt||"",i.#i=t.uuid,i}}class Go extends U{#t=null;#e=null;#s=null;#i=null;#r=null;#n="";#a=null;#o=!1;#l=null;#c=!1;#u=!1;static _type="stamp";static _editorType=K.STAMP;constructor(t){super({...t,name:"stampEditor"});this.#i=t.bitmapUrl,this.#r=t.bitmapFile,this.defaultL10nId="pdfjs-editor-stamp-editor"}static initialize(t,e){U.initialize(t,e)}static isHandlingMimeForPasting(t){return Zi.has(t)}static paste(t,e){e.pasteEditor({mode:K.STAMP},{bitmapFile:t.getAsFile()})}altTextFinish(){if(this._uiManager.useNewAltTextFlow)this.div.hidden=!1;super.altTextFinish()}get telemetryFinalData(){return{type:"stamp",hasAltText:!!this.altTextData?.altText}}static computeTelemetryFinalData(t){let e=t.get("hasAltText");return{hasAltText:e.get(!0)??0,hasNoAltText:e.get(!1)??0}}#h(t,e=!1){if(!t){this.remove();return}if(this.#t=t.bitmap,!e)this.#e=t.id,this.#c=t.isSvg;if(t.file)this.#n=t.file.name;this.#m()}#f(){if(this.#s=null,this._uiManager.enableWaiting(!1),!this.#a)return;if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#t){this.addEditToolbar().then(()=>{this._editToolbar.hide(),this._uiManager.editAltText(this,!0)});return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#t){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}async mlGuessAltText(t=null,e=!0){if(this.hasAltTextData())return null;let{mlManager:s}=this._uiManager;if(!s)throw Error("No ML.");if(!await s.isEnabledFor("altText"))throw Error("ML isn't enabled for alt text.");let{data:i,width:r,height:n}=t||this.copyCanvas(null,null,!0).imageData,a=await s.guess({name:"altText",request:{data:i,width:r,height:n,channels:i.length/(r*n)}});if(!a)throw Error("No response from the AI service.");if(a.error)throw Error("Error from the AI service.");if(a.cancel)return null;if(!a.output)throw Error("No valid response from the AI service.");let o=a.output;if(await this.setGuessedAltText(o),e&&!this.hasAltTextData())this.altTextData={alt:o,decorative:!1};return o}#p(){if(this.#e){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(this.#e).then((s)=>this.#h(s,!0)).finally(()=>this.#f());return}if(this.#i){let s=this.#i;this.#i=null,this._uiManager.enableWaiting(!0),this.#s=this._uiManager.imageManager.getFromUrl(s).then((i)=>this.#h(i)).finally(()=>this.#f());return}if(this.#r){let s=this.#r;this.#r=null,this._uiManager.enableWaiting(!0),this.#s=this._uiManager.imageManager.getFromFile(s).then((i)=>this.#h(i)).finally(()=>this.#f());return}let t=document.createElement("input");t.type="file",t.accept=Zi.keys().join(",");let e=this._uiManager._signal;this.#s=new Promise((s)=>{t.addEventListener("change",async()=>{if(!t.files||t.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);let i=await this._uiManager.imageManager.getFromFile(t.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),this.#h(i)}s()},{signal:e}),t.addEventListener("cancel",()=>{this.remove(),s()},{signal:e})}).finally(()=>this.#f()),t.click()}remove(){if(this.#e){if(this.#t=null,this._uiManager.imageManager.deleteId(this.#e),this.#a?.remove(),this.#a=null,this.#l)clearTimeout(this.#l),this.#l=null}super.remove()}rebuild(){if(!this.parent){if(this.#e)this.#p();return}if(super.rebuild(),this.div===null)return;if(this.#e&&this.#a===null)this.#p();if(!this.isAttachedToDOM)this.parent.add(this)}onceAdded(t){if(this._isDraggable=!0,t)this.div.focus()}isEmpty(){return!(this.#s||this.#t||this.#i||this.#r||this.#e||this.#o)}get toolbarButtons(){return[["altText",this.createAltText()]]}get isResizable(){return!0}render(){if(this.div)return this.div;let t,e;if(this._isCopy)t=this.x,e=this.y;if(super.render(),this.div.hidden=!0,this.createAltText(),!this.#o)if(this.#t)this.#m();else this.#p();if(this._isCopy)this._moveAfterPaste(t,e);return this._uiManager.addShouldRescale(this),this.div}setCanvas(t,e){let{id:s,bitmap:i}=this._uiManager.imageManager.getFromCanvas(t,e);if(e.remove(),s&&this._uiManager.imageManager.isValidId(s)){if(this.#e=s,i)this.#t=i;this.#o=!1,this.#m()}}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;if(this.#l!==null)clearTimeout(this.#l);let t=200;this.#l=setTimeout(()=>{this.#l=null,this.#g()},t)}#m(){let{div:t}=this,{width:e,height:s}=this.#t,[i,r]=this.pageDimensions,n=0.75;if(this.width)e=this.width*i,s=this.height*r;else if(e>0.75*i||s>0.75*r){let o=Math.min(0.75*i/e,0.75*r/s);e*=o,s*=o}this._uiManager.enableWaiting(!1);let a=this.#a=document.createElement("canvas");if(a.setAttribute("role","img"),this.addContainer(a),this.width=e/i,this.height=s/r,this.setDims(),this._initialOptions?.isCentered)this.center();else this.fixAndSetPosition();if(this._initialOptions=null,!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)t.hidden=!1;if(this.#g(),!this.#u)this.parent.addUndoableEditor(this),this.#u=!0;if(this._reportTelemetry({action:"inserted_image"}),this.#n)this.div.setAttribute("aria-description",this.#n);if(!this.annotationElementId)this._uiManager.a11yAlert(U._l10nAlert.stamp)}copyCanvas(t,e,s=!1){t||=224;let{width:i,height:r}=this.#t,n=new Kt,a=this.#t,o=i,l=r,c=null;if(e){if(i>e||r>e){let w=Math.min(e/i,e/r);o=Math.floor(i*w),l=Math.floor(r*w)}c=document.createElement("canvas");let d=c.width=Math.ceil(o*n.sx),u=c.height=Math.ceil(l*n.sy);if(!this.#c)a=this.#d(d,u);let f=c.getContext("2d");f.filter=this._uiManager.hcmFilter;let p="white",g="#cfcfd8";if(this._uiManager.hcmFilter!=="none")g="black";else if(ca.isDarkMode)p="#8f8f9d",g="#42414d";let m=15,v=m*n.sx,y=m*n.sy,b=new OffscreenCanvas(v*2,y*2),_=b.getContext("2d");_.fillStyle=p,_.fillRect(0,0,v*2,y*2),_.fillStyle=g,_.fillRect(0,0,v,y),_.fillRect(v,y,v,y),f.fillStyle=f.createPattern(b,"repeat"),f.fillRect(0,0,d,u),f.drawImage(a,0,0,a.width,a.height,0,0,d,u)}let h=null;if(s){let d,u;if(n.symmetric&&a.width<t&&a.height<t)d=a.width,u=a.height;else if(a=this.#t,i>t||r>t){let g=Math.min(t/i,t/r);if(d=Math.floor(i*g),u=Math.floor(r*g),!this.#c)a=this.#d(d,u)}let p=new OffscreenCanvas(d,u).getContext("2d",{willReadFrequently:!0});p.drawImage(a,0,0,a.width,a.height,0,0,d,u),h={width:d,height:u,data:p.getImageData(0,0,d,u).data}}return{canvas:c,width:o,height:l,imageData:h}}#d(t,e){let{width:s,height:i}=this.#t,r=s,n=i,a=this.#t;while(r>2*t||n>2*e){let o=r,l=n;if(r>2*t)r=Math.ceil(r/2);if(n>2*e)n=Math.ceil(n/2);let c=new OffscreenCanvas(r,n);c.getContext("2d").drawImage(a,0,0,o,l,0,0,r,n),a=c.transferToImageBitmap()}return a}#g(){let[t,e]=this.parentDimensions,{width:s,height:i}=this,r=new Kt,n=Math.ceil(s*t*r.sx),a=Math.ceil(i*e*r.sy),o=this.#a;if(!o||o.width===n&&o.height===a)return;o.width=n,o.height=a;let l=this.#c?this.#t:this.#d(n,a),c=o.getContext("2d");c.filter=this._uiManager.hcmFilter,c.drawImage(l,0,0,l.width,l.height,0,0,n,a)}#v(t){if(t){if(this.#c){let i=this._uiManager.imageManager.getSvgUrl(this.#e);if(i)return i}let e=document.createElement("canvas");return{width:e.width,height:e.height}=this.#t,e.getContext("2d").drawImage(this.#t,0,0),e.toDataURL()}if(this.#c){let[e,s]=this.pageDimensions,i=Math.round(this.width*e*Le.PDF_TO_CSS_UNITS),r=Math.round(this.height*s*Le.PDF_TO_CSS_UNITS),n=new OffscreenCanvas(i,r);return n.getContext("2d").drawImage(this.#t,0,0,this.#t.width,this.#t.height,0,0,i,r),n.transferToImageBitmap()}return structuredClone(this.#t)}static async deserialize(t,e,s){let i=null,r=!1;if(t instanceof jr){let{data:{rect:p,rotation:g,id:m,structParent:v,popupRef:y,richText:b,contentsObj:_,creationDate:w,modificationDate:A},container:x,parent:{page:{pageNumber:E}},canvas:T}=t,k,C;if(T)delete t.canvas,{id:k,bitmap:C}=s.imageManager.getFromCanvas(x.id,T),T.remove();else r=!0,t._hasNoCanvas=!0;let R=(await e._structTree.getAriaAttributes(`${Ye}${m}`))?.get("aria-label")||"";i=t={annotationType:K.STAMP,bitmapId:k,bitmap:C,pageIndex:E-1,rect:p.slice(0),rotation:g,annotationElementId:m,id:m,deleted:!1,accessibilityData:{decorative:!1,altText:R},isSvg:!1,structParent:v,popupRef:y,richText:b,comment:_?.str||null,creationDate:w,modificationDate:A}}let n=await super.deserialize(t,e,s),{rect:a,bitmap:o,bitmapUrl:l,bitmapId:c,isSvg:h,accessibilityData:d}=t;if(r)s.addMissingCanvas(t.id,n),n.#o=!0;else if(c&&s.imageManager.isValidId(c)){if(n.#e=c,o)n.#t=o}else n.#i=l;n.#c=h;let[u,f]=n.pageDimensions;if(n.width=(a[2]-a[0])/u,n.height=(a[3]-a[1])/f,d)n.altTextData=d;if(n._initialData=i,t.comment)n.setCommentData(t);return n.#u=!!i,n}serialize(t=!1,e=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let s=Object.assign(super.serialize(t),{bitmapId:this.#e,isSvg:this.#c});if(this.addComment(s),t)return s.bitmapUrl=this.#v(!0),s.accessibilityData=this.serializeAltText(!0),s.isCopy=!0,s;let{decorative:i,altText:r}=this.serializeAltText(!1);if(!i&&r)s.accessibilityData={type:"Figure",alt:r};if(this.annotationElementId){let a=this.#y(s);if(a.isSame)return null;if(a.isSameAltText)delete s.accessibilityData;else{let o=this._initialData.structParent??-1;if(s.accessibilityData)s.accessibilityData.structParent=o;else if(o>=0)s.accessibilityData={type:"Figure",alt:"",structParent:o}}return s.id=this.annotationElementId,delete s.bitmapId,s}if(e===null)return s;e.stamps||=new Map;let n=this.#c?(s.rect[2]-s.rect[0])*(s.rect[3]-s.rect[1]):null;if(!e.stamps.has(this.#e))e.stamps.set(this.#e,{area:n,serialized:s}),s.bitmap=this.#v(!1);else if(this.#c){let a=e.stamps.get(this.#e);if(n>a.area)a.area=n,a.serialized.bitmap.close(),a.serialized.bitmap=this.#v(!1)}return s}#y(t){let{pageIndex:e,accessibilityData:{altText:s}}=this._initialData,i=t.pageIndex===e,r=(t.accessibilityData?.alt||"")===s;return{isSame:!this.hasEditedComment&&!this._hasBeenMoved&&!this._hasBeenResized&&i&&r,isSameAltText:r}}renderAnnotationElement(t){if(this.deleted)return t.hide(),null;return t.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null}}class fe{#t;#e=!1;#s=null;#i=null;#r=null;#n=new Map;#a=!1;#o=!1;#l=!1;#c=null;#u=null;#h=null;#f=null;#p=null;#m=-1;#d;static _initialized=!1;static#g=new Map([Pt,Vr,Go,ie,oe].map((t)=>[t._editorType,t]));constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:r,annotationLayer:n,drawLayer:a,textLayer:o,viewport:l,l10n:c}){let h=[...fe.#g.values()];if(!fe._initialized){fe._initialized=!0;for(let d of h)d.initialize(c,t)}t.registerEditorTypes(h),this.#d=t,this.pageIndex=e,this.div=s,this.#t=r,this.#s=n,this.viewport=l,this.#h=o,this.drawLayer=a,this._structTree=i,this.#d.addLayer(this)}get isEmpty(){return this.#n.size===0}get isInvisible(){return this.isEmpty&&this.#d.getMode()===K.NONE}updateToolbar(t){this.#d.updateToolbar(t)}updateMode(t=this.#d.getMode()){switch(this.#S(),t){case K.NONE:this.div.classList.toggle("nonEditing",!0),this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case K.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case K.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);let{classList:e}=this.div;if(e.toggle("nonEditing",!1),t===K.POPUP)e.toggle("commentEditing",!0);else{e.toggle("commentEditing",!1);for(let s of fe.#g.values())e.toggle(`${s._type}Editing`,t===s._editorType)}this.div.hidden=!1}hasTextLayer(t){return t===this.#h?.div}setEditingState(t){this.#d.setEditingState(t)}addCommands(t){this.#d.addCommands(t)}cleanUndoStack(t){this.#d.cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){this.#s?.togglePointerEvents(t)}get#v(){return this.#n.size!==0?this.#n.values():this.#d.getEditors(this.pageIndex)}async enable(){this.#l=!0,this.div.tabIndex=0,this.togglePointerEvents(!0),this.div.classList.toggle("nonEditing",!1),this.#p?.abort(),this.#p=null;let t=new Set;for(let s of this.#v)if(s.enableEditing(),s.show(!0),s.annotationElementId)this.#d.removeChangedExistingAnnotation(s),t.add(s.annotationElementId);let e=this.#s;if(e)for(let s of e.getEditableAnnotations()){if(s.hide(),this.#d.isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;let i=await this.deserialize(s);if(!i)continue;this.addOrRebuild(i),i.enableEditing()}this.#l=!1,this.#d._eventBus.dispatch("editorsrendered",{source:this,pageNumber:this.pageIndex+1})}disable(){if(this.#o=!0,this.div.tabIndex=-1,this.togglePointerEvents(!1),this.div.classList.toggle("nonEditing",!0),this.#h&&!this.#p){this.#p=new AbortController;let i=this.#d.combinedSignal(this.#p);this.#h.div.addEventListener("pointerdown",(r)=>{let{clientX:a,clientY:o,timeStamp:l}=r,c=this.#m;if(l-c>500){this.#m=l;return}this.#m=-1;let{classList:h}=this.div;h.toggle("getElements",!0);let d=document.elementsFromPoint(a,o);if(h.toggle("getElements",!1),!this.div.contains(d[0]))return;let u,f=new RegExp(`^${qe}[0-9]+$`);for(let g of d)if(f.test(g.id)){u=g.id;break}if(!u)return;let p=this.#n.get(u);if(p?.annotationElementId===null)Tt(r),p.dblclick(r)},{signal:i,capture:!0})}let t=this.#s,e=[];if(t){let i=new Map,r=new Map;for(let n of this.#v){if(n.disableEditing(),!n.annotationElementId){e.push(n);continue}if(n.serialize()!==null){i.set(n.annotationElementId,n);continue}else r.set(n.annotationElementId,n);this.getEditableAnnotation(n.annotationElementId)?.show(),n.remove()}for(let n of t.getEditableAnnotations()){let{id:a}=n.data;if(this.#d.isDeletedAnnotationElement(a)){n.updateEdited({deleted:!0});continue}let o=r.get(a);if(o){o.resetAnnotationElement(n),o.show(!1),n.show();continue}if(o=i.get(a),o){if(this.#d.addChangedExistingAnnotation(o),o.renderAnnotationElement(n))o.show(!1)}n.show()}}if(this.#S(),this.isEmpty)this.div.hidden=!0;let{classList:s}=this.div;for(let i of fe.#g.values())s.remove(`${i._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),t?.updateFakeAnnotations(e),this.#o=!1}getEditableAnnotation(t){return this.#s?.getEditableAnnotation(t)||null}setActiveEditor(t){if(this.#d.getActive()===t)return;this.#d.setActiveEditor(t)}enableTextSelection(){if(this.div.tabIndex=-1,this.#h?.div&&!this.#f){this.#f=new AbortController;let t=this.#d.combinedSignal(this.#f);this.#h.div.addEventListener("pointerdown",this.#y.bind(this),{signal:t}),this.#h.div.classList.add("highlighting")}}disableTextSelection(){if(this.div.tabIndex=0,this.#h?.div&&this.#f)this.#f.abort(),this.#f=null,this.#h.div.classList.remove("highlighting")}#y(t){this.#d.unselectAll();let{target:e}=t;if(e===this.#h.div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent")||e.classList.contains("textLayerImages")||e.classList.contains("textLayerImagePlaceholder"))&&this.#h.div.contains(e)){let{isMac:s}=lt.platform;if(t.button!==0||t.ctrlKey&&s)return;this.#d.showAllEditors("highlight",!0,!0),ie.startDrawing(this,this.#d,this.#d.direction==="ltr",t),t.preventDefault()}}enableClick(){if(this.#i)return;this.#i=new AbortController;let t=this.#d.combinedSignal(this.#i);this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});let e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){this.#i?.abort(),this.#i=null}attach(t){this.#n.set(t.id,t);let{annotationElementId:e}=t;if(e&&this.#d.isDeletedAnnotationElement(e))this.#d.removeDeletedAnnotationElement(t)}detach(t){if(this.#n.delete(t.id),this.#t?.removePointerInTextLayer(t.contentDiv),!this.#o&&t.annotationElementId)this.#d.addDeletedAnnotationElement(t)}remove(t){this.detach(t),this.#d.removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){if(t.parent===this)return;if(t.parent&&t.annotationElementId)this.#d.addDeletedAnnotationElement(t),U.deleteAnnotationElement(t),t.annotationElementId=null;if(this.attach(t),t.parent?.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM)t.div.remove(),this.div.append(t.div)}add(t){if(t.parent===this&&t.isAttachedToDOM)return;if(this.changeParent(t),this.#d.addEditor(t),this.attach(t),!t.isAttachedToDOM){let e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!this.#l),this.#d.addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}moveEditorInDOM(t){if(!t.isAttachedToDOM)return;let{activeElement:e}=document;if(t.div.contains(e)&&!this.#r)t._focusEventsAllowed=!1,this.#r=setTimeout(()=>{if(this.#r=null,!t.div.contains(document.activeElement))t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this.#d._signal}),e.focus();else t._focusEventsAllowed=!0},0);t._structTreeParentId=this.#t?.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){if(t.needsToBeRebuilt())t.parent||=this,t.rebuild(),t.show();else this.add(t)}addUndoableEditor(t){let e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getEditorByUID(t){for(let e of this.#n.values())if(e.uid===t)return e;return null}get#b(){return fe.#g.get(this.#d.getMode())}combinedSignal(t){return this.#d.combinedSignal(t)}#_(t){let e=this.#b;return e?new e.prototype.constructor(t):null}canCreateNewEmptyEditor(){return this.#b?.canCreateNewEmptyEditor()}async pasteEditor(t,e){this.updateToolbar(t),await this.#d.updateMode(t.mode);let{offsetX:s,offsetY:i}=this.#A(),r=this.#d.getId(),n=this.#_({parent:this,id:r,x:s,y:i,uiManager:this.#d,isCentered:!0,...e});if(n)this.add(n)}async deserialize(t){return await fe.#g.get(t.annotationType??t.annotationEditorType)?.deserialize(t,this,this.#d)||null}createAndAddNewEditor(t,e,s={}){let i=this.#d.getId(),r=this.#_({parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:this.#d,isCentered:e,...s});if(r)this.add(r);return r}get boundingClientRect(){return this.div.getBoundingClientRect()}#A(){let{x:t,y:e,width:s,height:i}=this.boundingClientRect,r=Math.max(0,t),n=Math.max(0,e),a=Math.min(window.innerWidth,t+s),o=Math.min(window.innerHeight,e+i),l=(r+a)/2-t,c=(n+o)/2-e,[h,d]=this.viewport.rotation%180===0?[l,c]:[c,l];return{offsetX:h,offsetY:d}}addNewEditor(t={}){this.createAndAddNewEditor(this.#A(),!0,t)}setSelected(t){this.#d.setSelected(t)}toggleSelected(t){this.#d.toggleSelected(t)}unselect(t){this.#d.unselect(t)}pointerup(t){let{isMac:e}=lt.platform;if(t.button!==0||t.ctrlKey&&e)return;if(t.target!==this.div)return;if(!this.#a)return;if(this.#a=!1,this.#b?.isDrawer&&this.#b.supportMultipleDrawings)return;if(!this.#e){this.#e=!0;return}let s=this.#d.getMode();if(s===K.STAMP||s===K.POPUP||s===K.SIGNATURE){this.#d.unselectAll();return}this.createAndAddNewEditor(t,!1)}pointerdown(t){if(this.#d.getMode()===K.HIGHLIGHT)this.enableTextSelection();if(this.#a){this.#a=!1;return}let{isMac:e}=lt.platform;if(t.button!==0||t.ctrlKey&&e)return;if(t.target!==this.div)return;if(this.#a=!0,this.#b?.isDrawer){this.startDrawingSession(t);return}let s=this.#d.getActive();this.#e=!s||s.isEmpty()}startDrawingSession(t){if(this.div.focus({preventScroll:!0}),this.#c){this.#b.startDrawing(this,this.#d,!1,t);return}this.#d.setCurrentDrawingSession(this),this.#c=new AbortController;let e=this.#d.combinedSignal(this.#c);this.div.addEventListener("blur",({relatedTarget:s})=>{if(s&&!this.div.contains(s))this.#u=null,this.commitOrRemove()},{signal:e}),this.#b.startDrawing(this,this.#d,!1,t)}pause(t){if(t){let{activeElement:e}=document;if(this.div.contains(e))this.#u=e;return}if(this.#u)setTimeout(()=>{this.#u?.focus(),this.#u=null},0)}endDrawingSession(t=!1){if(!this.#c)return null;return this.#d.setCurrentDrawingSession(null),this.#c.abort(),this.#c=null,this.#u=null,this.#b.endDrawing(t)}findNewParent(t,e,s){let i=this.#d.findParent(e,s);if(i===null||i===this)return!1;return i.changeParent(t),!0}commitOrRemove(){if(this.#c)return this.endDrawingSession(),!0;return!1}onScaleChanging(){if(!this.#c)return;this.#b.onScaleChangingWhenDrawing(this)}destroy(){if(this.commitOrRemove(),this.#d.getActive()?.parent===this)this.#d.commitOrRemove(),this.#d.setActiveEditor(null);if(this.#r)clearTimeout(this.#r),this.#r=null;for(let t of this.#n.values())this.#t?.removePointerInTextLayer(t.contentDiv),t.setParent(null),t.isAttachedToDOM=!1,t.div.remove();this.div=null,this.#n.clear(),this.#d.removeLayer(this)}#S(){for(let t of this.#n.values())if(t.isEmpty())t.remove()}async render({viewport:t}){this.viewport=t,Ne(this.div,t);for(let e of this.#d.getEditors(this.pageIndex))this.add(e),e.rebuild();await this.#d.findClonesForPage(this),this.div.hidden=this.isEmpty,this.updateMode()}update({viewport:t}){this.#d.commitOrRemove(),this.#S();let e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,Ne(this.div,{rotation:s}),e!==s)for(let i of this.#n.values())i.rotate(s)}get pageDimensions(){let{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return this.#d.viewParameters.realScale}}vc();function Nh(t,e){if(t===e)return 0;return t.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1}function Ns(t){if(!t)return null;return t.nodeType===Node.ELEMENT_NODE?t.closest(".textLayer"):t.parentElement?.closest(".textLayer")||null}function Bh(t,e,s,i){if(t===s)return e<=i;let r=t.compareDocumentPosition(s);if(r&Node.DOCUMENT_POSITION_FOLLOWING)return!0;if(r&Node.DOCUMENT_POSITION_PRECEDING)return!1;return null}function Cn(t,e,s){if(t.nodeType!==Node.ELEMENT_NODE||!t.classList.contains("textLayer")||e!==t.childNodes.length)return{container:t,offset:e};let i=t.lastChild;if(i?.nodeType===Node.ELEMENT_NODE&&i.classList.contains("endOfContent"))i=i.previousSibling;if(!i||!s.contains(i))return null;return i.nodeType===Node.TEXT_NODE?{container:i,offset:i.textContent.length}:{container:i,offset:i.childNodes.length}}class Y{#t=null;#e=new Map;#s=null;#i=null;#r=null;#n=null;#a=new Map;static#o=0;static#l=0;static#c=null;static#u=new Set;static#h=!1;static#f=new Set;static#p=new WeakMap;constructor({filterFactory:t=null,pageColors:e=null,pageIndex:s,textLayer:i=null}){if(this.pageIndex=s,this.#i=t,this.#r=e,i){let r=Y.#p.get(i);if(r?.selectionDiv)r.selectionDiv.remove(),Y.#u.delete(r.selectionDiv);if(Y.#p.set(i,{drawLayer:this}),Y.#f.add(i),this.#s=i,this.#n=new MutationObserver((n)=>{if(!this.#t||!this.#s?.isConnected||!Y.#d())return;for(let{addedNodes:a}of n)for(let o of a)if(o.nodeType===Node.ELEMENT_NODE&&o.classList.contains("endOfContent")){Y.#v();return}}),this.#n.observe(i,{childList:!0}),Y.#c===null){Y.#c=new AbortController;let{signal:n}=Y.#c;document.addEventListener("selectionchange",Y.#v.bind(Y),{signal:n}),document.addEventListener("pointerdown",()=>{Y.#h=!0},{signal:n}),document.addEventListener("pointerup",()=>{Y.#h=!1},{signal:n}),window.addEventListener("blur",()=>{Y.#h=!1},{signal:n})}}}setParent(t){if(!this.#t){if(this.#t=t,this.#s?.isConnected&&Y.#d())Y.#v();return}if(this.#t!==t){if(this.#e.size>0)for(let e of this.#e.values())e.remove(),t.append(e);this.#t=t}}static#m(t){let e=this.#p.get(t);if(!e?.selectionDiv)return;e.selectionDiv.remove(),this.#u.delete(e.selectionDiv),e.selectionDiv=null,e.path=null}static#d(){let t=document.getSelection();return!!t&&!t.isCollapsed}static#g(){return this.#f.keys().filter((t)=>t.isConnected).toArray().sort(Nh)}static#v(){let t=document.getSelection();if(!t||t.isCollapsed){for(let n of this.#u)n.remove();this.#u.clear();return}let e=new WeakMap,s=this.#g(),i=[];for(let n=0,a=t.rangeCount;n<a;n++){let o=t.getRangeAt(n);if(o.collapsed)continue;let{startContainer:l,startOffset:c,endContainer:h,endOffset:d}=o,u=Ns(l),f=Ns(h),p=u===null,g=f===null;if(this.#h&&p!==g)return;if(t.rangeCount===1){let{anchorNode:y,anchorOffset:b,focusNode:_,focusOffset:w}=t,A=Ns(y),x=Ns(_),E=Bh(y,b,_,w);if(A&&x&&E!==null)if(E)l=y,c=b,u=A,h=_,d=w,f=x;else l=_,c=w,u=x,h=y,d=b,f=A}let m=s.filter((y)=>o.intersectsNode(y));if(m.length===0)continue;let v=!1;if(!u)u=m[0],l=u,c=0,v=!0;if(!f)f=m.at(-1),h=f,d=f.childNodes.length,v=!0;if(h.nodeType===Node.ELEMENT_NODE){if(h.classList.contains("endOfContent")){let y=h.previousSibling;if(!y)continue;h=y,d=y.nodeType===Node.TEXT_NODE?y.textContent.length:y.childNodes.length}else if(h.classList.contains("textLayer")&&h.childNodes.length===d){let y=Cn(h,d,f);if(!y)continue;h=y.container,d=y.offset}}if(l.nodeType===Node.ELEMENT_NODE){let y=Cn(l,c,u);if(!y)continue;l=y.container,c=y.offset}if(u===f&&!v&&m.includes(u)){i.push([o,u]);continue}for(let y of m){let b=y.firstChild;if(!b)continue;let _=document.createRange();if(y===u)_.setStart(l,c);else _.setStartBefore(b);if(y===f)_.setEnd(h,d);else{let w=y.lastChild;if(!w)continue;if(w.nodeType===Node.ELEMENT_NODE&&w.classList.contains("endOfContent")){let A=w.previousSibling;if(!A)continue;_.setEndAfter(A)}else _.setEndAfter(w)}if(!_.collapsed)i.push([_,y])}}let r=new Set(i.map((n)=>n[1]));for(let n of this.#f)if(!r.has(n))this.#m(n);for(let[n,a]of i){let o=Y.#p.get(a);if(!o)continue;let l=e.get(a);if(!l){let f=a.getBoundingClientRect();l=(p,g,m,v)=>({x:(p-f.x)/f.width,y:(g-f.y)/f.height,width:m/f.width,height:v/f.height}),e.set(a,l)}let c=[];for(let{x:f,y:p,width:g,height:m}of n.getClientRects()){if(g===0||m===0)continue;if({x:f,y:p,width:g,height:m}=l(f,p,g,m),g===1&&m===1)continue;c.push(`M${f} ${p} h${g} v${m} h-${g} Z`)}if(c.length===0)continue;let{drawLayer:h,selectionDiv:d,path:u}=o;if(!d){let f=`clip_selection_${Y.#l++}`;d=document.createElement("div"),d.className="selection",d.style.clipPath=`url(#${f})`;let p=h.#i?.createSelectionStyle(h.#r);if(p)for(let[v,y]of Object.entries(p))d.style.setProperty(v,y);let g=Y._svgFactory.create(1,1,!0);g.setAttribute("aria-hidden","true"),g.setAttribute("width","100%"),g.setAttribute("height","100%");let m=Y._svgFactory.createElement("clipPath");m.setAttribute("id",f),m.setAttribute("clipPathUnits","objectBoundingBox"),u=Y._svgFactory.createElement("path"),m.append(u),g.append(m),d.append(g),o.path=u,o.selectionDiv=d}if(h.#t&&d.parentNode!==h.#t)h.#t.append(d),this.#u.add(d);u.setAttribute("d",c.join(" "))}}static get _svgFactory(){return L(this,"_svgFactory",new Fi)}static#y(t,[e,s,i,r]){let{style:n}=t;n.top=`${100*s}%`,n.left=`${100*e}%`,n.width=`${100*i}%`,n.height=`${100*r}%`}#b(){let t=Y._svgFactory.create(1,1,!0);return this.#t.append(t),t.setAttribute("aria-hidden","true"),t}#_(t,e){let s=Y._svgFactory.createElement("clipPath");t.append(s);let i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");let r=Y._svgFactory.createElement("use");return s.append(r),r.setAttribute("href",`#${e}`),r.classList.add("clip"),i}#A(t,e){for(let[s,i]of Object.entries(e))if(i===null)t.removeAttribute(s);else t.setAttribute(s,i)}draw(t,e=!1,s=!1){let i=Y.#o++,r=this.#b(),n=Y._svgFactory.createElement("defs");r.append(n);let a=Y._svgFactory.createElement("path");n.append(a);let o=`path_${i}`;if(a.setAttribute("id",o),a.setAttribute("vector-effect","non-scaling-stroke"),e)this.#a.set(i,a);let l=s?this.#_(n,o):null,c=Y._svgFactory.createElement("use");return r.append(c),c.setAttribute("href",`#${o}`),this.updateProperties(r,t),this.#e.set(i,r),{id:i,clipPathId:`url(#${l})`}}drawOutline(t,e){let s=Y.#o++,i=this.#b(),r=Y._svgFactory.createElement("defs");i.append(r);let n=Y._svgFactory.createElement("path");r.append(n);let a=`path_${s}`;n.setAttribute("id",a),n.setAttribute("vector-effect","non-scaling-stroke");let o;if(e){let h=Y._svgFactory.createElement("mask");r.append(h),o=`mask_${s}`,h.setAttribute("id",o),h.setAttribute("maskUnits","objectBoundingBox");let d=Y._svgFactory.createElement("rect");h.append(d),d.setAttribute("width","1"),d.setAttribute("height","1"),d.setAttribute("fill","white");let u=Y._svgFactory.createElement("use");h.append(u),u.setAttribute("href",`#${a}`),u.setAttribute("stroke","none"),u.setAttribute("fill","black"),u.setAttribute("fill-rule","nonzero"),u.classList.add("mask")}let l=Y._svgFactory.createElement("use");if(i.append(l),l.setAttribute("href",`#${a}`),o)l.setAttribute("mask",`url(#${o})`);let c=l.cloneNode();return i.append(c),l.classList.add("mainOutline"),c.classList.add("secondaryOutline"),this.updateProperties(i,t),this.#e.set(s,i),s}finalizeDraw(t,e){this.#a.delete(t),this.updateProperties(t,e)}updateProperties(t,e){if(!e)return;let{root:s,bbox:i,rootClass:r,path:n}=e,a=typeof t==="number"?this.#e.get(t):t;if(!a)return;if(s)this.#A(a,s);if(i)Y.#y(a,i);if(r){let{classList:o}=a;for(let[l,c]of Object.entries(r))o.toggle(l,c)}if(n){let l=a.firstElementChild.firstElementChild;this.#A(l,n)}}updateParent(t,e){if(e===this)return;let s=this.#e.get(t);if(!s)return;e.#t.append(s),this.#e.delete(t),e.#e.set(t,s)}remove(t){if(this.#a.delete(t),this.#t===null)return;this.#e.get(t).remove(),this.#e.delete(t)}destroy(){this.#t=null;for(let t of this.#e.values())t.remove();if(this.#e.clear(),this.#a.clear(),this.#n?.disconnect(),this.#n=null,this.#s){if(Y.#p.get(this.#s)?.drawLayer===this){if(Y.#m(this.#s),Y.#p.delete(this.#s),Y.#f.delete(this.#s),Y.#f.size===0)Y.#c?.abort(),Y.#c=null,Y.#h=!1}this.#s=null}}}function Bs(t){return`${(t*100).toFixed(2)}%`}class ei{#t=[];#e=new Map;#s=null;#i=0;#r=0;#n=0;static#a=null;constructor(t,e,s,i){this.#i=t,this.#t=e,this.#r=s.rawDims.pageWidth,this.#n=s.rawDims.pageHeight,this.#s=i}render(){let t=document.createElement("div");t.className="textLayerImages";for(let e=0;e<this.#t.length;e+=6){let s=this.#o(this.#t.subarray(e,e+6));if(s)t.append(s)}return t.addEventListener("contextmenu",(e)=>{if(!(e.target instanceof HTMLCanvasElement))return;let s=e.target,i=this.#e.get(s);if(!i)return;let r=ei.#a?.deref();if(r===s)return;if(r)r.width=0,r.height=0;ei.#a=new WeakRef(s);let{inverseTransform:n,x1:a,y1:o,width:l,height:c}=i,h=this.#s(),d=Math.ceil(a*h.width),u=Math.ceil(o*h.height),f=Math.floor((a+l/this.#r)*h.width),p=Math.floor((o+c/this.#n)*h.height);s.width=f-d,s.height=p-u;let g=s.getContext("2d");g.setTransform(...n),g.translate(-d,-u),g.drawImage(h,0,0)}),t}#o([t,e,s,i,r,n]){let a=Math.hypot((r-t)*this.#r,(n-e)*this.#n),o=Math.hypot((s-t)*this.#r,(i-e)*this.#n);if(a<this.#i||o<this.#i)return null;let l=[(r-t)*this.#r/a,(n-e)*this.#n/a,(s-t)*this.#r/o,(i-e)*this.#n/o,0,0],c=O.inverseTransform(l),h=document.createElement("canvas");return h.className="textLayerImagePlaceholder",h.width=0,h.height=0,Object.assign(h.style,{opacity:0,position:"absolute",left:Bs(t),top:Bs(e),width:Bs(a/this.#r),height:Bs(o/this.#n),transformOrigin:"0% 0%",transform:`matrix(${l.join(",")})`}),this.#e.set(h,{inverseTransform:c,width:a,height:o,x1:t,y1:e}),h}}globalThis._pdfjsTestingUtils={HighlightOutliner:Qs};globalThis.pdfjsLib={AbortException:ve,AnnotationEditorLayer:fe,AnnotationEditorParamsType:st,AnnotationEditorType:K,AnnotationEditorUIManager:Se,AnnotationLayer:Ur,AnnotationMode:we,AnnotationType:yt,applyOpacity:qc,build:Fh,ColorPicker:Qt,createValidAbsoluteUrl:ra,CSSConstants:ha,DOMSVGFactory:Fi,DrawLayer:Y,FeatureTest:lt,fetchData:Sr,findContrastColor:Jc,getDocument:Rr,getFilenameFromUrl:th,getPdfFilenameFromUrl:eh,getRGB:Es,getRGBA:ts,getUuid:oa,GlobalWorkerOptions:Zt,ImageKind:js,InvalidPDFException:Vs,isDataScheme:Ei,isPdfFile:Er,isValidExplicitDest:oh,makeArr:Ze,makeMap:Ws,makeObj:qi,makeSet:Kc,MathClamp:pt,noContextMenu:re,normalizeUnicode:Xc,OPS:pe,OutputScale:Kt,PasswordException:zs,PasswordResponses:$c,PDFDataRangeTransport:Dr,PDFDateString:Xs,PDFWorker:Ft,PermissionFlag:Uc,PixelsPerInch:Le,RenderingCancelledException:Si,renderRichText:da,ResponseException:gs,setLayerDimensions:Ne,shadow:L,SignatureExtractor:Oe,stopEvent:Tt,SupportedImageMimeTypes:Zi,TextLayer:Lt,TextLayerImages:ei,TouchManager:Cr,updateUrlHash:na,Util:O,VerbosityLevel:bi,version:Rh,XfaLayer:Ar};var Ps={maxBytes:104857600,maxPages:2000,maxCanvasPixels:16000000,maxImageWidth:4096};var zo=(t)=>Object.assign(Error(t),{name:"PdfTooLargeError"});async function Gh(t,e,s){if(e.aborted)return null;Zt.workerSrc=new URL(s,import.meta.url).href;let i=Rr({data:new Uint8Array(t),verbosity:0,stopAtErrors:!0,enableXfa:!1,maxImageSize:Ps.maxCanvasPixels,canvasMaxAreaInBytes:Ps.maxCanvasPixels*4}),r=()=>void i.destroy();e.addEventListener("abort",r,{once:!0});let n=async()=>{e.removeEventListener("abort",r),await i.destroy()};try{let a=await i.promise;if(a.numPages>Ps.maxPages)throw zo(`PDF has more than ${Ps.maxPages} pages`);let o=[];for(let h=1;h<=a.numPages;h++){let{width:d,height:u}=(await a.getPage(h)).getViewport({scale:1});if(e.aborted)return await n(),null;o.push({width:d,height:u})}return{pages:o,draw:async(h,d,u)=>{let f=await a.getPage(h+1);if(u.aborted)return null;let p=f.getViewport({scale:d/f.getViewport({scale:1}).width}),g=document.createElement("canvas");try{g.width=Math.round(p.width),g.height=Math.round(p.height);let m=f.render({canvas:g,viewport:p}),v=()=>m.cancel();u.addEventListener("abort",v,{once:!0});try{await m.promise}finally{u.removeEventListener("abort",v)}let y=await new Promise((b,_)=>g.toBlob((w)=>w?b(w):_(Error("The page could not be drawn")),"image/png"));if(u.aborted)return null;return{url:URL.createObjectURL(y),width:g.width,height:g.height}}finally{g.width=0,g.height=0,f.cleanup()}},textLayer:async(h,d,u)=>{let f=await a.getPage(h+1);if(u.aborted)return;let p=f.getViewport({scale:1}),g=d.cloneNode(!1);if(!(g instanceof HTMLElement))return;let m=new Lt({textContentSource:f.streamTextContent(),container:g,viewport:p}),v=()=>m.cancel();u.addEventListener("abort",v,{once:!0});try{await m.render()}finally{u.removeEventListener("abort",v)}if(u.aborted)return;for(let A of g.getAttributeNames())d.setAttribute(A,g.getAttribute(A)??"");let[y=0,b=0,_=0,w=0]=p.viewBox;d.style.width=`calc(var(--total-scale-factor) * ${_-y}px)`,d.style.height=`calc(var(--total-scale-factor) * ${w-b}px)`,d.replaceChildren(...g.childNodes)},close:n}}catch(a){if(await n(),e.aborted)return null;throw a}}export{Gh as openPdf};