@danielsimonjr/mathts-workbook 0.4.2 → 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/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;AAuCH,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAwOD,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC,CAqHvE;AAqDD,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,CAoC7D;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,CA+C7D;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,CAYjE;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,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yED;;;;;;;;;;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-4P6ZKIDU.js";
18
+ } from "./chunk-AFI7I47D.js";
19
19
  import {
20
20
  buildDependencyGraph,
21
21
  createExecutor,
@@ -257,6 +257,48 @@ ${items.join("\n")}
257
257
  return out.join("\n\n");
258
258
  }
259
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
+
260
302
  // src/html.ts
261
303
  function esc2(s) {
262
304
  return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
@@ -315,7 +357,7 @@ function renderCell(cell, parse3) {
315
357
  }
316
358
  case "chart": {
317
359
  const note = cell.note ? `<p class="note">\u26A0 ${esc2(cell.note)}</p>` : "";
318
- return `<figure class="cell cell-chart">${cap}${cell.chartSvg ?? '<p class="note">no chart</p>'}${note}</figure>`;
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>`;
319
361
  }
320
362
  default:
321
363
  return `<figure class="cell"><pre><code>${esc2(cell.content)}</code></pre></figure>`;
@@ -444,7 +486,7 @@ ${verbatimBody(val, "verbatim")}
444
486
  \\end{verbatim}`;
445
487
  }
446
488
  case "chart": {
447
- const chart = cell.chartTikz ?? "% no chart";
489
+ const chart = cell.chart ? renderChart(cell.chart.spec, cell.chart.x, cell.chart.y, "tikz") : "% no chart";
448
490
  const note = cell.note ? `
449
491
 
450
492
  \\textit{${texEscape(cell.note)}}` : "";
@@ -498,10 +540,11 @@ function renderCodeCell(cell, counter) {
498
540
  traceback: [cell.error]
499
541
  });
500
542
  } else if (cell.type === "chart") {
501
- if (cell.chartSvg !== void 0) {
543
+ if (cell.chart !== void 0) {
544
+ const svg = renderChart(cell.chart.spec, cell.chart.x, cell.chart.y, "svg");
502
545
  outputs.push({
503
546
  output_type: "display_data",
504
- data: { "image/svg+xml": toSourceLines(cell.chartSvg), "text/plain": ["<chart>"] },
547
+ data: { "image/svg+xml": toSourceLines(svg), "text/plain": ["<chart>"] },
505
548
  metadata: {}
506
549
  });
507
550
  }
@@ -556,48 +599,6 @@ function toIpynb(doc) {
556
599
  return JSON.stringify(notebook, null, 2);
557
600
  }
558
601
 
559
- // src/svg.ts
560
- import { line, scatter, bar } from "@danielsimonjr/mathts-plot";
561
- function coerce(v) {
562
- if (typeof v === "number") return v;
563
- if (typeof v === "bigint") return Number(v);
564
- const u = v;
565
- if (u && typeof u.toNumeric === "function") {
566
- try {
567
- return Number(u.toNumeric());
568
- } catch {
569
- return NaN;
570
- }
571
- }
572
- return Number(v);
573
- }
574
- function toNums(raw) {
575
- let arr = raw;
576
- const m = raw;
577
- if (m && typeof m.toArray === "function") {
578
- try {
579
- arr = m.toArray();
580
- } catch {
581
- arr = raw;
582
- }
583
- }
584
- return Array.isArray(arr) ? arr.flat(Infinity).map(coerce) : [];
585
- }
586
- function renderChart(spec, xRaw, yRaw, format = "svg") {
587
- const xs = toNums(xRaw);
588
- const ys = toNums(yRaw);
589
- const opts = format === "tikz" ? {
590
- title: spec.title,
591
- xLabel: spec.xLabel,
592
- yLabel: spec.yLabel,
593
- format: "tikz",
594
- tikz: { standalone: false }
595
- } : { title: spec.title, xLabel: spec.xLabel, yLabel: spec.yLabel };
596
- if (spec.type === "scatter") return scatter(xs, ys, opts);
597
- if (spec.type === "bar") return bar(xs, ys, opts);
598
- return line(xs, ys, opts);
599
- }
600
-
601
602
  // src/cli.ts
602
603
  var parse2 = mathFunctions.parse;
603
604
  var HELP = `
@@ -1092,7 +1093,7 @@ function metaCommand(args) {
1092
1093
  return { stdout: jsonEnvelope("meta", true, next.metadata, []), stderr: "", exitCode: 0 };
1093
1094
  return { stdout: "", stderr: `Updated metadata in ${file}`, exitCode: 0 };
1094
1095
  }
1095
- function buildRenderDoc(workbook, byId, format = "svg") {
1096
+ function buildRenderDoc(workbook, byId) {
1096
1097
  const lookup = (ref) => {
1097
1098
  if (typeof ref !== "string") return ref;
1098
1099
  return byId?.get(ref)?.output ?? workbook.cells.find((c) => c.id === ref)?.output;
@@ -1104,14 +1105,16 @@ function buildRenderDoc(workbook, byId, format = "svg") {
1104
1105
  rc.type = "chart";
1105
1106
  try {
1106
1107
  const spec = parseYamlSafe(c.content);
1107
- const rendered = renderChart(
1108
- { type: spec?.type, title: spec?.title, xLabel: spec?.x?.label, yLabel: spec?.y?.label },
1109
- lookup(spec?.x?.data),
1110
- lookup(spec?.y?.data),
1111
- format
1112
- );
1113
- if (format === "tikz") rc.chartTikz = rendered;
1114
- else rc.chartSvg = rendered;
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
+ };
1115
1118
  const unresolved = [];
1116
1119
  for (const ref of [spec?.x?.data, spec?.y?.data]) {
1117
1120
  if (typeof ref !== "string") continue;
@@ -1126,9 +1129,7 @@ function buildRenderDoc(workbook, byId, format = "svg") {
1126
1129
  rc.note = `chart data did not resolve: ${unresolved.join(", ")}${byId ? "" : " (try without --no-run)"}`;
1127
1130
  }
1128
1131
  } catch (error2) {
1129
- const placeholder = renderChart({}, [], [], format);
1130
- if (format === "tikz") rc.chartTikz = placeholder;
1131
- else rc.chartSvg = placeholder;
1132
+ rc.chart = { spec: {}, x: [], y: [] };
1132
1133
  rc.note = `invalid chart spec: ${errMessage(error2)}`;
1133
1134
  }
1134
1135
  return rc;
@@ -1228,14 +1229,14 @@ async function exportCommand(args) {
1228
1229
  const outPath2 = flagValue(args, "-o") ?? flagValue(args, "--output");
1229
1230
  if (!outPath2) return fail(["--format pdf requires an output path: -o <file.pdf>"]);
1230
1231
  try {
1231
- await toPDF(buildRenderDoc(workbook, byId, "tikz"), outPath2, { parse: parse2 });
1232
+ await toPDF(buildRenderDoc(workbook, byId), outPath2, { parse: parse2 });
1232
1233
  } catch (error) {
1233
1234
  return fail([`PDF export failed: ${errMessage(error)}`]);
1234
1235
  }
1235
1236
  return json ? { stdout: jsonEnvelope("export", true, { path: outPath2 }, []), stderr: "", exitCode: 0 } : { stdout: "", stderr: `Exported ${file} -> ${outPath2}`, exitCode: 0 };
1236
1237
  }
1237
1238
  const fragment = args.includes("--fragment");
1238
- const rendered = format === "tex" ? toTeX(buildRenderDoc(workbook, byId, "tikz"), { parse: parse2, fragment }) : format === "ipynb" ? toIpynb(buildRenderDoc(workbook, byId)) : toHTML(buildRenderDoc(workbook, byId), { parse: parse2 });
1239
+ const rendered = format === "tex" ? toTeX(buildRenderDoc(workbook, byId), { parse: parse2, fragment }) : format === "ipynb" ? toIpynb(buildRenderDoc(workbook, byId)) : toHTML(buildRenderDoc(workbook, byId), { parse: parse2 });
1239
1240
  const bytes = Buffer.byteLength(rendered, "utf-8");
1240
1241
  const outPath = flagValue(args, "-o") ?? flagValue(args, "--output");
1241
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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/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: {
@@ -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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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"}
@@ -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
@@ -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: pre-rendered inline SVG. */
22
- chartSvg?: string;
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;
@@ -1 +1 @@
1
- {"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,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,kDAAkD;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uEAAuE;IACvE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yEAAyE;IACzE,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,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,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"}
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
@@ -11,7 +11,7 @@ import {
11
11
  renameCell,
12
12
  runWorkbookWithTimeout,
13
13
  setMetadata
14
- } from "./chunk-4P6ZKIDU.js";
14
+ } from "./chunk-AFI7I47D.js";
15
15
  import {
16
16
  WorkbookExecutor,
17
17
  buildDependencyGraph,
@@ -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;AAoHvD,mFAAmF;AACnF,wBAAgB,OAAO,CAAC,GAAG,EAAE,SAAS,GAAG,MAAM,CAqB9C"}
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"}
@@ -5,6 +5,19 @@
5
5
  * inline markers are applied to the escaped text, and link hrefs pass a strict
6
6
  * protocol allowlist (not a denylist).
7
7
  */
8
+ /**
9
+ * Convert a small Markdown subset to HTML. The subset is headings, paragraphs, bold,
10
+ * italic, inline code, fenced code, lists, links and horizontal rules.
11
+ *
12
+ * The function escapes `&`, `<` and `>` in the text before it applies the inline
13
+ * markers. A link keeps its `href` only if the target is an `http:`, `https:` or
14
+ * `mailto:` URL, or a relative link that starts with `/`, `./`, `../` or `#`. The
15
+ * function rejects a link that starts with `//`. Otherwise the function keeps only the
16
+ * link text.
17
+ *
18
+ * @param src - The Markdown source.
19
+ * @returns The HTML fragment. An empty string gives an empty string.
20
+ */
8
21
  export declare function markdownToHtml(src: string): string;
9
22
  /** Escape LaTeX specials in a single pass (an escape's own backslash/braces are never re-scanned). */
10
23
  export declare function texEscape(s: string): string;
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../src/markdown.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA2EH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CA+DlD;AAED,sGAAsG;AACtG,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAa3C;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,GAAG,YAAY,GAAG,MAAM,CAEjF;AA+BD,mFAAmF;AACnF,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CA+DjD"}
1
+ {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../src/markdown.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA2EH;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CA+DlD;AAED,sGAAsG;AACtG,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAa3C;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,GAAG,YAAY,GAAG,MAAM,CAEjF;AA+BD,mFAAmF;AACnF,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CA+DjD"}
package/dist/pdf.d.ts CHANGED
@@ -5,8 +5,22 @@
5
5
  */
6
6
  import { type RenderOptions } from '@danielsimonjr/mathts-plot/render';
7
7
  import type { RenderDoc } from './html.js';
8
+ /**
9
+ * Options for `toPDF()`: the render options of the plot package, plus the expression
10
+ * parser for equation cells.
11
+ */
8
12
  export interface ToPdfOptions extends RenderOptions {
9
13
  parse?: (expr: string) => unknown;
10
14
  }
15
+ /**
16
+ * Render a document to a PDF file. The function makes a standalone document with
17
+ * `toTeX()` and gives it to `latexToPdf()` from the plot package.
18
+ *
19
+ * @param doc - The document to render.
20
+ * @param outPath - The path of the PDF file to write.
21
+ * @param options - The expression parser and the render options.
22
+ * @returns A promise that resolves when `latexToPdf()` completes. It rejects if
23
+ * `latexToPdf()` fails.
24
+ */
11
25
  export declare function toPDF(doc: RenderDoc, outPath: string, options?: ToPdfOptions): Promise<void>;
12
26
  //# sourceMappingURL=pdf.d.ts.map
package/dist/pdf.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"pdf.d.ts","sourceRoot":"","sources":["../src/pdf.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAc,KAAK,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAEnF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,MAAM,WAAW,YAAa,SAAQ,aAAa;IACjD,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;CACnC;AAED,wBAAgB,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAGhG"}
1
+ {"version":3,"file":"pdf.d.ts","sourceRoot":"","sources":["../src/pdf.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAc,KAAK,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAEnF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C;;;GAGG;AACH,MAAM,WAAW,YAAa,SAAQ,aAAa;IACjD,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;CACnC;AAED;;;;;;;;;GASG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAGhG"}