@diagrammo/dgmo 0.25.4 → 0.25.5

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.
Files changed (46) hide show
  1. package/dist/advanced.cjs +62543 -0
  2. package/dist/advanced.d.cts +5684 -0
  3. package/dist/advanced.d.ts +5684 -0
  4. package/dist/advanced.js +62296 -0
  5. package/dist/auto.cjs +59850 -0
  6. package/dist/auto.css +214 -0
  7. package/dist/auto.d.cts +39 -0
  8. package/dist/auto.d.ts +39 -0
  9. package/dist/auto.js +437 -0
  10. package/dist/auto.mjs +59860 -0
  11. package/dist/cli.cjs +465 -0
  12. package/dist/editor.cjs +432 -0
  13. package/dist/editor.d.cts +26 -0
  14. package/dist/editor.d.ts +26 -0
  15. package/dist/editor.js +401 -0
  16. package/dist/highlight.cjs +720 -0
  17. package/dist/highlight.d.cts +32 -0
  18. package/dist/highlight.d.ts +32 -0
  19. package/dist/highlight.js +690 -0
  20. package/dist/index.cjs +59036 -0
  21. package/dist/index.d.cts +375 -0
  22. package/dist/index.d.ts +375 -0
  23. package/dist/index.js +59040 -0
  24. package/dist/internal.cjs +62545 -0
  25. package/dist/internal.d.cts +5684 -0
  26. package/dist/internal.d.ts +5684 -0
  27. package/dist/internal.js +62296 -0
  28. package/dist/map-data/PROVENANCE.json +1 -0
  29. package/dist/map-data/gazetteer.json +1 -0
  30. package/dist/map-data/lakes.json +1 -0
  31. package/dist/map-data/mountain-ranges.json +1 -0
  32. package/dist/map-data/na-lakes.json +1 -0
  33. package/dist/map-data/na-land.json +1 -0
  34. package/dist/map-data/region-names.json +1 -0
  35. package/dist/map-data/rivers.json +1 -0
  36. package/dist/map-data/us-states.json +1 -0
  37. package/dist/map-data/water-bodies.json +1 -0
  38. package/dist/map-data/world-coarse.json +1 -0
  39. package/dist/map-data/world-detail.json +1 -0
  40. package/dist/pert.cjs +325 -0
  41. package/dist/pert.d.cts +554 -0
  42. package/dist/pert.d.ts +554 -0
  43. package/dist/pert.js +294 -0
  44. package/package.json +1 -1
  45. package/src/editor/dgmo.grammar.js +18 -0
  46. package/src/editor/dgmo.grammar.terms.js +35 -0
