@arcgis/core 6.0.0-next.53 → 6.0.0-next.55
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/WebScene.js +2 -2
- package/applications/Components/OrientedImageryViewer/shared/constants.js +1 -1
- package/applications/SceneViewer/sceneViewerUtils.js +1 -1
- package/arcade/arcadeAsyncRuntime.js +1 -1
- package/arcade/arcadeCompiler.js +1 -1
- package/arcade/arcadeRuntime.js +1 -1
- package/arcade/featureset/support/sqlUtils.js +1 -1
- package/arcade/validation/arcadeValidator.js +1 -1
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/0329fa3aa3403f1c243b.js +1 -0
- package/assets/esri/core/workers/chunks/{6602310c3fcd91fb6a2f.js → 07c8ac092e4b9e8d5b3c.js} +1 -1
- package/assets/esri/core/workers/chunks/0a97b1974367382cfdf5.js +1 -0
- package/assets/esri/core/workers/chunks/{db0a7671ab5cbe8afd72.js → 123661019bb69c53f2d3.js} +1 -1
- package/assets/esri/core/workers/chunks/{d14732a57c8e63948c60.js → 14259910f44c08fd5bbd.js} +1 -1
- package/assets/esri/core/workers/chunks/{1b41ba050cde068d2860.js → 193a73a2c7f4f8482c21.js} +1 -1
- package/assets/esri/core/workers/chunks/20acb6f3ed5140b6c6c6.js +1 -0
- package/assets/esri/core/workers/chunks/{e507dfc4788295d9c244.js → 249a687ce1b6d0815242.js} +1 -1
- package/assets/esri/core/workers/chunks/{afb4dfb89fbc8a342cc5.js → 3354f1fa90f8ce4c8fde.js} +1 -1
- package/assets/esri/core/workers/chunks/{9b458b0d1627f22fdd93.js → 3b11e4d2e69b7aea1d65.js} +1 -1
- package/assets/esri/core/workers/chunks/41694ee8990e799da225.js +1 -0
- package/assets/esri/core/workers/chunks/{e592f2483db71230e8e5.js → 4401b3f8ebb658abe789.js} +1 -1
- package/assets/esri/core/workers/chunks/{12add2003631fa314f25.js → 5060be52a380fc4920f8.js} +1 -1
- package/assets/esri/core/workers/chunks/{2aa6be0b047a1b25a520.js → 53bbb9aa6e4e4a0a8121.js} +1 -1
- package/assets/esri/core/workers/chunks/{4707aedcc1b3bdf5e987.js → 5c34d49a6c9cc34b7626.js} +1 -1
- package/assets/esri/core/workers/chunks/69a09c6acb5ae03c67f6.js +1 -0
- package/assets/esri/core/workers/chunks/7b156905d168bf973518.js +1 -0
- package/assets/esri/core/workers/chunks/{e83806797979138fd22a.js → 844c593754b2692257f4.js} +1 -1
- package/assets/esri/core/workers/chunks/{2d3e977f3b75474d7ebc.js → 846248697c398468d8e6.js} +1 -1
- package/assets/esri/core/workers/chunks/{f7e33d37dd11fb08f3f8.js → 97107e64407fa6825620.js} +1 -1
- package/assets/esri/core/workers/chunks/{032733b863426c5bde00.js → 9e508f930086d2ef5f22.js} +3 -3
- package/assets/esri/core/workers/chunks/{5118c7269b706089c88e.js → a05a2c2aaf0c288f9681.js} +1 -1
- package/assets/esri/core/workers/chunks/{817bf487df056da1e6ec.js → a116dd204921e7464944.js} +1 -1
- package/assets/esri/core/workers/chunks/{944f17e9c9f681b971fb.js → a12e2a345005189c64be.js} +1 -1
- package/assets/esri/core/workers/chunks/{15b3386ad92a0b4149b8.js → a24dc5350af001db417a.js} +1 -1
- package/assets/esri/core/workers/chunks/{10967a36c77c5188690d.js → a66d6298236d59a615db.js} +1 -1
- package/assets/esri/core/workers/chunks/{255f5b45c4d32f97f86c.js → ac0861014b3d2f1a1de2.js} +1 -1
- package/assets/esri/core/workers/chunks/ace210d313ce53f3ae10.js +1 -0
- package/assets/esri/core/workers/chunks/ae48ee283cfa5b3c14b0.js +1 -0
- package/assets/esri/core/workers/chunks/bbd8fcb0bbba7bde3d9b.js +1 -0
- package/assets/esri/core/workers/chunks/{ac8d38016e4bee37a77c.js → be0b8bb4f09aae6ff5de.js} +1 -1
- package/assets/esri/core/workers/chunks/d0659f1b0495734be4b3.js +1 -0
- package/assets/esri/core/workers/chunks/{b9a2b05ede02c305e865.js → d8ffb1502def5c85740b.js} +1 -1
- package/assets/esri/core/workers/chunks/{7dfe1e78d2e66de6be22.js → d9ef244019954d5a8a27.js} +1 -1
- package/assets/esri/core/workers/chunks/{95403bb27a4ea0a4b7b1.js → ddbfa664e69612295785.js} +1 -1
- package/assets/esri/core/workers/chunks/{c6d82397044e403a1f61.js → e61082f56c08abe54b3a.js} +1 -1
- package/assets/esri/core/workers/chunks/{55d28d3f5b8ced061e39.js → eaf73ce60f39a48ddd2a.js} +1 -1
- package/assets/esri/core/workers/chunks/ed2f2a5da830d058e339.js +1 -0
- package/assets/esri/core/workers/chunks/{944cb751c85d3a127f49.js → f52d081bbde5c95265cf.js} +1 -1
- package/assets/esri/core/workers/chunks/{1de9be7b65109c207bd5.js → fbd5f3b81cd9f061824d.js} +1 -1
- package/assets/esri/layers/raster/formats/blosc-wasm.wasm +0 -0
- package/assets/esri/libs/librust-parquet/pkg/parquet_bg.wasm +0 -0
- package/basemapGallery/support/basemapCompatibilityUtils.js +1 -1
- package/chunks/CypherParser.js +1 -1
- package/chunks/GeodeticDistanceCalculator-zRp89-dW.js +1 -1
- package/chunks/MultiPathImpl.js +1 -1
- package/chunks/OperatorGeodesicBuffer.js +1 -1
- package/chunks/UnitFactory.js +1 -1
- package/chunks/blosc-wasm.js +2 -0
- package/chunks/cameraUtilsSpherical.js +1 -1
- package/chunks/parquet.js +1 -1
- package/chunks/text.js +1 -1
- package/config.js +1 -1
- package/core/sql/SqlInterval.js +1 -1
- package/core/urlUtils.js +1 -1
- package/geometry/geometryEngine.js +1 -1
- package/geometry/operators/gx/operatorOffset.js +1 -1
- package/geometry/support/Ellipsoid.js +1 -1
- package/geometry/support/curves/ellipticArc7Utils.js +1 -1
- package/geometry/support/geodesicConstants.js +1 -1
- package/geometry/support/meshUtils/primitives.js +1 -1
- package/kernel.js +1 -1
- package/layers/Lyr3DWasmPerSceneView.js +1 -1
- package/layers/VoxelWasmPerSceneView.js +1 -1
- package/layers/effects/parser.js +1 -1
- package/layers/geospatialPDF/GeospatialPDFLayerWorker.js +1 -1
- package/layers/graphics/controllers/I3SOnDemandController.js +1 -1
- package/layers/graphics/data/QueryEngineResult.js +1 -1
- package/layers/graphics/sources/support/ParquetSourceWorker.js +1 -1
- package/layers/parquet.js +1 -1
- package/layers/raster/datasets/ZarrRaster.js +1 -1
- package/layers/raster/datasets/wcsCoverageParser.js +1 -1
- package/layers/raster/formats/RasterCodec.js +1 -1
- package/layers/raster/formats/blosc.js +2 -0
- package/layers/support/BuildingFilter.js +1 -1
- package/layers/support/IntegratedMeshSemantics.js +1 -1
- package/layers/support/fieldUtils.d.ts +23 -87
- package/layers/support/fieldUtils.js +1 -1
- package/layers/support/layersMapping.js +1 -1
- package/layers/video/VideoController.js +1 -1
- package/legend/ActiveLayerInfo.js +1 -1
- package/libs/ajv/ajv.bundle-wrapper.js +1 -1
- package/package.json +4 -4
- package/renderers/types.d.ts +1 -1
- package/rest/knowledgeGraphService.js +1 -1
- package/rest/query/operations/pbfFeatureServiceParser.js +1 -1
- package/smartMapping/statistics/support/attributeDensity.js +1 -1
- package/smartMapping/support/adapters/support/utils.js +1 -1
- package/support/tests/serviceMockDependencies.js +1 -1
- package/symbols/cim/CIMEffects.js +1 -1
- package/symbols/cim/CIMSymbolDrawHelper.js +1 -1
- package/symbols/cim/effects/EffectControlMeasureLine.js +1 -1
- package/symbols/cim/placements/PlacementInsidePolygon.js +1 -1
- package/symbols/cim/rasterizingUtils.js +1 -1
- package/views/2d/PaddedViewState.js +1 -1
- package/views/2d/engine/vectorTiles/buckets/FillBucket.js +1 -1
- package/views/2d/engine/vectorTiles/constants.js +1 -1
- package/views/2d/engine/vectorTiles/style/geoJSONVectorTileUtils.js +1 -1
- package/views/2d/engine/webgl/effects/HighlightEffect.js +1 -1
- package/views/2d/engine/webgl/mesh/templates/segmentUtils.js +1 -1
- package/views/2d/engine/webgl/mesh/templates/shapingUtils.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/shaders/constants.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/text/TextShader.js +1 -1
- package/views/2d/interactive/editingTools/ControlPointsTransformTool.js +1 -1
- package/views/2d/interactive/editingTools/TransformTool.js +1 -1
- package/views/2d/layers/FeatureLikeLayerView2D.js +1 -1
- package/views/2d/layers/ParquetLayerView2D.js +1 -1
- package/views/2d/layers/features/Processor.js +1 -1
- package/views/2d/layers/features/aggregation/GridSpatialIndex.js +1 -1
- package/views/2d/layers/features/support/AttributeStore.js +1 -1
- package/views/2d/layers/features/support/FeatureSetReaderPBF.js +1 -1
- package/views/2d/layers/graphics/GraphicsView2D.js +1 -1
- package/views/3d/analysis/AreaMeasurement/support/AreaMeasurementPathHelper.js +1 -1
- package/views/3d/analysis/Dimension/DimensionTool.js +1 -1
- package/views/3d/analysis/Dimension/LengthDimensionSubTool.js +1 -1
- package/views/3d/analysis/ElevationProfile/ElevationProfileLineSceneComputation.js +1 -1
- package/views/3d/analysis/LineOfSight/LineOfSightController.js +1 -1
- package/views/3d/analysis/LineOfSight/LineOfSightItemManipulatedObject3D.js +1 -1
- package/views/3d/analysis/LineOfSight/LineOfSightRayIntersector.js +1 -1
- package/views/3d/analysis/ShadowCastAnalysisView3D.js +1 -1
- package/views/3d/analysis/Slice/SliceTool.js +1 -1
- package/views/3d/analysis/Viewshed/ViewshedObserverManipulatedObject3D.js +1 -1
- package/views/3d/analysis/Viewshed/ViewshedSnappingController.js +1 -1
- package/views/3d/analysis/Viewshed/ViewshedTool.js +1 -1
- package/views/3d/analysis/ViewshedAnalysisView3D.js +1 -1
- package/views/3d/analysis/VolumeMeasurement/VolumeMeasurementCutFillComputation.js +1 -1
- package/views/3d/analysis/VolumeMeasurement/VolumeMeasurementVisualization.js +1 -1
- package/views/3d/animation/pointToPoint/Camera.js +1 -1
- package/views/3d/camera/constraintUtils.js +1 -1
- package/views/3d/camera/intersectionUtils.js +1 -1
- package/views/3d/environment/EnvironmentView.js +1 -1
- package/views/3d/focusAreaUtils.js +1 -1
- package/views/3d/interactive/editingTools/ManipulatedObject3DGraphic.js +1 -1
- package/views/3d/interactive/editingTools/dragEventPipeline3D.js +1 -1
- package/views/3d/interactive/editingTools/manipulations/config.js +1 -1
- package/views/3d/interactive/editingTools/media/MediaElementControllerControlPoints.js +1 -1
- package/views/3d/interactive/editingTools/media/MediaElementControllerShape.js +1 -1
- package/views/3d/interactive/editingTools/move/MoveTool3D.js +1 -1
- package/views/3d/interactive/editingTools/transform/ScaleRotateMeshAdapter.js +1 -1
- package/views/3d/interactive/editingTools/transform/TransformTool3D.js +1 -1
- package/views/3d/interactive/measurementTools/areaMeasurement3D/AreaMeasurement3DTool.js +1 -1
- package/views/3d/interactive/measurementTools/areaMeasurement3D/AreaMeasurement3DView.js +1 -1
- package/views/3d/interactive/measurementTools/directLineMeasurement3D/DirectLineMeasurement3DTool.js +1 -1
- package/views/3d/layers/I3SMeshView3D.js +1 -1
- package/views/3d/layers/SceneLayerGraphicsView3D.js +1 -1
- package/views/3d/layers/TiledLayerView3D.js +1 -1
- package/views/3d/layers/graphics/Graphics3DExtrudeSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DIconSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DLineSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DMeshFillSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DObjectSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DPathSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DPolygonFillSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DSymbolFactory.js +1 -1
- package/views/3d/layers/graphics/LabelInfo.js +1 -1
- package/views/3d/layers/i3s/I3SClientNodeLoader.js +1 -1
- package/views/3d/layers/i3s/I3SIndex.js +1 -1
- package/views/3d/layers/i3s/I3SIntersectionHandler.js +1 -1
- package/views/3d/layers/i3s/I3SMeshViewFilter.js +1 -1
- package/views/3d/layers/i3s/I3SNode.js +1 -1
- package/views/3d/layers/i3s/I3SOverrides.js +1 -1
- package/views/3d/layers/i3s/I3SViewportQueries.js +1 -1
- package/views/3d/layers/i3s/LayerElevationProvider.js +1 -1
- package/views/3d/layers/support/FeatureTileFetcher3D.js +1 -1
- package/views/3d/layers/support/FeatureTileFetcher3DContext.js +1 -1
- package/views/3d/layers/support/FeatureTileMeasurements3D.js +1 -1
- package/views/3d/layers/support/FeatureTileVisibility3D.js +1 -1
- package/views/3d/layers/support/StageLayerElevationProvider.js +1 -1
- package/views/3d/layers/support/Tiles3DLayerViewRegistration.js +1 -1
- package/views/3d/layers/support/selectTiles3DSpatialReference.js +1 -1
- package/views/3d/layers/support/uvUtils.js +1 -1
- package/views/3d/state/Constraints.js +1 -1
- package/views/3d/state/ConstraintsManager.js +1 -1
- package/views/3d/state/NearFarHeuristic.js +1 -1
- package/views/3d/state/ViewState.js +1 -1
- package/views/3d/state/ViewStateManager.js +1 -1
- package/views/3d/state/controllers/PinchAndPanControllerGlobal.js +1 -1
- package/views/3d/state/controllers/PinchAndPanControllerLocal.js +1 -1
- package/views/3d/state/controllers/PointToPointAnimationController.js +1 -1
- package/views/3d/state/controllers/ZoomStepControllerGlobal.js +1 -1
- package/views/3d/state/controllers/ZoomStepControllerLocal.js +1 -1
- package/views/3d/state/helpers/SceneIntersectionHelper.js +1 -1
- package/views/3d/state/utils/OffsetCorrectionController.js +1 -1
- package/views/3d/state/utils/groundNavigationUtils.js +1 -1
- package/views/3d/state/utils/navigationUtils.js +1 -1
- package/views/3d/support/FrustumExtentIntersection.js +1 -1
- package/views/3d/support/RenderCoordsHelper.js +1 -1
- package/views/3d/support/SweptSphereVolume.js +1 -1
- package/views/3d/support/cameraUtils.js +1 -1
- package/views/3d/support/elevationUpdateExtentUtils.js +1 -1
- package/views/3d/support/engineContent/line.js +1 -1
- package/views/3d/support/engineContent/marker.js +1 -1
- package/views/3d/support/hitTest.js +1 -1
- package/views/3d/support/orientedBoundingBox.js +1 -1
- package/views/3d/support/pointsOfInterest/CameraOnSurface.js +1 -1
- package/views/3d/support/pointsOfInterest/PointsOfInterest.js +1 -1
- package/views/3d/support/pointsOfInterest/SurfaceGeometryUpdates.js +1 -1
- package/views/3d/support/sunUtils.js +1 -1
- package/views/3d/terrain/ExtentHelper.js +1 -1
- package/views/3d/terrain/OverlayManager.js +1 -1
- package/views/3d/terrain/OverlayRenderer.js +1 -1
- package/views/3d/terrain/PatchGeometryFactory.js +1 -1
- package/views/3d/terrain/TerrainRenderer.js +1 -1
- package/views/3d/terrain/TerrainSurface.js +1 -1
- package/views/3d/terrain/Tile.js +1 -1
- package/views/3d/terrain/TilingSchemeLogic.js +1 -1
- package/views/3d/terrain/terrainUtils.js +1 -1
- package/views/3d/webgl/RenderCamera.js +1 -1
- package/views/3d/webgl-engine/Stage.js +1 -1
- package/views/3d/webgl-engine/collections/Component/ComponentObject.js +1 -1
- package/views/3d/webgl-engine/collections/Component/ComponentObjectCollection.js +1 -1
- package/views/3d/webgl-engine/collections/Component/ComponentObjectElevationAgnosticBVH.js +1 -1
- package/views/3d/webgl-engine/collections/Component/ComponentObjectElevationAgnosticComponentGeometryBVH.js +1 -1
- package/views/3d/webgl-engine/collections/Component/ElevationAgnosticBVH.js +1 -1
- package/views/3d/webgl-engine/collections/Component/IntersectionGeometry.js +1 -1
- package/views/3d/webgl-engine/collections/Component/Material/ComponentMaterial.js +1 -1
- package/views/3d/webgl-engine/collections/Component/Material/ComponentMaterialRepository.js +1 -1
- package/views/3d/webgl-engine/collections/Component/Material/ComponentTechniqueConfiguration.js +1 -1
- package/views/3d/webgl-engine/core/shaderLibrary/terrain/Overlay.glsl.js +1 -1
- package/views/3d/webgl-engine/effects/atmosphere/MarsAtmosphere.js +1 -1
- package/views/3d/webgl-engine/effects/debug/RenderNodeVisualizerNode.js +1 -1
- package/views/3d/webgl-engine/effects/highlight/ShadowHighlight.js +1 -1
- package/views/3d/webgl-engine/effects/laserlines/LaserlinePathData.js +1 -1
- package/views/3d/webgl-engine/effects/shadowAccumulation/ShadowAccumulator.js +1 -1
- package/views/3d/webgl-engine/lib/Intersector.js +1 -1
- package/views/3d/webgl-engine/lib/Renderer.js +1 -1
- package/views/3d/webgl-engine/lib/ShadowMap.js +1 -1
- package/views/3d/webgl-engine/lib/TextRenderParameters.js +1 -1
- package/views/3d/webgl-engine/lib/TextRenderer.js +1 -1
- package/views/3d/webgl-engine/lib/TriangleIntersectionData.js +1 -1
- package/views/3d/webgl-engine/lib/edgeRendering/EdgeView.js +1 -1
- package/views/3d/webgl-engine/lib/edgeRendering/strokes.js +1 -1
- package/views/3d/webgl-engine/lib/verticalOffsetUtils.js +1 -1
- package/views/3d/webgl-engine/materials/DefaultMaterial.js +1 -1
- package/views/3d/webgl-engine/materials/PolygonOffset.js +1 -1
- package/views/3d/webgl-engine/materials/RibbonLineMaterial.js +1 -1
- package/views/3d/webgl-engine/parts/RenderView.js +1 -1
- package/views/MapView.d.ts +1 -0
- package/views/SceneView.js +1 -1
- package/views/View2D.js +1 -1
- package/views/ViewingMode.js +1 -1
- package/views/analysis/ElevationProfile/elevationProfileChartBoundsUtils.js +1 -1
- package/views/analysis/ElevationProfile/elevationProfileGeometryUtils.js +1 -1
- package/views/draw/DrawAction.js +1 -1
- package/views/draw/DrawOperation.js +1 -1
- package/views/draw/DrawTool.js +1 -1
- package/views/draw/SegmentDrawAction.js +1 -1
- package/views/draw/support/Reshape.js +1 -1
- package/views/draw/support/helpMessageUtils.js +1 -1
- package/views/draw/support/managers/EditSessionManager.js +1 -1
- package/views/interactive/dragEventPipeline.js +1 -1
- package/views/interactive/editGeometry/EditGeometry.js +1 -1
- package/views/interactive/editGeometry/EditGeometryOperations.js +1 -1
- package/views/interactive/editGeometry/operations/AddOrUpdatePart.js +1 -1
- package/views/layers/support/editableLayerViews.js +1 -1
- package/views/overlay/TextOverlayItem.js +1 -1
- package/views/support/DefaultsFromMap.js +1 -1
- package/views/support/Scheduler.js +1 -1
- package/views/support/spatialReferenceSupport.js +1 -1
- package/views/webgl/ShaderTranspiler.js +2 -2
- package/widgets/AreaMeasurement2D/AreaMeasurement2DTool.js +1 -1
- package/widgets/BasemapGallery/support/basemapCompatibilityUtils.js +1 -1
- package/widgets/BatchAttributeForm.js +1 -1
- package/widgets/DistanceMeasurement2D/DistanceMeasurement2DTool.js +1 -1
- package/widgets/Editor/workflowUtils.js +1 -1
- package/widgets/ElevationProfile/ElevationProfileLineView.js +1 -1
- package/widgets/ElevationProfile/support/chartUtils.js +1 -1
- package/widgets/ElevationProfile/support/geometryUtils.js +1 -1
- package/widgets/FeatureForm.js +1 -1
- package/widgets/Legend/styles/card/ColorRamp.js +1 -1
- package/widgets/Legend/support/ActiveLayerInfo.js +1 -1
- package/widgets/Measurement.js +1 -1
- package/widgets/OrientedImageryViewer/components/ImageLocationWidget.js +1 -1
- package/widgets/OrientedImageryViewer/components/ImageMeasurementWidget.js +1 -1
- package/widgets/Search/support/layerSearchUtils.js +1 -1
- package/widgets/ShadowCast/ShadowCastViewModel.js +1 -1
- package/widgets/UtilityNetworkAssociations/UtilityNetworkAssociationsViewModel.js +1 -1
- package/widgets/UtilityNetworkAssociations.js +1 -1
- package/widgets/Weather/WeatherViewModel.js +1 -1
- package/widgets/Weather/css.js +1 -1
- package/widgets/Weather.js +1 -1
- package/assets/esri/core/workers/chunks/021bd07b9a3e70598840.js +0 -1
- package/assets/esri/core/workers/chunks/170e68624b71ac96de4a.js +0 -1
- package/assets/esri/core/workers/chunks/8a820e303941b351de81.js +0 -1
- package/assets/esri/core/workers/chunks/90d567e920b6982b402d.js +0 -1
- package/assets/esri/core/workers/chunks/97cdcedfe853280f6258.js +0 -1
- package/assets/esri/core/workers/chunks/9ebc6026934400fc1e1f.js +0 -1
- package/assets/esri/core/workers/chunks/b4a325dcf50e276751d7.js +0 -1
- package/assets/esri/core/workers/chunks/be5857b0d1b00faf430b.js +0 -1
- package/assets/esri/core/workers/chunks/cd9100a7c8309dfa7569.js +0 -1
- package/assets/esri/core/workers/chunks/e58f51618251f74aaafd.js +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import{getAssetUrl as e}from"../../assets.js";import t from"../../core/Error.js";import{create as n,fromValues as r}from"../../core/libs/gl-matrix-2/factories/mat2df64.js";import{invert as i}from"../../core/libs/gl-matrix-2/math/mat2d.js";import{throwIfAborted as a}from"../../core/promiseUtils.js";import o from"../../geometry/Extent.js";import s from"../../request.js";import{parseAttachments as c}from"./parseAttachmentUtils.js";import{renderBitmap as l}from"./renderExtentUtils.js";const u=!(typeof process!=`object`||process+``!=`[object process]`||process.versions.nw||process.versions.electron&&process.type&&process.type!==`browser`),d=[1/0,1/0,-1/0,-1/0],f=new Float32Array(d),p=[.001,0,0,.001,0,0],m=1.35,h={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},g=`pdfjs_internal_id_`,_=`pdfjs_internal_editor_`,v={NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15,POPUP:16,SIGNATURE:101},y={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},b={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},x={WARNINGS:1,INFOS:5},S={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 C=x.WARNINGS;function w(e){Number.isInteger(e)&&(C=e)}function T(){return C}function E(e){C>=x.INFOS&&console.info(`Info: ${e}`)}function D(e){C>=x.WARNINGS&&console.warn(`Warning: ${e}`)}function O(e){throw Error(e)}function k(e,t){e||O(t)}function A(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 ee(e,t,n=!1){let r=URL.parse(e);if(r){r.hash=t;return r.href}return n&&A(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 te extends M{constructor(e,t){super(e,`PasswordException`);this.code=t}}class ne extends M{constructor(e,t){super(e,`UnknownErrorException`);this.details=t}}class re extends M{constructor(e){super(e,`InvalidPDFException`)}}class ie extends M{constructor(e,t,n){super(e,`ResponseException`);this.status=t;this.missing=n}}class ae extends M{constructor(e){super(e,`FormatError`)}}class oe extends M{constructor(e){super(e,`AbortException`)}}function se(e){typeof e!=`string`&&O(`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 ce(){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||O(`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 le=()=>[],ue=()=>new Map,de=()=>Object.create(null);function F(e,t,n){return Math.min(Math.max(e,t),n)}class fe{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(!fe.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 pe{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&&fe.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&&fe.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 me{static CSS=96;static PDF=72;static PDF_TO_CSS_UNITS=this.CSS/this.PDF}async function he(e,t=`text`){if(xe(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 ge{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 ge({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 _e extends M{constructor(e,t=0){super(e,`RenderingCancelledException`);this.extraDelay=t}}function ve(e){let t=e.length,n=0;for(;n<t&&e[n].trim()===``;)n++;return e.substring(n,n+5).toLowerCase()===`data:`}function ye(e){return typeof e==`string`&&/\.pdf$/i.test(e)}class be{#e=new Map;times=[];time(e){this.#e.has(e)&&D(`Timer is already running for ${e}`);this.#e.set(e,Date.now())}timeEnd(e){this.#e.has(e)||D(`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 xe(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 Se{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 Ce(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 we(e){let t=Ce(e);if(!t){D(`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 Te(e,t,n=!1,r=!0){if(t instanceof ge){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 Ee{constructor(){let{pixelRatio:e}=Ee;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=Ee.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 De=[`image/apng`,`image/avif`,`image/bmp`,`image/gif`,`image/jpeg`,`image/png`,`image/svg+xml`,`image/webp`,`image/x-icon`];class Oe{static get isDarkMode(){return j(this,`isDarkMode`,!!window?.matchMedia?.(`(prefers-color-scheme: dark)`).matches)}}function ke({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 pe.render({xfaHtml:e,div:i,intent:`richText`});i.firstElementChild.classList.add(`richText`,n);r.append(i)}function Ae(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:D(`Unrecognized drawing path operator: ${e[n-1]}`)}return t}class je{#e=null;#t=null;#n;#r=null;#i=null;#a=null;#o=null;#s=null;static#c=null;constructor(e){this.#n=e;je.#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`,je.#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`,je.#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 Me{#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 Ne(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 Pe{#e=0;get id(){return`${_}${this.#e++}`}}class Fe{#e=ce();#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 he(t,`blob`)}else t instanceof File?e=n.file=t:t instanceof Blob&&(e=t);if(e.type===`image/svg+xml`){let t=Fe._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){D(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 Ie{#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 Le{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 Re{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,we(r))}t.remove()})(e);return j(this,`_colors`,e)}convert(e){let t=we(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 Re._colorsMapping.get(e);return t}getHexCode(e){let t=this._colors.get(e);return t?P.makeHexColor(...t):e}}class ze{#e=new AbortController;#t=null;#n=null;#r=new Map;#i=new Map;#a=null;#o=null;#s=null;#c=null;#l=new Ie;#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 Pe;#O=!1;#k=!1;#A=!1;#j=null;#M=null;#N=null;#P=null;#F=null;#I=v.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=ze.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 Le([[[`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:me.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*me.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===v.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(v.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 Me(this);this.#E.show(t,n,this.direction===`ltr`)}}getAndRemoveDataFromAnnotationStorage(e){if(!this.#s)return null;let t=`${_}${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===v.HIGHLIGHT||this.#I===v.NONE){this.#I===v.HIGHLIGHT&&this.showAllEditors(`highlight`,!0,!0);this.#T=this.isShiftKeyDown;if(!this.isShiftKeyDown){let e=this.#I===v.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===v.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){D(`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){D(`paste: "${e.message}".`)}}keydown(e){this.isShiftKeyDown||e.key!==`Shift`||(this.isShiftKeyDown=!0);this.#I===v.NONE||this.isEditorHandlingKeyboard||ze._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!==v.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===v.HIGHLIGHT&&!1===e.hasSelectedEditor&&this.#de([[y.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!==v.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===v.POPUP&&this.#u?.hideSidebar();this.#u?.destroyPopup();this.#I=e;if(e!==v.NONE){for(let e of this.#r.values())e.addStandaloneCommentButton();e===v.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===v.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 y.CREATE:this.currentLayer.addNewEditor(t);return;case y.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(y.HIGHLIGHT_SHOW_ALL)??!0)!==t&&this.#de([[y.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!==v.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!==v.NONE}get imageManager(){return j(this,`imageManager`,new Fe)}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!==v.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 Be{#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;Be.#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){Be._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`,Be.#f.missing);t.setAttribute(`data-l10n-id`,Be.#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 Be._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`,Be.#f[this.#p]);this.#r?.setAttribute(`data-l10n-id`,Be.#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 Ve{#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 He{#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/Ee.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)<=He.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 Re;static _zIndex=1;static _telemetryTimeout=1e3;static get _resizerKeyboardManager(){let e=H.prototype._resizeWithKeyboard,t=ze.TRANSLATE_SMALL,n=ze.TRANSLATE_BIG;return j(this,`_resizerKeyboardManager`,new Le([[[`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 Ue({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){O(`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],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 je(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){Be.initialize(H._l10n);this.#n=new Be(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 Ve(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 Ve(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 Ve(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 Ve(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);Ne(this,e,[`keydown`,`pointerdown`,`dblclick`]);this.isResizable&&this._uiManager._supportsPinchToZoom&&(this.#C||=new He({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 Ue extends H{constructor(e){super(e);this.annotationElementId=e.annotationElementId;this.deleted=!0}serialize(){return this.serializeDeleted()}}const We=0xc3d2e1f0,U=0xffff0000,Ge=65535;class Ke{constructor(e){this.h1=e?0|e:We;this.h2=e?0|e:We}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=0xcc9e2d51,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&Ge;o=o<<15|o>>>17;o=o*d&U|o*p&Ge;c^=o;c=c<<13|c>>>19;c=5*c+0xe6546b64}else{s=a[e];s=s*u&U|s*f&Ge;s=s<<15|s>>>17;s=s*d&U|s*p&Ge;l^=s;l=l<<13|l>>>19;l=5*l+0xe6546b64}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&Ge;o=o<<15|o>>>17;o=o*d&U|o*p&Ge;1&r?c^=o:l^=o}this.h1=c;this.h2=l}hexdigest(){let e=this.h1,t=this.h2;e^=t>>>1;e=0xed558ccd*e&U|36045*e&Ge;t=0xff51afd7*t&U|(0xafd7ed55*(t<<16|e>>>16)&U)>>>16;e^=t>>>1;e=444984403*e&U|60499*e&Ge;t=0xc4ceb9fe*t&U|(0xb9fe1a85*(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 qe=Object.freeze({map:null,hash:``,transfer:void 0});class Je{#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 Ye(this)}get serializable(){if(this.#r.size===0)return qe;let e=new Map,t=new Ke,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}:qe}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,ue);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 Ke;n.update(e.join(`,`));t=n.hexdigest()}return this.#t={ids:new Set(e),hash:t}}[Symbol.iterator](){return this.#r.entries()}}class Ye extends Je{#e=qe;constructor(e){super();let{serializable:t}=e;if(t===qe)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(){O(`Should not call PrintAnnotationStorage.print`)}get serializable(){return this.#e}get modifiedIds(){return j(this,`modifiedIds`,{ids:new Set,hash:``})}}const Xe=`__forcedDependency`,{floor:Ze,ceil:Qe}=Math;function $e(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 et=new Uint32Array(new Uint8Array([255,255,0,0]).buffer)[0];class tt{#e;#t;constructor(e,t){this.#e=e;this.#t=t}get length(){return this.#e.length}isEmpty(e){return this.#e[e]===et}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 nt=(e,t)=>e?.getOrInsertComputed(t,()=>({dependencies:new Set,isRenderingOperation:!1}));class rt{#e=[[1,0,0,1,0,0]];#t=[-1/0,-1/0,1/0,1/0];#n=new Float64Array(d);_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(et,t.length)}else this.#o.fill(et)}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(d,0)}return this}recordClipBox(e,t,n,r,i,a){let o=P.multiplyByDOMMatrix(this.#e.at(-1),t.getTransform()),s=d.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=d.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=Ze(256*this.#n[0]/this.#r),i=Ze(256*this.#n[1]/this.#i),a=Qe(256*this.#n[2]/this.#r),o=Qe(256*this.#n[3]/this.#i);$e(this.#a,e,r,i,a,o);if(n)for(let t of n)for(let n of t)n!==e&&$e(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 tt(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 it{#e={__proto__:null};#t={__proto__:null,transform:[],moveText:[],sameLineText:[],[Xe]:[]};#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)=>{nt(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},[Xe]:{__proto__:this.#t[Xe]}};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(Xe,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(Xe,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,[Xe]);if(this.#a){let t=nt(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 at{#e;#t;#n;#r=0;#i=0;constructor(e,t,n){if(e instanceof at&&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 ot=[`path`,`transform`,`filter`,`strokeColor`,`strokeAlpha`,`lineWidth`,`lineCap`,`lineJoin`,`miterLimit`,`dash`],st=[`path`,`transform`,`filter`,`fillColor`,`fillAlpha`,`globalCompositeOperation`,`SMask`],ct=[`transform`,`SMask`,`filter`,`fillAlpha`,`strokeAlpha`,`globalCompositeOperation`],lt=[`filter`,`fillColor`,`fillAlpha`],ut=[`transform`,`leading`,`charSpacing`,`wordSpacing`,`hScale`,`textRise`,`moveText`,`textMatrix`,`font`,`fontObj`,`filter`,`fillColor`,`textRenderingMode`,`SMask`,`fillAlpha`,`strokeAlpha`,`globalCompositeOperation`,`sameLineText`],dt=[`transform`],ft=[`transform`,`fillColor`];class pt{#e;#t;#n=4;#r=0;#i=new pt.#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 pt.#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=d.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 mt{#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)){k(!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{D(`Cannot load system font: ${e.baseFontName}, installing it could help to improve PDF rendering.`);this.removeNativeFontFace(a)}return}O(`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){D(`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`,u||N.platform.isFirefox)}_queueLoadingCallback(e){let{loadingRequests:t}=this,n={done:!1,complete:function(){k(!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=0x58585858,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){D(`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 ht{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){D(`getPathGenerator - ignoring character: "${e}".`)}let i=Ae(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 gt{static strings=[`fontFamily`,`fontWeight`,`italicAngle`]}class _t{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 vt{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 yt{#e;#t=new TextDecoder;#n;constructor(e){this.#e=e;this.#n=new DataView(e)}#r(e){k(e<gt.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 bt{#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){k(e<_t.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 xt{#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){k(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){k(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;k(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){k(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 yt(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 bt(n.buffer)}}class St{constructor(e){this.buffer=e;this.view=new DataView(e);this.data=new Uint8Array(e)}getIR(){let e=this.view,t=this.data[vt.KIND],n=!!this.data[vt.HAS_BBOX],r=!!this.data[vt.HAS_BACKGROUND],i=e.getUint32(vt.N_COORD,!0),a=e.getUint32(vt.N_COLOR,!0),o=e.getUint32(vt.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 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,u,Array.from(c.slice(0,2)),Array.from(c.slice(2,4)),null,null];if(t===2)return[`RadialAxial`,`radial`,f,u,[c[0],c[1]],[c[3],c[4]],c[2],c[5]];if(t===3){let e=this.data[vt.SHADING_TYPE],t=null;if(c.length>0){t=d.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 Ct{#e;constructor(e){this.#e=e}get path(){return N.isFloat16ArraySupported?new Float16Array(this.#e):new Float32Array(this.#e)}}function wt(e){if(typeof e!=`string`)return null;if(e.endsWith(`/`))return e;throw Error(`Invalid factory url: "${e}" must include trailing slash.`)}const Tt=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,Tt,e=>typeof e==`object`&&typeof e?.name==`string`);class Et{#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){D("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 Dt(){}function G(e){if(e instanceof oe||e instanceof re||e instanceof te||e instanceof ie||e instanceof ne)return e;e instanceof Error||typeof e==`object`&&e||O(`wrapReason: Expected "reason" to be a (possibly cloned) Error.`);switch(e.name){case`AbortException`:return new oe(e.message);case`InvalidPDFException`:return new re(e.message);case`PasswordException`:return new te(e.message,e.code);case`ResponseException`:return new ie(e.message,e.status,e.missing);case`UnknownErrorException`:return new ne(e.message,e.details)}return new ne(e.message,e.toString())}class Ot{#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=>{k(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){k(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||Dt).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:k(a,`enqueue should have stream controller`);if(a.isClosed)break;a.controller.enqueue(e.chunk);break;case 3:k(a,`close should have stream controller`);if(a.isClosed)break;a.isClosed=!0;a.controller.close();this.#i(a,t);break;case 5:k(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||Dt,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 kt{#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:O(`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){O("Abstract method `_fetch` called.")}}class At extends kt{async _fetch(e,t){let n=await he(e,t!==`cMapUrl`||e.endsWith(`.bcmap`)?`bytes`:`text`);return n instanceof Uint8Array?n:se(n)}}class jt{#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){O("Abstract method `_createCanvas` called.")}}class Mt extends jt{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 Nt{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 Pt extends Nt{#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&&(ve(e)?D(`#createUrl: ignore "data:"-URL for performance reasons.`):this.#e=ee(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 we(getComputedStyle(this.#l).getPropertyValue(`color`))}}u&&D("Please use the `legacy` build in Node.js environments.");class Ft extends Nt{}class It extends jt{_createCanvas(e,t){return process.getBuiltinModule(`module`).createRequire(import.meta.url)(`@napi-rs/canvas`).createCanvas(e,t)}}class Lt extends kt{async _fetch(e,t){return async function(e){let t=await process.getBuiltinModule(`fs/promises`).readFile(e);return new Uint8Array(t)}(e)}}const Rt=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"../../core/Error.js";import{create as n,fromValues as r}from"../../core/libs/gl-matrix-2/factories/mat2df64.js";import{invert as i}from"../../core/libs/gl-matrix-2/math/mat2d.js";import{throwIfAborted as a}from"../../core/promiseUtils.js";import o from"../../geometry/Extent.js";import s from"../../request.js";import{parseAttachments as c}from"./parseAttachmentUtils.js";import{renderBitmap as l}from"./renderExtentUtils.js";const u=!(typeof process!=`object`||process+``!=`[object process]`||process.versions.nw||process.versions.electron&&process.type&&process.type!==`browser`),d=[1/0,1/0,-1/0,-1/0],f=new Float32Array(d),p=[.001,0,0,.001,0,0],m=1.35,h={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},g=`pdfjs_internal_id_`,_=`pdfjs_internal_editor_`,v={NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15,POPUP:16,SIGNATURE:101},y={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},b={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},x={WARNINGS:1,INFOS:5},S={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 C=x.WARNINGS;function w(e){Number.isInteger(e)&&(C=e)}function T(){return C}function E(e){C>=x.INFOS&&console.info(`Info: ${e}`)}function D(e){C>=x.WARNINGS&&console.warn(`Warning: ${e}`)}function O(e){throw Error(e)}function k(e,t){e||O(t)}function A(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 ee(e,t,n=!1){let r=URL.parse(e);if(r){r.hash=t;return r.href}return n&&A(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 te extends M{constructor(e,t){super(e,`PasswordException`);this.code=t}}class ne extends M{constructor(e,t){super(e,`UnknownErrorException`);this.details=t}}class re extends M{constructor(e){super(e,`InvalidPDFException`)}}class ie extends M{constructor(e,t,n){super(e,`ResponseException`);this.status=t;this.missing=n}}class ae extends M{constructor(e){super(e,`FormatError`)}}class oe extends M{constructor(e){super(e,`AbortException`)}}function se(e){typeof e!=`string`&&O(`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 ce(){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||O(`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 le=()=>[],ue=()=>new Map,de=()=>Object.create(null);function F(e,t,n){return Math.min(Math.max(e,t),n)}class fe{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(!fe.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 pe{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&&fe.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&&fe.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 me{static CSS=96;static PDF=72;static PDF_TO_CSS_UNITS=this.CSS/this.PDF}async function he(e,t=`text`){if(xe(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 ge{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 ge({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 _e extends M{constructor(e,t=0){super(e,`RenderingCancelledException`);this.extraDelay=t}}function ve(e){let t=e.length,n=0;for(;n<t&&e[n].trim()===``;)n++;return e.substring(n,n+5).toLowerCase()===`data:`}function ye(e){return typeof e==`string`&&/\.pdf$/i.test(e)}class be{#e=new Map;times=[];time(e){this.#e.has(e)&&D(`Timer is already running for ${e}`);this.#e.set(e,Date.now())}timeEnd(e){this.#e.has(e)||D(`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 xe(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 Se{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 Ce(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 we(e){let t=Ce(e);if(!t){D(`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 Te(e,t,n=!1,r=!0){if(t instanceof ge){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 Ee{constructor(){let{pixelRatio:e}=Ee;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=Ee.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 De=[`image/apng`,`image/avif`,`image/bmp`,`image/gif`,`image/jpeg`,`image/png`,`image/svg+xml`,`image/webp`,`image/x-icon`];class Oe{static get isDarkMode(){return j(this,`isDarkMode`,!!window?.matchMedia?.(`(prefers-color-scheme: dark)`).matches)}}function ke({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 pe.render({xfaHtml:e,div:i,intent:`richText`});i.firstElementChild.classList.add(`richText`,n);r.append(i)}function Ae(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:D(`Unrecognized drawing path operator: ${e[n-1]}`)}return t}class je{#e=null;#t=null;#n;#r=null;#i=null;#a=null;#o=null;#s=null;static#c=null;constructor(e){this.#n=e;je.#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`,je.#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`,je.#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 Me{#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 Ne(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 Pe{#e=0;get id(){return`${_}${this.#e++}`}}class Fe{#e=ce();#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 he(t,`blob`)}else t instanceof File?e=n.file=t:t instanceof Blob&&(e=t);if(e.type===`image/svg+xml`){let t=Fe._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){D(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 Ie{#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 Le{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 Re{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,we(r))}t.remove()})(e);return j(this,`_colors`,e)}convert(e){let t=we(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 Re._colorsMapping.get(e);return t}getHexCode(e){let t=this._colors.get(e);return t?P.makeHexColor(...t):e}}class ze{#e=new AbortController;#t=null;#n=null;#r=new Map;#i=new Map;#a=null;#o=null;#s=null;#c=null;#l=new Ie;#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 Pe;#O=!1;#k=!1;#A=!1;#j=null;#M=null;#N=null;#P=null;#F=null;#I=v.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=ze.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 Le([[[`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:me.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*me.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===v.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(v.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 Me(this);this.#E.show(t,n,this.direction===`ltr`)}}getAndRemoveDataFromAnnotationStorage(e){if(!this.#s)return null;let t=`${_}${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===v.HIGHLIGHT||this.#I===v.NONE){this.#I===v.HIGHLIGHT&&this.showAllEditors(`highlight`,!0,!0);this.#T=this.isShiftKeyDown;if(!this.isShiftKeyDown){let e=this.#I===v.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===v.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){D(`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){D(`paste: "${e.message}".`)}}keydown(e){this.isShiftKeyDown||e.key!==`Shift`||(this.isShiftKeyDown=!0);this.#I===v.NONE||this.isEditorHandlingKeyboard||ze._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!==v.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===v.HIGHLIGHT&&!1===e.hasSelectedEditor&&this.#de([[y.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!==v.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===v.POPUP&&this.#u?.hideSidebar();this.#u?.destroyPopup();this.#I=e;if(e!==v.NONE){for(let e of this.#r.values())e.addStandaloneCommentButton();e===v.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===v.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 y.CREATE:this.currentLayer.addNewEditor(t);return;case y.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(y.HIGHLIGHT_SHOW_ALL)??!0)!==t&&this.#de([[y.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!==v.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!==v.NONE}get imageManager(){return j(this,`imageManager`,new Fe)}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!==v.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 Be{#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;Be.#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){Be._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`,Be.#f.missing);t.setAttribute(`data-l10n-id`,Be.#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 Be._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`,Be.#f[this.#p]);this.#r?.setAttribute(`data-l10n-id`,Be.#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 Ve{#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 He{#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/Ee.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)<=He.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 Re;static _zIndex=1;static _telemetryTimeout=1e3;static get _resizerKeyboardManager(){let e=H.prototype._resizeWithKeyboard,t=ze.TRANSLATE_SMALL,n=ze.TRANSLATE_BIG;return j(this,`_resizerKeyboardManager`,new Le([[[`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 Ue({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){O(`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],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 je(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){Be.initialize(H._l10n);this.#n=new Be(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 Ve(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 Ve(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 Ve(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 Ve(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);Ne(this,e,[`keydown`,`pointerdown`,`dblclick`]);this.isResizable&&this._uiManager._supportsPinchToZoom&&(this.#C||=new He({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 Ue extends H{constructor(e){super(e);this.annotationElementId=e.annotationElementId;this.deleted=!0}serialize(){return this.serializeDeleted()}}const We=0xc3d2e1f0,U=0xffff0000,Ge=65535;class Ke{constructor(e){this.h1=e?0|e:We;this.h2=e?0|e:We}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=0xcc9e2d51,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&Ge;o=o<<15|o>>>17;o=o*d&U|o*p&Ge;c^=o;c=c<<13|c>>>19;c=5*c+0xe6546b64}else{s=a[e];s=s*u&U|s*f&Ge;s=s<<15|s>>>17;s=s*d&U|s*p&Ge;l^=s;l=l<<13|l>>>19;l=5*l+0xe6546b64}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&Ge;o=o<<15|o>>>17;o=o*d&U|o*p&Ge;1&r?c^=o:l^=o}this.h1=c;this.h2=l}hexdigest(){let e=this.h1,t=this.h2;e^=t>>>1;e=0xed558ccd*e&U|36045*e&Ge;t=0xff51afd7*t&U|(0xafd7ed55*(t<<16|e>>>16)&U)>>>16;e^=t>>>1;e=444984403*e&U|60499*e&Ge;t=0xc4ceb9fe*t&U|(0xb9fe1a85*(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 qe=Object.freeze({map:null,hash:``,transfer:void 0});class Je{#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 Ye(this)}get serializable(){if(this.#r.size===0)return qe;let e=new Map,t=new Ke,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}:qe}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,ue);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 Ke;n.update(e.join(`,`));t=n.hexdigest()}return this.#t={ids:new Set(e),hash:t}}[Symbol.iterator](){return this.#r.entries()}}class Ye extends Je{#e=qe;constructor(e){super();let{serializable:t}=e;if(t===qe)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(){O(`Should not call PrintAnnotationStorage.print`)}get serializable(){return this.#e}get modifiedIds(){return j(this,`modifiedIds`,{ids:new Set,hash:``})}}const Xe=`__forcedDependency`,{floor:Ze,ceil:Qe}=Math;function $e(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 et=new Uint32Array(new Uint8Array([255,255,0,0]).buffer)[0];class tt{#e;#t;constructor(e,t){this.#e=e;this.#t=t}get length(){return this.#e.length}isEmpty(e){return this.#e[e]===et}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 nt=(e,t)=>e?.getOrInsertComputed(t,()=>({dependencies:new Set,isRenderingOperation:!1}));class rt{#e=[[1,0,0,1,0,0]];#t=[-1/0,-1/0,1/0,1/0];#n=new Float64Array(d);_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(et,t.length)}else this.#o.fill(et)}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(d,0)}return this}recordClipBox(e,t,n,r,i,a){let o=P.multiplyByDOMMatrix(this.#e.at(-1),t.getTransform()),s=d.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=d.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=Ze(256*this.#n[0]/this.#r),i=Ze(256*this.#n[1]/this.#i),a=Qe(256*this.#n[2]/this.#r),o=Qe(256*this.#n[3]/this.#i);$e(this.#a,e,r,i,a,o);if(n)for(let t of n)for(let n of t)n!==e&&$e(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 tt(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 it{#e={__proto__:null};#t={__proto__:null,transform:[],moveText:[],sameLineText:[],[Xe]:[]};#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)=>{nt(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},[Xe]:{__proto__:this.#t[Xe]}};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(Xe,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(Xe,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,[Xe]);if(this.#a){let t=nt(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 at{#e;#t;#n;#r=0;#i=0;constructor(e,t,n){if(e instanceof at&&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 ot=[`path`,`transform`,`filter`,`strokeColor`,`strokeAlpha`,`lineWidth`,`lineCap`,`lineJoin`,`miterLimit`,`dash`],st=[`path`,`transform`,`filter`,`fillColor`,`fillAlpha`,`globalCompositeOperation`,`SMask`],ct=[`transform`,`SMask`,`filter`,`fillAlpha`,`strokeAlpha`,`globalCompositeOperation`],lt=[`filter`,`fillColor`,`fillAlpha`],ut=[`transform`,`leading`,`charSpacing`,`wordSpacing`,`hScale`,`textRise`,`moveText`,`textMatrix`,`font`,`fontObj`,`filter`,`fillColor`,`textRenderingMode`,`SMask`,`fillAlpha`,`strokeAlpha`,`globalCompositeOperation`,`sameLineText`],dt=[`transform`],ft=[`transform`,`fillColor`];class pt{#e;#t;#n=4;#r=0;#i=new pt.#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 pt.#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=d.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 mt{#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)){k(!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{D(`Cannot load system font: ${e.baseFontName}, installing it could help to improve PDF rendering.`);this.removeNativeFontFace(a)}return}O(`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){D(`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`,u||N.platform.isFirefox)}_queueLoadingCallback(e){let{loadingRequests:t}=this,n={done:!1,complete:function(){k(!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=0x58585858,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){D(`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 ht{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){D(`getPathGenerator - ignoring character: "${e}".`)}let i=Ae(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 gt{static strings=[`fontFamily`,`fontWeight`,`italicAngle`]}class _t{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 vt{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 yt{#e;#t=new TextDecoder;#n;constructor(e){this.#e=e;this.#n=new DataView(e)}#r(e){k(e<gt.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 bt{#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){k(e<_t.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 xt{#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){k(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){k(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;k(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){k(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 yt(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 bt(n.buffer)}}class St{constructor(e){this.buffer=e;this.view=new DataView(e);this.data=new Uint8Array(e)}getIR(){let e=this.view,t=this.data[vt.KIND],n=!!this.data[vt.HAS_BBOX],r=!!this.data[vt.HAS_BACKGROUND],i=e.getUint32(vt.N_COORD,!0),a=e.getUint32(vt.N_COLOR,!0),o=e.getUint32(vt.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 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,u,Array.from(c.slice(0,2)),Array.from(c.slice(2,4)),null,null];if(t===2)return[`RadialAxial`,`radial`,f,u,[c[0],c[1]],[c[3],c[4]],c[2],c[5]];if(t===3){let e=this.data[vt.SHADING_TYPE],t=null;if(c.length>0){t=d.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 Ct{#e;constructor(e){this.#e=e}get path(){return N.isFloat16ArraySupported?new Float16Array(this.#e):new Float32Array(this.#e)}}function wt(e){if(typeof e!=`string`)return null;if(e.endsWith(`/`))return e;throw Error(`Invalid factory url: "${e}" must include trailing slash.`)}const Tt=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,Tt,e=>typeof e==`object`&&typeof e?.name==`string`);class Et{#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){D("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 Dt(){}function G(e){if(e instanceof oe||e instanceof re||e instanceof te||e instanceof ie||e instanceof ne)return e;e instanceof Error||typeof e==`object`&&e||O(`wrapReason: Expected "reason" to be a (possibly cloned) Error.`);switch(e.name){case`AbortException`:return new oe(e.message);case`InvalidPDFException`:return new re(e.message);case`PasswordException`:return new te(e.message,e.code);case`ResponseException`:return new ie(e.message,e.status,e.missing);case`UnknownErrorException`:return new ne(e.message,e.details)}return new ne(e.message,e.toString())}class Ot{#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=>{k(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){k(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||Dt).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:k(a,`enqueue should have stream controller`);if(a.isClosed)break;a.controller.enqueue(e.chunk);break;case 3:k(a,`close should have stream controller`);if(a.isClosed)break;a.isClosed=!0;a.controller.close();this.#i(a,t);break;case 5:k(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||Dt,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 kt{#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:O(`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){O("Abstract method `_fetch` called.")}}class At extends kt{async _fetch(e,t){let n=await he(e,t!==`cMapUrl`||e.endsWith(`.bcmap`)?`bytes`:`text`);return n instanceof Uint8Array?n:se(n)}}class jt{#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){O("Abstract method `_createCanvas` called.")}}class Mt extends jt{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 Nt{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 Pt extends Nt{#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&&(ve(e)?D(`#createUrl: ignore "data:"-URL for performance reasons.`):this.#e=ee(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 we(getComputedStyle(this.#l).getPropertyValue(`color`))}}u&&D("Please use the `legacy` build in Node.js environments.");class Ft extends Nt{}class It extends jt{_createCanvas(e,t){return process.getBuiltinModule(`module`).createRequire(import.meta.url)(`@napi-rs/canvas`).createCanvas(e,t)}}class Lt extends kt{async _fetch(e,t){return async function(e){let t=await process.getBuiltinModule(`fs/promises`).readFile(e);return new Uint8Array(t)}(e)}}const Rt=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,
|