@mylasertools/kerfscript 0.9.0 → 0.11.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.
Files changed (67) hide show
  1. package/CHANGELOG.md +287 -0
  2. package/LANGUAGE.md +100 -44
  3. package/README.md +2 -1
  4. package/dist/assembly.d.cts +22 -1
  5. package/dist/assembly.d.ts +22 -1
  6. package/dist/bores.d.cts +10 -0
  7. package/dist/bores.d.ts +10 -0
  8. package/dist/cli.js +9977 -6847
  9. package/dist/colors.d.cts +4 -0
  10. package/dist/colors.d.ts +4 -0
  11. package/dist/customizer.d.cts +3 -0
  12. package/dist/customizer.d.ts +3 -0
  13. package/dist/effects.d.cts +31 -0
  14. package/dist/effects.d.ts +31 -0
  15. package/dist/evaluator.d.cts +10 -1
  16. package/dist/evaluator.d.ts +10 -1
  17. package/dist/export/mesh.d.cts +66 -0
  18. package/dist/export/mesh.d.ts +66 -0
  19. package/dist/export/model.d.cts +14 -0
  20. package/dist/export/model.d.ts +14 -0
  21. package/dist/export/pages.d.cts +23 -0
  22. package/dist/export/pages.d.ts +23 -0
  23. package/dist/export/triangulate.d.cts +5 -0
  24. package/dist/export/triangulate.d.ts +5 -0
  25. package/dist/export/zip.d.cts +5 -0
  26. package/dist/export/zip.d.ts +5 -0
  27. package/dist/geometry.d.cts +21 -0
  28. package/dist/geometry.d.ts +21 -0
  29. package/dist/hardware.d.cts +2 -0
  30. package/dist/hardware.d.ts +2 -0
  31. package/dist/highlight.cjs +2 -2
  32. package/dist/highlight.js +2 -2
  33. package/dist/import/dbg.d.cts +1 -0
  34. package/dist/import/dbg.d.ts +1 -0
  35. package/dist/index.cjs +1693 -75
  36. package/dist/index.d.cts +9 -3
  37. package/dist/index.d.ts +9 -3
  38. package/dist/index.js +1693 -75
  39. package/dist/instructions.d.cts +27 -0
  40. package/dist/instructions.d.ts +27 -0
  41. package/dist/language.cjs +1664 -53
  42. package/dist/language.js +1664 -53
  43. package/dist/libraries.cjs +1641 -36
  44. package/dist/libraries.js +1641 -36
  45. package/dist/lights.d.cts +38 -0
  46. package/dist/lights.d.ts +38 -0
  47. package/dist/png.d.cts +14 -0
  48. package/dist/png.d.ts +14 -0
  49. package/dist/render.d.cts +8 -0
  50. package/dist/render.d.ts +8 -0
  51. package/dist/signatures.cjs +98 -9
  52. package/dist/signatures.js +98 -9
  53. package/dist/text.d.cts +29 -0
  54. package/dist/text.d.ts +29 -0
  55. package/dist/verify/types.d.cts +6 -0
  56. package/dist/verify/types.d.ts +6 -0
  57. package/docs/3d-files.md +93 -0
  58. package/docs/cli.md +38 -22
  59. package/docs/customizer.md +69 -0
  60. package/docs/javascript.md +51 -0
  61. package/docs/layers.md +24 -1
  62. package/docs/library.md +574 -16
  63. package/docs/openscad.md +15 -13
  64. package/docs/parts-and-sheets.md +207 -29
  65. package/docs/verification.md +1 -1
  66. package/docs/versions.md +2 -2
  67. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,292 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.11.0 (2026-11-18)
