@swirly/renderer 0.20.0 → 0.22.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.
- package/LICENSE +1 -1
- package/README.md +4 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/arrow.d.ts +1 -1
- package/dist/arrow.js +29 -26
- package/dist/arrow.js.map +1 -1
- package/dist/decoration/barrier.d.ts +2 -2
- package/dist/decoration/barrier.js +8 -8
- package/dist/decoration/barrier.js.map +1 -1
- package/dist/decoration/index.d.ts +2 -2
- package/dist/decoration/index.js +3 -3
- package/dist/decoration/index.js.map +1 -1
- package/dist/decoration/range.d.ts +2 -2
- package/dist/decoration/range.js +7 -7
- package/dist/decoration/range.js.map +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.js +28 -20
- package/dist/index.js.map +1 -1
- package/dist/message/complete.d.ts +2 -2
- package/dist/message/complete.js +10 -10
- package/dist/message/complete.js.map +1 -1
- package/dist/message/error.d.ts +2 -2
- package/dist/message/error.js +12 -12
- package/dist/message/error.js.map +1 -1
- package/dist/message/index.d.ts +2 -2
- package/dist/message/index.js +2 -2
- package/dist/message/index.js.map +1 -1
- package/dist/message/non-stream.d.ts +2 -2
- package/dist/message/non-stream.js +5 -9
- package/dist/message/non-stream.js.map +1 -1
- package/dist/message/scalar.d.ts +2 -2
- package/dist/message/scalar.js +21 -21
- package/dist/message/scalar.js.map +1 -1
- package/dist/message/stream.d.ts +2 -2
- package/dist/message/stream.js +7 -7
- package/dist/message/stream.js.map +1 -1
- package/dist/operator.d.ts +2 -2
- package/dist/operator.js +70 -52
- package/dist/operator.js.map +1 -1
- package/dist/stream/core.d.ts +1 -1
- package/dist/stream/core.js +2 -2
- package/dist/stream/core.js.map +1 -1
- package/dist/stream/factory.d.ts +2 -2
- package/dist/stream/factory.js +18 -24
- package/dist/stream/factory.js.map +1 -1
- package/dist/stream/full.d.ts +2 -2
- package/dist/stream/full.js +14 -14
- package/dist/stream/full.js.map +1 -1
- package/dist/types.d.ts +14 -17
- package/dist/util/degrees-to-radians.js.map +1 -1
- package/dist/util/geometry.d.ts +1 -1
- package/dist/util/geometry.js +6 -6
- package/dist/util/geometry.js.map +1 -1
- package/dist/util/hex-to-dec.js +2 -2
- package/dist/util/hex-to-dec.js.map +1 -1
- package/dist/util/merge-styles.d.ts +1 -1
- package/dist/util/merge-styles.js.map +1 -1
- package/dist/util/notification-kind.js +4 -4
- package/dist/util/notification-kind.js.map +1 -1
- package/dist/util/string-to-color.d.ts +1 -1
- package/dist/util/string-to-color.js +3 -3
- package/dist/util/string-to-color.js.map +1 -1
- package/dist/util/svg-xml.d.ts +1 -1
- package/dist/util/svg-xml.js +8 -8
- package/dist/util/svg-xml.js.map +1 -1
- package/dist/util/transform.js +3 -3
- package/dist/util/transform.js.map +1 -1
- package/package.json +20 -20
- package/src/arrow.ts +43 -40
- package/src/decoration/barrier.ts +20 -24
- package/src/decoration/index.ts +11 -11
- package/src/decoration/range.ts +20 -27
- package/src/index.ts +61 -63
- package/src/message/complete.ts +24 -28
- package/src/message/error.ts +27 -27
- package/src/message/index.ts +8 -12
- package/src/message/non-stream.ts +12 -20
- package/src/message/scalar.ts +44 -52
- package/src/message/stream.ts +27 -40
- package/src/operator.ts +121 -113
- package/src/stream/core.ts +3 -3
- package/src/stream/factory.ts +86 -102
- package/src/stream/full.ts +34 -37
- package/src/types.ts +39 -43
- package/src/util/degrees-to-radians.ts +1 -2
- package/src/util/geometry.ts +29 -42
- package/src/util/hex-to-dec.ts +8 -8
- package/src/util/merge-styles.ts +9 -11
- package/src/util/notification-kind.ts +8 -8
- package/src/util/string-to-color.ts +10 -10
- package/src/util/svg-xml.ts +20 -23
- package/src/util/transform.ts +11 -17
package/src/util/svg-xml.ts
CHANGED
|
@@ -1,44 +1,41 @@
|
|
|
1
|
-
import { SVGDocument } from
|
|
1
|
+
import { SVGDocument } from "@swirly/types";
|
|
2
2
|
|
|
3
|
-
export const SVG_NS =
|
|
4
|
-
export const SVG_MIME_TYPE =
|
|
3
|
+
export const SVG_NS = "http://www.w3.org/2000/svg";
|
|
4
|
+
export const SVG_MIME_TYPE = "image/svg+xml";
|
|
5
5
|
|
|
6
|
-
export const XHTML_NS =
|
|
6
|
+
export const XHTML_NS = "http://www.w3.org/1999/xhtml";
|
|
7
7
|
|
|
8
|
-
const EMPTY_SVG_XML = `<svg xmlns="${SVG_NS}"
|
|
8
|
+
const EMPTY_SVG_XML = `<svg xmlns="${SVG_NS}"/>`;
|
|
9
9
|
|
|
10
|
-
const parseXml = (
|
|
11
|
-
xml
|
|
12
|
-
mimeType: string,
|
|
13
|
-
DOMParserImpl: typeof DOMParser = DOMParser
|
|
14
|
-
) => new DOMParserImpl().parseFromString(xml, mimeType as any) as XMLDocument
|
|
10
|
+
const parseXml = (xml: string, mimeType: string, DOMParserImpl: typeof DOMParser = DOMParser) =>
|
|
11
|
+
new DOMParserImpl().parseFromString(xml, mimeType as any) as XMLDocument;
|
|
15
12
|
|
|
16
13
|
export const createSvgDocument = (DOMParserImpl?: typeof DOMParser) =>
|
|
17
|
-
parseXml(EMPTY_SVG_XML, SVG_MIME_TYPE, DOMParserImpl) as SVGDocument
|
|
14
|
+
parseXml(EMPTY_SVG_XML, SVG_MIME_TYPE, DOMParserImpl) as SVGDocument;
|
|
18
15
|
|
|
19
16
|
export const createSvgElement = (
|
|
20
17
|
document: SVGDocument,
|
|
21
18
|
name: string,
|
|
22
19
|
attrs: Record<string, any> = {},
|
|
23
|
-
text: string =
|
|
20
|
+
text: string = "",
|
|
24
21
|
): SVGElement => {
|
|
25
|
-
const $el = document.createElementNS(SVG_NS, name)
|
|
22
|
+
const $el = document.createElementNS(SVG_NS, name);
|
|
26
23
|
for (const [name, value] of Object.entries(attrs)) {
|
|
27
|
-
$el.setAttribute(name, String(value))
|
|
24
|
+
$el.setAttribute(name, String(value));
|
|
28
25
|
}
|
|
29
|
-
if (text !==
|
|
30
|
-
$el.textContent = text
|
|
26
|
+
if (text !== "") {
|
|
27
|
+
$el.textContent = text;
|
|
31
28
|
}
|
|
32
|
-
return $el
|
|
33
|
-
}
|
|
29
|
+
return $el;
|
|
30
|
+
};
|
|
34
31
|
|
|
35
32
|
export const setSvgDimensions = (
|
|
36
33
|
$svg: SVGSVGElement,
|
|
37
34
|
width: number,
|
|
38
35
|
height: number,
|
|
39
|
-
scale: number = 1
|
|
36
|
+
scale: number = 1,
|
|
40
37
|
) => {
|
|
41
|
-
$svg.setAttribute(
|
|
42
|
-
$svg.setAttribute(
|
|
43
|
-
$svg.setAttribute(
|
|
44
|
-
}
|
|
38
|
+
$svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
|
|
39
|
+
$svg.setAttribute("width", String(width * scale));
|
|
40
|
+
$svg.setAttribute("height", String(height * scale));
|
|
41
|
+
};
|
package/src/util/transform.ts
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
export const transform = ($element: SVGElement, value: string) => {
|
|
2
|
-
const existing = $element.getAttribute(
|
|
3
|
-
const updated =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
2
|
+
const existing = $element.getAttribute("transform");
|
|
3
|
+
const updated = (existing != null && existing !== "" ? existing + " " : "") + value;
|
|
4
|
+
$element.setAttribute("transform", updated);
|
|
5
|
+
};
|
|
7
6
|
|
|
8
7
|
export const translate = ($element: SVGElement, x: number, y: number) => {
|
|
9
8
|
if (x === 0 && y === 0) {
|
|
10
|
-
return
|
|
9
|
+
return;
|
|
11
10
|
}
|
|
12
|
-
transform($element, `translate(${x} ${y})`)
|
|
13
|
-
}
|
|
11
|
+
transform($element, `translate(${x} ${y})`);
|
|
12
|
+
};
|
|
14
13
|
|
|
15
|
-
export const rotate = (
|
|
16
|
-
$element: SVGElement,
|
|
17
|
-
angle: number,
|
|
18
|
-
x: number = 0,
|
|
19
|
-
y: number = 0
|
|
20
|
-
) => {
|
|
14
|
+
export const rotate = ($element: SVGElement, angle: number, x: number = 0, y: number = 0) => {
|
|
21
15
|
if (angle === 0) {
|
|
22
|
-
return
|
|
16
|
+
return;
|
|
23
17
|
}
|
|
24
|
-
transform($element, `rotate(${angle} ${x} ${y})`)
|
|
25
|
-
}
|
|
18
|
+
transform($element, `rotate(${angle} ${x} ${y})`);
|
|
19
|
+
};
|