@retikz/core 0.0.1-rc.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 (233) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2 -0
  3. package/dist/es/_virtual/jsx-runtime.js +5 -0
  4. package/dist/es/_virtual/jsx-runtime2.js +4 -0
  5. package/dist/es/_virtual/react-jsx-runtime.development.js +4 -0
  6. package/dist/es/_virtual/react-jsx-runtime.production.js +4 -0
  7. package/dist/es/components/Scope.d.ts +6 -0
  8. package/dist/es/components/Scope.js +10 -0
  9. package/dist/es/components/TikZ.d.ts +9 -0
  10. package/dist/es/components/TikZ.js +12 -0
  11. package/dist/es/components/draw/Draw.d.ts +18 -0
  12. package/dist/es/components/draw/Draw.js +34 -0
  13. package/dist/es/components/draw/InnerDraw.d.ts +13 -0
  14. package/dist/es/components/draw/InnerDraw.js +47 -0
  15. package/dist/es/components/draw/arrow/index.d.ts +9 -0
  16. package/dist/es/components/draw/arrow/index.js +10 -0
  17. package/dist/es/components/draw/arrow/stealth.d.ts +7 -0
  18. package/dist/es/components/draw/arrow/stealth.js +29 -0
  19. package/dist/es/components/draw/arrow/types.d.ts +21 -0
  20. package/dist/es/components/draw/common.d.ts +4 -0
  21. package/dist/es/components/draw/common.js +12 -0
  22. package/dist/es/components/draw/index.d.ts +3 -0
  23. package/dist/es/components/draw/segment/Segment.d.ts +12 -0
  24. package/dist/es/components/draw/segment/Segment.js +41 -0
  25. package/dist/es/components/draw/segment/index.d.ts +19 -0
  26. package/dist/es/components/draw/segment/index.js +41 -0
  27. package/dist/es/components/draw/segment/useArrow.d.ts +12 -0
  28. package/dist/es/components/draw/segment/useArrow.js +52 -0
  29. package/dist/es/components/draw/segment/useConvertWay.d.ts +14 -0
  30. package/dist/es/components/draw/segment/useConvertWay.js +95 -0
  31. package/dist/es/components/draw/types.d.ts +29 -0
  32. package/dist/es/components/node/InnerNode.d.ts +33 -0
  33. package/dist/es/components/node/InnerNode.js +88 -0
  34. package/dist/es/components/node/Node.d.ts +54 -0
  35. package/dist/es/components/node/Node.js +87 -0
  36. package/dist/es/components/node/_hooks/useNodeConfig.d.ts +3 -0
  37. package/dist/es/components/node/_hooks/useNodeConfig.js +13 -0
  38. package/dist/es/components/node/_hooks/useNodeContent.d.ts +4 -0
  39. package/dist/es/components/node/_hooks/useNodeContent.js +27 -0
  40. package/dist/es/components/node/_hooks/useNodeShape.d.ts +4 -0
  41. package/dist/es/components/node/_hooks/useNodeShape.js +34 -0
  42. package/dist/es/components/node/index.d.ts +3 -0
  43. package/dist/es/components/node/index.js +4 -0
  44. package/dist/es/components/pathNode/PathNode.d.ts +39 -0
  45. package/dist/es/components/pathNode/PathNode.js +76 -0
  46. package/dist/es/components/pathNode/index.d.ts +3 -0
  47. package/dist/es/components/pathNode/index.js +4 -0
  48. package/dist/es/components/pathNode/useAnchor.d.ts +6 -0
  49. package/dist/es/components/pathNode/useAnchor.js +49 -0
  50. package/dist/es/container/Group.d.ts +6 -0
  51. package/dist/es/container/Group.js +7 -0
  52. package/dist/es/container/Surface.d.ts +17 -0
  53. package/dist/es/container/Surface.js +23 -0
  54. package/dist/es/elements/Path.d.ts +4 -0
  55. package/dist/es/elements/Path.js +13 -0
  56. package/dist/es/elements/Rect.d.ts +6 -0
  57. package/dist/es/elements/Rect.js +8 -0
  58. package/dist/es/elements/Text.d.ts +19 -0
  59. package/dist/es/elements/Text.js +35 -0
  60. package/dist/es/hooks/context/useCalculate.d.ts +7 -0
  61. package/dist/es/hooks/context/useCalculate.js +9 -0
  62. package/dist/es/hooks/context/useNodes.d.ts +9 -0
  63. package/dist/es/hooks/context/useNodes.js +33 -0
  64. package/dist/es/hooks/context/usePath.d.ts +13 -0
  65. package/dist/es/hooks/context/usePath.js +20 -0
  66. package/dist/es/hooks/context/useScope.d.ts +11 -0
  67. package/dist/es/hooks/context/useScope.js +7 -0
  68. package/dist/es/hooks/useForceUpdate.d.ts +2 -0
  69. package/dist/es/hooks/useForceUpdate.js +8 -0
  70. package/dist/es/index.d.ts +10 -0
  71. package/dist/es/index.js +12 -0
  72. package/dist/es/model/component/node.d.ts +45 -0
  73. package/dist/es/model/component/node.js +164 -0
  74. package/dist/es/model/component/path.d.ts +19 -0
  75. package/dist/es/model/component/path.js +47 -0
  76. package/dist/es/model/equation/line.d.ts +21 -0
  77. package/dist/es/model/equation/line.js +75 -0
  78. package/dist/es/model/geometry/point/DescartesPoint.d.ts +21 -0
  79. package/dist/es/model/geometry/point/DescartesPoint.js +50 -0
  80. package/dist/es/model/geometry/point/PolarPoint.d.ts +14 -0
  81. package/dist/es/model/geometry/point/PolarPoint.js +27 -0
  82. package/dist/es/node_modules/.pnpm/d3-color@3.1.0/node_modules/d3-color/src/color.js +338 -0
  83. package/dist/es/node_modules/.pnpm/d3-color@3.1.0/node_modules/d3-color/src/define.js +13 -0
  84. package/dist/es/node_modules/.pnpm/d3-path@3.1.0/node_modules/d3-path/src/path.js +88 -0
  85. package/dist/es/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/array.js +6 -0
  86. package/dist/es/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/constant.js +8 -0
  87. package/dist/es/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/curve/linear.js +39 -0
  88. package/dist/es/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/line.js +41 -0
  89. package/dist/es/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/path.js +19 -0
  90. package/dist/es/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/point.js +10 -0
  91. package/dist/es/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.development.js +20 -0
  92. package/dist/es/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.production.js +41 -0
  93. package/dist/es/node_modules/.pnpm/react@19.0.0/node_modules/react/jsx-runtime.js +17 -0
  94. package/dist/es/types/coordinate/descartes.d.ts +23 -0
  95. package/dist/es/types/coordinate/index.d.ts +5 -0
  96. package/dist/es/types/coordinate/polar.d.ts +5 -0
  97. package/dist/es/types/distance/index.d.ts +8 -0
  98. package/dist/es/types/distance/sep.d.ts +9 -0
  99. package/dist/es/types/shape/index.d.ts +8 -0
  100. package/dist/es/types/shape/index.js +9 -0
  101. package/dist/es/types/shape/rect.d.ts +25 -0
  102. package/dist/es/types/shape/rect.js +30 -0
  103. package/dist/es/types/svg/font.d.ts +10 -0
  104. package/dist/es/types/svg/stroke.d.ts +10 -0
  105. package/dist/es/types/tikz/index.d.ts +6 -0
  106. package/dist/es/utils/compare.d.ts +4 -0
  107. package/dist/es/utils/compare.js +20 -0
  108. package/dist/es/utils/css.d.ts +6 -0
  109. package/dist/es/utils/css.js +26 -0
  110. package/dist/es/utils/math.d.ts +9 -0
  111. package/dist/es/utils/math.js +26 -0
  112. package/dist/es/utils/string.d.ts +7 -0
  113. package/dist/es/utils/string.js +7 -0
  114. package/dist/es/utils/style/font.d.ts +17 -0
  115. package/dist/es/utils/style/font.js +34 -0
  116. package/dist/es/utils/style/stroke.d.ts +19 -0
  117. package/dist/es/utils/style/stroke.js +40 -0
  118. package/dist/lib/_virtual/jsx-runtime.cjs +5 -0
  119. package/dist/lib/_virtual/jsx-runtime2.cjs +4 -0
  120. package/dist/lib/_virtual/react-jsx-runtime.development.cjs +4 -0
  121. package/dist/lib/_virtual/react-jsx-runtime.production.cjs +4 -0
  122. package/dist/lib/components/Scope.cjs +10 -0
  123. package/dist/lib/components/Scope.d.ts +6 -0
  124. package/dist/lib/components/TikZ.cjs +12 -0
  125. package/dist/lib/components/TikZ.d.ts +9 -0
  126. package/dist/lib/components/draw/Draw.cjs +34 -0
  127. package/dist/lib/components/draw/Draw.d.ts +18 -0
  128. package/dist/lib/components/draw/InnerDraw.cjs +47 -0
  129. package/dist/lib/components/draw/InnerDraw.d.ts +13 -0
  130. package/dist/lib/components/draw/arrow/index.cjs +10 -0
  131. package/dist/lib/components/draw/arrow/index.d.ts +9 -0
  132. package/dist/lib/components/draw/arrow/stealth.cjs +29 -0
  133. package/dist/lib/components/draw/arrow/stealth.d.ts +7 -0
  134. package/dist/lib/components/draw/arrow/types.d.ts +21 -0
  135. package/dist/lib/components/draw/common.cjs +12 -0
  136. package/dist/lib/components/draw/common.d.ts +4 -0
  137. package/dist/lib/components/draw/index.d.ts +3 -0
  138. package/dist/lib/components/draw/segment/Segment.cjs +41 -0
  139. package/dist/lib/components/draw/segment/Segment.d.ts +12 -0
  140. package/dist/lib/components/draw/segment/index.cjs +41 -0
  141. package/dist/lib/components/draw/segment/index.d.ts +19 -0
  142. package/dist/lib/components/draw/segment/useArrow.cjs +52 -0
  143. package/dist/lib/components/draw/segment/useArrow.d.ts +12 -0
  144. package/dist/lib/components/draw/segment/useConvertWay.cjs +95 -0
  145. package/dist/lib/components/draw/segment/useConvertWay.d.ts +14 -0
  146. package/dist/lib/components/draw/types.d.ts +29 -0
  147. package/dist/lib/components/node/InnerNode.cjs +88 -0
  148. package/dist/lib/components/node/InnerNode.d.ts +33 -0
  149. package/dist/lib/components/node/Node.cjs +87 -0
  150. package/dist/lib/components/node/Node.d.ts +54 -0
  151. package/dist/lib/components/node/_hooks/useNodeConfig.cjs +13 -0
  152. package/dist/lib/components/node/_hooks/useNodeConfig.d.ts +3 -0
  153. package/dist/lib/components/node/_hooks/useNodeContent.cjs +27 -0
  154. package/dist/lib/components/node/_hooks/useNodeContent.d.ts +4 -0
  155. package/dist/lib/components/node/_hooks/useNodeShape.cjs +34 -0
  156. package/dist/lib/components/node/_hooks/useNodeShape.d.ts +4 -0
  157. package/dist/lib/components/node/index.cjs +4 -0
  158. package/dist/lib/components/node/index.d.ts +3 -0
  159. package/dist/lib/components/pathNode/PathNode.cjs +76 -0
  160. package/dist/lib/components/pathNode/PathNode.d.ts +39 -0
  161. package/dist/lib/components/pathNode/index.cjs +4 -0
  162. package/dist/lib/components/pathNode/index.d.ts +3 -0
  163. package/dist/lib/components/pathNode/useAnchor.cjs +49 -0
  164. package/dist/lib/components/pathNode/useAnchor.d.ts +6 -0
  165. package/dist/lib/container/Group.cjs +7 -0
  166. package/dist/lib/container/Group.d.ts +6 -0
  167. package/dist/lib/container/Surface.cjs +23 -0
  168. package/dist/lib/container/Surface.d.ts +17 -0
  169. package/dist/lib/elements/Path.cjs +13 -0
  170. package/dist/lib/elements/Path.d.ts +4 -0
  171. package/dist/lib/elements/Rect.cjs +8 -0
  172. package/dist/lib/elements/Rect.d.ts +6 -0
  173. package/dist/lib/elements/Text.cjs +35 -0
  174. package/dist/lib/elements/Text.d.ts +19 -0
  175. package/dist/lib/hooks/context/useCalculate.cjs +9 -0
  176. package/dist/lib/hooks/context/useCalculate.d.ts +7 -0
  177. package/dist/lib/hooks/context/useNodes.cjs +33 -0
  178. package/dist/lib/hooks/context/useNodes.d.ts +9 -0
  179. package/dist/lib/hooks/context/usePath.cjs +20 -0
  180. package/dist/lib/hooks/context/usePath.d.ts +13 -0
  181. package/dist/lib/hooks/context/useScope.cjs +7 -0
  182. package/dist/lib/hooks/context/useScope.d.ts +11 -0
  183. package/dist/lib/hooks/useForceUpdate.cjs +8 -0
  184. package/dist/lib/hooks/useForceUpdate.d.ts +2 -0
  185. package/dist/lib/index.cjs +12 -0
  186. package/dist/lib/index.d.ts +10 -0
  187. package/dist/lib/model/component/node.cjs +164 -0
  188. package/dist/lib/model/component/node.d.ts +45 -0
  189. package/dist/lib/model/component/path.cjs +47 -0
  190. package/dist/lib/model/component/path.d.ts +19 -0
  191. package/dist/lib/model/equation/line.cjs +75 -0
  192. package/dist/lib/model/equation/line.d.ts +21 -0
  193. package/dist/lib/model/geometry/point/DescartesPoint.cjs +50 -0
  194. package/dist/lib/model/geometry/point/DescartesPoint.d.ts +21 -0
  195. package/dist/lib/model/geometry/point/PolarPoint.cjs +27 -0
  196. package/dist/lib/model/geometry/point/PolarPoint.d.ts +14 -0
  197. package/dist/lib/node_modules/.pnpm/d3-color@3.1.0/node_modules/d3-color/src/color.cjs +338 -0
  198. package/dist/lib/node_modules/.pnpm/d3-color@3.1.0/node_modules/d3-color/src/define.cjs +13 -0
  199. package/dist/lib/node_modules/.pnpm/d3-path@3.1.0/node_modules/d3-path/src/path.cjs +88 -0
  200. package/dist/lib/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/array.cjs +6 -0
  201. package/dist/lib/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/constant.cjs +8 -0
  202. package/dist/lib/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/curve/linear.cjs +39 -0
  203. package/dist/lib/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/line.cjs +41 -0
  204. package/dist/lib/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/path.cjs +19 -0
  205. package/dist/lib/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/point.cjs +10 -0
  206. package/dist/lib/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.development.cjs +20 -0
  207. package/dist/lib/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.production.cjs +41 -0
  208. package/dist/lib/node_modules/.pnpm/react@19.0.0/node_modules/react/jsx-runtime.cjs +17 -0
  209. package/dist/lib/types/coordinate/descartes.d.ts +23 -0
  210. package/dist/lib/types/coordinate/index.d.ts +5 -0
  211. package/dist/lib/types/coordinate/polar.d.ts +5 -0
  212. package/dist/lib/types/distance/index.d.ts +8 -0
  213. package/dist/lib/types/distance/sep.d.ts +9 -0
  214. package/dist/lib/types/shape/index.cjs +9 -0
  215. package/dist/lib/types/shape/index.d.ts +8 -0
  216. package/dist/lib/types/shape/rect.cjs +30 -0
  217. package/dist/lib/types/shape/rect.d.ts +25 -0
  218. package/dist/lib/types/svg/font.d.ts +10 -0
  219. package/dist/lib/types/svg/stroke.d.ts +10 -0
  220. package/dist/lib/types/tikz/index.d.ts +6 -0
  221. package/dist/lib/utils/compare.cjs +20 -0
  222. package/dist/lib/utils/compare.d.ts +4 -0
  223. package/dist/lib/utils/css.cjs +26 -0
  224. package/dist/lib/utils/css.d.ts +6 -0
  225. package/dist/lib/utils/math.cjs +26 -0
  226. package/dist/lib/utils/math.d.ts +9 -0
  227. package/dist/lib/utils/string.cjs +7 -0
  228. package/dist/lib/utils/string.d.ts +7 -0
  229. package/dist/lib/utils/style/font.cjs +34 -0
  230. package/dist/lib/utils/style/font.d.ts +17 -0
  231. package/dist/lib/utils/style/stroke.cjs +40 -0
  232. package/dist/lib/utils/style/stroke.d.ts +19 -0
  233. package/package.json +57 -0
