@danielsimonjr/sciengjs 0.8.0 → 0.10.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 (116) hide show
  1. package/README.md +27 -4
  2. package/THIRD_PARTY_NOTICES.md +65 -4
  3. package/dist/core.js +2 -0
  4. package/dist/core.js.map +1 -1
  5. package/dist/errors.d.ts +2 -0
  6. package/dist/errors.js +4 -0
  7. package/dist/errors.js.map +1 -1
  8. package/dist/graph/backend-pdf.js +3 -2
  9. package/dist/graph/backend-pdf.js.map +1 -1
  10. package/dist/graph/backend-png.js +3 -2
  11. package/dist/graph/backend-png.js.map +1 -1
  12. package/dist/graph/backend-svg.js +3 -2
  13. package/dist/graph/backend-svg.js.map +1 -1
  14. package/dist/graph/dot.d.ts +0 -2
  15. package/dist/graph/dot.js +0 -4
  16. package/dist/graph/dot.js.map +1 -1
  17. package/dist/graph/text.d.ts +12 -0
  18. package/dist/graph/text.js +21 -0
  19. package/dist/graph/text.js.map +1 -0
  20. package/dist/mermaid/backend-pdf.js +2 -1
  21. package/dist/mermaid/backend-pdf.js.map +1 -1
  22. package/dist/mermaid/backend-png.js +2 -1
  23. package/dist/mermaid/backend-png.js.map +1 -1
  24. package/dist/mermaid/backend-svg.js +2 -1
  25. package/dist/mermaid/backend-svg.js.map +1 -1
  26. package/dist/mermaid/class.js +3 -7
  27. package/dist/mermaid/class.js.map +1 -1
  28. package/dist/mermaid/common.d.ts +0 -10
  29. package/dist/mermaid/common.js +2 -16
  30. package/dist/mermaid/common.js.map +1 -1
  31. package/dist/mermaid/sequence-layout.js +1 -1
  32. package/dist/mermaid/sequence-layout.js.map +1 -1
  33. package/dist/mermaid/sequence.js +2 -1
  34. package/dist/mermaid/sequence.js.map +1 -1
  35. package/dist/mermaid/state.js +3 -1
  36. package/dist/mermaid/state.js.map +1 -1
  37. package/dist/registry.js +6 -0
  38. package/dist/registry.js.map +1 -1
  39. package/dist/sysml/backend-pdf.d.ts +3 -0
  40. package/dist/sysml/backend-pdf.js +10 -0
  41. package/dist/sysml/backend-pdf.js.map +1 -0
  42. package/dist/sysml/backend-png.d.ts +6 -0
  43. package/dist/sysml/backend-png.js +19 -0
  44. package/dist/sysml/backend-png.js.map +1 -0
  45. package/dist/sysml/backend-svg.d.ts +3 -0
  46. package/dist/sysml/backend-svg.js +8 -0
  47. package/dist/sysml/backend-svg.js.map +1 -0
  48. package/dist/sysml/index.d.ts +8 -0
  49. package/dist/sysml/index.js +9 -0
  50. package/dist/sysml/index.js.map +1 -0
  51. package/dist/sysml/parse.d.ts +99 -0
  52. package/dist/sysml/parse.js +480 -0
  53. package/dist/sysml/parse.js.map +1 -0
  54. package/dist/sysml/render.d.ts +7 -0
  55. package/dist/sysml/render.js +11 -0
  56. package/dist/sysml/render.js.map +1 -0
  57. package/dist/sysml/tokens.d.ts +14 -0
  58. package/dist/sysml/tokens.js +93 -0
  59. package/dist/sysml/tokens.js.map +1 -0
  60. package/dist/sysml/views.d.ts +16 -0
  61. package/dist/sysml/views.js +156 -0
  62. package/dist/sysml/views.js.map +1 -0
  63. package/dist/tex/backend-pdf.d.ts +3 -0
  64. package/dist/tex/backend-pdf.js +10 -0
  65. package/dist/tex/backend-pdf.js.map +1 -0
  66. package/dist/tex/backend-png.d.ts +6 -0
  67. package/dist/tex/backend-png.js +19 -0
  68. package/dist/tex/backend-png.js.map +1 -0
  69. package/dist/tex/backend-svg.d.ts +3 -0
  70. package/dist/tex/backend-svg.js +8 -0
  71. package/dist/tex/backend-svg.js.map +1 -0
  72. package/dist/tex/bundles.d.ts +43 -0
  73. package/dist/tex/bundles.js +150 -0
  74. package/dist/tex/bundles.js.map +1 -0
  75. package/dist/tex/bundles.json +26 -0
  76. package/dist/tex/detect.d.ts +27 -0
  77. package/dist/tex/detect.js +212 -0
  78. package/dist/tex/detect.js.map +1 -0
  79. package/dist/tex/dvi.d.ts +44 -0
  80. package/dist/tex/dvi.js +280 -0
  81. package/dist/tex/dvi.js.map +1 -0
  82. package/dist/tex/host.d.ts +82 -0
  83. package/dist/tex/host.js +313 -0
  84. package/dist/tex/host.js.map +1 -0
  85. package/dist/tex/index.d.ts +16 -0
  86. package/dist/tex/index.js +17 -0
  87. package/dist/tex/index.js.map +1 -0
  88. package/dist/tex/render.d.ts +66 -0
  89. package/dist/tex/render.js +72 -0
  90. package/dist/tex/render.js.map +1 -0
  91. package/dist/tex/run.d.ts +51 -0
  92. package/dist/tex/run.js +54 -0
  93. package/dist/tex/run.js.map +1 -0
  94. package/dist/tex/specials.d.ts +32 -0
  95. package/dist/tex/specials.js +145 -0
  96. package/dist/tex/specials.js.map +1 -0
  97. package/dist/tex/stage.d.ts +15 -0
  98. package/dist/tex/stage.js +93 -0
  99. package/dist/tex/stage.js.map +1 -0
  100. package/dist/tex/tfm.d.ts +15 -0
  101. package/dist/tex/tfm.js +33 -0
  102. package/dist/tex/tfm.js.map +1 -0
  103. package/dist/tex/type1.d.ts +32 -0
  104. package/dist/tex/type1.js +402 -0
  105. package/dist/tex/type1.js.map +1 -0
  106. package/dist/tex/vfs.d.ts +37 -0
  107. package/dist/tex/vfs.js +80 -0
  108. package/dist/tex/vfs.js.map +1 -0
  109. package/dist/tex/wasm.d.ts +16 -0
  110. package/dist/tex/wasm.js +8 -0
  111. package/dist/tex/wasm.js.map +1 -0
  112. package/dist/version.d.ts +1 -1
  113. package/dist/version.js +1 -1
  114. package/dist/version.js.map +1 -1
  115. package/dist/worker/protocol.d.ts +4 -0
  116. package/package.json +10 -2
