react-route-profile 0.1.13 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
'use strict';var reactWrapper=require('@googlemaps/react-wrapper'),T=require('react'),jsxRuntime=require('react/jsx-runtime'),recharts=require('recharts');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var T__namespace=/*#__PURE__*/_interopNamespace(T);var
|
|
1
|
+
'use strict';var reactWrapper=require('@googlemaps/react-wrapper'),T=require('react'),jsxRuntime=require('react/jsx-runtime'),recharts=require('recharts');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var T__namespace=/*#__PURE__*/_interopNamespace(T);var $=()=>typeof window>"u"?true:window.innerWidth>=window.innerHeight,z=()=>{let[e,r]=T.useState($);return T.useEffect(()=>{let o=()=>r($());return window.addEventListener("resize",o),()=>window.removeEventListener("resize",o)},[]),{isHorizontal:e,isVertical:!e}};var S={colors:{primary:"rgba(14, 165, 233, 1)",primaryMuted:"rgba(14, 165, 233, 0.7)",accent:"rgba(132, 204, 22, 1)",surface:"rgba(248, 250, 252, 1)"},marker:{outer:"rgba(132, 204, 22, 1)",inner:"rgba(248, 250, 252, 1)",startInner:"rgba(34, 197, 94, 1)",finishInner:"rgba(239, 68, 68, 1)"},dots:{mapActive:"rgba(132, 204, 22, 1)",chart:"rgba(132, 204, 22, 1)",chartActive:"rgba(132, 204, 22, 1)"},map:{strokeWeight:10,markerSize:50,markerLabelFontSize:20,markerLabelFontWeight:"bold",hoverMarkerScale:6},chart:{margin:{top:4,right:8,bottom:4,left:8},gridStroke:"rgba(255,255,255,0.08)",gridDasharray:"3 3",axisStroke:"rgba(226, 232, 240, 0.7)",cursorStroke:"rgba(226,232,240,0.4)",cursorStrokeWidth:1,yAxisWidth:60,lineStrokeWidth:1,dotRadius:3,dotOpacity:.9,activeDotRadius:3,referenceDotRadius:7,referenceLineOpacity:.5,gradientStartOpacity:.6,gradientEndOpacity:.1,xTickFontSize:12,xTickDy:12,xTickUnitFontSize:10,xTickUnitDx:2,yTickFontSize:12,yTickDy:4,yTickUnitFontSize:10,yTickUnitDx:2},tooltip:{background:"rgba(15,23,42,0.9)",textColor:"#e2e8f0",padding:"6px 8px",borderRadius:6},markerShape:{size:33,lift:20,text:{fontSize:12,fontWeight:300,letterSpacing:2,xOffset:15,lineHeight:12,startLiftPerWord:10}}};var J=T.createContext(S),qe=e=>({colors:{...S.colors,...e?.colors??{}},marker:{...S.marker,...e?.marker??{}},dots:{...S.dots,...e?.dots??{}},map:{...S.map,...e?.map??{}},chart:{...S.chart,...e?.chart??{}},tooltip:{...S.tooltip,...e?.tooltip??{}},markerShape:{...S.markerShape,...e?.markerShape??{},text:{...S.markerShape.text,...e?.markerShape?.text??{}}}}),H=({theme:e,children:r})=>{let o=T.useMemo(()=>qe(e),[e]);return jsxRuntime.jsx(J.Provider,{value:o,children:r})},h=()=>T.useContext(J);var tt=({message:e="Loading map...",height:r="100dvh"})=>{let o=h(),t={height:r,background:o.colors.surface,color:o.colors.primary};return jsxRuntime.jsx("div",{className:"rrpLoader",style:t,children:e})},V=tt;var K=e=>{let{x:r,y:o,payload:t}=e,n=h(),i=Math.round((t?.value??0)/1e3);return jsxRuntime.jsxs("text",{x:r,y:o,fill:n.chart.axisStroke,fontSize:n.chart.xTickFontSize,textAnchor:"middle",dy:n.chart.xTickDy,children:[jsxRuntime.jsx("tspan",{children:i}),jsxRuntime.jsx("tspan",{fontSize:n.chart.xTickUnitFontSize,dx:n.chart.xTickUnitDx,children:"km"})]})};var ee=T.createContext(void 0),te=({children:e})=>{let[r,o]=T.useState({}),t=T.useCallback(s=>o(s),[]),n=T.useCallback(()=>o({}),[]),i=T.useMemo(()=>({hover:r,setHover:t,clearHover:n}),[r,t,n]);return jsxRuntime.jsx(ee.Provider,{value:i,children:e})},N=()=>{let e=T.useContext(ee);if(!e)throw new Error("useHover must be used within HoverProvider");return e};var re=e=>{let{cx:r,cy:o,fill:t}=e,n=h();return r===void 0||o===void 0?null:jsxRuntime.jsx("circle",{cx:r,cy:o,r:n.chart.dotRadius,fill:t,opacity:n.chart.dotOpacity})},ne=e=>{let r=h();return jsxRuntime.jsx(re,{...e,fill:r.dots.chart})},oe=e=>{let r=h();return jsxRuntime.jsx(re,{...e,fill:r.dots.mapActive})};var se=e=>{let{x:r,y:o,payload:t}=e,n=h(),i=Math.round(t?.value??0);return jsxRuntime.jsxs("text",{x:r,y:o,fill:n.chart.axisStroke,fontSize:n.chart.yTickFontSize,textAnchor:"end",dy:n.chart.yTickDy,children:[jsxRuntime.jsx("tspan",{children:i}),jsxRuntime.jsx("tspan",{fontSize:n.chart.yTickUnitFontSize,dx:n.chart.yTickUnitDx,children:"m"})]})};var ae="./surface_asphalt-ZUAYWE5E.png";var ce="./surface_compacted-JVQXEHW6.png";var ue="./surface_concrete-TRX2AGHQ.png";var le="./surface_natural-AFI6LXRM.png";var me="./surface_penetrated-4K24DL3E.png";var de=(i=>(i.Asphalt="asphalt",i.Compacted="compacted",i.Concrete="concrete",i.Natural="natural",i.Penetrated="penetrated",i))(de||{});var pe=30,A=16,U={asphalt:{file:ae,width:30,height:22},compacted:{file:ce,width:200,height:16},concrete:{file:ue},natural:{file:le,width:30,height:22},penetrated:{file:me,width:30,height:22}},he=({route:e,maxDistance:r,xAxisMap:o,offset:t})=>{let n=e.surface??[];if(!n.length)return null;let i=o?Object.values(o)[0]:void 0,s=i?.scale,a=i?.x??t?.left??0,c=i?.width??t?.width??0,m=i?.y??(t?.top??0)+(t?.height??0),l=A,d=m-l;return !s||c<=0?null:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("defs",{children:Object.entries(U).map(([u,{file:v,width:p,height:x}])=>jsxRuntime.jsx("pattern",{id:`surface-${u}`,patternUnits:u==="compacted"?void 0:"userSpaceOnUse",width:p??pe,height:x??A,children:jsxRuntime.jsx("image",{href:v,x:"0",y:"0",width:p??pe,height:x??A})},u))}),jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx("rect",{x:a,y:d,width:c,height:l,fill:"none"}),n.map((u,v)=>{let[p,x]=u.segment,y=Math.max(0,Math.min(p,r)),f=Math.max(0,Math.min(x,r)),w=Math.min(y,f),E=Math.max(y,f);if(E<=w)return null;let R=s(w),C=s(E),O=Math.min(R,C),D=Math.max(0,Math.abs(C-R));return D<=0?null:jsxRuntime.jsx("rect",{x:O,y:d,width:D,height:l,fill:`url(#surface-${u.type})`},`${u.type}-${v}`)})]})]})};var gt=300,xt=(e,r)=>e?.length?e.find(o=>{let[t,n]=o.segment,i=Math.min(t,n),s=Math.max(t,n);return r>=i&&r<=s})??null:null,vt=(e,r)=>e?.length?e.find(o=>{let[t,n]=o.segment,i=Math.min(t,n),s=Math.max(t,n);return r>=i&&r<=s})??null:null,yt=e=>e.charAt(0).toUpperCase()+e.slice(1),ge=e=>{let[r,o]=e,t=Math.min(r,o),n=Math.max(r,o),i=s=>{let c=(s/1e3).toFixed(1);return c.endsWith(".0")?c.slice(0,-2):c};return `(${i(t)} km - ${i(n)} km)`},xe=({active:e,payload:r,label:o,accent:t,primary:n,markers:i,surfaces:s,routes:a})=>{let{tooltip:c}=h();if(!e||!r?.length)return null;let m=r[0]?.payload,l=m?.distance??o,d=i.find(f=>Math.abs((f?.distance??-1)-(m?.distance??0))<=gt),u=xt(s,l),v=u?.type?U[u.type]:null,p=vt(a,l),x=Math.trunc(o/1e3),y=Math.round(o%1e3);return jsxRuntime.jsxs("div",{style:{background:c.background,border:"none",color:c.textColor,padding:"4px 6px",borderRadius:c.borderRadius,fontSize:13,lineHeight:1.2},children:[jsxRuntime.jsxs("div",{style:{fontWeight:600,color:n},children:[x," km ",y," m"]}),jsxRuntime.jsxs("div",{children:["Elevation: ",jsxRuntime.jsxs("strong",{children:[Math.round(m?.elevation??0)," m"]})]}),u?.type?jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[jsxRuntime.jsx("svg",{width:"20",height:"14","aria-hidden":"true",style:{display:"block"},children:v?jsxRuntime.jsx("image",{href:v.file,x:"0",y:"0",width:"20",height:"14",preserveAspectRatio:"xMidYMid slice"}):jsxRuntime.jsx("rect",{width:"20",height:"14",fill:c.textColor})}),jsxRuntime.jsx("span",{children:yt(u.type)}),jsxRuntime.jsx("span",{children:ge(u.segment)})]}):null,p?jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[jsxRuntime.jsx("svg",{width:"20",height:"14","aria-hidden":"true",style:{display:"block"},children:jsxRuntime.jsx("rect",{width:"20",height:"14",fill:p.color})}),jsxRuntime.jsx("span",{children:p.id}),jsxRuntime.jsx("span",{children:ge(p.segment)})]}):null,d?.name?jsxRuntime.jsx("div",{style:{color:t,fontWeight:600},children:d.name}):null]})};var ve=`<svg stroke="currentColor" fill="#84CC16" stroke-width="2" viewBox="0 0 24 24" aria-hidden="true" height="200px" width="200px" xmlns="http://www.w3.org/2000/svg">
|
|
2
2
|
<path stroke-linecap="round" stroke-linejoin="round" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"></path>
|
|
3
3
|
<path fill="white" stroke-linecap="round" stroke-linejoin="round" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"></path>
|
|
4
4
|
</svg>
|
|
5
|
-
`;var Et=(e,r,o)=>{let t=0;return e.replace(/fill="[^"]*"/g,n=>(t+=1,t===1?`fill="${r}"`:t===2?`fill="${o}"`:n))},P=(e,r)=>{let o=Et(we,e,r).trim();return `data:image/svg+xml,${encodeURIComponent(o).replace(/'/g,"%27").replace(/"/g,"%22")}`};var Se=e=>{let{cx:r,cy:o,fill:t,name:n}=e,i=h(),s=i.markerShape,a=s.size,c=T.useMemo(()=>P(i.marker.outer,i.marker.inner),[i.marker.inner,i.marker.outer]);if(r===void 0||o===void 0)return null;let m=typeof n=="string"?n.split(/\s+/).map(l=>l.trim()).filter(Boolean):[];return jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx(se,{cx:r,cy:o}),jsxRuntime.jsx("image",{x:r-a/2,y:o-a/2-s.lift,width:a,height:a,href:c}),n?jsxRuntime.jsx(kt,{words:m,cx:r,cy:o,fill:t}):null]})},kt=({words:e,cx:r,cy:o,fill:t})=>{let i=h().markerShape.text;return jsxRuntime.jsx("text",{y:o-e.length*i.startLiftPerWord,fill:t||"#fff",fontSize:i.fontSize,fontWeight:i.fontWeight,letterSpacing:i.letterSpacing,style:{userSelect:"none"},children:e.map((s,a)=>jsxRuntime.jsx(Ct,{word:s,index:a,cx:r},s))})},Ct=({word:e,index:r,cx:o})=>{let n=h().markerShape.text,i=T.useId();return jsxRuntime.jsx("tspan",{x:o+n.xOffset,dy:r===0?0:n.lineHeight,children:e},i)};var Ee=({route:e,maxDistance:r,belowHeight:o=0,xAxisMap:t,offset:n})=>{let i=e.routes??[];if(!i.length)return null;let s=t?Object.values(t)[0]:void 0,a=s?.scale,c=s?.x??n?.left??0,m=s?.width??n?.width??0,l=s?.y??(n?.top??0)+(n?.height??0),d=16,u=l-o-d;return !a||m<=0?null:jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx("rect",{x:c,y:u,width:m,height:d,fill:"none"}),i.map((v,p)=>{let[x,y]=v.segment,f=Math.max(0,Math.min(x,r)),w=Math.max(0,Math.min(y,r)),E=Math.min(f,w),R=Math.max(f,w);if(R<=E)return null;let C=a(E),O=a(R),D=Math.min(C,O),F=Math.max(0,Math.abs(O-C));return F<=0?null:jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx("rect",{x:D,y:u,width:F,height:d,fill:v.color}),jsxRuntime.jsx("text",{x:D+F/2,y:u+d/2,fill:"#000000",fontSize:10,fontWeight:600,textAnchor:"middle",dominantBaseline:"middle",children:v.id})]},`${v.id}-${p}`)})]})};function Te(e){let[r,o]=T.useState(null),t=T.useMemo(()=>r!=null?e[r]:null,[r,e]),n=T.useCallback(()=>{o(null);},[]),i=T.useCallback(s=>{if(!e.length)return;let a=0,c=e.length-1;for(;a<c;){let l=Math.floor((a+c)/2);e[l].distance<s?a=l+1:c=l;}let m=a;if(a>0){let l=e[a-1],d=e[a];Math.abs(l.distance-s)<Math.abs(d.distance-s)&&(m=a-1);}o(m);},[e]);return {activeIndex:r,activePoint:t,triggerByXValue:i,clearActiveIndex:n}}var ke=e=>e.length?e[e.length-1].distance:0,Ce=(e,r=2e3)=>{let o=[];for(let t=0;t<=e;t+=r)o.push(t);return o[o.length-1]<e&&o.push(e),o},Me=e=>[...e.geoJson?.features?.find(n=>n?.geometry?.type==="LineString"&&n?.properties?.elevationProfile?.points)?.properties?.elevationProfile?.points||[]].sort((n,i)=>(n?.distance??0)-(i?.distance??0)),Pe=e=>(e.geoJson?.features?.find(t=>t?.geometry?.type==="LineString"&&t?.geometry?.coordinates)).geometry.coordinates,Le=e=>{if(!e.length)return [0,0];let r=e.map(i=>i.elevation),o=Math.min(...r),t=Math.max(...r),n=Math.max(10,(t-o)*.05);return [Math.floor(o-n),Math.ceil(t+n)]},De=(e,r=false)=>{let[o,t]=e,n=(t-o)*1.2,i=Math.max(10,Math.round(n/6/10)*10||50),s=r?-20:0,a=Math.floor((o-(n-(t-o))/2)/i)*i+s,c=Math.ceil((t+(n-(t-o))/2)/i)*i+s,m=[];for(let l=a;l<=c+i/2;l+=i)m.push(l);return [a,c,m]},Ie=(e,r)=>{if(!e?.length)return [];let t=(r?.features??[]).filter(i=>i?.geometry?.type==="Point"),n=[];return t.forEach(i=>{let s=i?.geometry?.coordinates;if(!Array.isArray(s)||s.length<2)return;let[a,c]=s;if(!Number.isFinite(c)||!Number.isFinite(a))return;let m=e.reduce((l,d)=>{let u=Math.pow(d.lat-c,2)+Math.pow(d.lng-a,2);return u<l.dist?{point:d,dist:u}:l},{point:null,dist:Number.POSITIVE_INFINITY});if(m.point){if(m.point.distance===0)return;n.push({distance:m.point.distance,elevation:m.point.elevation,name:i?.properties?.name});}}),n.sort((i,s)=>(i.distance??0)-(s.distance??0))},Ae=(e,r)=>{if(!e.length)return null;let o=null,t=Number.POSITIVE_INFINITY;return e.forEach(([n,i])=>{let s=(i-r.lat)**2+(n-r.lng)**2;s<t&&(t=s,o={lat:i,lng:n});}),o},Oe=(e,r)=>{if(!e.length)return null;let o=null,t=Number.POSITIVE_INFINITY;return e.forEach(n=>{let i=(n.lat-r[0])**2+(n.lng-r[1])**2;i<t&&(t=i,o=n);}),o};var ze=(e,r,o=1e3)=>r&&Math.abs((r.distance??0)-(e.distance??0))<o;var G=({route:e})=>{let{hover:r,setHover:o}=N(),t=h(),n=T.useMemo(()=>Me(e),[e]),i=T.useMemo(()=>Ie(n,e.geoJson),[n,e.geoJson]),s=ke(n),a=Ce(s),[c,m]=Le(n),[l,d,u]=T.useMemo(()=>De([c,m],!!e.surface?.length),[c,m,e.surface?.length]),{activeIndex:v,activePoint:p,triggerByXValue:x,clearActiveIndex:y}=Te(n);return T.useEffect(()=>{if(r.source==="chart"||!r.lat||!r.lng)return;let f=Oe(n,[r.lat,r.lng]);f&&x(f.distance);},[r,n,x]),n.length?jsxRuntime.jsx(recharts.ResponsiveContainer,{width:"100%",height:"100%",style:{userSelect:"none"},children:jsxRuntime.jsxs(recharts.ComposedChart,{data:n,margin:t.chart.margin,onMouseMove:({activePayload:f})=>{v&&y();let w=f?.[0];if(!w)return;let{lat:E,lng:R}=w.payload;o({lat:E,lng:R,source:"chart"});},onMouseEnter:()=>y(),children:[jsxRuntime.jsx("defs",{children:jsxRuntime.jsxs("linearGradient",{id:"elevationGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[jsxRuntime.jsx("stop",{offset:"0%",stopColor:t.colors.primary,stopOpacity:t.chart.gradientStartOpacity}),jsxRuntime.jsx("stop",{offset:"100%",stopColor:t.colors.primaryMuted,stopOpacity:t.chart.gradientEndOpacity})]})}),jsxRuntime.jsx(recharts.CartesianGrid,{stroke:t.chart.gridStroke,strokeDasharray:t.chart.gridDasharray}),jsxRuntime.jsx(recharts.Customized,{component:jsxRuntime.jsx(Ee,{route:e,maxDistance:s,belowHeight:A})}),jsxRuntime.jsx(recharts.Customized,{component:jsxRuntime.jsx(xe,{route:e,maxDistance:s})}),jsxRuntime.jsx(recharts.XAxis,{dataKey:"distance",type:"number",domain:[0,s],ticks:a,tick:jsxRuntime.jsx(ee,{}),stroke:t.chart.axisStroke}),jsxRuntime.jsx(recharts.YAxis,{dataKey:"elevation",tick:jsxRuntime.jsx(ce,{}),domain:[l,d],ticks:u,stroke:t.chart.axisStroke,width:t.chart.yAxisWidth}),jsxRuntime.jsx(recharts.Tooltip,{cursor:{stroke:t.chart.cursorStroke,strokeWidth:t.chart.cursorStrokeWidth},content:jsxRuntime.jsx(ye,{accent:t.colors.accent,primary:t.colors.primary,markers:i,surfaces:e.surface,routes:e.routes})}),jsxRuntime.jsx(recharts.Line,{type:"monotone",dataKey:"elevation",stroke:t.colors.primary,strokeWidth:t.chart.lineStrokeWidth,dot:f=>{let{cx:w,cy:E,index:R}=f;return !(R===v)||!p?jsxRuntime.jsx(jsxRuntime.Fragment,{}):jsxRuntime.jsx(ie,{cx:w,cy:E})},activeDot:{r:t.chart.activeDotRadius,fill:t.dots.chartActive,strokeWidth:0},fill:"url(#elevationGradient)",isAnimationActive:false}),i.length>0&&i.map((f,w)=>{let E=ze(i[w],i[w+1]);return jsxRuntime.jsx(recharts.ReferenceDot,{x:f.distance,y:f.elevation,r:t.chart.referenceDotRadius,shape:R=>jsxRuntime.jsx(Se,{...R,name:E?void 0:f.name,fill:t.colors.accent})},`${f.distance}-${w}`)}),p&&jsxRuntime.jsx(recharts.ReferenceLine,{x:p.distance,opacity:t.chart.referenceLineOpacity})]})}):null};var Fe={lat:48.9325937,lng:20.3452306},Xe=13,Ue=12;var We=.2,_e=.15;var Q={};var Ye=({route:e,height:r,isHorizontal:o})=>{let t=h(),{hover:n,setHover:i}=N(),s=T.useRef(null),a=T.useRef(null),c=T.useRef(null),m=T.useMemo(()=>Pe(e),[e]),l=T.useMemo(()=>({default:P(t.marker.outer,t.marker.inner),start:P(t.marker.outer,t.marker.startInner),finish:P(t.marker.outer,t.marker.finishInner)}),[t.marker]);return T.useEffect(()=>{if(!s.current||!window.google?.maps)return;let d=o&&(e.zoomHorizontal||Xe)||e.zoomVertical||Ue,u=new window.google.maps.Map(s.current,{center:e.center||Fe,zoom:d,mapTypeId:window.google.maps.MapTypeId.SATELLITE,streetViewControl:false});c.current=u,u.data.setStyle(p=>{let x=p.getProperty("name"),y=p.getProperty("first"),f=p.getProperty("last");return {strokeColor:t.colors.primaryMuted,strokeWeight:t.map.strokeWeight,icon:{url:y?l.start:f?l.finish:l.default,scaledSize:new window.google.maps.Size(t.map.markerSize,t.map.markerSize),optimized:false,zIndex:y||f?100:10,collisionBehavior:window.google?.maps?.CollisionBehavior?.REQUIRED_AND_HIDES_OPTIONAL},label:{className:Q.rrpMarkerLabel,fontSize:`${t.map.markerLabelFontSize}px`,fontWeight:t.map.markerLabelFontWeight,color:t.colors.accent,text:x}}}),u.data.addGeoJson(e.geoJson);let v=u.addListener("mousemove",p=>{let x=p.latLng;if(!x)return;let y=Ae(m,{lat:x.lat(),lng:x.lng()});y&&i({lat:y.lat,lng:y.lng,source:"map"});});return ()=>{v.remove(),u.data.forEach(p=>{u.data.remove(p);}),c.current=null;}},[e,o,t,m,i,l]),T.useEffect(()=>{if(!s.current||!window.google?.maps)return;let d=c.current;if(!d)return;if(!n.lat||!n.lng){a.current&&(a.current.setMap(null),a.current=null);return}let u={path:window.google.maps.SymbolPath.CIRCLE,scale:t.map.hoverMarkerScale,fillColor:t.dots.mapActive,fillOpacity:1,strokeWeight:0};a.current?a.current.setIcon(u):a.current=new window.google.maps.Marker({map:d,icon:u}),a.current.setPosition({lat:n.lat,lng:n.lng}),a.current.setMap(d);},[n,t]),jsxRuntime.jsx("div",{ref:s,className:Q.rrpMapCanvas,style:{height:r}})};var B={};var Zt={apiKey:"Oops! Cannot display the map: Google Maps API key missing",[reactWrapper.Status.FAILURE]:"Unable to load Google Maps API. Check your API key or network.",[reactWrapper.Status.LOADING]:void 0,[reactWrapper.Status.SUCCESS]:void 0},Be=({type:e,height:r})=>jsxRuntime.jsx("div",{style:{height:r},children:jsxRuntime.jsx(K,{message:Zt[e],height:r})}),$t=(e,r)=>jsxRuntime.jsx(Be,{type:e,height:r}),Ze=({apiKey:e,route:r,height:o="100dvh",className:t,style:n,theme:i=S})=>{let{isHorizontal:s}=z();if(!e)return jsxRuntime.jsx(H,{theme:i,children:jsxRuntime.jsx(Be,{type:"apiKey",height:o})});let a={height:o,width:"100%",...n};return jsxRuntime.jsx(H,{theme:i,children:jsxRuntime.jsx(ne,{children:jsxRuntime.jsxs("div",{className:t,style:a,children:[jsxRuntime.jsx(reactWrapper.Wrapper,{apiKey:e,render:c=>$t(c,o),children:jsxRuntime.jsx(Ye,{route:r,height:o,isHorizontal:s})}),jsxRuntime.jsx("div",{className:B.rrpChartLayer,children:jsxRuntime.jsx("div",{className:B.rrpChartBody,children:jsxRuntime.jsx(G,{route:r})})})]})})})};function $(){let[e,r]=T__namespace.useState({width:null,height:null}),o=T__namespace.useRef(null);return [T__namespace.useCallback(n=>{if(o.current&&(o.current.disconnect(),o.current=null),n?.nodeType===Node.ELEMENT_NODE){let i=new ResizeObserver(([s])=>{if(s&&s.borderBoxSize){let{inlineSize:a,blockSize:c}=s.borderBoxSize[0];r({width:a,height:c});}});i.observe(n),o.current=i;}},[]),e]}var $e=100,Vt=()=>{let{isVertical:e}=z(),[r,{height:o}]=$(),[t,{height:n}]=$(),i=e?We:_e,a=(typeof window<"u"?window.innerHeight:$e/i)*i||$e,c=o||a,m=`calc(100dvh - ${c}px)`;return {refHeader:r,refMapContainer:t,targetHeaderFraction:i,effectiveHeaderHeight:c,mapHeight:n||m}};exports.RouteMap=Ze;exports.SurfaceType=fe;exports.ThemeProvider=H;exports.theme=S;exports.useMapHeader=Vt;exports.useTheme=h;//# sourceMappingURL=index.cjs.map
|
|
5
|
+
`;var St=(e,r,o)=>{let t=0;return e.replace(/fill="[^"]*"/g,n=>(t+=1,t===1?`fill="${r}"`:t===2?`fill="${o}"`:n))},P=(e,r)=>{let o=St(ve,e,r).trim();return `data:image/svg+xml,${encodeURIComponent(o).replace(/'/g,"%27").replace(/"/g,"%22")}`};var ye=e=>{let{cx:r,cy:o,fill:t,name:n}=e,i=h(),s=i.markerShape,a=s.size,c=T.useMemo(()=>P(i.marker.outer,i.marker.inner),[i.marker.inner,i.marker.outer]);if(r===void 0||o===void 0)return null;let m=typeof n=="string"?n.split(/\s+/).map(l=>l.trim()).filter(Boolean):[];return jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx(oe,{cx:r,cy:o}),jsxRuntime.jsx("image",{x:r-a/2,y:o-a/2-s.lift,width:a,height:a,href:c}),n?jsxRuntime.jsx(Rt,{words:m,cx:r,cy:o,fill:t}):null]})},Rt=({words:e,cx:r,cy:o,fill:t})=>{let i=h().markerShape.text;return jsxRuntime.jsx("text",{y:o-e.length*i.startLiftPerWord,fill:t||"#fff",fontSize:i.fontSize,fontWeight:i.fontWeight,letterSpacing:i.letterSpacing,style:{userSelect:"none"},children:e.map((s,a)=>jsxRuntime.jsx(Tt,{word:s,index:a,cx:r},s))})},Tt=({word:e,index:r,cx:o})=>{let n=h().markerShape.text,i=T.useId();return jsxRuntime.jsx("tspan",{x:o+n.xOffset,dy:r===0?0:n.lineHeight,children:e},i)};var Se=({route:e,maxDistance:r,belowHeight:o=0,xAxisMap:t,offset:n})=>{let i=e.routes??[];if(!i.length)return null;let s=t?Object.values(t)[0]:void 0,a=s?.scale,c=s?.x??n?.left??0,m=s?.width??n?.width??0,l=s?.y??(n?.top??0)+(n?.height??0),d=16,u=l-o-d;return !a||m<=0?null:jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx("rect",{x:c,y:u,width:m,height:d,fill:"none"}),i.map((v,p)=>{let[x,y]=v.segment,f=Math.max(0,Math.min(x,r)),w=Math.max(0,Math.min(y,r)),E=Math.min(f,w),R=Math.max(f,w);if(R<=E)return null;let C=a(E),O=a(R),D=Math.min(C,O),F=Math.max(0,Math.abs(O-C));return F<=0?null:jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx("rect",{x:D,y:u,width:F,height:d,fill:v.color}),jsxRuntime.jsx("text",{x:D+F/2,y:u+d/2,fill:"#000000",fontSize:10,fontWeight:600,textAnchor:"middle",dominantBaseline:"middle",children:v.id})]},`${v.id}-${p}`)})]})};function Ee(e){let[r,o]=T.useState(null),t=T.useMemo(()=>r!=null?e[r]:null,[r,e]),n=T.useCallback(()=>{o(null);},[]),i=T.useCallback(s=>{if(!e.length)return;let a=0,c=e.length-1;for(;a<c;){let l=Math.floor((a+c)/2);e[l].distance<s?a=l+1:c=l;}let m=a;if(a>0){let l=e[a-1],d=e[a];Math.abs(l.distance-s)<Math.abs(d.distance-s)&&(m=a-1);}o(m);},[e]);return {activeIndex:r,activePoint:t,triggerByXValue:i,clearActiveIndex:n}}var Re=e=>e.length?e[e.length-1].distance:0,Te=(e,r=2e3)=>{let o=[];for(let t=0;t<=e;t+=r)o.push(t);return o[o.length-1]<e&&o.push(e),o},ke=e=>[...e.geoJson?.features?.find(n=>n?.geometry?.type==="LineString"&&n?.properties?.elevationProfile?.points)?.properties?.elevationProfile?.points||[]].sort((n,i)=>(n?.distance??0)-(i?.distance??0)),Ce=e=>(e.geoJson?.features?.find(t=>t?.geometry?.type==="LineString"&&t?.geometry?.coordinates)).geometry.coordinates,Me=e=>{if(!e.length)return [0,0];let r=e.map(i=>i.elevation),o=Math.min(...r),t=Math.max(...r),n=Math.max(10,(t-o)*.05);return [Math.floor(o-n),Math.ceil(t+n)]},Pe=(e,r=false)=>{let[o,t]=e,n=(t-o)*1.2,i=Math.max(10,Math.round(n/6/10)*10||50),s=r?-20:0,a=Math.floor((o-(n-(t-o))/2)/i)*i+s,c=Math.ceil((t+(n-(t-o))/2)/i)*i+s,m=[];for(let l=a;l<=c+i/2;l+=i)m.push(l);return [a,c,m]},Le=(e,r)=>{if(!e?.length)return [];let t=(r?.features??[]).filter(i=>i?.geometry?.type==="Point"),n=[];return t.forEach(i=>{let s=i?.geometry?.coordinates;if(!Array.isArray(s)||s.length<2)return;let[a,c]=s;if(!Number.isFinite(c)||!Number.isFinite(a))return;let m=e.reduce((l,d)=>{let u=Math.pow(d.lat-c,2)+Math.pow(d.lng-a,2);return u<l.dist?{point:d,dist:u}:l},{point:null,dist:Number.POSITIVE_INFINITY});if(m.point){if(m.point.distance===0)return;n.push({distance:m.point.distance,elevation:m.point.elevation,name:i?.properties?.name});}}),n.sort((i,s)=>(i.distance??0)-(s.distance??0))},De=(e,r)=>{if(!e.length)return null;let o=null,t=Number.POSITIVE_INFINITY;return e.forEach(([n,i])=>{let s=(i-r.lat)**2+(n-r.lng)**2;s<t&&(t=s,o={lat:i,lng:n});}),o},Ie=(e,r)=>{if(!e.length)return null;let o=null,t=Number.POSITIVE_INFINITY;return e.forEach(n=>{let i=(n.lat-r[0])**2+(n.lng-r[1])**2;i<t&&(t=i,o=n);}),o};var Ae=(e,r,o=1e3)=>r&&Math.abs((r.distance??0)-(e.distance??0))<o;var G=({route:e})=>{let{hover:r,setHover:o}=N(),t=h(),n=T.useMemo(()=>ke(e),[e]),i=T.useMemo(()=>Le(n,e.geoJson),[n,e.geoJson]),s=Re(n),a=Te(s),[c,m]=Me(n),[l,d,u]=T.useMemo(()=>Pe([c,m],!!e.surface?.length),[c,m,e.surface?.length]),{activeIndex:v,activePoint:p,triggerByXValue:x,clearActiveIndex:y}=Ee(n);return T.useEffect(()=>{if(r.source==="chart"||!r.lat||!r.lng)return;let f=Ie(n,[r.lat,r.lng]);f&&x(f.distance);},[r,n,x]),n.length?jsxRuntime.jsx(recharts.ResponsiveContainer,{width:"100%",height:"100%",style:{userSelect:"none"},children:jsxRuntime.jsxs(recharts.ComposedChart,{data:n,margin:t.chart.margin,onMouseMove:({activePayload:f})=>{v&&y();let w=f?.[0];if(!w)return;let{lat:E,lng:R}=w.payload;o({lat:E,lng:R,source:"chart"});},onMouseEnter:()=>y(),children:[jsxRuntime.jsx("defs",{children:jsxRuntime.jsxs("linearGradient",{id:"elevationGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[jsxRuntime.jsx("stop",{offset:"0%",stopColor:t.colors.primary,stopOpacity:t.chart.gradientStartOpacity}),jsxRuntime.jsx("stop",{offset:"100%",stopColor:t.colors.primaryMuted,stopOpacity:t.chart.gradientEndOpacity})]})}),jsxRuntime.jsx(recharts.CartesianGrid,{stroke:t.chart.gridStroke,strokeDasharray:t.chart.gridDasharray}),jsxRuntime.jsx(recharts.Customized,{component:jsxRuntime.jsx(Se,{route:e,maxDistance:s,belowHeight:A})}),jsxRuntime.jsx(recharts.Customized,{component:jsxRuntime.jsx(he,{route:e,maxDistance:s})}),jsxRuntime.jsx(recharts.XAxis,{dataKey:"distance",type:"number",domain:[0,s],ticks:a,tick:jsxRuntime.jsx(K,{}),stroke:t.chart.axisStroke}),jsxRuntime.jsx(recharts.YAxis,{dataKey:"elevation",tick:jsxRuntime.jsx(se,{}),domain:[l,d],ticks:u,stroke:t.chart.axisStroke,width:t.chart.yAxisWidth}),jsxRuntime.jsx(recharts.Tooltip,{cursor:{stroke:t.chart.cursorStroke,strokeWidth:t.chart.cursorStrokeWidth},content:jsxRuntime.jsx(xe,{accent:t.colors.accent,primary:t.colors.primary,markers:i,surfaces:e.surface,routes:e.routes})}),jsxRuntime.jsx(recharts.Line,{type:"monotone",dataKey:"elevation",stroke:t.colors.primary,strokeWidth:t.chart.lineStrokeWidth,dot:f=>{let{cx:w,cy:E,index:R}=f;return !(R===v)||!p?jsxRuntime.jsx(jsxRuntime.Fragment,{}):jsxRuntime.jsx(ne,{cx:w,cy:E})},activeDot:{r:t.chart.activeDotRadius,fill:t.dots.chartActive,strokeWidth:0},fill:"url(#elevationGradient)",isAnimationActive:false}),i.length>0&&i.map((f,w)=>{let E=Ae(i[w],i[w+1]);return jsxRuntime.jsx(recharts.ReferenceDot,{x:f.distance,y:f.elevation,r:t.chart.referenceDotRadius,shape:R=>jsxRuntime.jsx(ye,{...R,name:E?void 0:f.name,fill:t.colors.accent})},`${f.distance}-${w}`)}),p&&jsxRuntime.jsx(recharts.ReferenceLine,{x:p.distance,opacity:t.chart.referenceLineOpacity})]})}):null};var He={lat:48.9325937,lng:20.3452306},Ne=13,Fe=12;var Xe=.2,Ue=.15;var We={};var Qe=({route:e,height:r,isHorizontal:o})=>{let t=h(),{hover:n,setHover:i}=N(),s=T.useRef(null),a=T.useRef(null),c=T.useRef(null),m=T.useMemo(()=>Ce(e),[e]),l=T.useMemo(()=>({default:P(t.marker.outer,t.marker.inner),start:P(t.marker.outer,t.marker.startInner),finish:P(t.marker.outer,t.marker.finishInner)}),[t.marker]);return T.useEffect(()=>{if(!s.current||!window.google?.maps)return;let d=o&&(e.zoomHorizontal||Ne)||e.zoomVertical||Fe,u=new window.google.maps.Map(s.current,{center:e.center||He,zoom:d,mapTypeId:window.google.maps.MapTypeId.SATELLITE,streetViewControl:false});c.current=u,u.data.setStyle(p=>{let x=p.getProperty("name"),y=p.getProperty("first"),f=p.getProperty("last");return {strokeColor:t.colors.primaryMuted,strokeWeight:t.map.strokeWeight,icon:{url:y?l.start:f?l.finish:l.default,scaledSize:new window.google.maps.Size(t.map.markerSize,t.map.markerSize),optimized:false,zIndex:y||f?100:10,collisionBehavior:window.google?.maps?.CollisionBehavior?.REQUIRED_AND_HIDES_OPTIONAL},label:{className:"rrpMarkerLabel",fontSize:`${t.map.markerLabelFontSize}px`,fontWeight:t.map.markerLabelFontWeight,color:t.colors.accent,text:x}}}),u.data.addGeoJson(e.geoJson);let v=u.addListener("mousemove",p=>{let x=p.latLng;if(!x)return;let y=De(m,{lat:x.lat(),lng:x.lng()});y&&i({lat:y.lat,lng:y.lng,source:"map"});});return ()=>{v.remove(),u.data.forEach(p=>{u.data.remove(p);}),c.current=null;}},[e,o,t,m,i,l]),T.useEffect(()=>{if(!s.current||!window.google?.maps)return;let d=c.current;if(!d)return;if(!n.lat||!n.lng){a.current&&(a.current.setMap(null),a.current=null);return}let u={path:window.google.maps.SymbolPath.CIRCLE,scale:t.map.hoverMarkerScale,fillColor:t.dots.mapActive,fillOpacity:1,strokeWeight:0};a.current?a.current.setIcon(u):a.current=new window.google.maps.Marker({map:d,icon:u}),a.current.setPosition({lat:n.lat,lng:n.lng}),a.current.setMap(d);},[n,t]),jsxRuntime.jsx("div",{ref:s,className:We.rrpMapCanvas,style:{height:r}})};var Y={};var Yt={apiKey:"Oops! Cannot display the map: Google Maps API key missing",[reactWrapper.Status.FAILURE]:"Unable to load Google Maps API. Check your API key or network.",[reactWrapper.Status.LOADING]:void 0,[reactWrapper.Status.SUCCESS]:void 0},Ye=({type:e,height:r})=>jsxRuntime.jsx("div",{style:{height:r},children:jsxRuntime.jsx(V,{message:Yt[e],height:r})}),Bt=(e,r)=>jsxRuntime.jsx(Ye,{type:e,height:r}),Be=({apiKey:e,route:r,height:o="100dvh",className:t,style:n,theme:i=S})=>{let{isHorizontal:s}=z();if(!e)return jsxRuntime.jsx(H,{theme:i,children:jsxRuntime.jsx(Ye,{type:"apiKey",height:o})});let a={height:o,width:"100%",...n};return jsxRuntime.jsx(H,{theme:i,children:jsxRuntime.jsx(te,{children:jsxRuntime.jsxs("div",{className:t,style:a,children:[jsxRuntime.jsx(reactWrapper.Wrapper,{apiKey:e,render:c=>Bt(c,o),children:jsxRuntime.jsx(Qe,{route:r,height:o,isHorizontal:s})}),jsxRuntime.jsx("div",{className:Y.rrpChartLayer,children:jsxRuntime.jsx("div",{className:Y.rrpChartBody,children:jsxRuntime.jsx(G,{route:r})})})]})})})};function Z(){let[e,r]=T__namespace.useState({width:null,height:null}),o=T__namespace.useRef(null);return [T__namespace.useCallback(n=>{if(o.current&&(o.current.disconnect(),o.current=null),n?.nodeType===Node.ELEMENT_NODE){let i=new ResizeObserver(([s])=>{if(s&&s.borderBoxSize){let{inlineSize:a,blockSize:c}=s.borderBoxSize[0];r({width:a,height:c});}});i.observe(n),o.current=i;}},[]),e]}var Ze=100,$t=()=>{let{isVertical:e}=z(),[r,{height:o}]=Z(),[t,{height:n}]=Z(),i=e?Xe:Ue,a=(typeof window<"u"?window.innerHeight:Ze/i)*i||Ze,c=o||a,m=`calc(100dvh - ${c}px)`;return {refHeader:r,refMapContainer:t,targetHeaderFraction:i,effectiveHeaderHeight:c,mapHeight:n||m}};exports.RouteMap=Be;exports.SurfaceType=de;exports.ThemeProvider=H;exports.theme=S;exports.useMapHeader=$t;exports.useTheme=h;//# sourceMappingURL=index.cjs.map
|
|
6
6
|
//# sourceMappingURL=index.cjs.map
|