react-route-profile 0.1.25 → 0.1.27
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/assets/surface/surface_asphalt.png +0 -0
- package/dist/assets/surface/surface_compacted.png +0 -0
- package/dist/assets/surface/surface_concrete.png +0 -0
- package/dist/assets/surface/surface_natural.png +0 -0
- package/dist/assets/surface/surface_penetrated.png +0 -0
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/surface_asphalt-ZUAYWE5E.png +0 -0
- package/dist/surface_compacted-JVQXEHW6.png +0 -0
- package/dist/surface_concrete-TRX2AGHQ.png +0 -0
- package/dist/surface_natural-AFI6LXRM.png +0 -0
- package/dist/surface_penetrated-4K24DL3E.png +0 -0
- package/package.json +4 -2
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
'use strict';var reactWrapper=require('@googlemaps/react-wrapper'),
|
|
1
|
+
'use strict';var reactWrapper=require('@googlemaps/react-wrapper'),T=require('react'),jsxRuntime=require('react/jsx-runtime'),je=require('./Loader.module-M6WPG37K.module.css'),recharts=require('recharts'),Nt=require('./GoogleMapCanvas.module-GCGVA6T4.module.css'),Xe=require('./RouteMap.module-4GSEMCKC.module.css');require('./index-DIK6ZNA4.css');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}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 je__default=/*#__PURE__*/_interopDefault(je);var Nt__default=/*#__PURE__*/_interopDefault(Nt);var Xe__default=/*#__PURE__*/_interopDefault(Xe);var Y=()=>typeof window>"u"?true:window.innerWidth>=window.innerHeight,Z=()=>{let[e,n]=T.useState(Y);return T.useEffect(()=>{let r=()=>n(Y());return window.addEventListener("resize",r),()=>window.removeEventListener("resize",r)},[]),{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 $=T.createContext(S),Je=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??{}}}}),O=({theme:e,children:n})=>{let r=T.useMemo(()=>Je(e),[e]);return jsxRuntime.jsx($.Provider,{value:r,children:n})},h=()=>T.useContext($);var qe=({message:e="Loading map...",height:n="100dvh"})=>{let r=h(),t={height:n,background:r.colors.surface,color:r.colors.primary};return jsxRuntime.jsx("div",{className:je__default.default.rrpLoader,style:t,children:e})},B=qe;var V=e=>{let{x:n,y:r,payload:t}=e,o=h(),i=Math.round((t?.value??0)/1e3);return jsxRuntime.jsxs("text",{x:n,y:r,fill:o.chart.axisStroke,fontSize:o.chart.xTickFontSize,textAnchor:"middle",dy:o.chart.xTickDy,children:[jsxRuntime.jsx("tspan",{children:i}),jsxRuntime.jsx("tspan",{fontSize:o.chart.xTickUnitFontSize,dx:o.chart.xTickUnitDx,children:"km"})]})};var q=T.createContext(void 0),K=({children:e})=>{let[n,r]=T.useState({}),t=T.useCallback(s=>r(s),[]),o=T.useCallback(()=>r({}),[]),i=T.useMemo(()=>({hover:n,setHover:t,clearHover:o}),[n,t,o]);return jsxRuntime.jsx(q.Provider,{value:i,children:e})},H=()=>{let e=T.useContext(q);if(!e)throw new Error("useHover must be used within HoverProvider");return e};var ee=e=>{let{cx:n,cy:r,fill:t}=e,o=h();return n===void 0||r===void 0?null:jsxRuntime.jsx("circle",{cx:n,cy:r,r:o.chart.dotRadius,fill:t,opacity:o.chart.dotOpacity})},te=e=>{let n=h();return jsxRuntime.jsx(ee,{...e,fill:n.dots.chart})},ne=e=>{let n=h();return jsxRuntime.jsx(ee,{...e,fill:n.dots.mapActive})};var oe=e=>{let{x:n,y:r,payload:t}=e,o=h(),i=Math.round(t?.value??0);return jsxRuntime.jsxs("text",{x:n,y:r,fill:o.chart.axisStroke,fontSize:o.chart.yTickFontSize,textAnchor:"end",dy:o.chart.yTickDy,children:[jsxRuntime.jsx("tspan",{children:i}),jsxRuntime.jsx("tspan",{fontSize:o.chart.yTickUnitFontSize,dx:o.chart.yTickUnitDx,children:"m"})]})};var ie="./surface_asphalt-ZUAYWE5E.png";var se="./surface_compacted-JVQXEHW6.png";var ae="./surface_concrete-TRX2AGHQ.png";var ce="./surface_natural-AFI6LXRM.png";var ue="./surface_penetrated-4K24DL3E.png";var le=(i=>(i.Asphalt="asphalt",i.Compacted="compacted",i.Concrete="concrete",i.Natural="natural",i.Penetrated="penetrated",i))(le||{});var me=30,A=16,U={asphalt:{file:ie,width:30,height:22},compacted:{file:se,width:200,height:16},concrete:{file:ae},natural:{file:ce,width:30,height:22},penetrated:{file:ue,width:30,height:22}},pe=({route:e,maxDistance:n,xAxisMap:r,offset:t})=>{let o=e.surface??[];if(!o.length)return null;let i=r?Object.values(r)[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??me,height:x??A,children:jsxRuntime.jsx("image",{href:v,x:"0",y:"0",width:p??me,height:x??A})},u))}),jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx("rect",{x:a,y:d,width:c,height:l,fill:"none"}),o.map((u,v)=>{let[p,x]=u.segment,y=Math.max(0,Math.min(p,n)),f=Math.max(0,Math.min(x,n)),w=Math.min(y,f),b=Math.max(y,f);if(b<=w)return null;let R=s(w),C=s(b),z=Math.min(R,C),D=Math.max(0,Math.abs(C-R));return D<=0?null:jsxRuntime.jsx("rect",{x:z,y:d,width:D,height:l,fill:`url(#surface-${u.type})`},`${u.type}-${v}`)})]})]})};var pt=300,ft=(e,n)=>e?.length?e.find(r=>{let[t,o]=r.segment,i=Math.min(t,o),s=Math.max(t,o);return n>=i&&n<=s})??null:null,ht=(e,n)=>e?.length?e.find(r=>{let[t,o]=r.segment,i=Math.min(t,o),s=Math.max(t,o);return n>=i&&n<=s})??null:null,gt=e=>e.charAt(0).toUpperCase()+e.slice(1),fe=e=>{let[n,r]=e,t=Math.min(n,r),o=Math.max(n,r),i=s=>{let c=(s/1e3).toFixed(1);return c.endsWith(".0")?c.slice(0,-2):c};return `(${i(t)} km - ${i(o)} km)`},he=({active:e,payload:n,label:r,accent:t,primary:o,markers:i,surfaces:s,routes:a})=>{let{tooltip:c}=h();if(!e||!n?.length)return null;let m=n[0]?.payload,l=m?.distance??r,d=i.find(f=>Math.abs((f?.distance??-1)-(m?.distance??0))<=pt),u=ft(s,l),v=u?.type?U[u.type]:null,p=ht(a,l),x=Math.trunc(r/1e3),y=Math.round(r%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:o},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:gt(u.type)}),jsxRuntime.jsx("span",{children:fe(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:fe(p.segment)})]}):null,d?.name?jsxRuntime.jsx("div",{style:{color:t,fontWeight:600},children:d.name}):null]})};var ge=`<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 pt=(e,r,n)=>{let t=0;return e.replace(/fill="[^"]*"/g,o=>(t+=1,t===1?`fill="${r}"`:t===2?`fill="${n}"`:o))},L=(e,r)=>{let n=pt(me,e,r).trim();return `data:image/svg+xml,${encodeURIComponent(n).replace(/'/g,"%27").replace(/"/g,"%22")}`};var de=e=>{let{cx:r,cy:n,fill:t,name:o}=e,s=h(),a=s.markerShape,i=a.size,c=k.useMemo(()=>L(s.marker.outer,s.marker.inner),[s.marker.inner,s.marker.outer]);if(r===void 0||n===void 0)return null;let m=typeof o=="string"?o.split(/\s+/).map(l=>l.trim()).filter(Boolean):[];return jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx(re,{cx:r,cy:n}),jsxRuntime.jsx("image",{x:r-i/2,y:n-i/2-a.lift,width:i,height:i,href:c}),o?jsxRuntime.jsx(gt,{words:m,cx:r,cy:n,fill:t}):null]})},gt=({words:e,cx:r,cy:n,fill:t})=>{let s=h().markerShape.text;return jsxRuntime.jsx("text",{y:n-e.length*s.startLiftPerWord,fill:t||"#fff",fontSize:s.fontSize,fontWeight:s.fontWeight,letterSpacing:s.letterSpacing,style:{userSelect:"none"},children:e.map((a,i)=>jsxRuntime.jsx(vt,{word:a,index:i,cx:r},a))})},vt=({word:e,index:r,cx:n})=>{let o=h().markerShape.text,s=k.useId();return jsxRuntime.jsx("tspan",{x:n+o.xOffset,dy:r===0?0:o.lineHeight,children:e},s)};var fe=({route:e,maxDistance:r,belowHeight:n=0,xAxisMap:t,offset:o})=>{let s=e.routes??[];if(!s.length)return null;let a=t?Object.values(t)[0]:void 0,i=a?.scale,c=a?.x??o?.left??0,m=a?.width??o?.width??0,l=a?.y??(o?.top??0)+(o?.height??0),d=16,u=l-n-d;return !i||m<=0?null:jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx("rect",{x:c,y:u,width:m,height:d,fill:"none"}),s.map((y,p)=>{let[v,S]=y.segment,f=Math.max(0,Math.min(v,r)),x=Math.max(0,Math.min(S,r)),b=Math.min(f,x),E=Math.max(f,x);if(E<=b)return null;let C=i(b),O=i(E),I=Math.min(C,O),z=Math.max(0,Math.abs(O-C));return z<=0?null:jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx("rect",{x:I,y:u,width:z,height:d,fill:y.color}),jsxRuntime.jsx("text",{x:I+z/2,y:u+d/2,fill:"#000000",fontSize:10,fontWeight:600,textAnchor:"middle",dominantBaseline:"middle",children:y.id})]},`${y.id}-${p}`)})]})};function ge(e){let[r,n]=k.useState(null),t=k.useMemo(()=>r!=null?e[r]:null,[r,e]),o=k.useCallback(()=>{n(null);},[]),s=k.useCallback(a=>{if(!e.length)return;let i=0,c=e.length-1;for(;i<c;){let l=Math.floor((i+c)/2);e[l].distance<a?i=l+1:c=l;}let m=i;if(i>0){let l=e[i-1],d=e[i];Math.abs(l.distance-a)<Math.abs(d.distance-a)&&(m=i-1);}n(m);},[e]);return {activeIndex:r,activePoint:t,triggerByXValue:s,clearActiveIndex:o}}var ve=e=>e.length?e[e.length-1].distance:0,ye=(e,r=2e3)=>{let n=[];for(let t=0;t<=e;t+=r)n.push(t);return n[n.length-1]<e&&n.push(e),n},Se=e=>[...e.geoJson?.features?.find(o=>o?.geometry?.type==="LineString"&&o?.properties?.elevationProfile?.points)?.properties?.elevationProfile?.points||[]].sort((o,s)=>(o?.distance??0)-(s?.distance??0)),xe=e=>(e.geoJson?.features?.find(t=>t?.geometry?.type==="LineString"&&t?.geometry?.coordinates)).geometry.coordinates,we=e=>{if(!e.length)return [0,0];let r=e.map(s=>s.elevation),n=Math.min(...r),t=Math.max(...r),o=Math.max(10,(t-n)*.05);return [Math.floor(n-o),Math.ceil(t+o)]},be=(e,r=false)=>{let[n,t]=e,o=(t-n)*1.2,s=Math.max(10,Math.round(o/6/10)*10||50),a=r?-20:0,i=Math.floor((n-(o-(t-n))/2)/s)*s+a,c=Math.ceil((t+(o-(t-n))/2)/s)*s+a,m=[];for(let l=i;l<=c+s/2;l+=s)m.push(l);return [i,c,m]},Re=(e,r)=>{if(!e?.length)return [];let t=(r?.features??[]).filter(s=>s?.geometry?.type==="Point"),o=[];return t.forEach(s=>{let a=s?.geometry?.coordinates;if(!Array.isArray(a)||a.length<2)return;let[i,c]=a;if(!Number.isFinite(c)||!Number.isFinite(i))return;let m=e.reduce((l,d)=>{let u=Math.pow(d.lat-c,2)+Math.pow(d.lng-i,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;o.push({distance:m.point.distance,elevation:m.point.elevation,name:s?.properties?.name});}}),o.sort((s,a)=>(s.distance??0)-(a.distance??0))},Ee=(e,r)=>{if(!e.length)return null;let n=null,t=Number.POSITIVE_INFINITY;return e.forEach(([o,s])=>{let a=(s-r.lat)**2+(o-r.lng)**2;a<t&&(t=a,n={lat:s,lng:o});}),n},ke=(e,r)=>{if(!e.length)return null;let n=null,t=Number.POSITIVE_INFINITY;return e.forEach(o=>{let s=(o.lat-r[0])**2+(o.lng-r[1])**2;s<t&&(t=s,n=o);}),n};var Te=(e,r,n=1e3)=>r&&Math.abs((r.distance??0)-(e.distance??0))<n;var Y=({route:e})=>{let{hover:r,setHover:n}=H(),t=h(),o=k.useMemo(()=>Se(e),[e]),s=k.useMemo(()=>Re(o,e.geoJson),[o,e.geoJson]),a=ve(o),i=ye(a),[c,m]=we(o),[l,d,u]=k.useMemo(()=>be([c,m],!!e.surface?.length),[c,m,e.surface?.length]),{activeIndex:y,activePoint:p,triggerByXValue:v,clearActiveIndex:S}=ge(o);return k.useEffect(()=>{if(r.source==="chart"||!r.lat||!r.lng)return;let f=ke(o,[r.lat,r.lng]);f&&v(f.distance);},[r,o,v]),o.length?jsxRuntime.jsx(recharts.ResponsiveContainer,{width:"100%",height:"100%",style:{userSelect:"none"},children:jsxRuntime.jsxs(recharts.ComposedChart,{data:o,margin:t.chart.margin,onMouseMove:({activePayload:f})=>{y&&S();let x=f?.[0];if(!x)return;let{lat:b,lng:E}=x.payload;n({lat:b,lng:E,source:"chart"});},onMouseEnter:()=>S(),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(fe,{route:e,maxDistance:a,belowHeight:A})}),jsxRuntime.jsx(recharts.Customized,{component:jsxRuntime.jsx(ce,{route:e,maxDistance:a})}),jsxRuntime.jsx(recharts.XAxis,{dataKey:"distance",type:"number",domain:[0,a],ticks:i,tick:jsxRuntime.jsx(Z,{}),stroke:t.chart.axisStroke}),jsxRuntime.jsx(recharts.YAxis,{dataKey:"elevation",tick:jsxRuntime.jsx(oe,{}),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(le,{accent:t.colors.accent,primary:t.colors.primary,markers:s,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:x,cy:b,index:E}=f;if(E===y&&p)return jsxRuntime.jsx(te,{cx:x,cy:b},`dot-${x}-${b}`)},activeDot:{r:t.chart.activeDotRadius,fill:t.dots.chartActive,strokeWidth:0},fill:"url(#elevationGradient)",isAnimationActive:false}),s.length>0&&s.map((f,x)=>{let b=Te(s[x],s[x+1]);return jsxRuntime.jsx(recharts.ReferenceDot,{x:f.distance,y:f.elevation,r:t.chart.referenceDotRadius,shape:E=>jsxRuntime.jsx(de,{...E,name:b?void 0:f.name,fill:t.colors.accent})},`${f.distance}-${x}`)}),p&&jsxRuntime.jsx(recharts.ReferenceLine,{x:p.distance,opacity:t.chart.referenceLineOpacity})]})}):null};var Le={lat:48.9325937,lng:20.3452306},Pe=13,Ie=12;var Oe=({route:e,height:r,isHorizontal:n})=>{let t=h(),{hover:o,setHover:s}=H(),a=k.useRef(null),i=k.useRef(null),c=k.useRef(null),m=k.useMemo(()=>xe(e),[e]),l=k.useMemo(()=>({default:L(t.marker.outer,t.marker.inner),start:L(t.marker.outer,t.marker.startInner),finish:L(t.marker.outer,t.marker.finishInner)}),[t.marker]);return k.useEffect(()=>{if(!a.current||!window.google?.maps)return;let d=n&&(e.zoomHorizontal||Pe)||e.zoomVertical||Ie,u=new window.google.maps.Map(a.current,{center:e.center||Le,zoom:d,mapTypeId:window.google.maps.MapTypeId.SATELLITE,streetViewControl:false});c.current=u,u.data.setStyle(p=>{let v=p.getProperty("name"),S=p.getProperty("first"),f=p.getProperty("last");return {strokeColor:t.colors.primaryMuted,strokeWeight:t.map.strokeWeight,icon:{url:S?l.start:f?l.finish:l.default,scaledSize:new window.google.maps.Size(t.map.markerSize,t.map.markerSize),optimized:false,zIndex:S||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:v}}}),u.data.addGeoJson(e.geoJson);let y=u.addListener("mousemove",p=>{let v=p.latLng;if(!v)return;let S=Ee(m,{lat:v.lat(),lng:v.lng()});S&&s({lat:S.lat,lng:S.lng,source:"map"});});return ()=>{y.remove(),u.data.forEach(p=>{u.data.remove(p);}),c.current=null;}},[e,n,t,m,s,l]),k.useEffect(()=>{if(!a.current||!window.google?.maps)return;let d=c.current;if(!d)return;if(!o.lat||!o.lng){i.current&&(i.current.setMap(null),i.current=null);return}let u={path:window.google.maps.SymbolPath.CIRCLE,scale:t.map.hoverMarkerScale,fillColor:t.dots.mapActive,fillOpacity:1,strokeWeight:0};i.current?i.current.setIcon(u):i.current=new window.google.maps.Marker({map:d,icon:u}),i.current.setPosition({lat:o.lat,lng:o.lng}),i.current.setMap(d);},[o,t]),jsxRuntime.jsx("div",{ref:a,className:Dt__default.default.rrpMapCanvas,style:{height:r}})};var Nt={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},He=({type:e,height:r})=>jsxRuntime.jsx("div",{style:{height:r},children:jsxRuntime.jsx(J,{message:Nt[e],height:r})}),Ht=(e,r)=>jsxRuntime.jsx(He,{type:e,height:r}),ze=({apiKey:e,route:r,height:n="100dvh",className:t,style:o,theme:s=w})=>{let{isHorizontal:a}=G();if(!e)return jsxRuntime.jsx(N,{theme:s,children:jsxRuntime.jsx(He,{type:"apiKey",height:n})});let i={height:n,width:"100%",...o};return jsxRuntime.jsx(N,{theme:s,children:jsxRuntime.jsx(j,{children:jsxRuntime.jsxs("div",{className:t,style:i,children:[jsxRuntime.jsx(reactWrapper.Wrapper,{apiKey:e,render:c=>Ht(c,n),children:jsxRuntime.jsx(Oe,{route:r,height:n,isHorizontal:a})}),jsxRuntime.jsx("div",{className:Ne__default.default.rrpChartLayer,children:jsxRuntime.jsx("div",{className:Ne__default.default.rrpChartBody,children:jsxRuntime.jsx(Y,{route:r})})})]})})})};function Ue(){let[e,r]=k__namespace.useState({width:null,height:null}),n=k__namespace.useRef(null);return [k__namespace.useCallback(o=>{if(n.current&&(n.current.disconnect(),n.current=null),o?.nodeType===Node.ELEMENT_NODE){let s=new ResizeObserver(([a])=>{if(a&&a.borderBoxSize){let{inlineSize:i,blockSize:c}=a.borderBoxSize[0];r({width:i,height:c});}});s.observe(o),n.current=s;}},[]),e]}var Ut=()=>{let[e,{height:r}]=Ue(),n=!!r,t=n?`calc(100dvh - ${r}px)`:"0px";return {refHeader:e,isHeaderReady:n,headerHeight:r,mapHeight:t}};exports.RouteMap=ze;exports.SurfaceType=se;exports.ThemeProvider=N;exports.theme=w;exports.useMapHeader=Ut;exports.useTheme=h;//# sourceMappingURL=index.cjs.map
|
|
5
|
+
`;var vt=(e,n,r)=>{let t=0;return e.replace(/fill="[^"]*"/g,o=>(t+=1,t===1?`fill="${n}"`:t===2?`fill="${r}"`:o))},P=(e,n)=>{let r=vt(ge,e,n).trim();return `data:image/svg+xml,${encodeURIComponent(r).replace(/'/g,"%27").replace(/"/g,"%22")}`};var xe=e=>{let{cx:n,cy:r,fill:t,name:o}=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(n===void 0||r===void 0)return null;let m=typeof o=="string"?o.split(/\s+/).map(l=>l.trim()).filter(Boolean):[];return jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx(ne,{cx:n,cy:r}),jsxRuntime.jsx("image",{x:n-a/2,y:r-a/2-s.lift,width:a,height:a,href:c}),o?jsxRuntime.jsx(St,{words:m,cx:n,cy:r,fill:t}):null]})},St=({words:e,cx:n,cy:r,fill:t})=>{let i=h().markerShape.text;return jsxRuntime.jsx("text",{y:r-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(bt,{word:s,index:a,cx:n},s))})},bt=({word:e,index:n,cx:r})=>{let o=h().markerShape.text,i=T.useId();return jsxRuntime.jsx("tspan",{x:r+o.xOffset,dy:n===0?0:o.lineHeight,children:e},i)};var ye=({route:e,maxDistance:n,belowHeight:r=0,xAxisMap:t,offset:o})=>{let i=e.routes??[];if(!i.length)return null;let s=t?Object.values(t)[0]:void 0,a=s?.scale,c=s?.x??o?.left??0,m=s?.width??o?.width??0,l=s?.y??(o?.top??0)+(o?.height??0),d=16,u=l-r-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,n)),w=Math.max(0,Math.min(y,n)),b=Math.min(f,w),R=Math.max(f,w);if(R<=b)return null;let C=a(b),z=a(R),D=Math.min(C,z),N=Math.max(0,Math.abs(z-C));return N<=0?null:jsxRuntime.jsxs("g",{children:[jsxRuntime.jsx("rect",{x:D,y:u,width:N,height:d,fill:v.color}),jsxRuntime.jsx("text",{x:D+N/2,y:u+d/2,fill:"#000000",fontSize:10,fontWeight:600,textAnchor:"middle",dominantBaseline:"middle",children:v.id})]},`${v.id}-${p}`)})]})};function Se(e){let[n,r]=T.useState(null),t=T.useMemo(()=>n!=null?e[n]:null,[n,e]),o=T.useCallback(()=>{r(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);}r(m);},[e]);return {activeIndex:n,activePoint:t,triggerByXValue:i,clearActiveIndex:o}}var be=e=>e.length?e[e.length-1].distance:0,Ee=(e,n=2e3)=>{let r=[];for(let t=0;t<=e;t+=n)r.push(t);return r[r.length-1]<e&&r.push(e),r},Re=e=>[...e.geoJson?.features?.find(o=>o?.geometry?.type==="LineString"&&o?.properties?.elevationProfile?.points)?.properties?.elevationProfile?.points||[]].sort((o,i)=>(o?.distance??0)-(i?.distance??0)),Te=e=>(e.geoJson?.features?.find(t=>t?.geometry?.type==="LineString"&&t?.geometry?.coordinates)).geometry.coordinates,ke=e=>{if(!e.length)return [0,0];let n=e.map(i=>i.elevation),r=Math.min(...n),t=Math.max(...n),o=Math.max(10,(t-r)*.05);return [Math.floor(r-o),Math.ceil(t+o)]},Ce=(e,n=false)=>{let[r,t]=e,o=(t-r)*1.2,i=Math.max(10,Math.round(o/6/10)*10||50),s=n?-20:0,a=Math.floor((r-(o-(t-r))/2)/i)*i+s,c=Math.ceil((t+(o-(t-r))/2)/i)*i+s,m=[];for(let l=a;l<=c+i/2;l+=i)m.push(l);return [a,c,m]},Me=(e,n)=>{if(!e?.length)return [];let t=(n?.features??[]).filter(i=>i?.geometry?.type==="Point"),o=[];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;o.push({distance:m.point.distance,elevation:m.point.elevation,name:i?.properties?.name});}}),o.sort((i,s)=>(i.distance??0)-(s.distance??0))},Pe=(e,n)=>{if(!e.length)return null;let r=null,t=Number.POSITIVE_INFINITY;return e.forEach(([o,i])=>{let s=(i-n.lat)**2+(o-n.lng)**2;s<t&&(t=s,r={lat:i,lng:o});}),r},Le=(e,n)=>{if(!e.length)return null;let r=null,t=Number.POSITIVE_INFINITY;return e.forEach(o=>{let i=(o.lat-n[0])**2+(o.lng-n[1])**2;i<t&&(t=i,r=o);}),r};var De=(e,n,r=1e3)=>n&&Math.abs((n.distance??0)-(e.distance??0))<r;var _=({route:e})=>{let{hover:n,setHover:r}=H(),t=h(),o=T.useMemo(()=>Re(e),[e]),i=T.useMemo(()=>Me(o,e.geoJson),[o,e.geoJson]),s=be(o),a=Ee(s),[c,m]=ke(o),[l,d,u]=T.useMemo(()=>Ce([c,m],!!e.surface?.length),[c,m,e.surface?.length]),{activeIndex:v,activePoint:p,triggerByXValue:x,clearActiveIndex:y}=Se(o);return T.useEffect(()=>{if(n.source==="chart"||!n.lat||!n.lng)return;let f=Le(o,[n.lat,n.lng]);f&&x(f.distance);},[n,o,x]),o.length?jsxRuntime.jsx(recharts.ResponsiveContainer,{width:"100%",height:"100%",style:{userSelect:"none"},children:jsxRuntime.jsxs(recharts.ComposedChart,{data:o,margin:t.chart.margin,onMouseMove:({activePayload:f})=>{v&&y();let w=f?.[0];if(!w)return;let{lat:b,lng:R}=w.payload;r({lat:b,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(ye,{route:e,maxDistance:s,belowHeight:A})}),jsxRuntime.jsx(recharts.Customized,{component:jsxRuntime.jsx(pe,{route:e,maxDistance:s})}),jsxRuntime.jsx(recharts.XAxis,{dataKey:"distance",type:"number",domain:[0,s],ticks:a,tick:jsxRuntime.jsx(V,{}),stroke:t.chart.axisStroke}),jsxRuntime.jsx(recharts.YAxis,{dataKey:"elevation",tick:jsxRuntime.jsx(oe,{}),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(he,{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:b,index:R}=f;if(R===v&&p)return jsxRuntime.jsx(te,{cx:w,cy:b},`dot-${w}-${b}`)},activeDot:{r:t.chart.activeDotRadius,fill:t.dots.chartActive,strokeWidth:0},fill:"url(#elevationGradient)",isAnimationActive:false}),i.length>0&&i.map((f,w)=>{let b=De(i[w],i[w+1]);return jsxRuntime.jsx(recharts.ReferenceDot,{x:f.distance,y:f.elevation,r:t.chart.referenceDotRadius,shape:R=>jsxRuntime.jsx(xe,{...R,name:b?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 ze={lat:48.9325937,lng:20.3452306},Oe=13,He=12;var Ue=({route:e,height:n,isHorizontal:r})=>{let t=h(),{hover:o,setHover:i}=H(),s=T.useRef(null),a=T.useRef(null),c=T.useRef(null),m=T.useMemo(()=>Te(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=r&&(e.zoomHorizontal||Oe)||e.zoomVertical||He,u=new window.google.maps.Map(s.current,{center:e.center||ze,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=Pe(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,r,t,m,i,l]),T.useEffect(()=>{if(!s.current||!window.google?.maps)return;let d=c.current;if(!d)return;if(!o.lat||!o.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:o.lat,lng:o.lng}),a.current.setMap(d);},[o,t]),jsxRuntime.jsx("div",{ref:s,className:Nt__default.default.rrpMapCanvas,style:{height:n}})};var Xt={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},We=({type:e,height:n})=>jsxRuntime.jsx("div",{style:{height:n},children:jsxRuntime.jsx(B,{message:Xt[e],height:n})}),Wt=(e,n)=>jsxRuntime.jsx(We,{type:e,height:n}),_e=({apiKey:e,route:n,height:r="100dvh",className:t,style:o,theme:i=S})=>{let{isHorizontal:s}=Z();if(!e)return jsxRuntime.jsx(O,{theme:i,children:jsxRuntime.jsx(We,{type:"apiKey",height:r})});let a={height:r,width:"100%",...o};return jsxRuntime.jsx(O,{theme:i,children:jsxRuntime.jsx(K,{children:jsxRuntime.jsxs("div",{className:t,style:a,children:[jsxRuntime.jsx(reactWrapper.Wrapper,{apiKey:e,render:c=>Wt(c,r),children:jsxRuntime.jsx(Ue,{route:n,height:r,isHorizontal:s})}),jsxRuntime.jsx("div",{className:Xe__default.default.rrpChartLayer,children:jsxRuntime.jsx("div",{className:Xe__default.default.rrpChartBody,children:jsxRuntime.jsx(_,{route:n})})})]})})})};function Ge(){let[e,n]=T__namespace.useState({width:null,height:null}),r=T__namespace.useRef(null);return [T__namespace.useCallback(o=>{if(r.current&&(r.current.disconnect(),r.current=null),o?.nodeType===Node.ELEMENT_NODE){let i=new ResizeObserver(([s])=>{if(s&&s.borderBoxSize){let{inlineSize:a,blockSize:c}=s.borderBoxSize[0];n({width:a,height:c});}});i.observe(o),r.current=i;}},[]),e]}var Gt=()=>{let[e,{height:n}]=Ge(),r=!!n,t=r?`calc(100dvh - ${n}px)`:"0px";return {refHeader:e,isHeaderReady:r,headerHeight:n,mapHeight:t}};exports.RouteMap=_e;exports.SurfaceType=le;exports.ThemeProvider=O;exports.theme=S;exports.useMapHeader=Gt;exports.useTheme=h;//# sourceMappingURL=index.cjs.map
|
|
6
6
|
//# sourceMappingURL=index.cjs.map
|