@lofcz/tikz 0.0.0-stage → 0.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.
Files changed (118) hide show
  1. package/LICENSE +674 -0
  2. package/NOTICE.md +30 -0
  3. package/README.md +127 -2
  4. package/package.json +56 -4
  5. package/runtime/LICENSE +165 -0
  6. package/runtime/NOTICE.md +32 -0
  7. package/runtime/dist/auto.d.ts +68 -0
  8. package/runtime/dist/auto.js +564 -0
  9. package/runtime/dist/bibtex.mjs +2 -0
  10. package/runtime/dist/bibtex.wasm +0 -0
  11. package/runtime/dist/bundles/cm-tfm/files.br +0 -0
  12. package/runtime/dist/bundles/cm-tfm/files.index.json +1 -0
  13. package/runtime/dist/bundles/cm-tfm/manifest.json +1 -0
  14. package/runtime/dist/bundles/cm-type1/files.br +0 -0
  15. package/runtime/dist/bundles/cm-type1/files.index.json +1 -0
  16. package/runtime/dist/bundles/cm-type1/manifest.json +1 -0
  17. package/runtime/dist/bundles/core/files.br +0 -0
  18. package/runtime/dist/bundles/core/files.index.json +1 -0
  19. package/runtime/dist/bundles/core/manifest.json +1 -0
  20. package/runtime/dist/bundles/hot.json +1 -0
  21. package/runtime/dist/bundles/index.json +80 -0
  22. package/runtime/dist/bundles/latex-core/files.br +0 -0
  23. package/runtime/dist/bundles/latex-core/files.index.json +1 -0
  24. package/runtime/dist/bundles/latex-core/manifest.json +1 -0
  25. package/runtime/dist/bundles/latex-extra/files.br +0 -0
  26. package/runtime/dist/bundles/latex-extra/files.index.json +1 -0
  27. package/runtime/dist/bundles/latex-extra/manifest.json +1 -0
  28. package/runtime/dist/bundles/lm-fonts/files.br +0 -0
  29. package/runtime/dist/bundles/lm-fonts/files.index.json +1 -0
  30. package/runtime/dist/bundles/lm-fonts/manifest.json +1 -0
  31. package/runtime/dist/bundles/luatex/files.br +0 -0
  32. package/runtime/dist/bundles/luatex/files.index.json +1 -0
  33. package/runtime/dist/bundles/luatex/manifest.json +1 -0
  34. package/runtime/dist/bundles/ps-fonts/files.br +0 -0
  35. package/runtime/dist/bundles/ps-fonts/files.index.json +1 -0
  36. package/runtime/dist/bundles/ps-fonts/manifest.json +1 -0
  37. package/runtime/dist/bundles/tex-plain/files.br +0 -0
  38. package/runtime/dist/bundles/tex-plain/files.index.json +1 -0
  39. package/runtime/dist/bundles/tex-plain/manifest.json +1 -0
  40. package/runtime/dist/bundles/tikz-snapshot/files.br +0 -0
  41. package/runtime/dist/bundles/tikz-snapshot/files.index.json +1 -0
  42. package/runtime/dist/bundles/tikz-snapshot/manifest.json +1 -0
  43. package/runtime/dist/bundles-config.d.ts +3 -0
  44. package/runtime/dist/bundles-config.js +16 -0
  45. package/runtime/dist/cli.d.ts +2 -0
  46. package/runtime/dist/cli.js +372 -0
  47. package/runtime/dist/core.d.ts +124 -0
  48. package/runtime/dist/core.js +927 -0
  49. package/runtime/dist/diagnostics.d.ts +53 -0
  50. package/runtime/dist/diagnostics.js +184 -0
  51. package/runtime/dist/dvisvgm.d.ts +20 -0
  52. package/runtime/dist/dvisvgm.js +46 -0
  53. package/runtime/dist/dvisvgm.mjs +2 -0
  54. package/runtime/dist/dvisvgm.wasm +0 -0
  55. package/runtime/dist/figures.d.ts +92 -0
  56. package/runtime/dist/figures.js +250 -0
  57. package/runtime/dist/ghostscript.d.ts +92 -0
  58. package/runtime/dist/ghostscript.js +218 -0
  59. package/runtime/dist/index.d.ts +87 -0
  60. package/runtime/dist/index.js +364 -0
  61. package/runtime/dist/logger.d.ts +48 -0
  62. package/runtime/dist/logger.js +55 -0
  63. package/runtime/dist/luatex.mjs +2 -0
  64. package/runtime/dist/luatex.wasm +0 -0
  65. package/runtime/dist/makeindex.mjs +2 -0
  66. package/runtime/dist/makeindex.wasm +0 -0
  67. package/runtime/dist/mplib.d.ts +106 -0
  68. package/runtime/dist/mplib.js +85 -0
  69. package/runtime/dist/mplib.mjs +2 -0
  70. package/runtime/dist/mplib.wasm +0 -0
  71. package/runtime/dist/node.d.ts +4 -0
  72. package/runtime/dist/node.js +49 -0
  73. package/runtime/dist/postscript.d.ts +21 -0
  74. package/runtime/dist/postscript.js +130 -0
  75. package/runtime/dist/prerender.d.ts +55 -0
  76. package/runtime/dist/prerender.js +106 -0
  77. package/runtime/dist/render/svg.d.ts +20 -0
  78. package/runtime/dist/render/svg.js +96 -0
  79. package/runtime/dist/tex/bridge.d.ts +93 -0
  80. package/runtime/dist/tex/bridge.js +223 -0
  81. package/runtime/dist/tex/cache-key.d.ts +33 -0
  82. package/runtime/dist/tex/cache-key.js +150 -0
  83. package/runtime/dist/tex/mpto.d.ts +60 -0
  84. package/runtime/dist/tex/mpto.js +112 -0
  85. package/runtime/dist/tex/mpx.d.ts +25 -0
  86. package/runtime/dist/tex/mpx.js +54 -0
  87. package/runtime/dist/tex/scanner.d.ts +78 -0
  88. package/runtime/dist/tex/scanner.js +326 -0
  89. package/runtime/dist/tex.mjs +2 -0
  90. package/runtime/dist/tex.wasm +0 -0
  91. package/runtime/dist/texengine.d.ts +35 -0
  92. package/runtime/dist/texengine.js +57 -0
  93. package/runtime/dist/texutils.d.ts +19 -0
  94. package/runtime/dist/texutils.js +60 -0
  95. package/runtime/dist/types.d.ts +376 -0
  96. package/runtime/dist/types.js +6 -0
  97. package/runtime/dist/vfs/bundle.d.ts +88 -0
  98. package/runtime/dist/vfs/bundle.js +315 -0
  99. package/runtime/dist/vfs/lazyfs.d.ts +62 -0
  100. package/runtime/dist/vfs/lazyfs.js +133 -0
  101. package/runtime/dist/worker.d.ts +15 -0
  102. package/runtime/dist/worker.js +143 -0
  103. package/runtime/licenses/COPYING.AFPL +230 -0
  104. package/runtime/licenses/COPYING.makeindex +42 -0
  105. package/runtime/licenses/GPL-3.0.txt +674 -0
  106. package/runtime/licenses/LGPL-3.0.txt +165 -0
  107. package/runtime/licenses/OFL-1.1.txt +93 -0
  108. package/runtime/package.json +1 -0
  109. package/runtime/upstream.json +27 -0
  110. package/src/browser-worker.js +26 -0
  111. package/src/browser.d.ts +18 -0
  112. package/src/browser.js +68 -0
  113. package/src/deploy.d.ts +5 -0
  114. package/src/deploy.js +48 -0
  115. package/src/index.d.ts +28 -0
  116. package/src/index.js +103 -0
  117. package/src/worker.js +15 -0
  118. package/upstream.json +27 -0
