@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,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,129 +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
6
  RendererOptions,
7
- StreamSpecification
8
- } from '@swirly/types'
7
+ StreamSpecification,
8
+ } from "@swirly/types";
9
9
 
10
- import { renderOperator } from './operator.js'
11
- import { renderStream } from './stream/full.js'
12
- import {
13
- RendererContext,
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'
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";
23
15
 
24
- const isOperator = (item: StreamSpecification | OperatorSpecification) =>
25
- item.kind === 'O'
16
+ const isOperator = (item: StreamSpecification | OperatorSpecification) => item.kind === "O";
26
17
 
27
- const isStream = (item: StreamSpecification | OperatorSpecification) =>
28
- !isOperator(item)
18
+ const isStream = (item: StreamSpecification | OperatorSpecification) => !isOperator(item);
29
19
 
30
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 minX = 0
68
- let maxX = 0
69
- let y = 0
57
+ let minX = 0;
58
+ let maxX = 0;
59
+ let y = 0;
70
60
  for (const item of spec.content) {
71
61
  const rendererResult: RendererResult = isOperator(item)
72
62
  ? renderOperator(ctx, item as OperatorSpecification)
73
- : renderStream(ctx, item as StreamSpecification)
74
- const { element, bbox, update } = rendererResult as UpdatableRendererResult
63
+ : renderStream(ctx, item as StreamSpecification);
64
+ const { element, bbox, update } = rendererResult as UpdatableRendererResult;
75
65
 
76
- translate(element, 0, y - bbox.y1)
77
- $group.appendChild(element)
66
+ translate(element, 0, y - bbox.y1);
67
+ $group.appendChild(element);
78
68
 
79
- minX = Math.min(minX, bbox.x1)
80
- maxX = Math.max(maxX, bbox.x2)
69
+ minX = Math.min(minX, bbox.x1);
70
+ maxX = Math.max(maxX, bbox.x2);
81
71
 
82
- const height = bbox.y2 - bbox.y1
83
- y += height + styles.stream_spacing!
72
+ const height = bbox.y2 - bbox.y1;
73
+ y += height + styles.stream_spacing!;
84
74
 
85
75
  if (update != null) {
86
- updaters.push(update)
76
+ updaters.push(update);
87
77
  }
88
78
  }
89
79
 
90
- const dx = minX < 0 ? -minX : 0
91
- translate($group, dx, 0)
80
+ const dx = minX < 0 ? -minX : 0;
81
+ translate($group, dx, 0);
92
82
 
93
- const innerWidth = Math.max(maxX - minX, styles.minimum_width!)
94
- const innerHeight = Math.max(
95
- y - styles.stream_spacing!,
96
- styles.minimum_height!
97
- )
83
+ const innerWidth = Math.max(maxX - minX, styles.minimum_width!);
84
+ const innerHeight = Math.max(y - styles.stream_spacing!, styles.minimum_height!);
98
85
 
99
- const width = styles.canvas_padding! + innerWidth + styles.canvas_padding!
100
- const height = styles.canvas_padding! + innerHeight + styles.canvas_padding!
86
+ const width = styles.canvas_padding! + innerWidth + styles.canvas_padding!;
87
+ const height = styles.canvas_padding! + innerHeight + styles.canvas_padding!;
101
88
 
102
- setSvgDimensions($svg, width, height)
89
+ setSvgDimensions($svg, width, height);
103
90
 
104
- const bgColor = styles.background_color!
105
- if (bgColor !== '' && bgColor !== 'transparent') {
106
- const $bg = createSvgElement(document, 'rect', {
91
+ const bgColor = styles.background_color!;
92
+ if (bgColor !== "" && bgColor !== "transparent") {
93
+ const $bg = createSvgElement(document, "rect", {
107
94
  x: 0,
108
95
  y: 0,
109
96
  width,
110
97
  height,
111
- fill: bgColor
112
- })
113
- $svg.insertBefore($bg, $svg.firstChild)
98
+ fill: bgColor,
99
+ });
100
+ $svg.insertBefore($bg, $svg.firstChild);
114
101
  }
115
102
 
116
103
  for (const update of updaters) {
117
104
  update({
118
105
  width: innerWidth,
119
106
  height: innerHeight,
120
- dx
121
- })
107
+ dx,
108
+ });
122
109
  }
123
110
 
124
111
  return {
125
112
  document,
126
113
  width,
127
- height
128
- }
129
- }
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
+ };
@@ -1,30 +1,22 @@
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 { 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
- !('value' in notification) || typeof notification.value !== 'object'
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 };
@@ -1,94 +1,86 @@
1
1
  import {
2
2
  MessageSpecification,
3
3
  ScalarNextMessageStyles,
4
- ScalarNextNotificationSpecification
5
- } from '@swirly/types'
4
+ ScalarNextNotificationSpecification,
5
+ } from "@swirly/types";
6
6
 
7
- import {
8
- MessageRendererOptions,
9
- RendererContext,
10
- RendererResult
11
- } from '../types.js'
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, 'light' | 'dark'> = {
18
- auto: 'light',
19
- auto_light: 'light',
20
- auto_dark: '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
- styles,
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, 'g')
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, 'ellipse', {
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
- 'stroke-width': s.stroke_width!
55
- })
56
- )
46
+ "stroke-width": s.stroke_width!,
47
+ }),
48
+ );
57
49
 
58
50
  const $label = createSvgElement(
59
51
  document,
60
- 'text',
52
+ "text",
61
53
  {
62
54
  x: 0,
63
55
  y: 0,
64
56
  fill: s.value_color!,
65
- 'font-family': s.value_font_family!,
66
- 'font-size': s.value_font_size! + 'px',
67
- 'font-weight': s.value_font_weight!,
68
- 'font-style': s.value_font_style!,
69
- 'dominant-baseline': 'middle',
70
- 'text-anchor': 'middle'
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
+ };