jww-parser 2025.12.3 → 2025.12.7
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/LICENSE +202 -0
- package/README.mbt.md +1 -0
- package/dist/index.cjs +10800 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +10 -946
- package/dist/index.mjs +10794 -722
- package/dist/index.mjs.map +1 -0
- package/dist/moonbit.d.ts +57 -0
- package/package.json +35 -40
- package/README.md +0 -138
- package/dist/index.d.mts +0 -947
- package/dist/index.js +0 -768
- package/wasm/jww-parser.wasm +0 -0
- package/wasm/wasm_exec.js +0 -575
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A non-public unique symbol used to mark the brand of a type.
|
|
3
|
+
* And avoid user to construct values of the type.
|
|
4
|
+
*/
|
|
5
|
+
export const __brand: unique symbol;
|
|
6
|
+
|
|
7
|
+
export type Unit = undefined;
|
|
8
|
+
export type Bool = boolean;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A signed integer in 32-bit two's complement format.
|
|
12
|
+
*/
|
|
13
|
+
export type Int = number;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* An unsigned integer in 32-bit two's complement format.
|
|
17
|
+
*/
|
|
18
|
+
export type UInt = number;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A character in the range 0-0x10FFFF.
|
|
22
|
+
*/
|
|
23
|
+
export type Char = number;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A byte in the range 0-255.
|
|
27
|
+
*/
|
|
28
|
+
export type Byte = number;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Single-precision floating point number.
|
|
32
|
+
*/
|
|
33
|
+
export type Float = number;
|
|
34
|
+
|
|
35
|
+
export type Double = number;
|
|
36
|
+
|
|
37
|
+
export type Int64 = { [__brand]: 568910272 };
|
|
38
|
+
|
|
39
|
+
export type UInt64 = { [__brand]: 689305396 };
|
|
40
|
+
|
|
41
|
+
export type String = string;
|
|
42
|
+
|
|
43
|
+
export type Bytes = Uint8Array;
|
|
44
|
+
|
|
45
|
+
export type FixedArray<T> = T[];
|
|
46
|
+
|
|
47
|
+
export type UnboxedOption<T> =
|
|
48
|
+
| /* Some */ T
|
|
49
|
+
| /* None */ undefined;
|
|
50
|
+
|
|
51
|
+
export type UnboxedOptionAsInt<T> =
|
|
52
|
+
| /* Some */ T
|
|
53
|
+
| /* None */ -1;
|
|
54
|
+
|
|
55
|
+
export type Result<T, E> =
|
|
56
|
+
| /* Ok */ { $tag: 1, _0: T }
|
|
57
|
+
| /* Err */ { $tag: 0, _0: E };
|
package/package.json
CHANGED
|
@@ -1,54 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jww-parser",
|
|
3
|
-
"version": "2025.12.
|
|
4
|
-
"description": "JWW
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
3
|
+
"version": "2025.12.7",
|
|
4
|
+
"description": "JWW file parser and DXF converter powered by MoonBit",
|
|
5
|
+
"author": "f12o",
|
|
6
|
+
"license": "AGPL-3.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/f4ah6o/jww_parser.mbt.git"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"jww",
|
|
13
|
+
"dxf",
|
|
14
|
+
"cad",
|
|
15
|
+
"parser",
|
|
16
|
+
"converter",
|
|
17
|
+
"moonbit",
|
|
18
|
+
"webassembly"
|
|
19
|
+
],
|
|
20
|
+
"main": "./dist/index.cjs",
|
|
21
|
+
"module": "./dist/index.mjs",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
8
23
|
"exports": {
|
|
9
24
|
".": {
|
|
10
25
|
"types": "./dist/index.d.ts",
|
|
11
26
|
"import": "./dist/index.mjs",
|
|
12
|
-
"require": "./dist/index.
|
|
27
|
+
"require": "./dist/index.cjs"
|
|
13
28
|
}
|
|
14
29
|
},
|
|
15
30
|
"files": [
|
|
16
31
|
"dist",
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
"scripts": {
|
|
20
|
-
"build": "npm run build:wasm && npm run build:js",
|
|
21
|
-
"build:wasm": "mkdir -p wasm && cd .. && make build-wasm copy-wasm-exec && cp dist/jww-parser.wasm dist/wasm_exec.js npm/wasm/",
|
|
22
|
-
"build:js": "tsup src/index.ts --format cjs,esm --dts",
|
|
23
|
-
"prepublishOnly": "npm run build"
|
|
24
|
-
},
|
|
25
|
-
"keywords": [
|
|
26
|
-
"jww",
|
|
27
|
-
"jw-cad",
|
|
28
|
-
"jwcad",
|
|
29
|
-
"dxf",
|
|
30
|
-
"cad",
|
|
31
|
-
"converter",
|
|
32
|
-
"parser",
|
|
33
|
-
"webassembly",
|
|
34
|
-
"wasm"
|
|
32
|
+
"README.md",
|
|
33
|
+
"LICENSE"
|
|
35
34
|
],
|
|
36
|
-
"author": "f12o",
|
|
37
|
-
"license": "AGPL-3.0",
|
|
38
|
-
"repository": {
|
|
39
|
-
"type": "git",
|
|
40
|
-
"url": "git+https://github.com/f4ah6o/jww-parser.git"
|
|
41
|
-
},
|
|
42
|
-
"bugs": {
|
|
43
|
-
"url": "https://github.com/f4ah6o/jww-parser/issues"
|
|
44
|
-
},
|
|
45
|
-
"homepage": "https://github.com/f4ah6o/jww-parser#readme",
|
|
46
35
|
"devDependencies": {
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"typescript": "^5.3.0"
|
|
36
|
+
"rolldown": "^1.0.0-beta.57",
|
|
37
|
+
"typescript": "^5.9.3"
|
|
50
38
|
},
|
|
51
|
-
"
|
|
52
|
-
"
|
|
39
|
+
"scripts": {
|
|
40
|
+
"clean": "rm -rf target dist",
|
|
41
|
+
"build:moon": "moon build --target js",
|
|
42
|
+
"build:patch": "node scripts/patch-js.js",
|
|
43
|
+
"build:bundle": "rolldown -c rolldown.config.mjs",
|
|
44
|
+
"build:types": "mkdir -p dist && cp target/js/release/build/jww_parser.d.ts dist/index.d.ts && cp target/js/release/build/moonbit.d.ts dist/moonbit.d.ts",
|
|
45
|
+
"build": "pnpm run clean && pnpm run build:moon && pnpm run build:patch && pnpm run build:bundle && pnpm run build:types",
|
|
46
|
+
"set-version": "node scripts/sync-version.js && git add package.json moon.mod.json examples/package.json",
|
|
47
|
+
"release": "node scripts/release.js"
|
|
53
48
|
}
|
|
54
|
-
}
|
|
49
|
+
}
|
package/README.md
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
# jww-parser
|
|
2
|
-
|
|
3
|
-
JWW (Jw_cad) file parser and DXF converter for JavaScript/TypeScript.
|
|
4
|
-
|
|
5
|
-
This package uses WebAssembly to parse JWW binary files (created by [Jw_cad](https://www.jwcad.net/), a popular Japanese CAD software) and convert them to DXF format.
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install jww-parser
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
### Node.js
|
|
16
|
-
|
|
17
|
-
```typescript
|
|
18
|
-
import { createParser } from 'jww-parser';
|
|
19
|
-
import { readFileSync } from 'fs';
|
|
20
|
-
|
|
21
|
-
async function main() {
|
|
22
|
-
// Create and initialize the parser
|
|
23
|
-
const parser = await createParser();
|
|
24
|
-
|
|
25
|
-
// Read a JWW file
|
|
26
|
-
const jwwData = readFileSync('drawing.jww');
|
|
27
|
-
const data = new Uint8Array(jwwData);
|
|
28
|
-
|
|
29
|
-
// Parse JWW to get document structure
|
|
30
|
-
const doc = parser.parse(data);
|
|
31
|
-
console.log('Entities:', doc.Entities.length);
|
|
32
|
-
console.log('Layers:', doc.LayerGroups.length);
|
|
33
|
-
|
|
34
|
-
// Convert to DXF string
|
|
35
|
-
const dxfString = parser.toDxfString(data);
|
|
36
|
-
writeFileSync('output.dxf', dxfString);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
main();
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
### Browser
|
|
43
|
-
|
|
44
|
-
```html
|
|
45
|
-
<!-- Include wasm_exec.js from Go -->
|
|
46
|
-
<script src="wasm_exec.js"></script>
|
|
47
|
-
<script type="module">
|
|
48
|
-
import { createParser } from 'jww-parser';
|
|
49
|
-
|
|
50
|
-
async function convertFile(file) {
|
|
51
|
-
const parser = await createParser('path/to/jww-parser.wasm');
|
|
52
|
-
|
|
53
|
-
const buffer = await file.arrayBuffer();
|
|
54
|
-
const data = new Uint8Array(buffer);
|
|
55
|
-
|
|
56
|
-
// Get DXF content
|
|
57
|
-
const dxfString = parser.toDxfString(data);
|
|
58
|
-
|
|
59
|
-
// Download as file
|
|
60
|
-
const blob = new Blob([dxfString], { type: 'application/dxf' });
|
|
61
|
-
const url = URL.createObjectURL(blob);
|
|
62
|
-
const a = document.createElement('a');
|
|
63
|
-
a.href = url;
|
|
64
|
-
a.download = file.name.replace('.jww', '.dxf');
|
|
65
|
-
a.click();
|
|
66
|
-
}
|
|
67
|
-
</script>
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
## API
|
|
71
|
-
|
|
72
|
-
### `createParser(wasmPath?: string): Promise<JwwParser>`
|
|
73
|
-
|
|
74
|
-
Create and initialize a JWW parser instance.
|
|
75
|
-
|
|
76
|
-
- `wasmPath` - Optional path to the `jww-parser.wasm` file
|
|
77
|
-
|
|
78
|
-
### `JwwParser`
|
|
79
|
-
|
|
80
|
-
#### `init(): Promise<void>`
|
|
81
|
-
|
|
82
|
-
Initialize the WASM module. Called automatically by `createParser()`.
|
|
83
|
-
|
|
84
|
-
#### `parse(data: Uint8Array): JwwDocument`
|
|
85
|
-
|
|
86
|
-
Parse a JWW file and return the document structure.
|
|
87
|
-
|
|
88
|
-
#### `toDxf(data: Uint8Array): DxfDocument`
|
|
89
|
-
|
|
90
|
-
Parse a JWW file and convert to DXF document structure (JSON).
|
|
91
|
-
|
|
92
|
-
#### `toDxfString(data: Uint8Array): string`
|
|
93
|
-
|
|
94
|
-
Parse a JWW file and convert to DXF file content string.
|
|
95
|
-
|
|
96
|
-
## Types
|
|
97
|
-
|
|
98
|
-
### JwwDocument
|
|
99
|
-
|
|
100
|
-
```typescript
|
|
101
|
-
interface JwwDocument {
|
|
102
|
-
Version: number;
|
|
103
|
-
Memo: string;
|
|
104
|
-
PaperSize: number;
|
|
105
|
-
LayerGroups: LayerGroup[];
|
|
106
|
-
Entities: JwwEntity[];
|
|
107
|
-
Blocks: JwwBlock[];
|
|
108
|
-
}
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
### JwwEntity
|
|
112
|
-
|
|
113
|
-
Supported entity types:
|
|
114
|
-
- `JwwLine` - Line segments
|
|
115
|
-
- `JwwArc` - Arcs and circles
|
|
116
|
-
- `JwwPoint` - Points
|
|
117
|
-
- `JwwText` - Text annotations
|
|
118
|
-
- `JwwSolid` - Solid fills
|
|
119
|
-
- `JwwBlockRef` - Block references
|
|
120
|
-
|
|
121
|
-
### DxfDocument
|
|
122
|
-
|
|
123
|
-
```typescript
|
|
124
|
-
interface DxfDocument {
|
|
125
|
-
Layers: DxfLayer[];
|
|
126
|
-
Entities: DxfEntity[];
|
|
127
|
-
Blocks: DxfBlock[];
|
|
128
|
-
}
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
## Requirements
|
|
132
|
-
|
|
133
|
-
- Node.js >= 18.0.0 (for Node.js usage)
|
|
134
|
-
- Modern browser with WebAssembly support (for browser usage)
|
|
135
|
-
|
|
136
|
-
## License
|
|
137
|
-
|
|
138
|
-
AGPL-3.0
|