@classic-homes/gantt-core 0.3.2 → 0.3.3

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.
@@ -4,7 +4,7 @@
4
4
  var MINUTE = 6e4;
5
5
  var HOUR = 60 * MINUTE;
6
6
  var DAY = 24 * HOUR;
7
- var ISO_RE = /^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?/;
7
+ var ISO_RE = /^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(?:Z|[+-](?:[01]\d|2[0-3]):?[0-5]\d)?)?$/;
8
8
  function isDateOnly(input) {
9
9
  return typeof input === "string" && /^\d{4}-\d{2}-\d{2}$/.test(input.trim());
10
10
  }
@@ -15,21 +15,25 @@ function parseTime(input) {
15
15
  }
16
16
  if (input instanceof Date) {
17
17
  if (Number.isNaN(input.getTime())) throw new RangeError("Invalid Date");
18
- return Date.UTC(
19
- input.getFullYear(),
20
- input.getMonth(),
21
- input.getDate(),
18
+ const date2 = /* @__PURE__ */ new Date(0);
19
+ date2.setUTCFullYear(input.getFullYear(), input.getMonth(), input.getDate());
20
+ date2.setUTCHours(
22
21
  input.getHours(),
23
22
  input.getMinutes(),
24
- input.getSeconds()
23
+ input.getSeconds(),
24
+ input.getMilliseconds()
25
25
  );
26
+ return date2.getTime();
26
27
  }
27
28
  const m = ISO_RE.exec(input.trim());
28
29
  if (!m) throw new RangeError(`Invalid time: "${input}"`);
29
- const [, y, mo, d, h = "0", mi = "0", s = "0"] = m;
30
- const t = Date.UTC(+y, +mo - 1, +d, +h, +mi, +s);
31
- if (Number.isNaN(t)) throw new RangeError(`Invalid time: "${input}"`);
32
- return t;
30
+ const [, y, mo, d, h = "0", mi = "0", s = "0", fraction = "0"] = m;
31
+ const date = /* @__PURE__ */ new Date(0);
32
+ date.setUTCFullYear(+y, +mo - 1, +d);
33
+ date.setUTCHours(+h, +mi, +s, +fraction.padEnd(3, "0"));
34
+ if (date.getUTCFullYear() !== +y || date.getUTCMonth() !== +mo - 1 || date.getUTCDate() !== +d || date.getUTCHours() !== +h || date.getUTCMinutes() !== +mi || date.getUTCSeconds() !== +s)
35
+ throw new RangeError(`Invalid time: "${input}"`);
36
+ return date.getTime();
33
37
  }
