Files
Investidor-V2/outputs/investmoz-audit-current-20261012/node_modules/@viz-js/viz/src/viz.js
T
nala ba1c0340ea
tests / ci (push) Canceled after 0s
oportunidades 8
2026-10-14 08:25:30 +02:00

74 lines
1.6 KiB
JavaScript

import { getGraphvizVersion, getPluginList, renderInput } from "./wrapper.js";
class Viz {
constructor(module) {
this.module = module;
}
get graphvizVersion() {
return getGraphvizVersion(this.module);
}
get formats() {
return getPluginList(this.module, "device");
}
get engines() {
return getPluginList(this.module, "layout");
}
renderFormats(input, formats, options = {}) {
return renderInput(this.module, input, formats, { engine: "dot", ...options });
}
render(input, options = {}) {
let format;
if (options.format === void 0) {
format = "dot";
} else {
format = options.format;
}
let result = renderInput(this.module, input, [format], { engine: "dot", ...options });
if (result.status === "success") {
result.output = result.output[format];
}
return result;
}
renderString(src, options = {}) {
const result = this.render(src, options);
if (result.status !== "success") {
throw new Error(result.errors.find(e => e.level == "error")?.message || "render failed");
}
return result.output;
}
renderSVGElement(src, options = {}) {
const str = this.renderString(src, { ...options, format: "svg" });
let input;
if (typeof options.trustedTypePolicy !== "undefined") {
input = options.trustedTypePolicy.createHTML(str);
} else {
input = str;
}
const parser = new DOMParser();
return parser.parseFromString(input, "image/svg+xml").documentElement;
}
renderJSON(src, options = {}) {
const str = this.renderString(src, { ...options, format: "json" });
return JSON.parse(str);
}
}
export default Viz;