jww-parser 2025.12.2 → 2025.12.4
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/dist/index.d.ts +809 -30
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +845 -166
- package/package.json +3 -3
- package/wasm/jww-parser.wasm +0 -0
- package/dist/index.d.mts +0 -168
- package/dist/index.mjs +0 -130
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jww-parser",
|
|
3
|
-
"version": "2025.12.
|
|
3
|
+
"version": "2025.12.4",
|
|
4
4
|
"description": "JWW (Jw_cad) file parser and DXF converter for JavaScript/TypeScript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"wasm"
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
|
+
"build:wasm": "make -C .. build-wasm copy-wasm-exec && mkdir -p wasm && rm -f wasm/wasm_exec.js wasm/jww-parser.wasm && cp ../dist/jww-parser.wasm ../dist/wasm_exec.js wasm/",
|
|
21
|
+
"build:js": "tsc",
|
|
20
22
|
"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
23
|
"prepublishOnly": "npm run build"
|
|
24
24
|
},
|
|
25
25
|
"keywords": [
|
package/wasm/jww-parser.wasm
CHANGED
|
Binary file
|
package/dist/index.d.mts
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* JWW (Jw_cad) file parser and DXF converter
|
|
3
|
-
*
|
|
4
|
-
* This module provides functionality to parse JWW binary files
|
|
5
|
-
* and convert them to DXF format using WebAssembly.
|
|
6
|
-
*/
|
|
7
|
-
interface JwwDocument {
|
|
8
|
-
Version: number;
|
|
9
|
-
Memo: string;
|
|
10
|
-
PaperSize: number;
|
|
11
|
-
LayerGroups: LayerGroup[];
|
|
12
|
-
Entities: JwwEntity[];
|
|
13
|
-
Blocks: JwwBlock[];
|
|
14
|
-
}
|
|
15
|
-
interface LayerGroup {
|
|
16
|
-
Name: string;
|
|
17
|
-
Layers: Layer[];
|
|
18
|
-
}
|
|
19
|
-
interface Layer {
|
|
20
|
-
Name: string;
|
|
21
|
-
Visible: boolean;
|
|
22
|
-
Locked: boolean;
|
|
23
|
-
}
|
|
24
|
-
interface JwwEntityBase {
|
|
25
|
-
Type: string;
|
|
26
|
-
Group: number;
|
|
27
|
-
PenStyle: number;
|
|
28
|
-
PenColor: number;
|
|
29
|
-
PenWidth: number;
|
|
30
|
-
Layer: number;
|
|
31
|
-
LayerGroup: number;
|
|
32
|
-
}
|
|
33
|
-
interface JwwLine extends JwwEntityBase {
|
|
34
|
-
Type: "Line";
|
|
35
|
-
X1: number;
|
|
36
|
-
Y1: number;
|
|
37
|
-
X2: number;
|
|
38
|
-
Y2: number;
|
|
39
|
-
}
|
|
40
|
-
interface JwwArc extends JwwEntityBase {
|
|
41
|
-
Type: "Arc";
|
|
42
|
-
CenterX: number;
|
|
43
|
-
CenterY: number;
|
|
44
|
-
Radius: number;
|
|
45
|
-
StartAngle: number;
|
|
46
|
-
EndAngle: number;
|
|
47
|
-
Flatness: number;
|
|
48
|
-
}
|
|
49
|
-
interface JwwPoint extends JwwEntityBase {
|
|
50
|
-
Type: "Point";
|
|
51
|
-
X: number;
|
|
52
|
-
Y: number;
|
|
53
|
-
Code: number;
|
|
54
|
-
}
|
|
55
|
-
interface JwwText extends JwwEntityBase {
|
|
56
|
-
Type: "Text";
|
|
57
|
-
X: number;
|
|
58
|
-
Y: number;
|
|
59
|
-
Text: string;
|
|
60
|
-
FontName: string;
|
|
61
|
-
Height: number;
|
|
62
|
-
Width: number;
|
|
63
|
-
Angle: number;
|
|
64
|
-
}
|
|
65
|
-
interface JwwSolid extends JwwEntityBase {
|
|
66
|
-
Type: "Solid";
|
|
67
|
-
Points: [number, number][];
|
|
68
|
-
}
|
|
69
|
-
interface JwwBlockRef extends JwwEntityBase {
|
|
70
|
-
Type: "Block";
|
|
71
|
-
X: number;
|
|
72
|
-
Y: number;
|
|
73
|
-
ScaleX: number;
|
|
74
|
-
ScaleY: number;
|
|
75
|
-
Angle: number;
|
|
76
|
-
BlockNumber: number;
|
|
77
|
-
}
|
|
78
|
-
type JwwEntity = JwwLine | JwwArc | JwwPoint | JwwText | JwwSolid | JwwBlockRef;
|
|
79
|
-
interface JwwBlock {
|
|
80
|
-
Name: string;
|
|
81
|
-
Entities: JwwEntity[];
|
|
82
|
-
}
|
|
83
|
-
interface DxfDocument {
|
|
84
|
-
Layers: DxfLayer[];
|
|
85
|
-
Entities: DxfEntity[];
|
|
86
|
-
Blocks: DxfBlock[];
|
|
87
|
-
}
|
|
88
|
-
interface DxfLayer {
|
|
89
|
-
Name: string;
|
|
90
|
-
Color: number;
|
|
91
|
-
Frozen: boolean;
|
|
92
|
-
Locked: boolean;
|
|
93
|
-
}
|
|
94
|
-
interface DxfEntity {
|
|
95
|
-
Type: string;
|
|
96
|
-
Layer: string;
|
|
97
|
-
Color?: number;
|
|
98
|
-
[key: string]: unknown;
|
|
99
|
-
}
|
|
100
|
-
interface DxfBlock {
|
|
101
|
-
Name: string;
|
|
102
|
-
Entities: DxfEntity[];
|
|
103
|
-
}
|
|
104
|
-
interface WasmResult {
|
|
105
|
-
ok: boolean;
|
|
106
|
-
data?: string;
|
|
107
|
-
error?: string;
|
|
108
|
-
}
|
|
109
|
-
declare global {
|
|
110
|
-
var Go: new () => GoInstance;
|
|
111
|
-
var jwwParse: (data: Uint8Array) => WasmResult;
|
|
112
|
-
var jwwToDxf: (data: Uint8Array) => WasmResult;
|
|
113
|
-
var jwwToDxfString: (data: Uint8Array) => WasmResult;
|
|
114
|
-
}
|
|
115
|
-
interface GoInstance {
|
|
116
|
-
importObject: WebAssembly.Imports;
|
|
117
|
-
run(instance: WebAssembly.Instance): Promise<void>;
|
|
118
|
-
}
|
|
119
|
-
declare class JwwParser {
|
|
120
|
-
private initialized;
|
|
121
|
-
private initPromise;
|
|
122
|
-
private wasmPath;
|
|
123
|
-
/**
|
|
124
|
-
* Create a new JWW parser instance
|
|
125
|
-
* @param wasmPath - Path to the jww-parser.wasm file
|
|
126
|
-
*/
|
|
127
|
-
constructor(wasmPath?: string);
|
|
128
|
-
private getDefaultWasmPath;
|
|
129
|
-
/**
|
|
130
|
-
* Initialize the WASM module
|
|
131
|
-
* Must be called before using parse methods
|
|
132
|
-
*/
|
|
133
|
-
init(): Promise<void>;
|
|
134
|
-
private loadWasm;
|
|
135
|
-
private loadWasmExec;
|
|
136
|
-
private waitForWasmFunctions;
|
|
137
|
-
private ensureInitialized;
|
|
138
|
-
/**
|
|
139
|
-
* Parse a JWW file and return the document structure
|
|
140
|
-
* @param data - JWW file content as Uint8Array
|
|
141
|
-
* @returns Parsed JWW document
|
|
142
|
-
*/
|
|
143
|
-
parse(data: Uint8Array): JwwDocument;
|
|
144
|
-
/**
|
|
145
|
-
* Parse a JWW file and convert to DXF document structure
|
|
146
|
-
* @param data - JWW file content as Uint8Array
|
|
147
|
-
* @returns DXF document object
|
|
148
|
-
*/
|
|
149
|
-
toDxf(data: Uint8Array): DxfDocument;
|
|
150
|
-
/**
|
|
151
|
-
* Parse a JWW file and convert to DXF file content string
|
|
152
|
-
* @param data - JWW file content as Uint8Array
|
|
153
|
-
* @returns DXF file content as string
|
|
154
|
-
*/
|
|
155
|
-
toDxfString(data: Uint8Array): string;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Create and initialize a JWW parser instance
|
|
159
|
-
* @param wasmPath - Optional path to the jww-parser.wasm file
|
|
160
|
-
* @returns Initialized JwwParser instance
|
|
161
|
-
*/
|
|
162
|
-
declare function createParser(wasmPath?: string): Promise<JwwParser>;
|
|
163
|
-
declare const _default: {
|
|
164
|
-
JwwParser: typeof JwwParser;
|
|
165
|
-
createParser: typeof createParser;
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
export { type DxfBlock, type DxfDocument, type DxfEntity, type DxfLayer, type JwwArc, type JwwBlock, type JwwBlockRef, type JwwDocument, type JwwEntity, type JwwEntityBase, type JwwLine, JwwParser, type JwwPoint, type JwwSolid, type JwwText, type Layer, type LayerGroup, createParser, _default as default };
|
package/dist/index.mjs
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
var JwwParser = class {
|
|
3
|
-
/**
|
|
4
|
-
* Create a new JWW parser instance
|
|
5
|
-
* @param wasmPath - Path to the jww-parser.wasm file
|
|
6
|
-
*/
|
|
7
|
-
constructor(wasmPath) {
|
|
8
|
-
this.initialized = false;
|
|
9
|
-
this.initPromise = null;
|
|
10
|
-
this.wasmPath = wasmPath || this.getDefaultWasmPath();
|
|
11
|
-
}
|
|
12
|
-
getDefaultWasmPath() {
|
|
13
|
-
if (typeof process !== "undefined" && process.versions?.node) {
|
|
14
|
-
return new URL("../wasm/jww-parser.wasm", import.meta.url).pathname;
|
|
15
|
-
}
|
|
16
|
-
return "jww-parser.wasm";
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Initialize the WASM module
|
|
20
|
-
* Must be called before using parse methods
|
|
21
|
-
*/
|
|
22
|
-
async init() {
|
|
23
|
-
if (this.initialized) return;
|
|
24
|
-
if (this.initPromise) return this.initPromise;
|
|
25
|
-
this.initPromise = this.loadWasm();
|
|
26
|
-
await this.initPromise;
|
|
27
|
-
this.initialized = true;
|
|
28
|
-
}
|
|
29
|
-
async loadWasm() {
|
|
30
|
-
if (typeof Go === "undefined") {
|
|
31
|
-
await this.loadWasmExec();
|
|
32
|
-
}
|
|
33
|
-
const go = new Go();
|
|
34
|
-
let wasmInstance;
|
|
35
|
-
if (typeof process !== "undefined" && process.versions?.node) {
|
|
36
|
-
const fs = await import("fs");
|
|
37
|
-
const path = await import("path");
|
|
38
|
-
const wasmBuffer = fs.readFileSync(this.wasmPath);
|
|
39
|
-
const wasmModule = await WebAssembly.compile(wasmBuffer);
|
|
40
|
-
wasmInstance = await WebAssembly.instantiate(wasmModule, go.importObject);
|
|
41
|
-
} else {
|
|
42
|
-
const result = await WebAssembly.instantiateStreaming(
|
|
43
|
-
fetch(this.wasmPath),
|
|
44
|
-
go.importObject
|
|
45
|
-
).catch(async () => {
|
|
46
|
-
const response = await fetch(this.wasmPath);
|
|
47
|
-
const bytes = await response.arrayBuffer();
|
|
48
|
-
return WebAssembly.instantiate(bytes, go.importObject);
|
|
49
|
-
});
|
|
50
|
-
wasmInstance = result.instance;
|
|
51
|
-
}
|
|
52
|
-
go.run(wasmInstance);
|
|
53
|
-
await this.waitForWasmFunctions();
|
|
54
|
-
}
|
|
55
|
-
async loadWasmExec() {
|
|
56
|
-
if (typeof process !== "undefined" && process.versions?.node) {
|
|
57
|
-
const wasmExecPath = new URL("../wasm/wasm_exec.js", import.meta.url).pathname;
|
|
58
|
-
await import(wasmExecPath);
|
|
59
|
-
} else {
|
|
60
|
-
throw new Error(
|
|
61
|
-
"Go runtime not loaded. Please include wasm_exec.js in your HTML."
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
async waitForWasmFunctions(timeout = 5e3, interval = 50) {
|
|
66
|
-
const start = Date.now();
|
|
67
|
-
while (Date.now() - start < timeout) {
|
|
68
|
-
if (typeof globalThis.jwwParse === "function" && typeof globalThis.jwwToDxf === "function" && typeof globalThis.jwwToDxfString === "function") {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
72
|
-
}
|
|
73
|
-
throw new Error("WASM functions not available after timeout");
|
|
74
|
-
}
|
|
75
|
-
ensureInitialized() {
|
|
76
|
-
if (!this.initialized) {
|
|
77
|
-
throw new Error("Parser not initialized. Call init() first.");
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Parse a JWW file and return the document structure
|
|
82
|
-
* @param data - JWW file content as Uint8Array
|
|
83
|
-
* @returns Parsed JWW document
|
|
84
|
-
*/
|
|
85
|
-
parse(data) {
|
|
86
|
-
this.ensureInitialized();
|
|
87
|
-
const result = globalThis.jwwParse(data);
|
|
88
|
-
if (!result.ok) {
|
|
89
|
-
throw new Error(result.error || "Parse failed");
|
|
90
|
-
}
|
|
91
|
-
return JSON.parse(result.data);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Parse a JWW file and convert to DXF document structure
|
|
95
|
-
* @param data - JWW file content as Uint8Array
|
|
96
|
-
* @returns DXF document object
|
|
97
|
-
*/
|
|
98
|
-
toDxf(data) {
|
|
99
|
-
this.ensureInitialized();
|
|
100
|
-
const result = globalThis.jwwToDxf(data);
|
|
101
|
-
if (!result.ok) {
|
|
102
|
-
throw new Error(result.error || "Conversion failed");
|
|
103
|
-
}
|
|
104
|
-
return JSON.parse(result.data);
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Parse a JWW file and convert to DXF file content string
|
|
108
|
-
* @param data - JWW file content as Uint8Array
|
|
109
|
-
* @returns DXF file content as string
|
|
110
|
-
*/
|
|
111
|
-
toDxfString(data) {
|
|
112
|
-
this.ensureInitialized();
|
|
113
|
-
const result = globalThis.jwwToDxfString(data);
|
|
114
|
-
if (!result.ok) {
|
|
115
|
-
throw new Error(result.error || "Conversion failed");
|
|
116
|
-
}
|
|
117
|
-
return result.data;
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
async function createParser(wasmPath) {
|
|
121
|
-
const parser = new JwwParser(wasmPath);
|
|
122
|
-
await parser.init();
|
|
123
|
-
return parser;
|
|
124
|
-
}
|
|
125
|
-
var index_default = { JwwParser, createParser };
|
|
126
|
-
export {
|
|
127
|
-
JwwParser,
|
|
128
|
-
createParser,
|
|
129
|
-
index_default as default
|
|
130
|
-
};
|