@mylasertools/kerfscript 0.6.0 → 0.7.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 (83) hide show
  1. package/CHANGELOG.md +167 -1
  2. package/LANGUAGE.md +160 -30
  3. package/README.md +8 -2
  4. package/THIRD-PARTY-NOTICES.md +113 -0
  5. package/dist/analysis.d.cts +20 -0
  6. package/dist/analysis.d.ts +20 -0
  7. package/dist/assembly.d.cts +28 -1
  8. package/dist/assembly.d.ts +28 -1
  9. package/dist/ast.d.cts +9 -0
  10. package/dist/ast.d.ts +9 -0
  11. package/dist/cli.js +10165 -4669
  12. package/dist/diff.d.cts +18 -0
  13. package/dist/diff.d.ts +18 -0
  14. package/dist/evaluator.d.cts +34 -0
  15. package/dist/evaluator.d.ts +34 -0
  16. package/dist/functions.d.cts +1 -0
  17. package/dist/functions.d.ts +1 -0
  18. package/dist/geometry.d.cts +17 -0
  19. package/dist/geometry.d.ts +17 -0
  20. package/dist/hardware.d.cts +13 -0
  21. package/dist/hardware.d.ts +13 -0
  22. package/dist/highlight.cjs +2 -2
  23. package/dist/highlight.js +2 -2
  24. package/dist/index.cjs +1941 -52
  25. package/dist/index.d.cts +11 -2
  26. package/dist/index.d.ts +11 -2
  27. package/dist/index.js +1941 -52
  28. package/dist/instructions.d.cts +3 -0
  29. package/dist/instructions.d.ts +3 -0
  30. package/dist/language.cjs +1899 -51
  31. package/dist/language.js +1899 -51
  32. package/dist/libraries.cjs +1874 -26
  33. package/dist/libraries.d.cts +3 -0
  34. package/dist/libraries.d.ts +3 -0
  35. package/dist/libraries.js +1874 -26
  36. package/dist/png.d.cts +9 -0
  37. package/dist/png.d.ts +9 -0
  38. package/dist/render.d.cts +22 -1
  39. package/dist/render.d.ts +22 -1
  40. package/dist/signatures.cjs +244 -11
  41. package/dist/signatures.js +244 -11
  42. package/dist/slots.d.cts +8 -0
  43. package/dist/slots.d.ts +8 -0
  44. package/dist/values.d.cts +6 -1
  45. package/dist/values.d.ts +6 -1
  46. package/dist/verify/command.d.cts +1 -0
  47. package/dist/verify/command.d.ts +1 -0
  48. package/dist/verify/geometry.d.cts +25 -0
  49. package/dist/verify/geometry.d.ts +25 -0
  50. package/dist/verify/index.d.cts +10 -0
  51. package/dist/verify/index.d.ts +10 -0
  52. package/dist/verify/joints.d.cts +7 -0
  53. package/dist/verify/joints.d.ts +7 -0
  54. package/dist/verify/mechanics.d.cts +11 -0
  55. package/dist/verify/mechanics.d.ts +11 -0
  56. package/dist/verify/motion.d.cts +8 -0
  57. package/dist/verify/motion.d.ts +8 -0
  58. package/dist/verify/pose.d.cts +5 -0
  59. package/dist/verify/pose.d.ts +5 -0
  60. package/dist/verify/relations.d.cts +8 -0
  61. package/dist/verify/relations.d.ts +8 -0
  62. package/dist/verify/snapshot.d.cts +11 -0
  63. package/dist/verify/snapshot.d.ts +11 -0
  64. package/dist/verify/solids.d.cts +39 -0
  65. package/dist/verify/solids.d.ts +39 -0
  66. package/dist/verify/spec.d.cts +9 -0
  67. package/dist/verify/spec.d.ts +9 -0
  68. package/dist/verify/summary.d.cts +17 -0
  69. package/dist/verify/summary.d.ts +17 -0
  70. package/dist/verify/types.d.cts +299 -0
  71. package/dist/verify/types.d.ts +299 -0
  72. package/docs/cli.md +87 -15
  73. package/docs/javascript.md +57 -25
  74. package/docs/layers.md +42 -2
  75. package/docs/library.md +299 -3
  76. package/docs/parts-and-sheets.md +186 -1
  77. package/docs/shared-libraries.md +8 -1
  78. package/docs/specification.md +78 -23
  79. package/docs/verification.md +363 -0
  80. package/docs/versions.md +2 -2
  81. package/package.json +2 -1
  82. package/dist/import/dbg.d.cts +0 -1
  83. package/dist/import/dbg.d.ts +0 -1
