@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,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
2
|
import { ScopeProps as ScopeContextProps } from '../hooks/context/useScope';
|
|
3
3
|
import { GroupProps } from '../container/Group';
|
|
4
4
|
export type ScopeProps = ScopeContextProps & Omit<GroupProps, 'offset'>;
|
|
5
|
-
declare const Scope:
|
|
5
|
+
declare const Scope: import('react').ForwardRefExoticComponent<Omit<PropsWithChildren<ScopeProps>, "ref"> & import('react').RefAttributes<SVGGElement>>;
|
|
6
6
|
export default Scope;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import useScope, { ScopeContext } from "../hooks/context/useScope.js";
|
|
3
4
|
import Group from "../container/Group.js";
|
|
4
|
-
const Scope = (props) => {
|
|
5
|
-
const { children,
|
|
6
|
-
|
|
7
|
-
};
|
|
5
|
+
const Scope = forwardRef((props, ref) => {
|
|
6
|
+
const { children, ...resProps } = props;
|
|
7
|
+
const baseScopeValue = useScope();
|
|
8
|
+
return /* @__PURE__ */ jsx(ScopeContext.Provider, { value: { ...baseScopeValue, ...resProps }, children: /* @__PURE__ */ jsx(Group, { ref, children }) });
|
|
9
|
+
});
|
|
8
10
|
export {
|
|
9
11
|
Scope as default
|
|
10
12
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import Surface from "../container/Surface.js";
|
|
3
3
|
import { CalculateContext } from "../hooks/context/useCalculate.js";
|
|
4
4
|
import { NodesContext } from "../hooks/context/useNodes.js";
|
|
5
5
|
import { ScopeContext } from "../hooks/context/useScope.js";
|
|
6
6
|
const TikZ = (props) => {
|
|
7
7
|
const { precision = 2, offset, node, draw, ...resProps } = props;
|
|
8
|
-
return /* @__PURE__ */
|
|
8
|
+
return /* @__PURE__ */ jsx(NodesContext.Provider, { value: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ jsx(CalculateContext.Provider, { value: { precision }, children: /* @__PURE__ */ jsx(ScopeContext.Provider, { value: { offset, node, draw }, children: /* @__PURE__ */ jsx(Surface, { ...resProps }) }) }) });
|
|
9
9
|
};
|
|
10
10
|
export {
|
|
11
11
|
TikZ as default
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
2
|
import { PointPosition } from '../../types/coordinate';
|
|
3
3
|
import { StrokeProps } from '../../types/svg/stroke';
|
|
4
4
|
import { StrokeShortcutProps, StrokeType } from '../../utils/style/stroke';
|
|
5
5
|
import { ArrowProps, DrawWayType } from './types';
|
|
6
6
|
export type DrawProps = {
|
|
7
|
-
ref?: Ref<SVGPathElement>;
|
|
8
7
|
way: DrawWayType[];
|
|
9
8
|
/** 位置偏移 */
|
|
10
9
|
offset?: PointPosition;
|
|
@@ -14,5 +13,14 @@ export type DrawProps = {
|
|
|
14
13
|
strokeType?: StrokeType;
|
|
15
14
|
children?: ReactElement | ReactElement[] | null;
|
|
16
15
|
} & StrokeProps & StrokeShortcutProps & ArrowProps;
|
|
17
|
-
declare const Draw:
|
|
16
|
+
declare const Draw: import('react').ForwardRefExoticComponent<{
|
|
17
|
+
way: DrawWayType[];
|
|
18
|
+
/** 位置偏移 */
|
|
19
|
+
offset?: PointPosition;
|
|
20
|
+
/** 同 stroke */
|
|
21
|
+
color?: string;
|
|
22
|
+
/** 线段样式快捷属性 */
|
|
23
|
+
strokeType?: StrokeType;
|
|
24
|
+
children?: ReactElement | ReactElement[] | null;
|
|
25
|
+
} & StrokeProps & StrokeShortcutProps & ArrowProps & import('react').RefAttributes<SVGPathElement>>;
|
|
18
26
|
export default Draw;
|
|
@@ -1,22 +1,47 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useMemo } from "react";
|
|
2
3
|
import useScope from "../../hooks/context/useScope.js";
|
|
3
4
|
import DescartesPoint from "../../model/geometry/point/DescartesPoint.js";
|
|
4
5
|
import { convertStrokeType, convertStrokeShortcut } from "../../utils/style/stroke.js";
|
|
5
6
|
import InnerDraw from "./InnerDraw.js";
|
|
6
|
-
const Draw = (props) => {
|
|
7
|
+
const Draw = forwardRef((props, ref) => {
|
|
7
8
|
const { draw: scopeProps } = useScope();
|
|
8
9
|
const realProps = { ...scopeProps, ...props };
|
|
9
|
-
const { offset, color, stroke, strokeWidth, startArrow, startArrows, endArrow, endArrows, ...
|
|
10
|
+
const { offset, color, stroke, strokeWidth, startArrow, startArrows, endArrow, endArrows, ...resProps } = realProps;
|
|
10
11
|
const realStroke = stroke || color;
|
|
11
12
|
const realStartArrow = typeof startArrow === "string" ? { type: startArrow } : startArrow;
|
|
12
13
|
const realStartArrows = typeof startArrows === "string" ? { type: startArrows } : startArrows;
|
|
13
14
|
const realEndArrow = typeof endArrow === "string" ? { type: endArrow } : endArrow;
|
|
14
15
|
const realEndArrows = typeof endArrows === "string" ? { type: endArrows } : endArrows;
|
|
15
16
|
const convertOffset = offset ? DescartesPoint.formatPosition(offset) : [0, 0];
|
|
16
|
-
const getStrokeTypes = () =>
|
|
17
|
-
|
|
17
|
+
const getStrokeTypes = () => resProps.strokeType ? convertStrokeType(resProps.strokeType, strokeWidth ?? 1) : convertStrokeShortcut(resProps, strokeWidth ?? 1);
|
|
18
|
+
const drawProps = useMemo(() => {
|
|
19
|
+
const props2 = { ...resProps };
|
|
20
|
+
[
|
|
21
|
+
"solid",
|
|
22
|
+
"dashed",
|
|
23
|
+
"denselyDashed",
|
|
24
|
+
"looselyDashed",
|
|
25
|
+
"dotted",
|
|
26
|
+
"denselyDotted",
|
|
27
|
+
"looselyDotted",
|
|
28
|
+
"dashDot",
|
|
29
|
+
"denselyDashDot",
|
|
30
|
+
"looselyDashDot",
|
|
31
|
+
"dashDashDot",
|
|
32
|
+
"denselyDashDashDot",
|
|
33
|
+
"looselyDashDashDot"
|
|
34
|
+
].forEach((key) => {
|
|
35
|
+
if (key in props2) {
|
|
36
|
+
delete props2[key];
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return props2;
|
|
40
|
+
}, [props]);
|
|
41
|
+
return /* @__PURE__ */ jsx(
|
|
18
42
|
InnerDraw,
|
|
19
43
|
{
|
|
44
|
+
ref,
|
|
20
45
|
...getStrokeTypes(),
|
|
21
46
|
offset: convertOffset,
|
|
22
47
|
stroke: realStroke,
|
|
@@ -28,7 +53,7 @@ const Draw = (props) => {
|
|
|
28
53
|
...drawProps
|
|
29
54
|
}
|
|
30
55
|
);
|
|
31
|
-
};
|
|
56
|
+
});
|
|
32
57
|
export {
|
|
33
58
|
Draw as default
|
|
34
59
|
};
|
|
@@ -1,13 +1,17 @@
|
|
|
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 { ArrowConfig, ArrowProps, DrawWayType } from './types';
|
|
5
5
|
export type InnerDrawProps = {
|
|
6
|
-
ref?: Ref<SVGPathElement>;
|
|
7
6
|
/** 位置偏移 */
|
|
8
7
|
offset: Position;
|
|
9
8
|
way: DrawWayType[];
|
|
10
9
|
children?: ReactNode;
|
|
11
10
|
} & StrokeProps & ArrowProps<ArrowConfig>;
|
|
12
|
-
declare const InnerDraw:
|
|
11
|
+
declare const InnerDraw: import('react').ForwardRefExoticComponent<{
|
|
12
|
+
/** 位置偏移 */
|
|
13
|
+
offset: Position;
|
|
14
|
+
way: DrawWayType[];
|
|
15
|
+
children?: ReactNode;
|
|
16
|
+
} & StrokeProps & ArrowProps<ArrowConfig> & import('react').RefAttributes<SVGPathElement>>;
|
|
13
17
|
export default InnerDraw;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useMemo } from "react";
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useMemo } from "react";
|
|
3
3
|
import Group from "../../container/Group.js";
|
|
4
4
|
import { PathContext } from "../../hooks/context/usePath.js";
|
|
5
5
|
import PathModel from "../../model/component/path.js";
|
|
6
6
|
import { getDrawPointType } from "./common.js";
|
|
7
7
|
import DrawSegment from "./segment/index.js";
|
|
8
|
-
const InnerDraw = (props) => {
|
|
9
|
-
const { way,
|
|
8
|
+
const InnerDraw = forwardRef((props, ref) => {
|
|
9
|
+
const { way, offset, startArrow, startArrows, endArrow, endArrows, children, ...strokeProps } = props;
|
|
10
10
|
const waySegments = useMemo(() => {
|
|
11
11
|
let preNodeType = "coordinate";
|
|
12
12
|
const waySegments2 = [];
|
|
@@ -26,22 +26,27 @@ const InnerDraw = (props) => {
|
|
|
26
26
|
}
|
|
27
27
|
return waySegments2;
|
|
28
28
|
}, [way]);
|
|
29
|
-
return /* @__PURE__ */
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
29
|
+
return /* @__PURE__ */ jsx(
|
|
30
|
+
PathContext.Provider,
|
|
31
|
+
{
|
|
32
|
+
value: new PathModel(new Array(waySegments.length).fill([]), Number(strokeProps.strokeWidth) || 1, false),
|
|
33
|
+
children: /* @__PURE__ */ jsxs(Group, { ref, transform: `translate(${offset[0]}, ${offset[1]})`, children: [
|
|
34
|
+
waySegments.map((segment, index) => /* @__PURE__ */ jsx(
|
|
35
|
+
DrawSegment,
|
|
36
|
+
{
|
|
37
|
+
index,
|
|
38
|
+
way: segment,
|
|
39
|
+
...strokeProps,
|
|
40
|
+
endArrow: index === waySegments.length - 1 ? endArrow || endArrows : endArrows,
|
|
41
|
+
startArrow: index === waySegments.length - 1 ? startArrow || startArrows : startArrows
|
|
42
|
+
},
|
|
43
|
+
JSON.stringify(segment)
|
|
44
|
+
)),
|
|
45
|
+
children
|
|
46
|
+
] })
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
});
|
|
45
50
|
export {
|
|
46
51
|
InnerDraw as default
|
|
47
52
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const getCirclePath = (attributes) => {
|
|
2
|
+
const {
|
|
3
|
+
width = 5,
|
|
4
|
+
left = false,
|
|
5
|
+
right = false,
|
|
6
|
+
scale = 1
|
|
7
|
+
} = attributes;
|
|
8
|
+
const radius = width / 2 * scale;
|
|
9
|
+
const diameter = width * scale;
|
|
10
|
+
const startPoint = [0, 0];
|
|
11
|
+
const path = `M ${startPoint.join(",")} ` + (left ? `A ${radius},${radius} 0 1,0 ${-diameter},0 Z` : right ? `A ${radius},${radius} 0 1,1 ${-diameter},0 Z` : `A ${radius},${radius} 0 1,0 ${-diameter},0A ${radius},${radius} 0 1,0 ${startPoint.join(",")} Z`);
|
|
12
|
+
return {
|
|
13
|
+
d: path,
|
|
14
|
+
offsetDistance: radius,
|
|
15
|
+
insertDistance: radius
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export {
|
|
19
|
+
getCirclePath as default
|
|
20
|
+
};
|
|
@@ -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;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import getCirclePath from "./circle.js";
|
|
1
2
|
import getStealthPath from "./stealth.js";
|
|
2
3
|
const getArrowPath = (type, attributes) => {
|
|
3
4
|
switch (type) {
|
|
4
5
|
case "Stealth":
|
|
5
6
|
return getStealthPath(attributes);
|
|
7
|
+
case "Circle":
|
|
8
|
+
return getCirclePath(attributes);
|
|
6
9
|
}
|
|
7
10
|
};
|
|
8
11
|
export {
|
|
@@ -2,7 +2,7 @@ const offsetReg = /\+[[(]?[+-]?\d+(?:\.\d+)?,\s*[+-]?\d+(?:\.\d+)?[)\]]?/;
|
|
|
2
2
|
const moveReg = /\+\+[[(]?[+-]?\d+(?:\.\d+)?,\s*[+-]?\d+(?:\.\d+)?[)\]]?/;
|
|
3
3
|
const getDrawPointType = (point) => {
|
|
4
4
|
if (typeof point !== "string") return "coordinate";
|
|
5
|
-
if (["-|", "|-"].includes(point)) return "vertical";
|
|
5
|
+
if (["-|", "|-", "-|-", "|-|"].includes(point)) return "vertical";
|
|
6
6
|
if (point.match(moveReg)) return "move";
|
|
7
7
|
if (point.match(offsetReg)) return "offset";
|
|
8
8
|
return "node";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useMemo } from "react";
|
|
3
3
|
import Path from "../../../elements/Path.js";
|
|
4
4
|
import Group from "../../../container/Group.js";
|
|
@@ -8,7 +8,7 @@ const InnerDrawSegment = (props) => {
|
|
|
8
8
|
const { way, startArrow, endArrow, ...strokeProps } = props;
|
|
9
9
|
const pickedArrowStrokeProps = {
|
|
10
10
|
stroke: strokeProps.stroke,
|
|
11
|
-
strokeWidth: strokeProps.strokeWidth,
|
|
11
|
+
strokeWidth: Number(strokeProps.strokeWidth),
|
|
12
12
|
strokeOpacity: strokeProps.strokeOpacity
|
|
13
13
|
};
|
|
14
14
|
const startArrowPath = useArrow(
|
|
@@ -30,11 +30,11 @@ const InnerDrawSegment = (props) => {
|
|
|
30
30
|
const straightLine = line().x((d2) => d2[0]).y((d2) => d2[1]);
|
|
31
31
|
return straightLine(realWay);
|
|
32
32
|
}, [way]);
|
|
33
|
-
return endArrowPath || startArrowPath ? /* @__PURE__ */
|
|
34
|
-
/* @__PURE__ */
|
|
33
|
+
return endArrowPath || startArrowPath ? /* @__PURE__ */ jsxs(Group, { children: [
|
|
34
|
+
/* @__PURE__ */ jsx(Path, { d: d ?? "", ...strokeProps }),
|
|
35
35
|
startArrowPath ? startArrowPath.arrowPath : null,
|
|
36
36
|
endArrowPath ? endArrowPath.arrowPath : null
|
|
37
|
-
] }) : /* @__PURE__ */
|
|
37
|
+
] }) : /* @__PURE__ */ jsx(Path, { d: d ?? "", ...strokeProps });
|
|
38
38
|
};
|
|
39
39
|
export {
|
|
40
40
|
InnerDrawSegment as default
|
|
@@ -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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useMemo } from "react";
|
|
3
3
|
import NodeModel from "../../../model/component/node.js";
|
|
4
4
|
import { convertStrokeType } from "../../../utils/style/stroke.js";
|
|
@@ -6,7 +6,7 @@ import InnerDrawSegment from "./Segment.js";
|
|
|
6
6
|
import useConvertWay from "./useConvertWay.js";
|
|
7
7
|
import usePath from "../../../hooks/context/usePath.js";
|
|
8
8
|
const DrawSegment = (props) => {
|
|
9
|
-
const { way, index,
|
|
9
|
+
const { way, index, startArrow, endArrow, ...resProps } = props;
|
|
10
10
|
const { strokeType = "solid", strokeWidth = 1, ...strokeProps } = resProps;
|
|
11
11
|
const [convertedWay, nodesInit] = useConvertWay(way);
|
|
12
12
|
const { model, updateModel } = usePath();
|
|
@@ -18,13 +18,13 @@ const DrawSegment = (props) => {
|
|
|
18
18
|
}
|
|
19
19
|
return wayPoint;
|
|
20
20
|
});
|
|
21
|
-
const newWay = [...model
|
|
21
|
+
const newWay = [...model.ways];
|
|
22
22
|
newWay[index] = realWay;
|
|
23
23
|
updateModel({ ways: newWay, init: nodesInit });
|
|
24
24
|
return realWay;
|
|
25
25
|
}, [convertedWay]);
|
|
26
26
|
if (!nodesInit) return null;
|
|
27
|
-
return /* @__PURE__ */
|
|
27
|
+
return /* @__PURE__ */ jsx(
|
|
28
28
|
InnerDrawSegment,
|
|
29
29
|
{
|
|
30
30
|
way: pointWay,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useMemo } from "react";
|
|
3
3
|
import useCalculate from "../../../hooks/context/useCalculate.js";
|
|
4
4
|
import getArrowPath from "../arrow/index.js";
|
|
@@ -31,7 +31,7 @@ const useArrow = (linkConfig, arrowConfig) => {
|
|
|
31
31
|
)}) rotate(${convertPrecision(degree * (180 / Math.PI), precision)})`;
|
|
32
32
|
return {
|
|
33
33
|
linkPoint,
|
|
34
|
-
arrowPath: /* @__PURE__ */
|
|
34
|
+
arrowPath: /* @__PURE__ */ jsx(
|
|
35
35
|
Path,
|
|
36
36
|
{
|
|
37
37
|
d,
|
|
@@ -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,各种坐标,垂点,位移点
|
|
@@ -6,7 +6,7 @@ import PolarPoint from "../../../model/geometry/point/PolarPoint.js";
|
|
|
6
6
|
import { getDrawPointType } from "../common.js";
|
|
7
7
|
const formatPointPosition = (point) => {
|
|
8
8
|
if (Array.isArray(point)) return point;
|
|
9
|
-
if (
|
|
9
|
+
if ("x" in point && "y" in point) {
|
|
10
10
|
const p = point;
|
|
11
11
|
return [p.x, p.y];
|
|
12
12
|
}
|
|
@@ -15,10 +15,16 @@ const formatPointPosition = (point) => {
|
|
|
15
15
|
const getVerticalPoint = (point1, point2, type) => {
|
|
16
16
|
const p1 = formatPointPosition(point1);
|
|
17
17
|
const p2 = formatPointPosition(point2);
|
|
18
|
-
return type === "-|" ? [p2[0], p1[1]] : [p1[0], p2[1]];
|
|
18
|
+
if (["-|", "|-"].includes(type)) return type === "-|" ? [p2[0], p1[1]] : [p1[0], p2[1]];
|
|
19
|
+
if (type === "-|-") {
|
|
20
|
+
const centerX = (p1[0] + p2[0]) / 2;
|
|
21
|
+
return [[centerX, p1[1]], [centerX, p2[1]]];
|
|
22
|
+
}
|
|
23
|
+
const centerY = (p1[1] + p2[1]) / 2;
|
|
24
|
+
return [[p1[0], centerY], [p2[0], centerY]];
|
|
19
25
|
};
|
|
20
26
|
const convertOffsetAndMovePoint = (point) => {
|
|
21
|
-
const filterPoint = point.replace(/[+()
|
|
27
|
+
const filterPoint = point.replace(/[+()[\]\s]/g, "");
|
|
22
28
|
return filterPoint.split(",").map((item) => parseFloat(item));
|
|
23
29
|
};
|
|
24
30
|
const useConvertWay = (way) => {
|
|
@@ -37,14 +43,15 @@ const useConvertWay = (way) => {
|
|
|
37
43
|
const subscribeCbs = [];
|
|
38
44
|
let allNodeInit = true;
|
|
39
45
|
const result = useMemo(
|
|
40
|
-
() => way.
|
|
46
|
+
() => way.reduce((acc, item, index) => {
|
|
41
47
|
const type = getDrawPointType(item);
|
|
42
48
|
switch (type) {
|
|
43
|
-
case "coordinate":
|
|
49
|
+
case "coordinate": {
|
|
44
50
|
const corPosition = formatPointPosition(item);
|
|
45
51
|
cursor = corPosition;
|
|
46
|
-
return corPosition;
|
|
47
|
-
|
|
52
|
+
return acc.concat(corPosition);
|
|
53
|
+
}
|
|
54
|
+
case "node": {
|
|
48
55
|
if (![0, way.length - 1].includes(index)) {
|
|
49
56
|
throw new Error(
|
|
50
57
|
"Node can only be the first or last point on DrawSegment component, this may be a retikz bug, please report it."
|
|
@@ -58,8 +65,9 @@ const useConvertWay = (way) => {
|
|
|
58
65
|
});
|
|
59
66
|
if (cb) subscribeCbs.push(cb);
|
|
60
67
|
cursor = nodeModel.center;
|
|
61
|
-
return nodeModel;
|
|
62
|
-
|
|
68
|
+
return acc.concat(nodeModel);
|
|
69
|
+
}
|
|
70
|
+
case "vertical": {
|
|
63
71
|
if ([0, way.length - 1].includes(index)) {
|
|
64
72
|
throw new Error("Vertical point can not be the first point on path.");
|
|
65
73
|
}
|
|
@@ -71,16 +79,23 @@ const useConvertWay = (way) => {
|
|
|
71
79
|
}
|
|
72
80
|
const afterPosition = afterPointType === "node" ? tryGetModel(afterPoint).center : formatPointPosition(afterPoint);
|
|
73
81
|
const verPosition = getVerticalPoint(beforePosition, afterPosition, item);
|
|
82
|
+
if (Array.isArray(verPosition[0])) {
|
|
83
|
+
const realVerPosition = verPosition;
|
|
84
|
+
cursor = realVerPosition[realVerPosition.length - 1];
|
|
85
|
+
return acc.concat(realVerPosition);
|
|
86
|
+
}
|
|
74
87
|
cursor = verPosition;
|
|
75
|
-
return
|
|
76
|
-
|
|
88
|
+
return acc.concat(verPosition);
|
|
89
|
+
}
|
|
90
|
+
default: {
|
|
77
91
|
if (index === 0) throw new Error("offset/move point can not be the first point on path.");
|
|
78
92
|
const convertedPos = convertOffsetAndMovePoint(item);
|
|
79
93
|
const curPos = DescartesPoint.plus(convertedPos, cursor);
|
|
80
94
|
if (type === "move") cursor = curPos;
|
|
81
|
-
return curPos;
|
|
95
|
+
return acc.concat(curPos);
|
|
96
|
+
}
|
|
82
97
|
}
|
|
83
|
-
}),
|
|
98
|
+
}, []),
|
|
84
99
|
[way, nodeUpdateCount.current]
|
|
85
100
|
);
|
|
86
101
|
useLayoutEffect(() => () => {
|
|
@@ -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,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,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useRef, useLayoutEffect } from "react";
|
|
1
|
+
import { jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useRef, useLayoutEffect } from "react";
|
|
3
3
|
import Group from "../../container/Group.js";
|
|
4
4
|
import useNodeShape from "./_hooks/useNodeShape.js";
|
|
5
5
|
import useNodeContent from "./_hooks/useNodeContent.js";
|
|
@@ -8,8 +8,8 @@ import { convertCssToPx } from "../../utils/css.js";
|
|
|
8
8
|
import useNodes from "../../hooks/context/useNodes.js";
|
|
9
9
|
import useCalculate from "../../hooks/context/useCalculate.js";
|
|
10
10
|
import { convertPrecision } from "../../utils/math.js";
|
|
11
|
-
const InnerNode = (props) => {
|
|
12
|
-
const { name,
|
|
11
|
+
const InnerNode = forwardRef((props, ref) => {
|
|
12
|
+
const { name, position, width, height, innerSep, outerSep, rotate } = props;
|
|
13
13
|
const nodeRef = useRef(null);
|
|
14
14
|
const shapeRef = useRef(null);
|
|
15
15
|
const contentRef = useRef(null);
|
|
@@ -70,7 +70,7 @@ const InnerNode = (props) => {
|
|
|
70
70
|
},
|
|
71
71
|
[name]
|
|
72
72
|
);
|
|
73
|
-
return /* @__PURE__ */
|
|
73
|
+
return /* @__PURE__ */ jsxs(
|
|
74
74
|
Group,
|
|
75
75
|
{
|
|
76
76
|
ref: ref || nodeRef,
|
|
@@ -82,7 +82,7 @@ const InnerNode = (props) => {
|
|
|
82
82
|
]
|
|
83
83
|
}
|
|
84
84
|
);
|
|
85
|
-
};
|
|
85
|
+
});
|
|
86
86
|
export {
|
|
87
87
|
InnerNode as default
|
|
88
88
|
};
|
|
@@ -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,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useMemo } from "react";
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useMemo } from "react";
|
|
3
3
|
import InnerNode from "./InnerNode.js";
|
|
4
4
|
import { convertCssToPx } from "../../utils/css.js";
|
|
5
5
|
import { convertStrokeType, convertStrokeShortcut } from "../../utils/style/stroke.js";
|
|
@@ -7,7 +7,7 @@ import { convertFontSize, convertFontStyle } from "../../utils/style/font.js";
|
|
|
7
7
|
import DescartesPoint from "../../model/geometry/point/DescartesPoint.js";
|
|
8
8
|
import useScope from "../../hooks/context/useScope.js";
|
|
9
9
|
import color, { hsl } from "../../node_modules/.pnpm/d3-color@3.1.0/node_modules/d3-color/src/color.js";
|
|
10
|
-
const Node = (props) => {
|
|
10
|
+
const Node = forwardRef((props, ref) => {
|
|
11
11
|
const { offset: scopeOffset, node } = useScope();
|
|
12
12
|
const nodeScopeProps = { offset: scopeOffset, ...node };
|
|
13
13
|
const realProps = {
|
|
@@ -17,7 +17,7 @@ const Node = (props) => {
|
|
|
17
17
|
};
|
|
18
18
|
const { shape = "rectangle", width, height, position, offset, innerSep, outerSep, ...res1Props } = realProps;
|
|
19
19
|
const { r, rx, ry, fill, fillOpacity, stroke = "transparent", strokeWidth = 1, strokeType, ...res2Props } = res1Props;
|
|
20
|
-
const { color: color$1 = "currentColor", size, fontSize,
|
|
20
|
+
const { color: color$1 = "currentColor", size, fontSize, style, ...otherProps } = res2Props;
|
|
21
21
|
const realPosition = useMemo(() => {
|
|
22
22
|
const formatPosition = position ? DescartesPoint.formatPosition(position) : [0, 0];
|
|
23
23
|
const formatOffset = offset ? DescartesPoint.formatPosition(offset) : [0, 0];
|
|
@@ -59,9 +59,10 @@ const Node = (props) => {
|
|
|
59
59
|
[innerSep]
|
|
60
60
|
);
|
|
61
61
|
const adjustedOuterSep = useMemo(() => getSep(outerSep, 0), [outerSep]);
|
|
62
|
-
return /* @__PURE__ */
|
|
62
|
+
return /* @__PURE__ */ jsx(
|
|
63
63
|
InnerNode,
|
|
64
64
|
{
|
|
65
|
+
ref,
|
|
65
66
|
width: convertCssToPx(width),
|
|
66
67
|
height: convertCssToPx(height),
|
|
67
68
|
shape,
|
|
@@ -81,7 +82,7 @@ const Node = (props) => {
|
|
|
81
82
|
...otherProps
|
|
82
83
|
}
|
|
83
84
|
);
|
|
84
|
-
};
|
|
85
|
+
});
|
|
85
86
|
export {
|
|
86
87
|
Node as default
|
|
87
88
|
};
|