@defra/interactive-map 0.0.56-alpha → 0.0.57-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.
- package/dist/esm/im-core.js +1 -1
- package/dist/umd/im-core.js +1 -1
- package/dist/umd/index.js +1 -1
- package/docs/api/button-definition.md +11 -0
- package/docs/api/context.md +2 -0
- package/docs/api.md +3 -1
- package/docs/plugins/draw.md +189 -33
- package/package.json +1 -1
- package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
- package/plugins/datasets/dist/umd/index.js +1 -1
- package/plugins/datasets/src/initialise/DatasetsInit.jsx +6 -17
- package/plugins/datasets/src/initialise/DatasetsInit.test.jsx +3 -43
- package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/esm/index.js +1 -1
- package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/umd/index.js +1 -1
- package/plugins/draw/src/DrawInit.jsx +9 -6
- package/plugins/draw/src/DrawInit.test.jsx +15 -0
- package/plugins/draw/src/adapterEvents.js +78 -44
- package/plugins/draw/src/adapters/adapterContract.test.js +3 -3
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +18 -10
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +31 -22
- package/plugins/draw/src/adapters/maplibre/drawEvents.js +2 -1
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/clickHandlers.js +13 -12
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/clickHandlers.test.js +5 -5
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/undoHandlers.js +1 -1
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/undoHandlers.test.js +2 -2
- package/plugins/draw/src/adapters/maplibre/modes/drawPointMode.js +6 -9
- package/plugins/draw/src/adapters/maplibre/modes/drawPointMode.test.js +4 -4
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.js +6 -9
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.test.js +1 -1
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode/undoHandlers.js +8 -14
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode/undoHandlers.test.js +37 -8
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode.js +11 -1
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/undoHandlers.js +14 -19
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/undoHandlers.test.js +41 -4
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode.js +12 -1
- package/plugins/draw/src/adapters/maplibre/utils/editModeEvents.js +3 -1
- package/plugins/draw/src/adapters/maplibre/utils/geometryValidation.js +9 -10
- package/plugins/draw/src/adapters/maplibre/utils/geometryValidation.test.js +5 -24
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +10 -7
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +12 -7
- package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.js +5 -0
- package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.test.js +7 -3
- package/plugins/draw/src/adapters/openlayers/draw/DrawMode.js +11 -11
- package/plugins/draw/src/adapters/openlayers/draw/DrawMode.test.js +15 -15
- package/plugins/draw/src/adapters/openlayers/edit/EditMode.js +21 -28
- package/plugins/draw/src/adapters/openlayers/edit/EditMode.test.js +26 -5
- package/plugins/draw/src/adapters/openlayers/edit/selectionState.js +5 -6
- package/plugins/draw/src/adapters/openlayers/edit/selectionState.test.js +2 -12
- package/plugins/draw/src/adapters/openlayers/edit/undoOps.js +9 -0
- package/plugins/draw/src/adapters/openlayers/edit/undoOps.test.js +7 -0
- package/plugins/draw/src/adapters/openlayers/point/drawPointMode.js +6 -9
- package/plugins/draw/src/adapters/openlayers/point/drawPointMode.test.js +3 -3
- package/plugins/draw/src/adapters/openlayers/point/editPointMode.js +18 -9
- package/plugins/draw/src/adapters/openlayers/point/editPointMode.test.js +29 -4
- package/plugins/draw/src/adapters/openlayers/point/pointOps.js +3 -2
- package/plugins/draw/src/adapters/openlayers/point/pointOps.test.js +6 -0
- package/plugins/draw/src/adapters/openlayers/point/pointSelectionState.js +3 -4
- package/plugins/draw/src/adapters/openlayers/point/pointSelectionState.test.js +2 -12
- package/plugins/draw/src/api/createNewShape.js +4 -4
- package/plugins/draw/src/api/createNewShape.test.js +1 -1
- package/plugins/draw/src/api/editFeature.js +8 -11
- package/plugins/draw/src/api/editFeature.test.js +33 -22
- package/plugins/draw/src/api/newLine.test.js +3 -3
- package/plugins/draw/src/api/newPoint.js +4 -5
- package/plugins/draw/src/api/newPoint.test.js +3 -3
- package/plugins/draw/src/api/newPolygon.test.js +3 -3
- package/plugins/draw/src/api/recheckGeometry.js +32 -0
- package/plugins/draw/src/api/recheckGeometry.test.js +55 -0
- package/plugins/draw/src/api/setGeometry.js +33 -0
- package/plugins/draw/src/api/setGeometry.test.js +48 -0
- package/plugins/draw/src/api/split.js +23 -22
- package/plugins/draw/src/api/split.test.js +33 -18
- package/plugins/draw/src/events.js +265 -77
- package/plugins/draw/src/events.test.js +708 -34
- package/plugins/draw/src/hooks/useSpatialList.js +10 -11
- package/plugins/draw/src/hooks/useSpatialList.test.js +3 -3
- package/plugins/draw/src/manifest.js +30 -15
- package/plugins/draw/src/manifest.test.js +91 -9
- package/plugins/draw/src/reducer.js +31 -9
- package/plugins/draw/src/reducer.test.js +35 -3
- package/plugins/draw/src/utils/drawModes.js +27 -0
- package/plugins/draw/src/utils/drawModes.test.js +27 -0
- package/plugins/draw/src/utils/needsDrawTarget.js +1 -5
- package/plugins/draw/src/utils/needsDrawTarget.test.js +1 -11
- package/plugins/draw/src/utils/touchTarget.js +34 -26
- package/plugins/draw/src/utils/touchTarget.test.js +32 -20
- package/plugins/draw/src/validation/commitChecks.js +185 -0
- package/plugins/draw/src/validation/commitChecks.test.js +205 -0
- package/plugins/draw/src/validation/liveDrawChecks.js +11 -11
- package/plugins/draw/src/validation/liveDrawChecks.test.js +37 -37
- package/plugins/draw/src/validation/liveStroke.js +6 -6
- package/plugins/draw/src/validation/liveStroke.test.js +27 -27
- package/plugins/draw/src/validation/rules.js +16 -14
- package/plugins/draw/src/validation/rules.test.js +5 -5
- package/plugins/draw/src/validation/validateGeometry.js +58 -31
- package/plugins/draw/src/validation/validateGeometry.test.js +68 -44
- package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/umd/index.js +1 -1
- package/plugins/interact/src/hooks/useInteractionHandlers.js +3 -5
- package/plugins/interact/src/hooks/useInteractionHandlers.test.js +4 -3
- package/plugins/interact/src/hooks/useSpatialList.js +16 -17
- package/plugins/interact/src/hooks/useSpatialList.test.js +9 -9
- package/plugins/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
- package/plugins/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
- package/plugins/map-styles/src/MapStyles.jsx +2 -2
- package/providers/maplibre/dist/esm/index.js +1 -1
- package/providers/maplibre/dist/umd/index.js +1 -1
- package/providers/maplibre/src/index.js +11 -2
- package/providers/maplibre/src/index.test.js +23 -1
- package/providers/maplibre/src/utils/detectModuleWorker.js +8 -19
- package/providers/maplibre/src/utils/detectModuleWorker.test.js +19 -23
- package/providers/maplibre/src/utils/workerUrl.js +12 -0
- package/providers/maplibre/src/utils/workerUrl.test.js +14 -1
- package/src/App/components/MapButton/MapButton.jsx +6 -0
- package/src/App/components/MapButton/MapButton.test.jsx +10 -0
- package/src/App/components/Markers/Markers.jsx +3 -5
- package/src/App/components/Markers/Markers.test.jsx +9 -11
- package/src/App/components/Panel/Panel.jsx +2 -9
- package/src/App/hooks/useInterfaceAPI.js +16 -4
- package/src/App/hooks/useInterfaceAPI.test.js +66 -1
- package/src/App/renderer/mapButtons.js +2 -1
- package/src/App/renderer/mapButtons.test.js +9 -0
- package/src/App/store/MapProvider.jsx +3 -0
- package/src/App/store/MapProvider.test.jsx +24 -0
- package/src/config/mapSizeScales.js +3 -0
- package/src/types.js +4 -0
- package/src/utils/focusAfterPanelClose.js +9 -0
- package/src/utils/focusAfterPanelClose.test.js +40 -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 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
|
+
import{useRef as e,useEffect as t,useLayoutEffect as n}from"preact/compat";const r=new Set(["draw_polygon","draw_line"]),i=new Set(["draw_polygon","draw_line","draw_point"]),o=new Set(["edit_vertex","edit_point"]),s=new Set(["draw_polygon","draw_line","edit_vertex","edit_point"]),a=new Set(["draw_polygon","draw_line","draw_point","edit_vertex","edit_point"]),l=e=>r.has(e),u=e=>i.has(e),c=e=>o.has(e),p=e=>s.has(e),h={SET_MODE:(e,t)=>({...e,mode:t,numVertices:l(t)?0:e.numVertices,validationStatus:"idle",checkSlow:!1,holding:!1,previewValid:!0,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_VALIDATION_STATUS:(e,t)=>({...e,validationStatus:t,checkSlow:!1}),SET_CHECK_SLOW:e=>({...e,checkSlow:!0}),SET_HOLDING:(e,t)=>({...e,holding:!!t}),SET_PREVIEW_VALID:(e,t)=>({...e,previewValid:!!t}),SET_CAN_ADD_POINT:(e,t)=>({...e,canAddPoint:!!t})},d={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"},f="change",g={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 y=6371008.8,m={centimeters:637100880,centimetres:637100880,degrees:360/(2*Math.PI),feet:20902260.511392,inches:39.37*y,kilometers:6371.0088,kilometres:6371.0088,meters:y,metres:y,miles:3958.761333810546,millimeters:6371008800,millimetres:6371008800,nauticalmiles:y/1852,radians:1,yards:6967335.223679999};function v(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 E(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(!C(e[0])||!C(e[1]))throw new Error("coordinates must contain numbers");return v({type:"Point",coordinates:e},t,n)}function S(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 v({type:"Polygon",coordinates:e},t,n)}function w(e,t,n={}){if(e.length<2)throw new Error("coordinates must be an array of two or more positions");return v({type:"LineString",coordinates:e},t,n)}function b(e,t={}){const n={type:"FeatureCollection"};return t.id&&(n.id=t.id),t.bbox&&(n.bbox=t.bbox),n.features=e,n}function P(e,t,n={}){return v({type:"MultiLineString",coordinates:e},t,n)}function x(e,t="kilometers"){const n=m[t];if(!n)throw new Error(t+" units is invalid");return e*n}function _(e,t="kilometers"){const n=m[t];if(!n)throw new Error(t+" units is invalid");return e/n}function T(e){return 180*(e%(2*Math.PI))/Math.PI}function A(e){return e%360*Math.PI/180}function C(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}function I(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 v=0;v<a;v++){var E=0,S=0;if(null!==(s=c?u.geometries[v]:u)){l=s.coordinates;var w=s.type;switch(p=0,w){case null:break;case"Point":if(!1===t(l,h,m,E,S))return!1;h++,E++;break;case"LineString":case"MultiPoint":for(r=0;r<l.length;r++){if(!1===t(l[r],h,m,E,S))return!1;h++,"MultiPoint"===w&&E++}"LineString"===w&&E++;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,E,S))return!1;h++}"MultiLineString"===w&&E++,"Polygon"===w&&S++}"Polygon"===w&&E++;break;case"MultiPolygon":for(r=0;r<l.length;r++){for(S=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,E,S))return!1;h++}S++}E++}break;case"GeometryCollection":for(r=0;r<s.geometries.length;r++)if(!1===I(s.geometries[r],t))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function L(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 M(e){var t=[];return I(e,function(e){t.push(e)}),t}function k(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 R(e,t){k(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(v(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 u=e.coordinates[l];if(!1===t(v({type:s,coordinates:u},r),n,l))return!1}})}function N(e){let t=0;if(e&&e.length>0){t+=Math.abs(D(e[0]));for(let n=1;n<e.length;n++)t-=Math.abs(D(e[n]))}return t}var O=20294876564838.72,G=Math.PI/180;function D(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]*G,l=o[1]*G;n+=(s[0]*G-a)*Math.sin(l),r++}return n*O}var V=function(e){return function(e,t,n){var r=n;return k(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 N(e.coordinates);case"MultiPolygon":for(t=0;t<e.coordinates.length;t++)n+=N(e.coordinates[t]);return n;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}(t),0)};const B={Polygon:3,LineString:2},F=e=>e?.geometry??e,U=e=>{const t=F(e);return"Polygon"===t?.type?t:null},H=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},q=e=>[...e,e[0]],j=(e,t,n)=>(t[0]-e[0])*(n[1]-e[1])-(t[1]-e[1])*(n[0]-e[0]),z=(e,t)=>e>0&&t<0||e<0&&t>0,W=(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),Y=(e,t,n,r)=>{const i=j(n,r,e),o=j(n,r,t),s=j(e,t,n),a=j(e,t,r);return!(!z(i,o)||!z(s,a))||(W(i,n,e,r)||W(o,n,t,r)||W(s,e,n,t)||W(a,e,r,t))},$=(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)&&Y(e[i],e[(i+1)%n],e[o],e[(o+1)%n]))return!0}return!1},K=e=>{const t=U(e);if(!t)return{valid:!0};const n=H(t);return n.length<4?{valid:!0}:$(n,!0)?{valid:!1,reason:"Shape must not intersect itself"}:{valid:!0}},X=e=>{const t=U(e);if(!t)return{valid:!0};const n=H(t);if(n.length<B.Polygon)return{valid:!0};let r=0;try{r=V({type:"Feature",geometry:{type:"Polygon",coordinates:[q(n)]},properties:{}})}catch{return{valid:!0}}return r>0?{valid:!0}:{valid:!1,reason:"Shape must enclose an area"}},Z={Polygon:"Shape needs at least 3 points",LineString:"Line needs at least 2 points"},J=[K,X,e=>{const t=F(e);return"Polygon"===t?.type?H(t).length>=B.Polygon?{valid:!0}:{valid:!1,reason:Z.Polygon}:"LineString"===t?.type?(t.coordinates?.length??0)>=B.LineString?{valid:!0}:{valid:!1,reason:Z.LineString}:{valid:!0}}],Q=[K,X],ee=[e=>(e=>{const t=U(e);if(!t)return!1;const n=H(t);return!(n.length<4)&&$(n,!1)})(e)?{valid:!1,reason:"Shape must not intersect itself"}:{valid:!0}],te=e=>{if(void 0===e||!0===e)return{valid:!0};if(!1===e)return{valid:!1,reason:null};const{valid:t,reason:n,announcement:r,recheckOnFinish:i}=e;return{valid:!1!==t,reason:n,...r&&{announcement:r},...i&&{recheckOnFinish:!0}}},ne=(e,t)=>e.valid?e:{...e,source:t},re=(e,t={},n={})=>{const{rules:r=J,onGeometryPreview:i}=n;for(const n of r){const r=te(n(e,t));if(!r.valid)return ne(r,"rules")}return"function"==typeof i?ne(te(i({feature:e,...t})),"callback"):{valid:!0}},ie=(e,t={},n={})=>{const{rules:r=ee,onGeometryPreview:i}=n;return re(e,{...t,phase:"place"},{rules:r,onGeometryPreview:i})},oe={Polygon:"draw_polygon",LineString:"draw_line"},se=(e,{reason:t,source:n,announcement:r},{mode:i,vertexIndex:o})=>({feature:e,reason:t??null,source:n,...r&&{announcement:r},phase:"place",mode:i,vertexIndex:o}),ae=({placed:e,point:t,geometryType:n,onGeometryPreview:r})=>{const i=[...e,t],o={type:"Feature",geometry:"Polygon"===n?{type:"Polygon",coordinates:[i]}:{type:"LineString",coordinates:i},properties:{}},s=oe[n],a=e.length,l=ie(o,{mode:s,vertexIndex:a},{onGeometryPreview:r});return l.valid?{valid:!0}:{valid:!1,blocked:se(o,l,{mode:s,vertexIndex:a})}},le=(e,t={},n={})=>{const{rules:r=Q,onGeometryPreview:i}=n,o=B[e?.geometry?.type??e?.type]??0,s=(t.numVertices??0)<o?[]:r;return re(e,{...t,phase:t.phase??"preview"},{rules:s,onGeometryPreview:i})},ue="[interactive-map]",ce={warn:(...e)=>console.warn(ue,...e),error:(...e)=>console.error(ue,...e)},pe=new Set(["symbol","symbolSvgContent","symbolViewBox","symbolAnchor","symbolSize","symbolBackgroundColor","symbolForegroundColor","symbolHaloWidth","symbolGraphic"]),he=e=>{if(!e?.properties)return e;const t={};for(const[n,r]of Object.entries(e.properties)){"sortKey"===n||n.startsWith("symbol")&&!pe.has(n)||(t[n]=r)}return{...e,properties:t}},de={revision:0,status:"idle",result:null,feature:null,context:null,slow:!1,afterPending:!1},fe=e=>e.valid?"valid":"invalid",ge=new WeakMap,ye=e=>{let t=ge.get(e);return t||(t=(()=>{let e=0,t=null,n=null,r=null,i=de,o=null,s=null;const a=()=>{r?.abort(),r=null,clearTimeout(n)},l=(s,a)=>{if(s!==e)return;"pending"!==a.status&&(r=null,clearTimeout(n));const l=!!a.slow,u="pending"!==a.status&&t===s;t=l?s:null,i={...a,revision:s,slow:l,afterPending:u},o?.(i)};return{get state(){return i},setOnSettle(e){o=e},get heldId(){return s?.revision===e?s.id:void 0},hold(t){s={id:t,revision:e}},release(){s=null},run({feature:t,context:i,onGeometryChange:o,rules:s=J}){a(),e++;const u=e,c={feature:t,context:i},p=re(t,i,{rules:s});if(!p.valid||"function"!=typeof o)return void l(u,{...c,status:fe(p),result:p});r=new AbortController;const h=t=>{u===e&&(ce.warn("[draw] onGeometryChange failed",t),l(u,{...c,status:"error",result:{valid:!1,reason:null,source:"callback"},error:t}))};let d;try{d=o({feature:t,...i},{signal:r.signal,revision:u})}catch(e){return void h(e)}const f=e=>{const t=ne(te(e),"callback");l(u,{...c,status:fe(t),result:t})};var g;g=d,"function"==typeof g?.then?(l(u,{...c,status:"pending",result:null}),n=setTimeout(()=>l(u,{...c,status:"pending",result:null,slow:!0}),300),d.then(f,h)):f(d)},reset(){const t=s?.revision===e?s.id:void 0;return a(),e++,i=de,s=null,t}}})(),ge.set(e,t)),t},me=e=>{const t=e[0],n=e[e.length-1];return e.length>1&&t[0]===n[0]&&t[1]===n[1]?e.slice(0,-1):e},ve=e=>"Polygon"===e.type?e.coordinates.map(me):e.coordinates,Ee=(e,t={},n={},r=null)=>{e._previewValidator=t.onGeometryPreview??n.onGeometryPreview,e._commitValidator=t.onGeometryChange??n.onGeometryChange;const i=ye(e).reset();if(void 0!==i){const t=e.get(i);e.delete(i),r?.emit("draw:cancelled",he(t))}},Se="draw:created",we=new WeakMap,be=new WeakMap,Pe=new Set(["create","edit-finish"]),xe=({result:e,context:t})=>!!e?.recheckOnFinish&&!Pe.has(t?.phase),_e=(e,t)=>({announcement:n,...r})=>{var i;e.emit("draw:geometryinvalid",r),n||!r.reason||(i=r.reason,Object.values(Z).includes(i))||t.show(r.reason)},Te=({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}}),Ae={pending:"Checking shape",valid:"Shape check passed",invalid:"Shape check failed",error:"Shape could not be checked"},Ce=({draw:e,dispatch:t,emitGeometryInvalid:n,announce:r})=>i=>{const{status:o,result:s,context:a,feature:l}=i,u="valid"===o;if(t(i.slow?{type:"SET_CHECK_SLOW"}:{type:"SET_VALIDATION_STATUS",payload:o}),((e,{status:t,result:n,slow:r,afterPending:i})=>{n?.announcement?e?.(n.announcement,"action"):"pending"===t?r&&e?.(Ae.pending,"action"):i&&e?.("invalid"===t&&n.reason||Ae[t],"action")})(r,i),e.setCanFinish?.(u||"pending"===o),"pending"!==o&&"error"!==o&&(c(e.getMode())&&e.setInvalid?.(!u),!u&&"edit-start"!==a?.phase)){const{reason:e,source:t,announcement:r}=s;n({reason:e,source:t,announcement:r,...a,feature:he(l)})}};function Ie({appState:e,appConfig:t,mapState:n,draw:r,dispatch:i,eventBus:o,resetState:s}){const a=ye(r),l=e=>{s(),setTimeout(()=>r.changeMode("disabled"),0),o.emit(Se,he(e))},u=(s,a)=>{we.set(r,s),setTimeout(()=>(({draw:e,appState:t,appConfig:n,mapState:r,dispatch:i,eventBus:o},s,a)=>{const l="Point"===a?"edit_point":"edit_vertex";e.changeMode(l,{container:t?.layoutRefs?.viewportRef?.current,deleteVertexButtonId:`${n?.id}-draw-delete-point`,undoButtonId:`${n?.id}-draw-undo`,isPanEnabled:"keyboard"!==t?.interfaceType,interfaceType:t?.interfaceType,scale:r?.mapSizeScale,featureId:s,getSnapEnabled:()=>e.isSnapEnabled()});const u=e.get(s),{status:c,result:p}=ye(e).state;i({type:"SET_FEATURE",payload:{feature:u,tempFeature:u}}),i({type:"SET_MODE",payload:l}),i({type:"SET_VALIDATION_STATUS",payload:c}),e.setCanFinish?.("valid"===c||"pending"===c),e.setInvalid?.("invalid"===c),o.emit("draw:reopened",{feature:he(u),status:c,reason:p?.reason??null})})({draw:r,appState:e,appConfig:t,mapState:n,dispatch:i,eventBus:o},s,a),0)},c=e=>{const{status:t,feature:n}=a.state;return("valid"===t||"pending"===t)&&((e,t)=>{const n=e?.geometry,r=t?.geometry;return!(!n||!r||n.type!==r.type)&&JSON.stringify(ve(n))===JSON.stringify(ve(r))})(n,e)&&!xe(a.state)||a.run({feature:e,context:{phase:"create",mode:r.getMode()},onGeometryChange:r._commitValidator}),a.state},p=e=>{const t=c(e);var n;"valid"===t.status?l(e):"pending"===t.status?(n=e.id,a.hold(n),i({type:"SET_HOLDING",payload:!0}),setTimeout(()=>r.changeMode("disabled"),0)):u(e.id,e.geometry?.type)};return{onCreate:p,onCheckSettled:e=>{const t=a.heldId;if(void 0===t||"pending"===e.status)return;a.release();const n=r.get(t);xe(e)?p(n):"valid"===e.status?l(n):u(t,n?.geometry?.type)},onEditFinish:e=>{s(),setTimeout(()=>r.changeMode("disabled"),0),we.get(r)===e.id?(we.delete(r),o.emit(Se,he(e))):o.emit("draw:edited",he(e))}}}function Le({draw:e,dispatch:t}){const n=ye(e),r=n=>{be.set(e,n),t({type:"SET_HOLDING",payload:!0})},i=i=>{if("pending"===i.status)return void r(i.revision);if(!xe(i))return void e.done();n.run({feature:i.feature,context:{phase:"edit-finish",mode:e.getMode()},onGeometryChange:e._commitValidator});const o=n.state;"pending"===o.status?r(o.revision):"valid"===o.status?e.done():t({type:"SET_HOLDING",payload:!1})};return{handleDone:()=>{c(e.getMode())?i(n.state):e.done()},onEditCheckSettled:n=>{if(!be.has(e))return;const r=be.get(e)===n.revision;r&&"pending"===n.status||(be.delete(e),r&&"valid"===n.status?i(n):t({type:"SET_HOLDING",payload:!1}))}}}function Me({appState:e,appConfig:t,mapState:n,pluginState:r,mapProvider:i,buttonConfig:o,eventBus:s,hints:a,announce:l}){const{draw:u}=i,h=_e(s,a),d=function({appState:e,appConfig:t,mapState:n,pluginState:r,mapProvider:i,eventBus:o,emitGeometryInvalid:s,announce:a,resetState:l}){const{draw:u}=i,{feature:h,tempFeature:d}=r,{dispatch:f}=r,g=ye(u);return{...Le({draw:u,dispatch:f}),handleCancel:()=>{const e=u.getMode(),t=c(e)&&!!d?.id,n=t&&we.get(u)===d.id,r=g.heldId??(n?d.id:void 0);t&&!n&&u.add(h),we.delete(u),g.release(),u.cancel(),void 0!==r&&u.delete(r),l(),o.emit("draw:cancelled",he(h))},handleUndo:()=>u.undo(),handleDeleteVertex:()=>u.deleteVertex(),handleSnap:()=>{r.dispatch({type:"TOGGLE_SNAP"}),u.setSnapEnabled(!r.snap)},onCancel:()=>{g.reset()},...Ie({appState:e,appConfig:t,mapState:n,draw:u,dispatch:f,eventBus:o,resetState:l}),...Te({draw:u,pluginState:r,mapProvider:i,eventBus:o}),onUndoChange:e=>{r.dispatch({type:"SET_UNDO_STACK_LENGTH",payload:e})},onUpdate:e=>{o.emit("draw:updated",he(e))},onGeometryChange:e=>{if(!e?.phase)return;const t=u.getMode();p(t)&&g.run({feature:e.feature,context:{phase:e.phase,vertexIndex:e.vertexIndex,mode:t},onGeometryChange:u._commitValidator})},onPlacementBlocked:e=>{e.announcement&&a?.(e.announcement,"action"),s({...e,feature:he(e.feature)})},onValidityChange:e=>{r.dispatch({type:"SET_PREVIEW_VALID",payload:e.valid})},onCanPlaceChange:e=>{r.dispatch({type:"SET_CAN_ADD_POINT",payload:e.canPlace})},onInterfaceTypeChange:e=>{o.emit("draw:interfacetypechange",{interfaceType:e.interfaceType})}}}({appState:e,appConfig:t,mapState:n,pluginState:r,mapProvider:i,eventBus:s,emitGeometryInvalid:h,announce:l,resetState:()=>{r.dispatch({type:"SET_MODE",payload:null}),r.dispatch({type:"SET_FEATURE",payload:{feature:null,tempFeature:null}}),i.activeMoveTarget=null,ye(u).reset(),be.delete(u)}}),f=ye(u),y=Ce({draw:u,dispatch:r.dispatch,emitGeometryInvalid:h,announce:l});return f.setOnSettle(e=>{y(e),d.onCheckSettled(e),d.onEditCheckSettled(e)}),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,d),function(e,t){e.on(g.CREATE,t.onCreate),e.on(g.EDIT_FINISH,t.onEditFinish),e.on(g.CANCEL,t.onCancel),e.on(g.VERTEX_SELECTION,t.onVertexSelection),e.on(g.VERTEX_CHANGE,t.onVertexChange),e.on(g.UNDO_CHANGE,t.onUndoChange),e.on(g.UPDATE,t.onUpdate),e.on(g.GEOMETRY_CHANGE,t.onGeometryChange),e.on(g.PLACEMENT_BLOCKED,t.onPlacementBlocked),e.on(g.VALIDITY_CHANGE,t.onValidityChange),e.on(g.CAN_PLACE_CHANGE,t.onCanPlaceChange),e.on(g.INTERFACE_TYPE_CHANGE,t.onInterfaceTypeChange)}(u,d),()=>{f.setOnSettle(null),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(g.CREATE,t.onCreate),e.off(g.EDIT_FINISH,t.onEditFinish),e.off(g.CANCEL,t.onCancel),e.off(g.VERTEX_SELECTION,t.onVertexSelection),e.off(g.VERTEX_CHANGE,t.onVertexChange),e.off(g.UNDO_CHANGE,t.onUndoChange),e.off(g.UPDATE,t.onUpdate),e.off(g.GEOMETRY_CHANGE,t.onGeometryChange),e.off(g.PLACEMENT_BLOCKED,t.onPlacementBlocked),e.off(g.VALIDITY_CHANGE,t.onValidityChange),e.off(g.CAN_PLACE_CHANGE,t.onCanPlaceChange),e.off(g.INTERFACE_TYPE_CHANGE,t.onInterfaceTypeChange)}(u,d)}}const ke="edit_vertex",Re="draw",Ne=(e,t,n)=>{const{x:r,y:i}=e.mapToScreen(n);return{x:r*t,y:i*t}},Oe=(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,...Ne(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,...Ne(e,t,r)}))(r[s],s))}),i};function Ge({mapState:n,pluginState:r,services:i,mapProvider:o,spatialListRegistry:s,viewportRef:a}){const{mapSizeScale:l}=n,{eventBus:u,announce:c}=i,p=e([]),h=e(null);!function({pluginState:e,mapProvider:n,mapSizeScale:r,spatialListRegistry:i,itemsRef:o,eventBus:s}){t(()=>{const t=()=>{o.current=e.mode===ke?Oe(n,r):[],i.notifyItemsChanged(Re)};t(),s.on(d.MAP_MOVE_END,t);const{draw:a}=n;return a?(a.on(g.UPDATE,t),()=>{s.off(d.MAP_MOVE_END,t),a.off(g.UPDATE,t)}):()=>s.off(d.MAP_MOVE_END,t)},[e.mode,n,r,i,o,s]),t(()=>(i.registerItemProvider(Re,{getItems:()=>({items:o.current,multiselectable:!1,label:"Shape points",focusable:!1}),exclusive:!0}),()=>{i.unregisterItemProvider(Re)}),[i,o]),t(()=>{if(e.mode===ke)return i.claimExclusive(Re),()=>i.releaseExclusive(Re)},[e.mode,i])}({pluginState:r,mapProvider:o,mapSizeScale:l,spatialListRegistry:s,itemsRef:p,eventBus:u}),function({eventBus:e,mapProvider:n,pluginState:r,activeIdRef:i}){t(()=>{const t=({id:e})=>{i.current=e,null!==e&&r.mode===ke&&n.draw?.selectVertex?.(Number(e))};return e.on(d.MAP_SET_ACTIVE_ITEM,t),()=>{e.off(d.MAP_SET_ACTIVE_ITEM,t)}},[e,n,r.mode,i])}({eventBus:u,mapProvider:o,pluginState:r,activeIdRef:h}),function({eventBus:e,mapProvider:n,pluginState:r,activeIdRef:i,itemsRef:o,viewportRef:s,announce:a}){t(()=>{const t=()=>{if(r.mode!==ke||null===i.current)return;const e=o.current.find(e=>e.id===i.current);e&&(e.isMidpoint?(n.draw?.insertVertexAtMidpoint?.(Number(i.current)),a("New point inserted","action")):a(`${e.label} selected`,"action"),s.current?.focus())};return e.on(d.MAP_SELECT_ITEM,t),()=>{e.off(d.MAP_SELECT_ITEM,t)}},[e,n,r.mode,i,o,s,a])}({eventBus:u,mapProvider:o,pluginState:r,activeIdRef:h,itemsRef:p,viewportRef:a,announce:c})}const De={small:1,medium:1.5,large:2},Ve="rgba(29,112,184,1)",Be="#ffffff",Fe="rgba(11,12,12,1)",Ue="rgba(212,53,28,0.5)",He={editStroke:{light:Ve,dark:Be},editFill:{light:"rgba(29,112,184,0.1)",dark:"rgba(255,255,255,0.1)"},editVertex:{light:Ve,dark:Be},editMidpoint:{light:Ve,dark:Be},editHalo:{light:Be,dark:Fe},editActive:{light:Fe,dark:Be},splitInvalid:{light:Ve,dark:Be},splitValid:{light:Ve,dark:Be},invalidStroke:{light:Ve,dark:Be},shapeStroke:"rgba(212,53,28,1)",shapeFill:Ue,snapVertex:Ue,snapMidpoint:"rgba(40,161,151,1)",snapEdge:"rgba(29,112,184,0.5)"},qe={strokeWidth:2,vertexRadius:6,midpointRadius:4,vertexHaloRadius:8,midpointHaloRadius:6,touchTargetSize:48},je={snapRadius:12},ze={nudgeAmount:1,stepAmount:5},We="draw",Ye=({appState:e,pluginState:t})=>u(t.mode)&&("touch"===e.interfaceType||!!e.expandedButtons?.has("mapControls"));function $e({mapState:n,pluginConfig:r,pluginState:i,mapProvider:o,eventBus:s,symbolRegistry:a}){const l=e(!0),u=e(!1);t(()=>{if(!n.isMapReady||u.current)return;u.current=!0;(async()=>{if(await new Promise(e=>setTimeout(e,0)),!l.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}"`)}})(o,{mapStyle:n.mapStyle,snapLayers:r.snapLayers,pluginConfig:r,events:d,eventBus:s,symbolRegistry:a});l.current?(o.draw=e,i.dispatch({type:"SET_HAS_SNAP_LAYERS",payload:r.snapLayers?.length>0}),s.emit("draw:ready")):e.remove()})().catch(e=>ce.error("[draw] failed to load the draw adapter",e))},[n.isMapReady]),t(()=>()=>{l.current=!1,o.draw?.remove(),o.draw=null,o.activeMoveTarget=null},[])}const Ke=new Set(["stroke","fill","strokeWidth"]),Xe=e=>{if(!e)return{};const t={};for(const[n,r]of Object.entries(e))if(Ke.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},Ze=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;const{stroke:d,fill:f,strokeWidth:g,properties:y,onGeometryChange:m,onGeometryPreview:v,...E}=u;Ee(p,{onGeometryChange:m,onGeometryPreview:v},r,h),h.emit("draw:started",{mode:e,featureId:l});const S=void 0===u.snapLayers?r.snapLayers??null:u.snapLayers;p.setSnapLayers(S),c({type:"SET_HAS_SNAP_LAYERS",payload:S?.length>0});const w={...y,...Xe({stroke:d,fill:f,strokeWidth:g})};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,...E,properties:w}),c({type:"SET_MODE",payload:e})},Je=Ze("draw_polygon"),Qe=Ze("draw_line"),et=new Set(["Point","LineString","Polygon"]),tt=new Set(["stroke","fill","strokeWidth"]);function nt(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return rt(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 rt(e)}),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return ot(e);default:throw new Error("unknown GeoJSON type")}}function rt(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=it(e.properties),t.geometry=ot(e.geometry),t}function it(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]=it(r):t[n]=r}),t):t}function ot(e){var t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(function(e){return ot(e)}),t):(t.coordinates=st(e.coordinates),t)}function st(e){var t=e;return"object"!=typeof t[0]?t.slice():t.map(function(e){return st(e)})}function at(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 lt(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 ut(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=nt(e));var o=[];switch(e.type){case"GeometryCollection":return k(e,function(e){ct(e,r)}),e;case"FeatureCollection":return L(e,function(e){L(ct(e,r),function(e){o.push(e)})}),b(o)}return ct(e,r)}function ct(e,t){switch("Feature"===e.type?e.geometry.type:e.type){case"GeometryCollection":return k(e,function(e){ct(e,t)}),e;case"LineString":return pt(lt(e),t),e;case"Polygon":return ht(lt(e),t),e;case"MultiLineString":return lt(e).forEach(function(e){pt(e,t)}),e;case"MultiPolygon":return lt(e).forEach(function(e){ht(e,t)}),e;case"Point":case"MultiPoint":return e}}function pt(e,t){at(e)===t&&e.reverse()}function ht(e,t){at(e[0])!==t&&e[0].reverse();for(var n=1;n<e.length;n++)at(e[n])===t&&e[n].reverse()}const dt=11102230246251565e-32,ft=134217729,gt=(3+8*dt)*dt;function yt(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 mt(e){return new Float64Array(e)}const vt=mt(4),Et=mt(8),St=mt(12),wt=mt(16),bt=mt(4);function Pt(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,v,E,S,w,b,P,x;const _=e-i,T=n-i,A=t-o,C=r-o;S=_*C,h=ft*_,d=h-(h-_),f=_-d,h=ft*C,g=h-(h-C),y=C-g,w=f*y-(S-d*g-f*g-d*y),b=A*T,h=ft*A,d=h-(h-A),f=A-d,h=ft*T,g=h-(h-T),y=T-g,P=f*y-(b-d*g-f*g-d*y),m=w-P,p=w-m,vt[0]=w-(m+p)+(p-P),v=S+m,p=v-S,E=S-(v-p)+(m-p),m=E-b,p=E-m,vt[1]=E-(m+p)+(p-b),x=v+m,p=x-v,vt[2]=v-(x-p)+(m-p),vt[3]=x;let I=function(e,t){let n=t[0];for(let r=1;r<e;r++)n+=t[r];return n}(4,vt),L=22204460492503146e-32*s;if(I>=L||-I>=L)return I;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 I;if(L=11093356479670487e-47*s+gt*Math.abs(I),I+=_*c+C*a-(A*u+T*l),I>=L||-I>=L)return I;S=a*C,h=ft*a,d=h-(h-a),f=a-d,h=ft*C,g=h-(h-C),y=C-g,w=f*y-(S-d*g-f*g-d*y),b=l*T,h=ft*l,d=h-(h-l),f=l-d,h=ft*T,g=h-(h-T),y=T-g,P=f*y-(b-d*g-f*g-d*y),m=w-P,p=w-m,bt[0]=w-(m+p)+(p-P),v=S+m,p=v-S,E=S-(v-p)+(m-p),m=E-b,p=E-m,bt[1]=E-(m+p)+(p-b),x=v+m,p=x-v,bt[2]=v-(x-p)+(m-p),bt[3]=x;const M=yt(4,vt,4,bt,Et);S=_*c,h=ft*_,d=h-(h-_),f=_-d,h=ft*c,g=h-(h-c),y=c-g,w=f*y-(S-d*g-f*g-d*y),b=A*u,h=ft*A,d=h-(h-A),f=A-d,h=ft*u,g=h-(h-u),y=u-g,P=f*y-(b-d*g-f*g-d*y),m=w-P,p=w-m,bt[0]=w-(m+p)+(p-P),v=S+m,p=v-S,E=S-(v-p)+(m-p),m=E-b,p=E-m,bt[1]=E-(m+p)+(p-b),x=v+m,p=x-v,bt[2]=v-(x-p)+(m-p),bt[3]=x;const k=yt(M,Et,4,bt,St);S=a*c,h=ft*a,d=h-(h-a),f=a-d,h=ft*c,g=h-(h-c),y=c-g,w=f*y-(S-d*g-f*g-d*y),b=l*u,h=ft*l,d=h-(h-l),f=l-d,h=ft*u,g=h-(h-u),y=u-g,P=f*y-(b-d*g-f*g-d*y),m=w-P,p=w-m,bt[0]=w-(m+p)+(p-P),v=S+m,p=v-S,E=S-(v-p)+(m-p),m=E-b,p=E-m,bt[1]=E-(m+p)+(p-b),x=v+m,p=x-v,bt[2]=v-(x-p)+(m-p),bt[3]=x;const R=yt(k,St,4,bt,wt);return wt[R-1]}(e,t,n,r,i,o,u)}function xt(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=Pt(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 _t=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},Tt=function(e){this.p=e},At=function(e,t){this.id=e,this.rawCoords=t};function Ct(e,t){return!(e.maxX<t[0])&&(!(e.minX>t[2])&&(!(e.maxY<t[1])&&!(e.minY>t[3])))}var It=function(e,t,n,r){this.p=e,this.polylineEdge=t,this.polygonEdge=n,this.isHeadingIn=r,this.distanceFromPolylineEdgeStart=Lt(this.polylineEdge.p1.p,this.p),this.distanceFromPolygonEdgeStart=Lt(this.polygonEdge.p1.p,this.p),this.polygonEdge.intersectionPoints.push(this),this.polylineEdge.intersectionPoints.push(this),this.visitCount=0};function Lt(e,t){var n=t[0]-e[0],r=t[1]-e[1];return n*=n,r*=r,Math.sqrt(n+r)}It.prototype.incrementVisitCount=function(){this.visitCount=this.visitCount+1};var Mt=1e-9;function kt(e,t){return e[0]*t[1]-e[1]*t[0]}function Rt(e,t){return e[0]*t[0]+e[1]*t[1]}function Nt(e,t,n){return[e[0]+t*n[0],e[1]+t*n[1]]}function Ot(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=kt(r,i),a=s*s,l=Rt(r,r);if(a>0){var u=kt(o,i)/s;if(u<0||u>1)return null;var c=kt(o,r)/s;return c<0||c>1?null:0===u||1===u?[Nt(e.p1.p,u,r)]:0===c||1===c?[Nt(t.p1.p,c,i)]:[Nt(e.p1.p,u,r)]}var p=Rt(o,o);if((a=(s=kt(o,r))*s)>Mt*l*p)return null;var h=Rt(r,o)/l,d=h+Rt(r,i)/l,f=Math.min(h,d),g=Math.max(h,d);return f<=1&&g>=0?1===f?[Nt(e.p1.p,f>0?f:0,r)]:0===g?[Nt(e.p1.p,g<1?g:1,r)]:[Nt(e.p1.p,f>0?f:0,r),Nt(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 Tt(l[c][0]),d=null,f={nextEdge:null},g=0;g<p;g++){d=new Tt(l[c][g+1]),h.nextPoint=d,d.prevPoint=h;var y=new _t(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,v="Polygon"===m.type?[m.coordinates]:m.coordinates,E=v.length,S=0;S<E;S++)for(var w=v[S].length,b=0;b<w;b++){o+=1;var P=v[S][b],x=P.length;s.push(new At(o,P));for(var _=new Tt(P[0]),T=_,A=void 0,C=null,I={nextEdge:null,prevEdge:null},L=null,M=1;M<x;M++)A=new Tt(P[M]),T.nextPoint=A,A.prevPoint=T,C=new _t(T,A,"polygon",u,o),I.nextEdge=C,C.prevEdge=I,1===M&&(L=C),b>0&&(C.interiorRing=!0),C.intersectPolylineBbox=Ct(C,i),n.push(C),T=A,u+=1,I=C;C.nextEdge=L,L.prevEdge=C,A.nextPoint=_.nextPoint,_.prevPoint=A.prevPoint}return s}(ut(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=Ot(l,u);if(null!==c)for(o=0;o<c.length;o++){var p=Pt(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 It(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 v=Ft(h,m),E=!1;if(v===(d=v)&&2===n.length)for(var S=0;S<n.length;S++){n[S].visitCount<2&&(E=!0)}for(;v!==h||E;){(v=(v.isHeadingIn?qt:Ht)(v,m))!==h&&(v=Ft(v,m)),E=!1}if(d.visitCount>=2){for(var w=!1,b=0;b<n.length;b++){var P=n[b];if(P.visitCount<2){h=P,w=!0;break}}w&&(d=h)}h=d}for(var x=l.map(function(e){return[e]}),_=Object.keys(s),T=0;T<_.length;T++){var A=_[T];if(0===s[A])Bt(Vt(Dt(r,parseInt(A)),o),x)}return{type:"Feature",properties:{},geometry:{type:"MultiPolygon",coordinates:x}}}function Dt(e,t){for(var n=0;n<e.length;n++){var r=e[n];if(r.polygonContourId===t)return r}}function Vt(e,t){return t.find(function(t){return t.id===e.polygonContourId}).rawCoords}function Bt(e,t){for(var n=0;n<t.length;n++){var r=t[n];if(xt(e[0],[r[0]]))return void r.push(e)}t.push([e])}function Ft(e,t){var n=e.polygonEdge;if(n.intersectionPoints.length>1&&n.intersectionPoints[n.intersectionPoints.length-1]!==e){var r=Ut(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 Ut(e,t){for(var n=0;n<t.length;n++){if(t[n]===e)return n}return null}function Ht(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=Ut(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 qt(e,t){var n=e.polylineEdge;if(n.intersectionPoints.length>1&&n.intersectionPoints[n.intersectionPoints.length-1]!==e){var r=Ut(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 jt=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,zt=Math.ceil,Wt=Math.floor,Yt="[BigNumber Error] ",$t=Yt+"Number primitive has more than 15 significant digits: ",Kt=1e14,Xt=14,Zt=9007199254740991,Jt=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],Qt=1e7,en=1e9;function tn(e){var t=0|e;return e>0||e===t?t:t-1}function nn(e){for(var t,n,r=1,i=e.length,o=e[0]+"";r<i;){for(t=e[r++]+"",n=Xt-t.length;n--;t="0"+t);o+=t}for(i=o.length;48===o.charCodeAt(--i););return o.slice(0,i+1||1)}function rn(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 on(e,t,n,r){if(e<t||e>n||e!==Wt(e))throw Error(Yt+(r||"Argument")+("number"==typeof e?e<t||e>n?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function sn(e){var t=e.c.length-1;return tn(e.e/Xt)==t&&e.c[t]%2!=0}function an(e,t){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(t<0?"e":"e+")+t}function ln(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 un=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,v=-1e7,E=1e7,S=!1,w=1,b=0,P={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},x="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>E?h.c=h.e=null:e.e<v?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>E?h.c=h.e=null:(h.e=a,h.c=[e]))}p=String(e)}else{if(!jt.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(on(t,2,x.length,"Base"),10==t&&_)return L(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($t+e)}else h.s=45===p.charCodeAt(0)?(p=p.slice(1),-1):1;for(n=x.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>Zt||e!==Wt(e)))throw Error($t+h.s*e);if((a=a-l-1)>E)h.c=h.e=null;else if(a<v)h.c=[h.e=0];else{if(h.e=a,h.c=[],l=(a+1)%Xt,a<0&&(l+=Xt),l<c){for(l&&h.c.push(+p.slice(0,l)),c-=Xt;l<c;)h.c.push(+p.slice(l,l+=Xt));l=Xt-(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:on(n,0,8),!e.c)return e.toString();if(i=e.c[0],s=e.e,null==t)l=nn(e.c),l=1==r||2==r&&(s<=y||s>=m)?an(l,s):ln(l,s,"0");else if(o=(e=L(new T(e),t,n)).e,a=(l=nn(e.c)).length,1==r||2==r&&(t<=o||o<=y)){for(;a<t;l+="0",a++);l=an(l,o)}else if(t-=s+(2===r&&o>s),l=ln(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=rn(o,r))===t||0===n&&o.s===t)&&(o=r);return o}function I(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*Xt-1)>E?e.c=e.e=null:n<v?e.c=[e.e=0]:(e.e=n,e.c=t),e}function L(e,t,n,r){var i,o,s,a,l,u,c,p=e.c,h=Jt;if(p){e:{for(i=1,a=p[0];a>=10;a/=10,i++);if((o=t-i)<0)o+=Xt,s=t,l=p[u=0],c=Wt(l/h[i-s-1]%10);else if((u=zt((o+1)/Xt))>=p.length){if(!r)break e;for(;p.length<=u;p.push(0));l=c=0,i=1,s=(o%=Xt)-Xt+1}else{for(l=a=p[u],i=1;a>=10;a/=10,i++);c=(s=(o%=Xt)-Xt+i)<0?0:Wt(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[(Xt-t%Xt)%Xt],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[Xt-o],p[u]=s>0?Wt(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]==Kt&&(p[0]=1));break}if(p[u]+=a,p[u]!=Kt)break;p[u--]=0,a=1}for(o=p.length;0===p[--o];p.pop());}e.e>E?e.c=e.e=null:e.e<v&&(e.c=[e.e=0])}return e}function M(e){var t,n=e.e;return null===n?e.toString():(t=nn(e.c),t=n<=y||n>=m?an(t,n):ln(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(Yt+"Object expected: "+e);if(e.hasOwnProperty(t="DECIMAL_PLACES")&&(on(n=e[t],0,en,t),f=n),e.hasOwnProperty(t="ROUNDING_MODE")&&(on(n=e[t],0,8,t),g=n),e.hasOwnProperty(t="EXPONENTIAL_AT")&&((n=e[t])&&n.pop?(on(n[0],-en,0,t),on(n[1],0,en,t),y=n[0],m=n[1]):(on(n,-en,en,t),y=-(m=n<0?-n:n))),e.hasOwnProperty(t="RANGE"))if((n=e[t])&&n.pop)on(n[0],-en,-1,t),on(n[1],1,en,t),v=n[0],E=n[1];else{if(on(n,-en,en,t),!n)throw Error(Yt+t+" cannot be zero: "+n);v=-(E=n<0?-n:n)}if(e.hasOwnProperty(t="CRYPTO")){if((n=e[t])!==!!n)throw Error(Yt+t+" not true or false: "+n);if(n){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw S=!n,Error(Yt+"crypto unavailable");S=n}else S=n}if(e.hasOwnProperty(t="MODULO_MODE")&&(on(n=e[t],0,9,t),w=n),e.hasOwnProperty(t="POW_PRECISION")&&(on(n=e[t],0,en,t),b=n),e.hasOwnProperty(t="FORMAT")){if("object"!=typeof(n=e[t]))throw Error(Yt+t+" not an object: "+n);P=n}if(e.hasOwnProperty(t="ALPHABET")){if("string"!=typeof(n=e[t])||/^.?$|[+\-.\s]|(.).*\1/.test(n))throw Error(Yt+t+" invalid: "+n);_="0123456789"==n.slice(0,10),x=n}}return{DECIMAL_PLACES:f,ROUNDING_MODE:g,EXPONENTIAL_AT:[y,m],RANGE:[v,E],CRYPTO:S,MODULO_MODE:w,POW_PRECISION:b,FORMAT:P,ALPHABET:x}},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>=-en&&i<=en&&i===Wt(i)){if(0===r[0]){if(0===i&&1===r.length)return!0;break e}if((t=(i+1)%Xt)<1&&(t+=Xt),String(r[0]).length==t){for(t=0;t<r.length;t++)if((n=r[t])<0||n>=Kt||n!==Wt(n))break e;if(0!==n)return!0}}}else if(null===r&&null===i&&(null===o||1===o||-1===o))return!0;throw Error(Yt+"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 Wt(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:on(e,0,en),i=zt(e/Xt),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(Yt+"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%=Xt,i&&e&&(o=Jt[Xt-e],l[a]=Wt(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-=Xt);for(a=1,o=l[0];o>=10;o/=10,a++);a<Xt&&(r-=Xt-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,v=r.indexOf("."),E=f,S=g;for(v>=0&&(p=b,b=0,r=r.replace(".",""),d=(m=new T(i)).pow(r.length-v),b=p,m.c=t(ln(nn(d.c),d.e,"0"),10,o,e),m.e=m.c.length),c=p=(y=t(r,i,o,a?(l=x,e):(l=e,x))).length;0==y[--p];y.pop());if(!y[0])return l.charAt(0);if(v<0?--c:(d.c=y,d.e=c,d.s=s,y=(d=n(d,m,E,S,o)).c,h=d.r,c=d.e),v=y[u=c+E+1],p=o/2,h=h||u<0||null!=y[u+1],h=S<4?(null!=v||h)&&(0==S||S==(d.s<0?3:2)):v>p||v==p&&(4==S||h||6==S&&1&y[u-1]||S==(d.s<0?8:7)),u<1||!y[0])r=h?ln(l.charAt(1),-E,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(v=0,r="";v<=p;r+=l.charAt(y[v++]));r=ln(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%Qt,c=t/Qt|0;for(e=e.slice();l--;)a=((i=u*(o=e[l]%Qt)+(r=c*o+(s=e[l]/Qt|0)*u)%Qt*Qt+a)/n|0)+(r/Qt|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,v,E,S,w,b,P,x,_=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=Kt,u=tn(r.e/Xt)-tn(i.e/Xt),_=_/Xt|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,P=C.length,c=0,_+=2,(h=Wt(a/(C[0]+1)))>1&&(C=e(C,h,a),A=e(A,h,a),P=C.length,w=A.length),S=P,v=(m=A.slice(0,P)).length;v<P;m[v++]=0);x=C.slice(),x=[0].concat(x),b=C[0],C[1]>=a/2&&b++;do{if(h=0,(l=t(C,m,P,v))<0){if(E=m[0],P!=v&&(E=E*a+(m[1]||0)),(h=Wt(E/b))>1)for(h>=a&&(h=a-1),f=(d=e(C,h,a)).length,v=m.length;1==t(d,m,f,v);)h--,n(d,P<f?x:C,f,a),f=d.length,l=1;else 0==h&&(l=h=1),f=(d=C.slice()).length;if(f<v&&(d=[0].concat(d)),n(m,d,v,a),v=m.length,-1==l)for(;t(C,m,P,v)<1;)h++,n(m,P<v?x:C,v,a),v=m.length}else 0===l&&(h++,m=[0]);y[c++]=h,m[0]?m[v++]=A[S]||0:(m=[A[S]],v=1)}while((S++<w||null!=m[0])&&_--);p=null!=m[0],y[0]||y.splice(0,1)}if(a==Kt){for(c=1,_=y[0];_>=10;_/=10,c++);L(g,o+(g.e=c+u*Xt-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(Yt+"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 rn(this,new T(e,t))},h.decimalPlaces=h.dp=function(e,t){var n,r,i,o=this;if(null!=e)return on(e,0,en),null==t?t=g:on(t,0,8),L(new T(o),e+o.e+1,t);if(!(n=o.c))return null;if(r=((i=n.length-1)-tn(this.e/Xt))*Xt,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(Yt+"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-sn(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&&sn(e)?-0:0,c.e>-1&&(o=1/o),new T(a?1/o:o);b&&(o=zt(b/Xt+2))}for(s?(n=new T(.5),a&&(e.s=1),l=sn(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=Wt(i/2)))break;l=i%2}else if(L(e=e.times(n),e.e+1,1),e.e>14)l=sn(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?L(u,b,g,void 0):u)},h.integerValue=function(e){var t=new T(this);return null==e?e=g:on(e,0,8),L(t,t.e+1,e)},h.isEqualTo=h.eq=function(e,t){return 0===rn(this,new T(e,t))},h.isFinite=function(){return!!this.c},h.isGreaterThan=h.gt=function(e,t){return rn(this,new T(e,t))>0},h.isGreaterThanOrEqualTo=h.gte=function(e,t){return 1===(t=rn(this,new T(e,t)))||0===t},h.isInteger=function(){return!!this.c&&tn(this.e/Xt)>this.c.length-2},h.isLessThan=h.lt=function(e,t){return rn(this,new T(e,t))<0},h.isLessThanOrEqualTo=h.lte=function(e,t){return-1===(t=rn(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/Xt,u=e.e/Xt,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=tn(l),u=tn(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=Kt-1;r>a;){if(c[--r]<p[r]){for(n=r;n&&!c[--n];c[n]=t);--c[n],c[r]+=Kt}c[r]-=p[r]}for(;0==c[0];c.splice(0,1),--u);return c[0]?I(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,v=m.c,E=(e=new T(e,t)).c;if(!(v&&E&&v[0]&&E[0]))return!m.s||!e.s||v&&!v[0]&&!E||E&&!E[0]&&!v?e.c=e.e=e.s=null:(e.s*=m.s,v&&E?(e.c=[0],e.e=0):e.c=e.e=null),e;for(r=tn(m.e/Xt)+tn(e.e/Xt),e.s*=m.s,(l=v.length)<(p=E.length)&&(f=v,v=E,E=f,i=l,l=p,p=i),i=l+p,f=[];i--;f.push(0));for(g=Kt,y=Qt,i=p;--i>=0;){for(n=0,h=E[i]%y,d=E[i]/y|0,o=i+(s=l);o>i;)n=((u=h*(u=v[--s]%y)+(a=d*u+(c=v[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),I(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/Xt,s=e.e/Xt,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=tn(o),s=tn(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)/Kt|0,a[t]=Kt===a[t]?0:a[t]%Kt;return i&&(a=[i].concat(a),++s),I(e,a,s)},h.precision=h.sd=function(e,t){var n,r,i,o=this;if(null!=e&&e!==!!e)return on(e,1,en),null==t?t=g:on(t,0,8),L(new T(o),e,t);if(!(n=o.c))return null;if(r=(i=n.length-1)*Xt+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 on(e,-9007199254740991,Zt),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=nn(a)).length+u)%2==0&&(t+="0"),l=Math.sqrt(+t),u=tn((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))),nn(o.c).slice(0,l)===(t=nn(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))||(L(r,r.e+f+2,1),e=!r.times(r).eq(s));break}if(!i&&(L(o,o.e+f+2,0),o.times(o).eq(s))){r=o;break}c+=4,l+=4,i=1}return L(r,r.e+f+1,g,e)},h.toExponential=function(e,t){return null!=e&&(on(e,0,en),e++),A(this,e,t,1)},h.toFixed=function(e,t){return null!=e&&(on(e,0,en),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=P;else if("object"!=typeof n)throw Error(Yt+"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(Yt+"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=nn(m),s=t.e=f.length-y.e-1,t.c[0]=Jt[(a=s%Xt)<0?Xt+a:a],e=!e||l.comparedTo(t)>0?s>0?t:c:l,a=E,E=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],E=a,h},h.toNumber=function(){return+M(this)},h.toPrecision=function(e,t){return null!=e&&on(e,1,en),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?an(nn(n.c),o):ln(nn(n.c),o,"0"):10===e&&_?t=ln(nn((n=L(new T(n),f+o+1,g)).c),n.e,"0"):(on(e,2,x.length,"Base"),t=r(ln(nn(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}(),cn=class{key;left=null;right=null;constructor(e){this.key=e}},pn=class extends cn{constructor(e){super(e)}},hn=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)}}},dn=class e extends hn{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 pn(e),t),this}addAndReturn(e){const t=this.splay(e);return 0!=t&&this.addNewRoot(new pn(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 pn(e.key);return function e(t,n){let r,i;do{if(r=t.left,i=t.right,null!=r){const t=new pn(r.key);n.left=t,e(r,t)}if(null!=i){const e=new pn(i.key);n.right=e,t=i,n=e}}while(null!=i)}(e,t),t}toSet(){return this.clone()}entries(){return new yn(this.wrap())}keys(){return this[Symbol.iterator]()}values(){return this[Symbol.iterator]()}[Symbol.iterator](){return new gn(this.wrap())}[Symbol.toStringTag]="[object Set]"},fn=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}},gn=class extends fn{getValue(e){return e.key}},yn=class extends fn{getValue(e){return[e.key,e.key]}},mn=e=>()=>e,vn=e=>{const t=e?(t,n)=>n.minus(t).abs().isLessThanOrEqualTo(e):mn(!1);return(e,n)=>t(e,n)?0:e.comparedTo(n)};function En(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)):mn(!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 Sn=e=>e,wn=e=>{if(e){const t=new dn(vn(e)),n=new dn(vn(e)),r=(e,t)=>t.addAndReturn(e),i=e=>({x:r(e.x,t),y:r(e.y,n)});return i({x:new un(0),y:new un(0)}),i}return Sn},bn=e=>({set:e=>{Pn=bn(e)},reset:()=>bn(e),compare:vn(e),snap:wn(e),orient:En(e)}),Pn=bn(),xn=(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),_n=(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)),An=(e,t)=>e.x.times(t.x).plus(e.y.times(t.y)),Cn=e=>An(e,e).sqrt(),In=(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(Cn(i)).div(Cn(r))},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 An(i,r).div(Cn(i)).div(Cn(r))},Mn=(e,t,n)=>t.y.isZero()?null:{x:e.x.plus(t.x.div(t.y).times(n.minus(e.y))),y:n},kn=(e,t,n)=>t.x.isZero()?null:{x:n,y:e.y.plus(t.y.div(t.x).times(n.minus(e.x)))},Rn=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:Un.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:In(this.point,e.point,r.point),cosine:Ln(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}}},Nn=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!==Pn.orient(r,e,i)&&(t.push(r),e=r)}if(1===t.length)return null;const n=t[0],r=t[1];0===Pn.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];Rn.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}}},On=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 On(r));else{const e=r.enclosingRing();e?.poly||t.push(new On(e)),e?.poly?.addInterior(r)}}return t}},Dn=class{queue;tree;segments;constructor(e,t=Un.compare){this.queue=e,this.tree=new dn(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=Rn.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}},Vn=new class{type;numMultiPolys;run(e,t,n){Vn.type=e;const r=[new jn(t,!0)];for(let e=0,t=n.length;e<t;e++)r.push(new jn(n[e],!1));if(Vn.numMultiPolys=r.length,"difference"===Vn.type){const e=r[0];let t=1;for(;t<r.length;)null!==_n(r[t].bbox,e.bbox)?t++:r.splice(t,1)}if("intersection"===Vn.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===_n(t.bbox,r[n].bbox))return[]}const i=new dn(Rn.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}Pn.reset();const a=Nn.factory(o.segments);return new Gn(a).getGeom()}},Bn=Vn,Fn=0,Un=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=++Fn,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=Rn.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 Rn(i,!0),u=new Rn(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 Pn.orient(this.leftSE.point,e,this.rightSE.point)}getIntersection(e){const t=this.bbox(),n=e.bbox(),r=_n(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=xn(t,s)&&0===this.comparePoint(s),u=xn(n,i)&&0===e.comparePoint(i),c=xn(t,a)&&0===this.comparePoint(a),p=xn(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 kn(n,r,e.x);if(r.x.isZero())return kn(e,t,n.x);if(t.y.isZero())return Mn(n,r,e.y);if(r.y.isZero())return Mn(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)),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:xn(r,h)?Pn.snap(h):null}split(t){const n=[],r=void 0!==t.events,i=new Rn(t,!0),o=new Rn(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 Rn.comparePoints(a.leftSE.point,a.rightSE.point)>0&&a.swapEvents(),Rn.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(Bn.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===Bn.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}},Hn=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=Pn.snap({x:new un(e[0][0]),y:new un(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=Pn.snap({x:new un(e[t][0]),y:new un(e[t][1])});n.x.eq(i.x)&&n.y.eq(i.y)||(this.segments.push(Un.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(Un.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}},qn=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 Hn(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 Hn(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}},jn=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 un(Number.POSITIVE_INFINITY),y:new un(Number.POSITIVE_INFINITY)},ur:{x:new un(Number.NEGATIVE_INFINITY),y:new un(Number.NEGATIVE_INFINITY)}};for(let t=0,n=e.length;t<n;t++){const n=new qn(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}};Pn.set;var zn=function(e,t={}){const n=[];if(k(e,e=>{n.push(e.coordinates)}),n.length<2)throw new Error("Must have at least 2 geometries");const r=((e,...t)=>Bn.run("union",e,t))(n[0],...n.slice(1));return 0===r.length?null:1===r.length?S(r[0],t.properties):function(e,t,n={}){return v({type:"MultiPolygon",coordinates:e},t,n)}(r,t.properties)};const Wn=(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,w(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=>S(t,e.properties));const o=e.id??e.properties?.id??"poly";return b(i.map((t,n)=>S(t.geometry.coordinates,{...e.properties,id:o},{id:`${o}-${n+1}`})))},Yn=([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))},$n=(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(Yn(e[n],e[r])<t)return!0;return!1})(n,t))},Kn=(e,t=.01)=>{if(e.length<=1)return!0;const n=e[e.length-1],r=e[e.length-2];return Yn(n,r)>=t},Xn=e=>e[0].length<=1||$n(e),Zn="_splitter",Jn=({draw:e,polygonFeature:t,feature:n})=>{const r=((e,t)=>{const n=t.geometry?.coordinates;return!(!n||n.length<2||!Wn(e,{geometry:t.geometry}))})(t,n);return e.setDrawingPreviewProperty("splitter",r?"valid":"invalid"),r},Qn=e=>e?{valid:!0}:{valid:!1,reason:"Line does not split the shape into two parts"},er=({draw:e,dispatch:t,polygonFeature:n})=>({feature:r,phase:i})=>i===f?Qn((({draw:e,dispatch:t,polygonFeature:n,feature:r})=>{const i=Jn({draw:e,polygonFeature:n,feature:r});return t({type:"SET_ACTION",payload:{name:"split",isValid:i}}),i})({draw:e,dispatch:t,polygonFeature:n,feature:r})):{valid:!0},tr=()=>"undefined"!=typeof navigator&&/mac/i.test(navigator.userAgentData?.platform||navigator.platform||""),nr=tr()?"<kbd>Command</kbd> + <kbd>Z</kbd>":"<kbd>Ctrl</kbd> + <kbd>Z</kbd>",rr=tr()?"<kbd>Option</kbd>":"<kbd>Alt</kbd>",ir="top-middle",or=({checkSlow:e,holding:t})=>!(!e||!t),sr=(e,t="actions")=>({mobile:{slot:t,showLabel:e},tablet:{slot:t,showLabel:e},desktop:{slot:t,showLabel:e}}),ar={reducer:{initialState:{mode:null,action:null,actionValid:!1,feature:null,tempFeature:null,selectedVertexIndex:-1,numVertices:null,validationStatus:"idle",checkSlow:!1,holding:!1,previewValid:!0,canAddPoint:!0,snap:!1,hasSnapLayers:!1,undoStackLength:0},actions:h},InitComponent:({appState:r,appConfig:i,mapState:o,pluginConfig:s,pluginState:l,services:c,mapProvider:p,buttonConfig:h,setApplicationMode:f,clearApplicationMode:g})=>{const{eventBus:y,hints:m,symbolRegistry:v}=c,{crossHair:E}=o;Ge({mapState:o,pluginState:l,services:c,mapProvider:p,spatialListRegistry:r.spatialListRegistry,viewportRef:r.layoutRefs.viewportRef});const S=e(!1);S.current=!l.holding&&(Ye({appState:r,pluginState:l})||u(l.mode)&&"keyboard"===r.interfaceType),$e({mapState:o,pluginConfig:s,pluginState:l,mapProvider:p,eventBus:y,symbolRegistry:v}),n(()=>{if(l.mode)return f(We),()=>g(We);g(We)},[l.mode]),t(()=>{const e=null!==l.mode&&"edit_vertex"!==l.mode;return y.emit(d.MAP_SET_SPATIAL_LIST_SUPPRESSED,{suppressed:e}),()=>{y.emit(d.MAP_SET_SPATIAL_LIST_SUPPRESSED,{suppressed:!1})}},[l.mode,y]),t(()=>{if(!S.current)return;const e=E.isVisible;return E.fixAtCenter(),()=>{e||S.current||E.hide()}},[l.mode,l.holding,r.interfaceType,r.expandedButtons]),t(()=>{var e;(e=l.mode,a.has(e)&&p.draw)&&p.draw.setInterfaceType(r.interfaceType)},[r.interfaceType,l.mode]),t(()=>{if(p.draw)return Me({appState:r,appConfig:i,mapState:o,mapProvider:p,buttonConfig:h,pluginState:l,eventBus:y,hints:m,announce:c.announce})},[p,r,l])},applicationModes:{[We]:{include:["mapStyles","mapControls","scaleBar"]}},buttons:[{id:"drawCancel",label:"Cancel",variant:"tertiary",exclusiveSlot:!0,hiddenWhen:({pluginState:e})=>!e.mode,...sr(!0)},{id:"drawAddPoint",label:"Add point",variant:"primary",exclusiveSlot:!0,hiddenWhen:({appState:e,pluginState:t})=>!Ye({appState:e,pluginState:t}),enableWhen:({pluginState:e})=>e.canAddPoint&&!e.holding,...sr(!0)},{id:"drawDone",label:({pluginState:e})=>or(e)?"Checking…":"Done",busyWhen:({pluginState:e})=>or(e),variant:"primary",exclusiveSlot:!0,hiddenWhen:({pluginState:e})=>!p(e.mode)&&!e.holding,enableWhen:({pluginState:e})=>{const{mode:t,validationStatus:n,previewValid:r,holding:i}=e,o="valid"===n||"pending"===n;return p(t)&&o&&r&&!i},...sr(!0)},{id:"drawUndo",label:"Undo",iconId:"undo",hiddenWhen:({pluginState:e})=>!p(e.mode),enableWhen:({pluginState:e})=>!e.holding&&(l(e.mode)?e.numVertices>0:e.undoStackLength>0),...sr(!1,ir)},{id:"drawSnap",label:"Snap",iconId:"magnet",hiddenWhen:({pluginState:e})=>!e.mode||!e.hasSnapLayers,enableWhen:({pluginState:e})=>!e.holding,pressedWhen:({pluginState:e})=>!!e.snap,...sr(!0,ir)},{id:"drawDeletePoint",label:"Delete point",iconId:"trash",enableWhen:({pluginState:e})=>{if(e.holding||e.selectedVertexIndex<0)return!1;return"Polygon"===e.feature?.geometry?.type?e.numVertices>3:e.numVertices>2},hiddenWhen:({pluginState:e})=>"edit_vertex"!==e.mode,...sr(!1,ir)}],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:`${rr} + <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:nr}],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:Je,newLine:Qe,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;const{properties:h,onGeometryChange:d,onGeometryPreview:f,...g}=l;Ee(c,{onGeometryChange:d,onGeometryPreview:f},n,p),p.emit("draw:started",{mode:"draw_point",featureId:a});const y=void 0===l.snapLayers?n.snapLayers??null:l.snapLayers;c.setSnapLayers(y),u({type:"SET_HAS_SNAP_LAYERS",payload:y?.length>0});const m={};pe.forEach(e=>{void 0!==g[e]&&(m[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:{...h,...m}}),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;Ee(c,l,r,p);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],featureId:a});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:n.mapSizeScale,featureId:a,getSnapEnabled:()=>c.isSnapEnabled()});const g=c.get(a);return u({type:"SET_FEATURE",payload:{feature:g,tempFeature:g}}),u({type:"SET_MODE",payload:d}),ye(c).run({feature:g,context:{phase:"edit-start",mode:d},onGeometryChange:c._commitValidator}),!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,...Xe({stroke:o,fill:s,strokeWidth:a})}};(e=>et.has(e.geometry?.type)&&void 0!==e.geometry?.coordinates)(c)?(r.add(c),i.emit("draw:add",he(c))):ce.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 ce.warn("setStyle: no feature found for id",n),!1;const s={},a={};for(const[e,t]of Object.entries(r))(tt.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})({...Xe(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},s,a={})=>{const{dispatch:l}=n,{draw:u}=i,{eventBus:c}=o;if(!u)return;const p=u.get(s),h=u._previewValidator,d=u._commitValidator;u._previewValidator=(({draw:e,polygonFeature:t})=>({feature:n,phase:r})=>"preview"===r?Qn(Jn({draw:e,polygonFeature:t,feature:n})):{valid:!0})({draw:u,polygonFeature:p}),u._commitValidator=er({draw:u,dispatch:l,polygonFeature:p}),ye(u).reset();const f=["stroke-inactive.cold",...a.snapLayers||[]];u.setSnapLayers(f),l({type:"SET_HAS_SNAP_LAYERS",payload:!0}),u.changeMode("draw_line",{container:e.layoutRefs.viewportRef.current,addVertexButtonId:`${t.id}-draw-add-point`,interfaceType:e.interfaceType,crossHair:r?.crossHair,getSnapEnabled:()=>u.isSnapEnabled(),featureId:Zn,properties:{splitter:"invalid"}});const y=()=>{u._previewValidator=h,u._commitValidator=d,u.off(g.CREATE,m),u.off(g.CANCEL,v)},m=e=>{y(),u.delete(Zn);const t=Wn(p,e);l({type:"SET_ACTION",payload:{name:"split",isValid:!!t}}),t&&c.emit("draw:split",{originalFeatureId:s,featureCollection:t})},v=()=>{y()};u.on(g.CREATE,m),u.on(g.CANCEL,v),l({type:"SET_MODE",payload:"draw_line"}),l({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=zn(b(e))}catch{return null}if("Polygon"!==t?.geometry?.type)return null;const n=e[0].id??e[0].properties?.id??"poly";return S(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},setGeometry:({mapProvider:e,pluginState:t},n)=>{const{draw:r}=e;if(!r||!c(r.getMode()))return!1;const i=r.get(t.feature?.id);return!(!i||i.geometry?.type!==n?.type)&&(r.setGeometry({type:n.type,coordinates:(o=n.coordinates,JSON.parse(JSON.stringify(o)))}),!0);var o},recheckGeometry:({mapProvider:e},t)=>{const{draw:n}=e;if(!n)return!1;const r=n.getMode(),i=ye(n),{feature:o}=i.state;if(!p(r)||!o)return!1;const s={phase:"recheck",mode:r,...void 0!==t&&{detail:t}};return i.run({feature:o,context:s,onGeometryChange:n._commitValidator}),!0}}};var lr=Object.freeze({__proto__:null,manifest:ar});export{g as A,ee as B,f as C,lr as D,ze as K,B as M,Q as P,qe as S,je as T,ae as a,Xn as b,I as c,Kn as d,A as e,T as f,S as g,w as h,C as i,R as j,b as k,_ as l,P as m,v as n,L as o,E as p,M as q,x as r,He as s,se as t,ce as u,ie as v,De as w,oe as x,le as y,re as z};
|
|
@@ -1 +1 @@
|
|
|
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.
|
|
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.D});case 1:return n=r.v.manifest,r.a(2,n)}},e)})),function(){return t.apply(this,arguments)})})}export{t as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{S as e,
|
|
1
|
+
import{S as e,s as t,y as r,M as n,z as l,P as a,B as o}from"./im-draw-plugin.js";const i=e.touchTargetSize/2;const s=t=>{let r=t.querySelector("[data-im-draw-touch-target]");return r||(t.insertAdjacentHTML("beforeend",function(){const t=e.touchTargetSize;return`\n <svg width='${t}' height='${t}' viewBox='0 0 48 48' fill-rule='evenodd'\n class='im-draw-touch-target' data-im-draw-touch-target>\n <circle cx='24' cy='24' r='24' fill='var(--draw-halo, #000)'/>\n <path d="M37.543 25H34a1 1 0 1 1 0-2h3.629l-.836-.837a1 1 0 0 1 1.414-1.414l2.5 2.501A1 1 0 0 1 41 24a1 1 0 0 1-.487.858l-2.306 2.306a1 1 0 0 1-1.414-1.414l.75-.75zM23 10.414l-.793.793a1 1 0 0 1-1.414-1.414l2.5-2.5C23.481 7.105 23.734 7 24 7s.519.105.707.293l2.5 2.5a1 1 0 0 1-1.414 1.414L25 10.414V14a1 1 0 1 1-2 0v-3.586zM7 24a1 1 0 0 1 .293-.75l2.5-2.501a1 1 0 0 1 1.414 1.414l-.836.837H14a1 1 0 1 1 0 2h-3.543l.75.75a1 1 0 0 1-1.414 1.414l-2.306-2.306A1 1 0 0 1 7 24zm16.293 16.707l-2.5-2.5a1 1 0 0 1 1.414-1.414l.793.793V34a1 1 0 1 1 2 0v3.586l.793-.793a1 1 0 0 1 1.414 1.414l-2.5 2.5c-.188.188-.441.293-.707.293s-.519-.105-.707-.293zM24 20c2.208 0 4 1.792 4 4s-1.792 4-4 4-4-1.792-4-4 1.792-4 4-4z" fill='var(--draw-bg, #fff)'/>\n </svg>\n `}()),r=t.querySelector("[data-im-draw-touch-target]"),Object.assign(r.style,{display:"none",position:"absolute",top:"0",left:"0",margin:`${i}px 0 0 -${i}px`,cursor:"grab"})),r},u=(e,t)=>{e&&(e.style.setProperty("--draw-halo",t.editActive),e.style.setProperty("--draw-bg",t.editHalo),e.style.setProperty("--draw-primary",t.editVertex))},d=(e,t)=>{t&&e&&(e.style.left=`${t.x}px`,e.style.top=`${t.y}px`,e.style.display="block")},c=e=>{e&&(e.style.display="none")},p=e=>{if(!e)return!1;const t=e.parentNode;return t instanceof globalThis.SVGElement||null!=t?.ownerSVGElement},h=(r,n={})=>{const l=r?.mapColorScheme??"light",a=r?.id??null,o=e=>((e,t,r=null)=>"object"!=typeof e||null===e?e:r&&void 0!==e[r]?e[r]:void 0!==e[t]?e[t]:void 0!==e.light?e.light:Object.values(e)[0])(n[e]??t[e],l,a);return{editStroke:o("editStroke"),editFill:o("editFill"),editVertex:o("editVertex"),editMidpoint:o("editMidpoint"),editActive:o("editActive"),editHalo:o("editHalo"),invalidStroke:o("invalidStroke"),splitValid:o("splitValid"),splitInvalid:o("splitInvalid"),shapeStroke:o("shapeStroke"),strokeWidth:n.strokeWidth??e.strokeWidth,shapeFill:o("shapeFill"),snapVertex:o("snapVertex"),snapEdge:o("snapEdge"),mapStyleId:a}},y=(e,t,r)=>{const n=(e,t)=>e[0]===t[0]&&e[1]===t[1],l=t.filter(t=>{const l=Math.abs(t[0]-e[0]),a=Math.abs(t[1]-e[1]);let o=!1;return o="ArrowUp"===r?t[1]<=e[1]&&a>=l:"ArrowDown"===r?t[1]>e[1]&&a>=l:"ArrowLeft"===r?t[0]<=e[0]&&a<l:"ArrowRight"!==r||t[0]>e[0]&&a<l,o&&!n(t,e)});l.length||l.push(e);const a=t=>Math.hypot(e[0]-t[0],e[1]-t[1]),o=l.reduce((e,t)=>a(t)<a(e)?t:e,l[0]);return t.findIndex(e=>n(e,o))},m=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Enter"]),v=e=>{e.altKey&&m.has(e.key)&&e.stopPropagation()},f=e=>{const t=[];return{push(r){t.push(r),e(t.length)},pop(){const r=t.pop();return e(t.length),r},clear(){t.length=0,e(t.length)},get length(){return t.length}}},g=e=>!(!e?.symbol&&!e?.symbolSvgContent),w=e=>"function"==typeof requestAnimationFrame?requestAnimationFrame(e):setTimeout(e,16),x=e=>"function"==typeof cancelAnimationFrame?cancelAnimationFrame(e):clearTimeout(e),A=({onChange:e,validate:t=r})=>{let n=!1,l=null,a=null;const o=()=>{null!=l&&(x(l),l=null),a=null},i=(t,r)=>{t!==n&&(n=t,e(t,r??null))},s=()=>{if(l=null,!a)return;const{feature:e,context:r,onGeometryPreview:n}=a,{valid:o,reason:s}=t(e,r,{onGeometryPreview:n});i(!o,s)};return{update({feature:e,context:r={},numVertices:n,onGeometryPreview:u}){const d={...r,numVertices:n},c=t(e,d);return c.valid?"function"!=typeof u?(o(),void i(!1,null)):(a={feature:e,context:d,onGeometryPreview:u},void(null==l&&(l=w(s)))):(o(),void i(!0,c.reason))},set(e,t){o(),i(e,t??null)},refresh(){e(n,null)},destroy(){o()}}},S=({onStrokeChange:e,onPlaceChange:t})=>{const r=e=>{let t=!1;return(r,n)=>{r!==t&&(t=r,e(r,n??null))}},i=r(e),s=r(t);let u=!1,d=null,c=null,p=null;const h=()=>{null!=c&&(x(c),c=null),p=null},y=(e,t,r,n,a)=>{const o=(t.numVertices??0)<n?{valid:!0}:l(e,{...t,phase:"preview"},{rules:r});a(!o.valid||u,o.valid?d:o.reason)},m=()=>{if(!p)return;const{feature:e,context:t}=p,r=n[e?.geometry?.type]??0;y(e,t,a,r,i),y(e,t,o,0,s)},v=()=>{if(c=null,!p)return;const{feature:e,context:t,onGeometryPreview:r}=p,n=l(e,{...t,phase:"preview"},{rules:[],onGeometryPreview:r});u=!n.valid,d=n.reason,m()};return{update({feature:e,context:t={},numVertices:r,onGeometryPreview:n}){p={feature:e,context:{...t,numVertices:r},onGeometryPreview:n},m(),"function"==typeof n&&null==c&&(c=w(v))},reset(){h(),u=!1,d=null,i(!1,null),s(!1,null)},destroy(){h()}}};export{u as a,v as b,s as c,f as d,A as e,S as f,c as g,g as h,d as i,p as j,h as r,y as s};
|