@@ -0,0 +1,18 @@
1
+ import type { RenderResult } from './render.cjs';
2
+ export interface DiffEntry {
3
+ part: string;
4
+ copy: number;
5
+ /** The layer, or none when the whole part is added or removed */
6
+ layer?: string;
7
+ change: 'added' | 'removed' | 'changed';
8
+ /** Area of the closed shapes that differ, mm² */
9
+ area?: number;
10
+ /** Open lines only in the first render, and only in the second */
11
+ linesRemoved?: number;
12
+ linesAdded?: number;
13
+ /** Where, as [x0, y0, x1, y1] in the part's coordinates */
14
+ at?: [number, number, number, number];
15
+ }
16
+ /** The differences between two renders made with `layout: "none"`, at
17
+ * most `tolerance` mm² of area counted as the same. */
18
+ export declare function diffRenders(a: RenderResult, b: RenderResult, tolerance?: number): DiffEntry[];
package/dist/diff.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import type { RenderResult } from './render.js';
2
+ export interface DiffEntry {
3
+ part: string;
4
+ copy: number;
5
+ /** The layer, or none when the whole part is added or removed */
6
+ layer?: string;
7
+ change: 'added' | 'removed' | 'changed';
8
+ /** Area of the closed shapes that differ, mm² */
9
+ area?: number;
10
+ /** Open lines only in the first render, and only in the second */
11
+ linesRemoved?: number;
12
+ linesAdded?: number;
13
+ /** Where, as [x0, y0, x1, y1] in the part's coordinates */
14
+ at?: [number, number, number, number];
15
+ }
16
+ /** The differences between two renders made with `layout: "none"`, at
17
+ * most `tolerance` mm² of area counted as the same. */
18
+ export declare function diffRenders(a: RenderResult, b: RenderResult, tolerance?: number): DiffEntry[];
@@ -1,12 +1,27 @@
1
1
  import type { Expr, Param, Program, Stmt } from './ast.cjs';
2
2
  import { type Shape } from './geometry.cjs';
3
+ import { type Vec3 } from './assembly.cjs';
3
4
  import { type Pos } from './lexer.cjs';
4
5
  import { type FontBook } from './text.cjs';
5
6
  import { type Closure, type Value } from './values.cjs';
7
+ export declare const MAX_HARDWARE_SIDES = 128;
6
8
  export interface LayerDef {
7
9
  name: string;
8
10
  mode: 'cut' | 'line' | 'fill' | 'guide';
9
11
  color: string;
12
+ side?: 'back';
13
+ order?: number;
14
+ bleed?: number;
15
+ }
16
+ export interface HardwareItem {
17
+ kind: string;
18
+ from: Vec3;
19
+ to: Vec3;
20
+ size: number | [number, number];
21
+ up: Vec3;
22
+ sides: number;
23
+ step: number;
24
+ label?: string;
10
25
  }
11
26
  export declare const DEFAULT_LAYERS: LayerDef[];
