@mylasertools/kerfscript 0.5.0 → 0.7.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 +195 -1
- package/LANGUAGE.md +160 -30
- package/README.md +22 -5
- package/THIRD-PARTY-NOTICES.md +113 -0
- package/dist/analysis.d.cts +20 -0
- package/dist/analysis.d.ts +20 -0
- package/dist/assembly.d.cts +28 -1
- package/dist/assembly.d.ts +28 -1
- package/dist/ast.d.cts +9 -0
- package/dist/ast.d.ts +9 -0
- package/dist/cli.js +13060 -5013
- package/dist/diff.d.cts +18 -0
- package/dist/diff.d.ts +18 -0
- package/dist/evaluator.d.cts +34 -0
- package/dist/evaluator.d.ts +34 -0
- package/dist/functions.d.cts +1 -0
- package/dist/functions.d.ts +1 -0
- package/dist/geometry.d.cts +17 -0
- package/dist/geometry.d.ts +17 -0
- package/dist/hardware.d.cts +13 -0
- package/dist/hardware.d.ts +13 -0
- package/dist/highlight.cjs +2 -2
- package/dist/highlight.js +2 -2
- 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 +1955 -32
- package/dist/index.d.cts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.js +1955 -32
- package/dist/instructions.d.cts +3 -0
- package/dist/instructions.d.ts +3 -0
- package/dist/language.cjs +1899 -51
- package/dist/language.js +1899 -51
- package/dist/libraries.cjs +1874 -26
- package/dist/libraries.d.cts +3 -0
- package/dist/libraries.d.ts +3 -0
- package/dist/libraries.js +1874 -26
- package/dist/paths.d.cts +1 -1
- package/dist/paths.d.ts +1 -1
- package/dist/png.d.cts +9 -0
- package/dist/png.d.ts +9 -0
- package/dist/render.d.cts +22 -1
- package/dist/render.d.ts +22 -1
- package/dist/signatures.cjs +244 -11
- package/dist/signatures.js +244 -11
- package/dist/slots.d.cts +8 -0
- package/dist/slots.d.ts +8 -0
- package/dist/values.d.cts +6 -1
- package/dist/values.d.ts +6 -1
- package/dist/verify/command.d.cts +1 -0
- package/dist/verify/command.d.ts +1 -0
- package/dist/verify/geometry.d.cts +25 -0
- package/dist/verify/geometry.d.ts +25 -0
- package/dist/verify/index.d.cts +10 -0
- package/dist/verify/index.d.ts +10 -0
- package/dist/verify/joints.d.cts +7 -0
- package/dist/verify/joints.d.ts +7 -0
- package/dist/verify/mechanics.d.cts +11 -0
- package/dist/verify/mechanics.d.ts +11 -0
- package/dist/verify/motion.d.cts +8 -0
- package/dist/verify/motion.d.ts +8 -0
- package/dist/verify/pose.d.cts +5 -0
- package/dist/verify/pose.d.ts +5 -0
- package/dist/verify/relations.d.cts +8 -0
- package/dist/verify/relations.d.ts +8 -0
- package/dist/verify/snapshot.d.cts +11 -0
- package/dist/verify/snapshot.d.ts +11 -0
- package/dist/verify/solids.d.cts +39 -0
- package/dist/verify/solids.d.ts +39 -0
- package/dist/verify/spec.d.cts +9 -0
- package/dist/verify/spec.d.ts +9 -0
- package/dist/verify/summary.d.cts +17 -0
- package/dist/verify/summary.d.ts +17 -0
- package/dist/verify/types.d.cts +299 -0
- package/dist/verify/types.d.ts +299 -0
- package/docs/cli.md +96 -15
- package/docs/import.md +149 -0
- package/docs/javascript.md +88 -25
- package/docs/layers.md +42 -2
- package/docs/library/calibration.svg +1 -1
- package/docs/library/hanging.svg +1 -1
- package/docs/library/hinge.svg +1 -1
- package/docs/library.md +299 -3
- package/docs/mcp.md +88 -0
- package/docs/parts-and-sheets.md +186 -1
- package/docs/shared-libraries.md +8 -1
- package/docs/specification.md +78 -23
- package/docs/verification.md +363 -0
- package/docs/versions.md +2 -2
- package/package.json +3 -3
package/docs/cli.md
CHANGED
|
@@ -47,10 +47,14 @@ to try these commands.
|
|
|
47
47
|
kerf render <file.kerf> [-o out.svg] [options]
|
|
48
48
|
kerf params <file.kerf>
|
|
49
49
|
kerf check <file.kerf>
|
|
50
|
+
kerf verify <file.kerf> --spec <file.json> [-o report.json] [--summary]
|
|
51
|
+
kerf diff <a.kerf> <b.kerf> [-D name=value] [--json]
|
|
52
|
+
kerf instructions <file.kerf> [-o out.html] [options]
|
|
50
53
|
kerf fmt <files or folders>
|
|
51
54
|
kerf fmt --check <files or folders>
|
|
52
55
|
kerf fmt -
|
|
53
56
|
kerf lsp [--timeout <seconds>]
|
|
57
|
+
kerf import <file.svg> [-o out.kerf] [--dpi <n>] [--tolerance <mm>] [--kerf <mm>] [--pack]
|
|
54
58
|
kerf add <source>
|
|
55
59
|
kerf remove <name>
|
|
56
60
|
kerf install [--frozen | --check]
|
|
@@ -61,6 +65,11 @@ kerf pack [folder] [-o file]
|
|
|
61
65
|
choose the format. `params` lists the editable settings as JSON. `check`
|
|
62
66
|
reports parts, dimensions, cut lengths, sheets and warnings.
|
|
63
67
|
|
|
68
|
+
`verify` checks explicit rigid fit, retention, installation and motion contracts and writes a JSON report. It
|
|
69
|
+
exits with 0 for passed required claims, 1 for failures, and 2 for unverified or
|
|
70
|
+
invalid inputs. See [Assembly verification](verification.md) for supported claims,
|
|
71
|
+
material profiles and the limits of a pass.
|
|
72
|
+
|
|
64
73
|
`fmt` formats `.kerf` files in place, searching folders for them, except
|
|
65
74
|
`kerf_libraries/`, whose files `kerf.lock` pins as they are. It sets
|
|
66
75
|
indentation (two spaces), the spaces between tokens, blank lines (at most one
|
|
@@ -71,6 +80,13 @@ exits with 1 when there are any, for CI. `kerf fmt -` formats standard input
|
|
|
71
80
|
to standard output, for editors. A file that does not parse is reported and
|
|
72
81
|
left alone.
|
|
73
82
|
|
|
83
|
+
`import` turns an SVG drawing into a `.kerf` program next to it, or to the
|
|
84
|
+
`-o` file; `-o -` prints it. It does not replace a program already next to
|
|
85
|
+
the drawing unless that file is named with `-o`. It writes the circles, rectangles, tabs, slots,
|
|
86
|
+
finger joints, hanger holes and keyholes it finds as the modules that make
|
|
87
|
+
them, and checks each part against the drawing: see
|
|
88
|
+
[Importing SVG drawings](import.md) for what it finds and for its options.
|
|
89
|
+
|
|
74
90
|
`lsp` runs the language server on standard input and output, for editors:
|
|
75
91
|
see [Editors](editors.md). It stops checking a design after `--timeout`
|
|
76
92
|
seconds, 10 by default.
|
|
@@ -88,25 +104,89 @@ installed libraries by themselves.
|
|
|
88
104
|
|
|
89
105
|
## Options
|
|
90
106
|
|
|
91
|
-
| Option
|
|
92
|
-
|
|
|
93
|
-
| `-o, --out <file>`
|
|
94
|
-
| `-D name=value`
|
|
95
|
-
| `-p, --params <file>`
|
|
96
|
-
| `--font <file.ttf>`
|
|
97
|
-
| `--kerf <mm>`
|
|
98
|
-
| `--sheet <W>x<H>`
|
|
99
|
-
| `--gap <mm>`
|
|
100
|
-
| `--margin <mm>`
|
|
101
|
-
| `--no-pack`
|
|
102
|
-
| `--guides`
|
|
103
|
-
| `--split`
|
|
104
|
-
|
|
|
105
|
-
|
|
|
107
|
+
| Option | Use |
|
|
108
|
+
| ---------------------- | ------------------------------------------------------------------------------------ |
|
|
109
|
+
| `-o, --out <file>` | Output path ending in `.svg`, `.dxf` or `.json`; defaults to `<file>.svg` |
|
|
110
|
+
| `-D name=value` | Override a parameter; repeat for multiple values |
|
|
111
|
+
| `-p, --params <file>` | Load parameter values from a JSON file |
|
|
112
|
+
| `--font <file.ttf>` | Supply a font file; repeat for multiple fonts. `Atkinson` is built in |
|
|
113
|
+
| `--kerf <mm>` | Override kerf for every part |
|
|
114
|
+
| `--sheet <W>x<H>` | Set the sheet width and height in millimetres |
|
|
115
|
+
| `--gap <mm>` | Set spacing between parts |
|
|
116
|
+
| `--margin <mm>` | Set spacing at sheet edges; defaults to the gap |
|
|
117
|
+
| `--no-pack` | Keep the positions defined in the program |
|
|
118
|
+
| `--guides` | Include the guide layer |
|
|
119
|
+
| `--split` | Export one file per sheet, and each sheet's back-face job |
|
|
120
|
+
| `--nest` | Pack small parts into the holes of bigger ones |
|
|
121
|
+
| `--stats` | With `check`: points in the files, by part and layer |
|
|
122
|
+
| `--sweep name=a:s:b` | With `check`: try every value from a to b in steps of s, or `name=a,b,c` |
|
|
123
|
+
| `-o out.png`, `--px n` | A picture of each sheet, `n` pixels wide (1200), to look at rather than cut |
|
|
124
|
+
| `--call 'm(1, 2)'` | Run one call of the file's modules instead of its program; `-D` sets variables first |
|
|
125
|
+
| `--params-list file` | With `check`: try each set of settings in a JSON list of objects |
|
|
126
|
+
| `-h, --help` | Show command help |
|
|
127
|
+
| `-v, --version` | Show version numbers |
|
|
106
128
|
|
|
107
129
|
`-D` accepts KerfScript values, including numbers, quoted strings, booleans
|
|
108
130
|
and lists. For example: `-D width=200` or `-D 'name="Ada"'`.
|
|
109
131
|
|
|
132
|
+
`kerf check` lists the parts, how many make each glued stack and what a
|
|
133
|
+
part is glued to, the hardware to buy, alike pieces counted together, and
|
|
134
|
+
the assembly steps. A design with marks on the parts' back faces writes a
|
|
135
|
+
second file beside the first, `design-back.svg`: the sheet turned over
|
|
136
|
+
left to right, for the job after the parts are turned over.
|
|
137
|
+
|
|
138
|
+
`--sweep` checks a design over many settings at once. Repeat it to try
|
|
139
|
+
every combination; each line says `ok` or lists what went wrong, and the
|
|
140
|
+
command exits with 1 if any combination warns or fails:
|
|
141
|
+
|
|
142
|
+
```sh
|
|
143
|
+
kerf check tray.kerf --sweep '$thickness=3:0.5:6' --sweep size=small,large
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Settings that only make sense together go in one `--sweep`, their names
|
|
147
|
+
joined by commas and each set of values after a `;`, so the sets are tried
|
|
148
|
+
as they are rather than crossed. `--params-list` reads the sets from a JSON
|
|
149
|
+
list instead; both cross with the other sweeps:
|
|
150
|
+
|
|
151
|
+
```sh
|
|
152
|
+
kerf check room.kerf --sweep 'width,depth,height=115,140,190;160,200,260' --sweep '$thickness=3,4'
|
|
153
|
+
kerf check room.kerf --params-list sizes.json
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
`--call` tries one module of a library on its own, without writing a
|
|
157
|
+
design for it. The file's modules and functions are available, as with
|
|
158
|
+
`use`; `-D` values are set first, so they can be special variables or
|
|
159
|
+
names in the call:
|
|
160
|
+
|
|
161
|
+
```sh
|
|
162
|
+
kerf render lib/props.kerf --call 'roses(40, 30)' -D '$thickness=4' -o roses.svg
|
|
163
|
+
kerf check lib/kerf/box.kerf --call 'box([w, 40, 30])' -D w=60
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
`kerf instructions` writes the assembly instructions as one HTML page to
|
|
167
|
+
print or save as PDF: the parts list with each part's number, the sheets,
|
|
168
|
+
then a page per `step()` with the model drawn as it stands after it, the
|
|
169
|
+
step's parts in orange, and the parts and hardware it adds. With
|
|
170
|
+
`$label_parts = true` the numbers match the ones engraved on the parts.
|
|
171
|
+
|
|
172
|
+
```sh
|
|
173
|
+
kerf instructions lock-box.kerf -o lock-box-instructions.html
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
`kerf diff` renders two designs (or one design before and after a change)
|
|
177
|
+
with the same settings and lists, part by part and layer by layer, what
|
|
178
|
+
differs: the area of shapes that changed, open lines added or removed, and
|
|
179
|
+
where, in the part's own coordinates. It exits 1 if anything changed, so a
|
|
180
|
+
refactor can prove it changed nothing:
|
|
181
|
+
|
|
182
|
+
```sh
|
|
183
|
+
kerf diff old/garage.kerf garage.kerf
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
The `"sheet": [600, 400]` in a project's `kerf.json` is the sheet for every
|
|
187
|
+
design in the project that does not set `$sheet`: set your laser's bed
|
|
188
|
+
once.
|
|
189
|
+
|
|
110
190
|
## Examples
|
|
111
191
|
|
|
112
192
|
```sh
|
|
@@ -114,6 +194,7 @@ kerf render name-sign.kerf -D 'name="Ada"' --font Inter-Bold.ttf -o ada.svg
|
|
|
114
194
|
kerf render box.kerf --sheet 400x300 --kerf 0.12 --split -o box.svg
|
|
115
195
|
kerf render box.kerf -o box.dxf
|
|
116
196
|
kerf check box.kerf
|
|
197
|
+
kerf import ornament.svg -o ornament.kerf
|
|
117
198
|
```
|
|
118
199
|
|
|
119
200
|
For multiple sheets, `--split` creates numbered files such as `box-1.svg`
|
package/docs/import.md
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# Importing SVG drawings
|
|
2
|
+
|
|
3
|
+
`kerf import` turns an SVG drawing into a KerfScript program that cuts the
|
|
4
|
+
same shapes. Use it to make an existing design parametric, or to continue
|
|
5
|
+
a design drawn in Inkscape, Illustrator or a box generator.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
kerf import ornament.svg # writes ornament.kerf, if there is none
|
|
9
|
+
kerf import ornament.svg -o tree.kerf
|
|
10
|
+
kerf import ornament.svg -o - # prints the program
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
In the [playground](https://kerfscript.mylasertools.com/playground/),
|
|
14
|
+
choose **Import SVG** or drop an SVG file on the editor: the program opens
|
|
15
|
+
in the editor, and the console says what was found.
|
|
16
|
+
|
|
17
|
+
The importer looks for the shapes KerfScript has modules for and writes
|
|
18
|
+
those modules instead of a list of points:
|
|
19
|
+
|
|
20
|
+
| In the drawing | In the program |
|
|
21
|
+
| -------------------------------------------------- | ----------------------------------------------- |
|
|
22
|
+
| Circles, ellipses, rectangles, rounded rectangles | `circle()`, `ellipse()`, `rect()` |
|
|
23
|
+
| Regular polygons and stars | `regular_polygon()`, `star()` |
|
|
24
|
+
| A small round hole high up in the middle of a part | `hanging_hole()`, or two of them with `spacing` |
|
|
25
|
+
| A round hole with a slot, for hanging on a screw | `keyhole()`, or `keyholes()` for a level pair |
|
|
26
|
+
| A ring around a hole on the edge of an ornament | `hanging_loop()` |
|
|
27
|
+
| A rectangle with tabs | `tab_rect()`, or `tabs()` on each side |
|
|
28
|
+
| A row of slots the tabs go through | `slots()` |
|
|
29
|
+
| A rectangle with finger joints | `finger_rect()` |
|
|
30
|
+
| Holes a divider's fingers go through | `finger_holes()` |
|
|
31
|
+
| Fingers and notches from another program | `rect()` with the notches cut out, in loops |
|
|
32
|
+
| The same hole repeated in a row or a grid | a `for` loop |
|
|
33
|
+
| Anything else | `polygon()` or `path()`, exactly as drawn |
|
|
34
|
+
|
|
35
|
+
For example, a sign with a hanger hole, a keyhole and a row of holes comes
|
|
36
|
+
back as:
|
|
37
|
+
|
|
38
|
+
```kerf
|
|
39
|
+
// sign.svg: imported from an SVG drawing.
|
|
40
|
+
// 1 part; found 1 rectangle, 1 hanger hole, 7 circles, 1 hole pattern, 1 keyhole.
|
|
41
|
+
|
|
42
|
+
use <kerf/hanging>
|
|
43
|
+
|
|
44
|
+
$layout = "none"; // keep the parts where the drawing has them
|
|
45
|
+
|
|
46
|
+
translate([3, 3]) part("sign") {
|
|
47
|
+
difference() {
|
|
48
|
+
rect([120, 80], r = 5);
|
|
49
|
+
hanging_hole([60, 70]);
|
|
50
|
+
for (x = [30:10:90]) translate([x, 30]) circle(d = 3);
|
|
51
|
+
translate([20, 60]) keyhole();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Change a number and render it to get a new version of the design.
|
|
57
|
+
|
|
58
|
+
## Checked against the drawing
|
|
59
|
+
|
|
60
|
+
Every part is run once it is written and compared with the drawing. A
|
|
61
|
+
shape is only written as a module when its outline is within 0.05 mm of
|
|
62
|
+
the drawn one; set this with `--tolerance`. When a part's modules do not
|
|
63
|
+
match the drawing closely enough, the part is written as it is drawn, and
|
|
64
|
+
a comment at the top of the program says so. A part that no shape can
|
|
65
|
+
reproduce exactly is cut as the lines it is drawn with. Nothing in the
|
|
66
|
+
drawing is left out because it was not recognised.
|
|
67
|
+
|
|
68
|
+
## Parts, holes and layers
|
|
69
|
+
|
|
70
|
+
Each closed cut outline is a part, and the outlines inside it are its
|
|
71
|
+
holes. An outline inside a hole is a part again: a piece that falls out.
|
|
72
|
+
Parts are named after their group or element, as `id`, Inkscape label or
|
|
73
|
+
Illustrator layer name, and otherwise numbered.
|
|
74
|
+
|
|
75
|
+
Colours become [layers](layers.md), as most laser software reads them:
|
|
76
|
+
|
|
77
|
+
- Red lines are cut and blue lines are scored. Without red, the colour
|
|
78
|
+
used most is cut.
|
|
79
|
+
- Filled shapes without a line are engraved. A drawing with no lines at
|
|
80
|
+
all is a silhouette, and its filled shapes are cut out.
|
|
81
|
+
- Groups named cut, score, engrave or guide put their shapes on that
|
|
82
|
+
layer, whatever their colour. Files that KerfScript wrote come back on
|
|
83
|
+
the layers they were written from.
|
|
84
|
+
- Lines in other colours go on a layer of their own, named after the
|
|
85
|
+
colour, set to mark and not cut.
|
|
86
|
+
|
|
87
|
+
Lines that meet end to end are joined. A loop of lines becomes a hole
|
|
88
|
+
when nothing is inside it, and stays as cut lines when it holds marks or
|
|
89
|
+
other lines, as a piece to press out does.
|
|
90
|
+
|
|
91
|
+
Some drawings cannot be held as shapes and stay cut lines exactly as
|
|
92
|
+
drawn: outlines that touch or cross a hole of the same part, holes that
|
|
93
|
+
overlap, outlines that cross themselves or have a slit drawn into them,
|
|
94
|
+
and closed paths with no area. Lines and marks that leave the part they
|
|
95
|
+
start in are kept on their own, so the part does not trim them. In a
|
|
96
|
+
silhouette, each filled shape is a piece of its own.
|
|
97
|
+
|
|
98
|
+
Text keeps its words, size and alignment and is written as `text()` in
|
|
99
|
+
the built-in font, with the drawing's font named in a comment; to use
|
|
100
|
+
that font, add `font = "..."` to the `text()` and pass the font file to
|
|
101
|
+
`kerf render` with `--font`. Text on the cut layer cuts the letters of
|
|
102
|
+
that font, not the drawing's: convert it to paths in your editor to cut
|
|
103
|
+
it as drawn. Embedded images and hidden elements are left out, and the
|
|
104
|
+
comment at the top says how many.
|
|
105
|
+
|
|
106
|
+
## Material thickness and kerf
|
|
107
|
+
|
|
108
|
+
The depth of tabs and finger joints gives the material thickness, written
|
|
109
|
+
as `$thickness`. Change it and the joints follow. A part whose joints are
|
|
110
|
+
deeper, such as a tenon through a thick leg, gets its own
|
|
111
|
+
`material(thickness = ...)`.
|
|
112
|
+
|
|
113
|
+
Many drawings are made for one laser: their cut outlines are moved out by
|
|
114
|
+
half the beam's width, which rounds every outer corner a little. The
|
|
115
|
+
importer finds that, moves the outlines back to the sizes they were
|
|
116
|
+
designed at, and sets [`$kerf`](kerf.md) so the program cuts the same. A
|
|
117
|
+
part that cannot be moved back exactly, such as a strip as narrow as the
|
|
118
|
+
kerf, keeps its outlines as drawn and is cut with `material(kerf = 0)`.
|
|
119
|
+
Use `--kerf 0` to take the outlines as drawn, or `--kerf 0.15` to give the
|
|
120
|
+
kerf yourself.
|
|
121
|
+
|
|
122
|
+
## Layout
|
|
123
|
+
|
|
124
|
+
The program keeps the parts where the drawing has them, with
|
|
125
|
+
`$layout = "none"`. With `--pack`, identical parts become one part with a
|
|
126
|
+
quantity, and KerfScript arranges them on sheets as usual.
|
|
127
|
+
|
|
128
|
+
## Units
|
|
129
|
+
|
|
130
|
+
Drawings in millimetres, centimetres, inches or points are read at their
|
|
131
|
+
size. A drawing measured in pixels is read at 96 pixels per inch, or 72
|
|
132
|
+
for an Adobe Illustrator file; give another with `--dpi`.
|
|
133
|
+
|
|
134
|
+
## In JavaScript
|
|
135
|
+
|
|
136
|
+
`importSvg(svg, options)` does the same in a browser or in Node.js, and
|
|
137
|
+
returns the program as `source`. `svg` is the text of the drawing or the
|
|
138
|
+
bytes of its file:
|
|
139
|
+
|
|
140
|
+
```js
|
|
141
|
+
import { importSvg } from '@mylasertools/kerfscript';
|
|
142
|
+
|
|
143
|
+
const { source, summary, notes } = importSvg(svgText, { tolerance: 0.05 });
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
`summary` says in words how many parts there are and what was found, and
|
|
147
|
+
`notes` holds the remarks written at the top of the program. The options
|
|
148
|
+
are `dpi`, `tolerance`, `kerf`, `pack` and `name`, the drawing's name for
|
|
149
|
+
the first comment. See [JavaScript](javascript.md#importsvg).
|
package/docs/javascript.md
CHANGED
|
@@ -31,20 +31,23 @@ changing the source string.
|
|
|
31
31
|
|
|
32
32
|
### Options
|
|
33
33
|
|
|
34
|
-
| Option
|
|
35
|
-
|
|
|
36
|
-
| `params`
|
|
37
|
-
| `fonts`
|
|
38
|
-
| `defaultFont`
|
|
39
|
-
| `resolve`
|
|
40
|
-
| `kerf`
|
|
41
|
-
| `layout`
|
|
42
|
-
| `sheet`
|
|
43
|
-
| `
|
|
44
|
-
| `
|
|
45
|
-
| `
|
|
46
|
-
| `
|
|
47
|
-
| `
|
|
34
|
+
| Option | Value |
|
|
35
|
+
| -------------- | ------------------------------------------------------------------------------------- |
|
|
36
|
+
| `params` | Parameter values keyed by name |
|
|
37
|
+
| `fonts` | Font files keyed by name, as `ArrayBuffer` or `Uint8Array` |
|
|
38
|
+
| `defaultFont` | Name to use when `text()` does not specify a font |
|
|
39
|
+
| `resolve` | `(path) => source` callback for libraries outside the standard library |
|
|
40
|
+
| `kerf` | Kerf override for every part, in millimetres |
|
|
41
|
+
| `layout` | `"pack"` or `"none"` |
|
|
42
|
+
| `sheet` | `[width, height]` in millimetres, over the program's `$sheet` |
|
|
43
|
+
| `defaultSheet` | `[width, height]` for programs that do not set `$sheet`: the laser bed |
|
|
44
|
+
| `nest` | Pack small parts into the holes of bigger ones, as `$nest` |
|
|
45
|
+
| `gap` | Space between parts, in millimetres |
|
|
46
|
+
| `margin` | Space at sheet edges, in millimetres; defaults to `gap` |
|
|
47
|
+
| `guides` | Whether to include guide geometry |
|
|
48
|
+
| `analysis` | Capture nominal cut geometry before compensation, for [verification](verification.md) |
|
|
49
|
+
| `maxSteps` | Evaluation step limit |
|
|
50
|
+
| `limits` | Memory limits, see below; any you leave out keep their default |
|
|
48
51
|
|
|
49
52
|
Supply a font for programs that use text:
|
|
50
53
|
|
|
@@ -61,17 +64,30 @@ The URL should point to a font file provided by your application.
|
|
|
61
64
|
|
|
62
65
|
### Result
|
|
63
66
|
|
|
64
|
-
| Field | Contents
|
|
65
|
-
| ----------------- |
|
|
66
|
-
| `svg` | Combined SVG containing all sheets
|
|
67
|
-
| `width`, `height` | Combined SVG dimensions in millimetres
|
|
68
|
-
| `sheets` | Each sheet's dimensions, material, thickness, SVG, DXF, paths and placed items
|
|
69
|
-
| `parts` | Part names, quantities, dimensions, piece counts, cut lengths and material properties
|
|
70
|
-
| `assembly` | One entry per copy of a part with `name`, `copy`, `thickness`, `outline`, a 4 × 4 `matrix` and `placed`, for showing the design put together. Parts without `at` or `rotate` have `placed: false` |
|
|
71
|
-
| `
|
|
72
|
-
| `
|
|
73
|
-
| `
|
|
74
|
-
| `
|
|
67
|
+
| Field | Contents |
|
|
68
|
+
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
69
|
+
| `svg` | Combined SVG containing all sheets |
|
|
70
|
+
| `width`, `height` | Combined SVG dimensions in millimetres |
|
|
71
|
+
| `sheets` | Each sheet's dimensions, material, thickness, SVG, DXF, paths and placed items |
|
|
72
|
+
| `parts` | Part names, quantities, dimensions, piece counts, cut lengths and material properties |
|
|
73
|
+
| `assembly` | One entry per copy of a part with `name`, `copy`, `thickness`, `material`, `outline`, a 4 × 4 `matrix` and `placed`, for showing the design put together. Parts without `at` or `rotate` have `placed: false`. A bent part has `bends`; a part in a step has `step`; `marks` holds what is engraved and scored on it, front and back |
|
|
74
|
+
| `steps` | The text of each assembly step, in order; a part's `step` counts from 1 |
|
|
75
|
+
| `hardware` | Each `hardware()`: `kind`, `from`, `to`, `size`, `up`, `sides`, `step` and `label` |
|
|
76
|
+
| `paths` | Layer paths with `name`, `mode`, `color`, `d`, `regions` and `lines` |
|
|
77
|
+
| `layers` | Layer definitions in output order |
|
|
78
|
+
| `warnings` | Problems that did not stop the render |
|
|
79
|
+
| `echoes` | Output from the program's `echo()` calls |
|
|
80
|
+
| `analysis` | When requested: nominal cut regions and lines per definition, with compensation kerf; see [assembly verification](verification.md) |
|
|
81
|
+
|
|
82
|
+
Each sheet with back-face marks has `back`, with its own `svg`, `dxf` and
|
|
83
|
+
`paths`: the sheet turned over left to right.
|
|
84
|
+
|
|
85
|
+
`bendPoint(bends, thickness, [x, y, z])` gives where a point of a bent
|
|
86
|
+
part goes, in the part's own coordinates, before its `matrix`; and
|
|
87
|
+
`meshPieces(outline, bends)` cuts a part's outline into pieces narrow
|
|
88
|
+
enough across its hinges to bend smoothly. A 3D view extrudes each piece
|
|
89
|
+
by the thickness, moves its points with `bendPoint()` and then by the
|
|
90
|
+
`matrix`.
|
|
75
91
|
|
|
76
92
|
Use `result.svg` for a combined preview. Use `result.sheets[i].svg` or
|
|
77
93
|
`.dxf` to export individual sheets, particularly when they use different
|
|
@@ -129,6 +145,53 @@ format('x=1;module m(a,b=2){rect([a,b]);}');
|
|
|
129
145
|
|
|
130
146
|
`format(source, { indent: 4 })` uses four spaces per level.
|
|
131
147
|
|
|
148
|
+
## instructionsHtml()
|
|
149
|
+
|
|
150
|
+
`instructionsHtml(result, title)` turns a `render()` result into the page
|
|
151
|
+
`kerf instructions` writes: a standalone HTML document with the parts,
|
|
152
|
+
the sheets and a drawing for each step.
|
|
153
|
+
|
|
154
|
+
## diffRenders()
|
|
155
|
+
|
|
156
|
+
`diffRenders(a, b)` compares two results of `render(source, { layout: "none" })`
|
|
157
|
+
and returns what differs, one entry per part copy and layer: `part`, `copy`,
|
|
158
|
+
`layer`, `change` (`"added"`, `"removed"` or `"changed"`), `area` (mm² of
|
|
159
|
+
shapes that differ), `linesAdded`, `linesRemoved` and `at`, the box of the
|
|
160
|
+
difference in the part's own coordinates. With layout `"none"`, each sheet
|
|
161
|
+
item's `offset` is the move from the part's coordinates (y down) to the
|
|
162
|
+
sheet's.
|
|
163
|
+
|
|
164
|
+
## importSvg()
|
|
165
|
+
|
|
166
|
+
`importSvg(svg, options)` turns an SVG drawing into a program, as
|
|
167
|
+
`kerf import` does. `svg` is the text of the drawing, or the bytes of the
|
|
168
|
+
file as a `Uint8Array` or `ArrayBuffer`; bytes are read as UTF-8 or UTF-16,
|
|
169
|
+
which some programs write. It returns:
|
|
170
|
+
|
|
171
|
+
- `source`: the program
|
|
172
|
+
- `parts`: the number of parts
|
|
173
|
+
- `found`: what was recognised, as counts by kind
|
|
174
|
+
- `summary`: the same in words, such as `2 parts; found 3 circles.`
|
|
175
|
+
- `notes`: what to know about the drawing, also written at the top of the
|
|
176
|
+
program
|
|
177
|
+
|
|
178
|
+
The options are those of `kerf import`: `dpi`, `tolerance`, `kerf` and
|
|
179
|
+
`pack`, and `name`, the drawing's name for the comment at the top. See
|
|
180
|
+
[Importing SVG drawings](import.md).
|
|
181
|
+
|
|
182
|
+
```js
|
|
183
|
+
import { importSvg, render } from '@mylasertools/kerfscript';
|
|
184
|
+
|
|
185
|
+
const file = input.files[0];
|
|
186
|
+
const { source, summary } = importSvg(await file.arrayBuffer(), { name: file.name });
|
|
187
|
+
const result = render(source, { fonts, defaultFont: 'Atkinson' });
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
A drawing with text needs a font to render, as any program with `text()`
|
|
191
|
+
does. A large drawing can take some seconds to import: in a browser, call
|
|
192
|
+
`importSvg()` in a web worker so the page stays responsive. It throws an
|
|
193
|
+
`Error` for a file that is not SVG.
|
|
194
|
+
|
|
132
195
|
## Syntax colouring
|
|
133
196
|
|
|
134
197
|
`@mylasertools/kerfscript/highlight` colours KerfScript code without loading
|
package/docs/layers.md
CHANGED
|
@@ -99,10 +99,50 @@ The rectangle and circle use separate engraving layers. You can assign each
|
|
|
99
99
|
a different power in your laser software. Supported modes are `"cut"`,
|
|
100
100
|
`"line"`, `"fill"` and `"guide"`.
|
|
101
101
|
|
|
102
|
+
## The back face
|
|
103
|
+
|
|
104
|
+
`engrave(side = "back")`, `score(side = "back")` and `layer(name, side =
|
|
105
|
+
"back")` mark the face underneath, made after the parts are turned over.
|
|
106
|
+
Draw the marks where they are on the part seen from the top; text reads
|
|
107
|
+
the right way round on the back. They go into each sheet's back job,
|
|
108
|
+
turned over left to right, and not into the front file.
|
|
109
|
+
|
|
110
|
+
## Painting in order
|
|
111
|
+
|
|
112
|
+
`paint()` lays shapes like paint, each over the ones before: every child
|
|
113
|
+
loses the area of the children after it. Give it a layer for each child,
|
|
114
|
+
and a picture in several tones comes out with no two layers overlapping:
|
|
115
|
+
|
|
116
|
+
```kerf
|
|
117
|
+
layer("light", mode = "fill", color = "#c8a070");
|
|
118
|
+
layer("dark", mode = "fill", color = "#000000");
|
|
119
|
+
part("tile") {
|
|
120
|
+
rect([60, 60]);
|
|
121
|
+
paint(["light", "dark"]) {
|
|
122
|
+
circle(d = 50);
|
|
123
|
+
translate([30, 30]) circle(d = 20);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
A child given the layer `""` is left out, but still covers the ones
|
|
129
|
+
before it: a bare patch.
|
|
130
|
+
|
|
131
|
+
## Printing on parts
|
|
132
|
+
|
|
133
|
+
To print on the parts and then cut them, `layer(name, mode = "fill",
|
|
134
|
+
bleed = 2)` lets the printed layer run 2 mm past each part's edge, so the
|
|
135
|
+
cut never leaves a bare rim. `$registration = true` puts marks in three
|
|
136
|
+
corners of every sheet, on the `registration` layer, for a print-and-cut
|
|
137
|
+
machine to line the cut up with the print.
|
|
138
|
+
|
|
102
139
|
## Order in the file
|
|
103
140
|
|
|
104
|
-
KerfScript writes layers in this order: engrave, custom layers,
|
|
105
|
-
|
|
141
|
+
KerfScript writes layers in this order: engrave, custom fill layers,
|
|
142
|
+
custom line and cut layers, score, cut, then guide, so a line is never
|
|
143
|
+
hidden under a fill. `layer(name, order = n)` moves a custom layer among
|
|
144
|
+
the others, lowest first. Within a cut layer, inner paths precede outer
|
|
145
|
+
outlines.
|
|
106
146
|
|
|
107
147
|
Laser software may reorder these paths. Check its job preview so engraving
|
|
108
148
|
runs before cutting and holes are cut before the surrounding part.
|