@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.
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 +29 -26
  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 +2 -4
  17. package/dist/index.js +28 -20
  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 +70 -52
  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 +14 -17
  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 +43 -40
  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 +61 -63
  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 +121 -113
  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 -43
  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
package/src/arrow.ts CHANGED
@@ -1,62 +1,65 @@
1
- import { RendererContext, RendererResult } from './types.js'
2
- import { degreesToRadians } from './util/degrees-to-radians.js'
3
- import { createSvgElement } from './util/svg-xml.js'
1
+ import { RendererContext, RendererResult } from "./types.js";
2
+ import { degreesToRadians } from "./util/degrees-to-radians.js";
3
+ import { createSvgElement } from "./util/svg-xml.js";
4
4
 
5
5
  export const renderArrow = (
6
6
  { document, styles, streamHeight }: RendererContext,
7
7
  arrowStyles: any,
8
8
  arrowheadAngle: number,
9
- duration: number
9
+ duration: number,
10
10
  ): RendererResult => {
11
- const y = streamHeight / 2
12
- const width = duration * styles.frame_width! + streamHeight
13
- const arrowheadWidth = arrowStyles.width!
14
- const arrowheadHeight =
15
- arrowheadWidth * Math.tan(degreesToRadians(arrowheadAngle / 2))
16
- const y1 = y - arrowheadHeight
17
- const y2 = y + arrowheadHeight
11
+ const centerY = streamHeight / 2;
12
+ const lineWidth = duration * styles.frame_width! + streamHeight;
13
+ const arrowheadWidth = arrowStyles.width!;
14
+ const arrowheadHeight = arrowheadWidth * Math.tan(degreesToRadians(arrowheadAngle / 2));
15
+ const arrowHeadProtrusion =
16
+ arrowStyles.stroke_width! / Math.sin(degreesToRadians(arrowheadAngle));
18
17
 
19
- const fillColor = arrowStyles.fill_color!
20
- const filled = typeof fillColor === 'string' && fillColor !== ''
18
+ const strokeWidth = arrowStyles.stroke_width!;
19
+ const strokeColor = arrowStyles.stroke_color!;
20
+ const fillColor = arrowStyles.fill_color!;
21
+ const filled = typeof fillColor === "string" && fillColor !== "";
21
22
 
22
- const $group = createSvgElement(document, 'g')
23
+ const $group = createSvgElement(document, "g");
23
24
 
24
25
  $group.appendChild(
25
- createSvgElement(document, 'line', {
26
+ createSvgElement(document, "line", {
26
27
  x1: 0,
27
- y1: y,
28
- x2: width - (filled ? arrowheadWidth : 0),
29
- y2: y,
30
- stroke: arrowStyles.stroke_color!,
31
- 'stroke-width': arrowStyles.stroke_width!
32
- })
33
- )
28
+ y1: centerY,
29
+ x2: lineWidth - (filled ? arrowheadWidth : 0),
30
+ y2: centerY,
31
+ stroke: strokeColor,
32
+ "stroke-width": strokeWidth,
33
+ }),
34
+ );
34
35
 
36
+ const arrowheadTopY = centerY - arrowheadHeight;
37
+ const arrowheadBottomY = centerY + arrowheadHeight;
35
38
  const points = [
36
- `${width - arrowheadWidth},${y1}`,
37
- `${width},${y}`,
38
- `${width - arrowheadWidth},${y2}`
39
- ]
39
+ `${lineWidth - arrowheadWidth},${arrowheadTopY}`,
40
+ `${lineWidth},${centerY}`,
41
+ `${lineWidth - arrowheadWidth},${arrowheadBottomY}`,
42
+ ];
40
43
 
41
44
  $group.appendChild(
42
- createSvgElement(document, filled ? 'polygon' : 'polyline', {
43
- points: points.join(' '),
44
- fill: filled ? fillColor : 'none',
45
- stroke: arrowStyles.stroke_color!,
46
- 'stroke-width': arrowStyles.stroke_width!,
47
- 'stroke-linecap': 'square'
48
- })
49
- )
45
+ createSvgElement(document, filled ? "polygon" : "polyline", {
46
+ points: points.join(" "),
47
+ fill: filled ? fillColor : "none",
48
+ stroke: strokeColor,
49
+ "stroke-width": strokeWidth,
50
+ "stroke-linecap": "square",
51
+ }),
52
+ );
50
53
 