12
27
  export interface EvalOptions {
@@ -28,6 +43,7 @@ export interface Limits {
28
43
  maxCollisionPairs: number;
29
44
  }
30
45
  export declare const DEFAULT_LIMITS: Limits;
46
+ export declare function besideFile(from: string | undefined, path: string): string | undefined;
31
47
  interface ModDef {
32
48
  params: Param[];
33
49
  body: Stmt[];
@@ -75,6 +91,8 @@ export interface EvalResult {
75
91
  layers: Map<string, LayerDef>;
76
92
  echoes: string[];
77
93
  warnings: string[];
94
+ hardware: HardwareItem[];
95
+ steps: string[];
78
96
  }
79
97
  export declare const STDLIB: Record<string, string>;
80
98
  export declare class Evaluator {
@@ -86,6 +104,11 @@ export declare class Evaluator {
86
104
  private pointCount;
87
105
  private itemCount;
88
106
  private copies;
107
+ private frame;
108
+ private step;
109
+ readonly stepNames: string[];
110
+ private stepFolded;
111
+ readonly hardware: HardwareItem[];
89
112
  readonly echoes: string[];
90
113
  readonly warnings: string[];
91
114
  readonly layers: Map<string, LayerDef>;
@@ -96,6 +119,10 @@ export declare class Evaluator {
96
119
  private tick;
97
120
  private load;
98
121
  private hoist;
122
+ private childCache;
123
+ private childKey;
124
+ private effects;
125
+ private unscaled?;
99
126
  private using;
100
127
  private including;
101
128
  private enter;
@@ -112,6 +139,7 @@ export declare class Evaluator {
112
139
  private checkCount;
113
140
  private unknownArg;
114
141
  private warn;
142
+ private callByName;
115
143
  private callModule;
116
144
  private childStmts;
117
145
  callFunction(f: FnDef | Closure, args: Args, caller: Env, name: string): Value;
@@ -121,6 +149,10 @@ export declare class Evaluator {
121
149
  private grow;
122
150
  private charge;
123
151
  private call;
152
+ private invisiblePaint;
153
+ private record;
154
+ private length;
155
+ private callable;
124
156
  private specialFunction;
125
157
  private assert;
126
158
  private echo;
@@ -142,6 +174,8 @@ export declare class Evaluator {
142
174
  private measure;
143
175
  private textOpts;
144
176
  private edges;
177
+ private backLayer;
178
+ private bends;
145
179
  private makeBuiltins;
146
180
  }
147
181
  export {};
@@ -1,12 +1,27 @@
1
1
  import type { Expr, Param, Program, Stmt } from './ast.js';
2
2
  import { type Shape } from './geometry.js';
3
+ import { type Vec3 } from './assembly.js';
3
4
  import { type Pos } from './lexer.js';
4
5
  import { type FontBook } from './text.js';
5
6
  import { type Closure, type Value } from './values.js';
7
+ export declare const MAX_HARDWARE_SIDES = 128;
6
8
  export interface LayerDef {
7
9
  name: string;
8
10
  mode: 'cut' | 'line' | 'fill' | 'guide';
9
11
  color: string;
12
+ side?: 'back';
13
+ order?: number;
14
+ bleed?: number;
15
+ }
16
+ export interface HardwareItem {
17
+ kind: string;
18
+ from: Vec3;
19
+ to: Vec3;
20
+ size: number | [number, number];
21
+ up: Vec3;
22
+ sides: number;
23
+ step: number;
24
+ label?: string;
10
25
  }
11
26
  export declare const DEFAULT_LAYERS: LayerDef[];
12
27
  export interface EvalOptions {
@@ -28,6 +43,7 @@ export interface Limits {
28
43
  maxCollisionPairs: number;
29
44
  }
30
45
  export declare const DEFAULT_LIMITS: Limits;
46
+ export declare function besideFile(from: string | undefined, path: string): string | undefined;
31
47
  interface ModDef {
32
48
  params: Param[];
33
49
  body: Stmt[];
@@ -75,6 +91,8 @@ export interface EvalResult {
75
91
  layers: Map<string, LayerDef>;
76
92
  echoes: string[];
77
93
  warnings: string[];
94
+ hardware: HardwareItem[];
95
+ steps: string[];
78
96
  }
79
97
  export declare const STDLIB: Record<string, string>;
80
98
  export declare class Evaluator {
@@ -86,6 +104,11 @@ export declare class Evaluator {
86
104
  private pointCount;
87
105
  private itemCount;
88
106
  private copies;
107
+ private frame;
108
+ private step;
109
+ readonly stepNames: string[];
110
+ private stepFolded;
111
+ readonly hardware: HardwareItem[];
89
112
  readonly echoes: string[];
90
113
  readonly warnings: string[];
91
114
  readonly layers: Map<string, LayerDef>;
@@ -96,6 +119,10 @@ export declare class Evaluator {
96
119
  private tick;
97
120
  private load;
98
121
  private hoist;
122
+ private childCache;
123
+ private childKey;
124
+ private effects;
125
+ private unscaled?;
99
126
  private using;
100
127
  private including;
101
128
  private enter;
@@ -112,6 +139,7 @@ export declare class Evaluator {
112
139
  private checkCount;
113
140
  private unknownArg;
114
141
  private warn;
142
+ private callByName;
115
143
  private callModule;
116
144
  private childStmts;
117
145
  callFunction(f: FnDef | Closure, args: Args, caller: Env, name: string): Value;
@@ -121,6 +149,10 @@ export declare class Evaluator {
121
149
  private grow;
122
150
  private charge;
123
151
  private call;
152
+ private invisiblePaint;
153
+ private record;
154
+ private length;
155
+ private callable;
124
156
  private specialFunction;
125
157
  private assert;
126
158
  private echo;
@@ -142,6 +174,8 @@ export declare class Evaluator {
142
174
  private measure;
143
175
  private textOpts;
144
176
  private edges;
177
+ private backLayer;
178
+ private bends;
145
179
  private makeBuiltins;
146
180
  }
147
181
  export {};
@@ -20,4 +20,5 @@ export declare function bindArgs(f: Builtin, pos: Value[], named: Map<string, Va
20
20
  */
21
21
  export declare function argumentWork(name: string, args: Value[], max: number): number;
22
22
  export declare const FUNCTIONS: Record<string, Builtin>;
23
+ export declare function catmullRom(p: [number, number][], n: number, closed?: boolean): [number, number][];
23
24
  export {};
@@ -20,4 +20,5 @@ export declare function bindArgs(f: Builtin, pos: Value[], named: Map<string, Va
20
20
  */
21
21
  export declare function argumentWork(name: string, args: Value[], max: number): number;
22
22
  export declare const FUNCTIONS: Record<string, Builtin>;
23
+ export declare function catmullRom(p: [number, number][], n: number, closed?: boolean): [number, number][];
23
24
  export {};
@@ -14,6 +14,23 @@ export interface PartShape {
14
14
  kerf: number;
15
15
  material: string;
16
16
  placements?: Placement[];
17
+ stack?: number;
18
+ bends?: Bend[];
19
+ on?: string;
20
+ slots?: string[];
21
+ clearance?: number;
22
+ step?: number;
23
+ glue?: {
24
+ host: string;
25
+ face: 'top' | 'bottom';
26
+ };
27
+ mirrored?: boolean;
28
+ copies?: number[];
29
+ }
30
+ export interface Bend {
31
+ x0: number;
32
+ x1: number;
33
+ angle: number;
17
34
  }
18
35
  export interface Shape {
19
36
  layers: Map<string, Layer>;
@@ -14,6 +14,23 @@ export interface PartShape {
14
14
  kerf: number;
15
15
  material: string;
16
16
  placements?: Placement[];
17
+ stack?: number;
18
+ bends?: Bend[];
19
+ on?: string;
20
+ slots?: string[];
21
+ clearance?: number;
22
+ step?: number;
23
+ glue?: {
24
+ host: string;
25
+ face: 'top' | 'bottom';
26
+ };
27
+ mirrored?: boolean;
28
+ copies?: number[];
29
+ }
30
+ export interface Bend {
31
+ x0: number;
32
+ x1: number;
33
+ angle: number;
17
34
  }
18
35
  export interface Shape {
19
36
  layers: Map<string, Layer>;
@@ -0,0 +1,13 @@
1
+ export interface HardwareKind {
2
+ /** Colour as #rrggbb */
3
+ color: string;
4
+ /** Metal: shiny in the 3D view */
5
+ metal?: boolean;
6
+ /** Gives off light, as an LED */
7
+ glow?: boolean;
8
+ /** What it is, for the docs */
9
+ doc: string;
10
+ }
11
+ export declare const HARDWARE_KINDS: Record<string, HardwareKind>;
12
+ /** Colours a hardware kind may also be named by */
13
+ export declare const HARDWARE_COLORS: Record<string, string>;
@@ -0,0 +1,13 @@
1
+ export interface HardwareKind {
2
+ /** Colour as #rrggbb */
3
+ color: string;
4
+ /** Metal: shiny in the 3D view */
5
+ metal?: boolean;
6
+ /** Gives off light, as an LED */
7
+ glow?: boolean;
8
+ /** What it is, for the docs */
9
+ doc: string;
10
+ }
11
+ export declare const HARDWARE_KINDS: Record<string, HardwareKind>;
12
+ /** Colours a hardware kind may also be named by */
13
+ export declare const HARDWARE_COLORS: Record<string, string>;
@@ -42,9 +42,9 @@ var KEYWORDS = /* @__PURE__ */ new Set([
42
42
  var CONSTANTS = /* @__PURE__ */ new Set(["true", "false", "undef", "PI"]);
43
43
  var LAYERS = /* @__PURE__ */ new Set(["cut", "score", "engrave", "guide", "layer"]);
44
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(" ")
45
+ "rect square circle ellipse regular_polygon star polygon path text line polyline arc translate rotate scale mirror multmatrix union group difference intersection hull offset pattern spline hatch paint measure fill_holes close stroke outline part place call step hardware material finger_rect finger_holes tslot living_hinge children echo assert box divider kerf_gauge slot_gauge joint_test slotted_divider grid_dividers enclosure enclosure_cutouts vents spur_gear gear_window rack lantern_disc peg_wheel eccentric snail_cam tappets world_map keyhole keyholes hanging_hole hanging_loop flex_rect flex_box flex_panel narrow_hinge flex_strip cam_lock lock_key ring_stack halved_pair symbol tabs slots tab_rect abs sign floor ceil round sqrt exp ln log sin cos tan asin acos atan atan2 pow min max clamp lerp norm cross path_length point_at heading_at path_points spline_points rotation euler orient len keys merge 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 is_record type_of rands text_width text_metrics finger_count".split(" ")
46
46
  );
47
- var NUMBER = /(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/y;
47
+ var NUMBER = /(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?(?:(?:mm|cm|m|in|ft)(?![A-Za-z0-9_]))?/y;
48
48
  var WORD = /\$?[A-Za-z_][A-Za-z0-9_]*/y;
49
49
  var CALL = /\s*\(/y;
50
50
  var PATH = /<[^>]*>?/y;
package/dist/highlight.js CHANGED
@@ -15,9 +15,9 @@ var KEYWORDS = /* @__PURE__ */ new Set([
15
15
  var CONSTANTS = /* @__PURE__ */ new Set(["true", "false", "undef", "PI"]);
16
16
  var LAYERS = /* @__PURE__ */ new Set(["cut", "score", "engrave", "guide", "layer"]);
17
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(" ")
18
+ "rect square circle ellipse regular_polygon star polygon path text line polyline arc translate rotate scale mirror multmatrix union group difference intersection hull offset pattern spline hatch paint measure fill_holes close stroke outline part place call step hardware material finger_rect finger_holes tslot living_hinge children echo assert box divider kerf_gauge slot_gauge joint_test slotted_divider grid_dividers enclosure enclosure_cutouts vents spur_gear gear_window rack lantern_disc peg_wheel eccentric snail_cam tappets world_map keyhole keyholes hanging_hole hanging_loop flex_rect flex_box flex_panel narrow_hinge flex_strip cam_lock lock_key ring_stack halved_pair symbol tabs slots tab_rect abs sign floor ceil round sqrt exp ln log sin cos tan asin acos atan atan2 pow min max clamp lerp norm cross path_length point_at heading_at path_points spline_points rotation euler orient len keys merge 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 is_record type_of rands text_width text_metrics finger_count".split(" ")
19
19
  );
20
- var NUMBER = /(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/y;
20
+ var NUMBER = /(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?(?:(?:mm|cm|m|in|ft)(?![A-Za-z0-9_]))?/y;
21
21
  var WORD = /\$?[A-Za-z_][A-Za-z0-9_]*/y;
22
22
  var CALL = /\s*\(/y;
23
23
  var PATH = /<[^>]*>?/y;