@mylasertools/kerfscript 0.3.0 → 0.5.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 (62) hide show
  1. package/CHANGELOG.md +114 -0
  2. package/LANGUAGE.md +43 -23
  3. package/README.md +65 -2
  4. package/dist/assembly.d.cts +20 -0
  5. package/dist/assembly.d.ts +20 -0
  6. package/dist/ast.d.cts +13 -1
  7. package/dist/ast.d.ts +13 -1
  8. package/dist/cli.js +5037 -1359
  9. package/dist/diagnostics.d.cts +6 -0
  10. package/dist/diagnostics.d.ts +6 -0
  11. package/dist/evaluator.d.cts +15 -0
  12. package/dist/evaluator.d.ts +15 -0
  13. package/dist/format.d.cts +4 -0
  14. package/dist/format.d.ts +4 -0
  15. package/dist/geometry.d.cts +2 -0
  16. package/dist/geometry.d.ts +2 -0
  17. package/dist/highlight.cjs +151 -0
  18. package/dist/highlight.d.cts +13 -0
  19. package/dist/highlight.d.ts +13 -0
  20. package/dist/highlight.js +131 -0
  21. package/dist/index.cjs +369 -20
  22. package/dist/index.d.cts +6 -3
  23. package/dist/index.d.ts +6 -3
  24. package/dist/index.js +369 -20
  25. package/dist/language.cjs +417 -0
  26. package/dist/language.d.cts +143 -0
  27. package/dist/language.d.ts +143 -0
  28. package/dist/language.js +417 -0
  29. package/dist/lexer.d.cts +17 -0
  30. package/dist/lexer.d.ts +17 -0
  31. package/dist/libraries.cjs +380 -0
  32. package/dist/libraries.d.cts +112 -0
  33. package/dist/libraries.d.ts +112 -0
  34. package/dist/libraries.js +380 -0
  35. package/dist/lsp.d.cts +12 -0
  36. package/dist/lsp.d.ts +12 -0
  37. package/dist/render.d.cts +2 -0
  38. package/dist/render.d.ts +2 -0
  39. package/dist/signatures.cjs +675 -0
  40. package/dist/signatures.d.cts +20 -0
  41. package/dist/signatures.d.ts +20 -0
  42. package/dist/signatures.js +655 -0
  43. package/docs/cli.md +45 -2
  44. package/docs/desktop.md +5 -0
  45. package/docs/editors.md +121 -0
  46. package/docs/javascript.md +157 -20
  47. package/docs/kerf.md +10 -0
  48. package/docs/library/box.svg +11 -0
  49. package/docs/library/calibration.svg +11 -0
  50. package/docs/library/dividers.svg +11 -0
  51. package/docs/library/enclosure.svg +11 -0
  52. package/docs/library/hanging.svg +11 -0
  53. package/docs/library/hinge.svg +11 -0
  54. package/docs/library/tabs.svg +11 -0
  55. package/docs/library.md +339 -0
  56. package/docs/openscad.md +1 -1
  57. package/docs/parts-and-sheets.md +32 -0
  58. package/docs/shared-libraries.md +229 -0
  59. package/docs/specification.md +529 -0
  60. package/docs/versions.md +2 -2
  61. package/docs/webassembly.md +3 -1
  62. package/package.json +51 -4
@@ -0,0 +1,6 @@
1
+ export interface FormatOptions {
2
+ file?: string;
3
+ resolve?: (path: string) => string | undefined;
4
+ }
5
+ export declare const markLength: (line: string, col: number) => number;
6
+ export declare function formatError(error: unknown, source: string, options?: FormatOptions): string;
@@ -0,0 +1,6 @@
1
+ export interface FormatOptions {
2
+ file?: string;
3
+ resolve?: (path: string) => string | undefined;
4
+ }
5
+ export declare const markLength: (line: string, col: number) => number;
6
+ export declare function formatError(error: unknown, source: string, options?: FormatOptions): string;
@@ -25,6 +25,7 @@ export interface Limits {
25
25
  maxPoints: number;
26
26
  maxOutputPoints: number;
27
27
  maxSheets: number;
28
+ maxCollisionPairs: number;
28
29
  }
