@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.
Files changed (92) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +4 -1
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/arrow.d.ts +1 -1
  5. package/dist/arrow.js +14 -14
  6. package/dist/arrow.js.map +1 -1
  7. package/dist/decoration/barrier.d.ts +2 -2
  8. package/dist/decoration/barrier.js +8 -8
  9. package/dist/decoration/barrier.js.map +1 -1
  10. package/dist/decoration/index.d.ts +2 -2
  11. package/dist/decoration/index.js +3 -3
  12. package/dist/decoration/index.js.map +1 -1
  13. package/dist/decoration/range.d.ts +2 -2
  14. package/dist/decoration/range.js +7 -7
  15. package/dist/decoration/range.js.map +1 -1
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.js +15 -15
  18. package/dist/index.js.map +1 -1
  19. package/dist/message/complete.d.ts +2 -2
  20. package/dist/message/complete.js +10 -10
  21. package/dist/message/complete.js.map +1 -1
  22. package/dist/message/error.d.ts +2 -2
  23. package/dist/message/error.js +12 -12
  24. package/dist/message/error.js.map +1 -1
  25. package/dist/message/index.d.ts +2 -2
  26. package/dist/message/index.js +2 -2
  27. package/dist/message/index.js.map +1 -1
  28. package/dist/message/non-stream.d.ts +2 -2
  29. package/dist/message/non-stream.js +5 -9
  30. package/dist/message/non-stream.js.map +1 -1
  31. package/dist/message/scalar.d.ts +2 -2
  32. package/dist/message/scalar.js +21 -21
  33. package/dist/message/scalar.js.map +1 -1
  34. package/dist/message/stream.d.ts +2 -2
  35. package/dist/message/stream.js +7 -7
  36. package/dist/message/stream.js.map +1 -1
  37. package/dist/operator.d.ts +2 -2
  38. package/dist/operator.js +40 -40
  39. package/dist/operator.js.map +1 -1
  40. package/dist/stream/core.d.ts +1 -1
  41. package/dist/stream/core.js +2 -2
  42. package/dist/stream/core.js.map +1 -1
  43. package/dist/stream/factory.d.ts +2 -2
  44. package/dist/stream/factory.js +18 -24
  45. package/dist/stream/factory.js.map +1 -1
  46. package/dist/stream/full.d.ts +2 -2
  47. package/dist/stream/full.js +14 -14
  48. package/dist/stream/full.js.map +1 -1
  49. package/dist/types.d.ts +13 -13
  50. package/dist/util/degrees-to-radians.js.map +1 -1
  51. package/dist/util/geometry.d.ts +1 -1
  52. package/dist/util/geometry.js +6 -6
  53. package/dist/util/geometry.js.map +1 -1
  54. package/dist/util/hex-to-dec.js +2 -2
  55. package/dist/util/hex-to-dec.js.map +1 -1
  56. package/dist/util/merge-styles.d.ts +1 -1
  57. package/dist/util/merge-styles.js.map +1 -1
  58. package/dist/util/notification-kind.js +4 -4
  59. package/dist/util/notification-kind.js.map +1 -1
  60. package/dist/util/string-to-color.d.ts +1 -1
  61. package/dist/util/string-to-color.js +3 -3
  62. package/dist/util/string-to-color.js.map +1 -1
  63. package/dist/util/svg-xml.d.ts +1 -1
  64. package/dist/util/svg-xml.js +8 -8
  65. package/dist/util/svg-xml.js.map +1 -1
  66. package/dist/util/transform.js +3 -3
  67. package/dist/util/transform.js.map +1 -1
  68. package/package.json +20 -20
  69. package/src/arrow.ts +34 -35
  70. package/src/decoration/barrier.ts +20 -24
  71. package/src/decoration/index.ts +11 -11
  72. package/src/decoration/range.ts +20 -27
  73. package/src/index.ts +55 -68
  74. package/src/message/complete.ts +24 -28
  75. package/src/message/error.ts +27 -27
  76. package/src/message/index.ts +8 -12
  77. package/src/message/non-stream.ts +12 -20
  78. package/src/message/scalar.ts +44 -52
  79. package/src/message/stream.ts +27 -40
  80. package/src/operator.ts +104 -120
  81. package/src/stream/core.ts +3 -3
  82. package/src/stream/factory.ts +86 -102
  83. package/src/stream/full.ts +34 -37
  84. package/src/types.ts +39 -39
  85. package/src/util/degrees-to-radians.ts +1 -2
  86. package/src/util/geometry.ts +29 -42
  87. package/src/util/hex-to-dec.ts +8 -8
  88. package/src/util/merge-styles.ts +9 -11
  89. package/src/util/notification-kind.ts +8 -8
  90. package/src/util/string-to-color.ts +10 -10
  91. package/src/util/svg-xml.ts +20 -23
  92. package/src/util/transform.ts +11 -17
