@classic-homes/gantt-core 0.3.1 → 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.
package/dist/index.d.cts CHANGED
@@ -32,7 +32,7 @@ interface GanttModelOptions {
32
32
  schedule?: ScheduleOptions;
33
33
  /** Collapsed summaries. Everything is expanded by default. */
34
34
  collapsed?: Iterable<string>;
35
- /** Maximum undo steps (default 100) */
35
+ /** Maximum undo steps (default 100); 0 disables history. */
36
36
  historyLimit?: number;
37
37
  }
38
38
  interface GanttModelState {
package/dist/index.d.ts CHANGED
@@ -32,7 +32,7 @@ interface GanttModelOptions {
32
32
  schedule?: ScheduleOptions;
33
33
  /** Collapsed summaries. Everything is expanded by default. */
34
34
  collapsed?: Iterable<string>;
35
- /** Maximum undo steps (default 100) */
35
+ /** Maximum undo steps (default 100); 0 disables history. */
36
36
  historyLimit?: number;
37
37
  }
38
38
  interface GanttModelState {
package/dist/index.js CHANGED
@@ -1,40 +1,61 @@
1
1
  import './chunk-FXPGR372.js';
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
- import { addUnits } from './chunk-MDRXY4HU.js';
6
- export { ZOOM_LEVELS, ZOOM_PRESETS, addUnits, barGeometry, createTimeScale, floorUnit, hitTestBar, pathFromPoints, routeDependency, scaleTicks, snapToUnit, timelineRange, virtualWindow } from './chunk-MDRXY4HU.js';
7
- import { DAY, HOUR, formatTime, startOfDay, parseTime, isDateOnly, createTimeFormatter } from './chunk-LPH2V7XM.js';
8
- export { DAY, HOUR, MINUTE, createTimeFormatter, dayIndex, formatTime, isDateOnly, parseTime, startOfDay, toLocalDate, tryParseTime, weekday } from './chunk-LPH2V7XM.js';
2
+ import { buildTaskTree, descendantsOf, scheduleProject, wouldCreateCycle } from './chunk-INRQCGC4.js';
3
+ export { ancestorsOf, buildOrderingGraph, buildTaskTree, descendantsOf, edgeKey, findCycle, isAncestor, leavesOf, scheduleProject, taskDaySpan, topoSort, wouldCreateCycle } from './chunk-INRQCGC4.js';
4
+ export { CONTINUOUS_CALENDAR, STANDARD_CALENDAR, STANDARD_CALENDAR_ID, compileCalendar, compileCalendars, nonWorkingSpans } from './chunk-LQGY5EOM.js';
5
+ import { addUnits } from './chunk-JS3ZLEZJ.js';
6
+ export { ZOOM_LEVELS, ZOOM_PRESETS, addUnits, barGeometry, createTimeScale, floorUnit, hitTestBar, pathFromPoints, routeDependency, scaleTicks, snapToUnit, timelineRange, virtualWindow } from './chunk-JS3ZLEZJ.js';
7
+ import { DAY, HOUR, startOfDay, MINUTE, formatTime, parseTime, toLocalDate, isDateOnly, createTimeFormatter } from './chunk-FV63P7UY.js';
8
+ export { DAY, HOUR, MINUTE, createTimeFormatter, dayIndex, formatTime, isDateOnly, parseTime, startOfDay, toLocalDate, tryParseTime, weekday } from './chunk-FV63P7UY.js';
9
9
 
10
10
  // src/model/tree.ts
11
11
  function flattenTasks(tasks, isExpanded, tree = buildTaskTree(tasks)) {
12
12
  const byId = new Map(tasks.map((t) => [t.id, t]));
13
13
  const rows = [];
14
14
  const wbs = /* @__PURE__ */ new Map();
15
- const walk = (parentId, prefix, level, visible) => {
16
- const kids = tree.children.get(parentId) ?? [];
17
- kids.forEach((id, i) => {
18
- const code = prefix ? `${prefix}.${i + 1}` : String(i + 1);
19
- wbs.set(id, code);
20
- const hasChildren = (tree.children.get(id)?.length ?? 0) > 0;
21
- const expanded = hasChildren && isExpanded(id);
22
- if (visible) {
23
- rows.push({
24
- id,
25
- task: byId.get(id),
26
- index: rows.length,
27
- level,
28
- wbs: code,
29
- hasChildren,
30
- expanded,
31
- parentId
32
- });
33
- }
34
- if (hasChildren) walk(id, code, level + 1, visible && expanded);
35
- });
36
- };
37
- walk(null, "", 1, true);
15
+ const stack = [
16
+ {
17
+ parentId: null,
18
+ prefix: "",
19
+ level: 1,
20
+ visible: true,
21
+ kids: tree.children.get(null) ?? [],
22
+ index: 0
23
+ }
24
+ ];
25
+ while (stack.length) {
26
+ const frame = stack[stack.length - 1];
27
+ if (frame.index >= frame.kids.length) {
28
+ stack.pop();
29
+ continue;
30
+ }
31
+ const i = frame.index++;
32
+ const id = frame.kids[i];
33
+ const code = frame.prefix ? `${frame.prefix}.${i + 1}` : String(i + 1);
34
+ wbs.set(id, code);
35
+ const kids = tree.children.get(id) ?? [];
36
+ const hasChildren = kids.length > 0;
37
+ const expanded = hasChildren && isExpanded(id);
38
+ if (frame.visible)
39
+ rows.push({
40
+ id,
41
+ task: byId.get(id),
42
+ index: rows.length,
43
+ level: frame.level,
44
+ wbs: code,
45
+ hasChildren,
46
+ expanded,
47
+ parentId: frame.parentId
48
+ });
49
+ if (hasChildren)
50
+ stack.push({
51
+ parentId: id,
52
+ prefix: code,
53
+ level: frame.level + 1,
54
+ visible: frame.visible && expanded,
55
+ kids,
56
+ index: 0
57
+ });
58
+ }
38
59
  return { rows, wbs };
39
60
  }
40
61
 
@@ -52,13 +73,29 @@ function applyOperation(data, op) {
52
73
  const fail = (msg) => {
53
74
  throw new GanttEditError(msg, op);
54
75
  };
76
+ const tree = buildTaskTree(tasks);
77
+ const protectedIds = /* @__PURE__ */ new Set();
78
+ const protectedStack = tasks.filter((t) => t.readonly).map((t) => t.id);
79
+ while (protectedStack.length) {
80
+ const id = protectedStack.pop();
81
+ if (protectedIds.has(id)) continue;
82
+ protectedIds.add(id);
83
+ for (const child of tree.children.get(id) ?? []) protectedStack.push(child);
84
+ }
85
+ const writable = (id) => {
86
+ if (id != null && protectedIds.has(id)) fail(`Task "${id}" is read-only`);
87
+ };
55
88
  switch (op.type) {
56
89
  case "update-task": {
57
90
  const i = tasks.findIndex((t) => t.id === op.id);
58
91
  if (i < 0) fail(`Unknown task "${op.id}"`);
59
92
  const prev = tasks[i];
93
+ writable(op.id);
94
+ writable(op.patch.parentId);
95
+ if ("parentId" in op.patch && op.patch.parentId !== prev.parentId) {
96
+ for (const id of descendantsOf(tree, op.id)) writable(id);
97
+ }
60
98
  if ("parentId" in op.patch && op.patch.parentId) {
61
- const tree = buildTaskTree(tasks);
62
99
  if (op.patch.parentId === op.id || descendantsOf(tree, op.id).includes(op.patch.parentId)) {
63
100
  fail("A task cannot be moved under itself");
64
101
  }
@@ -82,6 +119,7 @@ function applyOperation(data, op) {
82
119
  case "add-task": {
83
120
  if (!op.task.id) fail("Task needs an id");
84
121
  if (tasks.some((t) => t.id === op.task.id)) fail(`Task "${op.task.id}" already exists`);
122
+ writable(op.task.parentId);
85
123
  const copy = tasks.slice();
86
124
  const index = op.index === void 0 ? copy.length : Math.max(0, Math.min(op.index, copy.length));
87
125
  copy.splice(index, 0, op.task);
@@ -93,24 +131,34 @@ function applyOperation(data, op) {
93
131
  case "remove-task": {
94
132
  const i = tasks.findIndex((t) => t.id === op.id);
95
133
  if (i < 0) fail(`Unknown task "${op.id}"`);
96
- const tree = buildTaskTree(tasks);
97
134
  const doomed = /* @__PURE__ */ new Set([op.id, ...descendantsOf(tree, op.id)]);
135
+ for (const id of doomed) writable(id);
136
+ for (const d of dependencies) {
137
+ if (doomed.has(d.from) || doomed.has(d.to)) {
138
+ writable(d.from);
139
+ writable(d.to);
140
+ }
141
+ }
98
142
  const inverse = [];
99
143
  tasks.forEach((t, index) => {
100
144
  if (doomed.has(t.id)) inverse.push({ type: "add-task", task: t, index });
101
145
  });
102
- const removedDeps = dependencies.filter((d) => doomed.has(d.from) || doomed.has(d.to));
103
- for (const d of removedDeps) inverse.push({ type: "add-dependency", dependency: d });
146
+ dependencies.forEach((d, index) => {
147
+ if (doomed.has(d.from) || doomed.has(d.to))
148
+ inverse.push({ type: "add-dependency", dependency: d, index });
149
+ });
104
150
  return {
105
151
  data: {
106
152
  tasks: tasks.filter((t) => !doomed.has(t.id)),
107
- dependencies: dependencies.filter((d) => !removedDeps.includes(d))
153
+ dependencies: dependencies.filter((d) => !doomed.has(d.from) && !doomed.has(d.to))
108
154
  },
109
155
  inverse
110
156
  };
111
157
  }
112
158
  case "add-dependency": {
113
159
  const d = op.dependency;
160
+ writable(d.from);
161
+ writable(d.to);
114
162
  if (!d.id) fail("Dependency needs an id");
115
163
  if (dependencies.some((x) => x.id === d.id)) fail(`Dependency "${d.id}" already exists`);
116
164
  if (!tasks.some((t) => t.id === d.from) || !tasks.some((t) => t.id === d.to)) {
@@ -120,8 +168,11 @@ function applyOperation(data, op) {
120
168
  fail("These tasks are already linked");
121
169
  if (wouldCreateCycle(tasks, dependencies, d.from, d.to))
122
170
  fail("This link would create a circular dependency");
171
+ const copy = dependencies.slice();
172
+ const index = op.index === void 0 ? copy.length : Math.max(0, Math.min(op.index, copy.length));
173
+ copy.splice(index, 0, d);
123
174
  return {
124
- data: { tasks, dependencies: [...dependencies, d] },
175
+ data: { tasks, dependencies: copy },
125
176
  inverse: [{ type: "remove-dependency", id: d.id }]
126
177
  };
127
178
  }
@@ -129,7 +180,14 @@ function applyOperation(data, op) {
129
180
  const i = dependencies.findIndex((d) => d.id === op.id);
130
181
  if (i < 0) fail(`Unknown dependency "${op.id}"`);
131
182
  const prev = dependencies[i];
183
+ writable(prev.from);
184
+ writable(prev.to);
132
185
  const next = { ...prev, ...op.patch };
186
+ writable(next.from);
187
+ writable(next.to);
188
+ for (const [k, v] of Object.entries(op.patch)) {
189
+ if (v === void 0) delete next[k];
190
+ }
133
191
  if (next.from !== prev.from || next.to !== prev.to) {
134
192
  const others = dependencies.filter((_, j) => j !== i);
135
193
  if (wouldCreateCycle(tasks, others, next.from, next.to))
@@ -146,11 +204,13 @@ function applyOperation(data, op) {
146
204
  };
147
205
  }
148
206
  case "remove-dependency": {
149
- const dep = dependencies.find((d) => d.id === op.id);
150
- if (!dep) fail(`Unknown dependency "${op.id}"`);
207
+ const index = dependencies.findIndex((d) => d.id === op.id);
208
+ if (index < 0) fail(`Unknown dependency "${op.id}"`);
209
+ writable(dependencies[index].from);
210
+ writable(dependencies[index].to);
151
211
  return {
152
212
  data: { tasks, dependencies: dependencies.filter((d) => d.id !== op.id) },
153
- inverse: [{ type: "add-dependency", dependency: dep }]
213
+ inverse: [{ type: "add-dependency", dependency: dependencies[index], index }]
154
214
  };
155
215
  }
156
216
  }
@@ -186,19 +246,61 @@ function createGanttModel(options) {
186
246
  let calendars = options.calendars ?? [];
187
247
  let scheduleOptions = options.schedule ?? {};
188
248
  const historyLimit = options.historyLimit ?? 100;
249
+ if (!Number.isSafeInteger(historyLimit) || historyLimit < 0)
250
+ throw new RangeError("historyLimit must be a nonnegative integer");
189
251
  const collapsed = new Set(options.collapsed ?? []);
190
252
  let selection = /* @__PURE__ */ new Set();
191
253
  let focusedId = null;
192
254
  let undoStack = [];
193
255
  let redoStack = [];
194
256
  let version = 0;
195
- const run = (d) => scheduleProject(d.tasks, d.dependencies, calendars, scheduleOptions);
257
+ const run = (d, c = calendars, o = scheduleOptions) => scheduleProject(d.tasks, d.dependencies, c, o);
258
+ const prepare = (operations) => {
259
+ try {
260
+ const candidate = applyAll(data, operations);
261
+ for (const task of candidate.data.tasks) {
262
+ if (!task.id || typeof task.name !== "string") throw new Error("Task needs an id and name");
263
+ if (task.duration !== void 0 && (!Number.isFinite(task.duration) || task.duration < 0))
264
+ throw new Error(`Task "${task.id}" needs a finite, nonnegative duration`);
265
+ if (task.progress !== void 0 && (!Number.isFinite(task.progress) || task.progress < 0 || task.progress > 100))
266
+ throw new Error(`Task "${task.id}" progress must be between 0 and 100`);
267
+ }
268
+ const pairs = /* @__PURE__ */ new Set();
269
+ for (const dep of candidate.data.dependencies) {
270
+ if (!dep.id) throw new Error("Dependency needs an id");
271
+ if (dep.type !== void 0 && !["FS", "SS", "FF", "SF"].includes(dep.type))
272
+ throw new Error("Unknown dependency type");
273
+ if (dep.lag !== void 0 && !Number.isFinite(dep.lag))
274
+ throw new Error("Dependency needs a finite lag");
275
+ const pair = JSON.stringify([dep.from, dep.to]);
276
+ if (pairs.has(pair)) throw new Error("These tasks are already linked");
277
+ pairs.add(pair);
278
+ }
279
+ const result = run(candidate.data);
280
+ const invalid = result.conflicts.find(
281
+ (c) => c.kind === "cycle" || c.kind === "invalid-dependency"
282
+ );
283
+ if (invalid) throw new Error(invalid.message);
284
+ return { ...candidate, schedule: result };
285
+ } catch (err) {
286
+ if (err instanceof GanttEditError || !operations.length) throw err;
287
+ throw new GanttEditError(err instanceof Error ? err.message : String(err), operations[0]);
288
+ }
289
+ };
196
290
  let schedule = run(data);
291
+ let flattenedTasks;
292
+ let flattened;
293
+ let rowsDirty = true;
197
294
  let state = build();
198
295
  const listeners = /* @__PURE__ */ new Set();
199
296
  const changeListeners = /* @__PURE__ */ new Set();
200
297
  function build() {
201
- const { rows, wbs } = flattenTasks(data.tasks, (id) => !collapsed.has(id));
298
+ if (rowsDirty || flattenedTasks !== data.tasks) {
299
+ flattened = flattenTasks(data.tasks, (id) => !collapsed.has(id));
300
+ flattenedTasks = data.tasks;
301
+ rowsDirty = false;
302
+ }
303
+ const { rows, wbs } = flattened;
202
304
  return {
203
305
  tasks: data.tasks,
204
306
  dependencies: data.dependencies,
@@ -217,10 +319,10 @@ function createGanttModel(options) {
217
319
  state = build();
218
320
  for (const l of listeners) l(state);
219
321
  }
220
- function commit(next, source, operations, label) {
322
+ function commit(next, source, operations, label, nextSchedule) {
221
323
  const before = schedule;
222
324
  data = next;
223
- schedule = run(data);
325
+ schedule = nextSchedule;
224
326
  const ids = new Set(data.tasks.map((t) => t.id));
225
327
  selection = new Set([...selection].filter((id) => ids.has(id)));
226
328
  if (focusedId !== null && !ids.has(focusedId)) focusedId = null;
@@ -249,72 +351,85 @@ function createGanttModel(options) {
249
351
  },
250
352
  apply(operations, label) {
251
353
  const ops = asArray(operations);
252
- const { data: next, inverse } = applyAll(data, ops);
253
- undoStack.push({ label, forward: ops, inverse });
254
- if (undoStack.length > historyLimit) undoStack = undoStack.slice(-historyLimit);
354
+ const { data: next, inverse, schedule: nextSchedule } = prepare(ops);
355
+ if (historyLimit > 0) {
356
+ undoStack.push({ label, forward: ops, inverse, before: data, after: next });
357
+ if (undoStack.length > historyLimit) undoStack = undoStack.slice(-historyLimit);
358
+ }
255
359
  redoStack = [];
256
- return commit(next, "edit", ops, label);
360
+ return commit(next, "edit", ops, label, nextSchedule);
257
361
  },
258
362
  validate(operations) {
259
363
  try {
260
- applyAll(data, asArray(operations));
364
+ prepare(asArray(operations));
261
365
  return null;
262
366
  } catch (e) {
263
367
  return e instanceof Error ? e.message : String(e);
264
368
  }
265
369
  },
266
370
  preview(operations) {
267
- return run(applyAll(data, asArray(operations)).data);
371
+ return prepare(asArray(operations)).schedule;
268
372
  },
269
373
  undo() {
270
- const entry = undoStack.pop();
374
+ const entry = undoStack[undoStack.length - 1];
271
375
  if (!entry) return null;
272
- const { data: next } = applyAll(data, entry.inverse);
376
+ const nextSchedule = run(entry.before);
377
+ undoStack.pop();
273
378
  redoStack.push(entry);
274
- return commit(next, "undo", entry.inverse, entry.label);
379
+ return commit(entry.before, "undo", entry.inverse, entry.label, nextSchedule);
275
380
  },
276
381
  redo() {
277
- const entry = redoStack.pop();
382
+ const entry = redoStack[redoStack.length - 1];
278
383
  if (!entry) return null;
279
- const { data: next, inverse } = applyAll(data, entry.forward);
280
- undoStack.push({ ...entry, inverse });
281
- return commit(next, "redo", entry.forward, entry.label);
384
+ const nextSchedule = run(entry.after);
385
+ redoStack.pop();
386
+ undoStack.push(entry);
387
+ return commit(entry.after, "redo", entry.forward, entry.label, nextSchedule);
282
388
  },
283
389
  setData(next) {
284
- data = {
390
+ const candidate = {
285
391
  tasks: next.tasks ?? data.tasks,
286
392
  dependencies: next.dependencies ?? data.dependencies
287
393
  };
288
- if (next.calendars) calendars = next.calendars;
394
+ const nextCalendars = next.calendars ?? calendars;
395
+ const nextSchedule = run(candidate, nextCalendars);
396
+ data = candidate;
397
+ rowsDirty = true;
398
+ calendars = nextCalendars;
289
399
  undoStack = [];
290
400
  redoStack = [];
291
- schedule = run(data);
401
+ schedule = nextSchedule;
292
402
  const ids = new Set(data.tasks.map((t) => t.id));
293
403
  selection = new Set([...selection].filter((id) => ids.has(id)));
294
404
  if (focusedId !== null && !ids.has(focusedId)) focusedId = null;
295
405
  emit();
296
406
  },
297
407
  setScheduleOptions(next) {
408
+ const nextSchedule = run(data, calendars, next);
298
409
  scheduleOptions = next;
299
- schedule = run(data);
410
+ schedule = nextSchedule;
300
411
  emit();
301
412
  },
302
413
  toggle(id) {
414
+ rowsDirty = true;
303
415
  if (collapsed.has(id)) collapsed.delete(id);
304
416
  else collapsed.add(id);
305
417
  emit();
306
418
  },
307
419
  setExpanded(id, expanded) {
308
420
  if (expanded === !collapsed.has(id)) return;
421
+ rowsDirty = true;
309
422
  if (expanded) collapsed.delete(id);
310
423
  else collapsed.add(id);
311
424
  emit();
312
425
  },
313
426
  expandAll() {
427
+ rowsDirty = true;
314
428
  collapsed.clear();
315
429
  emit();
316
430
  },
317
431
  collapseAll() {
432
+ rowsDirty = true;
318
433
  const tree = buildTaskTree(data.tasks);
319
434
  for (const t of data.tasks) if (tree.children.get(t.id)?.length) collapsed.add(t.id);
320
435
  emit();
@@ -399,8 +514,12 @@ function editOperation(ctx, mode, preview) {
399
514
  const { source, calendar: cal, minutesPerDay, snap } = ctx;
400
515
  const coarse = snap !== "hour";
401
516
  const fmt = (t, original, isFinish) => {
517
+ if (original instanceof Date) return toLocalDate(t);
518
+ if (typeof original === "number") return t;
402
519
  if (coarse && original !== void 0 && isDateOnly(original)) {
403
- return formatTime(isFinish && t % DAY === 0 ? t - 1 : t, { dateOnly: true });
520
+ return formatTime(isFinish && preview.start !== preview.finish && t % DAY === 0 ? t - 1 : t, {
521
+ dateOnly: true
522
+ });
404
523
  }
405
524
  return formatTime(t);
406
525
  };
@@ -409,7 +528,7 @@ function editOperation(ctx, mode, preview) {
409
528
  const isMilestone = ctx.task.type === "milestone";
410
529
  if (mode === "move" || isMilestone) {
411
530
  patch.start = fmt(preview.start, source.start, false);
412
- if (usesEnd && !isMilestone) patch.end = fmt(preview.finish, source.end, true);
531
+ if (usesEnd) patch.end = fmt(preview.finish, source.end, true);
413
532
  } else if (mode === "resize-end") {
414
533
  if (usesEnd) patch.end = fmt(preview.finish, source.end, true);
415
534
  else patch.duration = round(cal.between(preview.start, preview.finish) / minutesPerDay);
@@ -420,9 +539,9 @@ function editOperation(ctx, mode, preview) {
420
539
  }
421
540
  const c = source.constraint;
422
541
  if (c && (c.type === "SNET" || c.type === "MSO") && patch.start !== void 0) {
423
- patch.constraint = { ...c, date: patch.start };
542
+ patch.constraint = { ...c, date: fmt(preview.start, c.date, false) };
424
543
  } else if (c && (c.type === "FNET" || c.type === "MFO") && (patch.start !== void 0 || patch.end !== void 0 || patch.duration !== void 0)) {
425
- patch.constraint = { ...c, date: formatTime(preview.finish) };
544
+ patch.constraint = { ...c, date: fmt(preview.finish, c.date, true) };
426
545
  }
427
546
  return { type: "update-task", id: source.id, patch };
428
547
  }
@@ -495,8 +614,14 @@ function rescheduleOperation(ctx, edit) {
495
614
  const patch = {};
496
615
  if (moved) Object.assign(patch, patchOf(editOperation(c, "move", preview)));
497
616
  if (resized) {
498
- if (length === 0) patch.duration = 0;
499
- else Object.assign(patch, patchOf(editOperation(c, "resize-end", preview)));
617
+ if (length === 0 && ctx.source.duration === void 0 && ctx.source.end !== void 0) {
618
+ Object.assign(patch, patchOf(editOperation(c, "resize-end", preview)));
619
+ patch.type = "milestone";
620
+ } else {
621
+ Object.assign(patch, patchOf(editOperation(c, "resize-end", preview)));
622
+ if (length === 0) patch.duration = 0;
623
+ }
624
+ if (length > 0 && ctx.source.type === "milestone") patch.type = "task";
500
625
  }
501
626
  return Object.keys(patch).length ? { type: "update-task", id: ctx.source.id, patch } : null;
502
627
  }
@@ -526,10 +651,15 @@ function parseDuration(text, minutesPerDay = 480) {
526
651
  const m = /^\s*(\d+(?:[.,]\d+)?)\s*([a-z]*)\s*$/i.exec(text);
527
652
  if (!m) return void 0;
528
653
  const n = Number(m[1].replace(",", "."));
654
+ if (!Number.isFinite(n) || !Number.isFinite(minutesPerDay) || minutesPerDay <= 0)
655
+ return void 0;
529
656
  const unit = m[2].toLowerCase();
530
657
  if (!unit || /^d(ays?)?$/.test(unit)) return n;
531
- if (/^h((ou)?rs?)?$/.test(unit)) return round(n * 60 / minutesPerDay);
532
- if (/^w((ee)?ks?)?$/.test(unit)) return n * 5;
658
+ if (/^h((ou)?rs?)?$/.test(unit)) {
659
+ const days = round(n * 60 / minutesPerDay);
660
+ return Number.isFinite(days) ? days : void 0;
661
+ }
662
+ if (/^w((ee)?ks?)?$/.test(unit)) return Number.isFinite(n * 5) ? n * 5 : void 0;
533
663
  return void 0;
534
664
  }
535
665
  function indentOperation(tasks, id) {
@@ -687,18 +817,25 @@ function exportProject(tasks, dependencies, calendars = [], schedule) {
687
817
  const s = schedule?.tasks.get(t.id);
688
818
  const out = { ...t };
689
819
  if (s) {
690
- out.start = formatTime(s.start);
691
- if (s.type !== "milestone" && t.duration === void 0) out.end = formatTime(s.finish);
820
+ out.start = serialiseTime(s.start);
821
+ if (s.type !== "milestone" && t.duration === void 0) out.end = serialiseTime(s.finish);
692
822
  }
693
- for (const [k, v] of Object.entries(out))
694
- if (v instanceof Date)
695
- out[k] = formatTime(parseTime(v));
696
- return out;
823
+ return serialiseWallDates(out);
697
824
  }),
698
825
  dependencies,
699
826
  calendars: calendars.length ? calendars : void 0
700
827
  };
701
828
  }
829
+ var serialiseTime = (time) => time % MINUTE === 0 ? formatTime(time) : new Date(time).toISOString().slice(0, -1);
830
+ function serialiseWallDates(value) {
831
+ if (value instanceof Date) return serialiseTime(parseTime(value));
832
+ if (Array.isArray(value)) return value.map(serialiseWallDates);
833
+ if (value && typeof value === "object")
834
+ return Object.fromEntries(
835
+ Object.entries(value).map(([key, item]) => [key, serialiseWallDates(item)])
836
+ );
837
+ return value;
838
+ }
702
839
  function importProject(input) {
703
840
  const data = typeof input === "string" ? JSON.parse(input) : input;
704
841
  if (!data || typeof data !== "object") throw new TypeError("Project must be an object");
@@ -732,7 +869,8 @@ function importProject(input) {
732
869
  }
733
870
  function tableToCsv(table) {
734
871
  const cell = (v) => {
735
- const s = v === void 0 || v === null ? "" : String(v);
872
+ const raw = v === void 0 || v === null ? "" : String(v);
873
+ const s = /^[\s]*[=+@-]/.test(raw) ? `'${raw}` : raw;
736
874
  return /[",\n\r]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s;
737
875
  };
738
876
  const lines = [table.columns.map((c) => cell(c.header)).join(",")];
@@ -1,2 +1,2 @@
1
- export { ZOOM_LEVELS, ZOOM_PRESETS, addUnits, barGeometry, createTimeScale, floorUnit, hitTestBar, pathFromPoints, routeDependency, scaleTicks, snapToUnit, timelineRange, virtualWindow } from '../chunk-MDRXY4HU.js';
2
- import '../chunk-LPH2V7XM.js';
1
+ export { ZOOM_LEVELS, ZOOM_PRESETS, addUnits, barGeometry, createTimeScale, floorUnit, hitTestBar, pathFromPoints, routeDependency, scaleTicks, snapToUnit, timelineRange, virtualWindow } from '../chunk-JS3ZLEZJ.js';
2
+ import '../chunk-FV63P7UY.js';