likec4 0.41.0 → 0.42.1

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 (144) hide show
  1. package/README.md +108 -0
  2. package/dist/__app__/src/App.jsx +1 -1
  3. package/dist/__app__/src/components/view-page/ExportDiagram.jsx +72 -0
  4. package/dist/__app__/src/components/view-page/ViewActionsToolbar.jsx +38 -12
  5. package/dist/cli/index.js +53 -53
  6. package/package.json +6 -6
  7. package/dist/@likec4/diagrams/cjs/components/EmbeddedDiagram.js +0 -83
  8. package/dist/@likec4/diagrams/cjs/components/FullscreenDiagramBrowser.js +0 -50
  9. package/dist/@likec4/diagrams/cjs/components/index.js +0 -49
  10. package/dist/@likec4/diagrams/cjs/components/primitives/fullscreen/CloseButton.js +0 -44
  11. package/dist/@likec4/diagrams/cjs/components/primitives/fullscreen/FullscreenDiagram.js +0 -110
  12. package/dist/@likec4/diagrams/cjs/components/primitives/fullscreen/FullscreenDiagramTitle.js +0 -39
  13. package/dist/@likec4/diagrams/cjs/components/primitives/index.js +0 -38
  14. package/dist/@likec4/diagrams/cjs/components/primitives/responsive/ResponsiveDiagram.js +0 -56
  15. package/dist/@likec4/diagrams/cjs/components/types.js +0 -1
  16. package/dist/@likec4/diagrams/cjs/diagram/Diagram.js +0 -326
  17. package/dist/@likec4/diagrams/cjs/diagram/Edges.js +0 -121
  18. package/dist/@likec4/diagrams/cjs/diagram/Nodes.js +0 -204
  19. package/dist/@likec4/diagrams/cjs/diagram/icons/BrainIcon.js +0 -25
  20. package/dist/@likec4/diagrams/cjs/diagram/icons/ExternalLink.js +0 -82
  21. package/dist/@likec4/diagrams/cjs/diagram/icons/index.js +0 -27
  22. package/dist/@likec4/diagrams/cjs/diagram/index.js +0 -27
  23. package/dist/@likec4/diagrams/cjs/diagram/shapes/Browser.js +0 -67
  24. package/dist/@likec4/diagrams/cjs/diagram/shapes/Compound.js +0 -55
  25. package/dist/@likec4/diagrams/cjs/diagram/shapes/Cylinder.js +0 -71
  26. package/dist/@likec4/diagrams/cjs/diagram/shapes/Edge.js +0 -62
  27. package/dist/@likec4/diagrams/cjs/diagram/shapes/Mobile.js +0 -45
  28. package/dist/@likec4/diagrams/cjs/diagram/shapes/NodeIcon.js +0 -38
  29. package/dist/@likec4/diagrams/cjs/diagram/shapes/NodeLabel.js +0 -62
  30. package/dist/@likec4/diagrams/cjs/diagram/shapes/Person.js +0 -48
  31. package/dist/@likec4/diagrams/cjs/diagram/shapes/Queue.js +0 -72
  32. package/dist/@likec4/diagrams/cjs/diagram/shapes/Rectangle.js +0 -30
  33. package/dist/@likec4/diagrams/cjs/diagram/shapes/index.js +0 -54
  34. package/dist/@likec4/diagrams/cjs/diagram/shapes/types.js +0 -1
  35. package/dist/@likec4/diagrams/cjs/diagram/shapes/utils.js +0 -19
  36. package/dist/@likec4/diagrams/cjs/diagram/springs.js +0 -61
  37. package/dist/@likec4/diagrams/cjs/diagram/state/atoms.js +0 -63
  38. package/dist/@likec4/diagrams/cjs/diagram/state/gestures.js +0 -26
  39. package/dist/@likec4/diagrams/cjs/diagram/state/hooks.js +0 -36
  40. package/dist/@likec4/diagrams/cjs/diagram/state/index.js +0 -38
  41. package/dist/@likec4/diagrams/cjs/diagram/state/provider.js +0 -18
  42. package/dist/@likec4/diagrams/cjs/diagram/types.js +0 -1
  43. package/dist/@likec4/diagrams/cjs/hooks/index.js +0 -49
  44. package/dist/@likec4/diagrams/cjs/hooks/useDarkMode.js +0 -11
  45. package/dist/@likec4/diagrams/cjs/hooks/useDiagramApi.js +0 -27
  46. package/dist/@likec4/diagrams/cjs/hooks/useImageLoader.js +0 -68
  47. package/dist/@likec4/diagrams/cjs/hooks/useViewIdFromHash.js +0 -93
  48. package/dist/@likec4/diagrams/cjs/index.js +0 -51
  49. package/dist/@likec4/diagrams/cjs/konva-html.js +0 -93
  50. package/dist/@likec4/diagrams/cjs/konva-portal.js +0 -50
  51. package/dist/@likec4/diagrams/cjs/konva.js +0 -102
  52. package/dist/@likec4/diagrams/cjs/likec4.js +0 -91
  53. package/dist/@likec4/diagrams/components/EmbeddedDiagram.mjs +0 -77
  54. package/dist/@likec4/diagrams/components/FullscreenDiagramBrowser.mjs +0 -52
  55. package/dist/@likec4/diagrams/components/index.mjs +0 -4
  56. package/dist/@likec4/diagrams/components/primitives/fullscreen/CloseButton.mjs +0 -43
  57. package/dist/@likec4/diagrams/components/primitives/fullscreen/FullscreenDiagram.mjs +0 -116
  58. package/dist/@likec4/diagrams/components/primitives/fullscreen/FullscreenDiagramTitle.mjs +0 -32
  59. package/dist/@likec4/diagrams/components/primitives/index.mjs +0 -3
  60. package/dist/@likec4/diagrams/components/primitives/responsive/ResponsiveDiagram.mjs +0 -42
  61. package/dist/@likec4/diagrams/components/types.mjs +0 -0
  62. package/dist/@likec4/diagrams/diagram/Diagram.mjs +0 -307
  63. package/dist/@likec4/diagrams/diagram/Edges.mjs +0 -117
  64. package/dist/@likec4/diagrams/diagram/Nodes.mjs +0 -178
  65. package/dist/@likec4/diagrams/diagram/icons/BrainIcon.mjs +0 -20
  66. package/dist/@likec4/diagrams/diagram/icons/ExternalLink.mjs +0 -90
  67. package/dist/@likec4/diagrams/diagram/icons/index.mjs +0 -2
  68. package/dist/@likec4/diagrams/diagram/index.mjs +0 -2
  69. package/dist/@likec4/diagrams/diagram/shapes/Browser.mjs +0 -49
  70. package/dist/@likec4/diagrams/diagram/shapes/Compound.mjs +0 -48
  71. package/dist/@likec4/diagrams/diagram/shapes/Cylinder.mjs +0 -57
  72. package/dist/@likec4/diagrams/diagram/shapes/Edge.mjs +0 -63
  73. package/dist/@likec4/diagrams/diagram/shapes/Mobile.mjs +0 -33
  74. package/dist/@likec4/diagrams/diagram/shapes/NodeIcon.mjs +0 -28
  75. package/dist/@likec4/diagrams/diagram/shapes/NodeLabel.mjs +0 -59
  76. package/dist/@likec4/diagrams/diagram/shapes/Person.mjs +0 -42
  77. package/dist/@likec4/diagrams/diagram/shapes/Queue.mjs +0 -58
  78. package/dist/@likec4/diagrams/diagram/shapes/Rectangle.mjs +0 -20
  79. package/dist/@likec4/diagrams/diagram/shapes/index.mjs +0 -7
  80. package/dist/@likec4/diagrams/diagram/shapes/types.mjs +0 -0
  81. package/dist/@likec4/diagrams/diagram/shapes/utils.mjs +0 -12
  82. package/dist/@likec4/diagrams/diagram/springs.mjs +0 -57
  83. package/dist/@likec4/diagrams/diagram/state/atoms.mjs +0 -71
  84. package/dist/@likec4/diagrams/diagram/state/gestures.mjs +0 -19
  85. package/dist/@likec4/diagrams/diagram/state/hooks.mjs +0 -28
  86. package/dist/@likec4/diagrams/diagram/state/index.mjs +0 -3
  87. package/dist/@likec4/diagrams/diagram/state/provider.mjs +0 -7
  88. package/dist/@likec4/diagrams/diagram/types.mjs +0 -0
  89. package/dist/@likec4/diagrams/esm/components/EmbeddedDiagram.js +0 -77
  90. package/dist/@likec4/diagrams/esm/components/FullscreenDiagramBrowser.js +0 -52
  91. package/dist/@likec4/diagrams/esm/components/index.js +0 -4
  92. package/dist/@likec4/diagrams/esm/components/primitives/fullscreen/CloseButton.js +0 -43
  93. package/dist/@likec4/diagrams/esm/components/primitives/fullscreen/FullscreenDiagram.js +0 -116
  94. package/dist/@likec4/diagrams/esm/components/primitives/fullscreen/FullscreenDiagramTitle.js +0 -32
  95. package/dist/@likec4/diagrams/esm/components/primitives/index.js +0 -3
  96. package/dist/@likec4/diagrams/esm/components/primitives/responsive/ResponsiveDiagram.js +0 -42
  97. package/dist/@likec4/diagrams/esm/components/types.js +0 -0
  98. package/dist/@likec4/diagrams/esm/diagram/Diagram.js +0 -307
  99. package/dist/@likec4/diagrams/esm/diagram/Edges.js +0 -117
  100. package/dist/@likec4/diagrams/esm/diagram/Nodes.js +0 -178
  101. package/dist/@likec4/diagrams/esm/diagram/icons/BrainIcon.js +0 -20
  102. package/dist/@likec4/diagrams/esm/diagram/icons/ExternalLink.js +0 -90
  103. package/dist/@likec4/diagrams/esm/diagram/icons/index.js +0 -2
  104. package/dist/@likec4/diagrams/esm/diagram/index.js +0 -2
  105. package/dist/@likec4/diagrams/esm/diagram/shapes/Browser.js +0 -49
  106. package/dist/@likec4/diagrams/esm/diagram/shapes/Compound.js +0 -48
  107. package/dist/@likec4/diagrams/esm/diagram/shapes/Cylinder.js +0 -57
  108. package/dist/@likec4/diagrams/esm/diagram/shapes/Edge.js +0 -63
  109. package/dist/@likec4/diagrams/esm/diagram/shapes/Mobile.js +0 -33
  110. package/dist/@likec4/diagrams/esm/diagram/shapes/NodeIcon.js +0 -28
  111. package/dist/@likec4/diagrams/esm/diagram/shapes/NodeLabel.js +0 -59
  112. package/dist/@likec4/diagrams/esm/diagram/shapes/Person.js +0 -42
  113. package/dist/@likec4/diagrams/esm/diagram/shapes/Queue.js +0 -58
  114. package/dist/@likec4/diagrams/esm/diagram/shapes/Rectangle.js +0 -20
  115. package/dist/@likec4/diagrams/esm/diagram/shapes/index.js +0 -7
  116. package/dist/@likec4/diagrams/esm/diagram/shapes/types.js +0 -0
  117. package/dist/@likec4/diagrams/esm/diagram/shapes/utils.js +0 -12
  118. package/dist/@likec4/diagrams/esm/diagram/springs.js +0 -57
  119. package/dist/@likec4/diagrams/esm/diagram/state/atoms.js +0 -71
  120. package/dist/@likec4/diagrams/esm/diagram/state/gestures.js +0 -19
  121. package/dist/@likec4/diagrams/esm/diagram/state/hooks.js +0 -28
  122. package/dist/@likec4/diagrams/esm/diagram/state/index.js +0 -3
  123. package/dist/@likec4/diagrams/esm/diagram/state/provider.js +0 -7
  124. package/dist/@likec4/diagrams/esm/diagram/types.js +0 -0
  125. package/dist/@likec4/diagrams/esm/hooks/index.js +0 -4
  126. package/dist/@likec4/diagrams/esm/hooks/useDarkMode.js +0 -5
  127. package/dist/@likec4/diagrams/esm/hooks/useDiagramApi.js +0 -27
  128. package/dist/@likec4/diagrams/esm/hooks/useImageLoader.js +0 -64
  129. package/dist/@likec4/diagrams/esm/hooks/useViewIdFromHash.js +0 -87
  130. package/dist/@likec4/diagrams/esm/index.js +0 -4
  131. package/dist/@likec4/diagrams/esm/konva-html.js +0 -74
  132. package/dist/@likec4/diagrams/esm/konva-portal.js +0 -34
  133. package/dist/@likec4/diagrams/esm/konva.js +0 -22
  134. package/dist/@likec4/diagrams/esm/likec4.js +0 -54
  135. package/dist/@likec4/diagrams/hooks/index.mjs +0 -4
  136. package/dist/@likec4/diagrams/hooks/useDarkMode.mjs +0 -5
  137. package/dist/@likec4/diagrams/hooks/useDiagramApi.mjs +0 -27
  138. package/dist/@likec4/diagrams/hooks/useImageLoader.mjs +0 -64
  139. package/dist/@likec4/diagrams/hooks/useViewIdFromHash.mjs +0 -87
  140. package/dist/@likec4/diagrams/index.mjs +0 -4
  141. package/dist/@likec4/diagrams/konva-html.mjs +0 -74
  142. package/dist/@likec4/diagrams/konva-portal.mjs +0 -34
  143. package/dist/@likec4/diagrams/konva.mjs +0 -33
  144. package/dist/@likec4/diagrams/likec4.mjs +0 -54
