@mylasertools/kerfscript 0.2.1 → 0.4.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 +99 -2
- package/LANGUAGE.md +102 -66
- package/README.md +21 -10
- package/THIRD-PARTY-NOTICES.md +13 -4
- package/dist/assembly.d.cts +20 -0
- package/dist/assembly.d.ts +20 -0
- package/dist/cli.js +923 -288
- package/dist/evaluator.d.cts +6 -0
- package/dist/evaluator.d.ts +6 -0
- package/dist/export/dxf.d.cts +1 -1
- package/dist/export/dxf.d.ts +1 -1
- 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/geometry.d.cts +2 -0
- package/dist/geometry.d.ts +2 -0
- package/dist/index.cjs +24 -19
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +24 -19
- 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 -1
- package/dist/render.d.ts +3 -1
- 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 +46 -20
- package/docs/compatibility.md +3 -3
- package/docs/customizer.md +9 -9
- package/docs/desktop.md +96 -0
- package/docs/javascript.md +30 -27
- package/docs/layers.md +6 -6
- package/docs/openscad.md +9 -9
- package/docs/parts-and-sheets.md +32 -0
- package/docs/versions.md +2 -2
- package/docs/webassembly.md +133 -0
- package/fonts/OFL.txt +92 -0
- package/package.json +6 -3
|
@@ -0,0 +1,133 @@
|
|
|
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
|
+
`assembly`, `warnings`, `echoes` and `sheets`. `assembly` is the same as
|
|
64
|
+
from [`render()`](javascript.md): one entry per copy of a part, with its
|
|
65
|
+
outline, thickness and placement. Each sheet has `width`, `height`,
|
|
66
|
+
`material`, `thickness`, `svg` and `dxf`; write one file per sheet to cut.
|
|
67
|
+
- `params`: `parameters`, as from [`parameters()`](javascript.md).
|
|
68
|
+
- `version`: `version` (package) and `language`.
|
|
69
|
+
- `licenses`: `files`, the licence texts of the module and of everything
|
|
70
|
+
built into it, keyed by file name: `LICENSE`, `COMMERCIAL-LICENSE.md`,
|
|
71
|
+
`THIRD-PARTY-NOTICES.md`, `THIRD-PARTY-LICENSES.md` (the JavaScript engine
|
|
72
|
+
and its Rust crates) and `OFL.txt`. The release ZIP has the same files.
|
|
73
|
+
|
|
74
|
+
## Python
|
|
75
|
+
|
|
76
|
+
With the [`wasmtime`](https://pypi.org/project/wasmtime/) package:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
import json, os, tempfile
|
|
80
|
+
from wasmtime import Engine, Linker, Module, Store, WasiConfig
|
|
81
|
+
|
|
82
|
+
engine = Engine()
|
|
83
|
+
module = Module.from_file(engine, "kerfscript.wasm")
|
|
84
|
+
linker = Linker(engine)
|
|
85
|
+
linker.define_wasi()
|
|
86
|
+
|
|
87
|
+
def kerf(request):
|
|
88
|
+
with tempfile.TemporaryDirectory() as d:
|
|
89
|
+
inp, out = os.path.join(d, "in.json"), os.path.join(d, "out.json")
|
|
90
|
+
with open(inp, "w", encoding="utf-8") as f:
|
|
91
|
+
json.dump(request, f)
|
|
92
|
+
wasi = WasiConfig()
|
|
93
|
+
wasi.stdin_file = inp
|
|
94
|
+
wasi.stdout_file = out
|
|
95
|
+
store = Store(engine)
|
|
96
|
+
store.set_wasi(wasi)
|
|
97
|
+
linker.instantiate(store, module).exports(store)["_start"](store)
|
|
98
|
+
with open(out, encoding="utf-8") as f:
|
|
99
|
+
return json.load(f)
|
|
100
|
+
|
|
101
|
+
result = kerf({"source": "w = 80; rect([w, 50]);", "params": {"w": 120}})
|
|
102
|
+
for i, sheet in enumerate(result["sheets"]):
|
|
103
|
+
with open(f"sheet-{i + 1}.svg", "w", encoding="utf-8", newline="") as f:
|
|
104
|
+
f.write(sheet["svg"])
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Compile the module once and reuse it; each request only needs a new `Store`.
|
|
108
|
+
|
|
109
|
+
## Node.js
|
|
110
|
+
|
|
111
|
+
The JavaScript package is the better fit in Node.js, but the module also runs
|
|
112
|
+
under `node:wasi`, which is how the test suite checks it:
|
|
113
|
+
|
|
114
|
+
```js
|
|
115
|
+
import { closeSync, openSync, readFileSync, writeFileSync } from 'node:fs';
|
|
116
|
+
import { WASI } from 'node:wasi';
|
|
117
|
+
|
|
118
|
+
const module = await WebAssembly.compile(readFileSync('kerfscript.wasm'));
|
|
119
|
+
writeFileSync('in.json', JSON.stringify({ source: 'rect([80, 50]);' }));
|
|
120
|
+
const stdin = openSync('in.json', 'r');
|
|
121
|
+
const stdout = openSync('out.json', 'w');
|
|
122
|
+
const wasi = new WASI({ version: 'preview1', stdin, stdout, returnOnExit: true });
|
|
123
|
+
wasi.start(await WebAssembly.instantiate(module, wasi.getImportObject()));
|
|
124
|
+
closeSync(stdin);
|
|
125
|
+
closeSync(stdout);
|
|
126
|
+
console.log(JSON.parse(readFileSync('out.json', 'utf8')).svg);
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Performance
|
|
130
|
+
|
|
131
|
+
The module carries its own JavaScript engine (QuickJS), so it is about 2 MB
|
|
132
|
+
and renders roughly three to five times slower than Node.js. The example
|
|
133
|
+
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mylasertools/kerfscript",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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",
|
|
@@ -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,10 @@
|
|
|
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
|
+
"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",
|
|
75
77
|
"compat": "node scripts/compat.mjs",
|
|
78
|
+
"wasm": "node scripts/wasm.mjs",
|
|
76
79
|
"readme-images": "npm run build && cd site && node ../scripts/readme-images.mjs"
|
|
77
80
|
},
|
|
78
81
|
"devDependencies": {
|