@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
|
@@ -1,30 +1,22 @@
|
|
|
1
|
-
import { MessageSpecification } from
|
|
1
|
+
import { MessageSpecification } from "@swirly/types";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '../types.js'
|
|
8
|
-
import { completeMessageRenderer } from './complete.js'
|
|
9
|
-
import { errorMessageRenderer } from './error.js'
|
|
10
|
-
import { scalarMessageRenderer } from './scalar.js'
|
|
3
|
+
import { MessageRendererOptions, RendererContext, RendererResult } from "../types.js";
|
|
4
|
+
import { completeMessageRenderer } from "./complete.js";
|
|
5
|
+
import { errorMessageRenderer } from "./error.js";
|
|
6
|
+
import { scalarMessageRenderer } from "./scalar.js";
|
|
11
7
|
|
|
12
|
-
const strategies = [
|
|
13
|
-
completeMessageRenderer,
|
|
14
|
-
errorMessageRenderer,
|
|
15
|
-
scalarMessageRenderer
|
|
16
|
-
]
|
|
8
|
+
const strategies = [completeMessageRenderer, errorMessageRenderer, scalarMessageRenderer];
|
|
17
9
|
|
|
18
10
|
const supports = ({ notification }: MessageSpecification) =>
|
|
19
|
-
!(
|
|
11
|
+
!("value" in notification) || typeof notification.value !== "object";
|
|
20
12
|
|
|
21
13
|
const render = (
|
|
22
14
|
ctx: RendererContext,
|
|
23
15
|
message: MessageSpecification,
|
|
24
|
-
options: MessageRendererOptions
|
|
16
|
+
options: MessageRendererOptions,
|
|
25
17
|
): RendererResult => {
|
|
26
|
-
const renderer = strategies.find((renderer) => renderer.supports(message))
|
|
27
|
-
return renderer.render(ctx, message, options)
|
|
28
|
-
}
|
|
18
|
+
const renderer = strategies.find((renderer) => renderer.supports(message))!;
|
|
19
|
+
return renderer.render(ctx, message, options);
|
|
20
|
+
};
|
|
29
21
|
|
|
30
|
-
export const nonStreamMessageRenderer = { supports, render }
|
|
22
|
+
export const nonStreamMessageRenderer = { supports, render };
|
package/src/message/scalar.ts
CHANGED
|
@@ -1,94 +1,86 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MessageSpecification,
|
|
3
3
|
ScalarNextMessageStyles,
|
|
4
|
-
ScalarNextNotificationSpecification
|
|
5
|
-
} from
|
|
4
|
+
ScalarNextNotificationSpecification,
|
|
5
|
+
} from "@swirly/types";
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from
|
|
12
|
-
import { mergeStyles } from '../util/merge-styles.js'
|
|
13
|
-
import { stringToColor } from '../util/string-to-color.js'
|
|
14
|
-
import { createSvgElement } from '../util/svg-xml.js'
|
|
15
|
-
import { rotate, translate } from '../util/transform.js'
|
|
7
|
+
import { MessageRendererOptions, RendererContext, RendererResult } from "../types.js";
|
|
8
|
+
import { mergeStyles } from "../util/merge-styles.js";
|
|
9
|
+
import { stringToColor } from "../util/string-to-color.js";
|
|
10
|
+
import { createSvgElement } from "../util/svg-xml.js";
|
|
11
|
+
import { rotate, translate } from "../util/transform.js";
|
|
16
12
|
|
|
17
|
-
const COLOR_TO_MODE: Record<string,
|
|
18
|
-
auto:
|
|
19
|
-
auto_light:
|
|
20
|
-
auto_dark:
|
|
21
|
-
}
|
|
13
|
+
const COLOR_TO_MODE: Record<string, "light" | "dark"> = {
|
|
14
|
+
auto: "light",
|
|
15
|
+
auto_light: "light",
|
|
16
|
+
auto_dark: "dark",
|
|
17
|
+
};
|
|
22
18
|
|
|
23
|
-
const supports = () => true
|
|
19
|
+
const supports = () => true;
|
|
24
20
|
|
|
25
21
|
const render = (
|
|
26
22
|
{ document, styles, streamHeight }: RendererContext,
|
|
27
23
|
message: MessageSpecification,
|
|
28
|
-
{ valueAngle }: MessageRendererOptions
|
|
24
|
+
{ valueAngle }: MessageRendererOptions,
|
|
29
25
|
): RendererResult => {
|
|
30
|
-
const s: ScalarNextMessageStyles = mergeStyles(
|
|
31
|
-
|
|
32
|
-
message.styles,
|
|
33
|
-
'event_'
|
|
34
|
-
)
|
|
35
|
-
const { value } = message.notification as ScalarNextNotificationSpecification
|
|
26
|
+
const s: ScalarNextMessageStyles = mergeStyles(styles, message.styles, "event_");
|
|
27
|
+
const { value } = message.notification as ScalarNextNotificationSpecification;
|
|
36
28
|
|
|
37
|
-
const x = message.frame * styles.frame_width! - styles.event_radius
|
|
29
|
+
const x = message.frame * styles.frame_width! - styles.event_radius!;
|
|
38
30
|
|
|
39
|
-
const $group = createSvgElement(document,
|
|
40
|
-
translate($group, x, 0)
|
|
31
|
+
const $group = createSvgElement(document, "g");
|
|
32
|
+
translate($group, x, 0);
|
|
41
33
|
|
|
42
|
-
const fillColorMode = COLOR_TO_MODE[s.fill_color!]
|
|
34
|
+
const fillColorMode = COLOR_TO_MODE[s.fill_color!];
|
|
43
35
|
const finalFillColor =
|
|
44
|
-
fillColorMode != null ? stringToColor(value, fillColorMode) : s.fill_color
|
|
36
|
+
fillColorMode != null ? stringToColor(value, fillColorMode) : s.fill_color!;
|
|
45
37
|
|
|
46
38
|
$group.appendChild(
|
|
47
|
-
createSvgElement(document,
|
|
39
|
+
createSvgElement(document, "ellipse", {
|
|
48
40
|
cx: styles.event_radius,
|
|
49
41
|
cy: streamHeight / 2,
|
|
50
42
|
rx: styles.event_radius! - s.stroke_width! / 2,
|
|
51
43
|
ry: styles.event_radius! - s.stroke_width! / 2,
|
|
52
44
|
fill: finalFillColor,
|
|
53
45
|
stroke: s.stroke_color!,
|
|
54
|
-
|
|
55
|
-
})
|
|
56
|
-
)
|
|
46
|
+
"stroke-width": s.stroke_width!,
|
|
47
|
+
}),
|
|
48
|
+
);
|
|
57
49
|
|
|
58
50
|
const $label = createSvgElement(
|
|
59
51
|
document,
|
|
60
|
-
|
|
52
|
+
"text",
|
|
61
53
|
{
|
|
62
54
|
x: 0,
|
|
63
55
|
y: 0,
|
|
64
56
|
fill: s.value_color!,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
57
|
+
"font-family": s.value_font_family!,
|
|
58
|
+
"font-size": s.value_font_size! + "px",
|
|
59
|
+
"font-weight": s.value_font_weight!,
|
|
60
|
+
"font-style": s.value_font_style!,
|
|
61
|
+
"dominant-baseline": "middle",
|
|
62
|
+
"text-anchor": "middle",
|
|
71
63
|
},
|
|
72
|
-
value
|
|
73
|
-
)
|
|
74
|
-
translate($label, styles.event_radius!, streamHeight / 2)
|
|
75
|
-
rotate($label, valueAngle, 0, 0)
|
|
76
|
-
$group.appendChild($label)
|
|
64
|
+
value,
|
|
65
|
+
);
|
|
66
|
+
translate($label, styles.event_radius!, streamHeight / 2);
|
|
67
|
+
rotate($label, valueAngle, 0, 0);
|
|
68
|
+
$group.appendChild($label);
|
|
77
69
|
|
|
78
70
|
const bbox = {
|
|
79
71
|
x1: x,
|
|
80
72
|
y1: 0,
|
|
81
73
|
x2: x + styles.event_radius! * 2,
|
|
82
|
-
y2: streamHeight
|
|
83
|
-
}
|
|
74
|
+
y2: streamHeight,
|
|
75
|
+
};
|
|
84
76
|
|
|
85
77
|
return {
|
|
86
78
|
element: $group,
|
|
87
|
-
bbox
|
|
88
|
-
}
|
|
89
|
-
}
|
|
79
|
+
bbox,
|
|
80
|
+
};
|
|
81
|
+
};
|
|
90
82
|
|
|
91
83
|
export const scalarMessageRenderer = {
|
|
92
84
|
supports,
|
|
93
|
-
render
|
|
94
|
-
}
|
|
85
|
+
render,
|
|
86
|
+
};
|
package/src/message/stream.ts
CHANGED
|
@@ -1,55 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import { rotateRectangle, translateRectangle } from '../util/geometry.js'
|
|
14
|
-
import { rotate, translate } from '../util/transform.js'
|
|
15
|
-
import { nonStreamMessageRenderer } from './non-stream.js'
|
|
16
|
-
|
|
17
|
-
const supports = (message: MessageSpecification) =>
|
|
18
|
-
!nonStreamMessageRenderer.supports(message)
|
|
19
|
-
|
|
20
|
-
const renderStreamImpl = createRenderStream(nonStreamMessageRenderer.render)
|
|
1
|
+
import { MessageSpecification, StreamNextNotificationSpecification } from "@swirly/types";
|
|
2
|
+
|
|
3
|
+
import { createRenderStream } from "../stream/factory.js";
|
|
4
|
+
import { MessageRendererOptions, RendererContext, RendererResult } from "../types.js";
|
|
5
|
+
import { degreesToRadians } from "../util/degrees-to-radians.js";
|
|
6
|
+
import { rotateRectangle, translateRectangle } from "../util/geometry.js";
|
|
7
|
+
import { rotate, translate } from "../util/transform.js";
|
|
8
|
+
import { nonStreamMessageRenderer } from "./non-stream.js";
|
|
9
|
+
|
|
10
|
+
const supports = (message: MessageSpecification) => !nonStreamMessageRenderer.supports(message);
|
|
11
|
+
|
|
12
|
+
const renderStreamImpl = createRenderStream(nonStreamMessageRenderer.render);
|
|
21
13
|
|
|
22
14
|
const render = (
|
|
23
15
|
ctx: RendererContext,
|
|
24
16
|
{ frame, notification }: MessageSpecification,
|
|
25
|
-
{ verticalOffset }: MessageRendererOptions
|
|
17
|
+
{ verticalOffset }: MessageRendererOptions,
|
|
26
18
|
): RendererResult => {
|
|
27
|
-
const { styles, streamHeight } = ctx
|
|
28
|
-
const { value, isGhost } = notification as StreamNextNotificationSpecification
|
|
19
|
+
const { styles, streamHeight } = ctx;
|
|
20
|
+
const { value, isGhost } = notification as StreamNextNotificationSpecification;
|
|
29
21
|
|
|
30
|
-
const x = frame * styles.frame_width
|
|
31
|
-
const y = streamHeight / 2 + verticalOffset
|
|
22
|
+
const x = frame * styles.frame_width!;
|
|
23
|
+
const y = streamHeight / 2 + verticalOffset;
|
|
32
24
|
|
|
33
|
-
const { element: $group, bbox } = renderStreamImpl(ctx, value, true, isGhost)
|
|
25
|
+
const { element: $group, bbox } = renderStreamImpl(ctx, value, true, isGhost);
|
|
34
26
|
|
|
35
|
-
rotate($group, styles.higher_order_angle!, x, y)
|
|
36
|
-
translate($group, x, 0)
|
|
27
|
+
rotate($group, styles.higher_order_angle!, x, y);
|
|
28
|
+
translate($group, x, 0);
|
|
37
29
|
|
|
38
|
-
const rotatedBBox = rotateRectangle(
|
|
39
|
-
|
|
40
|
-
degreesToRadians(styles.higher_order_angle!),
|
|
41
|
-
0,
|
|
42
|
-
y
|
|
43
|
-
)
|
|
44
|
-
const translatedBBox = translateRectangle(rotatedBBox, x, 0)
|
|
30
|
+
const rotatedBBox = rotateRectangle(bbox, degreesToRadians(styles.higher_order_angle!), 0, y);
|
|
31
|
+
const translatedBBox = translateRectangle(rotatedBBox, x, 0);
|
|
45
32
|
|
|
46
33
|
return {
|
|
47
34
|
element: $group,
|
|
48
|
-
bbox: translatedBBox
|
|
49
|
-
}
|
|
50
|
-
}
|
|
35
|
+
bbox: translatedBBox,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
51
38
|
|
|
52
39
|
export const streamMessageRenderer = {
|
|
53
40
|
supports,
|
|
54
|
-
render
|
|
55
|
-
}
|
|
41
|
+
render,
|
|
42
|
+
};
|
package/src/operator.ts
CHANGED
|
@@ -3,195 +3,203 @@ import {
|
|
|
3
3
|
OperatorSpecification,
|
|
4
4
|
OperatorStyles,
|
|
5
5
|
OperatorTitleSegment,
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
StreamOperatorTitleSegment,
|
|
7
|
+
StreamSpecification,
|
|
8
|
+
TextOperatorTitleSegment,
|
|
9
|
+
} from "@swirly/types";
|
|
8
10
|
|
|
9
|
-
import { renderStreamBase } from
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} from './types.js'
|
|
15
|
-
import { mergeStyles } from './util/merge-styles.js'
|
|
16
|
-
import {
|
|
17
|
-
createSvgDocument,
|
|
18
|
-
createSvgElement,
|
|
19
|
-
setSvgDimensions,
|
|
20
|
-
XHTML_NS
|
|
21
|
-
} from './util/svg-xml.js'
|
|
11
|
+
import { renderStreamBase } from "./stream/core.js";
|
|
12
|
+
import { PostRenderUpdateContext, RendererContext, UpdatableRendererResult } from "./types.js";
|
|
13
|
+
import { mergeStyles } from "./util/merge-styles.js";
|
|
14
|
+
import { createSvgDocument, createSvgElement, setSvgDimensions, XHTML_NS } from "./util/svg-xml.js";
|
|
15
|
+
import { translate } from "./util/transform.js";
|
|
22
16
|
|
|
23
|
-
const NON_BREAKING_SPACE =
|
|
17
|
+
const NON_BREAKING_SPACE = "\xA0";
|
|
24
18
|
|
|
25
|
-
const reSpace = / /g
|
|
19
|
+
const reSpace = / /g;
|
|
26
20
|
|
|
27
21
|
const createRootDiv = (document: Document, styles: Record<string, any>) => {
|
|
28
|
-
const $div = document.createElementNS(XHTML_NS,
|
|
22
|
+
const $div = document.createElementNS(XHTML_NS, "div");
|
|
29
23
|
$div.setAttribute(
|
|
30
|
-
|
|
24
|
+
"style",
|
|
31
25
|
Object.entries(styles)
|
|
32
26
|
.map(([name, value]) => `${name}: ${value};`)
|
|
33
|
-
.join(
|
|
34
|
-
)
|
|
35
|
-
return $div
|
|
36
|
-
}
|
|
27
|
+
.join(" "),
|
|
28
|
+
);
|
|
29
|
+
return $div;
|
|
30
|
+
};
|
|
37
31
|
|
|
38
32
|
const renderStream = (spec: StreamSpecification, ctx: RendererContext) => {
|
|
39
33
|
const {
|
|
40
34
|
element: $group,
|
|
41
|
-
bbox: { x2
|
|
42
|
-
} = renderStreamBase(ctx, spec, false, false)
|
|
35
|
+
bbox: { x1, x2, y2 },
|
|
36
|
+
} = renderStreamBase(ctx, spec, false, false);
|
|
37
|
+
let width;
|
|
38
|
+
if (x1 < 0) {
|
|
39
|
+
translate($group, -x1, 0);
|
|
40
|
+
width = x2 - x1;
|
|
41
|
+
} else {
|
|
42
|
+
width = x2;
|
|
43
|
+
}
|
|
43
44
|
return {
|
|
44
45
|
$group,
|
|
45
46
|
width,
|
|
46
|
-
height
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
47
|
+
height: y2,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const renderStreamTitleSegment = (
|
|
52
|
+
segment: StreamOperatorTitleSegment,
|
|
53
|
+
ctx: RendererContext,
|
|
54
|
+
styles: OperatorStyles,
|
|
55
|
+
) => {
|
|
56
|
+
const { documentElement: $svg } = createSvgDocument(ctx.DOMParser);
|
|
57
|
+
const { $group, width, height } = renderStream(segment.value, ctx);
|
|
58
|
+
setSvgDimensions($svg, width, height, (styles.stream_scale ?? 100) / 100);
|
|
59
|
+
$svg.appendChild($group);
|
|
60
|
+
return $svg;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const renderTextTitleSegment = (segment: TextOperatorTitleSegment, ctx: RendererContext) => {
|
|
64
|
+
const $div = ctx.document.createElement("div");
|
|
65
|
+
$div.textContent = segment.value.replace(reSpace, NON_BREAKING_SPACE);
|
|
66
|
+
return $div;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const renderTitleSegment = (
|
|
70
|
+
segment: OperatorTitleSegment,
|
|
71
|
+
ctx: RendererContext,
|
|
72
|
+
styles: OperatorStyles,
|
|
73
|
+
) => {
|
|
74
|
+
switch (segment.type) {
|
|
75
|
+
case "stream":
|
|
76
|
+
return renderStreamTitleSegment(segment, ctx, styles);
|
|
77
|
+
case "text":
|
|
78
|
+
return renderTextTitleSegment(segment, ctx);
|
|
79
|
+
default:
|
|
80
|
+
return null;
|
|
66
81
|
}
|
|
67
|
-
}
|
|
82
|
+
};
|
|
68
83
|
|
|
69
84
|
const renderRichTitle = (
|
|
70
85
|
segments: OperatorTitleSegment[],
|
|
71
86
|
ctx: RendererContext,
|
|
72
87
|
color: Color,
|
|
73
88
|
styles: OperatorStyles,
|
|
74
|
-
fontStyles: Record<string, any
|
|
89
|
+
fontStyles: Record<string, any>,
|
|
75
90
|
) => {
|
|
76
|
-
const $foreignObject = createSvgElement(ctx.document,
|
|
91
|
+
const $foreignObject = createSvgElement(ctx.document, "foreignObject", {
|
|
77
92
|
y: styles.spacing!,
|
|
78
|
-
height: styles.height
|
|
79
|
-
})
|
|
93
|
+
height: styles.height!,
|
|
94
|
+
});
|
|
80
95
|
const $container = createRootDiv(ctx.document, {
|
|
81
|
-
width:
|
|
82
|
-
height:
|
|
83
|
-
display:
|
|
84
|
-
|
|
85
|
-
|
|
96
|
+
width: "100%",
|
|
97
|
+
height: "100%",
|
|
98
|
+
display: "flex",
|
|
99
|
+
"align-items": "center",
|
|
100
|
+
"justify-content": "center",
|
|
86
101
|
color,
|
|
87
|
-
...fontStyles
|
|
88
|
-
})
|
|
89
|
-
$foreignObject.appendChild($container)
|
|
102
|
+
...fontStyles,
|
|
103
|
+
});
|
|
104
|
+
$foreignObject.appendChild($container);
|
|
90
105
|
for (const segment of segments) {
|
|
91
|
-
const $element =
|
|
92
|
-
|
|
93
|
-
ctx,
|
|
94
|
-
styles
|
|
95
|
-
)
|
|
96
|
-
$container.appendChild($element)
|
|
106
|
+
const $element = renderTitleSegment(segment, ctx, styles)!;
|
|
107
|
+
$container.appendChild($element);
|
|
97
108
|
}
|
|
98
|
-
return $foreignObject
|
|
99
|
-
}
|
|
109
|
+
return $foreignObject;
|
|
110
|
+
};
|
|
100
111
|
|
|
101
112
|
const renderTextTitle = (
|
|
102
113
|
text: string,
|
|
103
114
|
ctx: RendererContext,
|
|
104
115
|
color: Color,
|
|
105
116
|
styles: OperatorStyles,
|
|
106
|
-
fontStyles: Record<string, any
|
|
117
|
+
fontStyles: Record<string, any>,
|
|
107
118
|
) =>
|
|
108
119
|
createSvgElement(
|
|
109
120
|
ctx.document,
|
|
110
|
-
|
|
121
|
+
"text",
|
|
111
122
|
{
|
|
112
123
|
x: styles.spacing!,
|
|
113
124
|
y: styles.spacing! + styles.height! / 2,
|
|
114
125
|
fill: color,
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
...fontStyles
|
|
126
|
+
"dominant-baseline": "middle",
|
|
127
|
+
"text-anchor": "middle",
|
|
128
|
+
...fontStyles,
|
|
118
129
|
},
|
|
119
|
-
text
|
|
120
|
-
)
|
|
130
|
+
text,
|
|
131
|
+
);
|
|
121
132
|
|
|
122
133
|
const renderTitle = (
|
|
123
134
|
segments: OperatorTitleSegment[],
|
|
124
135
|
ctx: RendererContext,
|
|
125
|
-
styles: OperatorStyles
|
|
136
|
+
styles: OperatorStyles,
|
|
126
137
|
) => {
|
|
127
|
-
const color = styles.title_color
|
|
138
|
+
const color = styles.title_color!;
|
|
128
139
|
const fontStyles = {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
140
|
+
"font-family": styles.title_font_family!,
|
|
141
|
+
"font-size": styles.title_font_size! + "px",
|
|
142
|
+
"font-weight": styles.title_font_weight!,
|
|
143
|
+
"font-style": styles.title_font_style!,
|
|
144
|
+
};
|
|
134
145
|
|
|
135
|
-
const isText = segments.length === 1 && segments[0].type ===
|
|
146
|
+
const isText = segments.length === 1 && segments[0].type === "text";
|
|
136
147
|
|
|
137
148
|
const $title = isText
|
|
138
149
|
? renderTextTitle(
|
|
139
|
-
segments[0]
|
|
150
|
+
(segments[0] as TextOperatorTitleSegment).value,
|
|
140
151
|
ctx,
|
|
141
152
|
color,
|
|
142
153
|
styles,
|
|
143
|
-
fontStyles
|
|
144
|
-
|
|
145
|
-
: renderRichTitle(segments, ctx, color, styles, fontStyles)
|
|
154
|
+
fontStyles,
|
|
155
|
+
)
|
|
156
|
+
: renderRichTitle(segments, ctx, color, styles, fontStyles);
|
|
146
157
|
|
|
147
|
-
return { $title, shouldCenter: isText }
|
|
148
|
-
}
|
|
158
|
+
return { $title, shouldCenter: isText };
|
|
159
|
+
};
|
|
149
160
|
|
|
150
161
|
export const renderOperator = (
|
|
151
162
|
ctx: RendererContext,
|
|
152
|
-
operator: OperatorSpecification
|
|
163
|
+
operator: OperatorSpecification,
|
|
153
164
|
): UpdatableRendererResult => {
|
|
154
|
-
const s: OperatorStyles = mergeStyles(
|
|
155
|
-
ctx.styles,
|
|
156
|
-
operator.styles,
|
|
157
|
-
'operator_'
|
|
158
|
-
)
|
|
165
|
+
const s: OperatorStyles = mergeStyles(ctx.styles, operator.styles, "operator_");
|
|
159
166
|
|
|
160
|
-
const $group = createSvgElement(ctx.document,
|
|
167
|
+
const $group = createSvgElement(ctx.document, "g");
|
|
161
168
|
|
|
162
|
-
const $rect = createSvgElement(ctx.document,
|
|
163
|
-
x:
|
|
164
|
-
y: s.spacing
|
|
169
|
+
const $rect = createSvgElement(ctx.document, "rect", {
|
|
170
|
+
x: s.stroke_width! / 2,
|
|
171
|
+
y: s.spacing! + s.stroke_width! / 2,
|
|
165
172
|
width: 1,
|
|
166
173
|
height: s.height! - s.stroke_width!,
|
|
167
174
|
fill: s.fill_color!,
|
|
168
175
|
stroke: s.stroke_color!,
|
|
169
|
-
|
|
170
|
-
rx: s.corner_radius
|
|
171
|
-
})
|
|
172
|
-
$group.appendChild($rect)
|
|
176
|
+
"stroke-width": s.stroke_width!,
|
|
177
|
+
rx: s.corner_radius!,
|
|
178
|
+
});
|
|
179
|
+
$group.appendChild($rect);
|
|
173
180
|
|
|
174
|
-
const { $title, shouldCenter } = renderTitle(operator.title, ctx, s)
|
|
175
|
-
$group.appendChild($title)
|
|
181
|
+
const { $title, shouldCenter } = renderTitle(operator.title, ctx, s);
|
|
182
|
+
$group.appendChild($title);
|
|
176
183
|
|
|
177
184
|
const bbox = {
|
|
178
185
|
x1: 0,
|
|
179
186
|
y1: 0,
|
|
180
187
|
x2: 1,
|
|
181
|
-
y2: s.height! + 2 * s.spacing
|
|
182
|
-
}
|
|
188
|
+
y2: s.height! + 2 * s.spacing!,
|
|
189
|
+
};
|
|
183
190
|
|
|
184
|
-
const update = ({ width }: PostRenderUpdateContext) => {
|
|
185
|
-
$rect.setAttribute(
|
|
186
|
-
$title.setAttribute(
|
|
191
|
+
const update = ({ width, dx }: PostRenderUpdateContext) => {
|
|
192
|
+
$rect.setAttribute("width", String(width - s.stroke_width!));
|
|
193
|
+
$title.setAttribute("width", String(width));
|
|
194
|
+
translate($group, -dx, 0);
|
|
187
195
|
if (shouldCenter) {
|
|
188
|
-
$title.setAttribute(
|
|
196
|
+
$title.setAttribute("x", String(width / 2));
|
|
189
197
|
}
|
|
190
|
-
}
|
|
198
|
+
};
|
|
191
199
|
|
|
192
200
|
return {
|
|
193
201
|
element: $group,
|
|
194
202
|
bbox,
|
|
195
|
-
update
|
|
196
|
-
}
|
|
197
|
-
}
|
|
203
|
+
update,
|
|
204
|
+
};
|
|
205
|
+
};
|
package/src/stream/core.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { renderMessage } from
|
|
2
|
-
import { createRenderStream } from
|
|
1
|
+
import { renderMessage } from "../message/index.js";
|
|
2
|
+
import { createRenderStream } from "./factory.js";
|
|
3
3
|
|
|
4
|
-
export const renderStreamBase = createRenderStream(renderMessage)
|
|
4
|
+
export const renderStreamBase = createRenderStream(renderMessage);
|