@retikz/core 0.0.1-rc.1 → 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.js +3 -2
- 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/segment/useConvertWay.d.ts +1 -1
- package/dist/es/components/draw/segment/useConvertWay.js +18 -7
- package/dist/es/components/draw/types.d.ts +1 -1
- package/dist/es/model/equation/line.js +1 -0
- package/dist/lib/components/Scope.cjs +2 -1
- 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/segment/useConvertWay.cjs +18 -7
- package/dist/lib/components/draw/segment/useConvertWay.d.ts +1 -1
- package/dist/lib/components/draw/types.d.ts +1 -1
- package/dist/lib/model/equation/line.cjs +1 -0
- package/package.json +8 -8
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef } from "react";
|
|
3
|
-
import { ScopeContext } from "../hooks/context/useScope.js";
|
|
3
|
+
import useScope, { ScopeContext } from "../hooks/context/useScope.js";
|
|
4
4
|
import Group from "../container/Group.js";
|
|
5
5
|
const Scope = forwardRef((props, ref) => {
|
|
6
6
|
const { children, ...resProps } = props;
|
|
7
|
-
|
|
7
|
+
const baseScopeValue = useScope();
|
|
8
|
+
return /* @__PURE__ */ jsx(ScopeContext.Provider, { value: { ...baseScopeValue, ...resProps }, children: /* @__PURE__ */ jsx(Group, { ref, children }) });
|
|
8
9
|
});
|
|
9
10
|
export {
|
|
10
11
|
Scope as default
|
|
@@ -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";
|
|
@@ -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,各种坐标,垂点,位移点
|
|
@@ -15,7 +15,13 @@ 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
27
|
const filterPoint = point.replace(/[+()[\]\s]/g, "");
|
|
@@ -37,13 +43,13 @@ 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
49
|
case "coordinate": {
|
|
44
50
|
const corPosition = formatPointPosition(item);
|
|
45
51
|
cursor = corPosition;
|
|
46
|
-
return corPosition;
|
|
52
|
+
return acc.concat(corPosition);
|
|
47
53
|
}
|
|
48
54
|
case "node": {
|
|
49
55
|
if (![0, way.length - 1].includes(index)) {
|
|
@@ -59,7 +65,7 @@ const useConvertWay = (way) => {
|
|
|
59
65
|
});
|
|
60
66
|
if (cb) subscribeCbs.push(cb);
|
|
61
67
|
cursor = nodeModel.center;
|
|
62
|
-
return nodeModel;
|
|
68
|
+
return acc.concat(nodeModel);
|
|
63
69
|
}
|
|
64
70
|
case "vertical": {
|
|
65
71
|
if ([0, way.length - 1].includes(index)) {
|
|
@@ -73,18 +79,23 @@ const useConvertWay = (way) => {
|
|
|
73
79
|
}
|
|
74
80
|
const afterPosition = afterPointType === "node" ? tryGetModel(afterPoint).center : formatPointPosition(afterPoint);
|
|
75
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
|
+
}
|
|
76
87
|
cursor = verPosition;
|
|
77
|
-
return
|
|
88
|
+
return acc.concat(verPosition);
|
|
78
89
|
}
|
|
79
90
|
default: {
|
|
80
91
|
if (index === 0) throw new Error("offset/move point can not be the first point on path.");
|
|
81
92
|
const convertedPos = convertOffsetAndMovePoint(item);
|
|
82
93
|
const curPos = DescartesPoint.plus(convertedPos, cursor);
|
|
83
94
|
if (type === "move") cursor = curPos;
|
|
84
|
-
return curPos;
|
|
95
|
+
return acc.concat(curPos);
|
|
85
96
|
}
|
|
86
97
|
}
|
|
87
|
-
}),
|
|
98
|
+
}, []),
|
|
88
99
|
[way, nodeUpdateCount.current]
|
|
89
100
|
);
|
|
90
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
|
/** 路径点类型:节点,坐标,垂点,偏移点,移动点 */
|
|
@@ -6,6 +6,7 @@ const useScope = require("../hooks/context/useScope.cjs");
|
|
|
6
6
|
const Group = require("../container/Group.cjs");
|
|
7
7
|
const Scope = react.forwardRef((props, ref) => {
|
|
8
8
|
const { children, ...resProps } = props;
|
|
9
|
-
|
|
9
|
+
const baseScopeValue = useScope.default();
|
|
10
|
+
return /* @__PURE__ */ jsxRuntime.jsx(useScope.ScopeContext.Provider, { value: { ...baseScopeValue, ...resProps }, children: /* @__PURE__ */ jsxRuntime.jsx(Group.default, { ref, children }) });
|
|
10
11
|
});
|
|
11
12
|
exports.default = Scope;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const getCirclePath = (attributes) => {
|
|
4
|
+
const {
|
|
5
|
+
width = 5,
|
|
6
|
+
left = false,
|
|
7
|
+
right = false,
|
|
8
|
+
scale = 1
|
|
9
|
+
} = attributes;
|
|
10
|
+
const radius = width / 2 * scale;
|
|
11
|
+
const diameter = width * scale;
|
|
12
|
+
const startPoint = [0, 0];
|
|
13
|
+
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`);
|
|
14
|
+
return {
|
|
15
|
+
d: path,
|
|
16
|
+
offsetDistance: radius,
|
|
17
|
+
insertDistance: radius
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
exports.default = getCirclePath;
|
|
@@ -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";
|
|
@@ -17,7 +17,13 @@ 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
29
|
const filterPoint = point.replace(/[+()[\]\s]/g, "");
|
|
@@ -39,13 +45,13 @@ const useConvertWay = (way) => {
|
|
|
39
45
|
const subscribeCbs = [];
|
|
40
46
|
let allNodeInit = true;
|
|
41
47
|
const result = react.useMemo(
|
|
42
|
-
() => way.
|
|
48
|
+
() => way.reduce((acc, item, index) => {
|
|
43
49
|
const type = common.getDrawPointType(item);
|
|
44
50
|
switch (type) {
|
|
45
51
|
case "coordinate": {
|
|
46
52
|
const corPosition = formatPointPosition(item);
|
|
47
53
|
cursor = corPosition;
|
|
48
|
-
return corPosition;
|
|
54
|
+
return acc.concat(corPosition);
|
|
49
55
|
}
|
|
50
56
|
case "node": {
|
|
51
57
|
if (![0, way.length - 1].includes(index)) {
|
|
@@ -61,7 +67,7 @@ const useConvertWay = (way) => {
|
|
|
61
67
|
});
|
|
62
68
|
if (cb) subscribeCbs.push(cb);
|
|
63
69
|
cursor = nodeModel.center;
|
|
64
|
-
return nodeModel;
|
|
70
|
+
return acc.concat(nodeModel);
|
|
65
71
|
}
|
|
66
72
|
case "vertical": {
|
|
67
73
|
if ([0, way.length - 1].includes(index)) {
|
|
@@ -75,18 +81,23 @@ const useConvertWay = (way) => {
|
|
|
75
81
|
}
|
|
76
82
|
const afterPosition = afterPointType === "node" ? tryGetModel(afterPoint).center : formatPointPosition(afterPoint);
|
|
77
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
|
+
}
|
|
78
89
|
cursor = verPosition;
|
|
79
|
-
return
|
|
90
|
+
return acc.concat(verPosition);
|
|
80
91
|
}
|
|
81
92
|
default: {
|
|
82
93
|
if (index === 0) throw new Error("offset/move point can not be the first point on path.");
|
|
83
94
|
const convertedPos = convertOffsetAndMovePoint(item);
|
|
84
95
|
const curPos = DescartesPoint.default.plus(convertedPos, cursor);
|
|
85
96
|
if (type === "move") cursor = curPos;
|
|
86
|
-
return curPos;
|
|
97
|
+
return acc.concat(curPos);
|
|
87
98
|
}
|
|
88
99
|
}
|
|
89
|
-
}),
|
|
100
|
+
}, []),
|
|
90
101
|
[way, nodeUpdateCount.current]
|
|
91
102
|
);
|
|
92
103
|
react.useLayoutEffect(() => () => {
|
|
@@ -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
|
/** 路径点类型:节点,坐标,垂点,偏移点,移动点 */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@retikz/core",
|
|
3
|
-
"version": "0.0.1-rc.
|
|
3
|
+
"version": "0.0.1-rc.2",
|
|
4
4
|
"description": "atomic drawing library implemented using react and d3, inspired by tikz",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"homepage": "https://pionpill.github.io/retikz.doc/",
|
|
@@ -22,12 +22,6 @@
|
|
|
22
22
|
"README.md",
|
|
23
23
|
"dist/**/*"
|
|
24
24
|
],
|
|
25
|
-
"scripts": {
|
|
26
|
-
"dev": "vite",
|
|
27
|
-
"build": "vite build",
|
|
28
|
-
"lint": "eslint .",
|
|
29
|
-
"preview": "vite preview"
|
|
30
|
-
},
|
|
31
25
|
"peerDependencies": {
|
|
32
26
|
"react": ">=18",
|
|
33
27
|
"react-dom": ">=18"
|
|
@@ -54,5 +48,11 @@
|
|
|
54
48
|
"typescript-eslint": "^8.15.0",
|
|
55
49
|
"vite": "^6.0.1",
|
|
56
50
|
"vite-plugin-dts": "^4.5.0"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"dev": "vite",
|
|
54
|
+
"build": "vite build",
|
|
55
|
+
"lint": "eslint .",
|
|
56
|
+
"preview": "vite preview"
|
|
57
57
|
}
|
|
58
|
-
}
|
|
58
|
+
}
|