@mylasertools/kerfscript 0.5.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 +29 -1
- package/README.md +14 -3
- package/dist/cli.js +2869 -318
- 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 +46 -12
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +46 -12
- package/dist/language.cjs +26 -26
- package/dist/language.js +26 -26
- package/dist/paths.d.cts +1 -1
- package/dist/paths.d.ts +1 -1
- package/docs/cli.md +9 -0
- package/docs/import.md +149 -0
- package/docs/javascript.md +31 -0
- package/docs/library/calibration.svg +1 -1
- package/docs/library/hanging.svg +1 -1
- package/docs/library/hinge.svg +1 -1
- package/docs/mcp.md +88 -0
- package/docs/versions.md +2 -2
- package/package.json +2 -3
package/dist/paths.d.cts
CHANGED
|
@@ -25,4 +25,4 @@ export interface Flattened {
|
|
|
25
25
|
open: Poly[];
|
|
26
26
|
}
|
|
27
27
|
export declare function flatten(cmds: Cmd[], tolerance?: number): Flattened;
|
|
28
|
-
export declare function parseSvgPath(d: string): Cmd[];
|
|
28
|
+
export declare function parseSvgPath(d: string, arcStep?: number, onError?: (message: string) => void): Cmd[];
|
package/dist/paths.d.ts
CHANGED
|
@@ -25,4 +25,4 @@ export interface Flattened {
|
|
|
25
25
|
open: Poly[];
|
|
26
26
|
}
|
|
27
27
|
export declare function flatten(cmds: Cmd[], tolerance?: number): Flattened;
|
|
28
|
-
export declare function parseSvgPath(d: string): Cmd[];
|
|
28
|
+
export declare function parseSvgPath(d: string, arcStep?: number, onError?: (message: string) => void): Cmd[];
|
package/docs/cli.md
CHANGED
|
@@ -51,6 +51,7 @@ kerf fmt <files or folders>
|
|
|
51
51
|
kerf fmt --check <files or folders>
|
|
52
52
|
kerf fmt -
|
|
53
53
|
kerf lsp [--timeout <seconds>]
|
|
54
|
+
kerf import <file.svg> [-o out.kerf] [--dpi <n>] [--tolerance <mm>] [--kerf <mm>] [--pack]
|
|
54
55
|
kerf add <source>
|
|
55
56
|
kerf remove <name>
|
|
56
57
|
kerf install [--frozen | --check]
|
|
@@ -71,6 +72,13 @@ exits with 1 when there are any, for CI. `kerf fmt -` formats standard input
|
|
|
71
72
|
to standard output, for editors. A file that does not parse is reported and
|
|
72
73
|
left alone.
|
|
73
74
|
|
|
75
|
+
`import` turns an SVG drawing into a `.kerf` program next to it, or to the
|
|
76
|
+
`-o` file; `-o -` prints it. It does not replace a program already next to
|
|
77
|
+
the drawing unless that file is named with `-o`. It writes the circles, rectangles, tabs, slots,
|
|
78
|
+
finger joints, hanger holes and keyholes it finds as the modules that make
|
|
79
|
+
them, and checks each part against the drawing: see
|
|
80
|
+
[Importing SVG drawings](import.md) for what it finds and for its options.
|
|
81
|
+
|
|
74
82
|
`lsp` runs the language server on standard input and output, for editors:
|
|
75
83
|
see [Editors](editors.md). It stops checking a design after `--timeout`
|
|
76
84
|
seconds, 10 by default.
|
|
@@ -114,6 +122,7 @@ kerf render name-sign.kerf -D 'name="Ada"' --font Inter-Bold.ttf -o ada.svg
|
|
|
114
122
|
kerf render box.kerf --sheet 400x300 --kerf 0.12 --split -o box.svg
|
|
115
123
|
kerf render box.kerf -o box.dxf
|
|
116
124
|
kerf check box.kerf
|
|
125
|
+
kerf import ornament.svg -o ornament.kerf
|
|
117
126
|
```
|
|
118
127
|
|
|
119
128
|
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
|
@@ -129,6 +129,37 @@ format('x=1;module m(a,b=2){rect([a,b]);}');
|
|
|
129
129
|
|
|
130
130
|
`format(source, { indent: 4 })` uses four spaces per level.
|
|
131
131
|
|
|
132
|
+
## importSvg()
|
|
133
|
+
|
|
134
|
+
`importSvg(svg, options)` turns an SVG drawing into a program, as
|
|
135
|
+
`kerf import` does. `svg` is the text of the drawing, or the bytes of the
|
|
136
|
+
file as a `Uint8Array` or `ArrayBuffer`; bytes are read as UTF-8 or UTF-16,
|
|
137
|
+
which some programs write. It returns:
|
|
138
|
+
|
|
139
|
+
- `source`: the program
|
|
140
|
+
- `parts`: the number of parts
|
|
141
|
+
- `found`: what was recognised, as counts by kind
|
|
142
|
+
- `summary`: the same in words, such as `2 parts; found 3 circles.`
|
|
143
|
+
- `notes`: what to know about the drawing, also written at the top of the
|
|
144
|
+
program
|
|
145
|
+
|
|
146
|
+
The options are those of `kerf import`: `dpi`, `tolerance`, `kerf` and
|
|
147
|
+
`pack`, and `name`, the drawing's name for the comment at the top. See
|
|
148
|
+
[Importing SVG drawings](import.md).
|
|
149
|
+
|
|
150
|
+
```js
|
|
151
|
+
import { importSvg, render } from '@mylasertools/kerfscript';
|
|
152
|
+
|
|
153
|
+
const file = input.files[0];
|
|
154
|
+
const { source, summary } = importSvg(await file.arrayBuffer(), { name: file.name });
|
|
155
|
+
const result = render(source, { fonts, defaultFont: 'Atkinson' });
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
A drawing with text needs a font to render, as any program with `text()`
|
|
159
|
+
does. A large drawing can take some seconds to import: in a browser, call
|
|
160
|
+
`importSvg()` in a web worker so the page stays responsive. It throws an
|
|
161
|
+
`Error` for a file that is not SVG.
|
|
162
|
+
|
|
132
163
|
## Syntax colouring
|
|
133
164
|
|
|
134
165
|
`@mylasertools/kerfscript/highlight` colours KerfScript code without loading
|