@@ -0,0 +1,33 @@
1
+ import { FC, ReactNode } from 'react';
2
+ import { Position } from '../../types/coordinate/descartes';
3
+ import { StrokeProps } from '../../types/svg/stroke';
4
+ import { TikZProps } from '../../types/tikz';
5
+ import { DirectionDistance } from '../../types/distance';
6
+ import { FontProps } from '../../types/svg/font';
7
+ /** 节点外边框形状 */
8
+ export type NodeShape = 'rectangle';
9
+ /** 外层形状相关属性 */
10
+ export type ShapeProps = {
11
+ shape: NodeShape;
12
+ rx?: number | string;
13
+ ry?: number | string;
14
+ fill?: string;
15
+ fillOpacity?: number;
16
+ } & StrokeProps;
17
+ /** 内容相关属性 */
18
+ export type ContentProps = {
19
+ color: string;
20
+ opacity?: number;
21
+ children?: ReactNode;
22
+ size?: string | number;
23
+ } & FontProps;
24
+ export type InnerNodeProps = {
25
+ position: Position;
26
+ width?: number;
27
+ height?: number;
28
+ innerSep: DirectionDistance<number | string>;
29
+ outerSep: DirectionDistance<number | string>;
30
+ rotate?: number;
31
+ } & TikZProps & ContentProps & ShapeProps;
32
+ declare const InnerNode: FC<InnerNodeProps>;
33
+ export default InnerNode;
@@ -0,0 +1,88 @@
1
+ import { j as jsxRuntimeExports } from "../../_virtual/jsx-runtime.js";
2
+ import { useRef, useLayoutEffect } from "react";
3
+ import Group from "../../container/Group.js";
4
+ import useNodeShape from "./_hooks/useNodeShape.js";
5
+ import useNodeContent from "./_hooks/useNodeContent.js";
6
+ import useNodeConfig from "./_hooks/useNodeConfig.js";
7
+ import { convertCssToPx } from "../../utils/css.js";
8
+ import useNodes from "../../hooks/context/useNodes.js";
9
+ import useCalculate from "../../hooks/context/useCalculate.js";
10
+ import { convertPrecision } from "../../utils/math.js";
11
+ const InnerNode = (props) => {
12
+ const { name, ref, position, width, height, innerSep, outerSep, rotate } = props;
13
+ const nodeRef = useRef(null);
14
+ const shapeRef = useRef(null);
15
+ const contentRef = useRef(null);
16
+ const { getModel, updateModel, deleteModel } = useNodes();
17
+ const { precision } = useCalculate();
18
+ const nodeConfig = useNodeConfig();
19
+ nodeConfig.current.position = position;
20
+ if (name && !getModel(name)) {
21
+ updateModel(name, nodeConfig.current, false);
22
+ }
23
+ const groupElement = ref && "current" in ref ? ref.current : nodeRef.current;
24
+ useLayoutEffect(() => {
25
+ const contentElement = contentRef.current;
26
+ if (!contentElement) return;
27
+ const { width: elementWidth, height: elementHeight } = contentElement.getBoundingClientRect();
28
+ nodeConfig.current.contentSize = [Math.max(elementWidth, width || 0), Math.max(elementHeight, height || 0)];
29
+ });
30
+ const getSep = (sep) => {
31
+ const { width: width2 = 100, height: height2 = 100 } = (groupElement == null ? void 0 : groupElement.getBoundingClientRect()) || {};
32
+ const remPx = parseFloat(getComputedStyle(document.documentElement).fontSize);
33
+ const emPx = groupElement ? parseFloat(getComputedStyle(groupElement).fontSize) : remPx;
34
+ return {
35
+ left: convertCssToPx(sep.left, { remPx, emPx, parentPx: width2 }),
36
+ right: convertCssToPx(sep.right, { remPx, emPx, parentPx: width2 }),
37
+ top: convertCssToPx(sep.top, { remPx, emPx, parentPx: height2 }),
38
+ bottom: convertCssToPx(sep.bottom, { remPx, emPx, parentPx: height2 })
39
+ };
40
+ };
41
+ useLayoutEffect(() => {
42
+ nodeConfig.current.innerSep = getSep(innerSep);
43
+ }, [innerSep]);
44
+ useLayoutEffect(() => {
45
+ nodeConfig.current.outerSep = getSep(outerSep);
46
+ }, [outerSep]);
47
+ useLayoutEffect(() => {
48
+ var _a, _b, _c, _d;
49
+ const {
50
+ contentSize: [width2, height2],
51
+ innerSep: innerSep2
52
+ } = nodeConfig.current;
53
+ const realX = -width2 / 2 - innerSep2.left;
54
+ (_a = shapeRef.current) == null ? void 0 : _a.setAttribute("x", convertPrecision(realX, precision).toString());
55
+ const realY = -height2 / 2 - innerSep2.top;
56
+ (_b = shapeRef.current) == null ? void 0 : _b.setAttribute("y", convertPrecision(realY, precision).toString());
57
+ const realWidth = width2 + innerSep2.left + innerSep2.right;
58
+ (_c = shapeRef.current) == null ? void 0 : _c.setAttribute("width", convertPrecision(realWidth, precision).toString());
59
+ const realHeight = height2 + innerSep2.top + innerSep2.bottom;
60
+ (_d = shapeRef.current) == null ? void 0 : _d.setAttribute("height", convertPrecision(realHeight, precision).toString());
61
+ }, [nodeConfig.current.position, nodeConfig.current.contentSize, nodeConfig.current.innerSep]);
62
+ useLayoutEffect(() => {
63
+ if (name) updateModel(name, nodeConfig.current);
64
+ });
65
+ useLayoutEffect(
66
+ () => () => {
67
+ if (name) {
68
+ deleteModel(name);
69
+ }
70
+ },
71
+ [name]
72
+ );
73
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(
74
+ Group,
75
+ {
76
+ ref: ref || nodeRef,
77
+ id: name,
78
+ transform: `translate(${position[0]}, ${position[1]}) ${rotate ? `rotate(${rotate})` : ""}`,
79
+ children: [
80
+ useNodeShape(props, shapeRef),
81
+ useNodeContent(props, contentRef)
82
+ ]
83
+ }
84
+ );
85
+ };
86
+ export {
87
+ InnerNode as default
88
+ };
@@ -0,0 +1,54 @@
1
+ import { FC, ReactNode, Ref } from 'react';
2
+ import { NodeShape } from './InnerNode';
3
+ import { CssDistanceType } from '../../types/distance';
4
+ import { SepProps } from '../../types/distance/sep';
5
+ import { StrokeProps } from '../../types/svg/stroke';
6
+ import { TikZKey } from '../../types/tikz';
7
+ import { StrokeShortcutProps, StrokeType } from '../../utils/style/stroke';
8
+ import { PointPosition } from '../../types/coordinate';
9
+ import { TikZFontSize } from '../../utils/style/font';
10
+ import { FontProps } from '../../types/svg/font';
11
+ export type NodeProps = {
12
+ name?: TikZKey;
13
+ ref?: Ref<SVGGElement>;
14
+ /** 位置 */
15
+ position?: PointPosition;
16
+ /** 位置偏移 */
17
+ offset?: PointPosition;
18
+ /** 内容宽度 */
19
+ width?: CssDistanceType;
20
+ /** 内容高度 */
21
+ height?: CssDistanceType;
22
+ /** 内容(文本)颜色 */
23
+ color?: 'currentColor' | 'auto' | string;
24
+ /** 内容(文本)透明度 */
25
+ opacity?: number;
26
+ /** 内容(文本)字体大小 */
27
+ size?: string | TikZFontSize | number;
28
+ /** 内容 */
29
+ children?: ReactNode;
30
+ /** 边框形状 */
31
+ shape?: NodeShape;
32
+ /** 边框圆角 */
33
+ r?: CssDistanceType;
34
+ /** 边框圆角-x */
35
+ rx?: CssDistanceType;
36
+ /** 边框圆角-y */
37
+ ry?: CssDistanceType;
38
+ /** 背景填充色,默认为 auto */
39
+ fill?: string | 'auto';
40
+ /** 背景填充色透明度 */
41
+ fillOpacity?: number;
42
+ /** 边框样式 */
43
+ strokeType?: StrokeType;
44
+ /** 内边距 */
45
+ innerSep?: CssDistanceType | SepProps;
46
+ /** 外边距 */
47
+ outerSep?: CssDistanceType | SepProps;
48
+ /** 旋转 */
49
+ rotate?: number;
50
+ /** 样式 */
51
+ style?: 'bold' | 'italic' | 'serif' | 'sans-serif';
52
+ } & Partial<FontProps> & Partial<StrokeProps> & StrokeShortcutProps;
53
+ declare const Node: FC<NodeProps>;
54
+ export default Node;
@@ -0,0 +1,87 @@
1
+ import { j as jsxRuntimeExports } from "../../_virtual/jsx-runtime.js";
2
+ import { useMemo } from "react";
3
+ import InnerNode from "./InnerNode.js";
4
+ import { convertCssToPx } from "../../utils/css.js";
5
+ import { convertStrokeType, convertStrokeShortcut } from "../../utils/style/stroke.js";
6
+ import { convertFontSize, convertFontStyle } from "../../utils/style/font.js";
7
+ import DescartesPoint from "../../model/geometry/point/DescartesPoint.js";
8
+ import useScope from "../../hooks/context/useScope.js";
9
+ import color, { hsl } from "../../node_modules/.pnpm/d3-color@3.1.0/node_modules/d3-color/src/color.js";
10
+ const Node = (props) => {
11
+ const { offset: scopeOffset, node } = useScope();
12
+ const nodeScopeProps = { offset: scopeOffset, ...node };
13
+ const realProps = {
14
+ ...nodeScopeProps,
15
+ ...props,
16
+ offset: DescartesPoint.plus(scopeOffset || [0, 0], props.offset || [0, 0])
17
+ };
18
+ const { shape = "rectangle", width, height, position, offset, innerSep, outerSep, ...res1Props } = realProps;
19
+ const { r, rx, ry, fill, fillOpacity, stroke = "transparent", strokeWidth = 1, strokeType, ...res2Props } = res1Props;
20
+ const { color: color$1 = "currentColor", size, fontSize, fontStyle, fontFamily, style, ...otherProps } = res2Props;
21
+ const realPosition = useMemo(() => {
22
+ const formatPosition = position ? DescartesPoint.formatPosition(position) : [0, 0];
23
+ const formatOffset = offset ? DescartesPoint.formatPosition(offset) : [0, 0];
24
+ return [formatPosition[0] + formatOffset[0], formatPosition[1] + formatOffset[1]];
25
+ }, [position]);
26
+ const realColor = useMemo(() => {
27
+ if (color$1 === "auto" && fill && fill !== "currentColor") {
28
+ const fillColor = color(fill);
29
+ if (!fillColor) return color$1 || "currentColor";
30
+ fillColor.opacity = fillOpacity || 1;
31
+ const lightness = hsl(fillColor).l;
32
+ return lightness < 0.5 ? "white" : "black";
33
+ }
34
+ return color$1 || "currentColor";
35
+ }, [color$1, fill, fillOpacity]);
36
+ const realRx = rx || r;
37
+ const realRy = ry || r;
38
+ const getStrokeAttributes = () => strokeType ? convertStrokeType(strokeType, strokeWidth) : convertStrokeShortcut(otherProps, strokeWidth);
39
+ const getSep = (sep, defaultVal) => {
40
+ if (typeof sep !== "object") {
41
+ return {
42
+ left: sep ?? defaultVal,
43
+ right: sep ?? defaultVal,
44
+ top: sep ?? defaultVal,
45
+ bottom: sep ?? defaultVal
46
+ };
47
+ }
48
+ return {
49
+ left: sep.left ?? sep.x ?? defaultVal,
50
+ right: sep.right ?? sep.x ?? defaultVal,
51
+ top: sep.top ?? sep.y ?? defaultVal,
52
+ bottom: sep.bottom ?? sep.y ?? defaultVal
53
+ };
54
+ };
55
+ const getFontStyle = () => convertFontStyle(style);
56
+ const adjustFontSize = useMemo(() => convertFontSize(size || fontSize), [size, fontSize]);
57
+ const adjustedInnerSep = useMemo(
58
+ () => getSep(innerSep, convertCssToPx(adjustFontSize) / 3 || "0.3333em"),
59
+ [innerSep]
60
+ );
61
+ const adjustedOuterSep = useMemo(() => getSep(outerSep, 0), [outerSep]);
62
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
63
+ InnerNode,
64
+ {
65
+ width: convertCssToPx(width),
66
+ height: convertCssToPx(height),
67
+ shape,
68
+ position: realPosition,
69
+ color: realColor,
70
+ fill: fill || "transparent",
71
+ fillOpacity,
72
+ rx: realRx,
73
+ ry: realRy,
74
+ stroke,
75
+ strokeWidth,
76
+ innerSep: adjustedInnerSep,
77
+ outerSep: adjustedOuterSep,
78
+ size: adjustFontSize,
79
+ ...getFontStyle(),
80
+ ...getStrokeAttributes(),
81
+ ...otherProps
82
+ }
83
+ );
84
+ };
85
+ export {
86
+ Node as default
87
+ };
@@ -0,0 +1,3 @@
1
+ import { NodeConfig } from '../../../model/component/node';
2
+ declare const useNodeConfig: () => import('react').RefObject<NodeConfig>;
3
+ export default useNodeConfig;
@@ -0,0 +1,13 @@
1
+ import { useRef } from "react";
2
+ const useNodeConfig = () => {
3
+ const configRef = useRef({
4
+ position: [0, 0],
5
+ contentSize: [0, 0],
6
+ innerSep: { left: 0, right: 0, top: 0, bottom: 0 },
7
+ outerSep: { left: 0, right: 0, top: 0, bottom: 0 }
8
+ });
9
+ return configRef;
10
+ };
11
+ export {
12
+ useNodeConfig as default
13
+ };
@@ -0,0 +1,4 @@
1
+ import { Ref } from 'react';
2
+ import { ContentProps } from '../InnerNode';
3
+ declare const useNodeContent: (props: ContentProps, ref: Ref<SVGElement>) => import("react/jsx-runtime").JSX.Element | null;
4
+ export default useNodeContent;
@@ -0,0 +1,27 @@
1
+ import { j as jsxRuntimeExports } from "../../../_virtual/jsx-runtime.js";
2
+ import { isValidElement, useMemo, cloneElement } from "react";
3
+ import Text from "../../../elements/Text.js";
4
+ const useNodeContent = (props, ref) => {
5
+ const { color, size, opacity, fontWeight, fontStyle, fontFamily, fontStretch, children } = props;
6
+ const isTextNode = children !== null && !isValidElement(children);
7
+ return useMemo(
8
+ () => isTextNode ? /* @__PURE__ */ jsxRuntimeExports.jsx(
9
+ Text,
10
+ {
11
+ fill: color,
12
+ fontSize: size,
13
+ fillOpacity: opacity,
14
+ fontWeight,
15
+ fontStyle,
16
+ fontFamily,
17
+ fontStretch,
18
+ ref,
19
+ children
20
+ }
21
+ ) : isValidElement(children) ? cloneElement(children, { ref }) : children,
22
+ isTextNode ? [color, size, children] : [children]
23
+ );
24
+ };
25
+ export {
26
+ useNodeContent as default
27
+ };
@@ -0,0 +1,4 @@
1
+ import { Ref } from 'react';
2
+ import { ShapeProps } from '../InnerNode';
3
+ declare const useNodeShape: (props: ShapeProps, ref: Ref<SVGGraphicsElement>) => import("react/jsx-runtime").JSX.Element;
4
+ export default useNodeShape;
@@ -0,0 +1,34 @@
1
+ import { j as jsxRuntimeExports } from "../../../_virtual/jsx-runtime.js";
2
+ import { useMemo } from "react";
3
+ import Rect from "../../../elements/Rect.js";
4
+ const getShapeProps = (nodeProps) => {
5
+ const { rx, ry, fill, fillOpacity, stroke, strokeWidth, strokeOpacity } = nodeProps;
6
+ const { strokeDasharray, strokeDashoffset, strokeLinecap, strokeLinejoin, strokeMiterlimit } = nodeProps;
7
+ return {
8
+ rx,
9
+ ry,
10
+ fill,
11
+ fillOpacity,
12
+ stroke,
13
+ strokeWidth,
14
+ strokeOpacity,
15
+ strokeDasharray,
16
+ strokeDashoffset,
17
+ strokeLinecap,
18
+ strokeLinejoin,
19
+ strokeMiterlimit
20
+ };
21
+ };
22
+ const useNodeShape = (props, ref) => {
23
+ const shapeProps = getShapeProps(props);
24
+ const Shape = useMemo(() => {
25
+ switch (props.shape) {
26
+ case "rectangle":
27
+ return Rect;
28
+ }
29
+ }, [props.shape, ...Object.values(shapeProps)]);
30
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(Shape, { ref, ...shapeProps });
31
+ };
32
+ export {
33
+ useNodeShape as default
34
+ };
@@ -0,0 +1,3 @@
1
+ import { default as Node } from './Node';
2
+ export type { NodeProps } from './Node';
3
+ export default Node;
@@ -0,0 +1,4 @@
1
+ import Node from "./Node.js";
2
+ export {
3
+ Node as default
4
+ };
@@ -0,0 +1,39 @@
1
+ import { FC } from 'react';
2
+ import { Direction } from '../../types/coordinate';
3
+ import { Position } from '../../types/coordinate/descartes';
4
+ import { NodeProps } from '../node/Node';
5
+ type PathNodePositionProps = {
6
+ left?: boolean | number | string;
7
+ right?: boolean | number | string;
8
+ above?: boolean | number | string;
9
+ below?: boolean | number | string;
10
+ };
11
+ type PosShortcutProps = {
12
+ /** pos: 0 */
13
+ start?: boolean;
14
+ /** pos: 0.125 */
15
+ veryNearStart?: boolean;
16
+ /** pos: 0.25 */
17
+ nearStart?: boolean;
18
+ /** pos: 0.5 */
19
+ midway?: boolean;
20
+ /** pos: 0.75 */
21
+ nearEnd?: boolean;
22
+ /** pos: 0.875 */
23
+ veryNearEnd?: boolean;
24
+ /** pos: 1 */
25
+ end?: boolean;
26
+ };
27
+ export type PathNodeProps = {
28
+ segmentIndex?: number;
29
+ /** path 片段的下标 */
30
+ pos?: number;
31
+ /** 相对于路径的位置 */
32
+ anchor?: Direction | 'center';
33
+ /** 偏移位置 */
34
+ offset?: Position;
35
+ /** 跟随箭头位置 */
36
+ sloped?: boolean;
37
+ } & PathNodePositionProps & PosShortcutProps & Omit<NodeProps, 'position'>;
38
+ declare const PathNode: FC<PathNodeProps>;
39
+ export default PathNode;
@@ -0,0 +1,76 @@
1
+ import { j as jsxRuntimeExports } from "../../_virtual/jsx-runtime.js";
2
+ import { useId, useMemo, useState, useLayoutEffect } from "react";
3
+ import useCalculate from "../../hooks/context/useCalculate.js";
4
+ import useNodes from "../../hooks/context/useNodes.js";
5
+ import useScope, { ScopeContext } from "../../hooks/context/useScope.js";
6
+ import DescartesPoint from "../../model/geometry/point/DescartesPoint.js";
7
+ import { convertCssToPx } from "../../utils/css.js";
8
+ import { convertPrecision } from "../../utils/math.js";
9
+ import Node from "../node/Node.js";
10
+ import useAnchor from "./useAnchor.js";
11
+ const PathNode = (props) => {
12
+ const { segmentIndex = -1, offset = [0, 0], anchor, ref, left, right, above, below, name, ...resProps } = props;
13
+ const { pos, veryNearStart, veryNearEnd, start, nearStart, midway, nearEnd, end, sloped, ...nodeProps } = resProps;
14
+ const id = useId();
15
+ const realName = name ?? id;
16
+ const { precision } = useCalculate();
17
+ const posRadio = useMemo(() => {
18
+ if (pos !== void 0) return pos;
19
+ if (start) return 0;
20
+ if (veryNearStart) return 0.125;
21
+ if (nearStart) return 0.25;
22
+ if (midway) return 0.5;
23
+ if (nearEnd) return 0.75;
24
+ if (veryNearEnd) return 0.875;
25
+ return 1;
26
+ }, [pos, veryNearStart, veryNearEnd, start, nearStart, midway, nearEnd, end]);
27
+ const directionPos = useMemo(() => {
28
+ if (left) return { direction: "left", distance: typeof left === "boolean" ? 0 : convertCssToPx(left) };
29
+ if (right) return { direction: "right", distance: typeof right === "boolean" ? 0 : convertCssToPx(right) };
30
+ if (above) return { direction: "top", distance: typeof above === "boolean" ? 0 : convertCssToPx(above) };
31
+ if (below) return { direction: "bottom", distance: typeof below === "boolean" ? 0 : convertCssToPx(below) };
32
+ return { direction: anchor ?? "center", distance: 0 };
33
+ }, [anchor, left, right, above, below]);
34
+ const { position: anchorPosition, angle: anchorAngle } = useAnchor(posRadio, segmentIndex);
35
+ const [adjustOffset, setAdjustOffset] = useState(DescartesPoint.plus(anchorPosition, offset));
36
+ const { getModel } = useNodes();
37
+ const rotate = useMemo(() => {
38
+ if (!sloped) return 0;
39
+ return anchorAngle * (180 / Math.PI);
40
+ }, [sloped, anchorAngle]);
41
+ useLayoutEffect(() => {
42
+ const model = getModel(realName);
43
+ if (!model || !model.init) return;
44
+ const { direction, distance } = directionPos;
45
+ let directionPosition = [0, 0];
46
+ switch (direction) {
47
+ case "left":
48
+ directionPosition = [-(model == null ? void 0 : model.getOuterDistance("left")) - distance, 0];
49
+ break;
50
+ case "right":
51
+ directionPosition = [(model == null ? void 0 : model.getOuterDistance("right")) + distance, 0];
52
+ break;
53
+ case "top":
54
+ directionPosition = [0, -(model == null ? void 0 : model.getOuterDistance("top")) - distance];
55
+ break;
56
+ case "bottom":
57
+ directionPosition = [0, (model == null ? void 0 : model.getOuterDistance("bottom")) + distance];
58
+ break;
59
+ }
60
+ setAdjustOffset(DescartesPoint.plus(anchorPosition, directionPosition, offset));
61
+ }, [anchorPosition, directionPos]);
62
+ const scope = useScope();
63
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(ScopeContext, { value: { ...scope, offset: [0, 0] }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
64
+ Node,
65
+ {
66
+ name: realName,
67
+ position: convertPrecision(adjustOffset, precision),
68
+ ref,
69
+ rotate,
70
+ ...nodeProps
71
+ }
72
+ ) });
73
+ };
74
+ export {
75
+ PathNode as default
76
+ };
@@ -0,0 +1,3 @@
1
+ import { default as PathNode } from './PathNode';
2
+ export type { PathNodeProps } from './PathNode';
3
+ export default PathNode;
@@ -0,0 +1,4 @@
1
+ import PathNode from "./PathNode.js";
2
+ export {
3
+ PathNode as default
4
+ };
@@ -0,0 +1,6 @@
1
+ import { Position } from '../../types/coordinate/descartes';
2
+ declare const useAnchor: (pos: number, segmentIndex: number) => {
3
+ position: Position;
4
+ angle: number;
5
+ };
6
+ export default useAnchor;
@@ -0,0 +1,49 @@
1
+ import { useRef, useLayoutEffect, useMemo } from "react";
2
+ import useCalculate from "../../hooks/context/useCalculate.js";
3
+ import usePath from "../../hooks/context/usePath.js";
4
+ import useForceUpdate from "../../hooks/useForceUpdate.js";
5
+ import Line from "../../model/equation/line.js";
6
+ import { between, convertPrecision } from "../../utils/math.js";
7
+ const useAnchor = (pos, segmentIndex) => {
8
+ const pathUpdateCount = useRef(0);
9
+ const forceUpdate = useForceUpdate();
10
+ const { model, subscribeModel } = usePath();
11
+ const { precision } = useCalculate();
12
+ const subscribeCb = subscribeModel((model2) => {
13
+ if (!(model2 == null ? void 0 : model2.init)) return;
14
+ pathUpdateCount.current += 1;
15
+ queueMicrotask(forceUpdate);
16
+ });
17
+ useLayoutEffect(() => () => {
18
+ subscribeCb == null ? void 0 : subscribeCb();
19
+ });
20
+ const adjustIndex = segmentIndex >= 0 ? segmentIndex : model.ways.length + segmentIndex;
21
+ if (!between(adjustIndex, [0, model.ways.length - 1], true)) throw new Error("segmentIndex is out of range");
22
+ return useMemo(() => {
23
+ if (!model.init)
24
+ return {
25
+ position: [Number.MAX_SAFE_INTEGER / 2, Number.MAX_SAFE_INTEGER / 2],
26
+ angle: 0
27
+ };
28
+ const way = model.ways[adjustIndex];
29
+ const waySegments = way.length - 1;
30
+ const segmentPercent = 1 / waySegments;
31
+ let segmentSum = 0;
32
+ let index = 0;
33
+ while (pos >= segmentSum) {
34
+ segmentSum += segmentPercent;
35
+ index++;
36
+ }
37
+ const startPoint = way[index - 1];
38
+ const endPoint = way[index];
39
+ const percent = pos % segmentPercent / segmentPercent;
40
+ const position = index === way.length ? startPoint : Line.getPositionByPercent(startPoint, endPoint, percent);
41
+ return {
42
+ position: convertPrecision(position, precision),
43
+ angle: index === way.length ? Line.getDegree(way[way.length - 2], way[way.length - 1]) : Line.getDegree(startPoint, endPoint)
44
+ };
45
+ }, [pos, segmentIndex, pathUpdateCount.current]);
46
+ };
47
+ export {
48
+ useAnchor as default
49
+ };
@@ -0,0 +1,6 @@
1
+ import { FC, PropsWithChildren, Ref, SVGProps } from 'react';
2
+ export type GroupProps = {
3
+ ref?: Ref<SVGGElement>;
4
+ } & SVGProps<SVGGElement>;
5
+ declare const Group: FC<PropsWithChildren<GroupProps>>;
6
+ export default Group;
@@ -0,0 +1,7 @@
1
+ import { j as jsxRuntimeExports } from "../_virtual/jsx-runtime.js";
2
+ const Group = (props) => {
3
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("g", { ...props });
4
+ };
5
+ export {
6
+ Group as default
7
+ };
@@ -0,0 +1,17 @@
1
+ import { CSSProperties, FC, PropsWithChildren } from 'react';
2
+ export type SurfaceProps = {
3
+ title?: string;
4
+ desc?: string;
5
+ width?: string | number;
6
+ height?: string | number;
7
+ viewBox?: {
8
+ x?: number;
9
+ y?: number;
10
+ width?: number;
11
+ height?: number;
12
+ };
13
+ className?: string;
14
+ style?: CSSProperties;
15
+ };
16
+ declare const Surface: FC<PropsWithChildren<SurfaceProps>>;
17
+ export default Surface;
@@ -0,0 +1,23 @@
1
+ import { j as jsxRuntimeExports } from "../_virtual/jsx-runtime.js";
2
+ import { useMemo } from "react";
3
+ const Surface = (props) => {
4
+ const { title, desc, viewBox, children, width, height, ...otherProps } = props;
5
+ const svgViewBox = useMemo(() => {
6
+ if (!(viewBox == null ? void 0 : viewBox.x) && !(viewBox == null ? void 0 : viewBox.y)) {
7
+ return void 0;
8
+ }
9
+ const viewX = (viewBox == null ? void 0 : viewBox.x) || 0;
10
+ const viewY = (viewBox == null ? void 0 : viewBox.y) || 0;
11
+ const viewWidth = (viewBox == null ? void 0 : viewBox.width) || width;
12
+ const viewHeight = (viewBox == null ? void 0 : viewBox.height) || height;
13
+ return viewWidth === void 0 || viewHeight === void 0 ? [viewX, viewY].join(" ") : [viewX, viewY, viewWidth, viewHeight].join(" ");
14
+ }, [width, height, viewBox]);
15
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("svg", { viewBox: svgViewBox, width, height, ...otherProps, children: [
16
+ title ? /* @__PURE__ */ jsxRuntimeExports.jsx("title", { children: title }) : null,
17
+ desc ? /* @__PURE__ */ jsxRuntimeExports.jsx("desc", { children: desc }) : null,
18
+ children
19
+ ] });
20
+ };
21
+ export {
22
+ Surface as default
23
+ };
@@ -0,0 +1,4 @@
1
+ import { FC, SVGProps } from 'react';
2
+ export type PathProps = {} & SVGProps<SVGPathElement>;
3
+ declare const Path: FC<PathProps>;
4
+ export default Path;
@@ -0,0 +1,13 @@
1
+ import { j as jsxRuntimeExports } from "../_virtual/jsx-runtime.js";
2
+ const Path = (props) => {
3
+ const { fill: propFill, strokeWidth: propStrokeWidth, stroke: propStroke, ...otherProps } = props;
4
+ const defaultProps = {
5
+ fill: propFill || "transparent",
6
+ strokeWidth: propStrokeWidth ?? 1,
7
+ stroke: propStroke || "currentColor"
8
+ };
9
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("path", { ...defaultProps, ...otherProps });
10
+ };
11
+ export {
12
+ Path as default
13
+ };
@@ -0,0 +1,6 @@
1
+ import { FC, PropsWithChildren, Ref, SVGProps } from 'react';
2
+ export type RectProps = {
3
+ ref?: Ref<SVGRectElement>;
4
+ } & SVGProps<SVGRectElement>;
5
+ declare const Rect: FC<PropsWithChildren<RectProps>>;
6
+ export default Rect;
@@ -0,0 +1,8 @@
1
+ import { j as jsxRuntimeExports } from "../_virtual/jsx-runtime.js";
2
+ const Rect = (props) => {
3
+ const { ref, ...otherProps } = props;
4
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("rect", { ref, ...otherProps });
5
+ };
6
+ export {
7
+ Rect as default
8
+ };