woodml-parser 1.0.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/README.md +181 -0
- package/dist/cli.d.ts +7 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +554 -0
- package/dist/cli.js.map +1 -0
- package/dist/cost.d.ts +94 -0
- package/dist/cost.d.ts.map +1 -0
- package/dist/cost.js +340 -0
- package/dist/cost.js.map +1 -0
- package/dist/cost.test.d.ts +2 -0
- package/dist/cost.test.d.ts.map +1 -0
- package/dist/cost.test.js +241 -0
- package/dist/cost.test.js.map +1 -0
- package/dist/example.d.ts +6 -0
- package/dist/example.d.ts.map +1 -0
- package/dist/example.js +136 -0
- package/dist/example.js.map +1 -0
- package/dist/formulas.d.ts +23 -0
- package/dist/formulas.d.ts.map +1 -0
- package/dist/formulas.js +442 -0
- package/dist/formulas.js.map +1 -0
- package/dist/formulas.test.d.ts +5 -0
- package/dist/formulas.test.d.ts.map +1 -0
- package/dist/formulas.test.js +360 -0
- package/dist/formulas.test.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +93 -0
- package/dist/index.js.map +1 -0
- package/dist/integration.test.d.ts +6 -0
- package/dist/integration.test.d.ts.map +1 -0
- package/dist/integration.test.js +271 -0
- package/dist/integration.test.js.map +1 -0
- package/dist/optimizer.d.ts +119 -0
- package/dist/optimizer.d.ts.map +1 -0
- package/dist/optimizer.js +423 -0
- package/dist/optimizer.js.map +1 -0
- package/dist/optimizer.test.d.ts +2 -0
- package/dist/optimizer.test.d.ts.map +1 -0
- package/dist/optimizer.test.js +225 -0
- package/dist/optimizer.test.js.map +1 -0
- package/dist/parser.d.ts +59 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/parser.js +305 -0
- package/dist/parser.js.map +1 -0
- package/dist/parser.test.d.ts +5 -0
- package/dist/parser.test.d.ts.map +1 -0
- package/dist/parser.test.js +486 -0
- package/dist/parser.test.js.map +1 -0
- package/dist/pdf.d.ts +36 -0
- package/dist/pdf.d.ts.map +1 -0
- package/dist/pdf.js +316 -0
- package/dist/pdf.js.map +1 -0
- package/dist/svg.d.ts +73 -0
- package/dist/svg.d.ts.map +1 -0
- package/dist/svg.js +613 -0
- package/dist/svg.js.map +1 -0
- package/dist/svg.test.d.ts +5 -0
- package/dist/svg.test.d.ts.map +1 -0
- package/dist/svg.test.js +333 -0
- package/dist/svg.test.js.map +1 -0
- package/dist/templates.d.ts +126 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/templates.js +448 -0
- package/dist/templates.js.map +1 -0
- package/dist/templates.test.d.ts +5 -0
- package/dist/templates.test.d.ts.map +1 -0
- package/dist/templates.test.js +630 -0
- package/dist/templates.test.js.map +1 -0
- package/dist/types.d.ts +250 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/units.d.ts +53 -0
- package/dist/units.d.ts.map +1 -0
- package/dist/units.js +359 -0
- package/dist/units.js.map +1 -0
- package/dist/units.test.d.ts +5 -0
- package/dist/units.test.d.ts.map +1 -0
- package/dist/units.test.js +364 -0
- package/dist/units.test.js.map +1 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# WoodML Parser (TypeScript)
|
|
2
|
+
|
|
3
|
+
Reference implementation of the WoodML parser for TypeScript/JavaScript.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install woodml-parser
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## CLI Usage
|
|
12
|
+
|
|
13
|
+
After installation, the `woodml` command is available:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# Parse and display project info
|
|
17
|
+
woodml parse project.woodml
|
|
18
|
+
|
|
19
|
+
# Generate a cut list
|
|
20
|
+
woodml cutlist project.woodml -f table
|
|
21
|
+
|
|
22
|
+
# Validate a file
|
|
23
|
+
woodml validate project.woodml
|
|
24
|
+
|
|
25
|
+
# Show project information
|
|
26
|
+
woodml info project.woodml -f json
|
|
27
|
+
|
|
28
|
+
# Generate SVG diagram
|
|
29
|
+
woodml diagram project.woodml -o diagram.svg
|
|
30
|
+
|
|
31
|
+
# Generate exploded view with blueprint colors
|
|
32
|
+
woodml diagram project.woodml -t exploded -c blueprint -o exploded.svg
|
|
33
|
+
|
|
34
|
+
# Generate cut list layout diagram
|
|
35
|
+
woodml diagram project.woodml -t cutlist -o cutlist.svg
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### CLI Options
|
|
39
|
+
|
|
40
|
+
- `-o, --output <file>` - Write output to file instead of stdout
|
|
41
|
+
- `-f, --format <fmt>` - Output format: json, text, table (default: text)
|
|
42
|
+
- `-v, --verbose` - Show detailed output
|
|
43
|
+
- `-h, --help` - Show help message
|
|
44
|
+
|
|
45
|
+
### Diagram Options
|
|
46
|
+
|
|
47
|
+
- `-t, --type <type>` - Diagram type: parts, exploded, cutlist (default: parts)
|
|
48
|
+
- `-c, --color <scheme>` - Color scheme: default, blueprint, monochrome
|
|
49
|
+
- `-w, --width <px>` - SVG width in pixels (default: 800)
|
|
50
|
+
- `--height <px>` - SVG height in pixels (default: 600)
|
|
51
|
+
|
|
52
|
+
## Library Usage
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import {
|
|
56
|
+
parse,
|
|
57
|
+
parseAndResolve,
|
|
58
|
+
validateDocument,
|
|
59
|
+
generateCutList,
|
|
60
|
+
formatCutList,
|
|
61
|
+
calculateBoardFeet
|
|
62
|
+
} from 'woodml-parser';
|
|
63
|
+
|
|
64
|
+
// Parse a WoodML file
|
|
65
|
+
const doc = parse(woodmlSource);
|
|
66
|
+
|
|
67
|
+
// Parse and resolve all variables
|
|
68
|
+
const resolved = parseAndResolve(woodmlSource);
|
|
69
|
+
|
|
70
|
+
// Validate document
|
|
71
|
+
const errors = validateDocument(doc);
|
|
72
|
+
|
|
73
|
+
// Generate cut list
|
|
74
|
+
const cutList = generateCutList(resolved);
|
|
75
|
+
console.log(formatCutList(cutList));
|
|
76
|
+
|
|
77
|
+
// Calculate total board feet
|
|
78
|
+
const boardFeet = calculateBoardFeet(resolved);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Working with Dimensions
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import {
|
|
85
|
+
parseDimension,
|
|
86
|
+
toInches,
|
|
87
|
+
toMillimeters,
|
|
88
|
+
formatImperial,
|
|
89
|
+
formatMetric
|
|
90
|
+
} from 'woodml-parser';
|
|
91
|
+
|
|
92
|
+
// Parse various dimension formats
|
|
93
|
+
const dim1 = parseDimension('24"'); // 24 inches
|
|
94
|
+
const dim2 = parseDimension('3-1/2"'); // 3.5 inches
|
|
95
|
+
const dim3 = parseDimension("6'4\""); // 76 inches
|
|
96
|
+
const dim4 = parseDimension('610mm'); // 610 millimeters
|
|
97
|
+
const dim5 = parseDimension('4/4'); // 1 inch (quarter notation)
|
|
98
|
+
|
|
99
|
+
// Convert between units
|
|
100
|
+
const inches = toInches(dim4); // 24.0157...
|
|
101
|
+
const mm = toMillimeters(dim1); // 609.6
|
|
102
|
+
|
|
103
|
+
// Format for display
|
|
104
|
+
console.log(formatImperial(dim1)); // "2'"
|
|
105
|
+
console.log(formatMetric(dim4)); // "61cm"
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Working with Formulas
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
import { createContext, evaluateFormula, resolveFormulas } from 'woodml-parser';
|
|
112
|
+
|
|
113
|
+
// Create a context with variables
|
|
114
|
+
const ctx = createContext({
|
|
115
|
+
width: '24"',
|
|
116
|
+
depth: '18"',
|
|
117
|
+
height: '30"',
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// Evaluate formulas
|
|
121
|
+
const area = evaluateFormula('$width * $depth', ctx);
|
|
122
|
+
const diagonal = evaluateFormula('diagonal($width, $depth)', ctx);
|
|
123
|
+
|
|
124
|
+
// Available functions:
|
|
125
|
+
// Math: min, max, abs, sqrt, round, floor, ceil, sin, cos, tan
|
|
126
|
+
// Woodworking: board_feet, square_feet, miter_angle, diagonal, golden_ratio
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## API Reference
|
|
130
|
+
|
|
131
|
+
### Parser Functions
|
|
132
|
+
|
|
133
|
+
- `parse(source: string): WoodMLDocument` - Parse WoodML source
|
|
134
|
+
- `parseAndResolve(source: string): ResolvedDocument` - Parse and resolve variables
|
|
135
|
+
- `validateDocument(doc: WoodMLDocument): ValidationError[]` - Validate document
|
|
136
|
+
|
|
137
|
+
### Cut List Functions
|
|
138
|
+
|
|
139
|
+
- `generateCutList(doc: ResolvedDocument): CutListItem[]` - Generate cut list
|
|
140
|
+
- `formatCutList(items: CutListItem[]): string` - Format as table
|
|
141
|
+
- `calculateBoardFeet(doc: ResolvedDocument): number` - Calculate total board feet
|
|
142
|
+
|
|
143
|
+
### Unit Functions
|
|
144
|
+
|
|
145
|
+
- `parseDimension(input: string): Dimension` - Parse dimension string
|
|
146
|
+
- `toInches(dim: Dimension): number` - Convert to inches
|
|
147
|
+
- `toMillimeters(dim: Dimension): number` - Convert to millimeters
|
|
148
|
+
- `formatImperial(dim: Dimension): string` - Format as imperial
|
|
149
|
+
- `formatMetric(dim: Dimension): string` - Format as metric
|
|
150
|
+
|
|
151
|
+
### SVG Generation
|
|
152
|
+
|
|
153
|
+
- `generateSVG(doc, type?, options?)` - Generate SVG diagram
|
|
154
|
+
- `generatePartSVG(part, options?)` - Generate SVG for single part
|
|
155
|
+
- `SVGGenerator` - Class for fine-grained control
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
import { parseAndResolve, generateSVG, SVGGenerator } from 'woodml-parser';
|
|
159
|
+
|
|
160
|
+
const doc = parseAndResolve(source);
|
|
161
|
+
|
|
162
|
+
// Quick generation
|
|
163
|
+
const svg = generateSVG(doc, 'parts', { colorScheme: 'blueprint' });
|
|
164
|
+
|
|
165
|
+
// Using the generator class
|
|
166
|
+
const generator = new SVGGenerator({
|
|
167
|
+
width: 1200,
|
|
168
|
+
height: 800,
|
|
169
|
+
showDimensions: true,
|
|
170
|
+
showGrain: true,
|
|
171
|
+
colorScheme: 'default',
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
const partsDiagram = generator.generatePartsDiagram(doc);
|
|
175
|
+
const explodedView = generator.generateExplodedView(doc);
|
|
176
|
+
const cutlistLayout = generator.generateCutListDiagram(doc, 48, 96);
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## License
|
|
180
|
+
|
|
181
|
+
MIT
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;GAGG"}
|