@mathlabs/tikra 1.1.1 → 1.2.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 +3 -3
- package/index.d.cts +16 -4
- package/index.d.ts +16 -4
- package/node/tikra_wasm.cjs +29 -23
- package/node/wrap.cjs +4 -4
- package/package.json +1 -1
- package/tikra.wasm +0 -0
- package/web/tikra_wasm.js +29 -23
- package/web/wrap.js +4 -4
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ import { writeFileSync } from "node:fs";
|
|
|
30
30
|
const svg = tikzToSvg(String.raw`\begin{tikzpicture}\draw[->] (0,0) -- (2,1) node[right] {$\vec v$};\end{tikzpicture}`);
|
|
31
31
|
writeFileSync("v.svg", svg);
|
|
32
32
|
writeFileSync("v.png", png(svg, { dpi: 300 }));
|
|
33
|
-
const { warnings } = render(String.raw`\tikz \draw (0,0) circle (1);`); // []
|
|
33
|
+
const { warnings, alt } = render(String.raw`\tikz \draw (0,0) circle (1);`); // [], "Drawing of one shape, without text"
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
## Browsers and bundlers (Vite, webpack, esbuild)
|
|
@@ -59,8 +59,8 @@ Without a bundler, from a CDN:
|
|
|
59
59
|
| | |
|
|
60
60
|
|---|---|
|
|
61
61
|
| `init(input?)` | Loads the wasm. Needed once in browsers and bundlers; does nothing in Node. `input` overrides where the wasm comes from (a URL, a `Response`, bytes or a `WebAssembly.Module`). |
|
|
62
|
-
| `tikzToSvg(code)` | The SVG as a string. |
|
|
63
|
-
| `render(code)` | `{ svg, warnings }`: `warnings` lists, as strings, what was ignored or approximated. |
|
|
62
|
+
| `tikzToSvg(code, options?)` | The SVG as a string. `options.locale` (`"en"` by default, or `"pt-BR"`, `"es"`, `"fr"`, `"de"`, `"it"`, `"ru"`, `"zh"`, `"ja"`, `"ko"`, `"hi"`, `"ar"`, `"id"`, `"tr"`, `"nl"`, `"pl"`) is the language of the figure in words; the drawing is the same in all. |
|
|
63
|
+
| `render(code, options?)` | `{ svg, alt, description, warnings }`, the words in `options.locale`: `alt` is the figure in one sentence (the SVG's `<title>`, for an image's `alt`), `description` the figure in words (the SVG's `<desc>`: a chart's axes and data, a diagram's nodes and connections), and `warnings` lists, as strings, what was ignored or approximated. When the picture has its author's text (`\begin{tikzpicture}[alt={…}]`), `alt` and `description` are that text. The words tikra writes are not perfect (they say what is in the drawing, not what it means, and little about free drawings): review them before publishing. |
|
|
64
64
|
| `png(svg, options?)` | PNG bytes as a `Uint8Array`. Options: `dpi` (300 by default) and `background` (`true`, white, by default; `false` for transparent). |
|
|
65
65
|
| `version()` | The version of tikra's core inside the package (the npm package has its own version). |
|
|
66
66
|
|
package/index.d.cts
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
export interface Result {
|
|
2
2
|
/** Standalone SVG, with math labels typeset by mathra. */
|
|
3
3
|
svg: string;
|
|
4
|
+
/** The figure in a sentence, for readers who cannot see it: the SVG's `<title>`, an image's `alt`. */
|
|
5
|
+
alt: string;
|
|
6
|
+
/** The figure in words (axes, data, nodes and their connections): the SVG's `<desc>`. */
|
|
7
|
+
description: string;
|
|
4
8
|
/** What was ignored or approximated: unsupported commands, labels with broken LaTeX. */
|
|
5
9
|
warnings: string[];
|
|
6
10
|
}
|
|
7
11
|
|
|
12
|
+
/** mathra's languages: the figure in words (`alt`, `description`) is told in them; the drawing is the same. */
|
|
13
|
+
export type Locale = "en" | "pt-BR" | "es" | "fr" | "de" | "it" | "ru" | "zh" | "ja" | "ko" | "hi" | "ar" | "id" | "tr" | "nl" | "pl";
|
|
14
|
+
|
|
15
|
+
export interface Options {
|
|
16
|
+
/** The language of the figure in words. Default `"en"`. A code with a region (`"es-MX"`) takes its language. */
|
|
17
|
+
locale?: Locale | (string & {});
|
|
18
|
+
}
|
|
19
|
+
|
|
8
20
|
export interface PngOptions {
|
|
9
21
|
/** Resolution. Default 300, for print. */
|
|
10
22
|
dpi?: number;
|
|
@@ -15,11 +27,11 @@ export interface PngOptions {
|
|
|
15
27
|
/** Loads the WebAssembly module: await it once before converting in browsers and bundlers. In Node it does nothing. */
|
|
16
28
|
export function init(input?: RequestInfo | URL | Response | BufferSource | WebAssembly.Module): Promise<void>;
|
|
17
29
|
|
|
18
|
-
/** Converts a TikZ figure (a `standalone` document, a `tikzpicture`, `\tikz`, an `axis` or loose statements) to SVG. Throws when there is no figure to draw. */
|
|
19
|
-
export function tikzToSvg(code: string): string;
|
|
30
|
+
/** Converts a TikZ figure (a `standalone` document, a `tikzpicture`, `\tikz`, an `axis` or loose statements) to SVG, with the figure in words in `options.locale`. Throws when there is no figure to draw or the locale is unknown. */
|
|
31
|
+
export function tikzToSvg(code: string, options?: Options): string;
|
|
20
32
|
|
|
21
|
-
/** Converts a TikZ figure and returns the SVG
|
|
22
|
-
export function render(code: string): Result;
|
|
33
|
+
/** Converts a TikZ figure and returns the SVG, the figure in words and the warnings. */
|
|
34
|
+
export function render(code: string, options?: Options): Result;
|
|
23
35
|
|
|
24
36
|
/** Rasterizes an SVG written by tikra to PNG bytes. Throws on an invalid SVG or dpi, or past 100 megapixels. */
|
|
25
37
|
export function png(svg: string, options?: PngOptions): Uint8Array;
|
package/index.d.ts
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
export interface Result {
|
|
2
2
|
/** Standalone SVG, with math labels typeset by mathra. */
|
|
3
3
|
svg: string;
|
|
4
|
+
/** The figure in a sentence, for readers who cannot see it: the SVG's `<title>`, an image's `alt`. */
|
|
5
|
+
alt: string;
|
|
6
|
+
/** The figure in words (axes, data, nodes and their connections): the SVG's `<desc>`. */
|
|
7
|
+
description: string;
|
|
4
8
|
/** What was ignored or approximated: unsupported commands, labels with broken LaTeX. */
|
|
5
9
|
warnings: string[];
|
|
6
10
|
}
|
|
7
11
|
|
|
12
|
+
/** mathra's languages: the figure in words (`alt`, `description`) is told in them; the drawing is the same. */
|
|
13
|
+
export type Locale = "en" | "pt-BR" | "es" | "fr" | "de" | "it" | "ru" | "zh" | "ja" | "ko" | "hi" | "ar" | "id" | "tr" | "nl" | "pl";
|
|
14
|
+
|
|
15
|
+
export interface Options {
|
|
16
|
+
/** The language of the figure in words. Default `"en"`. A code with a region (`"es-MX"`) takes its language. */
|
|
17
|
+
locale?: Locale | (string & {});
|
|
18
|
+
}
|
|
19
|
+
|
|
8
20
|
export interface PngOptions {
|
|
9
21
|
/** Resolution. Default 300, for print. */
|
|
10
22
|
dpi?: number;
|
|
@@ -15,11 +27,11 @@ export interface PngOptions {
|
|
|
15
27
|
/** Loads the WebAssembly module: await it once before converting in browsers and bundlers. In Node it does nothing. */
|
|
16
28
|
export function init(input?: RequestInfo | URL | Response | BufferSource | WebAssembly.Module): Promise<void>;
|
|
17
29
|
|
|
18
|
-
/** Converts a TikZ figure (a `standalone` document, a `tikzpicture`, `\tikz`, an `axis` or loose statements) to SVG. Throws when there is no figure to draw. */
|
|
19
|
-
export function tikzToSvg(code: string): string;
|
|
30
|
+
/** Converts a TikZ figure (a `standalone` document, a `tikzpicture`, `\tikz`, an `axis` or loose statements) to SVG, with the figure in words in `options.locale`. Throws when there is no figure to draw or the locale is unknown. */
|
|
31
|
+
export function tikzToSvg(code: string, options?: Options): string;
|
|
20
32
|
|
|
21
|
-
/** Converts a TikZ figure and returns the SVG
|
|
22
|
-
export function render(code: string): Result;
|
|
33
|
+
/** Converts a TikZ figure and returns the SVG, the figure in words and the warnings. */
|
|
34
|
+
export function render(code: string, options?: Options): Result;
|
|
23
35
|
|
|
24
36
|
/** Rasterizes an SVG written by tikra to PNG bytes. Throws on an invalid SVG or dpi, or past 100 megapixels. */
|
|
25
37
|
export function png(svg: string, options?: PngOptions): Uint8Array;
|
package/node/tikra_wasm.cjs
CHANGED
|
@@ -19,28 +19,31 @@ function png(svg, dpi, background) {
|
|
|
19
19
|
exports.png = png;
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* The SVG and what was ignored or approximated, as JSON (see `convert_json`).
|
|
22
|
+
* The SVG, the figure in words and what was ignored or approximated, as JSON (see `convert_json`).
|
|
23
23
|
* @param {string} code
|
|
24
|
+
* @param {string | null} [locale]
|
|
24
25
|
* @returns {string}
|
|
25
26
|
*/
|
|
26
|
-
function render(code) {
|
|
27
|
-
let
|
|
28
|
-
let
|
|
27
|
+
function render(code, locale) {
|
|
28
|
+
let deferred4_0;
|
|
29
|
+
let deferred4_1;
|
|
29
30
|
try {
|
|
30
31
|
const ptr0 = passStringToWasm0(code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
31
32
|
const len0 = WASM_VECTOR_LEN;
|
|
32
|
-
|
|
33
|
-
var
|
|
34
|
-
|
|
33
|
+
var ptr1 = isLikeNone(locale) ? 0 : passStringToWasm0(locale, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
34
|
+
var len1 = WASM_VECTOR_LEN;
|
|
35
|
+
const ret = wasm.render(ptr0, len0, ptr1, len1);
|
|
36
|
+
var ptr3 = ret[0];
|
|
37
|
+
var len3 = ret[1];
|
|
35
38
|
if (ret[3]) {
|
|
36
|
-
|
|
39
|
+
ptr3 = 0; len3 = 0;
|
|
37
40
|
throw takeFromExternrefTable0(ret[2]);
|
|
38
41
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return getStringFromWasm0(
|
|
42
|
+
deferred4_0 = ptr3;
|
|
43
|
+
deferred4_1 = len3;
|
|
44
|
+
return getStringFromWasm0(ptr3, len3);
|
|
42
45
|
} finally {
|
|
43
|
-
wasm.__wbindgen_free(
|
|
46
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
49
|
exports.render = render;
|
|
@@ -48,26 +51,29 @@ exports.render = render;
|
|
|
48
51
|
/**
|
|
49
52
|
* Converts a TikZ figure (a `standalone` document, a `tikzpicture`, `\tikz` or an `axis`) to SVG.
|
|
50
53
|
* @param {string} code
|
|
54
|
+
* @param {string | null} [locale]
|
|
51
55
|
* @returns {string}
|
|
52
56
|
*/
|
|
53
|
-
function tikzToSvg(code) {
|
|
54
|
-
let
|
|
55
|
-
let
|
|
57
|
+
function tikzToSvg(code, locale) {
|
|
58
|
+
let deferred4_0;
|
|
59
|
+
let deferred4_1;
|
|
56
60
|
try {
|
|
57
61
|
const ptr0 = passStringToWasm0(code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
58
62
|
const len0 = WASM_VECTOR_LEN;
|
|
59
|
-
|
|
60
|
-
var
|
|
61
|
-
|
|
63
|
+
var ptr1 = isLikeNone(locale) ? 0 : passStringToWasm0(locale, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
64
|
+
var len1 = WASM_VECTOR_LEN;
|
|
65
|
+
const ret = wasm.tikzToSvg(ptr0, len0, ptr1, len1);
|
|
66
|
+
var ptr3 = ret[0];
|
|
67
|
+
var len3 = ret[1];
|
|
62
68
|
if (ret[3]) {
|
|
63
|
-
|
|
69
|
+
ptr3 = 0; len3 = 0;
|
|
64
70
|
throw takeFromExternrefTable0(ret[2]);
|
|
65
71
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return getStringFromWasm0(
|
|
72
|
+
deferred4_0 = ptr3;
|
|
73
|
+
deferred4_1 = len3;
|
|
74
|
+
return getStringFromWasm0(ptr3, len3);
|
|
69
75
|
} finally {
|
|
70
|
-
wasm.__wbindgen_free(
|
|
76
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
71
77
|
}
|
|
72
78
|
}
|
|
73
79
|
exports.tikzToSvg = tikzToSvg;
|
package/node/wrap.cjs
CHANGED
|
@@ -5,13 +5,13 @@ function wrap(raw, isReady) {
|
|
|
5
5
|
if (!isReady()) throw new Error("tikra: call `await init()` once before converting (only needed outside Node)");
|
|
6
6
|
};
|
|
7
7
|
return {
|
|
8
|
-
tikzToSvg(code) {
|
|
8
|
+
tikzToSvg(code, options) {
|
|
9
9
|
check();
|
|
10
|
-
return raw.tikzToSvg(code);
|
|
10
|
+
return raw.tikzToSvg(code, options?.locale ?? null);
|
|
11
11
|
},
|
|
12
|
-
render(code) {
|
|
12
|
+
render(code, options) {
|
|
13
13
|
check();
|
|
14
|
-
return JSON.parse(raw.render(code));
|
|
14
|
+
return JSON.parse(raw.render(code, options?.locale ?? null));
|
|
15
15
|
},
|
|
16
16
|
png(svg, options) {
|
|
17
17
|
check();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mathlabs/tikra",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "TikZ and pgfplots figures to SVG and PNG, without a TeX install. Math labels typeset by mathra. Runs on WebAssembly in Node, bundlers and browsers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tikz",
|
package/tikra.wasm
CHANGED
|
Binary file
|
package/web/tikra_wasm.js
CHANGED
|
@@ -18,54 +18,60 @@ export function png(svg, dpi, background) {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* The SVG and what was ignored or approximated, as JSON (see `convert_json`).
|
|
21
|
+
* The SVG, the figure in words and what was ignored or approximated, as JSON (see `convert_json`).
|
|
22
22
|
* @param {string} code
|
|
23
|
+
* @param {string | null} [locale]
|
|
23
24
|
* @returns {string}
|
|
24
25
|
*/
|
|
25
|
-
export function render(code) {
|
|
26
|
-
let
|
|
27
|
-
let
|
|
26
|
+
export function render(code, locale) {
|
|
27
|
+
let deferred4_0;
|
|
28
|
+
let deferred4_1;
|
|
28
29
|
try {
|
|
29
30
|
const ptr0 = passStringToWasm0(code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
30
31
|
const len0 = WASM_VECTOR_LEN;
|
|
31
|
-
|
|
32
|
-
var
|
|
33
|
-
|
|
32
|
+
var ptr1 = isLikeNone(locale) ? 0 : passStringToWasm0(locale, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
33
|
+
var len1 = WASM_VECTOR_LEN;
|
|
34
|
+
const ret = wasm.render(ptr0, len0, ptr1, len1);
|
|
35
|
+
var ptr3 = ret[0];
|
|
36
|
+
var len3 = ret[1];
|
|
34
37
|
if (ret[3]) {
|
|
35
|
-
|
|
38
|
+
ptr3 = 0; len3 = 0;
|
|
36
39
|
throw takeFromExternrefTable0(ret[2]);
|
|
37
40
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return getStringFromWasm0(
|
|
41
|
+
deferred4_0 = ptr3;
|
|
42
|
+
deferred4_1 = len3;
|
|
43
|
+
return getStringFromWasm0(ptr3, len3);
|
|
41
44
|
} finally {
|
|
42
|
-
wasm.__wbindgen_free(
|
|
45
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
/**
|
|
47
50
|
* Converts a TikZ figure (a `standalone` document, a `tikzpicture`, `\tikz` or an `axis`) to SVG.
|
|
48
51
|
* @param {string} code
|
|
52
|
+
* @param {string | null} [locale]
|
|
49
53
|
* @returns {string}
|
|
50
54
|
*/
|
|
51
|
-
export function tikzToSvg(code) {
|
|
52
|
-
let
|
|
53
|
-
let
|
|
55
|
+
export function tikzToSvg(code, locale) {
|
|
56
|
+
let deferred4_0;
|
|
57
|
+
let deferred4_1;
|
|
54
58
|
try {
|
|
55
59
|
const ptr0 = passStringToWasm0(code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
56
60
|
const len0 = WASM_VECTOR_LEN;
|
|
57
|
-
|
|
58
|
-
var
|
|
59
|
-
|
|
61
|
+
var ptr1 = isLikeNone(locale) ? 0 : passStringToWasm0(locale, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
62
|
+
var len1 = WASM_VECTOR_LEN;
|
|
63
|
+
const ret = wasm.tikzToSvg(ptr0, len0, ptr1, len1);
|
|
64
|
+
var ptr3 = ret[0];
|
|
65
|
+
var len3 = ret[1];
|
|
60
66
|
if (ret[3]) {
|
|
61
|
-
|
|
67
|
+
ptr3 = 0; len3 = 0;
|
|
62
68
|
throw takeFromExternrefTable0(ret[2]);
|
|
63
69
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return getStringFromWasm0(
|
|
70
|
+
deferred4_0 = ptr3;
|
|
71
|
+
deferred4_1 = len3;
|
|
72
|
+
return getStringFromWasm0(ptr3, len3);
|
|
67
73
|
} finally {
|
|
68
|
-
wasm.__wbindgen_free(
|
|
74
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
69
75
|
}
|
|
70
76
|
}
|
|
71
77
|
|
package/web/wrap.js
CHANGED
|
@@ -5,13 +5,13 @@ export function wrap(raw, isReady) {
|
|
|
5
5
|
if (!isReady()) throw new Error("tikra: call `await init()` once before converting (only needed outside Node)");
|
|
6
6
|
};
|
|
7
7
|
return {
|
|
8
|
-
tikzToSvg(code) {
|
|
8
|
+
tikzToSvg(code, options) {
|
|
9
9
|
check();
|
|
10
|
-
return raw.tikzToSvg(code);
|
|
10
|
+
return raw.tikzToSvg(code, options?.locale ?? null);
|
|
11
11
|
},
|
|
12
|
-
render(code) {
|
|
12
|
+
render(code, options) {
|
|
13
13
|
check();
|
|
14
|
-
return JSON.parse(raw.render(code));
|
|
14
|
+
return JSON.parse(raw.render(code, options?.locale ?? null));
|
|
15
15
|
},
|
|
16
16
|
png(svg, options) {
|
|
17
17
|
check();
|