easyeda-mcp-pro 0.33.0 → 0.34.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 (173) hide show
  1. package/dist/bridge/types.d.ts +1 -0
  2. package/dist/bridge/types.js +1 -0
  3. package/dist/bridge/types.js.map +1 -1
  4. package/dist/circuit/circuit-ir.d.ts +15 -2
  5. package/dist/circuit/circuit-ir.js +2 -0
  6. package/dist/circuit/circuit-ir.js.map +1 -1
  7. package/dist/circuit/compiler.js +1 -0
  8. package/dist/circuit/compiler.js.map +1 -1
  9. package/dist/circuit/design-intent.d.ts +13 -0
  10. package/dist/circuit/design-intent.js +2 -0
  11. package/dist/circuit/design-intent.js.map +1 -1
  12. package/dist/circuit/index.d.ts +2 -0
  13. package/dist/circuit/index.js +2 -0
  14. package/dist/circuit/index.js.map +1 -1
  15. package/dist/circuit/reference-design.d.ts +16 -0
  16. package/dist/circuit/reference-design.js +16 -0
  17. package/dist/circuit/reference-design.js.map +1 -0
  18. package/dist/config/profiles.js +4 -4
  19. package/dist/config/version.d.ts +1 -1
  20. package/dist/config/version.js +1 -1
  21. package/dist/layout/autofix.d.ts +93 -0
  22. package/dist/layout/autofix.js +376 -0
  23. package/dist/layout/autofix.js.map +1 -0
  24. package/dist/layout/block-detector.d.ts +3 -0
  25. package/dist/layout/block-detector.js +252 -0
  26. package/dist/layout/block-detector.js.map +1 -0
  27. package/dist/layout/geometry.d.ts +20 -0
  28. package/dist/layout/geometry.js +150 -0
  29. package/dist/layout/geometry.js.map +1 -0
  30. package/dist/layout/graph.d.ts +5 -0
  31. package/dist/layout/graph.js +185 -0
  32. package/dist/layout/graph.js.map +1 -0
  33. package/dist/layout/index.d.ts +8 -0
  34. package/dist/layout/index.js +9 -0
  35. package/dist/layout/index.js.map +1 -0
  36. package/dist/layout/operations.d.ts +7 -0
  37. package/dist/layout/operations.js +170 -0
  38. package/dist/layout/operations.js.map +1 -0
  39. package/dist/layout/placement.d.ts +79 -0
  40. package/dist/layout/placement.js +248 -0
  41. package/dist/layout/placement.js.map +1 -0
  42. package/dist/layout/planner.d.ts +98 -0
  43. package/dist/layout/planner.js +338 -0
  44. package/dist/layout/planner.js.map +1 -0
  45. package/dist/layout/types.d.ts +281 -0
  46. package/dist/layout/types.js +2 -0
  47. package/dist/layout/types.js.map +1 -0
  48. package/dist/live/readback.d.ts +16 -0
  49. package/dist/live/readback.js +38 -0
  50. package/dist/live/readback.js.map +1 -0
  51. package/dist/professional-layout-templates/catalog.v1.d.ts +390 -0
  52. package/dist/professional-layout-templates/catalog.v1.js +460 -0
  53. package/dist/professional-layout-templates/catalog.v1.js.map +1 -0
  54. package/dist/professional-layout-templates/index.d.ts +14 -0
  55. package/dist/professional-layout-templates/index.js +118 -0
  56. package/dist/professional-layout-templates/index.js.map +1 -0
  57. package/dist/professional-layout-templates/types.d.ts +74 -0
  58. package/dist/professional-layout-templates/types.js +2 -0
  59. package/dist/professional-layout-templates/types.js.map +1 -0
  60. package/dist/router/astar.d.ts +23 -0
  61. package/dist/router/astar.js +177 -0
  62. package/dist/router/astar.js.map +1 -0
  63. package/dist/router/geometry.d.ts +39 -0
  64. package/dist/router/geometry.js +240 -0
  65. package/dist/router/geometry.js.map +1 -0
  66. package/dist/router/grid.d.ts +24 -0
  67. package/dist/router/grid.js +50 -0
  68. package/dist/router/grid.js.map +1 -0
  69. package/dist/router/obstacles.d.ts +33 -0
  70. package/dist/router/obstacles.js +243 -0
  71. package/dist/router/obstacles.js.map +1 -0
  72. package/dist/router/path-simplifier.d.ts +6 -0
  73. package/dist/router/path-simplifier.js +35 -0
  74. package/dist/router/path-simplifier.js.map +1 -0
  75. package/dist/router/pin-escape.d.ts +24 -0
  76. package/dist/router/pin-escape.js +155 -0
  77. package/dist/router/pin-escape.js.map +1 -0
  78. package/dist/router/route-cost.d.ts +10 -0
  79. package/dist/router/route-cost.js +82 -0
  80. package/dist/router/route-cost.js.map +1 -0
  81. package/dist/router/types.d.ts +187 -0
  82. package/dist/router/types.js +2 -0
  83. package/dist/router/types.js.map +1 -0
  84. package/dist/schematic-engine/errors.d.ts +22 -0
  85. package/dist/schematic-engine/errors.js +83 -0
  86. package/dist/schematic-engine/errors.js.map +1 -0
  87. package/dist/schematic-engine/geometry.d.ts +33 -0
  88. package/dist/schematic-engine/geometry.js +49 -0
  89. package/dist/schematic-engine/geometry.js.map +1 -0
  90. package/dist/schematic-engine/index.d.ts +2 -0
  91. package/dist/schematic-engine/index.js +3 -0
  92. package/dist/schematic-engine/index.js.map +1 -0
  93. package/dist/schematic-model/connectivity-fingerprint.d.ts +60 -0
  94. package/dist/schematic-model/connectivity-fingerprint.js +117 -0
  95. package/dist/schematic-model/connectivity-fingerprint.js.map +1 -0
  96. package/dist/schematic-model/geometry-model.d.ts +329 -0
  97. package/dist/schematic-model/geometry-model.js +8 -0
  98. package/dist/schematic-model/geometry-model.js.map +1 -0
  99. package/dist/schematic-model/geometry-net-names.d.ts +23 -0
  100. package/dist/schematic-model/geometry-net-names.js +166 -0
  101. package/dist/schematic-model/geometry-net-names.js.map +1 -0
  102. package/dist/schematic-model/geometry-normalize.d.ts +18 -0
  103. package/dist/schematic-model/geometry-normalize.js +281 -0
  104. package/dist/schematic-model/geometry-normalize.js.map +1 -0
  105. package/dist/schematic-model/imported-symbols.d.ts +13 -0
  106. package/dist/schematic-model/imported-symbols.js +155 -0
  107. package/dist/schematic-model/imported-symbols.js.map +1 -0
  108. package/dist/schematic-model/live-functional-layout.d.ts +45 -0
  109. package/dist/schematic-model/live-functional-layout.js +109 -0
  110. package/dist/schematic-model/live-functional-layout.js.map +1 -0
  111. package/dist/schematic-model/live-layout-autofix.d.ts +59 -0
  112. package/dist/schematic-model/live-layout-autofix.js +132 -0
  113. package/dist/schematic-model/live-layout-autofix.js.map +1 -0
  114. package/dist/schematic-model/live-placement-check.d.ts +32 -0
  115. package/dist/schematic-model/live-placement-check.js +56 -0
  116. package/dist/schematic-model/live-placement-check.js.map +1 -0
  117. package/dist/schematic-model/live-primitive-bounds.d.ts +18 -0
  118. package/dist/schematic-model/live-primitive-bounds.js +83 -0
  119. package/dist/schematic-model/live-primitive-bounds.js.map +1 -0
  120. package/dist/schematic-model/live-snapshot.d.ts +16 -0
  121. package/dist/schematic-model/live-snapshot.js +99 -0
  122. package/dist/schematic-model/live-snapshot.js.map +1 -0
  123. package/dist/schematic-model/model-builder.d.ts +7 -0
  124. package/dist/schematic-model/model-builder.js +429 -0
  125. package/dist/schematic-model/model-builder.js.map +1 -0
  126. package/dist/schematic-model/model-validator.d.ts +8 -0
  127. package/dist/schematic-model/model-validator.js +180 -0
  128. package/dist/schematic-model/model-validator.js.map +1 -0
  129. package/dist/schematic-model/pin-semantics.d.ts +17 -0
  130. package/dist/schematic-model/pin-semantics.js +70 -0
  131. package/dist/schematic-model/pin-semantics.js.map +1 -0
  132. package/dist/schematic-model/primitive-bounds.d.ts +69 -0
  133. package/dist/schematic-model/primitive-bounds.js +141 -0
  134. package/dist/schematic-model/primitive-bounds.js.map +1 -0
  135. package/dist/tools/L1_bom_core.js +3 -2
  136. package/dist/tools/L1_bom_core.js.map +1 -1
  137. package/dist/tools/L1_schematic_read.js +29 -4
  138. package/dist/tools/L1_schematic_read.js.map +1 -1
  139. package/dist/tools/L1_visual.js +146 -0
  140. package/dist/tools/L1_visual.js.map +1 -1
  141. package/dist/tools/L2_schematic_layout.d.ts +141 -0
  142. package/dist/tools/L2_schematic_layout.js +1155 -0
  143. package/dist/tools/L2_schematic_layout.js.map +1 -0
  144. package/dist/tools/L2_workflows.js +301 -10
  145. package/dist/tools/L2_workflows.js.map +1 -1
  146. package/dist/tools/register.js +2 -0
  147. package/dist/tools/register.js.map +1 -1
  148. package/dist/transactions/operation-log.d.ts +32 -0
  149. package/dist/transactions/operation-log.js +58 -0
  150. package/dist/transactions/operation-log.js.map +1 -0
  151. package/dist/workflows/index.d.ts +1 -1
  152. package/dist/workflows/led-blinker-template.d.ts +131 -0
  153. package/dist/workflows/led-blinker-template.js +212 -0
  154. package/dist/workflows/led-blinker-template.js.map +1 -0
  155. package/dist/workflows/ne555-astable-template.js +2 -2
  156. package/dist/workflows/ne555-astable-template.js.map +1 -1
  157. package/dist/workflows/ne555-wire-stubs.d.ts +17 -0
  158. package/dist/workflows/ne555-wire-stubs.js +114 -31
  159. package/dist/workflows/ne555-wire-stubs.js.map +1 -1
  160. package/dist/workflows/planner.js +58 -8
  161. package/dist/workflows/planner.js.map +1 -1
  162. package/dist/workflows/rp2040-servo-module-scaffold.d.ts +22 -1
  163. package/dist/workflows/rp2040-servo-module-scaffold.js +218 -77
  164. package/dist/workflows/rp2040-servo-module-scaffold.js.map +1 -1
  165. package/dist/workflows/schematic-layout-qa.d.ts +177 -0
  166. package/dist/workflows/schematic-layout-qa.js +727 -0
  167. package/dist/workflows/schematic-layout-qa.js.map +1 -0
  168. package/dist/workflows/types.d.ts +50 -0
  169. package/dist/workflows/wire-stub-generator.d.ts +104 -0
  170. package/dist/workflows/wire-stub-generator.js +105 -0
  171. package/dist/workflows/wire-stub-generator.js.map +1 -0
  172. package/easyeda-bridge-extension.eext +0 -0
  173. package/package.json +1 -1
