@mylasertools/kerfscript 0.9.0 → 0.10.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 +88 -0
- package/LANGUAGE.md +13 -5
- package/README.md +2 -1
- package/dist/assembly.d.cts +2 -0
- package/dist/assembly.d.ts +2 -0
- package/dist/bores.d.cts +10 -0
- package/dist/bores.d.ts +10 -0
- package/dist/cli.js +7899 -6630
- package/dist/customizer.d.cts +3 -0
- package/dist/customizer.d.ts +3 -0
- package/dist/effects.d.cts +31 -0
- package/dist/effects.d.ts +31 -0
- package/dist/evaluator.d.cts +1 -0
- package/dist/evaluator.d.ts +1 -0
- package/dist/export/mesh.d.cts +53 -0
- package/dist/export/mesh.d.ts +53 -0
- package/dist/export/model.d.cts +12 -0
- package/dist/export/model.d.ts +12 -0
- package/dist/export/triangulate.d.cts +5 -0
- package/dist/export/triangulate.d.ts +5 -0
- package/dist/export/zip.d.cts +5 -0
- package/dist/export/zip.d.ts +5 -0
- package/dist/geometry.d.cts +1 -0
- package/dist/geometry.d.ts +1 -0
- package/dist/highlight.cjs +2 -2
- package/dist/highlight.js +2 -2
- package/dist/import/dbg.d.cts +1 -0
- package/dist/import/dbg.d.ts +1 -0
- package/dist/index.cjs +435 -48
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +435 -48
- package/dist/language.cjs +410 -30
- package/dist/language.js +410 -30
- package/dist/libraries.cjs +393 -14
- package/dist/libraries.js +393 -14
- package/dist/render.d.cts +3 -0
- package/dist/render.d.ts +3 -0
- package/dist/signatures.cjs +23 -5
- package/dist/signatures.js +23 -5
- package/dist/text.d.cts +6 -0
- package/dist/text.d.ts +6 -0
- package/docs/3d-files.md +72 -0
- package/docs/cli.md +27 -22
- package/docs/customizer.md +56 -0
- package/docs/javascript.md +46 -0
- package/docs/library.md +120 -0
- package/docs/openscad.md +15 -13
- package/docs/parts-and-sheets.md +2 -1
- package/docs/versions.md +2 -2
- package/package.json +1 -1
package/dist/signatures.cjs
CHANGED
|
@@ -60,9 +60,13 @@ var text = (name, doc) => ({
|
|
|
60
60
|
p("size", "Font size in millimetres", "10"),
|
|
61
61
|
p("font", "Font name", "$font"),
|
|
62
62
|
named("halign", "left, center or right", '"left"'),
|
|
63
|
-
named(
|
|
63
|
+
named(
|
|
64
|
+
"valign",
|
|
65
|
+
"baseline, top, center, bottom, or cap (capitals centred on y = 0)",
|
|
66
|
+
'"baseline"'
|
|
67
|
+
),
|
|
64
68
|
named("spacing", "Letter spacing factor", "1"),
|
|
65
|
-
named("fit", "Measure at the size that fits this width")
|
|
69
|
+
named("fit", "Measure at the size that fits this width, or [width, cap height]")
|
|
66
70
|
],
|
|
67
71
|
section: "Text measurements",
|
|
68
72
|
doc
|
|
@@ -101,7 +105,10 @@ var SIGNATURES = [
|
|
|
101
105
|
{
|
|
102
106
|
name: "ellipse",
|
|
103
107
|
kind: "module",
|
|
104
|
-
params: [
|
|
108
|
+
params: [
|
|
109
|
+
p("r", "[rx, ry], or one radius for both", "1"),
|
|
110
|
+
named("d", "[width, height], or one diameter for both, instead of r")
|
|
111
|
+
],
|
|
105
112
|
section: "Shapes",
|
|
106
113
|
doc: "An ellipse centred on the origin"
|
|
107
114
|
},
|
|
@@ -152,9 +159,16 @@ var SIGNATURES = [
|
|
|
152
159
|
p("size", "Font size in millimetres", "10"),
|
|
153
160
|
p("font", "Font name", "$font"),
|
|
154
161
|
named("halign", "left, center or right", '"left"'),
|
|
155
|
-
named(
|
|
162
|
+
named(
|
|
163
|
+
"valign",
|
|
164
|
+
"baseline, top, center, bottom, or cap (capitals centred on y = 0)",
|
|
165
|
+
'"baseline"'
|
|
166
|
+
),
|
|
156
167
|
named("spacing", "Letter spacing factor", "1"),
|
|
157
|
-
named(
|
|
168
|
+
named(
|
|
169
|
+
"fit",
|
|
170
|
+
"Shrink the size so the text is no wider than this, or fits [width, cap height]"
|
|
171
|
+
),
|
|
158
172
|
named(
|
|
159
173
|
"weight",
|
|
160
174
|
'"bold" thickens the strokes by 3.5% of the size, or a number of mm (less than 0 thins them)',
|
|
@@ -1073,6 +1087,10 @@ var SIGNATURES = [
|
|
|
1073
1087
|
// Text and joints
|
|
1074
1088
|
text("text_width", "The advance width of the text, including spacing"),
|
|
1075
1089
|
text("text_metrics", "The text as [advance, [[x0, y0], [x1, y1]], ascent, descent]"),
|
|
1090
|
+
text(
|
|
1091
|
+
"text_size",
|
|
1092
|
+
"The text as a record: width (advance), height, bounds, cap (capital height), ascent, descent and size"
|
|
1093
|
+
),
|
|
1076
1094
|
{
|
|
1077
1095
|
name: "finger_count",
|
|
1078
1096
|
kind: "function",
|
package/dist/signatures.js
CHANGED
|
@@ -35,9 +35,13 @@ var text = (name, doc) => ({
|
|
|
35
35
|
p("size", "Font size in millimetres", "10"),
|
|
36
36
|
p("font", "Font name", "$font"),
|
|
37
37
|
named("halign", "left, center or right", '"left"'),
|
|
38
|
-
named(
|
|
38
|
+
named(
|
|
39
|
+
"valign",
|
|
40
|
+
"baseline, top, center, bottom, or cap (capitals centred on y = 0)",
|
|
41
|
+
'"baseline"'
|
|
42
|
+
),
|
|
39
43
|
named("spacing", "Letter spacing factor", "1"),
|
|
40
|
-
named("fit", "Measure at the size that fits this width")
|
|
44
|
+
named("fit", "Measure at the size that fits this width, or [width, cap height]")
|
|
41
45
|
],
|
|
42
46
|
section: "Text measurements",
|
|
43
47
|
doc
|
|
@@ -76,7 +80,10 @@ var SIGNATURES = [
|
|
|
76
80
|
{
|
|
77
81
|
name: "ellipse",
|
|
78
82
|
kind: "module",
|
|
79
|
-
params: [
|
|
83
|
+
params: [
|
|
84
|
+
p("r", "[rx, ry], or one radius for both", "1"),
|
|
85
|
+
named("d", "[width, height], or one diameter for both, instead of r")
|
|
86
|
+
],
|
|
80
87
|
section: "Shapes",
|
|
81
88
|
doc: "An ellipse centred on the origin"
|
|
82
89
|
},
|
|
@@ -127,9 +134,16 @@ var SIGNATURES = [
|
|
|
127
134
|
p("size", "Font size in millimetres", "10"),
|
|
128
135
|
p("font", "Font name", "$font"),
|
|
129
136
|
named("halign", "left, center or right", '"left"'),
|
|
130
|
-
named(
|
|
137
|
+
named(
|
|
138
|
+
"valign",
|
|
139
|
+
"baseline, top, center, bottom, or cap (capitals centred on y = 0)",
|
|
140
|
+
'"baseline"'
|
|
141
|
+
),
|
|
131
142
|
named("spacing", "Letter spacing factor", "1"),
|
|
132
|
-
named(
|
|
143
|
+
named(
|
|
144
|
+
"fit",
|
|
145
|
+
"Shrink the size so the text is no wider than this, or fits [width, cap height]"
|
|
146
|
+
),
|
|
133
147
|
named(
|
|
134
148
|
"weight",
|
|
135
149
|
'"bold" thickens the strokes by 3.5% of the size, or a number of mm (less than 0 thins them)',
|
|
@@ -1048,6 +1062,10 @@ var SIGNATURES = [
|
|
|
1048
1062
|
// Text and joints
|
|
1049
1063
|
text("text_width", "The advance width of the text, including spacing"),
|
|
1050
1064
|
text("text_metrics", "The text as [advance, [[x0, y0], [x1, y1]], ascent, descent]"),
|
|
1065
|
+
text(
|
|
1066
|
+
"text_size",
|
|
1067
|
+
"The text as a record: width (advance), height, bounds, cap (capital height), ascent, descent and size"
|
|
1068
|
+
),
|
|
1051
1069
|
{
|
|
1052
1070
|
name: "finger_count",
|
|
1053
1071
|
kind: "function",
|
package/dist/text.d.cts
CHANGED
|
@@ -9,6 +9,11 @@ interface OtFont {
|
|
|
9
9
|
ascender: number;
|
|
10
10
|
descender: number;
|
|
11
11
|
unitsPerEm: number;
|
|
12
|
+
tables?: {
|
|
13
|
+
os2?: {
|
|
14
|
+
sCapHeight?: number;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
12
17
|
}
|
|
13
18
|
export declare class FontBook {
|
|
14
19
|
private sources;
|
|
@@ -32,5 +37,6 @@ export declare function textMetrics(book: FontBook, text: string, o: TextOptions
|
|
|
32
37
|
bounds: number[][];
|
|
33
38
|
ascent: number;
|
|
34
39
|
descent: number;
|
|
40
|
+
cap: number;
|
|
35
41
|
};
|
|
36
42
|
export {};
|
package/dist/text.d.ts
CHANGED
|
@@ -9,6 +9,11 @@ interface OtFont {
|
|
|
9
9
|
ascender: number;
|
|
10
10
|
descender: number;
|
|
11
11
|
unitsPerEm: number;
|
|
12
|
+
tables?: {
|
|
13
|
+
os2?: {
|
|
14
|
+
sCapHeight?: number;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
12
17
|
}
|
|
13
18
|
export declare class FontBook {
|
|
14
19
|
private sources;
|
|
@@ -32,5 +37,6 @@ export declare function textMetrics(book: FontBook, text: string, o: TextOptions
|
|
|
32
37
|
bounds: number[][];
|
|
33
38
|
ascent: number;
|
|
34
39
|
descent: number;
|
|
40
|
+
cap: number;
|
|
35
41
|
};
|
|
36
42
|
export {};
|
package/docs/3d-files.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# 3D files
|
|
2
|
+
|
|
3
|
+
KerfScript writes a model in 3D as well as the files you cut: a GLB to look
|
|
4
|
+
at or render, a 3MF to 3D print in colour, or an STL. Each part becomes a
|
|
5
|
+
solid as thick as its sheet, and what is engraved or scored on it becomes a
|
|
6
|
+
thin coloured layer on its face.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
kerf render box.kerf -o box.glb # the assembled model, to view or render
|
|
10
|
+
kerf render sign.kerf -o sign.3mf --flat # the parts flat, to print in colour
|
|
11
|
+
kerf render coaster.kerf -o coaster.stl # one mesh
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The format follows the file's extension.
|
|
15
|
+
|
|
16
|
+
## What is in the model
|
|
17
|
+
|
|
18
|
+
- **Parts** are solids `$thickness` thick, where `part(at, rotate)` and
|
|
19
|
+
`place()` put them. A part that bends on a living hinge is bent, its
|
|
20
|
+
hinge's slits cut through it. Each copy of a part is a solid of its own.
|
|
21
|
+
- **Engraving and scoring** are separate bodies on the part's face, in their
|
|
22
|
+
layer's colour, standing 0.1 mm off it (`--mark-height` sets how far).
|
|
23
|
+
Score lines become strips 0.3 mm wide. Each overlaps the face by 0.01 mm,
|
|
24
|
+
so the two never share a face. Marks for the back face (`side = "back"`)
|
|
25
|
+
are on the back.
|
|
26
|
+
- **Hardware** from `hardware()` becomes rods, bars and balls in its colour.
|
|
27
|
+
|
|
28
|
+
A program that places no parts is laid out flat, as `--flat` does.
|
|
29
|
+
|
|
30
|
+
## Assembled or flat
|
|
31
|
+
|
|
32
|
+
By default the parts are where the assembly puts them. With `--flat` they
|
|
33
|
+
lie side by side on the bed, front face up, which is how a flat design
|
|
34
|
+
prints: a coaster, a sign, an ornament, a bookmark. Laid flat, marks for
|
|
35
|
+
the back face and hardware are left out, since nothing can stand under a
|
|
36
|
+
part on the bed.
|
|
37
|
+
|
|
38
|
+
For printing, set the marks to a few layers' height. `--print` does both:
|
|
39
|
+
the parts flat and the marks 0.6 mm high, so the engraving prints as a
|
|
40
|
+
raised second colour.
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
kerf render coaster.kerf -o coaster.3mf --print
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Formats
|
|
47
|
+
|
|
48
|
+
| File | Units | Holds |
|
|
49
|
+
| ------ | ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
50
|
+
| `.glb` | metres, y up (glTF) | a node and mesh for each body, with materials named after the sheet material or layer; each node's `extras` give its `kind` (part, mark, hardware), `part` and `copy` |
|
|
51
|
+
| `.3mf` | millimetres, z up | each part one object, with its engraving and scoring as coloured parts of it, so a slicer prints each in its own colour |
|
|
52
|
+
| `.stl` | millimetres, z up | every body in one mesh, without colours |
|
|
53
|
+
|
|
54
|
+
Every part and mark is a closed solid: each edge is shared by exactly two
|
|
55
|
+
triangles, facing out. A bent part is the exception: it is built from bands
|
|
56
|
+
across its hinge, which meet inside it.
|
|
57
|
+
|
|
58
|
+
## From JavaScript
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
import { render, toModel } from '@mylasertools/kerfscript';
|
|
62
|
+
|
|
63
|
+
const result = render(source);
|
|
64
|
+
const glb = toModel(result, 'glb'); // a Uint8Array
|
|
65
|
+
const print = toModel(result, '3mf', { layout: 'flat', markHeight: 0.6 });
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`meshBodies(result, options)` gives the bodies themselves (positions and
|
|
69
|
+
triangles in millimetres) for a viewer of your own, and `toGlb()`, `to3mf()`
|
|
70
|
+
and `toStl()` write them. The options are `layout` (`"assembled"` or
|
|
71
|
+
`"flat"`), `markHeight`, `lineWidth`, `slitWidth`, `hardware` and `gap`.
|
|
72
|
+
See the [JavaScript API](javascript.md).
|
package/docs/cli.md
CHANGED
|
@@ -104,28 +104,33 @@ installed libraries by themselves.
|
|
|
104
104
|
|
|
105
105
|
## Options
|
|
106
106
|
|
|
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
|
-
| `--
|
|
124
|
-
|
|
|
125
|
-
| `--
|
|
126
|
-
|
|
|
127
|
-
|
|
|
128
|
-
|
|
|
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
|
+
| `--settings` | With `check`: what each setting changes across its range; exit 1 if one changes nothing |
|
|
124
|
+
| `--drive` | With `check`: try every value of the setting marked `drive` (see the customizer) |
|
|
125
|
+
| `-o out.png`, `--px n` | A picture of each sheet, `n` pixels wide (1200), to look at rather than cut |
|
|
126
|
+
| `-o out.glb` | The model in 3D: `.glb` to view, `.3mf` to print in colour, `.stl`; see [3D files](3d-files.md) |
|
|
127
|
+
| `--flat` | With a 3D file: the parts side by side, front face up |
|
|
128
|
+
| `--print` | With a 3D file: `--flat` with the marks 0.6 mm high, to print as a second colour |
|
|
129
|
+
| `--mark-height <mm>` | With a 3D file: how far engraving and scoring stand off the face (0.1) |
|
|
130
|
+
| `--call 'm(1, 2)'` | Run one call of the file's modules instead of its program; `-D` sets variables first |
|
|
131
|
+
| `--params-list file` | With `check`: try each set of settings in a JSON list of objects |
|
|
132
|
+
| `-h, --help` | Show command help |
|
|
133
|
+
| `-v, --version` | Show version numbers |
|
|
129
134
|
|
|
130
135
|
`-D` accepts KerfScript values, including numbers, quoted strings, booleans
|
|
131
136
|
and lists. For example: `-D width=200` or `-D 'name="Ada"'`.
|
package/docs/customizer.md
CHANGED
|
@@ -73,6 +73,62 @@ The playground gives it a Play button that steps it round its range, and
|
|
|
73
73
|
any position that warns (parts colliding, a slot that misses), as
|
|
74
74
|
`--sweep crank=0:5:360` would. `kerf params` lists it with `"drive": true`.
|
|
75
75
|
|
|
76
|
+
## Settings that apply only sometimes
|
|
77
|
+
|
|
78
|
+
A setting that matters only with certain other choices can say so with
|
|
79
|
+
`when` and a condition at the end of its comment, after its range or
|
|
80
|
+
choices or on its own. The playground and the desktop app show it only
|
|
81
|
+
while the condition holds, and hide a group when none of its settings
|
|
82
|
+
show:
|
|
83
|
+
|
|
84
|
+
```kerf
|
|
85
|
+
mount = "wall"; // [wall:On a wall, stand:On a stand]
|
|
86
|
+
// Room for the stand's tabs in their slots
|
|
87
|
+
clearance = 0.15; // [0:0.05:0.5] when mount == "stand"
|
|
88
|
+
// Hole for a nail
|
|
89
|
+
hole = 5; // when mount == "wall"
|
|
90
|
+
|
|
91
|
+
rect([120, 80], r = 6);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The condition can use the other settings by name, numbers, strings,
|
|
95
|
+
`true` and `false`, comparisons, `&&`, `||`, `!`, arithmetic, `? :` and
|
|
96
|
+
`[i]` indexing. A condition that names something other than a setting, or
|
|
97
|
+
calls a function, is reported as a warning, and the setting then always
|
|
98
|
+
shows. `kerf params` lists the condition as `"when"`, and in JavaScript
|
|
99
|
+
`shown(parameter, values, parameters)` says whether a setting applies to
|
|
100
|
+
the values chosen so far.
|
|
101
|
+
|
|
102
|
+
## Settings that do nothing
|
|
103
|
+
|
|
104
|
+
A setting whose slider moves nothing confuses the people using the design.
|
|
105
|
+
`kerf check --settings` tries each setting across its range, the others as
|
|
106
|
+
they are, and says what it changes:
|
|
107
|
+
|
|
108
|
+
```text
|
|
109
|
+
$ kerf check sign.kerf --settings
|
|
110
|
+
Each setting tried across its range, the others as they are:
|
|
111
|
+
name: changes the files
|
|
112
|
+
band: changes the files
|
|
113
|
+
from 50 to 60 it changes nothing
|
|
114
|
+
notes: changes nothing at "for the shop", "for th", "pohs eht rof"
|
|
115
|
+
lift: changes only the assembled view, not the files
|
|
116
|
+
mount: changes the files
|
|
117
|
+
"wall" and "hook" give the same result
|
|
118
|
+
clearance: not tried, as it applies only when mount == "stand"
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
A range is tried at its ends and three points between, a menu at every
|
|
122
|
+
choice, a checkbox both ways and text shorter and changed. The files, the
|
|
123
|
+
sheets' material and thickness and the parts list count as what is cut;
|
|
124
|
+
each part's shape, marks and place as the assembled view. A setting that
|
|
125
|
+
changes nothing, or that the program stops at for all values but one, makes
|
|
126
|
+
the command exit with 1, with the errors listed; a range where nothing
|
|
127
|
+
changes, or choices that give the same result, are pointed out without
|
|
128
|
+
failing. The
|
|
129
|
+
setting marked `drive` and settings whose `when` doesn't hold are left out.
|
|
130
|
+
In JavaScript, `settingEffects(source, options)` gives the same as a list.
|
|
131
|
+
|
|
76
132
|
## Changing settings without editing the file
|
|
77
133
|
|
|
78
134
|
The CLI accepts values with `-D` or a JSON file with `--params`:
|
package/docs/javascript.md
CHANGED
|
@@ -127,6 +127,52 @@ if (width) {
|
|
|
127
127
|
Read the settings again after editing the source; the offsets refer to the
|
|
128
128
|
string passed to `parameters()`.
|
|
129
129
|
|
|
130
|
+
A setting whose comment ends with a `when` condition (see the
|
|
131
|
+
[customizer](customizer.md)) has it as `when`. `shown()` says whether it
|
|
132
|
+
applies to the values chosen so far, the others at their initial values:
|
|
133
|
+
|
|
134
|
+
```js
|
|
135
|
+
import { parameters, shown } from '@mylasertools/kerfscript';
|
|
136
|
+
|
|
137
|
+
const settings = parameters(source).parameters;
|
|
138
|
+
const visible = settings.filter((p) => shown(p, { mount: 'stand' }, settings));
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## settingEffects()
|
|
142
|
+
|
|
143
|
+
What each setting changes, as `kerf check --settings` reports it:
|
|
144
|
+
|
|
145
|
+
```js
|
|
146
|
+
import { settingEffects } from '@mylasertools/kerfscript';
|
|
147
|
+
|
|
148
|
+
for (const e of settingEffects(source)) console.log(e.name, e.effect, e.same);
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Each entry has `name`, the values `tried` and `effect`: `"files"`,
|
|
152
|
+
`"view"` (only the assembled view, steps or hardware), `"nothing"`,
|
|
153
|
+
`"failed"` (the program stops at all values but one, or all of them) or
|
|
154
|
+
`"skipped"` with a `reason`. `same` lists runs of a range, or groups of
|
|
155
|
+
choices, that give the same result, and `errors` the values the program
|
|
156
|
+
stops at. Pass render options as the second argument and how many values
|
|
157
|
+
of a range to try as the third (5).
|
|
158
|
+
|
|
159
|
+
## toModel()
|
|
160
|
+
|
|
161
|
+
Write the model in 3D, as [3D files](3d-files.md) describes:
|
|
162
|
+
|
|
163
|
+
```js
|
|
164
|
+
import { render, toModel } from '@mylasertools/kerfscript';
|
|
165
|
+
|
|
166
|
+
const glb = toModel(render(source), 'glb');
|
|
167
|
+
const print = toModel(render(source), '3mf', { layout: 'flat', markHeight: 0.6 });
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
The format is `"glb"`, `"3mf"` or `"stl"`, and the result a `Uint8Array`.
|
|
171
|
+
`meshBodies(result, options)` gives the solid bodies (positions and
|
|
172
|
+
triangles in millimetres, z up) for a viewer of your own; `toGlb()`,
|
|
173
|
+
`to3mf()` and `toStl()` write a list of them. `result.flat` lists every copy
|
|
174
|
+
of every part flat at its own origin, placed or not.
|
|
175
|
+
|
|
130
176
|
## format()
|
|
131
177
|
|
|
132
178
|
`format(source)` returns the program with its layout set, as `kerf fmt`
|
package/docs/library.md
CHANGED
|
@@ -21,6 +21,7 @@ show each module's description when you hover over it.
|
|
|
21
21
|
| ---------------------------------- | -------------------------------------------------------------- |
|
|
22
22
|
| [`kerf/box`](#boxes) | Finger-jointed boxes and dividers that slide into them |
|
|
23
23
|
| [`kerf/tabs`](#tabs-and-slots) | Tabs on one panel and the slots in another that they go into |
|
|
24
|
+
| [`kerf/stand`](#stands) | A sign or photo standing in a base, upright or leaning back |
|
|
24
25
|
| [`kerf/hinge`](#living-hinges) | Living hinges that bend flat sheet, and a box with round sides |
|
|
25
26
|
| [`kerf/dividers`](#dividers) | Dividers that slot into each other like an egg crate |
|
|
26
27
|
| [`kerf/hanging`](#hanging) | Keyholes, holes and loops for hanging things on a wall |
|
|
@@ -33,6 +34,7 @@ show each module's description when you hover over it.
|
|
|
33
34
|
| [`kerf/rings`](#rings) | Round things of stacked rings on a crossed core |
|
|
34
35
|
| [`kerf/joints`](#joints) | Two profiles halved into each other: crosses, fonts, domes |
|
|
35
36
|
| [`kerf/fit`](#fit-and-align) | Drawings scaled to a size and placed by a point of their box |
|
|
37
|
+
| [`kerf/shapes`](#shapes) | Hearts, teardrops, clouds, shields, banners, tags and more |
|
|
36
38
|
| [`kerf/sizes`](#sizes) | Paper, card and photo sizes |
|
|
37
39
|
| [`kerf/symbols`](#symbols) | 867 pictograms by name |
|
|
38
40
|
| [`kerf/geo`](#maps) | The world's land, for maps and globes |
|
|
@@ -41,6 +43,17 @@ Sizes are in millimetres. Joints use `$thickness`, the sheet thickness, so
|
|
|
41
43
|
set it to what you measure. Each section has an example in the gallery that
|
|
42
44
|
you can open in the playground.
|
|
43
45
|
|
|
46
|
+
### Before you draw it yourself
|
|
47
|
+
|
|
48
|
+
| To | Use |
|
|
49
|
+
| -------------------------------------------------- | ------------------------------------------------------- |
|
|
50
|
+
| Draw a heart, a teardrop, a cloud, a banner or tag | [`kerf/shapes`](#shapes) |
|
|
51
|
+
| Draw a pictogram: a paw, a tree, a star, a house | `symbol("paw", size)` from [`kerf/symbols`](#symbols) |
|
|
52
|
+
| Scale a drawing to a box, or place it by a corner | `fit()` and `align()` from [`kerf/fit`](#fit-and-align) |
|
|
53
|
+
| Close small gaps between shapes | `close(r)`, in place of `offset(delta = -r) offset(r)` |
|
|
54
|
+
| Fit text to a width or a height | `text(fit = [w, h])`, and `text_size()` to measure it |
|
|
55
|
+
| Stand a sign or a photo up | `stand()` from [`kerf/stand`](#stands) |
|
|
56
|
+
|
|
44
57
|
## Boxes
|
|
45
58
|
|
|
46
59
|
`use <kerf/box>`
|
|
@@ -126,6 +139,50 @@ is `true` or `false` for all four, or `[bottom, right, top, left]`.
|
|
|
126
139
|
The centres of the tabs along an edge, for placing anything else that
|
|
127
140
|
lines up with them.
|
|
128
141
|
|
|
142
|
+
## Stands
|
|
143
|
+
|
|
144
|
+
`use <kerf/stand>`
|
|
145
|
+
|
|
146
|
+
A panel (a sign, a photo frame, a calendar) standing in a base, its tabs
|
|
147
|
+
through slots in the base, upright or leaning back. `stand()` makes both
|
|
148
|
+
parts and puts them together; the tabs and slots always match, at any
|
|
149
|
+
lean and `$thickness`.
|
|
150
|
+
|
|
151
|
+
```kerf
|
|
152
|
+
use <kerf/stand>
|
|
153
|
+
|
|
154
|
+
stand(160, depth = 45, lean = 10) {
|
|
155
|
+
rect([160, 90], r = 6);
|
|
156
|
+
engrave() translate([80, 45]) text("OPEN", fit = [120, 40], halign = "center", valign = "cap");
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### `stand(width, depth = 40, count, tab, lean = 0, margin = 10, back, r = 3, clearance = 0.1, name = "Sign")`
|
|
161
|
+
|
|
162
|
+
The children draw the panel, its bottom edge on y = 0 from x = 0 to
|
|
163
|
+
`width`; `stand()` adds the tabs. The base is `depth` deep, `margin` wider
|
|
164
|
+
than the panel on each side, with corners rounded to `r`. The panel leans
|
|
165
|
+
back by `lean` degrees (up to 45), its back face meeting the base `back`
|
|
166
|
+
from the front (half way by default). The parts are `name` and
|
|
167
|
+
`"name stand"`.
|
|
168
|
+
|
|
169
|
+
| Parameter | Default | Meaning |
|
|
170
|
+
| ----------- | ------------------------------- | ------------------------------------ |
|
|
171
|
+
| `count` | one for every 50 mm, at least 1 | Number of tabs |
|
|
172
|
+
| `tab` | half the space between tabs | Width of each tab |
|
|
173
|
+
| `clearance` | `0.1` | Added to each slot's width and depth |
|
|
174
|
+
|
|
175
|
+
### `stand_tabs(width, count, tab, lean = 0)`
|
|
176
|
+
|
|
177
|
+
The tabs for the bottom edge of a panel, x from 0 to `width`, hanging below
|
|
178
|
+
y = 0 far enough to go through a base `$thickness` thick at that lean.
|
|
179
|
+
|
|
180
|
+
### `stand_slots(width, count, tab, lean = 0, clearance = 0.1)`
|
|
181
|
+
|
|
182
|
+
The slots for `stand_tabs()` with the same `width`, `count`, `tab` and
|
|
183
|
+
`lean`, for a base of your own: x from 0 to `width`, for a panel whose back
|
|
184
|
+
face meets the top of the base on y = 0, leaning back towards +y.
|
|
185
|
+
|
|
129
186
|
## Living hinges
|
|
130
187
|
|
|
131
188
|
`use <kerf/hinge>`
|
|
@@ -767,6 +824,69 @@ the origin: `"center"`, `"left"`, `"right"`, `"top"`, `"bottom"`,
|
|
|
767
824
|
`"top-left"`, `"top-right"`, `"bottom-left"`, `"bottom-right"`, or
|
|
768
825
|
`[fx, fy]` as fractions of the box. `anchor_point()` gives those fractions.
|
|
769
826
|
|
|
827
|
+
## Shapes
|
|
828
|
+
|
|
829
|
+
`use <kerf/shapes>`
|
|
830
|
+
|
|
831
|
+
Basic shapes by name, each sized to a box: `size` is `[w, h]`, or one
|
|
832
|
+
number for both, and the shape is centred on the origin as `circle()` and
|
|
833
|
+
`ellipse()` are. Arrows and chevrons point along x; the others stand
|
|
834
|
+
upright. Curves follow `$fn` when it is set, and otherwise take about a
|
|
835
|
+
point per millimetre.
|
|
836
|
+
|
|
837
|
+
```kerf
|
|
838
|
+
use <kerf/shapes>
|
|
839
|
+
|
|
840
|
+
part("gift tag") {
|
|
841
|
+
tag([70, 36]);
|
|
842
|
+
engrave() translate([8, 0]) heart([16, 14]);
|
|
843
|
+
}
|
|
844
|
+
part("sign", at = [0, 50, 0]) {
|
|
845
|
+
banner([120, 30]);
|
|
846
|
+
engrave() text("WELCOME", fit = [80, 12], halign = "center", valign = "cap");
|
|
847
|
+
}
|
|
848
|
+
```
|
|
849
|
+
|
|
850
|
+
A shape with one outline also has a `_points()` function that gives the
|
|
851
|
+
outline as points, counter-clockwise, with the same arguments: for
|
|
852
|
+
`offset_path()`, `flex_strip()`, `point_at()` and anything else that works
|
|
853
|
+
on a list of points. `heart_points(40)` is the outline of `heart(40)`.
|
|
854
|
+
|
|
855
|
+
| Shape | Draws |
|
|
856
|
+
| ------------------------------------------- | ----------------------------------------------------------------------------------------------- |
|
|
857
|
+
| `heart(size = 20)` | a heart: two round lobes, a dip between them and a point at the bottom |
|
|
858
|
+
| `teardrop(size = [14, 20])` | round at the bottom, a point at the top; taller than it is wide |
|
|
859
|
+
| `egg(size = [16, 20], taper = 0.2)` | an egg on its broad end; `taper` 0 is an ellipse |
|
|
860
|
+
| `lens(size = [10, 20])` | two arcs meeting in a point at each end of its longer side: a leaf, a petal, an eye |
|
|
861
|
+
| `crescent(d = 20, thickness)` | a crescent moon `d` across, open to the right, `thickness` (`d / 4`) at its widest |
|
|
862
|
+
| `capsule(size = [30, 10])` | a rectangle with round ends |
|
|
863
|
+
| `diamond(size = [14, 20])` | a rhombus touching the middle of each side of its box |
|
|
864
|
+
| `rounded_polygon(n = 6, r = 10, round = 2)` | `regular_polygon(n, r)` with each corner rounded to radius `round` |
|
|
865
|
+
| `shield(size = [16, 20], point = 0.55)` | a flat top and straight sides curving in to a point; `point` is the curve's part of `h` |
|
|
866
|
+
| `arrow(size = [30, 14], shaft, head)` | an arrow `size[0]` long with a head `size[1]` wide; `shaft` is `h / 3`, `head` `h` |
|
|
867
|
+
| `chevron(size = [12, 20], thickness)` | a chevron (>), each arm `thickness` (`w / 2`) across along x |
|
|
868
|
+
| `banner(size = [60, 16], notch)` | a banner with a V `notch` (`h / 3`) deep cut into each end |
|
|
869
|
+
| `house(size = [20, 24], roof)` | walls and a pitched roof `roof` (`w / 2`) tall |
|
|
870
|
+
| `tag(size = [50, 25], cut, hole)` | a tag with its left corners cut off by `cut` (`h / 4`) and a hole `hole` (`h / 4`) across |
|
|
871
|
+
| `ring(d = 20, width = 3)` | a ring `d` across with a band `width` wide |
|
|
872
|
+
| `scalloped(d = 30, n = 16)` | a circle `d` across with `n` round scallops round its edge |
|
|
873
|
+
| `flower(d = 30, petals = 6, center = 0.35)` | petals round a round middle `center` of `d` across |
|
|
874
|
+
| `cloud(size = [40, 24], puffs = 3)` | a flat bottom with `puffs` round puffs along the top |
|
|
875
|
+
| `speech_bubble(size = [40, 30], r, tail)` | a rounded box with a tail `tail` (`h / 4`) long at its bottom left; `mirror()` it for the right |
|
|
876
|
+
|
|
877
|
+
The outlines: `heart_points()`, `teardrop_points()`, `egg_points()`,
|
|
878
|
+
`lens_points()`, `crescent_points()`, `capsule_points()`,
|
|
879
|
+
`diamond_points()`, `rounded_polygon_points()`, `shield_points()`,
|
|
880
|
+
`arrow_points()`, `chevron_points()`, `banner_points()`, `house_points()`
|
|
881
|
+
and `tag_points()` (without the hole).
|
|
882
|
+
|
|
883
|
+
The library's helpers are there for your own shapes too:
|
|
884
|
+
`shape_size(size, what)` turns a number or `[w, h]` into `[w, h]` and
|
|
885
|
+
checks it, `shape_steps(length)` is the number of points for a curve about
|
|
886
|
+
`length` mm long, `shape_fill(points, size)` scales points to fill a box
|
|
887
|
+
centred on the origin, `shape_centre(points)` centres them, and
|
|
888
|
+
`shape_arc(c, r, a0, a1, n)` gives `n + 1` points along an arc. `shape_tall_lens([w, h])` is a lens pointed at the top and the bottom, as `lens()` draws one no wider than it is tall.
|
|
889
|
+
|
|
770
890
|
## Sizes
|
|
771
891
|
|
|
772
892
|
`use <kerf/sizes>`
|
package/docs/openscad.md
CHANGED
|
@@ -23,15 +23,15 @@ See the [language reference](../LANGUAGE.md) for supported arguments.
|
|
|
23
23
|
|
|
24
24
|
## Different
|
|
25
25
|
|
|
26
|
-
| Feature | OpenSCAD | KerfScript
|
|
27
|
-
| ----------- | ------------------------------------------------------------ |
|
|
28
|
-
| Geometry | 3D and 2D | 2D parts for laser cutting
|
|
29
|
-
| Output | 3D formats and 2D exports | SVG and DXF with operation layers
|
|
30
|
-
| Assignments | The last assignment in a scope applies throughout that scope | Assignments take effect in order
|
|
31
|
-
| Type errors | Many produce `undef` and a warning | Stop evaluation with an error
|
|
32
|
-
| `color()` | Sets a shape's colour |
|
|
33
|
-
| Fonts | Looks up system fonts | Uses fonts supplied by the application or CLI
|
|
34
|
-
| Libraries | Can load local files | Loads the standard library and sources allowed by the host
|
|
26
|
+
| Feature | OpenSCAD | KerfScript |
|
|
27
|
+
| ----------- | ------------------------------------------------------------ | ------------------------------------------------------------------------ |
|
|
28
|
+
| Geometry | 3D and 2D | 2D parts for laser cutting |
|
|
29
|
+
| Output | 3D formats and 2D exports | SVG and DXF with operation layers |
|
|
30
|
+
| Assignments | The last assignment in a scope applies throughout that scope | Assignments take effect in order |
|
|
31
|
+
| Type errors | Many produce `undef` and a warning | Stop evaluation with an error |
|
|
32
|
+
| `color()` | Sets a shape's colour | Ignored with a warning; use `cut()`, `score()`, `engrave()` or `layer()` |
|
|
33
|
+
| Fonts | Looks up system fonts | Uses fonts supplied by the application or CLI |
|
|
34
|
+
| Libraries | Can load local files | Loads the standard library and sources allowed by the host |
|
|
35
35
|
|
|
36
36
|
Assignment order is especially important when adapting a design. A value
|
|
37
37
|
assigned later in a KerfScript program does not change earlier geometry.
|
|
@@ -39,11 +39,13 @@ assigned later in a KerfScript program does not change earlier geometry.
|
|
|
39
39
|
## Not in KerfScript
|
|
40
40
|
|
|
41
41
|
KerfScript does not support `cube`, `sphere`, `cylinder`, `polyhedron`,
|
|
42
|
-
`
|
|
43
|
-
`
|
|
42
|
+
`rotate_extrude` or `projection`. It also does not support `minkowski`,
|
|
43
|
+
`resize`, `import`, `surface` or `render`. Calls to these modules produce an
|
|
44
|
+
error.
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
2D
|
|
46
|
+
`color()` and `linear_extrude()` run as their children, with a warning, so
|
|
47
|
+
the 2D part of an OpenSCAD file runs as it is: `linear_extrude(3) shape();`
|
|
48
|
+
cuts `shape()` as a flat part, whose thickness comes from `$thickness`.
|
|
47
49
|
|
|
48
50
|
## Only in KerfScript
|
|
49
51
|
|
package/docs/parts-and-sheets.md
CHANGED
|
@@ -99,7 +99,8 @@ place(at = [20, 10, 30], rotate = [0, 0, 90]) box([80, 60, 40], name = "crate");
|
|
|
99
99
|
as wrapping it in `material(name = "red acrylic")` would.
|
|
100
100
|
- `mirror = true` cuts the part mirrored left to right. A lopsided end
|
|
101
101
|
plate's other half is the same part mirrored, and its engraving still
|
|
102
|
-
reads the right way round.
|
|
102
|
+
reads the right way round. A mirrored copy of a bent part bends as its
|
|
103
|
+
mirror image: give `bend` as for the part itself.
|
|
103
104
|
- `glue = "top plate", face = "top"` lays a part on another part's face,
|
|
104
105
|
its `at` and `rotate` measured on that face. Move the plate, and what is
|
|
105
106
|
glued on it moves too. A stack glued under a part (`face = "bottom"`)
|
package/docs/versions.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Versions
|
|
2
2
|
|
|
3
|
-
KerfScript 0.
|
|
3
|
+
KerfScript 0.10.0 implements language version 0.3. The package version tracks
|
|
4
4
|
the software release; the language version tracks the syntax and behavior
|
|
5
5
|
of `.kerf` programs.
|
|
6
6
|
|
|
@@ -30,4 +30,4 @@ files used with a design. Applications that store designs should retain
|
|
|
30
30
|
that information and compare the output before upgrading the interpreter.
|
|
31
31
|
|
|
32
32
|
Pin the npm package to an exact version when your application needs a fixed
|
|
33
|
-
renderer, for example `@mylasertools/kerfscript@0.
|
|
33
|
+
renderer, for example `@mylasertools/kerfscript@0.10.0`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mylasertools/kerfscript",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "KerfScript: a programming language and library for laser-cutting generators. Write parametric 2D parts with cut, score and engrave layers, kerf compensation and joinery, then turn settings into SVG or DXF cut files from Node.js, the browser, the command line or WebAssembly.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "AGPL-3.0-only",
|