package/dist/pert.cjs ADDED
@@ -0,0 +1,325 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/pert/index.ts
21
+ var pert_exports = {};
22
+ __export(pert_exports, {
23
+ buildSimulationContext: () => buildSimulationContext,
24
+ mulberry32: () => mulberry32,
25
+ sampleBetaPert: () => sampleBetaPert,
26
+ simulateCanonical: () => simulateCanonical,
27
+ simulateFast: () => simulateFast
28
+ });
29
+ module.exports = __toCommonJS(pert_exports);
30
+
31
+ // src/pert/internal.ts
32
+ var UNIT_TO_DAYS_LOCAL = {
33
+ min: 1 / (60 * 24),
34
+ h: 1 / 24,
35
+ d: 1,
36
+ bd: 1,
37
+ // PERT has no calendar; bd ≈ d for analytical purposes
38
+ w: 7,
39
+ m: 30,
40
+ q: 90,
41
+ y: 365,
42
+ s: 14
43
+ // sprint (14 calendar days) — not seconds
44
+ };
45
+ function unitToDays(unit) {
46
+ return UNIT_TO_DAYS_LOCAL[unit];
47
+ }
48
+
49
+ // src/pert/monte-carlo.ts
50
+ function lagDays(lag) {
51
+ return lag === null ? 0 : lag.amount * unitToDays(lag.unit);
52
+ }
53
+ function mulberry32(seed) {
54
+ let s = seed >>> 0;
55
+ return () => {
56
+ s = s + 1831565813 >>> 0;
57
+ let t = s;
58
+ t = Math.imul(t ^ t >>> 15, t | 1);
59
+ t ^= t + Math.imul(t ^ t >>> 7, t | 61);
60
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
61
+ };
62
+ }
63
+ function standardNormal(rng) {
64
+ let u = 0;
65
+ let v = 0;
66
+ while (u === 0) u = rng();
67
+ while (v === 0) v = rng();
68
+ return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
69
+ }
70
+ function gamma(shape, rng) {
71
+ if (shape < 1) {
72
+ const u = rng();
73
+ return gamma(shape + 1, rng) * Math.pow(u, 1 / shape);
74
+ }
75
+ const d = shape - 1 / 3;
76
+ const c = 1 / Math.sqrt(9 * d);
77
+ while (true) {
78
+ let x;
79
+ let v;
80
+ do {
81
+ x = standardNormal(rng);
82
+ v = 1 + c * x;
83
+ } while (v <= 0);
84
+ v = v * v * v;
85
+ const u = rng();
86
+ if (u < 1 - 0.0331 * x * x * x * x) return d * v;
87
+ if (Math.log(u) < x * x / 2 + d * (1 - v + Math.log(v))) return d * v;
88
+ }
89
+ }
90
+ function sampleBeta(alpha, beta, rng) {
91
+ const x = gamma(alpha, rng);
92
+ const y = gamma(beta, rng);
93
+ return x / (x + y);
94
+ }
95
+ function sampleBetaPert(o, m, p, rng) {
96
+ if (o === p) return m;
97
+ const range = p - o;
98
+ const alpha = 1 + 4 * (m - o) / range;
99
+ const beta = 1 + 4 * (p - m) / range;
100
+ return o + sampleBeta(alpha, beta, rng) * range;
101
+ }
102
+ function simulate(resolved, expanded, _predecessors, _successors, topo, terminals, poisoned, opts) {
103
+ const rng = mulberry32(opts.seed);
104
+ const expById = /* @__PURE__ */ new Map();
105
+ for (const e of expanded) expById.set(e.id, e);
106
+ const completionTimes = new Array(opts.trials);
107
+ const criticalityCount = /* @__PURE__ */ new Map();
108
+ for (const id of topo) criticalityCount.set(id, 0);
109
+ const pathCount = /* @__PURE__ */ new Map();
110
+ const pathById = /* @__PURE__ */ new Map();
111
+ const incomingEdges = /* @__PURE__ */ new Map();
112
+ for (const id of topo) incomingEdges.set(id, []);
113
+ for (const e of resolved.edges) incomingEdges.get(e.target)?.push(e);
114
+ const es = /* @__PURE__ */ new Map();
115
+ const ef = /* @__PURE__ */ new Map();
116
+ const predOnLongestPath = /* @__PURE__ */ new Map();
117
+ for (let trial = 0; trial < opts.trials; trial++) {
118
+ for (const id of topo) {
119
+ const exp = expById.get(id);
120
+ let duration;
121
+ if (!exp || poisoned.has(id)) {
122
+ duration = 0;
123
+ } else if (exp.o === exp.p) {
124
+ duration = exp.m;
125
+ } else {
126
+ duration = sampleBetaPert(exp.o, exp.m, exp.p, rng);
127
+ }
128
+ let esLower = 0;
129
+ let efLower = -Infinity;
130
+ let bestPred = null;
131
+ let bestPredVal = -Infinity;
132
+ for (const edge of incomingEdges.get(id) ?? []) {
133
+ const aEs = es.get(edge.source) ?? 0;
134
+ const aEf = ef.get(edge.source) ?? 0;
135
+ const lag = lagDays(edge.lag);
136
+ let candES = -Infinity;
137
+ let candEF = -Infinity;
138
+ switch (edge.type) {
139
+ case "FS":
140
+ candES = aEf + lag;
141
+ break;
142
+ case "SS":
143
+ candES = aEs + lag;
144
+ break;
145
+ case "FF":
146
+ candEF = aEf + lag;
147
+ break;
148
+ case "SF":
149
+ candEF = aEs + lag;
150
+ break;
151
+ }
152
+ if (candES > esLower) esLower = candES;
153
+ if (candEF > efLower) efLower = candEF;
154
+ const contribution = Math.max(candES, candEF - duration);
155
+ if (contribution > bestPredVal) {
156
+ bestPredVal = contribution;
157
+ bestPred = edge.source;
158
+ }
159
+ }
160
+ let esVal = esLower;
161
+ let efVal = esVal + duration;
162
+ if (efLower > efVal) {
163
+ efVal = efLower;
164
+ esVal = efVal - duration;
165
+ }
166
+ es.set(id, esVal);
167
+ ef.set(id, efVal);
168
+ predOnLongestPath.set(id, bestPred);
169
+ }
170
+ let endEf = 0;
171
+ let endId = terminals[0] ?? null;
172
+ for (const id of topo) {
173
+ const e = ef.get(id) ?? 0;
174
+ if (e > endEf) {
175
+ endEf = e;
176
+ endId = id;
177
+ }
178
+ }
179
+ completionTimes[trial] = endEf;
180
+ if (endId !== null) {
181
+ const path = [];
182
+ let cur = endId;
183
+ while (cur !== null) {
184
+ path.unshift(cur);
185
+ criticalityCount.set(cur, (criticalityCount.get(cur) ?? 0) + 1);
186
+ cur = predOnLongestPath.get(cur) ?? null;
187
+ }
188
+ const key = path.join("\0");
189
+ pathCount.set(key, (pathCount.get(key) ?? 0) + 1);
190
+ if (!pathById.has(key)) pathById.set(key, path);
191
+ }
192
+ }
193
+ completionTimes.sort((a, b) => a - b);
194
+ const pct = (frac) => {
195
+ const idx = Math.min(
196
+ completionTimes.length - 1,
197
+ Math.max(0, Math.floor(frac * completionTimes.length))
198
+ );
199
+ return completionTimes[idx] ?? 0;
200
+ };
201
+ const minDurationDays = completionTimes[0] ?? 0;
202
+ const maxDurationDays = completionTimes[completionTimes.length - 1] ?? 0;
203
+ let modalKey = "";
204
+ let modalCount = -1;
205
+ for (const [key, count] of pathCount) {
206
+ if (count > modalCount) {
207
+ modalCount = count;
208
+ modalKey = key;
209
+ } else if (count === modalCount) {
210
+ const a = pathById.get(modalKey) ?? [];
211
+ const b = pathById.get(key) ?? [];
212
+ const va = pathVariance(a, expById);
213
+ const vb = pathVariance(b, expById);
214
+ if (vb > va) {
215
+ modalKey = key;
216
+ } else if (vb === va && key.localeCompare(modalKey) < 0) {
217
+ modalKey = key;
218
+ }
219
+ }
220
+ }
221
+ const criticalityByActivity = {};
222
+ for (const id of topo) {
223
+ criticalityByActivity[id] = (criticalityCount.get(id) ?? 0) / opts.trials;
224
+ }
225
+ return {
226
+ trials: opts.trials,
227
+ seed: opts.seed,
228
+ p50: pct(0.5),
229
+ p80: pct(0.8),
230
+ p95: pct(0.95),
231
+ p16: pct(0.16),
232
+ p84: pct(0.84),
233
+ criticalityByActivity,
234
+ modalCriticalPath: pathById.get(modalKey) ?? [],
235
+ // Analyzer populates this after MC returns by running the
236
+ // deterministic per-activity tornado pass. Empty here so the
237
+ // type contract is satisfied even in scrubber/fast paths that
238
+ // never compute swings.
239
+ tornadoSwings: [],
240
+ minDurationDays,
241
+ maxDurationDays
242
+ };
243
+ }
244
+ function pathVariance(path, expById) {
245
+ let sum = 0;
246
+ for (const id of path) {
247
+ const e = expById.get(id);
248
+ if (!e) continue;
249
+ const sigma = (e.p - e.o) / 6;
250
+ sum += sigma * sigma;
251
+ }
252
+ return sum;
253
+ }
254
+ function buildSimulationContext(resolved) {
255
+ const predecessors = /* @__PURE__ */ new Map();
256
+ const successors = /* @__PURE__ */ new Map();
257
+ for (const r of resolved.activities) {
258
+ predecessors.set(r.activity.id, []);
259
+ successors.set(r.activity.id, []);
260
+ }
261
+ for (const e of resolved.edges) {
262
+ successors.get(e.source)?.push(e.target);
263
+ predecessors.get(e.target)?.push(e.source);
264
+ }
265
+ const inDegree = /* @__PURE__ */ new Map();
266
+ for (const r of resolved.activities) {
267
+ inDegree.set(r.activity.id, predecessors.get(r.activity.id).length);
268
+ }
269
+ const queue = [];
270
+ for (const [id, deg] of inDegree) if (deg === 0) queue.push(id);
271
+ const topo = [];
272
+ while (queue.length > 0) {
273
+ const id = queue.shift();
274
+ topo.push(id);
275
+ for (const next of successors.get(id) ?? []) {
276
+ const deg = (inDegree.get(next) ?? 0) - 1;
277
+ inDegree.set(next, deg);
278
+ if (deg === 0) queue.push(next);
279
+ }
280
+ }
281
+ const terminals = [];
282
+ for (const r of resolved.activities) {
283
+ if ((successors.get(r.activity.id) ?? []).length === 0) {
284
+ terminals.push(r.activity.id);
285
+ }
286
+ }
287
+ const poisoned = /* @__PURE__ */ new Set();
288
+ for (const r of resolved.activities) {
289
+ if (r.activity.duration === null) {
290
+ const stack = [r.activity.id];
291
+ while (stack.length > 0) {
292
+ const id = stack.pop();
293
+ if (poisoned.has(id)) continue;
294
+ poisoned.add(id);
295
+ for (const next of successors.get(id) ?? []) stack.push(next);
296
+ }
297
+ }
298
+ }
299
+ return { predecessors, successors, topo, terminals, poisoned };
300
+ }
301
+ function simulateCanonical(resolved, expanded, opts) {
302
+ const ctx = buildSimulationContext(resolved);
303
+ return simulate(
304
+ resolved,
305
+ expanded,
306
+ ctx.predecessors,
307
+ ctx.successors,
308
+ ctx.topo,
309
+ ctx.terminals,
310
+ ctx.poisoned,
311
+ { trials: opts.trials, seed: opts.seed }
312
+ );
313
+ }
314
+ function simulateFast(resolved, expanded, opts) {
315
+ return simulateCanonical(resolved, expanded, opts);
316
+ }
317
+ // Annotate the CommonJS export names for ESM import in node:
318
+ 0 && (module.exports = {
319
+ buildSimulationContext,
320
+ mulberry32,
321
+ sampleBetaPert,
322
+ simulateCanonical,
323
+ simulateFast
324
+ });
325
+ //# sourceMappingURL=pert.cjs.map