@metronforge/concept-map 0.3.2 → 0.4.1
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/README.md +5 -2
- package/dist/layout/hints.d.ts +2 -2
- package/dist/layout/hints.d.ts.map +1 -1
- package/dist/layout/hints.js.map +1 -1
- package/dist/layout/index.d.ts +1 -6
- package/dist/layout/index.d.ts.map +1 -1
- package/dist/layout/index.js +1 -89
- package/dist/layout/index.js.map +1 -1
- package/dist/layout/layout.d.ts +7 -0
- package/dist/layout/layout.d.ts.map +1 -0
- package/dist/layout/layout.js +83 -0
- package/dist/layout/layout.js.map +1 -0
- package/dist/layout/place-sketch.d.ts +74 -0
- package/dist/layout/place-sketch.d.ts.map +1 -0
- package/dist/layout/place-sketch.js +20 -0
- package/dist/layout/place-sketch.js.map +1 -0
- package/dist/layout/place-with-hints.d.ts +7 -0
- package/dist/layout/place-with-hints.d.ts.map +1 -0
- package/dist/layout/place-with-hints.js +17 -0
- package/dist/layout/place-with-hints.js.map +1 -0
- package/dist/layout/relations/align-layout.d.ts.map +1 -1
- package/dist/layout/relations/align-layout.js +6 -2
- package/dist/layout/relations/align-layout.js.map +1 -1
- package/dist/layout/relations/apply.js +1 -1
- package/dist/layout/relations/apply.js.map +1 -1
- package/dist/layout/relations/bounds.d.ts +24 -0
- package/dist/layout/relations/bounds.d.ts.map +1 -0
- package/dist/layout/relations/bounds.js +126 -0
- package/dist/layout/relations/bounds.js.map +1 -0
- package/dist/layout/relations/check-linear.d.ts +17 -0
- package/dist/layout/relations/check-linear.d.ts.map +1 -0
- package/dist/layout/relations/check-linear.js +88 -0
- package/dist/layout/relations/check-linear.js.map +1 -0
- package/dist/layout/relations/check-objective.d.ts +10 -0
- package/dist/layout/relations/check-objective.d.ts.map +1 -0
- package/dist/layout/relations/check-objective.js +41 -0
- package/dist/layout/relations/check-objective.js.map +1 -0
- package/dist/layout/relations/check-witness.d.ts +4 -0
- package/dist/layout/relations/check-witness.d.ts.map +1 -1
- package/dist/layout/relations/check-witness.js +86 -5
- package/dist/layout/relations/check-witness.js.map +1 -1
- package/dist/layout/relations/cross.d.ts +1 -1
- package/dist/layout/relations/cross.d.ts.map +1 -1
- package/dist/layout/relations/cross.js +2 -2
- package/dist/layout/relations/cross.js.map +1 -1
- package/dist/layout/relations/derive.d.ts.map +1 -1
- package/dist/layout/relations/derive.js +18 -9
- package/dist/layout/relations/derive.js.map +1 -1
- package/dist/layout/relations/derived-input.d.ts +3 -0
- package/dist/layout/relations/derived-input.d.ts.map +1 -1
- package/dist/layout/relations/derived-input.js +9 -0
- package/dist/layout/relations/derived-input.js.map +1 -1
- package/dist/layout/relations/explain.d.ts +5 -0
- package/dist/layout/relations/explain.d.ts.map +1 -1
- package/dist/layout/relations/explain.js +53 -28
- package/dist/layout/relations/explain.js.map +1 -1
- package/dist/layout/relations/free-witness.d.ts +8 -0
- package/dist/layout/relations/free-witness.d.ts.map +1 -0
- package/dist/layout/relations/free-witness.js +38 -0
- package/dist/layout/relations/free-witness.js.map +1 -0
- package/dist/layout/relations/implication.d.ts +4 -0
- package/dist/layout/relations/implication.d.ts.map +1 -0
- package/dist/layout/relations/implication.js +23 -0
- package/dist/layout/relations/implication.js.map +1 -0
- package/dist/layout/relations/linear-differences.d.ts +16 -0
- package/dist/layout/relations/linear-differences.d.ts.map +1 -0
- package/dist/layout/relations/linear-differences.js +57 -0
- package/dist/layout/relations/linear-differences.js.map +1 -0
- package/dist/layout/relations/linear.d.ts +25 -0
- package/dist/layout/relations/linear.d.ts.map +1 -0
- package/dist/layout/relations/linear.js +75 -0
- package/dist/layout/relations/linear.js.map +1 -0
- package/dist/layout/relations/min-cost-flow.d.ts +7 -0
- package/dist/layout/relations/min-cost-flow.d.ts.map +1 -0
- package/dist/layout/relations/min-cost-flow.js +79 -0
- package/dist/layout/relations/min-cost-flow.js.map +1 -0
- package/dist/layout/relations/objective.d.ts +14 -0
- package/dist/layout/relations/objective.d.ts.map +1 -0
- package/dist/layout/relations/objective.js +33 -0
- package/dist/layout/relations/objective.js.map +1 -0
- package/dist/layout/relations/optimise.d.ts +20 -0
- package/dist/layout/relations/optimise.d.ts.map +1 -0
- package/dist/layout/relations/optimise.js +54 -0
- package/dist/layout/relations/optimise.js.map +1 -0
- package/dist/layout/relations/paths.d.ts +6 -0
- package/dist/layout/relations/paths.d.ts.map +1 -1
- package/dist/layout/relations/paths.js +35 -0
- package/dist/layout/relations/paths.js.map +1 -1
- package/dist/layout/relations/rank.d.ts +3 -2
- package/dist/layout/relations/rank.d.ts.map +1 -1
- package/dist/layout/relations/rank.js +5 -5
- package/dist/layout/relations/rank.js.map +1 -1
- package/dist/layout/relations/rational.d.ts +13 -0
- package/dist/layout/relations/rational.d.ts.map +1 -0
- package/dist/layout/relations/rational.js +28 -0
- package/dist/layout/relations/rational.js.map +1 -0
- package/dist/layout/relations/reduce-objective.d.ts +12 -0
- package/dist/layout/relations/reduce-objective.d.ts.map +1 -0
- package/dist/layout/relations/reduce-objective.js +37 -0
- package/dist/layout/relations/reduce-objective.js.map +1 -0
- package/dist/layout/relations/sketch-order.d.ts +7 -0
- package/dist/layout/relations/sketch-order.d.ts.map +1 -0
- package/dist/layout/relations/sketch-order.js +67 -0
- package/dist/layout/relations/sketch-order.js.map +1 -0
- package/dist/layout/relations/sketch-placement.d.ts +14 -0
- package/dist/layout/relations/sketch-placement.d.ts.map +1 -0
- package/dist/layout/relations/sketch-placement.js +123 -0
- package/dist/layout/relations/sketch-placement.js.map +1 -0
- package/dist/layout/relations/sketch-ranks.d.ts +5 -0
- package/dist/layout/relations/sketch-ranks.d.ts.map +1 -0
- package/dist/layout/relations/sketch-ranks.js +26 -0
- package/dist/layout/relations/sketch-ranks.js.map +1 -0
- package/dist/layout/relations/solve.d.ts +4 -1
- package/dist/layout/relations/solve.d.ts.map +1 -1
- package/dist/layout/relations/solve.js +10 -6
- package/dist/layout/relations/solve.js.map +1 -1
- package/dist/layout/route/channel-layout.d.ts +1 -0
- package/dist/layout/route/channel-layout.d.ts.map +1 -1
- package/dist/layout/route/channel-layout.js +4 -0
- package/dist/layout/route/channel-layout.js.map +1 -1
- package/dist/layout/route/channel-moved.d.ts +1 -1
- package/dist/layout/route/channel-moved.d.ts.map +1 -1
- package/dist/layout/route/channel-moved.js +8 -5
- package/dist/layout/route/channel-moved.js.map +1 -1
- package/dist/layout/sketch-agreement.d.ts +7 -0
- package/dist/layout/sketch-agreement.d.ts.map +1 -0
- package/dist/layout/sketch-agreement.js +48 -0
- package/dist/layout/sketch-agreement.js.map +1 -0
- package/dist/layout/sketch-bends.d.ts +5 -0
- package/dist/layout/sketch-bends.d.ts.map +1 -0
- package/dist/layout/sketch-bends.js +21 -0
- package/dist/layout/sketch-bends.js.map +1 -0
- package/dist/layout/sketch-conflicts.d.ts +8 -0
- package/dist/layout/sketch-conflicts.d.ts.map +1 -0
- package/dist/layout/sketch-conflicts.js +56 -0
- package/dist/layout/sketch-conflicts.js.map +1 -0
- package/dist/layout/sketch-returns.d.ts +4 -0
- package/dist/layout/sketch-returns.d.ts.map +1 -0
- package/dist/layout/sketch-returns.js +67 -0
- package/dist/layout/sketch-returns.js.map +1 -0
- package/dist/layout/sketch-route.d.ts +12 -0
- package/dist/layout/sketch-route.d.ts.map +1 -0
- package/dist/layout/sketch-route.js +109 -0
- package/dist/layout/sketch-route.js.map +1 -0
- package/dist/layout/sketch-safety.d.ts +6 -0
- package/dist/layout/sketch-safety.d.ts.map +1 -0
- package/dist/layout/sketch-safety.js +29 -0
- package/dist/layout/sketch-safety.js.map +1 -0
- package/dist/layout/sketch-shortcuts.d.ts +4 -0
- package/dist/layout/sketch-shortcuts.d.ts.map +1 -0
- package/dist/layout/sketch-shortcuts.js +51 -0
- package/dist/layout/sketch-shortcuts.js.map +1 -0
- package/dist/layout/stages/hints.d.ts.map +1 -1
- package/dist/layout/stages/hints.js +33 -15
- package/dist/layout/stages/hints.js.map +1 -1
- package/dist/layout/width.d.ts +1 -0
- package/dist/layout/width.d.ts.map +1 -1
- package/dist/layout/width.js +3 -0
- package/dist/layout/width.js.map +1 -1
- package/package.json +2 -2
- package/src/layout/hints.ts +2 -2
- package/src/layout/index.ts +1 -155
- package/src/layout/layout.ts +147 -0
- package/src/layout/place-sketch.ts +39 -0
- package/src/layout/place-with-hints.ts +32 -0
- package/src/layout/relations/align-layout.ts +11 -6
- package/src/layout/relations/apply.ts +1 -1
- package/src/layout/relations/bounds.ts +163 -0
- package/src/layout/relations/check-linear.ts +153 -0
- package/src/layout/relations/check-objective.ts +60 -0
- package/src/layout/relations/check-witness.ts +118 -5
- package/src/layout/relations/cross.ts +2 -1
- package/src/layout/relations/derive.ts +24 -9
- package/src/layout/relations/derived-input.ts +13 -0
- package/src/layout/relations/explain.ts +69 -32
- package/src/layout/relations/free-witness.ts +41 -0
- package/src/layout/relations/implication.ts +30 -0
- package/src/layout/relations/linear-differences.ts +77 -0
- package/src/layout/relations/linear.ts +107 -0
- package/src/layout/relations/min-cost-flow.ts +96 -0
- package/src/layout/relations/objective.ts +53 -0
- package/src/layout/relations/optimise.ts +97 -0
- package/src/layout/relations/paths.ts +35 -0
- package/src/layout/relations/rank.ts +7 -4
- package/src/layout/relations/rational.ts +39 -0
- package/src/layout/relations/reduce-objective.ts +60 -0
- package/src/layout/relations/sketch-order.ts +90 -0
- package/src/layout/relations/sketch-placement.ts +174 -0
- package/src/layout/relations/sketch-ranks.ts +29 -0
- package/src/layout/relations/solve.ts +14 -6
- package/src/layout/route/channel-layout.ts +7 -0
- package/src/layout/route/channel-moved.ts +8 -6
- package/src/layout/sketch-agreement.ts +69 -0
- package/src/layout/sketch-bends.ts +29 -0
- package/src/layout/sketch-conflicts.ts +69 -0
- package/src/layout/sketch-returns.ts +81 -0
- package/src/layout/sketch-route.ts +199 -0
- package/src/layout/sketch-safety.ts +64 -0
- package/src/layout/sketch-shortcuts.ts +65 -0
- package/src/layout/stages/hints.ts +47 -19
- package/src/layout/width.ts +4 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sketch-safety.d.ts","sourceRoot":"","sources":["../../src/layout/sketch-safety.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAQ3D,wBAAgB,UAAU,CACxB,MAAM,EAAE,SAAS,EACjB,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,YAAY,EACtB,SAAS,EAAE,YAAY,EACvB,QAAQ,EAAE,QAAQ,EAClB,UAAU,CAAC,EAAE,eAAe,GAC3B,OAAO,CAYT"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createRouteInspector } from "./inspect-routes.js";
|
|
2
|
+
import { resolveMeasured } from "./resolve-measured.js";
|
|
3
|
+
import { placeAnnotations } from "./stages/placement.js";
|
|
4
|
+
import { check } from "./stages/report.js";
|
|
5
|
+
import { refine } from "./stages/refine.js";
|
|
6
|
+
import { atWidth } from "./width.js";
|
|
7
|
+
export function safeSketch(source, graph, original, candidate, measurer, refinement) {
|
|
8
|
+
const inspect = createRouteInspector(source, graph, original, measurer, refinement);
|
|
9
|
+
return (!inspect(candidate).length &&
|
|
10
|
+
!addsCrossings(source, graph, original, candidate, measurer, refinement));
|
|
11
|
+
}
|
|
12
|
+
function addsCrossings(source, graph, original, candidate, measurer, refinement) {
|
|
13
|
+
const resolved = (result) => placeAnnotations(resolveMeasured(source, graph, result, measurer));
|
|
14
|
+
const before = resolved(original);
|
|
15
|
+
const after = resolved(candidate);
|
|
16
|
+
const report = check(source, after);
|
|
17
|
+
if (report.constraints.some((constraint) => constraint.strength === "required" && !constraint.holds))
|
|
18
|
+
return true;
|
|
19
|
+
if (report.crossings.count > check(source, before).crossings.count)
|
|
20
|
+
return true;
|
|
21
|
+
if (refinement) {
|
|
22
|
+
const narrow = (result) => refine(result, atWidth(refinement.measurer, result, refinement.widthEm));
|
|
23
|
+
if (check(source, narrow(after)).crossings.count >
|
|
24
|
+
check(source, narrow(before)).crossings.count)
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=sketch-safety.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sketch-safety.js","sourceRoot":"","sources":["../../src/layout/sketch-safety.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,UAAU,UAAU,CACxB,MAAiB,EACjB,KAAkB,EAClB,QAAsB,EACtB,SAAuB,EACvB,QAAkB,EAClB,UAA4B;IAE5B,MAAM,OAAO,GAAG,oBAAoB,CAClC,MAAM,EACN,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,UAAU,CACX,CAAC;IACF,OAAO,CACL,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM;QAC1B,CAAC,aAAa,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,CAAC,CACzE,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CACpB,MAAiB,EACjB,KAAkB,EAClB,QAAsB,EACtB,SAAuB,EACvB,QAAkB,EAClB,UAA4B;IAE5B,MAAM,QAAQ,GAAG,CAAC,MAAoB,EAAE,EAAE,CACxC,gBAAgB,CAAC,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IACrE,MAAM,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAClC,MAAM,KAAK,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACpC,IACE,MAAM,CAAC,WAAW,CAAC,IAAI,CACrB,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,KAAK,UAAU,IAAI,CAAC,UAAU,CAAC,KAAK,CACxE;QAED,OAAO,IAAI,CAAC;IACd,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,SAAS,CAAC,KAAK;QAChE,OAAO,IAAI,CAAC;IACd,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,MAAM,GAAG,CAAC,MAAqB,EAAE,EAAE,CACvC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;QAC3E,IACE,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK;YAC5C,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK;YAE7C,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { LayoutGraph, LayoutResult } from "./types.js";
|
|
2
|
+
/** Keep at most two single-arrow changes on the cheapest safe order gain. */
|
|
3
|
+
export declare function shortenArrows(graph: LayoutGraph, candidate: LayoutResult, cap: number, bends: (route: LayoutResult) => number, safe: (base: LayoutResult, route: LayoutResult) => boolean): LayoutResult | null;
|
|
4
|
+
//# sourceMappingURL=sketch-shortcuts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sketch-shortcuts.d.ts","sourceRoot":"","sources":["../../src/layout/sketch-shortcuts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAwCvE,6EAA6E;AAC7E,wBAAgB,aAAa,CAC3B,KAAK,EAAE,WAAW,EAClB,SAAS,EAAE,YAAY,EACvB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,MAAM,EACtC,IAAI,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,KAAK,OAAO,uBAkB3D"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { routeBounds, routeLayout } from "./route/channel-layout.js";
|
|
2
|
+
function* portPairs(from, to) {
|
|
3
|
+
const right = 2 * from[0] + from[2] < 2 * to[0] + to[2];
|
|
4
|
+
const down = 2 * from[1] + from[3] < 2 * to[1] + to[3];
|
|
5
|
+
yield {
|
|
6
|
+
from: down ? "bottom" : "top",
|
|
7
|
+
to: right ? "left" : "right",
|
|
8
|
+
};
|
|
9
|
+
yield {
|
|
10
|
+
from: right ? "right" : "left",
|
|
11
|
+
to: down ? "top" : "bottom",
|
|
12
|
+
};
|
|
13
|
+
for (const side of ["top", "right", "bottom", "left"])
|
|
14
|
+
yield { from: side, to: side };
|
|
15
|
+
}
|
|
16
|
+
function* shortcuts(graph, current) {
|
|
17
|
+
const bounds = routeBounds(current.nodes);
|
|
18
|
+
for (const edge of graph.edges) {
|
|
19
|
+
if (current.edges[edge.id].points.length < 4)
|
|
20
|
+
continue;
|
|
21
|
+
for (const pair of portPairs(current.nodes[edge.from], current.nodes[edge.to])) {
|
|
22
|
+
const route = routeLayout({ ...graph, edges: [edge] }, current, current.nodes, bounds, {
|
|
23
|
+
[edge.id]: pair,
|
|
24
|
+
});
|
|
25
|
+
if (route)
|
|
26
|
+
yield route;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** Keep at most two single-arrow changes on the cheapest safe order gain. */
|
|
31
|
+
export function shortenArrows(graph, candidate, cap, bends, safe) {
|
|
32
|
+
let current = candidate;
|
|
33
|
+
for (let step = 0; step < 2; step++) {
|
|
34
|
+
let best = current;
|
|
35
|
+
let count = bends(current);
|
|
36
|
+
for (const option of shortcuts(graph, current)) {
|
|
37
|
+
const turns = bends(option);
|
|
38
|
+
if (turns < count && safe(current, option)) {
|
|
39
|
+
best = option;
|
|
40
|
+
count = turns;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (count <= cap)
|
|
44
|
+
return best;
|
|
45
|
+
if (best === current)
|
|
46
|
+
break;
|
|
47
|
+
current = best;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=sketch-shortcuts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sketch-shortcuts.js","sourceRoot":"","sources":["../../src/layout/sketch-shortcuts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAErE,QAAQ,CAAC,CAAC,SAAS,CAAC,IAAe,EAAE,EAAa;IAChD,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IACxD,MAAM,IAAI,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IACvD,MAAM;QACJ,IAAI,EAAE,IAAI,CAAC,C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,MAAM,UAAU,aAAa,CAC3B,KAAkB,EAClB,SAAuB,EACvB,GAAW,EACX,KAAsC,EACtC,IAA0D;IAE1D,IAAI,OAAO,GAAG,SAAS,CAAC;IACxB,KAAK,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC;QACpC,IAAI,IAAI,GAAG,OAAO,CAAC;QACnB,IAAI,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;QAC3B,KAAK,MAAM,MAAM,IAAI,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC;YAC/C,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;YAC5B,IAAI,KAAK,GAAG,KAAK,IAAI,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,CAAC;gBAC3C,IAAI,GAAG,MAAM,CAAC;gBACd,KAAK,GAAG,KAAK,CAAC;YAChB,CAAC;QACH,CAAC;QACD,IAAI,KAAK,IAAI,GAAG;YAAE,OAAO,IAAI,CAAC;QAC9B,IAAI,IAAI,KAAK,OAAO;YAAE,MAAM;QAC5B,OAAO,GAAG,IAAI,CAAC;IACjB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hints.d.ts","sourceRoot":"","sources":["../../../src/layout/stages/hints.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"hints.d.ts","sourceRoot":"","sources":["../../../src/layout/stages/hints.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAmEvD,4EAA4E;AAC5E,wBAAgB,UAAU,CACxB,MAAM,EAAE,SAAS,GAAG,WAAW,EAC/B,QAAQ,EAAE,WAAW,GACpB,iBAAiB,EAAE,CA8BrB"}
|
|
@@ -22,32 +22,50 @@ function sideHolds(hint, source, resolved) {
|
|
|
22
22
|
point[other] >= box[other] - epsilon(other) &&
|
|
23
23
|
point[other] <= box[other] + box[other + 2] + epsilon(other));
|
|
24
24
|
}
|
|
25
|
+
function pinVerdict(hint, pins, resolved, axis) {
|
|
26
|
+
const box = resolved.nodes[hint.node]?.box;
|
|
27
|
+
const distance = box
|
|
28
|
+
? Math.hypot(...hint.at.map((at, i) => box[i] + box[i + 2] / 2 - at))
|
|
29
|
+
: Infinity;
|
|
30
|
+
const holds = hint.strength === "required"
|
|
31
|
+
? distance <= 1e-6
|
|
32
|
+
: !box ||
|
|
33
|
+
pins.some((other) => {
|
|
34
|
+
const target = resolved.nodes[other.node]?.box;
|
|
35
|
+
const order = Math.sign(hint.at[1 - axis] - other.at[1 - axis]);
|
|
36
|
+
return (Math.round(other.at[axis] * 64) ===
|
|
37
|
+
Math.round(hint.at[axis] * 64) &&
|
|
38
|
+
(box[axis] !== target?.[axis] ||
|
|
39
|
+
(order &&
|
|
40
|
+
Math.sign(box[1 - axis] - target[1 - axis]) !== order)));
|
|
41
|
+
})
|
|
42
|
+
? false
|
|
43
|
+
: null;
|
|
44
|
+
return {
|
|
45
|
+
...hint,
|
|
46
|
+
holds,
|
|
47
|
+
message: `${constraintName(hint)}: distance: ${distance}`,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
25
50
|
/** Geometry is authoritative; rank exclusion cannot be inferred from it. */
|
|
26
51
|
export function checkHints(source, resolved) {
|
|
27
52
|
const axis = source.direction === "right" ? 0 : 1;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
: Infinity;
|
|
34
|
-
const message = `${hint.path}: pin (${hint.node}): ${distance} units from box centre`;
|
|
35
|
-
return hint.strength === "required"
|
|
36
|
-
? { ...hint, holds: distance <= 1e-6, message }
|
|
37
|
-
: { ...hint, holds: null, message };
|
|
38
|
-
}
|
|
53
|
+
const hints = statedHints(source);
|
|
54
|
+
const pins = hints.filter((h) => h.kind === "pin" && h.strength !== "required");
|
|
55
|
+
return hints.map((hint) => {
|
|
56
|
+
if (hint.kind === "pin")
|
|
57
|
+
return pinVerdict(hint, pins, resolved, axis);
|
|
39
58
|
if (hint.kind === "free")
|
|
40
59
|
return {
|
|
41
60
|
...hint,
|
|
42
61
|
holds: null,
|
|
43
62
|
message: `${constraintName(hint)}: not verifiable from the drawing`,
|
|
44
63
|
};
|
|
45
|
-
const positions = hint.kind === "sameRank"
|
|
46
|
-
? hint.nodes.map((id) => resolved.nodes[id]?.box[axis])
|
|
47
|
-
: [];
|
|
48
64
|
const holds = hint.kind === "side"
|
|
49
65
|
? sideHolds(hint, source, resolved)
|
|
50
|
-
:
|
|
66
|
+
: hint.nodes
|
|
67
|
+
.map((id) => resolved.nodes[id]?.box[axis])
|
|
68
|
+
.every((position, _index, positions) => position !== undefined && position === positions[0]);
|
|
51
69
|
return {
|
|
52
70
|
...hint,
|
|
53
71
|
holds,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hints.js","sourceRoot":"","sources":["../../../src/layout/stages/hints.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG1D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,SAAS,SAAS,CAChB,IAA2C,EAC3C,MAA+B,EAC/B,QAAqB;IAErB,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,GAAG,GAAG,IAAI,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC;IACxD,MAAM,I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EAAE,CAC9B,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,CACtD,CAAC;QACV,OAAO;YACL,GAAG,IAAI;YACP,KAAK;YACL,OAAO,EAAE,GAAG,cAAc,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,cAAc,EAAE;SAC3E,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/layout/width.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ResolvedMap } from "../schema.js";
|
|
2
2
|
import type { Measurer } from "./ports.js";
|
|
3
|
+
export declare function needsWidthPass(map: ResolvedMap, widthEm?: number): boolean;
|
|
3
4
|
/** Match the text floor of a drawing fitted into a width in label em.
|
|
4
5
|
* The first engine pass supplies a size for reserving space in the second.
|
|
5
6
|
* Final annotation refinement uses that second drawing's actual width;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"width.d.ts","sourceRoot":"","sources":["../../src/layout/width.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;kEAGkE;AAClE,wBAAgB,OAAO,CACrB,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,WAAW,EAChB,OAAO,CAAC,EAAE,MAAM,GACf,QAAQ,CAUV"}
|
|
1
|
+
{"version":3,"file":"width.d.ts","sourceRoot":"","sources":["../../src/layout/width.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,wBAAgB,cAAc,CAAC,GAAG,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAE1E;AAED;;;kEAGkE;AAClE,wBAAgB,OAAO,CACrB,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,WAAW,EAChB,OAAO,CAAC,EAAE,MAAM,GACf,QAAQ,CAUV"}
|
package/dist/layout/width.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export function needsWidthPass(map, widthEm) {
|
|
2
|
+
return widthEm !== undefined && map.viewBox[0] / widthEm > 10.5;
|
|
3
|
+
}
|
|
1
4
|
/** Match the text floor of a drawing fitted into a width in label em.
|
|
2
5
|
* The first engine pass supplies a size for reserving space in the second.
|
|
3
6
|
* Final annotation refinement uses that second drawing's actual width;
|
package/dist/layout/width.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"width.js","sourceRoot":"","sources":["../../src/layout/width.ts"],"names":[],"mappings":"AAGA;;;kEAGkE;AAClE,MAAM,UAAU,OAAO,CACrB,QAAkB,EAClB,GAAgB,EAChB,OAAgB;IAEhB,MAAM,OAAO,GAAG,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;IACrE,OAAO;QACL,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,OAAO,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CACvB,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE;YACrB,GAAG,KAAK;YACR,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC;SAC5C,CAAC;KACL,CAAC;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"file":"width.js","sourceRoot":"","sources":["../../src/layout/width.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,cAAc,CAAC,GAAgB,EAAE,OAAgB;IAC/D,OAAO,OAAO,KAAK,SAAS,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,IAAI,CAAC;AAClE,CAAC;AAED;;;kEAGkE;AAClE,MAAM,UAAU,OAAO,CACrB,QAAkB,EAClB,GAAgB,EAChB,OAAgB;IAEhB,MAAM,OAAO,GAAG,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;IACrE,OAAO;QACL,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,OAAO,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CACvB,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE;YACrB,GAAG,KAAK;YACR,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC;SAC5C,CAAC;KACL,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metronforge/concept-map",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Server-rendered concept maps with an accessible browser player",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"rolldown": "1.3.2",
|
|
101
101
|
"size-limit": "^14.3.0",
|
|
102
102
|
"typescript": "6.0.3",
|
|
103
|
-
"typescript-eslint": "^8.
|
|
103
|
+
"typescript-eslint": "^8.74.0",
|
|
104
104
|
"vite": "8.3.8",
|
|
105
105
|
"vitest": "5.1.0",
|
|
106
106
|
"zod": "4.6.7"
|
package/src/layout/hints.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SourceMap, ResolvedMap } from "../schema.js";
|
|
2
2
|
import type { Constraint } from "./problem.js";
|
|
3
|
-
import type { LayoutOptions, UnsupportedHint } from "./types.js";
|
|
3
|
+
import type { LayoutOptions, StatedHint, UnsupportedHint } from "./types.js";
|
|
4
4
|
|
|
5
5
|
export function statedHints(map: SourceMap | ResolvedMap) {
|
|
6
6
|
return (map.layout?.hints ?? []).map((hint, i) => ({
|
|
@@ -11,7 +11,7 @@ export function statedHints(map: SourceMap | ResolvedMap) {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
/** Name source hints in capability refusals without losing their references. */
|
|
14
|
-
export function constraintName(constraint: Constraint): string {
|
|
14
|
+
export function constraintName(constraint: Constraint | StatedHint): string {
|
|
15
15
|
if (!constraint.path) return constraint.kind;
|
|
16
16
|
const ids =
|
|
17
17
|
constraint.kind === "side"
|
package/src/layout/index.ts
CHANGED
|
@@ -1,25 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { validateReferences } from "../schema/references.js";
|
|
3
|
-
import { parseMap } from "./check.js";
|
|
4
|
-
import { asMeasurer } from "./measure.js";
|
|
5
|
-
import type { Measurer } from "./ports.js";
|
|
6
|
-
import { atWidth } from "./width.js";
|
|
7
|
-
import { refine } from "./stages/refine.js";
|
|
8
|
-
import { buildProblem, problemGraph } from "./build-problem.js";
|
|
9
|
-
import { reportUnsupportedHints } from "./hints.js";
|
|
10
|
-
import { asPlacer } from "./legacy.js";
|
|
11
|
-
import { place } from "./place.js";
|
|
12
|
-
import { checkConstraints } from "./stages/constraints.js";
|
|
13
|
-
import { resolveMeasured } from "./resolve-measured.js";
|
|
14
|
-
import type { RouteRefinement } from "./inspect-routes.js";
|
|
15
|
-
import type { LayoutEngine, LayoutOptions, UnsupportedHint } from "./types.js";
|
|
16
|
-
import {
|
|
17
|
-
EngineFailedError,
|
|
18
|
-
ResultRejectedError,
|
|
19
|
-
UnsupportedConstraintsError,
|
|
20
|
-
LayoutDefectsError,
|
|
21
|
-
} from "./errors.js";
|
|
22
|
-
import { placeAnnotations } from "./stages/placement.js";
|
|
1
|
+
export { layout } from "./layout.js";
|
|
23
2
|
export {
|
|
24
3
|
LayoutError,
|
|
25
4
|
EngineFailedError,
|
|
@@ -55,136 +34,3 @@ export type {
|
|
|
55
34
|
Contact,
|
|
56
35
|
LayoutReport,
|
|
57
36
|
} from "./stages/report.js";
|
|
58
|
-
|
|
59
|
-
/** Validate first, then measure and lay out; complete hand geometry is retained.
|
|
60
|
-
* `layout` proposes a drawing; `check` judges it. Success here does not mean
|
|
61
|
-
* the drawing was checked unless `strict` is set. */
|
|
62
|
-
export async function layout(
|
|
63
|
-
input: unknown,
|
|
64
|
-
engine: LayoutEngine,
|
|
65
|
-
options: LayoutOptions = {},
|
|
66
|
-
): Promise<ResolvedMap> {
|
|
67
|
-
const map = parseMap(input);
|
|
68
|
-
validateReferences(map);
|
|
69
|
-
if (
|
|
70
|
-
options.widthEm !== undefined &&
|
|
71
|
-
(!Number.isFinite(options.widthEm) || options.widthEm <= 0)
|
|
72
|
-
)
|
|
73
|
-
throw new Error("widthEm must be a finite positive number");
|
|
74
|
-
const measurer = asMeasurer(options.measureLabel);
|
|
75
|
-
if ("viewBox" in map)
|
|
76
|
-
return strict(
|
|
77
|
-
map,
|
|
78
|
-
map,
|
|
79
|
-
atWidth(measurer, map, options.widthEm).measure,
|
|
80
|
-
options,
|
|
81
|
-
);
|
|
82
|
-
const resolved = await resolveAtWidth(map, engine, measurer, options);
|
|
83
|
-
return strict(
|
|
84
|
-
map,
|
|
85
|
-
resolved,
|
|
86
|
-
atWidth(measurer, resolved, options.widthEm).measure,
|
|
87
|
-
options,
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async function resolveAtWidth(
|
|
92
|
-
map: SourceMap,
|
|
93
|
-
engine: LayoutEngine,
|
|
94
|
-
measurer: Measurer,
|
|
95
|
-
options: LayoutOptions,
|
|
96
|
-
): Promise<ResolvedMap> {
|
|
97
|
-
let hints: readonly UnsupportedHint[] = [];
|
|
98
|
-
const collect = {
|
|
99
|
-
...options,
|
|
100
|
-
onUnsupportedHints: (items: readonly UnsupportedHint[]) => {
|
|
101
|
-
hints = items;
|
|
102
|
-
},
|
|
103
|
-
};
|
|
104
|
-
let resolved = await resolveSource(map, engine, measurer, collect);
|
|
105
|
-
if (
|
|
106
|
-
options.widthEm !== undefined &&
|
|
107
|
-
resolved.viewBox[0] / options.widthEm > 10.5
|
|
108
|
-
) {
|
|
109
|
-
hints = [];
|
|
110
|
-
resolved = await resolveSource(
|
|
111
|
-
map,
|
|
112
|
-
engine,
|
|
113
|
-
atWidth(measurer, resolved, options.widthEm),
|
|
114
|
-
collect,
|
|
115
|
-
{ measurer, widthEm: options.widthEm },
|
|
116
|
-
);
|
|
117
|
-
resolved = refine(resolved, atWidth(measurer, resolved, options.widthEm));
|
|
118
|
-
}
|
|
119
|
-
if (hints.length) options.onUnsupportedHints?.(hints);
|
|
120
|
-
return resolved;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
async function resolveSource(
|
|
124
|
-
map: SourceMap,
|
|
125
|
-
engine: LayoutEngine,
|
|
126
|
-
measurer: Measurer,
|
|
127
|
-
options: LayoutOptions,
|
|
128
|
-
refinement?: RouteRefinement,
|
|
129
|
-
): Promise<ResolvedMap> {
|
|
130
|
-
const measure = measurer.measure.bind(measurer);
|
|
131
|
-
const problem = buildProblem(map, measure, options.intent);
|
|
132
|
-
const graph = problemGraph(problem);
|
|
133
|
-
const placer = asPlacer(engine);
|
|
134
|
-
const sameRank = map.layout?.hints.some((h) => h.kind === "sameRank");
|
|
135
|
-
const requiredPin = map.layout?.hints.some(
|
|
136
|
-
(h) => h.kind === "pin" && h.strength === "required",
|
|
137
|
-
);
|
|
138
|
-
const free = map.layout?.hints.some((h) => h.kind === "free");
|
|
139
|
-
const outcome =
|
|
140
|
-
(sameRank || requiredPin) && !free
|
|
141
|
-
? await (
|
|
142
|
-
await import("./place-same-rank.js")
|
|
143
|
-
).placeSameRank(map, problem, placer, measurer, refinement)
|
|
144
|
-
: free
|
|
145
|
-
? await (
|
|
146
|
-
await import("./place-free.js")
|
|
147
|
-
).placeFree(map, problem, placer, measurer, refinement)
|
|
148
|
-
: await place(problem, placer);
|
|
149
|
-
if (outcome.kind === "engine-failed") throw new EngineFailedError(outcome);
|
|
150
|
-
if (outcome.kind === "unsupported-constraints")
|
|
151
|
-
throw new UnsupportedConstraintsError(outcome);
|
|
152
|
-
reportUnsupportedHints(
|
|
153
|
-
outcome.unsupported,
|
|
154
|
-
options.onUnsupportedHints,
|
|
155
|
-
outcome.dropped,
|
|
156
|
-
);
|
|
157
|
-
const resolved = resolveMeasured(map, graph, outcome.result, measurer);
|
|
158
|
-
checkRequired(map, resolved, placer.name);
|
|
159
|
-
validateReferences(resolved);
|
|
160
|
-
return placeAnnotations(resolved);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function checkRequired(map: SourceMap, resolved: ResolvedMap, placer: string) {
|
|
164
|
-
const rejected = checkConstraints(map, resolved).find(
|
|
165
|
-
(c) => c.strength === "required" && c.holds === false,
|
|
166
|
-
);
|
|
167
|
-
if (rejected)
|
|
168
|
-
throw new ResultRejectedError({
|
|
169
|
-
placer,
|
|
170
|
-
constraint: rejected.kind,
|
|
171
|
-
message: rejected.message,
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/** The check is loaded only for `strict`, so plain layout stays small. */
|
|
176
|
-
async function strict(
|
|
177
|
-
source: SourceMap | ResolvedMap,
|
|
178
|
-
resolved: ResolvedMap,
|
|
179
|
-
measure: import("./types.js").LabelMeasurer,
|
|
180
|
-
options: LayoutOptions,
|
|
181
|
-
): Promise<ResolvedMap> {
|
|
182
|
-
if (!options.strict) return resolved;
|
|
183
|
-
const { check, describeDefects } = await import("./stages/report.js");
|
|
184
|
-
const report = check(source, resolved, { measureLabel: measure });
|
|
185
|
-
if (!report.hard) return resolved;
|
|
186
|
-
throw new LayoutDefectsError(
|
|
187
|
-
report,
|
|
188
|
-
`The layout has hard defects:\n${describeDefects(report).join("\n")}`,
|
|
189
|
-
);
|
|
190
|
-
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { ResolvedMap, SourceMap } from "../schema.js";
|
|
2
|
+
import { validateReferences } from "../schema/references.js";
|
|
3
|
+
import { parseMap } from "./check.js";
|
|
4
|
+
import { asMeasurer } from "./measure.js";
|
|
5
|
+
import type { Measurer } from "./ports.js";
|
|
6
|
+
import { atWidth, needsWidthPass } from "./width.js";
|
|
7
|
+
import { refine } from "./stages/refine.js";
|
|
8
|
+
import { buildProblem, problemGraph } from "./build-problem.js";
|
|
9
|
+
import { reportUnsupportedHints } from "./hints.js";
|
|
10
|
+
import { asPlacer } from "./legacy.js";
|
|
11
|
+
import { placeWithHints } from "./place-with-hints.js";
|
|
12
|
+
import { checkConstraints } from "./stages/constraints.js";
|
|
13
|
+
import { resolveMeasured } from "./resolve-measured.js";
|
|
14
|
+
import type { RouteRefinement } from "./inspect-routes.js";
|
|
15
|
+
import type { LayoutEngine, LayoutOptions, UnsupportedHint } from "./types.js";
|
|
16
|
+
import {
|
|
17
|
+
EngineFailedError,
|
|
18
|
+
ResultRejectedError,
|
|
19
|
+
UnsupportedConstraintsError,
|
|
20
|
+
LayoutDefectsError,
|
|
21
|
+
} from "./errors.js";
|
|
22
|
+
import { placeAnnotations } from "./stages/placement.js";
|
|
23
|
+
/** Validate first, then measure and lay out; complete hand geometry is retained.
|
|
24
|
+
* `layout` proposes a drawing; `check` judges it. Success here does not mean
|
|
25
|
+
* the drawing was checked unless `strict` is set. */
|
|
26
|
+
export async function layout(
|
|
27
|
+
input: unknown,
|
|
28
|
+
engine: LayoutEngine,
|
|
29
|
+
options: LayoutOptions = {},
|
|
30
|
+
): Promise<ResolvedMap> {
|
|
31
|
+
const map = parseMap(input);
|
|
32
|
+
validateReferences(map);
|
|
33
|
+
if (
|
|
34
|
+
options.widthEm !== undefined &&
|
|
35
|
+
(!Number.isFinite(options.widthEm) || options.widthEm <= 0)
|
|
36
|
+
)
|
|
37
|
+
throw new Error("widthEm must be a finite positive number");
|
|
38
|
+
const measurer = asMeasurer(options.measureLabel);
|
|
39
|
+
if ("viewBox" in map)
|
|
40
|
+
return strict(
|
|
41
|
+
map,
|
|
42
|
+
map,
|
|
43
|
+
atWidth(measurer, map, options.widthEm).measure,
|
|
44
|
+
options,
|
|
45
|
+
);
|
|
46
|
+
const resolved = await resolveAtWidth(map, engine, measurer, options);
|
|
47
|
+
return strict(
|
|
48
|
+
map,
|
|
49
|
+
resolved,
|
|
50
|
+
atWidth(measurer, resolved, options.widthEm).measure,
|
|
51
|
+
options,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function resolveAtWidth(
|
|
56
|
+
map: SourceMap,
|
|
57
|
+
engine: LayoutEngine,
|
|
58
|
+
measurer: Measurer,
|
|
59
|
+
options: LayoutOptions,
|
|
60
|
+
): Promise<ResolvedMap> {
|
|
61
|
+
let hints: readonly UnsupportedHint[] = [];
|
|
62
|
+
const collect = {
|
|
63
|
+
...options,
|
|
64
|
+
onUnsupportedHints: (items: readonly UnsupportedHint[]) => {
|
|
65
|
+
hints = items;
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
let resolved = await resolveSource(map, engine, measurer, collect);
|
|
69
|
+
if (
|
|
70
|
+
options.widthEm !== undefined &&
|
|
71
|
+
needsWidthPass(resolved, options.widthEm)
|
|
72
|
+
) {
|
|
73
|
+
hints = [];
|
|
74
|
+
resolved = await resolveSource(
|
|
75
|
+
map,
|
|
76
|
+
engine,
|
|
77
|
+
atWidth(measurer, resolved, options.widthEm),
|
|
78
|
+
collect,
|
|
79
|
+
{ measurer, widthEm: options.widthEm },
|
|
80
|
+
);
|
|
81
|
+
resolved = refine(resolved, atWidth(measurer, resolved, options.widthEm));
|
|
82
|
+
}
|
|
83
|
+
if (hints.length) options.onUnsupportedHints?.(hints);
|
|
84
|
+
return resolved;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function resolveSource(
|
|
88
|
+
map: SourceMap,
|
|
89
|
+
engine: LayoutEngine,
|
|
90
|
+
measurer: Measurer,
|
|
91
|
+
options: LayoutOptions,
|
|
92
|
+
refinement?: RouteRefinement,
|
|
93
|
+
): Promise<ResolvedMap> {
|
|
94
|
+
const measure = measurer.measure.bind(measurer);
|
|
95
|
+
const problem = buildProblem(map, measure, options.intent);
|
|
96
|
+
const graph = problemGraph(problem);
|
|
97
|
+
const placer = asPlacer(engine);
|
|
98
|
+
const outcome = await placeWithHints(
|
|
99
|
+
map,
|
|
100
|
+
problem,
|
|
101
|
+
placer,
|
|
102
|
+
measurer,
|
|
103
|
+
refinement,
|
|
104
|
+
refinement ? undefined : options.widthEm,
|
|
105
|
+
);
|
|
106
|
+
if (outcome.kind === "engine-failed") throw new EngineFailedError(outcome);
|
|
107
|
+
if (outcome.kind === "unsupported-constraints")
|
|
108
|
+
throw new UnsupportedConstraintsError(outcome);
|
|
109
|
+
reportUnsupportedHints(
|
|
110
|
+
outcome.unsupported,
|
|
111
|
+
options.onUnsupportedHints,
|
|
112
|
+
outcome.dropped,
|
|
113
|
+
);
|
|
114
|
+
const resolved = resolveMeasured(map, graph, outcome.result, measurer);
|
|
115
|
+
checkRequired(map, resolved, placer.name);
|
|
116
|
+
validateReferences(resolved);
|
|
117
|
+
return placeAnnotations(resolved);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function checkRequired(map: SourceMap, resolved: ResolvedMap, placer: string) {
|
|
121
|
+
const rejected = checkConstraints(map, resolved).find(
|
|
122
|
+
(c) => c.strength === "required" && c.holds === false,
|
|
123
|
+
);
|
|
124
|
+
if (rejected)
|
|
125
|
+
throw new ResultRejectedError({
|
|
126
|
+
placer,
|
|
127
|
+
constraint: rejected.kind,
|
|
128
|
+
message: rejected.message,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** The check is loaded only for `strict`, so plain layout stays small. */
|
|
133
|
+
async function strict(
|
|
134
|
+
source: SourceMap | ResolvedMap,
|
|
135
|
+
resolved: ResolvedMap,
|
|
136
|
+
measure: import("./types.js").LabelMeasurer,
|
|
137
|
+
options: LayoutOptions,
|
|
138
|
+
): Promise<ResolvedMap> {
|
|
139
|
+
if (!options.strict) return resolved;
|
|
140
|
+
const { check, describeDefects } = await import("./stages/report.js");
|
|
141
|
+
const report = check(source, resolved, { measureLabel: measure });
|
|
142
|
+
if (!report.hard) return resolved;
|
|
143
|
+
throw new LayoutDefectsError(
|
|
144
|
+
report,
|
|
145
|
+
`The layout has hard defects:\n${describeDefects(report).join("\n")}`,
|
|
146
|
+
);
|
|
147
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { SourceMap } from "../schema.js";
|
|
2
|
+
import type { LayoutProblem } from "./problem.js";
|
|
3
|
+
import type { Measurer, Placer } from "./ports.js";
|
|
4
|
+
import type { RouteRefinement } from "./inspect-routes.js";
|
|
5
|
+
import { place } from "./place.js";
|
|
6
|
+
import { problemGraph } from "./build-problem.js";
|
|
7
|
+
import { sketchConflicts } from "./sketch-conflicts.js";
|
|
8
|
+
import { routeSketch } from "./sketch-route.js";
|
|
9
|
+
|
|
10
|
+
/** Optional preferred-pin pass after an engine places the boxes. */
|
|
11
|
+
export async function placeSketch(
|
|
12
|
+
source: SourceMap,
|
|
13
|
+
problem: LayoutProblem,
|
|
14
|
+
placer: Placer,
|
|
15
|
+
measurer: Measurer,
|
|
16
|
+
refinement?: RouteRefinement,
|
|
17
|
+
sizingWidthEm?: number,
|
|
18
|
+
) {
|
|
19
|
+
const outcome = await place(problem, placer);
|
|
20
|
+
if (outcome.kind !== "placed") return outcome;
|
|
21
|
+
const graph = problemGraph(problem);
|
|
22
|
+
const diagnostics = sketchConflicts(problem);
|
|
23
|
+
const result = routeSketch(
|
|
24
|
+
source,
|
|
25
|
+
problem,
|
|
26
|
+
graph,
|
|
27
|
+
outcome.result,
|
|
28
|
+
measurer,
|
|
29
|
+
refinement,
|
|
30
|
+
sizingWidthEm,
|
|
31
|
+
diagnostics.record,
|
|
32
|
+
);
|
|
33
|
+
return {
|
|
34
|
+
...outcome,
|
|
35
|
+
dropped: diagnostics.hints,
|
|
36
|
+
unsupported: outcome.unsupported.filter((hint) => hint.kind !== "pin"),
|
|
37
|
+
result,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { SourceMap } from "../schema.js";
|
|
2
|
+
import type { LayoutProblem } from "./problem.js";
|
|
3
|
+
import type { Measurer, Placer } from "./ports.js";
|
|
4
|
+
import type { RouteRefinement } from "./inspect-routes.js";
|
|
5
|
+
import { place } from "./place.js";
|
|
6
|
+
|
|
7
|
+
/** Load only the hint stage needed by this map. */
|
|
8
|
+
export async function placeWithHints(
|
|
9
|
+
map: SourceMap,
|
|
10
|
+
problem: LayoutProblem,
|
|
11
|
+
placer: Placer,
|
|
12
|
+
measurer: Measurer,
|
|
13
|
+
refinement?: RouteRefinement,
|
|
14
|
+
sizingWidthEm?: number,
|
|
15
|
+
) {
|
|
16
|
+
const hints = map.layout?.hints ?? [];
|
|
17
|
+
const sameRank = hints.some((h) => h.kind === "sameRank");
|
|
18
|
+
const requiredPin = hints.some(
|
|
19
|
+
(h) => h.kind === "pin" && h.strength === "required",
|
|
20
|
+
);
|
|
21
|
+
const free = hints.some((h) => h.kind === "free");
|
|
22
|
+
const args = [map, problem, placer, measurer, refinement] as const;
|
|
23
|
+
if ((sameRank || requiredPin) && !free)
|
|
24
|
+
return (await import("./place-same-rank.js")).placeSameRank(...args);
|
|
25
|
+
if (free) return (await import("./place-free.js")).placeFree(...args);
|
|
26
|
+
if (hints.some((hint) => hint.kind === "pin"))
|
|
27
|
+
return (await import("./place-sketch.js")).placeSketch(
|
|
28
|
+
...args,
|
|
29
|
+
sizingWidthEm,
|
|
30
|
+
);
|
|
31
|
+
return place(problem, placer);
|
|
32
|
+
}
|