@defra/interactive-map 0.0.61-alpha → 0.0.62-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/esm/im-shell.js +1 -1
- package/dist/umd/im-core.js +1 -1
- package/dist/umd/index.js +1 -1
- package/docs/api.md +20 -0
- package/package.json +1 -1
- package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
- package/plugins/datasets/src/reducers/datasetsToMenu.js +12 -9
- package/plugins/datasets/src/reducers/datasetsToMenu.test.js +42 -0
- package/plugins/datasets/src/reducers/pluginState.test.js +12 -0
- package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
- package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
- package/providers/openlayers/dist/esm/im-openlayers-provider.js +1 -1
- package/providers/openlayers/dist/umd/im-openlayers-provider.js +1 -1
- package/providers/openlayers/src/openlayersProvider.js +2 -1
- package/providers/openlayers/src/openlayersProvider.test.js +1 -1
- package/src/App/components/MapControls/MapControls.jsx +2 -1
- package/src/App/components/MapControls/MapControls.test.jsx +1 -1
- package/src/App/components/PopupMenu/PopupMenu.test.jsx +22 -0
- package/src/App/components/PopupMenu/usePopupMenu.js +9 -6
- package/src/App/components/Viewport/MapController.jsx +2 -0
- package/src/App/components/Viewport/MapController.test.jsx +3 -0
- package/src/App/hooks/useMapProviderOverrides.js +10 -5
- package/src/App/hooks/useMapProviderOverrides.test.js +11 -0
- package/src/App/hooks/useResetViewTarget.js +135 -0
- package/src/App/hooks/useResetViewTarget.test.js +211 -0
- package/src/App/hooks/useUserMoveTracking.js +7 -0
- package/src/App/hooks/useUserMoveTracking.test.js +21 -3
- package/src/App/renderer/mapButtons.js +2 -1
- package/src/App/renderer/mapButtons.test.js +12 -0
- package/src/App/store/ServiceProvider.jsx +8 -2
- package/src/App/store/ServiceProvider.test.jsx +13 -0
- package/src/App/store/mapActionsMap.js +14 -0
- package/src/App/store/mapActionsMap.test.js +11 -0
- package/src/App/store/mapReducer.js +4 -0
- package/src/App/store/mapReducer.test.js +2 -0
- package/src/InteractiveMap/InteractiveMap.js +8 -0
- package/src/InteractiveMap/InteractiveMap.test.js +5 -0
- package/src/config/appConfig.js +17 -0
- package/src/config/appConfig.test.js +28 -0
- package/src/config/defaults.js +1 -0
- package/src/config/events.js +2 -0
- package/src/services/mapFocus.js +3 -2
- package/src/services/mapFocus.test.js +10 -0
- package/src/types.js +5 -0
- package/src/utils/focusAfterPanelClose.js +3 -1
- package/src/utils/getFocusOptions.js +3 -0
- package/src/utils/getFocusOptions.test.js +11 -0
- package/src/utils/mapStateSync.js +1 -0
- package/src/utils/resetView.js +61 -0
- package/src/utils/resetView.test.js +62 -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",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 m=6371008.8,y={centimeters:637100880,centimetres:637100880,degrees:360/(2*Math.PI),feet:20902260.511392,inches:39.37*m,kilometers:6371.0088,kilometres:6371.0088,meters:m,metres:m,miles:3958.761333810546,millimeters:6371008800,millimetres:6371008800,nauticalmiles:m/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=y[t];if(!n)throw new Error(t+" units is invalid");return e*n}function _(e,t="kilometers"){const n=y[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,m=f?e.features.length:1,y=0;y<m;y++){a=(c=!!(u=f?e.features[y].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,y,E,S))return!1;h++,E++;break;case"LineString":case"MultiPoint":for(r=0;r<l.length;r++){if(!1===t(l[r],h,y,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,y,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,y,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]),z=(e,t)=>e>0&&t<0||e<0&&t>0,$=(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!(!z(i,o)||!z(s,a))||($(i,n,e,r)||$(o,n,t,r)||$(s,e,n,t)||$(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",me=new Set(["invalid","error"]),ye=new WeakMap,ve=e=>{let t=ye.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}}})(),ye.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&&!me.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 ze({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 $e({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{...$e({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()},...ze({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),m=qe({draw:u,dispatch:r.dispatch,emitGeometryInvalid:h,announce:l});return f.setOnSettle(e=>{m(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=(e,t)=>"number"==typeof e?.snapMinZoom&&"number"==typeof t&&t<e.snapMinZoom,ct=e=>e?.snapZoomInHintText??"Zoom in to use snap";const pt=({appState:e,pluginState:t})=>u(t.mode)&&("touch"===e.interfaceType||!!e.expandedButtons?.has("mapControls"));function ht({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 dt=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:m,onGeometryChange:y,onGeometryPreview:v,onGeometryFinish:E,...S}=u;be(p,{onGeometryChange:y,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={...m,...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})},ft=dt("draw_polygon"),gt=dt("draw_line"),mt=new Set(["Point","LineString","Polygon"]),yt=new Set(["stroke","fill","strokeWidth"]),vt=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,void 0===t?null:t]));function Et(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return St(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 St(e)}),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return bt(e);default:throw new Error("unknown GeoJSON type")}}function St(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=wt(e.properties),t.geometry=bt(e.geometry),t}function wt(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]=wt(r):t[n]=r}),t):t}function bt(e){var t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(function(e){return bt(e)}),t):(t.coordinates=Pt(e.coordinates),t)}function Pt(e){var t=e;return"object"!=typeof t[0]?t.slice():t.map(function(e){return Pt(e)})}function xt(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 _t(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 Tt(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=Et(e));var o=[];switch(e.type){case"GeometryCollection":return M(e,function(e){At(e,r)}),e;case"FeatureCollection":return L(e,function(e){L(At(e,r),function(e){o.push(e)})}),b(o)}return At(e,r)}function At(e,t){switch("Feature"===e.type?e.geometry.type:e.type){case"GeometryCollection":return M(e,function(e){At(e,t)}),e;case"LineString":return Ct(_t(e),t),e;case"Polygon":return It(_t(e),t),e;case"MultiLineString":return _t(e).forEach(function(e){Ct(e,t)}),e;case"MultiPolygon":return _t(e).forEach(function(e){It(e,t)}),e;case"Point":case"MultiPoint":return e}}function Ct(e,t){xt(e)===t&&e.reverse()}function It(e,t){xt(e[0])!==t&&e[0].reverse();for(var n=1;n<e.length;n++)xt(e[n])===t&&e[n].reverse()}const Lt=11102230246251565e-32,kt=134217729,Mt=(3+8*Lt)*Lt;function Rt(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 Nt(e){return new Float64Array(e)}const Ot=Nt(4),Gt=Nt(8),Dt=Nt(12),Vt=Nt(16),Ft=Nt(4);function Bt(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,m,y,v,E,S,w,b,P,x;const _=e-i,T=n-i,A=t-o,C=r-o;S=_*C,h=kt*_,d=h-(h-_),f=_-d,h=kt*C,g=h-(h-C),m=C-g,w=f*m-(S-d*g-f*g-d*m),b=A*T,h=kt*A,d=h-(h-A),f=A-d,h=kt*T,g=h-(h-T),m=T-g,P=f*m-(b-d*g-f*g-d*m),y=w-P,p=w-y,Ot[0]=w-(y+p)+(p-P),v=S+y,p=v-S,E=S-(v-p)+(y-p),y=E-b,p=E-y,Ot[1]=E-(y+p)+(p-b),x=v+y,p=x-v,Ot[2]=v-(x-p)+(y-p),Ot[3]=x;let I=function(e,t){let n=t[0];for(let r=1;r<e;r++)n+=t[r];return n}(4,Ot),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+Mt*Math.abs(I),I+=_*c+C*a-(A*u+T*l),I>=L||-I>=L)return I;S=a*C,h=kt*a,d=h-(h-a),f=a-d,h=kt*C,g=h-(h-C),m=C-g,w=f*m-(S-d*g-f*g-d*m),b=l*T,h=kt*l,d=h-(h-l),f=l-d,h=kt*T,g=h-(h-T),m=T-g,P=f*m-(b-d*g-f*g-d*m),y=w-P,p=w-y,Ft[0]=w-(y+p)+(p-P),v=S+y,p=v-S,E=S-(v-p)+(y-p),y=E-b,p=E-y,Ft[1]=E-(y+p)+(p-b),x=v+y,p=x-v,Ft[2]=v-(x-p)+(y-p),Ft[3]=x;const k=Rt(4,Ot,4,Ft,Gt);S=_*c,h=kt*_,d=h-(h-_),f=_-d,h=kt*c,g=h-(h-c),m=c-g,w=f*m-(S-d*g-f*g-d*m),b=A*u,h=kt*A,d=h-(h-A),f=A-d,h=kt*u,g=h-(h-u),m=u-g,P=f*m-(b-d*g-f*g-d*m),y=w-P,p=w-y,Ft[0]=w-(y+p)+(p-P),v=S+y,p=v-S,E=S-(v-p)+(y-p),y=E-b,p=E-y,Ft[1]=E-(y+p)+(p-b),x=v+y,p=x-v,Ft[2]=v-(x-p)+(y-p),Ft[3]=x;const M=Rt(k,Gt,4,Ft,Dt);S=a*c,h=kt*a,d=h-(h-a),f=a-d,h=kt*c,g=h-(h-c),m=c-g,w=f*m-(S-d*g-f*g-d*m),b=l*u,h=kt*l,d=h-(h-l),f=l-d,h=kt*u,g=h-(h-u),m=u-g,P=f*m-(b-d*g-f*g-d*m),y=w-P,p=w-y,Ft[0]=w-(y+p)+(p-P),v=S+y,p=v-S,E=S-(v-p)+(y-p),y=E-b,p=E-y,Ft[1]=E-(y+p)+(p-b),x=v+y,p=x-v,Ft[2]=v-(x-p)+(y-p),Ft[3]=x;const R=Rt(M,Dt,4,Ft,Vt);return Vt[R-1]}(e,t,n,r,i,o,u)}function Ht(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],m=g.length-1;if((u=g[0])[0]!==g[m][0]&&u[1]!==g[m][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<m;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=Bt(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 Ut=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},jt=function(e){this.p=e},qt=function(e,t){this.id=e,this.rawCoords=t};function zt(e,t){return!(e.maxX<t[0])&&(!(e.minX>t[2])&&(!(e.maxY<t[1])&&!(e.minY>t[3])))}var $t=function(e,t,n,r){this.p=e,this.polylineEdge=t,this.polygonEdge=n,this.isHeadingIn=r,this.distanceFromPolylineEdgeStart=Wt(this.polylineEdge.p1.p,this.p),this.distanceFromPolygonEdgeStart=Wt(this.polygonEdge.p1.p,this.p),this.polygonEdge.intersectionPoints.push(this),this.polylineEdge.intersectionPoints.push(this),this.visitCount=0};function Wt(e,t){var n=t[0]-e[0],r=t[1]-e[1];return n*=n,r*=r,Math.sqrt(n+r)}$t.prototype.incrementVisitCount=function(){this.visitCount=this.visitCount+1};var Yt=1e-9;function Kt(e,t){return e[0]*t[1]-e[1]*t[0]}function Xt(e,t){return e[0]*t[0]+e[1]*t[1]}function Zt(e,t,n){return[e[0]+t*n[0],e[1]+t*n[1]]}function Jt(e,t,n){var r=[e.p2.p[0]-e.p1.p[0],e.p2.p[1]-e.p1.p[1]],i=[t.p2.p[0]-t.p1.p[0],t.p2.p[1]-t.p1.p[1]],o=[t.p1.p[0]-e.p1.p[0],t.p1.p[1]-e.p1.p[1]],s=Kt(r,i),a=s*s,l=Xt(r,r);if(a>0){var u=Kt(o,i)/s;if(u<0||u>1)return null;var c=Kt(o,r)/s;return c<0||c>1?null:0===u||1===u?[Zt(e.p1.p,u,r)]:0===c||1===c?[Zt(t.p1.p,c,i)]:[Zt(e.p1.p,u,r)]}var p=Xt(o,o);if((a=(s=Kt(o,r))*s)>Yt*l*p)return null;var h=Xt(r,o)/l,d=h+Xt(r,i)/l,f=Math.min(h,d),g=Math.max(h,d);return f<=1&&g>=0?1===f?[Zt(e.p1.p,f>0?f:0,r)]:0===g?[Zt(e.p1.p,g<1?g:1,r)]:[Zt(e.p1.p,f>0?f:0,r),Zt(e.p1.p,g<1?g:1,r)]:null}function Qt(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 jt(l[c][0]),d=null,f={nextEdge:null},g=0;g<p;g++){d=new jt(l[c][g+1]),h.nextPoint=d,d.prevPoint=h;var m=new Ut(h,d,"polyline",u,null);r.push(m),f.nextEdge=m,m.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=m}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 y="Feature"===e.type?e.geometry:e,v="Polygon"===y.type?[y.coordinates]:y.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 qt(o,P));for(var _=new jt(P[0]),T=_,A=void 0,C=null,I={nextEdge:null,prevEdge:null},L=null,k=1;k<x;k++)A=new jt(P[k]),T.nextPoint=A,A.prevPoint=T,C=new Ut(T,A,"polygon",u,o),I.nextEdge=C,C.prevEdge=I,1===k&&(L=C),b>0&&(C.interiorRing=!0),C.intersectPolylineBbox=zt(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}(Tt(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=Jt(l,u);if(null!==c)for(o=0;o<c.length;o++){var p=Bt(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 $t(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 m=n[g];if(m.visitCount<2){h=m,f=!0;break}}if(!f)break}h.visitCount=h.visitCount+1;var y=[];l.push(y),y.push(h.p),h.visitCount=h.visitCount+1;var v=rn(h,y),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?an:sn)(v,y))!==h&&(v=rn(v,y)),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])nn(tn(en(r,parseInt(A)),o),x)}return{type:"Feature",properties:{},geometry:{type:"MultiPolygon",coordinates:x}}}function en(e,t){for(var n=0;n<e.length;n++){var r=e[n];if(r.polygonContourId===t)return r}}function tn(e,t){return t.find(function(t){return t.id===e.polygonContourId}).rawCoords}function nn(e,t){for(var n=0;n<t.length;n++){var r=t[n];if(Ht(e[0],[r[0]]))return void r.push(e)}t.push([e])}function rn(e,t){var n=e.polygonEdge;if(n.intersectionPoints.length>1&&n.intersectionPoints[n.intersectionPoints.length-1]!==e){var r=on(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 on(e,t){for(var n=0;n<t.length;n++){if(t[n]===e)return n}return null}function sn(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=on(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 an(e,t){var n=e.polylineEdge;if(n.intersectionPoints.length>1&&n.intersectionPoints[n.intersectionPoints.length-1]!==e){var r=on(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 ln=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,un=Math.ceil,cn=Math.floor,pn="[BigNumber Error] ",hn=pn+"Number primitive has more than 15 significant digits: ",dn=1e14,fn=14,gn=9007199254740991,mn=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],yn=1e7,vn=1e9;function En(e){var t=0|e;return e>0||e===t?t:t-1}function Sn(e){for(var t,n,r=1,i=e.length,o=e[0]+"";r<i;){for(t=e[r++]+"",n=fn-t.length;n--;t="0"+t);o+=t}for(i=o.length;48===o.charCodeAt(--i););return o.slice(0,i+1||1)}function wn(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 bn(e,t,n,r){if(e<t||e>n||e!==cn(e))throw Error(pn+(r||"Argument")+("number"==typeof e?e<t||e>n?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function Pn(e){var t=e.c.length-1;return En(e.e/fn)==t&&e.c[t]%2!=0}function xn(e,t){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(t<0?"e":"e+")+t}function _n(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 Tn=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,m=-7,y=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(!ln.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(bn(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(hn+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>gn||e!==cn(e)))throw Error(hn+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)%fn,a<0&&(l+=fn),l<c){for(l&&h.c.push(+p.slice(0,l)),c-=fn;l<c;)h.c.push(+p.slice(l,l+=fn));l=fn-(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:bn(n,0,8),!e.c)return e.toString();if(i=e.c[0],s=e.e,null==t)l=Sn(e.c),l=1==r||2==r&&(s<=m||s>=y)?xn(l,s):_n(l,s,"0");else if(o=(e=L(new T(e),t,n)).e,a=(l=Sn(e.c)).length,1==r||2==r&&(t<=o||o<=m)){for(;a<t;l+="0",a++);l=xn(l,o)}else if(t-=s+(2===r&&o>s),l=_n(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=wn(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*fn-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=mn;if(p){e:{for(i=1,a=p[0];a>=10;a/=10,i++);if((o=t-i)<0)o+=fn,s=t,l=p[u=0],c=cn(l/h[i-s-1]%10);else if((u=un((o+1)/fn))>=p.length){if(!r)break e;for(;p.length<=u;p.push(0));l=c=0,i=1,s=(o%=fn)-fn+1}else{for(l=a=p[u],i=1;a>=10;a/=10,i++);c=(s=(o%=fn)-fn+i)<0?0:cn(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[(fn-t%fn)%fn],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[fn-o],p[u]=s>0?cn(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]==dn&&(p[0]=1));break}if(p[u]+=a,p[u]!=dn)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=Sn(e.c),t=n<=m||n>=y?xn(t,n):_n(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(pn+"Object expected: "+e);if(e.hasOwnProperty(t="DECIMAL_PLACES")&&(bn(n=e[t],0,vn,t),f=n),e.hasOwnProperty(t="ROUNDING_MODE")&&(bn(n=e[t],0,8,t),g=n),e.hasOwnProperty(t="EXPONENTIAL_AT")&&((n=e[t])&&n.pop?(bn(n[0],-vn,0,t),bn(n[1],0,vn,t),m=n[0],y=n[1]):(bn(n,-vn,vn,t),m=-(y=n<0?-n:n))),e.hasOwnProperty(t="RANGE"))if((n=e[t])&&n.pop)bn(n[0],-vn,-1,t),bn(n[1],1,vn,t),v=n[0],E=n[1];else{if(bn(n,-vn,vn,t),!n)throw Error(pn+t+" cannot be zero: "+n);v=-(E=n<0?-n:n)}if(e.hasOwnProperty(t="CRYPTO")){if((n=e[t])!==!!n)throw Error(pn+t+" not true or false: "+n);if(n){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw S=!n,Error(pn+"crypto unavailable");S=n}else S=n}if(e.hasOwnProperty(t="MODULO_MODE")&&(bn(n=e[t],0,9,t),w=n),e.hasOwnProperty(t="POW_PRECISION")&&(bn(n=e[t],0,vn,t),b=n),e.hasOwnProperty(t="FORMAT")){if("object"!=typeof(n=e[t]))throw Error(pn+t+" not an object: "+n);P=n}if(e.hasOwnProperty(t="ALPHABET")){if("string"!=typeof(n=e[t])||/^.?$|[+\-.\s]|(.).*\1/.test(n))throw Error(pn+t+" invalid: "+n);_="0123456789"==n.slice(0,10),x=n}}return{DECIMAL_PLACES:f,ROUNDING_MODE:g,EXPONENTIAL_AT:[m,y],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>=-vn&&i<=vn&&i===cn(i)){if(0===r[0]){if(0===i&&1===r.length)return!0;break e}if((t=(i+1)%fn)<1&&(t+=fn),String(r[0]).length==t){for(t=0;t<r.length;t++)if((n=r[t])<0||n>=dn||n!==cn(n))break e;if(0!==n)return!0}}}else if(null===r&&null===i&&(null===o||1===o||-1===o))return!0;throw Error(pn+"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 cn(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:bn(e,0,vn),i=un(e/fn),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(pn+"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%=fn,i&&e&&(o=mn[fn-e],l[a]=cn(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-=fn);for(a=1,o=l[0];o>=10;o/=10,a++);a<fn&&(r-=fn-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,m,y,v=r.indexOf("."),E=f,S=g;for(v>=0&&(p=b,b=0,r=r.replace(".",""),d=(y=new T(i)).pow(r.length-v),b=p,y.c=t(_n(Sn(d.c),d.e,"0"),10,o,e),y.e=y.c.length),c=p=(m=t(r,i,o,a?(l=x,e):(l=e,x))).length;0==m[--p];m.pop());if(!m[0])return l.charAt(0);if(v<0?--c:(d.c=m,d.e=c,d.s=s,m=(d=n(d,y,E,S,o)).c,h=d.r,c=d.e),v=m[u=c+E+1],p=o/2,h=h||u<0||null!=m[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&m[u-1]||S==(d.s<0?8:7)),u<1||!m[0])r=h?_n(l.charAt(1),-E,l.charAt(0)):l.charAt(0);else{if(m.length=u,h)for(--o;++m[--u]>o;)m[u]=0,u||(++c,m=[1].concat(m));for(p=m.length;!m[--p];);for(v=0,r="";v<=p;r+=l.charAt(m[v++]));r=_n(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%yn,c=t/yn|0;for(e=e.slice();l--;)a=((i=u*(o=e[l]%yn)+(r=c*o+(s=e[l]/yn|0)*u)%yn*yn+a)/n|0)+(r/yn|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,m,y,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(m=(g=new T(_)).c=[],_=o+(u=r.e-i.e)+1,a||(a=dn,u=En(r.e/fn)-En(i.e/fn),_=_/fn|0),c=0;C[c]==(A[c]||0);c++);if(C[c]>(A[c]||0)&&u--,_<0)m.push(1),p=!0;else{for(w=A.length,P=C.length,c=0,_+=2,(h=cn(a/(C[0]+1)))>1&&(C=e(C,h,a),A=e(A,h,a),P=C.length,w=A.length),S=P,v=(y=A.slice(0,P)).length;v<P;y[v++]=0);x=C.slice(),x=[0].concat(x),b=C[0],C[1]>=a/2&&b++;do{if(h=0,(l=t(C,y,P,v))<0){if(E=y[0],P!=v&&(E=E*a+(y[1]||0)),(h=cn(E/b))>1)for(h>=a&&(h=a-1),f=(d=e(C,h,a)).length,v=y.length;1==t(d,y,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(y,d,v,a),v=y.length,-1==l)for(;t(C,y,P,v)<1;)h++,n(y,P<v?x:C,v,a),v=y.length}else 0===l&&(h++,y=[0]);m[c++]=h,y[0]?y[v++]=A[S]||0:(y=[A[S]],v=1)}while((S++<w||null!=y[0])&&_--);p=null!=y[0],m[0]||m.splice(0,1)}if(a==dn){for(c=1,_=m[0];_>=10;_/=10,c++);L(g,o+(g.e=c+u*fn-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(pn+"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 wn(this,new T(e,t))},h.decimalPlaces=h.dp=function(e,t){var n,r,i,o=this;if(null!=e)return bn(e,0,vn),null==t?t=g:bn(t,0,8),L(new T(o),e+o.e+1,t);if(!(n=o.c))return null;if(r=((i=n.length-1)-En(this.e/fn))*fn,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(pn+"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-Pn(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&&Pn(e)?-0:0,c.e>-1&&(o=1/o),new T(a?1/o:o);b&&(o=un(b/fn+2))}for(s?(n=new T(.5),a&&(e.s=1),l=Pn(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=cn(i/2)))break;l=i%2}else if(L(e=e.times(n),e.e+1,1),e.e>14)l=Pn(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:bn(e,0,8),L(t,t.e+1,e)},h.isEqualTo=h.eq=function(e,t){return 0===wn(this,new T(e,t))},h.isFinite=function(){return!!this.c},h.isGreaterThan=h.gt=function(e,t){return wn(this,new T(e,t))>0},h.isGreaterThanOrEqualTo=h.gte=function(e,t){return 1===(t=wn(this,new T(e,t)))||0===t},h.isInteger=function(){return!!this.c&&En(this.e/fn)>this.c.length-2},h.isLessThan=h.lt=function(e,t){return wn(this,new T(e,t))<0},h.isLessThanOrEqualTo=h.lte=function(e,t){return-1===(t=wn(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/fn,u=e.e/fn,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=En(l),u=En(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=dn-1;r>a;){if(c[--r]<p[r]){for(n=r;n&&!c[--n];c[n]=t);--c[n],c[r]+=dn}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,m,y=this,v=y.c,E=(e=new T(e,t)).c;if(!(v&&E&&v[0]&&E[0]))return!y.s||!e.s||v&&!v[0]&&!E||E&&!E[0]&&!v?e.c=e.e=e.s=null:(e.s*=y.s,v&&E?(e.c=[0],e.e=0):e.c=e.e=null),e;for(r=En(y.e/fn)+En(e.e/fn),e.s*=y.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=dn,m=yn,i=p;--i>=0;){for(n=0,h=E[i]%m,d=E[i]/m|0,o=i+(s=l);o>i;)n=((u=h*(u=v[--s]%m)+(a=d*u+(c=v[s]/m|0)*h)%m*m+f[o]+n)/g|0)+(a/m|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/fn,s=e.e/fn,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=En(o),s=En(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)/dn|0,a[t]=dn===a[t]?0:a[t]%dn;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 bn(e,1,vn),null==t?t=g:bn(t,0,8),L(new T(o),e,t);if(!(n=o.c))return null;if(r=(i=n.length-1)*fn+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 bn(e,-9007199254740991,gn),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=Sn(a)).length+u)%2==0&&(t+="0"),l=Math.sqrt(+t),u=En((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))),Sn(o.c).slice(0,l)===(t=Sn(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&&(bn(e,0,vn),e++),A(this,e,t,1)},h.toFixed=function(e,t){return null!=e&&(bn(e,0,vn),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(pn+"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,m=this,y=m.c;if(null!=e&&(!(l=new T(e)).isInteger()&&(l.c||1!==l.s)||l.lt(d)))throw Error(pn+"Argument "+(l.isInteger()?"out of range: ":"not an integer: ")+k(l));if(!y)return new T(m);for(t=new T(d),c=r=new T(d),i=u=new T(d),f=Sn(y),s=t.e=f.length-m.e-1,t.c[0]=mn[(a=s%fn)<0?fn+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=m.s,h=n(c,i,s*=2,g).minus(m).abs().comparedTo(n(u,r,s,g).minus(m).abs())<1?[c,i]:[u,r],E=a,h},h.toNumber=function(){return+k(this)},h.toPrecision=function(e,t){return null!=e&&bn(e,1,vn),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<=m||o>=y?xn(Sn(n.c),o):_n(Sn(n.c),o,"0"):10===e&&_?t=_n(Sn((n=L(new T(n),f+o+1,g)).c),n.e,"0"):(bn(e,2,x.length,"Base"),t=r(_n(Sn(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}(),An=class{key;left=null;right=null;constructor(e){this.key=e}},Cn=class extends An{constructor(e){super(e)}},In=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)}}},Ln=class e extends In{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 Cn(e),t),this}addAndReturn(e){const t=this.splay(e);return 0!=t&&this.addNewRoot(new Cn(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 Cn(e.key);return function e(t,n){let r,i;do{if(r=t.left,i=t.right,null!=r){const t=new Cn(r.key);n.left=t,e(r,t)}if(null!=i){const e=new Cn(i.key);n.right=e,t=i,n=e}}while(null!=i)}(e,t),t}toSet(){return this.clone()}entries(){return new Rn(this.wrap())}keys(){return this[Symbol.iterator]()}values(){return this[Symbol.iterator]()}[Symbol.iterator](){return new Mn(this.wrap())}[Symbol.toStringTag]="[object Set]"},kn=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}},Mn=class extends kn{getValue(e){return e.key}},Rn=class extends kn{getValue(e){return[e.key,e.key]}},Nn=e=>()=>e,On=e=>{const t=e?(t,n)=>n.minus(t).abs().isLessThanOrEqualTo(e):Nn(!1);return(e,n)=>t(e,n)?0:e.comparedTo(n)};function Gn(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)):Nn(!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 Dn=e=>e,Vn=e=>{if(e){const t=new Ln(On(e)),n=new Ln(On(e)),r=(e,t)=>t.addAndReturn(e),i=e=>({x:r(e.x,t),y:r(e.y,n)});return i({x:new Tn(0),y:new Tn(0)}),i}return Dn},Fn=e=>({set:e=>{Bn=Fn(e)},reset:()=>Fn(e),compare:On(e),snap:Vn(e),orient:Gn(e)}),Bn=Fn(),Hn=(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),Un=(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}}},jn=(e,t)=>e.x.times(t.y).minus(e.y.times(t.x)),qn=(e,t)=>e.x.times(t.x).plus(e.y.times(t.y)),zn=e=>qn(e,e).sqrt(),$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 jn(i,r).div(zn(i)).div(zn(r))},Wn=(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 qn(i,r).div(zn(i)).div(zn(r))},Yn=(e,t,n)=>t.y.isZero()?null:{x:e.x.plus(t.x.div(t.y).times(n.minus(e.y))),y:n},Kn=(e,t,n)=>t.x.isZero()?null:{x:n,y:e.y.plus(t.y.div(t.x).times(n.minus(e.x)))},Xn=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:ir.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:$n(this.point,e.point,r.point),cosine:Wn(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}}},Zn=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!==Bn.orient(r,e,i)&&(t.push(r),e=r)}if(1===t.length)return null;const n=t[0],r=t[1];0===Bn.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];Xn.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}}},Jn=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}},Qn=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 Jn(r));else{const e=r.enclosingRing();e?.poly||t.push(new Jn(e)),e?.poly?.addInterior(r)}}return t}},er=class{queue;tree;segments;constructor(e,t=ir.compare){this.queue=e,this.tree=new Ln(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=Xn.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}},tr=new class{type;numMultiPolys;run(e,t,n){tr.type=e;const r=[new ar(t,!0)];for(let e=0,t=n.length;e<t;e++)r.push(new ar(n[e],!1));if(tr.numMultiPolys=r.length,"difference"===tr.type){const e=r[0];let t=1;for(;t<r.length;)null!==Un(r[t].bbox,e.bbox)?t++:r.splice(t,1)}if("intersection"===tr.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===Un(t.bbox,r[n].bbox))return[]}const i=new Ln(Xn.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 er(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}Bn.reset();const a=Zn.factory(o.segments);return new Qn(a).getGeom()}},nr=tr,rr=0,ir=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=++rr,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=Xn.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 Xn(i,!0),u=new Xn(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 Bn.orient(this.leftSE.point,e,this.rightSE.point)}getIntersection(e){const t=this.bbox(),n=e.bbox(),r=Un(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=Hn(t,s)&&0===this.comparePoint(s),u=Hn(n,i)&&0===e.comparePoint(i),c=Hn(t,a)&&0===this.comparePoint(a),p=Hn(n,o)&&0===e.comparePoint(o);if(u&&l)return p&&!c?o:!p&&c?a:null;if(u)return c&&i.x.eq(a.x)&&i.y.eq(a.y)?null:i;if(l)return p&&o.x.eq(s.x)&&o.y.eq(s.y)?null:s;if(p&&c)return null;if(p)return o;if(c)return a;const h=((e,t,n,r)=>{if(t.x.isZero())return Kn(n,r,e.x);if(r.x.isZero())return Kn(e,t,n.x);if(t.y.isZero())return Yn(n,r,e.y);if(r.y.isZero())return Yn(e,t,n.y);const i=jn(t,r);if(i.isZero())return null;const o={x:n.x.minus(e.x),y:n.y.minus(e.y)},s=jn(o,t).div(i),a=jn(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:Hn(r,h)?Bn.snap(h):null}split(t){const n=[],r=void 0!==t.events,i=new Xn(t,!0),o=new Xn(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 Xn.comparePoints(a.leftSE.point,a.rightSE.point)>0&&a.swapEvents(),Xn.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(nr.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===nr.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}},or=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=Bn.snap({x:new Tn(e[0][0]),y:new Tn(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=Bn.snap({x:new Tn(e[t][0]),y:new Tn(e[t][1])});n.x.eq(i.x)&&n.y.eq(i.y)||(this.segments.push(ir.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(ir.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}},sr=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 or(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 or(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}},ar=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 Tn(Number.POSITIVE_INFINITY),y:new Tn(Number.POSITIVE_INFINITY)},ur:{x:new Tn(Number.NEGATIVE_INFINITY),y:new Tn(Number.NEGATIVE_INFINITY)}};for(let t=0,n=e.length;t<n;t++){const n=new sr(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}};Bn.set;var lr=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)=>nr.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 ur=(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=Qt(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}`})))},cr=([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))},pr=(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(cr(e[n],e[r])<t)return!0;return!1})(n,t))},hr=(e,t=.01)=>{if(e.length<=1)return!0;const n=e[e.length-1],r=e[e.length-2];return cr(n,r)>=t},dr=e=>e[0].length<=1||pr(e),fr="_splitter",gr=({draw:e,polygonFeature:t,feature:n})=>{const r=((e,t)=>{const n=t.geometry?.coordinates;return!(!n||n.length<2||!ur(e,{geometry:t.geometry}))})(t,n);return e.setDrawingPreviewProperty("splitter",r?"valid":"invalid"),r},mr=({draw:e,dispatch:t,polygonFeature:n})=>({feature:r,phase:i})=>{return i===f?(o=(({draw:e,dispatch:t,polygonFeature:n,feature:r})=>{const i=gr({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},yr=()=>"undefined"!=typeof navigator&&/mac/i.test(navigator.userAgentData?.platform||navigator.platform||""),vr=yr()?"<kbd>Command</kbd> + <kbd>Z</kbd>":"<kbd>Ctrl</kbd> + <kbd>Z</kbd>",Er=yr()?"<kbd>Option</kbd>":"<kbd>Alt</kbd>",Sr="top-middle",wr=({checkSlow:e,holding:t})=>!(!e||!t),br=(e,t="actions")=>({mobile:{slot:t,showLabel:e},tablet:{slot:t,showLabel:e},desktop:{slot:t,showLabel:e}}),Pr={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:m,hints:y,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&&(pt({appState:r,pluginState:l})||u(l.mode)&&"keyboard"===r.interfaceType),ht({mapState:o,pluginConfig:s,pluginState:l,mapProvider:p,eventBus:m,symbolRegistry:v}),function({mapState:n,pluginConfig:r,pluginState:i,mapProvider:o,hints:s}){const{zoom:a,isUserMove:l}=n,{mode:u,hasSnapLayers:c,snap:p}=i,h=o.draw,d=ut(r,a),f=e({mode:null,isBelow:!1});t(()=>{if(!h)return;const e=f.current;f.current={mode:u,isBelow:d},h.setSnapAvailable(!d);const t=!!u&&e.mode===u&&c;d&&!e.isBelow&&t&&p&&l&&s.show(ct(r))},[h,u,d])}({mapState:o,pluginConfig:s,pluginState:l,mapProvider:p,hints:y}),n(()=>{if(l.mode)return f(lt),()=>g(lt);g(lt)},[l.mode]),t(()=>{const e=null!==l.mode&&"edit_vertex"!==l.mode;return m.emit(d.MAP_SET_SPATIAL_LIST_SUPPRESSED,{suppressed:e}),()=>{m.emit(d.MAP_SET_SPATIAL_LIST_SUPPRESSED,{suppressed:!1})}},[l.mode,m]),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:m,hints:y,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,...br(!0)},{id:"drawAddPoint",label:"Add point",variant:"primary",exclusiveSlot:!0,hiddenWhen:({appState:e,pluginState:t})=>!pt({appState:e,pluginState:t}),enableWhen:({pluginState:e})=>e.canAddPoint&&!e.holding,...br(!0)},{id:"drawDone",label:({pluginState:e})=>wr(e)?"Checking…":"Done",busyWhen:({pluginState:e})=>wr(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},...br(!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),...br(!1,Sr)},{id:"drawSnap",label:"Snap",iconId:"magnet",hiddenWhen:({pluginState:e})=>!e.mode||!e.hasSnapLayers,enableWhen:({pluginConfig:e,pluginState:t,mapState:n})=>!t.holding&&!ut(e,n.zoom),pressedWhen:({pluginState:e})=>!!e.snap,description:({pluginConfig:e,mapState:t})=>ut(e,t.zoom)?ct(e):void 0,...br(!0,Sr)},{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,...br(!1,Sr)}],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:`${Er} + <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:vr}],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:ft,newLine:gt,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,...m}=l;be(c,{onGeometryChange:d,onGeometryPreview:f,onGeometryFinish:g},n,p),p.emit("draw:started",{mode:"draw_point",featureId:a});const y=void 0===l.snapLayers?n.snapLayers??null:l.snapLayers;c.setSnapLayers(y),u({type:"SET_HAS_SNAP_LAYERS",payload:y?.length>0});const v={};pe.forEach(e=>{void 0!==m[e]&&(v[e]=m[e],delete m[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,...m,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=>mt.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))(yt.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:vt(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&&gr({draw:e,polygonFeature:t,feature:n}),{valid:!0}))({draw:u,polygonFeature:p}),u._commitValidator=mr({draw:u,dispatch:l,polygonFeature:p}),u._finishValidator=null,ve(u).reset();const m=["stroke-inactive.cold",...a.snapLayers||[]];u.setSnapLayers(m),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:fr,properties:{splitter:"invalid"}});const y=()=>{u._previewValidator=h,u._commitValidator=d,u._finishValidator=f,u.off(g.CREATE,v),u.off(g.CANCEL,E)},v=e=>{y(),u.delete(fr);const t=ur(p,e);l({type:"SET_ACTION",payload:{name:"split",isValid:!!t}}),t&&c.emit("draw:split",{originalFeatureId:s,featureCollection:t})},E=()=>{y()};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=lr(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 xr=Object.freeze({__proto__:null,manifest:Pr});export{g as A,re as B,f as C,ee as D,xr as E,at as K,F as M,Q as P,ot as S,st as T,ae as a,dr as b,I as c,hr 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
|
+
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_RESET_VIEW:"map:resetview",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 m=6371008.8,y={centimeters:637100880,centimetres:637100880,degrees:360/(2*Math.PI),feet:20902260.511392,inches:39.37*m,kilometers:6371.0088,kilometres:6371.0088,meters:m,metres:m,miles:3958.761333810546,millimeters:6371008800,millimetres:6371008800,nauticalmiles:m/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=y[t];if(!n)throw new Error(t+" units is invalid");return e*n}function _(e,t="kilometers"){const n=y[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,m=f?e.features.length:1,y=0;y<m;y++){a=(c=!!(u=f?e.features[y].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,y,E,S))return!1;h++,E++;break;case"LineString":case"MultiPoint":for(r=0;r<l.length;r++){if(!1===t(l[r],h,y,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,y,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,y,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]),z=(e,t)=>e>0&&t<0||e<0&&t>0,$=(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!(!z(i,o)||!z(s,a))||($(i,n,e,r)||$(o,n,t,r)||$(s,e,n,t)||$(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",me=new Set(["invalid","error"]),ye=new WeakMap,ve=e=>{let t=ye.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}}})(),ye.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&&!me.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 ze({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 $e({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{...$e({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()},...ze({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),m=qe({draw:u,dispatch:r.dispatch,emitGeometryInvalid:h,announce:l});return f.setOnSettle(e=>{m(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=(e,t)=>"number"==typeof e?.snapMinZoom&&"number"==typeof t&&t<e.snapMinZoom,ct=e=>e?.snapZoomInHintText??"Zoom in to use snap";const pt=({appState:e,pluginState:t})=>u(t.mode)&&("touch"===e.interfaceType||!!e.expandedButtons?.has("mapControls"));function ht({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 dt=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:m,onGeometryChange:y,onGeometryPreview:v,onGeometryFinish:E,...S}=u;be(p,{onGeometryChange:y,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={...m,...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})},ft=dt("draw_polygon"),gt=dt("draw_line"),mt=new Set(["Point","LineString","Polygon"]),yt=new Set(["stroke","fill","strokeWidth"]),vt=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,void 0===t?null:t]));function Et(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return St(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 St(e)}),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return bt(e);default:throw new Error("unknown GeoJSON type")}}function St(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=wt(e.properties),t.geometry=bt(e.geometry),t}function wt(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]=wt(r):t[n]=r}),t):t}function bt(e){var t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(function(e){return bt(e)}),t):(t.coordinates=Pt(e.coordinates),t)}function Pt(e){var t=e;return"object"!=typeof t[0]?t.slice():t.map(function(e){return Pt(e)})}function xt(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 _t(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 Tt(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=Et(e));var o=[];switch(e.type){case"GeometryCollection":return M(e,function(e){At(e,r)}),e;case"FeatureCollection":return L(e,function(e){L(At(e,r),function(e){o.push(e)})}),b(o)}return At(e,r)}function At(e,t){switch("Feature"===e.type?e.geometry.type:e.type){case"GeometryCollection":return M(e,function(e){At(e,t)}),e;case"LineString":return Ct(_t(e),t),e;case"Polygon":return It(_t(e),t),e;case"MultiLineString":return _t(e).forEach(function(e){Ct(e,t)}),e;case"MultiPolygon":return _t(e).forEach(function(e){It(e,t)}),e;case"Point":case"MultiPoint":return e}}function Ct(e,t){xt(e)===t&&e.reverse()}function It(e,t){xt(e[0])!==t&&e[0].reverse();for(var n=1;n<e.length;n++)xt(e[n])===t&&e[n].reverse()}const Lt=11102230246251565e-32,kt=134217729,Mt=(3+8*Lt)*Lt;function Rt(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 Nt(e){return new Float64Array(e)}const Ot=Nt(4),Gt=Nt(8),Dt=Nt(12),Vt=Nt(16),Ft=Nt(4);function Bt(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,m,y,v,E,S,w,b,P,x;const _=e-i,T=n-i,A=t-o,C=r-o;S=_*C,h=kt*_,d=h-(h-_),f=_-d,h=kt*C,g=h-(h-C),m=C-g,w=f*m-(S-d*g-f*g-d*m),b=A*T,h=kt*A,d=h-(h-A),f=A-d,h=kt*T,g=h-(h-T),m=T-g,P=f*m-(b-d*g-f*g-d*m),y=w-P,p=w-y,Ot[0]=w-(y+p)+(p-P),v=S+y,p=v-S,E=S-(v-p)+(y-p),y=E-b,p=E-y,Ot[1]=E-(y+p)+(p-b),x=v+y,p=x-v,Ot[2]=v-(x-p)+(y-p),Ot[3]=x;let I=function(e,t){let n=t[0];for(let r=1;r<e;r++)n+=t[r];return n}(4,Ot),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+Mt*Math.abs(I),I+=_*c+C*a-(A*u+T*l),I>=L||-I>=L)return I;S=a*C,h=kt*a,d=h-(h-a),f=a-d,h=kt*C,g=h-(h-C),m=C-g,w=f*m-(S-d*g-f*g-d*m),b=l*T,h=kt*l,d=h-(h-l),f=l-d,h=kt*T,g=h-(h-T),m=T-g,P=f*m-(b-d*g-f*g-d*m),y=w-P,p=w-y,Ft[0]=w-(y+p)+(p-P),v=S+y,p=v-S,E=S-(v-p)+(y-p),y=E-b,p=E-y,Ft[1]=E-(y+p)+(p-b),x=v+y,p=x-v,Ft[2]=v-(x-p)+(y-p),Ft[3]=x;const k=Rt(4,Ot,4,Ft,Gt);S=_*c,h=kt*_,d=h-(h-_),f=_-d,h=kt*c,g=h-(h-c),m=c-g,w=f*m-(S-d*g-f*g-d*m),b=A*u,h=kt*A,d=h-(h-A),f=A-d,h=kt*u,g=h-(h-u),m=u-g,P=f*m-(b-d*g-f*g-d*m),y=w-P,p=w-y,Ft[0]=w-(y+p)+(p-P),v=S+y,p=v-S,E=S-(v-p)+(y-p),y=E-b,p=E-y,Ft[1]=E-(y+p)+(p-b),x=v+y,p=x-v,Ft[2]=v-(x-p)+(y-p),Ft[3]=x;const M=Rt(k,Gt,4,Ft,Dt);S=a*c,h=kt*a,d=h-(h-a),f=a-d,h=kt*c,g=h-(h-c),m=c-g,w=f*m-(S-d*g-f*g-d*m),b=l*u,h=kt*l,d=h-(h-l),f=l-d,h=kt*u,g=h-(h-u),m=u-g,P=f*m-(b-d*g-f*g-d*m),y=w-P,p=w-y,Ft[0]=w-(y+p)+(p-P),v=S+y,p=v-S,E=S-(v-p)+(y-p),y=E-b,p=E-y,Ft[1]=E-(y+p)+(p-b),x=v+y,p=x-v,Ft[2]=v-(x-p)+(y-p),Ft[3]=x;const R=Rt(M,Dt,4,Ft,Vt);return Vt[R-1]}(e,t,n,r,i,o,u)}function Ht(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],m=g.length-1;if((u=g[0])[0]!==g[m][0]&&u[1]!==g[m][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<m;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=Bt(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 Ut=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},jt=function(e){this.p=e},qt=function(e,t){this.id=e,this.rawCoords=t};function zt(e,t){return!(e.maxX<t[0])&&(!(e.minX>t[2])&&(!(e.maxY<t[1])&&!(e.minY>t[3])))}var $t=function(e,t,n,r){this.p=e,this.polylineEdge=t,this.polygonEdge=n,this.isHeadingIn=r,this.distanceFromPolylineEdgeStart=Wt(this.polylineEdge.p1.p,this.p),this.distanceFromPolygonEdgeStart=Wt(this.polygonEdge.p1.p,this.p),this.polygonEdge.intersectionPoints.push(this),this.polylineEdge.intersectionPoints.push(this),this.visitCount=0};function Wt(e,t){var n=t[0]-e[0],r=t[1]-e[1];return n*=n,r*=r,Math.sqrt(n+r)}$t.prototype.incrementVisitCount=function(){this.visitCount=this.visitCount+1};var Yt=1e-9;function Kt(e,t){return e[0]*t[1]-e[1]*t[0]}function Xt(e,t){return e[0]*t[0]+e[1]*t[1]}function Zt(e,t,n){return[e[0]+t*n[0],e[1]+t*n[1]]}function Jt(e,t,n){var r=[e.p2.p[0]-e.p1.p[0],e.p2.p[1]-e.p1.p[1]],i=[t.p2.p[0]-t.p1.p[0],t.p2.p[1]-t.p1.p[1]],o=[t.p1.p[0]-e.p1.p[0],t.p1.p[1]-e.p1.p[1]],s=Kt(r,i),a=s*s,l=Xt(r,r);if(a>0){var u=Kt(o,i)/s;if(u<0||u>1)return null;var c=Kt(o,r)/s;return c<0||c>1?null:0===u||1===u?[Zt(e.p1.p,u,r)]:0===c||1===c?[Zt(t.p1.p,c,i)]:[Zt(e.p1.p,u,r)]}var p=Xt(o,o);if((a=(s=Kt(o,r))*s)>Yt*l*p)return null;var h=Xt(r,o)/l,d=h+Xt(r,i)/l,f=Math.min(h,d),g=Math.max(h,d);return f<=1&&g>=0?1===f?[Zt(e.p1.p,f>0?f:0,r)]:0===g?[Zt(e.p1.p,g<1?g:1,r)]:[Zt(e.p1.p,f>0?f:0,r),Zt(e.p1.p,g<1?g:1,r)]:null}function Qt(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 jt(l[c][0]),d=null,f={nextEdge:null},g=0;g<p;g++){d=new jt(l[c][g+1]),h.nextPoint=d,d.prevPoint=h;var m=new Ut(h,d,"polyline",u,null);r.push(m),f.nextEdge=m,m.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=m}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 y="Feature"===e.type?e.geometry:e,v="Polygon"===y.type?[y.coordinates]:y.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 qt(o,P));for(var _=new jt(P[0]),T=_,A=void 0,C=null,I={nextEdge:null,prevEdge:null},L=null,k=1;k<x;k++)A=new jt(P[k]),T.nextPoint=A,A.prevPoint=T,C=new Ut(T,A,"polygon",u,o),I.nextEdge=C,C.prevEdge=I,1===k&&(L=C),b>0&&(C.interiorRing=!0),C.intersectPolylineBbox=zt(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}(Tt(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=Jt(l,u);if(null!==c)for(o=0;o<c.length;o++){var p=Bt(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 $t(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 m=n[g];if(m.visitCount<2){h=m,f=!0;break}}if(!f)break}h.visitCount=h.visitCount+1;var y=[];l.push(y),y.push(h.p),h.visitCount=h.visitCount+1;var v=rn(h,y),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?an:sn)(v,y))!==h&&(v=rn(v,y)),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])nn(tn(en(r,parseInt(A)),o),x)}return{type:"Feature",properties:{},geometry:{type:"MultiPolygon",coordinates:x}}}function en(e,t){for(var n=0;n<e.length;n++){var r=e[n];if(r.polygonContourId===t)return r}}function tn(e,t){return t.find(function(t){return t.id===e.polygonContourId}).rawCoords}function nn(e,t){for(var n=0;n<t.length;n++){var r=t[n];if(Ht(e[0],[r[0]]))return void r.push(e)}t.push([e])}function rn(e,t){var n=e.polygonEdge;if(n.intersectionPoints.length>1&&n.intersectionPoints[n.intersectionPoints.length-1]!==e){var r=on(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 on(e,t){for(var n=0;n<t.length;n++){if(t[n]===e)return n}return null}function sn(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=on(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 an(e,t){var n=e.polylineEdge;if(n.intersectionPoints.length>1&&n.intersectionPoints[n.intersectionPoints.length-1]!==e){var r=on(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 ln=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,un=Math.ceil,cn=Math.floor,pn="[BigNumber Error] ",hn=pn+"Number primitive has more than 15 significant digits: ",dn=1e14,fn=14,gn=9007199254740991,mn=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],yn=1e7,vn=1e9;function En(e){var t=0|e;return e>0||e===t?t:t-1}function Sn(e){for(var t,n,r=1,i=e.length,o=e[0]+"";r<i;){for(t=e[r++]+"",n=fn-t.length;n--;t="0"+t);o+=t}for(i=o.length;48===o.charCodeAt(--i););return o.slice(0,i+1||1)}function wn(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 bn(e,t,n,r){if(e<t||e>n||e!==cn(e))throw Error(pn+(r||"Argument")+("number"==typeof e?e<t||e>n?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function Pn(e){var t=e.c.length-1;return En(e.e/fn)==t&&e.c[t]%2!=0}function xn(e,t){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(t<0?"e":"e+")+t}function _n(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 Tn=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,m=-7,y=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(!ln.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(bn(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(hn+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>gn||e!==cn(e)))throw Error(hn+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)%fn,a<0&&(l+=fn),l<c){for(l&&h.c.push(+p.slice(0,l)),c-=fn;l<c;)h.c.push(+p.slice(l,l+=fn));l=fn-(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:bn(n,0,8),!e.c)return e.toString();if(i=e.c[0],s=e.e,null==t)l=Sn(e.c),l=1==r||2==r&&(s<=m||s>=y)?xn(l,s):_n(l,s,"0");else if(o=(e=L(new T(e),t,n)).e,a=(l=Sn(e.c)).length,1==r||2==r&&(t<=o||o<=m)){for(;a<t;l+="0",a++);l=xn(l,o)}else if(t-=s+(2===r&&o>s),l=_n(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=wn(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*fn-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=mn;if(p){e:{for(i=1,a=p[0];a>=10;a/=10,i++);if((o=t-i)<0)o+=fn,s=t,l=p[u=0],c=cn(l/h[i-s-1]%10);else if((u=un((o+1)/fn))>=p.length){if(!r)break e;for(;p.length<=u;p.push(0));l=c=0,i=1,s=(o%=fn)-fn+1}else{for(l=a=p[u],i=1;a>=10;a/=10,i++);c=(s=(o%=fn)-fn+i)<0?0:cn(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[(fn-t%fn)%fn],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[fn-o],p[u]=s>0?cn(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]==dn&&(p[0]=1));break}if(p[u]+=a,p[u]!=dn)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=Sn(e.c),t=n<=m||n>=y?xn(t,n):_n(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(pn+"Object expected: "+e);if(e.hasOwnProperty(t="DECIMAL_PLACES")&&(bn(n=e[t],0,vn,t),f=n),e.hasOwnProperty(t="ROUNDING_MODE")&&(bn(n=e[t],0,8,t),g=n),e.hasOwnProperty(t="EXPONENTIAL_AT")&&((n=e[t])&&n.pop?(bn(n[0],-vn,0,t),bn(n[1],0,vn,t),m=n[0],y=n[1]):(bn(n,-vn,vn,t),m=-(y=n<0?-n:n))),e.hasOwnProperty(t="RANGE"))if((n=e[t])&&n.pop)bn(n[0],-vn,-1,t),bn(n[1],1,vn,t),v=n[0],E=n[1];else{if(bn(n,-vn,vn,t),!n)throw Error(pn+t+" cannot be zero: "+n);v=-(E=n<0?-n:n)}if(e.hasOwnProperty(t="CRYPTO")){if((n=e[t])!==!!n)throw Error(pn+t+" not true or false: "+n);if(n){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw S=!n,Error(pn+"crypto unavailable");S=n}else S=n}if(e.hasOwnProperty(t="MODULO_MODE")&&(bn(n=e[t],0,9,t),w=n),e.hasOwnProperty(t="POW_PRECISION")&&(bn(n=e[t],0,vn,t),b=n),e.hasOwnProperty(t="FORMAT")){if("object"!=typeof(n=e[t]))throw Error(pn+t+" not an object: "+n);P=n}if(e.hasOwnProperty(t="ALPHABET")){if("string"!=typeof(n=e[t])||/^.?$|[+\-.\s]|(.).*\1/.test(n))throw Error(pn+t+" invalid: "+n);_="0123456789"==n.slice(0,10),x=n}}return{DECIMAL_PLACES:f,ROUNDING_MODE:g,EXPONENTIAL_AT:[m,y],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>=-vn&&i<=vn&&i===cn(i)){if(0===r[0]){if(0===i&&1===r.length)return!0;break e}if((t=(i+1)%fn)<1&&(t+=fn),String(r[0]).length==t){for(t=0;t<r.length;t++)if((n=r[t])<0||n>=dn||n!==cn(n))break e;if(0!==n)return!0}}}else if(null===r&&null===i&&(null===o||1===o||-1===o))return!0;throw Error(pn+"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 cn(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:bn(e,0,vn),i=un(e/fn),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(pn+"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%=fn,i&&e&&(o=mn[fn-e],l[a]=cn(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-=fn);for(a=1,o=l[0];o>=10;o/=10,a++);a<fn&&(r-=fn-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,m,y,v=r.indexOf("."),E=f,S=g;for(v>=0&&(p=b,b=0,r=r.replace(".",""),d=(y=new T(i)).pow(r.length-v),b=p,y.c=t(_n(Sn(d.c),d.e,"0"),10,o,e),y.e=y.c.length),c=p=(m=t(r,i,o,a?(l=x,e):(l=e,x))).length;0==m[--p];m.pop());if(!m[0])return l.charAt(0);if(v<0?--c:(d.c=m,d.e=c,d.s=s,m=(d=n(d,y,E,S,o)).c,h=d.r,c=d.e),v=m[u=c+E+1],p=o/2,h=h||u<0||null!=m[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&m[u-1]||S==(d.s<0?8:7)),u<1||!m[0])r=h?_n(l.charAt(1),-E,l.charAt(0)):l.charAt(0);else{if(m.length=u,h)for(--o;++m[--u]>o;)m[u]=0,u||(++c,m=[1].concat(m));for(p=m.length;!m[--p];);for(v=0,r="";v<=p;r+=l.charAt(m[v++]));r=_n(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%yn,c=t/yn|0;for(e=e.slice();l--;)a=((i=u*(o=e[l]%yn)+(r=c*o+(s=e[l]/yn|0)*u)%yn*yn+a)/n|0)+(r/yn|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,m,y,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(m=(g=new T(_)).c=[],_=o+(u=r.e-i.e)+1,a||(a=dn,u=En(r.e/fn)-En(i.e/fn),_=_/fn|0),c=0;C[c]==(A[c]||0);c++);if(C[c]>(A[c]||0)&&u--,_<0)m.push(1),p=!0;else{for(w=A.length,P=C.length,c=0,_+=2,(h=cn(a/(C[0]+1)))>1&&(C=e(C,h,a),A=e(A,h,a),P=C.length,w=A.length),S=P,v=(y=A.slice(0,P)).length;v<P;y[v++]=0);x=C.slice(),x=[0].concat(x),b=C[0],C[1]>=a/2&&b++;do{if(h=0,(l=t(C,y,P,v))<0){if(E=y[0],P!=v&&(E=E*a+(y[1]||0)),(h=cn(E/b))>1)for(h>=a&&(h=a-1),f=(d=e(C,h,a)).length,v=y.length;1==t(d,y,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(y,d,v,a),v=y.length,-1==l)for(;t(C,y,P,v)<1;)h++,n(y,P<v?x:C,v,a),v=y.length}else 0===l&&(h++,y=[0]);m[c++]=h,y[0]?y[v++]=A[S]||0:(y=[A[S]],v=1)}while((S++<w||null!=y[0])&&_--);p=null!=y[0],m[0]||m.splice(0,1)}if(a==dn){for(c=1,_=m[0];_>=10;_/=10,c++);L(g,o+(g.e=c+u*fn-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(pn+"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 wn(this,new T(e,t))},h.decimalPlaces=h.dp=function(e,t){var n,r,i,o=this;if(null!=e)return bn(e,0,vn),null==t?t=g:bn(t,0,8),L(new T(o),e+o.e+1,t);if(!(n=o.c))return null;if(r=((i=n.length-1)-En(this.e/fn))*fn,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(pn+"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-Pn(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&&Pn(e)?-0:0,c.e>-1&&(o=1/o),new T(a?1/o:o);b&&(o=un(b/fn+2))}for(s?(n=new T(.5),a&&(e.s=1),l=Pn(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=cn(i/2)))break;l=i%2}else if(L(e=e.times(n),e.e+1,1),e.e>14)l=Pn(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:bn(e,0,8),L(t,t.e+1,e)},h.isEqualTo=h.eq=function(e,t){return 0===wn(this,new T(e,t))},h.isFinite=function(){return!!this.c},h.isGreaterThan=h.gt=function(e,t){return wn(this,new T(e,t))>0},h.isGreaterThanOrEqualTo=h.gte=function(e,t){return 1===(t=wn(this,new T(e,t)))||0===t},h.isInteger=function(){return!!this.c&&En(this.e/fn)>this.c.length-2},h.isLessThan=h.lt=function(e,t){return wn(this,new T(e,t))<0},h.isLessThanOrEqualTo=h.lte=function(e,t){return-1===(t=wn(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/fn,u=e.e/fn,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=En(l),u=En(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=dn-1;r>a;){if(c[--r]<p[r]){for(n=r;n&&!c[--n];c[n]=t);--c[n],c[r]+=dn}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,m,y=this,v=y.c,E=(e=new T(e,t)).c;if(!(v&&E&&v[0]&&E[0]))return!y.s||!e.s||v&&!v[0]&&!E||E&&!E[0]&&!v?e.c=e.e=e.s=null:(e.s*=y.s,v&&E?(e.c=[0],e.e=0):e.c=e.e=null),e;for(r=En(y.e/fn)+En(e.e/fn),e.s*=y.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=dn,m=yn,i=p;--i>=0;){for(n=0,h=E[i]%m,d=E[i]/m|0,o=i+(s=l);o>i;)n=((u=h*(u=v[--s]%m)+(a=d*u+(c=v[s]/m|0)*h)%m*m+f[o]+n)/g|0)+(a/m|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/fn,s=e.e/fn,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=En(o),s=En(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)/dn|0,a[t]=dn===a[t]?0:a[t]%dn;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 bn(e,1,vn),null==t?t=g:bn(t,0,8),L(new T(o),e,t);if(!(n=o.c))return null;if(r=(i=n.length-1)*fn+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 bn(e,-9007199254740991,gn),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=Sn(a)).length+u)%2==0&&(t+="0"),l=Math.sqrt(+t),u=En((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))),Sn(o.c).slice(0,l)===(t=Sn(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&&(bn(e,0,vn),e++),A(this,e,t,1)},h.toFixed=function(e,t){return null!=e&&(bn(e,0,vn),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(pn+"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,m=this,y=m.c;if(null!=e&&(!(l=new T(e)).isInteger()&&(l.c||1!==l.s)||l.lt(d)))throw Error(pn+"Argument "+(l.isInteger()?"out of range: ":"not an integer: ")+k(l));if(!y)return new T(m);for(t=new T(d),c=r=new T(d),i=u=new T(d),f=Sn(y),s=t.e=f.length-m.e-1,t.c[0]=mn[(a=s%fn)<0?fn+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=m.s,h=n(c,i,s*=2,g).minus(m).abs().comparedTo(n(u,r,s,g).minus(m).abs())<1?[c,i]:[u,r],E=a,h},h.toNumber=function(){return+k(this)},h.toPrecision=function(e,t){return null!=e&&bn(e,1,vn),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<=m||o>=y?xn(Sn(n.c),o):_n(Sn(n.c),o,"0"):10===e&&_?t=_n(Sn((n=L(new T(n),f+o+1,g)).c),n.e,"0"):(bn(e,2,x.length,"Base"),t=r(_n(Sn(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}(),An=class{key;left=null;right=null;constructor(e){this.key=e}},Cn=class extends An{constructor(e){super(e)}},In=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)}}},Ln=class e extends In{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 Cn(e),t),this}addAndReturn(e){const t=this.splay(e);return 0!=t&&this.addNewRoot(new Cn(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 Cn(e.key);return function e(t,n){let r,i;do{if(r=t.left,i=t.right,null!=r){const t=new Cn(r.key);n.left=t,e(r,t)}if(null!=i){const e=new Cn(i.key);n.right=e,t=i,n=e}}while(null!=i)}(e,t),t}toSet(){return this.clone()}entries(){return new Rn(this.wrap())}keys(){return this[Symbol.iterator]()}values(){return this[Symbol.iterator]()}[Symbol.iterator](){return new Mn(this.wrap())}[Symbol.toStringTag]="[object Set]"},kn=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}},Mn=class extends kn{getValue(e){return e.key}},Rn=class extends kn{getValue(e){return[e.key,e.key]}},Nn=e=>()=>e,On=e=>{const t=e?(t,n)=>n.minus(t).abs().isLessThanOrEqualTo(e):Nn(!1);return(e,n)=>t(e,n)?0:e.comparedTo(n)};function Gn(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)):Nn(!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 Dn=e=>e,Vn=e=>{if(e){const t=new Ln(On(e)),n=new Ln(On(e)),r=(e,t)=>t.addAndReturn(e),i=e=>({x:r(e.x,t),y:r(e.y,n)});return i({x:new Tn(0),y:new Tn(0)}),i}return Dn},Fn=e=>({set:e=>{Bn=Fn(e)},reset:()=>Fn(e),compare:On(e),snap:Vn(e),orient:Gn(e)}),Bn=Fn(),Hn=(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),Un=(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}}},jn=(e,t)=>e.x.times(t.y).minus(e.y.times(t.x)),qn=(e,t)=>e.x.times(t.x).plus(e.y.times(t.y)),zn=e=>qn(e,e).sqrt(),$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 jn(i,r).div(zn(i)).div(zn(r))},Wn=(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 qn(i,r).div(zn(i)).div(zn(r))},Yn=(e,t,n)=>t.y.isZero()?null:{x:e.x.plus(t.x.div(t.y).times(n.minus(e.y))),y:n},Kn=(e,t,n)=>t.x.isZero()?null:{x:n,y:e.y.plus(t.y.div(t.x).times(n.minus(e.x)))},Xn=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:ir.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:$n(this.point,e.point,r.point),cosine:Wn(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}}},Zn=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!==Bn.orient(r,e,i)&&(t.push(r),e=r)}if(1===t.length)return null;const n=t[0],r=t[1];0===Bn.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];Xn.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}}},Jn=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}},Qn=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 Jn(r));else{const e=r.enclosingRing();e?.poly||t.push(new Jn(e)),e?.poly?.addInterior(r)}}return t}},er=class{queue;tree;segments;constructor(e,t=ir.compare){this.queue=e,this.tree=new Ln(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=Xn.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}},tr=new class{type;numMultiPolys;run(e,t,n){tr.type=e;const r=[new ar(t,!0)];for(let e=0,t=n.length;e<t;e++)r.push(new ar(n[e],!1));if(tr.numMultiPolys=r.length,"difference"===tr.type){const e=r[0];let t=1;for(;t<r.length;)null!==Un(r[t].bbox,e.bbox)?t++:r.splice(t,1)}if("intersection"===tr.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===Un(t.bbox,r[n].bbox))return[]}const i=new Ln(Xn.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 er(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}Bn.reset();const a=Zn.factory(o.segments);return new Qn(a).getGeom()}},nr=tr,rr=0,ir=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=++rr,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=Xn.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 Xn(i,!0),u=new Xn(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 Bn.orient(this.leftSE.point,e,this.rightSE.point)}getIntersection(e){const t=this.bbox(),n=e.bbox(),r=Un(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=Hn(t,s)&&0===this.comparePoint(s),u=Hn(n,i)&&0===e.comparePoint(i),c=Hn(t,a)&&0===this.comparePoint(a),p=Hn(n,o)&&0===e.comparePoint(o);if(u&&l)return p&&!c?o:!p&&c?a:null;if(u)return c&&i.x.eq(a.x)&&i.y.eq(a.y)?null:i;if(l)return p&&o.x.eq(s.x)&&o.y.eq(s.y)?null:s;if(p&&c)return null;if(p)return o;if(c)return a;const h=((e,t,n,r)=>{if(t.x.isZero())return Kn(n,r,e.x);if(r.x.isZero())return Kn(e,t,n.x);if(t.y.isZero())return Yn(n,r,e.y);if(r.y.isZero())return Yn(e,t,n.y);const i=jn(t,r);if(i.isZero())return null;const o={x:n.x.minus(e.x),y:n.y.minus(e.y)},s=jn(o,t).div(i),a=jn(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:Hn(r,h)?Bn.snap(h):null}split(t){const n=[],r=void 0!==t.events,i=new Xn(t,!0),o=new Xn(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 Xn.comparePoints(a.leftSE.point,a.rightSE.point)>0&&a.swapEvents(),Xn.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(nr.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===nr.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}},or=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=Bn.snap({x:new Tn(e[0][0]),y:new Tn(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=Bn.snap({x:new Tn(e[t][0]),y:new Tn(e[t][1])});n.x.eq(i.x)&&n.y.eq(i.y)||(this.segments.push(ir.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(ir.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}},sr=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 or(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 or(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}},ar=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 Tn(Number.POSITIVE_INFINITY),y:new Tn(Number.POSITIVE_INFINITY)},ur:{x:new Tn(Number.NEGATIVE_INFINITY),y:new Tn(Number.NEGATIVE_INFINITY)}};for(let t=0,n=e.length;t<n;t++){const n=new sr(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}};Bn.set;var lr=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)=>nr.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 ur=(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=Qt(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}`})))},cr=([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))},pr=(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(cr(e[n],e[r])<t)return!0;return!1})(n,t))},hr=(e,t=.01)=>{if(e.length<=1)return!0;const n=e[e.length-1],r=e[e.length-2];return cr(n,r)>=t},dr=e=>e[0].length<=1||pr(e),fr="_splitter",gr=({draw:e,polygonFeature:t,feature:n})=>{const r=((e,t)=>{const n=t.geometry?.coordinates;return!(!n||n.length<2||!ur(e,{geometry:t.geometry}))})(t,n);return e.setDrawingPreviewProperty("splitter",r?"valid":"invalid"),r},mr=({draw:e,dispatch:t,polygonFeature:n})=>({feature:r,phase:i})=>{return i===f?(o=(({draw:e,dispatch:t,polygonFeature:n,feature:r})=>{const i=gr({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},yr=()=>"undefined"!=typeof navigator&&/mac/i.test(navigator.userAgentData?.platform||navigator.platform||""),vr=yr()?"<kbd>Command</kbd> + <kbd>Z</kbd>":"<kbd>Ctrl</kbd> + <kbd>Z</kbd>",Er=yr()?"<kbd>Option</kbd>":"<kbd>Alt</kbd>",Sr="top-middle",wr=({checkSlow:e,holding:t})=>!(!e||!t),br=(e,t="actions")=>({mobile:{slot:t,showLabel:e},tablet:{slot:t,showLabel:e},desktop:{slot:t,showLabel:e}}),Pr={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:m,hints:y,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&&(pt({appState:r,pluginState:l})||u(l.mode)&&"keyboard"===r.interfaceType),ht({mapState:o,pluginConfig:s,pluginState:l,mapProvider:p,eventBus:m,symbolRegistry:v}),function({mapState:n,pluginConfig:r,pluginState:i,mapProvider:o,hints:s}){const{zoom:a,isUserMove:l}=n,{mode:u,hasSnapLayers:c,snap:p}=i,h=o.draw,d=ut(r,a),f=e({mode:null,isBelow:!1});t(()=>{if(!h)return;const e=f.current;f.current={mode:u,isBelow:d},h.setSnapAvailable(!d);const t=!!u&&e.mode===u&&c;d&&!e.isBelow&&t&&p&&l&&s.show(ct(r))},[h,u,d])}({mapState:o,pluginConfig:s,pluginState:l,mapProvider:p,hints:y}),n(()=>{if(l.mode)return f(lt),()=>g(lt);g(lt)},[l.mode]),t(()=>{const e=null!==l.mode&&"edit_vertex"!==l.mode;return m.emit(d.MAP_SET_SPATIAL_LIST_SUPPRESSED,{suppressed:e}),()=>{m.emit(d.MAP_SET_SPATIAL_LIST_SUPPRESSED,{suppressed:!1})}},[l.mode,m]),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:m,hints:y,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,...br(!0)},{id:"drawAddPoint",label:"Add point",variant:"primary",exclusiveSlot:!0,hiddenWhen:({appState:e,pluginState:t})=>!pt({appState:e,pluginState:t}),enableWhen:({pluginState:e})=>e.canAddPoint&&!e.holding,...br(!0)},{id:"drawDone",label:({pluginState:e})=>wr(e)?"Checking…":"Done",busyWhen:({pluginState:e})=>wr(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},...br(!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),...br(!1,Sr)},{id:"drawSnap",label:"Snap",iconId:"magnet",hiddenWhen:({pluginState:e})=>!e.mode||!e.hasSnapLayers,enableWhen:({pluginConfig:e,pluginState:t,mapState:n})=>!t.holding&&!ut(e,n.zoom),pressedWhen:({pluginState:e})=>!!e.snap,description:({pluginConfig:e,mapState:t})=>ut(e,t.zoom)?ct(e):void 0,...br(!0,Sr)},{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,...br(!1,Sr)}],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:`${Er} + <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:vr}],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:ft,newLine:gt,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,...m}=l;be(c,{onGeometryChange:d,onGeometryPreview:f,onGeometryFinish:g},n,p),p.emit("draw:started",{mode:"draw_point",featureId:a});const y=void 0===l.snapLayers?n.snapLayers??null:l.snapLayers;c.setSnapLayers(y),u({type:"SET_HAS_SNAP_LAYERS",payload:y?.length>0});const v={};pe.forEach(e=>{void 0!==m[e]&&(v[e]=m[e],delete m[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,...m,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=>mt.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))(yt.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:vt(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&&gr({draw:e,polygonFeature:t,feature:n}),{valid:!0}))({draw:u,polygonFeature:p}),u._commitValidator=mr({draw:u,dispatch:l,polygonFeature:p}),u._finishValidator=null,ve(u).reset();const m=["stroke-inactive.cold",...a.snapLayers||[]];u.setSnapLayers(m),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:fr,properties:{splitter:"invalid"}});const y=()=>{u._previewValidator=h,u._commitValidator=d,u._finishValidator=f,u.off(g.CREATE,v),u.off(g.CANCEL,E)},v=e=>{y(),u.delete(fr);const t=ur(p,e);l({type:"SET_ACTION",payload:{name:"split",isValid:!!t}}),t&&c.emit("draw:split",{originalFeatureId:s,featureCollection:t})},E=()=>{y()};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=lr(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 xr=Object.freeze({__proto__:null,manifest:Pr});export{g as A,re as B,f as C,ee as D,xr as E,at as K,F as M,Q as P,ot as S,st as T,ae as a,dr as b,I as c,hr 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};
|