@@ -0,0 +1,376 @@
1
+ import { boundsInside, boundsOverlap, combineBounds, inflateBounds, translateBounds, } from '../schematic-engine/geometry.js';
2
+ import { compareConnectivityFingerprints, } from '../schematic-model/connectivity-fingerprint.js';
3
+ import { readStable } from '../live/readback.js';
4
+ import { operationId } from '../transactions/operation-log.js';
5
+ import { getPrimitiveSnapshot, rollbackEasyedaTransaction, } from '../transactions/easyeda.js';
6
+ import { checkPlacement } from './placement.js';
7
+ export class LayoutAutofixConnectivityError extends Error {
8
+ result;
9
+ constructor(message, result) {
10
+ super(message);
11
+ this.result = result;
12
+ this.name = 'LayoutAutofixConnectivityError';
13
+ }
14
+ }
15
+ const TEXT_TYPES = new Set(['text', 'label', 'annotation', 'section-title']);
16
+ const ELECTRICAL_TYPES = new Set(['wire', 'power-symbol', 'no-connect']);
17
+ function violation(code, primitiveIds, message) {
18
+ const sortedIds = [...primitiveIds].sort((a, b) => a.localeCompare(b));
19
+ return { id: `${code}:${sortedIds.join(':')}`, code, primitiveIds: sortedIds, message };
20
+ }
21
+ function detectViolations(input) {
22
+ const result = [];
23
+ const ordered = [...input.primitives].sort((a, b) => a.id.localeCompare(b.id));
24
+ for (const primitive of ordered) {
25
+ if (!boundsInside(primitive.combinedBounds, input.sheet.drawableBounds)) {
26
+ result.push(violation('PAGE_BOUNDARY_OVERFLOW', [primitive.id], `Primitive "${primitive.id}" extends beyond drawable sheet bounds.`));
27
+ }
28
+ if (input.sheet.titleBlockBounds &&
29
+ boundsOverlap(primitive.combinedBounds, input.sheet.titleBlockBounds)) {
30
+ result.push(violation('TITLE_BLOCK_OVERLAP', [primitive.id], `Primitive "${primitive.id}" intersects the title block.`));
31
+ }
32
+ }
33
+ for (let leftIndex = 0; leftIndex < ordered.length; leftIndex += 1) {
34
+ const left = ordered[leftIndex];
35
+ if (!left || left.primitiveType === 'section-box')
36
+ continue;
37
+ for (let rightIndex = leftIndex + 1; rightIndex < ordered.length; rightIndex += 1) {
38
+ const right = ordered[rightIndex];
39
+ if (!right || right.primitiveType === 'section-box')
40
+ continue;
41
+ if (!boundsOverlap(left.combinedBounds, right.combinedBounds))
42
+ continue;
43
+ const isText = TEXT_TYPES.has(left.primitiveType) || TEXT_TYPES.has(right.primitiveType);
44
+ result.push(violation(isText ? 'TEXT_OVERLAP' : 'COMPONENT_OVERLAP', [left.id, right.id], `Primitives "${left.id}" and "${right.id}" overlap.`));
45
+ }
46
+ }
47
+ for (const sectionBox of ordered.filter((item) => item.primitiveType === 'section-box')) {
48
+ const children = ordered.filter((item) => item.sectionId === sectionBox.sectionId && item.id !== sectionBox.id);
49
+ const childBounds = combineBounds(children.map((child) => child.combinedBounds));
50
+ if (childBounds && !boundsInside(childBounds, sectionBox.combinedBounds)) {
51
+ result.push(violation('SECTION_BOX_TOO_SMALL', [sectionBox.id, ...children.map((child) => child.id)], `Section box "${sectionBox.id}" does not enclose all section content.`));
52
+ }
53
+ }
54
+ return result.sort((a, b) => a.id.localeCompare(b.id));
55
+ }
56
+ function propertyAllowed(primitive, property, allowlist) {
57
+ if (primitive.locked || ELECTRICAL_TYPES.has(primitive.primitiveType))
58
+ return false;
59
+ if (!allowlist.primitiveTypes.includes(primitive.primitiveType))
60
+ return false;
61
+ if (!allowlist.properties.includes(property))
62
+ return false;
63
+ if (property === 'bounds')
64
+ return primitive.primitiveType === 'section-box';
65
+ return primitive.primitiveType !== 'section-box';
66
+ }
67
+ function primitiveRegions(primitives, excludedIds) {
68
+ return primitives
69
+ .filter((primitive) => !excludedIds.has(primitive.id))
70
+ .map((primitive) => ({
71
+ id: `primitive:${primitive.id}`,
72
+ kind: 'existing-object',
73
+ primitiveId: primitive.id,
74
+ bounds: primitive.combinedBounds,
75
+ }));
76
+ }
77
+ function moveForViolation(input, target, issue) {
78
+ const check = checkPlacement({
79
+ sheet: input.sheet,
80
+ candidate: {
81
+ origin: target.origin,
82
+ rotation: 0,
83
+ combinedBounds: target.combinedBounds,
84
+ },
85
+ hardKeepouts: input.hardKeepouts,
86
+ reservedRegions: input.callerReservedRegions,
87
+ occupiedRegions: primitiveRegions(input.primitives, new Set([target.id])),
88
+ minimumClearance: input.minimumClearance,
89
+ maxAlternatives: 1,
90
+ searchPreference: 'upper-left',
91
+ });
92
+ const alternative = check.suggestedAlternatives[0];
93
+ if (!alternative)
94
+ return undefined;
95
+ return {
96
+ id: `autofix:${issue.id}:${target.id}`,
97
+ primitiveId: target.id,
98
+ primitiveType: target.primitiveType,
99
+ property: 'position',
100
+ from: target.origin,
101
+ to: alternative.origin,
102
+ reason: issue.message,
103
+ expectedQaImprovement: `Resolve ${issue.code} while preserving rendered clearance constraints.`,
104
+ resolvesViolationIds: [issue.id],
105
+ };
106
+ }
107
+ function resizeSectionBox(input, target, issue) {
108
+ const children = input.primitives.filter((item) => item.sectionId === target.sectionId && item.id !== target.id);
109
+ const childBounds = combineBounds(children.map((child) => child.combinedBounds));
110
+ if (!childBounds)
111
+ return undefined;
112
+ const proposed = inflateBounds(childBounds, Math.max(0, input.minimumClearance ?? input.sheet.grid));
113
+ if (!boundsInside(proposed, input.sheet.drawableBounds))
114
+ return undefined;
115
+ if (input.sheet.titleBlockBounds && boundsOverlap(proposed, input.sheet.titleBlockBounds))
116
+ return undefined;
117
+ return {
118
+ id: `autofix:${issue.id}:${target.id}`,
119
+ primitiveId: target.id,
120
+ primitiveType: target.primitiveType,
121
+ property: 'bounds',
122
+ from: target.combinedBounds,
123
+ to: proposed,
124
+ reason: issue.message,
125
+ expectedQaImprovement: 'Resize the cosmetic section box to enclose its section content.',
126
+ resolvesViolationIds: [issue.id],
127
+ };
128
+ }
129
+ function moveTarget(issue, primitives, allowlist) {
130
+ const candidates = issue.primitiveIds
131
+ .map((id) => primitives.get(id))
132
+ .filter((item) => item !== undefined)
133
+ .filter((item) => propertyAllowed(item, 'position', allowlist));
134
+ return candidates.sort((a, b) => {
135
+ const aText = TEXT_TYPES.has(a.primitiveType) ? 0 : 1;
136
+ const bText = TEXT_TYPES.has(b.primitiveType) ? 0 : 1;
137
+ return aText - bText || b.id.localeCompare(a.id);
138
+ })[0];
139
+ }
140
+ export function previewLayoutAutofix(input) {
141
+ const violations = detectViolations(input);
142
+ const byId = new Map(input.primitives.map((primitive) => [primitive.id, primitive]));
143
+ const moves = [];
144
+ const skipped = [];
145
+ const maxMoves = Math.max(0, input.maxMoves ?? 100);
146
+ const movedIds = new Set();
147
+ for (const issue of violations) {
148
+ if (moves.length >= maxMoves) {
149
+ skipped.push({
150
+ violationId: issue.id,
151
+ reason: 'The configured autofix move limit was reached.',
152
+ });
153
+ continue;
154
+ }
155
+ const sectionBox = issue.code === 'SECTION_BOX_TOO_SMALL'
156
+ ? issue.primitiveIds
157
+ .map((id) => byId.get(id))
158
+ .find((item) => item?.primitiveType === 'section-box')
159
+ : undefined;
160
+ let move;
161
+ if (sectionBox && propertyAllowed(sectionBox, 'bounds', input.allowlist)) {
162
+ move = resizeSectionBox(input, sectionBox, issue);
163
+ }
164
+ else {
165
+ const target = moveTarget(issue, byId, input.allowlist);
166
+ if (target && !movedIds.has(target.id))
167
+ move = moveForViolation(input, target, issue);
168
+ }
169
+ if (move) {
170
+ moves.push(move);
171
+ movedIds.add(move.primitiveId);
172
+ }
173
+ else {
174
+ skipped.push({
175
+ violationId: issue.id,
176
+ reason: 'No explicitly allowed cosmetic change can resolve this violation safely.',
177
+ });
178
+ }
179
+ }
180
+ const proposed = new Set(moves.flatMap((move) => move.resolvesViolationIds));
181
+ return {
182
+ mode: 'preview',
183
+ requiresConfirmWrite: true,
184
+ violations,
185
+ moves,
186
+ report: {
187
+ fixed: [],
188
+ skipped,
189
+ remaining: violations.filter((issue) => !proposed.has(issue.id)).map((issue) => issue.id),
190
+ },
191
+ allowlist: {
192
+ primitiveTypes: [...input.allowlist.primitiveTypes],
193
+ properties: [...input.allowlist.properties],
194
+ },
195
+ };
196
+ }
197
+ function defaultOperationFactory(move, index) {
198
+ const input = {
199
+ primitiveId: move.primitiveId,
200
+ cosmeticOnly: true,
201
+ changes: move.property === 'position' ? { position: move.to } : { bounds: move.to },
202
+ };
203
+ return {
204
+ operationId: operationId('modifyComponent', input, index),
205
+ kind: 'modifyComponent',
206
+ input,
207
+ targetPrimitiveIds: [move.primitiveId],
208
+ order: index,
209
+ };
210
+ }
211
+ function batches(items, size) {
212
+ const result = [];
213
+ for (let index = 0; index < items.length; index += size) {
214
+ result.push(items.slice(index, index + size));
215
+ }
216
+ return result;
217
+ }
218
+ function appliedReport(preview) {
219
+ const fixed = [...new Set(preview.moves.flatMap((move) => move.resolvesViolationIds))].sort((a, b) => a.localeCompare(b));
220
+ return {
221
+ fixed,
222
+ skipped: preview.report.skipped,
223
+ remaining: preview.violations
224
+ .filter((issue) => !fixed.includes(issue.id))
225
+ .map((issue) => issue.id),
226
+ };
227
+ }
228
+ async function stableConnectivityRead(reader, options) {
229
+ const read = await readStable(reader, {
230
+ ...options,
231
+ fingerprint: options?.fingerprint ?? ((value) => value.hash),
232
+ });
233
+ if (!read.stable)
234
+ throw new Error('Connectivity readback did not stabilize.');
235
+ return read.value;
236
+ }
237
+ export async function applyLayoutAutofix(preview, options) {
238
+ if (!options.confirmWrite) {
239
+ return {
240
+ applied: false,
241
+ preview,
242
+ batchesVerified: 0,
243
+ actualStateReadAfterFailure: false,
244
+ report: preview.report,
245
+ };
246
+ }
247
+ const beforeFingerprint = await stableConnectivityRead(options.readConnectivity, options.stableRead);
248
+ if (preview.moves.length === 0) {
249
+ return {
250
+ applied: false,
251
+ preview,
252
+ beforeFingerprint,
253
+ afterFingerprint: beforeFingerprint,
254
+ connectivityDiff: compareConnectivityFingerprints(beforeFingerprint, beforeFingerprint),
255
+ batchesVerified: 0,
256
+ actualStateReadAfterFailure: false,
257
+ report: preview.report,
258
+ };
259
+ }
260
+ const operationFactory = options.operationFactory ?? defaultOperationFactory;
261
+ const operations = preview.moves.map((move, index) => operationFactory(move, index));
262
+ const operationBatches = batches(operations, Math.max(1, options.batchSize ?? 20));
263
+ const started = options.transactionManager.begin({
264
+ documentId: options.documentId,
265
+ label: 'schematic-layout-autofix',
266
+ });
267
+ const bridge = options.bridge;
268
+ let verified = 0;
269
+ let lastFingerprint = beforeFingerprint;
270
+ try {
271
+ for (const batch of operationBatches) {
272
+ for (const operation of batch) {
273
+ const targetId = operation.targetPrimitiveIds?.[0];
274
+ if (!targetId) {
275
+ throw new Error(`Operation ${operation.operationId} has no target primitive.`);
276
+ }
277
+ const changes = operation.input.changes;
278
+ await options.transactionManager.runModify(started.id, targetId, {
279
+ getSnapshot: () => getPrimitiveSnapshot(bridge, targetId),
280
+ apply: () => bridge.call('schematic.modifyPrimitive', { primitiveId: targetId, property: changes }),
281
+ restore: (snapshot) => bridge.call('schematic.restorePrimitiveSnapshot', { snapshot }),
282
+ });
283
+ }
284
+ lastFingerprint = await stableConnectivityRead(options.readConnectivity, options.stableRead);
285
+ const diff = compareConnectivityFingerprints(beforeFingerprint, lastFingerprint);
286
+ if (!diff.equal) {
287
+ await rollbackEasyedaTransaction(options.transactionManager, started.id, bridge);
288
+ const result = {
289
+ applied: false,
290
+ transaction: options.transactionManager.get(started.id),
291
+ preview,
292
+ beforeFingerprint,
293
+ afterFingerprint: lastFingerprint,
294
+ connectivityDiff: diff,
295
+ batchesVerified: verified,
296
+ actualStateReadAfterFailure: true,
297
+ report: preview.report,
298
+ };
299
+ throw new LayoutAutofixConnectivityError('Layout autofix changed electrical connectivity; the transaction was rolled back.', result);
300
+ }
301
+ verified += 1;
302
+ }
303
+ await options.transactionManager.validate(started.id, []);
304
+ const transaction = options.transactionManager.commit(started.id);
305
+ const diff = compareConnectivityFingerprints(beforeFingerprint, lastFingerprint);
306
+ return {
307
+ applied: true,
308
+ transaction,
309
+ preview,
310
+ beforeFingerprint,
311
+ afterFingerprint: lastFingerprint,
312
+ connectivityDiff: diff,
313
+ batchesVerified: verified,
314
+ actualStateReadAfterFailure: false,
315
+ report: appliedReport(preview),
316
+ };
317
+ }
318
+ catch (error) {
319
+ if (error instanceof LayoutAutofixConnectivityError)
320
+ throw error;
321
+ let actualStateReadAfterFailure = false;
322
+ let afterFingerprint = lastFingerprint;
323
+ try {
324
+ afterFingerprint = await options.readConnectivity();
325
+ actualStateReadAfterFailure = true;
326
+ }
327
+ catch {
328
+ // Preserve the original write/transaction failure when readback is also unavailable.
329
+ }
330
+ try {
331
+ await rollbackEasyedaTransaction(options.transactionManager, started.id, bridge);
332
+ }
333
+ catch {
334
+ // The manager may already have rolled back after an apply timeout or adapter failure.
335
+ }
336
+ const diff = compareConnectivityFingerprints(beforeFingerprint, afterFingerprint);
337
+ const result = {
338
+ applied: false,
339
+ transaction: options.transactionManager.get(started.id),
340
+ preview,
341
+ beforeFingerprint,
342
+ afterFingerprint,
343
+ connectivityDiff: diff,
344
+ batchesVerified: verified,
345
+ actualStateReadAfterFailure,
346
+ report: preview.report,
347
+ };
348
+ throw new LayoutAutofixConnectivityError(error instanceof Error ? error.message : 'Layout autofix failed.', result);
349
+ }
350
+ }
351
+ export function applyPreviewMovesToGeometry(primitives, preview) {
352
+ const moveById = new Map(preview.moves.map((move) => [move.primitiveId, move]));
353
+ return primitives.map((primitive) => {
354
+ const move = moveById.get(primitive.id);
355
+ if (!move)
356
+ return {
357
+ ...primitive,
358
+ origin: { ...primitive.origin },
359
+ combinedBounds: { ...primitive.combinedBounds },
360
+ };
361
+ if (move.property === 'bounds') {
362
+ const bounds = move.to;
363
+ return { ...primitive, origin: { x: bounds.x, y: bounds.y }, combinedBounds: { ...bounds } };
364
+ }
365
+ const origin = move.to;
366
+ return {
367
+ ...primitive,
368
+ origin: { ...origin },
369
+ combinedBounds: translateBounds(primitive.combinedBounds, {
370
+ x: origin.x - primitive.origin.x,
371
+ y: origin.y - primitive.origin.y,
372
+ }),
373
+ };
374
+ });
375
+ }
376
+ //# sourceMappingURL=autofix.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autofix.js","sourceRoot":"","sources":["../../src/layout/autofix.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,aAAa,EACb,aAAa,EACb,aAAa,EACb,eAAe,GAIhB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,+BAA+B,GAGhC,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,UAAU,EAA0B,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,WAAW,EAA2B,MAAM,kCAAkC,CAAC;AACxF,OAAO,EACL,oBAAoB,EACpB,0BAA0B,GAE3B,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,cAAc,EAAkC,MAAM,gBAAgB,CAAC;AAuGhF,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IAG5C;IAFX,YACE,OAAe,EACN,MAAgC;QAEzC,KAAK,CAAC,OAAO,CAAC,CAAC;QAFN,WAAM,GAAN,MAAM,CAA0B;QAGzC,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;IAC/C,CAAC;CACF;AAED,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,CAAC;gBAChC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;aACjC,CAAC;SACH,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { DetectedFunctionalBlock, ExplicitFunctionalBlock, FunctionalBlockKind, LayoutComponentInput, SchematicLayoutGraph } from './types.js';
2
+ export declare function inferFunctionalBlockKind(component: LayoutComponentInput): FunctionalBlockKind;
3
+ export declare function detectFunctionalBlocks(components: readonly LayoutComponentInput[], graph: SchematicLayoutGraph, explicitBlocks?: readonly ExplicitFunctionalBlock[]): DetectedFunctionalBlock[];
@@ -0,0 +1,252 @@
1
+ import { compareIds } from './geometry.js';
2
+ const KIND_TITLES = {
3
+ 'power-input': 'Power Input',
4
+ regulation: 'Power Regulation',
5
+ mcu: 'Microcontroller',
6
+ memory: 'Memory',
7
+ crystal: 'Crystal and Clock',
8
+ usb: 'USB',
9
+ 'motor-driver': 'Motor Driver',
10
+ 'led-chain': 'LED Chain',
11
+ connector: 'Connectors',
12
+ debug: 'Debug',
13
+ sensor: 'Sensors',
14
+ 'analog-front-end': 'Analog Front End',
15
+ other: 'Other',
16
+ };
17
+ const KIND_PRIORITY = [
18
+ 'usb',
19
+ 'debug',
20
+ 'regulation',
21
+ 'power-input',
22
+ 'mcu',
23
+ 'memory',
24
+ 'crystal',
25
+ 'motor-driver',
26
+ 'led-chain',
27
+ 'sensor',
28
+ 'analog-front-end',
29
+ 'connector',
30
+ 'other',
31
+ ];
32
+ function searchableText(component) {
33
+ return [
34
+ component.reference,
35
+ component.value,
36
+ component.deviceName,
37
+ component.description,
38
+ component.category,
39
+ ...(component.tags ?? []),
40
+ ]
41
+ .filter((value) => typeof value === 'string')
42
+ .join(' ')
43
+ .toLowerCase();
44
+ }
45
+ function matchesAny(text, expressions) {
46
+ return expressions.some((expression) => expression.test(text));
47
+ }
48
+ export function inferFunctionalBlockKind(component) {
49
+ const text = searchableText(component);
50
+ const reference = component.reference.toUpperCase();
51
+ if (matchesAny(text, [/\busb(?:-?c)?\b/, /type[\s-]*c/, /usb connector/]))
52
+ return 'usb';
53
+ if (matchesAny(text, [/\bjtag\b/, /\bswd\b/, /debug/, /program(?:mer|ming) header/]))
54
+ return 'debug';
55
+ if (matchesAny(text, [
56
+ /\bldo\b/,
57
+ /regulat/,
58
+ /buck converter/,
59
+ /boost converter/,
60
+ /dc[- ]?dc/,
61
+ /ams1117/,
62
+ /tps62/,
63
+ ])) {
64
+ return 'regulation';
65
+ }
66
+ if (matchesAny(text, [
67
+ /power input/,
68
+ /barrel jack/,
69
+ /dc input/,
70
+ /mains input/,
71
+ /power entry/,
72
+ /battery input/,
73
+ ])) {
74
+ return 'power-input';
75
+ }
76
+ if (matchesAny(text, [
77
+ /microcontroller/,
78
+ /\bmcu\b/,
79
+ /rp2040/,
80
+ /stm32/,
81
+ /esp32/,
82
+ /atmega/,
83
+ /samd2/,
84
+ /nrf5/,
85
+ ])) {
86
+ return 'mcu';
87
+ }
88
+ if (matchesAny(text, [/\bflash\b/, /\beeprom\b/, /\bsram\b/, /\bmemory\b/, /w25q/, /qspi/])) {
89
+ return 'memory';
90
+ }
91
+ if (matchesAny(text, [/\bcrystal\b/, /\bxtal\b/, /oscillator/, /resonator/]) ||
92
+ /^[XY]\d+/i.test(reference)) {
93
+ return 'crystal';
94
+ }
95
+ if (matchesAny(text, [
96
+ /motor driver/,
97
+ /h[- ]?bridge/,
98
+ /drv8\d/,
99
+ /tb66/,
100
+ /stepper driver/,
101
+ /gate driver/,
102
+ ])) {
103
+ return 'motor-driver';
104
+ }
105
+ if (matchesAny(text, [/ws2812/, /neopixel/, /led chain/, /addressable led/]))
106
+ return 'led-chain';
107
+ if (matchesAny(text, [
108
+ /accelerometer/,
109
+ /gyroscope/,
110
+ /\bimu\b/,
111
+ /temperature sensor/,
112
+ /pressure sensor/,
113
+ /proximity sensor/,
114
+ /\bsensor\b/,
115
+ ])) {
116
+ return 'sensor';
117
+ }
118
+ if (matchesAny(text, [
119
+ /analog front[- ]?end/,
120
+ /\bop[- ]?amp\b/,
121
+ /instrumentation amplifier/,
122
+ /transimpedance/,
123
+ /\badc\b/,
124
+ /\bdac\b/,
125
+ ])) {
126
+ return 'analog-front-end';
127
+ }
128
+ if (matchesAny(text, [/connector/, /header/, /terminal block/, /\bjack\b/]) ||
129
+ /^(J|P|CN)\d+/i.test(reference)) {
130
+ return 'connector';
131
+ }
132
+ if (matchesAny(text, [/led/, /light emitting diode/]) || /^D\d+/i.test(reference))
133
+ return 'led-chain';
134
+ return 'other';
135
+ }
136
+ function dominantKind(components) {
137
+ const counts = new Map();
138
+ for (const component of components) {
139
+ const kind = inferFunctionalBlockKind(component);
140
+ counts.set(kind, (counts.get(kind) ?? 0) + 1);
141
+ }
142
+ return ([...counts.entries()].sort(([kindA, countA], [kindB, countB]) => countB - countA || KIND_PRIORITY.indexOf(kindA) - KIND_PRIORITY.indexOf(kindB))[0]?.[0] ?? 'other');
143
+ }
144
+ function inferredBlock(id, kind, componentIds, confidence) {
145
+ return {
146
+ id,
147
+ kind,
148
+ title: KIND_TITLES[kind],
149
+ componentIds: [...componentIds].sort(compareIds),
150
+ source: 'inferred',
151
+ confidence,
152
+ locked: false,
153
+ preferredOrientation: kind === 'power-input' || kind === 'regulation' || kind === 'crystal'
154
+ ? 'vertical'
155
+ : 'horizontal',
156
+ };
157
+ }
158
+ function repeatSignature(block, componentById) {
159
+ if (block.source === 'explicit' || block.kind === 'other' || block.componentIds.length === 0) {
160
+ return undefined;
161
+ }
162
+ const anchorId = block.componentIds[0];
163
+ if (!anchorId)
164
+ return undefined;
165
+ const anchor = componentById.get(anchorId);
166
+ const part = (anchor?.deviceName ?? anchor?.value ?? anchor?.category ?? '').trim().toLowerCase();
167
+ return part ? `${block.kind}:${part}` : undefined;
168
+ }
169
+ export function detectFunctionalBlocks(components, graph, explicitBlocks = []) {
170
+ const componentById = new Map(components.map((component) => [component.id, component]));
171
+ const claimed = new Set();
172
+ const blocks = [];
173
+ for (const explicit of [...explicitBlocks].sort((a, b) => compareIds(a.id, b.id))) {
174
+ const componentIds = [...new Set(explicit.componentIds)]
175
+ .filter((componentId) => componentById.has(componentId) && !claimed.has(componentId))
176
+ .sort(compareIds);
177
+ if (componentIds.length === 0)
178
+ continue;
179
+ componentIds.forEach((componentId) => claimed.add(componentId));
180
+ blocks.push({
181
+ id: explicit.id,
182
+ kind: explicit.kind,
183
+ title: explicit.title ?? KIND_TITLES[explicit.kind],
184
+ sectionTitle: explicit.sectionTitle,
185
+ componentIds,
186
+ source: 'explicit',
187
+ confidence: 1,
188
+ locked: explicit.locked ?? false,
189
+ repeatedGroupId: explicit.repeatedGroupId,
190
+ preferredOrientation: explicit.preferredOrientation ?? 'horizontal',
191
+ });
192
+ }
193
+ const groupedByDeclaredBlock = new Map();
194
+ for (const component of components) {
195
+ if (claimed.has(component.id) || !component.blockId)
196
+ continue;
197
+ const grouped = groupedByDeclaredBlock.get(component.blockId) ?? [];
198
+ grouped.push(component);
199
+ groupedByDeclaredBlock.set(component.blockId, grouped);
200
+ }
201
+ for (const [blockId, members] of [...groupedByDeclaredBlock.entries()].sort(([a], [b]) => compareIds(a, b))) {
202
+ members.forEach((component) => claimed.add(component.id));
203
+ blocks.push(inferredBlock(`inferred:${blockId}`, dominantKind(members), members.map((component) => component.id), 0.9));
204
+ }
205
+ const anchorBlockByComponent = new Map();
206
+ for (const component of [...components].sort((a, b) => compareIds(a.id, b.id))) {
207
+ if (claimed.has(component.id))
208
+ continue;
209
+ const kind = inferFunctionalBlockKind(component);
210
+ if (kind === 'other')
211
+ continue;
212
+ const block = inferredBlock(`inferred:${kind}:${component.id}`, kind, [component.id], 0.82);
213
+ blocks.push(block);
214
+ anchorBlockByComponent.set(component.id, block);
215
+ claimed.add(component.id);
216
+ }
217
+ // Attach passive/helper parts to the nearest inferred anchor using the canonical graph.
218
+ for (const component of [...components].sort((a, b) => compareIds(a.id, b.id))) {
219
+ if (claimed.has(component.id))
220
+ continue;
221
+ const candidateBlocks = (graph.adjacency[component.id] ?? [])
222
+ .map((neighborId) => anchorBlockByComponent.get(neighborId))
223
+ .filter((block) => block !== undefined)
224
+ .sort((a, b) => KIND_PRIORITY.indexOf(a.kind) - KIND_PRIORITY.indexOf(b.kind) || compareIds(a.id, b.id));
225
+ const owner = candidateBlocks[0];
226
+ if (owner) {
227
+ owner.componentIds.push(component.id);
228
+ owner.componentIds.sort(compareIds);
229
+ }
230
+ else {
231
+ blocks.push(inferredBlock(`inferred:other:${component.id}`, 'other', [component.id], 0.35));
232
+ }
233
+ claimed.add(component.id);
234
+ }
235
+ const repeatBuckets = new Map();
236
+ for (const block of blocks) {
237
+ const signature = repeatSignature(block, componentById);
238
+ if (!signature)
239
+ continue;
240
+ const bucket = repeatBuckets.get(signature) ?? [];
241
+ bucket.push(block);
242
+ repeatBuckets.set(signature, bucket);
243
+ }
244
+ for (const [signature, repeated] of repeatBuckets) {
245
+ if (repeated.length < 2)
246
+ continue;
247
+ for (const block of repeated)
248
+ block.repeatedGroupId = `repeat:${signature}`;
249
+ }
250
+ return blocks.sort((a, b) => compareIds(a.id, b.id));
251
+ }
252
+ //# sourceMappingURL=block-detector.js.map