29
30
  export declare const DEFAULT_LIMITS: Limits;
30
31
  interface ModDef {
@@ -56,12 +57,18 @@ declare class Env {
56
57
  fn(name: string): FnDef | undefined;
57
58
  mod(name: string): ModDef | undefined;
58
59
  childCtx(): ChildCtx | undefined;
60
+ names(kind: 'vars' | 'fns' | 'mods'): string[];
59
61
  }
60
62
  interface Args {
61
63
  pos: Value[];
62
64
  named: Map<string, Value>;
65
+ all: {
66
+ name: string | null;
67
+ value: Value;
68
+ }[];
63
69
  at: Pos;
64
70
  }
71
+ export declare function didYouMean(name: string, known: Iterable<string>): string;
65
72
  export interface EvalResult {
66
73
  shape: Shape;
67
74
  globals: Env;
@@ -89,6 +96,9 @@ export declare class Evaluator {
89
96
  private tick;
90
97
  private load;
91
98
  private hoist;
99
+ private using;
100
+ private including;
101
+ private enter;
92
102
  private included;
93
103
  private assign;
94
104
  block(stmts: Stmt[], env: Env, top?: boolean): Shape;
@@ -98,11 +108,14 @@ export declare class Evaluator {
98
108
  private loop;
99
109
  private evalArgs;
100
110
  private bindParams;
111
+ private checkArgs;
112
+ private checkCount;
101
113
  private unknownArg;
102
114
  private warn;
103
115
  private callModule;
104
116
  private childStmts;
105
117
  callFunction(f: FnDef | Closure, args: Args, caller: Env, name: string): Value;
118
+ private inCall;
106
119
  expr(x: Expr, env: Env): Value;
107
120
  private listItem;
108
121
  private grow;
@@ -116,6 +129,8 @@ export declare class Evaluator {
116
129
  private arg;
117
130
  private num;
118
131
  private vec2;
132
+ private vec3;
133
+ private placements;
119
134
  private points;
120
135
  private dyn;
121
136
  private spend;
@@ -25,6 +25,7 @@ export interface Limits {
25
25
  maxPoints: number;
26
26
  maxOutputPoints: number;
27
27
  maxSheets: number;
28
+ maxCollisionPairs: number;
28
29
  }
29
30
  export declare const DEFAULT_LIMITS: Limits;
30
31
  interface ModDef {
@@ -56,12 +57,18 @@ declare class Env {
56
57
  fn(name: string): FnDef | undefined;
57
58
  mod(name: string): ModDef | undefined;
58
59
  childCtx(): ChildCtx | undefined;
60
+ names(kind: 'vars' | 'fns' | 'mods'): string[];
59
61
  }
60
62
  interface Args {
61
63
  pos: Value[];
62
64
  named: Map<string, Value>;
65
+ all: {
66
+ name: string | null;
67
+ value: Value;
68
+ }[];
63
69
  at: Pos;
64
70
  }
71
+ export declare function didYouMean(name: string, known: Iterable<string>): string;
65
72
  export interface EvalResult {
66
73
  shape: Shape;
67
74
  globals: Env;
@@ -89,6 +96,9 @@ export declare class Evaluator {
89
96
  private tick;
90
97
  private load;
91
98
  private hoist;
99
+ private using;
100
+ private including;
101
+ private enter;
92
102
  private included;
93
103
  private assign;
94
104
  block(stmts: Stmt[], env: Env, top?: boolean): Shape;
@@ -98,11 +108,14 @@ export declare class Evaluator {
98
108
  private loop;
99
109
  private evalArgs;
100
110
  private bindParams;
111
+ private checkArgs;
112
+ private checkCount;
101
113
  private unknownArg;
102
114
  private warn;
103
115
  private callModule;
104
116
  private childStmts;
105
117
  callFunction(f: FnDef | Closure, args: Args, caller: Env, name: string): Value;
118
+ private inCall;
106
119
  expr(x: Expr, env: Env): Value;
107
120
  private listItem;
108
121
  private grow;
@@ -116,6 +129,8 @@ export declare class Evaluator {
116
129
  private arg;
117
130
  private num;
118
131
  private vec2;
132
+ private vec3;
133
+ private placements;
119
134
  private points;
120
135
  private dyn;
121
136
  private spend;
@@ -0,0 +1,4 @@
1
+ export interface FormatOptions {
2
+ indent?: number;
3
+ }
4
+ export declare function format(source: string, options?: FormatOptions): string;
@@ -0,0 +1,4 @@
1
+ export interface FormatOptions {
2
+ indent?: number;
3
+ }
4
+ export declare function format(source: string, options?: FormatOptions): string;
@@ -1,3 +1,4 @@
1
+ import type { Placement } from './assembly.cjs';
1
2
  export type Pt = [number, number];
2
3
  export type Poly = Pt[];
3
4
  export type Matrix = [number, number, number, number, number, number];
@@ -12,6 +13,7 @@ export interface PartShape {
12
13
  thickness: number;
13
14
  kerf: number;
14
15
  material: string;
16
+ placements?: Placement[];
15
17
  }
16
18
  export interface Shape {
17
19
  layers: Map<string, Layer>;
@@ -1,3 +1,4 @@
1
+ import type { Placement } from './assembly.js';
1
2
  export type Pt = [number, number];
2
3
  export type Poly = Pt[];
3
4
  export type Matrix = [number, number, number, number, number, number];
@@ -12,6 +13,7 @@ export interface PartShape {
12
13
  thickness: number;
13
14
  kerf: number;
14
15
  material: string;
16
+ placements?: Placement[];
15
17
  }
16
18
  export interface Shape {
17
19
  layers: Map<string, Layer>;
@@ -0,0 +1,151 @@
1
+ /*! @mylasertools/kerfscript/highlight | (c) MyLaserTools | AGPL-3.0-only or commercial licence */
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/highlight.ts
22
+ var highlight_exports = {};
23
+ __export(highlight_exports, {
24
+ BUILTINS: () => BUILTINS,
25
+ LAYERS: () => LAYERS,
26
+ highlight: () => highlight,
27
+ highlightLine: () => highlightLine,
28
+ highlightLines: () => highlightLines
29
+ });
30
+ module.exports = __toCommonJS(highlight_exports);
31
+ var KEYWORDS = /* @__PURE__ */ new Set([
32
+ "module",
33
+ "function",
34
+ "if",
35
+ "else",
36
+ "for",
37
+ "let",
38
+ "each",
39
+ "use",
40
+ "include"
41
+ ]);
42
+ var CONSTANTS = /* @__PURE__ */ new Set(["true", "false", "undef", "PI"]);
43
+ var LAYERS = /* @__PURE__ */ new Set(["cut", "score", "engrave", "guide", "layer"]);
44
+ var BUILTINS = new Set(
45
+ "rect square circle ellipse regular_polygon star polygon path line polyline arc text translate rotate scale mirror multmatrix union group difference intersection hull offset stroke outline part material children echo assert finger_rect finger_holes tslot living_hinge box divider kerf_gauge slot_gauge joint_test slotted_divider grid_dividers enclosure enclosure_cutouts vents keyhole keyholes hanging_hole hanging_loop flex_rect flex_box flex_panel tabs slots tab_rect abs sign floor ceil round sqrt pow exp ln log sin cos tan asin acos atan atan2 min max clamp lerp norm cross len concat reverse sum slice str chr ord upper lower split join search contains lookup is_num is_string is_bool is_list is_undef is_function type_of rands text_width text_metrics finger_count".split(" ")
46
+ );
47
+ var NUMBER = /(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/y;
48
+ var WORD = /\$?[A-Za-z_][A-Za-z0-9_]*/y;
49
+ var CALL = /\s*\(/y;
50
+ var PATH = /<[^>]*>?/y;
51
+ var SECTION = /\/\*\s*\[[^\]]*\]\s*\*\//y;
52
+ var CONTROL = /\/\/\s*\[[^\]]*\]\s*$/y;
53
+ var MODIFIER = /[*#%](?=\s*[A-Za-z_$])/y;
54
+ var at = (re, line, i) => {
55
+ re.lastIndex = i;
56
+ return re.exec(line)?.[0] ?? null;
57
+ };
58
+ function highlightLine(line, state) {
59
+ const out = [];
60
+ const push = (kind, text) => {
61
+ const last = out[out.length - 1];
62
+ if (last && last.kind === kind) last.text += text;
63
+ else out.push({ kind, text });
64
+ };
65
+ let i = 0;
66
+ let prev = "";
67
+ let start = true;
68
+ while (i < line.length) {
69
+ const c = line[i];
70
+ let m;
71
+ if (state.inBlock) {
72
+ const end = line.indexOf("*/", i);
73
+ const stop = end < 0 ? line.length : end + 2;
74
+ push("comment", line.slice(i, stop));
75
+ if (end >= 0) state.inBlock = false;
76
+ i = stop;
77
+ } else if (m = at(SECTION, line, i)) {
78
+ push("section", m);
79
+ i += m.length;
80
+ } else if (m = at(CONTROL, line, i)) {
81
+ const open = m.indexOf("[");
82
+ push("comment", m.slice(0, open));
83
+ push("control", m.slice(open).trimEnd());
84
+ push("plain", m.slice(open + m.slice(open).trimEnd().length));
85
+ i += m.length;
86
+ } else if (line.startsWith("//", i)) {
87
+ push("comment", line.slice(i));
88
+ i = line.length;
89
+ } else if (line.startsWith("/*", i)) {
90
+ state.inBlock = true;
91
+ push("comment", "/*");
92
+ i += 2;
93
+ } else if (c === '"') {
94
+ let j = i + 1;
95
+ while (j < line.length && line[j] !== '"') j += line[j] === "\\" ? 2 : 1;
96
+ push("string", line.slice(i, j + 1));
97
+ i = j + 1;
98
+ prev = "";
99
+ start = false;
100
+ } else if ((prev === "use" || prev === "include") && c === "<" && (m = at(PATH, line, i))) {
101
+ push("string", m);
102
+ i += m.length;
103
+ prev = "";
104
+ } else if (start && (m = at(MODIFIER, line, i))) {
105
+ push("modifier", m);
106
+ i += m.length;
107
+ } else if (c === "#") {
108
+ push("modifier", c);
109
+ i++;
110
+ } else if (m = at(NUMBER, line, i)) {
111
+ push("number", m);
112
+ i += m.length;
113
+ prev = "";
114
+ start = false;
115
+ } else if (m = at(WORD, line, i)) {
116
+ const call = at(CALL, line, i + m.length) !== null;
117
+ if (m[0] === "$") push("special", m);
118
+ else if ((prev === "module" || prev === "function") && !KEYWORDS.has(m))
119
+ push("definition", m);
120
+ else if (KEYWORDS.has(m)) push("keyword", m);
121
+ else if (CONSTANTS.has(m)) push("constant", m);
122
+ else if (call && LAYERS.has(m)) push("layer", m);
123
+ else if (call && BUILTINS.has(m)) push("builtin", m);
124
+ else if (call) push("call", m);
125
+ else push("plain", m);
126
+ prev = m;
127
+ i += m.length;
128
+ start = false;
129
+ } else {
130
+ push("plain", c);
131
+ if (!/\s/.test(c)) {
132
+ prev = "";
133
+ start = c === ";" || c === "{" || c === "}";
134
+ }
135
+ i++;
136
+ }
137
+ }
138
+ return out;
139
+ }
140
+ function highlightLines(src) {
141
+ const state = { inBlock: false };
142
+ return src.split("\n").map((line) => highlightLine(line, state));
143
+ }
144
+ var esc = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
145
+ function highlight(src) {
146
+ return highlightLines(src).map(
147
+ (tokens) => tokens.map(
148
+ (t) => t.kind === "plain" ? esc(t.text) : `<span class="t-${t.kind}">${esc(t.text)}</span>`
149
+ ).join("")
150
+ ).join("\n");
151
+ }
@@ -0,0 +1,13 @@
1
+ export type HighlightKind = 'comment' | 'section' | 'control' | 'string' | 'number' | 'keyword' | 'constant' | 'definition' | 'builtin' | 'layer' | 'call' | 'special' | 'modifier' | 'plain';
2
+ export interface HighlightToken {
3
+ kind: HighlightKind;
4
+ text: string;
5
+ }
6
+ export interface HighlightState {
7
+ inBlock: boolean;
8
+ }
9
+ export declare const LAYERS: Set<string>;
10
+ export declare const BUILTINS: Set<string>;
11
+ export declare function highlightLine(line: string, state: HighlightState): HighlightToken[];
12
+ export declare function highlightLines(src: string): HighlightToken[][];
13
+ export declare function highlight(src: string): string;
@@ -0,0 +1,13 @@
1
+ export type HighlightKind = 'comment' | 'section' | 'control' | 'string' | 'number' | 'keyword' | 'constant' | 'definition' | 'builtin' | 'layer' | 'call' | 'special' | 'modifier' | 'plain';
2
+ export interface HighlightToken {
3
+ kind: HighlightKind;
4
+ text: string;
5
+ }
6
+ export interface HighlightState {
7
+ inBlock: boolean;
8
+ }
9
+ export declare const LAYERS: Set<string>;
10
+ export declare const BUILTINS: Set<string>;
11
+ export declare function highlightLine(line: string, state: HighlightState): HighlightToken[];
12
+ export declare function highlightLines(src: string): HighlightToken[][];
13
+ export declare function highlight(src: string): string;
@@ -0,0 +1,131 @@
1
+ /*! @mylasertools/kerfscript/highlight | (c) MyLaserTools | AGPL-3.0-only or commercial licence */
2
+
3
+ // src/highlight.ts
4
+ var KEYWORDS = /* @__PURE__ */ new Set([
5
+ "module",
6
+ "function",
7
+ "if",
8
+ "else",
9
+ "for",
10
+ "let",
11
+ "each",
12
+ "use",
13
+ "include"
14
+ ]);
15
+ var CONSTANTS = /* @__PURE__ */ new Set(["true", "false", "undef", "PI"]);
16
+ var LAYERS = /* @__PURE__ */ new Set(["cut", "score", "engrave", "guide", "layer"]);
17
+ var BUILTINS = new Set(
18
+ "rect square circle ellipse regular_polygon star polygon path line polyline arc text translate rotate scale mirror multmatrix union group difference intersection hull offset stroke outline part material children echo assert finger_rect finger_holes tslot living_hinge box divider kerf_gauge slot_gauge joint_test slotted_divider grid_dividers enclosure enclosure_cutouts vents keyhole keyholes hanging_hole hanging_loop flex_rect flex_box flex_panel tabs slots tab_rect abs sign floor ceil round sqrt pow exp ln log sin cos tan asin acos atan atan2 min max clamp lerp norm cross len concat reverse sum slice str chr ord upper lower split join search contains lookup is_num is_string is_bool is_list is_undef is_function type_of rands text_width text_metrics finger_count".split(" ")
19
+ );
20
+ var NUMBER = /(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/y;
21
+ var WORD = /\$?[A-Za-z_][A-Za-z0-9_]*/y;
22
+ var CALL = /\s*\(/y;
23
+ var PATH = /<[^>]*>?/y;
24
+ var SECTION = /\/\*\s*\[[^\]]*\]\s*\*\//y;
25
+ var CONTROL = /\/\/\s*\[[^\]]*\]\s*$/y;
26
+ var MODIFIER = /[*#%](?=\s*[A-Za-z_$])/y;
27
+ var at = (re, line, i) => {
28
+ re.lastIndex = i;
29
+ return re.exec(line)?.[0] ?? null;
30
+ };
31
+ function highlightLine(line, state) {
32
+ const out = [];
33
+ const push = (kind, text) => {
34
+ const last = out[out.length - 1];
35
+ if (last && last.kind === kind) last.text += text;
36
+ else out.push({ kind, text });
37
+ };
38
+ let i = 0;
39
+ let prev = "";
40
+ let start = true;
41
+ while (i < line.length) {
42
+ const c = line[i];
43
+ let m;
44
+ if (state.inBlock) {
45
+ const end = line.indexOf("*/", i);
46
+ const stop = end < 0 ? line.length : end + 2;
47
+ push("comment", line.slice(i, stop));
48
+ if (end >= 0) state.inBlock = false;
49
+ i = stop;
50
+ } else if (m = at(SECTION, line, i)) {
51
+ push("section", m);
52
+ i += m.length;
53
+ } else if (m = at(CONTROL, line, i)) {
54
+ const open = m.indexOf("[");
55
+ push("comment", m.slice(0, open));
56
+ push("control", m.slice(open).trimEnd());
57
+ push("plain", m.slice(open + m.slice(open).trimEnd().length));
58
+ i += m.length;
59
+ } else if (line.startsWith("//", i)) {
60
+ push("comment", line.slice(i));
61
+ i = line.length;
62
+ } else if (line.startsWith("/*", i)) {
63
+ state.inBlock = true;
64
+ push("comment", "/*");
65
+ i += 2;
66
+ } else if (c === '"') {
67
+ let j = i + 1;
68
+ while (j < line.length && line[j] !== '"') j += line[j] === "\\" ? 2 : 1;
69
+ push("string", line.slice(i, j + 1));
70
+ i = j + 1;
71
+ prev = "";
72
+ start = false;
73
+ } else if ((prev === "use" || prev === "include") && c === "<" && (m = at(PATH, line, i))) {
74
+ push("string", m);
75
+ i += m.length;
76
+ prev = "";
77
+ } else if (start && (m = at(MODIFIER, line, i))) {
78
+ push("modifier", m);
79
+ i += m.length;
80
+ } else if (c === "#") {
81
+ push("modifier", c);
82
+ i++;
83
+ } else if (m = at(NUMBER, line, i)) {
84
+ push("number", m);
85
+ i += m.length;
86
+ prev = "";
87
+ start = false;
88
+ } else if (m = at(WORD, line, i)) {
89
+ const call = at(CALL, line, i + m.length) !== null;
90
+ if (m[0] === "$") push("special", m);
91
+ else if ((prev === "module" || prev === "function") && !KEYWORDS.has(m))
92
+ push("definition", m);
93
+ else if (KEYWORDS.has(m)) push("keyword", m);
94
+ else if (CONSTANTS.has(m)) push("constant", m);
95
+ else if (call && LAYERS.has(m)) push("layer", m);
96
+ else if (call && BUILTINS.has(m)) push("builtin", m);
97
+ else if (call) push("call", m);
98
+ else push("plain", m);
99
+ prev = m;
100
+ i += m.length;
101
+ start = false;
102
+ } else {
103
+ push("plain", c);
104
+ if (!/\s/.test(c)) {
105
+ prev = "";
106
+ start = c === ";" || c === "{" || c === "}";
107
+ }
108
+ i++;
109
+ }
110
+ }
111
+ return out;
112
+ }
113
+ function highlightLines(src) {
114
+ const state = { inBlock: false };
115
+ return src.split("\n").map((line) => highlightLine(line, state));
116
+ }
117
+ var esc = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
118
+ function highlight(src) {
119
+ return highlightLines(src).map(
120
+ (tokens) => tokens.map(
121
+ (t) => t.kind === "plain" ? esc(t.text) : `<span class="t-${t.kind}">${esc(t.text)}</span>`
122
+ ).join("")
123
+ ).join("\n");
124
+ }
125
+ export {
126
+ BUILTINS,
127
+ LAYERS,
128
+ highlight,
129
+ highlightLine,
130
+ highlightLines
131
+ };