@mylasertools/kerfscript 0.4.0 → 0.6.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 (68) hide show
  1. package/CHANGELOG.md +125 -1
  2. package/LANGUAGE.md +26 -11
  3. package/README.md +79 -5
  4. package/dist/ast.d.cts +13 -1
  5. package/dist/ast.d.ts +13 -1
  6. package/dist/cli.js +7509 -1629
  7. package/dist/diagnostics.d.cts +6 -0
  8. package/dist/diagnostics.d.ts +6 -0
  9. package/dist/evaluator.d.cts +12 -0
  10. package/dist/evaluator.d.ts +12 -0
  11. package/dist/format.d.cts +4 -0
  12. package/dist/format.d.ts +4 -0
  13. package/dist/highlight.cjs +151 -0
  14. package/dist/highlight.d.cts +13 -0
  15. package/dist/highlight.d.ts +13 -0
  16. package/dist/highlight.js +131 -0
  17. package/dist/import/dbg.d.cts +1 -0
  18. package/dist/import/dbg.d.ts +1 -0
  19. package/dist/import/index.d.cts +16 -0
  20. package/dist/import/index.d.ts +16 -0
  21. package/dist/import/shapes.d.cts +76 -0
  22. package/dist/import/shapes.d.ts +76 -0
  23. package/dist/import/svg.d.cts +48 -0
  24. package/dist/import/svg.d.ts +48 -0
  25. package/dist/import/xml.d.cts +12 -0
  26. package/dist/import/xml.d.ts +12 -0
  27. package/dist/index.cjs +391 -13
  28. package/dist/index.d.cts +7 -3
  29. package/dist/index.d.ts +7 -3
  30. package/dist/index.js +391 -13
  31. package/dist/language.cjs +417 -0
  32. package/dist/language.d.cts +143 -0
  33. package/dist/language.d.ts +143 -0
  34. package/dist/language.js +417 -0
  35. package/dist/lexer.d.cts +17 -0
  36. package/dist/lexer.d.ts +17 -0
  37. package/dist/libraries.cjs +380 -0
  38. package/dist/libraries.d.cts +112 -0
  39. package/dist/libraries.d.ts +112 -0
  40. package/dist/libraries.js +380 -0
  41. package/dist/lsp.d.cts +12 -0
  42. package/dist/lsp.d.ts +12 -0
  43. package/dist/paths.d.cts +1 -1
  44. package/dist/paths.d.ts +1 -1
  45. package/dist/signatures.cjs +675 -0
  46. package/dist/signatures.d.cts +20 -0
  47. package/dist/signatures.d.ts +20 -0
  48. package/dist/signatures.js +655 -0
  49. package/docs/cli.md +54 -2
  50. package/docs/desktop.md +5 -0
  51. package/docs/editors.md +121 -0
  52. package/docs/import.md +149 -0
  53. package/docs/javascript.md +177 -10
  54. package/docs/kerf.md +10 -0
  55. package/docs/library/box.svg +11 -0
  56. package/docs/library/calibration.svg +11 -0
  57. package/docs/library/dividers.svg +11 -0
  58. package/docs/library/enclosure.svg +11 -0
  59. package/docs/library/hanging.svg +11 -0
  60. package/docs/library/hinge.svg +11 -0
  61. package/docs/library/tabs.svg +11 -0
  62. package/docs/library.md +339 -0
  63. package/docs/mcp.md +88 -0
  64. package/docs/openscad.md +1 -1
  65. package/docs/shared-libraries.md +229 -0
  66. package/docs/specification.md +529 -0
  67. package/docs/versions.md +2 -2
  68. package/package.json +52 -6
@@ -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;
@@ -57,12 +57,18 @@ declare class Env {
57
57
  fn(name: string): FnDef | undefined;
58
58
  mod(name: string): ModDef | undefined;
59
59
  childCtx(): ChildCtx | undefined;
60
+ names(kind: 'vars' | 'fns' | 'mods'): string[];
60
61
  }
61
62
  interface Args {
62
63
  pos: Value[];
63
64
  named: Map<string, Value>;
65
+ all: {
66
+ name: string | null;
67
+ value: Value;
68
+ }[];
64
69
  at: Pos;
65
70
  }