4
+
5
+ Language:
6
+
7
+ - `part(paint = "red")` paints a part: the 3D view, the 3D files and the
8
+ print layout show it in that colour, while it stays on the sheet of its
9
+ material. `layer(name, mode = "paint", color)` paints areas of a part,
10
+ shown the same way and never in the files for the laser. The parts list
11
+ says which parts are painted.
12
+ - Translucent materials: a part of vellum, tracing paper, parchment, rice
13
+ paper, frosted acrylic or paper shows translucent in the 3D view, so a
14
+ light behind it shows through, and GLB files make it partly transparent
15
+ with transmission. `hardware("vellum")` is new, and `hardware("paper")`
16
+ is translucent.
17
+ - A customizer menu can come from a library: `// [figure_names("easter")]`
18
+ or any function call in the brackets is run with the program's built-in
19
+ libraries, each item of the list a choice. `size_list(kind)` in
20
+ `kerf/sizes` lists a table's names for one.
21
+ - A layer's colour can be a name, as `"red"`, as well as a hex colour.
22
+ - `$stands = true` checks that a model meant to stand does: it warns when
23
+ its weight's centre is not over the outline of its lowest points. Parts
24
+ weigh as plywood (`$density`), and `hardware(..., mass = 60)` counts an
25
+ egg or bottle it holds.
26
+ - Parts too big for the bed: `part(split = true)` cuts a part into
27
+ pieces that fit the sheet (or `split = [w, h]`), along lines that cross
28
+ the least material and keep off engraving, joined by jigsaw knobs
29
+ (`$knob`, `$knob_clearance`). Each piece is a part of its own in its
30
+ place, and the parts list says which pieces it joins.
31
+ - Copies that differ: inside `part(qty = n)`, `$copy` is the copy being
32
+ drawn, 0 to n - 1, so a set of tags takes a name each. Copies that come
33
+ out alike stay one part; the parts list says which copies each part is.
34
+ - Hanging parts: `part(hang = [x, y], cord = 20)` hangs a part from a
35
+ point on it, at `at`, on a cord, ring or pin, swung in its own plane
36
+ until its weight is straight below, as a shelf sitter's legs; the cord
37
+ is listed as hardware.
38
+ - Folds along any line for card and paper: `part(fold = [from, to,
39
+ angle])`, or a list of them, folds the part's panels in the assembled
40
+ view and its 3D files, cut lines inside it (a pop-up's slits) parting
41
+ the panels too; `fold_open` opens every fold part of the way, for a
42
+ card shown half open. A fold that divides nothing warns.
43
+ `foldPanels()` and `panelMarks()` give a viewer of your own the panels.
44
+ - Welded text: `text(name, size, weld = true)` slides each word's letters
45
+ together until each overlaps the one before, so a name cuts out in one
46
+ piece; `underline = h` adds a bar under it joining the words. A piece
47
+ still loose, as an i's dot, warns.
48
+ - Text in lines: a `"\n"` in `text()` breaks a line, and
49
+ `text(t, fit = [w, h], lines = 2)` breaks a long name at a space when
50
+ two lines let it be bigger than one. `line_spacing` sets the distance
51
+ between lines.
52
+ - Text on a path: `text(t, size, path = points)` lays the text along a
53
+ path, each letter turned to it, and `text(t, size, arc = r)` round a
54
+ circle, over the top or (r less than 0) along the bottom. Cut, engraved
55
+ or bridged, as any text. A text longer than its path warns.
56
+ - `part(pieces = 2)` or `pieces = "any"` makes a part of loose pieces, as
57
+ a pair of eyes, without the warning that it cuts into separate pieces.
58
+ - Light sources: `hardware("tealight", at)` stands a tealight whose flame
59
+ flickers, LEDs (a strip when longer than 20 mm) and bulbs give off light,
60
+ and `light(at, color, lumens)` adds a light with nothing to show for it.
61
+ The 3D view lights the model with them, with "Dim the room" to see them
62
+ glow, `render()` returns them as `lights`, and GLB files carry them as
63
+ point lights with LEDs and flames emissive.
64
+
65
+ Command line:
66
+
67
+ - `kerf instructions -o out.pdf` writes the assembly instructions as a
68
+ PDF, and `-o out.png` as a picture of each page: the parts, then a page
69
+ for each step with the model as it stands, its new parts in orange and
70
+ what it adds. No browser is needed. Folded parts are drawn folded.
71
+
72
+ Libraries:
73
+
74
+ - `kerf/inlay`: `inlaid()` cuts inlay shapes through a part, or engraves
75
+ them as pockets, and cuts each again as an insert a press fit bigger, of
76
+ its own stock or painted. `part(press_fit = true)` with `glue` lets an
77
+ insert overlap the part it presses into without a collision warning.
78
+ - `kerf/sphere`: `ball()` makes a slot-together ball or dome of half-disc
79
+ fins round an upright axis held by rings with halving joints, hollow
80
+ with a floor and a rail for a scene inside if asked, and with holes for
81
+ a ribbon to hang it by.
82
+ - `kerf/layered`: `layered()` makes multilayer art from its children, the
83
+ layers back to front: each a part glued on the one behind and painted,
84
+ grown to hold up everything in front of it with a rim, with an optional
85
+ shadow layer and a hole through every layer to hang it by.
86
+ - `symbol(name, size, min_width = 1.6)` in `kerf/symbols` grows every
87
+ line narrower than `min_width` to that width, so a symbol drawn small
88
+ can be cut.
89
+ - `kerf/drawers`: `drawers()` makes a carcass of numbered sliding drawers
90
+ in a grid, as for an advent calendar, with the numbers in order, from a
91
+ list or shuffled, a notch or hole to pull each by, and a façade of any
92
+ shape with the drawers' openings cut through it.
93
+ - `kerf/scene` for scene boxes and dioramas: `scene_floor()` and
94
+ `scene_rails()` cut rows of rails, `standee()` gives a drawing feet that
95
+ stand in any rail (with a mound under a narrow one, and clipped to a
96
+ case if asked), `scene_figure()` stands a layered figure in a rail,
97
+ `figure_base()` puts one on a base of its own, and `drip_edge()` and
98
+ `wave_edge()` draw snow, icing and water edges.
99
+ - `kerf/figures`: 31 layered characters in five casts (Christmas, Easter,
100
+ Halloween, nativity and animals). `figure_parts()` builds one as a
101
+ backer, coloured pieces glued on it and details on those, each colour a
102
+ painted part; `figure()` cuts one from a single sheet with the pieces
103
+ scored and the details engraved; `figure_layer()` gives the shapes of
104
+ any layer.
105
+ - `kerf/sizes`: `note_size()` gives banknote sizes (US, Canadian, euro,
106
+ pound and Australian notes), `card_size("gift card")`, and
107
+ `part_size()` has tealights, a maxi tealight, an LED tealight and puck,
108
+ a fairy-light battery box, hen and chocolate eggs, a wine bottle, disc
109
+ magnets, a key ring, AA battery boxes, a coin cell holder, a key fob and
110
+ tissue boxes, with a `diameter` and `height` for round things and a
111
+ `hole` to stand or press them in.
112
+ - `wall(outline, depth)` in `kerf/hinge`: a front plate, a back plate and
113
+ a strip between them bent on living hinges round a closed outline, tabbed
114
+ into slots in both plates where it runs straight. The seam goes where
115
+ `join` asks, and a strip longer than `max_length` is cut into pieces that
116
+ fit the bed. `wall_path()`, `wall_pieces()` and `path_part()` go with it.
117
+
118
+ 3D files:
119
+
120
+ - The print layout, `--print` or `layout: "print"`, makes each part with
121
+ everything glued on it (`glue =` and the layers of a `stack`) one object,
122
+ each layer where the assembly puts it and in its own colour, lying on
123
+ its lowest face. Marks show only where nothing covers them. `--print`
124
+ laid the parts out flat and apart before.
125
+ - A layer's colour comes from a colour named in its material (green, blue,
126
+ yellow, orange, purple, pink, grey, gold, brown) or a `#rrggbb` in it.
127
+ - `result.assembly` entries say which entry each is glued on (`glued`).
128
+
129
+ Changes to the output of existing programs, each a fix:
130
+
131
+ - A child of `intersection()` that makes nothing at all, as OpenSCAD
132
+ counts it (an `if` whose condition is false and that has no `else`, an
133
+ `echo()` or `assert()` with no children), no longer empties the
134
+ intersection; in `difference()` it is not the shape cut from, the next
135
+ child is.
136
+ - `flex_strip()` and `strip_bends()` keep a curve whose radius changes as
137
+ several bends, one for each stretch of much the same radius, instead of
138
+ one bend of the average radius. The cut file is unchanged; the bent strip
139
+ in the 3D view, the exported models, the collision checks and the slots it
140
+ cuts follow the path.
141
+ - A path given to `flex_strip()` or `strip_bends()` that repeats a point,
142
+ as where a straight run and an arc share their end, bends where the arc
143
+ starts; the repeated point had started the hinge and the bend a few mm
144
+ early, on the straight.
145
+ - `flex_strip()` rounds each sharp corner of its path to the arc the strip
146
+ bends round, radius `r` inside, and is as long as that rounded path, so
147
+ it ends where the path ends; it ran on past it by about 1.6 mm a corner
148
+ before, and was cut that much too long. `strip_path()`, `strip_loop()`
149
+ and `strip_corner()` give the rounded path.
150
+ - Closed cuts on a sheet go deepest first: a part nested in another part's
151
+ hole is cut before that hole, and a hole before the outline round it.
152
+ Holes of every part used to come before every outline, so a part nested
153
+ in a hole could be cut after the hole had freed the stock under it.
154
+ - With `$layout = "none"`, parts of different materials or thicknesses go
155
+ on separate sheets, as when packed. They shared one sheet, labelled with
156
+ the first part's material.
157
+ - A tab that only dips into a part, less than 1 mm or half its thickness,
158
+ is not cut as a slot because another tab of its part goes deep enough:
159
+ each piece that enters the part is judged on its own depth, and the
160
+ shallow one is reported as a collision.
161
+ - A part glued to a stack (`glue =` a part with `stack = n`) goes on the
162
+ stack's top layer, or under its bottom one, not on its first layer inside
163
+ the stack; with as many copies as the stack has, one goes on each copy
164
+ of the stack, not all on the first.
165
+ - A bent part inside `translate()`, `scale()` or `mirror()` bends where its
166
+ drawing went; its bends stayed where they were drawn. Turning one with
167
+ `rotate()` is an error: turn it with `part(rotate = ...)`.
168
+ - `measure()` counts what any layer of mode `"cut"` cuts, and leaves out
169
+ any layer of mode `"guide"`; it went by the names `cut` and `guide`, so
170
+ a custom cut layer was left out of `$area` and `$centroid`.
171
+ - `text(fit = w)` is no wider than `w` where a glyph reaches past its
172
+ advance, as a `q`'s tail does; it was fitted by the advance alone.
173
+ - `pattern()` clips each tile that an edge of the area crosses. A tile with
174
+ its corners inside the area and none of the area's corners inside it was
175
+ kept whole, over a rib or a strip of the area running through it.
176
+
177
+ Fixes:
178
+
179
+ - A part with nothing in it warns: `Part "P" is empty`.
180
+ - `slots = []` asks for no slots, without a warning that none pass through.
181
+ - `flex_strip()` along a path with no curve or corner makes a straight
182
+ strip; it stopped with "bend must be [x0, x1, angle]". `bend = []` is no
183
+ bend.
184
+ - A `$kerf` or `$thickness` that is not a finite number, as `0/0` or
185
+ `1/0` gives, is an error; a NaN kerf was taken as 0 and an infinite
186
+ thickness accepted.
187
+ - A layer set again with `layer()` after marks went on its back face sets
188
+ its back the same way, mode, colour and order; the back kept the first
189
+ settings. Making it a cut layer then is an error.
190
+ - A library path in `use <...>` or `include <...>` may hold any character
191
+ a folder name has, as `(`, `#` or `é`.
192
+ - The back-face docs say the back job is turned over within the file's
193
+ width, and how far to move it on stock wider than the file.
194
+ - A stack whose layers take different blind slots, and so become a part
195
+ each (`"top, layer 1"`), is still found by its own name for `halving`,
196
+ and still prints as one stack with `--print`.
197
+ - `wall()` never cuts a piece longer than `max_length`; a cut it could not
198
+ put on a straight could leave one longer. Without `join`, its seam is in
199
+ the middle of the outline's longest side, not at its first point, which
200
+ is often a corner.
201
+
202
+ ## 0.10.0 (2026-11-16)
203
+
204
+ Language version 0.3, as in 0.9.0: programs run as before, except that
205
+ `color()` and `linear_extrude()` now warn instead of stopping.
206
+
207
+ Changes to the output of existing programs, each a fix (see Fixes below):
208
+
209
+ - Slots for parts that pass through at an angle are cut to what passes
210
+ through the sheet, so they can be narrower than before; check the fit of
211
+ angled tabs, tapered ones especially.
212
+ - `intersection()` with a part as its first child clips the part instead of
213
+ emptying it.
214
+ - A default such as `w = $thickness` takes the `$thickness` passed with the
215
+ call.
216
+ - Parts riding a bent part, and mirrored copies of bent parts, are placed,
217
+ slotted and bored where they end up.
218
+ - SVG import reads units on shapes and keeps a viewBox's proportions.
219
+
220
+ Language:
221
+
222
+ - `text(fit = [w, h])` keeps text no wider than `w` and its capitals no
223
+ taller than `h`; `valign = "cap"` centres the capitals on y = 0.
224
+ - `text_size()` gives a text's measurements as a record: `width`, `height`,
225
+ `bounds`, `cap`, `ascent`, `descent` and the `size` used.
226
+ - `ellipse(d = [w, h])` takes the width and height, as `circle(d)` does.
227
+ - `color()` and `linear_extrude()` run as their children with a warning, so
228
+ the 2D part of an OpenSCAD file runs unchanged.
229
+ - Recursion and step-limit errors say what to check, instead of assuming an
230
+ endless loop.
231
+ - `use <...>` takes a Windows path, as `use <C:\Designs\lib\feet>`, and
232
+ paths with spaces; a library named that way finds the libraries beside it.
233
+
234
+ Fixes:
235
+
236
+ - `intersection()` clips a part that is its first child to the other
237
+ children, and warns when it leaves a part nothing to cut.
238
+ - A module's or function's defaults see the special variables passed with
239
+ the call: `w = $thickness` called with `$thickness = 6` is 6.
240
+ - Slots for parts at an angle cut only what passes through the sheet: a
241
+ tapered tab no longer cuts its wider part into the slot.
242
+ - Parts riding a bent part (`on = "host"`) have their slots, bores and
243
+ halvings cut where they ride.
244
+ - `sort()` counts its comparisons against the step limit.
245
+ - A mirrored copy of a bent part bends as its mirror image, and the copies
246
+ of a mirrored rider each ride their own host.
247
+ - Children that define a layer are evaluated each time they are used.
248
+ - Shaft capture fails when a part on the shaft can slide off over a bearing
249
+ and its retainer.
250
+ - SVG import: lengths on shapes keep their units (`width="40mm"`), and a
251
+ viewBox keeps its proportions as `preserveAspectRatio` says, centred by
252
+ default.
253
+
254
+ 3D files:
255
+
256
+ - `kerf render model.kerf -o model.glb` writes the model in 3D: `.glb` to view
257
+ or render, `.3mf` to 3D print in colour, `.stl` as one mesh. Each part is a
258
+ closed solid as thick as its sheet, where the assembly puts it, bent on its
259
+ living hinges; engraving and scoring are thin coloured bodies on its faces,
260
+ and hardware rods and balls. `--flat` lays the parts side by side, front
261
+ face up, for printing; `--mark-height` sets how far the marks stand off,
262
+ and `--print` is `--flat` with the marks 0.6 mm high.
263
+ - In JavaScript, `toModel(result, "glb" | "3mf" | "stl", options)`, with
264
+ `meshBodies()` for the solid bodies and `result.flat` for every part flat.
265
+
266
+ Libraries:
267
+
268
+ - `kerf/shapes`: `heart`, `teardrop`, `egg`, `lens`, `crescent`, `capsule`,
269
+ `diamond`, `rounded_polygon`, `shield`, `arrow`, `chevron`, `banner`,
270
+ `house`, `tag`, `ring`, `scalloped`, `flower`, `cloud` and
271
+ `speech_bubble`, each sized to a box and centred; shapes with one outline
272
+ also give it as points, `heart_points()` and the like.
273
+ - `kerf/stand`: `stand()` stands a sign or a photo in a base, upright or
274
+ leaning back, with `stand_tabs()` and `stand_slots()` for a base of your
275
+ own.
276
+
277
+ Customizer:
278
+
279
+ - `kerf check --settings` tries each setting across its range and says what
280
+ it changes: the files, only the assembled view, or nothing. It points out
281
+ where a slider stops changing anything and menu choices that give the same
282
+ result, and exits with 1 when a setting changes nothing or the program
283
+ stops at its values.
284
+ `settingEffects()` gives the same in JavaScript.
285
+ - A setting can end its comment with `when` and a condition on the other
286
+ settings, `// [0:0.05:0.5] when mount == "stand"`: the playground and the
287
+ desktop app show it only while the condition holds. `shown()` evaluates
288
+ it in JavaScript.
289
+
3
290
  ## 0.9.0 (2026-11-09)
