@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
@@ -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
+ };
@@ -1,62 +1,59 @@
1
- import { StreamSpecification, StreamStyles } from '@swirly/types'
1
+ import { StreamSpecification, StreamStyles } from "@swirly/types";
2
2
 
3
- import { RendererContext, RendererResult } from '../types.js'
4
- import { mergeStyles } from '../util/merge-styles.js'
5
- import { createSvgElement } from '../util/svg-xml.js'
6
- import { translate } from '../util/transform.js'
7
- import { renderStreamBase } from './core.js'
3
+ import { RendererContext, RendererResult } from "../types.js";
4
+ import { mergeStyles } from "../util/merge-styles.js";
5
+ import { createSvgElement } from "../util/svg-xml.js";
6
+ import { translate } from "../util/transform.js";
7
+ import { renderStreamBase } from "./core.js";
8
8
 
9
- export const renderStream = (
10
- ctx: RendererContext,
11
- stream: StreamSpecification
12
- ): RendererResult => {
13
- const { document, styles, streamHeight, streamTitleEnabled } = ctx
14
- const s: StreamStyles = mergeStyles(styles, stream.styles, 'stream_')
9
+ export const renderStream = (ctx: RendererContext, stream: StreamSpecification): RendererResult => {
10
+ const { document, styles, streamHeight, streamTitleEnabled } = ctx;
11
+ const s: StreamStyles = mergeStyles(styles, stream.styles, "stream_");
15
12
 
16
- const renderStreamResult = renderStreamBase(ctx, stream, false, false)
13
+ const renderStreamResult = renderStreamBase(ctx, stream, false, false);
17
14
 
18
- const { element: $streamGroup, bbox } = renderStreamResult
15
+ const { element: $streamGroup, bbox } = renderStreamResult;
19
16
 
20
17
  if (stream.frame != null && stream.frame > 0) {
21
- const dx = stream.frame * styles.frame_width!
22
- translate($streamGroup, dx, 0)
23
- bbox.x1 += dx
24
- bbox.x2 += dx
18
+ const dx = stream.frame * styles.frame_width!;
19
+ translate($streamGroup, dx, 0);
20
+ bbox.x1 += dx;
21
+ bbox.x2 += dx;
25
22
  }
26
23
 
27
24
  if (!streamTitleEnabled) {
28
- return renderStreamResult
25
+ return renderStreamResult;
29
26
  }
30
27
 
31
- const $outerGroup = createSvgElement(document, 'g')
28
+ const $outerGroup = createSvgElement(document, "g");
32
29
 
33
- const title = typeof stream.title === 'string' ? stream.title : ''
30
+ const title = typeof stream.title === "string" ? stream.title : "";
34
31
  $outerGroup.appendChild(
35
32
  createSvgElement(
36
33
  document,
37
- 'text',
34
+ "text",
38
35
  {
39
36
  x: 0,
40
37
  y: streamHeight / 2,
41
38
  fill: s.title_color!,
42
- 'font-family': s.title_font_family!,
43
- 'font-size': s.title_font_size! + 'px',
44
- 'font-weight': s.title_font_weight!,
45
- 'font-style': s.title_font_style!,
46
- 'dominant-baseline': 'middle'
39
+ "font-family": s.title_font_family!,
40
+ "font-size": s.title_font_size! + "px",
41
+ "font-weight": s.title_font_weight!,
42
+ "font-style": s.title_font_style!,
43
+ "dominant-baseline": "middle",
47
44
  },
48
- title
49
- )
50
- )
45
+ title,
46
+ ),
47
+ );
51
48
 
52
- $outerGroup.appendChild($streamGroup)
53
- translate($streamGroup, s.title_width!, 0)
49
+ $outerGroup.appendChild($streamGroup);
50
+ translate($streamGroup, s.title_width!, 0);
54
51
 
55
- bbox.x1 = 0
56
- bbox.x2 += s.title_width!
52
+ bbox.x1 = 0;
53
+ bbox.x2 += s.title_width!;
57
54
 
