maplibre-gl-js-amplify 4.0.2 → 4.0.3

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.
@@ -107,6 +107,18 @@
107
107
  node.parentNode.removeChild(node);
108
108
  }
109
109
  }
110
+ /**
111
+ * Escapes HTML special characters to prevent XSS when interpolating
112
+ * user-controlled strings into HTML markup.
113
+ */
114
+ function escapeHtml(str) {
115
+ return str
116
+ .replace(/&/g, '&')
117
+ .replace(/</g, '&lt;')
118
+ .replace(/>/g, '&gt;')
119
+ .replace(/"/g, '&quot;')
120
+ .replace(/'/g, '&#39;');
121
+ }
110
122
 
111
123
  var __awaiter$3 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
112
124
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -393,8 +405,10 @@
393
405
  title = 'Coordinates';
394
406
  address = selectedFeature.geometry.coordinates;
395
407
  }
396
- const titleHtml = `<div class="${unclusteredLayerId}-popup-title" style="font-weight: ${fontWeight};">${title}</div>`;
397
- const addressHtml = `<div class="${unclusteredLayerId}-popup-address">${address}</div>`;
408
+ const safeTitle = escapeHtml(String(title));
409
+ const safeAddress = escapeHtml(String(address));
410
+ const titleHtml = `<div class="${unclusteredLayerId}-popup-title" style="font-weight: ${fontWeight};">${safeTitle}</div>`;
411
+ const addressHtml = `<div class="${unclusteredLayerId}-popup-address">${safeAddress}</div>`;
398
412
  const popupHtmlStyle = `background: ${background}; border: ${borderWidth}px solid ${borderColor}; color: ${fontColor}; border-radius: ${radius}px; padding: ${padding}px; word-wrap: break-word; margin: -10px -10px -15px;`;
399
413
  let popupHtml = `<div class="${unclusteredLayerId}-popup" style="${popupHtmlStyle}">`;
400
414
  if (title)
@@ -1301,7 +1315,7 @@
1301
1315
  geofenceControl.hideHighlightedGeofence();
1302
1316
  });
1303
1317
  const geofenceTitle = createElement('div', 'geofence-ctrl-list-item-title', geofenceTitleContainer);
1304
- geofenceTitle.innerHTML = geofence.geofenceId;
1318
+ geofenceTitle.innerHTML = escapeHtml(geofence.geofenceId);
1305
1319
  const editButton = createElement('div', 'geofence-ctrl-edit-button', geofenceTitleContainer);