51
54
  const bbox = {
52
55
  x1: 0,
53
56
  y1: 0,
54
- x2: width,
55
- y2: streamHeight
56
- }
57
+ x2: lineWidth + arrowHeadProtrusion,
58
+ y2: streamHeight,
59
+ };
57
60
 
58
61
  return {
59
62
  element: $group,
60
- bbox
61
- }
62
- }
63
+ bbox,
64
+ };
65
+ };
@@ -1,43 +1,39 @@
1
1
  import {
2
2
  BarrierDecorationSpecification,
3
3
  BarrierDecorationStyles,
4
- DecorationSpecification
5
- } from '@swirly/types'
4
+ DecorationSpecification,
5
+ } from "@swirly/types";
6
6
 
7
- import {
8
- DecorationRendererContext,
9
- DecorationRendererResult
10
- } from '../types.js'
11
- import { mergeStyles } from '../util/merge-styles.js'
12
- import { createSvgElement } from '../util/svg-xml.js'
13
- import { translate } from '../util/transform.js'
7
+ import { DecorationRendererContext, DecorationRendererResult } from "../types.js";
8
+ import { mergeStyles } from "../util/merge-styles.js";
9
+ import { createSvgElement } from "../util/svg-xml.js";
10
+ import { translate } from "../util/transform.js";
14
11
 
15
12
  export const renderBarrierDecoration = (
16
13
  { document, styles, bbox, scaleTime }: DecorationRendererContext,
17
- decoration: DecorationSpecification
14
+ decoration: DecorationSpecification,
18
15
  ): DecorationRendererResult => {
19
- const { frame, styles: ownStyles } =
20
- decoration as BarrierDecorationSpecification
16
+ const { frame, styles: ownStyles } = decoration as BarrierDecorationSpecification;
21
17
 
22
- const s: BarrierDecorationStyles = mergeStyles(styles, ownStyles, 'barrier_')
18
+ const s: BarrierDecorationStyles = mergeStyles(styles, ownStyles, "barrier_");
23
19
 
24
- const x = scaleTime(frame) * styles.frame_width! - s.stroke_width! / 2
25
- const y = bbox.y1
26
- const height = bbox.y2 - bbox.y1
20
+ const x = scaleTime(frame) * styles.frame_width! - s.stroke_width! / 2;
21
+ const y = bbox.y1;
22
+ const height = bbox.y2 - bbox.y1;
27
23
 
28
- const $line = createSvgElement(document, 'line', {
24
+ const $line = createSvgElement(document, "line", {
29
25
  x1: 0,
30
26
  y1: 0,
31
27
  x2: 0,
32
28
  y2: height,
33
29
  stroke: s.color!,
34
- 'stroke-width': s.stroke_width!,
35
- 'stroke-dasharray': s.stroke_dash_width!
36
- })
30
+ "stroke-width": s.stroke_width!,
31
+ "stroke-dasharray": s.stroke_dash_width!,
32
+ });
37
33
 
38
- translate($line, x, y)
34
+ translate($line, x, y);
39
35
 
40
36
  return {
41
- element: $line
42
- }
43
- }
37
+ element: $line,
38
+ };
39
+ };
@@ -1,22 +1,22 @@
1
- import { DecorationSpecification } from '@swirly/types'
1
+ import { DecorationSpecification } from "@swirly/types";
2
2
 
3
3
  import {
4
4
  DecorationRenderer,
5
5
  DecorationRendererContext,
6
- DecorationRendererResult
7
- } from '../types.js'
8
- import { renderBarrierDecoration } from './barrier.js'
9
- import { renderRangeDecoration } from './range.js'
6
+ DecorationRendererResult,
7
+ } from "../types.js";
8
+ import { renderBarrierDecoration } from "./barrier.js";
9
+ import { renderRangeDecoration } from "./range.js";
10
10
 
11
11
  const strategies: Record<string, DecorationRenderer> = {
12
12
  barrier: renderBarrierDecoration,
13
- range: renderRangeDecoration
14
- }
13
+ range: renderRangeDecoration,
14
+ };
15
15
 
