@mylasertools/kerfscript 0.2.0 → 0.2.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/dist/render.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { type LayerDef } from './evaluator.cjs';
1
+ import { type LayerDef, type Limits } from './evaluator.cjs';
2
2
  import { type LayerPath } from './export/svg.cjs';
3
3
  import { type Layer } from './geometry.cjs';
4
4
  import { type FontSource } from './text.cjs';
@@ -15,6 +15,7 @@ export interface RenderOptions {
15
15
  margin?: number;
16
16
  guides?: boolean;
17
17
  maxSteps?: number;
18
+ limits?: Partial<Limits>;
18
19
  }
19
20
  export interface PartInfo {
20
21
  name: string;
package/dist/render.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type LayerDef } from './evaluator.js';
1
+ import { type LayerDef, type Limits } from './evaluator.js';
2
2
  import { type LayerPath } from './export/svg.js';
3
3
  import { type Layer } from './geometry.js';
4
4
  import { type FontSource } from './text.js';
@@ -15,6 +15,7 @@ export interface RenderOptions {
15
15
  margin?: number;
16
16
  guides?: boolean;
17
17
  maxSteps?: number;
18
+ limits?: Partial<Limits>;
18
19
  }
19
20
  export interface PartInfo {
20
21
  name: string;
package/docs/cli.md CHANGED
@@ -1,61 +1,76 @@
1
1
  # Command line
2
2
 
3
- The `kerf` command renders `.kerf` files to SVG, DXF or JSON. It needs
4
- Node.js 20 or newer and comes with the `@mylasertools/kerfscript` npm
5
- package.
3
+ Use the `kerf` command to export designs, change parameters and inspect
4
+ parts from your terminal. Install the package with Node.js 20 or newer:
6
5
 
7
6
  ```sh
8
7
  npm install --global @mylasertools/kerfscript
9
8
  kerf render box.kerf -o box.svg
10
9
  ```
11
10
 
12
- Or without installing:
11
+ You can also run it through `npx`:
13
12
 
14
13
  ```sh
15
14
  npx @mylasertools/kerfscript render box.kerf -o box.svg
16
15
  ```
17
16
 
17
+ Save a `.kerf` file from the [models](https://kerfscript.mylasertools.com/models/)
18
+ to try these commands.
19
+
18
20
  ## Commands
19
21
 
20
22
  ```sh
21
23
  kerf render <file.kerf> [-o out.svg] [options]
22
- kerf params <file.kerf> # settings as JSON
23
- kerf check <file.kerf> # parts, sizes, cut length, sheets and warnings
24
+ kerf params <file.kerf>
25
+ kerf check <file.kerf>
24
26
  ```
25
27
 
28
+ `render` exports SVG, DXF or JSON, using the output file's extension to
29
+ choose the format. `params` lists the editable settings as JSON. `check`
30
+ reports parts, dimensions, cut lengths, sheets and warnings.
31
+
26
32
  ## Options
27
33
 
28
- | Option | What it does |
29
- | --------------------- | ---------------------------------------------------------------------- |
30
- | `-o, --out <file>` | output file, `.svg`, `.dxf` or `.json`; default `<file>.svg` |
31
- | `-D name=value` | set a setting; the value is KerfScript: `40`, `"Oak"`, `true`, `[1,2]` |
32
- | `-p, --params <file>` | JSON file of setting values |
33
- | `--font <file.ttf>` | font for `text()`; repeat for more fonts. The name is the file name |
34
- | `--kerf <mm>` | override kerf compensation for every part |
35
- | `--sheet <W>x<H>` | sheet size for packing, in mm |
36
- | `--gap <mm>` | space between packed parts |
37
- | `--margin <mm>` | space between the parts and the sheet edge (default: the gap) |
38
- | `--no-pack` | keep parts where the program placed them |
39
- | `--guides` | include guide layer geometry |
40
- | `--split` | write one file per sheet (`out-1.svg`, `out-2.svg`, ...) |
41
- | `-h, --help` | show help |
42
- | `-v, --version` | show the version |
34
+ | Option | Use |
35
+ | --- | --- |
36
+ | `-o, --out <file>` | Output path ending in `.svg`, `.dxf` or `.json`; defaults to `<file>.svg` |
37
+ | `-D name=value` | Override a parameter; repeat for multiple values |
38
+ | `-p, --params <file>` | Load parameter values from a JSON file |
39
+ | `--font <file.ttf>` | Supply a font file; repeat for multiple fonts |
40
+ | `--kerf <mm>` | Override kerf for every part |
41
+ | `--sheet <W>x<H>` | Set the sheet width and height in millimetres |
42
+ | `--gap <mm>` | Set spacing between parts |
43
+ | `--margin <mm>` | Set spacing at sheet edges; defaults to the gap |
44
+ | `--no-pack` | Keep the positions defined in the program |
45
+ | `--guides` | Include the guide layer |
46
+ | `--split` | Export one file per sheet |
47
+ | `-h, --help` | Show command help |
48
+ | `-v, --version` | Show version numbers |
49
+
50
+ `-D` accepts KerfScript values, including numbers, quoted strings, booleans
51
+ and lists. For example: `-D width=200` or `-D 'name="Ada"'`.
43
52
 
44
53
  ## Examples
45
54
 
46
55
  ```sh
47
- kerf render sign.kerf -D 'name="Ada"' --font Inter-Bold.ttf -o ada.svg
56
+ kerf render name-sign.kerf -D 'name="Ada"' --font Inter-Bold.ttf -o ada.svg
48
57
  kerf render box.kerf --sheet 400x300 --kerf 0.12 --split -o box.svg
49
58
  kerf render box.kerf -o box.dxf
50
59
  kerf check box.kerf
51
60
  ```
52
61
 
53
- Warnings go to standard error and do not stop the render. Errors stop it with
54
- the line and column, and a non-zero exit code.
62
+ For multiple sheets, `--split` creates numbered files such as `box-1.svg`
63
+ and `box-2.svg`. Use it for DXF exports of a design with several sheets.
64
+
65
+ Warnings are written to standard error and allow rendering to continue.
66
+ An error stops the command, reports its location when available and returns
67
+ a non-zero exit code.
55
68
 
56
69
  ## Fonts
57
70
 
58
- KerfScript does not ship fonts and never reads system fonts, so a file
59
- renders the same everywhere. Pass the fonts a design uses with `--font`. A
60
- design that asks for `font = "Inter-Bold"` needs `--font Inter-Bold.ttf`; the
61
- first font given is the default.
71
+ Supply font files with `--font` for designs that use text. The CLI does not
72
+ look up fonts installed on your system.
73
+
74
+ `--font Inter-Bold.ttf` makes the font available as `Inter-Bold`. A design
75
+ can request it with `font = "Inter-Bold"`. The first supplied font is the
76
+ default for text that does not name one.
@@ -1,89 +1,64 @@
1
1
  # Laser software
2
2
 
3
- KerfScript writes ordinary SVG and DXF files, so any program that reads
4
- those can open them. This page says what we have actually checked, in which
5
- version, and what you still need to set up yourself.
3
+ Export SVG or DXF from KerfScript, then set up the cutting job in your laser
4
+ software. Check the imported size and layers before assigning power, speed
5
+ and operation order.
6
6
 
7
7
  ## What is in the files
8
8
 
9
9
  **SVG**
10
10
 
11
- - Size in millimetres (`width="100mm"`), with a matching `viewBox`, so one
12
- unit is one millimetre.
13
- - One group per layer, marked as an Inkscape layer and named after it:
14
- `engrave`, your own layers, `score`, `cut`, `guide`.
15
- - Cut lines red `#ff0000`, score lines blue `#0000ff`, 0.1 mm hairline
16
- strokes. Engraved areas are filled black `#000000` with the even-odd rule.
17
- - Holes and inner cuts come before outer outlines.
11
+ - Millimetre dimensions with a matching `viewBox`.
12
+ - Named layer groups for engraving, scoring, cutting and any custom layers.
13
+ - Red cut paths, blue score paths and black filled engraving.
14
+ - Inner cut paths before outer outlines in the file.
18
15
 
19
16
  **DXF**
20
17
 
21
- - R12 (AC1009) polylines, units set to millimetres.
22
- - One DXF layer per KerfScript layer, in capitals (`CUT`, `SCORE`,
23
- `ENGRAVE`), with matching AutoCAD colours.
24
- - DXF R12 has no fills. Engraved areas arrive as outlines; set that layer to
25
- fill in your laser software.
26
- - A DXF holds one sheet. Use `--split` for designs with several sheets.
18
+ - R12 polylines with millimetre units.
19
+ - Named layers such as `CUT`, `SCORE` and `ENGRAVE`.
20
+ - Engraving as outlines. Set the engraving layer to fill in your laser software.
21
+ - One sheet per file. Use the CLI's `--split` option for several sheets.
27
22
 
28
23
  ## Checked
29
24
 
30
- | Program | Version | SVG | DXF | How |
31
- | -------- | ------- | --- | --- | --------------------------- |
32
- | Inkscape | 1.4.2 | yes | yes | automatic, `npm run compat` |
25
+ | Program | Version | SVG | DXF | Checks |
26
+ | --- | --- | --- | --- | --- |
27
+ | Inkscape | 1.4.2 | Passed | Passed | Dimensions, layers and SVG fills |
33
28
 
34
- `npm run compat` renders six reference models (the calibration square, the
35
- kerf test, a six-panel finger-jointed box, a living hinge card, a coaster
36
- with an engraved ring, and a jigsaw puzzle), opens every SVG and DXF in
37
- Inkscape from the command line, and checks that:
38
-
39
- - the size of the drawing matches KerfScript's geometry within 0.02 mm,
40
- kerf compensation included;
41
- - every layer arrives as a layer with the right name;
42
- - engraved layers are filled in the SVG.
43
-
44
- All six passed in both formats on 28 October 2026.
29
+ Six reference models passed these import checks on 28 October 2026.
30
+ Drawing dimensions matched within 0.02 mm, including kerf compensation.
31
+ These results cover file imports; they do not establish a fit for a
32
+ particular machine or material.
45
33
 
46
34
  ## Not checked yet
47
35
 
48
- We have not yet run the reference set through **LightBurn**, **xTool
49
- Studio** or **xTool Creative Space**, **RDWorks** or **LaserGRBL**, and we
50
- have not cut it on machines outside MyLaserTools. Until we have, treat them as
51
- untested: they read standard SVG and DXF, but each imports colours, layers
52
- and fills its own way.
53
-
54
- If you try one, we would like to hear what happened. The checklist below is
55
- what we look at.
36
+ LightBurn, xTool Studio, xTool Creative Space, RDWorks and LaserGRBL have
37
+ not yet been verified with the reference models. Import handling can differ
38
+ between programs, especially for units, layer colours and fills.
56
39
 
57
40
  ## Checklist for a new program
58
41
 
59
- Open `calibration-square.svg` and `box.svg` from the
60
- [models](https://kerfscript.mylasertools.com/models/) and check:
61
-
62
- 1. **Size.** The square is 100.15 mm wide with the default 0.15 mm kerf
63
- (100 mm plus compensation), not 26.4 mm or 377.95 mm. If it is wrong, the
64
- program ignored the millimetre units; look for an import DPI or unit
65
- setting.
66
- 2. **Layers.** Cut, score and engrave arrive as separate layers or colours,
67
- so each can get its own power and speed.
68
- 3. **Fill.** The engraved text on the square is filled, not just outlined.
69
- 4. **Holes.** The hole in the square is cut, and engraving does not appear
70
- inside it.
71
- 5. **Order.** The program's cut order cuts holes before outlines. Most
72
- programs have an "inner shapes first" option; turn it on.
73
- 6. **Parts.** All six box panels arrive, none overlapping.
42
+ Download the calibration square and box from the
43
+ [models](https://kerfscript.mylasertools.com/models/) and check their imports:
74
44
 
75
- ## What the file does not decide
45
+ 1. **Size:** the calibration square's cut path is 100.15 mm wide with
46
+ `$kerf = 0.15`, allowing for a finished 100 mm square. If the imported
47
+ size differs, check the unit and DPI settings.
48
+ 2. **Layers:** cutting, scoring and engraving can be assigned separate operations.
49
+ 3. **Fill:** engraved text has filled letters. For DXF, select fill in the
50
+ engraving layer's settings.
51
+ 4. **Holes:** cut holes remain open and contain no engraving.
52
+ 5. **Order:** the job preview cuts inner paths before outer outlines.
53
+ 6. **Parts:** the box contains all six panels without overlaps.
76
54
 
77
- The file describes geometry and layers. Your laser software decides how the
78
- machine runs it:
55
+ ## What the file does not decide
79
56
 
80
- - **Order of operations.** Layer order in an SVG is a hint. Most programs
81
- sort operations themselves; check that engraving runs before cutting and
82
- inner cuts before outer ones.
83
- - **Power, speed, passes and focus** for each layer and material.
84
- - **Material and thickness.** KerfScript records them per sheet; make sure
85
- the file you send matches the sheet in the machine.
86
- - **Kerf.** If your laser software also applies kerf offset, turn one of them
87
- off, or parts will be compensated twice.
57
+ Set power, speed, passes and focus for your machine and material. Check the
58
+ job preview for engraving before cutting and holes before outer outlines;
59
+ laser software can reorder the paths in a file.
88
60
 
89
- Always run a test on scrap before cutting good material.
61
+ For multiple sheets, use a separate file and matching material settings for
62
+ each sheet. If KerfScript has already applied kerf compensation, leave the
63
+ laser software's kerf offset at zero. Test the job on scrap before cutting
64
+ the final material.
@@ -1,9 +1,8 @@
1
1
  # Settings
2
2
 
3
- Top-level variables with a plain value become **settings**: sliders, menus,
4
- checkboxes and text boxes in the playground, on MyLaserTools, and in any tool
5
- that reads OpenSCAD customizer comments. The format is the same as
6
- OpenSCAD's.
3
+ Expose dimensions, text and other choices as controls beside your design.
4
+ Comments define sliders and menus, while the variable values provide their
5
+ defaults. KerfScript uses OpenSCAD's customizer comment format.
7
6
 
8
7
  ```kerf
9
8
  /* [Size] */
@@ -24,39 +23,52 @@ wall = 3;
24
23
  rect([width, depth]);
25
24
  ```
26
25
 
26
+ This example defines several control types. The rectangle uses `width`
27
+ and `depth`; the other variables illustrate settings you can use elsewhere
28
+ in a design.
29
+
27
30
  ## What becomes a setting
28
31
 
29
- A top-level assignment whose value is a number, a string, `true` or `false`,
30
- or a list of numbers. An expression like `width / 2` is not a setting; it is
31
- worked out from the others.
32
+ A variable declared at the top level becomes a setting when its value is a
33
+ number, string, boolean or list of numbers. Variables defined by expressions,
34
+ such as `half_width = width / 2`, are calculated from the other values and
35
+ do not get their own controls.
32
36
 
33
37
  ## Comments
34
38
 
35
- | Comment after the value | Control |
36
- | --------------------------------- | ----------------------------- |
37
- | `// [40:5:400]` | slider from 40 to 400, step 5 |
38
- | `// [40:400]` | slider from 40 to 400 |
39
- | `// [200]` | number up to 200 |
40
- | `// [2, 3, 4]` | menu of those values |
41
- | `// [round:Round, square:Square]` | menu with labels |
42
- | none, on `true` or `false` | checkbox |
43
- | none, on a string | text box |
44
-
45
- - `/* [Group name] */` starts a group for the settings below it.
46
- `/* [Hidden] */` hides the ones that follow.
47
- - A `//` comment on its own line just above a setting is its caption.
48
- A comment at the end of the line before does not count.
49
- - Put a blank line between a file's opening comment and its first setting,
50
- so the opening comment is not taken as that setting's caption.
39
+ Put a range or choice list after the assignment:
40
+
41
+ | Comment after the value | Control |
42
+ | --- | --- |
43
+ | `// [40:5:400]` | Slider from 40 to 400, in steps of 5 |
44
+ | `// [40:400]` | Slider from 40 to 400 |
45
+ | `// [200]` | Number with an upper limit of 200 |
46
+ | `// [2, 3, 4]` | Choice of 2, 3 or 4 |
47
+ | `// [round:Round, square:Square]` | Menu with a label for each value |
48
+ | No comment on a boolean | Checkbox |
49
+ | No comment on a string | Text field |
50
+
51
+ `/* [Size] */` starts a group named Size. `/* [Hidden] */` hides the
52
+ settings that follow it, until another group begins.
53
+
54
+ A `//` comment immediately above a variable supplies its caption. Keep the
55
+ file's introductory comment separate with a blank line so it does not
56
+ become the first setting's caption.
51
57
 
52
58
  ## Changing settings without editing the file
53
59
 
60
+ The CLI accepts values with `-D` or a JSON file with `--params`:
61
+
54
62
  ```sh
55
- kerf render box.kerf -D width=200 -D 'label="Oak"'
56
- kerf render box.kerf --params oak.json
63
+ kerf render box.kerf -D width=200
64
+ kerf render box.kerf --params box-settings.json
57
65
  kerf params box.kerf
58
66
  ```
59
67
 
60
- `-D` values are KerfScript values, so strings need their quotes. `kerf params`
61
- prints the settings as JSON. From JavaScript, pass `params` to `render()` and
62
- read them with `parameters()`; see [JavaScript API](javascript.md).
68
+ `box-settings.json` can contain `{"width": 200, "lid": false}`.
69
+ Use `kerf params` to list a design's settings as JSON.
70
+
71
+ String values need quotes, for example `-D 'label="Oak"'` for a design
72
+ with a `label` setting. In JavaScript, pass values through `render()`'s
73
+ `params` option and read the settings with `parameters()`. See the
74
+ [JavaScript API](javascript.md).
@@ -1,24 +1,24 @@
1
1
  # Getting started
2
2
 
3
- This guide takes you from an empty file to a cut file in about ten minutes.
4
- You need nothing installed: the [playground](https://kerfscript.mylasertools.com/playground/)
5
- runs KerfScript in your browser.
3
+ Make a small sign with two hanging holes and engraved text. You can follow
4
+ this guide in the [playground](https://kerfscript.mylasertools.com/playground/)
5
+ without installing anything.
6
6
 
7
7
  ## Your first part
8
8
 
9
- Open the playground, clear the editor and type:
9
+ Clear the playground editor and enter:
10
10
 
11
11
  ```kerf
12
12
  rect([80, 50], r = 4);
13
13
  ```
14
14
 
15
- That is a rounded rectangle, 80 by 50 mm. Units are always millimetres. A
16
- shape that is not on any other layer is **cut**, so this is a part you could
17
- cut out now.
15
+ This draws an 80 × 50 mm rectangle with 4 mm corner radii. KerfScript uses
16
+ millimetres for lengths and degrees for angles. Shapes go on the cut layer
17
+ unless you assign another layer.
18
18
 
19
19
  ## Holes
20
20
 
21
- `difference()` keeps the first shape and removes the rest from it:
21
+ Replace the rectangle with this code:
22
22
 
23
23
  ```kerf
24
24
  difference() {
@@ -28,13 +28,16 @@ difference() {
28
28
  }
29
29
  ```
30
30
 
31
- `translate([x, y])` moves what follows it. The y axis points up, and
32
- `rect()` starts at `[0, 0]` unless you pass `center = true`.
31
+ `difference()` subtracts the two circles from the rectangle. Each hole is
32
+ 5 mm across, centred 10 mm from a side and halfway up the sign.
33
+
34
+ `translate([x, y])` moves a shape. The x axis points right and the y axis
35
+ points up. A rectangle starts at `[0, 0]`; use `center = true` to centre it
36
+ on that point.
33
37
 
34
38
  ## Engraving and scoring
35
39
 
36
- Wrap shapes in `engrave()` to engrave their area, or `score()` to mark their
37
- outline without cutting through:
40
+ Add a scored border and engraved text:
38
41
 
39
42
  ```kerf
40
43
  difference() {
@@ -43,15 +46,19 @@ difference() {
43
46
  translate([70, 25]) circle(d = 5);
44
47
  }
45
48
  score() translate([20, 10]) rect([40, 30], r = 2);
46
- engrave() translate([40, 25]) text("Oak", size = 10, halign = "center", valign = "center");
49
+ engrave() translate([40, 25])
50
+ text("Oak", size = 10, halign = "center", valign = "center");
47
51
  ```
48
52
 
49
- Engraving and scoring are clipped to the material, so nothing is marked over
50
- a hole or off the edge. [Layers](layers.md) explains the rest.
53
+ `score()` marks the border's outline. `engrave()` fills the letters. Both
54
+ stay within the sign's cut outline, excluding the holes. The playground
55
+ supplies a font for this example.
56
+
57
+ See [Layers](layers.md) for custom layers and guide lines.
51
58
 
52
59
  ## Settings
53
60
 
54
- A top-level variable with a comment in square brackets becomes a slider:
61
+ Give dimensions names so you can change them without editing every shape:
55
62
 
56
63
  ```kerf
57
64
  width = 80; // [40:5:200]
@@ -67,32 +74,42 @@ engrave() translate([width / 2, height / 2])
67
74
  text(label, size = 10, halign = "center", valign = "center");
68
75
  ```
69
76
 
70
- Move a slider in the playground and the number in the code changes with it.
71
- [Settings](customizer.md) covers groups, captions and menus.
77
+ The comments create sliders for width and height. `[40:5:200]` means a
78
+ minimum of 40, a step of 5 and a maximum of 200. `label` becomes a text
79
+ field. The text and holes stay centred as the dimensions change.
80
+
81
+ In the playground, changing a control also updates its value in the code.
82
+ See [Settings](customizer.md) for menus, groups and captions.
72
83
 
73
84
  ## Kerf
74
85
 
75
- The laser burns away a thin line of material, the **kerf**. Tell KerfScript
76
- how wide it is and parts come out the size you typed:
86
+ The beam removes some material along each cut. To account for that width,
87
+ add your measured kerf near the top of the program:
77
88
 
78
89
  ```kerf
79
90
  $kerf = 0.15;
80
91
  ```
81
92
 
82
- Cut the [calibration square](../examples/calibration-square.kerf) once to
83
- measure yours. [Kerf](kerf.md) explains how.
93
+ Here, `0.15` is an example in millimetres. Use the
94
+ [calibration square](../examples/calibration-square.kerf) to measure a value
95
+ for your machine and material. [Kerf](kerf.md) explains the measurement and
96
+ how it affects the exported outlines.
84
97
 
85
98
  ## Getting the file
86
99
 
87
- In the playground, press **SVG** or **DXF**. Open the SVG in your laser
88
- software: cut lines are red, score lines blue and engraving black, each on its
89
- own layer. Set power, speed and the order of operations there, as you would
90
- for any other file. [Laser software](compatibility.md) has notes for the
91
- programs we have checked.
100
+ Choose **SVG** or **DXF** in the playground, then open the file in your laser
101
+ software. Assign the cut, score and engrave layers their power, speed and
102
+ operation order. In DXF, set engraved areas to fill.
103
+
104
+ If you used `$kerf`, leave kerf compensation off in the laser software to
105
+ avoid applying it twice. The [import guide](compatibility.md) covers sizes,
106
+ layers and tested programs.
107
+
108
+ Download **.kerf** to keep an editable copy of the design.
92
109
 
93
110
  ## Next
94
111
 
95
- - [Layers](layers.md): cut, score, engrave and your own layers
96
- - [Parts and sheets](parts-and-sheets.md): several pieces, quantities, materials
97
- - [Coming from OpenSCAD](openscad.md): what is the same and what is not
98
- - [Language reference](../LANGUAGE.md): everything in one page
112
+ - [Layers](layers.md): separate cutting, scoring and engraving.
113
+ - [Parts and sheets](parts-and-sheets.md): arrange several parts by material.
114
+ - [Coming from OpenSCAD](openscad.md): adapt an existing 2D design.
115
+ - [Language reference](../LANGUAGE.md): look up syntax and functions.