@classic-homes/gantt-core 0.3.0 → 0.3.2
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/calendar/index.cjs +87 -41
- package/dist/calendar/index.js +1 -1
- package/dist/{chunk-7OPVG2DP.js → chunk-3GIZDFDV.js} +87 -41
- package/dist/{chunk-FVSW2GH6.js → chunk-742OJYSO.js} +1 -1
- package/dist/index.cjs +97 -46
- package/dist/index.js +13 -8
- package/dist/scheduling/index.cjs +87 -41
- package/dist/scheduling/index.js +2 -2
- package/dist/types/index.d.cts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/calendar/index.cjs
CHANGED
|
@@ -142,8 +142,9 @@ function compileCalendar(def) {
|
|
|
142
142
|
const nextWorking = (t) => {
|
|
143
143
|
let day = dayIndex(t);
|
|
144
144
|
for (let i = 0; i < MAX_SCAN_DAYS; i++, day++) {
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
const base = day * DAY;
|
|
146
|
+
for (const [s, e] of rawIntervals(day)) {
|
|
147
|
+
if (t < base + e) return Math.max(base + s, t);
|
|
147
148
|
}
|
|
148
149
|
}
|
|
149
150
|
throw new RangeError(
|
|
@@ -153,62 +154,107 @@ function compileCalendar(def) {
|
|
|
153
154
|
const prevWorking = (t) => {
|
|
154
155
|
let day = dayIndex(t - 1);
|
|
155
156
|
for (let i = 0; i < MAX_SCAN_DAYS; i++, day--) {
|
|
156
|
-
const
|
|
157
|
+
const base = day * DAY;
|
|
158
|
+
const list = rawIntervals(day);
|
|
157
159
|
for (let j = list.length - 1; j >= 0; j--) {
|
|
158
160
|
const [s, e] = list[j];
|
|
159
|
-
if (t > s) return Math.min(e, t);
|
|
161
|
+
if (t > base + s) return Math.min(base + e, t);
|
|
160
162
|
}
|
|
161
163
|
}
|
|
162
164
|
throw new RangeError(
|
|
163
165
|
`Calendar "${def.id}": no working time before ${new Date(t).toISOString()}`
|
|
164
166
|
);
|
|
165
167
|
};
|
|
168
|
+
let origin = 0;
|
|
169
|
+
let cum = [];
|
|
170
|
+
const dayWork = (day) => {
|
|
171
|
+
let ms = 0;
|
|
172
|
+
for (const [s, e] of rawIntervals(day)) ms += e - s;
|
|
173
|
+
return ms;
|
|
174
|
+
};
|
|
175
|
+
const ensure = (day) => {
|
|
176
|
+
if (cum.length === 0) {
|
|
177
|
+
origin = day - 366;
|
|
178
|
+
cum = [0];
|
|
179
|
+
}
|
|
180
|
+
if (day < origin) {
|
|
181
|
+
const from = Math.max(day - 366, origin - MAX_SCAN_DAYS);
|
|
182
|
+
if (day < from) throw new RangeError(`Calendar "${def.id}": date out of range`);
|
|
183
|
+
const head = [0];
|
|
184
|
+
for (let d = from; d < origin; d++) head.push(head[head.length - 1] + dayWork(d));
|
|
185
|
+
const shift = head[head.length - 1];
|
|
186
|
+
cum = head.concat(cum.slice(1).map((v) => v + shift));
|
|
187
|
+
origin = from;
|
|
188
|
+
}
|
|
189
|
+
const need = day - origin + 1;
|
|
190
|
+
if (need >= cum.length) {
|
|
191
|
+
if (need - cum.length > MAX_SCAN_DAYS)
|
|
192
|
+
throw new RangeError(`Calendar "${def.id}": date out of range`);
|
|
193
|
+
const target = need + 366;
|
|
194
|
+
for (let i = cum.length; i <= target; i++) cum.push(cum[i - 1] + dayWork(origin + i - 1));
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
const workAt = (t) => {
|
|
198
|
+
const day = dayIndex(t);
|
|
199
|
+
ensure(day);
|
|
200
|
+
const base = day * DAY;
|
|
201
|
+
let ms = cum[day - origin];
|
|
202
|
+
for (const [s, e] of rawIntervals(day)) {
|
|
203
|
+
if (t <= base + s) break;
|
|
204
|
+
ms += Math.min(t, base + e) - (base + s);
|
|
205
|
+
}
|
|
206
|
+
return ms;
|
|
207
|
+
};
|
|
166
208
|
const add = (t, minutes) => {
|
|
167
209
|
if (minutes === 0) return t;
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
210
|
+
const forward = minutes > 0;
|
|
211
|
+
let target = 0;
|
|
212
|
+
for (let i = 0; ; i++) {
|
|
213
|
+
if (i > MAX_SCAN_DAYS / 366)
|
|
214
|
+
throw new RangeError(`Calendar "${def.id}": working-time arithmetic ran out of range`);
|
|
215
|
+
target = workAt(t) + minutes * MINUTE;
|
|
216
|
+
if (forward ? cum[cum.length - 1] >= target : cum[0] <= target) break;
|
|
217
|
+
ensure(forward ? origin + cum.length + 366 : origin - 1);
|
|
218
|
+
}
|
|
219
|
+
if (forward) {
|
|
220
|
+
let lo = 0;
|
|
221
|
+
let hi = cum.length - 1;
|
|
222
|
+
while (lo < hi) {
|
|
223
|
+
const mid = lo + hi >> 1;
|
|
224
|
+
if (cum[mid + 1] >= target) hi = mid;
|
|
225
|
+
else lo = mid + 1;
|
|
226
|
+
}
|
|
227
|
+
const day = origin + lo;
|
|
228
|
+
const base = day * DAY;
|
|
229
|
+
let r = target - cum[lo];
|
|
230
|
+
for (const [s, e] of rawIntervals(day)) {
|
|
231
|
+
if (r <= e - s) return base + s + r;
|
|
232
|
+
r -= e - s;
|
|
181
233
|
}
|
|
182
234
|
} else {
|
|
183
|
-
let
|
|
184
|
-
let
|
|
185
|
-
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
235
|
+
let lo = 0;
|
|
236
|
+
let hi = cum.length - 2;
|
|
237
|
+
while (lo < hi) {
|
|
238
|
+
const mid = lo + hi + 1 >> 1;
|
|
239
|
+
if (cum[mid] <= target) lo = mid;
|
|
240
|
+
else hi = mid - 1;
|
|
241
|
+
}
|
|
242
|
+
const day = origin + lo;
|
|
243
|
+
const base = day * DAY;
|
|
244
|
+
let r = target - cum[lo];
|
|
245
|
+
const list = rawIntervals(day);
|
|
246
|
+
for (let j = 0; j < list.length; j++) {
|
|
247
|
+
const [s, e] = list[j];
|
|
248
|
+
if (r < e - s || j === list.length - 1) return base + s + r;
|
|
249
|
+
r -= e - s;
|
|
196
250
|
}
|
|
197
251
|
}
|
|
198
252
|
throw new RangeError(`Calendar "${def.id}": working-time arithmetic ran out of range`);
|
|
199
253
|
};
|
|
200
254
|
const between = (a, b) => {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
for (let day = dayIndex(a); day <= last; day++) {
|
|
205
|
-
for (const [s, e] of intervalsOn(day)) {
|
|
206
|
-
const from = Math.max(s, a);
|
|
207
|
-
const to = Math.min(e, b);
|
|
208
|
-
if (to > from) total += to - from;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
return total / MINUTE;
|
|
255
|
+
ensure(dayIndex(a));
|
|
256
|
+
ensure(dayIndex(b));
|
|
257
|
+
return (workAt(b) - workAt(a)) / MINUTE || 0;
|
|
212
258
|
};
|
|
213
259
|
const minutesPerDay = weekHours.reduce((sum, [s, e]) => sum + (e - s), 0) / MINUTE || 480;
|
|
214
260
|
return {
|
package/dist/calendar/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { CONTINUOUS_CALENDAR, STANDARD_CALENDAR, STANDARD_CALENDAR_ID, compileCalendar, compileCalendars, nonWorkingSpans } from '../chunk-
|
|
1
|
+
export { CONTINUOUS_CALENDAR, STANDARD_CALENDAR, STANDARD_CALENDAR_ID, compileCalendar, compileCalendars, nonWorkingSpans } from '../chunk-3GIZDFDV.js';
|
|
2
2
|
export { DAY, HOUR, MINUTE, createTimeFormatter, dayIndex, formatTime, isDateOnly, parseTime, startOfDay, toLocalDate, tryParseTime, weekday } from '../chunk-LPH2V7XM.js';
|
|
@@ -63,8 +63,9 @@ function compileCalendar(def) {
|
|
|
63
63
|
const nextWorking = (t) => {
|
|
64
64
|
let day = dayIndex(t);
|
|
65
65
|
for (let i = 0; i < MAX_SCAN_DAYS; i++, day++) {
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
const base = day * DAY;
|
|
67
|
+
for (const [s, e] of rawIntervals(day)) {
|
|
68
|
+
if (t < base + e) return Math.max(base + s, t);
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
throw new RangeError(
|
|
@@ -74,62 +75,107 @@ function compileCalendar(def) {
|
|
|
74
75
|
const prevWorking = (t) => {
|
|
75
76
|
let day = dayIndex(t - 1);
|
|
76
77
|
for (let i = 0; i < MAX_SCAN_DAYS; i++, day--) {
|
|
77
|
-
const
|
|
78
|
+
const base = day * DAY;
|
|
79
|
+
const list = rawIntervals(day);
|
|
78
80
|
for (let j = list.length - 1; j >= 0; j--) {
|
|
79
81
|
const [s, e] = list[j];
|
|
80
|
-
if (t > s) return Math.min(e, t);
|
|
82
|
+
if (t > base + s) return Math.min(base + e, t);
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
throw new RangeError(
|
|
84
86
|
`Calendar "${def.id}": no working time before ${new Date(t).toISOString()}`
|
|
85
87
|
);
|
|
86
88
|
};
|
|
89
|
+
let origin = 0;
|
|
90
|
+
let cum = [];
|
|
91
|
+
const dayWork = (day) => {
|
|
92
|
+
let ms = 0;
|
|
93
|
+
for (const [s, e] of rawIntervals(day)) ms += e - s;
|
|
94
|
+
return ms;
|
|
95
|
+
};
|
|
96
|
+
const ensure = (day) => {
|
|
97
|
+
if (cum.length === 0) {
|
|
98
|
+
origin = day - 366;
|
|
99
|
+
cum = [0];
|
|
100
|
+
}
|
|
101
|
+
if (day < origin) {
|
|
102
|
+
const from = Math.max(day - 366, origin - MAX_SCAN_DAYS);
|
|
103
|
+
if (day < from) throw new RangeError(`Calendar "${def.id}": date out of range`);
|
|
104
|
+
const head = [0];
|
|
105
|
+
for (let d = from; d < origin; d++) head.push(head[head.length - 1] + dayWork(d));
|
|
106
|
+
const shift = head[head.length - 1];
|
|
107
|
+
cum = head.concat(cum.slice(1).map((v) => v + shift));
|
|
108
|
+
origin = from;
|
|
109
|
+
}
|
|
110
|
+
const need = day - origin + 1;
|
|
111
|
+
if (need >= cum.length) {
|
|
112
|
+
if (need - cum.length > MAX_SCAN_DAYS)
|
|
113
|
+
throw new RangeError(`Calendar "${def.id}": date out of range`);
|
|
114
|
+
const target = need + 366;
|
|
115
|
+
for (let i = cum.length; i <= target; i++) cum.push(cum[i - 1] + dayWork(origin + i - 1));
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const workAt = (t) => {
|
|
119
|
+
const day = dayIndex(t);
|
|
120
|
+
ensure(day);
|
|
121
|
+
const base = day * DAY;
|
|
122
|
+
let ms = cum[day - origin];
|
|
123
|
+
for (const [s, e] of rawIntervals(day)) {
|
|
124
|
+
if (t <= base + s) break;
|
|
125
|
+
ms += Math.min(t, base + e) - (base + s);
|
|
126
|
+
}
|
|
127
|
+
return ms;
|
|
128
|
+
};
|
|
87
129
|
const add = (t, minutes) => {
|
|
88
130
|
if (minutes === 0) return t;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
131
|
+
const forward = minutes > 0;
|
|
132
|
+
let target = 0;
|
|
133
|
+
for (let i = 0; ; i++) {
|
|
134
|
+
if (i > MAX_SCAN_DAYS / 366)
|
|
135
|
+
throw new RangeError(`Calendar "${def.id}": working-time arithmetic ran out of range`);
|
|
136
|
+
target = workAt(t) + minutes * MINUTE;
|
|
137
|
+
if (forward ? cum[cum.length - 1] >= target : cum[0] <= target) break;
|
|
138
|
+
ensure(forward ? origin + cum.length + 366 : origin - 1);
|
|
139
|
+
}
|
|
140
|
+
if (forward) {
|
|
141
|
+
let lo = 0;
|
|
142
|
+
let hi = cum.length - 1;
|
|
143
|
+
while (lo < hi) {
|
|
144
|
+
const mid = lo + hi >> 1;
|
|
145
|
+
if (cum[mid + 1] >= target) hi = mid;
|
|
146
|
+
else lo = mid + 1;
|
|
147
|
+
}
|
|
148
|
+
const day = origin + lo;
|
|
149
|
+
const base = day * DAY;
|
|
150
|
+
let r = target - cum[lo];
|
|
151
|
+
for (const [s, e] of rawIntervals(day)) {
|
|
152
|
+
if (r <= e - s) return base + s + r;
|
|
153
|
+
r -= e - s;
|
|
102
154
|
}
|
|
103
155
|
} else {
|
|
104
|
-
let
|
|
105
|
-
let
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
156
|
+
let lo = 0;
|
|
157
|
+
let hi = cum.length - 2;
|
|
158
|
+
while (lo < hi) {
|
|
159
|
+
const mid = lo + hi + 1 >> 1;
|
|
160
|
+
if (cum[mid] <= target) lo = mid;
|
|
161
|
+
else hi = mid - 1;
|
|
162
|
+
}
|
|
163
|
+
const day = origin + lo;
|
|
164
|
+
const base = day * DAY;
|
|
165
|
+
let r = target - cum[lo];
|
|
166
|
+
const list = rawIntervals(day);
|
|
167
|
+
for (let j = 0; j < list.length; j++) {
|
|
168
|
+
const [s, e] = list[j];
|
|
169
|
+
if (r < e - s || j === list.length - 1) return base + s + r;
|
|
170
|
+
r -= e - s;
|
|
117
171
|
}
|
|
118
172
|
}
|
|
119
173
|
throw new RangeError(`Calendar "${def.id}": working-time arithmetic ran out of range`);
|
|
120
174
|
};
|
|
121
175
|
const between = (a, b) => {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
for (let day = dayIndex(a); day <= last; day++) {
|
|
126
|
-
for (const [s, e] of intervalsOn(day)) {
|
|
127
|
-
const from = Math.max(s, a);
|
|
128
|
-
const to = Math.min(e, b);
|
|
129
|
-
if (to > from) total += to - from;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return total / MINUTE;
|
|
176
|
+
ensure(dayIndex(a));
|
|
177
|
+
ensure(dayIndex(b));
|
|
178
|
+
return (workAt(b) - workAt(a)) / MINUTE || 0;
|
|
133
179
|
};
|
|
134
180
|
const minutesPerDay = weekHours.reduce((sum, [s, e]) => sum + (e - s), 0) / MINUTE || 480;
|
|
135
181
|
return {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { compileCalendars, STANDARD_CALENDAR_ID } from './chunk-
|
|
1
|
+
import { compileCalendars, STANDARD_CALENDAR_ID } from './chunk-3GIZDFDV.js';
|
|
2
2
|
import { parseTime, startOfDay, dayIndex, isDateOnly, DAY } from './chunk-LPH2V7XM.js';
|
|
3
3
|
|
|
4
4
|
// src/scheduling/graph.ts
|
package/dist/index.cjs
CHANGED
|
@@ -142,8 +142,9 @@ function compileCalendar(def) {
|
|
|
142
142
|
const nextWorking = (t) => {
|
|
143
143
|
let day = dayIndex(t);
|
|
144
144
|
for (let i = 0; i < MAX_SCAN_DAYS; i++, day++) {
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
const base = day * DAY;
|
|
146
|
+
for (const [s, e] of rawIntervals(day)) {
|
|
147
|
+
if (t < base + e) return Math.max(base + s, t);
|
|
147
148
|
}
|
|
148
149
|
}
|
|
149
150
|
throw new RangeError(
|
|
@@ -153,62 +154,107 @@ function compileCalendar(def) {
|
|
|
153
154
|
const prevWorking = (t) => {
|
|
154
155
|
let day = dayIndex(t - 1);
|
|
155
156
|
for (let i = 0; i < MAX_SCAN_DAYS; i++, day--) {
|
|
156
|
-
const
|
|
157
|
+
const base = day * DAY;
|
|
158
|
+
const list = rawIntervals(day);
|
|
157
159
|
for (let j = list.length - 1; j >= 0; j--) {
|
|
158
160
|
const [s, e] = list[j];
|
|
159
|
-
if (t > s) return Math.min(e, t);
|
|
161
|
+
if (t > base + s) return Math.min(base + e, t);
|
|
160
162
|
}
|
|
161
163
|
}
|
|
162
164
|
throw new RangeError(
|
|
163
165
|
`Calendar "${def.id}": no working time before ${new Date(t).toISOString()}`
|
|
164
166
|
);
|
|
165
167
|
};
|
|
168
|
+
let origin = 0;
|
|
169
|
+
let cum = [];
|
|
170
|
+
const dayWork = (day) => {
|
|
171
|
+
let ms = 0;
|
|
172
|
+
for (const [s, e] of rawIntervals(day)) ms += e - s;
|
|
173
|
+
return ms;
|
|
174
|
+
};
|
|
175
|
+
const ensure = (day) => {
|
|
176
|
+
if (cum.length === 0) {
|
|
177
|
+
origin = day - 366;
|
|
178
|
+
cum = [0];
|
|
179
|
+
}
|
|
180
|
+
if (day < origin) {
|
|
181
|
+
const from = Math.max(day - 366, origin - MAX_SCAN_DAYS);
|
|
182
|
+
if (day < from) throw new RangeError(`Calendar "${def.id}": date out of range`);
|
|
183
|
+
const head = [0];
|
|
184
|
+
for (let d = from; d < origin; d++) head.push(head[head.length - 1] + dayWork(d));
|
|
185
|
+
const shift = head[head.length - 1];
|
|
186
|
+
cum = head.concat(cum.slice(1).map((v) => v + shift));
|
|
187
|
+
origin = from;
|
|
188
|
+
}
|
|
189
|
+
const need = day - origin + 1;
|
|
190
|
+
if (need >= cum.length) {
|
|
191
|
+
if (need - cum.length > MAX_SCAN_DAYS)
|
|
192
|
+
throw new RangeError(`Calendar "${def.id}": date out of range`);
|
|
193
|
+
const target = need + 366;
|
|
194
|
+
for (let i = cum.length; i <= target; i++) cum.push(cum[i - 1] + dayWork(origin + i - 1));
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
const workAt = (t) => {
|
|
198
|
+
const day = dayIndex(t);
|
|
199
|
+
ensure(day);
|
|
200
|
+
const base = day * DAY;
|
|
201
|
+
let ms = cum[day - origin];
|
|
202
|
+
for (const [s, e] of rawIntervals(day)) {
|
|
203
|
+
if (t <= base + s) break;
|
|
204
|
+
ms += Math.min(t, base + e) - (base + s);
|
|
205
|
+
}
|
|
206
|
+
return ms;
|
|
207
|
+
};
|
|
166
208
|
const add = (t, minutes) => {
|
|
167
209
|
if (minutes === 0) return t;
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
210
|
+
const forward = minutes > 0;
|
|
211
|
+
let target = 0;
|
|
212
|
+
for (let i = 0; ; i++) {
|
|
213
|
+
if (i > MAX_SCAN_DAYS / 366)
|
|
214
|
+
throw new RangeError(`Calendar "${def.id}": working-time arithmetic ran out of range`);
|
|
215
|
+
target = workAt(t) + minutes * MINUTE;
|
|
216
|
+
if (forward ? cum[cum.length - 1] >= target : cum[0] <= target) break;
|
|
217
|
+
ensure(forward ? origin + cum.length + 366 : origin - 1);
|
|
218
|
+
}
|
|
219
|
+
if (forward) {
|
|
220
|
+
let lo = 0;
|
|
221
|
+
let hi = cum.length - 1;
|
|
222
|
+
while (lo < hi) {
|
|
223
|
+
const mid = lo + hi >> 1;
|
|
224
|
+
if (cum[mid + 1] >= target) hi = mid;
|
|
225
|
+
else lo = mid + 1;
|
|
226
|
+
}
|
|
227
|
+
const day = origin + lo;
|
|
228
|
+
const base = day * DAY;
|
|
229
|
+
let r = target - cum[lo];
|
|
230
|
+
for (const [s, e] of rawIntervals(day)) {
|
|
231
|
+
if (r <= e - s) return base + s + r;
|
|
232
|
+
r -= e - s;
|
|
181
233
|
}
|
|
182
234
|
} else {
|
|
183
|
-
let
|
|
184
|
-
let
|
|
185
|
-
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
235
|
+
let lo = 0;
|
|
236
|
+
let hi = cum.length - 2;
|
|
237
|
+
while (lo < hi) {
|
|
238
|
+
const mid = lo + hi + 1 >> 1;
|
|
239
|
+
if (cum[mid] <= target) lo = mid;
|
|
240
|
+
else hi = mid - 1;
|
|
241
|
+
}
|
|
242
|
+
const day = origin + lo;
|
|
243
|
+
const base = day * DAY;
|
|
244
|
+
let r = target - cum[lo];
|
|
245
|
+
const list = rawIntervals(day);
|
|
246
|
+
for (let j = 0; j < list.length; j++) {
|
|
247
|
+
const [s, e] = list[j];
|
|
248
|
+
if (r < e - s || j === list.length - 1) return base + s + r;
|
|
249
|
+
r -= e - s;
|
|
196
250
|
}
|
|
197
251
|
}
|
|
198
252
|
throw new RangeError(`Calendar "${def.id}": working-time arithmetic ran out of range`);
|
|
199
253
|
};
|
|
200
254
|
const between = (a, b) => {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
for (let day = dayIndex(a); day <= last; day++) {
|
|
205
|
-
for (const [s, e] of intervalsOn(day)) {
|
|
206
|
-
const from = Math.max(s, a);
|
|
207
|
-
const to = Math.min(e, b);
|
|
208
|
-
if (to > from) total += to - from;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
return total / MINUTE;
|
|
255
|
+
ensure(dayIndex(a));
|
|
256
|
+
ensure(dayIndex(b));
|
|
257
|
+
return (workAt(b) - workAt(a)) / MINUTE || 0;
|
|
212
258
|
};
|
|
213
259
|
const minutesPerDay = weekHours.reduce((sum, [s, e]) => sum + (e - s), 0) / MINUTE || 480;
|
|
214
260
|
return {
|
|
@@ -985,7 +1031,9 @@ function applyOperation(data, op) {
|
|
|
985
1031
|
if (doomed.has(t.id)) inverse.push({ type: "add-task", task: t, index });
|
|
986
1032
|
});
|
|
987
1033
|
const removedDeps = dependencies.filter((d) => doomed.has(d.from) || doomed.has(d.to));
|
|
988
|
-
|
|
1034
|
+
dependencies.forEach((d, index) => {
|
|
1035
|
+
if (removedDeps.includes(d)) inverse.push({ type: "add-dependency", dependency: d, index });
|
|
1036
|
+
});
|
|
989
1037
|
return {
|
|
990
1038
|
data: {
|
|
991
1039
|
tasks: tasks.filter((t) => !doomed.has(t.id)),
|
|
@@ -1005,8 +1053,11 @@ function applyOperation(data, op) {
|
|
|
1005
1053
|
fail("These tasks are already linked");
|
|
1006
1054
|
if (wouldCreateCycle(tasks, dependencies, d.from, d.to))
|
|
1007
1055
|
fail("This link would create a circular dependency");
|
|
1056
|
+
const copy = dependencies.slice();
|
|
1057
|
+
const index = op.index === void 0 ? copy.length : Math.max(0, Math.min(op.index, copy.length));
|
|
1058
|
+
copy.splice(index, 0, d);
|
|
1008
1059
|
return {
|
|
1009
|
-
data: { tasks, dependencies:
|
|
1060
|
+
data: { tasks, dependencies: copy },
|
|
1010
1061
|
inverse: [{ type: "remove-dependency", id: d.id }]
|
|
1011
1062
|
};
|
|
1012
1063
|
}
|
|
@@ -1031,11 +1082,11 @@ function applyOperation(data, op) {
|
|
|
1031
1082
|
};
|
|
1032
1083
|
}
|
|
1033
1084
|
case "remove-dependency": {
|
|
1034
|
-
const
|
|
1035
|
-
if (
|
|
1085
|
+
const index = dependencies.findIndex((d) => d.id === op.id);
|
|
1086
|
+
if (index < 0) fail(`Unknown dependency "${op.id}"`);
|
|
1036
1087
|
return {
|
|
1037
1088
|
data: { tasks, dependencies: dependencies.filter((d) => d.id !== op.id) },
|
|
1038
|
-
inverse: [{ type: "add-dependency", dependency:
|
|
1089
|
+
inverse: [{ type: "add-dependency", dependency: dependencies[index], index }]
|
|
1039
1090
|
};
|
|
1040
1091
|
}
|
|
1041
1092
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import './chunk-FXPGR372.js';
|
|
2
|
-
import { buildTaskTree, descendantsOf, scheduleProject, wouldCreateCycle } from './chunk-
|
|
3
|
-
export { ancestorsOf, buildOrderingGraph, buildTaskTree, descendantsOf, edgeKey, findCycle, isAncestor, leavesOf, scheduleProject, taskDaySpan, topoSort, wouldCreateCycle } from './chunk-
|
|
4
|
-
export { CONTINUOUS_CALENDAR, STANDARD_CALENDAR, STANDARD_CALENDAR_ID, compileCalendar, compileCalendars, nonWorkingSpans } from './chunk-
|
|
2
|
+
import { buildTaskTree, descendantsOf, scheduleProject, wouldCreateCycle } from './chunk-742OJYSO.js';
|
|
3
|
+
export { ancestorsOf, buildOrderingGraph, buildTaskTree, descendantsOf, edgeKey, findCycle, isAncestor, leavesOf, scheduleProject, taskDaySpan, topoSort, wouldCreateCycle } from './chunk-742OJYSO.js';
|
|
4
|
+
export { CONTINUOUS_CALENDAR, STANDARD_CALENDAR, STANDARD_CALENDAR_ID, compileCalendar, compileCalendars, nonWorkingSpans } from './chunk-3GIZDFDV.js';
|
|
5
5
|
import { addUnits } from './chunk-MDRXY4HU.js';
|
|
6
6
|
export { ZOOM_LEVELS, ZOOM_PRESETS, addUnits, barGeometry, createTimeScale, floorUnit, hitTestBar, pathFromPoints, routeDependency, scaleTicks, snapToUnit, timelineRange, virtualWindow } from './chunk-MDRXY4HU.js';
|
|
7
7
|
import { DAY, HOUR, formatTime, startOfDay, parseTime, isDateOnly, createTimeFormatter } from './chunk-LPH2V7XM.js';
|
|
@@ -100,7 +100,9 @@ function applyOperation(data, op) {
|
|
|
100
100
|
if (doomed.has(t.id)) inverse.push({ type: "add-task", task: t, index });
|
|
101
101
|
});
|
|
102
102
|
const removedDeps = dependencies.filter((d) => doomed.has(d.from) || doomed.has(d.to));
|
|
103
|
-
|
|
103
|
+
dependencies.forEach((d, index) => {
|
|
104
|
+
if (removedDeps.includes(d)) inverse.push({ type: "add-dependency", dependency: d, index });
|
|
105
|
+
});
|
|
104
106
|
return {
|
|
105
107
|
data: {
|
|
106
108
|
tasks: tasks.filter((t) => !doomed.has(t.id)),
|
|
@@ -120,8 +122,11 @@ function applyOperation(data, op) {
|
|
|
120
122
|
fail("These tasks are already linked");
|
|
121
123
|
if (wouldCreateCycle(tasks, dependencies, d.from, d.to))
|
|
122
124
|
fail("This link would create a circular dependency");
|
|
125
|
+
const copy = dependencies.slice();
|
|
126
|
+
const index = op.index === void 0 ? copy.length : Math.max(0, Math.min(op.index, copy.length));
|
|
127
|
+
copy.splice(index, 0, d);
|
|
123
128
|
return {
|
|
124
|
-
data: { tasks, dependencies:
|
|
129
|
+
data: { tasks, dependencies: copy },
|
|
125
130
|
inverse: [{ type: "remove-dependency", id: d.id }]
|
|
126
131
|
};
|
|
127
132
|
}
|
|
@@ -146,11 +151,11 @@ function applyOperation(data, op) {
|
|
|
146
151
|
};
|
|
147
152
|
}
|
|
148
153
|
case "remove-dependency": {
|
|
149
|
-
const
|
|
150
|
-
if (
|
|
154
|
+
const index = dependencies.findIndex((d) => d.id === op.id);
|
|
155
|
+
if (index < 0) fail(`Unknown dependency "${op.id}"`);
|
|
151
156
|
return {
|
|
152
157
|
data: { tasks, dependencies: dependencies.filter((d) => d.id !== op.id) },
|
|
153
|
-
inverse: [{ type: "add-dependency", dependency:
|
|
158
|
+
inverse: [{ type: "add-dependency", dependency: dependencies[index], index }]
|
|
154
159
|
};
|
|
155
160
|
}
|
|
156
161
|
}
|
|
@@ -95,8 +95,9 @@ function compileCalendar(def) {
|
|
|
95
95
|
const nextWorking = (t) => {
|
|
96
96
|
let day = dayIndex(t);
|
|
97
97
|
for (let i = 0; i < MAX_SCAN_DAYS; i++, day++) {
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
const base = day * DAY;
|
|
99
|
+
for (const [s, e] of rawIntervals(day)) {
|
|
100
|
+
if (t < base + e) return Math.max(base + s, t);
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
throw new RangeError(
|
|
@@ -106,62 +107,107 @@ function compileCalendar(def) {
|
|
|
106
107
|
const prevWorking = (t) => {
|
|
107
108
|
let day = dayIndex(t - 1);
|
|
108
109
|
for (let i = 0; i < MAX_SCAN_DAYS; i++, day--) {
|
|
109
|
-
const
|
|
110
|
+
const base = day * DAY;
|
|
111
|
+
const list = rawIntervals(day);
|
|
110
112
|
for (let j = list.length - 1; j >= 0; j--) {
|
|
111
113
|
const [s, e] = list[j];
|
|
112
|
-
if (t > s) return Math.min(e, t);
|
|
114
|
+
if (t > base + s) return Math.min(base + e, t);
|
|
113
115
|
}
|
|
114
116
|
}
|
|
115
117
|
throw new RangeError(
|
|
116
118
|
`Calendar "${def.id}": no working time before ${new Date(t).toISOString()}`
|
|
117
119
|
);
|
|
118
120
|
};
|
|
121
|
+
let origin = 0;
|
|
122
|
+
let cum = [];
|
|
123
|
+
const dayWork = (day) => {
|
|
124
|
+
let ms = 0;
|
|
125
|
+
for (const [s, e] of rawIntervals(day)) ms += e - s;
|
|
126
|
+
return ms;
|
|
127
|
+
};
|
|
128
|
+
const ensure = (day) => {
|
|
129
|
+
if (cum.length === 0) {
|
|
130
|
+
origin = day - 366;
|
|
131
|
+
cum = [0];
|
|
132
|
+
}
|
|
133
|
+
if (day < origin) {
|
|
134
|
+
const from = Math.max(day - 366, origin - MAX_SCAN_DAYS);
|
|
135
|
+
if (day < from) throw new RangeError(`Calendar "${def.id}": date out of range`);
|
|
136
|
+
const head = [0];
|
|
137
|
+
for (let d = from; d < origin; d++) head.push(head[head.length - 1] + dayWork(d));
|
|
138
|
+
const shift = head[head.length - 1];
|
|
139
|
+
cum = head.concat(cum.slice(1).map((v) => v + shift));
|
|
140
|
+
origin = from;
|
|
141
|
+
}
|
|
142
|
+
const need = day - origin + 1;
|
|
143
|
+
if (need >= cum.length) {
|
|
144
|
+
if (need - cum.length > MAX_SCAN_DAYS)
|
|
145
|
+
throw new RangeError(`Calendar "${def.id}": date out of range`);
|
|
146
|
+
const target = need + 366;
|
|
147
|
+
for (let i = cum.length; i <= target; i++) cum.push(cum[i - 1] + dayWork(origin + i - 1));
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
const workAt = (t) => {
|
|
151
|
+
const day = dayIndex(t);
|
|
152
|
+
ensure(day);
|
|
153
|
+
const base = day * DAY;
|
|
154
|
+
let ms = cum[day - origin];
|
|
155
|
+
for (const [s, e] of rawIntervals(day)) {
|
|
156
|
+
if (t <= base + s) break;
|
|
157
|
+
ms += Math.min(t, base + e) - (base + s);
|
|
158
|
+
}
|
|
159
|
+
return ms;
|
|
160
|
+
};
|
|
119
161
|
const add = (t, minutes) => {
|
|
120
162
|
if (minutes === 0) return t;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
163
|
+
const forward = minutes > 0;
|
|
164
|
+
let target = 0;
|
|
165
|
+
for (let i = 0; ; i++) {
|
|
166
|
+
if (i > MAX_SCAN_DAYS / 366)
|
|
167
|
+
throw new RangeError(`Calendar "${def.id}": working-time arithmetic ran out of range`);
|
|
168
|
+
target = workAt(t) + minutes * MINUTE;
|
|
169
|
+
if (forward ? cum[cum.length - 1] >= target : cum[0] <= target) break;
|
|
170
|
+
ensure(forward ? origin + cum.length + 366 : origin - 1);
|
|
171
|
+
}
|
|
172
|
+
if (forward) {
|
|
173
|
+
let lo = 0;
|
|
174
|
+
let hi = cum.length - 1;
|
|
175
|
+
while (lo < hi) {
|
|
176
|
+
const mid = lo + hi >> 1;
|
|
177
|
+
if (cum[mid + 1] >= target) hi = mid;
|
|
178
|
+
else lo = mid + 1;
|
|
179
|
+
}
|
|
180
|
+
const day = origin + lo;
|
|
181
|
+
const base = day * DAY;
|
|
182
|
+
let r = target - cum[lo];
|
|
183
|
+
for (const [s, e] of rawIntervals(day)) {
|
|
184
|
+
if (r <= e - s) return base + s + r;
|
|
185
|
+
r -= e - s;
|
|
134
186
|
}
|
|
135
187
|
} else {
|
|
136
|
-
let
|
|
137
|
-
let
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
188
|
+
let lo = 0;
|
|
189
|
+
let hi = cum.length - 2;
|
|
190
|
+
while (lo < hi) {
|
|
191
|
+
const mid = lo + hi + 1 >> 1;
|
|
192
|
+
if (cum[mid] <= target) lo = mid;
|
|
193
|
+
else hi = mid - 1;
|
|
194
|
+
}
|
|
195
|
+
const day = origin + lo;
|
|
196
|
+
const base = day * DAY;
|
|
197
|
+
let r = target - cum[lo];
|
|
198
|
+
const list = rawIntervals(day);
|
|
199
|
+
for (let j = 0; j < list.length; j++) {
|
|
200
|
+
const [s, e] = list[j];
|
|
201
|
+
if (r < e - s || j === list.length - 1) return base + s + r;
|
|
202
|
+
r -= e - s;
|
|
149
203
|
}
|
|
150
204
|
}
|
|
151
205
|
throw new RangeError(`Calendar "${def.id}": working-time arithmetic ran out of range`);
|
|
152
206
|
};
|
|
153
207
|
const between = (a, b) => {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
for (let day = dayIndex(a); day <= last; day++) {
|
|
158
|
-
for (const [s, e] of intervalsOn(day)) {
|
|
159
|
-
const from = Math.max(s, a);
|
|
160
|
-
const to = Math.min(e, b);
|
|
161
|
-
if (to > from) total += to - from;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return total / MINUTE;
|
|
208
|
+
ensure(dayIndex(a));
|
|
209
|
+
ensure(dayIndex(b));
|
|
210
|
+
return (workAt(b) - workAt(a)) / MINUTE || 0;
|
|
165
211
|
};
|
|
166
212
|
const minutesPerDay = weekHours.reduce((sum, [s, e]) => sum + (e - s), 0) / MINUTE || 480;
|
|
167
213
|
return {
|
package/dist/scheduling/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { ancestorsOf, buildOrderingGraph, buildTaskTree, descendantsOf, edgeKey, findCycle, isAncestor, leavesOf, scheduleProject, taskDaySpan, topoSort, wouldCreateCycle } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
1
|
+
export { ancestorsOf, buildOrderingGraph, buildTaskTree, descendantsOf, edgeKey, findCycle, isAncestor, leavesOf, scheduleProject, taskDaySpan, topoSort, wouldCreateCycle } from '../chunk-742OJYSO.js';
|
|
2
|
+
import '../chunk-3GIZDFDV.js';
|
|
3
3
|
import '../chunk-LPH2V7XM.js';
|
package/dist/types/index.d.cts
CHANGED
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED