@defra/interactive-map 0.0.55-alpha → 0.0.56-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (394) hide show
  1. package/assets/templates/style-switcher.njk +2 -2
  2. package/dist/esm/im-core.js +1 -1
  3. package/dist/esm/im-shell.js +1 -1
  4. package/dist/umd/im-core.js +1 -1
  5. package/dist/umd/index.js +1 -1
  6. package/docs/api/context.md +2 -0
  7. package/docs/api.md +17 -1
  8. package/docs/architecture/interactive-map.likec4 +4 -4
  9. package/docs/plugins/datasets.md +11 -0
  10. package/docs/plugins/draw.md +8 -2
  11. package/docs/plugins/interact.md +24 -1
  12. package/docs/plugins/search.md +2 -2
  13. package/docusaurus.config.cjs +25 -3
  14. package/govuk-prototype-kit.config.json +6 -7
  15. package/package.json +20 -23
  16. package/plugins/datasets/dist/esm/im-datasets-esri-adapter.js +1 -1
  17. package/plugins/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
  18. package/plugins/datasets/dist/esm/im-datasets-ol-adapter.js +1 -1
  19. package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
  20. package/plugins/datasets/dist/esm/index.js +1 -1
  21. package/plugins/datasets/dist/esm/mapboxStyleLayerAdapter.js +1 -1
  22. package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
  23. package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
  24. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  25. package/plugins/datasets/dist/umd/index.js +1 -1
  26. package/plugins/datasets/src/adapters/esri/esriLayerAdapter.js +18 -16
  27. package/plugins/datasets/src/adapters/esri/esriLayerAdapter.test.js +2 -2
  28. package/plugins/datasets/src/adapters/esri/registry/esriDataset.js +2 -3
  29. package/plugins/datasets/src/adapters/esri/registry/esriDataset.test.js +1 -1
  30. package/plugins/datasets/src/adapters/loadLayerAdapter.js +2 -20
  31. package/plugins/datasets/src/adapters/loadLayerAdapter.test.js +9 -9
  32. package/plugins/datasets/src/adapters/mapboxStyleLayerAdapter.js +7 -7
  33. package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.js +19 -19
  34. package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.test.js +1 -1
  35. package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.test.js +1 -1
  36. package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.test.js +2 -2
  37. package/plugins/datasets/src/adapters/openlayers/layerBuilders.test.js +1 -1
  38. package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.js +21 -21
  39. package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.test.js +5 -5
  40. package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.js +2 -3
  41. package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.test.js +2 -2
  42. package/plugins/datasets/src/api/getOpacity.js +1 -2
  43. package/plugins/datasets/src/api/getOpacity.test.js +9 -12
  44. package/plugins/datasets/src/api/getStyle.js +1 -2
  45. package/plugins/datasets/src/api/getStyle.test.js +5 -8
  46. package/plugins/datasets/src/api/removeDataset.js +2 -4
  47. package/plugins/datasets/src/api/removeDataset.test.js +5 -10
  48. package/plugins/datasets/src/api/setData.js +2 -4
  49. package/plugins/datasets/src/api/setData.test.js +6 -14
  50. package/plugins/datasets/src/api/setFeatureVisibility.js +1 -2
  51. package/plugins/datasets/src/api/setFeatureVisibility.test.js +8 -11
  52. package/plugins/datasets/src/components/LayersMenu/LayersMenu.jsx +1 -0
  53. package/plugins/datasets/src/components/LayersMenu/LayersMenuCheckbox.jsx +1 -3
  54. package/plugins/datasets/src/components/LayersMenu/LayersMenuCheckbox.test.jsx +13 -18
  55. package/plugins/datasets/src/index.js +2 -2
  56. package/plugins/datasets/src/index.test.js +8 -1
  57. package/plugins/datasets/src/initialise/DatasetsInit.jsx +48 -26
  58. package/plugins/datasets/src/initialise/DatasetsInit.test.jsx +160 -89
  59. package/plugins/datasets/src/initialise/initialiseDatasets.js +2 -3
  60. package/plugins/datasets/src/initialise/initialiseDatasets.test.js +23 -10
  61. package/plugins/datasets/src/manifest.js +53 -44
  62. package/plugins/datasets/src/manifest.test.js +36 -4
  63. package/plugins/datasets/src/reducers/pluginState.js +5 -5
  64. package/plugins/datasets/src/reducers/pluginState.test.js +21 -20
  65. package/plugins/datasets/src/registry/__mocks__/datasetRegistry.js +7 -6
  66. package/plugins/datasets/src/registry/createDataset.js +2 -2
  67. package/plugins/datasets/src/registry/dataset.js +9 -10
  68. package/plugins/datasets/src/registry/dataset.test.js +63 -64
  69. package/plugins/datasets/src/registry/datasetRegistry.js +39 -10
  70. package/plugins/datasets/src/registry/datasetRegistry.test.js +83 -1
  71. package/plugins/datasets/src/registry/globalDataset.js +9 -17
  72. package/plugins/datasets/src/registry/isVisibleWhen.js +9 -17
  73. package/plugins/datasets/src/registry/isVisibleWhen.test.js +27 -20
  74. package/plugins/datasets/src/registry/mapboxStyleDataset.test.js +26 -27
  75. package/plugins/datasets/src/utils/hasLayersMenu.js +13 -0
  76. package/plugins/datasets/src/utils/hasLayersMenu.test.js +25 -0
  77. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  78. package/plugins/draw/dist/esm/index.js +1 -1
  79. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  80. package/plugins/draw/dist/umd/index.js +1 -1
  81. package/plugins/draw/src/DrawInit.jsx +47 -26
  82. package/plugins/draw/src/DrawInit.test.jsx +90 -2
  83. package/plugins/draw/src/adapters/openlayers/core/styles.test.js +1 -1
  84. package/plugins/draw/src/adapters/openlayers/point/pointSymbolImages.test.js +1 -1
  85. package/plugins/draw/src/manifest.js +3 -2
  86. package/plugins/draw/src/manifest.test.js +13 -1
  87. package/plugins/draw/src/utils/needsDrawTarget.js +22 -0
  88. package/plugins/draw/src/utils/needsDrawTarget.test.js +42 -0
  89. package/plugins/draw-es/dist/esm/index.js +1 -0
  90. package/plugins/{beta/draw-es → draw-es}/src/DrawInit.jsx +1 -1
  91. package/plugins/{beta/draw-es → draw-es}/src/events.test.js +1 -1
  92. package/plugins/{beta/draw-es → draw-es}/src/graphic.js +1 -1
  93. package/plugins/frame/dist/esm/index.js +1 -0
  94. package/plugins/{beta/frame → frame}/dist/umd/im-frame-plugin.js +1 -1
  95. package/plugins/{beta/frame → frame}/dist/umd/index.js +1 -1
  96. package/plugins/{beta/frame → frame}/package.json +2 -2
  97. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  98. package/plugins/interact/dist/esm/index.js +1 -1
  99. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  100. package/plugins/interact/dist/umd/index.js +1 -1
  101. package/plugins/interact/src/InteractInit.jsx +3 -3
  102. package/plugins/interact/src/api/enable.test.js +13 -0
  103. package/plugins/interact/src/defaults.js +1 -0
  104. package/plugins/interact/src/hooks/useCrossHairVisibility.js +27 -17
  105. package/plugins/interact/src/hooks/useCrossHairVisibility.test.js +72 -7
  106. package/plugins/interact/src/manifest.js +4 -4
  107. package/plugins/interact/src/manifest.test.js +29 -0
  108. package/plugins/interact/src/reducer.js +7 -2
  109. package/plugins/interact/src/reducer.test.js +12 -2
  110. package/plugins/interact/src/utils/needsTarget.js +20 -0
  111. package/plugins/interact/src/utils/needsTarget.test.js +36 -0
  112. package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
  113. package/plugins/map-key/dist/esm/index.js +1 -1
  114. package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
  115. package/plugins/map-key/dist/umd/index.js +1 -1
  116. package/plugins/map-key/src/components/Key/KeySvgSymbol.jsx +4 -0
  117. package/plugins/map-key/src/components/Key/MapKey.jsx +15 -15
  118. package/plugins/map-key/src/components/Key/MapKey.test.jsx +29 -15
  119. package/plugins/map-key/src/initialise/MapKeyInit.jsx +5 -8
  120. package/plugins/map-key/src/initialise/MapKeyInit.test.jsx +9 -7
  121. package/plugins/map-key/src/manifest.test.js +0 -1
  122. package/plugins/map-key/src/reducers/mergeKeyGroupItems.js +14 -33
  123. package/plugins/map-key/src/reducers/mergeKeyGroupItems.test.js +34 -50
  124. package/plugins/map-key/src/reducers/pluginState.js +6 -1
  125. package/plugins/map-key/src/reducers/pluginState.test.js +13 -4
  126. package/plugins/map-styles/dist/esm/index.js +1 -0
  127. package/plugins/{beta/map-styles → map-styles}/dist/umd/im-map-styles-plugin.js +1 -1
  128. package/plugins/{beta/map-styles → map-styles}/dist/umd/index.js +1 -1
  129. package/plugins/{beta/map-styles → map-styles}/src/MapStyles.jsx +2 -2
  130. package/plugins/{beta/map-styles → map-styles}/src/MapStylesInit.jsx +1 -1
  131. package/plugins/menu/dist/esm/index.js +1 -1
  132. package/plugins/scale-bar/dist/esm/index.js +1 -0
  133. package/plugins/{beta/scale-bar → scale-bar}/dist/umd/im-scale-bar-plugin.js +1 -1
  134. package/plugins/{beta/scale-bar → scale-bar}/dist/umd/index.js +1 -1
  135. package/plugins/{beta/scale-bar → scale-bar}/package.json +2 -2
  136. package/plugins/search/dist/esm/im-search-plugin.js +1 -1
  137. package/plugins/search/dist/esm/index.js +1 -1
  138. package/plugins/search/dist/umd/im-search-plugin.js +1 -1
  139. package/plugins/search/dist/umd/index.js +1 -1
  140. package/plugins/search/src/components/Suggestions/Suggestions.jsx +3 -1
  141. package/plugins/search/src/components/Suggestions/Suggestions.test.jsx +11 -0
  142. package/plugins/search/src/utils/markedToElements.jsx +25 -0
  143. package/plugins/search/src/utils/markedToElements.test.jsx +49 -0
  144. package/plugins/search/src/utils/parseOsNamesResults.js +6 -4
  145. package/plugins/search/src/utils/parseOsNamesResults.test.js +18 -0
  146. package/plugins/use-location/dist/esm/index.js +1 -0
  147. package/plugins/{beta/use-location → use-location}/dist/umd/im-use-location-plugin.js +1 -1
  148. package/plugins/{beta/use-location → use-location}/dist/umd/index.js +1 -1
  149. package/providers/esri/dist/esm/index.js +1 -0
  150. package/providers/{beta/esri → esri}/src/esriProvider.js +1 -1
  151. package/providers/{beta/esri → esri}/src/mapEvents.js +2 -2
  152. package/providers/maplibre/dist/esm/index.js +1 -1
  153. package/providers/open-names/dist/esm/index.js +1 -0
  154. package/providers/{beta/open-names → open-names}/dist/umd/im-reverse-geocode.js +1 -1
  155. package/providers/{beta/open-names → open-names}/dist/umd/index.js +1 -1
  156. package/providers/openlayers/dist/esm/index.js +1 -0
  157. package/providers/openlayers/dist/umd/im-openlayers-provider.js +2 -0
  158. package/providers/{beta/openlayers → openlayers}/dist/umd/index.js +1 -1
  159. package/providers/{beta/openlayers → openlayers}/src/index.js +4 -4
  160. package/providers/{beta/openlayers → openlayers}/src/mapEvents.js +2 -2
  161. package/providers/{beta/openlayers → openlayers}/src/mapEvents.test.js +2 -2
  162. package/providers/{beta/openlayers → openlayers}/src/openlayersProvider.js +3 -3
  163. package/providers/{beta/openlayers → openlayers}/src/utils/highlightFeatures.js +1 -1
  164. package/providers/{beta/openlayers → openlayers}/src/utils/patternImages.js +1 -1
  165. package/providers/{beta/openlayers → openlayers}/src/utils/symbolImages.js +1 -1
  166. package/rollup.esm.mjs +43 -47
  167. package/sonar-project.properties +1 -1
  168. package/src/App/App.jsx +4 -1
  169. package/src/App/App.test.jsx +6 -0
  170. package/src/App/renderer/PluginInits.jsx +8 -7
  171. package/src/App/renderer/PluginInits.test.jsx +20 -5
  172. package/src/App/renderer/SlotItemsProvider.jsx +33 -0
  173. package/src/App/renderer/SlotItemsProvider.test.jsx +59 -0
  174. package/src/App/renderer/SlotRenderer.jsx +3 -14
  175. package/src/App/renderer/SlotRenderer.test.jsx +11 -44
  176. package/src/App/renderer/mapButtons.js +22 -11
  177. package/src/App/renderer/mapButtons.test.js +23 -1
  178. package/src/App/renderer/mapControls.js +6 -8
  179. package/src/App/renderer/mapControls.test.js +10 -0
  180. package/src/App/renderer/mapPanels.js +16 -19
  181. package/src/App/renderer/mapPanels.test.js +37 -9
  182. package/src/App/renderer/pluginWrapper.js +10 -8
  183. package/src/App/renderer/pluginWrapper.test.js +23 -9
  184. package/src/App/renderer/slotAggregator.js +18 -5
  185. package/src/App/renderer/slotAggregator.test.js +68 -25
  186. package/src/App/renderer/slotHelpers.js +13 -0
  187. package/src/App/renderer/slotHelpers.test.js +16 -1
  188. package/src/App/store/AppProvider.jsx +19 -1
  189. package/src/App/store/AppProvider.test.jsx +41 -0
  190. package/src/App/store/appActionsMap.js +10 -1
  191. package/src/App/store/appActionsMap.test.js +21 -0
  192. package/src/App/store/appDispatchMiddleware.js +29 -17
  193. package/src/App/store/appDispatchMiddleware.test.js +31 -0
  194. package/src/InteractiveMap/parseDataProperties.js +4 -4
  195. package/src/InteractiveMap/parseDataProperties.test.js +62 -6
  196. package/src/config/events.js +4 -2
  197. package/src/scss/tools/_govuk-content.scss +4 -3
  198. package/webpack.dev.mjs +9 -3
  199. package/webpack.prod.mjs +11 -4
  200. package/webpack.umd.mjs +6 -7
  201. package/plugins/beta/draw-es/dist/esm/index.js +0 -1
  202. package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +0 -1
  203. package/plugins/beta/draw-ml/dist/esm/index.js +0 -1
  204. package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +0 -1
  205. package/plugins/beta/draw-ml/dist/umd/index.js +0 -2
  206. package/plugins/beta/draw-ml/src/DrawInit.jsx +0 -85
  207. package/plugins/beta/draw-ml/src/api/addFeature.js +0 -27
  208. package/plugins/beta/draw-ml/src/api/deleteFeature.js +0 -13
  209. package/plugins/beta/draw-ml/src/api/editFeature.js +0 -75
  210. package/plugins/beta/draw-ml/src/api/merge.js +0 -9
  211. package/plugins/beta/draw-ml/src/api/newLine.js +0 -68
  212. package/plugins/beta/draw-ml/src/api/newPolygon.js +0 -68
  213. package/plugins/beta/draw-ml/src/api/split.js +0 -81
  214. package/plugins/beta/draw-ml/src/defaults.js +0 -17
  215. package/plugins/beta/draw-ml/src/draw.scss +0 -26
  216. package/plugins/beta/draw-ml/src/events.js +0 -185
  217. package/plugins/beta/draw-ml/src/index.js +0 -13
  218. package/plugins/beta/draw-ml/src/manifest.js +0 -110
  219. package/plugins/beta/draw-ml/src/mapboxDraw.js +0 -143
  220. package/plugins/beta/draw-ml/src/mapboxSnap.js +0 -321
  221. package/plugins/beta/draw-ml/src/modes/createDrawMode.js +0 -552
  222. package/plugins/beta/draw-ml/src/modes/disabledMode.js +0 -23
  223. package/plugins/beta/draw-ml/src/modes/drawLineMode.js +0 -18
  224. package/plugins/beta/draw-ml/src/modes/drawPolygonMode.js +0 -16
  225. package/plugins/beta/draw-ml/src/modes/editVertex/geometryHelpers.js +0 -135
  226. package/plugins/beta/draw-ml/src/modes/editVertex/helpers.js +0 -2
  227. package/plugins/beta/draw-ml/src/modes/editVertex/touchHandlers.js +0 -142
  228. package/plugins/beta/draw-ml/src/modes/editVertex/undoHandlers.js +0 -133
  229. package/plugins/beta/draw-ml/src/modes/editVertex/vertexOperations.js +0 -142
  230. package/plugins/beta/draw-ml/src/modes/editVertex/vertexQueries.js +0 -121
  231. package/plugins/beta/draw-ml/src/modes/editVertexMode.js +0 -495
  232. package/plugins/beta/draw-ml/src/reducer.js +0 -90
  233. package/plugins/beta/draw-ml/src/styles.js +0 -190
  234. package/plugins/beta/draw-ml/src/undoStack.js +0 -50
  235. package/plugins/beta/draw-ml/src/utils/debounce.js +0 -16
  236. package/plugins/beta/draw-ml/src/utils/flattenStyleProperties.js +0 -49
  237. package/plugins/beta/draw-ml/src/utils/snapHelpers.js +0 -200
  238. package/plugins/beta/draw-ml/src/utils/spatial.js +0 -258
  239. package/plugins/beta/draw-ol/dist/css/index.css +0 -1
  240. package/plugins/beta/draw-ol/dist/esm/DrawMode.js +0 -1
  241. package/plugins/beta/draw-ol/dist/esm/EditMode.js +0 -1
  242. package/plugins/beta/draw-ol/dist/esm/geometryHelpers.js +0 -1
  243. package/plugins/beta/draw-ol/dist/esm/im-draw-ol-plugin.js +0 -1
  244. package/plugins/beta/draw-ol/dist/esm/index.js +0 -1
  245. package/plugins/beta/draw-ol/src/DrawInit.jsx +0 -65
  246. package/plugins/beta/draw-ol/src/api/addFeature.js +0 -29
  247. package/plugins/beta/draw-ol/src/api/deleteFeature.js +0 -11
  248. package/plugins/beta/draw-ol/src/api/editFeature.js +0 -50
  249. package/plugins/beta/draw-ol/src/api/newLine.js +0 -44
  250. package/plugins/beta/draw-ol/src/api/newPolygon.js +0 -44
  251. package/plugins/beta/draw-ol/src/core/OLDrawManager.js +0 -153
  252. package/plugins/beta/draw-ol/src/core/featureStore.js +0 -65
  253. package/plugins/beta/draw-ol/src/core/styles.js +0 -98
  254. package/plugins/beta/draw-ol/src/core/undoStack.js +0 -31
  255. package/plugins/beta/draw-ol/src/defaults.js +0 -16
  256. package/plugins/beta/draw-ol/src/draw/DrawMode.js +0 -121
  257. package/plugins/beta/draw-ol/src/draw/drawInput.js +0 -243
  258. package/plugins/beta/draw-ol/src/draw.scss +0 -17
  259. package/plugins/beta/draw-ol/src/edit/EditMode.js +0 -424
  260. package/plugins/beta/draw-ol/src/edit/keyboardHandler.js +0 -229
  261. package/plugins/beta/draw-ol/src/edit/midpointLayer.js +0 -57
  262. package/plugins/beta/draw-ol/src/edit/touchHandler.js +0 -171
  263. package/plugins/beta/draw-ol/src/edit/undoOps.js +0 -95
  264. package/plugins/beta/draw-ol/src/edit/vertexHitTest.js +0 -72
  265. package/plugins/beta/draw-ol/src/edit/vertexLayer.js +0 -49
  266. package/plugins/beta/draw-ol/src/edit/vertexOps.js +0 -99
  267. package/plugins/beta/draw-ol/src/events.js +0 -114
  268. package/plugins/beta/draw-ol/src/index.js +0 -12
  269. package/plugins/beta/draw-ol/src/manifest.js +0 -125
  270. package/plugins/beta/draw-ol/src/olDraw.js +0 -38
  271. package/plugins/beta/draw-ol/src/reducer.js +0 -41
  272. package/plugins/beta/draw-ol/src/snap/snapEngine.js +0 -153
  273. package/plugins/beta/draw-ol/src/snap/snapGeometry.js +0 -177
  274. package/plugins/beta/draw-ol/src/snap/snapIndicator.js +0 -81
  275. package/plugins/beta/draw-ol/src/snap/snapInteraction.js +0 -57
  276. package/plugins/beta/draw-ol/src/snap/snapManager.js +0 -99
  277. package/plugins/beta/draw-ol/src/utils/flattenStyleProperties.js +0 -47
  278. package/plugins/beta/draw-ol/src/utils/geometryHelpers.js +0 -103
  279. package/plugins/beta/draw-ol/src/utils/olCoords.js +0 -35
  280. package/plugins/beta/draw-ol/src/utils/resolveColors.js +0 -39
  281. package/plugins/beta/draw-ol/src/utils/spatial.js +0 -24
  282. package/plugins/beta/draw-ol/src/utils/touchTarget.js +0 -61
  283. package/plugins/beta/frame/dist/esm/index.js +0 -1
  284. package/plugins/beta/map-styles/dist/esm/index.js +0 -1
  285. package/plugins/beta/scale-bar/dist/esm/index.js +0 -1
  286. package/plugins/beta/use-location/dist/esm/index.js +0 -1
  287. package/plugins/map-key/src/registry/getDatasetRegistry.js +0 -6
  288. package/plugins/map-key/src/registry/getDatasetRegistry.test.js +0 -23
  289. package/plugins/map-key/src/registry/index.js +0 -1
  290. package/plugins/map-key/src/registry/index.test.js +0 -7
  291. package/providers/beta/esri/dist/esm/index.js +0 -1
  292. package/providers/beta/open-names/dist/esm/index.js +0 -1
  293. package/providers/beta/openlayers/dist/esm/index.js +0 -1
  294. package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +0 -2
  295. package/providers/beta/openlayers/dist/umd/index.js.LICENSE.txt +0 -1
  296. /package/plugins/{beta/draw-es → draw-es}/dist/esm/im-draw-es-plugin.js +0 -0
  297. /package/plugins/{beta/draw-es → draw-es}/src/api/addFeature.js +0 -0
  298. /package/plugins/{beta/draw-es → draw-es}/src/api/deleteFeature.js +0 -0
  299. /package/plugins/{beta/draw-es → draw-es}/src/api/editFeature.js +0 -0
  300. /package/plugins/{beta/draw-es → draw-es}/src/api/newPolygon.js +0 -0
  301. /package/plugins/{beta/draw-es → draw-es}/src/api/removeSafeZone.js +0 -0
  302. /package/plugins/{beta/draw-es → draw-es}/src/events.js +0 -0
  303. /package/plugins/{beta/draw-es → draw-es}/src/index.js +0 -0
  304. /package/plugins/{beta/draw-es → draw-es}/src/manifest.js +0 -0
  305. /package/plugins/{beta/draw-es → draw-es}/src/reducer.js +0 -0
  306. /package/plugins/{beta/draw-es → draw-es}/src/sketchViewModel.js +0 -0
  307. /package/plugins/{beta/frame → frame}/dist/css/index.css +0 -0
  308. /package/plugins/{beta/frame → frame}/dist/esm/im-frame-plugin.js +0 -0
  309. /package/plugins/{beta/draw-ml → frame}/dist/umd/index.js.LICENSE.txt +0 -0
  310. /package/plugins/{beta/frame → frame}/src/Frame.jsx +0 -0
  311. /package/plugins/{beta/frame → frame}/src/FrameInit.jsx +0 -0
  312. /package/plugins/{beta/frame → frame}/src/api/addFrame.js +0 -0
  313. /package/plugins/{beta/frame → frame}/src/api/editFeature.js +0 -0
  314. /package/plugins/{beta/frame → frame}/src/config.js +0 -0
  315. /package/plugins/{beta/frame → frame}/src/frame.scss +0 -0
  316. /package/plugins/{beta/frame → frame}/src/index.js +0 -0
  317. /package/plugins/{beta/frame → frame}/src/manifest.js +0 -0
  318. /package/plugins/{beta/frame → frame}/src/reducer.js +0 -0
  319. /package/plugins/{beta/frame → frame}/src/utils.js +0 -0
  320. /package/plugins/{beta/map-styles → map-styles}/dist/css/index.css +0 -0
  321. /package/plugins/{beta/map-styles → map-styles}/dist/esm/im-map-styles-plugin.js +0 -0
  322. /package/plugins/{beta/frame → map-styles}/dist/umd/index.js.LICENSE.txt +0 -0
  323. /package/plugins/{beta/map-styles → map-styles}/src/config.js +0 -0
  324. /package/plugins/{beta/map-styles → map-styles}/src/index.js +0 -0
  325. /package/plugins/{beta/map-styles → map-styles}/src/manifest.js +0 -0
  326. /package/plugins/{beta/map-styles → map-styles}/src/mapStyles.scss +0 -0
  327. /package/plugins/{beta/scale-bar → scale-bar}/dist/css/index.css +0 -0
  328. /package/plugins/{beta/scale-bar → scale-bar}/dist/esm/im-scale-bar-plugin.js +0 -0
  329. /package/plugins/{beta/map-styles → scale-bar}/dist/umd/index.js.LICENSE.txt +0 -0
  330. /package/plugins/{beta/scale-bar → scale-bar}/src/ScaleBar.jsx +0 -0
  331. /package/plugins/{beta/scale-bar → scale-bar}/src/ScaleBar.test.jsx +0 -0
  332. /package/plugins/{beta/scale-bar → scale-bar}/src/index.js +0 -0
  333. /package/plugins/{beta/scale-bar → scale-bar}/src/index.test.js +0 -0
  334. /package/plugins/{beta/scale-bar → scale-bar}/src/manifest.js +0 -0
  335. /package/plugins/{beta/scale-bar → scale-bar}/src/scaleBar.scss +0 -0
  336. /package/plugins/{beta/scale-bar → scale-bar}/src/utils.js +0 -0
  337. /package/plugins/{beta/scale-bar → scale-bar}/src/utils.test.js +0 -0
  338. /package/plugins/{beta/use-location → use-location}/dist/esm/im-use-location-plugin.js +0 -0
  339. /package/plugins/{beta/scale-bar → use-location}/dist/umd/index.js.LICENSE.txt +0 -0
  340. /package/plugins/{beta/use-location → use-location}/src/UseLocation.jsx +0 -0
  341. /package/plugins/{beta/use-location → use-location}/src/UseLocationInit.jsx +0 -0
  342. /package/plugins/{beta/use-location → use-location}/src/defaults.js +0 -0
  343. /package/plugins/{beta/use-location → use-location}/src/events.js +0 -0
  344. /package/plugins/{beta/use-location → use-location}/src/index.js +0 -0
  345. /package/plugins/{beta/use-location → use-location}/src/manifest.js +0 -0
  346. /package/plugins/{beta/use-location → use-location}/src/reducer.js +0 -0
  347. /package/providers/{beta/esri → esri}/dist/css/index.css +0 -0
  348. /package/providers/{beta/esri → esri}/dist/esm/im-esri-provider.js +0 -0
  349. /package/providers/{beta/esri → esri}/src/appEvents.js +0 -0
  350. /package/providers/{beta/esri → esri}/src/defaults.js +0 -0
  351. /package/providers/{beta/esri → esri}/src/esriProvider.scss +0 -0
  352. /package/providers/{beta/esri → esri}/src/index.js +0 -0
  353. /package/providers/{beta/esri → esri}/src/utils/coords.js +0 -0
  354. /package/providers/{beta/esri → esri}/src/utils/coords.test.js +0 -0
  355. /package/providers/{beta/esri → esri}/src/utils/detectWebGL.js +0 -0
  356. /package/providers/{beta/esri → esri}/src/utils/esriFixes.js +0 -0
  357. /package/providers/{beta/esri → esri}/src/utils/query.js +0 -0
  358. /package/providers/{beta/esri → esri}/src/utils/spatial.js +0 -0
  359. /package/providers/{beta/esri → esri}/src/utils/spatial.test.js +0 -0
  360. /package/providers/{beta/open-names → open-names}/dist/esm/im-reverse-geocode.js +0 -0
  361. /package/providers/{beta/open-names → open-names}/dist/umd/im-reverse-geocode.js.LICENSE.txt +0 -0
  362. /package/{plugins/beta/use-location → providers/open-names}/dist/umd/index.js.LICENSE.txt +0 -0
  363. /package/providers/{beta/open-names → open-names}/src/index.js +0 -0
  364. /package/providers/{beta/open-names → open-names}/src/reverseGeocode.js +0 -0
  365. /package/providers/{beta/open-names → open-names}/src/utils/mapToLocationModel.js +0 -0
  366. /package/providers/{beta/open-names → open-names}/src/utils/mapToLocationModel.test.js +0 -0
  367. /package/providers/{beta/openlayers → openlayers}/dist/esm/im-openlayers-provider.js +0 -0
  368. /package/providers/{beta/openlayers → openlayers}/dist/umd/im-openlayers-provider.js.LICENSE.txt +0 -0
  369. /package/providers/{beta/open-names → openlayers}/dist/umd/index.js.LICENSE.txt +0 -0
  370. /package/providers/{beta/openlayers → openlayers}/src/appEvents.js +0 -0
  371. /package/providers/{beta/openlayers → openlayers}/src/appEvents.test.js +0 -0
  372. /package/providers/{beta/openlayers → openlayers}/src/defaults.js +0 -0
  373. /package/providers/{beta/openlayers → openlayers}/src/index.test.js +0 -0
  374. /package/providers/{beta/openlayers → openlayers}/src/openlayersProvider.test.js +0 -0
  375. /package/providers/{beta/openlayers → openlayers}/src/utils/bngProjection.js +0 -0
  376. /package/providers/{beta/openlayers → openlayers}/src/utils/filterEvaluator.js +0 -0
  377. /package/providers/{beta/openlayers → openlayers}/src/utils/filterEvaluator.test.js +0 -0
  378. /package/providers/{beta/openlayers → openlayers}/src/utils/highlightFeatures.test.js +0 -0
  379. /package/providers/{beta/openlayers → openlayers}/src/utils/hoverCursor.js +0 -0
  380. /package/providers/{beta/openlayers → openlayers}/src/utils/hoverCursor.test.js +0 -0
  381. /package/providers/{beta/openlayers → openlayers}/src/utils/openLayersFixes.js +0 -0
  382. /package/providers/{beta/openlayers → openlayers}/src/utils/openLayersFixes.test.js +0 -0
  383. /package/providers/{beta/openlayers → openlayers}/src/utils/patternImages.test.js +0 -0
  384. /package/providers/{beta/openlayers → openlayers}/src/utils/queryFeatures.js +0 -0
  385. /package/providers/{beta/openlayers → openlayers}/src/utils/queryFeatures.test.js +0 -0
  386. /package/providers/{beta/openlayers → openlayers}/src/utils/spatial.js +0 -0
  387. /package/providers/{beta/openlayers → openlayers}/src/utils/spatial.test.js +0 -0
  388. /package/providers/{beta/openlayers → openlayers}/src/utils/symbolImages.test.js +0 -0
  389. /package/providers/{beta/openlayers → openlayers}/src/utils/tileLayers.js +0 -0
  390. /package/providers/{beta/openlayers → openlayers}/src/utils/tileLayers.test.js +0 -0
  391. /package/providers/{beta/openlayers → openlayers}/src/utils/vtTileFragments.js +0 -0
  392. /package/providers/{beta/openlayers → openlayers}/src/utils/vtTileFragments.test.js +0 -0
  393. /package/providers/{beta/openlayers → openlayers}/src/utils/zoom.js +0 -0
  394. /package/providers/{beta/openlayers → openlayers}/src/utils/zoom.test.js +0 -0
