@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.
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/dist/es/_virtual/jsx-runtime.js +5 -0
- package/dist/es/_virtual/jsx-runtime2.js +4 -0
- package/dist/es/_virtual/react-jsx-runtime.development.js +4 -0
- package/dist/es/_virtual/react-jsx-runtime.production.js +4 -0
- package/dist/es/components/Scope.d.ts +6 -0
- package/dist/es/components/Scope.js +10 -0
- package/dist/es/components/TikZ.d.ts +9 -0
- package/dist/es/components/TikZ.js +12 -0
- package/dist/es/components/draw/Draw.d.ts +18 -0
- package/dist/es/components/draw/Draw.js +34 -0
- package/dist/es/components/draw/InnerDraw.d.ts +13 -0
- package/dist/es/components/draw/InnerDraw.js +47 -0
- package/dist/es/components/draw/arrow/index.d.ts +9 -0
- package/dist/es/components/draw/arrow/index.js +10 -0
- package/dist/es/components/draw/arrow/stealth.d.ts +7 -0
- package/dist/es/components/draw/arrow/stealth.js +29 -0
- package/dist/es/components/draw/arrow/types.d.ts +21 -0
- package/dist/es/components/draw/common.d.ts +4 -0
- package/dist/es/components/draw/common.js +12 -0
- package/dist/es/components/draw/index.d.ts +3 -0
- package/dist/es/components/draw/segment/Segment.d.ts +12 -0
- package/dist/es/components/draw/segment/Segment.js +41 -0
- package/dist/es/components/draw/segment/index.d.ts +19 -0
- package/dist/es/components/draw/segment/index.js +41 -0
- package/dist/es/components/draw/segment/useArrow.d.ts +12 -0
- package/dist/es/components/draw/segment/useArrow.js +52 -0
- package/dist/es/components/draw/segment/useConvertWay.d.ts +14 -0
- package/dist/es/components/draw/segment/useConvertWay.js +95 -0
- package/dist/es/components/draw/types.d.ts +29 -0
- package/dist/es/components/node/InnerNode.d.ts +33 -0
- package/dist/es/components/node/InnerNode.js +88 -0
- package/dist/es/components/node/Node.d.ts +54 -0
- package/dist/es/components/node/Node.js +87 -0
- package/dist/es/components/node/_hooks/useNodeConfig.d.ts +3 -0
- package/dist/es/components/node/_hooks/useNodeConfig.js +13 -0
- package/dist/es/components/node/_hooks/useNodeContent.d.ts +4 -0
- package/dist/es/components/node/_hooks/useNodeContent.js +27 -0
- package/dist/es/components/node/_hooks/useNodeShape.d.ts +4 -0
- package/dist/es/components/node/_hooks/useNodeShape.js +34 -0
- package/dist/es/components/node/index.d.ts +3 -0
- package/dist/es/components/node/index.js +4 -0
- package/dist/es/components/pathNode/PathNode.d.ts +39 -0
- package/dist/es/components/pathNode/PathNode.js +76 -0
- package/dist/es/components/pathNode/index.d.ts +3 -0
- package/dist/es/components/pathNode/index.js +4 -0
- package/dist/es/components/pathNode/useAnchor.d.ts +6 -0
- package/dist/es/components/pathNode/useAnchor.js +49 -0
- package/dist/es/container/Group.d.ts +6 -0
- package/dist/es/container/Group.js +7 -0
- package/dist/es/container/Surface.d.ts +17 -0
- package/dist/es/container/Surface.js +23 -0
- package/dist/es/elements/Path.d.ts +4 -0
- package/dist/es/elements/Path.js +13 -0
- package/dist/es/elements/Rect.d.ts +6 -0
- package/dist/es/elements/Rect.js +8 -0
- package/dist/es/elements/Text.d.ts +19 -0
- package/dist/es/elements/Text.js +35 -0
- package/dist/es/hooks/context/useCalculate.d.ts +7 -0
- package/dist/es/hooks/context/useCalculate.js +9 -0
- package/dist/es/hooks/context/useNodes.d.ts +9 -0
- package/dist/es/hooks/context/useNodes.js +33 -0
- package/dist/es/hooks/context/usePath.d.ts +13 -0
- package/dist/es/hooks/context/usePath.js +20 -0
- package/dist/es/hooks/context/useScope.d.ts +11 -0
- package/dist/es/hooks/context/useScope.js +7 -0
- package/dist/es/hooks/useForceUpdate.d.ts +2 -0
- package/dist/es/hooks/useForceUpdate.js +8 -0
- package/dist/es/index.d.ts +10 -0
- package/dist/es/index.js +12 -0
- package/dist/es/model/component/node.d.ts +45 -0
- package/dist/es/model/component/node.js +164 -0
- package/dist/es/model/component/path.d.ts +19 -0
- package/dist/es/model/component/path.js +47 -0
- package/dist/es/model/equation/line.d.ts +21 -0
- package/dist/es/model/equation/line.js +75 -0
- package/dist/es/model/geometry/point/DescartesPoint.d.ts +21 -0
- package/dist/es/model/geometry/point/DescartesPoint.js +50 -0
- package/dist/es/model/geometry/point/PolarPoint.d.ts +14 -0
- package/dist/es/model/geometry/point/PolarPoint.js +27 -0
- package/dist/es/node_modules/.pnpm/d3-color@3.1.0/node_modules/d3-color/src/color.js +338 -0
- package/dist/es/node_modules/.pnpm/d3-color@3.1.0/node_modules/d3-color/src/define.js +13 -0
- package/dist/es/node_modules/.pnpm/d3-path@3.1.0/node_modules/d3-path/src/path.js +88 -0
- package/dist/es/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/array.js +6 -0
- package/dist/es/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/constant.js +8 -0
- package/dist/es/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/curve/linear.js +39 -0
- package/dist/es/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/line.js +41 -0
- package/dist/es/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/path.js +19 -0
- package/dist/es/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/point.js +10 -0
- package/dist/es/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.development.js +20 -0
- package/dist/es/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.production.js +41 -0
- package/dist/es/node_modules/.pnpm/react@19.0.0/node_modules/react/jsx-runtime.js +17 -0
- package/dist/es/types/coordinate/descartes.d.ts +23 -0
- package/dist/es/types/coordinate/index.d.ts +5 -0
- package/dist/es/types/coordinate/polar.d.ts +5 -0
- package/dist/es/types/distance/index.d.ts +8 -0
- package/dist/es/types/distance/sep.d.ts +9 -0
- package/dist/es/types/shape/index.d.ts +8 -0
- package/dist/es/types/shape/index.js +9 -0
- package/dist/es/types/shape/rect.d.ts +25 -0
- package/dist/es/types/shape/rect.js +30 -0
- package/dist/es/types/svg/font.d.ts +10 -0
- package/dist/es/types/svg/stroke.d.ts +10 -0
- package/dist/es/types/tikz/index.d.ts +6 -0
- package/dist/es/utils/compare.d.ts +4 -0
- package/dist/es/utils/compare.js +20 -0
- package/dist/es/utils/css.d.ts +6 -0
- package/dist/es/utils/css.js +26 -0
- package/dist/es/utils/math.d.ts +9 -0
- package/dist/es/utils/math.js +26 -0
- package/dist/es/utils/string.d.ts +7 -0
- package/dist/es/utils/string.js +7 -0
- package/dist/es/utils/style/font.d.ts +17 -0
- package/dist/es/utils/style/font.js +34 -0
- package/dist/es/utils/style/stroke.d.ts +19 -0
- package/dist/es/utils/style/stroke.js +40 -0
- package/dist/lib/_virtual/jsx-runtime.cjs +5 -0
- package/dist/lib/_virtual/jsx-runtime2.cjs +4 -0
- package/dist/lib/_virtual/react-jsx-runtime.development.cjs +4 -0
- package/dist/lib/_virtual/react-jsx-runtime.production.cjs +4 -0
- package/dist/lib/components/Scope.cjs +10 -0
- package/dist/lib/components/Scope.d.ts +6 -0
- package/dist/lib/components/TikZ.cjs +12 -0
- package/dist/lib/components/TikZ.d.ts +9 -0
- package/dist/lib/components/draw/Draw.cjs +34 -0
- package/dist/lib/components/draw/Draw.d.ts +18 -0
- package/dist/lib/components/draw/InnerDraw.cjs +47 -0
- package/dist/lib/components/draw/InnerDraw.d.ts +13 -0
- package/dist/lib/components/draw/arrow/index.cjs +10 -0
- package/dist/lib/components/draw/arrow/index.d.ts +9 -0
- package/dist/lib/components/draw/arrow/stealth.cjs +29 -0
- package/dist/lib/components/draw/arrow/stealth.d.ts +7 -0
- package/dist/lib/components/draw/arrow/types.d.ts +21 -0
- package/dist/lib/components/draw/common.cjs +12 -0
- package/dist/lib/components/draw/common.d.ts +4 -0
- package/dist/lib/components/draw/index.d.ts +3 -0
- package/dist/lib/components/draw/segment/Segment.cjs +41 -0
- package/dist/lib/components/draw/segment/Segment.d.ts +12 -0
- package/dist/lib/components/draw/segment/index.cjs +41 -0
- package/dist/lib/components/draw/segment/index.d.ts +19 -0
- package/dist/lib/components/draw/segment/useArrow.cjs +52 -0
- package/dist/lib/components/draw/segment/useArrow.d.ts +12 -0
- package/dist/lib/components/draw/segment/useConvertWay.cjs +95 -0
- package/dist/lib/components/draw/segment/useConvertWay.d.ts +14 -0
- package/dist/lib/components/draw/types.d.ts +29 -0
- package/dist/lib/components/node/InnerNode.cjs +88 -0
- package/dist/lib/components/node/InnerNode.d.ts +33 -0
- package/dist/lib/components/node/Node.cjs +87 -0
- package/dist/lib/components/node/Node.d.ts +54 -0
- package/dist/lib/components/node/_hooks/useNodeConfig.cjs +13 -0
- package/dist/lib/components/node/_hooks/useNodeConfig.d.ts +3 -0
- package/dist/lib/components/node/_hooks/useNodeContent.cjs +27 -0
- package/dist/lib/components/node/_hooks/useNodeContent.d.ts +4 -0
- package/dist/lib/components/node/_hooks/useNodeShape.cjs +34 -0
- package/dist/lib/components/node/_hooks/useNodeShape.d.ts +4 -0
- package/dist/lib/components/node/index.cjs +4 -0
- package/dist/lib/components/node/index.d.ts +3 -0
- package/dist/lib/components/pathNode/PathNode.cjs +76 -0
- package/dist/lib/components/pathNode/PathNode.d.ts +39 -0
- package/dist/lib/components/pathNode/index.cjs +4 -0
- package/dist/lib/components/pathNode/index.d.ts +3 -0
- package/dist/lib/components/pathNode/useAnchor.cjs +49 -0
- package/dist/lib/components/pathNode/useAnchor.d.ts +6 -0
- package/dist/lib/container/Group.cjs +7 -0
- package/dist/lib/container/Group.d.ts +6 -0
- package/dist/lib/container/Surface.cjs +23 -0
- package/dist/lib/container/Surface.d.ts +17 -0
- package/dist/lib/elements/Path.cjs +13 -0
- package/dist/lib/elements/Path.d.ts +4 -0
- package/dist/lib/elements/Rect.cjs +8 -0
- package/dist/lib/elements/Rect.d.ts +6 -0
- package/dist/lib/elements/Text.cjs +35 -0
- package/dist/lib/elements/Text.d.ts +19 -0
- package/dist/lib/hooks/context/useCalculate.cjs +9 -0
- package/dist/lib/hooks/context/useCalculate.d.ts +7 -0
- package/dist/lib/hooks/context/useNodes.cjs +33 -0
- package/dist/lib/hooks/context/useNodes.d.ts +9 -0
- package/dist/lib/hooks/context/usePath.cjs +20 -0
- package/dist/lib/hooks/context/usePath.d.ts +13 -0
- package/dist/lib/hooks/context/useScope.cjs +7 -0
- package/dist/lib/hooks/context/useScope.d.ts +11 -0
- package/dist/lib/hooks/useForceUpdate.cjs +8 -0
- package/dist/lib/hooks/useForceUpdate.d.ts +2 -0
- package/dist/lib/index.cjs +12 -0
- package/dist/lib/index.d.ts +10 -0
- package/dist/lib/model/component/node.cjs +164 -0
- package/dist/lib/model/component/node.d.ts +45 -0
- package/dist/lib/model/component/path.cjs +47 -0
- package/dist/lib/model/component/path.d.ts +19 -0
- package/dist/lib/model/equation/line.cjs +75 -0
- package/dist/lib/model/equation/line.d.ts +21 -0
- package/dist/lib/model/geometry/point/DescartesPoint.cjs +50 -0
- package/dist/lib/model/geometry/point/DescartesPoint.d.ts +21 -0
- package/dist/lib/model/geometry/point/PolarPoint.cjs +27 -0
- package/dist/lib/model/geometry/point/PolarPoint.d.ts +14 -0
- package/dist/lib/node_modules/.pnpm/d3-color@3.1.0/node_modules/d3-color/src/color.cjs +338 -0
- package/dist/lib/node_modules/.pnpm/d3-color@3.1.0/node_modules/d3-color/src/define.cjs +13 -0
- package/dist/lib/node_modules/.pnpm/d3-path@3.1.0/node_modules/d3-path/src/path.cjs +88 -0
- package/dist/lib/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/array.cjs +6 -0
- package/dist/lib/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/constant.cjs +8 -0
- package/dist/lib/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/curve/linear.cjs +39 -0
- package/dist/lib/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/line.cjs +41 -0
- package/dist/lib/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/path.cjs +19 -0
- package/dist/lib/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/point.cjs +10 -0
- package/dist/lib/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.development.cjs +20 -0
- package/dist/lib/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.production.cjs +41 -0
- package/dist/lib/node_modules/.pnpm/react@19.0.0/node_modules/react/jsx-runtime.cjs +17 -0
- package/dist/lib/types/coordinate/descartes.d.ts +23 -0
- package/dist/lib/types/coordinate/index.d.ts +5 -0
- package/dist/lib/types/coordinate/polar.d.ts +5 -0
- package/dist/lib/types/distance/index.d.ts +8 -0
- package/dist/lib/types/distance/sep.d.ts +9 -0
- package/dist/lib/types/shape/index.cjs +9 -0
- package/dist/lib/types/shape/index.d.ts +8 -0
- package/dist/lib/types/shape/rect.cjs +30 -0
- package/dist/lib/types/shape/rect.d.ts +25 -0
- package/dist/lib/types/svg/font.d.ts +10 -0
- package/dist/lib/types/svg/stroke.d.ts +10 -0
- package/dist/lib/types/tikz/index.d.ts +6 -0
- package/dist/lib/utils/compare.cjs +20 -0
- package/dist/lib/utils/compare.d.ts +4 -0
- package/dist/lib/utils/css.cjs +26 -0
- package/dist/lib/utils/css.d.ts +6 -0
- package/dist/lib/utils/math.cjs +26 -0
- package/dist/lib/utils/math.d.ts +9 -0
- package/dist/lib/utils/string.cjs +7 -0
- package/dist/lib/utils/string.d.ts +7 -0
- package/dist/lib/utils/style/font.cjs +34 -0
- package/dist/lib/utils/style/font.d.ts +17 -0
- package/dist/lib/utils/style/stroke.cjs +40 -0
- package/dist/lib/utils/style/stroke.d.ts +19 -0
- package/package.json +57 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const line = require("../../../node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/line.cjs");
|
|
4
|
+
const getStealthPath = (attributes) => {
|
|
5
|
+
const {
|
|
6
|
+
width = 4,
|
|
7
|
+
length = 5,
|
|
8
|
+
insert = 1.75,
|
|
9
|
+
left = false,
|
|
10
|
+
right = false,
|
|
11
|
+
scale = 1,
|
|
12
|
+
strokeWidth = 1,
|
|
13
|
+
round,
|
|
14
|
+
strokeLinejoin = "miter"
|
|
15
|
+
} = attributes;
|
|
16
|
+
const startPoint = [0, 0];
|
|
17
|
+
const leftPoint = [-length * scale, -width / 2 * scale];
|
|
18
|
+
const insertPoint = [(-length + insert) * scale, 0];
|
|
19
|
+
const rightPoint = [-length * scale, width / 2 * scale];
|
|
20
|
+
const way = left ? [startPoint, leftPoint, insertPoint] : right ? [startPoint, rightPoint, insertPoint] : [startPoint, leftPoint, insertPoint, rightPoint];
|
|
21
|
+
const straightLine = line.default().x((d) => d[0]).y((d) => d[1]);
|
|
22
|
+
const radio = width / 2 / Math.sqrt(length ** 2 + (width / 2) ** 2);
|
|
23
|
+
return {
|
|
24
|
+
d: straightLine(way) + "Z",
|
|
25
|
+
offsetDistance: round || strokeLinejoin === "round" ? strokeWidth / 2 : strokeWidth / (2 * radio),
|
|
26
|
+
insertDistance: length - insert
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
exports.default = getStealthPath;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** 箭头属性 */
|
|
2
|
+
export type ArrowAttributes = {
|
|
3
|
+
width?: number;
|
|
4
|
+
length?: number;
|
|
5
|
+
insert?: number;
|
|
6
|
+
left?: boolean;
|
|
7
|
+
right?: boolean;
|
|
8
|
+
round?: boolean;
|
|
9
|
+
strokeWidth?: number;
|
|
10
|
+
scale?: number;
|
|
11
|
+
linkType?: 'center' | 'end';
|
|
12
|
+
strokeLinejoin?: "round" | "inherit" | "bevel" | "miter";
|
|
13
|
+
};
|
|
14
|
+
export type ArrowPathConfig = {
|
|
15
|
+
/** path d 属性路径 */
|
|
16
|
+
d: string;
|
|
17
|
+
/** 箭头顶点与 path 顶点的距离 */
|
|
18
|
+
offsetDistance: number;
|
|
19
|
+
/** insert 点与 path 顶点的距离 */
|
|
20
|
+
insertDistance: number;
|
|
21
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const offsetReg = /\+[[(]?[+-]?\d+(?:\.\d+)?,\s*[+-]?\d+(?:\.\d+)?[)\]]?/;
|
|
4
|
+
const moveReg = /\+\+[[(]?[+-]?\d+(?:\.\d+)?,\s*[+-]?\d+(?:\.\d+)?[)\]]?/;
|
|
5
|
+
const getDrawPointType = (point) => {
|
|
6
|
+
if (typeof point !== "string") return "coordinate";
|
|
7
|
+
if (["-|", "|-"].includes(point)) return "vertical";
|
|
8
|
+
if (point.match(moveReg)) return "move";
|
|
9
|
+
if (point.match(offsetReg)) return "offset";
|
|
10
|
+
return "node";
|
|
11
|
+
};
|
|
12
|
+
exports.getDrawPointType = getDrawPointType;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const jsxRuntime = require("../../../_virtual/jsx-runtime.cjs");
|
|
4
|
+
const require$$0 = require("react");
|
|
5
|
+
const Path = require("../../../elements/Path.cjs");
|
|
6
|
+
const Group = require("../../../container/Group.cjs");
|
|
7
|
+
const useArrow = require("./useArrow.cjs");
|
|
8
|
+
const line = require("../../../node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/line.cjs");
|
|
9
|
+
const InnerDrawSegment = (props) => {
|
|
10
|
+
const { way, startArrow, endArrow, ...strokeProps } = props;
|
|
11
|
+
const pickedArrowStrokeProps = {
|
|
12
|
+
stroke: strokeProps.stroke,
|
|
13
|
+
strokeWidth: strokeProps.strokeWidth,
|
|
14
|
+
strokeOpacity: strokeProps.strokeOpacity
|
|
15
|
+
};
|
|
16
|
+
const startArrowPath = useArrow.default(
|
|
17
|
+
{ position: way[0], nearPosition: way[1], arrowType: "start" },
|
|
18
|
+
startArrow ? { ...pickedArrowStrokeProps, ...startArrow } : void 0
|
|
19
|
+
);
|
|
20
|
+
const endArrowPath = useArrow.default(
|
|
21
|
+
{ position: way[way.length - 1], nearPosition: way[way.length - 2], arrowType: "end" },
|
|
22
|
+
endArrow ? { ...pickedArrowStrokeProps, ...endArrow } : void 0
|
|
23
|
+
);
|
|
24
|
+
const d = require$$0.useMemo(() => {
|
|
25
|
+
const realWay = [...way];
|
|
26
|
+
if (startArrowPath) {
|
|
27
|
+
realWay[0] = startArrowPath.linkPoint;
|
|
28
|
+
}
|
|
29
|
+
if (endArrowPath) {
|
|
30
|
+
realWay[realWay.length - 1] = endArrowPath.linkPoint;
|
|
31
|
+
}
|
|
32
|
+
const straightLine = line.default().x((d2) => d2[0]).y((d2) => d2[1]);
|
|
33
|
+
return straightLine(realWay);
|
|
34
|
+
}, [way]);
|
|
35
|
+
return endArrowPath || startArrowPath ? /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Group.default, { children: [
|
|
36
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Path.default, { d: d ?? "", ...strokeProps }),
|
|
37
|
+
startArrowPath ? startArrowPath.arrowPath : null,
|
|
38
|
+
endArrowPath ? endArrowPath.arrowPath : null
|
|
39
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Path.default, { d: d ?? "", ...strokeProps });
|
|
40
|
+
};
|
|
41
|
+
exports.default = InnerDrawSegment;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { Position } from '../../../types/coordinate/descartes';
|
|
3
|
+
import { StrokeProps } from '../../../types/svg/stroke';
|
|
4
|
+
import { ArrowConfig } from '../types';
|
|
5
|
+
export type InnerDrawSegmentProps = {
|
|
6
|
+
/** 路径,始末节点为 undefined 表示临近点在 node 外边界内 */
|
|
7
|
+
way: Position[];
|
|
8
|
+
startArrow?: ArrowConfig;
|
|
9
|
+
endArrow?: ArrowConfig;
|
|
10
|
+
} & StrokeProps;
|
|
11
|
+
declare const InnerDrawSegment: FC<InnerDrawSegmentProps>;
|
|
12
|
+
export default InnerDrawSegment;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const jsxRuntime = require("../../../_virtual/jsx-runtime.cjs");
|
|
4
|
+
const require$$0 = require("react");
|
|
5
|
+
const node = require("../../../model/component/node.cjs");
|
|
6
|
+
const stroke = require("../../../utils/style/stroke.cjs");
|
|
7
|
+
const Segment = require("./Segment.cjs");
|
|
8
|
+
const useConvertWay = require("./useConvertWay.cjs");
|
|
9
|
+
const usePath = require("../../../hooks/context/usePath.cjs");
|
|
10
|
+
const DrawSegment = (props) => {
|
|
11
|
+
const { way, index, color, startArrow, endArrow, isLastSegment, ...resProps } = props;
|
|
12
|
+
const { strokeType = "solid", strokeWidth = 1, ...strokeProps } = resProps;
|
|
13
|
+
const [convertedWay, nodesInit] = useConvertWay.default(way);
|
|
14
|
+
const { model, updateModel } = usePath.default();
|
|
15
|
+
const pointWay = require$$0.useMemo(() => {
|
|
16
|
+
const realWay = convertedWay.map((wayPoint, index2) => {
|
|
17
|
+
if (wayPoint instanceof node.default) {
|
|
18
|
+
const neighborPoint = index2 === 0 ? convertedWay[1] : convertedWay[index2 - 1];
|
|
19
|
+
return wayPoint.getCrossPoint(neighborPoint instanceof node.default ? neighborPoint.center : neighborPoint);
|
|
20
|
+
}
|
|
21
|
+
return wayPoint;
|
|
22
|
+
});
|
|
23
|
+
const newWay = [...model == null ? void 0 : model.ways];
|
|
24
|
+
newWay[index] = realWay;
|
|
25
|
+
updateModel({ ways: newWay, init: nodesInit });
|
|
26
|
+
return realWay;
|
|
27
|
+
}, [convertedWay]);
|
|
28
|
+
if (!nodesInit) return null;
|
|
29
|
+
return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
|
|
30
|
+
Segment.default,
|
|
31
|
+
{
|
|
32
|
+
way: pointWay,
|
|
33
|
+
startArrow,
|
|
34
|
+
endArrow,
|
|
35
|
+
strokeWidth,
|
|
36
|
+
...stroke.convertStrokeType(strokeType, strokeWidth),
|
|
37
|
+
...strokeProps
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
exports.default = DrawSegment;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { StrokeProps } from '../../../types/svg/stroke';
|
|
3
|
+
import { TikZKey } from '../../../types/tikz';
|
|
4
|
+
import { ArrowConfig, DrawWaySegmentType } from '../types';
|
|
5
|
+
export type DrawSegmentProps = {
|
|
6
|
+
/** 路径,首位可以是 Node,其他必须是坐标 */
|
|
7
|
+
way: DrawWaySegmentType;
|
|
8
|
+
index: number;
|
|
9
|
+
isLastSegment: boolean;
|
|
10
|
+
/** 线段颜色 */
|
|
11
|
+
color?: TikZKey;
|
|
12
|
+
/** 线段样式 */
|
|
13
|
+
strokeType?: 'solid' | 'dashed' | 'dotted';
|
|
14
|
+
startArrow?: ArrowConfig;
|
|
15
|
+
endArrow?: ArrowConfig;
|
|
16
|
+
} & StrokeProps;
|
|
17
|
+
/** 单条连续的路径 */
|
|
18
|
+
declare const DrawSegment: FC<DrawSegmentProps>;
|
|
19
|
+
export default DrawSegment;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const jsxRuntime = require("../../../_virtual/jsx-runtime.cjs");
|
|
4
|
+
const require$$0 = require("react");
|
|
5
|
+
const useCalculate = require("../../../hooks/context/useCalculate.cjs");
|
|
6
|
+
const index = require("../arrow/index.cjs");
|
|
7
|
+
const Path = require("../../../elements/Path.cjs");
|
|
8
|
+
const line = require("../../../model/equation/line.cjs");
|
|
9
|
+
const math = require("../../../utils/math.cjs");
|
|
10
|
+
const useArrow = (linkConfig, arrowConfig) => {
|
|
11
|
+
const { precision } = useCalculate.default();
|
|
12
|
+
return require$$0.useMemo(() => {
|
|
13
|
+
if (!arrowConfig) return null;
|
|
14
|
+
const { position, nearPosition } = linkConfig;
|
|
15
|
+
const { type, stroke, linkType = "end", round, strokeLinejoin, strokeWidth, ...strokeProps } = arrowConfig;
|
|
16
|
+
const degree = line.default.getDegree(nearPosition, position);
|
|
17
|
+
const isRound = round || strokeLinejoin === "round";
|
|
18
|
+
const realStrokeWidth = strokeWidth ?? 1;
|
|
19
|
+
const { d, offsetDistance, insertDistance } = index.default(type, arrowConfig);
|
|
20
|
+
const endOffset = [
|
|
21
|
+
(isRound ? realStrokeWidth : offsetDistance) * Math.cos(degree),
|
|
22
|
+
(isRound ? realStrokeWidth : offsetDistance) * Math.sin(degree)
|
|
23
|
+
];
|
|
24
|
+
const translatePosition = linkType === "end" ? [position[0] - endOffset[0], position[1] - endOffset[1]] : [position[0] + insertDistance * Math.cos(degree), position[1] + insertDistance * Math.sin(degree)];
|
|
25
|
+
const linkPoint = linkType === "end" ? [
|
|
26
|
+
position[0] - insertDistance * Math.cos(degree) - endOffset[0],
|
|
27
|
+
position[1] - insertDistance * Math.sin(degree) - endOffset[1]
|
|
28
|
+
] : position;
|
|
29
|
+
const transform = `translate(
|
|
30
|
+
${math.convertPrecision(translatePosition[0], precision)}, ${math.convertPrecision(
|
|
31
|
+
translatePosition[1],
|
|
32
|
+
precision
|
|
33
|
+
)}) rotate(${math.convertPrecision(degree * (180 / Math.PI), precision)})`;
|
|
34
|
+
return {
|
|
35
|
+
linkPoint,
|
|
36
|
+
arrowPath: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
|
|
37
|
+
Path.default,
|
|
38
|
+
{
|
|
39
|
+
d,
|
|
40
|
+
strokeWidth,
|
|
41
|
+
strokeLinejoin: round ? "round" : "miter",
|
|
42
|
+
strokeMiterlimit: 10,
|
|
43
|
+
fill: stroke || "currentColor",
|
|
44
|
+
stroke,
|
|
45
|
+
transform,
|
|
46
|
+
...strokeProps
|
|
47
|
+
}
|
|
48
|
+
)
|
|
49
|
+
};
|
|
50
|
+
}, [arrowConfig, linkConfig]);
|
|
51
|
+
};
|
|
52
|
+
exports.default = useArrow;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ArrowConfig } from '../types';
|
|
2
|
+
import { Position } from '../../../types/coordinate/descartes';
|
|
3
|
+
export type ArrowLinkConfig = {
|
|
4
|
+
nearPosition: Position;
|
|
5
|
+
position: Position;
|
|
6
|
+
arrowType: 'start' | 'end';
|
|
7
|
+
};
|
|
8
|
+
declare const useArrow: (linkConfig: ArrowLinkConfig, arrowConfig?: ArrowConfig) => {
|
|
9
|
+
linkPoint: Position;
|
|
10
|
+
arrowPath: import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
} | null;
|
|
12
|
+
export default useArrow;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const require$$0 = require("react");
|
|
4
|
+
const useNodes = require("../../../hooks/context/useNodes.cjs");
|
|
5
|
+
const useForceUpdate = require("../../../hooks/useForceUpdate.cjs");
|
|
6
|
+
const DescartesPoint = require("../../../model/geometry/point/DescartesPoint.cjs");
|
|
7
|
+
const PolarPoint = require("../../../model/geometry/point/PolarPoint.cjs");
|
|
8
|
+
const common = require("../common.cjs");
|
|
9
|
+
const formatPointPosition = (point) => {
|
|
10
|
+
if (Array.isArray(point)) return point;
|
|
11
|
+
if (point.hasOwnProperty("x") && point.hasOwnProperty("y")) {
|
|
12
|
+
const p = point;
|
|
13
|
+
return [p.x, p.y];
|
|
14
|
+
}
|
|
15
|
+
return PolarPoint.default.convertPolarToDescartesPosition(point);
|
|
16
|
+
};
|
|
17
|
+
const getVerticalPoint = (point1, point2, type) => {
|
|
18
|
+
const p1 = formatPointPosition(point1);
|
|
19
|
+
const p2 = formatPointPosition(point2);
|
|
20
|
+
return type === "-|" ? [p2[0], p1[1]] : [p1[0], p2[1]];
|
|
21
|
+
};
|
|
22
|
+
const convertOffsetAndMovePoint = (point) => {
|
|
23
|
+
const filterPoint = point.replace(/[+()\[\]\s]/g, "");
|
|
24
|
+
return filterPoint.split(",").map((item) => parseFloat(item));
|
|
25
|
+
};
|
|
26
|
+
const useConvertWay = (way) => {
|
|
27
|
+
const { getModel, subscribeModel } = useNodes.default();
|
|
28
|
+
const forceUpdate = useForceUpdate.default();
|
|
29
|
+
const nodeUpdateCount = require$$0.useRef(0);
|
|
30
|
+
let cursor = [0, 0];
|
|
31
|
+
const tryGetModel = (name) => {
|
|
32
|
+
const model = getModel(name);
|
|
33
|
+
if (!model) {
|
|
34
|
+
throw new Error(`Node ${name} is not defined`);
|
|
35
|
+
}
|
|
36
|
+
cursor = model.center;
|
|
37
|
+
return model;
|
|
38
|
+
};
|
|
39
|
+
const subscribeCbs = [];
|
|
40
|
+
let allNodeInit = true;
|
|
41
|
+
const result = require$$0.useMemo(
|
|
42
|
+
() => way.map((item, index) => {
|
|
43
|
+
const type = common.getDrawPointType(item);
|
|
44
|
+
switch (type) {
|
|
45
|
+
case "coordinate":
|
|
46
|
+
const corPosition = formatPointPosition(item);
|
|
47
|
+
cursor = corPosition;
|
|
48
|
+
return corPosition;
|
|
49
|
+
case "node":
|
|
50
|
+
if (![0, way.length - 1].includes(index)) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
"Node can only be the first or last point on DrawSegment component, this may be a retikz bug, please report it."
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
const nodeModel = tryGetModel(item);
|
|
56
|
+
if (!nodeModel.init) allNodeInit = false;
|
|
57
|
+
const cb = subscribeModel(item, () => {
|
|
58
|
+
nodeUpdateCount.current += 1;
|
|
59
|
+
forceUpdate();
|
|
60
|
+
});
|
|
61
|
+
if (cb) subscribeCbs.push(cb);
|
|
62
|
+
cursor = nodeModel.center;
|
|
63
|
+
return nodeModel;
|
|
64
|
+
case "vertical":
|
|
65
|
+
if ([0, way.length - 1].includes(index)) {
|
|
66
|
+
throw new Error("Vertical point can not be the first point on path.");
|
|
67
|
+
}
|
|
68
|
+
const beforePosition = cursor;
|
|
69
|
+
const afterPoint = way[index + 1];
|
|
70
|
+
const afterPointType = common.getDrawPointType(afterPoint);
|
|
71
|
+
if (["vertical", "offset", "move"].includes(afterPointType)) {
|
|
72
|
+
throw new Error("Vertical point can not be followed by these point type: vertical offset move.");
|
|
73
|
+
}
|
|
74
|
+
const afterPosition = afterPointType === "node" ? tryGetModel(afterPoint).center : formatPointPosition(afterPoint);
|
|
75
|
+
const verPosition = getVerticalPoint(beforePosition, afterPosition, item);
|
|
76
|
+
cursor = verPosition;
|
|
77
|
+
return cursor;
|
|
78
|
+
default:
|
|
79
|
+
if (index === 0) throw new Error("offset/move point can not be the first point on path.");
|
|
80
|
+
const convertedPos = convertOffsetAndMovePoint(item);
|
|
81
|
+
const curPos = DescartesPoint.default.plus(convertedPos, cursor);
|
|
82
|
+
if (type === "move") cursor = curPos;
|
|
83
|
+
return curPos;
|
|
84
|
+
}
|
|
85
|
+
}),
|
|
86
|
+
[way, nodeUpdateCount.current]
|
|
87
|
+
);
|
|
88
|
+
require$$0.useLayoutEffect(() => () => {
|
|
89
|
+
subscribeCbs.forEach((cb) => cb && cb());
|
|
90
|
+
});
|
|
91
|
+
return [result, allNodeInit];
|
|
92
|
+
};
|
|
93
|
+
exports.default = useConvertWay;
|
|
94
|
+
exports.formatPointPosition = formatPointPosition;
|
|
95
|
+
exports.getVerticalPoint = getVerticalPoint;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { default as NodeModel } from '../../../model/component/node';
|
|
2
|
+
import { PointPosition } from '../../../types/coordinate';
|
|
3
|
+
import { Position } from '../../../types/coordinate/descartes';
|
|
4
|
+
import { DrawWaySegmentType } from '../types';
|
|
5
|
+
/** 将坐标格式转换为笛卡尔坐标数组形式 */
|
|
6
|
+
export declare const formatPointPosition: (point: PointPosition) => Position;
|
|
7
|
+
/** 获取两点间的垂直点 */
|
|
8
|
+
export declare const getVerticalPoint: (point1: PointPosition, point2: PointPosition, type: "-|" | "|-") => Position;
|
|
9
|
+
/**
|
|
10
|
+
* 将特殊路径点转换为坐标,Node 节点转换为对应的 Model
|
|
11
|
+
* 目前支持的节点类型:node,各种坐标,垂点,位移点
|
|
12
|
+
*/
|
|
13
|
+
declare const useConvertWay: (way: DrawWaySegmentType) => [Array<Position | NodeModel>, boolean];
|
|
14
|
+
export default useConvertWay;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { PointPosition } from '../../types/coordinate';
|
|
2
|
+
import { StrokeProps } from '../../types/svg/stroke';
|
|
3
|
+
import { TikZKey } from '../../types/tikz';
|
|
4
|
+
import { ArrowPositionAttributes, ArrowType } from './arrow';
|
|
5
|
+
export type ArrowConfig = {
|
|
6
|
+
type: ArrowType;
|
|
7
|
+
fill?: string;
|
|
8
|
+
} & ArrowPositionAttributes & StrokeProps;
|
|
9
|
+
/** 垂直路径点,临近的节点不能都是特殊路径点 */
|
|
10
|
+
export type VerticalDrawPosition = '-|' | '|-';
|
|
11
|
+
/** 偏移与移动点 */
|
|
12
|
+
export type OffSetOrMovePosition = string;
|
|
13
|
+
/** 路径点类型:节点,坐标,垂点,偏移点,移动点 */
|
|
14
|
+
export type DrawPointType = 'node' | 'coordinate' | 'vertical' | 'offset' | 'move';
|
|
15
|
+
/** 路径节点类型 */
|
|
16
|
+
export type DrawWayType = TikZKey | PointPosition | VerticalDrawPosition | OffSetOrMovePosition;
|
|
17
|
+
/** 路径片段节点类型 */
|
|
18
|
+
export type DrawWaySegmentType = [
|
|
19
|
+
TikZKey | PointPosition,
|
|
20
|
+
...Array<PointPosition | VerticalDrawPosition | OffSetOrMovePosition>,
|
|
21
|
+
TikZKey | PointPosition
|
|
22
|
+
];
|
|
23
|
+
/** 箭头属性 */
|
|
24
|
+
export type ArrowProps<T = ArrowType | ArrowConfig> = {
|
|
25
|
+
startArrow?: T;
|
|
26
|
+
startArrows?: T;
|
|
27
|
+
endArrow?: T;
|
|
28
|
+
endArrows?: T;
|
|
29
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const jsxRuntime = require("../../_virtual/jsx-runtime.cjs");
|
|
4
|
+
const require$$0 = require("react");
|
|
5
|
+
const Group = require("../../container/Group.cjs");
|
|
6
|
+
const useNodeShape = require("./_hooks/useNodeShape.cjs");
|
|
7
|
+
const useNodeContent = require("./_hooks/useNodeContent.cjs");
|
|
8
|
+
const useNodeConfig = require("./_hooks/useNodeConfig.cjs");
|
|
9
|
+
const css = require("../../utils/css.cjs");
|
|
10
|
+
const useNodes = require("../../hooks/context/useNodes.cjs");
|
|
11
|
+
const useCalculate = require("../../hooks/context/useCalculate.cjs");
|
|
12
|
+
const math = require("../../utils/math.cjs");
|
|
13
|
+
const InnerNode = (props) => {
|
|
14
|
+
const { name, ref, position, width, height, innerSep, outerSep, rotate } = props;
|
|
15
|
+
const nodeRef = require$$0.useRef(null);
|
|
16
|
+
const shapeRef = require$$0.useRef(null);
|
|
17
|
+
const contentRef = require$$0.useRef(null);
|
|
18
|
+
const { getModel, updateModel, deleteModel } = useNodes.default();
|
|
19
|
+
const { precision } = useCalculate.default();
|
|
20
|
+
const nodeConfig = useNodeConfig.default();
|
|
21
|
+
nodeConfig.current.position = position;
|
|
22
|
+
if (name && !getModel(name)) {
|
|
23
|
+
updateModel(name, nodeConfig.current, false);
|
|
24
|
+
}
|
|
25
|
+
const groupElement = ref && "current" in ref ? ref.current : nodeRef.current;
|
|
26
|
+
require$$0.useLayoutEffect(() => {
|
|
27
|
+
const contentElement = contentRef.current;
|
|
28
|
+
if (!contentElement) return;
|
|
29
|
+
const { width: elementWidth, height: elementHeight } = contentElement.getBoundingClientRect();
|
|
30
|
+
nodeConfig.current.contentSize = [Math.max(elementWidth, width || 0), Math.max(elementHeight, height || 0)];
|
|
31
|
+
});
|
|
32
|
+
const getSep = (sep) => {
|
|
33
|
+
const { width: width2 = 100, height: height2 = 100 } = (groupElement == null ? void 0 : groupElement.getBoundingClientRect()) || {};
|
|
34
|
+
const remPx = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
35
|
+
const emPx = groupElement ? parseFloat(getComputedStyle(groupElement).fontSize) : remPx;
|
|
36
|
+
return {
|
|
37
|
+
left: css.convertCssToPx(sep.left, { remPx, emPx, parentPx: width2 }),
|
|
38
|
+
right: css.convertCssToPx(sep.right, { remPx, emPx, parentPx: width2 }),
|
|
39
|
+
top: css.convertCssToPx(sep.top, { remPx, emPx, parentPx: height2 }),
|
|
40
|
+
bottom: css.convertCssToPx(sep.bottom, { remPx, emPx, parentPx: height2 })
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
require$$0.useLayoutEffect(() => {
|
|
44
|
+
nodeConfig.current.innerSep = getSep(innerSep);
|
|
45
|
+
}, [innerSep]);
|
|
46
|
+
require$$0.useLayoutEffect(() => {
|
|
47
|
+
nodeConfig.current.outerSep = getSep(outerSep);
|
|
48
|
+
}, [outerSep]);
|
|
49
|
+
require$$0.useLayoutEffect(() => {
|
|
50
|
+
var _a, _b, _c, _d;
|
|
51
|
+
const {
|
|
52
|
+
contentSize: [width2, height2],
|
|
53
|
+
innerSep: innerSep2
|
|
54
|
+
} = nodeConfig.current;
|
|
55
|
+
const realX = -width2 / 2 - innerSep2.left;
|
|
56
|
+
(_a = shapeRef.current) == null ? void 0 : _a.setAttribute("x", math.convertPrecision(realX, precision).toString());
|
|
57
|
+
const realY = -height2 / 2 - innerSep2.top;
|
|
58
|
+
(_b = shapeRef.current) == null ? void 0 : _b.setAttribute("y", math.convertPrecision(realY, precision).toString());
|
|
59
|
+
const realWidth = width2 + innerSep2.left + innerSep2.right;
|
|
60
|
+
(_c = shapeRef.current) == null ? void 0 : _c.setAttribute("width", math.convertPrecision(realWidth, precision).toString());
|
|
61
|
+
const realHeight = height2 + innerSep2.top + innerSep2.bottom;
|
|
62
|
+
(_d = shapeRef.current) == null ? void 0 : _d.setAttribute("height", math.convertPrecision(realHeight, precision).toString());
|
|
63
|
+
}, [nodeConfig.current.position, nodeConfig.current.contentSize, nodeConfig.current.innerSep]);
|
|
64
|
+
require$$0.useLayoutEffect(() => {
|
|
65
|
+
if (name) updateModel(name, nodeConfig.current);
|
|
66
|
+
});
|
|
67
|
+
require$$0.useLayoutEffect(
|
|
68
|
+
() => () => {
|
|
69
|
+
if (name) {
|
|
70
|
+
deleteModel(name);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
[name]
|
|
74
|
+
);
|
|
75
|
+
return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(
|
|
76
|
+
Group.default,
|
|
77
|
+
{
|
|
78
|
+
ref: ref || nodeRef,
|
|
79
|
+
id: name,
|
|
80
|
+
transform: `translate(${position[0]}, ${position[1]}) ${rotate ? `rotate(${rotate})` : ""}`,
|
|
81
|
+
children: [
|
|
82
|
+
useNodeShape.default(props, shapeRef),
|
|
83
|
+
useNodeContent.default(props, contentRef)
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
exports.default = InnerNode;
|
|
@@ -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,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const jsxRuntime = require("../../_virtual/jsx-runtime.cjs");
|
|
4
|
+
const require$$0 = require("react");
|
|
5
|
+
const InnerNode = require("./InnerNode.cjs");
|
|
6
|
+
const css = require("../../utils/css.cjs");
|
|
7
|
+
const stroke = require("../../utils/style/stroke.cjs");
|
|
8
|
+
const font = require("../../utils/style/font.cjs");
|
|
9
|
+
const DescartesPoint = require("../../model/geometry/point/DescartesPoint.cjs");
|
|
10
|
+
const useScope = require("../../hooks/context/useScope.cjs");
|
|
11
|
+
const color = require("../../node_modules/.pnpm/d3-color@3.1.0/node_modules/d3-color/src/color.cjs");
|
|
12
|
+
const Node = (props) => {
|
|
13
|
+
const { offset: scopeOffset, node } = useScope.default();
|
|
14
|
+
const nodeScopeProps = { offset: scopeOffset, ...node };
|
|
15
|
+
const realProps = {
|
|
16
|
+
...nodeScopeProps,
|
|
17
|
+
...props,
|
|
18
|
+
offset: DescartesPoint.default.plus(scopeOffset || [0, 0], props.offset || [0, 0])
|
|
19
|
+
};
|
|
20
|
+
const { shape = "rectangle", width, height, position, offset, innerSep, outerSep, ...res1Props } = realProps;
|
|
21
|
+
const { r, rx, ry, fill, fillOpacity, stroke: stroke$1 = "transparent", strokeWidth = 1, strokeType, ...res2Props } = res1Props;
|
|
22
|
+
const { color: color$1 = "currentColor", size, fontSize, fontStyle, fontFamily, style, ...otherProps } = res2Props;
|
|
23
|
+
const realPosition = require$$0.useMemo(() => {
|
|
24
|
+
const formatPosition = position ? DescartesPoint.default.formatPosition(position) : [0, 0];
|
|
25
|
+
const formatOffset = offset ? DescartesPoint.default.formatPosition(offset) : [0, 0];
|
|
26
|
+
return [formatPosition[0] + formatOffset[0], formatPosition[1] + formatOffset[1]];
|
|
27
|
+
}, [position]);
|
|
28
|
+
const realColor = require$$0.useMemo(() => {
|
|
29
|
+
if (color$1 === "auto" && fill && fill !== "currentColor") {
|
|
30
|
+
const fillColor = color.default(fill);
|
|
31
|
+
if (!fillColor) return color$1 || "currentColor";
|
|
32
|
+
fillColor.opacity = fillOpacity || 1;
|
|
33
|
+
const lightness = color.hsl(fillColor).l;
|
|
34
|
+
return lightness < 0.5 ? "white" : "black";
|
|
35
|
+
}
|
|
36
|
+
return color$1 || "currentColor";
|
|
37
|
+
}, [color$1, fill, fillOpacity]);
|
|
38
|
+
const realRx = rx || r;
|
|
39
|
+
const realRy = ry || r;
|
|
40
|
+
const getStrokeAttributes = () => strokeType ? stroke.convertStrokeType(strokeType, strokeWidth) : stroke.convertStrokeShortcut(otherProps, strokeWidth);
|
|
41
|
+
const getSep = (sep, defaultVal) => {
|
|
42
|
+
if (typeof sep !== "object") {
|
|
43
|
+
return {
|
|
44
|
+
left: sep ?? defaultVal,
|
|
45
|
+
right: sep ?? defaultVal,
|
|
46
|
+
top: sep ?? defaultVal,
|
|
47
|
+
bottom: sep ?? defaultVal
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
left: sep.left ?? sep.x ?? defaultVal,
|
|
52
|
+
right: sep.right ?? sep.x ?? defaultVal,
|
|
53
|
+
top: sep.top ?? sep.y ?? defaultVal,
|
|
54
|
+
bottom: sep.bottom ?? sep.y ?? defaultVal
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const getFontStyle = () => font.convertFontStyle(style);
|
|
58
|
+
const adjustFontSize = require$$0.useMemo(() => font.convertFontSize(size || fontSize), [size, fontSize]);
|
|
59
|
+
const adjustedInnerSep = require$$0.useMemo(
|
|
60
|
+
() => getSep(innerSep, css.convertCssToPx(adjustFontSize) / 3 || "0.3333em"),
|
|
61
|
+
[innerSep]
|
|
62
|
+
);
|
|
63
|
+
const adjustedOuterSep = require$$0.useMemo(() => getSep(outerSep, 0), [outerSep]);
|
|
64
|
+
return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
|
|
65
|
+
InnerNode.default,
|
|
66
|
+
{
|
|
67
|
+
width: css.convertCssToPx(width),
|
|
68
|
+
height: css.convertCssToPx(height),
|
|
69
|
+
shape,
|
|
70
|
+
position: realPosition,
|
|
71
|
+
color: realColor,
|
|
72
|
+
fill: fill || "transparent",
|
|
73
|
+
fillOpacity,
|
|
74
|
+
rx: realRx,
|
|
75
|
+
ry: realRy,
|
|
76
|
+
stroke: stroke$1,
|
|
77
|
+
strokeWidth,
|
|
78
|
+
innerSep: adjustedInnerSep,
|
|
79
|
+
outerSep: adjustedOuterSep,
|
|
80
|
+
size: adjustFontSize,
|
|
81
|
+
...getFontStyle(),
|
|
82
|
+
...getStrokeAttributes(),
|
|
83
|
+
...otherProps
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
exports.default = Node;
|