@@ -1,2 +0,0 @@
1
- export { Diagram } from "./Diagram.js";
2
- export * from "./state/index.js";
@@ -1,49 +0,0 @@
1
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { useShadowSprings } from "../springs.js";
3
- import { AnimatedRect, Circle } from "../../konva.js";
4
- import { NodeLabels } from "./NodeLabel.js";
5
- export function BrowserShape({ node, theme, springs, isHovered }) {
6
- const colors = theme.colors[node.color];
7
- return /* @__PURE__ */ jsxs(Fragment, { children: [
8
- /* @__PURE__ */ jsx(
9
- AnimatedRect,
10
- {
11
- ...useShadowSprings(isHovered, theme, springs),
12
- cornerRadius: 6,
13
- perfectDrawEnabled: false,
14
- strokeEnabled: false,
15
- width: springs.width,
16
- height: springs.height,
17
- fill: springs.stroke
18
- }
19
- ),
20
- /* @__PURE__ */ jsx(Circle, { x: 16, y: 15, radius: 7, fill: colors.fill, listening: false }),
21
- /* @__PURE__ */ jsx(Circle, { x: 36, y: 15, radius: 7, fill: colors.fill, listening: false }),
22
- /* @__PURE__ */ jsx(Circle, { x: 56, y: 15, radius: 7, fill: colors.fill, listening: false }),
23
- /* @__PURE__ */ jsx(
24
- AnimatedRect,
25
- {
26
- cornerRadius: 5,
27
- x: 70,
28
- y: 7,
29
- width: springs.width.to((w) => w - 80),
30
- height: 16,
31
- fill: springs.fill,
32
- listening: false
33
- }
34
- ),
35
- /* @__PURE__ */ jsx(
36
- AnimatedRect,
37
- {
38
- cornerRadius: 5,
39
- x: 9,
40
- y: 31,
41
- width: springs.width.to((w) => w - 18),
42
- height: springs.height.to((h) => h - 40),
43
- fill: springs.fill,
44
- listening: false
45
- }
46
- ),
47
- /* @__PURE__ */ jsx(NodeLabels, { node, theme, offsetY: -8 })
48
- ] });
49
- }
@@ -1,48 +0,0 @@
1
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { AnimatedRect, AnimatedText } from "../../konva.js";
3
- export function CompoundShape({ node, theme, springs }) {
4
- const { labels } = node;
5
- return /* @__PURE__ */ jsxs(Fragment, { children: [
6
- /* @__PURE__ */ jsx(
7
- AnimatedRect,
8
- {
9
- cornerRadius: 4,
10
- shadowColor: theme.shadow,
11
- shadowBlur: node.level > 0 ? 20 : 10,
12
- shadowOpacity: node.level > 0 ? 0.35 : 0.8,
13
- shadowOffsetX: 0,
14
- shadowOffsetY: 4,
15
- shadowEnabled: springs.opacity.to((v) => v > 0.7),
16
- width: springs.width,
17
- height: springs.height,
18
- fill: springs.fill,
19
- strokeEnabled: false,
20
- listening: false
21
- }
22
- ),
23
- labels.map(({ pt: [x, y], ...label }, i) => /* @__PURE__ */ jsx(
24
- AnimatedText,
25
- {
26
- x,
27
- y: y - label.fontSize / 2,
28
- offsetX: 4,
29
- offsetY: 4,
30
- width: springs.width.to((v) => v - x - 4),
31
- fill: "#BABABA",
32
- fontFamily: theme.font,
33
- fontSize: label.fontSize,
34
- fontStyle: label.fontStyle ?? "normal",
35
- letterSpacing: 0.8,
36
- align: label.align,
37
- text: label.text,
38
- wrap: "none",
39
- ellipsis: true,
40
- perfectDrawEnabled: false,
41
- padding: 6,
42
- hitStrokeWidth: 3,
43
- globalCompositeOperation: "luminosity"
44
- },
45
- i
46
- ))
47
- ] });
48
- }
@@ -1,57 +0,0 @@
1
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { useSpring } from "@react-spring/konva";
3
- import { AnimatedEllipse, AnimatedPath } from "../../konva.js";
4
- import { NodeLabels } from "./NodeLabel.js";
5
- import { useShadowSprings } from "../springs.js";
6
- function cylinderSVGPath(diameter, height, tilt = 0.0825) {
7
- const radius = Math.round(diameter / 2);
8
- const rx = radius;
9
- const ry = Math.round(tilt * radius);
10
- const tiltAdjustedHeight = height - 2 * ry;
11
- const path = ` M ${diameter},${ry}
12
- a ${rx},${ry} 0,0,0 ${-diameter} 0
13
- l 0,${tiltAdjustedHeight}
14
- a ${rx},${ry} 0,0,0 ${diameter} 0
15
- l 0,${-tiltAdjustedHeight}
16
- `.replace(/\s+/g, " ").trim();
17
- return {
18
- path,
19
- ry,
20
- rx
21
- };
22
- }
23
- export function CylinderShape({ node, theme, springs, isHovered }) {
24
- const {
25
- size: { width, height }
26
- } = node;
27
- const { path, rx, ry } = cylinderSVGPath(width, height);
28
- const cylinder = useSpring({
29
- to: {
30
- rx,
31
- ry
32
- }
33
- });
34
- return /* @__PURE__ */ jsxs(Fragment, { children: [
35
- /* @__PURE__ */ jsx(
36
- AnimatedPath,
37
- {
38
- ...useShadowSprings(isHovered, theme, springs),
39
- data: path,
40
- perfectDrawEnabled: false,
41
- shadowForStrokeEnabled: false,
42
- fill: springs.fill
43
- }
44
- ),
45
- /* @__PURE__ */ jsx(
46
- AnimatedEllipse,
47
- {
48
- x: cylinder.rx,
49
- y: cylinder.ry,
50
- radiusX: cylinder.rx,
51
- radiusY: cylinder.ry,
52
- fill: springs.stroke
53
- }
54
- ),
55
- /* @__PURE__ */ jsx(NodeLabels, { node, offsetY: -ry * (node.icon ? 1.5 : 0.5), theme })
56
- ] });
57
- }
@@ -1,63 +0,0 @@
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]);
8
- 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
- /* @__PURE__ */ jsx(
21
- AnimatedLine,
22
- {
23
- opacity: springs.opacity,
24
- bezier: true,
25
- dashEnabled: true,
26
- points: points.flat(),
27
- stroke: springs.lineColor,
28
- strokeWidth: springs.lineWidth,
29
- hitStrokeWidth: 20
30
- }
31
- ),
32
- headArrow && /* @__PURE__ */ jsx(
33
- AnimatedLine,
34
- {
35
- opacity: springs.opacity,
36
- points: headArrow.flat(),
37
- closed: true,
38
- fill: springs.lineColor,
39
- stroke: springs.lineColor,
40
- strokeWidth: 2,
41
- hitStrokeWidth: 5
42
- }
43
- ),
44
- labels.map((label, i) => /* @__PURE__ */ jsx(
45
- AnimatedText,
46
- {
47
- x: label.pt[0] - 4,
48
- y: label.pt[1] - label.fontSize / 2 - 4,
49
- opacity: springs.opacity,
50
- padding: 4,
51
- fill: springs.labelColor,
52
- fontFamily: theme.font,
53
- fontSize: label.fontSize,
54
- fontStyle: label.fontStyle ?? "normal",
55
- align: label.align,
56
- text: label.text,
57
- perfectDrawEnabled: false,
58
- hitStrokeWidth: 10
59
- },
60
- i
61
- ))
62
- ] });
63
- }
@@ -1,33 +0,0 @@
1
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { AnimatedRect, Circle } from "../../konva.js";
3
- import { NodeLabels } from "./NodeLabel.js";
4
- import { useShadowSprings } from "../springs.js";
5
- export function MobileShape({ node, theme, springs, isHovered }) {
6
- const colors = theme.colors[node.color];
7
- return /* @__PURE__ */ jsxs(Fragment, { children: [
8
- /* @__PURE__ */ jsx(
9
- AnimatedRect,
10
- {
11
- ...useShadowSprings(isHovered, theme, springs),
12
- cornerRadius: 6,
13
- width: springs.width,
14
- height: springs.height,
15
- fill: springs.stroke
16
- }
17
- ),
18
- /* @__PURE__ */ jsx(Circle, { x: 16, y: node.size.height / 2, radius: 10, fill: colors.fill, listening: false }),
19
- /* @__PURE__ */ jsx(
20
- AnimatedRect,
21
- {
22
- cornerRadius: 4,
23
- x: 31,
24
- y: 12,
25
- width: springs.width.to((w) => w - 43),
26
- height: springs.height.to((h) => h - 24),
27
- fill: springs.fill,
28
- listening: false
29
- }
30
- ),
31
- /* @__PURE__ */ jsx(NodeLabels, { node, theme, offsetX: -6 })
32
- ] });
33
- }
@@ -1,28 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import useImageLoader from "../../hooks/useImageLoader.js";
3
- import { Image } from "../../konva.js";
4
- export function NodeIcon({ icon, maxWidth, maxHeight, offsetX = 0, offsetY = 0 }) {
5
- const [image] = useImageLoader(icon);
6
- if (!image) {
7
- return null;
8
- }
9
- const padding = 16;
10
- const maxIconWidth = Math.round(maxWidth - padding * 2);
11
- const maxIconHeight = Math.round(maxHeight - padding * 2);
12
- const scale = Math.min(maxIconWidth / image.width, maxIconHeight / image.height, 1);
13
- const iconWidth = Math.floor(image.width * scale);
14
- const iconHeight = Math.floor(image.height * scale);
15
- return /* @__PURE__ */ jsx(
16
- Image,
17
- {
18
- image,
19
- x: padding + (maxIconWidth - iconWidth) / 2,
20
- y: padding + (maxIconHeight - iconHeight) / 2,
21
- offsetX,
22
- offsetY,
23
- width: iconWidth,
24
- height: iconHeight,
25
- listening: false
26
- }
27
- );
28
- }
@@ -1,59 +0,0 @@
1
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { Text } from "../../konva.js";
3
- import { NodeIcon } from "./NodeIcon.js";
4
- export function NodeLabels({
5
- node: { icon, labels, size, color },
6
- theme,
7
- offsetX = 0,
8
- offsetY = 0,
9
- maxWidth
10
- }) {
11
- const colors = theme.colors[color];
12
- const width = maxWidth ?? size.width;
13
- const firstLabel = labels[0];
14
- const titleFontSize = firstLabel?.fontSize ?? 12;
15
- let nodeIcon;
16
- if (icon) {
17
- const maxHeight = firstLabel ? Math.floor(firstLabel.pt[1] - firstLabel.fontSize / 2) : size.height;
18
- nodeIcon = /* @__PURE__ */ jsx(
19
- NodeIcon,
20
- {
21
- icon,
22
- maxWidth: width,
23
- maxHeight,
24
- offsetX,
25
- offsetY
26
- }
27
- );
28
- }
29
- return /* @__PURE__ */ jsxs(Fragment, { children: [
30
- nodeIcon,
31
- labels.map((label, i) => {
32
- let color2 = colors.hiContrast;
33
- if (label.fontSize !== titleFontSize) {
34
- color2 = colors.loContrast;
35
- }
36
- return /* @__PURE__ */ jsx(
37
- Text,
38
- {
39
- x: 8,
40
- width: width - 16,
41
- y: label.pt[1],
42
- offsetY: offsetY + label.fontSize / 2,
43
- offsetX,
44
- fill: color2,
45
- fontFamily: theme.font,
46
- fontSize: label.fontSize,
47
- fontStyle: label.fontStyle ?? "normal",
48
- align: "center",
49
- text: label.text,
50
- strokeEnabled: false,
51
- perfectDrawEnabled: false,
52
- listening: false
53
- },
54
- label.text + i
55
- );
56
- })
57
- ] });
58
- }
59
- NodeLabels.displayName = "NodeLabels";
@@ -1,42 +0,0 @@
1
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { useShadowSprings } from "../springs.js";
3
- import { AnimatedPath, AnimatedRect } from "../../konva.js";
4
- import { NodeLabels } from "./NodeLabel.js";
5
- const PersonIcon = {
6
- width: 115,
7
- height: 120,
8
- path: `M57.9197 0C10.9124 0 33.5766 54.75 33.5766 54.75C38.6131 62.25 45.3285 60.75 45.3285 66C45.3285 70.5 39.4526 72 33.5766 72.75C24.3431 72.75 15.9489 71.25 7.55474 84.75C2.51825 93 0 120 0 120H115C115 120 112.482 93 108.285 84.75C99.8905 70.5 91.4963 72.75 82.2628 72C76.3869 71.25 70.5109 69.75 70.5109 65.25C70.5109 60.75 77.2263 62.25 82.2628 54C82.2628 54.75 104.927 0 57.9197 0V0Z`
9
- };
10
- export function PersonShape({ node, theme, springs, isHovered }) {
11
- return /* @__PURE__ */ jsxs(Fragment, { children: [
12
- /* @__PURE__ */ jsx(
13
- AnimatedRect,
14
- {
15
- ...useShadowSprings(isHovered, theme, springs),
16
- cornerRadius: 6,
17
- perfectDrawEnabled: false,
18
- strokeEnabled: false,
19
- width: springs.width,
20
- height: springs.height,
21
- fill: springs.fill
22
- }
23
- ),
24
- /* @__PURE__ */ jsx(
25
- AnimatedPath,
26
- {
27
- x: springs.width.to((v) => v - 8),
28
- y: springs.height,
29
- data: PersonIcon.path,
30
- width: PersonIcon.width,
31
- height: PersonIcon.height,
32
- fill: springs.stroke,
33
- opacity: 0.7,
34
- perfectDrawEnabled: false,
35
- offsetX: PersonIcon.width,
36
- offsetY: PersonIcon.height,
37
- listening: false
38
- }
39
- ),
40
- /* @__PURE__ */ jsx(NodeLabels, { node, theme })
41
- ] });
42
- }
@@ -1,58 +0,0 @@
1
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { useShadowSprings } from "../springs.js";
3
- import { AnimatedEllipse, AnimatedPath } from "../../konva.js";
4
- import { NodeLabels } from "./NodeLabel.js";
5
- import { useSpring } from "@react-spring/konva";
6
- function queueSVGPath(width, height, tilt = 0.2) {
7
- const diameter = height;
8
- const radius = Math.round(diameter / 2);
9
- const ry = radius;
10
- const rx = Math.round(diameter / 2 * tilt);
11
- const tiltAdjustedWidth = width - 2 * rx;
12
- const path = ` M ${rx},0
13
- a ${rx},${ry} 0,0,0 0 ${diameter}
14
- l ${tiltAdjustedWidth},0
15
- a ${rx},${ry} 0,0,0 0 ${-diameter}
16
- `.replace(/\s+/g, " ").trim();
17
- return {
18
- path,
19
- ry,
20
- rx
21
- };
22
- }
23
- export function QueueShape({ node, theme, springs, isHovered }) {
24
- const {
25
- size: { width, height }
26
- } = node;
27
- const { path, rx, ry } = queueSVGPath(width, height);
28
- const props = useSpring({
29
- to: {
30
- x: width - rx,
31
- y: ry,
32
- rx,
33
- ry
34
- }
35
- });
36
- return /* @__PURE__ */ jsxs(Fragment, { children: [
37
- /* @__PURE__ */ jsx(
38
- AnimatedPath,
39
- {
40
- ...useShadowSprings(isHovered, theme, springs),
41
- data: path,
42
- perfectDrawEnabled: false,
43
- fill: springs.fill
44
- }
45
- ),
46
- /* @__PURE__ */ jsx(
47
- AnimatedEllipse,
48
- {
49
- x: props.x,
50
- y: props.y,
51
- radiusX: props.rx,
52
- radiusY: props.ry,
53
- fill: springs.stroke
54
- }
55
- ),
56
- /* @__PURE__ */ jsx(NodeLabels, { node, maxWidth: width - rx * 2, theme })
57
- ] });
58
- }
@@ -1,20 +0,0 @@
1
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { AnimatedRect } from "../../konva.js";
3
- import { NodeLabels } from "./NodeLabel.js";
4
- import { useShadowSprings } from "../springs.js";
5
- export function RectangleShape({ node, theme, springs, isHovered }) {
6
- return /* @__PURE__ */ jsxs(Fragment, { children: [
7
- /* @__PURE__ */ jsx(
8
- AnimatedRect,
9
- {
10
- ...useShadowSprings(isHovered, theme, springs),
11
- cornerRadius: 6,
12
- strokeEnabled: false,
13
- width: springs.width,
14
- height: springs.height,
15
- fill: springs.fill
16
- }
17
- ),
18
- /* @__PURE__ */ jsx(NodeLabels, { node, theme })
19
- ] });
20
- }
@@ -1,7 +0,0 @@
1
- export { CompoundShape } from "./Compound.js";
2
- export { RectangleShape } from "./Rectangle.js";
3
- export { CylinderShape } from "./Cylinder.js";
4
- export { MobileShape } from "./Mobile.js";
5
- export { QueueShape } from "./Queue.js";
6
- export { PersonShape } from "./Person.js";
7
- export { EdgeShape } from "./Edge.js";
File without changes
@@ -1,12 +0,0 @@
1
- export function mousePointer(e) {
2
- const container = e.target.getStage()?.container();
3
- if (container) {
4
- container.style.cursor = "pointer";
5
- }
6
- }
7
- export function mouseDefault(e) {
8
- const container = e.target.getStage()?.container();
9
- if (container) {
10
- container.style.cursor = "auto";
11
- }
12
- }
@@ -1,57 +0,0 @@
1
- import { useSpring } from "@react-spring/konva";
2
- import { scale, toHex } from "khroma";
3
- import { memoize } from "rambdax";
4
- import { useCallback } from "react";
5
- const compoundColor = memoize(
6
- (color, depth) => toHex(
7
- scale(color, {
8
- l: -35 - 5 * depth,
9
- s: -15 - 5 * depth
10
- })
11
- )
12
- );
13
- const isCompound = (node) => {
14
- return node.children.length > 0;
15
- };
16
- function nodeSprings(theme, node) {
17
- const {
18
- position: [x, y],
19
- size: { width, height },
20
- color
21
- } = node;
22
- const colors = theme.colors[color];
23
- const offsetX = Math.round(width / 2);
24
- const offsetY = Math.round(height / 2);
25
- return {
26
- opacity: 1,
27
- scaleX: 1,
28
- scaleY: 1,
29
- x: x + offsetX,
30
- y: y + offsetY,
31
- fill: isCompound(node) ? compoundColor(colors.fill, node.depth ?? 1) : colors.fill,
32
- stroke: isCompound(node) ? compoundColor(colors.stroke, node.depth ?? 1) : colors.stroke,
33
- width,
34
- height,
35
- offsetX,
36
- offsetY
37
- };
38
- }
39
- export const useNodeSpringsFn = (theme) => {
40
- return useCallback((node) => nodeSprings(theme, node), [theme]);
41
- };
42
- export const useShadowSprings = (isHovered = false, theme, springs) => {
43
- const [values] = useSpring(
44
- {
45
- shadowBlur: isHovered ? 30 : 12,
46
- shadowOpacity: isHovered ? 0.5 : 0.35,
47
- shadowOffsetX: 0,
48
- shadowOffsetY: isHovered ? 16 : 4,
49
- shadowColor: theme.shadow
50
- },
51
- [isHovered, theme]
52
- );
53
- return {
54
- shadowEnabled: springs.opacity.to((v) => v > 0.8),
55
- ...values
56
- };
57
- };
@@ -1,71 +0,0 @@
1
- import { atom } from "jotai";
2
- import { equals } from "rambdax";
3
- import { selectAtom } from "jotai/utils";
4
- const currentHoveredNodeAtom = atom(null);
5
- const nodeTimeoutAtom = atom(void 0);
6
- export const hoveredNodeAtom = atom(
7
- (get) => get(currentHoveredNodeAtom),
8
- (get, set, update) => {
9
- clearTimeout(get(nodeTimeoutAtom));
10
- const _prev = get(currentHoveredNodeAtom);
11
- const _next = typeof update === "function" ? update(_prev) : update;
12
- if (equals(_prev, _next)) {
13
- return false;
14
- }
15
- if (_next != null && _prev == null) {
16
- set(
17
- nodeTimeoutAtom,
18
- setTimeout(() => {
19
- set(currentHoveredNodeAtom, _next);
20
- }, 100)
21
- );
22
- return true;
23
- }
24
- if (_next == null && _prev != null) {
25
- set(
26
- nodeTimeoutAtom,
27
- setTimeout(() => {
28
- set(currentHoveredNodeAtom, null);
29
- }, 150)
30
- );
31
- return true;
32
- }
33
- set(currentHoveredNodeAtom, _next);
34
- return true;
35
- }
36
- );
37
- export const hoveredNodeIdAtom = selectAtom(hoveredNodeAtom, (node) => node?.id ?? null);
38
- const currentHoveredEdgeAtom = atom(null);
39
- const edgeTimeoutAtom = atom(void 0);
40
- export const hoveredEdgeAtom = atom(
41
- (get) => get(currentHoveredEdgeAtom),
42
- (get, set, update) => {
43
- clearTimeout(get(edgeTimeoutAtom));
44
- const _prev = get(currentHoveredEdgeAtom);
45
- const _next = typeof update === "function" ? update(_prev) : update;
46
- if (equals(_prev, _next)) {
47
- return false;
48
- }
49
- if (_next != null && _prev == null) {
50
- set(
51
- edgeTimeoutAtom,
52
- setTimeout(() => {
53
- set(currentHoveredEdgeAtom, _next);
54
- }, 100)
55
- );
56
- return true;
57
- }
58
- if (_next == null && _prev != null) {
59
- set(
60
- edgeTimeoutAtom,
61
- setTimeout(() => {
62
- set(currentHoveredEdgeAtom, null);
63
- }, 150)
64
- );
65
- return true;
66
- }
67
- set(currentHoveredEdgeAtom, _next);
68
- return true;
69
- }
70
- );
71
- export const hoveredEdgeIdAtom = selectAtom(hoveredEdgeAtom, (edge) => edge?.id ?? null);
@@ -1,19 +0,0 @@
1
- let _isDragging = false;
2
- let tm;
3
- export const DiagramGesture = {
4
- get isDragging() {
5
- return _isDragging;
6
- },
7
- set isDragging(value) {
8
- clearTimeout(tm);
9
- if (value) {
10
- _isDragging = value;
11
- return;
12
- }
13
- if (_isDragging) {
14
- tm = setTimeout(() => {
15
- _isDragging = false;
16
- }, 100);
17
- }
18
- }
19
- };
@@ -1,28 +0,0 @@
1
- import { useAtom, useAtomValue, useSetAtom } from "jotai";
2
- import { selectAtom } from "jotai/utils";
3
- import { hoveredEdgeAtom, hoveredEdgeIdAtom, hoveredNodeAtom, hoveredNodeIdAtom } from "./atoms.js";
4
- import { useCallback } from "react";
5
- export function useHoveredNode() {
6
- return useAtom(hoveredNodeAtom);
7
- }
8
- export function useHoveredNodeId() {
9
- return useAtomValue(hoveredNodeIdAtom);
10
- }
11
- export function useSetHoveredNode() {
12
- return useSetAtom(hoveredNodeAtom);
13
- }
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
- export function useHoveredEdgeId() {
24
- return useAtomValue(hoveredEdgeIdAtom);
25
- }
26
- export function useSetHoveredEdge() {
27
- return useSetAtom(hoveredEdgeAtom);
28
- }
@@ -1,3 +0,0 @@
1
- export * from "./hooks.js";
2
- export * from "./gestures.js";
3
- export * from "./provider.js";
@@ -1,7 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { Provider, createStore } from "jotai";
3
- import { useState } from "react";
4
- export function DiagramStateProvider({ children }) {
5
- const [store] = useState(() => createStore());
6
- return /* @__PURE__ */ jsx(Provider, { store, children });
7
- }
File without changes