16
16
  export const renderDecoration = (
17
17
  ctx: DecorationRendererContext,
18
- decoration: DecorationSpecification
18
+ decoration: DecorationSpecification,
19
19
  ): DecorationRendererResult => {
20
- const render: DecorationRenderer = strategies[decoration.kind]
21
- return render(ctx, decoration)
22
- }
20
+ const render: DecorationRenderer = strategies[decoration.kind];
21
+ return render(ctx, decoration);
22
+ };
@@ -1,47 +1,40 @@
1
1
  import {
2
2
  DecorationSpecification,
3
3
  RangeDecorationSpecification,
4
- RangeDecorationStyles
5
- } from '@swirly/types'
4
+ RangeDecorationStyles,
5
+ } from "@swirly/types";
6
6
 
7
- import {
8
- DecorationRendererContext,
9
- DecorationRendererResult
10
- } from '../types.js'
11
- import { mergeStyles } from '../util/merge-styles.js'
12
- import { createSvgElement } from '../util/svg-xml.js'
13
- import { translate } from '../util/transform.js'
7
+ import { DecorationRendererContext, DecorationRendererResult } from "../types.js";
8
+ import { mergeStyles } from "../util/merge-styles.js";
9
+ import { createSvgElement } from "../util/svg-xml.js";
10
+ import { translate } from "../util/transform.js";
14
11
 
15
12
  export const renderRangeDecoration = (
16
13
  { document, styles, streamHeight, scaleTime }: DecorationRendererContext,
17
- decoration: DecorationSpecification
14
+ decoration: DecorationSpecification,
18
15
  ): DecorationRendererResult => {
19
- const {
20
- frame,
21
- duration,
22
- styles: ownStyles
23
- } = decoration as RangeDecorationSpecification
16
+ const { frame, duration, styles: ownStyles } = decoration as RangeDecorationSpecification;
24
17
 
25
- const s: RangeDecorationStyles = mergeStyles(styles, ownStyles, 'range_')
18
+ const s: RangeDecorationStyles = mergeStyles(styles, ownStyles, "range_");
26
19
 
27
- const x = scaleTime(frame) * styles.frame_width!
28
- const y = (streamHeight - s.height!) / 2
29
- const width = scaleTime(duration) * styles.frame_width!
30
- const height = s.height!
20
+ const x = scaleTime(frame) * styles.frame_width!;
21
+ const y = (streamHeight - s.height!) / 2;
22
+ const width = scaleTime(duration) * styles.frame_width!;
23
+ const height = s.height!;
31
24
 
32
- const $rect = createSvgElement(document, 'rect', {
25
+ const $rect = createSvgElement(document, "rect", {
33
26
  x: 0,
34
27
  y: 0,
35
28
  width,
36
29
  height,
37
30
  fill: s.fill_color!,
38
31
  stroke: s.stroke_color!,
39
- 'stroke-width': s.stroke_width!
40
- })
32
+ "stroke-width": s.stroke_width!,
33
+ });
41
34
 
42
- translate($rect, x, y)
35
+ translate($rect, x, y);
43
36
 
44
37
  return {
45
- element: $rect
46
- }
47
- }
38
+ element: $rect,
39
+ };
40
+ };
package/src/index.ts CHANGED
@@ -1,118 +1,116 @@
1
- import { lightStyles } from '@swirly/theme-default-light'
1
+ import { lightStyles } from "@swirly/theme-default-light";
2
2
  import {
3
3
  DiagramRendering,
4
4
  DiagramSpecification,
5
5
  OperatorSpecification,
6
- StreamSpecification
7
- } from '@swirly/types'
8
-
9
- import { renderOperator } from './operator.js'
10
- import { renderStream } from './stream/full.js'
11
- import {
12
- RendererContext,
13
6
  RendererOptions,
14
- RendererResult,
15
- UpdatableRendererResult
16
- } from './types.js'
17
- import {
18
- createSvgDocument,
19
- createSvgElement,
20
- setSvgDimensions
21
- } from './util/svg-xml.js'
22
- import { translate } from './util/transform.js'
7
+ StreamSpecification,
8
+ } from "@swirly/types";
23
9
 
24
- const isOperator = (item: StreamSpecification | OperatorSpecification) =>
25
- item.kind === 'O'
10
+ import { renderOperator } from "./operator.js";
11
+ import { renderStream } from "./stream/full.js";
12
+ import { RendererContext, RendererResult, UpdatableRendererResult } from "./types.js";
13
+ import { createSvgDocument, createSvgElement, setSvgDimensions } from "./util/svg-xml.js";
14
+ import { translate } from "./util/transform.js";
26
15
 
