@danielsimonjr/mathts-workbook 0.3.24 → 0.4.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/dist/{chunk-RKUVI3F6.js → chunk-ZVCYWKM5.js} +1 -1
- package/dist/cli.js +12 -1
- package/dist/index.d.ts +20 -1
- package/dist/index.js +19 -1
- package/package.json +4 -4
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-ZVCYWKM5.js";
|
|
19
19
|
import {
|
|
20
20
|
buildDependencyGraph,
|
|
21
21
|
createExecutor,
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
} from "./chunk-M2K7SQG2.js";
|
|
32
32
|
|
|
33
33
|
// src/cli.ts
|
|
34
|
+
import { createHash } from "crypto";
|
|
34
35
|
import { readFileSync, writeFileSync, lstatSync, realpathSync } from "fs";
|
|
35
36
|
import { pathToFileURL } from "url";
|
|
36
37
|
import { basename } from "path";
|
|
@@ -599,6 +600,7 @@ mtsw - MathTS Workbook CLI
|
|
|
599
600
|
|
|
600
601
|
Usage:
|
|
601
602
|
mtsw run <file> [-c <id>] [-v] [--json] [--write] [--timeout <ms>]
|
|
603
|
+
[--expect-hash <sha256>]
|
|
602
604
|
Execute a workbook (or one cell + its
|
|
603
605
|
deps with -c/--cell). -v: events,
|
|
604
606
|
--json: machine output, --write: persist
|
|
@@ -607,6 +609,8 @@ Usage:
|
|
|
607
609
|
kills it (WorkbookTimeoutError) if it
|
|
608
610
|
exceeds the budget \u2014 a runaway cell can't
|
|
609
611
|
hang the process. Incompatible with -c/-v.
|
|
612
|
+
--expect-hash refuses to run unless the
|
|
613
|
+
file's SHA-256 matches (optimistic lock).
|
|
610
614
|
mtsw describe <file> [--json] Structured document model (cells, graph)
|
|
611
615
|
mtsw validate <file> [--json] Validate structure (ids, deps, cycles)
|
|
612
616
|
mtsw graph <file> [-f mermaid|dot] Print the dependency graph
|
|
@@ -790,6 +794,13 @@ async function runCommand(args) {
|
|
|
790
794
|
}
|
|
791
795
|
const read = readFile(file);
|
|
792
796
|
if (read.error) return fail([read.error]);
|
|
797
|
+
const expectHash = flagValue(args, "--expect-hash");
|
|
798
|
+
if (expectHash !== void 0) {
|
|
799
|
+
const actual = createHash("sha256").update(read.content, "utf8").digest("hex");
|
|
800
|
+
if (actual.toLowerCase() !== expectHash.toLowerCase()) {
|
|
801
|
+
return fail([`--expect-hash mismatch: file SHA-256 is ${actual}, expected ${expectHash}`]);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
793
804
|
const parsed = parseWorkbook(read.content);
|
|
794
805
|
if (!parsed.success) {
|
|
795
806
|
const problems2 = parsed.errors ?? [];
|
package/dist/index.d.ts
CHANGED
|
@@ -431,6 +431,25 @@ interface HandleResult {
|
|
|
431
431
|
}
|
|
432
432
|
declare function handleRequest(session: Session, request: JsonRpcRequest): Promise<HandleResult>;
|
|
433
433
|
|
|
434
|
+
/**
|
|
435
|
+
* MathML → SVG typesetting. Wraps a MathML fragment in an SVG document so
|
|
436
|
+
* rendered workbooks can emit SVG (browsers, rsvg, inkscape) instead of raw
|
|
437
|
+
* MathML. The glyph metrics are a conservative estimate — consumers that need
|
|
438
|
+
* pixel-perfect layout should typeset with a real engine; this is the
|
|
439
|
+
* no-dependency path the CLI/export uses.
|
|
440
|
+
*/
|
|
441
|
+
interface MathSvgOptions {
|
|
442
|
+
/** Display (`block`) or inline. Default `block`. */
|
|
443
|
+
display?: 'block' | 'inline';
|
|
444
|
+
/** Extra padding in CSS pixels. Default 4. */
|
|
445
|
+
padding?: number;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Wrap a MathML fragment (or a full `<math>` document) in an SVG with a
|
|
449
|
+
* `foreignObject` so the math remains selectable and scalable.
|
|
450
|
+
*/
|
|
451
|
+
declare function mathMLToSVG(mathml: string, options?: MathSvgOptions): string;
|
|
452
|
+
|
|
434
453
|
/**
|
|
435
454
|
* Shared message/result shapes between `timeout-runner.ts` (the coordinator,
|
|
436
455
|
* running on the caller's thread) and `run-worker.ts` (the `worker_threads`
|
|
@@ -480,4 +499,4 @@ declare class WorkbookTimeoutError extends Error {
|
|
|
480
499
|
*/
|
|
481
500
|
declare function runWorkbookWithTimeout(source: string, options: RunWorkbookWithTimeoutOptions): Promise<SerializedRunResult>;
|
|
482
501
|
|
|
483
|
-
export { type Cell, type CellPosition, type CellResult, type CellType, type ExecutionMode, type ParseResult, type RemoveResult, type RunResult, type RunWorkbookWithTimeoutOptions, type RuntimeConfig, SCHEMA_VERSION, type SerializedCellResult, type SerializedRunResult, Session, VERSION, type Workbook, type WorkbookEvent, WorkbookExecutor, type WorkbookMetadata, WorkbookTimeoutError, addCell, buildDependencyGraph, createExecutor, detectCellType, detectCycles, editCell, formatResult, getAncestors, getDependents, handleRequest, moveCell, parseWorkbook, removeCell, renameCell, runWorkbookWithTimeout, serializeWorkbook, setMetadata, stripOutputs, toMermaid, topologicalSort };
|
|
502
|
+
export { type Cell, type CellPosition, type CellResult, type CellType, type ExecutionMode, type MathSvgOptions, type ParseResult, type RemoveResult, type RunResult, type RunWorkbookWithTimeoutOptions, type RuntimeConfig, SCHEMA_VERSION, type SerializedCellResult, type SerializedRunResult, Session, VERSION, type Workbook, type WorkbookEvent, WorkbookExecutor, type WorkbookMetadata, WorkbookTimeoutError, addCell, buildDependencyGraph, createExecutor, detectCellType, detectCycles, editCell, formatResult, getAncestors, getDependents, handleRequest, mathMLToSVG, moveCell, parseWorkbook, removeCell, renameCell, runWorkbookWithTimeout, serializeWorkbook, setMetadata, stripOutputs, toMermaid, topologicalSort };
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
renameCell,
|
|
12
12
|
runWorkbookWithTimeout,
|
|
13
13
|
setMetadata
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-ZVCYWKM5.js";
|
|
15
15
|
import {
|
|
16
16
|
WorkbookExecutor,
|
|
17
17
|
buildDependencyGraph,
|
|
@@ -27,6 +27,23 @@ import {
|
|
|
27
27
|
toMermaid,
|
|
28
28
|
topologicalSort
|
|
29
29
|
} from "./chunk-M2K7SQG2.js";
|
|
30
|
+
|
|
31
|
+
// src/svg-math.ts
|
|
32
|
+
function mathMLToSVG(mathml, options = {}) {
|
|
33
|
+
const display = options.display ?? "block";
|
|
34
|
+
const pad = options.padding ?? 4;
|
|
35
|
+
const inner = mathml.includes("<math") ? mathml : `<math xmlns="http://www.w3.org/1998/Math/MathML" display="${display}">${mathml}</math>`;
|
|
36
|
+
const text = inner.replace(/<[^>]+>/g, "");
|
|
37
|
+
const width = Math.max(24, text.length * 10 + pad * 2);
|
|
38
|
+
const height = display === "block" ? 36 + pad * 2 : 20 + pad * 2;
|
|
39
|
+
return [
|
|
40
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">`,
|
|
41
|
+
`<foreignObject x="${pad}" y="${pad}" width="${width - pad * 2}" height="${height - pad * 2}">`,
|
|
42
|
+
inner,
|
|
43
|
+
`</foreignObject>`,
|
|
44
|
+
`</svg>`
|
|
45
|
+
].join("");
|
|
46
|
+
}
|
|
30
47
|
export {
|
|
31
48
|
SCHEMA_VERSION,
|
|
32
49
|
Session,
|
|
@@ -43,6 +60,7 @@ export {
|
|
|
43
60
|
getAncestors,
|
|
44
61
|
getDependents,
|
|
45
62
|
handleRequest,
|
|
63
|
+
mathMLToSVG,
|
|
46
64
|
moveCell,
|
|
47
65
|
parseWorkbook,
|
|
48
66
|
removeCell,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danielsimonjr/mathts-workbook",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Scientific workbook runtime for MathTS (.mtsw format)",
|
|
5
5
|
"author": "Daniel Simon Jr.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@danielsimonjr/mathts-core": "^0.14.1",
|
|
38
38
|
"@danielsimonjr/mathts-expression": "^0.7.1",
|
|
39
|
-
"@danielsimonjr/mathts-functions": "^0.
|
|
40
|
-
"@danielsimonjr/mathts-plot": "^0.4.
|
|
39
|
+
"@danielsimonjr/mathts-functions": "^0.64.0",
|
|
40
|
+
"@danielsimonjr/mathts-plot": "^0.4.2",
|
|
41
41
|
"yaml": "^2.3.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@types/node": "^
|
|
44
|
+
"@types/node": "^26.2.0",
|
|
45
45
|
"tsup": "^8.0.0",
|
|
46
46
|
"typescript": "^5.3.0",
|
|
47
47
|
"vitest": "^4.1.10"
|