@metronforge/concept-map 0.3.2 → 0.4.0

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 (181) hide show
  1. package/README.md +5 -2
  2. package/dist/layout/index.js +4 -11
  3. package/dist/layout/index.js.map +1 -1
  4. package/dist/layout/place-sketch.d.ts +74 -0
  5. package/dist/layout/place-sketch.d.ts.map +1 -0
  6. package/dist/layout/place-sketch.js +16 -0
  7. package/dist/layout/place-sketch.js.map +1 -0
  8. package/dist/layout/place-with-hints.d.ts +7 -0
  9. package/dist/layout/place-with-hints.d.ts.map +1 -0
  10. package/dist/layout/place-with-hints.js +17 -0
  11. package/dist/layout/place-with-hints.js.map +1 -0
  12. package/dist/layout/relations/align-layout.d.ts.map +1 -1
  13. package/dist/layout/relations/align-layout.js +6 -2
  14. package/dist/layout/relations/align-layout.js.map +1 -1
  15. package/dist/layout/relations/apply.js +1 -1
  16. package/dist/layout/relations/apply.js.map +1 -1
  17. package/dist/layout/relations/bounds.d.ts +24 -0
  18. package/dist/layout/relations/bounds.d.ts.map +1 -0
  19. package/dist/layout/relations/bounds.js +126 -0
  20. package/dist/layout/relations/bounds.js.map +1 -0
  21. package/dist/layout/relations/check-linear.d.ts +17 -0
  22. package/dist/layout/relations/check-linear.d.ts.map +1 -0
  23. package/dist/layout/relations/check-linear.js +88 -0
  24. package/dist/layout/relations/check-linear.js.map +1 -0
  25. package/dist/layout/relations/check-objective.d.ts +10 -0
  26. package/dist/layout/relations/check-objective.d.ts.map +1 -0
  27. package/dist/layout/relations/check-objective.js +41 -0
  28. package/dist/layout/relations/check-objective.js.map +1 -0
  29. package/dist/layout/relations/check-witness.d.ts +4 -0
  30. package/dist/layout/relations/check-witness.d.ts.map +1 -1
  31. package/dist/layout/relations/check-witness.js +86 -5
  32. package/dist/layout/relations/check-witness.js.map +1 -1
  33. package/dist/layout/relations/cross.d.ts +1 -1
  34. package/dist/layout/relations/cross.d.ts.map +1 -1
  35. package/dist/layout/relations/cross.js +2 -2
  36. package/dist/layout/relations/cross.js.map +1 -1
  37. package/dist/layout/relations/derive.d.ts.map +1 -1
  38. package/dist/layout/relations/derive.js +18 -9
  39. package/dist/layout/relations/derive.js.map +1 -1
  40. package/dist/layout/relations/derived-input.d.ts +3 -0
  41. package/dist/layout/relations/derived-input.d.ts.map +1 -1
  42. package/dist/layout/relations/derived-input.js +9 -0
  43. package/dist/layout/relations/derived-input.js.map +1 -1
  44. package/dist/layout/relations/explain.d.ts +5 -0
  45. package/dist/layout/relations/explain.d.ts.map +1 -1
  46. package/dist/layout/relations/explain.js +53 -28
  47. package/dist/layout/relations/explain.js.map +1 -1
  48. package/dist/layout/relations/free-witness.d.ts +8 -0
  49. package/dist/layout/relations/free-witness.d.ts.map +1 -0
  50. package/dist/layout/relations/free-witness.js +38 -0
  51. package/dist/layout/relations/free-witness.js.map +1 -0
  52. package/dist/layout/relations/implication.d.ts +4 -0
  53. package/dist/layout/relations/implication.d.ts.map +1 -0
  54. package/dist/layout/relations/implication.js +23 -0
  55. package/dist/layout/relations/implication.js.map +1 -0
  56. package/dist/layout/relations/linear-differences.d.ts +16 -0
  57. package/dist/layout/relations/linear-differences.d.ts.map +1 -0
  58. package/dist/layout/relations/linear-differences.js +57 -0
  59. package/dist/layout/relations/linear-differences.js.map +1 -0
  60. package/dist/layout/relations/linear.d.ts +25 -0
  61. package/dist/layout/relations/linear.d.ts.map +1 -0
  62. package/dist/layout/relations/linear.js +75 -0
  63. package/dist/layout/relations/linear.js.map +1 -0
  64. package/dist/layout/relations/min-cost-flow.d.ts +7 -0
  65. package/dist/layout/relations/min-cost-flow.d.ts.map +1 -0
  66. package/dist/layout/relations/min-cost-flow.js +79 -0
  67. package/dist/layout/relations/min-cost-flow.js.map +1 -0
  68. package/dist/layout/relations/objective.d.ts +14 -0
  69. package/dist/layout/relations/objective.d.ts.map +1 -0
  70. package/dist/layout/relations/objective.js +33 -0
  71. package/dist/layout/relations/objective.js.map +1 -0
  72. package/dist/layout/relations/optimise.d.ts +20 -0
  73. package/dist/layout/relations/optimise.d.ts.map +1 -0
  74. package/dist/layout/relations/optimise.js +54 -0
  75. package/dist/layout/relations/optimise.js.map +1 -0
  76. package/dist/layout/relations/paths.d.ts +6 -0
  77. package/dist/layout/relations/paths.d.ts.map +1 -1
  78. package/dist/layout/relations/paths.js +35 -0
  79. package/dist/layout/relations/paths.js.map +1 -1
  80. package/dist/layout/relations/rank.d.ts +3 -2
  81. package/dist/layout/relations/rank.d.ts.map +1 -1
  82. package/dist/layout/relations/rank.js +5 -5
  83. package/dist/layout/relations/rank.js.map +1 -1
  84. package/dist/layout/relations/rational.d.ts +13 -0
  85. package/dist/layout/relations/rational.d.ts.map +1 -0
  86. package/dist/layout/relations/rational.js +28 -0
  87. package/dist/layout/relations/rational.js.map +1 -0
  88. package/dist/layout/relations/reduce-objective.d.ts +12 -0
  89. package/dist/layout/relations/reduce-objective.d.ts.map +1 -0
  90. package/dist/layout/relations/reduce-objective.js +37 -0
  91. package/dist/layout/relations/reduce-objective.js.map +1 -0
  92. package/dist/layout/relations/sketch-order.d.ts +6 -0
  93. package/dist/layout/relations/sketch-order.d.ts.map +1 -0
  94. package/dist/layout/relations/sketch-order.js +66 -0
  95. package/dist/layout/relations/sketch-order.js.map +1 -0
  96. package/dist/layout/relations/sketch-placement.d.ts +13 -0
  97. package/dist/layout/relations/sketch-placement.d.ts.map +1 -0
  98. package/dist/layout/relations/sketch-placement.js +123 -0
  99. package/dist/layout/relations/sketch-placement.js.map +1 -0
  100. package/dist/layout/relations/sketch-ranks.d.ts +5 -0
  101. package/dist/layout/relations/sketch-ranks.d.ts.map +1 -0
  102. package/dist/layout/relations/sketch-ranks.js +26 -0
  103. package/dist/layout/relations/sketch-ranks.js.map +1 -0
  104. package/dist/layout/relations/solve.d.ts +4 -1
  105. package/dist/layout/relations/solve.d.ts.map +1 -1
  106. package/dist/layout/relations/solve.js +10 -6
  107. package/dist/layout/relations/solve.js.map +1 -1
  108. package/dist/layout/route/channel-layout.d.ts +1 -0
  109. package/dist/layout/route/channel-layout.d.ts.map +1 -1
  110. package/dist/layout/route/channel-layout.js +4 -0
  111. package/dist/layout/route/channel-layout.js.map +1 -1
  112. package/dist/layout/route/channel-moved.d.ts +1 -1
  113. package/dist/layout/route/channel-moved.d.ts.map +1 -1
  114. package/dist/layout/route/channel-moved.js +8 -5
  115. package/dist/layout/route/channel-moved.js.map +1 -1
  116. package/dist/layout/sketch-agreement.d.ts +7 -0
  117. package/dist/layout/sketch-agreement.d.ts.map +1 -0
  118. package/dist/layout/sketch-agreement.js +48 -0
  119. package/dist/layout/sketch-agreement.js.map +1 -0
  120. package/dist/layout/sketch-bends.d.ts +5 -0
  121. package/dist/layout/sketch-bends.d.ts.map +1 -0
  122. package/dist/layout/sketch-bends.js +21 -0
  123. package/dist/layout/sketch-bends.js.map +1 -0
  124. package/dist/layout/sketch-returns.d.ts +4 -0
  125. package/dist/layout/sketch-returns.d.ts.map +1 -0
  126. package/dist/layout/sketch-returns.js +67 -0
  127. package/dist/layout/sketch-returns.js.map +1 -0
  128. package/dist/layout/sketch-route.d.ts +11 -0
  129. package/dist/layout/sketch-route.d.ts.map +1 -0
  130. package/dist/layout/sketch-route.js +109 -0
  131. package/dist/layout/sketch-route.js.map +1 -0
  132. package/dist/layout/sketch-safety.d.ts +6 -0
  133. package/dist/layout/sketch-safety.d.ts.map +1 -0
  134. package/dist/layout/sketch-safety.js +29 -0
  135. package/dist/layout/sketch-safety.js.map +1 -0
  136. package/dist/layout/sketch-shortcuts.d.ts +4 -0
  137. package/dist/layout/sketch-shortcuts.d.ts.map +1 -0
  138. package/dist/layout/sketch-shortcuts.js +51 -0
  139. package/dist/layout/sketch-shortcuts.js.map +1 -0
  140. package/dist/layout/width.d.ts +1 -0
  141. package/dist/layout/width.d.ts.map +1 -1
  142. package/dist/layout/width.js +3 -0
  143. package/dist/layout/width.js.map +1 -1
  144. package/package.json +2 -2
  145. package/src/layout/index.ts +10 -17
  146. package/src/layout/place-sketch.ts +34 -0
  147. package/src/layout/place-with-hints.ts +32 -0
  148. package/src/layout/relations/align-layout.ts +11 -6
  149. package/src/layout/relations/apply.ts +1 -1
  150. package/src/layout/relations/bounds.ts +163 -0
  151. package/src/layout/relations/check-linear.ts +153 -0
  152. package/src/layout/relations/check-objective.ts +60 -0
  153. package/src/layout/relations/check-witness.ts +118 -5
  154. package/src/layout/relations/cross.ts +2 -1
  155. package/src/layout/relations/derive.ts +24 -9
  156. package/src/layout/relations/derived-input.ts +13 -0
  157. package/src/layout/relations/explain.ts +69 -32
  158. package/src/layout/relations/free-witness.ts +41 -0
  159. package/src/layout/relations/implication.ts +30 -0
  160. package/src/layout/relations/linear-differences.ts +77 -0
  161. package/src/layout/relations/linear.ts +107 -0
  162. package/src/layout/relations/min-cost-flow.ts +96 -0
  163. package/src/layout/relations/objective.ts +53 -0
  164. package/src/layout/relations/optimise.ts +97 -0
  165. package/src/layout/relations/paths.ts +35 -0
  166. package/src/layout/relations/rank.ts +7 -4
  167. package/src/layout/relations/rational.ts +39 -0
  168. package/src/layout/relations/reduce-objective.ts +60 -0
  169. package/src/layout/relations/sketch-order.ts +79 -0
  170. package/src/layout/relations/sketch-placement.ts +168 -0
  171. package/src/layout/relations/sketch-ranks.ts +29 -0
  172. package/src/layout/relations/solve.ts +14 -6
  173. package/src/layout/route/channel-layout.ts +7 -0
  174. package/src/layout/route/channel-moved.ts +8 -6
  175. package/src/layout/sketch-agreement.ts +69 -0
  176. package/src/layout/sketch-bends.ts +29 -0
  177. package/src/layout/sketch-returns.ts +81 -0
  178. package/src/layout/sketch-route.ts +196 -0
  179. package/src/layout/sketch-safety.ts +64 -0
  180. package/src/layout/sketch-shortcuts.ts +65 -0
  181. package/src/layout/width.ts +4 -0
