@osrd-project/ui-charts 0.0.68 → 0.0.70
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.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/manchette/consts.d.ts +1 -0
- package/dist/manchette/hooks/useManchetteWithSpaceTimeChart.d.ts +31 -13
- package/dist/manchette/utils/helpers.d.ts +24 -9
- package/dist/spaceTimeChart/components/Quadrilateral.d.ts +19 -0
- package/dist/spaceTimeChart/components/Tooltip.d.ts +7 -0
- package/dist/spaceTimeChart/components/WorkScheduleLayer.d.ts +6 -1
- package/dist/spaceTimeChart/index.d.ts +10 -1
- package/dist/spaceTimeChart/lib/consts.d.ts +0 -17
- package/dist/spaceTimeChart/lib/types.d.ts +1 -1
- package/dist/spaceTimeChart/utils/canvas.d.ts +11 -3
- package/dist/speedSpaceChart/components/SpeedSpaceChart.d.ts +1 -1
- package/dist/speedSpaceChart/components/common/DetailsBox.d.ts +1 -1
- package/dist/speedSpaceChart/components/common/InteractionButtons.d.ts +1 -1
- package/dist/speedSpaceChart/components/common/SettingsPanel.d.ts +1 -1
- package/dist/speedSpaceChart/components/const.d.ts +1 -1
- package/dist/speedSpaceChart/components/helpers/drawElements/axisY.d.ts +1 -1
- package/dist/speedSpaceChart/components/helpers/drawElements/curve.d.ts +1 -1
- package/dist/speedSpaceChart/components/helpers/drawElements/declivity.d.ts +1 -1
- package/dist/speedSpaceChart/components/helpers/drawElements/electricalProfile.d.ts +1 -1
- package/dist/speedSpaceChart/components/helpers/drawElements/powerRestrictions.d.ts +1 -1
- package/dist/speedSpaceChart/components/helpers/drawElements/reticle.d.ts +1 -1
- package/dist/speedSpaceChart/components/helpers/drawElements/speedLimitTags.d.ts +1 -1
- package/dist/speedSpaceChart/components/helpers/drawElements/speedLimits.d.ts +1 -1
- package/dist/speedSpaceChart/components/helpers/drawElements/steps.d.ts +1 -1
- package/dist/speedSpaceChart/components/helpers/drawElements/tickX.d.ts +1 -1
- package/dist/speedSpaceChart/components/helpers/drawElements/tickYRight.d.ts +1 -1
- package/dist/speedSpaceChart/components/helpers/frontFrame.d.ts +1 -1
- package/dist/speedSpaceChart/components/helpers/layersManager.d.ts +1 -1
- package/dist/speedSpaceChart/components/hooks.d.ts +1 -1
- package/dist/speedSpaceChart/components/layers/CurveLayer.d.ts +1 -1
- package/dist/speedSpaceChart/components/layers/DeclivityLayer.d.ts +1 -1
- package/dist/speedSpaceChart/components/layers/ElectricalProfileLayer.d.ts +1 -1
- package/dist/speedSpaceChart/components/layers/FrontInteractivityLayer.d.ts +1 -1
- package/dist/speedSpaceChart/components/layers/PowerRestrictionsLayer.d.ts +1 -1
- package/dist/speedSpaceChart/components/layers/ReticleLayer.d.ts +1 -1
- package/dist/speedSpaceChart/components/layers/SpeedLimitTagsLayer.d.ts +1 -1
- package/dist/speedSpaceChart/components/layers/SpeedLimitsLayer.d.ts +1 -1
- package/dist/speedSpaceChart/components/layers/StepsLayer.d.ts +1 -1
- package/dist/speedSpaceChart/components/layers/TickLayerX.d.ts +1 -1
- package/dist/speedSpaceChart/components/layers/TickLayerY.d.ts +1 -1
- package/dist/speedSpaceChart/components/layers/TickLayerYRight.d.ts +1 -1
- package/dist/speedSpaceChart/components/utils.d.ts +8 -2
- package/dist/speedSpaceChart/index.d.ts +2 -1
- package/dist/speedSpaceChart/{types/chartTypes.d.ts → types.d.ts} +5 -4
- package/dist/theme.css +0 -108
- package/dist/theme.css.map +1 -1
- package/package.json +4 -4
- package/dist/spaceTimeChart/stories/additional-data.stories.d.ts +0 -20
- package/dist/spaceTimeChart/stories/base-rendering.stories.d.ts +0 -28
- package/dist/spaceTimeChart/stories/custom-styles.stories.d.ts +0 -24
- package/dist/spaceTimeChart/stories/horizontal-zoom.stories.d.ts +0 -31
- package/dist/spaceTimeChart/stories/layers.stories.d.ts +0 -9
- package/dist/spaceTimeChart/stories/lib/components.d.ts +0 -15
- package/dist/spaceTimeChart/stories/lib/paths.d.ts +0 -16
- package/dist/spaceTimeChart/stories/lib/utils.d.ts +0 -22
- package/dist/spaceTimeChart/stories/measuring.stories.d.ts +0 -20
- package/dist/spaceTimeChart/stories/options.stories.d.ts +0 -27
- package/dist/spaceTimeChart/stories/paths-interactions.stories.d.ts +0 -24
- package/dist/spaceTimeChart/stories/performances.stories.d.ts +0 -25
- package/dist/spaceTimeChart/stories/rectangle-zoom.stories.d.ts +0 -40
- package/dist/spaceTimeChart/stories/scroll-navigation.stories.d.ts +0 -19
- package/dist/spaceTimeChart/stories/split.stories.d.ts +0 -21
- package/dist/spaceTimeChart/stories/stage-interactions.stories.d.ts +0 -25
- package/dist/spaceTimeChart/stories/work-schedules.stories.d.ts +0 -31
- package/dist/spaceTimeChart/types.d.ts +0 -6
- package/dist/speedSpaceChart/stories/SpeedSpaceChart.stories.d.ts +0 -8
- package/dist/speedSpaceChart/stories/assets/const.d.ts +0 -70
- package/dist/speedSpaceChart/stories/assets/path_properties_PMP_LM.d.ts +0 -2
- package/dist/speedSpaceChart/stories/assets/power_restrictions_PMP_LM.d.ts +0 -7
- package/dist/speedSpaceChart/stories/assets/simulation_PMP_LM.d.ts +0 -2
- package/dist/speedSpaceChart/stories/assets/speed_limit_tags_PMP_LM.d.ts +0 -9
- package/dist/speedSpaceChart/stories/utils.d.ts +0 -5
- package/dist/speedSpaceChart/types/simulationTypes.d.ts +0 -47
package/dist/index.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e,{useState as t,useEffect as i,createContext as o,useRef as n,useCallback as r,useMemo as a,useContext as s,useLayoutEffect as l}from"react";import c from"classnames";import{isEqual as h,identity as d,clamp as m,inRange as p,last as f,sum as u}from"lodash";import g from"chroma-js";import{ZoomOut as x,ZoomIn as y,Iterations as T,Plus as E,Dash as v,KebabHorizontal as w,X as S}from"@osrd-project/ui-icons";import{Checkbox as I}from"@osrd-project/ui-core";import*as R from"d3-selection";import*as P from"d3-zoom";function b(e){const[o,n]=t({width:e?.offsetWidth||1,height:e?.offsetHeight||1});return i((()=>{const t=()=>{const t=e?.offsetWidth||1,i=e?.offsetHeight||1;t===o.width&&i===o.height||n({width:t,height:i})};if(e){const i=new ResizeObserver(t);return i.observe(e),()=>{i.disconnect()}}t()}),[e,o.height,o.width]),o}const M=o(void 0),N=o(void 0),_=o(void 0),A="stop",k=["paths"],O=["background","graduations","paths","overlay","captions"],G={},C={};function L(e){if(C[e])return C[e];const t=`#${e.toString(16).padStart(6,"0")}`.toLowerCase();return G[t]=e,C[e]=t,t}function D(e){return e.toString(16).padStart(2,"0").toLowerCase()}function H(e){return g(e).rgba()}const F="picking",B="rendering";function W(e,o,s){const l=n({}),c=n({}),d=n(k.reduce(((e,t)=>({...e,[t]:new Set})),{})),m=n(O.reduce(((e,t)=>({...e,[t]:new Set})),{})),p=n(o),f=n(null),[u,g]=t(null),x=b(e),y=n(x);i((()=>{y.current=x}),[x]);const T=function(){const[e,o]=t(window.devicePixelRatio||1);return i((()=>{if(!window.matchMedia||!window.devicePixelRatio)return;const e=()=>{o(window.devicePixelRatio)},t=window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`);return t.addEventListener("change",e),()=>{t.removeEventListener("change",e)}}),[e]),e}(),E=r(((e,t)=>{e.resetPickingElements(),k.forEach((i=>{if(t&&!t.has(i))return;const o=c.current[`${F}-${i}`],n=d.current[i];if(o){const{width:t,height:i}=y.current;o.clearRect(0,0,t,i);const r=o.getImageData(0,0,o.canvas.width,o.canvas.height);n.forEach((t=>t(r,e))),o.putImageData(r,0,0)}}))}),[]),v=r(((e,t)=>{O.forEach((i=>{if(t&&!t.has(i))return;const o=c.current[`${B}-${i}`],n=m.current[i];if(o){const{width:t,height:i}=y.current;o.clearRect(0,0,t,i),n.forEach((t=>t(o,e)))}}))}),[]),w=r((()=>{v(p.current),E(p.current),f.current&&(window.cancelAnimationFrame(f.current.frameId),f.current=null)}),[]),S=r((()=>{f.current||(f.current={frameId:window.requestAnimationFrame(w)})}),[]),I=r((({type:e,layer:t,fn:i})=>{if("picking"===e){const e=d.current[t];if(e.has(i))throw new Error("This picking function has already been registered.");e.add(i)}else if("rendering"===e){const e=m.current[t];if(e.has(i))throw new Error("This drawing function has already been registered.");e.add(i)}S()}),[]),R=r((({type:e,layer:t,fn:i})=>{if("picking"===e){const e=d.current[t];if(!e.has(i))throw new Error("This picking function has not been registered.");e.delete(i)}else if("rendering"===e){const e=m.current[t];if(!e.has(i))throw new Error("This drawing function has not been registered.");e.delete(i)}S()}),[]),P=r((()=>async function(e,t,i="#fff"){if(!t.length)throw Error("There must be at least one layer to capture.");const o=e[t[0]],n=o.width,r=o.height,a=document.createElement("CANVAS");a.setAttribute("width",n+""),a.setAttribute("height",r+"");const s=a.getContext("2d");return s.fillStyle=i,s.fillRect(0,0,n,r),t.forEach((t=>{s.drawImage(e[t],0,0,n,r,0,0,n,r)})),new Promise(((e,t)=>{a.toBlob((i=>{i?e(i):t()}),"image/png")}))}(l.current,O.map((e=>`${B}-${e}`)),p.current.theme.background)),[]);i((()=>{if(!e)return;const t=l.current,i=c.current;[...O.map((e=>({layer:e,type:"rendering"}))),...k.map((e=>({layer:e,type:"picking"})))].forEach((({layer:o,type:n})=>{const r=`${n}-${o}`;if(!t[r]){const a=document.createElement("CANVAS"),s=a.getContext("2d");a.classList.add(`layer-${n}-${o}`),a.style.position="absolute",a.style.inset="0",e.appendChild(a),t[r]=a,i[r]=s,"picking"===n&&(a.style.display="none")}}))}),[e]),i((()=>{p.current=o,w()}),[o.fingerprint]),i((()=>{for(const e in l.current){const t=l.current[e],i=c.current[e];t&&(t.style.width=x.width+"px",t.style.height=x.height+"px",t.setAttribute("width",x.width*T+"px"),t.setAttribute("height",x.height*T+"px"),i.setTransform(1,0,0,1,0,0),i.scale(T,T))}w()}),[x,T]),i((()=>{let e=null;k.some((t=>{const i=c.current[`${F}-${t}`];if(i&&s){const[o,n,r,a]=i.getImageData(s.x,s.y,1,1).data;if(255===a){const i=function(e,t,i){return`#${D(e)}${D(t)}${D(i)}`}(o,n,r),a=function(e){return G[e.toLowerCase()]}(i),s=p.current.pickingElements[a];return e={layer:t,element:s},!0}}return!1})),h(e,u)||g(e)}),[s,u]);return{canvasContext:a((()=>({register:I,unregister:R,captureCanvases:P})),[I,R,P]),hoveredItem:u}}function $(e,t){const{register:o,unregister:n}=s(N);i((()=>(o({type:"picking",layer:e,fn:t}),()=>{n({type:"picking",layer:e,fn:t})})),[e,t,o,n])}function U(e,t){const{register:o,unregister:n}=s(N);i((()=>(o({type:"rendering",layer:e,fn:t}),()=>{n({type:"rendering",layer:e,fn:t})})),[e,t,o,n])}function z(e,t,i,[o,n,r],a,s,l=Math.ceil(a/2)){if(t.x>i.x)return z(e,i,t,[o,n,r],a);const c=e.width,h=e.height,d=i.x-t.x,p=i.y-t.y,f=Math.sqrt(d*d+p*p),u=-p/f,g=d/f,x=l,y={x:t.x+(+u-d/f)*x,y:t.y+(+g-p/f)*x},T={x:t.x+(-u-d/f)*x,y:t.y+(-g-p/f)*x},E={x:i.x+(d/f-u)*x,y:i.y+(p/f-g)*x},v={x:i.x+(+u+d/f)*x,y:i.y+(+g+p/f)*x},w=t.y<i.y,S=w?v:y,I=w?y:T,R=w?E:v,P=w?T:E,b=m(Math.floor(I.x),0,c),M=m(Math.ceil(R.x),0,c),N=m(Math.floor(P.y),0,h),_=m(Math.ceil(S.y),0,h);for(let t=N;t<=_;t++){const i=m(t<I.y?Math.floor(P.x+(t-P.y)*(I.x-P.x)/(I.y-P.y)):Math.floor(I.x+(t-I.y)*(I.x-S.x)/(I.y-S.y)),b,M),a=m(t<R.y?Math.ceil(P.x+(t-P.y)*(R.x-P.x)/(R.y-P.y)):Math.ceil(R.x+(t-R.y)*(R.x-S.x)/(R.y-S.y)),b,M);for(let s=i;s<=a;s++){const i=4*(t*c+s);e.data[i+3]||(e.data[i]=o,e.data[i+1]=n,e.data[i+2]=r,e.data[i+3]=255)}}}const X=new Map;function V(e,{x:t,y:i},o,[n,r,a],s){t=Math.round(t),i=Math.round(i),o=Math.ceil(o);const{width:l,height:c}=e,h=function(e){const t=X.get(e);if(t)return t;const i=2*e+1,o=new Uint8Array(i*i);for(let t=-e;t<=e;t++)for(let n=-e;n<=e;n++)n*n+t*t<=e*e&&(o[(t+e)*i+(n+e)]=1);return X.set(e,o),o}(o),d=2*o+1;for(let s=-o;s<=o;s++)for(let m=-o;m<=o;m++){if(1===h[(s+o)*d+(m+o)]){const o=t+m,h=i+s;if(o>=0&&o<l&&h>=0&&h<c){const t=4*(h*l+o);e.data[t]=n,e.data[t+1]=r,e.data[t+2]=a,e.data[t+3]=255}}}}function Y(e,{x:t,y:i},o,n,[r,a,s]){const l=m(t,0,e.width),c=m(i,0,e.height),h=m(t+o,0,e.width),d=m(i+n,0,e.height);for(let t=l;t<h;t++)for(let i=c;i<d;i++){const o=4*(i*e.width+t);e.data[o]=r,e.data[o+1]=a,e.data[o+2]=s,e.data[o+3]=255}}const Z=6;const j=12;function q(e,t,i,o,n,r,a){"out"===a?function(e,t,i,o,n,r){let a="from"===n?-1:1,s=("backward"===r?-1:1)*a,l=t+4*a,c=i+(j-2)*s,h=t,d=i;o&&([a,s]=[s,a],[l,c]=[c,l],[h,d]=[d,h]),e.beginPath(),e.moveTo(h,d),e.bezierCurveTo(l,c,l,c,h+j*a,d+j*s),e.stroke()}(e,t,i,o,n,r):function(e,t,i,o){e.beginPath(),o?(e.moveTo(i-Z/2,t),e.lineTo(i+Z/2,t)):(e.moveTo(t,i-Z/2),e.lineTo(t,i+Z/2)),e.stroke()}(e,t,i,o)}function K(e,t,i,o,n=d){const r={},a=60*new Date(e).getTimezoneOffset()*1e3;return i.forEach(((i,s)=>{const l=o[s];if(!l)return;let c=Math.floor((e-a)/i)*i+a;for(;c<=t;)c>=e&&(r[c]=n(l,s)),c+=i})),r}function Q(e,t,i=window.devicePixelRatio||1){const o=t/2;return Math.round((e-o)*i)/i+o}function J({points:e},t,i){if(e.length<2||!e[t])return"still";const o=e[t].position;let n,r=t;for(;n=e[r];){if(n.position!==o){return(i?o-n.position:n.position-o)>0?"forward":"backward"}r+=i?-1:1}return"still"}function ee(e,t){const i=e(t),o=e(t,!0);return i===o?[i]:[i,o]}const te=()=>(U("graduations",r(((e,{timePixelOffset:t,getSpacePixel:i,operationalPoints:o,swapAxis:n,width:r,height:a,theme:{spaceGraduationsStyles:s}})=>{const l=n?a:r;o.forEach((o=>{const r=s[o.importanceLevel||0];r&&(e.strokeStyle=r.color,e.lineWidth=r.width,e.globalAlpha=r.opacity||1,r.dashArray&&(e.setLineDash(r.dashArray||[]),e.lineDashOffset=-t),ee(i,o.position).forEach((t=>{const i=Q(t,e.lineWidth);e.beginPath(),n?(e.moveTo(i,0),e.lineTo(i,l)):(e.moveTo(0,i),e.lineTo(l,i)),e.stroke()})))})),e.setLineDash([]),e.lineDashOffset=0,e.globalAlpha=1}),[])),null),ie="#2170B9",oe="#B6B2AF",ne="IBM Plex Sans",re=6e4,ae=36e5,se={background:"white",breakpoints:[.2,.4,.8,2.4,12,32,72,1/0],timeRanges:[1e4,3e4,6e4,3e5,9e5,18e5,1*ae,3*ae,6*ae,12*ae,24*ae],pathsStyles:{fontSize:10,fontFamily:ne},spaceGraduationsStyles:{1:{width:.5,color:ie,opacity:.75},2:{width:.5,color:ie,opacity:.25},3:{width:.5,color:"#EDEDED"}},timeCaptionsPriorities:[[0,0,0,0,0,0,0,0,1,1,1],[0,0,0,0,0,0,0,1,1,1,1],[0,0,0,0,0,0,1,1,1,1,1],[0,0,0,0,0,3,1,1,1,1,1],[0,0,0,0,3,1,1,1,1,1,1],[0,0,0,3,2,1,1,1,1,1,1],[0,0,3,2,1,1,1,1,1,1,1],[0,0,3,2,1,1,1,1,1,1,1]],timeCaptionsStyles:{1:{color:"#797671",font:`12px ${ne}`,topOffset:11},2:{color:oe,font:`12px ${ne}`,topOffset:9},3:{color:oe,font:`10px ${ne}`,topOffset:6},4:{color:oe,font:`8px ${ne}`,topOffset:8}},timeGraduationsPriorities:[[0,0,0,0,0,0,0,4,3,2,1],[0,0,0,0,0,0,4,3,3,2,1],[0,0,0,0,0,6,4,3,3,2,1],[0,0,0,0,6,5,4,3,3,2,1],[0,0,0,6,5,4,3,2,2,2,1],[0,0,6,5,4,4,3,2,2,2,1],[0,6,5,4,4,4,3,2,2,2,1],[6,0,5,4,4,4,3,2,2,2,1]],timeGraduationsStyles:{1:{width:.5,color:"#000000"},2:{width:.5,color:ie,opacity:.77},3:{width:.5,color:ie,opacity:.5},4:{width:.5,color:ie,opacity:.5,dashArray:[6,6]},5:{width:.5,color:ie,opacity:.5,dashArray:[6,18]},6:{width:1,color:ie,opacity:.5,dashArray:[1,12]}}},le=e=>`:${new Date(e).getMinutes().toString().padStart(2,"0")}`,ce=(e,t)=>{const i=new Date(e);if(t>1){return`${i.getHours().toString().padStart(2,"0")}:${i.getMinutes().toString().padStart(2,"0")}`}return i.getHours().toString().padStart(2,"0")},he=33,de=[()=>"",()=>"",le,le,le,le,ce,ce,ce,ce,ce],me=()=>(U("captions",r(((e,{timeScale:t,timeOrigin:i,timePixelOffset:o,getTimePixel:n,swapAxis:r,width:a,height:s,theme:{background:l,breakpoints:c,timeRanges:h,timeCaptionsPriorities:d,timeCaptionsStyles:m,timeGraduationsStyles:p},showTicks:f})=>{const u=r?s:a,g=r?a:s,x=i-t*o,y=x+t*a,T=1/t*re;let E=[];c.some(((e,t)=>T<e&&(E=d[t],!0)));const v=K(x,y,h,E,((e,t)=>({level:e,rangeIndex:t})));if(e.fillStyle=l,r?e.fillRect(0,0,he,u):e.fillRect(0,g-he,u,he),e.strokeStyle=p[1].color,e.lineWidth=p[1].width,!f){if(e.beginPath(),r){const t=Q(he,e.lineWidth);e.moveTo(t,0),e.lineTo(t,u)}else{const t=Q(g-he,e.lineWidth);e.moveTo(0,t),e.lineTo(u,t)}e.stroke()}for(const t in v){const{level:i,rangeIndex:o}=v[t],a=m[i],s=(0,de[o])(+t,T);e.textAlign="center",e.textBaseline="top",e.fillStyle=a.color,e.font=`${a.fontWeight||"normal"} ${a.font}`;const l=Q(n(+t),e.lineWidth);r?(e.save(),e.translate(he-(a.topOffset||0),l),e.rotate(Math.PI/2),e.fillText(s,0,0),e.restore()):(f&&(e.strokeStyle=m[1].color,e.moveTo(l,g-he),e.lineTo(l,+t%18e4==0?8:4),e.stroke()),e.fillText(s,l,g-he+(a.topOffset||0)))}}),[])),null),pe=()=>(U("graduations",r(((e,{timeScale:t,timeOrigin:i,timePixelOffset:o,spacePixelOffset:n,getTimePixel:r,swapAxis:a,width:s,height:l,theme:{breakpoints:c,timeRanges:h,timeGraduationsStyles:d,timeGraduationsPriorities:m}})=>{const p=a?s:l,f=i-t*o,u=f+t*(a?l:s),g=1/t*re;let x=[];c.some(((e,t)=>g<e&&(x=m[t],!0)));const y=K(f,u,h,x);for(const t in y){const i=d[y[t]];e.strokeStyle=i.color,e.lineWidth=i.width,e.globalAlpha=i.opacity||1,e.setLineDash(i.dashArray||[]),i.dashArray&&(e.lineDashOffset=-n);const o=Q(r(+t),e.lineWidth);e.beginPath(),a?(e.moveTo(0,o),e.lineTo(p,o)):(e.moveTo(o,0),e.lineTo(o,p)),e.stroke()}e.setLineDash([]),e.lineDashOffset=0,e.globalAlpha=1}),[])),null);function fe(e,t){const i=t.getBoundingClientRect();return{x:e.clientX-i.left,y:e.clientY-i.top}}function ue(e){if(void 0!==e.deltaY)return-3*e.deltaY/360;if(void 0!==e.detail)return e.detail/-9;throw new Error("Could not extract delta from event.")}function ge(e,t,i){e=m(e,t.from,t.to);let o=t;for(;"limit"in o;)o=i?e>=o.limit?o.right:o.left:e<=o.limit?o.left:o.right;return o}function xe(e,t,i){return o=>{const{from:n,pixelFrom:r,coefficient:a}=function(e,t){e=m(e,t.pixelFrom,t.pixelTo);let i=t;for(;"pixelLimit"in i;)i=e<=i.pixelLimit?i.left:i.right;return i}(o-t,i);return e+n+(o-t-r)*a}}function ye(e,t,i){if(t<e)return ye(t,e,i).reverse();e=Math.max(e,i.from),t=Math.min(t,i.to);let o=ge(e,i);const n=[];for(;o.to<t;)n.push(o.to),o=o.next;return n}function Te(e){return"point"===e.type}function Ee(e){return"segment"===e.type}const ve={1:{width:1.5,endWidth:1.5},2:{width:1,endWidth:1},3:{width:1,endWidth:1,dashArray:[5,5],lineCap:"square"},4:{width:1.5,endWidth:1,dashArray:[0,4],lineCap:"round"}},we=2,Se=({path:e,color:t,level:i=2,pickingTolerance:o=5,border:n})=>{const a=r((({getTimePixel:t,getSpacePixel:i,spaceScaleTree:o,timeAxis:n,spaceAxis:r})=>{const a=[];return e.points.forEach((({position:s,time:l},c,h)=>{if(c){const{position:d,time:m}=h[c-1],p=ye(d,s,o);let f=-1/0;p.forEach(((o,h)=>{const u=o===(p[h+1]??1/0),g=f===o?"forward"===J(e,c,!0):!!u&&"backward"===J(e,c-1),x=m+(o-d)/(s-d)*(l-m);a.push({[n]:t(x),[r]:i(o,g)}),f=o})),a.push({[n]:t(l),[r]:i(s)})}else a.push({[n]:t(l),[r]:i(s)})})),a}),[e]),s=r((({getTimePixel:t,getSpacePixel:i,timeAxis:o,spaceAxis:n,operationalPoints:r})=>{const a=[],s=new Set(r.map((e=>e.position)));return e.points.forEach((({position:e,time:r})=>{s.has(e)&&a.push({[o]:t(r),[n]:i(e)})})),a}),[e]),l=r(((t,{getTimePixel:i,getSpacePixel:o,operationalPoints:n,swapAxis:r})=>{const a=new Set(n.map((e=>e.position)));e.points.forEach((({position:e,time:n},s,l)=>{if(s){const{position:c,time:h}=l[s-1];c===e&&a.has(e)&&ee(o,e).forEach((e=>{const o=Q(e,t.lineWidth);t.beginPath(),r?(t.moveTo(o,i(h)),t.lineTo(o,i(n))):(t.moveTo(i(h),o),t.lineTo(i(n),o)),t.stroke()}))}}))}),[e]),c=r(((e,{width:t,height:i,swapAxis:o,theme:{background:n,pathsStyles:{fontSize:r,fontFamily:a}}},s,l,c,h)=>{if(!s)return;const d=c.findIndex((({x:e,y:n})=>o?p(e,he,t)&&p(n,0,i):p(e,0,t)&&p(n,0,i-he)));if(d<0)return;const m=c[d-1],f=c[d],u=c[d+1];let g=f,x=0;if(0===d)u&&(x=Math.atan2(u.y-f.y,u.x-f.x));else{const e=(f.y-m.y)/(f.x-m.x),t=f.y-f.x*e,i=f.x-f.y/e;g=t>=0?{x:0,y:t}:{x:i+10/e,y:10},x=Math.atan2(f.y-m.y,f.x-m.x)}e.save(),e.translate(g.x,g.y),e.rotate(x),e.font=`${r}px ${a}`,e.textAlign="start";const y=e.measureText(s),T=y.width+4,E=y.actualBoundingBoxAscent+y.actualBoundingBoxDescent+4,v=T<h?5:(h-T)/2,w=x>=0?-5:15;e.globalAlpha=.75,e.fillStyle=n,e.fillRect(v-2,w-E+2,T,E),e.fillStyle=l,e.globalAlpha=1,e.fillText(s,v,w),e.restore()}),[]),h=r(((t,{getTimePixel:i,getSpacePixel:o,swapAxis:n})=>{if(!e.points.length)return;const r=e.points[0],a=e.fromEnd||A,s=f(e.points),l=e.toEnd||A;q(t,i(r.time),o(r.position),n,"from",J(e,0),a),q(t,i(s.time),o(s.position),n,"to",J(e,e.points.length-1,!0),l)}),[e]),d=r(((t,i)=>{let o=0;const n=new Set(t.map((e=>e.position)));return e.points.forEach((({position:e,time:t},i,r)=>{if(i>0){const{position:a,time:s}=r[i-1];a===e&&n.has(e)&&(o+=t-s)}})),i.forEach((({x:e,y:t},i,n)=>{if(i>0){const{x:r,y:a}=n[i-1];o+=Math.sqrt(Math.pow(r-e,2)+Math.pow(a-t,2))}})),o}),[e]),m=r(((e,t)=>{if(!n)return;const o=n.width||1,r=ve[i],s=2*n.offset+r.width,l=n.backgroundColor||"#fff",c=a(t);e.save(),e.beginPath();const h=(t,i=n.color)=>{e.strokeStyle=i,e.lineWidth=t,e.lineCap="round",c.forEach((({x:t,y:i},o)=>{t===c[o-1]?.x&&i===c[o-1]?.y||(0===o?e.moveTo(t,i):e.lineTo(t,i))})),e.stroke()};h(s+2*o),h(s,l),e.restore()}),[n,a,i]);U("paths",r(((o,n)=>{m(o,n),o.strokeStyle=t,o.lineWidth=7,o.globalAlpha=.2,o.lineCap="round",l(o,n);const r=ve[i];o.strokeStyle=t,o.lineWidth=r.width,o.setLineDash(r.dashArray||[]),o.globalAlpha=r.opacity||1,o.lineCap=r.lineCap||"square",o.beginPath();const s=a(n);if(s.forEach((({x:e,y:t},i)=>{i?o.lineTo(e,t):o.moveTo(e,t)})),o.stroke(),o.setLineDash([]),o.lineWidth=r.endWidth,h(o,n),!n.hidePathsLabels){const i=d(n.operationalPoints,s);c(o,n,e.label,t,s,i)}}),[t,l,i,a,h,d,c,m,e.label]));return $("paths",r(((t,n)=>{const{registerPickingElement:r}=n;a(n).forEach(((n,a,s)=>{if(a){const l=s[a-1],c={type:"segment",pathId:e.id,from:l,to:n},h=H(L(r(c)));z(t,l,n,h,ve[i].width+o)}})),s(n).forEach((n=>{const a={type:"point",pathId:e.id,point:n},s=H(L(r(a)));V(t,n,2*(ve[i].width+o),s)}))}),[a,s,i,e.id,o])),null};const Ie=o=>{const{operationalPoints:s,spaceOrigin:l,spaceScales:h,timeOrigin:d,timeScale:m,xOffset:p=0,yOffset:f=0,swapAxis:u,onHoveredChildUpdate:g,children:x,enableSnapping:y,hideGrid:T,hidePathsLabels:E,showTicks:v,theme:w,onPan:S,onZoom:I,onClick:R,onMouseMove:P,...A}=o,[k,O]=t(null),[G,C]=t(null),L=a((()=>({...se,...w})),[w]),{width:D,height:H}=b(k),F=a((()=>JSON.stringify({operationalPoints:s,width:D,height:H,spaceOrigin:l,spaceScales:h,timeOrigin:d,timeScale:m,xOffset:p,yOffset:f,swapAxis:u,hideGrid:T,hidePathsLabels:E,showTicks:v})),[s,D,H,l,h,d,m,p,f,u,T,E,v]),B=a((()=>{const e=function(e,t){let i=e;if(t.some((e=>e.to<i||(i=e.to,!1))))throw new Error("Invalid scale: 'to' must be greater than previous 'to'.");if(t.some((e=>("size"in e?e.size:e.coefficient)<=0)))throw new Error("Invalid scale: 'to' must be greater than 'from'.");const o=[];let n=0;i=e;for(let e=0;e<t.length;e++){const r=t[e],a="coefficient"in r?r.coefficient:(r.to-i)/r.size,s="coefficient"in r?(r.to-i)/r.coefficient:r.size;o.push({from:i,to:r.to,pixelFrom:n,pixelTo:n+s,coefficient:a}),n+=s,i=r.to,e&&(o[e].previous=o[e-1],o[e-1].next=o[e])}return function e(t){if(0===t.length)return{coefficient:1,from:-1/0,to:1/0,pixelFrom:-1/0,pixelTo:1/0};if(1===t.length)return t[0];{const i=Math.ceil(t.length/2);return{limit:t[i-1].to,pixelLimit:t[i-1].pixelTo,from:t[0].from,to:t[t.length-1].to,pixelFrom:t[0].pixelFrom,pixelTo:t[t.length-1].pixelTo,left:e(t.slice(0,i)),right:e(t.slice(i))}}}(o)}(l,h),t=u?"y":"x",i=u?"x":"y";let o,n;u?(o=f,n=p):(o=p,n=f);const r=function(e,t,i){return o=>t+(o-e)/i}(d,o,m),a=(c=n,g=e,(e,t)=>{const{from:i,pixelFrom:o,coefficient:n}=ge(e,g,t);return c+o+(e-i)/n});var c,g;const x=function(e,t,i,o){return({time:n,position:r})=>({[i]:e(n),[o]:t(r)})}(r,a,t,i),w=function(e,t,i){return o=>(o-t)*i+e}(d,o,m),S=xe(l,n,e),I=function(e,t,i,o){return n=>({time:e(n[i]),position:t(n[o])})}(w,S,t,i),R=[];return{fingerprint:F,width:D,height:H,getTimePixel:r,getSpacePixel:a,getPoint:x,getTime:w,getSpace:S,getData:I,pickingElements:R,resetPickingElements:()=>{R.length=0},registerPickingElement:e=>(R.push(e),R.length-1),operationalPoints:s,spaceOrigin:l,spaceScaleTree:e,timeOrigin:d,timeScale:m,timePixelOffset:o,spacePixelOffset:n,timeAxis:t,spaceAxis:i,swapAxis:!!u,enableSnapping:!!y,hideGrid:!!T,hidePathsLabels:!!E,showTicks:!!v,theme:L}}),[F]),$=function(e){const[o,n]=t({isHover:!1,position:{x:NaN,y:NaN}}),a=r((t=>{e&&n((e=>({...e,down:{ctrl:t.ctrlKey,shift:t.shiftKey}})))}),[e]),s=r((()=>{e&&n((e=>({...e,down:void 0})))}),[e]),l=r((t=>{if(!e)return;const i=fe(t,e),{x:o,y:r}=i,a=e.offsetWidth,s=e.offsetHeight,l=o>=0&&o<=a&&r>=0&&r<=s;n((e=>({...e,position:i,isHover:l})))}),[e]);return i((()=>{if(e)return e.addEventListener("mousedown",a),()=>{e.removeEventListener("mousedown",a)}}),[e,a]),i((()=>(document.addEventListener("mouseup",s),()=>{document.removeEventListener("mouseup",s)})),[s]),i((()=>(document.addEventListener("mousemove",l),()=>{document.removeEventListener("mousemove",l)})),[l]),o}(k),{position:U,down:z,isHover:X}=$,{canvasContext:V,hoveredItem:Y}=W(G,B,U),Z=a((()=>{const e=y?function(e,t){return e&&t?Te(t.element)?t.element.point:Ee(t.element)?function(e,t,i){const{x:o,y:n}=e,{x:r,y:a}=t,{x:s,y:l}=i,c=s-r,h=l-a,d=c*c+h*h;if(0===d)return{x:r,y:a};let m=((o-r)*c+(n-a)*h)/d;return m<0?m=0:m>1&&(m=1),{x:r+m*c,y:a+m*h}}(e,t.element.from,t.element.to):e:e}($.position,Y):$.position;return{down:z,isHover:X,position:e,hoveredItem:Y,data:B.getData(e)}}),[y,$.position,Y,z,X,B]);return function(e,{position:o,hoveredItem:a,down:s,isHover:l},c,h){const d=n(h),m=n(c),[p,f]=t({type:"idle"});i((()=>{d.current=h}),[h.fingerprint]),i((()=>{m.current=c}),[c]);const u=r((t=>{if(!e)return;const{onClick:i}=m.current;i&&i({event:t,position:o,data:d.current.getData(o),hoveredItem:a,context:d.current})}),[e,a,o]),g=r((t=>{const{onZoom:i}=m.current;i&&e&&i({delta:ue(t),position:fe(t,e),event:t,context:d.current})}),[e]);i((()=>{if(e)return e.addEventListener("click",u),()=>{e.removeEventListener("click",u)}}),[e,u]),i((()=>{if(e)return e.addEventListener("wheel",g),()=>{e.removeEventListener("wheel",g)}}),[e,g]),i((()=>{const{onPan:e}=m.current;s?f({type:"panning",initialPosition:o,initialData:d.current.getData(o)}):("panning"===p.type&&e&&e({isPanning:!1,position:o,initialPosition:p.initialPosition,data:d.current.getData(o),initialData:p.initialData,context:d.current}),"idle"!==p.type&&f({type:"idle"}))}),[s]),i((()=>{const{onPan:e,onMouseMove:t}=m.current;t&&t({position:o,isHover:l,data:d.current.getData(o),hoveredItem:a,context:d.current}),"panning"===p.type&&e&&e({isPanning:!0,position:o,initialPosition:p.initialPosition,data:d.current.getData(o),initialData:p.initialData,context:d.current})}),[o.x,o.y])}(k,Z,{onPan:S,onZoom:I,onClick:R,onMouseMove:P},B),i((()=>{g&&g({item:Y,context:B})}),[Y]),i((()=>{!function({breakpoints:e,timeRanges:t,timeCaptionsStyles:i,timeCaptionsPriorities:o,timeGraduationsStyles:n,timeGraduationsPriorities:r}){const a="SpaceTimeChartTheme is invalid:",s=e.length,l=t.length,c=new Set(o.flatMap((e=>e))),h=new Set(r.flatMap((e=>e)));if(o.length!==s)throw new Error(`${a}: timeCaptionsPriorities should have as much elements as breakpoints.`);if(o.some((e=>e.length!==l)))throw new Error(`${a}: each array in timeCaptionsPriorities should have as much elements as timeRanges.`);if(Array.from(c).some((e=>0!==e&&!i[e])))throw new Error(`${a}: all values (except 0s) from timeCaptionsPriorities should have a matching style in timeCaptionsStyles.`);if(r.length!==s)throw new Error(`${a}: timeGraduationsPriorities should have as much elements as breakpoints.`);if(r.some((e=>e.length!==l)))throw new Error(`${a}: each array in timeGraduationsPriorities should have as much elements as timeRanges.`);if(Array.from(h).some((e=>0!==e&&!n[e])))throw new Error(`${a}: all values (except 0s) from timeGraduationsPriorities should have a matching style in timeGraduationsStyles.`);if(!n[1])throw new Error(`${a}: there should be a timeGraduationsStyles for value 1.`)}(L)}),[L]),e.createElement("div",{...A,ref:O,className:c("relative space-time-chart",A.className),style:{background:L.background}},e.createElement("div",{ref:C,className:"absolute inset-0"}),e.createElement(M.Provider,{value:B},e.createElement(N.Provider,{value:V},e.createElement(_.Provider,{value:Z},!T&&e.createElement(e.Fragment,null,e.createElement(te,null),e.createElement(pe,null),e.createElement(me,null)),x))))};function Re(e){return"conflict"===e.type}const Pe=[{opacity:.33,color:"#d91c1c",size:8},{opacity:.5,color:"#ff6868",size:4},{opacity:1,color:"#6b0000",size:0}],be=({conflicts:e})=>{U("paths",r(((t,{getTimePixel:i,getSpacePixel:o})=>{const n=Pe.map((()=>new Path2D));for(const t of e){const e=i(t.timeStart),r=o(t.spaceStart),a=i(t.timeEnd)-e,s=o(t.spaceEnd)-r;for(let t=0;t<Pe.length;t++){const i=Pe[t].size;n[t].rect(e-i,r-i,a+2*i,s+2*i)}}for(let e=0;e<Pe.length;e++)t.fillStyle=Pe[e].color,t.globalAlpha=Pe[e].opacity,t.fill(n[e])}),[e]));return $("paths",r(((t,{registerPickingElement:i,getTimePixel:o,getSpacePixel:n})=>{for(const[r,a]of e.entries()){const e=o(a.timeStart),s=n(a.spaceStart),l=o(a.timeEnd)-e,c=n(a.spaceEnd)-s,h=Pe[0].size;Y(t,{x:e-h,y:s-h},l+2*h,c+2*h,H(L(i({type:"conflict",conflictIndex:r}))))}}),[e])),null},Me=e=>(e/1e3).toLocaleString("en-US",{minimumFractionDigits:1,maximumFractionDigits:1}),Ne=({position:t,time:i,spaceStart:o,spaceEnd:n,timeStart:r,timeEnd:a,type:s,trains:l})=>e.createElement("div",{className:"spacetimechart-tooltip",style:{left:t.x,top:t.y}},e.createElement("div",{className:"time"},new Date(i).toLocaleTimeString()),e.createElement("div",{className:"position-range"},e.createElement("div",{className:"start-position"},Me(o)),e.createElement("div",{className:"end-position"},Me(n))),e.createElement("div",{className:"type-and-duration"},e.createElement("div",null,s),e.createElement("div",null,Math.round((a-r)/1e3),"s")),e.createElement("div",{className:"trains"},l.join(", "))),_e=({occupancyBlocks:e})=>(U("background",r(((t,{getTimePixel:i,getSpacePixel:o})=>{for(const n of e){const e=i(n.timeStart),r=o(n.spaceStart),a=i(n.timeEnd)-e,s=o(n.spaceEnd)-r;t.fillStyle=n.color,t.fillRect(e,r,a,s)}}),[e])),null),Ae=({imageElement:e,...t})=>(U("background",r(((i,o)=>{const n=i.createPattern(e,"repeat");n&&(i.fillStyle=n,function(e,t,i){const{getTimePixel:o,getSpacePixel:n,timeAxis:r}=i,{timeStart:a,timeEnd:s,spaceStart:l,spaceEnd:c}=t,h=o(Number(a)),d=o(Number(s)),m=n(l),p=n(c)-m,f=d-h;p&&f&&("x"===r?(e.translate(h,m),e.fillRect(0,0,f,p)):(e.translate(m,h),e.fillRect(0,0,p,f)))}(i,t,o))}),[e,t])),null),ke=({workSchedules:o,imageUrl:n})=>{const[r,a]=t();return i((()=>{if(n){const e=new Image;e.src=n,e.onload=()=>{a(e)}}}),[n]),r?o.flatMap((t=>t.spaceRanges.map((([i,o])=>e.createElement(Ae,{key:`${t.type}-${t.timeStart}-${t.timeEnd}-${i}-${o}`,timeStart:t.timeStart,timeEnd:t.timeEnd,spaceStart:i,spaceEnd:o,imageElement:r}))))):null},Oe=32,Ge=6e5,Ce=7500,Le=e=>e-40-Oe,De=e=>e.at(-1).position-e.at(0).position;const He=({waypoint:{name:t,secondaryCode:i,id:o,position:n,onClick:r},nameRef:a,isActive:s,isMenuActive:l})=>e.createElement("div",{className:c("flex waypoint items-baseline",{"waypoint-active":s,"menu-active":l}),id:o,onClick:()=>{r&&!l&&r(o)}},e.createElement("div",{className:"waypoint-position justify-self-start text-end"},(e=>Math.round(e/1e6*10)/10)(n)),e.createElement("div",{ref:a,className:"waypoint-name mx-2 justify-self-start"},t),e.createElement("div",{className:"waypoint-separator"}),e.createElement("div",{className:"waypoint-ch font-mono justify-self-end"},i),e.createElement("div",{className:"waypoint-separator"}),e.createElement("div",{className:"waypoint-type"}),e.createElement("div",{className:"waypoint-separator"})),Fe=({contents:t,activeWaypointId:i,activeWaypointRef:o})=>e.createElement("div",{className:"waypoint-list"},t.map(((t,n)=>{return null!=(r=t)&&"object"==typeof r&&"id"in r&&"position"in r?e.createElement("div",{key:t.id,className:"waypoint-wrapper flex justify-start",style:t.styles},e.createElement(He,{waypoint:t,nameRef:i===t.id?o:void 0,isActive:i===t.id,isMenuActive:!!i})):e.createElement("div",{key:n},t);var r}))),Be=({zoomYIn:i,zoomYOut:o,resetZoom:r,yZoom:a=1,contents:s,waypointMenuData:h,isProportional:d=!0,toggleMode:m,children:p,height:f=521})=>{const[u,g]=t(),T=n(null);return l((()=>{const e=h?.manchetteWrapperRef?.current?.getBoundingClientRect().top,t=T?.current?.getBoundingClientRect().top;g(e&&t?t-e:void 0)}),[h]),e.createElement("div",{className:"manchette-container"},h?.menu&&h.activeWaypointId&&e.createElement("div",{className:"menu-wrapper",style:{top:u}},h.menu),e.createElement("div",{className:"bg-white-100 border-r border-grey-30",style:{minHeight:`${f}px`}},e.createElement(Fe,{contents:s,activeWaypointId:h?.activeWaypointId,activeWaypointRef:T}),p),e.createElement("div",{className:"manchette-actions"},e.createElement("div",{className:"zoom-buttons"},e.createElement("button",{className:"zoom-out",onClick:o,disabled:a<=1||!!h?.activeWaypointId},e.createElement(x,null)),e.createElement("button",{className:"zoom-in",onClick:i,disabled:a>=10.5||!!h?.activeWaypointId},e.createElement(y,null)),e.createElement("button",{disabled:!!h?.activeWaypointId,className:"zoom-reset",onClick:r},"Fit")),e.createElement("div",{className:"flex items-center ml-auto text-sans font-semibold"},e.createElement("button",{disabled:!!h?.activeWaypointId,className:"toggle-mode",onClick:m},e.createElement("div",{className:"flex flex-col items-end pr-2"},e.createElement("span",{className:c({"text-grey-30":!d})},"Km"),e.createElement("span",{className:c({"text-grey-30":d})},"Linéaire"))))))},We=(e,{height:t,isProportional:i,yZoom:o})=>{if(e.length<2)return[];const n=De(e),r=Le(t);if(!i)return e.map(((t,i)=>{const n=e.at(i+1);return{...t,styles:{height:Oe*(n?o:1)+"px"}}}));const a=((e,t,i,o)=>{const n=e=>e.position/t*i,r=e.at(0),a=e.at(-1);if(!r||!a)return e;const s=[...e].sort(((e,t)=>(t.weight??0)-(e.weight??0))),l=[r,a];for(const e of s)!l.some((t=>Math.abs(n(e)-n(t))<o))&&l.push(e);return l.sort(((e,t)=>e.position-t.position))})(e,n,r,Oe/o);return a.map(((e,t)=>{const i=a.at(t+1);return{...e,styles:{height:i?(i.position-e.position)/n*r*o+"px":"32px"}}}))},$e=e=>Ge*Math.pow(.0010416666666666667,e/100),Ue=e=>100*Math.log(e/Ge)/Math.log(.0010416666666666667),ze=(e,t,i,o)=>{const n=m(i,0,100);return{xZoom:n,xOffset:o-(o-t)*$e(e)/$e(n)}},Xe=(e,o,n,s,l=561,c)=>{const[h,d]=t(!1),[m,p]=t({xZoom:Ue(7500),yZoom:1,xOffset:0,yOffset:0,scrollTo:null,panning:null,isProportional:!0,waypointsChart:[],scales:[]}),{xZoom:f,yZoom:u,xOffset:g,yOffset:x,scrollTo:y,panning:T,isProportional:E}=m,v=((e,t)=>a((()=>e.flatMap((e=>e.spaceTimeCurves.map(((i,o)=>{return{id:`${e.id}-${o}`,label:e.name,color:"#8A714B",level:t&&t===e.id?1:2,points:(n=i,r=e.departureTime,n.positions.map(((e,t)=>({time:n.times[t]+r.getTime(),position:e}))))};var n,r}))))),[e,t]))(o,s),w=a((()=>We(e,{height:l,isProportional:E,yZoom:u})),[e,l,E,u]),S=a((()=>w.map((e=>({id:e.id,label:e.id,position:e.position,importanceLevel:1})))),[w]),I=r((()=>{if(u<10.5){const e=u+.5,t=x*(e/u);p((i=>({...i,yZoom:e,yOffset:t,scrollTo:t})))}}),[u,x]),R=r((()=>{if(u>1){const e=u-.5,t=x*(e/u);p((i=>({...i,yZoom:e,yOffset:t,scrollTo:t})))}}),[u,x]);i((()=>{null!==y&&n.current&&n.current.scrollTo({top:y,behavior:"instant"})}),[y,n]);const P=r((()=>{p((e=>({...e,yZoom:1})))}),[]),b=r((()=>{if(!h&&n.current){const{scrollTop:e}=n.current;(e||0===e)&&p((t=>({...t,yOffset:e})))}}),[h,n]),M=r((e=>{"Shift"===e.key&&d(!0)}),[]),N=r((e=>{"Shift"===e.key&&d(!1)}),[]);i((()=>(window.addEventListener("keydown",M),window.addEventListener("keyup",N),()=>{window.removeEventListener("keydown",M),window.removeEventListener("keyup",N)})),[M,N]);const _=r((()=>{p((e=>({...e,isProportional:!e.isProportional})))}),[]),A=a((()=>((e,{height:t,isProportional:i,yZoom:o})=>{if(e.length<2)return[];if(!i)return e.slice(0,-1).map(((t,i)=>{const n=e[i+1];return{from:t.position,to:n.position,size:Oe*o}}));const n=e.at(0).position,r=e.at(-1).position,a=De(e),s=Le(t);return[{from:n,to:r,...i?{coefficient:a/s/o}:{size:Oe*(e.length-1)*o}}]})(S,{height:l,isProportional:E,yZoom:u})),[S,l,E,u]),k=a((()=>({contents:w,zoomYIn:I,zoomYOut:R,resetZoom:P,toggleMode:_,yZoom:u,isProportional:E,yOffset:x})),[w,I,R,P,_,u,E,x]),O=r(((e,t=(c?.current?.offsetWidth||0)/2)=>{p((i=>({...i,...ze(i.xZoom,i.xOffset,e,t)})))}),[c]),G=a((()=>({operationalPoints:S,spaceScales:A,timeScale:$e(f),paths:v,xOffset:g,yOffset:14-x,onZoom:({delta:e,position:t})=>{h&&O(f+e,t.x)},onPan:e=>{const t=(i=e.initialPosition,{x:(o=e.position).x-i.x,y:o.y-i.y});var i,o;const r={...m};if(e.isPanning)if(T){const{initialOffset:e}=T;r.xOffset=e.x+t.x;const i=e.y-t.y;n.current&&i>=0&&i+n.current.offsetHeight<n.current.scrollHeight&&(r.yOffset=i,n.current.scrollTop=i)}else r.panning={initialOffset:{x:g,y:x}};else r.panning=null;p(r)}})),[S,A,f,v,g,h,m,T,x,n,O]);return a((()=>({manchetteProps:k,spaceTimeChartProps:G,handleScroll:b,handleXZoom:O,xZoom:f})),[k,G,b,O,f])},Ve=({waypoints:t,projectPathTrainResult:i,selectedTrain:o,height:r=561,children:a,header:s,manchetteProps:l,spaceTimeChartProps:c})=>{const h=n(null),d=n(null),{manchetteProps:m,spaceTimeChartProps:p,handleScroll:f}=Xe(t,i,h,o,r,d);return e.createElement("div",{className:"manchette-space-time-chart-wrapper"},e.createElement("div",{className:"header bg-ambientB-5 w-full border-b border-grey-30",style:{height:"40px"}},s),e.createElement("div",{ref:h,className:"manchette flex",style:{height:`${r}px`},onScroll:f},e.createElement(Be,{...m,...l}),e.createElement("div",{className:"space-time-chart-container w-full sticky",ref:d,style:{bottom:0,left:0,top:2,height:r-6+"px"}},e.createElement(Ie,{className:"inset-0 absolute h-full",spaceOrigin:0,timeOrigin:Math.min(...i.map((e=>+e.departureTime))),...p,...c},p.paths.map((t=>e.createElement(Se,{key:t.id,path:t,color:t.color,level:t.level}))),a))))},Ye=({reset:t,openSettingsPanel:i,store:o})=>e.createElement("div",{id:"interaction-button-container",className:"z-10"},e.createElement("div",{className:"zoom-buttons"},e.createElement("button",{className:c("interaction-button reset-button",{inactive:1==o.ratioX&&0==o.leftOffset}),onClick:()=>t()},e.createElement(T,null)),e.createElement("button",{className:"interaction-button plus-button inactive"},e.createElement(E,null)),e.createElement("button",{className:"interaction-button inactive"},e.createElement(v,null))),e.createElement("button",{className:"interaction-button elipsis-button",onClick:()=>i()},e.createElement(w,null))),Ze={Y_LEFT_VERTICAL:30,Y_LEFT_HORIZONTAL:22,Y_RIGHT_VERTICAL:36,Y_RIGHT_HORIZONTAL:42},je={MARGIN_LEFT:48,MARGIN_RIGHT:12,MARGIN_TOP:27,MARGIN_BOTTOM:52.5,CURVE_MARGIN_TOP:40,CURVE_MARGIN_SIDES:16,ELECTRICAL_PROFILES_MARGIN_TOP:8,RIGHT_TICK_MARGINS:60,OFFSET_RIGHT_AXIS:42},qe={ELECTRICAL_PROFILES_HEIGHT:56,POWER_RESTRICTIONS_HEIGHT:40,SPEED_LIMIT_TAGS_HEIGHT:40},Ke={electricalProfiles:qe.ELECTRICAL_PROFILES_HEIGHT,powerRestrictions:qe.POWER_RESTRICTIONS_HEIGHT},Qe="rgb(250, 249, 245)",Je="rgb(247, 246, 238)",et="rgb(242, 240, 228)",tt="#front-interactivity-layer",it=["energySource","tractionStatus","declivities","electricalProfiles","powerRestrictions"],ot=["steps","declivities","speedLimits","electricalProfiles","powerRestrictions","speedLimitTags"],nt=g(0,0,0),rt=g(255,104,104),at=g(217,28,28),st=g(121,118,113),lt=g(49,46,43),ct=g(33,112,185),ht=g(234,167,43),dt=g(255,255,255),mt={"#216482":"#E5F7FF","#D91C1C":"#F15981","#494641":"#F2F0E4","#EAA72B":"#EAA72B","#94918E":"#94918E"},pt=e=>e.layersDisplay.speedLimits&&e.mrsp?Math.max(...e.mrsp.values.map((({speed:e})=>e))):Math.max(...e.speeds.map((({value:e})=>e))),ft=e=>0===e.length?0:e[e.length-1].position.start,ut=(e,t,i)=>{e.clearRect(0,0,t,i)},gt=(e,t,i=!0)=>{const o=[t.electricalProfiles?qe.ELECTRICAL_PROFILES_HEIGHT:0,t.powerRestrictions?qe.POWER_RESTRICTIONS_HEIGHT:0,t.speedLimitTags?qe.SPEED_LIMIT_TAGS_HEIGHT:0].reduce(((e,t)=>e+t),0);return e+(i?o:-o)},xt=(e,t,i=!1)=>{let o=0;const{electricalProfiles:n,powerRestrictions:r}=t;return n&&(o=Ke.electricalProfiles),r&&i&&(o+=Ke.powerRestrictions),e+o-je.MARGIN_BOTTOM},yt=(e,t,i,o,n)=>e*((i-n.CURVE_MARGIN_SIDES-n.MARGIN_LEFT-n.MARGIN_RIGHT)/t)*o+n.MARGIN_LEFT+n.CURVE_MARGIN_SIDES/2,Tt=(e,t,i,o,n)=>{const{MARGIN_LEFT:r,MARGIN_RIGHT:a}=i;e.beginPath(),e.strokeStyle=t,e.lineWidth=1,e.moveTo(r,n),e.lineTo(o-a,n),e.stroke()},Et=(e,t,i,o,n,r)=>{const{MARGIN_LEFT:a,MARGIN_RIGHT:s}=i;e.beginPath(),e.fillStyle=t,e.fillRect(a,n-r+1,o-a-s,r)},vt=(e,t)=>"speedLimits"===t?e.mrsp:"electricalProfiles"===t?e.electricalProfiles:"powerRestrictions"===t?e.powerRestrictions:"speedLimitTags"!==t||e.speedLimitTags,wt=e=>{const t=e.slopes,i=Math.min(...t.map((({value:e})=>e))),o=Math.max(...t.map((({value:e})=>e)));return{minGradient:i,maxGradient:o,slopesRange:o-i,maxPosition:Math.max(...t.map((({position:e})=>e.start)))}},St=e=>new Promise(((t,i)=>{const o=new Image;o.onload=()=>t(o),o.onerror=e=>i(e),o.src=e})),It=e=>{const t=new Blob([e],{type:"image/svg+xml"});return URL.createObjectURL(t)},Rt=(e,t,i)=>{if(0===e.length)return-1;if(t<i(e[0]))return 0;if(t>i(e[e.length-1]))return e.length-1;let o=0,n=e.length;for(;o<n;){const r=Math.floor((o+n)/2);i(e[r])<t?o=r+1:n=r}return t!==i(e[o])&&o--,o},Pt=(e,t,i,o,n=0)=>e/t*((i-je.MARGIN_LEFT-je.MARGIN_RIGHT-je.CURVE_MARGIN_SIDES)*o)+(je.CURVE_MARGIN_SIDES/2+je.MARGIN_LEFT+n),bt=(e,t,i,o,n)=>e===i?t:t+(o-t)/(i-e)*(n-e),Mt=(e,t,i,o,n=8)=>{const r=(({elements:e,getPosition:t,getWeight:i,minSpace:o})=>{const n=[...e].sort(((e,t)=>(i(t)??0)-(i(e)??0))),r=[];for(const e of n){const i=t(e);!r.some((e=>Math.abs(i-e.position)<o))&&r.push({element:e,position:i})}return r.sort(((e,i)=>t(e.element)-t(i.element))).map((({element:e})=>e))})({elements:e,getPosition:e=>Pt(e.position.start,o,i,t),getWeight:e=>e.value.weight,minSpace:n});return r},Nt=(e,t,i)=>{const{ratioX:o,leftOffset:n}=i,r=ft(i.speeds);return(e-n-je.CURVE_MARGIN_SIDES/2)*r/((t-je.MARGIN_LEFT-je.MARGIN_RIGHT-je.CURVE_MARGIN_SIDES)*o)},_t=(e,t,i)=>{const{ratioX:o,leftOffset:n,stops:r}=i,a=ft(i.speeds),s=Mt(r,o,t,a);let l=0;if(s.length>1){const o=(c=Nt(e,t,i),h=0,d=a,Math.min(Math.max(c,h),d)),n=Rt(s,o,(e=>e.position.start)),r=Math.min(n+1,s.length-1);l=o-s[n].position.start<s[r].position.start-o?n:r}else{if(1!==s.length)return null;l=0}var c,h,d;const m=s[l].position.start,p=Pt(m,a,t,o,n);return Math.abs(p-(e+je.MARGIN_LEFT))<6?s[l]:null},At=({globalHeight:o,color:n,store:r,setStore:a,setIsMouseHoveringSettingsPanel:s,translations:l})=>{const[c,h]=t("442px");return i((()=>{const e=gt(0,r.layersDisplay);o<521.5+e&&h(o-e-79.5+"px")}),[o,r.layersDisplay]),e.createElement("div",{id:"settings-panel",style:{background:`rgba(${n.substring(4,n.length-1)}, 0.4)`,height:c},className:"font-sans",onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1)},e.createElement("div",{className:"settings-panel-section"},e.createElement("div",{className:"settings-panel-section-title"},e.createElement("span",null,l?.layersDisplay.context||"Context")),ot.map((t=>e.createElement("div",{key:t,className:"selection"},e.createElement(I,{label:l?.layersDisplay[t]||t,checked:r.layersDisplay[t],disabled:!vt(r,t),onChange:()=>{a((e=>({...e,layersDisplay:{...e.layersDisplay,[t]:!e.layersDisplay[t]}})))}}))))),e.createElement("div",{className:"settings-panel-section right"},e.createElement("div",{className:"settings-panel-section-title"},e.createElement("span",null,l?.detailsBoxDisplay.reticleInfos||"Reticle infos")),it.map((t=>e.createElement("div",{key:t,className:"selection"},e.createElement(I,{label:l?.detailsBoxDisplay[t]||t,checked:r.detailsBoxDisplay[t],onChange:()=>{a((e=>({...e,detailsBoxDisplay:{...e.detailsBoxDisplay,[t]:!e.detailsBoxDisplay[t]}})))}}))))),e.createElement("button",{id:"close-settings-panel",onClick:()=>(s(!1),void a((e=>({...e,isSettingsPanelOpened:!1}))))},e.createElement("span",null,e.createElement(S,null))))},kt=()=>P.zoom().transform(R.select(tt),P.zoomIdentity),{MARGIN_LEFT:Ot,MARGIN_RIGHT:Gt,MARGIN_TOP:Ct,MARGIN_BOTTOM:Lt}=je,Dt=({ctx:e,width:t,height:i,store:o})=>{const{stops:n,ratioX:r,leftOffset:a,cursor:s}=o;if(0===n.length)return;ut(e,t,i);const l=ft(o.speeds),c=Mt(n,r,t,l);e.save(),e.translate(a,0),e.strokeStyle=ct.alpha(.5).hex(),e.lineWidth=1,e.lineCap="round",e.setLineDash([1,6]),e.beginPath(),c.forEach((({position:o})=>{const n=Pt(o.start,l,t,r);e.moveTo(n,Ct),e.lineTo(n,i-Lt)})),e.stroke(),e.lineWidth=2,e.fillStyle=st.hex(),e.strokeStyle=st.hex(),e.setLineDash([]);const h=s.x?_t(s.x,t,o):null;c.forEach((({position:o})=>{if(h&&o.start===h.position.start)return;const n=Pt(o.start,l,t,r);e.beginPath(),e.roundRect(n-.5,i-6-Lt-1,1,6,[1,1,0,0]),e.fill(),e.closePath(),e.stroke()})),e.restore();const d=Mt(c,r,t,l,25),m=[],p=[];d.forEach((e=>{const i=Pt(e.position.start,l,t,r);s.x&&i<s.x+Ot-a&&(m.push(e),m.length>4&&m.shift()),s.x&&i>s.x+Ot-a&&p.length<4&&p.push(e)})),d.forEach((({position:o,value:n})=>{if(h&&o.start===h.position.start)return;e.save();const s=Pt(o.start,l,t,r,a),c=i-6-Lt-8;e.translate(s,c),e.rotate(-40*Math.PI/180),m.some((e=>e.position.start===o.start))||p.some((e=>e.position.start===o.start))?e.fillStyle=nt.hex():e.fillStyle=lt.alpha(.2).hex(),e.font="normal 12px IBM Plex Sans",e.textAlign="left",e.fillText(n.name,0,0),e.restore()})),e.clearRect(0,0,Ot,i),e.clearRect(t-Gt,0,Gt,i),e.clearRect(0,0,t,Ct),e.clearRect(0,i-Lt,t,Lt)},Ht=(e,{width:t,height:o,store:r,setStore:a})=>{const s=n(null);return i((()=>{const i=s.current.getContext("2d");e({ctx:i,width:t,height:o,store:r,setStore:a})}),[t,o,r]),s},Ft=({width:t,height:i,store:o})=>{const n=Ht(Dt,{width:t,height:i,store:o});return e.createElement("canvas",{id:"steps-layer",className:"absolute rounded-t-xl",ref:n,width:t,height:i})},{CURVE_MARGIN_TOP:Bt,MARGIN_RIGHT:Wt,MARGIN_LEFT:$t,MARGIN_BOTTOM:Ut,MARGIN_TOP:zt}=je,Xt=({ctx:e,width:t,height:i,store:o})=>{const{mrsp:n,trainLength:r,ratioX:a,leftOffset:s}=o;if(!n)return;ut(e,t,i),e.save(),e.translate(s,0);const l=i-Ut-zt,c=pt(o),h=ft(o.speeds);e.lineCap="round";let d=Pt(0,h,t,a),m=null;for(let i=0;i<n.values.length;i++){const{speed:o,isTemporary:s}=n.values[i],p=i==n.values.length-1,f=p?h:n.boundaries[i],u=Pt(f,h,t,a),g=l-o/c*(l-Bt)+zt;null!==m&&(e.beginPath(),e.strokeStyle=rt.alpha(.5).hex(),e.lineWidth=.5,e.moveTo(d,m),e.lineTo(d,g),e.stroke());const x=s?ht:at,y=e.createLinearGradient(0,g,0,g-16);s?y.addColorStop(0,x.alpha(.23).hex()):y.addColorStop(0,x.alpha(.15).hex()),y.addColorStop(1,x.alpha(0).hex()),e.fillStyle=y,e.rect(d,g,u-d,-16),e.fill();let T=null;!p&&n.values[i+1].speed>o&&(T=Pt(Math.min(f+r/1e3,h),h,t,a)),e.beginPath(),e.lineWidth=1,e.strokeStyle=x.hex(),e.moveTo(d,g),e.lineTo(T??u,g),null!==T&&(e.moveTo(T,g-4),e.lineTo(T,g+4)),e.stroke(),d=u,m=g}e.restore(),e.clearRect(0,0,$t,i),e.clearRect(t-Wt,0,Wt,i)},Vt=({width:t,height:i,store:o})=>{const n=Ht(Xt,{width:t,height:i,store:o});return e.createElement("canvas",{id:"speed-limits-layer",className:"absolute rounded-t-xl",ref:n,width:t,height:i})},{CURVE_MARGIN_TOP:Yt,CURVE_MARGIN_SIDES:Zt}=je,jt=(e,t,i)=>{const{maxSpeed:o,maxPosition:n,ratioX:r}=t,{width:a,height:s}=e,l=Zt/2,c=s-Yt,h=(a-Zt)/n*r,d=[];return i.forEach((({position:e,value:t})=>{const i=t/o,n=e.start*h+l,r=s-i*c;d.push({x:n,y:r})})),d.push({x:n*h+l,y:s}),d.push({x:l,y:s}),d},qt=({ctx:e,width:t,height:i,store:o})=>{const{speeds:n,ecoSpeeds:r,ratioX:a,leftOffset:s}=o,l=g(17,101,180),c=g(7,69,128);ut(e,t,i),e.save(),e.translate(s,0);const h=pt(o),d=ft(o.speeds),m=jt({width:t,height:i},{maxSpeed:h,maxPosition:d,ratioX:a},n),p=jt({width:t,height:i},{maxSpeed:h,maxPosition:d,ratioX:a},r);e.beginPath(),e.lineWidth=.5,e.strokeStyle=l.hex(),e.fillStyle=l.alpha(.15).hex(),m.forEach((({x:t,y:i})=>{e.lineTo(t,i)})),e.fill(),e.beginPath(),m.slice(0,m.length-2).forEach((({x:t,y:i})=>{e.lineTo(t,i)})),e.stroke(),e.beginPath(),e.fillStyle="rgba(255, 255, 255)",e.strokeStyle=c.hex(),e.globalCompositeOperation="destination-out",p.forEach((({x:t,y:i})=>{e.lineTo(t,i)})),e.fill(),e.beginPath(),e.globalCompositeOperation="source-over",p.slice(0,p.length-2).forEach((({x:t,y:i})=>{e.lineTo(t,i)})),e.stroke(),e.restore()},Kt=({width:t,height:i,store:o})=>{const n=Ht(qt,{width:t,height:i,store:o});return e.createElement("canvas",{id:"curve-layer",className:c("absolute rounded-t-xl",{"bg-white-25":!o.layersDisplay.declivities}),ref:n,width:t,height:i})},{CURVE_MARGIN_SIDES:Qt,MARGIN_TOP:Jt,MARGIN_BOTTOM:ei,RIGHT_TICK_MARGINS:ti}=je,ii=({ctx:e,width:t,height:i,store:o})=>{const{slopes:n,ratioX:r,leftOffset:a}=o,{maxGradient:s}=wt(o),l=ft(o.speeds);if(!n||0===n.length)return void console.error("Slopes data is missing or empty.");ut(e,t,i),e.save(),e.translate(a,0);const c=i-Jt-ei-ti/2,h=Jt+ti/2+c/2;e.fillStyle="#CFDDCE";try{const i=(t-Qt)/l*r;for(let t=0;t<n.length-1;t++){const{position:o,value:r}=n[t],{position:a}=n[t+1],l=o.start*i+Qt/2,d=a.start*i+Qt/2-l,m=r/s*(c/2),p=r>=0?h-m:h;e.fillRect(l,p,d,Math.abs(m))}}catch(e){console.error("Error while drawing declivity:",e)}e.restore()},oi=({width:t,height:i,store:o})=>{const n=Ht(ii,{width:t,height:i,store:o});return e.createElement("canvas",{id:"declivity-layer",className:c("absolute rounded-t-xl",{"bg-white-25":o.layersDisplay.declivities}),ref:n,width:t,height:i})},ni=e=>e>7?7:e,ri=({ctx:e,width:t,height:i,store:o})=>{const{electricalProfiles:n,ratioX:r,leftOffset:a,cursor:s}=o,{ELECTRICAL_PROFILES_HEIGHT:l}=qe;if(!n)return;ut(e,t,i);const c=i-l;e.save(),e.translate(a,0);const h=ft(o.speeds),{MARGIN_TOP:d,MARGIN_BOTTOM:m,MARGIN_LEFT:p,MARGIN_RIGHT:f,CURVE_MARGIN_SIDES:u,ELECTRICAL_PROFILES_MARGIN_TOP:g}=je;Et(e,Qe,je,t,c,l),n.forEach((i=>{const o=yt(i.position.start,h,t,r,je),n=yt(i.position.end,h,t,r,je);let f=c-m+g;const u=n-o;if("neutral"===i.value.electricalProfile)e.fillStyle="#1F1B17",e.fillRect(o,f+28,u,9),e.clearRect(o,f+31,u,3);else{const{start:t,end:n}=i.position,{electricalProfile:r,color:h,heightLevel:g}=i.value,x=ni(g);if(e.fillStyle=h,"incompatible"===r)for(let t=0;t<9;t++)e.fillRect(o,f+15+3*t,u,1);else{f+=4*x;const i=40-4*x;if(e.fillRect(o,f,u,i),s.y&&s.x&&s.y<=c-m+d&&s.y>=c-m+d-l&&s.x-a>=o-p&&s.x-a<=o+u-p){e.globalAlpha=.2,e.fillRect(o,d,u,c-30),e.globalAlpha=1;const i=Math.floor(e.measureText(r).width),a=20,s=Math.max(i+a-u,0);e.fillStyle="#000",e.font="600 14px IBM Plex Sans",e.textAlign="center",e.fillText(`${r}`,o+u/2,c/2),e.fillStyle="rgb(49, 46, 43)",e.font="400 14px IBM Plex Sans",e.textAlign="right",e.fillText(`${(t||0).toFixed(1)}`,o-(12+s/2),c/2),e.textAlign="left",e.fillText(`${n.toFixed(1)}`,o+u+(12+s/2),c/2)}}}}));const x=n.findIndex((({position:e})=>s.x-a<=yt(e.end,h,t,r,je)-p));if(s.y&&s.y<=c-m+d&&s.y>=c-m+d-l&&-1!==x){const{start:i,end:o}=n[x].position,{electricalProfile:a,heightLevel:s}=n[x].value;if(a&&"incompatible"!==a){const n=ni(s),a=c-m+g+4*n,l=yt(i,h,t,r,je)||p+u/2,d=(yt(o,h,t,r,je)||t-f-u/2)-l,x=40-4*n;e.shadowColor="rgba(0, 0, 0, 0.19)",e.shadowBlur=5,e.strokeStyle="#FFF",e.lineWidth=2,e.strokeRect(l-1,a-1,d+2,x+2),e.stroke()}}Tt(e,"rgba(0,0,0,0.1)",je,t,c+1-m),e.restore(),e.clearRect(0,0,p,i),e.clearRect(t-f,0,f,i)},ai=({width:t,height:i,store:o})=>{const n=Ht(ri,{width:t,height:i,store:o});return e.createElement("canvas",{id:"electrical-profile-layer",className:"absolute",ref:n,width:t,height:i})},si=({ctx:e,width:t,height:i,store:o,setStore:n})=>{ut(e,t,i);const r=R.select(tt);n&&r.call((e=>P.zoom().filter((e=>e.shiftKey)).on("zoom",(()=>{const t=R.select(tt),{k:i,x:o}=P.zoomTransform(t.node());i>=1?e((e=>({...e,ratioX:i,leftOffset:o}))):(e((e=>({...e,ratioX:1,leftOffset:0}))),t.call(kt))})))(n)),r.on("mousemove",(e=>{const t=R.pointer(e);n&&n((()=>({...o,cursor:{x:t[0],y:t[1]}})))})),r.on("mouseleave",(()=>{n&&n((()=>({...o,cursor:{x:null,y:null}})))}))},li=({width:t,height:i,store:o,setStore:n})=>{const r=Ht(si,{width:t,height:i,store:o,setStore:n});return e.createElement("canvas",{id:"front-interactivity-layer",className:"absolute",ref:r,width:t,height:i})},{MARGIN_LEFT:ci,MARGIN_RIGHT:hi}=je,di=({ctx:e,width:t,height:i,store:o})=>{const{powerRestrictions:n,ratioX:r,leftOffset:a,layersDisplay:{electricalProfiles:s}}=o;if(!n)return;ut(e,t,qe.POWER_RESTRICTIONS_HEIGHT),e.save(),e.translate(a,0);const l=ft(o.speeds);e.font="normal 12px IBM Plex Sans",e.fillStyle="rgb(121, 118, 113)",e.strokeStyle="rgb(121, 118, 113)",e.lineWidth=1,e.textAlign="center";let c=Qe;s&&(c=Je),Tt(e,"rgba(0,0,0,0.1)",je,t,i-qe.POWER_RESTRICTIONS_HEIGHT+1),Et(e,c,je,t,i,qe.POWER_RESTRICTIONS_HEIGHT-1),n.forEach((({position:i,value:o},a)=>{o.handled?(e.strokeStyle="rgb(121, 118, 113)",e.fillStyle="rgb(121, 118, 113)"):(e.strokeStyle="rgb(217, 28, 28)",e.fillStyle="rgb(217, 28, 28)");const s=yt(i.start,l,t,r,je);e.beginPath(),e.moveTo(s,8),e.lineTo(s,32);const c=Math.floor(e.measureText(o.powerRestriction).width);let h=yt(i.end,l,t,r,je);a===n.length-1&&(h-=je.CURVE_MARGIN_SIDES/2);const d=19;if(h-s<c+4+4)e.moveTo(s,d),e.lineTo(h-2,d);else{const t=(s+h)/2-c/2-2,i=(s+h)/2+c/2+2;e.moveTo(s,d),e.lineTo(t-2,d),e.moveTo(i+2,d),e.lineTo(h-2,d);const n=(s+h)/2;e.textBaseline="middle",e.fillText(o.powerRestriction,n,d+e.lineWidth/2)}e.moveTo(h-2,14),e.lineTo(h-2,26),e.stroke()})),e.restore(),e.clearRect(0,0,ci,qe.POWER_RESTRICTIONS_HEIGHT),e.clearRect(t-hi,0,hi,qe.POWER_RESTRICTIONS_HEIGHT)},mi=({width:t,marginTop:i,store:o})=>{const n=Ht(di,{width:t,height:qe.POWER_RESTRICTIONS_HEIGHT,store:o});return e.createElement("canvas",{id:"power-restrictions-layer",className:"absolute",ref:n,width:t,height:qe.POWER_RESTRICTIONS_HEIGHT,style:{marginTop:i}})},pi=({width:t,height:i,store:o,curveX:n,curveY:r,speedText:a,ecoSpeedText:s,effortText:l,electricalModeText:h,electricalProfileText:d,powerRestrictionText:m,previousGradientText:p,modeText:f})=>{const{MARGIN_BOTTOM:u,MARGIN_RIGHT:g}=je,{energySource:x,tractionStatus:y,declivities:T,electricalProfiles:E,powerRestrictions:v}=o.detailsBoxDisplay;let w=0,S=0;const I=document.getElementById("details-box")?.offsetWidth||0,R=document.getElementById("details-box")?.offsetHeight||0;n+I>t-g-10&&(w=I+12),r+R>i-u-10&&(S=R+12);const P=n+6-w,b=r+6-S,M=Number(a)-Number(s),N=0!==M?`-${M.toFixed(1)}`:null;return e.createElement("div",{id:"details-box",className:c("absolute flex flex-col",{block:r,hidden:!r}),style:{marginTop:b,marginLeft:P}},e.createElement("span",{id:"base-speed-text"},a||"--"),e.createElement("div",null,e.createElement("span",{id:"mareco-speed-text"},s||"--"),N&&e.createElement("span",{id:"speed-difference-text"},N)),(x||y||f||l)&&e.createElement("hr",null),x&&e.createElement("span",{id:"mode-text"},f||"--"),y&&e.createElement("span",{id:"effort-text"},l||"--"),h&&e.createElement("div",{id:"electrical-mode-text"},e.createElement("span",null,h||"--"),E&&e.createElement("span",{className:"ml-2"},d||"--")),v&&e.createElement("span",{id:"power-restriction-text"},m||"--"),T&&e.createElement(e.Fragment,null,e.createElement("hr",null),e.createElement("span",{id:"previous-gradient-text"},`${p} ‰`||"--")))},{MARGIN_LEFT:fi,MARGIN_RIGHT:ui,MARGIN_TOP:gi,MARGIN_BOTTOM:xi,CURVE_MARGIN_TOP:yi,CURVE_MARGIN_SIDES:Ti}=je,Ei=12.75,vi=({width:o,height:r,heightOffset:a,store:s})=>{const l=n(null),[c,h]=t(null),d=gt(a,s.layersDisplay,!1);return i((()=>{const e=l.current.getContext("2d");if(s.cursor.y&&s.cursor.y<d){const t=(({ctx:e,width:t,height:i,store:o})=>{ut(e,t,i);const{cursor:n,layersDisplay:r,ratioX:a,leftOffset:s,speeds:l,ecoSpeeds:c,electrifications:h,slopes:d,electricalProfiles:m,powerRestrictions:p}=o;let f="",u="",g="",x="coasting",y="",T="",E="",v=0,w="",S=0;const I=pt(o),R=ft(o.speeds),P=gt(i,r,!1)-xi-gi,b=t-fi-ui,M=e=>e*((b-Ti)/R)*a+s+Ti/2;if(null===n.x||null===n.y)return;let N=n.x+fi,_=Nt(n.x,t,o);if(_<0||_>R)return;let A=!1;if(r.steps){const e=_t(n.x,t,o);null!==e&&(A=!0,_=e.position.start,N=Pt(_,R,t,a,s),g=e.value.name)}if(m){const e=m.find((({position:e})=>M(e.start)<=n.x&&M(e.end)>=n.x))?.value.electricalProfile;e&&(T=e)}if(p){const e=p.find((({position:e})=>n.x>=M(e.start)&&n.x<=M(e.end)));E=e?.value.powerRestriction||""}const k=h.findLast((({position:e})=>e.start<=_)),O=k?.value;O&&(w="electrification"===O.type?"electric":"--",y=O.voltage);let G=Rt(l,_,(e=>e.position.start));G===l.length-1&&G--;let C=Rt(c,_,(e=>e.position.start));C===c.length-1&&C--;const L=l[G],D=l[G+1],H=bt(L.position.start,L.value,D.position.start,D.value,_);f=H.toFixed(1);const F=P-H/I*(P-yi)+gi,B=c[C],W=c[C+1],$=bt(B.position.start,B.value,W.position.start,W.value,_);u=$.toFixed(1),B.value<W.value?x="accelerating":B.value>W.value&&(x="decelerating"),S=P-$/I*(P-yi)+gi,v=d.findLast((({position:e})=>e.start<=_)).value,e.font="normal 12px IBM Plex Sans",e.fillStyle=nt.hex(),e.beginPath(),e.strokeStyle=nt.alpha(.4).hex(),e.lineWidth=.5,e.moveTo(N,F),e.lineTo(N,i-xi),e.moveTo(N,S),e.lineTo(fi,S),Math.abs(F-S)>2&&(e.moveTo(N,F),e.lineTo(fi,F)),e.stroke(),e.beginPath(),e.lineWidth=3,e.strokeStyle=dt.hex(),e.lineCap="round",e.moveTo(N-Ei,S),e.lineTo(N+Ei,S),e.moveTo(N,S-Ei),e.lineTo(N,S+Ei),e.stroke(),e.beginPath(),e.lineWidth=1,e.strokeStyle=nt.hex(),e.moveTo(N-Ei,S),e.lineTo(N+Ei,S),e.moveTo(N,S-Ei),e.lineTo(N,S+Ei),e.stroke(),e.beginPath(),e.strokeStyle=nt.hex(),e.lineCap="butt",e.lineWidth=1,e.moveTo(fi,S),e.lineTo(fi,S),e.stroke();const U=(Math.round(10*_)/10).toFixed(1).toString();return e.textAlign="center",A?(e.beginPath(),e.lineWidth=2,e.roundRect(N-.5,i-xi-24*.6,1,24,[1,1,1,1]),e.fill(),e.stroke(),e.fillText(U,N,i-xi+1.33*Ti)):(e.beginPath(),e.lineWidth=1,e.moveTo(N,i-xi),e.lineTo(N,i-xi+6),e.stroke(),e.fillText(U,N,i-xi+1.33*Ti)),N-fi<e.measureText(g).width/2?e.textAlign="start":N-fi>b-e.measureText(g).width/2&&(e.textAlign="end"),e.fillText(g,N,i-xi+36),e.clearRect(0,0,t,gi),{curveX:N,curveY:S,speedText:f,ecoSpeedText:u,effortText:x,electricalModeText:y,electricalProfileText:T,powerRestrictionText:E,previousGradientText:v,modeText:w}})({ctx:e,width:o,height:r,store:s});h(t||null)}else ut(e,o,r),h(null)}),[o,r,s,d]),e.createElement(e.Fragment,null,e.createElement("canvas",{id:"cursor-layer",className:"absolute",ref:l,width:o,height:r}),c&&e.createElement(pi,{width:o,height:r,store:s,...c}))},wi=({cursorX:t,cursorY:i,height:o,text:n})=>e.createElement("div",{id:"tooltip",className:"absolute",style:{marginTop:i,marginLeft:t-123,maxHeight:o}},e.createElement("span",null,n)),Si=17,Ii=12,Ri=({ctx:e,width:t,height:i,store:o,images:n})=>{const{speedLimitTags:r,ratioX:a,leftOffset:s,layersDisplay:{electricalProfiles:l,powerRestrictions:c}}=o,{MARGIN_BOTTOM:h,MARGIN_LEFT:d,MARGIN_RIGHT:m}=je;ut(e,t,qe.SPEED_LIMIT_TAGS_HEIGHT),e.save(),e.translate(s,0);const p=ft(o.speeds);let f=Qe;l&&c?f=et:(l||c)&&(f=Je),Tt(e,"rgba(0,0,0,0.1)",je,t,1),Et(e,f,je,t,h,qe.SPEED_LIMIT_TAGS_HEIGHT-1),r&&(r.forEach((({position:i,value:o},r)=>{const{tag:s,color:l}=o,c=yt(i.start,p,t,a,je),h=yt(i.end,p,t,a,je);if(void 0!==h){const t=h-c-1,i=mt[l]||l;e.fillStyle=l,e.strokeStyle="UU"===s?"#494641":l,e.lineWidth=1,e.beginPath(),e.fillRect(c,Ii,t-1,Si),e.fillStyle=i;const o=e.measureText(s).width+8+(0===r?8:0);if(e.fillRect(c+1+o,Ii,t-o-2,Si),e.rect(c+o,Ii,t-1-o,Si),e.strokeRect(c+1,Ii,t-1,Si),e.closePath(),"UU"===s&&(e.lineWidth=.5,e.beginPath(),e.moveTo(c+o+2,Ii),e.lineTo(c+o+2,29),e.closePath(),e.stroke()),"incompatible"===s||"missing_from_train"===s){const i="incompatible"===s?n.alertFillImage:n.questionImage;e.fillStyle=l;const o=c+(t-24)/2,r=8;((e,t,i,o,n,r)=>{e.beginPath(),e.moveTo(t+r,i),e.lineTo(t+o-r,i),e.quadraticCurveTo(t+o,i,t+o,i+r),e.lineTo(t+o,i+n-r),e.quadraticCurveTo(t+o,i+n,t+o-r,i+n),e.lineTo(t+r,i+n),e.quadraticCurveTo(t,i+n,t,i+n-r),e.lineTo(t,i+r),e.quadraticCurveTo(t,i,t+r,i),e.closePath(),e.fill(),e.stroke()})(e,o,r,24,24,4),null!==i&&((e,t,i,o,n,r,a)=>{const s=document.createElement("canvas"),l=s.getContext("2d");l&&(s.width=n,s.height=r,l.drawImage(t,0,0,n,r),l.globalCompositeOperation="source-in",l.fillStyle=a,l.fillRect(0,0,n,r),e.drawImage(s,i,o))})(e,i,o+4,r+4,16,16,dt.hex())}else{e.fillStyle="white",e.font='600 12px "IBM Plex Sans"',e.textAlign="left",e.textBaseline="middle";const t=c+4;e.fillText(s,t,21.5)}}})),Tt(e,"rgba(0,0,0,0.1)",je,t,i),e.restore(),e.clearRect(0,0,d,qe.SPEED_LIMIT_TAGS_HEIGHT),e.clearRect(t-m,0,t,qe.SPEED_LIMIT_TAGS_HEIGHT))},Pi=({width:o,marginTop:r,store:a})=>{const s=n(null),l=n(),[c,h]=t({questionImage:null,alertFillImage:null});return i((()=>{(async()=>{const e=It('<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8m8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13M6.92 6.085h.001a.75.75 0 1 1-1.342-.67c.169-.339.436-.701.849-.977C6.845 4.16 7.369 4 8 4a2.76 2.76 0 0 1 1.637.525c.503.377.863.965.863 1.725 0 .448-.115.83-.329 1.15-.205.307-.47.513-.692.662-.109.072-.22.138-.313.195l-.006.004a6 6 0 0 0-.26.16 1 1 0 0 0-.276.245.75.75 0 0 1-1.248-.832c.184-.264.42-.489.692-.661q.154-.1.313-.195l.007-.004c.1-.061.182-.11.258-.161a1 1 0 0 0 .277-.245C8.96 6.514 9 6.427 9 6.25a.61.61 0 0 0-.262-.525A1.27 1.27 0 0 0 8 5.5c-.369 0-.595.09-.74.187-.146.1-.263.238-.34.398M9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0"/></svg>'),t=It('<svg xmlns="http://www.w3.org/2000/svg" width = "16" height = "16" viewBox = "0 0 16 16" > <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575zM8 5a.75.75 0 0 0-.75.75v2.5a.75.75 0 0 0 1.5 0v-2.5A.75.75 0 0 0 8 5m1 6a1 1 0 1 0-2 0 1 1 0 0 0 2 0" /> </svg>'),i=await St(e),o=await St(t);h({questionImage:i,alertFillImage:o})})()}),[]),i((()=>{(async()=>{const e=s.current.getContext("2d"),t={speedLimitTags:a.speedLimitTags,ratioX:a.ratioX,leftOffset:a.leftOffset,layersDisplay:{electricalProfiles:a.layersDisplay.electricalProfiles,powerRestrictions:a.layersDisplay.powerRestrictions},speeds:a.speeds};await Ri({ctx:e,width:o,height:r,store:t,images:c})})()}),[o,r,a.speedLimitTags,a.ratioX,a.leftOffset,a.layersDisplay.electricalProfiles,a.layersDisplay.powerRestrictions,a.speeds,c]),i((()=>{(async()=>{s.current.getContext("2d"),l.current=await(({width:e,height:t,store:i})=>{const{speedLimitTags:o,ratioX:n,leftOffset:r,cursor:a}=i,{MARGIN_TOP:s,MARGIN_LEFT:l}=je,c=ft(i.speeds);if(!o)return null;for(const{position:i,value:h}of o){const o={incompatible:"Incompatible with the infrastructure"},{tag:d}=h;if(!(d in o))continue;const m=o[d];if(void 0===i.end||null===a.x||null===a.y)continue;const p=yt(i.start,c,e,n,je),f=yt(i.end,c,e,n,je)-p-1;if(a.x>=p-l+r&&a.x<=p-l+r+f&&a.y>=t-s+Ii-2&&a.y<=t-s+Ii-1+Si)return{cursorX:a.x+l,cursorY:Ii,text:m}}return null})({width:o,height:r,store:a})})()}),[o,r,a]),e.createElement(e.Fragment,null,e.createElement("canvas",{id:"speed-limit-tags-layer",className:"absolute",ref:s,width:o,height:qe.SPEED_LIMIT_TAGS_HEIGHT,style:{marginTop:r}}),l.current&&e.createElement(wi,{cursorX:l.current.cursorX,cursorY:r-40-2,height:40,text:l.current.text}))},{MARGIN_LEFT:bi,MARGIN_RIGHT:Mi,MARGIN_BOTTOM:Ni,CURVE_MARGIN_SIDES:_i}=je,Ai=({ctx:e,width:t,height:i,store:o})=>{const{ratioX:n,leftOffset:r,cursor:a}=o;ut(e,t,i),e.save(),e.translate(r,0),e.strokeStyle="rgb(121, 118, 113)",e.lineWidth=.5,e.font="normal 12px IBM Plex Sans",e.fillStyle="rgb(182, 179, 175)";const s=ft(o.speeds),l=s/o.ratioX;let c,h;l>=200?(c=5*Math.floor(l/200),h=2):l>=50?(c=2,h=5):l>=20?(c=1,h=5):(c=.1,h=5);const d=Math.floor(s/c),m=(t-_i-bi-Mi)*(d*c/s)*n/d;e.beginPath();const p=i-Ni;for(let o=0;o<=d;o++){const n=bi+_i/2+m*o,s=o%h==0?.66*_i:.33*_i;if(e.moveTo(n,p),e.lineTo(n,i-Ni+s),o%(2*h)==0){e.textAlign="center";const i=(c*o).toFixed(0),s=2*e.measureText(i).width,l=a.x?a.x+bi-r:1/0,h=Math.abs(l-n),d=Math.max(Math.min(h/s-.1,1),0),m=Math.abs(t-Mi-_i/2-r-n),f=Math.max(Math.min(m/s-.1,1),0),u=Math.abs(bi+_i/2-r-n);let g=Math.max(Math.min(u/s-.1,1),0);0===o&&(g=1);const x=Math.min(d,f,g);e.fillStyle=`rgb(182, 179, 175, ${x})`,e.fillText(i,n,p+1.33*_i)}}e.closePath(),e.stroke(),e.restore(),e.clearRect(0,0,bi,i),e.clearRect(t-Mi,0,t,i),e.fillStyle="rgb(182, 179, 175)",e.textAlign="center",e.shadowOffsetY=0,e.shadowBlur=0,e.beginPath(),e.fillText("km",t-Mi-_i/2,p+1.33*_i),e.closePath(),e.stroke()},ki=({width:t,height:i,store:o})=>{const n=Ht(Ai,{width:t,height:i,store:o});return e.createElement("canvas",{id:"tick-layer-x",className:"absolute rounded-t-xl",ref:n,width:t,height:i})},{MARGIN_LEFT:Oi,MARGIN_TOP:Gi,MARGIN_BOTTOM:Ci,CURVE_MARGIN_TOP:Li,MARGIN_RIGHT:Di}=je,{Y_LEFT_VERTICAL:Hi,Y_LEFT_HORIZONTAL:Fi}=Ze,Bi=({ctx:e,width:t,height:i,store:o})=>{const n=pt(o);ut(e,t,i),e.strokeStyle="rgb(121, 118, 113)",e.lineWidth=.5,e.font="normal 12px IBM Plex Sans",e.fillStyle="rgb(182, 178, 175)";let r=5;n>250?r=30:n>130?r=20:n>60&&(r=10);const a=Math.ceil(n/r),s=(i-Ci-Gi-Li)*(a*r/n)/a;e.beginPath();for(let t=0;t<=a;t++){const o=i-Ci-s*t;e.moveTo(Oi-6,o),e.lineTo(Oi,o),e.textAlign="right";const n=(t*r).toString(),a=o+4;e.fillStyle="rgb(182, 178, 175 )",e.fillText(n,36,a)}e.stroke(),e.strokeStyle="rgba(33, 112, 185, 0.6)",e.beginPath(),e.lineWidth=.5;for(let o=3;o<=a;o+=3){const n=i-Ci-s*o;e.moveTo(Oi,n),e.lineTo(t-Di,n)}e.stroke(),e.strokeStyle="rgba(33, 112, 185, 0.25)",e.beginPath();for(let o=1;o<=a;o++){if(o%3==0)continue;const n=i-Ci-s*o;e.moveTo(Oi,n),e.lineTo(t-Di,n)}e.stroke(),e.clearRect(0,0,t,Gi),e.clearRect(Oi-6,i-Ci,t,Ci),e.clearRect(0,i-Ci+6,Oi,Ci),e.fillStyle="rgb(182, 179, 175)",e.textAlign="center",e.shadowOffsetY=0,e.shadowBlur=0,e.beginPath(),e.fillText("km/h",Hi,Fi),e.closePath(),e.stroke()},Wi=({width:t,height:i,store:o})=>{const n=Ht(Bi,{width:t,height:i,store:o});return e.createElement("canvas",{id:"tick-layer-y",className:"absolute rounded-t-xl",ref:n,width:t,height:i})},{MARGIN_LEFT:$i,MARGIN_TOP:Ui,MARGIN_BOTTOM:zi,RIGHT_TICK_MARGINS:Xi}=je,{Y_RIGHT_VERTICAL:Vi,Y_RIGHT_HORIZONTAL:Yi}=Ze,Zi=({ctx:e,width:t,height:i,store:o})=>{ut(e,t,i);const{minGradient:n,maxGradient:r}=wt(o),a=i-Ui-zi-Xi,s=a/12,l=Ui+Xi/2+a/2+2,c=t-$i+10;e.font="normal 12px IBM Plex Sans",e.lineWidth=.5;const h=Math.max(r,n),d=6*Math.ceil(h/6)/6;e.beginPath();for(let i=-6;i<=6;i++){const o=i*d,n=l-i*s;e.moveTo(t-$i-6,n),e.lineTo(t-$i,n),e.strokeStyle="rgb(121, 118, 113)",e.textAlign="left";const r=o.toString(),a=n+4,h=1;e.fillStyle=`rgba(182, 179, 175, ${h})`,e.fillText(r,c,a),e.fillText("‰",t-Yi,Vi)}e.stroke(),e.clearRect(0,0,t,Ui),e.clearRect(t-$i,i-zi,t,zi),e.clearRect(0,i-zi+6,t-$i,zi)},ji=({width:t,height:i,store:o})=>{const n=Ht(Zi,{width:t,height:i,store:o});return e.createElement("canvas",{id:"tick-layer-y-right",className:"absolute rounded-t-xl",ref:n,width:t,height:i})},qi=({width:o,height:n,backgroundColor:r,data:a,setHeight:s,translations:l})=>{const[c,h]=t({speeds:[],ecoSpeeds:[],stops:[],electrifications:[],slopes:[],mrsp:void 0,powerRestrictions:void 0,electricalProfiles:void 0,speedLimitTags:void 0,trainLength:0,ratioX:1,leftOffset:0,cursor:{x:null,y:null},detailsBoxDisplay:{energySource:!0,tractionStatus:!0,declivities:!0,electricalProfiles:!0,powerRestrictions:!0},layersDisplay:{steps:!0,declivities:!1,speedLimits:!1,electricalProfiles:!1,powerRestrictions:!1,speedLimitTags:!1},isSettingsPanelOpened:!1}),{WIDTH_OFFSET:d,HEIGHT_OFFSET:m}=((e,t,i)=>({WIDTH_OFFSET:i?e-102:e-60,HEIGHT_OFFSET:t-80}))(o,n,c.layersDisplay.declivities),p=gt(n,c.layersDisplay),f=gt(m,c.layersDisplay),{OFFSET_RIGHT_AXIS:u}=je,g=c.layersDisplay.declivities?o-u:o,[x,y]=t(!1);return i((()=>{h((e=>({...e,...a})))}),[a]),i((()=>{s(p)}),[s,p]),e.createElement("div",{style:{width:`${o}px`,height:`${p}px`,backgroundColor:`${r}`},tabIndex:0},e.createElement("div",{className:"flex justify-end absolute base-margin-top",style:{width:g}},e.createElement(Ye,{reset:()=>{h((e=>({...e,ratioX:1,leftOffset:0}))),kt()},openSettingsPanel:()=>{h((e=>({...e,isSettingsPanelOpened:!0})))},store:c})),c.isSettingsPanelOpened&&e.createElement("div",{className:"flex justify-end absolute ml-2 base-margin-top",style:{width:g}},e.createElement(At,{globalHeight:p,color:r,store:c,setStore:h,setIsMouseHoveringSettingsPanel:y,translations:l})),c.layersDisplay.declivities&&e.createElement(oi,{width:d,height:m,store:c}),e.createElement(Kt,{width:d,height:m,store:c}),c.layersDisplay.speedLimits&&e.createElement(Vt,{width:g,height:n,store:c}),c.layersDisplay.steps&&e.createElement(Ft,{width:g,height:n,store:c}),e.createElement(Wi,{width:o,height:n,store:c}),c.layersDisplay.electricalProfiles&&e.createElement(ai,{width:g,height:n+qe.ELECTRICAL_PROFILES_HEIGHT,store:c}),c.layersDisplay.powerRestrictions&&e.createElement(mi,{width:g,marginTop:xt(n,c.layersDisplay),store:c}),c.layersDisplay.speedLimitTags&&e.createElement(Pi,{width:g,marginTop:xt(n,c.layersDisplay,c.layersDisplay.speedLimitTags),store:c}),e.createElement(ki,{width:g,height:p,store:c}),c.layersDisplay.declivities&&e.createElement(ji,{width:o,height:n,store:c}),!x&&e.createElement(vi,{width:g,height:p,heightOffset:f,store:c}),e.createElement(li,{width:d,height:f,store:c,setStore:h}))},Ki=100,Qi=48.5,Ji={SANS:"400 12px IBM Plex Sans",MONO:"400 10px IBM Plex Mono"},eo={GREY_20:"rgb(211, 209, 207)",GREY_50:"rgb(121, 118, 113)",GREY_60:"rgb(92, 89, 85)",GREY_80:"rgb(49, 46, 43)",HOUR_BACKGROUND:"rgba(243, 248, 253, 0.5)",RAIL_TICK:"rgb(33, 112, 185)",REMAINING_TRAINS_BACKGROUND:"rgba(0, 0, 0, 0.7)",SELECTION_20:"rgb(255, 242, 179)",WHITE_50:"rgba(255, 255, 255, 0.5)",WHITE_100:"rgb(255, 255, 255)"},to={MINUTE:[2,9,2],FIVE_MINUTES:[6,9,6],QUARTER_HOUR:[2,2,6,9,6,2,2],HALF_HOUR:[2,2,2,2,6,9,6,2,2,2,2],HOUR:[16,9,16]},io=[[0,0,0,0,0,0,1,1,1,1,1],[0,0,0,0,0,3,1,1,1,1,1],[0,0,0,3,2,1,1,1,1,1,1],[0,0,0,3,2,1,1,1,1,1,1],[0,0,3,2,1,1,1,1,1,1,1],[0,0,3,2,1,1,1,1,1,1,1],[0,0,3,2,1,1,1,1,1,1,1],[0,0,3,2,1,1,1,1,1,1,1]],oo=({ctx:e,text:t,x:i,y:o,color:n,xPosition:r="left",yPosition:a="bottom",font:s="400 12px IBM Plex Sans",rotateAngle:l=0,stroke:c})=>{e.save(),e.translate(i,o),e.rotate(l),e.font=s,e.textAlign=r,e.textBaseline=a,e.fillStyle=n,c&&(e.lineWidth=c.width,e.strokeStyle=c.color,e.strokeText(t,0,0)),e.fillText(t,0,0),e.restore()},no=e=>({"00":"HOUR",30:"HALF_HOUR",15:"QUARTER_HOUR",45:"QUARTER_HOUR","05":"FIVE_MINUTES",10:"FIVE_MINUTES",20:"FIVE_MINUTES",25:"FIVE_MINUTES",35:"FIVE_MINUTES",40:"FIVE_MINUTES",50:"FIVE_MINUTES",55:"FIVE_MINUTES"}[e]??"MINUTE"),ro={medium:24,small:4},ao=-30*Math.PI/180,{SANS:so,MONO:lo}=Ji,{WHITE_100:co,GREY_50:ho,GREY_60:mo,GREY_80:po,SELECTION_20:fo}=eo,{SANS:uo}=Ji,{REMAINING_TRAINS_BACKGROUND:go,WHITE_100:xo,SELECTION_20:yo}=eo,To=4.5,Eo=({ctx:e,remainingTrainsNb:t,xPosition:i})=>{e.fillStyle=go,e.beginPath(),e.rect(i,36.5,70,24),e.fill(),e.stroke(),e.fillStyle=xo,e.font=uo,e.textAlign="center",e.textBaseline="middle",e.fillText(`+${t} trains`,i+35,48.5)},vo=({ctx:e,zone:t,tracks:i,arrivalTimePixel:o,departureTimePixel:n,yPosition:r,isThroughTrain:a,selectedTrainId:s,setSelectedTrainId:l,xMousePosition:c,yMousePosition:h,index:d})=>{let m=s;const p=10+Ki*d+r,f=20+Ki*i.length-p,u=a?4:0,g=c>=o-u&&c<=n+u,x=Math.abs(h)>=f-3-1-u&&Math.abs(h)<=f+1+u;if(g&&x&&(l(t.id),m=t.id),e.fillStyle=t.color,e.strokeStyle=xo,e.lineJoin="round",e.lineCap="round",e.font="400 10px IBM Plex Mono",s===t.id){const i=a?8:4,s=e.measureText(t.originStation||"--").width,l=e.measureText(t.destinationStation||"--").width;e.save(),e.fillStyle=yo,e.beginPath(),e.roundRect(o-s-i,r-20,n-o+s+l+2*i,40,2),e.fill(),e.restore()}a?(({ctx:e,arrivalTimePixel:t})=>{e.beginPath(),e.moveTo(t-1,50),e.lineTo(t-To,45),e.lineTo(t+To,45),e.lineTo(t+1,50),e.lineTo(t+To,55),e.lineTo(t-To,55),e.lineTo(t-1,50),e.fill(),e.moveTo(t-1,50),e.lineTo(t+1,50),e.stroke()})({ctx:e,arrivalTimePixel:o}):(({ctx:e,arrivalTimePixel:t,departureTimePixel:i,yPosition:o})=>{e.beginPath(),e.rect(t,o,i-t,3),e.fill(),e.stroke()})({ctx:e,arrivalTimePixel:o,departureTimePixel:n,yPosition:r}),(({ctx:e,zone:t,arrivalTimePixel:i,departureTimePixel:o,yPosition:n,isThroughTrain:r,selectedTrainId:a})=>{const s=o-i-4,l=e=>s<ro[e];e.font="400 10px IBM Plex Mono";const c=e.measureText(t.originStation||"--").width;e.font="400 12px IBM Plex Mono";const h=e.measureText(t.arrivalTrainName).width,{xOriginTrainName:d,yOriginTrainName:m}=l("medium")?{xOriginTrainName:i-c+4-(r?6:0),yOriginTrainName:n-14}:{xOriginTrainName:i+8,yOriginTrainName:n-5},p=l("small")?"right":"center",f=l("small")?"left":"center",u={color:a===t.id?"transparent":co,width:4};if(a===t.id){const{xSelectedTrainNameBackground:t,ySelectedTrainNameBackground:o}=l("medium")?{xSelectedTrainNameBackground:d-8,ySelectedTrainNameBackground:n-28}:{xSelectedTrainNameBackground:i,ySelectedTrainNameBackground:n-18};e.save(),e.translate(t,o),e.rotate(ao),e.fillStyle=fo,e.beginPath(),e.roundRect(-4,0,h+8,18),e.fill(),e.restore()}oo({ctx:e,text:t.arrivalTrainName,x:d,y:m,color:ho,rotateAngle:ao,stroke:{color:co,width:4}}),oo({ctx:e,text:t.arrivalTime.getMinutes().toLocaleString("fr-FR",{minimumIntegerDigits:2}),x:r?i-4:i,y:n+8.5,color:po,xPosition:p,yPosition:"top",font:so,stroke:u}),r||oo({ctx:e,text:t.departureTime.getMinutes().toLocaleString("fr-FR",{minimumIntegerDigits:2}),x:o,y:n+8.5,color:po,xPosition:f,yPosition:"top",font:so,stroke:u}),oo({ctx:e,text:t.originStation||"--",x:r?i-4:i,y:n-5,color:mo,xPosition:"right",yPosition:"bottom",font:lo,stroke:u}),oo({ctx:e,text:t.destinationStation||"--",x:r?o+4:o,y:n-5,color:mo,xPosition:"left",yPosition:"bottom",font:lo,stroke:u})})({ctx:e,zone:t,arrivalTimePixel:o,departureTimePixel:n,yPosition:r,isThroughTrain:a,selectedTrainId:m})},wo=({useDraw:e,selectedTrainId:t,setSelectedTrainId:i,mousePosition:o})=>(e("paths",r(((e,{getTimePixel:n,tracks:r,occupancyZones:a,trackOccupancyWidth:s,trackOccupancyHeight:l})=>{l&&s&&(({ctx:e,width:t,height:i,tracks:o,occupancyZones:n,getTimePixel:r,selectedTrainId:a,setSelectedTrainId:s,mousePosition:l})=>{if(e.clearRect(0,0,t,i),e.save(),!o||!n||0===n.length)return;const c=n.sort(((e,t)=>e.arrivalTime.getTime()-t.arrivalTime.getTime()));o.forEach(((t,i)=>{const n=0===i?10:Ki;e.translate(0,n);const{x:h,y:d}=l,m=c.filter((e=>e.trackId===t.id));let p=0,f=0,u=f,g=Qi,x=4,y=0,T=0;for(;T<m.length;){const t=m[T],n=r(t.arrivalTime.getTime()),l=r(t.departureTime.getTime()),c=n===l;if(n>u){g=Qi,p=n,f=l,u=l,x=4,y=1,vo({ctx:e,zone:t,tracks:o,arrivalTimePixel:n,departureTimePixel:l,yPosition:g,isThroughTrain:c,selectedTrainId:a,setSelectedTrainId:s,index:i,xMousePosition:h,yMousePosition:d}),T++;continue}if(y<9){n>=p&&(y%2==0?g-=x:g+=x),l>=u&&(u=l),vo({ctx:e,zone:t,tracks:o,arrivalTimePixel:n,departureTimePixel:l,yPosition:g,isThroughTrain:c,selectedTrainId:a,setSelectedTrainId:s,index:i,xMousePosition:h,yMousePosition:d}),y++,x+=4,T++;continue}const E=m.findIndex(((e,t)=>t>T&&r(e.arrivalTime.getTime())>=u))-T;Eo({ctx:e,remainingTrainsNb:E,xPosition:p+(u-p)/2-35}),T+=E}})),e.restore()})({ctx:e,width:s,height:l,tracks:r,occupancyZones:a,getTimePixel:n,selectedTrainId:t,setSelectedTrainId:i,mousePosition:o})}),[o,t,i])),null),{WHITE_50:So,GREY_20:Io,RAIL_TICK:Ro}=eo,Po=({ctx:e,xStart:t,yStart:i,ticks:o,stroke:n})=>{const r=u(o)/2;e.strokeStyle=n,e.beginPath(),e.setLineDash(o),e.moveTo(t,i-r),e.lineTo(t,i+r),e.stroke()},bo=({ctx:e,width:t,getTimePixel:i,labelMarks:o})=>{e.fillStyle=So,e.save(),(({xStart:e,yStart:t,width:i,stroke:o=Io,ctx:n})=>{n.clearRect(e,t,i,9),n.fillStyle=So,n.strokeStyle=o,n.beginPath(),n.rect(e,t,i,8),n.fill(),n.stroke()})({xStart:-1,yStart:46,width:t+1,ctx:e});for(const t in o){const o=new Date(+t).getMinutes().toString().padStart(2,"0"),n=no(o);Po({ctx:e,xStart:i(+t),yStart:50,ticks:to[n],stroke:Ro})}e.restore()},{WHITE_100:Mo,HOUR_BACKGROUND:No}=eo,_o=({ctx:e,xStart:t,width:i,height:o,switchBackground:n})=>{t>=0&&(e.clearRect(t,0,i,o),e.fillStyle=n?No:Mo,e.fillRect(t,0,i,o))},Ao=({ctx:e,width:t,height:i,tracks:o,timeOrigin:n,timePixelOffset:r,getTimePixel:a,timeRanges:s,breakpoints:l,timeScale:c})=>{e.clearRect(0,0,t,i),e.save();const h=n-c*r,d=h+c*t,m=((e,t,i)=>{const o=e.findIndex((e=>t<e));return o>=0?i[o]:[]})(l,1/c*6e4,io),p=((e,t,i,o)=>{const n={};return e.map(((e,r)=>{const a=o[r];if(a)for(let o=Math.floor(t/e)*e;o<=i;o+=e)n[o]={level:a,rangeIndex:r}})),n})(s,h,d,m);let f=!1;for(const o in p){if("00"===new Date(+o).getMinutes().toString().padStart(2,"0"))f=!f,_o({ctx:e,xStart:a(+o),width:t,height:i,switchBackground:f})}o?.forEach(((i,o)=>{const n=0===o?10:Ki;e.translate(0,n),bo({ctx:e,width:t,getTimePixel:a,labelMarks:p})})),e.restore()},ko=({useDraw:e})=>(e("background",r(((e,{timeOrigin:t,timePixelOffset:i,getTimePixel:o,tracks:n,trackOccupancyWidth:r,trackOccupancyHeight:a,timeScale:s,theme:{timeRanges:l,breakpoints:c}})=>{a&&r&&Ao({ctx:e,width:r,height:a,tracks:n,timeOrigin:t,timePixelOffset:i,getTimePixel:o,timeRanges:l,breakpoints:c,timeScale:s})}),[])),null);new FontFace("IBM Plex Mono","url(/assets/IBMPlexMono-Regular.ttf)").load().then((e=>{document.fonts.add(e)}));const Oo=({opId:t,useDraw:i,setCanvasesRoot:o,selectedTrainId:n,setSelectedTrainId:r,mousePosition:a})=>e.createElement("div",{id:`track-occupancy-canvas-${t}`,className:"bg-white-100 canvas-container",ref:o},e.createElement(ko,{useDraw:i}),e.createElement(wo,{useDraw:i,selectedTrainId:n,setSelectedTrainId:r,mousePosition:a})),Go=({tracks:t})=>e.createElement("div",{id:"track-occupancy-manchette"},t.map((t=>e.createElement("div",{className:"track",key:t.id,style:{height:Ki}},e.createElement("span",{className:"track-line"},t.line),e.createElement("div",{className:"track-name"},t.name),e.createElement("div",{className:"track-rail"})))));export{be as ConflictLayer,Ne as ConflictTooltip,we as DEFAULT_LEVEL,Ce as DEFAULT_ZOOM_MS_PER_PX,Be as Manchette,Ve as ManchetteWithSpaceTimeChart,_e as OccupancyBlockLayer,Se as PathLayer,Ae as PatternRect,Ie as SpaceTimeChart,qi as SpeedSpaceChart,Oo as TrackOccupancyCanvas,Go as TrackOccupancyManchette,ke as WorkScheduleLayer,Re as isConflictPickingElement,Te as isPointPickingElement,Ee as isSegmentPickingElement,Ue as timeScaleToZoomValue,Xe as useManchetteWithSpaceTimeChart};
|
|
1
|
+
import e,{useState as t,useEffect as i,createContext as o,useContext as n,useRef as r,useCallback as a,useMemo as s,useLayoutEffect as l}from"react";import c from"classnames";import{identity as h,clamp as m,isEqual as d,inRange as p,last as f,sum as u}from"lodash";import g from"chroma-js";import{ZoomOut as x,ZoomIn as y,Iterations as T,Plus as E,Dash as S,KebabHorizontal as v,X as w}from"@osrd-project/ui-icons";import{Checkbox as I}from"@osrd-project/ui-core";import*as R from"d3-selection";import*as P from"d3-zoom";function M(e){const[o,n]=t({width:e?.offsetWidth||1,height:e?.offsetHeight||1});return i((()=>{const t=()=>{const t=e?.offsetWidth||1,i=e?.offsetHeight||1;t===o.width&&i===o.height||n({width:t,height:i})};if(e){const i=new ResizeObserver(t);return i.observe(e),()=>{i.disconnect()}}t()}),[e,o.height,o.width]),o}const b=o(void 0),N=o(void 0),_=o(void 0),O="stop",k=["paths"],A=["background","graduations","paths","overlay","captions"];function G(){const e=window.devicePixelRatio||1;return e>1?.5:.5*e}function C(e,{x:t,y:i},{x:o,y:n},[r,a,s],l,c,h=1){if(t>o)return C(e,{x:o,y:n},{x:t,y:i},[r,a,s],l,c,h);t=Math.round(t*h),i=Math.round(i*h),o=Math.round(o*h),n=Math.round(n*h),l=Math.round(l*h);const d=e.width,p=e.height,f=o-t,u=n-i,g=Math.sqrt(f*f+u*u),x=-u/g,y=f/g,T=Math.ceil(l/2),E={x:t+(+x-f/g)*T,y:i+(+y-u/g)*T},S={x:t+(-x-f/g)*T,y:i+(-y-u/g)*T},v={x:o+(f/g-x)*T,y:n+(u/g-y)*T},w={x:o+(+x+f/g)*T,y:n+(+y+u/g)*T},I=i<n,R=I?w:E,P=I?E:S,M=I?v:w,b=I?S:v,N=m(Math.floor(P.x),0,d),_=m(Math.ceil(M.x),0,d),O=m(Math.floor(b.y),0,p),k=m(Math.ceil(R.y),0,p);for(let t=O;t<=k;t++){const i=m(t<P.y?Math.floor(b.x+(t-b.y)*(P.x-b.x)/(P.y-b.y)):Math.floor(P.x+(t-P.y)*(P.x-R.x)/(P.y-R.y)),N,_),o=m(t<M.y?Math.ceil(b.x+(t-b.y)*(M.x-b.x)/(M.y-b.y)):Math.ceil(M.x+(t-M.y)*(M.x-R.x)/(M.y-R.y)),N,_);for(let n=i;n<=o;n++){const i=4*(t*d+n);e.data[i+3]||(e.data[i]=r,e.data[i+1]=a,e.data[i+2]=s,e.data[i+3]=255)}}}const L=new Map;function D(e,{x:t,y:i},o,[n,r,a],s,l=1){t=Math.round(t*l),i=Math.round(i*l),o=Math.ceil(o*l);const{width:c,height:h}=e,m=function(e){const t=L.get(e);if(t)return t;const i=2*e+1,o=new Uint8Array(i*i);for(let t=-e;t<=e;t++)for(let n=-e;n<=e;n++)n*n+t*t<=e*e&&(o[(t+e)*i+(n+e)]=1);return L.set(e,o),o}(o),d=2*o+1;for(let s=-o;s<=o;s++)for(let l=-o;l<=o;l++){if(1===m[(s+o)*d+(l+o)]){const o=t+l,m=i+s;if(o>=0&&o<c&&m>=0&&m<h){const t=4*(m*c+o);e.data[t]=n,e.data[t+1]=r,e.data[t+2]=a,e.data[t+3]=255}}}}function H(e,{x:t,y:i},o,n,[r,a,s],l=1){t=Math.round(t*l),i=Math.round(i*l),o=Math.round(o*l),n=Math.round(n*l);const c=m(t,0,e.width),h=m(i,0,e.height),d=m(t+o,0,e.width),p=m(i+n,0,e.height);for(let t=c;t<d;t++)for(let i=h;i<p;i++){const o=4*(i*e.width+t);e.data[o]=r,e.data[o+1]=a,e.data[o+2]=s,e.data[o+3]=255}}const F=6;const W=12;function B(e,t,i,o,n,r,a){"out"===a?function(e,t,i,o,n,r){let a="from"===n?-1:1,s=("backward"===r?-1:1)*a,l=t+4*a,c=i+(W-2)*s,h=t,m=i;o&&([a,s]=[s,a],[l,c]=[c,l],[h,m]=[m,h]),e.beginPath(),e.moveTo(h,m),e.bezierCurveTo(l,c,l,c,h+W*a,m+W*s),e.stroke()}(e,t,i,o,n,r):function(e,t,i,o){e.beginPath(),o?(e.moveTo(i-F/2,t),e.lineTo(i+F/2,t)):(e.moveTo(t,i-F/2),e.lineTo(t,i+F/2)),e.stroke()}(e,t,i,o)}function $(e,t,i,o,n=h){const r={},a=60*new Date(e).getTimezoneOffset()*1e3;return i.forEach(((i,s)=>{const l=o[s];if(!l)return;let c=Math.floor((e-a)/i)*i+a;for(;c<=t;)c>=e&&(r[c]=n(l,s)),c+=i})),r}function U(e,t,i=window.devicePixelRatio||1){const o=t/2;return Math.round((e-o)*i)/i+o}function z(e,t,i){const{getTimePixel:o,getSpacePixel:n,timeAxis:r}=i,{timeStart:a,timeEnd:s,spaceStart:l,spaceEnd:c}=t,h=o(Number(a)),m=o(Number(s)),d=n(l),p=n(c)-d,f=m-h;return p&&f?("x"===r?(e.translate(h,d),e.fillRect(0,0,f,p)):(e.translate(d,h),e.fillRect(0,0,p,f)),{areaTimeSize:f,areaSpaceSize:p}):{}}const Z={},X={};function V(e){if(X[e])return X[e];const t=`#${e.toString(16).padStart(6,"0")}`.toLowerCase();return Z[t]=e,X[e]=t,t}function Y(e){return e.toString(16).padStart(2,"0").toLowerCase()}function j(e){return g(e).rgba()}const q="picking",K="rendering";function Q(e,o,n){const l=r({}),c=r({}),h=r(k.reduce(((e,t)=>({...e,[t]:new Set})),{})),m=r(A.reduce(((e,t)=>({...e,[t]:new Set})),{})),p=r(o),f=r(null),[u,g]=t(null),x=M(e),y=r(x);i((()=>{y.current=x}),[x]);const T=function(){const[e,o]=t(window.devicePixelRatio||1);return i((()=>{if(!window.matchMedia||!window.devicePixelRatio)return;const e=()=>{o(window.devicePixelRatio)},t=window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`);return t.addEventListener("change",e),()=>{t.removeEventListener("change",e)}}),[e]),e}(),E=a(((e,t)=>{e.resetPickingElements(),k.forEach((i=>{if(t&&!t.has(i))return;const o=c.current[`${q}-${i}`],n=h.current[i];if(o){const{width:t,height:i}=y.current;o.clearRect(0,0,t,i);const r=o.getImageData(0,0,o.canvas.width,o.canvas.height),a=G();n.forEach((t=>t(r,e,a))),o.putImageData(r,0,0)}}))}),[]),S=a(((e,t)=>{A.forEach((i=>{if(t&&!t.has(i))return;const o=c.current[`${K}-${i}`],n=m.current[i];if(o){const{width:t,height:i}=y.current;o.clearRect(0,0,t,i),n.forEach((t=>t(o,e)))}}))}),[]),v=a((()=>{S(p.current),E(p.current),f.current&&(window.cancelAnimationFrame(f.current.frameId),f.current=null)}),[]),w=a((()=>{f.current||(f.current={frameId:window.requestAnimationFrame(v)})}),[]),I=a((({type:e,layer:t,fn:i})=>{if("picking"===e){const e=h.current[t];if(e.has(i))throw new Error("This picking function has already been registered.");e.add(i)}else if("rendering"===e){const e=m.current[t];if(e.has(i))throw new Error("This drawing function has already been registered.");e.add(i)}w()}),[]),R=a((({type:e,layer:t,fn:i})=>{if("picking"===e){const e=h.current[t];if(!e.has(i))throw new Error("This picking function has not been registered.");e.delete(i)}else if("rendering"===e){const e=m.current[t];if(!e.has(i))throw new Error("This drawing function has not been registered.");e.delete(i)}w()}),[]),P=a((()=>async function(e,t,i="#fff"){if(!t.length)throw Error("There must be at least one layer to capture.");const o=e[t[0]],n=o.width,r=o.height,a=document.createElement("CANVAS");a.setAttribute("width",n+""),a.setAttribute("height",r+"");const s=a.getContext("2d");return s.fillStyle=i,s.fillRect(0,0,n,r),t.forEach((t=>{s.drawImage(e[t],0,0,n,r,0,0,n,r)})),new Promise(((e,t)=>{a.toBlob((i=>{i?e(i):t()}),"image/png")}))}(l.current,A.map((e=>`${K}-${e}`)),p.current.theme.background)),[]);i((()=>{if(!e)return;const t=l.current,i=c.current;[...A.map((e=>({layer:e,type:"rendering"}))),...k.map((e=>({layer:e,type:"picking"})))].forEach((({layer:o,type:n})=>{const r=`${n}-${o}`;if(!t[r]){const a=document.createElement("CANVAS"),s=a.getContext("2d");a.classList.add(`layer-${n}-${o}`),a.style.position="absolute",a.style.inset="0",e.appendChild(a),t[r]=a,i[r]=s,"picking"===n&&(a.style.display="none")}}))}),[e]),i((()=>{p.current=o,v()}),[o.fingerprint]),i((()=>{const e=G();for(const t in l.current){const i=l.current[t],o=c.current[t],n=t.split("-")[0]===q;if(i){const t=n?e:T;i.style.width=x.width+"px",i.style.height=x.height+"px",i.setAttribute("width",x.width*t+"px"),i.setAttribute("height",x.height*t+"px"),n||(o.setTransform(1,0,0,1,0,0),o.scale(T,T))}}v()}),[x,T]),i((()=>{let e=null;const t=G();k.some((i=>{const o=c.current[`${q}-${i}`];if(o&&n){const[r,a,s,l]=o.getImageData(Math.round(n.x*t),Math.round(n.y*t),1,1).data;if(255===l){const t=function(e,t,i){return`#${Y(e)}${Y(t)}${Y(i)}`}(r,a,s),o=function(e){return Z[e.toLowerCase()]}(t),n=p.current.pickingElements[o];return e={layer:i,element:n},!0}}return!1})),d(e,u)||g(e)}),[n,u]);return{canvasContext:s((()=>({register:I,unregister:R,captureCanvases:P})),[I,R,P]),hoveredItem:u}}function J(e,t){const{register:o,unregister:r}=n(N);i((()=>(o({type:"picking",layer:e,fn:t}),()=>{r({type:"picking",layer:e,fn:t})})),[e,t,o,r])}function ee(e,t){const{register:o,unregister:r}=n(N);i((()=>(o({type:"rendering",layer:e,fn:t}),()=>{r({type:"rendering",layer:e,fn:t})})),[e,t,o,r])}function te({points:e},t,i){if(e.length<2||!e[t])return"still";const o=e[t].position;let n,r=t;for(;n=e[r];){if(n.position!==o){return(i?o-n.position:n.position-o)>0?"forward":"backward"}r+=i?-1:1}return"still"}function ie(e,t){const i=e(t),o=e(t,!0);return i===o?[i]:[i,o]}const oe=()=>(ee("graduations",a(((e,{timePixelOffset:t,getSpacePixel:i,operationalPoints:o,swapAxis:n,width:r,height:a,theme:{spaceGraduationsStyles:s}})=>{const l=n?a:r;o.forEach((o=>{const r=s[o.importanceLevel||0];r&&(e.strokeStyle=r.color,e.lineWidth=r.width,e.globalAlpha=r.opacity||1,r.dashArray&&(e.setLineDash(r.dashArray||[]),e.lineDashOffset=-t),ie(i,o.position).forEach((t=>{const i=U(t,e.lineWidth);e.beginPath(),n?(e.moveTo(i,0),e.lineTo(i,l)):(e.moveTo(0,i),e.lineTo(l,i)),e.stroke()})))})),e.setLineDash([]),e.lineDashOffset=0,e.globalAlpha=1}),[])),null),ne="#2170B9",re="#B6B2AF",ae="IBM Plex Sans",se=6e4,le=36e5,ce={background:"white",breakpoints:[.2,.4,.8,2.4,12,32,72,1/0],timeRanges:[1e4,3e4,6e4,3e5,9e5,18e5,1*le,3*le,6*le,12*le,24*le],pathsStyles:{fontSize:10,fontFamily:ae},spaceGraduationsStyles:{1:{width:.5,color:ne,opacity:.75},2:{width:.5,color:ne,opacity:.25},3:{width:.5,color:"#EDEDED"}},timeCaptionsPriorities:[[0,0,0,0,0,0,0,0,1,1,1],[0,0,0,0,0,0,0,1,1,1,1],[0,0,0,0,0,0,1,1,1,1,1],[0,0,0,0,0,3,1,1,1,1,1],[0,0,0,0,3,1,1,1,1,1,1],[0,0,0,3,2,1,1,1,1,1,1],[0,0,3,2,1,1,1,1,1,1,1],[0,0,3,2,1,1,1,1,1,1,1]],timeCaptionsStyles:{1:{color:"#797671",font:`12px ${ae}`,topOffset:11},2:{color:re,font:`12px ${ae}`,topOffset:9},3:{color:re,font:`10px ${ae}`,topOffset:6},4:{color:re,font:`8px ${ae}`,topOffset:8}},timeGraduationsPriorities:[[0,0,0,0,0,0,0,4,3,2,1],[0,0,0,0,0,0,4,3,3,2,1],[0,0,0,0,0,6,4,3,3,2,1],[0,0,0,0,6,5,4,3,3,2,1],[0,0,0,6,5,4,3,2,2,2,1],[0,0,6,5,4,4,3,2,2,2,1],[0,6,5,4,4,4,3,2,2,2,1],[6,0,5,4,4,4,3,2,2,2,1]],timeGraduationsStyles:{1:{width:.5,color:"#000000"},2:{width:.5,color:ne,opacity:.77},3:{width:.5,color:ne,opacity:.5},4:{width:.5,color:ne,opacity:.5,dashArray:[6,6]},5:{width:.5,color:ne,opacity:.5,dashArray:[6,18]},6:{width:1,color:ne,opacity:.5,dashArray:[1,12]}}},he=e=>`:${new Date(e).getMinutes().toString().padStart(2,"0")}`,me=(e,t)=>{const i=new Date(e);if(t>1){return`${i.getHours().toString().padStart(2,"0")}:${i.getMinutes().toString().padStart(2,"0")}`}return i.getHours().toString().padStart(2,"0")},de=33,pe=[()=>"",()=>"",he,he,he,he,me,me,me,me,me],fe=()=>(ee("captions",a(((e,{timeScale:t,timeOrigin:i,timePixelOffset:o,getTimePixel:n,swapAxis:r,width:a,height:s,theme:{background:l,breakpoints:c,timeRanges:h,timeCaptionsPriorities:m,timeCaptionsStyles:d,timeGraduationsStyles:p},showTicks:f})=>{const u=r?s:a,g=r?a:s,x=i-t*o,y=x+t*a,T=1/t*se;let E=[];c.some(((e,t)=>T<e&&(E=m[t],!0)));const S=$(x,y,h,E,((e,t)=>({level:e,rangeIndex:t})));if(e.fillStyle=l,r?e.fillRect(0,0,de,u):e.fillRect(0,g-de,u,de),e.strokeStyle=p[1].color,e.lineWidth=p[1].width,!f){if(e.beginPath(),r){const t=U(de,e.lineWidth);e.moveTo(t,0),e.lineTo(t,u)}else{const t=U(g-de,e.lineWidth);e.moveTo(0,t),e.lineTo(u,t)}e.stroke()}for(const t in S){const{level:i,rangeIndex:o}=S[t],a=d[i],s=(0,pe[o])(+t,T);e.textAlign="center",e.textBaseline="top",e.fillStyle=a.color,e.font=`${a.fontWeight||"normal"} ${a.font}`;const l=U(n(+t),e.lineWidth);r?(e.save(),e.translate(de-(a.topOffset||0),l),e.rotate(Math.PI/2),e.fillText(s,0,0),e.restore()):(f&&(e.strokeStyle=d[1].color,e.moveTo(l,g-de),e.lineTo(l,+t%18e4==0?8:4),e.stroke()),e.fillText(s,l,g-de+(a.topOffset||0)))}}),[])),null),ue=()=>(ee("graduations",a(((e,{timeScale:t,timeOrigin:i,timePixelOffset:o,spacePixelOffset:n,getTimePixel:r,swapAxis:a,width:s,height:l,theme:{breakpoints:c,timeRanges:h,timeGraduationsStyles:m,timeGraduationsPriorities:d}})=>{const p=a?s:l,f=i-t*o,u=f+t*(a?l:s),g=1/t*se;let x=[];c.some(((e,t)=>g<e&&(x=d[t],!0)));const y=$(f,u,h,x);for(const t in y){const i=m[y[t]];e.strokeStyle=i.color,e.lineWidth=i.width,e.globalAlpha=i.opacity||1,e.setLineDash(i.dashArray||[]),i.dashArray&&(e.lineDashOffset=-n);const o=U(r(+t),e.lineWidth);e.beginPath(),a?(e.moveTo(0,o),e.lineTo(p,o)):(e.moveTo(o,0),e.lineTo(o,p)),e.stroke()}e.setLineDash([]),e.lineDashOffset=0,e.globalAlpha=1}),[])),null);function ge(e,t){const i=t.getBoundingClientRect();return{x:e.clientX-i.left,y:e.clientY-i.top}}function xe(e){if(void 0!==e.deltaY)return-3*e.deltaY/360;if(void 0!==e.detail)return e.detail/-9;throw new Error("Could not extract delta from event.")}function ye(e,t,i){e=m(e,t.from,t.to);let o=t;for(;"limit"in o;)o=i?e>=o.limit?o.right:o.left:e<=o.limit?o.left:o.right;return o}function Te(e,t,i){return o=>{const{from:n,pixelFrom:r,coefficient:a}=function(e,t){e=m(e,t.pixelFrom,t.pixelTo);let i=t;for(;"pixelLimit"in i;)i=e<=i.pixelLimit?i.left:i.right;return i}(o-t,i);return e+n+(o-t-r)*a}}function Ee(e,t){const i=e.points.slice(0,-1).map(((t,i)=>[t,e.points[i+1]])).find((([e,i])=>p(t,e.time,i.time)));if(i){const[e,o]=i;return e.position+(t-e.time)/(o.time-e.time)*(o.position-e.position)}let o=e.points[0],n=e.points[0];return e.points.slice(1).forEach((e=>{e.time<o.time&&(o=e),e.time>n.time&&(n=e)})),o.time>t?o.position:n.position}function Se(e,t,i){if(t<e)return Se(t,e,i).reverse();e=Math.max(e,i.from),t=Math.min(t,i.to);let o=ye(e,i);const n=[];for(;o.to<t;)n.push(o.to),o=o.next;return n}function ve(e){return"point"===e.type}function we(e){return"segment"===e.type}const Ie={1:{width:1.5,endWidth:1.5},2:{width:1,endWidth:1},3:{width:1,endWidth:1,dashArray:[5,5],lineCap:"square"},4:{width:1.5,endWidth:1,dashArray:[0,4],lineCap:"round"}},Re=2,Pe=({path:e,color:t,level:i=2,pickingTolerance:o=5,border:n})=>{const r=a((({getTimePixel:t,getSpacePixel:i,spaceScaleTree:o,timeAxis:n,spaceAxis:r})=>{const a=[];return e.points.forEach((({position:s,time:l},c,h)=>{if(c){const{position:m,time:d}=h[c-1],p=Se(m,s,o);let f=-1/0;p.forEach(((o,h)=>{const u=o===(p[h+1]??1/0),g=f===o?"forward"===te(e,c,!0):!!u&&"backward"===te(e,c-1),x=d+(o-m)/(s-m)*(l-d);a.push({[n]:t(x),[r]:i(o,g)}),f=o})),a.push({[n]:t(l),[r]:i(s)})}else a.push({[n]:t(l),[r]:i(s)})})),a}),[e]),s=a((({getTimePixel:t,getSpacePixel:i,timeAxis:o,spaceAxis:n,operationalPoints:r})=>{const a=[],s=new Set(r.map((e=>e.position)));return e.points.forEach((({position:e,time:r})=>{s.has(e)&&a.push({[o]:t(r),[n]:i(e)})})),a}),[e]),l=a(((t,{getTimePixel:i,getSpacePixel:o,operationalPoints:n,swapAxis:r})=>{const a=new Set(n.map((e=>e.position)));e.points.forEach((({position:e,time:n},s,l)=>{if(s){const{position:c,time:h}=l[s-1];c===e&&a.has(e)&&ie(o,e).forEach((e=>{const o=U(e,t.lineWidth);t.beginPath(),r?(t.moveTo(o,i(h)),t.lineTo(o,i(n))):(t.moveTo(i(h),o),t.lineTo(i(n),o)),t.stroke()}))}}))}),[e]),c=a(((e,{width:t,height:i,swapAxis:o,theme:{background:n,pathsStyles:{fontSize:r,fontFamily:a}}},s,l,c,h)=>{if(!s)return;const m=c.findIndex((({x:e,y:n})=>o?p(e,de,t)&&p(n,0,i):p(e,0,t)&&p(n,0,i-de)));if(m<0)return;const d=c[m-1],f=c[m],u=c[m+1];let g=f,x=0;if(0===m)u&&(x=Math.atan2(u.y-f.y,u.x-f.x));else{const e=(f.y-d.y)/(f.x-d.x),t=f.y-f.x*e,i=f.x-f.y/e;g=t>=0?{x:0,y:t}:{x:i+10/e,y:10},x=Math.atan2(f.y-d.y,f.x-d.x)}e.save(),e.translate(g.x,g.y),e.rotate(x),e.font=`${r}px ${a}`,e.textAlign="start";const y=e.measureText(s),T=y.width+4,E=y.actualBoundingBoxAscent+y.actualBoundingBoxDescent+4,S=T<h?5:(h-T)/2,v=x>=0?-5:15;e.globalAlpha=.75,e.fillStyle=n,e.fillRect(S-2,v-E+2,T,E),e.fillStyle=l,e.globalAlpha=1,e.fillText(s,S,v),e.restore()}),[]),h=a(((t,{getTimePixel:i,getSpacePixel:o,swapAxis:n})=>{if(!e.points.length)return;const r=e.points[0],a=e.fromEnd||O,s=f(e.points),l=e.toEnd||O;B(t,i(r.time),o(r.position),n,"from",te(e,0),a),B(t,i(s.time),o(s.position),n,"to",te(e,e.points.length-1,!0),l)}),[e]),m=a(((t,i)=>{let o=0;const n=new Set(t.map((e=>e.position)));return e.points.forEach((({position:e,time:t},i,r)=>{if(i>0){const{position:a,time:s}=r[i-1];a===e&&n.has(e)&&(o+=t-s)}})),i.forEach((({x:e,y:t},i,n)=>{if(i>0){const{x:r,y:a}=n[i-1];o+=Math.sqrt(Math.pow(r-e,2)+Math.pow(a-t,2))}})),o}),[e]),d=a(((e,t)=>{if(!n)return;const o=n.width||1,a=Ie[i],s=2*n.offset+a.width,l=n.backgroundColor||"#fff",c=r(t);e.save(),e.beginPath();const h=(t,i=n.color)=>{e.strokeStyle=i,e.lineWidth=t,e.lineCap="round",c.forEach((({x:t,y:i},o)=>{t===c[o-1]?.x&&i===c[o-1]?.y||(0===o?e.moveTo(t,i):e.lineTo(t,i))})),e.stroke()};h(s+2*o),h(s,l),e.restore()}),[n,r,i]);ee("paths",a(((o,n)=>{d(o,n),o.strokeStyle=t,o.lineWidth=7,o.globalAlpha=.2,o.lineCap="round",l(o,n);const a=Ie[i];o.strokeStyle=t,o.lineWidth=a.width,o.setLineDash(a.dashArray||[]),o.globalAlpha=a.opacity||1,o.lineCap=a.lineCap||"square",o.beginPath();const s=r(n);if(s.forEach((({x:e,y:t},i)=>{i?o.lineTo(e,t):o.moveTo(e,t)})),o.stroke(),o.setLineDash([]),o.lineWidth=a.endWidth,h(o,n),!n.hidePathsLabels){const i=m(n.operationalPoints,s);c(o,n,e.label,t,s,i)}}),[t,l,i,r,h,m,c,d,e.label]));return J("paths",a(((t,n,a)=>{const{registerPickingElement:l}=n;r(n).forEach(((n,r,s)=>{if(r){const c=s[r-1],h={type:"segment",pathId:e.id,from:c,to:n},m=j(V(l(h)));C(t,c,n,m,Ie[i].width+o,!0,a)}})),s(n).forEach((n=>{const r={type:"point",pathId:e.id,point:n},s=j(V(l(r)));D(t,n,2*(Ie[i].width+o),s,0,a)}))}),[r,s,i,e.id,o])),null};const Me=o=>{const{operationalPoints:n,spaceOrigin:l,spaceScales:h,timeOrigin:m,timeScale:d,xOffset:p=0,yOffset:f=0,swapAxis:u,onHoveredChildUpdate:g,children:x,enableSnapping:y,hideGrid:T,hidePathsLabels:E,showTicks:S,theme:v,onPan:w,onZoom:I,onClick:R,onMouseMove:P,...O}=o,[k,A]=t(null),[G,C]=t(null),L=s((()=>({...ce,...v})),[v]),{width:D,height:H}=M(k),F=s((()=>JSON.stringify({operationalPoints:n,width:D,height:H,spaceOrigin:l,spaceScales:h,timeOrigin:m,timeScale:d,xOffset:p,yOffset:f,swapAxis:u,hideGrid:T,hidePathsLabels:E,showTicks:S})),[n,D,H,l,h,m,d,p,f,u,T,E,S]),W=s((()=>{const e=function(e,t){let i=e;if(t.some((e=>e.to<i||(i=e.to,!1))))throw new Error("Invalid scale: 'to' must be greater than previous 'to'.");if(t.some((e=>("size"in e?e.size:e.coefficient)<=0)))throw new Error("Invalid scale: 'to' must be greater than 'from'.");const o=[];let n=0;i=e;for(let e=0;e<t.length;e++){const r=t[e],a="coefficient"in r?r.coefficient:(r.to-i)/r.size,s="coefficient"in r?(r.to-i)/r.coefficient:r.size;o.push({from:i,to:r.to,pixelFrom:n,pixelTo:n+s,coefficient:a}),n+=s,i=r.to,e&&(o[e].previous=o[e-1],o[e-1].next=o[e])}return function e(t){if(0===t.length)return{coefficient:1,from:-1/0,to:1/0,pixelFrom:-1/0,pixelTo:1/0};if(1===t.length)return t[0];{const i=Math.ceil(t.length/2);return{limit:t[i-1].to,pixelLimit:t[i-1].pixelTo,from:t[0].from,to:t[t.length-1].to,pixelFrom:t[0].pixelFrom,pixelTo:t[t.length-1].pixelTo,left:e(t.slice(0,i)),right:e(t.slice(i))}}}(o)}(l,h),t=u?"y":"x",i=u?"x":"y";let o,r;u?(o=f,r=p):(o=p,r=f);const a=function(e,t,i){return o=>t+(o-e)/i}(m,o,d),s=(c=r,g=e,(e,t)=>{const{from:i,pixelFrom:o,coefficient:n}=ye(e,g,t);return c+o+(e-i)/n});var c,g;const x=function(e,t,i,o){return({time:n,position:r})=>({[i]:e(n),[o]:t(r)})}(a,s,t,i),v=function(e,t,i){return o=>(o-t)*i+e}(m,o,d),w=Te(l,r,e),I=function(e,t,i,o){return n=>({time:e(n[i]),position:t(n[o])})}(v,w,t,i),R=[];return{fingerprint:F,width:D,height:H,getTimePixel:a,getSpacePixel:s,getPoint:x,getTime:v,getSpace:w,getData:I,pickingElements:R,resetPickingElements:()=>{R.length=0},registerPickingElement:e=>(R.push(e),R.length-1),operationalPoints:n,spaceOrigin:l,spaceScaleTree:e,timeOrigin:m,timeScale:d,timePixelOffset:o,spacePixelOffset:r,timeAxis:t,spaceAxis:i,swapAxis:!!u,enableSnapping:!!y,hideGrid:!!T,hidePathsLabels:!!E,showTicks:!!S,theme:L}}),[F]),B=function(e){const[o,n]=t({isHover:!1,position:{x:NaN,y:NaN}}),r=a((t=>{e&&n((e=>({...e,down:{ctrl:t.ctrlKey,shift:t.shiftKey}})))}),[e]),s=a((()=>{e&&n((e=>({...e,down:void 0})))}),[e]),l=a((t=>{if(!e)return;const i=ge(t,e),{x:o,y:r}=i,a=e.offsetWidth,s=e.offsetHeight,l=o>=0&&o<=a&&r>=0&&r<=s;n((e=>({...e,position:i,isHover:l})))}),[e]);return i((()=>{if(e)return e.addEventListener("mousedown",r),()=>{e.removeEventListener("mousedown",r)}}),[e,r]),i((()=>(document.addEventListener("mouseup",s),()=>{document.removeEventListener("mouseup",s)})),[s]),i((()=>(document.addEventListener("mousemove",l),()=>{document.removeEventListener("mousemove",l)})),[l]),o}(k),{position:$,down:U,isHover:z}=B,{canvasContext:Z,hoveredItem:X}=Q(G,W,$),V=s((()=>{const e=y?function(e,t){return e&&t?ve(t.element)?t.element.point:we(t.element)?function(e,t,i){const{x:o,y:n}=e,{x:r,y:a}=t,{x:s,y:l}=i,c=s-r,h=l-a,m=c*c+h*h;if(0===m)return{x:r,y:a};let d=((o-r)*c+(n-a)*h)/m;return d<0?d=0:d>1&&(d=1),{x:r+d*c,y:a+d*h}}(e,t.element.from,t.element.to):e:e}(B.position,X):B.position;return{down:U,isHover:z,position:e,hoveredItem:X,data:W.getData(e)}}),[y,B.position,X,U,z,W]);return function(e,{position:o,hoveredItem:n,down:s,isHover:l},c,h){const m=r(h),d=r(c),[p,f]=t({type:"idle"});i((()=>{m.current=h}),[h.fingerprint]),i((()=>{d.current=c}),[c]);const u=a((t=>{if(!e)return;const{onClick:i}=d.current;i&&i({event:t,position:o,data:m.current.getData(o),hoveredItem:n,context:m.current})}),[e,n,o]),g=a((t=>{const{onZoom:i}=d.current;i&&e&&i({delta:xe(t),position:ge(t,e),event:t,context:m.current})}),[e]);i((()=>{if(e)return e.addEventListener("click",u),()=>{e.removeEventListener("click",u)}}),[e,u]),i((()=>{if(e)return e.addEventListener("wheel",g),()=>{e.removeEventListener("wheel",g)}}),[e,g]),i((()=>{const{onPan:e}=d.current;s?f({type:"panning",initialPosition:o,initialData:m.current.getData(o)}):("panning"===p.type&&e&&e({isPanning:!1,position:o,initialPosition:p.initialPosition,data:m.current.getData(o),initialData:p.initialData,context:m.current}),"idle"!==p.type&&f({type:"idle"}))}),[s]),i((()=>{const{onPan:e,onMouseMove:t}=d.current;t&&t({position:o,isHover:l,data:m.current.getData(o),hoveredItem:n,context:m.current}),"panning"===p.type&&e&&e({isPanning:!0,position:o,initialPosition:p.initialPosition,data:m.current.getData(o),initialData:p.initialData,context:m.current})}),[o.x,o.y])}(k,V,{onPan:w,onZoom:I,onClick:R,onMouseMove:P},W),i((()=>{g&&g({item:X,context:W})}),[X]),i((()=>{!function({breakpoints:e,timeRanges:t,timeCaptionsStyles:i,timeCaptionsPriorities:o,timeGraduationsStyles:n,timeGraduationsPriorities:r}){const a="SpaceTimeChartTheme is invalid:",s=e.length,l=t.length,c=new Set(o.flatMap((e=>e))),h=new Set(r.flatMap((e=>e)));if(o.length!==s)throw new Error(`${a}: timeCaptionsPriorities should have as much elements as breakpoints.`);if(o.some((e=>e.length!==l)))throw new Error(`${a}: each array in timeCaptionsPriorities should have as much elements as timeRanges.`);if(Array.from(c).some((e=>0!==e&&!i[e])))throw new Error(`${a}: all values (except 0s) from timeCaptionsPriorities should have a matching style in timeCaptionsStyles.`);if(r.length!==s)throw new Error(`${a}: timeGraduationsPriorities should have as much elements as breakpoints.`);if(r.some((e=>e.length!==l)))throw new Error(`${a}: each array in timeGraduationsPriorities should have as much elements as timeRanges.`);if(Array.from(h).some((e=>0!==e&&!n[e])))throw new Error(`${a}: all values (except 0s) from timeGraduationsPriorities should have a matching style in timeGraduationsStyles.`);if(!n[1])throw new Error(`${a}: there should be a timeGraduationsStyles for value 1.`)}(L)}),[L]),e.createElement("div",{...O,ref:A,className:c("relative space-time-chart",O.className),style:{background:L.background}},e.createElement("div",{ref:C,className:"absolute inset-0"}),e.createElement(b.Provider,{value:W},e.createElement(N.Provider,{value:Z},e.createElement(_.Provider,{value:V},!T&&e.createElement(e.Fragment,null,e.createElement(oe,null),e.createElement(ue,null),e.createElement(fe,null)),x))))};function be(e){return"conflict"===e.type}const Ne=[{opacity:.33,color:"#d91c1c",size:8},{opacity:.5,color:"#ff6868",size:4},{opacity:1,color:"#6b0000",size:0}],_e=({conflicts:e})=>{ee("paths",a(((t,{getTimePixel:i,getSpacePixel:o})=>{const n=Ne.map((()=>new Path2D));for(const t of e){const e=i(t.timeStart),r=o(t.spaceStart),a=i(t.timeEnd)-e,s=o(t.spaceEnd)-r;for(let t=0;t<Ne.length;t++){const i=Ne[t].size;n[t].rect(e-i,r-i,a+2*i,s+2*i)}}for(let e=0;e<Ne.length;e++)t.fillStyle=Ne[e].color,t.globalAlpha=Ne[e].opacity,t.fill(n[e])}),[e]));return J("paths",a(((t,{registerPickingElement:i,getTimePixel:o,getSpacePixel:n},r)=>{for(const[a,s]of e.entries()){const e=o(s.timeStart),l=n(s.spaceStart),c=o(s.timeEnd)-e,h=n(s.spaceEnd)-l,m=Ne[0].size;H(t,{x:e-m,y:l-m},c+2*m,h+2*m,j(V(i({type:"conflict",conflictIndex:a}))),r)}}),[e])),null},Oe=({position:t,children:i})=>e.createElement("div",{className:"spacetimechart-tooltip",style:{left:t.x,top:t.y}},i),ke=e=>(e/1e3).toLocaleString("en-US",{minimumFractionDigits:1,maximumFractionDigits:1}),Ae=({position:t,time:i,spaceStart:o,spaceEnd:n,timeStart:r,timeEnd:a,type:s,trains:l})=>e.createElement(Oe,{position:t},e.createElement("div",{className:"time"},new Date(i).toLocaleTimeString()),e.createElement("div",{className:"position-range"},e.createElement("div",{className:"start-position"},ke(o)),e.createElement("div",{className:"end-position"},ke(n))),e.createElement("div",{className:"type-and-duration"},e.createElement("div",null,s),e.createElement("div",null,Math.round((a-r)/1e3),"s")),e.createElement("div",{className:"trains"},l.join(", "))),Ge=({occupancyBlocks:e})=>(ee("background",a(((t,{getTimePixel:i,getSpacePixel:o})=>{for(const n of e){const e=i(n.timeStart),r=o(n.spaceStart),a=i(n.timeEnd)-e,s=o(n.spaceEnd)-r;t.fillStyle=n.color,t.fillRect(e,r,a,s)}}),[e])),null),Ce=({imageElement:e,...t})=>(ee("background",a(((i,o)=>{const n=i.createPattern(e,"repeat");n&&(i.fillStyle=n,z(i,t,o))}),[e,t])),null),Le=({workSchedules:o,imageUrl:n})=>{const[r,a]=t();return i((()=>{if(n){const e=new Image;e.src=n,e.onload=()=>{a(e)}}}),[n]),r?o.flatMap((t=>t.spaceRanges.map((([i,o])=>e.createElement(Ce,{key:`${t.type}-${t.timeStart}-${t.timeEnd}-${i}-${o}`,timeStart:t.timeStart,timeEnd:t.timeEnd,spaceStart:i,spaceEnd:o,imageElement:r}))))):null},De=({vertices:e,style:t})=>(ee("background",a(((i,{getSpacePixel:o,getTimePixel:n})=>{i.save(),i.fillStyle=t.backgroundColor??"lightblue",i.strokeStyle=t.borderColor??"lightblue",i.lineWidth=t.borderWidth??1,i.beginPath(),e.forEach((e=>{i.lineTo(n(e.time),o(e.position))})),i.closePath(),i.fill(),i.stroke(),i.restore()}),[e,t])),null);function He(e,t,i){e.save(),e.fillStyle="white",e.fillRect(t-1,i-1,3,3),e.fill(),e.fillStyle="black",e.fillRect(t,i,1,1),e.fill(),e.restore()}const Fe=e=>(ee("background",a(((t,i)=>{t.save(),t.fillStyle="#0000000D";const{areaTimeSize:o,areaSpaceSize:n}=z(t,e,i);if(o&&n){const e="x"===i.timeAxis?o:n,r="x"===i.timeAxis?n:o;t.lineWidth=1;for(let i=0;Math.abs(i)<Math.abs(e);i+=4*Math.sign(e))He(t,i,0),He(t,i,0+r);for(let i=0;Math.abs(i)<Math.abs(r);i+=4*Math.sign(r))He(t,0,i),He(t,0+e,i)}t.restore()}),[e])),null);function We(e,t){return{x:t.x-e.x,y:t.y-e.y}}function Be(e,t,i,o){const n=(e,t)=>e.x*t.y-e.y*t.x,r=We(t,e),a=We(o,i),s=n(r,a);if(0===s)return!1;const l=We(i,e),c=n(l,a)/s,h=n(l,r)/s;return p(c,0,1)&&p(h,0,1)}function $e(e,t,i){if(!i.length)return!1;if(1===i.length){const{x:o,y:n}=i[0];return p(o,0,e)&&p(n,0,t)}return i.slice(0,-1).map(((e,t)=>[e,i[t+1]])).some((([i,o])=>function(e,t,i,o){const n=({x:i,y:o})=>p(i,0,e)&&p(o,0,t);if(n(i)||n(o))return!0;const r={x:0,y:0},a={x:e,y:0},s={x:0,y:t},l={x:e,y:t};return Be(i,o,r,a)||Be(i,o,r,s)||Be(i,o,s,l)||Be(i,o,a,l)}(e,t,i,o)))}const Ue=32,ze=6e5,Ze=7500,Xe=10.5,Ve=e=>e.at(-1).position-e.at(0).position;const Ye=({waypoint:{name:t,secondaryCode:i,id:o,position:n,onClick:r},nameRef:a,isActive:s,isMenuActive:l})=>e.createElement("div",{className:c("flex waypoint items-baseline",{"waypoint-active":s,"menu-active":l}),id:o,onClick:()=>{r&&!l&&r(o)}},e.createElement("div",{className:"waypoint-position justify-self-start text-end"},(e=>Math.round(e/1e6*10)/10)(n)),e.createElement("div",{ref:a,className:"waypoint-name mx-2 justify-self-start"},t),e.createElement("div",{className:"waypoint-separator"}),e.createElement("div",{className:"waypoint-ch font-mono justify-self-end"},i),e.createElement("div",{className:"waypoint-separator"}),e.createElement("div",{className:"waypoint-type"}),e.createElement("div",{className:"waypoint-separator"})),je=({contents:t,activeWaypointId:i,activeWaypointRef:o})=>e.createElement("div",{className:"waypoint-list"},t.map(((t,n)=>{return null!=(r=t)&&"object"==typeof r&&"id"in r&&"position"in r?e.createElement("div",{key:t.id,className:"waypoint-wrapper flex justify-start",style:t.styles},e.createElement(Ye,{waypoint:t,nameRef:i===t.id?o:void 0,isActive:i===t.id,isMenuActive:!!i})):e.createElement("div",{key:n},t);var r}))),qe=({zoomYIn:i,zoomYOut:o,resetZoom:n,yZoom:a=1,contents:s,waypointMenuData:h,isProportional:m=!0,toggleMode:d,children:p,height:f=521})=>{const[u,g]=t(),T=r(null);return l((()=>{const e=h?.manchetteWrapperRef?.current?.getBoundingClientRect().top,t=T?.current?.getBoundingClientRect().top;g(e&&t?t-e:void 0)}),[h]),e.createElement("div",{className:"manchette-container"},h?.menu&&h.activeWaypointId&&e.createElement("div",{className:"menu-wrapper",style:{top:u}},h.menu),e.createElement("div",{className:"bg-white-100 border-r border-grey-30",style:{minHeight:`${f}px`}},e.createElement(je,{contents:s,activeWaypointId:h?.activeWaypointId,activeWaypointRef:T}),p),e.createElement("div",{className:"manchette-actions"},e.createElement("div",{className:"zoom-buttons"},e.createElement("button",{className:"zoom-out",onClick:o,disabled:a<=1||!!h?.activeWaypointId},e.createElement(x,null)),e.createElement("button",{className:"zoom-in",onClick:i,disabled:a>=Xe||!!h?.activeWaypointId},e.createElement(y,null)),e.createElement("button",{disabled:!!h?.activeWaypointId,className:"zoom-reset",onClick:n},"Fit")),e.createElement("div",{className:"flex items-center ml-auto text-sans font-semibold"},e.createElement("button",{disabled:!!h?.activeWaypointId,className:"toggle-mode",onClick:d},e.createElement("div",{className:"flex flex-col items-end pr-2"},e.createElement("span",{className:c({"text-grey-30":!m})},"Km"),e.createElement("span",{className:c({"text-grey-30":m})},"Linéaire"))))))},Ke=e=>ze*Math.pow(.0010416666666666667,e/100),Qe=e=>100*Math.log(e/ze)/Math.log(.0010416666666666667),Je=(e,t,i)=>e*Math.pow(t/e,(i-1)/9.5),et=(e,t,i,o)=>{const n=m(i,0,100);return{xZoom:n,xOffset:o-(o-t)*Ke(e)/Ke(n)}},tt=(e,{height:t,isProportional:i,yZoom:o},n,r)=>{if(e.length<2)return[];const a=Ve(e),s=(e=>e-40-Ue)(t);if(!i)return e.map(((t,i)=>{const n=e.at(i+1);return{...t,styles:{height:`${Ue*(n?o:1)}px`}}}));const l=((e,t,i,o)=>{const n=e=>e.position/t*i,r=e.at(0),a=e.at(-1);if(!r||!a)return e;const s=[...e].sort(((e,t)=>(t.weight??0)-(e.weight??0))),l=[r,a];for(const e of s)!l.some((t=>Math.abs(n(e)-n(t))<o))&&l.push(e);return l.sort(((e,t)=>e.position-t.position))})(e,a,s,Ue/o),c=Je(n,r,o);return l.map(((e,t)=>{const i=l.at(t+1),o=i?(i.position-e.position)/c:Ue;return{...e,styles:{height:`${Math.round(o)}px`}}}))},it=({waypoints:e,projectPathTrainResult:o,manchetteWithSpaceTimeChartRef:n,selectedTrain:r,height:l=561,spaceTimeChartRef:c,defaultTimeOrigin:h=0,defaultSpaceOrigin:d=0})=>{const[p,f]=t(!1),[u,g]=t({xZoom:Qe(7500),yZoom:1,timeOrigin:h,spaceOrigin:d,xOffset:0,yOffset:0,scrollTo:null,panning:null,zoomMode:!1,rect:null,pixelRect:null,isProportional:!0,waypointsChart:[],scales:[]}),{xZoom:x,yZoom:y,timeOrigin:T,spaceOrigin:E,xOffset:S,yOffset:v,scrollTo:w,panning:I,zoomMode:R,rect:P,pixelRect:M,isProportional:b}=u,N=a((e=>{g((t=>({...t,timeOrigin:e})))}),[]),_=((e,t)=>s((()=>e.flatMap((e=>e.spaceTimeCurves.map(((i,o)=>{return{id:`${e.id}-${o}`,label:e.name,color:"#8A714B",level:t&&t===e.id?1:2,points:(n=i,r=e.departureTime,n.positions.map(((e,t)=>({time:n.times[t]+r.getTime(),position:e}))))};var n,r}))))),[e,t]))(o,r),O=l-40,k=O-16,A=O-Ue,G=Ve(e),{minZoomMillimeterPerPx:C,maxZoomMillimeterPerPx:L}=((e,t,i)=>({minZoomMillimeterPerPx:i/t,maxZoomMillimeterPerPx:5e5/e}))(k,A,G),D=s((()=>tt(e,{height:l,isProportional:b,yZoom:y},C,L)),[e,l,b,y,C,L]),H=s((()=>D.map((e=>({id:e.id,label:e.id,position:e.position,importanceLevel:1})))),[D]),F=s((()=>((e,{isProportional:t,yZoom:i},o,n)=>e.length<2?[]:t?[{from:e.at(0).position,to:e.at(-1).position,...t?{coefficient:Je(o,n,i)}:{size:Ue*(e.length-1)*i}}]:e.slice(0,-1).map(((t,o)=>{const n=e[o+1];return{from:t.position,to:n.position,size:Ue*i}})))(H,{isProportional:b,yZoom:y},C,L)),[H,l,b,y,C,L]),W=a((({scales:{chosenTimeScale:e,chosenSpaceScale:t},overrideState:i})=>{g((o=>{if(o.zoomMode||!o.rect)return o;const n=m(e,625,ze),r=Qe(n),a=Math.min(Number(o.rect.timeStart),Number(o.rect.timeEnd)),s=(T-a)/n;let l=y,c=v;if(t){const e=m(t,L,C);l=((e,t,i)=>9.5*Math.log(i/e)/Math.log(t/e)+1)(C,L,e);const i=Math.min(o.rect.spaceStart,o.rect.spaceEnd);c=Math.abs(E-i)/e}return{...o,xZoom:r,yZoom:l,xOffset:s,yOffset:c,scrollTo:c,...i}}))}),[T,E,C,L,v,y]);i((()=>{if(P&&!R&&c?.current){const{timeStart:e,timeEnd:t,spaceStart:i,spaceEnd:o}=P,n=Math.abs(Number(t)-Number(e)),r=Math.abs(o-i),a=n/c.current.clientWidth;if(b){W({scales:{chosenTimeScale:a,chosenSpaceScale:r/k},overrideState:{rect:null}})}else if(M){const e=Ue*y,{yStart:t,yEnd:i}=M,o=Math.abs(i-t)/e;let n=k/o;const r=k/(2+Ue/n);n=Math.min(n,r);const s=n/Ue,l=(v+Math.min(t,i)-16)/e*n;W({scales:{chosenTimeScale:a},overrideState:{rect:null,pixelRect:null,yZoom:s,yOffset:l,scrollTo:l}})}}}),[u.rect,u.zoomMode,W,k,b,M,P,c,v,y,R]);const B=a((()=>{const e=b?Xe:(k-Ue)/64,t=Math.min(y+.5,e);if(t!==y){const e=v*(t/y);g((i=>({...i,yZoom:t,yOffset:e,scrollTo:e})))}}),[y,v,k,b]),$=a((()=>{const e=Math.max(1,y-.5);if(e!==y){const t=v*(e/y);g((i=>({...i,yZoom:e,yOffset:t,scrollTo:t})))}}),[y,v]),U=a(((e,t=(c?.current?.offsetWidth||0)/2)=>{g((i=>({...i,...et(i.xZoom,i.xOffset,e,t)})))}),[c]);i((()=>{null!==w&&n.current&&n.current.scrollTo({top:w,behavior:"instant"})}),[w,n]);const z=a((()=>{g((e=>({...e,yZoom:1})))}),[]),Z=a((()=>{if(!p&&n.current){const{scrollTop:e}=n.current;(e||0===e)&&g((t=>({...t,yOffset:e})))}}),[p,n]),X=a((e=>{"Shift"===e.key&&f(!0)}),[]),V=a((e=>{"Shift"===e.key&&f(!1)}),[]);i((()=>(window.addEventListener("keydown",X),window.addEventListener("keyup",V),()=>{window.removeEventListener("keydown",X),window.removeEventListener("keyup",V)})),[X,V]);const Y=a((()=>{g((e=>({...e,isProportional:!e.isProportional})))}),[]),j=a((()=>{g((e=>({...e,zoomMode:!e.zoomMode})))}),[]),q=s((()=>({contents:D,zoomYIn:B,zoomYOut:$,resetZoom:z,toggleMode:Y,yZoom:y,isProportional:b,yOffset:v})),[D,B,$,z,Y,y,b,v]),K=s((()=>({operationalPoints:H,spaceScales:F,timeScale:Ke(x),paths:_,xOffset:S,yOffset:14-v,timeOrigin:T,spaceOrigin:E,rect:P,onZoom:({delta:e,position:t})=>{p&&U(x+e,t.x)},onPan:e=>{const{initialData:t,data:i,initialPosition:o,position:r,isPanning:a,context:{width:s,getData:l}}=e,c=(h=o,{x:(d=r).x-h.x,y:d.y-h.y});var h,d;g((e=>{if(!a)return{...e,panning:null,zoomMode:!1};if(u.zoomMode){const n=l({x:0,y:0}),a=l({x:s,y:O}),c=m(t.time,n.time,a.time),h=m(i.time,n.time,a.time),d=m(t.position,n.position,a.position),p=m(i.position,n.position,a.position),f={timeStart:new Date(c),timeEnd:new Date(h),spaceStart:d,spaceEnd:p};let u=null;if(!b){u={xStart:m(o.x,0,s),xEnd:m(r.x,0,s),yStart:m(o.y,0,O),yEnd:m(r.y,0,O)}}return{...e,rect:f,pixelRect:u}}if(!I)return{...e,panning:{initialOffset:{x:S,y:v}}};const h={...e},{initialOffset:d}=I;h.xOffset=d.x+c.x;const p=d.y-c.y;return n.current&&p>=0&&p+n.current.offsetHeight<n.current.scrollHeight&&(h.yOffset=p,n.current.scrollTop=p),h}))}})),[H,F,x,_,S,p,u,I,v,n,U,b,P,E,T,O]),Q=s((()=>Ke(x)),[x]),J=s((()=>Je(C,L,y)),[y,C,L]);return s((()=>({manchetteProps:q,spaceTimeChartProps:K,handleScroll:Z,handleXZoom:U,xZoom:x,toggleZoomMode:j,zoomMode:R,rect:P,timeScale:Q,spaceScale:J,setTimeOrigin:N})),[q,K,Z,U,x,R,P,J,Q,j,N])},ot=({waypoints:t,projectPathTrainResult:i,selectedTrain:o,height:n=561,children:a,header:s,manchetteProps:l,spaceTimeChartProps:c})=>{const h=r(null),m=r(null),{manchetteProps:d,spaceTimeChartProps:p,handleScroll:f}=it({waypoints:t,projectPathTrainResult:i,manchetteWithSpaceTimeChartRef:h,selectedTrain:o,height:n,spaceTimeChartRef:m,defaultTimeOrigin:Math.min(...i.map((e=>+e.departureTime)))});return e.createElement("div",{className:"manchette-space-time-chart-wrapper"},e.createElement("div",{className:"header bg-ambientB-5 w-full border-b border-grey-30",style:{height:"40px"}},s),e.createElement("div",{ref:h,className:"manchette flex",style:{height:`${n}px`},onScroll:f},e.createElement(qe,{...d,...l}),e.createElement("div",{className:"space-time-chart-container w-full sticky",ref:m,style:{bottom:0,left:0,top:2,height:n-6+"px"}},e.createElement(Me,{className:"inset-0 absolute h-full",...p,...c},p.paths.map((t=>e.createElement(Pe,{key:t.id,path:t,color:t.color,level:t.level}))),a))))},nt=({reset:t,openSettingsPanel:i,store:o})=>e.createElement("div",{id:"interaction-button-container",className:"z-10"},e.createElement("div",{className:"zoom-buttons"},e.createElement("button",{className:c("interaction-button reset-button",{inactive:1==o.ratioX&&0==o.leftOffset}),onClick:()=>t()},e.createElement(T,null)),e.createElement("button",{className:"interaction-button plus-button inactive"},e.createElement(E,null)),e.createElement("button",{className:"interaction-button inactive"},e.createElement(S,null))),e.createElement("button",{className:"interaction-button elipsis-button",onClick:()=>i()},e.createElement(v,null))),rt={Y_LEFT_VERTICAL:30,Y_LEFT_HORIZONTAL:22,Y_RIGHT_VERTICAL:36,Y_RIGHT_HORIZONTAL:42},at={MARGIN_LEFT:48,MARGIN_RIGHT:12,MARGIN_TOP:27,MARGIN_BOTTOM:52.5,CURVE_MARGIN_TOP:40,CURVE_MARGIN_SIDES:16,ELECTRICAL_PROFILES_MARGIN_TOP:8,RIGHT_TICK_MARGINS:60,OFFSET_RIGHT_AXIS:42},st={ELECTRICAL_PROFILES_HEIGHT:56,POWER_RESTRICTIONS_HEIGHT:40,SPEED_LIMIT_TAGS_HEIGHT:40},lt={electricalProfiles:st.ELECTRICAL_PROFILES_HEIGHT,powerRestrictions:st.POWER_RESTRICTIONS_HEIGHT},ct="rgb(250, 249, 245)",ht="rgb(247, 246, 238)",mt="rgb(242, 240, 228)",dt="#front-interactivity-layer",pt=["energySource","tractionStatus","declivities","electricalProfiles","powerRestrictions"],ft=["steps","declivities","speedLimits","electricalProfiles","powerRestrictions","speedLimitTags"],ut=g(0,0,0),gt=g(255,104,104),xt=g(217,28,28),yt=g(121,118,113),Tt=g(49,46,43),Et=g(33,112,185),St=g(234,167,43),vt=g(255,255,255),wt={"#216482":"#E5F7FF","#D91C1C":"#F15981","#494641":"#F2F0E4","#EAA72B":"#EAA72B","#94918E":"#94918E"},It=e=>e.layersDisplay.speedLimits&&e.mrsp?Math.max(...e.mrsp.values.map((({speed:e})=>e))):Math.max(...e.speeds.map((({value:e})=>e))),Rt=e=>0===e.length?0:e[e.length-1].position.start,Pt=(e,t,i)=>{e.clearRect(0,0,t,i)},Mt=(e,t,i=!0)=>{const o=[t.electricalProfiles?st.ELECTRICAL_PROFILES_HEIGHT:0,t.powerRestrictions?st.POWER_RESTRICTIONS_HEIGHT:0,t.speedLimitTags?st.SPEED_LIMIT_TAGS_HEIGHT:0].reduce(((e,t)=>e+t),0);return e+(i?o:-o)},bt=(e,t,i=!1)=>{let o=0;const{electricalProfiles:n,powerRestrictions:r}=t;return n&&(o=lt.electricalProfiles),r&&i&&(o+=lt.powerRestrictions),e+o-at.MARGIN_BOTTOM},Nt=(e,t,i,o,n)=>e*((i-n.CURVE_MARGIN_SIDES-n.MARGIN_LEFT-n.MARGIN_RIGHT)/t)*o+n.MARGIN_LEFT+n.CURVE_MARGIN_SIDES/2,_t=(e,t,i,o,n)=>{const{MARGIN_LEFT:r,MARGIN_RIGHT:a}=i;e.beginPath(),e.strokeStyle=t,e.lineWidth=1,e.moveTo(r,n),e.lineTo(o-a,n),e.stroke()},Ot=(e,t,i,o,n,r)=>{const{MARGIN_LEFT:a,MARGIN_RIGHT:s}=i;e.beginPath(),e.fillStyle=t,e.fillRect(a,n-r+1,o-a-s,r)},kt=(e,t)=>"speedLimits"===t?e.mrsp:"electricalProfiles"===t?e.electricalProfiles:"powerRestrictions"===t?e.powerRestrictions:"speedLimitTags"!==t||e.speedLimitTags,At=e=>{const t=e.slopes,i=Math.min(...t.map((({value:e})=>e))),o=Math.max(...t.map((({value:e})=>e)));return{minGradient:i,maxGradient:o,slopesRange:o-i,maxPosition:Math.max(...t.map((({position:e})=>e.start)))}},Gt=e=>new Promise(((t,i)=>{const o=new Image;o.onload=()=>t(o),o.onerror=e=>i(e),o.src=e})),Ct=e=>{const t=new Blob([e],{type:"image/svg+xml"});return URL.createObjectURL(t)},Lt=(e,t,i)=>{if(0===e.length)return-1;if(t<i(e[0]))return 0;if(t>i(e[e.length-1]))return e.length-1;let o=0,n=e.length;for(;o<n;){const r=Math.floor((o+n)/2);i(e[r])<t?o=r+1:n=r}return t!==i(e[o])&&o--,o},Dt=(e,t,i,o,n=0)=>e/t*((i-at.MARGIN_LEFT-at.MARGIN_RIGHT-at.CURVE_MARGIN_SIDES)*o)+(at.CURVE_MARGIN_SIDES/2+at.MARGIN_LEFT+n),Ht=(e,t,i,o,n)=>e===i?t:t+(o-t)/(i-e)*(n-e),Ft=(e,t,i,o,n=8)=>{const r=(({elements:e,getPosition:t,getWeight:i,minSpace:o})=>{const n=[...e].sort(((e,t)=>(i(t)??0)-(i(e)??0))),r=[];for(const e of n){const i=t(e);!r.some((e=>Math.abs(i-e.position)<o))&&r.push({element:e,position:i})}return r.sort(((e,i)=>t(e.element)-t(i.element))).map((({element:e})=>e))})({elements:e,getPosition:e=>Dt(e.position.start,o,i,t),getWeight:e=>e.value.weight,minSpace:n});return r},Wt=(e,t,i)=>{const{ratioX:o,leftOffset:n}=i,r=Rt(i.speeds);return(e-n-at.CURVE_MARGIN_SIDES/2)*r/((t-at.MARGIN_LEFT-at.MARGIN_RIGHT-at.CURVE_MARGIN_SIDES)*o)},Bt=(e,t,i)=>{const{ratioX:o,leftOffset:n,stops:r}=i,a=Rt(i.speeds),s=Ft(r,o,t,a);let l=0;if(s.length>1){const o=(c=Wt(e,t,i),h=0,m=a,Math.min(Math.max(c,h),m)),n=Lt(s,o,(e=>e.position.start)),r=Math.min(n+1,s.length-1);l=o-s[n].position.start<s[r].position.start-o?n:r}else{if(1!==s.length)return null;l=0}var c,h,m;const d=s[l].position.start,p=Dt(d,a,t,o,n);return Math.abs(p-(e+at.MARGIN_LEFT))<6?s[l]:null},$t=({globalHeight:o,color:n,store:r,setStore:a,setIsMouseHoveringSettingsPanel:s,translations:l})=>{const[c,h]=t("442px");return i((()=>{const e=Mt(0,r.layersDisplay);o<521.5+e&&h(o-e-79.5+"px")}),[o,r.layersDisplay]),e.createElement("div",{id:"settings-panel",style:{background:`rgba(${n.substring(4,n.length-1)}, 0.4)`,height:c},className:"font-sans",onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1)},e.createElement("div",{className:"settings-panel-section"},e.createElement("div",{className:"settings-panel-section-title"},e.createElement("span",null,l?.layersDisplay.context||"Context")),ft.map((t=>e.createElement("div",{key:t,className:"selection"},e.createElement(I,{label:l?.layersDisplay[t]||t,checked:r.layersDisplay[t],disabled:!kt(r,t),onChange:()=>{a((e=>({...e,layersDisplay:{...e.layersDisplay,[t]:!e.layersDisplay[t]}})))}}))))),e.createElement("div",{className:"settings-panel-section right"},e.createElement("div",{className:"settings-panel-section-title"},e.createElement("span",null,l?.detailsBoxDisplay.reticleInfos||"Reticle infos")),pt.map((t=>e.createElement("div",{key:t,className:"selection"},e.createElement(I,{label:l?.detailsBoxDisplay[t]||t,checked:r.detailsBoxDisplay[t],onChange:()=>{a((e=>({...e,detailsBoxDisplay:{...e.detailsBoxDisplay,[t]:!e.detailsBoxDisplay[t]}})))}}))))),e.createElement("button",{id:"close-settings-panel",onClick:()=>(s(!1),void a((e=>({...e,isSettingsPanelOpened:!1}))))},e.createElement("span",null,e.createElement(w,null))))},Ut=()=>P.zoom().transform(R.select(dt),P.zoomIdentity),{MARGIN_LEFT:zt,MARGIN_RIGHT:Zt,MARGIN_TOP:Xt,MARGIN_BOTTOM:Vt}=at,Yt=({ctx:e,width:t,height:i,store:o})=>{const{stops:n,ratioX:r,leftOffset:a,cursor:s}=o;if(0===n.length)return;Pt(e,t,i);const l=Rt(o.speeds),c=Ft(n,r,t,l);e.save(),e.translate(a,0),e.strokeStyle=Et.alpha(.5).hex(),e.lineWidth=1,e.lineCap="round",e.setLineDash([1,6]),e.beginPath(),c.forEach((({position:o})=>{const n=Dt(o.start,l,t,r);e.moveTo(n,Xt),e.lineTo(n,i-Vt)})),e.stroke(),e.lineWidth=2,e.fillStyle=yt.hex(),e.strokeStyle=yt.hex(),e.setLineDash([]);const h=s.x?Bt(s.x,t,o):null;c.forEach((({position:o})=>{if(h&&o.start===h.position.start)return;const n=Dt(o.start,l,t,r);e.beginPath(),e.roundRect(n-.5,i-6-Vt-1,1,6,[1,1,0,0]),e.fill(),e.closePath(),e.stroke()})),e.restore();const m=Ft(c,r,t,l,25),d=[],p=[];m.forEach((e=>{const i=Dt(e.position.start,l,t,r);s.x&&i<s.x+zt-a&&(d.push(e),d.length>4&&d.shift()),s.x&&i>s.x+zt-a&&p.length<4&&p.push(e)})),m.forEach((({position:o,value:n})=>{if(h&&o.start===h.position.start)return;e.save();const s=Dt(o.start,l,t,r,a),c=i-6-Vt-8;e.translate(s,c),e.rotate(-40*Math.PI/180),d.some((e=>e.position.start===o.start))||p.some((e=>e.position.start===o.start))?e.fillStyle=ut.hex():e.fillStyle=Tt.alpha(.2).hex(),e.font="normal 12px IBM Plex Sans",e.textAlign="left",e.fillText(n.name,0,0),e.restore()})),e.clearRect(0,0,zt,i),e.clearRect(t-Zt,0,Zt,i),e.clearRect(0,0,t,Xt),e.clearRect(0,i-Vt,t,Vt)},jt=(e,{width:t,height:o,store:n,setStore:a})=>{const s=r(null);return i((()=>{const i=s.current.getContext("2d");e({ctx:i,width:t,height:o,store:n,setStore:a})}),[t,o,n]),s},qt=({width:t,height:i,store:o})=>{const n=jt(Yt,{width:t,height:i,store:o});return e.createElement("canvas",{id:"steps-layer",className:"absolute rounded-t-xl",ref:n,width:t,height:i})},{CURVE_MARGIN_TOP:Kt,MARGIN_RIGHT:Qt,MARGIN_LEFT:Jt,MARGIN_BOTTOM:ei,MARGIN_TOP:ti}=at,ii=({ctx:e,width:t,height:i,store:o})=>{const{mrsp:n,trainLength:r,ratioX:a,leftOffset:s}=o;if(!n)return;Pt(e,t,i),e.save(),e.translate(s,0);const l=i-ei-ti,c=It(o),h=Rt(o.speeds);e.lineCap="round";let m=Dt(0,h,t,a),d=null;for(let i=0;i<n.values.length;i++){const{speed:o,isTemporary:s}=n.values[i],p=i==n.values.length-1,f=p?h:n.boundaries[i],u=Dt(f,h,t,a),g=l-o/c*(l-Kt)+ti;null!==d&&(e.beginPath(),e.strokeStyle=gt.alpha(.5).hex(),e.lineWidth=.5,e.moveTo(m,d),e.lineTo(m,g),e.stroke());const x=s?St:xt,y=e.createLinearGradient(0,g,0,g-16);s?y.addColorStop(0,x.alpha(.23).hex()):y.addColorStop(0,x.alpha(.15).hex()),y.addColorStop(1,x.alpha(0).hex()),e.fillStyle=y,e.rect(m,g,u-m,-16),e.fill();let T=null;!p&&n.values[i+1].speed>o&&(T=Dt(Math.min(f+r/1e3,h),h,t,a)),e.beginPath(),e.lineWidth=1,e.strokeStyle=x.hex(),e.moveTo(m,g),e.lineTo(T??u,g),null!==T&&(e.moveTo(T,g-4),e.lineTo(T,g+4)),e.stroke(),m=u,d=g}e.restore(),e.clearRect(0,0,Jt,i),e.clearRect(t-Qt,0,Qt,i)},oi=({width:t,height:i,store:o})=>{const n=jt(ii,{width:t,height:i,store:o});return e.createElement("canvas",{id:"speed-limits-layer",className:"absolute rounded-t-xl",ref:n,width:t,height:i})},{CURVE_MARGIN_TOP:ni,CURVE_MARGIN_SIDES:ri}=at,ai=(e,t,i)=>{const{maxSpeed:o,maxPosition:n,ratioX:r}=t,{width:a,height:s}=e,l=ri/2,c=s-ni,h=(a-ri)/n*r,m=[];return i.forEach((({position:e,value:t})=>{const i=t/o,n=e.start*h+l,r=s-i*c;m.push({x:n,y:r})})),m.push({x:n*h+l,y:s}),m.push({x:l,y:s}),m},si=({ctx:e,width:t,height:i,store:o})=>{const{speeds:n,ecoSpeeds:r,ratioX:a,leftOffset:s}=o,l=g(17,101,180),c=g(7,69,128);Pt(e,t,i),e.save(),e.translate(s,0);const h=It(o),m=Rt(o.speeds),d=ai({width:t,height:i},{maxSpeed:h,maxPosition:m,ratioX:a},n),p=ai({width:t,height:i},{maxSpeed:h,maxPosition:m,ratioX:a},r);e.beginPath(),e.lineWidth=.5,e.strokeStyle=l.hex(),e.fillStyle=l.alpha(.15).hex(),d.forEach((({x:t,y:i})=>{e.lineTo(t,i)})),e.fill(),e.beginPath(),d.slice(0,d.length-2).forEach((({x:t,y:i})=>{e.lineTo(t,i)})),e.stroke(),e.beginPath(),e.fillStyle="rgba(255, 255, 255)",e.strokeStyle=c.hex(),e.globalCompositeOperation="destination-out",p.forEach((({x:t,y:i})=>{e.lineTo(t,i)})),e.fill(),e.beginPath(),e.globalCompositeOperation="source-over",p.slice(0,p.length-2).forEach((({x:t,y:i})=>{e.lineTo(t,i)})),e.stroke(),e.restore()},li=({width:t,height:i,store:o})=>{const n=jt(si,{width:t,height:i,store:o});return e.createElement("canvas",{id:"curve-layer",className:c("absolute rounded-t-xl",{"bg-white-25":!o.layersDisplay.declivities}),ref:n,width:t,height:i})},{CURVE_MARGIN_SIDES:ci,MARGIN_TOP:hi,MARGIN_BOTTOM:mi,RIGHT_TICK_MARGINS:di}=at,pi=({ctx:e,width:t,height:i,store:o})=>{const{slopes:n,ratioX:r,leftOffset:a}=o,{maxGradient:s}=At(o),l=Rt(o.speeds);if(!n||0===n.length)return void console.error("Slopes data is missing or empty.");Pt(e,t,i),e.save(),e.translate(a,0);const c=i-hi-mi-di/2,h=hi+di/2+c/2;e.fillStyle="#CFDDCE";try{const i=(t-ci)/l*r;for(let t=0;t<n.length-1;t++){const{position:o,value:r}=n[t],{position:a}=n[t+1],l=o.start*i+ci/2,m=a.start*i+ci/2-l,d=r/s*(c/2),p=r>=0?h-d:h;e.fillRect(l,p,m,Math.abs(d))}}catch(e){console.error("Error while drawing declivity:",e)}e.restore()},fi=({width:t,height:i,store:o})=>{const n=jt(pi,{width:t,height:i,store:o});return e.createElement("canvas",{id:"declivity-layer",className:c("absolute rounded-t-xl",{"bg-white-25":o.layersDisplay.declivities}),ref:n,width:t,height:i})},ui=e=>e>7?7:e,gi=({ctx:e,width:t,height:i,store:o})=>{const{electricalProfiles:n,ratioX:r,leftOffset:a,cursor:s}=o,{ELECTRICAL_PROFILES_HEIGHT:l}=st;if(!n)return;Pt(e,t,i);const c=i-l;e.save(),e.translate(a,0);const h=Rt(o.speeds),{MARGIN_TOP:m,MARGIN_BOTTOM:d,MARGIN_LEFT:p,MARGIN_RIGHT:f,CURVE_MARGIN_SIDES:u,ELECTRICAL_PROFILES_MARGIN_TOP:g}=at;Ot(e,ct,at,t,c,l),n.forEach((i=>{const o=Nt(i.position.start,h,t,r,at),n=Nt(i.position.end,h,t,r,at);let f=c-d+g;const u=n-o;if("neutral"===i.value.electricalProfile)e.fillStyle="#1F1B17",e.fillRect(o,f+28,u,9),e.clearRect(o,f+31,u,3);else{const{start:t,end:n}=i.position,{electricalProfile:r,color:h,heightLevel:g}=i.value,x=ui(g);if(e.fillStyle=h,"incompatible"===r)for(let t=0;t<9;t++)e.fillRect(o,f+15+3*t,u,1);else{f+=4*x;const i=40-4*x;if(e.fillRect(o,f,u,i),s.y&&s.x&&s.y<=c-d+m&&s.y>=c-d+m-l&&s.x-a>=o-p&&s.x-a<=o+u-p){e.globalAlpha=.2,e.fillRect(o,m,u,c-30),e.globalAlpha=1;const i=Math.floor(e.measureText(r).width),a=20,s=Math.max(i+a-u,0);e.fillStyle="#000",e.font="600 14px IBM Plex Sans",e.textAlign="center",e.fillText(`${r}`,o+u/2,c/2),e.fillStyle="rgb(49, 46, 43)",e.font="400 14px IBM Plex Sans",e.textAlign="right",e.fillText(`${(t||0).toFixed(1)}`,o-(12+s/2),c/2),e.textAlign="left",e.fillText(`${n.toFixed(1)}`,o+u+(12+s/2),c/2)}}}}));const x=n.findIndex((({position:e})=>s.x-a<=Nt(e.end,h,t,r,at)-p));if(s.y&&s.y<=c-d+m&&s.y>=c-d+m-l&&-1!==x){const{start:i,end:o}=n[x].position,{electricalProfile:a,heightLevel:s}=n[x].value;if(a&&"incompatible"!==a){const n=ui(s),a=c-d+g+4*n,l=Nt(i,h,t,r,at)||p+u/2,m=(Nt(o,h,t,r,at)||t-f-u/2)-l,x=40-4*n;e.shadowColor="rgba(0, 0, 0, 0.19)",e.shadowBlur=5,e.strokeStyle="#FFF",e.lineWidth=2,e.strokeRect(l-1,a-1,m+2,x+2),e.stroke()}}_t(e,"rgba(0,0,0,0.1)",at,t,c+1-d),e.restore(),e.clearRect(0,0,p,i),e.clearRect(t-f,0,f,i)},xi=({width:t,height:i,store:o})=>{const n=jt(gi,{width:t,height:i,store:o});return e.createElement("canvas",{id:"electrical-profile-layer",className:"absolute",ref:n,width:t,height:i})},yi=({ctx:e,width:t,height:i,store:o,setStore:n})=>{Pt(e,t,i);const r=R.select(dt);n&&r.call((e=>P.zoom().filter((e=>e.shiftKey)).on("zoom",(()=>{const t=R.select(dt),{k:i,x:o}=P.zoomTransform(t.node());i>=1?e((e=>({...e,ratioX:i,leftOffset:o}))):(e((e=>({...e,ratioX:1,leftOffset:0}))),t.call(Ut))})))(n)),r.on("mousemove",(e=>{const t=R.pointer(e);n&&n((()=>({...o,cursor:{x:t[0],y:t[1]}})))})),r.on("mouseleave",(()=>{n&&n((()=>({...o,cursor:{x:null,y:null}})))}))},Ti=({width:t,height:i,store:o,setStore:n})=>{const r=jt(yi,{width:t,height:i,store:o,setStore:n});return e.createElement("canvas",{id:"front-interactivity-layer",className:"absolute",ref:r,width:t,height:i})},{MARGIN_LEFT:Ei,MARGIN_RIGHT:Si}=at,vi=({ctx:e,width:t,height:i,store:o})=>{const{powerRestrictions:n,ratioX:r,leftOffset:a,layersDisplay:{electricalProfiles:s}}=o;if(!n)return;Pt(e,t,st.POWER_RESTRICTIONS_HEIGHT),e.save(),e.translate(a,0);const l=Rt(o.speeds);e.font="normal 12px IBM Plex Sans",e.fillStyle="rgb(121, 118, 113)",e.strokeStyle="rgb(121, 118, 113)",e.lineWidth=1,e.textAlign="center";let c=ct;s&&(c=ht),_t(e,"rgba(0,0,0,0.1)",at,t,i-st.POWER_RESTRICTIONS_HEIGHT+1),Ot(e,c,at,t,i,st.POWER_RESTRICTIONS_HEIGHT-1),n.forEach((({position:i,value:o},a)=>{o.handled?(e.strokeStyle="rgb(121, 118, 113)",e.fillStyle="rgb(121, 118, 113)"):(e.strokeStyle="rgb(217, 28, 28)",e.fillStyle="rgb(217, 28, 28)");const s=Nt(i.start,l,t,r,at);e.beginPath(),e.moveTo(s,8),e.lineTo(s,32);const c=Math.floor(e.measureText(o.powerRestriction).width);let h=Nt(i.end,l,t,r,at);a===n.length-1&&(h-=at.CURVE_MARGIN_SIDES/2);const m=19;if(h-s<c+4+4)e.moveTo(s,m),e.lineTo(h-2,m);else{const t=(s+h)/2-c/2-2,i=(s+h)/2+c/2+2;e.moveTo(s,m),e.lineTo(t-2,m),e.moveTo(i+2,m),e.lineTo(h-2,m);const n=(s+h)/2;e.textBaseline="middle",e.fillText(o.powerRestriction,n,m+e.lineWidth/2)}e.moveTo(h-2,14),e.lineTo(h-2,26),e.stroke()})),e.restore(),e.clearRect(0,0,Ei,st.POWER_RESTRICTIONS_HEIGHT),e.clearRect(t-Si,0,Si,st.POWER_RESTRICTIONS_HEIGHT)},wi=({width:t,marginTop:i,store:o})=>{const n=jt(vi,{width:t,height:st.POWER_RESTRICTIONS_HEIGHT,store:o});return e.createElement("canvas",{id:"power-restrictions-layer",className:"absolute",ref:n,width:t,height:st.POWER_RESTRICTIONS_HEIGHT,style:{marginTop:i}})},Ii=({width:t,height:i,store:o,curveX:n,curveY:r,speedText:a,ecoSpeedText:s,effortText:l,electricalModeText:h,electricalProfileText:m,powerRestrictionText:d,previousGradientText:p,modeText:f})=>{const{MARGIN_BOTTOM:u,MARGIN_RIGHT:g}=at,{energySource:x,tractionStatus:y,declivities:T,electricalProfiles:E,powerRestrictions:S}=o.detailsBoxDisplay;let v=0,w=0;const I=document.getElementById("details-box")?.offsetWidth||0,R=document.getElementById("details-box")?.offsetHeight||0;n+I>t-g-10&&(v=I+12),r+R>i-u-10&&(w=R+12);const P=n+6-v,M=r+6-w,b=Number(a)-Number(s),N=0!==b?`-${b.toFixed(1)}`:null;return e.createElement("div",{id:"details-box",className:c("absolute flex flex-col",{block:r,hidden:!r}),style:{marginTop:M,marginLeft:P}},e.createElement("span",{id:"base-speed-text"},a||"--"),e.createElement("div",null,e.createElement("span",{id:"mareco-speed-text"},s||"--"),N&&e.createElement("span",{id:"speed-difference-text"},N)),(x||y||f||l)&&e.createElement("hr",null),x&&e.createElement("span",{id:"mode-text"},f||"--"),y&&e.createElement("span",{id:"effort-text"},l||"--"),h&&e.createElement("div",{id:"electrical-mode-text"},e.createElement("span",null,h||"--"),E&&e.createElement("span",{className:"ml-2"},m||"--")),S&&e.createElement("span",{id:"power-restriction-text"},d||"--"),T&&e.createElement(e.Fragment,null,e.createElement("hr",null),e.createElement("span",{id:"previous-gradient-text"},`${p} ‰`||"--")))},{MARGIN_LEFT:Ri,MARGIN_RIGHT:Pi,MARGIN_TOP:Mi,MARGIN_BOTTOM:bi,CURVE_MARGIN_TOP:Ni,CURVE_MARGIN_SIDES:_i}=at,Oi=12.75,ki=({width:o,height:n,heightOffset:a,store:s})=>{const l=r(null),[c,h]=t(null),m=Mt(a,s.layersDisplay,!1);return i((()=>{const e=l.current.getContext("2d");if(s.cursor.y&&s.cursor.y<m){const t=(({ctx:e,width:t,height:i,store:o})=>{Pt(e,t,i);const{cursor:n,layersDisplay:r,ratioX:a,leftOffset:s,speeds:l,ecoSpeeds:c,electrifications:h,slopes:m,electricalProfiles:d,powerRestrictions:p}=o;let f="",u="",g="",x="coasting",y="",T="",E="",S=0,v="",w=0;const I=It(o),R=Rt(o.speeds),P=Mt(i,r,!1)-bi-Mi,M=t-Ri-Pi,b=e=>e*((M-_i)/R)*a+s+_i/2;if(null===n.x||null===n.y)return;let N=n.x+Ri,_=Wt(n.x,t,o);if(_<0||_>R)return;let O=!1;if(r.steps){const e=Bt(n.x,t,o);null!==e&&(O=!0,_=e.position.start,N=Dt(_,R,t,a,s),g=e.value.name)}if(d){const e=d.find((({position:e})=>b(e.start)<=n.x&&b(e.end)>=n.x))?.value.electricalProfile;e&&(T=e)}if(p){const e=p.find((({position:e})=>n.x>=b(e.start)&&n.x<=b(e.end)));E=e?.value.powerRestriction||""}const k=h.findLast((({position:e})=>e.start<=_)),A=k?.value;A&&(v="electrification"===A.type?"electric":"--",y=A.voltage);let G=Lt(l,_,(e=>e.position.start));G===l.length-1&&G--;let C=Lt(c,_,(e=>e.position.start));C===c.length-1&&C--;const L=l[G],D=l[G+1],H=Ht(L.position.start,L.value,D.position.start,D.value,_);f=H.toFixed(1);const F=P-H/I*(P-Ni)+Mi,W=c[C],B=c[C+1],$=Ht(W.position.start,W.value,B.position.start,B.value,_);u=$.toFixed(1),W.value<B.value?x="accelerating":W.value>B.value&&(x="decelerating"),w=P-$/I*(P-Ni)+Mi,S=m.findLast((({position:e})=>e.start<=_)).value,e.font="normal 12px IBM Plex Sans",e.fillStyle=ut.hex(),e.beginPath(),e.strokeStyle=ut.alpha(.4).hex(),e.lineWidth=.5,e.moveTo(N,F),e.lineTo(N,i-bi),e.moveTo(N,w),e.lineTo(Ri,w),Math.abs(F-w)>2&&(e.moveTo(N,F),e.lineTo(Ri,F)),e.stroke(),e.beginPath(),e.lineWidth=3,e.strokeStyle=vt.hex(),e.lineCap="round",e.moveTo(N-Oi,w),e.lineTo(N+Oi,w),e.moveTo(N,w-Oi),e.lineTo(N,w+Oi),e.stroke(),e.beginPath(),e.lineWidth=1,e.strokeStyle=ut.hex(),e.moveTo(N-Oi,w),e.lineTo(N+Oi,w),e.moveTo(N,w-Oi),e.lineTo(N,w+Oi),e.stroke(),e.beginPath(),e.strokeStyle=ut.hex(),e.lineCap="butt",e.lineWidth=1,e.moveTo(Ri,w),e.lineTo(Ri,w),e.stroke();const U=(Math.round(10*_)/10).toFixed(1).toString();return e.textAlign="center",O?(e.beginPath(),e.lineWidth=2,e.roundRect(N-.5,i-bi-24*.6,1,24,[1,1,1,1]),e.fill(),e.stroke(),e.fillText(U,N,i-bi+1.33*_i)):(e.beginPath(),e.lineWidth=1,e.moveTo(N,i-bi),e.lineTo(N,i-bi+6),e.stroke(),e.fillText(U,N,i-bi+1.33*_i)),N-Ri<e.measureText(g).width/2?e.textAlign="start":N-Ri>M-e.measureText(g).width/2&&(e.textAlign="end"),e.fillText(g,N,i-bi+36),e.clearRect(0,0,t,Mi),{curveX:N,curveY:w,speedText:f,ecoSpeedText:u,effortText:x,electricalModeText:y,electricalProfileText:T,powerRestrictionText:E,previousGradientText:S,modeText:v}})({ctx:e,width:o,height:n,store:s});h(t||null)}else Pt(e,o,n),h(null)}),[o,n,s,m]),e.createElement(e.Fragment,null,e.createElement("canvas",{id:"cursor-layer",className:"absolute",ref:l,width:o,height:n}),c&&e.createElement(Ii,{width:o,height:n,store:s,...c}))},Ai=({cursorX:t,cursorY:i,height:o,text:n})=>e.createElement("div",{id:"tooltip",className:"absolute",style:{marginTop:i,marginLeft:t-123,maxHeight:o}},e.createElement("span",null,n)),Gi=17,Ci=12,Li=({ctx:e,width:t,height:i,store:o,images:n})=>{const{speedLimitTags:r,ratioX:a,leftOffset:s,layersDisplay:{electricalProfiles:l,powerRestrictions:c}}=o,{MARGIN_BOTTOM:h,MARGIN_LEFT:m,MARGIN_RIGHT:d}=at;Pt(e,t,st.SPEED_LIMIT_TAGS_HEIGHT),e.save(),e.translate(s,0);const p=Rt(o.speeds);let f=ct;l&&c?f=mt:(l||c)&&(f=ht),_t(e,"rgba(0,0,0,0.1)",at,t,1),Ot(e,f,at,t,h,st.SPEED_LIMIT_TAGS_HEIGHT-1),r&&(r.forEach((({position:i,value:o},r)=>{const{tag:s,color:l}=o,c=Nt(i.start,p,t,a,at),h=Nt(i.end,p,t,a,at);if(void 0!==h){const t=h-c-1,i=wt[l]||l;e.fillStyle=l,e.strokeStyle="UU"===s?"#494641":l,e.lineWidth=1,e.beginPath(),e.fillRect(c,Ci,t-1,Gi),e.fillStyle=i;const o=e.measureText(s).width+8+(0===r?8:0);if(e.fillRect(c+1+o,Ci,t-o-2,Gi),e.rect(c+o,Ci,t-1-o,Gi),e.strokeRect(c+1,Ci,t-1,Gi),e.closePath(),"UU"===s&&(e.lineWidth=.5,e.beginPath(),e.moveTo(c+o+2,Ci),e.lineTo(c+o+2,29),e.closePath(),e.stroke()),"incompatible"===s||"missing_from_train"===s){const i="incompatible"===s?n.alertFillImage:n.questionImage;e.fillStyle=l;const o=c+(t-24)/2,r=8;((e,t,i,o,n,r)=>{e.beginPath(),e.moveTo(t+r,i),e.lineTo(t+o-r,i),e.quadraticCurveTo(t+o,i,t+o,i+r),e.lineTo(t+o,i+n-r),e.quadraticCurveTo(t+o,i+n,t+o-r,i+n),e.lineTo(t+r,i+n),e.quadraticCurveTo(t,i+n,t,i+n-r),e.lineTo(t,i+r),e.quadraticCurveTo(t,i,t+r,i),e.closePath(),e.fill(),e.stroke()})(e,o,r,24,24,4),null!==i&&((e,t,i,o,n,r,a)=>{const s=document.createElement("canvas"),l=s.getContext("2d");l&&(s.width=n,s.height=r,l.drawImage(t,0,0,n,r),l.globalCompositeOperation="source-in",l.fillStyle=a,l.fillRect(0,0,n,r),e.drawImage(s,i,o))})(e,i,o+4,r+4,16,16,vt.hex())}else{e.fillStyle="white",e.font='600 12px "IBM Plex Sans"',e.textAlign="left",e.textBaseline="middle";const t=c+4;e.fillText(s,t,21.5)}}})),_t(e,"rgba(0,0,0,0.1)",at,t,i),e.restore(),e.clearRect(0,0,m,st.SPEED_LIMIT_TAGS_HEIGHT),e.clearRect(t-d,0,t,st.SPEED_LIMIT_TAGS_HEIGHT))},Di=({width:o,marginTop:n,store:a})=>{const s=r(null),l=r(),[c,h]=t({questionImage:null,alertFillImage:null});return i((()=>{(async()=>{const e=Ct('<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8m8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13M6.92 6.085h.001a.75.75 0 1 1-1.342-.67c.169-.339.436-.701.849-.977C6.845 4.16 7.369 4 8 4a2.76 2.76 0 0 1 1.637.525c.503.377.863.965.863 1.725 0 .448-.115.83-.329 1.15-.205.307-.47.513-.692.662-.109.072-.22.138-.313.195l-.006.004a6 6 0 0 0-.26.16 1 1 0 0 0-.276.245.75.75 0 0 1-1.248-.832c.184-.264.42-.489.692-.661q.154-.1.313-.195l.007-.004c.1-.061.182-.11.258-.161a1 1 0 0 0 .277-.245C8.96 6.514 9 6.427 9 6.25a.61.61 0 0 0-.262-.525A1.27 1.27 0 0 0 8 5.5c-.369 0-.595.09-.74.187-.146.1-.263.238-.34.398M9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0"/></svg>'),t=Ct('<svg xmlns="http://www.w3.org/2000/svg" width = "16" height = "16" viewBox = "0 0 16 16" > <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575zM8 5a.75.75 0 0 0-.75.75v2.5a.75.75 0 0 0 1.5 0v-2.5A.75.75 0 0 0 8 5m1 6a1 1 0 1 0-2 0 1 1 0 0 0 2 0" /> </svg>'),i=await Gt(e),o=await Gt(t);h({questionImage:i,alertFillImage:o})})()}),[]),i((()=>{(async()=>{const e=s.current.getContext("2d"),t={speedLimitTags:a.speedLimitTags,ratioX:a.ratioX,leftOffset:a.leftOffset,layersDisplay:{electricalProfiles:a.layersDisplay.electricalProfiles,powerRestrictions:a.layersDisplay.powerRestrictions},speeds:a.speeds};await Li({ctx:e,width:o,height:n,store:t,images:c})})()}),[o,n,a.speedLimitTags,a.ratioX,a.leftOffset,a.layersDisplay.electricalProfiles,a.layersDisplay.powerRestrictions,a.speeds,c]),i((()=>{(async()=>{s.current.getContext("2d"),l.current=await(({width:e,height:t,store:i})=>{const{speedLimitTags:o,ratioX:n,leftOffset:r,cursor:a}=i,{MARGIN_TOP:s,MARGIN_LEFT:l}=at,c=Rt(i.speeds);if(!o)return null;for(const{position:i,value:h}of o){const o={incompatible:"Incompatible with the infrastructure"},{tag:m}=h;if(!(m in o))continue;const d=o[m];if(void 0===i.end||null===a.x||null===a.y)continue;const p=Nt(i.start,c,e,n,at),f=Nt(i.end,c,e,n,at)-p-1;if(a.x>=p-l+r&&a.x<=p-l+r+f&&a.y>=t-s+Ci-2&&a.y<=t-s+Ci-1+Gi)return{cursorX:a.x+l,cursorY:Ci,text:d}}return null})({width:o,height:n,store:a})})()}),[o,n,a]),e.createElement(e.Fragment,null,e.createElement("canvas",{id:"speed-limit-tags-layer",className:"absolute",ref:s,width:o,height:st.SPEED_LIMIT_TAGS_HEIGHT,style:{marginTop:n}}),l.current&&e.createElement(Ai,{cursorX:l.current.cursorX,cursorY:n-40-2,height:40,text:l.current.text}))},{MARGIN_LEFT:Hi,MARGIN_RIGHT:Fi,MARGIN_BOTTOM:Wi,CURVE_MARGIN_SIDES:Bi}=at,$i=({ctx:e,width:t,height:i,store:o})=>{const{ratioX:n,leftOffset:r,cursor:a}=o;Pt(e,t,i),e.save(),e.translate(r,0),e.strokeStyle="rgb(121, 118, 113)",e.lineWidth=.5,e.font="normal 12px IBM Plex Sans",e.fillStyle="rgb(182, 179, 175)";const s=Rt(o.speeds),l=s/o.ratioX;let c,h;l>=200?(c=5*Math.floor(l/200),h=2):l>=50?(c=2,h=5):l>=20?(c=1,h=5):(c=.1,h=5);const m=Math.floor(s/c),d=(t-Bi-Hi-Fi)*(m*c/s)*n/m;e.beginPath();const p=i-Wi;for(let o=0;o<=m;o++){const n=Hi+Bi/2+d*o,s=o%h==0?.66*Bi:.33*Bi;if(e.moveTo(n,p),e.lineTo(n,i-Wi+s),o%(2*h)==0){e.textAlign="center";const i=(c*o).toFixed(0),s=2*e.measureText(i).width,l=a.x?a.x+Hi-r:1/0,h=Math.abs(l-n),m=Math.max(Math.min(h/s-.1,1),0),d=Math.abs(t-Fi-Bi/2-r-n),f=Math.max(Math.min(d/s-.1,1),0),u=Math.abs(Hi+Bi/2-r-n);let g=Math.max(Math.min(u/s-.1,1),0);0===o&&(g=1);const x=Math.min(m,f,g);e.fillStyle=`rgb(182, 179, 175, ${x})`,e.fillText(i,n,p+1.33*Bi)}}e.closePath(),e.stroke(),e.restore(),e.clearRect(0,0,Hi,i),e.clearRect(t-Fi,0,t,i),e.fillStyle="rgb(182, 179, 175)",e.textAlign="center",e.shadowOffsetY=0,e.shadowBlur=0,e.beginPath(),e.fillText("km",t-Fi-Bi/2,p+1.33*Bi),e.closePath(),e.stroke()},Ui=({width:t,height:i,store:o})=>{const n=jt($i,{width:t,height:i,store:o});return e.createElement("canvas",{id:"tick-layer-x",className:"absolute rounded-t-xl",ref:n,width:t,height:i})},{MARGIN_LEFT:zi,MARGIN_TOP:Zi,MARGIN_BOTTOM:Xi,CURVE_MARGIN_TOP:Vi,MARGIN_RIGHT:Yi}=at,{Y_LEFT_VERTICAL:ji,Y_LEFT_HORIZONTAL:qi}=rt,Ki=({ctx:e,width:t,height:i,store:o})=>{const n=It(o);Pt(e,t,i),e.strokeStyle="rgb(121, 118, 113)",e.lineWidth=.5,e.font="normal 12px IBM Plex Sans",e.fillStyle="rgb(182, 178, 175)";let r=5;n>250?r=30:n>130?r=20:n>60&&(r=10);const a=Math.ceil(n/r),s=(i-Xi-Zi-Vi)*(a*r/n)/a;e.beginPath();for(let t=0;t<=a;t++){const o=i-Xi-s*t;e.moveTo(zi-6,o),e.lineTo(zi,o),e.textAlign="right";const n=(t*r).toString(),a=o+4;e.fillStyle="rgb(182, 178, 175 )",e.fillText(n,36,a)}e.stroke(),e.strokeStyle="rgba(33, 112, 185, 0.6)",e.beginPath(),e.lineWidth=.5;for(let o=3;o<=a;o+=3){const n=i-Xi-s*o;e.moveTo(zi,n),e.lineTo(t-Yi,n)}e.stroke(),e.strokeStyle="rgba(33, 112, 185, 0.25)",e.beginPath();for(let o=1;o<=a;o++){if(o%3==0)continue;const n=i-Xi-s*o;e.moveTo(zi,n),e.lineTo(t-Yi,n)}e.stroke(),e.clearRect(0,0,t,Zi),e.clearRect(zi-6,i-Xi,t,Xi),e.clearRect(0,i-Xi+6,zi,Xi),e.fillStyle="rgb(182, 179, 175)",e.textAlign="center",e.shadowOffsetY=0,e.shadowBlur=0,e.beginPath(),e.fillText("km/h",ji,qi),e.closePath(),e.stroke()},Qi=({width:t,height:i,store:o})=>{const n=jt(Ki,{width:t,height:i,store:o});return e.createElement("canvas",{id:"tick-layer-y",className:"absolute rounded-t-xl",ref:n,width:t,height:i})},{MARGIN_LEFT:Ji,MARGIN_TOP:eo,MARGIN_BOTTOM:to,RIGHT_TICK_MARGINS:io}=at,{Y_RIGHT_VERTICAL:oo,Y_RIGHT_HORIZONTAL:no}=rt,ro=({ctx:e,width:t,height:i,store:o})=>{Pt(e,t,i);const{minGradient:n,maxGradient:r}=At(o),a=i-eo-to-io,s=a/12,l=eo+io/2+a/2+2,c=t-Ji+10;e.font="normal 12px IBM Plex Sans",e.lineWidth=.5;const h=Math.max(r,n),m=6*Math.ceil(h/6)/6;e.beginPath();for(let i=-6;i<=6;i++){const o=i*m,n=l-i*s;e.moveTo(t-Ji-6,n),e.lineTo(t-Ji,n),e.strokeStyle="rgb(121, 118, 113)",e.textAlign="left";const r=o.toString(),a=n+4,h=1;e.fillStyle=`rgba(182, 179, 175, ${h})`,e.fillText(r,c,a),e.fillText("‰",t-no,oo)}e.stroke(),e.clearRect(0,0,t,eo),e.clearRect(t-Ji,i-to,t,to),e.clearRect(0,i-to+6,t-Ji,to)},ao=({width:t,height:i,store:o})=>{const n=jt(ro,{width:t,height:i,store:o});return e.createElement("canvas",{id:"tick-layer-y-right",className:"absolute rounded-t-xl",ref:n,width:t,height:i})},so=({width:o,height:n,backgroundColor:r,data:a,setHeight:s,translations:l})=>{const[c,h]=t({speeds:[],ecoSpeeds:[],stops:[],electrifications:[],slopes:[],mrsp:void 0,powerRestrictions:void 0,electricalProfiles:void 0,speedLimitTags:void 0,trainLength:0,ratioX:1,leftOffset:0,cursor:{x:null,y:null},detailsBoxDisplay:{energySource:!0,tractionStatus:!0,declivities:!0,electricalProfiles:!0,powerRestrictions:!0},layersDisplay:{steps:!0,declivities:!1,speedLimits:!1,electricalProfiles:!1,powerRestrictions:!1,speedLimitTags:!1},isSettingsPanelOpened:!1}),{WIDTH_OFFSET:m,HEIGHT_OFFSET:d}=((e,t,i)=>({WIDTH_OFFSET:i?e-102:e-60,HEIGHT_OFFSET:t-80}))(o,n,c.layersDisplay.declivities),p=Mt(n,c.layersDisplay),f=Mt(d,c.layersDisplay),{OFFSET_RIGHT_AXIS:u}=at,g=c.layersDisplay.declivities?o-u:o,[x,y]=t(!1);return i((()=>{h((e=>({...e,...a})))}),[a]),i((()=>{s(p)}),[s,p]),e.createElement("div",{style:{width:`${o}px`,height:`${p}px`,backgroundColor:`${r}`},tabIndex:0},e.createElement("div",{className:"flex justify-end absolute base-margin-top",style:{width:g}},e.createElement(nt,{reset:()=>{h((e=>({...e,ratioX:1,leftOffset:0}))),Ut()},openSettingsPanel:()=>{h((e=>({...e,isSettingsPanelOpened:!0})))},store:c})),c.isSettingsPanelOpened&&e.createElement("div",{className:"flex justify-end absolute ml-2 base-margin-top",style:{width:g}},e.createElement($t,{globalHeight:p,color:r,store:c,setStore:h,setIsMouseHoveringSettingsPanel:y,translations:l})),c.layersDisplay.declivities&&e.createElement(fi,{width:m,height:d,store:c}),e.createElement(li,{width:m,height:d,store:c}),c.layersDisplay.speedLimits&&e.createElement(oi,{width:g,height:n,store:c}),c.layersDisplay.steps&&e.createElement(qt,{width:g,height:n,store:c}),e.createElement(Qi,{width:o,height:n,store:c}),c.layersDisplay.electricalProfiles&&e.createElement(xi,{width:g,height:n+st.ELECTRICAL_PROFILES_HEIGHT,store:c}),c.layersDisplay.powerRestrictions&&e.createElement(wi,{width:g,marginTop:bt(n,c.layersDisplay),store:c}),c.layersDisplay.speedLimitTags&&e.createElement(Di,{width:g,marginTop:bt(n,c.layersDisplay,c.layersDisplay.speedLimitTags),store:c}),e.createElement(Ui,{width:g,height:p,store:c}),c.layersDisplay.declivities&&e.createElement(ao,{width:o,height:n,store:c}),!x&&e.createElement(ki,{width:g,height:p,heightOffset:f,store:c}),e.createElement(Ti,{width:m,height:f,store:c,setStore:h}))},lo=100,co=48.5,ho={SANS:"400 12px IBM Plex Sans",MONO:"400 10px IBM Plex Mono"},mo={GREY_20:"rgb(211, 209, 207)",GREY_50:"rgb(121, 118, 113)",GREY_60:"rgb(92, 89, 85)",GREY_80:"rgb(49, 46, 43)",HOUR_BACKGROUND:"rgba(243, 248, 253, 0.5)",RAIL_TICK:"rgb(33, 112, 185)",REMAINING_TRAINS_BACKGROUND:"rgba(0, 0, 0, 0.7)",SELECTION_20:"rgb(255, 242, 179)",WHITE_50:"rgba(255, 255, 255, 0.5)",WHITE_100:"rgb(255, 255, 255)"},po={MINUTE:[2,9,2],FIVE_MINUTES:[6,9,6],QUARTER_HOUR:[2,2,6,9,6,2,2],HALF_HOUR:[2,2,2,2,6,9,6,2,2,2,2],HOUR:[16,9,16]},fo=[[0,0,0,0,0,0,1,1,1,1,1],[0,0,0,0,0,3,1,1,1,1,1],[0,0,0,3,2,1,1,1,1,1,1],[0,0,0,3,2,1,1,1,1,1,1],[0,0,3,2,1,1,1,1,1,1,1],[0,0,3,2,1,1,1,1,1,1,1],[0,0,3,2,1,1,1,1,1,1,1],[0,0,3,2,1,1,1,1,1,1,1]],uo=({ctx:e,text:t,x:i,y:o,color:n,xPosition:r="left",yPosition:a="bottom",font:s="400 12px IBM Plex Sans",rotateAngle:l=0,stroke:c})=>{e.save(),e.translate(i,o),e.rotate(l),e.font=s,e.textAlign=r,e.textBaseline=a,e.fillStyle=n,c&&(e.lineWidth=c.width,e.strokeStyle=c.color,e.strokeText(t,0,0)),e.fillText(t,0,0),e.restore()},go=e=>({"00":"HOUR",30:"HALF_HOUR",15:"QUARTER_HOUR",45:"QUARTER_HOUR","05":"FIVE_MINUTES",10:"FIVE_MINUTES",20:"FIVE_MINUTES",25:"FIVE_MINUTES",35:"FIVE_MINUTES",40:"FIVE_MINUTES",50:"FIVE_MINUTES",55:"FIVE_MINUTES"}[e]??"MINUTE"),xo={medium:24,small:4},yo=-30*Math.PI/180,{SANS:To,MONO:Eo}=ho,{WHITE_100:So,GREY_50:vo,GREY_60:wo,GREY_80:Io,SELECTION_20:Ro}=mo,{SANS:Po}=ho,{REMAINING_TRAINS_BACKGROUND:Mo,WHITE_100:bo,SELECTION_20:No}=mo,_o=4.5,Oo=({ctx:e,remainingTrainsNb:t,xPosition:i})=>{e.fillStyle=Mo,e.beginPath(),e.rect(i,36.5,70,24),e.fill(),e.stroke(),e.fillStyle=bo,e.font=Po,e.textAlign="center",e.textBaseline="middle",e.fillText(`+${t} trains`,i+35,48.5)},ko=({ctx:e,zone:t,tracks:i,arrivalTimePixel:o,departureTimePixel:n,yPosition:r,isThroughTrain:a,selectedTrainId:s,setSelectedTrainId:l,xMousePosition:c,yMousePosition:h,index:m})=>{let d=s;const p=10+lo*m+r,f=20+lo*i.length-p,u=a?4:0,g=c>=o-u&&c<=n+u,x=Math.abs(h)>=f-3-1-u&&Math.abs(h)<=f+1+u;if(g&&x&&(l(t.id),d=t.id),e.fillStyle=t.color,e.strokeStyle=bo,e.lineJoin="round",e.lineCap="round",e.font="400 10px IBM Plex Mono",s===t.id){const i=a?8:4,s=e.measureText(t.originStation||"--").width,l=e.measureText(t.destinationStation||"--").width;e.save(),e.fillStyle=No,e.beginPath(),e.roundRect(o-s-i,r-20,n-o+s+l+2*i,40,2),e.fill(),e.restore()}a?(({ctx:e,arrivalTimePixel:t})=>{e.beginPath(),e.moveTo(t-1,50),e.lineTo(t-_o,45),e.lineTo(t+_o,45),e.lineTo(t+1,50),e.lineTo(t+_o,55),e.lineTo(t-_o,55),e.lineTo(t-1,50),e.fill(),e.moveTo(t-1,50),e.lineTo(t+1,50),e.stroke()})({ctx:e,arrivalTimePixel:o}):(({ctx:e,arrivalTimePixel:t,departureTimePixel:i,yPosition:o})=>{e.beginPath(),e.rect(t,o,i-t,3),e.fill(),e.stroke()})({ctx:e,arrivalTimePixel:o,departureTimePixel:n,yPosition:r}),(({ctx:e,zone:t,arrivalTimePixel:i,departureTimePixel:o,yPosition:n,isThroughTrain:r,selectedTrainId:a})=>{const s=o-i-4,l=e=>s<xo[e];e.font="400 10px IBM Plex Mono";const c=e.measureText(t.originStation||"--").width;e.font="400 12px IBM Plex Mono";const h=e.measureText(t.arrivalTrainName).width,{xOriginTrainName:m,yOriginTrainName:d}=l("medium")?{xOriginTrainName:i-c+4-(r?6:0),yOriginTrainName:n-14}:{xOriginTrainName:i+8,yOriginTrainName:n-5},p=l("small")?"right":"center",f=l("small")?"left":"center",u={color:a===t.id?"transparent":So,width:4};if(a===t.id){const{xSelectedTrainNameBackground:t,ySelectedTrainNameBackground:o}=l("medium")?{xSelectedTrainNameBackground:m-8,ySelectedTrainNameBackground:n-28}:{xSelectedTrainNameBackground:i,ySelectedTrainNameBackground:n-18};e.save(),e.translate(t,o),e.rotate(yo),e.fillStyle=Ro,e.beginPath(),e.roundRect(-4,0,h+8,18),e.fill(),e.restore()}uo({ctx:e,text:t.arrivalTrainName,x:m,y:d,color:vo,rotateAngle:yo,stroke:{color:So,width:4}}),uo({ctx:e,text:t.arrivalTime.getMinutes().toLocaleString("fr-FR",{minimumIntegerDigits:2}),x:r?i-4:i,y:n+8.5,color:Io,xPosition:p,yPosition:"top",font:To,stroke:u}),r||uo({ctx:e,text:t.departureTime.getMinutes().toLocaleString("fr-FR",{minimumIntegerDigits:2}),x:o,y:n+8.5,color:Io,xPosition:f,yPosition:"top",font:To,stroke:u}),uo({ctx:e,text:t.originStation||"--",x:r?i-4:i,y:n-5,color:wo,xPosition:"right",yPosition:"bottom",font:Eo,stroke:u}),uo({ctx:e,text:t.destinationStation||"--",x:r?o+4:o,y:n-5,color:wo,xPosition:"left",yPosition:"bottom",font:Eo,stroke:u})})({ctx:e,zone:t,arrivalTimePixel:o,departureTimePixel:n,yPosition:r,isThroughTrain:a,selectedTrainId:d})},Ao=({useDraw:e,selectedTrainId:t,setSelectedTrainId:i,mousePosition:o})=>(e("paths",a(((e,{getTimePixel:n,tracks:r,occupancyZones:a,trackOccupancyWidth:s,trackOccupancyHeight:l})=>{l&&s&&(({ctx:e,width:t,height:i,tracks:o,occupancyZones:n,getTimePixel:r,selectedTrainId:a,setSelectedTrainId:s,mousePosition:l})=>{if(e.clearRect(0,0,t,i),e.save(),!o||!n||0===n.length)return;const c=n.sort(((e,t)=>e.arrivalTime.getTime()-t.arrivalTime.getTime()));o.forEach(((t,i)=>{const n=0===i?10:lo;e.translate(0,n);const{x:h,y:m}=l,d=c.filter((e=>e.trackId===t.id));let p=0,f=0,u=f,g=co,x=4,y=0,T=0;for(;T<d.length;){const t=d[T],n=r(t.arrivalTime.getTime()),l=r(t.departureTime.getTime()),c=n===l;if(n>u){g=co,p=n,f=l,u=l,x=4,y=1,ko({ctx:e,zone:t,tracks:o,arrivalTimePixel:n,departureTimePixel:l,yPosition:g,isThroughTrain:c,selectedTrainId:a,setSelectedTrainId:s,index:i,xMousePosition:h,yMousePosition:m}),T++;continue}if(y<9){n>=p&&(y%2==0?g-=x:g+=x),l>=u&&(u=l),ko({ctx:e,zone:t,tracks:o,arrivalTimePixel:n,departureTimePixel:l,yPosition:g,isThroughTrain:c,selectedTrainId:a,setSelectedTrainId:s,index:i,xMousePosition:h,yMousePosition:m}),y++,x+=4,T++;continue}const E=d.findIndex(((e,t)=>t>T&&r(e.arrivalTime.getTime())>=u))-T;Oo({ctx:e,remainingTrainsNb:E,xPosition:p+(u-p)/2-35}),T+=E}})),e.restore()})({ctx:e,width:s,height:l,tracks:r,occupancyZones:a,getTimePixel:n,selectedTrainId:t,setSelectedTrainId:i,mousePosition:o})}),[o,t,i])),null),{WHITE_50:Go,GREY_20:Co,RAIL_TICK:Lo}=mo,Do=({ctx:e,xStart:t,yStart:i,ticks:o,stroke:n})=>{const r=u(o)/2;e.strokeStyle=n,e.beginPath(),e.setLineDash(o),e.moveTo(t,i-r),e.lineTo(t,i+r),e.stroke()},Ho=({ctx:e,width:t,getTimePixel:i,labelMarks:o})=>{e.fillStyle=Go,e.save(),(({xStart:e,yStart:t,width:i,stroke:o=Co,ctx:n})=>{n.clearRect(e,t,i,9),n.fillStyle=Go,n.strokeStyle=o,n.beginPath(),n.rect(e,t,i,8),n.fill(),n.stroke()})({xStart:-1,yStart:46,width:t+1,ctx:e});for(const t in o){const o=new Date(+t).getMinutes().toString().padStart(2,"0"),n=go(o);Do({ctx:e,xStart:i(+t),yStart:50,ticks:po[n],stroke:Lo})}e.restore()},{WHITE_100:Fo,HOUR_BACKGROUND:Wo}=mo,Bo=({ctx:e,xStart:t,width:i,height:o,switchBackground:n})=>{t>=0&&(e.clearRect(t,0,i,o),e.fillStyle=n?Wo:Fo,e.fillRect(t,0,i,o))},$o=({ctx:e,width:t,height:i,tracks:o,timeOrigin:n,timePixelOffset:r,getTimePixel:a,timeRanges:s,breakpoints:l,timeScale:c})=>{e.clearRect(0,0,t,i),e.save();const h=n-c*r,m=h+c*t,d=((e,t,i)=>{const o=e.findIndex((e=>t<e));return o>=0?i[o]:[]})(l,1/c*6e4,fo),p=((e,t,i,o)=>{const n={};return e.map(((e,r)=>{const a=o[r];if(a)for(let o=Math.floor(t/e)*e;o<=i;o+=e)n[o]={level:a,rangeIndex:r}})),n})(s,h,m,d);let f=!1;for(const o in p){if("00"===new Date(+o).getMinutes().toString().padStart(2,"0"))f=!f,Bo({ctx:e,xStart:a(+o),width:t,height:i,switchBackground:f})}o?.forEach(((i,o)=>{const n=0===o?10:lo;e.translate(0,n),Ho({ctx:e,width:t,getTimePixel:a,labelMarks:p})})),e.restore()},Uo=({useDraw:e})=>(e("background",a(((e,{timeOrigin:t,timePixelOffset:i,getTimePixel:o,tracks:n,trackOccupancyWidth:r,trackOccupancyHeight:a,timeScale:s,theme:{timeRanges:l,breakpoints:c}})=>{a&&r&&$o({ctx:e,width:r,height:a,tracks:n,timeOrigin:t,timePixelOffset:i,getTimePixel:o,timeRanges:l,breakpoints:c,timeScale:s})}),[])),null),zo=({opId:t,useDraw:i,setCanvasesRoot:o,selectedTrainId:n,setSelectedTrainId:r,mousePosition:a})=>e.createElement("div",{id:`track-occupancy-canvas-${t}`,className:"bg-white-100 canvas-container",ref:o},e.createElement(Uo,{useDraw:i}),e.createElement(Ao,{useDraw:i,selectedTrainId:n,setSelectedTrainId:r,mousePosition:a})),Zo=({tracks:t})=>e.createElement("div",{id:"track-occupancy-manchette"},t.map((t=>e.createElement("div",{className:"track",key:t.id,style:{height:lo}},e.createElement("span",{className:"track-line"},t.line),e.createElement("div",{className:"track-name"},t.name),e.createElement("div",{className:"track-rail"})))));export{de as CAPTION_SIZE,N as CanvasContext,_e as ConflictLayer,Ae as ConflictTooltip,Re as DEFAULT_LEVEL,ce as DEFAULT_THEME,Ze as DEFAULT_ZOOM_MS_PER_PX,qe as Manchette,ot as ManchetteWithSpaceTimeChart,_ as MouseContext,Ge as OccupancyBlockLayer,Pe as PathLayer,Ce as PatternRect,De as Quadrilateral,Me as SpaceTimeChart,b as SpaceTimeChartContext,so as SpeedSpaceChart,Oe as Tooltip,zo as TrackOccupancyCanvas,Zo as TrackOccupancyManchette,Le as WorkScheduleLayer,Fe as ZoomRect,Ee as getSpaceAtTime,be as isConflictPickingElement,$e as isPathOnScreen,ve as isPointPickingElement,we as isSegmentPickingElement,Qe as timeScaleToZoomValue,ee as useDraw,it as useManchetteWithSpaceTimeChart,J as usePicking};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|