@@ -1,55 +1,42 @@
1
- import {
2
- MessageSpecification,
3
- StreamNextNotificationSpecification
4
- } from '@swirly/types'
5
-
6
- import { createRenderStream } from '../stream/factory.js'
7
- import {
8
- MessageRendererOptions,
9
- RendererContext,
10
- RendererResult
11
- } from '../types.js'
12
- import { degreesToRadians } from '../util/degrees-to-radians.js'
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
- bbox,
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 '@swirly/types'
8
+ TextOperatorTitleSegment,
9
+ } from "@swirly/types";
10
10
 
11
- import { renderStreamBase } from './stream/core.js'
12
- import {
13
- PostRenderUpdateContext,
14
- RendererContext,
15
- UpdatableRendererResult
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 = '\xA0'
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, 'div')
22
+ const $div = document.createElementNS(XHTML_NS, "div");
32
23
  $div.setAttribute(
33
- 'style',
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 $div = ctx.document.createElement('div')
77
- $div.textContent = segment.value.replace(reSpace, NON_BREAKING_SPACE)
78
- return $div
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 'stream':
88
- return renderStreamTitleSegment(segment, ctx, styles)
89
- case 'text':
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, 'foreignObject', {
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: '100%',
109
- height: '100%',
110
- display: 'flex',
111
- 'align-items': 'center',
112
- 'justify-content': 'center',
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
- 'text',
121
+ "text",
134
122
  {
135
123
  x: styles.spacing!,
136
124
  y: styles.spacing! + styles.height! / 2,
137
125
  fill: color,
138
- 'dominant-baseline': 'middle',
139
- 'text-anchor': 'middle',
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
- 'font-family': styles.title_font_family!,
153
- 'font-size': styles.title_font_size! + 'px',
154
- 'font-weight': styles.title_font_weight!,
155
- 'font-style': styles.title_font_style!
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 === 'text'
146
+ const isText = segments.length === 1 && segments[0].type === "text";
159
147
 
160
148
  const $title = isText
161
149
  ? renderTextTitle(
162
- (segments[0] as TextOperatorTitleSegment).value,
163
- ctx,
164
- color,
165
- styles,
166
- fontStyles
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, 'g')
167
+ const $group = createSvgElement(ctx.document, "g");
184
168
 
185
- const $rect = createSvgElement(ctx.document, 'rect', {
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
- 'stroke-width': s.stroke_width!,
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('width', String(width - s.stroke_width!))
209
- $title.setAttribute('width', String(width))
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('x', String(width / 2))
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
+ };
@@ -1,4 +1,4 @@
1
- import { renderMessage } from '../message/index.js'
2
- import { createRenderStream } from './factory.js'
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);
@@ -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 '../arrow.js'
8
- import { renderDecoration } from '../decoration/index.js'
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 '../types.js'
16
- import { degreesToRadians } from '../util/degrees-to-radians.js'
17
- import { rectangleUnion } from '../util/geometry.js'
18
- import { mergeStyles } from '../util/merge-styles.js'
19
- import { NotificationKind } from '../util/notification-kind.js'
20
- import { createSvgElement } from '../util/svg-xml.js'
21
- import { translate } from '../util/transform.js'
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
- notification: { kind }
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
- ctx: RendererContext,
52
- stream: StreamSpecification,
53
- isHigherOrder: boolean,
54
- isGhost: boolean
55
- ): RendererResult => {
56
- const { document, styles } = ctx
57
-
58
- const scaleTime = isHigherOrder
59
- ? createScaleTime(styles.higher_order_angle!)
60
- : nullScaleTime
61
-
62
- const $group = createSvgElement(
63
- document,
64
- 'g',
65
- isGhost
66
- ? {
67
- style: `filter: opacity(${styles.ghost_opacity}%)`
68
- }
69
- : undefined
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
- const arrowStyles: ArrowStyles = mergeStyles(
79
- styles,
80
- stream.styles,
81
- 'arrow_',
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
- const priorCount = isNotification(message)
95
- ? countPriors(message, i, stream.messages)
96
- : 0
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
- const valueAngle = isHigherOrder
100
- ? styles.higher_order_event_value_angle!
101
- : 0
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
- const options = {
104
- verticalOffset: dy,
105
- valueAngle
106
- }
82
+ const priorCount = isNotification(message) ? countPriors(message, i, stream.messages) : 0;
83
+ const dy = priorCount * styles.stacking_height!;
107
84
 
108
- const { element, bbox } = renderMessage(ctx, scaledMessage, options)
85
+ const valueAngle = isHigherOrder ? styles.higher_order_event_value_angle! : 0;
109
86
 
110
- translate(element, 0, dy)
111
- bbox.y2 += dy
87
+ const options = {
88
+ verticalOffset: dy,
89
+ valueAngle,
90
+ };
112
91
 
113
- add({ element, bbox })
114
- }
92
+ const { element, bbox } = renderMessage(ctx, scaledMessage, options);
115
93
 
116
- const innerCtx = {
117
- ...ctx,
118
- scaleTime,
119
- bbox: rectangleUnion(bboxes)
120
- }
94
+ translate(element, 0, dy);
95
+ bbox.y2 += dy;
121
96
 
122
- if (stream.decorations != null) {
123
- for (const decoration of stream.decorations) {
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
- return {
133
- element: $group,
134
- bbox: innerCtx.bbox
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
+ };