27
- const isStream = (item: StreamSpecification | OperatorSpecification) =>
28
- !isOperator(item)
16
+ const isOperator = (item: StreamSpecification | OperatorSpecification) => item.kind === "O";
29
17
 
30
- const renderMarbleDiagram = (
18
+ const isStream = (item: StreamSpecification | OperatorSpecification) => !isOperator(item);
19
+
20
+ export const renderMarbleDiagram = (
31
21
  spec: DiagramSpecification,
32
- options: RendererOptions = {}
22
+ options: RendererOptions = {},
33
23
  ): DiagramRendering => {
34
24
  const styles = {
35
25
  ...lightStyles,
36
26
  ...options.styles,
37
- ...spec.styles
38
- }
27
+ ...spec.styles,
28
+ };
39
29
 
40
- const document = createSvgDocument(options.DOMParser)
41
- const $svg = document.documentElement
30
+ const document = createSvgDocument(options.DOMParser);
31
+ const $svg = document.documentElement;
42
32
 
43
- const $group = createSvgElement(document, 'g')
44
- translate($group, styles.canvas_padding!, styles.canvas_padding!)
45
- $svg.appendChild($group)
33
+ const $group = createSvgElement(document, "g");
34
+ translate($group, styles.canvas_padding!, styles.canvas_padding!);
35
+ $svg.appendChild($group);
46
36
 
47
37
  const streamHeight = Math.max(
48
38
  styles.event_radius! * 2,
49
39
  styles.completion_height!,
50
- styles.error_size!
51
- )
40
+ styles.error_size!,
41
+ );
52
42
 
53
43
  const streamTitleEnabled = spec.content.some(
54
- (item) => isStream(item) && item.title != null && item.title !== ''
55
- )
44
+ (item) => isStream(item) && item.title != null && item.title !== "",
45
+ );
56
46
 
57
47
  const ctx: RendererContext = {
58
48
  DOMParser: options.DOMParser,
59
49
  document,
60
50
  styles,
61
51
  streamHeight,
62
- streamTitleEnabled
63
- }
52
+ streamTitleEnabled,
53
+ };
64
54
 
65
- const updaters = []
55
+ const updaters = [];
66
56
 
67
- let maxX = 0
68
- let y = 0
57
+ let minX = 0;
58
+ let maxX = 0;
59
+ let y = 0;
69
60
  for (const item of spec.content) {
70
61
  const rendererResult: RendererResult = isOperator(item)
71
62
  ? renderOperator(ctx, item as OperatorSpecification)
72
- : renderStream(ctx, item as StreamSpecification)
73
- const { element, bbox, update } = rendererResult as UpdatableRendererResult
63
+ : renderStream(ctx, item as StreamSpecification);
64
+ const { element, bbox, update } = rendererResult as UpdatableRendererResult;
74
65
 
75
- translate(element, 0, y - bbox.y1)
76
- $group.appendChild(element)
66
+ translate(element, 0, y - bbox.y1);
67
+ $group.appendChild(element);
77
68
 
78
- maxX = Math.max(maxX, bbox.x2)
69
+ minX = Math.min(minX, bbox.x1);
70
+ maxX = Math.max(maxX, bbox.x2);
79
71
 
80
- const height = bbox.y2 - bbox.y1
81
- y += height + styles.stream_spacing!
72
+ const height = bbox.y2 - bbox.y1;
73
+ y += height + styles.stream_spacing!;
82
74
 
83
75
  if (update != null) {
84
- updaters.push(update)
76
+ updaters.push(update);
85
77
  }
86
78
  }
87
79
 
88
- y -= styles.stream_spacing!
80
+ const dx = minX < 0 ? -minX : 0;
81
+ translate($group, dx, 0);
82
+
83
+ const innerWidth = Math.max(maxX - minX, styles.minimum_width!);
84
+ const innerHeight = Math.max(y - styles.stream_spacing!, styles.minimum_height!);
89
85
 
90
- const width = styles.canvas_padding! + maxX + styles.canvas_padding!
91
- const height = styles.canvas_padding! + y + styles.canvas_padding!
86
+ const width = styles.canvas_padding! + innerWidth + styles.canvas_padding!;
87
+ const height = styles.canvas_padding! + innerHeight + styles.canvas_padding!;
92
88
 
93
- setSvgDimensions($svg, width, height)
89
+ setSvgDimensions($svg, width, height);
94
90
 
