UNPKG

2.88 kBJavaScriptView Raw
1import { sanitizeUrl } from "@braintree/sanitize-url";
2import { J as lineBreakRegex } from "./mermaid-6dc72991.js";
3const drawRect = (element, rectData) => {
4 const rectElement = element.append("rect");
5 rectElement.attr("x", rectData.x);
6 rectElement.attr("y", rectData.y);
7 rectElement.attr("fill", rectData.fill);
8 rectElement.attr("stroke", rectData.stroke);
9 rectElement.attr("width", rectData.width);
10 rectElement.attr("height", rectData.height);
11 if (rectData.name) {
12 rectElement.attr("name", rectData.name);
13 }
14 rectData.rx !== void 0 && rectElement.attr("rx", rectData.rx);
15 rectData.ry !== void 0 && rectElement.attr("ry", rectData.ry);
16 if (rectData.attrs !== void 0) {
17 for (const attrKey in rectData.attrs) {
18 rectElement.attr(attrKey, rectData.attrs[attrKey]);
19 }
20 }
21 rectData.class !== void 0 && rectElement.attr("class", rectData.class);
22 return rectElement;
23};
24const drawBackgroundRect = (element, bounds) => {
25 const rectData = {
26 x: bounds.startx,
27 y: bounds.starty,
28 width: bounds.stopx - bounds.startx,
29 height: bounds.stopy - bounds.starty,
30 fill: bounds.fill,
31 stroke: bounds.stroke,
32 class: "rect"
33 };
34 const rectElement = drawRect(element, rectData);
35 rectElement.lower();
36};
37const drawText = (element, textData) => {
38 const nText = textData.text.replace(lineBreakRegex, " ");
39 const textElem = element.append("text");
40 textElem.attr("x", textData.x);
41 textElem.attr("y", textData.y);
42 textElem.attr("class", "legend");
43 textElem.style("text-anchor", textData.anchor);
44 textData.class !== void 0 && textElem.attr("class", textData.class);
45 const tspan = textElem.append("tspan");
46 tspan.attr("x", textData.x + textData.textMargin * 2);
47 tspan.text(nText);
48 return textElem;
49};
50const drawImage = (elem, x, y, link) => {
51 const imageElement = elem.append("image");
52 imageElement.attr("x", x);
53 imageElement.attr("y", y);
54 const sanitizedLink = sanitizeUrl(link);
55 imageElement.attr("xlink:href", sanitizedLink);
56};
57const drawEmbeddedImage = (element, x, y, link) => {
58 const imageElement = element.append("use");
59 imageElement.attr("x", x);
60 imageElement.attr("y", y);
61 const sanitizedLink = sanitizeUrl(link);
62 imageElement.attr("xlink:href", `#${sanitizedLink}`);
63};
64const getNoteRect = () => {
65 const noteRectData = {
66 x: 0,
67 y: 0,
68 width: 100,
69 height: 100,
70 fill: "#EDF2AE",
71 stroke: "#666",
72 anchor: "start",
73 rx: 0,
74 ry: 0
75 };
76 return noteRectData;
77};
78const getTextObj = () => {
79 const testObject = {
80 x: 0,
81 y: 0,
82 width: 100,
83 height: 100,
84 "text-anchor": "start",
85 style: "#666",
86 textMargin: 0,
87 rx: 0,
88 ry: 0,
89 tspan: true
90 };
91 return testObject;
92};
93export {
94 drawBackgroundRect as a,
95 drawEmbeddedImage as b,
96 drawImage as c,
97 drawRect as d,
98 getTextObj as e,
99 drawText as f,
100 getNoteRect as g
101};