1306
1320
  editButton.addEventListener('click', function () {
1307
1321
  geofenceControl.editGeofence(geofence.geofenceId);
@@ -1400,7 +1414,7 @@
1400
1414
  _deleteGeofenceContainer = createElement('div', 'geofence-ctrl-delete-prompt-container', geofenceControlContainer);
1401
1415
  const deleteGeofencePrompt = createElement('div', 'geofence-ctrl-delete-prompt', _deleteGeofenceContainer);
1402
1416
  const title = createElement('div', 'geofence-ctrl-delete-geofence-title', deleteGeofencePrompt);
1403
- title.innerHTML = `Are you sure you want to delete <strong>${geofenceId}</strong>?`;
1417
+ title.innerHTML = `Are you sure you want to delete <strong>${escapeHtml(geofenceId)}</strong>?`;
1404
1418
  createDeleteButtonsContainer(deleteGeofencePrompt, geofenceId);
1405
1419
  }
1406
1420
  function createDeleteButtonsContainer(container, geofenceId) {
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@aws-amplify/core"),require("@aws-amplify/core/internals/utils"),require("@aws-amplify/geo"),require("maplibre-gl"),require("@maplibre/maplibre-gl-geocoder"),require("@turf/along"),require("@turf/circle"),require("@turf/length"),require("@turf/helpers"),require("debounce"),require("@mapbox/mapbox-gl-draw"),require("maplibre-gl-draw-circle")):"function"==typeof define&&define.amd?define(["exports","@aws-amplify/core","@aws-amplify/core/internals/utils","@aws-amplify/geo","maplibre-gl","@maplibre/maplibre-gl-geocoder","@turf/along","@turf/circle","@turf/length","@turf/helpers","debounce","@mapbox/mapbox-gl-draw","maplibre-gl-draw-circle"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).AmplifyMapLibre={},e.aws_amplify_core,e.utils,e.aws_amplify_geo,e.maplibregl,e.MaplibreGeocoder,e.along,e.circle,e.length,e.helpers,e.debounce,e.MapboxDraw,e.maplibreGlDrawCircle)}(this,(function(e,t,o,i,n,r,s,c,l,a,d,u,f){"use strict";function p(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var h=p(n),g=p(r),m=p(s),y=p(c),b=p(l),v=p(u);function w(e){return Array.isArray(e)&&"number"==typeof e[0]&&"number"==typeof e[1]}function G(e){return w(e[0])}function C(e){return(t=e[0])&&Array.isArray(t.coordinates)&&"number"==typeof t.coordinates[0]&&"number"==typeof t.coordinates[1];var t}function _(e){return Array.isArray(e)&&((t=e[0])&&"string"==typeof t.geofenceId&&"object"==typeof t.geometry);var t}function A(e){return Array.isArray(e)&&(t=e[0],Array.isArray(t)&&G(t[0]));var t}const L=e=>"string"==typeof e&&e.length>0,E=e=>{let t;return t=G(e)?e.map((e=>({type:"Feature",geometry:{type:"Point",coordinates:e},properties:{place_name:`Coordinates,${e}`}}))):C(e)?e.map((e=>({type:"Feature",geometry:{type:"Point",coordinates:e.coordinates},properties:{title:e.title,address:e.address}}))):e,t};function x(e,t,o){const i=window.document.createElement(e);return void 0!==t&&(i.className=t),o&&o.appendChild(i),i}function I(e){e.parentNode&&e.parentNode.removeChild(e)}var M=function(e,t,o,i){return new(o||(o=Promise))((function(n,r){function s(e){try{l(i.next(e))}catch(e){r(e)}}function c(e){try{l(i.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,c)}l((i=i.apply(e,t||[])).next())}))},k=function(e,t){var o={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(e);n<i.length;n++)t.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(o[i[n]]=e[i[n]])}return o};class S{constructor(e,i){this.refreshCredentials=()=>M(this,void 0,void 0,(function*(){try{this.credentials=(yield t.fetchAuthSession()).credentials}catch(e){throw console.error(`Failed to refresh credentials: ${e}`),e}})),this.refreshCredentialsWithRetry=()=>M(this,void 0,void 0,(function*(){try{const e=3e5;if(yield o.jitteredExponentialRetry(this.refreshCredentials,[],e),this.activeTimeout&&clearTimeout(this.activeTimeout),this.credentials.expiration.getTime()>(new Date).getTime()){const e=new Date(this.credentials.expiration).getTime()-(new Date).getTime()-1e4;this.activeTimeout=window.setTimeout(this.refreshCredentialsWithRetry,Math.min(e,36e5))}}catch(e){console.error(`Failed to refresh credentials: ${e}`)}})),this.transformRequest=(e,t)=>{let i=e;if("Style"===t&&!e.includes("://")){if(null==this.region)throw new Error("AWS region for map is undefined. Please verify that the region is set in aws-exports.js or that you are providing an AWS region parameter to createMap");i=`https://maps.geo.${this.region}.amazonaws.com/maps/v0/maps/${e}/style-descriptor`}const n=new URL(i);if(n.hostname.endsWith(".amazonaws.com"))return n.searchParams.append("x-amz-user-agent",encodeURIComponent(function(){const e=o.getAmplifyUserAgent();return e&&"object"==typeof e?e.map((([e,t])=>`${e}/${t}`)).join(" "):e}().replace(/\./g,"%2E"))),{url:o.Signer.signUrl(n.href,{access_key:this.credentials.accessKeyId,secret_key:this.credentials.secretAccessKey,session_token:this.credentials.sessionToken})}},this.credentials=e,this.region=i,this.activeTimeout=null,this.refreshCredentialsWithRetry(),t.Hub.listen("auth",(e=>{switch(e.payload.event){case"signedIn":case"signedOut":case"tokenRefresh":this.refreshCredentialsWithRetry()}}))}}S.createMapLibreMap=e=>M(void 0,void 0,void 0,(function*(){const{region:o,mapConstructor:r=n.Map}=e,s=k(e,["region","mapConstructor"]),c=i.Geo.getDefaultMap(),l=new S((yield t.fetchAuthSession()).credentials,o||c.region).transformRequest;return new r(Object.assign(Object.assign({},s),{style:e.style||c.mapName,transformRequest:l}))}));const H="#fff",P="#000",O="#5d8aff",T="#2194f3",R="#003560",N="#FF9900",D="M24.8133 38.533C18.76 31.493 13 28.8264 13 20.8264C13.4827 14.9864 16.552 9.67169 21.368 6.33302C33.768 -2.26165 50.824 5.78902 52.0667 20.8264C52.0667 28.613 46.5733 31.6797 40.6533 38.373C32.4933 47.5464 35.4 63.093 32.4933 63.093C29.72 63.093 32.4933 47.5464 24.8133 38.533ZM32.4933 8.23969C26.5573 8.23969 21.7467 13.0504 21.7467 18.9864C21.7467 24.9224 26.5573 29.733 32.4933 29.733C38.4293 29.733 43.24 24.9224 43.24 18.9864C43.24 13.0504 38.4293 8.23969 32.4933 8.23969Z";var $;!function(e){e.ESRI_TOPOGRAPHIC="VectorEsriTopographic",e.ESRI_STREETS="VectorEsriStreets",e.ESRI_LIGHT_GRAY="VectorEsriLightGrayCanvas",e.ESRI_DARK_GRAY="VectorEsriDarkGrayCanvas",e.ESRI_NAVIGATION="VectorEsriNavigation",e.HERE_BERLIN="VectorHereBerlin"}($||($={}));const B={[$.ESRI_TOPOGRAPHIC]:"Noto Sans Regular",[$.ESRI_STREETS]:"Arial Regular",[$.ESRI_LIGHT_GRAY]:"Ubuntu Regular",[$.ESRI_DARK_GRAY]:"Ubuntu Regular",[$.ESRI_NAVIGATION]:"Arial Regular",[$.HERE_BERLIN]:"Fira GO Regular"};function j(e){const t=(null==e?void 0:e.fillColor)?e.fillColor:O,o=(null==e?void 0:e.strokeColor)?e.strokeColor:H,i=(null==e?void 0:e.lineWidth)?e.lineWidth:4;return{width:64,height:64,data:new Uint8Array(16384),onAdd:function(){const e=document.createElement("canvas");e.width=this.width,e.height=this.height,this.context=e.getContext("2d")},render:function(){const e=this.context,n=new Path2D(D);return e.stroke(n),e.fillStyle=t,e.strokeStyle=o,e.lineWidth=i,e.fill(n),this.data=e.getImageData(0,0,this.width,this.height).data,!0}}}var V=function(e,t){var o={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(e);n<i.length;n++)t.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(o[i[n]]=e[i[n]])}return o};const F="amplify-tip";function Z(e,t,o){var{showMarkerPopup:i=!1}=o,r=V(o,["showMarkerPopup"]);const s=`${e}-layer-unclustered-point`;let c=null;function l(){null!==c&&(t.setLayoutProperty(s,"icon-image","inactive-marker"),c=null)}const a=r.popupRender?r.popupRender:function(e,{popupBackgroundColor:t="#fff",popupBorderColor:o="#0000001f",popupBorderWidth:i=2,popupFontColor:n="#000",popupPadding:r=20,popupBorderRadius:s=4,popupTitleFontWeight:c="bold"}){return l=>{let a,d;if(L(l.properties.place_name)){const e=l.properties.place_name.split(",");a=e[0],d=e.splice(1,e.length).join(",")}else L(l.properties.title)||L(l.properties.address)?(a=l.properties.title,d=l.properties.address):(a="Coordinates",d=l.geometry.coordinates);let u=`<div class="${e}-popup" style="background: ${t}; border: ${i}px solid ${o}; color: ${n}; border-radius: ${s}px; padding: ${r}px; word-wrap: break-word; margin: -10px -10px -15px;">`;return a&&(u+=`<div class="${e}-popup-title" style="font-weight: ${c};">${a}</div>`),d&&(u+=`<div class="${e}-popup-address">${d}</div>`),u+="</div>",u}}(s,r);!function(e,{selectedColor:t="#ff9900",selectedBorderColor:o="#fff",selectedBorderWidth:i=4,defaultBorderColor:n="#fff",defaultBorderWidth:r=4,defaultColor:s="#5d8aff",markerImageElement:c,activeMarkerImageElement:l}){const a=c||j({fillColor:s,strokeColor:n,lineWidth:r}),d=l||c||j({fillColor:t,strokeColor:o,lineWidth:i});e.addImage("inactive-marker",a,{pixelRatio:2}),e.addImage("active-marker",d,{pixelRatio:2})}(t,r);const d={id:s,type:"symbol",source:e,filter:["!",["has","point_count"]],layout:{"icon-image":"inactive-marker"}};if(t.addLayer(Object.assign({},d)),i){if(!document.getElementById(F)){const e=document.createElement("style");e.setAttribute("id",F),document.head.append(e),e.textContent=".mapboxgl-popup-tip { display: none; }"}}return t.on("click",(function(){l()})),t.on("click",s,(function(e){if("function"==typeof r.onClick&&r.onClick(e),c=e.features[0].id,t.setLayoutProperty(s,"icon-image",["match",["id"],c,"active-marker","inactive-marker"]),i){const o=e.features[0],i=o.geometry.coordinates;if(w(i)){(new n.Popup).setLngLat(i).setHTML(a(o)).setOffset(15).addTo(t).on("close",(function(){c===o.id&&l()}))}}})),t.on("mouseover",s,(function(){t.getCanvas().style.cursor="pointer"})),t.on("mouseleave",s,(()=>{t.getCanvas().style.cursor=""})),{unclusteredLayerId:s}}function W(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg"),t=document.createElementNS("http://www.w3.org/2000/svg","path"),o=document.createElement("circle");return e.setAttribute("viewBox","0 0 64 64"),e.setAttribute("width","32"),e.setAttribute("height","32"),t.setAttribute("d",D),t.setAttribute("fill","#5d8aff"),o.setAttribute("fill","white"),o.setAttribute("cx","50%"),o.setAttribute("cy","50%"),o.setAttribute("r","5"),e.appendChild(o),e.appendChild(t),e}var q=function(e,t,o,i){return new(o||(o=Promise))((function(n,r){function s(e){try{l(i.next(e))}catch(e){r(e)}}function c(e){try{l(i.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,c)}l((i=i.apply(e,t||[])).next())}))},z=function(e,t){var o={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(e);n<i.length;n++)t.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(o[i[n]]=e[i[n]])}return o};const U={forwardGeocode:e=>q(void 0,void 0,void 0,(function*(){const t=[];try{const o=yield i.Geo.searchByText(e.query,{biasPosition:e.bbox?void 0:e.proximity,searchAreaConstraints:e.bbox,countries:e.countries,maxResults:e.limit});o&&o.forEach((e=>{const{geometry:o}=e,i=z(e,["geometry"]);t.push({type:"Feature",geometry:{type:"Point",coordinates:o.point},properties:Object.assign({},i),place_name:i.label,text:i.label,center:o.point})}))}catch(e){console.error(`Failed to forwardGeocode with error: ${e}`)}return{features:t}})),reverseGeocode:e=>q(void 0,void 0,void 0,(function*(){const t=[];try{const o=yield i.Geo.searchByCoordinates(e.query,{maxResults:e.limit});if(o&&o.geometry){const{geometry:e}=o,i=z(o,["geometry"]);t.push({type:"Feature",geometry:{type:"Point",coordinates:e.point},properties:Object.assign({},i),place_name:i.label,text:i.label,center:e.point})}}catch(e){console.error(`Failed to reverseGeocode with error: ${e}`)}return{features:t}})),getSuggestions:e=>q(void 0,void 0,void 0,(function*(){const t=[];try{const o=yield i.Geo.searchForSuggestions(e.query,{biasPosition:e.proximity,searchAreaConstraints:e.bbox,countries:e.countries,maxResults:e.limit});t.push(...o)}catch(e){console.error(`Failed to get suggestions with error: ${e}`)}return{suggestions:t}})),searchByPlaceId:e=>q(void 0,void 0,void 0,(function*(){let t;try{const o=yield i.Geo.searchByPlaceId(e.query);if(o){const{geometry:e}=o,i=z(o,["geometry"]);t={type:"Feature",geometry:{type:"Point",coordinates:e.point},properties:Object.assign({},i),place_name:i.label,text:i.label,center:e.point}}}catch(e){console.error(`Failed to get place with error: ${e}`)}return{place:t}}))};const K=/^[-._\p{L}\p{N}]+$/iu,Y=e=>({type:"Feature",geometry:{type:"MultiPolygon",coordinates:_(e)?e.map((e=>e.geometry.polygon)):e},properties:{}}),J=e=>({type:"Feature",geometry:{type:"Polygon",coordinates:e},properties:{}}),Q=(e,t,{bounds:o,radius:i})=>{if(!o&&!i)throw new Error("Circle requires a bounds or a radius");!function(e){const[t,o]=e;if(!Number.isFinite(t)||!Number.isFinite(o))throw new Error(`Invalid coordinates: [${t},${o}]`);if(o<-90||o>90){const e="Latitude must be between -90 and 90 degrees inclusive.";throw console.warn(e),new Error(e)}if(t<-180||t>180){const e="Longitude must be between -180 and 180 degrees inclusive.";throw console.warn(e),new Error(e)}}(t);const n=null!=i?i:X(o)/8;return{id:e,type:"Feature",properties:{isCircle:!0,center:t,radius:n},geometry:{type:"Polygon",coordinates:y.default(t,n,{units:"miles"}).geometry.coordinates}}},X=e=>{const t=e.getSouthWest().toArray(),o=e.getNorthEast().toArray(),i=e.getCenter().toArray(),n=a.lineString([t,i,o]);return b.default(n,{units:"miles"})},ee=(e,t)=>((e,t)=>!!t[e])(e,t);function te(e,t,o,i={}){var n,r,s,c,l,a,d,u;if(!o||"function"!=typeof o.addSource||"function"!=typeof o.addLayer)throw new Error("Please use a maplibre map");if(t.length>0&&!_(t)&&!A(t))throw new Error("Please pass in an array of Geofences or an array of Polygons");const f=`${e}`;o.addSource(f,{type:"geojson",data:Y(t),generateId:!0});const p=null===(n=i.visible)||void 0===n||n?"visible":"none",h=`${e}-fill-layer`;o.addLayer({id:h,type:"fill",source:f,layout:{visibility:p},paint:{"fill-color":null!==(r=i.fillColor)&&void 0!==r?r:P,"fill-opacity":null!==(s=i.fillOpacity)&&void 0!==s?s:.3}});const g=`${e}-outline-layer`;o.addLayer({id:g,type:"line",source:f,layout:{visibility:p},paint:{"line-color":null!==(c=i.borderColor)&&void 0!==c?c:P,"line-opacity":null!==(l=i.borderOpacity)&&void 0!==l?l:.5,"line-width":null!==(a=i.borderWidth)&&void 0!==a?a:4,"line-offset":null!==(d=i.borderOffset)&&void 0!==d?d:(null!==(u=i.borderWidth)&&void 0!==u?u:4)/2*-1}});return{sourceId:f,outlineLayerId:g,fillLayerId:h,show:()=>{o.setLayoutProperty(h,"visibility","visible"),o.setLayoutProperty(g,"visibility","visible")},hide:()=>{o.setLayoutProperty(h,"visibility","none"),o.setLayoutProperty(g,"visibility","none")},isVisible:()=>"visible"===o.getLayoutProperty(h,"visibility"),setData:e=>{o.getSource(f).setData(e)}}}var oe=function(e,t,o,i){return new(o||(o=Promise))((function(n,r){function s(e){try{l(i.next(e))}catch(e){r(e)}}function c(e){try{l(i.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,c)}l((i=i.apply(e,t||[])).next())}))};function ie(e,t){let o,i,n,r,s,c,l,a,u,f,p,h,g,m;function y(t){f=x("div","geofence-ctrl-create-circle-mode-container",t);x("div","geofence-ctrl-create-circle-mode-title",f).innerHTML="Radius",m=x("input","geofence-ctrl-create-circle-mode-input",f),m.addEventListener("keydown",d.debounce(e.updateInputRadius,200))}function b(t){p=x("div","geofence-ctrl-create-polygon-mode-container",t);const o=x("div","geofence-ctrl-create-polygon-mode-info-container",p),i=x("div","geofence-ctrl-create-polygon-mode-icon",o);x("div","geofence-ctrl-create-polygon-mode-info-icon",i).innerHTML="i";x("div","geofence-ctrl-create-polygon-mode-title",o).innerHTML="How it works?";const n=x("div","geofence-ctrl-create-polygon-mode-reset-button geofence-ctrl-button",p);n.innerHTML="Reset",n.addEventListener("click",(()=>{e.resetGeofence()}));const r=function(e){const t=x("div","geofence-ctrl-create-polygon-mode-popup-container",e),o=x("div","geofence-ctrl-create-polygon-mode-popup",t);return v(o,"Move dots to desired position",function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 38 38"),e.setAttribute("width","38"),e.setAttribute("height","38"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","circle");t.setAttribute("cx","19"),t.setAttribute("cy","18"),t.setAttribute("r","8"),t.setAttribute("fill","#FF9900");const o=document.createElementNS("http://www.w3.org/2000/svg","path");o.setAttribute("d","M19 0L23.3302 7.5H14.6699L19 0Z"),o.setAttribute("fill","#003560");const i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("d","M19 36.5L14.6698 29H23.3301L19 36.5Z"),i.setAttribute("fill","#003560");const n=document.createElementNS("http://www.w3.org/2000/svg","path");n.setAttribute("d","M0 18.33L7.5 13.9999L7.5 22.6602L0 18.33Z"),n.setAttribute("fill","#003560");const r=document.createElementNS("http://www.w3.org/2000/svg","path");return r.setAttribute("d","M37.5 18.3301L30 22.6603V14L37.5 18.3301Z"),r.setAttribute("fill","#003560"),e.appendChild(t),e.appendChild(o),e.appendChild(i),e.appendChild(n),e.appendChild(r),e}()),v(o,"Click on a border to create a dot",function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 42 27"),e.setAttribute("width","42"),e.setAttribute("height","27"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","line");t.setAttribute("y1","8"),t.setAttribute("x2","42"),t.setAttribute("y2","8"),t.setAttribute("stroke","black"),t.setAttribute("stroke-width","2");const o=document.createElementNS("http://www.w3.org/2000/svg","circle");o.setAttribute("cx","21"),o.setAttribute("cy","8"),o.setAttribute("r","8"),o.setAttribute("fill","#FF9900");const i=document.createElementNS("http://www.w3.org/2000/svg","path");return i.setAttribute("d","M21 6.17822V22.488L24.6951 19.4356L27.172 26.1782L29.0399 25.3582L26.6035 18.57L31.4762 17.9322L21 6.17822Z"),i.setAttribute("fill","#003560"),e.appendChild(t),e.appendChild(o),e.appendChild(i),e}()),v(o,"Click into shape to move",function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 32 32"),e.setAttribute("width","32"),e.setAttribute("height","32"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","rect");t.setAttribute("y","1"),t.setAttribute("x","1"),t.setAttribute("width","30"),t.setAttribute("height","30"),t.setAttribute("fill","#2196F3"),t.setAttribute("fill-opacity","0.4"),t.setAttribute("stroke","#003560"),t.setAttribute("stroke-width","2");const o=document.createElementNS("http://www.w3.org/2000/svg","path");return o.setAttribute("d","M11 6V22.3098L14.6951 19.2574L17.172 26L19.0399 25.18L16.6035 18.3918L21.4762 17.754L11 6Z"),o.setAttribute("fill","#003560"),e.appendChild(t),e.appendChild(o),e}()),v(o,"Press delete to remove a dot",function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 64 20"),e.setAttribute("width","64"),e.setAttribute("height","20"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","rect");t.setAttribute("y","0.5"),t.setAttribute("x","0.5"),t.setAttribute("width","63"),t.setAttribute("height","19"),t.setAttribute("rx","3.5"),t.setAttribute("stroke","#014478");const o=document.createElementNS("http://www.w3.org/2000/svg","path");return o.setAttribute("d","M14.4148 15C17.517 15 19.3118 13.076 19.3118 9.89418C19.3118 6.72727 17.517 4.81818 14.5192 4.81818H11.1186V15H14.4148ZM12.6548 13.6577V6.16051H14.4247C16.652 6.16051 17.8004 7.4929 17.8004 9.89418C17.8004 12.3054 16.652 13.6577 14.3303 13.6577H12.6548ZM24.394 15.1541C26.0595 15.1541 27.2377 14.3338 27.5758 13.0909L26.1689 12.8374C25.9004 13.5582 25.2541 13.9261 24.4089 13.9261C23.1362 13.9261 22.2811 13.1009 22.2413 11.6293H27.6703V11.1023C27.6703 8.34304 26.0197 7.2642 24.2896 7.2642C22.1618 7.2642 20.7598 8.88494 20.7598 11.2315C20.7598 13.603 22.1419 15.1541 24.394 15.1541ZM22.2463 10.5156C22.3059 9.43182 23.0914 8.49219 24.2995 8.49219C25.4529 8.49219 26.2086 9.3473 26.2136 10.5156H22.2463ZM30.8061 4.81818H29.3196V15H30.8061V4.81818ZM36.0971 15.1541C37.7626 15.1541 38.9409 14.3338 39.2789 13.0909L37.872 12.8374C37.6035 13.5582 36.9572 13.9261 36.112 13.9261C34.8393 13.9261 33.9842 13.1009 33.9444 11.6293H39.3734V11.1023C39.3734 8.34304 37.7228 7.2642 35.9927 7.2642C33.8649 7.2642 32.4629 8.88494 32.4629 11.2315C32.4629 13.603 33.845 15.1541 36.0971 15.1541ZM33.9494 10.5156C34.0091 9.43182 34.7946 8.49219 36.0027 8.49219C37.1561 8.49219 37.9118 9.3473 37.9167 10.5156H33.9494ZM44.5874 7.36364H43.0213V5.53409H41.5348V7.36364H40.4162V8.55682H41.5348V13.0661C41.5298 14.4531 42.5888 15.1243 43.7621 15.0994C44.2344 15.0945 44.5526 15.005 44.7266 14.9403L44.4581 13.7124C44.3587 13.7322 44.1747 13.777 43.9361 13.777C43.4538 13.777 43.0213 13.6179 43.0213 12.7578V8.55682H44.5874V7.36364ZM49.4409 15.1541C51.1064 15.1541 52.2846 14.3338 52.6227 13.0909L51.2157 12.8374C50.9473 13.5582 50.301 13.9261 49.4558 13.9261C48.1831 13.9261 47.3279 13.1009 47.2882 11.6293H52.7172V11.1023C52.7172 8.34304 51.0666 7.2642 49.3365 7.2642C47.2086 7.2642 45.8066 8.88494 45.8066 11.2315C45.8066 13.603 47.1887 15.1541 49.4409 15.1541ZM47.2931 10.5156C47.3528 9.43182 48.1383 8.49219 49.3464 8.49219C50.4998 8.49219 51.2555 9.3473 51.2605 10.5156H47.2931Z"),o.setAttribute("fill","black"),e.appendChild(t),e.appendChild(o),e}()),o}(i);o.addEventListener("click",(()=>{r.classList.toggle("show")}))}function v(e,t,o){const i=x("div","geofence-ctrl-create-polygon-mode-popup-step",e);x("div","geofence-ctrl-create-polygon-mode-popup-step-image",i).appendChild(o);x("div","geofence-ctrl-create-polygon-mode-popup-step-text",i).innerHTML=t}function w(){I(o),G(),u.style.display="flex"}function G(){g&&(I(g),g=void 0)}return{registerControlPosition:function(e,t){if(e._controlPositions[t])return;const o=document.createElement("div");o.className=`maplibregl-ctrl-${t}`,e._controlContainer.appendChild(o),e._controlPositions[t]=o},createElement:x,removeElement:I,createGeofenceCreateContainer:function(o){const i=x("div","geofence-ctrl-create-prompt-container",t);if(c=x("div","geofence-ctrl-create-prompt",i),o){const t=x("div","geofence-ctrl-create-prompt-buttons",c),o=x("div","geofence-ctrl-create-prompt-button-circle geofence-ctrl-create-prompt-button",t);o.addEventListener("click",(()=>{o.classList.add("geofence-ctrl-create-prompt-selected"),i.classList.remove("geofence-ctrl-create-prompt-selected"),p&&(I(p),p=void 0),f||y(c),e.changeMode("draw_circle")})),o.innerHTML="Circle";const i=x("div","geofence-ctrl-create-prompt-button-polygon geofence-ctrl-create-prompt-button",t);i.addEventListener("click",(()=>{e.changeMode("draw_polygon"),i.classList.add("geofence-ctrl-create-prompt-selected"),o.classList.remove("geofence-ctrl-create-prompt-selected"),f&&(I(f),f=void 0),p||b(c)})),i.innerHTML="Custom",o.classList.add("geofence-ctrl-create-prompt-selected"),y(c)}else b(c)},createGeofenceListContainer:function(){const i=x("div","geofence-ctrl-list-container",t);!function(t){const i=x("div","geofence-ctrl-list-header",t);l=x("div","geofence-ctrl-list-header-title",i),l.innerHTML="Geofences (0)",a=x("div","geofence-ctrl-list-header-checkbox-create-container",i),function(t){u=x("div","geofence-ctrl-list-checkbox-all-container",t),r=x("input","geofence-ctrl-list-checkbox-all",u),r.type="checkbox",r.addEventListener("click",(function(){r.checked?(e.displayAllGeofences(),i.innerHTML="Deselect All"):(e.hideAllGeofences(),i.innerHTML="Select All")}));const i=x("div","geofence-ctrl-list-checkbox-all-title",u);i.innerHTML="Select all",n=x("div","geofence-ctrl-list-header-add-button",u),n.innerHTML="+ Add",n.addEventListener("click",(()=>{!function(){u.style.display="none",o=x("div","geofence-ctrl-add-geofence-container",a);const t=x("div","geofence-ctrl-add-geofence",o),i=x("input","geofence-ctrl-add-geofence-input",t);i.placeholder="Enter name";const n=x("div","geofence-ctrl-add-geofence-buttons",t),r=x("div","geofence-ctrl-add-geofence-cancel-button geofence-ctrl-button ",n);r.innerHTML="Cancel",r.addEventListener("click",(()=>{w(),e.setEditingModeEnabled(!1)}));const s=x("div","geofence-ctrl-button geofence-ctrl-save-button",n);s.innerHTML="Save",s.addEventListener("click",(function(){return oe(this,void 0,void 0,(function*(){G();(yield e.createGeofence(escape(i.value)))&&w()}))})),e.addEditableGeofence()}()}))}(a)}(i),s=x("div","geofence-ctrl-list",i),s.addEventListener("scroll",(()=>{const{scrollHeight:t,scrollTop:o,clientHeight:i}=s;o+i>=t-20&&e.loadMoreGeofences()}))},removeAddGeofenceContainer:w,createAddGeofencePromptError:function(e){if(g)return;g=x("div","geofence-ctrl-add-geofence-error",o),x("div","geofence-ctrl-add-geofence-error-icon",g).appendChild(function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 12 10"),e.setAttribute("width","12"),e.setAttribute("height","10"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d","M0 10H11.5789L5.78947 0L0 10ZM6.31579 8.42105H5.26316V7.36842H6.31579V8.42105ZM6.31579 6.31579H5.26316V4.21053H6.31579V6.31579Z"),t.setAttribute("fill","#FF5050"),e.appendChild(t),e}()),x("div","geofence-ctrl-add-geofence-error-text",g).innerHTML=e},renderListItem:function(o){const n=x("li","geofence-ctrl-list-item-container",s);n.id=`list-item-${o.geofenceId}`;const r=x("li","geofence-ctrl-list-item",n),c=x("div","geofence-ctrl-list-item-left-container",r),l=x("input","geofence-ctrl-list-item-checkbox",c);l.id=`list-item-checkbox-${o.geofenceId}`,l.type="checkbox",l.addEventListener("click",(function(){l.checked?(e.displayGeofence(o.geofenceId),e.fitGeofence(o.geofenceId)):e.hideGeofence(o.geofenceId)}));const a=x("div","geofence-ctrl-list-item-right-container",r),d=x("div","geofence-ctrl-list-item-title-container",a);d.addEventListener("mouseover",(function(){e.displayHighlightedGeofence(o.geofenceId)})),d.addEventListener("mouseout",(function(){e.hideHighlightedGeofence()})),x("div","geofence-ctrl-list-item-title",d).innerHTML=o.geofenceId;const u=x("div","geofence-ctrl-edit-button",d);u.addEventListener("click",(function(){e.editGeofence(o.geofenceId),function(o,n,r,s){const c=x("div","geofence-ctrl-list-item-controls",n),l=function(o,n){const r=x("div","geofence-ctrl-delete-button",o);return r.classList.add("geofence-ctrl-button"),r.addEventListener("click",(function(){!function(o){i=x("div","geofence-ctrl-delete-prompt-container",t);const n=x("div","geofence-ctrl-delete-prompt",i);x("div","geofence-ctrl-delete-geofence-title",n).innerHTML=`Are you sure you want to delete <strong>${o}</strong>?`,function(o,n){const r=x("div","geofence-ctrl-delete-geofence-buttons",o),s=x("div","geofence-ctrl-delete-geofence-cancel-button",r);s.innerHTML="Cancel",s.addEventListener("click",(()=>{I(i)}));const c=x("div","geofence-ctrl-delete-geofence-confirm-button",r);c.innerHTML="Delete",c.addEventListener("click",(function(){return oe(this,void 0,void 0,(function*(){(yield e.deleteGeofence(n))&&(!function(e){h=x("div","geofence-ctrl-delete-popdown-container",t);const o=x("div","geofence-ctrl-delete-popdown",h),i=x("div","geofence-ctrl-delete-popdown-close-button",h);i.appendChild(function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 12 12"),e.setAttribute("width","12"),e.setAttribute("height","12"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d","M10.773 2.28762L9.71231 1.22696L6 4.93927L2.28769 1.22696L1.22703 2.28762L4.93934 5.99993L1.22703 9.71224L2.28769 10.7729L6 7.06059L9.71231 10.7729L10.773 9.71224L7.06066 5.99993L10.773 2.28762Z"),t.setAttribute("fill","white"),t.setAttribute("fill-rule","evenodd"),t.setAttribute("clip-rule","evenodd"),e.appendChild(t),e}()),i.addEventListener("click",(()=>{I(h)}));x("div","geofence-ctrl-delete-popdown-icon",o).appendChild(function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 12 12"),e.setAttribute("width","12"),e.setAttribute("height","12"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d","M6 0C2.688 0 0 2.688 0 6C0 9.312 2.688 12 6 12C9.312 12 12 9.312 12 6C12 2.688 9.312 0 6 0ZM6 10.8C3.354 10.8 1.2 8.646 1.2 6C1.2 3.354 3.354 1.2 6 1.2C8.646 1.2 10.8 3.354 10.8 6C10.8 8.646 8.646 10.8 6 10.8ZM8.754 3.348L4.8 7.302L3.246 5.754L2.4 6.6L4.8 9L9.6 4.2L8.754 3.348Z"),t.setAttribute("fill","white"),e.appendChild(t),e}());x("div","geofence-ctrl-delete-popdown-text",o).innerHTML=e?"Geofence was deleted successfully":"Geofence failed to delete"}(!0),I(i),e.setEditingModeEnabled(!1))}))}))}(n,o)}(n)})),r.appendChild(function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg"),t=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("viewBox","0 0 12 16"),e.setAttribute("width","12"),e.setAttribute("height","16"),e.setAttribute("fill","none"),t.setAttribute("d","M9.33317 5.5V13.8333H2.6665V5.5H9.33317ZM8.08317 0.5H3.9165L3.08317 1.33333H0.166504V3H11.8332V1.33333H8.9165L8.08317 0.5ZM10.9998 3.83333H0.999837V13.8333C0.999837 14.75 1.74984 15.5 2.6665 15.5H9.33317C10.2498 15.5 10.9998 14.75 10.9998 13.8333V3.83333Z"),t.setAttribute("fill","white"),e.appendChild(t),e}()),r}(r,s),a=()=>{o.classList.remove("geofence-ctrl-list-selected-item"),o.classList.add("geofence-ctrl-list-item"),I(c),I(l)},d=x("div","geofence-ctrl-cancel-button",c);d.classList.add("geofence-ctrl-button"),d.innerHTML="Cancel",d.addEventListener("click",(()=>{e.setEditingModeEnabled(!1),a()}));const u=x("div","geofence-ctrl-save-button geofence-ctrl-button",c);u.addEventListener("click",(()=>oe(this,void 0,void 0,(function*(){yield e.saveGeofence(),a()})))),u.title="Save",u.innerHTML="Save"}(r,a,c,o.geofenceId),r.classList.remove("geofence-ctrl-list-item"),r.classList.add("geofence-ctrl-list-selected-item")})),u.appendChild(function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg"),t=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("viewBox","0 0 16 16"),e.setAttribute("width","16"),e.setAttribute("height","16"),e.setAttribute("fill","none"),t.setAttribute("d","M0.5 12.375V15.5H3.625L12.8417 6.28333L9.71667 3.15833L0.5 12.375ZM2.93333 13.8333H2.16667V13.0667L9.71667 5.51667L10.4833 6.28333L2.93333 13.8333ZM15.2583 2.69167L13.3083 0.741667C13.1417 0.575 12.9333 0.5 12.7167 0.5C12.5 0.5 12.2917 0.583333 12.1333 0.741667L10.6083 2.26667L13.7333 5.39167L15.2583 3.86667C15.5833 3.54167 15.5833 3.01667 15.2583 2.69167Z"),t.setAttribute("fill","white"),e.appendChild(t),e}())},updateCheckbox:function(e,t){const o=document.getElementById(`list-item-checkbox-${e}`);o&&(o.checked=t)},removeGeofenceListItem:function(e){I(document.getElementById(`list-item-${e}`))},setGeofenceListEnabled:function(e){r.disabled=!e,e?n.classList.remove("geofence-ctrl-noHover"):n.classList.add("geofence-ctrl-noHover");const t=document.getElementsByClassName("geofence-ctrl-list-item-checkbox");for(let o=0;o<t.length;o++)t.item(o).disabled=!e;const o=document.getElementsByClassName("geofence-ctrl-list-item-container");for(let t=0;t<o.length;t++)e?o.item(t).classList.remove("geofence-ctrl-noHover"):o.item(t).classList.add("geofence-ctrl-noHover")},getCheckboxAllValue:function(){return r.checked},removeGeofenceCreateContainer:function(){I(c),c=void 0,f=void 0,p=void 0},updateGeofenceCount:function(e){l.innerHTML=`Geofences (${e})`},updateGeofenceRadius:function(e){m&&(m.value=`${e}`)}}}class ne{constructor(e,t){this._mapBoxDraw=new v.default({displayControlsDefault:!1,defaultMode:"simple_select",userProperties:!0,controls:{trash:!0},modes:Object.assign(Object.assign({},v.default.modes),{draw_circle:f.CircleMode,direct_select:f.DirectMode,simple_select:f.SimpleSelectMode}),styles:[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"],["!=","mode","static"]],paint:{"fill-color":T,"fill-outline-color":T,"fill-opacity":.3}},{id:"gl-draw-polygon-midpoint",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"]],paint:{"circle-radius":5,"circle-color":N}},{id:"gl-draw-polygon-stroke-active",type:"line",filter:["all",["==","$type","Polygon"],["!=","mode","static"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":R,"line-width":4}},{id:"gl-draw-polygon-and-line-vertex-active",type:"circle",filter:["all",["==","meta","vertex"],["==","$type","Point"],["!=","mode","static"]],paint:{"circle-radius":8,"circle-color":N,"circle-stroke-color":R,"circle-stroke-width":1}}]}),this._map=e,this._ui=t,this.enable=this.enable.bind(this),this.disable=this.disable.bind(this),this.drawPolygonGeofence=this.drawPolygonGeofence.bind(this)}get(e){return this._mapBoxDraw.get(e)}add(e){const t=e.properties.isCircle;this.enable(t),this._mapBoxDraw.add(e),this._mapBoxDraw.changeMode("direct_select",{featureId:e.id})}delete(e){this._mapBoxDraw.delete(e)}disable(){this._map.hasControl(this._mapBoxDraw)&&this._map.removeControl(this._mapBoxDraw),this._ui.removeGeofenceCreateContainer()}enable(e){this._map.hasControl(this._mapBoxDraw)||(this._map.addControl(this._mapBoxDraw,"bottom-right"),this._ui.createGeofenceCreateContainer(e))}drawPolygonGeofence(e){const t=((e,t)=>{const o=t.getSouthWest().toArray(),i=t.getNorthEast().toArray(),n=t.getCenter().toArray(),r=a.lineString([o,n,i]),s=b.default(r,{units:"miles"}),c=m.default(r,s/4,{units:"miles"}).geometry.coordinates,l=m.default(r,s*(3/4),{units:"miles"}).geometry.coordinates;return{id:e,type:"Feature",geometry:{type:"Polygon",coordinates:[[l,[c[0],l[1]],c,[l[0],c[1]],l]]},properties:{}}})(e,this._map.getBounds());this.add(t)}drawCircularGeofence(e,t){const o=this._map.getBounds(),i=Q(e,this._map.getCenter().toArray(),{bounds:o,radius:t});this.add(i),this._ui.updateGeofenceRadius(t||i.properties.radius.toFixed(2))}}var re=function(e,t,o,i){return new(o||(o=Promise))((function(n,r){function s(e){try{l(i.next(e))}catch(e){r(e)}}function c(e){try{l(i.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,c)}l((i=i.apply(e,t||[])).next())}))};const se={left:240};e.AmplifyGeocoderAPI=U,e.AmplifyGeofenceControl=class{constructor(e){this._geofenceCollectionId=null==e?void 0:e.geofenceCollectionId,this._loadedGeofences={},this._displayedGeofences=[],this.changeMode=this.changeMode.bind(this),this.loadInitialGeofences=this.loadInitialGeofences.bind(this),this.loadMoreGeofences=this.loadMoreGeofences.bind(this),this._loadGeofence=this._loadGeofence.bind(this),this.updateInputRadius=this.updateInputRadius.bind(this),this.saveGeofence=this.saveGeofence.bind(this),this.editGeofence=this.editGeofence.bind(this),this.deleteGeofence=this.deleteGeofence.bind(this),this.displayAllGeofences=this.displayAllGeofences.bind(this),this.hideAllGeofences=this.hideAllGeofences.bind(this),this.addEditableGeofence=this.addEditableGeofence.bind(this),this.setEditingModeEnabled=this.setEditingModeEnabled.bind(this),this.displayHighlightedGeofence=this.displayHighlightedGeofence.bind(this),this.hideHighlightedGeofence=this.hideHighlightedGeofence.bind(this),this.displayGeofence=this.displayGeofence.bind(this),this.hideGeofence=this.hideGeofence.bind(this),this.fitGeofence=this.fitGeofence.bind(this),this.fitAllGeofences=this.fitAllGeofences.bind(this)}getDefaultPosition(){return"full-screen"}onRemove(){this._ui.removeElement(this._container)}reorderMapLibreClassNames(){const e=document.getElementsByClassName("maplibregl-canvas").item(0);e&&(e.className="mapboxgl-canvas maplibregl-canvas")}onAdd(e){return this._map=e,this.reorderMapLibreClassNames(),this._container=x("div","geofence-ctrl maplibregl-ctrl"),this._ui=ie(this,this._container),this._amplifyDraw=new ne(e,this._ui),this._ui.registerControlPosition(e,"full-screen"),this._ui.createGeofenceListContainer(),this._map.once("load",function(){this._map.getSource("displayedGeofences")||(this._drawGeofencesOutput=te("displayedGeofences",[],this._map,{fillColor:T,borderColor:R,borderOpacity:1}),this._highlightedGeofenceOutput=te("highlightedGeofence",[],this._map,{fillColor:T,borderColor:R,borderOpacity:1,borderWidth:6}),this.loadInitialGeofences(),e.addControl(new h.default.NavigationControl({showCompass:!1}),"bottom-right"))}.bind(this)),this._map.on("draw.update",(()=>{const e=this._amplifyDraw._mapBoxDraw.getAll().features[0].geometry.coordinates[0],t=((e,t)=>{const o=a.lineString([e,t]);return b.default(o,{units:"miles"})})(e[0],e[Math.floor(e.length/2)])/2;this._ui.updateGeofenceRadius(t.toFixed(2))})),this._container}createGeofence(e){return re(this,void 0,void 0,(function*(){if(e&&0!==e.length)if(e.match(K)){if(!ee(e,this._loadedGeofences))return this.saveGeofence(e);this._ui.createAddGeofencePromptError("Geofence ID already exists.")}else this._ui.createAddGeofencePromptError("Geofence ID contains special characters.");else this._ui.createAddGeofencePromptError("Geofence ID is empty.")}))}saveGeofence(e){return re(this,void 0,void 0,(function*(){const t=this._amplifyDraw.get(this._editingGeofenceId),o=e||this._editingGeofenceId,n=yield i.Geo.saveGeofences({geofenceId:o,geometry:{polygon:t.geometry.coordinates}});if(n.errors[0]){const e=n.errors[0];throw new Error(`There was an error saving geofence with id ${o}: ${e.error.code} - ${e.error.message}`)}const r={geofenceId:n.successes[0].geofenceId,geometry:{polygon:t.geometry.coordinates}};return this._loadGeofence(r),this.displayGeofence(r.geofenceId),this.setEditingModeEnabled(!1),r.geofenceId}))}loadInitialGeofences(){return re(this,void 0,void 0,(function*(){try{const{entries:e,nextToken:t}=yield i.Geo.listGeofences();this._listGeofencesNextToken=t;const o=this._loadGeofence;e.forEach((e=>o(e))),this._ui.updateGeofenceCount(Object.keys(this._loadedGeofences).length)}catch(e){throw new Error(`Error calling listGeofences: ${e}`)}}))}loadMoreGeofences(){return re(this,void 0,void 0,(function*(){if(this._listGeofencesNextToken)try{const{entries:e,nextToken:t}=yield i.Geo.listGeofences({nextToken:this._listGeofencesNextToken});this._listGeofencesNextToken=t;const o=this._loadGeofence;e.forEach((e=>o(e))),this._ui.updateGeofenceCount(Object.keys(this._loadedGeofences).length)}catch(e){throw new Error(`Error calling listGeofences: ${e}`)}}))}editGeofence(e){this.setEditingModeEnabled(!0);const t=this._loadedGeofences[e];if(!t)throw new Error(`Geofence with id ${e} does not exist`);const o=J(t.geometry.polygon),i=Object.assign({id:t.geofenceId},o);this._amplifyDraw.add(i),this._editingGeofenceId=t.geofenceId}deleteGeofence(e){return re(this,void 0,void 0,(function*(){const t=yield i.Geo.deleteGeofences(e);if(t.errors[0]){const o=t.errors[0].error;throw new Error(`There was an error deleting geofence with id ${e}: ${o.code} - ${o.message}`)}return this._ui.removeGeofenceListItem(e),delete this._loadedGeofences[e],this._ui.updateGeofenceCount(Object.keys(this._loadedGeofences).length),this._displayedGeofences=this._displayedGeofences.filter((t=>t.geofenceId!==e)),this._updateDisplayedGeofences(),e}))}deleteSelectedGeofences(){this._displayedGeofences.map((e=>e.geofenceId)).forEach((e=>{this._ui.removeGeofenceListItem(e),delete this._loadedGeofences[e]})),this._displayedGeofences=[],this._updateDisplayedGeofences()}_loadGeofence(e){this._loadedGeofences[e.geofenceId]?this._displayedGeofences=this._displayedGeofences.filter((t=>t.geofenceId!==e.geofenceId)):this._ui.renderListItem(e),this._loadedGeofences[e.geofenceId]=e,this._ui.updateGeofenceCount(Object.keys(this._loadedGeofences).length)}displayGeofence(e){this._displayedGeofences.push(this._loadedGeofences[e]),this._updateDisplayedGeofences(),this._ui.updateCheckbox(e,!0),this.fitAllGeofences()}displayAllGeofences(){this._displayedGeofences.push(...Object.values(this._loadedGeofences)),this._updateDisplayedGeofences();const e=document.getElementsByClassName("geofence-ctrl-list-item-checkbox");Array.from(e).forEach((e=>e.checked=this._ui.getCheckboxAllValue())),this.fitAllGeofences()}fitGeofence(e){const t=this._map.getBounds();this._loadedGeofences[e].geometry.polygon[0].forEach((e=>{t.extend(e)})),this._map.fitBounds(t,{padding:se})}fitAllGeofences(){let e=!1;const t=this._map.getBounds();this._displayedGeofences.forEach((o=>{o.geometry.polygon[0].forEach((o=>{t.contains(o)||(t.extend(o),e=!0)}))})),e&&this._map.fitBounds(t,{padding:se})}hideGeofence(e){this._displayedGeofences=this._displayedGeofences.filter((t=>t.geofenceId!==e)),this._updateDisplayedGeofences(),this._ui.updateCheckbox(e,!1)}hideAllGeofences(){this._displayedGeofences=[],this._updateDisplayedGeofences();const e=document.getElementsByClassName("geofence-ctrl-list-item-checkbox");Array.from(e).forEach((e=>e.checked=this._ui.getCheckboxAllValue()))}_updateDisplayedGeofences(){const e=Y(this._displayedGeofences);this._drawGeofencesOutput.setData(e)}displayHighlightedGeofence(e){const t=this._loadedGeofences[e];if(!t)return void console.warn(`Geofence with id ${e} does not exist`);const o=J(t.geometry.polygon);this._highlightedGeofenceOutput.setData(o),this._highlightedGeofenceOutput.show()}hideHighlightedGeofence(){this._highlightedGeofenceOutput.hide()}changeMode(e){this._amplifyDraw.delete(this._editingGeofenceId),"draw_circle"===e?this._amplifyDraw.drawCircularGeofence(this._editingGeofenceId):this._amplifyDraw.drawPolygonGeofence(this._editingGeofenceId)}resetGeofence(){this._amplifyDraw.delete(this._editingGeofenceId),ee(this._editingGeofenceId,this._loadedGeofences)?this.editGeofence(this._editingGeofenceId):this._amplifyDraw.drawPolygonGeofence(this._editingGeofenceId)}setEditingModeEnabled(e){e?this._amplifyDraw.enable():this._amplifyDraw.disable(),e?this._drawGeofencesOutput.hide():this._drawGeofencesOutput.show(),this._ui.setGeofenceListEnabled(!e)}updateInputRadius(e){const t=e.target.value,o=parseInt(t);isNaN(o)||this._amplifyDraw.drawCircularGeofence(this._editingGeofenceId,o)}addEditableGeofence(){this._editingGeofenceId="tempGeofence",this._amplifyDraw.drawCircularGeofence("tempGeofence"),this.setEditingModeEnabled(!0)}},e.AmplifyMapLibreRequest=S,e.createAmplifyGeocoder=function(e){return new g.default(U,Object.assign({maplibregl:h.default,showResultMarkers:{element:W()},marker:{element:W()},showResultsWhileTyping:null==e?void 0:e.autocomplete},e))},e.createDefaultIcon=W,e.createMap=e=>M(void 0,void 0,void 0,(function*(){return S.createMapLibreMap(e)})),e.drawGeofences=te,e.drawPoints=function(e,t,o,{showCluster:n=!0,clusterOptions:r={},unclusteredOptions:s={},autoFit:c=!0}={},l){var a,d;if(!o||"function"!=typeof o.addSource||"function"!=typeof o.addLayer)throw new Error("Please use a maplibre map");const u=E(t),f=e;let p,h;o.addSource(f,{type:"geojson",data:{type:"FeatureCollection",features:u},cluster:n,clusterMaxZoom:null!==(a=r.clusterMaxZoom)&&void 0!==a?a:14,clusterRadius:null!==(d=r.smCircleSize)&&void 0!==d?d:60,generateId:!0}),n&&({clusterLayerId:p,clusterSymbolLayerId:h}=function(e,t,{fillColor:o="#5d8aff",smCircleSize:n=60,smThreshold:r=50,mdCircleSize:s=100,mdThreshold:c=100,lgCircleSize:l=140,lgThreshold:a=500,xlCircleSize:d=180,borderWidth:u=4,borderColor:f="#fff",clusterPaint:p,onClick:h,showCount:g,clusterCountLayout:m,fontColor:y="#fff"},b){const v=`${e}-layer-clusters`,w=`${e}-layer-cluster-count`,G=Object.assign({"circle-color":["step",["get","point_count"],o,r,o,c,o,a,o],"circle-radius":["step",["get","point_count"],n,r,s,c,l,a,d],"circle-stroke-width":u,"circle-stroke-color":f},p),C={id:v,type:"circle",source:e,filter:["has","point_count"],paint:G};if(t.addLayer(Object.assign({},C)),t.on("click",v,(function(o){"function"==typeof h&&h(o);const i=t.queryRenderedFeatures(o.point,{layers:[v]}),n=i[0].properties.cluster_id,r=t.getSource(e);(function(e){return"geojson"===e.type})(r)&&r.getClusterExpansionZoom(n,(function(e,o){e||t.easeTo({center:i[0].geometry.coordinates,zoom:o})}))})),g){const o={"text-field":"{point_count_abbreviated}","text-size":24},n=b||i.Geo.getDefaultMap().style;n&&(o["text-font"]=[B[n]]);const r=Object.assign(Object.assign({},o),m),s={id:w,type:"symbol",source:e,filter:["has","point_count"],layout:r,paint:{"text-color":y}};t.addLayer(Object.assign({},s))}return{clusterLayerId:v,clusterSymbolLayerId:w}}(f,o,r,l));const{unclusteredLayerId:g}=Z(f,o,s||{});if(c){const e=o.getBounds();u.forEach((function(t){e.extend(t.geometry.coordinates)})),o.fitBounds(e)}return{sourceId:f,unclusteredLayerId:g,clusterLayerId:p,clusterSymbolLayerId:h,setData:e=>{const t=E(e);o.getSource(f).setData({type:"FeatureCollection",features:t})},show:()=>{o.setLayoutProperty(g,"visibility","visible"),p&&o.setLayoutProperty(p,"visibility","visible"),h&&o.setLayoutProperty(h,"visibility","visible")},hide:()=>{o.setLayoutProperty(g,"visibility","none"),p&&o.setLayoutProperty(p,"visibility","none"),h&&o.setLayoutProperty(h,"visibility","none")}}},Object.defineProperty(e,"__esModule",{value:!0})}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@aws-amplify/core"),require("@aws-amplify/core/internals/utils"),require("@aws-amplify/geo"),require("maplibre-gl"),require("@maplibre/maplibre-gl-geocoder"),require("@turf/along"),require("@turf/circle"),require("@turf/length"),require("@turf/helpers"),require("debounce"),require("@mapbox/mapbox-gl-draw"),require("maplibre-gl-draw-circle")):"function"==typeof define&&define.amd?define(["exports","@aws-amplify/core","@aws-amplify/core/internals/utils","@aws-amplify/geo","maplibre-gl","@maplibre/maplibre-gl-geocoder","@turf/along","@turf/circle","@turf/length","@turf/helpers","debounce","@mapbox/mapbox-gl-draw","maplibre-gl-draw-circle"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).AmplifyMapLibre={},e.aws_amplify_core,e.utils,e.aws_amplify_geo,e.maplibregl,e.MaplibreGeocoder,e.along,e.circle,e.length,e.helpers,e.debounce,e.MapboxDraw,e.maplibreGlDrawCircle)}(this,(function(e,t,o,i,n,r,s,c,l,a,d,u,f){"use strict";function p(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var h=p(n),g=p(r),m=p(s),y=p(c),b=p(l),v=p(u);function w(e){return Array.isArray(e)&&"number"==typeof e[0]&&"number"==typeof e[1]}function G(e){return w(e[0])}function C(e){return(t=e[0])&&Array.isArray(t.coordinates)&&"number"==typeof t.coordinates[0]&&"number"==typeof t.coordinates[1];var t}function _(e){return Array.isArray(e)&&((t=e[0])&&"string"==typeof t.geofenceId&&"object"==typeof t.geometry);var t}function A(e){return Array.isArray(e)&&(t=e[0],Array.isArray(t)&&G(t[0]));var t}const L=e=>"string"==typeof e&&e.length>0,E=e=>{let t;return t=G(e)?e.map((e=>({type:"Feature",geometry:{type:"Point",coordinates:e},properties:{place_name:`Coordinates,${e}`}}))):C(e)?e.map((e=>({type:"Feature",geometry:{type:"Point",coordinates:e.coordinates},properties:{title:e.title,address:e.address}}))):e,t};function x(e,t,o){const i=window.document.createElement(e);return void 0!==t&&(i.className=t),o&&o.appendChild(i),i}function I(e){e.parentNode&&e.parentNode.removeChild(e)}function M(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}var k=function(e,t,o,i){return new(o||(o=Promise))((function(n,r){function s(e){try{l(i.next(e))}catch(e){r(e)}}function c(e){try{l(i.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,c)}l((i=i.apply(e,t||[])).next())}))},S=function(e,t){var o={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(e);n<i.length;n++)t.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(o[i[n]]=e[i[n]])}return o};class H{constructor(e,i){this.refreshCredentials=()=>k(this,void 0,void 0,(function*(){try{this.credentials=(yield t.fetchAuthSession()).credentials}catch(e){throw console.error(`Failed to refresh credentials: ${e}`),e}})),this.refreshCredentialsWithRetry=()=>k(this,void 0,void 0,(function*(){try{const e=3e5;if(yield o.jitteredExponentialRetry(this.refreshCredentials,[],e),this.activeTimeout&&clearTimeout(this.activeTimeout),this.credentials.expiration.getTime()>(new Date).getTime()){const e=new Date(this.credentials.expiration).getTime()-(new Date).getTime()-1e4;this.activeTimeout=window.setTimeout(this.refreshCredentialsWithRetry,Math.min(e,36e5))}}catch(e){console.error(`Failed to refresh credentials: ${e}`)}})),this.transformRequest=(e,t)=>{let i=e;if("Style"===t&&!e.includes("://")){if(null==this.region)throw new Error("AWS region for map is undefined. Please verify that the region is set in aws-exports.js or that you are providing an AWS region parameter to createMap");i=`https://maps.geo.${this.region}.amazonaws.com/maps/v0/maps/${e}/style-descriptor`}const n=new URL(i);if(n.hostname.endsWith(".amazonaws.com"))return n.searchParams.append("x-amz-user-agent",encodeURIComponent(function(){const e=o.getAmplifyUserAgent();return e&&"object"==typeof e?e.map((([e,t])=>`${e}/${t}`)).join(" "):e}().replace(/\./g,"%2E"))),{url:o.Signer.signUrl(n.href,{access_key:this.credentials.accessKeyId,secret_key:this.credentials.secretAccessKey,session_token:this.credentials.sessionToken})}},this.credentials=e,this.region=i,this.activeTimeout=null,this.refreshCredentialsWithRetry(),t.Hub.listen("auth",(e=>{switch(e.payload.event){case"signedIn":case"signedOut":case"tokenRefresh":this.refreshCredentialsWithRetry()}}))}}H.createMapLibreMap=e=>k(void 0,void 0,void 0,(function*(){const{region:o,mapConstructor:r=n.Map}=e,s=S(e,["region","mapConstructor"]),c=i.Geo.getDefaultMap(),l=new H((yield t.fetchAuthSession()).credentials,o||c.region).transformRequest;return new r(Object.assign(Object.assign({},s),{style:e.style||c.mapName,transformRequest:l}))}));const P="#fff",O="#000",T="#5d8aff",R="#2194f3",N="#003560",D="#FF9900",$="M24.8133 38.533C18.76 31.493 13 28.8264 13 20.8264C13.4827 14.9864 16.552 9.67169 21.368 6.33302C33.768 -2.26165 50.824 5.78902 52.0667 20.8264C52.0667 28.613 46.5733 31.6797 40.6533 38.373C32.4933 47.5464 35.4 63.093 32.4933 63.093C29.72 63.093 32.4933 47.5464 24.8133 38.533ZM32.4933 8.23969C26.5573 8.23969 21.7467 13.0504 21.7467 18.9864C21.7467 24.9224 26.5573 29.733 32.4933 29.733C38.4293 29.733 43.24 24.9224 43.24 18.9864C43.24 13.0504 38.4293 8.23969 32.4933 8.23969Z";var B;!function(e){e.ESRI_TOPOGRAPHIC="VectorEsriTopographic",e.ESRI_STREETS="VectorEsriStreets",e.ESRI_LIGHT_GRAY="VectorEsriLightGrayCanvas",e.ESRI_DARK_GRAY="VectorEsriDarkGrayCanvas",e.ESRI_NAVIGATION="VectorEsriNavigation",e.HERE_BERLIN="VectorHereBerlin"}(B||(B={}));const j={[B.ESRI_TOPOGRAPHIC]:"Noto Sans Regular",[B.ESRI_STREETS]:"Arial Regular",[B.ESRI_LIGHT_GRAY]:"Ubuntu Regular",[B.ESRI_DARK_GRAY]:"Ubuntu Regular",[B.ESRI_NAVIGATION]:"Arial Regular",[B.HERE_BERLIN]:"Fira GO Regular"};function V(e){const t=(null==e?void 0:e.fillColor)?e.fillColor:T,o=(null==e?void 0:e.strokeColor)?e.strokeColor:P,i=(null==e?void 0:e.lineWidth)?e.lineWidth:4;return{width:64,height:64,data:new Uint8Array(16384),onAdd:function(){const e=document.createElement("canvas");e.width=this.width,e.height=this.height,this.context=e.getContext("2d")},render:function(){const e=this.context,n=new Path2D($);return e.stroke(n),e.fillStyle=t,e.strokeStyle=o,e.lineWidth=i,e.fill(n),this.data=e.getImageData(0,0,this.width,this.height).data,!0}}}var F=function(e,t){var o={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(e);n<i.length;n++)t.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(o[i[n]]=e[i[n]])}return o};const Z="amplify-tip";function q(e,t,o){var{showMarkerPopup:i=!1}=o,r=F(o,["showMarkerPopup"]);const s=`${e}-layer-unclustered-point`;let c=null;function l(){null!==c&&(t.setLayoutProperty(s,"icon-image","inactive-marker"),c=null)}const a=r.popupRender?r.popupRender:function(e,{popupBackgroundColor:t="#fff",popupBorderColor:o="#0000001f",popupBorderWidth:i=2,popupFontColor:n="#000",popupPadding:r=20,popupBorderRadius:s=4,popupTitleFontWeight:c="bold"}){return l=>{let a,d;if(L(l.properties.place_name)){const e=l.properties.place_name.split(",");a=e[0],d=e.splice(1,e.length).join(",")}else L(l.properties.title)||L(l.properties.address)?(a=l.properties.title,d=l.properties.address):(a="Coordinates",d=l.geometry.coordinates);const u=M(String(a)),f=M(String(d));let p=`<div class="${e}-popup" style="background: ${t}; border: ${i}px solid ${o}; color: ${n}; border-radius: ${s}px; padding: ${r}px; word-wrap: break-word; margin: -10px -10px -15px;">`;return a&&(p+=`<div class="${e}-popup-title" style="font-weight: ${c};">${u}</div>`),d&&(p+=`<div class="${e}-popup-address">${f}</div>`),p+="</div>",p}}(s,r);!function(e,{selectedColor:t="#ff9900",selectedBorderColor:o="#fff",selectedBorderWidth:i=4,defaultBorderColor:n="#fff",defaultBorderWidth:r=4,defaultColor:s="#5d8aff",markerImageElement:c,activeMarkerImageElement:l}){const a=c||V({fillColor:s,strokeColor:n,lineWidth:r}),d=l||c||V({fillColor:t,strokeColor:o,lineWidth:i});e.addImage("inactive-marker",a,{pixelRatio:2}),e.addImage("active-marker",d,{pixelRatio:2})}(t,r);const d={id:s,type:"symbol",source:e,filter:["!",["has","point_count"]],layout:{"icon-image":"inactive-marker"}};if(t.addLayer(Object.assign({},d)),i){if(!document.getElementById(Z)){const e=document.createElement("style");e.setAttribute("id",Z),document.head.append(e),e.textContent=".mapboxgl-popup-tip { display: none; }"}}return t.on("click",(function(){l()})),t.on("click",s,(function(e){if("function"==typeof r.onClick&&r.onClick(e),c=e.features[0].id,t.setLayoutProperty(s,"icon-image",["match",["id"],c,"active-marker","inactive-marker"]),i){const o=e.features[0],i=o.geometry.coordinates;if(w(i)){(new n.Popup).setLngLat(i).setHTML(a(o)).setOffset(15).addTo(t).on("close",(function(){c===o.id&&l()}))}}})),t.on("mouseover",s,(function(){t.getCanvas().style.cursor="pointer"})),t.on("mouseleave",s,(()=>{t.getCanvas().style.cursor=""})),{unclusteredLayerId:s}}function W(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg"),t=document.createElementNS("http://www.w3.org/2000/svg","path"),o=document.createElement("circle");return e.setAttribute("viewBox","0 0 64 64"),e.setAttribute("width","32"),e.setAttribute("height","32"),t.setAttribute("d",$),t.setAttribute("fill","#5d8aff"),o.setAttribute("fill","white"),o.setAttribute("cx","50%"),o.setAttribute("cy","50%"),o.setAttribute("r","5"),e.appendChild(o),e.appendChild(t),e}var z=function(e,t,o,i){return new(o||(o=Promise))((function(n,r){function s(e){try{l(i.next(e))}catch(e){r(e)}}function c(e){try{l(i.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,c)}l((i=i.apply(e,t||[])).next())}))},U=function(e,t){var o={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(e);n<i.length;n++)t.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(o[i[n]]=e[i[n]])}return o};const K={forwardGeocode:e=>z(void 0,void 0,void 0,(function*(){const t=[];try{const o=yield i.Geo.searchByText(e.query,{biasPosition:e.bbox?void 0:e.proximity,searchAreaConstraints:e.bbox,countries:e.countries,maxResults:e.limit});o&&o.forEach((e=>{const{geometry:o}=e,i=U(e,["geometry"]);t.push({type:"Feature",geometry:{type:"Point",coordinates:o.point},properties:Object.assign({},i),place_name:i.label,text:i.label,center:o.point})}))}catch(e){console.error(`Failed to forwardGeocode with error: ${e}`)}return{features:t}})),reverseGeocode:e=>z(void 0,void 0,void 0,(function*(){const t=[];try{const o=yield i.Geo.searchByCoordinates(e.query,{maxResults:e.limit});if(o&&o.geometry){const{geometry:e}=o,i=U(o,["geometry"]);t.push({type:"Feature",geometry:{type:"Point",coordinates:e.point},properties:Object.assign({},i),place_name:i.label,text:i.label,center:e.point})}}catch(e){console.error(`Failed to reverseGeocode with error: ${e}`)}return{features:t}})),getSuggestions:e=>z(void 0,void 0,void 0,(function*(){const t=[];try{const o=yield i.Geo.searchForSuggestions(e.query,{biasPosition:e.proximity,searchAreaConstraints:e.bbox,countries:e.countries,maxResults:e.limit});t.push(...o)}catch(e){console.error(`Failed to get suggestions with error: ${e}`)}return{suggestions:t}})),searchByPlaceId:e=>z(void 0,void 0,void 0,(function*(){let t;try{const o=yield i.Geo.searchByPlaceId(e.query);if(o){const{geometry:e}=o,i=U(o,["geometry"]);t={type:"Feature",geometry:{type:"Point",coordinates:e.point},properties:Object.assign({},i),place_name:i.label,text:i.label,center:e.point}}}catch(e){console.error(`Failed to get place with error: ${e}`)}return{place:t}}))};const Y=/^[-._\p{L}\p{N}]+$/iu,J=e=>({type:"Feature",geometry:{type:"MultiPolygon",coordinates:_(e)?e.map((e=>e.geometry.polygon)):e},properties:{}}),Q=e=>({type:"Feature",geometry:{type:"Polygon",coordinates:e},properties:{}}),X=(e,t,{bounds:o,radius:i})=>{if(!o&&!i)throw new Error("Circle requires a bounds or a radius");!function(e){const[t,o]=e;if(!Number.isFinite(t)||!Number.isFinite(o))throw new Error(`Invalid coordinates: [${t},${o}]`);if(o<-90||o>90){const e="Latitude must be between -90 and 90 degrees inclusive.";throw console.warn(e),new Error(e)}if(t<-180||t>180){const e="Longitude must be between -180 and 180 degrees inclusive.";throw console.warn(e),new Error(e)}}(t);const n=null!=i?i:ee(o)/8;return{id:e,type:"Feature",properties:{isCircle:!0,center:t,radius:n},geometry:{type:"Polygon",coordinates:y.default(t,n,{units:"miles"}).geometry.coordinates}}},ee=e=>{const t=e.getSouthWest().toArray(),o=e.getNorthEast().toArray(),i=e.getCenter().toArray(),n=a.lineString([t,i,o]);return b.default(n,{units:"miles"})},te=(e,t)=>((e,t)=>!!t[e])(e,t);function oe(e,t,o,i={}){var n,r,s,c,l,a,d,u;if(!o||"function"!=typeof o.addSource||"function"!=typeof o.addLayer)throw new Error("Please use a maplibre map");if(t.length>0&&!_(t)&&!A(t))throw new Error("Please pass in an array of Geofences or an array of Polygons");const f=`${e}`;o.addSource(f,{type:"geojson",data:J(t),generateId:!0});const p=null===(n=i.visible)||void 0===n||n?"visible":"none",h=`${e}-fill-layer`;o.addLayer({id:h,type:"fill",source:f,layout:{visibility:p},paint:{"fill-color":null!==(r=i.fillColor)&&void 0!==r?r:O,"fill-opacity":null!==(s=i.fillOpacity)&&void 0!==s?s:.3}});const g=`${e}-outline-layer`;o.addLayer({id:g,type:"line",source:f,layout:{visibility:p},paint:{"line-color":null!==(c=i.borderColor)&&void 0!==c?c:O,"line-opacity":null!==(l=i.borderOpacity)&&void 0!==l?l:.5,"line-width":null!==(a=i.borderWidth)&&void 0!==a?a:4,"line-offset":null!==(d=i.borderOffset)&&void 0!==d?d:(null!==(u=i.borderWidth)&&void 0!==u?u:4)/2*-1}});return{sourceId:f,outlineLayerId:g,fillLayerId:h,show:()=>{o.setLayoutProperty(h,"visibility","visible"),o.setLayoutProperty(g,"visibility","visible")},hide:()=>{o.setLayoutProperty(h,"visibility","none"),o.setLayoutProperty(g,"visibility","none")},isVisible:()=>"visible"===o.getLayoutProperty(h,"visibility"),setData:e=>{o.getSource(f).setData(e)}}}var ie=function(e,t,o,i){return new(o||(o=Promise))((function(n,r){function s(e){try{l(i.next(e))}catch(e){r(e)}}function c(e){try{l(i.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,c)}l((i=i.apply(e,t||[])).next())}))};function ne(e,t){let o,i,n,r,s,c,l,a,u,f,p,h,g,m;function y(t){f=x("div","geofence-ctrl-create-circle-mode-container",t);x("div","geofence-ctrl-create-circle-mode-title",f).innerHTML="Radius",m=x("input","geofence-ctrl-create-circle-mode-input",f),m.addEventListener("keydown",d.debounce(e.updateInputRadius,200))}function b(t){p=x("div","geofence-ctrl-create-polygon-mode-container",t);const o=x("div","geofence-ctrl-create-polygon-mode-info-container",p),i=x("div","geofence-ctrl-create-polygon-mode-icon",o);x("div","geofence-ctrl-create-polygon-mode-info-icon",i).innerHTML="i";x("div","geofence-ctrl-create-polygon-mode-title",o).innerHTML="How it works?";const n=x("div","geofence-ctrl-create-polygon-mode-reset-button geofence-ctrl-button",p);n.innerHTML="Reset",n.addEventListener("click",(()=>{e.resetGeofence()}));const r=function(e){const t=x("div","geofence-ctrl-create-polygon-mode-popup-container",e),o=x("div","geofence-ctrl-create-polygon-mode-popup",t);return v(o,"Move dots to desired position",function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 38 38"),e.setAttribute("width","38"),e.setAttribute("height","38"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","circle");t.setAttribute("cx","19"),t.setAttribute("cy","18"),t.setAttribute("r","8"),t.setAttribute("fill","#FF9900");const o=document.createElementNS("http://www.w3.org/2000/svg","path");o.setAttribute("d","M19 0L23.3302 7.5H14.6699L19 0Z"),o.setAttribute("fill","#003560");const i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("d","M19 36.5L14.6698 29H23.3301L19 36.5Z"),i.setAttribute("fill","#003560");const n=document.createElementNS("http://www.w3.org/2000/svg","path");n.setAttribute("d","M0 18.33L7.5 13.9999L7.5 22.6602L0 18.33Z"),n.setAttribute("fill","#003560");const r=document.createElementNS("http://www.w3.org/2000/svg","path");return r.setAttribute("d","M37.5 18.3301L30 22.6603V14L37.5 18.3301Z"),r.setAttribute("fill","#003560"),e.appendChild(t),e.appendChild(o),e.appendChild(i),e.appendChild(n),e.appendChild(r),e}()),v(o,"Click on a border to create a dot",function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 42 27"),e.setAttribute("width","42"),e.setAttribute("height","27"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","line");t.setAttribute("y1","8"),t.setAttribute("x2","42"),t.setAttribute("y2","8"),t.setAttribute("stroke","black"),t.setAttribute("stroke-width","2");const o=document.createElementNS("http://www.w3.org/2000/svg","circle");o.setAttribute("cx","21"),o.setAttribute("cy","8"),o.setAttribute("r","8"),o.setAttribute("fill","#FF9900");const i=document.createElementNS("http://www.w3.org/2000/svg","path");return i.setAttribute("d","M21 6.17822V22.488L24.6951 19.4356L27.172 26.1782L29.0399 25.3582L26.6035 18.57L31.4762 17.9322L21 6.17822Z"),i.setAttribute("fill","#003560"),e.appendChild(t),e.appendChild(o),e.appendChild(i),e}()),v(o,"Click into shape to move",function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 32 32"),e.setAttribute("width","32"),e.setAttribute("height","32"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","rect");t.setAttribute("y","1"),t.setAttribute("x","1"),t.setAttribute("width","30"),t.setAttribute("height","30"),t.setAttribute("fill","#2196F3"),t.setAttribute("fill-opacity","0.4"),t.setAttribute("stroke","#003560"),t.setAttribute("stroke-width","2");const o=document.createElementNS("http://www.w3.org/2000/svg","path");return o.setAttribute("d","M11 6V22.3098L14.6951 19.2574L17.172 26L19.0399 25.18L16.6035 18.3918L21.4762 17.754L11 6Z"),o.setAttribute("fill","#003560"),e.appendChild(t),e.appendChild(o),e}()),v(o,"Press delete to remove a dot",function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 64 20"),e.setAttribute("width","64"),e.setAttribute("height","20"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","rect");t.setAttribute("y","0.5"),t.setAttribute("x","0.5"),t.setAttribute("width","63"),t.setAttribute("height","19"),t.setAttribute("rx","3.5"),t.setAttribute("stroke","#014478");const o=document.createElementNS("http://www.w3.org/2000/svg","path");return o.setAttribute("d","M14.4148 15C17.517 15 19.3118 13.076 19.3118 9.89418C19.3118 6.72727 17.517 4.81818 14.5192 4.81818H11.1186V15H14.4148ZM12.6548 13.6577V6.16051H14.4247C16.652 6.16051 17.8004 7.4929 17.8004 9.89418C17.8004 12.3054 16.652 13.6577 14.3303 13.6577H12.6548ZM24.394 15.1541C26.0595 15.1541 27.2377 14.3338 27.5758 13.0909L26.1689 12.8374C25.9004 13.5582 25.2541 13.9261 24.4089 13.9261C23.1362 13.9261 22.2811 13.1009 22.2413 11.6293H27.6703V11.1023C27.6703 8.34304 26.0197 7.2642 24.2896 7.2642C22.1618 7.2642 20.7598 8.88494 20.7598 11.2315C20.7598 13.603 22.1419 15.1541 24.394 15.1541ZM22.2463 10.5156C22.3059 9.43182 23.0914 8.49219 24.2995 8.49219C25.4529 8.49219 26.2086 9.3473 26.2136 10.5156H22.2463ZM30.8061 4.81818H29.3196V15H30.8061V4.81818ZM36.0971 15.1541C37.7626 15.1541 38.9409 14.3338 39.2789 13.0909L37.872 12.8374C37.6035 13.5582 36.9572 13.9261 36.112 13.9261C34.8393 13.9261 33.9842 13.1009 33.9444 11.6293H39.3734V11.1023C39.3734 8.34304 37.7228 7.2642 35.9927 7.2642C33.8649 7.2642 32.4629 8.88494 32.4629 11.2315C32.4629 13.603 33.845 15.1541 36.0971 15.1541ZM33.9494 10.5156C34.0091 9.43182 34.7946 8.49219 36.0027 8.49219C37.1561 8.49219 37.9118 9.3473 37.9167 10.5156H33.9494ZM44.5874 7.36364H43.0213V5.53409H41.5348V7.36364H40.4162V8.55682H41.5348V13.0661C41.5298 14.4531 42.5888 15.1243 43.7621 15.0994C44.2344 15.0945 44.5526 15.005 44.7266 14.9403L44.4581 13.7124C44.3587 13.7322 44.1747 13.777 43.9361 13.777C43.4538 13.777 43.0213 13.6179 43.0213 12.7578V8.55682H44.5874V7.36364ZM49.4409 15.1541C51.1064 15.1541 52.2846 14.3338 52.6227 13.0909L51.2157 12.8374C50.9473 13.5582 50.301 13.9261 49.4558 13.9261C48.1831 13.9261 47.3279 13.1009 47.2882 11.6293H52.7172V11.1023C52.7172 8.34304 51.0666 7.2642 49.3365 7.2642C47.2086 7.2642 45.8066 8.88494 45.8066 11.2315C45.8066 13.603 47.1887 15.1541 49.4409 15.1541ZM47.2931 10.5156C47.3528 9.43182 48.1383 8.49219 49.3464 8.49219C50.4998 8.49219 51.2555 9.3473 51.2605 10.5156H47.2931Z"),o.setAttribute("fill","black"),e.appendChild(t),e.appendChild(o),e}()),o}(i);o.addEventListener("click",(()=>{r.classList.toggle("show")}))}function v(e,t,o){const i=x("div","geofence-ctrl-create-polygon-mode-popup-step",e);x("div","geofence-ctrl-create-polygon-mode-popup-step-image",i).appendChild(o);x("div","geofence-ctrl-create-polygon-mode-popup-step-text",i).innerHTML=t}function w(){I(o),G(),u.style.display="flex"}function G(){g&&(I(g),g=void 0)}return{registerControlPosition:function(e,t){if(e._controlPositions[t])return;const o=document.createElement("div");o.className=`maplibregl-ctrl-${t}`,e._controlContainer.appendChild(o),e._controlPositions[t]=o},createElement:x,removeElement:I,createGeofenceCreateContainer:function(o){const i=x("div","geofence-ctrl-create-prompt-container",t);if(c=x("div","geofence-ctrl-create-prompt",i),o){const t=x("div","geofence-ctrl-create-prompt-buttons",c),o=x("div","geofence-ctrl-create-prompt-button-circle geofence-ctrl-create-prompt-button",t);o.addEventListener("click",(()=>{o.classList.add("geofence-ctrl-create-prompt-selected"),i.classList.remove("geofence-ctrl-create-prompt-selected"),p&&(I(p),p=void 0),f||y(c),e.changeMode("draw_circle")})),o.innerHTML="Circle";const i=x("div","geofence-ctrl-create-prompt-button-polygon geofence-ctrl-create-prompt-button",t);i.addEventListener("click",(()=>{e.changeMode("draw_polygon"),i.classList.add("geofence-ctrl-create-prompt-selected"),o.classList.remove("geofence-ctrl-create-prompt-selected"),f&&(I(f),f=void 0),p||b(c)})),i.innerHTML="Custom",o.classList.add("geofence-ctrl-create-prompt-selected"),y(c)}else b(c)},createGeofenceListContainer:function(){const i=x("div","geofence-ctrl-list-container",t);!function(t){const i=x("div","geofence-ctrl-list-header",t);l=x("div","geofence-ctrl-list-header-title",i),l.innerHTML="Geofences (0)",a=x("div","geofence-ctrl-list-header-checkbox-create-container",i),function(t){u=x("div","geofence-ctrl-list-checkbox-all-container",t),r=x("input","geofence-ctrl-list-checkbox-all",u),r.type="checkbox",r.addEventListener("click",(function(){r.checked?(e.displayAllGeofences(),i.innerHTML="Deselect All"):(e.hideAllGeofences(),i.innerHTML="Select All")}));const i=x("div","geofence-ctrl-list-checkbox-all-title",u);i.innerHTML="Select all",n=x("div","geofence-ctrl-list-header-add-button",u),n.innerHTML="+ Add",n.addEventListener("click",(()=>{!function(){u.style.display="none",o=x("div","geofence-ctrl-add-geofence-container",a);const t=x("div","geofence-ctrl-add-geofence",o),i=x("input","geofence-ctrl-add-geofence-input",t);i.placeholder="Enter name";const n=x("div","geofence-ctrl-add-geofence-buttons",t),r=x("div","geofence-ctrl-add-geofence-cancel-button geofence-ctrl-button ",n);r.innerHTML="Cancel",r.addEventListener("click",(()=>{w(),e.setEditingModeEnabled(!1)}));const s=x("div","geofence-ctrl-button geofence-ctrl-save-button",n);s.innerHTML="Save",s.addEventListener("click",(function(){return ie(this,void 0,void 0,(function*(){G();(yield e.createGeofence(escape(i.value)))&&w()}))})),e.addEditableGeofence()}()}))}(a)}(i),s=x("div","geofence-ctrl-list",i),s.addEventListener("scroll",(()=>{const{scrollHeight:t,scrollTop:o,clientHeight:i}=s;o+i>=t-20&&e.loadMoreGeofences()}))},removeAddGeofenceContainer:w,createAddGeofencePromptError:function(e){if(g)return;g=x("div","geofence-ctrl-add-geofence-error",o),x("div","geofence-ctrl-add-geofence-error-icon",g).appendChild(function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 12 10"),e.setAttribute("width","12"),e.setAttribute("height","10"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d","M0 10H11.5789L5.78947 0L0 10ZM6.31579 8.42105H5.26316V7.36842H6.31579V8.42105ZM6.31579 6.31579H5.26316V4.21053H6.31579V6.31579Z"),t.setAttribute("fill","#FF5050"),e.appendChild(t),e}()),x("div","geofence-ctrl-add-geofence-error-text",g).innerHTML=e},renderListItem:function(o){const n=x("li","geofence-ctrl-list-item-container",s);n.id=`list-item-${o.geofenceId}`;const r=x("li","geofence-ctrl-list-item",n),c=x("div","geofence-ctrl-list-item-left-container",r),l=x("input","geofence-ctrl-list-item-checkbox",c);l.id=`list-item-checkbox-${o.geofenceId}`,l.type="checkbox",l.addEventListener("click",(function(){l.checked?(e.displayGeofence(o.geofenceId),e.fitGeofence(o.geofenceId)):e.hideGeofence(o.geofenceId)}));const a=x("div","geofence-ctrl-list-item-right-container",r),d=x("div","geofence-ctrl-list-item-title-container",a);d.addEventListener("mouseover",(function(){e.displayHighlightedGeofence(o.geofenceId)})),d.addEventListener("mouseout",(function(){e.hideHighlightedGeofence()})),x("div","geofence-ctrl-list-item-title",d).innerHTML=M(o.geofenceId);const u=x("div","geofence-ctrl-edit-button",d);u.addEventListener("click",(function(){e.editGeofence(o.geofenceId),function(o,n,r,s){const c=x("div","geofence-ctrl-list-item-controls",n),l=function(o,n){const r=x("div","geofence-ctrl-delete-button",o);return r.classList.add("geofence-ctrl-button"),r.addEventListener("click",(function(){!function(o){i=x("div","geofence-ctrl-delete-prompt-container",t);const n=x("div","geofence-ctrl-delete-prompt",i);x("div","geofence-ctrl-delete-geofence-title",n).innerHTML=`Are you sure you want to delete <strong>${M(o)}</strong>?`,function(o,n){const r=x("div","geofence-ctrl-delete-geofence-buttons",o),s=x("div","geofence-ctrl-delete-geofence-cancel-button",r);s.innerHTML="Cancel",s.addEventListener("click",(()=>{I(i)}));const c=x("div","geofence-ctrl-delete-geofence-confirm-button",r);c.innerHTML="Delete",c.addEventListener("click",(function(){return ie(this,void 0,void 0,(function*(){(yield e.deleteGeofence(n))&&(!function(e){h=x("div","geofence-ctrl-delete-popdown-container",t);const o=x("div","geofence-ctrl-delete-popdown",h),i=x("div","geofence-ctrl-delete-popdown-close-button",h);i.appendChild(function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 12 12"),e.setAttribute("width","12"),e.setAttribute("height","12"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d","M10.773 2.28762L9.71231 1.22696L6 4.93927L2.28769 1.22696L1.22703 2.28762L4.93934 5.99993L1.22703 9.71224L2.28769 10.7729L6 7.06059L9.71231 10.7729L10.773 9.71224L7.06066 5.99993L10.773 2.28762Z"),t.setAttribute("fill","white"),t.setAttribute("fill-rule","evenodd"),t.setAttribute("clip-rule","evenodd"),e.appendChild(t),e}()),i.addEventListener("click",(()=>{I(h)}));x("div","geofence-ctrl-delete-popdown-icon",o).appendChild(function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 12 12"),e.setAttribute("width","12"),e.setAttribute("height","12"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d","M6 0C2.688 0 0 2.688 0 6C0 9.312 2.688 12 6 12C9.312 12 12 9.312 12 6C12 2.688 9.312 0 6 0ZM6 10.8C3.354 10.8 1.2 8.646 1.2 6C1.2 3.354 3.354 1.2 6 1.2C8.646 1.2 10.8 3.354 10.8 6C10.8 8.646 8.646 10.8 6 10.8ZM8.754 3.348L4.8 7.302L3.246 5.754L2.4 6.6L4.8 9L9.6 4.2L8.754 3.348Z"),t.setAttribute("fill","white"),e.appendChild(t),e}());x("div","geofence-ctrl-delete-popdown-text",o).innerHTML=e?"Geofence was deleted successfully":"Geofence failed to delete"}(!0),I(i),e.setEditingModeEnabled(!1))}))}))}(n,o)}(n)})),r.appendChild(function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg"),t=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("viewBox","0 0 12 16"),e.setAttribute("width","12"),e.setAttribute("height","16"),e.setAttribute("fill","none"),t.setAttribute("d","M9.33317 5.5V13.8333H2.6665V5.5H9.33317ZM8.08317 0.5H3.9165L3.08317 1.33333H0.166504V3H11.8332V1.33333H8.9165L8.08317 0.5ZM10.9998 3.83333H0.999837V13.8333C0.999837 14.75 1.74984 15.5 2.6665 15.5H9.33317C10.2498 15.5 10.9998 14.75 10.9998 13.8333V3.83333Z"),t.setAttribute("fill","white"),e.appendChild(t),e}()),r}(r,s),a=()=>{o.classList.remove("geofence-ctrl-list-selected-item"),o.classList.add("geofence-ctrl-list-item"),I(c),I(l)},d=x("div","geofence-ctrl-cancel-button",c);d.classList.add("geofence-ctrl-button"),d.innerHTML="Cancel",d.addEventListener("click",(()=>{e.setEditingModeEnabled(!1),a()}));const u=x("div","geofence-ctrl-save-button geofence-ctrl-button",c);u.addEventListener("click",(()=>ie(this,void 0,void 0,(function*(){yield e.saveGeofence(),a()})))),u.title="Save",u.innerHTML="Save"}(r,a,c,o.geofenceId),r.classList.remove("geofence-ctrl-list-item"),r.classList.add("geofence-ctrl-list-selected-item")})),u.appendChild(function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg"),t=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("viewBox","0 0 16 16"),e.setAttribute("width","16"),e.setAttribute("height","16"),e.setAttribute("fill","none"),t.setAttribute("d","M0.5 12.375V15.5H3.625L12.8417 6.28333L9.71667 3.15833L0.5 12.375ZM2.93333 13.8333H2.16667V13.0667L9.71667 5.51667L10.4833 6.28333L2.93333 13.8333ZM15.2583 2.69167L13.3083 0.741667C13.1417 0.575 12.9333 0.5 12.7167 0.5C12.5 0.5 12.2917 0.583333 12.1333 0.741667L10.6083 2.26667L13.7333 5.39167L15.2583 3.86667C15.5833 3.54167 15.5833 3.01667 15.2583 2.69167Z"),t.setAttribute("fill","white"),e.appendChild(t),e}())},updateCheckbox:function(e,t){const o=document.getElementById(`list-item-checkbox-${e}`);o&&(o.checked=t)},removeGeofenceListItem:function(e){I(document.getElementById(`list-item-${e}`))},setGeofenceListEnabled:function(e){r.disabled=!e,e?n.classList.remove("geofence-ctrl-noHover"):n.classList.add("geofence-ctrl-noHover");const t=document.getElementsByClassName("geofence-ctrl-list-item-checkbox");for(let o=0;o<t.length;o++)t.item(o).disabled=!e;const o=document.getElementsByClassName("geofence-ctrl-list-item-container");for(let t=0;t<o.length;t++)e?o.item(t).classList.remove("geofence-ctrl-noHover"):o.item(t).classList.add("geofence-ctrl-noHover")},getCheckboxAllValue:function(){return r.checked},removeGeofenceCreateContainer:function(){I(c),c=void 0,f=void 0,p=void 0},updateGeofenceCount:function(e){l.innerHTML=`Geofences (${e})`},updateGeofenceRadius:function(e){m&&(m.value=`${e}`)}}}class re{constructor(e,t){this._mapBoxDraw=new v.default({displayControlsDefault:!1,defaultMode:"simple_select",userProperties:!0,controls:{trash:!0},modes:Object.assign(Object.assign({},v.default.modes),{draw_circle:f.CircleMode,direct_select:f.DirectMode,simple_select:f.SimpleSelectMode}),styles:[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"],["!=","mode","static"]],paint:{"fill-color":R,"fill-outline-color":R,"fill-opacity":.3}},{id:"gl-draw-polygon-midpoint",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"]],paint:{"circle-radius":5,"circle-color":D}},{id:"gl-draw-polygon-stroke-active",type:"line",filter:["all",["==","$type","Polygon"],["!=","mode","static"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":N,"line-width":4}},{id:"gl-draw-polygon-and-line-vertex-active",type:"circle",filter:["all",["==","meta","vertex"],["==","$type","Point"],["!=","mode","static"]],paint:{"circle-radius":8,"circle-color":D,"circle-stroke-color":N,"circle-stroke-width":1}}]}),this._map=e,this._ui=t,this.enable=this.enable.bind(this),this.disable=this.disable.bind(this),this.drawPolygonGeofence=this.drawPolygonGeofence.bind(this)}get(e){return this._mapBoxDraw.get(e)}add(e){const t=e.properties.isCircle;this.enable(t),this._mapBoxDraw.add(e),this._mapBoxDraw.changeMode("direct_select",{featureId:e.id})}delete(e){this._mapBoxDraw.delete(e)}disable(){this._map.hasControl(this._mapBoxDraw)&&this._map.removeControl(this._mapBoxDraw),this._ui.removeGeofenceCreateContainer()}enable(e){this._map.hasControl(this._mapBoxDraw)||(this._map.addControl(this._mapBoxDraw,"bottom-right"),this._ui.createGeofenceCreateContainer(e))}drawPolygonGeofence(e){const t=((e,t)=>{const o=t.getSouthWest().toArray(),i=t.getNorthEast().toArray(),n=t.getCenter().toArray(),r=a.lineString([o,n,i]),s=b.default(r,{units:"miles"}),c=m.default(r,s/4,{units:"miles"}).geometry.coordinates,l=m.default(r,s*(3/4),{units:"miles"}).geometry.coordinates;return{id:e,type:"Feature",geometry:{type:"Polygon",coordinates:[[l,[c[0],l[1]],c,[l[0],c[1]],l]]},properties:{}}})(e,this._map.getBounds());this.add(t)}drawCircularGeofence(e,t){const o=this._map.getBounds(),i=X(e,this._map.getCenter().toArray(),{bounds:o,radius:t});this.add(i),this._ui.updateGeofenceRadius(t||i.properties.radius.toFixed(2))}}var se=function(e,t,o,i){return new(o||(o=Promise))((function(n,r){function s(e){try{l(i.next(e))}catch(e){r(e)}}function c(e){try{l(i.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,c)}l((i=i.apply(e,t||[])).next())}))};const ce={left:240};e.AmplifyGeocoderAPI=K,e.AmplifyGeofenceControl=class{constructor(e){this._geofenceCollectionId=null==e?void 0:e.geofenceCollectionId,this._loadedGeofences={},this._displayedGeofences=[],this.changeMode=this.changeMode.bind(this),this.loadInitialGeofences=this.loadInitialGeofences.bind(this),this.loadMoreGeofences=this.loadMoreGeofences.bind(this),this._loadGeofence=this._loadGeofence.bind(this),this.updateInputRadius=this.updateInputRadius.bind(this),this.saveGeofence=this.saveGeofence.bind(this),this.editGeofence=this.editGeofence.bind(this),this.deleteGeofence=this.deleteGeofence.bind(this),this.displayAllGeofences=this.displayAllGeofences.bind(this),this.hideAllGeofences=this.hideAllGeofences.bind(this),this.addEditableGeofence=this.addEditableGeofence.bind(this),this.setEditingModeEnabled=this.setEditingModeEnabled.bind(this),this.displayHighlightedGeofence=this.displayHighlightedGeofence.bind(this),this.hideHighlightedGeofence=this.hideHighlightedGeofence.bind(this),this.displayGeofence=this.displayGeofence.bind(this),this.hideGeofence=this.hideGeofence.bind(this),this.fitGeofence=this.fitGeofence.bind(this),this.fitAllGeofences=this.fitAllGeofences.bind(this)}getDefaultPosition(){return"full-screen"}onRemove(){this._ui.removeElement(this._container)}reorderMapLibreClassNames(){const e=document.getElementsByClassName("maplibregl-canvas").item(0);e&&(e.className="mapboxgl-canvas maplibregl-canvas")}onAdd(e){return this._map=e,this.reorderMapLibreClassNames(),this._container=x("div","geofence-ctrl maplibregl-ctrl"),this._ui=ne(this,this._container),this._amplifyDraw=new re(e,this._ui),this._ui.registerControlPosition(e,"full-screen"),this._ui.createGeofenceListContainer(),this._map.once("load",function(){this._map.getSource("displayedGeofences")||(this._drawGeofencesOutput=oe("displayedGeofences",[],this._map,{fillColor:R,borderColor:N,borderOpacity:1}),this._highlightedGeofenceOutput=oe("highlightedGeofence",[],this._map,{fillColor:R,borderColor:N,borderOpacity:1,borderWidth:6}),this.loadInitialGeofences(),e.addControl(new h.default.NavigationControl({showCompass:!1}),"bottom-right"))}.bind(this)),this._map.on("draw.update",(()=>{const e=this._amplifyDraw._mapBoxDraw.getAll().features[0].geometry.coordinates[0],t=((e,t)=>{const o=a.lineString([e,t]);return b.default(o,{units:"miles"})})(e[0],e[Math.floor(e.length/2)])/2;this._ui.updateGeofenceRadius(t.toFixed(2))})),this._container}createGeofence(e){return se(this,void 0,void 0,(function*(){if(e&&0!==e.length)if(e.match(Y)){if(!te(e,this._loadedGeofences))return this.saveGeofence(e);this._ui.createAddGeofencePromptError("Geofence ID already exists.")}else this._ui.createAddGeofencePromptError("Geofence ID contains special characters.");else this._ui.createAddGeofencePromptError("Geofence ID is empty.")}))}saveGeofence(e){return se(this,void 0,void 0,(function*(){const t=this._amplifyDraw.get(this._editingGeofenceId),o=e||this._editingGeofenceId,n=yield i.Geo.saveGeofences({geofenceId:o,geometry:{polygon:t.geometry.coordinates}});if(n.errors[0]){const e=n.errors[0];throw new Error(`There was an error saving geofence with id ${o}: ${e.error.code} - ${e.error.message}`)}const r={geofenceId:n.successes[0].geofenceId,geometry:{polygon:t.geometry.coordinates}};return this._loadGeofence(r),this.displayGeofence(r.geofenceId),this.setEditingModeEnabled(!1),r.geofenceId}))}loadInitialGeofences(){return se(this,void 0,void 0,(function*(){try{const{entries:e,nextToken:t}=yield i.Geo.listGeofences();this._listGeofencesNextToken=t;const o=this._loadGeofence;e.forEach((e=>o(e))),this._ui.updateGeofenceCount(Object.keys(this._loadedGeofences).length)}catch(e){throw new Error(`Error calling listGeofences: ${e}`)}}))}loadMoreGeofences(){return se(this,void 0,void 0,(function*(){if(this._listGeofencesNextToken)try{const{entries:e,nextToken:t}=yield i.Geo.listGeofences({nextToken:this._listGeofencesNextToken});this._listGeofencesNextToken=t;const o=this._loadGeofence;e.forEach((e=>o(e))),this._ui.updateGeofenceCount(Object.keys(this._loadedGeofences).length)}catch(e){throw new Error(`Error calling listGeofences: ${e}`)}}))}editGeofence(e){this.setEditingModeEnabled(!0);const t=this._loadedGeofences[e];if(!t)throw new Error(`Geofence with id ${e} does not exist`);const o=Q(t.geometry.polygon),i=Object.assign({id:t.geofenceId},o);this._amplifyDraw.add(i),this._editingGeofenceId=t.geofenceId}deleteGeofence(e){return se(this,void 0,void 0,(function*(){const t=yield i.Geo.deleteGeofences(e);if(t.errors[0]){const o=t.errors[0].error;throw new Error(`There was an error deleting geofence with id ${e}: ${o.code} - ${o.message}`)}return this._ui.removeGeofenceListItem(e),delete this._loadedGeofences[e],this._ui.updateGeofenceCount(Object.keys(this._loadedGeofences).length),this._displayedGeofences=this._displayedGeofences.filter((t=>t.geofenceId!==e)),this._updateDisplayedGeofences(),e}))}deleteSelectedGeofences(){this._displayedGeofences.map((e=>e.geofenceId)).forEach((e=>{this._ui.removeGeofenceListItem(e),delete this._loadedGeofences[e]})),this._displayedGeofences=[],this._updateDisplayedGeofences()}_loadGeofence(e){this._loadedGeofences[e.geofenceId]?this._displayedGeofences=this._displayedGeofences.filter((t=>t.geofenceId!==e.geofenceId)):this._ui.renderListItem(e),this._loadedGeofences[e.geofenceId]=e,this._ui.updateGeofenceCount(Object.keys(this._loadedGeofences).length)}displayGeofence(e){this._displayedGeofences.push(this._loadedGeofences[e]),this._updateDisplayedGeofences(),this._ui.updateCheckbox(e,!0),this.fitAllGeofences()}displayAllGeofences(){this._displayedGeofences.push(...Object.values(this._loadedGeofences)),this._updateDisplayedGeofences();const e=document.getElementsByClassName("geofence-ctrl-list-item-checkbox");Array.from(e).forEach((e=>e.checked=this._ui.getCheckboxAllValue())),this.fitAllGeofences()}fitGeofence(e){const t=this._map.getBounds();this._loadedGeofences[e].geometry.polygon[0].forEach((e=>{t.extend(e)})),this._map.fitBounds(t,{padding:ce})}fitAllGeofences(){let e=!1;const t=this._map.getBounds();this._displayedGeofences.forEach((o=>{o.geometry.polygon[0].forEach((o=>{t.contains(o)||(t.extend(o),e=!0)}))})),e&&this._map.fitBounds(t,{padding:ce})}hideGeofence(e){this._displayedGeofences=this._displayedGeofences.filter((t=>t.geofenceId!==e)),this._updateDisplayedGeofences(),this._ui.updateCheckbox(e,!1)}hideAllGeofences(){this._displayedGeofences=[],this._updateDisplayedGeofences();const e=document.getElementsByClassName("geofence-ctrl-list-item-checkbox");Array.from(e).forEach((e=>e.checked=this._ui.getCheckboxAllValue()))}_updateDisplayedGeofences(){const e=J(this._displayedGeofences);this._drawGeofencesOutput.setData(e)}displayHighlightedGeofence(e){const t=this._loadedGeofences[e];if(!t)return void console.warn(`Geofence with id ${e} does not exist`);const o=Q(t.geometry.polygon);this._highlightedGeofenceOutput.setData(o),this._highlightedGeofenceOutput.show()}hideHighlightedGeofence(){this._highlightedGeofenceOutput.hide()}changeMode(e){this._amplifyDraw.delete(this._editingGeofenceId),"draw_circle"===e?this._amplifyDraw.drawCircularGeofence(this._editingGeofenceId):this._amplifyDraw.drawPolygonGeofence(this._editingGeofenceId)}resetGeofence(){this._amplifyDraw.delete(this._editingGeofenceId),te(this._editingGeofenceId,this._loadedGeofences)?this.editGeofence(this._editingGeofenceId):this._amplifyDraw.drawPolygonGeofence(this._editingGeofenceId)}setEditingModeEnabled(e){e?this._amplifyDraw.enable():this._amplifyDraw.disable(),e?this._drawGeofencesOutput.hide():this._drawGeofencesOutput.show(),this._ui.setGeofenceListEnabled(!e)}updateInputRadius(e){const t=e.target.value,o=parseInt(t);isNaN(o)||this._amplifyDraw.drawCircularGeofence(this._editingGeofenceId,o)}addEditableGeofence(){this._editingGeofenceId="tempGeofence",this._amplifyDraw.drawCircularGeofence("tempGeofence"),this.setEditingModeEnabled(!0)}},e.AmplifyMapLibreRequest=H,e.createAmplifyGeocoder=function(e){return new g.default(K,Object.assign({maplibregl:h.default,showResultMarkers:{element:W()},marker:{element:W()},showResultsWhileTyping:null==e?void 0:e.autocomplete},e))},e.createDefaultIcon=W,e.createMap=e=>k(void 0,void 0,void 0,(function*(){return H.createMapLibreMap(e)})),e.drawGeofences=oe,e.drawPoints=function(e,t,o,{showCluster:n=!0,clusterOptions:r={},unclusteredOptions:s={},autoFit:c=!0}={},l){var a,d;if(!o||"function"!=typeof o.addSource||"function"!=typeof o.addLayer)throw new Error("Please use a maplibre map");const u=E(t),f=e;let p,h;o.addSource(f,{type:"geojson",data:{type:"FeatureCollection",features:u},cluster:n,clusterMaxZoom:null!==(a=r.clusterMaxZoom)&&void 0!==a?a:14,clusterRadius:null!==(d=r.smCircleSize)&&void 0!==d?d:60,generateId:!0}),n&&({clusterLayerId:p,clusterSymbolLayerId:h}=function(e,t,{fillColor:o="#5d8aff",smCircleSize:n=60,smThreshold:r=50,mdCircleSize:s=100,mdThreshold:c=100,lgCircleSize:l=140,lgThreshold:a=500,xlCircleSize:d=180,borderWidth:u=4,borderColor:f="#fff",clusterPaint:p,onClick:h,showCount:g,clusterCountLayout:m,fontColor:y="#fff"},b){const v=`${e}-layer-clusters`,w=`${e}-layer-cluster-count`,G=Object.assign({"circle-color":["step",["get","point_count"],o,r,o,c,o,a,o],"circle-radius":["step",["get","point_count"],n,r,s,c,l,a,d],"circle-stroke-width":u,"circle-stroke-color":f},p),C={id:v,type:"circle",source:e,filter:["has","point_count"],paint:G};if(t.addLayer(Object.assign({},C)),t.on("click",v,(function(o){"function"==typeof h&&h(o);const i=t.queryRenderedFeatures(o.point,{layers:[v]}),n=i[0].properties.cluster_id,r=t.getSource(e);(function(e){return"geojson"===e.type})(r)&&r.getClusterExpansionZoom(n,(function(e,o){e||t.easeTo({center:i[0].geometry.coordinates,zoom:o})}))})),g){const o={"text-field":"{point_count_abbreviated}","text-size":24},n=b||i.Geo.getDefaultMap().style;n&&(o["text-font"]=[j[n]]);const r=Object.assign(Object.assign({},o),m),s={id:w,type:"symbol",source:e,filter:["has","point_count"],layout:r,paint:{"text-color":y}};t.addLayer(Object.assign({},s))}return{clusterLayerId:v,clusterSymbolLayerId:w}}(f,o,r,l));const{unclusteredLayerId:g}=q(f,o,s||{});if(c){const e=o.getBounds();u.forEach((function(t){e.extend(t.geometry.coordinates)})),o.fitBounds(e)}return{sourceId:f,unclusteredLayerId:g,clusterLayerId:p,clusterSymbolLayerId:h,setData:e=>{const t=E(e);o.getSource(f).setData({type:"FeatureCollection",features:t})},show:()=>{o.setLayoutProperty(g,"visibility","visible"),p&&o.setLayoutProperty(p,"visibility","visible"),h&&o.setLayoutProperty(h,"visibility","visible")},hide:()=>{o.setLayoutProperty(g,"visibility","none"),p&&o.setLayoutProperty(p,"visibility","none"),h&&o.setLayoutProperty(h,"visibility","none")}}},Object.defineProperty(e,"__esModule",{value:!0})}));
@@ -201,7 +201,7 @@ function AmplifyGeofenceControlUI(geofenceControl, geofenceControlContainer) {
201
201
  geofenceControl.hideHighlightedGeofence();
202
202
  });
203
203
  const geofenceTitle = (0, utils_1.createElement)('div', 'geofence-ctrl-list-item-title', geofenceTitleContainer);
204
- geofenceTitle.innerHTML = geofence.geofenceId;
204
+ geofenceTitle.innerHTML = (0, utils_1.escapeHtml)(geofence.geofenceId);
205
205
  const editButton = (0, utils_1.createElement)('div', 'geofence-ctrl-edit-button', geofenceTitleContainer);
206
206
  editButton.addEventListener('click', function () {
207
207
  geofenceControl.editGeofence(geofence.geofenceId);
@@ -300,7 +300,7 @@ function AmplifyGeofenceControlUI(geofenceControl, geofenceControlContainer) {
300
300
  _deleteGeofenceContainer = (0, utils_1.createElement)('div', 'geofence-ctrl-delete-prompt-container', geofenceControlContainer);
301
301
  const deleteGeofencePrompt = (0, utils_1.createElement)('div', 'geofence-ctrl-delete-prompt', _deleteGeofenceContainer);
302
302
  const title = (0, utils_1.createElement)('div', 'geofence-ctrl-delete-geofence-title', deleteGeofencePrompt);
303
- title.innerHTML = `Are you sure you want to delete <strong>${geofenceId}</strong>?`;
303
+ title.innerHTML = `Are you sure you want to delete <strong>${(0, utils_1.escapeHtml)(geofenceId)}</strong>?`;
304
304
  createDeleteButtonsContainer(deleteGeofencePrompt, geofenceId);
305
305
  }
306
306
  function createDeleteButtonsContainer(container, geofenceId) {
@@ -21,8 +21,10 @@ function getPopupRenderFunction(unclusteredLayerId, { popupBackgroundColor: back
21
21
  title = 'Coordinates';
22
22
  address = selectedFeature.geometry.coordinates;
23
23
  }
24
- const titleHtml = `<div class="${unclusteredLayerId}-popup-title" style="font-weight: ${fontWeight};">${title}</div>`;
25
- const addressHtml = `<div class="${unclusteredLayerId}-popup-address">${address}</div>`;
24
+ const safeTitle = (0, utils_1.escapeHtml)(String(title));
25
+ const safeAddress = (0, utils_1.escapeHtml)(String(address));
26
+ const titleHtml = `<div class="${unclusteredLayerId}-popup-title" style="font-weight: ${fontWeight};">${safeTitle}</div>`;
27
+ const addressHtml = `<div class="${unclusteredLayerId}-popup-address">${safeAddress}</div>`;
26
28
  const popupHtmlStyle = `background: ${background}; border: ${borderWidth}px solid ${borderColor}; color: ${fontColor}; border-radius: ${radius}px; padding: ${padding}px; word-wrap: break-word; margin: -10px -10px -15px;`;
27
29
  let popupHtml = `<div class="${unclusteredLayerId}-popup" style="${popupHtmlStyle}">`;
28
30
  if (title)
@@ -16,3 +16,8 @@ export declare const urlEncodePeriods: (str: string) => string;
16
16
  export declare function validateCoordinates(coordinates: Coordinates): void;
17
17
  export declare function createElement(tagName: string, className?: string, container?: HTMLElement): HTMLElement;
18
18
  export declare function removeElement(node: HTMLElement): void;
19
+ /**
20
+ * Escapes HTML special characters to prevent XSS when interpolating
21
+ * user-controlled strings into HTML markup.
22
+ */
23
+ export declare function escapeHtml(str: string): string;
package/lib/cjs/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removeElement = exports.createElement = exports.validateCoordinates = exports.urlEncodePeriods = exports.getFeaturesFromData = exports.strHasLength = exports.isGeoJsonSource = exports.isPolygonArray = exports.isPolygon = exports.isGeofenceArray = exports.isGeofence = exports.isNamedLocationArray = exports.isNamedLocation = exports.isCoordinatesArray = exports.isCoordinates = void 0;
3
+ exports.escapeHtml = exports.removeElement = exports.createElement = exports.validateCoordinates = exports.urlEncodePeriods = exports.getFeaturesFromData = exports.strHasLength = exports.isGeoJsonSource = exports.isPolygonArray = exports.isPolygon = exports.isGeofenceArray = exports.isGeofence = exports.isNamedLocationArray = exports.isNamedLocation = exports.isCoordinatesArray = exports.isCoordinates = void 0;
4
4
  function isCoordinates(array) {
5
5
  return (Array.isArray(array) &&
6
6
  typeof array[0] === 'number' &&
@@ -110,3 +110,16 @@ function removeElement(node) {
110
110
  }
111
111
  }
112
112
  exports.removeElement = removeElement;
113
+ /**
114
+ * Escapes HTML special characters to prevent XSS when interpolating
115
+ * user-controlled strings into HTML markup.
116
+ */
117
+ function escapeHtml(str) {
118
+ return str
119
+ .replace(/&/g, '&amp;')
120
+ .replace(/</g, '&lt;')
121
+ .replace(/>/g, '&gt;')
122
+ .replace(/"/g, '&quot;')
123
+ .replace(/'/g, '&#39;');
124
+ }
125
+ exports.escapeHtml = escapeHtml;
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { debounce } from 'debounce';
11
- import { createElement, removeElement } from '../utils';
11
+ import { createElement, escapeHtml, removeElement } from '../utils';
12
12
  import { createErrorIcon } from './icons';
13
13
  import { createEditIcon, createPopupStep1Icon, createPopupStep2Icon, createPopupStep3Icon, createPopupStep4Icon, createTrashIcon, createDeleteSuccessIcon, createCloseIcon, } from './icons';
14
14
  export function AmplifyGeofenceControlUI(geofenceControl, geofenceControlContainer) {
@@ -198,7 +198,7 @@ export function AmplifyGeofenceControlUI(geofenceControl, geofenceControlContain
198
198
  geofenceControl.hideHighlightedGeofence();
199
199
  });
200
200
  const geofenceTitle = createElement('div', 'geofence-ctrl-list-item-title', geofenceTitleContainer);
201
- geofenceTitle.innerHTML = geofence.geofenceId;
201
+ geofenceTitle.innerHTML = escapeHtml(geofence.geofenceId);
202
202
  const editButton = createElement('div', 'geofence-ctrl-edit-button', geofenceTitleContainer);
203
203
  editButton.addEventListener('click', function () {
204
204
  geofenceControl.editGeofence(geofence.geofenceId);
@@ -297,7 +297,7 @@ export function AmplifyGeofenceControlUI(geofenceControl, geofenceControlContain
297
297
  _deleteGeofenceContainer = createElement('div', 'geofence-ctrl-delete-prompt-container', geofenceControlContainer);
298
298
  const deleteGeofencePrompt = createElement('div', 'geofence-ctrl-delete-prompt', _deleteGeofenceContainer);
299
299
  const title = createElement('div', 'geofence-ctrl-delete-geofence-title', deleteGeofencePrompt);
300
- title.innerHTML = `Are you sure you want to delete <strong>${geofenceId}</strong>?`;
300
+ title.innerHTML = `Are you sure you want to delete <strong>${escapeHtml(geofenceId)}</strong>?`;
301
301
  createDeleteButtonsContainer(deleteGeofencePrompt, geofenceId);
302
302
  }
303
303
  function createDeleteButtonsContainer(container, geofenceId) {
@@ -1,4 +1,4 @@
1
- import { strHasLength } from './utils';
1
+ import { escapeHtml, strHasLength } from './utils';
2
2
  import { COLOR_BLACK, COLOR_WHITE, POPUP_BORDER_COLOR } from './constants';
3
3
  export function getPopupRenderFunction(unclusteredLayerId, { popupBackgroundColor: background = COLOR_WHITE, popupBorderColor: borderColor = POPUP_BORDER_COLOR, popupBorderWidth: borderWidth = 2, popupFontColor: fontColor = COLOR_BLACK, popupPadding: padding = 20, popupBorderRadius: radius = 4, popupTitleFontWeight: fontWeight = 'bold', }) {
4
4
  return (selectedFeature) => {
@@ -18,8 +18,10 @@ export function getPopupRenderFunction(unclusteredLayerId, { popupBackgroundColo
18
18
  title = 'Coordinates';
19
19
  address = selectedFeature.geometry.coordinates;
20
20
  }
21
- const titleHtml = `<div class="${unclusteredLayerId}-popup-title" style="font-weight: ${fontWeight};">${title}</div>`;
22
- const addressHtml = `<div class="${unclusteredLayerId}-popup-address">${address}</div>`;
21
+ const safeTitle = escapeHtml(String(title));
22
+ const safeAddress = escapeHtml(String(address));
23
+ const titleHtml = `<div class="${unclusteredLayerId}-popup-title" style="font-weight: ${fontWeight};">${safeTitle}</div>`;
24
+ const addressHtml = `<div class="${unclusteredLayerId}-popup-address">${safeAddress}</div>`;
23
25
  const popupHtmlStyle = `background: ${background}; border: ${borderWidth}px solid ${borderColor}; color: ${fontColor}; border-radius: ${radius}px; padding: ${padding}px; word-wrap: break-word; margin: -10px -10px -15px;`;
24
26
  let popupHtml = `<div class="${unclusteredLayerId}-popup" style="${popupHtmlStyle}">`;
25
27
  if (title)
@@ -16,3 +16,8 @@ export declare const urlEncodePeriods: (str: string) => string;
16
16
  export declare function validateCoordinates(coordinates: Coordinates): void;
17
17
  export declare function createElement(tagName: string, className?: string, container?: HTMLElement): HTMLElement;
18
18
  export declare function removeElement(node: HTMLElement): void;
19
+ /**
20
+ * Escapes HTML special characters to prevent XSS when interpolating
21
+ * user-controlled strings into HTML markup.
22
+ */
23
+ export declare function escapeHtml(str: string): string;
package/lib/esm/utils.js CHANGED
@@ -92,3 +92,15 @@ export function removeElement(node) {
92
92
  node.parentNode.removeChild(node);
93
93
  }
94
94
  }
95
+ /**
96
+ * Escapes HTML special characters to prevent XSS when interpolating
97
+ * user-controlled strings into HTML markup.
98
+ */
99
+ export function escapeHtml(str) {
100
+ return str
101
+ .replace(/&/g, '&amp;')
102
+ .replace(/</g, '&lt;')
103
+ .replace(/>/g, '&gt;')
104
+ .replace(/"/g, '&quot;')
105
+ .replace(/'/g, '&#39;');
106
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maplibre-gl-js-amplify",
3
- "version": "4.0.2",
3
+ "version": "4.0.3",
4
4
  "description": "MapLibre Plugin to Support Amplify Geo Integration",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./lib/esm/index.js",
@@ -114,6 +114,7 @@
114
114
  "resolutions": {
115
115
  "**/fast-xml-parser": "4.4.1",
116
116
  "cross-spawn": "7.0.5",
117
+ "form-data": "^3.0.5",
117
118
  "json5": "^2.2.2",
118
119
  "optionator": "^0.9.3"
119
120
  },