@arcgis/core 5.2.0-next.155 → 5.2.0-next.156
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.
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/{d994bcf0a65d1c07160f.js → 0320cbd825f9a4222042.js} +1 -1
- package/assets/esri/core/workers/chunks/0590857215c547e63b51.js +1 -0
- package/assets/esri/core/workers/chunks/08fe248e412bb170210d.js +1 -0
- package/assets/esri/core/workers/chunks/0cb50bc2b2125c5fedf2.js +1 -0
- package/assets/esri/core/workers/chunks/1201b8c5852830836eac.js +1 -0
- package/assets/esri/core/workers/chunks/129e04d24ced77c9bb6d.js +1 -0
- package/assets/esri/core/workers/chunks/15e1117a706a98b17ad5.js +1 -0
- package/assets/esri/core/workers/chunks/164e74d586297946a717.js +1 -0
- package/assets/esri/core/workers/chunks/168a523bdc3653081f8a.js +1 -0
- package/assets/esri/core/workers/chunks/{6f4e6022a52de0c54aab.js → 172cfeb5f415e4662432.js} +1 -1
- package/assets/esri/core/workers/chunks/1aa4f5394a596e544aeb.js +1 -0
- package/assets/esri/core/workers/chunks/22b01fe31bbf0bdc48db.js +1 -0
- package/assets/esri/core/workers/chunks/27c2da2e779def2ee08b.js +1 -0
- package/assets/esri/core/workers/chunks/{481589c3eddad6e026ad.js → 369780276b2755361f7d.js} +1 -1
- package/assets/esri/core/workers/chunks/{2a226b69d38c72a47a08.js → 3914d96147642a9d4b01.js} +1 -1
- package/assets/esri/core/workers/chunks/{731018c0deffc41ffc97.js → 3e3e076fa5e8d5d5f33f.js} +1 -1
- package/assets/esri/core/workers/chunks/{96b6ea199ad949fef17c.js → 43cf862577bf37344ff4.js} +1 -1
- package/assets/esri/core/workers/chunks/4932773663469919d10a.js +1 -0
- package/assets/esri/core/workers/chunks/4996869b9cbd8c8ddcfa.js +1 -0
- package/assets/esri/core/workers/chunks/4c389472b8cdb0c55154.js +1 -0
- package/assets/esri/core/workers/chunks/4e4f747de424941a0bfa.js +1 -0
- package/assets/esri/core/workers/chunks/{eb815148ae65388dd733.js → 544070198d2ca556103a.js} +1 -1
- package/assets/esri/core/workers/chunks/5736feefa261589b6273.js +1 -0
- package/assets/esri/core/workers/chunks/{aeaaff7a4b1a99540f52.js → 5cb26bbaa08114aec5ce.js} +1 -1
- package/assets/esri/core/workers/chunks/6f73e41e14817acfaead.js +1 -0
- package/assets/esri/core/workers/chunks/{320e5942a098dd104366.js → 74137ffec5265628c33b.js} +1 -1
- package/assets/esri/core/workers/chunks/7446d0dfebf93e86c098.js +1 -0
- package/assets/esri/core/workers/chunks/{688f2dbf784e66082308.js → 74c866e0b66e61751861.js} +1 -1
- package/assets/esri/core/workers/chunks/7711ae5612f685078fc8.js +1 -0
- package/assets/esri/core/workers/chunks/{5116b569a8dbda4910c8.js → 784a2fba3e18286958d1.js} +1 -1
- package/assets/esri/core/workers/chunks/{f6e62d2d279a328cbed7.js → 7bcedf479b07a4b4a234.js} +1 -1
- package/assets/esri/core/workers/chunks/842893e75696428d536f.js +1 -0
- package/assets/esri/core/workers/chunks/8e19629899a5becf8e19.js +1 -0
- package/assets/esri/core/workers/chunks/950d4578dc450467404c.js +1 -0
- package/assets/esri/core/workers/chunks/{68be3fb88ca61f82fb90.js → 95dbbddac6581b9d671f.js} +1 -1
- package/assets/esri/core/workers/chunks/{900181f68449d8f82eeb.js → aa1ac7954e4f0fefe15b.js} +1 -1
- package/assets/esri/core/workers/chunks/ac24b4370dc7194a3107.js +1 -0
- package/assets/esri/core/workers/chunks/ace2e0a9d9013edd8624.js +1 -0
- package/assets/esri/core/workers/chunks/b1d5d236d5268fcbc74b.js +1 -0
- package/assets/esri/core/workers/chunks/{49ff0985fb307ac193ab.js → b573df59391ca41ee5a7.js} +1 -1
- package/assets/esri/core/workers/chunks/bac8c32665e982896ecc.js +1 -0
- package/assets/esri/core/workers/chunks/{f3da30d7300b92bd8bb0.js → befa32b9e7b3fbdd431e.js} +1 -1
- package/assets/esri/core/workers/chunks/{6c469b43089767176ced.js → c5ed67fdf261cbb1624b.js} +1 -1
- package/assets/esri/core/workers/chunks/d9b1aed88b205689cec6.js +1 -0
- package/assets/esri/core/workers/chunks/{c598b22f78ccc57f9d6d.js → dfd2dc5cdc97ffba8926.js} +1 -1
- package/assets/esri/core/workers/chunks/e1b7806ab3e1967b15f0.js +1 -0
- package/assets/esri/core/workers/chunks/eaddffcc7004101fc230.js +1 -0
- package/assets/esri/core/workers/chunks/eb2652ec48faa78de3c5.js +1 -0
- package/assets/esri/core/workers/chunks/{c62738f84c914671b143.js → f4a7aa3cdbc0c429c359.js} +1 -1
- package/assets/esri/themes/base/widgets/_OrientedImageryViewer.scss +4 -0
- package/assets/esri/themes/dark/main.css +1 -1
- package/assets/esri/themes/light/main.css +1 -1
- package/assets/esri/themes/light/view.css +1 -1
- package/config.d.ts +2 -0
- package/config.js +1 -1
- package/core/ObjectPool.js +1 -1
- package/core/PooledArray.js +1 -1
- package/core/accessorSupport/tracking/SimpleTrackingTarget.js +1 -1
- package/geometry/support/buffer/BufferPool.js +1 -1
- package/geometry/support/coordsUtils.js +1 -1
- package/kernel.js +1 -1
- package/layers/AnnotationFeatureLayer.d.ts +2 -2
- package/layers/AnnotationFeatureLayer.js +1 -1
- package/layers/CatalogLayer.d.ts +2 -2
- package/layers/CatalogLayer.js +1 -1
- package/layers/DimensionFeatureLayer.d.ts +2 -2
- package/layers/DimensionFeatureLayer.js +1 -1
- package/layers/FeatureLayer.d.ts +2 -2
- package/layers/FeatureLayer.js +1 -1
- package/layers/SubtypeGroupLayer.d.ts +2 -2
- package/layers/SubtypeGroupLayer.js +1 -1
- package/layers/geospatialPDF/GeospatialPDFFrame.js +1 -1
- package/layers/geospatialPDF/GeospatialPDFLayerWorker.js +9 -9
- package/layers/geospatialPDF/GeospatialPDFWorkerClient.js +1 -1
- package/layers/geospatialPDF/LGIDictMapFrame.js +1 -1
- package/layers/geospatialPDF/ViewportMeasureFrame.js +1 -1
- package/layers/geospatialPDF/geospatialPDFParserUtils.js +1 -1
- package/layers/graphics/controllers/FeatureTileController3D.js +1 -1
- package/layers/graphics/sources/parquet/FileProvider.js +1 -1
- package/layers/mixins/{FeatureLayerReload.d.ts → ReloadableLayer.d.ts} +5 -3
- package/layers/mixins/ReloadableLayer.js +2 -0
- package/layers/orientedImagery/core/coverageUtils.js +1 -1
- package/layers/raster/datasets/BaseRaster.js +1 -1
- package/layers/raster/datasets/GeospatialPDFRaster.js +1 -1
- package/layers/raster/datasets/ImageAuxRaster.js +1 -1
- package/layers/raster/datasets/ImageServerRaster.js +1 -1
- package/layers/raster/datasets/MRFRaster.js +1 -1
- package/layers/raster/datasets/TIFFRaster.js +1 -1
- package/layers/raster/datasets/WCSRaster.js +1 -1
- package/layers/raster/formats/ImageCanvasDecoder.js +1 -1
- package/layers/raster/formats/RasterCodec.js +1 -1
- package/layers/raster/formats/TiffDecoder.js +1 -1
- package/layers/raster/formats/Zlib.js +1 -1
- package/layers/support/RasterWorker.js +1 -1
- package/package.json +2 -2
- package/popup/FeatureModel.js +1 -1
- package/popup/FeaturesModel.js +1 -1
- package/request/process.js +1 -1
- package/request/types.d.ts +7 -0
- package/views/2d/engine/webgl/shaderGraph/techniques/vectorTiles/VTLTechniqueBackground.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/vectorTiles/VTLTechniqueFill.js +1 -1
- package/views/3d/analysis/DirectLineMeasurementAnalysisView3D.js +1 -1
- package/views/3d/analysis/LineOfSight/LineOfSightItemTool.js +1 -1
- package/views/3d/analysis/LineOfSight/LineOfSightPlacementController.js +1 -1
- package/views/3d/analysis/LineOfSight/{LineOfSightRootPlugin.js → LineOfSightPlacementRootPlugin.js} +1 -1
- package/views/3d/analysis/LineOfSight/LineOfSightTool.js +1 -1
- package/views/3d/analysis/Viewshed/ViewshedSubTool.js +1 -1
- package/views/3d/analysis/Viewshed/ViewshedTool.js +1 -1
- package/views/3d/interactive/editingTools/ManipulatedObject3DGraphic.js +1 -1
- package/views/3d/support/MemoryController.js +1 -1
- package/views/3d/webgl-engine/effects/RenderPluginManager.js +1 -1
- package/views/3d/webgl-engine/effects/geometry/RenderOccluded.js +1 -1
- package/widgets/BatchAttributeForm/inputs/support/DynamicChoiceController.js +1 -1
- package/widgets/HistogramRangeSlider.d.ts +2 -2
- package/widgets/HistogramRangeSlider.js +1 -1
- package/widgets/OrientedImageryViewer/OrientedImageryViewerViewModel.js +1 -1
- package/widgets/OrientedImageryViewer.js +2 -2
- package/widgets/PanoramicViewer/PanoramicVideoViewerViewModel.js +1 -1
- package/widgets/ScaleRangeSlider/ScaleRangeSliderViewModel.d.ts +5 -2
- package/widgets/ScaleRangeSlider/ScaleRangeSliderViewModel.js +1 -1
- package/widgets/ScaleRangeSlider.js +1 -1
- package/widgets/ValuePicker/ValuePickerBaseComponent.d.ts +5 -1
- package/widgets/ValuePicker/ValuePickerCollection.d.ts +2 -0
- package/widgets/ValuePicker/ValuePickerCombobox.d.ts +7 -1
- package/widgets/ValuePicker/ValuePickerLabel.d.ts +7 -1
- package/widgets/ValuePicker/ValuePickerSlider.d.ts +2 -0
- package/widgets/ValuePicker/ValuePickerSliderVisibleElements.d.ts +5 -1
- package/widgets/ValuePicker/ValuePickerVisibleElements.d.ts +5 -1
- package/widgets/ValuePicker/types.d.ts +2 -0
- package/assets/esri/core/workers/chunks/03261b9451e293a0fac8.js +0 -1
- package/assets/esri/core/workers/chunks/0ad0484ffcbe4ad21bd3.js +0 -1
- package/assets/esri/core/workers/chunks/19743dedaa40446259ec.js +0 -1
- package/assets/esri/core/workers/chunks/1c65ab9ed611c322ce27.js +0 -1
- package/assets/esri/core/workers/chunks/1f339247b68b061ab0a4.js +0 -1
- package/assets/esri/core/workers/chunks/251921cd10ecfbc89451.js +0 -1
- package/assets/esri/core/workers/chunks/3252b1fae363bb0129a0.js +0 -1
- package/assets/esri/core/workers/chunks/408e81c8f1eff8a7b379.js +0 -1
- package/assets/esri/core/workers/chunks/50036a323c2e7f155311.js +0 -1
- package/assets/esri/core/workers/chunks/55dcbf296d8d0092e473.js +0 -1
- package/assets/esri/core/workers/chunks/59b216b60464611742d4.js +0 -1
- package/assets/esri/core/workers/chunks/5bfea0c55aca826de536.js +0 -1
- package/assets/esri/core/workers/chunks/60d3056a31d982c9cad0.js +0 -1
- package/assets/esri/core/workers/chunks/6558488ea96620439f34.js +0 -1
- package/assets/esri/core/workers/chunks/6aebf7cfd294e88bf926.js +0 -1
- package/assets/esri/core/workers/chunks/6b43bb78f9839ed43135.js +0 -1
- package/assets/esri/core/workers/chunks/6c83398cf586ecea0eb1.js +0 -1
- package/assets/esri/core/workers/chunks/7267b17de212207142c9.js +0 -1
- package/assets/esri/core/workers/chunks/88c74f3316f1fc253207.js +0 -1
- package/assets/esri/core/workers/chunks/912080c90b5cc2e817cf.js +0 -1
- package/assets/esri/core/workers/chunks/a97d85774f9a417202df.js +0 -1
- package/assets/esri/core/workers/chunks/aff32980d91dab07dfb7.js +0 -1
- package/assets/esri/core/workers/chunks/b1b4066e8d1c0c9656e5.js +0 -1
- package/assets/esri/core/workers/chunks/b6ba66a05030d3815dfd.js +0 -1
- package/assets/esri/core/workers/chunks/bbec9d2e3b75a5c59681.js +0 -1
- package/assets/esri/core/workers/chunks/bf69024804ac51c8f733.js +0 -1
- package/assets/esri/core/workers/chunks/c1254cd131a62750ff6f.js +0 -1
- package/assets/esri/core/workers/chunks/d938987344bce83cc660.js +0 -1
- package/assets/esri/core/workers/chunks/db1ab9b9c8bf5c7635d3.js +0 -1
- package/assets/esri/core/workers/chunks/fd9663952d5a94f3a83f.js +0 -1
- package/layers/mixins/FeatureLayerReload.js +0 -2
- /package/views/3d/analysis/LineOfSight/{lineOfSightPlacementUtils.js → placementUtils.js} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
|
|
2
|
-
import{getAssetUrl as e}from"../../assets.js";import t from"../../request.js";import n from"../../core/Error.js";import{throwIfAborted as r}from"../../core/promiseUtils.js";import{create as i,fromValues as a}from"../../core/libs/gl-matrix-2/factories/mat2df64.js";import{invert as o}from"../../core/libs/gl-matrix-2/math/mat2d.js";import s from"../../geometry/Extent.js";import{projectIsLoaded as c,projectLoad as l}from"../../geometry/operators/projectOperator.js";import{renderBitmap as u}from"./renderExtentUtils.js";const d=!(typeof process!=`object`||process+``!=`[object process]`||process.versions.nw||process.versions.electron&&process.type&&process.type!==`browser`),f=[1/0,1/0,-1/0,-1/0],p=new Float32Array(f),m=[.001,0,0,.001,0,0],h=1.35,g={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},_=`pdfjs_internal_id_`,v=`pdfjs_internal_editor_`,y={NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15,POPUP:16,SIGNATURE:101},b={CREATE:2,FREETEXT_SIZE:11,FREETEXT_COLOR:12,INK_COLOR:21,INK_THICKNESS:22,INK_OPACITY:23,INK_COLOR_AND_OPACITY:24,HIGHLIGHT_COLOR:31,HIGHLIGHT_THICKNESS:32,HIGHLIGHT_FREE:33,HIGHLIGHT_SHOW_ALL:34,DRAW_STEP:41},x={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},S={WARNINGS:1,INFOS:5},C={dependency:1,setLineWidth:2,setLineCap:3,setLineJoin:4,setMiterLimit:5,setDash:6,setRenderingIntent:7,setFlatness:8,setGState:9,save:10,restore:11,transform:12,moveTo:13,lineTo:14,curveTo:15,curveTo2:16,curveTo3:17,closePath:18,rectangle:19,stroke:20,closeStroke:21,fill:22,eoFill:23,fillStroke:24,eoFillStroke:25,closeFillStroke:26,closeEOFillStroke:27,endPath:28,clip:29,eoClip:30,beginText:31,endText:32,setCharSpacing:33,setWordSpacing:34,setHScale:35,setLeading:36,setFont:37,setTextRenderingMode:38,setTextRise:39,moveText:40,setLeadingMoveText:41,setTextMatrix:42,nextLine:43,showText:44,showSpacedText:45,nextLineShowText:46,nextLineSetSpacingShowText:47,setCharWidth:48,setCharWidthAndBounds:49,setStrokeColorSpace:50,setFillColorSpace:51,setStrokeColor:52,setStrokeColorN:53,setFillColor:54,setFillColorN:55,setStrokeGray:56,setFillGray:57,setStrokeRGBColor:58,setFillRGBColor:59,setStrokeCMYKColor:60,setFillCMYKColor:61,shadingFill:62,beginInlineImage:63,beginImageData:64,endInlineImage:65,paintXObject:66,markPoint:67,markPointProps:68,beginMarkedContent:69,beginMarkedContentProps:70,endMarkedContent:71,beginCompat:72,endCompat:73,paintFormXObjectBegin:74,paintFormXObjectEnd:75,beginGroup:76,endGroup:77,beginAnnotation:80,endAnnotation:81,paintImageMaskXObject:83,paintImageMaskXObjectGroup:84,paintImageXObject:85,paintInlineImageXObject:86,paintInlineImageXObjectGroup:87,paintImageXObjectRepeat:88,paintImageMaskXObjectRepeat:89,paintSolidColorImageMask:90,constructPath:91,setStrokeTransparent:92,setFillTransparent:93,rawFillPath:94};let w=S.WARNINGS;function T(e){Number.isInteger(e)&&(w=e)}function E(){return w}function D(e){w>=S.INFOS&&console.info(`Info: ${e}`)}function O(e){w>=S.WARNINGS&&console.warn(`Warning: ${e}`)}function k(e){throw Error(e)}function A(e,t){e||k(t)}function ee(e,t=null,n=null){if(!e)return null;if(n&&typeof e==`string`){n.addDefaultProtocol&&e.startsWith(`www.`)&&e.match(/\./g)?.length>=2&&(e=`http://${e}`);if(n.tryConvertEncoding)try{e=function(e){return decodeURIComponent(escape(e))}(e)}catch{}}let r=t?URL.parse(e,t):URL.parse(e);return function(e){switch(e?.protocol){case`http:`:case`https:`:case`ftp:`:case`mailto:`:case`tel:`:return!0;default:return!1}}(r)?r:null}function te(e,t,n=!1){let r=URL.parse(e);if(r){r.hash=t;return r.href}return n&&ee(e,`http://example.com`)?e.split(`#`,1)[0]+``:``}function j(e,t,n,r=!1){Object.defineProperty(e,t,{value:n,enumerable:!r,configurable:!0,writable:!1});return n}const M=function(){function e(e,t){this.message=e;this.name=t}e.prototype=Error();e.constructor=e;return e}();class ne extends M{constructor(e,t){super(e,`PasswordException`);this.code=t}}class re extends M{constructor(e,t){super(e,`UnknownErrorException`);this.details=t}}class ie extends M{constructor(e){super(e,`InvalidPDFException`)}}class ae extends M{constructor(e,t,n){super(e,`ResponseException`);this.status=t;this.missing=n}}class oe extends M{constructor(e){super(e,`FormatError`)}}class se extends M{constructor(e){super(e,`AbortException`)}}function ce(e){typeof e!=`string`&&k(`Invalid argument for stringToBytes`);let t=e.length,n=new Uint8Array(t);for(let r=0;r<t;++r)n[r]=255&e.charCodeAt(r);return n}class N{static get isLittleEndian(){let e=new Uint8Array(4);e[0]=1;return j(this,`isLittleEndian`,new Uint32Array(e.buffer,0,1)[0]===1)}static get isOffscreenCanvasSupported(){return j(this,`isOffscreenCanvasSupported`,typeof OffscreenCanvas<`u`)}static get isImageDecoderSupported(){return j(this,`isImageDecoderSupported`,typeof ImageDecoder<`u`)}static get isFloat16ArraySupported(){return j(this,`isFloat16ArraySupported`,typeof Float16Array<`u`)}static get isSanitizerSupported(){return j(this,`isSanitizerSupported`,typeof Sanitizer<`u`)}static get platform(){let{platform:e,userAgent:t}=navigator;return j(this,`platform`,{isAndroid:t.includes(`Android`),isLinux:e.includes(`Linux`),isMac:e.includes(`Mac`),isWindows:e.includes(`Win`),isFirefox:t.includes(`Firefox`)})}static get isCanvasFilterSupported(){let e;this.isOffscreenCanvasSupported?e=new OffscreenCanvas(1,1).getContext(`2d`):typeof document<`u`&&(e=document.createElement(`canvas`).getContext(`2d`));return j(this,`isCanvasFilterSupported`,e?.filter!==void 0)}static get isAlphaColorInputSupported(){return j(this,`isAlphaColorInputSupported`,(()=>{if(typeof document>`u`)return!1;let e=document.createElement(`input`);e.type=`color`;e.setAttribute(`alpha`,``);e.value=`#ff000080`;return e.value!==`#ff0000`})())}}class P{static get hexNums(){return j(this,`hexNums`,Array.from(Array(256).keys(),e=>e.toString(16).padStart(2,`0`)))}static makeHexColor(e,t,n){return`#${this.hexNums[e]}${this.hexNums[t]}${this.hexNums[n]}`}static domMatrixToTransform(e){return[e.a,e.b,e.c,e.d,e.e,e.f]}static scaleMinMax(e,t){let n;if(e[0]){if(e[0]<0){n=t[0];t[0]=t[2];t[2]=n}t[0]*=e[0];t[2]*=e[0];if(e[3]<0){n=t[1];t[1]=t[3];t[3]=n}t[1]*=e[3];t[3]*=e[3]}else{n=t[0];t[0]=t[1];t[1]=n;n=t[2];t[2]=t[3];t[3]=n;if(e[1]<0){n=t[1];t[1]=t[3];t[3]=n}t[1]*=e[1];t[3]*=e[1];if(e[2]<0){n=t[0];t[0]=t[2];t[2]=n}t[0]*=e[2];t[2]*=e[2]}t[0]+=e[4];t[1]+=e[5];t[2]+=e[4];t[3]+=e[5]}static transform(e,t){return[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],e[0]*t[4]+e[2]*t[5]+e[4],e[1]*t[4]+e[3]*t[5]+e[5]]}static multiplyByDOMMatrix(e,t){return[e[0]*t.a+e[2]*t.b,e[1]*t.a+e[3]*t.b,e[0]*t.c+e[2]*t.d,e[1]*t.c+e[3]*t.d,e[0]*t.e+e[2]*t.f+e[4],e[1]*t.e+e[3]*t.f+e[5]]}static applyTransform(e,t,n=0){let r=e[n],i=e[n+1];e[n]=r*t[0]+i*t[2]+t[4];e[n+1]=r*t[1]+i*t[3]+t[5]}static applyTransformToBezier(e,t,n=0){let r=t[0],i=t[1],a=t[2],o=t[3],s=t[4],c=t[5];for(let t=0;t<6;t+=2){let l=e[n+t],u=e[n+t+1];e[n+t]=l*r+u*a+s;e[n+t+1]=l*i+u*o+c}}static applyInverseTransform(e,t){let n=e[0],r=e[1],i=t[0]*t[3]-t[1]*t[2];e[0]=(n*t[3]-r*t[2]+t[2]*t[5]-t[4]*t[3])/i;e[1]=(-n*t[1]+r*t[0]+t[4]*t[1]-t[5]*t[0])/i}static axialAlignedBoundingBox(e,t,n){let r=t[0],i=t[1],a=t[2],o=t[3],s=t[4],c=t[5],l=e[0],u=e[1],d=e[2],f=e[3],p=r*l+s,m=p,h=r*d+s,g=h,_=o*u+c,v=_,y=o*f+c,b=y;if(i!==0||a!==0){let e=i*l,t=i*d,n=a*u,r=a*f;p+=n;g+=n;h+=r;m+=r;_+=e;b+=e;y+=t;v+=t}n[0]=Math.min(n[0],p,h,m,g);n[1]=Math.min(n[1],_,y,v,b);n[2]=Math.max(n[2],p,h,m,g);n[3]=Math.max(n[3],_,y,v,b)}static inverseTransform(e){let t=e[0]*e[3]-e[1]*e[2];return[e[3]/t,-e[1]/t,-e[2]/t,e[0]/t,(e[2]*e[5]-e[4]*e[3])/t,(e[4]*e[1]-e[5]*e[0])/t]}static singularValueDecompose2dScale(e,t){let n=e[0],r=e[1],i=e[2],a=e[3],o=n**2+r**2,s=n*i+r*a,c=i**2+a**2,l=(o+c)/2,u=Math.sqrt(l**2-(o*c-s**2));t[0]=Math.sqrt(l+u||1);t[1]=Math.sqrt(l-u||1)}static normalizeRect(e){let t=e.slice(0);if(e[0]>e[2]){t[0]=e[2];t[2]=e[0]}if(e[1]>e[3]){t[1]=e[3];t[3]=e[1]}return t}static intersect(e,t){let n=Math.max(Math.min(e[0],e[2]),Math.min(t[0],t[2])),r=Math.min(Math.max(e[0],e[2]),Math.max(t[0],t[2]));if(n>r)return null;let i=Math.max(Math.min(e[1],e[3]),Math.min(t[1],t[3])),a=Math.min(Math.max(e[1],e[3]),Math.max(t[1],t[3]));return i>a?null:[n,i,r,a]}static pointBoundingBox(e,t,n){n[0]=Math.min(n[0],e);n[1]=Math.min(n[1],t);n[2]=Math.max(n[2],e);n[3]=Math.max(n[3],t)}static rectBoundingBox(e,t,n,r,i){i[0]=Math.min(i[0],e,n);i[1]=Math.min(i[1],t,r);i[2]=Math.max(i[2],e,n);i[3]=Math.max(i[3],t,r)}static#e(e,t,n,r,i,a,o,s,c,l){if(c<=0||c>=1)return;let u=1-c,d=c*c,f=d*c,p=u*(u*(u*e+3*c*t)+3*d*n)+f*r,m=u*(u*(u*i+3*c*a)+3*d*o)+f*s;l[0]=Math.min(l[0],p);l[1]=Math.min(l[1],m);l[2]=Math.max(l[2],p);l[3]=Math.max(l[3],m)}static#t(e,t,n,r,i,a,o,s,c,l,u,d){if(Math.abs(c)<1e-12){Math.abs(l)>=1e-12&&this.#e(e,t,n,r,i,a,o,s,-u/l,d);return}let f=l**2-4*u*c;if(f<0)return;let p=Math.sqrt(f),m=2*c;this.#e(e,t,n,r,i,a,o,s,(-l+p)/m,d);this.#e(e,t,n,r,i,a,o,s,(-l-p)/m,d)}static bezierBoundingBox(e,t,n,r,i,a,o,s,c){c[0]=Math.min(c[0],e,o);c[1]=Math.min(c[1],t,s);c[2]=Math.max(c[2],e,o);c[3]=Math.max(c[3],t,s);this.#t(e,n,i,o,t,r,a,s,3*(3*(n-i)-e+o),6*(e-2*n+i),3*(n-e),c);this.#t(e,n,i,o,t,r,a,s,3*(3*(r-a)-t+s),6*(t-2*r+a),3*(r-t),c)}}function le(){if(typeof crypto.randomUUID==`function`)return crypto.randomUUID();let e=new Uint8Array(32);crypto.getRandomValues(e);return function(e){typeof e==`object`&&e?.length!==void 0||k(`Invalid argument for bytesToString`);let t=e.length,n=8192;if(t<n)return String.fromCharCode.apply(null,e);let r=[];for(let i=0;i<t;i+=n){let a=Math.min(i+n,t),o=e.subarray(i,a);r.push(String.fromCharCode.apply(null,o))}return r.join(``)}(e)}const ue=()=>[],de=()=>new Map,fe=()=>Object.create(null);function F(e,t,n){return Math.min(Math.max(e,t),n)}class pe{static textContent(e){let t=[],n={items:t,styles:Object.create(null)};(function e(n){if(!n)return;let r=null,i=n.name;if(i===`#text`)r=n.value;else{if(!pe.shouldBuildText(i))return;n?.attributes?.textContent?r=n.attributes.textContent:n.value&&(r=n.value)}r!==null&&t.push({str:r});if(n.children)for(let t of n.children)e(t)})(e);return n}static shouldBuildText(e){return e!==`textarea`&&e!==`input`&&e!==`option`&&e!==`select`}}class me{static setupStorage(e,t,n,r,i){let a=r.getValue(t,{value:null});switch(n.name){case`textarea`:a.value!==null&&(e.textContent=a.value);if(i===`print`)break;e.addEventListener(`input`,e=>{r.setValue(t,{value:e.target.value})});break;case`input`:if(n.attributes.type===`radio`||n.attributes.type===`checkbox`){a.value===n.attributes.xfaOn?e.setAttribute(`checked`,!0):a.value===n.attributes.xfaOff&&e.removeAttribute(`checked`);if(i===`print`)break;e.addEventListener(`change`,e=>{r.setValue(t,{value:e.target.checked?e.target.getAttribute(`xfaOn`):e.target.getAttribute(`xfaOff`)})})}else{a.value!==null&&e.setAttribute(`value`,a.value);if(i===`print`)break;e.addEventListener(`input`,e=>{r.setValue(t,{value:e.target.value})})}break;case`select`:if(a.value!==null){e.setAttribute(`value`,a.value);for(let e of n.children)e.attributes.value===a.value?e.attributes.selected=!0:Object.hasOwn(e.attributes,`selected`)&&delete e.attributes.selected}e.addEventListener(`input`,e=>{let n=e.target.options,i=n.selectedIndex===-1?``:n[n.selectedIndex].value;r.setValue(t,{value:i})})}}static setAttributes({html:e,element:t,storage:n=null,intent:r,linkService:i}){let{attributes:a}=t,o=e instanceof HTMLAnchorElement;a.type===`radio`&&(a.name=`${a.name}-${r}`);for(let[t,n]of Object.entries(a))if(n!=null)switch(t){case`class`:n.length&&e.setAttribute(t,n.join(` `));break;case`dataId`:break;case`id`:e.setAttribute(`data-element-id`,n);break;case`style`:Object.assign(e.style,n);break;case`textContent`:e.textContent=n;break;default:(!o||t!==`href`&&t!==`newWindow`)&&e.setAttribute(t,n)}o&&i.addLinkAttributes(e,a.href,a.newWindow);n&&a.dataId&&this.setupStorage(e,a.dataId,t,n)}static render(e){let t=e.annotationStorage,n=e.linkService,r=e.xfaHtml,i=e.intent||`display`,a=document.createElement(r.name);r.attributes&&this.setAttributes({html:a,element:r,intent:i,linkService:n});let o=i!==`richText`,s=e.div;s.append(a);if(e.viewport){let t=`matrix(${e.viewport.transform.join(`,`)})`;s.style.transform=t}o&&s.setAttribute(`class`,`xfaLayer xfaFont`);let c=[];if(r.children.length===0){if(r.value){let e=document.createTextNode(r.value);a.append(e);o&&pe.shouldBuildText(r.name)&&c.push(e)}return{textDivs:c}}let l=[[r,-1,a]];for(;l.length>0;){let[e,r,a]=l.at(-1);if(r+1===e.children.length){l.pop();continue}let s=e.children[++l.at(-1)[1]];if(s===null)continue;let{name:u}=s;if(u===`#text`){let e=document.createTextNode(s.value);c.push(e);a.append(e);continue}let d=s?.attributes?.xmlns?document.createElementNS(s.attributes.xmlns,u):document.createElement(u);a.append(d);s.attributes&&this.setAttributes({html:d,element:s,storage:t,intent:i,linkService:n});if(s.children?.length>0)l.push([s,-1,d]);else if(s.value){let e=document.createTextNode(s.value);o&&pe.shouldBuildText(u)&&c.push(e);d.append(e)}}for(let e of s.querySelectorAll(`.xfaNonInteractive input, .xfaNonInteractive textarea`))e.setAttribute(`readOnly`,!0);return{textDivs:c}}static update(e){let t=`matrix(${e.viewport.transform.join(`,`)})`;e.div.style.transform=t;e.div.hidden=!1}}const I=`http://www.w3.org/2000/svg`;class he{static CSS=96;static PDF=72;static PDF_TO_CSS_UNITS=this.CSS/this.PDF}async function ge(e,t=`text`){if(Se(e,document.baseURI)){let n=await fetch(e);if(!n.ok)throw Error(n.statusText);switch(t){case`blob`:return n.blob();case`bytes`:return n.bytes();case`json`:return n.json()}return n.text()}return new Promise((n,r)=>{let i=new XMLHttpRequest;i.open(`GET`,e,!0);i.responseType=t===`bytes`?`arraybuffer`:t;i.onreadystatechange=()=>{if(i.readyState===XMLHttpRequest.DONE){if(i.status!==200&&i.status!==0)r(Error(i.statusText));else{switch(t){case`bytes`:n(new Uint8Array(i.response));return;case`blob`:case`json`:n(i.response);return}n(i.responseText)}}};i.send(null)})}class _e{constructor({viewBox:e,userUnit:t,scale:n,rotation:r,offsetX:i=0,offsetY:a=0,dontFlip:o=!1}){this.viewBox=e;this.userUnit=t;this.scale=n;this.rotation=r;this.offsetX=i;this.offsetY=a;n*=t;let s=(e[2]+e[0])/2,c=(e[3]+e[1])/2,l,u,d,f,p,m,h,g;(r%=360)<0&&(r+=360);switch(r){case 180:l=-1;u=0;d=0;f=1;break;case 90:l=0;u=1;d=1;f=0;break;case 270:l=0;u=-1;d=-1;f=0;break;case 0:l=1;u=0;d=0;f=-1;break;default:throw Error(`PageViewport: Invalid rotation, must be a multiple of 90 degrees.`)}if(o){d=-d;f=-f}if(l===0){p=Math.abs(c-e[1])*n+i;m=Math.abs(s-e[0])*n+a;h=(e[3]-e[1])*n;g=(e[2]-e[0])*n}else{p=Math.abs(s-e[0])*n+i;m=Math.abs(c-e[1])*n+a;h=(e[2]-e[0])*n;g=(e[3]-e[1])*n}this.transform=[l*n,u*n,d*n,f*n,p-l*n*s-d*n*c,m-u*n*s-f*n*c];this.width=h;this.height=g}get rawDims(){let e=this.viewBox;return j(this,`rawDims`,{pageWidth:e[2]-e[0],pageHeight:e[3]-e[1],pageX:e[0],pageY:e[1]})}clone({scale:e=this.scale,rotation:t=this.rotation,offsetX:n=this.offsetX,offsetY:r=this.offsetY,dontFlip:i=!1}={}){return new _e({viewBox:this.viewBox.slice(),userUnit:this.userUnit,scale:e,rotation:t,offsetX:n,offsetY:r,dontFlip:i})}convertToViewportPoint(e,t){let n=[e,t];P.applyTransform(n,this.transform);return n}convertToViewportRectangle(e){let t=[e[0],e[1]];P.applyTransform(t,this.transform);let n=[e[2],e[3]];P.applyTransform(n,this.transform);return[t[0],t[1],n[0],n[1]]}convertToPdfPoint(e,t){let n=[e,t];P.applyInverseTransform(n,this.transform);return n}}class ve extends M{constructor(e,t=0){super(e,`RenderingCancelledException`);this.extraDelay=t}}function ye(e){let t=e.length,n=0;for(;n<t&&e[n].trim()===``;)n++;return e.substring(n,n+5).toLowerCase()===`data:`}function be(e){return typeof e==`string`&&/\.pdf$/i.test(e)}class xe{#e=new Map;times=[];time(e){this.#e.has(e)&&O(`Timer is already running for ${e}`);this.#e.set(e,Date.now())}timeEnd(e){this.#e.has(e)||O(`Timer has not been started for ${e}`);this.times.push({name:e,start:this.#e.get(e),end:Date.now()});this.#e.delete(e)}toString(){let e=Math.max(...this.times.map(e=>e.name.length));return this.times.map(t=>`${t.name.padEnd(e)} ${t.end-t.start}ms\n`).join(``)}}function Se(e,t){let n=t?URL.parse(e,t):URL.parse(e);return/https?:/.test(n?.protocol??``)}function L(e){e.preventDefault()}function R(e){e.preventDefault();e.stopPropagation()}class Ce{static#e;static toDateObject(e){if(e instanceof Date)return e;if(!e||typeof e!=`string`)return null;this.#e||=RegExp(`^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?`);let t=this.#e.exec(e);if(!t)return null;let n=parseInt(t[1],10),r=parseInt(t[2],10);r=r>=1&&r<=12?r-1:0;let i=parseInt(t[3],10);i=i>=1&&i<=31?i:1;let a=parseInt(t[4],10);a=a>=0&&a<=23?a:0;let o=parseInt(t[5],10);o=o>=0&&o<=59?o:0;let s=parseInt(t[6],10);s=s>=0&&s<=59?s:0;let c=t[7]||`Z`,l=parseInt(t[8],10);l=l>=0&&l<=23?l:0;let u=parseInt(t[9],10)||0;u=u>=0&&u<=59?u:0;if(c===`-`){a+=l;o+=u}else if(c===`+`){a-=l;o-=u}return new Date(Date.UTC(n,r,i,a,o,s))}}function we(e){if(e.startsWith(`#`)){let t=e.slice(1);return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16),t.length>=8?parseInt(t.slice(6,8),16)/255:1]}if(e.startsWith(`rgb(`)){let[t,n,r]=e.slice(4,-1).split(`,`).map(e=>parseInt(e,10));return[t,n,r,1]}if(e.startsWith(`rgba(`)){let t=e.slice(5,-1).split(`,`);return[parseInt(t[0],10),parseInt(t[1],10),parseInt(t[2],10),parseFloat(t[3])]}let t=e.match(/^color\(srgb\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)(?:\s*\/\s*([\d.]+|none))?\)$/);return t?[Math.round(255*parseFloat(t[1])),Math.round(255*parseFloat(t[2])),Math.round(255*parseFloat(t[3])),t[4]!==void 0&&t[4]!==`none`?parseFloat(t[4]):1]:null}function Te(e){let t=we(e);if(!t){O(`Not a valid color format: "${e}"`);return[0,0,0]}return t.slice(0,3)}function z(e){let{a:t,b:n,c:r,d:i,e:a,f:o}=e.getTransform();return[t,n,r,i,a,o]}function Ee(e){let{a:t,b:n,c:r,d:i,e:a,f:o}=e.getTransform().invertSelf();return[t,n,r,i,a,o]}function De(e,t,n=!1,r=!0){if(t instanceof _e){let{pageWidth:r,pageHeight:i}=t.rawDims,{style:a}=e,o=`round(down, var(--total-scale-factor) * ${r}px, var(--scale-round-x))`,s=`round(down, var(--total-scale-factor) * ${i}px, var(--scale-round-y))`;if(n&&t.rotation%180!=0){a.width=s;a.height=o}else{a.width=o;a.height=s}}r&&e.setAttribute(`data-main-rotation`,t.rotation)}class Oe{constructor(){let{pixelRatio:e}=Oe;this.sx=e;this.sy=e}get scaled(){return this.sx!==1||this.sy!==1}get symmetric(){return this.sx===this.sy}limitCanvas(e,t,n,r,i=-1){let a=1/0,o=1/0,s=1/0;(n=Oe.capPixels(n,i))>0&&(a=Math.sqrt(n/(e*t)));if(r!==-1){o=r/e;s=r/t}let c=Math.min(a,o,s);if(this.sx>c||this.sy>c){this.sx=c;this.sy=c;return!0}return!1}static get pixelRatio(){return globalThis.devicePixelRatio||1}static capPixels(e,t){if(t>=0){let n=Math.ceil(window.screen.availWidth*window.screen.availHeight*this.pixelRatio**2*(1+t/100));return e>0?Math.min(e,n):n}return e}}const ke=[`image/apng`,`image/avif`,`image/bmp`,`image/gif`,`image/jpeg`,`image/png`,`image/svg+xml`,`image/webp`,`image/x-icon`];class Ae{static get isDarkMode(){return j(this,`isDarkMode`,!!window?.matchMedia?.(`(prefers-color-scheme: dark)`).matches)}}function je({html:e,dir:t,className:n},r){let i=document.createDocumentFragment();if(typeof e==`string`){let n=document.createElement(`p`);n.dir=t||`auto`;let r=e.split(/(?:\r\n?|\n)/);for(let e=0,t=r.length;e<t;++e){let i=r[e];n.append(document.createTextNode(i));e<t-1&&n.append(document.createElement(`br`))}i.append(n)}else me.render({xfaHtml:e,div:i,intent:`richText`});i.firstElementChild.classList.add(`richText`,n);r.append(i)}function Me(e){let t=new Path2D;if(!e)return t;for(let n=0,r=e.length;n<r;)switch(e[n++]){case 0:t.moveTo(e[n++],e[n++]);break;case 1:t.lineTo(e[n++],e[n++]);break;case 2:t.bezierCurveTo(e[n++],e[n++],e[n++],e[n++],e[n++],e[n++]);break;case 3:t.quadraticCurveTo(e[n++],e[n++],e[n++],e[n++]);break;case 4:t.closePath();break;default:O(`Unrecognized drawing path operator: ${e[n-1]}`)}return t}class Ne{#e=null;#t=null;#n;#r=null;#i=null;#a=null;#o=null;#s=null;static#c=null;constructor(e){this.#n=e;Ne.#c||=Object.freeze({freetext:`pdfjs-editor-remove-freetext-button`,highlight:`pdfjs-editor-remove-highlight-button`,ink:`pdfjs-editor-remove-ink-button`,stamp:`pdfjs-editor-remove-stamp-button`,signature:`pdfjs-editor-remove-signature-button`})}render(){let e=this.#e=document.createElement(`div`);e.classList.add(`editToolbar`,`hidden`);e.setAttribute(`role`,`toolbar`);let t=this.#n._uiManager._signal;if(t instanceof AbortSignal&&!t.aborted){e.addEventListener(`contextmenu`,L,{signal:t});e.addEventListener(`pointerdown`,Ne.#l,{signal:t})}let n=this.#r=document.createElement(`div`);n.className=`buttons`;e.append(n);let r=this.#n.toolbarPosition;if(r){let{style:t}=e;t.insetInlineEnd=100*(this.#n._uiManager.direction===`ltr`?1-r[0]:r[0])+`%`;t.top=`calc(${100*r[1]}% + var(--editor-toolbar-vert-offset))`}return e}get div(){return this.#e}static#l(e){e.stopPropagation()}#u(e){this.#n._focusEventsAllowed=!1;R(e)}#d(e){this.#n._focusEventsAllowed=!0;R(e)}#f(e){let t=this.#n._uiManager._signal;if(!(t instanceof AbortSignal)||t.aborted)return!1;e.addEventListener(`focusin`,this.#u.bind(this),{capture:!0,signal:t});e.addEventListener(`focusout`,this.#d.bind(this),{capture:!0,signal:t});e.addEventListener(`contextmenu`,L,{signal:t});return!0}hide(){this.#e.classList.add(`hidden`);this.#t?.hideDropdown()}show(){this.#e.classList.remove(`hidden`);this.#i?.shown();this.#a?.shown()}addDeleteButton(){let{editorType:e,_uiManager:t}=this.#n,n=document.createElement(`button`);n.classList.add(`basic`,`deleteButton`);n.tabIndex=0;n.setAttribute(`data-l10n-id`,Ne.#c[e]);this.#f(n)&&n.addEventListener(`click`,e=>{t.delete()},{signal:t._signal});this.#r.append(n)}get#p(){let e=document.createElement(`div`);e.className=`divider`;return e}async addAltText(e){let t=await e.render();this.#f(t);this.#r.append(t,this.#p);this.#i=e}addComment(e,t=null){if(this.#a)return;let n=e.renderForToolbar();if(!n)return;this.#f(n);let r=this.#o=this.#p;if(t){this.#r.insertBefore(n,t);this.#r.insertBefore(r,t)}else this.#r.append(n,r);this.#a=e;e.toolbar=this}addColorPicker(e){if(this.#t)return;this.#t=e;let t=e.renderButton();this.#f(t);this.#r.append(t,this.#p)}async addEditSignatureButton(e){let t=this.#s=await e.renderEditButton(this.#n);this.#f(t);this.#r.append(t,this.#p)}removeButton(e){if(e===`comment`){this.#a?.removeToolbarCommentButton();this.#a=null;this.#o?.remove();this.#o=null}}async addButton(e,t){switch(e){case`colorPicker`:t&&this.addColorPicker(t);break;case`altText`:t&&await this.addAltText(t);break;case`editSignature`:t&&await this.addEditSignatureButton(t);break;case`delete`:this.addDeleteButton();break;case`comment`:t&&this.addComment(t)}}async addButtonBefore(e,t,n){if(!t&&e===`comment`)return;let r=this.#r.querySelector(n);r&&e===`comment`&&this.addComment(t,r)}updateEditSignatureButton(e){this.#s&&(this.#s.title=e)}remove(){this.#e.remove();this.#t?.destroy();this.#t=null}}class Pe{#e=null;#t=null;#n;constructor(e){this.#n=e}#r(){let e=this.#t=document.createElement(`div`);e.className=`editToolbar`;e.setAttribute(`role`,`toolbar`);let t=this.#n._signal;t instanceof AbortSignal&&!t.aborted&&e.addEventListener(`contextmenu`,L,{signal:t});let n=this.#e=document.createElement(`div`);n.className=`buttons`;e.append(n);this.#n.hasCommentManager()&&this.#a(`commentButton`,`pdfjs-comment-floating-button`,`pdfjs-comment-floating-button-label`,()=>{this.#n.commentSelection(`floating_button`)});this.#a(`highlightButton`,`pdfjs-highlight-floating-button1`,`pdfjs-highlight-floating-button-label`,()=>{this.#n.highlightSelection(`floating_button`)});return e}#i(e,t){let n=0,r=0;for(let i of e){let e=i.y+i.height;if(e<n)continue;let a=i.x+(t?i.width:0);if(e>n){r=a;n=e}else t?a>r&&(r=a):a<r&&(r=a)}return[t?1-r:r,n]}show(e,t,n){let[r,i]=this.#i(t,n),{style:a}=this.#t||=this.#r();e.append(this.#t);a.insetInlineEnd=100*r+`%`;a.top=`calc(${100*i}% + var(--editor-toolbar-vert-offset))`}hide(){this.#t.remove()}#a(e,t,n,r){let i=document.createElement(`button`);i.classList.add(`basic`,e);i.tabIndex=0;i.setAttribute(`data-l10n-id`,t);let a=document.createElement(`span`);i.append(a);a.className=`visuallyHidden`;a.setAttribute(`data-l10n-id`,n);let o=this.#n._signal;if(o instanceof AbortSignal&&!o.aborted){i.addEventListener(`contextmenu`,L,{signal:o});i.addEventListener(`click`,r,{signal:o})}this.#e.append(i)}}function Fe(e,t,n){for(let r of n)t.addEventListener(r,e[r].bind(e))}class B{static#e=NaN;static#t=null;static#n=NaN;static#r=null;static initializeAndAddPointerId(e){(B.#t||=new Set).add(e)}static setPointer(e,t){B.#e||=t;B.#r??=e}static setTimeStamp(e){B.#n=e}static isSamePointerId(e){return B.#e===e}static isSamePointerIdOrRemove(e){if(B.#e===e)return!0;B.#t?.delete(e);return!1}static isSamePointerType(e){return B.#r===e}static isInitializedAndDifferentPointerType(e){return B.#r!==null&&!B.isSamePointerType(e)}static isSameTimeStamp(e){return B.#n===e}static isUsingMultiplePointers(){return B.#t?.size>=1}static clearPointerType(){B.#r=null}static clearPointerIds(){B.#e=NaN;B.#t=null}static clearTimeStamp(){B.#n=NaN}}class Ie{#e=0;get id(){return`${v}${this.#e++}`}}class Le{#e=le();#t=0;#n=null;static get _isSVGFittingCanvas(){let e=new OffscreenCanvas(1,3).getContext(`2d`,{willReadFrequently:!0}),t=new Image;t.src=`data:image/svg+xml;charset=UTF-8,<svg viewBox="0 0 1 1" width="1" height="1" xmlns="http://www.w3.org/2000/svg"><rect width="1" height="1" style="fill:red;"/></svg>`;return j(this,`_isSVGFittingCanvas`,t.decode().then(()=>{e.drawImage(t,0,0,1,1,0,0,1,3);return new Uint32Array(e.getImageData(0,0,1,1).data.buffer)[0]===0}))}async#r(e,t){this.#n||=new Map;let n=this.#n.get(e);if(n===null)return null;if(n?.bitmap){n.refCounter+=1;return n}try{n||={bitmap:null,id:`image_${this.#e}_${this.#t++}`,refCounter:0,isSvg:!1};let e;if(typeof t==`string`){n.url=t;e=await ge(t,`blob`)}else t instanceof File?e=n.file=t:t instanceof Blob&&(e=t);if(e.type===`image/svg+xml`){let t=Le._isSVGFittingCanvas,r=new FileReader,i=new Image,a=new Promise((e,a)=>{i.onload=()=>{n.bitmap=i;n.isSvg=!0;e()};r.onload=async()=>{let e=n.svgUrl=r.result;i.src=await t?`${e}#svgView(preserveAspectRatio(none))`:e};i.onerror=r.onerror=a});r.readAsDataURL(e);await a}else n.bitmap=await createImageBitmap(e);n.refCounter=1}catch(e){O(e);n=null}this.#n.set(e,n);n&&this.#n.set(n.id,n);return n}async getFromFile(e){let{lastModified:t,name:n,size:r,type:i}=e;return this.#r(`${t}_${n}_${r}_${i}`,e)}async getFromUrl(e){return this.#r(e,e)}async getFromBlob(e,t){let n=await t;return this.#r(e,n)}async getFromId(e){this.#n||=new Map;let t=this.#n.get(e);if(!t)return null;if(t.bitmap){t.refCounter+=1;return t}if(t.file)return this.getFromFile(t.file);if(t.blobPromise){let{blobPromise:e}=t;delete t.blobPromise;return this.getFromBlob(t.id,e)}return this.getFromUrl(t.url)}getFromCanvas(e,t){this.#n||=new Map;let n=this.#n.get(e);if(n?.bitmap){n.refCounter+=1;return n}let r=new OffscreenCanvas(t.width,t.height);r.getContext(`2d`).drawImage(t,0,0);n={bitmap:r.transferToImageBitmap(),id:`image_${this.#e}_${this.#t++}`,refCounter:1,isSvg:!1};this.#n.set(e,n);this.#n.set(n.id,n);return n}getSvgUrl(e){let t=this.#n.get(e);return t?.isSvg?t.svgUrl:null}deleteId(e){this.#n||=new Map;let t=this.#n.get(e);if(!t)return;--t.refCounter;if(t.refCounter!==0)return;let{bitmap:n}=t;if(!t.url&&!t.file){let e=new OffscreenCanvas(n.width,n.height);e.getContext(`bitmaprenderer`).transferFromImageBitmap(n);t.blobPromise=e.convertToBlob()}n.close?.();t.bitmap=null}isValidId(e){return e.startsWith(`image_${this.#e}_`)}}class Re{#e=[];#t=!1;#n;#r=-1;constructor(e=128){this.#n=e}add({cmd:e,undo:t,post:n,mustExec:r,type:i=NaN,overwriteIfSameType:a=!1,keepUndo:o=!1}){r&&e();if(this.#t)return;let s={cmd:e,undo:t,post:n,type:i};if(this.#r===-1){this.#e.length>0&&(this.#e.length=0);this.#r=0;this.#e.push(s);return}if(a&&this.#e[this.#r].type===i){o&&(s.undo=this.#e[this.#r].undo);this.#e[this.#r]=s;return}let c=this.#r+1;if(c===this.#n)this.#e.splice(0,1);else{this.#r=c;c<this.#e.length&&this.#e.splice(c)}this.#e.push(s)}undo(){if(this.#r===-1)return;this.#t=!0;let{undo:e,post:t}=this.#e[this.#r];e();t?.();this.#t=!1;--this.#r}redo(){if(this.#r<this.#e.length-1){this.#r+=1;this.#t=!0;let{cmd:e,post:t}=this.#e[this.#r];e();t?.();this.#t=!1}}hasSomethingToUndo(){return this.#r!==-1}hasSomethingToRedo(){return this.#r<this.#e.length-1}cleanType(e){if(this.#r!==-1){for(let t=this.#r;t>=0;t--)if(this.#e[t].type!==e){this.#e.splice(t+1,this.#r-t);this.#r=t;return}this.#e.length=0;this.#r=-1}}destroy(){this.#e=null}}class ze{constructor(e){this.buffer=[];this.callbacks=new Map;this.allKeys=new Set;let{isMac:t}=N.platform;for(let[n,r,i={}]of e)for(let e of n){let n=e.startsWith(`mac+`);if(t&&n){this.callbacks.set(e.slice(4),{callback:r,options:i});this.allKeys.add(e.split(`+`).at(-1))}else if(!t&&!n){this.callbacks.set(e,{callback:r,options:i});this.allKeys.add(e.split(`+`).at(-1))}}}#e(e){e.altKey&&this.buffer.push(`alt`);e.ctrlKey&&this.buffer.push(`ctrl`);e.metaKey&&this.buffer.push(`meta`);e.shiftKey&&this.buffer.push(`shift`);this.buffer.push(e.key);let t=this.buffer.join(`+`);this.buffer.length=0;return t}exec(e,t){if(!this.allKeys.has(t.key))return;let n=this.callbacks.get(this.#e(t));if(!n)return;let{callback:r,options:{bubbles:i=!1,args:a=[],checker:o=null}}=n;if(!o||o(e,t)){r.bind(e,...a,t)();i||R(t)}}}class Be{static _colorsMapping=new Map([[`CanvasText`,[0,0,0]],[`Canvas`,[255,255,255]]]);get _colors(){let e=new Map([[`CanvasText`,null],[`Canvas`,null]]);(function(e){let t=document.createElement(`span`);t.style.visibility=`hidden`;t.style.colorScheme=`only light`;document.body.append(t);for(let n of e.keys()){t.style.color=n;let r=window.getComputedStyle(t).color;e.set(n,Te(r))}t.remove()})(e);return j(this,`_colors`,e)}convert(e){let t=Te(e);if(!window.matchMedia(`(forced-colors: active)`).matches)return t;for(let[e,n]of this._colors)if(n.every((e,n)=>e===t[n]))return Be._colorsMapping.get(e);return t}getHexCode(e){let t=this._colors.get(e);return t?P.makeHexColor(...t):e}}class Ve{#e=new AbortController;#t=null;#n=null;#r=new Map;#i=new Map;#a=null;#o=null;#s=null;#c=null;#l=new Re;#u=null;#d=null;#f=null;#p=0;#m=new Set;#h=null;#g=null;#_=new Set;_editorUndoBar=null;#v=!1;#y=!1;#b=!1;#x=null;#S=null;#C=null;#w=null;#T=!1;#E=null;#D=new Ie;#O=!1;#k=!1;#A=!1;#j=null;#M=null;#N=null;#P=null;#F=null;#I=y.NONE;#L=new Set;#R=null;#z=null;#B=null;#V=null;#H=null;#U={isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1};#W=[0,0];#G=null;#K=null;#q=null;#J=null;#Y=null;static TRANSLATE_SMALL=1;static TRANSLATE_BIG=10;static get _keyboardManager(){let e=Ve.prototype,t=e=>e.#K.contains(document.activeElement)&&document.activeElement.tagName!==`BUTTON`&&e.hasSomethingToControl(),n=(e,{target:t})=>{if(t instanceof HTMLInputElement){let{type:e}=t;return e!==`text`&&e!==`number`}return!0},r=this.TRANSLATE_SMALL,i=this.TRANSLATE_BIG;return j(this,`_keyboardManager`,new ze([[[`ctrl+a`,`mac+meta+a`],e.selectAll,{checker:n}],[[`ctrl+z`,`mac+meta+z`],e.undo,{checker:n}],[[`ctrl+y`,`ctrl+shift+z`,`mac+meta+shift+z`,`ctrl+shift+Z`,`mac+meta+shift+Z`],e.redo,{checker:n}],[[`Backspace`,`alt+Backspace`,`ctrl+Backspace`,`shift+Backspace`,`mac+Backspace`,`mac+alt+Backspace`,`mac+ctrl+Backspace`,`Delete`,`ctrl+Delete`,`shift+Delete`,`mac+Delete`],e.delete,{checker:n}],[[`Enter`,`mac+Enter`],e.addNewEditorFromKeyboard,{checker:(e,{target:t})=>!(t instanceof HTMLButtonElement)&&e.#K.contains(t)&&!e.isEnterHandled}],[[` `,`mac+ `],e.addNewEditorFromKeyboard,{checker:(e,{target:t})=>!(t instanceof HTMLButtonElement)&&e.#K.contains(document.activeElement)}],[[`Escape`,`mac+Escape`],e.unselectAll],[[`ArrowLeft`,`mac+ArrowLeft`],e.translateSelectedEditors,{args:[-r,0],checker:t}],[[`ctrl+ArrowLeft`,`mac+shift+ArrowLeft`],e.translateSelectedEditors,{args:[-i,0],checker:t}],[[`ArrowRight`,`mac+ArrowRight`],e.translateSelectedEditors,{args:[r,0],checker:t}],[[`ctrl+ArrowRight`,`mac+shift+ArrowRight`],e.translateSelectedEditors,{args:[i,0],checker:t}],[[`ArrowUp`,`mac+ArrowUp`],e.translateSelectedEditors,{args:[0,-r],checker:t}],[[`ctrl+ArrowUp`,`mac+shift+ArrowUp`],e.translateSelectedEditors,{args:[0,-i],checker:t}],[[`ArrowDown`,`mac+ArrowDown`],e.translateSelectedEditors,{args:[0,r],checker:t}],[[`ctrl+ArrowDown`,`mac+shift+ArrowDown`],e.translateSelectedEditors,{args:[0,i],checker:t}]]))}constructor(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){let g=this._signal=this.#e.signal;this.#K=e;this.#q=t;this.#J=n;this.#o=r;this.#u=i;this.#z=a;this.#H=s;this._eventBus=o;o._on(`editingaction`,this.onEditingAction.bind(this),{signal:g});o._on(`pagechanging`,this.onPageChanging.bind(this),{signal:g});o._on(`scalechanging`,this.onScaleChanging.bind(this),{signal:g});o._on(`rotationchanging`,this.onRotationChanging.bind(this),{signal:g});o._on(`setpreference`,this.onSetPreference.bind(this),{signal:g});o._on(`switchannotationeditorparams`,e=>this.updateParams(e.type,e.value),{signal:g});window.addEventListener(`pointerdown`,()=>{this.#k=!0},{capture:!0,signal:g});window.addEventListener(`pointerup`,()=>{this.#k=!1},{capture:!0,signal:g});window.addEventListener(`beforeunload`,this.#Q.bind(this),{capture:!0,signal:g});this.#ne();this.#le();this.#ae();this.#s=s.annotationStorage;this.#x=s.filterFactory;this.#B=c;this.#w=l||null;this.#v=u;this.#y=d;this.#b=f;this.#F=p||null;this.viewParameters={realScale:he.PDF_TO_CSS_UNITS,rotation:0};this.isShiftKeyDown=!1;this._editorUndoBar=m||null;this._supportsPinchToZoom=!1!==h;i?.setSidebarUiManager(this)}destroy(){this.#Y?.resolve();this.#Y=null;this.#e?.abort();this.#e=null;this._signal=null;for(let e of this.#i.values())e.destroy();this.#i.clear();this.#r.clear();this.#_.clear();this.#P?.clear();this.#t=null;this.#L.clear();this.#l.destroy();this.#o?.destroy();this.#u?.destroy();this.#z?.destroy();this.#E?.hide();this.#E=null;this.#N?.destroy();this.#N=null;this.#n=null;if(this.#S){clearTimeout(this.#S);this.#S=null}if(this.#G){clearTimeout(this.#G);this.#G=null}this._editorUndoBar?.destroy();this.#H=null}combinedSignal(e){return AbortSignal.any([this._signal,e.signal])}get mlManager(){return this.#F}get useNewAltTextFlow(){return this.#y}get useNewAltTextWhenAddingImage(){return this.#b}get hcmFilter(){return j(this,`hcmFilter`,this.#B?this.#x.addHCMFilter(this.#B.foreground,this.#B.background):`none`)}get direction(){return j(this,`direction`,getComputedStyle(this.#K).direction)}get _highlightColors(){return j(this,`_highlightColors`,this.#w?new Map(this.#w.split(`,`).map(e=>{(e=e.split(`=`).map(e=>e.trim()))[1]=e[1].toUpperCase();return e})):null)}get highlightColors(){let{_highlightColors:e}=this;if(!e)return j(this,`highlightColors`,null);let t=new Map,n=!!this.#B;for(let[r,i]of e){let e=r.endsWith(`_HCM`);n&&e?t.set(r.replace(`_HCM`,``),i):n||e||t.set(r,i)}return j(this,`highlightColors`,t)}get highlightColorNames(){return j(this,`highlightColorNames`,this.highlightColors?new Map(Array.from(this.highlightColors,e=>e.reverse())):null)}getNonHCMColor(e){if(!this._highlightColors)return e;let t=this.highlightColorNames.get(e);return this._highlightColors.get(t)||e}getNonHCMColorName(e){return this.highlightColorNames.get(e)||e}setCurrentDrawingSession(e){if(e){this.unselectAll();this.disableUserSelect(!0)}else this.disableUserSelect(!1);this.#f=e}setMainHighlightColorPicker(e){this.#N=e}editAltText(e,t=!1){this.#o?.editAltText(this,e,t)}hasCommentManager(){return!!this.#u}editComment(e,t,n,r){this.#u?.showDialog(this,e,t,n,r)}selectComment(e,t){(this.#i.get(e)?.getEditorByUID(t))?.toggleComment(!0,!0)}updateComment(e){this.#u?.updateComment(e.getData())}updatePopupColor(e){this.#u?.updatePopupColor(e)}removeComment(e){this.#u?.removeComments([e.uid])}deleteComment(e,t){let n=()=>{e.comment=t};this.addCommands({cmd:()=>{this._editorUndoBar?.show(n,`comment`);this.toggleComment(null);e.comment=null},undo:n,mustExec:!0})}toggleComment(e,t,n=void 0){this.#u?.toggleCommentPopup(e,t,n)}makeCommentColor(e,t){return e&&this.#u?.makeCommentColor(e,t)||null}getCommentDialogElement(){return this.#u?.dialogElement||null}async waitForEditorsRendered(e){if(this.#i.has(e-1))return;let{resolve:t,promise:n}=Promise.withResolvers(),r=n=>{if(n.pageNumber===e){this._eventBus._off(`editorsrendered`,r);t()}};this._eventBus.on(`editorsrendered`,r);await n}getSignature(e){this.#z?.getSignature({uiManager:this,editor:e})}get signatureManager(){return this.#z}switchToMode(e,t){this._eventBus.on(`annotationeditormodechanged`,t,{once:!0,signal:this._signal});this._eventBus.dispatch(`showannotationeditorui`,{source:this,mode:e})}setPreference(e,t){this._eventBus.dispatch(`setpreference`,{source:this,name:e,value:t})}onSetPreference({name:e,value:t}){e===`enableNewAltTextWhenAddingImage`&&(this.#b=t)}onPageChanging({pageNumber:e}){this.#p=e-1}deletePage(e){for(let t of this.getEditors(e))t.remove();this.#i.delete(e);this.#p===e&&(this.#p=0)}focusMainContainer(){this.#K.focus()}findParent(e,t){for(let n of this.#i.values()){let{x:r,y:i,width:a,height:o}=n.div.getBoundingClientRect();if(e>=r&&e<=r+a&&t>=i&&t<=i+o)return n}return null}disableUserSelect(e=!1){this.#q.classList.toggle(`noUserSelect`,e)}addShouldRescale(e){this.#_.add(e)}removeShouldRescale(e){this.#_.delete(e)}onScaleChanging({scale:e}){this.commitOrRemove();this.viewParameters.realScale=e*he.PDF_TO_CSS_UNITS;for(let e of this.#_)e.onScaleChanging();this.#f?.onScaleChanging()}onRotationChanging({pagesRotation:e}){this.commitOrRemove();this.viewParameters.rotation=e}#X({anchorNode:e}){return e.nodeType===Node.TEXT_NODE?e.parentElement:e}#Z(e){let{currentLayer:t}=this;if(t.hasTextLayer(e))return t;for(let t of this.#i.values())if(t.hasTextLayer(e))return t;return null}highlightSelection(e=``,t=!1){let n=document.getSelection();if(!n||n.isCollapsed)return;let{anchorNode:r,anchorOffset:i,focusNode:a,focusOffset:o}=n,s=n.toString(),c=this.#X(n).closest(`.textLayer`),l=this.getSelectionBoxes(c);if(!l)return;n.empty();let u=this.#Z(c),d=this.#I===y.NONE,f=()=>{let n=u?.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:e,boxes:l,anchorNode:r,anchorOffset:i,focusNode:a,focusOffset:o,text:s});d&&this.showAllEditors(`highlight`,!0,!0);t&&n?.editComment()};d?this.switchToMode(y.HIGHLIGHT,f):f()}commentSelection(e=``){this.highlightSelection(e,!0)}#Q(e){this.commitOrRemove();this.currentLayer?.endDrawingSession(!1)}#$(){let e=document.getSelection();if(!e||e.isCollapsed)return;let t=this.#X(e).closest(`.textLayer`),n=this.getSelectionBoxes(t);if(n){this.#E||=new Pe(this);this.#E.show(t,n,this.direction===`ltr`)}}getAndRemoveDataFromAnnotationStorage(e){if(!this.#s)return null;let t=`${v}${e}`,n=this.#s.getRawValue(t);n&&this.#s.remove(t);return n}addToAnnotationStorage(e){e.isEmpty()||!this.#s||this.#s.has(e.id)||this.#s.setValue(e.id,e)}a11yAlert(e,t=null){let n=this.#J;if(n){n.setAttribute(`data-l10n-id`,e);t?n.setAttribute(`data-l10n-args`,JSON.stringify(t)):n.removeAttribute(`data-l10n-args`)}}#ee(){let e=document.getSelection();if(!e||e.isCollapsed){if(this.#R){this.#E?.hide();this.#R=null;this.#ue({hasSelectedText:!1})}return}let{anchorNode:t}=e;if(t===this.#R)return;let n=this.#X(e).closest(`.textLayer`);if(n){this.#E?.hide();this.#R=t;this.#ue({hasSelectedText:!0});if(this.#I===y.HIGHLIGHT||this.#I===y.NONE){this.#I===y.HIGHLIGHT&&this.showAllEditors(`highlight`,!0,!0);this.#T=this.isShiftKeyDown;if(!this.isShiftKeyDown){let e=this.#I===y.HIGHLIGHT?this.#Z(n):null;e?.toggleDrawing();if(this.#k){let t=new AbortController,n=this.combinedSignal(t),r=n=>{if(n.type!==`pointerup`||n.button===0){t.abort();e?.toggleDrawing(!0);n.type===`pointerup`&&this.#te(`main_toolbar`)}};window.addEventListener(`pointerup`,r,{signal:n});window.addEventListener(`blur`,r,{signal:n})}else{e?.toggleDrawing(!0);this.#te(`main_toolbar`)}}}}else if(this.#R){this.#E?.hide();this.#R=null;this.#ue({hasSelectedText:!1})}}#te(e=``){this.#I===y.HIGHLIGHT?this.highlightSelection(e):this.#v&&this.#$()}#ne(){document.addEventListener(`selectionchange`,this.#ee.bind(this),{signal:this._signal})}#re(){if(this.#C)return;this.#C=new AbortController;let e=this.combinedSignal(this.#C);window.addEventListener(`focus`,this.focus.bind(this),{signal:e});window.addEventListener(`blur`,this.blur.bind(this),{signal:e})}#ie(){this.#C?.abort();this.#C=null}blur(){this.isShiftKeyDown=!1;if(this.#T){this.#T=!1;this.#te(`main_toolbar`)}if(!this.hasSelection)return;let{activeElement:e}=document;for(let t of this.#L)if(t.div.contains(e)){this.#M=[t,e];t._focusEventsAllowed=!1;break}}focus(){if(!this.#M)return;let[e,t]=this.#M;this.#M=null;t.addEventListener(`focusin`,()=>{e._focusEventsAllowed=!0},{once:!0,signal:this._signal});t.focus()}#ae(){if(this.#j)return;this.#j=new AbortController;let e=this.combinedSignal(this.#j);window.addEventListener(`keydown`,this.keydown.bind(this),{signal:e});window.addEventListener(`keyup`,this.keyup.bind(this),{signal:e})}#oe(){this.#j?.abort();this.#j=null}#se(){if(this.#d)return;this.#d=new AbortController;let e=this.combinedSignal(this.#d);document.addEventListener(`copy`,this.copy.bind(this),{signal:e});document.addEventListener(`cut`,this.cut.bind(this),{signal:e});document.addEventListener(`paste`,this.paste.bind(this),{signal:e})}#ce(){this.#d?.abort();this.#d=null}#le(){let e=this._signal;document.addEventListener(`dragover`,this.dragOver.bind(this),{signal:e});document.addEventListener(`drop`,this.drop.bind(this),{signal:e})}addEditListeners(){this.#ae();this.setEditingState(!0)}removeEditListeners(){this.#oe();this.setEditingState(!1)}dragOver(e){for(let{type:t}of e.dataTransfer.items)for(let n of this.#g)if(n.isHandlingMimeForPasting(t)){e.dataTransfer.dropEffect=`copy`;e.preventDefault();return}}drop(e){for(let t of e.dataTransfer.items)for(let n of this.#g)if(n.isHandlingMimeForPasting(t.type)){n.paste(t,this.currentLayer);e.preventDefault();return}}copy(e){e.preventDefault();this.#t?.commitOrRemove();if(!this.hasSelection)return;let t=[];for(let e of this.#L){let n=e.serialize(!0);n&&t.push(n)}t.length!==0&&e.clipboardData.setData(`application/pdfjs`,JSON.stringify(t))}cut(e){this.copy(e);this.delete()}async paste(e){e.preventDefault();let{clipboardData:t}=e;for(let e of t.items)for(let t of this.#g)if(t.isHandlingMimeForPasting(e.type)){t.paste(e,this.currentLayer);return}let n=t.getData(`application/pdfjs`);if(!n)return;try{n=JSON.parse(n)}catch(e){O(`paste: "${e.message}".`);return}if(!Array.isArray(n))return;this.unselectAll();let r=this.currentLayer;try{let e=[];for(let t of n){let n=await r.deserialize(t);if(!n)return;e.push(n)}this.addCommands({cmd:()=>{for(let t of e)this.#me(t);this.#_e(e)},undo:()=>{for(let t of e)t.remove()},mustExec:!0})}catch(e){O(`paste: "${e.message}".`)}}keydown(e){this.isShiftKeyDown||e.key!==`Shift`||(this.isShiftKeyDown=!0);this.#I===y.NONE||this.isEditorHandlingKeyboard||Ve._keyboardManager.exec(this,e)}keyup(e){if(this.isShiftKeyDown&&e.key===`Shift`){this.isShiftKeyDown=!1;if(this.#T){this.#T=!1;this.#te(`main_toolbar`)}}}onEditingAction({name:e}){switch(e){case`undo`:case`redo`:case`delete`:case`selectAll`:this[e]();break;case`highlightSelection`:this.highlightSelection(`context_menu`);break;case`commentSelection`:this.commentSelection(`context_menu`)}}updatePageIndex(e,t){for(let n of this.getEditors(e))n.pageIndex=t;let n=this.#a.get(e);if(n){n.pageIndex=t;this.#i.set(t,n);this.#O?n.enable():n.disable()}}startUpdatePages(){this.#a=new Map(this.#i);this.#i.clear()}endUpdatePages(){this.#a=null}clonePage(e,t){for(let n of this.getEditors(e)){let e=n.serialize(n.mode!==y.HIGHLIGHT);if(e){e.pageIndex=t;e.id=this.getId();e.isClone=!0;delete e.popupRef;this.#s.setValue(e.id,e)}}}findClonesForPage(e){let t=[],{pageIndex:n}=e;for(let[r,i]of this.#s)if(i.pageIndex===n&&i.isClone){this.#s.remove(r);t.push(e.deserialize(i).then(t=>{if(t){t.isClone=!0;e.addOrRebuild(t)}}))}return Promise.all(t)}#ue(e){if(Object.entries(e).some(([e,t])=>this.#U[e]!==t)){this._eventBus.dispatch(`editingstateschanged`,{source:this,details:Object.assign(this.#U,e)});this.#I===y.HIGHLIGHT&&!1===e.hasSelectedEditor&&this.#de([[b.HIGHLIGHT_FREE,!0]])}}#de(e){this._eventBus.dispatch(`annotationeditorparamschanged`,{source:this,details:e})}setEditingState(e){if(e){this.#re();this.#se();this.#ue({isEditing:this.#I!==y.NONE,isEmpty:this.#ge(),hasSomethingToUndo:this.#l.hasSomethingToUndo(),hasSomethingToRedo:this.#l.hasSomethingToRedo(),hasSelectedEditor:!1})}else{this.#ie();this.#ce();this.#ue({isEditing:!1});this.disableUserSelect(!1)}}registerEditorTypes(e){if(!this.#g){this.#g=e;for(let e of this.#g)this.#de(e.defaultPropertiesToUpdate)}}getId(){return this.#D.id}get currentLayer(){return this.#i.get(this.#p)}getLayer(e){return this.#i.get(e)}get currentPageIndex(){return this.#p}addLayer(e){this.#i.set(e.pageIndex,e);this.#O?e.enable():e.disable()}removeLayer(e){this.#i.delete(e.pageIndex)}async updateMode(e,t=null,n=!1,r=!1,i=!1,a=!1){if(this.#I!==e){if(this.#Y){await this.#Y.promise;if(!this.#Y)return}this.#Y=Promise.withResolvers();this.#f?.commitOrRemove();this.#I===y.POPUP&&this.#u?.hideSidebar();this.#u?.destroyPopup();this.#I=e;if(e!==y.NONE){for(let e of this.#r.values())e.addStandaloneCommentButton();e===y.SIGNATURE&&await this.#z?.loadSignatures();n&&B.clearPointerType();this.setEditingState(!0);await this.#fe();this.unselectAll();for(let t of this.#i.values())t.updateMode(e);if(e===y.POPUP){this.#n||=await this.#H.getAnnotationsByType(new Set(this.#g.map(e=>e._editorType)));let e=new Set,t=[];for(let n of this.#r.values()){let{annotationElementId:r,hasComment:i,deleted:a}=n;r&&e.add(r);i&&!a&&t.push(n.getData())}for(let n of this.#n){let{id:r,popupRef:i,contentsObj:a}=n;i&&a?.str&&!e.has(r)&&!this.#m.has(r)&&t.push(n)}this.#u?.showSidebar(t)}if(t){for(let e of this.#r.values())if(e.uid===t){this.setSelected(e);a?e.editComment():i?e.enterInEditMode():e.focus()}else e.unselect();this.#Y.resolve()}else{r&&this.addNewEditorFromKeyboard();this.#Y.resolve()}}else{this.setEditingState(!1);this.#pe();for(let e of this.#r.values())e.hideStandaloneCommentButton();this._editorUndoBar?.hide();this.toggleComment(null);this.#Y.resolve()}}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(e){e.mode!==this.#I&&this._eventBus.dispatch(`switchannotationeditormode`,{source:this,...e})}updateParams(e,t){if(this.#g){switch(e){case b.CREATE:this.currentLayer.addNewEditor(t);return;case b.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch(`reporttelemetry`,{source:this,details:{type:`editing`,data:{type:`highlight`,action:`toggle_visibility`}}});(this.#V||=new Map).set(e,t);this.showAllEditors(`highlight`,t)}if(this.hasSelection)for(let n of this.#L)n.updateParams(e,t);else for(let n of this.#g)n.updateDefaultParams(e,t)}}showAllEditors(e,t,n=!1){for(let n of this.#r.values())n.editorType===e&&n.show(t);(this.#V?.get(b.HIGHLIGHT_SHOW_ALL)??!0)!==t&&this.#de([[b.HIGHLIGHT_SHOW_ALL,t]])}enableWaiting(e=!1){if(this.#A!==e){this.#A=e;for(let t of this.#i.values()){e?t.disableClick():t.enableClick();t.div.classList.toggle(`waiting`,e)}}}async#fe(){if(!this.#O){this.#O=!0;let e=[];for(let t of this.#i.values())e.push(t.enable());await Promise.all(e);for(let e of this.#r.values())e.enable()}}#pe(){this.unselectAll();if(this.#O){this.#O=!1;for(let e of this.#i.values())e.disable();for(let e of this.#r.values())e.disable()}}*getEditors(e){for(let t of this.#r.values())t.pageIndex===e&&(yield t)}getEditor(e){return this.#r.get(e)}addEditor(e){this.#r.set(e.id,e)}removeEditor(e){if(e.div.contains(document.activeElement)){this.#S&&clearTimeout(this.#S);this.#S=setTimeout(()=>{this.focusMainContainer();this.#S=null},0)}this.#r.delete(e.id);e.annotationElementId&&this.#P?.delete(e.annotationElementId);this.unselect(e);e.annotationElementId&&this.#m.has(e.annotationElementId)||this.#s?.remove(e.id)}addDeletedAnnotationElement(e){this.#m.add(e.annotationElementId);this.addChangedExistingAnnotation(e);e.deleted=!0}isDeletedAnnotationElement(e){return this.#m.has(e)}removeDeletedAnnotationElement(e){this.#m.delete(e.annotationElementId);this.removeChangedExistingAnnotation(e);e.deleted=!1}#me(e){let t=this.#i.get(e.pageIndex);if(t)t.addOrRebuild(e);else{this.addEditor(e);this.addToAnnotationStorage(e)}}setActiveEditor(e){if(this.#t!==e){this.#t=e;e&&this.#de(e.propertiesToUpdate)}}get#he(){let e=null;for(e of this.#L);return e}updateUI(e){this.#he===e&&this.#de(e.propertiesToUpdate)}updateUIForDefaultProperties(e){this.#de(e.defaultPropertiesToUpdate)}toggleSelected(e){if(this.#L.has(e)){this.#L.delete(e);e.unselect();this.#ue({hasSelectedEditor:this.hasSelection})}else{this.#L.add(e);e.select();this.#de(e.propertiesToUpdate);this.#ue({hasSelectedEditor:!0})}}setSelected(e){this.updateToolbar({mode:e.mode,editId:e.uid});this.#f?.commitOrRemove();for(let t of this.#L)t!==e&&t.unselect();this.#u?.destroyPopup();this.#L.clear();this.#L.add(e);e.select();this.#de(e.propertiesToUpdate);this.#ue({hasSelectedEditor:!0})}isSelected(e){return this.#L.has(e)}get firstSelectedEditor(){return this.#L.values().next().value}unselect(e){e.unselect();this.#L.delete(e);this.#ue({hasSelectedEditor:this.hasSelection})}get hasSelection(){return this.#L.size!==0}get isEnterHandled(){return this.#L.size===1&&this.firstSelectedEditor.isEnterHandled}undo(){this.#l.undo();this.#ue({hasSomethingToUndo:this.#l.hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:this.#ge()});this._editorUndoBar?.hide()}redo(){this.#l.redo();this.#ue({hasSomethingToUndo:!0,hasSomethingToRedo:this.#l.hasSomethingToRedo(),isEmpty:this.#ge()})}addCommands(e){this.#l.add(e);this.#ue({hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:this.#ge()})}cleanUndoStack(e){this.#l.cleanType(e)}#ge(){if(this.#r.size===0)return!0;if(this.#r.size===1)for(let e of this.#r.values())return e.isEmpty();return!1}delete(){this.commitOrRemove();let e=this.currentLayer?.endDrawingSession(!0);if(!this.hasSelection&&!e)return;let t=e?[e]:[...this.#L],n=()=>{for(let e of t)this.#me(e)};this.addCommands({cmd:()=>{this._editorUndoBar?.show(n,t.length===1?t[0].editorType:t.length);for(let e of t)e.remove()},undo:n,mustExec:!0})}commitOrRemove(){this.#t?.commitOrRemove()}hasSomethingToControl(){return this.#t||this.hasSelection}#_e(e){for(let e of this.#L)e.unselect();this.#L.clear();for(let t of e)if(!t.isEmpty()){this.#L.add(t);t.select()}this.#ue({hasSelectedEditor:this.hasSelection})}selectAll(){for(let e of this.#L)e.commit();this.#_e(this.#r.values())}unselectAll(){if(this.#t){this.#t.commitOrRemove();if(this.#I!==y.NONE)return}if(!this.#f?.commitOrRemove()){this.#u?.destroyPopup();if(this.hasSelection){for(let e of this.#L)e.unselect();this.#L.clear();this.#ue({hasSelectedEditor:!1})}}}translateSelectedEditors(e,t,n=!1){n||this.commitOrRemove();if(!this.hasSelection)return;this.#W[0]+=e;this.#W[1]+=t;let[r,i]=this.#W,a=[...this.#L];this.#G&&clearTimeout(this.#G);this.#G=setTimeout(()=>{this.#G=null;this.#W[0]=this.#W[1]=0;this.addCommands({cmd:()=>{for(let e of a)if(this.#r.has(e.id)){e.translateInPage(r,i);e.translationDone()}},undo:()=>{for(let e of a)if(this.#r.has(e.id)){e.translateInPage(-r,-i);e.translationDone()}},mustExec:!1})},1e3);for(let n of a){n.translateInPage(e,t);n.translationDone()}}setUpDragSession(){if(this.hasSelection){this.disableUserSelect(!0);this.#h=new Map;for(let e of this.#L)this.#h.set(e,{savedX:e.x,savedY:e.y,savedPageIndex:e.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!this.#h)return!1;this.disableUserSelect(!1);let e=this.#h;this.#h=null;let t=!1;for(let[{x:n,y:r,pageIndex:i},a]of e){a.newX=n;a.newY=r;a.newPageIndex=i;t||=n!==a.savedX||r!==a.savedY||i!==a.savedPageIndex}if(!t)return!1;let n=(e,t,n,r)=>{if(this.#r.has(e.id)){let i=this.#i.get(r);if(i)e._setParentAndPosition(i,t,n);else{e.pageIndex=r;e.x=t;e.y=n}}};this.addCommands({cmd:()=>{for(let[t,{newX:r,newY:i,newPageIndex:a}]of e)n(t,r,i,a)},undo:()=>{for(let[t,{savedX:r,savedY:i,savedPageIndex:a}]of e)n(t,r,i,a)},mustExec:!0});return!0}dragSelectedEditors(e,t){if(this.#h)for(let n of this.#h.keys())n.drag(e,t)}rebuild(e){if(e.parent===null){let t=this.getLayer(e.pageIndex);if(t){t.changeParent(e);t.addOrRebuild(e)}else{this.addEditor(e);this.addToAnnotationStorage(e);e.rebuild()}}else e.parent.addOrRebuild(e)}get isEditorHandlingKeyboard(){return this.getActive()?.shouldGetKeyboardEvents()||this.#L.size===1&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(e){return this.#t===e}getActive(){return this.#t}getMode(){return this.#I}isEditingMode(){return this.#I!==y.NONE}get imageManager(){return j(this,`imageManager`,new Le)}getSelectionBoxes(e){if(!e)return null;let t=document.getSelection();for(let n=0,r=t.rangeCount;n<r;n++)if(!e.contains(t.getRangeAt(n).commonAncestorContainer))return null;let{x:n,y:r,width:i,height:a}=e.getBoundingClientRect(),o;switch(e.getAttribute(`data-main-rotation`)){case`90`:o=(e,t,o,s)=>({x:(t-r)/a,y:1-(e+o-n)/i,width:s/a,height:o/i});break;case`180`:o=(e,t,o,s)=>({x:1-(e+o-n)/i,y:1-(t+s-r)/a,width:o/i,height:s/a});break;case`270`:o=(e,t,o,s)=>({x:1-(t+s-r)/a,y:(e-n)/i,width:s/a,height:o/i});break;default:o=(e,t,o,s)=>({x:(e-n)/i,y:(t-r)/a,width:o/i,height:s/a})}let s=[];for(let e=0,n=t.rangeCount;e<n;e++){let n=t.getRangeAt(e);if(!n.collapsed)for(let{x:e,y:t,width:r,height:i}of n.getClientRects())r!==0&&i!==0&&s.push(o(e,t,r,i))}return s.length===0?null:s}addChangedExistingAnnotation({annotationElementId:e,id:t}){(this.#c||=new Map).set(e,t)}removeChangedExistingAnnotation({annotationElementId:e}){this.#c?.delete(e)}renderAnnotationElement(e){let t=this.#c?.get(e.data.id);if(!t)return;let n=this.#s.getRawValue(t);n&&(this.#I!==y.NONE||n.hasBeenModified)&&n.renderAnnotationElement(e)}setMissingCanvas(e,t,n){let r=this.#P?.get(e);if(r){r.setCanvas(t,n);this.#P.delete(e)}}addMissingCanvas(e,t){(this.#P||=new Map).set(e,t)}}class He{#e=null;#t=!1;#n=null;#r=null;#i=null;#a=null;#o=!1;#s=null;#c=null;#l=null;#u=null;#d=!1;static#f=null;static _l10n=null;constructor(e){this.#c=e;this.#d=e._uiManager.useNewAltTextFlow;He.#f||=Object.freeze({added:`pdfjs-editor-new-alt-text-added-button`,"added-label":`pdfjs-editor-new-alt-text-added-button-label`,missing:`pdfjs-editor-new-alt-text-missing-button`,"missing-label":`pdfjs-editor-new-alt-text-missing-button-label`,review:`pdfjs-editor-new-alt-text-to-review-button`,"review-label":`pdfjs-editor-new-alt-text-to-review-button-label`})}static initialize(e){He._l10n??=e}async render(){let e=this.#n=document.createElement(`button`);e.className=`altText`;e.tabIndex=`0`;let t=this.#r=document.createElement(`span`);e.append(t);if(this.#d){e.classList.add(`new`);e.setAttribute(`data-l10n-id`,He.#f.missing);t.setAttribute(`data-l10n-id`,He.#f[`missing-label`])}else{e.setAttribute(`data-l10n-id`,`pdfjs-editor-alt-text-button`);t.setAttribute(`data-l10n-id`,`pdfjs-editor-alt-text-button-label`)}let n=this.#c._uiManager._signal;e.addEventListener(`contextmenu`,L,{signal:n});e.addEventListener(`pointerdown`,e=>e.stopPropagation(),{signal:n});let r=e=>{e.preventDefault();this.#c._uiManager.editAltText(this.#c);this.#d&&this.#c._reportTelemetry({action:`pdfjs.image.alt_text.image_status_label_clicked`,data:{label:this.#p}})};e.addEventListener(`click`,r,{capture:!0,signal:n});e.addEventListener(`keydown`,t=>{if(t.target===e&&t.key===`Enter`){this.#o=!0;r(t)}},{signal:n});await this.#m();return e}get#p(){return(this.#e?`added`:this.#e===null&&this.guessedText&&`review`)||`missing`}finish(){if(this.#n){this.#n.focus({focusVisible:this.#o});this.#o=!1}}isEmpty(){return this.#d?this.#e===null:!this.#e&&!this.#t}hasData(){return this.#d?this.#e!==null||!!this.#l:this.isEmpty()}get guessedText(){return this.#l}async setGuessedText(e){if(this.#e===null){this.#l=e;this.#u=await He._l10n.get(`pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer`,{generatedAltText:e});this.#m()}}toggleAltTextBadge(e=!1){if(this.#d&&!this.#e){if(!this.#s){let e=this.#s=document.createElement(`div`);e.className=`noAltTextBadge`;this.#c.div.append(e)}this.#s.classList.toggle(`hidden`,!e)}else{this.#s?.remove();this.#s=null}}serialize(e){let t=this.#e;e||this.#l!==t||(t=this.#u);return{altText:t,decorative:this.#t,guessedText:this.#l,textWithDisclaimer:this.#u}}get data(){return{altText:this.#e,decorative:this.#t}}set data({altText:e,decorative:t,guessedText:n,textWithDisclaimer:r,cancel:i=!1}){if(n){this.#l=n;this.#u=r}if(this.#e!==e||this.#t!==t){if(!i){this.#e=e;this.#t=t}this.#m()}}toggle(e=!1){if(this.#n){if(!e&&this.#a){clearTimeout(this.#a);this.#a=null}this.#n.disabled=!e}}shown(){this.#c._reportTelemetry({action:`pdfjs.image.alt_text.image_status_label_displayed`,data:{label:this.#p}})}destroy(){this.#n?.remove();this.#n=null;this.#r=null;this.#i=null;this.#s?.remove();this.#s=null}async#m(){let e=this.#n;if(!e)return;if(this.#d){e.classList.toggle(`done`,!!this.#e);e.setAttribute(`data-l10n-id`,He.#f[this.#p]);this.#r?.setAttribute(`data-l10n-id`,He.#f[`${this.#p}-label`]);if(!this.#e){this.#i?.remove();return}}else{if(!this.#e&&!this.#t){e.classList.remove(`done`);this.#i?.remove();return}e.classList.add(`done`);e.setAttribute(`data-l10n-id`,`pdfjs-editor-alt-text-edit-button`)}let t=this.#i;if(!t){this.#i=t=document.createElement(`span`);t.className=`tooltip`;t.setAttribute(`role`,`tooltip`);t.id=`alt-text-tooltip-${this.#c.id}`;let n=this.#c._uiManager._signal;n.addEventListener(`abort`,()=>{clearTimeout(this.#a);this.#a=null},{once:!0});e.addEventListener(`mouseenter`,()=>{this.#a=setTimeout(()=>{this.#a=null;this.#i.classList.add(`show`);this.#c._reportTelemetry({action:`alt_text_tooltip`})},100)},{signal:n});e.addEventListener(`mouseleave`,()=>{if(this.#a){clearTimeout(this.#a);this.#a=null}this.#i?.classList.remove(`show`)},{signal:n})}if(this.#t)t.setAttribute(`data-l10n-id`,`pdfjs-editor-alt-text-decorative-tooltip`);else{t.removeAttribute(`data-l10n-id`);t.textContent=this.#e}t.parentNode||e.append(t);this.#c.getElementForAltText()?.setAttribute(`aria-describedby`,t.id)}}class Ue{#e=null;#t=null;#n=!1;#r=null;#i=null;#a=null;#o=null;#s=null;#c=!1;#l=null;constructor(e){this.#r=e}renderForToolbar(){let e=this.#t=document.createElement(`button`);e.className=`comment`;return this.#u(e,!1)}renderForStandalone(){let e=this.#e=document.createElement(`button`);e.className=`annotationCommentButton`;let t=this.#r.commentButtonPosition;if(t){let{style:n}=e;n.insetInlineEnd=`calc(${100*(this.#r._uiManager.direction===`ltr`?1-t[0]:t[0])}% - var(--comment-button-dim))`;n.top=`calc(${100*t[1]}% - var(--comment-button-dim))`;let r=this.#r.commentButtonColor;r&&(n.backgroundColor=r)}return this.#u(e,!0)}focusButton(){setTimeout(()=>{(this.#e??this.#t)?.focus()},0)}onUpdatedColor(){if(!this.#e)return;let e=this.#r.commentButtonColor;e&&(this.#e.style.backgroundColor=e);this.#r._uiManager.updatePopupColor(this.#r)}get commentButtonWidth(){return(this.#e?.getBoundingClientRect().width??0)/this.#r.parent.boundingClientRect.width}get commentPopupPositionInLayer(){if(this.#l)return this.#l;if(!this.#e)return null;let{x:e,y:t,height:n}=this.#e.getBoundingClientRect(),{x:r,y:i,width:a,height:o}=this.#r.parent.boundingClientRect;return[(e-r)/a,(t+n-i)/o]}set commentPopupPositionInLayer(e){this.#l=e}hasDefaultPopupPosition(){return this.#l===null}removeStandaloneCommentButton(){this.#e?.remove();this.#e=null}removeToolbarCommentButton(){this.#t?.remove();this.#t=null}setCommentButtonStates({selected:e,hasPopup:t}){if(this.#e){this.#e.classList.toggle(`selected`,e);this.#e.ariaExpanded=t}}#u(e,t){if(!this.#r._uiManager.hasCommentManager())return null;e.tabIndex=`0`;e.ariaHasPopup=`dialog`;if(t){e.ariaControls=`commentPopup`;e.setAttribute(`data-l10n-id`,`pdfjs-show-comment-button`)}else{e.ariaControlsElements=[this.#r._uiManager.getCommentDialogElement()];e.setAttribute(`data-l10n-id`,`pdfjs-editor-add-comment-button`)}let n=this.#r._uiManager._signal;if(!(n instanceof AbortSignal)||n.aborted)return e;e.addEventListener(`contextmenu`,L,{signal:n});if(t){e.addEventListener(`focusin`,e=>{this.#r._focusEventsAllowed=!1;R(e)},{capture:!0,signal:n});e.addEventListener(`focusout`,e=>{this.#r._focusEventsAllowed=!0;R(e)},{capture:!0,signal:n})}e.addEventListener(`pointerdown`,e=>e.stopPropagation(),{signal:n});let r=t=>{t.preventDefault();e===this.#t?this.edit():this.#r.toggleComment(!0)};e.addEventListener(`click`,r,{capture:!0,signal:n});e.addEventListener(`keydown`,t=>{if(t.target===e&&t.key===`Enter`){this.#n=!0;r(t)}},{signal:n});e.addEventListener(`pointerenter`,()=>{this.#r.toggleComment(!1,!0)},{signal:n});e.addEventListener(`pointerleave`,()=>{this.#r.toggleComment(!1,!1)},{signal:n});return e}edit(e){let t=this.commentPopupPositionInLayer,n,r;if(t)[n,r]=t;else{[n,r]=this.#r.commentButtonPosition;let{width:e,height:t,x:i,y:a}=this.#r;n=i+n*e;r=a+r*t}let i=this.#r.parent.boundingClientRect,{x:a,y:o,width:s,height:c}=i;this.#r._uiManager.editComment(this.#r,a+n*s,o+r*c,{...e,parentDimensions:i})}finish(){if(this.#t){this.#t.focus({focusVisible:this.#n});this.#n=!1}}isDeleted(){return this.#c||this.#o===``}isEmpty(){return this.#o===null}hasBeenEdited(){return this.isDeleted()||this.#o!==this.#i}serialize(){return this.data}get data(){return{text:this.#o,richText:this.#a,date:this.#s,deleted:this.isDeleted()}}set data(e){e!==this.#o&&(this.#a=null);if(e!==null){this.#o=e;this.#s=new Date;this.#c=!1}else{this.#o=``;this.#c=!0}}restoreData({text:e,richText:t,date:n}){this.#o=e;this.#a=t;this.#s=n;this.#c=!1}setInitialText(e,t=null){this.#i=e;this.data=e;this.#s=null;this.#a=t}shown(){}destroy(){this.#t?.remove();this.#t=null;this.#e?.remove();this.#e=null;this.#o=``;this.#a=null;this.#s=null;this.#r=null;this.#n=!1;this.#c=!1}}class We{#e;#t=!1;#n=null;#r;#i;#a;#o;#s=null;#c;#l=null;#u;#d=null;constructor({container:e,isPinchingDisabled:t=null,isPinchingStopped:n=null,onPinchStart:r=null,onPinching:i=null,onPinchEnd:a=null,signal:o}){this.#e=e;this.#n=n;this.#r=t;this.#i=r;this.#a=i;this.#o=a;this.#u=new AbortController;this.#c=AbortSignal.any([o,this.#u.signal]);e.addEventListener(`touchstart`,this.#f.bind(this),{passive:!1,signal:this.#c})}get MIN_TOUCH_DISTANCE_TO_PINCH(){return 35/Oe.pixelRatio}#f(e){if(this.#r?.())return;if(e.touches.length===1){if(this.#s)return;let e=this.#s=new AbortController,t=AbortSignal.any([this.#c,e.signal]),n=this.#e,r={capture:!0,signal:t,passive:!1},i=e=>{if(e.pointerType===`touch`){this.#s?.abort();this.#s=null}};n.addEventListener(`pointerdown`,e=>{if(e.pointerType===`touch`){R(e);i(e)}},r);n.addEventListener(`pointerup`,i,r);n.addEventListener(`pointercancel`,i,r);return}if(!this.#d){this.#d=new AbortController;let e=AbortSignal.any([this.#c,this.#d.signal]),t=this.#e,n={signal:e,capture:!1,passive:!1};t.addEventListener(`touchmove`,this.#p.bind(this),n);let r=this.#m.bind(this);t.addEventListener(`touchend`,r,n);t.addEventListener(`touchcancel`,r,n);n.capture=!0;t.addEventListener(`pointerdown`,R,n);t.addEventListener(`pointermove`,R,n);t.addEventListener(`pointercancel`,R,n);t.addEventListener(`pointerup`,R,n);this.#i?.()}R(e);if(e.touches.length!==2||this.#n?.()){this.#l=null;return}let[t,n]=e.touches;t.identifier>n.identifier&&([t,n]=[n,t]);this.#l={touch0X:t.screenX,touch0Y:t.screenY,touch1X:n.screenX,touch1Y:n.screenY}}#p(e){if(!this.#l||e.touches.length!==2)return;R(e);let[t,n]=e.touches;t.identifier>n.identifier&&([t,n]=[n,t]);let{screenX:r,screenY:i}=t,{screenX:a,screenY:o}=n,s=this.#l,{touch0X:c,touch0Y:l,touch1X:u,touch1Y:d}=s,f=u-c,p=d-l,m=a-r,h=o-i,g=Math.hypot(m,h)||1,_=Math.hypot(f,p)||1;if(!this.#t&&Math.abs(_-g)<=We.MIN_TOUCH_DISTANCE_TO_PINCH)return;s.touch0X=r;s.touch0Y=i;s.touch1X=a;s.touch1Y=o;if(!this.#t){this.#t=!0;return}let v=[(r+a)/2,(i+o)/2];this.#a?.(v,_,g)}#m(e){if(!(e.touches.length>=2)){if(this.#d){this.#d.abort();this.#d=null;this.#o?.()}if(this.#l){R(e);this.#l=null;this.#t=!1}}}destroy(){this.#u?.abort();this.#u=null;this.#s?.abort();this.#s=null}}class V{#e=null;#t=null;#n=null;#r=null;#i=null;#a=!1;#o=null;#s=``;#c=null;#l=null;#u=null;#d=null;#f=null;#p=``;#m=!1;#h=null;#g=!1;#_=!1;#v=!1;#y=null;#b=0;#x=0;#S=null;#C=null;isSelected=!1;_isCopy=!1;_editToolbar=null;_initialOptions=Object.create(null);_initialData=null;_isVisible=!0;_uiManager=null;_focusEventsAllowed=!0;static _l10n=null;static _l10nAlert=null;static _l10nResizer=null;#w=!1;#T=V._zIndex++;static _borderLineWidth=-1;static _colorManager=new Be;static _zIndex=1;static _telemetryTimeout=1e3;static get _resizerKeyboardManager(){let e=V.prototype._resizeWithKeyboard,t=Ve.TRANSLATE_SMALL,n=Ve.TRANSLATE_BIG;return j(this,`_resizerKeyboardManager`,new ze([[[`ArrowLeft`,`mac+ArrowLeft`],e,{args:[-t,0]}],[[`ctrl+ArrowLeft`,`mac+shift+ArrowLeft`],e,{args:[-n,0]}],[[`ArrowRight`,`mac+ArrowRight`],e,{args:[t,0]}],[[`ctrl+ArrowRight`,`mac+shift+ArrowRight`],e,{args:[n,0]}],[[`ArrowUp`,`mac+ArrowUp`],e,{args:[0,-t]}],[[`ctrl+ArrowUp`,`mac+shift+ArrowUp`],e,{args:[0,-n]}],[[`ArrowDown`,`mac+ArrowDown`],e,{args:[0,t]}],[[`ctrl+ArrowDown`,`mac+shift+ArrowDown`],e,{args:[0,n]}],[[`Escape`,`mac+Escape`],V.prototype._stopResizingWithKeyboard]]))}constructor(e){this.parent=e.parent;this.id=e.id;this.width=this.height=null;this.pageIndex=e.parent.pageIndex;this.name=e.name;this.div=null;this._uiManager=e.uiManager;this.annotationElementId=null;this._willKeepAspectRatio=!1;this._initialOptions.isCentered=e.isCentered;this._structTreeParentId=null;this.annotationElementId=e.annotationElementId||null;this.creationDate=e.creationDate||new Date;this.modificationDate=e.modificationDate||null;this.canAddComment=!0;let{rotation:t,rawDims:{pageWidth:n,pageHeight:r,pageX:i,pageY:a}}=this.parent.viewport;this.rotation=t;this.pageRotation=(360+t-this._uiManager.viewParameters.rotation)%360;this.pageDimensions=[n,r];this.pageTranslation=[i,a];let[o,s]=this.parentDimensions;this.x=e.x/o;this.y=e.y/s;this.isAttachedToDOM=!1;this.deleted=!1}updatePageIndex(e){this.pageIndex=e}get editorType(){return Object.getPrototypeOf(this).constructor._type}get mode(){return Object.getPrototypeOf(this).constructor._editorType}static get isDrawer(){return!1}static get _defaultLineColor(){return j(this,`_defaultLineColor`,this._colorManager.getHexCode(`CanvasText`))}static deleteAnnotationElement(e){let t=new Ge({id:e._uiManager.getId(),parent:e.parent,uiManager:e._uiManager});t.annotationElementId=e.annotationElementId;t.deleted=!0;t._uiManager.addToAnnotationStorage(t)}static initialize(e,t){V._l10n??=e;V._l10nAlert??=Object.freeze({highlight:`pdfjs-editor-highlight-added-alert`,freetext:`pdfjs-editor-freetext-added-alert`,ink:`pdfjs-editor-ink-added-alert`,stamp:`pdfjs-editor-stamp-added-alert`,signature:`pdfjs-editor-signature-added-alert`});V._l10nResizer??=Object.freeze({topLeft:`pdfjs-editor-resizer-top-left`,topMiddle:`pdfjs-editor-resizer-top-middle`,topRight:`pdfjs-editor-resizer-top-right`,middleRight:`pdfjs-editor-resizer-middle-right`,bottomRight:`pdfjs-editor-resizer-bottom-right`,bottomMiddle:`pdfjs-editor-resizer-bottom-middle`,bottomLeft:`pdfjs-editor-resizer-bottom-left`,middleLeft:`pdfjs-editor-resizer-middle-left`});if(V._borderLineWidth!==-1)return;let n=getComputedStyle(document.documentElement);V._borderLineWidth=parseFloat(n.getPropertyValue(`--outline-width`))||0}static updateDefaultParams(e,t){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(e){return!1}static paste(e,t){k(`Not implemented`)}get propertiesToUpdate(){return[]}get _isDraggable(){return this.#w}set _isDraggable(e){this.#w=e;this.div?.classList.toggle(`draggable`,e)}get uid(){return this.annotationElementId||this.id}get isEnterHandled(){return!0}center(){let[e,t]=this.pageDimensions;switch(this.parentRotation){case 90:this.x-=this.height*t/(2*e);this.y+=this.width*e/(2*t);break;case 180:this.x+=this.width/2;this.y+=this.height/2;break;case 270:this.x+=this.height*t/(2*e);this.y-=this.width*e/(2*t);break;default:this.x-=this.width/2;this.y-=this.height/2}this.fixAndSetPosition()}addCommands(e){this._uiManager.addCommands(e)}get currentLayer(){return this._uiManager.currentLayer}setInBackground(){this.div.style.zIndex=0}setInForeground(){this.div.style.zIndex=this.#T}setParent(e){if(e!==null){this.pageIndex=e.pageIndex;this.pageDimensions=e.pageDimensions}else{this.#W();this.#d?.remove();this.#d=null}this.parent=e}focusin(e){this._focusEventsAllowed&&(this.#m?this.#m=!1:this.parent.setSelected(this))}focusout(e){if(!this._focusEventsAllowed)return;if(!this.isAttachedToDOM)return;if(!e.relatedTarget?.closest(`#${this.id}`)){e.preventDefault();this.parent?.isMultipleSelection||this.commitOrRemove()}}commitOrRemove(){this.isEmpty()?this.remove():this.commit()}commit(){this.isInEditMode()&&this.addToAnnotationStorage()}addToAnnotationStorage(){this._uiManager.addToAnnotationStorage(this)}setAt(e,t,n,r){let[i,a]=this.parentDimensions;[n,r]=this.screenToPageTranslation(n,r);this.x=(e+n)/i;this.y=(t+r)/a;this.fixAndSetPosition()}_moveAfterPaste(e,t){if(this.isClone){delete this.isClone;return}let[n,r]=this.parentDimensions;this.setAt(e*n,t*r,this.width*n,this.height*r);this._onTranslated()}#E([e,t],n,r){[n,r]=this.screenToPageTranslation(n,r);this.x+=n/e;this.y+=r/t;this._onTranslating(this.x,this.y);this.fixAndSetPosition()}translate(e,t){this.#E(this.parentDimensions,e,t)}translateInPage(e,t){this.#h||=[this.x,this.y,this.width,this.height];this.#E(this.pageDimensions,e,t);this.div.scrollIntoView({block:`nearest`})}translationDone(){this._onTranslated(this.x,this.y)}drag(e,t){this.#h||=[this.x,this.y,this.width,this.height];let{div:n,parentDimensions:[r,i]}=this;this.x+=e/r;this.y+=t/i;if(this.parent&&(this.x<0||this.x>1||this.y<0||this.y>1)){let{x:e,y:t}=this.div.getBoundingClientRect();if(this.parent.findNewParent(this,e,t)){this.x-=Math.floor(this.x);this.y-=Math.floor(this.y)}}let{x:a,y:o}=this,[s,c]=this.getBaseTranslation();a+=s;o+=c;let{style:l}=n;l.left=`${(100*a).toFixed(2)}%`;l.top=`${(100*o).toFixed(2)}%`;this._onTranslating(a,o);n.scrollIntoView({block:`nearest`})}_onTranslating(e,t){}_onTranslated(e,t){}get _hasBeenMoved(){return!!this.#h&&(this.#h[0]!==this.x||this.#h[1]!==this.y)}get _hasBeenResized(){return!!this.#h&&(this.#h[2]!==this.width||this.#h[3]!==this.height)}getBaseTranslation(){let[e,t]=this.parentDimensions,{_borderLineWidth:n}=V,r=n/e,i=n/t;switch(this.rotation){case 90:return[-r,i];case 180:return[r,i];case 270:return[r,-i];default:return[-r,-i]}}get _mustFixPosition(){return!0}fixAndSetPosition(e=this.rotation){let{div:{style:t},pageDimensions:[n,r]}=this,{x:i,y:a,width:o,height:s}=this;o*=n;s*=r;i*=n;a*=r;if(this._mustFixPosition)switch(e){case 0:i=F(i,0,n-o);a=F(a,0,r-s);break;case 90:i=F(i,0,n-s);a=F(a,o,r);break;case 180:i=F(i,o,n);a=F(a,s,r);break;case 270:i=F(i,s,n);a=F(a,0,r-o)}this.x=i/=n;this.y=a/=r;let[c,l]=this.getBaseTranslation();i+=c;a+=l;t.left=`${(100*i).toFixed(2)}%`;t.top=`${(100*a).toFixed(2)}%`;this.moveInDOM()}static#D(e,t,n){switch(n){case 90:return[t,-e];case 180:return[-e,-t];case 270:return[-t,e];default:return[e,t]}}screenToPageTranslation(e,t){return V.#D(e,t,this.parentRotation)}pageTranslationToScreen(e,t){return V.#D(e,t,360-this.parentRotation)}#O(e){switch(e){case 90:{let[e,t]=this.pageDimensions;return[0,-e/t,t/e,0]}case 180:return[-1,0,0,-1];case 270:{let[e,t]=this.pageDimensions;return[0,e/t,-t/e,0]}default:return[1,0,0,1]}}get parentScale(){return this._uiManager.viewParameters.realScale}get parentRotation(){return(this._uiManager.viewParameters.rotation+this.pageRotation)%360}get parentDimensions(){let{parentScale:e,pageDimensions:[t,n]}=this;return[t*e,n*e]}setDims(){let{div:{style:e},width:t,height:n}=this;e.width=`${(100*t).toFixed(2)}%`;e.height=`${(100*n).toFixed(2)}%`}getInitialTranslation(){return[0,0]}#k(){if(this.#c)return;this.#c=document.createElement(`div`);this.#c.classList.add(`resizers`);let e=this._willKeepAspectRatio?[`topLeft`,`topRight`,`bottomRight`,`bottomLeft`]:[`topLeft`,`topMiddle`,`topRight`,`middleRight`,`bottomRight`,`bottomMiddle`,`bottomLeft`,`middleLeft`],t=this._uiManager._signal;for(let n of e){let e=document.createElement(`div`);this.#c.append(e);e.classList.add(`resizer`,n);e.setAttribute(`data-resizer-name`,n);e.addEventListener(`pointerdown`,this.#A.bind(this,n),{signal:t});e.addEventListener(`contextmenu`,L,{signal:t});e.tabIndex=-1}this.div.prepend(this.#c)}#A(e,t){t.preventDefault();let{isMac:n}=N.platform;if(t.button!==0||t.ctrlKey&&n)return;this.#n?.toggle(!1);let r=this._isDraggable;this._isDraggable=!1;this.#l=[t.screenX,t.screenY];let i=new AbortController,a=this._uiManager.combinedSignal(i);this.parent.togglePointerEvents(!1);window.addEventListener(`pointermove`,this.#N.bind(this,e),{passive:!0,capture:!0,signal:a});window.addEventListener(`touchmove`,R,{passive:!1,signal:a});window.addEventListener(`contextmenu`,L,{signal:a});this.#u={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};let o=this.parent.div.style.cursor,s=this.div.style.cursor;this.div.style.cursor=this.parent.div.style.cursor=window.getComputedStyle(t.target).cursor;let c=()=>{i.abort();this.parent.togglePointerEvents(!0);this.#n?.toggle(!0);this._isDraggable=r;this.parent.div.style.cursor=o;this.div.style.cursor=s;this.#M()};window.addEventListener(`pointerup`,c,{signal:a});window.addEventListener(`blur`,c,{signal:a})}#j(e,t,n,r){this.width=n;this.height=r;this.x=e;this.y=t;this.setDims();this.fixAndSetPosition();this._onResized()}_onResized(){}#M(){if(!this.#u)return;let{savedX:e,savedY:t,savedWidth:n,savedHeight:r}=this.#u;this.#u=null;let i=this.x,a=this.y,o=this.width,s=this.height;i===e&&a===t&&o===n&&s===r||this.addCommands({cmd:this.#j.bind(this,i,a,o,s),undo:this.#j.bind(this,e,t,n,r),mustExec:!0})}static _round(e){return Math.round(1e4*e)/1e4}#N(e,t){let[n,r]=this.parentDimensions,i=this.x,a=this.y,o=this.width,s=this.height,c=V.MIN_SIZE/n,l=V.MIN_SIZE/r,u=this.#O(this.rotation),d=(e,t)=>[u[0]*e+u[2]*t,u[1]*e+u[3]*t],f=this.#O(360-this.rotation),p,m,h=!1,g=!1;switch(e){case`topLeft`:h=!0;p=(e,t)=>[0,0];m=(e,t)=>[e,t];break;case`topMiddle`:p=(e,t)=>[e/2,0];m=(e,t)=>[e/2,t];break;case`topRight`:h=!0;p=(e,t)=>[e,0];m=(e,t)=>[0,t];break;case`middleRight`:g=!0;p=(e,t)=>[e,t/2];m=(e,t)=>[0,t/2];break;case`bottomRight`:h=!0;p=(e,t)=>[e,t];m=(e,t)=>[0,0];break;case`bottomMiddle`:p=(e,t)=>[e/2,t];m=(e,t)=>[e/2,0];break;case`bottomLeft`:h=!0;p=(e,t)=>[0,t];m=(e,t)=>[e,0];break;case`middleLeft`:g=!0;p=(e,t)=>[0,t/2];m=(e,t)=>[e,t/2]}let _=p(o,s),v=m(o,s),y=d(...v),b=V._round(i+y[0]),x=V._round(a+y[1]),S,C,w=1,T=1;if(t.fromKeyboard)({deltaX:S,deltaY:C}=t);else{let{screenX:e,screenY:n}=t,[r,i]=this.#l;[S,C]=this.screenToPageTranslation(e-r,n-i);this.#l[0]=e;this.#l[1]=n}[S,C]=(E=S/n,D=C/r,[f[0]*E+f[2]*D,f[1]*E+f[3]*D]);var E,D;if(h){let e=Math.hypot(o,s);w=T=Math.max(Math.min(Math.hypot(v[0]-_[0]-S,v[1]-_[1]-C)/e,1/o,1/s),c/o,l/s)}else g?w=F(Math.abs(v[0]-_[0]-S),c,1)/o:T=F(Math.abs(v[1]-_[1]-C),l,1)/s;let O=V._round(o*w),k=V._round(s*T);y=d(...m(O,k));let A=b-y[0],ee=x-y[1];this.#h||=[this.x,this.y,this.width,this.height];this.width=O;this.height=k;this.x=A;this.y=ee;this.setDims();this.fixAndSetPosition();this._onResizing()}_onResizing(){}altTextFinish(){this.#n?.finish()}get toolbarButtons(){return null}async addEditToolbar(){if(this._editToolbar||this.#_)return this._editToolbar;this._editToolbar=new Ne(this);this.div.append(this._editToolbar.render());let{toolbarButtons:e}=this;if(e)for(let[t,n]of e)await this._editToolbar.addButton(t,n);this.hasComment||this._editToolbar.addButton(`comment`,this.addCommentButton());this._editToolbar.addButton(`delete`);return this._editToolbar}addCommentButtonInToolbar(){this._editToolbar?.addButtonBefore(`comment`,this.addCommentButton(),`.deleteButton`)}removeCommentButtonFromToolbar(){this._editToolbar?.removeButton(`comment`)}removeEditToolbar(){this._editToolbar?.remove();this._editToolbar=null;this.#n?.destroy()}addContainer(e){let t=this._editToolbar?.div;t?t.before(e):this.div.append(e)}getClientDimensions(){return this.div.getBoundingClientRect()}createAltText(){if(!this.#n){He.initialize(V._l10n);this.#n=new He(this);if(this.#e){this.#n.data=this.#e;this.#e=null}}return this.#n}get altTextData(){return this.#n?.data}set altTextData(e){this.#n&&(this.#n.data=e)}get guessedAltText(){return this.#n?.guessedText}async setGuessedAltText(e){await this.#n?.setGuessedText(e)}serializeAltText(e){return this.#n?.serialize(e)}hasAltText(){return!!this.#n&&!this.#n.isEmpty()}hasAltTextData(){return this.#n?.hasData()??!1}focusCommentButton(){this.#r?.focusButton()}addCommentButton(){return this.canAddComment?this.#r||=new Ue(this):null}addStandaloneCommentButton(){if(this._uiManager.hasCommentManager()){if(this.#i)this._uiManager.isEditingMode()&&this.#i.classList.remove(`hidden`);else if(this.hasComment){this.#i=this.#r.renderForStandalone();this.div.append(this.#i)}}}removeStandaloneCommentButton(){this.#r.removeStandaloneCommentButton();this.#i=null}hideStandaloneCommentButton(){this.#i?.classList.add(`hidden`)}get comment(){if(!this.#r)return null;let{data:{richText:e,text:t,date:n,deleted:r}}=this.#r;return{text:t,richText:e,date:n,deleted:r,color:this.getNonHCMColor(),opacity:this.opacity??1}}set comment(e){this.#r||=new Ue(this);typeof e==`object`&&e?this.#r.restoreData(e):this.#r.data=e;if(this.hasComment){this.removeCommentButtonFromToolbar();this.addStandaloneCommentButton();this._uiManager.updateComment(this)}else{this.addCommentButtonInToolbar();this.removeStandaloneCommentButton();this._uiManager.removeComment(this)}}setCommentData({comment:e,popupRef:t,richText:n}){if(!t)return;this.#r||=new Ue(this);this.#r.setInitialText(e,n);if(!this.annotationElementId)return;let r=this._uiManager.getAndRemoveDataFromAnnotationStorage(this.annotationElementId);r&&this.updateFromAnnotationLayer(r)}get hasEditedComment(){return this.#r?.hasBeenEdited()}get hasDeletedComment(){return this.#r?.isDeleted()}get hasComment(){return!!this.#r&&!this.#r.isEmpty()&&!this.#r.isDeleted()}async editComment(e){this.#r||=new Ue(this);this.#r.edit(e)}toggleComment(e,t=void 0){this.hasComment&&this._uiManager.toggleComment(this,e,t)}setSelectedCommentButton(e){this.#r.setSelectedButton(e)}addComment(e){if(this.hasEditedComment){let[,,,t]=e.rect,[n]=this.pageDimensions,[r]=this.pageTranslation,i=r+n+1,a=t-100,o=i+180;e.popup={contents:this.comment.text,deleted:this.comment.deleted,rect:[i,a,o,t]}}}updateFromAnnotationLayer({popup:{contents:e,deleted:t}}){this.#r.data=t?null:e}get parentBoundingClientRect(){return this.parent.boundingClientRect}render(){let e=this.div=document.createElement(`div`);e.setAttribute(`data-editor-rotation`,(360-this.rotation)%360);e.className=this.name;e.setAttribute(`id`,this.id);e.tabIndex=this.#a?-1:0;e.setAttribute(`role`,`application`);this.defaultL10nId&&e.setAttribute(`data-l10n-id`,this.defaultL10nId);this._isVisible||e.classList.add(`hidden`);this.setInForeground();this.#z();let[t,n]=this.parentDimensions;if(this.parentRotation%180!=0){e.style.maxWidth=`${(100*n/t).toFixed(2)}%`;e.style.maxHeight=`${(100*t/n).toFixed(2)}%`}let[r,i]=this.getInitialTranslation();this.translate(r,i);Fe(this,e,[`keydown`,`pointerdown`,`dblclick`]);this.isResizable&&this._uiManager._supportsPinchToZoom&&(this.#C||=new We({container:e,isPinchingDisabled:()=>!this.isSelected,onPinchStart:this.#P.bind(this),onPinching:this.#F.bind(this),onPinchEnd:this.#I.bind(this),signal:this._uiManager._signal}));this.addStandaloneCommentButton();this._uiManager._editorUndoBar?.hide();return e}#P(){this.#u={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};this.#n?.toggle(!1);this.parent.togglePointerEvents(!1)}#F(e,t,n){let r=n/t*.7+1-.7;if(r===1)return;let i=this.#O(this.rotation),a=(e,t)=>[i[0]*e+i[2]*t,i[1]*e+i[3]*t],[o,s]=this.parentDimensions,c=this.x,l=this.y,u=this.width,d=this.height,f=V.MIN_SIZE/o,p=V.MIN_SIZE/s;r=Math.max(Math.min(r,1/u,1/d),f/u,p/d);let m=V._round(u*r),h=V._round(d*r);if(m===u&&h===d)return;this.#h||=[c,l,u,d];let g=a(u/2,d/2),_=V._round(c+g[0]),v=V._round(l+g[1]),y=a(m/2,h/2);this.x=_-y[0];this.y=v-y[1];this.width=m;this.height=h;this.setDims();this.fixAndSetPosition();this._onResizing()}#I(){this.#n?.toggle(!0);this.parent.togglePointerEvents(!0);this.#M()}pointerdown(e){let{isMac:t}=N.platform;if(e.button!==0||e.ctrlKey&&t)e.preventDefault();else{this.#m=!0;this._isDraggable?this.#R(e):this.#L(e)}}#L(e){let{isMac:t}=N.platform;e.ctrlKey&&!t||e.shiftKey||e.metaKey&&t?this.parent.toggleSelected(this):this.parent.setSelected(this)}#R(e){let{isSelected:t}=this;this._uiManager.setUpDragSession();let n=!1,r=new AbortController,i=this._uiManager.combinedSignal(r),a={capture:!0,passive:!1,signal:i},o=e=>{r.abort();this.#o=null;this.#m=!1;this._uiManager.endDragSession()||this.#L(e);n&&this._onStopDragging()};if(t){this.#b=e.clientX;this.#x=e.clientY;this.#o=e.pointerId;this.#s=e.pointerType;window.addEventListener(`pointermove`,e=>{if(!n){n=!0;this._uiManager.toggleComment(this,!0,!1);this._onStartDragging()}let{clientX:t,clientY:r,pointerId:i}=e;if(i!==this.#o){R(e);return}let[a,o]=this.screenToPageTranslation(t-this.#b,r-this.#x);this.#b=t;this.#x=r;this._uiManager.dragSelectedEditors(a,o)},a);window.addEventListener(`touchmove`,R,a);window.addEventListener(`pointerdown`,e=>{e.pointerType===this.#s&&(this.#C||e.isPrimary)&&o(e);R(e)},a)}let s=e=>{this.#o&&this.#o!==e.pointerId?R(e):o(e)};window.addEventListener(`pointerup`,s,{signal:i});window.addEventListener(`blur`,s,{signal:i})}_onStartDragging(){}_onStopDragging(){}moveInDOM(){this.#y&&clearTimeout(this.#y);this.#y=setTimeout(()=>{this.#y=null;this.parent?.moveEditorInDOM(this)},0)}_setParentAndPosition(e,t,n){e.changeParent(this);this.x=t;this.y=n;this.fixAndSetPosition();this._onTranslated()}getRect(e,t,n=this.rotation){let r=this.parentScale,[i,a]=this.pageDimensions,[o,s]=this.pageTranslation,c=e/r,l=t/r,u=this.x*i,d=this.y*a,f=this.width*i,p=this.height*a;switch(n){case 0:return[u+c+o,a-d-l-p+s,u+c+f+o,a-d-l+s];case 90:return[u+l+o,a-d+c+s,u+l+p+o,a-d+c+f+s];case 180:return[u-c-f+o,a-d+l+s,u-c+o,a-d+l+p+s];case 270:return[u-l-p+o,a-d-c-f+s,u-l+o,a-d-c+s];default:throw Error(`Invalid rotation`)}}getRectInCurrentCoords(e,t){let[n,r,i,a]=e,o=i-n,s=a-r;switch(this.rotation){case 0:return[n,t-a,o,s];case 90:return[n,t-r,s,o];case 180:return[i,t-r,o,s];case 270:return[i,t-a,s,o];default:throw Error(`Invalid rotation`)}}getPDFRect(){return this.getRect(0,0)}getNonHCMColor(){return this.color&&V._colorManager.convert(this._uiManager.getNonHCMColor(this.color))}onUpdatedColor(){this.#r?.onUpdatedColor()}getData(){let{comment:{text:e,color:t,date:n,opacity:r,deleted:i,richText:a},uid:o,pageIndex:s,creationDate:c,modificationDate:l}=this;return{id:o,pageIndex:s,rect:this.getPDFRect(),richText:a,contentsObj:{str:e},creationDate:c,modificationDate:n||l,popupRef:!i,color:t,opacity:r}}onceAdded(e){}isEmpty(){return!1}enableEditMode(){if(this.isInEditMode())return!1;this.parent.setEditingState(!1);this.#_=!0;return!0}disableEditMode(){if(!this.isInEditMode())return!1;this.parent.setEditingState(!0);this.#_=!1;return!0}isInEditMode(){return this.#_}shouldGetKeyboardEvents(){return this.#v}needsToBeRebuilt(){return this.div&&!this.isAttachedToDOM}get isOnScreen(){let{top:e,left:t,bottom:n,right:r}=this.getClientDimensions(),{innerHeight:i,innerWidth:a}=window;return t<a&&r>0&&e<i&&n>0}#z(){if(this.#f||!this.div)return;this.#f=new AbortController;let e=this._uiManager.combinedSignal(this.#f);this.div.addEventListener(`focusin`,this.focusin.bind(this),{signal:e});this.div.addEventListener(`focusout`,this.focusout.bind(this),{signal:e})}rebuild(){this.#z()}rotate(e){}resize(){}serializeDeleted(){return{id:this.annotationElementId,deleted:!0,pageIndex:this.pageIndex,popupRef:this._initialData?.popupRef||``}}serialize(e=!1,t=null){return{annotationType:this.mode,pageIndex:this.pageIndex,rect:this.getPDFRect(),rotation:this.rotation,structTreeParentId:this._structTreeParentId,popupRef:this._initialData?.popupRef||``}}static async deserialize(e,t,n){let r=new this.prototype.constructor({parent:t,id:n.getId(),uiManager:n,annotationElementId:e.annotationElementId,creationDate:e.creationDate,modificationDate:e.modificationDate});r.rotation=e.rotation;r.#e=e.accessibilityData;r._isCopy=e.isCopy||!1;let[i,a]=r.pageDimensions,[o,s,c,l]=r.getRectInCurrentCoords(e.rect,a);r.x=o/i;r.y=s/a;r.width=c/i;r.height=l/a;return r}get hasBeenModified(){return!!this.annotationElementId&&(this.deleted||this.serialize()!==null)}remove(){this.#f?.abort();this.#f=null;this.isEmpty()||this.commit();this.parent?this.parent.remove(this):this._uiManager.removeEditor(this);this.hideCommentPopup();if(this.#y){clearTimeout(this.#y);this.#y=null}this.#W();this.removeEditToolbar();if(this.#S){for(let e of this.#S.values())clearTimeout(e);this.#S=null}this.parent=null;this.#C?.destroy();this.#C=null;this.#d?.remove();this.#d=null}get isResizable(){return!1}makeResizable(){if(this.isResizable){this.#k();this.#c.classList.remove(`hidden`)}}get toolbarPosition(){return null}get commentButtonPosition(){return this._uiManager.direction===`ltr`?[1,0]:[0,0]}get commentButtonPositionInPage(){let{commentButtonPosition:[e,t]}=this,[n,r,i,a]=this.getPDFRect();return[V._round(n+(i-n)*e),V._round(r+(a-r)*(1-t))]}get commentButtonColor(){return this._uiManager.makeCommentColor(this.getNonHCMColor(),this.opacity)}get commentPopupPosition(){return this.#r.commentPopupPositionInLayer}set commentPopupPosition(e){this.#r.commentPopupPositionInLayer=e}hasDefaultPopupPosition(){return this.#r.hasDefaultPopupPosition()}get commentButtonWidth(){return this.#r.commentButtonWidth}get elementBeforePopup(){return this.div}setCommentButtonStates(e){this.#r?.setCommentButtonStates(e)}keydown(e){if(!this.isResizable||e.target!==this.div||e.key!==`Enter`)return;this._uiManager.setSelected(this);this.#u={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};let t=this.#c.children;if(!this.#t){this.#t=Array.from(t);let e=this.#B.bind(this),n=this.#V.bind(this),r=this._uiManager._signal;for(let t of this.#t){let i=t.getAttribute(`data-resizer-name`);t.setAttribute(`role`,`spinbutton`);t.addEventListener(`keydown`,e,{signal:r});t.addEventListener(`blur`,n,{signal:r});t.addEventListener(`focus`,this.#H.bind(this,i),{signal:r});t.setAttribute(`data-l10n-id`,V._l10nResizer[i])}}let n=this.#t[0],r=0;for(let e of t){if(e===n)break;r++}let i=(360-this.rotation+this.parentRotation)%360/90*(this.#t.length/4);if(i!==r){if(i<r)for(let e=0;e<r-i;e++)this.#c.append(this.#c.firstElementChild);else if(i>r)for(let e=0;e<i-r;e++)this.#c.firstElementChild.before(this.#c.lastElementChild);let e=0;for(let n of t){let t=this.#t[e++].getAttribute(`data-resizer-name`);n.setAttribute(`data-l10n-id`,V._l10nResizer[t])}}this.#U(0);this.#v=!0;this.#c.firstElementChild.focus({focusVisible:!0});e.preventDefault();e.stopImmediatePropagation()}#B(e){V._resizerKeyboardManager.exec(this,e)}#V(e){this.#v&&e.relatedTarget?.parentNode!==this.#c&&this.#W()}#H(e){this.#p=this.#v?e:``}#U(e){if(this.#t)for(let t of this.#t)t.tabIndex=e}_resizeWithKeyboard(e,t){this.#v&&this.#N(this.#p,{deltaX:e,deltaY:t,fromKeyboard:!0})}#W(){this.#v=!1;this.#U(-1);this.#M()}_stopResizingWithKeyboard(){this.#W();this.div.focus()}select(){if(this.isSelected&&this._editToolbar)this._editToolbar.show();else{this.isSelected=!0;this.makeResizable();this.div?.classList.add(`selectedEditor`);if(this._editToolbar){this._editToolbar?.show();this.#n?.toggleAltTextBadge(!1)}else this.addEditToolbar().then(()=>{this.div?.classList.contains(`selectedEditor`)&&this._editToolbar?.show()})}}focus(){this.div&&!this.div.contains(document.activeElement)&&setTimeout(()=>this.div?.focus({preventScroll:!0}),0)}unselect(){if(this.isSelected){this.isSelected=!1;this.#c?.classList.add(`hidden`);this.div?.classList.remove(`selectedEditor`);this.div?.contains(document.activeElement)&&this._uiManager.currentLayer.div.focus({preventScroll:!0});this._editToolbar?.hide();this.#n?.toggleAltTextBadge(!0);this.hideCommentPopup()}}hideCommentPopup(){this.hasComment&&this._uiManager.toggleComment(null)}updateParams(e,t){}disableEditing(){}enableEditing(){}get canChangeContent(){return!1}enterInEditMode(){if(this.canChangeContent){this.enableEditMode();this.div.focus()}}dblclick(e){if(e.target.nodeName!==`BUTTON`){this.enterInEditMode();this.parent.updateToolbar({mode:this.constructor._editorType,editId:this.uid})}}getElementForAltText(){return this.div}get contentDiv(){return this.div}get isEditing(){return this.#g}set isEditing(e){this.#g=e;if(this.parent){if(e){this.parent.setSelected(this);this.parent.setActiveEditor(this)}else this.parent.setActiveEditor(null)}}static get MIN_SIZE(){return 16}static canCreateNewEmptyEditor(){return!0}get telemetryInitialData(){return{action:`added`}}get telemetryFinalData(){return null}_reportTelemetry(e,t=!1){if(t){this.#S||=new Map;let{action:t}=e,n=this.#S.get(t);n&&clearTimeout(n);n=setTimeout(()=>{this._reportTelemetry(e);this.#S.delete(t);this.#S.size===0&&(this.#S=null)},V._telemetryTimeout);this.#S.set(t,n);return}e.type||=this.editorType;this._uiManager._eventBus.dispatch(`reporttelemetry`,{source:this,details:{type:`editing`,data:e}})}show(e=this._isVisible){this.div.classList.toggle(`hidden`,!e);this._isVisible=e}enable(){this.div&&(this.div.tabIndex=0);this.#a=!1}disable(){this.div&&(this.div.tabIndex=-1);this.#a=!0}updateFakeAnnotationElement(e){if(this.#d||this.deleted){if(this.deleted){this.#d.remove();this.#d=null}else(this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized)&&this.#d.updateEdited({rect:this.getPDFRect(),popup:this.comment})}else this.#d=e.addFakeAnnotation(this)}renderAnnotationElement(e){if(this.deleted){e.hide();return null}let t=e.container.querySelector(`.annotationContent`);if(t){if(t.nodeName===`CANVAS`){let e=t;t=document.createElement(`div`);t.classList.add(`annotationContent`,this.editorType);e.before(t)}}else{t=document.createElement(`div`);t.classList.add(`annotationContent`,this.editorType);e.container.prepend(t)}return t}resetAnnotationElement(e){let{firstElementChild:t}=e.container;t?.nodeName===`DIV`&&t.classList.contains(`annotationContent`)&&t.remove()}}class Ge extends V{constructor(e){super(e);this.annotationElementId=e.annotationElementId;this.deleted=!0}serialize(){return this.serializeDeleted()}}const Ke=3285377520,H=4294901760,qe=65535;class Je{constructor(e){this.h1=e?4294967295&e:Ke;this.h2=e?4294967295&e:Ke}update(e){let t,n;if(typeof e==`string`){t=new Uint8Array(2*e.length);n=0;for(let r=0,i=e.length;r<i;r++){let i=e.charCodeAt(r);if(i<=255)t[n++]=i;else{t[n++]=i>>>8;t[n++]=255&i}}}else{if(!ArrayBuffer.isView(e))throw Error(`Invalid data format, must be a string or TypedArray.`);t=e.slice();n=t.byteLength}let r=n>>2,i=n-4*r,a=new Uint32Array(t.buffer,0,r),o=0,s=0,c=this.h1,l=this.h2,u=3432918353,d=461845907,f=11601,p=13715;for(let e=0;e<r;e++)if(1&e){o=a[e];o=o*u&H|o*f&qe;o=o<<15|o>>>17;o=o*d&H|o*p&qe;c^=o;c=c<<13|c>>>19;c=5*c+3864292196}else{s=a[e];s=s*u&H|s*f&qe;s=s<<15|s>>>17;s=s*d&H|s*p&qe;l^=s;l=l<<13|l>>>19;l=5*l+3864292196}o=0;switch(i){case 3:o^=t[4*r+2]<<16;case 2:o^=t[4*r+1]<<8;case 1:o^=t[4*r];o=o*u&H|o*f&qe;o=o<<15|o>>>17;o=o*d&H|o*p&qe;1&r?c^=o:l^=o}this.h1=c;this.h2=l}hexdigest(){let e=this.h1,t=this.h2;e^=t>>>1;e=3981806797*e&H|36045*e&qe;t=4283543511*t&H|(2950163797*(t<<16|e>>>16)&H)>>>16;e^=t>>>1;e=444984403*e&H|60499*e&qe;t=3301882366*t&H|(3120437893*(t<<16|e>>>16)&H)>>>16;e^=t>>>1;return(e>>>0).toString(16).padStart(8,`0`)+(t>>>0).toString(16).padStart(8,`0`)}}const Ye=Object.freeze({map:null,hash:``,transfer:void 0});class Xe{#e=!1;#t=null;#n=null;#r=new Map;onSetModified=null;onResetModified=null;onAnnotationEditor=null;getValue(e,t){let n=this.#r.get(e);return n===void 0?t:Object.assign(t,n)}getRawValue(e){return this.#r.get(e)}remove(e){let t=this.#r.get(e);if(t!==void 0){t instanceof V&&this.#n.delete(t.annotationElementId);this.#r.delete(e);this.#r.size===0&&this.resetModified();this.#r.values().some(e=>e instanceof V)||this.onAnnotationEditor?.(null)}}setValue(e,t){let n=this.#r.get(e),r=!1;if(n!==void 0){for(let[e,i]of Object.entries(t))if(n[e]!==i){r=!0;n[e]=i}}else{r=!0;this.#r.set(e,t)}r&&this.#i();if(t instanceof V){(this.#n||=new Map).set(t.annotationElementId,t);this.onAnnotationEditor?.(t.constructor._type)}}has(e){return this.#r.has(e)}get size(){return this.#r.size}#i(){if(!this.#e){this.#e=!0;this.onSetModified?.()}}resetModified(){if(this.#e){this.#e=!1;this.onResetModified?.()}}get print(){return new Ze(this)}get serializable(){if(this.#r.size===0)return Ye;let e=new Map,t=new Je,n=[],r=Object.create(null),i=!1;for(let[n,a]of this.#r){let o=a instanceof V?a.serialize(!1,r):a;if(a.page){a.pageIndex=a.page._pageIndex;delete a.page}if(o){e.set(n,o);t.update(`${n}:${JSON.stringify(o)}`);i||=!!o.bitmap}}if(i)for(let t of e.values())t.bitmap&&n.push(t.bitmap);return e.size>0?{map:e,hash:t.hexdigest(),transfer:n}:Ye}get editorStats(){let e=null,t=new Map,n=0,r=0;for(let i of this.#r.values()){if(!(i instanceof V)){i.popup&&(i.popup.deleted?r+=1:n+=1);continue}i.isCommentDeleted?r+=1:i.hasEditedComment&&(n+=1);let a=i.telemetryFinalData;if(!a)continue;let{type:o}=a;t.has(o)||t.set(o,Object.getPrototypeOf(i).constructor);e||=Object.create(null);let s=e[o]||=new Map;for(let[e,t]of Object.entries(a)){if(e===`type`)continue;let n=s.getOrInsertComputed(e,de);n.set(t,(n.get(t)??0)+1)}}if(r>0||n>0){e||=Object.create(null);e.comments={deleted:r,edited:n}}if(!e)return null;for(let[n,r]of t)e[n]=r.computeTelemetryFinalData(e[n]);return e}resetModifiedIds(){this.#t=null}updateEditor(e,t){let n=this.#n?.get(e);if(n){n.updateFromAnnotationLayer(t);return!0}return!1}getEditor(e){return this.#n?.get(e)||null}get modifiedIds(){if(this.#t)return this.#t;let e=[];if(this.#n)for(let t of this.#n.values())t.serialize()&&e.push(t.annotationElementId);let t=``;if(e.length){let n=new Je;n.update(e.join(`,`));t=n.hexdigest()}return this.#t={ids:new Set(e),hash:t}}[Symbol.iterator](){return this.#r.entries()}}class Ze extends Xe{#e=Ye;constructor(e){super();let{serializable:t}=e;if(t===Ye)return;let{map:n,hash:r,transfer:i}=t,a=structuredClone(n,i?{transfer:i}:null);this.#e={map:a,hash:r,transfer:[]}}get print(){k(`Should not call PrintAnnotationStorage.print`)}get serializable(){return this.#e}get modifiedIds(){return j(this,`modifiedIds`,{ids:new Set,hash:``})}}const Qe=`__forcedDependency`,{floor:$e,ceil:et}=Math;function tt(e,t,n,r,i,a){e[4*t+0]=Math.min(e[4*t+0],n);e[4*t+1]=Math.min(e[4*t+1],r);e[4*t+2]=Math.max(e[4*t+2],i);e[4*t+3]=Math.max(e[4*t+3],a)}const nt=new Uint32Array(new Uint8Array([255,255,0,0]).buffer)[0];class rt{#e;#t;constructor(e,t){this.#e=e;this.#t=t}get length(){return this.#e.length}isEmpty(e){return this.#e[e]===nt}minX(e){return this.#t[4*e+0]/256}minY(e){return this.#t[4*e+1]/256}maxX(e){return(this.#t[4*e+2]+1)/256}maxY(e){return(this.#t[4*e+3]+1)/256}}const it=(e,t)=>e?.getOrInsertComputed(t,()=>({dependencies:new Set,isRenderingOperation:!1}));class at{#e=[[1,0,0,1,0,0]];#t=[-1/0,-1/0,1/0,1/0];#n=new Float64Array(f);_pendingBBoxIdx=-1;#r;#i;#a;#o;_savesStack=[];_markedContentStack=[];constructor(e,t){this.#r=e.width;this.#i=e.height;this.#s(t)}growOperationsCount(e){e>=this.#o.length&&this.#s(e,this.#o)}#s(e,t){let n=new ArrayBuffer(4*e);this.#a=new Uint8ClampedArray(n);this.#o=new Uint32Array(n);if(t&&t.length>0){this.#o.set(t);this.#o.fill(nt,t.length)}else this.#o.fill(nt)}get clipBox(){return this.#t}save(e){this.#t={__proto__:this.#t};this._savesStack.push(e);return this}restore(e,t){let n=Object.getPrototypeOf(this.#t);if(n===null)return this;this.#t=n;let r=this._savesStack.pop();if(r!==void 0){t?.(r,e);this.#o[e]=this.#o[r]}return this}recordOpenMarker(e){this._savesStack.push(e);return this}getOpenMarker(){return this._savesStack.length===0?null:this._savesStack.at(-1)}recordCloseMarker(e,t){let n=this._savesStack.pop();if(n!==void 0){t?.(n,e);this.#o[e]=this.#o[n]}return this}beginMarkedContent(e){this._markedContentStack.push(e);return this}endMarkedContent(e,t){let n=this._markedContentStack.pop();if(n!==void 0){t?.(n,e);this.#o[e]=this.#o[n]}return this}pushBaseTransform(e){this.#e.push(P.multiplyByDOMMatrix(this.#e.at(-1),e.getTransform()));return this}popBaseTransform(){this.#e.length>1&&this.#e.pop();return this}resetBBox(e){if(this._pendingBBoxIdx!==e){this._pendingBBoxIdx=e;this.#n.set(f,0)}return this}recordClipBox(e,t,n,r,i,a){let o=P.multiplyByDOMMatrix(this.#e.at(-1),t.getTransform()),s=f.slice();P.axialAlignedBoundingBox([n,i,r,a],o,s);let c=P.intersect(this.#t,s);if(c){this.#t[0]=c[0];this.#t[1]=c[1];this.#t[2]=c[2];this.#t[3]=c[3]}else{this.#t[0]=this.#t[1]=1/0;this.#t[2]=this.#t[3]=-1/0}return this}recordBBox(e,t,n,r,i,a){let o=this.#t;if(o[0]===1/0)return this;let s=P.multiplyByDOMMatrix(this.#e.at(-1),t.getTransform());if(o[0]===-1/0){P.axialAlignedBoundingBox([n,i,r,a],s,this.#n);return this}let c=f.slice();P.axialAlignedBoundingBox([n,i,r,a],s,c);this.#n[0]=F(c[0],o[0],this.#n[0]);this.#n[1]=F(c[1],o[1],this.#n[1]);this.#n[2]=F(c[2],this.#n[2],o[2]);this.#n[3]=F(c[3],this.#n[3],o[3]);return this}recordFullPageBBox(e){this.#n[0]=Math.max(0,this.#t[0]);this.#n[1]=Math.max(0,this.#t[1]);this.#n[2]=Math.min(this.#r,this.#t[2]);this.#n[3]=Math.min(this.#i,this.#t[3]);return this}recordOperation(e,t=!1,n){if(this._pendingBBoxIdx!==e)return this;let r=$e(256*this.#n[0]/this.#r),i=$e(256*this.#n[1]/this.#i),a=et(256*this.#n[2]/this.#r),o=et(256*this.#n[3]/this.#i);tt(this.#a,e,r,i,a,o);if(n)for(let t of n)for(let n of t)n!==e&&tt(this.#a,n,r,i,a,o);t||(this._pendingBBoxIdx=-1);return this}bboxToClipBoxDropOperation(e){if(this._pendingBBoxIdx===e){this._pendingBBoxIdx=-1;this.#t[0]=Math.max(this.#t[0],this.#n[0]);this.#t[1]=Math.max(this.#t[1],this.#n[1]);this.#t[2]=Math.min(this.#t[2],this.#n[2]);this.#t[3]=Math.min(this.#t[3],this.#n[3])}return this}take(){return new rt(this.#o,this.#a)}takeDebugMetadata(){throw Error(`Unreachable`)}recordSimpleData(e,t){return this}recordIncrementalData(e,t){return this}resetIncrementalData(e,t){return this}recordNamedData(e,t){return this}recordSimpleDataFromNamed(e,t,n){return this}recordFutureForcedDependency(e,t){return this}inheritSimpleDataAsFutureForcedDependencies(e){return this}inheritPendingDependenciesAsFutureForcedDependencies(){return this}recordCharacterBBox(e,t,n,r=1,i=0,a=0,o){return this}getSimpleIndex(e){}recordDependencies(e,t){return this}recordNamedDependency(e,t){return this}recordShowTextOperation(e,t=!1){return this}}class ot{#e={__proto__:null};#t={__proto__:null,transform:[],moveText:[],sameLineText:[],[Qe]:[]};#n=new Map;#r=new Set;#i=new Map;#a;#o;#s;constructor(e,t=!1){this.#s=e;if(t){this.#a=new Map;this.#o=(e,t)=>{it(this.#a,t).dependencies.add(e)}}}get clipBox(){return this.#s.clipBox}growOperationsCount(e){this.#s.growOperationsCount(e)}save(e){this.#e={__proto__:this.#e};this.#t={__proto__:this.#t,transform:{__proto__:this.#t.transform},moveText:{__proto__:this.#t.moveText},sameLineText:{__proto__:this.#t.sameLineText},[Qe]:{__proto__:this.#t[Qe]}};this.#s.save(e);return this}restore(e){this.#s.restore(e,this.#o);let t=Object.getPrototypeOf(this.#e);if(t===null)return this;this.#e=t;this.#t=Object.getPrototypeOf(this.#t);return this}recordOpenMarker(e){this.#s.recordOpenMarker(e,this.#o);return this}getOpenMarker(){return this.#s.getOpenMarker()}recordCloseMarker(e){this.#s.recordCloseMarker(e,this.#o);return this}beginMarkedContent(e){this.#s.beginMarkedContent(e);return this}endMarkedContent(e){this.#s.endMarkedContent(e,this.#o);return this}pushBaseTransform(e){this.#s.pushBaseTransform(e);return this}popBaseTransform(){this.#s.popBaseTransform();return this}recordSimpleData(e,t){this.#e[e]=t;return this}recordIncrementalData(e,t){this.#t[e].push(t);return this}resetIncrementalData(e,t){this.#t[e].length=0;return this}recordNamedData(e,t){this.#n.set(e,t);return this}recordSimpleDataFromNamed(e,t,n){this.#e[e]=this.#n.get(t)??n}recordFutureForcedDependency(e,t){this.recordIncrementalData(Qe,t);return this}inheritSimpleDataAsFutureForcedDependencies(e){for(let t of e)t in this.#e&&this.recordFutureForcedDependency(t,this.#e[t]);return this}inheritPendingDependenciesAsFutureForcedDependencies(){for(let e of this.#r)this.recordFutureForcedDependency(Qe,e);return this}resetBBox(e){this.#s.resetBBox(e);return this}recordClipBox(e,t,n,r,i,a){this.#s.recordClipBox(e,t,n,r,i,a);return this}recordBBox(e,t,n,r,i,a){this.#s.recordBBox(e,t,n,r,i,a);return this}recordCharacterBBox(e,t,n,r=1,i=0,a=0,o){let s=n.bbox,c,l;if(s){c=s[2]!==s[0]&&s[3]!==s[1]&&this.#i.get(n);if(!1!==c){l=[0,0,0,0];P.axialAlignedBoundingBox(s,n.fontMatrix,l);r===1&&i===0&&a===0||P.scaleMinMax([r,0,0,-r,i,a],l);if(c)return this.recordBBox(e,t,l[0],l[2],l[1],l[3])}}if(!o)return this.recordFullPageBBox(e);let u=o();if(s&&l&&c===void 0){c=l[0]<=i-u.actualBoundingBoxLeft&&l[2]>=i+u.actualBoundingBoxRight&&l[1]<=a-u.actualBoundingBoxAscent&&l[3]>=a+u.actualBoundingBoxDescent;this.#i.set(n,c);if(c)return this.recordBBox(e,t,l[0],l[2],l[1],l[3])}return this.recordBBox(e,t,i-u.actualBoundingBoxLeft,i+u.actualBoundingBoxRight,a-u.actualBoundingBoxAscent,a+u.actualBoundingBoxDescent)}recordFullPageBBox(e){this.#s.recordFullPageBBox(e);return this}getSimpleIndex(e){return this.#e[e]}recordDependencies(e,t){let n=this.#r,r=this.#e,i=this.#t;for(let e of t)e in this.#e?n.add(r[e]):e in i&&i[e].forEach(n.add,n);return this}recordNamedDependency(e,t){this.#n.has(t)&&this.#r.add(this.#n.get(t));return this}recordOperation(e,t=!1){this.recordDependencies(e,[Qe]);if(this.#a){let t=it(this.#a,e),{dependencies:n}=t;this.#r.forEach(n.add,n);this.#s._savesStack.forEach(n.add,n);this.#s._markedContentStack.forEach(n.add,n);n.delete(e);t.isRenderingOperation=!0}let n=!t&&e===this.#s._pendingBBoxIdx;this.#s.recordOperation(e,t,[this.#r,this.#s._savesStack,this.#s._markedContentStack]);n&&this.#r.clear();return this}recordShowTextOperation(e,t=!1){let n=Array.from(this.#r);this.recordOperation(e,t);this.recordIncrementalData(`sameLineText`,e);for(let e of n)this.recordIncrementalData(`sameLineText`,e);return this}bboxToClipBoxDropOperation(e,t=!1){let n=!t&&e===this.#s._pendingBBoxIdx;this.#s.bboxToClipBoxDropOperation(e);n&&this.#r.clear();return this}take(){this.#i.clear();return this.#s.take()}takeDebugMetadata(){return this.#a}}class st{#e;#t;#n;#r=0;#i=0;constructor(e,t,n){if(e instanceof st&&e.#n===!!n)return e;this.#e=e;this.#t=t;this.#n=!!n}get clipBox(){return this.#e.clipBox}growOperationsCount(){throw Error(`Unreachable`)}save(e){this.#i++;this.#e.save(this.#t);return this}restore(e){if(this.#i>0){this.#e.restore(this.#t);this.#i--}return this}recordOpenMarker(e){this.#r++;return this}getOpenMarker(){return this.#r>0?this.#t:this.#e.getOpenMarker()}recordCloseMarker(e){this.#r--;return this}beginMarkedContent(e){return this}endMarkedContent(e){return this}pushBaseTransform(e){this.#e.pushBaseTransform(e);return this}popBaseTransform(){this.#e.popBaseTransform();return this}recordSimpleData(e,t){this.#e.recordSimpleData(e,this.#t);return this}recordIncrementalData(e,t){this.#e.recordIncrementalData(e,this.#t);return this}resetIncrementalData(e,t){this.#e.resetIncrementalData(e,this.#t);return this}recordNamedData(e,t){return this}recordSimpleDataFromNamed(e,t,n){this.#e.recordSimpleDataFromNamed(e,t,this.#t);return this}recordFutureForcedDependency(e,t){this.#e.recordFutureForcedDependency(e,this.#t);return this}inheritSimpleDataAsFutureForcedDependencies(e){this.#e.inheritSimpleDataAsFutureForcedDependencies(e);return this}inheritPendingDependenciesAsFutureForcedDependencies(){this.#e.inheritPendingDependenciesAsFutureForcedDependencies();return this}resetBBox(e){this.#n||this.#e.resetBBox(this.#t);return this}recordClipBox(e,t,n,r,i,a){this.#n||this.#e.recordClipBox(this.#t,t,n,r,i,a);return this}recordBBox(e,t,n,r,i,a){this.#n||this.#e.recordBBox(this.#t,t,n,r,i,a);return this}recordCharacterBBox(e,t,n,r,i,a,o){this.#n||this.#e.recordCharacterBBox(this.#t,t,n,r,i,a,o);return this}recordFullPageBBox(e){this.#n||this.#e.recordFullPageBBox(this.#t);return this}getSimpleIndex(e){return this.#e.getSimpleIndex(e)}recordDependencies(e,t){this.#e.recordDependencies(this.#t,t);return this}recordNamedDependency(e,t){this.#e.recordNamedDependency(this.#t,t);return this}recordOperation(e){this.#e.recordOperation(this.#t,!0);return this}recordShowTextOperation(e){this.#e.recordShowTextOperation(this.#t,!0);return this}bboxToClipBoxDropOperation(e){this.#n||this.#e.bboxToClipBoxDropOperation(this.#t,!0);return this}take(){throw Error(`Unreachable`)}takeDebugMetadata(){throw Error(`Unreachable`)}}const ct=[`path`,`transform`,`filter`,`strokeColor`,`strokeAlpha`,`lineWidth`,`lineCap`,`lineJoin`,`miterLimit`,`dash`],lt=[`path`,`transform`,`filter`,`fillColor`,`fillAlpha`,`globalCompositeOperation`,`SMask`],ut=[`transform`,`SMask`,`filter`,`fillAlpha`,`strokeAlpha`,`globalCompositeOperation`],dt=[`filter`,`fillColor`,`fillAlpha`],ft=[`transform`,`leading`,`charSpacing`,`wordSpacing`,`hScale`,`textRise`,`moveText`,`textMatrix`,`font`,`fontObj`,`filter`,`fillColor`,`textRenderingMode`,`SMask`,`fillAlpha`,`strokeAlpha`,`globalCompositeOperation`,`sameLineText`],pt=[`transform`],mt=[`transform`,`fillColor`];class ht{#e;#t;#n=4;#r=0;#i=new ht.#a(6*this.#n);static#a=N.isFloat16ArraySupported?Float16Array:Float32Array;constructor(e){this.#e=e.width;this.#t=e.height}record(e,t,n,r){if(this.#r===this.#n){this.#n*=2;let e=new ht.#a(6*this.#n);e.set(this.#i);this.#i=e}let i=P.domMatrixToTransform(e.getTransform()),a;if(r[0]!==1/0){let e=f.slice();P.axialAlignedBoundingBox([0,-n,t,0],i,e);let o=P.intersect(r,e);if(!o)return;let[s,c,l,u]=o;if(s!==e[0]||c!==e[1]||l!==e[2]||u!==e[3]){let e=Math.atan2(i[1],i[0]),t=Math.abs(Math.sin(e)),n=Math.abs(Math.cos(e));if(t<1e-6||n<1e-6||Math.abs(t-n)<1e-6)a=[s,c,s,u,l,c];else{let e=l-s,r=u-c,i=t*t,o=n*n,d=n*t,f=o-i,p=(r*o-e*d)/f;a=[s+(r*d-e*i)/f,c,s,c+p,l,u-p]}}}if(!a){a=[0,-n,0,0,t,-n];P.applyTransform(a,i,0);P.applyTransform(a,i,2);P.applyTransform(a,i,4)}a[0]/=this.#e;a[1]/=this.#t;a[2]/=this.#e;a[3]/=this.#t;a[4]/=this.#e;a[5]/=this.#t;this.#i.set(a,6*this.#r);this.#r++}take(){return this.#i.subarray(0,6*this.#r)}}class gt{#e=new Set;constructor({ownerDocument:e=globalThis.document,styleElement:t=null}){this._document=e;this.nativeFontFaces=new Set;this.styleElement=null;this.loadingRequests=[];this.loadTestFontId=0}addNativeFontFace(e){this.nativeFontFaces.add(e);this._document.fonts.add(e)}removeNativeFontFace(e){this.nativeFontFaces.delete(e);this._document.fonts.delete(e)}insertRule(e){if(!this.styleElement){this.styleElement=this._document.createElement(`style`);this._document.documentElement.getElementsByTagName(`head`)[0].append(this.styleElement)}let t=this.styleElement.sheet;t.insertRule(e,t.cssRules.length)}clear(){for(let e of this.nativeFontFaces)this._document.fonts.delete(e);this.nativeFontFaces.clear();this.#e.clear();if(this.styleElement){this.styleElement.remove();this.styleElement=null}}async loadSystemFont({systemFontInfo:e,disableFontFace:t,_inspectFont:n}){if(e&&!this.#e.has(e.loadedName)){A(!t,"loadSystemFont shouldn't be called when `disableFontFace` is set.");if(this.isFontLoadingAPISupported){let{loadedName:t,src:r,style:i}=e,a=new FontFace(t,r,i);this.addNativeFontFace(a);try{await a.load();this.#e.add(t);n?.(e)}catch{O(`Cannot load system font: ${e.baseFontName}, installing it could help to improve PDF rendering.`);this.removeNativeFontFace(a)}return}k(`Not implemented: loadSystemFont without the Font Loading API.`)}}async bind(e){if(e.attached||e.missingFile&&!e.systemFontInfo)return;e.attached=!0;if(e.systemFontInfo){await this.loadSystemFont(e);return}if(this.isFontLoadingAPISupported){let t=e.createNativeFontFace();if(t){this.addNativeFontFace(t);try{await t.loaded}catch(n){O(`Failed to load font '${t.family}': '${n}'.`);e.disableFontFace=!0;throw n}}return}let t=e.createFontFaceRule();if(t){this.insertRule(t);if(this.isSyncFontLoadingSupported)return;await new Promise(t=>{let n=this._queueLoadingCallback(t);this._prepareFontLoadEvent(e,n)})}}get isFontLoadingAPISupported(){return j(this,`isFontLoadingAPISupported`,!!this._document?.fonts)}get isSyncFontLoadingSupported(){return j(this,`isSyncFontLoadingSupported`,d||N.platform.isFirefox)}_queueLoadingCallback(e){let{loadingRequests:t}=this,n={done:!1,complete:function(){A(!n.done,`completeRequest() cannot be called twice.`);n.done=!0;for(;t.length>0&&t[0].done;){let e=t.shift();setTimeout(e.callback,0)}},callback:e};t.push(n);return n}get _loadTestFont(){return j(this,`_loadTestFont`,atob(`T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==`))}_prepareFontLoadEvent(e,t){function n(e,t){return e.charCodeAt(t)<<24|e.charCodeAt(t+1)<<16|e.charCodeAt(t+2)<<8|255&e.charCodeAt(t+3)}function r(e,t,n,r){return e.substring(0,t)+r+e.substring(t+n)}let i,a,o=this._document.createElement(`canvas`);o.width=1;o.height=1;let s=o.getContext(`2d`),c=0,l=`lt${Date.now()}${this.loadTestFontId++}`,u=this._loadTestFont;u=r(u,976,l.length,l);let d=1482184792,f=n(u,16);for(i=0,a=l.length-3;i<a;i+=4)f=f-d+n(l,i)|0;i<l.length&&(f=f-d+n(l+`XXX`,i)|0);u=r(u,16,4,function(e){return String.fromCharCode(e>>24&255,e>>16&255,e>>8&255,255&e)}(f));let p=`@font-face {font-family:"${l}";src:${`url(data:font/opentype;base64,${btoa(u)});`}}`;this.insertRule(p);let m=this._document.createElement(`div`);m.style.visibility=`hidden`;m.style.width=m.style.height=`10px`;m.style.position=`absolute`;m.style.top=m.style.left=`0px`;for(let t of[e.loadedName,l]){let e=this._document.createElement(`span`);e.textContent=`Hi`;e.style.fontFamily=t;m.append(e)}this._document.body.append(m);(function e(t,n){if(++c>30){O(`Load test font never loaded.`);n();return}s.font=`30px `+t;s.fillText(`.`,0,20);s.getImageData(0,0,1,1).data[3]>0?n():setTimeout(e.bind(null,t,n))})(l,()=>{m.remove();t.complete()})}}class _t{compiledGlyphs=Object.create(null);#e;constructor(e,t=null,n,r){this.#e=e;this._inspectFont=t;n&&(this.charProcOperatorList=n);r&&Object.assign(this,r)}createNativeFontFace(){if(!this.data||this.disableFontFace)return null;let e;if(this.cssFontInfo){let t={weight:this.cssFontInfo.fontWeight};this.cssFontInfo.italicAngle&&(t.style=`oblique ${this.cssFontInfo.italicAngle}deg`);e=new FontFace(this.cssFontInfo.fontFamily,this.data,t)}else e=new FontFace(this.loadedName,this.data,{});this._inspectFont?.(this);return e}createFontFaceRule(){if(!this.data||this.disableFontFace)return null;let e=`url(data:${this.mimetype};base64,${this.data.toBase64()});`,t;if(this.cssFontInfo){let n=`font-weight: ${this.cssFontInfo.fontWeight};`;this.cssFontInfo.italicAngle&&(n+=`font-style: oblique ${this.cssFontInfo.italicAngle}deg;`);t=`@font-face {font-family:"${this.cssFontInfo.fontFamily}";${n}src:${e}}`}else t=`@font-face {font-family:"${this.loadedName}";src:${e}}`;this._inspectFont?.(this,e);return t}getPathGenerator(e,t){if(this.compiledGlyphs[t]!==void 0)return this.compiledGlyphs[t];let n=this.loadedName+`_path_`+t,r;try{r=e.get(n)}catch(e){O(`getPathGenerator - ignoring character: "${e}".`)}let i=Me(r?.path);this.fontExtraProperties||e.delete(n);return this.compiledGlyphs[t]=i}get black(){return this.#e.black}get bold(){return this.#e.bold}get disableFontFace(){return this.#e.disableFontFace}set disableFontFace(e){j(this,`disableFontFace`,!!e)}get fontExtraProperties(){return this.#e.fontExtraProperties}get isInvalidPDFjsFont(){return this.#e.isInvalidPDFjsFont}get isType3Font(){return this.#e.isType3Font}get italic(){return this.#e.italic}get missingFile(){return this.#e.missingFile}get remeasure(){return this.#e.remeasure}get vertical(){return this.#e.vertical}get ascent(){return this.#e.ascent}get defaultWidth(){return this.#e.defaultWidth}get descent(){return this.#e.descent}get bbox(){return this.#e.bbox}get fontMatrix(){return this.#e.fontMatrix}get fallbackName(){return this.#e.fallbackName}get loadedName(){return this.#e.loadedName}get mimetype(){return this.#e.mimetype}get name(){return this.#e.name}get data(){return this.#e.data}clearData(){this.#e.clearData()}get cssFontInfo(){return this.#e.cssFontInfo}get systemFontInfo(){return this.#e.systemFontInfo}get defaultVMetrics(){return this.#e.defaultVMetrics}}class vt{static strings=[`fontFamily`,`fontWeight`,`italicAngle`]}class yt{static strings=[`css`,`loadedName`,`baseFontName`,`src`]}class U{static bools=[`black`,`bold`,`disableFontFace`,`fontExtraProperties`,`isInvalidPDFjsFont`,`isType3Font`,`italic`,`missingFile`,`remeasure`,`vertical`];static numbers=[`ascent`,`defaultWidth`,`descent`];static strings=[`fallbackName`,`loadedName`,`mimetype`,`name`];static OFFSET_NUMBERS=Math.ceil(2*this.bools.length/8);static OFFSET_BBOX=this.OFFSET_NUMBERS+8*this.numbers.length;static OFFSET_FONT_MATRIX=this.OFFSET_BBOX+1+8;static OFFSET_DEFAULT_VMETRICS=this.OFFSET_FONT_MATRIX+1+48;static OFFSET_STRINGS=this.OFFSET_DEFAULT_VMETRICS+1+6}class bt{static KIND=0;static HAS_BBOX=1;static HAS_BACKGROUND=2;static SHADING_TYPE=3;static N_COORD=4;static N_COLOR=8;static N_STOP=12;static N_FIGURES=16}class xt{#e;#t=new TextDecoder;#n;constructor(e){this.#e=e;this.#n=new DataView(e)}#r(e){A(e<vt.strings.length,`Invalid string index`);let t=0;for(let n=0;n<e;n++)t+=this.#n.getUint32(t)+4;let n=this.#n.getUint32(t);return this.#t.decode(new Uint8Array(this.#e,t+4,n))}get fontFamily(){return this.#r(0)}get fontWeight(){return this.#r(1)}get italicAngle(){return this.#r(2)}}class St{#e;#t=new TextDecoder;#n;constructor(e){this.#e=e;this.#n=new DataView(e)}get guessFallback(){return this.#n.getUint8(0)!==0}#r(e){A(e<yt.strings.length,`Invalid string index`);let t=5;for(let n=0;n<e;n++)t+=this.#n.getUint32(t)+4;let n=this.#n.getUint32(t);return this.#t.decode(new Uint8Array(this.#e,t+4,n))}get css(){return this.#r(0)}get loadedName(){return this.#r(1)}get baseFontName(){return this.#r(2)}get src(){return this.#r(3)}get style(){let e=1;e+=4+this.#n.getUint32(e);let t=this.#n.getUint32(e),n=this.#t.decode(new Uint8Array(this.#e,e+4,t));e+=4+t;let r=this.#n.getUint32(e);return{style:n,weight:this.#t.decode(new Uint8Array(this.#e,e+4,r))}}}class Ct{#e;#t=new TextDecoder;#n;constructor({buffer:e,extra:t}){this.#e=e;this.#n=new DataView(e);t&&Object.assign(this,t)}#r(e){A(e<U.bools.length,`Invalid boolean index`);let t=Math.floor(e/4),n=2*e%8,r=this.#n.getUint8(t)>>n&3;return r===0?void 0:r===2}get black(){return this.#r(0)}get bold(){return this.#r(1)}get disableFontFace(){return this.#r(2)}get fontExtraProperties(){return this.#r(3)}get isInvalidPDFjsFont(){return this.#r(4)}get isType3Font(){return this.#r(5)}get italic(){return this.#r(6)}get missingFile(){return this.#r(7)}get remeasure(){return this.#r(8)}get vertical(){return this.#r(9)}#i(e){A(e<U.numbers.length,`Invalid number index`);return this.#n.getFloat64(U.OFFSET_NUMBERS+8*e)}get ascent(){return this.#i(0)}get defaultWidth(){return this.#i(1)}get descent(){return this.#i(2)}#a(e,t,n,r){let i=this.#n.getUint8(e);if(i===0)return;A(i===t,`Invalid array length.`);e+=1;let a=Array(i);for(let t=0;t<i;t++){a[t]=this.#n[n](e,!0);e+=r}return a}get bbox(){return this.#a(U.OFFSET_BBOX,4,`getInt16`,2)}get fontMatrix(){return this.#a(U.OFFSET_FONT_MATRIX,6,`getFloat64`,8)}get defaultVMetrics(){return this.#a(U.OFFSET_DEFAULT_VMETRICS,3,`getInt16`,2)}#o(e){A(e<U.strings.length,`Invalid string index`);let t=U.OFFSET_STRINGS+4;for(let n=0;n<e;n++)t+=this.#n.getUint32(t)+4;let n=this.#n.getUint32(t);return this.#t.decode(new Uint8Array(this.#e,t+4,n))}get fallbackName(){return this.#o(0)}get loadedName(){return this.#o(1)}get mimetype(){return this.#o(2)}get name(){return this.#o(3)}#s(){let e=U.OFFSET_STRINGS;e+=4+this.#n.getUint32(e);e+=4+this.#n.getUint32(e);e+=4+this.#n.getUint32(e);return{offset:e,length:this.#n.getUint32(e)}}get data(){let{offset:e,length:t}=this.#s();return t===0?void 0:new Uint8Array(this.#e,e+4,t)}clearData(){let{offset:e,length:t}=this.#s();if(t!==0){this.#n.setUint32(e,0);this.#e=new Uint8Array(this.#e,0,e+4).slice().buffer;this.#n=new DataView(this.#e)}}get cssFontInfo(){let e=U.OFFSET_STRINGS;e+=4+this.#n.getUint32(e);e+=4+this.#n.getUint32(e);let t=this.#n.getUint32(e);if(t===0)return null;let n=new Uint8Array(t);n.set(new Uint8Array(this.#e,e+4,t));return new xt(n.buffer)}get systemFontInfo(){let e=U.OFFSET_STRINGS;e+=4+this.#n.getUint32(e);let t=this.#n.getUint32(e);if(t===0)return null;let n=new Uint8Array(t);n.set(new Uint8Array(this.#e,e+4,t));return new St(n.buffer)}}class wt{constructor(e){this.buffer=e;this.view=new DataView(e);this.data=new Uint8Array(e)}getIR(){let e=this.view,t=this.data[bt.KIND],n=!!this.data[bt.HAS_BBOX],r=!!this.data[bt.HAS_BACKGROUND],i=e.getUint32(bt.N_COORD,!0),a=e.getUint32(bt.N_COLOR,!0),o=e.getUint32(bt.N_STOP,!0),s=20,c=new Float32Array(this.buffer,s,2*i);s+=8*i;let l=new Uint8Array(this.buffer,s,4*a);s+=4*a;let u=[];for(let t=0;t<o;++t){let t=e.getFloat32(s,!0);s+=4;let n=e.getUint32(s,!0);s+=4;u.push([t,`#${n.toString(16).padStart(6,`0`)}`])}let d=null;if(n){d=[];for(let t=0;t<4;++t){d.push(e.getFloat32(s,!0));s+=4}}let p=null;if(r){p=new Uint8Array(this.buffer,s,3);s+=3}if(t===1)return[`RadialAxial`,`axial`,d,u,Array.from(c.slice(0,2)),Array.from(c.slice(2,4)),null,null];if(t===2)return[`RadialAxial`,`radial`,d,u,[c[0],c[1]],[c[3],c[4]],c[2],c[5]];if(t===3){let e=this.data[bt.SHADING_TYPE],t=null;if(c.length>0){t=f.slice();for(let e=0,n=c.length;e<n;e+=2)P.pointBoundingBox(c[e],c[e+1],t)}return[`Mesh`,e,c,l,i,t,d,p]}throw Error(`Unsupported pattern kind: ${t}`)}}class Tt{#e;constructor(e){this.#e=e}get path(){return N.isFloat16ArraySupported?new Float16Array(this.#e):new Float32Array(this.#e)}}function Et(e){if(typeof e!=`string`)return null;if(e.endsWith(`/`))return e;throw Error(`Invalid factory url: "${e}" must include trailing slash.`)}const Dt=e=>typeof e==`object`&&Number.isInteger(e?.num)&&e.num>=0&&Number.isInteger(e?.gen)&&e.gen>=0;(function(e,t,n){if(!Array.isArray(n)||n.length<2)return!1;let[r,i,...a]=n;if(!e(r)&&!Number.isInteger(r))return!1;if(!t(i))return!1;let o=a.length,s=!0;switch(i.name){case`XYZ`:if(o<2||o>3)return!1;break;case`Fit`:case`FitB`:return o===0;case`FitH`:case`FitBH`:case`FitV`:case`FitBV`:if(o>1)return!1;break;case`FitR`:if(o!==4)return!1;s=!1;break;default:return!1}for(let e of a)if(!(typeof e==`number`||s&&e===null))return!1;return!0}).bind(null,Dt,e=>typeof e==`object`&&typeof e?.name==`string`);class Ot{#e=new Map;#t=Promise.resolve();postMessage(e,t){let n={data:structuredClone(e,t?{transfer:t}:null)};this.#t.then(()=>{for(let[e]of this.#e)e.call(this,n)})}addEventListener(e,t,n=null){let r=null;if(n?.signal instanceof AbortSignal){let{signal:i}=n;if(i.aborted){O("LoopbackPort - cannot use an `aborted` signal.");return}let a=()=>this.removeEventListener(e,t);r=()=>i.removeEventListener(`abort`,a);i.addEventListener(`abort`,a)}this.#e.set(t,r)}removeEventListener(e,t){this.#e.get(t)?.();this.#e.delete(t)}terminate(){for(let[,e]of this.#e)e?.();this.#e.clear()}}function kt(){}function W(e){if(e instanceof se||e instanceof ie||e instanceof ne||e instanceof ae||e instanceof re)return e;e instanceof Error||typeof e==`object`&&e||k(`wrapReason: Expected "reason" to be a (possibly cloned) Error.`);switch(e.name){case`AbortException`:return new se(e.message);case`InvalidPDFException`:return new ie(e.message);case`PasswordException`:return new ne(e.message,e.code);case`ResponseException`:return new ae(e.message,e.status,e.missing);case`UnknownErrorException`:return new re(e.message,e.details)}return new re(e.message,e.toString())}class At{#e=new AbortController;constructor(e,t,n){this.sourceName=e;this.targetName=t;this.comObj=n;this.callbackId=1;this.streamId=1;this.streamSinks=Object.create(null);this.streamControllers=Object.create(null);this.callbackCapabilities=Object.create(null);this.actionHandler=Object.create(null);n.addEventListener(`message`,this.#t.bind(this),{signal:this.#e.signal})}#t({data:e}){if(e.targetName!==this.sourceName)return;if(e.stream){this.#r(e);return}if(e.callback){let t=e.callbackId,n=this.callbackCapabilities[t];if(!n)throw Error(`Cannot resolve callback ${t}`);delete this.callbackCapabilities[t];if(e.callback===1)n.resolve(e.data);else{if(e.callback!==2)throw Error(`Unexpected callback case`);n.reject(W(e.reason))}return}let t=this.actionHandler[e.action];if(!t)throw Error(`Unknown action from worker: ${e.action}`);if(e.callbackId){let n=this.sourceName,r=e.sourceName,i=this.comObj;Promise.try(t,e.data).then(function(t){i.postMessage({sourceName:n,targetName:r,callback:1,callbackId:e.callbackId,data:t})},function(t){i.postMessage({sourceName:n,targetName:r,callback:2,callbackId:e.callbackId,reason:W(t)})});return}e.streamId?this.#n(e):t(e.data)}on(e,t){let n=this.actionHandler;if(n[e])throw Error(`There is already an actionName called "${e}"`);n[e]=t}send(e,t,n){this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:e,data:t},n)}sendWithPromise(e,t,n){let r=this.callbackId++,i=Promise.withResolvers();this.callbackCapabilities[r]=i;try{this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:e,callbackId:r,data:t},n)}catch(e){i.reject(e)}return i.promise}sendWithStream(e,t,n,r){let i=this.streamId++,a=this.sourceName,o=this.targetName,s=this.comObj;return new ReadableStream({start:n=>{let c=Promise.withResolvers();this.streamControllers[i]={controller:n,startCall:c,pullCall:null,cancelCall:null,isClosed:!1};s.postMessage({sourceName:a,targetName:o,action:e,streamId:i,data:t,desiredSize:n.desiredSize},r);return c.promise},pull:e=>{let t=Promise.withResolvers();this.streamControllers[i].pullCall=t;s.postMessage({sourceName:a,targetName:o,stream:6,streamId:i,desiredSize:e.desiredSize});return t.promise},cancel:e=>{A(e instanceof Error,`cancel must have a valid reason`);let t=Promise.withResolvers();this.streamControllers[i].cancelCall=t;this.streamControllers[i].isClosed=!0;s.postMessage({sourceName:a,targetName:o,stream:1,streamId:i,reason:W(e)});return t.promise}},n)}#n(e){let t=e.streamId,n=this.sourceName,r=e.sourceName,i=this.comObj,a=this,o=this.actionHandler[e.action],s={enqueue(e,a=1,o){if(this.isCancelled)return;let s=this.desiredSize;this.desiredSize-=a;if(s>0&&this.desiredSize<=0){this.sinkCapability=Promise.withResolvers();this.ready=this.sinkCapability.promise}i.postMessage({sourceName:n,targetName:r,stream:4,streamId:t,chunk:e},o)},close(){if(!this.isCancelled){this.isCancelled=!0;i.postMessage({sourceName:n,targetName:r,stream:3,streamId:t});delete a.streamSinks[t]}},error(e){A(e instanceof Error,`error must have a valid reason`);if(!this.isCancelled){this.isCancelled=!0;i.postMessage({sourceName:n,targetName:r,stream:5,streamId:t,reason:W(e)})}},sinkCapability:Promise.withResolvers(),onPull:null,onCancel:null,isCancelled:!1,desiredSize:e.desiredSize,ready:null};s.sinkCapability.resolve();s.ready=s.sinkCapability.promise;this.streamSinks[t]=s;Promise.try(o,e.data,s).then(function(){i.postMessage({sourceName:n,targetName:r,stream:8,streamId:t,success:!0})},function(e){i.postMessage({sourceName:n,targetName:r,stream:8,streamId:t,reason:W(e)})})}#r(e){let t=e.streamId,n=this.sourceName,r=e.sourceName,i=this.comObj,a=this.streamControllers[t],o=this.streamSinks[t];switch(e.stream){case 8:e.success?a.startCall.resolve():a.startCall.reject(W(e.reason));break;case 7:e.success?a.pullCall.resolve():a.pullCall.reject(W(e.reason));break;case 6:if(!o){i.postMessage({sourceName:n,targetName:r,stream:7,streamId:t,success:!0});break}o.desiredSize<=0&&e.desiredSize>0&&o.sinkCapability.resolve();o.desiredSize=e.desiredSize;Promise.try(o.onPull||kt).then(function(){i.postMessage({sourceName:n,targetName:r,stream:7,streamId:t,success:!0})},function(e){i.postMessage({sourceName:n,targetName:r,stream:7,streamId:t,reason:W(e)})});break;case 4:A(a,`enqueue should have stream controller`);if(a.isClosed)break;a.controller.enqueue(e.chunk);break;case 3:A(a,`close should have stream controller`);if(a.isClosed)break;a.isClosed=!0;a.controller.close();this.#i(a,t);break;case 5:A(a,`error should have stream controller`);a.controller.error(W(e.reason));this.#i(a,t);break;case 2:e.success?a.cancelCall.resolve():a.cancelCall.reject(W(e.reason));this.#i(a,t);break;case 1:if(!o)break;let s=W(e.reason);Promise.try(o.onCancel||kt,s).then(function(){i.postMessage({sourceName:n,targetName:r,stream:2,streamId:t,success:!0})},function(e){i.postMessage({sourceName:n,targetName:r,stream:2,streamId:t,reason:W(e)})});o.sinkCapability.reject(s);o.isCancelled=!0;delete this.streamSinks[t];break;default:throw Error(`Unexpected stream case`)}}async#i(e,t){await Promise.allSettled([e.startCall?.promise,e.pullCall?.promise,e.cancelCall?.promise]);delete this.streamControllers[t]}destroy(){this.#e?.abort();this.#e=null}}class jt{#e=Object.freeze({cMapUrl:`CMap`,standardFontDataUrl:`font`,wasmUrl:`wasm`});constructor({cMapUrl:e=null,standardFontDataUrl:t=null,wasmUrl:n=null}){this.cMapUrl=e;this.standardFontDataUrl=t;this.wasmUrl=n}async fetch({kind:e,filename:t}){switch(e){case`cMapUrl`:case`standardFontDataUrl`:case`wasmUrl`:break;default:k(`Not implemented: ${e}`)}let n=this[e];if(!n)throw Error(`Ensure that the \`${e}\` API parameter is provided.`);let r=`${n}${t}`;return this._fetch(r,e).catch(t=>{throw Error(`Unable to load ${this.#e[e]} data at: ${r}`)})}async _fetch(e,t){k("Abstract method `_fetch` called.")}}class Mt extends jt{async _fetch(e,t){let n=await ge(e,t!==`cMapUrl`||e.endsWith(`.bcmap`)?`bytes`:`text`);return n instanceof Uint8Array?n:ce(n)}}class Nt{#e=!1;constructor({enableHWA:e=!1}){this.#e=e}create(e,t){if(e<=0||t<=0)throw Error(`Invalid canvas size`);let n=this._createCanvas(e,t);return{canvas:n,context:n.getContext(`2d`,{willReadFrequently:!this.#e})}}reset({canvas:e},t,n){if(!e)throw Error(`Canvas is not specified`);if(t<=0||n<=0)throw Error(`Invalid canvas size`);e.width=t;e.height=n}destroy(e){let{canvas:t}=e;if(!t)throw Error(`Canvas is not specified`);t.width=t.height=0;e.canvas=null;e.context=null}_createCanvas(e,t){k("Abstract method `_createCanvas` called.")}}class Pt extends Nt{constructor({ownerDocument:e=globalThis.document,enableHWA:t=!1}){super({enableHWA:t});this._document=e}_createCanvas(e,t){let n=this._document.createElement(`canvas`);n.width=e;n.height=t;return n}}class Ft{addFilter(e){return`none`}addHCMFilter(e,t){return`none`}addAlphaFilter(e){return`none`}addLuminosityFilter(e){return`none`}addKnockoutFilter(e=0){return`none`}addHighlightHCMFilter(e,t,n,r,i){return`none`}destroy(e=!1){}}class It extends Ft{#e;#t;#n;#r;#i;#a;#o=0;constructor({docId:e,ownerDocument:t=globalThis.document}){super();this.#r=e;this.#i=t}get#s(){return this.#t||=new Map}get#c(){return this.#a||=new Map}get#l(){if(!this.#n){let e=this.#i.createElement(`div`),{style:t}=e;t.visibility=`hidden`;t.contain=`strict`;t.width=t.height=0;t.position=`absolute`;t.top=t.left=0;t.zIndex=-1;let n=this.#i.createElementNS(I,`svg`);n.setAttribute(`width`,0);n.setAttribute(`height`,0);this.#n=this.#i.createElementNS(I,`defs`);e.append(n);n.append(this.#n);this.#i.body.append(e)}return this.#n}#u(e){if(e.length===1){let t=e[0],n=Array(256);for(let e=0;e<256;e++)n[e]=t[e]/255;let r=n.join(`,`);return[r,r,r]}let[t,n,r]=e,i=Array(256),a=Array(256),o=Array(256);for(let e=0;e<256;e++){i[e]=t[e]/255;a[e]=n[e]/255;o[e]=r[e]/255}return[i.join(`,`),a.join(`,`),o.join(`,`)]}#d(e){if(this.#e===void 0){this.#e=``;let e=this.#i.URL;e!==this.#i.baseURI&&(ye(e)?O(`#createUrl: ignore "data:"-URL for performance reasons.`):this.#e=te(e,``))}return`url(${this.#e}#${e})`}addFilter(e){if(!e)return`none`;let t=this.#s.get(e);if(t)return t;let[n,r,i]=this.#u(e),a=e.length===1?n:`${n}${r}${i}`;t=this.#s.get(a);if(t){this.#s.set(e,t);return t}let o=`g_${this.#r}_transfer_map_${this.#o++}`,s=this.#d(o);this.#s.set(e,s);this.#s.set(a,s);let c=this.#m(o);this.#g(n,r,i,c);return s}addHCMFilter(e,t){let n=`${e}-${t}`,r=`base`,i=this.#c.get(r);if(i?.key===n)return i.url;if(i){i.filter?.remove();i.key=n;i.url=`none`;i.filter=null}else{i={key:n,url:`none`,filter:null};this.#c.set(r,i)}if(!e||!t)return i.url;let a=this.#v(e);e=P.makeHexColor(...a);let o=this.#v(t);t=P.makeHexColor(...o);this.#l.style.color=``;if(e===`#000000`&&t===`#ffffff`||e===t)return i.url;let s=Array(256);for(let e=0;e<=255;e++){let t=e/255;s[e]=t<=.03928?t/12.92:((t+.055)/1.055)**2.4}let c=s.join(`,`),l=`g_${this.#r}_hcm_filter`,u=i.filter=this.#m(l);this.#g(c,c,c,u);this.#p(u);let d=(e,t)=>{let n=a[e]/255,r=o[e]/255,i=Array(t+1);for(let e=0;e<=t;e++)i[e]=n+e/t*(r-n);return i.join(`,`)};this.#g(d(0,5),d(1,5),d(2,5),u);i.url=this.#d(l);return i.url}addAlphaFilter(e){let t=this.#s.get(e);if(t)return t;let[n]=this.#u([e]),r=`alpha_${n}`;t=this.#s.get(r);if(t){this.#s.set(e,t);return t}let i=`g_${this.#r}_alpha_map_${this.#o++}`,a=this.#d(i);this.#s.set(e,a);this.#s.set(r,a);let o=this.#m(i);this.#_(n,o);return a}addLuminosityFilter(e){let t,n,r=this.#s.get(e||`luminosity`);if(r)return r;if(e){[t]=this.#u([e]);n=`luminosity_${t}`}else n=`luminosity`;r=this.#s.get(n);if(r){this.#s.set(e,r);return r}let i=`g_${this.#r}_luminosity_map_${this.#o++}`,a=this.#d(i);this.#s.set(e,a);this.#s.set(n,a);let o=this.#m(i);this.#f(o);e&&this.#_(t,o);return a}addKnockoutFilter(e=0){let t=e>0?Math.min(1/e,1e6):1e6,n=`knockout_${t}`,r=this.#s.get(n);if(r)return r;let i=`g_${this.#r}_knockout_filter_${this.#o++}`,a=this.#d(i);this.#s.set(n,a);let o=this.#m(i),s=this.#i.createElementNS(I,`feComponentTransfer`);o.append(s);let c=this.#i.createElementNS(I,`feFuncA`);c.setAttribute(`type`,`linear`);c.setAttribute(`slope`,`${t}`);c.setAttribute(`intercept`,`0`);s.append(c);return a}addHighlightHCMFilter(e,t,n,r,i){let a=`${t}-${n}-${r}-${i}`,o=this.#c.get(e);if(o?.key===a)return o.url;if(o){o.filter?.remove();o.key=a;o.url=`none`;o.filter=null}else{o={key:a,url:`none`,filter:null};this.#c.set(e,o)}if(!t||!n)return o.url;let[s,c]=[t,n].map(this.#v.bind(this)),l=Math.round(.2126*s[0]+.7152*s[1]+.0722*s[2]),u=Math.round(.2126*c[0]+.7152*c[1]+.0722*c[2]),[d,f]=[r,i].map(this.#v.bind(this));u<l&&([l,u,d,f]=[u,l,f,d]);this.#l.style.color=``;let p=(e,t,n)=>{let r=Array(256),i=(u-l)/n,a=e/255,o=(t-e)/(255*n),s=0;for(let e=0;e<=n;e++){let t=Math.round(l+e*i),n=a+e*o;for(let e=s;e<=t;e++)r[e]=n;s=t+1}for(let e=s;e<256;e++)r[e]=r[s-1];return r.join(`,`)},m=`g_${this.#r}_hcm_${e}_filter`,h=o.filter=this.#m(m);this.#p(h);this.#g(p(d[0],f[0],5),p(d[1],f[1],5),p(d[2],f[2],5),h);o.url=this.#d(m);return o.url}destroy(e=!1){if(!e||!this.#a?.size){this.#n?.parentNode.parentNode.remove();this.#n=null;this.#t?.clear();this.#t=null;this.#a?.clear();this.#a=null;this.#o=0}}#f(e){let t=this.#i.createElementNS(I,`feColorMatrix`);t.setAttribute(`type`,`matrix`);t.setAttribute(`values`,`0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.59 0.11 0 0`);e.append(t)}#p(e){let t=this.#i.createElementNS(I,`feColorMatrix`);t.setAttribute(`type`,`matrix`);t.setAttribute(`values`,`0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0`);e.append(t)}#m(e){let t=this.#i.createElementNS(I,`filter`);t.setAttribute(`color-interpolation-filters`,`sRGB`);t.setAttribute(`id`,e);this.#l.append(t);return t}#h(e,t,n){let r=this.#i.createElementNS(I,t);r.setAttribute(`type`,`discrete`);r.setAttribute(`tableValues`,n);e.append(r)}#g(e,t,n,r){let i=this.#i.createElementNS(I,`feComponentTransfer`);r.append(i);this.#h(i,`feFuncR`,e);this.#h(i,`feFuncG`,t);this.#h(i,`feFuncB`,n)}#_(e,t){let n=this.#i.createElementNS(I,`feComponentTransfer`);t.append(n);this.#h(n,`feFuncA`,e)}#v(e){this.#l.style.color=e;return Te(getComputedStyle(this.#l).getPropertyValue(`color`))}}d&&O("Please use the `legacy` build in Node.js environments.");class Lt extends Ft{}class Rt extends Nt{_createCanvas(e,t){return process.getBuiltinModule(`module`).createRequire(import.meta.url)(`@napi-rs/canvas`).createCanvas(e,t)}}class zt extends jt{async _fetch(e,t){return async function(e){let t=await process.getBuiltinModule(`fs/promises`).readFile(e);return new Uint8Array(t)}(e)}}const Bt=new class{#e=null;#t=null;#n=null;#r=null;async#i(){if(!globalThis.navigator?.gpu)return!1;try{let e=await navigator.gpu.requestAdapter();if(!e)return!1;this.#r=navigator.gpu.getPreferredCanvasFormat();this.#t=await e.requestDevice();return!0}catch{return!1}}init(){return this.#e||=this.#i()}get isReady(){return this.#t!==null}loadMeshShader(){if(!this.#t||this.#n)return;let e=this.#t.createShaderModule({code:`
|
|
2
|
+
import{getAssetUrl as e}from"../../assets.js";import t from"../../request.js";import n from"../../core/Error.js";import{throwIfAborted as r}from"../../core/promiseUtils.js";import{create as i,fromValues as a}from"../../core/libs/gl-matrix-2/factories/mat2df64.js";import{invert as o}from"../../core/libs/gl-matrix-2/math/mat2d.js";import s from"../../geometry/Extent.js";import{renderBitmap as c}from"./renderExtentUtils.js";const l=!(typeof process!=`object`||process+``!=`[object process]`||process.versions.nw||process.versions.electron&&process.type&&process.type!==`browser`),u=[1/0,1/0,-1/0,-1/0],d=new Float32Array(u),f=[.001,0,0,.001,0,0],p=1.35,m={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},h=`pdfjs_internal_id_`,g=`pdfjs_internal_editor_`,_={NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15,POPUP:16,SIGNATURE:101},v={CREATE:2,FREETEXT_SIZE:11,FREETEXT_COLOR:12,INK_COLOR:21,INK_THICKNESS:22,INK_OPACITY:23,INK_COLOR_AND_OPACITY:24,HIGHLIGHT_COLOR:31,HIGHLIGHT_THICKNESS:32,HIGHLIGHT_FREE:33,HIGHLIGHT_SHOW_ALL:34,DRAW_STEP:41},y={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},b={WARNINGS:1,INFOS:5},x={dependency:1,setLineWidth:2,setLineCap:3,setLineJoin:4,setMiterLimit:5,setDash:6,setRenderingIntent:7,setFlatness:8,setGState:9,save:10,restore:11,transform:12,moveTo:13,lineTo:14,curveTo:15,curveTo2:16,curveTo3:17,closePath:18,rectangle:19,stroke:20,closeStroke:21,fill:22,eoFill:23,fillStroke:24,eoFillStroke:25,closeFillStroke:26,closeEOFillStroke:27,endPath:28,clip:29,eoClip:30,beginText:31,endText:32,setCharSpacing:33,setWordSpacing:34,setHScale:35,setLeading:36,setFont:37,setTextRenderingMode:38,setTextRise:39,moveText:40,setLeadingMoveText:41,setTextMatrix:42,nextLine:43,showText:44,showSpacedText:45,nextLineShowText:46,nextLineSetSpacingShowText:47,setCharWidth:48,setCharWidthAndBounds:49,setStrokeColorSpace:50,setFillColorSpace:51,setStrokeColor:52,setStrokeColorN:53,setFillColor:54,setFillColorN:55,setStrokeGray:56,setFillGray:57,setStrokeRGBColor:58,setFillRGBColor:59,setStrokeCMYKColor:60,setFillCMYKColor:61,shadingFill:62,beginInlineImage:63,beginImageData:64,endInlineImage:65,paintXObject:66,markPoint:67,markPointProps:68,beginMarkedContent:69,beginMarkedContentProps:70,endMarkedContent:71,beginCompat:72,endCompat:73,paintFormXObjectBegin:74,paintFormXObjectEnd:75,beginGroup:76,endGroup:77,beginAnnotation:80,endAnnotation:81,paintImageMaskXObject:83,paintImageMaskXObjectGroup:84,paintImageXObject:85,paintInlineImageXObject:86,paintInlineImageXObjectGroup:87,paintImageXObjectRepeat:88,paintImageMaskXObjectRepeat:89,paintSolidColorImageMask:90,constructPath:91,setStrokeTransparent:92,setFillTransparent:93,rawFillPath:94};let S=b.WARNINGS;function C(e){Number.isInteger(e)&&(S=e)}function w(){return S}function T(e){S>=b.INFOS&&console.info(`Info: ${e}`)}function E(e){S>=b.WARNINGS&&console.warn(`Warning: ${e}`)}function D(e){throw Error(e)}function O(e,t){e||D(t)}function k(e,t=null,n=null){if(!e)return null;if(n&&typeof e==`string`){n.addDefaultProtocol&&e.startsWith(`www.`)&&e.match(/\./g)?.length>=2&&(e=`http://${e}`);if(n.tryConvertEncoding)try{e=function(e){return decodeURIComponent(escape(e))}(e)}catch{}}let r=t?URL.parse(e,t):URL.parse(e);return function(e){switch(e?.protocol){case`http:`:case`https:`:case`ftp:`:case`mailto:`:case`tel:`:return!0;default:return!1}}(r)?r:null}function A(e,t,n=!1){let r=URL.parse(e);if(r){r.hash=t;return r.href}return n&&k(e,`http://example.com`)?e.split(`#`,1)[0]+``:``}function j(e,t,n,r=!1){Object.defineProperty(e,t,{value:n,enumerable:!r,configurable:!0,writable:!1});return n}const M=function(){function e(e,t){this.message=e;this.name=t}e.prototype=Error();e.constructor=e;return e}();class ee extends M{constructor(e,t){super(e,`PasswordException`);this.code=t}}class te extends M{constructor(e,t){super(e,`UnknownErrorException`);this.details=t}}class ne extends M{constructor(e){super(e,`InvalidPDFException`)}}class re extends M{constructor(e,t,n){super(e,`ResponseException`);this.status=t;this.missing=n}}class ie extends M{constructor(e){super(e,`FormatError`)}}class ae extends M{constructor(e){super(e,`AbortException`)}}function oe(e){typeof e!=`string`&&D(`Invalid argument for stringToBytes`);let t=e.length,n=new Uint8Array(t);for(let r=0;r<t;++r)n[r]=255&e.charCodeAt(r);return n}class N{static get isLittleEndian(){let e=new Uint8Array(4);e[0]=1;return j(this,`isLittleEndian`,new Uint32Array(e.buffer,0,1)[0]===1)}static get isOffscreenCanvasSupported(){return j(this,`isOffscreenCanvasSupported`,typeof OffscreenCanvas<`u`)}static get isImageDecoderSupported(){return j(this,`isImageDecoderSupported`,typeof ImageDecoder<`u`)}static get isFloat16ArraySupported(){return j(this,`isFloat16ArraySupported`,typeof Float16Array<`u`)}static get isSanitizerSupported(){return j(this,`isSanitizerSupported`,typeof Sanitizer<`u`)}static get platform(){let{platform:e,userAgent:t}=navigator;return j(this,`platform`,{isAndroid:t.includes(`Android`),isLinux:e.includes(`Linux`),isMac:e.includes(`Mac`),isWindows:e.includes(`Win`),isFirefox:t.includes(`Firefox`)})}static get isCanvasFilterSupported(){let e;this.isOffscreenCanvasSupported?e=new OffscreenCanvas(1,1).getContext(`2d`):typeof document<`u`&&(e=document.createElement(`canvas`).getContext(`2d`));return j(this,`isCanvasFilterSupported`,e?.filter!==void 0)}static get isAlphaColorInputSupported(){return j(this,`isAlphaColorInputSupported`,(()=>{if(typeof document>`u`)return!1;let e=document.createElement(`input`);e.type=`color`;e.setAttribute(`alpha`,``);e.value=`#ff000080`;return e.value!==`#ff0000`})())}}class P{static get hexNums(){return j(this,`hexNums`,Array.from(Array(256).keys(),e=>e.toString(16).padStart(2,`0`)))}static makeHexColor(e,t,n){return`#${this.hexNums[e]}${this.hexNums[t]}${this.hexNums[n]}`}static domMatrixToTransform(e){return[e.a,e.b,e.c,e.d,e.e,e.f]}static scaleMinMax(e,t){let n;if(e[0]){if(e[0]<0){n=t[0];t[0]=t[2];t[2]=n}t[0]*=e[0];t[2]*=e[0];if(e[3]<0){n=t[1];t[1]=t[3];t[3]=n}t[1]*=e[3];t[3]*=e[3]}else{n=t[0];t[0]=t[1];t[1]=n;n=t[2];t[2]=t[3];t[3]=n;if(e[1]<0){n=t[1];t[1]=t[3];t[3]=n}t[1]*=e[1];t[3]*=e[1];if(e[2]<0){n=t[0];t[0]=t[2];t[2]=n}t[0]*=e[2];t[2]*=e[2]}t[0]+=e[4];t[1]+=e[5];t[2]+=e[4];t[3]+=e[5]}static transform(e,t){return[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],e[0]*t[4]+e[2]*t[5]+e[4],e[1]*t[4]+e[3]*t[5]+e[5]]}static multiplyByDOMMatrix(e,t){return[e[0]*t.a+e[2]*t.b,e[1]*t.a+e[3]*t.b,e[0]*t.c+e[2]*t.d,e[1]*t.c+e[3]*t.d,e[0]*t.e+e[2]*t.f+e[4],e[1]*t.e+e[3]*t.f+e[5]]}static applyTransform(e,t,n=0){let r=e[n],i=e[n+1];e[n]=r*t[0]+i*t[2]+t[4];e[n+1]=r*t[1]+i*t[3]+t[5]}static applyTransformToBezier(e,t,n=0){let r=t[0],i=t[1],a=t[2],o=t[3],s=t[4],c=t[5];for(let t=0;t<6;t+=2){let l=e[n+t],u=e[n+t+1];e[n+t]=l*r+u*a+s;e[n+t+1]=l*i+u*o+c}}static applyInverseTransform(e,t){let n=e[0],r=e[1],i=t[0]*t[3]-t[1]*t[2];e[0]=(n*t[3]-r*t[2]+t[2]*t[5]-t[4]*t[3])/i;e[1]=(-n*t[1]+r*t[0]+t[4]*t[1]-t[5]*t[0])/i}static axialAlignedBoundingBox(e,t,n){let r=t[0],i=t[1],a=t[2],o=t[3],s=t[4],c=t[5],l=e[0],u=e[1],d=e[2],f=e[3],p=r*l+s,m=p,h=r*d+s,g=h,_=o*u+c,v=_,y=o*f+c,b=y;if(i!==0||a!==0){let e=i*l,t=i*d,n=a*u,r=a*f;p+=n;g+=n;h+=r;m+=r;_+=e;b+=e;y+=t;v+=t}n[0]=Math.min(n[0],p,h,m,g);n[1]=Math.min(n[1],_,y,v,b);n[2]=Math.max(n[2],p,h,m,g);n[3]=Math.max(n[3],_,y,v,b)}static inverseTransform(e){let t=e[0]*e[3]-e[1]*e[2];return[e[3]/t,-e[1]/t,-e[2]/t,e[0]/t,(e[2]*e[5]-e[4]*e[3])/t,(e[4]*e[1]-e[5]*e[0])/t]}static singularValueDecompose2dScale(e,t){let n=e[0],r=e[1],i=e[2],a=e[3],o=n**2+r**2,s=n*i+r*a,c=i**2+a**2,l=(o+c)/2,u=Math.sqrt(l**2-(o*c-s**2));t[0]=Math.sqrt(l+u||1);t[1]=Math.sqrt(l-u||1)}static normalizeRect(e){let t=e.slice(0);if(e[0]>e[2]){t[0]=e[2];t[2]=e[0]}if(e[1]>e[3]){t[1]=e[3];t[3]=e[1]}return t}static intersect(e,t){let n=Math.max(Math.min(e[0],e[2]),Math.min(t[0],t[2])),r=Math.min(Math.max(e[0],e[2]),Math.max(t[0],t[2]));if(n>r)return null;let i=Math.max(Math.min(e[1],e[3]),Math.min(t[1],t[3])),a=Math.min(Math.max(e[1],e[3]),Math.max(t[1],t[3]));return i>a?null:[n,i,r,a]}static pointBoundingBox(e,t,n){n[0]=Math.min(n[0],e);n[1]=Math.min(n[1],t);n[2]=Math.max(n[2],e);n[3]=Math.max(n[3],t)}static rectBoundingBox(e,t,n,r,i){i[0]=Math.min(i[0],e,n);i[1]=Math.min(i[1],t,r);i[2]=Math.max(i[2],e,n);i[3]=Math.max(i[3],t,r)}static#e(e,t,n,r,i,a,o,s,c,l){if(c<=0||c>=1)return;let u=1-c,d=c*c,f=d*c,p=u*(u*(u*e+3*c*t)+3*d*n)+f*r,m=u*(u*(u*i+3*c*a)+3*d*o)+f*s;l[0]=Math.min(l[0],p);l[1]=Math.min(l[1],m);l[2]=Math.max(l[2],p);l[3]=Math.max(l[3],m)}static#t(e,t,n,r,i,a,o,s,c,l,u,d){if(Math.abs(c)<1e-12){Math.abs(l)>=1e-12&&this.#e(e,t,n,r,i,a,o,s,-u/l,d);return}let f=l**2-4*u*c;if(f<0)return;let p=Math.sqrt(f),m=2*c;this.#e(e,t,n,r,i,a,o,s,(-l+p)/m,d);this.#e(e,t,n,r,i,a,o,s,(-l-p)/m,d)}static bezierBoundingBox(e,t,n,r,i,a,o,s,c){c[0]=Math.min(c[0],e,o);c[1]=Math.min(c[1],t,s);c[2]=Math.max(c[2],e,o);c[3]=Math.max(c[3],t,s);this.#t(e,n,i,o,t,r,a,s,3*(3*(n-i)-e+o),6*(e-2*n+i),3*(n-e),c);this.#t(e,n,i,o,t,r,a,s,3*(3*(r-a)-t+s),6*(t-2*r+a),3*(r-t),c)}}function se(){if(typeof crypto.randomUUID==`function`)return crypto.randomUUID();let e=new Uint8Array(32);crypto.getRandomValues(e);return function(e){typeof e==`object`&&e?.length!==void 0||D(`Invalid argument for bytesToString`);let t=e.length,n=8192;if(t<n)return String.fromCharCode.apply(null,e);let r=[];for(let i=0;i<t;i+=n){let a=Math.min(i+n,t),o=e.subarray(i,a);r.push(String.fromCharCode.apply(null,o))}return r.join(``)}(e)}const ce=()=>[],le=()=>new Map,ue=()=>Object.create(null);function F(e,t,n){return Math.min(Math.max(e,t),n)}class de{static textContent(e){let t=[],n={items:t,styles:Object.create(null)};(function e(n){if(!n)return;let r=null,i=n.name;if(i===`#text`)r=n.value;else{if(!de.shouldBuildText(i))return;n?.attributes?.textContent?r=n.attributes.textContent:n.value&&(r=n.value)}r!==null&&t.push({str:r});if(n.children)for(let t of n.children)e(t)})(e);return n}static shouldBuildText(e){return e!==`textarea`&&e!==`input`&&e!==`option`&&e!==`select`}}class fe{static setupStorage(e,t,n,r,i){let a=r.getValue(t,{value:null});switch(n.name){case`textarea`:a.value!==null&&(e.textContent=a.value);if(i===`print`)break;e.addEventListener(`input`,e=>{r.setValue(t,{value:e.target.value})});break;case`input`:if(n.attributes.type===`radio`||n.attributes.type===`checkbox`){a.value===n.attributes.xfaOn?e.setAttribute(`checked`,!0):a.value===n.attributes.xfaOff&&e.removeAttribute(`checked`);if(i===`print`)break;e.addEventListener(`change`,e=>{r.setValue(t,{value:e.target.checked?e.target.getAttribute(`xfaOn`):e.target.getAttribute(`xfaOff`)})})}else{a.value!==null&&e.setAttribute(`value`,a.value);if(i===`print`)break;e.addEventListener(`input`,e=>{r.setValue(t,{value:e.target.value})})}break;case`select`:if(a.value!==null){e.setAttribute(`value`,a.value);for(let e of n.children)e.attributes.value===a.value?e.attributes.selected=!0:Object.hasOwn(e.attributes,`selected`)&&delete e.attributes.selected}e.addEventListener(`input`,e=>{let n=e.target.options,i=n.selectedIndex===-1?``:n[n.selectedIndex].value;r.setValue(t,{value:i})})}}static setAttributes({html:e,element:t,storage:n=null,intent:r,linkService:i}){let{attributes:a}=t,o=e instanceof HTMLAnchorElement;a.type===`radio`&&(a.name=`${a.name}-${r}`);for(let[t,n]of Object.entries(a))if(n!=null)switch(t){case`class`:n.length&&e.setAttribute(t,n.join(` `));break;case`dataId`:break;case`id`:e.setAttribute(`data-element-id`,n);break;case`style`:Object.assign(e.style,n);break;case`textContent`:e.textContent=n;break;default:(!o||t!==`href`&&t!==`newWindow`)&&e.setAttribute(t,n)}o&&i.addLinkAttributes(e,a.href,a.newWindow);n&&a.dataId&&this.setupStorage(e,a.dataId,t,n)}static render(e){let t=e.annotationStorage,n=e.linkService,r=e.xfaHtml,i=e.intent||`display`,a=document.createElement(r.name);r.attributes&&this.setAttributes({html:a,element:r,intent:i,linkService:n});let o=i!==`richText`,s=e.div;s.append(a);if(e.viewport){let t=`matrix(${e.viewport.transform.join(`,`)})`;s.style.transform=t}o&&s.setAttribute(`class`,`xfaLayer xfaFont`);let c=[];if(r.children.length===0){if(r.value){let e=document.createTextNode(r.value);a.append(e);o&&de.shouldBuildText(r.name)&&c.push(e)}return{textDivs:c}}let l=[[r,-1,a]];for(;l.length>0;){let[e,r,a]=l.at(-1);if(r+1===e.children.length){l.pop();continue}let s=e.children[++l.at(-1)[1]];if(s===null)continue;let{name:u}=s;if(u===`#text`){let e=document.createTextNode(s.value);c.push(e);a.append(e);continue}let d=s?.attributes?.xmlns?document.createElementNS(s.attributes.xmlns,u):document.createElement(u);a.append(d);s.attributes&&this.setAttributes({html:d,element:s,storage:t,intent:i,linkService:n});if(s.children?.length>0)l.push([s,-1,d]);else if(s.value){let e=document.createTextNode(s.value);o&&de.shouldBuildText(u)&&c.push(e);d.append(e)}}for(let e of s.querySelectorAll(`.xfaNonInteractive input, .xfaNonInteractive textarea`))e.setAttribute(`readOnly`,!0);return{textDivs:c}}static update(e){let t=`matrix(${e.viewport.transform.join(`,`)})`;e.div.style.transform=t;e.div.hidden=!1}}const I=`http://www.w3.org/2000/svg`;class pe{static CSS=96;static PDF=72;static PDF_TO_CSS_UNITS=this.CSS/this.PDF}async function me(e,t=`text`){if(be(e,document.baseURI)){let n=await fetch(e);if(!n.ok)throw Error(n.statusText);switch(t){case`blob`:return n.blob();case`bytes`:return n.bytes();case`json`:return n.json()}return n.text()}return new Promise((n,r)=>{let i=new XMLHttpRequest;i.open(`GET`,e,!0);i.responseType=t===`bytes`?`arraybuffer`:t;i.onreadystatechange=()=>{if(i.readyState===XMLHttpRequest.DONE){if(i.status!==200&&i.status!==0)r(Error(i.statusText));else{switch(t){case`bytes`:n(new Uint8Array(i.response));return;case`blob`:case`json`:n(i.response);return}n(i.responseText)}}};i.send(null)})}class he{constructor({viewBox:e,userUnit:t,scale:n,rotation:r,offsetX:i=0,offsetY:a=0,dontFlip:o=!1}){this.viewBox=e;this.userUnit=t;this.scale=n;this.rotation=r;this.offsetX=i;this.offsetY=a;n*=t;let s=(e[2]+e[0])/2,c=(e[3]+e[1])/2,l,u,d,f,p,m,h,g;(r%=360)<0&&(r+=360);switch(r){case 180:l=-1;u=0;d=0;f=1;break;case 90:l=0;u=1;d=1;f=0;break;case 270:l=0;u=-1;d=-1;f=0;break;case 0:l=1;u=0;d=0;f=-1;break;default:throw Error(`PageViewport: Invalid rotation, must be a multiple of 90 degrees.`)}if(o){d=-d;f=-f}if(l===0){p=Math.abs(c-e[1])*n+i;m=Math.abs(s-e[0])*n+a;h=(e[3]-e[1])*n;g=(e[2]-e[0])*n}else{p=Math.abs(s-e[0])*n+i;m=Math.abs(c-e[1])*n+a;h=(e[2]-e[0])*n;g=(e[3]-e[1])*n}this.transform=[l*n,u*n,d*n,f*n,p-l*n*s-d*n*c,m-u*n*s-f*n*c];this.width=h;this.height=g}get rawDims(){let e=this.viewBox;return j(this,`rawDims`,{pageWidth:e[2]-e[0],pageHeight:e[3]-e[1],pageX:e[0],pageY:e[1]})}clone({scale:e=this.scale,rotation:t=this.rotation,offsetX:n=this.offsetX,offsetY:r=this.offsetY,dontFlip:i=!1}={}){return new he({viewBox:this.viewBox.slice(),userUnit:this.userUnit,scale:e,rotation:t,offsetX:n,offsetY:r,dontFlip:i})}convertToViewportPoint(e,t){let n=[e,t];P.applyTransform(n,this.transform);return n}convertToViewportRectangle(e){let t=[e[0],e[1]];P.applyTransform(t,this.transform);let n=[e[2],e[3]];P.applyTransform(n,this.transform);return[t[0],t[1],n[0],n[1]]}convertToPdfPoint(e,t){let n=[e,t];P.applyInverseTransform(n,this.transform);return n}}class ge extends M{constructor(e,t=0){super(e,`RenderingCancelledException`);this.extraDelay=t}}function _e(e){let t=e.length,n=0;for(;n<t&&e[n].trim()===``;)n++;return e.substring(n,n+5).toLowerCase()===`data:`}function ve(e){return typeof e==`string`&&/\.pdf$/i.test(e)}class ye{#e=new Map;times=[];time(e){this.#e.has(e)&&E(`Timer is already running for ${e}`);this.#e.set(e,Date.now())}timeEnd(e){this.#e.has(e)||E(`Timer has not been started for ${e}`);this.times.push({name:e,start:this.#e.get(e),end:Date.now()});this.#e.delete(e)}toString(){let e=Math.max(...this.times.map(e=>e.name.length));return this.times.map(t=>`${t.name.padEnd(e)} ${t.end-t.start}ms\n`).join(``)}}function be(e,t){let n=t?URL.parse(e,t):URL.parse(e);return/https?:/.test(n?.protocol??``)}function L(e){e.preventDefault()}function R(e){e.preventDefault();e.stopPropagation()}class xe{static#e;static toDateObject(e){if(e instanceof Date)return e;if(!e||typeof e!=`string`)return null;this.#e||=RegExp(`^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?`);let t=this.#e.exec(e);if(!t)return null;let n=parseInt(t[1],10),r=parseInt(t[2],10);r=r>=1&&r<=12?r-1:0;let i=parseInt(t[3],10);i=i>=1&&i<=31?i:1;let a=parseInt(t[4],10);a=a>=0&&a<=23?a:0;let o=parseInt(t[5],10);o=o>=0&&o<=59?o:0;let s=parseInt(t[6],10);s=s>=0&&s<=59?s:0;let c=t[7]||`Z`,l=parseInt(t[8],10);l=l>=0&&l<=23?l:0;let u=parseInt(t[9],10)||0;u=u>=0&&u<=59?u:0;if(c===`-`){a+=l;o+=u}else if(c===`+`){a-=l;o-=u}return new Date(Date.UTC(n,r,i,a,o,s))}}function Se(e){if(e.startsWith(`#`)){let t=e.slice(1);return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16),t.length>=8?parseInt(t.slice(6,8),16)/255:1]}if(e.startsWith(`rgb(`)){let[t,n,r]=e.slice(4,-1).split(`,`).map(e=>parseInt(e,10));return[t,n,r,1]}if(e.startsWith(`rgba(`)){let t=e.slice(5,-1).split(`,`);return[parseInt(t[0],10),parseInt(t[1],10),parseInt(t[2],10),parseFloat(t[3])]}let t=e.match(/^color\(srgb\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)(?:\s*\/\s*([\d.]+|none))?\)$/);return t?[Math.round(255*parseFloat(t[1])),Math.round(255*parseFloat(t[2])),Math.round(255*parseFloat(t[3])),t[4]!==void 0&&t[4]!==`none`?parseFloat(t[4]):1]:null}function Ce(e){let t=Se(e);if(!t){E(`Not a valid color format: "${e}"`);return[0,0,0]}return t.slice(0,3)}function z(e){let{a:t,b:n,c:r,d:i,e:a,f:o}=e.getTransform();return[t,n,r,i,a,o]}function B(e){let{a:t,b:n,c:r,d:i,e:a,f:o}=e.getTransform().invertSelf();return[t,n,r,i,a,o]}function we(e,t,n=!1,r=!0){if(t instanceof he){let{pageWidth:r,pageHeight:i}=t.rawDims,{style:a}=e,o=`round(down, var(--total-scale-factor) * ${r}px, var(--scale-round-x))`,s=`round(down, var(--total-scale-factor) * ${i}px, var(--scale-round-y))`;if(n&&t.rotation%180!=0){a.width=s;a.height=o}else{a.width=o;a.height=s}}r&&e.setAttribute(`data-main-rotation`,t.rotation)}class Te{constructor(){let{pixelRatio:e}=Te;this.sx=e;this.sy=e}get scaled(){return this.sx!==1||this.sy!==1}get symmetric(){return this.sx===this.sy}limitCanvas(e,t,n,r,i=-1){let a=1/0,o=1/0,s=1/0;(n=Te.capPixels(n,i))>0&&(a=Math.sqrt(n/(e*t)));if(r!==-1){o=r/e;s=r/t}let c=Math.min(a,o,s);if(this.sx>c||this.sy>c){this.sx=c;this.sy=c;return!0}return!1}static get pixelRatio(){return globalThis.devicePixelRatio||1}static capPixels(e,t){if(t>=0){let n=Math.ceil(window.screen.availWidth*window.screen.availHeight*this.pixelRatio**2*(1+t/100));return e>0?Math.min(e,n):n}return e}}const Ee=[`image/apng`,`image/avif`,`image/bmp`,`image/gif`,`image/jpeg`,`image/png`,`image/svg+xml`,`image/webp`,`image/x-icon`];class De{static get isDarkMode(){return j(this,`isDarkMode`,!!window?.matchMedia?.(`(prefers-color-scheme: dark)`).matches)}}function Oe({html:e,dir:t,className:n},r){let i=document.createDocumentFragment();if(typeof e==`string`){let n=document.createElement(`p`);n.dir=t||`auto`;let r=e.split(/(?:\r\n?|\n)/);for(let e=0,t=r.length;e<t;++e){let i=r[e];n.append(document.createTextNode(i));e<t-1&&n.append(document.createElement(`br`))}i.append(n)}else fe.render({xfaHtml:e,div:i,intent:`richText`});i.firstElementChild.classList.add(`richText`,n);r.append(i)}function ke(e){let t=new Path2D;if(!e)return t;for(let n=0,r=e.length;n<r;)switch(e[n++]){case 0:t.moveTo(e[n++],e[n++]);break;case 1:t.lineTo(e[n++],e[n++]);break;case 2:t.bezierCurveTo(e[n++],e[n++],e[n++],e[n++],e[n++],e[n++]);break;case 3:t.quadraticCurveTo(e[n++],e[n++],e[n++],e[n++]);break;case 4:t.closePath();break;default:E(`Unrecognized drawing path operator: ${e[n-1]}`)}return t}class Ae{#e=null;#t=null;#n;#r=null;#i=null;#a=null;#o=null;#s=null;static#c=null;constructor(e){this.#n=e;Ae.#c||=Object.freeze({freetext:`pdfjs-editor-remove-freetext-button`,highlight:`pdfjs-editor-remove-highlight-button`,ink:`pdfjs-editor-remove-ink-button`,stamp:`pdfjs-editor-remove-stamp-button`,signature:`pdfjs-editor-remove-signature-button`})}render(){let e=this.#e=document.createElement(`div`);e.classList.add(`editToolbar`,`hidden`);e.setAttribute(`role`,`toolbar`);let t=this.#n._uiManager._signal;if(t instanceof AbortSignal&&!t.aborted){e.addEventListener(`contextmenu`,L,{signal:t});e.addEventListener(`pointerdown`,Ae.#l,{signal:t})}let n=this.#r=document.createElement(`div`);n.className=`buttons`;e.append(n);let r=this.#n.toolbarPosition;if(r){let{style:t}=e;t.insetInlineEnd=100*(this.#n._uiManager.direction===`ltr`?1-r[0]:r[0])+`%`;t.top=`calc(${100*r[1]}% + var(--editor-toolbar-vert-offset))`}return e}get div(){return this.#e}static#l(e){e.stopPropagation()}#u(e){this.#n._focusEventsAllowed=!1;R(e)}#d(e){this.#n._focusEventsAllowed=!0;R(e)}#f(e){let t=this.#n._uiManager._signal;if(!(t instanceof AbortSignal)||t.aborted)return!1;e.addEventListener(`focusin`,this.#u.bind(this),{capture:!0,signal:t});e.addEventListener(`focusout`,this.#d.bind(this),{capture:!0,signal:t});e.addEventListener(`contextmenu`,L,{signal:t});return!0}hide(){this.#e.classList.add(`hidden`);this.#t?.hideDropdown()}show(){this.#e.classList.remove(`hidden`);this.#i?.shown();this.#a?.shown()}addDeleteButton(){let{editorType:e,_uiManager:t}=this.#n,n=document.createElement(`button`);n.classList.add(`basic`,`deleteButton`);n.tabIndex=0;n.setAttribute(`data-l10n-id`,Ae.#c[e]);this.#f(n)&&n.addEventListener(`click`,e=>{t.delete()},{signal:t._signal});this.#r.append(n)}get#p(){let e=document.createElement(`div`);e.className=`divider`;return e}async addAltText(e){let t=await e.render();this.#f(t);this.#r.append(t,this.#p);this.#i=e}addComment(e,t=null){if(this.#a)return;let n=e.renderForToolbar();if(!n)return;this.#f(n);let r=this.#o=this.#p;if(t){this.#r.insertBefore(n,t);this.#r.insertBefore(r,t)}else this.#r.append(n,r);this.#a=e;e.toolbar=this}addColorPicker(e){if(this.#t)return;this.#t=e;let t=e.renderButton();this.#f(t);this.#r.append(t,this.#p)}async addEditSignatureButton(e){let t=this.#s=await e.renderEditButton(this.#n);this.#f(t);this.#r.append(t,this.#p)}removeButton(e){if(e===`comment`){this.#a?.removeToolbarCommentButton();this.#a=null;this.#o?.remove();this.#o=null}}async addButton(e,t){switch(e){case`colorPicker`:t&&this.addColorPicker(t);break;case`altText`:t&&await this.addAltText(t);break;case`editSignature`:t&&await this.addEditSignatureButton(t);break;case`delete`:this.addDeleteButton();break;case`comment`:t&&this.addComment(t)}}async addButtonBefore(e,t,n){if(!t&&e===`comment`)return;let r=this.#r.querySelector(n);r&&e===`comment`&&this.addComment(t,r)}updateEditSignatureButton(e){this.#s&&(this.#s.title=e)}remove(){this.#e.remove();this.#t?.destroy();this.#t=null}}class je{#e=null;#t=null;#n;constructor(e){this.#n=e}#r(){let e=this.#t=document.createElement(`div`);e.className=`editToolbar`;e.setAttribute(`role`,`toolbar`);let t=this.#n._signal;t instanceof AbortSignal&&!t.aborted&&e.addEventListener(`contextmenu`,L,{signal:t});let n=this.#e=document.createElement(`div`);n.className=`buttons`;e.append(n);this.#n.hasCommentManager()&&this.#a(`commentButton`,`pdfjs-comment-floating-button`,`pdfjs-comment-floating-button-label`,()=>{this.#n.commentSelection(`floating_button`)});this.#a(`highlightButton`,`pdfjs-highlight-floating-button1`,`pdfjs-highlight-floating-button-label`,()=>{this.#n.highlightSelection(`floating_button`)});return e}#i(e,t){let n=0,r=0;for(let i of e){let e=i.y+i.height;if(e<n)continue;let a=i.x+(t?i.width:0);if(e>n){r=a;n=e}else t?a>r&&(r=a):a<r&&(r=a)}return[t?1-r:r,n]}show(e,t,n){let[r,i]=this.#i(t,n),{style:a}=this.#t||=this.#r();e.append(this.#t);a.insetInlineEnd=100*r+`%`;a.top=`calc(${100*i}% + var(--editor-toolbar-vert-offset))`}hide(){this.#t.remove()}#a(e,t,n,r){let i=document.createElement(`button`);i.classList.add(`basic`,e);i.tabIndex=0;i.setAttribute(`data-l10n-id`,t);let a=document.createElement(`span`);i.append(a);a.className=`visuallyHidden`;a.setAttribute(`data-l10n-id`,n);let o=this.#n._signal;if(o instanceof AbortSignal&&!o.aborted){i.addEventListener(`contextmenu`,L,{signal:o});i.addEventListener(`click`,r,{signal:o})}this.#e.append(i)}}function Me(e,t,n){for(let r of n)t.addEventListener(r,e[r].bind(e))}class V{static#e=NaN;static#t=null;static#n=NaN;static#r=null;static initializeAndAddPointerId(e){(V.#t||=new Set).add(e)}static setPointer(e,t){V.#e||=t;V.#r??=e}static setTimeStamp(e){V.#n=e}static isSamePointerId(e){return V.#e===e}static isSamePointerIdOrRemove(e){if(V.#e===e)return!0;V.#t?.delete(e);return!1}static isSamePointerType(e){return V.#r===e}static isInitializedAndDifferentPointerType(e){return V.#r!==null&&!V.isSamePointerType(e)}static isSameTimeStamp(e){return V.#n===e}static isUsingMultiplePointers(){return V.#t?.size>=1}static clearPointerType(){V.#r=null}static clearPointerIds(){V.#e=NaN;V.#t=null}static clearTimeStamp(){V.#n=NaN}}class Ne{#e=0;get id(){return`${g}${this.#e++}`}}class Pe{#e=se();#t=0;#n=null;static get _isSVGFittingCanvas(){let e=new OffscreenCanvas(1,3).getContext(`2d`,{willReadFrequently:!0}),t=new Image;t.src=`data:image/svg+xml;charset=UTF-8,<svg viewBox="0 0 1 1" width="1" height="1" xmlns="http://www.w3.org/2000/svg"><rect width="1" height="1" style="fill:red;"/></svg>`;return j(this,`_isSVGFittingCanvas`,t.decode().then(()=>{e.drawImage(t,0,0,1,1,0,0,1,3);return new Uint32Array(e.getImageData(0,0,1,1).data.buffer)[0]===0}))}async#r(e,t){this.#n||=new Map;let n=this.#n.get(e);if(n===null)return null;if(n?.bitmap){n.refCounter+=1;return n}try{n||={bitmap:null,id:`image_${this.#e}_${this.#t++}`,refCounter:0,isSvg:!1};let e;if(typeof t==`string`){n.url=t;e=await me(t,`blob`)}else t instanceof File?e=n.file=t:t instanceof Blob&&(e=t);if(e.type===`image/svg+xml`){let t=Pe._isSVGFittingCanvas,r=new FileReader,i=new Image,a=new Promise((e,a)=>{i.onload=()=>{n.bitmap=i;n.isSvg=!0;e()};r.onload=async()=>{let e=n.svgUrl=r.result;i.src=await t?`${e}#svgView(preserveAspectRatio(none))`:e};i.onerror=r.onerror=a});r.readAsDataURL(e);await a}else n.bitmap=await createImageBitmap(e);n.refCounter=1}catch(e){E(e);n=null}this.#n.set(e,n);n&&this.#n.set(n.id,n);return n}async getFromFile(e){let{lastModified:t,name:n,size:r,type:i}=e;return this.#r(`${t}_${n}_${r}_${i}`,e)}async getFromUrl(e){return this.#r(e,e)}async getFromBlob(e,t){let n=await t;return this.#r(e,n)}async getFromId(e){this.#n||=new Map;let t=this.#n.get(e);if(!t)return null;if(t.bitmap){t.refCounter+=1;return t}if(t.file)return this.getFromFile(t.file);if(t.blobPromise){let{blobPromise:e}=t;delete t.blobPromise;return this.getFromBlob(t.id,e)}return this.getFromUrl(t.url)}getFromCanvas(e,t){this.#n||=new Map;let n=this.#n.get(e);if(n?.bitmap){n.refCounter+=1;return n}let r=new OffscreenCanvas(t.width,t.height);r.getContext(`2d`).drawImage(t,0,0);n={bitmap:r.transferToImageBitmap(),id:`image_${this.#e}_${this.#t++}`,refCounter:1,isSvg:!1};this.#n.set(e,n);this.#n.set(n.id,n);return n}getSvgUrl(e){let t=this.#n.get(e);return t?.isSvg?t.svgUrl:null}deleteId(e){this.#n||=new Map;let t=this.#n.get(e);if(!t)return;--t.refCounter;if(t.refCounter!==0)return;let{bitmap:n}=t;if(!t.url&&!t.file){let e=new OffscreenCanvas(n.width,n.height);e.getContext(`bitmaprenderer`).transferFromImageBitmap(n);t.blobPromise=e.convertToBlob()}n.close?.();t.bitmap=null}isValidId(e){return e.startsWith(`image_${this.#e}_`)}}class Fe{#e=[];#t=!1;#n;#r=-1;constructor(e=128){this.#n=e}add({cmd:e,undo:t,post:n,mustExec:r,type:i=NaN,overwriteIfSameType:a=!1,keepUndo:o=!1}){r&&e();if(this.#t)return;let s={cmd:e,undo:t,post:n,type:i};if(this.#r===-1){this.#e.length>0&&(this.#e.length=0);this.#r=0;this.#e.push(s);return}if(a&&this.#e[this.#r].type===i){o&&(s.undo=this.#e[this.#r].undo);this.#e[this.#r]=s;return}let c=this.#r+1;if(c===this.#n)this.#e.splice(0,1);else{this.#r=c;c<this.#e.length&&this.#e.splice(c)}this.#e.push(s)}undo(){if(this.#r===-1)return;this.#t=!0;let{undo:e,post:t}=this.#e[this.#r];e();t?.();this.#t=!1;--this.#r}redo(){if(this.#r<this.#e.length-1){this.#r+=1;this.#t=!0;let{cmd:e,post:t}=this.#e[this.#r];e();t?.();this.#t=!1}}hasSomethingToUndo(){return this.#r!==-1}hasSomethingToRedo(){return this.#r<this.#e.length-1}cleanType(e){if(this.#r!==-1){for(let t=this.#r;t>=0;t--)if(this.#e[t].type!==e){this.#e.splice(t+1,this.#r-t);this.#r=t;return}this.#e.length=0;this.#r=-1}}destroy(){this.#e=null}}class Ie{constructor(e){this.buffer=[];this.callbacks=new Map;this.allKeys=new Set;let{isMac:t}=N.platform;for(let[n,r,i={}]of e)for(let e of n){let n=e.startsWith(`mac+`);if(t&&n){this.callbacks.set(e.slice(4),{callback:r,options:i});this.allKeys.add(e.split(`+`).at(-1))}else if(!t&&!n){this.callbacks.set(e,{callback:r,options:i});this.allKeys.add(e.split(`+`).at(-1))}}}#e(e){e.altKey&&this.buffer.push(`alt`);e.ctrlKey&&this.buffer.push(`ctrl`);e.metaKey&&this.buffer.push(`meta`);e.shiftKey&&this.buffer.push(`shift`);this.buffer.push(e.key);let t=this.buffer.join(`+`);this.buffer.length=0;return t}exec(e,t){if(!this.allKeys.has(t.key))return;let n=this.callbacks.get(this.#e(t));if(!n)return;let{callback:r,options:{bubbles:i=!1,args:a=[],checker:o=null}}=n;if(!o||o(e,t)){r.bind(e,...a,t)();i||R(t)}}}class Le{static _colorsMapping=new Map([[`CanvasText`,[0,0,0]],[`Canvas`,[255,255,255]]]);get _colors(){let e=new Map([[`CanvasText`,null],[`Canvas`,null]]);(function(e){let t=document.createElement(`span`);t.style.visibility=`hidden`;t.style.colorScheme=`only light`;document.body.append(t);for(let n of e.keys()){t.style.color=n;let r=window.getComputedStyle(t).color;e.set(n,Ce(r))}t.remove()})(e);return j(this,`_colors`,e)}convert(e){let t=Ce(e);if(!window.matchMedia(`(forced-colors: active)`).matches)return t;for(let[e,n]of this._colors)if(n.every((e,n)=>e===t[n]))return Le._colorsMapping.get(e);return t}getHexCode(e){let t=this._colors.get(e);return t?P.makeHexColor(...t):e}}class Re{#e=new AbortController;#t=null;#n=null;#r=new Map;#i=new Map;#a=null;#o=null;#s=null;#c=null;#l=new Fe;#u=null;#d=null;#f=null;#p=0;#m=new Set;#h=null;#g=null;#_=new Set;_editorUndoBar=null;#v=!1;#y=!1;#b=!1;#x=null;#S=null;#C=null;#w=null;#T=!1;#E=null;#D=new Ne;#O=!1;#k=!1;#A=!1;#j=null;#M=null;#N=null;#P=null;#F=null;#I=_.NONE;#L=new Set;#R=null;#z=null;#B=null;#V=null;#H=null;#U={isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1};#W=[0,0];#G=null;#K=null;#q=null;#J=null;#Y=null;static TRANSLATE_SMALL=1;static TRANSLATE_BIG=10;static get _keyboardManager(){let e=Re.prototype,t=e=>e.#K.contains(document.activeElement)&&document.activeElement.tagName!==`BUTTON`&&e.hasSomethingToControl(),n=(e,{target:t})=>{if(t instanceof HTMLInputElement){let{type:e}=t;return e!==`text`&&e!==`number`}return!0},r=this.TRANSLATE_SMALL,i=this.TRANSLATE_BIG;return j(this,`_keyboardManager`,new Ie([[[`ctrl+a`,`mac+meta+a`],e.selectAll,{checker:n}],[[`ctrl+z`,`mac+meta+z`],e.undo,{checker:n}],[[`ctrl+y`,`ctrl+shift+z`,`mac+meta+shift+z`,`ctrl+shift+Z`,`mac+meta+shift+Z`],e.redo,{checker:n}],[[`Backspace`,`alt+Backspace`,`ctrl+Backspace`,`shift+Backspace`,`mac+Backspace`,`mac+alt+Backspace`,`mac+ctrl+Backspace`,`Delete`,`ctrl+Delete`,`shift+Delete`,`mac+Delete`],e.delete,{checker:n}],[[`Enter`,`mac+Enter`],e.addNewEditorFromKeyboard,{checker:(e,{target:t})=>!(t instanceof HTMLButtonElement)&&e.#K.contains(t)&&!e.isEnterHandled}],[[` `,`mac+ `],e.addNewEditorFromKeyboard,{checker:(e,{target:t})=>!(t instanceof HTMLButtonElement)&&e.#K.contains(document.activeElement)}],[[`Escape`,`mac+Escape`],e.unselectAll],[[`ArrowLeft`,`mac+ArrowLeft`],e.translateSelectedEditors,{args:[-r,0],checker:t}],[[`ctrl+ArrowLeft`,`mac+shift+ArrowLeft`],e.translateSelectedEditors,{args:[-i,0],checker:t}],[[`ArrowRight`,`mac+ArrowRight`],e.translateSelectedEditors,{args:[r,0],checker:t}],[[`ctrl+ArrowRight`,`mac+shift+ArrowRight`],e.translateSelectedEditors,{args:[i,0],checker:t}],[[`ArrowUp`,`mac+ArrowUp`],e.translateSelectedEditors,{args:[0,-r],checker:t}],[[`ctrl+ArrowUp`,`mac+shift+ArrowUp`],e.translateSelectedEditors,{args:[0,-i],checker:t}],[[`ArrowDown`,`mac+ArrowDown`],e.translateSelectedEditors,{args:[0,r],checker:t}],[[`ctrl+ArrowDown`,`mac+shift+ArrowDown`],e.translateSelectedEditors,{args:[0,i],checker:t}]]))}constructor(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){let g=this._signal=this.#e.signal;this.#K=e;this.#q=t;this.#J=n;this.#o=r;this.#u=i;this.#z=a;this.#H=s;this._eventBus=o;o._on(`editingaction`,this.onEditingAction.bind(this),{signal:g});o._on(`pagechanging`,this.onPageChanging.bind(this),{signal:g});o._on(`scalechanging`,this.onScaleChanging.bind(this),{signal:g});o._on(`rotationchanging`,this.onRotationChanging.bind(this),{signal:g});o._on(`setpreference`,this.onSetPreference.bind(this),{signal:g});o._on(`switchannotationeditorparams`,e=>this.updateParams(e.type,e.value),{signal:g});window.addEventListener(`pointerdown`,()=>{this.#k=!0},{capture:!0,signal:g});window.addEventListener(`pointerup`,()=>{this.#k=!1},{capture:!0,signal:g});window.addEventListener(`beforeunload`,this.#Q.bind(this),{capture:!0,signal:g});this.#ne();this.#le();this.#ae();this.#s=s.annotationStorage;this.#x=s.filterFactory;this.#B=c;this.#w=l||null;this.#v=u;this.#y=d;this.#b=f;this.#F=p||null;this.viewParameters={realScale:pe.PDF_TO_CSS_UNITS,rotation:0};this.isShiftKeyDown=!1;this._editorUndoBar=m||null;this._supportsPinchToZoom=!1!==h;i?.setSidebarUiManager(this)}destroy(){this.#Y?.resolve();this.#Y=null;this.#e?.abort();this.#e=null;this._signal=null;for(let e of this.#i.values())e.destroy();this.#i.clear();this.#r.clear();this.#_.clear();this.#P?.clear();this.#t=null;this.#L.clear();this.#l.destroy();this.#o?.destroy();this.#u?.destroy();this.#z?.destroy();this.#E?.hide();this.#E=null;this.#N?.destroy();this.#N=null;this.#n=null;if(this.#S){clearTimeout(this.#S);this.#S=null}if(this.#G){clearTimeout(this.#G);this.#G=null}this._editorUndoBar?.destroy();this.#H=null}combinedSignal(e){return AbortSignal.any([this._signal,e.signal])}get mlManager(){return this.#F}get useNewAltTextFlow(){return this.#y}get useNewAltTextWhenAddingImage(){return this.#b}get hcmFilter(){return j(this,`hcmFilter`,this.#B?this.#x.addHCMFilter(this.#B.foreground,this.#B.background):`none`)}get direction(){return j(this,`direction`,getComputedStyle(this.#K).direction)}get _highlightColors(){return j(this,`_highlightColors`,this.#w?new Map(this.#w.split(`,`).map(e=>{(e=e.split(`=`).map(e=>e.trim()))[1]=e[1].toUpperCase();return e})):null)}get highlightColors(){let{_highlightColors:e}=this;if(!e)return j(this,`highlightColors`,null);let t=new Map,n=!!this.#B;for(let[r,i]of e){let e=r.endsWith(`_HCM`);n&&e?t.set(r.replace(`_HCM`,``),i):n||e||t.set(r,i)}return j(this,`highlightColors`,t)}get highlightColorNames(){return j(this,`highlightColorNames`,this.highlightColors?new Map(Array.from(this.highlightColors,e=>e.reverse())):null)}getNonHCMColor(e){if(!this._highlightColors)return e;let t=this.highlightColorNames.get(e);return this._highlightColors.get(t)||e}getNonHCMColorName(e){return this.highlightColorNames.get(e)||e}setCurrentDrawingSession(e){if(e){this.unselectAll();this.disableUserSelect(!0)}else this.disableUserSelect(!1);this.#f=e}setMainHighlightColorPicker(e){this.#N=e}editAltText(e,t=!1){this.#o?.editAltText(this,e,t)}hasCommentManager(){return!!this.#u}editComment(e,t,n,r){this.#u?.showDialog(this,e,t,n,r)}selectComment(e,t){(this.#i.get(e)?.getEditorByUID(t))?.toggleComment(!0,!0)}updateComment(e){this.#u?.updateComment(e.getData())}updatePopupColor(e){this.#u?.updatePopupColor(e)}removeComment(e){this.#u?.removeComments([e.uid])}deleteComment(e,t){let n=()=>{e.comment=t};this.addCommands({cmd:()=>{this._editorUndoBar?.show(n,`comment`);this.toggleComment(null);e.comment=null},undo:n,mustExec:!0})}toggleComment(e,t,n=void 0){this.#u?.toggleCommentPopup(e,t,n)}makeCommentColor(e,t){return e&&this.#u?.makeCommentColor(e,t)||null}getCommentDialogElement(){return this.#u?.dialogElement||null}async waitForEditorsRendered(e){if(this.#i.has(e-1))return;let{resolve:t,promise:n}=Promise.withResolvers(),r=n=>{if(n.pageNumber===e){this._eventBus._off(`editorsrendered`,r);t()}};this._eventBus.on(`editorsrendered`,r);await n}getSignature(e){this.#z?.getSignature({uiManager:this,editor:e})}get signatureManager(){return this.#z}switchToMode(e,t){this._eventBus.on(`annotationeditormodechanged`,t,{once:!0,signal:this._signal});this._eventBus.dispatch(`showannotationeditorui`,{source:this,mode:e})}setPreference(e,t){this._eventBus.dispatch(`setpreference`,{source:this,name:e,value:t})}onSetPreference({name:e,value:t}){e===`enableNewAltTextWhenAddingImage`&&(this.#b=t)}onPageChanging({pageNumber:e}){this.#p=e-1}deletePage(e){for(let t of this.getEditors(e))t.remove();this.#i.delete(e);this.#p===e&&(this.#p=0)}focusMainContainer(){this.#K.focus()}findParent(e,t){for(let n of this.#i.values()){let{x:r,y:i,width:a,height:o}=n.div.getBoundingClientRect();if(e>=r&&e<=r+a&&t>=i&&t<=i+o)return n}return null}disableUserSelect(e=!1){this.#q.classList.toggle(`noUserSelect`,e)}addShouldRescale(e){this.#_.add(e)}removeShouldRescale(e){this.#_.delete(e)}onScaleChanging({scale:e}){this.commitOrRemove();this.viewParameters.realScale=e*pe.PDF_TO_CSS_UNITS;for(let e of this.#_)e.onScaleChanging();this.#f?.onScaleChanging()}onRotationChanging({pagesRotation:e}){this.commitOrRemove();this.viewParameters.rotation=e}#X({anchorNode:e}){return e.nodeType===Node.TEXT_NODE?e.parentElement:e}#Z(e){let{currentLayer:t}=this;if(t.hasTextLayer(e))return t;for(let t of this.#i.values())if(t.hasTextLayer(e))return t;return null}highlightSelection(e=``,t=!1){let n=document.getSelection();if(!n||n.isCollapsed)return;let{anchorNode:r,anchorOffset:i,focusNode:a,focusOffset:o}=n,s=n.toString(),c=this.#X(n).closest(`.textLayer`),l=this.getSelectionBoxes(c);if(!l)return;n.empty();let u=this.#Z(c),d=this.#I===_.NONE,f=()=>{let n=u?.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:e,boxes:l,anchorNode:r,anchorOffset:i,focusNode:a,focusOffset:o,text:s});d&&this.showAllEditors(`highlight`,!0,!0);t&&n?.editComment()};d?this.switchToMode(_.HIGHLIGHT,f):f()}commentSelection(e=``){this.highlightSelection(e,!0)}#Q(e){this.commitOrRemove();this.currentLayer?.endDrawingSession(!1)}#$(){let e=document.getSelection();if(!e||e.isCollapsed)return;let t=this.#X(e).closest(`.textLayer`),n=this.getSelectionBoxes(t);if(n){this.#E||=new je(this);this.#E.show(t,n,this.direction===`ltr`)}}getAndRemoveDataFromAnnotationStorage(e){if(!this.#s)return null;let t=`${g}${e}`,n=this.#s.getRawValue(t);n&&this.#s.remove(t);return n}addToAnnotationStorage(e){e.isEmpty()||!this.#s||this.#s.has(e.id)||this.#s.setValue(e.id,e)}a11yAlert(e,t=null){let n=this.#J;if(n){n.setAttribute(`data-l10n-id`,e);t?n.setAttribute(`data-l10n-args`,JSON.stringify(t)):n.removeAttribute(`data-l10n-args`)}}#ee(){let e=document.getSelection();if(!e||e.isCollapsed){if(this.#R){this.#E?.hide();this.#R=null;this.#ue({hasSelectedText:!1})}return}let{anchorNode:t}=e;if(t===this.#R)return;let n=this.#X(e).closest(`.textLayer`);if(n){this.#E?.hide();this.#R=t;this.#ue({hasSelectedText:!0});if(this.#I===_.HIGHLIGHT||this.#I===_.NONE){this.#I===_.HIGHLIGHT&&this.showAllEditors(`highlight`,!0,!0);this.#T=this.isShiftKeyDown;if(!this.isShiftKeyDown){let e=this.#I===_.HIGHLIGHT?this.#Z(n):null;e?.toggleDrawing();if(this.#k){let t=new AbortController,n=this.combinedSignal(t),r=n=>{if(n.type!==`pointerup`||n.button===0){t.abort();e?.toggleDrawing(!0);n.type===`pointerup`&&this.#te(`main_toolbar`)}};window.addEventListener(`pointerup`,r,{signal:n});window.addEventListener(`blur`,r,{signal:n})}else{e?.toggleDrawing(!0);this.#te(`main_toolbar`)}}}}else if(this.#R){this.#E?.hide();this.#R=null;this.#ue({hasSelectedText:!1})}}#te(e=``){this.#I===_.HIGHLIGHT?this.highlightSelection(e):this.#v&&this.#$()}#ne(){document.addEventListener(`selectionchange`,this.#ee.bind(this),{signal:this._signal})}#re(){if(this.#C)return;this.#C=new AbortController;let e=this.combinedSignal(this.#C);window.addEventListener(`focus`,this.focus.bind(this),{signal:e});window.addEventListener(`blur`,this.blur.bind(this),{signal:e})}#ie(){this.#C?.abort();this.#C=null}blur(){this.isShiftKeyDown=!1;if(this.#T){this.#T=!1;this.#te(`main_toolbar`)}if(!this.hasSelection)return;let{activeElement:e}=document;for(let t of this.#L)if(t.div.contains(e)){this.#M=[t,e];t._focusEventsAllowed=!1;break}}focus(){if(!this.#M)return;let[e,t]=this.#M;this.#M=null;t.addEventListener(`focusin`,()=>{e._focusEventsAllowed=!0},{once:!0,signal:this._signal});t.focus()}#ae(){if(this.#j)return;this.#j=new AbortController;let e=this.combinedSignal(this.#j);window.addEventListener(`keydown`,this.keydown.bind(this),{signal:e});window.addEventListener(`keyup`,this.keyup.bind(this),{signal:e})}#oe(){this.#j?.abort();this.#j=null}#se(){if(this.#d)return;this.#d=new AbortController;let e=this.combinedSignal(this.#d);document.addEventListener(`copy`,this.copy.bind(this),{signal:e});document.addEventListener(`cut`,this.cut.bind(this),{signal:e});document.addEventListener(`paste`,this.paste.bind(this),{signal:e})}#ce(){this.#d?.abort();this.#d=null}#le(){let e=this._signal;document.addEventListener(`dragover`,this.dragOver.bind(this),{signal:e});document.addEventListener(`drop`,this.drop.bind(this),{signal:e})}addEditListeners(){this.#ae();this.setEditingState(!0)}removeEditListeners(){this.#oe();this.setEditingState(!1)}dragOver(e){for(let{type:t}of e.dataTransfer.items)for(let n of this.#g)if(n.isHandlingMimeForPasting(t)){e.dataTransfer.dropEffect=`copy`;e.preventDefault();return}}drop(e){for(let t of e.dataTransfer.items)for(let n of this.#g)if(n.isHandlingMimeForPasting(t.type)){n.paste(t,this.currentLayer);e.preventDefault();return}}copy(e){e.preventDefault();this.#t?.commitOrRemove();if(!this.hasSelection)return;let t=[];for(let e of this.#L){let n=e.serialize(!0);n&&t.push(n)}t.length!==0&&e.clipboardData.setData(`application/pdfjs`,JSON.stringify(t))}cut(e){this.copy(e);this.delete()}async paste(e){e.preventDefault();let{clipboardData:t}=e;for(let e of t.items)for(let t of this.#g)if(t.isHandlingMimeForPasting(e.type)){t.paste(e,this.currentLayer);return}let n=t.getData(`application/pdfjs`);if(!n)return;try{n=JSON.parse(n)}catch(e){E(`paste: "${e.message}".`);return}if(!Array.isArray(n))return;this.unselectAll();let r=this.currentLayer;try{let e=[];for(let t of n){let n=await r.deserialize(t);if(!n)return;e.push(n)}this.addCommands({cmd:()=>{for(let t of e)this.#me(t);this.#_e(e)},undo:()=>{for(let t of e)t.remove()},mustExec:!0})}catch(e){E(`paste: "${e.message}".`)}}keydown(e){this.isShiftKeyDown||e.key!==`Shift`||(this.isShiftKeyDown=!0);this.#I===_.NONE||this.isEditorHandlingKeyboard||Re._keyboardManager.exec(this,e)}keyup(e){if(this.isShiftKeyDown&&e.key===`Shift`){this.isShiftKeyDown=!1;if(this.#T){this.#T=!1;this.#te(`main_toolbar`)}}}onEditingAction({name:e}){switch(e){case`undo`:case`redo`:case`delete`:case`selectAll`:this[e]();break;case`highlightSelection`:this.highlightSelection(`context_menu`);break;case`commentSelection`:this.commentSelection(`context_menu`)}}updatePageIndex(e,t){for(let n of this.getEditors(e))n.pageIndex=t;let n=this.#a.get(e);if(n){n.pageIndex=t;this.#i.set(t,n);this.#O?n.enable():n.disable()}}startUpdatePages(){this.#a=new Map(this.#i);this.#i.clear()}endUpdatePages(){this.#a=null}clonePage(e,t){for(let n of this.getEditors(e)){let e=n.serialize(n.mode!==_.HIGHLIGHT);if(e){e.pageIndex=t;e.id=this.getId();e.isClone=!0;delete e.popupRef;this.#s.setValue(e.id,e)}}}findClonesForPage(e){let t=[],{pageIndex:n}=e;for(let[r,i]of this.#s)if(i.pageIndex===n&&i.isClone){this.#s.remove(r);t.push(e.deserialize(i).then(t=>{if(t){t.isClone=!0;e.addOrRebuild(t)}}))}return Promise.all(t)}#ue(e){if(Object.entries(e).some(([e,t])=>this.#U[e]!==t)){this._eventBus.dispatch(`editingstateschanged`,{source:this,details:Object.assign(this.#U,e)});this.#I===_.HIGHLIGHT&&!1===e.hasSelectedEditor&&this.#de([[v.HIGHLIGHT_FREE,!0]])}}#de(e){this._eventBus.dispatch(`annotationeditorparamschanged`,{source:this,details:e})}setEditingState(e){if(e){this.#re();this.#se();this.#ue({isEditing:this.#I!==_.NONE,isEmpty:this.#ge(),hasSomethingToUndo:this.#l.hasSomethingToUndo(),hasSomethingToRedo:this.#l.hasSomethingToRedo(),hasSelectedEditor:!1})}else{this.#ie();this.#ce();this.#ue({isEditing:!1});this.disableUserSelect(!1)}}registerEditorTypes(e){if(!this.#g){this.#g=e;for(let e of this.#g)this.#de(e.defaultPropertiesToUpdate)}}getId(){return this.#D.id}get currentLayer(){return this.#i.get(this.#p)}getLayer(e){return this.#i.get(e)}get currentPageIndex(){return this.#p}addLayer(e){this.#i.set(e.pageIndex,e);this.#O?e.enable():e.disable()}removeLayer(e){this.#i.delete(e.pageIndex)}async updateMode(e,t=null,n=!1,r=!1,i=!1,a=!1){if(this.#I!==e){if(this.#Y){await this.#Y.promise;if(!this.#Y)return}this.#Y=Promise.withResolvers();this.#f?.commitOrRemove();this.#I===_.POPUP&&this.#u?.hideSidebar();this.#u?.destroyPopup();this.#I=e;if(e!==_.NONE){for(let e of this.#r.values())e.addStandaloneCommentButton();e===_.SIGNATURE&&await this.#z?.loadSignatures();n&&V.clearPointerType();this.setEditingState(!0);await this.#fe();this.unselectAll();for(let t of this.#i.values())t.updateMode(e);if(e===_.POPUP){this.#n||=await this.#H.getAnnotationsByType(new Set(this.#g.map(e=>e._editorType)));let e=new Set,t=[];for(let n of this.#r.values()){let{annotationElementId:r,hasComment:i,deleted:a}=n;r&&e.add(r);i&&!a&&t.push(n.getData())}for(let n of this.#n){let{id:r,popupRef:i,contentsObj:a}=n;i&&a?.str&&!e.has(r)&&!this.#m.has(r)&&t.push(n)}this.#u?.showSidebar(t)}if(t){for(let e of this.#r.values())if(e.uid===t){this.setSelected(e);a?e.editComment():i?e.enterInEditMode():e.focus()}else e.unselect();this.#Y.resolve()}else{r&&this.addNewEditorFromKeyboard();this.#Y.resolve()}}else{this.setEditingState(!1);this.#pe();for(let e of this.#r.values())e.hideStandaloneCommentButton();this._editorUndoBar?.hide();this.toggleComment(null);this.#Y.resolve()}}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(e){e.mode!==this.#I&&this._eventBus.dispatch(`switchannotationeditormode`,{source:this,...e})}updateParams(e,t){if(this.#g){switch(e){case v.CREATE:this.currentLayer.addNewEditor(t);return;case v.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch(`reporttelemetry`,{source:this,details:{type:`editing`,data:{type:`highlight`,action:`toggle_visibility`}}});(this.#V||=new Map).set(e,t);this.showAllEditors(`highlight`,t)}if(this.hasSelection)for(let n of this.#L)n.updateParams(e,t);else for(let n of this.#g)n.updateDefaultParams(e,t)}}showAllEditors(e,t,n=!1){for(let n of this.#r.values())n.editorType===e&&n.show(t);(this.#V?.get(v.HIGHLIGHT_SHOW_ALL)??!0)!==t&&this.#de([[v.HIGHLIGHT_SHOW_ALL,t]])}enableWaiting(e=!1){if(this.#A!==e){this.#A=e;for(let t of this.#i.values()){e?t.disableClick():t.enableClick();t.div.classList.toggle(`waiting`,e)}}}async#fe(){if(!this.#O){this.#O=!0;let e=[];for(let t of this.#i.values())e.push(t.enable());await Promise.all(e);for(let e of this.#r.values())e.enable()}}#pe(){this.unselectAll();if(this.#O){this.#O=!1;for(let e of this.#i.values())e.disable();for(let e of this.#r.values())e.disable()}}*getEditors(e){for(let t of this.#r.values())t.pageIndex===e&&(yield t)}getEditor(e){return this.#r.get(e)}addEditor(e){this.#r.set(e.id,e)}removeEditor(e){if(e.div.contains(document.activeElement)){this.#S&&clearTimeout(this.#S);this.#S=setTimeout(()=>{this.focusMainContainer();this.#S=null},0)}this.#r.delete(e.id);e.annotationElementId&&this.#P?.delete(e.annotationElementId);this.unselect(e);e.annotationElementId&&this.#m.has(e.annotationElementId)||this.#s?.remove(e.id)}addDeletedAnnotationElement(e){this.#m.add(e.annotationElementId);this.addChangedExistingAnnotation(e);e.deleted=!0}isDeletedAnnotationElement(e){return this.#m.has(e)}removeDeletedAnnotationElement(e){this.#m.delete(e.annotationElementId);this.removeChangedExistingAnnotation(e);e.deleted=!1}#me(e){let t=this.#i.get(e.pageIndex);if(t)t.addOrRebuild(e);else{this.addEditor(e);this.addToAnnotationStorage(e)}}setActiveEditor(e){if(this.#t!==e){this.#t=e;e&&this.#de(e.propertiesToUpdate)}}get#he(){let e=null;for(e of this.#L);return e}updateUI(e){this.#he===e&&this.#de(e.propertiesToUpdate)}updateUIForDefaultProperties(e){this.#de(e.defaultPropertiesToUpdate)}toggleSelected(e){if(this.#L.has(e)){this.#L.delete(e);e.unselect();this.#ue({hasSelectedEditor:this.hasSelection})}else{this.#L.add(e);e.select();this.#de(e.propertiesToUpdate);this.#ue({hasSelectedEditor:!0})}}setSelected(e){this.updateToolbar({mode:e.mode,editId:e.uid});this.#f?.commitOrRemove();for(let t of this.#L)t!==e&&t.unselect();this.#u?.destroyPopup();this.#L.clear();this.#L.add(e);e.select();this.#de(e.propertiesToUpdate);this.#ue({hasSelectedEditor:!0})}isSelected(e){return this.#L.has(e)}get firstSelectedEditor(){return this.#L.values().next().value}unselect(e){e.unselect();this.#L.delete(e);this.#ue({hasSelectedEditor:this.hasSelection})}get hasSelection(){return this.#L.size!==0}get isEnterHandled(){return this.#L.size===1&&this.firstSelectedEditor.isEnterHandled}undo(){this.#l.undo();this.#ue({hasSomethingToUndo:this.#l.hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:this.#ge()});this._editorUndoBar?.hide()}redo(){this.#l.redo();this.#ue({hasSomethingToUndo:!0,hasSomethingToRedo:this.#l.hasSomethingToRedo(),isEmpty:this.#ge()})}addCommands(e){this.#l.add(e);this.#ue({hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:this.#ge()})}cleanUndoStack(e){this.#l.cleanType(e)}#ge(){if(this.#r.size===0)return!0;if(this.#r.size===1)for(let e of this.#r.values())return e.isEmpty();return!1}delete(){this.commitOrRemove();let e=this.currentLayer?.endDrawingSession(!0);if(!this.hasSelection&&!e)return;let t=e?[e]:[...this.#L],n=()=>{for(let e of t)this.#me(e)};this.addCommands({cmd:()=>{this._editorUndoBar?.show(n,t.length===1?t[0].editorType:t.length);for(let e of t)e.remove()},undo:n,mustExec:!0})}commitOrRemove(){this.#t?.commitOrRemove()}hasSomethingToControl(){return this.#t||this.hasSelection}#_e(e){for(let e of this.#L)e.unselect();this.#L.clear();for(let t of e)if(!t.isEmpty()){this.#L.add(t);t.select()}this.#ue({hasSelectedEditor:this.hasSelection})}selectAll(){for(let e of this.#L)e.commit();this.#_e(this.#r.values())}unselectAll(){if(this.#t){this.#t.commitOrRemove();if(this.#I!==_.NONE)return}if(!this.#f?.commitOrRemove()){this.#u?.destroyPopup();if(this.hasSelection){for(let e of this.#L)e.unselect();this.#L.clear();this.#ue({hasSelectedEditor:!1})}}}translateSelectedEditors(e,t,n=!1){n||this.commitOrRemove();if(!this.hasSelection)return;this.#W[0]+=e;this.#W[1]+=t;let[r,i]=this.#W,a=[...this.#L];this.#G&&clearTimeout(this.#G);this.#G=setTimeout(()=>{this.#G=null;this.#W[0]=this.#W[1]=0;this.addCommands({cmd:()=>{for(let e of a)if(this.#r.has(e.id)){e.translateInPage(r,i);e.translationDone()}},undo:()=>{for(let e of a)if(this.#r.has(e.id)){e.translateInPage(-r,-i);e.translationDone()}},mustExec:!1})},1e3);for(let n of a){n.translateInPage(e,t);n.translationDone()}}setUpDragSession(){if(this.hasSelection){this.disableUserSelect(!0);this.#h=new Map;for(let e of this.#L)this.#h.set(e,{savedX:e.x,savedY:e.y,savedPageIndex:e.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!this.#h)return!1;this.disableUserSelect(!1);let e=this.#h;this.#h=null;let t=!1;for(let[{x:n,y:r,pageIndex:i},a]of e){a.newX=n;a.newY=r;a.newPageIndex=i;t||=n!==a.savedX||r!==a.savedY||i!==a.savedPageIndex}if(!t)return!1;let n=(e,t,n,r)=>{if(this.#r.has(e.id)){let i=this.#i.get(r);if(i)e._setParentAndPosition(i,t,n);else{e.pageIndex=r;e.x=t;e.y=n}}};this.addCommands({cmd:()=>{for(let[t,{newX:r,newY:i,newPageIndex:a}]of e)n(t,r,i,a)},undo:()=>{for(let[t,{savedX:r,savedY:i,savedPageIndex:a}]of e)n(t,r,i,a)},mustExec:!0});return!0}dragSelectedEditors(e,t){if(this.#h)for(let n of this.#h.keys())n.drag(e,t)}rebuild(e){if(e.parent===null){let t=this.getLayer(e.pageIndex);if(t){t.changeParent(e);t.addOrRebuild(e)}else{this.addEditor(e);this.addToAnnotationStorage(e);e.rebuild()}}else e.parent.addOrRebuild(e)}get isEditorHandlingKeyboard(){return this.getActive()?.shouldGetKeyboardEvents()||this.#L.size===1&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(e){return this.#t===e}getActive(){return this.#t}getMode(){return this.#I}isEditingMode(){return this.#I!==_.NONE}get imageManager(){return j(this,`imageManager`,new Pe)}getSelectionBoxes(e){if(!e)return null;let t=document.getSelection();for(let n=0,r=t.rangeCount;n<r;n++)if(!e.contains(t.getRangeAt(n).commonAncestorContainer))return null;let{x:n,y:r,width:i,height:a}=e.getBoundingClientRect(),o;switch(e.getAttribute(`data-main-rotation`)){case`90`:o=(e,t,o,s)=>({x:(t-r)/a,y:1-(e+o-n)/i,width:s/a,height:o/i});break;case`180`:o=(e,t,o,s)=>({x:1-(e+o-n)/i,y:1-(t+s-r)/a,width:o/i,height:s/a});break;case`270`:o=(e,t,o,s)=>({x:1-(t+s-r)/a,y:(e-n)/i,width:s/a,height:o/i});break;default:o=(e,t,o,s)=>({x:(e-n)/i,y:(t-r)/a,width:o/i,height:s/a})}let s=[];for(let e=0,n=t.rangeCount;e<n;e++){let n=t.getRangeAt(e);if(!n.collapsed)for(let{x:e,y:t,width:r,height:i}of n.getClientRects())r!==0&&i!==0&&s.push(o(e,t,r,i))}return s.length===0?null:s}addChangedExistingAnnotation({annotationElementId:e,id:t}){(this.#c||=new Map).set(e,t)}removeChangedExistingAnnotation({annotationElementId:e}){this.#c?.delete(e)}renderAnnotationElement(e){let t=this.#c?.get(e.data.id);if(!t)return;let n=this.#s.getRawValue(t);n&&(this.#I!==_.NONE||n.hasBeenModified)&&n.renderAnnotationElement(e)}setMissingCanvas(e,t,n){let r=this.#P?.get(e);if(r){r.setCanvas(t,n);this.#P.delete(e)}}addMissingCanvas(e,t){(this.#P||=new Map).set(e,t)}}class ze{#e=null;#t=!1;#n=null;#r=null;#i=null;#a=null;#o=!1;#s=null;#c=null;#l=null;#u=null;#d=!1;static#f=null;static _l10n=null;constructor(e){this.#c=e;this.#d=e._uiManager.useNewAltTextFlow;ze.#f||=Object.freeze({added:`pdfjs-editor-new-alt-text-added-button`,"added-label":`pdfjs-editor-new-alt-text-added-button-label`,missing:`pdfjs-editor-new-alt-text-missing-button`,"missing-label":`pdfjs-editor-new-alt-text-missing-button-label`,review:`pdfjs-editor-new-alt-text-to-review-button`,"review-label":`pdfjs-editor-new-alt-text-to-review-button-label`})}static initialize(e){ze._l10n??=e}async render(){let e=this.#n=document.createElement(`button`);e.className=`altText`;e.tabIndex=`0`;let t=this.#r=document.createElement(`span`);e.append(t);if(this.#d){e.classList.add(`new`);e.setAttribute(`data-l10n-id`,ze.#f.missing);t.setAttribute(`data-l10n-id`,ze.#f[`missing-label`])}else{e.setAttribute(`data-l10n-id`,`pdfjs-editor-alt-text-button`);t.setAttribute(`data-l10n-id`,`pdfjs-editor-alt-text-button-label`)}let n=this.#c._uiManager._signal;e.addEventListener(`contextmenu`,L,{signal:n});e.addEventListener(`pointerdown`,e=>e.stopPropagation(),{signal:n});let r=e=>{e.preventDefault();this.#c._uiManager.editAltText(this.#c);this.#d&&this.#c._reportTelemetry({action:`pdfjs.image.alt_text.image_status_label_clicked`,data:{label:this.#p}})};e.addEventListener(`click`,r,{capture:!0,signal:n});e.addEventListener(`keydown`,t=>{if(t.target===e&&t.key===`Enter`){this.#o=!0;r(t)}},{signal:n});await this.#m();return e}get#p(){return(this.#e?`added`:this.#e===null&&this.guessedText&&`review`)||`missing`}finish(){if(this.#n){this.#n.focus({focusVisible:this.#o});this.#o=!1}}isEmpty(){return this.#d?this.#e===null:!this.#e&&!this.#t}hasData(){return this.#d?this.#e!==null||!!this.#l:this.isEmpty()}get guessedText(){return this.#l}async setGuessedText(e){if(this.#e===null){this.#l=e;this.#u=await ze._l10n.get(`pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer`,{generatedAltText:e});this.#m()}}toggleAltTextBadge(e=!1){if(this.#d&&!this.#e){if(!this.#s){let e=this.#s=document.createElement(`div`);e.className=`noAltTextBadge`;this.#c.div.append(e)}this.#s.classList.toggle(`hidden`,!e)}else{this.#s?.remove();this.#s=null}}serialize(e){let t=this.#e;e||this.#l!==t||(t=this.#u);return{altText:t,decorative:this.#t,guessedText:this.#l,textWithDisclaimer:this.#u}}get data(){return{altText:this.#e,decorative:this.#t}}set data({altText:e,decorative:t,guessedText:n,textWithDisclaimer:r,cancel:i=!1}){if(n){this.#l=n;this.#u=r}if(this.#e!==e||this.#t!==t){if(!i){this.#e=e;this.#t=t}this.#m()}}toggle(e=!1){if(this.#n){if(!e&&this.#a){clearTimeout(this.#a);this.#a=null}this.#n.disabled=!e}}shown(){this.#c._reportTelemetry({action:`pdfjs.image.alt_text.image_status_label_displayed`,data:{label:this.#p}})}destroy(){this.#n?.remove();this.#n=null;this.#r=null;this.#i=null;this.#s?.remove();this.#s=null}async#m(){let e=this.#n;if(!e)return;if(this.#d){e.classList.toggle(`done`,!!this.#e);e.setAttribute(`data-l10n-id`,ze.#f[this.#p]);this.#r?.setAttribute(`data-l10n-id`,ze.#f[`${this.#p}-label`]);if(!this.#e){this.#i?.remove();return}}else{if(!this.#e&&!this.#t){e.classList.remove(`done`);this.#i?.remove();return}e.classList.add(`done`);e.setAttribute(`data-l10n-id`,`pdfjs-editor-alt-text-edit-button`)}let t=this.#i;if(!t){this.#i=t=document.createElement(`span`);t.className=`tooltip`;t.setAttribute(`role`,`tooltip`);t.id=`alt-text-tooltip-${this.#c.id}`;let n=this.#c._uiManager._signal;n.addEventListener(`abort`,()=>{clearTimeout(this.#a);this.#a=null},{once:!0});e.addEventListener(`mouseenter`,()=>{this.#a=setTimeout(()=>{this.#a=null;this.#i.classList.add(`show`);this.#c._reportTelemetry({action:`alt_text_tooltip`})},100)},{signal:n});e.addEventListener(`mouseleave`,()=>{if(this.#a){clearTimeout(this.#a);this.#a=null}this.#i?.classList.remove(`show`)},{signal:n})}if(this.#t)t.setAttribute(`data-l10n-id`,`pdfjs-editor-alt-text-decorative-tooltip`);else{t.removeAttribute(`data-l10n-id`);t.textContent=this.#e}t.parentNode||e.append(t);this.#c.getElementForAltText()?.setAttribute(`aria-describedby`,t.id)}}class Be{#e=null;#t=null;#n=!1;#r=null;#i=null;#a=null;#o=null;#s=null;#c=!1;#l=null;constructor(e){this.#r=e}renderForToolbar(){let e=this.#t=document.createElement(`button`);e.className=`comment`;return this.#u(e,!1)}renderForStandalone(){let e=this.#e=document.createElement(`button`);e.className=`annotationCommentButton`;let t=this.#r.commentButtonPosition;if(t){let{style:n}=e;n.insetInlineEnd=`calc(${100*(this.#r._uiManager.direction===`ltr`?1-t[0]:t[0])}% - var(--comment-button-dim))`;n.top=`calc(${100*t[1]}% - var(--comment-button-dim))`;let r=this.#r.commentButtonColor;r&&(n.backgroundColor=r)}return this.#u(e,!0)}focusButton(){setTimeout(()=>{(this.#e??this.#t)?.focus()},0)}onUpdatedColor(){if(!this.#e)return;let e=this.#r.commentButtonColor;e&&(this.#e.style.backgroundColor=e);this.#r._uiManager.updatePopupColor(this.#r)}get commentButtonWidth(){return(this.#e?.getBoundingClientRect().width??0)/this.#r.parent.boundingClientRect.width}get commentPopupPositionInLayer(){if(this.#l)return this.#l;if(!this.#e)return null;let{x:e,y:t,height:n}=this.#e.getBoundingClientRect(),{x:r,y:i,width:a,height:o}=this.#r.parent.boundingClientRect;return[(e-r)/a,(t+n-i)/o]}set commentPopupPositionInLayer(e){this.#l=e}hasDefaultPopupPosition(){return this.#l===null}removeStandaloneCommentButton(){this.#e?.remove();this.#e=null}removeToolbarCommentButton(){this.#t?.remove();this.#t=null}setCommentButtonStates({selected:e,hasPopup:t}){if(this.#e){this.#e.classList.toggle(`selected`,e);this.#e.ariaExpanded=t}}#u(e,t){if(!this.#r._uiManager.hasCommentManager())return null;e.tabIndex=`0`;e.ariaHasPopup=`dialog`;if(t){e.ariaControls=`commentPopup`;e.setAttribute(`data-l10n-id`,`pdfjs-show-comment-button`)}else{e.ariaControlsElements=[this.#r._uiManager.getCommentDialogElement()];e.setAttribute(`data-l10n-id`,`pdfjs-editor-add-comment-button`)}let n=this.#r._uiManager._signal;if(!(n instanceof AbortSignal)||n.aborted)return e;e.addEventListener(`contextmenu`,L,{signal:n});if(t){e.addEventListener(`focusin`,e=>{this.#r._focusEventsAllowed=!1;R(e)},{capture:!0,signal:n});e.addEventListener(`focusout`,e=>{this.#r._focusEventsAllowed=!0;R(e)},{capture:!0,signal:n})}e.addEventListener(`pointerdown`,e=>e.stopPropagation(),{signal:n});let r=t=>{t.preventDefault();e===this.#t?this.edit():this.#r.toggleComment(!0)};e.addEventListener(`click`,r,{capture:!0,signal:n});e.addEventListener(`keydown`,t=>{if(t.target===e&&t.key===`Enter`){this.#n=!0;r(t)}},{signal:n});e.addEventListener(`pointerenter`,()=>{this.#r.toggleComment(!1,!0)},{signal:n});e.addEventListener(`pointerleave`,()=>{this.#r.toggleComment(!1,!1)},{signal:n});return e}edit(e){let t=this.commentPopupPositionInLayer,n,r;if(t)[n,r]=t;else{[n,r]=this.#r.commentButtonPosition;let{width:e,height:t,x:i,y:a}=this.#r;n=i+n*e;r=a+r*t}let i=this.#r.parent.boundingClientRect,{x:a,y:o,width:s,height:c}=i;this.#r._uiManager.editComment(this.#r,a+n*s,o+r*c,{...e,parentDimensions:i})}finish(){if(this.#t){this.#t.focus({focusVisible:this.#n});this.#n=!1}}isDeleted(){return this.#c||this.#o===``}isEmpty(){return this.#o===null}hasBeenEdited(){return this.isDeleted()||this.#o!==this.#i}serialize(){return this.data}get data(){return{text:this.#o,richText:this.#a,date:this.#s,deleted:this.isDeleted()}}set data(e){e!==this.#o&&(this.#a=null);if(e!==null){this.#o=e;this.#s=new Date;this.#c=!1}else{this.#o=``;this.#c=!0}}restoreData({text:e,richText:t,date:n}){this.#o=e;this.#a=t;this.#s=n;this.#c=!1}setInitialText(e,t=null){this.#i=e;this.data=e;this.#s=null;this.#a=t}shown(){}destroy(){this.#t?.remove();this.#t=null;this.#e?.remove();this.#e=null;this.#o=``;this.#a=null;this.#s=null;this.#r=null;this.#n=!1;this.#c=!1}}class Ve{#e;#t=!1;#n=null;#r;#i;#a;#o;#s=null;#c;#l=null;#u;#d=null;constructor({container:e,isPinchingDisabled:t=null,isPinchingStopped:n=null,onPinchStart:r=null,onPinching:i=null,onPinchEnd:a=null,signal:o}){this.#e=e;this.#n=n;this.#r=t;this.#i=r;this.#a=i;this.#o=a;this.#u=new AbortController;this.#c=AbortSignal.any([o,this.#u.signal]);e.addEventListener(`touchstart`,this.#f.bind(this),{passive:!1,signal:this.#c})}get MIN_TOUCH_DISTANCE_TO_PINCH(){return 35/Te.pixelRatio}#f(e){if(this.#r?.())return;if(e.touches.length===1){if(this.#s)return;let e=this.#s=new AbortController,t=AbortSignal.any([this.#c,e.signal]),n=this.#e,r={capture:!0,signal:t,passive:!1},i=e=>{if(e.pointerType===`touch`){this.#s?.abort();this.#s=null}};n.addEventListener(`pointerdown`,e=>{if(e.pointerType===`touch`){R(e);i(e)}},r);n.addEventListener(`pointerup`,i,r);n.addEventListener(`pointercancel`,i,r);return}if(!this.#d){this.#d=new AbortController;let e=AbortSignal.any([this.#c,this.#d.signal]),t=this.#e,n={signal:e,capture:!1,passive:!1};t.addEventListener(`touchmove`,this.#p.bind(this),n);let r=this.#m.bind(this);t.addEventListener(`touchend`,r,n);t.addEventListener(`touchcancel`,r,n);n.capture=!0;t.addEventListener(`pointerdown`,R,n);t.addEventListener(`pointermove`,R,n);t.addEventListener(`pointercancel`,R,n);t.addEventListener(`pointerup`,R,n);this.#i?.()}R(e);if(e.touches.length!==2||this.#n?.()){this.#l=null;return}let[t,n]=e.touches;t.identifier>n.identifier&&([t,n]=[n,t]);this.#l={touch0X:t.screenX,touch0Y:t.screenY,touch1X:n.screenX,touch1Y:n.screenY}}#p(e){if(!this.#l||e.touches.length!==2)return;R(e);let[t,n]=e.touches;t.identifier>n.identifier&&([t,n]=[n,t]);let{screenX:r,screenY:i}=t,{screenX:a,screenY:o}=n,s=this.#l,{touch0X:c,touch0Y:l,touch1X:u,touch1Y:d}=s,f=u-c,p=d-l,m=a-r,h=o-i,g=Math.hypot(m,h)||1,_=Math.hypot(f,p)||1;if(!this.#t&&Math.abs(_-g)<=Ve.MIN_TOUCH_DISTANCE_TO_PINCH)return;s.touch0X=r;s.touch0Y=i;s.touch1X=a;s.touch1Y=o;if(!this.#t){this.#t=!0;return}let v=[(r+a)/2,(i+o)/2];this.#a?.(v,_,g)}#m(e){if(!(e.touches.length>=2)){if(this.#d){this.#d.abort();this.#d=null;this.#o?.()}if(this.#l){R(e);this.#l=null;this.#t=!1}}}destroy(){this.#u?.abort();this.#u=null;this.#s?.abort();this.#s=null}}class H{#e=null;#t=null;#n=null;#r=null;#i=null;#a=!1;#o=null;#s=``;#c=null;#l=null;#u=null;#d=null;#f=null;#p=``;#m=!1;#h=null;#g=!1;#_=!1;#v=!1;#y=null;#b=0;#x=0;#S=null;#C=null;isSelected=!1;_isCopy=!1;_editToolbar=null;_initialOptions=Object.create(null);_initialData=null;_isVisible=!0;_uiManager=null;_focusEventsAllowed=!0;static _l10n=null;static _l10nAlert=null;static _l10nResizer=null;#w=!1;#T=H._zIndex++;static _borderLineWidth=-1;static _colorManager=new Le;static _zIndex=1;static _telemetryTimeout=1e3;static get _resizerKeyboardManager(){let e=H.prototype._resizeWithKeyboard,t=Re.TRANSLATE_SMALL,n=Re.TRANSLATE_BIG;return j(this,`_resizerKeyboardManager`,new Ie([[[`ArrowLeft`,`mac+ArrowLeft`],e,{args:[-t,0]}],[[`ctrl+ArrowLeft`,`mac+shift+ArrowLeft`],e,{args:[-n,0]}],[[`ArrowRight`,`mac+ArrowRight`],e,{args:[t,0]}],[[`ctrl+ArrowRight`,`mac+shift+ArrowRight`],e,{args:[n,0]}],[[`ArrowUp`,`mac+ArrowUp`],e,{args:[0,-t]}],[[`ctrl+ArrowUp`,`mac+shift+ArrowUp`],e,{args:[0,-n]}],[[`ArrowDown`,`mac+ArrowDown`],e,{args:[0,t]}],[[`ctrl+ArrowDown`,`mac+shift+ArrowDown`],e,{args:[0,n]}],[[`Escape`,`mac+Escape`],H.prototype._stopResizingWithKeyboard]]))}constructor(e){this.parent=e.parent;this.id=e.id;this.width=this.height=null;this.pageIndex=e.parent.pageIndex;this.name=e.name;this.div=null;this._uiManager=e.uiManager;this.annotationElementId=null;this._willKeepAspectRatio=!1;this._initialOptions.isCentered=e.isCentered;this._structTreeParentId=null;this.annotationElementId=e.annotationElementId||null;this.creationDate=e.creationDate||new Date;this.modificationDate=e.modificationDate||null;this.canAddComment=!0;let{rotation:t,rawDims:{pageWidth:n,pageHeight:r,pageX:i,pageY:a}}=this.parent.viewport;this.rotation=t;this.pageRotation=(360+t-this._uiManager.viewParameters.rotation)%360;this.pageDimensions=[n,r];this.pageTranslation=[i,a];let[o,s]=this.parentDimensions;this.x=e.x/o;this.y=e.y/s;this.isAttachedToDOM=!1;this.deleted=!1}updatePageIndex(e){this.pageIndex=e}get editorType(){return Object.getPrototypeOf(this).constructor._type}get mode(){return Object.getPrototypeOf(this).constructor._editorType}static get isDrawer(){return!1}static get _defaultLineColor(){return j(this,`_defaultLineColor`,this._colorManager.getHexCode(`CanvasText`))}static deleteAnnotationElement(e){let t=new He({id:e._uiManager.getId(),parent:e.parent,uiManager:e._uiManager});t.annotationElementId=e.annotationElementId;t.deleted=!0;t._uiManager.addToAnnotationStorage(t)}static initialize(e,t){H._l10n??=e;H._l10nAlert??=Object.freeze({highlight:`pdfjs-editor-highlight-added-alert`,freetext:`pdfjs-editor-freetext-added-alert`,ink:`pdfjs-editor-ink-added-alert`,stamp:`pdfjs-editor-stamp-added-alert`,signature:`pdfjs-editor-signature-added-alert`});H._l10nResizer??=Object.freeze({topLeft:`pdfjs-editor-resizer-top-left`,topMiddle:`pdfjs-editor-resizer-top-middle`,topRight:`pdfjs-editor-resizer-top-right`,middleRight:`pdfjs-editor-resizer-middle-right`,bottomRight:`pdfjs-editor-resizer-bottom-right`,bottomMiddle:`pdfjs-editor-resizer-bottom-middle`,bottomLeft:`pdfjs-editor-resizer-bottom-left`,middleLeft:`pdfjs-editor-resizer-middle-left`});if(H._borderLineWidth!==-1)return;let n=getComputedStyle(document.documentElement);H._borderLineWidth=parseFloat(n.getPropertyValue(`--outline-width`))||0}static updateDefaultParams(e,t){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(e){return!1}static paste(e,t){D(`Not implemented`)}get propertiesToUpdate(){return[]}get _isDraggable(){return this.#w}set _isDraggable(e){this.#w=e;this.div?.classList.toggle(`draggable`,e)}get uid(){return this.annotationElementId||this.id}get isEnterHandled(){return!0}center(){let[e,t]=this.pageDimensions;switch(this.parentRotation){case 90:this.x-=this.height*t/(2*e);this.y+=this.width*e/(2*t);break;case 180:this.x+=this.width/2;this.y+=this.height/2;break;case 270:this.x+=this.height*t/(2*e);this.y-=this.width*e/(2*t);break;default:this.x-=this.width/2;this.y-=this.height/2}this.fixAndSetPosition()}addCommands(e){this._uiManager.addCommands(e)}get currentLayer(){return this._uiManager.currentLayer}setInBackground(){this.div.style.zIndex=0}setInForeground(){this.div.style.zIndex=this.#T}setParent(e){if(e!==null){this.pageIndex=e.pageIndex;this.pageDimensions=e.pageDimensions}else{this.#W();this.#d?.remove();this.#d=null}this.parent=e}focusin(e){this._focusEventsAllowed&&(this.#m?this.#m=!1:this.parent.setSelected(this))}focusout(e){if(!this._focusEventsAllowed)return;if(!this.isAttachedToDOM)return;if(!e.relatedTarget?.closest(`#${this.id}`)){e.preventDefault();this.parent?.isMultipleSelection||this.commitOrRemove()}}commitOrRemove(){this.isEmpty()?this.remove():this.commit()}commit(){this.isInEditMode()&&this.addToAnnotationStorage()}addToAnnotationStorage(){this._uiManager.addToAnnotationStorage(this)}setAt(e,t,n,r){let[i,a]=this.parentDimensions;[n,r]=this.screenToPageTranslation(n,r);this.x=(e+n)/i;this.y=(t+r)/a;this.fixAndSetPosition()}_moveAfterPaste(e,t){if(this.isClone){delete this.isClone;return}let[n,r]=this.parentDimensions;this.setAt(e*n,t*r,this.width*n,this.height*r);this._onTranslated()}#E([e,t],n,r){[n,r]=this.screenToPageTranslation(n,r);this.x+=n/e;this.y+=r/t;this._onTranslating(this.x,this.y);this.fixAndSetPosition()}translate(e,t){this.#E(this.parentDimensions,e,t)}translateInPage(e,t){this.#h||=[this.x,this.y,this.width,this.height];this.#E(this.pageDimensions,e,t);this.div.scrollIntoView({block:`nearest`})}translationDone(){this._onTranslated(this.x,this.y)}drag(e,t){this.#h||=[this.x,this.y,this.width,this.height];let{div:n,parentDimensions:[r,i]}=this;this.x+=e/r;this.y+=t/i;if(this.parent&&(this.x<0||this.x>1||this.y<0||this.y>1)){let{x:e,y:t}=this.div.getBoundingClientRect();if(this.parent.findNewParent(this,e,t)){this.x-=Math.floor(this.x);this.y-=Math.floor(this.y)}}let{x:a,y:o}=this,[s,c]=this.getBaseTranslation();a+=s;o+=c;let{style:l}=n;l.left=`${(100*a).toFixed(2)}%`;l.top=`${(100*o).toFixed(2)}%`;this._onTranslating(a,o);n.scrollIntoView({block:`nearest`})}_onTranslating(e,t){}_onTranslated(e,t){}get _hasBeenMoved(){return!!this.#h&&(this.#h[0]!==this.x||this.#h[1]!==this.y)}get _hasBeenResized(){return!!this.#h&&(this.#h[2]!==this.width||this.#h[3]!==this.height)}getBaseTranslation(){let[e,t]=this.parentDimensions,{_borderLineWidth:n}=H,r=n/e,i=n/t;switch(this.rotation){case 90:return[-r,i];case 180:return[r,i];case 270:return[r,-i];default:return[-r,-i]}}get _mustFixPosition(){return!0}fixAndSetPosition(e=this.rotation){let{div:{style:t},pageDimensions:[n,r]}=this,{x:i,y:a,width:o,height:s}=this;o*=n;s*=r;i*=n;a*=r;if(this._mustFixPosition)switch(e){case 0:i=F(i,0,n-o);a=F(a,0,r-s);break;case 90:i=F(i,0,n-s);a=F(a,o,r);break;case 180:i=F(i,o,n);a=F(a,s,r);break;case 270:i=F(i,s,n);a=F(a,0,r-o)}this.x=i/=n;this.y=a/=r;let[c,l]=this.getBaseTranslation();i+=c;a+=l;t.left=`${(100*i).toFixed(2)}%`;t.top=`${(100*a).toFixed(2)}%`;this.moveInDOM()}static#D(e,t,n){switch(n){case 90:return[t,-e];case 180:return[-e,-t];case 270:return[-t,e];default:return[e,t]}}screenToPageTranslation(e,t){return H.#D(e,t,this.parentRotation)}pageTranslationToScreen(e,t){return H.#D(e,t,360-this.parentRotation)}#O(e){switch(e){case 90:{let[e,t]=this.pageDimensions;return[0,-e/t,t/e,0]}case 180:return[-1,0,0,-1];case 270:{let[e,t]=this.pageDimensions;return[0,e/t,-t/e,0]}default:return[1,0,0,1]}}get parentScale(){return this._uiManager.viewParameters.realScale}get parentRotation(){return(this._uiManager.viewParameters.rotation+this.pageRotation)%360}get parentDimensions(){let{parentScale:e,pageDimensions:[t,n]}=this;return[t*e,n*e]}setDims(){let{div:{style:e},width:t,height:n}=this;e.width=`${(100*t).toFixed(2)}%`;e.height=`${(100*n).toFixed(2)}%`}getInitialTranslation(){return[0,0]}#k(){if(this.#c)return;this.#c=document.createElement(`div`);this.#c.classList.add(`resizers`);let e=this._willKeepAspectRatio?[`topLeft`,`topRight`,`bottomRight`,`bottomLeft`]:[`topLeft`,`topMiddle`,`topRight`,`middleRight`,`bottomRight`,`bottomMiddle`,`bottomLeft`,`middleLeft`],t=this._uiManager._signal;for(let n of e){let e=document.createElement(`div`);this.#c.append(e);e.classList.add(`resizer`,n);e.setAttribute(`data-resizer-name`,n);e.addEventListener(`pointerdown`,this.#A.bind(this,n),{signal:t});e.addEventListener(`contextmenu`,L,{signal:t});e.tabIndex=-1}this.div.prepend(this.#c)}#A(e,t){t.preventDefault();let{isMac:n}=N.platform;if(t.button!==0||t.ctrlKey&&n)return;this.#n?.toggle(!1);let r=this._isDraggable;this._isDraggable=!1;this.#l=[t.screenX,t.screenY];let i=new AbortController,a=this._uiManager.combinedSignal(i);this.parent.togglePointerEvents(!1);window.addEventListener(`pointermove`,this.#N.bind(this,e),{passive:!0,capture:!0,signal:a});window.addEventListener(`touchmove`,R,{passive:!1,signal:a});window.addEventListener(`contextmenu`,L,{signal:a});this.#u={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};let o=this.parent.div.style.cursor,s=this.div.style.cursor;this.div.style.cursor=this.parent.div.style.cursor=window.getComputedStyle(t.target).cursor;let c=()=>{i.abort();this.parent.togglePointerEvents(!0);this.#n?.toggle(!0);this._isDraggable=r;this.parent.div.style.cursor=o;this.div.style.cursor=s;this.#M()};window.addEventListener(`pointerup`,c,{signal:a});window.addEventListener(`blur`,c,{signal:a})}#j(e,t,n,r){this.width=n;this.height=r;this.x=e;this.y=t;this.setDims();this.fixAndSetPosition();this._onResized()}_onResized(){}#M(){if(!this.#u)return;let{savedX:e,savedY:t,savedWidth:n,savedHeight:r}=this.#u;this.#u=null;let i=this.x,a=this.y,o=this.width,s=this.height;i===e&&a===t&&o===n&&s===r||this.addCommands({cmd:this.#j.bind(this,i,a,o,s),undo:this.#j.bind(this,e,t,n,r),mustExec:!0})}static _round(e){return Math.round(1e4*e)/1e4}#N(e,t){let[n,r]=this.parentDimensions,i=this.x,a=this.y,o=this.width,s=this.height,c=H.MIN_SIZE/n,l=H.MIN_SIZE/r,u=this.#O(this.rotation),d=(e,t)=>[u[0]*e+u[2]*t,u[1]*e+u[3]*t],f=this.#O(360-this.rotation),p,m,h=!1,g=!1;switch(e){case`topLeft`:h=!0;p=(e,t)=>[0,0];m=(e,t)=>[e,t];break;case`topMiddle`:p=(e,t)=>[e/2,0];m=(e,t)=>[e/2,t];break;case`topRight`:h=!0;p=(e,t)=>[e,0];m=(e,t)=>[0,t];break;case`middleRight`:g=!0;p=(e,t)=>[e,t/2];m=(e,t)=>[0,t/2];break;case`bottomRight`:h=!0;p=(e,t)=>[e,t];m=(e,t)=>[0,0];break;case`bottomMiddle`:p=(e,t)=>[e/2,t];m=(e,t)=>[e/2,0];break;case`bottomLeft`:h=!0;p=(e,t)=>[0,t];m=(e,t)=>[e,0];break;case`middleLeft`:g=!0;p=(e,t)=>[0,t/2];m=(e,t)=>[e,t/2]}let _=p(o,s),v=m(o,s),y=d(...v),b=H._round(i+y[0]),x=H._round(a+y[1]),S,C,w=1,T=1;if(t.fromKeyboard)({deltaX:S,deltaY:C}=t);else{let{screenX:e,screenY:n}=t,[r,i]=this.#l;[S,C]=this.screenToPageTranslation(e-r,n-i);this.#l[0]=e;this.#l[1]=n}[S,C]=(E=S/n,D=C/r,[f[0]*E+f[2]*D,f[1]*E+f[3]*D]);var E,D;if(h){let e=Math.hypot(o,s);w=T=Math.max(Math.min(Math.hypot(v[0]-_[0]-S,v[1]-_[1]-C)/e,1/o,1/s),c/o,l/s)}else g?w=F(Math.abs(v[0]-_[0]-S),c,1)/o:T=F(Math.abs(v[1]-_[1]-C),l,1)/s;let O=H._round(o*w),k=H._round(s*T);y=d(...m(O,k));let A=b-y[0],j=x-y[1];this.#h||=[this.x,this.y,this.width,this.height];this.width=O;this.height=k;this.x=A;this.y=j;this.setDims();this.fixAndSetPosition();this._onResizing()}_onResizing(){}altTextFinish(){this.#n?.finish()}get toolbarButtons(){return null}async addEditToolbar(){if(this._editToolbar||this.#_)return this._editToolbar;this._editToolbar=new Ae(this);this.div.append(this._editToolbar.render());let{toolbarButtons:e}=this;if(e)for(let[t,n]of e)await this._editToolbar.addButton(t,n);this.hasComment||this._editToolbar.addButton(`comment`,this.addCommentButton());this._editToolbar.addButton(`delete`);return this._editToolbar}addCommentButtonInToolbar(){this._editToolbar?.addButtonBefore(`comment`,this.addCommentButton(),`.deleteButton`)}removeCommentButtonFromToolbar(){this._editToolbar?.removeButton(`comment`)}removeEditToolbar(){this._editToolbar?.remove();this._editToolbar=null;this.#n?.destroy()}addContainer(e){let t=this._editToolbar?.div;t?t.before(e):this.div.append(e)}getClientDimensions(){return this.div.getBoundingClientRect()}createAltText(){if(!this.#n){ze.initialize(H._l10n);this.#n=new ze(this);if(this.#e){this.#n.data=this.#e;this.#e=null}}return this.#n}get altTextData(){return this.#n?.data}set altTextData(e){this.#n&&(this.#n.data=e)}get guessedAltText(){return this.#n?.guessedText}async setGuessedAltText(e){await this.#n?.setGuessedText(e)}serializeAltText(e){return this.#n?.serialize(e)}hasAltText(){return!!this.#n&&!this.#n.isEmpty()}hasAltTextData(){return this.#n?.hasData()??!1}focusCommentButton(){this.#r?.focusButton()}addCommentButton(){return this.canAddComment?this.#r||=new Be(this):null}addStandaloneCommentButton(){if(this._uiManager.hasCommentManager()){if(this.#i)this._uiManager.isEditingMode()&&this.#i.classList.remove(`hidden`);else if(this.hasComment){this.#i=this.#r.renderForStandalone();this.div.append(this.#i)}}}removeStandaloneCommentButton(){this.#r.removeStandaloneCommentButton();this.#i=null}hideStandaloneCommentButton(){this.#i?.classList.add(`hidden`)}get comment(){if(!this.#r)return null;let{data:{richText:e,text:t,date:n,deleted:r}}=this.#r;return{text:t,richText:e,date:n,deleted:r,color:this.getNonHCMColor(),opacity:this.opacity??1}}set comment(e){this.#r||=new Be(this);typeof e==`object`&&e?this.#r.restoreData(e):this.#r.data=e;if(this.hasComment){this.removeCommentButtonFromToolbar();this.addStandaloneCommentButton();this._uiManager.updateComment(this)}else{this.addCommentButtonInToolbar();this.removeStandaloneCommentButton();this._uiManager.removeComment(this)}}setCommentData({comment:e,popupRef:t,richText:n}){if(!t)return;this.#r||=new Be(this);this.#r.setInitialText(e,n);if(!this.annotationElementId)return;let r=this._uiManager.getAndRemoveDataFromAnnotationStorage(this.annotationElementId);r&&this.updateFromAnnotationLayer(r)}get hasEditedComment(){return this.#r?.hasBeenEdited()}get hasDeletedComment(){return this.#r?.isDeleted()}get hasComment(){return!!this.#r&&!this.#r.isEmpty()&&!this.#r.isDeleted()}async editComment(e){this.#r||=new Be(this);this.#r.edit(e)}toggleComment(e,t=void 0){this.hasComment&&this._uiManager.toggleComment(this,e,t)}setSelectedCommentButton(e){this.#r.setSelectedButton(e)}addComment(e){if(this.hasEditedComment){let[,,,t]=e.rect,[n]=this.pageDimensions,[r]=this.pageTranslation,i=r+n+1,a=t-100,o=i+180;e.popup={contents:this.comment.text,deleted:this.comment.deleted,rect:[i,a,o,t]}}}updateFromAnnotationLayer({popup:{contents:e,deleted:t}}){this.#r.data=t?null:e}get parentBoundingClientRect(){return this.parent.boundingClientRect}render(){let e=this.div=document.createElement(`div`);e.setAttribute(`data-editor-rotation`,(360-this.rotation)%360);e.className=this.name;e.setAttribute(`id`,this.id);e.tabIndex=this.#a?-1:0;e.setAttribute(`role`,`application`);this.defaultL10nId&&e.setAttribute(`data-l10n-id`,this.defaultL10nId);this._isVisible||e.classList.add(`hidden`);this.setInForeground();this.#z();let[t,n]=this.parentDimensions;if(this.parentRotation%180!=0){e.style.maxWidth=`${(100*n/t).toFixed(2)}%`;e.style.maxHeight=`${(100*t/n).toFixed(2)}%`}let[r,i]=this.getInitialTranslation();this.translate(r,i);Me(this,e,[`keydown`,`pointerdown`,`dblclick`]);this.isResizable&&this._uiManager._supportsPinchToZoom&&(this.#C||=new Ve({container:e,isPinchingDisabled:()=>!this.isSelected,onPinchStart:this.#P.bind(this),onPinching:this.#F.bind(this),onPinchEnd:this.#I.bind(this),signal:this._uiManager._signal}));this.addStandaloneCommentButton();this._uiManager._editorUndoBar?.hide();return e}#P(){this.#u={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};this.#n?.toggle(!1);this.parent.togglePointerEvents(!1)}#F(e,t,n){let r=n/t*.7+1-.7;if(r===1)return;let i=this.#O(this.rotation),a=(e,t)=>[i[0]*e+i[2]*t,i[1]*e+i[3]*t],[o,s]=this.parentDimensions,c=this.x,l=this.y,u=this.width,d=this.height,f=H.MIN_SIZE/o,p=H.MIN_SIZE/s;r=Math.max(Math.min(r,1/u,1/d),f/u,p/d);let m=H._round(u*r),h=H._round(d*r);if(m===u&&h===d)return;this.#h||=[c,l,u,d];let g=a(u/2,d/2),_=H._round(c+g[0]),v=H._round(l+g[1]),y=a(m/2,h/2);this.x=_-y[0];this.y=v-y[1];this.width=m;this.height=h;this.setDims();this.fixAndSetPosition();this._onResizing()}#I(){this.#n?.toggle(!0);this.parent.togglePointerEvents(!0);this.#M()}pointerdown(e){let{isMac:t}=N.platform;if(e.button!==0||e.ctrlKey&&t)e.preventDefault();else{this.#m=!0;this._isDraggable?this.#R(e):this.#L(e)}}#L(e){let{isMac:t}=N.platform;e.ctrlKey&&!t||e.shiftKey||e.metaKey&&t?this.parent.toggleSelected(this):this.parent.setSelected(this)}#R(e){let{isSelected:t}=this;this._uiManager.setUpDragSession();let n=!1,r=new AbortController,i=this._uiManager.combinedSignal(r),a={capture:!0,passive:!1,signal:i},o=e=>{r.abort();this.#o=null;this.#m=!1;this._uiManager.endDragSession()||this.#L(e);n&&this._onStopDragging()};if(t){this.#b=e.clientX;this.#x=e.clientY;this.#o=e.pointerId;this.#s=e.pointerType;window.addEventListener(`pointermove`,e=>{if(!n){n=!0;this._uiManager.toggleComment(this,!0,!1);this._onStartDragging()}let{clientX:t,clientY:r,pointerId:i}=e;if(i!==this.#o){R(e);return}let[a,o]=this.screenToPageTranslation(t-this.#b,r-this.#x);this.#b=t;this.#x=r;this._uiManager.dragSelectedEditors(a,o)},a);window.addEventListener(`touchmove`,R,a);window.addEventListener(`pointerdown`,e=>{e.pointerType===this.#s&&(this.#C||e.isPrimary)&&o(e);R(e)},a)}let s=e=>{this.#o&&this.#o!==e.pointerId?R(e):o(e)};window.addEventListener(`pointerup`,s,{signal:i});window.addEventListener(`blur`,s,{signal:i})}_onStartDragging(){}_onStopDragging(){}moveInDOM(){this.#y&&clearTimeout(this.#y);this.#y=setTimeout(()=>{this.#y=null;this.parent?.moveEditorInDOM(this)},0)}_setParentAndPosition(e,t,n){e.changeParent(this);this.x=t;this.y=n;this.fixAndSetPosition();this._onTranslated()}getRect(e,t,n=this.rotation){let r=this.parentScale,[i,a]=this.pageDimensions,[o,s]=this.pageTranslation,c=e/r,l=t/r,u=this.x*i,d=this.y*a,f=this.width*i,p=this.height*a;switch(n){case 0:return[u+c+o,a-d-l-p+s,u+c+f+o,a-d-l+s];case 90:return[u+l+o,a-d+c+s,u+l+p+o,a-d+c+f+s];case 180:return[u-c-f+o,a-d+l+s,u-c+o,a-d+l+p+s];case 270:return[u-l-p+o,a-d-c-f+s,u-l+o,a-d-c+s];default:throw Error(`Invalid rotation`)}}getRectInCurrentCoords(e,t){let[n,r,i,a]=e,o=i-n,s=a-r;switch(this.rotation){case 0:return[n,t-a,o,s];case 90:return[n,t-r,s,o];case 180:return[i,t-r,o,s];case 270:return[i,t-a,s,o];default:throw Error(`Invalid rotation`)}}getPDFRect(){return this.getRect(0,0)}getNonHCMColor(){return this.color&&H._colorManager.convert(this._uiManager.getNonHCMColor(this.color))}onUpdatedColor(){this.#r?.onUpdatedColor()}getData(){let{comment:{text:e,color:t,date:n,opacity:r,deleted:i,richText:a},uid:o,pageIndex:s,creationDate:c,modificationDate:l}=this;return{id:o,pageIndex:s,rect:this.getPDFRect(),richText:a,contentsObj:{str:e},creationDate:c,modificationDate:n||l,popupRef:!i,color:t,opacity:r}}onceAdded(e){}isEmpty(){return!1}enableEditMode(){if(this.isInEditMode())return!1;this.parent.setEditingState(!1);this.#_=!0;return!0}disableEditMode(){if(!this.isInEditMode())return!1;this.parent.setEditingState(!0);this.#_=!1;return!0}isInEditMode(){return this.#_}shouldGetKeyboardEvents(){return this.#v}needsToBeRebuilt(){return this.div&&!this.isAttachedToDOM}get isOnScreen(){let{top:e,left:t,bottom:n,right:r}=this.getClientDimensions(),{innerHeight:i,innerWidth:a}=window;return t<a&&r>0&&e<i&&n>0}#z(){if(this.#f||!this.div)return;this.#f=new AbortController;let e=this._uiManager.combinedSignal(this.#f);this.div.addEventListener(`focusin`,this.focusin.bind(this),{signal:e});this.div.addEventListener(`focusout`,this.focusout.bind(this),{signal:e})}rebuild(){this.#z()}rotate(e){}resize(){}serializeDeleted(){return{id:this.annotationElementId,deleted:!0,pageIndex:this.pageIndex,popupRef:this._initialData?.popupRef||``}}serialize(e=!1,t=null){return{annotationType:this.mode,pageIndex:this.pageIndex,rect:this.getPDFRect(),rotation:this.rotation,structTreeParentId:this._structTreeParentId,popupRef:this._initialData?.popupRef||``}}static async deserialize(e,t,n){let r=new this.prototype.constructor({parent:t,id:n.getId(),uiManager:n,annotationElementId:e.annotationElementId,creationDate:e.creationDate,modificationDate:e.modificationDate});r.rotation=e.rotation;r.#e=e.accessibilityData;r._isCopy=e.isCopy||!1;let[i,a]=r.pageDimensions,[o,s,c,l]=r.getRectInCurrentCoords(e.rect,a);r.x=o/i;r.y=s/a;r.width=c/i;r.height=l/a;return r}get hasBeenModified(){return!!this.annotationElementId&&(this.deleted||this.serialize()!==null)}remove(){this.#f?.abort();this.#f=null;this.isEmpty()||this.commit();this.parent?this.parent.remove(this):this._uiManager.removeEditor(this);this.hideCommentPopup();if(this.#y){clearTimeout(this.#y);this.#y=null}this.#W();this.removeEditToolbar();if(this.#S){for(let e of this.#S.values())clearTimeout(e);this.#S=null}this.parent=null;this.#C?.destroy();this.#C=null;this.#d?.remove();this.#d=null}get isResizable(){return!1}makeResizable(){if(this.isResizable){this.#k();this.#c.classList.remove(`hidden`)}}get toolbarPosition(){return null}get commentButtonPosition(){return this._uiManager.direction===`ltr`?[1,0]:[0,0]}get commentButtonPositionInPage(){let{commentButtonPosition:[e,t]}=this,[n,r,i,a]=this.getPDFRect();return[H._round(n+(i-n)*e),H._round(r+(a-r)*(1-t))]}get commentButtonColor(){return this._uiManager.makeCommentColor(this.getNonHCMColor(),this.opacity)}get commentPopupPosition(){return this.#r.commentPopupPositionInLayer}set commentPopupPosition(e){this.#r.commentPopupPositionInLayer=e}hasDefaultPopupPosition(){return this.#r.hasDefaultPopupPosition()}get commentButtonWidth(){return this.#r.commentButtonWidth}get elementBeforePopup(){return this.div}setCommentButtonStates(e){this.#r?.setCommentButtonStates(e)}keydown(e){if(!this.isResizable||e.target!==this.div||e.key!==`Enter`)return;this._uiManager.setSelected(this);this.#u={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};let t=this.#c.children;if(!this.#t){this.#t=Array.from(t);let e=this.#B.bind(this),n=this.#V.bind(this),r=this._uiManager._signal;for(let t of this.#t){let i=t.getAttribute(`data-resizer-name`);t.setAttribute(`role`,`spinbutton`);t.addEventListener(`keydown`,e,{signal:r});t.addEventListener(`blur`,n,{signal:r});t.addEventListener(`focus`,this.#H.bind(this,i),{signal:r});t.setAttribute(`data-l10n-id`,H._l10nResizer[i])}}let n=this.#t[0],r=0;for(let e of t){if(e===n)break;r++}let i=(360-this.rotation+this.parentRotation)%360/90*(this.#t.length/4);if(i!==r){if(i<r)for(let e=0;e<r-i;e++)this.#c.append(this.#c.firstElementChild);else if(i>r)for(let e=0;e<i-r;e++)this.#c.firstElementChild.before(this.#c.lastElementChild);let e=0;for(let n of t){let t=this.#t[e++].getAttribute(`data-resizer-name`);n.setAttribute(`data-l10n-id`,H._l10nResizer[t])}}this.#U(0);this.#v=!0;this.#c.firstElementChild.focus({focusVisible:!0});e.preventDefault();e.stopImmediatePropagation()}#B(e){H._resizerKeyboardManager.exec(this,e)}#V(e){this.#v&&e.relatedTarget?.parentNode!==this.#c&&this.#W()}#H(e){this.#p=this.#v?e:``}#U(e){if(this.#t)for(let t of this.#t)t.tabIndex=e}_resizeWithKeyboard(e,t){this.#v&&this.#N(this.#p,{deltaX:e,deltaY:t,fromKeyboard:!0})}#W(){this.#v=!1;this.#U(-1);this.#M()}_stopResizingWithKeyboard(){this.#W();this.div.focus()}select(){if(this.isSelected&&this._editToolbar)this._editToolbar.show();else{this.isSelected=!0;this.makeResizable();this.div?.classList.add(`selectedEditor`);if(this._editToolbar){this._editToolbar?.show();this.#n?.toggleAltTextBadge(!1)}else this.addEditToolbar().then(()=>{this.div?.classList.contains(`selectedEditor`)&&this._editToolbar?.show()})}}focus(){this.div&&!this.div.contains(document.activeElement)&&setTimeout(()=>this.div?.focus({preventScroll:!0}),0)}unselect(){if(this.isSelected){this.isSelected=!1;this.#c?.classList.add(`hidden`);this.div?.classList.remove(`selectedEditor`);this.div?.contains(document.activeElement)&&this._uiManager.currentLayer.div.focus({preventScroll:!0});this._editToolbar?.hide();this.#n?.toggleAltTextBadge(!0);this.hideCommentPopup()}}hideCommentPopup(){this.hasComment&&this._uiManager.toggleComment(null)}updateParams(e,t){}disableEditing(){}enableEditing(){}get canChangeContent(){return!1}enterInEditMode(){if(this.canChangeContent){this.enableEditMode();this.div.focus()}}dblclick(e){if(e.target.nodeName!==`BUTTON`){this.enterInEditMode();this.parent.updateToolbar({mode:this.constructor._editorType,editId:this.uid})}}getElementForAltText(){return this.div}get contentDiv(){return this.div}get isEditing(){return this.#g}set isEditing(e){this.#g=e;if(this.parent){if(e){this.parent.setSelected(this);this.parent.setActiveEditor(this)}else this.parent.setActiveEditor(null)}}static get MIN_SIZE(){return 16}static canCreateNewEmptyEditor(){return!0}get telemetryInitialData(){return{action:`added`}}get telemetryFinalData(){return null}_reportTelemetry(e,t=!1){if(t){this.#S||=new Map;let{action:t}=e,n=this.#S.get(t);n&&clearTimeout(n);n=setTimeout(()=>{this._reportTelemetry(e);this.#S.delete(t);this.#S.size===0&&(this.#S=null)},H._telemetryTimeout);this.#S.set(t,n);return}e.type||=this.editorType;this._uiManager._eventBus.dispatch(`reporttelemetry`,{source:this,details:{type:`editing`,data:e}})}show(e=this._isVisible){this.div.classList.toggle(`hidden`,!e);this._isVisible=e}enable(){this.div&&(this.div.tabIndex=0);this.#a=!1}disable(){this.div&&(this.div.tabIndex=-1);this.#a=!0}updateFakeAnnotationElement(e){if(this.#d||this.deleted){if(this.deleted){this.#d.remove();this.#d=null}else(this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized)&&this.#d.updateEdited({rect:this.getPDFRect(),popup:this.comment})}else this.#d=e.addFakeAnnotation(this)}renderAnnotationElement(e){if(this.deleted){e.hide();return null}let t=e.container.querySelector(`.annotationContent`);if(t){if(t.nodeName===`CANVAS`){let e=t;t=document.createElement(`div`);t.classList.add(`annotationContent`,this.editorType);e.before(t)}}else{t=document.createElement(`div`);t.classList.add(`annotationContent`,this.editorType);e.container.prepend(t)}return t}resetAnnotationElement(e){let{firstElementChild:t}=e.container;t?.nodeName===`DIV`&&t.classList.contains(`annotationContent`)&&t.remove()}}class He extends H{constructor(e){super(e);this.annotationElementId=e.annotationElementId;this.deleted=!0}serialize(){return this.serializeDeleted()}}const Ue=3285377520,U=4294901760,We=65535;class Ge{constructor(e){this.h1=e?4294967295&e:Ue;this.h2=e?4294967295&e:Ue}update(e){let t,n;if(typeof e==`string`){t=new Uint8Array(2*e.length);n=0;for(let r=0,i=e.length;r<i;r++){let i=e.charCodeAt(r);if(i<=255)t[n++]=i;else{t[n++]=i>>>8;t[n++]=255&i}}}else{if(!ArrayBuffer.isView(e))throw Error(`Invalid data format, must be a string or TypedArray.`);t=e.slice();n=t.byteLength}let r=n>>2,i=n-4*r,a=new Uint32Array(t.buffer,0,r),o=0,s=0,c=this.h1,l=this.h2,u=3432918353,d=461845907,f=11601,p=13715;for(let e=0;e<r;e++)if(1&e){o=a[e];o=o*u&U|o*f&We;o=o<<15|o>>>17;o=o*d&U|o*p&We;c^=o;c=c<<13|c>>>19;c=5*c+3864292196}else{s=a[e];s=s*u&U|s*f&We;s=s<<15|s>>>17;s=s*d&U|s*p&We;l^=s;l=l<<13|l>>>19;l=5*l+3864292196}o=0;switch(i){case 3:o^=t[4*r+2]<<16;case 2:o^=t[4*r+1]<<8;case 1:o^=t[4*r];o=o*u&U|o*f&We;o=o<<15|o>>>17;o=o*d&U|o*p&We;1&r?c^=o:l^=o}this.h1=c;this.h2=l}hexdigest(){let e=this.h1,t=this.h2;e^=t>>>1;e=3981806797*e&U|36045*e&We;t=4283543511*t&U|(2950163797*(t<<16|e>>>16)&U)>>>16;e^=t>>>1;e=444984403*e&U|60499*e&We;t=3301882366*t&U|(3120437893*(t<<16|e>>>16)&U)>>>16;e^=t>>>1;return(e>>>0).toString(16).padStart(8,`0`)+(t>>>0).toString(16).padStart(8,`0`)}}const Ke=Object.freeze({map:null,hash:``,transfer:void 0});class qe{#e=!1;#t=null;#n=null;#r=new Map;onSetModified=null;onResetModified=null;onAnnotationEditor=null;getValue(e,t){let n=this.#r.get(e);return n===void 0?t:Object.assign(t,n)}getRawValue(e){return this.#r.get(e)}remove(e){let t=this.#r.get(e);if(t!==void 0){t instanceof H&&this.#n.delete(t.annotationElementId);this.#r.delete(e);this.#r.size===0&&this.resetModified();this.#r.values().some(e=>e instanceof H)||this.onAnnotationEditor?.(null)}}setValue(e,t){let n=this.#r.get(e),r=!1;if(n!==void 0){for(let[e,i]of Object.entries(t))if(n[e]!==i){r=!0;n[e]=i}}else{r=!0;this.#r.set(e,t)}r&&this.#i();if(t instanceof H){(this.#n||=new Map).set(t.annotationElementId,t);this.onAnnotationEditor?.(t.constructor._type)}}has(e){return this.#r.has(e)}get size(){return this.#r.size}#i(){if(!this.#e){this.#e=!0;this.onSetModified?.()}}resetModified(){if(this.#e){this.#e=!1;this.onResetModified?.()}}get print(){return new Je(this)}get serializable(){if(this.#r.size===0)return Ke;let e=new Map,t=new Ge,n=[],r=Object.create(null),i=!1;for(let[n,a]of this.#r){let o=a instanceof H?a.serialize(!1,r):a;if(a.page){a.pageIndex=a.page._pageIndex;delete a.page}if(o){e.set(n,o);t.update(`${n}:${JSON.stringify(o)}`);i||=!!o.bitmap}}if(i)for(let t of e.values())t.bitmap&&n.push(t.bitmap);return e.size>0?{map:e,hash:t.hexdigest(),transfer:n}:Ke}get editorStats(){let e=null,t=new Map,n=0,r=0;for(let i of this.#r.values()){if(!(i instanceof H)){i.popup&&(i.popup.deleted?r+=1:n+=1);continue}i.isCommentDeleted?r+=1:i.hasEditedComment&&(n+=1);let a=i.telemetryFinalData;if(!a)continue;let{type:o}=a;t.has(o)||t.set(o,Object.getPrototypeOf(i).constructor);e||=Object.create(null);let s=e[o]||=new Map;for(let[e,t]of Object.entries(a)){if(e===`type`)continue;let n=s.getOrInsertComputed(e,le);n.set(t,(n.get(t)??0)+1)}}if(r>0||n>0){e||=Object.create(null);e.comments={deleted:r,edited:n}}if(!e)return null;for(let[n,r]of t)e[n]=r.computeTelemetryFinalData(e[n]);return e}resetModifiedIds(){this.#t=null}updateEditor(e,t){let n=this.#n?.get(e);if(n){n.updateFromAnnotationLayer(t);return!0}return!1}getEditor(e){return this.#n?.get(e)||null}get modifiedIds(){if(this.#t)return this.#t;let e=[];if(this.#n)for(let t of this.#n.values())t.serialize()&&e.push(t.annotationElementId);let t=``;if(e.length){let n=new Ge;n.update(e.join(`,`));t=n.hexdigest()}return this.#t={ids:new Set(e),hash:t}}[Symbol.iterator](){return this.#r.entries()}}class Je extends qe{#e=Ke;constructor(e){super();let{serializable:t}=e;if(t===Ke)return;let{map:n,hash:r,transfer:i}=t,a=structuredClone(n,i?{transfer:i}:null);this.#e={map:a,hash:r,transfer:[]}}get print(){D(`Should not call PrintAnnotationStorage.print`)}get serializable(){return this.#e}get modifiedIds(){return j(this,`modifiedIds`,{ids:new Set,hash:``})}}const Ye=`__forcedDependency`,{floor:Xe,ceil:Ze}=Math;function Qe(e,t,n,r,i,a){e[4*t+0]=Math.min(e[4*t+0],n);e[4*t+1]=Math.min(e[4*t+1],r);e[4*t+2]=Math.max(e[4*t+2],i);e[4*t+3]=Math.max(e[4*t+3],a)}const $e=new Uint32Array(new Uint8Array([255,255,0,0]).buffer)[0];class et{#e;#t;constructor(e,t){this.#e=e;this.#t=t}get length(){return this.#e.length}isEmpty(e){return this.#e[e]===$e}minX(e){return this.#t[4*e+0]/256}minY(e){return this.#t[4*e+1]/256}maxX(e){return(this.#t[4*e+2]+1)/256}maxY(e){return(this.#t[4*e+3]+1)/256}}const tt=(e,t)=>e?.getOrInsertComputed(t,()=>({dependencies:new Set,isRenderingOperation:!1}));class nt{#e=[[1,0,0,1,0,0]];#t=[-1/0,-1/0,1/0,1/0];#n=new Float64Array(u);_pendingBBoxIdx=-1;#r;#i;#a;#o;_savesStack=[];_markedContentStack=[];constructor(e,t){this.#r=e.width;this.#i=e.height;this.#s(t)}growOperationsCount(e){e>=this.#o.length&&this.#s(e,this.#o)}#s(e,t){let n=new ArrayBuffer(4*e);this.#a=new Uint8ClampedArray(n);this.#o=new Uint32Array(n);if(t&&t.length>0){this.#o.set(t);this.#o.fill($e,t.length)}else this.#o.fill($e)}get clipBox(){return this.#t}save(e){this.#t={__proto__:this.#t};this._savesStack.push(e);return this}restore(e,t){let n=Object.getPrototypeOf(this.#t);if(n===null)return this;this.#t=n;let r=this._savesStack.pop();if(r!==void 0){t?.(r,e);this.#o[e]=this.#o[r]}return this}recordOpenMarker(e){this._savesStack.push(e);return this}getOpenMarker(){return this._savesStack.length===0?null:this._savesStack.at(-1)}recordCloseMarker(e,t){let n=this._savesStack.pop();if(n!==void 0){t?.(n,e);this.#o[e]=this.#o[n]}return this}beginMarkedContent(e){this._markedContentStack.push(e);return this}endMarkedContent(e,t){let n=this._markedContentStack.pop();if(n!==void 0){t?.(n,e);this.#o[e]=this.#o[n]}return this}pushBaseTransform(e){this.#e.push(P.multiplyByDOMMatrix(this.#e.at(-1),e.getTransform()));return this}popBaseTransform(){this.#e.length>1&&this.#e.pop();return this}resetBBox(e){if(this._pendingBBoxIdx!==e){this._pendingBBoxIdx=e;this.#n.set(u,0)}return this}recordClipBox(e,t,n,r,i,a){let o=P.multiplyByDOMMatrix(this.#e.at(-1),t.getTransform()),s=u.slice();P.axialAlignedBoundingBox([n,i,r,a],o,s);let c=P.intersect(this.#t,s);if(c){this.#t[0]=c[0];this.#t[1]=c[1];this.#t[2]=c[2];this.#t[3]=c[3]}else{this.#t[0]=this.#t[1]=1/0;this.#t[2]=this.#t[3]=-1/0}return this}recordBBox(e,t,n,r,i,a){let o=this.#t;if(o[0]===1/0)return this;let s=P.multiplyByDOMMatrix(this.#e.at(-1),t.getTransform());if(o[0]===-1/0){P.axialAlignedBoundingBox([n,i,r,a],s,this.#n);return this}let c=u.slice();P.axialAlignedBoundingBox([n,i,r,a],s,c);this.#n[0]=F(c[0],o[0],this.#n[0]);this.#n[1]=F(c[1],o[1],this.#n[1]);this.#n[2]=F(c[2],this.#n[2],o[2]);this.#n[3]=F(c[3],this.#n[3],o[3]);return this}recordFullPageBBox(e){this.#n[0]=Math.max(0,this.#t[0]);this.#n[1]=Math.max(0,this.#t[1]);this.#n[2]=Math.min(this.#r,this.#t[2]);this.#n[3]=Math.min(this.#i,this.#t[3]);return this}recordOperation(e,t=!1,n){if(this._pendingBBoxIdx!==e)return this;let r=Xe(256*this.#n[0]/this.#r),i=Xe(256*this.#n[1]/this.#i),a=Ze(256*this.#n[2]/this.#r),o=Ze(256*this.#n[3]/this.#i);Qe(this.#a,e,r,i,a,o);if(n)for(let t of n)for(let n of t)n!==e&&Qe(this.#a,n,r,i,a,o);t||(this._pendingBBoxIdx=-1);return this}bboxToClipBoxDropOperation(e){if(this._pendingBBoxIdx===e){this._pendingBBoxIdx=-1;this.#t[0]=Math.max(this.#t[0],this.#n[0]);this.#t[1]=Math.max(this.#t[1],this.#n[1]);this.#t[2]=Math.min(this.#t[2],this.#n[2]);this.#t[3]=Math.min(this.#t[3],this.#n[3])}return this}take(){return new et(this.#o,this.#a)}takeDebugMetadata(){throw Error(`Unreachable`)}recordSimpleData(e,t){return this}recordIncrementalData(e,t){return this}resetIncrementalData(e,t){return this}recordNamedData(e,t){return this}recordSimpleDataFromNamed(e,t,n){return this}recordFutureForcedDependency(e,t){return this}inheritSimpleDataAsFutureForcedDependencies(e){return this}inheritPendingDependenciesAsFutureForcedDependencies(){return this}recordCharacterBBox(e,t,n,r=1,i=0,a=0,o){return this}getSimpleIndex(e){}recordDependencies(e,t){return this}recordNamedDependency(e,t){return this}recordShowTextOperation(e,t=!1){return this}}class rt{#e={__proto__:null};#t={__proto__:null,transform:[],moveText:[],sameLineText:[],[Ye]:[]};#n=new Map;#r=new Set;#i=new Map;#a;#o;#s;constructor(e,t=!1){this.#s=e;if(t){this.#a=new Map;this.#o=(e,t)=>{tt(this.#a,t).dependencies.add(e)}}}get clipBox(){return this.#s.clipBox}growOperationsCount(e){this.#s.growOperationsCount(e)}save(e){this.#e={__proto__:this.#e};this.#t={__proto__:this.#t,transform:{__proto__:this.#t.transform},moveText:{__proto__:this.#t.moveText},sameLineText:{__proto__:this.#t.sameLineText},[Ye]:{__proto__:this.#t[Ye]}};this.#s.save(e);return this}restore(e){this.#s.restore(e,this.#o);let t=Object.getPrototypeOf(this.#e);if(t===null)return this;this.#e=t;this.#t=Object.getPrototypeOf(this.#t);return this}recordOpenMarker(e){this.#s.recordOpenMarker(e,this.#o);return this}getOpenMarker(){return this.#s.getOpenMarker()}recordCloseMarker(e){this.#s.recordCloseMarker(e,this.#o);return this}beginMarkedContent(e){this.#s.beginMarkedContent(e);return this}endMarkedContent(e){this.#s.endMarkedContent(e,this.#o);return this}pushBaseTransform(e){this.#s.pushBaseTransform(e);return this}popBaseTransform(){this.#s.popBaseTransform();return this}recordSimpleData(e,t){this.#e[e]=t;return this}recordIncrementalData(e,t){this.#t[e].push(t);return this}resetIncrementalData(e,t){this.#t[e].length=0;return this}recordNamedData(e,t){this.#n.set(e,t);return this}recordSimpleDataFromNamed(e,t,n){this.#e[e]=this.#n.get(t)??n}recordFutureForcedDependency(e,t){this.recordIncrementalData(Ye,t);return this}inheritSimpleDataAsFutureForcedDependencies(e){for(let t of e)t in this.#e&&this.recordFutureForcedDependency(t,this.#e[t]);return this}inheritPendingDependenciesAsFutureForcedDependencies(){for(let e of this.#r)this.recordFutureForcedDependency(Ye,e);return this}resetBBox(e){this.#s.resetBBox(e);return this}recordClipBox(e,t,n,r,i,a){this.#s.recordClipBox(e,t,n,r,i,a);return this}recordBBox(e,t,n,r,i,a){this.#s.recordBBox(e,t,n,r,i,a);return this}recordCharacterBBox(e,t,n,r=1,i=0,a=0,o){let s=n.bbox,c,l;if(s){c=s[2]!==s[0]&&s[3]!==s[1]&&this.#i.get(n);if(!1!==c){l=[0,0,0,0];P.axialAlignedBoundingBox(s,n.fontMatrix,l);r===1&&i===0&&a===0||P.scaleMinMax([r,0,0,-r,i,a],l);if(c)return this.recordBBox(e,t,l[0],l[2],l[1],l[3])}}if(!o)return this.recordFullPageBBox(e);let u=o();if(s&&l&&c===void 0){c=l[0]<=i-u.actualBoundingBoxLeft&&l[2]>=i+u.actualBoundingBoxRight&&l[1]<=a-u.actualBoundingBoxAscent&&l[3]>=a+u.actualBoundingBoxDescent;this.#i.set(n,c);if(c)return this.recordBBox(e,t,l[0],l[2],l[1],l[3])}return this.recordBBox(e,t,i-u.actualBoundingBoxLeft,i+u.actualBoundingBoxRight,a-u.actualBoundingBoxAscent,a+u.actualBoundingBoxDescent)}recordFullPageBBox(e){this.#s.recordFullPageBBox(e);return this}getSimpleIndex(e){return this.#e[e]}recordDependencies(e,t){let n=this.#r,r=this.#e,i=this.#t;for(let e of t)e in this.#e?n.add(r[e]):e in i&&i[e].forEach(n.add,n);return this}recordNamedDependency(e,t){this.#n.has(t)&&this.#r.add(this.#n.get(t));return this}recordOperation(e,t=!1){this.recordDependencies(e,[Ye]);if(this.#a){let t=tt(this.#a,e),{dependencies:n}=t;this.#r.forEach(n.add,n);this.#s._savesStack.forEach(n.add,n);this.#s._markedContentStack.forEach(n.add,n);n.delete(e);t.isRenderingOperation=!0}let n=!t&&e===this.#s._pendingBBoxIdx;this.#s.recordOperation(e,t,[this.#r,this.#s._savesStack,this.#s._markedContentStack]);n&&this.#r.clear();return this}recordShowTextOperation(e,t=!1){let n=Array.from(this.#r);this.recordOperation(e,t);this.recordIncrementalData(`sameLineText`,e);for(let e of n)this.recordIncrementalData(`sameLineText`,e);return this}bboxToClipBoxDropOperation(e,t=!1){let n=!t&&e===this.#s._pendingBBoxIdx;this.#s.bboxToClipBoxDropOperation(e);n&&this.#r.clear();return this}take(){this.#i.clear();return this.#s.take()}takeDebugMetadata(){return this.#a}}class it{#e;#t;#n;#r=0;#i=0;constructor(e,t,n){if(e instanceof it&&e.#n===!!n)return e;this.#e=e;this.#t=t;this.#n=!!n}get clipBox(){return this.#e.clipBox}growOperationsCount(){throw Error(`Unreachable`)}save(e){this.#i++;this.#e.save(this.#t);return this}restore(e){if(this.#i>0){this.#e.restore(this.#t);this.#i--}return this}recordOpenMarker(e){this.#r++;return this}getOpenMarker(){return this.#r>0?this.#t:this.#e.getOpenMarker()}recordCloseMarker(e){this.#r--;return this}beginMarkedContent(e){return this}endMarkedContent(e){return this}pushBaseTransform(e){this.#e.pushBaseTransform(e);return this}popBaseTransform(){this.#e.popBaseTransform();return this}recordSimpleData(e,t){this.#e.recordSimpleData(e,this.#t);return this}recordIncrementalData(e,t){this.#e.recordIncrementalData(e,this.#t);return this}resetIncrementalData(e,t){this.#e.resetIncrementalData(e,this.#t);return this}recordNamedData(e,t){return this}recordSimpleDataFromNamed(e,t,n){this.#e.recordSimpleDataFromNamed(e,t,this.#t);return this}recordFutureForcedDependency(e,t){this.#e.recordFutureForcedDependency(e,this.#t);return this}inheritSimpleDataAsFutureForcedDependencies(e){this.#e.inheritSimpleDataAsFutureForcedDependencies(e);return this}inheritPendingDependenciesAsFutureForcedDependencies(){this.#e.inheritPendingDependenciesAsFutureForcedDependencies();return this}resetBBox(e){this.#n||this.#e.resetBBox(this.#t);return this}recordClipBox(e,t,n,r,i,a){this.#n||this.#e.recordClipBox(this.#t,t,n,r,i,a);return this}recordBBox(e,t,n,r,i,a){this.#n||this.#e.recordBBox(this.#t,t,n,r,i,a);return this}recordCharacterBBox(e,t,n,r,i,a,o){this.#n||this.#e.recordCharacterBBox(this.#t,t,n,r,i,a,o);return this}recordFullPageBBox(e){this.#n||this.#e.recordFullPageBBox(this.#t);return this}getSimpleIndex(e){return this.#e.getSimpleIndex(e)}recordDependencies(e,t){this.#e.recordDependencies(this.#t,t);return this}recordNamedDependency(e,t){this.#e.recordNamedDependency(this.#t,t);return this}recordOperation(e){this.#e.recordOperation(this.#t,!0);return this}recordShowTextOperation(e){this.#e.recordShowTextOperation(this.#t,!0);return this}bboxToClipBoxDropOperation(e){this.#n||this.#e.bboxToClipBoxDropOperation(this.#t,!0);return this}take(){throw Error(`Unreachable`)}takeDebugMetadata(){throw Error(`Unreachable`)}}const at=[`path`,`transform`,`filter`,`strokeColor`,`strokeAlpha`,`lineWidth`,`lineCap`,`lineJoin`,`miterLimit`,`dash`],ot=[`path`,`transform`,`filter`,`fillColor`,`fillAlpha`,`globalCompositeOperation`,`SMask`],st=[`transform`,`SMask`,`filter`,`fillAlpha`,`strokeAlpha`,`globalCompositeOperation`],ct=[`filter`,`fillColor`,`fillAlpha`],lt=[`transform`,`leading`,`charSpacing`,`wordSpacing`,`hScale`,`textRise`,`moveText`,`textMatrix`,`font`,`fontObj`,`filter`,`fillColor`,`textRenderingMode`,`SMask`,`fillAlpha`,`strokeAlpha`,`globalCompositeOperation`,`sameLineText`],ut=[`transform`],dt=[`transform`,`fillColor`];class ft{#e;#t;#n=4;#r=0;#i=new ft.#a(6*this.#n);static#a=N.isFloat16ArraySupported?Float16Array:Float32Array;constructor(e){this.#e=e.width;this.#t=e.height}record(e,t,n,r){if(this.#r===this.#n){this.#n*=2;let e=new ft.#a(6*this.#n);e.set(this.#i);this.#i=e}let i=P.domMatrixToTransform(e.getTransform()),a;if(r[0]!==1/0){let e=u.slice();P.axialAlignedBoundingBox([0,-n,t,0],i,e);let o=P.intersect(r,e);if(!o)return;let[s,c,l,d]=o;if(s!==e[0]||c!==e[1]||l!==e[2]||d!==e[3]){let e=Math.atan2(i[1],i[0]),t=Math.abs(Math.sin(e)),n=Math.abs(Math.cos(e));if(t<1e-6||n<1e-6||Math.abs(t-n)<1e-6)a=[s,c,s,d,l,c];else{let e=l-s,r=d-c,i=t*t,o=n*n,u=n*t,f=o-i,p=(r*o-e*u)/f;a=[s+(r*u-e*i)/f,c,s,c+p,l,d-p]}}}if(!a){a=[0,-n,0,0,t,-n];P.applyTransform(a,i,0);P.applyTransform(a,i,2);P.applyTransform(a,i,4)}a[0]/=this.#e;a[1]/=this.#t;a[2]/=this.#e;a[3]/=this.#t;a[4]/=this.#e;a[5]/=this.#t;this.#i.set(a,6*this.#r);this.#r++}take(){return this.#i.subarray(0,6*this.#r)}}class pt{#e=new Set;constructor({ownerDocument:e=globalThis.document,styleElement:t=null}){this._document=e;this.nativeFontFaces=new Set;this.styleElement=null;this.loadingRequests=[];this.loadTestFontId=0}addNativeFontFace(e){this.nativeFontFaces.add(e);this._document.fonts.add(e)}removeNativeFontFace(e){this.nativeFontFaces.delete(e);this._document.fonts.delete(e)}insertRule(e){if(!this.styleElement){this.styleElement=this._document.createElement(`style`);this._document.documentElement.getElementsByTagName(`head`)[0].append(this.styleElement)}let t=this.styleElement.sheet;t.insertRule(e,t.cssRules.length)}clear(){for(let e of this.nativeFontFaces)this._document.fonts.delete(e);this.nativeFontFaces.clear();this.#e.clear();if(this.styleElement){this.styleElement.remove();this.styleElement=null}}async loadSystemFont({systemFontInfo:e,disableFontFace:t,_inspectFont:n}){if(e&&!this.#e.has(e.loadedName)){O(!t,"loadSystemFont shouldn't be called when `disableFontFace` is set.");if(this.isFontLoadingAPISupported){let{loadedName:t,src:r,style:i}=e,a=new FontFace(t,r,i);this.addNativeFontFace(a);try{await a.load();this.#e.add(t);n?.(e)}catch{E(`Cannot load system font: ${e.baseFontName}, installing it could help to improve PDF rendering.`);this.removeNativeFontFace(a)}return}D(`Not implemented: loadSystemFont without the Font Loading API.`)}}async bind(e){if(e.attached||e.missingFile&&!e.systemFontInfo)return;e.attached=!0;if(e.systemFontInfo){await this.loadSystemFont(e);return}if(this.isFontLoadingAPISupported){let t=e.createNativeFontFace();if(t){this.addNativeFontFace(t);try{await t.loaded}catch(n){E(`Failed to load font '${t.family}': '${n}'.`);e.disableFontFace=!0;throw n}}return}let t=e.createFontFaceRule();if(t){this.insertRule(t);if(this.isSyncFontLoadingSupported)return;await new Promise(t=>{let n=this._queueLoadingCallback(t);this._prepareFontLoadEvent(e,n)})}}get isFontLoadingAPISupported(){return j(this,`isFontLoadingAPISupported`,!!this._document?.fonts)}get isSyncFontLoadingSupported(){return j(this,`isSyncFontLoadingSupported`,l||N.platform.isFirefox)}_queueLoadingCallback(e){let{loadingRequests:t}=this,n={done:!1,complete:function(){O(!n.done,`completeRequest() cannot be called twice.`);n.done=!0;for(;t.length>0&&t[0].done;){let e=t.shift();setTimeout(e.callback,0)}},callback:e};t.push(n);return n}get _loadTestFont(){return j(this,`_loadTestFont`,atob(`T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==`))}_prepareFontLoadEvent(e,t){function n(e,t){return e.charCodeAt(t)<<24|e.charCodeAt(t+1)<<16|e.charCodeAt(t+2)<<8|255&e.charCodeAt(t+3)}function r(e,t,n,r){return e.substring(0,t)+r+e.substring(t+n)}let i,a,o=this._document.createElement(`canvas`);o.width=1;o.height=1;let s=o.getContext(`2d`),c=0,l=`lt${Date.now()}${this.loadTestFontId++}`,u=this._loadTestFont;u=r(u,976,l.length,l);let d=1482184792,f=n(u,16);for(i=0,a=l.length-3;i<a;i+=4)f=f-d+n(l,i)|0;i<l.length&&(f=f-d+n(l+`XXX`,i)|0);u=r(u,16,4,function(e){return String.fromCharCode(e>>24&255,e>>16&255,e>>8&255,255&e)}(f));let p=`@font-face {font-family:"${l}";src:${`url(data:font/opentype;base64,${btoa(u)});`}}`;this.insertRule(p);let m=this._document.createElement(`div`);m.style.visibility=`hidden`;m.style.width=m.style.height=`10px`;m.style.position=`absolute`;m.style.top=m.style.left=`0px`;for(let t of[e.loadedName,l]){let e=this._document.createElement(`span`);e.textContent=`Hi`;e.style.fontFamily=t;m.append(e)}this._document.body.append(m);(function e(t,n){if(++c>30){E(`Load test font never loaded.`);n();return}s.font=`30px `+t;s.fillText(`.`,0,20);s.getImageData(0,0,1,1).data[3]>0?n():setTimeout(e.bind(null,t,n))})(l,()=>{m.remove();t.complete()})}}class mt{compiledGlyphs=Object.create(null);#e;constructor(e,t=null,n,r){this.#e=e;this._inspectFont=t;n&&(this.charProcOperatorList=n);r&&Object.assign(this,r)}createNativeFontFace(){if(!this.data||this.disableFontFace)return null;let e;if(this.cssFontInfo){let t={weight:this.cssFontInfo.fontWeight};this.cssFontInfo.italicAngle&&(t.style=`oblique ${this.cssFontInfo.italicAngle}deg`);e=new FontFace(this.cssFontInfo.fontFamily,this.data,t)}else e=new FontFace(this.loadedName,this.data,{});this._inspectFont?.(this);return e}createFontFaceRule(){if(!this.data||this.disableFontFace)return null;let e=`url(data:${this.mimetype};base64,${this.data.toBase64()});`,t;if(this.cssFontInfo){let n=`font-weight: ${this.cssFontInfo.fontWeight};`;this.cssFontInfo.italicAngle&&(n+=`font-style: oblique ${this.cssFontInfo.italicAngle}deg;`);t=`@font-face {font-family:"${this.cssFontInfo.fontFamily}";${n}src:${e}}`}else t=`@font-face {font-family:"${this.loadedName}";src:${e}}`;this._inspectFont?.(this,e);return t}getPathGenerator(e,t){if(this.compiledGlyphs[t]!==void 0)return this.compiledGlyphs[t];let n=this.loadedName+`_path_`+t,r;try{r=e.get(n)}catch(e){E(`getPathGenerator - ignoring character: "${e}".`)}let i=ke(r?.path);this.fontExtraProperties||e.delete(n);return this.compiledGlyphs[t]=i}get black(){return this.#e.black}get bold(){return this.#e.bold}get disableFontFace(){return this.#e.disableFontFace}set disableFontFace(e){j(this,`disableFontFace`,!!e)}get fontExtraProperties(){return this.#e.fontExtraProperties}get isInvalidPDFjsFont(){return this.#e.isInvalidPDFjsFont}get isType3Font(){return this.#e.isType3Font}get italic(){return this.#e.italic}get missingFile(){return this.#e.missingFile}get remeasure(){return this.#e.remeasure}get vertical(){return this.#e.vertical}get ascent(){return this.#e.ascent}get defaultWidth(){return this.#e.defaultWidth}get descent(){return this.#e.descent}get bbox(){return this.#e.bbox}get fontMatrix(){return this.#e.fontMatrix}get fallbackName(){return this.#e.fallbackName}get loadedName(){return this.#e.loadedName}get mimetype(){return this.#e.mimetype}get name(){return this.#e.name}get data(){return this.#e.data}clearData(){this.#e.clearData()}get cssFontInfo(){return this.#e.cssFontInfo}get systemFontInfo(){return this.#e.systemFontInfo}get defaultVMetrics(){return this.#e.defaultVMetrics}}class ht{static strings=[`fontFamily`,`fontWeight`,`italicAngle`]}class gt{static strings=[`css`,`loadedName`,`baseFontName`,`src`]}class W{static bools=[`black`,`bold`,`disableFontFace`,`fontExtraProperties`,`isInvalidPDFjsFont`,`isType3Font`,`italic`,`missingFile`,`remeasure`,`vertical`];static numbers=[`ascent`,`defaultWidth`,`descent`];static strings=[`fallbackName`,`loadedName`,`mimetype`,`name`];static OFFSET_NUMBERS=Math.ceil(2*this.bools.length/8);static OFFSET_BBOX=this.OFFSET_NUMBERS+8*this.numbers.length;static OFFSET_FONT_MATRIX=this.OFFSET_BBOX+1+8;static OFFSET_DEFAULT_VMETRICS=this.OFFSET_FONT_MATRIX+1+48;static OFFSET_STRINGS=this.OFFSET_DEFAULT_VMETRICS+1+6}class _t{static KIND=0;static HAS_BBOX=1;static HAS_BACKGROUND=2;static SHADING_TYPE=3;static N_COORD=4;static N_COLOR=8;static N_STOP=12;static N_FIGURES=16}class vt{#e;#t=new TextDecoder;#n;constructor(e){this.#e=e;this.#n=new DataView(e)}#r(e){O(e<ht.strings.length,`Invalid string index`);let t=0;for(let n=0;n<e;n++)t+=this.#n.getUint32(t)+4;let n=this.#n.getUint32(t);return this.#t.decode(new Uint8Array(this.#e,t+4,n))}get fontFamily(){return this.#r(0)}get fontWeight(){return this.#r(1)}get italicAngle(){return this.#r(2)}}class yt{#e;#t=new TextDecoder;#n;constructor(e){this.#e=e;this.#n=new DataView(e)}get guessFallback(){return this.#n.getUint8(0)!==0}#r(e){O(e<gt.strings.length,`Invalid string index`);let t=5;for(let n=0;n<e;n++)t+=this.#n.getUint32(t)+4;let n=this.#n.getUint32(t);return this.#t.decode(new Uint8Array(this.#e,t+4,n))}get css(){return this.#r(0)}get loadedName(){return this.#r(1)}get baseFontName(){return this.#r(2)}get src(){return this.#r(3)}get style(){let e=1;e+=4+this.#n.getUint32(e);let t=this.#n.getUint32(e),n=this.#t.decode(new Uint8Array(this.#e,e+4,t));e+=4+t;let r=this.#n.getUint32(e);return{style:n,weight:this.#t.decode(new Uint8Array(this.#e,e+4,r))}}}class bt{#e;#t=new TextDecoder;#n;constructor({buffer:e,extra:t}){this.#e=e;this.#n=new DataView(e);t&&Object.assign(this,t)}#r(e){O(e<W.bools.length,`Invalid boolean index`);let t=Math.floor(e/4),n=2*e%8,r=this.#n.getUint8(t)>>n&3;return r===0?void 0:r===2}get black(){return this.#r(0)}get bold(){return this.#r(1)}get disableFontFace(){return this.#r(2)}get fontExtraProperties(){return this.#r(3)}get isInvalidPDFjsFont(){return this.#r(4)}get isType3Font(){return this.#r(5)}get italic(){return this.#r(6)}get missingFile(){return this.#r(7)}get remeasure(){return this.#r(8)}get vertical(){return this.#r(9)}#i(e){O(e<W.numbers.length,`Invalid number index`);return this.#n.getFloat64(W.OFFSET_NUMBERS+8*e)}get ascent(){return this.#i(0)}get defaultWidth(){return this.#i(1)}get descent(){return this.#i(2)}#a(e,t,n,r){let i=this.#n.getUint8(e);if(i===0)return;O(i===t,`Invalid array length.`);e+=1;let a=Array(i);for(let t=0;t<i;t++){a[t]=this.#n[n](e,!0);e+=r}return a}get bbox(){return this.#a(W.OFFSET_BBOX,4,`getInt16`,2)}get fontMatrix(){return this.#a(W.OFFSET_FONT_MATRIX,6,`getFloat64`,8)}get defaultVMetrics(){return this.#a(W.OFFSET_DEFAULT_VMETRICS,3,`getInt16`,2)}#o(e){O(e<W.strings.length,`Invalid string index`);let t=W.OFFSET_STRINGS+4;for(let n=0;n<e;n++)t+=this.#n.getUint32(t)+4;let n=this.#n.getUint32(t);return this.#t.decode(new Uint8Array(this.#e,t+4,n))}get fallbackName(){return this.#o(0)}get loadedName(){return this.#o(1)}get mimetype(){return this.#o(2)}get name(){return this.#o(3)}#s(){let e=W.OFFSET_STRINGS;e+=4+this.#n.getUint32(e);e+=4+this.#n.getUint32(e);e+=4+this.#n.getUint32(e);return{offset:e,length:this.#n.getUint32(e)}}get data(){let{offset:e,length:t}=this.#s();return t===0?void 0:new Uint8Array(this.#e,e+4,t)}clearData(){let{offset:e,length:t}=this.#s();if(t!==0){this.#n.setUint32(e,0);this.#e=new Uint8Array(this.#e,0,e+4).slice().buffer;this.#n=new DataView(this.#e)}}get cssFontInfo(){let e=W.OFFSET_STRINGS;e+=4+this.#n.getUint32(e);e+=4+this.#n.getUint32(e);let t=this.#n.getUint32(e);if(t===0)return null;let n=new Uint8Array(t);n.set(new Uint8Array(this.#e,e+4,t));return new vt(n.buffer)}get systemFontInfo(){let e=W.OFFSET_STRINGS;e+=4+this.#n.getUint32(e);let t=this.#n.getUint32(e);if(t===0)return null;let n=new Uint8Array(t);n.set(new Uint8Array(this.#e,e+4,t));return new yt(n.buffer)}}class xt{constructor(e){this.buffer=e;this.view=new DataView(e);this.data=new Uint8Array(e)}getIR(){let e=this.view,t=this.data[_t.KIND],n=!!this.data[_t.HAS_BBOX],r=!!this.data[_t.HAS_BACKGROUND],i=e.getUint32(_t.N_COORD,!0),a=e.getUint32(_t.N_COLOR,!0),o=e.getUint32(_t.N_STOP,!0),s=20,c=new Float32Array(this.buffer,s,2*i);s+=8*i;let l=new Uint8Array(this.buffer,s,4*a);s+=4*a;let d=[];for(let t=0;t<o;++t){let t=e.getFloat32(s,!0);s+=4;let n=e.getUint32(s,!0);s+=4;d.push([t,`#${n.toString(16).padStart(6,`0`)}`])}let f=null;if(n){f=[];for(let t=0;t<4;++t){f.push(e.getFloat32(s,!0));s+=4}}let p=null;if(r){p=new Uint8Array(this.buffer,s,3);s+=3}if(t===1)return[`RadialAxial`,`axial`,f,d,Array.from(c.slice(0,2)),Array.from(c.slice(2,4)),null,null];if(t===2)return[`RadialAxial`,`radial`,f,d,[c[0],c[1]],[c[3],c[4]],c[2],c[5]];if(t===3){let e=this.data[_t.SHADING_TYPE],t=null;if(c.length>0){t=u.slice();for(let e=0,n=c.length;e<n;e+=2)P.pointBoundingBox(c[e],c[e+1],t)}return[`Mesh`,e,c,l,i,t,f,p]}throw Error(`Unsupported pattern kind: ${t}`)}}class St{#e;constructor(e){this.#e=e}get path(){return N.isFloat16ArraySupported?new Float16Array(this.#e):new Float32Array(this.#e)}}function Ct(e){if(typeof e!=`string`)return null;if(e.endsWith(`/`))return e;throw Error(`Invalid factory url: "${e}" must include trailing slash.`)}const wt=e=>typeof e==`object`&&Number.isInteger(e?.num)&&e.num>=0&&Number.isInteger(e?.gen)&&e.gen>=0;(function(e,t,n){if(!Array.isArray(n)||n.length<2)return!1;let[r,i,...a]=n;if(!e(r)&&!Number.isInteger(r))return!1;if(!t(i))return!1;let o=a.length,s=!0;switch(i.name){case`XYZ`:if(o<2||o>3)return!1;break;case`Fit`:case`FitB`:return o===0;case`FitH`:case`FitBH`:case`FitV`:case`FitBV`:if(o>1)return!1;break;case`FitR`:if(o!==4)return!1;s=!1;break;default:return!1}for(let e of a)if(!(typeof e==`number`||s&&e===null))return!1;return!0}).bind(null,wt,e=>typeof e==`object`&&typeof e?.name==`string`);class Tt{#e=new Map;#t=Promise.resolve();postMessage(e,t){let n={data:structuredClone(e,t?{transfer:t}:null)};this.#t.then(()=>{for(let[e]of this.#e)e.call(this,n)})}addEventListener(e,t,n=null){let r=null;if(n?.signal instanceof AbortSignal){let{signal:i}=n;if(i.aborted){E("LoopbackPort - cannot use an `aborted` signal.");return}let a=()=>this.removeEventListener(e,t);r=()=>i.removeEventListener(`abort`,a);i.addEventListener(`abort`,a)}this.#e.set(t,r)}removeEventListener(e,t){this.#e.get(t)?.();this.#e.delete(t)}terminate(){for(let[,e]of this.#e)e?.();this.#e.clear()}}function Et(){}function G(e){if(e instanceof ae||e instanceof ne||e instanceof ee||e instanceof re||e instanceof te)return e;e instanceof Error||typeof e==`object`&&e||D(`wrapReason: Expected "reason" to be a (possibly cloned) Error.`);switch(e.name){case`AbortException`:return new ae(e.message);case`InvalidPDFException`:return new ne(e.message);case`PasswordException`:return new ee(e.message,e.code);case`ResponseException`:return new re(e.message,e.status,e.missing);case`UnknownErrorException`:return new te(e.message,e.details)}return new te(e.message,e.toString())}class Dt{#e=new AbortController;constructor(e,t,n){this.sourceName=e;this.targetName=t;this.comObj=n;this.callbackId=1;this.streamId=1;this.streamSinks=Object.create(null);this.streamControllers=Object.create(null);this.callbackCapabilities=Object.create(null);this.actionHandler=Object.create(null);n.addEventListener(`message`,this.#t.bind(this),{signal:this.#e.signal})}#t({data:e}){if(e.targetName!==this.sourceName)return;if(e.stream){this.#r(e);return}if(e.callback){let t=e.callbackId,n=this.callbackCapabilities[t];if(!n)throw Error(`Cannot resolve callback ${t}`);delete this.callbackCapabilities[t];if(e.callback===1)n.resolve(e.data);else{if(e.callback!==2)throw Error(`Unexpected callback case`);n.reject(G(e.reason))}return}let t=this.actionHandler[e.action];if(!t)throw Error(`Unknown action from worker: ${e.action}`);if(e.callbackId){let n=this.sourceName,r=e.sourceName,i=this.comObj;Promise.try(t,e.data).then(function(t){i.postMessage({sourceName:n,targetName:r,callback:1,callbackId:e.callbackId,data:t})},function(t){i.postMessage({sourceName:n,targetName:r,callback:2,callbackId:e.callbackId,reason:G(t)})});return}e.streamId?this.#n(e):t(e.data)}on(e,t){let n=this.actionHandler;if(n[e])throw Error(`There is already an actionName called "${e}"`);n[e]=t}send(e,t,n){this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:e,data:t},n)}sendWithPromise(e,t,n){let r=this.callbackId++,i=Promise.withResolvers();this.callbackCapabilities[r]=i;try{this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:e,callbackId:r,data:t},n)}catch(e){i.reject(e)}return i.promise}sendWithStream(e,t,n,r){let i=this.streamId++,a=this.sourceName,o=this.targetName,s=this.comObj;return new ReadableStream({start:n=>{let c=Promise.withResolvers();this.streamControllers[i]={controller:n,startCall:c,pullCall:null,cancelCall:null,isClosed:!1};s.postMessage({sourceName:a,targetName:o,action:e,streamId:i,data:t,desiredSize:n.desiredSize},r);return c.promise},pull:e=>{let t=Promise.withResolvers();this.streamControllers[i].pullCall=t;s.postMessage({sourceName:a,targetName:o,stream:6,streamId:i,desiredSize:e.desiredSize});return t.promise},cancel:e=>{O(e instanceof Error,`cancel must have a valid reason`);let t=Promise.withResolvers();this.streamControllers[i].cancelCall=t;this.streamControllers[i].isClosed=!0;s.postMessage({sourceName:a,targetName:o,stream:1,streamId:i,reason:G(e)});return t.promise}},n)}#n(e){let t=e.streamId,n=this.sourceName,r=e.sourceName,i=this.comObj,a=this,o=this.actionHandler[e.action],s={enqueue(e,a=1,o){if(this.isCancelled)return;let s=this.desiredSize;this.desiredSize-=a;if(s>0&&this.desiredSize<=0){this.sinkCapability=Promise.withResolvers();this.ready=this.sinkCapability.promise}i.postMessage({sourceName:n,targetName:r,stream:4,streamId:t,chunk:e},o)},close(){if(!this.isCancelled){this.isCancelled=!0;i.postMessage({sourceName:n,targetName:r,stream:3,streamId:t});delete a.streamSinks[t]}},error(e){O(e instanceof Error,`error must have a valid reason`);if(!this.isCancelled){this.isCancelled=!0;i.postMessage({sourceName:n,targetName:r,stream:5,streamId:t,reason:G(e)})}},sinkCapability:Promise.withResolvers(),onPull:null,onCancel:null,isCancelled:!1,desiredSize:e.desiredSize,ready:null};s.sinkCapability.resolve();s.ready=s.sinkCapability.promise;this.streamSinks[t]=s;Promise.try(o,e.data,s).then(function(){i.postMessage({sourceName:n,targetName:r,stream:8,streamId:t,success:!0})},function(e){i.postMessage({sourceName:n,targetName:r,stream:8,streamId:t,reason:G(e)})})}#r(e){let t=e.streamId,n=this.sourceName,r=e.sourceName,i=this.comObj,a=this.streamControllers[t],o=this.streamSinks[t];switch(e.stream){case 8:e.success?a.startCall.resolve():a.startCall.reject(G(e.reason));break;case 7:e.success?a.pullCall.resolve():a.pullCall.reject(G(e.reason));break;case 6:if(!o){i.postMessage({sourceName:n,targetName:r,stream:7,streamId:t,success:!0});break}o.desiredSize<=0&&e.desiredSize>0&&o.sinkCapability.resolve();o.desiredSize=e.desiredSize;Promise.try(o.onPull||Et).then(function(){i.postMessage({sourceName:n,targetName:r,stream:7,streamId:t,success:!0})},function(e){i.postMessage({sourceName:n,targetName:r,stream:7,streamId:t,reason:G(e)})});break;case 4:O(a,`enqueue should have stream controller`);if(a.isClosed)break;a.controller.enqueue(e.chunk);break;case 3:O(a,`close should have stream controller`);if(a.isClosed)break;a.isClosed=!0;a.controller.close();this.#i(a,t);break;case 5:O(a,`error should have stream controller`);a.controller.error(G(e.reason));this.#i(a,t);break;case 2:e.success?a.cancelCall.resolve():a.cancelCall.reject(G(e.reason));this.#i(a,t);break;case 1:if(!o)break;let s=G(e.reason);Promise.try(o.onCancel||Et,s).then(function(){i.postMessage({sourceName:n,targetName:r,stream:2,streamId:t,success:!0})},function(e){i.postMessage({sourceName:n,targetName:r,stream:2,streamId:t,reason:G(e)})});o.sinkCapability.reject(s);o.isCancelled=!0;delete this.streamSinks[t];break;default:throw Error(`Unexpected stream case`)}}async#i(e,t){await Promise.allSettled([e.startCall?.promise,e.pullCall?.promise,e.cancelCall?.promise]);delete this.streamControllers[t]}destroy(){this.#e?.abort();this.#e=null}}class Ot{#e=Object.freeze({cMapUrl:`CMap`,standardFontDataUrl:`font`,wasmUrl:`wasm`});constructor({cMapUrl:e=null,standardFontDataUrl:t=null,wasmUrl:n=null}){this.cMapUrl=e;this.standardFontDataUrl=t;this.wasmUrl=n}async fetch({kind:e,filename:t}){switch(e){case`cMapUrl`:case`standardFontDataUrl`:case`wasmUrl`:break;default:D(`Not implemented: ${e}`)}let n=this[e];if(!n)throw Error(`Ensure that the \`${e}\` API parameter is provided.`);let r=`${n}${t}`;return this._fetch(r,e).catch(t=>{throw Error(`Unable to load ${this.#e[e]} data at: ${r}`)})}async _fetch(e,t){D("Abstract method `_fetch` called.")}}class kt extends Ot{async _fetch(e,t){let n=await me(e,t!==`cMapUrl`||e.endsWith(`.bcmap`)?`bytes`:`text`);return n instanceof Uint8Array?n:oe(n)}}class At{#e=!1;constructor({enableHWA:e=!1}){this.#e=e}create(e,t){if(e<=0||t<=0)throw Error(`Invalid canvas size`);let n=this._createCanvas(e,t);return{canvas:n,context:n.getContext(`2d`,{willReadFrequently:!this.#e})}}reset({canvas:e},t,n){if(!e)throw Error(`Canvas is not specified`);if(t<=0||n<=0)throw Error(`Invalid canvas size`);e.width=t;e.height=n}destroy(e){let{canvas:t}=e;if(!t)throw Error(`Canvas is not specified`);t.width=t.height=0;e.canvas=null;e.context=null}_createCanvas(e,t){D("Abstract method `_createCanvas` called.")}}class jt extends At{constructor({ownerDocument:e=globalThis.document,enableHWA:t=!1}){super({enableHWA:t});this._document=e}_createCanvas(e,t){let n=this._document.createElement(`canvas`);n.width=e;n.height=t;return n}}class Mt{addFilter(e){return`none`}addHCMFilter(e,t){return`none`}addAlphaFilter(e){return`none`}addLuminosityFilter(e){return`none`}addKnockoutFilter(e=0){return`none`}addHighlightHCMFilter(e,t,n,r,i){return`none`}destroy(e=!1){}}class Nt extends Mt{#e;#t;#n;#r;#i;#a;#o=0;constructor({docId:e,ownerDocument:t=globalThis.document}){super();this.#r=e;this.#i=t}get#s(){return this.#t||=new Map}get#c(){return this.#a||=new Map}get#l(){if(!this.#n){let e=this.#i.createElement(`div`),{style:t}=e;t.visibility=`hidden`;t.contain=`strict`;t.width=t.height=0;t.position=`absolute`;t.top=t.left=0;t.zIndex=-1;let n=this.#i.createElementNS(I,`svg`);n.setAttribute(`width`,0);n.setAttribute(`height`,0);this.#n=this.#i.createElementNS(I,`defs`);e.append(n);n.append(this.#n);this.#i.body.append(e)}return this.#n}#u(e){if(e.length===1){let t=e[0],n=Array(256);for(let e=0;e<256;e++)n[e]=t[e]/255;let r=n.join(`,`);return[r,r,r]}let[t,n,r]=e,i=Array(256),a=Array(256),o=Array(256);for(let e=0;e<256;e++){i[e]=t[e]/255;a[e]=n[e]/255;o[e]=r[e]/255}return[i.join(`,`),a.join(`,`),o.join(`,`)]}#d(e){if(this.#e===void 0){this.#e=``;let e=this.#i.URL;e!==this.#i.baseURI&&(_e(e)?E(`#createUrl: ignore "data:"-URL for performance reasons.`):this.#e=A(e,``))}return`url(${this.#e}#${e})`}addFilter(e){if(!e)return`none`;let t=this.#s.get(e);if(t)return t;let[n,r,i]=this.#u(e),a=e.length===1?n:`${n}${r}${i}`;t=this.#s.get(a);if(t){this.#s.set(e,t);return t}let o=`g_${this.#r}_transfer_map_${this.#o++}`,s=this.#d(o);this.#s.set(e,s);this.#s.set(a,s);let c=this.#m(o);this.#g(n,r,i,c);return s}addHCMFilter(e,t){let n=`${e}-${t}`,r=`base`,i=this.#c.get(r);if(i?.key===n)return i.url;if(i){i.filter?.remove();i.key=n;i.url=`none`;i.filter=null}else{i={key:n,url:`none`,filter:null};this.#c.set(r,i)}if(!e||!t)return i.url;let a=this.#v(e);e=P.makeHexColor(...a);let o=this.#v(t);t=P.makeHexColor(...o);this.#l.style.color=``;if(e===`#000000`&&t===`#ffffff`||e===t)return i.url;let s=Array(256);for(let e=0;e<=255;e++){let t=e/255;s[e]=t<=.03928?t/12.92:((t+.055)/1.055)**2.4}let c=s.join(`,`),l=`g_${this.#r}_hcm_filter`,u=i.filter=this.#m(l);this.#g(c,c,c,u);this.#p(u);let d=(e,t)=>{let n=a[e]/255,r=o[e]/255,i=Array(t+1);for(let e=0;e<=t;e++)i[e]=n+e/t*(r-n);return i.join(`,`)};this.#g(d(0,5),d(1,5),d(2,5),u);i.url=this.#d(l);return i.url}addAlphaFilter(e){let t=this.#s.get(e);if(t)return t;let[n]=this.#u([e]),r=`alpha_${n}`;t=this.#s.get(r);if(t){this.#s.set(e,t);return t}let i=`g_${this.#r}_alpha_map_${this.#o++}`,a=this.#d(i);this.#s.set(e,a);this.#s.set(r,a);let o=this.#m(i);this.#_(n,o);return a}addLuminosityFilter(e){let t,n,r=this.#s.get(e||`luminosity`);if(r)return r;if(e){[t]=this.#u([e]);n=`luminosity_${t}`}else n=`luminosity`;r=this.#s.get(n);if(r){this.#s.set(e,r);return r}let i=`g_${this.#r}_luminosity_map_${this.#o++}`,a=this.#d(i);this.#s.set(e,a);this.#s.set(n,a);let o=this.#m(i);this.#f(o);e&&this.#_(t,o);return a}addKnockoutFilter(e=0){let t=e>0?Math.min(1/e,1e6):1e6,n=`knockout_${t}`,r=this.#s.get(n);if(r)return r;let i=`g_${this.#r}_knockout_filter_${this.#o++}`,a=this.#d(i);this.#s.set(n,a);let o=this.#m(i),s=this.#i.createElementNS(I,`feComponentTransfer`);o.append(s);let c=this.#i.createElementNS(I,`feFuncA`);c.setAttribute(`type`,`linear`);c.setAttribute(`slope`,`${t}`);c.setAttribute(`intercept`,`0`);s.append(c);return a}addHighlightHCMFilter(e,t,n,r,i){let a=`${t}-${n}-${r}-${i}`,o=this.#c.get(e);if(o?.key===a)return o.url;if(o){o.filter?.remove();o.key=a;o.url=`none`;o.filter=null}else{o={key:a,url:`none`,filter:null};this.#c.set(e,o)}if(!t||!n)return o.url;let[s,c]=[t,n].map(this.#v.bind(this)),l=Math.round(.2126*s[0]+.7152*s[1]+.0722*s[2]),u=Math.round(.2126*c[0]+.7152*c[1]+.0722*c[2]),[d,f]=[r,i].map(this.#v.bind(this));u<l&&([l,u,d,f]=[u,l,f,d]);this.#l.style.color=``;let p=(e,t,n)=>{let r=Array(256),i=(u-l)/n,a=e/255,o=(t-e)/(255*n),s=0;for(let e=0;e<=n;e++){let t=Math.round(l+e*i),n=a+e*o;for(let e=s;e<=t;e++)r[e]=n;s=t+1}for(let e=s;e<256;e++)r[e]=r[s-1];return r.join(`,`)},m=`g_${this.#r}_hcm_${e}_filter`,h=o.filter=this.#m(m);this.#p(h);this.#g(p(d[0],f[0],5),p(d[1],f[1],5),p(d[2],f[2],5),h);o.url=this.#d(m);return o.url}destroy(e=!1){if(!e||!this.#a?.size){this.#n?.parentNode.parentNode.remove();this.#n=null;this.#t?.clear();this.#t=null;this.#a?.clear();this.#a=null;this.#o=0}}#f(e){let t=this.#i.createElementNS(I,`feColorMatrix`);t.setAttribute(`type`,`matrix`);t.setAttribute(`values`,`0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.59 0.11 0 0`);e.append(t)}#p(e){let t=this.#i.createElementNS(I,`feColorMatrix`);t.setAttribute(`type`,`matrix`);t.setAttribute(`values`,`0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0`);e.append(t)}#m(e){let t=this.#i.createElementNS(I,`filter`);t.setAttribute(`color-interpolation-filters`,`sRGB`);t.setAttribute(`id`,e);this.#l.append(t);return t}#h(e,t,n){let r=this.#i.createElementNS(I,t);r.setAttribute(`type`,`discrete`);r.setAttribute(`tableValues`,n);e.append(r)}#g(e,t,n,r){let i=this.#i.createElementNS(I,`feComponentTransfer`);r.append(i);this.#h(i,`feFuncR`,e);this.#h(i,`feFuncG`,t);this.#h(i,`feFuncB`,n)}#_(e,t){let n=this.#i.createElementNS(I,`feComponentTransfer`);t.append(n);this.#h(n,`feFuncA`,e)}#v(e){this.#l.style.color=e;return Ce(getComputedStyle(this.#l).getPropertyValue(`color`))}}l&&E("Please use the `legacy` build in Node.js environments.");class Pt extends Mt{}class Ft extends At{_createCanvas(e,t){return process.getBuiltinModule(`module`).createRequire(import.meta.url)(`@napi-rs/canvas`).createCanvas(e,t)}}class It extends Ot{async _fetch(e,t){return async function(e){let t=await process.getBuiltinModule(`fs/promises`).readFile(e);return new Uint8Array(t)}(e)}}const Lt=new class{#e=null;#t=null;#n=null;#r=null;async#i(){if(!globalThis.navigator?.gpu)return!1;try{let e=await navigator.gpu.requestAdapter();if(!e)return!1;this.#r=navigator.gpu.getPreferredCanvasFormat();this.#t=await e.requestDevice();return!0}catch{return!1}}init(){return this.#e||=this.#i()}get isReady(){return this.#t!==null}loadMeshShader(){if(!this.#t||this.#n)return;let e=this.#t.createShaderModule({code:`
|
|
3
3
|
struct Uniforms {
|
|
4
4
|
offsetX : f32,
|
|
5
5
|
offsetY : f32,
|
|
@@ -42,16 +42,16 @@ fn vs_main(in : VertexInput) -> VertexOutput {
|
|
|
42
42
|
fn fs_main(in : VertexOutput) -> @location(0) vec4<f32> {
|
|
43
43
|
return vec4<f32>(in.color, 1.0);
|
|
44
44
|
}
|
|
45
|
-
`});this.#n=this.#t.createRenderPipeline({layout:`auto`,vertex:{module:e,entryPoint:`vs_main`,buffers:[{arrayStride:8,attributes:[{shaderLocation:0,offset:0,format:`float32x2`}]},{arrayStride:4,attributes:[{shaderLocation:1,offset:0,format:`unorm8x4`}]}]},fragment:{module:e,entryPoint:`fs_main`,targets:[{format:this.#r}]},primitive:{topology:`triangle-list`}})}draw(e,t,n,r,i,a,o,s){this.loadMeshShader();let c=this.#t,{offsetX:l,offsetY:u,scaleX:d,scaleY:f}=r,p=c.createBuffer({size:Math.max(e.byteLength,4),usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST});e.byteLength>0&&c.queue.writeBuffer(p,0,e);let m=c.createBuffer({size:Math.max(t.byteLength,4),usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST});t.byteLength>0&&c.queue.writeBuffer(m,0,t);let h=c.createBuffer({size:32,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});c.queue.writeBuffer(h,0,new Float32Array([l,u,d,f,a,o,s,0]));let g=c.createBindGroup({layout:this.#n.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:h}}]}),_=new OffscreenCanvas(a,o),v=_.getContext(`webgpu`);v.configure({device:c,format:this.#r,alphaMode:i?`opaque`:`premultiplied`});let y=i?{r:i[0]/255,g:i[1]/255,b:i[2]/255,a:1}:{r:0,g:0,b:0,a:0},b=c.createCommandEncoder(),x=b.beginRenderPass({colorAttachments:[{view:v.getCurrentTexture().createView(),clearValue:y,loadOp:`clear`,storeOp:`store`}]});if(n>0){x.setPipeline(this.#n);x.setBindGroup(0,g);x.setVertexBuffer(0,p);x.setVertexBuffer(1,m);x.draw(n)}x.end();c.queue.submit([b.finish()]);p.destroy();m.destroy();h.destroy();return _.transferToImageBitmap()}},Vt=`Fill`,Ht=`Stroke`,Ut=`Shading`;function Wt(e,t){if(!t)return;let n=t[2]-t[0],r=t[3]-t[1],i=new Path2D;i.rect(t[0],t[1],n,r);e.clip(i)}class Gt{isModifyingCurrentTransform(){return!1}getPattern(){k("Abstract method `getPattern` called.")}}class Kt extends Gt{constructor(e){super();this._type=e[1];this._bbox=e[2];this._colorStops=e[3];this._p0=e[4];this._p1=e[5];this._r0=e[6];this._r1=e[7];this.matrix=null}isOriginBased(){return this._p0[0]===0&&this._p0[1]===0&&(!this.isRadial()||this._p1[0]===0&&this._p1[1]===0)}isRadial(){return this._type===`radial`}areConic(){if(!this.isRadial())return!1;let e=Math.hypot(this._p0[0]-this._p1[0],this._p0[1]-this._p1[1]);return e+this._r1>this._r0&&e+this._r0>this._r1}_createGradient(e,t=null){let n,r=this._p0,i=this._p1;if(t){r=r.slice();i=i.slice();P.applyTransform(r,t);P.applyTransform(i,t)}if(this._type===`axial`)n=e.createLinearGradient(r[0],r[1],i[0],i[1]);else if(this._type===`radial`){let a=this._r0,o=this._r1;if(t){let e=new Float32Array(2);P.singularValueDecompose2dScale(t,e);a*=e[0];o*=e[0]}n=e.createRadialGradient(r[0],r[1],a,i[0],i[1],o)}for(let e of this._colorStops)n.addColorStop(e[0],e[1]);return n}_createReversedGradient(e,t=null){let n=this._p1,r=this._p0;if(t){n=n.slice();r=r.slice();P.applyTransform(n,t);P.applyTransform(r,t)}let i=this._r1,a=this._r0;if(t){let e=new Float32Array(2);P.singularValueDecompose2dScale(t,e);i*=e[0];a*=e[0]}let o=e.createRadialGradient(n[0],n[1],i,r[0],r[1],a),s=this._colorStops.map(([e,t])=>[1-e,t]).reverse();for(let[e,t]of s)o.addColorStop(e,t);return o}getPattern(e,t,n,r){let i;if(r===Ht||r===Vt){if(this.isOriginBased()){let r=P.transform(n,t.baseTransform);this.matrix&&(r=P.transform(r,this.matrix));let i=.001,a=Math.hypot(r[0],r[1]),o=Math.hypot(r[2],r[3]),s=(r[0]*r[2]+r[1]*r[3])/(a*o);if(Math.abs(s)<i){if(!this.isRadial())return this._createGradient(e,r);if(Math.abs(a-o)<i)return this._createGradient(e,r)}}let a=t.current.getClippedPathBoundingBox(r,z(e))||[0,0,0,0],o=Math.ceil(a[2]-a[0])||1,s=Math.ceil(a[3]-a[1])||1,c=t.canvasFactory.create(o,s),l=c.context;l.clearRect(0,0,l.canvas.width,l.canvas.height);l.beginPath();l.rect(0,0,l.canvas.width,l.canvas.height);l.translate(-a[0],-a[1]);n=P.transform(n,[1,0,0,1,a[0],a[1]]);l.transform(...t.baseTransform);this.matrix&&l.transform(...this.matrix);Wt(l,this._bbox);if(this.areConic()){l.fillStyle=this._createReversedGradient(l);l.fill()}l.fillStyle=this._createGradient(l);l.fill();i=e.createPattern(c.canvas,`no-repeat`);t.canvasFactory.destroy(c);let u=new DOMMatrix(n);i.setTransform(u)}else{if(this.areConic()){e.save();Wt(e,this._bbox);e.fillStyle=this._createReversedGradient(e);e.fillRect(-1e10,-1e10,2e10,2e10);e.restore()}Wt(e,this._bbox);i=this._createGradient(e)}return i}}function qt(e,t,n,r,i,a,o,s){let c=t.coords,l=t.colors,u=e.data,d=4*e.width,f;if(c[2*n+1]>c[2*r+1]){f=n;n=r;r=f;f=a;a=o;o=f}if(c[2*r+1]>c[2*i+1]){f=r;r=i;i=f;f=o;o=s;s=f}if(c[2*n+1]>c[2*r+1]){f=n;n=r;r=f;f=a;a=o;o=f}let p=(c[2*n]+t.offsetX)*t.scaleX,m=(c[2*n+1]+t.offsetY)*t.scaleY,h=(c[2*r]+t.offsetX)*t.scaleX,g=(c[2*r+1]+t.offsetY)*t.scaleY,_=(c[2*i]+t.offsetX)*t.scaleX,v=(c[2*i+1]+t.offsetY)*t.scaleY;if(m>=v)return;let y=l[4*a],b=l[4*a+1],x=l[4*a+2],S=l[4*o],C=l[4*o+1],w=l[4*o+2],T=l[4*s],E=l[4*s+1],D=l[4*s+2],O=Math.round(m),k=Math.round(v),A,ee,te,j,M,ne,re,ie;for(let e=O;e<=k;e++){if(e<g){let t=e<m?0:(m-e)/(m-g);A=p-(p-h)*t;ee=y-(y-S)*t;te=b-(b-C)*t;j=x-(x-w)*t}else{let t;t=e>v?1:g===v?0:(g-e)/(g-v);A=h-(h-_)*t;ee=S-(S-T)*t;te=C-(C-E)*t;j=w-(w-D)*t}let t;t=e<m?0:e>v?1:(m-e)/(m-v);M=p-(p-_)*t;ne=y-(y-T)*t;re=b-(b-E)*t;ie=x-(x-D)*t;let n=Math.round(Math.min(A,M)),r=Math.round(Math.max(A,M)),i=d*e+4*n;for(let e=n;e<=r;e++){t=(A-e)/(A-M);t<0?t=0:t>1&&(t=1);u[i++]=ee-(ee-ne)*t|0;u[i++]=te-(te-re)*t|0;u[i++]=j-(j-ie)*t|0;u[i++]=255}}}class Jt extends Gt{constructor(e){super();this._posData=e[2];this._colData=e[3];this._vertexCount=e[4];this._bounds=e[5];this._bbox=e[6];this._background=e[7];this.matrix=null;(function(){Bt.loadMeshShader()})()}_createMeshCanvas(e,t,n){let r=Math.floor(this._bounds[0]),i=Math.floor(this._bounds[1]),a=Math.ceil(this._bounds[2])-r,o=Math.ceil(this._bounds[3])-i,s=Math.min(Math.ceil(Math.abs(a*e[0]*1.1)),3e3)||1,c=Math.min(Math.ceil(Math.abs(o*e[1]*1.1)),3e3)||1,l=a?a/s:1,u=o?o/c:1,d={coords:this._posData,colors:this._colData,offsetX:-r,offsetY:-i,scaleX:1/l,scaleY:1/u},f=s+4,p=c+4,m=n.create(f,p);if(function(){return Bt.isReady}()&&this._vertexCount>48)m.context.drawImage(function(e,t,n,r,i,a,o,s){return Bt.draw(e,t,n,r,i,a,o,s)}(this._posData,this._colData,this._vertexCount,d,t,f,p,2),0,0);else{let e=m.context.createImageData(s,c);if(t){let n=e.data;for(let e=0,r=n.length;e<r;e+=4){n[e]=t[0];n[e+1]=t[1];n[e+2]=t[2];n[e+3]=255}}for(let t=0,n=this._vertexCount;t<n;t+=3)qt(e,d,t,t+1,t+2,t,t+1,t+2);m.context.putImageData(e,2,2)}return{canvas:m.canvas,offsetX:r-2*l,offsetY:i-2*u,scaleX:l,scaleY:u}}isModifyingCurrentTransform(){return!0}getPattern(e,t,n,r){Wt(e,this._bbox);let i=new Float32Array(2);if(r===Ut)P.singularValueDecompose2dScale(z(e),i);else if(this.matrix){P.singularValueDecompose2dScale(this.matrix,i);let[e,n]=i;P.singularValueDecompose2dScale(t.baseTransform,i);i[0]*=e;i[1]*=n}else P.singularValueDecompose2dScale(t.baseTransform,i);let a=this._createMeshCanvas(i,r===Ut?null:this._background,t.canvasFactory);if(r!==Ut){e.setTransform(...t.baseTransform);this.matrix&&e.transform(...this.matrix)}e.translate(a.offsetX,a.offsetY);e.scale(a.scaleX,a.scaleY);let o=e.createPattern(a.canvas,`no-repeat`);t.canvasFactory.destroy(a);return o}}class Yt extends Gt{getPattern(){return`hotpink`}}class Xt{static MAX_PATTERN_SIZE=3e3;constructor(e,t,n,r){this.color=e[1];this.operatorList=e[2];this.matrix=e[3];this.bbox=e[4];this.xstep=e[5];this.ystep=e[6];this.paintType=e[7];this.tilingType=e[8];this.needsIsolation=e[9]??!0;this.ctx=t;this.canvasGraphicsFactory=n;this.baseTransform=r;this.patternBaseMatrix=this.matrix?P.transform(r,this.matrix):r}canSkipPatternCanvas([e,t,n,r]){let[i,a,o,s]=this.bbox,c=Math.abs(this.xstep),l=Math.abs(this.ystep);if(e>c+1e-6||t>l+1e-6)return null;let u=Math.floor((n-o)/c)+1,d=Math.ceil((n+e-i)/c)-1,f=Math.floor((r-s)/l)+1,p=Math.ceil((r+t-a)/l)-1;return d<=u&&p<=f?[u,f]:null}updatePatternDims(e,t){let n=P.inverseTransform(this.patternBaseMatrix),r=[e[0],e[1]],i=[e[2],e[3]];P.applyTransform(r,n);P.applyTransform(i,n);t[0]=Math.abs(i[0]-r[0]);t[1]=Math.abs(i[1]-r[1]);t[2]=Math.min(r[0],i[0]);t[3]=Math.min(r[1],i[1])}_renderTileCanvas(e,t,n,r){let[i,a,o,s]=this.bbox,c=e.canvasFactory.create(n.size,r.size),l=c.context,u=this.canvasGraphicsFactory.createCanvasGraphics(l,t);u.groupLevel=e.groupLevel;this.setFillAndStrokeStyleToContext(u,this.paintType,this.color);l.translate(-n.scale*i,-r.scale*a);u.transform(0,n.scale,0,0,r.scale,0,0);l.save();u.dependencyTracker?.save();this.clipBbox(u,i,a,o,s);u.baseTransform=z(u.ctx);u.executeOperatorList(this.operatorList);u.endDrawing();u.dependencyTracker?.restore();l.restore();return c}_getCombinedScales(){let e=new Float32Array(2);P.singularValueDecompose2dScale(this.matrix,e);let[t,n]=e;P.singularValueDecompose2dScale(this.baseTransform,e);return[t*e[0],n*e[1]]}drawPattern(e,t,n=!1,[r,i],a){let[o,s,c,l]=this.bbox,u=e.dependencyTracker;u&&(e.dependencyTracker=new st(u,a));e.save();n?e.ctx.clip(t,`evenodd`):e.ctx.clip(t);e.ctx.setTransform(...this.patternBaseMatrix);e.ctx.translate(r*this.xstep,i*this.ystep);if(this.needsIsolation||e.ctx.globalAlpha!==1||e.ctx.globalCompositeOperation!==`source-over`||e.inSMaskMode){let t=c-o,n=l-s,[r,i]=this._getCombinedScales(),u=this.getSizeAndScale(t,this.ctx.canvas.width,r),d=this.getSizeAndScale(n,this.ctx.canvas.height,i),f=this._renderTileCanvas(e,a,u,d);e.ctx.drawImage(f.canvas,o,s,t,n);e.canvasFactory.destroy(f)}else{this.setFillAndStrokeStyleToContext(e,this.paintType,this.color);this.clipBbox(e,o,s,c,l);e.baseTransformStack.push(e.baseTransform);e.baseTransform=z(e.ctx);e.executeOperatorList(this.operatorList);e.baseTransform=e.baseTransformStack.pop()}e.restore();u&&(e.dependencyTracker=u)}createPatternCanvas(e,t){let[n,r,i,a]=this.bbox,o=i-n,s=a-r,{xstep:c,ystep:l}=this;c=Math.abs(c);l=Math.abs(l);D(`TilingType: `+this.tilingType);let[u,d]=this._getCombinedScales(),f=o,p=s,m=!1,h=!1;Math.ceil(c*u)>=Math.ceil(o*u)?f=c:m=!0;Math.ceil(l*d)>=Math.ceil(s*d)?p=l:h=!0;let g=this.getSizeAndScale(f,this.ctx.canvas.width,u),_=this.getSizeAndScale(p,this.ctx.canvas.height,d),v=this._renderTileCanvas(e,t,g,_);if(m||h){let t=v.canvas;m&&(f=c);h&&(p=l);let i=this.getSizeAndScale(f,this.ctx.canvas.width,u),a=this.getSizeAndScale(p,this.ctx.canvas.height,d),g=i.size,_=a.size,y=e.canvasFactory.create(g,_),b=y.context,x=m?Math.floor(o/c):0,S=h?Math.floor(s/l):0;for(let e=0;e<=x;e++)for(let n=0;n<=S;n++)b.drawImage(t,g*e,_*n,g,_,0,0,g,_);e.canvasFactory.destroy(v);return{canvas:y.canvas,canvasEntry:y,scaleX:i.scale,scaleY:a.scale,offsetX:n,offsetY:r}}return{canvas:v.canvas,canvasEntry:v,scaleX:g.scale,scaleY:_.scale,offsetX:n,offsetY:r}}getSizeAndScale(e,t,n){let r=Math.max(Xt.MAX_PATTERN_SIZE,t),i=Math.ceil(e*n);i>=r?i=r:n=i/e;return{scale:n,size:i}}clipBbox(e,t,n,r,i){let a=r-t,o=i-n,s=new Path2D;s.rect(t,n,a,o);P.axialAlignedBoundingBox([t,n,r,i],z(e.ctx),e.current.minMax);e.ctx.clip(s);e.current.updateClipFromPath()}setFillAndStrokeStyleToContext(e,t,n){let r=e.ctx,i=e.current;i.patternFill=i.patternStroke=!1;switch(t){case 1:let{fillStyle:e,strokeStyle:a}=this.ctx;r.fillStyle=i.fillColor=e;r.strokeStyle=i.strokeColor=a;break;case 2:r.fillStyle=r.strokeStyle=n;i.fillColor=i.strokeColor=n;break;default:throw new oe(`Unsupported paint type: ${t}`)}}isModifyingCurrentTransform(){return!1}getPattern(e,t,n,r,i){let a=r===Ut?n:P.transform(n,this.patternBaseMatrix),o=this.createPatternCanvas(t,i),s=new DOMMatrix(a);s=s.translate(o.offsetX,o.offsetY);s=s.scale(1/o.scaleX,1/o.scaleY);let c=e.createPattern(o.canvas,`repeat`);t.canvasFactory.destroy(o.canvasEntry);c.setTransform(s);return c}}function Zt({src:e,srcPos:t=0,dest:n,width:r,height:i,nonBlackColor:a=4294967295,inverseDecode:o=!1}){let s=N.isLittleEndian?4278190080:255,[c,l]=o?[a,s]:[s,a],u=r>>3,d=7&r,f=c^l,p=e.length;n=new Uint32Array(n.buffer);let m=0;for(let r=0;r<i;++r){for(let r=t+u;t<r;++t,m+=8){let r=e[t];n[m]=c^-(r>>7&1)&f;n[m+1]=c^-(r>>6&1)&f;n[m+2]=c^-(r>>5&1)&f;n[m+3]=c^-(r>>4&1)&f;n[m+4]=c^-(r>>3&1)&f;n[m+5]=c^-(r>>2&1)&f;n[m+6]=c^-(r>>1&1)&f;n[m+7]=c^-(1&r)&f}if(d===0)continue;let r=t<p?e[t++]:255;for(let e=0;e<d;++e,++m)n[m]=c^-(r>>7-e&1)&f}return{srcPos:t,destPos:m}}const Qt=new DOMMatrix,G=new Float32Array(2);function $t(e,t){if(e._removeMirroring)throw Error(`Context is already forwarding operations.`);let n=new Map;for(let r of[`save`,`restore`,`rotate`,`scale`,`translate`,`transform`,`setTransform`,`resetTransform`,`clip`,`moveTo`,`lineTo`,`bezierCurveTo`,`quadraticCurveTo`,`arc`,`arcTo`,`ellipse`,`rect`,`roundRect`,`closePath`,`beginPath`]){let i=e[r];if(typeof i==`function`&&typeof t[r]==`function`){n.set(r,i);e[r]=function(...e){t[r](...e);return i.apply(this,e)}}}e._removeMirroring=()=>{for(let[t,r]of n)e[t]=r;delete e._removeMirroring}}function en(e,t,n,r,i,a,o,s,c,l){let[u,d,f,p,m,h]=z(e);if(d===0&&f===0){let g=o*u+m,_=Math.round(g),v=s*p+h,y=Math.round(v),b=(o+c)*u+m,x=Math.abs(Math.round(b)-_)||1,S=(s+l)*p+h,C=Math.abs(Math.round(S)-y)||1;e.setTransform(Math.sign(u),0,0,Math.sign(p),_,y);e.drawImage(t,n,r,i,a,0,0,x,C);e.setTransform(u,d,f,p,m,h);return[x,C]}if(u===0&&p===0){let g=s*f+m,_=Math.round(g),v=o*d+h,y=Math.round(v),b=(s+l)*f+m,x=Math.abs(Math.round(b)-_)||1,S=(o+c)*d+h,C=Math.abs(Math.round(S)-y)||1;e.setTransform(0,Math.sign(d),Math.sign(f),0,_,y);e.drawImage(t,n,r,i,a,0,0,C,x);e.setTransform(u,d,f,p,m,h);return[C,x]}e.drawImage(t,n,r,i,a,o,s,c,l);return[Math.hypot(u,d)*c,Math.hypot(f,p)*l]}class tn{alphaIsShape=!1;fontSize=0;fontSizeScale=1;textMatrix=null;textMatrixScale=1;fontMatrix=m;leading=0;x=0;y=0;lineX=0;lineY=0;charSpacing=0;wordSpacing=0;textHScale=1;textRenderingMode=0;textRise=0;fillColor=`#000000`;strokeColor=`#000000`;tilingPatternDims=null;patternFill=!1;patternStroke=!1;fillAlpha=1;strokeAlpha=1;lineWidth=1;activeSMask=null;transferMaps=`none`;minMax=p.slice();constructor(e,t){this.clipBox=new Float32Array([0,0,e,t])}clone(){let e=Object.create(this);e.clipBox=this.clipBox.slice();e.minMax=this.minMax.slice();e.tilingPatternDims=this.tilingPatternDims?.slice();return e}getPathBoundingBox(e=Vt,t=null){let n=this.minMax.slice();if(e===Ht){t||k(`Stroke bounding box must include transform.`);P.singularValueDecompose2dScale(t,G);let e=G[0]*this.lineWidth/2,r=G[1]*this.lineWidth/2;n[0]-=e;n[1]-=r;n[2]+=e;n[3]+=r}return n}updateClipFromPath(){let e=P.intersect(this.clipBox,this.getPathBoundingBox());this.startNewPathAndClipBox(e||[0,0,0,0])}isEmptyClip(){return this.minMax[0]===1/0}startNewPathAndClipBox(e){this.clipBox.set(e,0);this.minMax.set(p,0)}getClippedPathBoundingBox(e=Vt,t=null){return P.intersect(this.clipBox,this.getPathBoundingBox(e,t))}}function nn(e,t){if(t instanceof ImageData){e.putImageData(t,0,0);return}let n=t.height,r=t.width,i=n%16,a=(n-i)/16,o=i===0?a:a+1,s=e.createImageData(r,16),c,l=0,u=t.data,d=s.data,f,p,m,h;if(t.kind===x.GRAYSCALE_1BPP){let t=u.byteLength,n=new Uint32Array(d.buffer,0,d.byteLength>>2),h=n.length,g=r+7>>3,_=4294967295,v=N.isLittleEndian?4278190080:255;for(f=0;f<o;f++){m=f<a?16:i;c=0;for(p=0;p<m;p++){let e=t-l,i=0,a=e>g?r:8*e-7,o=-8&a,s=0,d=0;for(;i<o;i+=8){d=u[l++];n[c++]=128&d?_:v;n[c++]=64&d?_:v;n[c++]=32&d?_:v;n[c++]=16&d?_:v;n[c++]=8&d?_:v;n[c++]=4&d?_:v;n[c++]=2&d?_:v;n[c++]=1&d?_:v}for(;i<a;i++){if(s===0){d=u[l++];s=128}n[c++]=d&s?_:v;s>>=1}}for(;c<h;)n[c++]=0;e.putImageData(s,0,f*16)}}else if(t.kind===x.RGBA_32BPP){p=0;h=r*16*4;for(f=0;f<a;f++){d.set(u.subarray(l,l+h));l+=h;e.putImageData(s,0,p);p+=16}if(f<o){h=r*i*4;d.set(u.subarray(l,l+h));e.putImageData(s,0,p)}}else{if(t.kind!==x.RGB_24BPP)throw Error(`bad image kind: ${t.kind}`);m=16;h=r*m;for(f=0;f<o;f++){if(f>=a){m=i;h=r*m}c=0;for(p=h;p--;){d[c++]=u[l++];d[c++]=u[l++];d[c++]=u[l++];d[c++]=255}e.putImageData(s,0,f*16)}}}function rn(e,t){if(t.bitmap){e.drawImage(t.bitmap,0,0);return}let n=t.height,r=t.width,i=n%16,a=(n-i)/16,o=i===0?a:a+1,s=e.createImageData(r,16),c=0,l=t.data,u=s.data;for(let t=0;t<o;t++){let n=t<a?16:i;({srcPos:c}=Zt({src:l,srcPos:c,dest:u,width:r,height:n,nonBlackColor:0}));e.putImageData(s,0,t*16)}}function an(e,t){for(let n of[`strokeStyle`,`fillStyle`,`fillRule`,`globalAlpha`,`lineWidth`,`lineCap`,`lineJoin`,`miterLimit`,`globalCompositeOperation`,`font`,`filter`])e[n]!==void 0&&(t[n]=e[n]);if(e.setLineDash!==void 0){t.setLineDash(e.getLineDash());t.lineDashOffset=e.lineDashOffset}}function on(e){e.strokeStyle=e.fillStyle=`#000000`;e.fillRule=`nonzero`;e.globalAlpha=1;e.lineWidth=1;e.lineCap=`butt`;e.lineJoin=`miter`;e.miterLimit=10;e.globalCompositeOperation=`source-over`;e.font=`10px sans-serif`;if(e.setLineDash!==void 0){e.setLineDash([]);e.lineDashOffset=0}let{filter:t}=e;t!==`none`&&t!==``&&(e.filter=`none`)}function sn(e,t){if(t)return!0;P.singularValueDecompose2dScale(e,G);let n=Math.fround(Oe.pixelRatio*he.PDF_TO_CSS_UNITS);return G[0]<=n&&G[1]<=n}const cn=[`butt`,`round`,`square`],ln=[`miter`,`round`,`bevel`],un={},dn={};class fn{#e=0;#t=0;#n=null;#r=null;#i=null;#a=null;#o=1;#s;#c=null;#l=[];constructor(e,t,n,r,i,{optionalContentConfig:a,markedContentStack:o=null},s,c,l,u){this.ctx=e;this.current=new tn(this.ctx.canvas.width,this.ctx.canvas.height);this.stateStack=[];this.pendingClip=null;this.pendingEOFill=!1;this.commonObjs=t;this.objs=n;this.canvasFactory=r;this.filterFactory=i;this.groupStack=[];this.baseTransform=null;this.baseTransformStack=[];this.groupLevel=0;this.smaskStack=[];this.tempSMask=null;this.smaskGroupCanvases=[];this.smaskPreparedEntry=null;this.smaskPreparedFor=null;this.smaskPreparedOffsetX=0;this.smaskPreparedOffsetY=0;this.smaskPreparedOOBAlpha=null;this.suspendedCtx=null;this.contentVisible=!0;this.markedContentStack=o||[];this.optionalContentConfig=a;this.cachedPatterns=new Map;this.annotationCanvasMap=s;this.viewportScale=1;this.outputScaleX=1;this.outputScaleY=1;this.pageColors=c;this._cachedScaleForStroking=[-1,0];this._cachedGetSinglePixelWidth=null;this._cachedBitmapsMap=new Map;this.dependencyTracker=l??null;this.imagesTracker=u??null}getObject(e,t,n=null){if(typeof t==`string`){this.dependencyTracker?.recordNamedDependency(e,t);return t.startsWith(`g_`)?this.commonObjs.get(t):this.objs.get(t)}return n}beginDrawing({transform:e,viewport:t,transparency:n=!1,background:r=null}){let i=this.ctx.canvas.width,a=this.ctx.canvas.height,o=this.ctx.fillStyle;this.ctx.fillStyle=r||`#ffffff`;this.ctx.fillRect(0,0,i,a);this.ctx.fillStyle=o;if(n){let e=this.transparentCanvasEntry=this.canvasFactory.create(i,a);this.compositeCtx=this.ctx;({canvas:this.transparentCanvas,context:this.ctx}=e);this.ctx.save();this.ctx.transform(...z(this.compositeCtx))}this.ctx.save();on(this.ctx);if(e){this.ctx.transform(...e);this.outputScaleX=e[0];this.outputScaleY=e[3]}this.ctx.transform(...t.transform);this.viewportScale=t.scale;this.baseTransform=z(this.ctx)}executeOperatorList(e,t,n,r,i,a=null,o=null){let s=Number.isFinite(a?.executionTime)&&a.executionTime>0?a.executionTime:15,c=Number.isInteger(a?.executionSteps)&&a.executionSteps>0?a.executionSteps:10,l=e.argsArray,u=e.fnArray,d=t||0,f=l.length;if(f===d)return d;let p=f-d>c&&typeof n==`function`,m=p?performance.now()+s:0,h=0,g=this.commonObjs,_=this.objs,v,y;for(;;){if(r!==void 0){if(d===r.nextBreakPoint){r.breakIt(d,n);return d}if(r.shouldSkip(d)){if(++d===f)return d;continue}}if(!i||i(d)){v=u[d];y=l[d]??null;if(v!==C.dependency)y===null?this[v](d):this[v](d,...y);else for(let e of y){this.dependencyTracker?.recordNamedData(e,d);let t=e.startsWith(`g_`)?g:_;if(!t.has(e)){t.get(e,n);return d}}}d++;if(d===f)return d;if(p&&++h>c){let e=performance.now()>m;if(typeof o==`function`&&o()||e){n();return d}h=0}}}#u(){for(;this.stateStack.length||this.inSMaskMode;)this.restore();this.current.activeSMask=null;this.ctx.restore();if(this.transparentCanvas){this.ctx=this.compositeCtx;this.ctx.save();this.ctx.setTransform(1,0,0,1,0,0);this.ctx.drawImage(this.transparentCanvas,0,0);this.ctx.restore();this.canvasFactory.destroy(this.transparentCanvasEntry);this.transparentCanvas=null;this.transparentCanvasEntry=null}}endDrawing(){this.#u();for(let e of this.smaskGroupCanvases)this.canvasFactory.destroy(e);this.smaskGroupCanvases.length=0;this._clearPreparedSMask();this.tempSMask=null;this.smaskStack.length=0;for(let e of this.#l)this.#v(e);this.#l.length=0;this.#n=null;this.#r=null;this.#i=null;this.#a=null;this.#o=1;this.#c=null;this.#t=0;this.#e=0;this.cachedPatterns.clear();for(let e of this._cachedBitmapsMap.values()){for(let t of e.values())typeof HTMLCanvasElement<`u`&&t instanceof HTMLCanvasElement&&(t.width=t.height=0);e.clear()}this._cachedBitmapsMap.clear();this.#d()}#d(){if(this.pageColors){let e=this.filterFactory.addHCMFilter(this.pageColors.foreground,this.pageColors.background);if(e!==`none`){let t=this.ctx.filter;this.ctx.filter=e;this.ctx.drawImage(this.ctx.canvas,0,0);this.ctx.filter=t}}}_scaleImage(e,t){let n=e.width??e.displayWidth,r=e.height??e.displayHeight,i=[],a=Math.max(Math.hypot(t[0],t[1]),1),o=Math.max(Math.hypot(t[2],t[3]),1),s=n,c=r;for(;a>2&&s>1||o>2&&c>1;){let e=s,t=c;if(a>2&&s>1){e=Math.ceil(s/2);a/=s/e}if(o>2&&c>1){t=Math.ceil(c/2);o/=c/t}i.push({newWidth:e,newHeight:t});s=e;c=t}if(i.length===0)return{img:e,paintWidth:n,paintHeight:r,tmpCanvas:null};if(i.length===1){let{newWidth:t,newHeight:a}=i[0],o=this.canvasFactory.create(t,a);o.context.drawImage(e,0,0,n,r,0,0,t,a);return{img:o.canvas,paintWidth:t,paintHeight:a,tmpCanvas:o}}let l=this.canvasFactory.create(1,1),u=this.canvasFactory.create(1,1),d=n,f=r,p=e;for(let{newWidth:e,newHeight:t}of i){this.canvasFactory.reset(u,e,t);u.context.drawImage(p,0,0,d,f,0,0,e,t);[l,u]=[u,l];p=l.canvas;d=e;f=t}this.canvasFactory.destroy(u);return{img:l.canvas,paintWidth:d,paintHeight:f,tmpCanvas:l}}_createMaskCanvas(e,t){let n=this.ctx,{width:r,height:i}=t,a=this.current.fillColor,o=this.current.patternFill,s=z(n),c,l,u,d;if((t.bitmap||t.data)&&t.count>1){let n=t.bitmap||t.data.buffer;l=JSON.stringify(o?s:[s.slice(0,4),a]);c=this._cachedBitmapsMap.getOrInsertComputed(n,de);let r=c.get(l);if(r&&!o){let t=Math.round(Math.min(s[0],s[2])+s[4]),n=Math.round(Math.min(s[1],s[3])+s[5]);this.dependencyTracker?.recordDependencies(e,mt);return{canvas:r,offsetX:t,offsetY:n}}u=r}if(!u){d=this.canvasFactory.create(r,i);rn(d.context,t)}let f=P.transform(s,[1/r,0,0,-1/i,0,0]);f=P.transform(f,[1,0,0,1,0,-i]);let m=p.slice();P.axialAlignedBoundingBox([0,0,r,i],f,m);let[h,g,_,v]=m,y=Math.round(_-h)||1,b=Math.round(v-g)||1,x=this.canvasFactory.create(y,b),S=x.context,C=h,w=g;S.translate(-C,-w);S.transform(...f);let T=null;if(!u){let e=this._scaleImage(d.canvas,Ee(S));u=e.img;T=e.tmpCanvas;if(u!==d.canvas){this.canvasFactory.destroy(d);d=null}if(c&&o){c.set(l,u);T=null;d=null}}S.imageSmoothingEnabled=sn(z(S),t.interpolate);en(S,u,0,0,u.width,u.height,0,0,r,i);T&&this.canvasFactory.destroy(T);d&&this.canvasFactory.destroy(d);S.globalCompositeOperation=`source-in`;let E=P.transform(Ee(S),[1,0,0,1,-C,-w]);S.fillStyle=o?a.getPattern(n,this,E,Vt,e):a;S.fillRect(0,0,r,i);c&&!o&&c.set(l,x.canvas);this.dependencyTracker?.recordDependencies(e,mt);return{canvas:x.canvas,canvasEntry:c&&!o?null:x,offsetX:Math.round(C),offsetY:Math.round(w)}}setLineWidth(e,t){this.dependencyTracker?.recordSimpleData(`lineWidth`,e);t!==this.current.lineWidth&&(this._cachedScaleForStroking[0]=-1);this.current.lineWidth=t;this.ctx.lineWidth=t}setLineCap(e,t){this.dependencyTracker?.recordSimpleData(`lineCap`,e);this.ctx.lineCap=cn[t]}setLineJoin(e,t){this.dependencyTracker?.recordSimpleData(`lineJoin`,e);this.ctx.lineJoin=ln[t]}setMiterLimit(e,t){this.dependencyTracker?.recordSimpleData(`miterLimit`,e);this.ctx.miterLimit=t}setDash(e,t,n){this.dependencyTracker?.recordSimpleData(`dash`,e);let r=this.ctx;if(r.setLineDash!==void 0){r.setLineDash(t);r.lineDashOffset=n}}setRenderingIntent(e,t){}setFlatness(e,t){}setGState(e,t){for(let[n,r]of t)switch(n){case`LW`:this.setLineWidth(e,r);break;case`LC`:this.setLineCap(e,r);break;case`LJ`:this.setLineJoin(e,r);break;case`ML`:this.setMiterLimit(e,r);break;case`D`:this.setDash(e,r[0],r[1]);break;case`RI`:this.setRenderingIntent(e,r);break;case`FL`:this.setFlatness(e,r);break;case`Font`:this.setFont(e,r[0],r[1]);break;case`CA`:this.dependencyTracker?.recordSimpleData(`strokeAlpha`,e);this.current.strokeAlpha=r;break;case`ca`:this.dependencyTracker?.recordSimpleData(`fillAlpha`,e);this.ctx.globalAlpha=this.current.fillAlpha=r;break;case`BM`:this.dependencyTracker?.recordSimpleData(`globalCompositeOperation`,e);this.ctx.globalCompositeOperation=r;break;case`SMask`:this.dependencyTracker?.recordSimpleData(`SMask`,e);this.current.activeSMask=r?this.tempSMask:null;this.current.activeSMask&&(this.current.activeSMask.blendMode=this.ctx.globalCompositeOperation);this.tempSMask=null;this.checkSMaskState(e);break;case`TR`:this.dependencyTracker?.recordSimpleData(`filter`,e);this.ctx.filter=this.current.transferMaps=this.filterFactory.addFilter(r)}}get inSMaskMode(){return!!this.suspendedCtx}_clearPreparedSMask(){if(this.smaskPreparedEntry){this.canvasFactory.destroy(this.smaskPreparedEntry);this.smaskPreparedEntry=null}this.smaskPreparedFor=null;this.smaskPreparedOffsetX=0;this.smaskPreparedOffsetY=0;this.smaskPreparedOOBAlpha=null}_ensurePreparedSMask(e){if(e!==this.smaskPreparedFor){this._clearPreparedSMask();this._prepareSMaskCanvas(e)}}checkSMaskState(e){let t=this.inSMaskMode;this.current.activeSMask&&!t?this.beginSMaskMode(e):!this.current.activeSMask&&t?this.endSMaskMode():this.current.activeSMask&&t&&this._ensurePreparedSMask(this.current.activeSMask)}_prepareSMaskCanvas(e){let{canvas:t,subtype:n,backdrop:r,transferMap:i}=e,a=n===`Luminosity`||n===`Alpha`&&i;if(!(a||n===`Luminosity`&&r)){this.smaskPreparedFor=e;return}let o;if(n===`Luminosity`&&r){let[e,t,n]=we(r),a=Math.round(.3*e+.59*t+.11*n);o=i?.[a]??a}else o=i?.[0]??0;let{width:s,height:c}=this.ctx.canvas,l=s*c<4*(t.width*t.height),u=a?{url:n===`Alpha`?this.filterFactory.addAlphaFilter(i):this.filterFactory.addLuminosityFilter(i),subtype:n,transferMap:i}:null,d=n===`Luminosity`?r:null,f,p,m;if(l){f=this._bakeSMaskCanvas(t,e.offsetX,e.offsetY,s,c,d,u);p=0;m=0}else{f=this._bakeSMaskCanvas(t,0,0,t.width,t.height,d,u);p=e.offsetX;m=e.offsetY}this.smaskPreparedEntry=f;this.smaskPreparedFor=e;this.smaskPreparedOffsetX=p;this.smaskPreparedOffsetY=m;this.smaskPreparedOOBAlpha=l||o===0?null:o}_bakeSMaskCanvas(e,t,n,r,i,a,o){a||o||k(`_bakeSMaskCanvas with neither backdrop nor filter`);let s=this.canvasFactory.create(r,i),c=s.context;c.drawImage(e,t,n);if(a){c.globalCompositeOperation=`destination-atop`;c.fillStyle=a;c.fillRect(0,0,r,i)}if(!o)return s;let l=this.canvasFactory.create(r,i),u=l.context;u.filter=o.url;let d=N.isCanvasFilterSupported&&u.filter!==`none`&&u.filter!==``;u.drawImage(s.canvas,0,0);N.isCanvasFilterSupported&&(u.filter=`none`);if(!d){let e=u.getImageData(0,0,r,i),{data:t}=e,{transferMap:n}=o;if(o.subtype===`Luminosity`)for(let e=0,r=t.length;e<r;e+=4){let r=.3*t[e]+.59*t[e+1]+.11*t[e+2]+.5|0;t[e]=t[e+1]=t[e+2]=0;t[e+3]=n?.[r]??r}else for(let e=3,r=t.length;e<r;e+=4)t[e]=n[t[e]];u.putImageData(e,0,0)}this.canvasFactory.destroy(s);return l}beginSMaskMode(e){if(this.inSMaskMode)throw Error(`beginSMaskMode called while already in smask mode`);let{width:t,height:n}=this.ctx.canvas,r=this.canvasFactory.create(t,n);this.smaskScratchCanvas=r;this.suspendedCtx=this.ctx;let i=this.ctx=r.context;i.setTransform(this.suspendedCtx.getTransform());an(this.suspendedCtx,i);$t(i,this.suspendedCtx);this._ensurePreparedSMask(this.current.activeSMask);this.setGState(e,[[`BM`,`source-over`]])}endSMaskMode(){if(!this.inSMaskMode)throw Error(`endSMaskMode called while not in smask mode`);this.ctx._removeMirroring();an(this.ctx,this.suspendedCtx);this.ctx=this.suspendedCtx;this.suspendedCtx=null;this.canvasFactory.destroy(this.smaskScratchCanvas);this.smaskScratchCanvas=null;this._clearPreparedSMask()}#f(e,t=null,n=1){let{width:r,height:i}=e,a=t??this.canvasFactory.create(r,i),o=a.context,s=(n=Math.round(255*n)/255)<1;s&&this.#s===void 0&&(this.#s=N.isCanvasFilterSupported?new Map:`none`);let c=`none`;if(s&&this.#s instanceof Map){c=this.#s.get(n);if(!c){c=this.filterFactory.addKnockoutFilter(n);this.#s.set(n,c)}}if(!s||c!==`none`){if(t){o.save();o.setTransform(1,0,0,1,0,0);o.clearRect(0,0,r,i);o.restore()}o.filter=c;o.drawImage(e,0,0);o.filter=`none`;return a}let l=e.getContext(`2d`,{willReadFrequently:!0}).getImageData(0,0,r,i),u=o.createImageData(r,i),d=l.data,f=u.data,p=n>0?1/n:1e6;for(let e=3,t=d.length;e<t;e+=4)f[e]=Math.min(Math.round(d[e]*p),255);o.putImageData(u,0,0);return a}#p(e,t,n,r){let i=e?.[t]??null;if(i&&(i.canvas.width!==n||i.canvas.height!==r)){this.canvasFactory.destroy(i);i=null}if(!i){i=this.canvasFactory.create(n,r);e&&(e[t]=i);return i}let a=i.context;a.save();a.setTransform(1,0,0,1,0,0);a.clearRect(0,0,n,r);a.restore();return i}#m(e,t,n={}){let{backdropCanvas:r=null,destTransform:i=[1,0,0,1,0,0],backdropOffset:a=[0,0],reuseMaskEntry:o=null,poolMeta:s=null,sourceAlpha:c=1,sourceFilter:l=`none`,knockoutAlpha:u=1}=n,{width:d,height:f}=t,p=this.#f(t,o,u),m=e.globalCompositeOperation;e.save();e.setTransform(...i);e.globalAlpha=1;N.isCanvasFilterSupported&&(e.filter=`none`);e.globalCompositeOperation=`destination-out`;e.drawImage(p.canvas,0,0);if(r){let[t,n]=a,i=this.#p(s,`knockoutBackdropEntry`,d,f),o=i.context;o.drawImage(r,t,n,d,f,0,0,d,f);o.globalCompositeOperation=`destination-in`;o.drawImage(p.canvas,0,0);o.globalCompositeOperation=`source-over`;e.globalCompositeOperation=`destination-over`;e.drawImage(i.canvas,0,0);s||this.canvasFactory.destroy(i)}e.globalCompositeOperation=m;e.globalAlpha=c;N.isCanvasFilterSupported&&(e.filter=l??`none`);e.drawImage(t,0,0);e.restore();o||this.canvasFactory.destroy(p)}#h(e=1){if(this.#e===0||this.#t>0||!this.contentVisible)return!1;this.#t++;this.#o=e;let t=this.#l.at(-1),{canvas:n}=this.ctx,r=this.#p(t,`knockoutTempEntry`,n.width,n.height);this.#n=r;let i=r.context;i.save();i.setTransform(this.ctx.getTransform());an(this.ctx,i);this.#a=i.globalCompositeOperation;i.globalCompositeOperation=`source-over`;$t(i,this.ctx);this.#c=t;this.#r=this.ctx;this.#i=this.suspendedCtx;this.ctx=i;this.inSMaskMode&&(this.suspendedCtx=i);return!0}#g(e){if(!e)return;let t=this.#n,n=this.#r,r=this.#i,i=t.context;this.#n=null;this.#r=null;this.#i=null;this.inSMaskMode&&this.suspendedCtx===i&&this.ctx!==i&&this.endSMaskMode();this.inSMaskMode&&(this.suspendedCtx=r);this.ctx._removeMirroring();this.ctx.globalCompositeOperation=this.#a;this.#a=null;an(this.ctx,n);this.ctx=n;let a=this.#c;this.#c=null;let o=this.#o;this.#o=1;try{this.#m(r??n,t.canvas,{backdropCanvas:a?.backdropCtx?.canvas??null,backdropOffset:a?.backdropCtx?[a.offsetX,a.offsetY]:[0,0],reuseMaskEntry:a?.knockoutMaskEntry??null,poolMeta:a,knockoutAlpha:o})}finally{i.restore();this.#t--;a||this.canvasFactory.destroy(t)}}compose(e){if(!this.current.activeSMask)return;e=e?[Math.floor(e[0]),Math.floor(e[1]),Math.ceil(e[2]),Math.ceil(e[3])]:[0,0,this.ctx.canvas.width,this.ctx.canvas.height];let t=this.current.activeSMask,n=this.suspendedCtx,r=this.#t>0&&n===this.ctx;this.composeSMask(r?null:n,t,this.ctx,e);if(!r){this.ctx.save();this.ctx.setTransform(1,0,0,1,0,0);this.ctx.clearRect(e[0],e[1],e[2]-e[0],e[3]-e[1]);this.ctx.restore()}}composeSMask(e,t,n,r){let i=r[0],a=r[1],o=r[2]-i,s=r[3]-a;if(o===0||s===0)return;let c=this.smaskPreparedEntry;if(c){let e=i,r=a,l=o,u=s,d=this.smaskPreparedOOBAlpha,f=d!==null;if(f){e=Math.max(i,t.offsetX);r=Math.max(a,t.offsetY);l=Math.min(i+o,t.offsetX+t.canvas.width)-e;u=Math.min(a+s,t.offsetY+t.canvas.height)-r}if(l>0&&u>0){let t=e-this.smaskPreparedOffsetX,i=r-this.smaskPreparedOffsetY;n.save();n.globalAlpha=1;n.setTransform(1,0,0,1,0,0);let a=new Path2D;a.rect(e,r,l,u);n.clip(a);n.globalCompositeOperation=`destination-in`;n.drawImage(c.canvas,t,i,l,u,e,r,l,u);n.restore()}f&&d<255&&this._applySMaskOOBAlpha(n,i,a,o,s,e,r,e+l,r+u,d)}else this.genericComposeSMask(t,n,o,s,i,a);if(e){e.save();e.globalAlpha=1;e.globalCompositeOperation=t.blendMode||`source-over`;e.setTransform(1,0,0,1,0,0);e.drawImage(n.canvas,i,a,o,s,i,a,o,s);e.restore()}}_applySMaskOOBAlpha(e,t,n,r,i,a,o,s,c,l){let u=a<s&&o<c;if(u&&a===t&&o===n&&s===t+r&&c===n+i)return;let d=new Path2D;d.rect(t,n,r,i);u&&d.rect(a,o,s-a,c-o);e.save();e.globalAlpha=l/255;e.setTransform(1,0,0,1,0,0);e.clip(d,`evenodd`);e.globalCompositeOperation=`destination-in`;e.fillStyle=`#000000`;e.fillRect(t,n,r,i);e.restore()}genericComposeSMask(e,t,n,r,i,a){let{context:o,offsetX:s,offsetY:c}=e;t.save();t.globalAlpha=1;t.setTransform(1,0,0,1,0,0);let l=new Path2D;l.rect(i,a,n,r);t.clip(l);t.globalCompositeOperation=`destination-in`;t.drawImage(o.canvas,i-s,a-c,n,r,i,a,n,r);t.restore()}save(e){this.inSMaskMode&&an(this.ctx,this.suspendedCtx);this.ctx.save();let t=this.current;this.stateStack.push(t);this.current=t.clone();this.dependencyTracker?.save(e)}restore(e){this.dependencyTracker?.restore(e);if(this.stateStack.length!==0){this.current=this.stateStack.pop();this.ctx.restore();if(this.inSMaskMode){an(this.suspendedCtx,this.ctx);this.ctx.setTransform(this.suspendedCtx.getTransform())}this.checkSMaskState(e);this.pendingClip=null;this._cachedScaleForStroking[0]=-1;this._cachedGetSinglePixelWidth=null}else this.inSMaskMode&&this.endSMaskMode()}transform(e,t,n,r,i,a,o){this.dependencyTracker?.recordIncrementalData(`transform`,e);this.ctx.transform(t,n,r,i,a,o);this._cachedScaleForStroking[0]=-1;this._cachedGetSinglePixelWidth=null}constructPath(e,t,n,r){let[i]=n;if(!r){i||=n[0]=new Path2D;t!==C.stroke&&t!==C.closeStroke&&(this.current.tilingPatternDims=null);this[t](e,i);return}if(this.dependencyTracker!==null){let n=t===C.stroke?this.current.lineWidth/2:0;this.dependencyTracker.resetBBox(e).recordBBox(e,this.ctx,r[0]-n,r[2]+n,r[1]-n,r[3]+n).recordDependencies(e,[`transform`])}i instanceof Path2D||(i=n[0]=Me(i));P.axialAlignedBoundingBox(r,z(this.ctx),this.current.minMax);let a=this.current.tilingPatternDims;if(a&&t!==C.stroke&&t!==C.closeStroke&&this.current.fillColor instanceof Xt){let e=P.intersect(this.current.clipBox,this.current.minMax);e?this.current.fillColor.updatePatternDims(e,a):this.current.tilingPatternDims=null}this[t](e,i);this._pathStartIdx=e}closePath(e){this.ctx.closePath()}stroke(e,t,n=!0){let r=n&&this.#h(this.current.strokeAlpha),i=this.ctx,a=this.current.strokeColor;i.globalAlpha=this.current.strokeAlpha;if(this.contentVisible){if(typeof a==`object`&&a?.getPattern){let n=a.isModifyingCurrentTransform()?i.getTransform():null;i.save();i.strokeStyle=a.getPattern(i,this,Ee(i),Ht,e);if(n){let e=new Path2D;e.addPath(t,i.getTransform().invertSelf().multiplySelf(n));t=e}this.rescaleAndStroke(t,!1);i.restore()}else this.rescaleAndStroke(t,!0)}this.dependencyTracker?.recordDependencies(e,ct);n&&this.consumePath(e,t,this.current.getClippedPathBoundingBox(Ht,z(this.ctx)));i.globalAlpha=this.current.fillAlpha;this.#g(r)}closeStroke(e,t){this.stroke(e,t)}fill(e,t,n=!0){let r=n&&this.#h(this.current.fillAlpha),i=this.ctx,a=this.current.fillColor,o=this.current.patternFill,s=!1,c=this.current.getClippedPathBoundingBox();this.dependencyTracker?.recordDependencies(e,lt);if(o){let o=this.current.tilingPatternDims,l=o&&a.canSkipPatternCanvas(o);if(l){a.drawPattern(this,t,this.pendingEOFill,l,e);this.pendingEOFill=!1;n&&this.consumePath(e,t,c);this.current.tilingPatternDims=null;this.#g(r);return}let u=a.isModifyingCurrentTransform()?i.getTransform():null;this.dependencyTracker?.save(e);i.save();i.fillStyle=a.getPattern(i,this,Ee(i),Vt,e);if(u){let e=new Path2D;e.addPath(t,i.getTransform().invertSelf().multiplySelf(u));t=e}s=!0}if(this.contentVisible&&c!==null){if(this.pendingEOFill){i.fill(t,`evenodd`);this.pendingEOFill=!1}else i.fill(t)}if(s){i.restore();this.dependencyTracker?.restore(e)}n&&this.consumePath(e,t,c);this.#g(r)}eoFill(e,t){this.pendingEOFill=!0;this.fill(e,t)}fillStroke(e,t){let n=this.#h(Math.min(this.current.fillAlpha,this.current.strokeAlpha));this.fill(e,t,!1);this.stroke(e,t,!1);this.consumePath(e,t);this.#g(n)}eoFillStroke(e,t){this.pendingEOFill=!0;this.fillStroke(e,t)}closeFillStroke(e,t){this.fillStroke(e,t)}closeEOFillStroke(e,t){this.pendingEOFill=!0;this.fillStroke(e,t)}endPath(e,t){this.consumePath(e,t)}rawFillPath(e,t){let n=this.#h(this.current.fillAlpha);this.ctx.fill(t);this.dependencyTracker?.recordDependencies(e,dt).recordOperation(e);this.#g(n)}clip(e){this.dependencyTracker?.recordFutureForcedDependency(`clipMode`,e);this.pendingClip=un}eoClip(e){this.dependencyTracker?.recordFutureForcedDependency(`clipMode`,e);this.pendingClip=dn}beginText(e){this.current.textMatrix=null;this.current.textMatrixScale=1;this.current.x=this.current.lineX=0;this.current.y=this.current.lineY=0;this.dependencyTracker?.recordOpenMarker(e).resetIncrementalData(`sameLineText`).resetIncrementalData(`moveText`,e)}endText(e){let t=this.pendingTextPaths,n=this.ctx;if(this.dependencyTracker){let{dependencyTracker:n}=this;t!==void 0&&n.recordFutureForcedDependency(`textClip`,n.getOpenMarker()).recordFutureForcedDependency(`textClip`,e);n.recordCloseMarker(e)}if(t!==void 0){let e=new Path2D,r=n.getTransform().invertSelf();for(let{transform:n,x:i,y:a,fontSize:o,path:s}of t)s&&e.addPath(s,new DOMMatrix(n).preMultiplySelf(r).translate(i,a).scale(o,-o));n.clip(e)}delete this.pendingTextPaths}setCharSpacing(e,t){this.dependencyTracker?.recordSimpleData(`charSpacing`,e);this.current.charSpacing=t}setWordSpacing(e,t){this.dependencyTracker?.recordSimpleData(`wordSpacing`,e);this.current.wordSpacing=t}setHScale(e,t){this.dependencyTracker?.recordSimpleData(`hScale`,e);this.current.textHScale=t/100}setLeading(e,t){this.dependencyTracker?.recordSimpleData(`leading`,e);this.current.leading=-t}setFont(e,t,n){this.dependencyTracker?.recordSimpleData(`font`,e).recordSimpleDataFromNamed(`fontObj`,t,e);let r=this.commonObjs.get(t),i=this.current;if(!r)throw Error(`Can't find font for ${t}`);i.fontMatrix=r.fontMatrix||m;i.fontMatrix[0]!==0&&i.fontMatrix[3]!==0||O(`Invalid font matrix for font `+t);if(n<0){n=-n;i.fontDirection=-1}else i.fontDirection=1;this.current.font=r;this.current.fontSize=n;if(r.isType3Font)return;let a=r.loadedName||`sans-serif`,o=r.systemFontInfo?.css||`"${a}", ${r.fallbackName}`,s=`normal`;r.black?s=`900`:r.bold&&(s=`bold`);let c=r.italic?`italic`:`normal`,l=n;n<16?l=16:n>100&&(l=100);this.current.fontSizeScale=n/l;this.ctx.font=`${c} ${s} ${l}px ${o}`}setTextRenderingMode(e,t){this.dependencyTracker?.recordSimpleData(`textRenderingMode`,e);this.current.textRenderingMode=t}setTextRise(e,t){this.dependencyTracker?.recordSimpleData(`textRise`,e);this.current.textRise=t}moveText(e,t,n){this.dependencyTracker?.resetIncrementalData(`sameLineText`).recordIncrementalData(`moveText`,e);this.current.x=this.current.lineX+=t;this.current.y=this.current.lineY+=n}setLeadingMoveText(e,t,n){this.setLeading(e,-n);this.moveText(e,t,n)}setTextMatrix(e,t){this.dependencyTracker?.resetIncrementalData(`sameLineText`).recordSimpleData(`textMatrix`,e);let{current:n}=this;n.textMatrix=t;n.textMatrixScale=Math.hypot(t[0],t[1]);n.x=n.lineX=0;n.y=n.lineY=0}nextLine(e){this.moveText(e,0,this.current.leading);this.dependencyTracker?.recordIncrementalData(`moveText`,this.dependencyTracker.getSimpleIndex(`leading`)??e)}#_(e,t,n){let r=new Path2D;r.addPath(e,new DOMMatrix(n).invertSelf().multiplySelf(t));return r}paintChar(e,t,n,r,i,a){let o=this.ctx,s=this.current,c=s.font,l=s.textRenderingMode,u=s.fontSize/s.fontSizeScale,d=l&3,f=!!(l&4),p=s.patternFill&&!c.missingFile,m=s.patternStroke&&!c.missingFile,h;(c.disableFontFace||f||p||m)&&!c.missingFile&&(h=c.getPathGenerator(this.commonObjs,t));if(h&&(c.disableFontFace||p||m)){o.save();o.translate(n,r);o.scale(u,-u);this.dependencyTracker?.recordCharacterBBox(e,o,c);let t;if(d===0||d===2){if(i){t=o.getTransform();o.setTransform(...i);let e=this.#_(h,t,i);o.fill(e)}else o.fill(h)}if(d===1||d===2){if(a){t||=o.getTransform();o.setTransform(...a);let{a:e,b:n,c:r,d:i}=t,s=P.inverseTransform(a),c=P.transform([e,n,r,i,0,0],s);P.singularValueDecompose2dScale(c,G);o.lineWidth*=Math.max(G[0],G[1])/u;o.stroke(this.#_(h,t,a))}else{o.lineWidth/=u;o.stroke(h)}}o.restore()}else{if(d===0||d===2){o.fillText(t,n,r);this.dependencyTracker?.recordCharacterBBox(e,o,c,u,n,r,()=>o.measureText(t))}if(d===1||d===2){this.dependencyTracker&&this.dependencyTracker?.recordCharacterBBox(e,o,c,u,n,r,()=>o.measureText(t)).recordDependencies(e,ct);o.strokeText(t,n,r)}}if(f){(this.pendingTextPaths||=[]).push({transform:z(o),x:n,y:r,fontSize:u,path:h});this.dependencyTracker?.recordCharacterBBox(e,o,c,u,n,r)}}get isFontSubpixelAAEnabled(){let e=this.canvasFactory.create(10,10),t=e.context;t.scale(1.5,1);t.fillText(`I`,0,10);let n=t.getImageData(0,0,10,10).data;this.canvasFactory.destroy(e);let r=!1;for(let e=3;e<n.length;e+=4)if(n[e]>0&&n[e]<255){r=!0;break}return j(this,`isFontSubpixelAAEnabled`,r)}showText(e,t){if(this.dependencyTracker){this.dependencyTracker.recordDependencies(e,ft).resetBBox(e);this.current.textRenderingMode&4&&this.dependencyTracker.recordFutureForcedDependency(`textClip`,e).inheritPendingDependenciesAsFutureForcedDependencies()}let n=this.current,r=n.font;if(r.isType3Font){let r=this.#h(n.fillAlpha);this.showType3Text(e,t);this.dependencyTracker?.recordShowTextOperation(e);this.#g(r);return}let i=n.fontSize;if(i===0){this.dependencyTracker?.recordOperation(e);return}let a=this.#h(n.fillAlpha),o=this.ctx,s=n.fontSizeScale,c=n.charSpacing,l=n.wordSpacing,u=n.fontDirection,d=n.textHScale*u,f=t.length,p=r.vertical,m=p?1:-1,h=r.defaultVMetrics,g=i*n.fontMatrix[0],_=n.textRenderingMode===0&&!r.disableFontFace&&!n.patternFill;o.save();n.textMatrix&&o.transform(...n.textMatrix);o.translate(n.x,n.y+n.textRise);u>0?o.scale(d,-1):o.scale(d,1);let v,y,b=n.textRenderingMode&3,x=b===0||b===2,S=b===1||b===2,C=n.lineWidth,w=n.textMatrixScale;w===0||C===0?S&&(C=this.getSinglePixelWidth()):C/=w;if(s!==1){o.scale(s,s);C/=s}o.lineWidth=C;if(x&&n.patternFill){o.save();let t=n.fillColor.getPattern(o,this,Ee(o),Vt,e);v=z(o);o.restore();o.fillStyle=t}if(S&&n.patternStroke){o.save();let t=n.strokeColor.getPattern(o,this,Ee(o),Ht,e);y=z(o);o.restore();o.strokeStyle=t}if(r.isInvalidPDFjsFont){let r=[],i=0;for(let e of t){r.push(e.unicode);i+=e.width}let s=r.join(``);o.fillText(s,0,0);if(this.dependencyTracker!==null){let t=o.measureText(s);this.dependencyTracker.recordBBox(e,this.ctx,-t.actualBoundingBoxLeft,t.actualBoundingBoxRight,-t.actualBoundingBoxAscent,t.actualBoundingBoxDescent).recordShowTextOperation(e)}n.x+=i*g*d;o.restore();this.compose();this.#g(a);return}let T,E=0;for(T=0;T<f;++T){let n=t[T];if(typeof n==`number`){E+=m*n*i/1e3;continue}let a=!1,d=(n.isSpace?l:0)+c,f=n.fontChar,b=n.accent,x,S,C,w=n.width;if(p){let e=n.vmetric||h,t=-(n.vmetric?e[1]:.5*w)*g,r=e[2]*g;w=e?-e[0]:w;x=t/s;S=(E+r)/s}else{x=E/s;S=0}if(r.remeasure&&w>0){C=o.measureText(f);let e=1e3*C.width/i*s;if(w<e&&this.isFontSubpixelAAEnabled){let t=w/e;a=!0;o.save();o.scale(t,1);x/=t}else w!==e&&(x+=(w-e)/2e3*i/s)}if(this.contentVisible&&(n.isInFont||r.missingFile)){if(_&&!b){o.fillText(f,x,S);this.dependencyTracker?.recordCharacterBBox(e,o,C?{bbox:null}:r,i/s,x,S,()=>C??o.measureText(f))}else{this.paintChar(e,f,x,S,v,y);if(b){let t=x+i*b.offset.x/s,n=S-i*b.offset.y/s;this.paintChar(e,b.fontChar,t,n,v,y)}}}E+=p?w*g-d*u:w*g+d*u;a&&o.restore()}p?n.y-=E:n.x+=E*d;o.restore();this.compose();this.dependencyTracker?.recordShowTextOperation(e);this.#g(a)}showType3Text(e,t){let n=this.ctx,r=this.current,i=r.font,a=r.fontSize,o=r.fontDirection,s=i.vertical?1:-1,c=r.charSpacing,l=r.wordSpacing,u=r.textHScale*o,d=r.fontMatrix||m,f=t.length,p,h,g,_;if(r.textRenderingMode===3||a===0)return;this._cachedScaleForStroking[0]=-1;this._cachedGetSinglePixelWidth=null;n.save();r.textMatrix&&n.transform(...r.textMatrix);n.translate(r.x,r.y+r.textRise);n.scale(u,o);let v=this.dependencyTracker;this.dependencyTracker=v?new st(v,e):null;for(p=0;p<f;++p){h=t[p];if(typeof h==`number`){_=s*h*a/1e3;this.ctx.translate(_,0);r.x+=_*u;continue}let e=(h.isSpace?l:0)+c,o=i.charProcOperatorList[h.operatorListId];if(o){if(this.contentVisible){this.save();n.scale(a,a);n.transform(...d);this.executeOperatorList(o);this.restore()}}else O(`Type3 character "${h.operatorListId}" is not available.`);let f=[h.width,0];P.applyTransform(f,d);g=f[0]*a+e;n.translate(g,0);r.x+=g*u}n.restore();v&&(this.dependencyTracker=v)}setCharWidth(e,t,n){}setCharWidthAndBounds(e,t,n,r,i,a,o){let s=new Path2D;s.rect(r,i,a-r,o-i);this.ctx.clip(s);this.dependencyTracker?.recordBBox(e,this.ctx,r,a,i,o).recordClipBox(e,this.ctx,r,a,i,o);this.endPath(e)}getColorN_Pattern(e,t){let n;if(t[0]===`TilingPattern`){let e=this.baseTransform||z(this.ctx);n=new Xt(t,this.ctx,{createCanvasGraphics:(e,t)=>new fn(e,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack},void 0,void 0,this.dependencyTracker?new st(this.dependencyTracker,t,!0):null)},e)}else n=this._getPattern(e,t[1],t[2]);return n}setStrokeColorN(e,...t){this.dependencyTracker?.recordSimpleData(`strokeColor`,e);this.current.strokeColor=this.getColorN_Pattern(e,t);this.current.patternStroke=!0}setFillColorN(e,...t){this.dependencyTracker?.recordSimpleData(`fillColor`,e);let n=this.current.fillColor=this.getColorN_Pattern(e,t);this.current.patternFill=!0;this.current.tilingPatternDims=n instanceof Xt?[0,0,0,0]:null}setStrokeRGBColor(e,t){this.dependencyTracker?.recordSimpleData(`strokeColor`,e);this.ctx.strokeStyle=this.current.strokeColor=t;this.current.patternStroke=!1}setStrokeTransparent(e){this.dependencyTracker?.recordSimpleData(`strokeColor`,e);this.ctx.strokeStyle=this.current.strokeColor=`transparent`;this.current.patternStroke=!1}setFillRGBColor(e,t){this.dependencyTracker?.recordSimpleData(`fillColor`,e);this.ctx.fillStyle=this.current.fillColor=t;this.current.patternFill=!1;this.current.tilingPatternDims=null}setFillTransparent(e){this.dependencyTracker?.recordSimpleData(`fillColor`,e);this.ctx.fillStyle=this.current.fillColor=`transparent`;this.current.patternFill=!1;this.current.tilingPatternDims=null}_getPattern(e,t,n=null){let r;if(this.cachedPatterns.has(t))r=this.cachedPatterns.get(t);else{r=function(e){switch(e[0]){case`RadialAxial`:return new Kt(e);case`Mesh`:return new Jt(e);case`Dummy`:return new Yt}throw Error(`Unknown IR type: ${e[0]}`)}(this.getObject(e,t));this.cachedPatterns.set(t,r)}n&&(r.matrix=n);return r}shadingFill(e,t){if(!this.contentVisible)return;let n=this.#h(this.current.fillAlpha),r=this.ctx;this.save(e);r.fillStyle=this._getPattern(e,t).getPattern(r,this,Ee(r),Ut,e);let i=Ee(r);if(i){let{width:e,height:t}=r.canvas,n=p.slice();P.axialAlignedBoundingBox([0,0,e,t],i,n);let[a,o,s,c]=n;this.ctx.fillRect(a,o,s-a,c-o)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.dependencyTracker?.resetBBox(e).recordFullPageBBox(e).recordDependencies(e,pt).recordDependencies(e,lt).recordOperation(e);this.compose(this.current.getClippedPathBoundingBox());this.restore(e);this.#g(n)}beginInlineImage(){k(`Should not call beginInlineImage`)}beginImageData(){k(`Should not call beginImageData`)}paintFormXObjectBegin(e,t,n){if(this.contentVisible){this.save(e);this.baseTransformStack.push(this.baseTransform);t&&this.transform(e,...t);this.baseTransform=z(this.ctx);if(n){P.axialAlignedBoundingBox(n,this.baseTransform,this.current.minMax);let[t,r,i,a]=n,o=new Path2D;o.rect(t,r,i-t,a-r);this.ctx.clip(o);this.dependencyTracker?.recordClipBox(e,this.ctx,t,i,r,a);this.endPath(e)}}}paintFormXObjectEnd(e){if(this.contentVisible){this.restore(e);this.baseTransform=this.baseTransformStack.pop()}}beginGroup(e,t){if(!this.contentVisible)return;this.save(e);let{inSMaskMode:n}=this;if(n){this.endSMaskMode();this.current.activeSMask=null}let r=this.ctx;t.isolated||t.knockout||this.#e!==0||D(`TODO: Fully support non-isolated non-knockout groups.`);if(!t.needsIsolation&&!t.knockout&&this.#e===0&&r.globalAlpha===1&&r.globalCompositeOperation===`source-over`&&!n){if(t.bbox){let e=new Path2D,[n,i,a,o]=t.bbox;e.rect(n,i,a-n,o-i);if(t.matrix){let n=new Path2D;n.addPath(e,new DOMMatrix(t.matrix));e=n}r.clip(e)}this.groupStack.push(null);this.#l.push(null);this.groupLevel++;return}let i=z(r);t.matrix&&r.transform(...t.matrix);let a=[0,0,r.canvas.width,r.canvas.height],o;if(t.bbox){o=p.slice();P.axialAlignedBoundingBox(t.bbox,z(r),o);o=P.intersect(o,a)||[0,0,0,0]}else o=a;let s=Math.floor(o[0]),c=Math.floor(o[1]),l=Math.max(Math.ceil(o[2])-s,1),u=Math.max(Math.ceil(o[3])-c,1);this.current.startNewPathAndClipBox([0,0,l,u]);let d=this.canvasFactory.create(l,u);t.smask&&this.smaskGroupCanvases.push(d);let f=d.context,m=t.knockout&&!t.isolated?r:null,h=!t.isolated&&!t.knockout&&!t.smask&&t.needsIsolation&&this.#e>0,g=t.knockout?this.canvasFactory.create(l,u):null,_=this.#e;t.knockout?this.#e++:this.#e=0;f.translate(-s,-c);f.transform(...i);if(!t.isolated&&!t.smask&&n&&t.needsIsolation){f.save();f.setTransform(1,0,0,1,0,0);f.drawImage(r.canvas,-s,-c);f.restore()}if(t.bbox){let e=new Path2D,[n,r,i,a]=t.bbox;e.rect(n,r,i-n,a-r);if(t.matrix){let n=new Path2D;n.addPath(e,new DOMMatrix(t.matrix));e=n}f.clip(e)}t.smask&&this.smaskStack.push({canvas:d.canvas,context:f,offsetX:s,offsetY:c,subtype:t.smask.subtype,backdrop:t.smask.backdrop,transferMap:t.smask.transferMap||null});if(!t.smask||this.dependencyTracker){r.setTransform(1,0,0,1,0,0);r.translate(s,c);r.save()}an(r,f);this.ctx=f;this.dependencyTracker?.inheritSimpleDataAsFutureForcedDependencies([`fillAlpha`,`strokeAlpha`,`globalCompositeOperation`]).pushBaseTransform(r);this.setGState(e,[[`BM`,`source-over`],[`ca`,1],[`CA`,1],[`TR`,null]]);this.groupStack.push(r);this.#l.push({backdropCtx:m,savedKnockoutLevel:_,offsetX:s,offsetY:c,hasInnerBackdrop:h,knockoutMaskEntry:g,knockoutTempEntry:null,knockoutBackdropEntry:null});this.groupLevel++}endGroup(e,t){if(!this.contentVisible)return;this.groupLevel--;let n=this.ctx,r=this.groupStack.pop(),i=this.#l.pop();i&&(this.#e=i.savedKnockoutLevel);if(r!==null){this.ctx=r;this.ctx.imageSmoothingEnabled=!1;this.dependencyTracker?.popBaseTransform();if(t.smask){this.tempSMask=this.smaskStack.pop();this.restore(e);if(this.dependencyTracker){this.ctx.restore();this.inSMaskMode&&this.ctx.setTransform(this.suspendedCtx.getTransform())}this.#v(i)}else{this.ctx.restore();let t=z(this.ctx);this.restore(e);this.ctx.save();this.ctx.setTransform(...t);let a=p.slice();P.axialAlignedBoundingBox([0,0,n.canvas.width,n.canvas.height],t,a);let o=this.#l.at(-1);if(this.#e>0){if(i.hasInnerBackdrop){let{width:e,height:a}=n.canvas,o=this.canvasFactory.create(e,a),s=o.context;s.drawImage(r.canvas,i.offsetX,i.offsetY,e,a,0,0,e,a);s.globalCompositeOperation=`source-over`;s.drawImage(n.canvas,0,0);let c=this.#f(n.canvas);s.globalCompositeOperation=`destination-in`;s.drawImage(c.canvas,0,0);let l=this.ctx.globalCompositeOperation,u=this.ctx.globalAlpha,d=this.ctx.filter;this.ctx.save();this.ctx.setTransform(...t);this.ctx.globalAlpha=1;N.isCanvasFilterSupported&&(this.ctx.filter=`none`);this.ctx.globalCompositeOperation=`destination-out`;this.ctx.drawImage(c.canvas,0,0);this.ctx.globalCompositeOperation=l;this.ctx.globalAlpha=u;N.isCanvasFilterSupported&&(this.ctx.filter=d??`none`);this.ctx.drawImage(o.canvas,0,0);this.ctx.restore();this.canvasFactory.destroy(c);this.canvasFactory.destroy(o)}else{let e=o?.backdropCtx??null;this.#m(this.ctx,n.canvas,{backdropCanvas:e?.canvas??null,destTransform:t,backdropOffset:e?[o.offsetX+i.offsetX,o.offsetY+i.offsetY]:[0,0],sourceAlpha:this.ctx.globalAlpha,sourceFilter:this.ctx.filter})}}else this.ctx.drawImage(n.canvas,0,0);this.ctx.restore();this.canvasFactory.destroy({canvas:n.canvas,context:n});this.#v(i);this.compose(a)}}else this.restore(e)}#v(e){if(e){if(e.knockoutMaskEntry){this.canvasFactory.destroy(e.knockoutMaskEntry);e.knockoutMaskEntry=null}if(e.knockoutTempEntry){this.canvasFactory.destroy(e.knockoutTempEntry);e.knockoutTempEntry=null}if(e.knockoutBackdropEntry){this.canvasFactory.destroy(e.knockoutBackdropEntry);e.knockoutBackdropEntry=null}}}beginAnnotation(e,t,n,r,i,a){this.#u();on(this.ctx);this.ctx.save();this.save(e);this.baseTransform&&this.ctx.setTransform(...this.baseTransform);if(n){let i=n[2]-n[0],o=n[3]-n[1];if(a&&this.annotationCanvasMap){(r=r.slice())[4]-=n[0];r[5]-=n[1];(n=n.slice())[0]=n[1]=0;n[2]=i;n[3]=o;P.singularValueDecompose2dScale(z(this.ctx),G);let{viewportScale:e}=this,a=Math.ceil(i*this.outputScaleX*e),s=Math.ceil(o*this.outputScaleY*e);this.annotationCanvas=this.canvasFactory.create(a,s);let{canvas:c,context:l}=this.annotationCanvas;this.annotationCanvasMap.set(t,c);this.annotationCanvas.savedCtx=this.ctx;this.ctx=l;this.ctx.save();this.ctx.setTransform(G[0],0,0,-G[1],0,o*G[1]);on(this.ctx)}else{on(this.ctx);this.endPath(e);let t=new Path2D;t.rect(n[0],n[1],i,o);this.ctx.clip(t)}}this.current=new tn(this.ctx.canvas.width,this.ctx.canvas.height);this.baseTransformStack.push(this.baseTransform);this.transform(e,...r);this.transform(e,...i);this.baseTransform=z(this.ctx)}endAnnotation(e){if(this.annotationCanvas){this.ctx.restore();this.#d();this.ctx=this.annotationCanvas.savedCtx;delete this.annotationCanvas.savedCtx;delete this.annotationCanvas}this.baseTransform=this.baseTransformStack.pop()}paintImageMaskXObject(e,t){if(!this.contentVisible)return;let n=t.count;(t=this.getObject(e,t.data,t)).count=n;let r=this.#h(this.current.fillAlpha),i=this.ctx,a=this._createMaskCanvas(e,t),o=a.canvas;i.save();i.setTransform(1,0,0,1,0,0);i.drawImage(o,a.offsetX,a.offsetY);this.dependencyTracker?.resetBBox(e).recordBBox(e,this.ctx,a.offsetX,a.offsetX+o.width,a.offsetY,a.offsetY+o.height).recordOperation(e);i.restore();a.canvasEntry&&this.canvasFactory.destroy(a.canvasEntry);this.compose();this.#g(r)}paintImageMaskXObjectRepeat(e,t,n,r=0,i=0,a,o){if(!this.contentVisible)return;t=this.getObject(e,t.data,t);let s=this.#h(this.current.fillAlpha),c=this.ctx;c.save();let l=z(c);c.transform(n,r,i,a,0,0);let u=this._createMaskCanvas(e,t);c.setTransform(1,0,0,1,u.offsetX-l[4],u.offsetY-l[5]);this.dependencyTracker?.resetBBox(e);for(let t=0,s=o.length;t<s;t+=2){let s=P.transform(l,[n,r,i,a,o[t],o[t+1]]);c.drawImage(u.canvas,s[4],s[5]);this.dependencyTracker?.recordBBox(e,this.ctx,s[4],s[4]+u.canvas.width,s[5],s[5]+u.canvas.height)}c.restore();u.canvasEntry&&this.canvasFactory.destroy(u.canvasEntry);this.compose();this.dependencyTracker?.recordOperation(e);this.#g(s)}paintImageMaskXObjectGroup(e,t){if(!this.contentVisible)return;let n=this.#h(this.current.fillAlpha),r=this.ctx,i=this.current.fillColor,a=this.current.patternFill;this.dependencyTracker?.resetBBox(e).recordDependencies(e,mt);for(let n of t){let{data:t,width:o,height:s,transform:c}=n,l=this.canvasFactory.create(o,s),u=l.context;u.save();rn(u,this.getObject(e,t,n));u.globalCompositeOperation=`source-in`;u.fillStyle=a?i.getPattern(u,this,Ee(r),Vt,e):i;u.fillRect(0,0,o,s);u.restore();r.save();r.transform(...c);r.scale(1,-1);en(r,l.canvas,0,0,o,s,0,-1,1,1);this.canvasFactory.destroy(l);this.dependencyTracker?.recordBBox(e,r,0,o,0,s);r.restore()}this.compose();this.dependencyTracker?.recordOperation(e);this.#g(n)}paintImageXObject(e,t){if(!this.contentVisible)return;let n=this.getObject(e,t);n?this.paintInlineImageXObject(e,n):O(`Dependent image isn't ready yet`)}paintImageXObjectRepeat(e,t,n,r,i){if(!this.contentVisible)return;let a=this.getObject(e,t);if(!a){O(`Dependent image isn't ready yet`);return}let o=a.width,s=a.height,c=[];for(let e=0,t=i.length;e<t;e+=2)c.push({transform:[n,0,0,r,i[e],i[e+1]],x:0,y:0,w:o,h:s});this.paintInlineImageXObjectGroup(e,a,c)}applyTransferMapsToCanvas(e){if(this.current.transferMaps!==`none`){e.filter=this.current.transferMaps;e.drawImage(e.canvas,0,0);e.filter=`none`}return e.canvas}applyTransferMapsToBitmap(e){if(this.current.transferMaps===`none`)return{img:e.bitmap,canvasEntry:null};let{bitmap:t,width:n,height:r}=e,i=this.canvasFactory.create(n,r),a=i.context;a.filter=this.current.transferMaps;a.drawImage(t,0,0);a.filter=`none`;return{img:i.canvas,canvasEntry:i}}paintInlineImageXObject(e,t){if(!this.contentVisible)return;let n=t.width,r=t.height,i=this.#h(this.current.fillAlpha),a=this.ctx;this.save(e);let{filter:o}=a;o!==`none`&&o!==``&&(a.filter=`none`);a.scale(1/n,-1/r);let s,c=null;if(t.bitmap){let e=this.applyTransferMapsToBitmap(t);s=e.img;c=e.canvasEntry}else if(typeof HTMLElement==`function`&&t instanceof HTMLElement||!t.data)s=t;else{let e=this.canvasFactory.create(n,r);nn(e.context,t);s=this.applyTransferMapsToCanvas(e.context);c=e}let l=this._scaleImage(s,Ee(a));a.imageSmoothingEnabled=sn(z(a),t.interpolate);if(this.dependencyTracker){this.dependencyTracker.resetBBox(e).recordBBox(e,a,0,n,-r,0).recordDependencies(e,ut).recordOperation(e);this.imagesTracker?.record(a,n,r,this.dependencyTracker.clipBox)}en(a,l.img,0,0,l.paintWidth,l.paintHeight,0,-r,n,r);l.tmpCanvas&&this.canvasFactory.destroy(l.tmpCanvas);c&&this.canvasFactory.destroy(c);this.compose();this.restore(e);this.#g(i)}paintInlineImageXObjectGroup(e,t,n){if(!this.contentVisible)return;let r=this.#h(this.current.fillAlpha),i=this.ctx,a,o=null;if(t.bitmap)a=t.bitmap;else{let e=t.width,n=t.height,r=this.canvasFactory.create(e,n);nn(r.context,t);a=this.applyTransferMapsToCanvas(r.context);o=r}this.dependencyTracker?.resetBBox(e);for(let t of n){i.save();i.transform(...t.transform);i.scale(1,-1);en(i,a,t.x,t.y,t.w,t.h,0,-1,1,1);this.dependencyTracker?.recordBBox(e,i,0,1,-1,0);i.restore()}o&&this.canvasFactory.destroy(o);this.dependencyTracker?.recordOperation(e);this.compose();this.#g(r)}paintSolidColorImageMask(e){if(!this.contentVisible)return;let t=this.#h(this.current.fillAlpha);this.dependencyTracker?.resetBBox(e).recordBBox(e,this.ctx,0,1,0,1).recordDependencies(e,lt).recordOperation(e);this.ctx.fillRect(0,0,1,1);this.compose();this.#g(t)}markPoint(e,t){}markPointProps(e,t,n){}beginMarkedContent(e,t){this.dependencyTracker?.beginMarkedContent(e);this.markedContentStack.push({visible:!0})}beginMarkedContentProps(e,t,n){this.dependencyTracker?.beginMarkedContent(e);t===`OC`?this.markedContentStack.push({visible:this.optionalContentConfig.isVisible(n)}):this.markedContentStack.push({visible:!0});this.contentVisible=this.isContentVisible()}endMarkedContent(e){this.dependencyTracker?.endMarkedContent(e);this.markedContentStack.pop();this.contentVisible=this.isContentVisible()}beginCompat(e){}endCompat(e){}consumePath(e,t,n){let r=this.current.isEmptyClip();this.pendingClip&&this.current.updateClipFromPath();this.pendingClip||this.compose(n);let i=this.ctx;if(this.pendingClip){r||(this.pendingClip===dn?i.clip(t,`evenodd`):i.clip(t));this.pendingClip=null;this.dependencyTracker?.bboxToClipBoxDropOperation(e).recordFutureForcedDependency(`clipPath`,e)}else this.dependencyTracker?.recordOperation(e);this.current.startNewPathAndClipBox(this.current.clipBox)}getSinglePixelWidth(){if(!this._cachedGetSinglePixelWidth){let e=z(this.ctx);if(e[1]===0&&e[2]===0)this._cachedGetSinglePixelWidth=1/Math.min(Math.abs(e[0]),Math.abs(e[3]));else{let t=Math.abs(e[0]*e[3]-e[2]*e[1]),n=Math.hypot(e[0],e[2]),r=Math.hypot(e[1],e[3]);this._cachedGetSinglePixelWidth=Math.max(n,r)/t}}return this._cachedGetSinglePixelWidth}getScaleForStroking(){if(this._cachedScaleForStroking[0]===-1){let{lineWidth:e}=this.current,{a:t,b:n,c:r,d:i}=this.ctx.getTransform(),a,o;if(n===0&&r===0){let n=Math.abs(t),r=Math.abs(i);if(n===r){if(e===0)a=o=1/n;else{let t=n*e;a=o=t<1?1/t:1}}else if(e===0){a=1/n;o=1/r}else{let t=n*e,i=r*e;a=t<1?1/t:1;o=i<1?1/i:1}}else{let s=Math.abs(t*i-n*r),c=Math.hypot(t,n),l=Math.hypot(r,i);if(e===0){a=l/s;o=c/s}else{let t=e*s;a=l>t?l/t:1;o=c>t?c/t:1}}this._cachedScaleForStroking[0]=a;this._cachedScaleForStroking[1]=o}return this._cachedScaleForStroking}rescaleAndStroke(e,t){let{ctx:n,current:{lineWidth:r}}=this,[i,a]=this.getScaleForStroking();if(i===a){n.lineWidth=(r||1)*i;n.stroke(e);return}let o=n.getLineDash();t&&n.save();n.scale(i,a);Qt.a=1/i;Qt.d=1/a;let s=new Path2D;s.addPath(e,Qt);if(o.length>0){let e=Math.max(i,a);n.setLineDash(o.map(t=>t/e));n.lineDashOffset/=e}n.lineWidth=r||1;n.stroke(s);t&&n.restore()}isContentVisible(){for(let e=this.markedContentStack.length-1;e>=0;e--)if(!this.markedContentStack[e].visible)return!1;return!0}}for(let e in C)fn.prototype[e]!==void 0&&(fn.prototype[C[e]]=fn.prototype[e]);class pn{#e=null;#t=null;_fullReader=null;_rangeReaders=new Set;_source=null;constructor(e,t,n){this._source=e;this.#e=t;this.#t=n}get _progressiveDataLength(){return this._fullReader?._loaded??0}getFullReader(){A(!this._fullReader,`BasePDFStream.getFullReader can only be called once.`);return this._fullReader=new this.#e(this)}getRangeReader(e,t){if(t<=this._progressiveDataLength)return null;let n=new this.#t(this,e,t);this._rangeReaders.add(n);return n}cancelAllRequests(e){this._fullReader?.cancel(e);for(let t of new Set(this._rangeReaders))t.cancel(e)}}class mn{onProgress=null;_contentLength=0;_filename=null;_headersCapability=Promise.withResolvers();_isRangeSupported=!1;_isStreamingSupported=!1;_loaded=0;_stream=null;constructor(e){this._stream=e}_callOnProgress(){this.onProgress?.({loaded:this._loaded,total:this._contentLength})}get headersReady(){return this._headersCapability.promise}get filename(){return this._filename}get contentLength(){return this._contentLength}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}async read(){k("Abstract method `read` called")}cancel(e){k("Abstract method `cancel` called")}}class hn{_stream=null;constructor(e,t,n){this._stream=e}async read(){k("Abstract method `read` called")}cancel(e){k("Abstract method `cancel` called")}}function gn(e,t){let n=new Headers;if(!e||!t||typeof t!=`object`)return n;for(let e in t){let r=t[e];r!==void 0&&n.append(e,r)}return n}function _n(e){return URL.parse(e)?.origin??null}function vn({responseHeaders:e,isHttp:t,rangeChunkSize:n,disableRange:r}){let i={contentLength:0,isRangeSupported:!1},a=parseInt(e.get(`Content-Length`),10);if(!Number.isInteger(a))return i;i.contentLength=a;if(a<=2*n)return i;if(r||!t)return i;if(e.get(`Accept-Ranges`)!==`bytes`)return i;(e.get(`Content-Encoding`)||`identity`)===`identity`&&(i.isRangeSupported=!0);return i}function yn(e){let t=e.get(`Content-Disposition`);if(t){let e=function(e){let t=!0,n=r(`filename\\*`,`i`).exec(e);if(n){n=n[1];let e=o(n);e=unescape(e);e=s(e);e=c(e);return a(e)}n=function(e){let t=[],n,i=r(`filename\\*((?!0\\d)\\d+)(\\*?)`,`ig`);for(;(n=i.exec(e))!==null;){let[,e,r,i]=n;e=parseInt(e,10);if(e in t){if(e===0)break}else t[e]=[r,i]}let a=[];for(let e=0;e<t.length&&e in t;++e){let[n,r]=t[e];r=o(r);if(n){r=unescape(r);e===0&&(r=s(r))}a.push(r)}return a.join(``)}(e);if(n)return a(c(n));n=r(`filename`,`i`).exec(e);if(n){n=n[1];let e=o(n);e=c(e);return a(e)}function r(e,t){return RegExp(`(?:^|;)\\s*`+e+`\\s*=\\s*([^";\\s][^;\\s]*|"(?:[^"\\\\]|\\\\"?)+"?)`,t)}function i(e,n){if(e){if(!/^[\x00-\xFF]+$/.test(n))return n;try{let r=new TextDecoder(e,{fatal:!0}),i=ce(n);n=r.decode(i);t=!1}catch{}}return n}function a(e){if(t&&/[\x80-\xff]/.test(e)){e=i(`utf-8`,e);t&&(e=i(`iso-8859-1`,e))}return e}function o(e){if(e.startsWith(`"`)){let t=e.slice(1).split(`\\"`);for(let e=0;e<t.length;++e){let n=t[e].indexOf(`"`);if(n!==-1){t[e]=t[e].slice(0,n);t.length=e+1}t[e]=t[e].replaceAll(/\\(.)/g,`$1`)}e=t.join(`"`)}return e}function s(e){let t=e.indexOf(`'`);return t===-1?e:i(e.slice(0,t),e.slice(t+1).replace(/^[^']*'/,``))}function c(e){return!e.startsWith(`=?`)||/[\x00-\x19\x80-\xff]/.test(e)?e:e.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,function(e,t,n,r){if(n===`q`||n===`Q`)return i(t,r=(r=r.replaceAll(`_`,` `)).replaceAll(/=([0-9a-fA-F]{2})/g,function(e,t){return String.fromCharCode(parseInt(t,16))}));try{r=atob(r)}catch{}return i(t,r)})}return``}(t);if(e.includes(`%`))try{e=decodeURIComponent(e)}catch{}if(be(e))return e}return null}function bn(e,t){return new ae(`Unexpected server response (${e}) while retrieving PDF "${t.href}".`,e,e===404||e===0&&t.protocol===`file:`)}function xn(e,t){if(e!==t)throw Error(`Expected range response-origin "${e}" to match "${t}".`)}function Sn(e,t,n,r){return fetch(e,{method:`GET`,headers:t,signal:r.signal,mode:`cors`,credentials:n?`include`:`same-origin`,redirect:`follow`})}function Cn(e,t){if(e!==200&&e!==206)throw bn(e,t)}function wn(e){if(e instanceof Uint8Array)return e.buffer;if(e instanceof ArrayBuffer)return e;throw Error(`getArrayBuffer - unexpected data: ${e}`)}class Tn extends pn{_responseOrigin=null;constructor(e){super(e,En,Dn);let{httpHeaders:t,url:n}=e;A(/https?:/.test(n.protocol),`PDFFetchStream only supports http(s):// URLs.`);this.headers=gn(!0,t)}}class En extends mn{_abortController=new AbortController;_reader=null;constructor(e){super(e);let{disableRange:t,disableStream:n,rangeChunkSize:r,url:i,withCredentials:a}=e._source;this._isStreamingSupported=!n;Sn(i,new Headers(e.headers),a,this._abortController).then(n=>{e._responseOrigin=_n(n.url);Cn(n.status,i);this._reader=n.body.getReader();let a=n.headers,{contentLength:o,isRangeSupported:s}=vn({responseHeaders:a,isHttp:!0,rangeChunkSize:r,disableRange:t});this._contentLength=o;this._isRangeSupported=s;this._filename=yn(a);!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new se(`Streaming is disabled.`));this._headersCapability.resolve()}).catch(this._headersCapability.reject)}async read(){await this._headersCapability.promise;let{value:e,done:t}=await this._reader.read();if(t)return{value:e,done:t};this._loaded+=e.byteLength;this._callOnProgress();return{value:wn(e),done:!1}}cancel(e){this._reader?.cancel(e);this._abortController.abort()}}class Dn extends hn{_abortController=new AbortController;_readCapability=Promise.withResolvers();_reader=null;constructor(e,t,n){super(e,t,n);let{url:r,withCredentials:i}=e._source,a=new Headers(e.headers);a.append(`Range`,`bytes=${t}-${n-1}`);Sn(r,a,i,this._abortController).then(t=>{xn(_n(t.url),e._responseOrigin);Cn(t.status,r);this._reader=t.body.getReader();this._readCapability.resolve()}).catch(this._readCapability.reject)}async read(){await this._readCapability.promise;let{value:e,done:t}=await this._reader.read();return t?{value:e,done:t}:{value:wn(e),done:!1}}cancel(e){this._reader?.cancel(e);this._abortController.abort()}}function On(e){return e instanceof Uint8Array&&e.byteLength===e.buffer.byteLength?e.buffer:new Uint8Array(e).buffer}function kn(){for(let e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}class An extends pn{_progressiveDone=!1;_queuedChunks=[];constructor(e){super(e,jn,Mn);let{pdfDataRangeTransport:t}=e,{initialData:n,progressiveDone:r}=t;if(n?.length>0){let e=On(n);this._queuedChunks.push(e)}this._progressiveDone=r;t.transportReady(e=>{switch(e.type){case`range`:case`progressiveRead`:this.#e(e.begin,e.chunk);break;case`progressiveDone`:this._fullReader?.progressiveDone();this._progressiveDone=!0}})}#e(e,t){let n=On(t);if(e===void 0)this._fullReader?this._fullReader._enqueue(n):this._queuedChunks.push(n);else{let t=this._rangeReaders.keys().find(t=>t._begin===e);A(t,"#onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.");t._enqueue(n)}}getFullReader(){let e=super.getFullReader();this._queuedChunks=null;return e}getRangeReader(e,t){let n=super.getRangeReader(e,t);if(n){n.onDone=()=>this._rangeReaders.delete(n);this._source.pdfDataRangeTransport.requestDataRange(e,t)}return n}cancelAllRequests(e){super.cancelAllRequests(e);this._source.pdfDataRangeTransport.abort()}}class jn extends mn{#e=kn.bind(this);_done=!1;_queuedChunks=null;_requests=[];constructor(e){super(e);let{pdfDataRangeTransport:t,disableRange:n,disableStream:r}=e._source,{length:i,contentDispositionFilename:a}=t;this._queuedChunks=e._queuedChunks||[];for(let e of this._queuedChunks)this._loaded+=e.byteLength;this._done=e._progressiveDone;this._contentLength=i;this._isStreamingSupported=!r;this._isRangeSupported=!n;be(a)&&(this._filename=a);this._headersCapability.resolve();let o=this._loaded;Promise.resolve().then(()=>{o>0&&this._loaded===o&&this._callOnProgress()})}_enqueue(e){if(!this._done){this._requests.length>0?this._requests.shift().resolve({value:e,done:!1}):this._queuedChunks.push(e);this._loaded+=e.byteLength;this._callOnProgress()}}async read(){if(this._queuedChunks.length>0)return{value:this._queuedChunks.shift(),done:!1};if(this._done)return{value:void 0,done:!0};let e=Promise.withResolvers();this._requests.push(e);return e.promise}cancel(e){this._done=!0;this.#e()}progressiveDone(){this._done||=!0;this._queuedChunks.length===0&&this.#e()}}class Mn extends hn{#e=kn.bind(this);onDone=null;_begin=-1;_done=!1;_queuedChunk=null;_requests=[];constructor(e,t,n){super(e,t,n);this._begin=t}_enqueue(e){if(!this._done){if(this._requests.length===0)this._queuedChunk=e;else{this._requests.shift().resolve({value:e,done:!1});this.#e()}this._done=!0;this.onDone?.()}}async read(){if(this._queuedChunk){let e=this._queuedChunk;this._queuedChunk=null;return{value:e,done:!1}}if(this._done)return{value:void 0,done:!0};let e=Promise.withResolvers();this._requests.push(e);return e.promise}cancel(e){this._done=!0;this.#e();this.onDone?.()}}class Nn extends pn{#e=new WeakMap;_responseOrigin=null;constructor(e){super(e,Pn,Fn);let{httpHeaders:t,url:n}=e;this.url=n;this.isHttp=/https?:/.test(n.protocol);this.headers=gn(this.isHttp,t)}_request(e){let t=new XMLHttpRequest,n={validateStatus:null,onHeadersReceived:e.onHeadersReceived,onDone:e.onDone,onError:e.onError,onProgress:e.onProgress};this.#e.set(t,n);t.open(`GET`,this.url);t.withCredentials=this._source.withCredentials;for(let[e,n]of this.headers)t.setRequestHeader(e,n);if(this.isHttp&&`begin`in e&&`end`in e){t.setRequestHeader(`Range`,`bytes=${e.begin}-${e.end-1}`);n.validateStatus=e=>e===206||e===200}else n.validateStatus=e=>e===200;t.responseType=`arraybuffer`;A(e.onError,"Expected `onError` callback to be provided.");t.onerror=()=>e.onError(t.status);t.onreadystatechange=this.#n.bind(this,t);t.onprogress=this.#t.bind(this,t);t.send(null);return t}#t(e,t){this.#e.get(e)?.onProgress?.(t)}#n(e,t){let n=this.#e.get(e);if(!n)return;if(e.readyState>=2&&n.onHeadersReceived){n.onHeadersReceived();delete n.onHeadersReceived}if(e.readyState!==4)return;if(!this.#e.has(e))return;this.#e.delete(e);if(e.status===0&&this.isHttp){n.onError(e.status);return}let r=e.status||200;if(!n.validateStatus(r)){n.onError(e.status);return}let i=function(e){return typeof e==`string`?ce(e).buffer:e}(e.response);if(r===206){let t=e.getResponseHeader(`Content-Range`);if(/bytes (\d+)-(\d+)\/(\d+)/.test(t))n.onDone(i);else{O(`Missing or invalid "Content-Range" header.`);n.onError(0)}}else i?n.onDone(i):n.onError(e.status)}_abortRequest(e){if(this.#e.has(e)){this.#e.delete(e);e.abort()}}getRangeReader(e,t){let n=super.getRangeReader(e,t);n&&(n.onClosed=()=>this._rangeReaders.delete(n));return n}}class Pn extends mn{#e=kn.bind(this);_cachedChunks=[];_done=!1;_requests=[];_storedError=null;constructor(e){super(e);this._fullRequestXhr=e._request({onHeadersReceived:this.#t.bind(this),onDone:this.#n.bind(this),onError:this.#r.bind(this),onProgress:this.#i.bind(this)})}#t(){let e=this._stream,{disableRange:t,rangeChunkSize:n}=e._source,r=this._fullRequestXhr;e._responseOrigin=_n(r.responseURL);let i=r.getAllResponseHeaders(),a=new Headers(i?i.trimStart().replace(/[^\S ]+$/,``).split(/[\r\n]+/).map(e=>{let[t,...n]=e.split(`: `);return[t,n.join(`: `)]}):[]),{contentLength:o,isRangeSupported:s}=vn({responseHeaders:a,isHttp:e.isHttp,rangeChunkSize:n,disableRange:t});this._contentLength=o;this._isRangeSupported=s;this._filename=yn(a);this._isRangeSupported&&e._abortRequest(r);this._headersCapability.resolve()}#n(e){this._requests.length>0?this._requests.shift().resolve({value:e,done:!1}):this._cachedChunks.push(e);this._done=!0;this._cachedChunks.length===0&&this.#e()}#r(e){this._storedError=bn(e,this._stream.url);this._headersCapability.reject(this._storedError);for(let e of this._requests)e.reject(this._storedError);this._requests.length=0;this._cachedChunks.length=0}#i(e){this.onProgress?.({loaded:e.loaded,total:e.lengthComputable?e.total:this._contentLength})}async read(){await this._headersCapability.promise;if(this._storedError)throw this._storedError;if(this._cachedChunks.length>0)return{value:this._cachedChunks.shift(),done:!1};if(this._done)return{value:void 0,done:!0};let e=Promise.withResolvers();this._requests.push(e);return e.promise}cancel(e){this._done=!0;this._headersCapability.reject(e);this.#e();this._stream._abortRequest(this._fullRequestXhr);this._fullRequestXhr=null}}class Fn extends hn{#e=kn.bind(this);onClosed=null;_done=!1;_queuedChunk=null;_requests=[];_storedError=null;constructor(e,t,n){super(e,t,n);this._requestXhr=e._request({begin:t,end:n,onHeadersReceived:this.#t.bind(this),onDone:this.#n.bind(this),onError:this.#r.bind(this),onProgress:null})}#t(){let e=_n(this._requestXhr?.responseURL);try{xn(e,this._stream._responseOrigin)}catch(e){this._storedError=e;this.#r(0)}}#n(e){this._requests.length>0?this._requests.shift().resolve({value:e,done:!1}):this._queuedChunk=e;this._done=!0;this.#e();this.onClosed?.()}#r(e){this._storedError??=bn(e,this._stream.url);for(let e of this._requests)e.reject(this._storedError);this._requests.length=0;this._queuedChunk=null}async read(){if(this._storedError)throw this._storedError;if(this._queuedChunk!==null){let e=this._queuedChunk;this._queuedChunk=null;return{value:e,done:!1}}if(this._done)return{value:void 0,done:!0};let e=Promise.withResolvers();this._requests.push(e);return e.promise}cancel(e){this._done=!0;this.#e();this._stream._abortRequest(this._requestXhr);this.onClosed?.()}}function In(e,t=null){let n=process.getBuiltinModule(`fs`),{Readable:r}=process.getBuiltinModule(`stream`),i=n.createReadStream(e,t);return r.toWeb(i)}class Ln extends pn{constructor(e){super(e,Rn,zn);let{url:t}=e;A(t.protocol===`file:`,`PDFNodeStream only supports file:// URLs.`)}}class Rn extends mn{_reader=null;constructor(e){super(e);let{disableRange:t,disableStream:n,rangeChunkSize:r,url:i}=e._source;this._isStreamingSupported=!n;process.getBuiltinModule(`fs/promises`).lstat(i).then(e=>{let n=In(i);this._reader=n.getReader();let{size:a}=e;this._contentLength=a;this._isRangeSupported=!t&&a>2*r;!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new se(`Streaming is disabled.`));this._headersCapability.resolve()}).catch(e=>{e.code===`ENOENT`&&(e=bn(0,i));this._headersCapability.reject(e)})}async read(){await this._headersCapability.promise;let{value:e,done:t}=await this._reader.read();if(t)return{value:e,done:t};this._loaded+=e.byteLength;this._callOnProgress();return{value:wn(e),done:!1}}cancel(e){this._reader?.cancel(e)}}class zn extends hn{_readCapability=Promise.withResolvers();_reader=null;constructor(e,t,n){super(e,t,n);let{url:r}=e._source;try{let e=In(r,{start:t,end:n-1});this._reader=e.getReader();this._readCapability.resolve()}catch(e){this._readCapability.reject(e)}}async read(){await this._readCapability.promise;let{value:e,done:t}=await this._reader.read();return t?{value:e,done:t}:{value:wn(e),done:!1}}cancel(e){this._reader?.cancel(e)}}class Bn{static#e=null;static#t=``;static get workerPort(){return this.#e}static set workerPort(e){if(!(typeof Worker<`u`&&e instanceof Worker)&&e!==null)throw Error("Invalid `workerPort` type.");this.#e=e}static get workerSrc(){return this.#t}static set workerSrc(e){if(typeof e!=`string`)throw Error("Invalid `workerSrc` type.");this.#t=e}}class Vn{#e;#t;constructor({parsedData:e,rawData:t}){this.#e=e;this.#t=t}getRaw(){return this.#t}get(e){return this.#e.get(e)??null}[Symbol.iterator](){return this.#e.entries()}}const Hn=Symbol(`INTERNAL`);class Un{#e=!1;#t=!1;#n=!1;#r=!0;constructor(e,{name:t,intent:n,usage:r,rbGroups:i}){this.#e=!!(e&2);this.#t=!!(e&4);this.name=t;this.intent=n;this.usage=r;this.rbGroups=i}get visible(){if(this.#n)return this.#r;if(!this.#r)return!1;let{print:e,view:t}=this.usage;return this.#e?t?.viewState!==`OFF`:!this.#t||e?.printState!==`OFF`}_setVisible(e,t,n=!1){e!==Hn&&k("Internal method `_setVisible` called.");this.#n=n;this.#r=t}}class Wn{#e=null;#t=new Map;#n=null;#r=null;constructor(e,t=2){this.renderingIntent=t;this.name=null;this.creator=null;if(e!==null){this.name=e.name;this.creator=e.creator;this.#r=e.order;for(let n of e.groups)this.#t.set(n.id,new Un(t,n));if(e.baseState===`OFF`)for(let e of this.#t.values())e._setVisible(Hn,!1);for(let t of e.on)this.#t.get(t)._setVisible(Hn,!0);for(let t of e.off)this.#t.get(t)._setVisible(Hn,!1);this.#n=this.getHash()}}#i(e){let t=e.length;if(t<2)return!0;let n=e[0];for(let r=1;r<t;r++){let t=e[r],i;if(Array.isArray(t))i=this.#i(t);else{if(!this.#t.has(t)){O(`Optional content group not found: ${t}`);return!0}i=this.#t.get(t).visible}switch(n){case`And`:if(!i)return!1;break;case`Or`:if(i)return!0;break;case`Not`:return!i;default:return!0}}return n===`And`}isVisible(e){if(this.#t.size===0)return!0;if(!e){D(`Optional content group not defined.`);return!0}if(e.type===`OCG`){if(!this.#t.has(e.id)){O(`Optional content group not found: ${e.id}`);return!0}return this.#t.get(e.id).visible}if(e.type===`OCMD`){if(e.expression)return this.#i(e.expression);if(!e.policy||e.policy===`AnyOn`){for(let t of e.ids){if(!this.#t.has(t)){O(`Optional content group not found: ${t}`);return!0}if(this.#t.get(t).visible)return!0}return!1}if(e.policy===`AllOn`){for(let t of e.ids){if(!this.#t.has(t)){O(`Optional content group not found: ${t}`);return!0}if(!this.#t.get(t).visible)return!1}return!0}if(e.policy===`AnyOff`){for(let t of e.ids){if(!this.#t.has(t)){O(`Optional content group not found: ${t}`);return!0}if(!this.#t.get(t).visible)return!0}return!1}if(e.policy===`AllOff`){for(let t of e.ids){if(!this.#t.has(t)){O(`Optional content group not found: ${t}`);return!0}if(this.#t.get(t).visible)return!1}return!0}O(`Unknown optional content policy ${e.policy}.`);return!0}O(`Unknown group type ${e.type}.`);return!0}setVisibility(e,t=!0,n=!0){let r=this.#t.get(e);if(r){if(n&&t&&r.rbGroups.length)for(let t of r.rbGroups)for(let n of t)n!==e&&this.#t.get(n)?._setVisible(Hn,!1,!0);r._setVisible(Hn,!!t,!0);this.#e=null}else O(`Optional content group not found: ${e}`)}setOCGState({state:e,preserveRB:t}){let n;for(let r of e){switch(r){case`ON`:case`OFF`:case`Toggle`:n=r;continue}let e=this.#t.get(r);if(e)switch(n){case`ON`:this.setVisibility(r,!0,t);break;case`OFF`:this.setVisibility(r,!1,t);break;case`Toggle`:this.setVisibility(r,!e.visible,t)}}this.#e=null}get hasInitialVisibility(){return this.#n===null||this.getHash()===this.#n}getOrder(){return this.#t.size?this.#r?this.#r.slice():[...this.#t.keys()]:null}getGroup(e){return this.#t.get(e)||null}getHash(){if(this.#e!==null)return this.#e;let e=new Je;for(let[t,n]of this.#t)e.update(`${t}:${n.visible}`);return this.#e=e.hexdigest()}[Symbol.iterator](){return this.#t.entries()}}class Gn{#e=null;#t=null;#n=0;#r=null;#i=null;get pagesNumber(){return this.#n}set pagesNumber(e){if(this.#n!==e){this.#n=e;this.#e=null;this.#t=null}}#a(){if(this.#e)return;let e=this.#n,t=this.#e=new Uint32Array(e);for(let n=0;n<e;n++)t[n]=n+1;this.#t=new Int32Array(t)}#o(){let e=new Map,t=this.#e;for(let n=0,r=this.#n;n<r;n++){let r=t[n],i=e.get(r);i?i.push(n+1):e.set(r,[n+1])}return e}movePages(e,t,n){this.#a();let r=this.#e,i=this.#o(),a=t.length,o=new Uint32Array(a),s=0;for(let e=0;e<a;e++){let i=t[e]-1;o[e]=r[i];i<n&&s++}let c=this.#n,l=c-a,u=F(n-s,0,l);for(let t=0,n=0;t<c;t++)e.has(t+1)||(r[n++]=r[t]);r.copyWithin(u+a,u,l);r.set(o,u);this.#s(i);r.every((e,t)=>e===t+1)&&(this.#e=null)}deletePages(e){this.#a();let t=this.#e,n=this.#o();this.#i={pageNumberToId:t.slice(),pagesNumber:this.#n,prevPageNumbers:this.#t.slice()};let r=this.#n-e.length;this.#n=r;let i=this.#e=new Uint32Array(r);this.#t=new Int32Array(r);let a=0,o=0;for(let n of e){let e=n-1;if(e!==a){i.set(t.subarray(a,e),o);o+=e-a}a=e+1}a<t.length&&i.set(t.subarray(a),o);this.#s(n,new Set(e))}cancelDelete(){if(this.#i){this.#e=this.#i.pageNumberToId;this.#n=this.#i.pagesNumber;this.#t=this.#i.prevPageNumbers;this.#i=null}}cleanSavedData(){this.#i=null}copyPages(e){this.#a();this.#r={pageNumbers:e,pageIds:e.map(e=>this.#e[e-1])}}cancelCopy(){this.#r=null}pastePages(e){this.#a();let t=this.#e,n=this.#o(),{pageNumbers:r,pageIds:i}=this.#r,a=this.#n+r.length;this.#n=a;let o=this.#e=new Uint32Array(a);this.#t=new Int32Array(a);o.set(t.subarray(0,e),0);o.set(i,e);o.set(t.subarray(e),e+r.length);this.#s(n,null,e,r);this.#r=null}#s(e,t=null,n=-1,r=null){let i=this.#t,a=this.#e,o=n+(r?.length??0),s=new Map;for(let c=0,l=this.#n;c<l;c++){if(c>=n&&c<o){i[c]=-r[c-n];continue}let l=a[c],u=e.get(l),d=s.get(l)||0;if(t&&u)for(;d<u.length&&t.has(u[d]);)d++;i[c]=u?.[d];s.set(l,d+1)}}hasBeenAltered(){return this.#e!==null}getPageMappingForSaving(e=null){e??=this.#o();let t=0;for(let n of e.values())t=Math.max(t,n.length);let n=Array(t);for(let e=0;e<t;e++)n[e]={document:null,pageIndices:[],includePages:[]};for(let[t,r]of e)for(let e=0,i=r.length;e<i;e++)n[e].includePages.push([t-1,r[e]-1]);for(let{includePages:e,pageIndices:t}of n){e.sort((e,t)=>e[0]-t[0]);for(let n=0,r=e.length;n<r;n++){t.push(e[n][1]);e[n]=e[n][0]}}return n}extractPages(e){e=Array.from(e).sort((e,t)=>e-t);let t=new Map;for(let n=0,r=e.length;n<r;n++){let r=this.getPageId(e[n]);t.getOrInsertComputed(r,ue).push(n+1)}return this.getPageMappingForSaving(t)}getPrevPageNumber(e){return this.#t?.[e-1]??0}getPageNumber(e){if(!this.#e)return e;let t=this.#e;for(let n=0,r=this.#n;n<r;n++)if(t[n]===e)return n+1;return 0}getPageId(e){return this.#e?.[e-1]??e}getMapping(){return this.#e?.subarray(0,this.pagesNumber)}}const Kn=Symbol(`INITIAL_DATA`),qn=()=>({...Promise.withResolvers(),data:Kn});class Jn{#e=new Map;get(e,t=null){if(t){let n=this.#e.getOrInsertComputed(e,qn);n.promise.then(()=>t(n.data));return null}let n=this.#e.get(e);if(!n||n.data===Kn)throw Error(`Requesting object that isn't resolved yet ${e}.`);return n.data}has(e){let t=this.#e.get(e);return!!t&&t.data!==Kn}delete(e){let t=this.#e.get(e);if(!t||t.data===Kn)return!1;this.#e.delete(e);return!0}resolve(e,t=null){let n=this.#e.getOrInsertComputed(e,qn);if(n.data!==Kn)throw Error(`Object already resolved ${e}.`);n.data=t;n.resolve()}clear(){for(let{data:e}of this.#e.values())e?.bitmap?.close();this.#e.clear()}*[Symbol.iterator](){for(let[e,{data:t}]of this.#e)t!==Kn&&(yield[e,t])}}class K{#e=Promise.withResolvers();#t=null;#n=!1;#r=!!globalThis.FontInspector?.enabled;#i=null;#a=null;#o=null;#s=0;#c=0;#l=null;#u=null;#d=0;#f=0;#p=Object.create(null);#m=[];#h=null;#g=[];#_=new WeakMap;#v=null;static#y=new Map;static#b=new Map;static#x=new WeakMap;static#S=null;static#C=new Set;constructor({textContentSource:e,images:t,container:n,viewport:r}){if(e instanceof ReadableStream)this.#h=e;else{if(typeof e!=`object`)throw Error(`No "textContentSource" parameter specified.`);this.#h=new ReadableStream({start(t){t.enqueue(e);t.close()}})}this.#t=this.#u=n;this.#i=t;this.#f=r.scale*Oe.pixelRatio;this.#d=r.rotation;this.#o={div:null,properties:null,ctx:null};let{pageWidth:i,pageHeight:a,pageX:o,pageY:s}=r.rawDims;this.#v=[1,0,0,-1,-o,s+a];this.#c=i;this.#s=a;K.#k();n.style.setProperty(`--min-font-size`,K.#S);De(n,r);this.#e.promise.finally(()=>{K.#C.delete(this);this.#o=null;this.#p=null}).catch(()=>{})}static get fontFamilyMap(){let{isWindows:e,isFirefox:t}=N.platform;return j(this,`fontFamilyMap`,new Map([[`sans-serif`,(e&&t?`Calibri, `:``)+`sans-serif`],[`monospace`,(e&&t?`Lucida Console, `:``)+`monospace`]]))}render(){this.#i&&this.#t.append(this.#i.render());let e=()=>{this.#l.read().then(({value:t,done:n})=>{if(n)this.#e.resolve();else{this.#a??=t.lang;Object.assign(this.#p,t.styles);this.#w(t.items);e()}},this.#e.reject)};this.#l=this.#h.getReader();K.#C.add(this);e();return this.#e.promise}update({viewport:e,onBefore:t=null}){let n=e.scale*Oe.pixelRatio,r=e.rotation;if(r!==this.#d){t?.();this.#d=r;De(this.#u,{rotation:r})}if(n!==this.#f){t?.();this.#f=n;let e={div:null,properties:null,ctx:K.#D(this.#a)};for(let t of this.#g){e.properties=this.#_.get(t);e.div=t;this.#E(e)}}}cancel(){let e=new se(`TextLayer task cancelled.`);this.#l?.cancel(e).catch(()=>{});this.#l=null;this.#e.reject(e)}get textDivs(){return this.#g}get textContentItemsStr(){return this.#m}#w(e){if(this.#n)return;this.#o.ctx??=K.#D(this.#a);let t=this.#g,n=this.#m;for(let r of e){if(t.length>1e5){O(`Ignoring additional textDivs for performance reasons.`);this.#n=!0;return}if(r.str!==void 0){n.push(r.str);this.#T(r)}else if(r.type===`beginMarkedContentProps`||r.type===`beginMarkedContent`){let e=this.#t;this.#t=document.createElement(`span`);this.#t.classList.add(`markedContent`);r.id&&this.#t.setAttribute(`id`,`${r.id}`);r.tag===`Artifact`&&(this.#t.ariaHidden=!0);e.append(this.#t)}else r.type===`endMarkedContent`&&(this.#t=this.#t.parentNode)}}#T(e){let t=document.createElement(`span`),n={angle:0,canvasWidth:0,hasText:e.str!==``,hasEOL:e.hasEOL,fontSize:0};this.#g.push(t);let r=P.transform(this.#v,e.transform),i=Math.atan2(r[1],r[0]),a=this.#p[e.fontName];a.vertical&&(i+=Math.PI/2);let o=this.#r&&a.fontSubstitution||a.fontFamily;o=K.fontFamilyMap.get(o)||o;let s=Math.hypot(r[2],r[3]),c=s*K.#A(o,a,this.#a),l,u;if(i===0){l=r[4];u=r[5]-c}else{l=r[4]+c*Math.sin(i);u=r[5]-c*Math.cos(i)}let d=t.style;d.left=`${(100*l/this.#c).toFixed(2)}%`;d.top=`${(100*u/this.#s).toFixed(2)}%`;d.setProperty(`--font-height`,`${s.toFixed(2)}px`);d.fontFamily=o;n.fontSize=s;t.setAttribute(`role`,`presentation`);t.textContent=e.str;t.dir=e.dir;this.#r&&(t.dataset.fontName=a.fontSubstitutionLoadedName||e.fontName);i!==0&&(n.angle=180/Math.PI*i);let f=!1;if(e.str.length>1)f=!0;else if(e.str!==` `&&e.transform[0]!==e.transform[3]){let t=Math.abs(e.transform[0]),n=Math.abs(e.transform[3]);t!==n&&Math.max(t,n)/Math.min(t,n)>1.5&&(f=!0)}f&&(n.canvasWidth=a.vertical?e.height:e.width);this.#_.set(t,n);this.#o.div=t;this.#o.properties=n;this.#E(this.#o);n.hasText&&this.#t.append(t);if(n.hasEOL){let e=document.createElement(`br`);e.setAttribute(`role`,`presentation`);this.#t.append(e)}}#E(e){let{div:t,properties:n,ctx:r}=e,{style:i}=t;if(n.canvasWidth!==0&&n.hasText){let{fontFamily:e}=i,{canvasWidth:a,fontSize:o}=n;K.#O(r,o*this.#f,e);let{width:s}=r.measureText(t.textContent);s>0&&i.setProperty(`--scale-x`,a*this.#f/s)}n.angle!==0&&i.setProperty(`--rotate`,`${n.angle}deg`)}static cleanup(){if(!(this.#C.size>0)){this.#y.clear();for(let{canvas:e}of this.#b.values())e.remove();this.#b.clear()}}static#D(e=null){let t=this.#b.get(e||=``);if(!t){let n=document.createElement(`canvas`);n.className=`hiddenCanvasElement`;n.lang=e;document.body.append(n);t=n.getContext(`2d`,{alpha:!1,willReadFrequently:!0});this.#b.set(e,t);this.#x.set(t,{size:0,family:``})}return t}static#O(e,t,n){let r=this.#x.get(e);if(t!==r.size||n!==r.family){e.font=`${t}px ${n}`;r.size=t;r.family=n}}static#k(){if(this.#S!==null)return;let e=document.createElement(`div`);e.style.opacity=0;e.style.lineHeight=1;e.style.fontSize=`1px`;e.style.position=`absolute`;e.textContent=`X`;document.body.append(e);this.#S=e.getBoundingClientRect().height;e.remove()}static#A(e,t,n){let r=this.#y.get(e);if(r)return r;let i=this.#D(n);i.canvas.width=i.canvas.height=30;this.#O(i,30,e);let a=i.measureText(``),o=a.fontBoundingBoxAscent,s=Math.abs(a.fontBoundingBoxDescent);i.canvas.width=i.canvas.height=0;let c=.8;if(o)c=o/(o+s);else{N.platform.isFirefox&&O("Enable the `dom.textMetrics.fontBoundingBox.enabled` preference in `about:config` to improve TextLayer rendering.");t.ascent?c=t.ascent:t.descent&&(c=1+t.descent)}this.#y.set(e,c);return c}}function Yn(e={}){let t=new Xn,{docId:n}=t,r=e.url?function(e){if(e instanceof URL)return e;if(typeof e==`string`){if(d){if(/^[a-z][a-z0-9\-+.]+:/i.test(e))return new URL(e);let t=process.getBuiltinModule(`url`);return new URL(t.pathToFileURL(e))}let t=URL.parse(e,window.location);if(t)return t}throw Error(`Invalid PDF url data: either string or URL-object is expected in the url property.`)}(e.url):null,i=e.data?function(e){if(d&&typeof Buffer<`u`&&e instanceof Buffer)throw Error("Please provide binary data as `Uint8Array`, rather than `Buffer`.");if(e instanceof Uint8Array&&e.byteLength===e.buffer.byteLength)return e;if(typeof e==`string`)return ce(e);if(e instanceof ArrayBuffer||ArrayBuffer.isView(e)||typeof e==`object`&&!isNaN(e?.length))return new Uint8Array(e);throw Error(`Invalid PDF binary data: either TypedArray, string, or array-like object is expected in the data property.`)}(e.data):null,a=e.httpHeaders||null,o=!0===e.withCredentials,s=e.password??null,c=e.range instanceof Zn?e.range:null,l=Number.isInteger(e.rangeChunkSize)&&e.rangeChunkSize>0?e.rangeChunkSize:65536,u=e.worker instanceof q?e.worker:null,f=e.verbosity,p=typeof e.docBaseUrl!=`string`||ye(e.docBaseUrl)?null:e.docBaseUrl,m=Et(e.cMapUrl),h=!1!==e.cMapPacked,g=Et(e.iccUrl),_=Et(e.standardFontDataUrl),v=Et(e.wasmUrl),y=!0!==e.stopAtErrors,b=Number.isInteger(e.maxImageSize)&&e.maxImageSize>-1?e.maxImageSize:-1,x=typeof e.isOffscreenCanvasSupported==`boolean`?e.isOffscreenCanvasSupported:!d,S=typeof e.isImageDecoderSupported==`boolean`?e.isImageDecoderSupported:!d,C=Number.isInteger(e.canvasMaxAreaInBytes)?e.canvasMaxAreaInBytes:-1,w=typeof e.disableFontFace==`boolean`?e.disableFontFace:d,E=!0===e.fontExtraProperties,D=!0===e.enableXfa,O=e.ownerDocument||globalThis.document,k=!0===e.disableRange,A=!0===e.disableStream,ee=!0===e.disableAutoFetch,te=!0===e.pdfBug,j=e.CanvasFactory||(d?Rt:Pt),M=e.FilterFactory||(d?Lt:It),ne=e.BinaryDataFactory||(d?zt:Mt),re=!0===e.enableHWA,ie=!0===e.enableWebGPU?function(){return Bt.init()}():Promise.resolve(!1),ae=!1!==e.useWasm,oe=e.pagesMapper||new Gn,se=typeof e.useSystemFonts==`boolean`?e.useSystemFonts:!d&&!w,N=typeof e.useWorkerFetch==`boolean`?e.useWorkerFetch:!!(ne===Mt&&m&&h&&_&&v&&Se(m,document.baseURI)&&Se(_,document.baseURI)&&Se(v,document.baseURI));T(f);let P={canvasFactory:new j({ownerDocument:O,enableHWA:re}),filterFactory:new M({docId:n,ownerDocument:O}),binaryDataFactory:N?null:new ne({cMapUrl:m,standardFontDataUrl:_,wasmUrl:v})};if(!u){u=q.create({verbosity:f,port:Bn.workerPort});t._worker=u}let le={docId:n,apiVersion:`6.0.92`,data:i,password:s,disableAutoFetch:ee,rangeChunkSize:l,docBaseUrl:p,enableXfa:D,evaluatorOptions:{maxImageSize:b,disableFontFace:w,ignoreErrors:y,isOffscreenCanvasSupported:x,isImageDecoderSupported:S,canvasMaxAreaInBytes:C,fontExtraProperties:E,useSystemFonts:se,useWasm:ae,useWorkerFetch:N,cMapUrl:m,cMapPacked:h,iccUrl:g,standardFontDataUrl:_,wasmUrl:v,hasGPU:!1}},ue={ownerDocument:O,pdfBug:te,styleElement:null,enableHWA:re,loadingParams:{disableAutoFetch:ee,enableXfa:D}};Promise.all([u.promise,ie]).then(function([,e]){if(u.destroyed)throw Error(`Worker was destroyed`);le.evaluatorOptions.hasGPU=e;let s=u.messageHandler.sendWithPromise(`GetDocRequest`,le,i?[i.buffer]:null),f;if(!i){if(c)f=new An({pdfDataRangeTransport:c,disableRange:k,disableStream:A});else{if(!r)throw Error("getDocument - expected either `data`, `range`, or `url` parameter.");f=new(function(e){return Se(e)?Tn:d?Ln:Nn}(r))({url:r,httpHeaders:a,withCredentials:o,rangeChunkSize:l,disableRange:k,disableStream:A})}}return s.then(e=>{if(u.destroyed)throw Error(`Worker was destroyed`);let r=new At(n,e,u.port),i=new er(r,t,f,ue,P,oe);t._transport=i;if(t.destroyed)throw Error(`Loading aborted`);r.send(`Ready`,null)})}).catch(t._capability.reject).finally(t._setupCapability.resolve);return t}class Xn{static#e=0;_capability=Promise.withResolvers();_setupCapability=Promise.withResolvers();_transport=null;_worker=null;docId=`d`+Xn.#e++;destroyed=!1;onPassword=null;onProgress=null;get promise(){return this._capability.promise}async destroy(){this.destroyed=!0;this._capability.promise.catch(()=>{});try{this._worker?.port&&(this._worker._pendingDestroy=!0);await this._setupCapability.promise;await this._transport?.destroy()}catch(e){this._worker?.port&&delete this._worker._pendingDestroy;throw e}this._transport=null;this._worker?.destroy();this._worker=null}async getData(){return this._transport.getData()}}class Zn{#e=Promise.withResolvers();#t=null;constructor(e,t,n=!1,r=null){this.length=e;this.initialData=t;this.progressiveDone=n;this.contentDispositionFilename=r}onDataRange(e,t){this.#t({type:`range`,begin:e,chunk:t})}onDataProgressiveRead(e){this.#e.promise.then(()=>{this.#t({type:`progressiveRead`,chunk:e})})}onDataProgressiveDone(){this.#e.promise.then(()=>{this.#t({type:`progressiveDone`})})}transportReady(e){this.#t=e;this.#e.resolve()}requestDataRange(e,t){k(`Abstract method PDFDataRangeTransport.requestDataRange`)}abort(){}}class Qn{constructor(e,t){this._pdfInfo=e;this._transport=t}get pagesMapper(){return this._transport.pagesMapper}get annotationStorage(){return this._transport.annotationStorage}get canvasFactory(){return this._transport.canvasFactory}get filterFactory(){return this._transport.filterFactory}get numPages(){return this._pdfInfo.numPages}get fingerprints(){return this._pdfInfo.fingerprints}get isPureXfa(){return j(this,`isPureXfa`,!!this._transport._htmlForXfa)}get allXfaHtml(){return this._transport._htmlForXfa}getPage(e){return this._transport.getPage(e)}getPageIndex(e){return this._transport.getPageIndex(e)}getDestinations(){return this._transport.getDestinations()}getDestination(e){return this._transport.getDestination(e)}getPageLabels(){return this._transport.getPageLabels()}getPageLayout(){return this._transport.getPageLayout()}getPageMode(){return this._transport.getPageMode()}getViewerPreferences(){return this._transport.getViewerPreferences()}getOpenAction(){return this._transport.getOpenAction()}getAttachments(){return this._transport.getAttachments()}getAnnotationsByType(e,t){return this._transport.getAnnotationsByType(e,t)}getJSActions(){return this._transport.getDocJSActions()}getOutline(){return this._transport.getOutline()}getOptionalContentConfig({intent:e=`display`}={}){let{renderingIntent:t}=this._transport.getRenderingIntent(e);return this._transport.getOptionalContentConfig(t)}getPermissions(){return this._transport.getPermissions()}getMetadata(){return this._transport.getMetadata()}getMarkInfo(){return this._transport.getMarkInfo()}getData(){return this._transport.getData()}saveDocument(){return this._transport.saveDocument()}extractPages(e){return this._transport.extractPages(e)}getDownloadInfo(){return this._transport.downloadInfoCapability.promise}getRawData(e){return this._transport.getRawData(e)}cleanup(e=!1){return this._transport.startCleanup(e||this.isPureXfa)}cachedPageNumber(e){return this._transport.cachedPageNumber(e)}get loadingParams(){return this._transport.loadingParams}get loadingTask(){return this._transport.loadingTask}getFieldObjects(){return this._transport.getFieldObjects()}hasJSActions(){return this._transport.hasJSActions()}getCalculationOrderIds(){return this._transport.getCalculationOrderIds()}}class $n{#e=!1;#t=null;constructor(e,t,n,r,i=!1){this._pageIndex=e;this._pageInfo=t;this._transport=n;this._stats=i?new xe:null;this._pdfBug=i;this.commonObjs=n.commonObjs;this.objs=new Jn;this._intentStates=new Map;this.destroyed=!1;this.recordedBBoxes=null;this.#t=r;this.imageCoordinates=null}clone(e){let t=new $n(e,this._pageInfo,this._transport,this.#t,this._pdfBug);t.clonedFromIndex=this.clonedFromIndex??this._pageIndex;this._transport.updatePage(t);return t}get pageNumber(){return this._pageIndex+1}set pageNumber(e){this._pageIndex=e-1;this._transport.updatePage(this)}get rotate(){return this._pageInfo.rotate}get ref(){return this._pageInfo.ref}get userUnit(){return this._pageInfo.userUnit}get view(){return this._pageInfo.view}getViewport({scale:e,rotation:t=this.rotate,offsetX:n=0,offsetY:r=0,dontFlip:i=!1}={}){return new _e({viewBox:this.view,userUnit:this.userUnit,scale:e,rotation:t,offsetX:n,offsetY:r,dontFlip:i})}getAnnotations({intent:e=`display`}={}){let{renderingIntent:t}=this._transport.getRenderingIntent(e);return this._transport.getAnnotations(this._pageIndex,t)}getJSActions(){return this._transport.getPageJSActions(this._pageIndex)}get filterFactory(){return this._transport.filterFactory}get isPureXfa(){return j(this,`isPureXfa`,!!this._transport._htmlForXfa)}async getXfa(){return this._transport._htmlForXfa?.children[this._pageIndex]||null}render({canvasContext:e,canvas:t=e.canvas,viewport:n,intent:r=`display`,annotationMode:i=g.ENABLE,transform:a=null,background:o=null,optionalContentConfigPromise:s=null,annotationCanvasMap:c=null,pageColors:l=null,printAnnotationStorage:u=null,isEditing:d=!1,recordImages:f=!1,recordOperations:p=!1,operationsFilter:m=null,renderingBudget:h=null,renderingScheduler:_=null}){this._stats?.time(`Overall`);let v=this._transport.getRenderingIntent(r,i,u,d),{renderingIntent:y,cacheKey:b}=v;this.#e=!1;s||=this._transport.getOptionalContentConfig(y);let x=this._intentStates.getOrInsertComputed(b,fe);if(x.streamReaderCancelTimeout){clearTimeout(x.streamReaderCancelTimeout);x.streamReaderCancelTimeout=null}let S=!!(y&4);if(!x.displayReadyCapability){x.displayReadyCapability=Promise.withResolvers();x.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null};this._stats?.time(`Page Request`);this._pumpOperatorList(v)}let C=!(!this._pdfBug||!globalThis.StepperManager?.enabled),w=!!t&&!this.recordedBBoxes&&(p||C),T=!!t&&!this.imageCoordinates&&f,E=e=>{x.renderTasks.delete(k);if(w){let e=k.gfx?.dependencyTracker.take();if(e){k.stepper?.setOperatorBBoxes(e,k.gfx.dependencyTracker.takeDebugMetadata());p&&(this.recordedBBoxes=e)}}T&&!e&&(this.imageCoordinates=k.gfx?.imagesTracker.take());S&&(this.#e=!0);this.#n();if(e){k.capability.reject(e);this._abortOperatorList({intentState:x,reason:e instanceof Error?e:Error(e)})}else k.capability.resolve();if(this._stats){this._stats.timeEnd(`Rendering`);this._stats.timeEnd(`Overall`);globalThis.Stats?.enabled&&globalThis.Stats.add(this.pageNumber,this._stats)}},D=null,O=null;(w||T)&&(O=new at(t,x.operatorList.length));w&&(D=new ot(O,C));let k=new nr({callback:E,params:{canvas:t,canvasContext:e,dependencyTracker:D??O,imagesTracker:T?new ht(t):null,viewport:n,transform:a,background:o},objs:this.objs,commonObjs:this.commonObjs,annotationCanvasMap:c,operatorList:x.operatorList,pageIndex:this._pageIndex,canvasFactory:this._transport.canvasFactory,filterFactory:this._transport.filterFactory,useRequestAnimationFrame:!S,pdfBug:this._pdfBug,pageColors:l,enableHWA:this._transport.enableHWA,operationsFilter:m,renderingBudget:h,renderingScheduler:_});(x.renderTasks||=new Set).add(k);let A=k.task;Promise.all([x.displayReadyCapability.promise,s]).then(([e,t])=>{if(this.destroyed)E();else{this._stats?.time(`Rendering`);if(!(t.renderingIntent&y))throw Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");k.initializeGraphics({transparency:e,optionalContentConfig:t});k.operatorListChanged()}}).catch(E);return A}getOperatorList({intent:e=`display`,annotationMode:t=g.ENABLE,printAnnotationStorage:n=null,isEditing:r=!1}={}){let i=this._transport.getRenderingIntent(e,t,n,r,!0),a=this._intentStates.getOrInsertComputed(i.cacheKey,fe),o;if(!a.opListReadCapability){o=Object.create(null);o.operatorListChanged=function(){if(a.operatorList.lastChunk){a.opListReadCapability.resolve(a.operatorList);a.renderTasks.delete(o)}};a.opListReadCapability=Promise.withResolvers();(a.renderTasks||=new Set).add(o);a.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null};this._stats?.time(`Page Request`);this._pumpOperatorList(i)}return a.opListReadCapability.promise}streamTextContent({includeMarkedContent:e=!1,disableNormalization:t=!1}={}){return this._transport.messageHandler.sendWithStream(`GetTextContent`,{pageId:this.#t.getPageId(this._pageIndex+1)-1,pageIndex:this._pageIndex,includeMarkedContent:!0===e,disableNormalization:!0===t},{highWaterMark:100,size:e=>e.items.length})}async getTextContent(e={}){if(this._transport._htmlForXfa)return this.getXfa().then(e=>pe.textContent(e));let t=this.streamTextContent(e),n={items:[],styles:Object.create(null),lang:null};for await(let e of t){n.lang??=e.lang;Object.assign(n.styles,e.styles);n.items.push(...e.items)}return n}getStructTree(){return this._transport.getStructTree(this._pageIndex)}getGeospatialPDFMetadata(){return this._transport.getGeospatialPDFMetadata(this._pageIndex)}_destroy(){this.destroyed=!0;let e=[];for(let t of this._intentStates.values()){this._abortOperatorList({intentState:t,reason:Error(`Page was destroyed.`),force:!0});if(!t.opListReadCapability)for(let n of t.renderTasks){e.push(n.completed);n.cancel()}}this.objs.clear();this.#e=!1;return Promise.all(e)}cleanup(e=!1){this.#e=!0;let t=this.#n();e&&t&&(this._stats&&=new xe);return t}#n(){if(!this.#e||this.destroyed)return!1;for(let{renderTasks:e,operatorList:t}of this._intentStates.values())if(e.size>0||!t.lastChunk)return!1;this._intentStates.clear();this.objs.clear();this.#e=!1;return!0}_startRenderPage(e,t){let n=this._intentStates.get(t);if(n){this._stats?.timeEnd(`Page Request`);n.displayReadyCapability?.resolve(e)}}_renderPageChunk(e,t){for(let n=0,r=e.length;n<r;n++){t.operatorList.fnArray.push(e.fnArray[n]);t.operatorList.argsArray.push(e.argsArray[n])}t.operatorList.lastChunk=e.lastChunk;t.operatorList.separateAnnots=e.separateAnnots;for(let e of t.renderTasks)e.operatorListChanged();e.lastChunk&&this.#n()}_pumpOperatorList({renderingIntent:e,cacheKey:t,annotationStorageSerializable:n,modifiedIds:r}){let{map:i,transfer:a}=n,o=this._transport.messageHandler.sendWithStream(`GetOperatorList`,{pageId:this.#t.getPageId(this._pageIndex+1)-1,pageIndex:this._pageIndex,intent:e,cacheKey:t,annotationStorage:i,modifiedIds:r},void 0,a).getReader(),s=this._intentStates.get(t);s.streamReader=o;let c=()=>{o.read().then(({value:e,done:t})=>{if(t)s.streamReader=null;else if(!this._transport.destroyed){this._renderPageChunk(e,s);c()}},e=>{s.streamReader=null;if(!this._transport.destroyed){if(s.operatorList){s.operatorList.lastChunk=!0;for(let e of s.renderTasks)e.operatorListChanged();this.#n()}if(s.displayReadyCapability)s.displayReadyCapability.reject(e);else{if(!s.opListReadCapability)throw e;s.opListReadCapability.reject(e)}}})};c()}_abortOperatorList({intentState:e,reason:t,force:n=!1}){if(e.streamReader){if(e.streamReaderCancelTimeout){clearTimeout(e.streamReaderCancelTimeout);e.streamReaderCancelTimeout=null}if(!n){if(e.renderTasks.size>0)return;if(t instanceof ve){let n=100;t.extraDelay>0&&t.extraDelay<1e3&&(n+=t.extraDelay);e.streamReaderCancelTimeout=setTimeout(()=>{e.streamReaderCancelTimeout=null;this._abortOperatorList({intentState:e,reason:t,force:!0})},n);return}}e.streamReader.cancel(new se(t.message)).catch(()=>{});e.streamReader=null;if(!this._transport.destroyed){for(let[t,n]of this._intentStates)if(n===e){this._intentStates.delete(t);break}this.cleanup()}}}get stats(){return this._stats}}class q{#e=Promise.withResolvers();#t=null;#n=null;#r=null;static#i=0;static#a=!1;static#o=new WeakMap;static{if(d){this.#a=!0;Bn.workerSrc||=`./pdf.worker.mjs`}this._isSameOrigin=(e,t)=>{let n=URL.parse(e);if(!n?.origin||n.origin===`null`)return!1;let r=new URL(t,n);return n.origin===r.origin};this._createCDNWrapper=e=>{let t=`await import("${e}");`;return URL.createObjectURL(new Blob([t],{type:`text/javascript`}))}}constructor({name:e=null,port:t=null,verbosity:n=E()}={}){this.name=e;this.destroyed=!1;this.verbosity=n;if(t){if(q.#o.has(t))throw Error(`Cannot use more than one PDFWorker per port.`);q.#o.set(t,this);this.#c(t)}else this.#l()}get promise(){return this.#e.promise}#s(){this.#e.resolve();this.#t.send(`configure`,{verbosity:this.verbosity})}get port(){return this.#n}get messageHandler(){return this.#t}#c(e){this.#n=e;this.#t=new At(`main`,`worker`,e);this.#t.on(`ready`,()=>{});this.#s()}#l(){if(q.#a||q.#d){this.#u();return}let{workerSrc:e}=q;try{q._isSameOrigin(window.location,e)||(e=q._createCDNWrapper(new URL(e,window.location).href));let t=new Worker(e,{type:`module`}),n=new At(`main`,`worker`,t),r=()=>{i.abort();n.destroy();t.terminate();this.destroyed?this.#e.reject(Error(`Worker was destroyed`)):this.#u()},i=new AbortController;t.addEventListener(`error`,()=>{this.#r||r()},{signal:i.signal});n.on(`test`,e=>{i.abort();if(!this.destroyed&&e){this.#t=n;this.#n=t;this.#r=t;this.#s()}else r()});n.on(`ready`,e=>{i.abort();if(this.destroyed)r();else try{a()}catch{this.#u()}});let a=()=>{let e=new Uint8Array;n.send(`test`,e,[e.buffer])};a();return}catch{D(`The worker has been disabled.`)}this.#u()}#u(){if(!q.#a){O(`Setting up fake worker.`);q.#a=!0}q._setupFakeWorkerGlobal.then(e=>{if(this.destroyed){this.#e.reject(Error(`Worker was destroyed`));return}let t=new Ot;this.#n=t;let n=`fake`+q.#i++,r=new At(n+`_worker`,n,t);e.setup(r,t);this.#t=new At(n,n+`_worker`,t);this.#s()}).catch(e=>{this.#e.reject(Error(`Setting up fake worker failed: "${e.message}".`))})}destroy(){this.destroyed=!0;this.#r?.terminate();this.#r=null;q.#o.delete(this.#n);this.#n=null;this.#t?.destroy();this.#t=null}static create(e){let t=this.#o.get(e?.port);if(t){if(t._pendingDestroy)throw Error("PDFWorker.create - the worker is being destroyed.\nPlease remember to await `PDFDocumentLoadingTask.destroy()`-calls.");return t}return new q(e)}static get workerSrc(){if(Bn.workerSrc)return Bn.workerSrc;throw Error(`No "GlobalWorkerOptions.workerSrc" specified.`)}static get#d(){try{return globalThis.pdfjsWorker?.WorkerMessageHandler||null}catch{return null}}static get _setupFakeWorkerGlobal(){return j(this,`_setupFakeWorkerGlobal`,(async()=>{if(this.#d)return this.#d;return(await import(
|
|
45
|
+
`});this.#n=this.#t.createRenderPipeline({layout:`auto`,vertex:{module:e,entryPoint:`vs_main`,buffers:[{arrayStride:8,attributes:[{shaderLocation:0,offset:0,format:`float32x2`}]},{arrayStride:4,attributes:[{shaderLocation:1,offset:0,format:`unorm8x4`}]}]},fragment:{module:e,entryPoint:`fs_main`,targets:[{format:this.#r}]},primitive:{topology:`triangle-list`}})}draw(e,t,n,r,i,a,o,s){this.loadMeshShader();let c=this.#t,{offsetX:l,offsetY:u,scaleX:d,scaleY:f}=r,p=c.createBuffer({size:Math.max(e.byteLength,4),usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST});e.byteLength>0&&c.queue.writeBuffer(p,0,e);let m=c.createBuffer({size:Math.max(t.byteLength,4),usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST});t.byteLength>0&&c.queue.writeBuffer(m,0,t);let h=c.createBuffer({size:32,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});c.queue.writeBuffer(h,0,new Float32Array([l,u,d,f,a,o,s,0]));let g=c.createBindGroup({layout:this.#n.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:h}}]}),_=new OffscreenCanvas(a,o),v=_.getContext(`webgpu`);v.configure({device:c,format:this.#r,alphaMode:i?`opaque`:`premultiplied`});let y=i?{r:i[0]/255,g:i[1]/255,b:i[2]/255,a:1}:{r:0,g:0,b:0,a:0},b=c.createCommandEncoder(),x=b.beginRenderPass({colorAttachments:[{view:v.getCurrentTexture().createView(),clearValue:y,loadOp:`clear`,storeOp:`store`}]});if(n>0){x.setPipeline(this.#n);x.setBindGroup(0,g);x.setVertexBuffer(0,p);x.setVertexBuffer(1,m);x.draw(n)}x.end();c.queue.submit([b.finish()]);p.destroy();m.destroy();h.destroy();return _.transferToImageBitmap()}},Rt=`Fill`,zt=`Stroke`,Bt=`Shading`;function Vt(e,t){if(!t)return;let n=t[2]-t[0],r=t[3]-t[1],i=new Path2D;i.rect(t[0],t[1],n,r);e.clip(i)}class Ht{isModifyingCurrentTransform(){return!1}getPattern(){D("Abstract method `getPattern` called.")}}class Ut extends Ht{constructor(e){super();this._type=e[1];this._bbox=e[2];this._colorStops=e[3];this._p0=e[4];this._p1=e[5];this._r0=e[6];this._r1=e[7];this.matrix=null}isOriginBased(){return this._p0[0]===0&&this._p0[1]===0&&(!this.isRadial()||this._p1[0]===0&&this._p1[1]===0)}isRadial(){return this._type===`radial`}areConic(){if(!this.isRadial())return!1;let e=Math.hypot(this._p0[0]-this._p1[0],this._p0[1]-this._p1[1]);return e+this._r1>this._r0&&e+this._r0>this._r1}_createGradient(e,t=null){let n,r=this._p0,i=this._p1;if(t){r=r.slice();i=i.slice();P.applyTransform(r,t);P.applyTransform(i,t)}if(this._type===`axial`)n=e.createLinearGradient(r[0],r[1],i[0],i[1]);else if(this._type===`radial`){let a=this._r0,o=this._r1;if(t){let e=new Float32Array(2);P.singularValueDecompose2dScale(t,e);a*=e[0];o*=e[0]}n=e.createRadialGradient(r[0],r[1],a,i[0],i[1],o)}for(let e of this._colorStops)n.addColorStop(e[0],e[1]);return n}_createReversedGradient(e,t=null){let n=this._p1,r=this._p0;if(t){n=n.slice();r=r.slice();P.applyTransform(n,t);P.applyTransform(r,t)}let i=this._r1,a=this._r0;if(t){let e=new Float32Array(2);P.singularValueDecompose2dScale(t,e);i*=e[0];a*=e[0]}let o=e.createRadialGradient(n[0],n[1],i,r[0],r[1],a),s=this._colorStops.map(([e,t])=>[1-e,t]).reverse();for(let[e,t]of s)o.addColorStop(e,t);return o}getPattern(e,t,n,r){let i;if(r===zt||r===Rt){if(this.isOriginBased()){let r=P.transform(n,t.baseTransform);this.matrix&&(r=P.transform(r,this.matrix));let i=.001,a=Math.hypot(r[0],r[1]),o=Math.hypot(r[2],r[3]),s=(r[0]*r[2]+r[1]*r[3])/(a*o);if(Math.abs(s)<i){if(!this.isRadial())return this._createGradient(e,r);if(Math.abs(a-o)<i)return this._createGradient(e,r)}}let a=t.current.getClippedPathBoundingBox(r,z(e))||[0,0,0,0],o=Math.ceil(a[2]-a[0])||1,s=Math.ceil(a[3]-a[1])||1,c=t.canvasFactory.create(o,s),l=c.context;l.clearRect(0,0,l.canvas.width,l.canvas.height);l.beginPath();l.rect(0,0,l.canvas.width,l.canvas.height);l.translate(-a[0],-a[1]);n=P.transform(n,[1,0,0,1,a[0],a[1]]);l.transform(...t.baseTransform);this.matrix&&l.transform(...this.matrix);Vt(l,this._bbox);if(this.areConic()){l.fillStyle=this._createReversedGradient(l);l.fill()}l.fillStyle=this._createGradient(l);l.fill();i=e.createPattern(c.canvas,`no-repeat`);t.canvasFactory.destroy(c);let u=new DOMMatrix(n);i.setTransform(u)}else{if(this.areConic()){e.save();Vt(e,this._bbox);e.fillStyle=this._createReversedGradient(e);e.fillRect(-1e10,-1e10,2e10,2e10);e.restore()}Vt(e,this._bbox);i=this._createGradient(e)}return i}}function Wt(e,t,n,r,i,a,o,s){let c=t.coords,l=t.colors,u=e.data,d=4*e.width,f;if(c[2*n+1]>c[2*r+1]){f=n;n=r;r=f;f=a;a=o;o=f}if(c[2*r+1]>c[2*i+1]){f=r;r=i;i=f;f=o;o=s;s=f}if(c[2*n+1]>c[2*r+1]){f=n;n=r;r=f;f=a;a=o;o=f}let p=(c[2*n]+t.offsetX)*t.scaleX,m=(c[2*n+1]+t.offsetY)*t.scaleY,h=(c[2*r]+t.offsetX)*t.scaleX,g=(c[2*r+1]+t.offsetY)*t.scaleY,_=(c[2*i]+t.offsetX)*t.scaleX,v=(c[2*i+1]+t.offsetY)*t.scaleY;if(m>=v)return;let y=l[4*a],b=l[4*a+1],x=l[4*a+2],S=l[4*o],C=l[4*o+1],w=l[4*o+2],T=l[4*s],E=l[4*s+1],D=l[4*s+2],O=Math.round(m),k=Math.round(v),A,j,M,ee,te,ne,re,ie;for(let e=O;e<=k;e++){if(e<g){let t=e<m?0:(m-e)/(m-g);A=p-(p-h)*t;j=y-(y-S)*t;M=b-(b-C)*t;ee=x-(x-w)*t}else{let t;t=e>v?1:g===v?0:(g-e)/(g-v);A=h-(h-_)*t;j=S-(S-T)*t;M=C-(C-E)*t;ee=w-(w-D)*t}let t;t=e<m?0:e>v?1:(m-e)/(m-v);te=p-(p-_)*t;ne=y-(y-T)*t;re=b-(b-E)*t;ie=x-(x-D)*t;let n=Math.round(Math.min(A,te)),r=Math.round(Math.max(A,te)),i=d*e+4*n;for(let e=n;e<=r;e++){t=(A-e)/(A-te);t<0?t=0:t>1&&(t=1);u[i++]=j-(j-ne)*t|0;u[i++]=M-(M-re)*t|0;u[i++]=ee-(ee-ie)*t|0;u[i++]=255}}}class Gt extends Ht{constructor(e){super();this._posData=e[2];this._colData=e[3];this._vertexCount=e[4];this._bounds=e[5];this._bbox=e[6];this._background=e[7];this.matrix=null;(function(){Lt.loadMeshShader()})()}_createMeshCanvas(e,t,n){let r=Math.floor(this._bounds[0]),i=Math.floor(this._bounds[1]),a=Math.ceil(this._bounds[2])-r,o=Math.ceil(this._bounds[3])-i,s=Math.min(Math.ceil(Math.abs(a*e[0]*1.1)),3e3)||1,c=Math.min(Math.ceil(Math.abs(o*e[1]*1.1)),3e3)||1,l=a?a/s:1,u=o?o/c:1,d={coords:this._posData,colors:this._colData,offsetX:-r,offsetY:-i,scaleX:1/l,scaleY:1/u},f=s+4,p=c+4,m=n.create(f,p);if(function(){return Lt.isReady}()&&this._vertexCount>48)m.context.drawImage(function(e,t,n,r,i,a,o,s){return Lt.draw(e,t,n,r,i,a,o,s)}(this._posData,this._colData,this._vertexCount,d,t,f,p,2),0,0);else{let e=m.context.createImageData(s,c);if(t){let n=e.data;for(let e=0,r=n.length;e<r;e+=4){n[e]=t[0];n[e+1]=t[1];n[e+2]=t[2];n[e+3]=255}}for(let t=0,n=this._vertexCount;t<n;t+=3)Wt(e,d,t,t+1,t+2,t,t+1,t+2);m.context.putImageData(e,2,2)}return{canvas:m.canvas,offsetX:r-2*l,offsetY:i-2*u,scaleX:l,scaleY:u}}isModifyingCurrentTransform(){return!0}getPattern(e,t,n,r){Vt(e,this._bbox);let i=new Float32Array(2);if(r===Bt)P.singularValueDecompose2dScale(z(e),i);else if(this.matrix){P.singularValueDecompose2dScale(this.matrix,i);let[e,n]=i;P.singularValueDecompose2dScale(t.baseTransform,i);i[0]*=e;i[1]*=n}else P.singularValueDecompose2dScale(t.baseTransform,i);let a=this._createMeshCanvas(i,r===Bt?null:this._background,t.canvasFactory);if(r!==Bt){e.setTransform(...t.baseTransform);this.matrix&&e.transform(...this.matrix)}e.translate(a.offsetX,a.offsetY);e.scale(a.scaleX,a.scaleY);let o=e.createPattern(a.canvas,`no-repeat`);t.canvasFactory.destroy(a);return o}}class Kt extends Ht{getPattern(){return`hotpink`}}class qt{static MAX_PATTERN_SIZE=3e3;constructor(e,t,n,r){this.color=e[1];this.operatorList=e[2];this.matrix=e[3];this.bbox=e[4];this.xstep=e[5];this.ystep=e[6];this.paintType=e[7];this.tilingType=e[8];this.needsIsolation=e[9]??!0;this.ctx=t;this.canvasGraphicsFactory=n;this.baseTransform=r;this.patternBaseMatrix=this.matrix?P.transform(r,this.matrix):r}canSkipPatternCanvas([e,t,n,r]){let[i,a,o,s]=this.bbox,c=Math.abs(this.xstep),l=Math.abs(this.ystep);if(e>c+1e-6||t>l+1e-6)return null;let u=Math.floor((n-o)/c)+1,d=Math.ceil((n+e-i)/c)-1,f=Math.floor((r-s)/l)+1,p=Math.ceil((r+t-a)/l)-1;return d<=u&&p<=f?[u,f]:null}updatePatternDims(e,t){let n=P.inverseTransform(this.patternBaseMatrix),r=[e[0],e[1]],i=[e[2],e[3]];P.applyTransform(r,n);P.applyTransform(i,n);t[0]=Math.abs(i[0]-r[0]);t[1]=Math.abs(i[1]-r[1]);t[2]=Math.min(r[0],i[0]);t[3]=Math.min(r[1],i[1])}_renderTileCanvas(e,t,n,r){let[i,a,o,s]=this.bbox,c=e.canvasFactory.create(n.size,r.size),l=c.context,u=this.canvasGraphicsFactory.createCanvasGraphics(l,t);u.groupLevel=e.groupLevel;this.setFillAndStrokeStyleToContext(u,this.paintType,this.color);l.translate(-n.scale*i,-r.scale*a);u.transform(0,n.scale,0,0,r.scale,0,0);l.save();u.dependencyTracker?.save();this.clipBbox(u,i,a,o,s);u.baseTransform=z(u.ctx);u.executeOperatorList(this.operatorList);u.endDrawing();u.dependencyTracker?.restore();l.restore();return c}_getCombinedScales(){let e=new Float32Array(2);P.singularValueDecompose2dScale(this.matrix,e);let[t,n]=e;P.singularValueDecompose2dScale(this.baseTransform,e);return[t*e[0],n*e[1]]}drawPattern(e,t,n=!1,[r,i],a){let[o,s,c,l]=this.bbox,u=e.dependencyTracker;u&&(e.dependencyTracker=new it(u,a));e.save();n?e.ctx.clip(t,`evenodd`):e.ctx.clip(t);e.ctx.setTransform(...this.patternBaseMatrix);e.ctx.translate(r*this.xstep,i*this.ystep);if(this.needsIsolation||e.ctx.globalAlpha!==1||e.ctx.globalCompositeOperation!==`source-over`||e.inSMaskMode){let t=c-o,n=l-s,[r,i]=this._getCombinedScales(),u=this.getSizeAndScale(t,this.ctx.canvas.width,r),d=this.getSizeAndScale(n,this.ctx.canvas.height,i),f=this._renderTileCanvas(e,a,u,d);e.ctx.drawImage(f.canvas,o,s,t,n);e.canvasFactory.destroy(f)}else{this.setFillAndStrokeStyleToContext(e,this.paintType,this.color);this.clipBbox(e,o,s,c,l);e.baseTransformStack.push(e.baseTransform);e.baseTransform=z(e.ctx);e.executeOperatorList(this.operatorList);e.baseTransform=e.baseTransformStack.pop()}e.restore();u&&(e.dependencyTracker=u)}createPatternCanvas(e,t){let[n,r,i,a]=this.bbox,o=i-n,s=a-r,{xstep:c,ystep:l}=this;c=Math.abs(c);l=Math.abs(l);T(`TilingType: `+this.tilingType);let[u,d]=this._getCombinedScales(),f=o,p=s,m=!1,h=!1;Math.ceil(c*u)>=Math.ceil(o*u)?f=c:m=!0;Math.ceil(l*d)>=Math.ceil(s*d)?p=l:h=!0;let g=this.getSizeAndScale(f,this.ctx.canvas.width,u),_=this.getSizeAndScale(p,this.ctx.canvas.height,d),v=this._renderTileCanvas(e,t,g,_);if(m||h){let t=v.canvas;m&&(f=c);h&&(p=l);let i=this.getSizeAndScale(f,this.ctx.canvas.width,u),a=this.getSizeAndScale(p,this.ctx.canvas.height,d),g=i.size,_=a.size,y=e.canvasFactory.create(g,_),b=y.context,x=m?Math.floor(o/c):0,S=h?Math.floor(s/l):0;for(let e=0;e<=x;e++)for(let n=0;n<=S;n++)b.drawImage(t,g*e,_*n,g,_,0,0,g,_);e.canvasFactory.destroy(v);return{canvas:y.canvas,canvasEntry:y,scaleX:i.scale,scaleY:a.scale,offsetX:n,offsetY:r}}return{canvas:v.canvas,canvasEntry:v,scaleX:g.scale,scaleY:_.scale,offsetX:n,offsetY:r}}getSizeAndScale(e,t,n){let r=Math.max(qt.MAX_PATTERN_SIZE,t),i=Math.ceil(e*n);i>=r?i=r:n=i/e;return{scale:n,size:i}}clipBbox(e,t,n,r,i){let a=r-t,o=i-n,s=new Path2D;s.rect(t,n,a,o);P.axialAlignedBoundingBox([t,n,r,i],z(e.ctx),e.current.minMax);e.ctx.clip(s);e.current.updateClipFromPath()}setFillAndStrokeStyleToContext(e,t,n){let r=e.ctx,i=e.current;i.patternFill=i.patternStroke=!1;switch(t){case 1:let{fillStyle:e,strokeStyle:a}=this.ctx;r.fillStyle=i.fillColor=e;r.strokeStyle=i.strokeColor=a;break;case 2:r.fillStyle=r.strokeStyle=n;i.fillColor=i.strokeColor=n;break;default:throw new ie(`Unsupported paint type: ${t}`)}}isModifyingCurrentTransform(){return!1}getPattern(e,t,n,r,i){let a=r===Bt?n:P.transform(n,this.patternBaseMatrix),o=this.createPatternCanvas(t,i),s=new DOMMatrix(a);s=s.translate(o.offsetX,o.offsetY);s=s.scale(1/o.scaleX,1/o.scaleY);let c=e.createPattern(o.canvas,`repeat`);t.canvasFactory.destroy(o.canvasEntry);c.setTransform(s);return c}}function Jt({src:e,srcPos:t=0,dest:n,width:r,height:i,nonBlackColor:a=4294967295,inverseDecode:o=!1}){let s=N.isLittleEndian?4278190080:255,[c,l]=o?[a,s]:[s,a],u=r>>3,d=7&r,f=c^l,p=e.length;n=new Uint32Array(n.buffer);let m=0;for(let r=0;r<i;++r){for(let r=t+u;t<r;++t,m+=8){let r=e[t];n[m]=c^-(r>>7&1)&f;n[m+1]=c^-(r>>6&1)&f;n[m+2]=c^-(r>>5&1)&f;n[m+3]=c^-(r>>4&1)&f;n[m+4]=c^-(r>>3&1)&f;n[m+5]=c^-(r>>2&1)&f;n[m+6]=c^-(r>>1&1)&f;n[m+7]=c^-(1&r)&f}if(d===0)continue;let r=t<p?e[t++]:255;for(let e=0;e<d;++e,++m)n[m]=c^-(r>>7-e&1)&f}return{srcPos:t,destPos:m}}const Yt=new DOMMatrix,K=new Float32Array(2);function Xt(e,t){if(e._removeMirroring)throw Error(`Context is already forwarding operations.`);let n=new Map;for(let r of[`save`,`restore`,`rotate`,`scale`,`translate`,`transform`,`setTransform`,`resetTransform`,`clip`,`moveTo`,`lineTo`,`bezierCurveTo`,`quadraticCurveTo`,`arc`,`arcTo`,`ellipse`,`rect`,`roundRect`,`closePath`,`beginPath`]){let i=e[r];if(typeof i==`function`&&typeof t[r]==`function`){n.set(r,i);e[r]=function(...e){t[r](...e);return i.apply(this,e)}}}e._removeMirroring=()=>{for(let[t,r]of n)e[t]=r;delete e._removeMirroring}}function Zt(e,t,n,r,i,a,o,s,c,l){let[u,d,f,p,m,h]=z(e);if(d===0&&f===0){let g=o*u+m,_=Math.round(g),v=s*p+h,y=Math.round(v),b=(o+c)*u+m,x=Math.abs(Math.round(b)-_)||1,S=(s+l)*p+h,C=Math.abs(Math.round(S)-y)||1;e.setTransform(Math.sign(u),0,0,Math.sign(p),_,y);e.drawImage(t,n,r,i,a,0,0,x,C);e.setTransform(u,d,f,p,m,h);return[x,C]}if(u===0&&p===0){let g=s*f+m,_=Math.round(g),v=o*d+h,y=Math.round(v),b=(s+l)*f+m,x=Math.abs(Math.round(b)-_)||1,S=(o+c)*d+h,C=Math.abs(Math.round(S)-y)||1;e.setTransform(0,Math.sign(d),Math.sign(f),0,_,y);e.drawImage(t,n,r,i,a,0,0,C,x);e.setTransform(u,d,f,p,m,h);return[C,x]}e.drawImage(t,n,r,i,a,o,s,c,l);return[Math.hypot(u,d)*c,Math.hypot(f,p)*l]}class Qt{alphaIsShape=!1;fontSize=0;fontSizeScale=1;textMatrix=null;textMatrixScale=1;fontMatrix=f;leading=0;x=0;y=0;lineX=0;lineY=0;charSpacing=0;wordSpacing=0;textHScale=1;textRenderingMode=0;textRise=0;fillColor=`#000000`;strokeColor=`#000000`;tilingPatternDims=null;patternFill=!1;patternStroke=!1;fillAlpha=1;strokeAlpha=1;lineWidth=1;activeSMask=null;transferMaps=`none`;minMax=d.slice();constructor(e,t){this.clipBox=new Float32Array([0,0,e,t])}clone(){let e=Object.create(this);e.clipBox=this.clipBox.slice();e.minMax=this.minMax.slice();e.tilingPatternDims=this.tilingPatternDims?.slice();return e}getPathBoundingBox(e=Rt,t=null){let n=this.minMax.slice();if(e===zt){t||D(`Stroke bounding box must include transform.`);P.singularValueDecompose2dScale(t,K);let e=K[0]*this.lineWidth/2,r=K[1]*this.lineWidth/2;n[0]-=e;n[1]-=r;n[2]+=e;n[3]+=r}return n}updateClipFromPath(){let e=P.intersect(this.clipBox,this.getPathBoundingBox());this.startNewPathAndClipBox(e||[0,0,0,0])}isEmptyClip(){return this.minMax[0]===1/0}startNewPathAndClipBox(e){this.clipBox.set(e,0);this.minMax.set(d,0)}getClippedPathBoundingBox(e=Rt,t=null){return P.intersect(this.clipBox,this.getPathBoundingBox(e,t))}}function $t(e,t){if(t instanceof ImageData){e.putImageData(t,0,0);return}let n=t.height,r=t.width,i=n%16,a=(n-i)/16,o=i===0?a:a+1,s=e.createImageData(r,16),c,l=0,u=t.data,d=s.data,f,p,m,h;if(t.kind===y.GRAYSCALE_1BPP){let t=u.byteLength,n=new Uint32Array(d.buffer,0,d.byteLength>>2),h=n.length,g=r+7>>3,_=4294967295,v=N.isLittleEndian?4278190080:255;for(f=0;f<o;f++){m=f<a?16:i;c=0;for(p=0;p<m;p++){let e=t-l,i=0,a=e>g?r:8*e-7,o=-8&a,s=0,d=0;for(;i<o;i+=8){d=u[l++];n[c++]=128&d?_:v;n[c++]=64&d?_:v;n[c++]=32&d?_:v;n[c++]=16&d?_:v;n[c++]=8&d?_:v;n[c++]=4&d?_:v;n[c++]=2&d?_:v;n[c++]=1&d?_:v}for(;i<a;i++){if(s===0){d=u[l++];s=128}n[c++]=d&s?_:v;s>>=1}}for(;c<h;)n[c++]=0;e.putImageData(s,0,f*16)}}else if(t.kind===y.RGBA_32BPP){p=0;h=r*16*4;for(f=0;f<a;f++){d.set(u.subarray(l,l+h));l+=h;e.putImageData(s,0,p);p+=16}if(f<o){h=r*i*4;d.set(u.subarray(l,l+h));e.putImageData(s,0,p)}}else{if(t.kind!==y.RGB_24BPP)throw Error(`bad image kind: ${t.kind}`);m=16;h=r*m;for(f=0;f<o;f++){if(f>=a){m=i;h=r*m}c=0;for(p=h;p--;){d[c++]=u[l++];d[c++]=u[l++];d[c++]=u[l++];d[c++]=255}e.putImageData(s,0,f*16)}}}function en(e,t){if(t.bitmap){e.drawImage(t.bitmap,0,0);return}let n=t.height,r=t.width,i=n%16,a=(n-i)/16,o=i===0?a:a+1,s=e.createImageData(r,16),c=0,l=t.data,u=s.data;for(let t=0;t<o;t++){let n=t<a?16:i;({srcPos:c}=Jt({src:l,srcPos:c,dest:u,width:r,height:n,nonBlackColor:0}));e.putImageData(s,0,t*16)}}function tn(e,t){for(let n of[`strokeStyle`,`fillStyle`,`fillRule`,`globalAlpha`,`lineWidth`,`lineCap`,`lineJoin`,`miterLimit`,`globalCompositeOperation`,`font`,`filter`])e[n]!==void 0&&(t[n]=e[n]);if(e.setLineDash!==void 0){t.setLineDash(e.getLineDash());t.lineDashOffset=e.lineDashOffset}}function nn(e){e.strokeStyle=e.fillStyle=`#000000`;e.fillRule=`nonzero`;e.globalAlpha=1;e.lineWidth=1;e.lineCap=`butt`;e.lineJoin=`miter`;e.miterLimit=10;e.globalCompositeOperation=`source-over`;e.font=`10px sans-serif`;if(e.setLineDash!==void 0){e.setLineDash([]);e.lineDashOffset=0}let{filter:t}=e;t!==`none`&&t!==``&&(e.filter=`none`)}function rn(e,t){if(t)return!0;P.singularValueDecompose2dScale(e,K);let n=Math.fround(Te.pixelRatio*pe.PDF_TO_CSS_UNITS);return K[0]<=n&&K[1]<=n}const an=[`butt`,`round`,`square`],on=[`miter`,`round`,`bevel`],sn={},cn={};class ln{#e=0;#t=0;#n=null;#r=null;#i=null;#a=null;#o=1;#s;#c=null;#l=[];constructor(e,t,n,r,i,{optionalContentConfig:a,markedContentStack:o=null},s,c,l,u){this.ctx=e;this.current=new Qt(this.ctx.canvas.width,this.ctx.canvas.height);this.stateStack=[];this.pendingClip=null;this.pendingEOFill=!1;this.commonObjs=t;this.objs=n;this.canvasFactory=r;this.filterFactory=i;this.groupStack=[];this.baseTransform=null;this.baseTransformStack=[];this.groupLevel=0;this.smaskStack=[];this.tempSMask=null;this.smaskGroupCanvases=[];this.smaskPreparedEntry=null;this.smaskPreparedFor=null;this.smaskPreparedOffsetX=0;this.smaskPreparedOffsetY=0;this.smaskPreparedOOBAlpha=null;this.suspendedCtx=null;this.contentVisible=!0;this.markedContentStack=o||[];this.optionalContentConfig=a;this.cachedPatterns=new Map;this.annotationCanvasMap=s;this.viewportScale=1;this.outputScaleX=1;this.outputScaleY=1;this.pageColors=c;this._cachedScaleForStroking=[-1,0];this._cachedGetSinglePixelWidth=null;this._cachedBitmapsMap=new Map;this.dependencyTracker=l??null;this.imagesTracker=u??null}getObject(e,t,n=null){if(typeof t==`string`){this.dependencyTracker?.recordNamedDependency(e,t);return t.startsWith(`g_`)?this.commonObjs.get(t):this.objs.get(t)}return n}beginDrawing({transform:e,viewport:t,transparency:n=!1,background:r=null}){let i=this.ctx.canvas.width,a=this.ctx.canvas.height,o=this.ctx.fillStyle;this.ctx.fillStyle=r||`#ffffff`;this.ctx.fillRect(0,0,i,a);this.ctx.fillStyle=o;if(n){let e=this.transparentCanvasEntry=this.canvasFactory.create(i,a);this.compositeCtx=this.ctx;({canvas:this.transparentCanvas,context:this.ctx}=e);this.ctx.save();this.ctx.transform(...z(this.compositeCtx))}this.ctx.save();nn(this.ctx);if(e){this.ctx.transform(...e);this.outputScaleX=e[0];this.outputScaleY=e[3]}this.ctx.transform(...t.transform);this.viewportScale=t.scale;this.baseTransform=z(this.ctx)}executeOperatorList(e,t,n,r,i,a=null,o=null){let s=Number.isFinite(a?.executionTime)&&a.executionTime>0?a.executionTime:15,c=Number.isInteger(a?.executionSteps)&&a.executionSteps>0?a.executionSteps:10,l=e.argsArray,u=e.fnArray,d=t||0,f=l.length;if(f===d)return d;let p=f-d>c&&typeof n==`function`,m=p?performance.now()+s:0,h=0,g=this.commonObjs,_=this.objs,v,y;for(;;){if(r!==void 0){if(d===r.nextBreakPoint){r.breakIt(d,n);return d}if(r.shouldSkip(d)){if(++d===f)return d;continue}}if(!i||i(d)){v=u[d];y=l[d]??null;if(v!==x.dependency)y===null?this[v](d):this[v](d,...y);else for(let e of y){this.dependencyTracker?.recordNamedData(e,d);let t=e.startsWith(`g_`)?g:_;if(!t.has(e)){t.get(e,n);return d}}}d++;if(d===f)return d;if(p&&++h>c){let e=performance.now()>m;if(typeof o==`function`&&o()||e){n();return d}h=0}}}#u(){for(;this.stateStack.length||this.inSMaskMode;)this.restore();this.current.activeSMask=null;this.ctx.restore();if(this.transparentCanvas){this.ctx=this.compositeCtx;this.ctx.save();this.ctx.setTransform(1,0,0,1,0,0);this.ctx.drawImage(this.transparentCanvas,0,0);this.ctx.restore();this.canvasFactory.destroy(this.transparentCanvasEntry);this.transparentCanvas=null;this.transparentCanvasEntry=null}}endDrawing(){this.#u();for(let e of this.smaskGroupCanvases)this.canvasFactory.destroy(e);this.smaskGroupCanvases.length=0;this._clearPreparedSMask();this.tempSMask=null;this.smaskStack.length=0;for(let e of this.#l)this.#v(e);this.#l.length=0;this.#n=null;this.#r=null;this.#i=null;this.#a=null;this.#o=1;this.#c=null;this.#t=0;this.#e=0;this.cachedPatterns.clear();for(let e of this._cachedBitmapsMap.values()){for(let t of e.values())typeof HTMLCanvasElement<`u`&&t instanceof HTMLCanvasElement&&(t.width=t.height=0);e.clear()}this._cachedBitmapsMap.clear();this.#d()}#d(){if(this.pageColors){let e=this.filterFactory.addHCMFilter(this.pageColors.foreground,this.pageColors.background);if(e!==`none`){let t=this.ctx.filter;this.ctx.filter=e;this.ctx.drawImage(this.ctx.canvas,0,0);this.ctx.filter=t}}}_scaleImage(e,t){let n=e.width??e.displayWidth,r=e.height??e.displayHeight,i=[],a=Math.max(Math.hypot(t[0],t[1]),1),o=Math.max(Math.hypot(t[2],t[3]),1),s=n,c=r;for(;a>2&&s>1||o>2&&c>1;){let e=s,t=c;if(a>2&&s>1){e=Math.ceil(s/2);a/=s/e}if(o>2&&c>1){t=Math.ceil(c/2);o/=c/t}i.push({newWidth:e,newHeight:t});s=e;c=t}if(i.length===0)return{img:e,paintWidth:n,paintHeight:r,tmpCanvas:null};if(i.length===1){let{newWidth:t,newHeight:a}=i[0],o=this.canvasFactory.create(t,a);o.context.drawImage(e,0,0,n,r,0,0,t,a);return{img:o.canvas,paintWidth:t,paintHeight:a,tmpCanvas:o}}let l=this.canvasFactory.create(1,1),u=this.canvasFactory.create(1,1),d=n,f=r,p=e;for(let{newWidth:e,newHeight:t}of i){this.canvasFactory.reset(u,e,t);u.context.drawImage(p,0,0,d,f,0,0,e,t);[l,u]=[u,l];p=l.canvas;d=e;f=t}this.canvasFactory.destroy(u);return{img:l.canvas,paintWidth:d,paintHeight:f,tmpCanvas:l}}_createMaskCanvas(e,t){let n=this.ctx,{width:r,height:i}=t,a=this.current.fillColor,o=this.current.patternFill,s=z(n),c,l,u,f;if((t.bitmap||t.data)&&t.count>1){let n=t.bitmap||t.data.buffer;l=JSON.stringify(o?s:[s.slice(0,4),a]);c=this._cachedBitmapsMap.getOrInsertComputed(n,le);let r=c.get(l);if(r&&!o){let t=Math.round(Math.min(s[0],s[2])+s[4]),n=Math.round(Math.min(s[1],s[3])+s[5]);this.dependencyTracker?.recordDependencies(e,dt);return{canvas:r,offsetX:t,offsetY:n}}u=r}if(!u){f=this.canvasFactory.create(r,i);en(f.context,t)}let p=P.transform(s,[1/r,0,0,-1/i,0,0]);p=P.transform(p,[1,0,0,1,0,-i]);let m=d.slice();P.axialAlignedBoundingBox([0,0,r,i],p,m);let[h,g,_,v]=m,y=Math.round(_-h)||1,b=Math.round(v-g)||1,x=this.canvasFactory.create(y,b),S=x.context,C=h,w=g;S.translate(-C,-w);S.transform(...p);let T=null;if(!u){let e=this._scaleImage(f.canvas,B(S));u=e.img;T=e.tmpCanvas;if(u!==f.canvas){this.canvasFactory.destroy(f);f=null}if(c&&o){c.set(l,u);T=null;f=null}}S.imageSmoothingEnabled=rn(z(S),t.interpolate);Zt(S,u,0,0,u.width,u.height,0,0,r,i);T&&this.canvasFactory.destroy(T);f&&this.canvasFactory.destroy(f);S.globalCompositeOperation=`source-in`;let E=P.transform(B(S),[1,0,0,1,-C,-w]);S.fillStyle=o?a.getPattern(n,this,E,Rt,e):a;S.fillRect(0,0,r,i);c&&!o&&c.set(l,x.canvas);this.dependencyTracker?.recordDependencies(e,dt);return{canvas:x.canvas,canvasEntry:c&&!o?null:x,offsetX:Math.round(C),offsetY:Math.round(w)}}setLineWidth(e,t){this.dependencyTracker?.recordSimpleData(`lineWidth`,e);t!==this.current.lineWidth&&(this._cachedScaleForStroking[0]=-1);this.current.lineWidth=t;this.ctx.lineWidth=t}setLineCap(e,t){this.dependencyTracker?.recordSimpleData(`lineCap`,e);this.ctx.lineCap=an[t]}setLineJoin(e,t){this.dependencyTracker?.recordSimpleData(`lineJoin`,e);this.ctx.lineJoin=on[t]}setMiterLimit(e,t){this.dependencyTracker?.recordSimpleData(`miterLimit`,e);this.ctx.miterLimit=t}setDash(e,t,n){this.dependencyTracker?.recordSimpleData(`dash`,e);let r=this.ctx;if(r.setLineDash!==void 0){r.setLineDash(t);r.lineDashOffset=n}}setRenderingIntent(e,t){}setFlatness(e,t){}setGState(e,t){for(let[n,r]of t)switch(n){case`LW`:this.setLineWidth(e,r);break;case`LC`:this.setLineCap(e,r);break;case`LJ`:this.setLineJoin(e,r);break;case`ML`:this.setMiterLimit(e,r);break;case`D`:this.setDash(e,r[0],r[1]);break;case`RI`:this.setRenderingIntent(e,r);break;case`FL`:this.setFlatness(e,r);break;case`Font`:this.setFont(e,r[0],r[1]);break;case`CA`:this.dependencyTracker?.recordSimpleData(`strokeAlpha`,e);this.current.strokeAlpha=r;break;case`ca`:this.dependencyTracker?.recordSimpleData(`fillAlpha`,e);this.ctx.globalAlpha=this.current.fillAlpha=r;break;case`BM`:this.dependencyTracker?.recordSimpleData(`globalCompositeOperation`,e);this.ctx.globalCompositeOperation=r;break;case`SMask`:this.dependencyTracker?.recordSimpleData(`SMask`,e);this.current.activeSMask=r?this.tempSMask:null;this.current.activeSMask&&(this.current.activeSMask.blendMode=this.ctx.globalCompositeOperation);this.tempSMask=null;this.checkSMaskState(e);break;case`TR`:this.dependencyTracker?.recordSimpleData(`filter`,e);this.ctx.filter=this.current.transferMaps=this.filterFactory.addFilter(r)}}get inSMaskMode(){return!!this.suspendedCtx}_clearPreparedSMask(){if(this.smaskPreparedEntry){this.canvasFactory.destroy(this.smaskPreparedEntry);this.smaskPreparedEntry=null}this.smaskPreparedFor=null;this.smaskPreparedOffsetX=0;this.smaskPreparedOffsetY=0;this.smaskPreparedOOBAlpha=null}_ensurePreparedSMask(e){if(e!==this.smaskPreparedFor){this._clearPreparedSMask();this._prepareSMaskCanvas(e)}}checkSMaskState(e){let t=this.inSMaskMode;this.current.activeSMask&&!t?this.beginSMaskMode(e):!this.current.activeSMask&&t?this.endSMaskMode():this.current.activeSMask&&t&&this._ensurePreparedSMask(this.current.activeSMask)}_prepareSMaskCanvas(e){let{canvas:t,subtype:n,backdrop:r,transferMap:i}=e,a=n===`Luminosity`||n===`Alpha`&&i;if(!(a||n===`Luminosity`&&r)){this.smaskPreparedFor=e;return}let o;if(n===`Luminosity`&&r){let[e,t,n]=Se(r),a=Math.round(.3*e+.59*t+.11*n);o=i?.[a]??a}else o=i?.[0]??0;let{width:s,height:c}=this.ctx.canvas,l=s*c<4*(t.width*t.height),u=a?{url:n===`Alpha`?this.filterFactory.addAlphaFilter(i):this.filterFactory.addLuminosityFilter(i),subtype:n,transferMap:i}:null,d=n===`Luminosity`?r:null,f,p,m;if(l){f=this._bakeSMaskCanvas(t,e.offsetX,e.offsetY,s,c,d,u);p=0;m=0}else{f=this._bakeSMaskCanvas(t,0,0,t.width,t.height,d,u);p=e.offsetX;m=e.offsetY}this.smaskPreparedEntry=f;this.smaskPreparedFor=e;this.smaskPreparedOffsetX=p;this.smaskPreparedOffsetY=m;this.smaskPreparedOOBAlpha=l||o===0?null:o}_bakeSMaskCanvas(e,t,n,r,i,a,o){a||o||D(`_bakeSMaskCanvas with neither backdrop nor filter`);let s=this.canvasFactory.create(r,i),c=s.context;c.drawImage(e,t,n);if(a){c.globalCompositeOperation=`destination-atop`;c.fillStyle=a;c.fillRect(0,0,r,i)}if(!o)return s;let l=this.canvasFactory.create(r,i),u=l.context;u.filter=o.url;let d=N.isCanvasFilterSupported&&u.filter!==`none`&&u.filter!==``;u.drawImage(s.canvas,0,0);N.isCanvasFilterSupported&&(u.filter=`none`);if(!d){let e=u.getImageData(0,0,r,i),{data:t}=e,{transferMap:n}=o;if(o.subtype===`Luminosity`)for(let e=0,r=t.length;e<r;e+=4){let r=.3*t[e]+.59*t[e+1]+.11*t[e+2]+.5|0;t[e]=t[e+1]=t[e+2]=0;t[e+3]=n?.[r]??r}else for(let e=3,r=t.length;e<r;e+=4)t[e]=n[t[e]];u.putImageData(e,0,0)}this.canvasFactory.destroy(s);return l}beginSMaskMode(e){if(this.inSMaskMode)throw Error(`beginSMaskMode called while already in smask mode`);let{width:t,height:n}=this.ctx.canvas,r=this.canvasFactory.create(t,n);this.smaskScratchCanvas=r;this.suspendedCtx=this.ctx;let i=this.ctx=r.context;i.setTransform(this.suspendedCtx.getTransform());tn(this.suspendedCtx,i);Xt(i,this.suspendedCtx);this._ensurePreparedSMask(this.current.activeSMask);this.setGState(e,[[`BM`,`source-over`]])}endSMaskMode(){if(!this.inSMaskMode)throw Error(`endSMaskMode called while not in smask mode`);this.ctx._removeMirroring();tn(this.ctx,this.suspendedCtx);this.ctx=this.suspendedCtx;this.suspendedCtx=null;this.canvasFactory.destroy(this.smaskScratchCanvas);this.smaskScratchCanvas=null;this._clearPreparedSMask()}#f(e,t=null,n=1){let{width:r,height:i}=e,a=t??this.canvasFactory.create(r,i),o=a.context,s=(n=Math.round(255*n)/255)<1;s&&this.#s===void 0&&(this.#s=N.isCanvasFilterSupported?new Map:`none`);let c=`none`;if(s&&this.#s instanceof Map){c=this.#s.get(n);if(!c){c=this.filterFactory.addKnockoutFilter(n);this.#s.set(n,c)}}if(!s||c!==`none`){if(t){o.save();o.setTransform(1,0,0,1,0,0);o.clearRect(0,0,r,i);o.restore()}o.filter=c;o.drawImage(e,0,0);o.filter=`none`;return a}let l=e.getContext(`2d`,{willReadFrequently:!0}).getImageData(0,0,r,i),u=o.createImageData(r,i),d=l.data,f=u.data,p=n>0?1/n:1e6;for(let e=3,t=d.length;e<t;e+=4)f[e]=Math.min(Math.round(d[e]*p),255);o.putImageData(u,0,0);return a}#p(e,t,n,r){let i=e?.[t]??null;if(i&&(i.canvas.width!==n||i.canvas.height!==r)){this.canvasFactory.destroy(i);i=null}if(!i){i=this.canvasFactory.create(n,r);e&&(e[t]=i);return i}let a=i.context;a.save();a.setTransform(1,0,0,1,0,0);a.clearRect(0,0,n,r);a.restore();return i}#m(e,t,n={}){let{backdropCanvas:r=null,destTransform:i=[1,0,0,1,0,0],backdropOffset:a=[0,0],reuseMaskEntry:o=null,poolMeta:s=null,sourceAlpha:c=1,sourceFilter:l=`none`,knockoutAlpha:u=1}=n,{width:d,height:f}=t,p=this.#f(t,o,u),m=e.globalCompositeOperation;e.save();e.setTransform(...i);e.globalAlpha=1;N.isCanvasFilterSupported&&(e.filter=`none`);e.globalCompositeOperation=`destination-out`;e.drawImage(p.canvas,0,0);if(r){let[t,n]=a,i=this.#p(s,`knockoutBackdropEntry`,d,f),o=i.context;o.drawImage(r,t,n,d,f,0,0,d,f);o.globalCompositeOperation=`destination-in`;o.drawImage(p.canvas,0,0);o.globalCompositeOperation=`source-over`;e.globalCompositeOperation=`destination-over`;e.drawImage(i.canvas,0,0);s||this.canvasFactory.destroy(i)}e.globalCompositeOperation=m;e.globalAlpha=c;N.isCanvasFilterSupported&&(e.filter=l??`none`);e.drawImage(t,0,0);e.restore();o||this.canvasFactory.destroy(p)}#h(e=1){if(this.#e===0||this.#t>0||!this.contentVisible)return!1;this.#t++;this.#o=e;let t=this.#l.at(-1),{canvas:n}=this.ctx,r=this.#p(t,`knockoutTempEntry`,n.width,n.height);this.#n=r;let i=r.context;i.save();i.setTransform(this.ctx.getTransform());tn(this.ctx,i);this.#a=i.globalCompositeOperation;i.globalCompositeOperation=`source-over`;Xt(i,this.ctx);this.#c=t;this.#r=this.ctx;this.#i=this.suspendedCtx;this.ctx=i;this.inSMaskMode&&(this.suspendedCtx=i);return!0}#g(e){if(!e)return;let t=this.#n,n=this.#r,r=this.#i,i=t.context;this.#n=null;this.#r=null;this.#i=null;this.inSMaskMode&&this.suspendedCtx===i&&this.ctx!==i&&this.endSMaskMode();this.inSMaskMode&&(this.suspendedCtx=r);this.ctx._removeMirroring();this.ctx.globalCompositeOperation=this.#a;this.#a=null;tn(this.ctx,n);this.ctx=n;let a=this.#c;this.#c=null;let o=this.#o;this.#o=1;try{this.#m(r??n,t.canvas,{backdropCanvas:a?.backdropCtx?.canvas??null,backdropOffset:a?.backdropCtx?[a.offsetX,a.offsetY]:[0,0],reuseMaskEntry:a?.knockoutMaskEntry??null,poolMeta:a,knockoutAlpha:o})}finally{i.restore();this.#t--;a||this.canvasFactory.destroy(t)}}compose(e){if(!this.current.activeSMask)return;e=e?[Math.floor(e[0]),Math.floor(e[1]),Math.ceil(e[2]),Math.ceil(e[3])]:[0,0,this.ctx.canvas.width,this.ctx.canvas.height];let t=this.current.activeSMask,n=this.suspendedCtx,r=this.#t>0&&n===this.ctx;this.composeSMask(r?null:n,t,this.ctx,e);if(!r){this.ctx.save();this.ctx.setTransform(1,0,0,1,0,0);this.ctx.clearRect(e[0],e[1],e[2]-e[0],e[3]-e[1]);this.ctx.restore()}}composeSMask(e,t,n,r){let i=r[0],a=r[1],o=r[2]-i,s=r[3]-a;if(o===0||s===0)return;let c=this.smaskPreparedEntry;if(c){let e=i,r=a,l=o,u=s,d=this.smaskPreparedOOBAlpha,f=d!==null;if(f){e=Math.max(i,t.offsetX);r=Math.max(a,t.offsetY);l=Math.min(i+o,t.offsetX+t.canvas.width)-e;u=Math.min(a+s,t.offsetY+t.canvas.height)-r}if(l>0&&u>0){let t=e-this.smaskPreparedOffsetX,i=r-this.smaskPreparedOffsetY;n.save();n.globalAlpha=1;n.setTransform(1,0,0,1,0,0);let a=new Path2D;a.rect(e,r,l,u);n.clip(a);n.globalCompositeOperation=`destination-in`;n.drawImage(c.canvas,t,i,l,u,e,r,l,u);n.restore()}f&&d<255&&this._applySMaskOOBAlpha(n,i,a,o,s,e,r,e+l,r+u,d)}else this.genericComposeSMask(t,n,o,s,i,a);if(e){e.save();e.globalAlpha=1;e.globalCompositeOperation=t.blendMode||`source-over`;e.setTransform(1,0,0,1,0,0);e.drawImage(n.canvas,i,a,o,s,i,a,o,s);e.restore()}}_applySMaskOOBAlpha(e,t,n,r,i,a,o,s,c,l){let u=a<s&&o<c;if(u&&a===t&&o===n&&s===t+r&&c===n+i)return;let d=new Path2D;d.rect(t,n,r,i);u&&d.rect(a,o,s-a,c-o);e.save();e.globalAlpha=l/255;e.setTransform(1,0,0,1,0,0);e.clip(d,`evenodd`);e.globalCompositeOperation=`destination-in`;e.fillStyle=`#000000`;e.fillRect(t,n,r,i);e.restore()}genericComposeSMask(e,t,n,r,i,a){let{context:o,offsetX:s,offsetY:c}=e;t.save();t.globalAlpha=1;t.setTransform(1,0,0,1,0,0);let l=new Path2D;l.rect(i,a,n,r);t.clip(l);t.globalCompositeOperation=`destination-in`;t.drawImage(o.canvas,i-s,a-c,n,r,i,a,n,r);t.restore()}save(e){this.inSMaskMode&&tn(this.ctx,this.suspendedCtx);this.ctx.save();let t=this.current;this.stateStack.push(t);this.current=t.clone();this.dependencyTracker?.save(e)}restore(e){this.dependencyTracker?.restore(e);if(this.stateStack.length!==0){this.current=this.stateStack.pop();this.ctx.restore();if(this.inSMaskMode){tn(this.suspendedCtx,this.ctx);this.ctx.setTransform(this.suspendedCtx.getTransform())}this.checkSMaskState(e);this.pendingClip=null;this._cachedScaleForStroking[0]=-1;this._cachedGetSinglePixelWidth=null}else this.inSMaskMode&&this.endSMaskMode()}transform(e,t,n,r,i,a,o){this.dependencyTracker?.recordIncrementalData(`transform`,e);this.ctx.transform(t,n,r,i,a,o);this._cachedScaleForStroking[0]=-1;this._cachedGetSinglePixelWidth=null}constructPath(e,t,n,r){let[i]=n;if(!r){i||=n[0]=new Path2D;t!==x.stroke&&t!==x.closeStroke&&(this.current.tilingPatternDims=null);this[t](e,i);return}if(this.dependencyTracker!==null){let n=t===x.stroke?this.current.lineWidth/2:0;this.dependencyTracker.resetBBox(e).recordBBox(e,this.ctx,r[0]-n,r[2]+n,r[1]-n,r[3]+n).recordDependencies(e,[`transform`])}i instanceof Path2D||(i=n[0]=ke(i));P.axialAlignedBoundingBox(r,z(this.ctx),this.current.minMax);let a=this.current.tilingPatternDims;if(a&&t!==x.stroke&&t!==x.closeStroke&&this.current.fillColor instanceof qt){let e=P.intersect(this.current.clipBox,this.current.minMax);e?this.current.fillColor.updatePatternDims(e,a):this.current.tilingPatternDims=null}this[t](e,i);this._pathStartIdx=e}closePath(e){this.ctx.closePath()}stroke(e,t,n=!0){let r=n&&this.#h(this.current.strokeAlpha),i=this.ctx,a=this.current.strokeColor;i.globalAlpha=this.current.strokeAlpha;if(this.contentVisible){if(typeof a==`object`&&a?.getPattern){let n=a.isModifyingCurrentTransform()?i.getTransform():null;i.save();i.strokeStyle=a.getPattern(i,this,B(i),zt,e);if(n){let e=new Path2D;e.addPath(t,i.getTransform().invertSelf().multiplySelf(n));t=e}this.rescaleAndStroke(t,!1);i.restore()}else this.rescaleAndStroke(t,!0)}this.dependencyTracker?.recordDependencies(e,at);n&&this.consumePath(e,t,this.current.getClippedPathBoundingBox(zt,z(this.ctx)));i.globalAlpha=this.current.fillAlpha;this.#g(r)}closeStroke(e,t){this.stroke(e,t)}fill(e,t,n=!0){let r=n&&this.#h(this.current.fillAlpha),i=this.ctx,a=this.current.fillColor,o=this.current.patternFill,s=!1,c=this.current.getClippedPathBoundingBox();this.dependencyTracker?.recordDependencies(e,ot);if(o){let o=this.current.tilingPatternDims,l=o&&a.canSkipPatternCanvas(o);if(l){a.drawPattern(this,t,this.pendingEOFill,l,e);this.pendingEOFill=!1;n&&this.consumePath(e,t,c);this.current.tilingPatternDims=null;this.#g(r);return}let u=a.isModifyingCurrentTransform()?i.getTransform():null;this.dependencyTracker?.save(e);i.save();i.fillStyle=a.getPattern(i,this,B(i),Rt,e);if(u){let e=new Path2D;e.addPath(t,i.getTransform().invertSelf().multiplySelf(u));t=e}s=!0}if(this.contentVisible&&c!==null){if(this.pendingEOFill){i.fill(t,`evenodd`);this.pendingEOFill=!1}else i.fill(t)}if(s){i.restore();this.dependencyTracker?.restore(e)}n&&this.consumePath(e,t,c);this.#g(r)}eoFill(e,t){this.pendingEOFill=!0;this.fill(e,t)}fillStroke(e,t){let n=this.#h(Math.min(this.current.fillAlpha,this.current.strokeAlpha));this.fill(e,t,!1);this.stroke(e,t,!1);this.consumePath(e,t);this.#g(n)}eoFillStroke(e,t){this.pendingEOFill=!0;this.fillStroke(e,t)}closeFillStroke(e,t){this.fillStroke(e,t)}closeEOFillStroke(e,t){this.pendingEOFill=!0;this.fillStroke(e,t)}endPath(e,t){this.consumePath(e,t)}rawFillPath(e,t){let n=this.#h(this.current.fillAlpha);this.ctx.fill(t);this.dependencyTracker?.recordDependencies(e,ct).recordOperation(e);this.#g(n)}clip(e){this.dependencyTracker?.recordFutureForcedDependency(`clipMode`,e);this.pendingClip=sn}eoClip(e){this.dependencyTracker?.recordFutureForcedDependency(`clipMode`,e);this.pendingClip=cn}beginText(e){this.current.textMatrix=null;this.current.textMatrixScale=1;this.current.x=this.current.lineX=0;this.current.y=this.current.lineY=0;this.dependencyTracker?.recordOpenMarker(e).resetIncrementalData(`sameLineText`).resetIncrementalData(`moveText`,e)}endText(e){let t=this.pendingTextPaths,n=this.ctx;if(this.dependencyTracker){let{dependencyTracker:n}=this;t!==void 0&&n.recordFutureForcedDependency(`textClip`,n.getOpenMarker()).recordFutureForcedDependency(`textClip`,e);n.recordCloseMarker(e)}if(t!==void 0){let e=new Path2D,r=n.getTransform().invertSelf();for(let{transform:n,x:i,y:a,fontSize:o,path:s}of t)s&&e.addPath(s,new DOMMatrix(n).preMultiplySelf(r).translate(i,a).scale(o,-o));n.clip(e)}delete this.pendingTextPaths}setCharSpacing(e,t){this.dependencyTracker?.recordSimpleData(`charSpacing`,e);this.current.charSpacing=t}setWordSpacing(e,t){this.dependencyTracker?.recordSimpleData(`wordSpacing`,e);this.current.wordSpacing=t}setHScale(e,t){this.dependencyTracker?.recordSimpleData(`hScale`,e);this.current.textHScale=t/100}setLeading(e,t){this.dependencyTracker?.recordSimpleData(`leading`,e);this.current.leading=-t}setFont(e,t,n){this.dependencyTracker?.recordSimpleData(`font`,e).recordSimpleDataFromNamed(`fontObj`,t,e);let r=this.commonObjs.get(t),i=this.current;if(!r)throw Error(`Can't find font for ${t}`);i.fontMatrix=r.fontMatrix||f;i.fontMatrix[0]!==0&&i.fontMatrix[3]!==0||E(`Invalid font matrix for font `+t);if(n<0){n=-n;i.fontDirection=-1}else i.fontDirection=1;this.current.font=r;this.current.fontSize=n;if(r.isType3Font)return;let a=r.loadedName||`sans-serif`,o=r.systemFontInfo?.css||`"${a}", ${r.fallbackName}`,s=`normal`;r.black?s=`900`:r.bold&&(s=`bold`);let c=r.italic?`italic`:`normal`,l=n;n<16?l=16:n>100&&(l=100);this.current.fontSizeScale=n/l;this.ctx.font=`${c} ${s} ${l}px ${o}`}setTextRenderingMode(e,t){this.dependencyTracker?.recordSimpleData(`textRenderingMode`,e);this.current.textRenderingMode=t}setTextRise(e,t){this.dependencyTracker?.recordSimpleData(`textRise`,e);this.current.textRise=t}moveText(e,t,n){this.dependencyTracker?.resetIncrementalData(`sameLineText`).recordIncrementalData(`moveText`,e);this.current.x=this.current.lineX+=t;this.current.y=this.current.lineY+=n}setLeadingMoveText(e,t,n){this.setLeading(e,-n);this.moveText(e,t,n)}setTextMatrix(e,t){this.dependencyTracker?.resetIncrementalData(`sameLineText`).recordSimpleData(`textMatrix`,e);let{current:n}=this;n.textMatrix=t;n.textMatrixScale=Math.hypot(t[0],t[1]);n.x=n.lineX=0;n.y=n.lineY=0}nextLine(e){this.moveText(e,0,this.current.leading);this.dependencyTracker?.recordIncrementalData(`moveText`,this.dependencyTracker.getSimpleIndex(`leading`)??e)}#_(e,t,n){let r=new Path2D;r.addPath(e,new DOMMatrix(n).invertSelf().multiplySelf(t));return r}paintChar(e,t,n,r,i,a){let o=this.ctx,s=this.current,c=s.font,l=s.textRenderingMode,u=s.fontSize/s.fontSizeScale,d=l&3,f=!!(l&4),p=s.patternFill&&!c.missingFile,m=s.patternStroke&&!c.missingFile,h;(c.disableFontFace||f||p||m)&&!c.missingFile&&(h=c.getPathGenerator(this.commonObjs,t));if(h&&(c.disableFontFace||p||m)){o.save();o.translate(n,r);o.scale(u,-u);this.dependencyTracker?.recordCharacterBBox(e,o,c);let t;if(d===0||d===2){if(i){t=o.getTransform();o.setTransform(...i);let e=this.#_(h,t,i);o.fill(e)}else o.fill(h)}if(d===1||d===2){if(a){t||=o.getTransform();o.setTransform(...a);let{a:e,b:n,c:r,d:i}=t,s=P.inverseTransform(a),c=P.transform([e,n,r,i,0,0],s);P.singularValueDecompose2dScale(c,K);o.lineWidth*=Math.max(K[0],K[1])/u;o.stroke(this.#_(h,t,a))}else{o.lineWidth/=u;o.stroke(h)}}o.restore()}else{if(d===0||d===2){o.fillText(t,n,r);this.dependencyTracker?.recordCharacterBBox(e,o,c,u,n,r,()=>o.measureText(t))}if(d===1||d===2){this.dependencyTracker&&this.dependencyTracker?.recordCharacterBBox(e,o,c,u,n,r,()=>o.measureText(t)).recordDependencies(e,at);o.strokeText(t,n,r)}}if(f){(this.pendingTextPaths||=[]).push({transform:z(o),x:n,y:r,fontSize:u,path:h});this.dependencyTracker?.recordCharacterBBox(e,o,c,u,n,r)}}get isFontSubpixelAAEnabled(){let e=this.canvasFactory.create(10,10),t=e.context;t.scale(1.5,1);t.fillText(`I`,0,10);let n=t.getImageData(0,0,10,10).data;this.canvasFactory.destroy(e);let r=!1;for(let e=3;e<n.length;e+=4)if(n[e]>0&&n[e]<255){r=!0;break}return j(this,`isFontSubpixelAAEnabled`,r)}showText(e,t){if(this.dependencyTracker){this.dependencyTracker.recordDependencies(e,lt).resetBBox(e);this.current.textRenderingMode&4&&this.dependencyTracker.recordFutureForcedDependency(`textClip`,e).inheritPendingDependenciesAsFutureForcedDependencies()}let n=this.current,r=n.font;if(r.isType3Font){let r=this.#h(n.fillAlpha);this.showType3Text(e,t);this.dependencyTracker?.recordShowTextOperation(e);this.#g(r);return}let i=n.fontSize;if(i===0){this.dependencyTracker?.recordOperation(e);return}let a=this.#h(n.fillAlpha),o=this.ctx,s=n.fontSizeScale,c=n.charSpacing,l=n.wordSpacing,u=n.fontDirection,d=n.textHScale*u,f=t.length,p=r.vertical,m=p?1:-1,h=r.defaultVMetrics,g=i*n.fontMatrix[0],_=n.textRenderingMode===0&&!r.disableFontFace&&!n.patternFill;o.save();n.textMatrix&&o.transform(...n.textMatrix);o.translate(n.x,n.y+n.textRise);u>0?o.scale(d,-1):o.scale(d,1);let v,y,b=n.textRenderingMode&3,x=b===0||b===2,S=b===1||b===2,C=n.lineWidth,w=n.textMatrixScale;w===0||C===0?S&&(C=this.getSinglePixelWidth()):C/=w;if(s!==1){o.scale(s,s);C/=s}o.lineWidth=C;if(x&&n.patternFill){o.save();let t=n.fillColor.getPattern(o,this,B(o),Rt,e);v=z(o);o.restore();o.fillStyle=t}if(S&&n.patternStroke){o.save();let t=n.strokeColor.getPattern(o,this,B(o),zt,e);y=z(o);o.restore();o.strokeStyle=t}if(r.isInvalidPDFjsFont){let r=[],i=0;for(let e of t){r.push(e.unicode);i+=e.width}let s=r.join(``);o.fillText(s,0,0);if(this.dependencyTracker!==null){let t=o.measureText(s);this.dependencyTracker.recordBBox(e,this.ctx,-t.actualBoundingBoxLeft,t.actualBoundingBoxRight,-t.actualBoundingBoxAscent,t.actualBoundingBoxDescent).recordShowTextOperation(e)}n.x+=i*g*d;o.restore();this.compose();this.#g(a);return}let T,E=0;for(T=0;T<f;++T){let n=t[T];if(typeof n==`number`){E+=m*n*i/1e3;continue}let a=!1,d=(n.isSpace?l:0)+c,f=n.fontChar,b=n.accent,x,S,C,w=n.width;if(p){let e=n.vmetric||h,t=-(n.vmetric?e[1]:.5*w)*g,r=e[2]*g;w=e?-e[0]:w;x=t/s;S=(E+r)/s}else{x=E/s;S=0}if(r.remeasure&&w>0){C=o.measureText(f);let e=1e3*C.width/i*s;if(w<e&&this.isFontSubpixelAAEnabled){let t=w/e;a=!0;o.save();o.scale(t,1);x/=t}else w!==e&&(x+=(w-e)/2e3*i/s)}if(this.contentVisible&&(n.isInFont||r.missingFile)){if(_&&!b){o.fillText(f,x,S);this.dependencyTracker?.recordCharacterBBox(e,o,C?{bbox:null}:r,i/s,x,S,()=>C??o.measureText(f))}else{this.paintChar(e,f,x,S,v,y);if(b){let t=x+i*b.offset.x/s,n=S-i*b.offset.y/s;this.paintChar(e,b.fontChar,t,n,v,y)}}}E+=p?w*g-d*u:w*g+d*u;a&&o.restore()}p?n.y-=E:n.x+=E*d;o.restore();this.compose();this.dependencyTracker?.recordShowTextOperation(e);this.#g(a)}showType3Text(e,t){let n=this.ctx,r=this.current,i=r.font,a=r.fontSize,o=r.fontDirection,s=i.vertical?1:-1,c=r.charSpacing,l=r.wordSpacing,u=r.textHScale*o,d=r.fontMatrix||f,p=t.length,m,h,g,_;if(r.textRenderingMode===3||a===0)return;this._cachedScaleForStroking[0]=-1;this._cachedGetSinglePixelWidth=null;n.save();r.textMatrix&&n.transform(...r.textMatrix);n.translate(r.x,r.y+r.textRise);n.scale(u,o);let v=this.dependencyTracker;this.dependencyTracker=v?new it(v,e):null;for(m=0;m<p;++m){h=t[m];if(typeof h==`number`){_=s*h*a/1e3;this.ctx.translate(_,0);r.x+=_*u;continue}let e=(h.isSpace?l:0)+c,o=i.charProcOperatorList[h.operatorListId];if(o){if(this.contentVisible){this.save();n.scale(a,a);n.transform(...d);this.executeOperatorList(o);this.restore()}}else E(`Type3 character "${h.operatorListId}" is not available.`);let f=[h.width,0];P.applyTransform(f,d);g=f[0]*a+e;n.translate(g,0);r.x+=g*u}n.restore();v&&(this.dependencyTracker=v)}setCharWidth(e,t,n){}setCharWidthAndBounds(e,t,n,r,i,a,o){let s=new Path2D;s.rect(r,i,a-r,o-i);this.ctx.clip(s);this.dependencyTracker?.recordBBox(e,this.ctx,r,a,i,o).recordClipBox(e,this.ctx,r,a,i,o);this.endPath(e)}getColorN_Pattern(e,t){let n;if(t[0]===`TilingPattern`){let e=this.baseTransform||z(this.ctx);n=new qt(t,this.ctx,{createCanvasGraphics:(e,t)=>new ln(e,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack},void 0,void 0,this.dependencyTracker?new it(this.dependencyTracker,t,!0):null)},e)}else n=this._getPattern(e,t[1],t[2]);return n}setStrokeColorN(e,...t){this.dependencyTracker?.recordSimpleData(`strokeColor`,e);this.current.strokeColor=this.getColorN_Pattern(e,t);this.current.patternStroke=!0}setFillColorN(e,...t){this.dependencyTracker?.recordSimpleData(`fillColor`,e);let n=this.current.fillColor=this.getColorN_Pattern(e,t);this.current.patternFill=!0;this.current.tilingPatternDims=n instanceof qt?[0,0,0,0]:null}setStrokeRGBColor(e,t){this.dependencyTracker?.recordSimpleData(`strokeColor`,e);this.ctx.strokeStyle=this.current.strokeColor=t;this.current.patternStroke=!1}setStrokeTransparent(e){this.dependencyTracker?.recordSimpleData(`strokeColor`,e);this.ctx.strokeStyle=this.current.strokeColor=`transparent`;this.current.patternStroke=!1}setFillRGBColor(e,t){this.dependencyTracker?.recordSimpleData(`fillColor`,e);this.ctx.fillStyle=this.current.fillColor=t;this.current.patternFill=!1;this.current.tilingPatternDims=null}setFillTransparent(e){this.dependencyTracker?.recordSimpleData(`fillColor`,e);this.ctx.fillStyle=this.current.fillColor=`transparent`;this.current.patternFill=!1;this.current.tilingPatternDims=null}_getPattern(e,t,n=null){let r;if(this.cachedPatterns.has(t))r=this.cachedPatterns.get(t);else{r=function(e){switch(e[0]){case`RadialAxial`:return new Ut(e);case`Mesh`:return new Gt(e);case`Dummy`:return new Kt}throw Error(`Unknown IR type: ${e[0]}`)}(this.getObject(e,t));this.cachedPatterns.set(t,r)}n&&(r.matrix=n);return r}shadingFill(e,t){if(!this.contentVisible)return;let n=this.#h(this.current.fillAlpha),r=this.ctx;this.save(e);r.fillStyle=this._getPattern(e,t).getPattern(r,this,B(r),Bt,e);let i=B(r);if(i){let{width:e,height:t}=r.canvas,n=d.slice();P.axialAlignedBoundingBox([0,0,e,t],i,n);let[a,o,s,c]=n;this.ctx.fillRect(a,o,s-a,c-o)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.dependencyTracker?.resetBBox(e).recordFullPageBBox(e).recordDependencies(e,ut).recordDependencies(e,ot).recordOperation(e);this.compose(this.current.getClippedPathBoundingBox());this.restore(e);this.#g(n)}beginInlineImage(){D(`Should not call beginInlineImage`)}beginImageData(){D(`Should not call beginImageData`)}paintFormXObjectBegin(e,t,n){if(this.contentVisible){this.save(e);this.baseTransformStack.push(this.baseTransform);t&&this.transform(e,...t);this.baseTransform=z(this.ctx);if(n){P.axialAlignedBoundingBox(n,this.baseTransform,this.current.minMax);let[t,r,i,a]=n,o=new Path2D;o.rect(t,r,i-t,a-r);this.ctx.clip(o);this.dependencyTracker?.recordClipBox(e,this.ctx,t,i,r,a);this.endPath(e)}}}paintFormXObjectEnd(e){if(this.contentVisible){this.restore(e);this.baseTransform=this.baseTransformStack.pop()}}beginGroup(e,t){if(!this.contentVisible)return;this.save(e);let{inSMaskMode:n}=this;if(n){this.endSMaskMode();this.current.activeSMask=null}let r=this.ctx;t.isolated||t.knockout||this.#e!==0||T(`TODO: Fully support non-isolated non-knockout groups.`);if(!t.needsIsolation&&!t.knockout&&this.#e===0&&r.globalAlpha===1&&r.globalCompositeOperation===`source-over`&&!n){if(t.bbox){let e=new Path2D,[n,i,a,o]=t.bbox;e.rect(n,i,a-n,o-i);if(t.matrix){let n=new Path2D;n.addPath(e,new DOMMatrix(t.matrix));e=n}r.clip(e)}this.groupStack.push(null);this.#l.push(null);this.groupLevel++;return}let i=z(r);t.matrix&&r.transform(...t.matrix);let a=[0,0,r.canvas.width,r.canvas.height],o;if(t.bbox){o=d.slice();P.axialAlignedBoundingBox(t.bbox,z(r),o);o=P.intersect(o,a)||[0,0,0,0]}else o=a;let s=Math.floor(o[0]),c=Math.floor(o[1]),l=Math.max(Math.ceil(o[2])-s,1),u=Math.max(Math.ceil(o[3])-c,1);this.current.startNewPathAndClipBox([0,0,l,u]);let f=this.canvasFactory.create(l,u);t.smask&&this.smaskGroupCanvases.push(f);let p=f.context,m=t.knockout&&!t.isolated?r:null,h=!t.isolated&&!t.knockout&&!t.smask&&t.needsIsolation&&this.#e>0,g=t.knockout?this.canvasFactory.create(l,u):null,_=this.#e;t.knockout?this.#e++:this.#e=0;p.translate(-s,-c);p.transform(...i);if(!t.isolated&&!t.smask&&n&&t.needsIsolation){p.save();p.setTransform(1,0,0,1,0,0);p.drawImage(r.canvas,-s,-c);p.restore()}if(t.bbox){let e=new Path2D,[n,r,i,a]=t.bbox;e.rect(n,r,i-n,a-r);if(t.matrix){let n=new Path2D;n.addPath(e,new DOMMatrix(t.matrix));e=n}p.clip(e)}t.smask&&this.smaskStack.push({canvas:f.canvas,context:p,offsetX:s,offsetY:c,subtype:t.smask.subtype,backdrop:t.smask.backdrop,transferMap:t.smask.transferMap||null});if(!t.smask||this.dependencyTracker){r.setTransform(1,0,0,1,0,0);r.translate(s,c);r.save()}tn(r,p);this.ctx=p;this.dependencyTracker?.inheritSimpleDataAsFutureForcedDependencies([`fillAlpha`,`strokeAlpha`,`globalCompositeOperation`]).pushBaseTransform(r);this.setGState(e,[[`BM`,`source-over`],[`ca`,1],[`CA`,1],[`TR`,null]]);this.groupStack.push(r);this.#l.push({backdropCtx:m,savedKnockoutLevel:_,offsetX:s,offsetY:c,hasInnerBackdrop:h,knockoutMaskEntry:g,knockoutTempEntry:null,knockoutBackdropEntry:null});this.groupLevel++}endGroup(e,t){if(!this.contentVisible)return;this.groupLevel--;let n=this.ctx,r=this.groupStack.pop(),i=this.#l.pop();i&&(this.#e=i.savedKnockoutLevel);if(r!==null){this.ctx=r;this.ctx.imageSmoothingEnabled=!1;this.dependencyTracker?.popBaseTransform();if(t.smask){this.tempSMask=this.smaskStack.pop();this.restore(e);if(this.dependencyTracker){this.ctx.restore();this.inSMaskMode&&this.ctx.setTransform(this.suspendedCtx.getTransform())}this.#v(i)}else{this.ctx.restore();let t=z(this.ctx);this.restore(e);this.ctx.save();this.ctx.setTransform(...t);let a=d.slice();P.axialAlignedBoundingBox([0,0,n.canvas.width,n.canvas.height],t,a);let o=this.#l.at(-1);if(this.#e>0){if(i.hasInnerBackdrop){let{width:e,height:a}=n.canvas,o=this.canvasFactory.create(e,a),s=o.context;s.drawImage(r.canvas,i.offsetX,i.offsetY,e,a,0,0,e,a);s.globalCompositeOperation=`source-over`;s.drawImage(n.canvas,0,0);let c=this.#f(n.canvas);s.globalCompositeOperation=`destination-in`;s.drawImage(c.canvas,0,0);let l=this.ctx.globalCompositeOperation,u=this.ctx.globalAlpha,d=this.ctx.filter;this.ctx.save();this.ctx.setTransform(...t);this.ctx.globalAlpha=1;N.isCanvasFilterSupported&&(this.ctx.filter=`none`);this.ctx.globalCompositeOperation=`destination-out`;this.ctx.drawImage(c.canvas,0,0);this.ctx.globalCompositeOperation=l;this.ctx.globalAlpha=u;N.isCanvasFilterSupported&&(this.ctx.filter=d??`none`);this.ctx.drawImage(o.canvas,0,0);this.ctx.restore();this.canvasFactory.destroy(c);this.canvasFactory.destroy(o)}else{let e=o?.backdropCtx??null;this.#m(this.ctx,n.canvas,{backdropCanvas:e?.canvas??null,destTransform:t,backdropOffset:e?[o.offsetX+i.offsetX,o.offsetY+i.offsetY]:[0,0],sourceAlpha:this.ctx.globalAlpha,sourceFilter:this.ctx.filter})}}else this.ctx.drawImage(n.canvas,0,0);this.ctx.restore();this.canvasFactory.destroy({canvas:n.canvas,context:n});this.#v(i);this.compose(a)}}else this.restore(e)}#v(e){if(e){if(e.knockoutMaskEntry){this.canvasFactory.destroy(e.knockoutMaskEntry);e.knockoutMaskEntry=null}if(e.knockoutTempEntry){this.canvasFactory.destroy(e.knockoutTempEntry);e.knockoutTempEntry=null}if(e.knockoutBackdropEntry){this.canvasFactory.destroy(e.knockoutBackdropEntry);e.knockoutBackdropEntry=null}}}beginAnnotation(e,t,n,r,i,a){this.#u();nn(this.ctx);this.ctx.save();this.save(e);this.baseTransform&&this.ctx.setTransform(...this.baseTransform);if(n){let i=n[2]-n[0],o=n[3]-n[1];if(a&&this.annotationCanvasMap){(r=r.slice())[4]-=n[0];r[5]-=n[1];(n=n.slice())[0]=n[1]=0;n[2]=i;n[3]=o;P.singularValueDecompose2dScale(z(this.ctx),K);let{viewportScale:e}=this,a=Math.ceil(i*this.outputScaleX*e),s=Math.ceil(o*this.outputScaleY*e);this.annotationCanvas=this.canvasFactory.create(a,s);let{canvas:c,context:l}=this.annotationCanvas;this.annotationCanvasMap.set(t,c);this.annotationCanvas.savedCtx=this.ctx;this.ctx=l;this.ctx.save();this.ctx.setTransform(K[0],0,0,-K[1],0,o*K[1]);nn(this.ctx)}else{nn(this.ctx);this.endPath(e);let t=new Path2D;t.rect(n[0],n[1],i,o);this.ctx.clip(t)}}this.current=new Qt(this.ctx.canvas.width,this.ctx.canvas.height);this.baseTransformStack.push(this.baseTransform);this.transform(e,...r);this.transform(e,...i);this.baseTransform=z(this.ctx)}endAnnotation(e){if(this.annotationCanvas){this.ctx.restore();this.#d();this.ctx=this.annotationCanvas.savedCtx;delete this.annotationCanvas.savedCtx;delete this.annotationCanvas}this.baseTransform=this.baseTransformStack.pop()}paintImageMaskXObject(e,t){if(!this.contentVisible)return;let n=t.count;(t=this.getObject(e,t.data,t)).count=n;let r=this.#h(this.current.fillAlpha),i=this.ctx,a=this._createMaskCanvas(e,t),o=a.canvas;i.save();i.setTransform(1,0,0,1,0,0);i.drawImage(o,a.offsetX,a.offsetY);this.dependencyTracker?.resetBBox(e).recordBBox(e,this.ctx,a.offsetX,a.offsetX+o.width,a.offsetY,a.offsetY+o.height).recordOperation(e);i.restore();a.canvasEntry&&this.canvasFactory.destroy(a.canvasEntry);this.compose();this.#g(r)}paintImageMaskXObjectRepeat(e,t,n,r=0,i=0,a,o){if(!this.contentVisible)return;t=this.getObject(e,t.data,t);let s=this.#h(this.current.fillAlpha),c=this.ctx;c.save();let l=z(c);c.transform(n,r,i,a,0,0);let u=this._createMaskCanvas(e,t);c.setTransform(1,0,0,1,u.offsetX-l[4],u.offsetY-l[5]);this.dependencyTracker?.resetBBox(e);for(let t=0,s=o.length;t<s;t+=2){let s=P.transform(l,[n,r,i,a,o[t],o[t+1]]);c.drawImage(u.canvas,s[4],s[5]);this.dependencyTracker?.recordBBox(e,this.ctx,s[4],s[4]+u.canvas.width,s[5],s[5]+u.canvas.height)}c.restore();u.canvasEntry&&this.canvasFactory.destroy(u.canvasEntry);this.compose();this.dependencyTracker?.recordOperation(e);this.#g(s)}paintImageMaskXObjectGroup(e,t){if(!this.contentVisible)return;let n=this.#h(this.current.fillAlpha),r=this.ctx,i=this.current.fillColor,a=this.current.patternFill;this.dependencyTracker?.resetBBox(e).recordDependencies(e,dt);for(let n of t){let{data:t,width:o,height:s,transform:c}=n,l=this.canvasFactory.create(o,s),u=l.context;u.save();en(u,this.getObject(e,t,n));u.globalCompositeOperation=`source-in`;u.fillStyle=a?i.getPattern(u,this,B(r),Rt,e):i;u.fillRect(0,0,o,s);u.restore();r.save();r.transform(...c);r.scale(1,-1);Zt(r,l.canvas,0,0,o,s,0,-1,1,1);this.canvasFactory.destroy(l);this.dependencyTracker?.recordBBox(e,r,0,o,0,s);r.restore()}this.compose();this.dependencyTracker?.recordOperation(e);this.#g(n)}paintImageXObject(e,t){if(!this.contentVisible)return;let n=this.getObject(e,t);n?this.paintInlineImageXObject(e,n):E(`Dependent image isn't ready yet`)}paintImageXObjectRepeat(e,t,n,r,i){if(!this.contentVisible)return;let a=this.getObject(e,t);if(!a){E(`Dependent image isn't ready yet`);return}let o=a.width,s=a.height,c=[];for(let e=0,t=i.length;e<t;e+=2)c.push({transform:[n,0,0,r,i[e],i[e+1]],x:0,y:0,w:o,h:s});this.paintInlineImageXObjectGroup(e,a,c)}applyTransferMapsToCanvas(e){if(this.current.transferMaps!==`none`){e.filter=this.current.transferMaps;e.drawImage(e.canvas,0,0);e.filter=`none`}return e.canvas}applyTransferMapsToBitmap(e){if(this.current.transferMaps===`none`)return{img:e.bitmap,canvasEntry:null};let{bitmap:t,width:n,height:r}=e,i=this.canvasFactory.create(n,r),a=i.context;a.filter=this.current.transferMaps;a.drawImage(t,0,0);a.filter=`none`;return{img:i.canvas,canvasEntry:i}}paintInlineImageXObject(e,t){if(!this.contentVisible)return;let n=t.width,r=t.height,i=this.#h(this.current.fillAlpha),a=this.ctx;this.save(e);let{filter:o}=a;o!==`none`&&o!==``&&(a.filter=`none`);a.scale(1/n,-1/r);let s,c=null;if(t.bitmap){let e=this.applyTransferMapsToBitmap(t);s=e.img;c=e.canvasEntry}else if(typeof HTMLElement==`function`&&t instanceof HTMLElement||!t.data)s=t;else{let e=this.canvasFactory.create(n,r);$t(e.context,t);s=this.applyTransferMapsToCanvas(e.context);c=e}let l=this._scaleImage(s,B(a));a.imageSmoothingEnabled=rn(z(a),t.interpolate);if(this.dependencyTracker){this.dependencyTracker.resetBBox(e).recordBBox(e,a,0,n,-r,0).recordDependencies(e,st).recordOperation(e);this.imagesTracker?.record(a,n,r,this.dependencyTracker.clipBox)}Zt(a,l.img,0,0,l.paintWidth,l.paintHeight,0,-r,n,r);l.tmpCanvas&&this.canvasFactory.destroy(l.tmpCanvas);c&&this.canvasFactory.destroy(c);this.compose();this.restore(e);this.#g(i)}paintInlineImageXObjectGroup(e,t,n){if(!this.contentVisible)return;let r=this.#h(this.current.fillAlpha),i=this.ctx,a,o=null;if(t.bitmap)a=t.bitmap;else{let e=t.width,n=t.height,r=this.canvasFactory.create(e,n);$t(r.context,t);a=this.applyTransferMapsToCanvas(r.context);o=r}this.dependencyTracker?.resetBBox(e);for(let t of n){i.save();i.transform(...t.transform);i.scale(1,-1);Zt(i,a,t.x,t.y,t.w,t.h,0,-1,1,1);this.dependencyTracker?.recordBBox(e,i,0,1,-1,0);i.restore()}o&&this.canvasFactory.destroy(o);this.dependencyTracker?.recordOperation(e);this.compose();this.#g(r)}paintSolidColorImageMask(e){if(!this.contentVisible)return;let t=this.#h(this.current.fillAlpha);this.dependencyTracker?.resetBBox(e).recordBBox(e,this.ctx,0,1,0,1).recordDependencies(e,ot).recordOperation(e);this.ctx.fillRect(0,0,1,1);this.compose();this.#g(t)}markPoint(e,t){}markPointProps(e,t,n){}beginMarkedContent(e,t){this.dependencyTracker?.beginMarkedContent(e);this.markedContentStack.push({visible:!0})}beginMarkedContentProps(e,t,n){this.dependencyTracker?.beginMarkedContent(e);t===`OC`?this.markedContentStack.push({visible:this.optionalContentConfig.isVisible(n)}):this.markedContentStack.push({visible:!0});this.contentVisible=this.isContentVisible()}endMarkedContent(e){this.dependencyTracker?.endMarkedContent(e);this.markedContentStack.pop();this.contentVisible=this.isContentVisible()}beginCompat(e){}endCompat(e){}consumePath(e,t,n){let r=this.current.isEmptyClip();this.pendingClip&&this.current.updateClipFromPath();this.pendingClip||this.compose(n);let i=this.ctx;if(this.pendingClip){r||(this.pendingClip===cn?i.clip(t,`evenodd`):i.clip(t));this.pendingClip=null;this.dependencyTracker?.bboxToClipBoxDropOperation(e).recordFutureForcedDependency(`clipPath`,e)}else this.dependencyTracker?.recordOperation(e);this.current.startNewPathAndClipBox(this.current.clipBox)}getSinglePixelWidth(){if(!this._cachedGetSinglePixelWidth){let e=z(this.ctx);if(e[1]===0&&e[2]===0)this._cachedGetSinglePixelWidth=1/Math.min(Math.abs(e[0]),Math.abs(e[3]));else{let t=Math.abs(e[0]*e[3]-e[2]*e[1]),n=Math.hypot(e[0],e[2]),r=Math.hypot(e[1],e[3]);this._cachedGetSinglePixelWidth=Math.max(n,r)/t}}return this._cachedGetSinglePixelWidth}getScaleForStroking(){if(this._cachedScaleForStroking[0]===-1){let{lineWidth:e}=this.current,{a:t,b:n,c:r,d:i}=this.ctx.getTransform(),a,o;if(n===0&&r===0){let n=Math.abs(t),r=Math.abs(i);if(n===r){if(e===0)a=o=1/n;else{let t=n*e;a=o=t<1?1/t:1}}else if(e===0){a=1/n;o=1/r}else{let t=n*e,i=r*e;a=t<1?1/t:1;o=i<1?1/i:1}}else{let s=Math.abs(t*i-n*r),c=Math.hypot(t,n),l=Math.hypot(r,i);if(e===0){a=l/s;o=c/s}else{let t=e*s;a=l>t?l/t:1;o=c>t?c/t:1}}this._cachedScaleForStroking[0]=a;this._cachedScaleForStroking[1]=o}return this._cachedScaleForStroking}rescaleAndStroke(e,t){let{ctx:n,current:{lineWidth:r}}=this,[i,a]=this.getScaleForStroking();if(i===a){n.lineWidth=(r||1)*i;n.stroke(e);return}let o=n.getLineDash();t&&n.save();n.scale(i,a);Yt.a=1/i;Yt.d=1/a;let s=new Path2D;s.addPath(e,Yt);if(o.length>0){let e=Math.max(i,a);n.setLineDash(o.map(t=>t/e));n.lineDashOffset/=e}n.lineWidth=r||1;n.stroke(s);t&&n.restore()}isContentVisible(){for(let e=this.markedContentStack.length-1;e>=0;e--)if(!this.markedContentStack[e].visible)return!1;return!0}}for(let e in x)ln.prototype[e]!==void 0&&(ln.prototype[x[e]]=ln.prototype[e]);class un{#e=null;#t=null;_fullReader=null;_rangeReaders=new Set;_source=null;constructor(e,t,n){this._source=e;this.#e=t;this.#t=n}get _progressiveDataLength(){return this._fullReader?._loaded??0}getFullReader(){O(!this._fullReader,`BasePDFStream.getFullReader can only be called once.`);return this._fullReader=new this.#e(this)}getRangeReader(e,t){if(t<=this._progressiveDataLength)return null;let n=new this.#t(this,e,t);this._rangeReaders.add(n);return n}cancelAllRequests(e){this._fullReader?.cancel(e);for(let t of new Set(this._rangeReaders))t.cancel(e)}}class dn{onProgress=null;_contentLength=0;_filename=null;_headersCapability=Promise.withResolvers();_isRangeSupported=!1;_isStreamingSupported=!1;_loaded=0;_stream=null;constructor(e){this._stream=e}_callOnProgress(){this.onProgress?.({loaded:this._loaded,total:this._contentLength})}get headersReady(){return this._headersCapability.promise}get filename(){return this._filename}get contentLength(){return this._contentLength}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}async read(){D("Abstract method `read` called")}cancel(e){D("Abstract method `cancel` called")}}class fn{_stream=null;constructor(e,t,n){this._stream=e}async read(){D("Abstract method `read` called")}cancel(e){D("Abstract method `cancel` called")}}function pn(e,t){let n=new Headers;if(!e||!t||typeof t!=`object`)return n;for(let e in t){let r=t[e];r!==void 0&&n.append(e,r)}return n}function mn(e){return URL.parse(e)?.origin??null}function hn({responseHeaders:e,isHttp:t,rangeChunkSize:n,disableRange:r}){let i={contentLength:0,isRangeSupported:!1},a=parseInt(e.get(`Content-Length`),10);if(!Number.isInteger(a))return i;i.contentLength=a;if(a<=2*n)return i;if(r||!t)return i;if(e.get(`Accept-Ranges`)!==`bytes`)return i;(e.get(`Content-Encoding`)||`identity`)===`identity`&&(i.isRangeSupported=!0);return i}function gn(e){let t=e.get(`Content-Disposition`);if(t){let e=function(e){let t=!0,n=r(`filename\\*`,`i`).exec(e);if(n){n=n[1];let e=o(n);e=unescape(e);e=s(e);e=c(e);return a(e)}n=function(e){let t=[],n,i=r(`filename\\*((?!0\\d)\\d+)(\\*?)`,`ig`);for(;(n=i.exec(e))!==null;){let[,e,r,i]=n;e=parseInt(e,10);if(e in t){if(e===0)break}else t[e]=[r,i]}let a=[];for(let e=0;e<t.length&&e in t;++e){let[n,r]=t[e];r=o(r);if(n){r=unescape(r);e===0&&(r=s(r))}a.push(r)}return a.join(``)}(e);if(n)return a(c(n));n=r(`filename`,`i`).exec(e);if(n){n=n[1];let e=o(n);e=c(e);return a(e)}function r(e,t){return RegExp(`(?:^|;)\\s*`+e+`\\s*=\\s*([^";\\s][^;\\s]*|"(?:[^"\\\\]|\\\\"?)+"?)`,t)}function i(e,n){if(e){if(!/^[\x00-\xFF]+$/.test(n))return n;try{let r=new TextDecoder(e,{fatal:!0}),i=oe(n);n=r.decode(i);t=!1}catch{}}return n}function a(e){if(t&&/[\x80-\xff]/.test(e)){e=i(`utf-8`,e);t&&(e=i(`iso-8859-1`,e))}return e}function o(e){if(e.startsWith(`"`)){let t=e.slice(1).split(`\\"`);for(let e=0;e<t.length;++e){let n=t[e].indexOf(`"`);if(n!==-1){t[e]=t[e].slice(0,n);t.length=e+1}t[e]=t[e].replaceAll(/\\(.)/g,`$1`)}e=t.join(`"`)}return e}function s(e){let t=e.indexOf(`'`);return t===-1?e:i(e.slice(0,t),e.slice(t+1).replace(/^[^']*'/,``))}function c(e){return!e.startsWith(`=?`)||/[\x00-\x19\x80-\xff]/.test(e)?e:e.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,function(e,t,n,r){if(n===`q`||n===`Q`)return i(t,r=(r=r.replaceAll(`_`,` `)).replaceAll(/=([0-9a-fA-F]{2})/g,function(e,t){return String.fromCharCode(parseInt(t,16))}));try{r=atob(r)}catch{}return i(t,r)})}return``}(t);if(e.includes(`%`))try{e=decodeURIComponent(e)}catch{}if(ve(e))return e}return null}function _n(e,t){return new re(`Unexpected server response (${e}) while retrieving PDF "${t.href}".`,e,e===404||e===0&&t.protocol===`file:`)}function vn(e,t){if(e!==t)throw Error(`Expected range response-origin "${e}" to match "${t}".`)}function yn(e,t,n,r){return fetch(e,{method:`GET`,headers:t,signal:r.signal,mode:`cors`,credentials:n?`include`:`same-origin`,redirect:`follow`})}function bn(e,t){if(e!==200&&e!==206)throw _n(e,t)}function xn(e){if(e instanceof Uint8Array)return e.buffer;if(e instanceof ArrayBuffer)return e;throw Error(`getArrayBuffer - unexpected data: ${e}`)}class Sn extends un{_responseOrigin=null;constructor(e){super(e,Cn,wn);let{httpHeaders:t,url:n}=e;O(/https?:/.test(n.protocol),`PDFFetchStream only supports http(s):// URLs.`);this.headers=pn(!0,t)}}class Cn extends dn{_abortController=new AbortController;_reader=null;constructor(e){super(e);let{disableRange:t,disableStream:n,rangeChunkSize:r,url:i,withCredentials:a}=e._source;this._isStreamingSupported=!n;yn(i,new Headers(e.headers),a,this._abortController).then(n=>{e._responseOrigin=mn(n.url);bn(n.status,i);this._reader=n.body.getReader();let a=n.headers,{contentLength:o,isRangeSupported:s}=hn({responseHeaders:a,isHttp:!0,rangeChunkSize:r,disableRange:t});this._contentLength=o;this._isRangeSupported=s;this._filename=gn(a);!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new ae(`Streaming is disabled.`));this._headersCapability.resolve()}).catch(this._headersCapability.reject)}async read(){await this._headersCapability.promise;let{value:e,done:t}=await this._reader.read();if(t)return{value:e,done:t};this._loaded+=e.byteLength;this._callOnProgress();return{value:xn(e),done:!1}}cancel(e){this._reader?.cancel(e);this._abortController.abort()}}class wn extends fn{_abortController=new AbortController;_readCapability=Promise.withResolvers();_reader=null;constructor(e,t,n){super(e,t,n);let{url:r,withCredentials:i}=e._source,a=new Headers(e.headers);a.append(`Range`,`bytes=${t}-${n-1}`);yn(r,a,i,this._abortController).then(t=>{vn(mn(t.url),e._responseOrigin);bn(t.status,r);this._reader=t.body.getReader();this._readCapability.resolve()}).catch(this._readCapability.reject)}async read(){await this._readCapability.promise;let{value:e,done:t}=await this._reader.read();return t?{value:e,done:t}:{value:xn(e),done:!1}}cancel(e){this._reader?.cancel(e);this._abortController.abort()}}function Tn(e){return e instanceof Uint8Array&&e.byteLength===e.buffer.byteLength?e.buffer:new Uint8Array(e).buffer}function En(){for(let e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}class Dn extends un{_progressiveDone=!1;_queuedChunks=[];constructor(e){super(e,On,kn);let{pdfDataRangeTransport:t}=e,{initialData:n,progressiveDone:r}=t;if(n?.length>0){let e=Tn(n);this._queuedChunks.push(e)}this._progressiveDone=r;t.transportReady(e=>{switch(e.type){case`range`:case`progressiveRead`:this.#e(e.begin,e.chunk);break;case`progressiveDone`:this._fullReader?.progressiveDone();this._progressiveDone=!0}})}#e(e,t){let n=Tn(t);if(e===void 0)this._fullReader?this._fullReader._enqueue(n):this._queuedChunks.push(n);else{let t=this._rangeReaders.keys().find(t=>t._begin===e);O(t,"#onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.");t._enqueue(n)}}getFullReader(){let e=super.getFullReader();this._queuedChunks=null;return e}getRangeReader(e,t){let n=super.getRangeReader(e,t);if(n){n.onDone=()=>this._rangeReaders.delete(n);this._source.pdfDataRangeTransport.requestDataRange(e,t)}return n}cancelAllRequests(e){super.cancelAllRequests(e);this._source.pdfDataRangeTransport.abort()}}class On extends dn{#e=En.bind(this);_done=!1;_queuedChunks=null;_requests=[];constructor(e){super(e);let{pdfDataRangeTransport:t,disableRange:n,disableStream:r}=e._source,{length:i,contentDispositionFilename:a}=t;this._queuedChunks=e._queuedChunks||[];for(let e of this._queuedChunks)this._loaded+=e.byteLength;this._done=e._progressiveDone;this._contentLength=i;this._isStreamingSupported=!r;this._isRangeSupported=!n;ve(a)&&(this._filename=a);this._headersCapability.resolve();let o=this._loaded;Promise.resolve().then(()=>{o>0&&this._loaded===o&&this._callOnProgress()})}_enqueue(e){if(!this._done){this._requests.length>0?this._requests.shift().resolve({value:e,done:!1}):this._queuedChunks.push(e);this._loaded+=e.byteLength;this._callOnProgress()}}async read(){if(this._queuedChunks.length>0)return{value:this._queuedChunks.shift(),done:!1};if(this._done)return{value:void 0,done:!0};let e=Promise.withResolvers();this._requests.push(e);return e.promise}cancel(e){this._done=!0;this.#e()}progressiveDone(){this._done||=!0;this._queuedChunks.length===0&&this.#e()}}class kn extends fn{#e=En.bind(this);onDone=null;_begin=-1;_done=!1;_queuedChunk=null;_requests=[];constructor(e,t,n){super(e,t,n);this._begin=t}_enqueue(e){if(!this._done){if(this._requests.length===0)this._queuedChunk=e;else{this._requests.shift().resolve({value:e,done:!1});this.#e()}this._done=!0;this.onDone?.()}}async read(){if(this._queuedChunk){let e=this._queuedChunk;this._queuedChunk=null;return{value:e,done:!1}}if(this._done)return{value:void 0,done:!0};let e=Promise.withResolvers();this._requests.push(e);return e.promise}cancel(e){this._done=!0;this.#e();this.onDone?.()}}class An extends un{#e=new WeakMap;_responseOrigin=null;constructor(e){super(e,jn,Mn);let{httpHeaders:t,url:n}=e;this.url=n;this.isHttp=/https?:/.test(n.protocol);this.headers=pn(this.isHttp,t)}_request(e){let t=new XMLHttpRequest,n={validateStatus:null,onHeadersReceived:e.onHeadersReceived,onDone:e.onDone,onError:e.onError,onProgress:e.onProgress};this.#e.set(t,n);t.open(`GET`,this.url);t.withCredentials=this._source.withCredentials;for(let[e,n]of this.headers)t.setRequestHeader(e,n);if(this.isHttp&&`begin`in e&&`end`in e){t.setRequestHeader(`Range`,`bytes=${e.begin}-${e.end-1}`);n.validateStatus=e=>e===206||e===200}else n.validateStatus=e=>e===200;t.responseType=`arraybuffer`;O(e.onError,"Expected `onError` callback to be provided.");t.onerror=()=>e.onError(t.status);t.onreadystatechange=this.#n.bind(this,t);t.onprogress=this.#t.bind(this,t);t.send(null);return t}#t(e,t){this.#e.get(e)?.onProgress?.(t)}#n(e,t){let n=this.#e.get(e);if(!n)return;if(e.readyState>=2&&n.onHeadersReceived){n.onHeadersReceived();delete n.onHeadersReceived}if(e.readyState!==4)return;if(!this.#e.has(e))return;this.#e.delete(e);if(e.status===0&&this.isHttp){n.onError(e.status);return}let r=e.status||200;if(!n.validateStatus(r)){n.onError(e.status);return}let i=function(e){return typeof e==`string`?oe(e).buffer:e}(e.response);if(r===206){let t=e.getResponseHeader(`Content-Range`);if(/bytes (\d+)-(\d+)\/(\d+)/.test(t))n.onDone(i);else{E(`Missing or invalid "Content-Range" header.`);n.onError(0)}}else i?n.onDone(i):n.onError(e.status)}_abortRequest(e){if(this.#e.has(e)){this.#e.delete(e);e.abort()}}getRangeReader(e,t){let n=super.getRangeReader(e,t);n&&(n.onClosed=()=>this._rangeReaders.delete(n));return n}}class jn extends dn{#e=En.bind(this);_cachedChunks=[];_done=!1;_requests=[];_storedError=null;constructor(e){super(e);this._fullRequestXhr=e._request({onHeadersReceived:this.#t.bind(this),onDone:this.#n.bind(this),onError:this.#r.bind(this),onProgress:this.#i.bind(this)})}#t(){let e=this._stream,{disableRange:t,rangeChunkSize:n}=e._source,r=this._fullRequestXhr;e._responseOrigin=mn(r.responseURL);let i=r.getAllResponseHeaders(),a=new Headers(i?i.trimStart().replace(/[^\S ]+$/,``).split(/[\r\n]+/).map(e=>{let[t,...n]=e.split(`: `);return[t,n.join(`: `)]}):[]),{contentLength:o,isRangeSupported:s}=hn({responseHeaders:a,isHttp:e.isHttp,rangeChunkSize:n,disableRange:t});this._contentLength=o;this._isRangeSupported=s;this._filename=gn(a);this._isRangeSupported&&e._abortRequest(r);this._headersCapability.resolve()}#n(e){this._requests.length>0?this._requests.shift().resolve({value:e,done:!1}):this._cachedChunks.push(e);this._done=!0;this._cachedChunks.length===0&&this.#e()}#r(e){this._storedError=_n(e,this._stream.url);this._headersCapability.reject(this._storedError);for(let e of this._requests)e.reject(this._storedError);this._requests.length=0;this._cachedChunks.length=0}#i(e){this.onProgress?.({loaded:e.loaded,total:e.lengthComputable?e.total:this._contentLength})}async read(){await this._headersCapability.promise;if(this._storedError)throw this._storedError;if(this._cachedChunks.length>0)return{value:this._cachedChunks.shift(),done:!1};if(this._done)return{value:void 0,done:!0};let e=Promise.withResolvers();this._requests.push(e);return e.promise}cancel(e){this._done=!0;this._headersCapability.reject(e);this.#e();this._stream._abortRequest(this._fullRequestXhr);this._fullRequestXhr=null}}class Mn extends fn{#e=En.bind(this);onClosed=null;_done=!1;_queuedChunk=null;_requests=[];_storedError=null;constructor(e,t,n){super(e,t,n);this._requestXhr=e._request({begin:t,end:n,onHeadersReceived:this.#t.bind(this),onDone:this.#n.bind(this),onError:this.#r.bind(this),onProgress:null})}#t(){let e=mn(this._requestXhr?.responseURL);try{vn(e,this._stream._responseOrigin)}catch(e){this._storedError=e;this.#r(0)}}#n(e){this._requests.length>0?this._requests.shift().resolve({value:e,done:!1}):this._queuedChunk=e;this._done=!0;this.#e();this.onClosed?.()}#r(e){this._storedError??=_n(e,this._stream.url);for(let e of this._requests)e.reject(this._storedError);this._requests.length=0;this._queuedChunk=null}async read(){if(this._storedError)throw this._storedError;if(this._queuedChunk!==null){let e=this._queuedChunk;this._queuedChunk=null;return{value:e,done:!1}}if(this._done)return{value:void 0,done:!0};let e=Promise.withResolvers();this._requests.push(e);return e.promise}cancel(e){this._done=!0;this.#e();this._stream._abortRequest(this._requestXhr);this.onClosed?.()}}function Nn(e,t=null){let n=process.getBuiltinModule(`fs`),{Readable:r}=process.getBuiltinModule(`stream`),i=n.createReadStream(e,t);return r.toWeb(i)}class Pn extends un{constructor(e){super(e,Fn,In);let{url:t}=e;O(t.protocol===`file:`,`PDFNodeStream only supports file:// URLs.`)}}class Fn extends dn{_reader=null;constructor(e){super(e);let{disableRange:t,disableStream:n,rangeChunkSize:r,url:i}=e._source;this._isStreamingSupported=!n;process.getBuiltinModule(`fs/promises`).lstat(i).then(e=>{let n=Nn(i);this._reader=n.getReader();let{size:a}=e;this._contentLength=a;this._isRangeSupported=!t&&a>2*r;!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new ae(`Streaming is disabled.`));this._headersCapability.resolve()}).catch(e=>{e.code===`ENOENT`&&(e=_n(0,i));this._headersCapability.reject(e)})}async read(){await this._headersCapability.promise;let{value:e,done:t}=await this._reader.read();if(t)return{value:e,done:t};this._loaded+=e.byteLength;this._callOnProgress();return{value:xn(e),done:!1}}cancel(e){this._reader?.cancel(e)}}class In extends fn{_readCapability=Promise.withResolvers();_reader=null;constructor(e,t,n){super(e,t,n);let{url:r}=e._source;try{let e=Nn(r,{start:t,end:n-1});this._reader=e.getReader();this._readCapability.resolve()}catch(e){this._readCapability.reject(e)}}async read(){await this._readCapability.promise;let{value:e,done:t}=await this._reader.read();return t?{value:e,done:t}:{value:xn(e),done:!1}}cancel(e){this._reader?.cancel(e)}}class Ln{static#e=null;static#t=``;static get workerPort(){return this.#e}static set workerPort(e){if(!(typeof Worker<`u`&&e instanceof Worker)&&e!==null)throw Error("Invalid `workerPort` type.");this.#e=e}static get workerSrc(){return this.#t}static set workerSrc(e){if(typeof e!=`string`)throw Error("Invalid `workerSrc` type.");this.#t=e}}class Rn{#e;#t;constructor({parsedData:e,rawData:t}){this.#e=e;this.#t=t}getRaw(){return this.#t}get(e){return this.#e.get(e)??null}[Symbol.iterator](){return this.#e.entries()}}const zn=Symbol(`INTERNAL`);class Bn{#e=!1;#t=!1;#n=!1;#r=!0;constructor(e,{name:t,intent:n,usage:r,rbGroups:i}){this.#e=!!(e&2);this.#t=!!(e&4);this.name=t;this.intent=n;this.usage=r;this.rbGroups=i}get visible(){if(this.#n)return this.#r;if(!this.#r)return!1;let{print:e,view:t}=this.usage;return this.#e?t?.viewState!==`OFF`:!this.#t||e?.printState!==`OFF`}_setVisible(e,t,n=!1){e!==zn&&D("Internal method `_setVisible` called.");this.#n=n;this.#r=t}}class Vn{#e=null;#t=new Map;#n=null;#r=null;constructor(e,t=2){this.renderingIntent=t;this.name=null;this.creator=null;if(e!==null){this.name=e.name;this.creator=e.creator;this.#r=e.order;for(let n of e.groups)this.#t.set(n.id,new Bn(t,n));if(e.baseState===`OFF`)for(let e of this.#t.values())e._setVisible(zn,!1);for(let t of e.on)this.#t.get(t)._setVisible(zn,!0);for(let t of e.off)this.#t.get(t)._setVisible(zn,!1);this.#n=this.getHash()}}#i(e){let t=e.length;if(t<2)return!0;let n=e[0];for(let r=1;r<t;r++){let t=e[r],i;if(Array.isArray(t))i=this.#i(t);else{if(!this.#t.has(t)){E(`Optional content group not found: ${t}`);return!0}i=this.#t.get(t).visible}switch(n){case`And`:if(!i)return!1;break;case`Or`:if(i)return!0;break;case`Not`:return!i;default:return!0}}return n===`And`}isVisible(e){if(this.#t.size===0)return!0;if(!e){T(`Optional content group not defined.`);return!0}if(e.type===`OCG`){if(!this.#t.has(e.id)){E(`Optional content group not found: ${e.id}`);return!0}return this.#t.get(e.id).visible}if(e.type===`OCMD`){if(e.expression)return this.#i(e.expression);if(!e.policy||e.policy===`AnyOn`){for(let t of e.ids){if(!this.#t.has(t)){E(`Optional content group not found: ${t}`);return!0}if(this.#t.get(t).visible)return!0}return!1}if(e.policy===`AllOn`){for(let t of e.ids){if(!this.#t.has(t)){E(`Optional content group not found: ${t}`);return!0}if(!this.#t.get(t).visible)return!1}return!0}if(e.policy===`AnyOff`){for(let t of e.ids){if(!this.#t.has(t)){E(`Optional content group not found: ${t}`);return!0}if(!this.#t.get(t).visible)return!0}return!1}if(e.policy===`AllOff`){for(let t of e.ids){if(!this.#t.has(t)){E(`Optional content group not found: ${t}`);return!0}if(this.#t.get(t).visible)return!1}return!0}E(`Unknown optional content policy ${e.policy}.`);return!0}E(`Unknown group type ${e.type}.`);return!0}setVisibility(e,t=!0,n=!0){let r=this.#t.get(e);if(r){if(n&&t&&r.rbGroups.length)for(let t of r.rbGroups)for(let n of t)n!==e&&this.#t.get(n)?._setVisible(zn,!1,!0);r._setVisible(zn,!!t,!0);this.#e=null}else E(`Optional content group not found: ${e}`)}setOCGState({state:e,preserveRB:t}){let n;for(let r of e){switch(r){case`ON`:case`OFF`:case`Toggle`:n=r;continue}let e=this.#t.get(r);if(e)switch(n){case`ON`:this.setVisibility(r,!0,t);break;case`OFF`:this.setVisibility(r,!1,t);break;case`Toggle`:this.setVisibility(r,!e.visible,t)}}this.#e=null}get hasInitialVisibility(){return this.#n===null||this.getHash()===this.#n}getOrder(){return this.#t.size?this.#r?this.#r.slice():[...this.#t.keys()]:null}getGroup(e){return this.#t.get(e)||null}getHash(){if(this.#e!==null)return this.#e;let e=new Ge;for(let[t,n]of this.#t)e.update(`${t}:${n.visible}`);return this.#e=e.hexdigest()}[Symbol.iterator](){return this.#t.entries()}}class Hn{#e=null;#t=null;#n=0;#r=null;#i=null;get pagesNumber(){return this.#n}set pagesNumber(e){if(this.#n!==e){this.#n=e;this.#e=null;this.#t=null}}#a(){if(this.#e)return;let e=this.#n,t=this.#e=new Uint32Array(e);for(let n=0;n<e;n++)t[n]=n+1;this.#t=new Int32Array(t)}#o(){let e=new Map,t=this.#e;for(let n=0,r=this.#n;n<r;n++){let r=t[n],i=e.get(r);i?i.push(n+1):e.set(r,[n+1])}return e}movePages(e,t,n){this.#a();let r=this.#e,i=this.#o(),a=t.length,o=new Uint32Array(a),s=0;for(let e=0;e<a;e++){let i=t[e]-1;o[e]=r[i];i<n&&s++}let c=this.#n,l=c-a,u=F(n-s,0,l);for(let t=0,n=0;t<c;t++)e.has(t+1)||(r[n++]=r[t]);r.copyWithin(u+a,u,l);r.set(o,u);this.#s(i);r.every((e,t)=>e===t+1)&&(this.#e=null)}deletePages(e){this.#a();let t=this.#e,n=this.#o();this.#i={pageNumberToId:t.slice(),pagesNumber:this.#n,prevPageNumbers:this.#t.slice()};let r=this.#n-e.length;this.#n=r;let i=this.#e=new Uint32Array(r);this.#t=new Int32Array(r);let a=0,o=0;for(let n of e){let e=n-1;if(e!==a){i.set(t.subarray(a,e),o);o+=e-a}a=e+1}a<t.length&&i.set(t.subarray(a),o);this.#s(n,new Set(e))}cancelDelete(){if(this.#i){this.#e=this.#i.pageNumberToId;this.#n=this.#i.pagesNumber;this.#t=this.#i.prevPageNumbers;this.#i=null}}cleanSavedData(){this.#i=null}copyPages(e){this.#a();this.#r={pageNumbers:e,pageIds:e.map(e=>this.#e[e-1])}}cancelCopy(){this.#r=null}pastePages(e){this.#a();let t=this.#e,n=this.#o(),{pageNumbers:r,pageIds:i}=this.#r,a=this.#n+r.length;this.#n=a;let o=this.#e=new Uint32Array(a);this.#t=new Int32Array(a);o.set(t.subarray(0,e),0);o.set(i,e);o.set(t.subarray(e),e+r.length);this.#s(n,null,e,r);this.#r=null}#s(e,t=null,n=-1,r=null){let i=this.#t,a=this.#e,o=n+(r?.length??0),s=new Map;for(let c=0,l=this.#n;c<l;c++){if(c>=n&&c<o){i[c]=-r[c-n];continue}let l=a[c],u=e.get(l),d=s.get(l)||0;if(t&&u)for(;d<u.length&&t.has(u[d]);)d++;i[c]=u?.[d];s.set(l,d+1)}}hasBeenAltered(){return this.#e!==null}getPageMappingForSaving(e=null){e??=this.#o();let t=0;for(let n of e.values())t=Math.max(t,n.length);let n=Array(t);for(let e=0;e<t;e++)n[e]={document:null,pageIndices:[],includePages:[]};for(let[t,r]of e)for(let e=0,i=r.length;e<i;e++)n[e].includePages.push([t-1,r[e]-1]);for(let{includePages:e,pageIndices:t}of n){e.sort((e,t)=>e[0]-t[0]);for(let n=0,r=e.length;n<r;n++){t.push(e[n][1]);e[n]=e[n][0]}}return n}extractPages(e){e=Array.from(e).sort((e,t)=>e-t);let t=new Map;for(let n=0,r=e.length;n<r;n++){let r=this.getPageId(e[n]);t.getOrInsertComputed(r,ce).push(n+1)}return this.getPageMappingForSaving(t)}getPrevPageNumber(e){return this.#t?.[e-1]??0}getPageNumber(e){if(!this.#e)return e;let t=this.#e;for(let n=0,r=this.#n;n<r;n++)if(t[n]===e)return n+1;return 0}getPageId(e){return this.#e?.[e-1]??e}getMapping(){return this.#e?.subarray(0,this.pagesNumber)}}const Un=Symbol(`INITIAL_DATA`),Wn=()=>({...Promise.withResolvers(),data:Un});class Gn{#e=new Map;get(e,t=null){if(t){let n=this.#e.getOrInsertComputed(e,Wn);n.promise.then(()=>t(n.data));return null}let n=this.#e.get(e);if(!n||n.data===Un)throw Error(`Requesting object that isn't resolved yet ${e}.`);return n.data}has(e){let t=this.#e.get(e);return!!t&&t.data!==Un}delete(e){let t=this.#e.get(e);if(!t||t.data===Un)return!1;this.#e.delete(e);return!0}resolve(e,t=null){let n=this.#e.getOrInsertComputed(e,Wn);if(n.data!==Un)throw Error(`Object already resolved ${e}.`);n.data=t;n.resolve()}clear(){for(let{data:e}of this.#e.values())e?.bitmap?.close();this.#e.clear()}*[Symbol.iterator](){for(let[e,{data:t}]of this.#e)t!==Un&&(yield[e,t])}}class q{#e=Promise.withResolvers();#t=null;#n=!1;#r=!!globalThis.FontInspector?.enabled;#i=null;#a=null;#o=null;#s=0;#c=0;#l=null;#u=null;#d=0;#f=0;#p=Object.create(null);#m=[];#h=null;#g=[];#_=new WeakMap;#v=null;static#y=new Map;static#b=new Map;static#x=new WeakMap;static#S=null;static#C=new Set;constructor({textContentSource:e,images:t,container:n,viewport:r}){if(e instanceof ReadableStream)this.#h=e;else{if(typeof e!=`object`)throw Error(`No "textContentSource" parameter specified.`);this.#h=new ReadableStream({start(t){t.enqueue(e);t.close()}})}this.#t=this.#u=n;this.#i=t;this.#f=r.scale*Te.pixelRatio;this.#d=r.rotation;this.#o={div:null,properties:null,ctx:null};let{pageWidth:i,pageHeight:a,pageX:o,pageY:s}=r.rawDims;this.#v=[1,0,0,-1,-o,s+a];this.#c=i;this.#s=a;q.#k();n.style.setProperty(`--min-font-size`,q.#S);we(n,r);this.#e.promise.finally(()=>{q.#C.delete(this);this.#o=null;this.#p=null}).catch(()=>{})}static get fontFamilyMap(){let{isWindows:e,isFirefox:t}=N.platform;return j(this,`fontFamilyMap`,new Map([[`sans-serif`,(e&&t?`Calibri, `:``)+`sans-serif`],[`monospace`,(e&&t?`Lucida Console, `:``)+`monospace`]]))}render(){this.#i&&this.#t.append(this.#i.render());let e=()=>{this.#l.read().then(({value:t,done:n})=>{if(n)this.#e.resolve();else{this.#a??=t.lang;Object.assign(this.#p,t.styles);this.#w(t.items);e()}},this.#e.reject)};this.#l=this.#h.getReader();q.#C.add(this);e();return this.#e.promise}update({viewport:e,onBefore:t=null}){let n=e.scale*Te.pixelRatio,r=e.rotation;if(r!==this.#d){t?.();this.#d=r;we(this.#u,{rotation:r})}if(n!==this.#f){t?.();this.#f=n;let e={div:null,properties:null,ctx:q.#D(this.#a)};for(let t of this.#g){e.properties=this.#_.get(t);e.div=t;this.#E(e)}}}cancel(){let e=new ae(`TextLayer task cancelled.`);this.#l?.cancel(e).catch(()=>{});this.#l=null;this.#e.reject(e)}get textDivs(){return this.#g}get textContentItemsStr(){return this.#m}#w(e){if(this.#n)return;this.#o.ctx??=q.#D(this.#a);let t=this.#g,n=this.#m;for(let r of e){if(t.length>1e5){E(`Ignoring additional textDivs for performance reasons.`);this.#n=!0;return}if(r.str!==void 0){n.push(r.str);this.#T(r)}else if(r.type===`beginMarkedContentProps`||r.type===`beginMarkedContent`){let e=this.#t;this.#t=document.createElement(`span`);this.#t.classList.add(`markedContent`);r.id&&this.#t.setAttribute(`id`,`${r.id}`);r.tag===`Artifact`&&(this.#t.ariaHidden=!0);e.append(this.#t)}else r.type===`endMarkedContent`&&(this.#t=this.#t.parentNode)}}#T(e){let t=document.createElement(`span`),n={angle:0,canvasWidth:0,hasText:e.str!==``,hasEOL:e.hasEOL,fontSize:0};this.#g.push(t);let r=P.transform(this.#v,e.transform),i=Math.atan2(r[1],r[0]),a=this.#p[e.fontName];a.vertical&&(i+=Math.PI/2);let o=this.#r&&a.fontSubstitution||a.fontFamily;o=q.fontFamilyMap.get(o)||o;let s=Math.hypot(r[2],r[3]),c=s*q.#A(o,a,this.#a),l,u;if(i===0){l=r[4];u=r[5]-c}else{l=r[4]+c*Math.sin(i);u=r[5]-c*Math.cos(i)}let d=t.style;d.left=`${(100*l/this.#c).toFixed(2)}%`;d.top=`${(100*u/this.#s).toFixed(2)}%`;d.setProperty(`--font-height`,`${s.toFixed(2)}px`);d.fontFamily=o;n.fontSize=s;t.setAttribute(`role`,`presentation`);t.textContent=e.str;t.dir=e.dir;this.#r&&(t.dataset.fontName=a.fontSubstitutionLoadedName||e.fontName);i!==0&&(n.angle=180/Math.PI*i);let f=!1;if(e.str.length>1)f=!0;else if(e.str!==` `&&e.transform[0]!==e.transform[3]){let t=Math.abs(e.transform[0]),n=Math.abs(e.transform[3]);t!==n&&Math.max(t,n)/Math.min(t,n)>1.5&&(f=!0)}f&&(n.canvasWidth=a.vertical?e.height:e.width);this.#_.set(t,n);this.#o.div=t;this.#o.properties=n;this.#E(this.#o);n.hasText&&this.#t.append(t);if(n.hasEOL){let e=document.createElement(`br`);e.setAttribute(`role`,`presentation`);this.#t.append(e)}}#E(e){let{div:t,properties:n,ctx:r}=e,{style:i}=t;if(n.canvasWidth!==0&&n.hasText){let{fontFamily:e}=i,{canvasWidth:a,fontSize:o}=n;q.#O(r,o*this.#f,e);let{width:s}=r.measureText(t.textContent);s>0&&i.setProperty(`--scale-x`,a*this.#f/s)}n.angle!==0&&i.setProperty(`--rotate`,`${n.angle}deg`)}static cleanup(){if(!(this.#C.size>0)){this.#y.clear();for(let{canvas:e}of this.#b.values())e.remove();this.#b.clear()}}static#D(e=null){let t=this.#b.get(e||=``);if(!t){let n=document.createElement(`canvas`);n.className=`hiddenCanvasElement`;n.lang=e;document.body.append(n);t=n.getContext(`2d`,{alpha:!1,willReadFrequently:!0});this.#b.set(e,t);this.#x.set(t,{size:0,family:``})}return t}static#O(e,t,n){let r=this.#x.get(e);if(t!==r.size||n!==r.family){e.font=`${t}px ${n}`;r.size=t;r.family=n}}static#k(){if(this.#S!==null)return;let e=document.createElement(`div`);e.style.opacity=0;e.style.lineHeight=1;e.style.fontSize=`1px`;e.style.position=`absolute`;e.textContent=`X`;document.body.append(e);this.#S=e.getBoundingClientRect().height;e.remove()}static#A(e,t,n){let r=this.#y.get(e);if(r)return r;let i=this.#D(n);i.canvas.width=i.canvas.height=30;this.#O(i,30,e);let a=i.measureText(``),o=a.fontBoundingBoxAscent,s=Math.abs(a.fontBoundingBoxDescent);i.canvas.width=i.canvas.height=0;let c=.8;if(o)c=o/(o+s);else{N.platform.isFirefox&&E("Enable the `dom.textMetrics.fontBoundingBox.enabled` preference in `about:config` to improve TextLayer rendering.");t.ascent?c=t.ascent:t.descent&&(c=1+t.descent)}this.#y.set(e,c);return c}}function Kn(e={}){let t=new qn,{docId:n}=t,r=e.url?function(e){if(e instanceof URL)return e;if(typeof e==`string`){if(l){if(/^[a-z][a-z0-9\-+.]+:/i.test(e))return new URL(e);let t=process.getBuiltinModule(`url`);return new URL(t.pathToFileURL(e))}let t=URL.parse(e,window.location);if(t)return t}throw Error(`Invalid PDF url data: either string or URL-object is expected in the url property.`)}(e.url):null,i=e.data?function(e){if(l&&typeof Buffer<`u`&&e instanceof Buffer)throw Error("Please provide binary data as `Uint8Array`, rather than `Buffer`.");if(e instanceof Uint8Array&&e.byteLength===e.buffer.byteLength)return e;if(typeof e==`string`)return oe(e);if(e instanceof ArrayBuffer||ArrayBuffer.isView(e)||typeof e==`object`&&!isNaN(e?.length))return new Uint8Array(e);throw Error(`Invalid PDF binary data: either TypedArray, string, or array-like object is expected in the data property.`)}(e.data):null,a=e.httpHeaders||null,o=!0===e.withCredentials,s=e.password??null,c=e.range instanceof Jn?e.range:null,u=Number.isInteger(e.rangeChunkSize)&&e.rangeChunkSize>0?e.rangeChunkSize:65536,d=e.worker instanceof J?e.worker:null,f=e.verbosity,p=typeof e.docBaseUrl!=`string`||_e(e.docBaseUrl)?null:e.docBaseUrl,m=Ct(e.cMapUrl),h=!1!==e.cMapPacked,g=Ct(e.iccUrl),_=Ct(e.standardFontDataUrl),v=Ct(e.wasmUrl),y=!0!==e.stopAtErrors,b=Number.isInteger(e.maxImageSize)&&e.maxImageSize>-1?e.maxImageSize:-1,x=typeof e.isOffscreenCanvasSupported==`boolean`?e.isOffscreenCanvasSupported:!l,S=typeof e.isImageDecoderSupported==`boolean`?e.isImageDecoderSupported:!l,w=Number.isInteger(e.canvasMaxAreaInBytes)?e.canvasMaxAreaInBytes:-1,T=typeof e.disableFontFace==`boolean`?e.disableFontFace:l,E=!0===e.fontExtraProperties,D=!0===e.enableXfa,O=e.ownerDocument||globalThis.document,k=!0===e.disableRange,A=!0===e.disableStream,j=!0===e.disableAutoFetch,M=!0===e.pdfBug,ee=e.CanvasFactory||(l?Ft:jt),te=e.FilterFactory||(l?Pt:Nt),ne=e.BinaryDataFactory||(l?It:kt),re=!0===e.enableHWA,ie=!0===e.enableWebGPU?function(){return Lt.init()}():Promise.resolve(!1),ae=!1!==e.useWasm,N=e.pagesMapper||new Hn,P=typeof e.useSystemFonts==`boolean`?e.useSystemFonts:!l&&!T,se=typeof e.useWorkerFetch==`boolean`?e.useWorkerFetch:!!(ne===kt&&m&&h&&_&&v&&be(m,document.baseURI)&&be(_,document.baseURI)&&be(v,document.baseURI));C(f);let ce={canvasFactory:new ee({ownerDocument:O,enableHWA:re}),filterFactory:new te({docId:n,ownerDocument:O}),binaryDataFactory:se?null:new ne({cMapUrl:m,standardFontDataUrl:_,wasmUrl:v})};if(!d){d=J.create({verbosity:f,port:Ln.workerPort});t._worker=d}let le={docId:n,apiVersion:`6.0.92`,data:i,password:s,disableAutoFetch:j,rangeChunkSize:u,docBaseUrl:p,enableXfa:D,evaluatorOptions:{maxImageSize:b,disableFontFace:T,ignoreErrors:y,isOffscreenCanvasSupported:x,isImageDecoderSupported:S,canvasMaxAreaInBytes:w,fontExtraProperties:E,useSystemFonts:P,useWasm:ae,useWorkerFetch:se,cMapUrl:m,cMapPacked:h,iccUrl:g,standardFontDataUrl:_,wasmUrl:v,hasGPU:!1}},ue={ownerDocument:O,pdfBug:M,styleElement:null,enableHWA:re,loadingParams:{disableAutoFetch:j,enableXfa:D}};Promise.all([d.promise,ie]).then(function([,e]){if(d.destroyed)throw Error(`Worker was destroyed`);le.evaluatorOptions.hasGPU=e;let s=d.messageHandler.sendWithPromise(`GetDocRequest`,le,i?[i.buffer]:null),f;if(!i){if(c)f=new Dn({pdfDataRangeTransport:c,disableRange:k,disableStream:A});else{if(!r)throw Error("getDocument - expected either `data`, `range`, or `url` parameter.");f=new(function(e){return be(e)?Sn:l?Pn:An}(r))({url:r,httpHeaders:a,withCredentials:o,rangeChunkSize:u,disableRange:k,disableStream:A})}}return s.then(e=>{if(d.destroyed)throw Error(`Worker was destroyed`);let r=new Dt(n,e,d.port),i=new Zn(r,t,f,ue,ce,N);t._transport=i;if(t.destroyed)throw Error(`Loading aborted`);r.send(`Ready`,null)})}).catch(t._capability.reject).finally(t._setupCapability.resolve);return t}class qn{static#e=0;_capability=Promise.withResolvers();_setupCapability=Promise.withResolvers();_transport=null;_worker=null;docId=`d`+qn.#e++;destroyed=!1;onPassword=null;onProgress=null;get promise(){return this._capability.promise}async destroy(){this.destroyed=!0;this._capability.promise.catch(()=>{});try{this._worker?.port&&(this._worker._pendingDestroy=!0);await this._setupCapability.promise;await this._transport?.destroy()}catch(e){this._worker?.port&&delete this._worker._pendingDestroy;throw e}this._transport=null;this._worker?.destroy();this._worker=null}async getData(){return this._transport.getData()}}class Jn{#e=Promise.withResolvers();#t=null;constructor(e,t,n=!1,r=null){this.length=e;this.initialData=t;this.progressiveDone=n;this.contentDispositionFilename=r}onDataRange(e,t){this.#t({type:`range`,begin:e,chunk:t})}onDataProgressiveRead(e){this.#e.promise.then(()=>{this.#t({type:`progressiveRead`,chunk:e})})}onDataProgressiveDone(){this.#e.promise.then(()=>{this.#t({type:`progressiveDone`})})}transportReady(e){this.#t=e;this.#e.resolve()}requestDataRange(e,t){D(`Abstract method PDFDataRangeTransport.requestDataRange`)}abort(){}}class Yn{constructor(e,t){this._pdfInfo=e;this._transport=t}get pagesMapper(){return this._transport.pagesMapper}get annotationStorage(){return this._transport.annotationStorage}get canvasFactory(){return this._transport.canvasFactory}get filterFactory(){return this._transport.filterFactory}get numPages(){return this._pdfInfo.numPages}get fingerprints(){return this._pdfInfo.fingerprints}get isPureXfa(){return j(this,`isPureXfa`,!!this._transport._htmlForXfa)}get allXfaHtml(){return this._transport._htmlForXfa}getPage(e){return this._transport.getPage(e)}getPageIndex(e){return this._transport.getPageIndex(e)}getDestinations(){return this._transport.getDestinations()}getDestination(e){return this._transport.getDestination(e)}getPageLabels(){return this._transport.getPageLabels()}getPageLayout(){return this._transport.getPageLayout()}getPageMode(){return this._transport.getPageMode()}getViewerPreferences(){return this._transport.getViewerPreferences()}getOpenAction(){return this._transport.getOpenAction()}getAttachments(){return this._transport.getAttachments()}getAnnotationsByType(e,t){return this._transport.getAnnotationsByType(e,t)}getJSActions(){return this._transport.getDocJSActions()}getOutline(){return this._transport.getOutline()}getOptionalContentConfig({intent:e=`display`}={}){let{renderingIntent:t}=this._transport.getRenderingIntent(e);return this._transport.getOptionalContentConfig(t)}getPermissions(){return this._transport.getPermissions()}getMetadata(){return this._transport.getMetadata()}getMarkInfo(){return this._transport.getMarkInfo()}getData(){return this._transport.getData()}saveDocument(){return this._transport.saveDocument()}extractPages(e){return this._transport.extractPages(e)}getDownloadInfo(){return this._transport.downloadInfoCapability.promise}getRawData(e){return this._transport.getRawData(e)}cleanup(e=!1){return this._transport.startCleanup(e||this.isPureXfa)}cachedPageNumber(e){return this._transport.cachedPageNumber(e)}get loadingParams(){return this._transport.loadingParams}get loadingTask(){return this._transport.loadingTask}getFieldObjects(){return this._transport.getFieldObjects()}hasJSActions(){return this._transport.hasJSActions()}getCalculationOrderIds(){return this._transport.getCalculationOrderIds()}}class Xn{#e=!1;#t=null;constructor(e,t,n,r,i=!1){this._pageIndex=e;this._pageInfo=t;this._transport=n;this._stats=i?new ye:null;this._pdfBug=i;this.commonObjs=n.commonObjs;this.objs=new Gn;this._intentStates=new Map;this.destroyed=!1;this.recordedBBoxes=null;this.#t=r;this.imageCoordinates=null}clone(e){let t=new Xn(e,this._pageInfo,this._transport,this.#t,this._pdfBug);t.clonedFromIndex=this.clonedFromIndex??this._pageIndex;this._transport.updatePage(t);return t}get pageNumber(){return this._pageIndex+1}set pageNumber(e){this._pageIndex=e-1;this._transport.updatePage(this)}get rotate(){return this._pageInfo.rotate}get ref(){return this._pageInfo.ref}get userUnit(){return this._pageInfo.userUnit}get view(){return this._pageInfo.view}getViewport({scale:e,rotation:t=this.rotate,offsetX:n=0,offsetY:r=0,dontFlip:i=!1}={}){return new he({viewBox:this.view,userUnit:this.userUnit,scale:e,rotation:t,offsetX:n,offsetY:r,dontFlip:i})}getAnnotations({intent:e=`display`}={}){let{renderingIntent:t}=this._transport.getRenderingIntent(e);return this._transport.getAnnotations(this._pageIndex,t)}getJSActions(){return this._transport.getPageJSActions(this._pageIndex)}get filterFactory(){return this._transport.filterFactory}get isPureXfa(){return j(this,`isPureXfa`,!!this._transport._htmlForXfa)}async getXfa(){return this._transport._htmlForXfa?.children[this._pageIndex]||null}render({canvasContext:e,canvas:t=e.canvas,viewport:n,intent:r=`display`,annotationMode:i=m.ENABLE,transform:a=null,background:o=null,optionalContentConfigPromise:s=null,annotationCanvasMap:c=null,pageColors:l=null,printAnnotationStorage:u=null,isEditing:d=!1,recordImages:f=!1,recordOperations:p=!1,operationsFilter:h=null,renderingBudget:g=null,renderingScheduler:_=null}){this._stats?.time(`Overall`);let v=this._transport.getRenderingIntent(r,i,u,d),{renderingIntent:y,cacheKey:b}=v;this.#e=!1;s||=this._transport.getOptionalContentConfig(y);let x=this._intentStates.getOrInsertComputed(b,ue);if(x.streamReaderCancelTimeout){clearTimeout(x.streamReaderCancelTimeout);x.streamReaderCancelTimeout=null}let S=!!(y&4);if(!x.displayReadyCapability){x.displayReadyCapability=Promise.withResolvers();x.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null};this._stats?.time(`Page Request`);this._pumpOperatorList(v)}let C=!(!this._pdfBug||!globalThis.StepperManager?.enabled),w=!!t&&!this.recordedBBoxes&&(p||C),T=!!t&&!this.imageCoordinates&&f,E=e=>{x.renderTasks.delete(k);if(w){let e=k.gfx?.dependencyTracker.take();if(e){k.stepper?.setOperatorBBoxes(e,k.gfx.dependencyTracker.takeDebugMetadata());p&&(this.recordedBBoxes=e)}}T&&!e&&(this.imageCoordinates=k.gfx?.imagesTracker.take());S&&(this.#e=!0);this.#n();if(e){k.capability.reject(e);this._abortOperatorList({intentState:x,reason:e instanceof Error?e:Error(e)})}else k.capability.resolve();if(this._stats){this._stats.timeEnd(`Rendering`);this._stats.timeEnd(`Overall`);globalThis.Stats?.enabled&&globalThis.Stats.add(this.pageNumber,this._stats)}},D=null,O=null;(w||T)&&(O=new nt(t,x.operatorList.length));w&&(D=new rt(O,C));let k=new $n({callback:E,params:{canvas:t,canvasContext:e,dependencyTracker:D??O,imagesTracker:T?new ft(t):null,viewport:n,transform:a,background:o},objs:this.objs,commonObjs:this.commonObjs,annotationCanvasMap:c,operatorList:x.operatorList,pageIndex:this._pageIndex,canvasFactory:this._transport.canvasFactory,filterFactory:this._transport.filterFactory,useRequestAnimationFrame:!S,pdfBug:this._pdfBug,pageColors:l,enableHWA:this._transport.enableHWA,operationsFilter:h,renderingBudget:g,renderingScheduler:_});(x.renderTasks||=new Set).add(k);let A=k.task;Promise.all([x.displayReadyCapability.promise,s]).then(([e,t])=>{if(this.destroyed)E();else{this._stats?.time(`Rendering`);if(!(t.renderingIntent&y))throw Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");k.initializeGraphics({transparency:e,optionalContentConfig:t});k.operatorListChanged()}}).catch(E);return A}getOperatorList({intent:e=`display`,annotationMode:t=m.ENABLE,printAnnotationStorage:n=null,isEditing:r=!1}={}){let i=this._transport.getRenderingIntent(e,t,n,r,!0),a=this._intentStates.getOrInsertComputed(i.cacheKey,ue),o;if(!a.opListReadCapability){o=Object.create(null);o.operatorListChanged=function(){if(a.operatorList.lastChunk){a.opListReadCapability.resolve(a.operatorList);a.renderTasks.delete(o)}};a.opListReadCapability=Promise.withResolvers();(a.renderTasks||=new Set).add(o);a.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null};this._stats?.time(`Page Request`);this._pumpOperatorList(i)}return a.opListReadCapability.promise}streamTextContent({includeMarkedContent:e=!1,disableNormalization:t=!1}={}){return this._transport.messageHandler.sendWithStream(`GetTextContent`,{pageId:this.#t.getPageId(this._pageIndex+1)-1,pageIndex:this._pageIndex,includeMarkedContent:!0===e,disableNormalization:!0===t},{highWaterMark:100,size:e=>e.items.length})}async getTextContent(e={}){if(this._transport._htmlForXfa)return this.getXfa().then(e=>de.textContent(e));let t=this.streamTextContent(e),n={items:[],styles:Object.create(null),lang:null};for await(let e of t){n.lang??=e.lang;Object.assign(n.styles,e.styles);n.items.push(...e.items)}return n}getStructTree(){return this._transport.getStructTree(this._pageIndex)}getGeospatialPDFMetadata(){return this._transport.getGeospatialPDFMetadata(this._pageIndex)}_destroy(){this.destroyed=!0;let e=[];for(let t of this._intentStates.values()){this._abortOperatorList({intentState:t,reason:Error(`Page was destroyed.`),force:!0});if(!t.opListReadCapability)for(let n of t.renderTasks){e.push(n.completed);n.cancel()}}this.objs.clear();this.#e=!1;return Promise.all(e)}cleanup(e=!1){this.#e=!0;let t=this.#n();e&&t&&(this._stats&&=new ye);return t}#n(){if(!this.#e||this.destroyed)return!1;for(let{renderTasks:e,operatorList:t}of this._intentStates.values())if(e.size>0||!t.lastChunk)return!1;this._intentStates.clear();this.objs.clear();this.#e=!1;return!0}_startRenderPage(e,t){let n=this._intentStates.get(t);if(n){this._stats?.timeEnd(`Page Request`);n.displayReadyCapability?.resolve(e)}}_renderPageChunk(e,t){for(let n=0,r=e.length;n<r;n++){t.operatorList.fnArray.push(e.fnArray[n]);t.operatorList.argsArray.push(e.argsArray[n])}t.operatorList.lastChunk=e.lastChunk;t.operatorList.separateAnnots=e.separateAnnots;for(let e of t.renderTasks)e.operatorListChanged();e.lastChunk&&this.#n()}_pumpOperatorList({renderingIntent:e,cacheKey:t,annotationStorageSerializable:n,modifiedIds:r}){let{map:i,transfer:a}=n,o=this._transport.messageHandler.sendWithStream(`GetOperatorList`,{pageId:this.#t.getPageId(this._pageIndex+1)-1,pageIndex:this._pageIndex,intent:e,cacheKey:t,annotationStorage:i,modifiedIds:r},void 0,a).getReader(),s=this._intentStates.get(t);s.streamReader=o;let c=()=>{o.read().then(({value:e,done:t})=>{if(t)s.streamReader=null;else if(!this._transport.destroyed){this._renderPageChunk(e,s);c()}},e=>{s.streamReader=null;if(!this._transport.destroyed){if(s.operatorList){s.operatorList.lastChunk=!0;for(let e of s.renderTasks)e.operatorListChanged();this.#n()}if(s.displayReadyCapability)s.displayReadyCapability.reject(e);else{if(!s.opListReadCapability)throw e;s.opListReadCapability.reject(e)}}})};c()}_abortOperatorList({intentState:e,reason:t,force:n=!1}){if(e.streamReader){if(e.streamReaderCancelTimeout){clearTimeout(e.streamReaderCancelTimeout);e.streamReaderCancelTimeout=null}if(!n){if(e.renderTasks.size>0)return;if(t instanceof ge){let n=100;t.extraDelay>0&&t.extraDelay<1e3&&(n+=t.extraDelay);e.streamReaderCancelTimeout=setTimeout(()=>{e.streamReaderCancelTimeout=null;this._abortOperatorList({intentState:e,reason:t,force:!0})},n);return}}e.streamReader.cancel(new ae(t.message)).catch(()=>{});e.streamReader=null;if(!this._transport.destroyed){for(let[t,n]of this._intentStates)if(n===e){this._intentStates.delete(t);break}this.cleanup()}}}get stats(){return this._stats}}class J{#e=Promise.withResolvers();#t=null;#n=null;#r=null;static#i=0;static#a=!1;static#o=new WeakMap;static{if(l){this.#a=!0;Ln.workerSrc||=`./pdf.worker.mjs`}this._isSameOrigin=(e,t)=>{let n=URL.parse(e);if(!n?.origin||n.origin===`null`)return!1;let r=new URL(t,n);return n.origin===r.origin};this._createCDNWrapper=e=>{let t=`await import("${e}");`;return URL.createObjectURL(new Blob([t],{type:`text/javascript`}))}}constructor({name:e=null,port:t=null,verbosity:n=w()}={}){this.name=e;this.destroyed=!1;this.verbosity=n;if(t){if(J.#o.has(t))throw Error(`Cannot use more than one PDFWorker per port.`);J.#o.set(t,this);this.#c(t)}else this.#l()}get promise(){return this.#e.promise}#s(){this.#e.resolve();this.#t.send(`configure`,{verbosity:this.verbosity})}get port(){return this.#n}get messageHandler(){return this.#t}#c(e){this.#n=e;this.#t=new Dt(`main`,`worker`,e);this.#t.on(`ready`,()=>{});this.#s()}#l(){if(J.#a||J.#d){this.#u();return}let{workerSrc:e}=J;try{J._isSameOrigin(window.location,e)||(e=J._createCDNWrapper(new URL(e,window.location).href));let t=new Worker(e,{type:`module`}),n=new Dt(`main`,`worker`,t),r=()=>{i.abort();n.destroy();t.terminate();this.destroyed?this.#e.reject(Error(`Worker was destroyed`)):this.#u()},i=new AbortController;t.addEventListener(`error`,()=>{this.#r||r()},{signal:i.signal});n.on(`test`,e=>{i.abort();if(!this.destroyed&&e){this.#t=n;this.#n=t;this.#r=t;this.#s()}else r()});n.on(`ready`,e=>{i.abort();if(this.destroyed)r();else try{a()}catch{this.#u()}});let a=()=>{let e=new Uint8Array;n.send(`test`,e,[e.buffer])};a();return}catch{T(`The worker has been disabled.`)}this.#u()}#u(){if(!J.#a){E(`Setting up fake worker.`);J.#a=!0}J._setupFakeWorkerGlobal.then(e=>{if(this.destroyed){this.#e.reject(Error(`Worker was destroyed`));return}let t=new Tt;this.#n=t;let n=`fake`+J.#i++,r=new Dt(n+`_worker`,n,t);e.setup(r,t);this.#t=new Dt(n,n+`_worker`,t);this.#s()}).catch(e=>{this.#e.reject(Error(`Setting up fake worker failed: "${e.message}".`))})}destroy(){this.destroyed=!0;this.#r?.terminate();this.#r=null;J.#o.delete(this.#n);this.#n=null;this.#t?.destroy();this.#t=null}static create(e){let t=this.#o.get(e?.port);if(t){if(t._pendingDestroy)throw Error("PDFWorker.create - the worker is being destroyed.\nPlease remember to await `PDFDocumentLoadingTask.destroy()`-calls.");return t}return new J(e)}static get workerSrc(){if(Ln.workerSrc)return Ln.workerSrc;throw Error(`No "GlobalWorkerOptions.workerSrc" specified.`)}static get#d(){try{return globalThis.pdfjsWorker?.WorkerMessageHandler||null}catch{return null}}static get _setupFakeWorkerGlobal(){return j(this,`_setupFakeWorkerGlobal`,(async()=>{if(this.#d)return this.#d;return(await import(
|
|
46
46
|
/*webpackIgnore: true*/
|
|
47
47
|
/* @vite-ignore */
|
|
48
|
-
this.workerSrc)).WorkerMessageHandler})())}}class er{downloadInfoCapability=Promise.withResolvers();#e=null;#t=new Map;#n=null;#r=new Map;#i=new Map;#a=new Map;#o=null;constructor(e,t,n,r,i,a){this.messageHandler=e;this.loadingTask=t;this.#n=n;this.commonObjs=new Jn;this.fontLoader=new gt({ownerDocument:r.ownerDocument,styleElement:r.styleElement});this.enableHWA=r.enableHWA;this.loadingParams=r.loadingParams;this._params=r;this.canvasFactory=i.canvasFactory;this.filterFactory=i.filterFactory;this.binaryDataFactory=i.binaryDataFactory;this.pagesMapper=a;this.destroyed=!1;this.destroyCapability=null;this.setupMessageHandler()}updatePage(e){let{_pageIndex:t}=e;this.#r.set(t,e);this.#i.set(t,Promise.resolve(e))}#s(e,t=null){return this.#t.getOrInsertComputed(e,()=>this.messageHandler.sendWithPromise(e,t))}#c({loaded:e,total:t}){this.loadingTask.onProgress?.({loaded:e,total:t,percent:t?F(Math.round(e/t*100),0,100):NaN})}get annotationStorage(){return j(this,`annotationStorage`,new Xe)}getRenderingIntent(e,t=g.ENABLE,n=null,r=!1,i=!1){let a=2,o=Ye;switch(e){case`any`:a=1;break;case`display`:break;case`print`:a=4;break;default:O(`getRenderingIntent - invalid intent: ${e}`)}let s=a&4&&n instanceof Ze?n:this.annotationStorage;switch(t){case g.DISABLE:a+=64;break;case g.ENABLE:break;case g.ENABLE_FORMS:a+=16;break;case g.ENABLE_STORAGE:a+=32;o=s.serializable;break;default:O(`getRenderingIntent - invalid annotationMode: ${t}`)}r&&(a+=128);i&&(a+=256);let{ids:c,hash:l}=s.modifiedIds;return{renderingIntent:a,cacheKey:[a,o.hash,l].join(`_`),annotationStorageSerializable:o,modifiedIds:c}}destroy(){if(this.destroyCapability)return this.destroyCapability.promise;this.destroyed=!0;this.destroyCapability=Promise.withResolvers();this.#o?.reject(Error(`Worker was destroyed during onPassword callback`));let e=[];for(let t of this.#r.values())e.push(t._destroy());this.#r.clear();this.#i.clear();this.#a.clear();Object.hasOwn(this,`annotationStorage`)&&this.annotationStorage.resetModified();let t=this.messageHandler.sendWithPromise(`Terminate`,null);e.push(t);Promise.all(e).then(()=>{this.commonObjs.clear();this.fontLoader.clear();this.#t.clear();this.filterFactory.destroy();K.cleanup();this.#n?.cancelAllRequests(new se(`Worker was terminated.`));this.messageHandler?.destroy();this.messageHandler=null;this.destroyCapability.resolve()},this.destroyCapability.reject);return this.destroyCapability.promise}setupMessageHandler(){let{messageHandler:e,loadingTask:t}=this;e.on(`GetReader`,(e,t)=>{A(this.#n,"GetReader - no `BasePDFStream` instance available.");this.#e=this.#n.getFullReader();this.#e.onProgress=e=>this.#c(e);t.onPull=()=>{this.#e.read().then(function({value:e,done:n}){if(n)t.close();else{A(e instanceof ArrayBuffer,`GetReader - expected an ArrayBuffer.`);t.enqueue(new Uint8Array(e),1,[e])}}).catch(e=>{t.error(e)})};t.onCancel=e=>{this.#e.cancel(e);t.ready.catch(e=>{if(!this.destroyed)throw e})}});e.on(`ReaderHeadersReady`,async e=>{await this.#e.headersReady;let{isStreamingSupported:t,isRangeSupported:n,contentLength:r}=this.#e;t&&n&&(this.#e.onProgress=null);return{isStreamingSupported:t,isRangeSupported:n,contentLength:r}});e.on(`GetRangeReader`,(e,t)=>{A(this.#n,"GetRangeReader - no `BasePDFStream` instance available.");let n=this.#n.getRangeReader(e.begin,e.end);if(n){t.onPull=()=>{n.read().then(function({value:e,done:n}){if(n)t.close();else{A(e instanceof ArrayBuffer,`GetRangeReader - expected an ArrayBuffer.`);t.enqueue(new Uint8Array(e),1,[e])}}).catch(e=>{t.error(e)})};t.onCancel=e=>{n.cancel(e);t.ready.catch(e=>{if(!this.destroyed)throw e})}}else t.close()});e.on(`GetDoc`,({pdfInfo:e})=>{this.pagesMapper.pagesNumber=e.numPages;this._numPages=e.numPages;this._htmlForXfa=e.htmlForXfa;delete e.htmlForXfa;t._capability.resolve(new Qn(e,this))});e.on(`DocException`,e=>{t._capability.reject(W(e))});e.on(`PasswordRequest`,e=>{this.#o=Promise.withResolvers();try{if(!t.onPassword)throw W(e);t.onPassword(e=>{e instanceof Error?this.#o.reject(e):this.#o.resolve({password:e})},e.code)}catch(e){this.#o.reject(e)}return this.#o.promise});e.on(`DataLoaded`,e=>{this.#c({loaded:e.length,total:e.length});this.downloadInfoCapability.resolve(e)});e.on(`StartRenderPage`,e=>{if(this.destroyed)return;this.#r.get(e.pageIndex)._startRenderPage(e.transparency,e.cacheKey)});e.on(`commonobj`,([t,n,r])=>{if(this.destroyed)return null;if(this.commonObjs.has(t))return null;switch(n){case`Font`:if(`error`in r){let e=r.error;O(`Error during font loading: ${e}`);this.commonObjs.resolve(t,e);break}let i=new Ct(r),a=this._params.pdfBug&&globalThis.FontInspector?.enabled?(e,t)=>globalThis.FontInspector.fontAdded(e,t):null,o=new _t(i,a,r.charProcOperatorList,r.extra);this.fontLoader.bind(o).catch(()=>e.sendWithPromise(`FontFallback`,{id:t})).finally(()=>{o.fontExtraProperties||o.clearData();this.commonObjs.resolve(t,o)});break;case`CopyLocalImage`:let{imageRef:s}=r;A(s,`The imageRef must be defined.`);for(let e of this.#r.values())for(let[,n]of e.objs){if(n?.ref!==s)continue;if(!n.dataLen)return null;let e=structuredClone(n);this.commonObjs.resolve(t,e);return n.dataLen}break;case`FontPath`:this.commonObjs.resolve(t,new Tt(r));break;case`Image`:this.commonObjs.resolve(t,r);break;case`Pattern`:let c=new wt(r);this.commonObjs.resolve(t,c.getIR());break;default:throw Error(`Got unknown common object type ${n}`)}return null});e.on(`obj`,([e,t,n,r])=>{if(this.destroyed)return;let i=this.#r.get(t);if(!i.objs.has(e)){if(i._intentStates.size!==0)switch(n){case`Image`:case`Pattern`:i.objs.resolve(e,r);break;default:throw Error(`Got unknown object type ${n}`)}else r?.bitmap?.close()}});e.on(`DocProgress`,e=>{this.destroyed||this.#c(e)});e.on(`FetchBinaryData`,async e=>{if(this.destroyed)throw Error(`Worker was destroyed.`);if(!this.binaryDataFactory)throw Error("`BinaryDataFactory` not initialized, see the `useWorkerFetch` parameter.");return this.binaryDataFactory.fetch(e)})}getData(){return this.messageHandler.sendWithPromise(`GetData`,null)}saveDocument(){this.annotationStorage.size<=0&&O("saveDocument called while `annotationStorage` is empty, please use the getData-method instead.");let{map:e,transfer:t}=this.annotationStorage.serializable;return this.messageHandler.sendWithPromise(`SaveDocument`,{isPureXfa:!!this._htmlForXfa,numPages:this._numPages,annotationStorage:e,filename:this.#e?.filename??null},t).finally(()=>{this.annotationStorage.resetModified()})}extractPages(e){let t={pageInfos:e},n;if(this.annotationStorage.size>0){let e=this.annotationStorage.serializable,{map:r}=e;n=e.transfer;let i=this.pagesMapper.getMapping();if(i){let e=new Map;for(let[t,n]of r){if(n?.pageIndex!==void 0&&n.pageIndex>=0&&n.pageIndex<i.length){let r=i[n.pageIndex]-1;if(r!==n.pageIndex){e.set(t,{...n,pageIndex:r});continue}}e.set(t,n)}r=e}t.annotationStorage=r}return this.messageHandler.sendWithPromise(`ExtractPages`,t,n).finally(()=>{this.annotationStorage.resetModified()})}getPage(e){if(!Number.isInteger(e)||e<=0||e>this.pagesMapper.pagesNumber)return Promise.reject(Error(`Invalid page request.`));let t=e-1,n=this.pagesMapper.getPageId(e)-1,r=this.#i.get(t);if(r)return r;let i=this.messageHandler.sendWithPromise(`GetPage`,{pageIndex:n}).then(e=>{if(this.destroyed)throw Error(`Transport destroyed`);e.refStr&&this.#a.set(e.refStr,n);let r=new $n(t,e,this,this.pagesMapper,this._params.pdfBug);this.#r.set(t,r);return r});this.#i.set(t,i);return i}async getPageIndex(e){if(!Dt(e))throw Error(`Invalid pageIndex request.`);let t=await this.messageHandler.sendWithPromise(`GetPageIndex`,{num:e.num,gen:e.gen}),n=this.pagesMapper.getPageNumber(t+1);if(n===0)throw Error(`GetPageIndex: page has been removed.`);return n-1}getAnnotations(e,t){return this.messageHandler.sendWithPromise(`GetAnnotations`,{pageIndex:this.pagesMapper.getPageId(e+1)-1,intent:t})}getFieldObjects(){return this.#s(`GetFieldObjects`)}hasJSActions(){return this.#s(`HasJSActions`)}getCalculationOrderIds(){return this.messageHandler.sendWithPromise(`GetCalculationOrderIds`,null)}getDestinations(){return this.messageHandler.sendWithPromise(`GetDestinations`,null)}getDestination(e){return typeof e==`string`?this.messageHandler.sendWithPromise(`GetDestination`,{id:e}):Promise.reject(Error(`Invalid destination request.`))}getPageLabels(){return this.messageHandler.sendWithPromise(`GetPageLabels`,null)}getPageLayout(){return this.messageHandler.sendWithPromise(`GetPageLayout`,null)}getPageMode(){return this.messageHandler.sendWithPromise(`GetPageMode`,null)}getViewerPreferences(){return this.messageHandler.sendWithPromise(`GetViewerPreferences`,null)}getOpenAction(){return this.messageHandler.sendWithPromise(`GetOpenAction`,null)}getAttachments(){return this.messageHandler.sendWithPromise(`GetAttachments`,null)}getAnnotationsByType(e,t){return this.messageHandler.sendWithPromise(`GetAnnotationsByType`,{types:e,pageIndexesToSkip:t})}getDocJSActions(){return this.#s(`GetDocJSActions`)}getPageJSActions(e){return this.messageHandler.sendWithPromise(`GetPageJSActions`,{pageIndex:this.pagesMapper.getPageId(e+1)-1})}getStructTree(e){return this.messageHandler.sendWithPromise(`GetStructTree`,{pageIndex:this.pagesMapper.getPageId(e+1)-1})}getOutline(){return this.messageHandler.sendWithPromise(`GetOutline`,null)}getOptionalContentConfig(e){return this.#s(`GetOptionalContentConfig`).then(t=>new Wn(t,e))}getPermissions(){return this.messageHandler.sendWithPromise(`GetPermissions`,null)}getMetadata(){let e=`GetMetadata`;return this.#t.getOrInsertComputed(e,()=>this.messageHandler.sendWithPromise(e,null).then(e=>({info:e[0],metadata:e[1]?new Vn(e[1]):null,contentDispositionFilename:this.#e?.filename??null,contentLength:this.#e?.contentLength??null,hasStructTree:e[2]})))}getMarkInfo(){return this.messageHandler.sendWithPromise(`GetMarkInfo`,null)}getRawData(e){return this.messageHandler.sendWithPromise(`GetRawData`,e)}getGeospatialPDFMetadata(e){return this.messageHandler.sendWithPromise(`GetGeospatialPDFMetadata`,{pageIndex:e})}async startCleanup(e=!1){if(!this.destroyed){await this.messageHandler.sendWithPromise(`Cleanup`,null);for(let e of this.#r.values())if(!e.cleanup())throw Error(`startCleanup: Page ${e.pageNumber} is currently rendering.`);this.commonObjs.clear();e||this.fontLoader.clear();this.#t.clear();this.filterFactory.destroy(!0);K.cleanup()}}cachedPageNumber(e){if(!Dt(e))return null;let t=e.gen===0?`${e.num}R`:`${e.num}R${e.gen}`,n=this.#a.get(t);if(n>=0){let e=this.pagesMapper.getPageNumber(n+1);if(e!==0)return e}return null}}class tr{_internalRenderTask=null;onContinue=null;onError=null;constructor(e){this._internalRenderTask=e}get promise(){return this._internalRenderTask.capability.promise}cancel(e=0){this._internalRenderTask.cancel(null,e)}get separateAnnots(){let{separateAnnots:e}=this._internalRenderTask.operatorList;if(!e)return!1;let{annotationCanvasMap:t}=this._internalRenderTask;return e.form||e.canvas&&t?.size>0}get imageCoordinates(){return this._internalRenderTask.imageCoordinates||null}}class nr{#e=null;#t=null;static#n=new WeakSet;constructor({callback:e,params:t,objs:n,commonObjs:r,annotationCanvasMap:i,operatorList:a,pageIndex:o,canvasFactory:s,filterFactory:c,useRequestAnimationFrame:l=!1,pdfBug:u=!1,pageColors:d=null,enableHWA:f=!1,operationsFilter:p=null,renderingBudget:m=null,renderingScheduler:h=null}){this.callback=e;this.params=t;this.objs=n;this.commonObjs=r;this.annotationCanvasMap=i;this.operatorListIdx=null;this.operatorList=a;this._pageIndex=o;this.canvasFactory=s;this.filterFactory=c;this._pdfBug=u;this.pageColors=d;this.running=!1;this.graphicsReadyCallback=null;this.graphicsReady=!1;this._useRequestAnimationFrame=!0===l&&typeof window<`u`;this.cancelled=!1;this.capability=Promise.withResolvers();this.task=new tr(this);this._cancelBound=this.cancel.bind(this);this._continueBound=this._continue.bind(this);this._scheduleNextBound=this._scheduleNext.bind(this);this._nextBound=this._next.bind(this);this._canvas=t.canvas;this._canvasContext=t.canvas?null:t.canvasContext;this._enableHWA=f;this._dependencyTracker=t.dependencyTracker;this._imagesTracker=t.imagesTracker;this._operationsFilter=p;this._renderingBudget=m;this._renderingScheduler=h}get completed(){return this.capability.promise.catch(function(){})}initializeGraphics({transparency:e=!1,optionalContentConfig:t}){if(this.cancelled)return;if(this._canvas){if(nr.#n.has(this._canvas))throw Error(`Cannot use the same canvas during multiple render() operations. Use different canvas or ensure previous operations were cancelled or completed.`);nr.#n.add(this._canvas)}if(this._pdfBug&&globalThis.StepperManager?.enabled){this.stepper=globalThis.StepperManager.create(this._pageIndex);this.stepper.init(this.operatorList);this.stepper.nextBreakPoint=this.stepper.getNextBreakPoint()}let{viewport:n,transform:r,background:i,dependencyTracker:a,imagesTracker:o}=this.params,s=this._canvasContext||this._canvas.getContext(`2d`,{alpha:!1,willReadFrequently:!this._enableHWA});this.gfx=new fn(s,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:t},this.annotationCanvasMap,this.pageColors,a,o);this.gfx.beginDrawing({transform:r,viewport:n,transparency:e,background:i});this.operatorListIdx=0;this.graphicsReady=!0;this.graphicsReadyCallback?.()}cancel(e=null,t=0){this.running=!1;this.cancelled=!0;this.gfx?.endDrawing();this._cancelScheduledContinue();nr.#n.delete(this._canvas);e||=new ve(`Rendering cancelled, page ${this._pageIndex+1}`,t);this.callback(e);this.task.onError?.(e)}_cancelScheduledContinue(){if(this.#e){window.cancelAnimationFrame(this.#e);this.#e=null}this.#t?.();this.#t=null}operatorListChanged(){if(this.graphicsReady){this.gfx.dependencyTracker?.growOperationsCount(this.operatorList.fnArray.length);this.stepper?.updateOperatorList(this.operatorList);this.running||this._continue()}else this.graphicsReadyCallback||=this._continueBound}_continue(){this.running=!0;this.cancelled||(this.task.onContinue?this.task.onContinue(this._scheduleNextBound):this._scheduleNext())}_scheduleNext(){let e=e=>{this.#e=null;this.#t=null;this._nextBound(e||null).catch(this._cancelBound)};this._renderingScheduler?.scheduleContinue?this.#t=this._renderingScheduler.scheduleContinue(e)||null:this._useRequestAnimationFrame?this.#e=window.requestAnimationFrame(()=>{e(null)}):Promise.resolve().then(()=>e(null)).catch(this._cancelBound)}async _next(e=null){if(!this.cancelled){this.operatorListIdx=this.gfx.executeOperatorList(this.operatorList,this.operatorListIdx,this._continueBound,this.stepper,this._operationsFilter,this._renderingBudget,e);if(this.operatorListIdx===this.operatorList.argsArray.length){this.running=!1;if(this.operatorList.lastChunk){this.gfx.endDrawing();nr.#n.delete(this._canvas);this.callback()}}}}}class J{#e=null;#t=null;#n;#r=null;#i=!1;#a=!1;#o=null;#s;#c=null;#l=null;static#u=null;static get _keyboardManager(){return j(this,`_keyboardManager`,new ze([[[`Escape`,`mac+Escape`],J.prototype._hideDropdownFromKeyboard],[[` `,`mac+ `],J.prototype._colorSelectFromKeyboard],[[`ArrowDown`,`ArrowRight`,`mac+ArrowDown`,`mac+ArrowRight`],J.prototype._moveToNext],[[`ArrowUp`,`ArrowLeft`,`mac+ArrowUp`,`mac+ArrowLeft`],J.prototype._moveToPrevious],[[`Home`,`mac+Home`],J.prototype._moveToBeginning],[[`End`,`mac+End`],J.prototype._moveToEnd]]))}constructor({editor:e=null,uiManager:t=null}){if(e){this.#a=!1;this.#o=e}else this.#a=!0;this.#l=e?._uiManager||t;this.#s=this.#l._eventBus;this.#n=e?.color?.toUpperCase()||this.#l?.highlightColors.values().next().value||`#FFFF98`;J.#u||=Object.freeze({blue:`pdfjs-editor-colorpicker-blue`,green:`pdfjs-editor-colorpicker-green`,pink:`pdfjs-editor-colorpicker-pink`,red:`pdfjs-editor-colorpicker-red`,yellow:`pdfjs-editor-colorpicker-yellow`})}renderButton(){let e=this.#e=document.createElement(`button`);e.className=`colorPicker`;e.tabIndex=`0`;e.setAttribute(`data-l10n-id`,`pdfjs-editor-colorpicker-button`);e.ariaHasPopup=`true`;this.#o&&(e.ariaControls=`${this.#o.id}_colorpicker_dropdown`);let t=this.#l._signal;e.addEventListener(`click`,this.#m.bind(this),{signal:t});e.addEventListener(`keydown`,this.#p.bind(this),{signal:t});let n=this.#t=document.createElement(`span`);n.className=`swatch`;n.ariaHidden=`true`;n.style.backgroundColor=this.#n;e.append(n);return e}renderMainDropdown(){let e=this.#r=this.#d();e.ariaOrientation=`horizontal`;e.ariaLabelledBy=`highlightColorPickerLabel`;return e}#d(){let e=document.createElement(`div`),t=this.#l._signal;e.addEventListener(`contextmenu`,L,{signal:t});e.className=`dropdown`;e.role=`listbox`;e.ariaMultiSelectable=`false`;e.ariaOrientation=`vertical`;e.setAttribute(`data-l10n-id`,`pdfjs-editor-colorpicker-dropdown`);this.#o&&(e.id=`${this.#o.id}_colorpicker_dropdown`);for(let[n,r]of this.#l.highlightColors){let i=document.createElement(`button`);i.tabIndex=`0`;i.role=`option`;i.setAttribute(`data-color`,r);i.title=n;i.setAttribute(`data-l10n-id`,J.#u[n]);let a=document.createElement(`span`);i.append(a);a.className=`swatch`;a.style.backgroundColor=r;i.ariaSelected=r===this.#n;i.addEventListener(`click`,this.#f.bind(this,r),{signal:t});e.append(i)}e.addEventListener(`keydown`,this.#p.bind(this),{signal:t});return e}#f(e,t){t.stopPropagation();this.#s.dispatch(`switchannotationeditorparams`,{source:this,type:b.HIGHLIGHT_COLOR,value:e});this.updateColor(e)}_colorSelectFromKeyboard(e){if(e.target===this.#e){this.#m(e);return}let t=e.target.getAttribute(`data-color`);t&&this.#f(t,e)}_moveToNext(e){this.#g?e.target===this.#e?this.#r.firstElementChild?.focus():e.target.nextSibling?.focus():this.#m(e)}_moveToPrevious(e){if(e.target!==this.#r?.firstElementChild&&e.target!==this.#e){this.#g||this.#m(e);e.target.previousSibling?.focus()}else this.#g&&this._hideDropdownFromKeyboard()}_moveToBeginning(e){this.#g?this.#r.firstElementChild?.focus():this.#m(e)}_moveToEnd(e){this.#g?this.#r.lastElementChild?.focus():this.#m(e)}#p(e){J._keyboardManager.exec(this,e)}#m(e){if(this.#g){this.hideDropdown();return}this.#i=e.detail===0;if(!this.#c){this.#c=new AbortController;window.addEventListener(`pointerdown`,this.#h.bind(this),{signal:this.#l.combinedSignal(this.#c)})}this.#e.ariaExpanded=`true`;if(this.#r){this.#r.classList.remove(`hidden`);return}let t=this.#r=this.#d();this.#e.append(t)}#h(e){this.#r?.contains(e.target)||this.hideDropdown()}hideDropdown(){this.#r?.classList.add(`hidden`);this.#e.ariaExpanded=`false`;this.#c?.abort();this.#c=null}get#g(){return this.#r&&!this.#r.classList.contains(`hidden`)}_hideDropdownFromKeyboard(){if(!this.#a){if(this.#g){this.hideDropdown();this.#e.focus({preventScroll:!0,focusVisible:this.#i})}else this.#o?.unselect()}}updateColor(e){this.#t&&(this.#t.style.backgroundColor=e);if(!this.#r)return;let t=this.#l.highlightColors.values();for(let n of this.#r.children)n.ariaSelected=t.next().value===e.toUpperCase()}destroy(){this.#e?.remove();this.#e=null;this.#t=null;this.#r?.remove();this.#r=null}}class rr{#e=null;#t=!1;#n=null;#r=null;static#i=null;constructor(e){this.#n=e;this.#r=e._uiManager;rr.#i||=Object.freeze({freetext:`pdfjs-editor-color-picker-free-text-input`,ink:`pdfjs-editor-color-picker-ink-input`})}renderButton(){if(this.#e)return this.#e;let{editorType:e,colorType:t,colorAndOpacityType:n,opacityType:r,color:i,opacity:a}=this.#n,o=this.#t=N.isAlphaColorInputSupported&&r!==void 0,s=this.#e=document.createElement(`input`);s.type=`color`;if(o){s.setAttribute(`alpha`,``);let e=P.hexNums[Math.round(255*(a??1))];s.value=(i||`#000000`)+e}else s.value=i||`#000000`;s.className=`basicColorPicker`;s.tabIndex=0;s.setAttribute(`data-l10n-id`,rr.#i[e]);s.addEventListener(`input`,()=>{if(o){let e=we(s.value);if(!e)return;let[i,a,o,c]=e,l=P.makeHexColor(i,a,o);if(n!==void 0)this.#r.updateParams(n,{color:l,opacity:c});else{this.#r.updateParams(t,l);this.#r.updateParams(r,c)}}else this.#r.updateParams(t,s.value)},{signal:this.#r._signal});return s}update(e){if(this.#e){if(this.#t){let t=P.hexNums[Math.round(255*this.#n.opacity)];this.#e.value=e+t}else this.#e.value=e}}updateOpacity(e){if(!this.#e||!this.#t)return;let t=P.hexNums[Math.round(255*e)];this.#e.value=this.#n.color+t}destroy(){this.#e?.remove();this.#e=null}hideDropdown(){}}function ir(e){return Math.floor(255*F(e,0,1)).toString(16).padStart(2,`0`)}function ar(e){return 255*F(e,0,1)}class or{static CMYK_G([e,t,n,r]){return[`G`,1-Math.min(1,.3*e+.59*n+.11*t+r)]}static G_CMYK([e]){return[`CMYK`,0,0,0,1-e]}static G_RGB([e]){return[`RGB`,e,e,e]}static G_rgb([e]){return[e=ar(e),e,e]}static G_HTML([e]){let t=ir(e);return`#${t}${t}${t}`}static RGB_G([e,t,n]){return[`G`,.3*e+.59*t+.11*n]}static RGB_rgb(e){return e.map(ar)}static RGB_HTML(e){return`#${e.map(ir).join(``)}`}static T_HTML(){return`#00000000`}static T_rgb(){return[null]}static CMYK_RGB([e,t,n,r]){return[`RGB`,1-Math.min(1,e+r),1-Math.min(1,n+r),1-Math.min(1,t+r)]}static CMYK_rgb([e,t,n,r]){return[ar(1-Math.min(1,e+r)),ar(1-Math.min(1,n+r)),ar(1-Math.min(1,t+r))]}static CMYK_HTML(e){let t=this.CMYK_RGB(e).slice(1);return this.RGB_HTML(t)}static RGB_CMYK([e,t,n]){let r=1-e,i=1-t,a=1-n;return[`CMYK`,r,i,a,Math.min(r,i,a)]}}const sr=new WeakSet;60*new Date().getTimezoneOffset()*1e3;class Y{#e=null;#t=!1;#n=null;constructor(e,{isRenderable:t=!1,ignoreBorder:n=!1,createQuadrilaterals:r=!1}={}){this.isRenderable=t;this.data=e.data;this.layer=e.layer;this.linkService=e.linkService;this.downloadManager=e.downloadManager;this.imageResourcesPath=e.imageResourcesPath;this.renderForms=e.renderForms;this.svgFactory=e.svgFactory;this.annotationStorage=e.annotationStorage;this.enableComment=e.enableComment;this.enableScripting=e.enableScripting;this.hasJSActions=e.hasJSActions;this._fieldObjects=e.fieldObjects;this.parent=e.parent;this.hasOwnCommentButton=!1;t&&(this.contentElement=this.container=this._createContainer(n));r&&this._createQuadrilaterals()}static _hasPopupData({contentsObj:e,richText:t}){return!(!e?.str&&!t?.str)}get _isEditable(){return this.data.isEditable}get hasPopupData(){return Y._hasPopupData(this.data)||this.enableComment&&!!this.commentText}get commentData(){let{data:e}=this,t=this.annotationStorage?.getEditor(e.id);return t?t.getData():e}get hasCommentButton(){return this.enableComment&&this.hasPopupElement}get commentButtonPosition(){let e=this.annotationStorage?.getEditor(this.data.id);if(e)return e.commentButtonPositionInPage;let{quadPoints:t,inkLists:n,rect:r}=this.data,i=-1/0,a=-1/0;if(t?.length>=8){for(let e=0;e<t.length;e+=8)if(t[e+1]>a){a=t[e+1];i=t[e+2]}else t[e+1]===a&&(i=Math.max(i,t[e+2]));return[i,a]}if(n?.length>=1){for(let e of n)for(let t=0,n=e.length;t<n;t+=2)if(e[t+1]>a){a=e[t+1];i=e[t]}else e[t+1]===a&&(i=Math.max(i,e[t]));if(i!==1/0)return[i,a]}return r?[r[2],r[3]]:null}_normalizePoint(e){let{page:{view:t},viewport:{rawDims:{pageWidth:n,pageHeight:r,pageX:i,pageY:a}}}=this.parent;e[1]=t[3]-e[1]+t[1];e[0]=100*(e[0]-i)/n;e[1]=100*(e[1]-a)/r;return e}get commentText(){let{data:e}=this;return this.annotationStorage.getRawValue(`${v}${e.id}`)?.popup?.contents||e.contentsObj?.str||``}set commentText(e){let{data:t}=this,n={deleted:!e,contents:e||``};this.annotationStorage.updateEditor(t.id,{popup:n})||this.annotationStorage.setValue(`${v}${t.id}`,{id:t.id,annotationType:t.annotationType,page:this.parent.page,popup:n,popupRef:t.popupRef,modificationDate:new Date});e||this.removePopup()}removePopup(){(this.#n?.popup||this.popup)?.remove();this.#n=this.popup=null}updateEdited(e){if(!this.container)return;e.rect&&(this.#e||={rect:this.data.rect.slice(0)});let{rect:t,popup:n}=e;t&&this.#r(t);let r=this.#n?.popup||this.popup;if(!r&&n?.text){this._createPopup(n);r=this.#n.popup}if(r){r.updateEdited(e);if(n?.deleted){r.remove();this.#n=null;this.popup=null}}}resetEdited(){if(this.#e){this.#r(this.#e.rect);this.#n?.popup.resetEdited();this.#e=null}}#r(e){let{container:{style:t},data:{rect:n,rotation:r},parent:{viewport:{rawDims:{pageWidth:i,pageHeight:a,pageX:o,pageY:s}}}}=this;n?.splice(0,4,...e);t.left=100*(e[0]-o)/i+`%`;t.top=100*(a-e[3]+s)/a+`%`;if(r===0){t.width=100*(e[2]-e[0])/i+`%`;t.height=100*(e[3]-e[1])/a+`%`}else this.setRotation(r)}_createContainer(e){let{data:t,parent:{page:n,viewport:r}}=this,i=document.createElement(`section`);i.setAttribute(`data-annotation-id`,t.id);this instanceof lr||this instanceof cr||(i.tabIndex=0);let{style:a}=i;a.zIndex=this.parent.zIndex;this.parent.zIndex+=2;t.alternativeText&&(i.title=t.alternativeText);t.noRotate&&i.classList.add(`norotate`);if(!t.rect||this instanceof dr){let{rotation:e}=t;t.hasOwnCanvas||e===0||this.setRotation(e,i);return i}let{width:o,height:s}=this;if(!e&&t.borderStyle.width>0){a.borderWidth=`${t.borderStyle.width}px`;let e=t.borderStyle.horizontalCornerRadius,n=t.borderStyle.verticalCornerRadius;e>0||n>0?a.borderRadius=`calc(${e}px * var(--total-scale-factor)) / calc(${n}px * var(--total-scale-factor))`:this instanceof ur&&(a.borderRadius=`calc(${o}px * var(--total-scale-factor)) / calc(${s}px * var(--total-scale-factor))`);switch(t.borderStyle.style){case 1:a.borderStyle=`solid`;break;case 2:a.borderStyle=`dashed`;break;case 3:O(`Unimplemented border style: beveled`);break;case 4:O(`Unimplemented border style: inset`);break;case 5:a.borderBottomStyle=`solid`}let r=t.borderColor||null;if(r){this.#t=!0;a.borderColor=P.makeHexColor(...r)}else a.borderWidth=0}let c=P.normalizeRect([t.rect[0],n.view[3]-t.rect[1]+n.view[1],t.rect[2],n.view[3]-t.rect[3]+n.view[1]]),{pageWidth:l,pageHeight:u,pageX:d,pageY:f}=r.rawDims;a.left=100*(c[0]-d)/l+`%`;a.top=100*(c[1]-f)/u+`%`;let{rotation:p}=t;if(t.hasOwnCanvas||p===0){a.width=100*o/l+`%`;a.height=100*s/u+`%`}else this.setRotation(p,i);return i}setRotation(e,t=this.container){if(!this.data.rect)return;let{pageWidth:n,pageHeight:r}=this.parent.viewport.rawDims,{width:i,height:a}=this;e%180!=0&&([i,a]=[a,i]);t.style.width=100*i/n+`%`;t.style.height=100*a/r+`%`;t.setAttribute(`data-main-rotation`,(360-e)%360)}get _commonActions(){let e=(e,t,n)=>{let r=n.detail[e],i=r[0],a=r.slice(1);n.target.style[t]=or[`${i}_HTML`](a);this.annotationStorage.setValue(this.data.id,{[t]:or[`${i}_rgb`](a)})};return j(this,`_commonActions`,{display:e=>{let{display:t}=e.detail,n=t%2==1;this.container.style.visibility=n?`hidden`:`visible`;this.annotationStorage.setValue(this.data.id,{noView:n,noPrint:t===1||t===2})},print:e=>{this.annotationStorage.setValue(this.data.id,{noPrint:!e.detail.print})},hidden:e=>{let{hidden:t}=e.detail;this.container.style.visibility=t?`hidden`:`visible`;this.annotationStorage.setValue(this.data.id,{noPrint:t,noView:t})},focus:e=>{setTimeout(()=>e.target.focus({preventScroll:!1}),0)},userName:e=>{e.target.title=e.detail.userName},readonly:e=>{e.target.disabled=e.detail.readonly},required:e=>{this._setRequired(e.target,e.detail.required)},bgColor:t=>{e(`bgColor`,`backgroundColor`,t)},fillColor:t=>{e(`fillColor`,`backgroundColor`,t)},fgColor:t=>{e(`fgColor`,`color`,t)},textColor:t=>{e(`textColor`,`color`,t)},borderColor:t=>{e(`borderColor`,`borderColor`,t)},strokeColor:t=>{e(`strokeColor`,`borderColor`,t)},rotation:e=>{let t=e.detail.rotation;this.setRotation(t);this.annotationStorage.setValue(this.data.id,{rotation:t})}})}_dispatchEventFromSandbox(e,t){let n=this._commonActions;for(let r of Object.keys(t.detail))(e[r]||n[r])?.(t)}_setDefaultPropertiesFromJS(e){if(!this.enableScripting)return;let t=this.annotationStorage.getRawValue(this.data.id);if(!t)return;let n=this._commonActions;for(let[r,i]of Object.entries(t)){let a=n[r];if(a){a({detail:{[r]:i},target:e});delete t[r]}}}_createQuadrilaterals(){if(!this.container)return;let{quadPoints:e}=this.data;if(!e)return;let[t,n,r,i]=this.data.rect.map(e=>Math.fround(e));if(e.length===8){let[a,o,s,c]=e.subarray(2,6);if(r===a&&i===o&&t===s&&n===c)return}let{style:a}=this.container,o;if(this.#t){let{borderColor:e,borderWidth:t}=a;a.borderWidth=0;o=[`url('data:image/svg+xml;utf8,`,`<svg xmlns="http://www.w3.org/2000/svg"`,` preserveAspectRatio="none" viewBox="0 0 1 1">`,`<g fill="transparent" stroke="${e}" stroke-width="${t}">`];this.container.classList.add(`hasBorder`)}let s=r-t,c=i-n,{svgFactory:l}=this,u=l.createElement(`svg`);u.classList.add(`quadrilateralsContainer`);u.setAttribute(`width`,0);u.setAttribute(`height`,0);u.role=`none`;let d=l.createElement(`defs`);u.append(d);let f=l.createElement(`clipPath`),p=`clippath_${this.data.id}`;f.setAttribute(`id`,p);f.setAttribute(`clipPathUnits`,`objectBoundingBox`);d.append(f);for(let n=2,r=e.length;n<r;n+=8){let r=e[n],a=e[n+1],u=e[n+2],d=e[n+3],p=l.createElement(`rect`),m=(u-t)/s,h=(i-a)/c,g=(r-u)/s,_=(a-d)/c;p.setAttribute(`x`,m);p.setAttribute(`y`,h);p.setAttribute(`width`,g);p.setAttribute(`height`,_);f.append(p);o?.push(`<rect vector-effect="non-scaling-stroke" x="${m}" y="${h}" width="${g}" height="${_}"/>`)}if(this.#t){o.push(`</g></svg>')`);a.backgroundImage=o.join(``)}this.container.append(u);this.container.style.clipPath=`url(#${p})`}_createPopup(e=null){let{data:t}=this,n,r;if(e){n={str:e.text};r=e.date}else{n=t.contentsObj;r=t.modificationDate}this.#n=new dr({data:{color:t.color,titleObj:t.titleObj,modificationDate:r,contentsObj:n,richText:t.richText,parentRect:t.rect,borderStyle:0,id:`popup_${t.id}`,rotation:t.rotation,noRotate:!0},linkService:this.linkService,parent:this.parent,elements:[this]})}get hasPopupElement(){return!!(this.#n||this.popup||this.data.popupRef)}get extraPopupElement(){return this.#n}render(){k("Abstract method `AnnotationElement.render` called")}_getElementsByName(e,t=null){let n=[];if(this._fieldObjects){let r=this._fieldObjects[e];if(r)for(let{page:e,id:i,exportValues:a}of r){if(e===-1)continue;if(i===t)continue;let r=typeof a==`string`?a:null,o=document.querySelector(`[data-element-id="${i}"]`);!o||sr.has(o)?n.push({id:i,exportValue:r,domElement:o}):O(`_getElementsByName - element not allowed: ${i}`)}return n}for(let r of document.getElementsByName(e)){let{exportValue:e}=r,i=r.getAttribute(`data-element-id`);i!==t&&sr.has(r)&&n.push({id:i,exportValue:e,domElement:r})}return n}show(){this.container&&(this.container.hidden=!1);this.popup?.maybeShow()}hide(){this.container&&(this.container.hidden=!0);this.popup?.forceHide()}getElementsToTriggerPopup(){return this.container}addHighlightArea(){let e=this.getElementsToTriggerPopup();if(Array.isArray(e))for(let t of e)t.classList.add(`highlightArea`);else e.classList.add(`highlightArea`)}_editOnDoubleClick(){if(!this._isEditable)return;let{annotationEditorType:e,data:{id:t}}=this;this.container.addEventListener(`dblclick`,()=>{this.linkService.eventBus?.dispatch(`switchannotationeditormode`,{source:this,mode:e,editId:t,mustEnterInEditMode:!0})})}get width(){return this.data.rect[2]-this.data.rect[0]}get height(){return this.data.rect[3]-this.data.rect[1]}}class cr extends Y{constructor(e,t=null){super(e,{isRenderable:!0,ignoreBorder:!!t?.ignoreBorder,createQuadrilaterals:!0});this.isTooltipOnly=e.data.isTooltipOnly}render(){let{data:e,linkService:t}=this,n=document.createElement(`a`);n.setAttribute(`data-element-id`,e.id);let r=!1;if(e.url){t.addLinkAttributes(n,e.url,e.newWindow);r=!0}else if(e.action){this._bindNamedAction(n,e.action,e.overlaidText);r=!0}else if(e.attachment){this.#t(n,e.attachment,e.overlaidText,e.attachmentDest);r=!0}else if(e.setOCGState){this.#n(n,e.setOCGState,e.overlaidText);r=!0}else if(e.dest){this._bindLink(n,e.dest,e.overlaidText);r=!0}else{if(e.actions&&(e.actions.Action||e.actions[`Mouse Up`]||e.actions[`Mouse Down`])&&this.enableScripting&&this.hasJSActions){this._bindJSAction(n,e);r=!0}if(e.resetForm){this._bindResetFormAction(n,e.resetForm);r=!0}else if(this.isTooltipOnly&&!r){this._bindLink(n,``);r=!0}}this.container.classList.add(`linkAnnotation`);if(r){this.contentElement=n;this.container.append(n)}return this.container}#e(){this.container.setAttribute(`data-internal-link`,``)}_bindLink(e,t,n=``){e.href=this.linkService.getDestinationHash(t);e.onclick=()=>{t&&this.linkService.goToDestination(t);return!1};(t||t===``)&&this.#e();n&&(e.title=n)}_bindNamedAction(e,t,n=``){e.href=this.linkService.getAnchorUrl(``);e.onclick=()=>{this.linkService.executeNamedAction(t);return!1};n&&(e.title=n);this.#e()}#t(e,t,n=``,r=null){e.href=this.linkService.getAnchorUrl(``);t.description?e.title=t.description:n&&(e.title=n);e.onclick=()=>{this.downloadManager?.openOrDownloadData(t.content,t.filename,r);return!1};this.#e()}#n(e,t,n=``){e.href=this.linkService.getAnchorUrl(``);e.onclick=()=>{this.linkService.executeSetOCGState(t);return!1};n&&(e.title=n);this.#e()}_bindJSAction(e,t){e.href=this.linkService.getAnchorUrl(``);let n=new Map([[`Action`,`onclick`],[`Mouse Up`,`onmouseup`],[`Mouse Down`,`onmousedown`]]);for(let r of Object.keys(t.actions)){let i=n.get(r);i&&(e[i]=()=>{this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:t.id,name:r}});return!1})}t.overlaidText&&(e.title=t.overlaidText);e.onclick||=()=>!1;this.#e()}_bindResetFormAction(e,t){let n=e.onclick;n||(e.href=this.linkService.getAnchorUrl(``));this.#e();if(this._fieldObjects)e.onclick=()=>{n?.();let{fields:e,refs:r,include:i}=t,a=[];if(e.length!==0||r.length!==0){let t=new Set(r);for(let n of e){let e=this._fieldObjects[n]||[];for(let{id:n}of e)t.add(n)}for(let e of Object.values(this._fieldObjects))for(let n of e)t.has(n.id)===i&&a.push(n)}else for(let e of Object.values(this._fieldObjects))a.push(...e);let o=this.annotationStorage,s=[];for(let e of a){let{id:t}=e;s.push(t);switch(e.type){case`text`:{let n=e.defaultValue||``;o.setValue(t,{value:n});break}case`checkbox`:case`radiobutton`:{let n=e.defaultValue===e.exportValues;o.setValue(t,{value:n});break}case`combobox`:case`listbox`:{let n=e.defaultValue||``;o.setValue(t,{value:n});break}default:continue}let n=document.querySelector(`[data-element-id="${t}"]`);n&&(sr.has(n)?n.dispatchEvent(new Event(`resetform`)):O(`_bindResetFormAction - element not allowed: ${t}`))}this.enableScripting&&this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:`app`,ids:s,name:`ResetForm`}});return!1};else{O('_bindResetFormAction - "resetForm" action not supported, ensure that the `fieldObjects` parameter is provided.');n||(e.onclick=()=>!1)}}}class lr extends Y{render(){return this.container}showElementAndHideCanvas(e){if(this.data.hasOwnCanvas){e.previousSibling?.nodeName===`CANVAS`&&(e.previousSibling.hidden=!0);e.hidden=!1}}_getKeyModifier(e){return N.platform.isMac?e.metaKey:e.ctrlKey}_setEventListener(e,t,n,r,i){n.includes(`mouse`)?e.addEventListener(n,e=>{this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:this.data.id,name:r,value:i(e),shift:e.shiftKey,modifier:this._getKeyModifier(e)}})}):e.addEventListener(n,e=>{if(n===`blur`){if(!t.focused||!e.relatedTarget)return;t.focused=!1}else if(n===`focus`){if(t.focused)return;t.focused=!0}i&&this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:this.data.id,name:r,value:i(e)}})})}_setEventListeners(e,t,n,r){for(let[i,a]of n)if(a===`Action`||this.data.actions?.[a]){a!==`Focus`&&a!==`Blur`||(t||={focused:!1});this._setEventListener(e,t,i,a,r);a!==`Focus`||this.data.actions?.Blur?a!==`Blur`||this.data.actions?.Focus||this._setEventListener(e,t,`focus`,`Focus`,null):this._setEventListener(e,t,`blur`,`Blur`,null)}}_setBackgroundColor(e){let t=this.data.backgroundColor||null;e.style.backgroundColor=t===null?`transparent`:P.makeHexColor(...t)}_setTextStyle(e){let t=[`left`,`center`,`right`],{fontColor:n}=this.data.defaultAppearanceData,r=this.data.defaultAppearanceData.fontSize||9,i=e.style,a,o=e=>Math.round(10*e)/10;if(this.data.multiLine){let e=Math.abs(this.data.rect[3]-this.data.rect[1]-2),t=e/(Math.round(e/(h*r))||1);a=Math.min(r,o(t/h))}else{let e=Math.abs(this.data.rect[3]-this.data.rect[1]-2);a=Math.min(r,o(e/h))}i.fontSize=`calc(${a}px * var(--total-scale-factor))`;i.color=P.makeHexColor(...n);this.data.textAlignment!==null&&(i.textAlign=t[this.data.textAlignment])}_setRequired(e,t){t?e.setAttribute(`required`,!0):e.removeAttribute(`required`);e.setAttribute(`aria-required`,t)}}class ur extends lr{constructor(e){super(e,{isRenderable:e.renderForms})}render(){this.container.classList.add(`buttonWidgetAnnotation`,`radioButton`);let e=this.annotationStorage,t=this.data,n=t.id,r=e.getValue(n,{value:t.fieldValue===t.buttonValue}).value;if(typeof r==`string`){r=r!==t.buttonValue;e.setValue(n,{value:r})}if(r)for(let r of this._getElementsByName(t.fieldName,n))e.setValue(r.id,{value:!1});let i=document.createElement(`input`);sr.add(i);i.setAttribute(`data-element-id`,n);i.disabled=t.readOnly;this._setRequired(i,this.data.required);i.type=`radio`;i.name=t.fieldName;r&&i.setAttribute(`checked`,!0);i.tabIndex=0;i.addEventListener(`change`,t=>{let{name:r,checked:i}=t.target;for(let t of this._getElementsByName(r,n))e.setValue(t.id,{value:!1});e.setValue(n,{value:i})});i.addEventListener(`resetform`,e=>{let n=t.defaultFieldValue;e.target.checked=n!=null&&n===t.buttonValue});if(this.enableScripting&&this.hasJSActions){let r=t.buttonValue;i.addEventListener(`updatefromsandbox`,t=>{this._dispatchEventFromSandbox({value:t=>{let i=r===t.detail.value;for(let r of this._getElementsByName(t.target.name)){let t=i&&r.id===n;r.domElement&&(r.domElement.checked=t);e.setValue(r.id,{value:t})}}},t)});this._setEventListeners(i,null,[[`change`,`Validate`],[`change`,`Action`],[`focus`,`Focus`],[`blur`,`Blur`],[`mousedown`,`Mouse Down`],[`mouseenter`,`Mouse Enter`],[`mouseleave`,`Mouse Exit`],[`mouseup`,`Mouse Up`]],e=>e.target.checked)}this._setBackgroundColor(i);this._setDefaultPropertiesFromJS(i);this.container.append(i);return this.container}}class dr extends Y{constructor(e){let{data:t,elements:n,parent:r}=e,i=!!r._commentManager;super(e,{isRenderable:!i&&Y._hasPopupData(t)});this.elements=n;if(i&&Y._hasPopupData(t)){let e=this.popup=this.#e();for(let t of n)t.popup=e}else this.popup=null}#e(){return new fr({container:this.container,color:this.data.color,titleObj:this.data.titleObj,modificationDate:this.data.modificationDate||this.data.creationDate,contentsObj:this.data.contentsObj,richText:this.data.richText,rect:this.data.rect,parentRect:this.data.parentRect||null,parent:this.parent,elements:this.elements,open:this.data.open,commentManager:this.parent._commentManager})}render(){let{container:e}=this;e.classList.add(`popupAnnotation`);e.role=`comment`;let t=this.popup=this.#e(),n=[];for(let e of this.elements){e.popup=t;e.container.ariaHasPopup=`dialog`;n.push(e.data.id);e.addHighlightArea()}this.container.setAttribute(`aria-controls`,n.map(e=>`${_}${e}`).join(`,`));return this.container}}class fr{#e=null;#t=this.#P.bind(this);#n=this.#R.bind(this);#r=this.#L.bind(this);#i=this.#I.bind(this);#a=null;#o=null;#s=null;#c=null;#l=null;#u=null;#d=null;#f=!1;#p=null;#m=null;#h=null;#g=null;#_=null;#v=null;#y=null;#b=null;#x=null;#S=null;#C=!1;#w=null;#T=null;constructor({container:e,color:t,elements:n,titleObj:r,modificationDate:i,contentsObj:a,richText:o,parent:s,rect:c,parentRect:l,open:u,commentManager:d=null}){this.#o=e;this.#x=r;this.#s=a;this.#b=o;this.#u=s;this.#a=t;this.#y=c;this.#d=l;this.#l=n;this.#e=d;this.#w=n[0];this.#c=Ce.toDateObject(i);this.trigger=n.flatMap(e=>e.getElementsToTriggerPopup());if(!d){this.#E();this.#o.hidden=!0;u&&this.#I()}}#E(){if(this.#m)return;this.#m=new AbortController;let{signal:e}=this.#m;for(let t of this.trigger){t.addEventListener(`click`,this.#i,{signal:e});t.addEventListener(`pointerenter`,this.#r,{signal:e});t.addEventListener(`pointerleave`,this.#n,{signal:e});t.classList.add(`popupTriggerArea`)}for(let t of this.#l)t.container?.addEventListener(`keydown`,this.#t,{signal:e})}#D(){let e=this.#l.find(e=>e.hasCommentButton);e&&(this.#_=e._normalizePoint(e.commentButtonPosition))}renderCommentButton(){if(this.#g){this.#g.parentNode||this.#w.container.after(this.#g);return}this.#_||this.#D();if(!this.#_)return;let{signal:e}=this.#m=new AbortController,t=this.#w.hasOwnCommentButton,n=()=>{this.#e.toggleCommentPopup(this,!0,void 0,!t)},r=()=>{this.#e.toggleCommentPopup(this,!1,!0,!t)},i=()=>{this.#e.toggleCommentPopup(this,!1,!1)};if(t){this.#g=this.#w.container;for(let t of this.trigger){t.ariaHasPopup=`dialog`;t.ariaControls=`commentPopup`;t.addEventListener(`keydown`,this.#t,{signal:e});t.addEventListener(`click`,n,{signal:e});t.addEventListener(`pointerenter`,r,{signal:e});t.addEventListener(`pointerleave`,i,{signal:e});t.classList.add(`popupTriggerArea`)}}else{let t=this.#g=document.createElement(`button`);t.className=`annotationCommentButton`;let a=this.#w.container;t.style.zIndex=parseInt(a.style.zIndex,10)+1;t.tabIndex=0;t.ariaHasPopup=`dialog`;t.ariaControls=`commentPopup`;t.setAttribute(`data-l10n-id`,`pdfjs-show-comment-button`);this.#k();this.#O();t.addEventListener(`keydown`,this.#t,{signal:e});t.addEventListener(`click`,n,{signal:e});t.addEventListener(`pointerenter`,r,{signal:e});t.addEventListener(`pointerleave`,i,{signal:e});a.after(t)}}#O(){if(this.#w.extraPopupElement&&!this.#w.editor)return;this.#g||this.renderCommentButton();let[e,t]=this.#_,{style:n}=this.#g;n.left=`calc(${e}%)`;n.top=`calc(${t}% - var(--comment-button-dim))`}#k(){if(!this.#w.extraPopupElement){this.#g||this.renderCommentButton();this.#g.style.backgroundColor=this.commentButtonColor||``}}get commentButtonColor(){let{color:e,opacity:t}=this.#w.commentData;return e?this.#u._commentManager.makeCommentColor(e,t):null}focusCommentButton(){setTimeout(()=>{this.#g?.focus()},0)}getData(){let{richText:e,color:t,opacity:n,creationDate:r,modificationDate:i}=this.#w.commentData;return{contentsObj:{str:this.comment},richText:e,color:t,opacity:n,creationDate:r,modificationDate:i}}get elementBeforePopup(){return this.#g}get comment(){this.#T||=this.#w.commentText;return this.#T}set comment(e){e!==this.comment&&(this.#w.commentText=this.#T=e)}focus(){this.#w.container?.focus()}get parentBoundingClientRect(){return this.#w.layer.getBoundingClientRect()}setCommentButtonStates({selected:e,hasPopup:t}){if(this.#g){this.#g.classList.toggle(`selected`,e);this.#g.ariaExpanded=t}}setSelectedCommentButton(e){this.#g.classList.toggle(`selected`,e)}get commentPopupPosition(){if(this.#v)return this.#v;let{x:e,y:t,height:n}=this.#g.getBoundingClientRect(),{x:r,y:i,width:a,height:o}=this.#w.layer.getBoundingClientRect();return[(e-r)/a,(t+n-i)/o]}set commentPopupPosition(e){this.#v=e}hasDefaultPopupPosition(){return this.#v===null}get commentButtonPosition(){return this.#_}get commentButtonWidth(){return this.#g.getBoundingClientRect().width/this.parentBoundingClientRect.width}editComment(e){let[t,n]=this.#v||this.commentButtonPosition.map(e=>e/100),r=this.parentBoundingClientRect,{x:i,y:a,width:o,height:s}=r;this.#e.showDialog(null,this,i+t*o,a+n*s,{...e,parentDimensions:r})}render(){if(this.#p)return;let e=this.#p=document.createElement(`div`);e.className=`popup`;if(this.#a){let t=e.style.outlineColor=P.makeHexColor(...this.#a);e.style.backgroundColor=`color-mix(in srgb, ${t} 30%, white)`}let t=document.createElement(`span`);t.className=`header`;if(this.#x?.str){let e=document.createElement(`span`);e.className=`title`;t.append(e);({dir:e.dir,str:e.textContent}=this.#x)}e.append(t);if(this.#c){let e=document.createElement(`time`);e.className=`popupDate`;e.setAttribute(`data-l10n-id`,`pdfjs-annotation-date-time-string`);e.setAttribute(`data-l10n-args`,JSON.stringify({dateObj:this.#c.valueOf()}));e.dateTime=this.#c.toISOString();t.append(e)}je({html:this.#A||this.#s.str,dir:this.#s?.dir,className:`popupContent`},e);this.#o.append(e)}get#A(){let e=this.#b,t=this.#s;return!e?.str||t?.str&&t.str!==e.str?null:this.#b.html||null}get#j(){return this.#A?.attributes?.style?.fontSize||0}get#M(){return this.#A?.attributes?.style?.color||null}#N(e){let t=[],n={str:e,html:{name:`div`,attributes:{dir:`auto`},children:[{name:`p`,children:t}]}},r={style:{color:this.#M,fontSize:this.#j?`calc(${this.#j}px * var(--total-scale-factor))`:``}};for(let n of e.split(`
|
|
49
|
-
`))t.push({name:`span`,value:n,attributes:r});return n}#P(e){e.altKey||e.shiftKey||e.ctrlKey||e.metaKey||(e.key===`Enter`||e.key===`Escape`&&this.#f)&&this.#I()}updateEdited({rect:e,popup:t,deleted:n}){if(this.#e){if(n){this.remove();this.#T=null}else if(t){if(t.deleted)this.remove();else{this.#k();this.#T=t.text}}if(e){this.#_=null;this.#D();this.#O()}}else if(n||t?.deleted)this.remove();else{this.#E();this.#S||={contentsObj:this.#s,richText:this.#b};e&&(this.#h=null);if(t&&t.text){this.#b=this.#N(t.text);this.#c=Ce.toDateObject(t.date);this.#s=null}this.#p?.remove();this.#p=null}}resetEdited(){if(this.#S){({contentsObj:this.#s,richText:this.#b}=this.#S);this.#S=null;this.#p?.remove();this.#p=null;this.#h=null}}remove(){this.#m?.abort();this.#m=null;this.#p?.remove();this.#p=null;this.#C=!1;this.#f=!1;this.#g?.remove();this.#g=null;if(this.trigger)for(let e of this.trigger)e.classList.remove(`popupTriggerArea`)}#F(){if(this.#h!==null)return;let{page:{view:e},viewport:{rawDims:{pageWidth:t,pageHeight:n,pageX:r,pageY:i}}}=this.#u,a=!!this.#d,o=a?this.#d:this.#y;for(let e of this.#l)if(!o||P.intersect(e.data.rect,o)!==null){o=e.data.rect;a=!0;break}let s=P.normalizeRect([o[0],e[3]-o[1]+e[1],o[2],e[3]-o[3]+e[1]]),c=a?o[2]-o[0]+5:0,l=s[0]+c,u=s[1];this.#h=[100*(l-r)/t,100*(u-i)/n];let{style:d}=this.#o;d.left=`${this.#h[0]}%`;d.top=`${this.#h[1]}%`}#I(){if(this.#e)this.#e.toggleCommentPopup(this,!1);else{this.#f=!this.#f;if(this.#f){this.#L();this.#o.addEventListener(`click`,this.#i);this.#o.addEventListener(`keydown`,this.#t)}else{this.#R();this.#o.removeEventListener(`click`,this.#i);this.#o.removeEventListener(`keydown`,this.#t)}}}#L(){this.#p||this.render();if(this.isVisible)this.#f&&this.#o.classList.add(`focused`);else{this.#F();this.#o.hidden=!1;this.#o.style.zIndex=parseInt(this.#o.style.zIndex,10)+1e3}}#R(){this.#o.classList.remove(`focused`);if(!this.#f&&this.isVisible){this.#o.hidden=!0;this.#o.style.zIndex=parseInt(this.#o.style.zIndex,10)-1e3}}forceHide(){this.#C=this.isVisible;this.#C&&(this.#o.hidden=!0)}maybeShow(){if(!this.#e){this.#E();if(this.#C){this.#p||this.#L();this.#C=!1;this.#o.hidden=!1}}}get isVisible(){return!this.#e&&!1===this.#o.hidden}}class pr extends Y{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});this.textContent=e.data.textContent;this.textPosition=e.data.textPosition;this.annotationEditorType=y.FREETEXT}render(){this.container.classList.add(`freeTextAnnotation`);if(this.textContent){let e=this.contentElement=document.createElement(`div`);e.classList.add(`annotationTextContent`);e.setAttribute(`role`,`comment`);for(let t of this.textContent){let n=document.createElement(`span`);n.textContent=t;e.append(n)}this.container.append(e)}if(!this.data.popupRef&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}this._editOnDoubleClick();return this.container}}class mr extends Y{#e=null;#t=[];constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});this.containerClassName=`inkAnnotation`;this.svgElementName=`svg:polyline`;this.annotationEditorType=this.data.it===`InkHighlight`?y.HIGHLIGHT:y.INK}#n(e,t){switch(e){case 90:return{transform:`rotate(90) translate(${-t[0]},${t[1]}) scale(1,-1)`,width:t[3]-t[1],height:t[2]-t[0]};case 180:return{transform:`rotate(180) translate(${-t[2]},${t[1]}) scale(1,-1)`,width:t[2]-t[0],height:t[3]-t[1]};case 270:return{transform:`rotate(270) translate(${-t[2]},${t[3]}) scale(1,-1)`,width:t[3]-t[1],height:t[2]-t[0]};default:return{transform:`translate(${-t[0]},${t[3]}) scale(1,-1)`,width:t[2]-t[0],height:t[3]-t[1]}}}render(){this.container.classList.add(this.containerClassName);let{data:{rect:e,rotation:t,inkLists:n,borderStyle:r,popupRef:i}}=this,{transform:a,width:o,height:s}=this.#n(t,e),c=this.svgFactory.create(o,s,!0),l=this.#e=this.svgFactory.createElement(`svg:g`);c.append(l);l.setAttribute(`stroke-width`,r.width||1);l.setAttribute(`stroke-linecap`,`round`);l.setAttribute(`stroke-linejoin`,`round`);l.setAttribute(`stroke-miterlimit`,10);l.setAttribute(`stroke`,`transparent`);l.setAttribute(`fill`,`transparent`);l.setAttribute(`transform`,a);for(let e=0,t=n.length;e<t;e++){let t=this.svgFactory.createElement(this.svgElementName);this.#t.push(t);t.setAttribute(`points`,n[e].join(`,`));l.append(t)}if(!i&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}this.container.append(c);this._editOnDoubleClick();return this.container}updateEdited(e){super.updateEdited(e);let{thickness:t,points:n,rect:r}=e,i=this.#e;t>=0&&i.setAttribute(`stroke-width`,t||1);if(n)for(let e=0,t=this.#t.length;e<t;e++)this.#t[e].setAttribute(`points`,n[e].join(`,`));if(r){let{transform:e,width:t,height:n}=this.#n(this.data.rotation,r);i.parentElement.setAttribute(`viewBox`,`0 0 ${t} ${n}`);i.setAttribute(`transform`,e)}}getElementsToTriggerPopup(){return this.#t}addHighlightArea(){this.container.classList.add(`highlightArea`)}}class hr extends Y{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0});this.annotationEditorType=y.HIGHLIGHT}render(){let{data:{overlaidText:e,popupRef:t}}=this;if(!t&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}this.container.classList.add(`highlightAnnotation`);this._editOnDoubleClick();if(e){let t=document.createElement(`mark`);t.classList.add(`overlaidText`);t.textContent=e;this.container.append(t)}return this.container}}class gr extends Y{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});this.annotationEditorType=y.STAMP}render(){this.container.classList.add(`stampAnnotation`);this.container.setAttribute(`role`,`img`);if(!this.data.popupRef&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}this._editOnDoubleClick();return this.container}}const _r=/\r\n?|\n/g;class X extends V{#e=``;#t=`${this.id}-editor`;#n=null;#r;_colorPicker=null;static _freeTextDefaultContent=``;static _internalPadding=0;static _defaultColor=null;static _defaultFontSize=10;static get _keyboardManager(){let e=X.prototype,t=e=>e.isEmpty(),n=Ve.TRANSLATE_SMALL,r=Ve.TRANSLATE_BIG;return j(this,`_keyboardManager`,new ze([[[`ctrl+s`,`mac+meta+s`,`ctrl+p`,`mac+meta+p`],e.commitOrRemove,{bubbles:!0}],[[`ctrl+Enter`,`mac+meta+Enter`,`Escape`,`mac+Escape`],e.commitOrRemove],[[`ArrowLeft`,`mac+ArrowLeft`],e._translateEmpty,{args:[-n,0],checker:t}],[[`ctrl+ArrowLeft`,`mac+shift+ArrowLeft`],e._translateEmpty,{args:[-r,0],checker:t}],[[`ArrowRight`,`mac+ArrowRight`],e._translateEmpty,{args:[n,0],checker:t}],[[`ctrl+ArrowRight`,`mac+shift+ArrowRight`],e._translateEmpty,{args:[r,0],checker:t}],[[`ArrowUp`,`mac+ArrowUp`],e._translateEmpty,{args:[0,-n],checker:t}],[[`ctrl+ArrowUp`,`mac+shift+ArrowUp`],e._translateEmpty,{args:[0,-r],checker:t}],[[`ArrowDown`,`mac+ArrowDown`],e._translateEmpty,{args:[0,n],checker:t}],[[`ctrl+ArrowDown`,`mac+shift+ArrowDown`],e._translateEmpty,{args:[0,r],checker:t}]]))}static _type=`freetext`;static _editorType=y.FREETEXT;constructor(e){super({...e,name:`freeTextEditor`});this.color=e.color||X._defaultColor||V._defaultLineColor;this.#r=e.fontSize||X._defaultFontSize;this.annotationElementId||this._uiManager.a11yAlert(V._l10nAlert.freetext);this.canAddComment=!1}static initialize(e,t){V.initialize(e,t);let n=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(n.getPropertyValue(`--freetext-padding`))}static updateDefaultParams(e,t){switch(e){case b.FREETEXT_SIZE:X._defaultFontSize=t;break;case b.FREETEXT_COLOR:X._defaultColor=t}}updateParams(e,t){switch(e){case b.FREETEXT_SIZE:this.#i(t);break;case b.FREETEXT_COLOR:this.#a(t)}}static get defaultPropertiesToUpdate(){return[[b.FREETEXT_SIZE,X._defaultFontSize],[b.FREETEXT_COLOR,X._defaultColor||V._defaultLineColor]]}get propertiesToUpdate(){return[[b.FREETEXT_SIZE,this.#r],[b.FREETEXT_COLOR,this.color]]}get toolbarButtons(){this._colorPicker||=new rr(this);return[[`colorPicker`,this._colorPicker]]}get colorType(){return b.FREETEXT_COLOR}#i(e){let t=e=>{this.editorDiv.style.fontSize=`calc(${e}px * var(--total-scale-factor))`;this.translate(0,-(e-this.#r)*this.parentScale);this.#r=e;this.#s()},n=this.#r;this.addCommands({cmd:t.bind(this,e),undo:t.bind(this,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:b.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})}onUpdatedColor(){this.editorDiv.style.color=this.color;this._colorPicker?.update(this.color);super.onUpdatedColor()}#a(e){let t=e=>{this.color=e;this.onUpdatedColor()},n=this.color;this.addCommands({cmd:t.bind(this,e),undo:t.bind(this,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:b.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})}_translateEmpty(e,t){this._uiManager.translateSelectedEditors(e,t,!0)}getInitialTranslation(){let e=this.parentScale;return[-X._internalPadding*e,-(X._internalPadding+this.#r)*e]}rebuild(){if(this.parent){super.rebuild();this.div!==null&&(this.isAttachedToDOM||this.parent.add(this))}}enableEditMode(){if(!super.enableEditMode())return!1;this.overlayDiv.classList.remove(`enabled`);this.editorDiv.contentEditable=!0;this._isDraggable=!1;this.div.removeAttribute(`aria-activedescendant`);this.#n=new AbortController;let e=this._uiManager.combinedSignal(this.#n);this.editorDiv.addEventListener(`keydown`,this.editorDivKeydown.bind(this),{signal:e});this.editorDiv.addEventListener(`focus`,this.editorDivFocus.bind(this),{signal:e});this.editorDiv.addEventListener(`blur`,this.editorDivBlur.bind(this),{signal:e});this.editorDiv.addEventListener(`input`,this.editorDivInput.bind(this),{signal:e});this.editorDiv.addEventListener(`paste`,this.editorDivPaste.bind(this),{signal:e});return!0}disableEditMode(){if(!super.disableEditMode())return!1;this.overlayDiv.classList.add(`enabled`);this.editorDiv.contentEditable=!1;this.div.setAttribute(`aria-activedescendant`,this.#t);this._isDraggable=!0;this.#n?.abort();this.#n=null;this.div.focus({preventScroll:!0});this.isEditing=!1;this.parent.div.classList.add(`freetextEditing`);return!0}focusin(e){if(this._focusEventsAllowed){super.focusin(e);e.target!==this.editorDiv&&this.editorDiv.focus()}}onceAdded(e){if(!this.width){this.enableEditMode();e&&this.editorDiv.focus();this._initialOptions?.isCentered&&this.center();this._initialOptions=null}}isEmpty(){return!this.editorDiv||this.editorDiv.innerText.trim()===``}remove(){this.isEditing=!1;if(this.parent){this.parent.setEditingState(!0);this.parent.div.classList.add(`freetextEditing`)}super.remove()}#o(){let e=[];this.editorDiv.normalize();let t=null;for(let n of this.editorDiv.childNodes)if(t?.nodeType!==Node.TEXT_NODE||n.nodeName!==`BR`){e.push(X.#c(n));t=n}return e.join(`
|
|
50
|
-
`)}#s(){let[e,t]=this.parentDimensions,n;if(this.isAttachedToDOM)n=this.div.getBoundingClientRect();else{let{currentLayer:e,div:t}=this,r=t.style.display,i=t.classList.contains(`hidden`);t.classList.remove(`hidden`);t.style.display=`hidden`;e.div.append(this.div);n=t.getBoundingClientRect();t.remove();t.style.display=r;t.classList.toggle(`hidden`,i)}if(this.rotation%180==this.parentRotation%180){this.width=n.width/e;this.height=n.height/t}else{this.width=n.height/e;this.height=n.width/t}this.fixAndSetPosition()}commit(){if(!this.isInEditMode())return;super.commit();this.disableEditMode();let e=this.#e,t=this.#e=this.#o().trimEnd();if(e===t)return;let n=e=>{this.#e=e;if(e){this.#l();this._uiManager.rebuild(this);this.#s()}else this.remove()};this.addCommands({cmd:()=>{n(t)},undo:()=>{n(e)},mustExec:!1});this.#s()}shouldGetKeyboardEvents(){return this.isInEditMode()}enterInEditMode(){this.enableEditMode();this.editorDiv.focus()}keydown(e){if(e.target===this.div&&e.key===`Enter`){this.enterInEditMode();e.preventDefault()}}editorDivKeydown(e){X._keyboardManager.exec(this,e)}editorDivFocus(e){this.isEditing=!0}editorDivBlur(e){this.isEditing=!1}editorDivInput(e){this.parent.div.classList.toggle(`freetextEditing`,this.isEmpty())}disableEditing(){this.editorDiv.setAttribute(`role`,`comment`);this.editorDiv.removeAttribute(`aria-multiline`)}enableEditing(){this.editorDiv.setAttribute(`role`,`textbox`);this.editorDiv.setAttribute(`aria-multiline`,!0)}get canChangeContent(){return!0}render(){if(this.div)return this.div;let e,t;if(this._isCopy||this.annotationElementId){e=this.x;t=this.y}super.render();this.editorDiv=document.createElement(`div`);this.editorDiv.className=`internal`;this.editorDiv.setAttribute(`id`,this.#t);this.editorDiv.setAttribute(`data-l10n-id`,`pdfjs-free-text2`);this.editorDiv.setAttribute(`data-l10n-attrs`,`default-content`);this.enableEditing();this.editorDiv.contentEditable=!0;let{style:n}=this.editorDiv;n.fontSize=`calc(${this.#r}px * var(--total-scale-factor))`;n.color=this.color;this.div.append(this.editorDiv);this.overlayDiv=document.createElement(`div`);this.overlayDiv.classList.add(`overlay`,`enabled`);this.div.append(this.overlayDiv);if(this._isCopy||this.annotationElementId){let[n,r]=this.parentDimensions;if(this.annotationElementId){let{position:i}=this._initialData,[a,o]=this.getInitialTranslation();[a,o]=this.pageTranslationToScreen(a,o);let[s,c]=this.pageDimensions,[l,u]=this.pageTranslation,d,f;switch(this.rotation){case 0:d=e+(i[0]-l)/s;f=t+this.height-(i[1]-u)/c;break;case 90:d=e+(i[0]-l)/s;f=t-(i[1]-u)/c;[a,o]=[o,-a];break;case 180:d=e-this.width+(i[0]-l)/s;f=t-(i[1]-u)/c;[a,o]=[-a,-o];break;case 270:d=e+(i[0]-l-this.height*c)/s;f=t+(i[1]-u-this.width*s)/c;[a,o]=[-o,a]}this.setAt(d*n,f*r,a,o)}else this._moveAfterPaste(e,t);this.#l();this._isDraggable=!0;this.editorDiv.contentEditable=!1}else{this._isDraggable=!1;this.editorDiv.contentEditable=!0}return this.div}static#c(e){return(e.nodeType===Node.TEXT_NODE?e.nodeValue:e.innerText).replaceAll(
|
|
48
|
+
this.workerSrc)).WorkerMessageHandler})())}}class Zn{downloadInfoCapability=Promise.withResolvers();#e=null;#t=new Map;#n=null;#r=new Map;#i=new Map;#a=new Map;#o=null;constructor(e,t,n,r,i,a){this.messageHandler=e;this.loadingTask=t;this.#n=n;this.commonObjs=new Gn;this.fontLoader=new pt({ownerDocument:r.ownerDocument,styleElement:r.styleElement});this.enableHWA=r.enableHWA;this.loadingParams=r.loadingParams;this._params=r;this.canvasFactory=i.canvasFactory;this.filterFactory=i.filterFactory;this.binaryDataFactory=i.binaryDataFactory;this.pagesMapper=a;this.destroyed=!1;this.destroyCapability=null;this.setupMessageHandler()}updatePage(e){let{_pageIndex:t}=e;this.#r.set(t,e);this.#i.set(t,Promise.resolve(e))}#s(e,t=null){return this.#t.getOrInsertComputed(e,()=>this.messageHandler.sendWithPromise(e,t))}#c({loaded:e,total:t}){this.loadingTask.onProgress?.({loaded:e,total:t,percent:t?F(Math.round(e/t*100),0,100):NaN})}get annotationStorage(){return j(this,`annotationStorage`,new qe)}getRenderingIntent(e,t=m.ENABLE,n=null,r=!1,i=!1){let a=2,o=Ke;switch(e){case`any`:a=1;break;case`display`:break;case`print`:a=4;break;default:E(`getRenderingIntent - invalid intent: ${e}`)}let s=a&4&&n instanceof Je?n:this.annotationStorage;switch(t){case m.DISABLE:a+=64;break;case m.ENABLE:break;case m.ENABLE_FORMS:a+=16;break;case m.ENABLE_STORAGE:a+=32;o=s.serializable;break;default:E(`getRenderingIntent - invalid annotationMode: ${t}`)}r&&(a+=128);i&&(a+=256);let{ids:c,hash:l}=s.modifiedIds;return{renderingIntent:a,cacheKey:[a,o.hash,l].join(`_`),annotationStorageSerializable:o,modifiedIds:c}}destroy(){if(this.destroyCapability)return this.destroyCapability.promise;this.destroyed=!0;this.destroyCapability=Promise.withResolvers();this.#o?.reject(Error(`Worker was destroyed during onPassword callback`));let e=[];for(let t of this.#r.values())e.push(t._destroy());this.#r.clear();this.#i.clear();this.#a.clear();Object.hasOwn(this,`annotationStorage`)&&this.annotationStorage.resetModified();let t=this.messageHandler.sendWithPromise(`Terminate`,null);e.push(t);Promise.all(e).then(()=>{this.commonObjs.clear();this.fontLoader.clear();this.#t.clear();this.filterFactory.destroy();q.cleanup();this.#n?.cancelAllRequests(new ae(`Worker was terminated.`));this.messageHandler?.destroy();this.messageHandler=null;this.destroyCapability.resolve()},this.destroyCapability.reject);return this.destroyCapability.promise}setupMessageHandler(){let{messageHandler:e,loadingTask:t}=this;e.on(`GetReader`,(e,t)=>{O(this.#n,"GetReader - no `BasePDFStream` instance available.");this.#e=this.#n.getFullReader();this.#e.onProgress=e=>this.#c(e);t.onPull=()=>{this.#e.read().then(function({value:e,done:n}){if(n)t.close();else{O(e instanceof ArrayBuffer,`GetReader - expected an ArrayBuffer.`);t.enqueue(new Uint8Array(e),1,[e])}}).catch(e=>{t.error(e)})};t.onCancel=e=>{this.#e.cancel(e);t.ready.catch(e=>{if(!this.destroyed)throw e})}});e.on(`ReaderHeadersReady`,async e=>{await this.#e.headersReady;let{isStreamingSupported:t,isRangeSupported:n,contentLength:r}=this.#e;t&&n&&(this.#e.onProgress=null);return{isStreamingSupported:t,isRangeSupported:n,contentLength:r}});e.on(`GetRangeReader`,(e,t)=>{O(this.#n,"GetRangeReader - no `BasePDFStream` instance available.");let n=this.#n.getRangeReader(e.begin,e.end);if(n){t.onPull=()=>{n.read().then(function({value:e,done:n}){if(n)t.close();else{O(e instanceof ArrayBuffer,`GetRangeReader - expected an ArrayBuffer.`);t.enqueue(new Uint8Array(e),1,[e])}}).catch(e=>{t.error(e)})};t.onCancel=e=>{n.cancel(e);t.ready.catch(e=>{if(!this.destroyed)throw e})}}else t.close()});e.on(`GetDoc`,({pdfInfo:e})=>{this.pagesMapper.pagesNumber=e.numPages;this._numPages=e.numPages;this._htmlForXfa=e.htmlForXfa;delete e.htmlForXfa;t._capability.resolve(new Yn(e,this))});e.on(`DocException`,e=>{t._capability.reject(G(e))});e.on(`PasswordRequest`,e=>{this.#o=Promise.withResolvers();try{if(!t.onPassword)throw G(e);t.onPassword(e=>{e instanceof Error?this.#o.reject(e):this.#o.resolve({password:e})},e.code)}catch(e){this.#o.reject(e)}return this.#o.promise});e.on(`DataLoaded`,e=>{this.#c({loaded:e.length,total:e.length});this.downloadInfoCapability.resolve(e)});e.on(`StartRenderPage`,e=>{if(this.destroyed)return;this.#r.get(e.pageIndex)._startRenderPage(e.transparency,e.cacheKey)});e.on(`commonobj`,([t,n,r])=>{if(this.destroyed)return null;if(this.commonObjs.has(t))return null;switch(n){case`Font`:if(`error`in r){let e=r.error;E(`Error during font loading: ${e}`);this.commonObjs.resolve(t,e);break}let i=new bt(r),a=this._params.pdfBug&&globalThis.FontInspector?.enabled?(e,t)=>globalThis.FontInspector.fontAdded(e,t):null,o=new mt(i,a,r.charProcOperatorList,r.extra);this.fontLoader.bind(o).catch(()=>e.sendWithPromise(`FontFallback`,{id:t})).finally(()=>{o.fontExtraProperties||o.clearData();this.commonObjs.resolve(t,o)});break;case`CopyLocalImage`:let{imageRef:s}=r;O(s,`The imageRef must be defined.`);for(let e of this.#r.values())for(let[,n]of e.objs){if(n?.ref!==s)continue;if(!n.dataLen)return null;let e=structuredClone(n);this.commonObjs.resolve(t,e);return n.dataLen}break;case`FontPath`:this.commonObjs.resolve(t,new St(r));break;case`Image`:this.commonObjs.resolve(t,r);break;case`Pattern`:let c=new xt(r);this.commonObjs.resolve(t,c.getIR());break;default:throw Error(`Got unknown common object type ${n}`)}return null});e.on(`obj`,([e,t,n,r])=>{if(this.destroyed)return;let i=this.#r.get(t);if(!i.objs.has(e)){if(i._intentStates.size!==0)switch(n){case`Image`:case`Pattern`:i.objs.resolve(e,r);break;default:throw Error(`Got unknown object type ${n}`)}else r?.bitmap?.close()}});e.on(`DocProgress`,e=>{this.destroyed||this.#c(e)});e.on(`FetchBinaryData`,async e=>{if(this.destroyed)throw Error(`Worker was destroyed.`);if(!this.binaryDataFactory)throw Error("`BinaryDataFactory` not initialized, see the `useWorkerFetch` parameter.");return this.binaryDataFactory.fetch(e)})}getData(){return this.messageHandler.sendWithPromise(`GetData`,null)}saveDocument(){this.annotationStorage.size<=0&&E("saveDocument called while `annotationStorage` is empty, please use the getData-method instead.");let{map:e,transfer:t}=this.annotationStorage.serializable;return this.messageHandler.sendWithPromise(`SaveDocument`,{isPureXfa:!!this._htmlForXfa,numPages:this._numPages,annotationStorage:e,filename:this.#e?.filename??null},t).finally(()=>{this.annotationStorage.resetModified()})}extractPages(e){let t={pageInfos:e},n;if(this.annotationStorage.size>0){let e=this.annotationStorage.serializable,{map:r}=e;n=e.transfer;let i=this.pagesMapper.getMapping();if(i){let e=new Map;for(let[t,n]of r){if(n?.pageIndex!==void 0&&n.pageIndex>=0&&n.pageIndex<i.length){let r=i[n.pageIndex]-1;if(r!==n.pageIndex){e.set(t,{...n,pageIndex:r});continue}}e.set(t,n)}r=e}t.annotationStorage=r}return this.messageHandler.sendWithPromise(`ExtractPages`,t,n).finally(()=>{this.annotationStorage.resetModified()})}getPage(e){if(!Number.isInteger(e)||e<=0||e>this.pagesMapper.pagesNumber)return Promise.reject(Error(`Invalid page request.`));let t=e-1,n=this.pagesMapper.getPageId(e)-1,r=this.#i.get(t);if(r)return r;let i=this.messageHandler.sendWithPromise(`GetPage`,{pageIndex:n}).then(e=>{if(this.destroyed)throw Error(`Transport destroyed`);e.refStr&&this.#a.set(e.refStr,n);let r=new Xn(t,e,this,this.pagesMapper,this._params.pdfBug);this.#r.set(t,r);return r});this.#i.set(t,i);return i}async getPageIndex(e){if(!wt(e))throw Error(`Invalid pageIndex request.`);let t=await this.messageHandler.sendWithPromise(`GetPageIndex`,{num:e.num,gen:e.gen}),n=this.pagesMapper.getPageNumber(t+1);if(n===0)throw Error(`GetPageIndex: page has been removed.`);return n-1}getAnnotations(e,t){return this.messageHandler.sendWithPromise(`GetAnnotations`,{pageIndex:this.pagesMapper.getPageId(e+1)-1,intent:t})}getFieldObjects(){return this.#s(`GetFieldObjects`)}hasJSActions(){return this.#s(`HasJSActions`)}getCalculationOrderIds(){return this.messageHandler.sendWithPromise(`GetCalculationOrderIds`,null)}getDestinations(){return this.messageHandler.sendWithPromise(`GetDestinations`,null)}getDestination(e){return typeof e==`string`?this.messageHandler.sendWithPromise(`GetDestination`,{id:e}):Promise.reject(Error(`Invalid destination request.`))}getPageLabels(){return this.messageHandler.sendWithPromise(`GetPageLabels`,null)}getPageLayout(){return this.messageHandler.sendWithPromise(`GetPageLayout`,null)}getPageMode(){return this.messageHandler.sendWithPromise(`GetPageMode`,null)}getViewerPreferences(){return this.messageHandler.sendWithPromise(`GetViewerPreferences`,null)}getOpenAction(){return this.messageHandler.sendWithPromise(`GetOpenAction`,null)}getAttachments(){return this.messageHandler.sendWithPromise(`GetAttachments`,null)}getAnnotationsByType(e,t){return this.messageHandler.sendWithPromise(`GetAnnotationsByType`,{types:e,pageIndexesToSkip:t})}getDocJSActions(){return this.#s(`GetDocJSActions`)}getPageJSActions(e){return this.messageHandler.sendWithPromise(`GetPageJSActions`,{pageIndex:this.pagesMapper.getPageId(e+1)-1})}getStructTree(e){return this.messageHandler.sendWithPromise(`GetStructTree`,{pageIndex:this.pagesMapper.getPageId(e+1)-1})}getOutline(){return this.messageHandler.sendWithPromise(`GetOutline`,null)}getOptionalContentConfig(e){return this.#s(`GetOptionalContentConfig`).then(t=>new Vn(t,e))}getPermissions(){return this.messageHandler.sendWithPromise(`GetPermissions`,null)}getMetadata(){let e=`GetMetadata`;return this.#t.getOrInsertComputed(e,()=>this.messageHandler.sendWithPromise(e,null).then(e=>({info:e[0],metadata:e[1]?new Rn(e[1]):null,contentDispositionFilename:this.#e?.filename??null,contentLength:this.#e?.contentLength??null,hasStructTree:e[2]})))}getMarkInfo(){return this.messageHandler.sendWithPromise(`GetMarkInfo`,null)}getRawData(e){return this.messageHandler.sendWithPromise(`GetRawData`,e)}getGeospatialPDFMetadata(e){return this.messageHandler.sendWithPromise(`GetGeospatialPDFMetadata`,{pageIndex:e})}async startCleanup(e=!1){if(!this.destroyed){await this.messageHandler.sendWithPromise(`Cleanup`,null);for(let e of this.#r.values())if(!e.cleanup())throw Error(`startCleanup: Page ${e.pageNumber} is currently rendering.`);this.commonObjs.clear();e||this.fontLoader.clear();this.#t.clear();this.filterFactory.destroy(!0);q.cleanup()}}cachedPageNumber(e){if(!wt(e))return null;let t=e.gen===0?`${e.num}R`:`${e.num}R${e.gen}`,n=this.#a.get(t);if(n>=0){let e=this.pagesMapper.getPageNumber(n+1);if(e!==0)return e}return null}}class Qn{_internalRenderTask=null;onContinue=null;onError=null;constructor(e){this._internalRenderTask=e}get promise(){return this._internalRenderTask.capability.promise}cancel(e=0){this._internalRenderTask.cancel(null,e)}get separateAnnots(){let{separateAnnots:e}=this._internalRenderTask.operatorList;if(!e)return!1;let{annotationCanvasMap:t}=this._internalRenderTask;return e.form||e.canvas&&t?.size>0}get imageCoordinates(){return this._internalRenderTask.imageCoordinates||null}}class $n{#e=null;#t=null;static#n=new WeakSet;constructor({callback:e,params:t,objs:n,commonObjs:r,annotationCanvasMap:i,operatorList:a,pageIndex:o,canvasFactory:s,filterFactory:c,useRequestAnimationFrame:l=!1,pdfBug:u=!1,pageColors:d=null,enableHWA:f=!1,operationsFilter:p=null,renderingBudget:m=null,renderingScheduler:h=null}){this.callback=e;this.params=t;this.objs=n;this.commonObjs=r;this.annotationCanvasMap=i;this.operatorListIdx=null;this.operatorList=a;this._pageIndex=o;this.canvasFactory=s;this.filterFactory=c;this._pdfBug=u;this.pageColors=d;this.running=!1;this.graphicsReadyCallback=null;this.graphicsReady=!1;this._useRequestAnimationFrame=!0===l&&typeof window<`u`;this.cancelled=!1;this.capability=Promise.withResolvers();this.task=new Qn(this);this._cancelBound=this.cancel.bind(this);this._continueBound=this._continue.bind(this);this._scheduleNextBound=this._scheduleNext.bind(this);this._nextBound=this._next.bind(this);this._canvas=t.canvas;this._canvasContext=t.canvas?null:t.canvasContext;this._enableHWA=f;this._dependencyTracker=t.dependencyTracker;this._imagesTracker=t.imagesTracker;this._operationsFilter=p;this._renderingBudget=m;this._renderingScheduler=h}get completed(){return this.capability.promise.catch(function(){})}initializeGraphics({transparency:e=!1,optionalContentConfig:t}){if(this.cancelled)return;if(this._canvas){if($n.#n.has(this._canvas))throw Error(`Cannot use the same canvas during multiple render() operations. Use different canvas or ensure previous operations were cancelled or completed.`);$n.#n.add(this._canvas)}if(this._pdfBug&&globalThis.StepperManager?.enabled){this.stepper=globalThis.StepperManager.create(this._pageIndex);this.stepper.init(this.operatorList);this.stepper.nextBreakPoint=this.stepper.getNextBreakPoint()}let{viewport:n,transform:r,background:i,dependencyTracker:a,imagesTracker:o}=this.params,s=this._canvasContext||this._canvas.getContext(`2d`,{alpha:!1,willReadFrequently:!this._enableHWA});this.gfx=new ln(s,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:t},this.annotationCanvasMap,this.pageColors,a,o);this.gfx.beginDrawing({transform:r,viewport:n,transparency:e,background:i});this.operatorListIdx=0;this.graphicsReady=!0;this.graphicsReadyCallback?.()}cancel(e=null,t=0){this.running=!1;this.cancelled=!0;this.gfx?.endDrawing();this._cancelScheduledContinue();$n.#n.delete(this._canvas);e||=new ge(`Rendering cancelled, page ${this._pageIndex+1}`,t);this.callback(e);this.task.onError?.(e)}_cancelScheduledContinue(){if(this.#e){window.cancelAnimationFrame(this.#e);this.#e=null}this.#t?.();this.#t=null}operatorListChanged(){if(this.graphicsReady){this.gfx.dependencyTracker?.growOperationsCount(this.operatorList.fnArray.length);this.stepper?.updateOperatorList(this.operatorList);this.running||this._continue()}else this.graphicsReadyCallback||=this._continueBound}_continue(){this.running=!0;this.cancelled||(this.task.onContinue?this.task.onContinue(this._scheduleNextBound):this._scheduleNext())}_scheduleNext(){let e=e=>{this.#e=null;this.#t=null;this._nextBound(e||null).catch(this._cancelBound)};this._renderingScheduler?.scheduleContinue?this.#t=this._renderingScheduler.scheduleContinue(e)||null:this._useRequestAnimationFrame?this.#e=window.requestAnimationFrame(()=>{e(null)}):Promise.resolve().then(()=>e(null)).catch(this._cancelBound)}async _next(e=null){if(!this.cancelled){this.operatorListIdx=this.gfx.executeOperatorList(this.operatorList,this.operatorListIdx,this._continueBound,this.stepper,this._operationsFilter,this._renderingBudget,e);if(this.operatorListIdx===this.operatorList.argsArray.length){this.running=!1;if(this.operatorList.lastChunk){this.gfx.endDrawing();$n.#n.delete(this._canvas);this.callback()}}}}}class Y{#e=null;#t=null;#n;#r=null;#i=!1;#a=!1;#o=null;#s;#c=null;#l=null;static#u=null;static get _keyboardManager(){return j(this,`_keyboardManager`,new Ie([[[`Escape`,`mac+Escape`],Y.prototype._hideDropdownFromKeyboard],[[` `,`mac+ `],Y.prototype._colorSelectFromKeyboard],[[`ArrowDown`,`ArrowRight`,`mac+ArrowDown`,`mac+ArrowRight`],Y.prototype._moveToNext],[[`ArrowUp`,`ArrowLeft`,`mac+ArrowUp`,`mac+ArrowLeft`],Y.prototype._moveToPrevious],[[`Home`,`mac+Home`],Y.prototype._moveToBeginning],[[`End`,`mac+End`],Y.prototype._moveToEnd]]))}constructor({editor:e=null,uiManager:t=null}){if(e){this.#a=!1;this.#o=e}else this.#a=!0;this.#l=e?._uiManager||t;this.#s=this.#l._eventBus;this.#n=e?.color?.toUpperCase()||this.#l?.highlightColors.values().next().value||`#FFFF98`;Y.#u||=Object.freeze({blue:`pdfjs-editor-colorpicker-blue`,green:`pdfjs-editor-colorpicker-green`,pink:`pdfjs-editor-colorpicker-pink`,red:`pdfjs-editor-colorpicker-red`,yellow:`pdfjs-editor-colorpicker-yellow`})}renderButton(){let e=this.#e=document.createElement(`button`);e.className=`colorPicker`;e.tabIndex=`0`;e.setAttribute(`data-l10n-id`,`pdfjs-editor-colorpicker-button`);e.ariaHasPopup=`true`;this.#o&&(e.ariaControls=`${this.#o.id}_colorpicker_dropdown`);let t=this.#l._signal;e.addEventListener(`click`,this.#m.bind(this),{signal:t});e.addEventListener(`keydown`,this.#p.bind(this),{signal:t});let n=this.#t=document.createElement(`span`);n.className=`swatch`;n.ariaHidden=`true`;n.style.backgroundColor=this.#n;e.append(n);return e}renderMainDropdown(){let e=this.#r=this.#d();e.ariaOrientation=`horizontal`;e.ariaLabelledBy=`highlightColorPickerLabel`;return e}#d(){let e=document.createElement(`div`),t=this.#l._signal;e.addEventListener(`contextmenu`,L,{signal:t});e.className=`dropdown`;e.role=`listbox`;e.ariaMultiSelectable=`false`;e.ariaOrientation=`vertical`;e.setAttribute(`data-l10n-id`,`pdfjs-editor-colorpicker-dropdown`);this.#o&&(e.id=`${this.#o.id}_colorpicker_dropdown`);for(let[n,r]of this.#l.highlightColors){let i=document.createElement(`button`);i.tabIndex=`0`;i.role=`option`;i.setAttribute(`data-color`,r);i.title=n;i.setAttribute(`data-l10n-id`,Y.#u[n]);let a=document.createElement(`span`);i.append(a);a.className=`swatch`;a.style.backgroundColor=r;i.ariaSelected=r===this.#n;i.addEventListener(`click`,this.#f.bind(this,r),{signal:t});e.append(i)}e.addEventListener(`keydown`,this.#p.bind(this),{signal:t});return e}#f(e,t){t.stopPropagation();this.#s.dispatch(`switchannotationeditorparams`,{source:this,type:v.HIGHLIGHT_COLOR,value:e});this.updateColor(e)}_colorSelectFromKeyboard(e){if(e.target===this.#e){this.#m(e);return}let t=e.target.getAttribute(`data-color`);t&&this.#f(t,e)}_moveToNext(e){this.#g?e.target===this.#e?this.#r.firstElementChild?.focus():e.target.nextSibling?.focus():this.#m(e)}_moveToPrevious(e){if(e.target!==this.#r?.firstElementChild&&e.target!==this.#e){this.#g||this.#m(e);e.target.previousSibling?.focus()}else this.#g&&this._hideDropdownFromKeyboard()}_moveToBeginning(e){this.#g?this.#r.firstElementChild?.focus():this.#m(e)}_moveToEnd(e){this.#g?this.#r.lastElementChild?.focus():this.#m(e)}#p(e){Y._keyboardManager.exec(this,e)}#m(e){if(this.#g){this.hideDropdown();return}this.#i=e.detail===0;if(!this.#c){this.#c=new AbortController;window.addEventListener(`pointerdown`,this.#h.bind(this),{signal:this.#l.combinedSignal(this.#c)})}this.#e.ariaExpanded=`true`;if(this.#r){this.#r.classList.remove(`hidden`);return}let t=this.#r=this.#d();this.#e.append(t)}#h(e){this.#r?.contains(e.target)||this.hideDropdown()}hideDropdown(){this.#r?.classList.add(`hidden`);this.#e.ariaExpanded=`false`;this.#c?.abort();this.#c=null}get#g(){return this.#r&&!this.#r.classList.contains(`hidden`)}_hideDropdownFromKeyboard(){if(!this.#a){if(this.#g){this.hideDropdown();this.#e.focus({preventScroll:!0,focusVisible:this.#i})}else this.#o?.unselect()}}updateColor(e){this.#t&&(this.#t.style.backgroundColor=e);if(!this.#r)return;let t=this.#l.highlightColors.values();for(let n of this.#r.children)n.ariaSelected=t.next().value===e.toUpperCase()}destroy(){this.#e?.remove();this.#e=null;this.#t=null;this.#r?.remove();this.#r=null}}class er{#e=null;#t=!1;#n=null;#r=null;static#i=null;constructor(e){this.#n=e;this.#r=e._uiManager;er.#i||=Object.freeze({freetext:`pdfjs-editor-color-picker-free-text-input`,ink:`pdfjs-editor-color-picker-ink-input`})}renderButton(){if(this.#e)return this.#e;let{editorType:e,colorType:t,colorAndOpacityType:n,opacityType:r,color:i,opacity:a}=this.#n,o=this.#t=N.isAlphaColorInputSupported&&r!==void 0,s=this.#e=document.createElement(`input`);s.type=`color`;if(o){s.setAttribute(`alpha`,``);let e=P.hexNums[Math.round(255*(a??1))];s.value=(i||`#000000`)+e}else s.value=i||`#000000`;s.className=`basicColorPicker`;s.tabIndex=0;s.setAttribute(`data-l10n-id`,er.#i[e]);s.addEventListener(`input`,()=>{if(o){let e=Se(s.value);if(!e)return;let[i,a,o,c]=e,l=P.makeHexColor(i,a,o);if(n!==void 0)this.#r.updateParams(n,{color:l,opacity:c});else{this.#r.updateParams(t,l);this.#r.updateParams(r,c)}}else this.#r.updateParams(t,s.value)},{signal:this.#r._signal});return s}update(e){if(this.#e){if(this.#t){let t=P.hexNums[Math.round(255*this.#n.opacity)];this.#e.value=e+t}else this.#e.value=e}}updateOpacity(e){if(!this.#e||!this.#t)return;let t=P.hexNums[Math.round(255*e)];this.#e.value=this.#n.color+t}destroy(){this.#e?.remove();this.#e=null}hideDropdown(){}}function tr(e){return Math.floor(255*F(e,0,1)).toString(16).padStart(2,`0`)}function nr(e){return 255*F(e,0,1)}class rr{static CMYK_G([e,t,n,r]){return[`G`,1-Math.min(1,.3*e+.59*n+.11*t+r)]}static G_CMYK([e]){return[`CMYK`,0,0,0,1-e]}static G_RGB([e]){return[`RGB`,e,e,e]}static G_rgb([e]){return[e=nr(e),e,e]}static G_HTML([e]){let t=tr(e);return`#${t}${t}${t}`}static RGB_G([e,t,n]){return[`G`,.3*e+.59*t+.11*n]}static RGB_rgb(e){return e.map(nr)}static RGB_HTML(e){return`#${e.map(tr).join(``)}`}static T_HTML(){return`#00000000`}static T_rgb(){return[null]}static CMYK_RGB([e,t,n,r]){return[`RGB`,1-Math.min(1,e+r),1-Math.min(1,n+r),1-Math.min(1,t+r)]}static CMYK_rgb([e,t,n,r]){return[nr(1-Math.min(1,e+r)),nr(1-Math.min(1,n+r)),nr(1-Math.min(1,t+r))]}static CMYK_HTML(e){let t=this.CMYK_RGB(e).slice(1);return this.RGB_HTML(t)}static RGB_CMYK([e,t,n]){let r=1-e,i=1-t,a=1-n;return[`CMYK`,r,i,a,Math.min(r,i,a)]}}const ir=new WeakSet;60*new Date().getTimezoneOffset()*1e3;class ar{#e=null;#t=!1;#n=null;constructor(e,{isRenderable:t=!1,ignoreBorder:n=!1,createQuadrilaterals:r=!1}={}){this.isRenderable=t;this.data=e.data;this.layer=e.layer;this.linkService=e.linkService;this.downloadManager=e.downloadManager;this.imageResourcesPath=e.imageResourcesPath;this.renderForms=e.renderForms;this.svgFactory=e.svgFactory;this.annotationStorage=e.annotationStorage;this.enableComment=e.enableComment;this.enableScripting=e.enableScripting;this.hasJSActions=e.hasJSActions;this._fieldObjects=e.fieldObjects;this.parent=e.parent;this.hasOwnCommentButton=!1;t&&(this.contentElement=this.container=this._createContainer(n));r&&this._createQuadrilaterals()}static _hasPopupData({contentsObj:e,richText:t}){return!(!e?.str&&!t?.str)}get _isEditable(){return this.data.isEditable}get hasPopupData(){return ar._hasPopupData(this.data)||this.enableComment&&!!this.commentText}get commentData(){let{data:e}=this,t=this.annotationStorage?.getEditor(e.id);return t?t.getData():e}get hasCommentButton(){return this.enableComment&&this.hasPopupElement}get commentButtonPosition(){let e=this.annotationStorage?.getEditor(this.data.id);if(e)return e.commentButtonPositionInPage;let{quadPoints:t,inkLists:n,rect:r}=this.data,i=-1/0,a=-1/0;if(t?.length>=8){for(let e=0;e<t.length;e+=8)if(t[e+1]>a){a=t[e+1];i=t[e+2]}else t[e+1]===a&&(i=Math.max(i,t[e+2]));return[i,a]}if(n?.length>=1){for(let e of n)for(let t=0,n=e.length;t<n;t+=2)if(e[t+1]>a){a=e[t+1];i=e[t]}else e[t+1]===a&&(i=Math.max(i,e[t]));if(i!==1/0)return[i,a]}return r?[r[2],r[3]]:null}_normalizePoint(e){let{page:{view:t},viewport:{rawDims:{pageWidth:n,pageHeight:r,pageX:i,pageY:a}}}=this.parent;e[1]=t[3]-e[1]+t[1];e[0]=100*(e[0]-i)/n;e[1]=100*(e[1]-a)/r;return e}get commentText(){let{data:e}=this;return this.annotationStorage.getRawValue(`${g}${e.id}`)?.popup?.contents||e.contentsObj?.str||``}set commentText(e){let{data:t}=this,n={deleted:!e,contents:e||``};this.annotationStorage.updateEditor(t.id,{popup:n})||this.annotationStorage.setValue(`${g}${t.id}`,{id:t.id,annotationType:t.annotationType,page:this.parent.page,popup:n,popupRef:t.popupRef,modificationDate:new Date});e||this.removePopup()}removePopup(){(this.#n?.popup||this.popup)?.remove();this.#n=this.popup=null}updateEdited(e){if(!this.container)return;e.rect&&(this.#e||={rect:this.data.rect.slice(0)});let{rect:t,popup:n}=e;t&&this.#r(t);let r=this.#n?.popup||this.popup;if(!r&&n?.text){this._createPopup(n);r=this.#n.popup}if(r){r.updateEdited(e);if(n?.deleted){r.remove();this.#n=null;this.popup=null}}}resetEdited(){if(this.#e){this.#r(this.#e.rect);this.#n?.popup.resetEdited();this.#e=null}}#r(e){let{container:{style:t},data:{rect:n,rotation:r},parent:{viewport:{rawDims:{pageWidth:i,pageHeight:a,pageX:o,pageY:s}}}}=this;n?.splice(0,4,...e);t.left=100*(e[0]-o)/i+`%`;t.top=100*(a-e[3]+s)/a+`%`;if(r===0){t.width=100*(e[2]-e[0])/i+`%`;t.height=100*(e[3]-e[1])/a+`%`}else this.setRotation(r)}_createContainer(e){let{data:t,parent:{page:n,viewport:r}}=this,i=document.createElement(`section`);i.setAttribute(`data-annotation-id`,t.id);this instanceof sr||this instanceof or||(i.tabIndex=0);let{style:a}=i;a.zIndex=this.parent.zIndex;this.parent.zIndex+=2;t.alternativeText&&(i.title=t.alternativeText);t.noRotate&&i.classList.add(`norotate`);if(!t.rect||this instanceof lr){let{rotation:e}=t;t.hasOwnCanvas||e===0||this.setRotation(e,i);return i}let{width:o,height:s}=this;if(!e&&t.borderStyle.width>0){a.borderWidth=`${t.borderStyle.width}px`;let e=t.borderStyle.horizontalCornerRadius,n=t.borderStyle.verticalCornerRadius;e>0||n>0?a.borderRadius=`calc(${e}px * var(--total-scale-factor)) / calc(${n}px * var(--total-scale-factor))`:this instanceof cr&&(a.borderRadius=`calc(${o}px * var(--total-scale-factor)) / calc(${s}px * var(--total-scale-factor))`);switch(t.borderStyle.style){case 1:a.borderStyle=`solid`;break;case 2:a.borderStyle=`dashed`;break;case 3:E(`Unimplemented border style: beveled`);break;case 4:E(`Unimplemented border style: inset`);break;case 5:a.borderBottomStyle=`solid`}let r=t.borderColor||null;if(r){this.#t=!0;a.borderColor=P.makeHexColor(...r)}else a.borderWidth=0}let c=P.normalizeRect([t.rect[0],n.view[3]-t.rect[1]+n.view[1],t.rect[2],n.view[3]-t.rect[3]+n.view[1]]),{pageWidth:l,pageHeight:u,pageX:d,pageY:f}=r.rawDims;a.left=100*(c[0]-d)/l+`%`;a.top=100*(c[1]-f)/u+`%`;let{rotation:p}=t;if(t.hasOwnCanvas||p===0){a.width=100*o/l+`%`;a.height=100*s/u+`%`}else this.setRotation(p,i);return i}setRotation(e,t=this.container){if(!this.data.rect)return;let{pageWidth:n,pageHeight:r}=this.parent.viewport.rawDims,{width:i,height:a}=this;e%180!=0&&([i,a]=[a,i]);t.style.width=100*i/n+`%`;t.style.height=100*a/r+`%`;t.setAttribute(`data-main-rotation`,(360-e)%360)}get _commonActions(){let e=(e,t,n)=>{let r=n.detail[e],i=r[0],a=r.slice(1);n.target.style[t]=rr[`${i}_HTML`](a);this.annotationStorage.setValue(this.data.id,{[t]:rr[`${i}_rgb`](a)})};return j(this,`_commonActions`,{display:e=>{let{display:t}=e.detail,n=t%2==1;this.container.style.visibility=n?`hidden`:`visible`;this.annotationStorage.setValue(this.data.id,{noView:n,noPrint:t===1||t===2})},print:e=>{this.annotationStorage.setValue(this.data.id,{noPrint:!e.detail.print})},hidden:e=>{let{hidden:t}=e.detail;this.container.style.visibility=t?`hidden`:`visible`;this.annotationStorage.setValue(this.data.id,{noPrint:t,noView:t})},focus:e=>{setTimeout(()=>e.target.focus({preventScroll:!1}),0)},userName:e=>{e.target.title=e.detail.userName},readonly:e=>{e.target.disabled=e.detail.readonly},required:e=>{this._setRequired(e.target,e.detail.required)},bgColor:t=>{e(`bgColor`,`backgroundColor`,t)},fillColor:t=>{e(`fillColor`,`backgroundColor`,t)},fgColor:t=>{e(`fgColor`,`color`,t)},textColor:t=>{e(`textColor`,`color`,t)},borderColor:t=>{e(`borderColor`,`borderColor`,t)},strokeColor:t=>{e(`strokeColor`,`borderColor`,t)},rotation:e=>{let t=e.detail.rotation;this.setRotation(t);this.annotationStorage.setValue(this.data.id,{rotation:t})}})}_dispatchEventFromSandbox(e,t){let n=this._commonActions;for(let r of Object.keys(t.detail))(e[r]||n[r])?.(t)}_setDefaultPropertiesFromJS(e){if(!this.enableScripting)return;let t=this.annotationStorage.getRawValue(this.data.id);if(!t)return;let n=this._commonActions;for(let[r,i]of Object.entries(t)){let a=n[r];if(a){a({detail:{[r]:i},target:e});delete t[r]}}}_createQuadrilaterals(){if(!this.container)return;let{quadPoints:e}=this.data;if(!e)return;let[t,n,r,i]=this.data.rect.map(e=>Math.fround(e));if(e.length===8){let[a,o,s,c]=e.subarray(2,6);if(r===a&&i===o&&t===s&&n===c)return}let{style:a}=this.container,o;if(this.#t){let{borderColor:e,borderWidth:t}=a;a.borderWidth=0;o=[`url('data:image/svg+xml;utf8,`,`<svg xmlns="http://www.w3.org/2000/svg"`,` preserveAspectRatio="none" viewBox="0 0 1 1">`,`<g fill="transparent" stroke="${e}" stroke-width="${t}">`];this.container.classList.add(`hasBorder`)}let s=r-t,c=i-n,{svgFactory:l}=this,u=l.createElement(`svg`);u.classList.add(`quadrilateralsContainer`);u.setAttribute(`width`,0);u.setAttribute(`height`,0);u.role=`none`;let d=l.createElement(`defs`);u.append(d);let f=l.createElement(`clipPath`),p=`clippath_${this.data.id}`;f.setAttribute(`id`,p);f.setAttribute(`clipPathUnits`,`objectBoundingBox`);d.append(f);for(let n=2,r=e.length;n<r;n+=8){let r=e[n],a=e[n+1],u=e[n+2],d=e[n+3],p=l.createElement(`rect`),m=(u-t)/s,h=(i-a)/c,g=(r-u)/s,_=(a-d)/c;p.setAttribute(`x`,m);p.setAttribute(`y`,h);p.setAttribute(`width`,g);p.setAttribute(`height`,_);f.append(p);o?.push(`<rect vector-effect="non-scaling-stroke" x="${m}" y="${h}" width="${g}" height="${_}"/>`)}if(this.#t){o.push(`</g></svg>')`);a.backgroundImage=o.join(``)}this.container.append(u);this.container.style.clipPath=`url(#${p})`}_createPopup(e=null){let{data:t}=this,n,r;if(e){n={str:e.text};r=e.date}else{n=t.contentsObj;r=t.modificationDate}this.#n=new lr({data:{color:t.color,titleObj:t.titleObj,modificationDate:r,contentsObj:n,richText:t.richText,parentRect:t.rect,borderStyle:0,id:`popup_${t.id}`,rotation:t.rotation,noRotate:!0},linkService:this.linkService,parent:this.parent,elements:[this]})}get hasPopupElement(){return!!(this.#n||this.popup||this.data.popupRef)}get extraPopupElement(){return this.#n}render(){D("Abstract method `AnnotationElement.render` called")}_getElementsByName(e,t=null){let n=[];if(this._fieldObjects){let r=this._fieldObjects[e];if(r)for(let{page:e,id:i,exportValues:a}of r){if(e===-1)continue;if(i===t)continue;let r=typeof a==`string`?a:null,o=document.querySelector(`[data-element-id="${i}"]`);!o||ir.has(o)?n.push({id:i,exportValue:r,domElement:o}):E(`_getElementsByName - element not allowed: ${i}`)}return n}for(let r of document.getElementsByName(e)){let{exportValue:e}=r,i=r.getAttribute(`data-element-id`);i!==t&&ir.has(r)&&n.push({id:i,exportValue:e,domElement:r})}return n}show(){this.container&&(this.container.hidden=!1);this.popup?.maybeShow()}hide(){this.container&&(this.container.hidden=!0);this.popup?.forceHide()}getElementsToTriggerPopup(){return this.container}addHighlightArea(){let e=this.getElementsToTriggerPopup();if(Array.isArray(e))for(let t of e)t.classList.add(`highlightArea`);else e.classList.add(`highlightArea`)}_editOnDoubleClick(){if(!this._isEditable)return;let{annotationEditorType:e,data:{id:t}}=this;this.container.addEventListener(`dblclick`,()=>{this.linkService.eventBus?.dispatch(`switchannotationeditormode`,{source:this,mode:e,editId:t,mustEnterInEditMode:!0})})}get width(){return this.data.rect[2]-this.data.rect[0]}get height(){return this.data.rect[3]-this.data.rect[1]}}class or extends ar{constructor(e,t=null){super(e,{isRenderable:!0,ignoreBorder:!!t?.ignoreBorder,createQuadrilaterals:!0});this.isTooltipOnly=e.data.isTooltipOnly}render(){let{data:e,linkService:t}=this,n=document.createElement(`a`);n.setAttribute(`data-element-id`,e.id);let r=!1;if(e.url){t.addLinkAttributes(n,e.url,e.newWindow);r=!0}else if(e.action){this._bindNamedAction(n,e.action,e.overlaidText);r=!0}else if(e.attachment){this.#t(n,e.attachment,e.overlaidText,e.attachmentDest);r=!0}else if(e.setOCGState){this.#n(n,e.setOCGState,e.overlaidText);r=!0}else if(e.dest){this._bindLink(n,e.dest,e.overlaidText);r=!0}else{if(e.actions&&(e.actions.Action||e.actions[`Mouse Up`]||e.actions[`Mouse Down`])&&this.enableScripting&&this.hasJSActions){this._bindJSAction(n,e);r=!0}if(e.resetForm){this._bindResetFormAction(n,e.resetForm);r=!0}else if(this.isTooltipOnly&&!r){this._bindLink(n,``);r=!0}}this.container.classList.add(`linkAnnotation`);if(r){this.contentElement=n;this.container.append(n)}return this.container}#e(){this.container.setAttribute(`data-internal-link`,``)}_bindLink(e,t,n=``){e.href=this.linkService.getDestinationHash(t);e.onclick=()=>{t&&this.linkService.goToDestination(t);return!1};(t||t===``)&&this.#e();n&&(e.title=n)}_bindNamedAction(e,t,n=``){e.href=this.linkService.getAnchorUrl(``);e.onclick=()=>{this.linkService.executeNamedAction(t);return!1};n&&(e.title=n);this.#e()}#t(e,t,n=``,r=null){e.href=this.linkService.getAnchorUrl(``);t.description?e.title=t.description:n&&(e.title=n);e.onclick=()=>{this.downloadManager?.openOrDownloadData(t.content,t.filename,r);return!1};this.#e()}#n(e,t,n=``){e.href=this.linkService.getAnchorUrl(``);e.onclick=()=>{this.linkService.executeSetOCGState(t);return!1};n&&(e.title=n);this.#e()}_bindJSAction(e,t){e.href=this.linkService.getAnchorUrl(``);let n=new Map([[`Action`,`onclick`],[`Mouse Up`,`onmouseup`],[`Mouse Down`,`onmousedown`]]);for(let r of Object.keys(t.actions)){let i=n.get(r);i&&(e[i]=()=>{this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:t.id,name:r}});return!1})}t.overlaidText&&(e.title=t.overlaidText);e.onclick||=()=>!1;this.#e()}_bindResetFormAction(e,t){let n=e.onclick;n||(e.href=this.linkService.getAnchorUrl(``));this.#e();if(this._fieldObjects)e.onclick=()=>{n?.();let{fields:e,refs:r,include:i}=t,a=[];if(e.length!==0||r.length!==0){let t=new Set(r);for(let n of e){let e=this._fieldObjects[n]||[];for(let{id:n}of e)t.add(n)}for(let e of Object.values(this._fieldObjects))for(let n of e)t.has(n.id)===i&&a.push(n)}else for(let e of Object.values(this._fieldObjects))a.push(...e);let o=this.annotationStorage,s=[];for(let e of a){let{id:t}=e;s.push(t);switch(e.type){case`text`:{let n=e.defaultValue||``;o.setValue(t,{value:n});break}case`checkbox`:case`radiobutton`:{let n=e.defaultValue===e.exportValues;o.setValue(t,{value:n});break}case`combobox`:case`listbox`:{let n=e.defaultValue||``;o.setValue(t,{value:n});break}default:continue}let n=document.querySelector(`[data-element-id="${t}"]`);n&&(ir.has(n)?n.dispatchEvent(new Event(`resetform`)):E(`_bindResetFormAction - element not allowed: ${t}`))}this.enableScripting&&this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:`app`,ids:s,name:`ResetForm`}});return!1};else{E('_bindResetFormAction - "resetForm" action not supported, ensure that the `fieldObjects` parameter is provided.');n||(e.onclick=()=>!1)}}}class sr extends ar{render(){return this.container}showElementAndHideCanvas(e){if(this.data.hasOwnCanvas){e.previousSibling?.nodeName===`CANVAS`&&(e.previousSibling.hidden=!0);e.hidden=!1}}_getKeyModifier(e){return N.platform.isMac?e.metaKey:e.ctrlKey}_setEventListener(e,t,n,r,i){n.includes(`mouse`)?e.addEventListener(n,e=>{this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:this.data.id,name:r,value:i(e),shift:e.shiftKey,modifier:this._getKeyModifier(e)}})}):e.addEventListener(n,e=>{if(n===`blur`){if(!t.focused||!e.relatedTarget)return;t.focused=!1}else if(n===`focus`){if(t.focused)return;t.focused=!0}i&&this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:this.data.id,name:r,value:i(e)}})})}_setEventListeners(e,t,n,r){for(let[i,a]of n)if(a===`Action`||this.data.actions?.[a]){a!==`Focus`&&a!==`Blur`||(t||={focused:!1});this._setEventListener(e,t,i,a,r);a!==`Focus`||this.data.actions?.Blur?a!==`Blur`||this.data.actions?.Focus||this._setEventListener(e,t,`focus`,`Focus`,null):this._setEventListener(e,t,`blur`,`Blur`,null)}}_setBackgroundColor(e){let t=this.data.backgroundColor||null;e.style.backgroundColor=t===null?`transparent`:P.makeHexColor(...t)}_setTextStyle(e){let t=[`left`,`center`,`right`],{fontColor:n}=this.data.defaultAppearanceData,r=this.data.defaultAppearanceData.fontSize||9,i=e.style,a,o=e=>Math.round(10*e)/10;if(this.data.multiLine){let e=Math.abs(this.data.rect[3]-this.data.rect[1]-2),t=e/(Math.round(e/(p*r))||1);a=Math.min(r,o(t/p))}else{let e=Math.abs(this.data.rect[3]-this.data.rect[1]-2);a=Math.min(r,o(e/p))}i.fontSize=`calc(${a}px * var(--total-scale-factor))`;i.color=P.makeHexColor(...n);this.data.textAlignment!==null&&(i.textAlign=t[this.data.textAlignment])}_setRequired(e,t){t?e.setAttribute(`required`,!0):e.removeAttribute(`required`);e.setAttribute(`aria-required`,t)}}class cr extends sr{constructor(e){super(e,{isRenderable:e.renderForms})}render(){this.container.classList.add(`buttonWidgetAnnotation`,`radioButton`);let e=this.annotationStorage,t=this.data,n=t.id,r=e.getValue(n,{value:t.fieldValue===t.buttonValue}).value;if(typeof r==`string`){r=r!==t.buttonValue;e.setValue(n,{value:r})}if(r)for(let r of this._getElementsByName(t.fieldName,n))e.setValue(r.id,{value:!1});let i=document.createElement(`input`);ir.add(i);i.setAttribute(`data-element-id`,n);i.disabled=t.readOnly;this._setRequired(i,this.data.required);i.type=`radio`;i.name=t.fieldName;r&&i.setAttribute(`checked`,!0);i.tabIndex=0;i.addEventListener(`change`,t=>{let{name:r,checked:i}=t.target;for(let t of this._getElementsByName(r,n))e.setValue(t.id,{value:!1});e.setValue(n,{value:i})});i.addEventListener(`resetform`,e=>{let n=t.defaultFieldValue;e.target.checked=n!=null&&n===t.buttonValue});if(this.enableScripting&&this.hasJSActions){let r=t.buttonValue;i.addEventListener(`updatefromsandbox`,t=>{this._dispatchEventFromSandbox({value:t=>{let i=r===t.detail.value;for(let r of this._getElementsByName(t.target.name)){let t=i&&r.id===n;r.domElement&&(r.domElement.checked=t);e.setValue(r.id,{value:t})}}},t)});this._setEventListeners(i,null,[[`change`,`Validate`],[`change`,`Action`],[`focus`,`Focus`],[`blur`,`Blur`],[`mousedown`,`Mouse Down`],[`mouseenter`,`Mouse Enter`],[`mouseleave`,`Mouse Exit`],[`mouseup`,`Mouse Up`]],e=>e.target.checked)}this._setBackgroundColor(i);this._setDefaultPropertiesFromJS(i);this.container.append(i);return this.container}}class lr extends ar{constructor(e){let{data:t,elements:n,parent:r}=e,i=!!r._commentManager;super(e,{isRenderable:!i&&ar._hasPopupData(t)});this.elements=n;if(i&&ar._hasPopupData(t)){let e=this.popup=this.#e();for(let t of n)t.popup=e}else this.popup=null}#e(){return new ur({container:this.container,color:this.data.color,titleObj:this.data.titleObj,modificationDate:this.data.modificationDate||this.data.creationDate,contentsObj:this.data.contentsObj,richText:this.data.richText,rect:this.data.rect,parentRect:this.data.parentRect||null,parent:this.parent,elements:this.elements,open:this.data.open,commentManager:this.parent._commentManager})}render(){let{container:e}=this;e.classList.add(`popupAnnotation`);e.role=`comment`;let t=this.popup=this.#e(),n=[];for(let e of this.elements){e.popup=t;e.container.ariaHasPopup=`dialog`;n.push(e.data.id);e.addHighlightArea()}this.container.setAttribute(`aria-controls`,n.map(e=>`${h}${e}`).join(`,`));return this.container}}class ur{#e=null;#t=this.#P.bind(this);#n=this.#R.bind(this);#r=this.#L.bind(this);#i=this.#I.bind(this);#a=null;#o=null;#s=null;#c=null;#l=null;#u=null;#d=null;#f=!1;#p=null;#m=null;#h=null;#g=null;#_=null;#v=null;#y=null;#b=null;#x=null;#S=null;#C=!1;#w=null;#T=null;constructor({container:e,color:t,elements:n,titleObj:r,modificationDate:i,contentsObj:a,richText:o,parent:s,rect:c,parentRect:l,open:u,commentManager:d=null}){this.#o=e;this.#x=r;this.#s=a;this.#b=o;this.#u=s;this.#a=t;this.#y=c;this.#d=l;this.#l=n;this.#e=d;this.#w=n[0];this.#c=xe.toDateObject(i);this.trigger=n.flatMap(e=>e.getElementsToTriggerPopup());if(!d){this.#E();this.#o.hidden=!0;u&&this.#I()}}#E(){if(this.#m)return;this.#m=new AbortController;let{signal:e}=this.#m;for(let t of this.trigger){t.addEventListener(`click`,this.#i,{signal:e});t.addEventListener(`pointerenter`,this.#r,{signal:e});t.addEventListener(`pointerleave`,this.#n,{signal:e});t.classList.add(`popupTriggerArea`)}for(let t of this.#l)t.container?.addEventListener(`keydown`,this.#t,{signal:e})}#D(){let e=this.#l.find(e=>e.hasCommentButton);e&&(this.#_=e._normalizePoint(e.commentButtonPosition))}renderCommentButton(){if(this.#g){this.#g.parentNode||this.#w.container.after(this.#g);return}this.#_||this.#D();if(!this.#_)return;let{signal:e}=this.#m=new AbortController,t=this.#w.hasOwnCommentButton,n=()=>{this.#e.toggleCommentPopup(this,!0,void 0,!t)},r=()=>{this.#e.toggleCommentPopup(this,!1,!0,!t)},i=()=>{this.#e.toggleCommentPopup(this,!1,!1)};if(t){this.#g=this.#w.container;for(let t of this.trigger){t.ariaHasPopup=`dialog`;t.ariaControls=`commentPopup`;t.addEventListener(`keydown`,this.#t,{signal:e});t.addEventListener(`click`,n,{signal:e});t.addEventListener(`pointerenter`,r,{signal:e});t.addEventListener(`pointerleave`,i,{signal:e});t.classList.add(`popupTriggerArea`)}}else{let t=this.#g=document.createElement(`button`);t.className=`annotationCommentButton`;let a=this.#w.container;t.style.zIndex=parseInt(a.style.zIndex,10)+1;t.tabIndex=0;t.ariaHasPopup=`dialog`;t.ariaControls=`commentPopup`;t.setAttribute(`data-l10n-id`,`pdfjs-show-comment-button`);this.#k();this.#O();t.addEventListener(`keydown`,this.#t,{signal:e});t.addEventListener(`click`,n,{signal:e});t.addEventListener(`pointerenter`,r,{signal:e});t.addEventListener(`pointerleave`,i,{signal:e});a.after(t)}}#O(){if(this.#w.extraPopupElement&&!this.#w.editor)return;this.#g||this.renderCommentButton();let[e,t]=this.#_,{style:n}=this.#g;n.left=`calc(${e}%)`;n.top=`calc(${t}% - var(--comment-button-dim))`}#k(){if(!this.#w.extraPopupElement){this.#g||this.renderCommentButton();this.#g.style.backgroundColor=this.commentButtonColor||``}}get commentButtonColor(){let{color:e,opacity:t}=this.#w.commentData;return e?this.#u._commentManager.makeCommentColor(e,t):null}focusCommentButton(){setTimeout(()=>{this.#g?.focus()},0)}getData(){let{richText:e,color:t,opacity:n,creationDate:r,modificationDate:i}=this.#w.commentData;return{contentsObj:{str:this.comment},richText:e,color:t,opacity:n,creationDate:r,modificationDate:i}}get elementBeforePopup(){return this.#g}get comment(){this.#T||=this.#w.commentText;return this.#T}set comment(e){e!==this.comment&&(this.#w.commentText=this.#T=e)}focus(){this.#w.container?.focus()}get parentBoundingClientRect(){return this.#w.layer.getBoundingClientRect()}setCommentButtonStates({selected:e,hasPopup:t}){if(this.#g){this.#g.classList.toggle(`selected`,e);this.#g.ariaExpanded=t}}setSelectedCommentButton(e){this.#g.classList.toggle(`selected`,e)}get commentPopupPosition(){if(this.#v)return this.#v;let{x:e,y:t,height:n}=this.#g.getBoundingClientRect(),{x:r,y:i,width:a,height:o}=this.#w.layer.getBoundingClientRect();return[(e-r)/a,(t+n-i)/o]}set commentPopupPosition(e){this.#v=e}hasDefaultPopupPosition(){return this.#v===null}get commentButtonPosition(){return this.#_}get commentButtonWidth(){return this.#g.getBoundingClientRect().width/this.parentBoundingClientRect.width}editComment(e){let[t,n]=this.#v||this.commentButtonPosition.map(e=>e/100),r=this.parentBoundingClientRect,{x:i,y:a,width:o,height:s}=r;this.#e.showDialog(null,this,i+t*o,a+n*s,{...e,parentDimensions:r})}render(){if(this.#p)return;let e=this.#p=document.createElement(`div`);e.className=`popup`;if(this.#a){let t=e.style.outlineColor=P.makeHexColor(...this.#a);e.style.backgroundColor=`color-mix(in srgb, ${t} 30%, white)`}let t=document.createElement(`span`);t.className=`header`;if(this.#x?.str){let e=document.createElement(`span`);e.className=`title`;t.append(e);({dir:e.dir,str:e.textContent}=this.#x)}e.append(t);if(this.#c){let e=document.createElement(`time`);e.className=`popupDate`;e.setAttribute(`data-l10n-id`,`pdfjs-annotation-date-time-string`);e.setAttribute(`data-l10n-args`,JSON.stringify({dateObj:this.#c.valueOf()}));e.dateTime=this.#c.toISOString();t.append(e)}Oe({html:this.#A||this.#s.str,dir:this.#s?.dir,className:`popupContent`},e);this.#o.append(e)}get#A(){let e=this.#b,t=this.#s;return!e?.str||t?.str&&t.str!==e.str?null:this.#b.html||null}get#j(){return this.#A?.attributes?.style?.fontSize||0}get#M(){return this.#A?.attributes?.style?.color||null}#N(e){let t=[],n={str:e,html:{name:`div`,attributes:{dir:`auto`},children:[{name:`p`,children:t}]}},r={style:{color:this.#M,fontSize:this.#j?`calc(${this.#j}px * var(--total-scale-factor))`:``}};for(let n of e.split(`
|
|
49
|
+
`))t.push({name:`span`,value:n,attributes:r});return n}#P(e){e.altKey||e.shiftKey||e.ctrlKey||e.metaKey||(e.key===`Enter`||e.key===`Escape`&&this.#f)&&this.#I()}updateEdited({rect:e,popup:t,deleted:n}){if(this.#e){if(n){this.remove();this.#T=null}else if(t){if(t.deleted)this.remove();else{this.#k();this.#T=t.text}}if(e){this.#_=null;this.#D();this.#O()}}else if(n||t?.deleted)this.remove();else{this.#E();this.#S||={contentsObj:this.#s,richText:this.#b};e&&(this.#h=null);if(t&&t.text){this.#b=this.#N(t.text);this.#c=xe.toDateObject(t.date);this.#s=null}this.#p?.remove();this.#p=null}}resetEdited(){if(this.#S){({contentsObj:this.#s,richText:this.#b}=this.#S);this.#S=null;this.#p?.remove();this.#p=null;this.#h=null}}remove(){this.#m?.abort();this.#m=null;this.#p?.remove();this.#p=null;this.#C=!1;this.#f=!1;this.#g?.remove();this.#g=null;if(this.trigger)for(let e of this.trigger)e.classList.remove(`popupTriggerArea`)}#F(){if(this.#h!==null)return;let{page:{view:e},viewport:{rawDims:{pageWidth:t,pageHeight:n,pageX:r,pageY:i}}}=this.#u,a=!!this.#d,o=a?this.#d:this.#y;for(let e of this.#l)if(!o||P.intersect(e.data.rect,o)!==null){o=e.data.rect;a=!0;break}let s=P.normalizeRect([o[0],e[3]-o[1]+e[1],o[2],e[3]-o[3]+e[1]]),c=a?o[2]-o[0]+5:0,l=s[0]+c,u=s[1];this.#h=[100*(l-r)/t,100*(u-i)/n];let{style:d}=this.#o;d.left=`${this.#h[0]}%`;d.top=`${this.#h[1]}%`}#I(){if(this.#e)this.#e.toggleCommentPopup(this,!1);else{this.#f=!this.#f;if(this.#f){this.#L();this.#o.addEventListener(`click`,this.#i);this.#o.addEventListener(`keydown`,this.#t)}else{this.#R();this.#o.removeEventListener(`click`,this.#i);this.#o.removeEventListener(`keydown`,this.#t)}}}#L(){this.#p||this.render();if(this.isVisible)this.#f&&this.#o.classList.add(`focused`);else{this.#F();this.#o.hidden=!1;this.#o.style.zIndex=parseInt(this.#o.style.zIndex,10)+1e3}}#R(){this.#o.classList.remove(`focused`);if(!this.#f&&this.isVisible){this.#o.hidden=!0;this.#o.style.zIndex=parseInt(this.#o.style.zIndex,10)-1e3}}forceHide(){this.#C=this.isVisible;this.#C&&(this.#o.hidden=!0)}maybeShow(){if(!this.#e){this.#E();if(this.#C){this.#p||this.#L();this.#C=!1;this.#o.hidden=!1}}}get isVisible(){return!this.#e&&!1===this.#o.hidden}}class dr extends ar{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});this.textContent=e.data.textContent;this.textPosition=e.data.textPosition;this.annotationEditorType=_.FREETEXT}render(){this.container.classList.add(`freeTextAnnotation`);if(this.textContent){let e=this.contentElement=document.createElement(`div`);e.classList.add(`annotationTextContent`);e.setAttribute(`role`,`comment`);for(let t of this.textContent){let n=document.createElement(`span`);n.textContent=t;e.append(n)}this.container.append(e)}if(!this.data.popupRef&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}this._editOnDoubleClick();return this.container}}class fr extends ar{#e=null;#t=[];constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});this.containerClassName=`inkAnnotation`;this.svgElementName=`svg:polyline`;this.annotationEditorType=this.data.it===`InkHighlight`?_.HIGHLIGHT:_.INK}#n(e,t){switch(e){case 90:return{transform:`rotate(90) translate(${-t[0]},${t[1]}) scale(1,-1)`,width:t[3]-t[1],height:t[2]-t[0]};case 180:return{transform:`rotate(180) translate(${-t[2]},${t[1]}) scale(1,-1)`,width:t[2]-t[0],height:t[3]-t[1]};case 270:return{transform:`rotate(270) translate(${-t[2]},${t[3]}) scale(1,-1)`,width:t[3]-t[1],height:t[2]-t[0]};default:return{transform:`translate(${-t[0]},${t[3]}) scale(1,-1)`,width:t[2]-t[0],height:t[3]-t[1]}}}render(){this.container.classList.add(this.containerClassName);let{data:{rect:e,rotation:t,inkLists:n,borderStyle:r,popupRef:i}}=this,{transform:a,width:o,height:s}=this.#n(t,e),c=this.svgFactory.create(o,s,!0),l=this.#e=this.svgFactory.createElement(`svg:g`);c.append(l);l.setAttribute(`stroke-width`,r.width||1);l.setAttribute(`stroke-linecap`,`round`);l.setAttribute(`stroke-linejoin`,`round`);l.setAttribute(`stroke-miterlimit`,10);l.setAttribute(`stroke`,`transparent`);l.setAttribute(`fill`,`transparent`);l.setAttribute(`transform`,a);for(let e=0,t=n.length;e<t;e++){let t=this.svgFactory.createElement(this.svgElementName);this.#t.push(t);t.setAttribute(`points`,n[e].join(`,`));l.append(t)}if(!i&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}this.container.append(c);this._editOnDoubleClick();return this.container}updateEdited(e){super.updateEdited(e);let{thickness:t,points:n,rect:r}=e,i=this.#e;t>=0&&i.setAttribute(`stroke-width`,t||1);if(n)for(let e=0,t=this.#t.length;e<t;e++)this.#t[e].setAttribute(`points`,n[e].join(`,`));if(r){let{transform:e,width:t,height:n}=this.#n(this.data.rotation,r);i.parentElement.setAttribute(`viewBox`,`0 0 ${t} ${n}`);i.setAttribute(`transform`,e)}}getElementsToTriggerPopup(){return this.#t}addHighlightArea(){this.container.classList.add(`highlightArea`)}}class pr extends ar{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0});this.annotationEditorType=_.HIGHLIGHT}render(){let{data:{overlaidText:e,popupRef:t}}=this;if(!t&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}this.container.classList.add(`highlightAnnotation`);this._editOnDoubleClick();if(e){let t=document.createElement(`mark`);t.classList.add(`overlaidText`);t.textContent=e;this.container.append(t)}return this.container}}class mr extends ar{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});this.annotationEditorType=_.STAMP}render(){this.container.classList.add(`stampAnnotation`);this.container.setAttribute(`role`,`img`);if(!this.data.popupRef&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}this._editOnDoubleClick();return this.container}}const hr=/\r\n?|\n/g;class X extends H{#e=``;#t=`${this.id}-editor`;#n=null;#r;_colorPicker=null;static _freeTextDefaultContent=``;static _internalPadding=0;static _defaultColor=null;static _defaultFontSize=10;static get _keyboardManager(){let e=X.prototype,t=e=>e.isEmpty(),n=Re.TRANSLATE_SMALL,r=Re.TRANSLATE_BIG;return j(this,`_keyboardManager`,new Ie([[[`ctrl+s`,`mac+meta+s`,`ctrl+p`,`mac+meta+p`],e.commitOrRemove,{bubbles:!0}],[[`ctrl+Enter`,`mac+meta+Enter`,`Escape`,`mac+Escape`],e.commitOrRemove],[[`ArrowLeft`,`mac+ArrowLeft`],e._translateEmpty,{args:[-n,0],checker:t}],[[`ctrl+ArrowLeft`,`mac+shift+ArrowLeft`],e._translateEmpty,{args:[-r,0],checker:t}],[[`ArrowRight`,`mac+ArrowRight`],e._translateEmpty,{args:[n,0],checker:t}],[[`ctrl+ArrowRight`,`mac+shift+ArrowRight`],e._translateEmpty,{args:[r,0],checker:t}],[[`ArrowUp`,`mac+ArrowUp`],e._translateEmpty,{args:[0,-n],checker:t}],[[`ctrl+ArrowUp`,`mac+shift+ArrowUp`],e._translateEmpty,{args:[0,-r],checker:t}],[[`ArrowDown`,`mac+ArrowDown`],e._translateEmpty,{args:[0,n],checker:t}],[[`ctrl+ArrowDown`,`mac+shift+ArrowDown`],e._translateEmpty,{args:[0,r],checker:t}]]))}static _type=`freetext`;static _editorType=_.FREETEXT;constructor(e){super({...e,name:`freeTextEditor`});this.color=e.color||X._defaultColor||H._defaultLineColor;this.#r=e.fontSize||X._defaultFontSize;this.annotationElementId||this._uiManager.a11yAlert(H._l10nAlert.freetext);this.canAddComment=!1}static initialize(e,t){H.initialize(e,t);let n=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(n.getPropertyValue(`--freetext-padding`))}static updateDefaultParams(e,t){switch(e){case v.FREETEXT_SIZE:X._defaultFontSize=t;break;case v.FREETEXT_COLOR:X._defaultColor=t}}updateParams(e,t){switch(e){case v.FREETEXT_SIZE:this.#i(t);break;case v.FREETEXT_COLOR:this.#a(t)}}static get defaultPropertiesToUpdate(){return[[v.FREETEXT_SIZE,X._defaultFontSize],[v.FREETEXT_COLOR,X._defaultColor||H._defaultLineColor]]}get propertiesToUpdate(){return[[v.FREETEXT_SIZE,this.#r],[v.FREETEXT_COLOR,this.color]]}get toolbarButtons(){this._colorPicker||=new er(this);return[[`colorPicker`,this._colorPicker]]}get colorType(){return v.FREETEXT_COLOR}#i(e){let t=e=>{this.editorDiv.style.fontSize=`calc(${e}px * var(--total-scale-factor))`;this.translate(0,-(e-this.#r)*this.parentScale);this.#r=e;this.#s()},n=this.#r;this.addCommands({cmd:t.bind(this,e),undo:t.bind(this,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:v.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})}onUpdatedColor(){this.editorDiv.style.color=this.color;this._colorPicker?.update(this.color);super.onUpdatedColor()}#a(e){let t=e=>{this.color=e;this.onUpdatedColor()},n=this.color;this.addCommands({cmd:t.bind(this,e),undo:t.bind(this,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:v.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})}_translateEmpty(e,t){this._uiManager.translateSelectedEditors(e,t,!0)}getInitialTranslation(){let e=this.parentScale;return[-X._internalPadding*e,-(X._internalPadding+this.#r)*e]}rebuild(){if(this.parent){super.rebuild();this.div!==null&&(this.isAttachedToDOM||this.parent.add(this))}}enableEditMode(){if(!super.enableEditMode())return!1;this.overlayDiv.classList.remove(`enabled`);this.editorDiv.contentEditable=!0;this._isDraggable=!1;this.div.removeAttribute(`aria-activedescendant`);this.#n=new AbortController;let e=this._uiManager.combinedSignal(this.#n);this.editorDiv.addEventListener(`keydown`,this.editorDivKeydown.bind(this),{signal:e});this.editorDiv.addEventListener(`focus`,this.editorDivFocus.bind(this),{signal:e});this.editorDiv.addEventListener(`blur`,this.editorDivBlur.bind(this),{signal:e});this.editorDiv.addEventListener(`input`,this.editorDivInput.bind(this),{signal:e});this.editorDiv.addEventListener(`paste`,this.editorDivPaste.bind(this),{signal:e});return!0}disableEditMode(){if(!super.disableEditMode())return!1;this.overlayDiv.classList.add(`enabled`);this.editorDiv.contentEditable=!1;this.div.setAttribute(`aria-activedescendant`,this.#t);this._isDraggable=!0;this.#n?.abort();this.#n=null;this.div.focus({preventScroll:!0});this.isEditing=!1;this.parent.div.classList.add(`freetextEditing`);return!0}focusin(e){if(this._focusEventsAllowed){super.focusin(e);e.target!==this.editorDiv&&this.editorDiv.focus()}}onceAdded(e){if(!this.width){this.enableEditMode();e&&this.editorDiv.focus();this._initialOptions?.isCentered&&this.center();this._initialOptions=null}}isEmpty(){return!this.editorDiv||this.editorDiv.innerText.trim()===``}remove(){this.isEditing=!1;if(this.parent){this.parent.setEditingState(!0);this.parent.div.classList.add(`freetextEditing`)}super.remove()}#o(){let e=[];this.editorDiv.normalize();let t=null;for(let n of this.editorDiv.childNodes)if(t?.nodeType!==Node.TEXT_NODE||n.nodeName!==`BR`){e.push(X.#c(n));t=n}return e.join(`
|
|
50
|
+
`)}#s(){let[e,t]=this.parentDimensions,n;if(this.isAttachedToDOM)n=this.div.getBoundingClientRect();else{let{currentLayer:e,div:t}=this,r=t.style.display,i=t.classList.contains(`hidden`);t.classList.remove(`hidden`);t.style.display=`hidden`;e.div.append(this.div);n=t.getBoundingClientRect();t.remove();t.style.display=r;t.classList.toggle(`hidden`,i)}if(this.rotation%180==this.parentRotation%180){this.width=n.width/e;this.height=n.height/t}else{this.width=n.height/e;this.height=n.width/t}this.fixAndSetPosition()}commit(){if(!this.isInEditMode())return;super.commit();this.disableEditMode();let e=this.#e,t=this.#e=this.#o().trimEnd();if(e===t)return;let n=e=>{this.#e=e;if(e){this.#l();this._uiManager.rebuild(this);this.#s()}else this.remove()};this.addCommands({cmd:()=>{n(t)},undo:()=>{n(e)},mustExec:!1});this.#s()}shouldGetKeyboardEvents(){return this.isInEditMode()}enterInEditMode(){this.enableEditMode();this.editorDiv.focus()}keydown(e){if(e.target===this.div&&e.key===`Enter`){this.enterInEditMode();e.preventDefault()}}editorDivKeydown(e){X._keyboardManager.exec(this,e)}editorDivFocus(e){this.isEditing=!0}editorDivBlur(e){this.isEditing=!1}editorDivInput(e){this.parent.div.classList.toggle(`freetextEditing`,this.isEmpty())}disableEditing(){this.editorDiv.setAttribute(`role`,`comment`);this.editorDiv.removeAttribute(`aria-multiline`)}enableEditing(){this.editorDiv.setAttribute(`role`,`textbox`);this.editorDiv.setAttribute(`aria-multiline`,!0)}get canChangeContent(){return!0}render(){if(this.div)return this.div;let e,t;if(this._isCopy||this.annotationElementId){e=this.x;t=this.y}super.render();this.editorDiv=document.createElement(`div`);this.editorDiv.className=`internal`;this.editorDiv.setAttribute(`id`,this.#t);this.editorDiv.setAttribute(`data-l10n-id`,`pdfjs-free-text2`);this.editorDiv.setAttribute(`data-l10n-attrs`,`default-content`);this.enableEditing();this.editorDiv.contentEditable=!0;let{style:n}=this.editorDiv;n.fontSize=`calc(${this.#r}px * var(--total-scale-factor))`;n.color=this.color;this.div.append(this.editorDiv);this.overlayDiv=document.createElement(`div`);this.overlayDiv.classList.add(`overlay`,`enabled`);this.div.append(this.overlayDiv);if(this._isCopy||this.annotationElementId){let[n,r]=this.parentDimensions;if(this.annotationElementId){let{position:i}=this._initialData,[a,o]=this.getInitialTranslation();[a,o]=this.pageTranslationToScreen(a,o);let[s,c]=this.pageDimensions,[l,u]=this.pageTranslation,d,f;switch(this.rotation){case 0:d=e+(i[0]-l)/s;f=t+this.height-(i[1]-u)/c;break;case 90:d=e+(i[0]-l)/s;f=t-(i[1]-u)/c;[a,o]=[o,-a];break;case 180:d=e-this.width+(i[0]-l)/s;f=t-(i[1]-u)/c;[a,o]=[-a,-o];break;case 270:d=e+(i[0]-l-this.height*c)/s;f=t+(i[1]-u-this.width*s)/c;[a,o]=[-o,a]}this.setAt(d*n,f*r,a,o)}else this._moveAfterPaste(e,t);this.#l();this._isDraggable=!0;this.editorDiv.contentEditable=!1}else{this._isDraggable=!1;this.editorDiv.contentEditable=!0}return this.div}static#c(e){return(e.nodeType===Node.TEXT_NODE?e.nodeValue:e.innerText).replaceAll(hr,``)}editorDivPaste(e){let t=e.clipboardData||window.clipboardData,{types:n}=t;if(n.length===1&&n[0]===`text/plain`)return;e.preventDefault();let r=X.#d(t.getData(`text`)||``).replaceAll(hr,`
|
|
51
51
|
`);if(!r)return;let i=window.getSelection();if(!i.rangeCount)return;this.editorDiv.normalize();i.deleteFromDocument();let a=i.getRangeAt(0);if(!r.includes(`
|
|
52
|
-
`)){a.insertNode(document.createTextNode(r));this.editorDiv.normalize();i.collapseToStart();return}let{startContainer:o,startOffset:s}=a,c=[],l=[];if(o.nodeType===Node.TEXT_NODE){let e=o.parentElement;l.push(o.nodeValue.slice(s).replaceAll(
|
|
52
|
+
`)){a.insertNode(document.createTextNode(r));this.editorDiv.normalize();i.collapseToStart();return}let{startContainer:o,startOffset:s}=a,c=[],l=[];if(o.nodeType===Node.TEXT_NODE){let e=o.parentElement;l.push(o.nodeValue.slice(s).replaceAll(hr,``));if(e!==this.editorDiv){let t=c;for(let n of this.editorDiv.childNodes)n===e?t=l:t.push(X.#c(n))}c.push(o.nodeValue.slice(0,s).replaceAll(hr,``))}else if(o===this.editorDiv){let e=c,t=0;for(let n of this.editorDiv.childNodes){t++===s&&(e=l);e.push(X.#c(n))}}this.#e=`${c.join(`
|
|
53
53
|
`)}${r}${l.join(`
|
|
54
54
|
`)}`;this.#l();let u=new Range,d=Math.sumPrecise(c.map(e=>e.length));for(let{firstChild:e}of this.editorDiv.childNodes)if(e.nodeType===Node.TEXT_NODE){let t=e.nodeValue.length;if(d<=t){u.setStart(e,d);u.setEnd(e,d);break}d-=t}i.removeAllRanges();i.addRange(u)}#l(){this.editorDiv.replaceChildren();if(this.#e)for(let e of this.#e.split(`
|
|
55
|
-
`)){let t=document.createElement(`div`);t.append(e?document.createTextNode(e):document.createElement(`br`));this.editorDiv.append(t)}}#u(){return this.#e.replaceAll(`\xA0`,` `)}static#d(e){return e.replaceAll(` `,`\xA0`)}get contentDiv(){return this.editorDiv}getPDFRect(){let e=X._internalPadding*this.parentScale;return this.getRect(e,e)}static async deserialize(e,t,n){let r=null;if(e instanceof
|
|
56
|
-
`),position:p,pageIndex:m-1,rect:i.slice(0),rotation:a,annotationElementId:o,id:o,deleted:!1,popupRef:s,comment:l?.str||null,richText:c,creationDate:u,modificationDate:d}}let i=await super.deserialize(e,t,n);i.#r=e.fontSize;i.color=P.makeHexColor(...e.color);i.#e=X.#d(e.value);i._initialData=r;e.comment&&i.setCommentData(e);return i}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let t=
|
|
57
|
-
`)){let n=document.createElement(`div`);n.append(e?document.createTextNode(e):document.createElement(`br`));t.append(n)}e.updateEdited({rect:this.getPDFRect(),popup:this._uiManager.hasCommentManager()||this.hasEditedComment?this.comment:{text:this.#e}});return t}resetAnnotationElement(e){super.resetAnnotationElement(e);e.resetEdited()}}class Z{static PRECISION=1e-4;toSVGPath(){k("Abstract method `toSVGPath` must be implemented.")}get box(){k("Abstract getter `box` must be implemented.")}serialize(e,t){k("Abstract method `serialize` must be implemented.")}static _rescale(e,t,n,r,i,a){a||=new Float32Array(e.length);for(let o=0,s=e.length;o<s;o+=2){a[o]=t+e[o]*r;a[o+1]=n+e[o+1]*i}return a}static _rescaleAndSwap(e,t,n,r,i,a){a||=new Float32Array(e.length);for(let o=0,s=e.length;o<s;o+=2){a[o]=t+e[o+1]*r;a[o+1]=n+e[o]*i}return a}static _translate(e,t,n,r){r||=new Float32Array(e.length);for(let i=0,a=e.length;i<a;i+=2){r[i]=t+e[i];r[i+1]=n+e[i+1]}return r}static svgRound(e){return Math.round(1e4*e)}static _normalizePoint(e,t,n,r,i){switch(i){case 90:return[1-t/n,e/r];case 180:return[1-e/n,1-t/r];case 270:return[t/n,1-e/r];default:return[e/n,t/r]}}static _normalizePagePoint(e,t,n){switch(n){case 90:return[1-t,e];case 180:return[1-e,1-t];case 270:return[t,1-e];default:return[e,t]}}static createBezierPoints(e,t,n,r,i,a){return[(e+5*n)/6,(t+5*r)/6,(5*n+i)/6,(5*r+a)/6,(n+i)/2,(r+a)/2]}}class vr{#e;#t=[];#n;#r;#i=[];#a=new Float32Array(18);#o;#s;#c;#l;#u;#d;#f=[];static#p=8;static#m=2;static#h=vr.#p+vr.#m;constructor({x:e,y:t},n,r,i,a,o=0){this.#e=n;this.#d=i*r;this.#r=a;this.#a.set([NaN,NaN,NaN,NaN,e,t],6);this.#n=o;this.#l=vr.#p*r;this.#c=vr.#h*r;this.#u=r;this.#f.push(e,t)}isEmpty(){return isNaN(this.#a[8])}#g(){let e=this.#a.subarray(4,6),t=this.#a.subarray(16,18),[n,r,i,a]=this.#e;return[(this.#o+(e[0]-t[0])/2-n)/i,(this.#s+(e[1]-t[1])/2-r)/a,(this.#o+(t[0]-e[0])/2-n)/i,(this.#s+(t[1]-e[1])/2-r)/a]}add({x:e,y:t}){this.#o=e;this.#s=t;let[n,r,i,a]=this.#e,[o,s,c,l]=this.#a.subarray(8,12),u=e-c,d=t-l,f=Math.hypot(u,d);if(f<this.#c)return!1;let p=f-this.#l,m=p/f,h=m*u,g=m*d,_=o,v=s;o=c;s=l;c+=h;l+=g;this.#f?.push(e,t);let y=h/p,b=-g/p*this.#d,x=y*this.#d;this.#a.set(this.#a.subarray(2,8),0);this.#a.set([c+b,l+x],4);this.#a.set(this.#a.subarray(14,18),12);this.#a.set([c-b,l-x],16);if(isNaN(this.#a[6])){if(this.#i.length===0){this.#a.set([o+b,s+x],2);this.#i.push(NaN,NaN,NaN,NaN,(o+b-n)/i,(s+x-r)/a);this.#a.set([o-b,s-x],14);this.#t.push(NaN,NaN,NaN,NaN,(o-b-n)/i,(s-x-r)/a)}this.#a.set([_,v,o,s,c,l],6);return!this.isEmpty()}this.#a.set([_,v,o,s,c,l],6);if(Math.abs(Math.atan2(v-s,_-o)-Math.atan2(g,h))<Math.PI/2){[o,s,c,l]=this.#a.subarray(2,6);this.#i.push(NaN,NaN,NaN,NaN,((o+c)/2-n)/i,((s+l)/2-r)/a);[o,s,_,v]=this.#a.subarray(14,18);this.#t.push(NaN,NaN,NaN,NaN,((_+o)/2-n)/i,((v+s)/2-r)/a);return!0}[_,v,o,s,c,l]=this.#a.subarray(0,6);this.#i.push(((_+5*o)/6-n)/i,((v+5*s)/6-r)/a,((5*o+c)/6-n)/i,((5*s+l)/6-r)/a,((o+c)/2-n)/i,((s+l)/2-r)/a);[c,l,o,s,_,v]=this.#a.subarray(12,18);this.#t.push(((_+5*o)/6-n)/i,((v+5*s)/6-r)/a,((5*o+c)/6-n)/i,((5*s+l)/6-r)/a,((o+c)/2-n)/i,((s+l)/2-r)/a);return!0}toSVGPath(){if(this.isEmpty())return``;let e=this.#i,t=this.#t;if(isNaN(this.#a[6])&&!this.isEmpty())return this.#_();let n=[];n.push(`M${e[4]} ${e[5]}`);for(let t=6;t<e.length;t+=6)isNaN(e[t])?n.push(`L${e[t+4]} ${e[t+5]}`):n.push(`C${e[t]} ${e[t+1]} ${e[t+2]} ${e[t+3]} ${e[t+4]} ${e[t+5]}`);this.#y(n);for(let e=t.length-6;e>=6;e-=6)isNaN(t[e])?n.push(`L${t[e+4]} ${t[e+5]}`):n.push(`C${t[e]} ${t[e+1]} ${t[e+2]} ${t[e+3]} ${t[e+4]} ${t[e+5]}`);this.#v(n);return n.join(` `)}#_(){let[e,t,n,r]=this.#e,[i,a,o,s]=this.#g();return`M${(this.#a[2]-e)/n} ${(this.#a[3]-t)/r} L${(this.#a[4]-e)/n} ${(this.#a[5]-t)/r} L${i} ${a} L${o} ${s} L${(this.#a[16]-e)/n} ${(this.#a[17]-t)/r} L${(this.#a[14]-e)/n} ${(this.#a[15]-t)/r} Z`}#v(e){let t=this.#t;e.push(`L${t[4]} ${t[5]} Z`)}#y(e){let[t,n,r,i]=this.#e,a=this.#a.subarray(4,6),o=this.#a.subarray(16,18),[s,c,l,u]=this.#g();e.push(`L${(a[0]-t)/r} ${(a[1]-n)/i} L${s} ${c} L${l} ${u} L${(o[0]-t)/r} ${(o[1]-n)/i}`)}newFreeDrawOutline(e,t,n,r,i,a){return new yr(e,t,n,r,i,a)}getOutlines(){let e=this.#i,t=this.#t,n=this.#a,[r,i,a,o]=this.#e,s=new Float32Array((this.#f?.length??0)+2);for(let e=0,t=s.length-2;e<t;e+=2){s[e]=(this.#f[e]-r)/a;s[e+1]=(this.#f[e+1]-i)/o}s[s.length-2]=(this.#o-r)/a;s[s.length-1]=(this.#s-i)/o;if(isNaN(n[6])&&!this.isEmpty())return this.#b(s);let c=new Float32Array(this.#i.length+24+this.#t.length),l=e.length;for(let t=0;t<l;t+=2)if(isNaN(e[t]))c[t]=c[t+1]=NaN;else{c[t]=e[t];c[t+1]=e[t+1]}l=this.#S(c,l);for(let e=t.length-6;e>=6;e-=6)for(let n=0;n<6;n+=2)if(isNaN(t[e+n])){c[l]=c[l+1]=NaN;l+=2}else{c[l]=t[e+n];c[l+1]=t[e+n+1];l+=2}this.#x(c,l);return this.newFreeDrawOutline(c,s,this.#e,this.#u,this.#n,this.#r)}#b(e){let t=this.#a,[n,r,i,a]=this.#e,[o,s,c,l]=this.#g(),u=new Float32Array(36);u.set([NaN,NaN,NaN,NaN,(t[2]-n)/i,(t[3]-r)/a,NaN,NaN,NaN,NaN,(t[4]-n)/i,(t[5]-r)/a,NaN,NaN,NaN,NaN,o,s,NaN,NaN,NaN,NaN,c,l,NaN,NaN,NaN,NaN,(t[16]-n)/i,(t[17]-r)/a,NaN,NaN,NaN,NaN,(t[14]-n)/i,(t[15]-r)/a],0);return this.newFreeDrawOutline(u,e,this.#e,this.#u,this.#n,this.#r)}#x(e,t){let n=this.#t;e.set([NaN,NaN,NaN,NaN,n[4],n[5]],t);return t+6}#S(e,t){let n=this.#a.subarray(4,6),r=this.#a.subarray(16,18),[i,a,o,s]=this.#e,[c,l,u,d]=this.#g();e.set([NaN,NaN,NaN,NaN,(n[0]-i)/o,(n[1]-a)/s,NaN,NaN,NaN,NaN,c,l,NaN,NaN,NaN,NaN,u,d,NaN,NaN,NaN,NaN,(r[0]-i)/o,(r[1]-a)/s],t);return t+24}}class yr extends Z{#e;#t=new Float32Array(4);#n;#r;#i;#a;#o;constructor(e,t,n,r,i,a){super();this.#o=e;this.#i=t;this.#e=n;this.#a=r;this.#n=i;this.#r=a;this.firstPoint=[NaN,NaN];this.lastPoint=[NaN,NaN];this.#s(a);let[o,s,c,l]=this.#t;for(let t=0,n=e.length;t<n;t+=2){e[t]=(e[t]-o)/c;e[t+1]=(e[t+1]-s)/l}for(let e=0,n=t.length;e<n;e+=2){t[e]=(t[e]-o)/c;t[e+1]=(t[e+1]-s)/l}}toSVGPath(){let e=[`M${this.#o[4]} ${this.#o[5]}`];for(let t=6,n=this.#o.length;t<n;t+=6)isNaN(this.#o[t])?e.push(`L${this.#o[t+4]} ${this.#o[t+5]}`):e.push(`C${this.#o[t]} ${this.#o[t+1]} ${this.#o[t+2]} ${this.#o[t+3]} ${this.#o[t+4]} ${this.#o[t+5]}`);e.push(`Z`);return e.join(` `)}serialize([e,t,n,r],i){let a=n-e,o=r-t,s,c;switch(i){case 0:s=Z._rescale(this.#o,e,r,a,-o);c=Z._rescale(this.#i,e,r,a,-o);break;case 90:s=Z._rescaleAndSwap(this.#o,e,t,a,o);c=Z._rescaleAndSwap(this.#i,e,t,a,o);break;case 180:s=Z._rescale(this.#o,n,t,-a,o);c=Z._rescale(this.#i,n,t,-a,o);break;case 270:s=Z._rescaleAndSwap(this.#o,n,r,-a,-o);c=Z._rescaleAndSwap(this.#i,n,r,-a,-o)}return{outline:Array.from(s),points:[Array.from(c)]}}#s(e){let t=this.#o,n=t[4],r=t[5],i=[n,r,n,r],a=n,o=r,s=n,c=r,l=e?Math.max:Math.min,u=new Float32Array(4);for(let e=6,d=t.length;e<d;e+=6){let d=t[e+4],p=t[e+5];if(isNaN(t[e])){P.pointBoundingBox(d,p,i);if(o>p){a=d;o=p}else o===p&&(a=l(a,d));if(c<p){s=d;c=p}else c===p&&(s=l(s,d))}else{u.set(f,0);P.bezierBoundingBox(n,r,...t.slice(e,e+6),u);P.rectBoundingBox(...u,i);if(o>u[1]){a=u[0];o=u[1]}else o===u[1]&&(a=l(a,u[0]));if(c<u[3]){s=u[2];c=u[3]}else c===u[3]&&(s=l(s,u[2]))}n=d;r=p}let d=this.#t;d[0]=i[0]-this.#n;d[1]=i[1]-this.#n;d[2]=i[2]-i[0]+2*this.#n;d[3]=i[3]-i[1]+2*this.#n;this.firstPoint=[a,o];this.lastPoint=[s,c]}get box(){return this.#t}newOutliner(e,t,n,r,i,a=0){return new vr(e,t,n,r,i,a)}getNewOutline(e,t){let[n,r,i,a]=this.#t,[o,s,c,l]=this.#e,u=i*c,d=a*l,f=n*c+o,p=r*l+s,m=this.newOutliner({x:this.#i[0]*u+f,y:this.#i[1]*d+p},this.#e,this.#a,e,this.#r,t??this.#n);for(let e=2;e<this.#i.length;e+=2)m.add({x:this.#i[e]*u+f,y:this.#i[e+1]*d+p});return m.getOutlines()}}class br{#e;#t;#n;#r=[];#i=[];constructor(e,t=0,n=0,r=!0){let i=f.slice(),a=1e-4;for(let{x:n,y:r,width:o,height:s}of e){let e=Math.floor((n-t)/a)*a,c=Math.ceil((n+o+t)/a)*a,l=Math.floor((r-t)/a)*a,u=Math.ceil((r+s+t)/a)*a,d=[e,l,u,!0],f=[c,l,u,!1];this.#r.push(d,f);P.rectBoundingBox(e,l,c,u,i)}let o=i[2]-i[0]+2*n,s=i[3]-i[1]+2*n,c=i[0]-n,l=i[1]-n,u=r?-1/0:1/0,d=1/0,p=this.#r.at(r?-1:-2),m=[p[0],p[2]];for(let e of this.#r){let[t,n,i,a]=e;if(!a&&r){if(n<d){d=n;u=t}else n===d&&(u=Math.max(u,t))}else if(a&&!r){if(n<d){d=n;u=t}else n===d&&(u=Math.min(u,t))}e[0]=(t-c)/o;e[1]=(n-l)/s;e[2]=(i-l)/s}this.#e=new Float32Array([c,l,o,s]);this.#t=[u,d];this.#n=m}getOutlines(){this.#r.sort((e,t)=>e[0]-t[0]||e[1]-t[1]||e[2]-t[2]);let e=[];for(let t of this.#r)if(t[3]){e.push(...this.#l(t));this.#s(t)}else{this.#c(t);e.push(...this.#l(t))}return this.#a(e)}#a(e){let t=[],n=new Set;for(let n of e){let[e,r,i]=n;t.push([e,r,n],[e,i,n])}t.sort((e,t)=>e[1]-t[1]||e[0]-t[0]);for(let e=0,r=t.length;e<r;e+=2){let r=t[e][2],i=t[e+1][2];r.push(i);i.push(r);n.add(r);n.add(i)}let r=[],i;for(;n.size>0;){let e=n.values().next().value,[t,a,o,s,c]=e;n.delete(e);let l=t,u=a;i=[t,o];r.push(i);for(;;){let e;if(n.has(s))e=s;else{if(!n.has(c))break;e=c}n.delete(e);[t,a,o,s,c]=e;if(l!==t){i.push(l,u,t,u===a?a:o);l=t}u=u===a?o:a}i.push(l,u)}return new xr(r,this.#e,this.#t,this.#n)}#o(e){let t=this.#i,n=0,r=t.length-1;for(;n<=r;){let i=n+r>>1,a=t[i][0];if(a===e)return i;a<e?n=i+1:r=i-1}return r+1}#s([,e,t]){let n=this.#o(e);this.#i.splice(n,0,[e,t])}#c([,e,t]){let n=this.#o(e);for(let r=n;r<this.#i.length;r++){let[n,i]=this.#i[r];if(n!==e)break;if(n===e&&i===t){this.#i.splice(r,1);return}}for(let r=n-1;r>=0;r--){let[n,i]=this.#i[r];if(n!==e)break;if(n===e&&i===t){this.#i.splice(r,1);return}}}#l(e){let[t,n,r]=e,i=[[t,n,r]],a=this.#o(r);for(let e=0;e<a;e++){let[n,r]=this.#i[e];for(let e=0,a=i.length;e<a;e++){let[,o,s]=i[e];if(!(r<=o||s<=n)){if(o>=n){if(s>r)i[e][1]=r;else{if(a===1)return[];i.splice(e,1);e--;a--}}else{i[e][2]=n;s>r&&i.push([t,r,s])}}}}return i}}class xr extends Z{#e;#t;constructor(e,t,n,r){super();this.#t=e;this.#e=t;this.firstPoint=n;this.lastPoint=r}toSVGPath(){let e=[];for(let t of this.#t){let[n,r]=t;e.push(`M${n} ${r}`);for(let i=2;i<t.length;i+=2){let a=t[i],o=t[i+1];if(a===n){e.push(`V${o}`);r=o}else if(o===r){e.push(`H${a}`);n=a}}e.push(`Z`)}return e.join(` `)}serialize([e,t,n,r],i){let a=[],o=n-e,s=r-t;for(let t of this.#t){let n=Array(t.length);for(let i=0;i<t.length;i+=2){n[i]=e+t[i]*o;n[i+1]=r-t[i+1]*s}a.push(n)}return a}get box(){return this.#e}get classNamesForOutlining(){return[`highlightOutline`]}}class Sr extends vr{newFreeDrawOutline(e,t,n,r,i,a){return new Cr(e,t,n,r,i,a)}}class Cr extends yr{newOutliner(e,t,n,r,i,a=0){return new Sr(e,t,n,r,i,a)}}class Q extends V{#e=null;#t=0;#n;#r=null;#i=null;#a=null;#o=null;#s=0;#c=null;#l=null;#u=null;#d=!1;#f=null;#p=null;#m=null;#h=``;#g;#_=``;static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type=`highlight`;static _editorType=y.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId=``;static get _keyboardManager(){let e=Q.prototype;return j(this,`_keyboardManager`,new ze([[[`ArrowLeft`,`mac+ArrowLeft`],e._moveCaret,{args:[0]}],[[`ArrowRight`,`mac+ArrowRight`],e._moveCaret,{args:[1]}],[[`ArrowUp`,`mac+ArrowUp`],e._moveCaret,{args:[2]}],[[`ArrowDown`,`mac+ArrowDown`],e._moveCaret,{args:[3]}]]))}constructor(e){super({...e,name:`highlightEditor`});this.color=e.color||Q._defaultColor;this.#g=e.thickness||Q._defaultThickness;this.opacity=e.opacity||Q._defaultOpacity;this.#n=e.boxes||null;this.#_=e.methodOfCreation||``;this.#h=e.text||``;this._isDraggable=!1;this.defaultL10nId=`pdfjs-editor-highlight-editor`;if(e.highlightId>-1){this.#d=!0;this.#y(e);this.#w()}else if(this.#n){this.#e=e.anchorNode;this.#t=e.anchorOffset;this.#o=e.focusNode;this.#s=e.focusOffset;this.#v();this.#w();this.rotate(this.rotation)}this.annotationElementId||this._uiManager.a11yAlert(V._l10nAlert.highlight)}get telemetryInitialData(){return{action:`added`,type:this.#d?`free_highlight`:`highlight`,color:this._uiManager.getNonHCMColorName(this.color),thickness:this.#g,methodOfCreation:this.#_}}get telemetryFinalData(){return{type:`highlight`,color:this._uiManager.getNonHCMColorName(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get(`color`).size}}#v(){let e=new br(this.#n,.001);this.#l=e.getOutlines();[this.x,this.y,this.width,this.height]=this.#l.box;let t=new br(this.#n,.0025,.001,this._uiManager.direction===`ltr`);this.#a=t.getOutlines();let{firstPoint:n}=this.#l;this.#f=[(n[0]-this.x)/this.width,(n[1]-this.y)/this.height];let{lastPoint:r}=this.#a;this.#p=[(r[0]-this.x)/this.width,(r[1]-this.y)/this.height]}#y({highlightOutlines:e,highlightId:t,clipPathId:n}){this.#l=e;this.#a=e.getNewOutline(this.#g/2+1.5,.0025);if(t>=0){this.#u=t;this.#r=n;this.parent.drawLayer.finalizeDraw(t,{bbox:e.box,path:{d:e.toSVGPath()}});this.#m=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#a.box,path:{d:this.#a.toSVGPath()}},!0)}else if(this.parent){let t=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#u,{bbox:Q.#T(this.#l.box,(t-this.rotation+360)%360),path:{d:e.toSVGPath()}});this.parent.drawLayer.updateProperties(this.#m,{bbox:Q.#T(this.#a.box,t),path:{d:this.#a.toSVGPath()}})}let[r,i,a,o]=e.box;switch(this.rotation){case 0:this.x=r;this.y=i;this.width=a;this.height=o;break;case 90:{let[e,t]=this.parentDimensions;this.x=i;this.y=1-r;this.width=a*t/e;this.height=o*e/t;break}case 180:this.x=1-r;this.y=1-i;this.width=a;this.height=o;break;case 270:{let[e,t]=this.parentDimensions;this.x=1-i;this.y=r;this.width=a*t/e;this.height=o*e/t;break}}let{firstPoint:s}=e;this.#f=[(s[0]-r)/a,(s[1]-i)/o];let{lastPoint:c}=this.#a;this.#p=[(c[0]-r)/a,(c[1]-i)/o]}static initialize(e,t){V.initialize(e,t);Q._defaultColor||=t.highlightColors?.values().next().value||`#fff066`}static updateDefaultParams(e,t){switch(e){case b.HIGHLIGHT_COLOR:Q._defaultColor=t;break;case b.HIGHLIGHT_THICKNESS:Q._defaultThickness=t}}translateInPage(e,t){}get toolbarPosition(){return this.#p}get commentButtonPosition(){return this.#f}updateParams(e,t){switch(e){case b.HIGHLIGHT_COLOR:this.#b(t);break;case b.HIGHLIGHT_THICKNESS:this.#x(t)}}static get defaultPropertiesToUpdate(){return[[b.HIGHLIGHT_COLOR,Q._defaultColor],[b.HIGHLIGHT_THICKNESS,Q._defaultThickness]]}get propertiesToUpdate(){return[[b.HIGHLIGHT_COLOR,this.color||Q._defaultColor],[b.HIGHLIGHT_THICKNESS,this.#g||Q._defaultThickness],[b.HIGHLIGHT_FREE,this.#d]]}onUpdatedColor(){this.parent?.drawLayer.updateProperties(this.#u,{root:{fill:this.color,"fill-opacity":this.opacity}});this.#i?.updateColor(this.color);super.onUpdatedColor()}#b(e){let t=(e,t)=>{this.color=e;this.opacity=t;this.onUpdatedColor()},n=this.color,r=this.opacity;this.addCommands({cmd:t.bind(this,e,Q._defaultOpacity),undo:t.bind(this,n,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:b.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0});this._reportTelemetry({action:`color_changed`,color:this._uiManager.getNonHCMColorName(e)},!0)}#x(e){let t=this.#g,n=e=>{this.#g=e;this.#S(e)};this.addCommands({cmd:n.bind(this,e),undo:n.bind(this,t),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:b.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0});this._reportTelemetry({action:`thickness_changed`,thickness:e},!0)}get toolbarButtons(){if(this._uiManager.highlightColors)return[[`colorPicker`,this.#i=new J({editor:this})]];return super.toolbarButtons}disableEditing(){super.disableEditing();this.div.classList.toggle(`disabled`,!0)}enableEditing(){super.enableEditing();this.div.classList.toggle(`disabled`,!1)}fixAndSetPosition(){return super.fixAndSetPosition(this.#O())}getBaseTranslation(){return[0,0]}getRect(e,t){return super.getRect(e,t,this.#O())}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this);e&&this.div.focus()}remove(){this.#C();this._reportTelemetry({action:`deleted`});super.remove()}rebuild(){if(this.parent){super.rebuild();if(this.div!==null){this.#w();this.isAttachedToDOM||this.parent.add(this)}}}setParent(e){let t=!1;if(this.parent&&!e)this.#C();else if(e){this.#w(e);t=!this.parent&&this.div?.classList.contains(`selectedEditor`)}super.setParent(e);this.show(this._isVisible);t&&this.select()}#S(e){if(this.#d){this.#y({highlightOutlines:this.#l.getNewOutline(e/2)});this.fixAndSetPosition();this.setDims()}}#C(){if(this.#u!==null&&this.parent){this.parent.drawLayer.remove(this.#u);this.#u=null;this.parent.drawLayer.remove(this.#m);this.#m=null}}#w(e=this.parent){if(this.#u===null){({id:this.#u,clipPathId:this.#r}=e.drawLayer.draw({bbox:this.#l.box,root:{viewBox:`0 0 1 1`,fill:this.color,"fill-opacity":this.opacity},rootClass:{highlight:!0,free:this.#d},path:{d:this.#l.toSVGPath()}},!1,!0));this.#m=e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#d},bbox:this.#a.box,path:{d:this.#a.toSVGPath()}},this.#d);this.#c&&(this.#c.style.clipPath=this.#r)}}static#T([e,t,n,r],i){switch(i){case 90:return[1-t-r,e,r,n];case 180:return[1-e-n,1-t-r,n,r];case 270:return[t,1-e-n,r,n]}return[e,t,n,r]}rotate(e){let{drawLayer:t}=this.parent,n;if(this.#d){e=(e-this.rotation+360)%360;n=Q.#T(this.#l.box,e)}else n=Q.#T([this.x,this.y,this.width,this.height],e);t.updateProperties(this.#u,{bbox:n,root:{"data-main-rotation":e}});t.updateProperties(this.#m,{bbox:Q.#T(this.#a.box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;let e=super.render();if(this.#h){e.setAttribute(`aria-label`,this.#h);e.setAttribute(`role`,`mark`)}this.#d?e.classList.add(`free`):this.div.addEventListener(`keydown`,this.#E.bind(this),{signal:this._uiManager._signal});let t=this.#c=document.createElement(`div`);e.append(t);t.setAttribute(`aria-hidden`,`true`);t.className=`internal`;t.style.clipPath=this.#r;this.setDims();Fe(this,this.#c,[`pointerover`,`pointerleave`]);this.enableEditing();return e}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{hovered:!1}})}#E(e){Q._keyboardManager.exec(this,e)}_moveCaret(e){this.parent.unselect(this);switch(e){case 0:case 2:this.#D(!0);break;case 1:case 3:this.#D(!1)}}#D(e){if(!this.#e)return;let t=window.getSelection();e?t.setPosition(this.#e,this.#t):t.setPosition(this.#o,this.#s)}select(){super.select();this.#m&&this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect();if(this.#m){this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{selected:!1}});this.#d||this.#D(!1)}}get _mustFixPosition(){return!this.#d}show(e=this._isVisible){super.show(e);if(this.parent){this.parent.drawLayer.updateProperties(this.#u,{rootClass:{hidden:!e}});this.parent.drawLayer.updateProperties(this.#m,{rootClass:{hidden:!e}})}}#O(){return this.#d?this.rotation:0}#k(){if(this.#d)return null;let[e,t]=this.pageDimensions,[n,r]=this.pageTranslation,i=this.#n,a=new Float32Array(8*i.length),o=0;for(let{x:s,y:c,width:l,height:u}of i){let i=s*e+n,d=(1-c)*t+r;a[o]=a[o+4]=i;a[o+1]=a[o+3]=d;a[o+2]=a[o+6]=i+l*e;a[o+5]=a[o+7]=d-u*t;o+=8}return a}#A(e){return this.#l.serialize(e,this.#O())}static startHighlighting(e,t,{target:n,x:r,y:i}){let{x:a,y:o,width:s,height:c}=n.getBoundingClientRect(),l=new AbortController,u=e.combinedSignal(l),d=t=>{l.abort();this.#M(e,t)};window.addEventListener(`blur`,d,{signal:u});window.addEventListener(`pointerup`,d,{signal:u});window.addEventListener(`pointerdown`,R,{capture:!0,passive:!1,signal:u});window.addEventListener(`contextmenu`,L,{signal:u});n.addEventListener(`pointermove`,this.#j.bind(this,e),{signal:u});this._freeHighlight=new Sr({x:r,y:i},[a,o,s,c],e.scale,this._defaultThickness/2,t,.001);({id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:`0 0 1 1`,fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0))}static#j(e,t){this._freeHighlight.add(t)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#M(e,t){this._freeHighlight.isEmpty()?e.drawLayer.remove(this._freeHighlightId):e.createAndAddNewEditor(t,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:`main_toolbar`});this._freeHighlightId=-1;this._freeHighlight=null;this._freeHighlightClipId=``}static async deserialize(e,t,n){let r=null;if(e instanceof hr){let{data:{quadPoints:t,rect:n,rotation:i,id:a,color:o,opacity:s,popupRef:c,richText:l,contentsObj:u,creationDate:d,modificationDate:f},parent:{page:{pageNumber:p}}}=e;r=e={annotationType:y.HIGHLIGHT,color:Array.from(o),opacity:s,quadPoints:t,boxes:null,pageIndex:p-1,rect:n.slice(0),rotation:i,annotationElementId:a,id:a,deleted:!1,popupRef:c,richText:l,comment:u?.str||null,creationDate:d,modificationDate:f}}else if(e instanceof mr){let{data:{inkLists:t,rect:n,rotation:i,id:a,color:o,borderStyle:{rawWidth:s},popupRef:c,richText:l,contentsObj:u,creationDate:d,modificationDate:f},parent:{page:{pageNumber:p}}}=e;r=e={annotationType:y.HIGHLIGHT,color:Array.from(o),thickness:s,inkLists:t,boxes:null,pageIndex:p-1,rect:n.slice(0),rotation:i,annotationElementId:a,id:a,deleted:!1,popupRef:c,richText:l,comment:u?.str||null,creationDate:d,modificationDate:f}}let{color:i,quadPoints:a,inkLists:o,outlines:s,opacity:c}=e,l=await super.deserialize(e,t,n);l.color=P.makeHexColor(...i);l.opacity=c||1;o&&(l.#g=e.thickness);l._initialData=r;e.comment&&l.setCommentData(e);let[u,d]=l.pageDimensions,[f,p]=l.pageTranslation;if(a){let e=l.#n=[];for(let t=0;t<a.length;t+=8)e.push({x:(a[t]-f)/u,y:1-(a[t+1]-p)/d,width:(a[t+2]-a[t])/u,height:(a[t+1]-a[t+5])/d});l.#v();l.#w();l.rotate(l.rotation)}else if(o||s){l.#d=!0;let e=(o||s.points)[0],n={x:e[0]-f,y:d-(e[1]-p)},r=new Sr(n,[0,0,u,d],1,l.#g/2,!0,.001);for(let t=0,i=e.length;t<i;t+=2){n.x=e[t]-f;n.y=d-(e[t+1]-p);r.add(n)}let{id:i,clipPathId:a}=t.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:`0 0 1 1`,fill:l.color,"fill-opacity":l._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:r.toSVGPath()}},!0,!0);l.#y({highlightOutlines:r.getOutlines(),highlightId:i,clipPathId:a});l.#w();l.rotate(l.parentRotation)}return l}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();let t=V._colorManager.convert(this._uiManager.getNonHCMColor(this.color)),n=super.serialize(e);Object.assign(n,{color:t,opacity:this.opacity,thickness:this.#g,quadPoints:this.#k(),outlines:this.#A(n.rect)});this.addComment(n);if(this.annotationElementId&&!this.#N(n))return null;n.id=this.annotationElementId;return n}#N(e){let{color:t}=this._initialData;return this.hasEditedComment||e.color.some((e,n)=>e!==t[n])}renderAnnotationElement(e){if(this.deleted){e.hide();return null}e.updateEdited({rect:this.getPDFRect(),popup:this.comment});return null}static canCreateNewEmptyEditor(){return!1}}class wr{#e=Object.create(null);updateProperty(e,t){this[e]=t;this.updateSVGProperty(e,t)}updateProperties(e){if(e)for(let[t,n]of Object.entries(e))t.startsWith(`_`)||this.updateProperty(t,n)}updateSVGProperty(e,t){this.#e[e]=t}toSVGProperties(){let e=this.#e;this.#e=Object.create(null);return{root:e}}reset(){this.#e=Object.create(null)}updateAll(e=this){this.updateProperties(e)}clone(){k(`Not implemented`)}}class $ extends V{#e=null;#t;_colorPicker=null;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#n=null;static#r=null;static#i=null;static _INNER_MARGIN=3;constructor(e){super(e);this.#t=e.mustBeCommitted||!1;this._addOutlines(e)}onUpdatedColor(){this._colorPicker?.update(this.color);super.onUpdatedColor()}onUpdatedOpacity(){this._colorPicker?.updateOpacity?.(this.opacity)}_addOutlines(e){if(e.drawOutlines){this.#a(e);this.#c()}}#a({drawOutlines:e,drawId:t,drawingOptions:n}){this.#e=e;this._drawingOptions||=n;this.annotationElementId||this._uiManager.a11yAlert(V._l10nAlert[this.editorType]);if(t>=0){this._drawId=t;this.parent.drawLayer.finalizeDraw(t,e.defaultProperties)}else this._drawId=this.#o(e,this.parent);this.#d(e.box)}#o(e,t){let{id:n}=t.drawLayer.draw($._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return n}static _mergeSVGProperties(e,t){let n=new Set(Object.keys(e));for(let[r,i]of Object.entries(t))n.has(r)?Object.assign(e[r],i):e[r]=i;return e}static getDefaultDrawingOptions(e){k(`Not implemented`)}static get typesMap(){k(`Not implemented`)}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,t){let n=this.typesMap.get(e);n&&this._defaultDrawingOptions.updateProperty(n,t);if(this._currentParent){$.#n.updateProperty(n,t);this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties())}}updateParams(e,t){let n=this.constructor.typesMap.get(e);n&&this._updateProperty(e,n,t)}static get defaultPropertiesToUpdate(){let e=[],t=this._defaultDrawingOptions;for(let[n,r]of this.typesMap)e.push([n,t[r]]);return e}get propertiesToUpdate(){let e=[],{_drawingOptions:t}=this;for(let[n,r]of this.constructor.typesMap)e.push([n,t[r]]);return e}_updateProperty(e,t,n){let r=this._drawingOptions,i=r[t],a=n=>{r.updateProperty(t,n);let i=this.#e.updateProperty(t,n);i&&this.#d(i);this.parent?.drawLayer.updateProperties(this._drawId,r.toSVGProperties());e===this.colorType?this.onUpdatedColor():e===this.opacityType&&this.onUpdatedOpacity()};this.addCommands({cmd:a.bind(this,n),undo:a.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_updateColorAndOpacity(e,t){let n=this.constructor.typesMap.get(this.colorType),r=this.constructor.typesMap.get(this.opacityType),i=this._drawingOptions,a=i[n],o=i[r],s=(e,t)=>{i.updateProperty(n,e);i.updateProperty(r,t);this.#e.updateProperty(n,e);this.#e.updateProperty(r,t);this.parent?.drawLayer.updateProperties(this._drawId,i.toSVGProperties());this.onUpdatedColor();this.onUpdatedOpacity()};this.addCommands({cmd:s.bind(this,e,t),undo:s.bind(this,a,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:b.INK_COLOR_AND_OPACITY,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,$._mergeSVGProperties(this.#e.getPathResizingSVGProperties(this.#u()),{bbox:this.#f()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,$._mergeSVGProperties(this.#e.getPathResizedSVGProperties(this.#u()),{bbox:this.#f()}))}_onTranslating(e,t){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#f()})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,$._mergeSVGProperties(this.#e.getPathTranslatedSVGProperties(this.#u(),this.parentDimensions),{bbox:this.#f()}))}_onStartDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit();this.disableEditMode();this.disableEditing()}disableEditing(){super.disableEditing();this.div.classList.toggle(`disabled`,!0)}enableEditing(){super.enableEditing();this.div.classList.toggle(`disabled`,!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this);this._isDraggable=!0;if(this.#t){this.#t=!1;this.commit();this.parent.setSelected(this);e&&this.isOnScreen&&this.div.focus()}}remove(){this.#s();super.remove()}rebuild(){if(this.parent){super.rebuild();if(this.div!==null){this.#c();this.#d(this.#e.box);this.isAttachedToDOM||this.parent.add(this)}}}setParent(e){let t=!1;if(this.parent&&!e){this._uiManager.removeShouldRescale(this);this.#s()}else if(e){this._uiManager.addShouldRescale(this);this.#c(e);t=!this.parent&&this.div?.classList.contains(`selectedEditor`)}super.setParent(e);t&&this.select()}#s(){if(this._drawId!==null&&this.parent){this.parent.drawLayer.remove(this._drawId);this._drawId=null;this._drawingOptions.reset()}}#c(e=this.parent){if(this._drawId===null||this.parent!==e){if(this._drawId===null){this._drawingOptions.updateAll();this._drawId=this.#o(this.#e,e)}else this.parent.drawLayer.updateParent(this._drawId,e.drawLayer)}}#l([e,t,n,r]){let{parentDimensions:[i,a],rotation:o}=this;switch(o){case 90:return[t,1-e,a/i*n,i/a*r];case 180:return[1-e,1-t,n,r];case 270:return[1-t,e,a/i*n,i/a*r];default:return[e,t,n,r]}}#u(){let{x:e,y:t,width:n,height:r,parentDimensions:[i,a],rotation:o}=this;switch(o){case 90:return[1-t,e,i/a*n,a/i*r];case 180:return[1-e,1-t,n,r];case 270:return[t,1-e,i/a*n,a/i*r];default:return[e,t,n,r]}}#d(e){[this.x,this.y,this.width,this.height]=this.#l(e);if(this.div){this.fixAndSetPosition();this.setDims()}this._onResized()}#f(){let{x:e,y:t,width:n,height:r,rotation:i,parentRotation:a,parentDimensions:[o,s]}=this;switch((4*i+a)/90){case 1:return[1-t-r,e,r,n];case 2:return[1-e-n,1-t-r,n,r];case 3:return[t,1-e-n,r,n];case 4:return[e,t-o/s*n,s/o*r,o/s*n];case 5:return[1-t,e,o/s*n,s/o*r];case 6:return[1-e-s/o*r,1-t,s/o*r,o/s*n];case 7:return[t-o/s*n,1-e-s/o*r,o/s*n,s/o*r];case 8:return[e-n,t-r,n,r];case 9:return[1-t,e-n,r,n];case 10:return[1-e,1-t,n,r];case 11:return[t-r,1-e,r,n];case 12:return[e-s/o*r,t,s/o*r,o/s*n];case 13:return[1-t-o/s*n,e-s/o*r,o/s*n,s/o*r];case 14:return[1-e,1-t-o/s*n,s/o*r,o/s*n];case 15:return[t,1-e,o/s*n,s/o*r];default:return[e,t,n,r]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,$._mergeSVGProperties({bbox:this.#f()},this.#e.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#d(this.#e.updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;let e,t;if(this._isCopy){e=this.x;t=this.y}let n=super.render();n.classList.add(`draw`);let r=document.createElement(`div`);n.append(r);r.setAttribute(`aria-hidden`,`true`);r.className=`internal`;this.setDims();this._uiManager.addShouldRescale(this);this.disableEditing();this._isCopy&&this._moveAfterPaste(e,t);return n}static createDrawerInstance(e,t,n,r,i){k(`Not implemented`)}static startDrawing(e,t,n,r){let{target:i,offsetX:a,offsetY:o,pointerId:s,pointerType:c}=r;if(B.isInitializedAndDifferentPointerType(c))return;let{viewport:{rotation:l}}=e,{width:u,height:d}=i.getBoundingClientRect(),f=$.#r=new AbortController,p=e.combinedSignal(f);B.setPointer(c,s);window.addEventListener(`pointerup`,e=>{B.isSamePointerIdOrRemove(e.pointerId)&&this._endDraw(e)},{signal:p});window.addEventListener(`pointercancel`,e=>{B.isSamePointerIdOrRemove(e.pointerId)&&this._currentParent.endDrawingSession()},{signal:p});window.addEventListener(`pointerdown`,e=>{if(B.isSamePointerType(e.pointerType)){B.initializeAndAddPointerId(e.pointerId);if($.#n.isCancellable()){$.#n.removeLastElement();$.#n.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)}}},{capture:!0,passive:!1,signal:p});window.addEventListener(`contextmenu`,L,{signal:p});i.addEventListener(`pointermove`,this._drawMove.bind(this),{signal:p});i.addEventListener(`touchmove`,e=>{B.isSameTimeStamp(e.timeStamp)&&R(e)},{signal:p});e.toggleDrawing();t._editorUndoBar?.hide();if($.#n)e.drawLayer.updateProperties(this._currentDrawId,$.#n.startNew(a,o,u,d,l));else{t.updateUIForDefaultProperties(this);$.#n=this.createDrawerInstance(a,o,u,d,l);$.#i=this.getDefaultDrawingOptions();this._currentParent=e;({id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties($.#i.toSVGProperties(),$.#n.defaultSVGProperties),!0,!1))}}static _drawMove(e){B.isSameTimeStamp(e.timeStamp);if(!$.#n)return;let{offsetX:t,offsetY:n,pointerId:r}=e;if(B.isSamePointerId(r)){if(B.isUsingMultiplePointers())this._endDraw(e);else{this._currentParent.drawLayer.updateProperties(this._currentDrawId,$.#n.add(t,n));B.setTimeStamp(e.timeStamp);R(e)}}}static _cleanup(e){if(e){this._currentDrawId=-1;this._currentParent=null;$.#n=null;$.#i=null;B.clearTimeStamp()}if($.#r){$.#r.abort();$.#r=null;B.clearPointerIds()}}static _endDraw(e){let t=this._currentParent;if(t){t.toggleDrawing(!0);this._cleanup(!1);e?.target===t.div&&t.drawLayer.updateProperties(this._currentDrawId,$.#n.end(e.offsetX,e.offsetY));if(this.supportMultipleDrawings){let e=$.#n,n=this._currentDrawId,r=e.getLastElement();t.addCommands({cmd:()=>{t.drawLayer.updateProperties(n,e.setLastElement(r))},undo:()=>{t.drawLayer.updateProperties(n,e.removeLastElement())},mustExec:!1,type:b.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){let t=this._currentParent;if(!t)return null;t.toggleDrawing(!0);t.cleanUndoStack(b.DRAW_STEP);if(!$.#n.isEmpty()){let{pageDimensions:[n,r],scale:i}=t,a=t.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:$.#n.getOutlines(n*i,r*i,i,this._INNER_MARGIN),drawingOptions:$.#i,mustBeCommitted:!e});this._cleanup(!0);return a}t.drawLayer.remove(this._currentDrawId);this._cleanup(!0);return null}createDrawingOptions(e){}static deserializeDraw(e,t,n,r,i,a){k(`Not implemented`)}static async deserialize(e,t,n){let{rawDims:{pageWidth:r,pageHeight:i,pageX:a,pageY:o}}=t.viewport,s=this.deserializeDraw(a,o,r,i,this._INNER_MARGIN,e),c=await super.deserialize(e,t,n);c.createDrawingOptions(e);c.#a({drawOutlines:s});c.#c();c.onScaleChanging();c.rotate();return c}serializeDraw(e){let[t,n]=this.pageTranslation,[r,i]=this.pageDimensions;return this.#e.serialize([t,n,r,i],e)}renderAnnotationElement(e){e.updateEdited({rect:this.getPDFRect()});return null}static canCreateNewEmptyEditor(){return!1}}class Tr{#e=new Float64Array(6);#t;#n;#r;#i;#a;#o=``;#s=0;#c=new Er;#l;#u;constructor(e,t,n,r,i,a){this.#l=n;this.#u=r;this.#r=i;this.#i=a;[e,t]=this.#d(e,t);let o=this.#t=[NaN,NaN,NaN,NaN,e,t];this.#a=[e,t];this.#n=[{line:o,points:this.#a}];this.#e.set(o,0)}updateProperty(e,t){e===`stroke-width`&&(this.#i=t)}#d(e,t){return Z._normalizePoint(e,t,this.#l,this.#u,this.#r)}isEmpty(){return!this.#n||this.#n.length===0}isCancellable(){return this.#a.length<=10}add(e,t){[e,t]=this.#d(e,t);let[n,r,i,a]=this.#e.subarray(2,6),o=e-i,s=t-a;if(Math.hypot(this.#l*o,this.#u*s)<=2)return null;this.#a.push(e,t);if(isNaN(n)){this.#e.set([i,a,e,t],2);this.#t.push(NaN,NaN,NaN,NaN,e,t);return{path:{d:this.toSVGPath()}}}isNaN(this.#e[0])&&this.#t.splice(6,6);this.#e.set([n,r,i,a,e,t],0);this.#t.push(...Z.createBezierPoints(n,r,i,a,e,t));return{path:{d:this.toSVGPath()}}}end(e,t){return this.add(e,t)||(this.#a.length===2?{path:{d:this.toSVGPath()}}:null)}startNew(e,t,n,r,i){this.#l=n;this.#u=r;this.#r=i;[e,t]=this.#d(e,t);let a=this.#t=[NaN,NaN,NaN,NaN,e,t];this.#a=[e,t];let o=this.#n.at(-1);if(o){o.line=new Float32Array(o.line);o.points=new Float32Array(o.points)}this.#n.push({line:a,points:this.#a});this.#e.set(a,0);this.#s=0;this.toSVGPath();return null}getLastElement(){return this.#n.at(-1)}setLastElement(e){if(!this.#n)return this.#c.setLastElement(e);this.#n.push(e);this.#t=e.line;this.#a=e.points;this.#s=0;return{path:{d:this.toSVGPath()}}}removeLastElement(){if(!this.#n)return this.#c.removeLastElement();this.#n.pop();this.#o=``;for(let e=0,t=this.#n.length;e<t;e++){let{line:t,points:n}=this.#n[e];this.#t=t;this.#a=n;this.#s=0;this.toSVGPath()}return{path:{d:this.#o}}}toSVGPath(){let e=Z.svgRound(this.#t[4]),t=Z.svgRound(this.#t[5]);if(this.#a.length===2){this.#o=`${this.#o} M ${e} ${t} Z`;return this.#o}if(this.#a.length<=6){let n=this.#o.lastIndexOf(`M`);this.#o=`${this.#o.slice(0,n)} M ${e} ${t}`;this.#s=6}if(this.#a.length===4){let e=Z.svgRound(this.#t[10]),t=Z.svgRound(this.#t[11]);this.#o=`${this.#o} L ${e} ${t}`;this.#s=12;return this.#o}let n=[];if(this.#s===0){n.push(`M ${e} ${t}`);this.#s=6}for(let e=this.#s,t=this.#t.length;e<t;e+=6){let[t,r,i,a,o,s]=this.#t.slice(e,e+6).map(Z.svgRound);n.push(`C${t} ${r} ${i} ${a} ${o} ${s}`)}this.#o+=n.join(` `);this.#s=this.#t.length;return this.#o}getOutlines(e,t,n,r){let i=this.#n.at(-1);i.line=new Float32Array(i.line);i.points=new Float32Array(i.points);this.#c.build(this.#n,e,t,n,this.#r,this.#i,r);this.#e=null;this.#t=null;this.#n=null;this.#o=null;return this.#c}get defaultSVGProperties(){return{root:{viewBox:`0 0 10000 10000`},rootClass:{draw:!0},bbox:[0,0,1,1]}}}class Er extends Z{#e;#t=0;#n;#r;#i;#a;#o;#s;#c;build(e,t,n,r,i,a,o){this.#i=t;this.#a=n;this.#o=r;this.#s=i;this.#c=a;this.#n=o??0;this.#r=e;this.#d()}get thickness(){return this.#c}setLastElement(e){this.#r.push(e);return{path:{d:this.toSVGPath()}}}removeLastElement(){this.#r.pop();return{path:{d:this.toSVGPath()}}}toSVGPath(){let e=[];for(let{line:t}of this.#r){e.push(`M${Z.svgRound(t[4])} ${Z.svgRound(t[5])}`);if(t.length!==6){if(t.length===12&&isNaN(t[6]))e.push(`L${Z.svgRound(t[10])} ${Z.svgRound(t[11])}`);else for(let n=6,r=t.length;n<r;n+=6){let[r,i,a,o,s,c]=t.subarray(n,n+6).map(Z.svgRound);e.push(`C${r} ${i} ${a} ${o} ${s} ${c}`)}}else e.push(`Z`)}return e.join(``)}serialize([e,t,n,r],i){let a=[],o=[],[s,c,l,u]=this.#u(),d,f,p,m,h,g,_,v,y;switch(this.#s){case 0:y=Z._rescale;d=e;f=t+r;p=n;m=-r;h=e+s*n;g=t+(1-c-u)*r;_=e+(s+l)*n;v=t+(1-c)*r;break;case 90:y=Z._rescaleAndSwap;d=e;f=t;p=n;m=r;h=e+c*n;g=t+s*r;_=e+(c+u)*n;v=t+(s+l)*r;break;case 180:y=Z._rescale;d=e+n;f=t;p=-n;m=r;h=e+(1-s-l)*n;g=t+c*r;_=e+(1-s)*n;v=t+(c+u)*r;break;case 270:y=Z._rescaleAndSwap;d=e+n;f=t+r;p=-n;m=-r;h=e+(1-c-u)*n;g=t+(1-s-l)*r;_=e+(1-c)*n;v=t+(1-s)*r}for(let{line:e,points:t}of this.#r){a.push(y(e,d,f,p,m,i?Array(e.length):null));o.push(y(t,d,f,p,m,i?Array(t.length):null))}return{lines:a,points:o,rect:[h,g,_,v]}}static deserialize(e,t,n,r,i,{paths:{lines:a,points:o},rotation:s,thickness:c}){let l=[],u,d,f,p,m;switch(s){case 0:m=Z._rescale;u=-e/n;d=t/r+1;f=1/n;p=-1/r;break;case 90:m=Z._rescaleAndSwap;u=-t/r;d=-e/n;f=1/r;p=1/n;break;case 180:m=Z._rescale;u=e/n+1;d=-t/r;f=-1/n;p=1/r;break;case 270:m=Z._rescaleAndSwap;u=t/r+1;d=e/n+1;f=-1/r;p=-1/n}if(!a){a=[];for(let e of o){let t=e.length;if(t===2){a.push(new Float32Array([NaN,NaN,NaN,NaN,e[0],e[1]]));continue}if(t===4){a.push(new Float32Array([NaN,NaN,NaN,NaN,e[0],e[1],NaN,NaN,NaN,NaN,e[2],e[3]]));continue}let n=new Float32Array(3*(t-2));a.push(n);let[r,i,o,s]=e.subarray(0,4);n.set([NaN,NaN,NaN,NaN,r,i],0);for(let a=4;a<t;a+=2){let t=e[a],c=e[a+1];n.set(Z.createBezierPoints(r,i,o,s,t,c),3*(a-2));[r,i,o,s]=[o,s,t,c]}}}for(let e=0,t=a.length;e<t;e++)l.push({line:m(a[e].map(e=>e??NaN),u,d,f,p),points:m(o[e].map(e=>e??NaN),u,d,f,p)});let h=new this.prototype.constructor;h.build(l,n,r,1,s,c,i);return h}#l(e=this.#c){let t=this.#n+e/2*this.#o;return this.#s%180==0?[t/this.#i,t/this.#a]:[t/this.#a,t/this.#i]}#u(){let[e,t,n,r]=this.#e,[i,a]=this.#l(0);return[e+i,t+a,n-2*i,r-2*a]}#d(){let e=this.#e=p.slice();for(let{line:t}of this.#r){if(t.length<=12){for(let n=4,r=t.length;n<r;n+=6)P.pointBoundingBox(t[n],t[n+1],e);continue}let n=t[4],r=t[5];for(let i=6,a=t.length;i<a;i+=6){let[a,o,s,c,l,u]=t.subarray(i,i+6);P.bezierBoundingBox(n,r,a,o,s,c,l,u,e);n=l;r=u}}let[t,n]=this.#l();e[0]=F(e[0]-t,0,1);e[1]=F(e[1]-n,0,1);e[2]=F(e[2]+t,0,1);e[3]=F(e[3]+n,0,1);e[2]-=e[0];e[3]-=e[1]}get box(){return this.#e}updateProperty(e,t){return e===`stroke-width`?this.#f(t):null}#f(e){let[t,n]=this.#l();this.#c=e;let[r,i]=this.#l(),[a,o]=[r-t,i-n],s=this.#e;s[0]-=a;s[1]-=o;s[2]+=2*a;s[3]+=2*o;return s}updateParentDimensions([e,t],n){let[r,i]=this.#l();this.#i=e;this.#a=t;this.#o=n;let[a,o]=this.#l(),s=a-r,c=o-i,l=this.#e;l[0]-=s;l[1]-=c;l[2]+=2*s;l[3]+=2*c;return l}updateRotation(e){this.#t=e;return{path:{transform:this.rotationTransform}}}get viewBox(){return this.#e.map(Z.svgRound).join(` `)}get defaultProperties(){let[e,t]=this.#e;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`}}}get rotationTransform(){let[,,e,t]=this.#e,n=0,r=0,i=0,a=0,o=0,s=0;switch(this.#t){case 90:r=t/e;i=-e/t;o=e;break;case 180:n=-1;a=-1;o=e;s=t;break;case 270:r=-t/e;i=e/t;s=t;break;default:return``}return`matrix(${n} ${r} ${i} ${a} ${Z.svgRound(o)} ${Z.svgRound(s)})`}getPathResizingSVGProperties([e,t,n,r]){let[i,a]=this.#l(),[o,s,c,l]=this.#e;if(Math.abs(c-i)<=Z.PRECISION||Math.abs(l-a)<=Z.PRECISION){let i=e+n/2-(o+c/2),a=t+r/2-(s+l/2);return{path:{"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`,transform:`${this.rotationTransform} translate(${i} ${a})`}}}let u=(n-2*i)/(c-2*i),d=(r-2*a)/(l-2*a),f=c/n,p=l/r;return{path:{"transform-origin":`${Z.svgRound(o)} ${Z.svgRound(s)}`,transform:`${this.rotationTransform} scale(${f} ${p}) translate(${Z.svgRound(i)} ${Z.svgRound(a)}) scale(${u} ${d}) translate(${Z.svgRound(-i)} ${Z.svgRound(-a)})`}}}getPathResizedSVGProperties([e,t,n,r]){let[i,a]=this.#l(),o=this.#e,[s,c,l,u]=o;o[0]=e;o[1]=t;o[2]=n;o[3]=r;if(Math.abs(l-i)<=Z.PRECISION||Math.abs(u-a)<=Z.PRECISION){let i=e+n/2-(s+l/2),a=t+r/2-(c+u/2);for(let{line:e,points:t}of this.#r){Z._translate(e,i,a,e);Z._translate(t,i,a,t)}return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}let d=(n-2*i)/(l-2*i),f=(r-2*a)/(u-2*a),p=-d*(s+i)+e+i,m=-f*(c+a)+t+a;if(d!==1||f!==1||p!==0||m!==0)for(let{line:e,points:t}of this.#r){Z._rescale(e,p,m,d,f,e);Z._rescale(t,p,m,d,f,t)}return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,t],n){let[r,i]=n,a=this.#e,o=e-a[0],s=t-a[1];if(this.#i===r&&this.#a===i)for(let{line:e,points:t}of this.#r){Z._translate(e,o,s,e);Z._translate(t,o,s,t)}else{let e=this.#i/r,t=this.#a/i;this.#i=r;this.#a=i;for(let{line:n,points:r}of this.#r){Z._rescale(n,o,s,e,t,n);Z._rescale(r,o,s,e,t,r)}a[2]*=e;a[3]*=t}a[0]=e;a[1]=t;return{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`}}}get defaultSVGProperties(){let e=this.#e;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${Z.svgRound(e[0])} ${Z.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}}class Dr extends wr{constructor(e){super();this._viewParameters=e;super.updateProperties({fill:`none`,stroke:V._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-miterlimit":10})}updateSVGProperty(e,t){if(e===`stroke-width`){t??=this[`stroke-width`];t*=this._viewParameters.realScale}super.updateSVGProperty(e,t)}clone(){let e=new Dr(this._viewParameters);e.updateAll(this);return e}}class Or extends ${static _type=`ink`;static _editorType=y.INK;static _defaultDrawingOptions=null;constructor(e){super({...e,name:`inkEditor`});this._willKeepAspectRatio=!0;this.defaultL10nId=`pdfjs-editor-ink-editor`}static initialize(e,t){V.initialize(e,t);this._defaultDrawingOptions=new Dr(t.viewParameters)}static getDefaultDrawingOptions(e){let t=this._defaultDrawingOptions.clone();t.updateProperties(e);return t}static get supportMultipleDrawings(){return!0}static get typesMap(){return j(this,`typesMap`,new Map([[b.INK_THICKNESS,`stroke-width`],[b.INK_COLOR,`stroke`],[b.INK_OPACITY,`stroke-opacity`]]))}static createDrawerInstance(e,t,n,r,i){return new Tr(e,t,n,r,i,this._defaultDrawingOptions[`stroke-width`])}static deserializeDraw(e,t,n,r,i,a){return Er.deserialize(e,t,n,r,i,a)}static async deserialize(e,t,n){let r=null;if(e instanceof mr){let{data:{inkLists:t,rect:n,rotation:i,id:a,color:o,opacity:s,borderStyle:{rawWidth:c},popupRef:l,richText:u,contentsObj:d,creationDate:f,modificationDate:p},parent:{page:{pageNumber:m}}}=e;r=e={annotationType:y.INK,color:Array.from(o),thickness:c,opacity:s,paths:{points:t},boxes:null,pageIndex:m-1,rect:n.slice(0),rotation:i,annotationElementId:a,id:a,deleted:!1,popupRef:l,richText:u,comment:d?.str||null,creationDate:f,modificationDate:p}}let i=await super.deserialize(e,t,n);i._initialData=r;e.comment&&i.setCommentData(e);return i}get toolbarButtons(){this._colorPicker||=new rr(this);return[[`colorPicker`,this._colorPicker]]}get colorType(){return b.INK_COLOR}get colorAndOpacityType(){return b.INK_COLOR_AND_OPACITY}get opacityType(){return b.INK_OPACITY}updateParams(e,t){e===b.INK_COLOR_AND_OPACITY?this._updateColorAndOpacity(t.color,t.opacity):super.updateParams(e,t)}static updateDefaultParams(e,t){if(e!==b.INK_COLOR_AND_OPACITY)super.updateDefaultParams(e,t);else{super.updateDefaultParams(b.INK_COLOR,t.color);super.updateDefaultParams(b.INK_OPACITY,t.opacity)}}get color(){return this._drawingOptions.stroke}get opacity(){return this._drawingOptions[`stroke-opacity`]}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();let{_drawId:e,_drawingOptions:t,parent:n}=this;t.updateSVGProperty(`stroke-width`);n.drawLayer.updateProperties(e,t.toSVGProperties())}static onScaleChangingWhenDrawing(){let e=this._currentParent;if(e){super.onScaleChangingWhenDrawing();this._defaultDrawingOptions.updateSVGProperty(`stroke-width`);e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties())}}createDrawingOptions({color:e,thickness:t,opacity:n}){this._drawingOptions=Or.getDefaultDrawingOptions({stroke:P.makeHexColor(...e),"stroke-width":t,"stroke-opacity":n})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let{lines:t,points:n}=this.serializeDraw(e),{_drawingOptions:{stroke:r,"stroke-opacity":i,"stroke-width":a}}=this,o=Object.assign(super.serialize(e),{color:V._colorManager.convert(r),opacity:i,thickness:a,paths:{lines:t,points:n}});this.addComment(o);if(e){o.isCopy=!0;return o}if(this.annotationElementId&&!this.#e(o))return null;o.id=this.annotationElementId;return o}#e(e){let{color:t,thickness:n,opacity:r,pageIndex:i}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized||e.color.some((e,n)=>e!==t[n])||e.thickness!==n||e.opacity!==r||e.pageIndex!==i}renderAnnotationElement(e){if(this.deleted){e.hide();return null}let{points:t,rect:n}=this.serializeDraw(!1);e.updateEdited({rect:n,thickness:this._drawingOptions[`stroke-width`],points:t,popup:this.comment});return null}}class kr extends Er{toSVGPath(){let e=super.toSVGPath();e.endsWith(`Z`)||(e+=`Z`);return e}}class Ar{static#e={maxDim:512,sigmaSFactor:.02,sigmaR:25,kernelSize:16};static#t(e,t,n,r){r-=t;return(n-=e)===0?r>0?0:4:n===1?r+6:2-r}static#n=new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]);static#r(e,t,n,r,i,a,o){let s=this.#t(n,r,i,a);for(let i=0;i<8;i++){let a=(-i+s-o+16)%8;if(e[(n+this.#n[2*a])*t+(r+this.#n[2*a+1])]!==0)return a}return-1}static#i(e,t,n,r,i,a,o){let s=this.#t(n,r,i,a);for(let i=0;i<8;i++){let a=(i+s+o+16)%8;if(e[(n+this.#n[2*a])*t+(r+this.#n[2*a+1])]!==0)return a}return-1}static#a(e,t,n,r){let i=e.length,a=new Int32Array(i);for(let t=0;t<i;t++)a[t]=+(e[t]<=r);for(let e=1;e<n-1;e++)a[e*t]=a[e*t+t-1]=0;for(let e=0;e<t;e++)a[e]=a[t*n-1-e]=0;let o,s=1,c=[];for(let e=1;e<n-1;e++){o=1;for(let n=1;n<t-1;n++){let r=e*t+n,i=a[r];if(i===0)continue;let l=e,u=n;if(i===1&&a[r-1]===0){s+=1;--u}else{if(!(i>=1&&a[r+1]===0)){i!==1&&(o=Math.abs(i));continue}s+=1;u+=1;i>1&&(o=i)}let d=[n,e],f=u===n+1,p={isHole:f,points:d,id:s,parent:0};c.push(p);let m;for(let e of c)if(e.id===o){m=e;break}p.parent=m?m.isHole?f?m.parent:o:f?o:m.parent:f?o:0;let h=this.#r(a,t,e,n,l,u,0);if(h===-1){a[r]=-s;a[r]!==1&&(o=Math.abs(a[r]));continue}let g=this.#n[2*h],_=this.#n[2*h+1],v=e+g,y=n+_;l=v;u=y;let b=e,x=n;for(;;){let i=this.#i(a,t,b,x,l,u,1);g=this.#n[2*i];_=this.#n[2*i+1];let c=b+g,f=x+_;d.push(f,c);let p=b*t+x;a[p+1]===0?a[p]=-s:a[p]===1&&(a[p]=s);if(c===e&&f===n&&b===v&&x===y){a[r]!==1&&(o=Math.abs(a[r]));break}l=b;u=x;b=c;x=f}}}return c}static#o(e,t,n,r){if(n-t<=4){for(let i=t;i<n-2;i+=2)r.push(e[i],e[i+1]);return}let i=e[t],a=e[t+1],o=e[n-4]-i,s=e[n-3]-a,c=Math.hypot(o,s),l=o/c,u=s/c,d=l*a-u*i,f=s/o,p=1/c,m=Math.atan(f),h=Math.cos(m),g=Math.sin(m),_=p*(Math.abs(h)+Math.abs(g)),v=p*(1-_+_**2),y=Math.max(Math.atan(Math.abs(g+h)*v),Math.atan(Math.abs(g-h)*v)),b=0,x=t;for(let r=t+2;r<n-2;r+=2){let t=Math.abs(d-l*e[r+1]+u*e[r]);if(t>b){x=r;b=t}}if(b>(c*y)**2){this.#o(e,t,x+2,r);this.#o(e,x,n,r)}else r.push(i,a)}static#s(e){let t=[],n=e.length;this.#o(e,0,n,t);t.push(e[n-2],e[n-1]);return t.length<=4?null:t}static#c(e,t,n,r,i,a){let o=new Float32Array(a**2),s=-2*r**2,c=a>>1;for(let e=0;e<a;e++){let t=(e-c)**2;for(let n=0;n<a;n++)o[e*a+n]=Math.exp((t+(n-c)**2)/s)}let l=new Float32Array(256),u=-2*i**2;for(let e=0;e<256;e++)l[e]=Math.exp(e**2/u);let d=e.length,f=new Uint8Array(d),p=new Uint32Array(256);for(let r=0;r<n;r++)for(let i=0;i<t;i++){let s=r*t+i,u=e[s],d=0,m=0;for(let s=0;s<a;s++){let f=r+s-c;if(!(f<0||f>=n))for(let n=0;n<a;n++){let r=i+n-c;if(r<0||r>=t)continue;let p=e[f*t+r],h=o[s*a+n]*l[Math.abs(p-u)];d+=p*h;m+=h}}p[f[s]=Math.round(d/m)]++}return[f,p]}static#l(e){let t=new Uint32Array(256);for(let n of e)t[n]++;return t}static#u(e){let t=e.length,n=new Uint8ClampedArray(t>>2),r=-1/0,i=1/0;for(let t=0,a=n.length;t<a;t++){let a=n[t]=e[t<<2];r=Math.max(r,a);i=Math.min(i,a)}let a=255/(r-i);for(let e=0,t=n.length;e<t;e++)n[e]=(n[e]-i)*a;return n}static#d(e){let t,n=-1/0,r=-1/0,i=e.findIndex(e=>e!==0),a=i,o=i;for(t=i;t<256;t++){let i=e[t];if(i>n){if(t-a>r){r=t-a;o=t-1}n=i;a=t}}for(t=o-1;t>=0&&!(e[t]>e[t+1]);t--);return t}static#f(e){let t=e,{width:n,height:r}=e,{maxDim:i}=this.#e,a=n,o=r;if(n>i||r>i){let s=n,c=r,l=Math.log2(Math.max(n,r)/i),u=Math.floor(l);l=l===u?u-1:u;for(let n=0;n<l;n++){a=Math.ceil(s/2);o=Math.ceil(c/2);let n=new OffscreenCanvas(a,o);n.getContext(`2d`).drawImage(e,0,0,s,c,0,0,a,o);s=a;c=o;e!==t&&e.close();e=n.transferToImageBitmap()}let d=Math.min(i/a,i/o);a=Math.round(a*d);o=Math.round(o*d)}let s=new OffscreenCanvas(a,o).getContext(`2d`,{willReadFrequently:!0});s.fillStyle=`white`;s.fillRect(0,0,a,o);s.filter=`grayscale(1)`;s.drawImage(e,0,0,e.width,e.height,0,0,a,o);let c=s.getImageData(0,0,a,o).data;return[this.#u(c),a,o]}static extractContoursFromText(e,{fontFamily:t,fontStyle:n,fontWeight:r},i,a,o,s){let c=new OffscreenCanvas(1,1),l=c.getContext(`2d`,{alpha:!1}),u=l.font=`${n} ${r} 200px ${t}`,{actualBoundingBoxLeft:d,actualBoundingBoxRight:f,actualBoundingBoxAscent:p,actualBoundingBoxDescent:m,fontBoundingBoxAscent:h,fontBoundingBoxDescent:g,width:_}=l.measureText(e),v=1.5,y=Math.ceil(Math.max(Math.abs(d)+Math.abs(f)||0,_)*v),b=Math.ceil(Math.max(Math.abs(p)+Math.abs(m)||200,Math.abs(h)+Math.abs(g)||200)*v);c=new OffscreenCanvas(y,b);l=c.getContext(`2d`,{alpha:!0,willReadFrequently:!0});l.font=u;l.filter=`grayscale(1)`;l.fillStyle=`white`;l.fillRect(0,0,y,b);l.fillStyle=`black`;l.fillText(e,.5*y/2,1.5*b/2);let x=this.#u(l.getImageData(0,0,y,b).data),S=this.#l(x),C=this.#d(S),w=this.#a(x,y,b,C);return this.processDrawnLines({lines:{curves:w,width:y,height:b},pageWidth:i,pageHeight:a,rotation:o,innerMargin:s,mustSmooth:!0,areContours:!0})}static process(e,t,n,r,i){let[a,o,s]=this.#f(e),[c,l]=this.#c(a,o,s,Math.hypot(o,s)*this.#e.sigmaSFactor,this.#e.sigmaR,this.#e.kernelSize),u=this.#d(l),d=this.#a(c,o,s,u);return this.processDrawnLines({lines:{curves:d,width:o,height:s},pageWidth:t,pageHeight:n,rotation:r,innerMargin:i,mustSmooth:!0,areContours:!0})}static processDrawnLines({lines:e,pageWidth:t,pageHeight:n,rotation:r,innerMargin:i,mustSmooth:a,areContours:o}){r%180!=0&&([t,n]=[n,t]);let{curves:s,width:c,height:l}=e,u=e.thickness??0,d=[],f=Math.min(t/c,n/l),p=f/t,m=f/n,h=[];for(let{points:e}of s){let t=a?this.#s(e):e;if(!t)continue;h.push(t);let n=t.length,r=new Float32Array(n),i=new Float32Array(3*(n===2?2:n-2));d.push({line:i,points:r});if(n===2){r[0]=t[0]*p;r[1]=t[1]*m;i.set([NaN,NaN,NaN,NaN,r[0],r[1]],0);continue}let[o,s,c,l]=t;o*=p;s*=m;c*=p;l*=m;r.set([o,s,c,l],0);i.set([NaN,NaN,NaN,NaN,o,s],0);for(let e=4;e<n;e+=2){let n=r[e]=t[e]*p,a=r[e+1]=t[e+1]*m;i.set(Z.createBezierPoints(o,s,c,l,n,a),3*(e-2));[o,s,c,l]=[c,l,n,a]}}if(d.length===0)return null;let g=o?new kr:new Er;g.build(d,t,n,1,r,o?0:u,i);return{outline:g,newCurves:h,areContours:o,thickness:u,width:c,height:l}}static async compressSignature({outlines:e,areContours:t,thickness:n,width:r,height:i}){let a,o=1/0,s=-1/0,c=0;for(let t of e){c+=t.length;for(let e=2,n=t.length;e<n;e++){let n=t[e]-t[e-2];o=Math.min(o,n);s=Math.max(s,n)}}a=o>=-128&&s<=127?Int8Array:o>=-32768&&s<=32767?Int16Array:Int32Array;let l=e.length,u=8+3*l,d=new Uint32Array(u),f=0;d[f++]=u*Uint32Array.BYTES_PER_ELEMENT+(c-2*l)*a.BYTES_PER_ELEMENT;d[f++]=0;d[f++]=r;d[f++]=i;d[f++]=+!t;d[f++]=Math.max(0,Math.floor(n??0));d[f++]=l;d[f++]=a.BYTES_PER_ELEMENT;for(let t of e){d[f++]=t.length-2;d[f++]=t[0];d[f++]=t[1]}let p=new CompressionStream(`deflate-raw`),m=p.writable.getWriter();await m.ready;m.write(d);let h=a.prototype.constructor;for(let t of e){let e=new h(t.length-2);for(let n=2,r=t.length;n<r;n++)e[n-2]=t[n]-t[n-2];m.write(e)}m.close();return(await new Response(p.readable).bytes()).toBase64()}static async decompressSignature(e){try{let t=Uint8Array.fromBase64(e),{readable:n,writable:r}=new DecompressionStream(`deflate-raw`),i=r.getWriter();await i.ready;i.write(t).then(async()=>{await i.ready;await i.close()}).catch(()=>{});let a=null,o=0;for await(let e of n){a||=new Uint8Array(new Uint32Array(e.buffer,0,4)[0]);a.set(e,o);o+=e.length}let s=new Uint32Array(a.buffer,0,a.length>>2),c=s[1];if(c!==0)throw Error(`Invalid version: ${c}`);let l=s[2],u=s[3],d=s[4]===0,f=s[5],p=s[6],m=s[7],h=[],g=(8+3*p)*Uint32Array.BYTES_PER_ELEMENT,_;switch(m){case Int8Array.BYTES_PER_ELEMENT:_=new Int8Array(a.buffer,g);break;case Int16Array.BYTES_PER_ELEMENT:_=new Int16Array(a.buffer,g);break;case Int32Array.BYTES_PER_ELEMENT:_=new Int32Array(a.buffer,g)}o=0;for(let e=0;e<p;e++){let t=s[3*e+8],n=new Float32Array(t+2);h.push(n);for(let t=0;t<2;t++)n[t]=s[3*e+8+t+1];for(let e=0;e<t;e++)n[e+2]=n[e]+_[o++]}return{areContours:d,thickness:f,outlines:h,width:l,height:u}}catch(e){O(`decompressSignature: ${e}`);return null}}}class jr extends wr{constructor(){super();super.updateProperties({fill:V._defaultLineColor,"stroke-width":0})}clone(){let e=new jr;e.updateAll(this);return e}}class Mr extends Dr{constructor(e){super(e);super.updateProperties({stroke:V._defaultLineColor,"stroke-width":1})}clone(){let e=new Mr(this._viewParameters);e.updateAll(this);return e}}class Nr extends ${#e=!1;#t=null;#n=null;#r=null;static _type=`signature`;static _editorType=y.SIGNATURE;static _defaultDrawingOptions=null;constructor(e){super({...e,mustBeCommitted:!0,name:`signatureEditor`});this._willKeepAspectRatio=!0;this.#n=e.signatureData||null;this.#t=null;this.defaultL10nId=`pdfjs-editor-signature-editor1`}static initialize(e,t){V.initialize(e,t);this._defaultDrawingOptions=new jr;this._defaultDrawnSignatureOptions=new Mr(t.viewParameters)}static getDefaultDrawingOptions(e){let t=this._defaultDrawingOptions.clone();t.updateProperties(e);return t}static get supportMultipleDrawings(){return!1}static get typesMap(){return j(this,`typesMap`,new Map)}static get isDrawer(){return!1}get telemetryFinalData(){return{type:`signature`,hasDescription:!!this.#t}}static computeTelemetryFinalData(e){let t=e.get(`hasDescription`);return{hasAltText:t.get(!0)??0,hasNoAltText:t.get(!1)??0}}get isResizable(){return!0}onScaleChanging(){this._drawId!==null&&super.onScaleChanging()}render(){if(this.div)return this.div;let e,t,{_isCopy:n}=this;if(n){this._isCopy=!1;e=this.x;t=this.y}super.render();if(this._drawId===null){if(this.#n){let{lines:e,mustSmooth:t,areContours:n,description:r,uuid:i,heightInPage:a}=this.#n,{rawDims:{pageWidth:o,pageHeight:s},rotation:c}=this.parent.viewport,l=Ar.processDrawnLines({lines:e,pageWidth:o,pageHeight:s,rotation:c,innerMargin:Nr._INNER_MARGIN,mustSmooth:t,areContours:n});this.addSignature(l,a,r,i)}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.#t||``}));if(n){this._isCopy=!0;this._moveAfterPaste(e,t)}return this.div}setUuid(e){this.#r=e;this.addEditToolbar()}getUuid(){return this.#r}get description(){return this.#t}set description(e){this.#t=e;if(this.div){this.div.setAttribute(`data-l10n-args`,JSON.stringify({description:e}));super.addEditToolbar().then(t=>{t?.updateEditSignatureButton(e)})}}getSignaturePreview(){let{newCurves:e,areContours:t,thickness:n,width:r,height:i}=this.#n,a=Math.max(r,i);return{areContours:t,outline:Ar.processDrawnLines({lines:{curves:e.map(e=>({points:e})),thickness:n,width:r,height:i},pageWidth:a,pageHeight:a,rotation:0,innerMargin:0,mustSmooth:!1,areContours:t}).outline}}get toolbarButtons(){return this._uiManager.signatureManager?[[`editSignature`,this._uiManager.signatureManager]]:super.toolbarButtons}addSignature(e,t,n,r){let{x:i,y:a}=this,{outline:o}=this.#n=e;this.#e=o instanceof kr;this.description=n;let s;if(this.#e)s=Nr.getDefaultDrawingOptions();else{s=Nr._defaultDrawnSignatureOptions.clone();s.updateProperties({"stroke-width":o.thickness})}this._addOutlines({drawOutlines:o,drawingOptions:s});let[,c]=this.pageDimensions,l=t/c;l=l>=1?.5:l;this.width*=l/this.height;if(this.width>=1){l*=.9/this.width;this.width=.9}this.height=l;this.setDims();this.x=i;this.y=a;this.center();this._onResized();this.onScaleChanging();this.rotate();this._uiManager.addToAnnotationStorage(this);this.setUuid(r);this._reportTelemetry({action:`pdfjs.signature.inserted`,data:{hasBeenSaved:!!r,hasDescription:!!n}});this.div.hidden=!1}getFromImage(e){let{rawDims:{pageWidth:t,pageHeight:n},rotation:r}=this.parent.viewport;return Ar.process(e,t,n,r,Nr._INNER_MARGIN)}getFromText(e,t){let{rawDims:{pageWidth:n,pageHeight:r},rotation:i}=this.parent.viewport;return Ar.extractContoursFromText(e,t,n,r,i,Nr._INNER_MARGIN)}getDrawnSignature(e){let{rawDims:{pageWidth:t,pageHeight:n},rotation:r}=this.parent.viewport;return Ar.processDrawnLines({lines:e,pageWidth:t,pageHeight:n,rotation:r,innerMargin:Nr._INNER_MARGIN,mustSmooth:!1,areContours:!1})}createDrawingOptions({areContours:e,thickness:t}){if(e)this._drawingOptions=Nr.getDefaultDrawingOptions();else{this._drawingOptions=Nr._defaultDrawnSignatureOptions.clone();this._drawingOptions.updateProperties({"stroke-width":t})}}serialize(e=!1){if(this.isEmpty())return null;let{lines:t,points:n}=this.serializeDraw(e),{_drawingOptions:{"stroke-width":r}}=this,i=Object.assign(super.serialize(e),{isSignature:!0,areContours:this.#e,color:[0,0,0],thickness:this.#e?0:r});this.addComment(i);if(e){i.paths={lines:t,points:n};i.uuid=this.#r;i.isCopy=!0}else i.lines=t;this.#t&&(i.accessibilityData={type:`Figure`,alt:this.#t});return i}static deserializeDraw(e,t,n,r,i,a){return a.areContours?kr.deserialize(e,t,n,r,i,a):Er.deserialize(e,t,n,r,i,a)}static async deserialize(e,t,n){let r=await super.deserialize(e,t,n);r.#e=e.areContours;r.description=e.accessibilityData?.alt||``;r.#r=e.uuid;return r}}class Pr extends V{#e=null;#t=null;#n=null;#r=null;#i=null;#a=``;#o=null;#s=!1;#c=null;#l=!1;#u=!1;static _type=`stamp`;static _editorType=y.STAMP;constructor(e){super({...e,name:`stampEditor`});this.#r=e.bitmapUrl;this.#i=e.bitmapFile;this.defaultL10nId=`pdfjs-editor-stamp-editor`}static initialize(e,t){V.initialize(e,t)}static isHandlingMimeForPasting(e){return ke.includes(e)}static paste(e,t){t.pasteEditor({mode:y.STAMP},{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1);super.altTextFinish()}get telemetryFinalData(){return{type:`stamp`,hasAltText:!!this.altTextData?.altText}}static computeTelemetryFinalData(e){let t=e.get(`hasAltText`);return{hasAltText:t.get(!0)??0,hasNoAltText:t.get(!1)??0}}#d(e,t=!1){if(e){this.#e=e.bitmap;if(!t){this.#t=e.id;this.#l=e.isSvg}e.file&&(this.#a=e.file.name);this.#m()}else this.remove()}#f(){this.#n=null;this._uiManager.enableWaiting(!1);if(this.#o){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#e)this.addEditToolbar().then(()=>{this._editToolbar.hide();this._uiManager.editAltText(this,!0)});else{if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#e){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(e=null,t=!0){if(this.hasAltTextData())return null;let{mlManager:n}=this._uiManager;if(!n)throw Error(`No ML.`);if(!await n.isEnabledFor(`altText`))throw Error(`ML isn't enabled for alt text.`);let{data:r,width:i,height:a}=e||this.copyCanvas(null,null,!0).imageData,o=await n.guess({name:`altText`,request:{data:r,width:i,height:a,channels:r.length/(i*a)}});if(!o)throw Error(`No response from the AI service.`);if(o.error)throw Error(`Error from the AI service.`);if(o.cancel)return null;if(!o.output)throw Error(`No valid response from the AI service.`);let s=o.output;await this.setGuessedAltText(s);t&&!this.hasAltTextData()&&(this.altTextData={alt:s,decorative:!1});return s}#p(){if(this.#t){this._uiManager.enableWaiting(!0);this._uiManager.imageManager.getFromId(this.#t).then(e=>this.#d(e,!0)).finally(()=>this.#f());return}if(this.#r){let e=this.#r;this.#r=null;this._uiManager.enableWaiting(!0);this.#n=this._uiManager.imageManager.getFromUrl(e).then(e=>this.#d(e)).finally(()=>this.#f());return}if(this.#i){let e=this.#i;this.#i=null;this._uiManager.enableWaiting(!0);this.#n=this._uiManager.imageManager.getFromFile(e).then(e=>this.#d(e)).finally(()=>this.#f());return}let e=document.createElement(`input`);e.type=`file`;e.accept=ke.join(`,`);let t=this._uiManager._signal;this.#n=new Promise(n=>{e.addEventListener(`change`,async()=>{if(e.files&&e.files.length!==0){this._uiManager.enableWaiting(!0);let t=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:`pdfjs.image.image_selected`,data:{alt_text_modal:this._uiManager.useNewAltTextFlow}});this.#d(t)}else this.remove();n()},{signal:t});e.addEventListener(`cancel`,()=>{this.remove();n()},{signal:t})}).finally(()=>this.#f());e.click()}remove(){if(this.#t){this.#e=null;this._uiManager.imageManager.deleteId(this.#t);this.#o?.remove();this.#o=null;if(this.#c){clearTimeout(this.#c);this.#c=null}}super.remove()}rebuild(){if(this.parent){super.rebuild();if(this.div!==null){this.#t&&this.#o===null&&this.#p();this.isAttachedToDOM||this.parent.add(this)}}else this.#t&&this.#p()}onceAdded(e){this._isDraggable=!0;e&&this.div.focus()}isEmpty(){return!(this.#n||this.#e||this.#r||this.#i||this.#t||this.#s)}get toolbarButtons(){return[[`altText`,this.createAltText()]]}get isResizable(){return!0}render(){if(this.div)return this.div;let e,t;if(this._isCopy){e=this.x;t=this.y}super.render();this.div.hidden=!0;this.createAltText();this.#s||(this.#e?this.#m():this.#p());this._isCopy&&this._moveAfterPaste(e,t);this._uiManager.addShouldRescale(this);return this.div}setCanvas(e,t){let{id:n,bitmap:r}=this._uiManager.imageManager.getFromCanvas(e,t);t.remove();if(n&&this._uiManager.imageManager.isValidId(n)){this.#t=n;r&&(this.#e=r);this.#s=!1;this.#m()}}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;this.#c!==null&&clearTimeout(this.#c);this.#c=setTimeout(()=>{this.#c=null;this.#g()},200)}#m(){let{div:e}=this,{width:t,height:n}=this.#e,[r,i]=this.pageDimensions,a=.75;if(this.width){t=this.width*r;n=this.height*i}else if(t>a*r||n>a*i){let e=Math.min(a*r/t,a*i/n);t*=e;n*=e}this._uiManager.enableWaiting(!1);let o=this.#o=document.createElement(`canvas`);o.setAttribute(`role`,`img`);this.addContainer(o);this.width=t/r;this.height=n/i;this.setDims();this._initialOptions?.isCentered?this.center():this.fixAndSetPosition();this._initialOptions=null;this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&!this.annotationElementId||(e.hidden=!1);this.#g();if(!this.#u){this.parent.addUndoableEditor(this);this.#u=!0}this._reportTelemetry({action:`inserted_image`});this.#a&&this.div.setAttribute(`aria-description`,this.#a);this.annotationElementId||this._uiManager.a11yAlert(V._l10nAlert.stamp)}copyCanvas(e,t,n=!1){e||=224;let{width:r,height:i}=this.#e,a=new Oe,o=this.#e,s=r,c=i,l=null;if(t){if(r>t||i>t){let e=Math.min(t/r,t/i);s=Math.floor(r*e);c=Math.floor(i*e)}l=document.createElement(`canvas`);let e=l.width=Math.ceil(s*a.sx),n=l.height=Math.ceil(c*a.sy);this.#l||(o=this.#h(e,n));let u=l.getContext(`2d`);u.filter=this._uiManager.hcmFilter;let d=`white`,f=`#cfcfd8`;if(this._uiManager.hcmFilter!==`none`)f=`black`;else if(Ae.isDarkMode){d=`#8f8f9d`;f=`#42414d`}let p=15*a.sx,m=15*a.sy,h=new OffscreenCanvas(2*p,2*m),g=h.getContext(`2d`);g.fillStyle=d;g.fillRect(0,0,2*p,2*m);g.fillStyle=f;g.fillRect(0,0,p,m);g.fillRect(p,m,p,m);u.fillStyle=u.createPattern(h,`repeat`);u.fillRect(0,0,e,n);u.drawImage(o,0,0,o.width,o.height,0,0,e,n)}let u=null;if(n){let t,n;if(a.symmetric&&o.width<e&&o.height<e){t=o.width;n=o.height}else{o=this.#e;if(r>e||i>e){let a=Math.min(e/r,e/i);t=Math.floor(r*a);n=Math.floor(i*a);this.#l||(o=this.#h(t,n))}}let s=new OffscreenCanvas(t,n).getContext(`2d`,{willReadFrequently:!0});s.drawImage(o,0,0,o.width,o.height,0,0,t,n);u={width:t,height:n,data:s.getImageData(0,0,t,n).data}}return{canvas:l,width:s,height:c,imageData:u}}#h(e,t){let{width:n,height:r}=this.#e,i=n,a=r,o=this.#e;for(;i>2*e||a>2*t;){let n=i,r=a;i>2*e&&(i=Math.ceil(i/2));a>2*t&&(a=Math.ceil(a/2));let s=new OffscreenCanvas(i,a);s.getContext(`2d`).drawImage(o,0,0,n,r,0,0,i,a);o=s.transferToImageBitmap()}return o}#g(){let[e,t]=this.parentDimensions,{width:n,height:r}=this,i=new Oe,a=Math.ceil(n*e*i.sx),o=Math.ceil(r*t*i.sy),s=this.#o;if(!s||s.width===a&&s.height===o)return;s.width=a;s.height=o;let c=this.#l?this.#e:this.#h(a,o),l=s.getContext(`2d`);l.filter=this._uiManager.hcmFilter;l.drawImage(c,0,0,c.width,c.height,0,0,a,o)}#_(e){if(e){if(this.#l){let e=this._uiManager.imageManager.getSvgUrl(this.#t);if(e)return e}let e=document.createElement(`canvas`);({width:e.width,height:e.height}=this.#e);e.getContext(`2d`).drawImage(this.#e,0,0);return e.toDataURL()}if(this.#l){let[e,t]=this.pageDimensions,n=Math.round(this.width*e*he.PDF_TO_CSS_UNITS),r=Math.round(this.height*t*he.PDF_TO_CSS_UNITS),i=new OffscreenCanvas(n,r);i.getContext(`2d`).drawImage(this.#e,0,0,this.#e.width,this.#e.height,0,0,n,r);return i.transferToImageBitmap()}return structuredClone(this.#e)}static async deserialize(e,t,n){let r=null,i=!1;if(e instanceof gr){let{data:{rect:a,rotation:o,id:s,structParent:c,popupRef:l,richText:u,contentsObj:d,creationDate:f,modificationDate:p},container:m,parent:{page:{pageNumber:h}},canvas:g}=e,v,b;if(g){delete e.canvas;({id:v,bitmap:b}=n.imageManager.getFromCanvas(m.id,g));g.remove()}else{i=!0;e._hasNoCanvas=!0}let x=(await t._structTree.getAriaAttributes(`${_}${s}`))?.get(`aria-label`)||``;r=e={annotationType:y.STAMP,bitmapId:v,bitmap:b,pageIndex:h-1,rect:a.slice(0),rotation:o,annotationElementId:s,id:s,deleted:!1,accessibilityData:{decorative:!1,altText:x},isSvg:!1,structParent:c,popupRef:l,richText:u,comment:d?.str||null,creationDate:f,modificationDate:p}}let a=await super.deserialize(e,t,n),{rect:o,bitmap:s,bitmapUrl:c,bitmapId:l,isSvg:u,accessibilityData:d}=e;if(i){n.addMissingCanvas(e.id,a);a.#s=!0}else if(l&&n.imageManager.isValidId(l)){a.#t=l;s&&(a.#e=s)}else a.#r=c;a.#l=u;let[f,p]=a.pageDimensions;a.width=(o[2]-o[0])/f;a.height=(o[3]-o[1])/p;d&&(a.altTextData=d);a._initialData=r;e.comment&&a.setCommentData(e);a.#u=!!r;return a}serialize(e=!1,t=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let n=Object.assign(super.serialize(e),{bitmapId:this.#t,isSvg:this.#l});this.addComment(n);if(e){n.bitmapUrl=this.#_(!0);n.accessibilityData=this.serializeAltText(!0);n.isCopy=!0;return n}let{decorative:r,altText:i}=this.serializeAltText(!1);!r&&i&&(n.accessibilityData={type:`Figure`,alt:i});if(this.annotationElementId){let e=this.#v(n);if(e.isSame)return null;e.isSameAltText?delete n.accessibilityData:n.accessibilityData.structParent=this._initialData.structParent??-1;n.id=this.annotationElementId;delete n.bitmapId;return n}if(t===null)return n;t.stamps||=new Map;let a=this.#l?(n.rect[2]-n.rect[0])*(n.rect[3]-n.rect[1]):null;if(t.stamps.has(this.#t)){if(this.#l){let e=t.stamps.get(this.#t);if(a>e.area){e.area=a;e.serialized.bitmap.close();e.serialized.bitmap=this.#_(!1)}}}else{t.stamps.set(this.#t,{area:a,serialized:n});n.bitmap=this.#_(!1)}return n}#v(e){let{pageIndex:t,accessibilityData:{altText:n}}=this._initialData,r=e.pageIndex===t,i=(e.accessibilityData?.alt||``)===n;return{isSame:!this.hasEditedComment&&!this._hasBeenMoved&&!this._hasBeenResized&&r&&i,isSameAltText:i}}renderAnnotationElement(e){if(this.deleted){e.hide();return null}e.updateEdited({rect:this.getPDFRect(),popup:this.comment});return null}}class Fr{#e;#t=!1;#n=null;#r=null;#i=null;#a=new Map;#o=!1;#s=!1;#c=!1;#l=null;#u=null;#d=null;#f=null;#p=null;#m=-1;#h;static _initialized=!1;static#g=new Map([X,Or,Pr,Q,Nr].map(e=>[e._editorType,e]));constructor({uiManager:e,pageIndex:t,div:n,structTreeLayer:r,accessibilityManager:i,annotationLayer:a,drawLayer:o,textLayer:s,viewport:c,l10n:l}){let u=[...Fr.#g.values()];if(!Fr._initialized){Fr._initialized=!0;for(let t of u)t.initialize(l,e)}e.registerEditorTypes(u);this.#h=e;this.pageIndex=t;this.div=n;this.#e=i;this.#n=a;this.viewport=c;this.#d=s;this.drawLayer=o;this._structTree=r;this.#h.addLayer(this)}get isEmpty(){return this.#a.size===0}get isInvisible(){return this.isEmpty&&this.#h.getMode()===y.NONE}updateToolbar(e){this.#h.updateToolbar(e)}updateMode(e=this.#h.getMode()){this.#S();switch(e){case y.NONE:this.div.classList.toggle(`nonEditing`,!0);this.disableTextSelection();this.togglePointerEvents(!1);this.toggleAnnotationLayerPointerEvents(!0);this.disableClick();return;case y.INK:this.disableTextSelection();this.togglePointerEvents(!0);this.enableClick();break;case y.HIGHLIGHT:this.enableTextSelection();this.togglePointerEvents(!1);this.disableClick();break;default:this.disableTextSelection();this.togglePointerEvents(!0);this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);let{classList:t}=this.div;t.toggle(`nonEditing`,!1);if(e===y.POPUP)t.toggle(`commentEditing`,!0);else{t.toggle(`commentEditing`,!1);for(let n of Fr.#g.values())t.toggle(`${n._type}Editing`,e===n._editorType)}this.div.hidden=!1}hasTextLayer(e){return e===this.#d?.div}setEditingState(e){this.#h.setEditingState(e)}addCommands(e){this.#h.addCommands(e)}cleanUndoStack(e){this.#h.cleanUndoStack(e)}toggleDrawing(e=!1){this.div.classList.toggle(`drawing`,!e)}togglePointerEvents(e=!1){this.div.classList.toggle(`disabled`,!e)}toggleAnnotationLayerPointerEvents(e=!1){this.#n?.togglePointerEvents(e)}get#_(){return this.#a.size===0?this.#h.getEditors(this.pageIndex):this.#a.values()}async enable(){this.#c=!0;this.div.tabIndex=0;this.togglePointerEvents(!0);this.div.classList.toggle(`nonEditing`,!1);this.#p?.abort();this.#p=null;let e=new Set;for(let t of this.#_){t.enableEditing();t.show(!0);if(t.annotationElementId){this.#h.removeChangedExistingAnnotation(t);e.add(t.annotationElementId)}}let t=this.#n;if(t)for(let n of t.getEditableAnnotations()){n.hide();if(this.#h.isDeletedAnnotationElement(n.data.id))continue;if(e.has(n.data.id))continue;let t=await this.deserialize(n);if(t){this.addOrRebuild(t);t.enableEditing()}}this.#c=!1;this.#h._eventBus.dispatch(`editorsrendered`,{source:this,pageNumber:this.pageIndex+1})}disable(){this.#s=!0;this.div.tabIndex=-1;this.togglePointerEvents(!1);this.div.classList.toggle(`nonEditing`,!0);if(this.#d&&!this.#p){this.#p=new AbortController;let e=this.#h.combinedSignal(this.#p);this.#d.div.addEventListener(`pointerdown`,e=>{let{clientX:t,clientY:n,timeStamp:r}=e;if(r-this.#m>500){this.#m=r;return}this.#m=-1;let{classList:i}=this.div;i.toggle(`getElements`,!0);let a=document.elementsFromPoint(t,n);i.toggle(`getElements`,!1);if(!this.div.contains(a[0]))return;let o,s=RegExp(`^${v}[0-9]+$`);for(let e of a)if(s.test(e.id)){o=e.id;break}if(!o)return;let c=this.#a.get(o);if(c?.annotationElementId===null){R(e);c.dblclick(e)}},{signal:e,capture:!0})}let e=this.#n,t=[];if(e){let n=new Map,r=new Map;for(let e of this.#_){e.disableEditing();if(e.annotationElementId){if(e.serialize()===null){r.set(e.annotationElementId,e);this.getEditableAnnotation(e.annotationElementId)?.show();e.remove()}else n.set(e.annotationElementId,e)}else t.push(e)}for(let t of e.getEditableAnnotations()){let{id:e}=t.data;if(this.#h.isDeletedAnnotationElement(e)){t.updateEdited({deleted:!0});continue}let i=r.get(e);if(i){i.resetAnnotationElement(t);i.show(!1);t.show()}else{i=n.get(e);if(i){this.#h.addChangedExistingAnnotation(i);i.renderAnnotationElement(t)&&i.show(!1)}t.show()}}}this.#S();this.isEmpty&&(this.div.hidden=!0);let{classList:n}=this.div;for(let e of Fr.#g.values())n.remove(`${e._type}Editing`);this.disableTextSelection();this.toggleAnnotationLayerPointerEvents(!0);e?.updateFakeAnnotations(t);this.#s=!1}getEditableAnnotation(e){return this.#n?.getEditableAnnotation(e)||null}setActiveEditor(e){this.#h.getActive()!==e&&this.#h.setActiveEditor(e)}enableTextSelection(){this.div.tabIndex=-1;if(this.#d?.div&&!this.#f){this.#f=new AbortController;let e=this.#h.combinedSignal(this.#f);this.#d.div.addEventListener(`pointerdown`,this.#v.bind(this),{signal:e});this.#d.div.classList.add(`highlighting`)}}disableTextSelection(){this.div.tabIndex=0;if(this.#d?.div&&this.#f){this.#f.abort();this.#f=null;this.#d.div.classList.remove(`highlighting`)}}#v(e){this.#h.unselectAll();let{target:t}=e;if(t===this.#d.div||(t.getAttribute(`role`)===`img`||t.classList.contains(`endOfContent`)||t.classList.contains(`textLayerImages`)||t.classList.contains(`textLayerImagePlaceholder`))&&this.#d.div.contains(t)){let{isMac:t}=N.platform;if(e.button!==0||e.ctrlKey&&t)return;this.#h.showAllEditors(`highlight`,!0,!0);this.#d.div.classList.add(`free`);this.toggleDrawing();Q.startHighlighting(this,this.#h.direction===`ltr`,{target:this.#d.div,x:e.x,y:e.y});this.#d.div.addEventListener(`pointerup`,()=>{this.#d.div.classList.remove(`free`);this.toggleDrawing(!0)},{once:!0,signal:this.#h._signal});e.preventDefault()}}enableClick(){if(this.#r)return;this.#r=new AbortController;let e=this.#h.combinedSignal(this.#r);this.div.addEventListener(`pointerdown`,this.pointerdown.bind(this),{signal:e});let t=this.pointerup.bind(this);this.div.addEventListener(`pointerup`,t,{signal:e});this.div.addEventListener(`pointercancel`,t,{signal:e})}disableClick(){this.#r?.abort();this.#r=null}attach(e){this.#a.set(e.id,e);let{annotationElementId:t}=e;t&&this.#h.isDeletedAnnotationElement(t)&&this.#h.removeDeletedAnnotationElement(e)}detach(e){this.#a.delete(e.id);this.#e?.removePointerInTextLayer(e.contentDiv);!this.#s&&e.annotationElementId&&this.#h.addDeletedAnnotationElement(e)}remove(e){this.detach(e);this.#h.removeEditor(e);e.div.remove();e.isAttachedToDOM=!1}changeParent(e){if(e.parent!==this){if(e.parent&&e.annotationElementId){this.#h.addDeletedAnnotationElement(e);V.deleteAnnotationElement(e);e.annotationElementId=null}this.attach(e);e.parent?.detach(e);e.setParent(this);if(e.div&&e.isAttachedToDOM){e.div.remove();this.div.append(e.div)}}}add(e){if(e.parent!==this||!e.isAttachedToDOM){this.changeParent(e);this.#h.addEditor(e);this.attach(e);if(!e.isAttachedToDOM){let t=e.render();this.div.append(t);e.isAttachedToDOM=!0}e.fixAndSetPosition();e.onceAdded(!this.#c);this.#h.addToAnnotationStorage(e);e._reportTelemetry(e.telemetryInitialData)}}moveEditorInDOM(e){if(!e.isAttachedToDOM)return;let{activeElement:t}=document;if(e.div.contains(t)&&!this.#i){e._focusEventsAllowed=!1;this.#i=setTimeout(()=>{this.#i=null;if(e.div.contains(document.activeElement))e._focusEventsAllowed=!0;else{e.div.addEventListener(`focusin`,()=>{e._focusEventsAllowed=!0},{once:!0,signal:this.#h._signal});t.focus()}},0)}e._structTreeParentId=this.#e?.moveElementInDOM(this.div,e.div,e.contentDiv,!0)}addOrRebuild(e){if(e.needsToBeRebuilt()){e.parent||=this;e.rebuild();e.show()}else this.add(e)}addUndoableEditor(e){this.addCommands({cmd:()=>e._uiManager.rebuild(e),undo:()=>{e.remove()},mustExec:!1})}getEditorByUID(e){for(let t of this.#a.values())if(t.uid===e)return t;return null}get#y(){return Fr.#g.get(this.#h.getMode())}combinedSignal(e){return this.#h.combinedSignal(e)}#b(e){let t=this.#y;return t?new t.prototype.constructor(e):null}canCreateNewEmptyEditor(){return this.#y?.canCreateNewEmptyEditor()}async pasteEditor(e,t){this.updateToolbar(e);await this.#h.updateMode(e.mode);let{offsetX:n,offsetY:r}=this.#x(),i=this.#h.getId(),a=this.#b({parent:this,id:i,x:n,y:r,uiManager:this.#h,isCentered:!0,...t});a&&this.add(a)}async deserialize(e){return await Fr.#g.get(e.annotationType??e.annotationEditorType)?.deserialize(e,this,this.#h)||null}createAndAddNewEditor(e,t,n={}){let r=this.#h.getId(),i=this.#b({parent:this,id:r,x:e.offsetX,y:e.offsetY,uiManager:this.#h,isCentered:t,...n});i&&this.add(i);return i}get boundingClientRect(){return this.div.getBoundingClientRect()}#x(){let{x:e,y:t,width:n,height:r}=this.boundingClientRect,i=Math.max(0,e),a=Math.max(0,t),o=(i+Math.min(window.innerWidth,e+n))/2-e,s=(a+Math.min(window.innerHeight,t+r))/2-t,[c,l]=this.viewport.rotation%180==0?[o,s]:[s,o];return{offsetX:c,offsetY:l}}addNewEditor(e={}){this.createAndAddNewEditor(this.#x(),!0,e)}setSelected(e){this.#h.setSelected(e)}toggleSelected(e){this.#h.toggleSelected(e)}unselect(e){this.#h.unselect(e)}pointerup(e){let{isMac:t}=N.platform;if(e.button!==0||e.ctrlKey&&t)return;if(e.target!==this.div)return;if(!this.#o)return;this.#o=!1;if(this.#y?.isDrawer&&this.#y.supportMultipleDrawings)return;if(!this.#t){this.#t=!0;return}let n=this.#h.getMode();n!==y.STAMP&&n!==y.POPUP&&n!==y.SIGNATURE?this.createAndAddNewEditor(e,!1):this.#h.unselectAll()}pointerdown(e){this.#h.getMode()===y.HIGHLIGHT&&this.enableTextSelection();if(this.#o){this.#o=!1;return}let{isMac:t}=N.platform;if(e.button!==0||e.ctrlKey&&t)return;if(e.target!==this.div)return;this.#o=!0;if(this.#y?.isDrawer){this.startDrawingSession(e);return}let n=this.#h.getActive();this.#t=!n||n.isEmpty()}startDrawingSession(e){this.div.focus({preventScroll:!0});if(this.#l){this.#y.startDrawing(this,this.#h,!1,e);return}this.#h.setCurrentDrawingSession(this);this.#l=new AbortController;let t=this.#h.combinedSignal(this.#l);this.div.addEventListener(`blur`,({relatedTarget:e})=>{if(e&&!this.div.contains(e)){this.#u=null;this.commitOrRemove()}},{signal:t});this.#y.startDrawing(this,this.#h,!1,e)}pause(e){if(e){let{activeElement:e}=document;this.div.contains(e)&&(this.#u=e);return}this.#u&&setTimeout(()=>{this.#u?.focus();this.#u=null},0)}endDrawingSession(e=!1){if(!this.#l)return null;this.#h.setCurrentDrawingSession(null);this.#l.abort();this.#l=null;this.#u=null;return this.#y.endDrawing(e)}findNewParent(e,t,n){let r=this.#h.findParent(t,n);if(r===null||r===this)return!1;r.changeParent(e);return!0}commitOrRemove(){if(this.#l){this.endDrawingSession();return!0}return!1}onScaleChanging(){this.#l&&this.#y.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove();if(this.#h.getActive()?.parent===this){this.#h.commitOrRemove();this.#h.setActiveEditor(null)}if(this.#i){clearTimeout(this.#i);this.#i=null}for(let e of this.#a.values()){this.#e?.removePointerInTextLayer(e.contentDiv);e.setParent(null);e.isAttachedToDOM=!1;e.div.remove()}this.div=null;this.#a.clear();this.#h.removeLayer(this)}#S(){for(let e of this.#a.values())e.isEmpty()&&e.remove()}async render({viewport:e}){this.viewport=e;De(this.div,e);for(let e of this.#h.getEditors(this.pageIndex)){this.add(e);e.rebuild()}await this.#h.findClonesForPage(this);this.div.hidden=this.isEmpty;this.updateMode()}update({viewport:e}){this.#h.commitOrRemove();this.#S();let t=this.viewport.rotation,n=e.rotation;this.viewport=e;De(this.div,{rotation:n});if(t!==n)for(let e of this.#a.values())e.rotate(n)}get pageDimensions(){let{pageWidth:e,pageHeight:t}=this.viewport.rawDims;return[e,t]}get scale(){return this.#h.viewParameters.realScale}}globalThis._pdfjsTestingUtils={HighlightOutliner:br};const Ir={fonts:globalThis.fonts,createElement(e){if(e.toLowerCase()===`canvas`)return new OffscreenCanvas(1,1);return null}};class Lr{constructor(){this._pdfDocument=null;this._page=null;this._geospatialMetadata=null;this._baseViewport=null;this._inverseBaseViewport=null;this._pdfWorker=null;this._pdfWorkerBlobUrl=null}async loadPDF(n,s={}){c()||await l();r(s);let[{data:u},d]=await Promise.all([t(n.url,{responseType:`array-buffer`,signal:s?.signal}),this._getPDFWorker(s)]),f=Yn({data:u,wasmUrl:e(`esri/libs/pdfjs/wasm/`),ownerDocument:Ir,enableHWA:!0,useWorkerFetch:!0,worker:d,useWasm:!0});this._pdfDocument=await f.promise;r(s);this._page=await this._pdfDocument.getPage(n.page);r(s);this._geospatialMetadata=await this._page.getGeospatialPDFMetadata();r(s);this._baseViewport=this._page.getViewport({scale:1});this._inverseBaseViewport=i();o(this._inverseBaseViewport,a(...this._baseViewport.transform));return{geospatialMetadata:this._geospatialMetadata}}destroy(){this._page?.cleanup?.();this._page=null;this._pdfDocument?.cleanup();this._pdfDocument=null;this._geospatialMetadata=null;this._baseViewport=null;this._inverseBaseViewport=null;this._pdfWorker?.destroy();this._pdfWorker=null;if(this._pdfWorkerBlobUrl){URL.revokeObjectURL(this._pdfWorkerBlobUrl);this._pdfWorkerBlobUrl=null}}async renderPDF(e,t={}){if(!this._page||!this._baseViewport||!this._inverseBaseViewport)throw new n(`geospatial-pdf-layer-worker:not-loaded`,`PDF not loaded`);r(t);let{width:i,height:a,sourceExtentAsJSON:o,currentRing:c,ctm:l}=e,d=s.fromJSON(o),f=await u(d,i,a,l,this._page,this._baseViewport,this._inverseBaseViewport,c,t);r(t);return Rr(f,i,a)}async _getPDFWorker(n={}){if(this._pdfWorker)return this._pdfWorker;let r=e(`esri/libs/pdfjs/pdf.worker.mjs`),i=(await t(r,{responseType:`blob`,authMode:`anonymous`,signal:n.signal})).data,a=i.type===`application/javascript`||i.type===`text/javascript`?i:new Blob([i],{type:`application/javascript`}),o=URL.createObjectURL(a);try{let e=new Worker(o,{type:`module`,name:`geospatial-pdf-pdfjs-worker`}),t=new q({port:e});await t.promise;this._pdfWorker=t;this._pdfWorkerBlobUrl=o;return t}catch(e){URL.revokeObjectURL(o);throw e}}}function Rr(e,t,r){let i=e.getContext(`2d`);if(!i)throw new n(`geospatial-pdf-raster:canvas`,`Failed to create canvas context.`);let a=i.getImageData(0,0,t,r).data,o=t*r,s=new Uint8Array(o),c=new Uint8Array(o),l=new Uint8Array(o),u=new Uint8Array(o);for(let e=0,t=0;e<o;e++,t+=4){s[e]=a[t];c[e]=a[t+1];l[e]=a[t+2];u[e]=a[t+3]}return{width:t,height:r,red:s,green:c,blue:l,mask:u}}export{Lr as default};
|
|
55
|
+
`)){let t=document.createElement(`div`);t.append(e?document.createTextNode(e):document.createElement(`br`));this.editorDiv.append(t)}}#u(){return this.#e.replaceAll(`\xA0`,` `)}static#d(e){return e.replaceAll(` `,`\xA0`)}get contentDiv(){return this.editorDiv}getPDFRect(){let e=X._internalPadding*this.parentScale;return this.getRect(e,e)}static async deserialize(e,t,n){let r=null;if(e instanceof dr){let{data:{defaultAppearanceData:{fontSize:t,fontColor:n},rect:i,rotation:a,id:o,popupRef:s,richText:c,contentsObj:l,creationDate:u,modificationDate:d},textContent:f,textPosition:p,parent:{page:{pageNumber:m}}}=e;if(!f||f.length===0)return null;r=e={annotationType:_.FREETEXT,color:Array.from(n),fontSize:t,value:f.join(`
|
|
56
|
+
`),position:p,pageIndex:m-1,rect:i.slice(0),rotation:a,annotationElementId:o,id:o,deleted:!1,popupRef:s,comment:l?.str||null,richText:c,creationDate:u,modificationDate:d}}let i=await super.deserialize(e,t,n);i.#r=e.fontSize;i.color=P.makeHexColor(...e.color);i.#e=X.#d(e.value);i._initialData=r;e.comment&&i.setCommentData(e);return i}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let t=H._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:this.color),n=Object.assign(super.serialize(e),{color:t,fontSize:this.#r,value:this.#u()});this.addComment(n);if(e){n.isCopy=!0;return n}if(this.annotationElementId&&!this.#f(n))return null;n.id=this.annotationElementId;return n}#f(e){let{value:t,fontSize:n,color:r,pageIndex:i}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||e.value!==t||e.fontSize!==n||e.color.some((e,t)=>e!==r[t])||e.pageIndex!==i}renderAnnotationElement(e){let t=super.renderAnnotationElement(e);if(!t)return null;let{style:n}=t;n.fontSize=`calc(${this.#r}px * var(--total-scale-factor))`;n.color=this.color;t.replaceChildren();for(let e of this.#e.split(`
|
|
57
|
+
`)){let n=document.createElement(`div`);n.append(e?document.createTextNode(e):document.createElement(`br`));t.append(n)}e.updateEdited({rect:this.getPDFRect(),popup:this._uiManager.hasCommentManager()||this.hasEditedComment?this.comment:{text:this.#e}});return t}resetAnnotationElement(e){super.resetAnnotationElement(e);e.resetEdited()}}class Z{static PRECISION=1e-4;toSVGPath(){D("Abstract method `toSVGPath` must be implemented.")}get box(){D("Abstract getter `box` must be implemented.")}serialize(e,t){D("Abstract method `serialize` must be implemented.")}static _rescale(e,t,n,r,i,a){a||=new Float32Array(e.length);for(let o=0,s=e.length;o<s;o+=2){a[o]=t+e[o]*r;a[o+1]=n+e[o+1]*i}return a}static _rescaleAndSwap(e,t,n,r,i,a){a||=new Float32Array(e.length);for(let o=0,s=e.length;o<s;o+=2){a[o]=t+e[o+1]*r;a[o+1]=n+e[o]*i}return a}static _translate(e,t,n,r){r||=new Float32Array(e.length);for(let i=0,a=e.length;i<a;i+=2){r[i]=t+e[i];r[i+1]=n+e[i+1]}return r}static svgRound(e){return Math.round(1e4*e)}static _normalizePoint(e,t,n,r,i){switch(i){case 90:return[1-t/n,e/r];case 180:return[1-e/n,1-t/r];case 270:return[t/n,1-e/r];default:return[e/n,t/r]}}static _normalizePagePoint(e,t,n){switch(n){case 90:return[1-t,e];case 180:return[1-e,1-t];case 270:return[t,1-e];default:return[e,t]}}static createBezierPoints(e,t,n,r,i,a){return[(e+5*n)/6,(t+5*r)/6,(5*n+i)/6,(5*r+a)/6,(n+i)/2,(r+a)/2]}}class gr{#e;#t=[];#n;#r;#i=[];#a=new Float32Array(18);#o;#s;#c;#l;#u;#d;#f=[];static#p=8;static#m=2;static#h=gr.#p+gr.#m;constructor({x:e,y:t},n,r,i,a,o=0){this.#e=n;this.#d=i*r;this.#r=a;this.#a.set([NaN,NaN,NaN,NaN,e,t],6);this.#n=o;this.#l=gr.#p*r;this.#c=gr.#h*r;this.#u=r;this.#f.push(e,t)}isEmpty(){return isNaN(this.#a[8])}#g(){let e=this.#a.subarray(4,6),t=this.#a.subarray(16,18),[n,r,i,a]=this.#e;return[(this.#o+(e[0]-t[0])/2-n)/i,(this.#s+(e[1]-t[1])/2-r)/a,(this.#o+(t[0]-e[0])/2-n)/i,(this.#s+(t[1]-e[1])/2-r)/a]}add({x:e,y:t}){this.#o=e;this.#s=t;let[n,r,i,a]=this.#e,[o,s,c,l]=this.#a.subarray(8,12),u=e-c,d=t-l,f=Math.hypot(u,d);if(f<this.#c)return!1;let p=f-this.#l,m=p/f,h=m*u,g=m*d,_=o,v=s;o=c;s=l;c+=h;l+=g;this.#f?.push(e,t);let y=h/p,b=-g/p*this.#d,x=y*this.#d;this.#a.set(this.#a.subarray(2,8),0);this.#a.set([c+b,l+x],4);this.#a.set(this.#a.subarray(14,18),12);this.#a.set([c-b,l-x],16);if(isNaN(this.#a[6])){if(this.#i.length===0){this.#a.set([o+b,s+x],2);this.#i.push(NaN,NaN,NaN,NaN,(o+b-n)/i,(s+x-r)/a);this.#a.set([o-b,s-x],14);this.#t.push(NaN,NaN,NaN,NaN,(o-b-n)/i,(s-x-r)/a)}this.#a.set([_,v,o,s,c,l],6);return!this.isEmpty()}this.#a.set([_,v,o,s,c,l],6);if(Math.abs(Math.atan2(v-s,_-o)-Math.atan2(g,h))<Math.PI/2){[o,s,c,l]=this.#a.subarray(2,6);this.#i.push(NaN,NaN,NaN,NaN,((o+c)/2-n)/i,((s+l)/2-r)/a);[o,s,_,v]=this.#a.subarray(14,18);this.#t.push(NaN,NaN,NaN,NaN,((_+o)/2-n)/i,((v+s)/2-r)/a);return!0}[_,v,o,s,c,l]=this.#a.subarray(0,6);this.#i.push(((_+5*o)/6-n)/i,((v+5*s)/6-r)/a,((5*o+c)/6-n)/i,((5*s+l)/6-r)/a,((o+c)/2-n)/i,((s+l)/2-r)/a);[c,l,o,s,_,v]=this.#a.subarray(12,18);this.#t.push(((_+5*o)/6-n)/i,((v+5*s)/6-r)/a,((5*o+c)/6-n)/i,((5*s+l)/6-r)/a,((o+c)/2-n)/i,((s+l)/2-r)/a);return!0}toSVGPath(){if(this.isEmpty())return``;let e=this.#i,t=this.#t;if(isNaN(this.#a[6])&&!this.isEmpty())return this.#_();let n=[];n.push(`M${e[4]} ${e[5]}`);for(let t=6;t<e.length;t+=6)isNaN(e[t])?n.push(`L${e[t+4]} ${e[t+5]}`):n.push(`C${e[t]} ${e[t+1]} ${e[t+2]} ${e[t+3]} ${e[t+4]} ${e[t+5]}`);this.#y(n);for(let e=t.length-6;e>=6;e-=6)isNaN(t[e])?n.push(`L${t[e+4]} ${t[e+5]}`):n.push(`C${t[e]} ${t[e+1]} ${t[e+2]} ${t[e+3]} ${t[e+4]} ${t[e+5]}`);this.#v(n);return n.join(` `)}#_(){let[e,t,n,r]=this.#e,[i,a,o,s]=this.#g();return`M${(this.#a[2]-e)/n} ${(this.#a[3]-t)/r} L${(this.#a[4]-e)/n} ${(this.#a[5]-t)/r} L${i} ${a} L${o} ${s} L${(this.#a[16]-e)/n} ${(this.#a[17]-t)/r} L${(this.#a[14]-e)/n} ${(this.#a[15]-t)/r} Z`}#v(e){let t=this.#t;e.push(`L${t[4]} ${t[5]} Z`)}#y(e){let[t,n,r,i]=this.#e,a=this.#a.subarray(4,6),o=this.#a.subarray(16,18),[s,c,l,u]=this.#g();e.push(`L${(a[0]-t)/r} ${(a[1]-n)/i} L${s} ${c} L${l} ${u} L${(o[0]-t)/r} ${(o[1]-n)/i}`)}newFreeDrawOutline(e,t,n,r,i,a){return new _r(e,t,n,r,i,a)}getOutlines(){let e=this.#i,t=this.#t,n=this.#a,[r,i,a,o]=this.#e,s=new Float32Array((this.#f?.length??0)+2);for(let e=0,t=s.length-2;e<t;e+=2){s[e]=(this.#f[e]-r)/a;s[e+1]=(this.#f[e+1]-i)/o}s[s.length-2]=(this.#o-r)/a;s[s.length-1]=(this.#s-i)/o;if(isNaN(n[6])&&!this.isEmpty())return this.#b(s);let c=new Float32Array(this.#i.length+24+this.#t.length),l=e.length;for(let t=0;t<l;t+=2)if(isNaN(e[t]))c[t]=c[t+1]=NaN;else{c[t]=e[t];c[t+1]=e[t+1]}l=this.#S(c,l);for(let e=t.length-6;e>=6;e-=6)for(let n=0;n<6;n+=2)if(isNaN(t[e+n])){c[l]=c[l+1]=NaN;l+=2}else{c[l]=t[e+n];c[l+1]=t[e+n+1];l+=2}this.#x(c,l);return this.newFreeDrawOutline(c,s,this.#e,this.#u,this.#n,this.#r)}#b(e){let t=this.#a,[n,r,i,a]=this.#e,[o,s,c,l]=this.#g(),u=new Float32Array(36);u.set([NaN,NaN,NaN,NaN,(t[2]-n)/i,(t[3]-r)/a,NaN,NaN,NaN,NaN,(t[4]-n)/i,(t[5]-r)/a,NaN,NaN,NaN,NaN,o,s,NaN,NaN,NaN,NaN,c,l,NaN,NaN,NaN,NaN,(t[16]-n)/i,(t[17]-r)/a,NaN,NaN,NaN,NaN,(t[14]-n)/i,(t[15]-r)/a],0);return this.newFreeDrawOutline(u,e,this.#e,this.#u,this.#n,this.#r)}#x(e,t){let n=this.#t;e.set([NaN,NaN,NaN,NaN,n[4],n[5]],t);return t+6}#S(e,t){let n=this.#a.subarray(4,6),r=this.#a.subarray(16,18),[i,a,o,s]=this.#e,[c,l,u,d]=this.#g();e.set([NaN,NaN,NaN,NaN,(n[0]-i)/o,(n[1]-a)/s,NaN,NaN,NaN,NaN,c,l,NaN,NaN,NaN,NaN,u,d,NaN,NaN,NaN,NaN,(r[0]-i)/o,(r[1]-a)/s],t);return t+24}}class _r extends Z{#e;#t=new Float32Array(4);#n;#r;#i;#a;#o;constructor(e,t,n,r,i,a){super();this.#o=e;this.#i=t;this.#e=n;this.#a=r;this.#n=i;this.#r=a;this.firstPoint=[NaN,NaN];this.lastPoint=[NaN,NaN];this.#s(a);let[o,s,c,l]=this.#t;for(let t=0,n=e.length;t<n;t+=2){e[t]=(e[t]-o)/c;e[t+1]=(e[t+1]-s)/l}for(let e=0,n=t.length;e<n;e+=2){t[e]=(t[e]-o)/c;t[e+1]=(t[e+1]-s)/l}}toSVGPath(){let e=[`M${this.#o[4]} ${this.#o[5]}`];for(let t=6,n=this.#o.length;t<n;t+=6)isNaN(this.#o[t])?e.push(`L${this.#o[t+4]} ${this.#o[t+5]}`):e.push(`C${this.#o[t]} ${this.#o[t+1]} ${this.#o[t+2]} ${this.#o[t+3]} ${this.#o[t+4]} ${this.#o[t+5]}`);e.push(`Z`);return e.join(` `)}serialize([e,t,n,r],i){let a=n-e,o=r-t,s,c;switch(i){case 0:s=Z._rescale(this.#o,e,r,a,-o);c=Z._rescale(this.#i,e,r,a,-o);break;case 90:s=Z._rescaleAndSwap(this.#o,e,t,a,o);c=Z._rescaleAndSwap(this.#i,e,t,a,o);break;case 180:s=Z._rescale(this.#o,n,t,-a,o);c=Z._rescale(this.#i,n,t,-a,o);break;case 270:s=Z._rescaleAndSwap(this.#o,n,r,-a,-o);c=Z._rescaleAndSwap(this.#i,n,r,-a,-o)}return{outline:Array.from(s),points:[Array.from(c)]}}#s(e){let t=this.#o,n=t[4],r=t[5],i=[n,r,n,r],a=n,o=r,s=n,c=r,l=e?Math.max:Math.min,d=new Float32Array(4);for(let e=6,f=t.length;e<f;e+=6){let f=t[e+4],p=t[e+5];if(isNaN(t[e])){P.pointBoundingBox(f,p,i);if(o>p){a=f;o=p}else o===p&&(a=l(a,f));if(c<p){s=f;c=p}else c===p&&(s=l(s,f))}else{d.set(u,0);P.bezierBoundingBox(n,r,...t.slice(e,e+6),d);P.rectBoundingBox(...d,i);if(o>d[1]){a=d[0];o=d[1]}else o===d[1]&&(a=l(a,d[0]));if(c<d[3]){s=d[2];c=d[3]}else c===d[3]&&(s=l(s,d[2]))}n=f;r=p}let f=this.#t;f[0]=i[0]-this.#n;f[1]=i[1]-this.#n;f[2]=i[2]-i[0]+2*this.#n;f[3]=i[3]-i[1]+2*this.#n;this.firstPoint=[a,o];this.lastPoint=[s,c]}get box(){return this.#t}newOutliner(e,t,n,r,i,a=0){return new gr(e,t,n,r,i,a)}getNewOutline(e,t){let[n,r,i,a]=this.#t,[o,s,c,l]=this.#e,u=i*c,d=a*l,f=n*c+o,p=r*l+s,m=this.newOutliner({x:this.#i[0]*u+f,y:this.#i[1]*d+p},this.#e,this.#a,e,this.#r,t??this.#n);for(let e=2;e<this.#i.length;e+=2)m.add({x:this.#i[e]*u+f,y:this.#i[e+1]*d+p});return m.getOutlines()}}class vr{#e;#t;#n;#r=[];#i=[];constructor(e,t=0,n=0,r=!0){let i=u.slice(),a=1e-4;for(let{x:n,y:r,width:o,height:s}of e){let e=Math.floor((n-t)/a)*a,c=Math.ceil((n+o+t)/a)*a,l=Math.floor((r-t)/a)*a,u=Math.ceil((r+s+t)/a)*a,d=[e,l,u,!0],f=[c,l,u,!1];this.#r.push(d,f);P.rectBoundingBox(e,l,c,u,i)}let o=i[2]-i[0]+2*n,s=i[3]-i[1]+2*n,c=i[0]-n,l=i[1]-n,d=r?-1/0:1/0,f=1/0,p=this.#r.at(r?-1:-2),m=[p[0],p[2]];for(let e of this.#r){let[t,n,i,a]=e;if(!a&&r){if(n<f){f=n;d=t}else n===f&&(d=Math.max(d,t))}else if(a&&!r){if(n<f){f=n;d=t}else n===f&&(d=Math.min(d,t))}e[0]=(t-c)/o;e[1]=(n-l)/s;e[2]=(i-l)/s}this.#e=new Float32Array([c,l,o,s]);this.#t=[d,f];this.#n=m}getOutlines(){this.#r.sort((e,t)=>e[0]-t[0]||e[1]-t[1]||e[2]-t[2]);let e=[];for(let t of this.#r)if(t[3]){e.push(...this.#l(t));this.#s(t)}else{this.#c(t);e.push(...this.#l(t))}return this.#a(e)}#a(e){let t=[],n=new Set;for(let n of e){let[e,r,i]=n;t.push([e,r,n],[e,i,n])}t.sort((e,t)=>e[1]-t[1]||e[0]-t[0]);for(let e=0,r=t.length;e<r;e+=2){let r=t[e][2],i=t[e+1][2];r.push(i);i.push(r);n.add(r);n.add(i)}let r=[],i;for(;n.size>0;){let e=n.values().next().value,[t,a,o,s,c]=e;n.delete(e);let l=t,u=a;i=[t,o];r.push(i);for(;;){let e;if(n.has(s))e=s;else{if(!n.has(c))break;e=c}n.delete(e);[t,a,o,s,c]=e;if(l!==t){i.push(l,u,t,u===a?a:o);l=t}u=u===a?o:a}i.push(l,u)}return new yr(r,this.#e,this.#t,this.#n)}#o(e){let t=this.#i,n=0,r=t.length-1;for(;n<=r;){let i=n+r>>1,a=t[i][0];if(a===e)return i;a<e?n=i+1:r=i-1}return r+1}#s([,e,t]){let n=this.#o(e);this.#i.splice(n,0,[e,t])}#c([,e,t]){let n=this.#o(e);for(let r=n;r<this.#i.length;r++){let[n,i]=this.#i[r];if(n!==e)break;if(n===e&&i===t){this.#i.splice(r,1);return}}for(let r=n-1;r>=0;r--){let[n,i]=this.#i[r];if(n!==e)break;if(n===e&&i===t){this.#i.splice(r,1);return}}}#l(e){let[t,n,r]=e,i=[[t,n,r]],a=this.#o(r);for(let e=0;e<a;e++){let[n,r]=this.#i[e];for(let e=0,a=i.length;e<a;e++){let[,o,s]=i[e];if(!(r<=o||s<=n)){if(o>=n){if(s>r)i[e][1]=r;else{if(a===1)return[];i.splice(e,1);e--;a--}}else{i[e][2]=n;s>r&&i.push([t,r,s])}}}}return i}}class yr extends Z{#e;#t;constructor(e,t,n,r){super();this.#t=e;this.#e=t;this.firstPoint=n;this.lastPoint=r}toSVGPath(){let e=[];for(let t of this.#t){let[n,r]=t;e.push(`M${n} ${r}`);for(let i=2;i<t.length;i+=2){let a=t[i],o=t[i+1];if(a===n){e.push(`V${o}`);r=o}else if(o===r){e.push(`H${a}`);n=a}}e.push(`Z`)}return e.join(` `)}serialize([e,t,n,r],i){let a=[],o=n-e,s=r-t;for(let t of this.#t){let n=Array(t.length);for(let i=0;i<t.length;i+=2){n[i]=e+t[i]*o;n[i+1]=r-t[i+1]*s}a.push(n)}return a}get box(){return this.#e}get classNamesForOutlining(){return[`highlightOutline`]}}class br extends gr{newFreeDrawOutline(e,t,n,r,i,a){return new xr(e,t,n,r,i,a)}}class xr extends _r{newOutliner(e,t,n,r,i,a=0){return new br(e,t,n,r,i,a)}}class Q extends H{#e=null;#t=0;#n;#r=null;#i=null;#a=null;#o=null;#s=0;#c=null;#l=null;#u=null;#d=!1;#f=null;#p=null;#m=null;#h=``;#g;#_=``;static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type=`highlight`;static _editorType=_.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId=``;static get _keyboardManager(){let e=Q.prototype;return j(this,`_keyboardManager`,new Ie([[[`ArrowLeft`,`mac+ArrowLeft`],e._moveCaret,{args:[0]}],[[`ArrowRight`,`mac+ArrowRight`],e._moveCaret,{args:[1]}],[[`ArrowUp`,`mac+ArrowUp`],e._moveCaret,{args:[2]}],[[`ArrowDown`,`mac+ArrowDown`],e._moveCaret,{args:[3]}]]))}constructor(e){super({...e,name:`highlightEditor`});this.color=e.color||Q._defaultColor;this.#g=e.thickness||Q._defaultThickness;this.opacity=e.opacity||Q._defaultOpacity;this.#n=e.boxes||null;this.#_=e.methodOfCreation||``;this.#h=e.text||``;this._isDraggable=!1;this.defaultL10nId=`pdfjs-editor-highlight-editor`;if(e.highlightId>-1){this.#d=!0;this.#y(e);this.#w()}else if(this.#n){this.#e=e.anchorNode;this.#t=e.anchorOffset;this.#o=e.focusNode;this.#s=e.focusOffset;this.#v();this.#w();this.rotate(this.rotation)}this.annotationElementId||this._uiManager.a11yAlert(H._l10nAlert.highlight)}get telemetryInitialData(){return{action:`added`,type:this.#d?`free_highlight`:`highlight`,color:this._uiManager.getNonHCMColorName(this.color),thickness:this.#g,methodOfCreation:this.#_}}get telemetryFinalData(){return{type:`highlight`,color:this._uiManager.getNonHCMColorName(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get(`color`).size}}#v(){let e=new vr(this.#n,.001);this.#l=e.getOutlines();[this.x,this.y,this.width,this.height]=this.#l.box;let t=new vr(this.#n,.0025,.001,this._uiManager.direction===`ltr`);this.#a=t.getOutlines();let{firstPoint:n}=this.#l;this.#f=[(n[0]-this.x)/this.width,(n[1]-this.y)/this.height];let{lastPoint:r}=this.#a;this.#p=[(r[0]-this.x)/this.width,(r[1]-this.y)/this.height]}#y({highlightOutlines:e,highlightId:t,clipPathId:n}){this.#l=e;this.#a=e.getNewOutline(this.#g/2+1.5,.0025);if(t>=0){this.#u=t;this.#r=n;this.parent.drawLayer.finalizeDraw(t,{bbox:e.box,path:{d:e.toSVGPath()}});this.#m=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#a.box,path:{d:this.#a.toSVGPath()}},!0)}else if(this.parent){let t=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#u,{bbox:Q.#T(this.#l.box,(t-this.rotation+360)%360),path:{d:e.toSVGPath()}});this.parent.drawLayer.updateProperties(this.#m,{bbox:Q.#T(this.#a.box,t),path:{d:this.#a.toSVGPath()}})}let[r,i,a,o]=e.box;switch(this.rotation){case 0:this.x=r;this.y=i;this.width=a;this.height=o;break;case 90:{let[e,t]=this.parentDimensions;this.x=i;this.y=1-r;this.width=a*t/e;this.height=o*e/t;break}case 180:this.x=1-r;this.y=1-i;this.width=a;this.height=o;break;case 270:{let[e,t]=this.parentDimensions;this.x=1-i;this.y=r;this.width=a*t/e;this.height=o*e/t;break}}let{firstPoint:s}=e;this.#f=[(s[0]-r)/a,(s[1]-i)/o];let{lastPoint:c}=this.#a;this.#p=[(c[0]-r)/a,(c[1]-i)/o]}static initialize(e,t){H.initialize(e,t);Q._defaultColor||=t.highlightColors?.values().next().value||`#fff066`}static updateDefaultParams(e,t){switch(e){case v.HIGHLIGHT_COLOR:Q._defaultColor=t;break;case v.HIGHLIGHT_THICKNESS:Q._defaultThickness=t}}translateInPage(e,t){}get toolbarPosition(){return this.#p}get commentButtonPosition(){return this.#f}updateParams(e,t){switch(e){case v.HIGHLIGHT_COLOR:this.#b(t);break;case v.HIGHLIGHT_THICKNESS:this.#x(t)}}static get defaultPropertiesToUpdate(){return[[v.HIGHLIGHT_COLOR,Q._defaultColor],[v.HIGHLIGHT_THICKNESS,Q._defaultThickness]]}get propertiesToUpdate(){return[[v.HIGHLIGHT_COLOR,this.color||Q._defaultColor],[v.HIGHLIGHT_THICKNESS,this.#g||Q._defaultThickness],[v.HIGHLIGHT_FREE,this.#d]]}onUpdatedColor(){this.parent?.drawLayer.updateProperties(this.#u,{root:{fill:this.color,"fill-opacity":this.opacity}});this.#i?.updateColor(this.color);super.onUpdatedColor()}#b(e){let t=(e,t)=>{this.color=e;this.opacity=t;this.onUpdatedColor()},n=this.color,r=this.opacity;this.addCommands({cmd:t.bind(this,e,Q._defaultOpacity),undo:t.bind(this,n,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:v.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0});this._reportTelemetry({action:`color_changed`,color:this._uiManager.getNonHCMColorName(e)},!0)}#x(e){let t=this.#g,n=e=>{this.#g=e;this.#S(e)};this.addCommands({cmd:n.bind(this,e),undo:n.bind(this,t),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:v.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0});this._reportTelemetry({action:`thickness_changed`,thickness:e},!0)}get toolbarButtons(){if(this._uiManager.highlightColors)return[[`colorPicker`,this.#i=new Y({editor:this})]];return super.toolbarButtons}disableEditing(){super.disableEditing();this.div.classList.toggle(`disabled`,!0)}enableEditing(){super.enableEditing();this.div.classList.toggle(`disabled`,!1)}fixAndSetPosition(){return super.fixAndSetPosition(this.#O())}getBaseTranslation(){return[0,0]}getRect(e,t){return super.getRect(e,t,this.#O())}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this);e&&this.div.focus()}remove(){this.#C();this._reportTelemetry({action:`deleted`});super.remove()}rebuild(){if(this.parent){super.rebuild();if(this.div!==null){this.#w();this.isAttachedToDOM||this.parent.add(this)}}}setParent(e){let t=!1;if(this.parent&&!e)this.#C();else if(e){this.#w(e);t=!this.parent&&this.div?.classList.contains(`selectedEditor`)}super.setParent(e);this.show(this._isVisible);t&&this.select()}#S(e){if(this.#d){this.#y({highlightOutlines:this.#l.getNewOutline(e/2)});this.fixAndSetPosition();this.setDims()}}#C(){if(this.#u!==null&&this.parent){this.parent.drawLayer.remove(this.#u);this.#u=null;this.parent.drawLayer.remove(this.#m);this.#m=null}}#w(e=this.parent){if(this.#u===null){({id:this.#u,clipPathId:this.#r}=e.drawLayer.draw({bbox:this.#l.box,root:{viewBox:`0 0 1 1`,fill:this.color,"fill-opacity":this.opacity},rootClass:{highlight:!0,free:this.#d},path:{d:this.#l.toSVGPath()}},!1,!0));this.#m=e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#d},bbox:this.#a.box,path:{d:this.#a.toSVGPath()}},this.#d);this.#c&&(this.#c.style.clipPath=this.#r)}}static#T([e,t,n,r],i){switch(i){case 90:return[1-t-r,e,r,n];case 180:return[1-e-n,1-t-r,n,r];case 270:return[t,1-e-n,r,n]}return[e,t,n,r]}rotate(e){let{drawLayer:t}=this.parent,n;if(this.#d){e=(e-this.rotation+360)%360;n=Q.#T(this.#l.box,e)}else n=Q.#T([this.x,this.y,this.width,this.height],e);t.updateProperties(this.#u,{bbox:n,root:{"data-main-rotation":e}});t.updateProperties(this.#m,{bbox:Q.#T(this.#a.box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;let e=super.render();if(this.#h){e.setAttribute(`aria-label`,this.#h);e.setAttribute(`role`,`mark`)}this.#d?e.classList.add(`free`):this.div.addEventListener(`keydown`,this.#E.bind(this),{signal:this._uiManager._signal});let t=this.#c=document.createElement(`div`);e.append(t);t.setAttribute(`aria-hidden`,`true`);t.className=`internal`;t.style.clipPath=this.#r;this.setDims();Me(this,this.#c,[`pointerover`,`pointerleave`]);this.enableEditing();return e}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{hovered:!1}})}#E(e){Q._keyboardManager.exec(this,e)}_moveCaret(e){this.parent.unselect(this);switch(e){case 0:case 2:this.#D(!0);break;case 1:case 3:this.#D(!1)}}#D(e){if(!this.#e)return;let t=window.getSelection();e?t.setPosition(this.#e,this.#t):t.setPosition(this.#o,this.#s)}select(){super.select();this.#m&&this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect();if(this.#m){this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{selected:!1}});this.#d||this.#D(!1)}}get _mustFixPosition(){return!this.#d}show(e=this._isVisible){super.show(e);if(this.parent){this.parent.drawLayer.updateProperties(this.#u,{rootClass:{hidden:!e}});this.parent.drawLayer.updateProperties(this.#m,{rootClass:{hidden:!e}})}}#O(){return this.#d?this.rotation:0}#k(){if(this.#d)return null;let[e,t]=this.pageDimensions,[n,r]=this.pageTranslation,i=this.#n,a=new Float32Array(8*i.length),o=0;for(let{x:s,y:c,width:l,height:u}of i){let i=s*e+n,d=(1-c)*t+r;a[o]=a[o+4]=i;a[o+1]=a[o+3]=d;a[o+2]=a[o+6]=i+l*e;a[o+5]=a[o+7]=d-u*t;o+=8}return a}#A(e){return this.#l.serialize(e,this.#O())}static startHighlighting(e,t,{target:n,x:r,y:i}){let{x:a,y:o,width:s,height:c}=n.getBoundingClientRect(),l=new AbortController,u=e.combinedSignal(l),d=t=>{l.abort();this.#M(e,t)};window.addEventListener(`blur`,d,{signal:u});window.addEventListener(`pointerup`,d,{signal:u});window.addEventListener(`pointerdown`,R,{capture:!0,passive:!1,signal:u});window.addEventListener(`contextmenu`,L,{signal:u});n.addEventListener(`pointermove`,this.#j.bind(this,e),{signal:u});this._freeHighlight=new br({x:r,y:i},[a,o,s,c],e.scale,this._defaultThickness/2,t,.001);({id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:`0 0 1 1`,fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0))}static#j(e,t){this._freeHighlight.add(t)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#M(e,t){this._freeHighlight.isEmpty()?e.drawLayer.remove(this._freeHighlightId):e.createAndAddNewEditor(t,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:`main_toolbar`});this._freeHighlightId=-1;this._freeHighlight=null;this._freeHighlightClipId=``}static async deserialize(e,t,n){let r=null;if(e instanceof pr){let{data:{quadPoints:t,rect:n,rotation:i,id:a,color:o,opacity:s,popupRef:c,richText:l,contentsObj:u,creationDate:d,modificationDate:f},parent:{page:{pageNumber:p}}}=e;r=e={annotationType:_.HIGHLIGHT,color:Array.from(o),opacity:s,quadPoints:t,boxes:null,pageIndex:p-1,rect:n.slice(0),rotation:i,annotationElementId:a,id:a,deleted:!1,popupRef:c,richText:l,comment:u?.str||null,creationDate:d,modificationDate:f}}else if(e instanceof fr){let{data:{inkLists:t,rect:n,rotation:i,id:a,color:o,borderStyle:{rawWidth:s},popupRef:c,richText:l,contentsObj:u,creationDate:d,modificationDate:f},parent:{page:{pageNumber:p}}}=e;r=e={annotationType:_.HIGHLIGHT,color:Array.from(o),thickness:s,inkLists:t,boxes:null,pageIndex:p-1,rect:n.slice(0),rotation:i,annotationElementId:a,id:a,deleted:!1,popupRef:c,richText:l,comment:u?.str||null,creationDate:d,modificationDate:f}}let{color:i,quadPoints:a,inkLists:o,outlines:s,opacity:c}=e,l=await super.deserialize(e,t,n);l.color=P.makeHexColor(...i);l.opacity=c||1;o&&(l.#g=e.thickness);l._initialData=r;e.comment&&l.setCommentData(e);let[u,d]=l.pageDimensions,[f,p]=l.pageTranslation;if(a){let e=l.#n=[];for(let t=0;t<a.length;t+=8)e.push({x:(a[t]-f)/u,y:1-(a[t+1]-p)/d,width:(a[t+2]-a[t])/u,height:(a[t+1]-a[t+5])/d});l.#v();l.#w();l.rotate(l.rotation)}else if(o||s){l.#d=!0;let e=(o||s.points)[0],n={x:e[0]-f,y:d-(e[1]-p)},r=new br(n,[0,0,u,d],1,l.#g/2,!0,.001);for(let t=0,i=e.length;t<i;t+=2){n.x=e[t]-f;n.y=d-(e[t+1]-p);r.add(n)}let{id:i,clipPathId:a}=t.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:`0 0 1 1`,fill:l.color,"fill-opacity":l._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:r.toSVGPath()}},!0,!0);l.#y({highlightOutlines:r.getOutlines(),highlightId:i,clipPathId:a});l.#w();l.rotate(l.parentRotation)}return l}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();let t=H._colorManager.convert(this._uiManager.getNonHCMColor(this.color)),n=super.serialize(e);Object.assign(n,{color:t,opacity:this.opacity,thickness:this.#g,quadPoints:this.#k(),outlines:this.#A(n.rect)});this.addComment(n);if(this.annotationElementId&&!this.#N(n))return null;n.id=this.annotationElementId;return n}#N(e){let{color:t}=this._initialData;return this.hasEditedComment||e.color.some((e,n)=>e!==t[n])}renderAnnotationElement(e){if(this.deleted){e.hide();return null}e.updateEdited({rect:this.getPDFRect(),popup:this.comment});return null}static canCreateNewEmptyEditor(){return!1}}class Sr{#e=Object.create(null);updateProperty(e,t){this[e]=t;this.updateSVGProperty(e,t)}updateProperties(e){if(e)for(let[t,n]of Object.entries(e))t.startsWith(`_`)||this.updateProperty(t,n)}updateSVGProperty(e,t){this.#e[e]=t}toSVGProperties(){let e=this.#e;this.#e=Object.create(null);return{root:e}}reset(){this.#e=Object.create(null)}updateAll(e=this){this.updateProperties(e)}clone(){D(`Not implemented`)}}class $ extends H{#e=null;#t;_colorPicker=null;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#n=null;static#r=null;static#i=null;static _INNER_MARGIN=3;constructor(e){super(e);this.#t=e.mustBeCommitted||!1;this._addOutlines(e)}onUpdatedColor(){this._colorPicker?.update(this.color);super.onUpdatedColor()}onUpdatedOpacity(){this._colorPicker?.updateOpacity?.(this.opacity)}_addOutlines(e){if(e.drawOutlines){this.#a(e);this.#c()}}#a({drawOutlines:e,drawId:t,drawingOptions:n}){this.#e=e;this._drawingOptions||=n;this.annotationElementId||this._uiManager.a11yAlert(H._l10nAlert[this.editorType]);if(t>=0){this._drawId=t;this.parent.drawLayer.finalizeDraw(t,e.defaultProperties)}else this._drawId=this.#o(e,this.parent);this.#d(e.box)}#o(e,t){let{id:n}=t.drawLayer.draw($._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return n}static _mergeSVGProperties(e,t){let n=new Set(Object.keys(e));for(let[r,i]of Object.entries(t))n.has(r)?Object.assign(e[r],i):e[r]=i;return e}static getDefaultDrawingOptions(e){D(`Not implemented`)}static get typesMap(){D(`Not implemented`)}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,t){let n=this.typesMap.get(e);n&&this._defaultDrawingOptions.updateProperty(n,t);if(this._currentParent){$.#n.updateProperty(n,t);this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties())}}updateParams(e,t){let n=this.constructor.typesMap.get(e);n&&this._updateProperty(e,n,t)}static get defaultPropertiesToUpdate(){let e=[],t=this._defaultDrawingOptions;for(let[n,r]of this.typesMap)e.push([n,t[r]]);return e}get propertiesToUpdate(){let e=[],{_drawingOptions:t}=this;for(let[n,r]of this.constructor.typesMap)e.push([n,t[r]]);return e}_updateProperty(e,t,n){let r=this._drawingOptions,i=r[t],a=n=>{r.updateProperty(t,n);let i=this.#e.updateProperty(t,n);i&&this.#d(i);this.parent?.drawLayer.updateProperties(this._drawId,r.toSVGProperties());e===this.colorType?this.onUpdatedColor():e===this.opacityType&&this.onUpdatedOpacity()};this.addCommands({cmd:a.bind(this,n),undo:a.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_updateColorAndOpacity(e,t){let n=this.constructor.typesMap.get(this.colorType),r=this.constructor.typesMap.get(this.opacityType),i=this._drawingOptions,a=i[n],o=i[r],s=(e,t)=>{i.updateProperty(n,e);i.updateProperty(r,t);this.#e.updateProperty(n,e);this.#e.updateProperty(r,t);this.parent?.drawLayer.updateProperties(this._drawId,i.toSVGProperties());this.onUpdatedColor();this.onUpdatedOpacity()};this.addCommands({cmd:s.bind(this,e,t),undo:s.bind(this,a,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:v.INK_COLOR_AND_OPACITY,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,$._mergeSVGProperties(this.#e.getPathResizingSVGProperties(this.#u()),{bbox:this.#f()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,$._mergeSVGProperties(this.#e.getPathResizedSVGProperties(this.#u()),{bbox:this.#f()}))}_onTranslating(e,t){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#f()})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,$._mergeSVGProperties(this.#e.getPathTranslatedSVGProperties(this.#u(),this.parentDimensions),{bbox:this.#f()}))}_onStartDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit();this.disableEditMode();this.disableEditing()}disableEditing(){super.disableEditing();this.div.classList.toggle(`disabled`,!0)}enableEditing(){super.enableEditing();this.div.classList.toggle(`disabled`,!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this);this._isDraggable=!0;if(this.#t){this.#t=!1;this.commit();this.parent.setSelected(this);e&&this.isOnScreen&&this.div.focus()}}remove(){this.#s();super.remove()}rebuild(){if(this.parent){super.rebuild();if(this.div!==null){this.#c();this.#d(this.#e.box);this.isAttachedToDOM||this.parent.add(this)}}}setParent(e){let t=!1;if(this.parent&&!e){this._uiManager.removeShouldRescale(this);this.#s()}else if(e){this._uiManager.addShouldRescale(this);this.#c(e);t=!this.parent&&this.div?.classList.contains(`selectedEditor`)}super.setParent(e);t&&this.select()}#s(){if(this._drawId!==null&&this.parent){this.parent.drawLayer.remove(this._drawId);this._drawId=null;this._drawingOptions.reset()}}#c(e=this.parent){if(this._drawId===null||this.parent!==e){if(this._drawId===null){this._drawingOptions.updateAll();this._drawId=this.#o(this.#e,e)}else this.parent.drawLayer.updateParent(this._drawId,e.drawLayer)}}#l([e,t,n,r]){let{parentDimensions:[i,a],rotation:o}=this;switch(o){case 90:return[t,1-e,a/i*n,i/a*r];case 180:return[1-e,1-t,n,r];case 270:return[1-t,e,a/i*n,i/a*r];default:return[e,t,n,r]}}#u(){let{x:e,y:t,width:n,height:r,parentDimensions:[i,a],rotation:o}=this;switch(o){case 90:return[1-t,e,i/a*n,a/i*r];case 180:return[1-e,1-t,n,r];case 270:return[t,1-e,i/a*n,a/i*r];default:return[e,t,n,r]}}#d(e){[this.x,this.y,this.width,this.height]=this.#l(e);if(this.div){this.fixAndSetPosition();this.setDims()}this._onResized()}#f(){let{x:e,y:t,width:n,height:r,rotation:i,parentRotation:a,parentDimensions:[o,s]}=this;switch((4*i+a)/90){case 1:return[1-t-r,e,r,n];case 2:return[1-e-n,1-t-r,n,r];case 3:return[t,1-e-n,r,n];case 4:return[e,t-o/s*n,s/o*r,o/s*n];case 5:return[1-t,e,o/s*n,s/o*r];case 6:return[1-e-s/o*r,1-t,s/o*r,o/s*n];case 7:return[t-o/s*n,1-e-s/o*r,o/s*n,s/o*r];case 8:return[e-n,t-r,n,r];case 9:return[1-t,e-n,r,n];case 10:return[1-e,1-t,n,r];case 11:return[t-r,1-e,r,n];case 12:return[e-s/o*r,t,s/o*r,o/s*n];case 13:return[1-t-o/s*n,e-s/o*r,o/s*n,s/o*r];case 14:return[1-e,1-t-o/s*n,s/o*r,o/s*n];case 15:return[t,1-e,o/s*n,s/o*r];default:return[e,t,n,r]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,$._mergeSVGProperties({bbox:this.#f()},this.#e.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#d(this.#e.updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;let e,t;if(this._isCopy){e=this.x;t=this.y}let n=super.render();n.classList.add(`draw`);let r=document.createElement(`div`);n.append(r);r.setAttribute(`aria-hidden`,`true`);r.className=`internal`;this.setDims();this._uiManager.addShouldRescale(this);this.disableEditing();this._isCopy&&this._moveAfterPaste(e,t);return n}static createDrawerInstance(e,t,n,r,i){D(`Not implemented`)}static startDrawing(e,t,n,r){let{target:i,offsetX:a,offsetY:o,pointerId:s,pointerType:c}=r;if(V.isInitializedAndDifferentPointerType(c))return;let{viewport:{rotation:l}}=e,{width:u,height:d}=i.getBoundingClientRect(),f=$.#r=new AbortController,p=e.combinedSignal(f);V.setPointer(c,s);window.addEventListener(`pointerup`,e=>{V.isSamePointerIdOrRemove(e.pointerId)&&this._endDraw(e)},{signal:p});window.addEventListener(`pointercancel`,e=>{V.isSamePointerIdOrRemove(e.pointerId)&&this._currentParent.endDrawingSession()},{signal:p});window.addEventListener(`pointerdown`,e=>{if(V.isSamePointerType(e.pointerType)){V.initializeAndAddPointerId(e.pointerId);if($.#n.isCancellable()){$.#n.removeLastElement();$.#n.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)}}},{capture:!0,passive:!1,signal:p});window.addEventListener(`contextmenu`,L,{signal:p});i.addEventListener(`pointermove`,this._drawMove.bind(this),{signal:p});i.addEventListener(`touchmove`,e=>{V.isSameTimeStamp(e.timeStamp)&&R(e)},{signal:p});e.toggleDrawing();t._editorUndoBar?.hide();if($.#n)e.drawLayer.updateProperties(this._currentDrawId,$.#n.startNew(a,o,u,d,l));else{t.updateUIForDefaultProperties(this);$.#n=this.createDrawerInstance(a,o,u,d,l);$.#i=this.getDefaultDrawingOptions();this._currentParent=e;({id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties($.#i.toSVGProperties(),$.#n.defaultSVGProperties),!0,!1))}}static _drawMove(e){V.isSameTimeStamp(e.timeStamp);if(!$.#n)return;let{offsetX:t,offsetY:n,pointerId:r}=e;if(V.isSamePointerId(r)){if(V.isUsingMultiplePointers())this._endDraw(e);else{this._currentParent.drawLayer.updateProperties(this._currentDrawId,$.#n.add(t,n));V.setTimeStamp(e.timeStamp);R(e)}}}static _cleanup(e){if(e){this._currentDrawId=-1;this._currentParent=null;$.#n=null;$.#i=null;V.clearTimeStamp()}if($.#r){$.#r.abort();$.#r=null;V.clearPointerIds()}}static _endDraw(e){let t=this._currentParent;if(t){t.toggleDrawing(!0);this._cleanup(!1);e?.target===t.div&&t.drawLayer.updateProperties(this._currentDrawId,$.#n.end(e.offsetX,e.offsetY));if(this.supportMultipleDrawings){let e=$.#n,n=this._currentDrawId,r=e.getLastElement();t.addCommands({cmd:()=>{t.drawLayer.updateProperties(n,e.setLastElement(r))},undo:()=>{t.drawLayer.updateProperties(n,e.removeLastElement())},mustExec:!1,type:v.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){let t=this._currentParent;if(!t)return null;t.toggleDrawing(!0);t.cleanUndoStack(v.DRAW_STEP);if(!$.#n.isEmpty()){let{pageDimensions:[n,r],scale:i}=t,a=t.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:$.#n.getOutlines(n*i,r*i,i,this._INNER_MARGIN),drawingOptions:$.#i,mustBeCommitted:!e});this._cleanup(!0);return a}t.drawLayer.remove(this._currentDrawId);this._cleanup(!0);return null}createDrawingOptions(e){}static deserializeDraw(e,t,n,r,i,a){D(`Not implemented`)}static async deserialize(e,t,n){let{rawDims:{pageWidth:r,pageHeight:i,pageX:a,pageY:o}}=t.viewport,s=this.deserializeDraw(a,o,r,i,this._INNER_MARGIN,e),c=await super.deserialize(e,t,n);c.createDrawingOptions(e);c.#a({drawOutlines:s});c.#c();c.onScaleChanging();c.rotate();return c}serializeDraw(e){let[t,n]=this.pageTranslation,[r,i]=this.pageDimensions;return this.#e.serialize([t,n,r,i],e)}renderAnnotationElement(e){e.updateEdited({rect:this.getPDFRect()});return null}static canCreateNewEmptyEditor(){return!1}}class Cr{#e=new Float64Array(6);#t;#n;#r;#i;#a;#o=``;#s=0;#c=new wr;#l;#u;constructor(e,t,n,r,i,a){this.#l=n;this.#u=r;this.#r=i;this.#i=a;[e,t]=this.#d(e,t);let o=this.#t=[NaN,NaN,NaN,NaN,e,t];this.#a=[e,t];this.#n=[{line:o,points:this.#a}];this.#e.set(o,0)}updateProperty(e,t){e===`stroke-width`&&(this.#i=t)}#d(e,t){return Z._normalizePoint(e,t,this.#l,this.#u,this.#r)}isEmpty(){return!this.#n||this.#n.length===0}isCancellable(){return this.#a.length<=10}add(e,t){[e,t]=this.#d(e,t);let[n,r,i,a]=this.#e.subarray(2,6),o=e-i,s=t-a;if(Math.hypot(this.#l*o,this.#u*s)<=2)return null;this.#a.push(e,t);if(isNaN(n)){this.#e.set([i,a,e,t],2);this.#t.push(NaN,NaN,NaN,NaN,e,t);return{path:{d:this.toSVGPath()}}}isNaN(this.#e[0])&&this.#t.splice(6,6);this.#e.set([n,r,i,a,e,t],0);this.#t.push(...Z.createBezierPoints(n,r,i,a,e,t));return{path:{d:this.toSVGPath()}}}end(e,t){return this.add(e,t)||(this.#a.length===2?{path:{d:this.toSVGPath()}}:null)}startNew(e,t,n,r,i){this.#l=n;this.#u=r;this.#r=i;[e,t]=this.#d(e,t);let a=this.#t=[NaN,NaN,NaN,NaN,e,t];this.#a=[e,t];let o=this.#n.at(-1);if(o){o.line=new Float32Array(o.line);o.points=new Float32Array(o.points)}this.#n.push({line:a,points:this.#a});this.#e.set(a,0);this.#s=0;this.toSVGPath();return null}getLastElement(){return this.#n.at(-1)}setLastElement(e){if(!this.#n)return this.#c.setLastElement(e);this.#n.push(e);this.#t=e.line;this.#a=e.points;this.#s=0;return{path:{d:this.toSVGPath()}}}removeLastElement(){if(!this.#n)return this.#c.removeLastElement();this.#n.pop();this.#o=``;for(let e=0,t=this.#n.length;e<t;e++){let{line:t,points:n}=this.#n[e];this.#t=t;this.#a=n;this.#s=0;this.toSVGPath()}return{path:{d:this.#o}}}toSVGPath(){let e=Z.svgRound(this.#t[4]),t=Z.svgRound(this.#t[5]);if(this.#a.length===2){this.#o=`${this.#o} M ${e} ${t} Z`;return this.#o}if(this.#a.length<=6){let n=this.#o.lastIndexOf(`M`);this.#o=`${this.#o.slice(0,n)} M ${e} ${t}`;this.#s=6}if(this.#a.length===4){let e=Z.svgRound(this.#t[10]),t=Z.svgRound(this.#t[11]);this.#o=`${this.#o} L ${e} ${t}`;this.#s=12;return this.#o}let n=[];if(this.#s===0){n.push(`M ${e} ${t}`);this.#s=6}for(let e=this.#s,t=this.#t.length;e<t;e+=6){let[t,r,i,a,o,s]=this.#t.slice(e,e+6).map(Z.svgRound);n.push(`C${t} ${r} ${i} ${a} ${o} ${s}`)}this.#o+=n.join(` `);this.#s=this.#t.length;return this.#o}getOutlines(e,t,n,r){let i=this.#n.at(-1);i.line=new Float32Array(i.line);i.points=new Float32Array(i.points);this.#c.build(this.#n,e,t,n,this.#r,this.#i,r);this.#e=null;this.#t=null;this.#n=null;this.#o=null;return this.#c}get defaultSVGProperties(){return{root:{viewBox:`0 0 10000 10000`},rootClass:{draw:!0},bbox:[0,0,1,1]}}}class wr extends Z{#e;#t=0;#n;#r;#i;#a;#o;#s;#c;build(e,t,n,r,i,a,o){this.#i=t;this.#a=n;this.#o=r;this.#s=i;this.#c=a;this.#n=o??0;this.#r=e;this.#d()}get thickness(){return this.#c}setLastElement(e){this.#r.push(e);return{path:{d:this.toSVGPath()}}}removeLastElement(){this.#r.pop();return{path:{d:this.toSVGPath()}}}toSVGPath(){let e=[];for(let{line:t}of this.#r){e.push(`M${Z.svgRound(t[4])} ${Z.svgRound(t[5])}`);if(t.length!==6){if(t.length===12&&isNaN(t[6]))e.push(`L${Z.svgRound(t[10])} ${Z.svgRound(t[11])}`);else for(let n=6,r=t.length;n<r;n+=6){let[r,i,a,o,s,c]=t.subarray(n,n+6).map(Z.svgRound);e.push(`C${r} ${i} ${a} ${o} ${s} ${c}`)}}else e.push(`Z`)}return e.join(``)}serialize([e,t,n,r],i){let a=[],o=[],[s,c,l,u]=this.#u(),d,f,p,m,h,g,_,v,y;switch(this.#s){case 0:y=Z._rescale;d=e;f=t+r;p=n;m=-r;h=e+s*n;g=t+(1-c-u)*r;_=e+(s+l)*n;v=t+(1-c)*r;break;case 90:y=Z._rescaleAndSwap;d=e;f=t;p=n;m=r;h=e+c*n;g=t+s*r;_=e+(c+u)*n;v=t+(s+l)*r;break;case 180:y=Z._rescale;d=e+n;f=t;p=-n;m=r;h=e+(1-s-l)*n;g=t+c*r;_=e+(1-s)*n;v=t+(c+u)*r;break;case 270:y=Z._rescaleAndSwap;d=e+n;f=t+r;p=-n;m=-r;h=e+(1-c-u)*n;g=t+(1-s-l)*r;_=e+(1-c)*n;v=t+(1-s)*r}for(let{line:e,points:t}of this.#r){a.push(y(e,d,f,p,m,i?Array(e.length):null));o.push(y(t,d,f,p,m,i?Array(t.length):null))}return{lines:a,points:o,rect:[h,g,_,v]}}static deserialize(e,t,n,r,i,{paths:{lines:a,points:o},rotation:s,thickness:c}){let l=[],u,d,f,p,m;switch(s){case 0:m=Z._rescale;u=-e/n;d=t/r+1;f=1/n;p=-1/r;break;case 90:m=Z._rescaleAndSwap;u=-t/r;d=-e/n;f=1/r;p=1/n;break;case 180:m=Z._rescale;u=e/n+1;d=-t/r;f=-1/n;p=1/r;break;case 270:m=Z._rescaleAndSwap;u=t/r+1;d=e/n+1;f=-1/r;p=-1/n}if(!a){a=[];for(let e of o){let t=e.length;if(t===2){a.push(new Float32Array([NaN,NaN,NaN,NaN,e[0],e[1]]));continue}if(t===4){a.push(new Float32Array([NaN,NaN,NaN,NaN,e[0],e[1],NaN,NaN,NaN,NaN,e[2],e[3]]));continue}let n=new Float32Array(3*(t-2));a.push(n);let[r,i,o,s]=e.subarray(0,4);n.set([NaN,NaN,NaN,NaN,r,i],0);for(let a=4;a<t;a+=2){let t=e[a],c=e[a+1];n.set(Z.createBezierPoints(r,i,o,s,t,c),3*(a-2));[r,i,o,s]=[o,s,t,c]}}}for(let e=0,t=a.length;e<t;e++)l.push({line:m(a[e].map(e=>e??NaN),u,d,f,p),points:m(o[e].map(e=>e??NaN),u,d,f,p)});let h=new this.prototype.constructor;h.build(l,n,r,1,s,c,i);return h}#l(e=this.#c){let t=this.#n+e/2*this.#o;return this.#s%180==0?[t/this.#i,t/this.#a]:[t/this.#a,t/this.#i]}#u(){let[e,t,n,r]=this.#e,[i,a]=this.#l(0);return[e+i,t+a,n-2*i,r-2*a]}#d(){let e=this.#e=d.slice();for(let{line:t}of this.#r){if(t.length<=12){for(let n=4,r=t.length;n<r;n+=6)P.pointBoundingBox(t[n],t[n+1],e);continue}let n=t[4],r=t[5];for(let i=6,a=t.length;i<a;i+=6){let[a,o,s,c,l,u]=t.subarray(i,i+6);P.bezierBoundingBox(n,r,a,o,s,c,l,u,e);n=l;r=u}}let[t,n]=this.#l();e[0]=F(e[0]-t,0,1);e[1]=F(e[1]-n,0,1);e[2]=F(e[2]+t,0,1);e[3]=F(e[3]+n,0,1);e[2]-=e[0];e[3]-=e[1]}get box(){return this.#e}updateProperty(e,t){return e===`stroke-width`?this.#f(t):null}#f(e){let[t,n]=this.#l();this.#c=e;let[r,i]=this.#l(),[a,o]=[r-t,i-n],s=this.#e;s[0]-=a;s[1]-=o;s[2]+=2*a;s[3]+=2*o;return s}updateParentDimensions([e,t],n){let[r,i]=this.#l();this.#i=e;this.#a=t;this.#o=n;let[a,o]=this.#l(),s=a-r,c=o-i,l=this.#e;l[0]-=s;l[1]-=c;l[2]+=2*s;l[3]+=2*c;return l}updateRotation(e){this.#t=e;return{path:{transform:this.rotationTransform}}}get viewBox(){return this.#e.map(Z.svgRound).join(` `)}get defaultProperties(){let[e,t]=this.#e;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`}}}get rotationTransform(){let[,,e,t]=this.#e,n=0,r=0,i=0,a=0,o=0,s=0;switch(this.#t){case 90:r=t/e;i=-e/t;o=e;break;case 180:n=-1;a=-1;o=e;s=t;break;case 270:r=-t/e;i=e/t;s=t;break;default:return``}return`matrix(${n} ${r} ${i} ${a} ${Z.svgRound(o)} ${Z.svgRound(s)})`}getPathResizingSVGProperties([e,t,n,r]){let[i,a]=this.#l(),[o,s,c,l]=this.#e;if(Math.abs(c-i)<=Z.PRECISION||Math.abs(l-a)<=Z.PRECISION){let i=e+n/2-(o+c/2),a=t+r/2-(s+l/2);return{path:{"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`,transform:`${this.rotationTransform} translate(${i} ${a})`}}}let u=(n-2*i)/(c-2*i),d=(r-2*a)/(l-2*a),f=c/n,p=l/r;return{path:{"transform-origin":`${Z.svgRound(o)} ${Z.svgRound(s)}`,transform:`${this.rotationTransform} scale(${f} ${p}) translate(${Z.svgRound(i)} ${Z.svgRound(a)}) scale(${u} ${d}) translate(${Z.svgRound(-i)} ${Z.svgRound(-a)})`}}}getPathResizedSVGProperties([e,t,n,r]){let[i,a]=this.#l(),o=this.#e,[s,c,l,u]=o;o[0]=e;o[1]=t;o[2]=n;o[3]=r;if(Math.abs(l-i)<=Z.PRECISION||Math.abs(u-a)<=Z.PRECISION){let i=e+n/2-(s+l/2),a=t+r/2-(c+u/2);for(let{line:e,points:t}of this.#r){Z._translate(e,i,a,e);Z._translate(t,i,a,t)}return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}let d=(n-2*i)/(l-2*i),f=(r-2*a)/(u-2*a),p=-d*(s+i)+e+i,m=-f*(c+a)+t+a;if(d!==1||f!==1||p!==0||m!==0)for(let{line:e,points:t}of this.#r){Z._rescale(e,p,m,d,f,e);Z._rescale(t,p,m,d,f,t)}return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,t],n){let[r,i]=n,a=this.#e,o=e-a[0],s=t-a[1];if(this.#i===r&&this.#a===i)for(let{line:e,points:t}of this.#r){Z._translate(e,o,s,e);Z._translate(t,o,s,t)}else{let e=this.#i/r,t=this.#a/i;this.#i=r;this.#a=i;for(let{line:n,points:r}of this.#r){Z._rescale(n,o,s,e,t,n);Z._rescale(r,o,s,e,t,r)}a[2]*=e;a[3]*=t}a[0]=e;a[1]=t;return{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`}}}get defaultSVGProperties(){let e=this.#e;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${Z.svgRound(e[0])} ${Z.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}}class Tr extends Sr{constructor(e){super();this._viewParameters=e;super.updateProperties({fill:`none`,stroke:H._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-miterlimit":10})}updateSVGProperty(e,t){if(e===`stroke-width`){t??=this[`stroke-width`];t*=this._viewParameters.realScale}super.updateSVGProperty(e,t)}clone(){let e=new Tr(this._viewParameters);e.updateAll(this);return e}}class Er extends ${static _type=`ink`;static _editorType=_.INK;static _defaultDrawingOptions=null;constructor(e){super({...e,name:`inkEditor`});this._willKeepAspectRatio=!0;this.defaultL10nId=`pdfjs-editor-ink-editor`}static initialize(e,t){H.initialize(e,t);this._defaultDrawingOptions=new Tr(t.viewParameters)}static getDefaultDrawingOptions(e){let t=this._defaultDrawingOptions.clone();t.updateProperties(e);return t}static get supportMultipleDrawings(){return!0}static get typesMap(){return j(this,`typesMap`,new Map([[v.INK_THICKNESS,`stroke-width`],[v.INK_COLOR,`stroke`],[v.INK_OPACITY,`stroke-opacity`]]))}static createDrawerInstance(e,t,n,r,i){return new Cr(e,t,n,r,i,this._defaultDrawingOptions[`stroke-width`])}static deserializeDraw(e,t,n,r,i,a){return wr.deserialize(e,t,n,r,i,a)}static async deserialize(e,t,n){let r=null;if(e instanceof fr){let{data:{inkLists:t,rect:n,rotation:i,id:a,color:o,opacity:s,borderStyle:{rawWidth:c},popupRef:l,richText:u,contentsObj:d,creationDate:f,modificationDate:p},parent:{page:{pageNumber:m}}}=e;r=e={annotationType:_.INK,color:Array.from(o),thickness:c,opacity:s,paths:{points:t},boxes:null,pageIndex:m-1,rect:n.slice(0),rotation:i,annotationElementId:a,id:a,deleted:!1,popupRef:l,richText:u,comment:d?.str||null,creationDate:f,modificationDate:p}}let i=await super.deserialize(e,t,n);i._initialData=r;e.comment&&i.setCommentData(e);return i}get toolbarButtons(){this._colorPicker||=new er(this);return[[`colorPicker`,this._colorPicker]]}get colorType(){return v.INK_COLOR}get colorAndOpacityType(){return v.INK_COLOR_AND_OPACITY}get opacityType(){return v.INK_OPACITY}updateParams(e,t){e===v.INK_COLOR_AND_OPACITY?this._updateColorAndOpacity(t.color,t.opacity):super.updateParams(e,t)}static updateDefaultParams(e,t){if(e!==v.INK_COLOR_AND_OPACITY)super.updateDefaultParams(e,t);else{super.updateDefaultParams(v.INK_COLOR,t.color);super.updateDefaultParams(v.INK_OPACITY,t.opacity)}}get color(){return this._drawingOptions.stroke}get opacity(){return this._drawingOptions[`stroke-opacity`]}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();let{_drawId:e,_drawingOptions:t,parent:n}=this;t.updateSVGProperty(`stroke-width`);n.drawLayer.updateProperties(e,t.toSVGProperties())}static onScaleChangingWhenDrawing(){let e=this._currentParent;if(e){super.onScaleChangingWhenDrawing();this._defaultDrawingOptions.updateSVGProperty(`stroke-width`);e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties())}}createDrawingOptions({color:e,thickness:t,opacity:n}){this._drawingOptions=Er.getDefaultDrawingOptions({stroke:P.makeHexColor(...e),"stroke-width":t,"stroke-opacity":n})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let{lines:t,points:n}=this.serializeDraw(e),{_drawingOptions:{stroke:r,"stroke-opacity":i,"stroke-width":a}}=this,o=Object.assign(super.serialize(e),{color:H._colorManager.convert(r),opacity:i,thickness:a,paths:{lines:t,points:n}});this.addComment(o);if(e){o.isCopy=!0;return o}if(this.annotationElementId&&!this.#e(o))return null;o.id=this.annotationElementId;return o}#e(e){let{color:t,thickness:n,opacity:r,pageIndex:i}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized||e.color.some((e,n)=>e!==t[n])||e.thickness!==n||e.opacity!==r||e.pageIndex!==i}renderAnnotationElement(e){if(this.deleted){e.hide();return null}let{points:t,rect:n}=this.serializeDraw(!1);e.updateEdited({rect:n,thickness:this._drawingOptions[`stroke-width`],points:t,popup:this.comment});return null}}class Dr extends wr{toSVGPath(){let e=super.toSVGPath();e.endsWith(`Z`)||(e+=`Z`);return e}}class Or{static#e={maxDim:512,sigmaSFactor:.02,sigmaR:25,kernelSize:16};static#t(e,t,n,r){r-=t;return(n-=e)===0?r>0?0:4:n===1?r+6:2-r}static#n=new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]);static#r(e,t,n,r,i,a,o){let s=this.#t(n,r,i,a);for(let i=0;i<8;i++){let a=(-i+s-o+16)%8;if(e[(n+this.#n[2*a])*t+(r+this.#n[2*a+1])]!==0)return a}return-1}static#i(e,t,n,r,i,a,o){let s=this.#t(n,r,i,a);for(let i=0;i<8;i++){let a=(i+s+o+16)%8;if(e[(n+this.#n[2*a])*t+(r+this.#n[2*a+1])]!==0)return a}return-1}static#a(e,t,n,r){let i=e.length,a=new Int32Array(i);for(let t=0;t<i;t++)a[t]=+(e[t]<=r);for(let e=1;e<n-1;e++)a[e*t]=a[e*t+t-1]=0;for(let e=0;e<t;e++)a[e]=a[t*n-1-e]=0;let o,s=1,c=[];for(let e=1;e<n-1;e++){o=1;for(let n=1;n<t-1;n++){let r=e*t+n,i=a[r];if(i===0)continue;let l=e,u=n;if(i===1&&a[r-1]===0){s+=1;--u}else{if(!(i>=1&&a[r+1]===0)){i!==1&&(o=Math.abs(i));continue}s+=1;u+=1;i>1&&(o=i)}let d=[n,e],f=u===n+1,p={isHole:f,points:d,id:s,parent:0};c.push(p);let m;for(let e of c)if(e.id===o){m=e;break}p.parent=m?m.isHole?f?m.parent:o:f?o:m.parent:f?o:0;let h=this.#r(a,t,e,n,l,u,0);if(h===-1){a[r]=-s;a[r]!==1&&(o=Math.abs(a[r]));continue}let g=this.#n[2*h],_=this.#n[2*h+1],v=e+g,y=n+_;l=v;u=y;let b=e,x=n;for(;;){let i=this.#i(a,t,b,x,l,u,1);g=this.#n[2*i];_=this.#n[2*i+1];let c=b+g,f=x+_;d.push(f,c);let p=b*t+x;a[p+1]===0?a[p]=-s:a[p]===1&&(a[p]=s);if(c===e&&f===n&&b===v&&x===y){a[r]!==1&&(o=Math.abs(a[r]));break}l=b;u=x;b=c;x=f}}}return c}static#o(e,t,n,r){if(n-t<=4){for(let i=t;i<n-2;i+=2)r.push(e[i],e[i+1]);return}let i=e[t],a=e[t+1],o=e[n-4]-i,s=e[n-3]-a,c=Math.hypot(o,s),l=o/c,u=s/c,d=l*a-u*i,f=s/o,p=1/c,m=Math.atan(f),h=Math.cos(m),g=Math.sin(m),_=p*(Math.abs(h)+Math.abs(g)),v=p*(1-_+_**2),y=Math.max(Math.atan(Math.abs(g+h)*v),Math.atan(Math.abs(g-h)*v)),b=0,x=t;for(let r=t+2;r<n-2;r+=2){let t=Math.abs(d-l*e[r+1]+u*e[r]);if(t>b){x=r;b=t}}if(b>(c*y)**2){this.#o(e,t,x+2,r);this.#o(e,x,n,r)}else r.push(i,a)}static#s(e){let t=[],n=e.length;this.#o(e,0,n,t);t.push(e[n-2],e[n-1]);return t.length<=4?null:t}static#c(e,t,n,r,i,a){let o=new Float32Array(a**2),s=-2*r**2,c=a>>1;for(let e=0;e<a;e++){let t=(e-c)**2;for(let n=0;n<a;n++)o[e*a+n]=Math.exp((t+(n-c)**2)/s)}let l=new Float32Array(256),u=-2*i**2;for(let e=0;e<256;e++)l[e]=Math.exp(e**2/u);let d=e.length,f=new Uint8Array(d),p=new Uint32Array(256);for(let r=0;r<n;r++)for(let i=0;i<t;i++){let s=r*t+i,u=e[s],d=0,m=0;for(let s=0;s<a;s++){let f=r+s-c;if(!(f<0||f>=n))for(let n=0;n<a;n++){let r=i+n-c;if(r<0||r>=t)continue;let p=e[f*t+r],h=o[s*a+n]*l[Math.abs(p-u)];d+=p*h;m+=h}}p[f[s]=Math.round(d/m)]++}return[f,p]}static#l(e){let t=new Uint32Array(256);for(let n of e)t[n]++;return t}static#u(e){let t=e.length,n=new Uint8ClampedArray(t>>2),r=-1/0,i=1/0;for(let t=0,a=n.length;t<a;t++){let a=n[t]=e[t<<2];r=Math.max(r,a);i=Math.min(i,a)}let a=255/(r-i);for(let e=0,t=n.length;e<t;e++)n[e]=(n[e]-i)*a;return n}static#d(e){let t,n=-1/0,r=-1/0,i=e.findIndex(e=>e!==0),a=i,o=i;for(t=i;t<256;t++){let i=e[t];if(i>n){if(t-a>r){r=t-a;o=t-1}n=i;a=t}}for(t=o-1;t>=0&&!(e[t]>e[t+1]);t--);return t}static#f(e){let t=e,{width:n,height:r}=e,{maxDim:i}=this.#e,a=n,o=r;if(n>i||r>i){let s=n,c=r,l=Math.log2(Math.max(n,r)/i),u=Math.floor(l);l=l===u?u-1:u;for(let n=0;n<l;n++){a=Math.ceil(s/2);o=Math.ceil(c/2);let n=new OffscreenCanvas(a,o);n.getContext(`2d`).drawImage(e,0,0,s,c,0,0,a,o);s=a;c=o;e!==t&&e.close();e=n.transferToImageBitmap()}let d=Math.min(i/a,i/o);a=Math.round(a*d);o=Math.round(o*d)}let s=new OffscreenCanvas(a,o).getContext(`2d`,{willReadFrequently:!0});s.fillStyle=`white`;s.fillRect(0,0,a,o);s.filter=`grayscale(1)`;s.drawImage(e,0,0,e.width,e.height,0,0,a,o);let c=s.getImageData(0,0,a,o).data;return[this.#u(c),a,o]}static extractContoursFromText(e,{fontFamily:t,fontStyle:n,fontWeight:r},i,a,o,s){let c=new OffscreenCanvas(1,1),l=c.getContext(`2d`,{alpha:!1}),u=l.font=`${n} ${r} 200px ${t}`,{actualBoundingBoxLeft:d,actualBoundingBoxRight:f,actualBoundingBoxAscent:p,actualBoundingBoxDescent:m,fontBoundingBoxAscent:h,fontBoundingBoxDescent:g,width:_}=l.measureText(e),v=1.5,y=Math.ceil(Math.max(Math.abs(d)+Math.abs(f)||0,_)*v),b=Math.ceil(Math.max(Math.abs(p)+Math.abs(m)||200,Math.abs(h)+Math.abs(g)||200)*v);c=new OffscreenCanvas(y,b);l=c.getContext(`2d`,{alpha:!0,willReadFrequently:!0});l.font=u;l.filter=`grayscale(1)`;l.fillStyle=`white`;l.fillRect(0,0,y,b);l.fillStyle=`black`;l.fillText(e,.5*y/2,1.5*b/2);let x=this.#u(l.getImageData(0,0,y,b).data),S=this.#l(x),C=this.#d(S),w=this.#a(x,y,b,C);return this.processDrawnLines({lines:{curves:w,width:y,height:b},pageWidth:i,pageHeight:a,rotation:o,innerMargin:s,mustSmooth:!0,areContours:!0})}static process(e,t,n,r,i){let[a,o,s]=this.#f(e),[c,l]=this.#c(a,o,s,Math.hypot(o,s)*this.#e.sigmaSFactor,this.#e.sigmaR,this.#e.kernelSize),u=this.#d(l),d=this.#a(c,o,s,u);return this.processDrawnLines({lines:{curves:d,width:o,height:s},pageWidth:t,pageHeight:n,rotation:r,innerMargin:i,mustSmooth:!0,areContours:!0})}static processDrawnLines({lines:e,pageWidth:t,pageHeight:n,rotation:r,innerMargin:i,mustSmooth:a,areContours:o}){r%180!=0&&([t,n]=[n,t]);let{curves:s,width:c,height:l}=e,u=e.thickness??0,d=[],f=Math.min(t/c,n/l),p=f/t,m=f/n,h=[];for(let{points:e}of s){let t=a?this.#s(e):e;if(!t)continue;h.push(t);let n=t.length,r=new Float32Array(n),i=new Float32Array(3*(n===2?2:n-2));d.push({line:i,points:r});if(n===2){r[0]=t[0]*p;r[1]=t[1]*m;i.set([NaN,NaN,NaN,NaN,r[0],r[1]],0);continue}let[o,s,c,l]=t;o*=p;s*=m;c*=p;l*=m;r.set([o,s,c,l],0);i.set([NaN,NaN,NaN,NaN,o,s],0);for(let e=4;e<n;e+=2){let n=r[e]=t[e]*p,a=r[e+1]=t[e+1]*m;i.set(Z.createBezierPoints(o,s,c,l,n,a),3*(e-2));[o,s,c,l]=[c,l,n,a]}}if(d.length===0)return null;let g=o?new Dr:new wr;g.build(d,t,n,1,r,o?0:u,i);return{outline:g,newCurves:h,areContours:o,thickness:u,width:c,height:l}}static async compressSignature({outlines:e,areContours:t,thickness:n,width:r,height:i}){let a,o=1/0,s=-1/0,c=0;for(let t of e){c+=t.length;for(let e=2,n=t.length;e<n;e++){let n=t[e]-t[e-2];o=Math.min(o,n);s=Math.max(s,n)}}a=o>=-128&&s<=127?Int8Array:o>=-32768&&s<=32767?Int16Array:Int32Array;let l=e.length,u=8+3*l,d=new Uint32Array(u),f=0;d[f++]=u*Uint32Array.BYTES_PER_ELEMENT+(c-2*l)*a.BYTES_PER_ELEMENT;d[f++]=0;d[f++]=r;d[f++]=i;d[f++]=+!t;d[f++]=Math.max(0,Math.floor(n??0));d[f++]=l;d[f++]=a.BYTES_PER_ELEMENT;for(let t of e){d[f++]=t.length-2;d[f++]=t[0];d[f++]=t[1]}let p=new CompressionStream(`deflate-raw`),m=p.writable.getWriter();await m.ready;m.write(d);let h=a.prototype.constructor;for(let t of e){let e=new h(t.length-2);for(let n=2,r=t.length;n<r;n++)e[n-2]=t[n]-t[n-2];m.write(e)}m.close();return(await new Response(p.readable).bytes()).toBase64()}static async decompressSignature(e){try{let t=Uint8Array.fromBase64(e),{readable:n,writable:r}=new DecompressionStream(`deflate-raw`),i=r.getWriter();await i.ready;i.write(t).then(async()=>{await i.ready;await i.close()}).catch(()=>{});let a=null,o=0;for await(let e of n){a||=new Uint8Array(new Uint32Array(e.buffer,0,4)[0]);a.set(e,o);o+=e.length}let s=new Uint32Array(a.buffer,0,a.length>>2),c=s[1];if(c!==0)throw Error(`Invalid version: ${c}`);let l=s[2],u=s[3],d=s[4]===0,f=s[5],p=s[6],m=s[7],h=[],g=(8+3*p)*Uint32Array.BYTES_PER_ELEMENT,_;switch(m){case Int8Array.BYTES_PER_ELEMENT:_=new Int8Array(a.buffer,g);break;case Int16Array.BYTES_PER_ELEMENT:_=new Int16Array(a.buffer,g);break;case Int32Array.BYTES_PER_ELEMENT:_=new Int32Array(a.buffer,g)}o=0;for(let e=0;e<p;e++){let t=s[3*e+8],n=new Float32Array(t+2);h.push(n);for(let t=0;t<2;t++)n[t]=s[3*e+8+t+1];for(let e=0;e<t;e++)n[e+2]=n[e]+_[o++]}return{areContours:d,thickness:f,outlines:h,width:l,height:u}}catch(e){E(`decompressSignature: ${e}`);return null}}}class kr extends Sr{constructor(){super();super.updateProperties({fill:H._defaultLineColor,"stroke-width":0})}clone(){let e=new kr;e.updateAll(this);return e}}class Ar extends Tr{constructor(e){super(e);super.updateProperties({stroke:H._defaultLineColor,"stroke-width":1})}clone(){let e=new Ar(this._viewParameters);e.updateAll(this);return e}}class jr extends ${#e=!1;#t=null;#n=null;#r=null;static _type=`signature`;static _editorType=_.SIGNATURE;static _defaultDrawingOptions=null;constructor(e){super({...e,mustBeCommitted:!0,name:`signatureEditor`});this._willKeepAspectRatio=!0;this.#n=e.signatureData||null;this.#t=null;this.defaultL10nId=`pdfjs-editor-signature-editor1`}static initialize(e,t){H.initialize(e,t);this._defaultDrawingOptions=new kr;this._defaultDrawnSignatureOptions=new Ar(t.viewParameters)}static getDefaultDrawingOptions(e){let t=this._defaultDrawingOptions.clone();t.updateProperties(e);return t}static get supportMultipleDrawings(){return!1}static get typesMap(){return j(this,`typesMap`,new Map)}static get isDrawer(){return!1}get telemetryFinalData(){return{type:`signature`,hasDescription:!!this.#t}}static computeTelemetryFinalData(e){let t=e.get(`hasDescription`);return{hasAltText:t.get(!0)??0,hasNoAltText:t.get(!1)??0}}get isResizable(){return!0}onScaleChanging(){this._drawId!==null&&super.onScaleChanging()}render(){if(this.div)return this.div;let e,t,{_isCopy:n}=this;if(n){this._isCopy=!1;e=this.x;t=this.y}super.render();if(this._drawId===null){if(this.#n){let{lines:e,mustSmooth:t,areContours:n,description:r,uuid:i,heightInPage:a}=this.#n,{rawDims:{pageWidth:o,pageHeight:s},rotation:c}=this.parent.viewport,l=Or.processDrawnLines({lines:e,pageWidth:o,pageHeight:s,rotation:c,innerMargin:jr._INNER_MARGIN,mustSmooth:t,areContours:n});this.addSignature(l,a,r,i)}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.#t||``}));if(n){this._isCopy=!0;this._moveAfterPaste(e,t)}return this.div}setUuid(e){this.#r=e;this.addEditToolbar()}getUuid(){return this.#r}get description(){return this.#t}set description(e){this.#t=e;if(this.div){this.div.setAttribute(`data-l10n-args`,JSON.stringify({description:e}));super.addEditToolbar().then(t=>{t?.updateEditSignatureButton(e)})}}getSignaturePreview(){let{newCurves:e,areContours:t,thickness:n,width:r,height:i}=this.#n,a=Math.max(r,i);return{areContours:t,outline:Or.processDrawnLines({lines:{curves:e.map(e=>({points:e})),thickness:n,width:r,height:i},pageWidth:a,pageHeight:a,rotation:0,innerMargin:0,mustSmooth:!1,areContours:t}).outline}}get toolbarButtons(){return this._uiManager.signatureManager?[[`editSignature`,this._uiManager.signatureManager]]:super.toolbarButtons}addSignature(e,t,n,r){let{x:i,y:a}=this,{outline:o}=this.#n=e;this.#e=o instanceof Dr;this.description=n;let s;if(this.#e)s=jr.getDefaultDrawingOptions();else{s=jr._defaultDrawnSignatureOptions.clone();s.updateProperties({"stroke-width":o.thickness})}this._addOutlines({drawOutlines:o,drawingOptions:s});let[,c]=this.pageDimensions,l=t/c;l=l>=1?.5:l;this.width*=l/this.height;if(this.width>=1){l*=.9/this.width;this.width=.9}this.height=l;this.setDims();this.x=i;this.y=a;this.center();this._onResized();this.onScaleChanging();this.rotate();this._uiManager.addToAnnotationStorage(this);this.setUuid(r);this._reportTelemetry({action:`pdfjs.signature.inserted`,data:{hasBeenSaved:!!r,hasDescription:!!n}});this.div.hidden=!1}getFromImage(e){let{rawDims:{pageWidth:t,pageHeight:n},rotation:r}=this.parent.viewport;return Or.process(e,t,n,r,jr._INNER_MARGIN)}getFromText(e,t){let{rawDims:{pageWidth:n,pageHeight:r},rotation:i}=this.parent.viewport;return Or.extractContoursFromText(e,t,n,r,i,jr._INNER_MARGIN)}getDrawnSignature(e){let{rawDims:{pageWidth:t,pageHeight:n},rotation:r}=this.parent.viewport;return Or.processDrawnLines({lines:e,pageWidth:t,pageHeight:n,rotation:r,innerMargin:jr._INNER_MARGIN,mustSmooth:!1,areContours:!1})}createDrawingOptions({areContours:e,thickness:t}){if(e)this._drawingOptions=jr.getDefaultDrawingOptions();else{this._drawingOptions=jr._defaultDrawnSignatureOptions.clone();this._drawingOptions.updateProperties({"stroke-width":t})}}serialize(e=!1){if(this.isEmpty())return null;let{lines:t,points:n}=this.serializeDraw(e),{_drawingOptions:{"stroke-width":r}}=this,i=Object.assign(super.serialize(e),{isSignature:!0,areContours:this.#e,color:[0,0,0],thickness:this.#e?0:r});this.addComment(i);if(e){i.paths={lines:t,points:n};i.uuid=this.#r;i.isCopy=!0}else i.lines=t;this.#t&&(i.accessibilityData={type:`Figure`,alt:this.#t});return i}static deserializeDraw(e,t,n,r,i,a){return a.areContours?Dr.deserialize(e,t,n,r,i,a):wr.deserialize(e,t,n,r,i,a)}static async deserialize(e,t,n){let r=await super.deserialize(e,t,n);r.#e=e.areContours;r.description=e.accessibilityData?.alt||``;r.#r=e.uuid;return r}}class Mr extends H{#e=null;#t=null;#n=null;#r=null;#i=null;#a=``;#o=null;#s=!1;#c=null;#l=!1;#u=!1;static _type=`stamp`;static _editorType=_.STAMP;constructor(e){super({...e,name:`stampEditor`});this.#r=e.bitmapUrl;this.#i=e.bitmapFile;this.defaultL10nId=`pdfjs-editor-stamp-editor`}static initialize(e,t){H.initialize(e,t)}static isHandlingMimeForPasting(e){return Ee.includes(e)}static paste(e,t){t.pasteEditor({mode:_.STAMP},{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1);super.altTextFinish()}get telemetryFinalData(){return{type:`stamp`,hasAltText:!!this.altTextData?.altText}}static computeTelemetryFinalData(e){let t=e.get(`hasAltText`);return{hasAltText:t.get(!0)??0,hasNoAltText:t.get(!1)??0}}#d(e,t=!1){if(e){this.#e=e.bitmap;if(!t){this.#t=e.id;this.#l=e.isSvg}e.file&&(this.#a=e.file.name);this.#m()}else this.remove()}#f(){this.#n=null;this._uiManager.enableWaiting(!1);if(this.#o){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#e)this.addEditToolbar().then(()=>{this._editToolbar.hide();this._uiManager.editAltText(this,!0)});else{if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#e){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(e=null,t=!0){if(this.hasAltTextData())return null;let{mlManager:n}=this._uiManager;if(!n)throw Error(`No ML.`);if(!await n.isEnabledFor(`altText`))throw Error(`ML isn't enabled for alt text.`);let{data:r,width:i,height:a}=e||this.copyCanvas(null,null,!0).imageData,o=await n.guess({name:`altText`,request:{data:r,width:i,height:a,channels:r.length/(i*a)}});if(!o)throw Error(`No response from the AI service.`);if(o.error)throw Error(`Error from the AI service.`);if(o.cancel)return null;if(!o.output)throw Error(`No valid response from the AI service.`);let s=o.output;await this.setGuessedAltText(s);t&&!this.hasAltTextData()&&(this.altTextData={alt:s,decorative:!1});return s}#p(){if(this.#t){this._uiManager.enableWaiting(!0);this._uiManager.imageManager.getFromId(this.#t).then(e=>this.#d(e,!0)).finally(()=>this.#f());return}if(this.#r){let e=this.#r;this.#r=null;this._uiManager.enableWaiting(!0);this.#n=this._uiManager.imageManager.getFromUrl(e).then(e=>this.#d(e)).finally(()=>this.#f());return}if(this.#i){let e=this.#i;this.#i=null;this._uiManager.enableWaiting(!0);this.#n=this._uiManager.imageManager.getFromFile(e).then(e=>this.#d(e)).finally(()=>this.#f());return}let e=document.createElement(`input`);e.type=`file`;e.accept=Ee.join(`,`);let t=this._uiManager._signal;this.#n=new Promise(n=>{e.addEventListener(`change`,async()=>{if(e.files&&e.files.length!==0){this._uiManager.enableWaiting(!0);let t=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:`pdfjs.image.image_selected`,data:{alt_text_modal:this._uiManager.useNewAltTextFlow}});this.#d(t)}else this.remove();n()},{signal:t});e.addEventListener(`cancel`,()=>{this.remove();n()},{signal:t})}).finally(()=>this.#f());e.click()}remove(){if(this.#t){this.#e=null;this._uiManager.imageManager.deleteId(this.#t);this.#o?.remove();this.#o=null;if(this.#c){clearTimeout(this.#c);this.#c=null}}super.remove()}rebuild(){if(this.parent){super.rebuild();if(this.div!==null){this.#t&&this.#o===null&&this.#p();this.isAttachedToDOM||this.parent.add(this)}}else this.#t&&this.#p()}onceAdded(e){this._isDraggable=!0;e&&this.div.focus()}isEmpty(){return!(this.#n||this.#e||this.#r||this.#i||this.#t||this.#s)}get toolbarButtons(){return[[`altText`,this.createAltText()]]}get isResizable(){return!0}render(){if(this.div)return this.div;let e,t;if(this._isCopy){e=this.x;t=this.y}super.render();this.div.hidden=!0;this.createAltText();this.#s||(this.#e?this.#m():this.#p());this._isCopy&&this._moveAfterPaste(e,t);this._uiManager.addShouldRescale(this);return this.div}setCanvas(e,t){let{id:n,bitmap:r}=this._uiManager.imageManager.getFromCanvas(e,t);t.remove();if(n&&this._uiManager.imageManager.isValidId(n)){this.#t=n;r&&(this.#e=r);this.#s=!1;this.#m()}}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;this.#c!==null&&clearTimeout(this.#c);this.#c=setTimeout(()=>{this.#c=null;this.#g()},200)}#m(){let{div:e}=this,{width:t,height:n}=this.#e,[r,i]=this.pageDimensions,a=.75;if(this.width){t=this.width*r;n=this.height*i}else if(t>a*r||n>a*i){let e=Math.min(a*r/t,a*i/n);t*=e;n*=e}this._uiManager.enableWaiting(!1);let o=this.#o=document.createElement(`canvas`);o.setAttribute(`role`,`img`);this.addContainer(o);this.width=t/r;this.height=n/i;this.setDims();this._initialOptions?.isCentered?this.center():this.fixAndSetPosition();this._initialOptions=null;this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&!this.annotationElementId||(e.hidden=!1);this.#g();if(!this.#u){this.parent.addUndoableEditor(this);this.#u=!0}this._reportTelemetry({action:`inserted_image`});this.#a&&this.div.setAttribute(`aria-description`,this.#a);this.annotationElementId||this._uiManager.a11yAlert(H._l10nAlert.stamp)}copyCanvas(e,t,n=!1){e||=224;let{width:r,height:i}=this.#e,a=new Te,o=this.#e,s=r,c=i,l=null;if(t){if(r>t||i>t){let e=Math.min(t/r,t/i);s=Math.floor(r*e);c=Math.floor(i*e)}l=document.createElement(`canvas`);let e=l.width=Math.ceil(s*a.sx),n=l.height=Math.ceil(c*a.sy);this.#l||(o=this.#h(e,n));let u=l.getContext(`2d`);u.filter=this._uiManager.hcmFilter;let d=`white`,f=`#cfcfd8`;if(this._uiManager.hcmFilter!==`none`)f=`black`;else if(De.isDarkMode){d=`#8f8f9d`;f=`#42414d`}let p=15*a.sx,m=15*a.sy,h=new OffscreenCanvas(2*p,2*m),g=h.getContext(`2d`);g.fillStyle=d;g.fillRect(0,0,2*p,2*m);g.fillStyle=f;g.fillRect(0,0,p,m);g.fillRect(p,m,p,m);u.fillStyle=u.createPattern(h,`repeat`);u.fillRect(0,0,e,n);u.drawImage(o,0,0,o.width,o.height,0,0,e,n)}let u=null;if(n){let t,n;if(a.symmetric&&o.width<e&&o.height<e){t=o.width;n=o.height}else{o=this.#e;if(r>e||i>e){let a=Math.min(e/r,e/i);t=Math.floor(r*a);n=Math.floor(i*a);this.#l||(o=this.#h(t,n))}}let s=new OffscreenCanvas(t,n).getContext(`2d`,{willReadFrequently:!0});s.drawImage(o,0,0,o.width,o.height,0,0,t,n);u={width:t,height:n,data:s.getImageData(0,0,t,n).data}}return{canvas:l,width:s,height:c,imageData:u}}#h(e,t){let{width:n,height:r}=this.#e,i=n,a=r,o=this.#e;for(;i>2*e||a>2*t;){let n=i,r=a;i>2*e&&(i=Math.ceil(i/2));a>2*t&&(a=Math.ceil(a/2));let s=new OffscreenCanvas(i,a);s.getContext(`2d`).drawImage(o,0,0,n,r,0,0,i,a);o=s.transferToImageBitmap()}return o}#g(){let[e,t]=this.parentDimensions,{width:n,height:r}=this,i=new Te,a=Math.ceil(n*e*i.sx),o=Math.ceil(r*t*i.sy),s=this.#o;if(!s||s.width===a&&s.height===o)return;s.width=a;s.height=o;let c=this.#l?this.#e:this.#h(a,o),l=s.getContext(`2d`);l.filter=this._uiManager.hcmFilter;l.drawImage(c,0,0,c.width,c.height,0,0,a,o)}#_(e){if(e){if(this.#l){let e=this._uiManager.imageManager.getSvgUrl(this.#t);if(e)return e}let e=document.createElement(`canvas`);({width:e.width,height:e.height}=this.#e);e.getContext(`2d`).drawImage(this.#e,0,0);return e.toDataURL()}if(this.#l){let[e,t]=this.pageDimensions,n=Math.round(this.width*e*pe.PDF_TO_CSS_UNITS),r=Math.round(this.height*t*pe.PDF_TO_CSS_UNITS),i=new OffscreenCanvas(n,r);i.getContext(`2d`).drawImage(this.#e,0,0,this.#e.width,this.#e.height,0,0,n,r);return i.transferToImageBitmap()}return structuredClone(this.#e)}static async deserialize(e,t,n){let r=null,i=!1;if(e instanceof mr){let{data:{rect:a,rotation:o,id:s,structParent:c,popupRef:l,richText:u,contentsObj:d,creationDate:f,modificationDate:p},container:m,parent:{page:{pageNumber:g}},canvas:v}=e,y,b;if(v){delete e.canvas;({id:y,bitmap:b}=n.imageManager.getFromCanvas(m.id,v));v.remove()}else{i=!0;e._hasNoCanvas=!0}let x=(await t._structTree.getAriaAttributes(`${h}${s}`))?.get(`aria-label`)||``;r=e={annotationType:_.STAMP,bitmapId:y,bitmap:b,pageIndex:g-1,rect:a.slice(0),rotation:o,annotationElementId:s,id:s,deleted:!1,accessibilityData:{decorative:!1,altText:x},isSvg:!1,structParent:c,popupRef:l,richText:u,comment:d?.str||null,creationDate:f,modificationDate:p}}let a=await super.deserialize(e,t,n),{rect:o,bitmap:s,bitmapUrl:c,bitmapId:l,isSvg:u,accessibilityData:d}=e;if(i){n.addMissingCanvas(e.id,a);a.#s=!0}else if(l&&n.imageManager.isValidId(l)){a.#t=l;s&&(a.#e=s)}else a.#r=c;a.#l=u;let[f,p]=a.pageDimensions;a.width=(o[2]-o[0])/f;a.height=(o[3]-o[1])/p;d&&(a.altTextData=d);a._initialData=r;e.comment&&a.setCommentData(e);a.#u=!!r;return a}serialize(e=!1,t=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let n=Object.assign(super.serialize(e),{bitmapId:this.#t,isSvg:this.#l});this.addComment(n);if(e){n.bitmapUrl=this.#_(!0);n.accessibilityData=this.serializeAltText(!0);n.isCopy=!0;return n}let{decorative:r,altText:i}=this.serializeAltText(!1);!r&&i&&(n.accessibilityData={type:`Figure`,alt:i});if(this.annotationElementId){let e=this.#v(n);if(e.isSame)return null;e.isSameAltText?delete n.accessibilityData:n.accessibilityData.structParent=this._initialData.structParent??-1;n.id=this.annotationElementId;delete n.bitmapId;return n}if(t===null)return n;t.stamps||=new Map;let a=this.#l?(n.rect[2]-n.rect[0])*(n.rect[3]-n.rect[1]):null;if(t.stamps.has(this.#t)){if(this.#l){let e=t.stamps.get(this.#t);if(a>e.area){e.area=a;e.serialized.bitmap.close();e.serialized.bitmap=this.#_(!1)}}}else{t.stamps.set(this.#t,{area:a,serialized:n});n.bitmap=this.#_(!1)}return n}#v(e){let{pageIndex:t,accessibilityData:{altText:n}}=this._initialData,r=e.pageIndex===t,i=(e.accessibilityData?.alt||``)===n;return{isSame:!this.hasEditedComment&&!this._hasBeenMoved&&!this._hasBeenResized&&r&&i,isSameAltText:i}}renderAnnotationElement(e){if(this.deleted){e.hide();return null}e.updateEdited({rect:this.getPDFRect(),popup:this.comment});return null}}class Nr{#e;#t=!1;#n=null;#r=null;#i=null;#a=new Map;#o=!1;#s=!1;#c=!1;#l=null;#u=null;#d=null;#f=null;#p=null;#m=-1;#h;static _initialized=!1;static#g=new Map([X,Er,Mr,Q,jr].map(e=>[e._editorType,e]));constructor({uiManager:e,pageIndex:t,div:n,structTreeLayer:r,accessibilityManager:i,annotationLayer:a,drawLayer:o,textLayer:s,viewport:c,l10n:l}){let u=[...Nr.#g.values()];if(!Nr._initialized){Nr._initialized=!0;for(let t of u)t.initialize(l,e)}e.registerEditorTypes(u);this.#h=e;this.pageIndex=t;this.div=n;this.#e=i;this.#n=a;this.viewport=c;this.#d=s;this.drawLayer=o;this._structTree=r;this.#h.addLayer(this)}get isEmpty(){return this.#a.size===0}get isInvisible(){return this.isEmpty&&this.#h.getMode()===_.NONE}updateToolbar(e){this.#h.updateToolbar(e)}updateMode(e=this.#h.getMode()){this.#S();switch(e){case _.NONE:this.div.classList.toggle(`nonEditing`,!0);this.disableTextSelection();this.togglePointerEvents(!1);this.toggleAnnotationLayerPointerEvents(!0);this.disableClick();return;case _.INK:this.disableTextSelection();this.togglePointerEvents(!0);this.enableClick();break;case _.HIGHLIGHT:this.enableTextSelection();this.togglePointerEvents(!1);this.disableClick();break;default:this.disableTextSelection();this.togglePointerEvents(!0);this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);let{classList:t}=this.div;t.toggle(`nonEditing`,!1);if(e===_.POPUP)t.toggle(`commentEditing`,!0);else{t.toggle(`commentEditing`,!1);for(let n of Nr.#g.values())t.toggle(`${n._type}Editing`,e===n._editorType)}this.div.hidden=!1}hasTextLayer(e){return e===this.#d?.div}setEditingState(e){this.#h.setEditingState(e)}addCommands(e){this.#h.addCommands(e)}cleanUndoStack(e){this.#h.cleanUndoStack(e)}toggleDrawing(e=!1){this.div.classList.toggle(`drawing`,!e)}togglePointerEvents(e=!1){this.div.classList.toggle(`disabled`,!e)}toggleAnnotationLayerPointerEvents(e=!1){this.#n?.togglePointerEvents(e)}get#_(){return this.#a.size===0?this.#h.getEditors(this.pageIndex):this.#a.values()}async enable(){this.#c=!0;this.div.tabIndex=0;this.togglePointerEvents(!0);this.div.classList.toggle(`nonEditing`,!1);this.#p?.abort();this.#p=null;let e=new Set;for(let t of this.#_){t.enableEditing();t.show(!0);if(t.annotationElementId){this.#h.removeChangedExistingAnnotation(t);e.add(t.annotationElementId)}}let t=this.#n;if(t)for(let n of t.getEditableAnnotations()){n.hide();if(this.#h.isDeletedAnnotationElement(n.data.id))continue;if(e.has(n.data.id))continue;let t=await this.deserialize(n);if(t){this.addOrRebuild(t);t.enableEditing()}}this.#c=!1;this.#h._eventBus.dispatch(`editorsrendered`,{source:this,pageNumber:this.pageIndex+1})}disable(){this.#s=!0;this.div.tabIndex=-1;this.togglePointerEvents(!1);this.div.classList.toggle(`nonEditing`,!0);if(this.#d&&!this.#p){this.#p=new AbortController;let e=this.#h.combinedSignal(this.#p);this.#d.div.addEventListener(`pointerdown`,e=>{let{clientX:t,clientY:n,timeStamp:r}=e;if(r-this.#m>500){this.#m=r;return}this.#m=-1;let{classList:i}=this.div;i.toggle(`getElements`,!0);let a=document.elementsFromPoint(t,n);i.toggle(`getElements`,!1);if(!this.div.contains(a[0]))return;let o,s=RegExp(`^${g}[0-9]+$`);for(let e of a)if(s.test(e.id)){o=e.id;break}if(!o)return;let c=this.#a.get(o);if(c?.annotationElementId===null){R(e);c.dblclick(e)}},{signal:e,capture:!0})}let e=this.#n,t=[];if(e){let n=new Map,r=new Map;for(let e of this.#_){e.disableEditing();if(e.annotationElementId){if(e.serialize()===null){r.set(e.annotationElementId,e);this.getEditableAnnotation(e.annotationElementId)?.show();e.remove()}else n.set(e.annotationElementId,e)}else t.push(e)}for(let t of e.getEditableAnnotations()){let{id:e}=t.data;if(this.#h.isDeletedAnnotationElement(e)){t.updateEdited({deleted:!0});continue}let i=r.get(e);if(i){i.resetAnnotationElement(t);i.show(!1);t.show()}else{i=n.get(e);if(i){this.#h.addChangedExistingAnnotation(i);i.renderAnnotationElement(t)&&i.show(!1)}t.show()}}}this.#S();this.isEmpty&&(this.div.hidden=!0);let{classList:n}=this.div;for(let e of Nr.#g.values())n.remove(`${e._type}Editing`);this.disableTextSelection();this.toggleAnnotationLayerPointerEvents(!0);e?.updateFakeAnnotations(t);this.#s=!1}getEditableAnnotation(e){return this.#n?.getEditableAnnotation(e)||null}setActiveEditor(e){this.#h.getActive()!==e&&this.#h.setActiveEditor(e)}enableTextSelection(){this.div.tabIndex=-1;if(this.#d?.div&&!this.#f){this.#f=new AbortController;let e=this.#h.combinedSignal(this.#f);this.#d.div.addEventListener(`pointerdown`,this.#v.bind(this),{signal:e});this.#d.div.classList.add(`highlighting`)}}disableTextSelection(){this.div.tabIndex=0;if(this.#d?.div&&this.#f){this.#f.abort();this.#f=null;this.#d.div.classList.remove(`highlighting`)}}#v(e){this.#h.unselectAll();let{target:t}=e;if(t===this.#d.div||(t.getAttribute(`role`)===`img`||t.classList.contains(`endOfContent`)||t.classList.contains(`textLayerImages`)||t.classList.contains(`textLayerImagePlaceholder`))&&this.#d.div.contains(t)){let{isMac:t}=N.platform;if(e.button!==0||e.ctrlKey&&t)return;this.#h.showAllEditors(`highlight`,!0,!0);this.#d.div.classList.add(`free`);this.toggleDrawing();Q.startHighlighting(this,this.#h.direction===`ltr`,{target:this.#d.div,x:e.x,y:e.y});this.#d.div.addEventListener(`pointerup`,()=>{this.#d.div.classList.remove(`free`);this.toggleDrawing(!0)},{once:!0,signal:this.#h._signal});e.preventDefault()}}enableClick(){if(this.#r)return;this.#r=new AbortController;let e=this.#h.combinedSignal(this.#r);this.div.addEventListener(`pointerdown`,this.pointerdown.bind(this),{signal:e});let t=this.pointerup.bind(this);this.div.addEventListener(`pointerup`,t,{signal:e});this.div.addEventListener(`pointercancel`,t,{signal:e})}disableClick(){this.#r?.abort();this.#r=null}attach(e){this.#a.set(e.id,e);let{annotationElementId:t}=e;t&&this.#h.isDeletedAnnotationElement(t)&&this.#h.removeDeletedAnnotationElement(e)}detach(e){this.#a.delete(e.id);this.#e?.removePointerInTextLayer(e.contentDiv);!this.#s&&e.annotationElementId&&this.#h.addDeletedAnnotationElement(e)}remove(e){this.detach(e);this.#h.removeEditor(e);e.div.remove();e.isAttachedToDOM=!1}changeParent(e){if(e.parent!==this){if(e.parent&&e.annotationElementId){this.#h.addDeletedAnnotationElement(e);H.deleteAnnotationElement(e);e.annotationElementId=null}this.attach(e);e.parent?.detach(e);e.setParent(this);if(e.div&&e.isAttachedToDOM){e.div.remove();this.div.append(e.div)}}}add(e){if(e.parent!==this||!e.isAttachedToDOM){this.changeParent(e);this.#h.addEditor(e);this.attach(e);if(!e.isAttachedToDOM){let t=e.render();this.div.append(t);e.isAttachedToDOM=!0}e.fixAndSetPosition();e.onceAdded(!this.#c);this.#h.addToAnnotationStorage(e);e._reportTelemetry(e.telemetryInitialData)}}moveEditorInDOM(e){if(!e.isAttachedToDOM)return;let{activeElement:t}=document;if(e.div.contains(t)&&!this.#i){e._focusEventsAllowed=!1;this.#i=setTimeout(()=>{this.#i=null;if(e.div.contains(document.activeElement))e._focusEventsAllowed=!0;else{e.div.addEventListener(`focusin`,()=>{e._focusEventsAllowed=!0},{once:!0,signal:this.#h._signal});t.focus()}},0)}e._structTreeParentId=this.#e?.moveElementInDOM(this.div,e.div,e.contentDiv,!0)}addOrRebuild(e){if(e.needsToBeRebuilt()){e.parent||=this;e.rebuild();e.show()}else this.add(e)}addUndoableEditor(e){this.addCommands({cmd:()=>e._uiManager.rebuild(e),undo:()=>{e.remove()},mustExec:!1})}getEditorByUID(e){for(let t of this.#a.values())if(t.uid===e)return t;return null}get#y(){return Nr.#g.get(this.#h.getMode())}combinedSignal(e){return this.#h.combinedSignal(e)}#b(e){let t=this.#y;return t?new t.prototype.constructor(e):null}canCreateNewEmptyEditor(){return this.#y?.canCreateNewEmptyEditor()}async pasteEditor(e,t){this.updateToolbar(e);await this.#h.updateMode(e.mode);let{offsetX:n,offsetY:r}=this.#x(),i=this.#h.getId(),a=this.#b({parent:this,id:i,x:n,y:r,uiManager:this.#h,isCentered:!0,...t});a&&this.add(a)}async deserialize(e){return await Nr.#g.get(e.annotationType??e.annotationEditorType)?.deserialize(e,this,this.#h)||null}createAndAddNewEditor(e,t,n={}){let r=this.#h.getId(),i=this.#b({parent:this,id:r,x:e.offsetX,y:e.offsetY,uiManager:this.#h,isCentered:t,...n});i&&this.add(i);return i}get boundingClientRect(){return this.div.getBoundingClientRect()}#x(){let{x:e,y:t,width:n,height:r}=this.boundingClientRect,i=Math.max(0,e),a=Math.max(0,t),o=(i+Math.min(window.innerWidth,e+n))/2-e,s=(a+Math.min(window.innerHeight,t+r))/2-t,[c,l]=this.viewport.rotation%180==0?[o,s]:[s,o];return{offsetX:c,offsetY:l}}addNewEditor(e={}){this.createAndAddNewEditor(this.#x(),!0,e)}setSelected(e){this.#h.setSelected(e)}toggleSelected(e){this.#h.toggleSelected(e)}unselect(e){this.#h.unselect(e)}pointerup(e){let{isMac:t}=N.platform;if(e.button!==0||e.ctrlKey&&t)return;if(e.target!==this.div)return;if(!this.#o)return;this.#o=!1;if(this.#y?.isDrawer&&this.#y.supportMultipleDrawings)return;if(!this.#t){this.#t=!0;return}let n=this.#h.getMode();n!==_.STAMP&&n!==_.POPUP&&n!==_.SIGNATURE?this.createAndAddNewEditor(e,!1):this.#h.unselectAll()}pointerdown(e){this.#h.getMode()===_.HIGHLIGHT&&this.enableTextSelection();if(this.#o){this.#o=!1;return}let{isMac:t}=N.platform;if(e.button!==0||e.ctrlKey&&t)return;if(e.target!==this.div)return;this.#o=!0;if(this.#y?.isDrawer){this.startDrawingSession(e);return}let n=this.#h.getActive();this.#t=!n||n.isEmpty()}startDrawingSession(e){this.div.focus({preventScroll:!0});if(this.#l){this.#y.startDrawing(this,this.#h,!1,e);return}this.#h.setCurrentDrawingSession(this);this.#l=new AbortController;let t=this.#h.combinedSignal(this.#l);this.div.addEventListener(`blur`,({relatedTarget:e})=>{if(e&&!this.div.contains(e)){this.#u=null;this.commitOrRemove()}},{signal:t});this.#y.startDrawing(this,this.#h,!1,e)}pause(e){if(e){let{activeElement:e}=document;this.div.contains(e)&&(this.#u=e);return}this.#u&&setTimeout(()=>{this.#u?.focus();this.#u=null},0)}endDrawingSession(e=!1){if(!this.#l)return null;this.#h.setCurrentDrawingSession(null);this.#l.abort();this.#l=null;this.#u=null;return this.#y.endDrawing(e)}findNewParent(e,t,n){let r=this.#h.findParent(t,n);if(r===null||r===this)return!1;r.changeParent(e);return!0}commitOrRemove(){if(this.#l){this.endDrawingSession();return!0}return!1}onScaleChanging(){this.#l&&this.#y.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove();if(this.#h.getActive()?.parent===this){this.#h.commitOrRemove();this.#h.setActiveEditor(null)}if(this.#i){clearTimeout(this.#i);this.#i=null}for(let e of this.#a.values()){this.#e?.removePointerInTextLayer(e.contentDiv);e.setParent(null);e.isAttachedToDOM=!1;e.div.remove()}this.div=null;this.#a.clear();this.#h.removeLayer(this)}#S(){for(let e of this.#a.values())e.isEmpty()&&e.remove()}async render({viewport:e}){this.viewport=e;we(this.div,e);for(let e of this.#h.getEditors(this.pageIndex)){this.add(e);e.rebuild()}await this.#h.findClonesForPage(this);this.div.hidden=this.isEmpty;this.updateMode()}update({viewport:e}){this.#h.commitOrRemove();this.#S();let t=this.viewport.rotation,n=e.rotation;this.viewport=e;we(this.div,{rotation:n});if(t!==n)for(let e of this.#a.values())e.rotate(n)}get pageDimensions(){let{pageWidth:e,pageHeight:t}=this.viewport.rawDims;return[e,t]}get scale(){return this.#h.viewParameters.realScale}}globalThis._pdfjsTestingUtils={HighlightOutliner:vr};const Pr={fonts:globalThis.fonts,createElement(e){if(e.toLowerCase()===`canvas`)return new OffscreenCanvas(1,1);return null}};class Fr{constructor(){this._pdfDocument=null;this._page=null;this._geospatialMetadata=null;this._baseViewport=null;this._inverseBaseViewport=null;this._pdfWorker=null;this._pdfWorkerBlobUrl=null}async loadPDF(n,s={}){let[{data:c},l]=await Promise.all([t(n.url,{responseType:`array-buffer`,signal:s?.signal}),this._getPDFWorker(s)]),u=Kn({data:c,wasmUrl:e(`esri/libs/pdfjs/wasm/`),ownerDocument:Pr,enableHWA:!0,useWorkerFetch:!0,worker:l,useWasm:!0});this._pdfDocument=await u.promise;r(s);this._page=await this._pdfDocument.getPage(n.page);r(s);this._geospatialMetadata=await this._page.getGeospatialPDFMetadata();r(s);this._baseViewport=this._page.getViewport({scale:1});this._inverseBaseViewport=i();o(this._inverseBaseViewport,a(...this._baseViewport.transform));return{geospatialMetadata:this._geospatialMetadata}}destroy(){this._page?.cleanup?.();this._page=null;this._pdfDocument?.cleanup();this._pdfDocument=null;this._geospatialMetadata=null;this._baseViewport=null;this._inverseBaseViewport=null;this._pdfWorker?.destroy();this._pdfWorker=null;if(this._pdfWorkerBlobUrl){URL.revokeObjectURL(this._pdfWorkerBlobUrl);this._pdfWorkerBlobUrl=null}}async renderPDF(e,t={}){if(!this._page||!this._baseViewport||!this._inverseBaseViewport)throw new n(`geospatial-pdf-layer-worker:not-loaded`,`PDF not loaded`);r(t);let{width:i,height:a,sourceExtentAsJSON:o,currentRing:l,ctm:u}=e,d=s.fromJSON(o),f=await c(d,i,a,u,this._page,this._baseViewport,this._inverseBaseViewport,l,t);r(t);return Ir(f,i,a)}async _getPDFWorker(n={}){if(this._pdfWorker)return this._pdfWorker;let r=e(`esri/libs/pdfjs/pdf.worker.mjs`),i=(await t(r,{responseType:`blob`,authMode:`anonymous`,signal:n.signal})).data,a=i.type===`application/javascript`||i.type===`text/javascript`?i:new Blob([i],{type:`application/javascript`}),o=URL.createObjectURL(a);try{let e=new Worker(o,{type:`module`,name:`geospatial-pdf-pdfjs-worker`}),t=new J({port:e});await t.promise;this._pdfWorker=t;this._pdfWorkerBlobUrl=o;return t}catch(e){URL.revokeObjectURL(o);throw e}}}function Ir(e,t,r){let i=e.getContext(`2d`);if(!i)throw new n(`geospatial-pdf-raster:canvas`,`Failed to create canvas context.`);let a=i.getImageData(0,0,t,r).data,o=t*r,s=new Uint8Array(o),c=new Uint8Array(o),l=new Uint8Array(o),u=new Uint8Array(o);for(let e=0,t=0;e<o;e++,t+=4){s[e]=a[t];c[e]=a[t+1];l[e]=a[t+2];u[e]=a[t+3]}return{width:t,height:r,red:s,green:c,blue:l,mask:u}}export{Fr as default};
|