@@ -0,0 +1,313 @@
1
+ // The host functions of the TeX engine: the Pascal file model on the virtual file tree.
2
+ // A file variable is a slot in WASM memory: a handle (bytes 0-3) and the element buffer `f^` (from byte 8).
3
+ // The engine sees only the files of the tree and the terminal. The engine has no import that starts a program,
4
+ // so `\write18` has no shell path: TeX treats stream 18 as the terminal and the log.
5
+ import { RenderError } from "../errors.js";
6
+ import { isRenderError } from "../errors.js";
7
+ import { treeName } from "./vfs.js";
8
+ const FILE_SLOT = 8;
9
+ const NL = 10;
10
+ /** The number of host calls between two reads of the clock. */
11
+ const TICK_EVERY = 256;
12
+ /**
13
+ * The default bound on the bytes that one run writes, in the terminal output and in the output files together.
14
+ * It is 64 MiB: the log, the DVI and the terminal of a render hold well under 1 MiB, and the format build writes about 24 MB.
15
+ * A caller sets another bound with `maxOutputBytes`, for example from the `maxMemoryMb` key of the configuration.
16
+ */
17
+ export const DEFAULT_MAX_OUTPUT_BYTES = 64 * 1024 * 1024;
18
+ /** Thrown by the `hostexit` import to leave the program with an exit code. */
19
+ export class ExitSignal extends Error {
20
+ code;
21
+ constructor(code) {
22
+ super(`program exit ${code}`);
23
+ this.code = code;
24
+ }
25
+ }
26
+ /** The host of one run. */
27
+ export class TexHost {
28
+ files;
29
+ std;
30
+ extra;
31
+ ttyNames;
32
+ echoInput;
33
+ nameKey;
34
+ termIn;
35
+ termOut = [];
36
+ handles = [null];
37
+ mem;
38
+ dv;
39
+ ticks = 0;
40
+ outputBytes = 0;
41
+ maxOutputBytes;
42
+ refusedNames = [];
43
+ deadline;
44
+ timeoutMs;
45
+ constructor(o) {
46
+ this.files = o.files;
47
+ this.std = o.std;
48
+ this.extra = o.extra ?? {};
49
+ this.ttyNames = new Set(o.ttyNames ?? ["TTY:"]);
50
+ this.echoInput = o.echo ?? true;
51
+ this.nameKey = o.nameKey ?? treeName;
52
+ this.deadline = o.deadline;
53
+ this.timeoutMs = o.timeoutMs;
54
+ this.maxOutputBytes = o.maxOutputBytes ?? DEFAULT_MAX_OUTPUT_BYTES;
55
+ const term = "\n" + (o.terminal ?? []).map((l) => l + "\n").join("");
56
+ this.termIn = { data: latin1Bytes(term), pos: 0, text: true, es: 1, reading: true, tty: true, out: [], err: 0 };
57
+ }
58
+ /** Connects the host to the instance, whose memory the host functions read and write. */
59
+ attach(instance) {
60
+ const memory = instance.exports.memory;
61
+ this.mem = new Uint8Array(memory.buffer);
62
+ this.dv = new DataView(memory.buffer);
63
+ }
64
+ /** The text that the program wrote to the terminal. */
65
+ terminalText() {
66
+ // Pascal ends an incomplete last line of the terminal at the end of the program
67
+ if (this.termOut.length && this.termOut[this.termOut.length - 1] !== NL)
68
+ this.termOut.push(NL);
69
+ return latin1String(this.termOut);
70
+ }
71
+ /** The file names that the program tried to open and that escape the tree. Each open failed. */
72
+ get refused() {
73
+ return this.refusedNames.slice();
74
+ }
75
+ /** Stores every file that is still open for writing. */
76
+ finish() {
77
+ for (const h of this.handles)
78
+ if (h && !h.reading && !h.tty && !h.closed)
79
+ this.flush(h);
80
+ }
81
+ flush(h) {
82
+ // Pascal ends an incomplete last line of a text file
83
+ if (h.text && h.out.length && h.out[h.out.length - 1] !== NL)
84
+ h.out.push(NL);
85
+ if (h.name !== undefined)
86
+ this.files.put(h.name, Uint8Array.from(h.out));
87
+ }
88
+ // Counts n bytes that the program writes. A run over the bound ends with E_LIMIT.
89
+ charge(n) {
90
+ this.outputBytes += n;
91
+ if (this.outputBytes > this.maxOutputBytes) {
92
+ throw new RenderError("E_LIMIT", `the TeX run wrote more than ${this.maxOutputBytes} bytes`);
93
+ }
94
+ }
95
+ tick() {
96
+ if (this.deadline === undefined || ++this.ticks % TICK_EVERY !== 0)
97
+ return;
98
+ if (performance.now() > this.deadline) {
99
+ throw new RenderError("E_TIMEOUT", `the TeX run did not finish within ${this.timeoutMs} ms`);
100
+ }
101
+ }
102
+ handleOf(slot) {
103
+ this.tick();
104
+ let i = this.dv.getInt32(slot, true);
105
+ if (i === 0) {
106
+ // the standard files are open from the start
107
+ if (slot === this.std.output)
108
+ i = this.newHandle(slot, { tty: true, reading: false, text: true, es: 1, out: this.termOut, data: new Uint8Array(0), pos: 0, err: 0 });
109
+ else if (slot === this.std.input)
110
+ i = this.newHandle(slot, this.termIn);
111
+ else
112
+ throw new Error(`file at ${slot} is not open`);
113
+ }
114
+ return this.handles[i];
115
+ }
116
+ newHandle(slot, h) {
117
+ this.handles.push(h);
118
+ const i = this.handles.length - 1;
119
+ this.dv.setInt32(slot, i, true);
120
+ if (h.reading)
121
+ this.fill(slot, h);
122
+ return i;
123
+ }
124
+ name(addr, len) {
125
+ let s = "";
126
+ for (let k = 0; k < len; k++)
127
+ s += String.fromCharCode(this.mem[addr + k]);
128
+ return s.replace(/ +$/, "");
129
+ }
130
+ // put the current element into f^
131
+ fill(slot, h) {
132
+ const b = slot + FILE_SLOT;
133
+ if (h.text) {
134
+ const c = h.pos < h.data.length ? h.data[h.pos] : NL;
135
+ this.mem[b] = c === NL ? 32 : c;
136
+ return;
137
+ }
138
+ const at = h.pos * h.es;
139
+ for (let k = 0; k < h.es; k++)
140
+ this.mem[b + k] = at + k < h.data.length ? h.data[at + k] : 0;
141
+ }
142
+ // A terminal shows the line that the user types. The echo happens when the
143
+ // program moves past the end of the previous line.
144
+ echo(h) {
145
+ if (!this.echoInput || !h.tty || h.data[h.pos] !== NL || h.pos + 1 >= h.data.length)
146
+ return;
147
+ let e = h.pos + 1;
148
+ while (e < h.data.length && h.data[e] !== NL)
149
+ e++;
150
+ this.charge(e - h.pos);
151
+ for (let k = h.pos + 1; k <= e; k++)
152
+ this.termOut.push(h.data[k]);
153
+ }
154
+ eofOf(h) {
155
+ return h.text ? h.pos >= h.data.length : h.pos * h.es >= h.data.length;
156
+ }
157
+ /** The import object for `WebAssembly.instantiate`. */
158
+ imports() {
159
+ const env = {
160
+ f_open: (slot, mode, nameAddr, nameLen, es) => {
161
+ const raw = this.name(nameAddr, nameLen);
162
+ const text = (mode & 2) !== 0;
163
+ mode &= 1;
164
+ if (this.ttyNames.has(raw)) {
165
+ if (mode === 0)
166
+ this.newHandle(slot, this.termIn);
167
+ else
168
+ this.newHandle(slot, { tty: true, reading: false, text: true, es: 1, out: this.termOut, data: new Uint8Array(0), pos: 0, err: 0 });
169
+ return;
170
+ }
171
+ // A name that escapes the tree makes the open fail, as a missing file does, and the host records the name.
172
+ // A failed open keeps the run alive: the LaTeX kernel probes `/dev/null` to learn about the system.
173
+ let key;
174
+ try {
175
+ key = this.nameKey(raw);
176
+ }
177
+ catch (e) {
178
+ if (!isRenderError(e))
179
+ throw e;
180
+ this.refusedNames.push(raw);
181
+ }
182
+ if (mode === 0) {
183
+ let data = key === undefined ? undefined : this.files.get(key);
184
+ const ok = data !== undefined;
185
+ if (data === undefined)
186
+ data = new Uint8Array(0);
187
+ if (text && data.length && data[data.length - 1] !== NL)
188
+ data = Uint8Array.from([...data, NL]);
189
+ this.newHandle(slot, { data, pos: 0, es, text, reading: true, out: [], err: ok ? 0 : 1 });
190
+ }
191
+ else {
192
+ this.newHandle(slot, { name: key, data: new Uint8Array(0), pos: 0, out: [], es, text, reading: false, err: key === undefined ? 1 : 0 });
193
+ }
194
+ },
195
+ f_close: (slot) => {
196
+ const h = this.handles[this.dv.getInt32(slot, true)];
197
+ if (!h)
198
+ return;
199
+ if (!h.reading && !h.tty && h.err === 0)
200
+ this.flush(h);
201
+ h.closed = true;
202
+ this.dv.setInt32(slot, 0, true);
203
+ },
204
+ f_erstat: (slot) => this.handleOf(slot).err,
205
+ f_get: (slot) => {
206
+ const h = this.handleOf(slot);
207
+ this.echo(h);
208
+ h.pos++;
209
+ this.fill(slot, h);
210
+ },
211
+ f_put: (slot) => {
212
+ const h = this.handleOf(slot);
213
+ const b = slot + FILE_SLOT;
214
+ this.charge(h.es);
215
+ for (let k = 0; k < h.es; k++)
216
+ h.out.push(this.mem[b + k]);
217
+ },
218
+ f_eof: (slot) => (this.eofOf(this.handleOf(slot)) ? 1 : 0),
219
+ f_eoln: (slot) => {
220
+ const h = this.handleOf(slot);
221
+ return h.pos >= h.data.length || h.data[h.pos] === NL ? 1 : 0;
222
+ },
223
+ f_wstr: (slot, addr, len, width) => {
224
+ const h = this.handleOf(slot);
225
+ this.charge(Math.max(len, width));
226
+ for (let k = len; k < width; k++)
227
+ h.out.push(32);
228
+ for (let k = 0; k < len; k++)
229
+ h.out.push(this.mem[addr + k]);
230
+ },
231
+ f_wint: (slot, v, width) => {
232
+ const h = this.handleOf(slot);
233
+ const s = String(v).padStart(width, " ");
234
+ this.charge(s.length);
235
+ for (let k = 0; k < s.length; k++)
236
+ h.out.push(s.charCodeAt(k));
237
+ },
238
+ f_wchar: (slot, c, width) => {
239
+ const h = this.handleOf(slot);
240
+ this.charge(Math.max(1, width));
241
+ for (let k = 1; k < width; k++)
242
+ h.out.push(32);
243
+ h.out.push(c & 255);
244
+ },
245
+ f_wreal: (slot, v, width, digits) => {
246
+ const h = this.handleOf(slot);
247
+ let s;
248
+ if (digits >= 0)
249
+ s = v.toFixed(digits);
250
+ else {
251
+ const e = v.toExponential(Math.max(1, width - 7)).replace(/e([+-])(\d)$/, "e$10$2");
252
+ s = (v < 0 ? "" : " ") + e.toUpperCase();
253
+ }
254
+ s = s.padStart(width, " ");
255
+ this.charge(s.length);
256
+ for (let k = 0; k < s.length; k++)
257
+ h.out.push(s.charCodeAt(k));
258
+ },
259
+ f_wln: (slot) => {
260
+ const h = this.handleOf(slot);
261
+ this.charge(1);
262
+ h.out.push(NL);
263
+ },
264
+ f_break: () => { },
265
+ f_rint: (slot) => {
266
+ const h = this.handleOf(slot);
267
+ const d = h.data;
268
+ while (h.pos < d.length && (d[h.pos] === 32 || d[h.pos] === NL))
269
+ h.pos++;
270
+ let s = "";
271
+ if (d[h.pos] === 43 || d[h.pos] === 45)
272
+ s += String.fromCharCode(d[h.pos++]);
273
+ while (h.pos < d.length && d[h.pos] >= 48 && d[h.pos] <= 57)
274
+ s += String.fromCharCode(d[h.pos++]);
275
+ this.fill(slot, h);
276
+ return Number(s) | 0;
277
+ },
278
+ f_rln: (slot) => {
279
+ const h = this.handleOf(slot);
280
+ while (h.pos < h.data.length && h.data[h.pos] !== NL)
281
+ h.pos++;
282
+ this.echo(h);
283
+ h.pos++;
284
+ this.fill(slot, h);
285
+ },
286
+ f_setpos: (slot, n) => {
287
+ const h = this.handleOf(slot);
288
+ const items = Math.floor(h.data.length / h.es);
289
+ h.pos = n < 0 || n > items ? items : n;
290
+ this.fill(slot, h);
291
+ },
292
+ f_curpos: (slot) => this.handleOf(slot).pos,
293
+ range_err: (line, v) => {
294
+ throw new Error(`index ${v} outside the bounds at Pascal line ${line}`);
295
+ },
296
+ ...this.extra,
297
+ };
298
+ return { env };
299
+ }
300
+ }
301
+ function latin1Bytes(s) {
302
+ const b = new Uint8Array(s.length);
303
+ for (let i = 0; i < s.length; i++)
304
+ b[i] = s.charCodeAt(i) & 255;
305
+ return b;
306
+ }
307
+ function latin1String(bytes) {
308
+ let s = "";
309
+ for (let i = 0; i < bytes.length; i += 8192)
310
+ s += String.fromCharCode(...bytes.slice(i, i + 8192));
311
+ return s;
312
+ }
313
+ //# sourceMappingURL=host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.js","sourceRoot":"","sources":["../../src/tex/host.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,4GAA4G;AAC5G,+GAA+G;AAC/G,qFAAqF;AACrF,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,QAAQ,EAAgB,MAAM,UAAU,CAAC;AAElD,MAAM,SAAS,GAAG,CAAC,CAAC;AACpB,MAAM,EAAE,GAAG,EAAE,CAAC;AACd,+DAA+D;AAC/D,MAAM,UAAU,GAAG,GAAG,CAAC;AAEvB;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAEzD,8EAA8E;AAC9E,MAAM,OAAO,UAAW,SAAQ,KAAK;IAC1B,IAAI,CAAS;IACtB,YAAY,IAAY;QACtB,KAAK,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AA2CD,2BAA2B;AAC3B,MAAM,OAAO,OAAO;IACD,KAAK,CAAU;IACf,GAAG,CAAoC;IACvC,KAAK,CAAiD;IACtD,QAAQ,CAAc;IACtB,SAAS,CAAU;IACn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AC,GAAG,EAAE,CAAC;IACX,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,IAAI;QAAE,CAAC,IAAI,MAAM,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IACnG,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The runtime of the TeX stage: the virtual file tree, the host functions of the WASM engine, the run function,
3
+ * the DVI reader with the Type 1 and TFM readers, the dvisvgm specials, and the render that joins them.
4
+ * The surface also holds the bundle manager, the package detection and the tikz render.
5
+ */
6
+ export { TexTree, treeName, type TreeFile } from "./vfs.ts";
7
+ export { TexHost, ExitSignal, DEFAULT_MAX_OUTPUT_BYTES, type HostOptions } from "./host.ts";
8
+ export { runProgram, type RunOptions, type RunResult, type EngineSymbols } from "./run.ts";
9
+ export { readTfm, type Tfm } from "./tfm.ts";
10
+ export { readType1, decryptType1, type Type1Font, type Type1Glyph } from "./type1.ts";
11
+ export { dviToSvg, type DviOptions, type DviSvg, type FontFiles } from "./dvi.ts";
12
+ export { createSpecials, SPECIAL_UNIT_PER_PT, type Specials, type SpecialPosition, type SpecialResult } from "./specials.ts";
13
+ export { renderTex, type TexEngine, type RenderTexOptions, type RenderTexResult } from "./render.ts";
14
+ export { BUNDLES, CACHE_SUBFOLDER, bundleUrl, cachePath, findBundle, loadBundleBytes, loadBundles, unpackBundle, type BundleEntry, type BundleSettings } from "./bundles.ts";
15
+ export { detectBundles, type BundleName, type Detection } from "./detect.ts";
16
+ export { renderTikzSvg, wrapSource, type TikzSvg } from "./stage.ts";
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The runtime of the TeX stage: the virtual file tree, the host functions of the WASM engine, the run function,
3
+ * the DVI reader with the Type 1 and TFM readers, the dvisvgm specials, and the render that joins them.
4
+ * The surface also holds the bundle manager, the package detection and the tikz render.
5
+ */
6
+ export { TexTree, treeName } from "./vfs.js";
7
+ export { TexHost, ExitSignal, DEFAULT_MAX_OUTPUT_BYTES } from "./host.js";
8
+ export { runProgram } from "./run.js";
9
+ export { readTfm } from "./tfm.js";
10
+ export { readType1, decryptType1 } from "./type1.js";
11
+ export { dviToSvg } from "./dvi.js";
12
+ export { createSpecials, SPECIAL_UNIT_PER_PT } from "./specials.js";
13
+ export { renderTex } from "./render.js";
14
+ export { BUNDLES, CACHE_SUBFOLDER, bundleUrl, cachePath, findBundle, loadBundleBytes, loadBundles, unpackBundle } from "./bundles.js";
15
+ export { detectBundles } from "./detect.js";
16
+ export { renderTikzSvg, wrapSource } from "./stage.js";
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tex/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAiB,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,wBAAwB,EAAoB,MAAM,WAAW,CAAC;AAC5F,OAAO,EAAE,UAAU,EAAuD,MAAM,UAAU,CAAC;AAC3F,OAAO,EAAE,OAAO,EAAY,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,YAAY,EAAmC,MAAM,YAAY,CAAC;AACtF,OAAO,EAAE,QAAQ,EAAgD,MAAM,UAAU,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAA2D,MAAM,eAAe,CAAC;AAC7H,OAAO,EAAE,SAAS,EAA+D,MAAM,aAAa,CAAC;AACrG,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,YAAY,EAAyC,MAAM,cAAc,CAAC;AAC7K,OAAO,EAAE,aAAa,EAAmC,MAAM,aAAa,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,UAAU,EAAgB,MAAM,YAAY,CAAC"}
@@ -0,0 +1,66 @@
1
+ import { type DviSvg } from "./dvi.ts";
2
+ import { type EngineSymbols } from "./run.ts";
3
+ import type { TexTree } from "./vfs.ts";
4
+ import type { WasmModule } from "./wasm.ts";
5
+ /** The compiled engine and the files that it needs. */
6
+ export interface TexEngine {
7
+ /** The compiled WASM module. */
8
+ module: WasmModule;
9
+ /** The symbol table of the engine. */
10
+ symbols: EngineSymbols;
11
+ /** The string pool of the engine (`tex.pool`). */
12
+ pool: Uint8Array;
13
+ }
14
+ /** The inputs of one TeX render. */
15
+ export interface RenderTexOptions {
16
+ engine: TexEngine;
17
+ /** The format file and its name, for example `scieng.fmt`. */
18
+ format: {
19
+ name: string;
20
+ bytes: Uint8Array;
21
+ };
22
+ /**
23
+ * The tree with the bundles: the macro files, the TFM files and the PFB files.
24
+ * The render works on a fork of the tree, so the tree stays as it was.
25
+ */
26
+ tree: TexTree;
27
+ /** The TeX source. */
28
+ source: string | Uint8Array;
29
+ /** The job name. The default is `job`. */
30
+ jobName?: string;
31
+ /** The time limit of the TeX run in milliseconds. */
32
+ timeoutMs?: number;
33
+ /** The bound on the bytes that the run writes. A run over it rejects with `E_LIMIT`. The default is 64 MiB. */
34
+ maxOutputBytes?: number;
35
+ /** The border of the SVG in SVG units. */
36
+ margin?: number;
37
+ /**
38
+ * When `false`, the boxes of glyphs and rules inside a transformed raw group join the bounds, as in the T6 trial.
39
+ * The default is `true`: they do not join, because their DVI positions are not their places on the page.
40
+ */
41
+ skipTransformedBoxes?: boolean;
42
+ }
43
+ /** The result of one TeX render. */
44
+ export interface RenderTexResult extends Omit<DviSvg, "svg"> {
45
+ svg: string;
46
+ /** The text of the TeX log. */
47
+ log: string;
48
+ /** The text of the terminal. */
49
+ terminal: string;
50
+ /** The file names that the source tried to open and that escape the tree. Each open failed. */
51
+ refused: string[];
52
+ /** The DVI bytes. */
53
+ dvi: Uint8Array;
54
+ /** The first words of the specials that the converter did not handle. */
55
+ ignoredSpecials: string[];
56
+ /** The time of the TeX run in milliseconds. */
57
+ texMs: number;
58
+ /** The time of the DVI to SVG conversion in milliseconds. */
59
+ svgMs: number;
60
+ }
61
+ /**
62
+ * Renders a TeX source to SVG: runs the engine with the format on a fork of the tree, then converts the DVI.
63
+ * A source that makes TeX stop with no DVI rejects with `E_INPUT`, the first TeX error and its source line.
64
+ * The run follows the rules of `runProgram` for `E_TIMEOUT` and `E_INPUT`. A failure of the DVI conversion is `E_INTERNAL`.
65
+ */
66
+ export declare function renderTex(o: RenderTexOptions): Promise<RenderTexResult>;
@@ -0,0 +1,72 @@
1
+ import { isRenderError, RenderError } from "../errors.js";
2
+ import { dviToSvg } from "./dvi.js";
3
+ import { runProgram } from "./run.js";
4
+ import { createSpecials, SPECIAL_UNIT_PER_PT } from "./specials.js";
5
+ const decode = (b) => {
6
+ let s = "";
7
+ if (b === undefined)
8
+ return s;
9
+ for (let i = 0; i < b.length; i += 8192)
10
+ s += String.fromCharCode(...b.subarray(i, Math.min(b.length, i + 8192)));
11
+ return s;
12
+ };
13
+ /** The first TeX error of a log: the message after `! ` and the line number of the `l.<n>` line. */
14
+ function firstTexError(log, terminal) {
15
+ const text = log || terminal;
16
+ const lines = text.split("\n");
17
+ const at = lines.findIndex((l) => l.startsWith("!"));
18
+ if (at < 0)
19
+ return { message: "TeX produced no output", line: undefined };
20
+ const message = lines[at].slice(1).trim();
21
+ const lineRow = lines.slice(at).find((l) => /^l\.\d+/.test(l));
22
+ return { message, line: lineRow === undefined ? undefined : Number(/^l\.(\d+)/.exec(lineRow)[1]) };
23
+ }
24
+ /**
25
+ * Renders a TeX source to SVG: runs the engine with the format on a fork of the tree, then converts the DVI.
26
+ * A source that makes TeX stop with no DVI rejects with `E_INPUT`, the first TeX error and its source line.
27
+ * The run follows the rules of `runProgram` for `E_TIMEOUT` and `E_INPUT`. A failure of the DVI conversion is `E_INTERNAL`.
28
+ */
29
+ export async function renderTex(o) {
30
+ const job = (o.jobName ?? "job").toLowerCase();
31
+ const run = o.tree.fork();
32
+ run.add("tex.pool", o.engine.pool);
33
+ run.add(o.format.name, o.format.bytes);
34
+ run.add(`${job}.tex`, typeof o.source === "string" ? utf8Bytes(o.source) : o.source);
35
+ const t0 = performance.now();
36
+ const r = await runProgram({
37
+ module: o.engine.module,
38
+ symbols: o.engine.symbols,
39
+ files: run,
40
+ terminal: [`&${o.format.name.replace(/\.fmt$/i, "")} ${job}`],
41
+ ...(o.timeoutMs === undefined ? {} : { timeoutMs: o.timeoutMs }),
42
+ ...(o.maxOutputBytes === undefined ? {} : { maxOutputBytes: o.maxOutputBytes }),
43
+ });
44
+ const texMs = performance.now() - t0;
45
+ const dvi = run.written.get(`${job}.dvi`);
46
+ const log = decode(run.written.get(`${job}.log`));
47
+ if (dvi === undefined) {
48
+ const err = firstTexError(log, r.terminal);
49
+ throw new RenderError("E_INPUT", `TeX stopped with no output: ${err.message}`, err.line === undefined ? {} : { line: err.line });
50
+ }
51
+ const t1 = performance.now();
52
+ const specials = createSpecials();
53
+ let converted;
54
+ try {
55
+ converted = dviToSvg(dvi, (name) => {
56
+ const tfm = run.get(`${name}.tfm`);
57
+ return tfm ? { tfm, pfb: run.get(`${name}.pfb`) ?? null } : null;
58
+ }, { special: specials.special, transformed: o.skipTransformedBoxes === false ? () => false : specials.transformed, unitPerPt: SPECIAL_UNIT_PER_PT, ...(o.margin === undefined ? {} : { margin: o.margin }) });
59
+ }
60
+ catch (e) {
61
+ if (isRenderError(e))
62
+ throw e;
63
+ throw new RenderError("E_INTERNAL", `the DVI conversion failed: ${e instanceof Error ? e.message : String(e)}`);
64
+ }
65
+ const svgMs = performance.now() - t1;
66
+ return { ...converted, log, terminal: r.terminal, refused: r.refused, dvi, ignoredSpecials: specials.ignored(), texMs, svgMs };
67
+ }
68
+ /** TeX reads bytes. A source string goes in as its UTF-8 bytes. */
69
+ function utf8Bytes(s) {
70
+ return new TextEncoder().encode(s);
71
+ }
72
+ //# sourceMappingURL=render.js.map
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,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACrC,CAAC"}
@@ -0,0 +1,51 @@
1
+ import type { TexTree } from "./vfs.ts";
2
+ import { type WasmModule } from "./wasm.ts";
3
+ /** The symbol table that the engine compiler writes next to the WASM file. */
4
+ export interface EngineSymbols {
5
+ symbols: Record<string, {
6
+ addr: number;
7
+ }>;
8
+ }
9
+ /** The inputs of one run. */
10
+ export interface RunOptions {
11
+ /** The compiled engine. */
12
+ module: WasmModule;
13
+ /** The symbol table of the engine. */
14
+ symbols: EngineSymbols;
15
+ /** The virtual file tree. The program writes its output files to the tree. */
16
+ files: TexTree;
17
+ /** The lines of terminal input. */
18
+ terminal?: string[];
19
+ /**
20
+ * The time limit in milliseconds. The host checks the clock at the file calls of the program.
21
+ * A program that loops without a file call needs a thread that the caller can end: the render worker.
22
+ */
23
+ timeoutMs?: number;
24
+ /** The file names that mean the terminal. The default is `TTY:`. DVItype also names `termin`. */
25
+ ttyNames?: string[];
26
+ /** Turns a file name of the program into the key of the tree. The default is `treeName`. See `HostOptions.nameKey`. */
27
+ nameKey?: (raw: string) => string;
28
+ /** Echo the terminal input to the terminal output. The default is true. */
29
+ echo?: boolean;
30
+ /** The bound on the bytes that the run writes. A run over it ends with `E_LIMIT`. The default is `DEFAULT_MAX_OUTPUT_BYTES` (64 MiB). */
31
+ maxOutputBytes?: number;
32
+ }
33
+ /** The result of one run. */
34
+ export interface RunResult {
35
+ /** The text that the program wrote to the terminal. */
36
+ terminal: string;
37
+ /** The exit code. */
38
+ exit: number;
39
+ /** The file names that the program tried to open and that escape the tree. Each open failed. */
40
+ refused: string[];
41
+ /** The time to instantiate the module, in milliseconds. */
42
+ instantiateMs: number;
43
+ /** The time of the program, in milliseconds. */
44
+ runMs: number;
45
+ }
46
+ /**
47
+ * Runs the engine once. The host gives the engine the files of the tree and the terminal, and nothing else.
48
+ * A run that writes more than `maxOutputBytes` ends with `E_LIMIT`. A run that passes `timeoutMs` ends with `E_TIMEOUT`. An open of a name that escapes the tree fails like a missing file, and `refused` lists the name.
49
+ * Any other failure of the program ends with `E_INTERNAL`.
50
+ */
51
+ export declare function runProgram(o: RunOptions): Promise<RunResult>;
@@ -0,0 +1,54 @@
1
+ // Runs one compiled Pascal program (the TeX engine) on the virtual file tree.
2
+ import { isRenderError, RenderError } from "../errors.js";
3
+ import { ExitSignal, TexHost } from "./host.js";
4
+ import { instantiate } from "./wasm.js";
5
+ /**
6
+ * Runs the engine once. The host gives the engine the files of the tree and the terminal, and nothing else.
7
+ * A run that writes more than `maxOutputBytes` ends with `E_LIMIT`. A run that passes `timeoutMs` ends with `E_TIMEOUT`. An open of a name that escapes the tree fails like a missing file, and `refused` lists the name.
8
+ * Any other failure of the program ends with `E_INTERNAL`.
9
+ */
10
+ export async function runProgram(o) {
11
+ const std = { input: o.symbols.symbols.input?.addr, output: o.symbols.symbols.output?.addr };
12
+ if (std.input === undefined || std.output === undefined) {
13
+ throw new RenderError("E_INTERNAL", "the engine symbol table has no input or output file");
14
+ }
15
+ const t0 = performance.now();
16
+ const host = new TexHost({
17
+ files: o.files,
18
+ terminal: o.terminal,
19
+ std: { input: std.input, output: std.output },
20
+ echo: o.echo,
21
+ ...(o.ttyNames === undefined ? {} : { ttyNames: o.ttyNames }),
22
+ ...(o.nameKey === undefined ? {} : { nameKey: o.nameKey }),
23
+ ...(o.maxOutputBytes === undefined ? {} : { maxOutputBytes: o.maxOutputBytes }),
24
+ extra: {
25
+ hostexit: (code) => {
26
+ throw new ExitSignal(code);
27
+ },
28
+ },
29
+ ...(o.timeoutMs === undefined ? {} : { deadline: t0 + o.timeoutMs, timeoutMs: o.timeoutMs }),
30
+ });
31
+ const instance = await instantiate(o.module, host.imports());
32
+ host.attach(instance);
33
+ const t1 = performance.now();
34
+ let exit = 0;
35
+ try {
36
+ instance.exports.main();
37
+ }
38
+ catch (e) {
39
+ if (e instanceof ExitSignal)
40
+ exit = e.code;
41
+ else if (isRenderError(e))
42
+ throw e;
43
+ else if (e instanceof RangeError)
44
+ throw new RenderError("E_LIMIT", `the TeX engine ran out of stack: ${e.message}`);
45
+ else
46
+ throw new RenderError("E_INTERNAL", `the TeX engine failed: ${e instanceof Error ? e.message : String(e)}`);
47
+ }
48
+ finally {
49
+ host.finish();
50
+ }
51
+ const t2 = performance.now();
52
+ return { terminal: host.terminalText(), exit, refused: host.refused, instantiateMs: t1 - t0, runMs: t2 - t1 };
53
+ }
54
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/tex/run.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAmB,MAAM,WAAW,CAAC;AA8CzD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,CAAa;IAC5C,MAAM,GAAG,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC;IAC7F,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QACxD,MAAM,IAAI,WAAW,CAAC,YAAY,EAAE,qDAAqD,CAAC,CAAC;IAC7F,CAAC;IACD,MAAM,EAAE,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAC7B,MAAM,IAAI,GAAG,IAAI,OAAO,CAAC;QACvB,KAAK,EAAE,CAAC,CAAC,KAAK;QACd,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,GAAG,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,E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