@swirly/renderer 0.21.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 +14 -14
- 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 +1 -1
- package/dist/index.js +15 -15
- 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 +40 -40
- 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 +13 -13
- 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 +34 -35
- 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 +55 -68
- 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 +104 -120
- 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 -39
- 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/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
|
@@ -5,217 +5,201 @@ import {
|
|
|
5
5
|
OperatorTitleSegment,
|
|
6
6
|
StreamOperatorTitleSegment,
|
|
7
7
|
StreamSpecification,
|
|
8
|
-
TextOperatorTitleSegment
|
|
9
|
-
} from
|
|
8
|
+
TextOperatorTitleSegment,
|
|
9
|
+
} from "@swirly/types";
|
|
10
10
|
|
|
11
|
-
import { renderStreamBase } from
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} from './types.js'
|
|
17
|
-
import { mergeStyles } from './util/merge-styles.js'
|
|
18
|
-
import {
|
|
19
|
-
createSvgDocument,
|
|
20
|
-
createSvgElement,
|
|
21
|
-
setSvgDimensions,
|
|
22
|
-
XHTML_NS
|
|
23
|
-
} from './util/svg-xml.js'
|
|
24
|
-
import { translate } from './util/transform.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";
|
|
25
16
|
|
|
26
|
-
const NON_BREAKING_SPACE =
|
|
17
|
+
const NON_BREAKING_SPACE = "\xA0";
|
|
27
18
|
|
|
28
|
-
const reSpace = / /g
|
|
19
|
+
const reSpace = / /g;
|
|
29
20
|
|
|
30
21
|
const createRootDiv = (document: Document, styles: Record<string, any>) => {
|
|
31
|
-
const $div = document.createElementNS(XHTML_NS,
|
|
22
|
+
const $div = document.createElementNS(XHTML_NS, "div");
|
|
32
23
|
$div.setAttribute(
|
|
33
|
-
|
|
24
|
+
"style",
|
|
34
25
|
Object.entries(styles)
|
|
35
26
|
.map(([name, value]) => `${name}: ${value};`)
|
|
36
|
-
.join(
|
|
37
|
-
)
|
|
38
|
-
return $div
|
|
39
|
-
}
|
|
27
|
+
.join(" "),
|
|
28
|
+
);
|
|
29
|
+
return $div;
|
|
30
|
+
};
|
|
40
31
|
|
|
41
32
|
const renderStream = (spec: StreamSpecification, ctx: RendererContext) => {
|
|
42
33
|
const {
|
|
43
34
|
element: $group,
|
|
44
|
-
bbox: { x1, x2, y2 }
|
|
45
|
-
} = renderStreamBase(ctx, spec, false, false)
|
|
46
|
-
let width
|
|
35
|
+
bbox: { x1, x2, y2 },
|
|
36
|
+
} = renderStreamBase(ctx, spec, false, false);
|
|
37
|
+
let width;
|
|
47
38
|
if (x1 < 0) {
|
|
48
|
-
translate($group, -x1, 0)
|
|
49
|
-
width = x2 - x1
|
|
39
|
+
translate($group, -x1, 0);
|
|
40
|
+
width = x2 - x1;
|
|
50
41
|
} else {
|
|
51
|
-
width = x2
|
|
42
|
+
width = x2;
|
|
52
43
|
}
|
|
53
44
|
return {
|
|
54
45
|
$group,
|
|
55
46
|
width,
|
|
56
|
-
height: y2
|
|
57
|
-
}
|
|
58
|
-
}
|
|
47
|
+
height: y2,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
59
50
|
|
|
60
51
|
const renderStreamTitleSegment = (
|
|
61
52
|
segment: StreamOperatorTitleSegment,
|
|
62
53
|
ctx: RendererContext,
|
|
63
|
-
styles: OperatorStyles
|
|
64
|
-
) => {
|
|
65
|
-
const { documentElement: $svg } = createSvgDocument(ctx.DOMParser)
|
|
66
|
-
const { $group, width, height } = renderStream(segment.value, ctx)
|
|
67
|
-
setSvgDimensions($svg, width, height, (styles.stream_scale ?? 100) / 100)
|
|
68
|
-
$svg.appendChild($group)
|
|
69
|
-
return $svg
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const renderTextTitleSegment = (
|
|
73
|
-
segment: TextOperatorTitleSegment,
|
|
74
|
-
ctx: RendererContext
|
|
54
|
+
styles: OperatorStyles,
|
|
75
55
|
) => {
|
|
76
|
-
const $
|
|
77
|
-
$
|
|
78
|
-
|
|
79
|
-
|
|
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
|
+
};
|
|
80
68
|
|
|
81
69
|
const renderTitleSegment = (
|
|
82
70
|
segment: OperatorTitleSegment,
|
|
83
71
|
ctx: RendererContext,
|
|
84
|
-
styles: OperatorStyles
|
|
72
|
+
styles: OperatorStyles,
|
|
85
73
|
) => {
|
|
86
74
|
switch (segment.type) {
|
|
87
|
-
case
|
|
88
|
-
return renderStreamTitleSegment(segment, ctx, styles)
|
|
89
|
-
case
|
|
90
|
-
return renderTextTitleSegment(segment, ctx)
|
|
75
|
+
case "stream":
|
|
76
|
+
return renderStreamTitleSegment(segment, ctx, styles);
|
|
77
|
+
case "text":
|
|
78
|
+
return renderTextTitleSegment(segment, ctx);
|
|
91
79
|
default:
|
|
92
|
-
return null
|
|
80
|
+
return null;
|
|
93
81
|
}
|
|
94
|
-
}
|
|
82
|
+
};
|
|
95
83
|
|
|
96
84
|
const renderRichTitle = (
|
|
97
85
|
segments: OperatorTitleSegment[],
|
|
98
86
|
ctx: RendererContext,
|
|
99
87
|
color: Color,
|
|
100
88
|
styles: OperatorStyles,
|
|
101
|
-
fontStyles: Record<string, any
|
|
89
|
+
fontStyles: Record<string, any>,
|
|
102
90
|
) => {
|
|
103
|
-
const $foreignObject = createSvgElement(ctx.document,
|
|
91
|
+
const $foreignObject = createSvgElement(ctx.document, "foreignObject", {
|
|
104
92
|
y: styles.spacing!,
|
|
105
|
-
height: styles.height
|
|
106
|
-
})
|
|
93
|
+
height: styles.height!,
|
|
94
|
+
});
|
|
107
95
|
const $container = createRootDiv(ctx.document, {
|
|
108
|
-
width:
|
|
109
|
-
height:
|
|
110
|
-
display:
|
|
111
|
-
|
|
112
|
-
|
|
96
|
+
width: "100%",
|
|
97
|
+
height: "100%",
|
|
98
|
+
display: "flex",
|
|
99
|
+
"align-items": "center",
|
|
100
|
+
"justify-content": "center",
|
|
113
101
|
color,
|
|
114
|
-
...fontStyles
|
|
115
|
-
})
|
|
116
|
-
$foreignObject.appendChild($container)
|
|
102
|
+
...fontStyles,
|
|
103
|
+
});
|
|
104
|
+
$foreignObject.appendChild($container);
|
|
117
105
|
for (const segment of segments) {
|
|
118
|
-
const $element = renderTitleSegment(segment, ctx, styles)
|
|
119
|
-
$container.appendChild($element)
|
|
106
|
+
const $element = renderTitleSegment(segment, ctx, styles)!;
|
|
107
|
+
$container.appendChild($element);
|
|
120
108
|
}
|
|
121
|
-
return $foreignObject
|
|
122
|
-
}
|
|
109
|
+
return $foreignObject;
|
|
110
|
+
};
|
|
123
111
|
|
|
124
112
|
const renderTextTitle = (
|
|
125
113
|
text: string,
|
|
126
114
|
ctx: RendererContext,
|
|
127
115
|
color: Color,
|
|
128
116
|
styles: OperatorStyles,
|
|
129
|
-
fontStyles: Record<string, any
|
|
117
|
+
fontStyles: Record<string, any>,
|
|
130
118
|
) =>
|
|
131
119
|
createSvgElement(
|
|
132
120
|
ctx.document,
|
|
133
|
-
|
|
121
|
+
"text",
|
|
134
122
|
{
|
|
135
123
|
x: styles.spacing!,
|
|
136
124
|
y: styles.spacing! + styles.height! / 2,
|
|
137
125
|
fill: color,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
...fontStyles
|
|
126
|
+
"dominant-baseline": "middle",
|
|
127
|
+
"text-anchor": "middle",
|
|
128
|
+
...fontStyles,
|
|
141
129
|
},
|
|
142
|
-
text
|
|
143
|
-
)
|
|
130
|
+
text,
|
|
131
|
+
);
|
|
144
132
|
|
|
145
133
|
const renderTitle = (
|
|
146
134
|
segments: OperatorTitleSegment[],
|
|
147
135
|
ctx: RendererContext,
|
|
148
|
-
styles: OperatorStyles
|
|
136
|
+
styles: OperatorStyles,
|
|
149
137
|
) => {
|
|
150
|
-
const color = styles.title_color
|
|
138
|
+
const color = styles.title_color!;
|
|
151
139
|
const fontStyles = {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
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
|
+
};
|
|
157
145
|
|
|
158
|
-
const isText = segments.length === 1 && segments[0].type ===
|
|
146
|
+
const isText = segments.length === 1 && segments[0].type === "text";
|
|
159
147
|
|
|
160
148
|
const $title = isText
|
|
161
149
|
? renderTextTitle(
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
: renderRichTitle(segments, ctx, color, styles, fontStyles)
|
|
150
|
+
(segments[0] as TextOperatorTitleSegment).value,
|
|
151
|
+
ctx,
|
|
152
|
+
color,
|
|
153
|
+
styles,
|
|
154
|
+
fontStyles,
|
|
155
|
+
)
|
|
156
|
+
: renderRichTitle(segments, ctx, color, styles, fontStyles);
|
|
169
157
|
|
|
170
|
-
return { $title, shouldCenter: isText }
|
|
171
|
-
}
|
|
158
|
+
return { $title, shouldCenter: isText };
|
|
159
|
+
};
|
|
172
160
|
|
|
173
161
|
export const renderOperator = (
|
|
174
162
|
ctx: RendererContext,
|
|
175
|
-
operator: OperatorSpecification
|
|
163
|
+
operator: OperatorSpecification,
|
|
176
164
|
): UpdatableRendererResult => {
|
|
177
|
-
const s: OperatorStyles = mergeStyles(
|
|
178
|
-
ctx.styles,
|
|
179
|
-
operator.styles,
|
|
180
|
-
'operator_'
|
|
181
|
-
)
|
|
165
|
+
const s: OperatorStyles = mergeStyles(ctx.styles, operator.styles, "operator_");
|
|
182
166
|
|
|
183
|
-
const $group = createSvgElement(ctx.document,
|
|
167
|
+
const $group = createSvgElement(ctx.document, "g");
|
|
184
168
|
|
|
185
|
-
const $rect = createSvgElement(ctx.document,
|
|
169
|
+
const $rect = createSvgElement(ctx.document, "rect", {
|
|
186
170
|
x: s.stroke_width! / 2,
|
|
187
171
|
y: s.spacing! + s.stroke_width! / 2,
|
|
188
172
|
width: 1,
|
|
189
173
|
height: s.height! - s.stroke_width!,
|
|
190
174
|
fill: s.fill_color!,
|
|
191
175
|
stroke: s.stroke_color!,
|
|
192
|
-
|
|
193
|
-
rx: s.corner_radius
|
|
194
|
-
})
|
|
195
|
-
$group.appendChild($rect)
|
|
176
|
+
"stroke-width": s.stroke_width!,
|
|
177
|
+
rx: s.corner_radius!,
|
|
178
|
+
});
|
|
179
|
+
$group.appendChild($rect);
|
|
196
180
|
|
|
197
|
-
const { $title, shouldCenter } = renderTitle(operator.title, ctx, s)
|
|
198
|
-
$group.appendChild($title)
|
|
181
|
+
const { $title, shouldCenter } = renderTitle(operator.title, ctx, s);
|
|
182
|
+
$group.appendChild($title);
|
|
199
183
|
|
|
200
184
|
const bbox = {
|
|
201
185
|
x1: 0,
|
|
202
186
|
y1: 0,
|
|
203
187
|
x2: 1,
|
|
204
|
-
y2: s.height! + 2 * s.spacing
|
|
205
|
-
}
|
|
188
|
+
y2: s.height! + 2 * s.spacing!,
|
|
189
|
+
};
|
|
206
190
|
|
|
207
191
|
const update = ({ width, dx }: PostRenderUpdateContext) => {
|
|
208
|
-
$rect.setAttribute(
|
|
209
|
-
$title.setAttribute(
|
|
210
|
-
translate($group, -dx, 0)
|
|
192
|
+
$rect.setAttribute("width", String(width - s.stroke_width!));
|
|
193
|
+
$title.setAttribute("width", String(width));
|
|
194
|
+
translate($group, -dx, 0);
|
|
211
195
|
if (shouldCenter) {
|
|
212
|
-
$title.setAttribute(
|
|
196
|
+
$title.setAttribute("x", String(width / 2));
|
|
213
197
|
}
|
|
214
|
-
}
|
|
198
|
+
};
|
|
215
199
|
|
|
216
200
|
return {
|
|
217
201
|
element: $group,
|
|
218
202
|
bbox,
|
|
219
|
-
update
|
|
220
|
-
}
|
|
221
|
-
}
|
|
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);
|
package/src/stream/factory.ts
CHANGED
|
@@ -1,136 +1,120 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ArrowStyles,
|
|
3
|
-
MessageSpecification,
|
|
4
|
-
StreamSpecification
|
|
5
|
-
} from '@swirly/types'
|
|
1
|
+
import { ArrowStyles, MessageSpecification, StreamSpecification } from "@swirly/types";
|
|
6
2
|
|
|
7
|
-
import { renderArrow } from
|
|
8
|
-
import { renderDecoration } from
|
|
3
|
+
import { renderArrow } from "../arrow.js";
|
|
4
|
+
import { renderDecoration } from "../decoration/index.js";
|
|
9
5
|
import {
|
|
10
6
|
MessageRenderer,
|
|
11
7
|
Rectangle,
|
|
12
8
|
RendererContext,
|
|
13
9
|
RendererResult,
|
|
14
|
-
TimeScaler
|
|
15
|
-
} from
|
|
16
|
-
import { degreesToRadians } from
|
|
17
|
-
import { rectangleUnion } from
|
|
18
|
-
import { mergeStyles } from
|
|
19
|
-
import { NotificationKind } from
|
|
20
|
-
import { createSvgElement } from
|
|
21
|
-
import { translate } from
|
|
10
|
+
TimeScaler,
|
|
11
|
+
} from "../types.js";
|
|
12
|
+
import { degreesToRadians } from "../util/degrees-to-radians.js";
|
|
13
|
+
import { rectangleUnion } from "../util/geometry.js";
|
|
14
|
+
import { mergeStyles } from "../util/merge-styles.js";
|
|
15
|
+
import { NotificationKind } from "../util/notification-kind.js";
|
|
16
|
+
import { createSvgElement } from "../util/svg-xml.js";
|
|
17
|
+
import { translate } from "../util/transform.js";
|
|
22
18
|
|
|
23
|
-
const nullScaleTime: TimeScaler = (time) => time
|
|
19
|
+
const nullScaleTime: TimeScaler = (time) => time;
|
|
24
20
|
|
|
25
21
|
const createScaleTime = (higherOrderAngleDegrees: number): TimeScaler => {
|
|
26
|
-
const scale = 1 / Math.cos(degreesToRadians(higherOrderAngleDegrees))
|
|
27
|
-
return (time) => time * scale
|
|
28
|
-
}
|
|
22
|
+
const scale = 1 / Math.cos(degreesToRadians(higherOrderAngleDegrees));
|
|
23
|
+
return (time) => time * scale;
|
|
24
|
+
};
|
|
29
25
|
|
|
30
|
-
const isNotification = ({
|
|
31
|
-
|
|
32
|
-
}: MessageSpecification): boolean => NotificationKind.NEXT.equals(kind)
|
|
26
|
+
const isNotification = ({ notification: { kind } }: MessageSpecification): boolean =>
|
|
27
|
+
NotificationKind.NEXT.equals(kind);
|
|
33
28
|
|
|
34
29
|
const countPriors = (
|
|
35
30
|
message: MessageSpecification,
|
|
36
31
|
index: number,
|
|
37
|
-
messages: readonly MessageSpecification[]
|
|
32
|
+
messages: readonly MessageSpecification[],
|
|
38
33
|
): number => {
|
|
39
|
-
let count = 0
|
|
34
|
+
let count = 0;
|
|
40
35
|
for (let i = 0; i < index; ++i) {
|
|
41
36
|
if (isNotification(messages[i]) && messages[i].frame === message.frame) {
|
|
42
|
-
++count
|
|
37
|
+
++count;
|
|
43
38
|
}
|
|
44
39
|
}
|
|
45
|
-
return count
|
|
46
|
-
}
|
|
40
|
+
return count;
|
|
41
|
+
};
|
|
47
42
|
|
|
48
43
|
export const createRenderStream =
|
|
49
44
|
(renderMessage: MessageRenderer) =>
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
)
|
|
71
|
-
const bboxes: Rectangle[] = []
|
|
72
|
-
|
|
73
|
-
const add = ({ element, bbox }: RendererResult) => {
|
|
74
|
-
$group.appendChild(element)
|
|
75
|
-
bboxes.push(bbox)
|
|
76
|
-
}
|
|
45
|
+
(
|
|
46
|
+
ctx: RendererContext,
|
|
47
|
+
stream: StreamSpecification,
|
|
48
|
+
isHigherOrder: boolean,
|
|
49
|
+
isGhost: boolean,
|
|
50
|
+
): RendererResult => {
|
|
51
|
+
const { document, styles } = ctx;
|
|
52
|
+
|
|
53
|
+
const scaleTime = isHigherOrder ? createScaleTime(styles.higher_order_angle!) : nullScaleTime;
|
|
54
|
+
|
|
55
|
+
const $group = createSvgElement(
|
|
56
|
+
document,
|
|
57
|
+
"g",
|
|
58
|
+
isGhost
|
|
59
|
+
? {
|
|
60
|
+
style: `filter: opacity(${styles.ghost_opacity}%)`,
|
|
61
|
+
}
|
|
62
|
+
: undefined,
|
|
63
|
+
);
|
|
64
|
+
const bboxes: Rectangle[] = [];
|
|
77
65
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
true
|
|
83
|
-
)
|
|
84
|
-
const scaledDuration = scaleTime(stream.duration)
|
|
85
|
-
add(renderArrow(ctx, arrowStyles, styles.arrowhead_angle!, scaledDuration))
|
|
86
|
-
|
|
87
|
-
for (let i = stream.messages.length - 1; i >= 0; --i) {
|
|
88
|
-
const message = stream.messages[i]
|
|
89
|
-
const scaledMessage = {
|
|
90
|
-
...message,
|
|
91
|
-
frame: scaleTime(message.frame)
|
|
92
|
-
}
|
|
66
|
+
const add = ({ element, bbox }: RendererResult) => {
|
|
67
|
+
$group.appendChild(element);
|
|
68
|
+
bboxes.push(bbox);
|
|
69
|
+
};
|
|
93
70
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const dy = priorCount * styles.stacking_height!
|
|
71
|
+
const arrowStyles: ArrowStyles = mergeStyles(styles, stream.styles, "arrow_", true);
|
|
72
|
+
const scaledDuration = scaleTime(stream.duration);
|
|
73
|
+
add(renderArrow(ctx, arrowStyles, styles.arrowhead_angle!, scaledDuration));
|
|
98
74
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
75
|
+
for (let i = stream.messages.length - 1; i >= 0; --i) {
|
|
76
|
+
const message = stream.messages[i];
|
|
77
|
+
const scaledMessage = {
|
|
78
|
+
...message,
|
|
79
|
+
frame: scaleTime(message.frame),
|
|
80
|
+
};
|
|
102
81
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
valueAngle
|
|
106
|
-
}
|
|
82
|
+
const priorCount = isNotification(message) ? countPriors(message, i, stream.messages) : 0;
|
|
83
|
+
const dy = priorCount * styles.stacking_height!;
|
|
107
84
|
|
|
108
|
-
|
|
85
|
+
const valueAngle = isHigherOrder ? styles.higher_order_event_value_angle! : 0;
|
|
109
86
|
|
|
110
|
-
|
|
111
|
-
|
|
87
|
+
const options = {
|
|
88
|
+
verticalOffset: dy,
|
|
89
|
+
valueAngle,
|
|
90
|
+
};
|
|
112
91
|
|
|
113
|
-
|
|
114
|
-
}
|
|
92
|
+
const { element, bbox } = renderMessage(ctx, scaledMessage, options);
|
|
115
93
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
scaleTime,
|
|
119
|
-
bbox: rectangleUnion(bboxes)
|
|
120
|
-
}
|
|
94
|
+
translate(element, 0, dy);
|
|
95
|
+
bbox.y2 += dy;
|
|
121
96
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const { element, bbox } = renderDecoration(innerCtx, decoration)
|
|
125
|
-
$group.appendChild(element)
|
|
126
|
-
if (bbox != null) {
|
|
127
|
-
innerCtx.bbox = rectangleUnion([innerCtx.bbox, bbox])
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
97
|
+
add({ element, bbox });
|
|
98
|
+
}
|
|
131
99
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
100
|
+
const innerCtx = {
|
|
101
|
+
...ctx,
|
|
102
|
+
scaleTime,
|
|
103
|
+
bbox: rectangleUnion(bboxes),
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
if (stream.decorations != null) {
|
|
107
|
+
for (const decoration of stream.decorations) {
|
|
108
|
+
const { element, bbox } = renderDecoration(innerCtx, decoration);
|
|
109
|
+
$group.appendChild(element);
|
|
110
|
+
if (bbox != null) {
|
|
111
|
+
innerCtx.bbox = rectangleUnion([innerCtx.bbox, bbox]);
|
|
112
|
+
}
|
|
135
113
|
}
|
|
136
114
|
}
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
element: $group,
|
|
118
|
+
bbox: innerCtx.bbox,
|
|
119
|
+
};
|
|
120
|
+
};
|