@mylasertools/kerfscript 0.2.0 → 0.3.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 +97 -0
- package/CLA.md +8 -5
- package/COMMERCIAL-LICENSE.md +23 -28
- package/LANGUAGE.md +194 -60
- package/README.md +89 -39
- package/THIRD-PARTY-NOTICES.md +68 -4
- package/TRADEMARKS.md +16 -10
- package/dist/cli.js +773 -297
- package/dist/evaluator.d.cts +26 -0
- package/dist/evaluator.d.ts +26 -0
- package/dist/export/dxf.d.cts +1 -1
- package/dist/export/dxf.d.ts +1 -1
- package/dist/export/svg.d.cts +2 -0
- package/dist/export/svg.d.ts +2 -0
- package/dist/font.d.cts +3 -0
- package/dist/font.d.ts +3 -0
- package/dist/functions.d.cts +21 -2
- package/dist/functions.d.ts +21 -2
- package/dist/index.cjs +14 -14
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +14 -14
- package/dist/lexer.d.cts +4 -1
- package/dist/lexer.d.ts +4 -1
- package/dist/parser.d.cts +1 -1
- package/dist/parser.d.ts +1 -1
- package/dist/render.d.cts +3 -2
- package/dist/render.d.ts +3 -2
- package/dist/values.d.cts +10 -2
- package/dist/values.d.ts +10 -2
- package/dist/wasm.d.cts +1 -0
- package/dist/wasm.d.ts +1 -0
- package/docs/cli.md +69 -28
- package/docs/compatibility.md +40 -65
- package/docs/customizer.md +40 -28
- package/docs/desktop.md +96 -0
- package/docs/getting-started.md +48 -31
- package/docs/javascript.md +108 -51
- package/docs/kerf.md +36 -39
- package/docs/layers.md +71 -37
- package/docs/openscad.md +52 -48
- package/docs/parts-and-sheets.md +45 -31
- package/docs/versions.md +20 -30
- package/docs/webassembly.md +131 -0
- package/fonts/OFL.txt +92 -0
- package/package.json +10 -6
package/docs/openscad.md
CHANGED
|
@@ -1,67 +1,71 @@
|
|
|
1
1
|
# Coming from OpenSCAD
|
|
2
2
|
|
|
3
|
-
KerfScript
|
|
4
|
-
OpenSCAD
|
|
5
|
-
|
|
6
|
-
OpenSCAD files do not run unchanged.
|
|
3
|
+
KerfScript uses syntax familiar to OpenSCAD users, with features for laser
|
|
4
|
+
cutting. Existing OpenSCAD files may need changes to run in KerfScript.
|
|
5
|
+
This guide covers the shared syntax and the differences that affect a port.
|
|
7
6
|
|
|
8
7
|
## The same
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
You can use familiar building blocks:
|
|
10
|
+
|
|
11
|
+
- Modules, functions, `for`, `if`, `let`, `each`, list comprehensions,
|
|
12
|
+
ranges and function literals.
|
|
12
13
|
- `children()`, `children(i)` and `$children`.
|
|
13
|
-
-
|
|
14
|
-
|
|
15
|
-
- 2D shapes: `square()`
|
|
16
|
-
|
|
17
|
-
-
|
|
18
|
-
- Combining: `union`, `difference`, `intersection`, `hull`, `offset(r)`,
|
|
19
|
-
`offset(delta, chamfer)`.
|
|
14
|
+
- Dynamically scoped `$` variables, plus `$fn`, `$fa` and `$fs` for curve
|
|
15
|
+
resolution.
|
|
16
|
+
- 2D shapes: `square()` or `rect()`, `circle()`, `polygon()` and `text()`.
|
|
17
|
+
- Transforms: `translate`, `rotate`, `scale`, `mirror` and `multmatrix`.
|
|
18
|
+
- Shape operations: `union`, `difference`, `intersection`, `hull` and `offset`.
|
|
20
19
|
- `echo()`, `assert()`, `use <...>` and `include <...>`.
|
|
21
|
-
- Customizer comments
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
- Customizer comments for ranges, choices, groups and captions.
|
|
21
|
+
|
|
22
|
+
See the [language reference](../LANGUAGE.md) for supported arguments.
|
|
24
23
|
|
|
25
24
|
## Different
|
|
26
25
|
|
|
27
|
-
|
|
|
28
|
-
| ----------- |
|
|
29
|
-
|
|
|
30
|
-
|
|
|
31
|
-
| Assignments |
|
|
32
|
-
|
|
|
33
|
-
| `color()` |
|
|
34
|
-
| Fonts | system fonts
|
|
35
|
-
| Libraries |
|
|
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 | 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
|
+
|
|
36
|
+
Assignment order is especially important when adapting a design. A value
|
|
37
|
+
assigned later in a KerfScript program does not change earlier geometry.
|
|
36
38
|
|
|
37
39
|
## Not in KerfScript
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
`linear_extrude`, `rotate_extrude
|
|
41
|
-
`color`, `import`, `surface`
|
|
42
|
-
|
|
41
|
+
KerfScript does not support `cube`, `sphere`, `cylinder`, `polyhedron`,
|
|
42
|
+
`linear_extrude`, `rotate_extrude` or `projection`. It also does not support
|
|
43
|
+
`minkowski`, `resize`, `color`, `import`, `surface` or `render`.
|
|
44
|
+
|
|
45
|
+
Calls to these modules produce an error. For a design based on an extruded
|
|
46
|
+
2D outline, start with that outline and remove the extrusion.
|
|
43
47
|
|
|
44
48
|
## Only in KerfScript
|
|
45
49
|
|
|
46
|
-
-
|
|
47
|
-
|
|
48
|
-
-
|
|
49
|
-
- Parts
|
|
50
|
-
|
|
51
|
-
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
- Shapes OpenSCAD lacks: `ellipse`, `regular_polygon`, `star`, rounded
|
|
56
|
-
`rect(r =)`.
|
|
57
|
-
- `text_width()` and `text_metrics()`, to size a part to its text.
|
|
50
|
+
- **Operations:** `cut()`, `score()`, `engrave()`, `guide()` and `layer()`.
|
|
51
|
+
- **Material settings:** `$kerf` for cut compensation and `$thickness` for
|
|
52
|
+
material-dependent joints.
|
|
53
|
+
- **Parts and layout:** `part()`, `material()`, quantities, `$sheet` and `$gap`.
|
|
54
|
+
- **Joinery:** `finger_rect`, `finger_holes`, `tslot` and `living_hinge`.
|
|
55
|
+
- **Paths:** `line`, `polyline`, `arc`, `path`, `stroke` and `outline`.
|
|
56
|
+
- **Additional shapes:** `ellipse`, `regular_polygon`, `star` and rounded
|
|
57
|
+
rectangles with `rect(r = ...)`.
|
|
58
|
+
- **Text measurement:** `text_width()` and `text_metrics()`.
|
|
58
59
|
|
|
59
60
|
## Porting a 2D design
|
|
60
61
|
|
|
61
|
-
1.
|
|
62
|
-
2.
|
|
63
|
-
3. Check assignments
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
1. Keep the 2D geometry and remove extrusion or other 3D operations.
|
|
63
|
+
2. Assign shapes to cut, score or engrave layers.
|
|
64
|
+
3. Check repeated assignments and put each value before the code that uses it.
|
|
65
|
+
4. Supply the fonts used by `text()`.
|
|
66
|
+
5. Set the measured material thickness and kerf. Use the joinery modules
|
|
67
|
+
where they suit the design.
|
|
68
|
+
|
|
69
|
+
Render the result and check the dimensions and layers before exporting.
|
|
70
|
+
The [layers](layers.md), [kerf](kerf.md) and
|
|
71
|
+
[parts and sheets](parts-and-sheets.md) guides cover those steps.
|
package/docs/parts-and-sheets.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# Parts and sheets
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Use parts to name the pieces in a design, set quantities and assign
|
|
4
|
+
materials. KerfScript lays them out on sheets, grouping parts that use the
|
|
5
|
+
same material and thickness.
|
|
5
6
|
|
|
6
7
|
## Parts
|
|
7
8
|
|
|
@@ -10,16 +11,27 @@ part("side", qty = 2) rect([100, 60]);
|
|
|
10
11
|
part("base") rect([100, 100]);
|
|
11
12
|
```
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
This creates two side panels and one base. Each `part()` has its own layers
|
|
15
|
+
and appears in the parts list with dimensions and cut length. The default
|
|
16
|
+
quantity is one.
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
Shapes outside a `part()` are collected into a part named `part`.
|
|
19
|
+
|
|
20
|
+
Transforms and operations such as `translate()`, `difference()` and
|
|
21
|
+
`offset()` can wrap a part and change all of it. Layer wrappers such as
|
|
22
|
+
`score()` and `engrave()` go inside the part instead, since a whole part on
|
|
23
|
+
the score layer would have nothing to cut:
|
|
24
|
+
|
|
25
|
+
```kerf
|
|
26
|
+
part("tag") {
|
|
27
|
+
rect([60, 30], r = 3);
|
|
28
|
+
score() translate([5, 5]) rect([50, 20]);
|
|
29
|
+
}
|
|
30
|
+
```
|
|
18
31
|
|
|
19
32
|
## Materials
|
|
20
33
|
|
|
21
|
-
|
|
22
|
-
`material()` sets all three for the parts inside it:
|
|
34
|
+
`material()` sets the thickness, kerf and material name for its parts:
|
|
23
35
|
|
|
24
36
|
```kerf
|
|
25
37
|
material(thickness = 3, kerf = 0.15, name = "plywood") {
|
|
@@ -31,38 +43,40 @@ material(thickness = 2, kerf = 0.1, name = "acrylic") {
|
|
|
31
43
|
}
|
|
32
44
|
```
|
|
33
45
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
46
|
+
The two plywood panels share a sheet. The acrylic window goes on a separate
|
|
47
|
+
sheet. Each part records the `$thickness`, `$kerf` and `$material` values in
|
|
48
|
+
effect where it is defined.
|
|
37
49
|
|
|
38
|
-
|
|
39
|
-
2. copies each part `qty` times,
|
|
40
|
-
3. turns a part 90° when that makes it fit,
|
|
41
|
-
4. packs them in rows onto sheets of `$sheet` (600 by 400 mm by default),
|
|
42
|
-
with `$gap` millimetres between parts and around the edge.
|
|
50
|
+
## Sheets
|
|
43
51
|
|
|
44
|
-
|
|
45
|
-
stay where your program put them.
|
|
52
|
+
Set the available sheet size and spacing in millimetres:
|
|
46
53
|
|
|
47
54
|
```kerf
|
|
48
55
|
$sheet = [300, 200];
|
|
49
56
|
$gap = 4;
|
|
50
57
|
```
|
|
51
58
|
|
|
52
|
-
|
|
59
|
+
With the default `$layout = "pack"`, KerfScript arranges copies of each part
|
|
60
|
+
in rows, leaving the specified gap. It rotates a part 90° if that lets it
|
|
61
|
+
fit the sheet. The default sheet is 600 × 400 mm, with a 3 mm gap between
|
|
62
|
+
parts and at the sheet edges.
|
|
53
63
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
64
|
+
A part larger than the sheet produces a warning. Set `$layout = "none"`
|
|
65
|
+
to keep the positions from your code instead of packing the parts.
|
|
66
|
+
|
|
67
|
+
The CLI `--margin` option and API `margin` option let you set the edge
|
|
68
|
+
spacing separately from the gap between parts.
|
|
69
|
+
|
|
70
|
+
## One file per sheet
|
|
58
71
|
|
|
59
|
-
|
|
72
|
+
A combined SVG stacks all sheets in one preview. For the material example
|
|
73
|
+
above, export the plywood and acrylic sheets separately and cut each with
|
|
74
|
+
the matching material settings.
|
|
60
75
|
|
|
61
|
-
- On the command line, `--split`
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
-
|
|
65
|
-
|
|
76
|
+
- On the command line, add `--split` to write `design-1.svg`,
|
|
77
|
+
`design-2.svg` and so on. `kerf check` lists each sheet's material and
|
|
78
|
+
thickness.
|
|
79
|
+
- In JavaScript, `result.sheets` provides the SVG, DXF, material and
|
|
80
|
+
thickness for each sheet.
|
|
66
81
|
|
|
67
|
-
|
|
68
|
-
sheet in your machine.
|
|
82
|
+
DXF exports contain one sheet per file.
|
package/docs/versions.md
CHANGED
|
@@ -1,43 +1,33 @@
|
|
|
1
1
|
# Versions
|
|
2
2
|
|
|
3
|
-
KerfScript
|
|
3
|
+
KerfScript 0.3.0 implements language version 0.1. The package version tracks
|
|
4
|
+
the software release; the language version tracks the syntax and behavior
|
|
5
|
+
of `.kerf` programs.
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
version.
|
|
9
|
-
- The **package version** (now 0.2.0) is the version of the interpreter, the
|
|
10
|
-
`kerf` command and the JavaScript API. It changes more often: bug fixes,
|
|
11
|
-
new output options and API additions do not change the language.
|
|
12
|
-
|
|
13
|
-
The site footer, `kerf --version` and the `VERSION` and `LANGUAGE_VERSION`
|
|
14
|
-
exports show both.
|
|
7
|
+
Package updates can include bug fixes, export options and JavaScript API
|
|
8
|
+
changes without changing the language version. Use `kerf --version` to see
|
|
9
|
+
both numbers, or read the `VERSION` and `LANGUAGE_VERSION` exports in JavaScript.
|
|
15
10
|
|
|
16
11
|
## Before 1.0
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
The language may change before 1.0. Release notes identify changes that
|
|
14
|
+
affect existing programs or their output, including geometry and text layout
|
|
15
|
+
fixes. Removing or renaming a language feature requires a new language version.
|
|
20
16
|
|
|
21
|
-
|
|
22
|
-
produces is listed in the changelog under the version that made it.
|
|
23
|
-
- **Files keep running where we can manage it.** A program that worked keeps
|
|
24
|
-
working, or stops with an error that says what to change. It does not
|
|
25
|
-
silently start cutting something different.
|
|
26
|
-
- **Geometry changes are called out.** If the same file starts producing
|
|
27
|
-
different geometry, for example after a packing or text layout fix, the
|
|
28
|
-
changelog says which designs are affected.
|
|
29
|
-
- **Breaking changes raise the language version.** Package releases within
|
|
30
|
-
one language version do not remove or rename anything in the language.
|
|
17
|
+
Check the changelog when upgrading a tool that renders saved designs.
|
|
31
18
|
|
|
32
19
|
## From 1.0
|
|
33
20
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
21
|
+
The compatibility policy for language version 1.x is to keep existing
|
|
22
|
+
programs working throughout that series. New features will be added without
|
|
23
|
+
changing existing syntax. Bug fixes that affect output will be listed in
|
|
24
|
+
the changelog; other breaking changes will require language version 2.0.
|
|
38
25
|
|
|
39
26
|
## Pinning a version
|
|
40
27
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
28
|
+
For repeatable exports, record the interpreter version, settings and font
|
|
29
|
+
files used with a design. Applications that store designs should retain
|
|
30
|
+
that information and compare the output before upgrading the interpreter.
|
|
31
|
+
|
|
32
|
+
Pin the npm package to an exact version when your application needs a fixed
|
|
33
|
+
renderer, for example `@mylasertools/kerfscript@0.3.0`.
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# WebAssembly
|
|
2
|
+
|
|
3
|
+
`kerfscript.wasm` runs KerfScript from any language that can host a
|
|
4
|
+
WebAssembly module: Python, Rust, Go, C#, Java, Ruby and others. It is a
|
|
5
|
+
WASI (preview 1) module built from the same source as the JavaScript package,
|
|
6
|
+
so it makes the same SVG and DXF files, byte for byte.
|
|
7
|
+
|
|
8
|
+
For JavaScript applications, use the [JavaScript API](javascript.md)
|
|
9
|
+
instead: it is smaller and faster.
|
|
10
|
+
|
|
11
|
+
## Getting the module
|
|
12
|
+
|
|
13
|
+
Download `kerfscript-<version>.wasm` from the
|
|
14
|
+
[releases](https://github.com/mylasertools/kerfscript/releases) page and save
|
|
15
|
+
it as `kerfscript.wasm`, or get `kerfscript-wasm-<version>.zip`, which has the
|
|
16
|
+
module with this guide and its licences. You can also build it from the
|
|
17
|
+
repository with [Javy](https://github.com/bytecodealliance/javy):
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm run build
|
|
21
|
+
npm run wasm # writes dist/kerfscript.wasm
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Set `JAVY` to the javy binary if it is not on the `PATH`.
|
|
25
|
+
|
|
26
|
+
## How it works
|
|
27
|
+
|
|
28
|
+
The module reads one JSON request from standard input, writes one JSON
|
|
29
|
+
response to standard output and exits. Start a fresh instance for each
|
|
30
|
+
request. From a shell, with [Wasmtime](https://wasmtime.dev):
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
echo '{"source": "rect([80, 50]);"}' | wasmtime run kerfscript.wasm
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Request
|
|
37
|
+
|
|
38
|
+
| Field | Value |
|
|
39
|
+
| ------------- | --------------------------------------------------------------------------- |
|
|
40
|
+
| `command` | `"render"` (default), `"params"`, `"version"` or `"licenses"` |
|
|
41
|
+
| `source` | The program, as a string |
|
|
42
|
+
| `params` | Parameter values keyed by name |
|
|
43
|
+
| `files` | Libraries for `include` and `use`, keyed by path: `{"lib/tab.kerf": "..."}` |
|
|
44
|
+
| `fonts` | Font files keyed by name, base64 encoded. `Atkinson` is built in |
|
|
45
|
+
| `defaultFont` | Name to use when `text()` does not specify a font |
|
|
46
|
+
| `kerf` | Kerf override for every part, in millimetres |
|
|
47
|
+
| `layout` | `"pack"` (default) or `"none"` |
|
|
48
|
+
| `sheet` | Sheet size `[width, height]` in millimetres |
|
|
49
|
+
| `gap` | Space between packed parts |
|
|
50
|
+
| `margin` | Space between the parts and the sheet edge |
|
|
51
|
+
| `guides` | `true` to include guide layer geometry |
|
|
52
|
+
|
|
53
|
+
These match the [render() options](javascript.md#options). A path in `files`
|
|
54
|
+
can leave out `.kerf`, as in the program.
|
|
55
|
+
|
|
56
|
+
### Response
|
|
57
|
+
|
|
58
|
+
Every response has `ok`. When it is `false`, `error` holds the message and
|
|
59
|
+
`echoes` holds what the program echoed before it stopped. The module never
|
|
60
|
+
exits with an error code for a bad program.
|
|
61
|
+
|
|
62
|
+
- `render`: `svg` (all sheets, for preview), `width`, `height`, `parts`,
|
|
63
|
+
`warnings`, `echoes` and `sheets`. Each sheet has `width`, `height`,
|
|
64
|
+
`material`, `thickness`, `svg` and `dxf`; write one file per sheet to cut.
|
|
65
|
+
- `params`: `parameters`, as from [`parameters()`](javascript.md).
|
|
66
|
+
- `version`: `version` (package) and `language`.
|
|
67
|
+
- `licenses`: `files`, the licence texts of the module and of everything
|
|
68
|
+
built into it, keyed by file name: `LICENSE`, `COMMERCIAL-LICENSE.md`,
|
|
69
|
+
`THIRD-PARTY-NOTICES.md`, `THIRD-PARTY-LICENSES.md` (the JavaScript engine
|
|
70
|
+
and its Rust crates) and `OFL.txt`. The release ZIP has the same files.
|
|
71
|
+
|
|
72
|
+
## Python
|
|
73
|
+
|
|
74
|
+
With the [`wasmtime`](https://pypi.org/project/wasmtime/) package:
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
import json, os, tempfile
|
|
78
|
+
from wasmtime import Engine, Linker, Module, Store, WasiConfig
|
|
79
|
+
|
|
80
|
+
engine = Engine()
|
|
81
|
+
module = Module.from_file(engine, "kerfscript.wasm")
|
|
82
|
+
linker = Linker(engine)
|
|
83
|
+
linker.define_wasi()
|
|
84
|
+
|
|
85
|
+
def kerf(request):
|
|
86
|
+
with tempfile.TemporaryDirectory() as d:
|
|
87
|
+
inp, out = os.path.join(d, "in.json"), os.path.join(d, "out.json")
|
|
88
|
+
with open(inp, "w", encoding="utf-8") as f:
|
|
89
|
+
json.dump(request, f)
|
|
90
|
+
wasi = WasiConfig()
|
|
91
|
+
wasi.stdin_file = inp
|
|
92
|
+
wasi.stdout_file = out
|
|
93
|
+
store = Store(engine)
|
|
94
|
+
store.set_wasi(wasi)
|
|
95
|
+
linker.instantiate(store, module).exports(store)["_start"](store)
|
|
96
|
+
with open(out, encoding="utf-8") as f:
|
|
97
|
+
return json.load(f)
|
|
98
|
+
|
|
99
|
+
result = kerf({"source": "w = 80; rect([w, 50]);", "params": {"w": 120}})
|
|
100
|
+
for i, sheet in enumerate(result["sheets"]):
|
|
101
|
+
with open(f"sheet-{i + 1}.svg", "w", encoding="utf-8", newline="") as f:
|
|
102
|
+
f.write(sheet["svg"])
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Compile the module once and reuse it; each request only needs a new `Store`.
|
|
106
|
+
|
|
107
|
+
## Node.js
|
|
108
|
+
|
|
109
|
+
The JavaScript package is the better fit in Node.js, but the module also runs
|
|
110
|
+
under `node:wasi`, which is how the test suite checks it:
|
|
111
|
+
|
|
112
|
+
```js
|
|
113
|
+
import { closeSync, openSync, readFileSync, writeFileSync } from 'node:fs';
|
|
114
|
+
import { WASI } from 'node:wasi';
|
|
115
|
+
|
|
116
|
+
const module = await WebAssembly.compile(readFileSync('kerfscript.wasm'));
|
|
117
|
+
writeFileSync('in.json', JSON.stringify({ source: 'rect([80, 50]);' }));
|
|
118
|
+
const stdin = openSync('in.json', 'r');
|
|
119
|
+
const stdout = openSync('out.json', 'w');
|
|
120
|
+
const wasi = new WASI({ version: 'preview1', stdin, stdout, returnOnExit: true });
|
|
121
|
+
wasi.start(await WebAssembly.instantiate(module, wasi.getImportObject()));
|
|
122
|
+
closeSync(stdin);
|
|
123
|
+
closeSync(stdout);
|
|
124
|
+
console.log(JSON.parse(readFileSync('out.json', 'utf8')).svg);
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Performance
|
|
128
|
+
|
|
129
|
+
The module carries its own JavaScript engine (QuickJS), so it is about 2 MB
|
|
130
|
+
and renders roughly three to five times slower than Node.js. The example
|
|
131
|
+
designs take well under a second.
|
package/fonts/OFL.txt
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
Copyright 2020 Braille Institute of America, Inc.
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
http://scripts.sil.org/OFL
|
|
6
|
+
|
|
7
|
+
-----------------------------------------------------------
|
|
8
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
9
|
+
-----------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
PREAMBLE
|
|
12
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
13
|
+
development of collaborative font projects, to support the font creation
|
|
14
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
15
|
+
open framework in which fonts may be shared and improved in partnership
|
|
16
|
+
with others.
|
|
17
|
+
|
|
18
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
19
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
20
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
21
|
+
redistributed and/or sold with any software provided that any reserved
|
|
22
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
23
|
+
however, cannot be released under any other type of license. The
|
|
24
|
+
requirement for fonts to remain under this license does not apply
|
|
25
|
+
to any document created using the fonts or their derivatives.
|
|
26
|
+
|
|
27
|
+
DEFINITIONS
|
|
28
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
29
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
30
|
+
include source files, build scripts and documentation.
|
|
31
|
+
|
|
32
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
33
|
+
copyright statement(s).
|
|
34
|
+
|
|
35
|
+
"Original Version" refers to the collection of Font Software components as
|
|
36
|
+
distributed by the Copyright Holder(s).
|
|
37
|
+
|
|
38
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
39
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
40
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
41
|
+
new environment.
|
|
42
|
+
|
|
43
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
44
|
+
writer or other person who contributed to the Font Software.
|
|
45
|
+
|
|
46
|
+
PERMISSION & CONDITIONS
|
|
47
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
48
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
49
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
50
|
+
Software, subject to the following conditions:
|
|
51
|
+
|
|
52
|
+
1) Neither the Font Software nor any of its individual components,
|
|
53
|
+
in Original or Modified Versions, may be sold by itself.
|
|
54
|
+
|
|
55
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
56
|
+
redistributed and/or sold with any software, provided that each copy
|
|
57
|
+
contains the above copyright notice and this license. These can be
|
|
58
|
+
included either as stand-alone text files, human-readable headers or
|
|
59
|
+
in the appropriate machine-readable metadata fields within text or
|
|
60
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
61
|
+
|
|
62
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
63
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
64
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
65
|
+
presented to the users.
|
|
66
|
+
|
|
67
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
68
|
+
Software shall not be used to promote, endorse or advertise any
|
|
69
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
70
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
71
|
+
permission.
|
|
72
|
+
|
|
73
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
74
|
+
must be distributed entirely under this license, and must not be
|
|
75
|
+
distributed under any other license. The requirement for fonts to
|
|
76
|
+
remain under this license does not apply to any document created
|
|
77
|
+
using the Font Software.
|
|
78
|
+
|
|
79
|
+
TERMINATION
|
|
80
|
+
This license becomes null and void if any of the above conditions are
|
|
81
|
+
not met.
|
|
82
|
+
|
|
83
|
+
DISCLAIMER
|
|
84
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
85
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
86
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
87
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
88
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
89
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
90
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
91
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
92
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mylasertools/kerfscript",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "KerfScript: a programming language for laser cutting. Write parametric 2D parts with cut, score and engrave layers, kerf compensation and joinery, and export SVG or DXF.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
7
7
|
"author": "MyLaserTools",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/mylasertools
|
|
10
|
+
"url": "git+https://github.com/mylasertools/kerfscript.git"
|
|
11
11
|
},
|
|
12
|
-
"bugs": "https://github.com/mylasertools
|
|
12
|
+
"bugs": "https://github.com/mylasertools/kerfscript/issues",
|
|
13
13
|
"keywords": [
|
|
14
14
|
"kerfscript",
|
|
15
15
|
"laser-cutting",
|
|
@@ -45,12 +45,14 @@
|
|
|
45
45
|
},
|
|
46
46
|
"files": [
|
|
47
47
|
"dist",
|
|
48
|
+
"!dist/kerfscript.wasm",
|
|
48
49
|
"README.md",
|
|
49
50
|
"docs",
|
|
50
51
|
"LANGUAGE.md",
|
|
51
52
|
"LICENSE",
|
|
52
53
|
"COMMERCIAL-LICENSE.md",
|
|
53
54
|
"THIRD-PARTY-NOTICES.md",
|
|
55
|
+
"fonts/OFL.txt",
|
|
54
56
|
"CHANGELOG.md",
|
|
55
57
|
"TRADEMARKS.md",
|
|
56
58
|
"CLA.md"
|
|
@@ -70,9 +72,11 @@
|
|
|
70
72
|
"site": "npm run build && npm --prefix site run build",
|
|
71
73
|
"site:serve": "npm --prefix site run preview",
|
|
72
74
|
"prepack": "npm run check",
|
|
73
|
-
"format": "prettier --write .",
|
|
74
|
-
"format:check": "prettier --check .",
|
|
75
|
-
"compat": "node scripts/compat.mjs"
|
|
75
|
+
"format": "prettier --write . --ignore-path .gitignore --ignore-path .prettierignore --ignore-path .git/info/exclude",
|
|
76
|
+
"format:check": "prettier --check . --ignore-path .gitignore --ignore-path .prettierignore --ignore-path .git/info/exclude",
|
|
77
|
+
"compat": "node scripts/compat.mjs",
|
|
78
|
+
"wasm": "node scripts/wasm.mjs",
|
|
79
|
+
"readme-images": "npm run build && cd site && node ../scripts/readme-images.mjs"
|
|
76
80
|
},
|
|
77
81
|
"devDependencies": {
|
|
78
82
|
"@types/node": "20.19.43",
|