UNPKG

gantt-schedule-timeline-calendar

Version:

Gantt, Schedule, Timeline, Calendar components all in one. [gantt, timeline, schedule, scheduler, calendar, booking, gantt chart, reservation, javascript gantt, javascript timeline, javascript schedule, javascript scheduler, javascript calendar, javascrip

61 lines 185 kB
import{d as t,u as e,a as o,S as i,A as a,h as s,l as n,v as l,D as r,_ as c,m as d,b as h,c as u,p as m,P as g,e as f,f as p,J as w,V as v}from"./vendor.esm.min.js"; /** * Gantt-Schedule-Timeline-Calendar Time api * * @copyright NEURONET - Rafal Pospiech * @author Rafal Pospiech <neuronet.io@gmail.com> * @module gantt-schedule-timeline-calendar * @link https://github.com/neuronetio/gantt-schedule-timeline-calendar * @link https://gantt-schedule-timeline-calendar.neuronet.io * @version 3.40.7 * @released 2025-05-27 * @license SEE LICENSE IN LICENSE FILE */class b{constructor(i,a){this.utcMode=!1,this.unsubs=[],this.currentDateLastCheck=0,this.state=i,this.api=a,this.dayjs=t,this.dayjs.extend(e),this.dayjs.extend(o),this.unsubs.push(i.subscribe("config.utcMode",(t=>{this.utcMode=t}))),this.unsubs.push(i.subscribe("config.locale",(t=>{if(!t.name)throw new Error("Locale must have a name property.");this.locale=t,this.dayjs.locale(this.locale,null,!0)})))}destroy(){for(const t of this.unsubs)t()}date(e=void 0){return this.utcMode?t.utc(e).locale(this.locale.name):e?t(e).locale(this.locale.name):t().locale(this.locale.name)}recalculateTime(){this.api.main.recalculateTimes([{name:"all"}])}recalculateFromTo(t,e=!1){const o=t.period;if((t=Object.assign({},t)).from=+t.from,t.to=+t.to,t.fromDate=this.date(t.from).startOf(o),t.from=t.fromDate.valueOf(),t.toDate=this.date(t.to).endOf(o),t.to=t.toDate.valueOf(),!t.autoExpandTimeFromItems||t.calculatedZoomMode)return t;let i=Number.MAX_SAFE_INTEGER,a=0;const s=this.state.get("config.chart.items");if(Object.keys(s).length>0&&(0===t.from||0===t.to||e)){for(const t in s){const e=s[t];e.time.start<i&&e.time.start&&(i=e.time.start),e.time.end>a&&(a=e.time.end)}i<t.from&&(t.fromDate=this.date(i).startOf(o),t.from=t.fromDate.valueOf()),a>t.to&&(t.toDate=this.date(a).endOf(o),t.to=t.toDate.valueOf())}return t}getCenter(t){return t.leftGlobal+Math.round((t.rightGlobal-t.leftGlobal)/2)}isInCurrentView(t,e=this.state.get("$data.chart.time")){const o=t.valueOf();return!(o<e.leftGlobal||o>e.rightGlobal)}recalculateDatesWidths(t,e=this.state.get("$data.chart.time")){if(!e.timePerPixel)throw new Error("[gantt-schedule-timeline-calendar] No timePerPixel");for(const o of t){if(!o.leftGlobal||!o.rightGlobal)throw new Error("[gantt-schedule-timeline-calendar] No date leftGlobal or rightGlobal.");o.width=(o.rightGlobal+1-o.leftGlobal)/e.timePerPixel}return t}recalculateDatesPositions(t,e=this.state.get("$data.chart.time"),o=!0,i=!1){let a=0;if(o)for(const o of t){if(o.leftGlobal>=e.leftGlobal)break;if(isNaN(o.width))throw new Error("[gantt-schedule-timeline-calendar] NaN date width.");a-=o.width}for(let o of t){if(i&&(o=this.api.mergeDeep({},o)),o.leftPx=a,o.rightPx=a+o.width,isNaN(o.leftPx)||isNaN(o.rightPx))throw new Error("[gantt-schedule-timeline-calendar] Date leftPx or rightPx is a NaN.");o.currentView&&(o.currentView.leftPx=o.leftPx-e.leftPx,o.currentView.rightPx=o.rightPx-e.leftPx,o.currentView.width=o.currentView.rightPx-o.currentView.leftPx),a+=o.width}return t}setDatesCacheLevel(t,e,o=this.state.get("$data.chart.time")){if(!e.length)return;o.datesCache||(o.datesCache={timePerPixel:0,levels:[]}),o.datesCache.timePerPixel=o.timePerPixel,o.datesCache.levels[t]||(o.datesCache.levels[t]={leftTime:0,rightTime:0,dates:[]});const i=o.datesCache.levels[t];i.leftTime=e[0].leftGlobal,i.rightTime=e[e.length-1].rightGlobal,i.dates=[...e]}addDatesToCacheLevel(t,e,o=this.state.get("$data.chart.time")){if(!e.length)return;if(!o.datesCache)return;if(o.datesCache.timePerPixel!==o.timePerPixel)return e;const i=e[0],a=e[e.length-1],s=o.datesCache.levels[t];if(!s)return e;if(s.leftTime<=i.leftGlobal&&s.rightTime>=a.rightGlobal)return s.dates;if(s.dates.length>=1e6)throw new Error("[gantt-schedule-timeline-calendar] To many dates.");const n=[];if(i.leftGlobal<s.leftTime){for(const t of e){if(!(t.leftGlobal<s.leftTime))break;n.push(t)}s.leftTime=n[0].leftGlobal}for(const t of s.dates)n.push(t);if(a.rightGlobal>s.rightTime){for(const t of e)t.rightGlobal>s.rightTime&&n.push(t);s.rightTime=n[n.length-1].rightGlobal}return s.dates=n,s.dates}isLevelDateInCache(t,e,o=this.state.get("$data.chart.time")){if(!o.datesCache)return!1;if(o.datesCache.timePerPixel!==o.timePerPixel)return!1;const i=o.datesCache.levels[t];return!(!i||!i.dates.length)&&(e>=i.leftTime&&e<=i.rightTime)}getLevelDatesFromCache(t,e,o,i=this.state.get("$data.chart.time")){if(i.datesCache.timePerPixel!==i.timePerPixel)return[];const a=i.datesCache.levels[t];if(!a)return[];if(!(e>=a.leftTime&&o<=a.rightTime))return[];let s=0,n=0,l=!1;const r=a.dates.length;for(;n<r;n++){const t=a.dates[n];if(t.rightGlobal>=e&&(l=!0),t.rightGlobal>=o)break;l||s++}return{[Symbol.iterator](){let t=s;return{next:()=>t<=n?{value:a.dates[t++],done:!1}:(t=s,{done:!0})}},length:n-s+1}}getLevelDateFromCache(t,e,o=this.state.get("$data.chart.time")){if(!this.isLevelDateInCache(t,e,o))return null;for(const i of o.datesCache.levels[t].dates)if(i.rightGlobal>=e)return i;return null}getAllLevelDatesFromCache(t,e=this.state.get("$data.chart.time")){return e.datesCache.levels[t].dates}findOrCreateMainDateAtTime(t,e=this.state.get("$data.chart.time")){if(this.isLevelDateInCache(e.level,t,e))return this.getLevelDateFromCache(e.level,t,e);let o=[];e.datesCache.levels[e.level]&&(o=e.datesCache.levels[e.level].dates),o=this.addMissingDates(o,this.date(t),e);for(const e of o)if(e.rightGlobal>=t)return e;return null}addMissingDates(t,e,o=this.state.get("$data.chart.time"),i=!0){if(!t.length)return[];const a=t[0],s=t[t.length-1];if(!(e.valueOf()<a.leftGlobal||e.valueOf()>s.rightGlobal))return t;if(this.isLevelDateInCache(o.level,e.valueOf(),o))return this.getAllLevelDatesFromCache(o.level,o);const n=t.length;let l=t;if(i){l=new Array(n);for(let e=0;e<n;e++)l[e]=this.api.mergeDeep({},t[e])}const r=this.state.get(`config.chart.calendarLevels.${o.level}`),c=this.getCurrentFormatForLevel(r,o);let d=1;if("number"==typeof c.periodIncrement&&(d=c.periodIncrement),e.valueOf()<a.leftGlobal){if("function"==typeof c.periodIncrement)return t;const s=a.leftGlobalDate.subtract(1,"ms");let n=a.leftGlobalDate.subtract(d,o.period).startOf(o.period);for(;e.valueOf()<n.valueOf();)n=n.subtract(d,o.period).startOf(o.period);let r=[];do{r=this.generatePeriodDates({leftDate:n,rightDate:s,period:o.period,level:this.state.get(`config.chart.calendarLevels.${o.level}`),levelIndex:o.level,callOnDate:!0,callOnLevelDates:!0,time:o}),n=n.subtract(1,o.period)}while(!r.length||r[0].leftGlobal>e.valueOf());return r=r.filter((t=>!l.find((e=>e.leftGlobal===t.leftGlobal)))),t=[...r,...l],t=this.recalculateDatesWidths(t,o),t=this.recalculateDatesPositions(t,o,!0,i),this.addDatesToCacheLevel(o.level,t,o)}if(e.valueOf()>s.rightGlobal){let a=s.rightGlobalDate.add(d,o.period).endOf(o.period);for(;e.valueOf()>a.valueOf();)a=a.add(d,o.period).endOf(o.period);let n=this.generatePeriodDates({leftDate:s.rightGlobalDate.add(1,"ms"),rightDate:a,period:o.period,level:this.state.get(`config.chart.calendarLevels.${o.level}`),levelIndex:o.level,callOnDate:!0,callOnLevelDates:!0,time:o});return n=n.filter((t=>!l.find((e=>e.leftGlobal===t.leftGlobal)))),t=[...l,...n],t=this.recalculateDatesWidths(t,o),t=this.recalculateDatesPositions(t,o,!0,i),this.addDatesToCacheLevel(o.level,t,o)}return l}getGlobalOffsetPxFromDates(t,e=!0,o=this.state.get("$data.chart.time"),i=void 0){const a=t.valueOf();if(!o.allDates||0===o.allDates.length)return-100;if(void 0===i&&(i=o.allDates[o.level]),e&&(i=this.addMissingDates(i,t,o)),!i||0===i.length)return-1;let s;for(let t=0,e=i.length;t<e;t++){const e=i[t];if(a<=e.rightGlobal+1){s=e;break}}return s?a<s.leftGlobal?s.leftPx:s.rightPx-(s.rightGlobal-a)/o.timePerPixel:a<=o.leftGlobal?0:a>=o.rightGlobal?o.totalViewDurationPx+(a-o.rightGlobal+1)/o.timePerPixel:-1}getViewOffsetPxFromDates(t,e=!0,o=this.state.get("$data.chart.time"),i=void 0,a=!0){i||(i=o.allDates[o.level]),a&&(i=this.addMissingDates(i,t,o));const s=this.getDatesDiffPx(o.leftGlobalDate,t,o,!0,i);return e?this.limitOffsetPxToView(s):s}limitOffsetPxToView(t,e=this.state.get("$data.chart.time")){if(t<0)return 0;if(!e.levels.length)return e.width;const o=e.levels[e.level];if(!o.length)return e.width;const i=o[o.length-1];return t>i.currentView.rightPx?i.currentView.rightPx:t}findDateAtViewOffsetPx(t,e){return e.find((e=>e.currentView.rightPx>=t))}findDateIndex(t,e){let o=0;for(const i of e){if(i.rightGlobal>=t)return o;o++}return-1}findDateAtTime(t,e=void 0){if(!e){const t=this.state.get("$data.chart.time");e=t.allDates[t.level]}return e.find((e=>e.rightGlobal>=t))}getMainDateFromRelativePosition(t,e){const o=t.leftPx+e,i=this.state.get("$data.chart.time"),a=i.allDates[i.level];for(const t of a)if(t.rightPx>o)return t}getTimeFromOffsetPx(t,e=!0,o=this.state.get("$data.chart.time"),i=void 0){let a=t;e&&(a+=o.leftPx),i||(i=o.allDates[o.level]);const s=this.state.get(`config.chart.calendarLevels.${o.level}`),n=this.getCurrentFormatForLevel(s,o);let l=1;if("number"==typeof n.periodIncrement&&(l=n.periodIncrement),a<0){if("function"==typeof n.periodIncrement)return o.from;let t,e=o.fromDate.subtract(l,o.period).startOf(o.period),i=0;for(let s=0;s<1e3;s++){const s=this.generatePeriodDates({leftDate:e,rightDate:e.add(l,o.period).subtract(1,"ms"),period:o.period,time:o,level:this.state.get(`config.chart.calendarLevels.${o.level}`),levelIndex:o.level,callOnDate:!0,callOnLevelDates:!0,expandIfMissing:!1});if(s.length&&(t=s[0],i-=t.width,i<=a))return t.leftGlobal+(a-i)*o.timePerPixel;e=e.subtract(l,o.period).startOf(o.period)}}else if(a>o.totalViewDurationPx){let t,e=o.toDate.add(1,o.period).startOf(o.period),i=o.totalViewDurationPx;for(let s=0;s<1e3;s++){const s=this.generatePeriodDates({leftDate:e,rightDate:e.add(l,o.period).subtract(1,"ms"),period:o.period,time:o,level:this.state.get(`config.chart.calendarLevels.${o.level}`),levelIndex:o.level,callOnDate:!0,callOnLevelDates:!0,expandIfMissing:!1});if(s.length&&(t=s[0],i+=t.width,i>a))return t.rightGlobal+1-(i-a)*o.timePerPixel;e=e.add(l,o.period).startOf(o.period)}}for(let t=0,e=i.length;t<e;t++){const e=i[t];if(e.rightPx>a){const t=(e.rightPx-a)*o.timePerPixel;return e.rightGlobal+1-t}}const r=i[i.length-1];return r.rightGlobal+1-(r.rightPx-a)*o.timePerPixel}getCurrentFormatForLevel(t,e){return t.find((t=>+e.zoom<=+t.zoomTo))}alignLevelToMain(t,e,o=this.state.get("$data.chart.time")){if(t===o.level)return e;if(!this.state.get("config.chart.time.alignLevelsToMain"))return e;const i=o.allDates[o.level];if(!i||!i.length)return e;if(!e||!e.length)return e;const a=e.length;for(let t=0;t<a;t++){const a=e[t];let s,n=!1,l=0;for(const t of i){if(t.rightGlobal>=a.leftGlobal){if(!n)if(t.leftGlobal>=a.leftGlobal)a.leftGlobal=t.leftGlobal,a.leftGlobalDate=this.date(a.leftGlobal),a.leftPx=t.leftPx;else{const e=(t.rightGlobal-a.leftGlobal)/o.timePerPixel;l=-(t.width-e)}n=!0}if(t.leftGlobal>a.rightGlobal)break;n&&(l+=t.width,s=t)}if(s)if(s.rightGlobal<=a.rightGlobal)a.rightGlobal=s.rightGlobal,a.rightGlobalDate=this.date(a.rightGlobal),a.width=l,a.rightPx=a.leftPx+a.width;else{const t=(s.rightGlobal-a.rightGlobal)/o.timePerPixel;a.width=l-t,a.rightPx=a.leftPx+a.width}}return e}stopCheckingCurrentDates(){this.checkCurrentDateTimeoutId&&clearTimeout(this.checkCurrentDateTimeoutId)}checkCurrentDates(t=!1,e=this.state.get("$data.chart.time")){const o=this.date().valueOf(),i=e.checkCurrentDateInterval;if(this.stopCheckingCurrentDates(),t&&(this.checkCurrentDateTimeoutId=setTimeout((()=>{this.checkCurrentDates(t,e)}),i)),o-this.currentDateLastCheck<i)return;const a=e.allDates;let s=!1;for(const t of a){const e=t.length;for(let i=0;i<e;i++){const a=t[i],n=a.current;a.current=!1,a.previous=!1,a.next=!1,a.leftGlobal<=o&&a.rightGlobal>=o&&(!0!==n&&(s=!0),a.current=!0,i>0&&(t[i-1].previous=!0),i+1<e&&(t[i+1].next=!0))}}this.currentDateLastCheck=o,s&&this.state.update("$data.chart.time.levels",(t=>t),{data:"current-time"}),this.api.render()}getDSTDiffForLevel(t,e,o,i=this.state.get("$data.chart.time")){const a=this.api.time.getLevelDatesFromCache(t,e,o,i);let s=0;for(const t of a)t.DST.diffMs&&e<=t.DST.afterTime&&o>t.DST.afterTime&&(s+=t.DST.diffMs);return s}setDatesDST(t){for(const e of t){const t=e.rightGlobal-e.leftGlobal,o=e.rightGlobalDate.utc(!0).valueOf()-e.leftGlobalDate.utc(!0).valueOf();if(t!==o){e.DST={diffMs:t-o,afterTime:0,afterDate:null};for(let t=0;t<9216;t++)if(e.leftGlobalDate.add(t,"hour").hour()!==e.leftGlobalDate.utc(!0).add(t,"hour").hour()){e.DST.afterDate=e.leftGlobalDate.add(t,"hour").subtract(1,"ms"),e.DST.afterTime=e.DST.afterDate.valueOf();break}}}return t}_generatePeriodDates(t){const e=[];t=Object.assign({},t);const{datesCount:o,rightDate:i,period:a,level:s,levelIndex:n,time:l,originalLeftDate:r,format:c}=t;let d=t.leftDate;const h=this.date().valueOf();for(let t=0;t<o;t++){let t=c.periodIncrement||1;"function"==typeof t&&(t=t({currentDates:e,date:d,leftDate:r,rightDate:i,period:a,level:s,levelIndex:n,time:l,vido:this.api.vido,api:this.api}));const o=d.add(t-1,a).endOf(a),u=d.valueOf()<=h&&o.valueOf()>=h,m={id:`gstcid-${d.valueOf()}`,leftGlobal:d.valueOf(),leftGlobalDate:d,rightGlobalDate:o,rightGlobal:o.valueOf(),width:0,leftPx:0,rightPx:0,period:a,formatted:null,current:u,previous:!1,next:!1,periodIncrementedBy:t,DST:{diffMs:0,afterTime:0,afterDate:null}};u&&e.length&&(e[e.length-1].previous=!0),e.length&&e[e.length-1].current&&(m.next=!0);const g=m.rightGlobal+1-m.leftGlobal;m.width=g/l.timePerPixel,e.push(m),d=d.add(t||1,a)}return this.setDatesDST(e)}generatePeriodDates({leftDate:t,rightDate:e,period:o,level:i,levelIndex:a,time:s,callOnDate:n,callOnLevelDates:l,expandIfMissing:r=!0}){if(!s.timePerPixel)return[];const c=this.getCurrentFormatForLevel(i,s);t=t.startOf(o),e=e.endOf(o);const d=Math.ceil(e.diff(t,o,!0)),h=t.clone();let u=this._generatePeriodDates({datesCount:d,leftDate:t,rightDate:e,period:o,level:i,levelIndex:a,time:s,originalLeftDate:h,format:c});if(n){const t=[];for(let e=0;e<u.length;e++){let o=u[e];if(o){for(let t=0,e=s.onDate.length;t<e;t++)o=s.onDate[t]({date:o,format:c,time:s,level:i,levelIndex:a});o&&t.push(o)}}u=t}if(l)for(let t=0,e=s.onLevelDates.length;t<e;t++)u=s.onLevelDates[t]({dates:u,format:c,time:s,level:i,levelIndex:a});if((!u.length||u[u.length-1].rightGlobal<e.valueOf())&&r){let r=this._generatePeriodDates({datesCount:d+100,leftDate:t,rightDate:e,period:o,level:i,levelIndex:a,time:s,originalLeftDate:h,format:c});if(n){const t=[];for(let e=0;e<r.length;e++){let o=r[e];if(o){for(let t=0,e=s.onDate.length;t<e;t++)o=s.onDate[t]({date:o,format:c,time:s,level:i,levelIndex:a});o&&t.push(o)}}r=t}if(l)for(let t=0,e=s.onLevelDates.length;t<e;t++)r=s.onLevelDates[t]({dates:r,format:c,time:s,level:i,levelIndex:a});const u=[];for(const t of r)if(u.push(t),t.rightGlobal>=e.valueOf())return u}this.addDatesToCacheLevel(a,u,s);const m=[];for(const t of u)if(m.push(t),t.rightGlobal>=e.valueOf())return m;return m}getDatesDiffPx(t,e,o,i=!0,a=void 0){let s=e.valueOf(),n=t.valueOf();if(n===s)return 0;let l,r,c=0,d=!1;if(s<n){const o=t;t=e,n=s,s=(e=o).valueOf(),d=!0}if(void 0===a){if(!o.allDates||!o.allDates.length||!o.allDates[o.level])return 0;a=o.allDates[o.level]}if(0===a.length)return 0;if(this.isLevelDateInCache(o.level,n,o)?a=this.getAllLevelDatesFromCache(o.level,o):n<a[0].leftGlobal&&(a=this.addMissingDates(a,t,o)),this.isLevelDateInCache(o.level,s,o))a=this.getAllLevelDatesFromCache(o.level,o);else{s>a[a.length-1].rightGlobalDate.clone().valueOf()&&(a=this.addMissingDates(a,e,o))}this.addDatesToCacheLevel(o.level,a,o);let h=!1,u=0;for(const t of a)if(t.rightGlobal+1>=n&&!h&&(h=!0,r=t),h&&(c+=t.width),t.rightGlobal+1>=s){l=t,u=t.width;break}if(i){let t=n-r.leftGlobal;n<r.leftGlobal&&(t=0);let e=l.rightGlobal+1-s;l.leftGlobal>s&&(e=l.rightGlobal+1-l.leftGlobal);const i=(e+t)/o.timePerPixel;return d?-(c-i):c-i}return c-=u,d?-c:c}getDatesDiffMs(t,e,o,i=!0,a=void 0){if(t.valueOf()===e.valueOf())return 0;let s,n,l=0,r=!1;if(e.valueOf()<t.valueOf()){const o=t;t=e,e=o,r=!0}if(void 0===a){if(!o.allDates||!o.allDates.length||!o.allDates[o.level])return 0;a=o.allDates[o.level]}if(0===a.length)return 0;if(this.isLevelDateInCache(o.level,t.valueOf(),o)?a=this.getAllLevelDatesFromCache(o.level,o):t.valueOf()<a[0].leftGlobal&&(a=this.addMissingDates(a,t,o)),this.isLevelDateInCache(o.level,e.valueOf(),o))a=this.getAllLevelDatesFromCache(o.level,o);else{const t=a[a.length-1].rightGlobalDate.clone();e.valueOf()>t.valueOf()&&(a=this.addMissingDates(a,e,o))}this.addDatesToCacheLevel(o.level,a,o);let c=!1,d=0;for(const o of a)if(o.rightGlobal+1>=t.valueOf()&&!c&&(c=!0,n=o),c&&(l+=o.rightGlobal+1-o.leftGlobal),o.rightGlobal+1>=e.valueOf()){s=o,d=o.rightGlobal+1-o.leftGlobal;break}if(i){let o=t.valueOf()-n.leftGlobal;t.valueOf()<n.leftGlobal&&(o=0);let i=s.rightGlobal+1-e.valueOf();s.leftGlobal>e.valueOf()&&(i=s.rightGlobal+1-s.leftGlobal);const a=i+o;return r?-(l-a):l-a}return l-=d,r?-l:l}addTimeFromDates(t,e,o=this.state.get("$data.chart.time")){if(!o.allDates||!o.allDates.length||!o.allDates[o.level])return t+e;if(!e)return t;let i=this.getAllLevelDatesFromCache(o.level,o);const a=this.date(t);i=this.addMissingDates(i,a,o,!0);let s=this.findDateIndex(t,i),n=t-i[s].leftGlobal;n<0&&(n=0);let l=0;if(e>0){for(;l<e;){const t=i[s];if(l+=t.rightGlobal+1-t.leftGlobal,n&&(l-=n,n=0),l>=e)break;s++,i[s]||(i=this.addMissingDates(i,t.leftGlobalDate.add(1,o.period),o,!0))}return i[s].rightGlobal+1-(l-e)}for(;l>e;){let t=i[s];if(l-=n,n&&(n=0),l<=e)break;if(s--,s<0&&(i=this.addMissingDates(i,t.leftGlobalDate.subtract(1,o.period),o,!0),s=0),t=i[s],l-=t.rightGlobal+1-t.leftGlobal,l<=e)break}return i[s].leftGlobal+(-l+e)}getLeftViewDate(t=this.state.get("$data.chart.time")){if(!t.levels||!t.levels.length)return null;const e=t.levels[t.level];return e.length?e[0]:null}getRightViewDate(t=this.state.get("$data.chart.time")){if(!t.levels||!t.levels.length||!t.levels[t.level])return null;const e=t.levels[t.level];return e.length?e[e.length-1]:null}getLowerPeriod(t){switch(t){case"year":return"month";case"month":case"week":return"day";case"day":return"hour";case"hour":return"minute";case"minute":return"second";case"second":return"millisecond";default:return t}}getHigherPeriod(t){switch(t){case"month":return"year";case"week":case"day":return"month";case"hour":return"day";case"minute":return"hour";case"second":return"minute";case"millisecond":return"second";default:return t}}} /** * Gantt-Schedule-Timeline-Calendar IDApi * * @copyright NEURONET - Rafal Pospiech * @author Rafal Pospiech <neuronet.io@gmail.com> * @module gantt-schedule-timeline-calendar * @link https://github.com/neuronetio/gantt-schedule-timeline-calendar * @link https://gantt-schedule-timeline-calendar.neuronet.io * @version 3.40.7 * @released 2025-05-27 * @license SEE LICENSE IN LICENSE FILE */var D=new class{constructor(){this.GSTCID=this.GSTCID.bind(this),this.isGSTCID=this.isGSTCID.bind(this),this.sourceID=this.sourceID.bind(this)}GSTCID(t){return this.isGSTCID(t)?t:`gstcid-${t}`}isGSTCID(t){return String(t).startsWith("gstcid-")}sourceID(t){return this.isGSTCID(t)?t.substring(7):t}}; /** * Gantt-Schedule-Timeline-Calendar Slots * * @copyright NEURONET - Rafal Pospiech * @author Rafal Pospiech <neuronet.io@gmail.com> * @module gantt-schedule-timeline-calendar * @link https://github.com/neuronetio/gantt-schedule-timeline-calendar * @link https://gantt-schedule-timeline-calendar.neuronet.io * @version 3.40.7 * @released 2025-05-27 * @license SEE LICENSE IN LICENSE FILE */class y extends i{constructor(t,e,o){super(e,o),this.subs=[],this.name=t,this.subs.push(e.state.subscribe(`config.slots.${t}`,this.setComponents,{queue:!0}))}destroy(){this.subs.forEach((t=>t())),super.destroy()}getName(){return this.name}}function x(t,e,o){return new y(t,e,o)} /** * Gantt-Schedule-Timeline-Calendar helpers * * @copyright NEURONET - Rafal Pospiech * @author Rafal Pospiech <neuronet.io@gmail.com> * @module gantt-schedule-timeline-calendar * @link https://github.com/neuronetio/gantt-schedule-timeline-calendar * @link https://gantt-schedule-timeline-calendar.neuronet.io * @version 3.40.7 * @released 2025-05-27 * @license SEE LICENSE IN LICENSE FILE */const P="gstc";function W(t,e=""){let o=`${P}__${t}`;return t===P&&(o=P),e?`${o} ${o}--${e.replace(":","-")}`:o}function C(t,e){let o=`${P}__${t}`;return t===P&&(o=P),`${o}--${e}`} /** * Api functions * * @copyright NEURONET - Rafal Pospiech * @author Rafal Pospiech <neuronet.io@gmail.com> * @module gantt-schedule-timeline-calendar * @link https://github.com/neuronetio/gantt-schedule-timeline-calendar * @link https://gantt-schedule-timeline-calendar.neuronet.io * @version 3.40.7 * @released 2025-05-27 * @license SEE LICENSE IN LICENSE FILE */let $=0;const I=new Map;function S(t){return I.get(t.apiId)}class M{constructor(t){this.apiId=0,this.name=P,this.debug=!1,this.plugins={},this.iconsCache={},this.unsubscribes=[],this.mutedMethods=new Set,this.mergeDeep=null,this.generateSlots=x,this.getClass=W,this.getId=C,this.GSTCID=D.GSTCID,this.isGSTCID=D.isGSTCID,this.sourceID=D.sourceID,this.allActions=[],this.keysToKeep=["id","parents","children","allChildren","parentId"],this.apiId=++$,I.set(this.apiId,{rowsDataWithParentsExpanded:[],rowsIdsWithParentsExpanded:[],rowsWithParentsExpanded:[],rowsWithParentsExpandedAsMap:new Map,rowsPositionsMap:{id:"",dataIndex:0,keys:[]},allRowsIds:[],allRowsAsArray:[],rowsWithParentsExpandedDataIndexMap:new Map,itemsAsArray:[],itemsDataAsArray:[]}),this.state=t,this.time=new b(this.state,this),this.unsubscribes.push(this.state.subscribe("config.debug",(t=>this.debug=t))),this.unsubscribes.push(this.state.subscribe("config.chart.items;",(()=>this.resetRowsOverlappingCalculated()))),this.unsubscribes.push(this.state.subscribe("config.chart.items.:itemId.time",(t=>{var e;if(t.length){const o=this.getRowsData();if(!o)return;const i=this.state.get("config.chart.items");for(const a of t)if(null===(e=a.params)||void 0===e?void 0:e.itemId){const t=i[a.params.itemId];if(t){o[t.rowId].overlappingCalculated=!1}}}}),{bulk:!0,bulkValue:!1})),this.debug&&(window.state=t)}schedule(t){let e=0;return function(...o){e||(e=requestAnimationFrame((function(){e=0,t(...o)})))}}render(){return this.vido.update()}getListenerPosition(t){for(const e of this.state.getListeners().values())for(const o of e.listeners)if(o[1].fn===t)return o[0]}setVido(t){this.vido=t}clone(t){return this.mergeDeep({},t)}setMergeDeep(t){this.mergeDeep=t}log(...t){this.debug&&console.log.call(console,...t)}getInitializedPlugins(){return this.state.get("$data.initializedPlugins")}pluginInitialized(t){this.getInitializedPlugins().add(t)}pluginDestroyed(t){this.getInitializedPlugins().delete(t)}clearPluginsPositions(){this.getInitializedPlugins().clear()}isPluginInitialized(t){return this.getInitializedPlugins().has(t)}getPluginPosition(t){return[...this.getInitializedPlugins()].indexOf(t)}getPluginsPositions(){const t={};let e=0;for(const o of this.getInitializedPlugins())t[o]=e++;return t}isPluginInitializedBefore(t,e){return this.getPluginPosition(t)<this.getPluginPosition(e)}getActions(t){this.allActions.includes(t)||this.allActions.push(t);let e=this.state.get("config.actions."+t);return void 0===e&&(e=[]),e.slice()}isItemHorizontallyInViewport(t,e=void 0,o=void 0){if(!e||!o){const t=this.state.get().config.chart.time;e=t.leftGlobal,o=t.rightGlobal}return t.time.start<=o&&t.time.end>=e}getChildrenLinkedItemsIds(t,e,o=[]){const i=e[t];if(i.linkedWith&&i.linkedWith.length){o.includes(t)||o.push(t);for(const t of i.linkedWith){if(o.includes(t))continue;o.push(t);const i=e[t];i.linkedWith&&i.linkedWith.length&&this.getChildrenLinkedItemsIds(t,e,o)}}return o}collectAllLinkedItems(){const t=[],e=new Map,o=this.getAllItemsAsArray(),i=this.getItemsData();for(const e of o){const o=e.id;void 0===i[o]?t.push(o):i[e.id].linkedWith=e.linkedWith||[]}if(t.length)throw new Error(`Items with id [${t.join(", ")}] does not exists in "$data.chart.items". TIP: For performance reasons, state is mutable, so try not to modify items from the "state.get" method before you copy them (with "gstc.api.clone(items)" for example).`);for(const t of o){const o=t.id;if(e.has(o))continue;const a=this.getChildrenLinkedItemsIds(o,i);i[o].linkedWith.splice(i[o].linkedWith.length,0,...a);const s=Array.from(new Set(i[o].linkedWith));i[o].linkedWith=s.filter((t=>t!==o)),e.set(o,!0);for(const t of s)i[t].linkedWith=s.filter((e=>e!==t)),e.set(t,!0)}}getChildrenDependantItemsIds(t,e,o=[]){if(t.dependant&&t.dependant.length)for(const i of t.dependant){if(o.includes(i))continue;o.push(i);const a=e[i];if(!a)throw new Error(`Dependant item not found [id:'${i}'] found in item [id:'${t.id}']`);a.dependant&&a.dependant.length&&this.getChildrenDependantItemsIds(a,e,o)}return o}calculateItemVerticalPosition(t,e=null,o=null,i=null){if(i||(i=this.getItem(t)),e||(e=this.getItemData(t)),o||(o=this.getRowData(i.rowId)),i.gap&&e||(this.prepareItem(i),e=this.getItemData(t)),!o)return e.position;const a=o.position.top+i.gap.top,s=e.position.rowTop+i.gap.top,n=this.getRowViewTop(o.id);let l=n+e.position.actualRowTop;return n===1/0?l=1/0:-1===n&&(l=-1),e.position.top=a,e.position.actualRowTop=s,e.position.viewTop=l,e.position}setItemDataOutOfView(t,e=this.state.get("$data.chart.time")){t.outOfView||(t.outOfView={left:!1,right:!1,whole:!1});const o=t.time.startDate.valueOf(),i=t.time.endDate.valueOf();return t.outOfView.left=o<e.leftGlobal||o>=e.rightGlobal,t.outOfView.right=i>e.rightGlobal||i<=e.leftGlobal,t.outOfView.whole=i<=e.leftGlobal||o>=e.rightGlobal,t}calculateItemHorizontalPosition(t,e=null,o=null,i=this.state.get("$data.chart.time"),a=null){if(a||(a=this.getItem(t)),e||(e=this.getItemData(t)),o||(o=this.getRowData(a.rowId)),!o)return e.position;const s=e.time.startDate.valueOf()===a.time.start?e.time.startDate:this.time.date(a.time.start),n=e.time.endDate.valueOf()===a.time.end?e.time.endDate:this.time.date(a.time.end),l=this.time.getViewOffsetPxFromDates(s,!1,i),r=this.time.getViewOffsetPxFromDates(n.add(1,"ms"),!1,i);e.position.left=l,e.position.actualLeft=this.time.limitOffsetPxToView(l,i),e.position.right=r,e.position.actualRight=this.time.limitOffsetPxToView(r,i),e.width=r-l;let c=this.time.getViewOffsetPxFromDates(n,!1,i);c===r&&(c-=1/i.timePerPixel),e.timeWidth=c-l,e.actualWidth=e.position.actualRight-e.position.actualLeft;const d=this.state.get("config.chart.item.minWidth");return"number"==typeof d&&e.actualWidth<d&&(e.actualWidth=d),this.setItemDataOutOfView(e,i),e.position}calculateItemPosition(t,e=null,o=null,i=this.state.get("$data.chart.time"),a=null){return e||(e=this.state.get(`$data.chart.items.${t}`)),a||(a=this.state.get(`config.chart.items.${t}`)),o||(o=this.state.get(`$data.list.rows.${a.rowId}`)),this.calculateItemHorizontalPosition(t,e,o,i,a),this.calculateItemVerticalPosition(t,e,o,a),e.position}getItemPosition(t,e,o,i,a){var s,n;return void 0===e&&(e=null),void 0===o&&(o=null),void 0===i&&(i=null===(n=null===(s=this.state.get().$data)||void 0===s?void 0:s.chart)||void 0===n?void 0:n.time),void 0===a&&(a=null),a||(a=this.getItem(t)),e||(e=this.getItemData(t)),0===e.position.left&&0===e.position.right&&this.calculateItemPosition(t,e,o,i,a),e.position}getRow(t){return this.state.get().config.list.rows[t]}getRows(t){if(!t.length)return[];const e=this.getAllRows(),o=[];for(const i of t)e[i]&&o.push(e[i]);return o}getAllRows(){var t,e;return null===(e=null===(t=this.state.get().config)||void 0===t?void 0:t.list)||void 0===e?void 0:e.rows}getVisibleRowsId(){var t,e;return null===(e=null===(t=this.state.get().$data)||void 0===t?void 0:t.list)||void 0===e?void 0:e.visibleRows}getRowsData(){var t,e;return null===(e=null===(t=this.state.get().$data)||void 0===t?void 0:t.list)||void 0===e?void 0:e.rows}setRowsData(t){this.state.update("$data.list.rows",t)}getRowData(t){return this.state.get().$data.list.rows[t]}setRowData(t,e){this.state.update(`$data.list.rows.${t}`,e)}getItem(t){return this.state.get().config.chart.items[t]}getItems(t=[],e=this.getAllItems()){const o=[];for(const i of t)e[i]&&o.push(e[i]);return o}getAllItemsAsArray(){return S(this).itemsAsArray}getAllItemsDataAsArray(){return S(this).itemsDataAsArray}getAllItems(){return this.state.get().config.chart.items}getItemData(t){const e=this.state.get();if(e.$data&&e.$data.chart&&e.$data.chart.items)return e.$data.chart.items[t]}getItemsData(){const t=this.state.get();if(t.$data&&t.$data.chart)return t.$data.chart.items}setItemData(t,e){this.state.update(`$data.chart.items.${t}`,(t=>{for(const o in e)t[o]=e[o];return t}))}setItemsData(t){this.state.update("$data.chart.items",t)}prepareDependantItems(t,e){return this.getChildrenDependantItemsIds(t,e).filter((e=>e!==t.id))}prepareItem(t,e=this.state.get().config.chart.item.height,o=this.getItemsData(),i=this.getAllItems(),a=this.getAllRows()){let s=t.id;if(s=String(s),t.id=s,o[t.id]||(o[t.id]={id:t.id,actualHeight:0,outerHeight:0,time:null,position:{left:0,actualLeft:0,right:0,actualRight:0,rowTop:t.rowTop||0,actualRowTop:t.actualRowTop||0,top:0,viewTop:0},outOfView:{left:!1,right:!1,whole:!1},width:-1,actualWidth:-1,timeWidth:-1,detached:!1,linkedWith:[],dependant:this.getChildrenDependantItemsIds(t,i)}),t.time||console.error("There is something wrong with this item.",t),"number"!=typeof t.time.start||"number"!=typeof t.time.end)throw new Error('[gantt-schedule-timeline-calendar] Item "time.start" and "time.end" values should be a number (unix epoch milliseconds).');const n=t.rowId;if("string"!=typeof n)throw new Error('[gantt-schedule-timeline-calendar] Item "rowId" should be a string.');if(!n.startsWith("gstcid-"))throw new Error('[gantt-schedule-timeline-calendar] Item "rowId" should start with "gstcid-".');if(!a[n])throw new Error(`[gantt-schedule-timeline-calendar] Row for item "${t.id}" does not exists ("${n}"). TIP: Try updating the rows first to make sure the rows for the items exist.`);t.time.start=+t.time.start,t.time.end=+t.time.end,t.id=String(t.id);const l=this.state.get().config.chart.item;"number"!=typeof t.height&&(t.height=e),o[t.id].time=function(t,e,o){let i,a;return{get startDate(){return i||(i=o.time.date(t)),i},get endDate(){return a||(a=o.time.date(e)),a},set startDate(e){i=e,t=e.valueOf()},set endDate(t){a=t,e=t.valueOf()}}}(t.time.start,t.time.end,this),o[t.id].actualHeight=t.height,void 0===t.overlap&&(t.overlap=l.overlap),"number"!=typeof t.top&&(t.top=0),t.gap||(t.gap={}),"number"!=typeof t.gap.top&&(t.gap.top=l.gap.top),"number"!=typeof t.gap.bottom&&(t.gap.bottom=l.gap.bottom),"number"!=typeof t.minWidth&&(t.minWidth=l.minWidth),o[t.id].outerHeight=o[t.id].actualHeight+t.gap.top+t.gap.bottom,o[t.id].position.actualRowTop=o[t.id].position.rowTop+t.gap.top}prepareItems(t){const e=this.state.get("config.chart.item.height"),o=this.getItemsData(),i=S(this);i.itemsAsArray.length=0,i.itemsDataAsArray.length=0;for(const a in t){const s=t[a];this.prepareItem(s,e,o,t),i.itemsAsArray.push(t[a]),i.itemsDataAsArray.push(o[a])}return this.collectAllLinkedItems(),t}sortRowsByChildren(t,e={},o=this.state.get("config.list.rows"),i=this.state.get("$data.list.rows")){for(const a of t){const t=o[a],s=i[a],n=t.parentId&&e[t.parentId]||!t.parentId;!e[a]&&n&&(e[a]=t),s.children.length&&this.sortRowsByChildren(s.children,e,o,i)}return e}getSortableValue(t,e){return"string"==typeof t?e[t]:"function"==typeof t?t({row:e,vido:this.vido}):""}sortRowsByColumn(t,e=!0){const o=this.state.get("config.list.sort.compare");let i=this.getAllRows();const a=S(this);if(0===a.allRowsIds.length)return i;const s=a.allRowsAsArray;o?s.sort(o(t)):s.sort(((o,i)=>{const a=this.getSortableValue(t.sortable,o),s=this.getSortableValue(t.sortable,i);return"number"==typeof a?e?a-s:s-a:"string"==typeof a?e?a.localeCompare(s):s.localeCompare(a):void 0}));const n=s.map((t=>t.id)),l=this.getRowsData();for(const t of n){const e=l[t];e.children&&e.children.length&&e.children.sort(((t,e)=>n.indexOf(t)-n.indexOf(e)))}i=this.sortRowsByChildren(n),this.state.update("config.list.rows",i,{data:"sortRowsByColumn"});const r=this.getScrollTop();return this.state.get("config.scroll.vertical.byPixels")?this.setScrollTop(r.absolutePosPx):this.setScrollTop(r.dataIndex,r.preciseOffset),i}fillEmptyRowValues(t){const e=this.state.get("config.list.row.height"),o=this.getRowsData();let i=0;for(let a in t){const s=t[a];let n=o[a];if(a=String(a),s.id=a,"string"!=typeof a)throw new Error('[gantt-schedule-timeline-calendar] Row "id" must be a string.');if(!a.startsWith("gstcid-"))throw new Error(`[gantt-schedule-timeline-calendar] Row "id" should start with "gstcid-" (your row id: "${a}").`);if(a.startsWith("gstcid-gstcid-"))throw new Error(`[gantt-schedule-timeline-calendar] Your row "id" is wrapped more than once. It should look like this "gstcid-something" and it looks like this: "${a}".`);o[a]||(n={id:s.id,parentId:s.parentId,parents:[],children:[],allChildren:[],position:{top:0,bottom:0},items:[],itemsOrder:[],itemsTimeSectors:[],actualHeight:0,outerHeight:0,parentsExpanded:!0,inView:!0,overlappingCalculated:!1}),"number"!=typeof s.height&&(s.height=e),n.actualHeight=s.height,"boolean"!=typeof s.expanded&&(s.expanded=!1),n.position.top=i,"object"!=typeof s.gap&&(s.gap={}),"number"!=typeof s.gap.top&&(s.gap.top=0),"number"!=typeof s.gap.bottom&&(s.gap.bottom=0),void 0===s.visible&&(s.visible=!0),n.outerHeight=n.actualHeight+s.gap.top+s.gap.bottom,o[a]=n,i+=n.outerHeight}return t}itemsOnTheSameLevel(t,e){const o=t.position.rowTop+t.outerHeight,i=e.position.rowTop+e.outerHeight;return e.position.rowTop<=t.position.rowTop&&i>t.position.rowTop||(e.position.rowTop>=t.position.rowTop&&e.position.rowTop<o||e.position.rowTop>=t.position.rowTop&&i<o)}itemsTimeOverlaps(t,e){return e.time.start>=t.time.start&&e.time.start<=t.time.end||(e.time.end>=t.time.start&&e.time.end<=t.time.end||(e.time.start>=t.time.start&&e.time.end<=t.time.end||e.time.start<=t.time.start&&e.time.end>=t.time.end))}itemsOverlaps(t,e,o,i){const a=e.time.start&&t.time.start&&e.time.end&&t.time.end;return t.id!==e.id&&a&&this.itemsOnTheSameLevel(o,i)&&this.itemsTimeOverlaps(t,e)}itemOverlapsWithOthers(t,e,o=0){const i=this.getItemsData();for(let a=o,s=e.length;a<s;a++){const o=e[a];if(this.itemsOverlaps(t,o,i[t.id],i[o.id]))return o}return null}makeChildren(t,e={parents:[]}){if("object"!=typeof t)return[];t.children||(t.children=[]),t.allChildren||(t.allChildren=[]),t.parents||(t.parents=[...e.parents]),t.parentId&&"undefined"!==t.parentId&&t.parents.push(t.parentId);for(const e in t)if("id"!==e&&"parentId"!==e&&"children"!==e&&"allChildren"!==e&&"parents"!==e){"undefined"!==e&&(t.children.push(e),t.allChildren.push(e));const o=t[e];if("object"!=typeof o)continue;const i=this.makeChildren(o,t);t.allChildren.splice(t.allChildren.length,0,...i)}return t.allChildren}clearNested(t){for(const e in t)"object"!=typeof t[e]||Array.isArray(t[e])||this.clearNested(t[e]),this.keysToKeep.includes(e)||delete t[e],"parentId"===e&&"undefined"===t[e]&&(t[e]=void 0);return t}fastTree(t,e=null){var o,i;if(!e){e={undefined:{},id:"undefined"};for(const i in t){const a=t[i];e[a.id]||(e[a.id]={parentId:null!==(o=a.parentId)&&void 0!==o?o:"undefined",id:a.id})}}for(const t in e){const o=e[t];e[null!==(i=o.parentId)&&void 0!==i?i:"undefined"][o.id]=o}this.makeChildren(e[void 0]),delete e[void 0],delete e.id,delete e.parents,delete e.children,delete e.allChildren;for(const t in e)e[t]=this.clearNested(e[t]);return e}updateRowItemsAndItemRowMapForItem(t,e,o,i,a){var s,n,l;if(void 0===o&&(o=null===(s=this.state.get().$data)||void 0===s?void 0:s.itemRowMap),void 0===i&&(i=null===(l=null===(n=this.state.get().$data)||void 0===n?void 0:n.list)||void 0===l?void 0:l.rows),void 0===a&&(a=this.state.get().config.chart.items),!i[e])return;i[e].items||(i[e].items=[]);const r=o[t];r!==e&&(r&&i[r]&&(i[r].items=i[r].items.filter((e=>e!==t)).sort(((t,e)=>a[t].time.start-a[e].time.start))),o[t]=e,i[e].items.includes(t)||(i[e].items.push(t),this.timeSectorsItemsAddOrUpdate([a[t]],i[e].itemsTimeSectors)),r&&e!==r&&(i[r]&&(i[r].overlappingCalculated=!1),i[e]&&(i[e].overlappingCalculated=!1),this.timeSectorsDeleteItems([t],i[r].itemsTimeSectors)))}sortRowItemsInAddOrder(t,e){e.itemsOrder=e.items.slice(),e.itemsOrder.sort(((e,o)=>t[e]-t[o]))}sortRowItemsByTime(t){t.items=t.items.sort(((t,e)=>this.getItem(t).time.start-this.getItem(e).time.start))}makeTreeMap(t,e,o=!1){let i=this.state.get("$data.treeMap");if(!o||!i){i=this.fastTree(t);for(const e in t){const o=t[e],a=i[e];for(const t in a)o[t]=a[t]}}const a=this.state.get("$data.reloading")?{}:this.state.get("$data.itemRowMap"),s={};let n=0;const l=this.getAllItems();for(const t of e){const e=l[t];s[e.id]=n,this.updateRowItemsAndItemRowMapForItem(e.id,e.rowId,a),n++}for(const e in t){const o=t[e];this.sortRowItemsInAddOrder(s,o),o.itemsTimeSectors=this.timeSectorsGenerate(this.getItems(o.items))}return this.state.update("$data.itemRowMap",a),o||this.state.update("$data.treeMap",i),t}_updateRowsWithParentsExpandedCache(t){const e=S(this);e.rowsIdsWithParentsExpanded.length=0,e.rowsIdsWithParentsExpanded.splice(0,0,...t),e.rowsWithParentsExpanded.length=0,e.rowsDataWithParentsExpanded.length=0,e.rowsWithParentsExpandedDataIndexMap.clear();const o=this.state.get("config.list.rows"),i=this.state.get("$data.list.rows");e.rowsWithParentsExpandedAsMap.clear();let a=0;for(const t of e.rowsIdsWithParentsExpanded){const s=o[t];s&&(e.rowsWithParentsExpanded.push(s),e.rowsWithParentsExpandedAsMap.set(t,s),e.rowsDataWithParentsExpanded.push(i[t]),e.rowsWithParentsExpandedDataIndexMap.set(t,a),a++)}}generateRowsWithParentsExpanded(t){const e=[],o=this.getRowsData();t:for(const i in t){if(!o[i]||!o[i].parents)return[];if(this.isRowVisible(i)){for(const e of o[i].parents){const o=t[e];if(!o||!o.expanded)continue t}e.push(i)}}return this._updateRowsWithParentsExpandedCache(e),e}getRowInfoFromTop(t){const e=this.state.get("config.list.rows"),o=this.state.get("$data.list.rows"),i=this.getRowPositionMapNode(t);return{dataIndex:i.dataIndex,row:e[i.id],rowData:o[i.id]}}getRowViewTop(t,e=this.state.get("$data.list.rows"),o=this.state.get("$data.scroll.vertical")){return e[t].position.top-o.absolutePosPx-o.preciseOffset}parentsExpanded(t){return S(this).rowsWithParentsExpandedAsMap.has(t)}setAllRowsIdsCache(t){const e=S(this);e.allRowsIds=t;const o=this.state.get("config.list.rows");e.allRowsAsArray.length=0;for(const i of t)e.allRowsAsArray.push(o[i])}resetRowsOverlappingCalculated(t=this.getRowsData()){for(const e in t)t[e].overlappingCalculated=!1}timeSectorItemFits(t,e){return t.time.start>=e.from&&t.time.start<=e.to||t.time.end>=e.from&&t.time.end<=e.to||t.time.start<=e.from&&t.time.end>=e.to}timeSectorsGenerate(t,e=this.state.get().$data.chart.time,o=10){const i=[];if(e.from===e.to)return i;const a=this,s=Math.ceil((e.to-e.from)/o);for(let n=0;n<o;n++){const o={from:e.from+s*n,to:e.from+s*(n+1)-1,items:[],get fromDate(){return a.time.date(this.from)},get toDate(){return a.time.date(this.to)}};for(const e of t)this.timeSectorItemFits(e,o)&&o.items.push(e.id);i.push(o)}return i}timeSectorsItemsAddOrUpdate(t,e){for(const o of e)for(const e of t)if(this.timeSectorItemFits(e,o)){if(o.items.includes(e.id))continue;o.items.push(e.id)}else o.items=o.items.filter((t=>t!==e.id));return e}timeSectorsDeleteItems(t,e){for(const o of e)o.items=o.items.filter((e=>!t.includes(e)));return e}timeSectorsGenerateForRows(t=!1,e=this.getRowsData(),o=this.state.get().$data.chart.time,i=10){if(o.from===o.to)return e;const a=this.state.get().$data.list.rowsIds;for(const s of a){const a=e[s];!t&&a.itemsTimeSectors&&0!==a.itemsTimeSectors.length||(a.itemsTimeSectors=this.timeSectorsGenerate(this.getItems(a.itemsOrder),o,i))}return e}fixOverlappedItemsByTimeSectors(t){if(t.overlappingCalculated)return;if(this.isMutedMethod("fixOverlapped"))return;const e=this.getItemsData(),o=t.itemsTimeSectors=this.timeSectorsGenerate(this.getItems(t.itemsOrder)),i=this.getItems(t.items);for(const t of i){if(t.overlap)continue;const o=e[t.id];o&&(o.position.rowTop=t.top)}for(const t of o){const o=t.items,i=this.getItems(o);let a=0;for(const t of i){if(t.overlap)continue;const o=e[t.id];if(!o)continue;o.position.actualRowTop=o.position.rowTop+t.gap.top;let s=this.itemOverlapsWithOthers(t,i,a);if(s)for(;s;){const e=this.getItemData(s.id),n=i.findIndex((t=>t.id===s.id));n<a?(o.position.rowTop+=e.outerHeight,o.position.actualRowTop=o.position.rowTop+t.gap.top):(e.position.rowTop+=o.outerHeight,e.position.actualRowTop=e.position.rowTop+s.gap.top),s=this.itemOverlapsWithOthers(t,i)}a++}}o.length>0&&(t.overlappingCalculated=!0)}recalculateRowHeight(t,e){if(!e||!t||!t.gap)return 0;let o=0;const i=this.getItemsData();if(!i)return 0;if(!1===t.visible)return e.actualHeight=0,e.outerHeight=0,0;const a=this.getItems(e.itemsOrder);this.fixOverlappedItemsByTimeSectors(e);for(const t of a){const e=i[t.id];o=Math.max(o,e.position.rowTop+e.outerHeight)}return o<t.height&&(o=t.height),e.actualHeight=o,e.outerHeight=e.actualHeight+t.gap.top+t.gap.bottom,e.outerHeight}calculateVisibleRowsHeights(){var t;if(this.isMutedMethod("calculateVisibleRowsHeights"))return!1;const e=this.state.get("$data.list.visibleRows");let o=0;const i=this.getAllRows(),a=this.getRowsData();let s=!1;for(const n of e){const e=(null===(t=a[n])||void 0===t?void 0:t.outerHeight)||0,l=this.recalculateRowHeight(i[n],a[n]);e!==l&&(s=!0),o+=l}return this.state.update("$data.list.visibleRowsHeight",o),s&&this.measureRows(),s}getRealChartHeight(t=!0){const e=this.state.get("$data.scroll.vertical.preciseOffset")||0,o=t?this.state.get("config.innerHeight"):this.state.get("$data.chart.dimensions.heightWithoutScrollBar"),i=this.state.get("config.additionalSpace");return o-i.top-i.bottom+-1*e}getLastRowId(t=S(this).rowsIdsWithParentsExpanded,e=this.state.get("$data.scroll.vertical")){return t[this.getLastRowIndex(t,e)]}getLastRowIndex(t=S(this).rowsIdsWithParentsExpanded,e=this.state.get("$data.scroll.vertical")){return t.length-e.lastPageCount}generateRowsPositionsMap(t,e=0,o={id:"",dataIndex:0,keys:[]}){if(0===t.length)return o;if(1===t.length)return o[t[0].position.top]={id:t[0].id,dataIndex:e,keys:[]},o.keys=[t[0].position.top],o;const i=Math.floor(t.length/2),a=e,s=e+i,n=t.slice(1,i),l=t.slice(i+1);o.keys.push(t[0].position.top),o.keys.push(t[i].position.top);const r=o[t[0].position.top]={id:t[0].id,dataIndex:a,keys:[]},c=o[t[i].position.top]={id:t[i].id,dataIndex:s,keys:[]};return this.generateRowsPositionsMap(n,a+1,r),this.generateRowsPositionsMap(l,s+1,c),o}getRowPositionMapNode(t,e=S(this).rowsPositionsMap){return t>=e.keys[1]?this.getRowPositionMapNode(t,e[e.keys[1]]):t>=e.keys[0]?this.getRowPositionMapNode(t,e[e.keys[0]]):e}measureRows(t=!1){if(this.isMutedMethod("measureRows"))return;const e=this.state.get("$data.scroll.vertical"),o=this.state.get("config.list.rows"),i=this.getRealChartHeight(),a=this.getRowsData(),s=S(this);if(void 0===e.dataIndex)return[];const n=this.state.get("$data.list.rowsIds");let l=0;if(e.data&&(l=s.rowsWithParentsExpandedDataIndexMap.get(e.data.id),-1===l)){const t=this.getLastRowId(s.rowsIdsWithParentsExpanded,e);l=s.rowsWithParentsExpandedDataIndexMap.get(t)}let r=0,c=0,d=0;for(let h=n.length;d<h;d++){const h=n[d],u=s.rowsWithParentsExpandedAsMap.has(h),m=this.getRowViewTop(h,a,e),g=d>=l&&m<=i,f=a[h];if(!f)return[];t&&(f.overlappingCalculated=!1),this.recalculateRowHeight(o[h],f),f.inView=g,f.parentsExpanded=u,f.position.top=r,c=r+f.outerHeight,f.position.bottom=c,u&&(r+=f.outerHeight)}return s.rowsPositionsMap=this.generateRowsPositionsMap(s.rowsDataWithParentsExpanded),this.state.update("$data.list.rows",a,{data:"measureRows"}),this.state.update("$data.list.rowsHeight",c),this.state.update("$data.scroll.vertical.absoluteSize",c),this.calculateVerticalScrollSize(),c}isRowVisible(t,e=this.getAllRows(),o=this.getRowsData()){if(!e[t])return!1;if(!1===e[t].visible)return!1;if(!o[t])return!1;const i=o[t].parents;for(const t of i)if(!e[t]||!1===e[t].visible)return!1;return!0}getVisibleRows(){const t=this.state.get("$data.scroll.vertical"),e=S(this),o=e.rowsIdsWithParentsExpanded,i=this.getRowsData();if(!t.data)return[];const a=this.getRealChartHeight();if(!a)return[];let s=e.rowsWithParentsExpandedDataIndexMap.get(t.data.id);-1!==s&&void 0!==s||(s=t.dataIndex>e.rowsDataWithParentsExpanded.length-1?o.length-t.lastPageCount:t.dataIndex);const n=[];let l,r;for(let e=s,c=o.length;e<c;e++){const s=o[e];if(i[s]&&(r=i[s],l=this.getRowViewTop(s,i,t),l>=0&&l<=a?(n.push(s),r.parentsExpanded=!0):r.parentsExpanded=!1,l>a))break}return n}normalizeMouseWheelEvent(t){let e=t.deltaX||0,o=t.deltaY||0,i=t.deltaZ||0;const a=t.deltaMode,s=this.state.get("config.list.rowHeight");let n=1;switch(a){case 1:s&&(n=s);break;case 2:n=window.height}return e*=n,o*=n,i*=n,{x:e,y:o,z:i,event:t}}resetHorizontalScroll(t=this.state.get("$data.scroll.horizontal")){t.data=null,t.dataId="",t.dataIndex=0,t.handlePosPx=0,t.absolutePosPx=0,t.preciseOffset=0;const e=this.state.get("$data.chart.time");if(!e.allDates||!e.allDates.length)return;const o=e.allDates[e.level];if(!o||!o.length)return;const i=o[0];return t.data=Object.assign({},i),t.dataId=i.id,t}resetVerticalScroll(t=this.state.get("$data.scroll.vertical")){return t.data=null,t.dataId="",t.dataIndex=0,t.handlePosPx=0,t.absolutePosPx=0,t.preciseOffset=0,t.data=null,t.dataId=null,t}limitHorizontalScrollToView(t=this.state.get("$data.chart.time")){const e=this.state.get("$data.scroll.horizontal");if(!t.allDates||!t.allDates.length)return;const o=t.allDates[t.level].length-e.lastPageCount;e.dataIndex>o&&this.setScrollLeft(o,0,t)}calculateHorizontalScrollPosPxFromDates(t,e=0,o=this.state.get("$data.scroll.horizontal"),i=this.state.get("$data.chart.time")){if(i.calculatedZoomMode)return 0;if(void 0===t&&(t=0),!i.allDates||!i.allDates.length)return;const a=i.allDates[i.level];if(!a||!a.length)return;let s,n=0,l=0;if("number"==typeof t||""===t){""===t&&(t=0),l=t,s=a[l],s||(l=0,s=a[l]);const e=i.allDates[i.level].length-o.lastPageCount;l>e&&e>=0&&(l=e,s=a[l])}else if("string"==typeof t)for(let e=0;e<a.length;e++){const o=a[e];if(o.id===t){s=o,l=e;break}}if(!s&&o.data)for(let t=0;t<a.length;t++){const e=a[t];if(e.leftGlobal>=o.data.leftGlobal){s=e,l=t;break}}if(s||(l>0?(l=a.length-1,s=a[l]):(s=a[0],l=0)),l>a.length-o.lastPageCount&&(l=a.length-o.lastPageCount,s=a[l]),o.data=Object.assign({},s),n=s.leftPx-e,o.dataIndex=l,o.dataId=s.id,n){const t=n/o.absoluteSizeWithoutLastPage*o.maxHandlePosPx;o.handlePosPx=Math.max(t,0)}else o.handlePosPx=0;return o.handlePosPx>o.maxHandlePosPx&&(o.handlePosPx=Math.max(o.maxHandlePosPx,0)),o.preciseOffset=e,o.maxHandlePosPx>0?o.percent=o.handlePosPx/o.maxHandlePosPx*100:o.percent=0,o.absolutePosPx=Math.max(n,0),o}setScrollLeftByPixels(t){const e=this.state.get("$data.chart.time"),o=e.allDates[e.level];return o&&o.length?(t<0&&(t=0),this.state.update("$data.scroll.horizontal",(i=>{t>i.absoluteSizeWithoutLastPage&&(t=i.absoluteSizeWithoutLastPage);let a=0;const s=Math.round(t);let n;for(n of o){if(Math.round(n.rightPx)>s)break;a++}return i.dataIndex=a,i.dataId=n.id,i.preciseOffset=n.leftPx-t,this.calculateHorizontalScrollSizeAndPosFromDates(e.totalViewDurationPx,e,i,!1),t=i.absolutePosPx,i}),{data:"set-scroll-left"}),t):0}setScrollLeft(t,e=0,o=this.state.get("$data.chart.time")){if(o.calculatedZoomMode)return 0;if(this.state.get("config.scroll.horizontal.byPixels")){if("number"!=typeof t)throw new Error("When 'config.scroll.horizontal.byPixels' is true, 'dataIndexOrDateId' must be a number.");return t<0&&(t=0),this.setScrollLeftByPixels(t)}let i=0;const a=o.allDates[o.level];return a&&a.length?(this.state.update("$data.scroll.horizontal",(s=>{let n,l;if("number"==typeof t||""===t)n=t,l=a[n];else if("string"==typeof t)for(let e=0;e<a.length;e++)if(a[e].id===t){l=a[e],n=e;break}return l||(n>0?(n=a.length-1,l=a[n]):(n=0,l=a[0])),s.dataIndex=n,s.dataId=l.id,s.preciseOffset=e,this.calculateHorizontalScrollSizeAndPosFromDates(o.totalViewDurationPx,o,s,!1),i=s.absolutePosPx,s}),{data:"set-scroll-left"}),i):0}scrollToTime(t,e=!0){const o=this.state.get("$data.chart.time");if(o.calculatedZoomMode)return 0;if(!o.allDates)return 0;const i=this.time.findDateAtTime(t,o.allDates[o.level]);if(!i)return console.warn(`[gstc.api.scrollToTime] Time out of bounds (${t} -> ${this.time.date(t).format("YYYY-MM-DD HH:mm:ss")}).`),0;let a,s=0,n=0;if(e){const e=this.getChartWidth(!0)/2;n=(t-i.leftGlobal)/o.timePerPixel,i.rightPx<e&&(n=0);const l=-(e-n);if(a=this.time.getMainDateFromRelativePosition(i,l),!a)return console.warn(`[gstc.api.scrollToTime] Time out of bounds (${t} -> ${this.time.date(t).format("YYYY-MM-DD HH:mm:ss")}).`),0;s=o.allDates[o.level].indexOf(a)}else s=o.allDates[o.level].indexOf(i),n=(t-i.leftGlobal)/o.timePerPixel,a=i;if(-1===s)return 0;return this.state.get("config.scroll.horizontal").byPixels?this.setScrollLeft(a.leftPx+(e?a.width/2:0)):this.setScrollLeft(s,-n)}getScrollLeft(){return this.state.get("$data.scroll.horizontal")}getScrollSize(t){const e=this.state.get("$data.scroll.vertical.visible")?this.state.get("$data.chart.dimensions.widthWithoutScrollBar"):this.state.get("$data.chart.dimensions.width"),o=this.state.get("$data.scroll.horizontal.visible")?this.state.get("$data.chart.dimensions.heightWithoutScrollBar"):this.state.get("$data.chart.dimensions.innerHeight"),i=this.state.get("config.additionalSpace");return"horizontal"===t?e:o-i.top-i.bottom}getLastPageDatesWidth(t,e){let o=0,i=0;if(0===e.length)return{lastPageSize:o,lastPageCount:i};const a=this.state.get("config.scroll.horizontal"),s=a.byPixels||a.precise;for(let a=e.length-1;a>=0;a--){const s=e[a];if(o+=s.width,o>=t){o-=s.width;break}i++}return 0===o&&(o=t),s&&(o=t),{lastPageSize:o,lastPageCount:i}}calculateInitialChartWidth(t=!1){const e=this.state.get("config.initialWidth"),o=this.state.get("config.list.column