@@ -0,0 +1,196 @@
1
+ import { needsWidthPass } from "./width.js";
2
+ import { sketchOrder, meritsSketchCheck } from "./sketch-agreement.js";
3
+ import type { ResolvedMap, SourceMap } from "../schema.js";
4
+ import type { LayoutProblem } from "./problem.js";
5
+ import type { LayoutGraph, LayoutResult } from "./types.js";
6
+ import type { Measurer } from "./ports.js";
7
+ import type { RouteRefinement } from "./inspect-routes.js";
8
+ import { sketchPlacements } from "./relations/sketch-placement.js";
9
+ import { shortenSketchRoutes } from "./sketch-returns.js";
10
+ import { routeMoved } from "./route/channel-moved.js";
11
+ import { routeLayout, routeBounds } from "./route/channel-layout.js";
12
+ import { resolveMeasured } from "./resolve-measured.js";
13
+ import { placeAnnotations } from "./stages/placement.js";
14
+ import { checkHard } from "./stages/hard-check.js";
15
+ import { resolvedBends, bendCount } from "./sketch-bends.js";
16
+ import { safeSketch } from "./sketch-safety.js";
17
+ export { safeSketch } from "./sketch-safety.js";
18
+
19
+ /** Keep sketch order gains with at most four extra bends and no new hard
20
+ * contacts or crossings, before and after width refinement. */
21
+ export function routeSketch(
22
+ source: SourceMap,
23
+ problem: LayoutProblem,
24
+ graph: LayoutGraph,
25
+ original: LayoutResult,
26
+ measurer: Measurer,
27
+ refinement?: RouteRefinement,
28
+ sizingWidthEm?: number,
29
+ ): LayoutResult {
30
+ const checks = {
31
+ draw: (result: LayoutResult) =>
32
+ resolveMeasured(source, graph, result, measurer),
33
+ safe: (base: LayoutResult, route: LayoutResult) =>
34
+ safeSketch(source, graph, base, route, measurer, refinement),
35
+ };
36
+ const placed = choosePlacement(
37
+ problem,
38
+ graph,
39
+ original,
40
+ checks,
41
+ sizingWidthEm,
42
+ );
43
+ return chooseDetour(source, problem, graph, placed, measurer, checks);
44
+ }
45
+
46
+ function chooseDetour(
47
+ source: SourceMap,
48
+ problem: LayoutProblem,
49
+ graph: LayoutGraph,
50
+ placed: LayoutResult,
51
+ measurer: Measurer,
52
+ checks: SketchChecks,
53
+ ): LayoutResult {
54
+ const draw = (result: LayoutResult) => placeAnnotations(checks.draw(result));
55
+ const before = draw(placed);
56
+ const options = { measureLabel: measurer };
57
+ const initial = checkHard(source, before, options);
58
+ let best = placed;
59
+ let hard = initial.hard;
60
+ const routes = detours(problem, graph, placed, initial.lines.boxes);
61
+ for (const candidate of routes) {
62
+ const after = draw(candidate);
63
+ // A wider first pass enlarges boxes when layout remeasures at a given width.
64
+ if (after.viewBox[0] > before.viewBox[0]) continue;
65
+ const defects = checkHard(source, after, options).hard;
66
+ if (
67
+ defects < hard &&
68
+ resolvedBends(after) <= resolvedBends(before) &&
69
+ checks.safe(placed, candidate)
70
+ ) {
71
+ best = candidate;
72
+ hard = defects;
73
+ }
74
+ }
75
+ return best;
76
+ }
77
+
78
+ interface SketchChecks {
79
+ draw(result: LayoutResult): ResolvedMap;
80
+ safe(base: LayoutResult, route: LayoutResult): boolean;
81
+ }
82
+
83
+ function choosePlacement(
84
+ problem: LayoutProblem,
85
+ graph: LayoutGraph,
86
+ original: LayoutResult,
87
+ { draw, safe }: SketchChecks,
88
+ sizingWidthEm?: number,
89
+ ): LayoutResult {
90
+ const candidates = placementRoutes(problem, graph, original);
91
+ const bends = (result: LayoutResult) => resolvedBends(draw(result));
92
+ const originalBends = bends(original);
93
+ let best = original;
94
+ for (const option of candidates) {
95
+ if (!option) continue;
96
+ const gain =
97
+ sketchOrder(problem, option.nodes) - sketchOrder(problem, best.nodes);
98
+ if (
99
+ meritsSketchCheck(problem, gain, best, option) &&
100
+ bends(option) <=
101
+ Math.min(originalBends, bends(best) + (gain > 0 ? 4 : 0)) &&
102
+ safe(original, option)
103
+ )
104
+ best = option;
105
+ }
106
+ // Align return ports on the final box sizes. A sizing pass only estimates text width.
107
+ if (sizingWidthEm !== undefined && needsWidthPass(draw(best), sizingWidthEm))
108
+ return best;
109
+ return shortenSketchRoutes(
110
+ problem,
111
+ graph,
112
+ original,
113
+ best,
114
+ candidates,
115
+ bends,
116
+ safe,
117
+ );
118
+ }
119
+
120
+ function placementRoutes(
121
+ problem: LayoutProblem,
122
+ graph: LayoutGraph,
123
+ original: LayoutResult,
124
+ ) {
125
+ const rerouted = routeLayout(
126
+ graph,
127
+ original,
128
+ original.nodes,
129
+ routeBounds(original.nodes),
130
+ );
131
+ const candidates = sketchPlacements(problem, original).flatMap((nodes) =>
132
+ sketchRoutes(problem, graph, original, nodes),
133
+ );
134
+ return [rerouted, ...candidates];
135
+ }
136
+
137
+ /** A side shared by both ends can take an arrow around an intervening box. */
138
+ function* detours(
139
+ problem: LayoutProblem,
140
+ graph: LayoutGraph,
141
+ placed: LayoutResult,
142
+ contacts: ReturnType<typeof checkHard>["lines"]["boxes"],
143
+ ) {
144
+ if (!contacts.length) return;
145
+ for (const edge of graph.edges) {
146
+ if (
147
+ !contacts.some((c) => c.band === "defect" && c.b === `line:${edge.id}`) ||
148
+ problem.constraints.some((h) => h.kind === "side" && h.edge === edge.id)
149
+ )
150
+ continue;
151
+ for (const side of ["right", "left", "top", "bottom"] as const) {
152
+ const route = routeLayout(
153
+ { ...graph, edges: [edge] },
154
+ placed,
155
+ placed.nodes,
156
+ routeBounds(placed.nodes),
157
+ { [edge.id]: { from: side, to: side } },
158
+ );
159
+ if (route) yield route;
160
+ }
161
+ }
162
+ }
163
+
164
+ export function sketchRoutes(
165
+ problem: LayoutProblem,
166
+ graph: LayoutGraph,
167
+ original: LayoutResult,
168
+ nodes: LayoutResult["nodes"] | null,
169
+ ): (LayoutResult | null)[] {
170
+ if (!nodes) return [];
171
+ const bounds = routeBounds(nodes);
172
+ const routes = [
173
+ routeMoved(graph, original, nodes, bounds),
174
+ routeLayout(graph, original, nodes, bounds),
175
+ ];
176
+ // Engine ports can face away from neighbours after a sketch reorders boxes.
177
+ if (!problem.constraints.some((hint) => hint.kind === "side")) {
178
+ const pins = new Set(
179
+ problem.constraints.flatMap((hint) =>
180
+ hint.kind === "pin" ? [hint.node] : [],
181
+ ),
182
+ );
183
+ if (pins.size > 1) {
184
+ const facing = routeMoved(graph, original, nodes, bounds, pins);
185
+ routes.push(facing);
186
+ // Perpendicular ports can remove a bend between diagonally separated boxes.
187
+ if (
188
+ facing &&
189
+ bendCount(facing) > bendCount(original) &&
190
+ sketchOrder(problem, nodes) > sketchOrder(problem, original.nodes)
191
+ )
192
+ routes.push(routeMoved(graph, original, nodes, bounds, pins, true));
193
+ }
194
+ }
195
+ return routes;
196
+ }
@@ -0,0 +1,64 @@
1
+ import type { SourceMap } from "../schema.js";
2
+ import type { LayoutGraph, LayoutResult } from "./types.js";
3
+ import type { Measurer } from "./ports.js";
4
+ import type { RouteRefinement } from "./inspect-routes.js";
5
+ import { createRouteInspector } from "./inspect-routes.js";
6
+ import { resolveMeasured } from "./resolve-measured.js";
7
+ import { placeAnnotations } from "./stages/placement.js";
8
+ import { check } from "./stages/report.js";
9
+ import { refine } from "./stages/refine.js";
10
+ import { atWidth } from "./width.js";
11
+
12
+ export function safeSketch(
13
+ source: SourceMap,
14
+ graph: LayoutGraph,
15
+ original: LayoutResult,
16
+ candidate: LayoutResult,
17
+ measurer: Measurer,
18
+ refinement?: RouteRefinement,
19
+ ): boolean {
20
+ const inspect = createRouteInspector(
21
+ source,
22
+ graph,
23
+ original,
24
+ measurer,
25
+ refinement,
26
+ );
27
+ return (
28
+ !inspect(candidate).length &&
29
+ !addsCrossings(source, graph, original, candidate, measurer, refinement)
30
+ );
31
+ }
32
+
33
+ function addsCrossings(
34
+ source: SourceMap,
35
+ graph: LayoutGraph,
36
+ original: LayoutResult,
37
+ candidate: LayoutResult,
38
+ measurer: Measurer,
39
+ refinement?: RouteRefinement,
40
+ ): boolean {
41
+ const resolved = (result: LayoutResult) =>
42
+ placeAnnotations(resolveMeasured(source, graph, result, measurer));
43
+ const before = resolved(original);
44
+ const after = resolved(candidate);
45
+ const report = check(source, after);
46
+ if (
47
+ report.constraints.some(
48
+ (constraint) => constraint.strength === "required" && !constraint.holds,
49
+ )
50
+ )
51
+ return true;
52
+ if (report.crossings.count > check(source, before).crossings.count)
53
+ return true;
54
+ if (refinement) {
55
+ const narrow = (result: typeof before) =>
56
+ refine(result, atWidth(refinement.measurer, result, refinement.widthEm));
57
+ if (
58
+ check(source, narrow(after)).crossings.count >
59
+ check(source, narrow(before)).crossings.count
60
+ )
61
+ return true;
62
+ }
63
+ return false;
64
+ }
@@ -0,0 +1,65 @@
1
+ import type { LayoutBox, LayoutGraph, LayoutResult } from "./types.js";
2
+ import { routeBounds, routeLayout } from "./route/channel-layout.js";
3
+
4
+ function* portPairs(from: LayoutBox, to: LayoutBox) {
5
+ const right = 2 * from[0] + from[2] < 2 * to[0] + to[2];
6
+ const down = 2 * from[1] + from[3] < 2 * to[1] + to[3];
7
+ yield {
8
+ from: down ? "bottom" : "top",
9
+ to: right ? "left" : "right",
10
+ } as const;
11
+ yield {
12
+ from: right ? "right" : "left",
13
+ to: down ? "top" : "bottom",
14
+ } as const;
15
+ for (const side of ["top", "right", "bottom", "left"] as const)
16
+ yield { from: side, to: side };
17
+ }
18
+
19
+ function* shortcuts(graph: LayoutGraph, current: LayoutResult) {
20
+ const bounds = routeBounds(current.nodes);
21
+ for (const edge of graph.edges) {
22
+ if (current.edges[edge.id].points.length < 4) continue;
23
+ for (const pair of portPairs(
24
+ current.nodes[edge.from],
25
+ current.nodes[edge.to],
26
+ )) {
27
+ const route = routeLayout(
28
+ { ...graph, edges: [edge] },
29
+ current,
30
+ current.nodes,
31
+ bounds,
32
+ {
33
+ [edge.id]: pair,
34
+ },
35
+ );
36
+ if (route) yield route;
37
+ }
38
+ }
39
+ }
40
+
41
+ /** Keep at most two single-arrow changes on the cheapest safe order gain. */
42
+ export function shortenArrows(
43
+ graph: LayoutGraph,
44
+ candidate: LayoutResult,
45
+ cap: number,
46
+ bends: (route: LayoutResult) => number,
47
+ safe: (base: LayoutResult, route: LayoutResult) => boolean,
48
+ ) {
49
+ let current = candidate;
50
+ for (let step = 0; step < 2; step++) {
51
+ let best = current;
52
+ let count = bends(current);
53
+ for (const option of shortcuts(graph, current)) {
54
+ const turns = bends(option);
55
+ if (turns < count && safe(current, option)) {
56
+ best = option;
57
+ count = turns;
58
+ }
59
+ }
60
+ if (count <= cap) return best;
61
+ if (best === current) break;
62
+ current = best;
63
+ }
64
+ return null;
65
+ }
@@ -1,6 +1,10 @@
1
1
  import type { ResolvedMap } from "../schema.js";
2
2
  import type { Measurer } from "./ports.js";
3
3
 
4
+ export function needsWidthPass(map: ResolvedMap, widthEm?: number): boolean {
5
+ return widthEm !== undefined && map.viewBox[0] / widthEm > 10.5;
6
+ }
7
+
4
8
  /** Match the text floor of a drawing fitted into a width in label em.
5
9
  * The first engine pass supplies a size for reserving space in the second.
6
10
  * Final annotation refinement uses that second drawing's actual width;