ducsvg 3.1.2 β 3.2.1
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 +1 -3
- package/dist/ducToSvg.d.ts +7 -1
- package/dist/index.js +6 -6
- package/dist/pdf2svg/index.d.ts +12 -0
- package/dist/pdf2svg.d.ts +39 -0
- package/dist/pdf2svg.js +198 -0
- package/dist/pdf2svg.js.br +0 -0
- package/dist/pdf2svg_bg.wasm +0 -0
- package/dist/pdf2svg_bg.wasm.br +0 -0
- package/dist/pdf2svg_bg.wasm.d.ts +9 -0
- package/dist/wasm.d.ts +2 -0
- package/package.json +15 -18
package/README.md
CHANGED
|
@@ -13,9 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
`ducsvg` is a lightweight adapter for rendering `duc` CAD documents to SVG. Itβs built on top of `ducjs` and focuses on accurate, standards-compliant SVG output you can embed in browsers or export from Node.js.
|
|
15
15
|
|
|
16
|
-
> This library leverages the stable renderer from `ducpdf`, first converting the `duc` document to PDF format before transforming it into SVG using `
|
|
17
|
-
|
|
18
|
-
> π‘ Maybe in the future we could refactor `ducpdf` to leverage the growing library [`hayro_svg`](https://docs.rs/hayro-svg/latest/hayro_svg/) to convert PDF to SVG more seamlessly instead of using `pdf-into-svg` (C# library). Reference: [hayro project](https://github.com/LaurenzV/hayro?tab=readme-ov-file)
|
|
16
|
+
> This library leverages the stable renderer from `ducpdf`, first converting the `duc` document to PDF format before transforming it into SVG using `hayro` and `hayro_svg`. This approach ensures high fidelity in the SVG output by utilizing the robust rendering capabilities of the PDF format.
|
|
19
17
|
|
|
20
18
|
## Documentation
|
|
21
19
|
|
package/dist/ducToSvg.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import { type ConversionOptions } from "ducpdf";
|
|
2
|
-
|
|
2
|
+
import { type SvgDocument } from "./pdf2svg";
|
|
3
|
+
export type { SvgDocument };
|
|
4
|
+
/**
|
|
5
|
+
* Convert DUC data to SVG pages.
|
|
6
|
+
* Uses ducpdf to convert DUC to PDF, then pdf2svg to convert PDF to SVG.
|
|
7
|
+
*/
|
|
8
|
+
export declare const ducToSvg: (ducData: Uint8Array, options?: ConversionOptions) => Promise<SvgDocument>;
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { convertDucToPdf as
|
|
2
|
-
import { convertPdfToSvg as
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
return await
|
|
1
|
+
import { convertDucToPdf as n } from "ducpdf";
|
|
2
|
+
import { convertPdfToSvg as r } from "./pdf2svg";
|
|
3
|
+
const v = async (o, t) => {
|
|
4
|
+
const c = await n(o, t);
|
|
5
|
+
return await r(c);
|
|
6
6
|
};
|
|
7
7
|
export {
|
|
8
|
-
|
|
8
|
+
v as ducToSvg
|
|
9
9
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface SvgPage {
|
|
2
|
+
svg: string;
|
|
3
|
+
}
|
|
4
|
+
export interface SvgDocument {
|
|
5
|
+
pages: SvgPage[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Convert PDF bytes to SVG pages using hayro-svg WASM.
|
|
9
|
+
*/
|
|
10
|
+
export declare function convertPdfToSvg(pdfData: Uint8Array): Promise<SvgDocument>;
|
|
11
|
+
export declare function isWasmInitialized(): boolean;
|
|
12
|
+
export declare function resetWasmModule(): void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* WASM binding: Convert PDF bytes to JSON array of SVG pages
|
|
5
|
+
*/
|
|
6
|
+
export function convert_pdf_to_svg_rs(pdf_data: Uint8Array): string;
|
|
7
|
+
|
|
8
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
9
|
+
|
|
10
|
+
export interface InitOutput {
|
|
11
|
+
readonly memory: WebAssembly.Memory;
|
|
12
|
+
readonly convert_pdf_to_svg_rs: (a: number, b: number) => [number, number, number, number];
|
|
13
|
+
readonly __wbindgen_export_0: WebAssembly.Table;
|
|
14
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
15
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
16
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
17
|
+
readonly __wbindgen_start: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
21
|
+
/**
|
|
22
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
23
|
+
* a precompiled `WebAssembly.Module`.
|
|
24
|
+
*
|
|
25
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
26
|
+
*
|
|
27
|
+
* @returns {InitOutput}
|
|
28
|
+
*/
|
|
29
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
33
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
34
|
+
*
|
|
35
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
36
|
+
*
|
|
37
|
+
* @returns {Promise<InitOutput>}
|
|
38
|
+
*/
|
|
39
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
package/dist/pdf2svg.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
let wasm;
|
|
2
|
+
|
|
3
|
+
let cachedUint8ArrayMemory0 = null;
|
|
4
|
+
|
|
5
|
+
function getUint8ArrayMemory0() {
|
|
6
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
7
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
8
|
+
}
|
|
9
|
+
return cachedUint8ArrayMemory0;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
13
|
+
|
|
14
|
+
cachedTextDecoder.decode();
|
|
15
|
+
|
|
16
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
17
|
+
let numBytesDecoded = 0;
|
|
18
|
+
function decodeText(ptr, len) {
|
|
19
|
+
numBytesDecoded += len;
|
|
20
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
21
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
22
|
+
cachedTextDecoder.decode();
|
|
23
|
+
numBytesDecoded = len;
|
|
24
|
+
}
|
|
25
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getStringFromWasm0(ptr, len) {
|
|
29
|
+
ptr = ptr >>> 0;
|
|
30
|
+
return decodeText(ptr, len);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let WASM_VECTOR_LEN = 0;
|
|
34
|
+
|
|
35
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
36
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
37
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
38
|
+
WASM_VECTOR_LEN = arg.length;
|
|
39
|
+
return ptr;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function takeFromExternrefTable0(idx) {
|
|
43
|
+
const value = wasm.__wbindgen_export_0.get(idx);
|
|
44
|
+
wasm.__externref_table_dealloc(idx);
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* WASM binding: Convert PDF bytes to JSON array of SVG pages
|
|
49
|
+
* @param {Uint8Array} pdf_data
|
|
50
|
+
* @returns {string}
|
|
51
|
+
*/
|
|
52
|
+
export function convert_pdf_to_svg_rs(pdf_data) {
|
|
53
|
+
let deferred3_0;
|
|
54
|
+
let deferred3_1;
|
|
55
|
+
try {
|
|
56
|
+
const ptr0 = passArray8ToWasm0(pdf_data, wasm.__wbindgen_malloc);
|
|
57
|
+
const len0 = WASM_VECTOR_LEN;
|
|
58
|
+
const ret = wasm.convert_pdf_to_svg_rs(ptr0, len0);
|
|
59
|
+
var ptr2 = ret[0];
|
|
60
|
+
var len2 = ret[1];
|
|
61
|
+
if (ret[3]) {
|
|
62
|
+
ptr2 = 0; len2 = 0;
|
|
63
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
64
|
+
}
|
|
65
|
+
deferred3_0 = ptr2;
|
|
66
|
+
deferred3_1 = len2;
|
|
67
|
+
return getStringFromWasm0(ptr2, len2);
|
|
68
|
+
} finally {
|
|
69
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
|
|
74
|
+
|
|
75
|
+
async function __wbg_load(module, imports) {
|
|
76
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
77
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
78
|
+
try {
|
|
79
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
80
|
+
|
|
81
|
+
} catch (e) {
|
|
82
|
+
const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
|
|
83
|
+
|
|
84
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
85
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
86
|
+
|
|
87
|
+
} else {
|
|
88
|
+
throw e;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const bytes = await module.arrayBuffer();
|
|
94
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
95
|
+
|
|
96
|
+
} else {
|
|
97
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
98
|
+
|
|
99
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
100
|
+
return { instance, module };
|
|
101
|
+
|
|
102
|
+
} else {
|
|
103
|
+
return instance;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function __wbg_get_imports() {
|
|
109
|
+
const imports = {};
|
|
110
|
+
imports.wbg = {};
|
|
111
|
+
imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
|
|
112
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
113
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
114
|
+
return ret;
|
|
115
|
+
};
|
|
116
|
+
imports.wbg.__wbindgen_init_externref_table = function() {
|
|
117
|
+
const table = wasm.__wbindgen_export_0;
|
|
118
|
+
const offset = table.grow(4);
|
|
119
|
+
table.set(0, undefined);
|
|
120
|
+
table.set(offset + 0, undefined);
|
|
121
|
+
table.set(offset + 1, null);
|
|
122
|
+
table.set(offset + 2, true);
|
|
123
|
+
table.set(offset + 3, false);
|
|
124
|
+
;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
return imports;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function __wbg_init_memory(imports, memory) {
|
|
131
|
+
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function __wbg_finalize_init(instance, module) {
|
|
135
|
+
wasm = instance.exports;
|
|
136
|
+
__wbg_init.__wbindgen_wasm_module = module;
|
|
137
|
+
cachedUint8ArrayMemory0 = null;
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
wasm.__wbindgen_start();
|
|
141
|
+
return wasm;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function initSync(module) {
|
|
145
|
+
if (wasm !== undefined) return wasm;
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
if (typeof module !== 'undefined') {
|
|
149
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
150
|
+
({module} = module)
|
|
151
|
+
} else {
|
|
152
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const imports = __wbg_get_imports();
|
|
157
|
+
|
|
158
|
+
__wbg_init_memory(imports);
|
|
159
|
+
|
|
160
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
161
|
+
module = new WebAssembly.Module(module);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
165
|
+
|
|
166
|
+
return __wbg_finalize_init(instance, module);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function __wbg_init(module_or_path) {
|
|
170
|
+
if (wasm !== undefined) return wasm;
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
if (typeof module_or_path !== 'undefined') {
|
|
174
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
175
|
+
({module_or_path} = module_or_path)
|
|
176
|
+
} else {
|
|
177
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (typeof module_or_path === 'undefined') {
|
|
182
|
+
module_or_path = new URL('pdf2svg_bg.wasm', import.meta.url);
|
|
183
|
+
}
|
|
184
|
+
const imports = __wbg_get_imports();
|
|
185
|
+
|
|
186
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
187
|
+
module_or_path = fetch(module_or_path);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
__wbg_init_memory(imports);
|
|
191
|
+
|
|
192
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
193
|
+
|
|
194
|
+
return __wbg_finalize_init(instance, module);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export { initSync };
|
|
198
|
+
export default __wbg_init;
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const convert_pdf_to_svg_rs: (a: number, b: number) => [number, number, number, number];
|
|
5
|
+
export const __wbindgen_export_0: WebAssembly.Table;
|
|
6
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
7
|
+
export const __externref_table_dealloc: (a: number) => void;
|
|
8
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
9
|
+
export const __wbindgen_start: () => void;
|
package/dist/wasm.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ducsvg",
|
|
3
|
-
"version": "3.1
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "Adapter for converting duc CAD documents to SVG. Built on top of ducjs.",
|
|
5
|
+
"private": false,
|
|
6
|
+
"type": "module",
|
|
5
7
|
"main": "dist/index.js",
|
|
6
8
|
"module": "dist/index.js",
|
|
7
9
|
"types": "dist/index.d.ts",
|
|
@@ -9,26 +11,21 @@
|
|
|
9
11
|
".": {
|
|
10
12
|
"types": "./dist/index.d.ts",
|
|
11
13
|
"import": "./dist/index.js",
|
|
12
|
-
"
|
|
14
|
+
"default": "./dist/index.js"
|
|
13
15
|
},
|
|
14
|
-
"
|
|
15
|
-
"types":
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
],
|
|
19
|
-
"import": [
|
|
20
|
-
"./dist/*.js",
|
|
21
|
-
"./dist/*/index.js"
|
|
22
|
-
],
|
|
23
|
-
"require": [
|
|
24
|
-
"./dist/*.js",
|
|
25
|
-
"./dist/*/index.js"
|
|
26
|
-
]
|
|
16
|
+
"./pkg": {
|
|
17
|
+
"types": "./pkg/pdf2svg.d.ts",
|
|
18
|
+
"import": "./pkg/pdf2svg.js",
|
|
19
|
+
"default": "./pkg/pdf2svg.js"
|
|
27
20
|
}
|
|
28
21
|
},
|
|
29
22
|
"sideEffects": false,
|
|
30
23
|
"scripts": {
|
|
31
|
-
"build": "
|
|
24
|
+
"build": "bun run clean && bun run build:wasm && bun run copy:wasm-to-dist && bun run build:ts",
|
|
25
|
+
"build:ts": "vite build && pwd && tsc -p tsconfig.json",
|
|
26
|
+
"build:wasm": "cd src/pdf2svg && wasm-pack build --target web --out-dir ../../pkg --release",
|
|
27
|
+
"copy:wasm-to-dist": "mkdir -p dist && cp pkg/pdf2svg_bg.wasm dist/ && cp pkg/pdf2svg.js dist/ && cp pkg/pdf2svg.d.ts dist/ && cp pkg/pdf2svg_bg.wasm.d.ts dist/",
|
|
28
|
+
"clean": "rm -rf dist pkg && cd src/pdf2svg && cargo clean",
|
|
32
29
|
"check-types": "tsc --noEmit",
|
|
33
30
|
"test": "bun test",
|
|
34
31
|
"semantic-release": "semantic-release"
|
|
@@ -37,8 +34,7 @@
|
|
|
37
34
|
"license": "MIT",
|
|
38
35
|
"dependencies": {
|
|
39
36
|
"ducjs": "^2.2.2",
|
|
40
|
-
"ducpdf": "^2.
|
|
41
|
-
"pdf-into-svg": "1.0.1"
|
|
37
|
+
"ducpdf": "^3.2.1"
|
|
42
38
|
},
|
|
43
39
|
"devDependencies": {
|
|
44
40
|
"@xmldom/xmldom": "^0.8.11",
|
|
@@ -46,6 +42,7 @@
|
|
|
46
42
|
"semantic-release": "^24.1.2",
|
|
47
43
|
"typescript": "^5.8.3",
|
|
48
44
|
"vite": "^6.0.0",
|
|
45
|
+
"vite-plugin-compression": "^0.5.1",
|
|
49
46
|
"vitest": "^3.2.4"
|
|
50
47
|
},
|
|
51
48
|
"files": [
|