@mylasertools/kerfscript 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +125 -1
- package/LANGUAGE.md +26 -11
- package/README.md +79 -5
- package/dist/ast.d.cts +13 -1
- package/dist/ast.d.ts +13 -1
- package/dist/cli.js +7509 -1629
- package/dist/diagnostics.d.cts +6 -0
- package/dist/diagnostics.d.ts +6 -0
- package/dist/evaluator.d.cts +12 -0
- package/dist/evaluator.d.ts +12 -0
- package/dist/format.d.cts +4 -0
- package/dist/format.d.ts +4 -0
- package/dist/highlight.cjs +151 -0
- package/dist/highlight.d.cts +13 -0
- package/dist/highlight.d.ts +13 -0
- package/dist/highlight.js +131 -0
- package/dist/import/dbg.d.cts +1 -0
- package/dist/import/dbg.d.ts +1 -0
- package/dist/import/index.d.cts +16 -0
- package/dist/import/index.d.ts +16 -0
- package/dist/import/shapes.d.cts +76 -0
- package/dist/import/shapes.d.ts +76 -0
- package/dist/import/svg.d.cts +48 -0
- package/dist/import/svg.d.ts +48 -0
- package/dist/import/xml.d.cts +12 -0
- package/dist/import/xml.d.ts +12 -0
- package/dist/index.cjs +391 -13
- package/dist/index.d.cts +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +391 -13
- package/dist/language.cjs +417 -0
- package/dist/language.d.cts +143 -0
- package/dist/language.d.ts +143 -0
- package/dist/language.js +417 -0
- package/dist/lexer.d.cts +17 -0
- package/dist/lexer.d.ts +17 -0
- package/dist/libraries.cjs +380 -0
- package/dist/libraries.d.cts +112 -0
- package/dist/libraries.d.ts +112 -0
- package/dist/libraries.js +380 -0
- package/dist/lsp.d.cts +12 -0
- package/dist/lsp.d.ts +12 -0
- package/dist/paths.d.cts +1 -1
- package/dist/paths.d.ts +1 -1
- package/dist/signatures.cjs +675 -0
- package/dist/signatures.d.cts +20 -0
- package/dist/signatures.d.ts +20 -0
- package/dist/signatures.js +655 -0
- package/docs/cli.md +54 -2
- package/docs/desktop.md +5 -0
- package/docs/editors.md +121 -0
- package/docs/import.md +149 -0
- package/docs/javascript.md +177 -10
- package/docs/kerf.md +10 -0
- package/docs/library/box.svg +11 -0
- package/docs/library/calibration.svg +11 -0
- package/docs/library/dividers.svg +11 -0
- package/docs/library/enclosure.svg +11 -0
- package/docs/library/hanging.svg +11 -0
- package/docs/library/hinge.svg +11 -0
- package/docs/library/tabs.svg +11 -0
- package/docs/library.md +339 -0
- package/docs/mcp.md +88 -0
- package/docs/openscad.md +1 -1
- package/docs/shared-libraries.md +229 -0
- package/docs/specification.md +529 -0
- package/docs/versions.md +2 -2
- package/package.json +52 -6
package/docs/library.md
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
# Standard library
|
|
2
|
+
|
|
3
|
+
KerfScript comes with libraries for the parts most laser-cut designs need:
|
|
4
|
+
joints, hinges, dividers, hanging holes, boxes and test pieces. They are
|
|
5
|
+
built into every KerfScript renderer: the playground, the desktop app, the
|
|
6
|
+
command line and the JavaScript and WebAssembly libraries. A design that
|
|
7
|
+
uses them works everywhere without extra files.
|
|
8
|
+
|
|
9
|
+
```kerf
|
|
10
|
+
use <kerf/tabs>
|
|
11
|
+
|
|
12
|
+
part("shelf") tab_rect([200, 60], [false, true, false, true]);
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`use` brings in a library's modules and functions. Its variables stay
|
|
16
|
+
inside it, and a module or function of your own with the same name is used
|
|
17
|
+
instead of the library's. Editors with the [language server](editors.md)
|
|
18
|
+
show each module's description when you hover over it.
|
|
19
|
+
|
|
20
|
+
| Library | Makes |
|
|
21
|
+
| ---------------------------------- | -------------------------------------------------------------- |
|
|
22
|
+
| [`kerf/box`](#boxes) | Finger-jointed boxes and dividers that slide into them |
|
|
23
|
+
| [`kerf/tabs`](#tabs-and-slots) | Tabs on one panel and the slots in another that they go into |
|
|
24
|
+
| [`kerf/hinge`](#living-hinges) | Living hinges that bend flat sheet, and a box with round sides |
|
|
25
|
+
| [`kerf/dividers`](#dividers) | Dividers that slot into each other like an egg crate |
|
|
26
|
+
| [`kerf/hanging`](#hanging) | Keyholes, holes and loops for hanging things on a wall |
|
|
27
|
+
| [`kerf/enclosure`](#enclosures) | Boxes with a screwed-on lid, cutouts for ports and vents |
|
|
28
|
+
| [`kerf/calibration`](#calibration) | Test pieces that measure the kerf and how your sheet fits |
|
|
29
|
+
|
|
30
|
+
Sizes are in millimetres. Joints use `$thickness`, the sheet thickness, so
|
|
31
|
+
set it to what you measure. Each section has an example in the gallery that
|
|
32
|
+
you can open in the playground.
|
|
33
|
+
|
|
34
|
+
## Boxes
|
|
35
|
+
|
|
36
|
+
`use <kerf/box>`
|
|
37
|
+
|
|
38
|
+

|
|
39
|
+
|
|
40
|
+
Finger-jointed boxes. Example: [box.kerf](../examples/box.kerf).
|
|
41
|
+
|
|
42
|
+
### `box(size, lid = false, finger)`
|
|
43
|
+
|
|
44
|
+
The panels of a box as parts `bottom`, `front`, `back`, `left`, `right` and,
|
|
45
|
+
with a lid, `lid`, placed for the assembled view.
|
|
46
|
+
|
|
47
|
+
| Parameter | Default | Meaning |
|
|
48
|
+
| --------- | ------------------------ | ------------------------------------------------------ |
|
|
49
|
+
| `size` | | Outside `[width, depth, height]`, lid included |
|
|
50
|
+
| `lid` | `false` | Add a lid, finger-jointed to the walls like the bottom |
|
|
51
|
+
| `finger` | `max(3 * $thickness, 6)` | Finger width |
|
|
52
|
+
|
|
53
|
+
### `divider(size, finger)`
|
|
54
|
+
|
|
55
|
+
A divider `[width, height]` with finger tabs on both sides, to slide into
|
|
56
|
+
rows of `finger_holes()` cut in two walls.
|
|
57
|
+
|
|
58
|
+
## Tabs and slots
|
|
59
|
+
|
|
60
|
+
`use <kerf/tabs>`
|
|
61
|
+
|
|
62
|
+

|
|
63
|
+
|
|
64
|
+
Tab and slot joints, for one panel standing on or through another. The
|
|
65
|
+
tabs are as deep as `$thickness`, so they finish flush with the far side.
|
|
66
|
+
Example: [spice-shelf.kerf](../examples/spice-shelf.kerf), a wall shelf
|
|
67
|
+
held together by tabs alone.
|
|
68
|
+
|
|
69
|
+
```kerf
|
|
70
|
+
use <kerf/tabs>
|
|
71
|
+
|
|
72
|
+
// A side with a slot for the shelf 40 mm up, and the shelf
|
|
73
|
+
part("side") difference() {
|
|
74
|
+
rect([60, 120]);
|
|
75
|
+
translate([0, 40]) slots(60);
|
|
76
|
+
}
|
|
77
|
+
part("shelf") tab_rect([150, 60], [false, true, false, true]);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### `tabs(length, count, width, depth)`
|
|
81
|
+
|
|
82
|
+
Tabs along x from 0 to `length`, hanging below y = 0: join them to the
|
|
83
|
+
bottom edge of a panel.
|
|
84
|
+
|
|
85
|
+
| Parameter | Default | Meaning |
|
|
86
|
+
| --------- | ------------------------------- | -------------------------- |
|
|
87
|
+
| `length` | | Length of the edge |
|
|
88
|
+
| `count` | one for every 50 mm, at least 1 | Number of tabs |
|
|
89
|
+
| `width` | half the space between tabs | Width of each tab |
|
|
90
|
+
| `depth` | `$thickness` | How far the tabs stand out |
|
|
91
|
+
|
|
92
|
+
### `slots(length, count, width, clearance = 0.1)`
|
|
93
|
+
|
|
94
|
+
The slots that `tabs()` with the same `length`, `count` and `width` go
|
|
95
|
+
through, centred on y = 0. `clearance` is added to their width and to
|
|
96
|
+
`$thickness`; [cut a slot gauge](#calibration) to find the right
|
|
97
|
+
value for your sheet.
|
|
98
|
+
|
|
99
|
+
### `tab_rect(size, edges = true, count, width)`
|
|
100
|
+
|
|
101
|
+
A rectangle `[width, height]` with tabs outside it on some edges. `edges`
|
|
102
|
+
is `true` or `false` for all four, or `[bottom, right, top, left]`.
|
|
103
|
+
|
|
104
|
+
### `tab_positions(length, count)`
|
|
105
|
+
|
|
106
|
+
The centres of the tabs along an edge, for placing anything else that
|
|
107
|
+
lines up with them.
|
|
108
|
+
|
|
109
|
+
## Living hinges
|
|
110
|
+
|
|
111
|
+
`use <kerf/hinge>`
|
|
112
|
+
|
|
113
|
+

|
|
114
|
+
|
|
115
|
+
Living hinges: rows of cuts that let plywood bend. They work best in 3 mm
|
|
116
|
+
plywood or thinner. Example: [flex-box.kerf](../examples/flex-box.kerf),
|
|
117
|
+
and [hinge-card.kerf](../examples/hinge-card.kerf) for a simple fold.
|
|
118
|
+
|
|
119
|
+
```kerf
|
|
120
|
+
use <kerf/hinge>
|
|
121
|
+
|
|
122
|
+
// A strip that bends 90° around a 10 mm radius in the middle
|
|
123
|
+
flex_rect([200, 60], [100], width = bend_length(10));
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### `bend_length(r, angle = 90)`
|
|
127
|
+
|
|
128
|
+
How long a living hinge must be to bend `angle` degrees around an inside
|
|
129
|
+
radius `r`: the length of the arc through the middle of the sheet.
|
|
130
|
+
|
|
131
|
+
### `flex_rect(size, bends, width, spacing = 1.5, bridge = 3, r = 0)`
|
|
132
|
+
|
|
133
|
+
A rectangle with a living hinge across its full height at each x in
|
|
134
|
+
`bends`.
|
|
135
|
+
|
|
136
|
+
| Parameter | Default | Meaning |
|
|
137
|
+
| --------- | ----------------------------- | ----------------------------------------------------------- |
|
|
138
|
+
| `size` | | `[width, height]` |
|
|
139
|
+
| `bends` | | List of x positions, the middle of each hinge |
|
|
140
|
+
| `width` | `bend_length(3 * $thickness)` | Width of each hinge |
|
|
141
|
+
| `spacing` | `1.5` | Distance between the rows of cuts; closer bends more easily |
|
|
142
|
+
| `bridge` | `3` | Uncut length between cuts |
|
|
143
|
+
| `r` | `0` | Corner radius of the rectangle |
|
|
144
|
+
|
|
145
|
+
### `flex_box(size, r = 15, lid = true, clearance = 0.1, spacing = 1.5, bridge = 3)`
|
|
146
|
+
|
|
147
|
+
A box with round corners whose four sides are one strip, part `side`,
|
|
148
|
+
bent at the corners. The tabs of part `bottom` go through slots along the
|
|
149
|
+
strip. Part `lid` rests on top, and part `lid insert`, glued under it,
|
|
150
|
+
keeps it in place. `size` is the outside `[width, depth, height]`, lid
|
|
151
|
+
included, and `r` the outside corner radius, more than two thicknesses.
|
|
152
|
+
The strip is bent, so the parts are not placed in an assembled view.
|
|
153
|
+
|
|
154
|
+
### `flex_panel(size, r, sw, sd)`
|
|
155
|
+
|
|
156
|
+
The bottom of `flex_box()`: a rounded rectangle with tabs on its straight
|
|
157
|
+
edges, `sw` long on the front and back and `sd` on the sides.
|
|
158
|
+
|
|
159
|
+
## Dividers
|
|
160
|
+
|
|
161
|
+
`use <kerf/dividers>`
|
|
162
|
+
|
|
163
|
+

|
|
164
|
+
|
|
165
|
+
Dividers with slots halfway up, so a divider running one way and one
|
|
166
|
+
running the other slide into each other. Example:
|
|
167
|
+
[drawer-organizer.kerf](../examples/drawer-organizer.kerf), a box from
|
|
168
|
+
`kerf/box` with a grid of dividers inside.
|
|
169
|
+
|
|
170
|
+
```kerf
|
|
171
|
+
use <kerf/dividers>
|
|
172
|
+
|
|
173
|
+
// Four compartments across, two front to back, in a 200 × 120 space
|
|
174
|
+
grid_dividers([200, 120, 40], cols = 4, rows = 2);
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### `grid_dividers(size, cols = 2, rows = 2, clearance = 0.15, gap = 0.5, scoops = false, at = [0, 0, 0])`
|
|
178
|
+
|
|
179
|
+
The dividers for a space `[width, depth, height]`, such as the inside of
|
|
180
|
+
a box, making `cols` compartments across and `rows` front to back. Parts
|
|
181
|
+
`long divider` run left to right and `cross divider` front to back.
|
|
182
|
+
|
|
183
|
+
| Parameter | Default | Meaning |
|
|
184
|
+
| ----------- | ----------- | --------------------------------------------------------------------- |
|
|
185
|
+
| `size` | | Inside `[width, depth, height]`; the dividers are this tall |
|
|
186
|
+
| `cols` | `2` | Compartments across |
|
|
187
|
+
| `rows` | `2` | Compartments front to back |
|
|
188
|
+
| `clearance` | `0.15` | Added to the slot width |
|
|
189
|
+
| `gap` | `0.5` | How far the dividers stop short of the walls |
|
|
190
|
+
| `scoops` | `false` | Dip the top edge over each compartment, to reach in |
|
|
191
|
+
| `at` | `[0, 0, 0]` | Where the space's front left bottom corner is, for the assembled view |
|
|
192
|
+
|
|
193
|
+
### `slotted_divider(length, height, at = [], from = "top", clearance = 0.15, scoops = 0)`
|
|
194
|
+
|
|
195
|
+
One divider, with a slot half its height at each x in `at`: from the top,
|
|
196
|
+
or from the bottom with `from = "bottom"`. Two dividers that cross take
|
|
197
|
+
one of each. `scoops` is the number of finger dips in the top edge.
|
|
198
|
+
|
|
199
|
+
## Hanging
|
|
200
|
+
|
|
201
|
+
`use <kerf/hanging>`
|
|
202
|
+
|
|
203
|
+

|
|
204
|
+
|
|
205
|
+
Ways to hang a panel. Each module cuts its holes out of the shapes it is
|
|
206
|
+
given; given nothing, it makes the holes themselves, for a
|
|
207
|
+
`difference()` of your own. Example:
|
|
208
|
+
[wall-sign.kerf](../examples/wall-sign.kerf), with all three ways.
|
|
209
|
+
|
|
210
|
+
```kerf
|
|
211
|
+
use <kerf/hanging>
|
|
212
|
+
|
|
213
|
+
// Two keyholes 120 mm apart, 12 mm below the top edge
|
|
214
|
+
keyholes(120, at = [80, 48]) rect([160, 60], r = 5);
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### `keyhole(at = [0, 0], head = 9, shank = 4.5, drop = 10)`
|
|
218
|
+
|
|
219
|
+
A keyhole for a screw: the head goes through the round hole, then the
|
|
220
|
+
panel drops `drop` mm so the screw rests at `at`, at the top of the slot.
|
|
221
|
+
`head` and `shank` are the widths of the hole and the slot: measure the
|
|
222
|
+
screw and add a little. `drop` must be at least `(head + shank) / 2`.
|
|
223
|
+
|
|
224
|
+
### `keyholes(spacing, at = [0, 0], head = 9, shank = 4.5, drop = 10)`
|
|
225
|
+
|
|
226
|
+
Two keyholes `spacing` apart, centred on `at`, for a panel that hangs
|
|
227
|
+
level.
|
|
228
|
+
|
|
229
|
+
### `hanging_hole(at = [0, 0], d = 5, spacing = 0)`
|
|
230
|
+
|
|
231
|
+
A round hole for a nail, a hook or a cord, or two `spacing` apart.
|
|
232
|
+
|
|
233
|
+
### `hanging_loop(at = [0, 0], d = 4, wall = 3)`
|
|
234
|
+
|
|
235
|
+
A ring `wall` wide around a hole of diameter `d`, joined to the shapes it
|
|
236
|
+
is given. Put it over the edge of an ornament or a tag: the hole stays open
|
|
237
|
+
where the ring overlaps the shape. Overlap the ring with the shape, or the
|
|
238
|
+
loop comes out as a separate piece.
|
|
239
|
+
|
|
240
|
+
## Enclosures
|
|
241
|
+
|
|
242
|
+
`use <kerf/enclosure>`
|
|
243
|
+
|
|
244
|
+

|
|
245
|
+
|
|
246
|
+
A box whose lid comes off again, for electronics. The walls and the bottom
|
|
247
|
+
are finger jointed. The lid overhangs the walls a little and is held by
|
|
248
|
+
screws that go down into the walls' top edges, each into a nut that sits
|
|
249
|
+
in a T-slot. Example: [project-enclosure.kerf](../examples/project-enclosure.kerf).
|
|
250
|
+
|
|
251
|
+
```kerf
|
|
252
|
+
use <kerf/enclosure>
|
|
253
|
+
|
|
254
|
+
enclosure([150, 100, 60], cutouts = [
|
|
255
|
+
["front", [36, 28], 8], // a round hole for a jack
|
|
256
|
+
["back", [72, 15], [13, 6.5]], // a rectangle for a USB port
|
|
257
|
+
["lid", [75, 50], [70, 30], "vents"],
|
|
258
|
+
]);
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### `enclosure(size, screw = 3, screw_length = 12, nut, lip, cutouts = [], finger)`
|
|
262
|
+
|
|
263
|
+
Parts `bottom`, `lid`, `front`, `back`, `left` and `right`, placed for the
|
|
264
|
+
assembled view. Two screws go into the front wall and two into the back,
|
|
265
|
+
and one more each for every 80 mm of width.
|
|
266
|
+
|
|
267
|
+
| Parameter | Default | Meaning |
|
|
268
|
+
| -------------- | ---------------------------- | ---------------------------------------------- |
|
|
269
|
+
| `size` | | Outside `[width, depth, height]`, lid included |
|
|
270
|
+
| `screw` | `3` | Screw diameter: 3 for M3 |
|
|
271
|
+
| `screw_length` | `12` | Screw length under the head |
|
|
272
|
+
| `nut` | `[screw * 1.9, screw * 0.9]` | `[width, height]` of the slot for the nut |
|
|
273
|
+
| `lip` | `screw` | How far the lid overhangs the walls |
|
|
274
|
+
| `cutouts` | `[]` | Holes in the panels, see below |
|
|
275
|
+
| `finger` | `max(3 * $thickness, 6)` | Finger width |
|
|
276
|
+
|
|
277
|
+
The walls stand `lip` in from the edge of the lid, so a design for an
|
|
278
|
+
`[150, 100, 60]` enclosure with M3 screws has walls 144 × 94 mm.
|
|
279
|
+
|
|
280
|
+
### `enclosure_cutouts(side, cutouts)`
|
|
281
|
+
|
|
282
|
+
The holes in `cutouts` for one panel; `enclosure()` cuts them. Each is
|
|
283
|
+
`[side, [x, y], size]`:
|
|
284
|
+
|
|
285
|
+
- `side` is `"front"`, `"back"`, `"left"`, `"right"`, `"lid"` or `"bottom"`.
|
|
286
|
+
- `[x, y]` is the middle of the hole on the panel as it is drawn, from its
|
|
287
|
+
bottom left corner. On the front and back x runs left to right as seen
|
|
288
|
+
from the front; on the sides it runs from front to back. y runs up from
|
|
289
|
+
the bottom of the wall.
|
|
290
|
+
- A number `size` is a round hole of that diameter, `[width, height]` a
|
|
291
|
+
rectangle. Add `"vents"` after a rectangle to fill it with vents.
|
|
292
|
+
|
|
293
|
+
### `vents(size, slot = 3, pitch = 6)`
|
|
294
|
+
|
|
295
|
+
Ventilation slots across `[width, height]`, centred on the origin: upright
|
|
296
|
+
slots `slot` wide with round ends, `pitch` apart.
|
|
297
|
+
|
|
298
|
+
## Calibration
|
|
299
|
+
|
|
300
|
+
`use <kerf/calibration>`
|
|
301
|
+
|
|
302
|
+

|
|
303
|
+
|
|
304
|
+
Test pieces to cut once for every new material, before a design that has
|
|
305
|
+
to fit. Their labels are text, so they need a font, as
|
|
306
|
+
[`text()`](../LANGUAGE.md#shapes) does; `labels = false` leaves them off.
|
|
307
|
+
Example: [calibration-set.kerf](../examples/calibration-set.kerf); the
|
|
308
|
+
[Kerf](kerf.md) guide explains what to do with the results.
|
|
309
|
+
|
|
310
|
+
```kerf
|
|
311
|
+
use <kerf/calibration>
|
|
312
|
+
|
|
313
|
+
$thickness = 3;
|
|
314
|
+
part("kerf gauge") kerf_gauge();
|
|
315
|
+
part("slot gauge") slot_gauge();
|
|
316
|
+
joint_test([0.1, 0.15, 0.2]);
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
### `kerf_gauge(strips = 10, size = [60, 25], labels = true)`
|
|
320
|
+
|
|
321
|
+
A frame with `strips` strips inside, all separated by single cuts.
|
|
322
|
+
Single cut lines are not moved by kerf compensation, so each takes away
|
|
323
|
+
one kerf. Push the strips to one side and measure the gap they leave: the
|
|
324
|
+
kerf is the gap divided by `strips + 1`. `size` is the window the strips
|
|
325
|
+
fill.
|
|
326
|
+
|
|
327
|
+
### `slot_gauge(steps = 7, step = 0.1, depth = 15, labels = true)`
|
|
328
|
+
|
|
329
|
+
A comb of `steps` slots, from narrower than `$thickness` to wider, `step`
|
|
330
|
+
apart, each labelled with the difference. Try a scrap of the same sheet in
|
|
331
|
+
each: the one that fits as you want is the clearance for `slots()` and
|
|
332
|
+
`grid_dividers()`.
|
|
333
|
+
|
|
334
|
+
### `joint_test(kerfs = [0.1, 0.15, 0.2], size = [40, 20], finger, labels = true)`
|
|
335
|
+
|
|
336
|
+
A pair of finger-jointed pieces for each kerf in `kerfs`, parts
|
|
337
|
+
`joint <kerf> out` and `joint <kerf> in`, each cut with that kerf
|
|
338
|
+
compensation. The pair that holds together without glue or forcing has
|
|
339
|
+
the kerf to set for this sheet.
|
package/docs/mcp.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# AI assistants
|
|
2
|
+
|
|
3
|
+
The KerfScript MCP server lets an AI assistant write and check laser-cutting
|
|
4
|
+
designs. Through the [Model Context Protocol](https://modelcontextprotocol.io)
|
|
5
|
+
it reads this documentation and the examples, finds a design's settings and
|
|
6
|
+
renders it to SVG or DXF, so the assistant can try its code before giving it
|
|
7
|
+
to you.
|
|
8
|
+
|
|
9
|
+
It has four tools:
|
|
10
|
+
|
|
11
|
+
| Tool | What it does |
|
|
12
|
+
| ----------------------- | ------------------------------------------------------------------------------ |
|
|
13
|
+
| `kerfscript_docs` | Reads the guides and the language reference |
|
|
14
|
+
| `kerfscript_examples` | Finds examples by title or tag and returns their source |
|
|
15
|
+
| `kerfscript_parameters` | Lists a design's settings with their ranges and choices |
|
|
16
|
+
| `kerfscript_render` | Renders a design to SVG or DXF, with its parts, sizes, layers and any warnings |
|
|
17
|
+
|
|
18
|
+
## Connecting
|
|
19
|
+
|
|
20
|
+
The hosted server needs no account or key:
|
|
21
|
+
|
|
22
|
+
```text
|
|
23
|
+
https://mcp.mylasertools.com/mcp
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Claude Code**
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
claude mcp add --transport http kerfscript https://mcp.mylasertools.com/mcp
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Claude** (desktop and web): Settings → Connectors → Add custom connector, and
|
|
33
|
+
enter the address above.
|
|
34
|
+
|
|
35
|
+
**Cursor**: add it to `.cursor/mcp.json`:
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"mcpServers": {
|
|
40
|
+
"kerfscript": { "url": "https://mcp.mylasertools.com/mcp" }
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**VS Code**: add it to `.vscode/mcp.json`:
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{
|
|
49
|
+
"servers": {
|
|
50
|
+
"kerfscript": { "type": "http", "url": "https://mcp.mylasertools.com/mcp" }
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Other assistants that support remote MCP servers take the same address.
|
|
56
|
+
|
|
57
|
+
## Running it yourself
|
|
58
|
+
|
|
59
|
+
The same server runs on your computer with Node.js 20 or newer. Designs then
|
|
60
|
+
never leave your machine:
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"mcpServers": {
|
|
65
|
+
"kerfscript": { "command": "npx", "args": ["-y", "@mylasertools/kerfscript-mcp"] }
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
In Claude Code:
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
claude mcp add kerfscript -- npx -y @mylasertools/kerfscript-mcp
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Limits
|
|
77
|
+
|
|
78
|
+
A design may be up to 64,000 characters, with up to 20 libraries of its own
|
|
79
|
+
passed alongside it. It cannot read files or fetch anything from the network.
|
|
80
|
+
Each render stops at 100,000 steps, 100 parts and 10 sheets, and text uses the
|
|
81
|
+
bundled Atkinson Hyperlegible font. For bigger designs or other fonts, use the
|
|
82
|
+
[command line](cli.md) or the [JavaScript API](javascript.md).
|
|
83
|
+
|
|
84
|
+
The hosted server allows each client about 60 requests a minute and 1,000 a
|
|
85
|
+
day. It does not store or log the designs you send.
|
|
86
|
+
|
|
87
|
+
A render that succeeds does not mean the parts fit. Check a new design against
|
|
88
|
+
your material with a [test piece](library.md#calibration) before cutting it.
|
package/docs/openscad.md
CHANGED
|
@@ -10,7 +10,7 @@ You can use familiar building blocks:
|
|
|
10
10
|
|
|
11
11
|
- Modules, functions, `for`, `if`, `let`, `each`, list comprehensions,
|
|
12
12
|
ranges and function literals.
|
|
13
|
-
- `children()`, `children(
|
|
13
|
+
- `children()`, `children(index)` and `$children`.
|
|
14
14
|
- Dynamically scoped `$` variables, plus `$fn`, `$fa` and `$fs` for curve
|
|
15
15
|
resolution.
|
|
16
16
|
- 2D shapes: `square()` or `rect()`, `circle()`, `polygon()` and `text()`.
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# Shared libraries
|
|
2
|
+
|
|
3
|
+
A shared library is a folder of `.kerf` files with a `kerf.json` that names
|
|
4
|
+
it. You publish one by tagging a GitHub repository, or by putting a `.tar.gz`
|
|
5
|
+
anywhere that serves it over https. A project lists the libraries its designs
|
|
6
|
+
use in its own `kerf.json`. `kerf install` copies them into `kerf_libraries/`
|
|
7
|
+
and pins each one in `kerf.lock`, by its exact commit and a hash of its
|
|
8
|
+
files, so a design renders the same way on every machine, now and later.
|
|
9
|
+
|
|
10
|
+
The [standard library](library.md) is built into every renderer and needs
|
|
11
|
+
none of this: `use <kerf/box>` always works.
|
|
12
|
+
|
|
13
|
+
## Use a library
|
|
14
|
+
|
|
15
|
+
In the folder that holds your designs:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
kerf add github:maker/kerf-feet@v1.0.0
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
This creates a `kerf.json` the first time:
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
"libraries": {
|
|
26
|
+
"feet": "github:maker/kerf-feet@v1.0.0"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The library's own `kerf.json` gives its name, here `feet`. Its files go into
|
|
32
|
+
`kerf_libraries/feet/`, and `kerf.lock` records exactly what was installed.
|
|
33
|
+
A design then loads them with the library's name first:
|
|
34
|
+
|
|
35
|
+
```kerf
|
|
36
|
+
use <feet/feet>
|
|
37
|
+
|
|
38
|
+
part("base") difference() {
|
|
39
|
+
rect([100, 60]);
|
|
40
|
+
feet([100, 60]);
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`kerf render`, `kerf check`, the desktop app and the language server in your
|
|
45
|
+
editor all find it. The playground has the standard library only.
|
|
46
|
+
|
|
47
|
+
A source is one of:
|
|
48
|
+
|
|
49
|
+
| Source | Means |
|
|
50
|
+
| ----------------------------- | ----------------------------------------------------------------------------------- |
|
|
51
|
+
| `github:owner/repo@v1.0.0` | A GitHub repository at a tag, a branch or a commit; without `@`, its default branch |
|
|
52
|
+
| `https://…/feet-1.0.0.tar.gz` | A `.tar.gz` such as `kerf pack` writes, from any https link |
|
|
53
|
+
| `./libraries/feet` | A folder on this computer, for a library you are writing |
|
|
54
|
+
|
|
55
|
+
To change version, add it again with the new tag; `kerf add` replaces the
|
|
56
|
+
source. `kerf remove feet` takes a library out.
|
|
57
|
+
|
|
58
|
+
## What to commit
|
|
59
|
+
|
|
60
|
+
Commit `kerf.json` and `kerf.lock`. Then either:
|
|
61
|
+
|
|
62
|
+
- commit `kerf_libraries/` too, so the project works without a download,
|
|
63
|
+
in the desktop app as well, or
|
|
64
|
+
- leave it out (add it to `.gitignore`) and run `kerf install` after each
|
|
65
|
+
clone. It downloads the exact files `kerf.lock` pins.
|
|
66
|
+
|
|
67
|
+
## How a design finds a library
|
|
68
|
+
|
|
69
|
+
For a path that does not start with `kerf/`, a design looks in its project,
|
|
70
|
+
the nearest folder at or above the design's own with a `kerf.json`:
|
|
71
|
+
|
|
72
|
+
1. `use <name/...>`, where `name` is the project's own name in its
|
|
73
|
+
`kerf.json`: a file of the project, from its top folder. A library uses
|
|
74
|
+
this for its own files, and so do the designs and examples inside it.
|
|
75
|
+
2. `use <name/...>`, where `kerf_libraries/name/` exists: that installed
|
|
76
|
+
library's file.
|
|
77
|
+
3. Anything else: a file in the design's folder or below it, as before.
|
|
78
|
+
|
|
79
|
+
Each path is tried as written and with `.kerf` added. A design in
|
|
80
|
+
`projects/shelf/designs/` therefore finds `use <feet/feet>` in
|
|
81
|
+
`projects/shelf/kerf_libraries/feet/feet.kerf` when `projects/shelf/` has
|
|
82
|
+
the `kerf.json`.
|
|
83
|
+
|
|
84
|
+
## Reproducing a design
|
|
85
|
+
|
|
86
|
+
`kerf.lock` holds one entry for each library, including the ones other
|
|
87
|
+
libraries use:
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{
|
|
91
|
+
"lockVersion": 1,
|
|
92
|
+
"libraries": {
|
|
93
|
+
"feet": {
|
|
94
|
+
"source": "github:maker/kerf-feet@v1.0.0",
|
|
95
|
+
"version": "1.0.0",
|
|
96
|
+
"resolved": "https://github.com/maker/kerf-feet/archive/3f2c…e91a.tar.gz",
|
|
97
|
+
"integrity": "sha256-4hC4hj++68l+quohmEdLL/KYF9lwtTD7Hon6G+5V9kY="
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
- `resolved` is the exact commit. A tag can be moved to other code later; the
|
|
104
|
+
commit cannot, so `kerf install` downloads from here, not from the tag.
|
|
105
|
+
- `integrity` is a sha256 hash of the library's files. `kerf install` refuses
|
|
106
|
+
files that do not match it. The hash ignores line endings, so git's
|
|
107
|
+
conversions on Windows do not change it.
|
|
108
|
+
|
|
109
|
+
In CI, install exactly what is pinned, and fail if `kerf.lock` would need to
|
|
110
|
+
change:
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
kerf install --frozen
|
|
114
|
+
kerf render designs/shelf.kerf -o shelf.svg
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
`kerf install --check` downloads nothing. It checks that `kerf.json`,
|
|
118
|
+
`kerf.lock` and `kerf_libraries/` agree, and that no one has edited an
|
|
119
|
+
installed file. It exits with 1 and lists the differences when they do not.
|
|
120
|
+
|
|
121
|
+
The libraries are one part of a design's output; the renderer is the other.
|
|
122
|
+
Pin the `kerf` or npm package version too, as in [Versions](versions.md).
|
|
123
|
+
|
|
124
|
+
## Libraries that use libraries
|
|
125
|
+
|
|
126
|
+
A library's `kerf.json` can name libraries of its own, and `kerf install`
|
|
127
|
+
installs them too. There is one copy of each name in `kerf_libraries/`. When
|
|
128
|
+
two libraries want the same library from different sources, the install
|
|
129
|
+
stops and asks you to choose. Add that library to your own `kerf.json`; the
|
|
130
|
+
project's choice wins:
|
|
131
|
+
|
|
132
|
+
```json
|
|
133
|
+
{
|
|
134
|
+
"libraries": {
|
|
135
|
+
"stand": "github:maker/kerf-stand@v2.0.0",
|
|
136
|
+
"lamp": "github:other/kerf-lamp@v1.4.0",
|
|
137
|
+
"feet": "github:maker/kerf-feet@v1.1.0"
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Publish a library
|
|
143
|
+
|
|
144
|
+
A library's top folder holds its `kerf.json`:
|
|
145
|
+
|
|
146
|
+
```json
|
|
147
|
+
{
|
|
148
|
+
"name": "feet",
|
|
149
|
+
"version": "1.0.0",
|
|
150
|
+
"description": "Holes for rubber feet",
|
|
151
|
+
"license": "MIT",
|
|
152
|
+
"language": "0.2",
|
|
153
|
+
"libraries": {}
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
| Field | Use |
|
|
158
|
+
| ------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
159
|
+
| `name` | Required. Lowercase letters, digits, `-` and `_`. Designs write `use <name/...>`. `kerf` is the standard library's |
|
|
160
|
+
| `version` | Required to pack. `1.2.0`: raise the first number when a module's parameters change, or when existing designs would cut differently |
|
|
161
|
+
| `description` | One line on what it makes |
|
|
162
|
+
| `license` | The licence others may use it under |
|
|
163
|
+
| `language` | The oldest KerfScript language version it works with; older `kerf` versions refuse to install it |
|
|
164
|
+
| `libraries` | Libraries it uses, from `github:` or `https:` sources |
|
|
165
|
+
|
|
166
|
+
A library is its `.kerf` files in any folder, its `kerf.json`, and the
|
|
167
|
+
`README`, `LICENSE` and `CHANGELOG` in its top folder. Pictures, tests and
|
|
168
|
+
dot folders such as `.github` are left out when it is installed.
|
|
169
|
+
|
|
170
|
+
Inside the library, load its own files by its name, `use <feet/size>`, not
|
|
171
|
+
`use <size>`. That works while you write it, since the project is named
|
|
172
|
+
`feet`, and once it is installed next to someone else's designs. Put a
|
|
173
|
+
comment above each module: editors show it on hover, as for the
|
|
174
|
+
[standard library](library.md).
|
|
175
|
+
|
|
176
|
+
Before each release, run:
|
|
177
|
+
|
|
178
|
+
```sh
|
|
179
|
+
kerf pack
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
It parses every `.kerf` file and checks every `use <...>`. Each must name the
|
|
183
|
+
standard library, the library's own files as `<name/...>`, or a library in
|
|
184
|
+
its `kerf.json`. Then it writes `feet-1.0.0.tar.gz`. To publish:
|
|
185
|
+
|
|
186
|
+
1. On GitHub, commit, then tag the version and push the tag:
|
|
187
|
+
`git tag v1.0.0 && git push origin v1.0.0`. Others run
|
|
188
|
+
`kerf add github:you/kerf-feet@v1.0.0`.
|
|
189
|
+
2. Anywhere else, upload the `.tar.gz` (a GitHub release asset works too), and
|
|
190
|
+
others run `kerf add https://…/feet-1.0.0.tar.gz`.
|
|
191
|
+
|
|
192
|
+
Do not move a tag or replace a file once it is published. The projects that
|
|
193
|
+
pinned it would no longer install; publish a new version instead.
|
|
194
|
+
|
|
195
|
+
## Safety
|
|
196
|
+
|
|
197
|
+
A KerfScript program cannot read files or reach the network, so a library can
|
|
198
|
+
only make shapes and run within the renderer's step limits. `kerf install`
|
|
199
|
+
writes only inside `kerf_libraries/`. It refuses an archive with a file that
|
|
200
|
+
would land outside its folder, a plain `http://` link (except on this
|
|
201
|
+
computer), and a download over 20 MB. The desktop app reads only `.kerf`
|
|
202
|
+
files, and only from the design's folder and the project's.
|
|
203
|
+
|
|
204
|
+
## From JavaScript
|
|
205
|
+
|
|
206
|
+
The `@mylasertools/kerfscript/libraries` module, for Node.js, finds and
|
|
207
|
+
installs libraries the same way the command line does:
|
|
208
|
+
|
|
209
|
+
```js
|
|
210
|
+
import { render } from '@mylasertools/kerfscript';
|
|
211
|
+
import { resolver, install, check } from '@mylasertools/kerfscript/libraries';
|
|
212
|
+
import { readFileSync } from 'node:fs';
|
|
213
|
+
|
|
214
|
+
await install('projects/shelf', { frozen: true });
|
|
215
|
+
const file = 'projects/shelf/designs/shelf.kerf';
|
|
216
|
+
const result = render(readFileSync(file, 'utf8'), { resolve: resolver(file) });
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
| Export | Does |
|
|
220
|
+
| ----------------------------------------- | ---------------------------------------------------------------- |
|
|
221
|
+
| `resolver(designFile)` | A `resolve` option for `render()` that finds libraries as above |
|
|
222
|
+
| `libraryFile(folder, path)` | The file `use <path>` names for a design in `folder` |
|
|
223
|
+
| `findProject(folder)` | The nearest folder at or above `folder` with a `kerf.json` |
|
|
224
|
+
| `install(root, { frozen, fetch, log })` | `kerf install`; resolves to the new `kerf.lock` |
|
|
225
|
+
| `add(root, source)`, `remove(root, name)` | `kerf add`, `kerf remove` |
|
|
226
|
+
| `check(root)` | `kerf install --check`: a list of problems, empty when all agree |
|
|
227
|
+
| `pack(root, out?)` | `kerf pack` |
|
|
228
|
+
|
|
229
|
+
Problems are thrown as `LibraryError`, with a message to show as it is.
|