58
55
  return {
59
56
  element: $outerGroup,
60
- bbox
61
- }
62
- }
57
+ bbox,
58
+ };
59
+ };
package/src/types.ts CHANGED
@@ -2,72 +2,68 @@ import {
2
2
  DecorationSpecification,
3
3
  DiagramStyles,
4
4
  MessageSpecification,
5
- SVGDocument
6
- } from '@swirly/types'
5
+ SVGDocument,
6
+ } from "@swirly/types";
7
7
 
8
8
  export type Point = {
9
- x: number
10
- y: number
11
- }
9
+ x: number;
10
+ y: number;
11
+ };
12
12
 
13
13
  export type Rectangle = {
14
- x1: number
15
- y1: number
16
- x2: number
17
- y2: number
18
- }
14
+ x1: number;
15
+ y1: number;
16
+ x2: number;
17
+ y2: number;
18
+ };
19
19
 
20
- export type TimeScaler = (time: number) => number
21
-
22
- export type RendererOptions = {
23
- DOMParser?: typeof DOMParser
24
- styles?: DiagramStyles
25
- }
20
+ export type TimeScaler = (time: number) => number;
26
21
 
27
22
  export type RendererContext = {
28
- DOMParser?: typeof DOMParser
29
- document: SVGDocument
30
- styles: DiagramStyles
31
- streamHeight: number
32
- streamTitleEnabled: boolean
33
- }
23
+ DOMParser?: typeof DOMParser;
24
+ document: SVGDocument;
25
+ styles: DiagramStyles;
26
+ streamHeight: number;
27
+ streamTitleEnabled: boolean;
28
+ };
34
29
 
35
30
  export type RendererResult = {
36
- element: SVGElement
37
- bbox: Rectangle
38
- }
31
+ element: SVGElement;
32
+ bbox: Rectangle;
33
+ };
39
34
 
40
35
  export type PostRenderUpdateContext = {
41
- width: number
42
- height: number
43
- }
36
+ width: number;
37
+ height: number;
38
+ dx: number;
39
+ };
44
40
 
45
41
  export type UpdatableRendererResult = RendererResult & {
46
- update?: (ctx: PostRenderUpdateContext) => void
47
- }
42
+ update?: (ctx: PostRenderUpdateContext) => void;
43
+ };
48
44
 
49
45
  export type MessageRendererOptions = {
50
- verticalOffset: number
51
- valueAngle: number
52
- }
46
+ verticalOffset: number;
47
+ valueAngle: number;
48
+ };
53
49
 
54
50
  export type MessageRenderer = (
55
51
  ctx: RendererContext,
56
52
  message: MessageSpecification,
57
- options: MessageRendererOptions
58
- ) => RendererResult
53
+ options: MessageRendererOptions,
54
+ ) => RendererResult;
59
55
 
60
56
  export type DecorationRendererContext = RendererContext & {
61
- bbox: Rectangle
62
- scaleTime: TimeScaler
63
- }
57
+ bbox: Rectangle;
58
+ scaleTime: TimeScaler;
59
+ };
64
60
 
65
61
  export type DecorationRendererResult = {
66
- element: SVGElement
67
- bbox?: Rectangle
68
- }
62
+ element: SVGElement;
63
+ bbox?: Rectangle;
64
+ };
69
65
 
70
66
  export type DecorationRenderer = (
71
67
  ctx: DecorationRendererContext,
72
- decoration: DecorationSpecification
73
- ) => DecorationRendererResult
68
+ decoration: DecorationSpecification,
69
+ ) => DecorationRendererResult;
@@ -1,2 +1 @@
1
- export const degreesToRadians = (degrees: number): number =>
2
- (degrees / 180) * Math.PI
1
+ export const degreesToRadians = (degrees: number): number => (degrees / 180) * Math.PI;
@@ -1,74 +1,61 @@
1
- import { Point, Rectangle } from '../types.js'
1
+ import { Point, Rectangle } from "../types.js";
2
2
 
3
- export const translatePoint = (
4
- x: number,
5
- y: number,
6
- dx: number,
7
- dy: number
8
- ): Point => ({
3
+ export const translatePoint = (x: number, y: number, dx: number, dy: number): Point => ({
9
4
  x: x + dx,
10
- y: y + dy
11
- })
5
+ y: y + dy,
6
+ });
12
7
 
