kymostudio-core 0.3.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/README.md +65 -0
- package/kymostudio_core.d.ts +45 -0
- package/kymostudio_core.js +235 -0
- package/kymostudio_core_bg.wasm +0 -0
- package/package.json +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# kymostudio-core (Rust)
|
|
2
|
+
|
|
3
|
+
Pure-Rust SVG → PNG rasterizer core for **kymostudio**, built on
|
|
4
|
+
[`resvg`](https://github.com/linebender/resvg). No browser, no headless Chrome,
|
|
5
|
+
no C/Cairo/Skia system dependencies.
|
|
6
|
+
|
|
7
|
+
One core crate, compiled to **four targets** from a single source via feature
|
|
8
|
+
flags — so the Rust CLI, the Python package, and the JS/browser playground all
|
|
9
|
+
share the exact same resvg engine (`resvg` is **CSS-class-aware**, the reason the
|
|
10
|
+
project avoids cairosvg):
|
|
11
|
+
|
|
12
|
+
| Target | Feature | Build tool | Consumer |
|
|
13
|
+
|--------|---------|-----------|----------|
|
|
14
|
+
| Native lib + `kymo` CLI | `system-fonts` (default) | `cargo` | standalone CLI |
|
|
15
|
+
| Python extension (abi3) | `python` | `maturin` → wheel | `packages/python` |
|
|
16
|
+
| wasm (browser + Node) | `wasm` | `wasm-pack` → pkg | `packages/js`, website playground |
|
|
17
|
+
|
|
18
|
+
`svg_to_png(svg: &[u8], scale: f32) -> Result<Vec<u8>, RenderError>` is the one
|
|
19
|
+
core function; each binding (`src/python.rs`, `src/wasm.rs`) is a thin façade.
|
|
20
|
+
|
|
21
|
+
## CLI — `kymo`
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
kymo -i in.svg out.png # rasterize at intrinsic size
|
|
25
|
+
kymo -i diagram.svg # output defaults to diagram.png
|
|
26
|
+
kymo -i diagram.svg -s 2 hi.png # 2× resolution
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
| Flag | Meaning |
|
|
30
|
+
|------|---------|
|
|
31
|
+
| `-i, --input <FILE>` | Input SVG (required) |
|
|
32
|
+
| `-o, --output <FILE>` | Output PNG (or pass it positionally) |
|
|
33
|
+
| `-s, --scale <N>` | Scale factor, `1.0` = intrinsic size (default `1`) |
|
|
34
|
+
| `-h, --help` / `-V, --version` | Help / version |
|
|
35
|
+
|
|
36
|
+
## Build each target
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Native (CLI + lib + tests)
|
|
40
|
+
cargo test
|
|
41
|
+
cargo build --release --bin kymo # -> target/release/kymo
|
|
42
|
+
|
|
43
|
+
# Python wheel (abi3, one wheel for CPython ≥ 3.10)
|
|
44
|
+
maturin build --release --out dist # -> dist/kymostudio_core-*-abi3-*.whl
|
|
45
|
+
# import _kymostudio_core; _kymostudio_core.svg_to_png(svg_bytes, scale)
|
|
46
|
+
|
|
47
|
+
# wasm (browser + Node) — system-fonts OFF (no fs/mmap on wasm)
|
|
48
|
+
wasm-pack build --target web --out-dir pkg --out-name kymostudio_core \
|
|
49
|
+
-- --no-default-features --features wasm
|
|
50
|
+
# import { svgToPng } from './pkg/kymostudio_core.js'
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
CI builds and smoke-tests all of the above across Linux/macOS/Windows —
|
|
54
|
+
see `.github/workflows/rust.yml`.
|
|
55
|
+
|
|
56
|
+
## Library use (Rust)
|
|
57
|
+
|
|
58
|
+
```rust
|
|
59
|
+
let svg = std::fs::read("in.svg")?;
|
|
60
|
+
let png: Vec<u8> = kymostudio_core::svg_to_png(&svg, 1.0)?;
|
|
61
|
+
std::fs::write("out.png", png)?;
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The version is kept in **lockstep** with the rest of the monorepo
|
|
65
|
+
(`Cargo.toml` → `version`).
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Rasterize `svg` bytes to PNG bytes at `scale` (1.0 = intrinsic size).
|
|
6
|
+
*/
|
|
7
|
+
export function svgToPng(svg: Uint8Array, scale?: number | null): Uint8Array;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The crate version, exposed to JS as `version()`.
|
|
11
|
+
*/
|
|
12
|
+
export function version(): string;
|
|
13
|
+
|
|
14
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
15
|
+
|
|
16
|
+
export interface InitOutput {
|
|
17
|
+
readonly memory: WebAssembly.Memory;
|
|
18
|
+
readonly svgToPng: (a: number, b: number, c: number, d: number) => void;
|
|
19
|
+
readonly version: (a: number) => void;
|
|
20
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
21
|
+
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
22
|
+
readonly __wbindgen_export2: (a: number, b: number, c: number) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
29
|
+
* a precompiled `WebAssembly.Module`.
|
|
30
|
+
*
|
|
31
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
32
|
+
*
|
|
33
|
+
* @returns {InitOutput}
|
|
34
|
+
*/
|
|
35
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
39
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
40
|
+
*
|
|
41
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
42
|
+
*
|
|
43
|
+
* @returns {Promise<InitOutput>}
|
|
44
|
+
*/
|
|
45
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/* @ts-self-types="./kymostudio_core.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Rasterize `svg` bytes to PNG bytes at `scale` (1.0 = intrinsic size).
|
|
5
|
+
* @param {Uint8Array} svg
|
|
6
|
+
* @param {number | null} [scale]
|
|
7
|
+
* @returns {Uint8Array}
|
|
8
|
+
*/
|
|
9
|
+
export function svgToPng(svg, scale) {
|
|
10
|
+
try {
|
|
11
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
12
|
+
const ptr0 = passArray8ToWasm0(svg, wasm.__wbindgen_export);
|
|
13
|
+
const len0 = WASM_VECTOR_LEN;
|
|
14
|
+
wasm.svgToPng(retptr, ptr0, len0, isLikeNone(scale) ? Number.MAX_SAFE_INTEGER : Math.fround(scale));
|
|
15
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
16
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
17
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
18
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
19
|
+
if (r3) {
|
|
20
|
+
throw takeObject(r2);
|
|
21
|
+
}
|
|
22
|
+
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
23
|
+
wasm.__wbindgen_export2(r0, r1 * 1, 1);
|
|
24
|
+
return v2;
|
|
25
|
+
} finally {
|
|
26
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The crate version, exposed to JS as `version()`.
|
|
32
|
+
* @returns {string}
|
|
33
|
+
*/
|
|
34
|
+
export function version() {
|
|
35
|
+
let deferred1_0;
|
|
36
|
+
let deferred1_1;
|
|
37
|
+
try {
|
|
38
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
39
|
+
wasm.version(retptr);
|
|
40
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
41
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
42
|
+
deferred1_0 = r0;
|
|
43
|
+
deferred1_1 = r1;
|
|
44
|
+
return getStringFromWasm0(r0, r1);
|
|
45
|
+
} finally {
|
|
46
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
47
|
+
wasm.__wbindgen_export2(deferred1_0, deferred1_1, 1);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function __wbg_get_imports() {
|
|
51
|
+
const import0 = {
|
|
52
|
+
__proto__: null,
|
|
53
|
+
__wbg_Error_ef53bc310eb298a0: function(arg0, arg1) {
|
|
54
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
55
|
+
return addHeapObject(ret);
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
__proto__: null,
|
|
60
|
+
"./kymostudio_core_bg.js": import0,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function addHeapObject(obj) {
|
|
65
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
66
|
+
const idx = heap_next;
|
|
67
|
+
heap_next = heap[idx];
|
|
68
|
+
|
|
69
|
+
heap[idx] = obj;
|
|
70
|
+
return idx;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function dropObject(idx) {
|
|
74
|
+
if (idx < 1028) return;
|
|
75
|
+
heap[idx] = heap_next;
|
|
76
|
+
heap_next = idx;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
80
|
+
ptr = ptr >>> 0;
|
|
81
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let cachedDataViewMemory0 = null;
|
|
85
|
+
function getDataViewMemory0() {
|
|
86
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
87
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
88
|
+
}
|
|
89
|
+
return cachedDataViewMemory0;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function getStringFromWasm0(ptr, len) {
|
|
93
|
+
return decodeText(ptr >>> 0, len);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let cachedUint8ArrayMemory0 = null;
|
|
97
|
+
function getUint8ArrayMemory0() {
|
|
98
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
99
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
100
|
+
}
|
|
101
|
+
return cachedUint8ArrayMemory0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function getObject(idx) { return heap[idx]; }
|
|
105
|
+
|
|
106
|
+
let heap = new Array(1024).fill(undefined);
|
|
107
|
+
heap.push(undefined, null, true, false);
|
|
108
|
+
|
|
109
|
+
let heap_next = heap.length;
|
|
110
|
+
|
|
111
|
+
function isLikeNone(x) {
|
|
112
|
+
return x === undefined || x === null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
116
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
117
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
118
|
+
WASM_VECTOR_LEN = arg.length;
|
|
119
|
+
return ptr;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function takeObject(idx) {
|
|
123
|
+
const ret = getObject(idx);
|
|
124
|
+
dropObject(idx);
|
|
125
|
+
return ret;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
129
|
+
cachedTextDecoder.decode();
|
|
130
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
131
|
+
let numBytesDecoded = 0;
|
|
132
|
+
function decodeText(ptr, len) {
|
|
133
|
+
numBytesDecoded += len;
|
|
134
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
135
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
136
|
+
cachedTextDecoder.decode();
|
|
137
|
+
numBytesDecoded = len;
|
|
138
|
+
}
|
|
139
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
let WASM_VECTOR_LEN = 0;
|
|
143
|
+
|
|
144
|
+
let wasmModule, wasmInstance, wasm;
|
|
145
|
+
function __wbg_finalize_init(instance, module) {
|
|
146
|
+
wasmInstance = instance;
|
|
147
|
+
wasm = instance.exports;
|
|
148
|
+
wasmModule = module;
|
|
149
|
+
cachedDataViewMemory0 = null;
|
|
150
|
+
cachedUint8ArrayMemory0 = null;
|
|
151
|
+
return wasm;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async function __wbg_load(module, imports) {
|
|
155
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
156
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
157
|
+
try {
|
|
158
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
159
|
+
} catch (e) {
|
|
160
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
161
|
+
|
|
162
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
163
|
+
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);
|
|
164
|
+
|
|
165
|
+
} else { throw e; }
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const bytes = await module.arrayBuffer();
|
|
170
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
171
|
+
} else {
|
|
172
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
173
|
+
|
|
174
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
175
|
+
return { instance, module };
|
|
176
|
+
} else {
|
|
177
|
+
return instance;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function expectedResponseType(type) {
|
|
182
|
+
switch (type) {
|
|
183
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
184
|
+
}
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function initSync(module) {
|
|
190
|
+
if (wasm !== undefined) return wasm;
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
if (module !== undefined) {
|
|
194
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
195
|
+
({module} = module)
|
|
196
|
+
} else {
|
|
197
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const imports = __wbg_get_imports();
|
|
202
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
203
|
+
module = new WebAssembly.Module(module);
|
|
204
|
+
}
|
|
205
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
206
|
+
return __wbg_finalize_init(instance, module);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
async function __wbg_init(module_or_path) {
|
|
210
|
+
if (wasm !== undefined) return wasm;
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
if (module_or_path !== undefined) {
|
|
214
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
215
|
+
({module_or_path} = module_or_path)
|
|
216
|
+
} else {
|
|
217
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (module_or_path === undefined) {
|
|
222
|
+
module_or_path = new URL('kymostudio_core_bg.wasm', import.meta.url);
|
|
223
|
+
}
|
|
224
|
+
const imports = __wbg_get_imports();
|
|
225
|
+
|
|
226
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
227
|
+
module_or_path = fetch(module_or_path);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
231
|
+
|
|
232
|
+
return __wbg_finalize_init(instance, module);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "kymostudio-core",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "Type it. See it appear. Watch it animate.",
|
|
5
|
+
"version": "0.3.4",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/kymostudio/kymostudio"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"kymostudio_core_bg.wasm",
|
|
13
|
+
"kymostudio_core.js",
|
|
14
|
+
"kymostudio_core.d.ts"
|
|
15
|
+
],
|
|
16
|
+
"main": "kymostudio_core.js",
|
|
17
|
+
"homepage": "https://github.com/kymostudio/kymostudio",
|
|
18
|
+
"types": "kymostudio_core.d.ts",
|
|
19
|
+
"sideEffects": [
|
|
20
|
+
"./snippets/*"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"svg",
|
|
24
|
+
"png",
|
|
25
|
+
"rasterizer",
|
|
26
|
+
"diagram",
|
|
27
|
+
"resvg"
|
|
28
|
+
]
|
|
29
|
+
}
|