@osrd-project/ui-charts 0.0.70 → 0.0.71
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/components/ManchetteWithSpaceTimeChart.d.ts +1 -2
- package/dist/manchette/hooks/useManchetteWithSpaceTimeChart.d.ts +2 -4
- package/dist/manchette/hooks/usePaths.d.ts +2 -4
- package/dist/manchette/types.d.ts +1 -1
- package/dist/spaceTimeChart/components/TimeCaptions.d.ts +1 -3
- package/dist/spaceTimeChart/lib/consts.d.ts +17 -0
- package/dist/spaceTimeChart/lib/types.d.ts +15 -7
- package/dist/spaceTimeChart/utils/canvas.d.ts +12 -9
- package/dist/spaceTimeChart/utils/scales.d.ts +1 -1
- package/package.json +4 -4
package/dist/index.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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};
|
|
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{clamp as h,isEqual as m,inRange as d,last as p,sum as f}from"lodash";import u from"chroma-js";import{ZoomOut as g,ZoomIn as x,Iterations as y,Plus as T,Dash as E,KebabHorizontal as S,X as v}from"@osrd-project/ui-icons";import{Checkbox as w}from"@osrd-project/ui-core";import*as I from"d3-selection";import*as R from"d3-zoom";function P(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),b=o(void 0),N=o(void 0),_="stop",O=["paths"],k=["background","graduations","paths","overlay","captions"];function A(){const e=window.devicePixelRatio||1;return e>1?.5:.5*e}function G(e,{x:t,y:i},{x:o,y:n},[r,a,s],l,c,m=1){if(t>o)return G(e,{x:o,y:n},{x:t,y:i},[r,a,s],l,c,m);t=Math.round(t*m),i=Math.round(i*m),o=Math.round(o*m),n=Math.round(n*m),l=Math.round(l*m);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=h(Math.floor(P.x),0,d),_=h(Math.ceil(M.x),0,d),O=h(Math.floor(b.y),0,p),k=h(Math.ceil(R.y),0,p);for(let t=O;t<=k;t++){const i=h(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=h(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 C=new Map;function L(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=C.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 C.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 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.round(o*l),n=Math.round(n*l);const c=h(t,0,e.width),m=h(i,0,e.height),d=h(t+o,0,e.width),p=h(i+n,0,e.height);for(let t=c;t<d;t++)for(let i=m;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 H=6;const F=12;function W(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+(F-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+F*a,m+F*s),e.stroke()}(e,t,i,o,n,r):function(e,t,i,o){e.beginPath(),o?(e.moveTo(i-H/2,t),e.lineTo(i+H/2,t)):(e.moveTo(t,i-H/2),e.lineTo(t,i+H/2)),e.stroke()}(e,t,i,o)}function B(e,t,i,o,n=e=>({level:e})){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),time:c}),c+=i})),Object.values(r)}function $(e,t,i=window.devicePixelRatio||1){const o=t/2;return Math.round((e-o)*i)/i+o}function z(e,{timeStart:t,timeEnd:i,spaceStart:o,spaceEnd:n},{getPoint:r}){const a=r({time:Number(t),position:o}),s=r({time:Number(i),position:n}),l=s.x-a.x,c=s.y-a.y;return 0!==l&&0!==c&&(e.translate(a.x,a.y),e.fillRect(0,0,l,c)),{width:l,height:c}}const U={},Z={};function X(e){if(Z[e])return Z[e];const t=`#${e.toString(16).padStart(6,"0")}`.toLowerCase();return U[t]=e,Z[e]=t,t}function V(e){return e.toString(16).padStart(2,"0").toLowerCase()}function Y(e){return u(e).rgba()}const j="picking",q="rendering";function K(e,o,n){const l=r({}),c=r({}),h=r(O.reduce(((e,t)=>({...e,[t]:new Set})),{})),d=r(k.reduce(((e,t)=>({...e,[t]:new Set})),{})),p=r(o),f=r(null),[u,g]=t(null),x=P(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(),O.forEach((i=>{if(t&&!t.has(i))return;const o=c.current[`${j}-${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=A();n.forEach((t=>t(r,e,a))),o.putImageData(r,0,0)}}))}),[]),S=a(((e,t)=>{k.forEach((i=>{if(t&&!t.has(i))return;const o=c.current[`${q}-${i}`],n=d.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=d.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=d.current[t];if(!e.has(i))throw new Error("This drawing function has not been registered.");e.delete(i)}w()}),[]),M=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,k.map((e=>`${q}-${e}`)),p.current.theme.background)),[]);i((()=>{if(!e)return;const t=l.current,i=c.current;[...k.map((e=>({layer:e,type:"rendering"}))),...O.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=A();for(const t in l.current){const i=l.current[t],o=c.current[t],n=t.split("-")[0]===j;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=A();O.some((i=>{const o=c.current[`${j}-${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`#${V(e)}${V(t)}${V(i)}`}(r,a,s),o=function(e){return U[e.toLowerCase()]}(t),n=p.current.pickingElements[o];return e={layer:i,element:n},!0}}return!1})),m(e,u)||g(e)}),[n,u]);return{canvasContext:s((()=>({register:I,unregister:R,captureCanvases:M})),[I,R,M]),hoveredItem:u}}function Q(e,t){const{register:o,unregister:r}=n(b);i((()=>(o({type:"picking",layer:e,fn:t}),()=>{r({type:"picking",layer:e,fn:t})})),[e,t,o,r])}function J(e,t){const{register:o,unregister:r}=n(b);i((()=>(o({type:"rendering",layer:e,fn:t}),()=>{r({type:"rendering",layer:e,fn:t})})),[e,t,o,r])}function ee({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 te(e,t){const i=e(t),o=e(t,!0);return i===o?[i]:[i,o]}const ie=()=>(J("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),te(i,o.position).forEach((t=>{const i=$(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),oe="#2170B9",ne="#B6B3AF",re="IBM Plex Sans, sans-serif",ae=6e4,se=36e5,le={background:"white",breakpoints:[.2,.5,1,4,16,48,72,1/0],timeRanges:[1e4,3e4,6e4,3e5,9e5,18e5,1*se,3*se,6*se,12*se,24*se],pathsStyles:{fontSize:10,fontFamily:re},spaceGraduationsStyles:{1:{width:.5,color:oe,opacity:.75},2:{width:.5,color:oe,opacity:.25},3:{width:.5,color:"#EDEDED"}},timeCaptionsSize:40,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,2,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,1,1,1,1,1,1,1,1]],timeCaptionsStyles:{1:{color:"#797671",font:`12px ${re}`,topOffset:12},2:{color:ne,font:`12px ${re}`,topOffset:12},3:{color:ne,font:`10px ${re}`,topOffset:6}},dateCaptionsSize:0,dateCaptionsStyle:{color:ne,font:`10px ${re}`,topOffset:28,textAlign:"left"},timeGraduationsPriorities:[[0,0,0,0,0,0,0,6,4,2,1],[0,0,0,0,0,0,6,5,5,2,1],[0,0,0,0,0,6,4,3,3,2,1],[0,0,0,0,6,5,4,3,2,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,3,3,2,2,2,2,1],[6,5,4,3,3,3,2,2,2,2,1]],timeGraduationsStyles:{1:{width:.75,color:"#000000",opacity:.5},2:{width:.5,color:oe,opacity:.7},3:{width:.5,color:oe,opacity:.7,dashArray:[80,8]},4:{width:.5,color:oe,opacity:.6,dashArray:[16,4]},5:{width:.5,color:oe,opacity:.6,dashArray:[8,8]},6:{width:.75,color:oe,opacity:.6,dashArray:[2,8]}}},ce=e=>`:${new Date(e).getMinutes().toString().padStart(2,"0")}`,he=(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")},me=e=>{const t=new Date(e);return[t.getDate().toString().padStart(2,"0"),(t.getMonth()+1).toString().padStart(2,"0"),t.getFullYear().toString()].join("/")},de=[()=>"",()=>"",ce,ce,ce,ce,he,he,he,he,he],pe=()=>(J("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,dateCaptionsStyle:f},captionSize:u,hideDates:g,showTicks:x})=>{const y=r?s:a,T=(r?a:s)-u,E=i-t*(o+100),S=E+t*(a+200),v=1/t*ae;let w=[];c.some(((e,t)=>v<e&&(w=m[t],!0)));let I=B(E,S,h,w,((e,t)=>({level:e,styles:d[e],formatter:de[t]})));if(g||(I=I.concat(B(E,S,[24*se],[1],(e=>({level:e,styles:f,formatter:me}))))),e.fillStyle=l,r?e.fillRect(0,0,u,y):e.fillRect(0,T,y,u),I.forEach((({styles:t,formatter:i,time:o})=>{const a=i(o,v);e.textAlign=t.textAlign||"center",e.textBaseline="top",e.fillStyle=t.color,e.lineWidth=5,e.strokeStyle=l,e.lineCap="butt",e.font=`${t.fontWeight||"normal"} ${t.font}`;const s=$(n(o),e.lineWidth);r?(e.save(),e.translate(u-(t.topOffset||0),s),e.rotate(Math.PI/2),e.strokeText(a,0,0),e.fillText(a,0,0),e.restore()):(x&&(e.strokeStyle=d[1].color,e.moveTo(s,T),e.lineTo(s,o%18e4==0?8:4),e.stroke()),e.strokeText(a,s,T+(t.topOffset||0)),e.fillText(a,s,T+(t.topOffset||0)))})),e.strokeStyle=p[1].color,e.lineWidth=p[1].width,!x){if(e.beginPath(),r){const t=$(u,e.lineWidth);e.moveTo(t,0),e.lineTo(t,y)}else{const t=$(T,e.lineWidth);e.moveTo(0,t),e.lineTo(y,t)}e.stroke()}}),[])),null),fe=()=>(J("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*ae;let x=[];c.some(((e,t)=>g<e&&(x=d[t],!0)));B(f,u,h,x).forEach((({time:t,level:i})=>{const o=m[i];e.strokeStyle=o.color,e.lineWidth=o.width,e.globalAlpha=o.opacity||1,e.setLineDash(o.dashArray||[]),o.dashArray&&(e.lineDashOffset=-n);const s=$(r(t),e.lineWidth);e.beginPath(),a?(e.moveTo(0,s),e.lineTo(p,s)):(e.moveTo(s,0),e.lineTo(s,p)),e.stroke()})),e.setLineDash([]),e.lineDashOffset=0,e.globalAlpha=1}),[])),null);function ue(e,t){const i=t.getBoundingClientRect();return{x:e.clientX-i.left,y:e.clientY-i.top}}function ge(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 xe(e,t,i){e=h(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 ye(e,t){return i=>{const{from:o,pixelFrom:n,coefficient:r}=function(e,t){e=h(e,t.pixelFrom,t.pixelTo);let i=t;for(;"pixelLimit"in i;)i=e<=i.pixelLimit?i.left:i.right;return i}(i-e,t);return o+(i-e-n)*r}}function Te(e,t){const i=e.points.slice(0,-1).map(((t,i)=>[t,e.points[i+1]])).find((([e,i])=>d(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 Ee(e,t,i){if(t<e)return Ee(t,e,i).reverse();e=Math.max(e,i.from),t=Math.min(t,i.to);let o=xe(e,i);const n=[];for(;o.to<t;)n.push(o.to),o=o.next;return n}function Se(e){return"point"===e.type}function ve(e){return"segment"===e.type}const we={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"}},Ie=2,Re=({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=Ee(m,s,o);let f=-1/0;p.forEach(((o,h)=>{const u=o===(p[h+1]??1/0),g=f===o?"forward"===ee(e,c,!0):!!u&&"backward"===ee(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)&&te(o,e).forEach((e=>{const o=$(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,captionSize:n,theme:{background:r,pathsStyles:{fontSize:a,fontFamily:s}}},l,c,h,m)=>{if(!l)return;const p=h.findIndex((({x:e,y:r})=>o?d(e,n,t)&&d(r,0,i):d(e,0,t)&&d(r,0,i-n)));if(p<0)return;const f=h[p-1],u=h[p],g=h[p+1];let x=u,y=0;if(0===p)g&&(y=Math.atan2(g.y-u.y,g.x-u.x));else{const e=o?n:0,t=(u.y-f.y)/(u.x-f.x),i=u.y-(u.x-e)*t,r=u.x-e-u.y/t;x=i>=0?{x:e,y:i}:{x:r+10/t,y:10},y=Math.atan2(u.y-f.y,u.x-f.x)}e.save(),e.translate(x.x,x.y),e.rotate(y),e.font=`${a}px ${s}`,e.textAlign="start";const T=e.measureText(l),E=T.width+4,S=T.actualBoundingBoxAscent+T.actualBoundingBoxDescent+4,v=E<m?5:(m-E)/2,w=y>=0?-5:15;e.globalAlpha=.75,e.fillStyle=r,e.fillRect(v-2,w-S+2,E,S),e.fillStyle=c,e.globalAlpha=1,e.fillText(l,v,w),e.restore()}),[]),h=a(((t,{getTimePixel:i,getSpacePixel:o,swapAxis:n})=>{if(!e.points.length)return;const r=e.points[0],a=e.fromEnd||_,s=p(e.points),l=e.toEnd||_;W(t,i(r.time),o(r.position),n,"from",ee(e,0),a),W(t,i(s.time),o(s.position),n,"to",ee(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]),f=a(((e,t)=>{if(!n)return;const o=n.width||1,a=we[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]);J("paths",a(((o,n)=>{f(o,n),o.strokeStyle=t,o.lineWidth=7,o.globalAlpha=.2,o.lineCap="round",l(o,n);const a=we[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,f,e.label]));return Q("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=Y(X(l(h)));G(t,c,n,m,we[i].width+o,!0,a)}})),s(n).forEach((n=>{const r={type:"point",pathId:e.id,point:n},s=Y(X(l(r)));L(t,n,2*(we[i].width+o),s,0,a)}))}),[r,s,i,e.id,o])),null};const Pe=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,hideDates:v,theme:w,onPan:I,onZoom:R,onClick:_,onMouseMove:O,...k}=o,[A,G]=t(null),[C,L]=t(null),D=s((()=>({...le,...w})),[w]),{width:H,height:F}=P(A),W=s((()=>JSON.stringify({operationalPoints:n,width:H,height:F,spaceOrigin:l,spaceScales:h,timeOrigin:m,timeScale:d,xOffset:p,yOffset:f,swapAxis:u,hideGrid:T,hidePathsLabels:E,showTicks:S,hideDates:v})),[n,H,F,l,h,m,d,p,f,u,T,E,S,v]),B=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}=xe(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),w=function(e,t,i){return o=>(o-t)*i+e}(m,o,d),I=ye(r,e),R=function(e,t,i,o){return n=>({time:e(n[i]),position:t(n[o])})}(w,I,t,i),P=[];return{fingerprint:W,width:H,height:F,getTimePixel:a,getSpacePixel:s,getPoint:x,getTime:w,getSpace:I,getData:R,pickingElements:P,resetPickingElements:()=>{P.length=0},registerPickingElement:e=>(P.push(e),P.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,hideDates:!!v,theme:D,captionSize:v?D.timeCaptionsSize:D.dateCaptionsSize+D.timeCaptionsSize}}),[W]),$=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=ue(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}(A),{position:z,down:U,isHover:Z}=$,{canvasContext:X,hoveredItem:V}=K(C,B,z),Y=s((()=>{const e=y?function(e,t){return e&&t?Se(t.element)?t.element.point:ve(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}($.position,V):$.position;return{down:U,isHover:Z,position:e,hoveredItem:V,data:B.getData(e)}}),[y,$.position,V,U,Z,B]);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:ge(t),position:ue(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])}(A,Y,{onPan:I,onZoom:R,onClick:_,onMouseMove:O},B),i((()=>{g&&g({item:V,context:B})}),[V]),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.`)}(D)}),[D]),e.createElement("div",{...k,ref:G,className:c("relative space-time-chart",k.className),style:{background:D.background}},e.createElement("div",{ref:L,className:"absolute inset-0"}),e.createElement(M.Provider,{value:B},e.createElement(b.Provider,{value:X},e.createElement(N.Provider,{value:Y},!T&&e.createElement(e.Fragment,null,e.createElement(ie,null),e.createElement(fe,null),e.createElement(pe,null)),x))))};function Me(e){return"conflict"===e.type}const be=[{opacity:.33,color:"#d91c1c",size:8},{opacity:.5,color:"#ff6868",size:4},{opacity:1,color:"#6b0000",size:0}],Ne=({conflicts:e})=>{J("paths",a(((t,{getTimePixel:i,getSpacePixel:o})=>{const n=be.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<be.length;t++){const i=be[t].size;n[t].rect(e-i,r-i,a+2*i,s+2*i)}}for(let e=0;e<be.length;e++)t.fillStyle=be[e].color,t.globalAlpha=be[e].opacity,t.fill(n[e])}),[e]));return Q("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=be[0].size;D(t,{x:e-m,y:l-m},c+2*m,h+2*m,Y(X(i({type:"conflict",conflictIndex:a}))),r)}}),[e])),null},_e=({position:t,children:i})=>e.createElement("div",{className:"spacetimechart-tooltip",style:{left:t.x,top:t.y}},i),Oe=e=>(e/1e3).toLocaleString("en-US",{minimumFractionDigits:1,maximumFractionDigits:1}),ke=({position:t,time:i,spaceStart:o,spaceEnd:n,timeStart:r,timeEnd:a,type:s,trains:l})=>e.createElement(_e,{position:t},e.createElement("div",{className:"time"},new Date(i).toLocaleTimeString()),e.createElement("div",{className:"position-range"},e.createElement("div",{className:"start-position"},Oe(o)),e.createElement("div",{className:"end-position"},Oe(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(", "))),Ae=({occupancyBlocks:e})=>(J("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),Ge=({imageElement:e,...t})=>(J("background",a(((i,o)=>{const n=i.createPattern(e,"repeat");n&&(i.save(),i.fillStyle=n,z(i,t,o),i.restore())}),[e,t])),null),Ce=({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(Ge,{key:`${t.type}-${t.timeStart}-${t.timeEnd}-${i}-${o}`,timeStart:t.timeStart,timeEnd:t.timeEnd,spaceStart:i,spaceEnd:o,imageElement:r}))))):null},Le=({vertices:e,style:t})=>(J("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 De(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 He=e=>(J("background",a(((t,i)=>{t.save(),t.fillStyle="#0000000D";const{width:o,height:n}=z(t,e,i);if(o&&n){t.lineWidth=1;for(let e=0;Math.abs(e)<Math.abs(o);e+=4*Math.sign(o))De(t,e,0),De(t,e,0+n);for(let e=0;Math.abs(e)<Math.abs(n);e+=4*Math.sign(n))De(t,0,e),De(t,0+o,e)}t.restore()}),[e])),null);function Fe(e,t){return{x:t.x-e.x,y:t.y-e.y}}function We(e,t,i,o){const n=(e,t)=>e.x*t.y-e.y*t.x,r=Fe(t,e),a=Fe(o,i),s=n(r,a);if(0===s)return!1;const l=Fe(i,e),c=n(l,a)/s,h=n(l,r)/s;return d(c,0,1)&&d(h,0,1)}function Be(e,t,i){if(!i.length)return!1;if(1===i.length){const{x:o,y:n}=i[0];return d(o,0,e)&&d(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})=>d(i,0,e)&&d(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 We(i,o,r,a)||We(i,o,r,s)||We(i,o,s,l)||We(i,o,a,l)}(e,t,i,o)))}const $e=32,ze=6e5,Ue=7500,Ze=10.5,Xe=e=>e.at(-1).position-e.at(0).position;const Ve=({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"})),Ye=({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(Ve,{waypoint:t,nameRef:i===t.id?o:void 0,isActive:i===t.id,isMenuActive:!!i})):e.createElement("div",{key:n},t);var r}))),je=({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,y]=t(),T=r(null);return l((()=>{const e=h?.manchetteWrapperRef?.current?.getBoundingClientRect().top,t=T?.current?.getBoundingClientRect().top;y(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(Ye,{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(g,null)),e.createElement("button",{className:"zoom-in",onClick:i,disabled:a>=Ze||!!h?.activeWaypointId},e.createElement(x,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"))))))},qe=e=>ze*Math.pow(.0010416666666666667,e/100),Ke=e=>100*Math.log(e/ze)/Math.log(.0010416666666666667),Qe=(e,t,i)=>e*Math.pow(t/e,(i-1)/9.5),Je=(e,t,i,o)=>{const n=h(i,0,100);return{xZoom:n,xOffset:o-(o-t)*qe(e)/qe(n)}},et=(e,{height:t,isProportional:i,yZoom:o},n,r)=>{if(e.length<2)return[];const a=Xe(e),s=(e=>e-40-$e)(t);if(!i)return e.map(((t,i)=>{const n=e.at(i+1);return{...t,styles:{height:`${$e*(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,$e/o),c=Qe(n,r,o);return l.map(((e,t)=>{const i=l.at(t+1),o=i?(i.position-e.position)/c:$e;return{...e,styles:{height:`${Math.round(o)}px`}}}))},tt=({waypoints:e,projectPathTrainResult:o,manchetteWithSpaceTimeChartRef:n,height:r=561,spaceTimeChartRef:l,defaultTimeOrigin:c=0,defaultSpaceOrigin:m=0})=>{const[d,p]=t(!1),[f,u]=t({xZoom:Ke(7500),yZoom:1,timeOrigin:c,spaceOrigin:m,xOffset:0,yOffset:0,scrollTo:null,panning:null,zoomMode:!1,rect:null,pixelRect:null,isProportional:!0,waypointsChart:[],scales:[]}),{xZoom:g,yZoom:x,timeOrigin:y,spaceOrigin:T,xOffset:E,yOffset:S,scrollTo:v,panning:w,zoomMode:I,rect:R,pixelRect:P,isProportional:M}=f,b=a((e=>{u((t=>({...t,timeOrigin:e})))}),[]),N=(e=>s((()=>e.flatMap((e=>e.spaceTimeCurves.map((t=>{return{id:e.id,label:e.name,color:"#8A714B",points:(i=t,o=e.departureTime,i.positions.map(((e,t)=>({time:i.times[t]+o.getTime(),position:e}))))};var i,o}))))),[e]))(o),_=r-40,O=_-16,k=_-$e,A=Xe(e),{minZoomMillimeterPerPx:G,maxZoomMillimeterPerPx:C}=((e,t,i)=>({minZoomMillimeterPerPx:i/t,maxZoomMillimeterPerPx:5e5/e}))(O,k,A),L=s((()=>et(e,{height:r,isProportional:M,yZoom:x},G,C)),[e,r,M,x,G,C]),D=s((()=>L.map((e=>({id:e.id,label:e.id,position:e.position,importanceLevel:1})))),[L]),H=s((()=>((e,{isProportional:t,yZoom:i},o,n)=>e.length<2?[]:t?[{from:e.at(0).position,to:e.at(-1).position,...t?{coefficient:Qe(o,n,i)}:{size:$e*(e.length-1)*i}}]:e.slice(0,-1).map(((t,o)=>{const n=e[o+1];return{from:t.position,to:n.position,size:$e*i}})))(D,{isProportional:M,yZoom:x},G,C)),[D,r,M,x,G,C]),F=a((({scales:{chosenTimeScale:e,chosenSpaceScale:t},overrideState:i})=>{u((o=>{if(o.zoomMode||!o.rect)return o;const n=h(e,625,ze),r=Ke(n),a=Math.min(Number(o.rect.timeStart),Number(o.rect.timeEnd)),s=(y-a)/n;let l=x,c=S;if(t){const e=h(t,C,G);if(e!==G){l=((e,t,i)=>9.5*Math.log(i/e)/Math.log(t/e)+1)(G,C,e);const t=Math.min(o.rect.spaceStart,o.rect.spaceEnd);c=Math.abs(T-t)/e}}return{...o,xZoom:r,yZoom:l,xOffset:s,yOffset:c,scrollTo:c,...i}}))}),[y,T,G,C,S,x]);i((()=>{if(R&&!I&&l?.current){const{timeStart:e,timeEnd:t,spaceStart:i,spaceEnd:o}=R,n=Math.abs(Number(t)-Number(e)),r=Math.abs(o-i),a=n/l.current.clientWidth;if(M){F({scales:{chosenTimeScale:a,chosenSpaceScale:r/O},overrideState:{rect:null}})}else if(P){const e=$e*x,{yStart:t,yEnd:i}=P,o=Math.abs(i-t)/e;let n=O/o;const r=O/(2+$e/n);n=Math.min(n,r);const s=n/$e,l=(S+Math.min(t,i)-16)/e*n;F({scales:{chosenTimeScale:a},overrideState:{rect:null,pixelRect:null,yZoom:s,yOffset:l,scrollTo:l}})}}}),[f.rect,f.zoomMode,F,O,M,P,R,l,S,x,I]);const W=a((()=>{const e=M?Ze:(O-$e)/64,t=Math.min(x+.5,e);if(t!==x){const e=S*(t/x);u((i=>({...i,yZoom:t,yOffset:e,scrollTo:e})))}}),[x,S,O,M]),B=a((()=>{const e=Math.max(1,x-.5);if(e!==x){const t=S*(e/x);u((i=>({...i,yZoom:e,yOffset:t,scrollTo:t})))}}),[x,S]),$=a(((e,t=(l?.current?.offsetWidth||0)/2)=>{u((i=>({...i,...Je(i.xZoom,i.xOffset,e,t)})))}),[l]);i((()=>{null!==v&&n.current&&n.current.scrollTo({top:v,behavior:"instant"})}),[v,n]);const z=a((()=>{u((e=>({...e,yZoom:1})))}),[]),U=a((()=>{if(!d&&n.current){const{scrollTop:e}=n.current;(e||0===e)&&u((t=>({...t,yOffset:e})))}}),[d,n]),Z=a((e=>{"Shift"===e.key&&p(!0)}),[]),X=a((e=>{"Shift"===e.key&&p(!1)}),[]);i((()=>(window.addEventListener("keydown",Z),window.addEventListener("keyup",X),()=>{window.removeEventListener("keydown",Z),window.removeEventListener("keyup",X)})),[Z,X]);const V=a((()=>{u((e=>({...e,isProportional:!e.isProportional})))}),[]),Y=a((()=>{u((e=>({...e,zoomMode:!e.zoomMode})))}),[]),j=s((()=>({contents:L,zoomYIn:W,zoomYOut:B,resetZoom:z,toggleMode:V,yZoom:x,isProportional:M,yOffset:S})),[L,W,B,z,V,x,M,S]),q=s((()=>({operationalPoints:D,spaceScales:H,timeScale:qe(g),paths:N,xOffset:E,yOffset:14-S,timeOrigin:y,spaceOrigin:T,rect:R,onZoom:({delta:e,position:t})=>{d&&$(g+e,t.x)},onPan:e=>{const{initialData:t,data:i,initialPosition:o,position:r,isPanning:a,context:{width:s,getData:l}}=e,c=(m=o,{x:(d=r).x-m.x,y:d.y-m.y});var m,d;u((e=>{if(!a)return{...e,panning:null,zoomMode:!1};if(f.zoomMode){const n=l({x:0,y:0}),a=l({x:s,y:_}),c=h(t.time,n.time,a.time),m=h(i.time,n.time,a.time),d=h(t.position,n.position,a.position),p=h(i.position,n.position,a.position),f={timeStart:new Date(c),timeEnd:new Date(m),spaceStart:d,spaceEnd:p};let u=null;if(!M){u={xStart:h(o.x,0,s),xEnd:h(r.x,0,s),yStart:h(o.y,0,_),yEnd:h(r.y,0,_)}}return{...e,rect:f,pixelRect:u}}if(!w)return{...e,panning:{initialOffset:{x:E,y:S}}};const m={...e},{initialOffset:d}=w;m.xOffset=d.x+c.x;const p=d.y-c.y;return n.current&&p>=0&&p+n.current.offsetHeight<n.current.scrollHeight&&(m.yOffset=p,n.current.scrollTop=p),m}))}})),[D,H,g,N,E,d,f,w,S,n,$,M,R,T,y,_]),K=s((()=>qe(g)),[g]),Q=s((()=>Qe(G,C,x)),[x,G,C]);return s((()=>({manchetteProps:j,spaceTimeChartProps:q,handleScroll:U,handleXZoom:$,xZoom:g,toggleZoomMode:Y,zoomMode:I,rect:R,timeScale:K,spaceScale:Q,setTimeOrigin:b})),[j,q,U,$,g,I,R,Q,K,Y,b])},it=({waypoints:t,projectPathTrainResult:i,height:o=561,children:n,header:a,manchetteProps:s,spaceTimeChartProps:l})=>{const c=r(null),h=r(null),{manchetteProps:m,spaceTimeChartProps:d,handleScroll:p}=tt({waypoints:t,projectPathTrainResult:i,manchetteWithSpaceTimeChartRef:c,height:o,spaceTimeChartRef:h,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"}},a),e.createElement("div",{ref:c,className:"manchette flex",style:{height:`${o}px`},onScroll:p},e.createElement(je,{...m,...s}),e.createElement("div",{className:"space-time-chart-container w-full sticky",ref:h,style:{bottom:0,left:0,top:2,height:o-6+"px"}},e.createElement(Pe,{className:"inset-0 absolute h-full",...d,...l},d.paths.map((t=>e.createElement(Re,{key:t.id,path:t,color:t.color}))),n))))},ot=({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(y,null)),e.createElement("button",{className:"interaction-button plus-button inactive"},e.createElement(T,null)),e.createElement("button",{className:"interaction-button inactive"},e.createElement(E,null))),e.createElement("button",{className:"interaction-button elipsis-button",onClick:()=>i()},e.createElement(S,null))),nt={Y_LEFT_VERTICAL:30,Y_LEFT_HORIZONTAL:22,Y_RIGHT_VERTICAL:36,Y_RIGHT_HORIZONTAL:42},rt={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},at={ELECTRICAL_PROFILES_HEIGHT:56,POWER_RESTRICTIONS_HEIGHT:40,SPEED_LIMIT_TAGS_HEIGHT:40},st={electricalProfiles:at.ELECTRICAL_PROFILES_HEIGHT,powerRestrictions:at.POWER_RESTRICTIONS_HEIGHT},lt="rgb(250, 249, 245)",ct="rgb(247, 246, 238)",ht="rgb(242, 240, 228)",mt="#front-interactivity-layer",dt=["energySource","tractionStatus","declivities","electricalProfiles","powerRestrictions"],pt=["steps","declivities","speedLimits","electricalProfiles","powerRestrictions","speedLimitTags"],ft=u(0,0,0),ut=u(255,104,104),gt=u(217,28,28),xt=u(121,118,113),yt=u(49,46,43),Tt=u(33,112,185),Et=u(234,167,43),St=u(255,255,255),vt={"#216482":"#E5F7FF","#D91C1C":"#F15981","#494641":"#F2F0E4","#EAA72B":"#EAA72B","#94918E":"#94918E"},wt=e=>e.layersDisplay.speedLimits&&e.mrsp?Math.max(...e.mrsp.values.map((({speed:e})=>e))):Math.max(...e.speeds.map((({value:e})=>e))),It=e=>0===e.length?0:e[e.length-1].position.start,Rt=(e,t,i)=>{e.clearRect(0,0,t,i)},Pt=(e,t,i=!0)=>{const o=[t.electricalProfiles?at.ELECTRICAL_PROFILES_HEIGHT:0,t.powerRestrictions?at.POWER_RESTRICTIONS_HEIGHT:0,t.speedLimitTags?at.SPEED_LIMIT_TAGS_HEIGHT:0].reduce(((e,t)=>e+t),0);return e+(i?o:-o)},Mt=(e,t,i=!1)=>{let o=0;const{electricalProfiles:n,powerRestrictions:r}=t;return n&&(o=st.electricalProfiles),r&&i&&(o+=st.powerRestrictions),e+o-rt.MARGIN_BOTTOM},bt=(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,Nt=(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()},_t=(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)},Ot=(e,t)=>"speedLimits"===t?e.mrsp:"electricalProfiles"===t?e.electricalProfiles:"powerRestrictions"===t?e.powerRestrictions:"speedLimitTags"!==t||e.speedLimitTags,kt=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)))}},At=e=>new Promise(((t,i)=>{const o=new Image;o.onload=()=>t(o),o.onerror=e=>i(e),o.src=e})),Gt=e=>{const t=new Blob([e],{type:"image/svg+xml"});return URL.createObjectURL(t)},Ct=(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},Lt=(e,t,i,o,n=0)=>e/t*((i-rt.MARGIN_LEFT-rt.MARGIN_RIGHT-rt.CURVE_MARGIN_SIDES)*o)+(rt.CURVE_MARGIN_SIDES/2+rt.MARGIN_LEFT+n),Dt=(e,t,i,o,n)=>e===i?t:t+(o-t)/(i-e)*(n-e),Ht=(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=>Lt(e.position.start,o,i,t),getWeight:e=>e.value.weight,minSpace:n});return r},Ft=(e,t,i)=>{const{ratioX:o,leftOffset:n}=i,r=It(i.speeds);return(e-n-rt.CURVE_MARGIN_SIDES/2)*r/((t-rt.MARGIN_LEFT-rt.MARGIN_RIGHT-rt.CURVE_MARGIN_SIDES)*o)},Wt=(e,t,i)=>{const{ratioX:o,leftOffset:n,stops:r}=i,a=It(i.speeds),s=Ht(r,o,t,a);let l=0;if(s.length>1){const o=(c=Ft(e,t,i),h=0,m=a,Math.min(Math.max(c,h),m)),n=Ct(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=Lt(d,a,t,o,n);return Math.abs(p-(e+rt.MARGIN_LEFT))<6?s[l]:null},Bt=({globalHeight:o,color:n,store:r,setStore:a,setIsMouseHoveringSettingsPanel:s,translations:l})=>{const[c,h]=t("442px");return i((()=>{const e=Pt(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")),pt.map((t=>e.createElement("div",{key:t,className:"selection"},e.createElement(w,{label:l?.layersDisplay[t]||t,checked:r.layersDisplay[t],disabled:!Ot(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")),dt.map((t=>e.createElement("div",{key:t,className:"selection"},e.createElement(w,{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(v,null))))},$t=()=>R.zoom().transform(I.select(mt),R.zoomIdentity),{MARGIN_LEFT:zt,MARGIN_RIGHT:Ut,MARGIN_TOP:Zt,MARGIN_BOTTOM:Xt}=rt,Vt=({ctx:e,width:t,height:i,store:o})=>{const{stops:n,ratioX:r,leftOffset:a,cursor:s}=o;if(0===n.length)return;Rt(e,t,i);const l=It(o.speeds),c=Ht(n,r,t,l);e.save(),e.translate(a,0),e.strokeStyle=Tt.alpha(.5).hex(),e.lineWidth=1,e.lineCap="round",e.setLineDash([1,6]),e.beginPath(),c.forEach((({position:o})=>{const n=Lt(o.start,l,t,r);e.moveTo(n,Zt),e.lineTo(n,i-Xt)})),e.stroke(),e.lineWidth=2,e.fillStyle=xt.hex(),e.strokeStyle=xt.hex(),e.setLineDash([]);const h=s.x?Wt(s.x,t,o):null;c.forEach((({position:o})=>{if(h&&o.start===h.position.start)return;const n=Lt(o.start,l,t,r);e.beginPath(),e.roundRect(n-.5,i-6-Xt-1,1,6,[1,1,0,0]),e.fill(),e.closePath(),e.stroke()})),e.restore();const m=Ht(c,r,t,l,25),d=[],p=[];m.forEach((e=>{const i=Lt(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=Lt(o.start,l,t,r,a),c=i-6-Xt-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=ft.hex():e.fillStyle=yt.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-Ut,0,Ut,i),e.clearRect(0,0,t,Zt),e.clearRect(0,i-Xt,t,Xt)},Yt=(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},jt=({width:t,height:i,store:o})=>{const n=Yt(Vt,{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:qt,MARGIN_RIGHT:Kt,MARGIN_LEFT:Qt,MARGIN_BOTTOM:Jt,MARGIN_TOP:ei}=rt,ti=({ctx:e,width:t,height:i,store:o})=>{const{mrsp:n,trainLength:r,ratioX:a,leftOffset:s}=o;if(!n)return;Rt(e,t,i),e.save(),e.translate(s,0);const l=i-Jt-ei,c=wt(o),h=It(o.speeds);e.lineCap="round";let m=Lt(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=Lt(f,h,t,a),g=l-o/c*(l-qt)+ei;null!==d&&(e.beginPath(),e.strokeStyle=ut.alpha(.5).hex(),e.lineWidth=.5,e.moveTo(m,d),e.lineTo(m,g),e.stroke());const x=s?Et:gt,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=Lt(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,Qt,i),e.clearRect(t-Kt,0,Kt,i)},ii=({width:t,height:i,store:o})=>{const n=Yt(ti,{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:oi,CURVE_MARGIN_SIDES:ni}=rt,ri=(e,t,i)=>{const{maxSpeed:o,maxPosition:n,ratioX:r}=t,{width:a,height:s}=e,l=ni/2,c=s-oi,h=(a-ni)/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},ai=({ctx:e,width:t,height:i,store:o})=>{const{speeds:n,ecoSpeeds:r,ratioX:a,leftOffset:s}=o,l=u(17,101,180),c=u(7,69,128);Rt(e,t,i),e.save(),e.translate(s,0);const h=wt(o),m=It(o.speeds),d=ri({width:t,height:i},{maxSpeed:h,maxPosition:m,ratioX:a},n),p=ri({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()},si=({width:t,height:i,store:o})=>{const n=Yt(ai,{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:li,MARGIN_TOP:ci,MARGIN_BOTTOM:hi,RIGHT_TICK_MARGINS:mi}=rt,di=({ctx:e,width:t,height:i,store:o})=>{const{slopes:n,ratioX:r,leftOffset:a}=o,{maxGradient:s}=kt(o),l=It(o.speeds);if(!n||0===n.length)return void console.error("Slopes data is missing or empty.");Rt(e,t,i),e.save(),e.translate(a,0);const c=i-ci-hi-mi/2,h=ci+mi/2+c/2;e.fillStyle="#CFDDCE";try{const i=(t-li)/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+li/2,m=a.start*i+li/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()},pi=({width:t,height:i,store:o})=>{const n=Yt(di,{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})},fi=e=>e>7?7:e,ui=({ctx:e,width:t,height:i,store:o})=>{const{electricalProfiles:n,ratioX:r,leftOffset:a,cursor:s}=o,{ELECTRICAL_PROFILES_HEIGHT:l}=at;if(!n)return;Rt(e,t,i);const c=i-l;e.save(),e.translate(a,0);const h=It(o.speeds),{MARGIN_TOP:m,MARGIN_BOTTOM:d,MARGIN_LEFT:p,MARGIN_RIGHT:f,CURVE_MARGIN_SIDES:u,ELECTRICAL_PROFILES_MARGIN_TOP:g}=rt;_t(e,lt,rt,t,c,l),n.forEach((i=>{const o=bt(i.position.start,h,t,r,rt),n=bt(i.position.end,h,t,r,rt);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=fi(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<=bt(e.end,h,t,r,rt)-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=fi(s),a=c-d+g+4*n,l=bt(i,h,t,r,rt)||p+u/2,m=(bt(o,h,t,r,rt)||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()}}Nt(e,"rgba(0,0,0,0.1)",rt,t,c+1-d),e.restore(),e.clearRect(0,0,p,i),e.clearRect(t-f,0,f,i)},gi=({width:t,height:i,store:o})=>{const n=Yt(ui,{width:t,height:i,store:o});return e.createElement("canvas",{id:"electrical-profile-layer",className:"absolute",ref:n,width:t,height:i})},xi=({ctx:e,width:t,height:i,store:o,setStore:n})=>{Rt(e,t,i);const r=I.select(mt);n&&r.call((e=>R.zoom().filter((e=>e.shiftKey)).on("zoom",(()=>{const t=I.select(mt),{k:i,x:o}=R.zoomTransform(t.node());i>=1?e((e=>({...e,ratioX:i,leftOffset:o}))):(e((e=>({...e,ratioX:1,leftOffset:0}))),t.call($t))})))(n)),r.on("mousemove",(e=>{const t=I.pointer(e);n&&n((()=>({...o,cursor:{x:t[0],y:t[1]}})))})),r.on("mouseleave",(()=>{n&&n((()=>({...o,cursor:{x:null,y:null}})))}))},yi=({width:t,height:i,store:o,setStore:n})=>{const r=Yt(xi,{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:Ti,MARGIN_RIGHT:Ei}=rt,Si=({ctx:e,width:t,height:i,store:o})=>{const{powerRestrictions:n,ratioX:r,leftOffset:a,layersDisplay:{electricalProfiles:s}}=o;if(!n)return;Rt(e,t,at.POWER_RESTRICTIONS_HEIGHT),e.save(),e.translate(a,0);const l=It(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=lt;s&&(c=ct),Nt(e,"rgba(0,0,0,0.1)",rt,t,i-at.POWER_RESTRICTIONS_HEIGHT+1),_t(e,c,rt,t,i,at.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=bt(i.start,l,t,r,rt);e.beginPath(),e.moveTo(s,8),e.lineTo(s,32);const c=Math.floor(e.measureText(o.powerRestriction).width);let h=bt(i.end,l,t,r,rt);a===n.length-1&&(h-=rt.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,Ti,at.POWER_RESTRICTIONS_HEIGHT),e.clearRect(t-Ei,0,Ei,at.POWER_RESTRICTIONS_HEIGHT)},vi=({width:t,marginTop:i,store:o})=>{const n=Yt(Si,{width:t,height:at.POWER_RESTRICTIONS_HEIGHT,store:o});return e.createElement("canvas",{id:"power-restrictions-layer",className:"absolute",ref:n,width:t,height:at.POWER_RESTRICTIONS_HEIGHT,style:{marginTop:i}})},wi=({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}=rt,{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:Ii,MARGIN_RIGHT:Ri,MARGIN_TOP:Pi,MARGIN_BOTTOM:Mi,CURVE_MARGIN_TOP:bi,CURVE_MARGIN_SIDES:Ni}=rt,_i=12.75,Oi=({width:o,height:n,heightOffset:a,store:s})=>{const l=r(null),[c,h]=t(null),m=Pt(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})=>{Rt(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=wt(o),R=It(o.speeds),P=Pt(i,r,!1)-Mi-Pi,M=t-Ii-Ri,b=e=>e*((M-Ni)/R)*a+s+Ni/2;if(null===n.x||null===n.y)return;let N=n.x+Ii,_=Ft(n.x,t,o);if(_<0||_>R)return;let O=!1;if(r.steps){const e=Wt(n.x,t,o);null!==e&&(O=!0,_=e.position.start,N=Lt(_,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=Ct(l,_,(e=>e.position.start));G===l.length-1&&G--;let C=Ct(c,_,(e=>e.position.start));C===c.length-1&&C--;const L=l[G],D=l[G+1],H=Dt(L.position.start,L.value,D.position.start,D.value,_);f=H.toFixed(1);const F=P-H/I*(P-bi)+Pi,W=c[C],B=c[C+1],$=Dt(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-bi)+Pi,S=m.findLast((({position:e})=>e.start<=_)).value,e.font="normal 12px IBM Plex Sans",e.fillStyle=ft.hex(),e.beginPath(),e.strokeStyle=ft.alpha(.4).hex(),e.lineWidth=.5,e.moveTo(N,F),e.lineTo(N,i-Mi),e.moveTo(N,w),e.lineTo(Ii,w),Math.abs(F-w)>2&&(e.moveTo(N,F),e.lineTo(Ii,F)),e.stroke(),e.beginPath(),e.lineWidth=3,e.strokeStyle=St.hex(),e.lineCap="round",e.moveTo(N-_i,w),e.lineTo(N+_i,w),e.moveTo(N,w-_i),e.lineTo(N,w+_i),e.stroke(),e.beginPath(),e.lineWidth=1,e.strokeStyle=ft.hex(),e.moveTo(N-_i,w),e.lineTo(N+_i,w),e.moveTo(N,w-_i),e.lineTo(N,w+_i),e.stroke(),e.beginPath(),e.strokeStyle=ft.hex(),e.lineCap="butt",e.lineWidth=1,e.moveTo(Ii,w),e.lineTo(Ii,w),e.stroke();const z=(Math.round(10*_)/10).toFixed(1).toString();return e.textAlign="center",O?(e.beginPath(),e.lineWidth=2,e.roundRect(N-.5,i-Mi-24*.6,1,24,[1,1,1,1]),e.fill(),e.stroke(),e.fillText(z,N,i-Mi+1.33*Ni)):(e.beginPath(),e.lineWidth=1,e.moveTo(N,i-Mi),e.lineTo(N,i-Mi+6),e.stroke(),e.fillText(z,N,i-Mi+1.33*Ni)),N-Ii<e.measureText(g).width/2?e.textAlign="start":N-Ii>M-e.measureText(g).width/2&&(e.textAlign="end"),e.fillText(g,N,i-Mi+36),e.clearRect(0,0,t,Pi),{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 Rt(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(wi,{width:o,height:n,store:s,...c}))},ki=({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)),Ai=17,Gi=12,Ci=({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}=rt;Rt(e,t,at.SPEED_LIMIT_TAGS_HEIGHT),e.save(),e.translate(s,0);const p=It(o.speeds);let f=lt;l&&c?f=ht:(l||c)&&(f=ct),Nt(e,"rgba(0,0,0,0.1)",rt,t,1),_t(e,f,rt,t,h,at.SPEED_LIMIT_TAGS_HEIGHT-1),r&&(r.forEach((({position:i,value:o},r)=>{const{tag:s,color:l}=o,c=bt(i.start,p,t,a,rt),h=bt(i.end,p,t,a,rt);if(void 0!==h){const t=h-c-1,i=vt[l]||l;e.fillStyle=l,e.strokeStyle="UU"===s?"#494641":l,e.lineWidth=1,e.beginPath(),e.fillRect(c,Gi,t-1,Ai),e.fillStyle=i;const o=e.measureText(s).width+8+(0===r?8:0);if(e.fillRect(c+1+o,Gi,t-o-2,Ai),e.rect(c+o,Gi,t-1-o,Ai),e.strokeRect(c+1,Gi,t-1,Ai),e.closePath(),"UU"===s&&(e.lineWidth=.5,e.beginPath(),e.moveTo(c+o+2,Gi),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,St.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)}}})),Nt(e,"rgba(0,0,0,0.1)",rt,t,i),e.restore(),e.clearRect(0,0,m,at.SPEED_LIMIT_TAGS_HEIGHT),e.clearRect(t-d,0,t,at.SPEED_LIMIT_TAGS_HEIGHT))},Li=({width:o,marginTop:n,store:a})=>{const s=r(null),l=r(),[c,h]=t({questionImage:null,alertFillImage:null});return i((()=>{(async()=>{const e=Gt('<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=Gt('<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 At(e),o=await At(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 Ci({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}=rt,c=It(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=bt(i.start,c,e,n,rt),f=bt(i.end,c,e,n,rt)-p-1;if(a.x>=p-l+r&&a.x<=p-l+r+f&&a.y>=t-s+Gi-2&&a.y<=t-s+Gi-1+Ai)return{cursorX:a.x+l,cursorY:Gi,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:at.SPEED_LIMIT_TAGS_HEIGHT,style:{marginTop:n}}),l.current&&e.createElement(ki,{cursorX:l.current.cursorX,cursorY:n-40-2,height:40,text:l.current.text}))},{MARGIN_LEFT:Di,MARGIN_RIGHT:Hi,MARGIN_BOTTOM:Fi,CURVE_MARGIN_SIDES:Wi}=rt,Bi=({ctx:e,width:t,height:i,store:o})=>{const{ratioX:n,leftOffset:r,cursor:a}=o;Rt(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=It(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-Wi-Di-Hi)*(m*c/s)*n/m;e.beginPath();const p=i-Fi;for(let o=0;o<=m;o++){const n=Di+Wi/2+d*o,s=o%h==0?.66*Wi:.33*Wi;if(e.moveTo(n,p),e.lineTo(n,i-Fi+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+Di-r:1/0,h=Math.abs(l-n),m=Math.max(Math.min(h/s-.1,1),0),d=Math.abs(t-Hi-Wi/2-r-n),f=Math.max(Math.min(d/s-.1,1),0),u=Math.abs(Di+Wi/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*Wi)}}e.closePath(),e.stroke(),e.restore(),e.clearRect(0,0,Di,i),e.clearRect(t-Hi,0,t,i),e.fillStyle="rgb(182, 179, 175)",e.textAlign="center",e.shadowOffsetY=0,e.shadowBlur=0,e.beginPath(),e.fillText("km",t-Hi-Wi/2,p+1.33*Wi),e.closePath(),e.stroke()},$i=({width:t,height:i,store:o})=>{const n=Yt(Bi,{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:Ui,MARGIN_BOTTOM:Zi,CURVE_MARGIN_TOP:Xi,MARGIN_RIGHT:Vi}=rt,{Y_LEFT_VERTICAL:Yi,Y_LEFT_HORIZONTAL:ji}=nt,qi=({ctx:e,width:t,height:i,store:o})=>{const n=wt(o);Rt(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-Zi-Ui-Xi)*(a*r/n)/a;e.beginPath();for(let t=0;t<=a;t++){const o=i-Zi-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-Zi-s*o;e.moveTo(zi,n),e.lineTo(t-Vi,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-Zi-s*o;e.moveTo(zi,n),e.lineTo(t-Vi,n)}e.stroke(),e.clearRect(0,0,t,Ui),e.clearRect(zi-6,i-Zi,t,Zi),e.clearRect(0,i-Zi+6,zi,Zi),e.fillStyle="rgb(182, 179, 175)",e.textAlign="center",e.shadowOffsetY=0,e.shadowBlur=0,e.beginPath(),e.fillText("km/h",Yi,ji),e.closePath(),e.stroke()},Ki=({width:t,height:i,store:o})=>{const n=Yt(qi,{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:Qi,MARGIN_TOP:Ji,MARGIN_BOTTOM:eo,RIGHT_TICK_MARGINS:to}=rt,{Y_RIGHT_VERTICAL:io,Y_RIGHT_HORIZONTAL:oo}=nt,no=({ctx:e,width:t,height:i,store:o})=>{Rt(e,t,i);const{minGradient:n,maxGradient:r}=kt(o),a=i-Ji-eo-to,s=a/12,l=Ji+to/2+a/2+2,c=t-Qi+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-Qi-6,n),e.lineTo(t-Qi,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-oo,io)}e.stroke(),e.clearRect(0,0,t,Ji),e.clearRect(t-Qi,i-eo,t,eo),e.clearRect(0,i-eo+6,t-Qi,eo)},ro=({width:t,height:i,store:o})=>{const n=Yt(no,{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})},ao=({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=Pt(n,c.layersDisplay),f=Pt(d,c.layersDisplay),{OFFSET_RIGHT_AXIS:u}=rt,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(ot,{reset:()=>{h((e=>({...e,ratioX:1,leftOffset:0}))),$t()},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(Bt,{globalHeight:p,color:r,store:c,setStore:h,setIsMouseHoveringSettingsPanel:y,translations:l})),c.layersDisplay.declivities&&e.createElement(pi,{width:m,height:d,store:c}),e.createElement(si,{width:m,height:d,store:c}),c.layersDisplay.speedLimits&&e.createElement(ii,{width:g,height:n,store:c}),c.layersDisplay.steps&&e.createElement(jt,{width:g,height:n,store:c}),e.createElement(Ki,{width:o,height:n,store:c}),c.layersDisplay.electricalProfiles&&e.createElement(gi,{width:g,height:n+at.ELECTRICAL_PROFILES_HEIGHT,store:c}),c.layersDisplay.powerRestrictions&&e.createElement(vi,{width:g,marginTop:Mt(n,c.layersDisplay),store:c}),c.layersDisplay.speedLimitTags&&e.createElement(Li,{width:g,marginTop:Mt(n,c.layersDisplay,c.layersDisplay.speedLimitTags),store:c}),e.createElement($i,{width:g,height:p,store:c}),c.layersDisplay.declivities&&e.createElement(ro,{width:o,height:n,store:c}),!x&&e.createElement(Oi,{width:g,height:p,heightOffset:f,store:c}),e.createElement(yi,{width:m,height:f,store:c,setStore:h}))},so=100,lo=48.5,co={SANS:"400 12px IBM Plex Sans",MONO:"400 10px IBM Plex Mono"},ho={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)"},mo={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]},po=[[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]],fo=({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()},uo=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"),go={medium:24,small:4},xo=-30*Math.PI/180,{SANS:yo,MONO:To}=co,{WHITE_100:Eo,GREY_50:So,GREY_60:vo,GREY_80:wo,SELECTION_20:Io}=ho,{SANS:Ro}=co,{REMAINING_TRAINS_BACKGROUND:Po,WHITE_100:Mo,SELECTION_20:bo}=ho,No=4.5,_o=({ctx:e,remainingTrainsNb:t,xPosition:i})=>{e.fillStyle=Po,e.beginPath(),e.rect(i,36.5,70,24),e.fill(),e.stroke(),e.fillStyle=Mo,e.font=Ro,e.textAlign="center",e.textBaseline="middle",e.fillText(`+${t} trains`,i+35,48.5)},Oo=({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+so*m+r,f=20+so*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=Mo,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=bo,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-No,45),e.lineTo(t+No,45),e.lineTo(t+1,50),e.lineTo(t+No,55),e.lineTo(t-No,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<go[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":Eo,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(xo),e.fillStyle=Io,e.beginPath(),e.roundRect(-4,0,h+8,18),e.fill(),e.restore()}fo({ctx:e,text:t.arrivalTrainName,x:m,y:d,color:So,rotateAngle:xo,stroke:{color:Eo,width:4}}),fo({ctx:e,text:t.arrivalTime.getMinutes().toLocaleString("fr-FR",{minimumIntegerDigits:2}),x:r?i-4:i,y:n+8.5,color:wo,xPosition:p,yPosition:"top",font:yo,stroke:u}),r||fo({ctx:e,text:t.departureTime.getMinutes().toLocaleString("fr-FR",{minimumIntegerDigits:2}),x:o,y:n+8.5,color:wo,xPosition:f,yPosition:"top",font:yo,stroke:u}),fo({ctx:e,text:t.originStation||"--",x:r?i-4:i,y:n-5,color:vo,xPosition:"right",yPosition:"bottom",font:To,stroke:u}),fo({ctx:e,text:t.destinationStation||"--",x:r?o+4:o,y:n-5,color:vo,xPosition:"left",yPosition:"bottom",font:To,stroke:u})})({ctx:e,zone:t,arrivalTimePixel:o,departureTimePixel:n,yPosition:r,isThroughTrain:a,selectedTrainId:d})},ko=({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:so;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=lo,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=lo,p=n,f=l,u=l,x=4,y=1,Oo({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),Oo({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;_o({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:Ao,GREY_20:Go,RAIL_TICK:Co}=ho,Lo=({ctx:e,xStart:t,yStart:i,ticks:o,stroke:n})=>{const r=f(o)/2;e.strokeStyle=n,e.beginPath(),e.setLineDash(o),e.moveTo(t,i-r),e.lineTo(t,i+r),e.stroke()},Do=({ctx:e,width:t,getTimePixel:i,labelMarks:o})=>{e.fillStyle=Ao,e.save(),(({xStart:e,yStart:t,width:i,stroke:o=Go,ctx:n})=>{n.clearRect(e,t,i,9),n.fillStyle=Ao,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=uo(o);Lo({ctx:e,xStart:i(+t),yStart:50,ticks:mo[n],stroke:Co})}e.restore()},{WHITE_100:Ho,HOUR_BACKGROUND:Fo}=ho,Wo=({ctx:e,xStart:t,width:i,height:o,switchBackground:n})=>{t>=0&&(e.clearRect(t,0,i,o),e.fillStyle=n?Fo:Ho,e.fillRect(t,0,i,o))},Bo=({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,po),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,Wo({ctx:e,xStart:a(+o),width:t,height:i,switchBackground:f})}o?.forEach(((i,o)=>{const n=0===o?10:so;e.translate(0,n),Do({ctx:e,width:t,getTimePixel:a,labelMarks:p})})),e.restore()},$o=({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&&Bo({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($o,{useDraw:i}),e.createElement(ko,{useDraw:i,selectedTrainId:n,setSelectedTrainId:r,mousePosition:a})),Uo=({tracks:t})=>e.createElement("div",{id:"track-occupancy-manchette"},t.map((t=>e.createElement("div",{className:"track",key:t.id,style:{height:so}},e.createElement("span",{className:"track-line"},t.line),e.createElement("div",{className:"track-name"},t.name),e.createElement("div",{className:"track-rail"})))));export{b as CanvasContext,Ne as ConflictLayer,ke as ConflictTooltip,Ie as DEFAULT_LEVEL,le as DEFAULT_THEME,Ue as DEFAULT_ZOOM_MS_PER_PX,je as Manchette,it as ManchetteWithSpaceTimeChart,N as MouseContext,Ae as OccupancyBlockLayer,Re as PathLayer,Ge as PatternRect,Le as Quadrilateral,Pe as SpaceTimeChart,M as SpaceTimeChartContext,ao as SpeedSpaceChart,pe as TimeCaptions,_e as Tooltip,zo as TrackOccupancyCanvas,Uo as TrackOccupancyManchette,Ce as WorkScheduleLayer,He as ZoomRect,Te as getSpaceAtTime,Me as isConflictPickingElement,Be as isPathOnScreen,Se as isPointPickingElement,ve as isSegmentPickingElement,Ke as timeScaleToZoomValue,J as useDraw,tt as useManchetteWithSpaceTimeChart,Q as usePicking};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|