UNPKG

@geoapify/route-planner-sdk

Version:

TypeScript SDK for the Geoapify Route Planner API. Supports route optimization, delivery planning, and timeline visualization in browser and Node.js

2 lines 293 kB
"use strict";function t(t,e,i,n){return new(i||(i=Promise))((function(s,o){function r(t){try{d(n.next(t))}catch(t){o(t)}}function a(t){try{d(n.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(r,a)}d((n=n.apply(t,e||[])).next())}))}Object.defineProperty(exports,"__esModule",{value:!0}),"function"==typeof SuppressedError&&SuppressedError;class e{constructor(t){this.raw=t||{capabilities:[],time_windows:[],breaks:[]}}getRaw(){return this.raw}setRaw(t){return this.raw=t,this}setStartLocation(t,e){return this.raw.start_location=[t,e],this}setStartLocationIndex(t){return this.raw.start_location_index=t,this}setEndLocation(t,e){return this.raw.end_location=[t,e],this}setEndLocationIndex(t){return this.raw.end_location_index=t,this}setPickupCapacity(t){return this.raw.pickup_capacity=t,this}setDeliveryCapacity(t){return this.raw.delivery_capacity=t,this}addCapability(t){return this.raw.capabilities.push(t),this}addTimeWindow(t,e){return this.raw.time_windows.push([t,e]),this}addBreak(t){return this.raw.breaks.push(t.getRaw()),this}setId(t){return this.raw.id=t,this}setDescription(t){return this.raw.description=t,this}}class i{constructor(t){this.raw=t||{}}getRaw(){return this.raw}setRaw(t){return this.raw=t,this}setLat(t){return this.raw.lat=t,this}setLon(t){return this.raw.lon=t,this}}class n{constructor(t){this.raw=t||{values:[]}}getRaw(){return this.raw}setRaw(t){return this.raw=t,this}setType(t){return this.raw.type=t,this}addValue(t,e){let n=(new i).setLat(e).setLon(t);return this.raw.values.push(n.getRaw()),this}}class s{constructor(t){this.raw=t||{time_windows:[]}}getRaw(){return this.raw}setRaw(t){return this.raw=t,this}addTimeWindow(t,e){return this.raw.time_windows.push([t,e]),this}setDuration(t){return this.raw.duration=t,this}}class o{constructor(t){this.raw=t||{requirements:[],time_windows:[]}}getRaw(){return this.raw}setRaw(t){return this.raw=t,this}setLocation(t,e){return this.raw.location=[t,e],this}setLocationIndex(t){return this.raw.location_index=t,this}setPriority(t){return this.raw.priority=t,this}setDuration(t){return this.raw.duration=t,this}setPickupAmount(t){return this.raw.pickup_amount=t,this}setDeliveryAmount(t){return this.raw.delivery_amount=t,this}addRequirement(t){return this.raw.requirements.push(t),this}addTimeWindow(t,e){return this.raw.time_windows.push([t,e]),this}setId(t){return this.raw.id=t,this}setDescription(t){return this.raw.description=t,this}}class r{constructor(t){this.raw=t||{}}getRaw(){return this.raw}setRaw(t){return this.raw=t,this}setId(t){return this.raw.id=t,this}setLocation(t,e){return this.raw.location=[t,e],this}}class a{constructor(t){this.raw=t||{requirements:[]}}getRaw(){return this.raw}setRaw(t){return this.raw=t,this}setId(t){return this.raw.id=t,this}setPickup(t){return this.raw.pickup=t.getRaw(),this}setDelivery(t){return this.raw.delivery=t.getRaw(),this}addRequirement(t){return this.raw.requirements.push(t),this}setPriority(t){return this.raw.priority=t,this}setDescription(t){return this.raw.description=t,this}setAmount(t){return this.raw.amount=t,this}}class d{constructor(t){this.raw=t||{time_windows:[]}}getRaw(){return this.raw}setRaw(t){return this.raw=t,this}setLocation(t,e){return this.raw.location=[t,e],this}setLocationIndex(t){return this.raw.location_index=t,this}setDuration(t){return this.raw.duration=t,this}addTimeWindow(t,e){return this.raw.time_windows.push([t,e]),this}}class p{constructor(t){if(!t)throw new Error("RouteLegStepData is undefined");this.raw=t}getRaw(){return this.raw}getDistance(){return this.raw.distance}getTime(){return this.raw.time}getFromIndex(){return this.raw.from_index}getToIndex(){return this.raw.to_index}}class g{constructor(t){if(!t)throw new Error("RouteLegData is undefined");this.raw=t}getRaw(){return this.raw}getTime(){return this.raw.time}getDistance(){return this.raw.distance}getSteps(){return this.raw.steps.map((t=>new p(t)))}getFromWaypointIndex(){return this.raw.from_waypoint_index}getToWaypointIndex(){return this.raw.to_waypoint_index}}class h{constructor(t){if(!t)throw new Error("RouteActionData is undefined");this.raw=t}getRaw(){return this.raw}getType(){return this.raw.type}getStartTime(){return this.raw.start_time}getDuration(){return this.raw.duration}getShipmentIndex(){return this.raw.shipment_index}getShipmentId(){return this.raw.shipment_id}getLocationIndex(){return this.raw.location_index}getLocationId(){return this.raw.location_id}getJobIndex(){return this.raw.job_index}getJobId(){return this.raw.job_id}getIndex(){return this.raw.index}getWaypointIndex(){return this.raw.waypoint_index}}class u{constructor(t){if(!t)throw new Error("WaypointData is undefined");this.raw=t}getRaw(){return this.raw}getOriginalLocation(){return this.raw.original_location}getOriginalLocationIndex(){return this.raw.original_location_index}getOriginalLocationId(){return this.raw.original_location_id}getLocation(){return this.raw.location}getStartTime(){return this.raw.start_time}getDuration(){return this.raw.duration}getActions(){return this.raw.actions.map((t=>new h(t)))}getPrevLegIndex(){return this.raw.prev_leg_index}getNextLegIndex(){return this.raw.next_leg_index}}class l{constructor(t){if(!t)throw new Error("AgentSolutionData is undefined");this.raw=t}getRaw(){return this.raw}getAgentIndex(){return this.raw.agentIndex}getAgentId(){return this.raw.agentId}getTime(){return this.raw.time}getStartTime(){return this.raw.start_time}getEndTime(){return this.raw.end_time}getDistance(){return this.raw.distance}getMode(){return this.raw.mode}getLegs(){return this.raw.legs.map((t=>new g(t)))}getActions(){return this.raw.actions.map((t=>new h(t)))}getWaypoints(){return this.raw.waypoints.map((t=>new u(t)))}}class c{constructor(t){if(!t)throw new Error("RouteActionInfo is undefined");this.raw=t}getRaw(){return this.raw}getAgentId(){return this.raw.agentId}getActions(){return this.raw.actions}getAgent(){return this.raw.agent}}class m extends Error{constructor(t,e,i){super(e),this.errorName=t,this.message=e,this.rawResponse=i,this.name=t,this.rawResponse=i}}class w{static cleanObject(t){if(Array.isArray(t))return t.length>0?t.map(w.cleanObject):void 0;if(null!==t&&"object"==typeof t){const e=Object.entries(t).reduce(((t,[e,i])=>{const n=w.cleanObject(i);return void 0!==n&&(t[e]=n),t}),{});return Object.keys(e).length>0?e:void 0}return t}static cloneObject(t){return JSON.parse(JSON.stringify(t))}}class y{static generateRoutePlannerResultData(t){var e,i,n;let s=w.cloneObject(t);return{agents:this.generateAgents(s),inputData:s.properties.params,unassignedAgents:null===(e=s.properties.issues)||void 0===e?void 0:e.unassigned_agents,unassignedJobs:null===(i=s.properties.issues)||void 0===i?void 0:i.unassigned_jobs,unassignedShipments:null===(n=s.properties.issues)||void 0===n?void 0:n.unassigned_shipments}}static generateAgents(t){let e=[];return t.features.forEach((t=>{let i=t.properties;e.push({agentIndex:i.agent_index,agentId:i.agent_id,time:i.time,start_time:i.start_time,end_time:i.end_time,distance:i.distance,mode:i.mode,legs:this.generateRouteLegs(i.legs),actions:this.generateActions(i.actions),waypoints:this.generateWaypoints(i.waypoints)})})),e}static generateRouteLegs(t){return void 0===t?[]:t.map((t=>({time:t.time,distance:t.distance,steps:this.generateRouteLegSteps(t.steps),from_waypoint_index:t.from_waypoint_index,to_waypoint_index:t.to_waypoint_index})))}static generateRouteLegSteps(t){return t.map((t=>({distance:t.distance,time:t.distance,from_index:t.from_index,to_index:t.to_index})))}static generateActions(t){return t.map((t=>({type:t.type,start_time:t.start_time,duration:t.duration,shipment_index:t.shipment_index,shipment_id:t.shipment_id,location_index:t.location_index,location_id:t.location_id,job_index:t.job_index,job_id:t.job_id,index:t.index,waypoint_index:t.waypoint_index})))}static generateWaypoints(t){return t.map((t=>({original_location:t.original_location,original_location_index:t.original_location_index,original_location_id:t.original_location_id,location:t.location,start_time:t.start_time,duration:t.duration,actions:this.generateActions(t.actions),prev_leg_index:t.prev_leg_index,next_leg_index:t.next_leg_index})))}}class f{constructor(t){if(!t)throw new Error("JobSolutionData is undefined");this.raw=t}getRaw(){return this.raw}getAgentId(){return this.raw.agentId}getActions(){return this.raw.actions.map((t=>new h(t)))}getAgent(){return new l(this.raw.agent)}getJob(){return new o(this.raw.job)}}class v{constructor(t){if(!t)throw new Error("ShipmentSolutionData is undefined");this.raw=t}getRaw(){return this.raw}getAgentId(){return this.raw.agentId}getActions(){return this.raw.actions.map((t=>new h(t)))}getAgent(){return new l(this.raw.agent)}getShipment(){return new a(this.raw.shipment)}}class x{constructor(t,e){this.rawData=e,this.options=t}getData(){return y.generateRoutePlannerResultData(this.rawData)}getRawData(){return this.rawData}getAgentSolutions(){return this.getData().agents.map((t=>new l(t)))}getAgentSolutionsByIndex(){let t=this.getData(),e=Array(t.inputData.agents.length);return this.getData().agents.forEach((t=>{let i=new l(t);e[i.getAgentIndex()]=i})),e}getAgentSolution(t){let e=this.getData().agents.find((e=>e.agentId===t));return void 0===e?void 0:new l(e)}getAgentSolutionByIndex(t){let e=this.getData().agents.find((e=>e.agentIndex===t));return void 0===e?void 0:new l(e)}getAgentWaypoints(t){const e=this.getAgentSolution(t);return e?e.getWaypoints():[]}getAgentRouteActions(t){const e=this.getAgentSolution(t);return e?e.getActions():[]}getAgentRouteLegs(t){const e=this.getAgentSolution(t);return e?e.getLegs():[]}getOptions(){return this.options}getAgentJobs(t){const e=this.getAgentSolution(t);return void 0===e?[]:e.getActions().filter((t=>void 0!==t.getJobIndex())).map((t=>t.getJobIndex()))}getAgentShipments(t){const e=this.getAgentSolution(t);return void 0===e?[]:Array.from(new Set(e.getActions().filter((t=>void 0!==t.getShipmentIndex())).map((t=>t.getShipmentIndex())))).sort(((t,e)=>t-e))}getUnassignedAgents(){let t=this.getData();return t.unassignedAgents&&0!=t.unassignedAgents.length?t.unassignedAgents.map((e=>t.inputData.agents[e])):[]}getUnassignedJobs(){let t=this.getData();return t.unassignedJobs&&0!=t.unassignedJobs.length?t.unassignedJobs.map((e=>t.inputData.jobs[e])):[]}getUnassignedShipments(){let t=this.getData();return t.unassignedShipments&&0!=t.unassignedShipments.length?t.unassignedShipments.map((e=>t.inputData.shipments[e])):[]}getJobSolutions(){let t=[];return this.getAgentSolutions().forEach((e=>{let i=e.getActions(),n={};i.forEach((t=>{const e=t.getJobIndex();void 0!==e&&(n[e]||(n[e]=[]),n[e].push(t.getRaw()))}));for(const i in n){const s=n[+i];let o={agentId:e.getAgentId(),actions:s,agent:e.getRaw(),job:this.rawData.properties.params.jobs[s[0].job_index]};t.push(new f(o))}})),t}getJobSolution(t){for(let e of this.getJobSolutions())if(e.getJob().getRaw().id===t)return e}getShipmentSolutions(){let t=[];return this.getAgentSolutions().forEach((e=>{let i=e.getActions(),n={};i.forEach((t=>{const e=t.getShipmentIndex();void 0!==e&&(n[e]||(n[e]=[]),n[e].push(t.getRaw()))}));for(const i in n){const s=n[+i];let o={agentId:e.getAgentId(),actions:s,agent:e.getRaw(),shipment:this.rawData.properties.params.shipments[s[0].shipment_index]};t.push(new v(o))}})),t}getShipmentSolution(t){for(let e of this.getShipmentSolutions())if(e.getShipment().getRaw().id===t)return e}getJobInfo(t){if(!t)return;let e,i=[];for(const n of this.getAgentSolutions())for(const s of n.getActions())s.getJobId()===t&&(i.push(s),e=n);return 0!==i.length&&e?new c({agentId:e.getAgentId(),actions:i,agent:e}):void 0}getShipmentInfo(t){if(!t)return;let e,i=[];for(const n of this.getAgentSolutions())for(const s of n.getActions())s.getShipmentId()===t&&(i.push(s),e=n);return 0!==i.length&&e?new c({agentId:e.getAgentId(),actions:i,agent:e}):void 0}getJobInfoByIndex(t){if(t<0)return;let e,i=[];for(const n of this.getAgentSolutions())for(const s of n.getActions())s.getJobIndex()===t&&(i.push(s),e=n);return 0!==i.length&&e?new c({agentId:e.getAgentId(),actions:i,agent:e}):void 0}getShipmentInfoByIndex(t){if(t<0)return;let e,i=[];for(const n of this.getAgentSolutions())for(const s of n.getActions())s.getShipmentIndex()===t&&(i.push(s),e=n);return 0!==i.length&&e?new c({agentId:e.getAgentId(),actions:i,agent:e}):void 0}getAgentRoute(e,i){return t(this,void 0,void 0,(function*(){const t=this.getAgentSolution(e);if(!t)return;let n=t.getWaypoints().map((t=>"lonlat:"+t.getLocation())).join("|");if(0==n.length)return;const s=yield fetch(this.constructRoutingRequest(n,i));return yield s.json()}))}constructRoutingRequest(t,e){let i=`${this.getOptions().baseUrl}/v1/routing?waypoints=${t}&apiKey=${this.getOptions().apiKey}`;return e.mode&&(i+=`&mode=${e.mode}`),e.type&&(i+=`&type=${e.type}`),e.units&&(i+=`&units=${e.units}`),e.lang&&(i+=`&lang=${e.lang}`),e.avoid&&e.avoid.length>0&&(i+=`&avoid=${e.avoid.join("|")}`),e.details&&e.details.length>0&&(i+=`&details=${e.details.join(",")}`),e.traffic&&(i+=`&traffic=${e.traffic}`),e.max_speed&&(i+=`&max_speed=${e.max_speed}`),i}}var A={__proto__:null,Agent:e,AgentSolution:l,Avoid:n,Break:s,Coordinates:i,Job:o,Location:r,RouteAction:h,RouteActionInfo:c,RouteLeg:g,RouteLegStep:p,RoutePlannerError:m,RoutePlannerResult:x,Shipment:a,ShipmentStep:d,Waypoint:u};class b{constructor(t,e){this.options=t,this.options.baseUrl||(this.options.baseUrl="https://api.geoapify.com"),this.raw=e||{agents:[],jobs:[],shipments:[],locations:[],avoid:[]}}getRaw(){return this.raw}setRaw(t){return this.raw=t,this}setMode(t){return this.raw.mode=t,this}addAgent(t){return this.raw.agents.push(t.getRaw()),this}addJob(t){return this.raw.jobs.push(t.getRaw()),this}addLocation(t){return this.raw.locations.push(t.getRaw()),this}addShipment(t){return this.raw.shipments.push(t.getRaw()),this}addAvoid(t){return this.raw.avoid.push(t.getRaw()),this}setTraffic(t){return this.raw.traffic=t,this}setType(t){return this.raw.type=t,this}setMaxSpeed(t){return this.raw.max_speed=t,this}setUnits(t){return this.raw.units=t,this}plan(){return t(this,void 0,void 0,(function*(){const e=w.cleanObject(this.raw),i=yield function(e,i){return t(this,void 0,void 0,(function*(){if("undefined"!=typeof fetch)return fetch(e,i);try{const t=Function("return import('node-fetch')")();return(0,(yield t).default)(e,i)}catch(t){throw new Error("Fetch is not available in this environment. If you are using Node.js <18, install 'node-fetch' manually: npm install node-fetch")}}))}(`${this.options.baseUrl}/v1/routeplanner?apiKey=${this.options.apiKey}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!i.ok){let t=yield i.json();throw new m(t.error,t.message,t)}let n=yield i.json();return new x(this.options,n)}))}}class I{constructor(t,e,i){this.agentIndex=t,this.agentJobIndexes=new Set(e),this.agentShipmentIndexes=new Set(i)}}class _{constructor(t){this.result=t}optimizeRoute(e){return t(this,void 0,void 0,(function*(){let t=w.cloneObject(this.result.getRawData().properties.params),i={originalAgentIndex:e.agentIndex,originalJobsIndexes:{},originalShipmentsIndexes:{}};this.generateOptimizedRoute(t,e,i);const n=new b(this.result.getOptions(),t);let s=yield n.plan(),o=s.getRawData().features[0];return o&&(this.fixAgentIndex(e.agentIndex,o),this.fixShipmentJobIndexes(o,i),this.fixWaypointIndexes(o,i),this.fixUnassignedItems(s.getRawData(),i)),s}))}generateOptimizedRoute(t,e,i){var n,s,o;t.agents=null===(n=t.agents)||void 0===n?void 0:n.filter(((t,i)=>i==e.agentIndex));let r=0,a=[];null===(s=t.jobs)||void 0===s||s.forEach(((t,n)=>{e.agentJobIndexes.has(n)&&(a[r]=t,i.originalJobsIndexes[r]=n,r++)})),t.jobs=a;let d=0,p=[];null===(o=t.shipments)||void 0===o||o.forEach(((t,n)=>{e.agentShipmentIndexes.has(n)&&(p[d]=t,i.originalShipmentsIndexes[d]=n,d++)})),t.shipments=p}removeAgent(t){this.removeAgentWithIndex(t),this.addUnassignedAgentIfNeeded(t)}removeAgentWithIndex(t){this.result.getRawData().features=this.result.getRawData().features.filter((e=>e.properties.agent_index!=t))}updateAgent(t,e){t.getUnassignedAgents().length>0?(this.result.getRawData().properties.issues.unassigned_agents.includes(e)?this.updateResultWithUpdatedAgent(t,e):this.removeAgentWithIndex(e),this.updateUnassignedItems(t)):(this.result.getAgentSolutionByIndex(e)&&this.removeAgentWithIndex(e),this.updateResultWithUpdatedAgent(t,e),this.updateUnassignedItems(t))}updateResultWithUpdatedAgent(t,e){let i=t.getRawData().features[0];this.result.getRawData().features.push(i)}generateOptimizeAgentInput(t,e){if(!e)return new I(t,[],[]);let i=e.getActions().filter((t=>void 0!==t.getJobIndex())).map((t=>t.getJobIndex())),n=e.getActions().filter((t=>void 0!==t.getShipmentIndex())).map((t=>t.getShipmentIndex()));return new I(e.getAgentIndex(),i,n)}checkIfArrayIsUnique(t){return t.length===new Set(t).size}getAgentByIndex(t){return this.result.getRawData().properties.params.agents[t]}getJobByIndex(t){return this.result.getRawData().properties.params.jobs[t]}getShipmentByIndex(t){return this.result.getRawData().properties.params.shipments[t]}validateAgent(t){if(!this.getAgentByIndex(t))throw new Error(`Agent with index ${t} not found`)}updateUnassignedItems(t){this.updateUnassignedAgents(t),this.updateUnassignedJobs(t),this.updateUnassignedShipments(t)}updateUnassignedAgents(t){t.getUnassignedAgents().length>0?this.addUnassignedAgentIfNeeded(t.getRawData().properties.issues.unassigned_agents[0]):(this.addIssuesPropertiesIfMissing(),this.result.getRawData().properties.issues.unassigned_agents||(this.result.getRawData().properties.issues.unassigned_agents=[]),this.result.getRawData().properties.issues.unassigned_agents=this.result.getRawData().properties.issues.unassigned_agents.filter((e=>e!=t.getData().agents[0].agentIndex)))}updateUnassignedJobs(t){this.getUnassignedJobs(t).forEach((t=>{var e,i;(null===(i=null===(e=this.result.getRawData().properties.issues)||void 0===e?void 0:e.unassigned_jobs)||void 0===i?void 0:i.includes(t))||(this.addIssuesPropertiesIfMissing(),this.generateEmptyUnassignedJobsIfNeeded(),this.result.getRawData().properties.issues.unassigned_jobs.push(t))})),t.getRawData().features.length>0&&t.getRawData().features[0].properties.actions.filter((t=>null!=t.job_index)).map((t=>t.job_index)).forEach((t=>{var e,i;(null===(i=null===(e=this.result.getRawData().properties.issues)||void 0===e?void 0:e.unassigned_jobs)||void 0===i?void 0:i.includes(t))&&(this.addIssuesPropertiesIfMissing(),this.generateEmptyUnassignedJobsIfNeeded(),this.result.getRawData().properties.issues.unassigned_jobs=this.result.getRawData().properties.issues.unassigned_jobs.filter((e=>e!=t)))}))}updateUnassignedShipments(t){this.getUnassignedShipments(t).forEach((t=>{var e,i;(null===(i=null===(e=this.result.getRawData().properties.issues)||void 0===e?void 0:e.unassigned_shipments)||void 0===i?void 0:i.includes(t))||(this.addIssuesPropertiesIfMissing(),this.generateEmptyUnassignedShipmentsIfNeeded(),this.result.getRawData().properties.issues.unassigned_shipments.push(t))})),t.getRawData().features.length>0&&t.getRawData().features[0].properties.actions.filter((t=>null!=t.shipment_index)).map((t=>t.shipment_index)).forEach((t=>{var e,i;(null===(i=null===(e=this.result.getRawData().properties.issues)||void 0===e?void 0:e.unassigned_shipments)||void 0===i?void 0:i.includes(t))&&(this.addIssuesPropertiesIfMissing(),this.generateEmptyUnassignedShipmentsIfNeeded(),this.result.getRawData().properties.issues.unassigned_shipments=this.result.getRawData().properties.issues.unassigned_shipments.filter((e=>e!=t)))}))}getUnassignedJobs(t){return t.getRawData().properties.issues&&t.getRawData().properties.issues.unassigned_jobs?t.getRawData().properties.issues.unassigned_jobs:[]}getUnassignedShipments(t){return t.getRawData().properties.issues&&t.getRawData().properties.issues.unassigned_shipments?t.getRawData().properties.issues.unassigned_shipments:[]}addUnassignedAgentIfNeeded(t){this.result.getRawData().properties.issues.unassigned_agents.includes(t)||(this.result.getRawData().properties.issues.unassigned_agents||(this.result.getRawData().properties.issues.unassigned_agents=[]),this.result.getRawData().properties.issues.unassigned_agents.push(t))}addIssuesPropertiesIfMissing(){this.result.getRawData().properties.issues||(this.result.getRawData().properties.issues={unassigned_shipments:[],unassigned_jobs:[],unassigned_agents:[]})}fixAgentIndex(t,e){-1!=t?e.properties.agent_index=t:console.log(`Agent with index ${t} not found in the result`)}fixShipmentJobIndexes(t,e){t.properties.actions.forEach((t=>{null!=t.shipment_index&&(t.shipment_index=e.originalShipmentsIndexes[t.shipment_index]),null!=t.job_index&&(t.job_index=e.originalJobsIndexes[t.job_index])}))}fixWaypointIndexes(t,e){t.properties.waypoints.forEach((t=>{t.actions.forEach((t=>{null!=t.shipment_index&&(t.shipment_index=e.originalShipmentsIndexes[t.shipment_index]),null!=t.job_index&&(t.job_index=e.originalJobsIndexes[t.job_index])}))}))}generateEmptyUnassignedShipmentsIfNeeded(){this.result.getRawData().properties.issues?this.result.getRawData().properties.issues.unassigned_shipments||(this.result.getRawData().properties.issues.unassigned_shipments=[]):this.result.getRawData().properties.issues={unassigned_jobs:[],unassigned_agents:[],unassigned_shipments:[]}}generateEmptyUnassignedJobsIfNeeded(){this.result.getRawData().properties.issues?this.result.getRawData().properties.issues.unassigned_jobs||(this.result.getRawData().properties.issues.unassigned_jobs=[]):this.result.getRawData().properties.issues={unassigned_jobs:[],unassigned_agents:[],unassigned_shipments:[]}}fixUnassignedItems(t,e){var i,n,s;(null===(i=t.properties.issues)||void 0===i?void 0:i.unassigned_agents)&&(t.properties.issues.unassigned_agents=t.properties.issues.unassigned_agents.map((t=>e.originalAgentIndex))),(null===(n=t.properties.issues)||void 0===n?void 0:n.unassigned_jobs)&&(t.properties.issues.unassigned_jobs=t.properties.issues.unassigned_jobs.map((t=>e.originalJobsIndexes[t]))),(null===(s=t.properties.issues)||void 0===s?void 0:s.unassigned_shipments)&&(t.properties.issues.unassigned_shipments=t.properties.issues.unassigned_shipments.map((t=>e.originalShipmentsIndexes[t])))}}class S extends _{assignJobs(e,i,n){return t(this,void 0,void 0,(function*(){this.validateAgent(e),this.validateJobs(i,e);for(const t of i)this.setJobPriority(t,n),yield this.assignJob(t,e);return!0}))}removeJobs(e){return t(this,void 0,void 0,(function*(){this.validateJobs(e);for(const t of e)yield this.removeJob(t);return!0}))}addNewJobs(e,i){return t(this,void 0,void 0,(function*(){let t=i.map((t=>t.getRaw()));return this.validateAgent(e),this.validateNewJobs(t),yield this.addNewJobsToAgent(e,t),!0}))}assignJob(e,i){return t(this,void 0,void 0,(function*(){let t=this.result.getJobInfoByIndex(e),n=this.result.getAgentSolutionByIndex(i);n&&t&&(yield this.removeJobFromExistingAgent(t),yield this.addJobToExistingAgent(i,e)),n&&!t&&(yield this.addJobToExistingAgent(i,e)),!n&&t&&(yield this.removeJobFromExistingAgent(t),yield this.addJobToNonExistingAgent(i,e)),n||t||(yield this.addJobToNonExistingAgent(i,e))}))}removeJob(e){return t(this,void 0,void 0,(function*(){let t=this.result.getJobInfoByIndex(e);t?yield this.removeJobFromExistingAgent(t):this.result.getRawData().properties.issues.unassigned_jobs=this.result.getRawData().properties.issues.unassigned_jobs.filter((t=>t!==e))}))}addNewJobsToAgent(e,i){return t(this,void 0,void 0,(function*(){let t=this.result.getAgentSolutionByIndex(e),n=this.result.getRawData().properties.params.jobs.length;this.result.getRawData().properties.params.jobs.push(...i);let s=this.addJobsToAgent(e,i.map(((t,e)=>n+e)),t),o=yield this.optimizeRoute(s);this.updateAgent(o,e)}))}addJobToNonExistingAgent(e,i){return t(this,void 0,void 0,(function*(){let t=this.addJobsToAgent(e,[i]),n=yield this.optimizeRoute(t);this.updateAgent(n,e)}))}addJobToExistingAgent(e,i){return t(this,void 0,void 0,(function*(){let t=this.result.getAgentSolutionByIndex(e),n=this.addJobsToAgent(e,[i],t),s=yield this.optimizeRoute(n);this.updateAgent(s,e)}))}removeJobFromExistingAgent(e){return t(this,void 0,void 0,(function*(){let t=e.getAgent(),i=this.removeJobFromAgent(t,e.getActions()[0].getJobIndex());if(this.addUnassignedJob(e),0==i.agentShipmentIndexes.size&&0==i.agentJobIndexes.size)this.removeAgent(t.getAgentIndex());else{let e=yield this.optimizeRoute(i);this.updateAgent(e,t.getAgentIndex())}}))}addJobsToAgent(t,e,i){let n=this.generateOptimizeAgentInput(t,i);return e.forEach((t=>{n.agentJobIndexes.add(t)})),n}removeJobFromAgent(t,e){let i=this.generateOptimizeAgentInput(t.getAgentIndex(),t);return i.agentJobIndexes.delete(e),i}validateJobs(t,e){if(0==t.length)throw new Error("No jobs provided");if(!this.checkIfArrayIsUnique(t))throw new Error("Jobs are not unique");t.forEach((t=>{let i=this.result.getJobInfoByIndex(t);if(null==i&&this.validateJobExists(t),null!=e&&(null==i?void 0:i.getAgent().getAgentIndex())==e)throw new Error(`Job with index ${t} already assigned to agent with index ${e}`)}))}validateJobExists(t){let e=this.getJobByIndex(t);if(!e)throw new Error(`Job with index ${e} not found`);if(!this.result.getRawData().properties.issues.unassigned_jobs.includes(t))throw new Error(`Job with id ${t} is invalid`)}validateNewJobs(t){if(0==t.length)throw new Error("No jobs provided");if(!this.checkIfArrayIsUnique(t))throw new Error("Jobs are not unique");t.forEach((t=>{if(null==t.id)throw new Error("Job id is undefined")}))}addUnassignedJob(t){this.generateEmptyUnassignedJobsIfNeeded(),this.result.getRawData().properties.issues.unassigned_jobs.push(t.getActions()[0].getJobIndex())}setJobPriority(t,e){null!=e&&(this.result.getRawData().properties.params.jobs[t].priority=e)}}class R extends _{assignShipments(e,i,n){return t(this,void 0,void 0,(function*(){this.validateAgent(e),this.validateShipments(i,e);for(const t of i)this.setShipmentPriority(t,n),yield this.assignShipment(t,e);return!0}))}removeShipments(e){return t(this,void 0,void 0,(function*(){this.validateShipments(e);for(const t of e)yield this.removeShipment(t);return!0}))}addNewShipments(e,i){return t(this,void 0,void 0,(function*(){let t=i.map((t=>t.getRaw()));return this.validateAgent(e),this.validateNewShipments(t),yield this.addNewShipmentsToAgent(e,t),!0}))}assignShipment(e,i){return t(this,void 0,void 0,(function*(){let t=this.result.getShipmentInfoByIndex(e),n=this.result.getAgentSolutionByIndex(i);n&&t&&(yield this.removeShipmentFromExistingAgent(t),yield this.addShipmentToExistingAgent(i,e)),n&&!t&&(yield this.addShipmentToExistingAgent(i,e)),!n&&t&&(yield this.removeShipmentFromExistingAgent(t),yield this.addShipmentToNonExistingAgent(i,e)),n||t||(yield this.addShipmentToNonExistingAgent(i,e))}))}removeShipment(e){return t(this,void 0,void 0,(function*(){let t=this.result.getShipmentInfoByIndex(e);t?yield this.removeShipmentFromExistingAgent(t):this.result.getRawData().properties.issues.unassigned_shipments=this.result.getRawData().properties.issues.unassigned_shipments.filter((t=>t!=t))}))}addNewShipmentsToAgent(e,i){return t(this,void 0,void 0,(function*(){let t=this.result.getAgentSolutionByIndex(e),n=this.result.getRawData().properties.params.shipments.length;this.result.getRawData().properties.params.shipments.push(...i);let s=this.addShipmentsToAgent(e,i.map(((t,e)=>n+e)),t),o=yield this.optimizeRoute(s);this.updateAgent(o,e)}))}addShipmentToNonExistingAgent(e,i){return t(this,void 0,void 0,(function*(){let t=this.addShipmentsToAgent(e,[i]),n=yield this.optimizeRoute(t);this.updateAgent(n,e)}))}addShipmentToExistingAgent(e,i){return t(this,void 0,void 0,(function*(){let t=this.result.getAgentSolutionByIndex(e),n=this.addShipmentsToAgent(e,[i],t),s=yield this.optimizeRoute(n);this.updateAgent(s,e)}))}removeShipmentFromExistingAgent(e){return t(this,void 0,void 0,(function*(){let t=e.getAgent(),i=this.removeShipmentFromAgent(t,e.getActions()[0].getShipmentIndex());if(this.addUnassignedShipment(e),0==i.agentShipmentIndexes.size&&0==i.agentJobIndexes.size)this.removeAgent(t.getAgentIndex());else{let t=yield this.optimizeRoute(i);this.updateAgent(t,e.getAgent().getAgentIndex())}}))}addShipmentsToAgent(t,e,i){let n=this.generateOptimizeAgentInput(t,i);return e.forEach((t=>{n.agentShipmentIndexes.add(t)})),n}removeShipmentFromAgent(t,e){let i=this.generateOptimizeAgentInput(t.getAgentIndex(),t);return i.agentShipmentIndexes.delete(e),i}validateShipments(t,e){if(0==t.length)throw new Error("No shipments provided");if(!this.checkIfArrayIsUnique(t))throw new Error("Shipments are not unique");t.forEach((t=>{let i=this.result.getShipmentInfoByIndex(t);if(null==i&&this.validateShipmentExists(t),null!=e&&(null==i?void 0:i.getAgent().getAgentIndex())==e)throw new Error(`Shipment with index ${t} already assigned to agent with index ${e}`)}))}validateShipmentExists(t){if(!this.getShipmentByIndex(t))throw new Error(`Shipment with index ${t} not found`);if(!this.result.getRawData().properties.issues.unassigned_shipments.includes(t))throw new Error(`Shipment with index ${t} is invalid`)}validateNewShipments(t){if(0==t.length)throw new Error("No shipments provided");if(!this.checkIfArrayIsUnique(t))throw new Error("Shipments are not unique");t.forEach((t=>{if(null==t.id)throw new Error("Shipment id is undefined")}))}addUnassignedShipment(t){this.generateEmptyUnassignedShipmentsIfNeeded(),this.result.getRawData().properties.issues.unassigned_shipments.push(t.getActions()[0].getShipmentIndex())}setShipmentPriority(t,e){null!=e&&(this.result.getRawData().properties.params.shipments[t].priority=e)}}class D{constructor(t){this.result=new x(w.cloneObject(t.getOptions()),w.cloneObject(t.getRawData()))}assignJobs(e,i,n){return t(this,void 0,void 0,(function*(){this.assertArray(i,"jobIndexesOrIds");let t=this.convertAgentToIndex(e),s=this.convertJobsToIndexes(i);return new S(this.result).assignJobs(t,s,n)}))}assignShipments(e,i,n){return t(this,void 0,void 0,(function*(){this.assertArray(i,"shipmentIndexesOrIds");let t=this.convertShipmentsToIndexes(i),s=this.convertAgentToIndex(e);return new R(this.result).assignShipments(s,t,n)}))}removeJobs(e){return t(this,void 0,void 0,(function*(){this.assertArray(e,"jobIndexesOrIds");let t=this.convertJobsToIndexes(e);return new S(this.result).removeJobs(t)}))}removeShipments(e){return t(this,void 0,void 0,(function*(){this.assertArray(e,"shipmentIndexes");let t=this.convertShipmentsToIndexes(e);return new R(this.result).removeShipments(t)}))}addNewJobs(t,e){this.assertArray(e,"jobs");let i=this.convertAgentToIndex(t);return new S(this.result).addNewJobs(i,e)}addNewShipments(t,e){this.assertArray(e,"shipments");let i=this.convertAgentToIndex(t);return new R(this.result).addNewShipments(i,e)}getModifiedResult(){return this.result}assertArray(t,e){if(!Array.isArray(t))throw new Error("Type error: "+e+" must be an array")}convertJobsToIndexes(t){if("number"==typeof t[0])return t;let e=[];return t.forEach((t=>{let i=this.result.getData().inputData.jobs.findIndex((e=>e.id===t));if(i<0)throw new Error(`Job with id ${t} not found`);e.push(i)})),e}convertShipmentsToIndexes(t){if("number"==typeof t[0])return t;let e=[];return t.forEach((t=>{let i=this.result.getData().inputData.shipments.findIndex((e=>e.id===t));if(i<0)throw new Error(`Shipment with id ${t} not found`);e.push(i)})),e}convertAgentToIndex(t){if("number"==typeof t)return t;let e=this.result.getData().inputData.agents.findIndex((e=>e.id===t));if(-1===e)throw new Error(`Agent with id ${t} not found`);return e}}class T{static toPrettyDistance(t){return t>1e4?`${(t/1e3).toFixed(1)} km`:t>5e3?`${(t/1e3).toFixed(2)} km`:`${t} m`}static toPrettyTime(t){let e=Math.floor(t/3600),i=Math.floor((t-3600*e)/60);return 0===t?"0":e?i?e+"h "+i+"m":e+"h":i+"min"}}class E{constructor(t,e,i,n){this.WAYPOINT_POPUP_INITIALIZED_ATTRIBUTE="data-rp-timeline-popup-listeners",this.WAYPOINT_POPUP_CONTAINER_ID="geoapify-rp-sdk-waypoint-popup",this.defaultColors=["#ff4d4d","#1a8cff","#00cc66","#b300b3","#e6b800","#ff3385","#0039e6","#408000","#ffa31a","#990073","#cccc00","#cc5200","#6666ff","#009999"],this.timelineTemplate=(t,e,i,n,s,o)=>`\n <div class="geoapify-rp-sdk-timeline-item flex-container items-center ${e%2==0?"geoapify-rp-sdk-even":""}">\n <div class="geoapify-rp-sdk-timeline-item-agent flex-container items-center padding-top-5 padding-bottom-5 ${this.options.hasLargeDescription?"geoapify-rp-sdk-wider":""}">\n ${o&&o.length>0?`\n <div class="geoapify-rp-sdk-three-dot-menu" data-agent-index="${t.agentIndex}">\n <button class="geoapify-rp-sdk-three-dot-button">\n <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 512">\n <path d="M64 360a56 56 0 1 0 0 112 56 56 0 1 0 0-112zm0-160a56 56 0 1 0 0 112 56 56 0 1 0 0-112zM120 96A56 56 0 1 0 8 96a56 56 0 1 0 112 0z"/>\n </svg>\n </button>\n <ul class="geoapify-rp-sdk-menu-list">\n ${o.map((t=>`\n <li class="geoapify-rp-sdk-menu-item" data-key="${t.key}">${t.label}</li>\n `)).join("")}\n </ul>\n </div>\n `:""}\n <div style="color: ${t.color}" class="flex-main geoapify-rp-sdk-agent-info margin-right-10 flex-container column">\n <span class="geoapify-rp-sdk-mat-subtitle-2">${t.label}</span>\n <span class="geoapify-rp-sdk-mat-caption description">${t.description}</span>\n </div>\n </div>\n <div class="geoapify-rp-sdk-timeline flex-main" style="margin-left: 10px; position: relative; height: 100%; min-height: 45px;">\n <div class="geoapify-rp-sdk-line"></div>\n ${t.timelineLength&&"time"===i?`<div class="geoapify-rp-sdk-value-line"\n style="background-color: ${t.color}; width: ${t.timelineLength}; left: ${t.timelineLeft};"></div>\n `:""}\n ${t.distanceLineLength&&"distance"===i?`<div class="geoapify-rp-sdk-value-line"\n style="background-color: ${t.color}; width: ${t.distanceLineLength};"></div>`:""}\n\n ${"time"===i?`\n ${(t.itemsByTime||[]).map(((e,i)=>`\n <div class="geoapify-rp-sdk-solution-item"\n style="left: ${e.position}; width: ${e.minWidth||""}" data-tooltip="${e.description}"\n data-agent-index="${t.agentIndex}" data-waypoint-index="${i}">\n ${"full"===e.form?`<div class="geoapify-rp-sdk-solution-item-full" style="width: 100%; background-color: ${t.color};"></div>`:""}\n ${"standard"===e.form?`<div class="geoapify-rp-sdk-solution-item-standard" style="background-color: ${t.color};"></div>`:""}\n ${"minimal"===e.form?`<div class="geoapify-rp-sdk-solution-item-minimal" style="background-color: ${t.color};"></div>`:""}\n </div>`)).join("")}\n\n `:""}\n\n ${"distance"===i?`\n ${(t.itemsByDistance||[]).map(((e,i)=>`<div class="geoapify-rp-sdk-solution-item" style="left: ${e.position};" data-tooltip="${e.description}"\n data-agent-index="${t.agentIndex}" data-waypoint-index="${i}">\n <div class="geoapify-rp-sdk-solution-item-minimal" style="background-color: ${t.color};"></div>\n </div> `)).join("")}\n `:""}\n ${n&&"time"===i?`\n <div class="geoapify-rp-sdk-label-vertical-lines">\n ${(n||[]).map((t=>`\n <div class="geoapify-rp-sdk-label-vertical-line" style="left: ${t.position};"></div>\n `)).join("")}\n </div>\n `:""}\n\n ${s&&"distance"===i?`\n <div class="geoapify-rp-sdk-label-vertical-lines">\n ${(s||[]).map((t=>`<div class="geoapify-rp-sdk-label-vertical-line" style="left: ${t.position};"></div>`)).join("")}\n </div>\n `:""}\n <div id="global-tooltip" class="geoapify-rp-sdk-custom-tooltip" style="display: none;"></div>\n </div>\n </div>\n`,this.waypointPopupContainer=null,this.eventListeners={},this.container=t,this.result=i,this.inputData=e,this.options=n||{hasLargeDescription:!1,timelineType:"time",agentColors:this.defaultColors,capacityUnit:"items"},this.generateAgentTimeline(),this.initializeThreeDotMenus()}getHasLargeDescription(){return this.options.hasLargeDescription}setHasLargeDescription(t){this.options.hasLargeDescription=t,this.generateAgentTimeline()}getTimelineType(){return this.options.timelineType}setTimelineType(t){this.options.timelineType=t,this.generateAgentTimeline()}getAgentColors(){return this.options.agentColors}setAgentColors(t){this.options.agentColors=t,this.generateAgentTimeline()}getCapacityUnit(){return this.options.capacityUnit}setCapacityUnit(t){this.options.capacityUnit=t,this.generateAgentTimeline()}getTimeLabels(){return this.options.timeLabels}setTimeLabels(t){this.options.timeLabels=t,this.generateAgentTimeline()}getDistanceLabels(){return this.options.distanceLabels}setDistanceLabels(t){this.options.distanceLabels=t,this.generateAgentTimeline()}getAgentLabel(){return this.options.agentLabel}setAgentLabel(t){this.options.agentLabel=t,this.generateAgentTimeline()}getAgentMenuItems(){return this.options.agentMenuItems}setAgentMenuItems(t){this.options.agentMenuItems=t,this.generateAgentTimeline(),this.initializeThreeDotMenus()}getResult(){return this.result}setResult(t){this.result=t,this.generateAgentTimeline(),this.initializeThreeDotMenus()}on(t,e){this.eventListeners[t]||(this.eventListeners[t]=[]),this.eventListeners[t].includes(e)||this.eventListeners[t].push(e)}off(t,e){if(!this.eventListeners[t])return;const i=this.eventListeners[t].indexOf(e);i>-1&&this.eventListeners[t].splice(i,1)}getAgentColorByIndex(t){return this.options.agentColors[(t%this.options.agentColors.length+this.options.agentColors.length)%this.options.agentColors.length]}generateAgentTimeline(){let t;if(this.result&&!this.result.getRawData()){const e=this.result.getRawData().properties.params.agents.length;t=[];for(let i=0;i<=e;i++)t.push({label:`${this.options.agentLabel?this.options.agentLabel:"agent"} ${i+1}`,mode:this.result.getData().inputData.mode,color:this.getAgentColorByIndex(i),description:"",routeVisible:!0,agentIndex:i,timelineLength:"",distanceLineLength:"",itemsByDistance:[],itemsByTime:[],timelineLeft:"100%"});return this.drawTimelines(t,this.result),t}if(this.inputData)return t=this.inputData.agents.map(((t,e)=>{var i;const n=`${this.options.agentLabel?this.options.agentLabel:"Agent"} ${e+1}`;return n.length>=10&&(this.options.hasLargeDescription=!0),{label:n,mode:null===(i=this.inputData)||void 0===i?void 0:i.mode,color:this.getAgentColorByIndex(e),description:this.generateAgentDescription(t,this.options.hasLargeDescription).description,routeVisible:!0,agentIndex:e,timelineLength:"",distanceLineLength:"",itemsByDistance:[],itemsByTime:[],timelineLeft:"100%"}})),this.drawTimelines(t,this.result),t}drawTimelines(t,e){t&&e&&this.generateTimelinesData(t,e),this.container.innerHTML="",null==t||t.forEach(((t,e)=>{const i=this.timelineTemplate(t,e,this.options.timelineType,this.options.timeLabels||[],this.options.distanceLabels||[],this.options.agentMenuItems||[]);this.container.insertAdjacentHTML("beforeend",i),this.result&&this.container.querySelectorAll(".geoapify-rp-sdk-solution-item").forEach((t=>{const e=t.getAttribute("data-agent-index"),i=t.getAttribute("data-waypoint-index"),n=this.result.getAgentSolutions().find((t=>t.getAgentIndex()===+e));if(n&&i){const e=n.getWaypoints()[+i];t.addEventListener("mouseover",(()=>{this.emit("onWaypointHover",e)}))}}))})),this.options.showWaypointPopup&&(this.options.waypointPopupGenerator?this.initializeWaypointPopups():this.initializeGlobalTooltip())}generateTimelinesData(t,e){const i=this.options.capacityUnit||"items";let n=Math.max.apply(Math,e.getAgentSolutions().map((t=>t.getDistance()))),s=Math.max.apply(Math,e.getAgentSolutions().map((t=>t.getTime()+t.getStartTime())));e.getAgentSolutions().forEach((o=>{var r,a;const d=t[o.getAgentIndex()];d.timelineLength=(o.getTime()-((null===(r=o.getWaypoints())||void 0===r?void 0:r.length)?o.getWaypoints()[0].getStartTime():0))/s*100+"%",d.distanceLineLength=o.getDistance()/n*100+"%",d.itemsByDistance=[],d.timelineLeft=(o.getStartTime()||((null===(a=o.getWaypoints())||void 0===a?void 0:a.length)?o.getWaypoints()[0].getStartTime():0))/s*100+"%",this.generateItemsByTime(d,o,s,e,i),this.generateItemsByDistance(d,o,n)}))}emit(t,e){this.eventListeners[t]&&this.eventListeners[t].forEach((i=>{try{i(e)}catch(e){console.error(`Error in event handler for "${t}":`,e)}}))}generateItemsByTime(t,e,i,n,s){t.itemsByTime=[],e.getWaypoints().forEach(((e,o)=>{const r=e.getDuration()||0,a=r/i,d=[],p=[...new Set(e.getActions().map((t=>t.getType().charAt(0).toUpperCase()+t.getType().slice(1))))].join(" / ");d.push(`${o+1}: ${p}`),r&&d.push(`Duration: ${T.toPrettyTime(e.getDuration())}`),d.push(`Time before: ${T.toPrettyTime(e.getStartTime())}`),d.push(`Time after: ${T.toPrettyTime(e.getStartTime()+r)}`);const g=e.getActions().map((t=>{const e=[];if(t){let i=t.getJobIndex()&&t.getJobIndex()>=0?n.getData().inputData.jobs[t.getJobIndex()]:void 0;(null==i?void 0:i.pickup_amount)&&e.push(`pickup ${i.pickup_amount} ${s}`),(null==i?void 0:i.delivery_amount)&&e.push(`deliver ${i.delivery_amount} ${s}`)}let i=t.getShipmentIndex()&&t.getShipmentIndex()>=0?n.getData().inputData.shipments[t.getShipmentIndex()]:void 0;return i&&i.amount&&e.push("pickup"===t.getType()?`pickup ${i.amount} ${s}`:`deliver ${i.amount} ${s}`),e.join(", ")})).filter((t=>t)).join("; ");g&&d.push(`Actions: ${g}`);const h={type:"job",actualWidth:100*a+"%",position:100*(e.getStartTime()+r/2)/i+"%",form:"full",minWidth:100*a+"%",description:d.join("\n")};t.itemsByTime.push(h)}))}generateItemsByDistance(t,e,i){let n=0;e.getLegs().forEach(((s,o)=>{const r=e.getWaypoints()[s.getFromWaypointIndex()],a=e.getWaypoints()[s.getToWaypointIndex()];if(0===o){const e=[],i=[...new Set(r.getActions().map((t=>t.getType().charAt(0).toUpperCase()+t.getType().slice(1))))].join(" / ");e.push(i),e.push("Distance traveled: 0");const n={type:"job",actualWidth:"0",position:"0",form:"minimal",minWidth:"10px",description:e.join("\n")};t.itemsByDistance.push(n)}n+=s.getDistance();const d=[],p=[...new Set(a.getActions().map((t=>t.getType().charAt(0).toUpperCase()+t.getType().slice(1))))].join(" / ");d.push(p),d.push(`Distance traveled: ${T.toPrettyDistance(n)}`);const g={type:"job",actualWidth:"0",position:n/i*100+"%",form:"minimal",minWidth:"10px",description:d.join("\n")};t.itemsByDistance.push(g)}))}generateAgentDescription(t,e){const i=[];return t.pickup_capacity&&t.delivery_capacity?i.push(`${t.pickup_capacity} ${this.options.capacityUnit} / ${t.delivery_capacity} ${this.options.capacityUnit}`):(t.pickup_capacity||t.delivery_capacity)&&i.push(`${t.pickup_capacity||t.delivery_capacity} ${this.options.capacityUnit}`),t.time_windows&&i.push(t.time_windows.map((t=>`${T.toPrettyTime(t[0])}-${T.toPrettyTime(t[1])}`)).join(", ")),t.capabilities&&i.push(...t.capabilities),i.join(", ").length>20&&(e=!0),{description:i.join(", "),hasLargeDescription:e}}initializeGlobalTooltip(){if(document.getElementById("global-tooltip-listener"))return;const t=document.createElement("div");t.id="global-tooltip-listener",document.body.appendChild(t);const e=document.createElement("div");e.id="global-tooltip",e.className="geoapify-rp-sdk-custom-tooltip",e.style.display="none",document.body.appendChild(e),document.addEventListener("mouseover",(t=>{var i;const n=t.target,s=null===(i=n.closest(".geoapify-rp-sdk-solution-item"))||void 0===i?void 0:i.getAttribute("data-tooltip");if(s){const i=n.getBoundingClientRect();e.innerText=s,e.style.display="block",e.style.left=`${t.clientX}px`,e.style.top=`${i.bottom+6}px`,e.classList.add("geoapify-rp-sdk-show")}})),document.addEventListener("mouseout",(t=>{t.target.closest(".geoapify-rp-sdk-solution-item")&&(e.classList.remove("geoapify-rp-sdk-show"),e.style.display="none")}))}createWaypointPopupContainer(){const t=document.getElementById(this.WAYPOINT_POPUP_CONTAINER_ID);t?this.waypointPopupContainer=t:(this.waypointPopupContainer=document.createElement("div"),this.waypointPopupContainer.id="geoapify-rp-sdk-waypoint-popup",this.waypointPopupContainer.className="geoapify-rp-sdk-custom-tooltip",this.waypointPopupContainer.style.opacity="1",this.waypointPopupContainer.style.display="none",document.body.appendChild(this.waypointPopupContainer),document.addEventListener("mouseover",(t=>{if(!this.waypointPopupContainer||"none"===this.waypointPopupContainer.style.display)return;const e=t.target,i=this.waypointPopupContainer.contains(e),n=null!==e.closest(".geoapify-rp-sdk-solution-item");i||n||this.hideWaypointPopup()})))}initializeWaypointPopups(){"true"!==this.container.getAttribute(this.WAYPOINT_POPUP_INITIALIZED_ATTRIBUTE)&&(this.container.setAttribute("data-rp-timeline-popup-listeners","true"),this.createWaypointPopupContainer(),this.container.addEventListener("mouseover",(t=>{const e=t.target.closest(".geoapify-rp-sdk-solution-item");if(e){const t=e.getAttribute("data-agent-index"),i=e.getAttribute("data-waypoint-index");if(null!==t&&null!==i){const n=this.result.getAgentSolutions().find((e=>e.getAgentIndex()===+t));if(n){const t=n.getWaypoints()[+i];if(this.options.waypointPopupGenerator)try{const i=this.options.waypointPopupGenerator(t);this.showWaypointPopup(e,i)}catch(t){console.error("Error generating waypoint popup content:",t)}else this.hideWaypointPopup()}}}})))}showWaypointPopup(t,e){if(!this.waypointPopupContainer)return void console.error("Waypoint popup container not initialized.");this.waypointPopupContainer.innerHTML="",this.waypointPopupContainer.appendChild(e);const i=t.getBoundingClientRect();this.waypointPopupContainer.style.top=`${i.bottom+window.scrollY+10}px`;let n=i.left+window.scrollX+i.width/2-this.waypointPopupContainer.offsetWidth/2;const s=window.innerWidth,o=this.waypointPopupContainer.offsetWidth;n+o>s-10&&(n=s-o-10),n<10&&(n=10),this.waypointPopupContainer.style.left=`${n}px`,this.waypointPopupContainer.style.display="block"}hideWaypointPopup(){this.waypointPopupContainer&&(this.waypointPopupContainer.style.display="none")}initializeThreeDotMenus(){if("true"!==this.container.getAttribute("data-rp-timeline-menu-listeners")&&(this.container.setAttribute("data-rp-timeline-menu-listeners","true"),this.container.addEventListener("click",(t=>{const e=t.target.closest(".geoapify-rp-sdk-three-dot-button");if(e){const t=e.closest(".geoapify-rp-sdk-three-dot-menu");t&&this.toggleThreeDotMenu(t)}})),this.container.addEventListener("click",(t=>{const e=t.target.closest(".geoapify-rp-sdk-menu-item");if(e){const t=e.closest(".geoapify-rp-sdk-three-dot-menu"),i=null==t?void 0:t.getAttribute("data-agent-index"),n=i?+i:-1,s=e.getAttribute("data-key");if(s&&-1!==n&&this.options.agentMenuItems){const t=this.options.agentMenuItems.find((t=>t.key===s));t&&t.callback&&t.callback(n)}this.closeAllThreeDotMenus()}})),!document.getElementById("geoapify-rp-sdk-document-click-listener-flag"))){const t=document.createElement("div");t.id="geoapify-rp-sdk-document-click-listener-flag",t.style.display="none",document.body.appendChild(t),document.addEventListener("click",(t=>{const e=t.target;null!==e.closest(".geoapify-rp-sdk-three-dot-menu")||null!==e.closest(".geoapify-rp-sdk-three-dot-button")||this.closeAllThreeDotMenus()}))}}toggleThreeDotMenu(t){const e=t.querySelector(".geoapify-rp-sdk-menu-list");e&&(this.closeAllThreeDotMenus(t),e.style.display="block"===e.style.display?"none":"block")}closeAllThreeDotMenus(t){this.container.querySelectorAll(".geoapify-rp-sdk-menu-list").forEach((e=>{e.closest(".geoapify-rp-sdk-three-dot-menu")!==t&&(e.style.display="none")}))}}"undefined"!=typeof window&&(window.RoutePlannerSDK=Object.assign({RoutePlanner:b,RouteEditor:D,RoutePlannerTimeLine:E},A)),exports.Agent=e,exports.AgentSolution=l,exports.Avoid=n,exports.Break=s,exports.Coordinates=i,exports.Job=o,exports.Location=r,exports.RouteAction=h,exports.RouteActionInfo=c,exports.RouteLeg=g,exports.RouteLegStep=p,exports.RoutePlanner=b,exports.RoutePlannerError=m,exports.RoutePlannerResult=x,exports.RoutePlannerResultEditor=D,exports.RoutePlannerTimeline=E,exports.Shipment=a,exports.ShipmentStep=d,exports.Waypoint=u,exports.default=b; //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguY2pzLmpzIiwic291cmNlcyI6WyIuLi9ub2RlX21vZHVsZXMvdHNsaWIvdHNsaWIuZXM2LmpzIiwiLi4vc3JjL21vZGVscy9lbnRpdGllcy9uZXN0ZWQvaW5wdXQvYWdlbnQudHMiLCIuLi9zcmMvbW9kZWxzL2VudGl0aWVzL25lc3RlZC9pbnB1dC9jb29yZGluYXRlcy50cyIsIi4uL3NyYy9tb2RlbHMvZW50aXRpZXMvbmVzdGVkL2lucHV0L2F2b2lkLnRzIiwiLi4vc3JjL21vZGVscy9lbnRpdGllcy9uZXN0ZWQvaW5wdXQvYnJlYWsudHMiLCIuLi9zcmMvbW9kZWxzL2VudGl0aWVzL25lc3RlZC9pbnB1dC9qb2IudHMiLCIuLi9zcmMvbW9kZWxzL2VudGl0aWVzL25lc3RlZC9pbnB1dC9sb2NhdGlvbi50cyIsIi4uL3NyYy9tb2RlbHMvZW50aXRpZXMvbmVzdGVkL2lucHV0L3NoaXBtZW50LnRzIiwiLi4vc3JjL21vZGVscy9lbnRpdGllcy9uZXN0ZWQvaW5wdXQvc2hpcG1lbnQtc3RlcC50cyIsIi4uL3NyYy9tb2RlbHMvZW50aXRpZXMvbmVzdGVkL3Jlc3VsdC9yb3V0ZS1sZWctc3RlcC50cyIsIi4uL3NyYy9tb2RlbHMvZW50aXRpZXMvbmVzdGVkL3Jlc3VsdC9yb3V0ZS1sZWcudHMiLCIuLi9zcmMvbW9kZWxzL2VudGl0aWVzL25lc3RlZC9yZXN1bHQvcm91dGUtYWN0aW9uLnRzIiwiLi4vc3JjL21vZGVscy9lbnRpdGllcy9uZXN0ZWQvcmVzdWx0L3dheXBvaW50LnRzIiwiLi4vc3JjL21vZGVscy9lbnRpdGllcy9uZXN0ZWQvcmVzdWx0L2FnZW50LXNvbHV0aW9uLnRzIiwiLi4vc3JjL21vZGVscy9lbnRpdGllcy9uZXN0ZWQvcmVzdWx0L3JvdXRlLWFjdGlvbi1pbmZvLnRzIiwiLi4vc3JjL21vZGVscy9lbnRpdGllcy9yb3V0ZS1wbGFubmVyLWVycm9yLnRzIiwiLi4vc3JjL3Rvb2xzL3V0aWxzLnRzIiwiLi4vc3JjL3Rvb2xzL3JvdXRlLXBsYW5uZXItcmVzdWx0LWNvbnZlcnRlci50cyIsIi4uL3NyYy9tb2RlbHMvZW50aXRpZXMvbmVzdGVkL3Jlc3VsdC9qb2Itc29sdXRpb24udHMiLCIuLi9zcmMvbW9kZWxzL2VudGl0aWVzL25lc3RlZC9yZXN1bHQvc2hpcG1lbnQtc29sdXRpb24udHMiLCIuLi9zcmMvbW9kZWxzL2VudGl0aWVzL3JvdXRlLXBsYW5uZXItcmVzdWx0LnRzIiwiLi4vc3JjL3