95
- const bgColor = styles.background_color!
96
- if (bgColor !== '' && bgColor !== 'transparent') {
97
- const $bg = createSvgElement(document, 'rect', {
91
+ const bgColor = styles.background_color!;
92
+ if (bgColor !== "" && bgColor !== "transparent") {
93
+ const $bg = createSvgElement(document, "rect", {
98
94
  x: 0,
99
95
  y: 0,
100
96
  width,
101
97
  height,
102
- fill: bgColor
103
- })
104
- $svg.insertBefore($bg, $svg.firstChild)
98
+ fill: bgColor,
99
+ });
100
+ $svg.insertBefore($bg, $svg.firstChild);
105
101
  }
106
102
 
107
103
  for (const update of updaters) {
108
- update({ width: maxX, height: y })
104
+ update({
105
+ width: innerWidth,
106
+ height: innerHeight,
107
+ dx,
108
+ });
109
109
  }
110
110
 
111
111
  return {
112
112
  document,
113
113
  width,
114
- height
115
- }
116
- }
117
-
118
- export { RendererOptions, renderMarbleDiagram }
114
+ height,
115
+ };
116
+ };
@@ -1,53 +1,49 @@
1
- import { CompletionMessageStyles, MessageSpecification } from '@swirly/types'
1
+ import { CompletionMessageStyles, MessageSpecification } from "@swirly/types";
2
2
 
3
- import { RendererContext, RendererResult } from '../types.js'
4
- import { mergeStyles } from '../util/merge-styles.js'
5
- import { NotificationKind } from '../util/notification-kind.js'
6
- import { createSvgElement } from '../util/svg-xml.js'
7
- import { translate } from '../util/transform.js'
3
+ import { RendererContext, RendererResult } from "../types.js";
4
+ import { mergeStyles } from "../util/merge-styles.js";
5
+ import { NotificationKind } from "../util/notification-kind.js";
6
+ import { createSvgElement } from "../util/svg-xml.js";
7
+ import { translate } from "../util/transform.js";
8
8
 
9
9
  const supports = ({ notification: { kind } }: MessageSpecification) =>
10
- NotificationKind.COMPLETE.equals(kind)
10
+ NotificationKind.COMPLETE.equals(kind);
11
11
 
12
12
  const render = (
13
13
  { document, styles, streamHeight }: RendererContext,
14
- message: MessageSpecification
14
+ message: MessageSpecification,
15
15
  ): RendererResult => {
16
- const s: CompletionMessageStyles = mergeStyles(
17
- styles,
18
- message.styles,
19
- 'completion_'
20
- )
16
+ const s: CompletionMessageStyles = mergeStyles(styles, message.styles, "completion_");
21
17
 
22
- const x = message.frame * styles.frame_width! - s.stroke_width! / 2
23
- const y1 = (streamHeight - s.height!) / 2
24
- const y2 = y1 + s.height!
18
+ const x = message.frame * styles.frame_width! - s.stroke_width! / 2;
19
+ const y1 = (streamHeight - s.height!) / 2;
20
+ const y2 = y1 + s.height!;
25
21
 
26
- const $group = createSvgElement(document, 'g')
27
- translate($group, x, 0)
22
+ const $group = createSvgElement(document, "g");
23
+ translate($group, x, 0);
28
24
 
29
25
  $group.appendChild(
30
- createSvgElement(document, 'line', {
26
+ createSvgElement(document, "line", {
31
27
  x1: 0,
32
28
  y1,
33
29
  x2: 0,
34
30
  y2,
35
31
  stroke: s.stroke_color!,
36
- 'stroke-width': s.stroke_width!
37
- })
38
- )
32
+ "stroke-width": s.stroke_width!,
33
+ }),
34
+ );
39
35
 
40
36
  const bbox = {
41
37
  x1: x - s.stroke_width! / 2,
42
38
  y1,
43
39
  x2: x + s.stroke_width! / 2,
44
- y2
45
- }
40
+ y2,
41
+ };
46
42
 
47
43
  return {
48
44
  element: $group,
49
- bbox
50
- }
51
- }
45
+ bbox,
46
+ };
47
+ };
52
48
 
53
- export const completeMessageRenderer = { supports, render }
49
+ export const completeMessageRenderer = { supports, render };
@@ -1,59 +1,59 @@
1
- import { ErrorMessageStyles, MessageSpecification } from '@swirly/types'
1
+ import { ErrorMessageStyles, MessageSpecification } from "@swirly/types";
2
2
 
