@arcgis/core 6.0.0-next.13 → 6.0.0-next.15
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/arcade/containerUtils.js +1 -1
- package/arcade/featureset/sources/FeatureLayerDynamic.js +1 -1
- package/arcade/functions/feature.js +1 -1
- package/arcade/functions/featuresetstring.js +1 -1
- package/arcade/functions/geomasync.js +1 -1
- package/arcade/functions/portal.js +1 -1
- package/arcade/functions/string.js +1 -1
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/{5566f14afb63065e438f.js → 0050916e462e3c9e0627.js} +1 -1
- package/assets/esri/core/workers/chunks/02c5d027bdaee67869cf.js +1 -0
- package/assets/esri/core/workers/chunks/08fe248e412bb170210d.js +1 -0
- package/assets/esri/core/workers/chunks/0da6abe3ceabfe78f7a0.js +1 -0
- package/assets/esri/core/workers/chunks/0f617980c7dd9ad0444f.js +1 -0
- package/assets/esri/core/workers/chunks/{fb444954be74c1962ced.js → 10d80e793019dfb45ca2.js} +1 -1
- package/assets/esri/core/workers/chunks/{10445313d0d57b34511b.js → 2145a512d269d64036b0.js} +1 -1
- package/assets/esri/core/workers/chunks/21ddb26526bcb2b122c3.js +1 -0
- package/assets/esri/core/workers/chunks/25f19fc929f25ddd628c.js +1 -0
- package/assets/esri/core/workers/chunks/28b74bc77f7c13080074.js +1 -0
- package/assets/esri/core/workers/chunks/{2ef5237e4c876d6a4ee0.js → 2bd4ee083ca4ad221f8b.js} +1 -1
- package/assets/esri/core/workers/chunks/{f4f9d08b2df856e3b694.js → 2eae542fe7f0f6576ac1.js} +1 -1
- package/assets/esri/core/workers/chunks/{2aeb5cc32284dd3e4d22.js → 33e4ff228a8c81b99022.js} +1 -1
- package/assets/esri/core/workers/chunks/{42323093827adffe56d3.js → 3418877328f4f0830300.js} +1 -1
- package/assets/esri/core/workers/chunks/{8dc1c3042267618fd710.js → 34cbaf844730ac2d92c2.js} +2 -2
- package/assets/esri/core/workers/chunks/{96c50a0dda0f1503ef92.js → 3c301a689c7853c9fa67.js} +2 -2
- package/assets/esri/core/workers/chunks/{02253bdffbd580af22d8.js → 3ff6d1ed3c0f1285f3e7.js} +1 -1
- package/assets/esri/core/workers/chunks/{67e4b5651fd7ff7d8cf0.js → 4ac1d3e49e242e373a92.js} +1 -1
- package/assets/esri/core/workers/chunks/4df6cb1bee5d0720a43e.js +1 -0
- package/assets/esri/core/workers/chunks/{a4cab24af69260438ff4.js → 4e6f40cbdb8c508e6df1.js} +1 -1
- package/assets/esri/core/workers/chunks/5736feefa261589b6273.js +1 -0
- package/assets/esri/core/workers/chunks/601e1d020b8115497944.js +1 -0
- package/assets/esri/core/workers/chunks/{2686fe5b62dd0be699c0.js → 634523cc7757da9020e4.js} +1 -1
- package/assets/esri/core/workers/chunks/{a518ae5683367eeda74c.js → 70d3055f15d8b0cf4074.js} +1 -1
- package/assets/esri/core/workers/chunks/{1b946714ca4a1a7359d4.js → 76ab353d80d786777161.js} +2 -2
- package/assets/esri/core/workers/chunks/7f8e327acad48c9e75ea.js +1 -0
- package/assets/esri/core/workers/chunks/8052da8be251c3ff2176.js +1 -0
- package/assets/esri/core/workers/chunks/8e19629899a5becf8e19.js +1 -0
- package/assets/esri/core/workers/chunks/{f6e62d2d279a328cbed7.js → 90bdf86f553e2742d67c.js} +1 -1
- package/assets/esri/core/workers/chunks/91ebb2ccab1889eb7e81.js +1 -0
- package/assets/esri/core/workers/chunks/94e427040edb469d58ad.js +1 -0
- package/assets/esri/core/workers/chunks/{3d9d7d3a40b51eb7ee3d.js → 953ba13299e7aa92c1a0.js} +1 -1
- package/assets/esri/core/workers/chunks/{f46d9a19f79d4a4bd354.js → 9e1a3b6a08c96dcefdde.js} +1 -1
- package/assets/esri/core/workers/chunks/9f0a973a0dd28953ce25.js +1 -0
- package/assets/esri/core/workers/chunks/a2ad3e620c98e2b2eb06.js +1 -0
- package/assets/esri/core/workers/chunks/a34b3d2e11a777e1ff3f.js +1 -0
- package/assets/esri/core/workers/chunks/{140f2eeb11e39ab15734.js → aa36c3a9bbaa086e3757.js} +1 -1
- package/assets/esri/core/workers/chunks/ae31fd416bbb41a81392.js +1 -0
- package/assets/esri/core/workers/chunks/b49df4ebd4be1181b0f9.js +2 -0
- package/assets/esri/core/workers/chunks/{68d8ae42ab71d01a70a5.js → b557824bc1fa163d72a3.js} +2 -2
- package/assets/esri/core/workers/chunks/bc915fb182d463d804e6.js +1 -0
- package/assets/esri/core/workers/chunks/{992f102992c2bed7b34e.js → d5d0fe8e198ff5a902ee.js} +1 -1
- package/assets/esri/core/workers/chunks/e2190361247f35b02b32.js +1 -0
- package/assets/esri/core/workers/chunks/e2f42aec02bff33b25dd.js +1 -0
- package/assets/esri/core/workers/chunks/ebc1a2ef3aed8aa29424.js +1 -0
- package/assets/esri/core/workers/chunks/ed6e9d7f71bfd2691717.js +1 -0
- package/assets/esri/core/workers/chunks/ed8786fed345718ed684.js +1 -0
- package/assets/esri/core/workers/chunks/ee6679ef9efa1504e7eb.js +1 -0
- package/assets/esri/libs/lyr3d/lyr3DMain.wasm +0 -0
- package/assets/esri/libs/lyr3d/lyr3DWorker.wasm +0 -0
- package/assets/esri/libs/pdfjs/wasm/openjpeg_nowasm_fallback.js +1 -0
- package/chunks/BlendWeights.glsl.js +10 -10
- package/chunks/Blur.glsl.js +2 -2
- package/chunks/EdgeDetect.glsl.js +24 -19
- package/chunks/HUDMaterial.glsl.js +11 -1
- package/chunks/HighlightApply.glsl.js +4 -5
- package/chunks/HighlightBlur.glsl.js +5 -5
- package/chunks/HighlightDownsample.glsl.js +2 -2
- package/chunks/HighlightSharpApply.glsl.js +61 -0
- package/chunks/lyr3DMain.js +1 -1
- package/chunks/lyr3DWorker.js +2 -2
- package/chunks/portal.js +1 -1
- package/config.js +1 -1
- package/core/ObjectPool.js +1 -1
- package/core/PooledArray.js +1 -1
- package/core/accessorSupport/tracking/SimpleTrackingTarget.js +1 -1
- package/geometry/support/buffer/BufferPool.js +1 -1
- package/geometry/support/coordsUtils.js +1 -1
- package/geometry/support/curves/ellipticArc7Utils.js +1 -1
- package/geometry/support/curves/mathUtils.js +1 -1
- package/geometry/support/meshUtils.d.ts +5 -6
- package/interfaces.d.ts +18 -9
- package/kernel.js +1 -1
- package/layers/GeospatialPDFLayer.d.ts +154 -4
- package/layers/Layer.d.ts +2 -0
- package/layers/geospatialPDF/GeospatialPDFLayerWorker.js +1 -1
- package/layers/geospatialPDF/ViewportMeasureFrame.js +1 -1
- package/layers/geospatialPDF/geospatialPDFParserUtils.js +1 -1
- package/layers/geospatialPDF/projectionToWKTUtils.js +2 -2
- package/layers/graphics/controllers/FeatureTileController3D.js +1 -1
- package/layers/graphics/sources/GeoJSONSource.js +1 -1
- package/layers/graphics/sources/geojson/GeoJSONSourceWorker.js +1 -1
- package/layers/graphics/sources/support/MemorySourceWorker.js +1 -1
- package/layers/graphics/sources/support/clientSideDefaults.js +1 -1
- package/layers/graphics/sources/support/sourceUtils.js +1 -1
- package/layers/raster/datasets/TIFFRaster.js +1 -1
- package/layers/raster/datasets/pixelReader.js +1 -1
- package/layers/raster/functions/clipUtils.js +1 -1
- package/layers/support/LabelClass.d.ts +3 -2
- package/layers/support/PortalItemData.d.ts +31 -8
- package/layers/support/fieldUtils.js +1 -1
- package/layers/support/types.d.ts +4 -1
- package/package.json +2 -2
- package/portal/schemas/definitions.js +1 -1
- package/rest/knowledgeGraph/ObjectValue.js +1 -1
- package/symbols/cim/cimAnalyzer.js +1 -1
- package/views/2d/engine/webgl/GlyphWorker.js +1 -1
- package/views/2d/layers/features/schema/processor/symbols/ComplexSymbolSchema.js +1 -1
- package/views/3d/analysis/DirectLineMeasurementAnalysisView3D.js +1 -1
- package/views/3d/analysis/LineOfSight/LineOfSightItemTool.js +1 -1
- package/views/3d/analysis/LineOfSight/LineOfSightObserverPlugin.js +1 -1
- package/views/3d/analysis/LineOfSight/LineOfSightPlacementController.js +1 -1
- package/views/3d/analysis/LineOfSight/{LineOfSightRootPlugin.js → LineOfSightPlacementRootPlugin.js} +1 -1
- package/views/3d/analysis/LineOfSight/LineOfSightTargetPlugin.js +1 -1
- package/views/3d/analysis/LineOfSight/LineOfSightTool.js +1 -1
- package/views/3d/analysis/Viewshed/ViewshedPlacementPointPlugin.js +1 -1
- package/views/3d/analysis/Viewshed/ViewshedSubTool.js +1 -1
- package/views/3d/analysis/Viewshed/ViewshedTool.js +1 -1
- package/views/3d/interactive/editingTools/ManipulatedObject3DGraphic.js +1 -1
- package/views/3d/support/MemoryController.js +1 -1
- package/views/3d/terrain/TerrainData.js +1 -1
- package/views/3d/terrain/terrainUtils.js +1 -1
- package/views/3d/webgl-engine/core/shaderLibrary/HighlightCellGridScreenSpacePass.glsl.js +20 -6
- package/views/3d/webgl-engine/effects/RenderPluginManager.js +1 -1
- package/views/3d/webgl-engine/effects/geometry/RenderOccluded.js +1 -1
- package/views/3d/webgl-engine/effects/highlight/Highlight.js +1 -1
- package/views/3d/webgl-engine/effects/highlight/HighlightApply.glsl.js +1 -1
- package/views/3d/webgl-engine/effects/highlight/HighlightCellGridScreenSpacePassParameters.js +2 -0
- package/views/3d/webgl-engine/effects/highlight/HighlightDownsample.glsl.js +1 -1
- package/views/3d/webgl-engine/effects/highlight/HighlightPassParameters.js +1 -1
- package/views/3d/webgl-engine/effects/highlight/HighlightSharpApply.glsl.js +2 -0
- package/views/3d/webgl-engine/effects/highlight/HighlightSharpApplyTechnique.js +2 -0
- package/views/3d/webgl-engine/effects/smaa/BlendWeights.glsl.js +1 -1
- package/views/3d/webgl-engine/effects/smaa/Blur.glsl.js +1 -1
- package/views/3d/webgl-engine/effects/smaa/EdgeDetect.glsl.js +1 -1
- package/views/3d/webgl-engine/effects/smaa/SMAA.js +1 -1
- package/views/3d/webgl-engine/effects/smaa/SMAABlendWeightsTechnique.js +1 -1
- package/views/3d/webgl-engine/effects/smaa/SMAABlurTechnique.js +1 -1
- package/views/3d/webgl-engine/effects/smaa/SMAAEdgeDetectTechnique.js +1 -1
- package/views/3d/webgl-engine/effects/smaa/SMAAPassParameters.js +1 -1
- package/views/3d/webgl-engine/effects/smaa/SMAATechniqueConfiguration.js +2 -0
- package/views/3d/webgl-engine/lib/Compositor.js +1 -1
- package/views/3d/webgl-engine/lib/PathBuilder.js +1 -1
- package/views/3d/webgl-engine/lib/PathCapBuilder.js +1 -1
- package/views/3d/webgl-engine/lib/PathEvaluator.js +1 -1
- package/views/3d/webgl-engine/lib/PathExtruder.js +1 -1
- package/views/3d/webgl-engine/lib/PathProfile.js +1 -1
- package/views/3d/webgl-engine/lib/RenderFeature.js +1 -1
- package/views/3d/webgl-engine/lib/pathGeometryUtils.js +1 -1
- package/views/3d/webgl-engine/parts/RenderView.js +1 -1
- package/views/draw/DrawTool.js +1 -1
- package/views/draw/plugins/MultipointPlugin.js +1 -1
- package/views/draw/support/PluginContext.js +1 -1
- package/views/draw/support/managers/TooltipManager.js +1 -1
- package/views/draw/support/types.d.ts +5 -2
- package/views/support/HighlightDefaults.js +1 -1
- package/webdoc/applicationProperties/SearchLayerField.d.ts +7 -1
- package/webdoc/applicationProperties/SearchLayerField.js +1 -1
- package/webdoc/applicationProperties/SearchTableField.d.ts +7 -1
- package/webdoc/applicationProperties/SearchTableField.js +1 -1
- package/webdoc/applicationProperties/searchMode.js +2 -0
- package/widgets/BatchAttributeForm/batchAttributeFormUtils.js +1 -1
- package/widgets/BatchAttributeForm/inputs/support/DynamicChoiceController.js +1 -1
- package/widgets/BatchAttributeForm/inputs/support/inputUtils.js +1 -1
- package/widgets/BatchAttributeForm.js +1 -1
- package/widgets/Editor/EditorViewModel.d.ts +10 -1
- package/widgets/Editor.d.ts +10 -1
- package/widgets/FeatureTable/FeatureTableViewModel.js +1 -1
- package/widgets/FeatureTable/support/FeatureStore.js +1 -1
- package/widgets/HistogramRangeSlider.d.ts +2 -2
- package/widgets/HistogramRangeSlider.js +1 -1
- package/widgets/Legend.d.ts +1 -0
- package/widgets/OrientedImageryViewer/services/DepthImageService.js +1 -1
- package/widgets/ScaleRangeSlider/ScaleRangeSliderViewModel.d.ts +5 -2
- package/widgets/ScaleRangeSlider/ScaleRangeSliderViewModel.js +1 -1
- package/widgets/ScaleRangeSlider.js +1 -1
- package/widgets/Search/LayerSearchSource.d.ts +23 -1
- package/widgets/Search/LayerSearchSource.js +1 -1
- package/widgets/Search/support/layerSearchUtils.js +1 -1
- package/widgets/Search/types.d.ts +7 -0
- package/widgets/ValuePicker/ValuePickerBaseComponent.d.ts +5 -1
- package/widgets/ValuePicker/ValuePickerCollection.d.ts +2 -0
- package/widgets/ValuePicker/ValuePickerCombobox.d.ts +7 -1
- package/widgets/ValuePicker/ValuePickerLabel.d.ts +7 -1
- package/widgets/ValuePicker/ValuePickerSlider.d.ts +2 -0
- package/widgets/ValuePicker/ValuePickerSliderVisibleElements.d.ts +5 -1
- package/widgets/ValuePicker/ValuePickerVisibleElements.d.ts +5 -1
- package/widgets/ValuePicker/types.d.ts +2 -0
- package/widgets/support/forms/formUtils.js +1 -1
- package/widgets/support/forms/types.d.ts +1 -1
- package/assets/esri/core/workers/chunks/037a8cc19debbaaa4e10.js +0 -1
- package/assets/esri/core/workers/chunks/0dc66b03ff55d0ea5a09.js +0 -1
- package/assets/esri/core/workers/chunks/175c268e64ccd01f8c25.js +0 -1
- package/assets/esri/core/workers/chunks/1c65ab9ed611c322ce27.js +0 -1
- package/assets/esri/core/workers/chunks/2a1ec30f9ad305763f81.js +0 -2
- package/assets/esri/core/workers/chunks/3df5500a85345577480a.js +0 -1
- package/assets/esri/core/workers/chunks/3f7d583b676b23b3fadb.js +0 -1
- package/assets/esri/core/workers/chunks/408e81c8f1eff8a7b379.js +0 -1
- package/assets/esri/core/workers/chunks/4503b20ca6a80fb63d72.js +0 -1
- package/assets/esri/core/workers/chunks/4a640548032355e57acd.js +0 -1
- package/assets/esri/core/workers/chunks/53be85d04cd2da4f391d.js +0 -1
- package/assets/esri/core/workers/chunks/566e129f3d3805d7370a.js +0 -1
- package/assets/esri/core/workers/chunks/567a65f4203f6e81f4b4.js +0 -1
- package/assets/esri/core/workers/chunks/5982c6a8459c1237b298.js +0 -1
- package/assets/esri/core/workers/chunks/5eae5c29149f2429fe96.js +0 -1
- package/assets/esri/core/workers/chunks/6dc86e7496157c5e4d2c.js +0 -1
- package/assets/esri/core/workers/chunks/74b5c00f93cfc0d59029.js +0 -1
- package/assets/esri/core/workers/chunks/7c2c8f786a30267a5f05.js +0 -1
- package/assets/esri/core/workers/chunks/88e54449261ef94e390d.js +0 -1
- package/assets/esri/core/workers/chunks/9e142551163acf752618.js +0 -1
- package/assets/esri/core/workers/chunks/af75747b06d79446a855.js +0 -1
- package/assets/esri/core/workers/chunks/dba280c370df13196711.js +0 -1
- package/assets/esri/core/workers/chunks/dc486a3595b6d57018bb.js +0 -1
- package/assets/esri/core/workers/chunks/e3c1c9e6c62ba5cbcdb8.js +0 -1
- package/assets/esri/core/workers/chunks/f1f90adae13b04898008.js +0 -1
- package/assets/esri/core/workers/chunks/f47c7065da3b5001245f.js +0 -1
- /package/assets/esri/core/workers/chunks/{1b946714ca4a1a7359d4.js.LICENSE.txt → 34cbaf844730ac2d92c2.js.LICENSE.txt} +0 -0
- /package/assets/esri/core/workers/chunks/{96c50a0dda0f1503ef92.js.LICENSE.txt → 3c301a689c7853c9fa67.js.LICENSE.txt} +0 -0
- /package/assets/esri/core/workers/chunks/{8dc1c3042267618fd710.js.LICENSE.txt → 76ab353d80d786777161.js.LICENSE.txt} +0 -0
- /package/assets/esri/core/workers/chunks/{2a1ec30f9ad305763f81.js.LICENSE.txt → b49df4ebd4be1181b0f9.js.LICENSE.txt} +0 -0
- /package/assets/esri/core/workers/chunks/{68d8ae42ab71d01a70a5.js.LICENSE.txt → b557824bc1fa163d72a3.js.LICENSE.txt} +0 -0
- /package/views/3d/analysis/LineOfSight/{lineOfSightPlacementUtils.js → placementUtils.js} +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type Extent from "../geometry/Extent.js";
|
|
1
2
|
import type SpatialReference from "../geometry/SpatialReference.js";
|
|
2
3
|
import type Layer from "./Layer.js";
|
|
3
4
|
import type TileInfo from "./support/TileInfo.js";
|
|
@@ -7,21 +8,170 @@ import type { ScaleRangeLayer, ScaleRangeLayerProperties } from "./mixins/ScaleR
|
|
|
7
8
|
import type { GeospatialPDFDataUnion } from "./support/types.js";
|
|
8
9
|
import type { LayerProperties } from "./Layer.js";
|
|
9
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Properties used to construct a [GeospatialPDFLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/GeospatialPDFLayer/).
|
|
13
|
+
*
|
|
14
|
+
* @since 5.2
|
|
15
|
+
*/
|
|
10
16
|
export interface GeospatialPDFLayerProperties extends LayerProperties, ScaleRangeLayerProperties, BlendLayerProperties, Partial<Pick<GeospatialPDFLayer, "clippedToNeatline" | "data">> {}
|
|
11
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Displays a geospatial PDF document as georeferenced raster imagery.
|
|
20
|
+
* A geospatial PDF contains information that relates locations on a PDF page to real-world coordinates.
|
|
21
|
+
* This allows a map distributed as a PDF, such as a topographic map, to be displayed alongside other geographic data
|
|
22
|
+
* without manually specifying its location.
|
|
23
|
+
*
|
|
24
|
+
* To create a GeospatialPDFLayer, set the [data](https://developers.arcgis.com/javascript/latest/references/core/layers/GeospatialPDFLayer/#data) property to a PDF URL, a browser [File](https://developer.mozilla.org/en-US/docs/Web/API/File), or a [PortalItemData](https://developers.arcgis.com/javascript/latest/references/core/layers/support/PortalItemData/).
|
|
25
|
+
* Remote PDF URLs must be accessible to the application and comply with the browser's [cross-origin request restrictions](https://developers.arcgis.com/javascript/latest/cors/).
|
|
26
|
+
* The document is downloaded and rendered on the client; publishing an image service is not required.
|
|
27
|
+
* The first page of the PDF is used for georeferencing and rendering.
|
|
28
|
+
* The entire document is downloaded before rendering; large or complex PDFs can increase load time and memory usage.
|
|
29
|
+
* The layer derives its [spatial reference](https://developers.arcgis.com/javascript/latest/references/core/layers/GeospatialPDFLayer/#spatialReference) and
|
|
30
|
+
* [extent](https://developers.arcgis.com/javascript/latest/references/core/layers/GeospatialPDFLayer/#fullExtent) from the embedded georeferencing information.
|
|
31
|
+
* The rendered imagery can be reprojected to the spatial reference of the view. In an scene, it is draped on the ground.
|
|
32
|
+
*
|
|
33
|
+
* Additionally the PDF defines the boundary of the georeferenced map within the page, called a *neatline*.
|
|
34
|
+
* Set [clippedToNeatline](https://developers.arcgis.com/javascript/latest/references/core/layers/GeospatialPDFLayer/#clippedToNeatline) to `true` to hide content outside this boundary, such as page margins, legends, and titles.
|
|
35
|
+
*
|
|
36
|
+
* The [arcgis-print](https://developers.arcgis.com/javascript/latest/references/map-components/components/arcgis-print/) component can generate geospatial PDFs.
|
|
37
|
+
* When creating PDFs in ArcGIS Pro, enable "Export georeference information".
|
|
38
|
+
* Merely exporting a map to PDF does not guarantee that the resulting document contains georeferencing.
|
|
39
|
+
* See [Export to PDF](https://pro.arcgis.com/en/pro-app/latest/help/sharing/overview/pdf-export.htm) for export settings.
|
|
40
|
+
*
|
|
41
|
+
* > [!WARNING]
|
|
42
|
+
* >
|
|
43
|
+
* > **Known Limitations**
|
|
44
|
+
* >
|
|
45
|
+
* > - Documents that require a password to open are not supported.
|
|
46
|
+
* > - Tile reprojection is limited: grid-based transformations are not supported. As a result, the layer may still display but appear shifted. See the [project operator's known limitations](https://developers.arcgis.com/javascript/latest/references/core/geometry/operators/projectOperator/).
|
|
47
|
+
* > - To decode certain image types from PDF files, GeospatialPDFLayer is using WebAssembly features not available yet in Safari. As a result it uses a slower JavaScript fallback which impact the initial load of the layer.
|
|
48
|
+
* > - Not supported by the [Legend](https://developers.arcgis.com/javascript/latest/references/map-components/components/arcgis-legend/).
|
|
49
|
+
*
|
|
50
|
+
* @beta
|
|
51
|
+
* @since 5.2
|
|
52
|
+
* @see [PortalItemData](https://developers.arcgis.com/javascript/latest/references/core/layers/support/PortalItemData/)
|
|
53
|
+
* @see [GeospatialPDFDataUnion](https://developers.arcgis.com/javascript/latest/references/core/layers/support/types/#GeospatialPDFDataUnion)
|
|
54
|
+
* @see [GeospatialPDFLayer with a local file](https://developers.arcgis.com/javascript/latest/sample-code/layers-geospatialpdf/) sample
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import GeospatialPDFLayer from "@arcgis/core/layers/GeospatialPDFLayer.js";
|
|
58
|
+
*
|
|
59
|
+
* // Replace this URL with a georeferenced PDF.
|
|
60
|
+
* const layer = new GeospatialPDFLayer({
|
|
61
|
+
* data: "https://jsapi.maps.arcgis.com/sharing/rest/content/items/0d8613492b1e4598a5edb111f05be7fd/data",
|
|
62
|
+
* clippedToNeatline: true
|
|
63
|
+
* });
|
|
64
|
+
* // viewElement is an existing arcgis-map or arcgis-scene component.
|
|
65
|
+
* await viewElement.viewOnReady();
|
|
66
|
+
* viewElement.map.add(layer);
|
|
67
|
+
* ```
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* import GeospatialPDFLayer from "@arcgis/core/layers/GeospatialPDFLayer.js";
|
|
71
|
+
* import PortalItemData from "@arcgis/core/layers/support/PortalItemData.js";
|
|
72
|
+
*
|
|
73
|
+
* const layer = new GeospatialPDFLayer({
|
|
74
|
+
* data: new PortalItemData({
|
|
75
|
+
* portalItem: {
|
|
76
|
+
* id: "0d8613492b1e4598a5edb111f05be7fd"
|
|
77
|
+
* }
|
|
78
|
+
* })
|
|
79
|
+
* });
|
|
80
|
+
* // viewElement is an existing arcgis-map or arcgis-scene component.
|
|
81
|
+
* await viewElement.viewOnReady();
|
|
82
|
+
* viewElement.map.add(layer);
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
12
85
|
export default class GeospatialPDFLayer extends GeospatialPDFLayerSuperclass {
|
|
13
86
|
constructor(properties?: GeospatialPDFLayerProperties);
|
|
14
87
|
/**
|
|
15
|
-
*
|
|
88
|
+
* Indicates whether to hide PDF content outside the georeferenced map's neatline.
|
|
89
|
+
* A neatline is the boundary of the map within the PDF page. When `true`, content outside that boundary
|
|
90
|
+
* is masked out. When `false`, the entire page is displayed, including margins and other layout elements.
|
|
16
91
|
*
|
|
17
92
|
* @default false
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* layer.clippedToNeatline = true;
|
|
96
|
+
* ```
|
|
18
97
|
*/
|
|
19
98
|
accessor clippedToNeatline: boolean;
|
|
20
|
-
/**
|
|
99
|
+
/**
|
|
100
|
+
* The data source of the `GeospatialPDFLayer`.
|
|
101
|
+
*
|
|
102
|
+
* Specify one of the following before loading the layer:
|
|
103
|
+
* - A string containing the URL of a geospatial PDF.
|
|
104
|
+
* - A browser [File](https://developer.mozilla.org/en-US/docs/Web/API/File), for example from a file input.
|
|
105
|
+
* - A [PortalItemData](https://developers.arcgis.com/javascript/latest/references/core/layers/support/PortalItemData/) instance referencing a portal item whose
|
|
106
|
+
* [url](https://developers.arcgis.com/javascript/latest/references/core/portal/PortalItem/#url) resolves to a geospatial PDF.
|
|
107
|
+
*
|
|
108
|
+
* @see [GeospatialPDFDataUnion](https://developers.arcgis.com/javascript/latest/references/core/layers/support/types/#GeospatialPDFDataUnion)
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* import GeospatialPDFLayer from "@arcgis/core/layers/GeospatialPDFLayer.js";
|
|
112
|
+
*
|
|
113
|
+
* // Replace this URL with an accessible georeferenced PDF.
|
|
114
|
+
* const layer = new GeospatialPDFLayer({
|
|
115
|
+
* data: "https://jsapi.maps.arcgis.com/sharing/rest/content/items/0d8613492b1e4598a5edb111f05be7fd/data",
|
|
116
|
+
* clippedToNeatline: true
|
|
117
|
+
* });
|
|
118
|
+
* // viewElement is an existing arcgis-map or arcgis-scene component.
|
|
119
|
+
* await viewElement.viewOnReady();
|
|
120
|
+
* viewElement.map.add(layer);
|
|
121
|
+
* ```
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* import GeospatialPDFLayer from "@arcgis/core/layers/GeospatialPDFLayer.js";
|
|
125
|
+
* import PortalItemData from "@arcgis/core/layers/support/PortalItemData.js";
|
|
126
|
+
*
|
|
127
|
+
* const layer = new GeospatialPDFLayer({
|
|
128
|
+
* data: new PortalItemData({
|
|
129
|
+
* portalItem: {
|
|
130
|
+
* id: "0d8613492b1e4598a5edb111f05be7fd"
|
|
131
|
+
* }
|
|
132
|
+
* }),
|
|
133
|
+
* clippedToNeatline: true
|
|
134
|
+
* });
|
|
135
|
+
* // viewElement is an existing arcgis-map or arcgis-scene component.
|
|
136
|
+
* await viewElement.viewOnReady();
|
|
137
|
+
* viewElement.map.add(layer);
|
|
138
|
+
* ```
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* import GeospatialPDFLayer from "@arcgis/core/layers/GeospatialPDFLayer.js";
|
|
142
|
+
*
|
|
143
|
+
* // file is a File obtained from a file input or drag-and-drop.
|
|
144
|
+
* const layer = new GeospatialPDFLayer({
|
|
145
|
+
* data: file,
|
|
146
|
+
* clippedToNeatline: true
|
|
147
|
+
* });
|
|
148
|
+
* // viewElement is an existing arcgis-map or arcgis-scene component.
|
|
149
|
+
* await viewElement.viewOnReady();
|
|
150
|
+
* viewElement.map.add(layer);
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
21
153
|
accessor data: GeospatialPDFDataUnion | null | undefined;
|
|
22
|
-
/**
|
|
154
|
+
/**
|
|
155
|
+
* The full extent of the layer.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* await viewElement.viewOnReady();
|
|
160
|
+
* await layer.load();
|
|
161
|
+
* if (layer.fullExtent) {
|
|
162
|
+
* await viewElement.goTo(layer.fullExtent);
|
|
163
|
+
* }
|
|
164
|
+
* ```
|
|
165
|
+
* @example
|
|
166
|
+
* // Once the layer loads, set the view's extent to the layer's full extent
|
|
167
|
+
* layer.when(function(){
|
|
168
|
+
* view.extent = layer.fullExtent;
|
|
169
|
+
* });
|
|
170
|
+
*/
|
|
171
|
+
get fullExtent(): Extent | null | undefined;
|
|
172
|
+
/** The spatial reference of the layer derived from the georeferencing information found in the PDF. */
|
|
23
173
|
get spatialReference(): SpatialReference;
|
|
24
|
-
/**
|
|
174
|
+
/** Contains information about the tiling scheme for the layer used to render the PDF as raster tiles. */
|
|
25
175
|
get tileInfo(): TileInfo | null | undefined;
|
|
26
176
|
/** The layer type provides a convenient way to check the type of the layer without the need to import specific layer modules. */
|
|
27
177
|
get type(): "geospatial-pdf";
|
package/layers/Layer.d.ts
CHANGED
|
@@ -142,6 +142,7 @@ export interface FromArcGISServerUrlParameters {
|
|
|
142
142
|
* [WMTSLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/WMTSLayer/) | WMTS tile services, ArcGIS portal item | Image tiles | OGC specification | N/A
|
|
143
143
|
* [WebTileLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/WebTileLayer/) | non-ArcGIS, non-OGC, and non-OSM tile services | Image tiles | N/A | No editing, client-side rendering, or popup templates.
|
|
144
144
|
* [BingMapsLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/BingMapsLayer/) | Bing Spatial Data Service data | Image tiles | Displays Microsoft's Bing tiled content | Bing Maps key is required; three map styles are supported: `road`, `aerial`, and `hybrid`
|
|
145
|
+
* [GeospatialPDFLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/GeospatialPDFLayer/) | PDF File, ArcGIS portal item | PDF documents | Displays a geospatial PDF document as georeferenced raster imagery | Documents that require a password to open are not supported
|
|
145
146
|
* [MediaLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/MediaLayer/) | HTMLVideoElement, HTMLImageElement, or HTMLCanvasElement | Image/video element | Displays image and video elements in the map at specified geographic locations | GIF/APNG not currently
|
|
146
147
|
* [VideoLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/VideoLayer/) | ArcGIS VideoServer, ArcGIS portal item | Video | Displays a georeferenced video in the map | No 3D support
|
|
147
148
|
*
|
|
@@ -263,6 +264,7 @@ export default abstract class Layer extends LayerSuperclass {
|
|
|
263
264
|
* > **Known Limitations**
|
|
264
265
|
* >
|
|
265
266
|
* > - This method does not currently work with [OGCFeatureServer portal items](https://developers.arcgis.com/rest/users-groups-and-items/items-and-item-types/#layers).
|
|
267
|
+
* > - This method does not currently work with [GeospatialPDFLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/GeospatialPDFLayer/)
|
|
266
268
|
*
|
|
267
269
|
* @param params - The parameters for loading the portal item.
|
|
268
270
|
* @returns Returns a promise which resolves to the new layer instance.
|
|
@@ -54,4 +54,4 @@ this.workerSrc)).WorkerMessageHandler})())}}class er{downloadInfoCapability=Prom
|
|
|
54
54
|
`)}`;this.#l();let u=new Range,d=Math.sumPrecise(c.map(e=>e.length));for(let{firstChild:e}of this.editorDiv.childNodes)if(e.nodeType===Node.TEXT_NODE){let t=e.nodeValue.length;if(d<=t){u.setStart(e,d);u.setEnd(e,d);break}d-=t}i.removeAllRanges();i.addRange(u)}#l(){this.editorDiv.replaceChildren();if(this.#e)for(let e of this.#e.split(`
|
|
55
55
|
`)){let t=document.createElement(`div`);t.append(e?document.createTextNode(e):document.createElement(`br`));this.editorDiv.append(t)}}#u(){return this.#e.replaceAll(`\xA0`,` `)}static#d(e){return e.replaceAll(` `,`\xA0`)}get contentDiv(){return this.editorDiv}getPDFRect(){let e=X._internalPadding*this.parentScale;return this.getRect(e,e)}static async deserialize(e,t,n){let r=null;if(e instanceof pr){let{data:{defaultAppearanceData:{fontSize:t,fontColor:n},rect:i,rotation:a,id:o,popupRef:s,richText:c,contentsObj:l,creationDate:u,modificationDate:d},textContent:f,textPosition:p,parent:{page:{pageNumber:m}}}=e;if(!f||f.length===0)return null;r=e={annotationType:y.FREETEXT,color:Array.from(n),fontSize:t,value:f.join(`
|
|
56
56
|
`),position:p,pageIndex:m-1,rect:i.slice(0),rotation:a,annotationElementId:o,id:o,deleted:!1,popupRef:s,comment:l?.str||null,richText:c,creationDate:u,modificationDate:d}}let i=await super.deserialize(e,t,n);i.#r=e.fontSize;i.color=P.makeHexColor(...e.color);i.#e=X.#d(e.value);i._initialData=r;e.comment&&i.setCommentData(e);return i}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let t=V._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:this.color),n=Object.assign(super.serialize(e),{color:t,fontSize:this.#r,value:this.#u()});this.addComment(n);if(e){n.isCopy=!0;return n}if(this.annotationElementId&&!this.#f(n))return null;n.id=this.annotationElementId;return n}#f(e){let{value:t,fontSize:n,color:r,pageIndex:i}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||e.value!==t||e.fontSize!==n||e.color.some((e,t)=>e!==r[t])||e.pageIndex!==i}renderAnnotationElement(e){let t=super.renderAnnotationElement(e);if(!t)return null;let{style:n}=t;n.fontSize=`calc(${this.#r}px * var(--total-scale-factor))`;n.color=this.color;t.replaceChildren();for(let e of this.#e.split(`
|
|
57
|
-
`)){let n=document.createElement(`div`);n.append(e?document.createTextNode(e):document.createElement(`br`));t.append(n)}e.updateEdited({rect:this.getPDFRect(),popup:this._uiManager.hasCommentManager()||this.hasEditedComment?this.comment:{text:this.#e}});return t}resetAnnotationElement(e){super.resetAnnotationElement(e);e.resetEdited()}}class Z{static PRECISION=1e-4;toSVGPath(){k("Abstract method `toSVGPath` must be implemented.")}get box(){k("Abstract getter `box` must be implemented.")}serialize(e,t){k("Abstract method `serialize` must be implemented.")}static _rescale(e,t,n,r,i,a){a||=new Float32Array(e.length);for(let o=0,s=e.length;o<s;o+=2){a[o]=t+e[o]*r;a[o+1]=n+e[o+1]*i}return a}static _rescaleAndSwap(e,t,n,r,i,a){a||=new Float32Array(e.length);for(let o=0,s=e.length;o<s;o+=2){a[o]=t+e[o+1]*r;a[o+1]=n+e[o]*i}return a}static _translate(e,t,n,r){r||=new Float32Array(e.length);for(let i=0,a=e.length;i<a;i+=2){r[i]=t+e[i];r[i+1]=n+e[i+1]}return r}static svgRound(e){return Math.round(1e4*e)}static _normalizePoint(e,t,n,r,i){switch(i){case 90:return[1-t/n,e/r];case 180:return[1-e/n,1-t/r];case 270:return[t/n,1-e/r];default:return[e/n,t/r]}}static _normalizePagePoint(e,t,n){switch(n){case 90:return[1-t,e];case 180:return[1-e,1-t];case 270:return[t,1-e];default:return[e,t]}}static createBezierPoints(e,t,n,r,i,a){return[(e+5*n)/6,(t+5*r)/6,(5*n+i)/6,(5*r+a)/6,(n+i)/2,(r+a)/2]}}class vr{#e;#t=[];#n;#r;#i=[];#a=new Float32Array(18);#o;#s;#c;#l;#u;#d;#f=[];static#p=8;static#m=2;static#h=vr.#p+vr.#m;constructor({x:e,y:t},n,r,i,a,o=0){this.#e=n;this.#d=i*r;this.#r=a;this.#a.set([NaN,NaN,NaN,NaN,e,t],6);this.#n=o;this.#l=vr.#p*r;this.#c=vr.#h*r;this.#u=r;this.#f.push(e,t)}isEmpty(){return isNaN(this.#a[8])}#g(){let e=this.#a.subarray(4,6),t=this.#a.subarray(16,18),[n,r,i,a]=this.#e;return[(this.#o+(e[0]-t[0])/2-n)/i,(this.#s+(e[1]-t[1])/2-r)/a,(this.#o+(t[0]-e[0])/2-n)/i,(this.#s+(t[1]-e[1])/2-r)/a]}add({x:e,y:t}){this.#o=e;this.#s=t;let[n,r,i,a]=this.#e,[o,s,c,l]=this.#a.subarray(8,12),u=e-c,d=t-l,f=Math.hypot(u,d);if(f<this.#c)return!1;let p=f-this.#l,m=p/f,h=m*u,g=m*d,_=o,v=s;o=c;s=l;c+=h;l+=g;this.#f?.push(e,t);let y=h/p,b=-g/p*this.#d,x=y*this.#d;this.#a.set(this.#a.subarray(2,8),0);this.#a.set([c+b,l+x],4);this.#a.set(this.#a.subarray(14,18),12);this.#a.set([c-b,l-x],16);if(isNaN(this.#a[6])){if(this.#i.length===0){this.#a.set([o+b,s+x],2);this.#i.push(NaN,NaN,NaN,NaN,(o+b-n)/i,(s+x-r)/a);this.#a.set([o-b,s-x],14);this.#t.push(NaN,NaN,NaN,NaN,(o-b-n)/i,(s-x-r)/a)}this.#a.set([_,v,o,s,c,l],6);return!this.isEmpty()}this.#a.set([_,v,o,s,c,l],6);if(Math.abs(Math.atan2(v-s,_-o)-Math.atan2(g,h))<Math.PI/2){[o,s,c,l]=this.#a.subarray(2,6);this.#i.push(NaN,NaN,NaN,NaN,((o+c)/2-n)/i,((s+l)/2-r)/a);[o,s,_,v]=this.#a.subarray(14,18);this.#t.push(NaN,NaN,NaN,NaN,((_+o)/2-n)/i,((v+s)/2-r)/a);return!0}[_,v,o,s,c,l]=this.#a.subarray(0,6);this.#i.push(((_+5*o)/6-n)/i,((v+5*s)/6-r)/a,((5*o+c)/6-n)/i,((5*s+l)/6-r)/a,((o+c)/2-n)/i,((s+l)/2-r)/a);[c,l,o,s,_,v]=this.#a.subarray(12,18);this.#t.push(((_+5*o)/6-n)/i,((v+5*s)/6-r)/a,((5*o+c)/6-n)/i,((5*s+l)/6-r)/a,((o+c)/2-n)/i,((s+l)/2-r)/a);return!0}toSVGPath(){if(this.isEmpty())return``;let e=this.#i,t=this.#t;if(isNaN(this.#a[6])&&!this.isEmpty())return this.#_();let n=[];n.push(`M${e[4]} ${e[5]}`);for(let t=6;t<e.length;t+=6)isNaN(e[t])?n.push(`L${e[t+4]} ${e[t+5]}`):n.push(`C${e[t]} ${e[t+1]} ${e[t+2]} ${e[t+3]} ${e[t+4]} ${e[t+5]}`);this.#y(n);for(let e=t.length-6;e>=6;e-=6)isNaN(t[e])?n.push(`L${t[e+4]} ${t[e+5]}`):n.push(`C${t[e]} ${t[e+1]} ${t[e+2]} ${t[e+3]} ${t[e+4]} ${t[e+5]}`);this.#v(n);return n.join(` `)}#_(){let[e,t,n,r]=this.#e,[i,a,o,s]=this.#g();return`M${(this.#a[2]-e)/n} ${(this.#a[3]-t)/r} L${(this.#a[4]-e)/n} ${(this.#a[5]-t)/r} L${i} ${a} L${o} ${s} L${(this.#a[16]-e)/n} ${(this.#a[17]-t)/r} L${(this.#a[14]-e)/n} ${(this.#a[15]-t)/r} Z`}#v(e){let t=this.#t;e.push(`L${t[4]} ${t[5]} Z`)}#y(e){let[t,n,r,i]=this.#e,a=this.#a.subarray(4,6),o=this.#a.subarray(16,18),[s,c,l,u]=this.#g();e.push(`L${(a[0]-t)/r} ${(a[1]-n)/i} L${s} ${c} L${l} ${u} L${(o[0]-t)/r} ${(o[1]-n)/i}`)}newFreeDrawOutline(e,t,n,r,i,a){return new yr(e,t,n,r,i,a)}getOutlines(){let e=this.#i,t=this.#t,n=this.#a,[r,i,a,o]=this.#e,s=new Float32Array((this.#f?.length??0)+2);for(let e=0,t=s.length-2;e<t;e+=2){s[e]=(this.#f[e]-r)/a;s[e+1]=(this.#f[e+1]-i)/o}s[s.length-2]=(this.#o-r)/a;s[s.length-1]=(this.#s-i)/o;if(isNaN(n[6])&&!this.isEmpty())return this.#b(s);let c=new Float32Array(this.#i.length+24+this.#t.length),l=e.length;for(let t=0;t<l;t+=2)if(isNaN(e[t]))c[t]=c[t+1]=NaN;else{c[t]=e[t];c[t+1]=e[t+1]}l=this.#S(c,l);for(let e=t.length-6;e>=6;e-=6)for(let n=0;n<6;n+=2)if(isNaN(t[e+n])){c[l]=c[l+1]=NaN;l+=2}else{c[l]=t[e+n];c[l+1]=t[e+n+1];l+=2}this.#x(c,l);return this.newFreeDrawOutline(c,s,this.#e,this.#u,this.#n,this.#r)}#b(e){let t=this.#a,[n,r,i,a]=this.#e,[o,s,c,l]=this.#g(),u=new Float32Array(36);u.set([NaN,NaN,NaN,NaN,(t[2]-n)/i,(t[3]-r)/a,NaN,NaN,NaN,NaN,(t[4]-n)/i,(t[5]-r)/a,NaN,NaN,NaN,NaN,o,s,NaN,NaN,NaN,NaN,c,l,NaN,NaN,NaN,NaN,(t[16]-n)/i,(t[17]-r)/a,NaN,NaN,NaN,NaN,(t[14]-n)/i,(t[15]-r)/a],0);return this.newFreeDrawOutline(u,e,this.#e,this.#u,this.#n,this.#r)}#x(e,t){let n=this.#t;e.set([NaN,NaN,NaN,NaN,n[4],n[5]],t);return t+6}#S(e,t){let n=this.#a.subarray(4,6),r=this.#a.subarray(16,18),[i,a,o,s]=this.#e,[c,l,u,d]=this.#g();e.set([NaN,NaN,NaN,NaN,(n[0]-i)/o,(n[1]-a)/s,NaN,NaN,NaN,NaN,c,l,NaN,NaN,NaN,NaN,u,d,NaN,NaN,NaN,NaN,(r[0]-i)/o,(r[1]-a)/s],t);return t+24}}class yr extends Z{#e;#t=new Float32Array(4);#n;#r;#i;#a;#o;constructor(e,t,n,r,i,a){super();this.#o=e;this.#i=t;this.#e=n;this.#a=r;this.#n=i;this.#r=a;this.firstPoint=[NaN,NaN];this.lastPoint=[NaN,NaN];this.#s(a);let[o,s,c,l]=this.#t;for(let t=0,n=e.length;t<n;t+=2){e[t]=(e[t]-o)/c;e[t+1]=(e[t+1]-s)/l}for(let e=0,n=t.length;e<n;e+=2){t[e]=(t[e]-o)/c;t[e+1]=(t[e+1]-s)/l}}toSVGPath(){let e=[`M${this.#o[4]} ${this.#o[5]}`];for(let t=6,n=this.#o.length;t<n;t+=6)isNaN(this.#o[t])?e.push(`L${this.#o[t+4]} ${this.#o[t+5]}`):e.push(`C${this.#o[t]} ${this.#o[t+1]} ${this.#o[t+2]} ${this.#o[t+3]} ${this.#o[t+4]} ${this.#o[t+5]}`);e.push(`Z`);return e.join(` `)}serialize([e,t,n,r],i){let a=n-e,o=r-t,s,c;switch(i){case 0:s=Z._rescale(this.#o,e,r,a,-o);c=Z._rescale(this.#i,e,r,a,-o);break;case 90:s=Z._rescaleAndSwap(this.#o,e,t,a,o);c=Z._rescaleAndSwap(this.#i,e,t,a,o);break;case 180:s=Z._rescale(this.#o,n,t,-a,o);c=Z._rescale(this.#i,n,t,-a,o);break;case 270:s=Z._rescaleAndSwap(this.#o,n,r,-a,-o);c=Z._rescaleAndSwap(this.#i,n,r,-a,-o)}return{outline:Array.from(s),points:[Array.from(c)]}}#s(e){let t=this.#o,n=t[4],r=t[5],i=[n,r,n,r],a=n,o=r,s=n,c=r,l=e?Math.max:Math.min,u=new Float32Array(4);for(let e=6,d=t.length;e<d;e+=6){let d=t[e+4],p=t[e+5];if(isNaN(t[e])){P.pointBoundingBox(d,p,i);if(o>p){a=d;o=p}else o===p&&(a=l(a,d));if(c<p){s=d;c=p}else c===p&&(s=l(s,d))}else{u.set(f,0);P.bezierBoundingBox(n,r,...t.slice(e,e+6),u);P.rectBoundingBox(...u,i);if(o>u[1]){a=u[0];o=u[1]}else o===u[1]&&(a=l(a,u[0]));if(c<u[3]){s=u[2];c=u[3]}else c===u[3]&&(s=l(s,u[2]))}n=d;r=p}let d=this.#t;d[0]=i[0]-this.#n;d[1]=i[1]-this.#n;d[2]=i[2]-i[0]+2*this.#n;d[3]=i[3]-i[1]+2*this.#n;this.firstPoint=[a,o];this.lastPoint=[s,c]}get box(){return this.#t}newOutliner(e,t,n,r,i,a=0){return new vr(e,t,n,r,i,a)}getNewOutline(e,t){let[n,r,i,a]=this.#t,[o,s,c,l]=this.#e,u=i*c,d=a*l,f=n*c+o,p=r*l+s,m=this.newOutliner({x:this.#i[0]*u+f,y:this.#i[1]*d+p},this.#e,this.#a,e,this.#r,t??this.#n);for(let e=2;e<this.#i.length;e+=2)m.add({x:this.#i[e]*u+f,y:this.#i[e+1]*d+p});return m.getOutlines()}}class br{#e;#t;#n;#r=[];#i=[];constructor(e,t=0,n=0,r=!0){let i=f.slice(),a=1e-4;for(let{x:n,y:r,width:o,height:s}of e){let e=Math.floor((n-t)/a)*a,c=Math.ceil((n+o+t)/a)*a,l=Math.floor((r-t)/a)*a,u=Math.ceil((r+s+t)/a)*a,d=[e,l,u,!0],f=[c,l,u,!1];this.#r.push(d,f);P.rectBoundingBox(e,l,c,u,i)}let o=i[2]-i[0]+2*n,s=i[3]-i[1]+2*n,c=i[0]-n,l=i[1]-n,u=r?-1/0:1/0,d=1/0,p=this.#r.at(r?-1:-2),m=[p[0],p[2]];for(let e of this.#r){let[t,n,i,a]=e;if(!a&&r){if(n<d){d=n;u=t}else n===d&&(u=Math.max(u,t))}else if(a&&!r){if(n<d){d=n;u=t}else n===d&&(u=Math.min(u,t))}e[0]=(t-c)/o;e[1]=(n-l)/s;e[2]=(i-l)/s}this.#e=new Float32Array([c,l,o,s]);this.#t=[u,d];this.#n=m}getOutlines(){this.#r.sort((e,t)=>e[0]-t[0]||e[1]-t[1]||e[2]-t[2]);let e=[];for(let t of this.#r)if(t[3]){e.push(...this.#l(t));this.#s(t)}else{this.#c(t);e.push(...this.#l(t))}return this.#a(e)}#a(e){let t=[],n=new Set;for(let n of e){let[e,r,i]=n;t.push([e,r,n],[e,i,n])}t.sort((e,t)=>e[1]-t[1]||e[0]-t[0]);for(let e=0,r=t.length;e<r;e+=2){let r=t[e][2],i=t[e+1][2];r.push(i);i.push(r);n.add(r);n.add(i)}let r=[],i;for(;n.size>0;){let e=n.values().next().value,[t,a,o,s,c]=e;n.delete(e);let l=t,u=a;i=[t,o];r.push(i);for(;;){let e;if(n.has(s))e=s;else{if(!n.has(c))break;e=c}n.delete(e);[t,a,o,s,c]=e;if(l!==t){i.push(l,u,t,u===a?a:o);l=t}u=u===a?o:a}i.push(l,u)}return new xr(r,this.#e,this.#t,this.#n)}#o(e){let t=this.#i,n=0,r=t.length-1;for(;n<=r;){let i=n+r>>1,a=t[i][0];if(a===e)return i;a<e?n=i+1:r=i-1}return r+1}#s([,e,t]){let n=this.#o(e);this.#i.splice(n,0,[e,t])}#c([,e,t]){let n=this.#o(e);for(let r=n;r<this.#i.length;r++){let[n,i]=this.#i[r];if(n!==e)break;if(n===e&&i===t){this.#i.splice(r,1);return}}for(let r=n-1;r>=0;r--){let[n,i]=this.#i[r];if(n!==e)break;if(n===e&&i===t){this.#i.splice(r,1);return}}}#l(e){let[t,n,r]=e,i=[[t,n,r]],a=this.#o(r);for(let e=0;e<a;e++){let[n,r]=this.#i[e];for(let e=0,a=i.length;e<a;e++){let[,o,s]=i[e];if(!(r<=o||s<=n)){if(o>=n){if(s>r)i[e][1]=r;else{if(a===1)return[];i.splice(e,1);e--;a--}}else{i[e][2]=n;s>r&&i.push([t,r,s])}}}}return i}}class xr extends Z{#e;#t;constructor(e,t,n,r){super();this.#t=e;this.#e=t;this.firstPoint=n;this.lastPoint=r}toSVGPath(){let e=[];for(let t of this.#t){let[n,r]=t;e.push(`M${n} ${r}`);for(let i=2;i<t.length;i+=2){let a=t[i],o=t[i+1];if(a===n){e.push(`V${o}`);r=o}else if(o===r){e.push(`H${a}`);n=a}}e.push(`Z`)}return e.join(` `)}serialize([e,t,n,r],i){let a=[],o=n-e,s=r-t;for(let t of this.#t){let n=Array(t.length);for(let i=0;i<t.length;i+=2){n[i]=e+t[i]*o;n[i+1]=r-t[i+1]*s}a.push(n)}return a}get box(){return this.#e}get classNamesForOutlining(){return[`highlightOutline`]}}class Sr extends vr{newFreeDrawOutline(e,t,n,r,i,a){return new Cr(e,t,n,r,i,a)}}class Cr extends yr{newOutliner(e,t,n,r,i,a=0){return new Sr(e,t,n,r,i,a)}}class Q extends V{#e=null;#t=0;#n;#r=null;#i=null;#a=null;#o=null;#s=0;#c=null;#l=null;#u=null;#d=!1;#f=null;#p=null;#m=null;#h=``;#g;#_=``;static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type=`highlight`;static _editorType=y.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId=``;static get _keyboardManager(){let e=Q.prototype;return j(this,`_keyboardManager`,new ze([[[`ArrowLeft`,`mac+ArrowLeft`],e._moveCaret,{args:[0]}],[[`ArrowRight`,`mac+ArrowRight`],e._moveCaret,{args:[1]}],[[`ArrowUp`,`mac+ArrowUp`],e._moveCaret,{args:[2]}],[[`ArrowDown`,`mac+ArrowDown`],e._moveCaret,{args:[3]}]]))}constructor(e){super({...e,name:`highlightEditor`});this.color=e.color||Q._defaultColor;this.#g=e.thickness||Q._defaultThickness;this.opacity=e.opacity||Q._defaultOpacity;this.#n=e.boxes||null;this.#_=e.methodOfCreation||``;this.#h=e.text||``;this._isDraggable=!1;this.defaultL10nId=`pdfjs-editor-highlight-editor`;if(e.highlightId>-1){this.#d=!0;this.#y(e);this.#w()}else if(this.#n){this.#e=e.anchorNode;this.#t=e.anchorOffset;this.#o=e.focusNode;this.#s=e.focusOffset;this.#v();this.#w();this.rotate(this.rotation)}this.annotationElementId||this._uiManager.a11yAlert(V._l10nAlert.highlight)}get telemetryInitialData(){return{action:`added`,type:this.#d?`free_highlight`:`highlight`,color:this._uiManager.getNonHCMColorName(this.color),thickness:this.#g,methodOfCreation:this.#_}}get telemetryFinalData(){return{type:`highlight`,color:this._uiManager.getNonHCMColorName(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get(`color`).size}}#v(){let e=new br(this.#n,.001);this.#l=e.getOutlines();[this.x,this.y,this.width,this.height]=this.#l.box;let t=new br(this.#n,.0025,.001,this._uiManager.direction===`ltr`);this.#a=t.getOutlines();let{firstPoint:n}=this.#l;this.#f=[(n[0]-this.x)/this.width,(n[1]-this.y)/this.height];let{lastPoint:r}=this.#a;this.#p=[(r[0]-this.x)/this.width,(r[1]-this.y)/this.height]}#y({highlightOutlines:e,highlightId:t,clipPathId:n}){this.#l=e;this.#a=e.getNewOutline(this.#g/2+1.5,.0025);if(t>=0){this.#u=t;this.#r=n;this.parent.drawLayer.finalizeDraw(t,{bbox:e.box,path:{d:e.toSVGPath()}});this.#m=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#a.box,path:{d:this.#a.toSVGPath()}},!0)}else if(this.parent){let t=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#u,{bbox:Q.#T(this.#l.box,(t-this.rotation+360)%360),path:{d:e.toSVGPath()}});this.parent.drawLayer.updateProperties(this.#m,{bbox:Q.#T(this.#a.box,t),path:{d:this.#a.toSVGPath()}})}let[r,i,a,o]=e.box;switch(this.rotation){case 0:this.x=r;this.y=i;this.width=a;this.height=o;break;case 90:{let[e,t]=this.parentDimensions;this.x=i;this.y=1-r;this.width=a*t/e;this.height=o*e/t;break}case 180:this.x=1-r;this.y=1-i;this.width=a;this.height=o;break;case 270:{let[e,t]=this.parentDimensions;this.x=1-i;this.y=r;this.width=a*t/e;this.height=o*e/t;break}}let{firstPoint:s}=e;this.#f=[(s[0]-r)/a,(s[1]-i)/o];let{lastPoint:c}=this.#a;this.#p=[(c[0]-r)/a,(c[1]-i)/o]}static initialize(e,t){V.initialize(e,t);Q._defaultColor||=t.highlightColors?.values().next().value||`#fff066`}static updateDefaultParams(e,t){switch(e){case b.HIGHLIGHT_COLOR:Q._defaultColor=t;break;case b.HIGHLIGHT_THICKNESS:Q._defaultThickness=t}}translateInPage(e,t){}get toolbarPosition(){return this.#p}get commentButtonPosition(){return this.#f}updateParams(e,t){switch(e){case b.HIGHLIGHT_COLOR:this.#b(t);break;case b.HIGHLIGHT_THICKNESS:this.#x(t)}}static get defaultPropertiesToUpdate(){return[[b.HIGHLIGHT_COLOR,Q._defaultColor],[b.HIGHLIGHT_THICKNESS,Q._defaultThickness]]}get propertiesToUpdate(){return[[b.HIGHLIGHT_COLOR,this.color||Q._defaultColor],[b.HIGHLIGHT_THICKNESS,this.#g||Q._defaultThickness],[b.HIGHLIGHT_FREE,this.#d]]}onUpdatedColor(){this.parent?.drawLayer.updateProperties(this.#u,{root:{fill:this.color,"fill-opacity":this.opacity}});this.#i?.updateColor(this.color);super.onUpdatedColor()}#b(e){let t=(e,t)=>{this.color=e;this.opacity=t;this.onUpdatedColor()},n=this.color,r=this.opacity;this.addCommands({cmd:t.bind(this,e,Q._defaultOpacity),undo:t.bind(this,n,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:b.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0});this._reportTelemetry({action:`color_changed`,color:this._uiManager.getNonHCMColorName(e)},!0)}#x(e){let t=this.#g,n=e=>{this.#g=e;this.#S(e)};this.addCommands({cmd:n.bind(this,e),undo:n.bind(this,t),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:b.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0});this._reportTelemetry({action:`thickness_changed`,thickness:e},!0)}get toolbarButtons(){if(this._uiManager.highlightColors)return[[`colorPicker`,this.#i=new J({editor:this})]];return super.toolbarButtons}disableEditing(){super.disableEditing();this.div.classList.toggle(`disabled`,!0)}enableEditing(){super.enableEditing();this.div.classList.toggle(`disabled`,!1)}fixAndSetPosition(){return super.fixAndSetPosition(this.#O())}getBaseTranslation(){return[0,0]}getRect(e,t){return super.getRect(e,t,this.#O())}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this);e&&this.div.focus()}remove(){this.#C();this._reportTelemetry({action:`deleted`});super.remove()}rebuild(){if(this.parent){super.rebuild();if(this.div!==null){this.#w();this.isAttachedToDOM||this.parent.add(this)}}}setParent(e){let t=!1;if(this.parent&&!e)this.#C();else if(e){this.#w(e);t=!this.parent&&this.div?.classList.contains(`selectedEditor`)}super.setParent(e);this.show(this._isVisible);t&&this.select()}#S(e){if(this.#d){this.#y({highlightOutlines:this.#l.getNewOutline(e/2)});this.fixAndSetPosition();this.setDims()}}#C(){if(this.#u!==null&&this.parent){this.parent.drawLayer.remove(this.#u);this.#u=null;this.parent.drawLayer.remove(this.#m);this.#m=null}}#w(e=this.parent){if(this.#u===null){({id:this.#u,clipPathId:this.#r}=e.drawLayer.draw({bbox:this.#l.box,root:{viewBox:`0 0 1 1`,fill:this.color,"fill-opacity":this.opacity},rootClass:{highlight:!0,free:this.#d},path:{d:this.#l.toSVGPath()}},!1,!0));this.#m=e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#d},bbox:this.#a.box,path:{d:this.#a.toSVGPath()}},this.#d);this.#c&&(this.#c.style.clipPath=this.#r)}}static#T([e,t,n,r],i){switch(i){case 90:return[1-t-r,e,r,n];case 180:return[1-e-n,1-t-r,n,r];case 270:return[t,1-e-n,r,n]}return[e,t,n,r]}rotate(e){let{drawLayer:t}=this.parent,n;if(this.#d){e=(e-this.rotation+360)%360;n=Q.#T(this.#l.box,e)}else n=Q.#T([this.x,this.y,this.width,this.height],e);t.updateProperties(this.#u,{bbox:n,root:{"data-main-rotation":e}});t.updateProperties(this.#m,{bbox:Q.#T(this.#a.box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;let e=super.render();if(this.#h){e.setAttribute(`aria-label`,this.#h);e.setAttribute(`role`,`mark`)}this.#d?e.classList.add(`free`):this.div.addEventListener(`keydown`,this.#E.bind(this),{signal:this._uiManager._signal});let t=this.#c=document.createElement(`div`);e.append(t);t.setAttribute(`aria-hidden`,`true`);t.className=`internal`;t.style.clipPath=this.#r;this.setDims();Fe(this,this.#c,[`pointerover`,`pointerleave`]);this.enableEditing();return e}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{hovered:!1}})}#E(e){Q._keyboardManager.exec(this,e)}_moveCaret(e){this.parent.unselect(this);switch(e){case 0:case 2:this.#D(!0);break;case 1:case 3:this.#D(!1)}}#D(e){if(!this.#e)return;let t=window.getSelection();e?t.setPosition(this.#e,this.#t):t.setPosition(this.#o,this.#s)}select(){super.select();this.#m&&this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect();if(this.#m){this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{selected:!1}});this.#d||this.#D(!1)}}get _mustFixPosition(){return!this.#d}show(e=this._isVisible){super.show(e);if(this.parent){this.parent.drawLayer.updateProperties(this.#u,{rootClass:{hidden:!e}});this.parent.drawLayer.updateProperties(this.#m,{rootClass:{hidden:!e}})}}#O(){return this.#d?this.rotation:0}#k(){if(this.#d)return null;let[e,t]=this.pageDimensions,[n,r]=this.pageTranslation,i=this.#n,a=new Float32Array(8*i.length),o=0;for(let{x:s,y:c,width:l,height:u}of i){let i=s*e+n,d=(1-c)*t+r;a[o]=a[o+4]=i;a[o+1]=a[o+3]=d;a[o+2]=a[o+6]=i+l*e;a[o+5]=a[o+7]=d-u*t;o+=8}return a}#A(e){return this.#l.serialize(e,this.#O())}static startHighlighting(e,t,{target:n,x:r,y:i}){let{x:a,y:o,width:s,height:c}=n.getBoundingClientRect(),l=new AbortController,u=e.combinedSignal(l),d=t=>{l.abort();this.#M(e,t)};window.addEventListener(`blur`,d,{signal:u});window.addEventListener(`pointerup`,d,{signal:u});window.addEventListener(`pointerdown`,R,{capture:!0,passive:!1,signal:u});window.addEventListener(`contextmenu`,L,{signal:u});n.addEventListener(`pointermove`,this.#j.bind(this,e),{signal:u});this._freeHighlight=new Sr({x:r,y:i},[a,o,s,c],e.scale,this._defaultThickness/2,t,.001);({id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:`0 0 1 1`,fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0))}static#j(e,t){this._freeHighlight.add(t)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#M(e,t){this._freeHighlight.isEmpty()?e.drawLayer.remove(this._freeHighlightId):e.createAndAddNewEditor(t,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:`main_toolbar`});this._freeHighlightId=-1;this._freeHighlight=null;this._freeHighlightClipId=``}static async deserialize(e,t,n){let r=null;if(e instanceof hr){let{data:{quadPoints:t,rect:n,rotation:i,id:a,color:o,opacity:s,popupRef:c,richText:l,contentsObj:u,creationDate:d,modificationDate:f},parent:{page:{pageNumber:p}}}=e;r=e={annotationType:y.HIGHLIGHT,color:Array.from(o),opacity:s,quadPoints:t,boxes:null,pageIndex:p-1,rect:n.slice(0),rotation:i,annotationElementId:a,id:a,deleted:!1,popupRef:c,richText:l,comment:u?.str||null,creationDate:d,modificationDate:f}}else if(e instanceof mr){let{data:{inkLists:t,rect:n,rotation:i,id:a,color:o,borderStyle:{rawWidth:s},popupRef:c,richText:l,contentsObj:u,creationDate:d,modificationDate:f},parent:{page:{pageNumber:p}}}=e;r=e={annotationType:y.HIGHLIGHT,color:Array.from(o),thickness:s,inkLists:t,boxes:null,pageIndex:p-1,rect:n.slice(0),rotation:i,annotationElementId:a,id:a,deleted:!1,popupRef:c,richText:l,comment:u?.str||null,creationDate:d,modificationDate:f}}let{color:i,quadPoints:a,inkLists:o,outlines:s,opacity:c}=e,l=await super.deserialize(e,t,n);l.color=P.makeHexColor(...i);l.opacity=c||1;o&&(l.#g=e.thickness);l._initialData=r;e.comment&&l.setCommentData(e);let[u,d]=l.pageDimensions,[f,p]=l.pageTranslation;if(a){let e=l.#n=[];for(let t=0;t<a.length;t+=8)e.push({x:(a[t]-f)/u,y:1-(a[t+1]-p)/d,width:(a[t+2]-a[t])/u,height:(a[t+1]-a[t+5])/d});l.#v();l.#w();l.rotate(l.rotation)}else if(o||s){l.#d=!0;let e=(o||s.points)[0],n={x:e[0]-f,y:d-(e[1]-p)},r=new Sr(n,[0,0,u,d],1,l.#g/2,!0,.001);for(let t=0,i=e.length;t<i;t+=2){n.x=e[t]-f;n.y=d-(e[t+1]-p);r.add(n)}let{id:i,clipPathId:a}=t.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:`0 0 1 1`,fill:l.color,"fill-opacity":l._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:r.toSVGPath()}},!0,!0);l.#y({highlightOutlines:r.getOutlines(),highlightId:i,clipPathId:a});l.#w();l.rotate(l.parentRotation)}return l}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();let t=V._colorManager.convert(this._uiManager.getNonHCMColor(this.color)),n=super.serialize(e);Object.assign(n,{color:t,opacity:this.opacity,thickness:this.#g,quadPoints:this.#k(),outlines:this.#A(n.rect)});this.addComment(n);if(this.annotationElementId&&!this.#N(n))return null;n.id=this.annotationElementId;return n}#N(e){let{color:t}=this._initialData;return this.hasEditedComment||e.color.some((e,n)=>e!==t[n])}renderAnnotationElement(e){if(this.deleted){e.hide();return null}e.updateEdited({rect:this.getPDFRect(),popup:this.comment});return null}static canCreateNewEmptyEditor(){return!1}}class wr{#e=Object.create(null);updateProperty(e,t){this[e]=t;this.updateSVGProperty(e,t)}updateProperties(e){if(e)for(let[t,n]of Object.entries(e))t.startsWith(`_`)||this.updateProperty(t,n)}updateSVGProperty(e,t){this.#e[e]=t}toSVGProperties(){let e=this.#e;this.#e=Object.create(null);return{root:e}}reset(){this.#e=Object.create(null)}updateAll(e=this){this.updateProperties(e)}clone(){k(`Not implemented`)}}class $ extends V{#e=null;#t;_colorPicker=null;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#n=null;static#r=null;static#i=null;static _INNER_MARGIN=3;constructor(e){super(e);this.#t=e.mustBeCommitted||!1;this._addOutlines(e)}onUpdatedColor(){this._colorPicker?.update(this.color);super.onUpdatedColor()}onUpdatedOpacity(){this._colorPicker?.updateOpacity?.(this.opacity)}_addOutlines(e){if(e.drawOutlines){this.#a(e);this.#c()}}#a({drawOutlines:e,drawId:t,drawingOptions:n}){this.#e=e;this._drawingOptions||=n;this.annotationElementId||this._uiManager.a11yAlert(V._l10nAlert[this.editorType]);if(t>=0){this._drawId=t;this.parent.drawLayer.finalizeDraw(t,e.defaultProperties)}else this._drawId=this.#o(e,this.parent);this.#d(e.box)}#o(e,t){let{id:n}=t.drawLayer.draw($._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return n}static _mergeSVGProperties(e,t){let n=new Set(Object.keys(e));for(let[r,i]of Object.entries(t))n.has(r)?Object.assign(e[r],i):e[r]=i;return e}static getDefaultDrawingOptions(e){k(`Not implemented`)}static get typesMap(){k(`Not implemented`)}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,t){let n=this.typesMap.get(e);n&&this._defaultDrawingOptions.updateProperty(n,t);if(this._currentParent){$.#n.updateProperty(n,t);this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties())}}updateParams(e,t){let n=this.constructor.typesMap.get(e);n&&this._updateProperty(e,n,t)}static get defaultPropertiesToUpdate(){let e=[],t=this._defaultDrawingOptions;for(let[n,r]of this.typesMap)e.push([n,t[r]]);return e}get propertiesToUpdate(){let e=[],{_drawingOptions:t}=this;for(let[n,r]of this.constructor.typesMap)e.push([n,t[r]]);return e}_updateProperty(e,t,n){let r=this._drawingOptions,i=r[t],a=n=>{r.updateProperty(t,n);let i=this.#e.updateProperty(t,n);i&&this.#d(i);this.parent?.drawLayer.updateProperties(this._drawId,r.toSVGProperties());e===this.colorType?this.onUpdatedColor():e===this.opacityType&&this.onUpdatedOpacity()};this.addCommands({cmd:a.bind(this,n),undo:a.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_updateColorAndOpacity(e,t){let n=this.constructor.typesMap.get(this.colorType),r=this.constructor.typesMap.get(this.opacityType),i=this._drawingOptions,a=i[n],o=i[r],s=(e,t)=>{i.updateProperty(n,e);i.updateProperty(r,t);this.#e.updateProperty(n,e);this.#e.updateProperty(r,t);this.parent?.drawLayer.updateProperties(this._drawId,i.toSVGProperties());this.onUpdatedColor();this.onUpdatedOpacity()};this.addCommands({cmd:s.bind(this,e,t),undo:s.bind(this,a,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:b.INK_COLOR_AND_OPACITY,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,$._mergeSVGProperties(this.#e.getPathResizingSVGProperties(this.#u()),{bbox:this.#f()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,$._mergeSVGProperties(this.#e.getPathResizedSVGProperties(this.#u()),{bbox:this.#f()}))}_onTranslating(e,t){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#f()})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,$._mergeSVGProperties(this.#e.getPathTranslatedSVGProperties(this.#u(),this.parentDimensions),{bbox:this.#f()}))}_onStartDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit();this.disableEditMode();this.disableEditing()}disableEditing(){super.disableEditing();this.div.classList.toggle(`disabled`,!0)}enableEditing(){super.enableEditing();this.div.classList.toggle(`disabled`,!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this);this._isDraggable=!0;if(this.#t){this.#t=!1;this.commit();this.parent.setSelected(this);e&&this.isOnScreen&&this.div.focus()}}remove(){this.#s();super.remove()}rebuild(){if(this.parent){super.rebuild();if(this.div!==null){this.#c();this.#d(this.#e.box);this.isAttachedToDOM||this.parent.add(this)}}}setParent(e){let t=!1;if(this.parent&&!e){this._uiManager.removeShouldRescale(this);this.#s()}else if(e){this._uiManager.addShouldRescale(this);this.#c(e);t=!this.parent&&this.div?.classList.contains(`selectedEditor`)}super.setParent(e);t&&this.select()}#s(){if(this._drawId!==null&&this.parent){this.parent.drawLayer.remove(this._drawId);this._drawId=null;this._drawingOptions.reset()}}#c(e=this.parent){if(this._drawId===null||this.parent!==e){if(this._drawId===null){this._drawingOptions.updateAll();this._drawId=this.#o(this.#e,e)}else this.parent.drawLayer.updateParent(this._drawId,e.drawLayer)}}#l([e,t,n,r]){let{parentDimensions:[i,a],rotation:o}=this;switch(o){case 90:return[t,1-e,a/i*n,i/a*r];case 180:return[1-e,1-t,n,r];case 270:return[1-t,e,a/i*n,i/a*r];default:return[e,t,n,r]}}#u(){let{x:e,y:t,width:n,height:r,parentDimensions:[i,a],rotation:o}=this;switch(o){case 90:return[1-t,e,i/a*n,a/i*r];case 180:return[1-e,1-t,n,r];case 270:return[t,1-e,i/a*n,a/i*r];default:return[e,t,n,r]}}#d(e){[this.x,this.y,this.width,this.height]=this.#l(e);if(this.div){this.fixAndSetPosition();this.setDims()}this._onResized()}#f(){let{x:e,y:t,width:n,height:r,rotation:i,parentRotation:a,parentDimensions:[o,s]}=this;switch((4*i+a)/90){case 1:return[1-t-r,e,r,n];case 2:return[1-e-n,1-t-r,n,r];case 3:return[t,1-e-n,r,n];case 4:return[e,t-o/s*n,s/o*r,o/s*n];case 5:return[1-t,e,o/s*n,s/o*r];case 6:return[1-e-s/o*r,1-t,s/o*r,o/s*n];case 7:return[t-o/s*n,1-e-s/o*r,o/s*n,s/o*r];case 8:return[e-n,t-r,n,r];case 9:return[1-t,e-n,r,n];case 10:return[1-e,1-t,n,r];case 11:return[t-r,1-e,r,n];case 12:return[e-s/o*r,t,s/o*r,o/s*n];case 13:return[1-t-o/s*n,e-s/o*r,o/s*n,s/o*r];case 14:return[1-e,1-t-o/s*n,s/o*r,o/s*n];case 15:return[t,1-e,o/s*n,s/o*r];default:return[e,t,n,r]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,$._mergeSVGProperties({bbox:this.#f()},this.#e.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#d(this.#e.updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;let e,t;if(this._isCopy){e=this.x;t=this.y}let n=super.render();n.classList.add(`draw`);let r=document.createElement(`div`);n.append(r);r.setAttribute(`aria-hidden`,`true`);r.className=`internal`;this.setDims();this._uiManager.addShouldRescale(this);this.disableEditing();this._isCopy&&this._moveAfterPaste(e,t);return n}static createDrawerInstance(e,t,n,r,i){k(`Not implemented`)}static startDrawing(e,t,n,r){let{target:i,offsetX:a,offsetY:o,pointerId:s,pointerType:c}=r;if(B.isInitializedAndDifferentPointerType(c))return;let{viewport:{rotation:l}}=e,{width:u,height:d}=i.getBoundingClientRect(),f=$.#r=new AbortController,p=e.combinedSignal(f);B.setPointer(c,s);window.addEventListener(`pointerup`,e=>{B.isSamePointerIdOrRemove(e.pointerId)&&this._endDraw(e)},{signal:p});window.addEventListener(`pointercancel`,e=>{B.isSamePointerIdOrRemove(e.pointerId)&&this._currentParent.endDrawingSession()},{signal:p});window.addEventListener(`pointerdown`,e=>{if(B.isSamePointerType(e.pointerType)){B.initializeAndAddPointerId(e.pointerId);if($.#n.isCancellable()){$.#n.removeLastElement();$.#n.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)}}},{capture:!0,passive:!1,signal:p});window.addEventListener(`contextmenu`,L,{signal:p});i.addEventListener(`pointermove`,this._drawMove.bind(this),{signal:p});i.addEventListener(`touchmove`,e=>{B.isSameTimeStamp(e.timeStamp)&&R(e)},{signal:p});e.toggleDrawing();t._editorUndoBar?.hide();if($.#n)e.drawLayer.updateProperties(this._currentDrawId,$.#n.startNew(a,o,u,d,l));else{t.updateUIForDefaultProperties(this);$.#n=this.createDrawerInstance(a,o,u,d,l);$.#i=this.getDefaultDrawingOptions();this._currentParent=e;({id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties($.#i.toSVGProperties(),$.#n.defaultSVGProperties),!0,!1))}}static _drawMove(e){B.isSameTimeStamp(e.timeStamp);if(!$.#n)return;let{offsetX:t,offsetY:n,pointerId:r}=e;if(B.isSamePointerId(r)){if(B.isUsingMultiplePointers())this._endDraw(e);else{this._currentParent.drawLayer.updateProperties(this._currentDrawId,$.#n.add(t,n));B.setTimeStamp(e.timeStamp);R(e)}}}static _cleanup(e){if(e){this._currentDrawId=-1;this._currentParent=null;$.#n=null;$.#i=null;B.clearTimeStamp()}if($.#r){$.#r.abort();$.#r=null;B.clearPointerIds()}}static _endDraw(e){let t=this._currentParent;if(t){t.toggleDrawing(!0);this._cleanup(!1);e?.target===t.div&&t.drawLayer.updateProperties(this._currentDrawId,$.#n.end(e.offsetX,e.offsetY));if(this.supportMultipleDrawings){let e=$.#n,n=this._currentDrawId,r=e.getLastElement();t.addCommands({cmd:()=>{t.drawLayer.updateProperties(n,e.setLastElement(r))},undo:()=>{t.drawLayer.updateProperties(n,e.removeLastElement())},mustExec:!1,type:b.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){let t=this._currentParent;if(!t)return null;t.toggleDrawing(!0);t.cleanUndoStack(b.DRAW_STEP);if(!$.#n.isEmpty()){let{pageDimensions:[n,r],scale:i}=t,a=t.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:$.#n.getOutlines(n*i,r*i,i,this._INNER_MARGIN),drawingOptions:$.#i,mustBeCommitted:!e});this._cleanup(!0);return a}t.drawLayer.remove(this._currentDrawId);this._cleanup(!0);return null}createDrawingOptions(e){}static deserializeDraw(e,t,n,r,i,a){k(`Not implemented`)}static async deserialize(e,t,n){let{rawDims:{pageWidth:r,pageHeight:i,pageX:a,pageY:o}}=t.viewport,s=this.deserializeDraw(a,o,r,i,this._INNER_MARGIN,e),c=await super.deserialize(e,t,n);c.createDrawingOptions(e);c.#a({drawOutlines:s});c.#c();c.onScaleChanging();c.rotate();return c}serializeDraw(e){let[t,n]=this.pageTranslation,[r,i]=this.pageDimensions;return this.#e.serialize([t,n,r,i],e)}renderAnnotationElement(e){e.updateEdited({rect:this.getPDFRect()});return null}static canCreateNewEmptyEditor(){return!1}}class Tr{#e=new Float64Array(6);#t;#n;#r;#i;#a;#o=``;#s=0;#c=new Er;#l;#u;constructor(e,t,n,r,i,a){this.#l=n;this.#u=r;this.#r=i;this.#i=a;[e,t]=this.#d(e,t);let o=this.#t=[NaN,NaN,NaN,NaN,e,t];this.#a=[e,t];this.#n=[{line:o,points:this.#a}];this.#e.set(o,0)}updateProperty(e,t){e===`stroke-width`&&(this.#i=t)}#d(e,t){return Z._normalizePoint(e,t,this.#l,this.#u,this.#r)}isEmpty(){return!this.#n||this.#n.length===0}isCancellable(){return this.#a.length<=10}add(e,t){[e,t]=this.#d(e,t);let[n,r,i,a]=this.#e.subarray(2,6),o=e-i,s=t-a;if(Math.hypot(this.#l*o,this.#u*s)<=2)return null;this.#a.push(e,t);if(isNaN(n)){this.#e.set([i,a,e,t],2);this.#t.push(NaN,NaN,NaN,NaN,e,t);return{path:{d:this.toSVGPath()}}}isNaN(this.#e[0])&&this.#t.splice(6,6);this.#e.set([n,r,i,a,e,t],0);this.#t.push(...Z.createBezierPoints(n,r,i,a,e,t));return{path:{d:this.toSVGPath()}}}end(e,t){return this.add(e,t)||(this.#a.length===2?{path:{d:this.toSVGPath()}}:null)}startNew(e,t,n,r,i){this.#l=n;this.#u=r;this.#r=i;[e,t]=this.#d(e,t);let a=this.#t=[NaN,NaN,NaN,NaN,e,t];this.#a=[e,t];let o=this.#n.at(-1);if(o){o.line=new Float32Array(o.line);o.points=new Float32Array(o.points)}this.#n.push({line:a,points:this.#a});this.#e.set(a,0);this.#s=0;this.toSVGPath();return null}getLastElement(){return this.#n.at(-1)}setLastElement(e){if(!this.#n)return this.#c.setLastElement(e);this.#n.push(e);this.#t=e.line;this.#a=e.points;this.#s=0;return{path:{d:this.toSVGPath()}}}removeLastElement(){if(!this.#n)return this.#c.removeLastElement();this.#n.pop();this.#o=``;for(let e=0,t=this.#n.length;e<t;e++){let{line:t,points:n}=this.#n[e];this.#t=t;this.#a=n;this.#s=0;this.toSVGPath()}return{path:{d:this.#o}}}toSVGPath(){let e=Z.svgRound(this.#t[4]),t=Z.svgRound(this.#t[5]);if(this.#a.length===2){this.#o=`${this.#o} M ${e} ${t} Z`;return this.#o}if(this.#a.length<=6){let n=this.#o.lastIndexOf(`M`);this.#o=`${this.#o.slice(0,n)} M ${e} ${t}`;this.#s=6}if(this.#a.length===4){let e=Z.svgRound(this.#t[10]),t=Z.svgRound(this.#t[11]);this.#o=`${this.#o} L ${e} ${t}`;this.#s=12;return this.#o}let n=[];if(this.#s===0){n.push(`M ${e} ${t}`);this.#s=6}for(let e=this.#s,t=this.#t.length;e<t;e+=6){let[t,r,i,a,o,s]=this.#t.slice(e,e+6).map(Z.svgRound);n.push(`C${t} ${r} ${i} ${a} ${o} ${s}`)}this.#o+=n.join(` `);this.#s=this.#t.length;return this.#o}getOutlines(e,t,n,r){let i=this.#n.at(-1);i.line=new Float32Array(i.line);i.points=new Float32Array(i.points);this.#c.build(this.#n,e,t,n,this.#r,this.#i,r);this.#e=null;this.#t=null;this.#n=null;this.#o=null;return this.#c}get defaultSVGProperties(){return{root:{viewBox:`0 0 10000 10000`},rootClass:{draw:!0},bbox:[0,0,1,1]}}}class Er extends Z{#e;#t=0;#n;#r;#i;#a;#o;#s;#c;build(e,t,n,r,i,a,o){this.#i=t;this.#a=n;this.#o=r;this.#s=i;this.#c=a;this.#n=o??0;this.#r=e;this.#d()}get thickness(){return this.#c}setLastElement(e){this.#r.push(e);return{path:{d:this.toSVGPath()}}}removeLastElement(){this.#r.pop();return{path:{d:this.toSVGPath()}}}toSVGPath(){let e=[];for(let{line:t}of this.#r){e.push(`M${Z.svgRound(t[4])} ${Z.svgRound(t[5])}`);if(t.length!==6){if(t.length===12&&isNaN(t[6]))e.push(`L${Z.svgRound(t[10])} ${Z.svgRound(t[11])}`);else for(let n=6,r=t.length;n<r;n+=6){let[r,i,a,o,s,c]=t.subarray(n,n+6).map(Z.svgRound);e.push(`C${r} ${i} ${a} ${o} ${s} ${c}`)}}else e.push(`Z`)}return e.join(``)}serialize([e,t,n,r],i){let a=[],o=[],[s,c,l,u]=this.#u(),d,f,p,m,h,g,_,v,y;switch(this.#s){case 0:y=Z._rescale;d=e;f=t+r;p=n;m=-r;h=e+s*n;g=t+(1-c-u)*r;_=e+(s+l)*n;v=t+(1-c)*r;break;case 90:y=Z._rescaleAndSwap;d=e;f=t;p=n;m=r;h=e+c*n;g=t+s*r;_=e+(c+u)*n;v=t+(s+l)*r;break;case 180:y=Z._rescale;d=e+n;f=t;p=-n;m=r;h=e+(1-s-l)*n;g=t+c*r;_=e+(1-s)*n;v=t+(c+u)*r;break;case 270:y=Z._rescaleAndSwap;d=e+n;f=t+r;p=-n;m=-r;h=e+(1-c-u)*n;g=t+(1-s-l)*r;_=e+(1-c)*n;v=t+(1-s)*r}for(let{line:e,points:t}of this.#r){a.push(y(e,d,f,p,m,i?Array(e.length):null));o.push(y(t,d,f,p,m,i?Array(t.length):null))}return{lines:a,points:o,rect:[h,g,_,v]}}static deserialize(e,t,n,r,i,{paths:{lines:a,points:o},rotation:s,thickness:c}){let l=[],u,d,f,p,m;switch(s){case 0:m=Z._rescale;u=-e/n;d=t/r+1;f=1/n;p=-1/r;break;case 90:m=Z._rescaleAndSwap;u=-t/r;d=-e/n;f=1/r;p=1/n;break;case 180:m=Z._rescale;u=e/n+1;d=-t/r;f=-1/n;p=1/r;break;case 270:m=Z._rescaleAndSwap;u=t/r+1;d=e/n+1;f=-1/r;p=-1/n}if(!a){a=[];for(let e of o){let t=e.length;if(t===2){a.push(new Float32Array([NaN,NaN,NaN,NaN,e[0],e[1]]));continue}if(t===4){a.push(new Float32Array([NaN,NaN,NaN,NaN,e[0],e[1],NaN,NaN,NaN,NaN,e[2],e[3]]));continue}let n=new Float32Array(3*(t-2));a.push(n);let[r,i,o,s]=e.subarray(0,4);n.set([NaN,NaN,NaN,NaN,r,i],0);for(let a=4;a<t;a+=2){let t=e[a],c=e[a+1];n.set(Z.createBezierPoints(r,i,o,s,t,c),3*(a-2));[r,i,o,s]=[o,s,t,c]}}}for(let e=0,t=a.length;e<t;e++)l.push({line:m(a[e].map(e=>e??NaN),u,d,f,p),points:m(o[e].map(e=>e??NaN),u,d,f,p)});let h=new this.prototype.constructor;h.build(l,n,r,1,s,c,i);return h}#l(e=this.#c){let t=this.#n+e/2*this.#o;return this.#s%180==0?[t/this.#i,t/this.#a]:[t/this.#a,t/this.#i]}#u(){let[e,t,n,r]=this.#e,[i,a]=this.#l(0);return[e+i,t+a,n-2*i,r-2*a]}#d(){let e=this.#e=p.slice();for(let{line:t}of this.#r){if(t.length<=12){for(let n=4,r=t.length;n<r;n+=6)P.pointBoundingBox(t[n],t[n+1],e);continue}let n=t[4],r=t[5];for(let i=6,a=t.length;i<a;i+=6){let[a,o,s,c,l,u]=t.subarray(i,i+6);P.bezierBoundingBox(n,r,a,o,s,c,l,u,e);n=l;r=u}}let[t,n]=this.#l();e[0]=F(e[0]-t,0,1);e[1]=F(e[1]-n,0,1);e[2]=F(e[2]+t,0,1);e[3]=F(e[3]+n,0,1);e[2]-=e[0];e[3]-=e[1]}get box(){return this.#e}updateProperty(e,t){return e===`stroke-width`?this.#f(t):null}#f(e){let[t,n]=this.#l();this.#c=e;let[r,i]=this.#l(),[a,o]=[r-t,i-n],s=this.#e;s[0]-=a;s[1]-=o;s[2]+=2*a;s[3]+=2*o;return s}updateParentDimensions([e,t],n){let[r,i]=this.#l();this.#i=e;this.#a=t;this.#o=n;let[a,o]=this.#l(),s=a-r,c=o-i,l=this.#e;l[0]-=s;l[1]-=c;l[2]+=2*s;l[3]+=2*c;return l}updateRotation(e){this.#t=e;return{path:{transform:this.rotationTransform}}}get viewBox(){return this.#e.map(Z.svgRound).join(` `)}get defaultProperties(){let[e,t]=this.#e;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`}}}get rotationTransform(){let[,,e,t]=this.#e,n=0,r=0,i=0,a=0,o=0,s=0;switch(this.#t){case 90:r=t/e;i=-e/t;o=e;break;case 180:n=-1;a=-1;o=e;s=t;break;case 270:r=-t/e;i=e/t;s=t;break;default:return``}return`matrix(${n} ${r} ${i} ${a} ${Z.svgRound(o)} ${Z.svgRound(s)})`}getPathResizingSVGProperties([e,t,n,r]){let[i,a]=this.#l(),[o,s,c,l]=this.#e;if(Math.abs(c-i)<=Z.PRECISION||Math.abs(l-a)<=Z.PRECISION){let i=e+n/2-(o+c/2),a=t+r/2-(s+l/2);return{path:{"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`,transform:`${this.rotationTransform} translate(${i} ${a})`}}}let u=(n-2*i)/(c-2*i),d=(r-2*a)/(l-2*a),f=c/n,p=l/r;return{path:{"transform-origin":`${Z.svgRound(o)} ${Z.svgRound(s)}`,transform:`${this.rotationTransform} scale(${f} ${p}) translate(${Z.svgRound(i)} ${Z.svgRound(a)}) scale(${u} ${d}) translate(${Z.svgRound(-i)} ${Z.svgRound(-a)})`}}}getPathResizedSVGProperties([e,t,n,r]){let[i,a]=this.#l(),o=this.#e,[s,c,l,u]=o;o[0]=e;o[1]=t;o[2]=n;o[3]=r;if(Math.abs(l-i)<=Z.PRECISION||Math.abs(u-a)<=Z.PRECISION){let i=e+n/2-(s+l/2),a=t+r/2-(c+u/2);for(let{line:e,points:t}of this.#r){Z._translate(e,i,a,e);Z._translate(t,i,a,t)}return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}let d=(n-2*i)/(l-2*i),f=(r-2*a)/(u-2*a),p=-d*(s+i)+e+i,m=-f*(c+a)+t+a;if(d!==1||f!==1||p!==0||m!==0)for(let{line:e,points:t}of this.#r){Z._rescale(e,p,m,d,f,e);Z._rescale(t,p,m,d,f,t)}return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,t],n){let[r,i]=n,a=this.#e,o=e-a[0],s=t-a[1];if(this.#i===r&&this.#a===i)for(let{line:e,points:t}of this.#r){Z._translate(e,o,s,e);Z._translate(t,o,s,t)}else{let e=this.#i/r,t=this.#a/i;this.#i=r;this.#a=i;for(let{line:n,points:r}of this.#r){Z._rescale(n,o,s,e,t,n);Z._rescale(r,o,s,e,t,r)}a[2]*=e;a[3]*=t}a[0]=e;a[1]=t;return{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`}}}get defaultSVGProperties(){let e=this.#e;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${Z.svgRound(e[0])} ${Z.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}}class Dr extends wr{constructor(e){super();this._viewParameters=e;super.updateProperties({fill:`none`,stroke:V._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-miterlimit":10})}updateSVGProperty(e,t){if(e===`stroke-width`){t??=this[`stroke-width`];t*=this._viewParameters.realScale}super.updateSVGProperty(e,t)}clone(){let e=new Dr(this._viewParameters);e.updateAll(this);return e}}class Or extends ${static _type=`ink`;static _editorType=y.INK;static _defaultDrawingOptions=null;constructor(e){super({...e,name:`inkEditor`});this._willKeepAspectRatio=!0;this.defaultL10nId=`pdfjs-editor-ink-editor`}static initialize(e,t){V.initialize(e,t);this._defaultDrawingOptions=new Dr(t.viewParameters)}static getDefaultDrawingOptions(e){let t=this._defaultDrawingOptions.clone();t.updateProperties(e);return t}static get supportMultipleDrawings(){return!0}static get typesMap(){return j(this,`typesMap`,new Map([[b.INK_THICKNESS,`stroke-width`],[b.INK_COLOR,`stroke`],[b.INK_OPACITY,`stroke-opacity`]]))}static createDrawerInstance(e,t,n,r,i){return new Tr(e,t,n,r,i,this._defaultDrawingOptions[`stroke-width`])}static deserializeDraw(e,t,n,r,i,a){return Er.deserialize(e,t,n,r,i,a)}static async deserialize(e,t,n){let r=null;if(e instanceof mr){let{data:{inkLists:t,rect:n,rotation:i,id:a,color:o,opacity:s,borderStyle:{rawWidth:c},popupRef:l,richText:u,contentsObj:d,creationDate:f,modificationDate:p},parent:{page:{pageNumber:m}}}=e;r=e={annotationType:y.INK,color:Array.from(o),thickness:c,opacity:s,paths:{points:t},boxes:null,pageIndex:m-1,rect:n.slice(0),rotation:i,annotationElementId:a,id:a,deleted:!1,popupRef:l,richText:u,comment:d?.str||null,creationDate:f,modificationDate:p}}let i=await super.deserialize(e,t,n);i._initialData=r;e.comment&&i.setCommentData(e);return i}get toolbarButtons(){this._colorPicker||=new rr(this);return[[`colorPicker`,this._colorPicker]]}get colorType(){return b.INK_COLOR}get colorAndOpacityType(){return b.INK_COLOR_AND_OPACITY}get opacityType(){return b.INK_OPACITY}updateParams(e,t){e===b.INK_COLOR_AND_OPACITY?this._updateColorAndOpacity(t.color,t.opacity):super.updateParams(e,t)}static updateDefaultParams(e,t){if(e!==b.INK_COLOR_AND_OPACITY)super.updateDefaultParams(e,t);else{super.updateDefaultParams(b.INK_COLOR,t.color);super.updateDefaultParams(b.INK_OPACITY,t.opacity)}}get color(){return this._drawingOptions.stroke}get opacity(){return this._drawingOptions[`stroke-opacity`]}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();let{_drawId:e,_drawingOptions:t,parent:n}=this;t.updateSVGProperty(`stroke-width`);n.drawLayer.updateProperties(e,t.toSVGProperties())}static onScaleChangingWhenDrawing(){let e=this._currentParent;if(e){super.onScaleChangingWhenDrawing();this._defaultDrawingOptions.updateSVGProperty(`stroke-width`);e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties())}}createDrawingOptions({color:e,thickness:t,opacity:n}){this._drawingOptions=Or.getDefaultDrawingOptions({stroke:P.makeHexColor(...e),"stroke-width":t,"stroke-opacity":n})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let{lines:t,points:n}=this.serializeDraw(e),{_drawingOptions:{stroke:r,"stroke-opacity":i,"stroke-width":a}}=this,o=Object.assign(super.serialize(e),{color:V._colorManager.convert(r),opacity:i,thickness:a,paths:{lines:t,points:n}});this.addComment(o);if(e){o.isCopy=!0;return o}if(this.annotationElementId&&!this.#e(o))return null;o.id=this.annotationElementId;return o}#e(e){let{color:t,thickness:n,opacity:r,pageIndex:i}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized||e.color.some((e,n)=>e!==t[n])||e.thickness!==n||e.opacity!==r||e.pageIndex!==i}renderAnnotationElement(e){if(this.deleted){e.hide();return null}let{points:t,rect:n}=this.serializeDraw(!1);e.updateEdited({rect:n,thickness:this._drawingOptions[`stroke-width`],points:t,popup:this.comment});return null}}class kr extends Er{toSVGPath(){let e=super.toSVGPath();e.endsWith(`Z`)||(e+=`Z`);return e}}class Ar{static#e={maxDim:512,sigmaSFactor:.02,sigmaR:25,kernelSize:16};static#t(e,t,n,r){r-=t;return(n-=e)===0?r>0?0:4:n===1?r+6:2-r}static#n=new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]);static#r(e,t,n,r,i,a,o){let s=this.#t(n,r,i,a);for(let i=0;i<8;i++){let a=(-i+s-o+16)%8;if(e[(n+this.#n[2*a])*t+(r+this.#n[2*a+1])]!==0)return a}return-1}static#i(e,t,n,r,i,a,o){let s=this.#t(n,r,i,a);for(let i=0;i<8;i++){let a=(i+s+o+16)%8;if(e[(n+this.#n[2*a])*t+(r+this.#n[2*a+1])]!==0)return a}return-1}static#a(e,t,n,r){let i=e.length,a=new Int32Array(i);for(let t=0;t<i;t++)a[t]=+(e[t]<=r);for(let e=1;e<n-1;e++)a[e*t]=a[e*t+t-1]=0;for(let e=0;e<t;e++)a[e]=a[t*n-1-e]=0;let o,s=1,c=[];for(let e=1;e<n-1;e++){o=1;for(let n=1;n<t-1;n++){let r=e*t+n,i=a[r];if(i===0)continue;let l=e,u=n;if(i===1&&a[r-1]===0){s+=1;--u}else{if(!(i>=1&&a[r+1]===0)){i!==1&&(o=Math.abs(i));continue}s+=1;u+=1;i>1&&(o=i)}let d=[n,e],f=u===n+1,p={isHole:f,points:d,id:s,parent:0};c.push(p);let m;for(let e of c)if(e.id===o){m=e;break}p.parent=m?m.isHole?f?m.parent:o:f?o:m.parent:f?o:0;let h=this.#r(a,t,e,n,l,u,0);if(h===-1){a[r]=-s;a[r]!==1&&(o=Math.abs(a[r]));continue}let g=this.#n[2*h],_=this.#n[2*h+1],v=e+g,y=n+_;l=v;u=y;let b=e,x=n;for(;;){let i=this.#i(a,t,b,x,l,u,1);g=this.#n[2*i];_=this.#n[2*i+1];let c=b+g,f=x+_;d.push(f,c);let p=b*t+x;a[p+1]===0?a[p]=-s:a[p]===1&&(a[p]=s);if(c===e&&f===n&&b===v&&x===y){a[r]!==1&&(o=Math.abs(a[r]));break}l=b;u=x;b=c;x=f}}}return c}static#o(e,t,n,r){if(n-t<=4){for(let i=t;i<n-2;i+=2)r.push(e[i],e[i+1]);return}let i=e[t],a=e[t+1],o=e[n-4]-i,s=e[n-3]-a,c=Math.hypot(o,s),l=o/c,u=s/c,d=l*a-u*i,f=s/o,p=1/c,m=Math.atan(f),h=Math.cos(m),g=Math.sin(m),_=p*(Math.abs(h)+Math.abs(g)),v=p*(1-_+_**2),y=Math.max(Math.atan(Math.abs(g+h)*v),Math.atan(Math.abs(g-h)*v)),b=0,x=t;for(let r=t+2;r<n-2;r+=2){let t=Math.abs(d-l*e[r+1]+u*e[r]);if(t>b){x=r;b=t}}if(b>(c*y)**2){this.#o(e,t,x+2,r);this.#o(e,x,n,r)}else r.push(i,a)}static#s(e){let t=[],n=e.length;this.#o(e,0,n,t);t.push(e[n-2],e[n-1]);return t.length<=4?null:t}static#c(e,t,n,r,i,a){let o=new Float32Array(a**2),s=-2*r**2,c=a>>1;for(let e=0;e<a;e++){let t=(e-c)**2;for(let n=0;n<a;n++)o[e*a+n]=Math.exp((t+(n-c)**2)/s)}let l=new Float32Array(256),u=-2*i**2;for(let e=0;e<256;e++)l[e]=Math.exp(e**2/u);let d=e.length,f=new Uint8Array(d),p=new Uint32Array(256);for(let r=0;r<n;r++)for(let i=0;i<t;i++){let s=r*t+i,u=e[s],d=0,m=0;for(let s=0;s<a;s++){let f=r+s-c;if(!(f<0||f>=n))for(let n=0;n<a;n++){let r=i+n-c;if(r<0||r>=t)continue;let p=e[f*t+r],h=o[s*a+n]*l[Math.abs(p-u)];d+=p*h;m+=h}}p[f[s]=Math.round(d/m)]++}return[f,p]}static#l(e){let t=new Uint32Array(256);for(let n of e)t[n]++;return t}static#u(e){let t=e.length,n=new Uint8ClampedArray(t>>2),r=-1/0,i=1/0;for(let t=0,a=n.length;t<a;t++){let a=n[t]=e[t<<2];r=Math.max(r,a);i=Math.min(i,a)}let a=255/(r-i);for(let e=0,t=n.length;e<t;e++)n[e]=(n[e]-i)*a;return n}static#d(e){let t,n=-1/0,r=-1/0,i=e.findIndex(e=>e!==0),a=i,o=i;for(t=i;t<256;t++){let i=e[t];if(i>n){if(t-a>r){r=t-a;o=t-1}n=i;a=t}}for(t=o-1;t>=0&&!(e[t]>e[t+1]);t--);return t}static#f(e){let t=e,{width:n,height:r}=e,{maxDim:i}=this.#e,a=n,o=r;if(n>i||r>i){let s=n,c=r,l=Math.log2(Math.max(n,r)/i),u=Math.floor(l);l=l===u?u-1:u;for(let n=0;n<l;n++){a=Math.ceil(s/2);o=Math.ceil(c/2);let n=new OffscreenCanvas(a,o);n.getContext(`2d`).drawImage(e,0,0,s,c,0,0,a,o);s=a;c=o;e!==t&&e.close();e=n.transferToImageBitmap()}let d=Math.min(i/a,i/o);a=Math.round(a*d);o=Math.round(o*d)}let s=new OffscreenCanvas(a,o).getContext(`2d`,{willReadFrequently:!0});s.fillStyle=`white`;s.fillRect(0,0,a,o);s.filter=`grayscale(1)`;s.drawImage(e,0,0,e.width,e.height,0,0,a,o);let c=s.getImageData(0,0,a,o).data;return[this.#u(c),a,o]}static extractContoursFromText(e,{fontFamily:t,fontStyle:n,fontWeight:r},i,a,o,s){let c=new OffscreenCanvas(1,1),l=c.getContext(`2d`,{alpha:!1}),u=l.font=`${n} ${r} 200px ${t}`,{actualBoundingBoxLeft:d,actualBoundingBoxRight:f,actualBoundingBoxAscent:p,actualBoundingBoxDescent:m,fontBoundingBoxAscent:h,fontBoundingBoxDescent:g,width:_}=l.measureText(e),v=1.5,y=Math.ceil(Math.max(Math.abs(d)+Math.abs(f)||0,_)*v),b=Math.ceil(Math.max(Math.abs(p)+Math.abs(m)||200,Math.abs(h)+Math.abs(g)||200)*v);c=new OffscreenCanvas(y,b);l=c.getContext(`2d`,{alpha:!0,willReadFrequently:!0});l.font=u;l.filter=`grayscale(1)`;l.fillStyle=`white`;l.fillRect(0,0,y,b);l.fillStyle=`black`;l.fillText(e,.5*y/2,1.5*b/2);let x=this.#u(l.getImageData(0,0,y,b).data),S=this.#l(x),C=this.#d(S),w=this.#a(x,y,b,C);return this.processDrawnLines({lines:{curves:w,width:y,height:b},pageWidth:i,pageHeight:a,rotation:o,innerMargin:s,mustSmooth:!0,areContours:!0})}static process(e,t,n,r,i){let[a,o,s]=this.#f(e),[c,l]=this.#c(a,o,s,Math.hypot(o,s)*this.#e.sigmaSFactor,this.#e.sigmaR,this.#e.kernelSize),u=this.#d(l),d=this.#a(c,o,s,u);return this.processDrawnLines({lines:{curves:d,width:o,height:s},pageWidth:t,pageHeight:n,rotation:r,innerMargin:i,mustSmooth:!0,areContours:!0})}static processDrawnLines({lines:e,pageWidth:t,pageHeight:n,rotation:r,innerMargin:i,mustSmooth:a,areContours:o}){r%180!=0&&([t,n]=[n,t]);let{curves:s,width:c,height:l}=e,u=e.thickness??0,d=[],f=Math.min(t/c,n/l),p=f/t,m=f/n,h=[];for(let{points:e}of s){let t=a?this.#s(e):e;if(!t)continue;h.push(t);let n=t.length,r=new Float32Array(n),i=new Float32Array(3*(n===2?2:n-2));d.push({line:i,points:r});if(n===2){r[0]=t[0]*p;r[1]=t[1]*m;i.set([NaN,NaN,NaN,NaN,r[0],r[1]],0);continue}let[o,s,c,l]=t;o*=p;s*=m;c*=p;l*=m;r.set([o,s,c,l],0);i.set([NaN,NaN,NaN,NaN,o,s],0);for(let e=4;e<n;e+=2){let n=r[e]=t[e]*p,a=r[e+1]=t[e+1]*m;i.set(Z.createBezierPoints(o,s,c,l,n,a),3*(e-2));[o,s,c,l]=[c,l,n,a]}}if(d.length===0)return null;let g=o?new kr:new Er;g.build(d,t,n,1,r,o?0:u,i);return{outline:g,newCurves:h,areContours:o,thickness:u,width:c,height:l}}static async compressSignature({outlines:e,areContours:t,thickness:n,width:r,height:i}){let a,o=1/0,s=-1/0,c=0;for(let t of e){c+=t.length;for(let e=2,n=t.length;e<n;e++){let n=t[e]-t[e-2];o=Math.min(o,n);s=Math.max(s,n)}}a=o>=-128&&s<=127?Int8Array:o>=-32768&&s<=32767?Int16Array:Int32Array;let l=e.length,u=8+3*l,d=new Uint32Array(u),f=0;d[f++]=u*Uint32Array.BYTES_PER_ELEMENT+(c-2*l)*a.BYTES_PER_ELEMENT;d[f++]=0;d[f++]=r;d[f++]=i;d[f++]=+!t;d[f++]=Math.max(0,Math.floor(n??0));d[f++]=l;d[f++]=a.BYTES_PER_ELEMENT;for(let t of e){d[f++]=t.length-2;d[f++]=t[0];d[f++]=t[1]}let p=new CompressionStream(`deflate-raw`),m=p.writable.getWriter();await m.ready;m.write(d);let h=a.prototype.constructor;for(let t of e){let e=new h(t.length-2);for(let n=2,r=t.length;n<r;n++)e[n-2]=t[n]-t[n-2];m.write(e)}m.close();return(await new Response(p.readable).bytes()).toBase64()}static async decompressSignature(e){try{let t=Uint8Array.fromBase64(e),{readable:n,writable:r}=new DecompressionStream(`deflate-raw`),i=r.getWriter();await i.ready;i.write(t).then(async()=>{await i.ready;await i.close()}).catch(()=>{});let a=null,o=0;for await(let e of n){a||=new Uint8Array(new Uint32Array(e.buffer,0,4)[0]);a.set(e,o);o+=e.length}let s=new Uint32Array(a.buffer,0,a.length>>2),c=s[1];if(c!==0)throw Error(`Invalid version: ${c}`);let l=s[2],u=s[3],d=s[4]===0,f=s[5],p=s[6],m=s[7],h=[],g=(8+3*p)*Uint32Array.BYTES_PER_ELEMENT,_;switch(m){case Int8Array.BYTES_PER_ELEMENT:_=new Int8Array(a.buffer,g);break;case Int16Array.BYTES_PER_ELEMENT:_=new Int16Array(a.buffer,g);break;case Int32Array.BYTES_PER_ELEMENT:_=new Int32Array(a.buffer,g)}o=0;for(let e=0;e<p;e++){let t=s[3*e+8],n=new Float32Array(t+2);h.push(n);for(let t=0;t<2;t++)n[t]=s[3*e+8+t+1];for(let e=0;e<t;e++)n[e+2]=n[e]+_[o++]}return{areContours:d,thickness:f,outlines:h,width:l,height:u}}catch(e){O(`decompressSignature: ${e}`);return null}}}class jr extends wr{constructor(){super();super.updateProperties({fill:V._defaultLineColor,"stroke-width":0})}clone(){let e=new jr;e.updateAll(this);return e}}class Mr extends Dr{constructor(e){super(e);super.updateProperties({stroke:V._defaultLineColor,"stroke-width":1})}clone(){let e=new Mr(this._viewParameters);e.updateAll(this);return e}}class Nr extends ${#e=!1;#t=null;#n=null;#r=null;static _type=`signature`;static _editorType=y.SIGNATURE;static _defaultDrawingOptions=null;constructor(e){super({...e,mustBeCommitted:!0,name:`signatureEditor`});this._willKeepAspectRatio=!0;this.#n=e.signatureData||null;this.#t=null;this.defaultL10nId=`pdfjs-editor-signature-editor1`}static initialize(e,t){V.initialize(e,t);this._defaultDrawingOptions=new jr;this._defaultDrawnSignatureOptions=new Mr(t.viewParameters)}static getDefaultDrawingOptions(e){let t=this._defaultDrawingOptions.clone();t.updateProperties(e);return t}static get supportMultipleDrawings(){return!1}static get typesMap(){return j(this,`typesMap`,new Map)}static get isDrawer(){return!1}get telemetryFinalData(){return{type:`signature`,hasDescription:!!this.#t}}static computeTelemetryFinalData(e){let t=e.get(`hasDescription`);return{hasAltText:t.get(!0)??0,hasNoAltText:t.get(!1)??0}}get isResizable(){return!0}onScaleChanging(){this._drawId!==null&&super.onScaleChanging()}render(){if(this.div)return this.div;let e,t,{_isCopy:n}=this;if(n){this._isCopy=!1;e=this.x;t=this.y}super.render();if(this._drawId===null){if(this.#n){let{lines:e,mustSmooth:t,areContours:n,description:r,uuid:i,heightInPage:a}=this.#n,{rawDims:{pageWidth:o,pageHeight:s},rotation:c}=this.parent.viewport,l=Ar.processDrawnLines({lines:e,pageWidth:o,pageHeight:s,rotation:c,innerMargin:Nr._INNER_MARGIN,mustSmooth:t,areContours:n});this.addSignature(l,a,r,i)}else{this.div.setAttribute(`data-l10n-args`,JSON.stringify({description:``}));this.div.hidden=!0;this._uiManager.getSignature(this)}}else this.div.setAttribute(`data-l10n-args`,JSON.stringify({description:this.#t||``}));if(n){this._isCopy=!0;this._moveAfterPaste(e,t)}return this.div}setUuid(e){this.#r=e;this.addEditToolbar()}getUuid(){return this.#r}get description(){return this.#t}set description(e){this.#t=e;if(this.div){this.div.setAttribute(`data-l10n-args`,JSON.stringify({description:e}));super.addEditToolbar().then(t=>{t?.updateEditSignatureButton(e)})}}getSignaturePreview(){let{newCurves:e,areContours:t,thickness:n,width:r,height:i}=this.#n,a=Math.max(r,i);return{areContours:t,outline:Ar.processDrawnLines({lines:{curves:e.map(e=>({points:e})),thickness:n,width:r,height:i},pageWidth:a,pageHeight:a,rotation:0,innerMargin:0,mustSmooth:!1,areContours:t}).outline}}get toolbarButtons(){return this._uiManager.signatureManager?[[`editSignature`,this._uiManager.signatureManager]]:super.toolbarButtons}addSignature(e,t,n,r){let{x:i,y:a}=this,{outline:o}=this.#n=e;this.#e=o instanceof kr;this.description=n;let s;if(this.#e)s=Nr.getDefaultDrawingOptions();else{s=Nr._defaultDrawnSignatureOptions.clone();s.updateProperties({"stroke-width":o.thickness})}this._addOutlines({drawOutlines:o,drawingOptions:s});let[,c]=this.pageDimensions,l=t/c;l=l>=1?.5:l;this.width*=l/this.height;if(this.width>=1){l*=.9/this.width;this.width=.9}this.height=l;this.setDims();this.x=i;this.y=a;this.center();this._onResized();this.onScaleChanging();this.rotate();this._uiManager.addToAnnotationStorage(this);this.setUuid(r);this._reportTelemetry({action:`pdfjs.signature.inserted`,data:{hasBeenSaved:!!r,hasDescription:!!n}});this.div.hidden=!1}getFromImage(e){let{rawDims:{pageWidth:t,pageHeight:n},rotation:r}=this.parent.viewport;return Ar.process(e,t,n,r,Nr._INNER_MARGIN)}getFromText(e,t){let{rawDims:{pageWidth:n,pageHeight:r},rotation:i}=this.parent.viewport;return Ar.extractContoursFromText(e,t,n,r,i,Nr._INNER_MARGIN)}getDrawnSignature(e){let{rawDims:{pageWidth:t,pageHeight:n},rotation:r}=this.parent.viewport;return Ar.processDrawnLines({lines:e,pageWidth:t,pageHeight:n,rotation:r,innerMargin:Nr._INNER_MARGIN,mustSmooth:!1,areContours:!1})}createDrawingOptions({areContours:e,thickness:t}){if(e)this._drawingOptions=Nr.getDefaultDrawingOptions();else{this._drawingOptions=Nr._defaultDrawnSignatureOptions.clone();this._drawingOptions.updateProperties({"stroke-width":t})}}serialize(e=!1){if(this.isEmpty())return null;let{lines:t,points:n}=this.serializeDraw(e),{_drawingOptions:{"stroke-width":r}}=this,i=Object.assign(super.serialize(e),{isSignature:!0,areContours:this.#e,color:[0,0,0],thickness:this.#e?0:r});this.addComment(i);if(e){i.paths={lines:t,points:n};i.uuid=this.#r;i.isCopy=!0}else i.lines=t;this.#t&&(i.accessibilityData={type:`Figure`,alt:this.#t});return i}static deserializeDraw(e,t,n,r,i,a){return a.areContours?kr.deserialize(e,t,n,r,i,a):Er.deserialize(e,t,n,r,i,a)}static async deserialize(e,t,n){let r=await super.deserialize(e,t,n);r.#e=e.areContours;r.description=e.accessibilityData?.alt||``;r.#r=e.uuid;return r}}class Pr extends V{#e=null;#t=null;#n=null;#r=null;#i=null;#a=``;#o=null;#s=!1;#c=null;#l=!1;#u=!1;static _type=`stamp`;static _editorType=y.STAMP;constructor(e){super({...e,name:`stampEditor`});this.#r=e.bitmapUrl;this.#i=e.bitmapFile;this.defaultL10nId=`pdfjs-editor-stamp-editor`}static initialize(e,t){V.initialize(e,t)}static isHandlingMimeForPasting(e){return ke.includes(e)}static paste(e,t){t.pasteEditor({mode:y.STAMP},{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1);super.altTextFinish()}get telemetryFinalData(){return{type:`stamp`,hasAltText:!!this.altTextData?.altText}}static computeTelemetryFinalData(e){let t=e.get(`hasAltText`);return{hasAltText:t.get(!0)??0,hasNoAltText:t.get(!1)??0}}#d(e,t=!1){if(e){this.#e=e.bitmap;if(!t){this.#t=e.id;this.#l=e.isSvg}e.file&&(this.#a=e.file.name);this.#m()}else this.remove()}#f(){this.#n=null;this._uiManager.enableWaiting(!1);if(this.#o){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#e)this.addEditToolbar().then(()=>{this._editToolbar.hide();this._uiManager.editAltText(this,!0)});else{if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#e){this._reportTelemetry({action:`pdfjs.image.image_added`,data:{alt_text_modal:!1,alt_text_type:`empty`}});try{this.mlGuessAltText()}catch{}}this.div.focus()}}}async mlGuessAltText(e=null,t=!0){if(this.hasAltTextData())return null;let{mlManager:n}=this._uiManager;if(!n)throw Error(`No ML.`);if(!await n.isEnabledFor(`altText`))throw Error(`ML isn't enabled for alt text.`);let{data:r,width:i,height:a}=e||this.copyCanvas(null,null,!0).imageData,o=await n.guess({name:`altText`,request:{data:r,width:i,height:a,channels:r.length/(i*a)}});if(!o)throw Error(`No response from the AI service.`);if(o.error)throw Error(`Error from the AI service.`);if(o.cancel)return null;if(!o.output)throw Error(`No valid response from the AI service.`);let s=o.output;await this.setGuessedAltText(s);t&&!this.hasAltTextData()&&(this.altTextData={alt:s,decorative:!1});return s}#p(){if(this.#t){this._uiManager.enableWaiting(!0);this._uiManager.imageManager.getFromId(this.#t).then(e=>this.#d(e,!0)).finally(()=>this.#f());return}if(this.#r){let e=this.#r;this.#r=null;this._uiManager.enableWaiting(!0);this.#n=this._uiManager.imageManager.getFromUrl(e).then(e=>this.#d(e)).finally(()=>this.#f());return}if(this.#i){let e=this.#i;this.#i=null;this._uiManager.enableWaiting(!0);this.#n=this._uiManager.imageManager.getFromFile(e).then(e=>this.#d(e)).finally(()=>this.#f());return}let e=document.createElement(`input`);e.type=`file`;e.accept=ke.join(`,`);let t=this._uiManager._signal;this.#n=new Promise(n=>{e.addEventListener(`change`,async()=>{if(e.files&&e.files.length!==0){this._uiManager.enableWaiting(!0);let t=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:`pdfjs.image.image_selected`,data:{alt_text_modal:this._uiManager.useNewAltTextFlow}});this.#d(t)}else this.remove();n()},{signal:t});e.addEventListener(`cancel`,()=>{this.remove();n()},{signal:t})}).finally(()=>this.#f());e.click()}remove(){if(this.#t){this.#e=null;this._uiManager.imageManager.deleteId(this.#t);this.#o?.remove();this.#o=null;if(this.#c){clearTimeout(this.#c);this.#c=null}}super.remove()}rebuild(){if(this.parent){super.rebuild();if(this.div!==null){this.#t&&this.#o===null&&this.#p();this.isAttachedToDOM||this.parent.add(this)}}else this.#t&&this.#p()}onceAdded(e){this._isDraggable=!0;e&&this.div.focus()}isEmpty(){return!(this.#n||this.#e||this.#r||this.#i||this.#t||this.#s)}get toolbarButtons(){return[[`altText`,this.createAltText()]]}get isResizable(){return!0}render(){if(this.div)return this.div;let e,t;if(this._isCopy){e=this.x;t=this.y}super.render();this.div.hidden=!0;this.createAltText();this.#s||(this.#e?this.#m():this.#p());this._isCopy&&this._moveAfterPaste(e,t);this._uiManager.addShouldRescale(this);return this.div}setCanvas(e,t){let{id:n,bitmap:r}=this._uiManager.imageManager.getFromCanvas(e,t);t.remove();if(n&&this._uiManager.imageManager.isValidId(n)){this.#t=n;r&&(this.#e=r);this.#s=!1;this.#m()}}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;this.#c!==null&&clearTimeout(this.#c);this.#c=setTimeout(()=>{this.#c=null;this.#g()},200)}#m(){let{div:e}=this,{width:t,height:n}=this.#e,[r,i]=this.pageDimensions,a=.75;if(this.width){t=this.width*r;n=this.height*i}else if(t>a*r||n>a*i){let e=Math.min(a*r/t,a*i/n);t*=e;n*=e}this._uiManager.enableWaiting(!1);let o=this.#o=document.createElement(`canvas`);o.setAttribute(`role`,`img`);this.addContainer(o);this.width=t/r;this.height=n/i;this.setDims();this._initialOptions?.isCentered?this.center():this.fixAndSetPosition();this._initialOptions=null;this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&!this.annotationElementId||(e.hidden=!1);this.#g();if(!this.#u){this.parent.addUndoableEditor(this);this.#u=!0}this._reportTelemetry({action:`inserted_image`});this.#a&&this.div.setAttribute(`aria-description`,this.#a);this.annotationElementId||this._uiManager.a11yAlert(V._l10nAlert.stamp)}copyCanvas(e,t,n=!1){e||=224;let{width:r,height:i}=this.#e,a=new Oe,o=this.#e,s=r,c=i,l=null;if(t){if(r>t||i>t){let e=Math.min(t/r,t/i);s=Math.floor(r*e);c=Math.floor(i*e)}l=document.createElement(`canvas`);let e=l.width=Math.ceil(s*a.sx),n=l.height=Math.ceil(c*a.sy);this.#l||(o=this.#h(e,n));let u=l.getContext(`2d`);u.filter=this._uiManager.hcmFilter;let d=`white`,f=`#cfcfd8`;if(this._uiManager.hcmFilter!==`none`)f=`black`;else if(Ae.isDarkMode){d=`#8f8f9d`;f=`#42414d`}let p=15*a.sx,m=15*a.sy,h=new OffscreenCanvas(2*p,2*m),g=h.getContext(`2d`);g.fillStyle=d;g.fillRect(0,0,2*p,2*m);g.fillStyle=f;g.fillRect(0,0,p,m);g.fillRect(p,m,p,m);u.fillStyle=u.createPattern(h,`repeat`);u.fillRect(0,0,e,n);u.drawImage(o,0,0,o.width,o.height,0,0,e,n)}let u=null;if(n){let t,n;if(a.symmetric&&o.width<e&&o.height<e){t=o.width;n=o.height}else{o=this.#e;if(r>e||i>e){let a=Math.min(e/r,e/i);t=Math.floor(r*a);n=Math.floor(i*a);this.#l||(o=this.#h(t,n))}}let s=new OffscreenCanvas(t,n).getContext(`2d`,{willReadFrequently:!0});s.drawImage(o,0,0,o.width,o.height,0,0,t,n);u={width:t,height:n,data:s.getImageData(0,0,t,n).data}}return{canvas:l,width:s,height:c,imageData:u}}#h(e,t){let{width:n,height:r}=this.#e,i=n,a=r,o=this.#e;for(;i>2*e||a>2*t;){let n=i,r=a;i>2*e&&(i=Math.ceil(i/2));a>2*t&&(a=Math.ceil(a/2));let s=new OffscreenCanvas(i,a);s.getContext(`2d`).drawImage(o,0,0,n,r,0,0,i,a);o=s.transferToImageBitmap()}return o}#g(){let[e,t]=this.parentDimensions,{width:n,height:r}=this,i=new Oe,a=Math.ceil(n*e*i.sx),o=Math.ceil(r*t*i.sy),s=this.#o;if(!s||s.width===a&&s.height===o)return;s.width=a;s.height=o;let c=this.#l?this.#e:this.#h(a,o),l=s.getContext(`2d`);l.filter=this._uiManager.hcmFilter;l.drawImage(c,0,0,c.width,c.height,0,0,a,o)}#_(e){if(e){if(this.#l){let e=this._uiManager.imageManager.getSvgUrl(this.#t);if(e)return e}let e=document.createElement(`canvas`);({width:e.width,height:e.height}=this.#e);e.getContext(`2d`).drawImage(this.#e,0,0);return e.toDataURL()}if(this.#l){let[e,t]=this.pageDimensions,n=Math.round(this.width*e*he.PDF_TO_CSS_UNITS),r=Math.round(this.height*t*he.PDF_TO_CSS_UNITS),i=new OffscreenCanvas(n,r);i.getContext(`2d`).drawImage(this.#e,0,0,this.#e.width,this.#e.height,0,0,n,r);return i.transferToImageBitmap()}return structuredClone(this.#e)}static async deserialize(e,t,n){let r=null,i=!1;if(e instanceof gr){let{data:{rect:a,rotation:o,id:s,structParent:c,popupRef:l,richText:u,contentsObj:d,creationDate:f,modificationDate:p},container:m,parent:{page:{pageNumber:h}},canvas:g}=e,v,b;if(g){delete e.canvas;({id:v,bitmap:b}=n.imageManager.getFromCanvas(m.id,g));g.remove()}else{i=!0;e._hasNoCanvas=!0}let x=(await t._structTree.getAriaAttributes(`${_}${s}`))?.get(`aria-label`)||``;r=e={annotationType:y.STAMP,bitmapId:v,bitmap:b,pageIndex:h-1,rect:a.slice(0),rotation:o,annotationElementId:s,id:s,deleted:!1,accessibilityData:{decorative:!1,altText:x},isSvg:!1,structParent:c,popupRef:l,richText:u,comment:d?.str||null,creationDate:f,modificationDate:p}}let a=await super.deserialize(e,t,n),{rect:o,bitmap:s,bitmapUrl:c,bitmapId:l,isSvg:u,accessibilityData:d}=e;if(i){n.addMissingCanvas(e.id,a);a.#s=!0}else if(l&&n.imageManager.isValidId(l)){a.#t=l;s&&(a.#e=s)}else a.#r=c;a.#l=u;let[f,p]=a.pageDimensions;a.width=(o[2]-o[0])/f;a.height=(o[3]-o[1])/p;d&&(a.altTextData=d);a._initialData=r;e.comment&&a.setCommentData(e);a.#u=!!r;return a}serialize(e=!1,t=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let n=Object.assign(super.serialize(e),{bitmapId:this.#t,isSvg:this.#l});this.addComment(n);if(e){n.bitmapUrl=this.#_(!0);n.accessibilityData=this.serializeAltText(!0);n.isCopy=!0;return n}let{decorative:r,altText:i}=this.serializeAltText(!1);!r&&i&&(n.accessibilityData={type:`Figure`,alt:i});if(this.annotationElementId){let e=this.#v(n);if(e.isSame)return null;e.isSameAltText?delete n.accessibilityData:n.accessibilityData.structParent=this._initialData.structParent??-1;n.id=this.annotationElementId;delete n.bitmapId;return n}if(t===null)return n;t.stamps||=new Map;let a=this.#l?(n.rect[2]-n.rect[0])*(n.rect[3]-n.rect[1]):null;if(t.stamps.has(this.#t)){if(this.#l){let e=t.stamps.get(this.#t);if(a>e.area){e.area=a;e.serialized.bitmap.close();e.serialized.bitmap=this.#_(!1)}}}else{t.stamps.set(this.#t,{area:a,serialized:n});n.bitmap=this.#_(!1)}return n}#v(e){let{pageIndex:t,accessibilityData:{altText:n}}=this._initialData,r=e.pageIndex===t,i=(e.accessibilityData?.alt||``)===n;return{isSame:!this.hasEditedComment&&!this._hasBeenMoved&&!this._hasBeenResized&&r&&i,isSameAltText:i}}renderAnnotationElement(e){if(this.deleted){e.hide();return null}e.updateEdited({rect:this.getPDFRect(),popup:this.comment});return null}}class Fr{#e;#t=!1;#n=null;#r=null;#i=null;#a=new Map;#o=!1;#s=!1;#c=!1;#l=null;#u=null;#d=null;#f=null;#p=null;#m=-1;#h;static _initialized=!1;static#g=new Map([X,Or,Pr,Q,Nr].map(e=>[e._editorType,e]));constructor({uiManager:e,pageIndex:t,div:n,structTreeLayer:r,accessibilityManager:i,annotationLayer:a,drawLayer:o,textLayer:s,viewport:c,l10n:l}){let u=[...Fr.#g.values()];if(!Fr._initialized){Fr._initialized=!0;for(let t of u)t.initialize(l,e)}e.registerEditorTypes(u);this.#h=e;this.pageIndex=t;this.div=n;this.#e=i;this.#n=a;this.viewport=c;this.#d=s;this.drawLayer=o;this._structTree=r;this.#h.addLayer(this)}get isEmpty(){return this.#a.size===0}get isInvisible(){return this.isEmpty&&this.#h.getMode()===y.NONE}updateToolbar(e){this.#h.updateToolbar(e)}updateMode(e=this.#h.getMode()){this.#S();switch(e){case y.NONE:this.div.classList.toggle(`nonEditing`,!0);this.disableTextSelection();this.togglePointerEvents(!1);this.toggleAnnotationLayerPointerEvents(!0);this.disableClick();return;case y.INK:this.disableTextSelection();this.togglePointerEvents(!0);this.enableClick();break;case y.HIGHLIGHT:this.enableTextSelection();this.togglePointerEvents(!1);this.disableClick();break;default:this.disableTextSelection();this.togglePointerEvents(!0);this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);let{classList:t}=this.div;t.toggle(`nonEditing`,!1);if(e===y.POPUP)t.toggle(`commentEditing`,!0);else{t.toggle(`commentEditing`,!1);for(let n of Fr.#g.values())t.toggle(`${n._type}Editing`,e===n._editorType)}this.div.hidden=!1}hasTextLayer(e){return e===this.#d?.div}setEditingState(e){this.#h.setEditingState(e)}addCommands(e){this.#h.addCommands(e)}cleanUndoStack(e){this.#h.cleanUndoStack(e)}toggleDrawing(e=!1){this.div.classList.toggle(`drawing`,!e)}togglePointerEvents(e=!1){this.div.classList.toggle(`disabled`,!e)}toggleAnnotationLayerPointerEvents(e=!1){this.#n?.togglePointerEvents(e)}get#_(){return this.#a.size===0?this.#h.getEditors(this.pageIndex):this.#a.values()}async enable(){this.#c=!0;this.div.tabIndex=0;this.togglePointerEvents(!0);this.div.classList.toggle(`nonEditing`,!1);this.#p?.abort();this.#p=null;let e=new Set;for(let t of this.#_){t.enableEditing();t.show(!0);if(t.annotationElementId){this.#h.removeChangedExistingAnnotation(t);e.add(t.annotationElementId)}}let t=this.#n;if(t)for(let n of t.getEditableAnnotations()){n.hide();if(this.#h.isDeletedAnnotationElement(n.data.id))continue;if(e.has(n.data.id))continue;let t=await this.deserialize(n);if(t){this.addOrRebuild(t);t.enableEditing()}}this.#c=!1;this.#h._eventBus.dispatch(`editorsrendered`,{source:this,pageNumber:this.pageIndex+1})}disable(){this.#s=!0;this.div.tabIndex=-1;this.togglePointerEvents(!1);this.div.classList.toggle(`nonEditing`,!0);if(this.#d&&!this.#p){this.#p=new AbortController;let e=this.#h.combinedSignal(this.#p);this.#d.div.addEventListener(`pointerdown`,e=>{let{clientX:t,clientY:n,timeStamp:r}=e;if(r-this.#m>500){this.#m=r;return}this.#m=-1;let{classList:i}=this.div;i.toggle(`getElements`,!0);let a=document.elementsFromPoint(t,n);i.toggle(`getElements`,!1);if(!this.div.contains(a[0]))return;let o,s=RegExp(`^${v}[0-9]+$`);for(let e of a)if(s.test(e.id)){o=e.id;break}if(!o)return;let c=this.#a.get(o);if(c?.annotationElementId===null){R(e);c.dblclick(e)}},{signal:e,capture:!0})}let e=this.#n,t=[];if(e){let n=new Map,r=new Map;for(let e of this.#_){e.disableEditing();if(e.annotationElementId){if(e.serialize()===null){r.set(e.annotationElementId,e);this.getEditableAnnotation(e.annotationElementId)?.show();e.remove()}else n.set(e.annotationElementId,e)}else t.push(e)}for(let t of e.getEditableAnnotations()){let{id:e}=t.data;if(this.#h.isDeletedAnnotationElement(e)){t.updateEdited({deleted:!0});continue}let i=r.get(e);if(i){i.resetAnnotationElement(t);i.show(!1);t.show()}else{i=n.get(e);if(i){this.#h.addChangedExistingAnnotation(i);i.renderAnnotationElement(t)&&i.show(!1)}t.show()}}}this.#S();this.isEmpty&&(this.div.hidden=!0);let{classList:n}=this.div;for(let e of Fr.#g.values())n.remove(`${e._type}Editing`);this.disableTextSelection();this.toggleAnnotationLayerPointerEvents(!0);e?.updateFakeAnnotations(t);this.#s=!1}getEditableAnnotation(e){return this.#n?.getEditableAnnotation(e)||null}setActiveEditor(e){this.#h.getActive()!==e&&this.#h.setActiveEditor(e)}enableTextSelection(){this.div.tabIndex=-1;if(this.#d?.div&&!this.#f){this.#f=new AbortController;let e=this.#h.combinedSignal(this.#f);this.#d.div.addEventListener(`pointerdown`,this.#v.bind(this),{signal:e});this.#d.div.classList.add(`highlighting`)}}disableTextSelection(){this.div.tabIndex=0;if(this.#d?.div&&this.#f){this.#f.abort();this.#f=null;this.#d.div.classList.remove(`highlighting`)}}#v(e){this.#h.unselectAll();let{target:t}=e;if(t===this.#d.div||(t.getAttribute(`role`)===`img`||t.classList.contains(`endOfContent`)||t.classList.contains(`textLayerImages`)||t.classList.contains(`textLayerImagePlaceholder`))&&this.#d.div.contains(t)){let{isMac:t}=N.platform;if(e.button!==0||e.ctrlKey&&t)return;this.#h.showAllEditors(`highlight`,!0,!0);this.#d.div.classList.add(`free`);this.toggleDrawing();Q.startHighlighting(this,this.#h.direction===`ltr`,{target:this.#d.div,x:e.x,y:e.y});this.#d.div.addEventListener(`pointerup`,()=>{this.#d.div.classList.remove(`free`);this.toggleDrawing(!0)},{once:!0,signal:this.#h._signal});e.preventDefault()}}enableClick(){if(this.#r)return;this.#r=new AbortController;let e=this.#h.combinedSignal(this.#r);this.div.addEventListener(`pointerdown`,this.pointerdown.bind(this),{signal:e});let t=this.pointerup.bind(this);this.div.addEventListener(`pointerup`,t,{signal:e});this.div.addEventListener(`pointercancel`,t,{signal:e})}disableClick(){this.#r?.abort();this.#r=null}attach(e){this.#a.set(e.id,e);let{annotationElementId:t}=e;t&&this.#h.isDeletedAnnotationElement(t)&&this.#h.removeDeletedAnnotationElement(e)}detach(e){this.#a.delete(e.id);this.#e?.removePointerInTextLayer(e.contentDiv);!this.#s&&e.annotationElementId&&this.#h.addDeletedAnnotationElement(e)}remove(e){this.detach(e);this.#h.removeEditor(e);e.div.remove();e.isAttachedToDOM=!1}changeParent(e){if(e.parent!==this){if(e.parent&&e.annotationElementId){this.#h.addDeletedAnnotationElement(e);V.deleteAnnotationElement(e);e.annotationElementId=null}this.attach(e);e.parent?.detach(e);e.setParent(this);if(e.div&&e.isAttachedToDOM){e.div.remove();this.div.append(e.div)}}}add(e){if(e.parent!==this||!e.isAttachedToDOM){this.changeParent(e);this.#h.addEditor(e);this.attach(e);if(!e.isAttachedToDOM){let t=e.render();this.div.append(t);e.isAttachedToDOM=!0}e.fixAndSetPosition();e.onceAdded(!this.#c);this.#h.addToAnnotationStorage(e);e._reportTelemetry(e.telemetryInitialData)}}moveEditorInDOM(e){if(!e.isAttachedToDOM)return;let{activeElement:t}=document;if(e.div.contains(t)&&!this.#i){e._focusEventsAllowed=!1;this.#i=setTimeout(()=>{this.#i=null;if(e.div.contains(document.activeElement))e._focusEventsAllowed=!0;else{e.div.addEventListener(`focusin`,()=>{e._focusEventsAllowed=!0},{once:!0,signal:this.#h._signal});t.focus()}},0)}e._structTreeParentId=this.#e?.moveElementInDOM(this.div,e.div,e.contentDiv,!0)}addOrRebuild(e){if(e.needsToBeRebuilt()){e.parent||=this;e.rebuild();e.show()}else this.add(e)}addUndoableEditor(e){this.addCommands({cmd:()=>e._uiManager.rebuild(e),undo:()=>{e.remove()},mustExec:!1})}getEditorByUID(e){for(let t of this.#a.values())if(t.uid===e)return t;return null}get#y(){return Fr.#g.get(this.#h.getMode())}combinedSignal(e){return this.#h.combinedSignal(e)}#b(e){let t=this.#y;return t?new t.prototype.constructor(e):null}canCreateNewEmptyEditor(){return this.#y?.canCreateNewEmptyEditor()}async pasteEditor(e,t){this.updateToolbar(e);await this.#h.updateMode(e.mode);let{offsetX:n,offsetY:r}=this.#x(),i=this.#h.getId(),a=this.#b({parent:this,id:i,x:n,y:r,uiManager:this.#h,isCentered:!0,...t});a&&this.add(a)}async deserialize(e){return await Fr.#g.get(e.annotationType??e.annotationEditorType)?.deserialize(e,this,this.#h)||null}createAndAddNewEditor(e,t,n={}){let r=this.#h.getId(),i=this.#b({parent:this,id:r,x:e.offsetX,y:e.offsetY,uiManager:this.#h,isCentered:t,...n});i&&this.add(i);return i}get boundingClientRect(){return this.div.getBoundingClientRect()}#x(){let{x:e,y:t,width:n,height:r}=this.boundingClientRect,i=Math.max(0,e),a=Math.max(0,t),o=(i+Math.min(window.innerWidth,e+n))/2-e,s=(a+Math.min(window.innerHeight,t+r))/2-t,[c,l]=this.viewport.rotation%180==0?[o,s]:[s,o];return{offsetX:c,offsetY:l}}addNewEditor(e={}){this.createAndAddNewEditor(this.#x(),!0,e)}setSelected(e){this.#h.setSelected(e)}toggleSelected(e){this.#h.toggleSelected(e)}unselect(e){this.#h.unselect(e)}pointerup(e){let{isMac:t}=N.platform;if(e.button!==0||e.ctrlKey&&t)return;if(e.target!==this.div)return;if(!this.#o)return;this.#o=!1;if(this.#y?.isDrawer&&this.#y.supportMultipleDrawings)return;if(!this.#t){this.#t=!0;return}let n=this.#h.getMode();n!==y.STAMP&&n!==y.POPUP&&n!==y.SIGNATURE?this.createAndAddNewEditor(e,!1):this.#h.unselectAll()}pointerdown(e){this.#h.getMode()===y.HIGHLIGHT&&this.enableTextSelection();if(this.#o){this.#o=!1;return}let{isMac:t}=N.platform;if(e.button!==0||e.ctrlKey&&t)return;if(e.target!==this.div)return;this.#o=!0;if(this.#y?.isDrawer){this.startDrawingSession(e);return}let n=this.#h.getActive();this.#t=!n||n.isEmpty()}startDrawingSession(e){this.div.focus({preventScroll:!0});if(this.#l){this.#y.startDrawing(this,this.#h,!1,e);return}this.#h.setCurrentDrawingSession(this);this.#l=new AbortController;let t=this.#h.combinedSignal(this.#l);this.div.addEventListener(`blur`,({relatedTarget:e})=>{if(e&&!this.div.contains(e)){this.#u=null;this.commitOrRemove()}},{signal:t});this.#y.startDrawing(this,this.#h,!1,e)}pause(e){if(e){let{activeElement:e}=document;this.div.contains(e)&&(this.#u=e);return}this.#u&&setTimeout(()=>{this.#u?.focus();this.#u=null},0)}endDrawingSession(e=!1){if(!this.#l)return null;this.#h.setCurrentDrawingSession(null);this.#l.abort();this.#l=null;this.#u=null;return this.#y.endDrawing(e)}findNewParent(e,t,n){let r=this.#h.findParent(t,n);if(r===null||r===this)return!1;r.changeParent(e);return!0}commitOrRemove(){if(this.#l){this.endDrawingSession();return!0}return!1}onScaleChanging(){this.#l&&this.#y.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove();if(this.#h.getActive()?.parent===this){this.#h.commitOrRemove();this.#h.setActiveEditor(null)}if(this.#i){clearTimeout(this.#i);this.#i=null}for(let e of this.#a.values()){this.#e?.removePointerInTextLayer(e.contentDiv);e.setParent(null);e.isAttachedToDOM=!1;e.div.remove()}this.div=null;this.#a.clear();this.#h.removeLayer(this)}#S(){for(let e of this.#a.values())e.isEmpty()&&e.remove()}async render({viewport:e}){this.viewport=e;De(this.div,e);for(let e of this.#h.getEditors(this.pageIndex)){this.add(e);e.rebuild()}await this.#h.findClonesForPage(this);this.div.hidden=this.isEmpty;this.updateMode()}update({viewport:e}){this.#h.commitOrRemove();this.#S();let t=this.viewport.rotation,n=e.rotation;this.viewport=e;De(this.div,{rotation:n});if(t!==n)for(let e of this.#a.values())e.rotate(n)}get pageDimensions(){let{pageWidth:e,pageHeight:t}=this.viewport.rawDims;return[e,t]}get scale(){return this.#h.viewParameters.realScale}}globalThis._pdfjsTestingUtils={HighlightOutliner:br};const Ir={fonts:globalThis.fonts,createElement(e){if(e.toLowerCase()===`canvas`)return new OffscreenCanvas(1,1);return null}};class Lr{constructor(){this._pdfDocument=null;this._page=null;this._geospatialMetadata=null;this._baseViewport=null;this._inverseBaseViewport=null;this._pdfWorker=null;this._pdfWorkerBlobUrl=null}async loadPDF(n,s={}){c()||await l();r(s);let[{data:u},d]=await Promise.all([t(n.url,{responseType:`array-buffer`,signal:s?.signal}),this._getPDFWorker(s)]),f=Yn({data:u,wasmUrl:e(`esri/libs/pdfjs/wasm/`),ownerDocument:Ir,enableHWA:!0,useWorkerFetch:!0,worker:d});this._pdfDocument=await f.promise;r(s);this._page=await this._pdfDocument.getPage(n.page);r(s);this._geospatialMetadata=await this._page.getGeospatialPDFMetadata();r(s);this._baseViewport=this._page.getViewport({scale:1});this._inverseBaseViewport=i();o(this._inverseBaseViewport,a(...this._baseViewport.transform));return{geospatialMetadata:this._geospatialMetadata}}destroy(){this._page?.cleanup?.();this._page=null;this._pdfDocument?.cleanup();this._pdfDocument=null;this._geospatialMetadata=null;this._baseViewport=null;this._inverseBaseViewport=null;this._pdfWorker?.destroy();this._pdfWorker=null;if(this._pdfWorkerBlobUrl){URL.revokeObjectURL(this._pdfWorkerBlobUrl);this._pdfWorkerBlobUrl=null}}async renderPDF(e,t={}){if(!this._page||!this._baseViewport||!this._inverseBaseViewport)throw new n(`geospatial-pdf-layer-worker:not-loaded`,`PDF not loaded`);r(t);let{width:i,height:a,sourceExtentAsJSON:o,currentRing:c,ctm:l}=e,d=s.fromJSON(o),f=await u(d,i,a,l,this._page,this._baseViewport,this._inverseBaseViewport,c,t);r(t);return Rr(f,i,a)}async _getPDFWorker(n={}){if(this._pdfWorker)return this._pdfWorker;let r=e(`esri/libs/pdfjs/pdf.worker.mjs`),i=(await t(r,{responseType:`blob`,authMode:`anonymous`,signal:n.signal})).data,a=i.type===`application/javascript`||i.type===`text/javascript`?i:new Blob([i],{type:`application/javascript`}),o=URL.createObjectURL(a);try{let e=new Worker(o,{type:`module`,name:`geospatial-pdf-pdfjs-worker`}),t=new q({port:e});await t.promise;this._pdfWorker=t;this._pdfWorkerBlobUrl=o;return t}catch(e){URL.revokeObjectURL(o);throw e}}}function Rr(e,t,r){let i=e.getContext(`2d`);if(!i)throw new n(`geospatial-pdf-raster:canvas`,`Failed to create canvas context.`);let a=i.getImageData(0,0,t,r).data,o=t*r,s=new Uint8Array(o),c=new Uint8Array(o),l=new Uint8Array(o),u=new Uint8Array(o);for(let e=0,t=0;e<o;e++,t+=4){s[e]=a[t];c[e]=a[t+1];l[e]=a[t+2];u[e]=a[t+3]}return{width:t,height:r,red:s,green:c,blue:l,mask:u}}export{Lr as default};
|
|
57
|
+
`)){let n=document.createElement(`div`);n.append(e?document.createTextNode(e):document.createElement(`br`));t.append(n)}e.updateEdited({rect:this.getPDFRect(),popup:this._uiManager.hasCommentManager()||this.hasEditedComment?this.comment:{text:this.#e}});return t}resetAnnotationElement(e){super.resetAnnotationElement(e);e.resetEdited()}}class Z{static PRECISION=1e-4;toSVGPath(){k("Abstract method `toSVGPath` must be implemented.")}get box(){k("Abstract getter `box` must be implemented.")}serialize(e,t){k("Abstract method `serialize` must be implemented.")}static _rescale(e,t,n,r,i,a){a||=new Float32Array(e.length);for(let o=0,s=e.length;o<s;o+=2){a[o]=t+e[o]*r;a[o+1]=n+e[o+1]*i}return a}static _rescaleAndSwap(e,t,n,r,i,a){a||=new Float32Array(e.length);for(let o=0,s=e.length;o<s;o+=2){a[o]=t+e[o+1]*r;a[o+1]=n+e[o]*i}return a}static _translate(e,t,n,r){r||=new Float32Array(e.length);for(let i=0,a=e.length;i<a;i+=2){r[i]=t+e[i];r[i+1]=n+e[i+1]}return r}static svgRound(e){return Math.round(1e4*e)}static _normalizePoint(e,t,n,r,i){switch(i){case 90:return[1-t/n,e/r];case 180:return[1-e/n,1-t/r];case 270:return[t/n,1-e/r];default:return[e/n,t/r]}}static _normalizePagePoint(e,t,n){switch(n){case 90:return[1-t,e];case 180:return[1-e,1-t];case 270:return[t,1-e];default:return[e,t]}}static createBezierPoints(e,t,n,r,i,a){return[(e+5*n)/6,(t+5*r)/6,(5*n+i)/6,(5*r+a)/6,(n+i)/2,(r+a)/2]}}class vr{#e;#t=[];#n;#r;#i=[];#a=new Float32Array(18);#o;#s;#c;#l;#u;#d;#f=[];static#p=8;static#m=2;static#h=vr.#p+vr.#m;constructor({x:e,y:t},n,r,i,a,o=0){this.#e=n;this.#d=i*r;this.#r=a;this.#a.set([NaN,NaN,NaN,NaN,e,t],6);this.#n=o;this.#l=vr.#p*r;this.#c=vr.#h*r;this.#u=r;this.#f.push(e,t)}isEmpty(){return isNaN(this.#a[8])}#g(){let e=this.#a.subarray(4,6),t=this.#a.subarray(16,18),[n,r,i,a]=this.#e;return[(this.#o+(e[0]-t[0])/2-n)/i,(this.#s+(e[1]-t[1])/2-r)/a,(this.#o+(t[0]-e[0])/2-n)/i,(this.#s+(t[1]-e[1])/2-r)/a]}add({x:e,y:t}){this.#o=e;this.#s=t;let[n,r,i,a]=this.#e,[o,s,c,l]=this.#a.subarray(8,12),u=e-c,d=t-l,f=Math.hypot(u,d);if(f<this.#c)return!1;let p=f-this.#l,m=p/f,h=m*u,g=m*d,_=o,v=s;o=c;s=l;c+=h;l+=g;this.#f?.push(e,t);let y=h/p,b=-g/p*this.#d,x=y*this.#d;this.#a.set(this.#a.subarray(2,8),0);this.#a.set([c+b,l+x],4);this.#a.set(this.#a.subarray(14,18),12);this.#a.set([c-b,l-x],16);if(isNaN(this.#a[6])){if(this.#i.length===0){this.#a.set([o+b,s+x],2);this.#i.push(NaN,NaN,NaN,NaN,(o+b-n)/i,(s+x-r)/a);this.#a.set([o-b,s-x],14);this.#t.push(NaN,NaN,NaN,NaN,(o-b-n)/i,(s-x-r)/a)}this.#a.set([_,v,o,s,c,l],6);return!this.isEmpty()}this.#a.set([_,v,o,s,c,l],6);if(Math.abs(Math.atan2(v-s,_-o)-Math.atan2(g,h))<Math.PI/2){[o,s,c,l]=this.#a.subarray(2,6);this.#i.push(NaN,NaN,NaN,NaN,((o+c)/2-n)/i,((s+l)/2-r)/a);[o,s,_,v]=this.#a.subarray(14,18);this.#t.push(NaN,NaN,NaN,NaN,((_+o)/2-n)/i,((v+s)/2-r)/a);return!0}[_,v,o,s,c,l]=this.#a.subarray(0,6);this.#i.push(((_+5*o)/6-n)/i,((v+5*s)/6-r)/a,((5*o+c)/6-n)/i,((5*s+l)/6-r)/a,((o+c)/2-n)/i,((s+l)/2-r)/a);[c,l,o,s,_,v]=this.#a.subarray(12,18);this.#t.push(((_+5*o)/6-n)/i,((v+5*s)/6-r)/a,((5*o+c)/6-n)/i,((5*s+l)/6-r)/a,((o+c)/2-n)/i,((s+l)/2-r)/a);return!0}toSVGPath(){if(this.isEmpty())return``;let e=this.#i,t=this.#t;if(isNaN(this.#a[6])&&!this.isEmpty())return this.#_();let n=[];n.push(`M${e[4]} ${e[5]}`);for(let t=6;t<e.length;t+=6)isNaN(e[t])?n.push(`L${e[t+4]} ${e[t+5]}`):n.push(`C${e[t]} ${e[t+1]} ${e[t+2]} ${e[t+3]} ${e[t+4]} ${e[t+5]}`);this.#y(n);for(let e=t.length-6;e>=6;e-=6)isNaN(t[e])?n.push(`L${t[e+4]} ${t[e+5]}`):n.push(`C${t[e]} ${t[e+1]} ${t[e+2]} ${t[e+3]} ${t[e+4]} ${t[e+5]}`);this.#v(n);return n.join(` `)}#_(){let[e,t,n,r]=this.#e,[i,a,o,s]=this.#g();return`M${(this.#a[2]-e)/n} ${(this.#a[3]-t)/r} L${(this.#a[4]-e)/n} ${(this.#a[5]-t)/r} L${i} ${a} L${o} ${s} L${(this.#a[16]-e)/n} ${(this.#a[17]-t)/r} L${(this.#a[14]-e)/n} ${(this.#a[15]-t)/r} Z`}#v(e){let t=this.#t;e.push(`L${t[4]} ${t[5]} Z`)}#y(e){let[t,n,r,i]=this.#e,a=this.#a.subarray(4,6),o=this.#a.subarray(16,18),[s,c,l,u]=this.#g();e.push(`L${(a[0]-t)/r} ${(a[1]-n)/i} L${s} ${c} L${l} ${u} L${(o[0]-t)/r} ${(o[1]-n)/i}`)}newFreeDrawOutline(e,t,n,r,i,a){return new yr(e,t,n,r,i,a)}getOutlines(){let e=this.#i,t=this.#t,n=this.#a,[r,i,a,o]=this.#e,s=new Float32Array((this.#f?.length??0)+2);for(let e=0,t=s.length-2;e<t;e+=2){s[e]=(this.#f[e]-r)/a;s[e+1]=(this.#f[e+1]-i)/o}s[s.length-2]=(this.#o-r)/a;s[s.length-1]=(this.#s-i)/o;if(isNaN(n[6])&&!this.isEmpty())return this.#b(s);let c=new Float32Array(this.#i.length+24+this.#t.length),l=e.length;for(let t=0;t<l;t+=2)if(isNaN(e[t]))c[t]=c[t+1]=NaN;else{c[t]=e[t];c[t+1]=e[t+1]}l=this.#S(c,l);for(let e=t.length-6;e>=6;e-=6)for(let n=0;n<6;n+=2)if(isNaN(t[e+n])){c[l]=c[l+1]=NaN;l+=2}else{c[l]=t[e+n];c[l+1]=t[e+n+1];l+=2}this.#x(c,l);return this.newFreeDrawOutline(c,s,this.#e,this.#u,this.#n,this.#r)}#b(e){let t=this.#a,[n,r,i,a]=this.#e,[o,s,c,l]=this.#g(),u=new Float32Array(36);u.set([NaN,NaN,NaN,NaN,(t[2]-n)/i,(t[3]-r)/a,NaN,NaN,NaN,NaN,(t[4]-n)/i,(t[5]-r)/a,NaN,NaN,NaN,NaN,o,s,NaN,NaN,NaN,NaN,c,l,NaN,NaN,NaN,NaN,(t[16]-n)/i,(t[17]-r)/a,NaN,NaN,NaN,NaN,(t[14]-n)/i,(t[15]-r)/a],0);return this.newFreeDrawOutline(u,e,this.#e,this.#u,this.#n,this.#r)}#x(e,t){let n=this.#t;e.set([NaN,NaN,NaN,NaN,n[4],n[5]],t);return t+6}#S(e,t){let n=this.#a.subarray(4,6),r=this.#a.subarray(16,18),[i,a,o,s]=this.#e,[c,l,u,d]=this.#g();e.set([NaN,NaN,NaN,NaN,(n[0]-i)/o,(n[1]-a)/s,NaN,NaN,NaN,NaN,c,l,NaN,NaN,NaN,NaN,u,d,NaN,NaN,NaN,NaN,(r[0]-i)/o,(r[1]-a)/s],t);return t+24}}class yr extends Z{#e;#t=new Float32Array(4);#n;#r;#i;#a;#o;constructor(e,t,n,r,i,a){super();this.#o=e;this.#i=t;this.#e=n;this.#a=r;this.#n=i;this.#r=a;this.firstPoint=[NaN,NaN];this.lastPoint=[NaN,NaN];this.#s(a);let[o,s,c,l]=this.#t;for(let t=0,n=e.length;t<n;t+=2){e[t]=(e[t]-o)/c;e[t+1]=(e[t+1]-s)/l}for(let e=0,n=t.length;e<n;e+=2){t[e]=(t[e]-o)/c;t[e+1]=(t[e+1]-s)/l}}toSVGPath(){let e=[`M${this.#o[4]} ${this.#o[5]}`];for(let t=6,n=this.#o.length;t<n;t+=6)isNaN(this.#o[t])?e.push(`L${this.#o[t+4]} ${this.#o[t+5]}`):e.push(`C${this.#o[t]} ${this.#o[t+1]} ${this.#o[t+2]} ${this.#o[t+3]} ${this.#o[t+4]} ${this.#o[t+5]}`);e.push(`Z`);return e.join(` `)}serialize([e,t,n,r],i){let a=n-e,o=r-t,s,c;switch(i){case 0:s=Z._rescale(this.#o,e,r,a,-o);c=Z._rescale(this.#i,e,r,a,-o);break;case 90:s=Z._rescaleAndSwap(this.#o,e,t,a,o);c=Z._rescaleAndSwap(this.#i,e,t,a,o);break;case 180:s=Z._rescale(this.#o,n,t,-a,o);c=Z._rescale(this.#i,n,t,-a,o);break;case 270:s=Z._rescaleAndSwap(this.#o,n,r,-a,-o);c=Z._rescaleAndSwap(this.#i,n,r,-a,-o)}return{outline:Array.from(s),points:[Array.from(c)]}}#s(e){let t=this.#o,n=t[4],r=t[5],i=[n,r,n,r],a=n,o=r,s=n,c=r,l=e?Math.max:Math.min,u=new Float32Array(4);for(let e=6,d=t.length;e<d;e+=6){let d=t[e+4],p=t[e+5];if(isNaN(t[e])){P.pointBoundingBox(d,p,i);if(o>p){a=d;o=p}else o===p&&(a=l(a,d));if(c<p){s=d;c=p}else c===p&&(s=l(s,d))}else{u.set(f,0);P.bezierBoundingBox(n,r,...t.slice(e,e+6),u);P.rectBoundingBox(...u,i);if(o>u[1]){a=u[0];o=u[1]}else o===u[1]&&(a=l(a,u[0]));if(c<u[3]){s=u[2];c=u[3]}else c===u[3]&&(s=l(s,u[2]))}n=d;r=p}let d=this.#t;d[0]=i[0]-this.#n;d[1]=i[1]-this.#n;d[2]=i[2]-i[0]+2*this.#n;d[3]=i[3]-i[1]+2*this.#n;this.firstPoint=[a,o];this.lastPoint=[s,c]}get box(){return this.#t}newOutliner(e,t,n,r,i,a=0){return new vr(e,t,n,r,i,a)}getNewOutline(e,t){let[n,r,i,a]=this.#t,[o,s,c,l]=this.#e,u=i*c,d=a*l,f=n*c+o,p=r*l+s,m=this.newOutliner({x:this.#i[0]*u+f,y:this.#i[1]*d+p},this.#e,this.#a,e,this.#r,t??this.#n);for(let e=2;e<this.#i.length;e+=2)m.add({x:this.#i[e]*u+f,y:this.#i[e+1]*d+p});return m.getOutlines()}}class br{#e;#t;#n;#r=[];#i=[];constructor(e,t=0,n=0,r=!0){let i=f.slice(),a=1e-4;for(let{x:n,y:r,width:o,height:s}of e){let e=Math.floor((n-t)/a)*a,c=Math.ceil((n+o+t)/a)*a,l=Math.floor((r-t)/a)*a,u=Math.ceil((r+s+t)/a)*a,d=[e,l,u,!0],f=[c,l,u,!1];this.#r.push(d,f);P.rectBoundingBox(e,l,c,u,i)}let o=i[2]-i[0]+2*n,s=i[3]-i[1]+2*n,c=i[0]-n,l=i[1]-n,u=r?-1/0:1/0,d=1/0,p=this.#r.at(r?-1:-2),m=[p[0],p[2]];for(let e of this.#r){let[t,n,i,a]=e;if(!a&&r){if(n<d){d=n;u=t}else n===d&&(u=Math.max(u,t))}else if(a&&!r){if(n<d){d=n;u=t}else n===d&&(u=Math.min(u,t))}e[0]=(t-c)/o;e[1]=(n-l)/s;e[2]=(i-l)/s}this.#e=new Float32Array([c,l,o,s]);this.#t=[u,d];this.#n=m}getOutlines(){this.#r.sort((e,t)=>e[0]-t[0]||e[1]-t[1]||e[2]-t[2]);let e=[];for(let t of this.#r)if(t[3]){e.push(...this.#l(t));this.#s(t)}else{this.#c(t);e.push(...this.#l(t))}return this.#a(e)}#a(e){let t=[],n=new Set;for(let n of e){let[e,r,i]=n;t.push([e,r,n],[e,i,n])}t.sort((e,t)=>e[1]-t[1]||e[0]-t[0]);for(let e=0,r=t.length;e<r;e+=2){let r=t[e][2],i=t[e+1][2];r.push(i);i.push(r);n.add(r);n.add(i)}let r=[],i;for(;n.size>0;){let e=n.values().next().value,[t,a,o,s,c]=e;n.delete(e);let l=t,u=a;i=[t,o];r.push(i);for(;;){let e;if(n.has(s))e=s;else{if(!n.has(c))break;e=c}n.delete(e);[t,a,o,s,c]=e;if(l!==t){i.push(l,u,t,u===a?a:o);l=t}u=u===a?o:a}i.push(l,u)}return new xr(r,this.#e,this.#t,this.#n)}#o(e){let t=this.#i,n=0,r=t.length-1;for(;n<=r;){let i=n+r>>1,a=t[i][0];if(a===e)return i;a<e?n=i+1:r=i-1}return r+1}#s([,e,t]){let n=this.#o(e);this.#i.splice(n,0,[e,t])}#c([,e,t]){let n=this.#o(e);for(let r=n;r<this.#i.length;r++){let[n,i]=this.#i[r];if(n!==e)break;if(n===e&&i===t){this.#i.splice(r,1);return}}for(let r=n-1;r>=0;r--){let[n,i]=this.#i[r];if(n!==e)break;if(n===e&&i===t){this.#i.splice(r,1);return}}}#l(e){let[t,n,r]=e,i=[[t,n,r]],a=this.#o(r);for(let e=0;e<a;e++){let[n,r]=this.#i[e];for(let e=0,a=i.length;e<a;e++){let[,o,s]=i[e];if(!(r<=o||s<=n)){if(o>=n){if(s>r)i[e][1]=r;else{if(a===1)return[];i.splice(e,1);e--;a--}}else{i[e][2]=n;s>r&&i.push([t,r,s])}}}}return i}}class xr extends Z{#e;#t;constructor(e,t,n,r){super();this.#t=e;this.#e=t;this.firstPoint=n;this.lastPoint=r}toSVGPath(){let e=[];for(let t of this.#t){let[n,r]=t;e.push(`M${n} ${r}`);for(let i=2;i<t.length;i+=2){let a=t[i],o=t[i+1];if(a===n){e.push(`V${o}`);r=o}else if(o===r){e.push(`H${a}`);n=a}}e.push(`Z`)}return e.join(` `)}serialize([e,t,n,r],i){let a=[],o=n-e,s=r-t;for(let t of this.#t){let n=Array(t.length);for(let i=0;i<t.length;i+=2){n[i]=e+t[i]*o;n[i+1]=r-t[i+1]*s}a.push(n)}return a}get box(){return this.#e}get classNamesForOutlining(){return[`highlightOutline`]}}class Sr extends vr{newFreeDrawOutline(e,t,n,r,i,a){return new Cr(e,t,n,r,i,a)}}class Cr extends yr{newOutliner(e,t,n,r,i,a=0){return new Sr(e,t,n,r,i,a)}}class Q extends V{#e=null;#t=0;#n;#r=null;#i=null;#a=null;#o=null;#s=0;#c=null;#l=null;#u=null;#d=!1;#f=null;#p=null;#m=null;#h=``;#g;#_=``;static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type=`highlight`;static _editorType=y.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId=``;static get _keyboardManager(){let e=Q.prototype;return j(this,`_keyboardManager`,new ze([[[`ArrowLeft`,`mac+ArrowLeft`],e._moveCaret,{args:[0]}],[[`ArrowRight`,`mac+ArrowRight`],e._moveCaret,{args:[1]}],[[`ArrowUp`,`mac+ArrowUp`],e._moveCaret,{args:[2]}],[[`ArrowDown`,`mac+ArrowDown`],e._moveCaret,{args:[3]}]]))}constructor(e){super({...e,name:`highlightEditor`});this.color=e.color||Q._defaultColor;this.#g=e.thickness||Q._defaultThickness;this.opacity=e.opacity||Q._defaultOpacity;this.#n=e.boxes||null;this.#_=e.methodOfCreation||``;this.#h=e.text||``;this._isDraggable=!1;this.defaultL10nId=`pdfjs-editor-highlight-editor`;if(e.highlightId>-1){this.#d=!0;this.#y(e);this.#w()}else if(this.#n){this.#e=e.anchorNode;this.#t=e.anchorOffset;this.#o=e.focusNode;this.#s=e.focusOffset;this.#v();this.#w();this.rotate(this.rotation)}this.annotationElementId||this._uiManager.a11yAlert(V._l10nAlert.highlight)}get telemetryInitialData(){return{action:`added`,type:this.#d?`free_highlight`:`highlight`,color:this._uiManager.getNonHCMColorName(this.color),thickness:this.#g,methodOfCreation:this.#_}}get telemetryFinalData(){return{type:`highlight`,color:this._uiManager.getNonHCMColorName(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get(`color`).size}}#v(){let e=new br(this.#n,.001);this.#l=e.getOutlines();[this.x,this.y,this.width,this.height]=this.#l.box;let t=new br(this.#n,.0025,.001,this._uiManager.direction===`ltr`);this.#a=t.getOutlines();let{firstPoint:n}=this.#l;this.#f=[(n[0]-this.x)/this.width,(n[1]-this.y)/this.height];let{lastPoint:r}=this.#a;this.#p=[(r[0]-this.x)/this.width,(r[1]-this.y)/this.height]}#y({highlightOutlines:e,highlightId:t,clipPathId:n}){this.#l=e;this.#a=e.getNewOutline(this.#g/2+1.5,.0025);if(t>=0){this.#u=t;this.#r=n;this.parent.drawLayer.finalizeDraw(t,{bbox:e.box,path:{d:e.toSVGPath()}});this.#m=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#a.box,path:{d:this.#a.toSVGPath()}},!0)}else if(this.parent){let t=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#u,{bbox:Q.#T(this.#l.box,(t-this.rotation+360)%360),path:{d:e.toSVGPath()}});this.parent.drawLayer.updateProperties(this.#m,{bbox:Q.#T(this.#a.box,t),path:{d:this.#a.toSVGPath()}})}let[r,i,a,o]=e.box;switch(this.rotation){case 0:this.x=r;this.y=i;this.width=a;this.height=o;break;case 90:{let[e,t]=this.parentDimensions;this.x=i;this.y=1-r;this.width=a*t/e;this.height=o*e/t;break}case 180:this.x=1-r;this.y=1-i;this.width=a;this.height=o;break;case 270:{let[e,t]=this.parentDimensions;this.x=1-i;this.y=r;this.width=a*t/e;this.height=o*e/t;break}}let{firstPoint:s}=e;this.#f=[(s[0]-r)/a,(s[1]-i)/o];let{lastPoint:c}=this.#a;this.#p=[(c[0]-r)/a,(c[1]-i)/o]}static initialize(e,t){V.initialize(e,t);Q._defaultColor||=t.highlightColors?.values().next().value||`#fff066`}static updateDefaultParams(e,t){switch(e){case b.HIGHLIGHT_COLOR:Q._defaultColor=t;break;case b.HIGHLIGHT_THICKNESS:Q._defaultThickness=t}}translateInPage(e,t){}get toolbarPosition(){return this.#p}get commentButtonPosition(){return this.#f}updateParams(e,t){switch(e){case b.HIGHLIGHT_COLOR:this.#b(t);break;case b.HIGHLIGHT_THICKNESS:this.#x(t)}}static get defaultPropertiesToUpdate(){return[[b.HIGHLIGHT_COLOR,Q._defaultColor],[b.HIGHLIGHT_THICKNESS,Q._defaultThickness]]}get propertiesToUpdate(){return[[b.HIGHLIGHT_COLOR,this.color||Q._defaultColor],[b.HIGHLIGHT_THICKNESS,this.#g||Q._defaultThickness],[b.HIGHLIGHT_FREE,this.#d]]}onUpdatedColor(){this.parent?.drawLayer.updateProperties(this.#u,{root:{fill:this.color,"fill-opacity":this.opacity}});this.#i?.updateColor(this.color);super.onUpdatedColor()}#b(e){let t=(e,t)=>{this.color=e;this.opacity=t;this.onUpdatedColor()},n=this.color,r=this.opacity;this.addCommands({cmd:t.bind(this,e,Q._defaultOpacity),undo:t.bind(this,n,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:b.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0});this._reportTelemetry({action:`color_changed`,color:this._uiManager.getNonHCMColorName(e)},!0)}#x(e){let t=this.#g,n=e=>{this.#g=e;this.#S(e)};this.addCommands({cmd:n.bind(this,e),undo:n.bind(this,t),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:b.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0});this._reportTelemetry({action:`thickness_changed`,thickness:e},!0)}get toolbarButtons(){if(this._uiManager.highlightColors)return[[`colorPicker`,this.#i=new J({editor:this})]];return super.toolbarButtons}disableEditing(){super.disableEditing();this.div.classList.toggle(`disabled`,!0)}enableEditing(){super.enableEditing();this.div.classList.toggle(`disabled`,!1)}fixAndSetPosition(){return super.fixAndSetPosition(this.#O())}getBaseTranslation(){return[0,0]}getRect(e,t){return super.getRect(e,t,this.#O())}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this);e&&this.div.focus()}remove(){this.#C();this._reportTelemetry({action:`deleted`});super.remove()}rebuild(){if(this.parent){super.rebuild();if(this.div!==null){this.#w();this.isAttachedToDOM||this.parent.add(this)}}}setParent(e){let t=!1;if(this.parent&&!e)this.#C();else if(e){this.#w(e);t=!this.parent&&this.div?.classList.contains(`selectedEditor`)}super.setParent(e);this.show(this._isVisible);t&&this.select()}#S(e){if(this.#d){this.#y({highlightOutlines:this.#l.getNewOutline(e/2)});this.fixAndSetPosition();this.setDims()}}#C(){if(this.#u!==null&&this.parent){this.parent.drawLayer.remove(this.#u);this.#u=null;this.parent.drawLayer.remove(this.#m);this.#m=null}}#w(e=this.parent){if(this.#u===null){({id:this.#u,clipPathId:this.#r}=e.drawLayer.draw({bbox:this.#l.box,root:{viewBox:`0 0 1 1`,fill:this.color,"fill-opacity":this.opacity},rootClass:{highlight:!0,free:this.#d},path:{d:this.#l.toSVGPath()}},!1,!0));this.#m=e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#d},bbox:this.#a.box,path:{d:this.#a.toSVGPath()}},this.#d);this.#c&&(this.#c.style.clipPath=this.#r)}}static#T([e,t,n,r],i){switch(i){case 90:return[1-t-r,e,r,n];case 180:return[1-e-n,1-t-r,n,r];case 270:return[t,1-e-n,r,n]}return[e,t,n,r]}rotate(e){let{drawLayer:t}=this.parent,n;if(this.#d){e=(e-this.rotation+360)%360;n=Q.#T(this.#l.box,e)}else n=Q.#T([this.x,this.y,this.width,this.height],e);t.updateProperties(this.#u,{bbox:n,root:{"data-main-rotation":e}});t.updateProperties(this.#m,{bbox:Q.#T(this.#a.box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;let e=super.render();if(this.#h){e.setAttribute(`aria-label`,this.#h);e.setAttribute(`role`,`mark`)}this.#d?e.classList.add(`free`):this.div.addEventListener(`keydown`,this.#E.bind(this),{signal:this._uiManager._signal});let t=this.#c=document.createElement(`div`);e.append(t);t.setAttribute(`aria-hidden`,`true`);t.className=`internal`;t.style.clipPath=this.#r;this.setDims();Fe(this,this.#c,[`pointerover`,`pointerleave`]);this.enableEditing();return e}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{hovered:!1}})}#E(e){Q._keyboardManager.exec(this,e)}_moveCaret(e){this.parent.unselect(this);switch(e){case 0:case 2:this.#D(!0);break;case 1:case 3:this.#D(!1)}}#D(e){if(!this.#e)return;let t=window.getSelection();e?t.setPosition(this.#e,this.#t):t.setPosition(this.#o,this.#s)}select(){super.select();this.#m&&this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect();if(this.#m){this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{selected:!1}});this.#d||this.#D(!1)}}get _mustFixPosition(){return!this.#d}show(e=this._isVisible){super.show(e);if(this.parent){this.parent.drawLayer.updateProperties(this.#u,{rootClass:{hidden:!e}});this.parent.drawLayer.updateProperties(this.#m,{rootClass:{hidden:!e}})}}#O(){return this.#d?this.rotation:0}#k(){if(this.#d)return null;let[e,t]=this.pageDimensions,[n,r]=this.pageTranslation,i=this.#n,a=new Float32Array(8*i.length),o=0;for(let{x:s,y:c,width:l,height:u}of i){let i=s*e+n,d=(1-c)*t+r;a[o]=a[o+4]=i;a[o+1]=a[o+3]=d;a[o+2]=a[o+6]=i+l*e;a[o+5]=a[o+7]=d-u*t;o+=8}return a}#A(e){return this.#l.serialize(e,this.#O())}static startHighlighting(e,t,{target:n,x:r,y:i}){let{x:a,y:o,width:s,height:c}=n.getBoundingClientRect(),l=new AbortController,u=e.combinedSignal(l),d=t=>{l.abort();this.#M(e,t)};window.addEventListener(`blur`,d,{signal:u});window.addEventListener(`pointerup`,d,{signal:u});window.addEventListener(`pointerdown`,R,{capture:!0,passive:!1,signal:u});window.addEventListener(`contextmenu`,L,{signal:u});n.addEventListener(`pointermove`,this.#j.bind(this,e),{signal:u});this._freeHighlight=new Sr({x:r,y:i},[a,o,s,c],e.scale,this._defaultThickness/2,t,.001);({id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:`0 0 1 1`,fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0))}static#j(e,t){this._freeHighlight.add(t)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#M(e,t){this._freeHighlight.isEmpty()?e.drawLayer.remove(this._freeHighlightId):e.createAndAddNewEditor(t,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:`main_toolbar`});this._freeHighlightId=-1;this._freeHighlight=null;this._freeHighlightClipId=``}static async deserialize(e,t,n){let r=null;if(e instanceof hr){let{data:{quadPoints:t,rect:n,rotation:i,id:a,color:o,opacity:s,popupRef:c,richText:l,contentsObj:u,creationDate:d,modificationDate:f},parent:{page:{pageNumber:p}}}=e;r=e={annotationType:y.HIGHLIGHT,color:Array.from(o),opacity:s,quadPoints:t,boxes:null,pageIndex:p-1,rect:n.slice(0),rotation:i,annotationElementId:a,id:a,deleted:!1,popupRef:c,richText:l,comment:u?.str||null,creationDate:d,modificationDate:f}}else if(e instanceof mr){let{data:{inkLists:t,rect:n,rotation:i,id:a,color:o,borderStyle:{rawWidth:s},popupRef:c,richText:l,contentsObj:u,creationDate:d,modificationDate:f},parent:{page:{pageNumber:p}}}=e;r=e={annotationType:y.HIGHLIGHT,color:Array.from(o),thickness:s,inkLists:t,boxes:null,pageIndex:p-1,rect:n.slice(0),rotation:i,annotationElementId:a,id:a,deleted:!1,popupRef:c,richText:l,comment:u?.str||null,creationDate:d,modificationDate:f}}let{color:i,quadPoints:a,inkLists:o,outlines:s,opacity:c}=e,l=await super.deserialize(e,t,n);l.color=P.makeHexColor(...i);l.opacity=c||1;o&&(l.#g=e.thickness);l._initialData=r;e.comment&&l.setCommentData(e);let[u,d]=l.pageDimensions,[f,p]=l.pageTranslation;if(a){let e=l.#n=[];for(let t=0;t<a.length;t+=8)e.push({x:(a[t]-f)/u,y:1-(a[t+1]-p)/d,width:(a[t+2]-a[t])/u,height:(a[t+1]-a[t+5])/d});l.#v();l.#w();l.rotate(l.rotation)}else if(o||s){l.#d=!0;let e=(o||s.points)[0],n={x:e[0]-f,y:d-(e[1]-p)},r=new Sr(n,[0,0,u,d],1,l.#g/2,!0,.001);for(let t=0,i=e.length;t<i;t+=2){n.x=e[t]-f;n.y=d-(e[t+1]-p);r.add(n)}let{id:i,clipPathId:a}=t.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:`0 0 1 1`,fill:l.color,"fill-opacity":l._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:r.toSVGPath()}},!0,!0);l.#y({highlightOutlines:r.getOutlines(),highlightId:i,clipPathId:a});l.#w();l.rotate(l.parentRotation)}return l}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();let t=V._colorManager.convert(this._uiManager.getNonHCMColor(this.color)),n=super.serialize(e);Object.assign(n,{color:t,opacity:this.opacity,thickness:this.#g,quadPoints:this.#k(),outlines:this.#A(n.rect)});this.addComment(n);if(this.annotationElementId&&!this.#N(n))return null;n.id=this.annotationElementId;return n}#N(e){let{color:t}=this._initialData;return this.hasEditedComment||e.color.some((e,n)=>e!==t[n])}renderAnnotationElement(e){if(this.deleted){e.hide();return null}e.updateEdited({rect:this.getPDFRect(),popup:this.comment});return null}static canCreateNewEmptyEditor(){return!1}}class wr{#e=Object.create(null);updateProperty(e,t){this[e]=t;this.updateSVGProperty(e,t)}updateProperties(e){if(e)for(let[t,n]of Object.entries(e))t.startsWith(`_`)||this.updateProperty(t,n)}updateSVGProperty(e,t){this.#e[e]=t}toSVGProperties(){let e=this.#e;this.#e=Object.create(null);return{root:e}}reset(){this.#e=Object.create(null)}updateAll(e=this){this.updateProperties(e)}clone(){k(`Not implemented`)}}class $ extends V{#e=null;#t;_colorPicker=null;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#n=null;static#r=null;static#i=null;static _INNER_MARGIN=3;constructor(e){super(e);this.#t=e.mustBeCommitted||!1;this._addOutlines(e)}onUpdatedColor(){this._colorPicker?.update(this.color);super.onUpdatedColor()}onUpdatedOpacity(){this._colorPicker?.updateOpacity?.(this.opacity)}_addOutlines(e){if(e.drawOutlines){this.#a(e);this.#c()}}#a({drawOutlines:e,drawId:t,drawingOptions:n}){this.#e=e;this._drawingOptions||=n;this.annotationElementId||this._uiManager.a11yAlert(V._l10nAlert[this.editorType]);if(t>=0){this._drawId=t;this.parent.drawLayer.finalizeDraw(t,e.defaultProperties)}else this._drawId=this.#o(e,this.parent);this.#d(e.box)}#o(e,t){let{id:n}=t.drawLayer.draw($._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return n}static _mergeSVGProperties(e,t){let n=new Set(Object.keys(e));for(let[r,i]of Object.entries(t))n.has(r)?Object.assign(e[r],i):e[r]=i;return e}static getDefaultDrawingOptions(e){k(`Not implemented`)}static get typesMap(){k(`Not implemented`)}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,t){let n=this.typesMap.get(e);n&&this._defaultDrawingOptions.updateProperty(n,t);if(this._currentParent){$.#n.updateProperty(n,t);this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties())}}updateParams(e,t){let n=this.constructor.typesMap.get(e);n&&this._updateProperty(e,n,t)}static get defaultPropertiesToUpdate(){let e=[],t=this._defaultDrawingOptions;for(let[n,r]of this.typesMap)e.push([n,t[r]]);return e}get propertiesToUpdate(){let e=[],{_drawingOptions:t}=this;for(let[n,r]of this.constructor.typesMap)e.push([n,t[r]]);return e}_updateProperty(e,t,n){let r=this._drawingOptions,i=r[t],a=n=>{r.updateProperty(t,n);let i=this.#e.updateProperty(t,n);i&&this.#d(i);this.parent?.drawLayer.updateProperties(this._drawId,r.toSVGProperties());e===this.colorType?this.onUpdatedColor():e===this.opacityType&&this.onUpdatedOpacity()};this.addCommands({cmd:a.bind(this,n),undo:a.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_updateColorAndOpacity(e,t){let n=this.constructor.typesMap.get(this.colorType),r=this.constructor.typesMap.get(this.opacityType),i=this._drawingOptions,a=i[n],o=i[r],s=(e,t)=>{i.updateProperty(n,e);i.updateProperty(r,t);this.#e.updateProperty(n,e);this.#e.updateProperty(r,t);this.parent?.drawLayer.updateProperties(this._drawId,i.toSVGProperties());this.onUpdatedColor();this.onUpdatedOpacity()};this.addCommands({cmd:s.bind(this,e,t),undo:s.bind(this,a,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:b.INK_COLOR_AND_OPACITY,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,$._mergeSVGProperties(this.#e.getPathResizingSVGProperties(this.#u()),{bbox:this.#f()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,$._mergeSVGProperties(this.#e.getPathResizedSVGProperties(this.#u()),{bbox:this.#f()}))}_onTranslating(e,t){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#f()})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,$._mergeSVGProperties(this.#e.getPathTranslatedSVGProperties(this.#u(),this.parentDimensions),{bbox:this.#f()}))}_onStartDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit();this.disableEditMode();this.disableEditing()}disableEditing(){super.disableEditing();this.div.classList.toggle(`disabled`,!0)}enableEditing(){super.enableEditing();this.div.classList.toggle(`disabled`,!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this);this._isDraggable=!0;if(this.#t){this.#t=!1;this.commit();this.parent.setSelected(this);e&&this.isOnScreen&&this.div.focus()}}remove(){this.#s();super.remove()}rebuild(){if(this.parent){super.rebuild();if(this.div!==null){this.#c();this.#d(this.#e.box);this.isAttachedToDOM||this.parent.add(this)}}}setParent(e){let t=!1;if(this.parent&&!e){this._uiManager.removeShouldRescale(this);this.#s()}else if(e){this._uiManager.addShouldRescale(this);this.#c(e);t=!this.parent&&this.div?.classList.contains(`selectedEditor`)}super.setParent(e);t&&this.select()}#s(){if(this._drawId!==null&&this.parent){this.parent.drawLayer.remove(this._drawId);this._drawId=null;this._drawingOptions.reset()}}#c(e=this.parent){if(this._drawId===null||this.parent!==e){if(this._drawId===null){this._drawingOptions.updateAll();this._drawId=this.#o(this.#e,e)}else this.parent.drawLayer.updateParent(this._drawId,e.drawLayer)}}#l([e,t,n,r]){let{parentDimensions:[i,a],rotation:o}=this;switch(o){case 90:return[t,1-e,a/i*n,i/a*r];case 180:return[1-e,1-t,n,r];case 270:return[1-t,e,a/i*n,i/a*r];default:return[e,t,n,r]}}#u(){let{x:e,y:t,width:n,height:r,parentDimensions:[i,a],rotation:o}=this;switch(o){case 90:return[1-t,e,i/a*n,a/i*r];case 180:return[1-e,1-t,n,r];case 270:return[t,1-e,i/a*n,a/i*r];default:return[e,t,n,r]}}#d(e){[this.x,this.y,this.width,this.height]=this.#l(e);if(this.div){this.fixAndSetPosition();this.setDims()}this._onResized()}#f(){let{x:e,y:t,width:n,height:r,rotation:i,parentRotation:a,parentDimensions:[o,s]}=this;switch((4*i+a)/90){case 1:return[1-t-r,e,r,n];case 2:return[1-e-n,1-t-r,n,r];case 3:return[t,1-e-n,r,n];case 4:return[e,t-o/s*n,s/o*r,o/s*n];case 5:return[1-t,e,o/s*n,s/o*r];case 6:return[1-e-s/o*r,1-t,s/o*r,o/s*n];case 7:return[t-o/s*n,1-e-s/o*r,o/s*n,s/o*r];case 8:return[e-n,t-r,n,r];case 9:return[1-t,e-n,r,n];case 10:return[1-e,1-t,n,r];case 11:return[t-r,1-e,r,n];case 12:return[e-s/o*r,t,s/o*r,o/s*n];case 13:return[1-t-o/s*n,e-s/o*r,o/s*n,s/o*r];case 14:return[1-e,1-t-o/s*n,s/o*r,o/s*n];case 15:return[t,1-e,o/s*n,s/o*r];default:return[e,t,n,r]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,$._mergeSVGProperties({bbox:this.#f()},this.#e.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#d(this.#e.updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;let e,t;if(this._isCopy){e=this.x;t=this.y}let n=super.render();n.classList.add(`draw`);let r=document.createElement(`div`);n.append(r);r.setAttribute(`aria-hidden`,`true`);r.className=`internal`;this.setDims();this._uiManager.addShouldRescale(this);this.disableEditing();this._isCopy&&this._moveAfterPaste(e,t);return n}static createDrawerInstance(e,t,n,r,i){k(`Not implemented`)}static startDrawing(e,t,n,r){let{target:i,offsetX:a,offsetY:o,pointerId:s,pointerType:c}=r;if(B.isInitializedAndDifferentPointerType(c))return;let{viewport:{rotation:l}}=e,{width:u,height:d}=i.getBoundingClientRect(),f=$.#r=new AbortController,p=e.combinedSignal(f);B.setPointer(c,s);window.addEventListener(`pointerup`,e=>{B.isSamePointerIdOrRemove(e.pointerId)&&this._endDraw(e)},{signal:p});window.addEventListener(`pointercancel`,e=>{B.isSamePointerIdOrRemove(e.pointerId)&&this._currentParent.endDrawingSession()},{signal:p});window.addEventListener(`pointerdown`,e=>{if(B.isSamePointerType(e.pointerType)){B.initializeAndAddPointerId(e.pointerId);if($.#n.isCancellable()){$.#n.removeLastElement();$.#n.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)}}},{capture:!0,passive:!1,signal:p});window.addEventListener(`contextmenu`,L,{signal:p});i.addEventListener(`pointermove`,this._drawMove.bind(this),{signal:p});i.addEventListener(`touchmove`,e=>{B.isSameTimeStamp(e.timeStamp)&&R(e)},{signal:p});e.toggleDrawing();t._editorUndoBar?.hide();if($.#n)e.drawLayer.updateProperties(this._currentDrawId,$.#n.startNew(a,o,u,d,l));else{t.updateUIForDefaultProperties(this);$.#n=this.createDrawerInstance(a,o,u,d,l);$.#i=this.getDefaultDrawingOptions();this._currentParent=e;({id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties($.#i.toSVGProperties(),$.#n.defaultSVGProperties),!0,!1))}}static _drawMove(e){B.isSameTimeStamp(e.timeStamp);if(!$.#n)return;let{offsetX:t,offsetY:n,pointerId:r}=e;if(B.isSamePointerId(r)){if(B.isUsingMultiplePointers())this._endDraw(e);else{this._currentParent.drawLayer.updateProperties(this._currentDrawId,$.#n.add(t,n));B.setTimeStamp(e.timeStamp);R(e)}}}static _cleanup(e){if(e){this._currentDrawId=-1;this._currentParent=null;$.#n=null;$.#i=null;B.clearTimeStamp()}if($.#r){$.#r.abort();$.#r=null;B.clearPointerIds()}}static _endDraw(e){let t=this._currentParent;if(t){t.toggleDrawing(!0);this._cleanup(!1);e?.target===t.div&&t.drawLayer.updateProperties(this._currentDrawId,$.#n.end(e.offsetX,e.offsetY));if(this.supportMultipleDrawings){let e=$.#n,n=this._currentDrawId,r=e.getLastElement();t.addCommands({cmd:()=>{t.drawLayer.updateProperties(n,e.setLastElement(r))},undo:()=>{t.drawLayer.updateProperties(n,e.removeLastElement())},mustExec:!1,type:b.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){let t=this._currentParent;if(!t)return null;t.toggleDrawing(!0);t.cleanUndoStack(b.DRAW_STEP);if(!$.#n.isEmpty()){let{pageDimensions:[n,r],scale:i}=t,a=t.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:$.#n.getOutlines(n*i,r*i,i,this._INNER_MARGIN),drawingOptions:$.#i,mustBeCommitted:!e});this._cleanup(!0);return a}t.drawLayer.remove(this._currentDrawId);this._cleanup(!0);return null}createDrawingOptions(e){}static deserializeDraw(e,t,n,r,i,a){k(`Not implemented`)}static async deserialize(e,t,n){let{rawDims:{pageWidth:r,pageHeight:i,pageX:a,pageY:o}}=t.viewport,s=this.deserializeDraw(a,o,r,i,this._INNER_MARGIN,e),c=await super.deserialize(e,t,n);c.createDrawingOptions(e);c.#a({drawOutlines:s});c.#c();c.onScaleChanging();c.rotate();return c}serializeDraw(e){let[t,n]=this.pageTranslation,[r,i]=this.pageDimensions;return this.#e.serialize([t,n,r,i],e)}renderAnnotationElement(e){e.updateEdited({rect:this.getPDFRect()});return null}static canCreateNewEmptyEditor(){return!1}}class Tr{#e=new Float64Array(6);#t;#n;#r;#i;#a;#o=``;#s=0;#c=new Er;#l;#u;constructor(e,t,n,r,i,a){this.#l=n;this.#u=r;this.#r=i;this.#i=a;[e,t]=this.#d(e,t);let o=this.#t=[NaN,NaN,NaN,NaN,e,t];this.#a=[e,t];this.#n=[{line:o,points:this.#a}];this.#e.set(o,0)}updateProperty(e,t){e===`stroke-width`&&(this.#i=t)}#d(e,t){return Z._normalizePoint(e,t,this.#l,this.#u,this.#r)}isEmpty(){return!this.#n||this.#n.length===0}isCancellable(){return this.#a.length<=10}add(e,t){[e,t]=this.#d(e,t);let[n,r,i,a]=this.#e.subarray(2,6),o=e-i,s=t-a;if(Math.hypot(this.#l*o,this.#u*s)<=2)return null;this.#a.push(e,t);if(isNaN(n)){this.#e.set([i,a,e,t],2);this.#t.push(NaN,NaN,NaN,NaN,e,t);return{path:{d:this.toSVGPath()}}}isNaN(this.#e[0])&&this.#t.splice(6,6);this.#e.set([n,r,i,a,e,t],0);this.#t.push(...Z.createBezierPoints(n,r,i,a,e,t));return{path:{d:this.toSVGPath()}}}end(e,t){return this.add(e,t)||(this.#a.length===2?{path:{d:this.toSVGPath()}}:null)}startNew(e,t,n,r,i){this.#l=n;this.#u=r;this.#r=i;[e,t]=this.#d(e,t);let a=this.#t=[NaN,NaN,NaN,NaN,e,t];this.#a=[e,t];let o=this.#n.at(-1);if(o){o.line=new Float32Array(o.line);o.points=new Float32Array(o.points)}this.#n.push({line:a,points:this.#a});this.#e.set(a,0);this.#s=0;this.toSVGPath();return null}getLastElement(){return this.#n.at(-1)}setLastElement(e){if(!this.#n)return this.#c.setLastElement(e);this.#n.push(e);this.#t=e.line;this.#a=e.points;this.#s=0;return{path:{d:this.toSVGPath()}}}removeLastElement(){if(!this.#n)return this.#c.removeLastElement();this.#n.pop();this.#o=``;for(let e=0,t=this.#n.length;e<t;e++){let{line:t,points:n}=this.#n[e];this.#t=t;this.#a=n;this.#s=0;this.toSVGPath()}return{path:{d:this.#o}}}toSVGPath(){let e=Z.svgRound(this.#t[4]),t=Z.svgRound(this.#t[5]);if(this.#a.length===2){this.#o=`${this.#o} M ${e} ${t} Z`;return this.#o}if(this.#a.length<=6){let n=this.#o.lastIndexOf(`M`);this.#o=`${this.#o.slice(0,n)} M ${e} ${t}`;this.#s=6}if(this.#a.length===4){let e=Z.svgRound(this.#t[10]),t=Z.svgRound(this.#t[11]);this.#o=`${this.#o} L ${e} ${t}`;this.#s=12;return this.#o}let n=[];if(this.#s===0){n.push(`M ${e} ${t}`);this.#s=6}for(let e=this.#s,t=this.#t.length;e<t;e+=6){let[t,r,i,a,o,s]=this.#t.slice(e,e+6).map(Z.svgRound);n.push(`C${t} ${r} ${i} ${a} ${o} ${s}`)}this.#o+=n.join(` `);this.#s=this.#t.length;return this.#o}getOutlines(e,t,n,r){let i=this.#n.at(-1);i.line=new Float32Array(i.line);i.points=new Float32Array(i.points);this.#c.build(this.#n,e,t,n,this.#r,this.#i,r);this.#e=null;this.#t=null;this.#n=null;this.#o=null;return this.#c}get defaultSVGProperties(){return{root:{viewBox:`0 0 10000 10000`},rootClass:{draw:!0},bbox:[0,0,1,1]}}}class Er extends Z{#e;#t=0;#n;#r;#i;#a;#o;#s;#c;build(e,t,n,r,i,a,o){this.#i=t;this.#a=n;this.#o=r;this.#s=i;this.#c=a;this.#n=o??0;this.#r=e;this.#d()}get thickness(){return this.#c}setLastElement(e){this.#r.push(e);return{path:{d:this.toSVGPath()}}}removeLastElement(){this.#r.pop();return{path:{d:this.toSVGPath()}}}toSVGPath(){let e=[];for(let{line:t}of this.#r){e.push(`M${Z.svgRound(t[4])} ${Z.svgRound(t[5])}`);if(t.length!==6){if(t.length===12&&isNaN(t[6]))e.push(`L${Z.svgRound(t[10])} ${Z.svgRound(t[11])}`);else for(let n=6,r=t.length;n<r;n+=6){let[r,i,a,o,s,c]=t.subarray(n,n+6).map(Z.svgRound);e.push(`C${r} ${i} ${a} ${o} ${s} ${c}`)}}else e.push(`Z`)}return e.join(``)}serialize([e,t,n,r],i){let a=[],o=[],[s,c,l,u]=this.#u(),d,f,p,m,h,g,_,v,y;switch(this.#s){case 0:y=Z._rescale;d=e;f=t+r;p=n;m=-r;h=e+s*n;g=t+(1-c-u)*r;_=e+(s+l)*n;v=t+(1-c)*r;break;case 90:y=Z._rescaleAndSwap;d=e;f=t;p=n;m=r;h=e+c*n;g=t+s*r;_=e+(c+u)*n;v=t+(s+l)*r;break;case 180:y=Z._rescale;d=e+n;f=t;p=-n;m=r;h=e+(1-s-l)*n;g=t+c*r;_=e+(1-s)*n;v=t+(c+u)*r;break;case 270:y=Z._rescaleAndSwap;d=e+n;f=t+r;p=-n;m=-r;h=e+(1-c-u)*n;g=t+(1-s-l)*r;_=e+(1-c)*n;v=t+(1-s)*r}for(let{line:e,points:t}of this.#r){a.push(y(e,d,f,p,m,i?Array(e.length):null));o.push(y(t,d,f,p,m,i?Array(t.length):null))}return{lines:a,points:o,rect:[h,g,_,v]}}static deserialize(e,t,n,r,i,{paths:{lines:a,points:o},rotation:s,thickness:c}){let l=[],u,d,f,p,m;switch(s){case 0:m=Z._rescale;u=-e/n;d=t/r+1;f=1/n;p=-1/r;break;case 90:m=Z._rescaleAndSwap;u=-t/r;d=-e/n;f=1/r;p=1/n;break;case 180:m=Z._rescale;u=e/n+1;d=-t/r;f=-1/n;p=1/r;break;case 270:m=Z._rescaleAndSwap;u=t/r+1;d=e/n+1;f=-1/r;p=-1/n}if(!a){a=[];for(let e of o){let t=e.length;if(t===2){a.push(new Float32Array([NaN,NaN,NaN,NaN,e[0],e[1]]));continue}if(t===4){a.push(new Float32Array([NaN,NaN,NaN,NaN,e[0],e[1],NaN,NaN,NaN,NaN,e[2],e[3]]));continue}let n=new Float32Array(3*(t-2));a.push(n);let[r,i,o,s]=e.subarray(0,4);n.set([NaN,NaN,NaN,NaN,r,i],0);for(let a=4;a<t;a+=2){let t=e[a],c=e[a+1];n.set(Z.createBezierPoints(r,i,o,s,t,c),3*(a-2));[r,i,o,s]=[o,s,t,c]}}}for(let e=0,t=a.length;e<t;e++)l.push({line:m(a[e].map(e=>e??NaN),u,d,f,p),points:m(o[e].map(e=>e??NaN),u,d,f,p)});let h=new this.prototype.constructor;h.build(l,n,r,1,s,c,i);return h}#l(e=this.#c){let t=this.#n+e/2*this.#o;return this.#s%180==0?[t/this.#i,t/this.#a]:[t/this.#a,t/this.#i]}#u(){let[e,t,n,r]=this.#e,[i,a]=this.#l(0);return[e+i,t+a,n-2*i,r-2*a]}#d(){let e=this.#e=p.slice();for(let{line:t}of this.#r){if(t.length<=12){for(let n=4,r=t.length;n<r;n+=6)P.pointBoundingBox(t[n],t[n+1],e);continue}let n=t[4],r=t[5];for(let i=6,a=t.length;i<a;i+=6){let[a,o,s,c,l,u]=t.subarray(i,i+6);P.bezierBoundingBox(n,r,a,o,s,c,l,u,e);n=l;r=u}}let[t,n]=this.#l();e[0]=F(e[0]-t,0,1);e[1]=F(e[1]-n,0,1);e[2]=F(e[2]+t,0,1);e[3]=F(e[3]+n,0,1);e[2]-=e[0];e[3]-=e[1]}get box(){return this.#e}updateProperty(e,t){return e===`stroke-width`?this.#f(t):null}#f(e){let[t,n]=this.#l();this.#c=e;let[r,i]=this.#l(),[a,o]=[r-t,i-n],s=this.#e;s[0]-=a;s[1]-=o;s[2]+=2*a;s[3]+=2*o;return s}updateParentDimensions([e,t],n){let[r,i]=this.#l();this.#i=e;this.#a=t;this.#o=n;let[a,o]=this.#l(),s=a-r,c=o-i,l=this.#e;l[0]-=s;l[1]-=c;l[2]+=2*s;l[3]+=2*c;return l}updateRotation(e){this.#t=e;return{path:{transform:this.rotationTransform}}}get viewBox(){return this.#e.map(Z.svgRound).join(` `)}get defaultProperties(){let[e,t]=this.#e;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`}}}get rotationTransform(){let[,,e,t]=this.#e,n=0,r=0,i=0,a=0,o=0,s=0;switch(this.#t){case 90:r=t/e;i=-e/t;o=e;break;case 180:n=-1;a=-1;o=e;s=t;break;case 270:r=-t/e;i=e/t;s=t;break;default:return``}return`matrix(${n} ${r} ${i} ${a} ${Z.svgRound(o)} ${Z.svgRound(s)})`}getPathResizingSVGProperties([e,t,n,r]){let[i,a]=this.#l(),[o,s,c,l]=this.#e;if(Math.abs(c-i)<=Z.PRECISION||Math.abs(l-a)<=Z.PRECISION){let i=e+n/2-(o+c/2),a=t+r/2-(s+l/2);return{path:{"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`,transform:`${this.rotationTransform} translate(${i} ${a})`}}}let u=(n-2*i)/(c-2*i),d=(r-2*a)/(l-2*a),f=c/n,p=l/r;return{path:{"transform-origin":`${Z.svgRound(o)} ${Z.svgRound(s)}`,transform:`${this.rotationTransform} scale(${f} ${p}) translate(${Z.svgRound(i)} ${Z.svgRound(a)}) scale(${u} ${d}) translate(${Z.svgRound(-i)} ${Z.svgRound(-a)})`}}}getPathResizedSVGProperties([e,t,n,r]){let[i,a]=this.#l(),o=this.#e,[s,c,l,u]=o;o[0]=e;o[1]=t;o[2]=n;o[3]=r;if(Math.abs(l-i)<=Z.PRECISION||Math.abs(u-a)<=Z.PRECISION){let i=e+n/2-(s+l/2),a=t+r/2-(c+u/2);for(let{line:e,points:t}of this.#r){Z._translate(e,i,a,e);Z._translate(t,i,a,t)}return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}let d=(n-2*i)/(l-2*i),f=(r-2*a)/(u-2*a),p=-d*(s+i)+e+i,m=-f*(c+a)+t+a;if(d!==1||f!==1||p!==0||m!==0)for(let{line:e,points:t}of this.#r){Z._rescale(e,p,m,d,f,e);Z._rescale(t,p,m,d,f,t)}return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,t],n){let[r,i]=n,a=this.#e,o=e-a[0],s=t-a[1];if(this.#i===r&&this.#a===i)for(let{line:e,points:t}of this.#r){Z._translate(e,o,s,e);Z._translate(t,o,s,t)}else{let e=this.#i/r,t=this.#a/i;this.#i=r;this.#a=i;for(let{line:n,points:r}of this.#r){Z._rescale(n,o,s,e,t,n);Z._rescale(r,o,s,e,t,r)}a[2]*=e;a[3]*=t}a[0]=e;a[1]=t;return{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${Z.svgRound(e)} ${Z.svgRound(t)}`}}}get defaultSVGProperties(){let e=this.#e;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${Z.svgRound(e[0])} ${Z.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}}class Dr extends wr{constructor(e){super();this._viewParameters=e;super.updateProperties({fill:`none`,stroke:V._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-miterlimit":10})}updateSVGProperty(e,t){if(e===`stroke-width`){t??=this[`stroke-width`];t*=this._viewParameters.realScale}super.updateSVGProperty(e,t)}clone(){let e=new Dr(this._viewParameters);e.updateAll(this);return e}}class Or extends ${static _type=`ink`;static _editorType=y.INK;static _defaultDrawingOptions=null;constructor(e){super({...e,name:`inkEditor`});this._willKeepAspectRatio=!0;this.defaultL10nId=`pdfjs-editor-ink-editor`}static initialize(e,t){V.initialize(e,t);this._defaultDrawingOptions=new Dr(t.viewParameters)}static getDefaultDrawingOptions(e){let t=this._defaultDrawingOptions.clone();t.updateProperties(e);return t}static get supportMultipleDrawings(){return!0}static get typesMap(){return j(this,`typesMap`,new Map([[b.INK_THICKNESS,`stroke-width`],[b.INK_COLOR,`stroke`],[b.INK_OPACITY,`stroke-opacity`]]))}static createDrawerInstance(e,t,n,r,i){return new Tr(e,t,n,r,i,this._defaultDrawingOptions[`stroke-width`])}static deserializeDraw(e,t,n,r,i,a){return Er.deserialize(e,t,n,r,i,a)}static async deserialize(e,t,n){let r=null;if(e instanceof mr){let{data:{inkLists:t,rect:n,rotation:i,id:a,color:o,opacity:s,borderStyle:{rawWidth:c},popupRef:l,richText:u,contentsObj:d,creationDate:f,modificationDate:p},parent:{page:{pageNumber:m}}}=e;r=e={annotationType:y.INK,color:Array.from(o),thickness:c,opacity:s,paths:{points:t},boxes:null,pageIndex:m-1,rect:n.slice(0),rotation:i,annotationElementId:a,id:a,deleted:!1,popupRef:l,richText:u,comment:d?.str||null,creationDate:f,modificationDate:p}}let i=await super.deserialize(e,t,n);i._initialData=r;e.comment&&i.setCommentData(e);return i}get toolbarButtons(){this._colorPicker||=new rr(this);return[[`colorPicker`,this._colorPicker]]}get colorType(){return b.INK_COLOR}get colorAndOpacityType(){return b.INK_COLOR_AND_OPACITY}get opacityType(){return b.INK_OPACITY}updateParams(e,t){e===b.INK_COLOR_AND_OPACITY?this._updateColorAndOpacity(t.color,t.opacity):super.updateParams(e,t)}static updateDefaultParams(e,t){if(e!==b.INK_COLOR_AND_OPACITY)super.updateDefaultParams(e,t);else{super.updateDefaultParams(b.INK_COLOR,t.color);super.updateDefaultParams(b.INK_OPACITY,t.opacity)}}get color(){return this._drawingOptions.stroke}get opacity(){return this._drawingOptions[`stroke-opacity`]}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();let{_drawId:e,_drawingOptions:t,parent:n}=this;t.updateSVGProperty(`stroke-width`);n.drawLayer.updateProperties(e,t.toSVGProperties())}static onScaleChangingWhenDrawing(){let e=this._currentParent;if(e){super.onScaleChangingWhenDrawing();this._defaultDrawingOptions.updateSVGProperty(`stroke-width`);e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties())}}createDrawingOptions({color:e,thickness:t,opacity:n}){this._drawingOptions=Or.getDefaultDrawingOptions({stroke:P.makeHexColor(...e),"stroke-width":t,"stroke-opacity":n})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let{lines:t,points:n}=this.serializeDraw(e),{_drawingOptions:{stroke:r,"stroke-opacity":i,"stroke-width":a}}=this,o=Object.assign(super.serialize(e),{color:V._colorManager.convert(r),opacity:i,thickness:a,paths:{lines:t,points:n}});this.addComment(o);if(e){o.isCopy=!0;return o}if(this.annotationElementId&&!this.#e(o))return null;o.id=this.annotationElementId;return o}#e(e){let{color:t,thickness:n,opacity:r,pageIndex:i}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized||e.color.some((e,n)=>e!==t[n])||e.thickness!==n||e.opacity!==r||e.pageIndex!==i}renderAnnotationElement(e){if(this.deleted){e.hide();return null}let{points:t,rect:n}=this.serializeDraw(!1);e.updateEdited({rect:n,thickness:this._drawingOptions[`stroke-width`],points:t,popup:this.comment});return null}}class kr extends Er{toSVGPath(){let e=super.toSVGPath();e.endsWith(`Z`)||(e+=`Z`);return e}}class Ar{static#e={maxDim:512,sigmaSFactor:.02,sigmaR:25,kernelSize:16};static#t(e,t,n,r){r-=t;return(n-=e)===0?r>0?0:4:n===1?r+6:2-r}static#n=new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]);static#r(e,t,n,r,i,a,o){let s=this.#t(n,r,i,a);for(let i=0;i<8;i++){let a=(-i+s-o+16)%8;if(e[(n+this.#n[2*a])*t+(r+this.#n[2*a+1])]!==0)return a}return-1}static#i(e,t,n,r,i,a,o){let s=this.#t(n,r,i,a);for(let i=0;i<8;i++){let a=(i+s+o+16)%8;if(e[(n+this.#n[2*a])*t+(r+this.#n[2*a+1])]!==0)return a}return-1}static#a(e,t,n,r){let i=e.length,a=new Int32Array(i);for(let t=0;t<i;t++)a[t]=+(e[t]<=r);for(let e=1;e<n-1;e++)a[e*t]=a[e*t+t-1]=0;for(let e=0;e<t;e++)a[e]=a[t*n-1-e]=0;let o,s=1,c=[];for(let e=1;e<n-1;e++){o=1;for(let n=1;n<t-1;n++){let r=e*t+n,i=a[r];if(i===0)continue;let l=e,u=n;if(i===1&&a[r-1]===0){s+=1;--u}else{if(!(i>=1&&a[r+1]===0)){i!==1&&(o=Math.abs(i));continue}s+=1;u+=1;i>1&&(o=i)}let d=[n,e],f=u===n+1,p={isHole:f,points:d,id:s,parent:0};c.push(p);let m;for(let e of c)if(e.id===o){m=e;break}p.parent=m?m.isHole?f?m.parent:o:f?o:m.parent:f?o:0;let h=this.#r(a,t,e,n,l,u,0);if(h===-1){a[r]=-s;a[r]!==1&&(o=Math.abs(a[r]));continue}let g=this.#n[2*h],_=this.#n[2*h+1],v=e+g,y=n+_;l=v;u=y;let b=e,x=n;for(;;){let i=this.#i(a,t,b,x,l,u,1);g=this.#n[2*i];_=this.#n[2*i+1];let c=b+g,f=x+_;d.push(f,c);let p=b*t+x;a[p+1]===0?a[p]=-s:a[p]===1&&(a[p]=s);if(c===e&&f===n&&b===v&&x===y){a[r]!==1&&(o=Math.abs(a[r]));break}l=b;u=x;b=c;x=f}}}return c}static#o(e,t,n,r){if(n-t<=4){for(let i=t;i<n-2;i+=2)r.push(e[i],e[i+1]);return}let i=e[t],a=e[t+1],o=e[n-4]-i,s=e[n-3]-a,c=Math.hypot(o,s),l=o/c,u=s/c,d=l*a-u*i,f=s/o,p=1/c,m=Math.atan(f),h=Math.cos(m),g=Math.sin(m),_=p*(Math.abs(h)+Math.abs(g)),v=p*(1-_+_**2),y=Math.max(Math.atan(Math.abs(g+h)*v),Math.atan(Math.abs(g-h)*v)),b=0,x=t;for(let r=t+2;r<n-2;r+=2){let t=Math.abs(d-l*e[r+1]+u*e[r]);if(t>b){x=r;b=t}}if(b>(c*y)**2){this.#o(e,t,x+2,r);this.#o(e,x,n,r)}else r.push(i,a)}static#s(e){let t=[],n=e.length;this.#o(e,0,n,t);t.push(e[n-2],e[n-1]);return t.length<=4?null:t}static#c(e,t,n,r,i,a){let o=new Float32Array(a**2),s=-2*r**2,c=a>>1;for(let e=0;e<a;e++){let t=(e-c)**2;for(let n=0;n<a;n++)o[e*a+n]=Math.exp((t+(n-c)**2)/s)}let l=new Float32Array(256),u=-2*i**2;for(let e=0;e<256;e++)l[e]=Math.exp(e**2/u);let d=e.length,f=new Uint8Array(d),p=new Uint32Array(256);for(let r=0;r<n;r++)for(let i=0;i<t;i++){let s=r*t+i,u=e[s],d=0,m=0;for(let s=0;s<a;s++){let f=r+s-c;if(!(f<0||f>=n))for(let n=0;n<a;n++){let r=i+n-c;if(r<0||r>=t)continue;let p=e[f*t+r],h=o[s*a+n]*l[Math.abs(p-u)];d+=p*h;m+=h}}p[f[s]=Math.round(d/m)]++}return[f,p]}static#l(e){let t=new Uint32Array(256);for(let n of e)t[n]++;return t}static#u(e){let t=e.length,n=new Uint8ClampedArray(t>>2),r=-1/0,i=1/0;for(let t=0,a=n.length;t<a;t++){let a=n[t]=e[t<<2];r=Math.max(r,a);i=Math.min(i,a)}let a=255/(r-i);for(let e=0,t=n.length;e<t;e++)n[e]=(n[e]-i)*a;return n}static#d(e){let t,n=-1/0,r=-1/0,i=e.findIndex(e=>e!==0),a=i,o=i;for(t=i;t<256;t++){let i=e[t];if(i>n){if(t-a>r){r=t-a;o=t-1}n=i;a=t}}for(t=o-1;t>=0&&!(e[t]>e[t+1]);t--);return t}static#f(e){let t=e,{width:n,height:r}=e,{maxDim:i}=this.#e,a=n,o=r;if(n>i||r>i){let s=n,c=r,l=Math.log2(Math.max(n,r)/i),u=Math.floor(l);l=l===u?u-1:u;for(let n=0;n<l;n++){a=Math.ceil(s/2);o=Math.ceil(c/2);let n=new OffscreenCanvas(a,o);n.getContext(`2d`).drawImage(e,0,0,s,c,0,0,a,o);s=a;c=o;e!==t&&e.close();e=n.transferToImageBitmap()}let d=Math.min(i/a,i/o);a=Math.round(a*d);o=Math.round(o*d)}let s=new OffscreenCanvas(a,o).getContext(`2d`,{willReadFrequently:!0});s.fillStyle=`white`;s.fillRect(0,0,a,o);s.filter=`grayscale(1)`;s.drawImage(e,0,0,e.width,e.height,0,0,a,o);let c=s.getImageData(0,0,a,o).data;return[this.#u(c),a,o]}static extractContoursFromText(e,{fontFamily:t,fontStyle:n,fontWeight:r},i,a,o,s){let c=new OffscreenCanvas(1,1),l=c.getContext(`2d`,{alpha:!1}),u=l.font=`${n} ${r} 200px ${t}`,{actualBoundingBoxLeft:d,actualBoundingBoxRight:f,actualBoundingBoxAscent:p,actualBoundingBoxDescent:m,fontBoundingBoxAscent:h,fontBoundingBoxDescent:g,width:_}=l.measureText(e),v=1.5,y=Math.ceil(Math.max(Math.abs(d)+Math.abs(f)||0,_)*v),b=Math.ceil(Math.max(Math.abs(p)+Math.abs(m)||200,Math.abs(h)+Math.abs(g)||200)*v);c=new OffscreenCanvas(y,b);l=c.getContext(`2d`,{alpha:!0,willReadFrequently:!0});l.font=u;l.filter=`grayscale(1)`;l.fillStyle=`white`;l.fillRect(0,0,y,b);l.fillStyle=`black`;l.fillText(e,.5*y/2,1.5*b/2);let x=this.#u(l.getImageData(0,0,y,b).data),S=this.#l(x),C=this.#d(S),w=this.#a(x,y,b,C);return this.processDrawnLines({lines:{curves:w,width:y,height:b},pageWidth:i,pageHeight:a,rotation:o,innerMargin:s,mustSmooth:!0,areContours:!0})}static process(e,t,n,r,i){let[a,o,s]=this.#f(e),[c,l]=this.#c(a,o,s,Math.hypot(o,s)*this.#e.sigmaSFactor,this.#e.sigmaR,this.#e.kernelSize),u=this.#d(l),d=this.#a(c,o,s,u);return this.processDrawnLines({lines:{curves:d,width:o,height:s},pageWidth:t,pageHeight:n,rotation:r,innerMargin:i,mustSmooth:!0,areContours:!0})}static processDrawnLines({lines:e,pageWidth:t,pageHeight:n,rotation:r,innerMargin:i,mustSmooth:a,areContours:o}){r%180!=0&&([t,n]=[n,t]);let{curves:s,width:c,height:l}=e,u=e.thickness??0,d=[],f=Math.min(t/c,n/l),p=f/t,m=f/n,h=[];for(let{points:e}of s){let t=a?this.#s(e):e;if(!t)continue;h.push(t);let n=t.length,r=new Float32Array(n),i=new Float32Array(3*(n===2?2:n-2));d.push({line:i,points:r});if(n===2){r[0]=t[0]*p;r[1]=t[1]*m;i.set([NaN,NaN,NaN,NaN,r[0],r[1]],0);continue}let[o,s,c,l]=t;o*=p;s*=m;c*=p;l*=m;r.set([o,s,c,l],0);i.set([NaN,NaN,NaN,NaN,o,s],0);for(let e=4;e<n;e+=2){let n=r[e]=t[e]*p,a=r[e+1]=t[e+1]*m;i.set(Z.createBezierPoints(o,s,c,l,n,a),3*(e-2));[o,s,c,l]=[c,l,n,a]}}if(d.length===0)return null;let g=o?new kr:new Er;g.build(d,t,n,1,r,o?0:u,i);return{outline:g,newCurves:h,areContours:o,thickness:u,width:c,height:l}}static async compressSignature({outlines:e,areContours:t,thickness:n,width:r,height:i}){let a,o=1/0,s=-1/0,c=0;for(let t of e){c+=t.length;for(let e=2,n=t.length;e<n;e++){let n=t[e]-t[e-2];o=Math.min(o,n);s=Math.max(s,n)}}a=o>=-128&&s<=127?Int8Array:o>=-32768&&s<=32767?Int16Array:Int32Array;let l=e.length,u=8+3*l,d=new Uint32Array(u),f=0;d[f++]=u*Uint32Array.BYTES_PER_ELEMENT+(c-2*l)*a.BYTES_PER_ELEMENT;d[f++]=0;d[f++]=r;d[f++]=i;d[f++]=+!t;d[f++]=Math.max(0,Math.floor(n??0));d[f++]=l;d[f++]=a.BYTES_PER_ELEMENT;for(let t of e){d[f++]=t.length-2;d[f++]=t[0];d[f++]=t[1]}let p=new CompressionStream(`deflate-raw`),m=p.writable.getWriter();await m.ready;m.write(d);let h=a.prototype.constructor;for(let t of e){let e=new h(t.length-2);for(let n=2,r=t.length;n<r;n++)e[n-2]=t[n]-t[n-2];m.write(e)}m.close();return(await new Response(p.readable).bytes()).toBase64()}static async decompressSignature(e){try{let t=Uint8Array.fromBase64(e),{readable:n,writable:r}=new DecompressionStream(`deflate-raw`),i=r.getWriter();await i.ready;i.write(t).then(async()=>{await i.ready;await i.close()}).catch(()=>{});let a=null,o=0;for await(let e of n){a||=new Uint8Array(new Uint32Array(e.buffer,0,4)[0]);a.set(e,o);o+=e.length}let s=new Uint32Array(a.buffer,0,a.length>>2),c=s[1];if(c!==0)throw Error(`Invalid version: ${c}`);let l=s[2],u=s[3],d=s[4]===0,f=s[5],p=s[6],m=s[7],h=[],g=(8+3*p)*Uint32Array.BYTES_PER_ELEMENT,_;switch(m){case Int8Array.BYTES_PER_ELEMENT:_=new Int8Array(a.buffer,g);break;case Int16Array.BYTES_PER_ELEMENT:_=new Int16Array(a.buffer,g);break;case Int32Array.BYTES_PER_ELEMENT:_=new Int32Array(a.buffer,g)}o=0;for(let e=0;e<p;e++){let t=s[3*e+8],n=new Float32Array(t+2);h.push(n);for(let t=0;t<2;t++)n[t]=s[3*e+8+t+1];for(let e=0;e<t;e++)n[e+2]=n[e]+_[o++]}return{areContours:d,thickness:f,outlines:h,width:l,height:u}}catch(e){O(`decompressSignature: ${e}`);return null}}}class jr extends wr{constructor(){super();super.updateProperties({fill:V._defaultLineColor,"stroke-width":0})}clone(){let e=new jr;e.updateAll(this);return e}}class Mr extends Dr{constructor(e){super(e);super.updateProperties({stroke:V._defaultLineColor,"stroke-width":1})}clone(){let e=new Mr(this._viewParameters);e.updateAll(this);return e}}class Nr extends ${#e=!1;#t=null;#n=null;#r=null;static _type=`signature`;static _editorType=y.SIGNATURE;static _defaultDrawingOptions=null;constructor(e){super({...e,mustBeCommitted:!0,name:`signatureEditor`});this._willKeepAspectRatio=!0;this.#n=e.signatureData||null;this.#t=null;this.defaultL10nId=`pdfjs-editor-signature-editor1`}static initialize(e,t){V.initialize(e,t);this._defaultDrawingOptions=new jr;this._defaultDrawnSignatureOptions=new Mr(t.viewParameters)}static getDefaultDrawingOptions(e){let t=this._defaultDrawingOptions.clone();t.updateProperties(e);return t}static get supportMultipleDrawings(){return!1}static get typesMap(){return j(this,`typesMap`,new Map)}static get isDrawer(){return!1}get telemetryFinalData(){return{type:`signature`,hasDescription:!!this.#t}}static computeTelemetryFinalData(e){let t=e.get(`hasDescription`);return{hasAltText:t.get(!0)??0,hasNoAltText:t.get(!1)??0}}get isResizable(){return!0}onScaleChanging(){this._drawId!==null&&super.onScaleChanging()}render(){if(this.div)return this.div;let e,t,{_isCopy:n}=this;if(n){this._isCopy=!1;e=this.x;t=this.y}super.render();if(this._drawId===null){if(this.#n){let{lines:e,mustSmooth:t,areContours:n,description:r,uuid:i,heightInPage:a}=this.#n,{rawDims:{pageWidth:o,pageHeight:s},rotation:c}=this.parent.viewport,l=Ar.processDrawnLines({lines:e,pageWidth:o,pageHeight:s,rotation:c,innerMargin:Nr._INNER_MARGIN,mustSmooth:t,areContours:n});this.addSignature(l,a,r,i)}else{this.div.setAttribute(`data-l10n-args`,JSON.stringify({description:``}));this.div.hidden=!0;this._uiManager.getSignature(this)}}else this.div.setAttribute(`data-l10n-args`,JSON.stringify({description:this.#t||``}));if(n){this._isCopy=!0;this._moveAfterPaste(e,t)}return this.div}setUuid(e){this.#r=e;this.addEditToolbar()}getUuid(){return this.#r}get description(){return this.#t}set description(e){this.#t=e;if(this.div){this.div.setAttribute(`data-l10n-args`,JSON.stringify({description:e}));super.addEditToolbar().then(t=>{t?.updateEditSignatureButton(e)})}}getSignaturePreview(){let{newCurves:e,areContours:t,thickness:n,width:r,height:i}=this.#n,a=Math.max(r,i);return{areContours:t,outline:Ar.processDrawnLines({lines:{curves:e.map(e=>({points:e})),thickness:n,width:r,height:i},pageWidth:a,pageHeight:a,rotation:0,innerMargin:0,mustSmooth:!1,areContours:t}).outline}}get toolbarButtons(){return this._uiManager.signatureManager?[[`editSignature`,this._uiManager.signatureManager]]:super.toolbarButtons}addSignature(e,t,n,r){let{x:i,y:a}=this,{outline:o}=this.#n=e;this.#e=o instanceof kr;this.description=n;let s;if(this.#e)s=Nr.getDefaultDrawingOptions();else{s=Nr._defaultDrawnSignatureOptions.clone();s.updateProperties({"stroke-width":o.thickness})}this._addOutlines({drawOutlines:o,drawingOptions:s});let[,c]=this.pageDimensions,l=t/c;l=l>=1?.5:l;this.width*=l/this.height;if(this.width>=1){l*=.9/this.width;this.width=.9}this.height=l;this.setDims();this.x=i;this.y=a;this.center();this._onResized();this.onScaleChanging();this.rotate();this._uiManager.addToAnnotationStorage(this);this.setUuid(r);this._reportTelemetry({action:`pdfjs.signature.inserted`,data:{hasBeenSaved:!!r,hasDescription:!!n}});this.div.hidden=!1}getFromImage(e){let{rawDims:{pageWidth:t,pageHeight:n},rotation:r}=this.parent.viewport;return Ar.process(e,t,n,r,Nr._INNER_MARGIN)}getFromText(e,t){let{rawDims:{pageWidth:n,pageHeight:r},rotation:i}=this.parent.viewport;return Ar.extractContoursFromText(e,t,n,r,i,Nr._INNER_MARGIN)}getDrawnSignature(e){let{rawDims:{pageWidth:t,pageHeight:n},rotation:r}=this.parent.viewport;return Ar.processDrawnLines({lines:e,pageWidth:t,pageHeight:n,rotation:r,innerMargin:Nr._INNER_MARGIN,mustSmooth:!1,areContours:!1})}createDrawingOptions({areContours:e,thickness:t}){if(e)this._drawingOptions=Nr.getDefaultDrawingOptions();else{this._drawingOptions=Nr._defaultDrawnSignatureOptions.clone();this._drawingOptions.updateProperties({"stroke-width":t})}}serialize(e=!1){if(this.isEmpty())return null;let{lines:t,points:n}=this.serializeDraw(e),{_drawingOptions:{"stroke-width":r}}=this,i=Object.assign(super.serialize(e),{isSignature:!0,areContours:this.#e,color:[0,0,0],thickness:this.#e?0:r});this.addComment(i);if(e){i.paths={lines:t,points:n};i.uuid=this.#r;i.isCopy=!0}else i.lines=t;this.#t&&(i.accessibilityData={type:`Figure`,alt:this.#t});return i}static deserializeDraw(e,t,n,r,i,a){return a.areContours?kr.deserialize(e,t,n,r,i,a):Er.deserialize(e,t,n,r,i,a)}static async deserialize(e,t,n){let r=await super.deserialize(e,t,n);r.#e=e.areContours;r.description=e.accessibilityData?.alt||``;r.#r=e.uuid;return r}}class Pr extends V{#e=null;#t=null;#n=null;#r=null;#i=null;#a=``;#o=null;#s=!1;#c=null;#l=!1;#u=!1;static _type=`stamp`;static _editorType=y.STAMP;constructor(e){super({...e,name:`stampEditor`});this.#r=e.bitmapUrl;this.#i=e.bitmapFile;this.defaultL10nId=`pdfjs-editor-stamp-editor`}static initialize(e,t){V.initialize(e,t)}static isHandlingMimeForPasting(e){return ke.includes(e)}static paste(e,t){t.pasteEditor({mode:y.STAMP},{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1);super.altTextFinish()}get telemetryFinalData(){return{type:`stamp`,hasAltText:!!this.altTextData?.altText}}static computeTelemetryFinalData(e){let t=e.get(`hasAltText`);return{hasAltText:t.get(!0)??0,hasNoAltText:t.get(!1)??0}}#d(e,t=!1){if(e){this.#e=e.bitmap;if(!t){this.#t=e.id;this.#l=e.isSvg}e.file&&(this.#a=e.file.name);this.#m()}else this.remove()}#f(){this.#n=null;this._uiManager.enableWaiting(!1);if(this.#o){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#e)this.addEditToolbar().then(()=>{this._editToolbar.hide();this._uiManager.editAltText(this,!0)});else{if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#e){this._reportTelemetry({action:`pdfjs.image.image_added`,data:{alt_text_modal:!1,alt_text_type:`empty`}});try{this.mlGuessAltText()}catch{}}this.div.focus()}}}async mlGuessAltText(e=null,t=!0){if(this.hasAltTextData())return null;let{mlManager:n}=this._uiManager;if(!n)throw Error(`No ML.`);if(!await n.isEnabledFor(`altText`))throw Error(`ML isn't enabled for alt text.`);let{data:r,width:i,height:a}=e||this.copyCanvas(null,null,!0).imageData,o=await n.guess({name:`altText`,request:{data:r,width:i,height:a,channels:r.length/(i*a)}});if(!o)throw Error(`No response from the AI service.`);if(o.error)throw Error(`Error from the AI service.`);if(o.cancel)return null;if(!o.output)throw Error(`No valid response from the AI service.`);let s=o.output;await this.setGuessedAltText(s);t&&!this.hasAltTextData()&&(this.altTextData={alt:s,decorative:!1});return s}#p(){if(this.#t){this._uiManager.enableWaiting(!0);this._uiManager.imageManager.getFromId(this.#t).then(e=>this.#d(e,!0)).finally(()=>this.#f());return}if(this.#r){let e=this.#r;this.#r=null;this._uiManager.enableWaiting(!0);this.#n=this._uiManager.imageManager.getFromUrl(e).then(e=>this.#d(e)).finally(()=>this.#f());return}if(this.#i){let e=this.#i;this.#i=null;this._uiManager.enableWaiting(!0);this.#n=this._uiManager.imageManager.getFromFile(e).then(e=>this.#d(e)).finally(()=>this.#f());return}let e=document.createElement(`input`);e.type=`file`;e.accept=ke.join(`,`);let t=this._uiManager._signal;this.#n=new Promise(n=>{e.addEventListener(`change`,async()=>{if(e.files&&e.files.length!==0){this._uiManager.enableWaiting(!0);let t=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:`pdfjs.image.image_selected`,data:{alt_text_modal:this._uiManager.useNewAltTextFlow}});this.#d(t)}else this.remove();n()},{signal:t});e.addEventListener(`cancel`,()=>{this.remove();n()},{signal:t})}).finally(()=>this.#f());e.click()}remove(){if(this.#t){this.#e=null;this._uiManager.imageManager.deleteId(this.#t);this.#o?.remove();this.#o=null;if(this.#c){clearTimeout(this.#c);this.#c=null}}super.remove()}rebuild(){if(this.parent){super.rebuild();if(this.div!==null){this.#t&&this.#o===null&&this.#p();this.isAttachedToDOM||this.parent.add(this)}}else this.#t&&this.#p()}onceAdded(e){this._isDraggable=!0;e&&this.div.focus()}isEmpty(){return!(this.#n||this.#e||this.#r||this.#i||this.#t||this.#s)}get toolbarButtons(){return[[`altText`,this.createAltText()]]}get isResizable(){return!0}render(){if(this.div)return this.div;let e,t;if(this._isCopy){e=this.x;t=this.y}super.render();this.div.hidden=!0;this.createAltText();this.#s||(this.#e?this.#m():this.#p());this._isCopy&&this._moveAfterPaste(e,t);this._uiManager.addShouldRescale(this);return this.div}setCanvas(e,t){let{id:n,bitmap:r}=this._uiManager.imageManager.getFromCanvas(e,t);t.remove();if(n&&this._uiManager.imageManager.isValidId(n)){this.#t=n;r&&(this.#e=r);this.#s=!1;this.#m()}}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;this.#c!==null&&clearTimeout(this.#c);this.#c=setTimeout(()=>{this.#c=null;this.#g()},200)}#m(){let{div:e}=this,{width:t,height:n}=this.#e,[r,i]=this.pageDimensions,a=.75;if(this.width){t=this.width*r;n=this.height*i}else if(t>a*r||n>a*i){let e=Math.min(a*r/t,a*i/n);t*=e;n*=e}this._uiManager.enableWaiting(!1);let o=this.#o=document.createElement(`canvas`);o.setAttribute(`role`,`img`);this.addContainer(o);this.width=t/r;this.height=n/i;this.setDims();this._initialOptions?.isCentered?this.center():this.fixAndSetPosition();this._initialOptions=null;this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&!this.annotationElementId||(e.hidden=!1);this.#g();if(!this.#u){this.parent.addUndoableEditor(this);this.#u=!0}this._reportTelemetry({action:`inserted_image`});this.#a&&this.div.setAttribute(`aria-description`,this.#a);this.annotationElementId||this._uiManager.a11yAlert(V._l10nAlert.stamp)}copyCanvas(e,t,n=!1){e||=224;let{width:r,height:i}=this.#e,a=new Oe,o=this.#e,s=r,c=i,l=null;if(t){if(r>t||i>t){let e=Math.min(t/r,t/i);s=Math.floor(r*e);c=Math.floor(i*e)}l=document.createElement(`canvas`);let e=l.width=Math.ceil(s*a.sx),n=l.height=Math.ceil(c*a.sy);this.#l||(o=this.#h(e,n));let u=l.getContext(`2d`);u.filter=this._uiManager.hcmFilter;let d=`white`,f=`#cfcfd8`;if(this._uiManager.hcmFilter!==`none`)f=`black`;else if(Ae.isDarkMode){d=`#8f8f9d`;f=`#42414d`}let p=15*a.sx,m=15*a.sy,h=new OffscreenCanvas(2*p,2*m),g=h.getContext(`2d`);g.fillStyle=d;g.fillRect(0,0,2*p,2*m);g.fillStyle=f;g.fillRect(0,0,p,m);g.fillRect(p,m,p,m);u.fillStyle=u.createPattern(h,`repeat`);u.fillRect(0,0,e,n);u.drawImage(o,0,0,o.width,o.height,0,0,e,n)}let u=null;if(n){let t,n;if(a.symmetric&&o.width<e&&o.height<e){t=o.width;n=o.height}else{o=this.#e;if(r>e||i>e){let a=Math.min(e/r,e/i);t=Math.floor(r*a);n=Math.floor(i*a);this.#l||(o=this.#h(t,n))}}let s=new OffscreenCanvas(t,n).getContext(`2d`,{willReadFrequently:!0});s.drawImage(o,0,0,o.width,o.height,0,0,t,n);u={width:t,height:n,data:s.getImageData(0,0,t,n).data}}return{canvas:l,width:s,height:c,imageData:u}}#h(e,t){let{width:n,height:r}=this.#e,i=n,a=r,o=this.#e;for(;i>2*e||a>2*t;){let n=i,r=a;i>2*e&&(i=Math.ceil(i/2));a>2*t&&(a=Math.ceil(a/2));let s=new OffscreenCanvas(i,a);s.getContext(`2d`).drawImage(o,0,0,n,r,0,0,i,a);o=s.transferToImageBitmap()}return o}#g(){let[e,t]=this.parentDimensions,{width:n,height:r}=this,i=new Oe,a=Math.ceil(n*e*i.sx),o=Math.ceil(r*t*i.sy),s=this.#o;if(!s||s.width===a&&s.height===o)return;s.width=a;s.height=o;let c=this.#l?this.#e:this.#h(a,o),l=s.getContext(`2d`);l.filter=this._uiManager.hcmFilter;l.drawImage(c,0,0,c.width,c.height,0,0,a,o)}#_(e){if(e){if(this.#l){let e=this._uiManager.imageManager.getSvgUrl(this.#t);if(e)return e}let e=document.createElement(`canvas`);({width:e.width,height:e.height}=this.#e);e.getContext(`2d`).drawImage(this.#e,0,0);return e.toDataURL()}if(this.#l){let[e,t]=this.pageDimensions,n=Math.round(this.width*e*he.PDF_TO_CSS_UNITS),r=Math.round(this.height*t*he.PDF_TO_CSS_UNITS),i=new OffscreenCanvas(n,r);i.getContext(`2d`).drawImage(this.#e,0,0,this.#e.width,this.#e.height,0,0,n,r);return i.transferToImageBitmap()}return structuredClone(this.#e)}static async deserialize(e,t,n){let r=null,i=!1;if(e instanceof gr){let{data:{rect:a,rotation:o,id:s,structParent:c,popupRef:l,richText:u,contentsObj:d,creationDate:f,modificationDate:p},container:m,parent:{page:{pageNumber:h}},canvas:g}=e,v,b;if(g){delete e.canvas;({id:v,bitmap:b}=n.imageManager.getFromCanvas(m.id,g));g.remove()}else{i=!0;e._hasNoCanvas=!0}let x=(await t._structTree.getAriaAttributes(`${_}${s}`))?.get(`aria-label`)||``;r=e={annotationType:y.STAMP,bitmapId:v,bitmap:b,pageIndex:h-1,rect:a.slice(0),rotation:o,annotationElementId:s,id:s,deleted:!1,accessibilityData:{decorative:!1,altText:x},isSvg:!1,structParent:c,popupRef:l,richText:u,comment:d?.str||null,creationDate:f,modificationDate:p}}let a=await super.deserialize(e,t,n),{rect:o,bitmap:s,bitmapUrl:c,bitmapId:l,isSvg:u,accessibilityData:d}=e;if(i){n.addMissingCanvas(e.id,a);a.#s=!0}else if(l&&n.imageManager.isValidId(l)){a.#t=l;s&&(a.#e=s)}else a.#r=c;a.#l=u;let[f,p]=a.pageDimensions;a.width=(o[2]-o[0])/f;a.height=(o[3]-o[1])/p;d&&(a.altTextData=d);a._initialData=r;e.comment&&a.setCommentData(e);a.#u=!!r;return a}serialize(e=!1,t=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let n=Object.assign(super.serialize(e),{bitmapId:this.#t,isSvg:this.#l});this.addComment(n);if(e){n.bitmapUrl=this.#_(!0);n.accessibilityData=this.serializeAltText(!0);n.isCopy=!0;return n}let{decorative:r,altText:i}=this.serializeAltText(!1);!r&&i&&(n.accessibilityData={type:`Figure`,alt:i});if(this.annotationElementId){let e=this.#v(n);if(e.isSame)return null;e.isSameAltText?delete n.accessibilityData:n.accessibilityData.structParent=this._initialData.structParent??-1;n.id=this.annotationElementId;delete n.bitmapId;return n}if(t===null)return n;t.stamps||=new Map;let a=this.#l?(n.rect[2]-n.rect[0])*(n.rect[3]-n.rect[1]):null;if(t.stamps.has(this.#t)){if(this.#l){let e=t.stamps.get(this.#t);if(a>e.area){e.area=a;e.serialized.bitmap.close();e.serialized.bitmap=this.#_(!1)}}}else{t.stamps.set(this.#t,{area:a,serialized:n});n.bitmap=this.#_(!1)}return n}#v(e){let{pageIndex:t,accessibilityData:{altText:n}}=this._initialData,r=e.pageIndex===t,i=(e.accessibilityData?.alt||``)===n;return{isSame:!this.hasEditedComment&&!this._hasBeenMoved&&!this._hasBeenResized&&r&&i,isSameAltText:i}}renderAnnotationElement(e){if(this.deleted){e.hide();return null}e.updateEdited({rect:this.getPDFRect(),popup:this.comment});return null}}class Fr{#e;#t=!1;#n=null;#r=null;#i=null;#a=new Map;#o=!1;#s=!1;#c=!1;#l=null;#u=null;#d=null;#f=null;#p=null;#m=-1;#h;static _initialized=!1;static#g=new Map([X,Or,Pr,Q,Nr].map(e=>[e._editorType,e]));constructor({uiManager:e,pageIndex:t,div:n,structTreeLayer:r,accessibilityManager:i,annotationLayer:a,drawLayer:o,textLayer:s,viewport:c,l10n:l}){let u=[...Fr.#g.values()];if(!Fr._initialized){Fr._initialized=!0;for(let t of u)t.initialize(l,e)}e.registerEditorTypes(u);this.#h=e;this.pageIndex=t;this.div=n;this.#e=i;this.#n=a;this.viewport=c;this.#d=s;this.drawLayer=o;this._structTree=r;this.#h.addLayer(this)}get isEmpty(){return this.#a.size===0}get isInvisible(){return this.isEmpty&&this.#h.getMode()===y.NONE}updateToolbar(e){this.#h.updateToolbar(e)}updateMode(e=this.#h.getMode()){this.#S();switch(e){case y.NONE:this.div.classList.toggle(`nonEditing`,!0);this.disableTextSelection();this.togglePointerEvents(!1);this.toggleAnnotationLayerPointerEvents(!0);this.disableClick();return;case y.INK:this.disableTextSelection();this.togglePointerEvents(!0);this.enableClick();break;case y.HIGHLIGHT:this.enableTextSelection();this.togglePointerEvents(!1);this.disableClick();break;default:this.disableTextSelection();this.togglePointerEvents(!0);this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);let{classList:t}=this.div;t.toggle(`nonEditing`,!1);if(e===y.POPUP)t.toggle(`commentEditing`,!0);else{t.toggle(`commentEditing`,!1);for(let n of Fr.#g.values())t.toggle(`${n._type}Editing`,e===n._editorType)}this.div.hidden=!1}hasTextLayer(e){return e===this.#d?.div}setEditingState(e){this.#h.setEditingState(e)}addCommands(e){this.#h.addCommands(e)}cleanUndoStack(e){this.#h.cleanUndoStack(e)}toggleDrawing(e=!1){this.div.classList.toggle(`drawing`,!e)}togglePointerEvents(e=!1){this.div.classList.toggle(`disabled`,!e)}toggleAnnotationLayerPointerEvents(e=!1){this.#n?.togglePointerEvents(e)}get#_(){return this.#a.size===0?this.#h.getEditors(this.pageIndex):this.#a.values()}async enable(){this.#c=!0;this.div.tabIndex=0;this.togglePointerEvents(!0);this.div.classList.toggle(`nonEditing`,!1);this.#p?.abort();this.#p=null;let e=new Set;for(let t of this.#_){t.enableEditing();t.show(!0);if(t.annotationElementId){this.#h.removeChangedExistingAnnotation(t);e.add(t.annotationElementId)}}let t=this.#n;if(t)for(let n of t.getEditableAnnotations()){n.hide();if(this.#h.isDeletedAnnotationElement(n.data.id))continue;if(e.has(n.data.id))continue;let t=await this.deserialize(n);if(t){this.addOrRebuild(t);t.enableEditing()}}this.#c=!1;this.#h._eventBus.dispatch(`editorsrendered`,{source:this,pageNumber:this.pageIndex+1})}disable(){this.#s=!0;this.div.tabIndex=-1;this.togglePointerEvents(!1);this.div.classList.toggle(`nonEditing`,!0);if(this.#d&&!this.#p){this.#p=new AbortController;let e=this.#h.combinedSignal(this.#p);this.#d.div.addEventListener(`pointerdown`,e=>{let{clientX:t,clientY:n,timeStamp:r}=e;if(r-this.#m>500){this.#m=r;return}this.#m=-1;let{classList:i}=this.div;i.toggle(`getElements`,!0);let a=document.elementsFromPoint(t,n);i.toggle(`getElements`,!1);if(!this.div.contains(a[0]))return;let o,s=RegExp(`^${v}[0-9]+$`);for(let e of a)if(s.test(e.id)){o=e.id;break}if(!o)return;let c=this.#a.get(o);if(c?.annotationElementId===null){R(e);c.dblclick(e)}},{signal:e,capture:!0})}let e=this.#n,t=[];if(e){let n=new Map,r=new Map;for(let e of this.#_){e.disableEditing();if(e.annotationElementId){if(e.serialize()===null){r.set(e.annotationElementId,e);this.getEditableAnnotation(e.annotationElementId)?.show();e.remove()}else n.set(e.annotationElementId,e)}else t.push(e)}for(let t of e.getEditableAnnotations()){let{id:e}=t.data;if(this.#h.isDeletedAnnotationElement(e)){t.updateEdited({deleted:!0});continue}let i=r.get(e);if(i){i.resetAnnotationElement(t);i.show(!1);t.show()}else{i=n.get(e);if(i){this.#h.addChangedExistingAnnotation(i);i.renderAnnotationElement(t)&&i.show(!1)}t.show()}}}this.#S();this.isEmpty&&(this.div.hidden=!0);let{classList:n}=this.div;for(let e of Fr.#g.values())n.remove(`${e._type}Editing`);this.disableTextSelection();this.toggleAnnotationLayerPointerEvents(!0);e?.updateFakeAnnotations(t);this.#s=!1}getEditableAnnotation(e){return this.#n?.getEditableAnnotation(e)||null}setActiveEditor(e){this.#h.getActive()!==e&&this.#h.setActiveEditor(e)}enableTextSelection(){this.div.tabIndex=-1;if(this.#d?.div&&!this.#f){this.#f=new AbortController;let e=this.#h.combinedSignal(this.#f);this.#d.div.addEventListener(`pointerdown`,this.#v.bind(this),{signal:e});this.#d.div.classList.add(`highlighting`)}}disableTextSelection(){this.div.tabIndex=0;if(this.#d?.div&&this.#f){this.#f.abort();this.#f=null;this.#d.div.classList.remove(`highlighting`)}}#v(e){this.#h.unselectAll();let{target:t}=e;if(t===this.#d.div||(t.getAttribute(`role`)===`img`||t.classList.contains(`endOfContent`)||t.classList.contains(`textLayerImages`)||t.classList.contains(`textLayerImagePlaceholder`))&&this.#d.div.contains(t)){let{isMac:t}=N.platform;if(e.button!==0||e.ctrlKey&&t)return;this.#h.showAllEditors(`highlight`,!0,!0);this.#d.div.classList.add(`free`);this.toggleDrawing();Q.startHighlighting(this,this.#h.direction===`ltr`,{target:this.#d.div,x:e.x,y:e.y});this.#d.div.addEventListener(`pointerup`,()=>{this.#d.div.classList.remove(`free`);this.toggleDrawing(!0)},{once:!0,signal:this.#h._signal});e.preventDefault()}}enableClick(){if(this.#r)return;this.#r=new AbortController;let e=this.#h.combinedSignal(this.#r);this.div.addEventListener(`pointerdown`,this.pointerdown.bind(this),{signal:e});let t=this.pointerup.bind(this);this.div.addEventListener(`pointerup`,t,{signal:e});this.div.addEventListener(`pointercancel`,t,{signal:e})}disableClick(){this.#r?.abort();this.#r=null}attach(e){this.#a.set(e.id,e);let{annotationElementId:t}=e;t&&this.#h.isDeletedAnnotationElement(t)&&this.#h.removeDeletedAnnotationElement(e)}detach(e){this.#a.delete(e.id);this.#e?.removePointerInTextLayer(e.contentDiv);!this.#s&&e.annotationElementId&&this.#h.addDeletedAnnotationElement(e)}remove(e){this.detach(e);this.#h.removeEditor(e);e.div.remove();e.isAttachedToDOM=!1}changeParent(e){if(e.parent!==this){if(e.parent&&e.annotationElementId){this.#h.addDeletedAnnotationElement(e);V.deleteAnnotationElement(e);e.annotationElementId=null}this.attach(e);e.parent?.detach(e);e.setParent(this);if(e.div&&e.isAttachedToDOM){e.div.remove();this.div.append(e.div)}}}add(e){if(e.parent!==this||!e.isAttachedToDOM){this.changeParent(e);this.#h.addEditor(e);this.attach(e);if(!e.isAttachedToDOM){let t=e.render();this.div.append(t);e.isAttachedToDOM=!0}e.fixAndSetPosition();e.onceAdded(!this.#c);this.#h.addToAnnotationStorage(e);e._reportTelemetry(e.telemetryInitialData)}}moveEditorInDOM(e){if(!e.isAttachedToDOM)return;let{activeElement:t}=document;if(e.div.contains(t)&&!this.#i){e._focusEventsAllowed=!1;this.#i=setTimeout(()=>{this.#i=null;if(e.div.contains(document.activeElement))e._focusEventsAllowed=!0;else{e.div.addEventListener(`focusin`,()=>{e._focusEventsAllowed=!0},{once:!0,signal:this.#h._signal});t.focus()}},0)}e._structTreeParentId=this.#e?.moveElementInDOM(this.div,e.div,e.contentDiv,!0)}addOrRebuild(e){if(e.needsToBeRebuilt()){e.parent||=this;e.rebuild();e.show()}else this.add(e)}addUndoableEditor(e){this.addCommands({cmd:()=>e._uiManager.rebuild(e),undo:()=>{e.remove()},mustExec:!1})}getEditorByUID(e){for(let t of this.#a.values())if(t.uid===e)return t;return null}get#y(){return Fr.#g.get(this.#h.getMode())}combinedSignal(e){return this.#h.combinedSignal(e)}#b(e){let t=this.#y;return t?new t.prototype.constructor(e):null}canCreateNewEmptyEditor(){return this.#y?.canCreateNewEmptyEditor()}async pasteEditor(e,t){this.updateToolbar(e);await this.#h.updateMode(e.mode);let{offsetX:n,offsetY:r}=this.#x(),i=this.#h.getId(),a=this.#b({parent:this,id:i,x:n,y:r,uiManager:this.#h,isCentered:!0,...t});a&&this.add(a)}async deserialize(e){return await Fr.#g.get(e.annotationType??e.annotationEditorType)?.deserialize(e,this,this.#h)||null}createAndAddNewEditor(e,t,n={}){let r=this.#h.getId(),i=this.#b({parent:this,id:r,x:e.offsetX,y:e.offsetY,uiManager:this.#h,isCentered:t,...n});i&&this.add(i);return i}get boundingClientRect(){return this.div.getBoundingClientRect()}#x(){let{x:e,y:t,width:n,height:r}=this.boundingClientRect,i=Math.max(0,e),a=Math.max(0,t),o=(i+Math.min(window.innerWidth,e+n))/2-e,s=(a+Math.min(window.innerHeight,t+r))/2-t,[c,l]=this.viewport.rotation%180==0?[o,s]:[s,o];return{offsetX:c,offsetY:l}}addNewEditor(e={}){this.createAndAddNewEditor(this.#x(),!0,e)}setSelected(e){this.#h.setSelected(e)}toggleSelected(e){this.#h.toggleSelected(e)}unselect(e){this.#h.unselect(e)}pointerup(e){let{isMac:t}=N.platform;if(e.button!==0||e.ctrlKey&&t)return;if(e.target!==this.div)return;if(!this.#o)return;this.#o=!1;if(this.#y?.isDrawer&&this.#y.supportMultipleDrawings)return;if(!this.#t){this.#t=!0;return}let n=this.#h.getMode();n!==y.STAMP&&n!==y.POPUP&&n!==y.SIGNATURE?this.createAndAddNewEditor(e,!1):this.#h.unselectAll()}pointerdown(e){this.#h.getMode()===y.HIGHLIGHT&&this.enableTextSelection();if(this.#o){this.#o=!1;return}let{isMac:t}=N.platform;if(e.button!==0||e.ctrlKey&&t)return;if(e.target!==this.div)return;this.#o=!0;if(this.#y?.isDrawer){this.startDrawingSession(e);return}let n=this.#h.getActive();this.#t=!n||n.isEmpty()}startDrawingSession(e){this.div.focus({preventScroll:!0});if(this.#l){this.#y.startDrawing(this,this.#h,!1,e);return}this.#h.setCurrentDrawingSession(this);this.#l=new AbortController;let t=this.#h.combinedSignal(this.#l);this.div.addEventListener(`blur`,({relatedTarget:e})=>{if(e&&!this.div.contains(e)){this.#u=null;this.commitOrRemove()}},{signal:t});this.#y.startDrawing(this,this.#h,!1,e)}pause(e){if(e){let{activeElement:e}=document;this.div.contains(e)&&(this.#u=e);return}this.#u&&setTimeout(()=>{this.#u?.focus();this.#u=null},0)}endDrawingSession(e=!1){if(!this.#l)return null;this.#h.setCurrentDrawingSession(null);this.#l.abort();this.#l=null;this.#u=null;return this.#y.endDrawing(e)}findNewParent(e,t,n){let r=this.#h.findParent(t,n);if(r===null||r===this)return!1;r.changeParent(e);return!0}commitOrRemove(){if(this.#l){this.endDrawingSession();return!0}return!1}onScaleChanging(){this.#l&&this.#y.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove();if(this.#h.getActive()?.parent===this){this.#h.commitOrRemove();this.#h.setActiveEditor(null)}if(this.#i){clearTimeout(this.#i);this.#i=null}for(let e of this.#a.values()){this.#e?.removePointerInTextLayer(e.contentDiv);e.setParent(null);e.isAttachedToDOM=!1;e.div.remove()}this.div=null;this.#a.clear();this.#h.removeLayer(this)}#S(){for(let e of this.#a.values())e.isEmpty()&&e.remove()}async render({viewport:e}){this.viewport=e;De(this.div,e);for(let e of this.#h.getEditors(this.pageIndex)){this.add(e);e.rebuild()}await this.#h.findClonesForPage(this);this.div.hidden=this.isEmpty;this.updateMode()}update({viewport:e}){this.#h.commitOrRemove();this.#S();let t=this.viewport.rotation,n=e.rotation;this.viewport=e;De(this.div,{rotation:n});if(t!==n)for(let e of this.#a.values())e.rotate(n)}get pageDimensions(){let{pageWidth:e,pageHeight:t}=this.viewport.rawDims;return[e,t]}get scale(){return this.#h.viewParameters.realScale}}globalThis._pdfjsTestingUtils={HighlightOutliner:br};const Ir={fonts:globalThis.fonts,createElement(e){if(e.toLowerCase()===`canvas`)return new OffscreenCanvas(1,1);return null}};class Lr{constructor(){this._pdfDocument=null;this._page=null;this._geospatialMetadata=null;this._baseViewport=null;this._inverseBaseViewport=null;this._pdfWorker=null;this._pdfWorkerBlobUrl=null}async loadPDF(n,s={}){c()||await l();r(s);let[{data:u},d]=await Promise.all([t(n.url,{responseType:`array-buffer`,signal:s?.signal}),this._getPDFWorker(s)]),f=Yn({data:u,wasmUrl:e(`esri/libs/pdfjs/wasm/`),ownerDocument:Ir,enableHWA:!0,useWorkerFetch:!0,worker:d,useWasm:!0});this._pdfDocument=await f.promise;r(s);this._page=await this._pdfDocument.getPage(n.page);r(s);this._geospatialMetadata=await this._page.getGeospatialPDFMetadata();r(s);this._baseViewport=this._page.getViewport({scale:1});this._inverseBaseViewport=i();o(this._inverseBaseViewport,a(...this._baseViewport.transform));return{geospatialMetadata:this._geospatialMetadata}}destroy(){this._page?.cleanup?.();this._page=null;this._pdfDocument?.cleanup();this._pdfDocument=null;this._geospatialMetadata=null;this._baseViewport=null;this._inverseBaseViewport=null;this._pdfWorker?.destroy();this._pdfWorker=null;if(this._pdfWorkerBlobUrl){URL.revokeObjectURL(this._pdfWorkerBlobUrl);this._pdfWorkerBlobUrl=null}}async renderPDF(e,t={}){if(!this._page||!this._baseViewport||!this._inverseBaseViewport)throw new n(`geospatial-pdf-layer-worker:not-loaded`,`PDF not loaded`);r(t);let{width:i,height:a,sourceExtentAsJSON:o,currentRing:c,ctm:l}=e,d=s.fromJSON(o),f=await u(d,i,a,l,this._page,this._baseViewport,this._inverseBaseViewport,c,t);r(t);return Rr(f,i,a)}async _getPDFWorker(n={}){if(this._pdfWorker)return this._pdfWorker;let r=e(`esri/libs/pdfjs/pdf.worker.mjs`),i=(await t(r,{responseType:`blob`,authMode:`anonymous`,signal:n.signal})).data,a=i.type===`application/javascript`||i.type===`text/javascript`?i:new Blob([i],{type:`application/javascript`}),o=URL.createObjectURL(a);try{let e=new Worker(o,{type:`module`,name:`geospatial-pdf-pdfjs-worker`}),t=new q({port:e});await t.promise;this._pdfWorker=t;this._pdfWorkerBlobUrl=o;return t}catch(e){URL.revokeObjectURL(o);throw e}}}function Rr(e,t,r){let i=e.getContext(`2d`);if(!i)throw new n(`geospatial-pdf-raster:canvas`,`Failed to create canvas context.`);let a=i.getImageData(0,0,t,r).data,o=t*r,s=new Uint8Array(o),c=new Uint8Array(o),l=new Uint8Array(o),u=new Uint8Array(o);for(let e=0,t=0;e<o;e++,t+=4){s[e]=a[t];c[e]=a[t+1];l[e]=a[t+2];u[e]=a[t+3]}return{width:t,height:r,red:s,green:c,blue:l,mask:u}}export{Lr as default};
|