perfboard-designer-mcp 0.6.0 → 0.6.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 +1 -1
- package/dist/server.js +309 -146
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -101,7 +101,7 @@ the resource `perfboard://docs/guide` (`src/guide.ts`).
|
|
|
101
101
|
It also serves the format as **resources**: `perfboard://docs/project-file` (the project file
|
|
102
102
|
format, field by field), `perfboard://docs/share-links` (the link format), `perfboard://parts`
|
|
103
103
|
(the whole parts catalog as JSON), and example projects: `perfboard://examples/555-led-blinker` (a
|
|
104
|
-
555 LED blinker on a perfboard,
|
|
104
|
+
555 LED blinker on a perfboard, with bare-wire rails, a jumper and a link on the solder side) and
|
|
105
105
|
`perfboard://examples/555-led-blinker-stripboard` (the same circuit on a stripboard), read from
|
|
106
106
|
`../examples/`.
|
|
107
107
|
|
package/dist/server.js
CHANGED
|
@@ -95,7 +95,92 @@ var init_define_COMPONENT_ICONS = __esm({
|
|
|
95
95
|
var define_EXAMPLE_PROJECTS_default;
|
|
96
96
|
var init_define_EXAMPLE_PROJECTS = __esm({
|
|
97
97
|
"<define:EXAMPLE_PROJECTS>"() {
|
|
98
|
-
define_EXAMPLE_PROJECTS_default = { "555-led-blinker":
|
|
98
|
+
define_EXAMPLE_PROJECTS_default = { "555-led-blinker": `{
|
|
99
|
+
"version": 9,
|
|
100
|
+
"board": {"type": "perfboard", "cols": 20, "rows": 15},
|
|
101
|
+
"description": "An NE555 timer flashes a red LED about once a second from a 9 V battery, laid out the way the Learn guides suggest: https://perfboarddesigner.com/learn/\\n\\n**Power in.** The battery's leads go into the screw terminal J1 on the left edge, + at the top. D2 (1N4001) protects the circuit from a battery connected the wrong way round, and C3 (100 \xB5F) steadies the supply right where it comes in.\\n\\n**Rails.** Bare tinned wire on the solder side carries +9 V along the top and ground along the bottom, and a ground bus runs from J1 past C3 to U1.1.\\n\\n**The timer.** U1 sits in the middle, in an 8-pin socket, with C4 (100 nF) right across its supply pins U1.8 and U1.1. The red jumper ties U1.4 (reset) to +9 V. A short link under the socket, on the solder side, joins U1.2 to U1.6.\\n\\n**Timing.** R1 (1 k\u03A9), R2 (68 k\u03A9) and C1 (10 \xB5F) set the speed: about 0.48 s on and 0.47 s off. C2 (10 nF) keeps U1.5 quiet.\\n\\n**Output.** U1.3 lights D1 through R3 (470 \u03A9), at about 10 mA.\\n\\n**Mounting.** The four corners are kept clear for M3 screws.",
|
|
102
|
+
"pads": [
|
|
103
|
+
{"at": [1, 1], "note": "M3"},
|
|
104
|
+
{"at": [18, 1], "note": "M3"},
|
|
105
|
+
{"at": [1, 13], "note": "M3"},
|
|
106
|
+
{"at": [18, 13], "note": "M3"},
|
|
107
|
+
{"at": [1, 2], "note": "+9V"},
|
|
108
|
+
{"at": [1, 8], "note": "0V"}
|
|
109
|
+
],
|
|
110
|
+
"wires": [
|
|
111
|
+
{"from": [1, 4], "to": [3, 4], "kind": "solder"},
|
|
112
|
+
{"from": [1, 6], "to": [10, 5], "via": [[10, 6]], "kind": "solder"},
|
|
113
|
+
{"from": [3, 6], "to": [16, 12], "via": [[3, 12]], "kind": "solder"},
|
|
114
|
+
{"from": [7, 5], "to": [15, 2], "via": [[7, 2]], "kind": "solder"},
|
|
115
|
+
{"from": [7, 4], "to": [7, 5], "kind": "solder"},
|
|
116
|
+
{"from": [13, 2], "to": [13, 6], "kind": "solder"},
|
|
117
|
+
{"from": [10, 9], "to": [9, 2], "via": [[9, 9]], "color": "#ef4444"},
|
|
118
|
+
{"from": [10, 7], "to": [13, 8], "via": [[11, 7], [11, 8]], "color": "#facc15", "side": "bottom"},
|
|
119
|
+
{"from": [10, 8], "to": [8, 10], "via": [[8, 8]], "kind": "solder"},
|
|
120
|
+
{"from": [4, 10], "to": [4, 11], "kind": "solder"},
|
|
121
|
+
{"from": [13, 7], "to": [15, 6], "via": [[15, 7]], "kind": "solder"},
|
|
122
|
+
{"from": [13, 8], "to": [16, 11], "via": [[14, 8], [14, 11]], "kind": "solder"},
|
|
123
|
+
{"from": [13, 9], "to": [13, 10], "kind": "solder"}
|
|
124
|
+
],
|
|
125
|
+
"placedIcs": [
|
|
126
|
+
{"ref": "U1", "name": "NE555 Timer", "widthPin": 4, "heightPin": 4, "rotation": 0, "pinDescription": {"1": "GND", "2": "TRIG", "3": "OUT", "4": "RESET", "5": "CTRL", "6": "THRESH", "7": "DISCH", "8": "VCC"}, "at": [10, 6], "category": "ics.timers"}
|
|
127
|
+
],
|
|
128
|
+
"placedStandardComponents": [
|
|
129
|
+
{"ref": "D2", "definitionId": "diode", "from": [3, 4], "to": [7, 4], "value": "1N4001"},
|
|
130
|
+
{"ref": "C3", "definitionId": "electrolytic-capacitor", "from": [7, 6], "to": [7, 5], "value": "100u"},
|
|
131
|
+
{"ref": "C4", "definitionId": "ceramic-capacitor", "from": [10, 5], "to": [13, 5], "value": "100n"},
|
|
132
|
+
{"ref": "R1", "definitionId": "resistor", "from": [15, 2], "to": [15, 6], "value": "1k"},
|
|
133
|
+
{"ref": "R2", "definitionId": "resistor", "from": [15, 7], "to": [15, 11], "value": "68k"},
|
|
134
|
+
{"ref": "C1", "definitionId": "electrolytic-capacitor", "from": [16, 12], "to": [16, 11], "value": "10u"},
|
|
135
|
+
{"ref": "C2", "definitionId": "ceramic-capacitor", "from": [13, 10], "to": [13, 12], "value": "10n"},
|
|
136
|
+
{"ref": "R3", "definitionId": "resistor", "from": [8, 10], "to": [4, 10], "value": "470"},
|
|
137
|
+
{"ref": "D1", "definitionId": "led", "from": [4, 12], "to": [4, 11], "color": "red"}
|
|
138
|
+
],
|
|
139
|
+
"placedAdvancedComponents": [
|
|
140
|
+
{"ref": "J1", "definitionId": "screw-terminal-2", "at": [1, 4], "rotation": 90, "rows": 1, "cols": 1}
|
|
141
|
+
],
|
|
142
|
+
"customIcs": []
|
|
143
|
+
}
|
|
144
|
+
`, "555-led-blinker-stripboard": `{
|
|
145
|
+
"version": 3,
|
|
146
|
+
"board": {"type": "stripboard", "cols": 20, "rows": 15, "strips": "horizontal", "cuts": [[6, 3], [12, 6], [12, 7], [12, 8], [12, 9], [7, 5]]},
|
|
147
|
+
"description": "The same 555 LED blinker as the perfboard example, on stripboard: the strips run across the board and do most of the wiring, with a few links and cuts. Laid out the way the Learn guides suggest: https://perfboarddesigner.com/learn/stripboard-layout/\\n\\n**Strips.** From the top: +9 V, ground, the LED's strip, the chip's four rows, the timing strip and ground again.\\n\\n**Power in.** A 9 V battery clip plugs into J1 on the left, + at the top. D2 (1N4001) lies along the top strip across a cut, so current can only reach the circuit the right way round. C3 (100 \xB5F) and C4 (100 nF) sit across the two supply strips.\\n\\n**The chip.** U1 straddles four cuts, one under each pair of facing pins, so every pin has a strip of its own. Red links take U1.8 and U1.4 (reset) to +9 V, black links take U1.1 to both ground strips, and yellow links join U1.2 and U1.6 on the timing strip.\\n\\n**Timing.** R1 (1 k\u03A9), R2 (68 k\u03A9) and C1 (10 \xB5F) make the LED flash about once a second. C2 (10 nF) keeps U1.5 quiet.\\n\\n**Output.** R3 (470 \u03A9) feeds D1 from U1.3, at about 10 mA.\\n\\n**Mounting.** The corners are kept clear for M3 screws, a row away from any strip in use.",
|
|
148
|
+
"pads": [
|
|
149
|
+
{"at": [1, 1], "note": "M3"},
|
|
150
|
+
{"at": [18, 1], "note": "M3"},
|
|
151
|
+
{"at": [1, 13], "note": "M3"},
|
|
152
|
+
{"at": [18, 13], "note": "M3"},
|
|
153
|
+
{"at": [2, 3], "note": "+9V"},
|
|
154
|
+
{"at": [2, 4], "note": "0V"}
|
|
155
|
+
],
|
|
156
|
+
"wires": [
|
|
157
|
+
{"from": [15, 6], "to": [15, 3], "color": "#ef4444", "width": 4},
|
|
158
|
+
{"from": [10, 9], "to": [10, 3], "color": "#ef4444", "width": 4},
|
|
159
|
+
{"from": [8, 6], "to": [8, 4], "color": "#1f2937", "width": 4},
|
|
160
|
+
{"from": [7, 6], "to": [7, 11], "color": "#1f2937", "width": 4},
|
|
161
|
+
{"from": [9, 7], "to": [9, 10], "color": "#facc15", "width": 4},
|
|
162
|
+
{"from": [15, 8], "to": [15, 10], "color": "#facc15", "width": 4}
|
|
163
|
+
],
|
|
164
|
+
"placedIcs": [
|
|
165
|
+
{"ref": "U1", "name": "NE555 Timer", "widthPin": 4, "heightPin": 4, "rotation": 0, "pinDescription": {"1": "GND", "2": "TRIG", "3": "OUT", "4": "RESET", "5": "CTRL", "6": "THRESH", "7": "DISCH", "8": "VCC"}, "at": [11, 6], "category": "ics.timers"}
|
|
166
|
+
],
|
|
167
|
+
"placedStandardComponents": [
|
|
168
|
+
{"ref": "D2", "definitionId": "diode", "from": [4, 3], "to": [8, 3], "value": "1N4001"},
|
|
169
|
+
{"ref": "C3", "definitionId": "electrolytic-capacitor", "from": [9, 4], "to": [9, 3], "value": "100u"},
|
|
170
|
+
{"ref": "C4", "definitionId": "ceramic-capacitor", "from": [13, 4], "to": [13, 3], "value": "100n"},
|
|
171
|
+
{"ref": "R1", "definitionId": "resistor", "from": [16, 3], "to": [16, 7], "value": "1k"},
|
|
172
|
+
{"ref": "R2", "definitionId": "resistor", "from": [17, 7], "to": [17, 10], "value": "68k"},
|
|
173
|
+
{"ref": "C1", "definitionId": "electrolytic-capacitor", "from": [13, 11], "to": [13, 10], "value": "10u"},
|
|
174
|
+
{"ref": "C2", "definitionId": "ceramic-capacitor", "from": [16, 9], "to": [16, 11], "value": "10n"},
|
|
175
|
+
{"ref": "R3", "definitionId": "resistor", "from": [6, 8], "to": [6, 5], "value": "470"},
|
|
176
|
+
{"ref": "D1", "definitionId": "led", "from": [5, 4], "to": [5, 5], "color": "red"}
|
|
177
|
+
],
|
|
178
|
+
"placedAdvancedComponents": [
|
|
179
|
+
{"ref": "J1", "definitionId": "header-pins", "at": [3, 3], "rotation": 0, "rows": 2, "cols": 1}
|
|
180
|
+
],
|
|
181
|
+
"customIcs": []
|
|
182
|
+
}
|
|
183
|
+
` };
|
|
99
184
|
}
|
|
100
185
|
});
|
|
101
186
|
|
|
@@ -38129,7 +38214,7 @@ Rules: holes are [column, row] from the top-left hole, from 0, 2.54 mm apart. A
|
|
|
38129
38214
|
The full guide, with more on all this and on changing a board the user shares (read_share_link): the resource perfboard://docs/guide.`;
|
|
38130
38215
|
var GUIDE = `# Designing a board with Perfboard Designer
|
|
38131
38216
|
|
|
38132
|
-
Perfboard Designer (https://perfboarddesigner.com) is a browser editor for perfboard and stripboard layouts. With these tools you design a board as a project file (JSON through version
|
|
38217
|
+
Perfboard Designer (https://perfboarddesigner.com) is a browser editor for perfboard and stripboard layouts. With these tools you design a board as a project file (JSON through version 11) and give the user a link that opens it in the editor. Parts may carry an instanceId; version 8 adds optional requirements (independent intended nets, unused pins, component snapshots and a validate flag). Preserve these when editing. Requirement connections never derive from the board's wiring. When requirements.validate is true, validation also reports missing components/pins, missing or unexpected connections, and incomplete pin coverage. Unspecified pins are unchecked, not assumed disconnected; this differs from the existing complete-list expectNets contract. New parts join the requirement inventory unconnected; board changes must never overwrite intended nets. The goal is a board that's electrically right, looks neat and is easy to solder by hand: the user will build it.
|
|
38133
38218
|
|
|
38134
38219
|
## Workflow
|
|
38135
38220
|
|
|
@@ -38183,6 +38268,8 @@ When list_parts has nothing for a part, make it with add_part, then place more o
|
|
|
38183
38268
|
|
|
38184
38269
|
Name pins: wires and expectNets can then use the names ("M1.VCC", "Q1.B"), and get_nets shows them. The project file keeps each custom part whole in its placed part's "custom" (version 6) and each chip in "customIcs", so the user's editor adds them to its parts list when they open the board. A name already in the catalog is refused: use the catalog's part.
|
|
38185
38270
|
|
|
38271
|
+
A catalog connector's pins often mean something on the board: a JST whose pin 1 is +5V and pin 2 GND, a header whose pins are RS, EN, D4... Name one placed part's pins with update_part's \`pinNames\`, by pin number: \`{"op": "update_part", "ref": "J6", "pinNames": {"1": "+5V", "2": "GND"}}\`. Wires and expectNets can then use them ("J6.+5V"), get_nets shows them, and the board prints them by the pins. \`pinNames\` is the part's whole set: a pin left out goes by the catalog's name, "" shows a pin by its number, and {} gives the part back the catalog's names. Names are up to 24 characters, for pins the part has. Only that part is renamed: the catalog entry and other copies keep theirs.
|
|
38272
|
+
|
|
38186
38273
|
## Describing the board
|
|
38187
38274
|
|
|
38188
38275
|
edit_project's set_description op saves a description in the project: what the board does, how it works and anything a builder should know, such as the supply voltage, a part to substitute or what to check first. Keep it short and true to the board, and refer to parts by their refs, exactly as the board has them, and to pins as you'd wire them ("R1 and C1 set the blink rate", "U1.8"): readers can then find each one on the board. It takes a small part of Markdown, with no raw HTML or images: # headings, - and 1. lists, **bold**, *italic*, \`code\`, [links](https://...). A board the user shares may have one already: keep it, and change it only when the board's change makes it wrong or they ask. With a description, make_share_link also returns "page", the same link opening a page to read with the board, its description, parts and nets: the one for the user to send to others.
|
|
@@ -38233,7 +38320,7 @@ function holesAlong(px) {
|
|
|
38233
38320
|
init_define_COMPONENT_ICONS();
|
|
38234
38321
|
init_define_EXAMPLE_PROJECTS();
|
|
38235
38322
|
init_define_PNG_FONTS();
|
|
38236
|
-
var PROJECT_FILE_VERSION =
|
|
38323
|
+
var PROJECT_FILE_VERSION = 11;
|
|
38237
38324
|
function fileVersionFor(project) {
|
|
38238
38325
|
if (project.wires.some((wire) => wire.side === "bottom")) return 9;
|
|
38239
38326
|
if (project.requirements) return 8;
|
|
@@ -39739,6 +39826,118 @@ function getAdvancedComponentDefinition(id) {
|
|
|
39739
39826
|
return ADVANCED_COMPONENT_DEFINITIONS.find((def) => def.id === id);
|
|
39740
39827
|
}
|
|
39741
39828
|
|
|
39829
|
+
// ../src/parts/pin-names.ts
|
|
39830
|
+
init_define_COMPONENT_ICONS();
|
|
39831
|
+
init_define_EXAMPLE_PROJECTS();
|
|
39832
|
+
init_define_PNG_FONTS();
|
|
39833
|
+
|
|
39834
|
+
// ../src/parts/part-geometry.ts
|
|
39835
|
+
init_define_COMPONENT_ICONS();
|
|
39836
|
+
init_define_EXAMPLE_PROJECTS();
|
|
39837
|
+
init_define_PNG_FONTS();
|
|
39838
|
+
|
|
39839
|
+
// ../src/parts/rotate-offset.ts
|
|
39840
|
+
init_define_COMPONENT_ICONS();
|
|
39841
|
+
init_define_EXAMPLE_PROJECTS();
|
|
39842
|
+
init_define_PNG_FONTS();
|
|
39843
|
+
function rotateOffset(dx, dy, angle) {
|
|
39844
|
+
switch (angle) {
|
|
39845
|
+
case 90:
|
|
39846
|
+
return { x: -dy, y: dx };
|
|
39847
|
+
case 180:
|
|
39848
|
+
return { x: -dx, y: -dy };
|
|
39849
|
+
case 270:
|
|
39850
|
+
return { x: dy, y: -dx };
|
|
39851
|
+
default:
|
|
39852
|
+
return { x: dx, y: dy };
|
|
39853
|
+
}
|
|
39854
|
+
}
|
|
39855
|
+
|
|
39856
|
+
// ../src/parts/part-geometry.ts
|
|
39857
|
+
var BODY_PAD = 0.32;
|
|
39858
|
+
function boxAround(points, pad) {
|
|
39859
|
+
const xs = points.map((p2) => p2.x);
|
|
39860
|
+
const ys = points.map((p2) => p2.y);
|
|
39861
|
+
return { left: Math.min(...xs) - pad, top: Math.min(...ys) - pad, right: Math.max(...xs) + pad, bottom: Math.max(...ys) + pad };
|
|
39862
|
+
}
|
|
39863
|
+
function advancedPinOffsets(def, rows, cols) {
|
|
39864
|
+
if (!def.gridSizable) return def.pinOffsets;
|
|
39865
|
+
const offsets = [];
|
|
39866
|
+
for (let row = 0; row < rows; row++) {
|
|
39867
|
+
for (let col = 0; col < cols; col++) offsets.push({ dx: col, dy: row });
|
|
39868
|
+
}
|
|
39869
|
+
return offsets;
|
|
39870
|
+
}
|
|
39871
|
+
function advancedPinCount(def, rows, cols) {
|
|
39872
|
+
return def.gridSizable ? rows * cols : def.pinOffsets.length;
|
|
39873
|
+
}
|
|
39874
|
+
function advancedPartShape(def, part) {
|
|
39875
|
+
const place = (offsets) => offsets.map(({ dx, dy }) => {
|
|
39876
|
+
const r2 = rotateOffset(dx, dy, part.rotation);
|
|
39877
|
+
return { x: part.at[0] + r2.x, y: part.at[1] + r2.y };
|
|
39878
|
+
});
|
|
39879
|
+
const pins = place(advancedPinOffsets(def, part.rows, part.cols));
|
|
39880
|
+
const covered = place(def.shadedOffsets ?? []);
|
|
39881
|
+
let outline = [];
|
|
39882
|
+
if (def.gridSizable) {
|
|
39883
|
+
const left = -PIN_TILE_HALF, top = -PIN_TILE_HALF;
|
|
39884
|
+
const right = part.cols - 1 + PIN_TILE_HALF, bottom = part.rows - 1 + PIN_TILE_HALF;
|
|
39885
|
+
outline = place([{ dx: left, dy: top }, { dx: right, dy: top }, { dx: right, dy: bottom }, { dx: left, dy: bottom }]);
|
|
39886
|
+
} else if (def.bodyOutline) {
|
|
39887
|
+
outline = place(def.bodyOutline);
|
|
39888
|
+
}
|
|
39889
|
+
let iconAnchor;
|
|
39890
|
+
if (def.iconOffset) {
|
|
39891
|
+
iconAnchor = place([def.iconOffset])[0];
|
|
39892
|
+
} else {
|
|
39893
|
+
const box = boxAround(pins, 0);
|
|
39894
|
+
iconAnchor = { x: (box.left + box.right) / 2, y: (box.top + box.bottom) / 2 };
|
|
39895
|
+
}
|
|
39896
|
+
const body = outline.length >= 3 ? boxAround(outline, 0) : boxAround([...pins, ...covered], BODY_PAD);
|
|
39897
|
+
return { pins, covered, outline, iconAnchor, body };
|
|
39898
|
+
}
|
|
39899
|
+
function icPins(ic) {
|
|
39900
|
+
const [left, top] = ic.at;
|
|
39901
|
+
const pins = [];
|
|
39902
|
+
if (ic.rotation === 0 || ic.rotation === 180) {
|
|
39903
|
+
const perSide = ic.heightPin;
|
|
39904
|
+
const right = left + ic.widthPin - 1;
|
|
39905
|
+
for (let i = 0; i < perSide; i++) {
|
|
39906
|
+
pins.push({ pin: ic.rotation === 0 ? i + 1 : perSide + 1 + i, at: [left, top + i], side: "left" });
|
|
39907
|
+
pins.push({ pin: ic.rotation === 0 ? perSide * 2 - i : perSide - i, at: [right, top + i], side: "right" });
|
|
39908
|
+
}
|
|
39909
|
+
} else {
|
|
39910
|
+
const perSide = ic.widthPin;
|
|
39911
|
+
const bottom = top + ic.heightPin - 1;
|
|
39912
|
+
for (let i = 0; i < perSide; i++) {
|
|
39913
|
+
pins.push({ pin: ic.rotation === 90 ? perSide - i : perSide * 2 - i, at: [left + i, top], side: "top" });
|
|
39914
|
+
pins.push({ pin: ic.rotation === 90 ? perSide + 1 + i : i + 1, at: [left + i, bottom], side: "bottom" });
|
|
39915
|
+
}
|
|
39916
|
+
}
|
|
39917
|
+
return pins.sort((a, b) => a.pin - b.pin);
|
|
39918
|
+
}
|
|
39919
|
+
|
|
39920
|
+
// ../src/parts/pin-names.ts
|
|
39921
|
+
var MAX_PIN_NAME_LENGTH = 24;
|
|
39922
|
+
function pinLabelsWith(def, names, pins) {
|
|
39923
|
+
if (!names || !Object.keys(names).length) return def.pinLabels;
|
|
39924
|
+
return Array.from({ length: pins }, (_2, i) => {
|
|
39925
|
+
const name = names[i + 1];
|
|
39926
|
+
return typeof name === "string" ? name : def.pinLabels?.[i] ?? "";
|
|
39927
|
+
});
|
|
39928
|
+
}
|
|
39929
|
+
function keptPinNames(names, def, pins) {
|
|
39930
|
+
const kept = {};
|
|
39931
|
+
for (const [key6, value] of Object.entries(names ?? {})) {
|
|
39932
|
+
const pin = Number(key6);
|
|
39933
|
+
if (!Number.isInteger(pin) || pin < 1 || pin > pins || typeof value !== "string") continue;
|
|
39934
|
+
const name = value.trim().slice(0, MAX_PIN_NAME_LENGTH);
|
|
39935
|
+
if (def && name === (def.pinLabels?.[pin - 1] ?? "")) continue;
|
|
39936
|
+
kept[pin] = name;
|
|
39937
|
+
}
|
|
39938
|
+
return Object.keys(kept).length ? kept : void 0;
|
|
39939
|
+
}
|
|
39940
|
+
|
|
39742
39941
|
// ../src/parts/custom-parts.ts
|
|
39743
39942
|
var CUSTOM_PART_ID = "custom";
|
|
39744
39943
|
var CUSTOM_REF_PREFIX = "M";
|
|
@@ -39828,6 +40027,11 @@ function moduleDefinition(spec) {
|
|
|
39828
40027
|
};
|
|
39829
40028
|
}
|
|
39830
40029
|
function advancedDefinitionFor(part) {
|
|
40030
|
+
const def = catalogDefinitionFor(part);
|
|
40031
|
+
if (!def || !part.pinDescription) return def;
|
|
40032
|
+
return { ...def, pinLabels: pinLabelsWith(def, part.pinDescription, advancedPinCount(def, part.rows ?? 1, part.cols ?? 1)) };
|
|
40033
|
+
}
|
|
40034
|
+
function catalogDefinitionFor(part) {
|
|
39831
40035
|
return part.custom ? customPartDefinition(part.custom) : getAdvancedComponentDefinition(part.definitionId);
|
|
39832
40036
|
}
|
|
39833
40037
|
|
|
@@ -39902,91 +40106,6 @@ init_define_PNG_FONTS();
|
|
|
39902
40106
|
init_define_COMPONENT_ICONS();
|
|
39903
40107
|
init_define_EXAMPLE_PROJECTS();
|
|
39904
40108
|
init_define_PNG_FONTS();
|
|
39905
|
-
|
|
39906
|
-
// ../src/parts/part-geometry.ts
|
|
39907
|
-
init_define_COMPONENT_ICONS();
|
|
39908
|
-
init_define_EXAMPLE_PROJECTS();
|
|
39909
|
-
init_define_PNG_FONTS();
|
|
39910
|
-
|
|
39911
|
-
// ../src/parts/rotate-offset.ts
|
|
39912
|
-
init_define_COMPONENT_ICONS();
|
|
39913
|
-
init_define_EXAMPLE_PROJECTS();
|
|
39914
|
-
init_define_PNG_FONTS();
|
|
39915
|
-
function rotateOffset(dx, dy, angle) {
|
|
39916
|
-
switch (angle) {
|
|
39917
|
-
case 90:
|
|
39918
|
-
return { x: -dy, y: dx };
|
|
39919
|
-
case 180:
|
|
39920
|
-
return { x: -dx, y: -dy };
|
|
39921
|
-
case 270:
|
|
39922
|
-
return { x: dy, y: -dx };
|
|
39923
|
-
default:
|
|
39924
|
-
return { x: dx, y: dy };
|
|
39925
|
-
}
|
|
39926
|
-
}
|
|
39927
|
-
|
|
39928
|
-
// ../src/parts/part-geometry.ts
|
|
39929
|
-
var BODY_PAD = 0.32;
|
|
39930
|
-
function boxAround(points, pad) {
|
|
39931
|
-
const xs = points.map((p2) => p2.x);
|
|
39932
|
-
const ys = points.map((p2) => p2.y);
|
|
39933
|
-
return { left: Math.min(...xs) - pad, top: Math.min(...ys) - pad, right: Math.max(...xs) + pad, bottom: Math.max(...ys) + pad };
|
|
39934
|
-
}
|
|
39935
|
-
function advancedPinOffsets(def, rows, cols) {
|
|
39936
|
-
if (!def.gridSizable) return def.pinOffsets;
|
|
39937
|
-
const offsets = [];
|
|
39938
|
-
for (let row = 0; row < rows; row++) {
|
|
39939
|
-
for (let col = 0; col < cols; col++) offsets.push({ dx: col, dy: row });
|
|
39940
|
-
}
|
|
39941
|
-
return offsets;
|
|
39942
|
-
}
|
|
39943
|
-
function advancedPartShape(def, part) {
|
|
39944
|
-
const place = (offsets) => offsets.map(({ dx, dy }) => {
|
|
39945
|
-
const r2 = rotateOffset(dx, dy, part.rotation);
|
|
39946
|
-
return { x: part.at[0] + r2.x, y: part.at[1] + r2.y };
|
|
39947
|
-
});
|
|
39948
|
-
const pins = place(advancedPinOffsets(def, part.rows, part.cols));
|
|
39949
|
-
const covered = place(def.shadedOffsets ?? []);
|
|
39950
|
-
let outline = [];
|
|
39951
|
-
if (def.gridSizable) {
|
|
39952
|
-
const left = -PIN_TILE_HALF, top = -PIN_TILE_HALF;
|
|
39953
|
-
const right = part.cols - 1 + PIN_TILE_HALF, bottom = part.rows - 1 + PIN_TILE_HALF;
|
|
39954
|
-
outline = place([{ dx: left, dy: top }, { dx: right, dy: top }, { dx: right, dy: bottom }, { dx: left, dy: bottom }]);
|
|
39955
|
-
} else if (def.bodyOutline) {
|
|
39956
|
-
outline = place(def.bodyOutline);
|
|
39957
|
-
}
|
|
39958
|
-
let iconAnchor;
|
|
39959
|
-
if (def.iconOffset) {
|
|
39960
|
-
iconAnchor = place([def.iconOffset])[0];
|
|
39961
|
-
} else {
|
|
39962
|
-
const box = boxAround(pins, 0);
|
|
39963
|
-
iconAnchor = { x: (box.left + box.right) / 2, y: (box.top + box.bottom) / 2 };
|
|
39964
|
-
}
|
|
39965
|
-
const body = outline.length >= 3 ? boxAround(outline, 0) : boxAround([...pins, ...covered], BODY_PAD);
|
|
39966
|
-
return { pins, covered, outline, iconAnchor, body };
|
|
39967
|
-
}
|
|
39968
|
-
function icPins(ic) {
|
|
39969
|
-
const [left, top] = ic.at;
|
|
39970
|
-
const pins = [];
|
|
39971
|
-
if (ic.rotation === 0 || ic.rotation === 180) {
|
|
39972
|
-
const perSide = ic.heightPin;
|
|
39973
|
-
const right = left + ic.widthPin - 1;
|
|
39974
|
-
for (let i = 0; i < perSide; i++) {
|
|
39975
|
-
pins.push({ pin: ic.rotation === 0 ? i + 1 : perSide + 1 + i, at: [left, top + i], side: "left" });
|
|
39976
|
-
pins.push({ pin: ic.rotation === 0 ? perSide * 2 - i : perSide - i, at: [right, top + i], side: "right" });
|
|
39977
|
-
}
|
|
39978
|
-
} else {
|
|
39979
|
-
const perSide = ic.widthPin;
|
|
39980
|
-
const bottom = top + ic.heightPin - 1;
|
|
39981
|
-
for (let i = 0; i < perSide; i++) {
|
|
39982
|
-
pins.push({ pin: ic.rotation === 90 ? perSide - i : perSide * 2 - i, at: [left + i, top], side: "top" });
|
|
39983
|
-
pins.push({ pin: ic.rotation === 90 ? perSide + 1 + i : i + 1, at: [left + i, bottom], side: "bottom" });
|
|
39984
|
-
}
|
|
39985
|
-
}
|
|
39986
|
-
return pins.sort((a, b) => a.pin - b.pin);
|
|
39987
|
-
}
|
|
39988
|
-
|
|
39989
|
-
// ../src/project-file/pin-positions.ts
|
|
39990
40109
|
var hole = (p2) => [Math.round(p2.x), Math.round(p2.y)];
|
|
39991
40110
|
function partPins(project) {
|
|
39992
40111
|
const parts = [];
|
|
@@ -40033,7 +40152,9 @@ function partPins(project) {
|
|
|
40033
40152
|
kind: "advanced-component",
|
|
40034
40153
|
part: part.custom?.name ?? part.definitionId,
|
|
40035
40154
|
known: true,
|
|
40036
|
-
|
|
40155
|
+
// Any pin with a name (its own, the definition's, or a pin block's renamed one) is labelled
|
|
40156
|
+
// with it, so the nets name it that way; a numbered pin is not.
|
|
40157
|
+
pins: shape.pins.map((p2, i) => ({ pin: i + 1, ...def.pinLabels?.[i] ? { label: def.pinLabels[i] } : {}, at: hole(p2) })),
|
|
40037
40158
|
coveredHoles: shape.covered.map(hole),
|
|
40038
40159
|
body: shape.body
|
|
40039
40160
|
});
|
|
@@ -40450,6 +40571,9 @@ function pinLabels(value) {
|
|
|
40450
40571
|
}
|
|
40451
40572
|
return labels;
|
|
40452
40573
|
}
|
|
40574
|
+
function pinNames(value, def, rows, cols) {
|
|
40575
|
+
return keptPinNames(pinLabels(value), def, def ? advancedPinCount(def, rows, cols) : Infinity);
|
|
40576
|
+
}
|
|
40453
40577
|
function readCustomIc(entry) {
|
|
40454
40578
|
const widthPin = wholeCount(entry.widthPin);
|
|
40455
40579
|
const heightPin = wholeCount(entry.heightPin);
|
|
@@ -40465,7 +40589,7 @@ function readCustomIc(entry) {
|
|
|
40465
40589
|
};
|
|
40466
40590
|
}
|
|
40467
40591
|
var REF_PREFIX = /^[A-Za-z]{1,4}$/;
|
|
40468
|
-
var MAX_LABEL_LENGTH =
|
|
40592
|
+
var MAX_LABEL_LENGTH = MAX_PIN_NAME_LENGTH;
|
|
40469
40593
|
function readCustomPart(value) {
|
|
40470
40594
|
const entry = asEntry(value);
|
|
40471
40595
|
if (!entry) return void 0;
|
|
@@ -40679,16 +40803,20 @@ function readGridFile(data, version2) {
|
|
|
40679
40803
|
const isCustom = version2 >= 6 && (entry.custom !== void 0 || definitionId === CUSTOM_PART_ID);
|
|
40680
40804
|
const custom2 = isCustom ? readCustomPart(entry.custom) : void 0;
|
|
40681
40805
|
if (isCustom && !custom2) return void 0;
|
|
40806
|
+
const rows2 = wholeCount(entry.rows) ?? 1;
|
|
40807
|
+
const cols2 = wholeCount(entry.cols) ?? 1;
|
|
40808
|
+
const def = catalogDefinitionFor({ definitionId, custom: custom2 });
|
|
40682
40809
|
return {
|
|
40683
40810
|
instanceId: text(entry.instanceId),
|
|
40684
40811
|
ref: text(entry.ref) ?? "",
|
|
40685
40812
|
definitionId: custom2 ? CUSTOM_PART_ID : definitionId,
|
|
40686
40813
|
at,
|
|
40687
40814
|
rotation: rotation(entry.rotation),
|
|
40688
|
-
rows:
|
|
40689
|
-
cols:
|
|
40815
|
+
rows: rows2,
|
|
40816
|
+
cols: cols2,
|
|
40690
40817
|
...optional2("value", text(entry.value)),
|
|
40691
|
-
...custom2 ? { custom: custom2 } : {}
|
|
40818
|
+
...custom2 ? { custom: custom2 } : {},
|
|
40819
|
+
...optional2("pinDescription", pinNames(entry.pinDescription, def, rows2, cols2))
|
|
40692
40820
|
};
|
|
40693
40821
|
});
|
|
40694
40822
|
const customIcs = r2.list(data.customIcs, readCustomIc);
|
|
@@ -40777,7 +40905,7 @@ function readProjectFile(raw) {
|
|
|
40777
40905
|
const data = asEntry(raw);
|
|
40778
40906
|
if (!data) throw new ProjectFileError(NOT_A_PROJECT);
|
|
40779
40907
|
if (data.version === void 0) return asEntry(data.board) ? readGridFile(data, PROJECT_FILE_VERSION) : readV1(data);
|
|
40780
|
-
if (data.version === 2 || data.version === 3 || data.version === 4 || data.version === 5 || data.version === 6 || data.version === 7 || data.version === 8 || data.version === 9 || data.version === 10) return readGridFile(data, data.version);
|
|
40908
|
+
if (data.version === 2 || data.version === 3 || data.version === 4 || data.version === 5 || data.version === 6 || data.version === 7 || data.version === 8 || data.version === 9 || data.version === 10 || data.version === 11) return readGridFile(data, data.version);
|
|
40781
40909
|
if (typeof data.version === "number" && data.version > PROJECT_FILE_VERSION) {
|
|
40782
40910
|
throw new ProjectFileError(
|
|
40783
40911
|
"This project was saved by a newer version of Perfboard Designer. Reload the page to get the latest version, then open it again."
|
|
@@ -40913,19 +41041,25 @@ function shorted(marks) {
|
|
|
40913
41041
|
if (sides.has("ground") && sides.has("negative")) return true;
|
|
40914
41042
|
return new Set(marks.flatMap((mark) => mark.volts === void 0 ? [] : [mark.volts])).size > 1;
|
|
40915
41043
|
}
|
|
41044
|
+
function pinMarks(project) {
|
|
41045
|
+
const own2 = new Map(project.placedAdvancedComponents.map((part) => [part.ref, catalogDefinitionFor(part)?.pinLabels]));
|
|
41046
|
+
return (pin) => (pin.kind === "advanced-component" ? own2.get(pin.ref)?.[pin.pin - 1] : pin.label)?.trim() ?? "";
|
|
41047
|
+
}
|
|
40916
41048
|
function railMarks(project, netlist) {
|
|
40917
41049
|
const marked = /* @__PURE__ */ new Map();
|
|
40918
41050
|
const add = (net, mark) => marked.set(net, [...marked.get(net) ?? [], mark]);
|
|
40919
|
-
const sources = new Set(project.placedAdvancedComponents.filter((part) =>
|
|
41051
|
+
const sources = new Set(project.placedAdvancedComponents.filter((part) => catalogDefinitionFor(part)?.powerSource).map((part) => part.ref));
|
|
41052
|
+
const markOf = pinMarks(project);
|
|
40920
41053
|
for (const net of netlist.nets) {
|
|
40921
41054
|
const terminals = [];
|
|
40922
41055
|
for (const pin of net.pins) {
|
|
40923
|
-
const
|
|
40924
|
-
if (sources.has(pin.ref) && (PLUS.test(
|
|
40925
|
-
const plus = PLUS.test(
|
|
41056
|
+
const mark = markOf(pin);
|
|
41057
|
+
if (sources.has(pin.ref) && (PLUS.test(mark) || MINUS.test(mark))) {
|
|
41058
|
+
const plus = PLUS.test(mark);
|
|
40926
41059
|
terminals.push({ side: plus ? "positive" : "ground", name: `${pin.ref}'s ${plus ? "+" : "\u2212"} terminal`, pin });
|
|
40927
41060
|
continue;
|
|
40928
41061
|
}
|
|
41062
|
+
const label = pin.label?.trim() ?? "";
|
|
40929
41063
|
const side = pin.kind === "standard-component" ? void 0 : railSide(label);
|
|
40930
41064
|
if (side) add(net, { side, volts: railVolts(label), name: label, pin });
|
|
40931
41065
|
}
|
|
@@ -40974,21 +41108,20 @@ var LEVEL = { negative: 0, ground: 1, positive: 2 };
|
|
|
40974
41108
|
function inSentence(name) {
|
|
40975
41109
|
return name.replace(/\s*\(.*\)\s*$/, "").split(" ").map((word) => /^[A-Z0-9-]+$/.test(word) ? word : word.toLowerCase()).join(" ");
|
|
40976
41110
|
}
|
|
40977
|
-
function endName(
|
|
40978
|
-
const label = pin.label?.trim() ?? "";
|
|
41111
|
+
function endName(label, lead) {
|
|
40979
41112
|
if (label === "A") return "anode (A)";
|
|
40980
41113
|
if (label === "K") return "cathode (K)";
|
|
40981
41114
|
return `${MINUS.test(label) ? "\u2212" : "+"} ${lead}`;
|
|
40982
41115
|
}
|
|
40983
|
-
var isPositiveEnd = (
|
|
40984
|
-
var isNegativeEnd = (
|
|
40985
|
-
function polarizedParts(project, netlist) {
|
|
41116
|
+
var isPositiveEnd = (mark) => mark === "A" || PLUS.test(mark);
|
|
41117
|
+
var isNegativeEnd = (mark) => mark === "K" || MINUS.test(mark);
|
|
41118
|
+
function polarizedParts(project, netlist, markOf) {
|
|
40986
41119
|
const pinsOf2 = /* @__PURE__ */ new Map();
|
|
40987
41120
|
for (const net of netlist.nets) for (const pin of net.pins) pinsOf2.set(pin.ref, [...pinsOf2.get(pin.ref) ?? [], pin]);
|
|
40988
41121
|
const ends2 = (ref) => {
|
|
40989
41122
|
const pins = pinsOf2.get(ref) ?? [];
|
|
40990
|
-
const positive = pins.filter(isPositiveEnd);
|
|
40991
|
-
const negative = pins.filter(isNegativeEnd);
|
|
41123
|
+
const positive = pins.filter((pin) => isPositiveEnd(markOf(pin)));
|
|
41124
|
+
const negative = pins.filter((pin) => isNegativeEnd(markOf(pin)));
|
|
40992
41125
|
return positive.length === 1 && negative.length === 1 ? [positive[0], negative[0]] : void 0;
|
|
40993
41126
|
};
|
|
40994
41127
|
const parts = [];
|
|
@@ -40996,7 +41129,7 @@ function polarizedParts(project, netlist) {
|
|
|
40996
41129
|
const def = getComponentDefinition(entry.definitionId);
|
|
40997
41130
|
const found = def?.leadLabels && ends2(entry.ref);
|
|
40998
41131
|
if (!def || !found) continue;
|
|
40999
|
-
const capacitor = PLUS.test(found[0]
|
|
41132
|
+
const capacitor = PLUS.test(markOf(found[0]));
|
|
41000
41133
|
parts.push({
|
|
41001
41134
|
ref: entry.ref,
|
|
41002
41135
|
kind: "standard-component",
|
|
@@ -41008,7 +41141,7 @@ function polarizedParts(project, netlist) {
|
|
|
41008
41141
|
});
|
|
41009
41142
|
}
|
|
41010
41143
|
for (const entry of project.placedAdvancedComponents) {
|
|
41011
|
-
const def =
|
|
41144
|
+
const def = catalogDefinitionFor(entry);
|
|
41012
41145
|
const found = def && !def.powerSource && ends2(entry.ref);
|
|
41013
41146
|
if (!def || !found) continue;
|
|
41014
41147
|
parts.push({
|
|
@@ -41028,7 +41161,8 @@ function polarityWarnings(project, netlist) {
|
|
|
41028
41161
|
const isTop = (rail) => !all.some((other) => other !== rail && other.level === "positive" && other.volts !== void 0 && (rail.volts === void 0 || other.volts > rail.volts));
|
|
41029
41162
|
const isBottom = (rail) => rail.level === "ground" ? !all.some((other) => other.level === "negative") : !all.some((other) => other !== rail && other.level === "negative" && other.volts !== void 0 && (rail.volts === void 0 || other.volts < rail.volts));
|
|
41030
41163
|
const warnings = [];
|
|
41031
|
-
|
|
41164
|
+
const markOf = pinMarks(project);
|
|
41165
|
+
for (const part of polarizedParts(project, netlist, markOf)) {
|
|
41032
41166
|
const [high, low] = part.ends;
|
|
41033
41167
|
const highNet = netlist.netAt(high.at);
|
|
41034
41168
|
const lowNet = netlist.netAt(low.at);
|
|
@@ -41036,8 +41170,8 @@ function polarityWarnings(project, netlist) {
|
|
|
41036
41170
|
const highRail = rails.get(highNet);
|
|
41037
41171
|
const lowRail = rails.get(lowNet);
|
|
41038
41172
|
const lead = part.kind === "standard-component" ? "lead" : "pin";
|
|
41039
|
-
const highEnd = endName(high, lead);
|
|
41040
|
-
const lowEnd = endName(low, lead);
|
|
41173
|
+
const highEnd = endName(markOf(high), lead);
|
|
41174
|
+
const lowEnd = endName(markOf(low), lead);
|
|
41041
41175
|
let problem;
|
|
41042
41176
|
let detail = "";
|
|
41043
41177
|
if (part.mustFace) {
|
|
@@ -41736,11 +41870,20 @@ function pinLabelSpot(g, i, rotation3) {
|
|
|
41736
41870
|
return { x: g.pins[i].x + shift.x * GRID_PITCH_PX, y: g.pins[i].y + shift.y * GRID_PITCH_PX };
|
|
41737
41871
|
}
|
|
41738
41872
|
var pinLabelText = (g, i) => g.def.pinLabels?.[i] || String(i + 1);
|
|
41873
|
+
function shownPinLabels(g, rotation3) {
|
|
41874
|
+
return g.pins.flatMap((_2, i) => {
|
|
41875
|
+
const text2 = g.def.perPinIcon ? g.def.pinLabels?.[i]?.trim() ?? "" : pinLabelText(g, i);
|
|
41876
|
+
return text2 ? [{ text: text2, at: pinLabelSpot(g, i, rotation3) }] : [];
|
|
41877
|
+
});
|
|
41878
|
+
}
|
|
41879
|
+
function drawPinLabel(painter, { text: text2, at }) {
|
|
41880
|
+
painter.text(text2, at.x, at.y, { font: PIN_LABEL_FONT, color: PIN_LABEL_COLOR, align: "center", baseline: "middle", halo: LABEL_HALO });
|
|
41881
|
+
}
|
|
41739
41882
|
function drawBodyShape(painter, g, style) {
|
|
41740
41883
|
if (g.outline.length >= 3) painter.polygon(g.outline, style);
|
|
41741
41884
|
else painter.rect(g.bodyRect.x, g.bodyRect.y, g.bodyRect.w, g.bodyRect.h, style);
|
|
41742
41885
|
}
|
|
41743
|
-
function drawTiledPins(painter, g, look) {
|
|
41886
|
+
function drawTiledPins(painter, g, rotation3, look) {
|
|
41744
41887
|
const tile = PIN_TILE_HALF * 2 * GRID_PITCH_PX;
|
|
41745
41888
|
const half = tile / 2;
|
|
41746
41889
|
for (const pin of g.pins) {
|
|
@@ -41754,6 +41897,7 @@ function drawTiledPins(painter, g, look) {
|
|
|
41754
41897
|
stroke: { paint: SELECTION_COLOR, width: look.selected ? 3 : 2, ...look.ghost ? { dash: GHOST_DASH } : {} }
|
|
41755
41898
|
});
|
|
41756
41899
|
}
|
|
41900
|
+
for (const label of shownPinLabels(g, rotation3)) drawPinLabel(painter, label);
|
|
41757
41901
|
}
|
|
41758
41902
|
function iconBox(painter, g, rect, quarterTurned) {
|
|
41759
41903
|
const boxW = quarterTurned ? rect.h : rect.w;
|
|
@@ -41801,16 +41945,7 @@ function drawBody(painter, g, rotation3, look) {
|
|
|
41801
41945
|
});
|
|
41802
41946
|
}
|
|
41803
41947
|
if (skipBody && look.selected) drawBodyShape(painter, g, { stroke: { paint: SELECTION_COLOR, width: 3 } });
|
|
41804
|
-
|
|
41805
|
-
const { x, y } = pinLabelSpot(g, i, rotation3);
|
|
41806
|
-
painter.text(pinLabelText(g, i), x, y, {
|
|
41807
|
-
font: PIN_LABEL_FONT,
|
|
41808
|
-
color: PIN_LABEL_COLOR,
|
|
41809
|
-
align: "center",
|
|
41810
|
-
baseline: "middle",
|
|
41811
|
-
halo: LABEL_HALO
|
|
41812
|
-
});
|
|
41813
|
-
});
|
|
41948
|
+
for (const label of shownPinLabels(g, rotation3)) drawPinLabel(painter, label);
|
|
41814
41949
|
}
|
|
41815
41950
|
var advancedArtist = {
|
|
41816
41951
|
layer: "over-wires",
|
|
@@ -41818,7 +41953,7 @@ var advancedArtist = {
|
|
|
41818
41953
|
const g = advancedPartGeometry(part);
|
|
41819
41954
|
if (!g || g.pins.length === 0) return;
|
|
41820
41955
|
painter.group(look.ghost ? { opacity: GHOST_OPACITY } : {}, () => {
|
|
41821
|
-
if (g.def.perPinIcon) drawTiledPins(painter, g, look);
|
|
41956
|
+
if (g.def.perPinIcon) drawTiledPins(painter, g, part.rotation, look);
|
|
41822
41957
|
else drawBody(painter, g, part.rotation, look);
|
|
41823
41958
|
});
|
|
41824
41959
|
},
|
|
@@ -41832,18 +41967,16 @@ var advancedArtist = {
|
|
|
41832
41967
|
painter.circle(pin.x, pin.y, PIN_MARKER_RADIUS, { fill: i === 0 ? PIN1_COLOR2 : PIN_COLOR });
|
|
41833
41968
|
});
|
|
41834
41969
|
},
|
|
41835
|
-
// The body, and the
|
|
41970
|
+
// The body, and the labels round its pins as far as the font reaches.
|
|
41836
41971
|
extent(part) {
|
|
41837
41972
|
const g = advancedPartGeometry(part);
|
|
41838
41973
|
if (!g) return void 0;
|
|
41839
41974
|
const { x, y, w: w2, h: h2 } = g.bodyRect;
|
|
41840
|
-
if (g.def.perPinIcon) return g.bodyRect;
|
|
41841
41975
|
const corners = [{ x, y }, { x: x + w2, y: y + h2 }];
|
|
41842
|
-
|
|
41843
|
-
const
|
|
41844
|
-
|
|
41845
|
-
|
|
41846
|
-
});
|
|
41976
|
+
for (const { text: text2, at } of shownPinLabels(g, part.rotation)) {
|
|
41977
|
+
const halfWidth = text2.length * PIN_LABEL_CHAR_HALF_WIDTH;
|
|
41978
|
+
corners.push({ x: at.x - halfWidth, y: at.y - PIN_LABEL_HALF_HEIGHT }, { x: at.x + halfWidth, y: at.y + PIN_LABEL_HALF_HEIGHT });
|
|
41979
|
+
}
|
|
41847
41980
|
return boundingRect(corners);
|
|
41848
41981
|
},
|
|
41849
41982
|
// Printed on the body where the package has room for it (valueLabelOffset), else below the
|
|
@@ -43986,7 +44119,7 @@ function registerCatalogTools(server) {
|
|
|
43986
44119
|
query: string2().optional().describe('Words to match, e.g. "capacitor", "555", "header", "relay". Leave it out to list every part.'),
|
|
43987
44120
|
kind: _enum2(["standard-component", "advanced-component", "ic"]).optional().describe("standard-component: two-lead parts placed between two holes. advanced-component: fixed-footprint parts. ic: dual-row chips and modules.")
|
|
43988
44121
|
},
|
|
43989
|
-
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
44122
|
+
annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false }
|
|
43990
44123
|
}, async ({ query, kind }) => {
|
|
43991
44124
|
if (!query?.trim()) {
|
|
43992
44125
|
const parts2 = searchParts(void 0, kind);
|
|
@@ -44004,7 +44137,7 @@ function registerCatalogTools(server) {
|
|
|
44004
44137
|
ids: array(string2()).optional().describe('Part ids from list_parts, e.g. ["resistor", "ne555", "header-pins"].'),
|
|
44005
44138
|
id: string2().optional().describe("One part id, instead of `ids`.")
|
|
44006
44139
|
},
|
|
44007
|
-
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
44140
|
+
annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false }
|
|
44008
44141
|
}, async ({ ids, id }) => {
|
|
44009
44142
|
const wanted = [...ids ?? [], ...id ? [id] : []];
|
|
44010
44143
|
if (!wanted.length) return failure2("Give `ids`: the part ids from list_parts.");
|
|
@@ -44033,11 +44166,11 @@ init_define_PNG_FONTS();
|
|
|
44033
44166
|
var EXAMPLES = {
|
|
44034
44167
|
"555-led-blinker": {
|
|
44035
44168
|
title: "555 LED blinker (perfboard)",
|
|
44036
|
-
description: "An NE555 astable flashing an LED about once a second, on a perfboard:
|
|
44169
|
+
description: "An NE555 astable flashing an LED about once a second from a 9 V battery, on a perfboard laid out as a model board: a screw terminal with a reverse-polarity diode and a bulk capacitor, bare-wire supply rails (solder paths) along the top and bottom, a decoupling capacitor right across the chip's supply pins, the timing parts in a column, a red jumper for reset and a link under the chip on the solder side."
|
|
44037
44170
|
},
|
|
44038
44171
|
"555-led-blinker-stripboard": {
|
|
44039
44172
|
title: "555 LED blinker (stripboard)",
|
|
44040
|
-
description: "The same 555 LED blinker on a stripboard with horizontal strips:
|
|
44173
|
+
description: "The same 555 LED blinker on a stripboard with horizontal strips: +9 V and ground strips paired at the top for the supply capacitors and a second ground strip at the bottom, the diode across a cut in the supply strip, cuts under the chip so its two pin rows aren't shorted, and six wire links."
|
|
44041
44174
|
}
|
|
44042
44175
|
};
|
|
44043
44176
|
var EXAMPLE_IDS = Object.keys(EXAMPLES);
|
|
@@ -44198,7 +44331,8 @@ var editOp = discriminatedUnion("op", [
|
|
|
44198
44331
|
cols: number2().int().min(1).optional(),
|
|
44199
44332
|
value: string2().optional().describe('"" removes it.'),
|
|
44200
44333
|
color: string2().optional().describe('"" removes it.'),
|
|
44201
|
-
newRef: string2().optional()
|
|
44334
|
+
newRef: string2().optional(),
|
|
44335
|
+
pinNames: record(string2(), string2()).optional().describe(`A fixed-pin part's own pin names, by pin number (1 to its pin count), each up to 24 characters: {"1": "+5V", "2": "GND"} on a JST connector or header. They replace the part's numbers or names on the board, in the nets ("J6.+5V") and in the list of unconnected pins. This is the whole set: a pin left out goes by the catalog's name, "" shows a pin by its number, and {} gives the part back the catalog's names. Only this part is renamed, never the catalog entry.`)
|
|
44202
44336
|
}),
|
|
44203
44337
|
object({ op: literal("remove_parts"), refs: array(string2()).min(1) }),
|
|
44204
44338
|
object({
|
|
@@ -44459,7 +44593,7 @@ function placedBy(project, op) {
|
|
|
44459
44593
|
}
|
|
44460
44594
|
var REF_LETTERS = /^[A-Z]{1,4}$/;
|
|
44461
44595
|
var MAX_NAME = 60;
|
|
44462
|
-
var MAX_PIN_NAME =
|
|
44596
|
+
var MAX_PIN_NAME = MAX_PIN_NAME_LENGTH;
|
|
44463
44597
|
function findCustomPart(project, name) {
|
|
44464
44598
|
const wanted = name.trim().toLowerCase();
|
|
44465
44599
|
return project.placedAdvancedComponents.find((part) => part.custom?.name.toLowerCase() === wanted)?.custom;
|
|
@@ -44616,7 +44750,7 @@ function updatePart(project, op, placed) {
|
|
|
44616
44750
|
const moved = (at) => [at[0] + by[0], at[1] + by[1]];
|
|
44617
44751
|
if (op.by && (op.at || op.from || op.to)) throw new OpError("Give `by` or new positions, not both.");
|
|
44618
44752
|
if (found.kind === "standard-component") {
|
|
44619
|
-
notFor("a two-lead part", op, ["at", "rotation", "rows", "cols"]);
|
|
44753
|
+
notFor("a two-lead part", op, ["at", "rotation", "rows", "cols", "pinNames"]);
|
|
44620
44754
|
const e = found.entry;
|
|
44621
44755
|
const from = op.from ?? moved(e.from);
|
|
44622
44756
|
const to = op.to ?? moved(e.to);
|
|
@@ -44649,9 +44783,12 @@ function updatePart(project, op, placed) {
|
|
|
44649
44783
|
found.entry.rows = op.rows ?? found.entry.rows;
|
|
44650
44784
|
found.entry.cols = op.cols ?? found.entry.cols;
|
|
44651
44785
|
said.push(`${found.entry.rows}\xD7${found.entry.cols}`);
|
|
44786
|
+
const lost = dropLostPinNames(found.entry);
|
|
44787
|
+
if (lost.length) said.push(`no names on ${plural2(lost.length, "pin")} it no longer has (${lost.join(", ")})`);
|
|
44652
44788
|
}
|
|
44789
|
+
if (op.pinNames !== void 0) said.push(namePins(found.ref, found.entry, op.pinNames));
|
|
44653
44790
|
} else {
|
|
44654
|
-
notFor("a chip", op, ["rows", "cols", "value"]);
|
|
44791
|
+
notFor("a chip", op, ["rows", "cols", "value", "pinNames"]);
|
|
44655
44792
|
}
|
|
44656
44793
|
}
|
|
44657
44794
|
if (op.value !== void 0 && found.kind !== "ic") {
|
|
@@ -44705,6 +44842,32 @@ function notFor(kind, op, fields) {
|
|
|
44705
44842
|
const given = fields.filter((field) => op[field] !== void 0);
|
|
44706
44843
|
if (given.length) throw new OpError(`${given.map((f2) => `\`${f2}\``).join(", ")} ${given.length === 1 ? "doesn't" : "don't"} apply to ${kind}.`);
|
|
44707
44844
|
}
|
|
44845
|
+
function namePins(ref, entry, given) {
|
|
44846
|
+
const def = catalogDefinitionFor(entry);
|
|
44847
|
+
if (!def) throw new OpError(`${ref} is a "${entry.definitionId}", which this server doesn't know, so its pins can't be named.`);
|
|
44848
|
+
const pins = advancedPinCount(def, entry.rows, entry.cols);
|
|
44849
|
+
for (const [pin, name] of Object.entries(given)) {
|
|
44850
|
+
const number4 = Number(pin);
|
|
44851
|
+
if (!Number.isInteger(number4) || number4 < 1 || number4 > pins) {
|
|
44852
|
+
throw new OpError(`\`pinNames\` keys are ${ref}'s pin numbers, 1 to ${pins}: "${pin}" isn't one.`);
|
|
44853
|
+
}
|
|
44854
|
+
checkedPinName(name, number4 - 1, "`pinNames`:");
|
|
44855
|
+
}
|
|
44856
|
+
setPinNames(entry, keptPinNames(given, def, pins));
|
|
44857
|
+
const named = Object.entries(entry.pinDescription ?? {});
|
|
44858
|
+
return named.length ? `pin names ${named.map(([pin, name]) => `${pin} ${name || "(its number)"}`).join(", ")}` : "the catalog's pin names";
|
|
44859
|
+
}
|
|
44860
|
+
function dropLostPinNames(entry) {
|
|
44861
|
+
const def = catalogDefinitionFor(entry);
|
|
44862
|
+
const named = Object.keys(entry.pinDescription ?? {}).map(Number);
|
|
44863
|
+
if (!def || !named.length) return [];
|
|
44864
|
+
setPinNames(entry, keptPinNames(entry.pinDescription, def, advancedPinCount(def, entry.rows, entry.cols)));
|
|
44865
|
+
return named.filter((pin) => entry.pinDescription?.[pin] === void 0);
|
|
44866
|
+
}
|
|
44867
|
+
function setPinNames(entry, names) {
|
|
44868
|
+
if (names) entry.pinDescription = names;
|
|
44869
|
+
else delete entry.pinDescription;
|
|
44870
|
+
}
|
|
44708
44871
|
var sideOf = (op) => op.side === "bottom" ? { side: "bottom" } : {};
|
|
44709
44872
|
function addWire(project, op) {
|
|
44710
44873
|
if (op.path && (op.from || op.to)) throw new OpError("Give either `path` or `from` and `to`, not both.");
|
|
@@ -45336,7 +45499,7 @@ function registerProjectTools(server) {
|
|
|
45336
45499
|
title: "Get project",
|
|
45337
45500
|
description: "The whole project file of a project kept here, as the editor would save it (through version 8, preserving component identities and optional requirements), one entry per line.",
|
|
45338
45501
|
inputSchema: { projectId: string2() },
|
|
45339
|
-
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
45502
|
+
annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false }
|
|
45340
45503
|
}, async ({ projectId }) => {
|
|
45341
45504
|
const held = await heldProject(projectId);
|
|
45342
45505
|
if (!held) return failure2(unknownProjectId(projectId));
|
|
@@ -46168,7 +46331,7 @@ function registerBoardTools(server) {
|
|
|
46168
46331
|
title: "Get nets",
|
|
46169
46332
|
description: `Which pins the board connects: every net with its name (from its pins, e.g. GND), its pins ("U1.8 VCC" for a chip's pin, "D1.K" or "C1.+" for a polarized lead, "R1.1" otherwise) and the wires on it (indexes into wires). Also pins connected to nothing, wires that connect no pins, junctions (holes where three or more things are joined) and crossings (where a wire goes over another wire or over a hole without joining it). Wires are insulated jumpers: a wire joins only the holes at its two ends, so crossings are information, not connections or shorts. On a stripboard the strips connect too.`,
|
|
46170
46333
|
inputSchema: { project: projectInput, projectId: projectIdInput },
|
|
46171
|
-
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
46334
|
+
annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false }
|
|
46172
46335
|
}, async ({ project, projectId }) => {
|
|
46173
46336
|
const from = await projectSource({ project, projectId });
|
|
46174
46337
|
if ("error" in from) return failure2(from.error);
|
|
@@ -46189,7 +46352,7 @@ function registerBoardTools(server) {
|
|
|
46189
46352
|
projectId: projectIdInput,
|
|
46190
46353
|
refs: array(string2()).optional().describe('Only these parts, e.g. ["U1", "R2"]. All parts when omitted.')
|
|
46191
46354
|
},
|
|
46192
|
-
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
46355
|
+
annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false }
|
|
46193
46356
|
}, async ({ project, projectId, refs }) => {
|
|
46194
46357
|
const from = await projectSource({ project, projectId });
|
|
46195
46358
|
if ("error" in from) return failure2(from.error);
|
|
@@ -46215,7 +46378,7 @@ function registerBoardTools(server) {
|
|
|
46215
46378
|
area: object({ from: holeInput, to: holeInput }).optional().describe("Only this part of the board: two opposite corner holes. The whole board when left out."),
|
|
46216
46379
|
format: _enum2(["text", "png"]).optional().describe('"text" (default): the board as text. "png": a picture of it, 50 px per hole, scaled down to fit 1000 px.')
|
|
46217
46380
|
},
|
|
46218
|
-
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
46381
|
+
annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false }
|
|
46219
46382
|
}, async ({ project, projectId, area, format }) => {
|
|
46220
46383
|
const from = await projectSource({ project, projectId });
|
|
46221
46384
|
if ("error" in from) return failure2(from.error);
|
|
@@ -46516,7 +46679,7 @@ function registerShowBoardTool(server, DEFAULT_EDITOR_URL) {
|
|
|
46516
46679
|
description: "The page show_board shows the board in.",
|
|
46517
46680
|
// The picture is a data: image, and the page loads nothing else.
|
|
46518
46681
|
_meta: { ui: { prefersBorder: false } }
|
|
46519
|
-
}, async (uri) => ({ contents: [{ uri: uri.href, mimeType: p, text: '<!doctype html>\n<html lang="en">\n<head>\n<meta charset="utf-8">\n<meta name="viewport" content="width=device-width, initial-scale=1">\n<title>Perfboard board</title>\n<style>\n :root { color-scheme: light dark; font-family: system-ui, sans-serif; font-size: 14px; }\n body { margin: 0; background: transparent; color: CanvasText; }\n figure { margin: 0; display: flex; flex-direction: column; gap: 8px; }\n img { display: block; width: 100%; height: auto; border-radius: 6px; }\n img:not([src]) { display: none; }\n figcaption { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }\n #caption { opacity: 0.75; }\n button { font: inherit; padding: 6px 12px; border-radius: 6px; border: 1px solid #1f7a3a; background: #1f7a3a; color: #fff; cursor: pointer; }\n button:hover { background: #18602e; }\n button[hidden] { display: none; }\n</style>\n</head>\n<body>\n<figure>\n <img id="board" alt="">\n <figcaption>\n <span id="caption">Drawing the board\u2026</span>\n <button id="open" type="button" hidden>Open in Perfboard Designer</button>\n </figcaption>\n</figure>\n<script type="module">var f="2026-01-26",r=document.getElementById("board"),a=document.getElementById("caption"),u=document.getElementById("open"),i,g=1,s=new Map,o=t=>window.parent.postMessage({jsonrpc:"2.0",...t},"*");function m(t,e){let n=g++;return o({id:n,method:t,params:e}),new Promise(p=>s.set(n,p))}function h(t){let e=t._meta?.board;if(t.isError||!e){a.textContent=t.content?.find(n=>n.type==="text")?.text??"The board couldn\'t be shown.";return}r.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(e.svg)}`,r.alt=e.caption,a.textContent=e.caption,i=e.link,u.hidden=!i}window.addEventListener("message",({source:t,data:e})=>{t!==window.parent||e?.jsonrpc!=="2.0"||(e.method===void 0?(s.get(e.id)?.(e.result),s.delete(e.id)):e.method==="ui/notifications/tool-result"?h(e.params??{}):e.id!==void 0&&o({id:e.id,result:{}}))});u.addEventListener("click",()=>{i&&m("ui/open-link",{url:i})});var c=0,l=0;function d(){let t=document.documentElement,e=Math.ceil(t.getBoundingClientRect().height),n=Math.ceil(window.innerWidth);n===c&&e===l||(c=n,l=e,o({method:"ui/notifications/size-changed",params:{width:n,height:e}}))}await m("ui/initialize",{protocolVersion:f,appInfo:{name:"Perfboard Designer board",version:"0.6.
|
|
46682
|
+
}, async (uri) => ({ contents: [{ uri: uri.href, mimeType: p, text: '<!doctype html>\n<html lang="en">\n<head>\n<meta charset="utf-8">\n<meta name="viewport" content="width=device-width, initial-scale=1">\n<title>Perfboard board</title>\n<style>\n :root { color-scheme: light dark; font-family: system-ui, sans-serif; font-size: 14px; }\n body { margin: 0; background: transparent; color: CanvasText; }\n figure { margin: 0; display: flex; flex-direction: column; gap: 8px; }\n img { display: block; width: 100%; height: auto; border-radius: 6px; }\n img:not([src]) { display: none; }\n figcaption { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }\n #caption { opacity: 0.75; }\n button { font: inherit; padding: 6px 12px; border-radius: 6px; border: 1px solid #1f7a3a; background: #1f7a3a; color: #fff; cursor: pointer; }\n button:hover { background: #18602e; }\n button[hidden] { display: none; }\n</style>\n</head>\n<body>\n<figure>\n <img id="board" alt="">\n <figcaption>\n <span id="caption">Drawing the board\u2026</span>\n <button id="open" type="button" hidden>Open in Perfboard Designer</button>\n </figcaption>\n</figure>\n<script type="module">var f="2026-01-26",r=document.getElementById("board"),a=document.getElementById("caption"),u=document.getElementById("open"),i,g=1,s=new Map,o=t=>window.parent.postMessage({jsonrpc:"2.0",...t},"*");function m(t,e){let n=g++;return o({id:n,method:t,params:e}),new Promise(p=>s.set(n,p))}function h(t){let e=t._meta?.board;if(t.isError||!e){a.textContent=t.content?.find(n=>n.type==="text")?.text??"The board couldn\'t be shown.";return}r.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(e.svg)}`,r.alt=e.caption,a.textContent=e.caption,i=e.link,u.hidden=!i}window.addEventListener("message",({source:t,data:e})=>{t!==window.parent||e?.jsonrpc!=="2.0"||(e.method===void 0?(s.get(e.id)?.(e.result),s.delete(e.id)):e.method==="ui/notifications/tool-result"?h(e.params??{}):e.id!==void 0&&o({id:e.id,result:{}}))});u.addEventListener("click",()=>{i&&m("ui/open-link",{url:i})});var c=0,l=0;function d(){let t=document.documentElement,e=Math.ceil(t.getBoundingClientRect().height),n=Math.ceil(window.innerWidth);n===c&&e===l||(c=n,l=e,o({method:"ui/notifications/size-changed",params:{width:n,height:e}}))}await m("ui/initialize",{protocolVersion:f,appInfo:{name:"Perfboard Designer board",version:"0.6.1"},appCapabilities:{}});o({method:"ui/notifications/initialized",params:{}});new ResizeObserver(()=>requestAnimationFrame(d)).observe(document.body);r.addEventListener("load",d);d();\n</script>\n</body>\n</html>\n', _meta: { ui: { prefersBorder: false } } }] }));
|
|
46520
46683
|
K3(server, "show_board", {
|
|
46521
46684
|
title: "Show board",
|
|
46522
46685
|
description: "Shows the user a picture of the board right in the conversation, as the editor draws it, with a button that opens it in Perfboard Designer. Only in clients that show MCP Apps (e.g. Claude, ChatGPT); elsewhere the user sees nothing, so give them make_share_link's link too. The picture goes to the user, not to you: to look at the board yourself, use render_board.",
|
|
@@ -46525,7 +46688,7 @@ function registerShowBoardTool(server, DEFAULT_EDITOR_URL) {
|
|
|
46525
46688
|
projectId: projectIdInput,
|
|
46526
46689
|
name: string2().optional().describe("The project's name, shown under the picture and in the editor. Defaults to the name it was given in new_project or came with from read_share_link.")
|
|
46527
46690
|
},
|
|
46528
|
-
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
46691
|
+
annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false },
|
|
46529
46692
|
_meta: { ui: { resourceUri: VIEW_URI }, "openai/outputTemplate": VIEW_URI }
|
|
46530
46693
|
}, async ({ project, projectId, name }) => {
|
|
46531
46694
|
const from = await projectSource({ project, projectId });
|
|
@@ -46559,12 +46722,12 @@ function registerResources(server) {
|
|
|
46559
46722
|
title: "Project file format",
|
|
46560
46723
|
description: "The project file format (version 8), including component identities and optional circuit requirements, as TypeScript types.",
|
|
46561
46724
|
mimeType: "text/plain"
|
|
46562
|
-
}, async (uri) => ({ contents: [{ uri: uri.href, mimeType: "text/plain", text: 'import {GridPos} from "./grid";\nimport type {CustomPartSpec} from "../parts/custom-parts";\nimport type {CircuitRequirements} from "./requirements";\n\n// The project file format, version 10. Positions are grid [column, row] pairs counted from the\n// top-left hole (column = left to right, row = top to bottom), not pixels, and only holes with a\n// note are listed. Older files are still read, see read-project-file.ts:\n// - version 9: the same, minus the description (`description`).\n// - version 8: the same as 9, minus wires on the solder side (a wire\'s `side`).\n// - version 7: the same as 8, minus circuit requirements (`requirements`).\n// - version 6: the same as 7, minus part identities (a placed part\'s `instanceId`).\n// - version 5: the same as 6, minus custom parts (a fixed-pin part\'s `custom`).\n// - version 4: the same as 5, minus solder paths (a wire\'s `kind`).\n// - version 3: the same as 4, minus bent wires (a wire\'s `via`).\n// - version 2: the same as 3, minus the board type (always a perfboard) and part refs.\n// - version 1 (no `version` field): pixel coordinates, every hole listed, the whole IC catalog.\nexport const PROJECT_FILE_VERSION = 10;\n\n// A file says the oldest version that holds everything in it: 9 with a wire on the solder side,\n// else 8 with requirements, else 6 with a\n// custom part, else 5 with a solder path, else 4 if a wire bends, else 3. So a board without them\n// still opens in editors and tools from before. Part identities (version 7) don\'t raise it: older\n// readers skip the field, and identities only matter to requirements, which are version 8. Nor does\n// the description (version 10): older readers skip it too, and the board is the same without it.\nexport type FileVersion = 3 | 4 | 5 | 6 | 8 | 9;\n\nexport function fileVersionFor(project: Pick<ProjectFile, "wires" | "placedAdvancedComponents" | "requirements">): FileVersion {\n if (project.wires.some(wire => wire.side === "bottom")) return 9;\n if (project.requirements) return 8;\n if (project.placedAdvancedComponents.some(part => part.custom)) return 6;\n if (project.wires.some(wire => wire.kind === "solder")) return 5;\n return project.wires.some(wire => wire.via?.length) ? 4 : 3;\n}\n\nexport type Rotation = 0 | 90 | 180 | 270;\n\n// A perfboard has a separate copper pad around every hole: nothing is connected until it\'s wired.\n// A stripboard has long copper strips instead, each connecting a whole line of holes.\nexport type BoardType = "perfboard" | "stripboard";\n\n// Which way a stripboard\'s strips run. "horizontal": every hole in the same row is on one strip.\n// "vertical": every hole in the same column is.\nexport type StripDirection = "horizontal" | "vertical";\n\nexport interface SavedPerfboard {\n type: "perfboard";\n cols: number;\n rows: number;\n}\n\nexport interface SavedStripboard {\n type: "stripboard";\n cols: number;\n rows: number;\n strips: StripDirection;\n // Holes where the strip is cut (drilled through). A cut splits its strip in two, and the cut\n // hole itself connects to neither side: a lead in it is connected to nothing.\n cuts: GridPos[];\n}\n\nexport type SavedBoard = SavedPerfboard | SavedStripboard;\n\n// A hole with a note on it ("+9V", "GND", "to battery"). Purely a label: it says nothing about\n// what\'s connected. (Files from before notes were the only mark may give a hole a `color` too;\n// it\'s ignored.)\nexport interface SavedPad {\n at: GridPos;\n note: string;\n}\n\n// What a wire is made of (version 5):\n// - "jumper": an insulated jumper wire on the component side. It joins the holes at its two ends\n// and nothing else: not the holes it passes over, and not its corners.\n// - "solder": a solder path, a trail of solder bridging pad to pad on the copper side. Bare metal,\n// so it joins every hole it runs over: its ends, its corners and each hole along the way\n// (solderPathHoles() in wire-path.ts), and any solder path it touches. A cut hole on a\n// stripboard has no copper for it to join, so whatever is in one stays unconnected.\nexport type WireKind = "jumper" | "solder";\n\n// A wire: a jumper unless `kind` says otherwise.\nexport interface SavedWire {\n from: GridPos;\n to: GridPos;\n // Where it bends on its way from `from` to `to`, in order (version 4): it runs straight from\n // hole to hole through these. A jumper\'s corner is a bend over a hole, never a joint; a solder\n // path\'s joins that hole like the rest of its holes. Absent: straight.\n via?: GridPos[];\n // Absent: "jumper". Only solder paths say it.\n kind?: WireKind;\n // A jumper\'s insulation colour and thickness (drawing px). A solder path has neither.\n color?: string;\n width?: number;\n // Which face of the board a jumper lies on (version 9). Absent: "top", the component side.\n // A "bottom" jumper is on the solder side: it joins the holes at its ends like any jumper (so a\n // wire or a pin in the same hole is on its net), but never goes over or under a top wire, since\n // they\'re on different faces. Only jumpers have it; a solder path is always on the copper side.\n side?: WireSide;\n}\n\nexport type WireSide = "top" | "bottom";\n\n// Every placed part has a `ref`: its reference designator (R1, C2, U1...), unique on the board\n// ignoring case. See part-refs.ts.\n\nexport interface SavedIc {\n instanceId?: string;\n ref: string;\n name: string;\n // Pin columns and rows as placed, i.e. already swapped by any 90/270 rotation.\n widthPin: number;\n heightPin: number;\n rotation: Rotation;\n pinDescription: Record<number, string>;\n // Top-left pin.\n at: GridPos;\n // The catalog category the chip was placed from; "modules\u2026" parts are drawn as boards. Absent in\n // files from before this was recorded.\n category?: string;\n}\n\nexport interface SavedStandardComponent {\n instanceId?: string;\n ref: string;\n definitionId: string;\n from: GridPos;\n to: GridPos;\n value?: string;\n color?: string;\n}\n\nexport interface SavedAdvancedComponent {\n instanceId?: string;\n ref: string;\n definitionId: string;\n // The anchor pin (the definition\'s pins[0]), or a grid-sizable block\'s top-left pin.\n at: GridPos;\n rotation: Rotation;\n rows: number;\n cols: number;\n value?: string;\n // A user-made part (version 6, definitionId "custom"): its whole definition, so the board needs\n // nothing else to draw it and know its pins (src/parts/custom-parts.ts): `name`, `cols` x `rows`\n // holes of body, its `pins` in order, each `at` a [column, row] within the body from its top-left\n // hole with an optional `label`, and optionally `refPrefix`, `color` (the body\'s) and `id` (its\n // entry in the editor\'s catalog). `at` above is pin 1\'s hole. With `shape`, the id of a built-in\n // fixed-pin part (e.g. "transistor", a TO-92), it\'s that part\'s package with its own name and pin\n // names: the package decides its pins\' holes (`cols`, `rows` and each `at` are written to match,\n // so a reader without shapes still finds the same pins) and how it\'s drawn; `color` is unused.\n custom?: CustomPartSpec;\n}\n\n// A user-made IC catalog entry. Loading a file adds these to the catalog (keyed by id) rather\n// than replacing it.\nexport interface SavedCustomIc {\n id?: number;\n name: string;\n widthPin: number;\n heightPin: number;\n pinDescription: Record<number, string>;\n // Where the part is listed in the Components panel; absent in files from before the catalog.\n category?: string;\n}\n\nexport interface ProjectFile {\n requirements?: CircuitRequirements;\n // What the board is and how it works, in its maker\'s words, for whoever opens it (version 10). Up\n // to 20,000 characters of a small part of Markdown, no raw HTML: # headings, - and 1. lists,\n // **bold**, *italic*, `code`, [links](https://...). A part\'s ref in it, with or without a pin (R1,\n // U1.8, D1.K), finds that part on the board where it\'s shown. See description.ts.\n description?: string;\n version: FileVersion;\n board: SavedBoard;\n pads: SavedPad[];\n wires: SavedWire[];\n // One array per kind, each in stacking order (see PartState.parts).\n placedIcs: SavedIc[];\n placedStandardComponents: SavedStandardComponent[];\n placedAdvancedComponents: SavedAdvancedComponent[];\n customIcs: SavedCustomIc[];\n}\n\nimport type { ProjectFile } from "./project-file";\nimport { partPins } from "./pin-positions";\nimport { boardPins, computeNets, Net, NetPin, netName, pinId, pinName } from "./nets";\n\nexport interface RequiredPin {\n componentId: string;\n pin: number;\n}\n\nexport interface RequiredComponent {\n id: string;\n ref: string;\n name: string;\n pins: { pin: number; label?: string }[];\n}\n\nexport interface RequiredNet {\n id: string;\n pins: RequiredPin[];\n}\n\nexport interface CircuitRequirements {\n validate: boolean;\n components: RequiredComponent[];\n nets: RequiredNet[];\n unused: RequiredPin[];\n}\n\nexport interface RequirementIssue {\n kind:\n | "missing-component"\n | "missing-pin"\n | "missing-connection"\n | "unexpected-connection";\n message: string;\n pins: RequiredPin[];\n}\n\nexport interface RequirementValidation {\n status: "disabled" | "incomplete" | "mismatch" | "match";\n issues: RequirementIssue[];\n unspecified: RequiredPin[];\n checked: number;\n total: number;\n}\n\n' }] }));
|
|
46725
|
+
}, async (uri) => ({ contents: [{ uri: uri.href, mimeType: "text/plain", text: 'import {GridPos} from "./grid";\nimport type {CustomPartSpec} from "../parts/custom-parts";\nimport type {PinNames} from "../parts/pin-names";\nimport type {CircuitRequirements} from "./requirements";\n\n// The project file format, version 11. Positions are grid [column, row] pairs counted from the\n// top-left hole (column = left to right, row = top to bottom), not pixels, and only holes with a\n// note are listed. Older files are still read, see read-project-file.ts:\n// - version 10: the same, minus a placed fixed-pin part\'s own pin names (`pinDescription`).\n// - version 9: the same as 10, minus the description (`description`).\n// - version 8: the same as 9, minus wires on the solder side (a wire\'s `side`).\n// - version 7: the same as 8, minus circuit requirements (`requirements`).\n// - version 6: the same as 7, minus part identities (a placed part\'s `instanceId`).\n// - version 5: the same as 6, minus custom parts (a fixed-pin part\'s `custom`).\n// - version 4: the same as 5, minus solder paths (a wire\'s `kind`).\n// - version 3: the same as 4, minus bent wires (a wire\'s `via`).\n// - version 2: the same as 3, minus the board type (always a perfboard) and part refs.\n// - version 1 (no `version` field): pixel coordinates, every hole listed, the whole IC catalog.\nexport const PROJECT_FILE_VERSION = 11;\n\n// A file says the oldest version that holds everything in it: 9 with a wire on the solder side,\n// else 8 with requirements, else 6 with a\n// custom part, else 5 with a solder path, else 4 if a wire bends, else 3. So a board without them\n// still opens in editors and tools from before. Part identities (version 7) don\'t raise it: older\n// readers skip the field, and identities only matter to requirements, which are version 8. Nor does\n// the description (version 10): older readers skip it too, and the board is the same without it.\n// Nor do a placed part\'s own pin names (version 11): older readers show the part\'s own names instead.\nexport type FileVersion = 3 | 4 | 5 | 6 | 8 | 9;\n\nexport function fileVersionFor(project: Pick<ProjectFile, "wires" | "placedAdvancedComponents" | "requirements">): FileVersion {\n if (project.wires.some(wire => wire.side === "bottom")) return 9;\n if (project.requirements) return 8;\n if (project.placedAdvancedComponents.some(part => part.custom)) return 6;\n if (project.wires.some(wire => wire.kind === "solder")) return 5;\n return project.wires.some(wire => wire.via?.length) ? 4 : 3;\n}\n\nexport type Rotation = 0 | 90 | 180 | 270;\n\n// A perfboard has a separate copper pad around every hole: nothing is connected until it\'s wired.\n// A stripboard has long copper strips instead, each connecting a whole line of holes.\nexport type BoardType = "perfboard" | "stripboard";\n\n// Which way a stripboard\'s strips run. "horizontal": every hole in the same row is on one strip.\n// "vertical": every hole in the same column is.\nexport type StripDirection = "horizontal" | "vertical";\n\nexport interface SavedPerfboard {\n type: "perfboard";\n cols: number;\n rows: number;\n}\n\nexport interface SavedStripboard {\n type: "stripboard";\n cols: number;\n rows: number;\n strips: StripDirection;\n // Holes where the strip is cut (drilled through). A cut splits its strip in two, and the cut\n // hole itself connects to neither side: a lead in it is connected to nothing.\n cuts: GridPos[];\n}\n\nexport type SavedBoard = SavedPerfboard | SavedStripboard;\n\n// A hole with a note on it ("+9V", "GND", "to battery"). Purely a label: it says nothing about\n// what\'s connected. (Files from before notes were the only mark may give a hole a `color` too;\n// it\'s ignored.)\nexport interface SavedPad {\n at: GridPos;\n note: string;\n}\n\n// What a wire is made of (version 5):\n// - "jumper": an insulated jumper wire on the component side. It joins the holes at its two ends\n// and nothing else: not the holes it passes over, and not its corners.\n// - "solder": a solder path, a trail of solder bridging pad to pad on the copper side. Bare metal,\n// so it joins every hole it runs over: its ends, its corners and each hole along the way\n// (solderPathHoles() in wire-path.ts), and any solder path it touches. A cut hole on a\n// stripboard has no copper for it to join, so whatever is in one stays unconnected.\nexport type WireKind = "jumper" | "solder";\n\n// A wire: a jumper unless `kind` says otherwise.\nexport interface SavedWire {\n from: GridPos;\n to: GridPos;\n // Where it bends on its way from `from` to `to`, in order (version 4): it runs straight from\n // hole to hole through these. A jumper\'s corner is a bend over a hole, never a joint; a solder\n // path\'s joins that hole like the rest of its holes. Absent: straight.\n via?: GridPos[];\n // Absent: "jumper". Only solder paths say it.\n kind?: WireKind;\n // A jumper\'s insulation colour and thickness (drawing px). A solder path has neither.\n color?: string;\n width?: number;\n // Which face of the board a jumper lies on (version 9). Absent: "top", the component side.\n // A "bottom" jumper is on the solder side: it joins the holes at its ends like any jumper (so a\n // wire or a pin in the same hole is on its net), but never goes over or under a top wire, since\n // they\'re on different faces. Only jumpers have it; a solder path is always on the copper side.\n side?: WireSide;\n}\n\nexport type WireSide = "top" | "bottom";\n\n// Every placed part has a `ref`: its reference designator (R1, C2, U1...), unique on the board\n// ignoring case. See part-refs.ts.\n\nexport interface SavedIc {\n instanceId?: string;\n ref: string;\n name: string;\n // Pin columns and rows as placed, i.e. already swapped by any 90/270 rotation.\n widthPin: number;\n heightPin: number;\n rotation: Rotation;\n pinDescription: Record<number, string>;\n // Top-left pin.\n at: GridPos;\n // The catalog category the chip was placed from; "modules\u2026" parts are drawn as boards. Absent in\n // files from before this was recorded.\n category?: string;\n}\n\nexport interface SavedStandardComponent {\n instanceId?: string;\n ref: string;\n definitionId: string;\n from: GridPos;\n to: GridPos;\n value?: string;\n color?: string;\n}\n\nexport interface SavedAdvancedComponent {\n instanceId?: string;\n ref: string;\n definitionId: string;\n // The anchor pin (the definition\'s pins[0]), or a grid-sizable block\'s top-left pin.\n at: GridPos;\n rotation: Rotation;\n rows: number;\n cols: number;\n value?: string;\n // Version 11: this one part\'s pin names, by pin number ("1": "+5V", "2": "GND"), for a connector\n // whose pins mean something here. They replace the definition\'s own names on the board and in\n // the nets; a blank one ("") shows a pin the definition names by its number. Only pins the part\n // has, each name at most 24 characters and only where it differs from the definition\'s own\n // (src/parts/pin-names.ts). Only this placed part is renamed, never the catalog entry it came\n // from; the MCP server writes it through `edit_project`\'s `pinNames`, as does the editor\'s Pin\n // Names action.\n pinDescription?: PinNames;\n // A user-made part (version 6, definitionId "custom"): its whole definition, so the board needs\n // nothing else to draw it and know its pins (src/parts/custom-parts.ts): `name`, `cols` x `rows`\n // holes of body, its `pins` in order, each `at` a [column, row] within the body from its top-left\n // hole with an optional `label`, and optionally `refPrefix`, `color` (the body\'s) and `id` (its\n // entry in the editor\'s catalog). `at` above is pin 1\'s hole. With `shape`, the id of a built-in\n // fixed-pin part (e.g. "transistor", a TO-92), it\'s that part\'s package with its own name and pin\n // names: the package decides its pins\' holes (`cols`, `rows` and each `at` are written to match,\n // so a reader without shapes still finds the same pins) and how it\'s drawn; `color` is unused.\n custom?: CustomPartSpec;\n}\n\n// A user-made IC catalog entry. Loading a file adds these to the catalog (keyed by id) rather\n// than replacing it.\nexport interface SavedCustomIc {\n id?: number;\n name: string;\n widthPin: number;\n heightPin: number;\n pinDescription: Record<number, string>;\n // Where the part is listed in the Components panel; absent in files from before the catalog.\n category?: string;\n}\n\nexport interface ProjectFile {\n requirements?: CircuitRequirements;\n // What the board is and how it works, in its maker\'s words, for whoever opens it (version 10). Up\n // to 20,000 characters of a small part of Markdown, no raw HTML: # headings, - and 1. lists,\n // **bold**, *italic*, `code`, [links](https://...). A part\'s ref in it, with or without a pin (R1,\n // U1.8, D1.K), finds that part on the board where it\'s shown. See description.ts.\n description?: string;\n version: FileVersion;\n board: SavedBoard;\n pads: SavedPad[];\n wires: SavedWire[];\n // One array per kind, each in stacking order (see PartState.parts).\n placedIcs: SavedIc[];\n placedStandardComponents: SavedStandardComponent[];\n placedAdvancedComponents: SavedAdvancedComponent[];\n customIcs: SavedCustomIc[];\n}\n\nimport type { ProjectFile } from "./project-file";\nimport { partPins } from "./pin-positions";\nimport { boardPins, computeNets, Net, NetPin, netName, pinId, pinName } from "./nets";\n\nexport interface RequiredPin {\n componentId: string;\n pin: number;\n}\n\nexport interface RequiredComponent {\n id: string;\n ref: string;\n name: string;\n pins: { pin: number; label?: string }[];\n}\n\nexport interface RequiredNet {\n id: string;\n pins: RequiredPin[];\n}\n\nexport interface CircuitRequirements {\n validate: boolean;\n components: RequiredComponent[];\n nets: RequiredNet[];\n unused: RequiredPin[];\n}\n\nexport interface RequirementIssue {\n kind:\n | "missing-component"\n | "missing-pin"\n | "missing-connection"\n | "unexpected-connection";\n message: string;\n pins: RequiredPin[];\n}\n\nexport interface RequirementValidation {\n status: "disabled" | "incomplete" | "mismatch" | "match";\n issues: RequirementIssue[];\n unspecified: RequiredPin[];\n checked: number;\n total: number;\n}\n\n' }] }));
|
|
46563
46726
|
server.registerResource("share-links", "perfboard://docs/share-links", {
|
|
46564
46727
|
title: "Share links",
|
|
46565
46728
|
description: "How a share link carries a project, and what happens when the user opens one.",
|
|
46566
46729
|
mimeType: "text/markdown"
|
|
46567
|
-
}, async (uri) => ({ contents: [{ uri: uri.href, mimeType: "text/markdown", text: '# Share links\n\nA share link opens a board in Perfboard Designer for whoever clicks it. The whole project travels\ninside the link itself, so there\'s no account, no upload and no server. In the editor, use\n**\u{1F517} Share** (or **File \u2192 Share Link...**) to make one. The same dialog can also make a **short\nlink** to a copy of the board stored on Perfboard Designer\'s server (`p`, below).\n\nThis page is the link format, written so that people and programs can make links too, including\nAI agents that design a board and hand the user a link to open it. The code is\n[`src/project-file/share-link.ts`](../src/project-file/share-link.ts). An agent that can use MCP\ncan skip most of this page: the [MCP server](../mcp/README.md) looks up parts, checks the project\nand makes the link for it.\n\n## What happens when a link is opened\n\n- The project is added to the receiver\'s projects (kept in their browser) as a **new project**,\n and opened. Whatever they had open stays as it was. The link is a snapshot: later changes by the\n sender aren\'t in it.\n- It\'s named after the link\'s `name`, or "Shared project". If a project with that name exists,\n the new one is numbered: "LED demo 2".\n- The link is then removed from the address bar, so reloading doesn\'t add the project again.\n- The project is checked like an imported file. Entries that can\'t be read are left out, and the\n user is told how many. A link that can\'t be read at all leaves everything untouched and says why.\n\n## A page to read instead\n\nThe same link with `view/` in place of `app/` opens a read-only page about the board, for sending\nto someone who wants to see it before (or instead of) opening it:\n\n```\nhttps://perfboarddesigner.com/view/#<fragment>\n```\n\nIt shows the project\'s name, a picture of the board (from either side, and full screen to zoom\ninto), its description, its parts and its nets, with buttons that open a copy in the editor, print\nthe project PDF and show it in 3D. Part names in the description, and the parts and nets listed,\nlight up on the picture. It takes every form of the fragment below. It keeps\nnothing and changes nothing: the receiver\'s projects stay as they are, and the link stays in the\naddress bar. A `src` project is downloaded only once the reader agrees, as in the editor.\n\n## Format\n\n```\nhttps://perfboarddesigner.com/app/#<fragment>\n```\n\nThe project goes in the URL **fragment** (after `#`), which browsers never send to a server. The\nfragment holds `key=value` parameters joined with `&`, like a query string:\n\n| Parameter | Value |\n| --- | --- |\n| `name` | Optional. The project\'s name, percent-encoded. |\n| `z` | The project file, compressed (see below). This is what the editor makes. |\n| `json` | The project file as plain JSON, percent-encoded. Must be the **last** parameter. |\n| `src` | The `https://` address of a project file hosted somewhere else, percent-encoded. |\n| `p` | The id of a project stored on Perfboard Designer\'s server: a short link. |\n\nUse exactly one of `z`, `json`, `src` and `p`. If several are present, `json` wins, then `z`, then\n`src`, then `p`.\n\n### `z`: compressed (shortest)\n\n1. Write the project file as JSON (minified is best).\n2. Compress its UTF-8 bytes with **raw DEFLATE** (no zlib or gzip header).\n3. Encode the result as **base64url** (`-` and `_` instead of `+` and `/`) with no `=` padding.\n\nThe reader is forgiving about what programs commonly produce instead. It also accepts zlib- or\ngzip-wrapped data, plain base64 with `+`, `/` and `=` padding, and line breaks in the base64 text.\n\nPython:\n\n```python\nimport base64, json, urllib.parse, zlib\n\ndef share_link(project: dict, name: str = "") -> str:\n data = json.dumps(project, separators=(",", ":")).encode("utf-8")\n deflate = zlib.compressobj(9, zlib.DEFLATED, -15) # -15: raw DEFLATE, no header\n z = base64.urlsafe_b64encode(deflate.compress(data) + deflate.flush()).rstrip(b"=").decode()\n name_param = f"name={urllib.parse.quote(name, safe=\'\')}&" if name else ""\n return f"https://perfboarddesigner.com/app/#{name_param}z={z}"\n```\n\nNode.js:\n\n```js\nconst zlib = require("zlib");\n\nfunction shareLink(project, name = "") {\n const z = zlib.deflateRawSync(Buffer.from(JSON.stringify(project))).toString("base64url");\n const nameParam = name ? `name=${encodeURIComponent(name)}&` : "";\n return `https://perfboarddesigner.com/app/#${nameParam}z=${z}`;\n}\n```\n\n### `json`: plain JSON (no tools needed)\n\n```\nhttps://perfboarddesigner.com/app/#name=LED%20demo&json=<percent-encoded project file JSON>\n```\n\nThis is for writers that can\'t compress, such as a language model writing the link directly.\nThese links are 3 to 7 times longer than `z` links. Rules:\n\n- `json` must be the **last parameter**: everything after `json=` is the project.\n- Percent-encode the JSON, as `encodeURIComponent` or Python\'s\n `urllib.parse.quote(text, safe="")` do. Encode at least spaces (`%20`), `#` (`%23`, which\n starts every color), `%` (`%25`) and `+` (`%2B`). A `+` is kept as a plus sign, never read as\n a space. Unencoded links may survive in a browser\'s address bar but are often broken by the chat\n apps and editors that turn text into links.\n- The reader tolerates a stray `%` that doesn\'t start an escape, such as a note saying `50%`.\n\n### `src`: a file hosted elsewhere\n\n```\nhttps://perfboarddesigner.com/app/#src=https%3A%2F%2Fexample.com%2Fmy-board.json\n```\n\n- The address must be `http://` or `https://`, and the site must allow other websites to read\n the file (CORS). Raw GitHub Gist and raw GitHub file addresses\n (`gist.githubusercontent.com`, `raw.githubusercontent.com`) do. A gist\'s normal page does not.\n- The user is asked before anything is downloaded, since fetching the file shows that site the\n visit.\n- Without a `name`, the project is named after the file (`my-board.json` \u2192 "my-board").\n- There\'s no size limit to worry about here, so this suits large boards and programs that can\n publish files.\n\n### `p`: a stored project (short link)\n\n```\nhttps://perfboarddesigner.com/app/#name=LED%20blinker&p=led-blinker\n```\n\n- The project is stored on Perfboard Designer\'s own server, `https://projects.perfboarddesigner.com`\n (below), and the link names it by its id. It\'s fetched without asking, since it\'s the site\'s own.\n- Without a `name`, the project is named after its id.\n- A stored project never changes, and it\'s deleted after a year unopened. Anyone with the link\n can open it. Unlike the other forms, it needs the server: the Share dialog offers the full link\n beside it, which works without one.\n\n### Stored projects\n\n`https://projects.perfboarddesigner.com` keeps projects for short links. Anyone can store one:\n\n| Request | Answer |\n| --- | --- |\n| `POST /projects` with `{"project": {\u2026}, "id": "led-blinker", "name": "LED blinker"}` (`id` and `name` optional) | `{id, link, file, image, png}`: the id it got, a short link, the file\'s address and its pictures\' |\n| `GET /<id>.json` | the project file |\n| `GET /<id>.png`, `GET /<id>.svg` | pictures of the board |\n\n- **Ids** are lowercase letters, digits and dashes, at most 40 characters, made from the wanted\n `id` or else the `name` (`"M\xE1gneses kapcsol\xF3!"` \u2192 `magneses-kapcsolo`). If another board has\n that id, a few characters of the board\'s SHA-256 are added (`led-blinker-08196a`); storing the\n same board under the same id again gives the same id back. With neither, the id is the hash.\n- Only valid project files are stored, as the editor reads them, up to 1 MB.\n- Every site may call it (CORS). There\'s no sign-in.\n- It\'s the [MCP server\'s](../mcp/README.md) Cloudflare Worker, which agents store through too.\n\n### Limits\n\n- The project file may be at most 5 MB once unpacked, and a board at most 500 holes on a side.\n- Links longer than about 8,000 characters may be cut off by some chat apps and mail clients; the\n Share dialog warns about these. For scale, the boards in [`examples/`](../examples) make `z`\n links of 0.8k to 2.7k characters.\n\n## The project file\n\nVersion 10 adds an optional `description`: what the board is and how it works, for whoever opens\nit, up to 20,000 characters. It\'s written in a small part of Markdown (`#` headings, `-` and `1.`\nlists, `**bold**`, `*italic*`, `` `code` ``, `[links](https://...)` and bare `https://` addresses),\nwithout raw HTML or images, and a line break stays a line break. A part\'s `ref` written exactly as\nthe board has it, with or without a pin (`R1`, `U1.8`, `U1.VCC`, `D1.K`), finds that part: on the\npage to read it lights up on the board, and in the editor a click selects it. Older readers skip\nthe description, so it doesn\'t need a newer version on its own.\n\nVersion 8 adds optional `requirements`: independent intended `nets` containing\n`{componentId, pin}` terminals, an explicit `unused` terminal list, component/pin snapshots\n(`components`) and an opt-in `validate` flag.\nAll terminals refer to stable component identities, not editable reference names. Snapshots\nkeep missing components/pins reportable; unspecified terminals are unchecked rather than unused.\nInvalid or overlapping requirement assignments reject the import instead of silently dropping\nconstraints. Board edits must preserve intended nets; adding a component extends the shared\ninventory without assigning new connections.\n\nVersion 7 adds a project-scoped `instanceId` to each placed part. Older readers skip it, so it\ndoesn\'t need a newer version on its own. A top-level `schematic` field, written by older editors,\nis ignored.\n\nA share link carries the same project file as **File \u2192 Save Project to File**. Every version\nopens, but write the oldest one that holds your board: version 9 with a wire on the solder side,\nelse version 8 with requirements, else version 6 with a custom module, else 5\nwith a solder path, else 4 if a wire bends, else 3 (the same without any of them), which older\neditors open too. It\'s documented field by field in\n[`src/project-file/project-file.ts`](../src/project-file/project-file.ts). In short:\n\n- Positions are `[column, row]` grid holes counted from the **top-left hole**, both starting at 0.\n Neighbouring holes are 2.54 mm (0.1 in) apart.\n- `board`: `{"type": "perfboard", "cols": 12, "rows": 8}`, or a stripboard with\n `"strips": "horizontal" | "vertical"` and `"cuts": [[col, row], ...]`.\n- `pads`: holes with a `note` (like `+9V` or `GND`), as `{"at": [c, r], "note": "+9V"}`. Purely\n a label: it doesn\'t connect anything.\n- `wires`: `{"from": [c, r], "to": [c, r]}`, with optional `color` (`"#rrggbb"`) and `width`. A\n wire joins only its two end holes. With `"via": [[c, r], ...]` (version 4) it bends at those\n holes on its way, in order; a bend joins nothing. With `"kind": "solder"` (version 5) it\'s a\n solder path instead: a trail of solder on the copper side, with no `color` or `width`, that\n joins every hole it runs over (ends, bends and the holes between) and any solder path it\n touches. With `"side": "bottom"` (version 9) a jumper lies on the solder side of the board: it\n joins its end holes like any jumper (so it shares a net with a pin or another wire\'s end in the\n same hole) but never crosses a top wire. Absent: the top. A solder path takes no `side`.\n- `placedStandardComponents`: two-lead parts placed between two holes: `definitionId`, `from`,\n `to`, optional `value` (`"10k"`, `"100n"`) and `color` (LEDs). On polarized parts, `from` is\n an LED\'s cathode, a diode\'s anode and an electrolytic capacitor\'s \u2212 lead (`leadLabels` in the\n definitions).\n- `placedAdvancedComponents`: fixed-footprint parts: `definitionId`, the anchor pin `at`,\n `rotation` (0, 90, 180 or 270), `rows` and `cols` (1 except for sizable parts such as header\n pins), optional `value`. A user-made module has `"definitionId": "custom"` and carries the\n whole part in `custom` (version 6): `name`, optional `refPrefix`, its size in holes `cols` and\n `rows`, its `pins` in order as `{"at": [c, r], "label": "VCC"}` (holes within the body from its\n top-left hole; pin 1 is the anchor `at`) and an optional `color`. With `"shape"`, the id of a\n built-in fixed-pin part (e.g. `"transistor"` for a TO-92), it\'s that package with its own `name`\n and pin names (`pins` in the package\'s pin order, each `{"label": "B"}`): the package decides its\n holes, and `cols`, `rows` and each `at` are written to match it.\n- `placedIcs`: DIP chips and dual-row modules: `name`, `at` (top-left pin), `widthPin` (columns\n including both pin rows, 4 for a 0.3" DIP), `heightPin` (pins per side), `rotation`, and\n `pinDescription` (`{"1": "GND", "2": "TRIG", ...}`, numbered counter-clockwise from pin 1).\n- `customIcs`: user-made catalog entries. `[]` is fine.\n- Every part should have a unique `ref` (R1, C2, U1...). Missing or duplicate refs are numbered\n automatically.\n\nThe reader is forgiving: empty lists can be left out, a file without `version` that has a `board`\nis read as version 10, and board entries it can\'t read are skipped (and counted) instead of failing the\nwhole project.\n\nThe `definitionId`s, with each part\'s pins, are in\n[`component-definitions.ts`](../src/parts/component-definitions.ts)\n(two-lead parts such as `resistor`, `ceramic-capacitor`, `electrolytic-capacitor`, `led` and\n`diode`) and\n[`advanced-component-definitions.ts`](../src/parts/advanced-component-definitions.ts)\n(fixed-footprint parts such as `transistor`, `potentiometer` and `header-pins`). Built-in chips are\nin [`ic-definitions.ts`](../src/parts/ic-definitions.ts), and footprints are described in\n[component-footprints.md](component-footprints.md). Check ids against these files: a part with an\nunknown `definitionId` isn\'t skipped, it stays on the board as an unrecognised part with an `X` ref.\n\n## Example\n\nA 9 V LED circuit on a 12 \xD7 8 perfboard:\n\n```json\n{\n "version": 3,\n "board": {"type": "perfboard", "cols": 12, "rows": 8},\n "pads": [{"at": [1, 1], "note": "+9V"}, {"at": [1, 6], "note": "GND"}],\n "wires": [\n {"from": [1, 1], "to": [3, 1], "color": "#ef4444"},\n {"from": [8, 4], "to": [8, 6]},\n {"from": [8, 6], "to": [1, 6]}\n ],\n "placedIcs": [],\n "placedStandardComponents": [\n {"ref": "R1", "definitionId": "resistor", "from": [3, 1], "to": [8, 1], "value": "470"},\n {"ref": "D1", "definitionId": "led", "from": [8, 2], "to": [8, 4], "color": "#22c55e"}\n ],\n "placedAdvancedComponents": [\n {"ref": "J1", "definitionId": "header-pins", "at": [0, 1], "rotation": 0, "rows": 6, "cols": 1}\n ],\n "customIcs": []\n}\n```\n\nAs a `json` link (the start of it):\n\n```\nhttps://perfboarddesigner.com/app/#name=LED%20demo&json=%7B%22version%22%3A3%2C%22board%22%3A%7B%22type%22%3A%22perfboard%22%2C...\n```\n' }] }));
|
|
46730
|
+
}, async (uri) => ({ contents: [{ uri: uri.href, mimeType: "text/markdown", text: '# Share links\n\nA share link opens a board in Perfboard Designer for whoever clicks it. The whole project travels\ninside the link itself, so there\'s no account, no upload and no server. In the editor, use\n**\u{1F517} Share** (or **File \u2192 Share Link...**) to make one. The same dialog can also make a **short\nlink** to a copy of the board stored on Perfboard Designer\'s server (`p`, below).\n\nThis page is the link format, written so that people and programs can make links too, including\nAI agents that design a board and hand the user a link to open it. The code is\n[`src/project-file/share-link.ts`](../src/project-file/share-link.ts). An agent that can use MCP\ncan skip most of this page: the [MCP server](../mcp/README.md) looks up parts, checks the project\nand makes the link for it.\n\n## What happens when a link is opened\n\n- The project is added to the receiver\'s projects (kept in their browser) as a **new project**,\n and opened. Whatever they had open stays as it was. The link is a snapshot: later changes by the\n sender aren\'t in it.\n- It\'s named after the link\'s `name`, or "Shared project". If a project with that name exists,\n the new one is numbered: "LED demo 2".\n- The link is then removed from the address bar, so reloading doesn\'t add the project again.\n- The project is checked like an imported file. Entries that can\'t be read are left out, and the\n user is told how many. A link that can\'t be read at all leaves everything untouched and says why.\n\n## A page to read instead\n\nThe same link with `view/` in place of `app/` opens a read-only page about the board, for sending\nto someone who wants to see it before (or instead of) opening it:\n\n```\nhttps://perfboarddesigner.com/view/#<fragment>\n```\n\nIt shows the project\'s name, a picture of the board (from either side, and full screen to zoom\ninto), its description, its parts and its nets, with buttons that open a copy in the editor, print\nthe project PDF and show it in 3D. Part names in the description, and the parts and nets listed,\nlight up on the picture. It takes every form of the fragment below. It keeps\nnothing and changes nothing: the receiver\'s projects stay as they are, and the link stays in the\naddress bar. A `src` project is downloaded only once the reader agrees, as in the editor.\n\n## Format\n\n```\nhttps://perfboarddesigner.com/app/#<fragment>\n```\n\nThe project goes in the URL **fragment** (after `#`), which browsers never send to a server. The\nfragment holds `key=value` parameters joined with `&`, like a query string:\n\n| Parameter | Value |\n| --- | --- |\n| `name` | Optional. The project\'s name, percent-encoded. |\n| `z` | The project file, compressed (see below). This is what the editor makes. |\n| `json` | The project file as plain JSON, percent-encoded. Must be the **last** parameter. |\n| `src` | The `https://` address of a project file hosted somewhere else, percent-encoded. |\n| `p` | The id of a project stored on Perfboard Designer\'s server: a short link. |\n\nUse exactly one of `z`, `json`, `src` and `p`. If several are present, `json` wins, then `z`, then\n`src`, then `p`.\n\n### `z`: compressed (shortest)\n\n1. Write the project file as JSON (minified is best).\n2. Compress its UTF-8 bytes with **raw DEFLATE** (no zlib or gzip header).\n3. Encode the result as **base64url** (`-` and `_` instead of `+` and `/`) with no `=` padding.\n\nThe reader is forgiving about what programs commonly produce instead. It also accepts zlib- or\ngzip-wrapped data, plain base64 with `+`, `/` and `=` padding, and line breaks in the base64 text.\n\nPython:\n\n```python\nimport base64, json, urllib.parse, zlib\n\ndef share_link(project: dict, name: str = "") -> str:\n data = json.dumps(project, separators=(",", ":")).encode("utf-8")\n deflate = zlib.compressobj(9, zlib.DEFLATED, -15) # -15: raw DEFLATE, no header\n z = base64.urlsafe_b64encode(deflate.compress(data) + deflate.flush()).rstrip(b"=").decode()\n name_param = f"name={urllib.parse.quote(name, safe=\'\')}&" if name else ""\n return f"https://perfboarddesigner.com/app/#{name_param}z={z}"\n```\n\nNode.js:\n\n```js\nconst zlib = require("zlib");\n\nfunction shareLink(project, name = "") {\n const z = zlib.deflateRawSync(Buffer.from(JSON.stringify(project))).toString("base64url");\n const nameParam = name ? `name=${encodeURIComponent(name)}&` : "";\n return `https://perfboarddesigner.com/app/#${nameParam}z=${z}`;\n}\n```\n\n### `json`: plain JSON (no tools needed)\n\n```\nhttps://perfboarddesigner.com/app/#name=LED%20demo&json=<percent-encoded project file JSON>\n```\n\nThis is for writers that can\'t compress, such as a language model writing the link directly.\nThese links are 3 to 7 times longer than `z` links. Rules:\n\n- `json` must be the **last parameter**: everything after `json=` is the project.\n- Percent-encode the JSON, as `encodeURIComponent` or Python\'s\n `urllib.parse.quote(text, safe="")` do. Encode at least spaces (`%20`), `#` (`%23`, which\n starts every color), `%` (`%25`) and `+` (`%2B`). A `+` is kept as a plus sign, never read as\n a space. Unencoded links may survive in a browser\'s address bar but are often broken by the chat\n apps and editors that turn text into links.\n- The reader tolerates a stray `%` that doesn\'t start an escape, such as a note saying `50%`.\n\n### `src`: a file hosted elsewhere\n\n```\nhttps://perfboarddesigner.com/app/#src=https%3A%2F%2Fexample.com%2Fmy-board.json\n```\n\n- The address must be `http://` or `https://`, and the site must allow other websites to read\n the file (CORS). Raw GitHub Gist and raw GitHub file addresses\n (`gist.githubusercontent.com`, `raw.githubusercontent.com`) do. A gist\'s normal page does not.\n- The user is asked before anything is downloaded, since fetching the file shows that site the\n visit.\n- Without a `name`, the project is named after the file (`my-board.json` \u2192 "my-board").\n- There\'s no size limit to worry about here, so this suits large boards and programs that can\n publish files.\n\n### `p`: a stored project (short link)\n\n```\nhttps://perfboarddesigner.com/app/#name=LED%20blinker&p=led-blinker\n```\n\n- The project is stored on Perfboard Designer\'s own server, `https://projects.perfboarddesigner.com`\n (below), and the link names it by its id. It\'s fetched without asking, since it\'s the site\'s own.\n- Without a `name`, the project is named after its id.\n- A stored project never changes, and it\'s deleted after a year unopened. Anyone with the link\n can open it. Unlike the other forms, it needs the server: the Share dialog offers the full link\n beside it, which works without one.\n\n### Stored projects\n\n`https://projects.perfboarddesigner.com` keeps projects for short links. Anyone can store one:\n\n| Request | Answer |\n| --- | --- |\n| `POST /projects` with `{"project": {\u2026}, "id": "led-blinker", "name": "LED blinker"}` (`id` and `name` optional) | `{id, link, file, image, png}`: the id it got, a short link, the file\'s address and its pictures\' |\n| `GET /<id>.json` | the project file |\n| `GET /<id>.png`, `GET /<id>.svg` | pictures of the board |\n\n- **Ids** are lowercase letters, digits and dashes, at most 40 characters, made from the wanted\n `id` or else the `name` (`"M\xE1gneses kapcsol\xF3!"` \u2192 `magneses-kapcsolo`). If another board has\n that id, a few characters of the board\'s SHA-256 are added (`led-blinker-08196a`); storing the\n same board under the same id again gives the same id back. With neither, the id is the hash.\n- Only valid project files are stored, as the editor reads them, up to 1 MB.\n- Every site may call it (CORS). There\'s no sign-in.\n- It\'s the [MCP server\'s](../mcp/README.md) Cloudflare Worker, which agents store through too.\n\n### Limits\n\n- The project file may be at most 5 MB once unpacked, and a board at most 500 holes on a side.\n- Links longer than about 8,000 characters may be cut off by some chat apps and mail clients; the\n Share dialog warns about these. For scale, the boards in [`examples/`](../examples) make `z`\n links of 0.8k to 2.7k characters.\n\n## The project file\n\nVersion 11 adds a fixed-pin part\'s own pin names, `pinDescription` (below). Older readers skip\nthem and show the part\'s own pin names, so they don\'t need a newer version on their own.\n\nVersion 10 adds an optional `description`: what the board is and how it works, for whoever opens\nit, up to 20,000 characters. It\'s written in a small part of Markdown (`#` headings, `-` and `1.`\nlists, `**bold**`, `*italic*`, `` `code` ``, `[links](https://...)` and bare `https://` addresses),\nwithout raw HTML or images, and a line break stays a line break. A part\'s `ref` written exactly as\nthe board has it, with or without a pin (`R1`, `U1.8`, `U1.VCC`, `D1.K`), finds that part: on the\npage to read it lights up on the board, and in the editor a click selects it. Older readers skip\nthe description, so it doesn\'t need a newer version on its own.\n\nVersion 8 adds optional `requirements`: independent intended `nets` containing\n`{componentId, pin}` terminals, an explicit `unused` terminal list, component/pin snapshots\n(`components`) and an opt-in `validate` flag.\nAll terminals refer to stable component identities, not editable reference names. Snapshots\nkeep missing components/pins reportable; unspecified terminals are unchecked rather than unused.\nInvalid or overlapping requirement assignments reject the import instead of silently dropping\nconstraints. Board edits must preserve intended nets; adding a component extends the shared\ninventory without assigning new connections.\n\nVersion 7 adds a project-scoped `instanceId` to each placed part. Older readers skip it, so it\ndoesn\'t need a newer version on its own. A top-level `schematic` field, written by older editors,\nis ignored.\n\nA share link carries the same project file as **File \u2192 Save Project to File**. Every version\nopens, but write the oldest one that holds your board: version 9 with a wire on the solder side,\nelse version 8 with requirements, else version 6 with a custom module, else 5\nwith a solder path, else 4 if a wire bends, else 3 (the same without any of them), which older\neditors open too. It\'s documented field by field in\n[`src/project-file/project-file.ts`](../src/project-file/project-file.ts). In short:\n\n- Positions are `[column, row]` grid holes counted from the **top-left hole**, both starting at 0.\n Neighbouring holes are 2.54 mm (0.1 in) apart.\n- `board`: `{"type": "perfboard", "cols": 12, "rows": 8}`, or a stripboard with\n `"strips": "horizontal" | "vertical"` and `"cuts": [[col, row], ...]`.\n- `pads`: holes with a `note` (like `+9V` or `GND`), as `{"at": [c, r], "note": "+9V"}`. Purely\n a label: it doesn\'t connect anything.\n- `wires`: `{"from": [c, r], "to": [c, r]}`, with optional `color` (`"#rrggbb"`) and `width`. A\n wire joins only its two end holes. With `"via": [[c, r], ...]` (version 4) it bends at those\n holes on its way, in order; a bend joins nothing. With `"kind": "solder"` (version 5) it\'s a\n solder path instead: a trail of solder on the copper side, with no `color` or `width`, that\n joins every hole it runs over (ends, bends and the holes between) and any solder path it\n touches. With `"side": "bottom"` (version 9) a jumper lies on the solder side of the board: it\n joins its end holes like any jumper (so it shares a net with a pin or another wire\'s end in the\n same hole) but never crosses a top wire. Absent: the top. A solder path takes no `side`.\n- `placedStandardComponents`: two-lead parts placed between two holes: `definitionId`, `from`,\n `to`, optional `value` (`"10k"`, `"100n"`) and `color` (LEDs). On polarized parts, `from` is\n an LED\'s cathode, a diode\'s anode and an electrolytic capacitor\'s \u2212 lead (`leadLabels` in the\n definitions).\n- `placedAdvancedComponents`: fixed-footprint parts: `definitionId`, the anchor pin `at`,\n `rotation` (0, 90, 180 or 270), `rows` and `cols` (1 except for sizable parts such as header\n pins), optional `value`, and optional `pinDescription` (`{"1": "+5V", "2": "GND"}`, version 11):\n this one part\'s own pin names, by pin number, which replace the part\'s own numbers or names on\n the board and in the nets (`"J6.+5V"`). Only that placed part is renamed. A blank name (`""`)\n shows a pin the part names by its number; names are at most 24 characters, and names for pins\n the part doesn\'t have are ignored. A user-made module has `"definitionId": "custom"` and carries the\n whole part in `custom` (version 6): `name`, optional `refPrefix`, its size in holes `cols` and\n `rows`, its `pins` in order as `{"at": [c, r], "label": "VCC"}` (holes within the body from its\n top-left hole; pin 1 is the anchor `at`) and an optional `color`. With `"shape"`, the id of a\n built-in fixed-pin part (e.g. `"transistor"` for a TO-92), it\'s that package with its own `name`\n and pin names (`pins` in the package\'s pin order, each `{"label": "B"}`): the package decides its\n holes, and `cols`, `rows` and each `at` are written to match it.\n- `placedIcs`: DIP chips and dual-row modules: `name`, `at` (top-left pin), `widthPin` (columns\n including both pin rows, 4 for a 0.3" DIP), `heightPin` (pins per side), `rotation`, and\n `pinDescription` (`{"1": "GND", "2": "TRIG", ...}`, numbered counter-clockwise from pin 1).\n- `customIcs`: user-made catalog entries. `[]` is fine.\n- Every part should have a unique `ref` (R1, C2, U1...). Missing or duplicate refs are numbered\n automatically.\n\nThe reader is forgiving: empty lists can be left out, a file without `version` that has a `board`\nis read as version 11, and board entries it can\'t read are skipped (and counted) instead of failing the\nwhole project.\n\nThe `definitionId`s, with each part\'s pins, are in\n[`component-definitions.ts`](../src/parts/component-definitions.ts)\n(two-lead parts such as `resistor`, `ceramic-capacitor`, `electrolytic-capacitor`, `led` and\n`diode`) and\n[`advanced-component-definitions.ts`](../src/parts/advanced-component-definitions.ts)\n(fixed-footprint parts such as `transistor`, `potentiometer` and `header-pins`). Built-in chips are\nin [`ic-definitions.ts`](../src/parts/ic-definitions.ts), and footprints are described in\n[component-footprints.md](component-footprints.md). Check ids against these files: a part with an\nunknown `definitionId` isn\'t skipped, it stays on the board as an unrecognised part with an `X` ref.\n\n## Example\n\nA 9 V LED circuit on a 12 \xD7 8 perfboard:\n\n```json\n{\n "version": 3,\n "board": {"type": "perfboard", "cols": 12, "rows": 8},\n "pads": [{"at": [1, 1], "note": "+9V"}, {"at": [1, 6], "note": "GND"}],\n "wires": [\n {"from": [1, 1], "to": [3, 1], "color": "#ef4444"},\n {"from": [8, 4], "to": [8, 6]},\n {"from": [8, 6], "to": [1, 6]}\n ],\n "placedIcs": [],\n "placedStandardComponents": [\n {"ref": "R1", "definitionId": "resistor", "from": [3, 1], "to": [8, 1], "value": "470"},\n {"ref": "D1", "definitionId": "led", "from": [8, 2], "to": [8, 4], "color": "#22c55e"}\n ],\n "placedAdvancedComponents": [\n {"ref": "J1", "definitionId": "header-pins", "at": [0, 1], "rotation": 0, "rows": 6, "cols": 1}\n ],\n "customIcs": []\n}\n```\n\nAs a `json` link (the start of it):\n\n```\nhttps://perfboarddesigner.com/app/#name=LED%20demo&json=%7B%22version%22%3A3%2C%22board%22%3A%7B%22type%22%3A%22perfboard%22%2C...\n```\n' }] }));
|
|
46568
46731
|
server.registerResource("parts", "perfboard://parts", {
|
|
46569
46732
|
title: "Parts catalog",
|
|
46570
46733
|
description: "Every part a project can place, with pins and pin labels, as JSON.",
|
|
@@ -46581,7 +46744,7 @@ function registerResources(server) {
|
|
|
46581
46744
|
|
|
46582
46745
|
// src/create-server.ts
|
|
46583
46746
|
function createServer({ editorUrl, imageUrl: imageUrl2, storage }) {
|
|
46584
|
-
const server = new McpServer({ name: "perfboard-designer", version: "0.6.
|
|
46747
|
+
const server = new McpServer({ name: "perfboard-designer", version: "0.6.1" }, { instructions: INSTRUCTIONS });
|
|
46585
46748
|
registerCatalogTools(server);
|
|
46586
46749
|
registerProjectTools(server);
|
|
46587
46750
|
registerBoardTools(server);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "perfboard-designer-mcp",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "MCP server for Perfboard Designer: lets AI agents look up parts, check perfboard and stripboard layouts, and hand back a link that opens the board in the editor.",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"mcpName": "com.perfboarddesigner/mcp",
|