@defra/interactive-map 0.0.58-alpha → 0.0.59-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/docs/plugins/draw.md +95 -13
- package/package.json +1 -1
- 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/adapterEvents.js +2 -0
- package/plugins/draw/src/adapters/adapterContract.test.js +1 -0
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +15 -3
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -0
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.js +8 -19
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.test.js +20 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/pointerHandlers.js +6 -17
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/pointerHandlers.test.js +19 -0
- package/plugins/draw/src/adapters/maplibre/utils/editModeEvents.js +29 -1
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +13 -3
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +28 -0
- package/plugins/draw/src/api/addFeature.js +9 -6
- package/plugins/draw/src/api/addFeature.test.js +37 -10
- package/plugins/draw/src/api/editFeature.js +1 -1
- package/plugins/draw/src/api/recheckGeometry.js +1 -1
- package/plugins/draw/src/api/recheckGeometry.test.js +2 -2
- package/plugins/draw/src/api/setProperties.js +39 -0
- package/plugins/draw/src/api/setProperties.test.js +74 -0
- package/plugins/draw/src/api/setStyle.js +16 -19
- package/plugins/draw/src/api/setStyle.test.js +17 -2
- package/plugins/draw/src/api/split.js +7 -4
- package/plugins/draw/src/api/split.test.js +25 -2
- package/plugins/draw/src/events.js +95 -53
- package/plugins/draw/src/events.test.js +425 -6
- package/plugins/draw/src/manifest.js +6 -4
- package/plugins/draw/src/manifest.test.js +20 -26
- package/plugins/draw/src/reducer.js +7 -0
- package/plugins/draw/src/reducer.test.js +11 -0
- package/plugins/draw/src/utils/flattenStyleProperties.js +54 -2
- package/plugins/draw/src/utils/flattenStyleProperties.test.js +74 -1
- package/plugins/draw/src/utils/isPlainObject.js +14 -0
- package/plugins/draw/src/utils/isPlainObject.test.js +24 -0
- package/plugins/draw/src/utils/mergeFeatureProperties.js +45 -0
- package/plugins/draw/src/utils/mergeFeatureProperties.test.js +48 -0
- package/plugins/draw/src/utils/stripInternalProperties.js +3 -2
- package/plugins/draw/src/validation/commitChecks.js +29 -11
- package/plugins/draw/src/validation/commitChecks.test.js +67 -11
- package/plugins/draw/src/validation/validateGeometry.js +12 -5
- package/plugins/draw/src/validation/validateGeometry.test.js +18 -0
- package/src/App/store/MapProvider.jsx +1 -0
- package/src/App/store/MapProvider.test.jsx +25 -0
- package/src/App/store/mapActionsMap.js +6 -0
- package/src/App/store/mapActionsMap.test.js +7 -0
- package/src/App/store/mapReducer.js +2 -0
- package/src/App/store/mapReducer.test.js +2 -0
|
@@ -1 +1 @@
|
|
|
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 F={Polygon:3,LineString:2},B=e=>e?.geometry??e,U=e=>{const t=B(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<F.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=B(e);return"Polygon"===t?.type?H(t).length>=F.Polygon?{valid:!0}:{valid:!1,reason:Z.Polygon}:"LineString"===t?.type?(t.coordinates?.length??0)>=F.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=F[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,e._finishValidator=t.onGeometryFinish??n.onGeometryFinish;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=(e,{result:t,context:n})=>!(Pe.has(n?.phase)||"function"!=typeof e._finishValidator&&!t?.recheckOnFinish),_e=e=>e._finishValidator??e._commitValidator,Te=(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)},Ae=({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}}),Ce={pending:"Checking shape",valid:"Shape check passed",invalid:"Shape check failed",error:"Shape could not be checked"},Ie=({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?.(Ce.pending,"action"):i&&e?.("invalid"===t&&n.reason||Ce[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 Le({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(r,a.state)||a.run({feature:e,context:{phase:"create",mode:r.getMode()},onGeometryChange:_e(r)}),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(r,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 Me({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&&!e._finishValidator)return void r(i.revision);if(!xe(e,i))return void e.done();n.run({feature:i.feature,context:{phase:"edit-finish",mode:e.getMode()},onGeometryChange:_e(e)});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 ke({appState:e,appConfig:t,mapState:n,pluginState:r,mapProvider:i,buttonConfig:o,eventBus:s,hints:a,announce:l}){const{draw:u}=i,h=Te(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{...Me({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()},...Le({appState:e,appConfig:t,mapState:n,draw:u,dispatch:f,eventBus:o,resetState:l}),...Ae({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=Ie({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 Re="edit_vertex",Ne="draw",Oe=(e,t,n)=>{const{x:r,y:i}=e.mapToScreen(n);return{x:r*t,y:i*t}},Ge=(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,...Oe(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,...Oe(e,t,r)}))(r[s],s))}),i};function De({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===Re?Ge(n,r):[],i.notifyItemsChanged(Ne)};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(Ne,{getItems:()=>({items:o.current,multiselectable:!1,label:"Shape points",focusable:!1}),exclusive:!0}),()=>{i.unregisterItemProvider(Ne)}),[i,o]),t(()=>{if(e.mode===Re)return i.claimExclusive(Ne),()=>i.releaseExclusive(Ne)},[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===Re&&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!==Re||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 Ve={small:1,medium:1.5,large:2},Fe="rgba(29,112,184,1)",Be="#ffffff",Ue="rgba(11,12,12,1)",He="rgba(212,53,28,0.5)",qe={editStroke:{light:Fe,dark:Be},editFill:{light:"rgba(29,112,184,0.1)",dark:"rgba(255,255,255,0.1)"},editVertex:{light:Fe,dark:Be},editMidpoint:{light:Fe,dark:Be},editHalo:{light:Be,dark:Ue},editActive:{light:Ue,dark:Be},splitInvalid:{light:Fe,dark:Be},splitValid:{light:Fe,dark:Be},invalidStroke:{light:Fe,dark:Be},shapeStroke:"rgba(212,53,28,1)",shapeFill:He,snapVertex:He,snapMidpoint:"rgba(40,161,151,1)",snapEdge:"rgba(29,112,184,0.5)"},je={strokeWidth:2,vertexRadius:6,midpointRadius:4,vertexHaloRadius:8,midpointHaloRadius:6,touchTargetSize:48},ze={snapRadius:12},We={nudgeAmount:1,stepAmount:5},Ye="draw",$e=({appState:e,pluginState:t})=>u(t.mode)&&("touch"===e.interfaceType||!!e.expandedButtons?.has("mapControls"));function Ke({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 Xe=new Set(["stroke","fill","strokeWidth"]),Ze=e=>{if(!e)return{};const t={};for(const[n,r]of Object.entries(e))if(Xe.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},Je=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,onGeometryFinish:E,...S}=u;Ee(p,{onGeometryChange:m,onGeometryPreview:v,onGeometryFinish:E},r,h),h.emit("draw:started",{mode:e,featureId:l});const w=void 0===u.snapLayers?r.snapLayers??null:u.snapLayers;p.setSnapLayers(w),c({type:"SET_HAS_SNAP_LAYERS",payload:w?.length>0});const b={...y,...Ze({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,...S,properties:b}),c({type:"SET_MODE",payload:e})},Qe=Je("draw_polygon"),et=Je("draw_line"),tt=new Set(["Point","LineString","Polygon"]),nt=new Set(["stroke","fill","strokeWidth"]);function rt(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return it(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 it(e)}),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return st(e);default:throw new Error("unknown GeoJSON type")}}function it(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=ot(e.properties),t.geometry=st(e.geometry),t}function ot(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]=ot(r):t[n]=r}),t):t}function st(e){var t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(function(e){return st(e)}),t):(t.coordinates=at(e.coordinates),t)}function at(e){var t=e;return"object"!=typeof t[0]?t.slice():t.map(function(e){return at(e)})}function lt(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 ut(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 ct(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=rt(e));var o=[];switch(e.type){case"GeometryCollection":return k(e,function(e){pt(e,r)}),e;case"FeatureCollection":return L(e,function(e){L(pt(e,r),function(e){o.push(e)})}),b(o)}return pt(e,r)}function pt(e,t){switch("Feature"===e.type?e.geometry.type:e.type){case"GeometryCollection":return k(e,function(e){pt(e,t)}),e;case"LineString":return ht(ut(e),t),e;case"Polygon":return dt(ut(e),t),e;case"MultiLineString":return ut(e).forEach(function(e){ht(e,t)}),e;case"MultiPolygon":return ut(e).forEach(function(e){dt(e,t)}),e;case"Point":case"MultiPoint":return e}}function ht(e,t){lt(e)===t&&e.reverse()}function dt(e,t){lt(e[0])!==t&&e[0].reverse();for(var n=1;n<e.length;n++)lt(e[n])===t&&e[n].reverse()}const ft=11102230246251565e-32,gt=134217729,yt=(3+8*ft)*ft;function mt(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 vt(e){return new Float64Array(e)}const Et=vt(4),St=vt(8),wt=vt(12),bt=vt(16),Pt=vt(4);function xt(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=gt*_,d=h-(h-_),f=_-d,h=gt*C,g=h-(h-C),y=C-g,w=f*y-(S-d*g-f*g-d*y),b=A*T,h=gt*A,d=h-(h-A),f=A-d,h=gt*T,g=h-(h-T),y=T-g,P=f*y-(b-d*g-f*g-d*y),m=w-P,p=w-m,Et[0]=w-(m+p)+(p-P),v=S+m,p=v-S,E=S-(v-p)+(m-p),m=E-b,p=E-m,Et[1]=E-(m+p)+(p-b),x=v+m,p=x-v,Et[2]=v-(x-p)+(m-p),Et[3]=x;let I=function(e,t){let n=t[0];for(let r=1;r<e;r++)n+=t[r];return n}(4,Et),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+yt*Math.abs(I),I+=_*c+C*a-(A*u+T*l),I>=L||-I>=L)return I;S=a*C,h=gt*a,d=h-(h-a),f=a-d,h=gt*C,g=h-(h-C),y=C-g,w=f*y-(S-d*g-f*g-d*y),b=l*T,h=gt*l,d=h-(h-l),f=l-d,h=gt*T,g=h-(h-T),y=T-g,P=f*y-(b-d*g-f*g-d*y),m=w-P,p=w-m,Pt[0]=w-(m+p)+(p-P),v=S+m,p=v-S,E=S-(v-p)+(m-p),m=E-b,p=E-m,Pt[1]=E-(m+p)+(p-b),x=v+m,p=x-v,Pt[2]=v-(x-p)+(m-p),Pt[3]=x;const M=mt(4,Et,4,Pt,St);S=_*c,h=gt*_,d=h-(h-_),f=_-d,h=gt*c,g=h-(h-c),y=c-g,w=f*y-(S-d*g-f*g-d*y),b=A*u,h=gt*A,d=h-(h-A),f=A-d,h=gt*u,g=h-(h-u),y=u-g,P=f*y-(b-d*g-f*g-d*y),m=w-P,p=w-m,Pt[0]=w-(m+p)+(p-P),v=S+m,p=v-S,E=S-(v-p)+(m-p),m=E-b,p=E-m,Pt[1]=E-(m+p)+(p-b),x=v+m,p=x-v,Pt[2]=v-(x-p)+(m-p),Pt[3]=x;const k=mt(M,St,4,Pt,wt);S=a*c,h=gt*a,d=h-(h-a),f=a-d,h=gt*c,g=h-(h-c),y=c-g,w=f*y-(S-d*g-f*g-d*y),b=l*u,h=gt*l,d=h-(h-l),f=l-d,h=gt*u,g=h-(h-u),y=u-g,P=f*y-(b-d*g-f*g-d*y),m=w-P,p=w-m,Pt[0]=w-(m+p)+(p-P),v=S+m,p=v-S,E=S-(v-p)+(m-p),m=E-b,p=E-m,Pt[1]=E-(m+p)+(p-b),x=v+m,p=x-v,Pt[2]=v-(x-p)+(m-p),Pt[3]=x;const R=mt(k,wt,4,Pt,bt);return bt[R-1]}(e,t,n,r,i,o,u)}function _t(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=xt(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 Tt=function(e,t,n,r,i){this.p1=e,this.p2=t,this.edgeType=n,this.originalIndex=r,this.polygonContourId=i,this.interiorRing=!1,this.minX=Math.min(e.p[0],t.p[0]),this.minY=Math.min(e.p[1],t.p[1]),this.maxX=Math.max(e.p[0],t.p[0]),this.maxY=Math.max(e.p[1],t.p[1]),this.intersectionPoints=[],this.nextEdge=null},At=function(e){this.p=e},Ct=function(e,t){this.id=e,this.rawCoords=t};function It(e,t){return!(e.maxX<t[0])&&(!(e.minX>t[2])&&(!(e.maxY<t[1])&&!(e.minY>t[3])))}var Lt=function(e,t,n,r){this.p=e,this.polylineEdge=t,this.polygonEdge=n,this.isHeadingIn=r,this.distanceFromPolylineEdgeStart=Mt(this.polylineEdge.p1.p,this.p),this.distanceFromPolygonEdgeStart=Mt(this.polygonEdge.p1.p,this.p),this.polygonEdge.intersectionPoints.push(this),this.polylineEdge.intersectionPoints.push(this),this.visitCount=0};function Mt(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 kt=1e-9;function Rt(e,t){return e[0]*t[1]-e[1]*t[0]}function Nt(e,t){return e[0]*t[0]+e[1]*t[1]}function Ot(e,t,n){return[e[0]+t*n[0],e[1]+t*n[1]]}function Gt(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=Rt(r,i),a=s*s,l=Nt(r,r);if(a>0){var u=Rt(o,i)/s;if(u<0||u>1)return null;var c=Rt(o,r)/s;return c<0||c>1?null:0===u||1===u?[Ot(e.p1.p,u,r)]:0===c||1===c?[Ot(t.p1.p,c,i)]:[Ot(e.p1.p,u,r)]}var p=Nt(o,o);if((a=(s=Rt(o,r))*s)>kt*l*p)return null;var h=Nt(r,o)/l,d=h+Nt(r,i)/l,f=Math.min(h,d),g=Math.max(h,d);return f<=1&&g>=0?1===f?[Ot(e.p1.p,f>0?f:0,r)]:0===g?[Ot(e.p1.p,g<1?g:1,r)]:[Ot(e.p1.p,f>0?f:0,r),Ot(e.p1.p,g<1?g:1,r)]:null}function Dt(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 At(l[c][0]),d=null,f={nextEdge:null},g=0;g<p;g++){d=new At(l[c][g+1]),h.nextPoint=d,d.prevPoint=h;var y=new Tt(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 Ct(o,P));for(var _=new At(P[0]),T=_,A=void 0,C=null,I={nextEdge:null,prevEdge:null},L=null,M=1;M<x;M++)A=new At(P[M]),T.nextPoint=A,A.prevPoint=T,C=new Tt(T,A,"polygon",u,o),I.nextEdge=C,C.prevEdge=I,1===M&&(L=C),b>0&&(C.interiorRing=!0),C.intersectPolylineBbox=It(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}(ct(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=Gt(l,u);if(null!==c)for(o=0;o<c.length;o++){var p=xt(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 v=Ut(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?jt:qt)(v,m))!==h&&(v=Ut(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(Ft(Vt(r,parseInt(A)),o),x)}return{type:"Feature",properties:{},geometry:{type:"MultiPolygon",coordinates:x}}}function Vt(e,t){for(var n=0;n<e.length;n++){var r=e[n];if(r.polygonContourId===t)return r}}function Ft(e,t){return t.find(function(t){return t.id===e.polygonContourId}).rawCoords}function Bt(e,t){for(var n=0;n<t.length;n++){var r=t[n];if(_t(e[0],[r[0]]))return void r.push(e)}t.push([e])}function Ut(e,t){var n=e.polygonEdge;if(n.intersectionPoints.length>1&&n.intersectionPoints[n.intersectionPoints.length-1]!==e){var r=Ht(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 Ht(e,t){for(var n=0;n<t.length;n++){if(t[n]===e)return n}return null}function qt(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=Ht(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 jt(e,t){var n=e.polylineEdge;if(n.intersectionPoints.length>1&&n.intersectionPoints[n.intersectionPoints.length-1]!==e){var r=Ht(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 zt=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,Wt=Math.ceil,Yt=Math.floor,$t="[BigNumber Error] ",Kt=$t+"Number primitive has more than 15 significant digits: ",Xt=1e14,Zt=14,Jt=9007199254740991,Qt=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],en=1e7,tn=1e9;function nn(e){var t=0|e;return e>0||e===t?t:t-1}function rn(e){for(var t,n,r=1,i=e.length,o=e[0]+"";r<i;){for(t=e[r++]+"",n=Zt-t.length;n--;t="0"+t);o+=t}for(i=o.length;48===o.charCodeAt(--i););return o.slice(0,i+1||1)}function on(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 sn(e,t,n,r){if(e<t||e>n||e!==Yt(e))throw Error($t+(r||"Argument")+("number"==typeof e?e<t||e>n?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function an(e){var t=e.c.length-1;return nn(e.e/Zt)==t&&e.c[t]%2!=0}function ln(e,t){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(t<0?"e":"e+")+t}function un(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 cn=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(!zt.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(sn(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(Kt+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>Jt||e!==Yt(e)))throw Error(Kt+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)%Zt,a<0&&(l+=Zt),l<c){for(l&&h.c.push(+p.slice(0,l)),c-=Zt;l<c;)h.c.push(+p.slice(l,l+=Zt));l=Zt-(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:sn(n,0,8),!e.c)return e.toString();if(i=e.c[0],s=e.e,null==t)l=rn(e.c),l=1==r||2==r&&(s<=y||s>=m)?ln(l,s):un(l,s,"0");else if(o=(e=L(new T(e),t,n)).e,a=(l=rn(e.c)).length,1==r||2==r&&(t<=o||o<=y)){for(;a<t;l+="0",a++);l=ln(l,o)}else if(t-=s+(2===r&&o>s),l=un(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=on(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*Zt-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=Qt;if(p){e:{for(i=1,a=p[0];a>=10;a/=10,i++);if((o=t-i)<0)o+=Zt,s=t,l=p[u=0],c=Yt(l/h[i-s-1]%10);else if((u=Wt((o+1)/Zt))>=p.length){if(!r)break e;for(;p.length<=u;p.push(0));l=c=0,i=1,s=(o%=Zt)-Zt+1}else{for(l=a=p[u],i=1;a>=10;a/=10,i++);c=(s=(o%=Zt)-Zt+i)<0?0:Yt(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[(Zt-t%Zt)%Zt],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[Zt-o],p[u]=s>0?Yt(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]==Xt&&(p[0]=1));break}if(p[u]+=a,p[u]!=Xt)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=rn(e.c),t=n<=y||n>=m?ln(t,n):un(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($t+"Object expected: "+e);if(e.hasOwnProperty(t="DECIMAL_PLACES")&&(sn(n=e[t],0,tn,t),f=n),e.hasOwnProperty(t="ROUNDING_MODE")&&(sn(n=e[t],0,8,t),g=n),e.hasOwnProperty(t="EXPONENTIAL_AT")&&((n=e[t])&&n.pop?(sn(n[0],-tn,0,t),sn(n[1],0,tn,t),y=n[0],m=n[1]):(sn(n,-tn,tn,t),y=-(m=n<0?-n:n))),e.hasOwnProperty(t="RANGE"))if((n=e[t])&&n.pop)sn(n[0],-tn,-1,t),sn(n[1],1,tn,t),v=n[0],E=n[1];else{if(sn(n,-tn,tn,t),!n)throw Error($t+t+" cannot be zero: "+n);v=-(E=n<0?-n:n)}if(e.hasOwnProperty(t="CRYPTO")){if((n=e[t])!==!!n)throw Error($t+t+" not true or false: "+n);if(n){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw S=!n,Error($t+"crypto unavailable");S=n}else S=n}if(e.hasOwnProperty(t="MODULO_MODE")&&(sn(n=e[t],0,9,t),w=n),e.hasOwnProperty(t="POW_PRECISION")&&(sn(n=e[t],0,tn,t),b=n),e.hasOwnProperty(t="FORMAT")){if("object"!=typeof(n=e[t]))throw Error($t+t+" not an object: "+n);P=n}if(e.hasOwnProperty(t="ALPHABET")){if("string"!=typeof(n=e[t])||/^.?$|[+\-.\s]|(.).*\1/.test(n))throw Error($t+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>=-tn&&i<=tn&&i===Yt(i)){if(0===r[0]){if(0===i&&1===r.length)return!0;break e}if((t=(i+1)%Zt)<1&&(t+=Zt),String(r[0]).length==t){for(t=0;t<r.length;t++)if((n=r[t])<0||n>=Xt||n!==Yt(n))break e;if(0!==n)return!0}}}else if(null===r&&null===i&&(null===o||1===o||-1===o))return!0;throw Error($t+"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 Yt(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:sn(e,0,tn),i=Wt(e/Zt),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($t+"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%=Zt,i&&e&&(o=Qt[Zt-e],l[a]=Yt(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-=Zt);for(a=1,o=l[0];o>=10;o/=10,a++);a<Zt&&(r-=Zt-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(un(rn(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?un(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=un(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%en,c=t/en|0;for(e=e.slice();l--;)a=((i=u*(o=e[l]%en)+(r=c*o+(s=e[l]/en|0)*u)%en*en+a)/n|0)+(r/en|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=Xt,u=nn(r.e/Zt)-nn(i.e/Zt),_=_/Zt|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=Yt(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=Yt(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==Xt){for(c=1,_=y[0];_>=10;_/=10,c++);L(g,o+(g.e=c+u*Zt-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($t+"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 on(this,new T(e,t))},h.decimalPlaces=h.dp=function(e,t){var n,r,i,o=this;if(null!=e)return sn(e,0,tn),null==t?t=g:sn(t,0,8),L(new T(o),e+o.e+1,t);if(!(n=o.c))return null;if(r=((i=n.length-1)-nn(this.e/Zt))*Zt,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($t+"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-an(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&&an(e)?-0:0,c.e>-1&&(o=1/o),new T(a?1/o:o);b&&(o=Wt(b/Zt+2))}for(s?(n=new T(.5),a&&(e.s=1),l=an(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=Yt(i/2)))break;l=i%2}else if(L(e=e.times(n),e.e+1,1),e.e>14)l=an(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:sn(e,0,8),L(t,t.e+1,e)},h.isEqualTo=h.eq=function(e,t){return 0===on(this,new T(e,t))},h.isFinite=function(){return!!this.c},h.isGreaterThan=h.gt=function(e,t){return on(this,new T(e,t))>0},h.isGreaterThanOrEqualTo=h.gte=function(e,t){return 1===(t=on(this,new T(e,t)))||0===t},h.isInteger=function(){return!!this.c&&nn(this.e/Zt)>this.c.length-2},h.isLessThan=h.lt=function(e,t){return on(this,new T(e,t))<0},h.isLessThanOrEqualTo=h.lte=function(e,t){return-1===(t=on(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/Zt,u=e.e/Zt,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=nn(l),u=nn(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=Xt-1;r>a;){if(c[--r]<p[r]){for(n=r;n&&!c[--n];c[n]=t);--c[n],c[r]+=Xt}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=nn(m.e/Zt)+nn(e.e/Zt),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=Xt,y=en,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/Zt,s=e.e/Zt,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=nn(o),s=nn(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)/Xt|0,a[t]=Xt===a[t]?0:a[t]%Xt;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 sn(e,1,tn),null==t?t=g:sn(t,0,8),L(new T(o),e,t);if(!(n=o.c))return null;if(r=(i=n.length-1)*Zt+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 sn(e,-9007199254740991,Jt),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=rn(a)).length+u)%2==0&&(t+="0"),l=Math.sqrt(+t),u=nn((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))),rn(o.c).slice(0,l)===(t=rn(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&&(sn(e,0,tn),e++),A(this,e,t,1)},h.toFixed=function(e,t){return null!=e&&(sn(e,0,tn),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($t+"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($t+"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=rn(m),s=t.e=f.length-y.e-1,t.c[0]=Qt[(a=s%Zt)<0?Zt+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&&sn(e,1,tn),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?ln(rn(n.c),o):un(rn(n.c),o,"0"):10===e&&_?t=un(rn((n=L(new T(n),f+o+1,g)).c),n.e,"0"):(sn(e,2,x.length,"Base"),t=r(un(rn(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}(),pn=class{key;left=null;right=null;constructor(e){this.key=e}},hn=class extends pn{constructor(e){super(e)}},dn=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)}}},fn=class e extends dn{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 hn(e),t),this}addAndReturn(e){const t=this.splay(e);return 0!=t&&this.addNewRoot(new hn(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 hn(e.key);return function e(t,n){let r,i;do{if(r=t.left,i=t.right,null!=r){const t=new hn(r.key);n.left=t,e(r,t)}if(null!=i){const e=new hn(i.key);n.right=e,t=i,n=e}}while(null!=i)}(e,t),t}toSet(){return this.clone()}entries(){return new mn(this.wrap())}keys(){return this[Symbol.iterator]()}values(){return this[Symbol.iterator]()}[Symbol.iterator](){return new yn(this.wrap())}[Symbol.toStringTag]="[object Set]"},gn=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}},yn=class extends gn{getValue(e){return e.key}},mn=class extends gn{getValue(e){return[e.key,e.key]}},vn=e=>()=>e,En=e=>{const t=e?(t,n)=>n.minus(t).abs().isLessThanOrEqualTo(e):vn(!1);return(e,n)=>t(e,n)?0:e.comparedTo(n)};function Sn(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)):vn(!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 wn=e=>e,bn=e=>{if(e){const t=new fn(En(e)),n=new fn(En(e)),r=(e,t)=>t.addAndReturn(e),i=e=>({x:r(e.x,t),y:r(e.y,n)});return i({x:new cn(0),y:new cn(0)}),i}return wn},Pn=e=>({set:e=>{xn=Pn(e)},reset:()=>Pn(e),compare:En(e),snap:bn(e),orient:Sn(e)}),xn=Pn(),_n=(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),Tn=(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}}},An=(e,t)=>e.x.times(t.y).minus(e.y.times(t.x)),Cn=(e,t)=>e.x.times(t.x).plus(e.y.times(t.y)),In=e=>Cn(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 An(i,r).div(In(i)).div(In(r))},Mn=(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 Cn(i,r).div(In(i)).div(In(r))},kn=(e,t,n)=>t.y.isZero()?null:{x:e.x.plus(t.x.div(t.y).times(n.minus(e.y))),y:n},Rn=(e,t,n)=>t.x.isZero()?null:{x:n,y:e.y.plus(t.y.div(t.x).times(n.minus(e.x)))},Nn=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:Hn.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:Mn(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}}},On=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!==xn.orient(r,e,i)&&(t.push(r),e=r)}if(1===t.length)return null;const n=t[0],r=t[1];0===xn.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];Nn.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}}},Gn=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}},Dn=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 Gn(r));else{const e=r.enclosingRing();e?.poly||t.push(new Gn(e)),e?.poly?.addInterior(r)}}return t}},Vn=class{queue;tree;segments;constructor(e,t=Hn.compare){this.queue=e,this.tree=new fn(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=Nn.comparePoints(o,s)<=0?o:s}this.queue.delete(t.rightSE),n.push(t.rightSE);const r=t.split(e);for(let e=0,t=r.length;e<t;e++)n.push(r[e])}n.length>0?(this.tree.delete(t),n.push(e)):(this.segments.push(t),t.prev=r)}else{if(r&&i){const e=r.getIntersection(i);if(null!==e){if(!r.isAnEndpoint(e)){const t=this._splitSafely(r,e);for(let e=0,r=t.length;e<r;e++)n.push(t[e])}if(!i.isAnEndpoint(e)){const t=this._splitSafely(i,e);for(let e=0,r=t.length;e<r;e++)n.push(t[e])}}}this.tree.delete(t)}return n}_splitSafely(e,t){this.tree.delete(e);const n=e.rightSE;this.queue.delete(n);const r=e.split(t);return r.push(n),void 0===e.consumedBy&&this.tree.add(e),r}},Fn=new class{type;numMultiPolys;run(e,t,n){Fn.type=e;const r=[new zn(t,!0)];for(let e=0,t=n.length;e<t;e++)r.push(new zn(n[e],!1));if(Fn.numMultiPolys=r.length,"difference"===Fn.type){const e=r[0];let t=1;for(;t<r.length;)null!==Tn(r[t].bbox,e.bbox)?t++:r.splice(t,1)}if("intersection"===Fn.type)for(let e=0,t=r.length;e<t;e++){const t=r[e];for(let n=e+1,i=r.length;n<i;n++)if(null===Tn(t.bbox,r[n].bbox))return[]}const i=new fn(Nn.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 Vn(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}xn.reset();const a=On.factory(o.segments);return new Dn(a).getGeom()}},Bn=Fn,Un=0,Hn=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=++Un,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=Nn.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 Nn(i,!0),u=new Nn(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 xn.orient(this.leftSE.point,e,this.rightSE.point)}getIntersection(e){const t=this.bbox(),n=e.bbox(),r=Tn(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=_n(t,s)&&0===this.comparePoint(s),u=_n(n,i)&&0===e.comparePoint(i),c=_n(t,a)&&0===this.comparePoint(a),p=_n(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 Rn(n,r,e.x);if(r.x.isZero())return Rn(e,t,n.x);if(t.y.isZero())return kn(n,r,e.y);if(r.y.isZero())return kn(e,t,n.y);const i=An(t,r);if(i.isZero())return null;const o={x:n.x.minus(e.x),y:n.y.minus(e.y)},s=An(o,t).div(i),a=An(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:_n(r,h)?xn.snap(h):null}split(t){const n=[],r=void 0!==t.events,i=new Nn(t,!0),o=new Nn(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 Nn.comparePoints(a.leftSE.point,a.rightSE.point)>0&&a.swapEvents(),Nn.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}},qn=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=xn.snap({x:new cn(e[0][0]),y:new cn(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=xn.snap({x:new cn(e[t][0]),y:new cn(e[t][1])});n.x.eq(i.x)&&n.y.eq(i.y)||(this.segments.push(Hn.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(Hn.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}},jn=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 qn(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 qn(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}},zn=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 cn(Number.POSITIVE_INFINITY),y:new cn(Number.POSITIVE_INFINITY)},ur:{x:new cn(Number.NEGATIVE_INFINITY),y:new cn(Number.NEGATIVE_INFINITY)}};for(let t=0,n=e.length;t<n;t++){const n=new jn(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}};xn.set;var Wn=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 Yn=(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=Dt(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}`})))},$n=([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))},Kn=(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($n(e[n],e[r])<t)return!0;return!1})(n,t))},Xn=(e,t=.01)=>{if(e.length<=1)return!0;const n=e[e.length-1],r=e[e.length-2];return $n(n,r)>=t},Zn=e=>e[0].length<=1||Kn(e),Jn="_splitter",Qn=({draw:e,polygonFeature:t,feature:n})=>{const r=((e,t)=>{const n=t.geometry?.coordinates;return!(!n||n.length<2||!Yn(e,{geometry:t.geometry}))})(t,n);return e.setDrawingPreviewProperty("splitter",r?"valid":"invalid"),r},er=e=>e?{valid:!0}:{valid:!1,reason:"Line does not split the shape into two parts"},tr=({draw:e,dispatch:t,polygonFeature:n})=>({feature:r,phase:i})=>i===f?er((({draw:e,dispatch:t,polygonFeature:n,feature:r})=>{const i=Qn({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},nr=()=>"undefined"!=typeof navigator&&/mac/i.test(navigator.userAgentData?.platform||navigator.platform||""),rr=nr()?"<kbd>Command</kbd> + <kbd>Z</kbd>":"<kbd>Ctrl</kbd> + <kbd>Z</kbd>",ir=nr()?"<kbd>Option</kbd>":"<kbd>Alt</kbd>",or="top-middle",sr=({checkSlow:e,holding:t})=>!(!e||!t),ar=(e,t="actions")=>({mobile:{slot:t,showLabel:e},tablet:{slot:t,showLabel:e},desktop:{slot:t,showLabel:e}}),lr={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;De({mapState:o,pluginState:l,services:c,mapProvider:p,spatialListRegistry:r.spatialListRegistry,viewportRef:r.layoutRefs.viewportRef});const S=e(!1);S.current=!l.holding&&($e({appState:r,pluginState:l})||u(l.mode)&&"keyboard"===r.interfaceType),Ke({mapState:o,pluginConfig:s,pluginState:l,mapProvider:p,eventBus:y,symbolRegistry:v}),n(()=>{if(l.mode)return f(Ye),()=>g(Ye);g(Ye)},[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 ke({appState:r,appConfig:i,mapState:o,mapProvider:p,buttonConfig:h,pluginState:l,eventBus:y,hints:m,announce:c.announce})},[p,r,l])},applicationModes:{[Ye]:{include:["mapStyles","mapControls","scaleBar"]}},buttons:[{id:"drawCancel",label:"Cancel",variant:"tertiary",exclusiveSlot:!0,hiddenWhen:({pluginState:e})=>!e.mode,...ar(!0)},{id:"drawAddPoint",label:"Add point",variant:"primary",exclusiveSlot:!0,hiddenWhen:({appState:e,pluginState:t})=>!$e({appState:e,pluginState:t}),enableWhen:({pluginState:e})=>e.canAddPoint&&!e.holding,...ar(!0)},{id:"drawDone",label:({pluginState:e})=>sr(e)?"Checking…":"Done",busyWhen:({pluginState:e})=>sr(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},...ar(!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),...ar(!1,or)},{id:"drawSnap",label:"Snap",iconId:"magnet",hiddenWhen:({pluginState:e})=>!e.mode||!e.hasSnapLayers,enableWhen:({pluginState:e})=>!e.holding,pressedWhen:({pluginState:e})=>!!e.snap,...ar(!0,or)},{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,...ar(!1,or)}],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:`${ir} + <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:rr}],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:Qe,newLine:et,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,onGeometryFinish:g,...y}=l;Ee(c,{onGeometryChange:d,onGeometryPreview:f,onGeometryFinish:g},n,p),p.emit("draw:started",{mode:"draw_point",featureId:a});const m=void 0===l.snapLayers?n.snapLayers??null:l.snapLayers;c.setSnapLayers(m),u({type:"SET_HAS_SNAP_LAYERS",payload:m?.length>0});const v={};pe.forEach(e=>{void 0!==y[e]&&(v[e]=y[e],delete y[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,...y,properties:{...h,...v}}),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,...Ze({stroke:o,fill:s,strokeWidth:a})}};(e=>tt.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))(nt.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})({...Ze(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,f=u._finishValidator;u._previewValidator=(({draw:e,polygonFeature:t})=>({feature:n,phase:r})=>"preview"===r?er(Qn({draw:e,polygonFeature:t,feature:n})):{valid:!0})({draw:u,polygonFeature:p}),u._commitValidator=tr({draw:u,dispatch:l,polygonFeature:p}),u._finishValidator=null,ye(u).reset();const y=["stroke-inactive.cold",...a.snapLayers||[]];u.setSnapLayers(y),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:Jn,properties:{splitter:"invalid"}});const m=()=>{u._previewValidator=h,u._commitValidator=d,u._finishValidator=f,u.off(g.CREATE,v),u.off(g.CANCEL,E)},v=e=>{m(),u.delete(Jn);const t=Yn(p,e);l({type:"SET_ACTION",payload:{name:"split",isValid:!!t}}),t&&c.emit("draw:split",{originalFeatureId:s,featureCollection:t})},E=()=>{m()};u.on(g.CREATE,v),u.on(g.CANCEL,E),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=Wn(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 ur=Object.freeze({__proto__:null,manifest:lr});export{g as A,ee as B,f as C,ur as D,We as K,F as M,Q as P,je as S,ze as T,ae as a,Zn as b,I as c,Xn 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,qe as s,se as t,ce as u,ie as v,Ve as w,oe as x,le as y,re 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",canFinish:!1,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_CAN_FINISH:(e,t)=>({...e,canFinish:!!t}),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 k(e){var t=[];return I(e,function(e){t.push(e)}),t}function M(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){M(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 M(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 F={Polygon:3,LineString:2},B=e=>e?.geometry??e,H=e=>{const t=B(e);return"Polygon"===t?.type?t:null},U=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},j=e=>[...e,e[0]],q=(e,t,n)=>(t[0]-e[0])*(n[1]-e[1])-(t[1]-e[1])*(n[0]-e[0]),$=(e,t)=>e>0&&t<0||e<0&&t>0,z=(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),W=(e,t,n,r)=>{const i=q(n,r,e),o=q(n,r,t),s=q(e,t,n),a=q(e,t,r);return!(!$(i,o)||!$(s,a))||(z(i,n,e,r)||z(o,n,t,r)||z(s,e,n,t)||z(a,e,r,t))},Y=(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)&&W(e[i],e[(i+1)%n],e[o],e[(o+1)%n]))return!0}return!1},K=e=>{const t=H(e);if(!t)return{valid:!0};const n=U(t);return n.length<4?{valid:!0}:Y(n,!0)?{valid:!1,reason:"Shape must not intersect itself"}:{valid:!0}},X=e=>{const t=H(e);if(!t)return{valid:!0};const n=U(t);if(n.length<F.Polygon)return{valid:!0};let r=0;try{r=V({type:"Feature",geometry:{type:"Polygon",coordinates:[j(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=B(e);return"Polygon"===t?.type?U(t).length>=F.Polygon?{valid:!0}:{valid:!1,reason:Z.Polygon}:"LineString"===t?.type?(t.coordinates?.length??0)>=F.LineString?{valid:!0}:{valid:!1,reason:Z.LineString}:{valid:!0}}],Q=[K,X],ee=[e=>(e=>{const t=H(e);if(!t)return!1;const n=U(t);return!(n.length<4)&&Y(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,reopen:o,properties:s}=e,a=!1!==t;return{valid:a,reason:n,...r&&{announcement:r},...i&&{recheckOnFinish:!0},...a&&o&&{reopen:!0},...a&&null!=s&&{properties:s}}},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=F[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=>"sortKey"===e||e.startsWith("symbol")&&!pe.has(e),de=e=>{if(!e?.properties)return e;const t={};for(const[n,r]of Object.entries(e.properties))he(n)||(t[n]=r);return{...e,properties:t}},fe={revision:0,status:"idle",result:null,feature:null,context:null,slow:!1,afterPending:!1,lastResultStatus:null},ge=e=>e.valid?"valid":"invalid",ye=new Set(["invalid","error"]),me=new WeakMap,ve=e=>{let t=me.get(e);return t||(t=(()=>{let e=0,t=null,n=null,r=null,i=fe,o=null,s=null;const a=()=>{r?.abort(),r=null,clearTimeout(n)},l=(s,a,{fromCallback:l=!1}={})=>{if(s!==e)return;const u=l?a.status:i.lastResultStatus;"pending"!==a.status&&(r=null,clearTimeout(n));const c=!!a.slow,p="pending"!==a.status&&t===s;t=c?s:null,i={...a,revision:s,slow:c,afterPending:p,lastResultStatus: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,consumerCheck: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:ge(p),result:p});r=new AbortController;const h=t=>{u===e&&(ce.warn(`[draw] geometry check failed (${i?.phase})`,t),l(u,{...c,status:"error",result:{valid:!1,reason:null,source:"callback"},error:t},{fromCallback:!0}))};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:ge(t),result:t},{fromCallback:!0})};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=fe,s=null,t}}})(),me.set(e,t)),t},Ee=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},Se=e=>"Polygon"===e.type?e.coordinates.map(Ee):e.coordinates,we=(e,t)=>{const n=e?.geometry,r=t?.geometry;return!(!n||!r||n.type!==r.type)&&JSON.stringify(Se(n))===JSON.stringify(Se(r))},be=(e,t={},n={},r=null)=>{e._previewValidator=t.onGeometryPreview??n.onGeometryPreview,e._commitValidator=t.onGeometryChange??n.onGeometryChange,e._finishValidator=t.onGeometryFinish??n.onGeometryFinish;const i=ve(e).reset();if(void 0!==i){const t=e.get(i);e.delete(i),r?.emit("draw:cancelled",de(t))}},Pe=e=>{if(null===e||"object"!=typeof e)return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype},xe=new Set(["stroke","fill","strokeWidth"]),_e=e=>e.charAt(0).toUpperCase()+e.slice(1),Te=e=>{if(!e)return{};const t={};for(const[n,r]of Object.entries(e))if(xe.has(n)&&Pe(r)){const e=Object.entries(r);e.length>0&&(t[n]=e[0][1]);for(const[r,i]of e)t[`${n}${_e(r)}`]=i}else t[n]=r;return t},Ae=(e={})=>{const t={};for(const[n,r]of Object.entries(e))void 0!==r&&(t[n]=r);return t},Ce=e=>e?.mapStyles?.map(e=>e.id)??[],Ie=(e,t=[])=>xe.has(e)||pe.has(e)||[...xe].some(n=>t.some(t=>e===`${n}${_e(t)}`)),Le=(e={},t={},n=[])=>{const r=Ae(t),i={};for(const t of Object.keys(r))if(xe.has(t))for(const r of n){const n=`${t}${_e(r)}`;n in e&&(i[n]=void 0)}return{...i,...Te(r)}},ke=(e,t,n,{caller:r,styleIds:i=[]})=>{if(null==n)return{};if(!Pe(n))return ce.warn(`${r}: ignoring properties that aren't a plain object`,n),{};const o={},s=[];for(const[e,t]of Object.entries(Ae(n)))he(e)||Ie(e,i)?s.push(e):o[e]=t;return s.length&&ce.warn(`${r}: ignoring internal and style properties — use setStyle for style`,s),Object.keys(o).length&&e.setProperties(t,o),o},Me="draw:created",Re=new WeakMap,Ne=new WeakMap,Oe=new Set(["create","edit-finish"]),Ge=(e,{result:t,context:n})=>!(Oe.has(n?.phase)||"function"!=typeof e._finishValidator&&!t?.recheckOnFinish),De=e=>e._finishValidator??e._commitValidator,Ve=(e,{status:t,result:n,context:r,feature:i},o)=>"function"==typeof e._finishValidator&&Oe.has(r?.phase)&&"valid"===t&&we(i,o)?n:null,Fe=(e,t,n)=>{const r=Ve(e,ve(e).state,t)?.properties;return r?(ke(e,t.id,r,{caller:"onGeometryFinish",styleIds:Ce(n)}),e.get(t.id)):t},Be=(e,t,n)=>{const r=(({status:e,lastResultStatus:t,context:n})=>"valid"===e||"pending"===e&&"edit-start"!==n?.phase&&!ye.has(t))(n);e.setCanFinish?.(r),t({type:"SET_CAN_FINISH",payload:r})},He=(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)},Ue=({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}}),je={pending:"Checking shape",valid:"Shape check passed",invalid:"Shape check failed",error:"Shape could not be checked"},qe=({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?.(je.pending,"action"):i&&e?.("invalid"===t&&n.reason||je[t],"action")})(r,i),Be(e,t,i),"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:de(l)})}};function $e({appState:e,appConfig:t,mapState:n,draw:r,dispatch:i,eventBus:o,resetState:s}){const a=ve(r),l=(s,a)=>{Re.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),c=ve(e).state,{status:p,result:h}=c;i({type:"SET_FEATURE",payload:{feature:u,tempFeature:u}}),i({type:"SET_MODE",payload:l}),i({type:"SET_VALIDATION_STATUS",payload:p}),Be(e,i,c),e.setInvalid?.("invalid"===p),o.emit("draw:reopened",{feature:de(u),status:p,reason:h?.reason??null})})({draw:r,appState:e,appConfig:t,mapState:n,dispatch:i,eventBus:o},s,a),0)},u=(e,t)=>{"create"===t.context?.phase&&!!Ve(r,t,e)?.reopen?l(e.id,e.geometry?.type):(e=>{const t=Fe(r,e,n);s(),setTimeout(()=>r.changeMode("disabled"),0),o.emit(Me,de(t))})(e)},c=e=>{const t=(e=>{const{status:t,feature:n}=a.state;return("valid"===t||"pending"===t)&&we(n,e)&&!Ge(r,a.state)||a.run({feature:e,context:{phase:"create",mode:r.getMode()},consumerCheck:De(r)}),a.state})(e);var n;"valid"===t.status?u(e,t):"pending"===t.status?(n=e.id,a.hold(n),i({type:"SET_HOLDING",payload:!0}),setTimeout(()=>r.changeMode("disabled"),0)):l(e.id,e.geometry?.type)};return{onCreate:c,onCheckSettled:e=>{const t=a.heldId;if(void 0===t||"pending"===e.status)return;a.release();const n=r.get(t);Ge(r,e)?c(n):"valid"===e.status?u(n,e):l(t,n?.geometry?.type)},onEditFinish:e=>{const t=Fe(r,e,n);s(),setTimeout(()=>r.changeMode("disabled"),0),Re.get(r)===e.id?(Re.delete(r),o.emit(Me,de(t))):o.emit("draw:edited",de(t))}}}function ze({draw:e,dispatch:t}){const n=ve(e),r=n=>{Ne.set(e,n),t({type:"SET_HOLDING",payload:!0})},i=i=>{if("pending"===i.status&&!e._finishValidator)return void r(i.revision);if(!Ge(e,i))return void e.done();n.run({feature:i.feature,context:{phase:"edit-finish",mode:e.getMode()},consumerCheck:De(e)});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(!Ne.has(e))return;const r=Ne.get(e)===n.revision;r&&"pending"===n.status||(Ne.delete(e),r&&"valid"===n.status?i(n):t({type:"SET_HOLDING",payload:!1}))}}}function We({appState:e,appConfig:t,mapState:n,pluginState:r,mapProvider:i,buttonConfig:o,eventBus:s,hints:a,announce:l}){const{draw:u}=i,h=He(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=ve(u);return{...ze({draw:u,dispatch:f}),handleCancel:()=>{const e=u.getMode(),t=c(e)&&!!d?.id,n=t&&Re.get(u)===d.id,r=g.heldId??(n?d.id:void 0);t&&!n&&u.add(h),Re.delete(u),g.release(),u.cancel(),void 0!==r&&u.delete(r),l(),o.emit("draw:cancelled",de(h))},handleUndo:()=>u.undo(),handleDeleteVertex:()=>u.deleteVertex(),handleSnap:()=>{r.dispatch({type:"TOGGLE_SNAP"}),u.setSnapEnabled(!r.snap)},onCancel:()=>{g.reset()},...$e({appState:e,appConfig:t,mapState:n,draw:u,dispatch:f,eventBus:o,resetState:l}),...Ue({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",de(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},consumerCheck:u._commitValidator})},onPlacementBlocked:e=>{e.announcement&&a?.(e.announcement,"action"),s({...e,feature:de(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,ve(u).reset(),Ne.delete(u)}}),f=ve(u),y=qe({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 Ye="edit_vertex",Ke="draw",Xe=(e,t,n)=>{const{x:r,y:i}=e.mapToScreen(n);return{x:r*t,y:i*t}},Ze=(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,...Xe(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,...Xe(e,t,r)}))(r[s],s))}),i};function Je({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===Ye?Ze(n,r):[],i.notifyItemsChanged(Ke)};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(Ke,{getItems:()=>({items:o.current,multiselectable:!1,label:"Shape points",focusable:!1}),exclusive:!0}),()=>{i.unregisterItemProvider(Ke)}),[i,o]),t(()=>{if(e.mode===Ye)return i.claimExclusive(Ke),()=>i.releaseExclusive(Ke)},[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===Ye&&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!==Ye||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 Qe={small:1,medium:1.5,large:2},et="rgba(29,112,184,1)",tt="#ffffff",nt="rgba(11,12,12,1)",rt="rgba(212,53,28,0.5)",it={editStroke:{light:et,dark:tt},editFill:{light:"rgba(29,112,184,0.1)",dark:"rgba(255,255,255,0.1)"},editVertex:{light:et,dark:tt},editMidpoint:{light:et,dark:tt},editHalo:{light:tt,dark:nt},editActive:{light:nt,dark:tt},splitInvalid:{light:et,dark:tt},splitValid:{light:et,dark:tt},invalidStroke:{light:et,dark:tt},shapeStroke:"rgba(212,53,28,1)",shapeFill:rt,snapVertex:rt,snapMidpoint:"rgba(40,161,151,1)",snapEdge:"rgba(29,112,184,0.5)"},ot={strokeWidth:2,vertexRadius:6,midpointRadius:4,vertexHaloRadius:8,midpointHaloRadius:6,touchTargetSize:48},st={snapRadius:12},at={nudgeAmount:1,stepAmount:5},lt="draw",ut=({appState:e,pluginState:t})=>u(t.mode)&&("touch"===e.interfaceType||!!e.expandedButtons?.has("mapControls"));function ct({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 pt=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,onGeometryFinish:E,...S}=u;be(p,{onGeometryChange:m,onGeometryPreview:v,onGeometryFinish:E},r,h),h.emit("draw:started",{mode:e,featureId:l});const w=void 0===u.snapLayers?r.snapLayers??null:u.snapLayers;p.setSnapLayers(w),c({type:"SET_HAS_SNAP_LAYERS",payload:w?.length>0});const b={...y,...Te({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,...S,properties:b}),c({type:"SET_MODE",payload:e})},ht=pt("draw_polygon"),dt=pt("draw_line"),ft=new Set(["Point","LineString","Polygon"]),gt=new Set(["stroke","fill","strokeWidth"]),yt=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,void 0===t?null:t]));function mt(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return vt(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 vt(e)}),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return St(e);default:throw new Error("unknown GeoJSON type")}}function vt(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=Et(e.properties),t.geometry=St(e.geometry),t}function Et(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]=Et(r):t[n]=r}),t):t}function St(e){var t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(function(e){return St(e)}),t):(t.coordinates=wt(e.coordinates),t)}function wt(e){var t=e;return"object"!=typeof t[0]?t.slice():t.map(function(e){return wt(e)})}function bt(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 Pt(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 xt(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=mt(e));var o=[];switch(e.type){case"GeometryCollection":return M(e,function(e){_t(e,r)}),e;case"FeatureCollection":return L(e,function(e){L(_t(e,r),function(e){o.push(e)})}),b(o)}return _t(e,r)}function _t(e,t){switch("Feature"===e.type?e.geometry.type:e.type){case"GeometryCollection":return M(e,function(e){_t(e,t)}),e;case"LineString":return Tt(Pt(e),t),e;case"Polygon":return At(Pt(e),t),e;case"MultiLineString":return Pt(e).forEach(function(e){Tt(e,t)}),e;case"MultiPolygon":return Pt(e).forEach(function(e){At(e,t)}),e;case"Point":case"MultiPoint":return e}}function Tt(e,t){bt(e)===t&&e.reverse()}function At(e,t){bt(e[0])!==t&&e[0].reverse();for(var n=1;n<e.length;n++)bt(e[n])===t&&e[n].reverse()}const Ct=11102230246251565e-32,It=134217729,Lt=(3+8*Ct)*Ct;function kt(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 Rt=Mt(4),Nt=Mt(8),Ot=Mt(12),Gt=Mt(16),Dt=Mt(4);function Vt(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=It*_,d=h-(h-_),f=_-d,h=It*C,g=h-(h-C),y=C-g,w=f*y-(S-d*g-f*g-d*y),b=A*T,h=It*A,d=h-(h-A),f=A-d,h=It*T,g=h-(h-T),y=T-g,P=f*y-(b-d*g-f*g-d*y),m=w-P,p=w-m,Rt[0]=w-(m+p)+(p-P),v=S+m,p=v-S,E=S-(v-p)+(m-p),m=E-b,p=E-m,Rt[1]=E-(m+p)+(p-b),x=v+m,p=x-v,Rt[2]=v-(x-p)+(m-p),Rt[3]=x;let I=function(e,t){let n=t[0];for(let r=1;r<e;r++)n+=t[r];return n}(4,Rt),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+Lt*Math.abs(I),I+=_*c+C*a-(A*u+T*l),I>=L||-I>=L)return I;S=a*C,h=It*a,d=h-(h-a),f=a-d,h=It*C,g=h-(h-C),y=C-g,w=f*y-(S-d*g-f*g-d*y),b=l*T,h=It*l,d=h-(h-l),f=l-d,h=It*T,g=h-(h-T),y=T-g,P=f*y-(b-d*g-f*g-d*y),m=w-P,p=w-m,Dt[0]=w-(m+p)+(p-P),v=S+m,p=v-S,E=S-(v-p)+(m-p),m=E-b,p=E-m,Dt[1]=E-(m+p)+(p-b),x=v+m,p=x-v,Dt[2]=v-(x-p)+(m-p),Dt[3]=x;const k=kt(4,Rt,4,Dt,Nt);S=_*c,h=It*_,d=h-(h-_),f=_-d,h=It*c,g=h-(h-c),y=c-g,w=f*y-(S-d*g-f*g-d*y),b=A*u,h=It*A,d=h-(h-A),f=A-d,h=It*u,g=h-(h-u),y=u-g,P=f*y-(b-d*g-f*g-d*y),m=w-P,p=w-m,Dt[0]=w-(m+p)+(p-P),v=S+m,p=v-S,E=S-(v-p)+(m-p),m=E-b,p=E-m,Dt[1]=E-(m+p)+(p-b),x=v+m,p=x-v,Dt[2]=v-(x-p)+(m-p),Dt[3]=x;const M=kt(k,Nt,4,Dt,Ot);S=a*c,h=It*a,d=h-(h-a),f=a-d,h=It*c,g=h-(h-c),y=c-g,w=f*y-(S-d*g-f*g-d*y),b=l*u,h=It*l,d=h-(h-l),f=l-d,h=It*u,g=h-(h-u),y=u-g,P=f*y-(b-d*g-f*g-d*y),m=w-P,p=w-m,Dt[0]=w-(m+p)+(p-P),v=S+m,p=v-S,E=S-(v-p)+(m-p),m=E-b,p=E-m,Dt[1]=E-(m+p)+(p-b),x=v+m,p=x-v,Dt[2]=v-(x-p)+(m-p),Dt[3]=x;const R=kt(M,Ot,4,Dt,Gt);return Gt[R-1]}(e,t,n,r,i,o,u)}function Ft(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=Vt(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 Bt=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},Ht=function(e){this.p=e},Ut=function(e,t){this.id=e,this.rawCoords=t};function jt(e,t){return!(e.maxX<t[0])&&(!(e.minX>t[2])&&(!(e.maxY<t[1])&&!(e.minY>t[3])))}var qt=function(e,t,n,r){this.p=e,this.polylineEdge=t,this.polygonEdge=n,this.isHeadingIn=r,this.distanceFromPolylineEdgeStart=$t(this.polylineEdge.p1.p,this.p),this.distanceFromPolygonEdgeStart=$t(this.polygonEdge.p1.p,this.p),this.polygonEdge.intersectionPoints.push(this),this.polylineEdge.intersectionPoints.push(this),this.visitCount=0};function $t(e,t){var n=t[0]-e[0],r=t[1]-e[1];return n*=n,r*=r,Math.sqrt(n+r)}qt.prototype.incrementVisitCount=function(){this.visitCount=this.visitCount+1};var zt=1e-9;function Wt(e,t){return e[0]*t[1]-e[1]*t[0]}function Yt(e,t){return e[0]*t[0]+e[1]*t[1]}function Kt(e,t,n){return[e[0]+t*n[0],e[1]+t*n[1]]}function Xt(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=Wt(r,i),a=s*s,l=Yt(r,r);if(a>0){var u=Wt(o,i)/s;if(u<0||u>1)return null;var c=Wt(o,r)/s;return c<0||c>1?null:0===u||1===u?[Kt(e.p1.p,u,r)]:0===c||1===c?[Kt(t.p1.p,c,i)]:[Kt(e.p1.p,u,r)]}var p=Yt(o,o);if((a=(s=Wt(o,r))*s)>zt*l*p)return null;var h=Yt(r,o)/l,d=h+Yt(r,i)/l,f=Math.min(h,d),g=Math.max(h,d);return f<=1&&g>=0?1===f?[Kt(e.p1.p,f>0?f:0,r)]:0===g?[Kt(e.p1.p,g<1?g:1,r)]:[Kt(e.p1.p,f>0?f:0,r),Kt(e.p1.p,g<1?g:1,r)]:null}function Zt(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 Ht(l[c][0]),d=null,f={nextEdge:null},g=0;g<p;g++){d=new Ht(l[c][g+1]),h.nextPoint=d,d.prevPoint=h;var y=new Bt(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 Ut(o,P));for(var _=new Ht(P[0]),T=_,A=void 0,C=null,I={nextEdge:null,prevEdge:null},L=null,k=1;k<x;k++)A=new Ht(P[k]),T.nextPoint=A,A.prevPoint=T,C=new Bt(T,A,"polygon",u,o),I.nextEdge=C,C.prevEdge=I,1===k&&(L=C),b>0&&(C.interiorRing=!0),C.intersectPolylineBbox=jt(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}(xt(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=Xt(l,u);if(null!==c)for(o=0;o<c.length;o++){var p=Vt(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 qt(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=tn(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?on:rn)(v,m))!==h&&(v=tn(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])en(Qt(Jt(r,parseInt(A)),o),x)}return{type:"Feature",properties:{},geometry:{type:"MultiPolygon",coordinates:x}}}function Jt(e,t){for(var n=0;n<e.length;n++){var r=e[n];if(r.polygonContourId===t)return r}}function Qt(e,t){return t.find(function(t){return t.id===e.polygonContourId}).rawCoords}function en(e,t){for(var n=0;n<t.length;n++){var r=t[n];if(Ft(e[0],[r[0]]))return void r.push(e)}t.push([e])}function tn(e,t){var n=e.polygonEdge;if(n.intersectionPoints.length>1&&n.intersectionPoints[n.intersectionPoints.length-1]!==e){var r=nn(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 nn(e,t){for(var n=0;n<t.length;n++){if(t[n]===e)return n}return null}function rn(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=nn(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 on(e,t){var n=e.polylineEdge;if(n.intersectionPoints.length>1&&n.intersectionPoints[n.intersectionPoints.length-1]!==e){var r=nn(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 sn=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,an=Math.ceil,ln=Math.floor,un="[BigNumber Error] ",cn=un+"Number primitive has more than 15 significant digits: ",pn=1e14,hn=14,dn=9007199254740991,fn=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],gn=1e7,yn=1e9;function mn(e){var t=0|e;return e>0||e===t?t:t-1}function vn(e){for(var t,n,r=1,i=e.length,o=e[0]+"";r<i;){for(t=e[r++]+"",n=hn-t.length;n--;t="0"+t);o+=t}for(i=o.length;48===o.charCodeAt(--i););return o.slice(0,i+1||1)}function En(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 Sn(e,t,n,r){if(e<t||e>n||e!==ln(e))throw Error(un+(r||"Argument")+("number"==typeof e?e<t||e>n?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function wn(e){var t=e.c.length-1;return mn(e.e/hn)==t&&e.c[t]%2!=0}function bn(e,t){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(t<0?"e":"e+")+t}function Pn(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 xn=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(!sn.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(Sn(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(cn+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>dn||e!==ln(e)))throw Error(cn+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)%hn,a<0&&(l+=hn),l<c){for(l&&h.c.push(+p.slice(0,l)),c-=hn;l<c;)h.c.push(+p.slice(l,l+=hn));l=hn-(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:Sn(n,0,8),!e.c)return e.toString();if(i=e.c[0],s=e.e,null==t)l=vn(e.c),l=1==r||2==r&&(s<=y||s>=m)?bn(l,s):Pn(l,s,"0");else if(o=(e=L(new T(e),t,n)).e,a=(l=vn(e.c)).length,1==r||2==r&&(t<=o||o<=y)){for(;a<t;l+="0",a++);l=bn(l,o)}else if(t-=s+(2===r&&o>s),l=Pn(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=En(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*hn-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=fn;if(p){e:{for(i=1,a=p[0];a>=10;a/=10,i++);if((o=t-i)<0)o+=hn,s=t,l=p[u=0],c=ln(l/h[i-s-1]%10);else if((u=an((o+1)/hn))>=p.length){if(!r)break e;for(;p.length<=u;p.push(0));l=c=0,i=1,s=(o%=hn)-hn+1}else{for(l=a=p[u],i=1;a>=10;a/=10,i++);c=(s=(o%=hn)-hn+i)<0?0:ln(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[(hn-t%hn)%hn],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[hn-o],p[u]=s>0?ln(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]==pn&&(p[0]=1));break}if(p[u]+=a,p[u]!=pn)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 k(e){var t,n=e.e;return null===n?e.toString():(t=vn(e.c),t=n<=y||n>=m?bn(t,n):Pn(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(un+"Object expected: "+e);if(e.hasOwnProperty(t="DECIMAL_PLACES")&&(Sn(n=e[t],0,yn,t),f=n),e.hasOwnProperty(t="ROUNDING_MODE")&&(Sn(n=e[t],0,8,t),g=n),e.hasOwnProperty(t="EXPONENTIAL_AT")&&((n=e[t])&&n.pop?(Sn(n[0],-yn,0,t),Sn(n[1],0,yn,t),y=n[0],m=n[1]):(Sn(n,-yn,yn,t),y=-(m=n<0?-n:n))),e.hasOwnProperty(t="RANGE"))if((n=e[t])&&n.pop)Sn(n[0],-yn,-1,t),Sn(n[1],1,yn,t),v=n[0],E=n[1];else{if(Sn(n,-yn,yn,t),!n)throw Error(un+t+" cannot be zero: "+n);v=-(E=n<0?-n:n)}if(e.hasOwnProperty(t="CRYPTO")){if((n=e[t])!==!!n)throw Error(un+t+" not true or false: "+n);if(n){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw S=!n,Error(un+"crypto unavailable");S=n}else S=n}if(e.hasOwnProperty(t="MODULO_MODE")&&(Sn(n=e[t],0,9,t),w=n),e.hasOwnProperty(t="POW_PRECISION")&&(Sn(n=e[t],0,yn,t),b=n),e.hasOwnProperty(t="FORMAT")){if("object"!=typeof(n=e[t]))throw Error(un+t+" not an object: "+n);P=n}if(e.hasOwnProperty(t="ALPHABET")){if("string"!=typeof(n=e[t])||/^.?$|[+\-.\s]|(.).*\1/.test(n))throw Error(un+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>=-yn&&i<=yn&&i===ln(i)){if(0===r[0]){if(0===i&&1===r.length)return!0;break e}if((t=(i+1)%hn)<1&&(t+=hn),String(r[0]).length==t){for(t=0;t<r.length;t++)if((n=r[t])<0||n>=pn||n!==ln(n))break e;if(0!==n)return!0}}}else if(null===r&&null===i&&(null===o||1===o||-1===o))return!0;throw Error(un+"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 ln(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:Sn(e,0,yn),i=an(e/hn),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(un+"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%=hn,i&&e&&(o=fn[hn-e],l[a]=ln(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-=hn);for(a=1,o=l[0];o>=10;o/=10,a++);a<hn&&(r-=hn-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(Pn(vn(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?Pn(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=Pn(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%gn,c=t/gn|0;for(e=e.slice();l--;)a=((i=u*(o=e[l]%gn)+(r=c*o+(s=e[l]/gn|0)*u)%gn*gn+a)/n|0)+(r/gn|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=pn,u=mn(r.e/hn)-mn(i.e/hn),_=_/hn|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=ln(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=ln(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==pn){for(c=1,_=y[0];_>=10;_/=10,c++);L(g,o+(g.e=c+u*hn-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(un+"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 En(this,new T(e,t))},h.decimalPlaces=h.dp=function(e,t){var n,r,i,o=this;if(null!=e)return Sn(e,0,yn),null==t?t=g:Sn(t,0,8),L(new T(o),e+o.e+1,t);if(!(n=o.c))return null;if(r=((i=n.length-1)-mn(this.e/hn))*hn,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(un+"Exponent not an integer: "+k(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(+k(c),s?e.s*(2-wn(e)):+k(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&&wn(e)?-0:0,c.e>-1&&(o=1/o),new T(a?1/o:o);b&&(o=an(b/hn+2))}for(s?(n=new T(.5),a&&(e.s=1),l=wn(e)):l=(i=Math.abs(+k(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=ln(i/2)))break;l=i%2}else if(L(e=e.times(n),e.e+1,1),e.e>14)l=wn(e);else{if(0===(i=+k(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:Sn(e,0,8),L(t,t.e+1,e)},h.isEqualTo=h.eq=function(e,t){return 0===En(this,new T(e,t))},h.isFinite=function(){return!!this.c},h.isGreaterThan=h.gt=function(e,t){return En(this,new T(e,t))>0},h.isGreaterThanOrEqualTo=h.gte=function(e,t){return 1===(t=En(this,new T(e,t)))||0===t},h.isInteger=function(){return!!this.c&&mn(this.e/hn)>this.c.length-2},h.isLessThan=h.lt=function(e,t){return En(this,new T(e,t))<0},h.isLessThanOrEqualTo=h.lte=function(e,t){return-1===(t=En(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/hn,u=e.e/hn,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=mn(l),u=mn(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=pn-1;r>a;){if(c[--r]<p[r]){for(n=r;n&&!c[--n];c[n]=t);--c[n],c[r]+=pn}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=mn(m.e/hn)+mn(e.e/hn),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=pn,y=gn,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/hn,s=e.e/hn,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=mn(o),s=mn(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)/pn|0,a[t]=pn===a[t]?0:a[t]%pn;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 Sn(e,1,yn),null==t?t=g:Sn(t,0,8),L(new T(o),e,t);if(!(n=o.c))return null;if(r=(i=n.length-1)*hn+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 Sn(e,-9007199254740991,dn),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(+k(s)))||l==1/0?(((t=vn(a)).length+u)%2==0&&(t+="0"),l=Math.sqrt(+t),u=mn((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))),vn(o.c).slice(0,l)===(t=vn(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&&(Sn(e,0,yn),e++),A(this,e,t,1)},h.toFixed=function(e,t){return null!=e&&(Sn(e,0,yn),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(un+"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(un+"Argument "+(l.isInteger()?"out of range: ":"not an integer: ")+k(l));if(!m)return new T(y);for(t=new T(d),c=r=new T(d),i=u=new T(d),f=vn(m),s=t.e=f.length-y.e-1,t.c[0]=fn[(a=s%hn)<0?hn+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+k(this)},h.toPrecision=function(e,t){return null!=e&&Sn(e,1,yn),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?bn(vn(n.c),o):Pn(vn(n.c),o,"0"):10===e&&_?t=Pn(vn((n=L(new T(n),f+o+1,g)).c),n.e,"0"):(Sn(e,2,x.length,"Base"),t=r(Pn(vn(n.c),o,"0"),10,e,i,!0)),i<0&&n.c[0]&&(t="-"+t)),t},h.valueOf=h.toJSON=function(){return k(this)},h._isBigNumber=!0,h[Symbol.toStringTag]="BigNumber",h[Symbol.for("nodejs.util.inspect.custom")]=h.valueOf,null!=t&&T.set(t),T}(),_n=class{key;left=null;right=null;constructor(e){this.key=e}},Tn=class extends _n{constructor(e){super(e)}},An=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)}}},Cn=class e extends An{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 Tn(e),t),this}addAndReturn(e){const t=this.splay(e);return 0!=t&&this.addNewRoot(new Tn(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 Tn(e.key);return function e(t,n){let r,i;do{if(r=t.left,i=t.right,null!=r){const t=new Tn(r.key);n.left=t,e(r,t)}if(null!=i){const e=new Tn(i.key);n.right=e,t=i,n=e}}while(null!=i)}(e,t),t}toSet(){return this.clone()}entries(){return new kn(this.wrap())}keys(){return this[Symbol.iterator]()}values(){return this[Symbol.iterator]()}[Symbol.iterator](){return new Ln(this.wrap())}[Symbol.toStringTag]="[object Set]"},In=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}},Ln=class extends In{getValue(e){return e.key}},kn=class extends In{getValue(e){return[e.key,e.key]}},Mn=e=>()=>e,Rn=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 Nn(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 On=e=>e,Gn=e=>{if(e){const t=new Cn(Rn(e)),n=new Cn(Rn(e)),r=(e,t)=>t.addAndReturn(e),i=e=>({x:r(e.x,t),y:r(e.y,n)});return i({x:new xn(0),y:new xn(0)}),i}return On},Dn=e=>({set:e=>{Vn=Dn(e)},reset:()=>Dn(e),compare:Rn(e),snap:Gn(e),orient:Nn(e)}),Vn=Dn(),Fn=(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),Bn=(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}}},Hn=(e,t)=>e.x.times(t.y).minus(e.y.times(t.x)),Un=(e,t)=>e.x.times(t.x).plus(e.y.times(t.y)),jn=e=>Un(e,e).sqrt(),qn=(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 Hn(i,r).div(jn(i)).div(jn(r))},$n=(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 Un(i,r).div(jn(i)).div(jn(r))},zn=(e,t,n)=>t.y.isZero()?null:{x:e.x.plus(t.x.div(t.y).times(n.minus(e.y))),y:n},Wn=(e,t,n)=>t.x.isZero()?null:{x:n,y:e.y.plus(t.y.div(t.x).times(n.minus(e.x)))},Yn=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:nr.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:qn(this.point,e.point,r.point),cosine:$n(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}}},Kn=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!==Vn.orient(r,e,i)&&(t.push(r),e=r)}if(1===t.length)return null;const n=t[0],r=t[1];0===Vn.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];Yn.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}}},Xn=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}},Zn=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 Xn(r));else{const e=r.enclosingRing();e?.poly||t.push(new Xn(e)),e?.poly?.addInterior(r)}}return t}},Jn=class{queue;tree;segments;constructor(e,t=nr.compare){this.queue=e,this.tree=new Cn(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=Yn.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}},Qn=new class{type;numMultiPolys;run(e,t,n){Qn.type=e;const r=[new or(t,!0)];for(let e=0,t=n.length;e<t;e++)r.push(new or(n[e],!1));if(Qn.numMultiPolys=r.length,"difference"===Qn.type){const e=r[0];let t=1;for(;t<r.length;)null!==Bn(r[t].bbox,e.bbox)?t++:r.splice(t,1)}if("intersection"===Qn.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===Bn(t.bbox,r[n].bbox))return[]}const i=new Cn(Yn.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 Jn(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}Vn.reset();const a=Kn.factory(o.segments);return new Zn(a).getGeom()}},er=Qn,tr=0,nr=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=++tr,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=Yn.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 Yn(i,!0),u=new Yn(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 Vn.orient(this.leftSE.point,e,this.rightSE.point)}getIntersection(e){const t=this.bbox(),n=e.bbox(),r=Bn(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=Fn(t,s)&&0===this.comparePoint(s),u=Fn(n,i)&&0===e.comparePoint(i),c=Fn(t,a)&&0===this.comparePoint(a),p=Fn(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 Wn(n,r,e.x);if(r.x.isZero())return Wn(e,t,n.x);if(t.y.isZero())return zn(n,r,e.y);if(r.y.isZero())return zn(e,t,n.y);const i=Hn(t,r);if(i.isZero())return null;const o={x:n.x.minus(e.x),y:n.y.minus(e.y)},s=Hn(o,t).div(i),a=Hn(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:Fn(r,h)?Vn.snap(h):null}split(t){const n=[],r=void 0!==t.events,i=new Yn(t,!0),o=new Yn(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 Yn.comparePoints(a.leftSE.point,a.rightSE.point)>0&&a.swapEvents(),Yn.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(er.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===er.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}},rr=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=Vn.snap({x:new xn(e[0][0]),y:new xn(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=Vn.snap({x:new xn(e[t][0]),y:new xn(e[t][1])});n.x.eq(i.x)&&n.y.eq(i.y)||(this.segments.push(nr.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(nr.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}},ir=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 rr(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 rr(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}},or=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 xn(Number.POSITIVE_INFINITY),y:new xn(Number.POSITIVE_INFINITY)},ur:{x:new xn(Number.NEGATIVE_INFINITY),y:new xn(Number.NEGATIVE_INFINITY)}};for(let t=0,n=e.length;t<n;t++){const n=new ir(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}};Vn.set;var sr=function(e,t={}){const n=[];if(M(e,e=>{n.push(e.coordinates)}),n.length<2)throw new Error("Must have at least 2 geometries");const r=((e,...t)=>er.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 ar=(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=Zt(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}`})))},lr=([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))},ur=(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(lr(e[n],e[r])<t)return!0;return!1})(n,t))},cr=(e,t=.01)=>{if(e.length<=1)return!0;const n=e[e.length-1],r=e[e.length-2];return lr(n,r)>=t},pr=e=>e[0].length<=1||ur(e),hr="_splitter",dr=({draw:e,polygonFeature:t,feature:n})=>{const r=((e,t)=>{const n=t.geometry?.coordinates;return!(!n||n.length<2||!ar(e,{geometry:t.geometry}))})(t,n);return e.setDrawingPreviewProperty("splitter",r?"valid":"invalid"),r},fr=({draw:e,dispatch:t,polygonFeature:n})=>({feature:r,phase:i})=>{return i===f?(o=(({draw:e,dispatch:t,polygonFeature:n,feature:r})=>{const i=dr({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}),o?{valid:!0}:{valid:!1,reason:"Line does not split the shape into two parts"}):{valid:!0};var o},gr=()=>"undefined"!=typeof navigator&&/mac/i.test(navigator.userAgentData?.platform||navigator.platform||""),yr=gr()?"<kbd>Command</kbd> + <kbd>Z</kbd>":"<kbd>Ctrl</kbd> + <kbd>Z</kbd>",mr=gr()?"<kbd>Option</kbd>":"<kbd>Alt</kbd>",vr="top-middle",Er=({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}}),wr={reducer:{initialState:{mode:null,action:null,actionValid:!1,feature:null,tempFeature:null,selectedVertexIndex:-1,numVertices:null,validationStatus:"idle",canFinish:!1,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;Je({mapState:o,pluginState:l,services:c,mapProvider:p,spatialListRegistry:r.spatialListRegistry,viewportRef:r.layoutRefs.viewportRef});const S=e(!1);S.current=!l.holding&&(ut({appState:r,pluginState:l})||u(l.mode)&&"keyboard"===r.interfaceType),ct({mapState:o,pluginConfig:s,pluginState:l,mapProvider:p,eventBus:y,symbolRegistry:v}),n(()=>{if(l.mode)return f(lt),()=>g(lt);g(lt)},[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 We({appState:r,appConfig:i,mapState:o,mapProvider:p,buttonConfig:h,pluginState:l,eventBus:y,hints:m,announce:c.announce})},[p,r,l])},applicationModes:{[lt]:{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})=>!ut({appState:e,pluginState:t}),enableWhen:({pluginState:e})=>e.canAddPoint&&!e.holding,...Sr(!0)},{id:"drawDone",label:({pluginState:e})=>Er(e)?"Checking…":"Done",busyWhen:({pluginState:e})=>Er(e),variant:"primary",exclusiveSlot:!0,hiddenWhen:({pluginState:e})=>!p(e.mode)&&!e.holding,enableWhen:({pluginState:e})=>{const{mode:t,canFinish:n,previewValid:r,holding:i}=e;return p(t)&&n&&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,vr)},{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,vr)},{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,vr)}],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:`${mr} + <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:yr}],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:ht,newLine:dt,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,onGeometryFinish:g,...y}=l;be(c,{onGeometryChange:d,onGeometryPreview:f,onGeometryFinish:g},n,p),p.emit("draw:started",{mode:"draw_point",featureId:a});const m=void 0===l.snapLayers?n.snapLayers??null:l.snapLayers;c.setSnapLayers(m),u({type:"SET_HAS_SNAP_LAYERS",payload:m?.length>0});const v={};pe.forEach(e=>{void 0!==y[e]&&(v[e]=y[e],delete y[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,...y,properties:{...h,...v}}),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;be(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}),ve(c).run({feature:g,context:{phase:"edit-start",mode:d},consumerCheck:c._commitValidator}),!0},addFeature:({mapState:e,mapProvider:t,services:n},r)=>{const{draw:i}=t,{eventBus:o}=n;if(!i)return;const{stroke:s,fill:a,strokeWidth:l,properties:u,...c}=r,p=Te(u),h={type:"Feature",...c,properties:Ae({...p,...Le(p,{stroke:s,fill:a,strokeWidth:l},Ce(e))})};(e=>ft.has(e.geometry?.type)&&void 0!==e.geometry?.coordinates)(h)?(i.add(h),o.emit("draw:add",de(h))):ce.warn("addFeature: ignoring invalid GeoJSON feature",h)},setStyle:({mapState:e,mapProvider:t,services:n},r,i={})=>{const{draw:o}=t,{eventBus:s}=n;if(!o)return!1;const a=o.get(r);if(!a)return ce.warn("setStyle: no feature found for id",r),!1;const l={},u={};for(const[e,t]of Object.entries(i))(gt.has(e)?l:u)[e]=t;const c={...Le(a.properties,l,Ce(e)),...Ae(u)};return o.setStyle(r,c),s.emit("draw:stylechange",{featureId:r,properties:yt(c)}),!0},setProperties:({pluginState:e,mapState:t,mapProvider:n,services:r},i,o={})=>{const{draw:s}=n,{eventBus:a}=r;if(!s)return!1;if(!s.get(i))return ce.warn("setProperties: no feature found for id",i),!1;const l=ke(s,i,o,{caller:"setProperties",styleIds:Ce(t)}),{feature:u,dispatch:p}=e;return c(s.getMode())&&u?.id===i&&p({type:"SET_FEATURE",payload:{feature:{...u,properties:{...u.properties,...l}}}}),a.emit("draw:propertieschange",{featureId:i,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,f=u._finishValidator;u._previewValidator=(({draw:e,polygonFeature:t})=>({feature:n,phase:r})=>("preview"===r&&dr({draw:e,polygonFeature:t,feature:n}),{valid:!0}))({draw:u,polygonFeature:p}),u._commitValidator=fr({draw:u,dispatch:l,polygonFeature:p}),u._finishValidator=null,ve(u).reset();const y=["stroke-inactive.cold",...a.snapLayers||[]];u.setSnapLayers(y),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:hr,properties:{splitter:"invalid"}});const m=()=>{u._previewValidator=h,u._commitValidator=d,u._finishValidator=f,u.off(g.CREATE,v),u.off(g.CANCEL,E)},v=e=>{m(),u.delete(hr);const t=ar(p,e);l({type:"SET_ACTION",payload:{name:"split",isValid:!!t}}),t&&c.emit("draw:split",{originalFeatureId:s,featureCollection:t})},E=()=>{m()};u.on(g.CREATE,v),u.on(g.CANCEL,E),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=sr(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=ve(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,consumerCheck:n._commitValidator}),!0}}};var br=Object.freeze({__proto__:null,manifest:wr});export{g as A,re as B,f as C,ee as D,br as E,at as K,F as M,Q as P,ot as S,st as T,ae as a,pr as b,I as c,cr 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,k as q,x as r,it as s,se as t,ce as u,ie as v,Qe as w,Ae as x,oe as y,le 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.E});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,s as t,
|
|
1
|
+
import{S as e,s as t,z as r,M as n,B as l,P as a,D 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};
|