@@ -1 +1 @@
1
- import{useRef as e,useEffect as t,useLayoutEffect as n}from"preact/compat";import"preact/jsx-runtime";const r=new Set(["draw_polygon","draw_line"]),i={SET_MODE:(e,t)=>({...e,mode:t,numVertices:r.has(t)?0:e.numVertices,geometryValid:!1,canAddPoint:!0}),SET_ACTION:(e,t)=>({...e,action:t.name,actionValid:t.isValid}),SET_FEATURE:(e,t)=>({...e,feature:void 0===t.feature?e.feature:t.feature,tempFeature:void 0===t.tempFeature?e.tempFeature:t.tempFeature}),SET_SELECTED_VERTEX_INDEX:(e,t)=>({...e,selectedVertexIndex:t.index,numVertices:t.numVertices}),TOGGLE_SNAP:e=>({...e,snap:!e.snap}),SET_HAS_SNAP_LAYERS:(e,t)=>({...e,hasSnapLayers:!!t}),SET_UNDO_STACK_LENGTH:(e,t)=>({...e,undoStackLength:t}),SET_GEOMETRY_VALID:(e,t)=>({...e,geometryValid:!!t}),SET_CAN_ADD_POINT:(e,t)=>({...e,canAddPoint:!!t})},o={APP_ADD_MARKER:"app:addmarker",APP_UPDATE_MARKER:"app:updatemarker",APP_REMOVE_MARKER:"app:removemarker",APP_ADD_BUTTON:"app:addbutton",APP_TOGGLE_BUTTON_STATE:"app:togglebuttonstate",APP_ADD_PANEL:"app:addpanel",APP_REMOVE_PANEL:"app:removepanel",APP_SHOW_PANEL:"app:showpanel",APP_HIDE_PANEL:"app:hidepanel",APP_ADD_CONTROL:"app:addcontrol",APP_SET_APPLICATION_MODE:"app:setapplicationmode",APP_CLEAR_APPLICATION_MODE:"app:clearapplicationmode",APP_SHOW_HINT:"app:showhint",APP_DISMISS_HINT:"app:dismisshint",APP_READY:"app:ready",APP_OPENED:"app:opened",APP_CLOSED:"app:closed",APP_FULLSCREEN_CHANGE:"app:fullscreenchange",APP_PANEL_OPENED:"app:panelopened",APP_PANEL_CLOSED:"app:panelclosed",MAP_SET_STYLE:"map:setstyle",MAP_SET_SIZE:"map:setsize",MAP_SET_SPATIAL_LIST:"map:setspatiallist",MAP_SET_SPATIAL_LIST_SUPPRESSED:"map:setspatiallistsuppressed",MAP_SET_ACTIVE_ITEM:"map:setactiveitem",MAP_SELECT_ITEM:"map:selectitem",MAP_SET_PIXEL_RATIO:"map:setpixelratio",MAP_FIT_TO_BOUNDS:"map:fittobounds",MAP_SET_VIEW:"map:setview",MAP_INIT_MAP_STYLES:"map:initmapstyles",MAP_STYLE_CHANGE:"map:stylechange",MAP_LOADED:"map:loaded",MAP_READY:"map:ready",MAP_SIZE_CHANGE:"map:sizechange",MAP_FIRST_IDLE:"map:firstidle",MAP_MOVE_START:"map:movestart",MAP_MOVE:"map:move",MAP_MOVE_END:"map:moveend",MAP_STATE_UPDATED:"map:stateupdated",MAP_DATA_CHANGE:"map:datachange",MAP_RENDER:"map:render",MAP_CLICK:"map:click",MAP_DESTROY:"map:destroy"},s={CREATE:"create",EDIT_FINISH:"editfinish",CANCEL:"cancel",VERTEX_SELECTION:"vertexselection",VERTEX_CHANGE:"vertexchange",UNDO_CHANGE:"undochange",UPDATE:"update",GEOMETRY_CHANGE:"geometrychange",INTERFACE_TYPE_CHANGE:"interfacetypechange",PLACEMENT_BLOCKED:"placementblocked",VALIDITY_CHANGE:"validitychange",CAN_PLACE_CHANGE:"canplacechange"};var a=6371008.8,l={centimeters:637100880,centimetres:637100880,degrees:360/(2*Math.PI),feet:20902260.511392,inches:39.37*a,kilometers:6371.0088,kilometres:6371.0088,meters:a,metres:a,miles:3958.761333810546,millimeters:6371008800,millimetres:6371008800,nauticalmiles:a/1852,radians:1,yards:6967335.223679999};function u(e,t,n={}){const r={type:"Feature"};return(0===n.id||n.id)&&(r.id=n.id),n.bbox&&(r.bbox=n.bbox),r.properties=t||{},r.geometry=e,r}function c(e,t,n={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!v(e[0])||!v(e[1]))throw new Error("coordinates must contain numbers");return u({type:"Point",coordinates:e},t,n)}function h(e,t,n={}){for(const t of e){if(t.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(t[t.length-1].length!==t[0].length)throw new Error("First and last Position are not equivalent.");for(let e=0;e<t[t.length-1].length;e++)if(t[t.length-1][e]!==t[0][e])throw new Error("First and last Position are not equivalent.")}return u({type:"Polygon",coordinates:e},t,n)}function p(e,t,n={}){if(e.length<2)throw new Error("coordinates must be an array of two or more positions");return u({type:"LineString",coordinates:e},t,n)}function d(e,t={}){const n={type:"FeatureCollection"};return t.id&&(n.id=t.id),t.bbox&&(n.bbox=t.bbox),n.features=e,n}function f(e,t,n={}){return u({type:"MultiLineString",coordinates:e},t,n)}function g(e,t="kilometers"){const n=l[t];if(!n)throw new Error(t+" units is invalid");return e*n}function y(e,t="kilometers"){const n=l[t];if(!n)throw new Error(t+" units is invalid");return e/n}function m(e){return 180*(e%(2*Math.PI))/Math.PI}function E(e){return e%360*Math.PI/180}function v(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}function S(e,t,n){if(null!==e)for(var r,i,o,s,a,l,u,c,h=0,p=0,d=e.type,f="FeatureCollection"===d,g="Feature"===d,y=f?e.features.length:1,m=0;m<y;m++){a=(c=!!(u=f?e.features[m].geometry:g?e.geometry:e)&&"GeometryCollection"===u.type)?u.geometries.length:1;for(var E=0;E<a;E++){var v=0,w=0;if(null!==(s=c?u.geometries[E]:u)){l=s.coordinates;var b=s.type;switch(h=0,b){case null:break;case"Point":if(!1===t(l,p,m,v,w))return!1;p++,v++;break;case"LineString":case"MultiPoint":for(r=0;r<l.length;r++){if(!1===t(l[r],p,m,v,w))return!1;p++,"MultiPoint"===b&&v++}"LineString"===b&&v++;break;case"Polygon":case"MultiLineString":for(r=0;r<l.length;r++){for(i=0;i<l[r].length-h;i++){if(!1===t(l[r][i],p,m,v,w))return!1;p++}"MultiLineString"===b&&v++,"Polygon"===b&&w++}"Polygon"===b&&v++;break;case"MultiPolygon":for(r=0;r<l.length;r++){for(w=0,i=0;i<l[r].length;i++){for(o=0;o<l[r][i].length-h;o++){if(!1===t(l[r][i][o],p,m,v,w))return!1;p++}w++}v++}break;case"GeometryCollection":for(r=0;r<s.geometries.length;r++)if(!1===S(s.geometries[r],t))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function w(e,t){if("Feature"===e.type)t(e,0);else if("FeatureCollection"===e.type)for(var n=0;n<e.features.length&&!1!==t(e.features[n],n);n++);}function b(e){var t=[];return S(e,function(e){t.push(e)}),t}function x(e,t){var n,r,i,o,s,a,l,u,c,h,p=0,d="FeatureCollection"===e.type,f="Feature"===e.type,g=d?e.features.length:1;for(n=0;n<g;n++){for(a=d?e.features[n].geometry:f?e.geometry:e,u=d?e.features[n].properties:f?e.properties:{},c=d?e.features[n].bbox:f?e.bbox:void 0,h=d?e.features[n].id:f?e.id:void 0,s=(l=!!a&&"GeometryCollection"===a.type)?a.geometries.length:1,i=0;i<s;i++)if(null!==(o=l?a.geometries[i]:a))switch(o.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(!1===t(o,p,u,c,h))return!1;break;case"GeometryCollection":for(r=0;r<o.geometries.length;r++)if(!1===t(o.geometries[r],p,u,c,h))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===t(null,p,u,c,h))return!1;p++}}function P(e,t){x(e,function(e,n,r,i,o){var s,a=null===e?null:e.type;switch(a){case null:case"Point":case"LineString":case"Polygon":return!1!==t(u(e,r,{bbox:i,id:o}),n,0)&&void 0}switch(a){case"MultiPoint":s="Point";break;case"MultiLineString":s="LineString";break;case"MultiPolygon":s="Polygon"}for(var l=0;l<e.coordinates.length;l++){var c=e.coordinates[l];if(!1===t(u({type:s,coordinates:c},r),n,l))return!1}})}function _(e){let t=0;if(e&&e.length>0){t+=Math.abs(C(e[0]));for(let n=1;n<e.length;n++)t-=Math.abs(C(e[n]))}return t}var T=20294876564838.72,A=Math.PI/180;function C(e){const t=e.length-1;if(t<=2)return 0;let n=0,r=0;for(;r<t;){const i=e[r],o=e[r+1===t?0:r+1],s=e[r+2>=t?(r+2)%t:r+2],a=i[0]*A,l=o[1]*A;n+=(s[0]*A-a)*Math.sin(l),r++}return n*T}var L=function(e){return function(e,t,n){var r=n;return x(e,function(e,n,i,o,s){r=t(r,e,n,i,o,s)}),r}(e,(e,t)=>e+function(e){let t,n=0;switch(e.type){case"Polygon":return _(e.coordinates);case"MultiPolygon":for(t=0;t<e.coordinates.length;t++)n+=_(e.coordinates[t]);return n;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}(t),0)};const I={Polygon:3,LineString:2},M=e=>e?.geometry??e,R=e=>{const t=M(e);return"Polygon"===t?.type?t:null},N=e=>{const t=e.coordinates?.[0]??[],n=t.filter((e,n)=>0===n||e[0]!==t[n-1][0]||e[1]!==t[n-1][1]);for(;n.length>1&&n[0][0]===n[n.length-1][0]&&n[0][1]===n[n.length-1][1];)n.pop();return n},k=e=>[...e,e[0]],O=(e,t,n)=>(t[0]-e[0])*(n[1]-e[1])-(t[1]-e[1])*(n[0]-e[0]),D=(e,t)=>e>0&&t<0||e<0&&t>0,G=(e,t,n,r)=>0===e&&((e,t,n)=>Math.min(e[0],n[0])<=t[0]&&t[0]<=Math.max(e[0],n[0])&&Math.min(e[1],n[1])<=t[1]&&t[1]<=Math.max(e[1],n[1]))(t,n,r),V=(e,t,n,r)=>{const i=O(n,r,e),o=O(n,r,t),s=O(e,t,n),a=O(e,t,r);return!(!D(i,o)||!D(s,a))||(G(i,n,e,r)||G(o,n,t,r)||G(s,e,n,t)||G(a,e,r,t))},B=(e,t)=>{const n=e.length,r=t?n:n-1;for(let i=0;i<r;i++)for(let o=i+1;o<r;o++){if(!(o===i+1||t&&0===i&&o===r-1)&&V(e[i],e[(i+1)%n],e[o],e[(o+1)%n]))return!0}return!1},F=e=>{const t=R(e);if(!t)return{valid:!0};const n=N(t);return n.length<4?{valid:!0}:B(n,!0)?{valid:!1,reason:"Shape must not intersect itself"}:{valid:!0}},U=e=>{const t=R(e);if(!t)return{valid:!0};const n=N(t);if(n.length<I.Polygon)return{valid:!0};let r=0;try{r=L({type:"Feature",geometry:{type:"Polygon",coordinates:[k(n)]},properties:{}})}catch{return{valid:!0}}return r>0?{valid:!0}:{valid:!1,reason:"Shape must enclose an area"}},H={Polygon:"Shape needs at least 3 points",LineString:"Line needs at least 2 points"},q=[F,U,e=>{const t=M(e);return"Polygon"===t?.type?N(t).length>=I.Polygon?{valid:!0}:{valid:!1,reason:H.Polygon}:"LineString"===t?.type?(t.coordinates?.length??0)>=I.LineString?{valid:!0}:{valid:!1,reason:H.LineString}:{valid:!0}}],Y=[F,U],j=[e=>(e=>{const t=R(e);if(!t)return!1;const n=N(t);return!(n.length<4)&&B(n,!1)})(e)?{valid:!1,reason:"Shape must not intersect itself"}:{valid:!0}],z=e=>void 0===e||!0===e?{valid:!0}:!1===e?{valid:!1,reason:null}:{valid:!1!==e.valid,reason:e.reason},$=(e,t={},n={})=>{const{rules:r=q,onGeometryChange:i}=n;for(const n of r){const r=z(n(e,t));if(!r.valid)return r}return"function"==typeof i?z(i({feature:e,...t})):{valid:!0}},W=(e,t={},n={})=>{const{rules:r=j,onGeometryChange:i}=n;return $(e,{...t,phase:"place"},{rules:r,onGeometryChange:i})},X={Polygon:"draw_polygon",LineString:"draw_line"},K=({placed:e,point:t,geometryType:n,onGeometryChange:r})=>{const i=[...e,t],o={type:"Feature",geometry:"Polygon"===n?{type:"Polygon",coordinates:[i]}:{type:"LineString",coordinates:i},properties:{}},s=X[n],{valid:a,reason:l}=W(o,{mode:s,vertexIndex:e.length},{onGeometryChange:r});return a?{valid:!0}:{valid:!1,blocked:{feature:o,reason:l??null,phase:"place",mode:s,vertexIndex:e.length}}},Z=(e,t={},n={})=>{const{rules:r=Y,onGeometryChange:i}=n,o=I[e?.geometry?.type??e?.type]??0,s=(t.numVertices??0)<o?[]:r;return $(e,{...t,phase:t.phase??"preview"},{rules:s,onGeometryChange:i})},J={small:1,medium:1.5,large:2},Q="rgba(29,112,184,1)",ee="#ffffff",te="rgba(11,12,12,1)",ne="rgba(212,53,28,0.5)",re={editStroke:{light:Q,dark:ee},editFill:{light:"rgba(29,112,184,0.1)",dark:"rgba(255,255,255,0.1)"},editVertex:{light:Q,dark:ee},editMidpoint:{light:Q,dark:ee},editHalo:{light:ee,dark:te},editActive:{light:te,dark:ee},splitInvalid:{light:Q,dark:ee},splitValid:{light:Q,dark:ee},invalidStroke:{light:Q,dark:ee},shapeStroke:"rgba(212,53,28,1)",shapeFill:ne,snapVertex:ne,snapMidpoint:"rgba(40,161,151,1)",snapEdge:"rgba(29,112,184,0.5)"},ie={strokeWidth:2,vertexRadius:6,midpointRadius:4,vertexHaloRadius:8,midpointHaloRadius:6,touchTargetSize:48},oe={snapRadius:12},se={nudgeAmount:1,stepAmount:5},ae="draw",le=new Set(["symbol","symbolSvgContent","symbolViewBox","symbolAnchor","symbolSize","symbolBackgroundColor","symbolForegroundColor","symbolHaloWidth","symbolGraphic"]),ue=e=>{if(!e?.properties)return e;const t={};for(const[n,r]of Object.entries(e.properties)){"sortKey"===n||n.startsWith("symbol")&&!le.has(n)||(t[n]=r)}return{...e,properties:t}},ce="edit_vertex",he=new Set([ce,"edit_point"]),pe=(e,t)=>n=>{var r;e.emit("draw:geometryinvalid",n),n.reason&&(r=n.reason,!Object.values(H).includes(r))&&t.show(n.reason)},de=({draw:e,pluginState:t,mapProvider:n,eventBus:r})=>({onVertexSelection:i=>{t.dispatch({type:"SET_SELECTED_VERTEX_INDEX",payload:i}),n.activeMoveTarget=i.index>=0?(e=>({move:(t,n,r)=>e.nudgeSelectedVertex(t,n,r),label:"vertex"}))(e):null,r.emit("draw:vertexselection",i)},onVertexChange:e=>{t.dispatch({type:"SET_SELECTED_VERTEX_INDEX",payload:{index:-1,numVertices:e.numVertices}}),n.activeMoveTarget=null}});function fe({appState:e,appConfig:t,mapState:n,pluginState:r,mapProvider:i,eventBus:o,hints:s,resetState:a}){const{draw:l}=i,u=pe(o,s),{feature:c,tempFeature:h}=r,{dispatch:p}=r;let d=null;return{handleDone:()=>{l.done()},handleCancel:()=>{const e=l.getMode();he.has(e)&&h?.id&&l.add(c),d=null,l.cancel(),a(),o.emit("draw:cancelled",ue(c))},handleUndo:()=>l.undo(),handleDeleteVertex:()=>l.deleteVertex(),handleSnap:()=>{r.dispatch({type:"TOGGLE_SNAP"}),l.setSnapEnabled(!r.snap)},onCreate:r=>{const{valid:i,reason:s}=$(r,{phase:"create",mode:l.getMode()},{onGeometryChange:l._geometryValidator});if(!i)return d=r.id,u({feature:ue(r),reason:s,phase:"create",mode:ce}),void setTimeout(()=>(({draw:e,appState:t,appConfig:n,mapState:r,dispatch:i},o)=>{e.changeMode(ce,{container:t?.layoutRefs?.viewportRef?.current,deleteVertexButtonId:`${n?.id}-draw-delete-point`,undoButtonId:`${n?.id}-draw-undo`,isPanEnabled:"keyboard"!==t?.interfaceType,interfaceType:t?.interfaceType,scale:J[r?.mapSize],featureId:o,getSnapEnabled:()=>e.isSnapEnabled()});const s=e.get(o);i({type:"SET_FEATURE",payload:{feature:s,tempFeature:s}}),i({type:"SET_MODE",payload:ce}),i({type:"SET_GEOMETRY_VALID",payload:!1}),e.setGeometryValid?.(!1),e.setInvalid?.(!0)})({draw:l,appState:e,appConfig:t,mapState:n,dispatch:p},r.id),0);a(),setTimeout(()=>l.changeMode("disabled"),0),o.emit("draw:created",ue(r))},onEditFinish:e=>{a(),setTimeout(()=>l.changeMode("disabled"),0),d&&e.id===d?(d=null,o.emit("draw:created",ue(e))):o.emit("draw:edited",ue(e))},onCancel:()=>{},...de({draw:l,pluginState:r,mapProvider:i,eventBus:o}),onUndoChange:e=>{r.dispatch({type:"SET_UNDO_STACK_LENGTH",payload:e})},onUpdate:e=>{o.emit("draw:updated",ue(e))},onGeometryChange:e=>{if(!e?.phase)return;const t=l.getMode(),n={phase:e.phase,vertexIndex:e.vertexIndex,mode:t},{valid:i,reason:o}=$(e.feature,n,{onGeometryChange:l._geometryValidator});r.dispatch({type:"SET_GEOMETRY_VALID",payload:i}),l.setGeometryValid?.(i),he.has(t)&&l.setInvalid?.(!i),i||u({reason:o,...n,feature:ue(e.feature)})},onPlacementBlocked:e=>{u({...e,feature:ue(e.feature)})},onValidityChange:e=>{r.dispatch({type:"SET_GEOMETRY_VALID",payload:e.valid}),l.setGeometryValid?.(e.valid)},onCanPlaceChange:e=>{r.dispatch({type:"SET_CAN_ADD_POINT",payload:e.canPlace})},onInterfaceTypeChange:e=>{o.emit("draw:interfacetypechange",{interfaceType:e.interfaceType})}}}function ge({appState:e,appConfig:t,mapState:n,pluginState:r,mapProvider:i,buttonConfig:o,eventBus:a,hints:l}){const{draw:u}=i,c=fe({appState:e,appConfig:t,mapState:n,pluginState:r,mapProvider:i,eventBus:a,hints:l,resetState:()=>{r.dispatch({type:"SET_MODE",payload:null}),r.dispatch({type:"SET_FEATURE",payload:{feature:null,tempFeature:null}}),i.activeMoveTarget=null}});return function(e,t){const{drawDone:n,drawCancel:r,drawUndo:i,drawDeletePoint:o,drawSnap:s}=e;n.onClick=t.handleDone,r.onClick=t.handleCancel,i.onClick=t.handleUndo,o&&(o.onClick=t.handleDeleteVertex),s&&(s.onClick=t.handleSnap)}(o,c),function(e,t){e.on(s.CREATE,t.onCreate),e.on(s.EDIT_FINISH,t.onEditFinish),e.on(s.CANCEL,t.onCancel),e.on(s.VERTEX_SELECTION,t.onVertexSelection),e.on(s.VERTEX_CHANGE,t.onVertexChange),e.on(s.UNDO_CHANGE,t.onUndoChange),e.on(s.UPDATE,t.onUpdate),e.on(s.GEOMETRY_CHANGE,t.onGeometryChange),e.on(s.PLACEMENT_BLOCKED,t.onPlacementBlocked),e.on(s.VALIDITY_CHANGE,t.onValidityChange),e.on(s.CAN_PLACE_CHANGE,t.onCanPlaceChange),e.on(s.INTERFACE_TYPE_CHANGE,t.onInterfaceTypeChange)}(u,c),()=>{!function(e){const{drawDone:t,drawCancel:n,drawUndo:r,drawDeletePoint:i,drawSnap:o}=e;t.onClick=null,n.onClick=null,r.onClick=null,i&&(i.onClick=null),o&&(o.onClick=null)}(o),function(e,t){e.off(s.CREATE,t.onCreate),e.off(s.EDIT_FINISH,t.onEditFinish),e.off(s.CANCEL,t.onCancel),e.off(s.VERTEX_SELECTION,t.onVertexSelection),e.off(s.VERTEX_CHANGE,t.onVertexChange),e.off(s.UNDO_CHANGE,t.onUndoChange),e.off(s.UPDATE,t.onUpdate),e.off(s.GEOMETRY_CHANGE,t.onGeometryChange),e.off(s.PLACEMENT_BLOCKED,t.onPlacementBlocked),e.off(s.VALIDITY_CHANGE,t.onValidityChange),e.off(s.CAN_PLACE_CHANGE,t.onCanPlaceChange),e.off(s.INTERFACE_TYPE_CHANGE,t.onInterfaceTypeChange)}(u,c)}}const ye="[interactive-map]",me={warn:(...e)=>console.warn(ye,...e),error:(...e)=>console.error(ye,...e)},Ee=e=>!(!e?.symbol&&!e?.symbolSvgContent),ve="edit_vertex",Se="draw",we=(e,t,n)=>{const{x:r,y:i}=e.mapToScreen(n);return{x:r*J[t],y:i*J[t]}},be=(e,t)=>{const{vertices:n,midpoints:r}=e.draw?.getVertexItems?.()??{vertices:[],midpoints:[]},i=[];return n.forEach((o,s)=>{i.push(((n,r)=>({id:String(r),label:`Point ${r+1}`,isMidpoint:!1,...we(e,t,n)}))(o,s)),s<r.length&&i.push(((r,i)=>({id:String(n.length+i),label:`Insert ${i+1}-${(i+1)%n.length+1}`,isMidpoint:!0,...we(e,t,r)}))(r[s],s))}),i};function xe({mapState:n,pluginState:r,services:i,mapProvider:a,spatialListRegistry:l,viewportRef:u}){const{mapSize:c}=n,{eventBus:h,announce:p}=i,d=e([]),f=e(null);!function({pluginState:e,mapProvider:n,mapSize:r,spatialListRegistry:i,itemsRef:a,eventBus:l}){t(()=>{const t=()=>{a.current=e.mode===ve?be(n,r):[],i.notifyItemsChanged(Se)};t(),l.on(o.MAP_MOVE_END,t);const{draw:u}=n;return u?(u.on(s.UPDATE,t),()=>{l.off(o.MAP_MOVE_END,t),u.off(s.UPDATE,t)}):()=>l.off(o.MAP_MOVE_END,t)},[e.mode,n,r,i,a,l]),t(()=>(i.registerItemProvider(Se,{getItems:()=>({items:a.current,multiselectable:!1,label:"Shape points",focusable:!1}),exclusive:!0}),()=>{i.unregisterItemProvider(Se)}),[i,a]),t(()=>{if(e.mode===ve)return i.claimExclusive(Se),()=>i.releaseExclusive(Se)},[e.mode,i])}({pluginState:r,mapProvider:a,mapSize:c,spatialListRegistry:l,itemsRef:d,eventBus:h}),function({eventBus:e,mapProvider:n,pluginState:r,activeIdRef:i}){t(()=>{const t=({id:e})=>{i.current=e,null!==e&&r.mode===ve&&n.draw?.selectVertex?.(Number(e))};return e.on(o.MAP_SET_ACTIVE_ITEM,t),()=>{e.off(o.MAP_SET_ACTIVE_ITEM,t)}},[e,n,r.mode,i])}({eventBus:h,mapProvider:a,pluginState:r,activeIdRef:f}),function({eventBus:e,mapProvider:n,pluginState:r,activeIdRef:i,itemsRef:s,viewportRef:a,announce:l}){t(()=>{const t=()=>{if(r.mode!==ve||null===i.current)return;const e=s.current.find(e=>e.id===i.current);e&&(e.isMidpoint?(n.draw?.insertVertexAtMidpoint?.(Number(i.current)),l("New point inserted","action")):l(`${e.label} selected`,"action"),a.current?.focus())};return e.on(o.MAP_SELECT_ITEM,t),()=>{e.off(o.MAP_SELECT_ITEM,t)}},[e,n,r.mode,i,s,a,l])}({eventBus:h,mapProvider:a,pluginState:r,activeIdRef:f,itemsRef:d,viewportRef:u,announce:p})}function Pe({mapState:e,pluginConfig:n,pluginState:r,mapProvider:i,eventBus:s,symbolRegistry:a}){t(()=>{if(!e.isMapReady)return;let t=!0;return(async(e,t)=>{switch(e.name){case"MapLibreProvider":{const{MaplibreDrawAdapter:n}=await import(/* webpackChunkName: "im-draw-ml-adapter" */ "./im-draw-ml-adapter.js");return new n(e,t)}case"OpenLayersProvider":{const{OLDrawAdapter:n}=await import(/* webpackChunkName: "im-draw-ol-adapter" */ "./im-draw-ol-adapter.js");return new n(e,t)}default:throw new Error(`No draw adapter available for map provider "${e.name}"`)}})(i,{mapStyle:e.mapStyle,snapLayers:n.snapLayers,pluginConfig:n,events:o,eventBus:s,symbolRegistry:a}).then(e=>{t&&(i.draw=e,r.dispatch({type:"SET_HAS_SNAP_LAYERS",payload:n.snapLayers?.length>0}),s.emit("draw:ready"))}).catch(e=>me.error("[draw] failed to load the draw adapter",e)),()=>{t=!1,i.draw?.remove(),i.draw=null,i.activeMoveTarget=null}},[e.isMapReady])}const _e=new Set(["stroke","fill","strokeWidth"]),Te=e=>{if(!e)return{};const t={};for(const[n,r]of Object.entries(e))if(_e.has(n)&&"object"==typeof r&&null!==r){const e=Object.entries(r);e.length>0&&(t[n]=e[0][1]);for(const[r,i]of e)t[`${n}${r.charAt(0).toUpperCase()+r.slice(1)}`]=i}else t[n]=r;return t},Ae=e=>({appState:t,appConfig:n,pluginConfig:r,pluginState:i,mapState:o,mapProvider:s,services:a},l,u={})=>{const{dispatch:c}=i,{draw:h}=s,{eventBus:p}=a;if(!h)return;p.emit("draw:started",{mode:e});const d=void 0===u.snapLayers?r.snapLayers??null:u.snapLayers;h.setSnapLayers(d),c({type:"SET_HAS_SNAP_LAYERS",payload:d?.length>0});const{stroke:f,fill:g,strokeWidth:y,properties:m,onGeometryChange:E,...v}=u;h._geometryValidator=E??r.onGeometryChange;const S={...m,...Te({stroke:f,fill:g,strokeWidth:y})};h.changeMode(e,{container:t.layoutRefs.viewportRef.current,addVertexButtonId:`${n.id}-draw-add-point`,interfaceType:t.interfaceType,crossHair:o.crossHair,getSnapEnabled:()=>h.isSnapEnabled(),featureId:l,...v,properties:S}),c({type:"SET_MODE",payload:e})},Ce=Ae("draw_polygon"),Le=Ae("draw_line"),Ie=new Set(["Point","LineString","Polygon"]),Me=new Set(["stroke","fill","strokeWidth"]);function Re(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return Ne(e);case"FeatureCollection":return function(e){var t={type:"FeatureCollection"};return Object.keys(e).forEach(function(n){switch(n){case"type":case"features":return;default:t[n]=e[n]}}),t.features=e.features.map(function(e){return Ne(e)}),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return Oe(e);default:throw new Error("unknown GeoJSON type")}}function Ne(e){var t={type:"Feature"};return Object.keys(e).forEach(function(n){switch(n){case"type":case"properties":case"geometry":return;default:t[n]=e[n]}}),t.properties=ke(e.properties),t.geometry=Oe(e.geometry),t}function ke(e){var t={};return e?(Object.keys(e).forEach(function(n){var r=e[n];"object"==typeof r?null===r?t[n]=null:Array.isArray(r)?t[n]=r.map(function(e){return e}):t[n]=ke(r):t[n]=r}),t):t}function Oe(e){var t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(function(e){return Oe(e)}),t):(t.coordinates=De(e.coordinates),t)}function De(e){var t=e;return"object"!=typeof t[0]?t.slice():t.map(function(e){return De(e)})}function Ge(e){for(var t,n,r=function(e){if(Array.isArray(e))return e;if("Feature"===e.type){if(null!==e.geometry)return e.geometry.coordinates}else if(e.coordinates)return e.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}(e),i=0,o=1;o<r.length;)t=n||r[0],i+=((n=r[o])[0]-t[0])*(n[1]+t[1]),o++;return i>0}function Ve(e){if(Array.isArray(e))return e;if("Feature"===e.type){if(null!==e.geometry)return e.geometry.coordinates}else if(e.coordinates)return e.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function Be(e,t){if(null===(n=t=t||{})||"object"!=typeof n||Array.isArray(n))throw new Error("options is invalid");var n,r=t.reverse||!1,i=t.mutate||!1;if(!e)throw new Error("<geojson> is required");if("boolean"!=typeof r)throw new Error("<reverse> must be a boolean");if("boolean"!=typeof i)throw new Error("<mutate> must be a boolean");!1===i&&(e=Re(e));var o=[];switch(e.type){case"GeometryCollection":return x(e,function(e){Fe(e,r)}),e;case"FeatureCollection":return w(e,function(e){w(Fe(e,r),function(e){o.push(e)})}),d(o)}return Fe(e,r)}function Fe(e,t){switch("Feature"===e.type?e.geometry.type:e.type){case"GeometryCollection":return x(e,function(e){Fe(e,t)}),e;case"LineString":return Ue(Ve(e),t),e;case"Polygon":return He(Ve(e),t),e;case"MultiLineString":return Ve(e).forEach(function(e){Ue(e,t)}),e;case"MultiPolygon":return Ve(e).forEach(function(e){He(e,t)}),e;case"Point":case"MultiPoint":return e}}function Ue(e,t){Ge(e)===t&&e.reverse()}function He(e,t){Ge(e[0])!==t&&e[0].reverse();for(var n=1;n<e.length;n++)Ge(e[n])===t&&e[n].reverse()}const qe=11102230246251565e-32,Ye=134217729,je=(3+8*qe)*qe;function ze(e,t,n,r,i){let o,s,a,l,u=t[0],c=r[0],h=0,p=0;c>u==c>-u?(o=u,u=t[++h]):(o=c,c=r[++p]);let d=0;if(h<e&&p<n)for(c>u==c>-u?(s=u+o,a=o-(s-u),u=t[++h]):(s=c+o,a=o-(s-c),c=r[++p]),o=s,0!==a&&(i[d++]=a);h<e&&p<n;)c>u==c>-u?(s=o+u,l=s-o,a=o-(s-l)+(u-l),u=t[++h]):(s=o+c,l=s-o,a=o-(s-l)+(c-l),c=r[++p]),o=s,0!==a&&(i[d++]=a);for(;h<e;)s=o+u,l=s-o,a=o-(s-l)+(u-l),u=t[++h],o=s,0!==a&&(i[d++]=a);for(;p<n;)s=o+c,l=s-o,a=o-(s-l)+(c-l),c=r[++p],o=s,0!==a&&(i[d++]=a);return 0===o&&0!==d||(i[d++]=o),d}function $e(e){return new Float64Array(e)}const We=$e(4),Xe=$e(8),Ke=$e(12),Ze=$e(16),Je=$e(4);function Qe(e,t,n,r,i,o){const s=(t-o)*(n-i),a=(e-i)*(r-o),l=s-a,u=Math.abs(s+a);return Math.abs(l)>=33306690738754716e-32*u?l:-function(e,t,n,r,i,o,s){let a,l,u,c,h,p,d,f,g,y,m,E,v,S,w,b,x,P;const _=e-i,T=n-i,A=t-o,C=r-o;S=_*C,p=Ye*_,d=p-(p-_),f=_-d,p=Ye*C,g=p-(p-C),y=C-g,w=f*y-(S-d*g-f*g-d*y),b=A*T,p=Ye*A,d=p-(p-A),f=A-d,p=Ye*T,g=p-(p-T),y=T-g,x=f*y-(b-d*g-f*g-d*y),m=w-x,h=w-m,We[0]=w-(m+h)+(h-x),E=S+m,h=E-S,v=S-(E-h)+(m-h),m=v-b,h=v-m,We[1]=v-(m+h)+(h-b),P=E+m,h=P-E,We[2]=E-(P-h)+(m-h),We[3]=P;let L=function(e,t){let n=t[0];for(let r=1;r<e;r++)n+=t[r];return n}(4,We),I=22204460492503146e-32*s;if(L>=I||-L>=I)return L;if(h=e-_,a=e-(_+h)+(h-i),h=n-T,u=n-(T+h)+(h-i),h=t-A,l=t-(A+h)+(h-o),h=r-C,c=r-(C+h)+(h-o),0===a&&0===l&&0===u&&0===c)return L;if(I=11093356479670487e-47*s+je*Math.abs(L),L+=_*c+C*a-(A*u+T*l),L>=I||-L>=I)return L;S=a*C,p=Ye*a,d=p-(p-a),f=a-d,p=Ye*C,g=p-(p-C),y=C-g,w=f*y-(S-d*g-f*g-d*y),b=l*T,p=Ye*l,d=p-(p-l),f=l-d,p=Ye*T,g=p-(p-T),y=T-g,x=f*y-(b-d*g-f*g-d*y),m=w-x,h=w-m,Je[0]=w-(m+h)+(h-x),E=S+m,h=E-S,v=S-(E-h)+(m-h),m=v-b,h=v-m,Je[1]=v-(m+h)+(h-b),P=E+m,h=P-E,Je[2]=E-(P-h)+(m-h),Je[3]=P;const M=ze(4,We,4,Je,Xe);S=_*c,p=Ye*_,d=p-(p-_),f=_-d,p=Ye*c,g=p-(p-c),y=c-g,w=f*y-(S-d*g-f*g-d*y),b=A*u,p=Ye*A,d=p-(p-A),f=A-d,p=Ye*u,g=p-(p-u),y=u-g,x=f*y-(b-d*g-f*g-d*y),m=w-x,h=w-m,Je[0]=w-(m+h)+(h-x),E=S+m,h=E-S,v=S-(E-h)+(m-h),m=v-b,h=v-m,Je[1]=v-(m+h)+(h-b),P=E+m,h=P-E,Je[2]=E-(P-h)+(m-h),Je[3]=P;const R=ze(M,Xe,4,Je,Ke);S=a*c,p=Ye*a,d=p-(p-a),f=a-d,p=Ye*c,g=p-(p-c),y=c-g,w=f*y-(S-d*g-f*g-d*y),b=l*u,p=Ye*l,d=p-(p-l),f=l-d,p=Ye*u,g=p-(p-u),y=u-g,x=f*y-(b-d*g-f*g-d*y),m=w-x,h=w-m,Je[0]=w-(m+h)+(h-x),E=S+m,h=E-S,v=S-(E-h)+(m-h),m=v-b,h=v-m,Je[1]=v-(m+h)+(h-b),P=E+m,h=P-E,Je[2]=E-(P-h)+(m-h),Je[3]=P;const N=ze(R,Ke,4,Je,Ze);return Ze[N-1]}(e,t,n,r,i,o,u)}function et(e,t){var n,r,i,o,s,a,l,u,c,h=0,p=e[0],d=e[1],f=t.length;for(n=0;n<f;n++){r=0;var g=t[n],y=g.length-1;if((u=g[0])[0]!==g[y][0]&&u[1]!==g[y][1])throw new Error("First and last coordinates in a ring must be the same");for(o=u[0]-p,s=u[1]-d;r<y;r++){if(a=(c=g[r+1])[0]-p,l=c[1]-d,0===s&&0===l){if(a<=0&&o>=0||o<=0&&a>=0)return 0}else if(l>=0&&s<=0||l<=0&&s>=0){if(0===(i=Qe(o,a,s,l,0,0)))return 0;(i>0&&l>0&&s<=0||i<0&&l<=0&&s>0)&&h++}u=c,s=l,o=a}}return h%2!=0}var tt=function(e,t,n,r,i){this.p1=e,this.p2=t,this.edgeType=n,this.originalIndex=r,this.polygonContourId=i,this.interiorRing=!1,this.minX=Math.min(e.p[0],t.p[0]),this.minY=Math.min(e.p[1],t.p[1]),this.maxX=Math.max(e.p[0],t.p[0]),this.maxY=Math.max(e.p[1],t.p[1]),this.intersectionPoints=[],this.nextEdge=null},nt=function(e){this.p=e},rt=function(e,t){this.id=e,this.rawCoords=t};function it(e,t){return!(e.maxX<t[0])&&(!(e.minX>t[2])&&(!(e.maxY<t[1])&&!(e.minY>t[3])))}var ot=function(e,t,n,r){this.p=e,this.polylineEdge=t,this.polygonEdge=n,this.isHeadingIn=r,this.distanceFromPolylineEdgeStart=st(this.polylineEdge.p1.p,this.p),this.distanceFromPolygonEdgeStart=st(this.polygonEdge.p1.p,this.p),this.polygonEdge.intersectionPoints.push(this),this.polylineEdge.intersectionPoints.push(this),this.visitCount=0};function st(e,t){var n=t[0]-e[0],r=t[1]-e[1];return n*=n,r*=r,Math.sqrt(n+r)}ot.prototype.incrementVisitCount=function(){this.visitCount=this.visitCount+1};var at=1e-9;function lt(e,t){return e[0]*t[1]-e[1]*t[0]}function ut(e,t){return e[0]*t[0]+e[1]*t[1]}function ct(e,t,n){return[e[0]+t*n[0],e[1]+t*n[1]]}function ht(e,t,n){var r=[e.p2.p[0]-e.p1.p[0],e.p2.p[1]-e.p1.p[1]],i=[t.p2.p[0]-t.p1.p[0],t.p2.p[1]-t.p1.p[1]],o=[t.p1.p[0]-e.p1.p[0],t.p1.p[1]-e.p1.p[1]],s=lt(r,i),a=s*s,l=ut(r,r);if(a>0){var u=lt(o,i)/s;if(u<0||u>1)return null;var c=lt(o,r)/s;return c<0||c>1?null:0===u||1===u?[ct(e.p1.p,u,r)]:0===c||1===c?[ct(t.p1.p,c,i)]:[ct(e.p1.p,u,r)]}var h=ut(o,o);if((a=(s=lt(o,r))*s)>at*l*h)return null;var p=ut(r,o)/l,d=p+ut(r,i)/l,f=Math.min(p,d),g=Math.max(p,d);return f<=1&&g>=0?1===f?[ct(e.p1.p,f>0?f:0,r)]:0===g?[ct(e.p1.p,g<1?g:1,r)]:[ct(e.p1.p,f>0?f:0,r),ct(e.p1.p,g<1?g:1,r)]:null}function pt(e,t){var n=[],r=[],i=[],o=function(e,t,n,r,i){for(var o=0,s=[],a="Feature"===t.type?t.geometry:t,l="LineString"===a.type?[a.coordinates]:a.coordinates,u=0,c=0;c<l.length;c++){for(var h=l[c].length-1,p=new nt(l[c][0]),d=null,f={nextEdge:null},g=0;g<h;g++){d=new nt(l[c][g+1]),p.nextPoint=d,d.prevPoint=p;var y=new tt(p,d,"polyline",u,null);r.push(y),f.nextEdge=y,y.prevEdge=f,i[0]=Math.min(i[0],p.p[0]),i[1]=Math.min(i[1],p.p[1]),i[2]=Math.max(i[2],p.p[0]),i[3]=Math.max(i[3],p.p[1]),p=d,u+=1,f=y}i[0]=Math.min(i[0],l[c][h][0]),i[1]=Math.min(i[1],l[c][h][1]),i[2]=Math.max(i[2],l[c][h][0]),i[3]=Math.max(i[3],l[c][h][1])}for(var m="Feature"===e.type?e.geometry:e,E="Polygon"===m.type?[m.coordinates]:m.coordinates,v=E.length,S=0;S<v;S++)for(var w=E[S].length,b=0;b<w;b++){o+=1;var x=E[S][b],P=x.length;s.push(new rt(o,x));for(var _=new nt(x[0]),T=_,A=void 0,C=null,L={nextEdge:null,prevEdge:null},I=null,M=1;M<P;M++)A=new nt(x[M]),T.nextPoint=A,A.prevPoint=T,C=new tt(T,A,"polygon",u,o),L.nextEdge=C,C.prevEdge=L,1===M&&(I=C),b>0&&(C.interiorRing=!0),C.intersectPolylineBbox=it(C,i),n.push(C),T=A,u+=1,L=C;C.nextEdge=I,I.prevEdge=C,A.nextPoint=_.nextPoint,_.prevPoint=A.prevPoint}return s}(Be(e),t,r,i,[1/0,1/0,1/0,1/0]);if(function(e,t,n){var r,i,o,s=t.length,a=e.length;for(r=0;r<s;r++){var l=t[r];for(i=0;i<a;i++){var u=e[i];if(u.intersectPolylineBbox&&!(u.maxX<l.minX||u.minX>l.maxX||u.maxY<l.minY||u.minY>l.maxY)){var c=ht(l,u);if(null!==c)for(o=0;o<c.length;o++){var h=Qe(u.p1.p[0],u.p1.p[1],u.p2.p[0],u.p2.p[1],l.p1.p[0],l.p1.p[1]),p=new ot(c[o],l,u,h>0);n.push(p)}}}}t.forEach(function(e){e.intersectionPoints.sort(function(e,t){return e.distanceFromPolylineEdgeStart-t.distanceFromPolylineEdgeStart})}),e.forEach(function(e){e.intersectionPoints.sort(function(e,t){return e.distanceFromPolygonEdgeStart-t.distanceFromPolygonEdgeStart})})}(r,i,n),0===n.length)return e;var s={};o.forEach(function(e){return s[e.id]=0}),n.forEach(function(e){var t=e.polygonEdge.polygonContourId;s[t]=s[t]+1});for(var a=0,l=[],u=null,c=0;c<i.length;c++){var h=i[c];if(h.intersectionPoints.length>0){u=h.intersectionPoints[0];break}}for(var p=u,d={visitCount:1};u!==d&&!(a>2*n.length);){if(a=a++,d.visitCount>=2){for(var f=!1,g=0;g<n.length;g++){var y=n[g];if(y.visitCount<2){p=y,f=!0;break}}if(!f)break}p.visitCount=p.visitCount+1;var m=[];l.push(m),m.push(p.p),p.visitCount=p.visitCount+1;var E=yt(p,m),v=!1;if(E===(d=E)&&2===n.length)for(var S=0;S<n.length;S++){n[S].visitCount<2&&(v=!0)}for(;E!==p||v;){(E=(E.isHeadingIn?vt:Et)(E,m))!==p&&(E=yt(E,m)),v=!1}if(d.visitCount>=2){for(var w=!1,b=0;b<n.length;b++){var x=n[b];if(x.visitCount<2){p=x,w=!0;break}}w&&(d=p)}p=d}for(var P=l.map(function(e){return[e]}),_=Object.keys(s),T=0;T<_.length;T++){var A=_[T];if(0===s[A])gt(ft(dt(r,parseInt(A)),o),P)}return{type:"Feature",properties:{},geometry:{type:"MultiPolygon",coordinates:P}}}function dt(e,t){for(var n=0;n<e.length;n++){var r=e[n];if(r.polygonContourId===t)return r}}function ft(e,t){return t.find(function(t){return t.id===e.polygonContourId}).rawCoords}function gt(e,t){for(var n=0;n<t.length;n++){var r=t[n];if(et(e[0],[r[0]]))return void r.push(e)}t.push([e])}function yt(e,t){var n=e.polygonEdge;if(n.intersectionPoints.length>1&&n.intersectionPoints[n.intersectionPoints.length-1]!==e){var r=mt(e,n.intersectionPoints),i=n.intersectionPoints[r+1];return t.push(i.p),i.incrementVisitCount(),i}for(var o=!0;o;){if(t.push(n.p2.p),null===(n=n.nextEdge))return e;n.intersectionPoints.length>0&&(o=!1)}return n.intersectionPoints[0].incrementVisitCount(),t.push(n.intersectionPoints[0].p),n.intersectionPoints[0]}function mt(e,t){for(var n=0;n<t.length;n++){if(t[n]===e)return n}return null}function Et(e,t){var n=e.polylineEdge;if(2===n.intersectionPoints.length){var r=n.intersectionPoints[n.intersectionPoints.length-1];if(r===e){var i=n.intersectionPoints[0];return t.push(i.p),i.incrementVisitCount(),i}return t.push(r.p),r.incrementVisitCount(),r}if(n.intersectionPoints.length>2&&n.intersectionPoints[0]!==e){var o=mt(e,n.intersectionPoints),s=n.intersectionPoints[o-1];return t.push(s.p),s.incrementVisitCount(),s}for(var a=!0;a;){if(t.push(n.p1.p),void 0===(n=n.prevEdge).originalIndex)return e;n.intersectionPoints.length>0&&(a=!1)}if(void 0===n.originalIndex)return e;var l=n.intersectionPoints[n.intersectionPoints.length-1];return l.incrementVisitCount(),t.push(l.p),l}function vt(e,t){var n=e.polylineEdge;if(n.intersectionPoints.length>1&&n.intersectionPoints[n.intersectionPoints.length-1]!==e){var r=mt(e,n.intersectionPoints),i=n.intersectionPoints[r+1];return t.push(i.p),i.incrementVisitCount(),i}for(var o=!0;o;){if(t.push(n.p2.p),null===(n=n.nextEdge))return e;n.intersectionPoints.length>0&&(o=!1)}if(void 0===n)return e;var s=n.intersectionPoints[0];return s.incrementVisitCount(),t.push(s.p),s}var St=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,wt=Math.ceil,bt=Math.floor,xt="[BigNumber Error] ",Pt=xt+"Number primitive has more than 15 significant digits: ",_t=1e14,Tt=14,At=9007199254740991,Ct=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],Lt=1e7,It=1e9;function Mt(e){var t=0|e;return e>0||e===t?t:t-1}function Rt(e){for(var t,n,r=1,i=e.length,o=e[0]+"";r<i;){for(t=e[r++]+"",n=Tt-t.length;n--;t="0"+t);o+=t}for(i=o.length;48===o.charCodeAt(--i););return o.slice(0,i+1||1)}function Nt(e,t){var n,r,i=e.c,o=t.c,s=e.s,a=t.s,l=e.e,u=t.e;if(!s||!a)return null;if(n=i&&!i[0],r=o&&!o[0],n||r)return n?r?0:-a:s;if(s!=a)return s;if(n=s<0,r=l==u,!i||!o)return r?0:!i^n?1:-1;if(!r)return l>u^n?1:-1;for(a=(l=i.length)<(u=o.length)?l:u,s=0;s<a;s++)if(i[s]!=o[s])return i[s]>o[s]^n?1:-1;return l==u?0:l>u^n?1:-1}function kt(e,t,n,r){if(e<t||e>n||e!==bt(e))throw Error(xt+(r||"Argument")+("number"==typeof e?e<t||e>n?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function Ot(e){var t=e.c.length-1;return Mt(e.e/Tt)==t&&e.c[t]%2!=0}function Dt(e,t){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(t<0?"e":"e+")+t}function Gt(e,t,n){var r,i;if(t<0){for(i=n+".";++t;i+=n);e=i+e}else if(++t>(r=e.length)){for(i=n,t-=r;--t;i+=n);e+=i}else t<r&&(e=e.slice(0,t)+"."+e.slice(t));return e}var Vt=function e(t){var n,r,i,o,s,a,l,u,c,h,p=T.prototype={constructor:T,toString:null,valueOf:null},d=new T(1),f=20,g=4,y=-7,m=21,E=-1e7,v=1e7,S=!1,w=1,b=0,x={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},P="0123456789abcdefghijklmnopqrstuvwxyz",_=!0;function T(e,t){var n,o,s,a,l,u,c,h,p=this;if(!(p instanceof T))return new T(e,t);if(null==t){if(e&&!0===e._isBigNumber)return p.s=e.s,void(!e.c||e.e>v?p.c=p.e=null:e.e<E?p.c=[p.e=0]:(p.e=e.e,p.c=e.c.slice()));if((u="number"==typeof e)&&0*e==0){if(p.s=1/e<0?(e=-e,-1):1,e===~~e){for(a=0,l=e;l>=10;l/=10,a++);return void(a>v?p.c=p.e=null:(p.e=a,p.c=[e]))}h=String(e)}else{if(!St.test(h=String(e)))return i(p,h,u);p.s=45==h.charCodeAt(0)?(h=h.slice(1),-1):1}(a=h.indexOf("."))>-1&&(h=h.replace(".","")),(l=h.search(/e/i))>0?(a<0&&(a=l),a+=+h.slice(l+1),h=h.substring(0,l)):a<0&&(a=h.length)}else{if(kt(t,2,P.length,"Base"),10==t&&_)return I(p=new T(e),f+p.e+1,g);if(h=String(e),u="number"==typeof e){if(0*e!=0)return i(p,h,u,t);if(p.s=1/e<0?(h=h.slice(1),-1):1,T.DEBUG&&h.replace(/^0\.0*|\./,"").length>15)throw Error(Pt+e)}else p.s=45===h.charCodeAt(0)?(h=h.slice(1),-1):1;for(n=P.slice(0,t),a=l=0,c=h.length;l<c;l++)if(n.indexOf(o=h.charAt(l))<0){if("."==o){if(l>a){a=c;continue}}else if(!s&&(h==h.toUpperCase()&&(h=h.toLowerCase())||h==h.toLowerCase()&&(h=h.toUpperCase()))){s=!0,l=-1,a=0;continue}return i(p,String(e),u,t)}u=!1,(a=(h=r(h,t,10,p.s)).indexOf("."))>-1?h=h.replace(".",""):a=h.length}for(l=0;48===h.charCodeAt(l);l++);for(c=h.length;48===h.charCodeAt(--c););if(h=h.slice(l,++c)){if(c-=l,u&&T.DEBUG&&c>15&&(e>At||e!==bt(e)))throw Error(Pt+p.s*e);if((a=a-l-1)>v)p.c=p.e=null;else if(a<E)p.c=[p.e=0];else{if(p.e=a,p.c=[],l=(a+1)%Tt,a<0&&(l+=Tt),l<c){for(l&&p.c.push(+h.slice(0,l)),c-=Tt;l<c;)p.c.push(+h.slice(l,l+=Tt));l=Tt-(h=h.slice(l)).length}else l-=c;for(;l--;h+="0");p.c.push(+h)}}else p.c=[p.e=0]}function A(e,t,n,r){var i,o,s,a,l;if(null==n?n=g:kt(n,0,8),!e.c)return e.toString();if(i=e.c[0],s=e.e,null==t)l=Rt(e.c),l=1==r||2==r&&(s<=y||s>=m)?Dt(l,s):Gt(l,s,"0");else if(o=(e=I(new T(e),t,n)).e,a=(l=Rt(e.c)).length,1==r||2==r&&(t<=o||o<=y)){for(;a<t;l+="0",a++);l=Dt(l,o)}else if(t-=s+(2===r&&o>s),l=Gt(l,o,"0"),o+1>a){if(--t>0)for(l+=".";t--;l+="0");}else if((t+=o-a)>0)for(o+1==a&&(l+=".");t--;l+="0");return e.s<0&&i?"-"+l:l}function C(e,t){for(var n,r,i=1,o=new T(e[0]);i<e.length;i++)(!(r=new T(e[i])).s||(n=Nt(o,r))===t||0===n&&o.s===t)&&(o=r);return o}function L(e,t,n){for(var r=1,i=t.length;!t[--i];t.pop());for(i=t[0];i>=10;i/=10,r++);return(n=r+n*Tt-1)>v?e.c=e.e=null:n<E?e.c=[e.e=0]:(e.e=n,e.c=t),e}function I(e,t,n,r){var i,o,s,a,l,u,c,h=e.c,p=Ct;if(h){e:{for(i=1,a=h[0];a>=10;a/=10,i++);if((o=t-i)<0)o+=Tt,s=t,l=h[u=0],c=bt(l/p[i-s-1]%10);else if((u=wt((o+1)/Tt))>=h.length){if(!r)break e;for(;h.length<=u;h.push(0));l=c=0,i=1,s=(o%=Tt)-Tt+1}else{for(l=a=h[u],i=1;a>=10;a/=10,i++);c=(s=(o%=Tt)-Tt+i)<0?0:bt(l/p[i-s-1]%10)}if(r=r||t<0||null!=h[u+1]||(s<0?l:l%p[i-s-1]),r=n<4?(c||r)&&(0==n||n==(e.s<0?3:2)):c>5||5==c&&(4==n||r||6==n&&(o>0?s>0?l/p[i-s]:0:h[u-1])%10&1||n==(e.s<0?8:7)),t<1||!h[0])return h.length=0,r?(t-=e.e+1,h[0]=p[(Tt-t%Tt)%Tt],e.e=-t||0):h[0]=e.e=0,e;if(0==o?(h.length=u,a=1,u--):(h.length=u+1,a=p[Tt-o],h[u]=s>0?bt(l/p[i-s]%p[s])*a:0),r)for(;;){if(0==u){for(o=1,s=h[0];s>=10;s/=10,o++);for(s=h[0]+=a,a=1;s>=10;s/=10,a++);o!=a&&(e.e++,h[0]==_t&&(h[0]=1));break}if(h[u]+=a,h[u]!=_t)break;h[u--]=0,a=1}for(o=h.length;0===h[--o];h.pop());}e.e>v?e.c=e.e=null:e.e<E&&(e.c=[e.e=0])}return e}function M(e){var t,n=e.e;return null===n?e.toString():(t=Rt(e.c),t=n<=y||n>=m?Dt(t,n):Gt(t,n,"0"),e.s<0?"-"+t:t)}return T.clone=e,T.ROUND_UP=0,T.ROUND_DOWN=1,T.ROUND_CEIL=2,T.ROUND_FLOOR=3,T.ROUND_HALF_UP=4,T.ROUND_HALF_DOWN=5,T.ROUND_HALF_EVEN=6,T.ROUND_HALF_CEIL=7,T.ROUND_HALF_FLOOR=8,T.EUCLID=9,T.config=T.set=function(e){var t,n;if(null!=e){if("object"!=typeof e)throw Error(xt+"Object expected: "+e);if(e.hasOwnProperty(t="DECIMAL_PLACES")&&(kt(n=e[t],0,It,t),f=n),e.hasOwnProperty(t="ROUNDING_MODE")&&(kt(n=e[t],0,8,t),g=n),e.hasOwnProperty(t="EXPONENTIAL_AT")&&((n=e[t])&&n.pop?(kt(n[0],-It,0,t),kt(n[1],0,It,t),y=n[0],m=n[1]):(kt(n,-It,It,t),y=-(m=n<0?-n:n))),e.hasOwnProperty(t="RANGE"))if((n=e[t])&&n.pop)kt(n[0],-It,-1,t),kt(n[1],1,It,t),E=n[0],v=n[1];else{if(kt(n,-It,It,t),!n)throw Error(xt+t+" cannot be zero: "+n);E=-(v=n<0?-n:n)}if(e.hasOwnProperty(t="CRYPTO")){if((n=e[t])!==!!n)throw Error(xt+t+" not true or false: "+n);if(n){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw S=!n,Error(xt+"crypto unavailable");S=n}else S=n}if(e.hasOwnProperty(t="MODULO_MODE")&&(kt(n=e[t],0,9,t),w=n),e.hasOwnProperty(t="POW_PRECISION")&&(kt(n=e[t],0,It,t),b=n),e.hasOwnProperty(t="FORMAT")){if("object"!=typeof(n=e[t]))throw Error(xt+t+" not an object: "+n);x=n}if(e.hasOwnProperty(t="ALPHABET")){if("string"!=typeof(n=e[t])||/^.?$|[+\-.\s]|(.).*\1/.test(n))throw Error(xt+t+" invalid: "+n);_="0123456789"==n.slice(0,10),P=n}}return{DECIMAL_PLACES:f,ROUNDING_MODE:g,EXPONENTIAL_AT:[y,m],RANGE:[E,v],CRYPTO:S,MODULO_MODE:w,POW_PRECISION:b,FORMAT:x,ALPHABET:P}},T.isBigNumber=function(e){if(!e||!0!==e._isBigNumber)return!1;if(!T.DEBUG)return!0;var t,n,r=e.c,i=e.e,o=e.s;e:if("[object Array]"=={}.toString.call(r)){if((1===o||-1===o)&&i>=-It&&i<=It&&i===bt(i)){if(0===r[0]){if(0===i&&1===r.length)return!0;break e}if((t=(i+1)%Tt)<1&&(t+=Tt),String(r[0]).length==t){for(t=0;t<r.length;t++)if((n=r[t])<0||n>=_t||n!==bt(n))break e;if(0!==n)return!0}}}else if(null===r&&null===i&&(null===o||1===o||-1===o))return!0;throw Error(xt+"Invalid BigNumber: "+e)},T.maximum=T.max=function(){return C(arguments,-1)},T.minimum=T.min=function(){return C(arguments,1)},T.random=(o=9007199254740992,s=Math.random()*o&2097151?function(){return bt(Math.random()*o)}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(e){var t,n,r,i,o,a=0,l=[],u=new T(d);if(null==e?e=f:kt(e,0,It),i=wt(e/Tt),S)if(crypto.getRandomValues){for(t=crypto.getRandomValues(new Uint32Array(i*=2));a<i;)(o=131072*t[a]+(t[a+1]>>>11))>=9e15?(n=crypto.getRandomValues(new Uint32Array(2)),t[a]=n[0],t[a+1]=n[1]):(l.push(o%1e14),a+=2);a=i/2}else{if(!crypto.randomBytes)throw S=!1,Error(xt+"crypto unavailable");for(t=crypto.randomBytes(i*=7);a<i;)(o=281474976710656*(31&t[a])+1099511627776*t[a+1]+4294967296*t[a+2]+16777216*t[a+3]+(t[a+4]<<16)+(t[a+5]<<8)+t[a+6])>=9e15?crypto.randomBytes(7).copy(t,a):(l.push(o%1e14),a+=7);a=i/7}if(!S)for(;a<i;)(o=s())<9e15&&(l[a++]=o%1e14);for(i=l[--a],e%=Tt,i&&e&&(o=Ct[Tt-e],l[a]=bt(i/o)*o);0===l[a];l.pop(),a--);if(a<0)l=[r=0];else{for(r=-1;0===l[0];l.splice(0,1),r-=Tt);for(a=1,o=l[0];o>=10;o/=10,a++);a<Tt&&(r-=Tt-a)}return u.e=r,u.c=l,u}),T.sum=function(){for(var e=1,t=arguments,n=new T(t[0]);e<t.length;)n=n.plus(t[e++]);return n},r=function(){var e="0123456789";function t(e,t,n,r){for(var i,o,s=[0],a=0,l=e.length;a<l;){for(o=s.length;o--;s[o]*=t);for(s[0]+=r.indexOf(e.charAt(a++)),i=0;i<s.length;i++)s[i]>n-1&&(null==s[i+1]&&(s[i+1]=0),s[i+1]+=s[i]/n|0,s[i]%=n)}return s.reverse()}return function(r,i,o,s,a){var l,u,c,h,p,d,y,m,E=r.indexOf("."),v=f,S=g;for(E>=0&&(h=b,b=0,r=r.replace(".",""),d=(m=new T(i)).pow(r.length-E),b=h,m.c=t(Gt(Rt(d.c),d.e,"0"),10,o,e),m.e=m.c.length),c=h=(y=t(r,i,o,a?(l=P,e):(l=e,P))).length;0==y[--h];y.pop());if(!y[0])return l.charAt(0);if(E<0?--c:(d.c=y,d.e=c,d.s=s,y=(d=n(d,m,v,S,o)).c,p=d.r,c=d.e),E=y[u=c+v+1],h=o/2,p=p||u<0||null!=y[u+1],p=S<4?(null!=E||p)&&(0==S||S==(d.s<0?3:2)):E>h||E==h&&(4==S||p||6==S&&1&y[u-1]||S==(d.s<0?8:7)),u<1||!y[0])r=p?Gt(l.charAt(1),-v,l.charAt(0)):l.charAt(0);else{if(y.length=u,p)for(--o;++y[--u]>o;)y[u]=0,u||(++c,y=[1].concat(y));for(h=y.length;!y[--h];);for(E=0,r="";E<=h;r+=l.charAt(y[E++]));r=Gt(r,c,l.charAt(0))}return r}}(),n=function(){function e(e,t,n){var r,i,o,s,a=0,l=e.length,u=t%Lt,c=t/Lt|0;for(e=e.slice();l--;)a=((i=u*(o=e[l]%Lt)+(r=c*o+(s=e[l]/Lt|0)*u)%Lt*Lt+a)/n|0)+(r/Lt|0)+c*s,e[l]=i%n;return a&&(e=[a].concat(e)),e}function t(e,t,n,r){var i,o;if(n!=r)o=n>r?1:-1;else for(i=o=0;i<n;i++)if(e[i]!=t[i]){o=e[i]>t[i]?1:-1;break}return o}function n(e,t,n,r){for(var i=0;n--;)e[n]-=i,i=e[n]<t[n]?1:0,e[n]=i*r+e[n]-t[n];for(;!e[0]&&e.length>1;e.splice(0,1));}return function(r,i,o,s,a){var l,u,c,h,p,d,f,g,y,m,E,v,S,w,b,x,P,_=r.s==i.s?1:-1,A=r.c,C=i.c;if(!(A&&A[0]&&C&&C[0]))return new T(r.s&&i.s&&(A?!C||A[0]!=C[0]:C)?A&&0==A[0]||!C?0*_:_/0:NaN);for(y=(g=new T(_)).c=[],_=o+(u=r.e-i.e)+1,a||(a=_t,u=Mt(r.e/Tt)-Mt(i.e/Tt),_=_/Tt|0),c=0;C[c]==(A[c]||0);c++);if(C[c]>(A[c]||0)&&u--,_<0)y.push(1),h=!0;else{for(w=A.length,x=C.length,c=0,_+=2,(p=bt(a/(C[0]+1)))>1&&(C=e(C,p,a),A=e(A,p,a),x=C.length,w=A.length),S=x,E=(m=A.slice(0,x)).length;E<x;m[E++]=0);P=C.slice(),P=[0].concat(P),b=C[0],C[1]>=a/2&&b++;do{if(p=0,(l=t(C,m,x,E))<0){if(v=m[0],x!=E&&(v=v*a+(m[1]||0)),(p=bt(v/b))>1)for(p>=a&&(p=a-1),f=(d=e(C,p,a)).length,E=m.length;1==t(d,m,f,E);)p--,n(d,x<f?P:C,f,a),f=d.length,l=1;else 0==p&&(l=p=1),f=(d=C.slice()).length;if(f<E&&(d=[0].concat(d)),n(m,d,E,a),E=m.length,-1==l)for(;t(C,m,x,E)<1;)p++,n(m,x<E?P:C,E,a),E=m.length}else 0===l&&(p++,m=[0]);y[c++]=p,m[0]?m[E++]=A[S]||0:(m=[A[S]],E=1)}while((S++<w||null!=m[0])&&_--);h=null!=m[0],y[0]||y.splice(0,1)}if(a==_t){for(c=1,_=y[0];_>=10;_/=10,c++);I(g,o+(g.e=c+u*Tt-1)+1,s,h)}else g.e=u,g.r=+h;return g}}(),a=/^(-?)0([xbo])(?=\w[\w.]*$)/i,l=/^([^.]+)\.$/,u=/^\.([^.]+)$/,c=/^-?(Infinity|NaN)$/,h=/^\s*\+(?=[\w.])|^\s+|\s+$/g,i=function(e,t,n,r){var i,o=n?t:t.replace(h,"");if(c.test(o))e.s=isNaN(o)?null:o<0?-1:1;else{if(!n&&(o=o.replace(a,function(e,t,n){return i="x"==(n=n.toLowerCase())?16:"b"==n?2:8,r&&r!=i?e:t}),r&&(i=r,o=o.replace(l,"$1").replace(u,"0.$1")),t!=o))return new T(o,i);if(T.DEBUG)throw Error(xt+"Not a"+(r?" base "+r:"")+" number: "+t);e.s=null}e.c=e.e=null},p.absoluteValue=p.abs=function(){var e=new T(this);return e.s<0&&(e.s=1),e},p.comparedTo=function(e,t){return Nt(this,new T(e,t))},p.decimalPlaces=p.dp=function(e,t){var n,r,i,o=this;if(null!=e)return kt(e,0,It),null==t?t=g:kt(t,0,8),I(new T(o),e+o.e+1,t);if(!(n=o.c))return null;if(r=((i=n.length-1)-Mt(this.e/Tt))*Tt,i=n[i])for(;i%10==0;i/=10,r--);return r<0&&(r=0),r},p.dividedBy=p.div=function(e,t){return n(this,new T(e,t),f,g)},p.dividedToIntegerBy=p.idiv=function(e,t){return n(this,new T(e,t),0,1)},p.exponentiatedBy=p.pow=function(e,t){var n,r,i,o,s,a,l,u,c=this;if((e=new T(e)).c&&!e.isInteger())throw Error(xt+"Exponent not an integer: "+M(e));if(null!=t&&(t=new T(t)),s=e.e>14,!c.c||!c.c[0]||1==c.c[0]&&!c.e&&1==c.c.length||!e.c||!e.c[0])return u=new T(Math.pow(+M(c),s?e.s*(2-Ot(e)):+M(e))),t?u.mod(t):u;if(a=e.s<0,t){if(t.c?!t.c[0]:!t.s)return new T(NaN);(r=!a&&c.isInteger()&&t.isInteger())&&(c=c.mod(t))}else{if(e.e>9&&(c.e>0||c.e<-1||(0==c.e?c.c[0]>1||s&&c.c[1]>=24e7:c.c[0]<8e13||s&&c.c[0]<=9999975e7)))return o=c.s<0&&Ot(e)?-0:0,c.e>-1&&(o=1/o),new T(a?1/o:o);b&&(o=wt(b/Tt+2))}for(s?(n=new T(.5),a&&(e.s=1),l=Ot(e)):l=(i=Math.abs(+M(e)))%2,u=new T(d);;){if(l){if(!(u=u.times(c)).c)break;o?u.c.length>o&&(u.c.length=o):r&&(u=u.mod(t))}if(i){if(0===(i=bt(i/2)))break;l=i%2}else if(I(e=e.times(n),e.e+1,1),e.e>14)l=Ot(e);else{if(0===(i=+M(e)))break;l=i%2}c=c.times(c),o?c.c&&c.c.length>o&&(c.c.length=o):r&&(c=c.mod(t))}return r?u:(a&&(u=d.div(u)),t?u.mod(t):o?I(u,b,g,void 0):u)},p.integerValue=function(e){var t=new T(this);return null==e?e=g:kt(e,0,8),I(t,t.e+1,e)},p.isEqualTo=p.eq=function(e,t){return 0===Nt(this,new T(e,t))},p.isFinite=function(){return!!this.c},p.isGreaterThan=p.gt=function(e,t){return Nt(this,new T(e,t))>0},p.isGreaterThanOrEqualTo=p.gte=function(e,t){return 1===(t=Nt(this,new T(e,t)))||0===t},p.isInteger=function(){return!!this.c&&Mt(this.e/Tt)>this.c.length-2},p.isLessThan=p.lt=function(e,t){return Nt(this,new T(e,t))<0},p.isLessThanOrEqualTo=p.lte=function(e,t){return-1===(t=Nt(this,new T(e,t)))||0===t},p.isNaN=function(){return!this.s},p.isNegative=function(){return this.s<0},p.isPositive=function(){return this.s>0},p.isZero=function(){return!!this.c&&0==this.c[0]},p.minus=function(e,t){var n,r,i,o,s=this,a=s.s;if(t=(e=new T(e,t)).s,!a||!t)return new T(NaN);if(a!=t)return e.s=-t,s.plus(e);var l=s.e/Tt,u=e.e/Tt,c=s.c,h=e.c;if(!l||!u){if(!c||!h)return c?(e.s=-t,e):new T(h?s:NaN);if(!c[0]||!h[0])return h[0]?(e.s=-t,e):new T(c[0]?s:3==g?-0:0)}if(l=Mt(l),u=Mt(u),c=c.slice(),a=l-u){for((o=a<0)?(a=-a,i=c):(u=l,i=h),i.reverse(),t=a;t--;i.push(0));i.reverse()}else for(r=(o=(a=c.length)<(t=h.length))?a:t,a=t=0;t<r;t++)if(c[t]!=h[t]){o=c[t]<h[t];break}if(o&&(i=c,c=h,h=i,e.s=-e.s),(t=(r=h.length)-(n=c.length))>0)for(;t--;c[n++]=0);for(t=_t-1;r>a;){if(c[--r]<h[r]){for(n=r;n&&!c[--n];c[n]=t);--c[n],c[r]+=_t}c[r]-=h[r]}for(;0==c[0];c.splice(0,1),--u);return c[0]?L(e,c,u):(e.s=3==g?-1:1,e.c=[e.e=0],e)},p.modulo=p.mod=function(e,t){var r,i,o=this;return e=new T(e,t),!o.c||!e.s||e.c&&!e.c[0]?new T(NaN):!e.c||o.c&&!o.c[0]?new T(o):(9==w?(i=e.s,e.s=1,r=n(o,e,0,3),e.s=i,r.s*=i):r=n(o,e,0,w),(e=o.minus(r.times(e))).c[0]||1!=w||(e.s=o.s),e)},p.multipliedBy=p.times=function(e,t){var n,r,i,o,s,a,l,u,c,h,p,d,f,g,y,m=this,E=m.c,v=(e=new T(e,t)).c;if(!(E&&v&&E[0]&&v[0]))return!m.s||!e.s||E&&!E[0]&&!v||v&&!v[0]&&!E?e.c=e.e=e.s=null:(e.s*=m.s,E&&v?(e.c=[0],e.e=0):e.c=e.e=null),e;for(r=Mt(m.e/Tt)+Mt(e.e/Tt),e.s*=m.s,(l=E.length)<(h=v.length)&&(f=E,E=v,v=f,i=l,l=h,h=i),i=l+h,f=[];i--;f.push(0));for(g=_t,y=Lt,i=h;--i>=0;){for(n=0,p=v[i]%y,d=v[i]/y|0,o=i+(s=l);o>i;)n=((u=p*(u=E[--s]%y)+(a=d*u+(c=E[s]/y|0)*p)%y*y+f[o]+n)/g|0)+(a/y|0)+d*c,f[o--]=u%g;f[o]=n}return n?++r:f.splice(0,1),L(e,f,r)},p.negated=function(){var e=new T(this);return e.s=-e.s||null,e},p.plus=function(e,t){var n,r=this,i=r.s;if(t=(e=new T(e,t)).s,!i||!t)return new T(NaN);if(i!=t)return e.s=-t,r.minus(e);var o=r.e/Tt,s=e.e/Tt,a=r.c,l=e.c;if(!o||!s){if(!a||!l)return new T(i/0);if(!a[0]||!l[0])return l[0]?e:new T(a[0]?r:0*i)}if(o=Mt(o),s=Mt(s),a=a.slice(),i=o-s){for(i>0?(s=o,n=l):(i=-i,n=a),n.reverse();i--;n.push(0));n.reverse()}for((i=a.length)-(t=l.length)<0&&(n=l,l=a,a=n,t=i),i=0;t;)i=(a[--t]=a[t]+l[t]+i)/_t|0,a[t]=_t===a[t]?0:a[t]%_t;return i&&(a=[i].concat(a),++s),L(e,a,s)},p.precision=p.sd=function(e,t){var n,r,i,o=this;if(null!=e&&e!==!!e)return kt(e,1,It),null==t?t=g:kt(t,0,8),I(new T(o),e,t);if(!(n=o.c))return null;if(r=(i=n.length-1)*Tt+1,i=n[i]){for(;i%10==0;i/=10,r--);for(i=n[0];i>=10;i/=10,r++);}return e&&o.e+1>r&&(r=o.e+1),r},p.shiftedBy=function(e){return kt(e,-9007199254740991,At),this.times("1e"+e)},p.squareRoot=p.sqrt=function(){var e,t,r,i,o,s=this,a=s.c,l=s.s,u=s.e,c=f+4,h=new T("0.5");if(1!==l||!a||!a[0])return new T(!l||l<0&&(!a||a[0])?NaN:a?s:1/0);if(0==(l=Math.sqrt(+M(s)))||l==1/0?(((t=Rt(a)).length+u)%2==0&&(t+="0"),l=Math.sqrt(+t),u=Mt((u+1)/2)-(u<0||u%2),r=new T(t=l==1/0?"5e"+u:(t=l.toExponential()).slice(0,t.indexOf("e")+1)+u)):r=new T(l+""),r.c[0])for((l=(u=r.e)+c)<3&&(l=0);;)if(o=r,r=h.times(o.plus(n(s,o,c,1))),Rt(o.c).slice(0,l)===(t=Rt(r.c)).slice(0,l)){if(r.e<u&&--l,"9999"!=(t=t.slice(l-3,l+1))&&(i||"4999"!=t)){+t&&(+t.slice(1)||"5"!=t.charAt(0))||(I(r,r.e+f+2,1),e=!r.times(r).eq(s));break}if(!i&&(I(o,o.e+f+2,0),o.times(o).eq(s))){r=o;break}c+=4,l+=4,i=1}return I(r,r.e+f+1,g,e)},p.toExponential=function(e,t){return null!=e&&(kt(e,0,It),e++),A(this,e,t,1)},p.toFixed=function(e,t){return null!=e&&(kt(e,0,It),e=e+this.e+1),A(this,e,t)},p.toFormat=function(e,t,n){var r,i=this;if(null==n)null!=e&&t&&"object"==typeof t?(n=t,t=null):e&&"object"==typeof e?(n=e,e=t=null):n=x;else if("object"!=typeof n)throw Error(xt+"Argument not an object: "+n);if(r=i.toFixed(e,t),i.c){var o,s=r.split("."),a=+n.groupSize,l=+n.secondaryGroupSize,u=n.groupSeparator||"",c=s[0],h=s[1],p=i.s<0,d=p?c.slice(1):c,f=d.length;if(l&&(o=a,a=l,l=o,f-=o),a>0&&f>0){for(o=f%a||a,c=d.substr(0,o);o<f;o+=a)c+=u+d.substr(o,a);l>0&&(c+=u+d.slice(o)),p&&(c="-"+c)}r=h?c+(n.decimalSeparator||"")+((l=+n.fractionGroupSize)?h.replace(new RegExp("\\d{"+l+"}\\B","g"),"$&"+(n.fractionGroupSeparator||"")):h):c}return(n.prefix||"")+r+(n.suffix||"")},p.toFraction=function(e){var t,r,i,o,s,a,l,u,c,h,p,f,y=this,m=y.c;if(null!=e&&(!(l=new T(e)).isInteger()&&(l.c||1!==l.s)||l.lt(d)))throw Error(xt+"Argument "+(l.isInteger()?"out of range: ":"not an integer: ")+M(l));if(!m)return new T(y);for(t=new T(d),c=r=new T(d),i=u=new T(d),f=Rt(m),s=t.e=f.length-y.e-1,t.c[0]=Ct[(a=s%Tt)<0?Tt+a:a],e=!e||l.comparedTo(t)>0?s>0?t:c:l,a=v,v=1/0,l=new T(f),u.c[0]=0;h=n(l,t,0,1),1!=(o=r.plus(h.times(i))).comparedTo(e);)r=i,i=o,c=u.plus(h.times(o=c)),u=o,t=l.minus(h.times(o=t)),l=o;return o=n(e.minus(r),i,0,1),u=u.plus(o.times(c)),r=r.plus(o.times(i)),u.s=c.s=y.s,p=n(c,i,s*=2,g).minus(y).abs().comparedTo(n(u,r,s,g).minus(y).abs())<1?[c,i]:[u,r],v=a,p},p.toNumber=function(){return+M(this)},p.toPrecision=function(e,t){return null!=e&&kt(e,1,It),A(this,e,t,2)},p.toString=function(e){var t,n=this,i=n.s,o=n.e;return null===o?i?(t="Infinity",i<0&&(t="-"+t)):t="NaN":(null==e?t=o<=y||o>=m?Dt(Rt(n.c),o):Gt(Rt(n.c),o,"0"):10===e&&_?t=Gt(Rt((n=I(new T(n),f+o+1,g)).c),n.e,"0"):(kt(e,2,P.length,"Base"),t=r(Gt(Rt(n.c),o,"0"),10,e,i,!0)),i<0&&n.c[0]&&(t="-"+t)),t},p.valueOf=p.toJSON=function(){return M(this)},p._isBigNumber=!0,p[Symbol.toStringTag]="BigNumber",p[Symbol.for("nodejs.util.inspect.custom")]=p.valueOf,null!=t&&T.set(t),T}(),Bt=class{key;left=null;right=null;constructor(e){this.key=e}},Ft=class extends Bt{constructor(e){super(e)}},Ut=class{size=0;modificationCount=0;splayCount=0;splay(e){const t=this.root;if(null==t)return this.compare(e,e),-1;let n=null,r=null,i=null,o=null,s=t;const a=this.compare;let l;for(;;)if(l=a(s.key,e),l>0){let t=s.left;if(null==t)break;if(l=a(t.key,e),l>0&&(s.left=t.right,t.right=s,s=t,t=s.left,null==t))break;null==n?r=s:n.left=s,n=s,s=t}else{if(!(l<0))break;{let t=s.right;if(null==t)break;if(l=a(t.key,e),l<0&&(s.right=t.left,t.left=s,s=t,t=s.right,null==t))break;null==i?o=s:i.right=s,i=s,s=t}}return null!=i&&(i.right=s.left,s.left=o),null!=n&&(n.left=s.right,s.right=r),this.root!==s&&(this.root=s,this.splayCount++),l}splayMin(e){let t=e,n=t.left;for(;null!=n;){const e=n;t.left=e.right,e.right=t,t=e,n=t.left}return t}splayMax(e){let t=e,n=t.right;for(;null!=n;){const e=n;t.right=e.left,e.left=t,t=e,n=t.right}return t}_delete(e){if(null==this.root)return null;if(0!=this.splay(e))return null;let t=this.root;const n=t,r=t.left;if(this.size--,null==r)this.root=t.right;else{const e=t.right;t=this.splayMax(r),t.right=e,this.root=t}return this.modificationCount++,n}addNewRoot(e,t){this.size++,this.modificationCount++;const n=this.root;null!=n?(t<0?(e.left=n,e.right=n.right,n.right=null):(e.right=n,e.left=n.left,n.left=null),this.root=e):this.root=e}_first(){const e=this.root;return null==e?null:(this.root=this.splayMin(e),this.root)}_last(){const e=this.root;return null==e?null:(this.root=this.splayMax(e),this.root)}clear(){this.root=null,this.size=0,this.modificationCount++}has(e){return this.validKey(e)&&0==this.splay(e)}defaultCompare(){return(e,t)=>e<t?-1:e>t?1:0}wrap(){return{getRoot:()=>this.root,setRoot:e=>{this.root=e},getSize:()=>this.size,getModificationCount:()=>this.modificationCount,getSplayCount:()=>this.splayCount,setSplayCount:e=>{this.splayCount=e},splay:e=>this.splay(e),has:e=>this.has(e)}}},Ht=class e extends Ut{root=null;compare;validKey;constructor(e,t){super(),this.compare=e??this.defaultCompare(),this.validKey=t??(e=>null!=e&&null!=e)}delete(e){return!!this.validKey(e)&&null!=this._delete(e)}deleteAll(e){for(const t of e)this.delete(t)}forEach(e){const t=this[Symbol.iterator]();let n;for(;n=t.next(),!n.done;)e(n.value,n.value,this)}add(e){const t=this.splay(e);return 0!=t&&this.addNewRoot(new Ft(e),t),this}addAndReturn(e){const t=this.splay(e);return 0!=t&&this.addNewRoot(new Ft(e),t),this.root.key}addAll(e){for(const t of e)this.add(t)}isEmpty(){return null==this.root}isNotEmpty(){return null!=this.root}single(){if(0==this.size)throw"Bad state: No element";if(this.size>1)throw"Bad state: Too many element";return this.root.key}first(){if(0==this.size)throw"Bad state: No element";return this._first().key}last(){if(0==this.size)throw"Bad state: No element";return this._last().key}lastBefore(e){if(null==e)throw"Invalid arguments(s)";if(null==this.root)return null;if(this.splay(e)<0)return this.root.key;let t=this.root.left;if(null==t)return null;let n=t.right;for(;null!=n;)t=n,n=t.right;return t.key}firstAfter(e){if(null==e)throw"Invalid arguments(s)";if(null==this.root)return null;if(this.splay(e)>0)return this.root.key;let t=this.root.right;if(null==t)return null;let n=t.left;for(;null!=n;)t=n,n=t.left;return t.key}retainAll(t){const n=new e(this.compare,this.validKey),r=this.modificationCount;for(const e of t){if(r!=this.modificationCount)throw"Concurrent modification during iteration.";this.validKey(e)&&0==this.splay(e)&&n.add(this.root.key)}n.size!=this.size&&(this.root=n.root,this.size=n.size,this.modificationCount++)}lookup(e){if(!this.validKey(e))return null;return 0!=this.splay(e)?null:this.root.key}intersection(t){const n=new e(this.compare,this.validKey);for(const e of this)t.has(e)&&n.add(e);return n}difference(t){const n=new e(this.compare,this.validKey);for(const e of this)t.has(e)||n.add(e);return n}union(e){const t=this.clone();return t.addAll(e),t}clone(){const t=new e(this.compare,this.validKey);return t.size=this.size,t.root=this.copyNode(this.root),t}copyNode(e){if(null==e)return null;const t=new Ft(e.key);return function e(t,n){let r,i;do{if(r=t.left,i=t.right,null!=r){const t=new Ft(r.key);n.left=t,e(r,t)}if(null!=i){const e=new Ft(i.key);n.right=e,t=i,n=e}}while(null!=i)}(e,t),t}toSet(){return this.clone()}entries(){return new jt(this.wrap())}keys(){return this[Symbol.iterator]()}values(){return this[Symbol.iterator]()}[Symbol.iterator](){return new Yt(this.wrap())}[Symbol.toStringTag]="[object Set]"},qt=class{tree;path=new Array;modificationCount=null;splayCount;constructor(e){this.tree=e,this.splayCount=e.getSplayCount()}[Symbol.iterator](){return this}next(){return this.moveNext()?{done:!1,value:this.current()}:{done:!0,value:null}}current(){if(!this.path.length)return null;const e=this.path[this.path.length-1];return this.getValue(e)}rebuildPath(e){this.path.splice(0,this.path.length),this.tree.splay(e),this.path.push(this.tree.getRoot()),this.splayCount=this.tree.getSplayCount()}findLeftMostDescendent(e){for(;null!=e;)this.path.push(e),e=e.left}moveNext(){if(this.modificationCount!=this.tree.getModificationCount()){if(null==this.modificationCount){this.modificationCount=this.tree.getModificationCount();let e=this.tree.getRoot();for(;null!=e;)this.path.push(e),e=e.left;return this.path.length>0}throw"Concurrent modification during iteration."}if(!this.path.length)return!1;this.splayCount!=this.tree.getSplayCount()&&this.rebuildPath(this.path[this.path.length-1].key);let e=this.path[this.path.length-1],t=e.right;if(null!=t){for(;null!=t;)this.path.push(t),t=t.left;return!0}for(this.path.pop();this.path.length&&this.path[this.path.length-1].right===e;)e=this.path.pop();return this.path.length>0}},Yt=class extends qt{getValue(e){return e.key}},jt=class extends qt{getValue(e){return[e.key,e.key]}},zt=e=>()=>e,$t=e=>{const t=e?(t,n)=>n.minus(t).abs().isLessThanOrEqualTo(e):zt(!1);return(e,n)=>t(e,n)?0:e.comparedTo(n)};function Wt(e){const t=e?(t,n,r,i,o)=>t.exponentiatedBy(2).isLessThanOrEqualTo(i.minus(n).exponentiatedBy(2).plus(o.minus(r).exponentiatedBy(2)).times(e)):zt(!1);return(e,n,r)=>{const i=e.x,o=e.y,s=r.x,a=r.y,l=o.minus(a).times(n.x.minus(s)).minus(i.minus(s).times(n.y.minus(a)));return t(l,i,o,s,a)?0:l.comparedTo(0)}}var Xt=e=>e,Kt=e=>{if(e){const t=new Ht($t(e)),n=new Ht($t(e)),r=(e,t)=>t.addAndReturn(e),i=e=>({x:r(e.x,t),y:r(e.y,n)});return i({x:new Vt(0),y:new Vt(0)}),i}return Xt},Zt=e=>({set:e=>{Jt=Zt(e)},reset:()=>Zt(e),compare:$t(e),snap:Kt(e),orient:Wt(e)}),Jt=Zt(),Qt=(e,t)=>e.ll.x.isLessThanOrEqualTo(t.x)&&t.x.isLessThanOrEqualTo(e.ur.x)&&e.ll.y.isLessThanOrEqualTo(t.y)&&t.y.isLessThanOrEqualTo(e.ur.y),en=(e,t)=>{if(t.ur.x.isLessThan(e.ll.x)||e.ur.x.isLessThan(t.ll.x)||t.ur.y.isLessThan(e.ll.y)||e.ur.y.isLessThan(t.ll.y))return null;const n=e.ll.x.isLessThan(t.ll.x)?t.ll.x:e.ll.x,r=e.ur.x.isLessThan(t.ur.x)?e.ur.x:t.ur.x;return{ll:{x:n,y:e.ll.y.isLessThan(t.ll.y)?t.ll.y:e.ll.y},ur:{x:r,y:e.ur.y.isLessThan(t.ur.y)?e.ur.y:t.ur.y}}},tn=(e,t)=>e.x.times(t.y).minus(e.y.times(t.x)),nn=(e,t)=>e.x.times(t.x).plus(e.y.times(t.y)),rn=e=>nn(e,e).sqrt(),on=(e,t,n)=>{const r={x:t.x.minus(e.x),y:t.y.minus(e.y)},i={x:n.x.minus(e.x),y:n.y.minus(e.y)};return tn(i,r).div(rn(i)).div(rn(r))},sn=(e,t,n)=>{const r={x:t.x.minus(e.x),y:t.y.minus(e.y)},i={x:n.x.minus(e.x),y:n.y.minus(e.y)};return nn(i,r).div(rn(i)).div(rn(r))},an=(e,t,n)=>t.y.isZero()?null:{x:e.x.plus(t.x.div(t.y).times(n.minus(e.y))),y:n},ln=(e,t,n)=>t.x.isZero()?null:{x:n,y:e.y.plus(t.y.div(t.x).times(n.minus(e.x)))},un=class e{point;isLeft;segment;otherSE;consumedBy;static compare(t,n){const r=e.comparePoints(t.point,n.point);return 0!==r?r:(t.point!==n.point&&t.link(n),t.isLeft!==n.isLeft?t.isLeft?1:-1:mn.compare(t.segment,n.segment))}static comparePoints(e,t){return e.x.isLessThan(t.x)?-1:e.x.isGreaterThan(t.x)?1:e.y.isLessThan(t.y)?-1:e.y.isGreaterThan(t.y)?1:0}constructor(e,t){void 0===e.events?e.events=[this]:e.events.push(this),this.point=e,this.isLeft=t}link(e){if(e.point===this.point)throw new Error("Tried to link already linked events");const t=e.point.events;for(let e=0,n=t.length;e<n;e++){const n=t[e];this.point.events.push(n),n.point=this.point}this.checkForConsuming()}checkForConsuming(){const e=this.point.events.length;for(let t=0;t<e;t++){const n=this.point.events[t];if(void 0===n.segment.consumedBy)for(let r=t+1;r<e;r++){const e=this.point.events[r];void 0===e.consumedBy&&(n.otherSE.point.events===e.otherSE.point.events&&n.segment.consume(e.segment))}}}getAvailableLinkedEvents(){const e=[];for(let t=0,n=this.point.events.length;t<n;t++){const n=this.point.events[t];n!==this&&!n.segment.ringOut&&n.segment.isInResult()&&e.push(n)}return e}getLeftmostComparator(e){const t=new Map,n=n=>{const r=n.otherSE;t.set(n,{sine:on(this.point,e.point,r.point),cosine:sn(this.point,e.point,r.point)})};return(e,r)=>{t.has(e)||n(e),t.has(r)||n(r);const{sine:i,cosine:o}=t.get(e),{sine:s,cosine:a}=t.get(r);return i.isGreaterThanOrEqualTo(0)&&s.isGreaterThanOrEqualTo(0)?o.isLessThan(a)?1:o.isGreaterThan(a)?-1:0:i.isLessThan(0)&&s.isLessThan(0)?o.isLessThan(a)?-1:o.isGreaterThan(a)?1:0:s.isLessThan(i)?-1:s.isGreaterThan(i)?1:0}}},cn=class e{events;poly;_isExteriorRing;_enclosingRing;static factory(t){const n=[];for(let r=0,i=t.length;r<i;r++){const i=t[r];if(!i.isInResult()||i.ringOut)continue;let o=null,s=i.leftSE,a=i.rightSE;const l=[s],u=s.point,c=[];for(;o=s,s=a,l.push(s),s.point!==u;)for(;;){const t=s.getAvailableLinkedEvents();if(0===t.length){const e=l[0].point,t=l[l.length-1].point;throw new Error(`Unable to complete output ring starting at [${e.x}, ${e.y}]. Last matching segment found ends at [${t.x}, ${t.y}].`)}if(1===t.length){a=t[0].otherSE;break}let r=null;for(let e=0,t=c.length;e<t;e++)if(c[e].point===s.point){r=e;break}if(null!==r){const t=c.splice(r)[0],i=l.splice(t.index);i.unshift(i[0].otherSE),n.push(new e(i.reverse()));continue}c.push({index:l.length,point:s.point});const i=s.getLeftmostComparator(o);a=t.sort(i)[0].otherSE;break}n.push(new e(l))}return n}constructor(e){this.events=e;for(let t=0,n=e.length;t<n;t++)e[t].segment.ringOut=this;this.poly=null}getGeom(){let e=this.events[0].point;const t=[e];for(let n=1,r=this.events.length-1;n<r;n++){const r=this.events[n].point,i=this.events[n+1].point;0!==Jt.orient(r,e,i)&&(t.push(r),e=r)}if(1===t.length)return null;const n=t[0],r=t[1];0===Jt.orient(n,e,r)&&t.shift(),t.push(t[0]);const i=this.isExteriorRing()?1:-1,o=this.isExteriorRing()?0:t.length-1,s=this.isExteriorRing()?t.length:-1,a=[];for(let e=o;e!=s;e+=i)a.push([t[e].x.toNumber(),t[e].y.toNumber()]);return a}isExteriorRing(){if(void 0===this._isExteriorRing){const e=this.enclosingRing();this._isExteriorRing=!e||!e.isExteriorRing()}return this._isExteriorRing}enclosingRing(){return void 0===this._enclosingRing&&(this._enclosingRing=this._calcEnclosingRing()),this._enclosingRing}_calcEnclosingRing(){let e=this.events[0];for(let t=1,n=this.events.length;t<n;t++){const n=this.events[t];un.compare(e,n)>0&&(e=n)}let t=e.segment.prevInResult(),n=t?t.prevInResult():null;for(;;){if(!t)return null;if(!n)return t.ringOut;if(n.ringOut!==t.ringOut)return n.ringOut?.enclosingRing()!==t.ringOut?t.ringOut:t.ringOut?.enclosingRing();t=n.prevInResult(),n=t?t.prevInResult():null}}},hn=class{exteriorRing;interiorRings;constructor(e){this.exteriorRing=e,e.poly=this,this.interiorRings=[]}addInterior(e){this.interiorRings.push(e),e.poly=this}getGeom(){const e=this.exteriorRing.getGeom();if(null===e)return null;const t=[e];for(let e=0,n=this.interiorRings.length;e<n;e++){const n=this.interiorRings[e].getGeom();null!==n&&t.push(n)}return t}},pn=class{rings;polys;constructor(e){this.rings=e,this.polys=this._composePolys(e)}getGeom(){const e=[];for(let t=0,n=this.polys.length;t<n;t++){const n=this.polys[t].getGeom();null!==n&&e.push(n)}return e}_composePolys(e){const t=[];for(let n=0,r=e.length;n<r;n++){const r=e[n];if(!r.poly)if(r.isExteriorRing())t.push(new hn(r));else{const e=r.enclosingRing();e?.poly||t.push(new hn(e)),e?.poly?.addInterior(r)}}return t}},dn=class{queue;tree;segments;constructor(e,t=mn.compare){this.queue=e,this.tree=new Ht(t),this.segments=[]}process(e){const t=e.segment,n=[];if(e.consumedBy)return e.isLeft?this.queue.delete(e.otherSE):this.tree.delete(t),n;e.isLeft&&this.tree.add(t);let r=t,i=t;do{r=this.tree.lastBefore(r)}while(null!=r&&null!=r.consumedBy);do{i=this.tree.firstAfter(i)}while(null!=i&&null!=i.consumedBy);if(e.isLeft){let o=null;if(r){const e=r.getIntersection(t);if(null!==e&&(t.isAnEndpoint(e)||(o=e),!r.isAnEndpoint(e))){const t=this._splitSafely(r,e);for(let e=0,r=t.length;e<r;e++)n.push(t[e])}}let s=null;if(i){const e=i.getIntersection(t);if(null!==e&&(t.isAnEndpoint(e)||(s=e),!i.isAnEndpoint(e))){const t=this._splitSafely(i,e);for(let e=0,r=t.length;e<r;e++)n.push(t[e])}}if(null!==o||null!==s){let e=null;if(null===o)e=s;else if(null===s)e=o;else{e=un.comparePoints(o,s)<=0?o:s}this.queue.delete(t.rightSE),n.push(t.rightSE);const r=t.split(e);for(let e=0,t=r.length;e<t;e++)n.push(r[e])}n.length>0?(this.tree.delete(t),n.push(e)):(this.segments.push(t),t.prev=r)}else{if(r&&i){const e=r.getIntersection(i);if(null!==e){if(!r.isAnEndpoint(e)){const t=this._splitSafely(r,e);for(let e=0,r=t.length;e<r;e++)n.push(t[e])}if(!i.isAnEndpoint(e)){const t=this._splitSafely(i,e);for(let e=0,r=t.length;e<r;e++)n.push(t[e])}}}this.tree.delete(t)}return n}_splitSafely(e,t){this.tree.delete(e);const n=e.rightSE;this.queue.delete(n);const r=e.split(t);return r.push(n),void 0===e.consumedBy&&this.tree.add(e),r}},fn=new class{type;numMultiPolys;run(e,t,n){fn.type=e;const r=[new Sn(t,!0)];for(let e=0,t=n.length;e<t;e++)r.push(new Sn(n[e],!1));if(fn.numMultiPolys=r.length,"difference"===fn.type){const e=r[0];let t=1;for(;t<r.length;)null!==en(r[t].bbox,e.bbox)?t++:r.splice(t,1)}if("intersection"===fn.type)for(let e=0,t=r.length;e<t;e++){const t=r[e];for(let n=e+1,i=r.length;n<i;n++)if(null===en(t.bbox,r[n].bbox))return[]}const i=new Ht(un.compare);for(let e=0,t=r.length;e<t;e++){const t=r[e].getSweepEvents();for(let e=0,n=t.length;e<n;e++)i.add(t[e])}const o=new dn(i);let s=null;for(0!=i.size&&(s=i.first(),i.delete(s));s;){const e=o.process(s);for(let t=0,n=e.length;t<n;t++){const n=e[t];void 0===n.consumedBy&&i.add(n)}0!=i.size?(s=i.first(),i.delete(s)):s=null}Jt.reset();const a=cn.factory(o.segments);return new pn(a).getGeom()}},gn=fn,yn=0,mn=class e{id;leftSE;rightSE;rings;windings;ringOut;consumedBy;prev;_prevInResult;_beforeState;_afterState;_isInResult;static compare(e,t){const n=e.leftSE.point.x,r=t.leftSE.point.x,i=e.rightSE.point.x,o=t.rightSE.point.x;if(o.isLessThan(n))return 1;if(i.isLessThan(r))return-1;const s=e.leftSE.point.y,a=t.leftSE.point.y,l=e.rightSE.point.y,u=t.rightSE.point.y;if(n.isLessThan(r)){if(a.isLessThan(s)&&a.isLessThan(l))return 1;if(a.isGreaterThan(s)&&a.isGreaterThan(l))return-1;const n=e.comparePoint(t.leftSE.point);if(n<0)return 1;if(n>0)return-1;const r=t.comparePoint(e.rightSE.point);return 0!==r?r:-1}if(n.isGreaterThan(r)){if(s.isLessThan(a)&&s.isLessThan(u))return-1;if(s.isGreaterThan(a)&&s.isGreaterThan(u))return 1;const n=t.comparePoint(e.leftSE.point);if(0!==n)return n;const r=e.comparePoint(t.rightSE.point);return r<0?1:r>0?-1:1}if(s.isLessThan(a))return-1;if(s.isGreaterThan(a))return 1;if(i.isLessThan(o)){const n=t.comparePoint(e.rightSE.point);if(0!==n)return n}if(i.isGreaterThan(o)){const n=e.comparePoint(t.rightSE.point);if(n<0)return 1;if(n>0)return-1}if(!i.eq(o)){const e=l.minus(s),t=i.minus(n),c=u.minus(a),h=o.minus(r);if(e.isGreaterThan(t)&&c.isLessThan(h))return 1;if(e.isLessThan(t)&&c.isGreaterThan(h))return-1}return i.isGreaterThan(o)?1:i.isLessThan(o)||l.isLessThan(u)?-1:l.isGreaterThan(u)?1:e.id<t.id?-1:e.id>t.id?1:0}constructor(e,t,n,r){this.id=++yn,this.leftSE=e,e.segment=this,e.otherSE=t,this.rightSE=t,t.segment=this,t.otherSE=e,this.rings=n,this.windings=r}static fromRing(t,n,r){let i,o,s;const a=un.comparePoints(t,n);if(a<0)i=t,o=n,s=1;else{if(!(a>0))throw new Error(`Tried to create degenerate segment at [${t.x}, ${t.y}]`);i=n,o=t,s=-1}const l=new un(i,!0),u=new un(o,!1);return new e(l,u,[r],[s])}replaceRightSE(e){this.rightSE=e,this.rightSE.segment=this,this.rightSE.otherSE=this.leftSE,this.leftSE.otherSE=this.rightSE}bbox(){const e=this.leftSE.point.y,t=this.rightSE.point.y;return{ll:{x:this.leftSE.point.x,y:e.isLessThan(t)?e:t},ur:{x:this.rightSE.point.x,y:e.isGreaterThan(t)?e:t}}}vector(){return{x:this.rightSE.point.x.minus(this.leftSE.point.x),y:this.rightSE.point.y.minus(this.leftSE.point.y)}}isAnEndpoint(e){return e.x.eq(this.leftSE.point.x)&&e.y.eq(this.leftSE.point.y)||e.x.eq(this.rightSE.point.x)&&e.y.eq(this.rightSE.point.y)}comparePoint(e){return Jt.orient(this.leftSE.point,e,this.rightSE.point)}getIntersection(e){const t=this.bbox(),n=e.bbox(),r=en(t,n);if(null===r)return null;const i=this.leftSE.point,o=this.rightSE.point,s=e.leftSE.point,a=e.rightSE.point,l=Qt(t,s)&&0===this.comparePoint(s),u=Qt(n,i)&&0===e.comparePoint(i),c=Qt(t,a)&&0===this.comparePoint(a),h=Qt(n,o)&&0===e.comparePoint(o);if(u&&l)return h&&!c?o:!h&&c?a:null;if(u)return c&&i.x.eq(a.x)&&i.y.eq(a.y)?null:i;if(l)return h&&o.x.eq(s.x)&&o.y.eq(s.y)?null:s;if(h&&c)return null;if(h)return o;if(c)return a;const p=((e,t,n,r)=>{if(t.x.isZero())return ln(n,r,e.x);if(r.x.isZero())return ln(e,t,n.x);if(t.y.isZero())return an(n,r,e.y);if(r.y.isZero())return an(e,t,n.y);const i=tn(t,r);if(i.isZero())return null;const o={x:n.x.minus(e.x),y:n.y.minus(e.y)},s=tn(o,t).div(i),a=tn(o,r).div(i),l=e.x.plus(a.times(t.x)),u=n.x.plus(s.times(r.x)),c=e.y.plus(a.times(t.y)),h=n.y.plus(s.times(r.y));return{x:l.plus(u).div(2),y:c.plus(h).div(2)}})(i,this.vector(),s,e.vector());return null===p?null:Qt(r,p)?Jt.snap(p):null}split(t){const n=[],r=void 0!==t.events,i=new un(t,!0),o=new un(t,!1),s=this.rightSE;this.replaceRightSE(o),n.push(o),n.push(i);const a=new e(i,s,this.rings.slice(),this.windings.slice());return un.comparePoints(a.leftSE.point,a.rightSE.point)>0&&a.swapEvents(),un.comparePoints(this.leftSE.point,this.rightSE.point)>0&&this.swapEvents(),r&&(i.checkForConsuming(),o.checkForConsuming()),n}swapEvents(){const e=this.rightSE;this.rightSE=this.leftSE,this.leftSE=e,this.leftSE.isLeft=!0,this.rightSE.isLeft=!1;for(let e=0,t=this.windings.length;e<t;e++)this.windings[e]*=-1}consume(t){let n=this,r=t;for(;n.consumedBy;)n=n.consumedBy;for(;r.consumedBy;)r=r.consumedBy;const i=e.compare(n,r);if(0!==i){if(i>0){const e=n;n=r,r=e}if(n.prev===r){const e=n;n=r,r=e}for(let e=0,t=r.rings.length;e<t;e++){const t=r.rings[e],i=r.windings[e],o=n.rings.indexOf(t);-1===o?(n.rings.push(t),n.windings.push(i)):n.windings[o]+=i}r.rings=null,r.windings=null,r.consumedBy=n,r.leftSE.consumedBy=n.leftSE,r.rightSE.consumedBy=n.rightSE}}prevInResult(){return void 0!==this._prevInResult||(this.prev?this.prev.isInResult()?this._prevInResult=this.prev:this._prevInResult=this.prev.prevInResult():this._prevInResult=null),this._prevInResult}beforeState(){if(void 0!==this._beforeState)return this._beforeState;if(this.prev){const e=this.prev.consumedBy||this.prev;this._beforeState=e.afterState()}else this._beforeState={rings:[],windings:[],multiPolys:[]};return this._beforeState}afterState(){if(void 0!==this._afterState)return this._afterState;const e=this.beforeState();this._afterState={rings:e.rings.slice(0),windings:e.windings.slice(0),multiPolys:[]};const t=this._afterState.rings,n=this._afterState.windings,r=this._afterState.multiPolys;for(let e=0,r=this.rings.length;e<r;e++){const r=this.rings[e],i=this.windings[e],o=t.indexOf(r);-1===o?(t.push(r),n.push(i)):n[o]+=i}const i=[],o=[];for(let e=0,r=t.length;e<r;e++){if(0===n[e])continue;const r=t[e],s=r.poly;if(-1===o.indexOf(s))if(r.isExterior)i.push(s);else{-1===o.indexOf(s)&&o.push(s);const e=i.indexOf(r.poly);-1!==e&&i.splice(e,1)}}for(let e=0,t=i.length;e<t;e++){const t=i[e].multiPoly;-1===r.indexOf(t)&&r.push(t)}return this._afterState}isInResult(){if(this.consumedBy)return!1;if(void 0!==this._isInResult)return this._isInResult;const e=this.beforeState().multiPolys,t=this.afterState().multiPolys;switch(gn.type){case"union":{const n=0===e.length,r=0===t.length;this._isInResult=n!==r;break}case"intersection":{let n,r;e.length<t.length?(n=e.length,r=t.length):(n=t.length,r=e.length),this._isInResult=r===gn.numMultiPolys&&n<r;break}case"xor":{const n=Math.abs(e.length-t.length);this._isInResult=n%2==1;break}case"difference":{const n=e=>1===e.length&&e[0].isSubject;this._isInResult=n(e)!==n(t);break}}return this._isInResult}},En=class{poly;isExterior;segments;bbox;constructor(e,t,n){if(!Array.isArray(e)||0===e.length)throw new Error("Input geometry is not a valid Polygon or MultiPolygon");if(this.poly=t,this.isExterior=n,this.segments=[],"number"!=typeof e[0][0]||"number"!=typeof e[0][1])throw new Error("Input geometry is not a valid Polygon or MultiPolygon");const r=Jt.snap({x:new Vt(e[0][0]),y:new Vt(e[0][1])});this.bbox={ll:{x:r.x,y:r.y},ur:{x:r.x,y:r.y}};let i=r;for(let t=1,n=e.length;t<n;t++){if("number"!=typeof e[t][0]||"number"!=typeof e[t][1])throw new Error("Input geometry is not a valid Polygon or MultiPolygon");const n=Jt.snap({x:new Vt(e[t][0]),y:new Vt(e[t][1])});n.x.eq(i.x)&&n.y.eq(i.y)||(this.segments.push(mn.fromRing(i,n,this)),n.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=n.x),n.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=n.y),n.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=n.x),n.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=n.y),i=n)}r.x.eq(i.x)&&r.y.eq(i.y)||this.segments.push(mn.fromRing(i,r,this))}getSweepEvents(){const e=[];for(let t=0,n=this.segments.length;t<n;t++){const n=this.segments[t];e.push(n.leftSE),e.push(n.rightSE)}return e}},vn=class{multiPoly;exteriorRing;interiorRings;bbox;constructor(e,t){if(!Array.isArray(e))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");this.exteriorRing=new En(e[0],this,!0),this.bbox={ll:{x:this.exteriorRing.bbox.ll.x,y:this.exteriorRing.bbox.ll.y},ur:{x:this.exteriorRing.bbox.ur.x,y:this.exteriorRing.bbox.ur.y}},this.interiorRings=[];for(let t=1,n=e.length;t<n;t++){const n=new En(e[t],this,!1);n.bbox.ll.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=n.bbox.ll.x),n.bbox.ll.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=n.bbox.ll.y),n.bbox.ur.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=n.bbox.ur.x),n.bbox.ur.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=n.bbox.ur.y),this.interiorRings.push(n)}this.multiPoly=t}getSweepEvents(){const e=this.exteriorRing.getSweepEvents();for(let t=0,n=this.interiorRings.length;t<n;t++){const n=this.interiorRings[t].getSweepEvents();for(let t=0,r=n.length;t<r;t++)e.push(n[t])}return e}},Sn=class{isSubject;polys;bbox;constructor(e,t){if(!Array.isArray(e))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");try{"number"==typeof e[0][0][0]&&(e=[e])}catch(e){}this.polys=[],this.bbox={ll:{x:new Vt(Number.POSITIVE_INFINITY),y:new Vt(Number.POSITIVE_INFINITY)},ur:{x:new Vt(Number.NEGATIVE_INFINITY),y:new Vt(Number.NEGATIVE_INFINITY)}};for(let t=0,n=e.length;t<n;t++){const n=new vn(e[t],this);n.bbox.ll.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=n.bbox.ll.x),n.bbox.ll.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=n.bbox.ll.y),n.bbox.ur.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=n.bbox.ur.x),n.bbox.ur.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=n.bbox.ur.y),this.polys.push(n)}this.isSubject=t}getSweepEvents(){const e=[];for(let t=0,n=this.polys.length;t<n;t++){const n=this.polys[t].getSweepEvents();for(let t=0,r=n.length;t<r;t++)e.push(n[t])}return e}};Jt.set;var wn=function(e,t={}){const n=[];if(x(e,e=>{n.push(e.coordinates)}),n.length<2)throw new Error("Must have at least 2 geometries");const r=((e,...t)=>gn.run("union",e,t))(n[0],...n.slice(1));return 0===r.length?null:1===r.length?h(r[0],t.properties):function(e,t,n={}){return u({type:"MultiPolygon",coordinates:e},t,n)}(r,t.properties)};const bn=(e,t)=>{const n=function(e,t=.01){const n=e.geometry.coordinates.map(e=>[...e]),r=n.length-1,i=(e,n)=>[e[0]+(e[0]-n[0])*t,e[1]+(e[1]-n[1])*t],o=i(n[0],n[1]),s=i(n[r],n[r-1]);return n[0]=o,n[r]=s,p(n)}(t);let r;try{r=pt(e,n)}catch{return null}let i=[];if("MultiPolygon"!==r.geometry.type)return null;if(2!==r.geometry.coordinates.length)return null;i=r.geometry.coordinates.map(t=>h(t,e.properties));const o=e.id??e.properties?.id??"poly";return d(i.map((t,n)=>h(t.geometry.coordinates,{...e.properties,id:o},{id:`${o}-${n+1}`})))},xn=([e,t],[n,r])=>{const i=e=>e*Math.PI/180,o=i(r-t),s=i(n-e),a=Math.sin(o/2)**2+Math.cos(i(t))*Math.cos(i(r))*Math.sin(s/2)**2;return 12742e3*Math.atan2(Math.sqrt(a),Math.sqrt(1-a))},Pn=(e,t=.01)=>{const n=e[0];return n.length<=1||!(n.length<=3&&((e,t)=>{for(let n=0;n<e.length;n++)for(let r=n+1;r<e.length;r++)if(xn(e[n],e[r])<t)return!0;return!1})(n,t))},_n=(e,t=.01)=>{if(e.length<=1)return!0;const n=e[e.length-1],r=e[e.length-2];return xn(n,r)>=t},Tn=e=>e[0].length<=1||Pn(e),An="_splitter",Cn=({draw:e,polygonFeature:t,feature:n})=>{const r=((e,t)=>{const n=t.geometry?.coordinates;return!(!n||n.length<2||!bn(e,{geometry:t.geometry}))})(t,n);return e.setDrawingPreviewProperty("splitter",r?"valid":"invalid"),r},Ln=({draw:e,dispatch:t,polygonFeature:n})=>({feature:r,phase:i})=>{let o;if("preview"===i)o=Cn({draw:e,polygonFeature:n,feature:r});else{if(!i?.startsWith("commit-"))return{valid:!0};o=(({draw:e,dispatch:t,polygonFeature:n,feature:r})=>{const i=Cn({draw:e,polygonFeature:n,feature:r});return t({type:"SET_ACTION",payload:{name:"split",isValid:i}}),t({type:"SET_GEOMETRY_VALID",payload:i}),e.setGeometryValid(i),i})({draw:e,dispatch:t,polygonFeature:n,feature:r})}return o?{valid:!0}:{valid:!1,reason:"Line does not split the shape into two parts"}},In=()=>"undefined"!=typeof navigator&&/mac/i.test(navigator.userAgentData?.platform||navigator.platform||""),Mn=new Set(["edit_vertex","edit_point"]),Rn=e=>Mn.has(e),Nn=In()?"<kbd>Command</kbd> + <kbd>Z</kbd>":"<kbd>Ctrl</kbd> + <kbd>Z</kbd>",kn=In()?"<kbd>Option</kbd>":"<kbd>Alt</kbd>",On="top-middle",Dn=(e,t="actions")=>({mobile:{slot:t,showLabel:e},tablet:{slot:t,showLabel:e},desktop:{slot:t,showLabel:e}}),Gn={reducer:{initialState:{mode:null,action:null,actionValid:!1,feature:null,tempFeature:null,selectedVertexIndex:-1,numVertices:null,geometryValid:!0,canAddPoint:!0,snap:!1,hasSnapLayers:!1,undoStackLength:0},actions:i},InitComponent:({appState:r,appConfig:i,mapState:s,pluginConfig:a,pluginState:l,services:u,mapProvider:c,buttonConfig:h,setApplicationMode:p,clearApplicationMode:d})=>{const{eventBus:f,hints:g,symbolRegistry:y}=u,{crossHair:m}=s,E=["touch","keyboard"].includes(r.interfaceType);xe({mapState:s,pluginState:l,services:u,mapProvider:c,spatialListRegistry:r.spatialListRegistry,viewportRef:r.layoutRefs.viewportRef});const v=e(!1);v.current=["draw_polygon","draw_line","draw_point"].includes(l.mode)&&(E||r.expandedButtons?.has("mapControls")),Pe({mapState:s,pluginConfig:a,pluginState:l,mapProvider:c,eventBus:f,symbolRegistry:y}),n(()=>{if(l.mode)return p(ae),()=>d(ae);d(ae)},[l.mode]),t(()=>{const e=null!==l.mode&&"edit_vertex"!==l.mode;return f.emit(o.MAP_SET_SPATIAL_LIST_SUPPRESSED,{suppressed:e}),()=>{f.emit(o.MAP_SET_SPATIAL_LIST_SUPPRESSED,{suppressed:!1})}},[l.mode,f]),t(()=>{if(!v.current)return;const e=m.isVisible;return m.fixAtCenter(),()=>{e||v.current||m.hide()}},[l.mode,r.interfaceType,r.expandedButtons]),t(()=>{["edit_vertex","edit_point","draw_polygon","draw_line","draw_point"].includes(l.mode)&&c.draw&&c.draw.setInterfaceType(r.interfaceType)},[r.interfaceType,l.mode]),t(()=>{if(c.draw)return ge({appState:r,appConfig:i,mapState:s,mapProvider:c,buttonConfig:h,pluginState:l,eventBus:f,hints:g})},[c,r,l])},applicationModes:{[ae]:{include:["mapStyles","mapControls","scaleBar"]}},buttons:[{id:"drawCancel",label:"Cancel",variant:"tertiary",exclusiveSlot:!0,hiddenWhen:({pluginState:e})=>!e.mode,...Dn(!0)},{id:"drawAddPoint",label:"Add point",variant:"primary",exclusiveSlot:!0,hiddenWhen:({appState:e,pluginState:t})=>!["draw_polygon","draw_line","draw_point"].includes(t.mode)||"touch"!==e.interfaceType,enableWhen:({pluginState:e})=>e.canAddPoint,...Dn(!0)},{id:"drawDone",label:"Done",variant:"primary",exclusiveSlot:!0,hiddenWhen:({pluginState:e})=>!(["draw_polygon","draw_line"].includes(e.mode)||Rn(e.mode)),enableWhen:({pluginState:e})=>{const{mode:t,geometryValid:n}=e;return(["draw_polygon","draw_line"].includes(t)||Rn(t))&&n},...Dn(!0)},{id:"drawUndo",label:"Undo",iconId:"undo",hiddenWhen:({pluginState:e})=>!(["draw_polygon","draw_line"].includes(e.mode)||Rn(e.mode)),enableWhen:({pluginState:e})=>["draw_polygon","draw_line"].includes(e.mode)?e.numVertices>0:e.undoStackLength>0,...Dn(!1,On)},{id:"drawSnap",label:"Snap",iconId:"magnet",hiddenWhen:({pluginState:e})=>!e.mode||!e.hasSnapLayers,pressedWhen:({pluginState:e})=>!!e.snap,...Dn(!0,On)},{id:"drawDeletePoint",label:"Delete point",iconId:"trash",enableWhen:({pluginState:e})=>{if(e.selectedVertexIndex<0)return!1;return"Polygon"===e.feature?.geometry?.type?e.numVertices>3:e.numVertices>2},hiddenWhen:({pluginState:e})=>"edit_vertex"!==e.mode,...Dn(!1,On)}],keyboardShortcuts:[{id:"drawAddPoint",group:"Drawing",title:"Add point (draw)",command:"<kbd>Enter</kbd>"},{id:"drawSelectPoint",group:"Drawing",title:"Select nearest point (edit)",command:"<kbd>Spacebar</kbd>"},{id:"drawSelectAdjacentPoint",group:"Drawing",title:"Select adjacent point (edit)",command:`${kn} + <kbd>↑</kbd> <kbd>↓</kbd> <kbd>←</kbd> or <kbd>→</kbd>`},{id:"drawMovePoint",group:"Drawing",title:"Move point (edit)",command:"<kbd>↑</kbd> <kbd>↓</kbd> <kbd>←</kbd> or <kbd>→</kbd>"},{id:"drawNudgePoint",group:"Drawing",title:"Nudge point (edit)",command:"<kbd>Shift</kbd> + <kbd>↑</kbd> <kbd>↓</kbd> <kbd>←</kbd> or <kbd>→</kbd>"},{id:"drawDeletePoint",group:"Drawing",title:"Delete point (edit)",command:"<kbd>Delete</kbd>"},{id:"drawUndo",group:"Drawing",title:"Undo",command:Nn}],icons:[{id:"undo",svgContent:'<path d="M9 14 4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11"/>'},{id:"magnet",svgContent:'<path d="m12 15 4 4"/><path d="M2.352 10.648a1.205 1.205 0 0 0 0 1.704l2.296 2.296a1.205 1.205 0 0 0 1.704 0l6.029-6.029a1 1 0 1 1 3 3l-6.029 6.029a1.205 1.205 0 0 0 0 1.704l2.296 2.296a1.205 1.205 0 0 0 1.704 0l6.365-6.367A1 1 0 0 0 8.716 4.282z"/><path d="m5 8 4 4"/>'},{id:"trash",svgContent:'<path d="M10 11v6"/><path d="M14 11v6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"/><path d="M3 6h18"/><path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>'}],api:{newPolygon:Ce,newLine:Le,newPoint:({appState:e,appConfig:t,pluginConfig:n,pluginState:r,mapState:i,mapProvider:o,services:s},a,l={})=>{const{dispatch:u}=r,{draw:c}=o,{eventBus:h}=s;if(!c)return;h.emit("draw:started",{mode:"draw_point"});const p=void 0===l.snapLayers?n.snapLayers??null:l.snapLayers;c.setSnapLayers(p),u({type:"SET_HAS_SNAP_LAYERS",payload:p?.length>0});const{properties:d,onGeometryChange:f,...g}=l;c._geometryValidator=f??n.onGeometryChange;const y={};le.forEach(e=>{void 0!==g[e]&&(y[e]=g[e],delete g[e])}),c.changeMode("draw_point",{container:e.layoutRefs.viewportRef.current,addVertexButtonId:`${t.id}-draw-add-point`,interfaceType:e.interfaceType,crossHair:i.crossHair,getSnapEnabled:()=>c.isSnapEnabled(),featureId:a,...g,properties:{...d,...y}}),u({type:"SET_MODE",payload:"draw_point"})},editFeature:({appState:e,appConfig:t,mapState:n,pluginConfig:r,pluginState:i,mapProvider:o,services:s},a,l={})=>{const{dispatch:u}=i,{draw:c}=o,{eventBus:h}=s;if(!c)return!1;const p=c.get(a);if(!p)return!1;c._geometryValidator=l.onGeometryChange??r.onGeometryChange;const d="Point"===p.geometry.type?"edit_point":"edit_vertex";h.emit("draw:editstart",{mode:{LineString:"edit_line",Polygon:"edit_polygon",Point:"edit_point"}[p.geometry.type]});const f=void 0===l.snapLayers?r.snapLayers??null:l.snapLayers;c.setSnapLayers(f),u({type:"SET_HAS_SNAP_LAYERS",payload:f?.length>0}),c.changeMode(d,{container:e.layoutRefs.viewportRef.current,deleteVertexButtonId:`${t.id}-draw-delete-point`,undoButtonId:`${t.id}-draw-undo`,isPanEnabled:"keyboard"!==e.interfaceType,interfaceType:e.interfaceType,scale:J[n.mapSize],featureId:a,getSnapEnabled:()=>c.isSnapEnabled()});const g=c.get(a);u({type:"SET_FEATURE",payload:{feature:g,tempFeature:g}}),u({type:"SET_MODE",payload:d});const{valid:y}=$(g,{phase:"edit-start",mode:d},{onGeometryChange:c._geometryValidator});return u({type:"SET_GEOMETRY_VALID",payload:y}),c.setInvalid?.(!y),!0},addFeature:({mapProvider:e,services:t},n)=>{const{draw:r}=e,{eventBus:i}=t;if(!r)return;const{stroke:o,fill:s,strokeWidth:a,properties:l,...u}=n,c={type:"Feature",...u,properties:{...l,...Te({stroke:o,fill:s,strokeWidth:a})}};(e=>Ie.has(e.geometry?.type)&&void 0!==e.geometry?.coordinates)(c)?(r.add(c),i.emit("draw:add",ue(c))):me.warn("addFeature: ignoring invalid GeoJSON feature",c)},setStyle:({mapProvider:e,services:t},n,r={})=>{const{draw:i}=e,{eventBus:o}=t;if(!i)return!1;if(!i.get(n))return me.warn("setStyle: no feature found for id",n),!1;const s={},a={};for(const[e,t]of Object.entries(r))(Me.has(e)?s:a)[e]=t;const l=(e=>{const t={};for(const[n,r]of Object.entries(e))void 0!==r&&(t[n]=r);return t})({...Te(s),...a});return i.setStyle(n,l),o.emit("draw:stylechange",{featureId:n,properties:l}),!0},deleteFeature:({mapProvider:e,services:t},n)=>{const{draw:r}=e,{eventBus:i}=t;r&&(r.delete(n),i.emit("draw:delete",{featureId:n}))},split:({appState:e,appConfig:t,pluginState:n,mapState:r,mapProvider:i,services:o},a,l={})=>{const{dispatch:u}=n,{draw:c}=i,{eventBus:h}=o;if(!c)return;const p=c.get(a),d=c._geometryValidator;c._geometryValidator=Ln({draw:c,dispatch:u,polygonFeature:p});const f=["stroke-inactive.cold",...l.snapLayers||[]];c.setSnapLayers(f),u({type:"SET_HAS_SNAP_LAYERS",payload:!0}),c.changeMode("draw_line",{container:e.layoutRefs.viewportRef.current,addVertexButtonId:`${t.id}-draw-add-point`,interfaceType:e.interfaceType,crossHair:r?.crossHair,getSnapEnabled:()=>c.isSnapEnabled(),featureId:An,properties:{splitter:"invalid"}});const g=()=>{c._geometryValidator=d,c.off(s.CREATE,y),c.off(s.CANCEL,m)},y=e=>{g(),c.delete(An);const t=bn(p,e);u({type:"SET_ACTION",payload:{name:"split",isValid:!!t}}),t&&h.emit("draw:split",{originalFeatureId:a,featureCollection:t})},m=()=>{g()};c.on(s.CREATE,y),c.on(s.CANCEL,m),u({type:"SET_MODE",payload:"draw_line"}),u({type:"SET_ACTION",payload:{name:"split"}})},merge:({mapProvider:e,services:t},n)=>{const{draw:r}=e,{eventBus:i}=t;if(!r)return null;const o=(e=>{let t;try{t=wn(d(e))}catch{return null}if("Polygon"!==t?.geometry?.type)return null;const n=e[0].id??e[0].properties?.id??"poly";return h(t.geometry.coordinates,{...e[0].properties,id:n},{id:n})})(n.map(e=>r.get(e)));return o&&i.emit("draw:merge",{originalFeatureIds:n,feature:o}),o}}};var Vn=Object.freeze({__proto__:null,manifest:Gn});export{s as A,re as C,j as H,se as K,Y as L,I as M,ie as S,oe as T,K as a,Tn as b,S as c,_n as d,E as e,m as f,h as g,p as h,v as i,P as j,d as k,y as l,f as m,u as n,w as o,c as p,b as q,g as r,Ee as s,me as t,J as u,W as v,X as w,Z as x,$ as y,Vn as z};
1
+ import{useRef as e,useEffect as t,useLayoutEffect as n}from"preact/compat";import"preact/jsx-runtime";const r=new Set(["draw_polygon","draw_line"]),i={SET_MODE:(e,t)=>({...e,mode:t,numVertices:r.has(t)?0:e.numVertices,geometryValid:!1,canAddPoint:!0}),SET_ACTION:(e,t)=>({...e,action:t.name,actionValid:t.isValid}),SET_FEATURE:(e,t)=>({...e,feature:void 0===t.feature?e.feature:t.feature,tempFeature:void 0===t.tempFeature?e.tempFeature:t.tempFeature}),SET_SELECTED_VERTEX_INDEX:(e,t)=>({...e,selectedVertexIndex:t.index,numVertices:t.numVertices}),TOGGLE_SNAP:e=>({...e,snap:!e.snap}),SET_HAS_SNAP_LAYERS:(e,t)=>({...e,hasSnapLayers:!!t}),SET_UNDO_STACK_LENGTH:(e,t)=>({...e,undoStackLength:t}),SET_GEOMETRY_VALID:(e,t)=>({...e,geometryValid:!!t}),SET_CAN_ADD_POINT:(e,t)=>({...e,canAddPoint:!!t})},o={APP_ADD_MARKER:"app:addmarker",APP_UPDATE_MARKER:"app:updatemarker",APP_REMOVE_MARKER:"app:removemarker",APP_ADD_BUTTON:"app:addbutton",APP_TOGGLE_BUTTON_STATE:"app:togglebuttonstate",APP_ADD_PANEL:"app:addpanel",APP_REMOVE_PANEL:"app:removepanel",APP_SHOW_PANEL:"app:showpanel",APP_HIDE_PANEL:"app:hidepanel",APP_ADD_CONTROL:"app:addcontrol",APP_SET_APPLICATION_MODE:"app:setapplicationmode",APP_CLEAR_APPLICATION_MODE:"app:clearapplicationmode",APP_SHOW_HINT:"app:showhint",APP_DISMISS_HINT:"app:dismisshint",APP_READY:"app:ready",APP_OPENED:"app:opened",APP_CLOSED:"app:closed",APP_FULLSCREEN_CHANGE:"app:fullscreenchange",APP_PANEL_OPENED:"app:panelopened",APP_PANEL_CLOSED:"app:panelclosed",MAP_SET_STYLE:"map:setstyle",MAP_SET_SIZE:"map:setsize",MAP_SET_SPATIAL_LIST:"map:setspatiallist",MAP_SET_SPATIAL_LIST_SUPPRESSED:"map:setspatiallistsuppressed",MAP_SET_ACTIVE_ITEM:"map:setactiveitem",MAP_SELECT_ITEM:"map:selectitem",MAP_SET_PIXEL_RATIO:"map:setpixelratio",MAP_FIT_TO_BOUNDS:"map:fittobounds",MAP_SET_VIEW:"map:setview",MAP_INIT_MAP_STYLES:"map:initmapstyles",MAP_STYLE_CHANGE:"map:stylechange",MAP_LOADED:"map:loaded",MAP_READY:"map:ready",MAP_SIZE_CHANGE:"map:sizechange",MAP_FIRST_IDLE:"map:firstidle",MAP_MOVE_START:"map:movestart",MAP_MOVE:"map:move",MAP_MOVE_END:"map:moveend",MAP_STATE_UPDATED:"map:stateupdated",MAP_DATA_CHANGE:"map:datachange",MAP_RENDER:"map:render",MAP_CLICK:"map:click",MAP_DESTROY:"map:destroy"},s={CREATE:"create",EDIT_FINISH:"editfinish",CANCEL:"cancel",VERTEX_SELECTION:"vertexselection",VERTEX_CHANGE:"vertexchange",UNDO_CHANGE:"undochange",UPDATE:"update",GEOMETRY_CHANGE:"geometrychange",INTERFACE_TYPE_CHANGE:"interfacetypechange",PLACEMENT_BLOCKED:"placementblocked",VALIDITY_CHANGE:"validitychange",CAN_PLACE_CHANGE:"canplacechange"};var a=6371008.8,l={centimeters:637100880,centimetres:637100880,degrees:360/(2*Math.PI),feet:20902260.511392,inches:39.37*a,kilometers:6371.0088,kilometres:6371.0088,meters:a,metres:a,miles:3958.761333810546,millimeters:6371008800,millimetres:6371008800,nauticalmiles:a/1852,radians:1,yards:6967335.223679999};function u(e,t,n={}){const r={type:"Feature"};return(0===n.id||n.id)&&(r.id=n.id),n.bbox&&(r.bbox=n.bbox),r.properties=t||{},r.geometry=e,r}function c(e,t,n={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!v(e[0])||!v(e[1]))throw new Error("coordinates must contain numbers");return u({type:"Point",coordinates:e},t,n)}function p(e,t,n={}){for(const t of e){if(t.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(t[t.length-1].length!==t[0].length)throw new Error("First and last Position are not equivalent.");for(let e=0;e<t[t.length-1].length;e++)if(t[t.length-1][e]!==t[0][e])throw new Error("First and last Position are not equivalent.")}return u({type:"Polygon",coordinates:e},t,n)}function h(e,t,n={}){if(e.length<2)throw new Error("coordinates must be an array of two or more positions");return u({type:"LineString",coordinates:e},t,n)}function d(e,t={}){const n={type:"FeatureCollection"};return t.id&&(n.id=t.id),t.bbox&&(n.bbox=t.bbox),n.features=e,n}function f(e,t,n={}){return u({type:"MultiLineString",coordinates:e},t,n)}function g(e,t="kilometers"){const n=l[t];if(!n)throw new Error(t+" units is invalid");return e*n}function y(e,t="kilometers"){const n=l[t];if(!n)throw new Error(t+" units is invalid");return e/n}function m(e){return 180*(e%(2*Math.PI))/Math.PI}function E(e){return e%360*Math.PI/180}function v(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}function S(e,t,n){if(null!==e)for(var r,i,o,s,a,l,u,c,p=0,h=0,d=e.type,f="FeatureCollection"===d,g="Feature"===d,y=f?e.features.length:1,m=0;m<y;m++){a=(c=!!(u=f?e.features[m].geometry:g?e.geometry:e)&&"GeometryCollection"===u.type)?u.geometries.length:1;for(var E=0;E<a;E++){var v=0,w=0;if(null!==(s=c?u.geometries[E]:u)){l=s.coordinates;var b=s.type;switch(p=0,b){case null:break;case"Point":if(!1===t(l,h,m,v,w))return!1;h++,v++;break;case"LineString":case"MultiPoint":for(r=0;r<l.length;r++){if(!1===t(l[r],h,m,v,w))return!1;h++,"MultiPoint"===b&&v++}"LineString"===b&&v++;break;case"Polygon":case"MultiLineString":for(r=0;r<l.length;r++){for(i=0;i<l[r].length-p;i++){if(!1===t(l[r][i],h,m,v,w))return!1;h++}"MultiLineString"===b&&v++,"Polygon"===b&&w++}"Polygon"===b&&v++;break;case"MultiPolygon":for(r=0;r<l.length;r++){for(w=0,i=0;i<l[r].length;i++){for(o=0;o<l[r][i].length-p;o++){if(!1===t(l[r][i][o],h,m,v,w))return!1;h++}w++}v++}break;case"GeometryCollection":for(r=0;r<s.geometries.length;r++)if(!1===S(s.geometries[r],t))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function w(e,t){if("Feature"===e.type)t(e,0);else if("FeatureCollection"===e.type)for(var n=0;n<e.features.length&&!1!==t(e.features[n],n);n++);}function b(e){var t=[];return S(e,function(e){t.push(e)}),t}function x(e,t){var n,r,i,o,s,a,l,u,c,p,h=0,d="FeatureCollection"===e.type,f="Feature"===e.type,g=d?e.features.length:1;for(n=0;n<g;n++){for(a=d?e.features[n].geometry:f?e.geometry:e,u=d?e.features[n].properties:f?e.properties:{},c=d?e.features[n].bbox:f?e.bbox:void 0,p=d?e.features[n].id:f?e.id:void 0,s=(l=!!a&&"GeometryCollection"===a.type)?a.geometries.length:1,i=0;i<s;i++)if(null!==(o=l?a.geometries[i]:a))switch(o.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(!1===t(o,h,u,c,p))return!1;break;case"GeometryCollection":for(r=0;r<o.geometries.length;r++)if(!1===t(o.geometries[r],h,u,c,p))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===t(null,h,u,c,p))return!1;h++}}function P(e,t){x(e,function(e,n,r,i,o){var s,a=null===e?null:e.type;switch(a){case null:case"Point":case"LineString":case"Polygon":return!1!==t(u(e,r,{bbox:i,id:o}),n,0)&&void 0}switch(a){case"MultiPoint":s="Point";break;case"MultiLineString":s="LineString";break;case"MultiPolygon":s="Polygon"}for(var l=0;l<e.coordinates.length;l++){var c=e.coordinates[l];if(!1===t(u({type:s,coordinates:c},r),n,l))return!1}})}function _(e){let t=0;if(e&&e.length>0){t+=Math.abs(C(e[0]));for(let n=1;n<e.length;n++)t-=Math.abs(C(e[n]))}return t}var T=20294876564838.72,A=Math.PI/180;function C(e){const t=e.length-1;if(t<=2)return 0;let n=0,r=0;for(;r<t;){const i=e[r],o=e[r+1===t?0:r+1],s=e[r+2>=t?(r+2)%t:r+2],a=i[0]*A,l=o[1]*A;n+=(s[0]*A-a)*Math.sin(l),r++}return n*T}var L=function(e){return function(e,t,n){var r=n;return x(e,function(e,n,i,o,s){r=t(r,e,n,i,o,s)}),r}(e,(e,t)=>e+function(e){let t,n=0;switch(e.type){case"Polygon":return _(e.coordinates);case"MultiPolygon":for(t=0;t<e.coordinates.length;t++)n+=_(e.coordinates[t]);return n;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}(t),0)};const I={Polygon:3,LineString:2},M=e=>e?.geometry??e,R=e=>{const t=M(e);return"Polygon"===t?.type?t:null},N=e=>{const t=e.coordinates?.[0]??[],n=t.filter((e,n)=>0===n||e[0]!==t[n-1][0]||e[1]!==t[n-1][1]);for(;n.length>1&&n[0][0]===n[n.length-1][0]&&n[0][1]===n[n.length-1][1];)n.pop();return n},k=e=>[...e,e[0]],O=(e,t,n)=>(t[0]-e[0])*(n[1]-e[1])-(t[1]-e[1])*(n[0]-e[0]),D=(e,t)=>e>0&&t<0||e<0&&t>0,G=(e,t,n,r)=>0===e&&((e,t,n)=>Math.min(e[0],n[0])<=t[0]&&t[0]<=Math.max(e[0],n[0])&&Math.min(e[1],n[1])<=t[1]&&t[1]<=Math.max(e[1],n[1]))(t,n,r),V=(e,t,n,r)=>{const i=O(n,r,e),o=O(n,r,t),s=O(e,t,n),a=O(e,t,r);return!(!D(i,o)||!D(s,a))||(G(i,n,e,r)||G(o,n,t,r)||G(s,e,n,t)||G(a,e,r,t))},B=(e,t)=>{const n=e.length,r=t?n:n-1;for(let i=0;i<r;i++)for(let o=i+1;o<r;o++){if(!(o===i+1||t&&0===i&&o===r-1)&&V(e[i],e[(i+1)%n],e[o],e[(o+1)%n]))return!0}return!1},F=e=>{const t=R(e);if(!t)return{valid:!0};const n=N(t);return n.length<4?{valid:!0}:B(n,!0)?{valid:!1,reason:"Shape must not intersect itself"}:{valid:!0}},U=e=>{const t=R(e);if(!t)return{valid:!0};const n=N(t);if(n.length<I.Polygon)return{valid:!0};let r=0;try{r=L({type:"Feature",geometry:{type:"Polygon",coordinates:[k(n)]},properties:{}})}catch{return{valid:!0}}return r>0?{valid:!0}:{valid:!1,reason:"Shape must enclose an area"}},H={Polygon:"Shape needs at least 3 points",LineString:"Line needs at least 2 points"},q=[F,U,e=>{const t=M(e);return"Polygon"===t?.type?N(t).length>=I.Polygon?{valid:!0}:{valid:!1,reason:H.Polygon}:"LineString"===t?.type?(t.coordinates?.length??0)>=I.LineString?{valid:!0}:{valid:!1,reason:H.LineString}:{valid:!0}}],Y=[F,U],j=[e=>(e=>{const t=R(e);if(!t)return!1;const n=N(t);return!(n.length<4)&&B(n,!1)})(e)?{valid:!1,reason:"Shape must not intersect itself"}:{valid:!0}],z=e=>void 0===e||!0===e?{valid:!0}:!1===e?{valid:!1,reason:null}:{valid:!1!==e.valid,reason:e.reason},$=(e,t={},n={})=>{const{rules:r=q,onGeometryChange:i}=n;for(const n of r){const r=z(n(e,t));if(!r.valid)return r}return"function"==typeof i?z(i({feature:e,...t})):{valid:!0}},W=(e,t={},n={})=>{const{rules:r=j,onGeometryChange:i}=n;return $(e,{...t,phase:"place"},{rules:r,onGeometryChange:i})},X={Polygon:"draw_polygon",LineString:"draw_line"},K=({placed:e,point:t,geometryType:n,onGeometryChange:r})=>{const i=[...e,t],o={type:"Feature",geometry:"Polygon"===n?{type:"Polygon",coordinates:[i]}:{type:"LineString",coordinates:i},properties:{}},s=X[n],{valid:a,reason:l}=W(o,{mode:s,vertexIndex:e.length},{onGeometryChange:r});return a?{valid:!0}:{valid:!1,blocked:{feature:o,reason:l??null,phase:"place",mode:s,vertexIndex:e.length}}},Z=(e,t={},n={})=>{const{rules:r=Y,onGeometryChange:i}=n,o=I[e?.geometry?.type??e?.type]??0,s=(t.numVertices??0)<o?[]:r;return $(e,{...t,phase:t.phase??"preview"},{rules:s,onGeometryChange:i})},J={small:1,medium:1.5,large:2},Q="rgba(29,112,184,1)",ee="#ffffff",te="rgba(11,12,12,1)",ne="rgba(212,53,28,0.5)",re={editStroke:{light:Q,dark:ee},editFill:{light:"rgba(29,112,184,0.1)",dark:"rgba(255,255,255,0.1)"},editVertex:{light:Q,dark:ee},editMidpoint:{light:Q,dark:ee},editHalo:{light:ee,dark:te},editActive:{light:te,dark:ee},splitInvalid:{light:Q,dark:ee},splitValid:{light:Q,dark:ee},invalidStroke:{light:Q,dark:ee},shapeStroke:"rgba(212,53,28,1)",shapeFill:ne,snapVertex:ne,snapMidpoint:"rgba(40,161,151,1)",snapEdge:"rgba(29,112,184,0.5)"},ie={strokeWidth:2,vertexRadius:6,midpointRadius:4,vertexHaloRadius:8,midpointHaloRadius:6,touchTargetSize:48},oe={snapRadius:12},se={nudgeAmount:1,stepAmount:5},ae="draw",le=new Set(["symbol","symbolSvgContent","symbolViewBox","symbolAnchor","symbolSize","symbolBackgroundColor","symbolForegroundColor","symbolHaloWidth","symbolGraphic"]),ue=e=>{if(!e?.properties)return e;const t={};for(const[n,r]of Object.entries(e.properties)){"sortKey"===n||n.startsWith("symbol")&&!le.has(n)||(t[n]=r)}return{...e,properties:t}},ce="edit_vertex",pe=new Set([ce,"edit_point"]),he=(e,t)=>n=>{var r;e.emit("draw:geometryinvalid",n),n.reason&&(r=n.reason,!Object.values(H).includes(r))&&t.show(n.reason)},de=({draw:e,pluginState:t,mapProvider:n,eventBus:r})=>({onVertexSelection:i=>{t.dispatch({type:"SET_SELECTED_VERTEX_INDEX",payload:i}),n.activeMoveTarget=i.index>=0?(e=>({move:(t,n,r)=>e.nudgeSelectedVertex(t,n,r),label:"vertex"}))(e):null,r.emit("draw:vertexselection",i)},onVertexChange:e=>{t.dispatch({type:"SET_SELECTED_VERTEX_INDEX",payload:{index:-1,numVertices:e.numVertices}}),n.activeMoveTarget=null}});function fe({appState:e,appConfig:t,mapState:n,pluginState:r,mapProvider:i,eventBus:o,hints:s,resetState:a}){const{draw:l}=i,u=he(o,s),{feature:c,tempFeature:p}=r,{dispatch:h}=r;let d=null;return{handleDone:()=>{l.done()},handleCancel:()=>{const e=l.getMode();pe.has(e)&&p?.id&&l.add(c),d=null,l.cancel(),a(),o.emit("draw:cancelled",ue(c))},handleUndo:()=>l.undo(),handleDeleteVertex:()=>l.deleteVertex(),handleSnap:()=>{r.dispatch({type:"TOGGLE_SNAP"}),l.setSnapEnabled(!r.snap)},onCreate:r=>{const{valid:i,reason:s}=$(r,{phase:"create",mode:l.getMode()},{onGeometryChange:l._geometryValidator});if(!i)return d=r.id,u({feature:ue(r),reason:s,phase:"create",mode:ce}),void setTimeout(()=>(({draw:e,appState:t,appConfig:n,mapState:r,dispatch:i},o)=>{e.changeMode(ce,{container:t?.layoutRefs?.viewportRef?.current,deleteVertexButtonId:`${n?.id}-draw-delete-point`,undoButtonId:`${n?.id}-draw-undo`,isPanEnabled:"keyboard"!==t?.interfaceType,interfaceType:t?.interfaceType,scale:J[r?.mapSize],featureId:o,getSnapEnabled:()=>e.isSnapEnabled()});const s=e.get(o);i({type:"SET_FEATURE",payload:{feature:s,tempFeature:s}}),i({type:"SET_MODE",payload:ce}),i({type:"SET_GEOMETRY_VALID",payload:!1}),e.setGeometryValid?.(!1),e.setInvalid?.(!0)})({draw:l,appState:e,appConfig:t,mapState:n,dispatch:h},r.id),0);a(),setTimeout(()=>l.changeMode("disabled"),0),o.emit("draw:created",ue(r))},onEditFinish:e=>{a(),setTimeout(()=>l.changeMode("disabled"),0),d&&e.id===d?(d=null,o.emit("draw:created",ue(e))):o.emit("draw:edited",ue(e))},onCancel:()=>{},...de({draw:l,pluginState:r,mapProvider:i,eventBus:o}),onUndoChange:e=>{r.dispatch({type:"SET_UNDO_STACK_LENGTH",payload:e})},onUpdate:e=>{o.emit("draw:updated",ue(e))},onGeometryChange:e=>{if(!e?.phase)return;const t=l.getMode(),n={phase:e.phase,vertexIndex:e.vertexIndex,mode:t},{valid:i,reason:o}=$(e.feature,n,{onGeometryChange:l._geometryValidator});r.dispatch({type:"SET_GEOMETRY_VALID",payload:i}),l.setGeometryValid?.(i),pe.has(t)&&l.setInvalid?.(!i),i||u({reason:o,...n,feature:ue(e.feature)})},onPlacementBlocked:e=>{u({...e,feature:ue(e.feature)})},onValidityChange:e=>{r.dispatch({type:"SET_GEOMETRY_VALID",payload:e.valid}),l.setGeometryValid?.(e.valid)},onCanPlaceChange:e=>{r.dispatch({type:"SET_CAN_ADD_POINT",payload:e.canPlace})},onInterfaceTypeChange:e=>{o.emit("draw:interfacetypechange",{interfaceType:e.interfaceType})}}}function ge({appState:e,appConfig:t,mapState:n,pluginState:r,mapProvider:i,buttonConfig:o,eventBus:a,hints:l}){const{draw:u}=i,c=fe({appState:e,appConfig:t,mapState:n,pluginState:r,mapProvider:i,eventBus:a,hints:l,resetState:()=>{r.dispatch({type:"SET_MODE",payload:null}),r.dispatch({type:"SET_FEATURE",payload:{feature:null,tempFeature:null}}),i.activeMoveTarget=null}});return function(e,t){const{drawDone:n,drawCancel:r,drawUndo:i,drawDeletePoint:o,drawSnap:s}=e;n.onClick=t.handleDone,r.onClick=t.handleCancel,i.onClick=t.handleUndo,o&&(o.onClick=t.handleDeleteVertex),s&&(s.onClick=t.handleSnap)}(o,c),function(e,t){e.on(s.CREATE,t.onCreate),e.on(s.EDIT_FINISH,t.onEditFinish),e.on(s.CANCEL,t.onCancel),e.on(s.VERTEX_SELECTION,t.onVertexSelection),e.on(s.VERTEX_CHANGE,t.onVertexChange),e.on(s.UNDO_CHANGE,t.onUndoChange),e.on(s.UPDATE,t.onUpdate),e.on(s.GEOMETRY_CHANGE,t.onGeometryChange),e.on(s.PLACEMENT_BLOCKED,t.onPlacementBlocked),e.on(s.VALIDITY_CHANGE,t.onValidityChange),e.on(s.CAN_PLACE_CHANGE,t.onCanPlaceChange),e.on(s.INTERFACE_TYPE_CHANGE,t.onInterfaceTypeChange)}(u,c),()=>{!function(e){const{drawDone:t,drawCancel:n,drawUndo:r,drawDeletePoint:i,drawSnap:o}=e;t.onClick=null,n.onClick=null,r.onClick=null,i&&(i.onClick=null),o&&(o.onClick=null)}(o),function(e,t){e.off(s.CREATE,t.onCreate),e.off(s.EDIT_FINISH,t.onEditFinish),e.off(s.CANCEL,t.onCancel),e.off(s.VERTEX_SELECTION,t.onVertexSelection),e.off(s.VERTEX_CHANGE,t.onVertexChange),e.off(s.UNDO_CHANGE,t.onUndoChange),e.off(s.UPDATE,t.onUpdate),e.off(s.GEOMETRY_CHANGE,t.onGeometryChange),e.off(s.PLACEMENT_BLOCKED,t.onPlacementBlocked),e.off(s.VALIDITY_CHANGE,t.onValidityChange),e.off(s.CAN_PLACE_CHANGE,t.onCanPlaceChange),e.off(s.INTERFACE_TYPE_CHANGE,t.onInterfaceTypeChange)}(u,c)}}const ye="[interactive-map]",me={warn:(...e)=>console.warn(ye,...e),error:(...e)=>console.error(ye,...e)},Ee=e=>!(!e?.symbol&&!e?.symbolSvgContent),ve="edit_vertex",Se="draw",we=(e,t,n)=>{const{x:r,y:i}=e.mapToScreen(n);return{x:r*J[t],y:i*J[t]}},be=(e,t)=>{const{vertices:n,midpoints:r}=e.draw?.getVertexItems?.()??{vertices:[],midpoints:[]},i=[];return n.forEach((o,s)=>{i.push(((n,r)=>({id:String(r),label:`Point ${r+1}`,isMidpoint:!1,...we(e,t,n)}))(o,s)),s<r.length&&i.push(((r,i)=>({id:String(n.length+i),label:`Insert ${i+1}-${(i+1)%n.length+1}`,isMidpoint:!0,...we(e,t,r)}))(r[s],s))}),i};function xe({mapState:n,pluginState:r,services:i,mapProvider:a,spatialListRegistry:l,viewportRef:u}){const{mapSize:c}=n,{eventBus:p,announce:h}=i,d=e([]),f=e(null);!function({pluginState:e,mapProvider:n,mapSize:r,spatialListRegistry:i,itemsRef:a,eventBus:l}){t(()=>{const t=()=>{a.current=e.mode===ve?be(n,r):[],i.notifyItemsChanged(Se)};t(),l.on(o.MAP_MOVE_END,t);const{draw:u}=n;return u?(u.on(s.UPDATE,t),()=>{l.off(o.MAP_MOVE_END,t),u.off(s.UPDATE,t)}):()=>l.off(o.MAP_MOVE_END,t)},[e.mode,n,r,i,a,l]),t(()=>(i.registerItemProvider(Se,{getItems:()=>({items:a.current,multiselectable:!1,label:"Shape points",focusable:!1}),exclusive:!0}),()=>{i.unregisterItemProvider(Se)}),[i,a]),t(()=>{if(e.mode===ve)return i.claimExclusive(Se),()=>i.releaseExclusive(Se)},[e.mode,i])}({pluginState:r,mapProvider:a,mapSize:c,spatialListRegistry:l,itemsRef:d,eventBus:p}),function({eventBus:e,mapProvider:n,pluginState:r,activeIdRef:i}){t(()=>{const t=({id:e})=>{i.current=e,null!==e&&r.mode===ve&&n.draw?.selectVertex?.(Number(e))};return e.on(o.MAP_SET_ACTIVE_ITEM,t),()=>{e.off(o.MAP_SET_ACTIVE_ITEM,t)}},[e,n,r.mode,i])}({eventBus:p,mapProvider:a,pluginState:r,activeIdRef:f}),function({eventBus:e,mapProvider:n,pluginState:r,activeIdRef:i,itemsRef:s,viewportRef:a,announce:l}){t(()=>{const t=()=>{if(r.mode!==ve||null===i.current)return;const e=s.current.find(e=>e.id===i.current);e&&(e.isMidpoint?(n.draw?.insertVertexAtMidpoint?.(Number(i.current)),l("New point inserted","action")):l(`${e.label} selected`,"action"),a.current?.focus())};return e.on(o.MAP_SELECT_ITEM,t),()=>{e.off(o.MAP_SELECT_ITEM,t)}},[e,n,r.mode,i,s,a,l])}({eventBus:p,mapProvider:a,pluginState:r,activeIdRef:f,itemsRef:d,viewportRef:u,announce:h})}const Pe=new Set(["draw_polygon","draw_line","draw_point"]),_e=e=>Pe.has(e),Te=({appState:e,pluginState:t})=>_e(t.mode)&&("touch"===e.interfaceType||!!e.expandedButtons?.has("mapControls"));function Ae({mapState:n,pluginConfig:r,pluginState:i,mapProvider:s,eventBus:a,symbolRegistry:l}){const u=e(!0),c=e(!1);t(()=>{if(!n.isMapReady||c.current)return;c.current=!0;(async()=>{if(await new Promise(e=>setTimeout(e,0)),!u.current)return;const e=await(async(e,t)=>{switch(e.name){case"MapLibreProvider":{const{MaplibreDrawAdapter:n}=await import(/* webpackChunkName: "im-draw-ml-adapter" */ "./im-draw-ml-adapter.js");return new n(e,t)}case"OpenLayersProvider":{const{OLDrawAdapter:n}=await import(/* webpackChunkName: "im-draw-ol-adapter" */ "./im-draw-ol-adapter.js");return new n(e,t)}default:throw new Error(`No draw adapter available for map provider "${e.name}"`)}})(s,{mapStyle:n.mapStyle,snapLayers:r.snapLayers,pluginConfig:r,events:o,eventBus:a,symbolRegistry:l});u.current?(s.draw=e,i.dispatch({type:"SET_HAS_SNAP_LAYERS",payload:r.snapLayers?.length>0}),a.emit("draw:ready")):e.remove()})().catch(e=>me.error("[draw] failed to load the draw adapter",e))},[n.isMapReady]),t(()=>()=>{u.current=!1,s.draw?.remove(),s.draw=null,s.activeMoveTarget=null},[])}const Ce=new Set(["stroke","fill","strokeWidth"]),Le=e=>{if(!e)return{};const t={};for(const[n,r]of Object.entries(e))if(Ce.has(n)&&"object"==typeof r&&null!==r){const e=Object.entries(r);e.length>0&&(t[n]=e[0][1]);for(const[r,i]of e)t[`${n}${r.charAt(0).toUpperCase()+r.slice(1)}`]=i}else t[n]=r;return t},Ie=e=>({appState:t,appConfig:n,pluginConfig:r,pluginState:i,mapState:o,mapProvider:s,services:a},l,u={})=>{const{dispatch:c}=i,{draw:p}=s,{eventBus:h}=a;if(!p)return;h.emit("draw:started",{mode:e});const d=void 0===u.snapLayers?r.snapLayers??null:u.snapLayers;p.setSnapLayers(d),c({type:"SET_HAS_SNAP_LAYERS",payload:d?.length>0});const{stroke:f,fill:g,strokeWidth:y,properties:m,onGeometryChange:E,...v}=u;p._geometryValidator=E??r.onGeometryChange;const S={...m,...Le({stroke:f,fill:g,strokeWidth:y})};p.changeMode(e,{container:t.layoutRefs.viewportRef.current,addVertexButtonId:`${n.id}-draw-add-point`,interfaceType:t.interfaceType,crossHair:o.crossHair,getSnapEnabled:()=>p.isSnapEnabled(),featureId:l,...v,properties:S}),c({type:"SET_MODE",payload:e})},Me=Ie("draw_polygon"),Re=Ie("draw_line"),Ne=new Set(["Point","LineString","Polygon"]),ke=new Set(["stroke","fill","strokeWidth"]);function Oe(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return De(e);case"FeatureCollection":return function(e){var t={type:"FeatureCollection"};return Object.keys(e).forEach(function(n){switch(n){case"type":case"features":return;default:t[n]=e[n]}}),t.features=e.features.map(function(e){return De(e)}),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return Ve(e);default:throw new Error("unknown GeoJSON type")}}function De(e){var t={type:"Feature"};return Object.keys(e).forEach(function(n){switch(n){case"type":case"properties":case"geometry":return;default:t[n]=e[n]}}),t.properties=Ge(e.properties),t.geometry=Ve(e.geometry),t}function Ge(e){var t={};return e?(Object.keys(e).forEach(function(n){var r=e[n];"object"==typeof r?null===r?t[n]=null:Array.isArray(r)?t[n]=r.map(function(e){return e}):t[n]=Ge(r):t[n]=r}),t):t}function Ve(e){var t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(function(e){return Ve(e)}),t):(t.coordinates=Be(e.coordinates),t)}function Be(e){var t=e;return"object"!=typeof t[0]?t.slice():t.map(function(e){return Be(e)})}function Fe(e){for(var t,n,r=function(e){if(Array.isArray(e))return e;if("Feature"===e.type){if(null!==e.geometry)return e.geometry.coordinates}else if(e.coordinates)return e.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}(e),i=0,o=1;o<r.length;)t=n||r[0],i+=((n=r[o])[0]-t[0])*(n[1]+t[1]),o++;return i>0}function Ue(e){if(Array.isArray(e))return e;if("Feature"===e.type){if(null!==e.geometry)return e.geometry.coordinates}else if(e.coordinates)return e.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function He(e,t){if(null===(n=t=t||{})||"object"!=typeof n||Array.isArray(n))throw new Error("options is invalid");var n,r=t.reverse||!1,i=t.mutate||!1;if(!e)throw new Error("<geojson> is required");if("boolean"!=typeof r)throw new Error("<reverse> must be a boolean");if("boolean"!=typeof i)throw new Error("<mutate> must be a boolean");!1===i&&(e=Oe(e));var o=[];switch(e.type){case"GeometryCollection":return x(e,function(e){qe(e,r)}),e;case"FeatureCollection":return w(e,function(e){w(qe(e,r),function(e){o.push(e)})}),d(o)}return qe(e,r)}function qe(e,t){switch("Feature"===e.type?e.geometry.type:e.type){case"GeometryCollection":return x(e,function(e){qe(e,t)}),e;case"LineString":return Ye(Ue(e),t),e;case"Polygon":return je(Ue(e),t),e;case"MultiLineString":return Ue(e).forEach(function(e){Ye(e,t)}),e;case"MultiPolygon":return Ue(e).forEach(function(e){je(e,t)}),e;case"Point":case"MultiPoint":return e}}function Ye(e,t){Fe(e)===t&&e.reverse()}function je(e,t){Fe(e[0])!==t&&e[0].reverse();for(var n=1;n<e.length;n++)Fe(e[n])===t&&e[n].reverse()}const ze=11102230246251565e-32,$e=134217729,We=(3+8*ze)*ze;function Xe(e,t,n,r,i){let o,s,a,l,u=t[0],c=r[0],p=0,h=0;c>u==c>-u?(o=u,u=t[++p]):(o=c,c=r[++h]);let d=0;if(p<e&&h<n)for(c>u==c>-u?(s=u+o,a=o-(s-u),u=t[++p]):(s=c+o,a=o-(s-c),c=r[++h]),o=s,0!==a&&(i[d++]=a);p<e&&h<n;)c>u==c>-u?(s=o+u,l=s-o,a=o-(s-l)+(u-l),u=t[++p]):(s=o+c,l=s-o,a=o-(s-l)+(c-l),c=r[++h]),o=s,0!==a&&(i[d++]=a);for(;p<e;)s=o+u,l=s-o,a=o-(s-l)+(u-l),u=t[++p],o=s,0!==a&&(i[d++]=a);for(;h<n;)s=o+c,l=s-o,a=o-(s-l)+(c-l),c=r[++h],o=s,0!==a&&(i[d++]=a);return 0===o&&0!==d||(i[d++]=o),d}function Ke(e){return new Float64Array(e)}const Ze=Ke(4),Je=Ke(8),Qe=Ke(12),et=Ke(16),tt=Ke(4);function nt(e,t,n,r,i,o){const s=(t-o)*(n-i),a=(e-i)*(r-o),l=s-a,u=Math.abs(s+a);return Math.abs(l)>=33306690738754716e-32*u?l:-function(e,t,n,r,i,o,s){let a,l,u,c,p,h,d,f,g,y,m,E,v,S,w,b,x,P;const _=e-i,T=n-i,A=t-o,C=r-o;S=_*C,h=$e*_,d=h-(h-_),f=_-d,h=$e*C,g=h-(h-C),y=C-g,w=f*y-(S-d*g-f*g-d*y),b=A*T,h=$e*A,d=h-(h-A),f=A-d,h=$e*T,g=h-(h-T),y=T-g,x=f*y-(b-d*g-f*g-d*y),m=w-x,p=w-m,Ze[0]=w-(m+p)+(p-x),E=S+m,p=E-S,v=S-(E-p)+(m-p),m=v-b,p=v-m,Ze[1]=v-(m+p)+(p-b),P=E+m,p=P-E,Ze[2]=E-(P-p)+(m-p),Ze[3]=P;let L=function(e,t){let n=t[0];for(let r=1;r<e;r++)n+=t[r];return n}(4,Ze),I=22204460492503146e-32*s;if(L>=I||-L>=I)return L;if(p=e-_,a=e-(_+p)+(p-i),p=n-T,u=n-(T+p)+(p-i),p=t-A,l=t-(A+p)+(p-o),p=r-C,c=r-(C+p)+(p-o),0===a&&0===l&&0===u&&0===c)return L;if(I=11093356479670487e-47*s+We*Math.abs(L),L+=_*c+C*a-(A*u+T*l),L>=I||-L>=I)return L;S=a*C,h=$e*a,d=h-(h-a),f=a-d,h=$e*C,g=h-(h-C),y=C-g,w=f*y-(S-d*g-f*g-d*y),b=l*T,h=$e*l,d=h-(h-l),f=l-d,h=$e*T,g=h-(h-T),y=T-g,x=f*y-(b-d*g-f*g-d*y),m=w-x,p=w-m,tt[0]=w-(m+p)+(p-x),E=S+m,p=E-S,v=S-(E-p)+(m-p),m=v-b,p=v-m,tt[1]=v-(m+p)+(p-b),P=E+m,p=P-E,tt[2]=E-(P-p)+(m-p),tt[3]=P;const M=Xe(4,Ze,4,tt,Je);S=_*c,h=$e*_,d=h-(h-_),f=_-d,h=$e*c,g=h-(h-c),y=c-g,w=f*y-(S-d*g-f*g-d*y),b=A*u,h=$e*A,d=h-(h-A),f=A-d,h=$e*u,g=h-(h-u),y=u-g,x=f*y-(b-d*g-f*g-d*y),m=w-x,p=w-m,tt[0]=w-(m+p)+(p-x),E=S+m,p=E-S,v=S-(E-p)+(m-p),m=v-b,p=v-m,tt[1]=v-(m+p)+(p-b),P=E+m,p=P-E,tt[2]=E-(P-p)+(m-p),tt[3]=P;const R=Xe(M,Je,4,tt,Qe);S=a*c,h=$e*a,d=h-(h-a),f=a-d,h=$e*c,g=h-(h-c),y=c-g,w=f*y-(S-d*g-f*g-d*y),b=l*u,h=$e*l,d=h-(h-l),f=l-d,h=$e*u,g=h-(h-u),y=u-g,x=f*y-(b-d*g-f*g-d*y),m=w-x,p=w-m,tt[0]=w-(m+p)+(p-x),E=S+m,p=E-S,v=S-(E-p)+(m-p),m=v-b,p=v-m,tt[1]=v-(m+p)+(p-b),P=E+m,p=P-E,tt[2]=E-(P-p)+(m-p),tt[3]=P;const N=Xe(R,Qe,4,tt,et);return et[N-1]}(e,t,n,r,i,o,u)}function rt(e,t){var n,r,i,o,s,a,l,u,c,p=0,h=e[0],d=e[1],f=t.length;for(n=0;n<f;n++){r=0;var g=t[n],y=g.length-1;if((u=g[0])[0]!==g[y][0]&&u[1]!==g[y][1])throw new Error("First and last coordinates in a ring must be the same");for(o=u[0]-h,s=u[1]-d;r<y;r++){if(a=(c=g[r+1])[0]-h,l=c[1]-d,0===s&&0===l){if(a<=0&&o>=0||o<=0&&a>=0)return 0}else if(l>=0&&s<=0||l<=0&&s>=0){if(0===(i=nt(o,a,s,l,0,0)))return 0;(i>0&&l>0&&s<=0||i<0&&l<=0&&s>0)&&p++}u=c,s=l,o=a}}return p%2!=0}var it=function(e,t,n,r,i){this.p1=e,this.p2=t,this.edgeType=n,this.originalIndex=r,this.polygonContourId=i,this.interiorRing=!1,this.minX=Math.min(e.p[0],t.p[0]),this.minY=Math.min(e.p[1],t.p[1]),this.maxX=Math.max(e.p[0],t.p[0]),this.maxY=Math.max(e.p[1],t.p[1]),this.intersectionPoints=[],this.nextEdge=null},ot=function(e){this.p=e},st=function(e,t){this.id=e,this.rawCoords=t};function at(e,t){return!(e.maxX<t[0])&&(!(e.minX>t[2])&&(!(e.maxY<t[1])&&!(e.minY>t[3])))}var lt=function(e,t,n,r){this.p=e,this.polylineEdge=t,this.polygonEdge=n,this.isHeadingIn=r,this.distanceFromPolylineEdgeStart=ut(this.polylineEdge.p1.p,this.p),this.distanceFromPolygonEdgeStart=ut(this.polygonEdge.p1.p,this.p),this.polygonEdge.intersectionPoints.push(this),this.polylineEdge.intersectionPoints.push(this),this.visitCount=0};function ut(e,t){var n=t[0]-e[0],r=t[1]-e[1];return n*=n,r*=r,Math.sqrt(n+r)}lt.prototype.incrementVisitCount=function(){this.visitCount=this.visitCount+1};var ct=1e-9;function pt(e,t){return e[0]*t[1]-e[1]*t[0]}function ht(e,t){return e[0]*t[0]+e[1]*t[1]}function dt(e,t,n){return[e[0]+t*n[0],e[1]+t*n[1]]}function ft(e,t,n){var r=[e.p2.p[0]-e.p1.p[0],e.p2.p[1]-e.p1.p[1]],i=[t.p2.p[0]-t.p1.p[0],t.p2.p[1]-t.p1.p[1]],o=[t.p1.p[0]-e.p1.p[0],t.p1.p[1]-e.p1.p[1]],s=pt(r,i),a=s*s,l=ht(r,r);if(a>0){var u=pt(o,i)/s;if(u<0||u>1)return null;var c=pt(o,r)/s;return c<0||c>1?null:0===u||1===u?[dt(e.p1.p,u,r)]:0===c||1===c?[dt(t.p1.p,c,i)]:[dt(e.p1.p,u,r)]}var p=ht(o,o);if((a=(s=pt(o,r))*s)>ct*l*p)return null;var h=ht(r,o)/l,d=h+ht(r,i)/l,f=Math.min(h,d),g=Math.max(h,d);return f<=1&&g>=0?1===f?[dt(e.p1.p,f>0?f:0,r)]:0===g?[dt(e.p1.p,g<1?g:1,r)]:[dt(e.p1.p,f>0?f:0,r),dt(e.p1.p,g<1?g:1,r)]:null}function gt(e,t){var n=[],r=[],i=[],o=function(e,t,n,r,i){for(var o=0,s=[],a="Feature"===t.type?t.geometry:t,l="LineString"===a.type?[a.coordinates]:a.coordinates,u=0,c=0;c<l.length;c++){for(var p=l[c].length-1,h=new ot(l[c][0]),d=null,f={nextEdge:null},g=0;g<p;g++){d=new ot(l[c][g+1]),h.nextPoint=d,d.prevPoint=h;var y=new it(h,d,"polyline",u,null);r.push(y),f.nextEdge=y,y.prevEdge=f,i[0]=Math.min(i[0],h.p[0]),i[1]=Math.min(i[1],h.p[1]),i[2]=Math.max(i[2],h.p[0]),i[3]=Math.max(i[3],h.p[1]),h=d,u+=1,f=y}i[0]=Math.min(i[0],l[c][p][0]),i[1]=Math.min(i[1],l[c][p][1]),i[2]=Math.max(i[2],l[c][p][0]),i[3]=Math.max(i[3],l[c][p][1])}for(var m="Feature"===e.type?e.geometry:e,E="Polygon"===m.type?[m.coordinates]:m.coordinates,v=E.length,S=0;S<v;S++)for(var w=E[S].length,b=0;b<w;b++){o+=1;var x=E[S][b],P=x.length;s.push(new st(o,x));for(var _=new ot(x[0]),T=_,A=void 0,C=null,L={nextEdge:null,prevEdge:null},I=null,M=1;M<P;M++)A=new ot(x[M]),T.nextPoint=A,A.prevPoint=T,C=new it(T,A,"polygon",u,o),L.nextEdge=C,C.prevEdge=L,1===M&&(I=C),b>0&&(C.interiorRing=!0),C.intersectPolylineBbox=at(C,i),n.push(C),T=A,u+=1,L=C;C.nextEdge=I,I.prevEdge=C,A.nextPoint=_.nextPoint,_.prevPoint=A.prevPoint}return s}(He(e),t,r,i,[1/0,1/0,1/0,1/0]);if(function(e,t,n){var r,i,o,s=t.length,a=e.length;for(r=0;r<s;r++){var l=t[r];for(i=0;i<a;i++){var u=e[i];if(u.intersectPolylineBbox&&!(u.maxX<l.minX||u.minX>l.maxX||u.maxY<l.minY||u.minY>l.maxY)){var c=ft(l,u);if(null!==c)for(o=0;o<c.length;o++){var p=nt(u.p1.p[0],u.p1.p[1],u.p2.p[0],u.p2.p[1],l.p1.p[0],l.p1.p[1]),h=new lt(c[o],l,u,p>0);n.push(h)}}}}t.forEach(function(e){e.intersectionPoints.sort(function(e,t){return e.distanceFromPolylineEdgeStart-t.distanceFromPolylineEdgeStart})}),e.forEach(function(e){e.intersectionPoints.sort(function(e,t){return e.distanceFromPolygonEdgeStart-t.distanceFromPolygonEdgeStart})})}(r,i,n),0===n.length)return e;var s={};o.forEach(function(e){return s[e.id]=0}),n.forEach(function(e){var t=e.polygonEdge.polygonContourId;s[t]=s[t]+1});for(var a=0,l=[],u=null,c=0;c<i.length;c++){var p=i[c];if(p.intersectionPoints.length>0){u=p.intersectionPoints[0];break}}for(var h=u,d={visitCount:1};u!==d&&!(a>2*n.length);){if(a=a++,d.visitCount>=2){for(var f=!1,g=0;g<n.length;g++){var y=n[g];if(y.visitCount<2){h=y,f=!0;break}}if(!f)break}h.visitCount=h.visitCount+1;var m=[];l.push(m),m.push(h.p),h.visitCount=h.visitCount+1;var E=vt(h,m),v=!1;if(E===(d=E)&&2===n.length)for(var S=0;S<n.length;S++){n[S].visitCount<2&&(v=!0)}for(;E!==h||v;){(E=(E.isHeadingIn?bt:wt)(E,m))!==h&&(E=vt(E,m)),v=!1}if(d.visitCount>=2){for(var w=!1,b=0;b<n.length;b++){var x=n[b];if(x.visitCount<2){h=x,w=!0;break}}w&&(d=h)}h=d}for(var P=l.map(function(e){return[e]}),_=Object.keys(s),T=0;T<_.length;T++){var A=_[T];if(0===s[A])Et(mt(yt(r,parseInt(A)),o),P)}return{type:"Feature",properties:{},geometry:{type:"MultiPolygon",coordinates:P}}}function yt(e,t){for(var n=0;n<e.length;n++){var r=e[n];if(r.polygonContourId===t)return r}}function mt(e,t){return t.find(function(t){return t.id===e.polygonContourId}).rawCoords}function Et(e,t){for(var n=0;n<t.length;n++){var r=t[n];if(rt(e[0],[r[0]]))return void r.push(e)}t.push([e])}function vt(e,t){var n=e.polygonEdge;if(n.intersectionPoints.length>1&&n.intersectionPoints[n.intersectionPoints.length-1]!==e){var r=St(e,n.intersectionPoints),i=n.intersectionPoints[r+1];return t.push(i.p),i.incrementVisitCount(),i}for(var o=!0;o;){if(t.push(n.p2.p),null===(n=n.nextEdge))return e;n.intersectionPoints.length>0&&(o=!1)}return n.intersectionPoints[0].incrementVisitCount(),t.push(n.intersectionPoints[0].p),n.intersectionPoints[0]}function St(e,t){for(var n=0;n<t.length;n++){if(t[n]===e)return n}return null}function wt(e,t){var n=e.polylineEdge;if(2===n.intersectionPoints.length){var r=n.intersectionPoints[n.intersectionPoints.length-1];if(r===e){var i=n.intersectionPoints[0];return t.push(i.p),i.incrementVisitCount(),i}return t.push(r.p),r.incrementVisitCount(),r}if(n.intersectionPoints.length>2&&n.intersectionPoints[0]!==e){var o=St(e,n.intersectionPoints),s=n.intersectionPoints[o-1];return t.push(s.p),s.incrementVisitCount(),s}for(var a=!0;a;){if(t.push(n.p1.p),void 0===(n=n.prevEdge).originalIndex)return e;n.intersectionPoints.length>0&&(a=!1)}if(void 0===n.originalIndex)return e;var l=n.intersectionPoints[n.intersectionPoints.length-1];return l.incrementVisitCount(),t.push(l.p),l}function bt(e,t){var n=e.polylineEdge;if(n.intersectionPoints.length>1&&n.intersectionPoints[n.intersectionPoints.length-1]!==e){var r=St(e,n.intersectionPoints),i=n.intersectionPoints[r+1];return t.push(i.p),i.incrementVisitCount(),i}for(var o=!0;o;){if(t.push(n.p2.p),null===(n=n.nextEdge))return e;n.intersectionPoints.length>0&&(o=!1)}if(void 0===n)return e;var s=n.intersectionPoints[0];return s.incrementVisitCount(),t.push(s.p),s}var xt=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,Pt=Math.ceil,_t=Math.floor,Tt="[BigNumber Error] ",At=Tt+"Number primitive has more than 15 significant digits: ",Ct=1e14,Lt=14,It=9007199254740991,Mt=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],Rt=1e7,Nt=1e9;function kt(e){var t=0|e;return e>0||e===t?t:t-1}function Ot(e){for(var t,n,r=1,i=e.length,o=e[0]+"";r<i;){for(t=e[r++]+"",n=Lt-t.length;n--;t="0"+t);o+=t}for(i=o.length;48===o.charCodeAt(--i););return o.slice(0,i+1||1)}function Dt(e,t){var n,r,i=e.c,o=t.c,s=e.s,a=t.s,l=e.e,u=t.e;if(!s||!a)return null;if(n=i&&!i[0],r=o&&!o[0],n||r)return n?r?0:-a:s;if(s!=a)return s;if(n=s<0,r=l==u,!i||!o)return r?0:!i^n?1:-1;if(!r)return l>u^n?1:-1;for(a=(l=i.length)<(u=o.length)?l:u,s=0;s<a;s++)if(i[s]!=o[s])return i[s]>o[s]^n?1:-1;return l==u?0:l>u^n?1:-1}function Gt(e,t,n,r){if(e<t||e>n||e!==_t(e))throw Error(Tt+(r||"Argument")+("number"==typeof e?e<t||e>n?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function Vt(e){var t=e.c.length-1;return kt(e.e/Lt)==t&&e.c[t]%2!=0}function Bt(e,t){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(t<0?"e":"e+")+t}function Ft(e,t,n){var r,i;if(t<0){for(i=n+".";++t;i+=n);e=i+e}else if(++t>(r=e.length)){for(i=n,t-=r;--t;i+=n);e+=i}else t<r&&(e=e.slice(0,t)+"."+e.slice(t));return e}var Ut=function e(t){var n,r,i,o,s,a,l,u,c,p,h=T.prototype={constructor:T,toString:null,valueOf:null},d=new T(1),f=20,g=4,y=-7,m=21,E=-1e7,v=1e7,S=!1,w=1,b=0,x={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},P="0123456789abcdefghijklmnopqrstuvwxyz",_=!0;function T(e,t){var n,o,s,a,l,u,c,p,h=this;if(!(h instanceof T))return new T(e,t);if(null==t){if(e&&!0===e._isBigNumber)return h.s=e.s,void(!e.c||e.e>v?h.c=h.e=null:e.e<E?h.c=[h.e=0]:(h.e=e.e,h.c=e.c.slice()));if((u="number"==typeof e)&&0*e==0){if(h.s=1/e<0?(e=-e,-1):1,e===~~e){for(a=0,l=e;l>=10;l/=10,a++);return void(a>v?h.c=h.e=null:(h.e=a,h.c=[e]))}p=String(e)}else{if(!xt.test(p=String(e)))return i(h,p,u);h.s=45==p.charCodeAt(0)?(p=p.slice(1),-1):1}(a=p.indexOf("."))>-1&&(p=p.replace(".","")),(l=p.search(/e/i))>0?(a<0&&(a=l),a+=+p.slice(l+1),p=p.substring(0,l)):a<0&&(a=p.length)}else{if(Gt(t,2,P.length,"Base"),10==t&&_)return I(h=new T(e),f+h.e+1,g);if(p=String(e),u="number"==typeof e){if(0*e!=0)return i(h,p,u,t);if(h.s=1/e<0?(p=p.slice(1),-1):1,T.DEBUG&&p.replace(/^0\.0*|\./,"").length>15)throw Error(At+e)}else h.s=45===p.charCodeAt(0)?(p=p.slice(1),-1):1;for(n=P.slice(0,t),a=l=0,c=p.length;l<c;l++)if(n.indexOf(o=p.charAt(l))<0){if("."==o){if(l>a){a=c;continue}}else if(!s&&(p==p.toUpperCase()&&(p=p.toLowerCase())||p==p.toLowerCase()&&(p=p.toUpperCase()))){s=!0,l=-1,a=0;continue}return i(h,String(e),u,t)}u=!1,(a=(p=r(p,t,10,h.s)).indexOf("."))>-1?p=p.replace(".",""):a=p.length}for(l=0;48===p.charCodeAt(l);l++);for(c=p.length;48===p.charCodeAt(--c););if(p=p.slice(l,++c)){if(c-=l,u&&T.DEBUG&&c>15&&(e>It||e!==_t(e)))throw Error(At+h.s*e);if((a=a-l-1)>v)h.c=h.e=null;else if(a<E)h.c=[h.e=0];else{if(h.e=a,h.c=[],l=(a+1)%Lt,a<0&&(l+=Lt),l<c){for(l&&h.c.push(+p.slice(0,l)),c-=Lt;l<c;)h.c.push(+p.slice(l,l+=Lt));l=Lt-(p=p.slice(l)).length}else l-=c;for(;l--;p+="0");h.c.push(+p)}}else h.c=[h.e=0]}function A(e,t,n,r){var i,o,s,a,l;if(null==n?n=g:Gt(n,0,8),!e.c)return e.toString();if(i=e.c[0],s=e.e,null==t)l=Ot(e.c),l=1==r||2==r&&(s<=y||s>=m)?Bt(l,s):Ft(l,s,"0");else if(o=(e=I(new T(e),t,n)).e,a=(l=Ot(e.c)).length,1==r||2==r&&(t<=o||o<=y)){for(;a<t;l+="0",a++);l=Bt(l,o)}else if(t-=s+(2===r&&o>s),l=Ft(l,o,"0"),o+1>a){if(--t>0)for(l+=".";t--;l+="0");}else if((t+=o-a)>0)for(o+1==a&&(l+=".");t--;l+="0");return e.s<0&&i?"-"+l:l}function C(e,t){for(var n,r,i=1,o=new T(e[0]);i<e.length;i++)(!(r=new T(e[i])).s||(n=Dt(o,r))===t||0===n&&o.s===t)&&(o=r);return o}function L(e,t,n){for(var r=1,i=t.length;!t[--i];t.pop());for(i=t[0];i>=10;i/=10,r++);return(n=r+n*Lt-1)>v?e.c=e.e=null:n<E?e.c=[e.e=0]:(e.e=n,e.c=t),e}function I(e,t,n,r){var i,o,s,a,l,u,c,p=e.c,h=Mt;if(p){e:{for(i=1,a=p[0];a>=10;a/=10,i++);if((o=t-i)<0)o+=Lt,s=t,l=p[u=0],c=_t(l/h[i-s-1]%10);else if((u=Pt((o+1)/Lt))>=p.length){if(!r)break e;for(;p.length<=u;p.push(0));l=c=0,i=1,s=(o%=Lt)-Lt+1}else{for(l=a=p[u],i=1;a>=10;a/=10,i++);c=(s=(o%=Lt)-Lt+i)<0?0:_t(l/h[i-s-1]%10)}if(r=r||t<0||null!=p[u+1]||(s<0?l:l%h[i-s-1]),r=n<4?(c||r)&&(0==n||n==(e.s<0?3:2)):c>5||5==c&&(4==n||r||6==n&&(o>0?s>0?l/h[i-s]:0:p[u-1])%10&1||n==(e.s<0?8:7)),t<1||!p[0])return p.length=0,r?(t-=e.e+1,p[0]=h[(Lt-t%Lt)%Lt],e.e=-t||0):p[0]=e.e=0,e;if(0==o?(p.length=u,a=1,u--):(p.length=u+1,a=h[Lt-o],p[u]=s>0?_t(l/h[i-s]%h[s])*a:0),r)for(;;){if(0==u){for(o=1,s=p[0];s>=10;s/=10,o++);for(s=p[0]+=a,a=1;s>=10;s/=10,a++);o!=a&&(e.e++,p[0]==Ct&&(p[0]=1));break}if(p[u]+=a,p[u]!=Ct)break;p[u--]=0,a=1}for(o=p.length;0===p[--o];p.pop());}e.e>v?e.c=e.e=null:e.e<E&&(e.c=[e.e=0])}return e}function M(e){var t,n=e.e;return null===n?e.toString():(t=Ot(e.c),t=n<=y||n>=m?Bt(t,n):Ft(t,n,"0"),e.s<0?"-"+t:t)}return T.clone=e,T.ROUND_UP=0,T.ROUND_DOWN=1,T.ROUND_CEIL=2,T.ROUND_FLOOR=3,T.ROUND_HALF_UP=4,T.ROUND_HALF_DOWN=5,T.ROUND_HALF_EVEN=6,T.ROUND_HALF_CEIL=7,T.ROUND_HALF_FLOOR=8,T.EUCLID=9,T.config=T.set=function(e){var t,n;if(null!=e){if("object"!=typeof e)throw Error(Tt+"Object expected: "+e);if(e.hasOwnProperty(t="DECIMAL_PLACES")&&(Gt(n=e[t],0,Nt,t),f=n),e.hasOwnProperty(t="ROUNDING_MODE")&&(Gt(n=e[t],0,8,t),g=n),e.hasOwnProperty(t="EXPONENTIAL_AT")&&((n=e[t])&&n.pop?(Gt(n[0],-Nt,0,t),Gt(n[1],0,Nt,t),y=n[0],m=n[1]):(Gt(n,-Nt,Nt,t),y=-(m=n<0?-n:n))),e.hasOwnProperty(t="RANGE"))if((n=e[t])&&n.pop)Gt(n[0],-Nt,-1,t),Gt(n[1],1,Nt,t),E=n[0],v=n[1];else{if(Gt(n,-Nt,Nt,t),!n)throw Error(Tt+t+" cannot be zero: "+n);E=-(v=n<0?-n:n)}if(e.hasOwnProperty(t="CRYPTO")){if((n=e[t])!==!!n)throw Error(Tt+t+" not true or false: "+n);if(n){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw S=!n,Error(Tt+"crypto unavailable");S=n}else S=n}if(e.hasOwnProperty(t="MODULO_MODE")&&(Gt(n=e[t],0,9,t),w=n),e.hasOwnProperty(t="POW_PRECISION")&&(Gt(n=e[t],0,Nt,t),b=n),e.hasOwnProperty(t="FORMAT")){if("object"!=typeof(n=e[t]))throw Error(Tt+t+" not an object: "+n);x=n}if(e.hasOwnProperty(t="ALPHABET")){if("string"!=typeof(n=e[t])||/^.?$|[+\-.\s]|(.).*\1/.test(n))throw Error(Tt+t+" invalid: "+n);_="0123456789"==n.slice(0,10),P=n}}return{DECIMAL_PLACES:f,ROUNDING_MODE:g,EXPONENTIAL_AT:[y,m],RANGE:[E,v],CRYPTO:S,MODULO_MODE:w,POW_PRECISION:b,FORMAT:x,ALPHABET:P}},T.isBigNumber=function(e){if(!e||!0!==e._isBigNumber)return!1;if(!T.DEBUG)return!0;var t,n,r=e.c,i=e.e,o=e.s;e:if("[object Array]"=={}.toString.call(r)){if((1===o||-1===o)&&i>=-Nt&&i<=Nt&&i===_t(i)){if(0===r[0]){if(0===i&&1===r.length)return!0;break e}if((t=(i+1)%Lt)<1&&(t+=Lt),String(r[0]).length==t){for(t=0;t<r.length;t++)if((n=r[t])<0||n>=Ct||n!==_t(n))break e;if(0!==n)return!0}}}else if(null===r&&null===i&&(null===o||1===o||-1===o))return!0;throw Error(Tt+"Invalid BigNumber: "+e)},T.maximum=T.max=function(){return C(arguments,-1)},T.minimum=T.min=function(){return C(arguments,1)},T.random=(o=9007199254740992,s=Math.random()*o&2097151?function(){return _t(Math.random()*o)}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(e){var t,n,r,i,o,a=0,l=[],u=new T(d);if(null==e?e=f:Gt(e,0,Nt),i=Pt(e/Lt),S)if(crypto.getRandomValues){for(t=crypto.getRandomValues(new Uint32Array(i*=2));a<i;)(o=131072*t[a]+(t[a+1]>>>11))>=9e15?(n=crypto.getRandomValues(new Uint32Array(2)),t[a]=n[0],t[a+1]=n[1]):(l.push(o%1e14),a+=2);a=i/2}else{if(!crypto.randomBytes)throw S=!1,Error(Tt+"crypto unavailable");for(t=crypto.randomBytes(i*=7);a<i;)(o=281474976710656*(31&t[a])+1099511627776*t[a+1]+4294967296*t[a+2]+16777216*t[a+3]+(t[a+4]<<16)+(t[a+5]<<8)+t[a+6])>=9e15?crypto.randomBytes(7).copy(t,a):(l.push(o%1e14),a+=7);a=i/7}if(!S)for(;a<i;)(o=s())<9e15&&(l[a++]=o%1e14);for(i=l[--a],e%=Lt,i&&e&&(o=Mt[Lt-e],l[a]=_t(i/o)*o);0===l[a];l.pop(),a--);if(a<0)l=[r=0];else{for(r=-1;0===l[0];l.splice(0,1),r-=Lt);for(a=1,o=l[0];o>=10;o/=10,a++);a<Lt&&(r-=Lt-a)}return u.e=r,u.c=l,u}),T.sum=function(){for(var e=1,t=arguments,n=new T(t[0]);e<t.length;)n=n.plus(t[e++]);return n},r=function(){var e="0123456789";function t(e,t,n,r){for(var i,o,s=[0],a=0,l=e.length;a<l;){for(o=s.length;o--;s[o]*=t);for(s[0]+=r.indexOf(e.charAt(a++)),i=0;i<s.length;i++)s[i]>n-1&&(null==s[i+1]&&(s[i+1]=0),s[i+1]+=s[i]/n|0,s[i]%=n)}return s.reverse()}return function(r,i,o,s,a){var l,u,c,p,h,d,y,m,E=r.indexOf("."),v=f,S=g;for(E>=0&&(p=b,b=0,r=r.replace(".",""),d=(m=new T(i)).pow(r.length-E),b=p,m.c=t(Ft(Ot(d.c),d.e,"0"),10,o,e),m.e=m.c.length),c=p=(y=t(r,i,o,a?(l=P,e):(l=e,P))).length;0==y[--p];y.pop());if(!y[0])return l.charAt(0);if(E<0?--c:(d.c=y,d.e=c,d.s=s,y=(d=n(d,m,v,S,o)).c,h=d.r,c=d.e),E=y[u=c+v+1],p=o/2,h=h||u<0||null!=y[u+1],h=S<4?(null!=E||h)&&(0==S||S==(d.s<0?3:2)):E>p||E==p&&(4==S||h||6==S&&1&y[u-1]||S==(d.s<0?8:7)),u<1||!y[0])r=h?Ft(l.charAt(1),-v,l.charAt(0)):l.charAt(0);else{if(y.length=u,h)for(--o;++y[--u]>o;)y[u]=0,u||(++c,y=[1].concat(y));for(p=y.length;!y[--p];);for(E=0,r="";E<=p;r+=l.charAt(y[E++]));r=Ft(r,c,l.charAt(0))}return r}}(),n=function(){function e(e,t,n){var r,i,o,s,a=0,l=e.length,u=t%Rt,c=t/Rt|0;for(e=e.slice();l--;)a=((i=u*(o=e[l]%Rt)+(r=c*o+(s=e[l]/Rt|0)*u)%Rt*Rt+a)/n|0)+(r/Rt|0)+c*s,e[l]=i%n;return a&&(e=[a].concat(e)),e}function t(e,t,n,r){var i,o;if(n!=r)o=n>r?1:-1;else for(i=o=0;i<n;i++)if(e[i]!=t[i]){o=e[i]>t[i]?1:-1;break}return o}function n(e,t,n,r){for(var i=0;n--;)e[n]-=i,i=e[n]<t[n]?1:0,e[n]=i*r+e[n]-t[n];for(;!e[0]&&e.length>1;e.splice(0,1));}return function(r,i,o,s,a){var l,u,c,p,h,d,f,g,y,m,E,v,S,w,b,x,P,_=r.s==i.s?1:-1,A=r.c,C=i.c;if(!(A&&A[0]&&C&&C[0]))return new T(r.s&&i.s&&(A?!C||A[0]!=C[0]:C)?A&&0==A[0]||!C?0*_:_/0:NaN);for(y=(g=new T(_)).c=[],_=o+(u=r.e-i.e)+1,a||(a=Ct,u=kt(r.e/Lt)-kt(i.e/Lt),_=_/Lt|0),c=0;C[c]==(A[c]||0);c++);if(C[c]>(A[c]||0)&&u--,_<0)y.push(1),p=!0;else{for(w=A.length,x=C.length,c=0,_+=2,(h=_t(a/(C[0]+1)))>1&&(C=e(C,h,a),A=e(A,h,a),x=C.length,w=A.length),S=x,E=(m=A.slice(0,x)).length;E<x;m[E++]=0);P=C.slice(),P=[0].concat(P),b=C[0],C[1]>=a/2&&b++;do{if(h=0,(l=t(C,m,x,E))<0){if(v=m[0],x!=E&&(v=v*a+(m[1]||0)),(h=_t(v/b))>1)for(h>=a&&(h=a-1),f=(d=e(C,h,a)).length,E=m.length;1==t(d,m,f,E);)h--,n(d,x<f?P:C,f,a),f=d.length,l=1;else 0==h&&(l=h=1),f=(d=C.slice()).length;if(f<E&&(d=[0].concat(d)),n(m,d,E,a),E=m.length,-1==l)for(;t(C,m,x,E)<1;)h++,n(m,x<E?P:C,E,a),E=m.length}else 0===l&&(h++,m=[0]);y[c++]=h,m[0]?m[E++]=A[S]||0:(m=[A[S]],E=1)}while((S++<w||null!=m[0])&&_--);p=null!=m[0],y[0]||y.splice(0,1)}if(a==Ct){for(c=1,_=y[0];_>=10;_/=10,c++);I(g,o+(g.e=c+u*Lt-1)+1,s,p)}else g.e=u,g.r=+p;return g}}(),a=/^(-?)0([xbo])(?=\w[\w.]*$)/i,l=/^([^.]+)\.$/,u=/^\.([^.]+)$/,c=/^-?(Infinity|NaN)$/,p=/^\s*\+(?=[\w.])|^\s+|\s+$/g,i=function(e,t,n,r){var i,o=n?t:t.replace(p,"");if(c.test(o))e.s=isNaN(o)?null:o<0?-1:1;else{if(!n&&(o=o.replace(a,function(e,t,n){return i="x"==(n=n.toLowerCase())?16:"b"==n?2:8,r&&r!=i?e:t}),r&&(i=r,o=o.replace(l,"$1").replace(u,"0.$1")),t!=o))return new T(o,i);if(T.DEBUG)throw Error(Tt+"Not a"+(r?" base "+r:"")+" number: "+t);e.s=null}e.c=e.e=null},h.absoluteValue=h.abs=function(){var e=new T(this);return e.s<0&&(e.s=1),e},h.comparedTo=function(e,t){return Dt(this,new T(e,t))},h.decimalPlaces=h.dp=function(e,t){var n,r,i,o=this;if(null!=e)return Gt(e,0,Nt),null==t?t=g:Gt(t,0,8),I(new T(o),e+o.e+1,t);if(!(n=o.c))return null;if(r=((i=n.length-1)-kt(this.e/Lt))*Lt,i=n[i])for(;i%10==0;i/=10,r--);return r<0&&(r=0),r},h.dividedBy=h.div=function(e,t){return n(this,new T(e,t),f,g)},h.dividedToIntegerBy=h.idiv=function(e,t){return n(this,new T(e,t),0,1)},h.exponentiatedBy=h.pow=function(e,t){var n,r,i,o,s,a,l,u,c=this;if((e=new T(e)).c&&!e.isInteger())throw Error(Tt+"Exponent not an integer: "+M(e));if(null!=t&&(t=new T(t)),s=e.e>14,!c.c||!c.c[0]||1==c.c[0]&&!c.e&&1==c.c.length||!e.c||!e.c[0])return u=new T(Math.pow(+M(c),s?e.s*(2-Vt(e)):+M(e))),t?u.mod(t):u;if(a=e.s<0,t){if(t.c?!t.c[0]:!t.s)return new T(NaN);(r=!a&&c.isInteger()&&t.isInteger())&&(c=c.mod(t))}else{if(e.e>9&&(c.e>0||c.e<-1||(0==c.e?c.c[0]>1||s&&c.c[1]>=24e7:c.c[0]<8e13||s&&c.c[0]<=9999975e7)))return o=c.s<0&&Vt(e)?-0:0,c.e>-1&&(o=1/o),new T(a?1/o:o);b&&(o=Pt(b/Lt+2))}for(s?(n=new T(.5),a&&(e.s=1),l=Vt(e)):l=(i=Math.abs(+M(e)))%2,u=new T(d);;){if(l){if(!(u=u.times(c)).c)break;o?u.c.length>o&&(u.c.length=o):r&&(u=u.mod(t))}if(i){if(0===(i=_t(i/2)))break;l=i%2}else if(I(e=e.times(n),e.e+1,1),e.e>14)l=Vt(e);else{if(0===(i=+M(e)))break;l=i%2}c=c.times(c),o?c.c&&c.c.length>o&&(c.c.length=o):r&&(c=c.mod(t))}return r?u:(a&&(u=d.div(u)),t?u.mod(t):o?I(u,b,g,void 0):u)},h.integerValue=function(e){var t=new T(this);return null==e?e=g:Gt(e,0,8),I(t,t.e+1,e)},h.isEqualTo=h.eq=function(e,t){return 0===Dt(this,new T(e,t))},h.isFinite=function(){return!!this.c},h.isGreaterThan=h.gt=function(e,t){return Dt(this,new T(e,t))>0},h.isGreaterThanOrEqualTo=h.gte=function(e,t){return 1===(t=Dt(this,new T(e,t)))||0===t},h.isInteger=function(){return!!this.c&&kt(this.e/Lt)>this.c.length-2},h.isLessThan=h.lt=function(e,t){return Dt(this,new T(e,t))<0},h.isLessThanOrEqualTo=h.lte=function(e,t){return-1===(t=Dt(this,new T(e,t)))||0===t},h.isNaN=function(){return!this.s},h.isNegative=function(){return this.s<0},h.isPositive=function(){return this.s>0},h.isZero=function(){return!!this.c&&0==this.c[0]},h.minus=function(e,t){var n,r,i,o,s=this,a=s.s;if(t=(e=new T(e,t)).s,!a||!t)return new T(NaN);if(a!=t)return e.s=-t,s.plus(e);var l=s.e/Lt,u=e.e/Lt,c=s.c,p=e.c;if(!l||!u){if(!c||!p)return c?(e.s=-t,e):new T(p?s:NaN);if(!c[0]||!p[0])return p[0]?(e.s=-t,e):new T(c[0]?s:3==g?-0:0)}if(l=kt(l),u=kt(u),c=c.slice(),a=l-u){for((o=a<0)?(a=-a,i=c):(u=l,i=p),i.reverse(),t=a;t--;i.push(0));i.reverse()}else for(r=(o=(a=c.length)<(t=p.length))?a:t,a=t=0;t<r;t++)if(c[t]!=p[t]){o=c[t]<p[t];break}if(o&&(i=c,c=p,p=i,e.s=-e.s),(t=(r=p.length)-(n=c.length))>0)for(;t--;c[n++]=0);for(t=Ct-1;r>a;){if(c[--r]<p[r]){for(n=r;n&&!c[--n];c[n]=t);--c[n],c[r]+=Ct}c[r]-=p[r]}for(;0==c[0];c.splice(0,1),--u);return c[0]?L(e,c,u):(e.s=3==g?-1:1,e.c=[e.e=0],e)},h.modulo=h.mod=function(e,t){var r,i,o=this;return e=new T(e,t),!o.c||!e.s||e.c&&!e.c[0]?new T(NaN):!e.c||o.c&&!o.c[0]?new T(o):(9==w?(i=e.s,e.s=1,r=n(o,e,0,3),e.s=i,r.s*=i):r=n(o,e,0,w),(e=o.minus(r.times(e))).c[0]||1!=w||(e.s=o.s),e)},h.multipliedBy=h.times=function(e,t){var n,r,i,o,s,a,l,u,c,p,h,d,f,g,y,m=this,E=m.c,v=(e=new T(e,t)).c;if(!(E&&v&&E[0]&&v[0]))return!m.s||!e.s||E&&!E[0]&&!v||v&&!v[0]&&!E?e.c=e.e=e.s=null:(e.s*=m.s,E&&v?(e.c=[0],e.e=0):e.c=e.e=null),e;for(r=kt(m.e/Lt)+kt(e.e/Lt),e.s*=m.s,(l=E.length)<(p=v.length)&&(f=E,E=v,v=f,i=l,l=p,p=i),i=l+p,f=[];i--;f.push(0));for(g=Ct,y=Rt,i=p;--i>=0;){for(n=0,h=v[i]%y,d=v[i]/y|0,o=i+(s=l);o>i;)n=((u=h*(u=E[--s]%y)+(a=d*u+(c=E[s]/y|0)*h)%y*y+f[o]+n)/g|0)+(a/y|0)+d*c,f[o--]=u%g;f[o]=n}return n?++r:f.splice(0,1),L(e,f,r)},h.negated=function(){var e=new T(this);return e.s=-e.s||null,e},h.plus=function(e,t){var n,r=this,i=r.s;if(t=(e=new T(e,t)).s,!i||!t)return new T(NaN);if(i!=t)return e.s=-t,r.minus(e);var o=r.e/Lt,s=e.e/Lt,a=r.c,l=e.c;if(!o||!s){if(!a||!l)return new T(i/0);if(!a[0]||!l[0])return l[0]?e:new T(a[0]?r:0*i)}if(o=kt(o),s=kt(s),a=a.slice(),i=o-s){for(i>0?(s=o,n=l):(i=-i,n=a),n.reverse();i--;n.push(0));n.reverse()}for((i=a.length)-(t=l.length)<0&&(n=l,l=a,a=n,t=i),i=0;t;)i=(a[--t]=a[t]+l[t]+i)/Ct|0,a[t]=Ct===a[t]?0:a[t]%Ct;return i&&(a=[i].concat(a),++s),L(e,a,s)},h.precision=h.sd=function(e,t){var n,r,i,o=this;if(null!=e&&e!==!!e)return Gt(e,1,Nt),null==t?t=g:Gt(t,0,8),I(new T(o),e,t);if(!(n=o.c))return null;if(r=(i=n.length-1)*Lt+1,i=n[i]){for(;i%10==0;i/=10,r--);for(i=n[0];i>=10;i/=10,r++);}return e&&o.e+1>r&&(r=o.e+1),r},h.shiftedBy=function(e){return Gt(e,-9007199254740991,It),this.times("1e"+e)},h.squareRoot=h.sqrt=function(){var e,t,r,i,o,s=this,a=s.c,l=s.s,u=s.e,c=f+4,p=new T("0.5");if(1!==l||!a||!a[0])return new T(!l||l<0&&(!a||a[0])?NaN:a?s:1/0);if(0==(l=Math.sqrt(+M(s)))||l==1/0?(((t=Ot(a)).length+u)%2==0&&(t+="0"),l=Math.sqrt(+t),u=kt((u+1)/2)-(u<0||u%2),r=new T(t=l==1/0?"5e"+u:(t=l.toExponential()).slice(0,t.indexOf("e")+1)+u)):r=new T(l+""),r.c[0])for((l=(u=r.e)+c)<3&&(l=0);;)if(o=r,r=p.times(o.plus(n(s,o,c,1))),Ot(o.c).slice(0,l)===(t=Ot(r.c)).slice(0,l)){if(r.e<u&&--l,"9999"!=(t=t.slice(l-3,l+1))&&(i||"4999"!=t)){+t&&(+t.slice(1)||"5"!=t.charAt(0))||(I(r,r.e+f+2,1),e=!r.times(r).eq(s));break}if(!i&&(I(o,o.e+f+2,0),o.times(o).eq(s))){r=o;break}c+=4,l+=4,i=1}return I(r,r.e+f+1,g,e)},h.toExponential=function(e,t){return null!=e&&(Gt(e,0,Nt),e++),A(this,e,t,1)},h.toFixed=function(e,t){return null!=e&&(Gt(e,0,Nt),e=e+this.e+1),A(this,e,t)},h.toFormat=function(e,t,n){var r,i=this;if(null==n)null!=e&&t&&"object"==typeof t?(n=t,t=null):e&&"object"==typeof e?(n=e,e=t=null):n=x;else if("object"!=typeof n)throw Error(Tt+"Argument not an object: "+n);if(r=i.toFixed(e,t),i.c){var o,s=r.split("."),a=+n.groupSize,l=+n.secondaryGroupSize,u=n.groupSeparator||"",c=s[0],p=s[1],h=i.s<0,d=h?c.slice(1):c,f=d.length;if(l&&(o=a,a=l,l=o,f-=o),a>0&&f>0){for(o=f%a||a,c=d.substr(0,o);o<f;o+=a)c+=u+d.substr(o,a);l>0&&(c+=u+d.slice(o)),h&&(c="-"+c)}r=p?c+(n.decimalSeparator||"")+((l=+n.fractionGroupSize)?p.replace(new RegExp("\\d{"+l+"}\\B","g"),"$&"+(n.fractionGroupSeparator||"")):p):c}return(n.prefix||"")+r+(n.suffix||"")},h.toFraction=function(e){var t,r,i,o,s,a,l,u,c,p,h,f,y=this,m=y.c;if(null!=e&&(!(l=new T(e)).isInteger()&&(l.c||1!==l.s)||l.lt(d)))throw Error(Tt+"Argument "+(l.isInteger()?"out of range: ":"not an integer: ")+M(l));if(!m)return new T(y);for(t=new T(d),c=r=new T(d),i=u=new T(d),f=Ot(m),s=t.e=f.length-y.e-1,t.c[0]=Mt[(a=s%Lt)<0?Lt+a:a],e=!e||l.comparedTo(t)>0?s>0?t:c:l,a=v,v=1/0,l=new T(f),u.c[0]=0;p=n(l,t,0,1),1!=(o=r.plus(p.times(i))).comparedTo(e);)r=i,i=o,c=u.plus(p.times(o=c)),u=o,t=l.minus(p.times(o=t)),l=o;return o=n(e.minus(r),i,0,1),u=u.plus(o.times(c)),r=r.plus(o.times(i)),u.s=c.s=y.s,h=n(c,i,s*=2,g).minus(y).abs().comparedTo(n(u,r,s,g).minus(y).abs())<1?[c,i]:[u,r],v=a,h},h.toNumber=function(){return+M(this)},h.toPrecision=function(e,t){return null!=e&&Gt(e,1,Nt),A(this,e,t,2)},h.toString=function(e){var t,n=this,i=n.s,o=n.e;return null===o?i?(t="Infinity",i<0&&(t="-"+t)):t="NaN":(null==e?t=o<=y||o>=m?Bt(Ot(n.c),o):Ft(Ot(n.c),o,"0"):10===e&&_?t=Ft(Ot((n=I(new T(n),f+o+1,g)).c),n.e,"0"):(Gt(e,2,P.length,"Base"),t=r(Ft(Ot(n.c),o,"0"),10,e,i,!0)),i<0&&n.c[0]&&(t="-"+t)),t},h.valueOf=h.toJSON=function(){return M(this)},h._isBigNumber=!0,h[Symbol.toStringTag]="BigNumber",h[Symbol.for("nodejs.util.inspect.custom")]=h.valueOf,null!=t&&T.set(t),T}(),Ht=class{key;left=null;right=null;constructor(e){this.key=e}},qt=class extends Ht{constructor(e){super(e)}},Yt=class{size=0;modificationCount=0;splayCount=0;splay(e){const t=this.root;if(null==t)return this.compare(e,e),-1;let n=null,r=null,i=null,o=null,s=t;const a=this.compare;let l;for(;;)if(l=a(s.key,e),l>0){let t=s.left;if(null==t)break;if(l=a(t.key,e),l>0&&(s.left=t.right,t.right=s,s=t,t=s.left,null==t))break;null==n?r=s:n.left=s,n=s,s=t}else{if(!(l<0))break;{let t=s.right;if(null==t)break;if(l=a(t.key,e),l<0&&(s.right=t.left,t.left=s,s=t,t=s.right,null==t))break;null==i?o=s:i.right=s,i=s,s=t}}return null!=i&&(i.right=s.left,s.left=o),null!=n&&(n.left=s.right,s.right=r),this.root!==s&&(this.root=s,this.splayCount++),l}splayMin(e){let t=e,n=t.left;for(;null!=n;){const e=n;t.left=e.right,e.right=t,t=e,n=t.left}return t}splayMax(e){let t=e,n=t.right;for(;null!=n;){const e=n;t.right=e.left,e.left=t,t=e,n=t.right}return t}_delete(e){if(null==this.root)return null;if(0!=this.splay(e))return null;let t=this.root;const n=t,r=t.left;if(this.size--,null==r)this.root=t.right;else{const e=t.right;t=this.splayMax(r),t.right=e,this.root=t}return this.modificationCount++,n}addNewRoot(e,t){this.size++,this.modificationCount++;const n=this.root;null!=n?(t<0?(e.left=n,e.right=n.right,n.right=null):(e.right=n,e.left=n.left,n.left=null),this.root=e):this.root=e}_first(){const e=this.root;return null==e?null:(this.root=this.splayMin(e),this.root)}_last(){const e=this.root;return null==e?null:(this.root=this.splayMax(e),this.root)}clear(){this.root=null,this.size=0,this.modificationCount++}has(e){return this.validKey(e)&&0==this.splay(e)}defaultCompare(){return(e,t)=>e<t?-1:e>t?1:0}wrap(){return{getRoot:()=>this.root,setRoot:e=>{this.root=e},getSize:()=>this.size,getModificationCount:()=>this.modificationCount,getSplayCount:()=>this.splayCount,setSplayCount:e=>{this.splayCount=e},splay:e=>this.splay(e),has:e=>this.has(e)}}},jt=class e extends Yt{root=null;compare;validKey;constructor(e,t){super(),this.compare=e??this.defaultCompare(),this.validKey=t??(e=>null!=e&&null!=e)}delete(e){return!!this.validKey(e)&&null!=this._delete(e)}deleteAll(e){for(const t of e)this.delete(t)}forEach(e){const t=this[Symbol.iterator]();let n;for(;n=t.next(),!n.done;)e(n.value,n.value,this)}add(e){const t=this.splay(e);return 0!=t&&this.addNewRoot(new qt(e),t),this}addAndReturn(e){const t=this.splay(e);return 0!=t&&this.addNewRoot(new qt(e),t),this.root.key}addAll(e){for(const t of e)this.add(t)}isEmpty(){return null==this.root}isNotEmpty(){return null!=this.root}single(){if(0==this.size)throw"Bad state: No element";if(this.size>1)throw"Bad state: Too many element";return this.root.key}first(){if(0==this.size)throw"Bad state: No element";return this._first().key}last(){if(0==this.size)throw"Bad state: No element";return this._last().key}lastBefore(e){if(null==e)throw"Invalid arguments(s)";if(null==this.root)return null;if(this.splay(e)<0)return this.root.key;let t=this.root.left;if(null==t)return null;let n=t.right;for(;null!=n;)t=n,n=t.right;return t.key}firstAfter(e){if(null==e)throw"Invalid arguments(s)";if(null==this.root)return null;if(this.splay(e)>0)return this.root.key;let t=this.root.right;if(null==t)return null;let n=t.left;for(;null!=n;)t=n,n=t.left;return t.key}retainAll(t){const n=new e(this.compare,this.validKey),r=this.modificationCount;for(const e of t){if(r!=this.modificationCount)throw"Concurrent modification during iteration.";this.validKey(e)&&0==this.splay(e)&&n.add(this.root.key)}n.size!=this.size&&(this.root=n.root,this.size=n.size,this.modificationCount++)}lookup(e){if(!this.validKey(e))return null;return 0!=this.splay(e)?null:this.root.key}intersection(t){const n=new e(this.compare,this.validKey);for(const e of this)t.has(e)&&n.add(e);return n}difference(t){const n=new e(this.compare,this.validKey);for(const e of this)t.has(e)||n.add(e);return n}union(e){const t=this.clone();return t.addAll(e),t}clone(){const t=new e(this.compare,this.validKey);return t.size=this.size,t.root=this.copyNode(this.root),t}copyNode(e){if(null==e)return null;const t=new qt(e.key);return function e(t,n){let r,i;do{if(r=t.left,i=t.right,null!=r){const t=new qt(r.key);n.left=t,e(r,t)}if(null!=i){const e=new qt(i.key);n.right=e,t=i,n=e}}while(null!=i)}(e,t),t}toSet(){return this.clone()}entries(){return new Wt(this.wrap())}keys(){return this[Symbol.iterator]()}values(){return this[Symbol.iterator]()}[Symbol.iterator](){return new $t(this.wrap())}[Symbol.toStringTag]="[object Set]"},zt=class{tree;path=new Array;modificationCount=null;splayCount;constructor(e){this.tree=e,this.splayCount=e.getSplayCount()}[Symbol.iterator](){return this}next(){return this.moveNext()?{done:!1,value:this.current()}:{done:!0,value:null}}current(){if(!this.path.length)return null;const e=this.path[this.path.length-1];return this.getValue(e)}rebuildPath(e){this.path.splice(0,this.path.length),this.tree.splay(e),this.path.push(this.tree.getRoot()),this.splayCount=this.tree.getSplayCount()}findLeftMostDescendent(e){for(;null!=e;)this.path.push(e),e=e.left}moveNext(){if(this.modificationCount!=this.tree.getModificationCount()){if(null==this.modificationCount){this.modificationCount=this.tree.getModificationCount();let e=this.tree.getRoot();for(;null!=e;)this.path.push(e),e=e.left;return this.path.length>0}throw"Concurrent modification during iteration."}if(!this.path.length)return!1;this.splayCount!=this.tree.getSplayCount()&&this.rebuildPath(this.path[this.path.length-1].key);let e=this.path[this.path.length-1],t=e.right;if(null!=t){for(;null!=t;)this.path.push(t),t=t.left;return!0}for(this.path.pop();this.path.length&&this.path[this.path.length-1].right===e;)e=this.path.pop();return this.path.length>0}},$t=class extends zt{getValue(e){return e.key}},Wt=class extends zt{getValue(e){return[e.key,e.key]}},Xt=e=>()=>e,Kt=e=>{const t=e?(t,n)=>n.minus(t).abs().isLessThanOrEqualTo(e):Xt(!1);return(e,n)=>t(e,n)?0:e.comparedTo(n)};function Zt(e){const t=e?(t,n,r,i,o)=>t.exponentiatedBy(2).isLessThanOrEqualTo(i.minus(n).exponentiatedBy(2).plus(o.minus(r).exponentiatedBy(2)).times(e)):Xt(!1);return(e,n,r)=>{const i=e.x,o=e.y,s=r.x,a=r.y,l=o.minus(a).times(n.x.minus(s)).minus(i.minus(s).times(n.y.minus(a)));return t(l,i,o,s,a)?0:l.comparedTo(0)}}var Jt=e=>e,Qt=e=>{if(e){const t=new jt(Kt(e)),n=new jt(Kt(e)),r=(e,t)=>t.addAndReturn(e),i=e=>({x:r(e.x,t),y:r(e.y,n)});return i({x:new Ut(0),y:new Ut(0)}),i}return Jt},en=e=>({set:e=>{tn=en(e)},reset:()=>en(e),compare:Kt(e),snap:Qt(e),orient:Zt(e)}),tn=en(),nn=(e,t)=>e.ll.x.isLessThanOrEqualTo(t.x)&&t.x.isLessThanOrEqualTo(e.ur.x)&&e.ll.y.isLessThanOrEqualTo(t.y)&&t.y.isLessThanOrEqualTo(e.ur.y),rn=(e,t)=>{if(t.ur.x.isLessThan(e.ll.x)||e.ur.x.isLessThan(t.ll.x)||t.ur.y.isLessThan(e.ll.y)||e.ur.y.isLessThan(t.ll.y))return null;const n=e.ll.x.isLessThan(t.ll.x)?t.ll.x:e.ll.x,r=e.ur.x.isLessThan(t.ur.x)?e.ur.x:t.ur.x;return{ll:{x:n,y:e.ll.y.isLessThan(t.ll.y)?t.ll.y:e.ll.y},ur:{x:r,y:e.ur.y.isLessThan(t.ur.y)?e.ur.y:t.ur.y}}},on=(e,t)=>e.x.times(t.y).minus(e.y.times(t.x)),sn=(e,t)=>e.x.times(t.x).plus(e.y.times(t.y)),an=e=>sn(e,e).sqrt(),ln=(e,t,n)=>{const r={x:t.x.minus(e.x),y:t.y.minus(e.y)},i={x:n.x.minus(e.x),y:n.y.minus(e.y)};return on(i,r).div(an(i)).div(an(r))},un=(e,t,n)=>{const r={x:t.x.minus(e.x),y:t.y.minus(e.y)},i={x:n.x.minus(e.x),y:n.y.minus(e.y)};return sn(i,r).div(an(i)).div(an(r))},cn=(e,t,n)=>t.y.isZero()?null:{x:e.x.plus(t.x.div(t.y).times(n.minus(e.y))),y:n},pn=(e,t,n)=>t.x.isZero()?null:{x:n,y:e.y.plus(t.y.div(t.x).times(n.minus(e.x)))},hn=class e{point;isLeft;segment;otherSE;consumedBy;static compare(t,n){const r=e.comparePoints(t.point,n.point);return 0!==r?r:(t.point!==n.point&&t.link(n),t.isLeft!==n.isLeft?t.isLeft?1:-1:Sn.compare(t.segment,n.segment))}static comparePoints(e,t){return e.x.isLessThan(t.x)?-1:e.x.isGreaterThan(t.x)?1:e.y.isLessThan(t.y)?-1:e.y.isGreaterThan(t.y)?1:0}constructor(e,t){void 0===e.events?e.events=[this]:e.events.push(this),this.point=e,this.isLeft=t}link(e){if(e.point===this.point)throw new Error("Tried to link already linked events");const t=e.point.events;for(let e=0,n=t.length;e<n;e++){const n=t[e];this.point.events.push(n),n.point=this.point}this.checkForConsuming()}checkForConsuming(){const e=this.point.events.length;for(let t=0;t<e;t++){const n=this.point.events[t];if(void 0===n.segment.consumedBy)for(let r=t+1;r<e;r++){const e=this.point.events[r];void 0===e.consumedBy&&(n.otherSE.point.events===e.otherSE.point.events&&n.segment.consume(e.segment))}}}getAvailableLinkedEvents(){const e=[];for(let t=0,n=this.point.events.length;t<n;t++){const n=this.point.events[t];n!==this&&!n.segment.ringOut&&n.segment.isInResult()&&e.push(n)}return e}getLeftmostComparator(e){const t=new Map,n=n=>{const r=n.otherSE;t.set(n,{sine:ln(this.point,e.point,r.point),cosine:un(this.point,e.point,r.point)})};return(e,r)=>{t.has(e)||n(e),t.has(r)||n(r);const{sine:i,cosine:o}=t.get(e),{sine:s,cosine:a}=t.get(r);return i.isGreaterThanOrEqualTo(0)&&s.isGreaterThanOrEqualTo(0)?o.isLessThan(a)?1:o.isGreaterThan(a)?-1:0:i.isLessThan(0)&&s.isLessThan(0)?o.isLessThan(a)?-1:o.isGreaterThan(a)?1:0:s.isLessThan(i)?-1:s.isGreaterThan(i)?1:0}}},dn=class e{events;poly;_isExteriorRing;_enclosingRing;static factory(t){const n=[];for(let r=0,i=t.length;r<i;r++){const i=t[r];if(!i.isInResult()||i.ringOut)continue;let o=null,s=i.leftSE,a=i.rightSE;const l=[s],u=s.point,c=[];for(;o=s,s=a,l.push(s),s.point!==u;)for(;;){const t=s.getAvailableLinkedEvents();if(0===t.length){const e=l[0].point,t=l[l.length-1].point;throw new Error(`Unable to complete output ring starting at [${e.x}, ${e.y}]. Last matching segment found ends at [${t.x}, ${t.y}].`)}if(1===t.length){a=t[0].otherSE;break}let r=null;for(let e=0,t=c.length;e<t;e++)if(c[e].point===s.point){r=e;break}if(null!==r){const t=c.splice(r)[0],i=l.splice(t.index);i.unshift(i[0].otherSE),n.push(new e(i.reverse()));continue}c.push({index:l.length,point:s.point});const i=s.getLeftmostComparator(o);a=t.sort(i)[0].otherSE;break}n.push(new e(l))}return n}constructor(e){this.events=e;for(let t=0,n=e.length;t<n;t++)e[t].segment.ringOut=this;this.poly=null}getGeom(){let e=this.events[0].point;const t=[e];for(let n=1,r=this.events.length-1;n<r;n++){const r=this.events[n].point,i=this.events[n+1].point;0!==tn.orient(r,e,i)&&(t.push(r),e=r)}if(1===t.length)return null;const n=t[0],r=t[1];0===tn.orient(n,e,r)&&t.shift(),t.push(t[0]);const i=this.isExteriorRing()?1:-1,o=this.isExteriorRing()?0:t.length-1,s=this.isExteriorRing()?t.length:-1,a=[];for(let e=o;e!=s;e+=i)a.push([t[e].x.toNumber(),t[e].y.toNumber()]);return a}isExteriorRing(){if(void 0===this._isExteriorRing){const e=this.enclosingRing();this._isExteriorRing=!e||!e.isExteriorRing()}return this._isExteriorRing}enclosingRing(){return void 0===this._enclosingRing&&(this._enclosingRing=this._calcEnclosingRing()),this._enclosingRing}_calcEnclosingRing(){let e=this.events[0];for(let t=1,n=this.events.length;t<n;t++){const n=this.events[t];hn.compare(e,n)>0&&(e=n)}let t=e.segment.prevInResult(),n=t?t.prevInResult():null;for(;;){if(!t)return null;if(!n)return t.ringOut;if(n.ringOut!==t.ringOut)return n.ringOut?.enclosingRing()!==t.ringOut?t.ringOut:t.ringOut?.enclosingRing();t=n.prevInResult(),n=t?t.prevInResult():null}}},fn=class{exteriorRing;interiorRings;constructor(e){this.exteriorRing=e,e.poly=this,this.interiorRings=[]}addInterior(e){this.interiorRings.push(e),e.poly=this}getGeom(){const e=this.exteriorRing.getGeom();if(null===e)return null;const t=[e];for(let e=0,n=this.interiorRings.length;e<n;e++){const n=this.interiorRings[e].getGeom();null!==n&&t.push(n)}return t}},gn=class{rings;polys;constructor(e){this.rings=e,this.polys=this._composePolys(e)}getGeom(){const e=[];for(let t=0,n=this.polys.length;t<n;t++){const n=this.polys[t].getGeom();null!==n&&e.push(n)}return e}_composePolys(e){const t=[];for(let n=0,r=e.length;n<r;n++){const r=e[n];if(!r.poly)if(r.isExteriorRing())t.push(new fn(r));else{const e=r.enclosingRing();e?.poly||t.push(new fn(e)),e?.poly?.addInterior(r)}}return t}},yn=class{queue;tree;segments;constructor(e,t=Sn.compare){this.queue=e,this.tree=new jt(t),this.segments=[]}process(e){const t=e.segment,n=[];if(e.consumedBy)return e.isLeft?this.queue.delete(e.otherSE):this.tree.delete(t),n;e.isLeft&&this.tree.add(t);let r=t,i=t;do{r=this.tree.lastBefore(r)}while(null!=r&&null!=r.consumedBy);do{i=this.tree.firstAfter(i)}while(null!=i&&null!=i.consumedBy);if(e.isLeft){let o=null;if(r){const e=r.getIntersection(t);if(null!==e&&(t.isAnEndpoint(e)||(o=e),!r.isAnEndpoint(e))){const t=this._splitSafely(r,e);for(let e=0,r=t.length;e<r;e++)n.push(t[e])}}let s=null;if(i){const e=i.getIntersection(t);if(null!==e&&(t.isAnEndpoint(e)||(s=e),!i.isAnEndpoint(e))){const t=this._splitSafely(i,e);for(let e=0,r=t.length;e<r;e++)n.push(t[e])}}if(null!==o||null!==s){let e=null;if(null===o)e=s;else if(null===s)e=o;else{e=hn.comparePoints(o,s)<=0?o:s}this.queue.delete(t.rightSE),n.push(t.rightSE);const r=t.split(e);for(let e=0,t=r.length;e<t;e++)n.push(r[e])}n.length>0?(this.tree.delete(t),n.push(e)):(this.segments.push(t),t.prev=r)}else{if(r&&i){const e=r.getIntersection(i);if(null!==e){if(!r.isAnEndpoint(e)){const t=this._splitSafely(r,e);for(let e=0,r=t.length;e<r;e++)n.push(t[e])}if(!i.isAnEndpoint(e)){const t=this._splitSafely(i,e);for(let e=0,r=t.length;e<r;e++)n.push(t[e])}}}this.tree.delete(t)}return n}_splitSafely(e,t){this.tree.delete(e);const n=e.rightSE;this.queue.delete(n);const r=e.split(t);return r.push(n),void 0===e.consumedBy&&this.tree.add(e),r}},mn=new class{type;numMultiPolys;run(e,t,n){mn.type=e;const r=[new xn(t,!0)];for(let e=0,t=n.length;e<t;e++)r.push(new xn(n[e],!1));if(mn.numMultiPolys=r.length,"difference"===mn.type){const e=r[0];let t=1;for(;t<r.length;)null!==rn(r[t].bbox,e.bbox)?t++:r.splice(t,1)}if("intersection"===mn.type)for(let e=0,t=r.length;e<t;e++){const t=r[e];for(let n=e+1,i=r.length;n<i;n++)if(null===rn(t.bbox,r[n].bbox))return[]}const i=new jt(hn.compare);for(let e=0,t=r.length;e<t;e++){const t=r[e].getSweepEvents();for(let e=0,n=t.length;e<n;e++)i.add(t[e])}const o=new yn(i);let s=null;for(0!=i.size&&(s=i.first(),i.delete(s));s;){const e=o.process(s);for(let t=0,n=e.length;t<n;t++){const n=e[t];void 0===n.consumedBy&&i.add(n)}0!=i.size?(s=i.first(),i.delete(s)):s=null}tn.reset();const a=dn.factory(o.segments);return new gn(a).getGeom()}},En=mn,vn=0,Sn=class e{id;leftSE;rightSE;rings;windings;ringOut;consumedBy;prev;_prevInResult;_beforeState;_afterState;_isInResult;static compare(e,t){const n=e.leftSE.point.x,r=t.leftSE.point.x,i=e.rightSE.point.x,o=t.rightSE.point.x;if(o.isLessThan(n))return 1;if(i.isLessThan(r))return-1;const s=e.leftSE.point.y,a=t.leftSE.point.y,l=e.rightSE.point.y,u=t.rightSE.point.y;if(n.isLessThan(r)){if(a.isLessThan(s)&&a.isLessThan(l))return 1;if(a.isGreaterThan(s)&&a.isGreaterThan(l))return-1;const n=e.comparePoint(t.leftSE.point);if(n<0)return 1;if(n>0)return-1;const r=t.comparePoint(e.rightSE.point);return 0!==r?r:-1}if(n.isGreaterThan(r)){if(s.isLessThan(a)&&s.isLessThan(u))return-1;if(s.isGreaterThan(a)&&s.isGreaterThan(u))return 1;const n=t.comparePoint(e.leftSE.point);if(0!==n)return n;const r=e.comparePoint(t.rightSE.point);return r<0?1:r>0?-1:1}if(s.isLessThan(a))return-1;if(s.isGreaterThan(a))return 1;if(i.isLessThan(o)){const n=t.comparePoint(e.rightSE.point);if(0!==n)return n}if(i.isGreaterThan(o)){const n=e.comparePoint(t.rightSE.point);if(n<0)return 1;if(n>0)return-1}if(!i.eq(o)){const e=l.minus(s),t=i.minus(n),c=u.minus(a),p=o.minus(r);if(e.isGreaterThan(t)&&c.isLessThan(p))return 1;if(e.isLessThan(t)&&c.isGreaterThan(p))return-1}return i.isGreaterThan(o)?1:i.isLessThan(o)||l.isLessThan(u)?-1:l.isGreaterThan(u)?1:e.id<t.id?-1:e.id>t.id?1:0}constructor(e,t,n,r){this.id=++vn,this.leftSE=e,e.segment=this,e.otherSE=t,this.rightSE=t,t.segment=this,t.otherSE=e,this.rings=n,this.windings=r}static fromRing(t,n,r){let i,o,s;const a=hn.comparePoints(t,n);if(a<0)i=t,o=n,s=1;else{if(!(a>0))throw new Error(`Tried to create degenerate segment at [${t.x}, ${t.y}]`);i=n,o=t,s=-1}const l=new hn(i,!0),u=new hn(o,!1);return new e(l,u,[r],[s])}replaceRightSE(e){this.rightSE=e,this.rightSE.segment=this,this.rightSE.otherSE=this.leftSE,this.leftSE.otherSE=this.rightSE}bbox(){const e=this.leftSE.point.y,t=this.rightSE.point.y;return{ll:{x:this.leftSE.point.x,y:e.isLessThan(t)?e:t},ur:{x:this.rightSE.point.x,y:e.isGreaterThan(t)?e:t}}}vector(){return{x:this.rightSE.point.x.minus(this.leftSE.point.x),y:this.rightSE.point.y.minus(this.leftSE.point.y)}}isAnEndpoint(e){return e.x.eq(this.leftSE.point.x)&&e.y.eq(this.leftSE.point.y)||e.x.eq(this.rightSE.point.x)&&e.y.eq(this.rightSE.point.y)}comparePoint(e){return tn.orient(this.leftSE.point,e,this.rightSE.point)}getIntersection(e){const t=this.bbox(),n=e.bbox(),r=rn(t,n);if(null===r)return null;const i=this.leftSE.point,o=this.rightSE.point,s=e.leftSE.point,a=e.rightSE.point,l=nn(t,s)&&0===this.comparePoint(s),u=nn(n,i)&&0===e.comparePoint(i),c=nn(t,a)&&0===this.comparePoint(a),p=nn(n,o)&&0===e.comparePoint(o);if(u&&l)return p&&!c?o:!p&&c?a:null;if(u)return c&&i.x.eq(a.x)&&i.y.eq(a.y)?null:i;if(l)return p&&o.x.eq(s.x)&&o.y.eq(s.y)?null:s;if(p&&c)return null;if(p)return o;if(c)return a;const h=((e,t,n,r)=>{if(t.x.isZero())return pn(n,r,e.x);if(r.x.isZero())return pn(e,t,n.x);if(t.y.isZero())return cn(n,r,e.y);if(r.y.isZero())return cn(e,t,n.y);const i=on(t,r);if(i.isZero())return null;const o={x:n.x.minus(e.x),y:n.y.minus(e.y)},s=on(o,t).div(i),a=on(o,r).div(i),l=e.x.plus(a.times(t.x)),u=n.x.plus(s.times(r.x)),c=e.y.plus(a.times(t.y)),p=n.y.plus(s.times(r.y));return{x:l.plus(u).div(2),y:c.plus(p).div(2)}})(i,this.vector(),s,e.vector());return null===h?null:nn(r,h)?tn.snap(h):null}split(t){const n=[],r=void 0!==t.events,i=new hn(t,!0),o=new hn(t,!1),s=this.rightSE;this.replaceRightSE(o),n.push(o),n.push(i);const a=new e(i,s,this.rings.slice(),this.windings.slice());return hn.comparePoints(a.leftSE.point,a.rightSE.point)>0&&a.swapEvents(),hn.comparePoints(this.leftSE.point,this.rightSE.point)>0&&this.swapEvents(),r&&(i.checkForConsuming(),o.checkForConsuming()),n}swapEvents(){const e=this.rightSE;this.rightSE=this.leftSE,this.leftSE=e,this.leftSE.isLeft=!0,this.rightSE.isLeft=!1;for(let e=0,t=this.windings.length;e<t;e++)this.windings[e]*=-1}consume(t){let n=this,r=t;for(;n.consumedBy;)n=n.consumedBy;for(;r.consumedBy;)r=r.consumedBy;const i=e.compare(n,r);if(0!==i){if(i>0){const e=n;n=r,r=e}if(n.prev===r){const e=n;n=r,r=e}for(let e=0,t=r.rings.length;e<t;e++){const t=r.rings[e],i=r.windings[e],o=n.rings.indexOf(t);-1===o?(n.rings.push(t),n.windings.push(i)):n.windings[o]+=i}r.rings=null,r.windings=null,r.consumedBy=n,r.leftSE.consumedBy=n.leftSE,r.rightSE.consumedBy=n.rightSE}}prevInResult(){return void 0!==this._prevInResult||(this.prev?this.prev.isInResult()?this._prevInResult=this.prev:this._prevInResult=this.prev.prevInResult():this._prevInResult=null),this._prevInResult}beforeState(){if(void 0!==this._beforeState)return this._beforeState;if(this.prev){const e=this.prev.consumedBy||this.prev;this._beforeState=e.afterState()}else this._beforeState={rings:[],windings:[],multiPolys:[]};return this._beforeState}afterState(){if(void 0!==this._afterState)return this._afterState;const e=this.beforeState();this._afterState={rings:e.rings.slice(0),windings:e.windings.slice(0),multiPolys:[]};const t=this._afterState.rings,n=this._afterState.windings,r=this._afterState.multiPolys;for(let e=0,r=this.rings.length;e<r;e++){const r=this.rings[e],i=this.windings[e],o=t.indexOf(r);-1===o?(t.push(r),n.push(i)):n[o]+=i}const i=[],o=[];for(let e=0,r=t.length;e<r;e++){if(0===n[e])continue;const r=t[e],s=r.poly;if(-1===o.indexOf(s))if(r.isExterior)i.push(s);else{-1===o.indexOf(s)&&o.push(s);const e=i.indexOf(r.poly);-1!==e&&i.splice(e,1)}}for(let e=0,t=i.length;e<t;e++){const t=i[e].multiPoly;-1===r.indexOf(t)&&r.push(t)}return this._afterState}isInResult(){if(this.consumedBy)return!1;if(void 0!==this._isInResult)return this._isInResult;const e=this.beforeState().multiPolys,t=this.afterState().multiPolys;switch(En.type){case"union":{const n=0===e.length,r=0===t.length;this._isInResult=n!==r;break}case"intersection":{let n,r;e.length<t.length?(n=e.length,r=t.length):(n=t.length,r=e.length),this._isInResult=r===En.numMultiPolys&&n<r;break}case"xor":{const n=Math.abs(e.length-t.length);this._isInResult=n%2==1;break}case"difference":{const n=e=>1===e.length&&e[0].isSubject;this._isInResult=n(e)!==n(t);break}}return this._isInResult}},wn=class{poly;isExterior;segments;bbox;constructor(e,t,n){if(!Array.isArray(e)||0===e.length)throw new Error("Input geometry is not a valid Polygon or MultiPolygon");if(this.poly=t,this.isExterior=n,this.segments=[],"number"!=typeof e[0][0]||"number"!=typeof e[0][1])throw new Error("Input geometry is not a valid Polygon or MultiPolygon");const r=tn.snap({x:new Ut(e[0][0]),y:new Ut(e[0][1])});this.bbox={ll:{x:r.x,y:r.y},ur:{x:r.x,y:r.y}};let i=r;for(let t=1,n=e.length;t<n;t++){if("number"!=typeof e[t][0]||"number"!=typeof e[t][1])throw new Error("Input geometry is not a valid Polygon or MultiPolygon");const n=tn.snap({x:new Ut(e[t][0]),y:new Ut(e[t][1])});n.x.eq(i.x)&&n.y.eq(i.y)||(this.segments.push(Sn.fromRing(i,n,this)),n.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=n.x),n.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=n.y),n.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=n.x),n.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=n.y),i=n)}r.x.eq(i.x)&&r.y.eq(i.y)||this.segments.push(Sn.fromRing(i,r,this))}getSweepEvents(){const e=[];for(let t=0,n=this.segments.length;t<n;t++){const n=this.segments[t];e.push(n.leftSE),e.push(n.rightSE)}return e}},bn=class{multiPoly;exteriorRing;interiorRings;bbox;constructor(e,t){if(!Array.isArray(e))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");this.exteriorRing=new wn(e[0],this,!0),this.bbox={ll:{x:this.exteriorRing.bbox.ll.x,y:this.exteriorRing.bbox.ll.y},ur:{x:this.exteriorRing.bbox.ur.x,y:this.exteriorRing.bbox.ur.y}},this.interiorRings=[];for(let t=1,n=e.length;t<n;t++){const n=new wn(e[t],this,!1);n.bbox.ll.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=n.bbox.ll.x),n.bbox.ll.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=n.bbox.ll.y),n.bbox.ur.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=n.bbox.ur.x),n.bbox.ur.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=n.bbox.ur.y),this.interiorRings.push(n)}this.multiPoly=t}getSweepEvents(){const e=this.exteriorRing.getSweepEvents();for(let t=0,n=this.interiorRings.length;t<n;t++){const n=this.interiorRings[t].getSweepEvents();for(let t=0,r=n.length;t<r;t++)e.push(n[t])}return e}},xn=class{isSubject;polys;bbox;constructor(e,t){if(!Array.isArray(e))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");try{"number"==typeof e[0][0][0]&&(e=[e])}catch(e){}this.polys=[],this.bbox={ll:{x:new Ut(Number.POSITIVE_INFINITY),y:new Ut(Number.POSITIVE_INFINITY)},ur:{x:new Ut(Number.NEGATIVE_INFINITY),y:new Ut(Number.NEGATIVE_INFINITY)}};for(let t=0,n=e.length;t<n;t++){const n=new bn(e[t],this);n.bbox.ll.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=n.bbox.ll.x),n.bbox.ll.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=n.bbox.ll.y),n.bbox.ur.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=n.bbox.ur.x),n.bbox.ur.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=n.bbox.ur.y),this.polys.push(n)}this.isSubject=t}getSweepEvents(){const e=[];for(let t=0,n=this.polys.length;t<n;t++){const n=this.polys[t].getSweepEvents();for(let t=0,r=n.length;t<r;t++)e.push(n[t])}return e}};tn.set;var Pn=function(e,t={}){const n=[];if(x(e,e=>{n.push(e.coordinates)}),n.length<2)throw new Error("Must have at least 2 geometries");const r=((e,...t)=>En.run("union",e,t))(n[0],...n.slice(1));return 0===r.length?null:1===r.length?p(r[0],t.properties):function(e,t,n={}){return u({type:"MultiPolygon",coordinates:e},t,n)}(r,t.properties)};const _n=(e,t)=>{const n=function(e,t=.01){const n=e.geometry.coordinates.map(e=>[...e]),r=n.length-1,i=(e,n)=>[e[0]+(e[0]-n[0])*t,e[1]+(e[1]-n[1])*t],o=i(n[0],n[1]),s=i(n[r],n[r-1]);return n[0]=o,n[r]=s,h(n)}(t);let r;try{r=gt(e,n)}catch{return null}let i=[];if("MultiPolygon"!==r.geometry.type)return null;if(2!==r.geometry.coordinates.length)return null;i=r.geometry.coordinates.map(t=>p(t,e.properties));const o=e.id??e.properties?.id??"poly";return d(i.map((t,n)=>p(t.geometry.coordinates,{...e.properties,id:o},{id:`${o}-${n+1}`})))},Tn=([e,t],[n,r])=>{const i=e=>e*Math.PI/180,o=i(r-t),s=i(n-e),a=Math.sin(o/2)**2+Math.cos(i(t))*Math.cos(i(r))*Math.sin(s/2)**2;return 12742e3*Math.atan2(Math.sqrt(a),Math.sqrt(1-a))},An=(e,t=.01)=>{const n=e[0];return n.length<=1||!(n.length<=3&&((e,t)=>{for(let n=0;n<e.length;n++)for(let r=n+1;r<e.length;r++)if(Tn(e[n],e[r])<t)return!0;return!1})(n,t))},Cn=(e,t=.01)=>{if(e.length<=1)return!0;const n=e[e.length-1],r=e[e.length-2];return Tn(n,r)>=t},Ln=e=>e[0].length<=1||An(e),In="_splitter",Mn=({draw:e,polygonFeature:t,feature:n})=>{const r=((e,t)=>{const n=t.geometry?.coordinates;return!(!n||n.length<2||!_n(e,{geometry:t.geometry}))})(t,n);return e.setDrawingPreviewProperty("splitter",r?"valid":"invalid"),r},Rn=({draw:e,dispatch:t,polygonFeature:n})=>({feature:r,phase:i})=>{let o;if("preview"===i)o=Mn({draw:e,polygonFeature:n,feature:r});else{if(!i?.startsWith("commit-"))return{valid:!0};o=(({draw:e,dispatch:t,polygonFeature:n,feature:r})=>{const i=Mn({draw:e,polygonFeature:n,feature:r});return t({type:"SET_ACTION",payload:{name:"split",isValid:i}}),t({type:"SET_GEOMETRY_VALID",payload:i}),e.setGeometryValid(i),i})({draw:e,dispatch:t,polygonFeature:n,feature:r})}return o?{valid:!0}:{valid:!1,reason:"Line does not split the shape into two parts"}},Nn=()=>"undefined"!=typeof navigator&&/mac/i.test(navigator.userAgentData?.platform||navigator.platform||""),kn=new Set(["edit_vertex","edit_point"]),On=e=>kn.has(e),Dn=Nn()?"<kbd>Command</kbd> + <kbd>Z</kbd>":"<kbd>Ctrl</kbd> + <kbd>Z</kbd>",Gn=Nn()?"<kbd>Option</kbd>":"<kbd>Alt</kbd>",Vn="top-middle",Bn=(e,t="actions")=>({mobile:{slot:t,showLabel:e},tablet:{slot:t,showLabel:e},desktop:{slot:t,showLabel:e}}),Fn={reducer:{initialState:{mode:null,action:null,actionValid:!1,feature:null,tempFeature:null,selectedVertexIndex:-1,numVertices:null,geometryValid:!0,canAddPoint:!0,snap:!1,hasSnapLayers:!1,undoStackLength:0},actions:i},InitComponent:({appState:r,appConfig:i,mapState:s,pluginConfig:a,pluginState:l,services:u,mapProvider:c,buttonConfig:p,setApplicationMode:h,clearApplicationMode:d})=>{const{eventBus:f,hints:g,symbolRegistry:y}=u,{crossHair:m}=s;xe({mapState:s,pluginState:l,services:u,mapProvider:c,spatialListRegistry:r.spatialListRegistry,viewportRef:r.layoutRefs.viewportRef});const E=e(!1);E.current=Te({appState:r,pluginState:l})||_e(l.mode)&&"keyboard"===r.interfaceType,Ae({mapState:s,pluginConfig:a,pluginState:l,mapProvider:c,eventBus:f,symbolRegistry:y}),n(()=>{if(l.mode)return h(ae),()=>d(ae);d(ae)},[l.mode]),t(()=>{const e=null!==l.mode&&"edit_vertex"!==l.mode;return f.emit(o.MAP_SET_SPATIAL_LIST_SUPPRESSED,{suppressed:e}),()=>{f.emit(o.MAP_SET_SPATIAL_LIST_SUPPRESSED,{suppressed:!1})}},[l.mode,f]),t(()=>{if(!E.current)return;const e=m.isVisible;return m.fixAtCenter(),()=>{e||E.current||m.hide()}},[l.mode,r.interfaceType,r.expandedButtons]),t(()=>{["edit_vertex","edit_point","draw_polygon","draw_line","draw_point"].includes(l.mode)&&c.draw&&c.draw.setInterfaceType(r.interfaceType)},[r.interfaceType,l.mode]),t(()=>{if(c.draw)return ge({appState:r,appConfig:i,mapState:s,mapProvider:c,buttonConfig:p,pluginState:l,eventBus:f,hints:g})},[c,r,l])},applicationModes:{[ae]:{include:["mapStyles","mapControls","scaleBar"]}},buttons:[{id:"drawCancel",label:"Cancel",variant:"tertiary",exclusiveSlot:!0,hiddenWhen:({pluginState:e})=>!e.mode,...Bn(!0)},{id:"drawAddPoint",label:"Add point",variant:"primary",exclusiveSlot:!0,hiddenWhen:({appState:e,pluginState:t})=>!Te({appState:e,pluginState:t}),enableWhen:({pluginState:e})=>e.canAddPoint,...Bn(!0)},{id:"drawDone",label:"Done",variant:"primary",exclusiveSlot:!0,hiddenWhen:({pluginState:e})=>!(["draw_polygon","draw_line"].includes(e.mode)||On(e.mode)),enableWhen:({pluginState:e})=>{const{mode:t,geometryValid:n}=e;return(["draw_polygon","draw_line"].includes(t)||On(t))&&n},...Bn(!0)},{id:"drawUndo",label:"Undo",iconId:"undo",hiddenWhen:({pluginState:e})=>!(["draw_polygon","draw_line"].includes(e.mode)||On(e.mode)),enableWhen:({pluginState:e})=>["draw_polygon","draw_line"].includes(e.mode)?e.numVertices>0:e.undoStackLength>0,...Bn(!1,Vn)},{id:"drawSnap",label:"Snap",iconId:"magnet",hiddenWhen:({pluginState:e})=>!e.mode||!e.hasSnapLayers,pressedWhen:({pluginState:e})=>!!e.snap,...Bn(!0,Vn)},{id:"drawDeletePoint",label:"Delete point",iconId:"trash",enableWhen:({pluginState:e})=>{if(e.selectedVertexIndex<0)return!1;return"Polygon"===e.feature?.geometry?.type?e.numVertices>3:e.numVertices>2},hiddenWhen:({pluginState:e})=>"edit_vertex"!==e.mode,...Bn(!1,Vn)}],keyboardShortcuts:[{id:"drawAddPoint",group:"Drawing",title:"Add point (draw)",command:"<kbd>Enter</kbd>"},{id:"drawSelectPoint",group:"Drawing",title:"Select nearest point (edit)",command:"<kbd>Spacebar</kbd>"},{id:"drawSelectAdjacentPoint",group:"Drawing",title:"Select adjacent point (edit)",command:`${Gn} + <kbd>↑</kbd> <kbd>↓</kbd> <kbd>←</kbd> or <kbd>→</kbd>`},{id:"drawMovePoint",group:"Drawing",title:"Move point (edit)",command:"<kbd>↑</kbd> <kbd>↓</kbd> <kbd>←</kbd> or <kbd>→</kbd>"},{id:"drawNudgePoint",group:"Drawing",title:"Nudge point (edit)",command:"<kbd>Shift</kbd> + <kbd>↑</kbd> <kbd>↓</kbd> <kbd>←</kbd> or <kbd>→</kbd>"},{id:"drawDeletePoint",group:"Drawing",title:"Delete point (edit)",command:"<kbd>Delete</kbd>"},{id:"drawUndo",group:"Drawing",title:"Undo",command:Dn}],icons:[{id:"undo",svgContent:'<path d="M9 14 4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11"/>'},{id:"magnet",svgContent:'<path d="m12 15 4 4"/><path d="M2.352 10.648a1.205 1.205 0 0 0 0 1.704l2.296 2.296a1.205 1.205 0 0 0 1.704 0l6.029-6.029a1 1 0 1 1 3 3l-6.029 6.029a1.205 1.205 0 0 0 0 1.704l2.296 2.296a1.205 1.205 0 0 0 1.704 0l6.365-6.367A1 1 0 0 0 8.716 4.282z"/><path d="m5 8 4 4"/>'},{id:"trash",svgContent:'<path d="M10 11v6"/><path d="M14 11v6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"/><path d="M3 6h18"/><path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>'}],api:{newPolygon:Me,newLine:Re,newPoint:({appState:e,appConfig:t,pluginConfig:n,pluginState:r,mapState:i,mapProvider:o,services:s},a,l={})=>{const{dispatch:u}=r,{draw:c}=o,{eventBus:p}=s;if(!c)return;p.emit("draw:started",{mode:"draw_point"});const h=void 0===l.snapLayers?n.snapLayers??null:l.snapLayers;c.setSnapLayers(h),u({type:"SET_HAS_SNAP_LAYERS",payload:h?.length>0});const{properties:d,onGeometryChange:f,...g}=l;c._geometryValidator=f??n.onGeometryChange;const y={};le.forEach(e=>{void 0!==g[e]&&(y[e]=g[e],delete g[e])}),c.changeMode("draw_point",{container:e.layoutRefs.viewportRef.current,addVertexButtonId:`${t.id}-draw-add-point`,interfaceType:e.interfaceType,crossHair:i.crossHair,getSnapEnabled:()=>c.isSnapEnabled(),featureId:a,...g,properties:{...d,...y}}),u({type:"SET_MODE",payload:"draw_point"})},editFeature:({appState:e,appConfig:t,mapState:n,pluginConfig:r,pluginState:i,mapProvider:o,services:s},a,l={})=>{const{dispatch:u}=i,{draw:c}=o,{eventBus:p}=s;if(!c)return!1;const h=c.get(a);if(!h)return!1;c._geometryValidator=l.onGeometryChange??r.onGeometryChange;const d="Point"===h.geometry.type?"edit_point":"edit_vertex";p.emit("draw:editstart",{mode:{LineString:"edit_line",Polygon:"edit_polygon",Point:"edit_point"}[h.geometry.type]});const f=void 0===l.snapLayers?r.snapLayers??null:l.snapLayers;c.setSnapLayers(f),u({type:"SET_HAS_SNAP_LAYERS",payload:f?.length>0}),c.changeMode(d,{container:e.layoutRefs.viewportRef.current,deleteVertexButtonId:`${t.id}-draw-delete-point`,undoButtonId:`${t.id}-draw-undo`,isPanEnabled:"keyboard"!==e.interfaceType,interfaceType:e.interfaceType,scale:J[n.mapSize],featureId:a,getSnapEnabled:()=>c.isSnapEnabled()});const g=c.get(a);u({type:"SET_FEATURE",payload:{feature:g,tempFeature:g}}),u({type:"SET_MODE",payload:d});const{valid:y}=$(g,{phase:"edit-start",mode:d},{onGeometryChange:c._geometryValidator});return u({type:"SET_GEOMETRY_VALID",payload:y}),c.setInvalid?.(!y),!0},addFeature:({mapProvider:e,services:t},n)=>{const{draw:r}=e,{eventBus:i}=t;if(!r)return;const{stroke:o,fill:s,strokeWidth:a,properties:l,...u}=n,c={type:"Feature",...u,properties:{...l,...Le({stroke:o,fill:s,strokeWidth:a})}};(e=>Ne.has(e.geometry?.type)&&void 0!==e.geometry?.coordinates)(c)?(r.add(c),i.emit("draw:add",ue(c))):me.warn("addFeature: ignoring invalid GeoJSON feature",c)},setStyle:({mapProvider:e,services:t},n,r={})=>{const{draw:i}=e,{eventBus:o}=t;if(!i)return!1;if(!i.get(n))return me.warn("setStyle: no feature found for id",n),!1;const s={},a={};for(const[e,t]of Object.entries(r))(ke.has(e)?s:a)[e]=t;const l=(e=>{const t={};for(const[n,r]of Object.entries(e))void 0!==r&&(t[n]=r);return t})({...Le(s),...a});return i.setStyle(n,l),o.emit("draw:stylechange",{featureId:n,properties:l}),!0},deleteFeature:({mapProvider:e,services:t},n)=>{const{draw:r}=e,{eventBus:i}=t;r&&(r.delete(n),i.emit("draw:delete",{featureId:n}))},split:({appState:e,appConfig:t,pluginState:n,mapState:r,mapProvider:i,services:o},a,l={})=>{const{dispatch:u}=n,{draw:c}=i,{eventBus:p}=o;if(!c)return;const h=c.get(a),d=c._geometryValidator;c._geometryValidator=Rn({draw:c,dispatch:u,polygonFeature:h});const f=["stroke-inactive.cold",...l.snapLayers||[]];c.setSnapLayers(f),u({type:"SET_HAS_SNAP_LAYERS",payload:!0}),c.changeMode("draw_line",{container:e.layoutRefs.viewportRef.current,addVertexButtonId:`${t.id}-draw-add-point`,interfaceType:e.interfaceType,crossHair:r?.crossHair,getSnapEnabled:()=>c.isSnapEnabled(),featureId:In,properties:{splitter:"invalid"}});const g=()=>{c._geometryValidator=d,c.off(s.CREATE,y),c.off(s.CANCEL,m)},y=e=>{g(),c.delete(In);const t=_n(h,e);u({type:"SET_ACTION",payload:{name:"split",isValid:!!t}}),t&&p.emit("draw:split",{originalFeatureId:a,featureCollection:t})},m=()=>{g()};c.on(s.CREATE,y),c.on(s.CANCEL,m),u({type:"SET_MODE",payload:"draw_line"}),u({type:"SET_ACTION",payload:{name:"split"}})},merge:({mapProvider:e,services:t},n)=>{const{draw:r}=e,{eventBus:i}=t;if(!r)return null;const o=(e=>{let t;try{t=Pn(d(e))}catch{return null}if("Polygon"!==t?.geometry?.type)return null;const n=e[0].id??e[0].properties?.id??"poly";return p(t.geometry.coordinates,{...e[0].properties,id:n},{id:n})})(n.map(e=>r.get(e)));return o&&i.emit("draw:merge",{originalFeatureIds:n,feature:o}),o}}};var Un=Object.freeze({__proto__:null,manifest:Fn});export{s as A,re as C,j as H,se as K,Y as L,I as M,ie as S,oe as T,K as a,Ln as b,S as c,Cn as d,E as e,m as f,p as g,h,v as i,P as j,d as k,y as l,f as m,u as n,w as o,c as p,b as q,g as r,Ee as s,me as t,J as u,W as v,X as w,Z as x,$ as y,Un as z};
@@ -1 +1 @@
1
- import r from"@babel/runtime/helpers/asyncToGenerator";import e from"@babel/runtime/helpers/defineProperty";import t from"@babel/runtime/regenerator";function n(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})),t.push.apply(t,n)}return t}function o(r){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?n(Object(o),!0).forEach(function(t){e(r,t,o[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(o,e))})}return r}function i(){var e;return o(o({},arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),{},{id:"draw",load:(e=r(t.mark(function r(){var e;return t.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=1,import(/* webpackChunkName: "im-draw-plugin" */ "./im-draw-plugin.js").then(function(r){return r.z});case 1:return e=r.sent.manifest,r.abrupt("return",e);case 2:case"end":return r.stop()}},r)})),function(){return e.apply(this,arguments)})})}export{i as default};
1
+ import r from"@babel/runtime/helpers/regenerator";import e from"@babel/runtime/helpers/asyncToGenerator";import n from"@babel/runtime/helpers/objectSpread2";function t(){var t;return n(n({},arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),{},{id:"draw",load:(t=e(r().m(function e(){var n;return r().w(function(r){for(;;)switch(r.n){case 0:return r.n=1,import(/* webpackChunkName: "im-draw-plugin" */ "./im-draw-plugin.js").then(function(r){return r.z});case 1:return n=r.v.manifest,r.a(2,n)}},e)})),function(){return t.apply(this,arguments)})})}export{t as default};