@retikz/core 0.0.1-rc.0 → 0.0.1-rc.2
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/dist/es/components/Scope.d.ts +2 -2
- package/dist/es/components/Scope.js +8 -6
- package/dist/es/components/TikZ.js +2 -2
- package/dist/es/components/draw/Draw.d.ts +11 -3
- package/dist/es/components/draw/Draw.js +31 -6
- package/dist/es/components/draw/InnerDraw.d.ts +7 -3
- package/dist/es/components/draw/InnerDraw.js +25 -20
- package/dist/es/components/draw/arrow/circle.d.ts +7 -0
- package/dist/es/components/draw/arrow/circle.js +20 -0
- package/dist/es/components/draw/arrow/index.d.ts +1 -1
- package/dist/es/components/draw/arrow/index.js +3 -0
- package/dist/es/components/draw/common.js +1 -1
- package/dist/es/components/draw/index.js +4 -0
- package/dist/es/components/draw/segment/Segment.js +5 -5
- package/dist/es/components/draw/segment/index.d.ts +0 -4
- package/dist/es/components/draw/segment/index.js +4 -4
- package/dist/es/components/draw/segment/useArrow.js +2 -2
- package/dist/es/components/draw/segment/useConvertWay.d.ts +1 -1
- package/dist/es/components/draw/segment/useConvertWay.js +28 -13
- package/dist/es/components/draw/types.d.ts +1 -1
- package/dist/es/components/node/InnerNode.d.ts +2 -2
- package/dist/es/components/node/InnerNode.js +6 -6
- package/dist/es/components/node/Node.d.ts +42 -3
- package/dist/es/components/node/Node.js +7 -6
- package/dist/es/components/node/_hooks/useNodeConfig.d.ts +1 -1
- package/dist/es/components/node/_hooks/useNodeContent.js +6 -3
- package/dist/es/components/node/_hooks/useNodeShape.js +2 -2
- package/dist/es/components/{pathNode → path-node}/PathNode.d.ts +11 -2
- package/dist/es/components/{pathNode → path-node}/PathNode.js +6 -6
- package/dist/es/container/Group.d.ts +2 -2
- package/dist/es/container/Group.js +5 -4
- package/dist/es/container/Surface.d.ts +4 -2
- package/dist/es/container/Surface.js +7 -7
- package/dist/es/elements/Path.d.ts +2 -2
- package/dist/es/elements/Path.js +5 -4
- package/dist/es/elements/Rect.d.ts +3 -5
- package/dist/es/elements/Rect.js +6 -5
- package/dist/es/elements/Text.d.ts +2 -3
- package/dist/es/elements/Text.js +7 -7
- package/dist/es/hooks/useForceUpdate.d.ts +1 -1
- package/dist/es/index.d.ts +4 -4
- package/dist/es/index.js +1 -1
- package/dist/es/model/equation/line.js +1 -0
- package/dist/es/test.d.ts +1 -0
- package/dist/es/types/svg/stroke.d.ts +2 -2
- package/dist/es/utils/style/stroke.d.ts +4 -3
- package/dist/es/utils/style/stroke.js +4 -2
- package/dist/lib/components/Scope.cjs +7 -5
- package/dist/lib/components/Scope.d.ts +2 -2
- package/dist/lib/components/TikZ.cjs +2 -2
- package/dist/lib/components/draw/Draw.cjs +31 -6
- package/dist/lib/components/draw/Draw.d.ts +11 -3
- package/dist/lib/components/draw/InnerDraw.cjs +26 -21
- package/dist/lib/components/draw/InnerDraw.d.ts +7 -3
- package/dist/lib/components/draw/arrow/circle.cjs +20 -0
- package/dist/lib/components/draw/arrow/circle.d.ts +7 -0
- package/dist/lib/components/draw/arrow/index.cjs +3 -0
- package/dist/lib/components/draw/arrow/index.d.ts +1 -1
- package/dist/lib/components/draw/common.cjs +1 -1
- package/dist/lib/components/draw/index.cjs +4 -0
- package/dist/lib/components/draw/segment/Segment.cjs +7 -7
- package/dist/lib/components/draw/segment/index.cjs +6 -6
- package/dist/lib/components/draw/segment/index.d.ts +0 -4
- package/dist/lib/components/draw/segment/useArrow.cjs +4 -4
- package/dist/lib/components/draw/segment/useConvertWay.cjs +32 -17
- package/dist/lib/components/draw/segment/useConvertWay.d.ts +1 -1
- package/dist/lib/components/draw/types.d.ts +1 -1
- package/dist/lib/components/node/InnerNode.cjs +15 -15
- package/dist/lib/components/node/InnerNode.d.ts +2 -2
- package/dist/lib/components/node/Node.cjs +12 -11
- package/dist/lib/components/node/Node.d.ts +42 -3
- package/dist/lib/components/node/_hooks/useNodeConfig.cjs +2 -2
- package/dist/lib/components/node/_hooks/useNodeConfig.d.ts +1 -1
- package/dist/lib/components/node/_hooks/useNodeContent.cjs +9 -6
- package/dist/lib/components/node/_hooks/useNodeShape.cjs +4 -4
- package/dist/lib/components/{pathNode → path-node}/PathNode.cjs +12 -12
- package/dist/lib/components/{pathNode → path-node}/PathNode.d.ts +11 -2
- package/dist/lib/components/{pathNode → path-node}/useAnchor.cjs +4 -4
- package/dist/lib/container/Group.cjs +5 -4
- package/dist/lib/container/Group.d.ts +2 -2
- package/dist/lib/container/Surface.cjs +8 -8
- package/dist/lib/container/Surface.d.ts +4 -2
- package/dist/lib/elements/Path.cjs +5 -4
- package/dist/lib/elements/Path.d.ts +2 -2
- package/dist/lib/elements/Rect.cjs +6 -5
- package/dist/lib/elements/Rect.d.ts +3 -5
- package/dist/lib/elements/Text.cjs +8 -8
- package/dist/lib/elements/Text.d.ts +2 -3
- package/dist/lib/hooks/context/useCalculate.cjs +3 -3
- package/dist/lib/hooks/context/useNodes.cjs +3 -3
- package/dist/lib/hooks/context/usePath.cjs +3 -3
- package/dist/lib/hooks/context/useScope.cjs +3 -3
- package/dist/lib/hooks/useForceUpdate.cjs +2 -2
- package/dist/lib/hooks/useForceUpdate.d.ts +1 -1
- package/dist/lib/index.cjs +1 -1
- package/dist/lib/index.d.ts +4 -4
- package/dist/lib/model/equation/line.cjs +1 -0
- package/dist/lib/test.d.ts +1 -0
- package/dist/lib/types/svg/stroke.d.ts +2 -2
- package/dist/lib/utils/style/stroke.cjs +4 -2
- package/dist/lib/utils/style/stroke.d.ts +4 -3
- package/package.json +16 -15
- package/dist/es/_virtual/jsx-runtime.js +0 -5
- package/dist/es/_virtual/jsx-runtime2.js +0 -4
- package/dist/es/_virtual/react-jsx-runtime.development.js +0 -4
- package/dist/es/_virtual/react-jsx-runtime.production.js +0 -4
- package/dist/es/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.development.js +0 -20
- package/dist/es/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.production.js +0 -41
- package/dist/es/node_modules/.pnpm/react@19.0.0/node_modules/react/jsx-runtime.js +0 -17
- package/dist/lib/_virtual/jsx-runtime.cjs +0 -5
- package/dist/lib/_virtual/jsx-runtime2.cjs +0 -4
- package/dist/lib/_virtual/react-jsx-runtime.development.cjs +0 -4
- package/dist/lib/_virtual/react-jsx-runtime.production.cjs +0 -4
- package/dist/lib/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.development.cjs +0 -20
- package/dist/lib/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.production.cjs +0 -41
- package/dist/lib/node_modules/.pnpm/react@19.0.0/node_modules/react/jsx-runtime.cjs +0 -17
- /package/dist/es/components/{pathNode → path-node}/index.d.ts +0 -0
- /package/dist/es/components/{pathNode → path-node}/index.js +0 -0
- /package/dist/es/components/{pathNode → path-node}/useAnchor.d.ts +0 -0
- /package/dist/es/components/{pathNode → path-node}/useAnchor.js +0 -0
- /package/dist/lib/components/{pathNode → path-node}/index.cjs +0 -0
- /package/dist/lib/components/{pathNode → path-node}/index.d.ts +0 -0
- /package/dist/lib/components/{pathNode → path-node}/useAnchor.d.ts +0 -0
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const circle = require("./circle.cjs");
|
|
3
4
|
const stealth = require("./stealth.cjs");
|
|
4
5
|
const getArrowPath = (type, attributes) => {
|
|
5
6
|
switch (type) {
|
|
6
7
|
case "Stealth":
|
|
7
8
|
return stealth.default(attributes);
|
|
9
|
+
case "Circle":
|
|
10
|
+
return circle.default(attributes);
|
|
8
11
|
}
|
|
9
12
|
};
|
|
10
13
|
exports.default = getArrowPath;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ArrowAttributes, ArrowPathConfig } from './types';
|
|
2
2
|
export type { ArrowAttributes as ArrowPositionAttributes, ArrowPathConfig };
|
|
3
|
-
export type ArrowType = 'Stealth';
|
|
3
|
+
export type ArrowType = 'Stealth' | 'Circle';
|
|
4
4
|
declare const getArrowPath: (type: ArrowType, attributes: ArrowAttributes) => {
|
|
5
5
|
d: string;
|
|
6
6
|
offsetDistance: number;
|
|
@@ -4,7 +4,7 @@ const offsetReg = /\+[[(]?[+-]?\d+(?:\.\d+)?,\s*[+-]?\d+(?:\.\d+)?[)\]]?/;
|
|
|
4
4
|
const moveReg = /\+\+[[(]?[+-]?\d+(?:\.\d+)?,\s*[+-]?\d+(?:\.\d+)?[)\]]?/;
|
|
5
5
|
const getDrawPointType = (point) => {
|
|
6
6
|
if (typeof point !== "string") return "coordinate";
|
|
7
|
-
if (["-|", "|-"].includes(point)) return "vertical";
|
|
7
|
+
if (["-|", "|-", "-|-", "|-|"].includes(point)) return "vertical";
|
|
8
8
|
if (point.match(moveReg)) return "move";
|
|
9
9
|
if (point.match(offsetReg)) return "offset";
|
|
10
10
|
return "node";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
-
const jsxRuntime = require("
|
|
4
|
-
const
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
5
|
const Path = require("../../../elements/Path.cjs");
|
|
6
6
|
const Group = require("../../../container/Group.cjs");
|
|
7
7
|
const useArrow = require("./useArrow.cjs");
|
|
@@ -10,7 +10,7 @@ const InnerDrawSegment = (props) => {
|
|
|
10
10
|
const { way, startArrow, endArrow, ...strokeProps } = props;
|
|
11
11
|
const pickedArrowStrokeProps = {
|
|
12
12
|
stroke: strokeProps.stroke,
|
|
13
|
-
strokeWidth: strokeProps.strokeWidth,
|
|
13
|
+
strokeWidth: Number(strokeProps.strokeWidth),
|
|
14
14
|
strokeOpacity: strokeProps.strokeOpacity
|
|
15
15
|
};
|
|
16
16
|
const startArrowPath = useArrow.default(
|
|
@@ -21,7 +21,7 @@ const InnerDrawSegment = (props) => {
|
|
|
21
21
|
{ position: way[way.length - 1], nearPosition: way[way.length - 2], arrowType: "end" },
|
|
22
22
|
endArrow ? { ...pickedArrowStrokeProps, ...endArrow } : void 0
|
|
23
23
|
);
|
|
24
|
-
const d =
|
|
24
|
+
const d = react.useMemo(() => {
|
|
25
25
|
const realWay = [...way];
|
|
26
26
|
if (startArrowPath) {
|
|
27
27
|
realWay[0] = startArrowPath.linkPoint;
|
|
@@ -32,10 +32,10 @@ const InnerDrawSegment = (props) => {
|
|
|
32
32
|
const straightLine = line.default().x((d2) => d2[0]).y((d2) => d2[1]);
|
|
33
33
|
return straightLine(realWay);
|
|
34
34
|
}, [way]);
|
|
35
|
-
return endArrowPath || startArrowPath ? /* @__PURE__ */ jsxRuntime.
|
|
36
|
-
/* @__PURE__ */ jsxRuntime.
|
|
35
|
+
return endArrowPath || startArrowPath ? /* @__PURE__ */ jsxRuntime.jsxs(Group.default, { children: [
|
|
36
|
+
/* @__PURE__ */ jsxRuntime.jsx(Path.default, { d: d ?? "", ...strokeProps }),
|
|
37
37
|
startArrowPath ? startArrowPath.arrowPath : null,
|
|
38
38
|
endArrowPath ? endArrowPath.arrowPath : null
|
|
39
|
-
] }) : /* @__PURE__ */ jsxRuntime.
|
|
39
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsx(Path.default, { d: d ?? "", ...strokeProps });
|
|
40
40
|
};
|
|
41
41
|
exports.default = InnerDrawSegment;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
-
const jsxRuntime = require("
|
|
4
|
-
const
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
5
|
const node = require("../../../model/component/node.cjs");
|
|
6
6
|
const stroke = require("../../../utils/style/stroke.cjs");
|
|
7
7
|
const Segment = require("./Segment.cjs");
|
|
8
8
|
const useConvertWay = require("./useConvertWay.cjs");
|
|
9
9
|
const usePath = require("../../../hooks/context/usePath.cjs");
|
|
10
10
|
const DrawSegment = (props) => {
|
|
11
|
-
const { way, index,
|
|
11
|
+
const { way, index, startArrow, endArrow, ...resProps } = props;
|
|
12
12
|
const { strokeType = "solid", strokeWidth = 1, ...strokeProps } = resProps;
|
|
13
13
|
const [convertedWay, nodesInit] = useConvertWay.default(way);
|
|
14
14
|
const { model, updateModel } = usePath.default();
|
|
15
|
-
const pointWay =
|
|
15
|
+
const pointWay = react.useMemo(() => {
|
|
16
16
|
const realWay = convertedWay.map((wayPoint, index2) => {
|
|
17
17
|
if (wayPoint instanceof node.default) {
|
|
18
18
|
const neighborPoint = index2 === 0 ? convertedWay[1] : convertedWay[index2 - 1];
|
|
@@ -20,13 +20,13 @@ const DrawSegment = (props) => {
|
|
|
20
20
|
}
|
|
21
21
|
return wayPoint;
|
|
22
22
|
});
|
|
23
|
-
const newWay = [...model
|
|
23
|
+
const newWay = [...model.ways];
|
|
24
24
|
newWay[index] = realWay;
|
|
25
25
|
updateModel({ ways: newWay, init: nodesInit });
|
|
26
26
|
return realWay;
|
|
27
27
|
}, [convertedWay]);
|
|
28
28
|
if (!nodesInit) return null;
|
|
29
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
29
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
30
30
|
Segment.default,
|
|
31
31
|
{
|
|
32
32
|
way: pointWay,
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
2
|
import { StrokeProps } from '../../../types/svg/stroke';
|
|
3
|
-
import { TikZKey } from '../../../types/tikz';
|
|
4
3
|
import { ArrowConfig, DrawWaySegmentType } from '../types';
|
|
5
4
|
export type DrawSegmentProps = {
|
|
6
5
|
/** 路径,首位可以是 Node,其他必须是坐标 */
|
|
7
6
|
way: DrawWaySegmentType;
|
|
8
7
|
index: number;
|
|
9
|
-
isLastSegment: boolean;
|
|
10
|
-
/** 线段颜色 */
|
|
11
|
-
color?: TikZKey;
|
|
12
8
|
/** 线段样式 */
|
|
13
9
|
strokeType?: 'solid' | 'dashed' | 'dotted';
|
|
14
10
|
startArrow?: ArrowConfig;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
-
const jsxRuntime = require("
|
|
4
|
-
const
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
5
|
const useCalculate = require("../../../hooks/context/useCalculate.cjs");
|
|
6
6
|
const index = require("../arrow/index.cjs");
|
|
7
7
|
const Path = require("../../../elements/Path.cjs");
|
|
@@ -9,7 +9,7 @@ const line = require("../../../model/equation/line.cjs");
|
|
|
9
9
|
const math = require("../../../utils/math.cjs");
|
|
10
10
|
const useArrow = (linkConfig, arrowConfig) => {
|
|
11
11
|
const { precision } = useCalculate.default();
|
|
12
|
-
return
|
|
12
|
+
return react.useMemo(() => {
|
|
13
13
|
if (!arrowConfig) return null;
|
|
14
14
|
const { position, nearPosition } = linkConfig;
|
|
15
15
|
const { type, stroke, linkType = "end", round, strokeLinejoin, strokeWidth, ...strokeProps } = arrowConfig;
|
|
@@ -33,7 +33,7 @@ const useArrow = (linkConfig, arrowConfig) => {
|
|
|
33
33
|
)}) rotate(${math.convertPrecision(degree * (180 / Math.PI), precision)})`;
|
|
34
34
|
return {
|
|
35
35
|
linkPoint,
|
|
36
|
-
arrowPath: /* @__PURE__ */ jsxRuntime.
|
|
36
|
+
arrowPath: /* @__PURE__ */ jsxRuntime.jsx(
|
|
37
37
|
Path.default,
|
|
38
38
|
{
|
|
39
39
|
d,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
-
const
|
|
3
|
+
const react = require("react");
|
|
4
4
|
const useNodes = require("../../../hooks/context/useNodes.cjs");
|
|
5
5
|
const useForceUpdate = require("../../../hooks/useForceUpdate.cjs");
|
|
6
6
|
const DescartesPoint = require("../../../model/geometry/point/DescartesPoint.cjs");
|
|
@@ -8,7 +8,7 @@ const PolarPoint = require("../../../model/geometry/point/PolarPoint.cjs");
|
|
|
8
8
|
const common = require("../common.cjs");
|
|
9
9
|
const formatPointPosition = (point) => {
|
|
10
10
|
if (Array.isArray(point)) return point;
|
|
11
|
-
if (
|
|
11
|
+
if ("x" in point && "y" in point) {
|
|
12
12
|
const p = point;
|
|
13
13
|
return [p.x, p.y];
|
|
14
14
|
}
|
|
@@ -17,16 +17,22 @@ const formatPointPosition = (point) => {
|
|
|
17
17
|
const getVerticalPoint = (point1, point2, type) => {
|
|
18
18
|
const p1 = formatPointPosition(point1);
|
|
19
19
|
const p2 = formatPointPosition(point2);
|
|
20
|
-
return type === "-|" ? [p2[0], p1[1]] : [p1[0], p2[1]];
|
|
20
|
+
if (["-|", "|-"].includes(type)) return type === "-|" ? [p2[0], p1[1]] : [p1[0], p2[1]];
|
|
21
|
+
if (type === "-|-") {
|
|
22
|
+
const centerX = (p1[0] + p2[0]) / 2;
|
|
23
|
+
return [[centerX, p1[1]], [centerX, p2[1]]];
|
|
24
|
+
}
|
|
25
|
+
const centerY = (p1[1] + p2[1]) / 2;
|
|
26
|
+
return [[p1[0], centerY], [p2[0], centerY]];
|
|
21
27
|
};
|
|
22
28
|
const convertOffsetAndMovePoint = (point) => {
|
|
23
|
-
const filterPoint = point.replace(/[+()
|
|
29
|
+
const filterPoint = point.replace(/[+()[\]\s]/g, "");
|
|
24
30
|
return filterPoint.split(",").map((item) => parseFloat(item));
|
|
25
31
|
};
|
|
26
32
|
const useConvertWay = (way) => {
|
|
27
33
|
const { getModel, subscribeModel } = useNodes.default();
|
|
28
34
|
const forceUpdate = useForceUpdate.default();
|
|
29
|
-
const nodeUpdateCount =
|
|
35
|
+
const nodeUpdateCount = react.useRef(0);
|
|
30
36
|
let cursor = [0, 0];
|
|
31
37
|
const tryGetModel = (name) => {
|
|
32
38
|
const model = getModel(name);
|
|
@@ -38,15 +44,16 @@ const useConvertWay = (way) => {
|
|
|
38
44
|
};
|
|
39
45
|
const subscribeCbs = [];
|
|
40
46
|
let allNodeInit = true;
|
|
41
|
-
const result =
|
|
42
|
-
() => way.
|
|
47
|
+
const result = react.useMemo(
|
|
48
|
+
() => way.reduce((acc, item, index) => {
|
|
43
49
|
const type = common.getDrawPointType(item);
|
|
44
50
|
switch (type) {
|
|
45
|
-
case "coordinate":
|
|
51
|
+
case "coordinate": {
|
|
46
52
|
const corPosition = formatPointPosition(item);
|
|
47
53
|
cursor = corPosition;
|
|
48
|
-
return corPosition;
|
|
49
|
-
|
|
54
|
+
return acc.concat(corPosition);
|
|
55
|
+
}
|
|
56
|
+
case "node": {
|
|
50
57
|
if (![0, way.length - 1].includes(index)) {
|
|
51
58
|
throw new Error(
|
|
52
59
|
"Node can only be the first or last point on DrawSegment component, this may be a retikz bug, please report it."
|
|
@@ -60,8 +67,9 @@ const useConvertWay = (way) => {
|
|
|
60
67
|
});
|
|
61
68
|
if (cb) subscribeCbs.push(cb);
|
|
62
69
|
cursor = nodeModel.center;
|
|
63
|
-
return nodeModel;
|
|
64
|
-
|
|
70
|
+
return acc.concat(nodeModel);
|
|
71
|
+
}
|
|
72
|
+
case "vertical": {
|
|
65
73
|
if ([0, way.length - 1].includes(index)) {
|
|
66
74
|
throw new Error("Vertical point can not be the first point on path.");
|
|
67
75
|
}
|
|
@@ -73,19 +81,26 @@ const useConvertWay = (way) => {
|
|
|
73
81
|
}
|
|
74
82
|
const afterPosition = afterPointType === "node" ? tryGetModel(afterPoint).center : formatPointPosition(afterPoint);
|
|
75
83
|
const verPosition = getVerticalPoint(beforePosition, afterPosition, item);
|
|
84
|
+
if (Array.isArray(verPosition[0])) {
|
|
85
|
+
const realVerPosition = verPosition;
|
|
86
|
+
cursor = realVerPosition[realVerPosition.length - 1];
|
|
87
|
+
return acc.concat(realVerPosition);
|
|
88
|
+
}
|
|
76
89
|
cursor = verPosition;
|
|
77
|
-
return
|
|
78
|
-
|
|
90
|
+
return acc.concat(verPosition);
|
|
91
|
+
}
|
|
92
|
+
default: {
|
|
79
93
|
if (index === 0) throw new Error("offset/move point can not be the first point on path.");
|
|
80
94
|
const convertedPos = convertOffsetAndMovePoint(item);
|
|
81
95
|
const curPos = DescartesPoint.default.plus(convertedPos, cursor);
|
|
82
96
|
if (type === "move") cursor = curPos;
|
|
83
|
-
return curPos;
|
|
97
|
+
return acc.concat(curPos);
|
|
98
|
+
}
|
|
84
99
|
}
|
|
85
|
-
}),
|
|
100
|
+
}, []),
|
|
86
101
|
[way, nodeUpdateCount.current]
|
|
87
102
|
);
|
|
88
|
-
|
|
103
|
+
react.useLayoutEffect(() => () => {
|
|
89
104
|
subscribeCbs.forEach((cb) => cb && cb());
|
|
90
105
|
});
|
|
91
106
|
return [result, allNodeInit];
|
|
@@ -5,7 +5,7 @@ import { DrawWaySegmentType } from '../types';
|
|
|
5
5
|
/** 将坐标格式转换为笛卡尔坐标数组形式 */
|
|
6
6
|
export declare const formatPointPosition: (point: PointPosition) => Position;
|
|
7
7
|
/** 获取两点间的垂直点 */
|
|
8
|
-
export declare const getVerticalPoint: (point1: PointPosition, point2: PointPosition, type: "-|" | "|-") => Position;
|
|
8
|
+
export declare const getVerticalPoint: (point1: PointPosition, point2: PointPosition, type: "-|" | "|-" | "-|-" | "|-|") => Position | Position[];
|
|
9
9
|
/**
|
|
10
10
|
* 将特殊路径点转换为坐标,Node 节点转换为对应的 Model
|
|
11
11
|
* 目前支持的节点类型:node,各种坐标,垂点,位移点
|
|
@@ -7,7 +7,7 @@ export type ArrowConfig = {
|
|
|
7
7
|
fill?: string;
|
|
8
8
|
} & ArrowPositionAttributes & StrokeProps;
|
|
9
9
|
/** 垂直路径点,临近的节点不能都是特殊路径点 */
|
|
10
|
-
export type VerticalDrawPosition = '-|' | '|-';
|
|
10
|
+
export type VerticalDrawPosition = '-|' | '|-' | '-|-' | '|-|';
|
|
11
11
|
/** 偏移与移动点 */
|
|
12
12
|
export type OffSetOrMovePosition = string;
|
|
13
13
|
/** 路径点类型:节点,坐标,垂点,偏移点,移动点 */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
-
const jsxRuntime = require("
|
|
4
|
-
const
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
5
|
const Group = require("../../container/Group.cjs");
|
|
6
6
|
const useNodeShape = require("./_hooks/useNodeShape.cjs");
|
|
7
7
|
const useNodeContent = require("./_hooks/useNodeContent.cjs");
|
|
@@ -10,11 +10,11 @@ const css = require("../../utils/css.cjs");
|
|
|
10
10
|
const useNodes = require("../../hooks/context/useNodes.cjs");
|
|
11
11
|
const useCalculate = require("../../hooks/context/useCalculate.cjs");
|
|
12
12
|
const math = require("../../utils/math.cjs");
|
|
13
|
-
const InnerNode = (props) => {
|
|
14
|
-
const { name,
|
|
15
|
-
const nodeRef =
|
|
16
|
-
const shapeRef =
|
|
17
|
-
const contentRef =
|
|
13
|
+
const InnerNode = react.forwardRef((props, ref) => {
|
|
14
|
+
const { name, position, width, height, innerSep, outerSep, rotate } = props;
|
|
15
|
+
const nodeRef = react.useRef(null);
|
|
16
|
+
const shapeRef = react.useRef(null);
|
|
17
|
+
const contentRef = react.useRef(null);
|
|
18
18
|
const { getModel, updateModel, deleteModel } = useNodes.default();
|
|
19
19
|
const { precision } = useCalculate.default();
|
|
20
20
|
const nodeConfig = useNodeConfig.default();
|
|
@@ -23,7 +23,7 @@ const InnerNode = (props) => {
|
|
|
23
23
|
updateModel(name, nodeConfig.current, false);
|
|
24
24
|
}
|
|
25
25
|
const groupElement = ref && "current" in ref ? ref.current : nodeRef.current;
|
|
26
|
-
|
|
26
|
+
react.useLayoutEffect(() => {
|
|
27
27
|
const contentElement = contentRef.current;
|
|
28
28
|
if (!contentElement) return;
|
|
29
29
|
const { width: elementWidth, height: elementHeight } = contentElement.getBoundingClientRect();
|
|
@@ -40,13 +40,13 @@ const InnerNode = (props) => {
|
|
|
40
40
|
bottom: css.convertCssToPx(sep.bottom, { remPx, emPx, parentPx: height2 })
|
|
41
41
|
};
|
|
42
42
|
};
|
|
43
|
-
|
|
43
|
+
react.useLayoutEffect(() => {
|
|
44
44
|
nodeConfig.current.innerSep = getSep(innerSep);
|
|
45
45
|
}, [innerSep]);
|
|
46
|
-
|
|
46
|
+
react.useLayoutEffect(() => {
|
|
47
47
|
nodeConfig.current.outerSep = getSep(outerSep);
|
|
48
48
|
}, [outerSep]);
|
|
49
|
-
|
|
49
|
+
react.useLayoutEffect(() => {
|
|
50
50
|
var _a, _b, _c, _d;
|
|
51
51
|
const {
|
|
52
52
|
contentSize: [width2, height2],
|
|
@@ -61,10 +61,10 @@ const InnerNode = (props) => {
|
|
|
61
61
|
const realHeight = height2 + innerSep2.top + innerSep2.bottom;
|
|
62
62
|
(_d = shapeRef.current) == null ? void 0 : _d.setAttribute("height", math.convertPrecision(realHeight, precision).toString());
|
|
63
63
|
}, [nodeConfig.current.position, nodeConfig.current.contentSize, nodeConfig.current.innerSep]);
|
|
64
|
-
|
|
64
|
+
react.useLayoutEffect(() => {
|
|
65
65
|
if (name) updateModel(name, nodeConfig.current);
|
|
66
66
|
});
|
|
67
|
-
|
|
67
|
+
react.useLayoutEffect(
|
|
68
68
|
() => () => {
|
|
69
69
|
if (name) {
|
|
70
70
|
deleteModel(name);
|
|
@@ -72,7 +72,7 @@ const InnerNode = (props) => {
|
|
|
72
72
|
},
|
|
73
73
|
[name]
|
|
74
74
|
);
|
|
75
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
75
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
76
76
|
Group.default,
|
|
77
77
|
{
|
|
78
78
|
ref: ref || nodeRef,
|
|
@@ -84,5 +84,5 @@ const InnerNode = (props) => {
|
|
|
84
84
|
]
|
|
85
85
|
}
|
|
86
86
|
);
|
|
87
|
-
};
|
|
87
|
+
});
|
|
88
88
|
exports.default = InnerNode;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
2
|
import { Position } from '../../types/coordinate/descartes';
|
|
3
3
|
import { StrokeProps } from '../../types/svg/stroke';
|
|
4
4
|
import { TikZProps } from '../../types/tikz';
|
|
@@ -29,5 +29,5 @@ export type InnerNodeProps = {
|
|
|
29
29
|
outerSep: DirectionDistance<number | string>;
|
|
30
30
|
rotate?: number;
|
|
31
31
|
} & TikZProps & ContentProps & ShapeProps;
|
|
32
|
-
declare const InnerNode:
|
|
32
|
+
declare const InnerNode: import('react').ForwardRefExoticComponent<Omit<InnerNodeProps, "ref"> & import('react').RefAttributes<SVGGElement>>;
|
|
33
33
|
export default InnerNode;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
-
const jsxRuntime = require("
|
|
4
|
-
const
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
5
|
const InnerNode = require("./InnerNode.cjs");
|
|
6
6
|
const css = require("../../utils/css.cjs");
|
|
7
7
|
const stroke = require("../../utils/style/stroke.cjs");
|
|
@@ -9,7 +9,7 @@ const font = require("../../utils/style/font.cjs");
|
|
|
9
9
|
const DescartesPoint = require("../../model/geometry/point/DescartesPoint.cjs");
|
|
10
10
|
const useScope = require("../../hooks/context/useScope.cjs");
|
|
11
11
|
const color = require("../../node_modules/.pnpm/d3-color@3.1.0/node_modules/d3-color/src/color.cjs");
|
|
12
|
-
const Node = (props) => {
|
|
12
|
+
const Node = react.forwardRef((props, ref) => {
|
|
13
13
|
const { offset: scopeOffset, node } = useScope.default();
|
|
14
14
|
const nodeScopeProps = { offset: scopeOffset, ...node };
|
|
15
15
|
const realProps = {
|
|
@@ -19,13 +19,13 @@ const Node = (props) => {
|
|
|
19
19
|
};
|
|
20
20
|
const { shape = "rectangle", width, height, position, offset, innerSep, outerSep, ...res1Props } = realProps;
|
|
21
21
|
const { r, rx, ry, fill, fillOpacity, stroke: stroke$1 = "transparent", strokeWidth = 1, strokeType, ...res2Props } = res1Props;
|
|
22
|
-
const { color: color$1 = "currentColor", size, fontSize,
|
|
23
|
-
const realPosition =
|
|
22
|
+
const { color: color$1 = "currentColor", size, fontSize, style, ...otherProps } = res2Props;
|
|
23
|
+
const realPosition = react.useMemo(() => {
|
|
24
24
|
const formatPosition = position ? DescartesPoint.default.formatPosition(position) : [0, 0];
|
|
25
25
|
const formatOffset = offset ? DescartesPoint.default.formatPosition(offset) : [0, 0];
|
|
26
26
|
return [formatPosition[0] + formatOffset[0], formatPosition[1] + formatOffset[1]];
|
|
27
27
|
}, [position]);
|
|
28
|
-
const realColor =
|
|
28
|
+
const realColor = react.useMemo(() => {
|
|
29
29
|
if (color$1 === "auto" && fill && fill !== "currentColor") {
|
|
30
30
|
const fillColor = color.default(fill);
|
|
31
31
|
if (!fillColor) return color$1 || "currentColor";
|
|
@@ -55,15 +55,16 @@ const Node = (props) => {
|
|
|
55
55
|
};
|
|
56
56
|
};
|
|
57
57
|
const getFontStyle = () => font.convertFontStyle(style);
|
|
58
|
-
const adjustFontSize =
|
|
59
|
-
const adjustedInnerSep =
|
|
58
|
+
const adjustFontSize = react.useMemo(() => font.convertFontSize(size || fontSize), [size, fontSize]);
|
|
59
|
+
const adjustedInnerSep = react.useMemo(
|
|
60
60
|
() => getSep(innerSep, css.convertCssToPx(adjustFontSize) / 3 || "0.3333em"),
|
|
61
61
|
[innerSep]
|
|
62
62
|
);
|
|
63
|
-
const adjustedOuterSep =
|
|
64
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
63
|
+
const adjustedOuterSep = react.useMemo(() => getSep(outerSep, 0), [outerSep]);
|
|
64
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
65
65
|
InnerNode.default,
|
|
66
66
|
{
|
|
67
|
+
ref,
|
|
67
68
|
width: css.convertCssToPx(width),
|
|
68
69
|
height: css.convertCssToPx(height),
|
|
69
70
|
shape,
|
|
@@ -83,5 +84,5 @@ const Node = (props) => {
|
|
|
83
84
|
...otherProps
|
|
84
85
|
}
|
|
85
86
|
);
|
|
86
|
-
};
|
|
87
|
+
});
|
|
87
88
|
exports.default = Node;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
2
|
import { NodeShape } from './InnerNode';
|
|
3
3
|
import { CssDistanceType } from '../../types/distance';
|
|
4
4
|
import { SepProps } from '../../types/distance/sep';
|
|
@@ -10,7 +10,6 @@ import { TikZFontSize } from '../../utils/style/font';
|
|
|
10
10
|
import { FontProps } from '../../types/svg/font';
|
|
11
11
|
export type NodeProps = {
|
|
12
12
|
name?: TikZKey;
|
|
13
|
-
ref?: Ref<SVGGElement>;
|
|
14
13
|
/** 位置 */
|
|
15
14
|
position?: PointPosition;
|
|
16
15
|
/** 位置偏移 */
|
|
@@ -50,5 +49,45 @@ export type NodeProps = {
|
|
|
50
49
|
/** 样式 */
|
|
51
50
|
style?: 'bold' | 'italic' | 'serif' | 'sans-serif';
|
|
52
51
|
} & Partial<FontProps> & Partial<StrokeProps> & StrokeShortcutProps;
|
|
53
|
-
declare const Node:
|
|
52
|
+
declare const Node: import('react').ForwardRefExoticComponent<{
|
|
53
|
+
name?: TikZKey;
|
|
54
|
+
/** 位置 */
|
|
55
|
+
position?: PointPosition;
|
|
56
|
+
/** 位置偏移 */
|
|
57
|
+
offset?: PointPosition;
|
|
58
|
+
/** 内容宽度 */
|
|
59
|
+
width?: CssDistanceType;
|
|
60
|
+
/** 内容高度 */
|
|
61
|
+
height?: CssDistanceType;
|
|
62
|
+
/** 内容(文本)颜色 */
|
|
63
|
+
color?: "currentColor" | "auto" | string;
|
|
64
|
+
/** 内容(文本)透明度 */
|
|
65
|
+
opacity?: number;
|
|
66
|
+
/** 内容(文本)字体大小 */
|
|
67
|
+
size?: string | TikZFontSize | number;
|
|
68
|
+
/** 内容 */
|
|
69
|
+
children?: ReactNode;
|
|
70
|
+
/** 边框形状 */
|
|
71
|
+
shape?: NodeShape;
|
|
72
|
+
/** 边框圆角 */
|
|
73
|
+
r?: CssDistanceType;
|
|
74
|
+
/** 边框圆角-x */
|
|
75
|
+
rx?: CssDistanceType;
|
|
76
|
+
/** 边框圆角-y */
|
|
77
|
+
ry?: CssDistanceType;
|
|
78
|
+
/** 背景填充色,默认为 auto */
|
|
79
|
+
fill?: string | "auto";
|
|
80
|
+
/** 背景填充色透明度 */
|
|
81
|
+
fillOpacity?: number;
|
|
82
|
+
/** 边框样式 */
|
|
83
|
+
strokeType?: StrokeType;
|
|
84
|
+
/** 内边距 */
|
|
85
|
+
innerSep?: CssDistanceType | SepProps;
|
|
86
|
+
/** 外边距 */
|
|
87
|
+
outerSep?: CssDistanceType | SepProps;
|
|
88
|
+
/** 旋转 */
|
|
89
|
+
rotate?: number;
|
|
90
|
+
/** 样式 */
|
|
91
|
+
style?: "bold" | "italic" | "serif" | "sans-serif";
|
|
92
|
+
} & Partial<FontProps> & Partial<StrokeProps> & StrokeShortcutProps & import('react').RefAttributes<SVGGElement>>;
|
|
54
93
|
export default Node;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
-
const
|
|
3
|
+
const react = require("react");
|
|
4
4
|
const useNodeConfig = () => {
|
|
5
|
-
const configRef =
|
|
5
|
+
const configRef = react.useRef({
|
|
6
6
|
position: [0, 0],
|
|
7
7
|
contentSize: [0, 0],
|
|
8
8
|
innerSep: { left: 0, right: 0, top: 0, bottom: 0 },
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
-
const jsxRuntime = require("
|
|
4
|
-
const
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
5
|
const Text = require("../../../elements/Text.cjs");
|
|
6
6
|
const useNodeContent = (props, ref) => {
|
|
7
7
|
const { color, size, opacity, fontWeight, fontStyle, fontFamily, fontStretch, children } = props;
|
|
8
|
-
const isTextNode = children !== null && !
|
|
9
|
-
return
|
|
10
|
-
() => isTextNode ? /* @__PURE__ */ jsxRuntime.
|
|
8
|
+
const isTextNode = children !== null && !react.isValidElement(children);
|
|
9
|
+
return react.useMemo(
|
|
10
|
+
() => isTextNode ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
11
11
|
Text.default,
|
|
12
12
|
{
|
|
13
13
|
fill: color,
|
|
@@ -20,7 +20,10 @@ const useNodeContent = (props, ref) => {
|
|
|
20
20
|
ref,
|
|
21
21
|
children
|
|
22
22
|
}
|
|
23
|
-
) :
|
|
23
|
+
) : react.isValidElement(children) ? (
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
react.cloneElement(children, { ref })
|
|
26
|
+
) : children,
|
|
24
27
|
isTextNode ? [color, size, children] : [children]
|
|
25
28
|
);
|
|
26
29
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
-
const jsxRuntime = require("
|
|
4
|
-
const
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
5
|
const Rect = require("../../../elements/Rect.cjs");
|
|
6
6
|
const getShapeProps = (nodeProps) => {
|
|
7
7
|
const { rx, ry, fill, fillOpacity, stroke, strokeWidth, strokeOpacity } = nodeProps;
|
|
@@ -23,12 +23,12 @@ const getShapeProps = (nodeProps) => {
|
|
|
23
23
|
};
|
|
24
24
|
const useNodeShape = (props, ref) => {
|
|
25
25
|
const shapeProps = getShapeProps(props);
|
|
26
|
-
const Shape =
|
|
26
|
+
const Shape = react.useMemo(() => {
|
|
27
27
|
switch (props.shape) {
|
|
28
28
|
case "rectangle":
|
|
29
29
|
return Rect.default;
|
|
30
30
|
}
|
|
31
31
|
}, [props.shape, ...Object.values(shapeProps)]);
|
|
32
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
32
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Shape, { ref, ...shapeProps });
|
|
33
33
|
};
|
|
34
34
|
exports.default = useNodeShape;
|