@danielsimonjr/sciengjs 0.0.0-stage → 0.1.1

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 (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +183 -3
  3. package/THIRD_PARTY_NOTICES.md +57 -0
  4. package/assets/fonts/LiberationSerif-Regular.LICENSE.txt +102 -0
  5. package/assets/fonts/LiberationSerif-Regular.ttf +0 -0
  6. package/assets/index_bg.wasm +0 -0
  7. package/assets/licenses/EPL-2.0.txt +278 -0
  8. package/assets/licenses/MPL-2.0.txt +374 -0
  9. package/dist/assets.d.ts +12 -0
  10. package/dist/assets.js +63 -0
  11. package/dist/assets.js.map +1 -0
  12. package/dist/config.d.ts +32 -0
  13. package/dist/config.js +186 -0
  14. package/dist/config.js.map +1 -0
  15. package/dist/core.d.ts +10 -0
  16. package/dist/core.js +85 -0
  17. package/dist/core.js.map +1 -0
  18. package/dist/errors.d.ts +24 -0
  19. package/dist/errors.js +40 -0
  20. package/dist/errors.js.map +1 -0
  21. package/dist/graph/backend-png.d.ts +5 -0
  22. package/dist/graph/backend-png.js +57 -0
  23. package/dist/graph/backend-png.js.map +1 -0
  24. package/dist/graph/backend-svg.d.ts +3 -0
  25. package/dist/graph/backend-svg.js +12 -0
  26. package/dist/graph/backend-svg.js.map +1 -0
  27. package/dist/graph/dot.d.ts +12 -0
  28. package/dist/graph/dot.js +48 -0
  29. package/dist/graph/dot.js.map +1 -0
  30. package/dist/graph/image.d.ts +23 -0
  31. package/dist/graph/image.js +292 -0
  32. package/dist/graph/image.js.map +1 -0
  33. package/dist/graph/index.d.ts +3 -0
  34. package/dist/graph/index.js +3 -0
  35. package/dist/graph/index.js.map +1 -0
  36. package/dist/index.d.ts +9 -0
  37. package/dist/index.js +14 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/pairs.d.ts +11 -0
  40. package/dist/pairs.js +43 -0
  41. package/dist/pairs.js.map +1 -0
  42. package/dist/raster/index.d.ts +24 -0
  43. package/dist/raster/index.js +83 -0
  44. package/dist/raster/index.js.map +1 -0
  45. package/dist/raster/warnings.d.ts +12 -0
  46. package/dist/raster/warnings.js +175 -0
  47. package/dist/raster/warnings.js.map +1 -0
  48. package/dist/registry.d.ts +13 -0
  49. package/dist/registry.js +17 -0
  50. package/dist/registry.js.map +1 -0
  51. package/dist/types.d.ts +48 -0
  52. package/dist/types.js +19 -0
  53. package/dist/types.js.map +1 -0
  54. package/dist/version.d.ts +1 -0
  55. package/dist/version.js +3 -0
  56. package/dist/version.js.map +1 -0
  57. package/dist/worker/entry.d.ts +1 -0
  58. package/dist/worker/entry.js +38 -0
  59. package/dist/worker/entry.js.map +1 -0
  60. package/dist/worker/protocol.d.ts +39 -0
  61. package/dist/worker/protocol.js +2 -0
  62. package/dist/worker/protocol.js.map +1 -0
  63. package/dist/worker/run.d.ts +30 -0
  64. package/dist/worker/run.js +90 -0
  65. package/dist/worker/run.js.map +1 -0
  66. package/package.json +71 -6
@@ -0,0 +1,292 @@
1
+ /** The attribute keys that name an external resource. The scanner removes each of them. */
2
+ const EXTERNAL_KEYS = ["image", "stylesheet"];
3
+ function isSpace(c) {
4
+ return c === " " || c === "\t" || c === "\r" || c === "\n" || c === "\f" || c === "\v";
5
+ }
6
+ // DOT identifiers take every byte from 0x80 upward, so every non-ASCII character counts as a letter.
7
+ function isWordChar(c) {
8
+ return ((c >= "a" && c <= "z") ||
9
+ (c >= "A" && c <= "Z") ||
10
+ (c >= "0" && c <= "9") ||
11
+ c === "." ||
12
+ c === "_" ||
13
+ c >= "\u0080");
14
+ }
15
+ function tokenize(source) {
16
+ const tokens = [];
17
+ const len = source.length;
18
+ let i = 0;
19
+ while (i < len) {
20
+ const c = source[i];
21
+ if (isSpace(c)) {
22
+ i++;
23
+ continue;
24
+ }
25
+ if (c === "/" && source[i + 1] === "/") {
26
+ i += 2;
27
+ while (i < len && source[i] !== "\n") {
28
+ i++;
29
+ }
30
+ continue;
31
+ }
32
+ if (c === "/" && source[i + 1] === "*") {
33
+ i += 2;
34
+ while (i < len && !(source[i] === "*" && source[i + 1] === "/")) {
35
+ i++;
36
+ }
37
+ if (i < len) {
38
+ i += 2;
39
+ }
40
+ continue;
41
+ }
42
+ if (c === "#" && (i === 0 || source[i - 1] === "\n")) {
43
+ while (i < len && source[i] !== "\n") {
44
+ i++;
45
+ }
46
+ continue;
47
+ }
48
+ if (c === '"') {
49
+ const start = i;
50
+ i++;
51
+ let text = "";
52
+ while (i < len) {
53
+ const ch = source[i];
54
+ if (ch === "\\" && i + 1 < len) {
55
+ text += source[i + 1];
56
+ i += 2;
57
+ continue;
58
+ }
59
+ if (ch === '"') {
60
+ i++;
61
+ break;
62
+ }
63
+ text += ch;
64
+ i++;
65
+ }
66
+ tokens.push({ kind: "string", text, start, end: i });
67
+ continue;
68
+ }
69
+ if (c === "<") {
70
+ const start = i;
71
+ i++;
72
+ let text = "";
73
+ let depth = 1;
74
+ while (i < len && depth > 0) {
75
+ const ch = source[i];
76
+ if (ch === "<") {
77
+ depth++;
78
+ }
79
+ else if (ch === ">") {
80
+ depth--;
81
+ if (depth === 0) {
82
+ i++;
83
+ break;
84
+ }
85
+ }
86
+ text += ch;
87
+ i++;
88
+ }
89
+ tokens.push({ kind: "html", text, start, end: i });
90
+ continue;
91
+ }
92
+ if (isWordChar(c)) {
93
+ const start = i;
94
+ let text = "";
95
+ while (i < len && isWordChar(source[i])) {
96
+ text += source[i];
97
+ i++;
98
+ }
99
+ tokens.push({ kind: "ident", text, start, end: i });
100
+ continue;
101
+ }
102
+ tokens.push({ kind: "char", text: c, start: i, end: i + 1 });
103
+ i++;
104
+ }
105
+ return joinConcatenations(tokens);
106
+ }
107
+ // DOT joins quoted strings with "+". The joined text is one string token.
108
+ function joinConcatenations(tokens) {
109
+ const joined = [];
110
+ for (const token of tokens) {
111
+ const last = joined[joined.length - 1];
112
+ const prior = joined[joined.length - 2];
113
+ if (token.kind === "string" && last?.kind === "char" && last.text === "+" && prior?.kind === "string") {
114
+ joined.length -= 2;
115
+ joined.push({ kind: "string", text: prior.text + token.text, start: prior.start, end: token.end });
116
+ continue;
117
+ }
118
+ joined.push(token);
119
+ }
120
+ return joined;
121
+ }
122
+ function skipTrivia(source, from) {
123
+ const len = source.length;
124
+ let j = from;
125
+ while (j < len) {
126
+ const c = source[j];
127
+ if (isSpace(c)) {
128
+ j++;
129
+ continue;
130
+ }
131
+ if (c === "/" && source[j + 1] === "/") {
132
+ j += 2;
133
+ while (j < len && source[j] !== "\n") {
134
+ j++;
135
+ }
136
+ continue;
137
+ }
138
+ if (c === "/" && source[j + 1] === "*") {
139
+ j += 2;
140
+ while (j < len && !(source[j] === "*" && source[j + 1] === "/")) {
141
+ j++;
142
+ }
143
+ if (j < len) {
144
+ j += 2;
145
+ }
146
+ continue;
147
+ }
148
+ break;
149
+ }
150
+ return j;
151
+ }
152
+ /** Counts the lines from a known position, so that a scan with many hits reads the source once. */
153
+ class LineCounter {
154
+ source;
155
+ index = 0;
156
+ line = 1;
157
+ constructor(source) {
158
+ this.source = source;
159
+ }
160
+ /** The line of an index. The indexes of the calls must not decrease. */
161
+ at(index) {
162
+ for (; this.index < index; this.index++) {
163
+ if (this.source[this.index] === "\n") {
164
+ this.line++;
165
+ }
166
+ }
167
+ return this.line;
168
+ }
169
+ }
170
+ /** Removes each image and stylesheet attribute of a DOT source and reports its key, line and value. Comments, quoted strings and HTML strings keep their text. */
171
+ export function stripImageAttributes(source) {
172
+ const tokens = tokenize(source);
173
+ const ranges = [];
174
+ const lines = new LineCounter(source);
175
+ for (let i = 0; i < tokens.length; i++) {
176
+ const key = tokens[i];
177
+ const isKey = (key.kind === "ident" || key.kind === "string") && EXTERNAL_KEYS.includes(key.text);
178
+ if (!isKey) {
179
+ continue;
180
+ }
181
+ const eq = tokens[i + 1];
182
+ if (!eq || eq.kind !== "char" || eq.text !== "=") {
183
+ continue;
184
+ }
185
+ const value = tokens[i + 2];
186
+ if (!value || (value.kind !== "ident" && value.kind !== "string" && value.kind !== "html")) {
187
+ continue;
188
+ }
189
+ let end = value.end;
190
+ const sep = skipTrivia(source, value.end);
191
+ if (sep < source.length && (source[sep] === "," || source[sep] === ";")) {
192
+ end = sep + 1;
193
+ }
194
+ ranges.push({ start: key.start, end, key: key.text, line: lines.at(key.start), file: value.text });
195
+ i += 2;
196
+ }
197
+ const chars = source.split("");
198
+ for (const range of ranges) {
199
+ for (let k = range.start; k < range.end; k++) {
200
+ chars[k] = source[k] === "\n" ? "\n" : " ";
201
+ }
202
+ }
203
+ const removed = ranges.map((range) => ({ key: range.key, line: range.line, file: range.file }));
204
+ return { source: chars.join(""), removed };
205
+ }
206
+ function findImageClose(svg, from) {
207
+ const len = svg.length;
208
+ let idx = svg.indexOf("</image", from);
209
+ while (idx !== -1) {
210
+ const c = svg.charAt(idx + 7);
211
+ if (c === ">") {
212
+ return idx + 8;
213
+ }
214
+ if (c !== "" && isSpace(c)) {
215
+ let m = idx + 7;
216
+ while (m < len && isSpace(svg[m])) {
217
+ m++;
218
+ }
219
+ if (m < len && svg[m] === ">") {
220
+ return m + 1;
221
+ }
222
+ }
223
+ idx = svg.indexOf("</image", idx + 7);
224
+ }
225
+ return -1;
226
+ }
227
+ function imageRemovalEnd(svg, start) {
228
+ const len = svg.length;
229
+ let j = start + 6;
230
+ let quote = null;
231
+ while (j < len) {
232
+ const c = svg[j];
233
+ if (quote !== null) {
234
+ if (c === quote) {
235
+ quote = null;
236
+ }
237
+ }
238
+ else if (c === '"' || c === "'") {
239
+ quote = c;
240
+ }
241
+ else if (c === ">") {
242
+ break;
243
+ }
244
+ j++;
245
+ }
246
+ if (j >= len) {
247
+ return len;
248
+ }
249
+ let k = j - 1;
250
+ while (k >= 0 && isSpace(svg[k])) {
251
+ k--;
252
+ }
253
+ if (k >= start && svg[k] === "/") {
254
+ return j + 1;
255
+ }
256
+ const close = findImageClose(svg, j + 1);
257
+ return close === -1 ? len : close;
258
+ }
259
+ /** Removes each SVG image element, with its attributes and its closing tag, and counts the removed elements. */
260
+ export function dropImageElements(svg) {
261
+ const len = svg.length;
262
+ let out = "";
263
+ let copied = 0;
264
+ let i = 0;
265
+ let dropped = 0;
266
+ while (i < len) {
267
+ if (svg.startsWith("<image", i)) {
268
+ const next = svg.charAt(i + 6);
269
+ if (next === "/" || next === ">" || isSpace(next)) {
270
+ const removeEnd = imageRemovalEnd(svg, i);
271
+ out += svg.slice(copied, i);
272
+ dropped++;
273
+ copied = removeEnd;
274
+ i = removeEnd;
275
+ continue;
276
+ }
277
+ }
278
+ i++;
279
+ }
280
+ out += svg.slice(copied);
281
+ return { svg: out, dropped };
282
+ }
283
+ /** Removes each xml-stylesheet processing instruction of an SVG and counts the removed instructions. */
284
+ export function dropStylesheetInstructions(svg) {
285
+ let dropped = 0;
286
+ const out = svg.replace(/<\?xml-stylesheet[^>]*?\?>(\r?\n)?/g, () => {
287
+ dropped++;
288
+ return "";
289
+ });
290
+ return { svg: out, dropped };
291
+ }
292
+ //# sourceMappingURL=image.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image.js","sourceRoot":"","sources":["../../src/graph/image.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,MAAM,aAAa,GAAsB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;AAgCjE,SAAS,OAAO,CAAC,CAAS;IACxB,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC;AACzF,CAAC;AAED,qGAAqG;AACrG,SAAS,UAAU,CAAC,CAAS;IAC3B,OAAO,CACL,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,CAAC;QACtB,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,CAAC;QACtB,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,CAAC;QACtB,CAAC,KAAK,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AC;QACD,CAAC,EAAE,CAAC;IACN,CAAC;IACD,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACzB,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC;AAC/B,CAAC;AAED,wGAAwG;AACxG,MAAM,UAAU,0BAA0B,CAAC,GAAW;IACpD,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAClE,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** The graph stage: DOT to SVG through the viz library, which holds Graphviz. */
2
+ export { dotToSvg } from "./dot.ts";
3
+ export type { DotSvgResult } from "./dot.ts";
@@ -0,0 +1,3 @@
1
+ /** The graph stage: DOT to SVG through the viz library, which holds Graphviz. */
2
+ export { dotToSvg } from "./dot.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/graph/index.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { SciengConfig } from "./config.ts";
2
+ import type { Capability, RenderRequest, RenderResult } from "./types.ts";
3
+ export { RenderError, RENDER_ERROR_CODES, type RenderErrorCode } from "./errors.ts";
4
+ export { loadConfig, type SciengConfig, type NetworkPolicy } from "./config.ts";
5
+ export { INPUT_TYPES, OUTPUT_FORMATS, type InputType, type OutputFormat, type RenderOptions, type RenderRequest, type RenderResult, type RenderAsset, type Capability, } from "./types.ts";
6
+ /** Renders one source to the requested format. Rejects with a RenderError. Never falls back to another format. */
7
+ export declare function render(req: RenderRequest, config?: Partial<SciengConfig>): Promise<RenderResult>;
8
+ /** Reports each supported pair, its stage and whether that stage is ready on this machine. */
9
+ export declare function capabilities(config?: Partial<SciengConfig>): Promise<Capability[]>;
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ import { capabilitiesWithRegistry, renderWithRegistry } from "./core.js";
2
+ import { DEFAULT_REGISTRY } from "./registry.js";
3
+ export { RenderError, RENDER_ERROR_CODES } from "./errors.js";
4
+ export { loadConfig } from "./config.js";
5
+ export { INPUT_TYPES, OUTPUT_FORMATS, } from "./types.js";
6
+ /** Renders one source to the requested format. Rejects with a RenderError. Never falls back to another format. */
7
+ export function render(req, config) {
8
+ return renderWithRegistry(req, config ?? {}, DEFAULT_REGISTRY);
9
+ }
10
+ /** Reports each supported pair, its stage and whether that stage is ready on this machine. */
11
+ export function capabilities(config) {
12
+ return capabilitiesWithRegistry(config ?? {}, DEFAULT_REGISTRY);
13
+ }
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAIjD,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAwB,MAAM,aAAa,CAAC;AACpF,OAAO,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAC;AAChF,OAAO,EACL,WAAW,EACX,cAAc,GAQf,MAAM,YAAY,CAAC;AAEpB,kHAAkH;AAClH,MAAM,UAAU,MAAM,CAAC,GAAkB,EAAE,MAA8B;IACvE,OAAO,kBAAkB,CAAC,GAAG,EAAE,MAAM,IAAI,EAAE,EAAE,gBAAgB,CAAC,CAAC;AACjE,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,YAAY,CAAC,MAA8B;IACzD,OAAO,wBAAwB,CAAC,MAAM,IAAI,EAAE,EAAE,gBAAgB,CAAC,CAAC;AAClE,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { InputType, OutputFormat } from "./types.ts";
2
+ /** One (input, output) pair of the design, with the stage that renders it. */
3
+ export interface PairSpec {
4
+ type: InputType;
5
+ format: OutputFormat;
6
+ stage: string;
7
+ }
8
+ /** The pairs of the design section "Scope". A pair missing here is unsupported. */
9
+ export declare const PAIRS: readonly PairSpec[];
10
+ /** Returns the pair of the table, or undefined when the design does not list it. */
11
+ export declare function findPair(type: InputType, format: OutputFormat): PairSpec | undefined;
package/dist/pairs.js ADDED
@@ -0,0 +1,43 @@
1
+ /** The pairs of the design section "Scope". A pair missing here is unsupported. */
2
+ export const PAIRS = [
3
+ { type: "dot", format: "svg", stage: "graph" },
4
+ { type: "dot", format: "png", stage: "graph" },
5
+ { type: "dot", format: "pdf", stage: "browser" },
6
+ { type: "mermaid", format: "svg", stage: "browser" },
7
+ { type: "mermaid", format: "png", stage: "browser" },
8
+ { type: "mermaid", format: "pdf", stage: "browser" },
9
+ { type: "math", format: "svg", stage: "math" },
10
+ { type: "math", format: "png", stage: "math" },
11
+ { type: "math", format: "pdf", stage: "math" },
12
+ { type: "tikz", format: "svg", stage: "tex" },
13
+ { type: "tikz", format: "png", stage: "tex" },
14
+ { type: "tikz", format: "pdf", stage: "tex" },
15
+ { type: "plot", format: "svg", stage: "plot" },
16
+ { type: "plot", format: "png", stage: "plot" },
17
+ { type: "plot", format: "pdf", stage: "plot" },
18
+ { type: "plot", format: "html", stage: "plot" },
19
+ { type: "sysml", format: "svg", stage: "graph" },
20
+ { type: "sysml", format: "png", stage: "graph" },
21
+ { type: "sysml", format: "pdf", stage: "graph" },
22
+ { type: "step", format: "html", stage: "mesh" },
23
+ { type: "step", format: "png", stage: "browser" },
24
+ { type: "step", format: "glb", stage: "mesh" },
25
+ { type: "iges", format: "html", stage: "mesh" },
26
+ { type: "iges", format: "png", stage: "browser" },
27
+ { type: "iges", format: "glb", stage: "mesh" },
28
+ { type: "brep", format: "html", stage: "mesh" },
29
+ { type: "brep", format: "png", stage: "browser" },
30
+ { type: "brep", format: "glb", stage: "mesh" },
31
+ { type: "cad", format: "html", stage: "mesh" },
32
+ { type: "cad", format: "png", stage: "browser" },
33
+ { type: "cad", format: "glb", stage: "mesh" },
34
+ { type: "cad", format: "stl", stage: "mesh" },
35
+ { type: "html", format: "png", stage: "browser" },
36
+ { type: "html", format: "pdf", stage: "browser" },
37
+ { type: "html", format: "md", stage: "html" },
38
+ ];
39
+ /** Returns the pair of the table, or undefined when the design does not list it. */
40
+ export function findPair(type, format) {
41
+ return PAIRS.find((p) => p.type === type && p.format === format);
42
+ }
43
+ //# sourceMappingURL=pairs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pairs.js","sourceRoot":"","sources":["../src/pairs.ts"],"names":[],"mappings":"AASA,mFAAmF;AACnF,MAAM,CAAC,MAAM,KAAK,GAAwB;IACxC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE;IAC9C,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE;IAC9C,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE;IAChD,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE;IACpD,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE;IACpD,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE;IACpD,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE;IAC9C,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE;IA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AAI,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC;AACnE,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The most megabytes of RGBA pixels that one PNG render accepts. Measured: a render holds about two
3
+ * copies of the pixel buffer (the pixmap and the PNG encoder input), so the peak is 2.0 times the pixels
4
+ * (8000 by 8000 pixels peak at 536 MB, 16000 by 16000 at 1999 MB). WASM memory ends at 4 GiB.
5
+ */
6
+ export declare const MAX_PNG_PIXEL_MB = 1024;
7
+ /** The options of one SVG to PNG render. */
8
+ export interface SvgToPngOptions {
9
+ scale: number;
10
+ maxMemoryMb: number;
11
+ font?: Uint8Array;
12
+ /**
13
+ * The folder URL of the bundled files. When the folder URL is absent, the code uses the
14
+ * package assets folder (DEFAULT_ASSETS_URL). The code reads the WASM file from this folder on
15
+ * the first start of the module only.
16
+ */
17
+ assetsUrl?: string;
18
+ /** Replaces the reader of the resvg WASM file. Tests use it to fail the first start. */
19
+ readWasm?: () => Uint8Array;
20
+ }
21
+ /** Renders an SVG to PNG bytes with resvg. The scale multiplies the SVG size. A pixel buffer over maxMemoryMb or over MAX_PNG_PIXEL_MB rejects with E_LIMIT. */
22
+ export declare function svgToPng(svg: string, options: SvgToPngOptions): Promise<Uint8Array>;
23
+ /** Tells whether the bytes start with a TrueType, OpenType or Apple TrueType font signature. A collection (ttcf) is not a single font. */
24
+ export declare function isFontFile(bytes: Uint8Array): boolean;
@@ -0,0 +1,83 @@
1
+ import { initWasm, Resvg } from "@resvg/resvg-wasm";
2
+ import { readAsset, RESVG_WASM_FILE } from "../assets.js";
3
+ import { DEFAULT_ASSETS_URL } from "../config.js";
4
+ import { RenderError } from "../errors.js";
5
+ /**
6
+ * The most megabytes of RGBA pixels that one PNG render accepts. Measured: a render holds about two
7
+ * copies of the pixel buffer (the pixmap and the PNG encoder input), so the peak is 2.0 times the pixels
8
+ * (8000 by 8000 pixels peak at 536 MB, 16000 by 16000 at 1999 MB). WASM memory ends at 4 GiB.
9
+ */
10
+ export const MAX_PNG_PIXEL_MB = 1024;
11
+ let wasmPromise;
12
+ // The first start decides the bytes; later calls reuse the started module whatever their assetsUrl.
13
+ // A failed start is not cached, so a later render can try again.
14
+ function ensureWasm(readWasm) {
15
+ if (wasmPromise === undefined) {
16
+ const started = (async () => {
17
+ const bytes = readWasm();
18
+ try {
19
+ await initWasm(bytes);
20
+ }
21
+ catch (err) {
22
+ const message = err instanceof Error ? err.message : String(err);
23
+ throw new RenderError("E_STAGE_MISSING", RESVG_WASM_FILE + " is not a usable WebAssembly module: " + message);
24
+ }
25
+ })();
26
+ wasmPromise = started;
27
+ started.catch(() => {
28
+ if (wasmPromise === started) {
29
+ wasmPromise = undefined;
30
+ }
31
+ });
32
+ }
33
+ return wasmPromise;
34
+ }
35
+ /** Renders an SVG to PNG bytes with resvg. The scale multiplies the SVG size. A pixel buffer over maxMemoryMb or over MAX_PNG_PIXEL_MB rejects with E_LIMIT. */
36
+ export async function svgToPng(svg, options) {
37
+ const assetsUrl = options.assetsUrl ?? DEFAULT_ASSETS_URL;
38
+ await ensureWasm(options.readWasm ?? (() => readAsset(assetsUrl, RESVG_WASM_FILE)));
39
+ let resvg;
40
+ try {
41
+ resvg = new Resvg(svg, {
42
+ fitTo: { mode: "zoom", value: options.scale },
43
+ dpi: 72,
44
+ font: { loadSystemFonts: false, fontBuffers: options.font ? [options.font] : [] },
45
+ });
46
+ }
47
+ catch (err) {
48
+ throw new RenderError("E_INPUT", "resvg cannot read the SVG: " + (err instanceof Error ? err.message : String(err)));
49
+ }
50
+ try {
51
+ const limitMb = Math.min(options.maxMemoryMb, MAX_PNG_PIXEL_MB);
52
+ const limitBytes = limitMb * 1048576;
53
+ const needed = Math.ceil(resvg.width * options.scale) * Math.ceil(resvg.height * options.scale) * 4;
54
+ if (needed > limitBytes) {
55
+ throw new RenderError("E_LIMIT", "the PNG needs " + needed + " bytes of pixels; the limit is " + limitBytes + " bytes");
56
+ }
57
+ return resvg.render().asPng();
58
+ }
59
+ finally {
60
+ resvg.free();
61
+ }
62
+ }
63
+ /** Tells whether the bytes start with a TrueType, OpenType or Apple TrueType font signature. A collection (ttcf) is not a single font. */
64
+ export function isFontFile(bytes) {
65
+ if (bytes.length < 4) {
66
+ return false;
67
+ }
68
+ const b0 = bytes[0];
69
+ const b1 = bytes[1];
70
+ const b2 = bytes[2];
71
+ const b3 = bytes[3];
72
+ if (b0 === 0x00 && b1 === 0x01 && b2 === 0x00 && b3 === 0x00) {
73
+ return true;
74
+ }
75
+ if (b0 === 0x4f && b1 === 0x54 && b2 === 0x54 && b3 === 0x4f) {
76
+ return true;
77
+ }
78
+ if (b0 === 0x74 && b1 === 0x72 && b2 === 0x75 && b3 === 0x65) {
79
+ return true;
80
+ }
81
+ return false;
82
+ }
83
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/raster/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAiBrC,IAAI,WAAsC,CAAC;AAE3C,oGAAoG;AACpG,iEAAiE;AACjE,SAAS,UAAU,CAAC,QAA0B;IAC5C,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC9B,MAAM,OAAO,GAAG,CAAC,KAAK,IAAI,EAAE;YAC1B,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC;YACzB,IAAI,CAAC;gBACH,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;YACxB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,MAAM,OAAO,GAAG,GAAG,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IAAI,CAAC;IACd,CAAC;IACD,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC;QAC7D,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC;QAC7D,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,12 @@
1
+ /** Tells whether the font holds a glyph for a code point. */
2
+ export type CoverageTest = (codePoint: number) => boolean;
3
+ /**
4
+ * Reads the Unicode character map of a TrueType or OpenType font (formats 4 and 12).
5
+ * Returns undefined when the font has no readable map, so the caller skips the check.
6
+ */
7
+ export declare function fontCovers(font: Uint8Array): CoverageTest | undefined;
8
+ /**
9
+ * Lists what the raster font cannot draw in the text of an SVG. The font has one face, so bold and
10
+ * italic text draw in that face. A character without a glyph draws no pixel. Each kind gives one warning.
11
+ */
12
+ export declare function rasterWarnings(svg: string, font: Uint8Array): string[];