4
291
 
5
292
  Language version 0.3, as in 0.8.0: programs run as before.
package/LANGUAGE.md CHANGED
@@ -193,26 +193,31 @@ module hang_hole(d = 5) {
193
193
 
194
194
  ## Special variables
195
195
 
196
- | Name | Default | Meaning |
197
- | ----------------- | ------------- | ----------------------------------------------------------------------------- |
198
- | `$thickness` | `3` | material thickness, used by joinery and stored on parts |
199
- | `$kerf` | `0` | beam width; cut outlines are offset by half of it |
200
- | `$material` | `"material"` | material name; parts are packed per material and thickness |
201
- | `$sheet` | `[600, 400]` | sheet size for packing |
202
- | `$gap` | `3` | space between packed parts and around the sheet edge |
203
- | `$layout` | `"pack"` | `"pack"` packs parts onto sheets, `"none"` keeps your placement |
204
- | `$fn` `$fa` `$fs` | `0` `2` `0.2` | curve resolution: fixed segment count, or max angle and max segment length |
205
- | `$font` | | default font name for `text()` |
206
- | `$mirrored` | `false` | set inside a mirrored part and on the back face: `text()` reads right |
207
- | `$scale` | `1` | the model's scale: `140cm` is 1400 mm divided by `$scale` |
208
- | `$nest` | `false` | pack small parts into the holes of bigger ones |
209
- | `$registration` | `false` | print-and-cut marks in three corners of every sheet |
210
- | `$label_parts` | `false` | engrave each part's number on its back face, as in the parts list and steps |
211
- | `$join_lines` | `false` | join lines that meet end to end and order them nearest first, for less travel |
212
- | `$min_width` | `1.5` | warn where a part's material is narrower than this; `0` turns it off |
213
- | `$bounds` | | set by `measure()` for the children after the one it measures |
214
- | `$area` | | set by `measure()`: the area of material the measured child cuts |
215
- | `$centroid` | | set by `measure()`: the measured child's balance point `[x, y]` |
196
+ | Name | Default | Meaning |
197
+ | ----------------- | ------------- | ------------------------------------------------------------------------------------------------------ |
198
+ | `$thickness` | `3` | material thickness, used by joinery and stored on parts |
199
+ | `$kerf` | `0` | beam width; cut outlines are offset by half of it |
200
+ | `$material` | `"material"` | material name; parts are packed per material and thickness |
201
+ | `$sheet` | `[600, 400]` | sheet size for packing |
202
+ | `$gap` | `3` | space between packed parts and around the sheet edge |
203
+ | `$layout` | `"pack"` | `"pack"` packs parts onto sheets, `"none"` keeps your placement |
204
+ | `$fn` `$fa` `$fs` | `0` `2` `0.2` | curve resolution: fixed segment count, or max angle and max segment length |
205
+ | `$font` | | default font name for `text()` |
206
+ | `$mirrored` | `false` | set inside a mirrored part and on the back face: `text()` reads right |
207
+ | `$copy` | | inside `part(qty = n)`: the copy being drawn, 0 to n - 1; copies that differ become parts of their own |
208
+ | `$scale` | `1` | the model's scale: `140cm` is 1400 mm divided by `$scale` |
209
+ | `$nest` | `false` | pack small parts into the holes of bigger ones |
210
+ | `$registration` | `false` | print-and-cut marks in three corners of every sheet |
211
+ | `$label_parts` | `false` | engrave each part's number on its back face, as in the parts list and steps |
212
+ | `$join_lines` | `false` | join lines that meet end to end and order them nearest first, for less travel |
213
+ | `$min_width` | `1.5` | warn where a part's material is narrower than this; `0` turns it off |
214
+ | `$knob` | `12` | the size of the jigsaw knobs joining the pieces of a split part |
215
+ | `$stands` | `false` | `true` for a model meant to stand: it warns if its weight's centre is not over what it stands on |
216
+ | `$density` | `0.6` | the parts' density in g/cm³ for that check, plywood's by default |
217
+ | `$knob_clearance` | `0.15` | the room between a knob and its socket |
218
+ | `$bounds` | | set by `measure()` for the children after the one it measures |
219
+ | `$area` | | set by `measure()`: the area of material the measured child cuts |
220
+ | `$centroid` | | set by `measure()`: the measured child's balance point `[x, y]` |
216
221
 
217
222
  ## Layers
218
223
 
@@ -231,7 +236,9 @@ layer("pocket", mode = "fill", color = "#00aa00") ...
231
236
  ```
232
237
 
233
238
  Use `layer(name, mode, color)` to define a custom layer. Its mode is
234
- `"cut"`, `"line"`, `"fill"` or `"guide"`.
239
+ `"cut"`, `"line"`, `"fill"`, `"guide"` or `"paint"`; a paint layer is
240
+ never cut or engraved, only shown in 3D views and the print layout. Its
241
+ colour is a hex colour or a name, as `"red"`.
235
242
 
236
243
  Marks can go on a part's **back face** too: `engrave(side = "back")`,
237
244
  `score(side = "back")` or `layer(name, side = "back")`. Draw them where
@@ -288,6 +295,10 @@ material(thickness = 4, kerf = 0.12, name = "birch") {
288
295
  - More about a part, all named:
289
296
  - `material = "red acrylic"`: the part's material, as `material(name =
290
297
  ...)` would set `$material` round it.
298
+ - `pieces = 2` or `pieces = "any"`: the part is meant to cut into that
299
+ many separate pieces, so it does not warn that it is in pieces.
300
+ - `paint = "red"`: the part's colour in 3D views and the print
301
+ layout, painted after cutting; it stays on the sheet of its material.
291
302
  - `stack = n`: n layers glued at each placement, one thickness apart
292
303
  along the part's z. The parts list says how many make a stack.
293
304
  - `mirror = true`: the part is cut mirrored left to right (x becomes
@@ -299,9 +310,27 @@ material(thickness = 4, kerf = 0.12, name = "birch") {
299
310
  - `bend = [x0, x1, angle]`, or a list of them: a living hinge from x0 to
300
311
  x1 along the part's x bends it by `angle` degrees in the assembled
301
312
  view, folding the far end up towards its top face (down for a negative
302
- angle). The hinge's middle layer keeps its length.
313
+ angle). The hinge's middle layer keeps its length. An empty list is
314
+ no bend.
315
+ - `fold = [from, to, angle]`, or a list of them: folds along any line
316
+ in the assembled view, as for card. The folds (and cut lines inside
317
+ the part, as a pop-up's slits) cut it into panels; the one at the
318
+ origin stays flat and each other turns about the folds between,
319
+ towards the top face for an angle more than 0. `fold_open` (1) scales
320
+ every fold's angle, 0 lying flat. A fold that divides nothing warns.
321
+ - `split = true`, or `[w, h]`: a part too big for the bed is cut into
322
+ pieces that fit the sheet (less its margins) or that size, joined by
323
+ jigsaw knobs `$knob` mm across; the parts list says which pieces each
324
+ joins.
325
+ - `hang = [x, y]`, `cord = 0`: the part hangs from that point on it, at
326
+ `at`, and swings in the plane `rotate` gives until its weight is
327
+ straight below; `cord` hangs it that much lower on a cord, listed as
328
+ hardware.
303
329
  - `on = "name"`: the part is glued to that bent part, and moves with the
304
330
  run of it under its centre.
331
+ - `press_fit = true` with `glue`: the part is pressed into the one it is
332
+ glued to, as an inlay, so the two overlap on purpose and are not
333
+ checked against each other.
305
334
  - `glue = "name"`, `face = "top"`: the part is glued flat on that part's
306
335
  top (or bottom) face; its `at` and `rotate` are measured on the face,
307
336
  and the parts list says what it is glued to. With as many copies as
@@ -345,7 +374,14 @@ material(thickness = 4, kerf = 0.12, name = "birch") {
345
374
  to 128. `shape = "ball"` (or `sides = 0`) is a ball of diameter `size`
346
375
  midway between `from` and `to`; `to` may be left out. It comes back with
347
376
  `sides = 0` and `from` and `to` both at its centre. `render()` returns it
348
- as `hardware`, and `kerf check` lists it.
377
+ as `hardware`, and `kerf check` lists it. A `"tealight"` stands at
378
+ `from`, 39 mm across and 16 mm high unless `to` and `size` say
379
+ otherwise; tealights, LEDs and bulbs give off light.
380
+ - `light(at, color = "warm white", lumens = 20, to, flicker = false,
381
+ label)` is a light source with nothing to show for it, at a point or,
382
+ with `to`, all along a strip. `render()` returns every light, those of
383
+ tealights, LEDs and bulbs too, as `lights`; the 3D view lights the model
384
+ with them and GLB files carry them.
349
385
  - Shapes outside any part form one part named `part`.
350
386
  - `material(thickness, kerf, name) { ... }` sets those special variables for
351
387
  its children.
@@ -364,24 +400,29 @@ export examples.
364
400
 
365
401
  ### Shapes
366
402
 
367
- | Module | Notes |
368
- | ---------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
369
- | `rect(size, center = false, r = 0)` | `size` is a number or `[w, h]`; `r` rounds the corners. `square` is an alias |
370
- | `circle(r)` or `circle(d = ...)` | |
371
- | `ellipse([rx, ry])` | |
372
- | `regular_polygon(n, r)` | corner radius `r` |
373
- | `star(n, r, inner)` | |
374
- | `polygon(points, paths)` | even-odd fill, `paths` lists point indexes per outline |
375
- | `path(d, fill = "evenodd", close = false)` | SVG path data; closed subpaths become shapes, open ones lines unless `close` |
376
- | `text(text, size = 10, font, halign, valign, spacing = 1)` | `halign`: left, center, right; `valign`: baseline, top, center, bottom |
377
- | `text(text, size, fit = width)` | no wider than `fit`: the size shrinks to fit, never above `size` if given |
378
- | `text(text, size, weight = "bold")` | strokes thickened by 3.5% of the size, or by a number of mm (less than 0 thins) |
379
- | `text(text, size, bridge = w)` | every island (an i's dot, an accent, a stencil's counter) joined to the rest by a strip `w` wide, for cut-out and stencil lettering |
380
- | `line(from, to)` | a line, not an area |
381
- | `line(from, to, width)` | a strip `width` wide between the points, an area |
382
- | `spline(points, width, steps = 8, closed = false)` | a smooth curve through the points; with `width`, an area along it |
383
- | `polyline(points, closed = false)` | |
384
- | `arc(r, start = 0, end = 90)` | arc line, angles in degrees |
403
+ | Module | Notes |
404
+ | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
405
+ | `rect(size, center = false, r = 0)` | `size` is a number or `[w, h]`; `r` rounds the corners. `square` is an alias |
406
+ | `circle(r)` or `circle(d = ...)` | |
407
+ | `ellipse([rx, ry])` or `ellipse(d = [w, h])` | radii, or the width and height |
408
+ | `regular_polygon(n, r)` | corner radius `r` |
409
+ | `star(n, r, inner)` | |
410
+ | `polygon(points, paths)` | even-odd fill, `paths` lists point indexes per outline |
411
+ | `path(d, fill = "evenodd", close = false)` | SVG path data; closed subpaths become shapes, open ones lines unless `close` |
412
+ | `text(text, size = 10, font, halign, valign, spacing = 1)` | `halign`: left, center, right; `valign`: baseline, top, center, bottom, or cap (capitals centred on y = 0) |
413
+ | `text(text, size, fit = width)` | no wider than `fit`: the size shrinks to fit, never above `size` if given |
414
+ | `text(text, size, fit = [w, h])` | no wider than `w`, capitals no taller than `h`; either may be `undef` |
415
+ | `text(text, size, weight = "bold")` | strokes thickened by 3.5% of the size, or by a number of mm (less than 0 thins) |
416
+ | `text(text, size, bridge = w)` | every island (an i's dot, an accent, a stencil's counter) joined to the rest by a strip `w` wide, for cut-out and stencil lettering |
417
+ | `text(text, size, weld = true)` | each word's letters slid together until each overlaps the one before (by a tenth of the size and at least 1.5 mm, or by `weld` mm when it is a number), so a name cuts out in one piece, as script names on key rings and toppers are; `underline = h` adds a bar `h` high under the baseline that joins the words; what is still loose, as an i's dot, warns |
418
+ | `text(text, size, lines = n)` | a block of lines: a `"\n"` in the text breaks a line, and the text breaks at spaces into up to `n` lines in all, as even as they go; with `fit`, as many lines as let the text be biggest, so a long name fills a tag in two; `line_spacing = 1` sets the distance between lines; `halign` aligns each line and `valign` the block |
419
+ | `text(text, size, path = points)` | laid along the path through the points, each letter turned to it, its baseline on the path; centred on the path, or `halign` puts the start or end there; a warning if it runs past an end |
420
+ | `text(text, size, arc = r)` | round a circle of radius `r` about the origin: centred over the top, reading round it, or with `r` less than 0 along the bottom, reading left to right |
421
+ | `line(from, to)` | a line, not an area |
422
+ | `line(from, to, width)` | a strip `width` wide between the points, an area |
423
+ | `spline(points, width, steps = 8, closed = false)` | a smooth curve through the points; with `width`, an area along it |
424
+ | `polyline(points, closed = false)` | |
425
+ | `arc(r, start = 0, end = 90)` | arc line, angles in degrees |
385
426
 
386
427
  Supply geometry as children of a shape-processing module, for example
387
428
  `translate([10, 0]) circle(d = 5);`. Fonts used by `text()` must be supplied
@@ -424,6 +465,14 @@ playground, the command line and `kerfscript.wasm` have `Atkinson`
424
465
  | `stroke(width)` | turns lines into areas of that width, for cutting single line art |
425
466
  | `outline()` | turns areas into their outline lines |
426
467
 
468
+ As in OpenSCAD, a child that makes nothing at all is left out of
469
+ `difference()` and `intersection()`: an `if` whose condition is false and
470
+ that has no `else`, an `echo()` or `assert()` with no children, or a child
471
+ switched off with `*`. It neither empties an intersection nor becomes the
472
+ shape a difference cuts from. Any other child counts even when it draws
473
+ nothing, such as a `for` over an empty list or an empty `union()`, and
474
+ then empties an intersection.
475
+
427
476
  ### Joinery
428
477
 
429
478
  | Module | Notes |
@@ -581,11 +630,18 @@ related but different pattern.
581
630
 
582
631
  `text_width(text, size, font)` returns the advance width, including glyph
583
632
  spacing. `text_metrics(text, size, font)` returns
584
- `[advance, [[x0, y0], [x1, y1]], ascent, descent]`.
633
+ `[advance, [[x0, y0], [x1, y1]], ascent, descent]`. `text_size(text, size,
634
+ font)` returns the same as a record, with the capital height and the size
635
+ used: `width`, `height`, `bounds`, `cap`, `ascent`, `descent` and `size`.
636
+
637
+ ```kerf
638
+ m = text_size("Anna", fit = [80, 20]);
639
+ echo(m.size, m.cap); // the size that fits, and capitals 20 mm tall
640
+ ```
585
641
 
586
- With `fit = width` they measure the text at the size `text()` would fit it to.
642
+ With `fit` they measure the text at the size `text()` would fit it to.
587
643
 
588
- Both require the font to be available to the renderer, just like `text()`.
644
+ All three require the font to be available to the renderer, just like `text()`.
589
645
 
590
646
  ### Joint dimensions
591
647
 
package/README.md CHANGED
@@ -235,7 +235,8 @@ Errors are thrown as `KerfError` with `line` and `col`.
235
235
 
236
236
  - [Getting started](docs/getting-started.md), then the guides on
237
237
  [layers](docs/layers.md), [kerf](docs/kerf.md),
238
- [parts and sheets](docs/parts-and-sheets.md), [settings](docs/customizer.md),
238
+ [parts and sheets](docs/parts-and-sheets.md), [3D files](docs/3d-files.md),
239
+ [settings](docs/customizer.md),
239
240
  the [desktop app](docs/desktop.md), the [command line](docs/cli.md), the
240
241
  [JavaScript API](docs/javascript.md),
241
242
  [assembly verification](docs/verification.md),
@@ -1,4 +1,4 @@
1
- import { type Bend, type Poly } from './geometry.cjs';
1
+ import { type Bend, type Fold, type Poly } from './geometry.cjs';
2
2
  export type Vec3 = [number, number, number];
3
3
  export interface Placement {
4
4
  at: Vec3;
@@ -10,12 +10,16 @@ export interface AssemblyPart {
10
10
  copy: number;
11
11
  thickness: number;
12
12
  material?: string;
13
+ paint?: string;
13
14
  matrix: number[];
14
15
  outline: Poly[];
15
16
  placed: boolean;
16
17
  bends?: Bend[];
18
+ folds?: Fold[];
17
19
  step?: number;
18
20
  stack?: number;
21
+ glued?: number;
22
+ pressFit?: boolean;
19
23
  marks?: Mark[];
20
24
  }
21
25
  export interface Mark {
@@ -39,10 +43,27 @@ export declare function translation(x: number, y: number, z: number): number[];
39
43
  export declare const IDENTITY4: number[];
40
44
  export declare function invert(m: number[]): number[];
41
45
  export declare function sortedBends(bends: Bend[]): Bend[];
46
+ /** Where each bend lies along the part's own x, as [from, to] */
47
+ export declare function bendSpans(bends: Bend[]): [number, number][];
42
48
  export declare function bendRuns(bends: Bend[], t: number): number[][];
43
49
  export declare function bendPoint(bends: Bend[], t: number, p: Vec3): Vec3;
44
50
  export declare function runOf(bends: Bend[], x: number): number;
45
51
  export declare function bentPieces(p: AssemblyPart): AssemblyPart[];
52
+ /** A folded part's panels, each its outline and the 4 x 4 matrix that
53
+ * folds it, in the part's own coordinates. The folds cut the part into
54
+ * panels; the panel at the origin (else the biggest) stays flat, and each
55
+ * other one turns about the folds between it and that one, towards the
56
+ * top face for an angle more than 0, hinged on the face it folds towards.
57
+ * `unused` lists the folds that do not divide the part. */
58
+ export declare function foldPanels(outline: Poly[], folds: Fold[], thickness: number): {
59
+ outline: Poly[];
60
+ matrix: number[];
61
+ }[] & {
62
+ unused?: number[];
63
+ };
64
+ /** The marks on one panel of a folded part: fills clipped to it, lines
65
+ * (and the outlines of line marks) cut where they leave it */
66
+ export declare function panelMarks(marks: Mark[], panel: Poly[]): Mark[];
46
67
  /** The most bands a part's bends are cut into for a 3D view */
47
68
  export declare const MAX_BENT_BANDS = 2000;
48
69
  export declare function meshPieces(regions: Poly[], bends?: Bend[], step?: number): Poly[][];
@@ -1,4 +1,4 @@
1
- import { type Bend, type Poly } from './geometry.js';
1
+ import { type Bend, type Fold, type Poly } from './geometry.js';
2
2
  export type Vec3 = [number, number, number];
3
3
  export interface Placement {
4
4
  at: Vec3;
@@ -10,12 +10,16 @@ export interface AssemblyPart {
10
10
  copy: number;
11
11
  thickness: number;
12
12
  material?: string;
13
+ paint?: string;
13
14
  matrix: number[];
14
15
  outline: Poly[];
15
16
  placed: boolean;
16
17
  bends?: Bend[];
18
+ folds?: Fold[];
17
19
  step?: number;
18
20
  stack?: number;
21
+ glued?: number;
22
+ pressFit?: boolean;
19
23
  marks?: Mark[];
20
24
  }
21
25
  export interface Mark {
@@ -39,10 +43,27 @@ export declare function translation(x: number, y: number, z: number): number[];
39
43
  export declare const IDENTITY4: number[];
40
44
  export declare function invert(m: number[]): number[];
41
45
  export declare function sortedBends(bends: Bend[]): Bend[];
46
+ /** Where each bend lies along the part's own x, as [from, to] */
47
+ export declare function bendSpans(bends: Bend[]): [number, number][];
42
48
  export declare function bendRuns(bends: Bend[], t: number): number[][];
43
49
  export declare function bendPoint(bends: Bend[], t: number, p: Vec3): Vec3;
44
50
  export declare function runOf(bends: Bend[], x: number): number;
45
51
  export declare function bentPieces(p: AssemblyPart): AssemblyPart[];
52
+ /** A folded part's panels, each its outline and the 4 x 4 matrix that
53
+ * folds it, in the part's own coordinates. The folds cut the part into
54
+ * panels; the panel at the origin (else the biggest) stays flat, and each
55
+ * other one turns about the folds between it and that one, towards the
56
+ * top face for an angle more than 0, hinged on the face it folds towards.
57
+ * `unused` lists the folds that do not divide the part. */
58
+ export declare function foldPanels(outline: Poly[], folds: Fold[], thickness: number): {
59
+ outline: Poly[];
60
+ matrix: number[];
61
+ }[] & {
62
+ unused?: number[];
63
+ };
64
+ /** The marks on one panel of a folded part: fills clipped to it, lines
65
+ * (and the outlines of line marks) cut where they leave it */
66
+ export declare function panelMarks(marks: Mark[], panel: Poly[]): Mark[];
46
67
  /** The most bands a part's bends are cut into for a 3D view */
47
68
  export declare const MAX_BENT_BANDS = 2000;
48
69
  export declare function meshPieces(regions: Poly[], bends?: Bend[], step?: number): Poly[][];