71
+ export declare function didYouMean(name: string, known: Iterable<string>): string;
66
72
  export interface EvalResult {
67
73
  shape: Shape;
68
74
  globals: Env;
@@ -90,6 +96,9 @@ export declare class Evaluator {
90
96
  private tick;
91
97
  private load;
92
98
  private hoist;
99
+ private using;
100
+ private including;
101
+ private enter;
93
102
  private included;
94
103
  private assign;
95
104
  block(stmts: Stmt[], env: Env, top?: boolean): Shape;
@@ -99,11 +108,14 @@ export declare class Evaluator {
99
108
  private loop;
100
109
  private evalArgs;
101
110
  private bindParams;
111
+ private checkArgs;
112
+ private checkCount;
102
113
  private unknownArg;
103
114
  private warn;
104
115
  private callModule;
105
116
  private childStmts;
106
117
  callFunction(f: FnDef | Closure, args: Args, caller: Env, name: string): Value;
118
+ private inCall;
107
119
  expr(x: Expr, env: Env): Value;
108
120
  private listItem;
109
121
  private grow;
@@ -57,12 +57,18 @@ declare class Env {
57
57
  fn(name: string): FnDef | undefined;
58
58
  mod(name: string): ModDef | undefined;
59
59
  childCtx(): ChildCtx | undefined;
60
+ names(kind: 'vars' | 'fns' | 'mods'): string[];
60
61
  }
61
62
  interface Args {
62
63
  pos: Value[];
63
64
  named: Map<string, Value>;
65
+ all: {
66
+ name: string | null;
67
+ value: Value;
68
+ }[];
64
69
  at: Pos;
65
70
  }
71
+ export declare function didYouMean(name: string, known: Iterable<string>): string;
66
72
  export interface EvalResult {
67
73
  shape: Shape;
68
74
  globals: Env;
@@ -90,6 +96,9 @@ export declare class Evaluator {
90
96
  private tick;
91
97
  private load;
92
98
  private hoist;
99
+ private using;
100
+ private including;
101
+ private enter;
93
102
  private included;
94
103
  private assign;
95
104
  block(stmts: Stmt[], env: Env, top?: boolean): Shape;
@@ -99,11 +108,14 @@ export declare class Evaluator {
99
108
  private loop;
100
109
  private evalArgs;
101
110
  private bindParams;
111
+ private checkArgs;
112
+ private checkCount;
102
113
  private unknownArg;
103
114
  private warn;
104
115
  private callModule;
105
116
  private childStmts;
106
117
  callFunction(f: FnDef | Closure, args: Args, caller: Env, name: string): Value;
118
+ private inCall;
107
119
  expr(x: Expr, env: Env): Value;
108
120
  private listItem;
109
121
  private grow;
@@ -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;
@@ -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
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ export interface ImportOptions {
2
+ dpi?: number;
3
+ tolerance?: number;
4
+ name?: string;
5
+ pack?: boolean;
6
+ kerf?: number;
7
+ }
8
+ export interface ImportResult {
9
+ source: string;
10
+ parts: number;
11
+ found: Record<string, number>;
12
+ summary: string;
13
+ notes: string[];
14
+ }
15
+ export declare function decodeSvg(bytes: Uint8Array | ArrayBuffer): string;
16
+ export declare function importSvg(svg: string | Uint8Array | ArrayBuffer, options?: ImportOptions): ImportResult;
@@ -0,0 +1,16 @@
1
+ export interface ImportOptions {
2
+ dpi?: number;
3
+ tolerance?: number;
4
+ name?: string;
5
+ pack?: boolean;
6
+ kerf?: number;
7
+ }
8
+ export interface ImportResult {
9
+ source: string;
10
+ parts: number;
11
+ found: Record<string, number>;
12
+ summary: string;
13
+ notes: string[];
14
+ }
15
+ export declare function decodeSvg(bytes: Uint8Array | ArrayBuffer): string;
16
+ export declare function importSvg(svg: string | Uint8Array | ArrayBuffer, options?: ImportOptions): ImportResult;
@@ -0,0 +1,76 @@
1
+ import { type Poly, type Pt } from '../geometry.cjs';
2
+ import { type Edge } from '../joinery.cjs';
3
+ import type { Sub } from './svg.cjs';
4
+ export declare const dist: (a: Pt, b: Pt) => number;
5
+ declare const rot: ([x, y]: Pt, deg: number) => Pt;
6
+ declare const add: (a: Pt, b: Pt) => Pt;
7
+ declare const sub: (a: Pt, b: Pt) => Pt;
8
+ export declare function flattenSub(s: Sub, tol?: number): Poly;
9
+ export declare function perimeter(p: Poly, closed?: boolean): number;
10
+ export declare function resample(p: Poly, closed: boolean, step: number): Pt[];
11
+ export declare function tangled(polys: Poly[], tol: number): {
12
+ self: boolean[];
13
+ pairs: [number, number][];
14
+ };
15
+ export declare function sameOutlines(a: Poly[], b: Poly[], tol: number, closed?: boolean): boolean;
16
+ export declare function materialTest(outline: Poly, holes: Poly[], tol: number): (line: Poly, closed: boolean) => boolean;
17
+ export declare function touches(lines: Poly[], outline: Poly, tol: number): boolean;
18
+ export declare function inside(pt: Pt, poly: Poly): boolean;
19
+ export declare function fitCircle(pts: Pt[]): {
20
+ c: Pt;
21
+ r: number;
22
+ } | null;
23
+ export declare function simplify(p: Poly, tol?: number): Poly;
24
+ export declare function kerfRadius(polys: Poly[]): number | undefined;
25
+ export declare function sharpen(p: Poly, r: number): Poly;
26
+ export declare function snap(v: number): number;
27
+ export declare const num: (v: number) => string;
28
+ export declare const vec: (p: Pt) => string;
29
+ export declare function angle(a: number): number;
30
+ export declare function place(at: Pt, deg: number, body: string): string;
31
+ export interface Found {
32
+ kind: 'circle' | 'ellipse' | 'rect' | 'polygon' | 'star' | 'tabs' | 'fingers' | 'keyhole' | 'outline';
33
+ body: string;
34
+ at: Pt;
35
+ angle: number;
36
+ center: Pt;
37
+ label?: string;
38
+ thickness?: number;
39
+ circle?: {
40
+ c: Pt;
41
+ r: number;
42
+ };
43
+ rect?: {
44
+ w: number;
45
+ h: number;
46
+ r: number;
47
+ };
48
+ keyhole?: {
49
+ head: number;
50
+ shank: number;
51
+ drop: number;
52
+ top: Pt;
53
+ };
54
+ library?: 'tabs' | 'hanging';
55
+ radius?: number;
56
+ generic?: boolean;
57
+ edges?: Edge[];
58
+ finger?: number;
59
+ }
60
+ export interface Outline {
61
+ poly: Poly;
62
+ area: number;
63
+ box: [number, number, number, number];
64
+ ends?: Pt[];
65
+ }
66
+ export declare function outlineOf(poly: Poly, s?: Sub): Outline;
67
+ declare const rectPoly: (x0: number, y0: number, x1: number, y1: number) => Poly;
68
+ export declare function circleOf(o: Outline, tol: number): Found | undefined;
69
+ export declare function ellipseOf(o: Outline, tol: number): Found | undefined;
70
+ export declare function rectOf(o: Outline, tol: number): Found | undefined;
71
+ export declare function regularOf(o: Outline, tol: number): Found | undefined;
72
+ export declare function jointOf(o: Outline, tol: number, preferThickness?: number): Found | undefined;
73
+ export declare function keyholeOf(o: Outline, tol: number): Found | undefined;
74
+ export declare function outlineCode(s: Sub, origin: Pt): string;
75
+ export declare function pathData(subs: Sub[], origin: Pt): string;
76
+ export { rot, add, sub, rectPoly };
@@ -0,0 +1,76 @@
1
+ import { type Poly, type Pt } from '../geometry.js';
2
+ import { type Edge } from '../joinery.js';
3
+ import type { Sub } from './svg.js';
4
+ export declare const dist: (a: Pt, b: Pt) => number;
5
+ declare const rot: ([x, y]: Pt, deg: number) => Pt;
6
+ declare const add: (a: Pt, b: Pt) => Pt;
7
+ declare const sub: (a: Pt, b: Pt) => Pt;
8
+ export declare function flattenSub(s: Sub, tol?: number): Poly;
9
+ export declare function perimeter(p: Poly, closed?: boolean): number;
10
+ export declare function resample(p: Poly, closed: boolean, step: number): Pt[];
11
+ export declare function tangled(polys: Poly[], tol: number): {
12
+ self: boolean[];
13
+ pairs: [number, number][];
14
+ };
15
+ export declare function sameOutlines(a: Poly[], b: Poly[], tol: number, closed?: boolean): boolean;
16
+ export declare function materialTest(outline: Poly, holes: Poly[], tol: number): (line: Poly, closed: boolean) => boolean;
17
+ export declare function touches(lines: Poly[], outline: Poly, tol: number): boolean;
18
+ export declare function inside(pt: Pt, poly: Poly): boolean;
19
+ export declare function fitCircle(pts: Pt[]): {
20
+ c: Pt;
21
+ r: number;
22
+ } | null;
23
+ export declare function simplify(p: Poly, tol?: number): Poly;
24
+ export declare function kerfRadius(polys: Poly[]): number | undefined;
25
+ export declare function sharpen(p: Poly, r: number): Poly;
26
+ export declare function snap(v: number): number;
27
+ export declare const num: (v: number) => string;
28
+ export declare const vec: (p: Pt) => string;
29
+ export declare function angle(a: number): number;
30
+ export declare function place(at: Pt, deg: number, body: string): string;
31
+ export interface Found {
32
+ kind: 'circle' | 'ellipse' | 'rect' | 'polygon' | 'star' | 'tabs' | 'fingers' | 'keyhole' | 'outline';
33
+ body: string;
34
+ at: Pt;
35
+ angle: number;
36
+ center: Pt;
37
+ label?: string;
38
+ thickness?: number;
39
+ circle?: {
40
+ c: Pt;
41
+ r: number;
42
+ };
43
+ rect?: {
44
+ w: number;
45
+ h: number;
46
+ r: number;
47
+ };
48
+ keyhole?: {
49
+ head: number;
50
+ shank: number;
51
+ drop: number;
52
+ top: Pt;
53
+ };
54
+ library?: 'tabs' | 'hanging';
55
+ radius?: number;
56
+ generic?: boolean;
57
+ edges?: Edge[];
58
+ finger?: number;
59
+ }
60
+ export interface Outline {
61
+ poly: Poly;
62
+ area: number;
63
+ box: [number, number, number, number];
64
+ ends?: Pt[];
65
+ }
66
+ export declare function outlineOf(poly: Poly, s?: Sub): Outline;
67
+ declare const rectPoly: (x0: number, y0: number, x1: number, y1: number) => Poly;
68
+ export declare function circleOf(o: Outline, tol: number): Found | undefined;
69
+ export declare function ellipseOf(o: Outline, tol: number): Found | undefined;
70
+ export declare function rectOf(o: Outline, tol: number): Found | undefined;
71
+ export declare function regularOf(o: Outline, tol: number): Found | undefined;
72
+ export declare function jointOf(o: Outline, tol: number, preferThickness?: number): Found | undefined;
73
+ export declare function keyholeOf(o: Outline, tol: number): Found | undefined;
74
+ export declare function outlineCode(s: Sub, origin: Pt): string;
75
+ export declare function pathData(subs: Sub[], origin: Pt): string;
76
+ export { rot, add, sub, rectPoly };
@@ -0,0 +1,48 @@
1
+ import { type Matrix, type Pt } from '../geometry.cjs';
2
+ export type Seg = {
3
+ c: 'L';
4
+ a: Pt;
5
+ b: Pt;
6
+ } | {
7
+ c: 'C';
8
+ a: Pt;
9
+ p1: Pt;
10
+ p2: Pt;
11
+ b: Pt;
12
+ };
13
+ export interface Sub {
14
+ segs: Seg[];
15
+ closed: boolean;
16
+ }
17
+ export interface LayerRef {
18
+ name: string;
19
+ mode: 'cut' | 'line' | 'fill' | 'guide';
20
+ color: string;
21
+ }
22
+ export interface Item {
23
+ subs: Sub[];
24
+ layer: LayerRef;
25
+ fillRule: 'nonzero' | 'evenodd';
26
+ names: string[];
27
+ filled?: boolean;
28
+ }
29
+ export interface TextItem {
30
+ text: string;
31
+ at: Pt;
32
+ size: number;
33
+ angle: number;
34
+ font: string;
35
+ anchor: 'left' | 'center' | 'right';
36
+ layer: LayerRef;
37
+ }
38
+ export interface SvgDrawing {
39
+ items: Item[];
40
+ texts: TextItem[];
41
+ notes: string[];
42
+ }
43
+ export interface ReadOptions {
44
+ dpi?: number;
45
+ }
46
+ export declare const LAYERS: Record<string, LayerRef>;
47
+ export declare function parseTransform(s: string | undefined): Matrix;
48
+ export declare function readSvg(src: string, opts?: ReadOptions): SvgDrawing;