34
38
  function tryParseTime(input) {
35
39
  if (input === void 0 || input === null || input === "") return void 0;
@@ -42,20 +46,16 @@ function tryParseTime(input) {
42
46
  var pad = (n) => String(n).padStart(2, "0");
43
47
  function formatTime(t, options = {}) {
44
48
  const d = new Date(t);
45
- const date = `${d.getUTCFullYear()}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())}`;
49
+ const date = `${String(d.getUTCFullYear()).padStart(4, "0")}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())}`;
46
50
  if (options.dateOnly) return date;
47
51
  return `${date}T${pad(d.getUTCHours())}:${pad(d.getUTCMinutes())}`;
48
52
  }
49
53
  function toLocalDate(t) {
50
54
  const d = new Date(t);
51
- return new Date(
52
- d.getUTCFullYear(),
53
- d.getUTCMonth(),
54
- d.getUTCDate(),
55
- d.getUTCHours(),
56
- d.getUTCMinutes(),
57
- d.getUTCSeconds()
58
- );
55
+ const local = /* @__PURE__ */ new Date(0);
56
+ local.setFullYear(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
57
+ local.setHours(d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds());
58
+ return local;
59
59
  }
60
60
  function startOfDay(t) {
61
61
  return Math.floor(t / DAY) * DAY;
@@ -1,2 +1,2 @@
1
- export { CONTINUOUS_CALENDAR, STANDARD_CALENDAR, STANDARD_CALENDAR_ID, compileCalendar, compileCalendars, nonWorkingSpans } from '../chunk-3GIZDFDV.js';
2
- export { DAY, HOUR, MINUTE, createTimeFormatter, dayIndex, formatTime, isDateOnly, parseTime, startOfDay, toLocalDate, tryParseTime, weekday } from '../chunk-LPH2V7XM.js';
1
+ export { CONTINUOUS_CALENDAR, STANDARD_CALENDAR, STANDARD_CALENDAR_ID, compileCalendar, compileCalendars, nonWorkingSpans } from '../chunk-LQGY5EOM.js';
2
+ export { DAY, HOUR, MINUTE, createTimeFormatter, dayIndex, formatTime, isDateOnly, parseTime, startOfDay, toLocalDate, tryParseTime, weekday } from '../chunk-FV63P7UY.js';
@@ -2,7 +2,7 @@
2
2
  var MINUTE = 6e4;
3
3
  var HOUR = 60 * MINUTE;
4
4
  var DAY = 24 * HOUR;
5
- var ISO_RE = /^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?/;
5
+ var ISO_RE = /^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(?:Z|[+-](?:[01]\d|2[0-3]):?[0-5]\d)?)?$/;
6
6
  function isDateOnly(input) {
7
7
  return typeof input === "string" && /^\d{4}-\d{2}-\d{2}$/.test(input.trim());
8
8
  }
@@ -13,21 +13,25 @@ function parseTime(input) {
13
13
  }
14
14
  if (input instanceof Date) {
15
15
  if (Number.isNaN(input.getTime())) throw new RangeError("Invalid Date");
16
- return Date.UTC(
17
- input.getFullYear(),
18
- input.getMonth(),
19
- input.getDate(),
16
+ const date2 = /* @__PURE__ */ new Date(0);
17
+ date2.setUTCFullYear(input.getFullYear(), input.getMonth(), input.getDate());
18
+ date2.setUTCHours(
20
19
  input.getHours(),
21
20
  input.getMinutes(),
22
- input.getSeconds()
21
+ input.getSeconds(),
22
+ input.getMilliseconds()
23
23
  );
24
+ return date2.getTime();
24
25
  }
25
26
  const m = ISO_RE.exec(input.trim());
26
27
  if (!m) throw new RangeError(`Invalid time: "${input}"`);
27
- const [, y, mo, d, h = "0", mi = "0", s = "0"] = m;
28
- const t = Date.UTC(+y, +mo - 1, +d, +h, +mi, +s);
29
- if (Number.isNaN(t)) throw new RangeError(`Invalid time: "${input}"`);
30
- return t;
28
+ const [, y, mo, d, h = "0", mi = "0", s = "0", fraction = "0"] = m;
29
+ const date = /* @__PURE__ */ new Date(0);
30
+ date.setUTCFullYear(+y, +mo - 1, +d);
31
+ date.setUTCHours(+h, +mi, +s, +fraction.padEnd(3, "0"));
32
+ if (date.getUTCFullYear() !== +y || date.getUTCMonth() !== +mo - 1 || date.getUTCDate() !== +d || date.getUTCHours() !== +h || date.getUTCMinutes() !== +mi || date.getUTCSeconds() !== +s)
33
+ throw new RangeError(`Invalid time: "${input}"`);
34
+ return date.getTime();
31
35
  }
32
36
  function tryParseTime(input) {
33
37
  if (input === void 0 || input === null || input === "") return void 0;
@@ -40,20 +44,16 @@ function tryParseTime(input) {
40
44
  var pad = (n) => String(n).padStart(2, "0");
41
45
  function formatTime(t, options = {}) {
42
46
  const d = new Date(t);
43
- const date = `${d.getUTCFullYear()}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())}`;
47
+ const date = `${String(d.getUTCFullYear()).padStart(4, "0")}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())}`;
44
48
  if (options.dateOnly) return date;
45
49
  return `${date}T${pad(d.getUTCHours())}:${pad(d.getUTCMinutes())}`;
46
50
  }
47
51
  function toLocalDate(t) {
48
52
  const d = new Date(t);
49
- return new Date(
50
- d.getUTCFullYear(),
51
- d.getUTCMonth(),
52
- d.getUTCDate(),
53
- d.getUTCHours(),
54
- d.getUTCMinutes(),
55
- d.getUTCSeconds()
56
- );
53
+ const local = /* @__PURE__ */ new Date(0);
54
+ local.setFullYear(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
55
+ local.setHours(d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds());
56
+ return local;
57
57
  }
58
58
  function startOfDay(t) {
59
59
  return Math.floor(t / DAY) * DAY;
@@ -1,5 +1,5 @@
1
- import { compileCalendars, STANDARD_CALENDAR_ID } from './chunk-3GIZDFDV.js';
2
- import { parseTime, startOfDay, dayIndex, isDateOnly, DAY } from './chunk-LPH2V7XM.js';
1
+ import { compileCalendars, STANDARD_CALENDAR_ID } from './chunk-LQGY5EOM.js';
2
+ import { parseTime, startOfDay, dayIndex, isDateOnly, DAY } from './chunk-FV63P7UY.js';
3
3
 
4
4
  // src/scheduling/graph.ts
5
5
  function buildTaskTree(tasks) {
@@ -16,18 +16,21 @@ function buildTaskTree(tasks) {
16
16
  if (p === t.id) invalidParents.push({ id: t.id, reason: "cycle" });
17
17
  }
18
18
  }
19
+ const done = /* @__PURE__ */ new Set();
19
20
  for (const t of tasks) {
20
- const seen = /* @__PURE__ */ new Set([t.id]);
21
- let cur = parent.get(t.id) ?? null;
22
- while (cur !== null) {
23
- if (seen.has(cur)) {
24
- parent.set(t.id, null);
25
- invalidParents.push({ id: t.id, reason: "cycle" });
21
+ if (done.has(t.id)) continue;
22
+ const path = /* @__PURE__ */ new Set();
23
+ let cur = t.id;
24
+ while (cur !== null && !done.has(cur)) {
25
+ if (path.has(cur)) {
26
+ parent.set(cur, null);
27
+ invalidParents.push({ id: cur, reason: "cycle" });
26
28
  break;
27
29
  }
28
- seen.add(cur);
30
+ path.add(cur);
29
31
  cur = parent.get(cur) ?? null;
30
32
  }
33
+ for (const id of path) done.add(id);
31
34
  }
32
35
  const children = /* @__PURE__ */ new Map();
33
36
  for (const t of tasks) {
@@ -88,26 +91,27 @@ function findCycle(nodes, successors) {
88
91
  const allowed = new Set(nodes);
89
92
  const state = /* @__PURE__ */ new Map();
90
93
  const path = [];
91
- const visit = (n) => {
92
- state.set(n, 1);
93
- path.push(n);
94
- for (const s of successors.get(n) ?? []) {
95
- if (!allowed.has(s)) continue;
96
- const st = state.get(s);
97
- if (st === 1) return path.slice(path.indexOf(s));
98
- if (st === void 0) {
99
- const found = visit(s);
100
- if (found) return found;
101
- }
102
- }
103
- path.pop();
104
- state.set(n, 2);
105
- return null;
106
- };
107
94
  for (const n of nodes) {
108
- if (!state.has(n)) {
109
- const found = visit(n);
110
- if (found) return found;
95
+ if (state.has(n)) continue;
96
+ const stack = [];
97
+ const enter = (id) => {
98
+ state.set(id, 1);
99
+ path.push(id);
100
+ stack.push({ id, next: (successors.get(id) ?? /* @__PURE__ */ new Set()).values() });
101
+ };
102
+ enter(n);
103
+ while (stack.length) {
104
+ const frame = stack[stack.length - 1];
105
+ const next = frame.next.next();
106
+ if (next.done) {
107
+ stack.pop();
108
+ path.pop();
109
+ state.set(frame.id, 2);
110
+ } else if (allowed.has(next.value)) {
111
+ const st = state.get(next.value);
112
+ if (st === 1) return path.slice(path.indexOf(next.value));
113
+ if (st === void 0) enter(next.value);
114
+ }
111
115
  }
112
116
  }
113
117
  return null;
@@ -167,6 +171,30 @@ function parseFinish(cal, end) {
167
171
  const t = parseTime(end);
168
172
  return cal.prevWorking(isDateOnly(end) ? t + DAY : t);
169
173
  }
174
+ function latestLagSource(cal, bound, lag) {
175
+ if (lag === 0) return bound;
176
+ const candidate = cal.add(bound, -lag);
177
+ let lo = candidate;
178
+ let hi = candidate;
179
+ let span = DAY;
180
+ if (cal.add(candidate, lag) <= bound) {
181
+ do {
182
+ hi = candidate + span;
183
+ span *= 2;
184
+ } while (cal.add(hi, lag) <= bound);
185
+ } else {
186
+ do {
187
+ lo = candidate - span;
188
+ span *= 2;
189
+ } while (cal.add(lo, lag) > bound);
190
+ }
191
+ while (hi - lo > 1) {
192
+ const mid = lo + Math.floor((hi - lo) / 2);
193
+ if (cal.add(mid, lag) <= bound) lo = mid;
194
+ else hi = mid;
195
+ }
196
+ return lo;
197
+ }
170
198
  function scheduleProject(tasks, dependencies = [], calendars = [], options = {}) {
171
199
  const conflicts = [];
172
200
  const cals = compileCalendars(calendars);
@@ -437,16 +465,16 @@ function scheduleProject(tasks, dependencies = [], calendars = [], options = {})
437
465
  const t = nodes.get(tid);
438
466
  switch (e.type) {
439
467
  case "FS":
440
- lf = min(lf, t.cal.add(t.ls, -e.lag));
468
+ lf = min(lf, latestLagSource(t.cal, t.ls, e.lag));
441
469
  break;
442
470
  case "SS":
443
- ls = min(ls, t.cal.add(t.ls, -e.lag));
471
+ ls = min(ls, latestLagSource(t.cal, t.ls, e.lag));
444
472
  break;
445
473
  case "FF":
446
- lf = min(lf, t.cal.add(t.lf, -e.lag));
474
+ lf = min(lf, latestLagSource(t.cal, t.lf, e.lag));
447
475
  break;
448
476
  case "SF":
449
- ls = min(ls, t.cal.add(t.lf, -e.lag));
477
+ ls = min(ls, latestLagSource(t.cal, t.lf, e.lag));
450
478
  break;
451
479
  }
452
480
  }
@@ -477,7 +505,10 @@ function scheduleProject(tasks, dependencies = [], calendars = [], options = {})
477
505
  if (n.deadline !== void 0) lf = min(lf, n.deadline);
478
506
  let finish = n.duration === 0 ? lf : n.cal.prevWorking(lf);
479
507
  if (ls !== INF)
480
- finish = min(finish, n.duration === 0 ? ls : n.cal.add(n.cal.prevWorking(ls), n.duration));
508
+ finish = min(
509
+ finish,
510
+ n.duration === 0 ? ls : n.cal.add(n.cal.isWorking(ls) ? ls : n.cal.prevWorking(ls) - 1, n.duration)
511
+ );
481
512
  n.lf = finish;
482
513
  n.ls = startFromFinish(n, finish);
483
514
  }
@@ -526,16 +557,16 @@ function scheduleProject(tasks, dependencies = [], calendars = [], options = {})
526
557
  let allowed;
527
558
  switch (e.type) {
528
559
  case "FS":
529
- allowed = n.cal.between(n.ef, n.cal.prevWorking(t.cal.add(t.es, -e.lag)));
560
+ allowed = n.cal.between(n.ef, n.cal.prevWorking(latestLagSource(t.cal, t.es, e.lag)));
530
561
  break;
531
562
  case "SS":
532
- allowed = n.cal.between(n.es, t.cal.add(t.es, -e.lag));
563
+ allowed = n.cal.between(n.es, latestLagSource(t.cal, t.es, e.lag));
533
564
  break;
534
565
  case "FF":
535
- allowed = n.cal.between(n.ef, t.cal.add(t.ef, -e.lag));
566
+ allowed = n.cal.between(n.ef, latestLagSource(t.cal, t.ef, e.lag));
536
567
  break;
537
568
  case "SF":
538
- allowed = n.cal.between(n.es, t.cal.add(t.ef, -e.lag));
569
+ allowed = n.cal.between(n.es, latestLagSource(t.cal, t.ef, e.lag));
539
570
  break;
540
571
  }
541
572
  freeSlack = min(freeSlack, allowed);
@@ -548,23 +579,34 @@ function scheduleProject(tasks, dependencies = [], calendars = [], options = {})
548
579
  if (isCritical) critical.push(id);
549
580
  result.set(id, toScheduled(n, totalSlack, freeSlack, isCritical));
550
581
  }
582
+ const aggregates = /* @__PURE__ */ new Map();
551
583
  for (const id of order) {
552
584
  const n = nodes.get(id);
553
- if (!n.isSummary) continue;
554
- const leafIds = leaves(id);
555
- let weighted = 0;
556
- let weight = 0;
557
- let slack = INF;
558
- let anyCritical = false;
559
- for (const l of leafIds) {
560
- const st = result.get(l);
561
- weighted += st.progress * st.duration;
562
- weight += st.duration;
563
- slack = min(slack, st.totalSlack);
564
- anyCritical || (anyCritical = st.critical);
585
+ if (!n.isSummary) {
586
+ const st = result.get(id);
587
+ aggregates.set(id, {
588
+ weighted: st.progress * st.duration,
589
+ weight: st.duration,
590
+ progress: st.progress,
591
+ count: 1,
592
+ slack: st.totalSlack,
593
+ critical: st.critical
594
+ });
595
+ continue;
596
+ }
597
+ const sum = { weighted: 0, weight: 0, progress: 0, count: 0, slack: INF, critical: false };
598
+ for (const child of tree.children.get(id) ?? []) {
599
+ const a = aggregates.get(child);
600
+ sum.weighted += a.weighted;
601
+ sum.weight += a.weight;
602
+ sum.progress += a.progress;
603
+ sum.count += a.count;
604
+ sum.slack = min(sum.slack, a.slack);
605
+ sum.critical || (sum.critical = a.critical);
565
606
  }
566
- n.progress = weight > 0 ? weighted / weight : leafIds.reduce((s, l) => s + result.get(l).progress, 0) / Math.max(1, leafIds.length);
567
- result.set(id, toScheduled(n, slack === INF ? 0 : slack, 0, anyCritical));
607
+ aggregates.set(id, sum);
608
+ n.progress = sum.weight > 0 ? sum.weighted / sum.weight : sum.progress / Math.max(1, sum.count);
609
+ result.set(id, toScheduled(n, sum.slack === INF ? 0 : sum.slack, 0, sum.critical));
568
610
  }
569
611
  function toScheduled(n, totalSlack, freeSlack, isCritical) {
570
612
  const baseline = n.task.baseline;
@@ -1,4 +1,4 @@
1
- import { DAY, HOUR, createTimeFormatter } from './chunk-LPH2V7XM.js';
1
+ import { DAY, HOUR, createTimeFormatter } from './chunk-FV63P7UY.js';
2
2
 
3
3
  // src/layout/index.ts
4
4
  var ZOOM_LEVELS = ["hour", "day", "week", "month", "quarter", "year"];
@@ -1,4 +1,4 @@
1
- import { dayIndex, parseTime, MINUTE, DAY } from './chunk-LPH2V7XM.js';
1
+ import { dayIndex, parseTime, MINUTE, DAY } from './chunk-FV63P7UY.js';
2
2
 
3
3
  // src/calendar/index.ts
4
4
  var STANDARD_CALENDAR_ID = "standard";