@danielsimonjr/mathts-workbook 0.4.1 → 0.4.3
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 +247 -247
- package/dist/{chunk-JM3ZAYJC.js → chunk-AFI7I47D.js} +10 -4
- package/dist/cli.d.ts +134 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +74 -68
- package/dist/doc.d.ts +5 -0
- package/dist/doc.d.ts.map +1 -1
- package/dist/edit.d.ts +69 -0
- package/dist/edit.d.ts.map +1 -1
- package/dist/formatter.d.ts +12 -0
- package/dist/formatter.d.ts.map +1 -1
- package/dist/html.d.ts +26 -4
- package/dist/html.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/ipynb.d.ts.map +1 -1
- package/dist/markdown.d.ts +20 -0
- package/dist/markdown.d.ts.map +1 -1
- package/dist/pdf.d.ts +14 -0
- package/dist/pdf.d.ts.map +1 -1
- package/dist/rpc.d.ts +28 -0
- package/dist/rpc.d.ts.map +1 -1
- package/dist/session.d.ts +9 -0
- package/dist/session.d.ts.map +1 -1
- package/dist/svg.d.ts +3 -0
- package/dist/svg.d.ts.map +1 -1
- package/dist/tex.d.ts +3 -0
- package/dist/tex.d.ts.map +1 -1
- package/dist/timeout-runner.d.ts +3 -0
- package/dist/timeout-runner.d.ts.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/worker-protocol.d.ts +6 -0
- package/dist/worker-protocol.d.ts.map +1 -1
- package/package.json +65 -64
package/dist/cli.d.ts
CHANGED
|
@@ -7,18 +7,94 @@
|
|
|
7
7
|
* `main()` at the bottom wires them to the real streams, and only runs when
|
|
8
8
|
* this file is the process entry point.
|
|
9
9
|
*/
|
|
10
|
+
/**
|
|
11
|
+
* Result of one CLI command handler. `main()` writes `stdout` and `stderr` to the
|
|
12
|
+
* process streams and exits with `exitCode`. A handler returns this value and does
|
|
13
|
+
* not write to the console itself.
|
|
14
|
+
*/
|
|
10
15
|
export interface CommandResult {
|
|
11
16
|
stdout: string;
|
|
12
17
|
stderr: string;
|
|
13
18
|
exitCode: number;
|
|
14
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Run a workbook file (`mtsw run`) and report each cell result.
|
|
22
|
+
*
|
|
23
|
+
* The command first checks the optional `--expect-hash` SHA-256, then parses the file.
|
|
24
|
+
* With `--timeout <ms>`, the run occurs in a worker thread that is terminated when the
|
|
25
|
+
* budget expires. `--timeout` refuses `-c` and `-v`. Without `--timeout`, the run uses
|
|
26
|
+
* `runReport()`, so one failed cell does not stop the other cells. `--write` stores the
|
|
27
|
+
* results back into the file with an atomic write.
|
|
28
|
+
*
|
|
29
|
+
* @param args - Command arguments after `run`.
|
|
30
|
+
* @returns Exit code 0 if every reported cell succeeds or passes. Exit code 1 for a
|
|
31
|
+
* usage, read, hash, parse, unknown-cell, timeout or write error, or for any failed cell.
|
|
32
|
+
*/
|
|
15
33
|
export declare function runCommand(args: string[]): Promise<CommandResult>;
|
|
34
|
+
/**
|
|
35
|
+
* Parse a workbook file and list its problems (`mtsw validate`). The command does not
|
|
36
|
+
* run the cells.
|
|
37
|
+
*
|
|
38
|
+
* @param args - Command arguments after `validate`.
|
|
39
|
+
* @returns Exit code 0 if the file has no problems. Exit code 1 for a usage or read
|
|
40
|
+
* error, or if the file has one or more problems.
|
|
41
|
+
*/
|
|
16
42
|
export declare function validateCommand(args: string[]): CommandResult;
|
|
43
|
+
/**
|
|
44
|
+
* Print the structure of a workbook file (`mtsw describe`): cells, types and the
|
|
45
|
+
* dependency graph. With `--json`, the data is the `DescribeDoc` from `describeData()`.
|
|
46
|
+
* The command does not run the cells.
|
|
47
|
+
*
|
|
48
|
+
* @param args - Command arguments after `describe`.
|
|
49
|
+
* @returns Exit code 0 if the file parses with no problems, else exit code 1.
|
|
50
|
+
*/
|
|
17
51
|
export declare function describeCommand(args: string[]): CommandResult;
|
|
52
|
+
/**
|
|
53
|
+
* Print the CLI version, the schema version, the supported and deferred cell types,
|
|
54
|
+
* and the command list (`mtsw capabilities`).
|
|
55
|
+
*
|
|
56
|
+
* @param args - Command arguments. Only `--json` has an effect.
|
|
57
|
+
* @returns Always exit code 0.
|
|
58
|
+
*/
|
|
18
59
|
export declare function capabilitiesCommand(args: string[]): CommandResult;
|
|
60
|
+
/**
|
|
61
|
+
* List the names and descriptions of the templates that `mtsw new` accepts.
|
|
62
|
+
*
|
|
63
|
+
* @param args - Command arguments. Only `--json` has an effect.
|
|
64
|
+
* @returns Always exit code 0.
|
|
65
|
+
*/
|
|
19
66
|
export declare function templatesCommand(args: string[]): CommandResult;
|
|
67
|
+
/**
|
|
68
|
+
* List the function names and constant names that expression cells can use
|
|
69
|
+
* (`mtsw functions`).
|
|
70
|
+
*
|
|
71
|
+
* @param args - Command arguments. Only `--json` has an effect.
|
|
72
|
+
* @returns Always exit code 0.
|
|
73
|
+
*/
|
|
20
74
|
export declare function functionsCommand(args: string[]): CommandResult;
|
|
75
|
+
/**
|
|
76
|
+
* Read or change the workbook metadata (`mtsw meta get|set`).
|
|
77
|
+
*
|
|
78
|
+
* `set` accepts `--title`, `--author`, `--description` and `--tags` (a comma-separated
|
|
79
|
+
* list). `set` writes the file with an atomic write.
|
|
80
|
+
*
|
|
81
|
+
* @param args - Command arguments after `meta`. The first argument is `get` or `set`.
|
|
82
|
+
* @returns Exit code 0 on success. Exit code 1 for a usage, read, parse or write
|
|
83
|
+
* error, or for `set` with no field to change.
|
|
84
|
+
*/
|
|
21
85
|
export declare function metaCommand(args: string[]): CommandResult;
|
|
86
|
+
/**
|
|
87
|
+
* Export a workbook as HTML, TeX, JSON, PDF or ipynb (`mtsw export`).
|
|
88
|
+
*
|
|
89
|
+
* The command runs the workbook first, unless `--no-run` is given. If the run fails as a
|
|
90
|
+
* whole (a result with the id `(workbook)`, for example a dependency cycle), the export
|
|
91
|
+
* stops with exit code 1. The `json` format needs a run. The `pdf` format needs `-o`.
|
|
92
|
+
* Without `-o`, the rendered text goes to stdout.
|
|
93
|
+
*
|
|
94
|
+
* @param args - Command arguments after `export`.
|
|
95
|
+
* @returns Exit code 0 on success. Exit code 1 for an unknown format, a usage, read,
|
|
96
|
+
* parse or write error, a whole-run failure, or a PDF render error.
|
|
97
|
+
*/
|
|
22
98
|
export declare function exportCommand(args: string[]): Promise<CommandResult>;
|
|
23
99
|
/**
|
|
24
100
|
* Run the JSON-RPC-over-stdio server loop until `shutdown`, stdin EOF, or a
|
|
@@ -26,11 +102,69 @@ export declare function exportCommand(args: string[]): Promise<CommandResult>;
|
|
|
26
102
|
* for a run are flushed before that run's response (not mid-run in v1).
|
|
27
103
|
*/
|
|
28
104
|
export declare function runServer(input?: NodeJS.ReadableStream, output?: NodeJS.WritableStream): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Start the JSON-RPC server on stdin and stdout (`mtsw serve`). The returned promise
|
|
107
|
+
* resolves after `runServer()` stops.
|
|
108
|
+
*
|
|
109
|
+
* @returns Always exit code 0, with empty `stdout` and `stderr`.
|
|
110
|
+
*/
|
|
29
111
|
export declare function serveCommand(): Promise<CommandResult>;
|
|
112
|
+
/**
|
|
113
|
+
* Print the dependency graph of a workbook file (`mtsw graph`). The default output is
|
|
114
|
+
* one line for each cell. `-f mermaid` and `-f dot` select the other formats.
|
|
115
|
+
*
|
|
116
|
+
* `graph` has no JSON output. With `--json`, the command returns a JSON error envelope
|
|
117
|
+
* that tells the user to use `describe --json`.
|
|
118
|
+
*
|
|
119
|
+
* @param args - Command arguments after `graph`.
|
|
120
|
+
* @returns Exit code 0 on success. Exit code 1 for `--json`, or for a usage, read or
|
|
121
|
+
* parse error.
|
|
122
|
+
*/
|
|
30
123
|
export declare function graphCommand(args: string[]): CommandResult;
|
|
124
|
+
/**
|
|
125
|
+
* Remove the stored outputs from a workbook file (`mtsw strip`). The command prints the
|
|
126
|
+
* result. With `-w` or `--write`, the command writes the result back into the file with
|
|
127
|
+
* an atomic write.
|
|
128
|
+
*
|
|
129
|
+
* @param args - Command arguments after `strip`.
|
|
130
|
+
* @returns Exit code 0 on success. Exit code 1 for a usage, read, parse or write error.
|
|
131
|
+
*/
|
|
31
132
|
export declare function stripCommand(args: string[]): CommandResult;
|
|
133
|
+
/**
|
|
134
|
+
* Create a new workbook file from a template (`mtsw new`).
|
|
135
|
+
*
|
|
136
|
+
* A bare name must match `[A-Za-z0-9._-]+` and must not be `.`, `..` or a reserved
|
|
137
|
+
* Windows device name. This check stops a bare name from selecting a different
|
|
138
|
+
* directory. `-o <path>` gives an explicit path, and the name check does not apply to
|
|
139
|
+
* it. Without `--force`, the command does not overwrite an existing file. With
|
|
140
|
+
* `--force`, the command still refuses to overwrite a symbolic link.
|
|
141
|
+
*
|
|
142
|
+
* @param args - Command arguments after `new`.
|
|
143
|
+
* @returns Exit code 0 when the file is created. Exit code 1 for an unknown template,
|
|
144
|
+
* a missing or invalid name, an existing file or symbolic link, or a write error.
|
|
145
|
+
*/
|
|
32
146
|
export declare function newCommand(args: string[]): CommandResult;
|
|
147
|
+
/**
|
|
148
|
+
* Convert JSON or YAML input into a workbook (`mtsw import`). The input comes from a
|
|
149
|
+
* file, or from stdin if the file argument is absent or `-`. With `-o`, the command
|
|
150
|
+
* writes the result with an atomic write. Otherwise it prints the result.
|
|
151
|
+
*
|
|
152
|
+
* @param args - Command arguments after `import`.
|
|
153
|
+
* @returns Exit code 0 on success. Exit code 1 if no input is available, or for a
|
|
154
|
+
* read, import or write error.
|
|
155
|
+
*/
|
|
33
156
|
export declare function importCommand(args: string[]): CommandResult;
|
|
157
|
+
/**
|
|
158
|
+
* Add, edit, remove, move or rename one cell in a workbook file (`mtsw cell`).
|
|
159
|
+
*
|
|
160
|
+
* Each verb calls the related function in `edit.ts`. If that function throws, the
|
|
161
|
+
* command writes nothing and returns exit code 1. `--dry-run` prints the result and
|
|
162
|
+
* does not write. The command writes the file only if the content changed.
|
|
163
|
+
*
|
|
164
|
+
* @param args - Command arguments after `cell`. The first argument is the verb.
|
|
165
|
+
* @returns Exit code 0 on success, which includes "no change". Exit code 1 for a
|
|
166
|
+
* usage, read, parse, edit or write error.
|
|
167
|
+
*/
|
|
34
168
|
export declare function cellCommand(args: string[]): CommandResult;
|
|
35
169
|
/**
|
|
36
170
|
* Route argv to a command handler. Pure — returns a CommandResult.
|
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;GAOG;AAsCH;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAwOD;;;;;;;;;;;;GAYG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC,CAqHvE;AAqDD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,CAoC7D;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,CA+C7D;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,CAYjE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,CAa9D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,CAU9D;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,CA2DzD;AAoFD;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC,CA8H1E;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CACvB,KAAK,GAAE,MAAM,CAAC,cAA8B,EAC5C,MAAM,GAAE,MAAM,CAAC,cAA+B,GAC7C,OAAO,CAAC,IAAI,CAAC,CAuEf;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,aAAa,CAAC,CAG3D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,CAsC1D;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,CA0B1D;AAuDD;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,CAqFxD;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,CAiD3D;AAyED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,CA4HzD;AAED;;GAEG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC,CAuDrE"}
|
package/dist/cli.js
CHANGED
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
runWorkbookWithTimeout,
|
|
16
16
|
setMetadata,
|
|
17
17
|
writeFileAtomic
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-AFI7I47D.js";
|
|
19
19
|
import {
|
|
20
20
|
buildDependencyGraph,
|
|
21
21
|
createExecutor,
|
|
@@ -162,6 +162,9 @@ function texEscape(s) {
|
|
|
162
162
|
}
|
|
163
163
|
});
|
|
164
164
|
}
|
|
165
|
+
function verbatimBody(body, env) {
|
|
166
|
+
return body.split(`\\end{${env}}`).join(`\\end {${env}}`);
|
|
167
|
+
}
|
|
165
168
|
function escapeInlineNonLink(text) {
|
|
166
169
|
let s = texEscape(text);
|
|
167
170
|
s = s.replace(/`([^`]+)`/g, (_m, code) => `\\texttt{${code}}`);
|
|
@@ -199,9 +202,11 @@ function markdownToTex(src) {
|
|
|
199
202
|
i++;
|
|
200
203
|
}
|
|
201
204
|
i++;
|
|
202
|
-
out.push(
|
|
203
|
-
|
|
204
|
-
|
|
205
|
+
out.push(
|
|
206
|
+
`\\begin{lstlisting}
|
|
207
|
+
${verbatimBody(buf.join("\n"), "lstlisting")}
|
|
208
|
+
\\end{lstlisting}`
|
|
209
|
+
);
|
|
205
210
|
continue;
|
|
206
211
|
}
|
|
207
212
|
if (line2.trim() === "") {
|
|
@@ -252,6 +257,48 @@ ${items.join("\n")}
|
|
|
252
257
|
return out.join("\n\n");
|
|
253
258
|
}
|
|
254
259
|
|
|
260
|
+
// src/svg.ts
|
|
261
|
+
import { line, scatter, bar } from "@danielsimonjr/mathts-plot";
|
|
262
|
+
function coerce(v) {
|
|
263
|
+
if (typeof v === "number") return v;
|
|
264
|
+
if (typeof v === "bigint") return Number(v);
|
|
265
|
+
const u = v;
|
|
266
|
+
if (u && typeof u.toNumeric === "function") {
|
|
267
|
+
try {
|
|
268
|
+
return Number(u.toNumeric());
|
|
269
|
+
} catch {
|
|
270
|
+
return NaN;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return Number(v);
|
|
274
|
+
}
|
|
275
|
+
function toNums(raw) {
|
|
276
|
+
let arr = raw;
|
|
277
|
+
const m = raw;
|
|
278
|
+
if (m && typeof m.toArray === "function") {
|
|
279
|
+
try {
|
|
280
|
+
arr = m.toArray();
|
|
281
|
+
} catch {
|
|
282
|
+
arr = raw;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return Array.isArray(arr) ? arr.flat(Infinity).map(coerce) : [];
|
|
286
|
+
}
|
|
287
|
+
function renderChart(spec, xRaw, yRaw, format = "svg") {
|
|
288
|
+
const xs = toNums(xRaw);
|
|
289
|
+
const ys = toNums(yRaw);
|
|
290
|
+
const opts = format === "tikz" ? {
|
|
291
|
+
title: spec.title,
|
|
292
|
+
xLabel: spec.xLabel,
|
|
293
|
+
yLabel: spec.yLabel,
|
|
294
|
+
format: "tikz",
|
|
295
|
+
tikz: { standalone: false }
|
|
296
|
+
} : { title: spec.title, xLabel: spec.xLabel, yLabel: spec.yLabel };
|
|
297
|
+
if (spec.type === "scatter") return scatter(xs, ys, opts);
|
|
298
|
+
if (spec.type === "bar") return bar(xs, ys, opts);
|
|
299
|
+
return line(xs, ys, opts);
|
|
300
|
+
}
|
|
301
|
+
|
|
255
302
|
// src/html.ts
|
|
256
303
|
function esc2(s) {
|
|
257
304
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
@@ -310,7 +357,7 @@ function renderCell(cell, parse3) {
|
|
|
310
357
|
}
|
|
311
358
|
case "chart": {
|
|
312
359
|
const note = cell.note ? `<p class="note">\u26A0 ${esc2(cell.note)}</p>` : "";
|
|
313
|
-
return `<figure class="cell cell-chart">${cap}${cell.
|
|
360
|
+
return `<figure class="cell cell-chart">${cap}${cell.chart ? renderChart(cell.chart.spec, cell.chart.x, cell.chart.y, "svg") : '<p class="note">no chart</p>'}${note}</figure>`;
|
|
314
361
|
}
|
|
315
362
|
default:
|
|
316
363
|
return `<figure class="cell"><pre><code>${esc2(cell.content)}</code></pre></figure>`;
|
|
@@ -407,7 +454,7 @@ function renderCellTex(cell, parse3) {
|
|
|
407
454
|
const cap = cell.id ? `\\textit{${texEscape(cell.id)}}\\\\
|
|
408
455
|
` : "";
|
|
409
456
|
const src = `\\begin{lstlisting}
|
|
410
|
-
${cell.content}
|
|
457
|
+
${verbatimBody(cell.content, "lstlisting")}
|
|
411
458
|
\\end{lstlisting}`;
|
|
412
459
|
let res = "";
|
|
413
460
|
if (cell.error !== void 0)
|
|
@@ -418,7 +465,7 @@ ${cell.content}
|
|
|
418
465
|
res = `
|
|
419
466
|
|
|
420
467
|
\\begin{verbatim}
|
|
421
|
-
${cell.output}
|
|
468
|
+
${verbatimBody(cell.output, "verbatim")}
|
|
422
469
|
\\end{verbatim}`;
|
|
423
470
|
return `${cap}${src}${res}`;
|
|
424
471
|
}
|
|
@@ -435,11 +482,11 @@ ${cell.output}
|
|
|
435
482
|
const cap = cell.id ? `\\textit{${texEscape(cell.id)}}\\\\
|
|
436
483
|
` : "";
|
|
437
484
|
return `${cap}\\begin{verbatim}
|
|
438
|
-
${val}
|
|
485
|
+
${verbatimBody(val, "verbatim")}
|
|
439
486
|
\\end{verbatim}`;
|
|
440
487
|
}
|
|
441
488
|
case "chart": {
|
|
442
|
-
const chart = cell.
|
|
489
|
+
const chart = cell.chart ? renderChart(cell.chart.spec, cell.chart.x, cell.chart.y, "tikz") : "% no chart";
|
|
443
490
|
const note = cell.note ? `
|
|
444
491
|
|
|
445
492
|
\\textit{${texEscape(cell.note)}}` : "";
|
|
@@ -449,7 +496,7 @@ ${chart}
|
|
|
449
496
|
}
|
|
450
497
|
default:
|
|
451
498
|
return `\\begin{verbatim}
|
|
452
|
-
${cell.content}
|
|
499
|
+
${verbatimBody(cell.content, "verbatim")}
|
|
453
500
|
\\end{verbatim}`;
|
|
454
501
|
}
|
|
455
502
|
}
|
|
@@ -493,10 +540,11 @@ function renderCodeCell(cell, counter) {
|
|
|
493
540
|
traceback: [cell.error]
|
|
494
541
|
});
|
|
495
542
|
} else if (cell.type === "chart") {
|
|
496
|
-
if (cell.
|
|
543
|
+
if (cell.chart !== void 0) {
|
|
544
|
+
const svg = renderChart(cell.chart.spec, cell.chart.x, cell.chart.y, "svg");
|
|
497
545
|
outputs.push({
|
|
498
546
|
output_type: "display_data",
|
|
499
|
-
data: { "image/svg+xml": toSourceLines(
|
|
547
|
+
data: { "image/svg+xml": toSourceLines(svg), "text/plain": ["<chart>"] },
|
|
500
548
|
metadata: {}
|
|
501
549
|
});
|
|
502
550
|
}
|
|
@@ -551,48 +599,6 @@ function toIpynb(doc) {
|
|
|
551
599
|
return JSON.stringify(notebook, null, 2);
|
|
552
600
|
}
|
|
553
601
|
|
|
554
|
-
// src/svg.ts
|
|
555
|
-
import { line, scatter, bar } from "@danielsimonjr/mathts-plot";
|
|
556
|
-
function coerce(v) {
|
|
557
|
-
if (typeof v === "number") return v;
|
|
558
|
-
if (typeof v === "bigint") return Number(v);
|
|
559
|
-
const u = v;
|
|
560
|
-
if (u && typeof u.toNumeric === "function") {
|
|
561
|
-
try {
|
|
562
|
-
return Number(u.toNumeric());
|
|
563
|
-
} catch {
|
|
564
|
-
return NaN;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
return Number(v);
|
|
568
|
-
}
|
|
569
|
-
function toNums(raw) {
|
|
570
|
-
let arr = raw;
|
|
571
|
-
const m = raw;
|
|
572
|
-
if (m && typeof m.toArray === "function") {
|
|
573
|
-
try {
|
|
574
|
-
arr = m.toArray();
|
|
575
|
-
} catch {
|
|
576
|
-
arr = raw;
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
return Array.isArray(arr) ? arr.flat(Infinity).map(coerce) : [];
|
|
580
|
-
}
|
|
581
|
-
function renderChart(spec, xRaw, yRaw, format = "svg") {
|
|
582
|
-
const xs = toNums(xRaw);
|
|
583
|
-
const ys = toNums(yRaw);
|
|
584
|
-
const opts = format === "tikz" ? {
|
|
585
|
-
title: spec.title,
|
|
586
|
-
xLabel: spec.xLabel,
|
|
587
|
-
yLabel: spec.yLabel,
|
|
588
|
-
format: "tikz",
|
|
589
|
-
tikz: { standalone: false }
|
|
590
|
-
} : { title: spec.title, xLabel: spec.xLabel, yLabel: spec.yLabel };
|
|
591
|
-
if (spec.type === "scatter") return scatter(xs, ys, opts);
|
|
592
|
-
if (spec.type === "bar") return bar(xs, ys, opts);
|
|
593
|
-
return line(xs, ys, opts);
|
|
594
|
-
}
|
|
595
|
-
|
|
596
602
|
// src/cli.ts
|
|
597
603
|
var parse2 = mathFunctions.parse;
|
|
598
604
|
var HELP = `
|
|
@@ -1087,7 +1093,7 @@ function metaCommand(args) {
|
|
|
1087
1093
|
return { stdout: jsonEnvelope("meta", true, next.metadata, []), stderr: "", exitCode: 0 };
|
|
1088
1094
|
return { stdout: "", stderr: `Updated metadata in ${file}`, exitCode: 0 };
|
|
1089
1095
|
}
|
|
1090
|
-
function buildRenderDoc(workbook, byId
|
|
1096
|
+
function buildRenderDoc(workbook, byId) {
|
|
1091
1097
|
const lookup = (ref) => {
|
|
1092
1098
|
if (typeof ref !== "string") return ref;
|
|
1093
1099
|
return byId?.get(ref)?.output ?? workbook.cells.find((c) => c.id === ref)?.output;
|
|
@@ -1099,14 +1105,16 @@ function buildRenderDoc(workbook, byId, format = "svg") {
|
|
|
1099
1105
|
rc.type = "chart";
|
|
1100
1106
|
try {
|
|
1101
1107
|
const spec = parseYamlSafe(c.content);
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1108
|
+
rc.chart = {
|
|
1109
|
+
spec: {
|
|
1110
|
+
type: spec?.type,
|
|
1111
|
+
title: spec?.title,
|
|
1112
|
+
xLabel: spec?.x?.label,
|
|
1113
|
+
yLabel: spec?.y?.label
|
|
1114
|
+
},
|
|
1115
|
+
x: lookup(spec?.x?.data),
|
|
1116
|
+
y: lookup(spec?.y?.data)
|
|
1117
|
+
};
|
|
1110
1118
|
const unresolved = [];
|
|
1111
1119
|
for (const ref of [spec?.x?.data, spec?.y?.data]) {
|
|
1112
1120
|
if (typeof ref !== "string") continue;
|
|
@@ -1121,9 +1129,7 @@ function buildRenderDoc(workbook, byId, format = "svg") {
|
|
|
1121
1129
|
rc.note = `chart data did not resolve: ${unresolved.join(", ")}${byId ? "" : " (try without --no-run)"}`;
|
|
1122
1130
|
}
|
|
1123
1131
|
} catch (error2) {
|
|
1124
|
-
|
|
1125
|
-
if (format === "tikz") rc.chartTikz = placeholder;
|
|
1126
|
-
else rc.chartSvg = placeholder;
|
|
1132
|
+
rc.chart = { spec: {}, x: [], y: [] };
|
|
1127
1133
|
rc.note = `invalid chart spec: ${errMessage(error2)}`;
|
|
1128
1134
|
}
|
|
1129
1135
|
return rc;
|
|
@@ -1223,14 +1229,14 @@ async function exportCommand(args) {
|
|
|
1223
1229
|
const outPath2 = flagValue(args, "-o") ?? flagValue(args, "--output");
|
|
1224
1230
|
if (!outPath2) return fail(["--format pdf requires an output path: -o <file.pdf>"]);
|
|
1225
1231
|
try {
|
|
1226
|
-
await toPDF(buildRenderDoc(workbook, byId
|
|
1232
|
+
await toPDF(buildRenderDoc(workbook, byId), outPath2, { parse: parse2 });
|
|
1227
1233
|
} catch (error) {
|
|
1228
1234
|
return fail([`PDF export failed: ${errMessage(error)}`]);
|
|
1229
1235
|
}
|
|
1230
1236
|
return json ? { stdout: jsonEnvelope("export", true, { path: outPath2 }, []), stderr: "", exitCode: 0 } : { stdout: "", stderr: `Exported ${file} -> ${outPath2}`, exitCode: 0 };
|
|
1231
1237
|
}
|
|
1232
1238
|
const fragment = args.includes("--fragment");
|
|
1233
|
-
const rendered = format === "tex" ? toTeX(buildRenderDoc(workbook, byId
|
|
1239
|
+
const rendered = format === "tex" ? toTeX(buildRenderDoc(workbook, byId), { parse: parse2, fragment }) : format === "ipynb" ? toIpynb(buildRenderDoc(workbook, byId)) : toHTML(buildRenderDoc(workbook, byId), { parse: parse2 });
|
|
1234
1240
|
const bytes = Buffer.byteLength(rendered, "utf-8");
|
|
1235
1241
|
const outPath = flagValue(args, "-o") ?? flagValue(args, "--output");
|
|
1236
1242
|
if (outPath) {
|
package/dist/doc.d.ts
CHANGED
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
* command and the serve JSON-RPC router (kept out of cli.ts to avoid a cycle).
|
|
4
4
|
*/
|
|
5
5
|
import type { Workbook } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* Structured description of a workbook: metadata, runtime settings, cells, and the
|
|
8
|
+
* dependency graph with its cycles. `describeData()` builds it. The `describe` command
|
|
9
|
+
* and the JSON-RPC router return it.
|
|
10
|
+
*/
|
|
6
11
|
export interface DescribeDoc {
|
|
7
12
|
version: string;
|
|
8
13
|
metadata: Workbook['metadata'];
|
package/dist/doc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doc.d.ts","sourceRoot":"","sources":["../src/doc.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGxC,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC/B,OAAO,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC7B,KAAK,EAAE,KAAK,CAAC;QACX,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,EAAE,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAClC,MAAM,EAAE,OAAO,CAAC;QAChB,KAAK,EAAE,OAAO,CAAC;KAChB,CAAC,CAAC;IACH,KAAK,EAAE;QAAE,KAAK,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,EAAE,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAA;KAAE,CAAC;CAC3E;AAED,sEAAsE;AACtE,wBAAgB,YAAY,CAAC,EAAE,EAAE,QAAQ,GAAG,SAAS,GAAG,WAAW,
|
|
1
|
+
{"version":3,"file":"doc.d.ts","sourceRoot":"","sources":["../src/doc.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGxC;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC/B,OAAO,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC7B,KAAK,EAAE,KAAK,CAAC;QACX,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,EAAE,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAClC,MAAM,EAAE,OAAO,CAAC;QAChB,KAAK,EAAE,OAAO,CAAC;KAChB,CAAC,CAAC;IACH,KAAK,EAAE;QAAE,KAAK,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,EAAE,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAA;KAAE,CAAC;CAC3E;AAED,sEAAsE;AACtE,wBAAgB,YAAY,CAAC,EAAE,EAAE,QAAQ,GAAG,SAAS,GAAG,WAAW,CAwBlE"}
|
package/dist/edit.d.ts
CHANGED
|
@@ -8,31 +8,100 @@
|
|
|
8
8
|
* file on a throw.
|
|
9
9
|
*/
|
|
10
10
|
import type { Workbook, CellType } from './types';
|
|
11
|
+
/**
|
|
12
|
+
* Insertion point for a cell. The functions use the first field that is set, in this
|
|
13
|
+
* order: `at` (an index), `before` (a cell id), `after` (a cell id). With no field set,
|
|
14
|
+
* the cell goes at the end.
|
|
15
|
+
*/
|
|
11
16
|
export interface CellPosition {
|
|
12
17
|
before?: string;
|
|
13
18
|
after?: string;
|
|
14
19
|
at?: number;
|
|
15
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Result of `removeCell()`: the new workbook and the cells that were detached from the
|
|
23
|
+
* removed cell.
|
|
24
|
+
*/
|
|
16
25
|
export interface RemoveResult {
|
|
17
26
|
workbook: Workbook;
|
|
18
27
|
/** Cells whose `depends_on` was edited to detach the removed cell (force). */
|
|
19
28
|
changedCells: string[];
|
|
20
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Add a cell and return a new workbook. The input workbook does not change.
|
|
32
|
+
*
|
|
33
|
+
* @param wb - The workbook to start from.
|
|
34
|
+
* @param spec - The id, type, content and dependencies of the new cell.
|
|
35
|
+
* @param position - Where to put the cell. The default is the end.
|
|
36
|
+
* @returns A new workbook that contains the cell.
|
|
37
|
+
* @throws Error if the id is not an identifier or is a duplicate, if the type is not
|
|
38
|
+
* supported, if a dependency is unknown or is the cell itself, if the position is not
|
|
39
|
+
* valid, or if the change creates a new dependency cycle.
|
|
40
|
+
*/
|
|
21
41
|
export declare function addCell(wb: Workbook, spec: {
|
|
22
42
|
id: string;
|
|
23
43
|
type: CellType;
|
|
24
44
|
content?: string;
|
|
25
45
|
dependsOn?: string[];
|
|
26
46
|
}, position?: CellPosition): Workbook;
|
|
47
|
+
/**
|
|
48
|
+
* Change the content, type or dependencies of a cell and return a new workbook. The
|
|
49
|
+
* input workbook does not change. A changed cell loses its stored output and error.
|
|
50
|
+
*
|
|
51
|
+
* @param wb - The workbook to start from.
|
|
52
|
+
* @param id - The id of the cell to change.
|
|
53
|
+
* @param changes - The fields to change. An absent field keeps its value.
|
|
54
|
+
* @returns A new workbook that contains the changed cell.
|
|
55
|
+
* @throws Error if the cell does not exist, if the type is not supported, if a
|
|
56
|
+
* dependency is unknown or is the cell itself, or if the change creates a new
|
|
57
|
+
* dependency cycle.
|
|
58
|
+
*/
|
|
27
59
|
export declare function editCell(wb: Workbook, id: string, changes: {
|
|
28
60
|
content?: string;
|
|
29
61
|
type?: CellType;
|
|
30
62
|
dependsOn?: string[];
|
|
31
63
|
}): Workbook;
|
|
64
|
+
/**
|
|
65
|
+
* Remove a cell and return a new workbook. The input workbook does not change.
|
|
66
|
+
*
|
|
67
|
+
* If other cells depend on the removed cell, the function throws, unless `force` is
|
|
68
|
+
* set. With `force`, the function removes the dependency from each dependent cell. It
|
|
69
|
+
* also clears the stored output and error of each such cell.
|
|
70
|
+
*
|
|
71
|
+
* @param wb - The workbook to start from.
|
|
72
|
+
* @param id - The id of the cell to remove.
|
|
73
|
+
* @param options - Set `force` to detach the dependent cells.
|
|
74
|
+
* @returns The new workbook and the ids of the detached cells.
|
|
75
|
+
* @throws Error if the cell does not exist, or if it has dependents and `force` is not set.
|
|
76
|
+
*/
|
|
32
77
|
export declare function removeCell(wb: Workbook, id: string, options?: {
|
|
33
78
|
force?: boolean;
|
|
34
79
|
}): RemoveResult;
|
|
80
|
+
/**
|
|
81
|
+
* Move a cell to a new position and return a new workbook. The input workbook does not
|
|
82
|
+
* change. A move relative to the cell itself returns an unchanged copy.
|
|
83
|
+
*
|
|
84
|
+
* @param wb - The workbook to start from.
|
|
85
|
+
* @param id - The id of the cell to move.
|
|
86
|
+
* @param position - The new position.
|
|
87
|
+
* @returns A new workbook with the cell at the new position.
|
|
88
|
+
* @throws Error if the cell does not exist or if the position is not valid.
|
|
89
|
+
*/
|
|
35
90
|
export declare function moveCell(wb: Workbook, id: string, position: CellPosition): Workbook;
|
|
91
|
+
/**
|
|
92
|
+
* Rename a cell and return a new workbook. The input workbook does not change.
|
|
93
|
+
*
|
|
94
|
+
* Each dependent cell gets the new id in its `dependsOn` list. The function also
|
|
95
|
+
* replaces each whole-word match of the old id in the content of those dependent
|
|
96
|
+
* cells. This replacement can also change the old id inside a string literal. Stored
|
|
97
|
+
* outputs do not change.
|
|
98
|
+
*
|
|
99
|
+
* @param wb - The workbook to start from.
|
|
100
|
+
* @param oldId - The current id.
|
|
101
|
+
* @param newId - The new id.
|
|
102
|
+
* @returns A new workbook with the renamed cell.
|
|
103
|
+
* @throws Error if the cell does not exist, or if `newId` is not an identifier or is a duplicate.
|
|
104
|
+
*/
|
|
36
105
|
export declare function renameCell(wb: Workbook, oldId: string, newId: string): Workbook;
|
|
37
106
|
/** Update workbook-level metadata fields (only the provided ones). */
|
|
38
107
|
export declare function setMetadata(wb: Workbook, changes: {
|
package/dist/edit.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../src/edit.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAQ,QAAQ,EAAE,MAAM,SAAS,CAAC;AAIxD,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,QAAQ,CAAC;IACnB,8EAA8E;IAC9E,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;
|
|
1
|
+
{"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../src/edit.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAQ,QAAQ,EAAE,MAAM,SAAS,CAAC;AAIxD;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,QAAQ,CAAC;IACnB,8EAA8E;IAC9E,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAoFD;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CACrB,EAAE,EAAE,QAAQ,EACZ,IAAI,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,EAC5E,QAAQ,CAAC,EAAE,YAAY,GACtB,QAAQ,CAiBV;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CACtB,EAAE,EAAE,QAAQ,EACZ,EAAE,EAAE,MAAM,EACV,OAAO,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,QAAQ,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,GACnE,QAAQ,CAyBV;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,YAAY,CAsBhG;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,GAAG,QAAQ,CASnF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,CA6B/E;AAED,sEAAsE;AACtE,wBAAgB,WAAW,CACzB,EAAE,EAAE,QAAQ,EACZ,OAAO,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,GAClF,QAAQ,CAOV"}
|
package/dist/formatter.d.ts
CHANGED
|
@@ -5,5 +5,17 @@
|
|
|
5
5
|
* MUST NOT throw — circular references, BigInt, and unserializable values all
|
|
6
6
|
* fall back to safe markers rather than crashing the run.
|
|
7
7
|
*/
|
|
8
|
+
/**
|
|
9
|
+
* Convert a cell result to text for the terminal.
|
|
10
|
+
*
|
|
11
|
+
* `null` and `undefined` give `(no result)`. A non-array object with a custom
|
|
12
|
+
* `toString` method uses that method, if the method returns text other than
|
|
13
|
+
* `[object Object]`. Other objects use JSON: a BigInt becomes `<digits>n`, and a
|
|
14
|
+
* circular reference becomes `[Circular]`. The function catches the errors of
|
|
15
|
+
* `toString` and of JSON conversion, and then uses a fallback text.
|
|
16
|
+
*
|
|
17
|
+
* @param value - The value to convert.
|
|
18
|
+
* @returns The text form of the value.
|
|
19
|
+
*/
|
|
8
20
|
export declare function formatResult(value: unknown): string;
|
|
9
21
|
//# sourceMappingURL=formatter.d.ts.map
|
package/dist/formatter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAkDH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CA8BnD"}
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAkDH;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CA8BnD"}
|
package/dist/html.d.ts
CHANGED
|
@@ -9,6 +9,22 @@
|
|
|
9
9
|
* outputs are pre-formatted strings supplied by the caller. All user content is
|
|
10
10
|
* HTML-escaped before embedding.
|
|
11
11
|
*/
|
|
12
|
+
import { type ChartSpec } from './svg.js';
|
|
13
|
+
/**
|
|
14
|
+
* The chart of a `chart` cell: the chart settings and the raw x and y data.
|
|
15
|
+
*/
|
|
16
|
+
export interface RenderChart {
|
|
17
|
+
spec: ChartSpec;
|
|
18
|
+
x: unknown;
|
|
19
|
+
y: unknown;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* One cell of a `RenderDoc`.
|
|
23
|
+
*
|
|
24
|
+
* SECURITY: a cell does not carry chart markup. `toHTML()`, `toTeX()` and `toIpynb()`
|
|
25
|
+
* make the chart markup from `chart` with `renderChart()`. The plot package escapes
|
|
26
|
+
* the title and the axis labels.
|
|
27
|
+
*/
|
|
12
28
|
export interface RenderCell {
|
|
13
29
|
type: string;
|
|
14
30
|
content: string;
|
|
@@ -18,13 +34,16 @@ export interface RenderCell {
|
|
|
18
34
|
error?: string;
|
|
19
35
|
/** For `test` cells: whether the assertion passed. */
|
|
20
36
|
passed?: boolean;
|
|
21
|
-
/** For `chart` cells:
|
|
22
|
-
|
|
23
|
-
/** For `chart` cells in a TeX export: pre-rendered embeddable TikZ. */
|
|
24
|
-
chartTikz?: string;
|
|
37
|
+
/** For `chart` cells: the chart settings and data. If omitted, the export shows "no chart". */
|
|
38
|
+
chart?: RenderChart;
|
|
25
39
|
/** Optional diagnostic note (e.g. a chart whose data didn't resolve). */
|
|
26
40
|
note?: string;
|
|
27
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Document structure that `toHTML()`, `toTeX()` and `toPDF()` render. It does not use
|
|
44
|
+
* the `Workbook` type. `toHTML()` escapes `title`, `author`, `description` and `tags`.
|
|
45
|
+
* `toTeX()` escapes `title` and `author`.
|
|
46
|
+
*/
|
|
28
47
|
export interface RenderDoc {
|
|
29
48
|
title?: string;
|
|
30
49
|
author?: string;
|
|
@@ -32,6 +51,9 @@ export interface RenderDoc {
|
|
|
32
51
|
tags?: string[];
|
|
33
52
|
cells: RenderCell[];
|
|
34
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Options for `toHTML()`.
|
|
56
|
+
*/
|
|
35
57
|
export interface ToHtmlOptions {
|
|
36
58
|
/** Parser for equation expressions (e.g. the functions package `parse`). */
|
|
37
59
|
parse?: (expr: string) => unknown;
|
package/dist/html.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,SAAS,CAAC;IAChB,CAAC,EAAE,OAAO,CAAC;IACX,CAAC,EAAE,OAAO,CAAC;CACZ;AAED;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,gFAAgF;IAChF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,+FAA+F;IAC/F,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,yEAAyE;IACzE,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,EAAE,UAAU,EAAE,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,4EAA4E;IAC5E,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;CACnC;AAyED,sFAAsF;AACtF,wBAAgB,KAAK,IAAI,MAAM,CA8B9B;AAED,4EAA4E;AAC5E,wBAAgB,MAAM,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CA6B1E"}
|
package/dist/index.js
CHANGED
package/dist/ipynb.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ipynb.d.ts","sourceRoot":"","sources":["../src/ipynb.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAc,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"ipynb.d.ts","sourceRoot":"","sources":["../src/ipynb.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAc,MAAM,WAAW,CAAC;AAsHvD,mFAAmF;AACnF,wBAAgB,OAAO,CAAC,GAAG,EAAE,SAAS,GAAG,MAAM,CAqB9C"}
|