likec4 1.0.0-build.2 → 1.0.0-build.4

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.
@@ -29,8 +29,9 @@ const slate = {
29
29
  loContrast: "#e2e8f0"
30
30
  };
31
31
  export const RelationColors = {
32
- lineColor: "#b1b1b1",
33
- labelColor: "#b1b1b1"
32
+ lineColor: "#6E6E6E",
33
+ labelBgColor: "#18191b",
34
+ labelColor: "#C6C6C6"
34
35
  };
35
36
  export const Colors = {
36
37
  primary: blue,
@@ -1,3 +1,4 @@
1
+ export { hasAtLeast } from "remeda";
1
2
  export function isString(value) {
2
3
  return value != null && typeof value === "string";
3
4
  }
@@ -6,20 +6,14 @@ import { mouseDefault, mousePointer } from "./shapes/utils.js";
6
6
  import { DiagramGesture, useHoveredEdgeId, useSetHoveredEdge } from "./state/index.js";
7
7
  import { useTransition } from "@react-spring/konva";
8
8
  import { scale, toHex } from "khroma";
9
- const edgeColors = ({ relation: { lineColor, labelColor } }, isHovered = false) => {
10
- if (Array.isArray(lineColor)) {
11
- lineColor = isHovered ? lineColor[1].onHover : lineColor[0];
12
- } else if (isHovered) {
9
+ const edgeColors = ({ relation: { lineColor, labelBgColor, labelColor } }, isHovered = false) => {
10
+ if (isHovered) {
13
11
  lineColor = toHex(
14
12
  scale(lineColor, {
15
13
  l: 35,
16
14
  s: -5
17
15
  })
18
16
  );
19
- }
20
- if (Array.isArray(labelColor)) {
21
- labelColor = isHovered ? labelColor[1].onHover : labelColor[0];
22
- } else if (isHovered) {
23
17
  labelColor = toHex(
24
18
  scale(labelColor, {
25
19
  l: 50
@@ -28,6 +22,7 @@ const edgeColors = ({ relation: { lineColor, labelColor } }, isHovered = false)
28
22
  }
29
23
  return {
30
24
  lineColor,
25
+ labelBgColor,
31
26
  labelColor
32
27
  };
33
28
  };
@@ -105,6 +100,7 @@ export function Edges({ animate, theme, diagram, onEdgeClick }) {
105
100
  children: /* @__PURE__ */ jsx(
106
101
  EdgeShape,
107
102
  {
103
+ animate,
108
104
  edge,
109
105
  isHovered: hoveredEdgeId === edge.id,
110
106
  theme,
@@ -1,22 +1,36 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { AnimatedCircle, AnimatedLine, AnimatedText } from "../../konva.js";
3
- import { invariant, nonNullable } from "@likec4/core";
4
- export function EdgeShape({ edge, theme, isHovered, springs }) {
5
- const { points, headArrow, labels } = edge;
6
- invariant(points[0], "Edge must have at least one point");
7
- const [x, y] = nonNullable(points[0]);
2
+ import { useSpring } from "@react-spring/konva";
3
+ import { AnimatedLine, AnimatedRect, AnimatedText } from "../../konva.js";
4
+ function EdgeLabelBg({
5
+ animate,
6
+ labelBBox,
7
+ isHovered,
8
+ springs
9
+ }) {
10
+ const props = useSpring({
11
+ to: {
12
+ x: labelBBox.x - 4,
13
+ y: labelBBox.y - 4,
14
+ width: labelBBox.width + 8,
15
+ height: labelBBox.height + 8,
16
+ opacity: isHovered ? 0.25 : 0.1
17
+ },
18
+ immediate: !animate
19
+ });
20
+ return /* @__PURE__ */ jsx(
21
+ AnimatedRect,
22
+ {
23
+ ...props,
24
+ fill: springs.labelBgColor,
25
+ cornerRadius: 2,
26
+ globalCompositeOperation: "darken",
27
+ hitStrokeWidth: 5
28
+ }
29
+ );
30
+ }
31
+ export function EdgeShape({ animate = true, edge, theme, isHovered, springs }) {
32
+ const { points, headArrow, labelBBox, labels } = edge;
8
33
  return /* @__PURE__ */ jsxs(Fragment, { children: [
9
- /* @__PURE__ */ jsx(
10
- AnimatedCircle,
11
- {
12
- opacity: springs.opacity,
13
- x,
14
- y,
15
- radius: springs.lineWidth.to((v) => v + 1),
16
- fill: springs.lineColor,
17
- visible: isHovered
18
- }
19
- ),
20
34
  /* @__PURE__ */ jsx(
21
35
  AnimatedLine,
22
36
  {
@@ -24,9 +38,11 @@ export function EdgeShape({ edge, theme, isHovered, springs }) {
24
38
  bezier: true,
25
39
  dashEnabled: true,
26
40
  points: points.flat(),
41
+ dash: [8, 4],
27
42
  stroke: springs.lineColor,
28
43
  strokeWidth: springs.lineWidth,
29
- hitStrokeWidth: 20
44
+ hitStrokeWidth: 20,
45
+ globalCompositeOperation: "luminosity"
30
46
  }
31
47
  ),
32
48
  headArrow && /* @__PURE__ */ jsx(
@@ -37,25 +53,41 @@ export function EdgeShape({ edge, theme, isHovered, springs }) {
37
53
  closed: true,
38
54
  fill: springs.lineColor,
39
55
  stroke: springs.lineColor,
40
- strokeWidth: 2,
41
- hitStrokeWidth: 5
56
+ strokeWidth: 1,
57
+ hitStrokeWidth: 5,
58
+ globalCompositeOperation: "luminosity"
59
+ }
60
+ ),
61
+ labelBBox && labelBBox.width > 0 && /* @__PURE__ */ jsx(
62
+ EdgeLabelBg,
63
+ {
64
+ animate,
65
+ labelBBox,
66
+ isHovered,
67
+ springs
42
68
  }
43
69
  ),
44
- labels.map((label, i) => /* @__PURE__ */ jsx(
70
+ labels && labels.map((label, i) => /* @__PURE__ */ jsx(
45
71
  AnimatedText,
46
72
  {
47
- x: label.pt[0] - 4,
48
- y: label.pt[1] - label.fontSize / 2 - 4,
73
+ x: label.pt[0],
74
+ y: label.pt[1],
75
+ offsetY: label.fontSize / 2,
49
76
  opacity: springs.opacity,
50
- padding: 4,
51
77
  fill: springs.labelColor,
52
78
  fontFamily: theme.font,
53
79
  fontSize: label.fontSize,
54
80
  fontStyle: label.fontStyle ?? "normal",
55
- align: label.align,
56
81
  text: label.text,
57
82
  perfectDrawEnabled: false,
58
- hitStrokeWidth: 10
83
+ listening: false,
84
+ globalCompositeOperation: "luminosity",
85
+ shadowEnabled: springs.opacity.to((o) => o > 0.5),
86
+ shadowColor: "#222",
87
+ shadowOpacity: 0.15,
88
+ shadowOffsetX: 1,
89
+ shadowOffsetY: 2,
90
+ shadowBlur: 2
59
91
  },
60
92
  i
61
93
  ))
@@ -22,7 +22,8 @@ export function NodeIcon({ icon, maxWidth, maxHeight, offsetX = 0, offsetY = 0 }
22
22
  offsetY,
23
23
  width: iconWidth,
24
24
  height: iconHeight,
25
- listening: false
25
+ listening: false,
26
+ globalCompositeOperation: "hard-light"
26
27
  }
27
28
  );
28
29
  }
@@ -1,7 +1,7 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { AnimatedRect } from "../../konva.js";
3
- import { NodeLabels } from "./NodeLabel.js";
4
3
  import { useShadowSprings } from "../springs.js";
4
+ import { NodeLabels } from "./NodeLabel.js";
5
5
  export function RectangleShape({ node, theme, springs, isHovered }) {
6
6
  return /* @__PURE__ */ jsxs(Fragment, { children: [
7
7
  /* @__PURE__ */ jsx(
@@ -1,7 +1,5 @@
1
1
  import { useAtom, useAtomValue, useSetAtom } from "jotai";
2
- import { selectAtom } from "jotai/utils";
3
2
  import { hoveredEdgeAtom, hoveredEdgeIdAtom, hoveredNodeAtom, hoveredNodeIdAtom } from "./atoms.js";
4
- import { useCallback } from "react";
5
3
  export function useHoveredNode() {
6
4
  return useAtom(hoveredNodeAtom);
7
5
  }
@@ -11,15 +9,6 @@ export function useHoveredNodeId() {
11
9
  export function useSetHoveredNode() {
12
10
  return useSetAtom(hoveredNodeAtom);
13
11
  }
14
- export function useGetNodeState(nodeId) {
15
- const isHovered = useAtomValue(
16
- selectAtom(
17
- hoveredNodeAtom,
18
- useCallback((node) => node?.id === nodeId, [nodeId])
19
- )
20
- );
21
- return { isHovered };
22
- }
23
12
  export function useHoveredEdgeId() {
24
13
  return useAtomValue(hoveredEdgeIdAtom);
25
14
  }