3
- import { RendererContext, RendererResult } from '../types.js'
4
- import { mergeStyles } from '../util/merge-styles.js'
5
- import { NotificationKind } from '../util/notification-kind.js'
6
- import { createSvgElement } from '../util/svg-xml.js'
7
- import { translate } from '../util/transform.js'
3
+ import { RendererContext, RendererResult } from "../types.js";
4
+ import { mergeStyles } from "../util/merge-styles.js";
5
+ import { NotificationKind } from "../util/notification-kind.js";
6
+ import { createSvgElement } from "../util/svg-xml.js";
7
+ import { translate } from "../util/transform.js";
8
8
 
9
9
  const supports = ({ notification: { kind } }: MessageSpecification) =>
10
- NotificationKind.ERROR.equals(kind)
10
+ NotificationKind.ERROR.equals(kind);
11
11
 
12
12
  const render = (
13
13
  { document, styles, streamHeight }: RendererContext,
14
- message: MessageSpecification
14
+ message: MessageSpecification,
15
15
  ): RendererResult => {
16
- const s: ErrorMessageStyles = mergeStyles(styles, message.styles, 'error_')
16
+ const s: ErrorMessageStyles = mergeStyles(styles, message.styles, "error_");
17
17
 
18
- const x = message.frame * styles.frame_width! - s.size! / 2
19
- const y = (streamHeight - s.size!) / 2
18
+ const x = message.frame * styles.frame_width! - s.size! / 2;
19
+ const y = (streamHeight - s.size!) / 2;
20
20
 
21
- const $group = createSvgElement(document, 'g')
22
- translate($group, x, y)
21
+ const $group = createSvgElement(document, "g");
22
+ translate($group, x, y);
23
23
 
24
24
  $group.appendChild(
25
- createSvgElement(document, 'line', {
25
+ createSvgElement(document, "line", {
26
26
  x1: 0,
27
27
  y1: 0,
28
28
  x2: s.size!,
29
29
  y2: s.size!,
30
30
  stroke: s.color!,
31
- 'stroke-width': s.stroke_width!
32
- })
33
- )
31
+ "stroke-width": s.stroke_width!,
32
+ }),
33
+ );
34
34
 
35
35
  $group.appendChild(
36
- createSvgElement(document, 'line', {
36
+ createSvgElement(document, "line", {
37
37
  x1: s.size!,
38
38
  y1: 0,
39
39
  x2: 0,
40
40
  y2: s.size!,
41
41
  stroke: s.color!,
42
- 'stroke-width': s.stroke_width!
43
- })
44
- )
42
+ "stroke-width": s.stroke_width!,
43
+ }),
44
+ );
45
45
 
46
46
  const bbox = {
47
47
  x1: x,
48
48
  y1: y,
49
49
  x2: x + s.size!,
50
- y2: y + s.size!
51
- }
50
+ y2: y + s.size!,
51
+ };
52
52
 
53
53
  return {
54
54
  element: $group,
55
- bbox
56
- }
57
- }
55
+ bbox,
56
+ };
57
+ };
58
58
 
59
- export const errorMessageRenderer = { supports, render }
59
+ export const errorMessageRenderer = { supports, render };
@@ -1,20 +1,16 @@
1
- import { MessageSpecification } from '@swirly/types'
1
+ import { MessageSpecification } from "@swirly/types";
2
2
 
3
- import {
4
- MessageRendererOptions,
5
- RendererContext,
6
- RendererResult
7
- } from '../types.js'
8
- import { nonStreamMessageRenderer } from './non-stream.js'
9
- import { streamMessageRenderer } from './stream.js'
3
+ import { MessageRendererOptions, RendererContext, RendererResult } from "../types.js";
4
+ import { nonStreamMessageRenderer } from "./non-stream.js";
5
+ import { streamMessageRenderer } from "./stream.js";
10
6
 
11
7
  export const renderMessage = (
12
8
  ctx: RendererContext,
13
9
  message: MessageSpecification,
14
- options: MessageRendererOptions
10
+ options: MessageRendererOptions,
15
11
  ): RendererResult => {
16
12
  const renderer = streamMessageRenderer.supports(message)
17
13
  ? streamMessageRenderer
18
- : nonStreamMessageRenderer
19
- return renderer.render(ctx, message, options)
20
- }
14
+ : nonStreamMessageRenderer;
15
+ return renderer.render(ctx, message, options);
16
+ };