13
8
  export const translateRectangle = (
14
9
  { x1, y1, x2, y2 }: Rectangle,
15
10
  dx: number,
16
- dy: number
11
+ dy: number,
17
12
  ): Rectangle => {
18
- const p1 = translatePoint(x1, y1, dx, dy)
19
- const p2 = translatePoint(x2, y2, dx, dy)
13
+ const p1 = translatePoint(x1, y1, dx, dy);
14
+ const p2 = translatePoint(x2, y2, dx, dy);
20
15
  return {
21
16
  x1: p1.x,
22
17
  y1: p1.y,
23
18
  x2: p2.x,
24
- y2: p2.y
25
- }
26
- }
19
+ y2: p2.y,
20
+ };
21
+ };
27
22
 
28
- export const rotatePoint = (
29
- x: number,
30
- y: number,
31
- angle: number,
32
- x0: number,
33
- y0: number
34
- ): Point => {
35
- const s = Math.sin(angle)
36
- const c = Math.cos(angle)
37
- x -= x0
38
- y -= y0
23
+ export const rotatePoint = (x: number, y: number, angle: number, x0: number, y0: number): Point => {
24
+ const s = Math.sin(angle);
25
+ const c = Math.cos(angle);
26
+ x -= x0;
27
+ y -= y0;
39
28
  return {
40
29
  x: x * c - y * s + x0,
41
- y: x * s + y * c + y0
42
- }
43
- }
30
+ y: x * s + y * c + y0,
31
+ };
32
+ };
44
33
 
45
34
  export const rotateRectangle = (
46
35
  { x1, y1, x2, y2 }: Rectangle,
47
36
  angle: number,
48
37
  x0: number,
49
- y0: number
38
+ y0: number,
50
39
  ): Rectangle => {
51
- const p1 = rotatePoint(x1, y1, angle, x0, y0)
52
- const p2 = rotatePoint(x2, y2, angle, x0, y0)
40
+ const p1 = rotatePoint(x1, y1, angle, x0, y0);
41
+ const p2 = rotatePoint(x2, y2, angle, x0, y0);
53
42
  return {
54
43
  x1: p1.x,
55
44
  y1: p1.y,
56
45
  x2: p2.x,
57
- y2: p2.y
58
- }
59
- }
46
+ y2: p2.y,
47
+ };
48
+ };
60
49
 
61
50
  export const rectangleUnion = (rects: readonly Rectangle[]): Rectangle => {
62
- const nonEmptyRects = rects.filter(
63
- ({ x1, y1, x2, y2 }) => x2 - x1 !== 0 && y2 - y1 !== 0
64
- )
51
+ const nonEmptyRects = rects.filter(({ x1, y1, x2, y2 }) => x2 - x1 !== 0 && y2 - y1 !== 0);
65
52
  if (nonEmptyRects.length === 0) {
66
- throw new Error('All rectangles empty')
53
+ throw new Error("All rectangles empty");
67
54
  }
68
55
  return {
69
56
  x1: Math.min(...nonEmptyRects.map((rect) => rect.x1)),
70
57
  y1: Math.min(...nonEmptyRects.map((rect) => rect.y1)),
71
58
  x2: Math.max(...nonEmptyRects.map((rect) => rect.x2)),
72
- y2: Math.max(...nonEmptyRects.map((rect) => rect.y2))
73
- }
74
- }
59
+ y2: Math.max(...nonEmptyRects.map((rect) => rect.y2)),
60
+ };
61
+ };
@@ -1,12 +1,12 @@
1
- const A = 'A'.charCodeAt(0)
2
- const ZERO = '0'.charCodeAt(0)
1
+ const A = "A".charCodeAt(0);
2
+ const ZERO = "0".charCodeAt(0);
3
3
 