@@ -0,0 +1,60 @@
1
+ /**
2
+ * BibTeX's transcript. A warning is `Warning--...`, sometimes followed by
3
+ * `--line N of file F`; an error names its place after three dashes, on its own
4
+ * line or the next one (`I couldn't open database file x.bib` / `---line 6 of file doc.aux`,
5
+ * `Repeated entry---line 1 of file refs.bib`, `I found no style file---while reading file doc.aux`).
6
+ */
7
+ export function parseBibtexLog(blg) {
8
+ const out = [];
9
+ const lines = blg.split(/\r?\n/);
10
+ for (let i = 0; i < lines.length; i++) {
11
+ const l = lines[i];
12
+ const w = /^Warning--(.*)$/.exec(l);
13
+ if (w) {
14
+ const d = { severity: 'warning', source: 'bibtex', message: w[1] };
15
+ const at = /^--line (\d+) of file (.+)$/.exec(lines[i + 1] ?? '');
16
+ if (at) {
17
+ d.line = Number(at[1]);
18
+ d.file = at[2];
19
+ i++;
20
+ }
21
+ out.push(d);
22
+ continue;
23
+ }
24
+ const e = /^(.*?)---(?:line (\d+) of file (.+)|while reading file (.+)|entry "([^"]*)")$/.exec(l);
25
+ if (!e)
26
+ continue;
27
+ let message = e[1] || (lines[i - 1] ?? '');
28
+ if (e[5] !== undefined)
29
+ message = `${message} (entry "${e[5]}")${lines[i + 1] ? ` ${lines[++i]}` : ''}`; // a bad cross reference: the reason is on the next line
30
+ const d = { severity: 'error', source: 'bibtex', message };
31
+ if (e[2]) {
32
+ d.line = Number(e[2]);
33
+ d.file = e[3];
34
+ }
35
+ else if (e[4])
36
+ d.file = e[4];
37
+ out.push(d);
38
+ }
39
+ return out;
40
+ }
41
+ /**
42
+ * makeindex's transcript: `!! Input index error (file = doc.idx, line = 40):` or
43
+ * `## Warning (input = doc.idx, line = 39; output = doc.ind, line = 54):`, each
44
+ * followed by ` -- message`; `!! Input style error` likewise for the .ist.
45
+ */
46
+ export function parseMakeindexLog(ilg) {
47
+ const out = [];
48
+ const lines = ilg.split(/\r?\n/);
49
+ for (let i = 0; i < lines.length; i++) {
50
+ const m = /^(!!|##) (.*?) \((?:file|input) = ([^,;]+), line = (\d+)[;)]/.exec(lines[i]);
51
+ if (!m)
52
+ continue;
53
+ const text = /^\s*-- (.*)$/.exec(lines[i + 1] ?? '');
54
+ if (text)
55
+ i++;
56
+ out.push({ severity: m[1] === '!!' ? 'error' : 'warning', source: 'makeindex', message: text ? text[1] : m[2], file: m[3], line: Number(m[4]) });
57
+ }
58
+ return out;
59
+ }
60
+ //# sourceMappingURL=texutils.js.map
@@ -0,0 +1,376 @@
1
+ /**
2
+ * mp-tikz-wasm — public types. Mirrors reference/api.d.ts (the M7 contract);
3
+ * see docs/08-javascript-api.md for the rationale behind each choice.
4
+ */
5
+ export type BundleName = 'core' | 'cm-tfm' | 'cm-type1' | 'tex-plain' | 'latex-core' | 'latex-extra' | 'opentype' | 'otf-fonts' | 'classico' | 'ghostscript' | 'latex-doc' | (string & {});
6
+ export interface BundleSpec {
7
+ name: string;
8
+ /** URL (browser) or directory (Node) of the bundle's manifest.json. */
9
+ manifestUrl: string;
10
+ blobBaseUrl?: string;
11
+ }
12
+ export type NumberSystem = 'scaled' | 'double' | 'decimal' | 'binary' | 'interval';
13
+ export type TexEngine = 'none' | 'plain' | 'etex' | 'latex' | 'auto';
14
+ export type MpFileType = 'terminal' | 'error' | 'program' | 'log' | 'postscript' | 'bitmap' | 'memfile' | 'metrics' | 'fontmap' | 'font' | 'encoding' | 'text';
15
+ export type PrefetchKind = 'metapost' | 'latex' | 'lualatex' | 'plain';
16
+ /** How much a run writes to the console; each level includes the ones before it. */
17
+ export type LogLevel = 'silent' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
18
+ /** Who produced a log record: an engine's own output, the bundle loader, or the library itself. */
19
+ export type LogSource = 'metapost' | 'tex' | 'dvisvgm' | 'bibtex' | 'makeindex' | 'bundle' | 'host';
20
+ export interface LogRecord {
21
+ level: Exclude<LogLevel, 'silent'>;
22
+ source: LogSource;
23
+ message: string;
24
+ /** Milliseconds since the engine was created. */
25
+ time: number;
26
+ }
27
+ export interface MetaPostOptions {
28
+ /** Bundles to load. Default: ['core', 'cm-tfm', 'cm-type1', 'tex-plain', 'latex-core'] when a bundleBaseUrl is known. */
29
+ bundles?: (BundleName | BundleSpec)[];
30
+ /** Base URL (browser) or directory (Node) under which `<bundle>/manifest.json` lives. */
31
+ bundleBaseUrl?: string;
32
+ /** Node only: a texmf directory to mount directly (mirrors build/texmf). Overrides bundles. */
33
+ texmfDir?: string;
34
+ numberSystem?: NumberSystem;
35
+ tex?: TexEngine;
36
+ texPreamble?: string;
37
+ deterministic?: boolean;
38
+ randomSeed?: number;
39
+ interaction?: 'batch' | 'nonstop' | 'scroll';
40
+ haltOnError?: boolean;
41
+ /** false selects the classic .mpx path instead of the make_text path. */
42
+ extensions?: boolean;
43
+ /** Append `end.` after `input <job>` so a file that forgets `end` still finishes cleanly (default true). */
44
+ autoEnd?: boolean;
45
+ memoryLimitBytes?: number;
46
+ /** A run is terminated when it makes no progress (no engine phase change, no file fetched) for this long.
47
+ * Default 20 000 ms; worker only. It is a stall limit, not a total: a first run on a slow host may fetch
48
+ * a hundred files one after another and is not cut short for it. */
49
+ timeoutMs?: number;
50
+ /** Fetch, in parallel, the bundle files a first run of these kinds needs, right after the engine starts
51
+ * (from `bundles/hot.json`, recorded at build time). On a high-latency host this turns ~90 serial
52
+ * round trips into a few seconds. The drop-in tags do it automatically for the kinds the page contains. */
53
+ prefetch?: PrefetchKind[];
54
+ texTimeoutMs?: number;
55
+ maxTexRuns?: number;
56
+ runScript?: (code: string) => string;
57
+ makeText?: (text: string, verbatim: boolean) => string | undefined;
58
+ onFindFile?: (name: string, type: MpFileType, mode: 'r' | 'w') => string | undefined;
59
+ cache?: 'memory' | false;
60
+ /** How much each run writes to the console (default 'warn'). 'silent': nothing. 'error': the errors of every run
61
+ * (MetaPost, TeX, dvisvgm, bundles). 'warn': plus warnings. 'info': plus one line per run and per engine pass,
62
+ * with timings. 'debug': plus the engines' own terminal output, line by line, as it is written. 'trace': plus
63
+ * every file looked up or fetched and every label-cache lookup. `mp.logLevel = 'debug'` changes it at any time. */
64
+ logLevel?: LogLevel;
65
+ /** Receives every record the level admits, instead of the console (also the 'record' event). */
66
+ logger?: (record: LogRecord) => void;
67
+ /** Every line the engines print, whatever the level (also the 'log' event). */
68
+ log?: (line: string) => void;
69
+ wasmUrls?: {
70
+ mplib?: string;
71
+ tex?: string;
72
+ };
73
+ /**
74
+ * PostScript in LaTeX documents (PSTricks, EPS images, `\special{ps: …}`,
75
+ * graphicx's rotation and scaling under its dvips driver) through a separate
76
+ * Ghostscript module (AGPL), loaded only when a document's DVI carries such
77
+ * PostScript. On by default when the `ghostscript` bundle is in `bundles`;
78
+ * set it for `texmfDir`, which has no bundle list.
79
+ */
80
+ ghostscript?: boolean;
81
+ /** Where the Ghostscript module's gs.mjs and gs.wasm are; default `ghostscript/` beside index.js. */
82
+ ghostscriptBaseUrl?: string;
83
+ /** Pre-loaded Emscripten module factories (e.g. for a single-file build); in-process mode only. */
84
+ modules?: {
85
+ mplib?: (opts?: Record<string, unknown>) => Promise<any>;
86
+ tex?: (opts?: Record<string, unknown>) => Promise<any>;
87
+ luatex?: (opts?: Record<string, unknown>) => Promise<any>;
88
+ dvisvgm?: (opts?: Record<string, unknown>) => Promise<any>;
89
+ ghostscript?: (opts?: Record<string, unknown>) => Promise<any>;
90
+ bibtex?: (opts?: Record<string, unknown>) => Promise<any>;
91
+ makeindex?: (opts?: Record<string, unknown>) => Promise<any>;
92
+ };
93
+ /** Custom bundle I/O (e.g. files embedded in the page); in-process mode only. */
94
+ bundleIO?: {
95
+ fetch(url: string): Promise<Uint8Array>;
96
+ fetchSync?: (url: string) => Uint8Array;
97
+ fetchJson(url: string): Promise<unknown>;
98
+ };
99
+ /** Run in-process instead of in a Web Worker (default: worker in browsers, in-process in Node). */
100
+ worker?: boolean;
101
+ /** Default for latex()'s snapshot option. Node: 'auto' (tikz.fmt from local files is free). Browser: 'none',
102
+ * because the 5.8 MB format does not compress and costs more to download than the files it replaces
103
+ * (2.5 MB gzipped); set 'auto' when many TikZ figures amortise it or the format is already cached. */
104
+ snapshot?: 'auto' | 'none';
105
+ }
106
+ export type OutputFormat = 'svg' | 'eps' | 'json' | 'none';
107
+ export interface RunOptions {
108
+ format?: OutputFormat | OutputFormat[];
109
+ prologues?: 0 | 1 | 2 | 3;
110
+ procset?: 0 | 1;
111
+ files?: Record<string, string | Uint8Array>;
112
+ jobName?: string;
113
+ internals?: Record<string, number | string>;
114
+ tex?: TexEngine;
115
+ svg?: SvgPostOptions;
116
+ signal?: AbortSignal;
117
+ }
118
+ export interface SvgPostOptions {
119
+ /** Round numbers to this many decimals (default 3). false = leave MetaPost's %.6f. */
120
+ precision?: number | false;
121
+ /** Prefix glyph ids so several figures can be inlined on one page (default: per figure). */
122
+ idPrefix?: string | false;
123
+ /** Rewrite xlink:href to href. Default false (keep upstream output). */
124
+ modernHref?: boolean;
125
+ /** Add role="img" and a <title>. */
126
+ title?: string;
127
+ /** Units for width/height: 'pt' keeps MetaPost's, 'px' converts at 96/72, 'none' drops them. */
128
+ units?: 'pt' | 'px' | 'none';
129
+ }
130
+ export type Status = 'ok' | 'warning' | 'error' | 'fatal';
131
+ export interface RunResult {
132
+ status: Status;
133
+ history: 0 | 1 | 2 | 3 | 4;
134
+ figures: FigureResult[];
135
+ log: string;
136
+ texLog?: string;
137
+ diagnostics: Diagnostic[];
138
+ stats: RunStats;
139
+ artifacts: Record<string, Uint8Array>;
140
+ }
141
+ export interface FigureResult {
142
+ charcode: number;
143
+ bbox: [number, number, number, number];
144
+ width: number;
145
+ height: number;
146
+ depth: number;
147
+ italicCorrection: number;
148
+ svg?: string;
149
+ eps?: string;
150
+ json?: Figure;
151
+ }
152
+ export interface RunStats {
153
+ totalMs: number;
154
+ metapostMs: number;
155
+ texMs: number;
156
+ texRuns: number;
157
+ metapostRuns: number;
158
+ snippetCacheHits: number;
159
+ snippetCacheMisses: number;
160
+ }
161
+ export interface Diagnostic {
162
+ severity: 'error' | 'warning';
163
+ source: 'metapost' | 'tex' | 'bundle' | 'host' | 'bibtex' | 'makeindex';
164
+ message: string;
165
+ help?: string[];
166
+ file?: string;
167
+ line?: number;
168
+ column?: number;
169
+ snippet?: string;
170
+ }
171
+ export interface ProgressEvent {
172
+ /** `fetching`: a bundle file is being fetched on demand (Worker only); `detail` is its name. */
173
+ phase: 'loading' | 'fetching' | 'scanning' | 'typesetting' | 'running' | 'rendering';
174
+ detail?: string;
175
+ current?: number;
176
+ total?: number;
177
+ }
178
+ export interface Figure {
179
+ charcode: number;
180
+ bbox: [number, number, number, number];
181
+ width: number;
182
+ height: number;
183
+ depth: number;
184
+ italicCorrection: number;
185
+ objects: GraphicObject[];
186
+ }
187
+ export type GraphicObject = FillObject | StrokeObject | TextObject | ClipObject | BoundsObject | SpecialObject;
188
+ export interface Knot {
189
+ x: number;
190
+ y: number;
191
+ lx: number;
192
+ ly: number;
193
+ rx: number;
194
+ ry: number;
195
+ leftType: KnotType;
196
+ rightType: KnotType;
197
+ }
198
+ export type KnotType = 0 | 1 | 2 | 3 | 4 | 5;
199
+ export interface Color {
200
+ model: 'none' | 'grey' | 'rgb' | 'cmyk';
201
+ values: number[];
202
+ }
203
+ interface ObjectBase {
204
+ prescript?: string;
205
+ postscript?: string;
206
+ }
207
+ export interface FillObject extends ObjectBase {
208
+ type: 'fill';
209
+ path: Knot[];
210
+ closed: boolean;
211
+ htap?: Knot[];
212
+ pen?: Knot[];
213
+ color: Color;
214
+ ljoin: number;
215
+ miterlimit: number;
216
+ }
217
+ export interface StrokeObject extends ObjectBase {
218
+ type: 'stroke';
219
+ path: Knot[];
220
+ closed: boolean;
221
+ pen?: Knot[];
222
+ color: Color;
223
+ ljoin: number;
224
+ lcap: number;
225
+ miterlimit: number;
226
+ dash?: {
227
+ offset: number;
228
+ pattern: number[];
229
+ };
230
+ }
231
+ export interface TextObject extends ObjectBase {
232
+ type: 'text';
233
+ text: string;
234
+ font: string;
235
+ designSize: number;
236
+ color: Color;
237
+ width: number;
238
+ height: number;
239
+ depth: number;
240
+ transform: [number, number, number, number, number, number];
241
+ }
242
+ export interface ClipObject {
243
+ type: 'startClip' | 'stopClip';
244
+ path?: Knot[];
245
+ }
246
+ export interface BoundsObject {
247
+ type: 'startBounds' | 'stopBounds';
248
+ path?: Knot[];
249
+ }
250
+ export interface SpecialObject extends ObjectBase {
251
+ type: 'special';
252
+ script: string;
253
+ }
254
+ export interface LatexRunOptions {
255
+ /** Which engine and format run the document. Default 'latex' (pdfTeX in DVI mode). 'plain' is
256
+ * plain TeX with e-TeX extensions (TeX Live's etex; PGF needs them); 'tex' is Knuth-compatible
257
+ * plain.fmt. 'lualatex' and 'luatex' run LuaTeX in DVI mode (TeX Live's dvilualatex/dviluatex),
258
+ * which is what TikZ's graphdrawing library and \directlua need; text is set in the Type 1
259
+ * fonts unless the `opentype` bundle is loaded, which adds luaotfload and so \usepackage{fontspec}
260
+ * with real OTF/TTF faces. 'auto' picks 'lualatex' when the source uses
261
+ * graphdrawing, \directlua or luacode, 'plain' for a \bye document, 'latex' otherwise. */
262
+ engine?: 'latex' | 'plain' | 'etex' | 'tex' | 'lualatex' | 'luatex' | 'auto';
263
+ /** What the run produces: 'svg' (default; DVI, then one SVG per page through dvisvgm) or 'pdf'
264
+ * (pdfTeX's or LuaTeX's own PDF back end: `pdf` in the result holds the document, `pages` is
265
+ * empty, and the SVG options -- fonts, bbox, dvisvgmArgs, svg, pages -- do not apply). */
266
+ output?: 'svg' | 'pdf';
267
+ /** PGF system driver. 'dvisvgm' (default) prepends \def\pgfsysdriver{pgfsys-dvisvgm.def} so TikZ
268
+ * draws with SVG specials -- with output 'pdf', the driver that matches it instead
269
+ * (pgfsys-pdftex.def or pgfsys-luatex.def); 'auto' leaves PGF's own choice (in DVI mode dvips,
270
+ * whose PostScript specials need Ghostscript and are ignored here). */
271
+ pgfDriver?: 'dvisvgm' | 'auto';
272
+ /** The pre-warmed format: 'auto' (default) runs documents that load tikz, pgfplots or tikz-cd with
273
+ * tikz.fmt (LaTeX with PGF, its common libraries and pgfplots already loaded);
274
+ * 'tikz' forces it, 'none' always uses plain latex.fmt. Requires the tikz-snapshot bundle.
275
+ * Never used with output 'pdf': the snapshot has PGF's dvisvgm driver built in. */
276
+ snapshot?: 'auto' | 'tikz' | 'none';
277
+ /** The date and time TeX sees: \today, \time, babel's dates, the PDF's CreationDate and ModDate.
278
+ * 'fixed' (default): 1 January 2025, 00:00 UTC, so the same source always gives the same bytes
279
+ * (what figures and tests want). 'now': the clock, in the local time zone, as a desktop TeX
280
+ * run (what a person exporting a document wants). A Date, or milliseconds since 1970 as
281
+ * Date.now() gives: that instant, \today included, in UTC. */
282
+ date?: 'fixed' | 'now' | Date | number;
283
+ /** Files to place next to the document (images, .sty, .tex inputs, the previous pass's .aux).
284
+ * They stay on the instance for later runs, as addFiles' do, until removeFiles takes them off. */
285
+ files?: Record<string, string | Uint8Array>;
286
+ jobName?: string;
287
+ /** Which DVI pages to convert: 'all' or a 1-based page number. Default 'all'. */
288
+ pages?: 'all' | number;
289
+ /** How text is emitted: 'paths' (glyph outlines, self-contained; default) or 'woff2' (embedded web fonts). */
290
+ fonts?: 'paths' | 'woff2';
291
+ /** Bounding box for each page: dvisvgm's --bbox value ('min' default, 'preview', 'papersize', 'dvi', or explicit). */
292
+ bbox?: string;
293
+ /** Extra dvisvgm command-line arguments, appended verbatim. */
294
+ dvisvgmArgs?: string[];
295
+ svg?: SvgPostOptions;
296
+ signal?: AbortSignal;
297
+ }
298
+ export interface LatexResult {
299
+ status: Status;
300
+ /** One SVG per DVI page (empty with output 'pdf'). */
301
+ pages: string[];
302
+ /** The PDF, with output 'pdf' (absent when TeX wrote none). */
303
+ pdf?: Uint8Array;
304
+ log: string;
305
+ texLog: string;
306
+ dvisvgmLog: string;
307
+ diagnostics: Diagnostic[];
308
+ stats: {
309
+ totalMs: number;
310
+ texMs: number;
311
+ dvisvgmMs: number;
312
+ texSetupMs: number;
313
+ texMainMs: number;
314
+ instantiateMs: number;
315
+ };
316
+ /** The format that ran the document ('latex', 'tikz', 'etex', 'plain', 'dvilualatex', 'dviluatex'). */
317
+ format: string;
318
+ /** The files TeX wrote beside the document (.aux, .toc, .out, .idx, ...), apart from the
319
+ * output and the .log. A file passed in `files` is among them when TeX wrote it again, so one
320
+ * pass's artifacts are the next pass's `files`, however many passes there are. */
321
+ artifacts: Record<string, Uint8Array>;
322
+ }
323
+ export interface BibtexOptions {
324
+ /** The .aux file's name without .aux, as `bibtex doc` takes it. Default 'doc', latex()'s default jobName. */
325
+ jobName?: string;
326
+ /** Files to place beside it: the .aux (latex()'s artifacts), the .bib databases, a .bst of the
327
+ * document's own. They stay on the instance, as latex()'s `files` do, until removeFiles. The
328
+ * styles TeX Live ships (plainnat, apalike, plain, unsrt, ...) come from the `latex-doc` bundle. */
329
+ files?: Record<string, string | Uint8Array>;
330
+ /** More command-line options, before the name: ['-min-crossrefs=3']. */
331
+ args?: string[];
332
+ }
333
+ export interface MakeindexOptions {
334
+ /** The index file to sort, as `makeindex doc.idx` takes it. Default 'doc.idx'; imakeidx's
335
+ * \makeindex[name=authors] writes authors.idx. */
336
+ input?: string;
337
+ /** An index style (makeindex -s): a file passed in `files`, or one from the `latex-doc` bundle. */
338
+ style?: string;
339
+ /** Files to place beside it (the .idx: latex()'s artifacts); they stay on the instance, as latex()'s do. */
340
+ files?: Record<string, string | Uint8Array>;
341
+ /** More command-line options, before the input: ['-l'], ['-g'], ['-o', 'other.ind']. */
342
+ args?: string[];
343
+ }
344
+ export interface ToolResult {
345
+ /** 'ok'; 'warning' when the .blg or .ilg has warnings (or makeindex rejected entries), though
346
+ * the program exited 0; 'error' when it stopped or reported errors (BibTeX exit 1 or 2,
347
+ * makeindex exit 1); 'fatal' after one of BibTeX's fatal errors (exit 3). */
348
+ status: Status;
349
+ exitCode: number;
350
+ /** What the program printed. */
351
+ log: string;
352
+ /** The files it wrote: BibTeX doc.bbl and doc.blg, makeindex doc.ind and doc.ilg (or what -o and -t name).
353
+ * Pass them to the next latex() run with the previous run's artifacts. */
354
+ artifacts: Record<string, Uint8Array>;
355
+ /** The .blg's or .ilg's warnings and errors, with the file and line they name. */
356
+ diagnostics: Diagnostic[];
357
+ stats: {
358
+ totalMs: number;
359
+ };
360
+ }
361
+ /** The bundle manifest format (docs/06 §3). Paths are relative to the texmf root. */
362
+ export interface BundleManifest {
363
+ name: string;
364
+ version: string;
365
+ texlive?: string;
366
+ /** relative path -> size in bytes (and optional sha256) */
367
+ files: Record<string, {
368
+ size: number;
369
+ sha?: string;
370
+ }>;
371
+ /** files fetched together with the manifest */
372
+ eager?: string[];
373
+ /** directories that exist even if empty */
374
+ dirs?: string[];
375
+ }
376
+ export {};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * mp-tikz-wasm — public types. Mirrors reference/api.d.ts (the M7 contract);
3
+ * see docs/08-javascript-api.md for the rationale behind each choice.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,88 @@
1
+ /**
2
+ * bundle.ts — texmf bundles: manifest + files (docs/06 §3–§4).
3
+ *
4
+ * A bundle is a directory (or URL prefix) holding `manifest.json` and the
5
+ * files themselves under `files/<relative path>`. The BundleSet merges any
6
+ * number of bundles into one virtual texmf tree rooted at /texmf.
7
+ *
8
+ * Loading strategies:
9
+ * - Node: files are read with fs.readFileSync on demand (always sync).
10
+ * - Worker: files are fetched with a synchronous XMLHttpRequest on demand.
11
+ * - Main thread: no sync I/O; everything reachable is prefetched with
12
+ * fetch() by `prefetchAll()` before the engine runs.
13
+ */
14
+ import type { BundleManifest, BundleSpec } from '../types.js';
15
+ import { type EmscriptenFS } from './lazyfs.js';
16
+ import { Logger } from '../logger.js';
17
+ export interface BundleFile {
18
+ bundle: string;
19
+ path: string;
20
+ size: number;
21
+ sha?: string;
22
+ url: string;
23
+ }
24
+ export interface BundleIO {
25
+ /** async fetch of bytes */
26
+ fetch(url: string): Promise<Uint8Array>;
27
+ /** sync fetch of bytes, or undefined if this environment cannot do sync I/O */
28
+ fetchSync?: (url: string) => Uint8Array;
29
+ /** fetch + parse JSON */
30
+ fetchJson(url: string): Promise<unknown>;
31
+ }
32
+ export declare const TEXMF_ROOT = "/texmf";
33
+ export declare class BundleSet {
34
+ private io;
35
+ readonly files: Map<string, BundleFile>;
36
+ readonly byName: Map<string, BundleFile[]>;
37
+ readonly manifests: {
38
+ spec: BundleSpec;
39
+ manifest: BundleManifest;
40
+ base: string;
41
+ }[];
42
+ private cache;
43
+ private negative;
44
+ /** The files a first run of each kind touches (`bundles/hot.json`, written by scripts/make-hotlists.mjs). */
45
+ hot: Record<string, string[]>;
46
+ /** Where fetches are reported: prefetch summaries at info, on-demand loads at debug, every file at trace. */
47
+ logger: Logger;
48
+ constructor(io: BundleIO);
49
+ /** Load a manifest; `spec.manifestUrl` is the bundle directory/URL (containing manifest.json). */
50
+ add(spec: BundleSpec): Promise<void>;
51
+ private addLoaded;
52
+ /** Add several bundles: the manifests are fetched in parallel, then merged in the given order (first bundle wins). */
53
+ addAll(specs: BundleSpec[]): Promise<void>;
54
+ /** Load the hot lists; optional, so a missing file is not an error. */
55
+ loadHot(url: string): Promise<void>;
56
+ /** Fetch, in parallel, every file the hot lists name for these kinds that is not in memory yet. Returns how many. */
57
+ prefetchHot(kinds: string[], concurrency?: number): Promise<number>;
58
+ /** Every manifest's `eager` list, fetched into memory. */
59
+ prefetchEager(): Promise<void>;
60
+ /** Fetch every file in the set (for environments without sync I/O). */
61
+ prefetchAll(filter?: (f: BundleFile) => boolean): Promise<void>;
62
+ fetchAsync(f: BundleFile): Promise<Uint8Array>;
63
+ /** Synchronous bytes for a file: from memory, else via fetchSync. Throws if impossible. */
64
+ fetchSyncFile(f: BundleFile): Uint8Array;
65
+ get canFetchSync(): boolean;
66
+ has(path: string): boolean;
67
+ /**
68
+ * Materialise the tree in the Emscripten FS under /texmf, plus an ls-R
69
+ * database so kpathsea never has to walk directories. Directories are
70
+ * created on demand: the root gets a lookup hook that creates a child
71
+ * directory or a lazy file the first time anything asks for it, so a run
72
+ * pays for the handful of files it touches, not for the whole tree
73
+ * (installing every node eagerly cost ~60 ms per TeX run).
74
+ */
75
+ install(FS: EmscriptenFS, root?: string): void;
76
+ private lsRText?;
77
+ private indexCache?;
78
+ /** directory -> immediate children, for the on-demand tree */
79
+ private index;
80
+ /** kpathsea ls-R database text for the merged tree. */
81
+ lsR(): string;
82
+ /** Find bundle files by bare name (e.g. "cmr10.tfm"), optionally restricted to a directory prefix. */
83
+ lookup(name: string, prefixes?: string[]): BundleFile | undefined;
84
+ noteMiss(key: string): void;
85
+ isMiss(key: string): boolean;
86
+ }
87
+ /** Browser I/O: fetch() plus a synchronous XHR that only works inside a Worker. */
88
+ export declare function browserIO(): BundleIO;