4
4
  export const hexToDec = (hex: string): number => {
5
- let dec = 0
6
- hex = hex.toUpperCase()
5
+ let dec = 0;
6
+ hex = hex.toUpperCase();
7
7
  for (let i = 0; i < hex.length; ++i) {
8
- const c = hex.charCodeAt(i)
9
- dec = (dec << 4) + (c >= A ? c - A + 10 : c - ZERO)
8
+ const c = hex.charCodeAt(i);
9
+ dec = (dec << 4) + (c >= A ? c - A + 10 : c - ZERO);
10
10
  }
11
- return dec
12
- }
11
+ return dec;
12
+ };
@@ -1,24 +1,22 @@
1
- import { FreeformStyles } from '@swirly/types'
1
+ import { FreeformStyles } from "@swirly/types";
2
2
 
3
3
  export const mergeStyles = (
4
4
  globalStyles: FreeformStyles,
5
5
  localStyles: FreeformStyles | null | undefined,
6
6
  globalPrefix: string,
7
- localStylesPrefixed: boolean = false
7
+ localStylesPrefixed: boolean = false,
8
8
  ): FreeformStyles => {
9
- const result: FreeformStyles = {}
9
+ const result: FreeformStyles = {};
10
10
 
11
- const globalKeys = Object.keys(globalStyles).filter((key) =>
12
- key.startsWith(globalPrefix)
13
- )
11
+ const globalKeys = Object.keys(globalStyles).filter((key) => key.startsWith(globalPrefix));
14
12
  for (const globalKey of globalKeys) {
15
- const simpleKey = globalKey.substring(globalPrefix.length)
16
- const localKey = localStylesPrefixed ? globalKey : simpleKey
13
+ const simpleKey = globalKey.substring(globalPrefix.length);
14
+ const localKey = localStylesPrefixed ? globalKey : simpleKey;
17
15
  result[simpleKey] =
18
16
  localStyles != null && localStyles[localKey] != null
19
17
  ? localStyles[localKey]
20
- : globalStyles[globalKey]
18
+ : globalStyles[globalKey];
21
19
  }
22
20
 
23
- return result
24
- }
21
+ return result;
22
+ };
@@ -1,15 +1,15 @@
1
1
  export class NotificationKind {
2
- static NEXT = new NotificationKind('N')
3
- static COMPLETE = new NotificationKind('C')
4
- static ERROR = new NotificationKind('E')
2
+ static NEXT = new NotificationKind("N");
3
+ static COMPLETE = new NotificationKind("C");
4
+ static ERROR = new NotificationKind("E");
5
5
 
6
- #char: string
6
+ #char: string;
7
7
 
8
- private constructor (char: string) {
9
- this.#char = char
8
+ private constructor(char: string) {
9
+ this.#char = char;
10
10
  }
11
11
 
12
- equals (x: any): boolean {
13
- return typeof x === 'string' && x.charAt(0).toUpperCase() === this.#char
12
+ equals(x: any): boolean {
13
+ return typeof x === "string" && x.charAt(0).toUpperCase() === this.#char;
14
14
  }
15
15
  }
@@ -1,13 +1,13 @@
1
1
  // @ts-ignore
2
- import { sync as sha1 } from 'simple-sha1'
2
+ import { sync as sha1 } from "simple-sha1";
3
3
 
4
- import { hexToDec } from './hex-to-dec.js'
4
+ import { hexToDec } from "./hex-to-dec.js";
5
5
 
6
- export const stringToColor = (str: string, mode: 'light' | 'dark'): string => {
7
- const hashHex = sha1(str)
8
- const hash = hexToDec(hashHex.substring(4, 8))
9
- const hue = Math.round((hash / (1 << 16)) * 360)
10
- const saturation = 60
11
- const lightness = mode === 'dark' ? 20 : 80
12
- return `hsl(${hue}, ${saturation}%, ${lightness}%)`
13
- }
6
+ export const stringToColor = (str: string, mode: "light" | "dark"): string => {
7
+ const hashHex = sha1(str);
8
+ const hash = hexToDec(hashHex.substring(4, 8));
9
+ const hue = Math.round((hash / (1 << 16)) * 360);
10
+ const saturation = 60;
11
+ const lightness = mode === "dark" ? 20 : 80;
12
+ return `hsl(${hue}, ${saturation}%, ${lightness}%)`;
13
+ };