@retikz/core 0.0.1-rc.0 → 0.0.1-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/dist/es/components/Scope.d.ts +2 -2
  2. package/dist/es/components/Scope.js +6 -5
  3. package/dist/es/components/TikZ.js +2 -2
  4. package/dist/es/components/draw/Draw.d.ts +11 -3
  5. package/dist/es/components/draw/Draw.js +31 -6
  6. package/dist/es/components/draw/InnerDraw.d.ts +7 -3
  7. package/dist/es/components/draw/InnerDraw.js +25 -20
  8. package/dist/es/components/draw/index.js +4 -0
  9. package/dist/es/components/draw/segment/Segment.js +5 -5
  10. package/dist/es/components/draw/segment/index.d.ts +0 -4
  11. package/dist/es/components/draw/segment/index.js +4 -4
  12. package/dist/es/components/draw/segment/useArrow.js +2 -2
  13. package/dist/es/components/draw/segment/useConvertWay.js +10 -6
  14. package/dist/es/components/node/InnerNode.d.ts +2 -2
  15. package/dist/es/components/node/InnerNode.js +6 -6
  16. package/dist/es/components/node/Node.d.ts +42 -3
  17. package/dist/es/components/node/Node.js +7 -6
  18. package/dist/es/components/node/_hooks/useNodeConfig.d.ts +1 -1
  19. package/dist/es/components/node/_hooks/useNodeContent.js +6 -3
  20. package/dist/es/components/node/_hooks/useNodeShape.js +2 -2
  21. package/dist/es/components/{pathNode → path-node}/PathNode.d.ts +11 -2
  22. package/dist/es/components/{pathNode → path-node}/PathNode.js +6 -6
  23. package/dist/es/container/Group.d.ts +2 -2
  24. package/dist/es/container/Group.js +5 -4
  25. package/dist/es/container/Surface.d.ts +4 -2
  26. package/dist/es/container/Surface.js +7 -7
  27. package/dist/es/elements/Path.d.ts +2 -2
  28. package/dist/es/elements/Path.js +5 -4
  29. package/dist/es/elements/Rect.d.ts +3 -5
  30. package/dist/es/elements/Rect.js +6 -5
  31. package/dist/es/elements/Text.d.ts +2 -3
  32. package/dist/es/elements/Text.js +7 -7
  33. package/dist/es/hooks/useForceUpdate.d.ts +1 -1
  34. package/dist/es/index.d.ts +4 -4
  35. package/dist/es/index.js +1 -1
  36. package/dist/es/test.d.ts +1 -0
  37. package/dist/es/types/svg/stroke.d.ts +2 -2
  38. package/dist/es/utils/style/stroke.d.ts +4 -3
  39. package/dist/es/utils/style/stroke.js +4 -2
  40. package/dist/lib/components/Scope.cjs +6 -5
  41. package/dist/lib/components/Scope.d.ts +2 -2
  42. package/dist/lib/components/TikZ.cjs +2 -2
  43. package/dist/lib/components/draw/Draw.cjs +31 -6
  44. package/dist/lib/components/draw/Draw.d.ts +11 -3
  45. package/dist/lib/components/draw/InnerDraw.cjs +26 -21
  46. package/dist/lib/components/draw/InnerDraw.d.ts +7 -3
  47. package/dist/lib/components/draw/index.cjs +4 -0
  48. package/dist/lib/components/draw/segment/Segment.cjs +7 -7
  49. package/dist/lib/components/draw/segment/index.cjs +6 -6
  50. package/dist/lib/components/draw/segment/index.d.ts +0 -4
  51. package/dist/lib/components/draw/segment/useArrow.cjs +4 -4
  52. package/dist/lib/components/draw/segment/useConvertWay.cjs +14 -10
  53. package/dist/lib/components/node/InnerNode.cjs +15 -15
  54. package/dist/lib/components/node/InnerNode.d.ts +2 -2
  55. package/dist/lib/components/node/Node.cjs +12 -11
  56. package/dist/lib/components/node/Node.d.ts +42 -3
  57. package/dist/lib/components/node/_hooks/useNodeConfig.cjs +2 -2
  58. package/dist/lib/components/node/_hooks/useNodeConfig.d.ts +1 -1
  59. package/dist/lib/components/node/_hooks/useNodeContent.cjs +9 -6
  60. package/dist/lib/components/node/_hooks/useNodeShape.cjs +4 -4
  61. package/dist/lib/components/{pathNode → path-node}/PathNode.cjs +12 -12
  62. package/dist/lib/components/{pathNode → path-node}/PathNode.d.ts +11 -2
  63. package/dist/lib/components/{pathNode → path-node}/useAnchor.cjs +4 -4
  64. package/dist/lib/container/Group.cjs +5 -4
  65. package/dist/lib/container/Group.d.ts +2 -2
  66. package/dist/lib/container/Surface.cjs +8 -8
  67. package/dist/lib/container/Surface.d.ts +4 -2
  68. package/dist/lib/elements/Path.cjs +5 -4
  69. package/dist/lib/elements/Path.d.ts +2 -2
  70. package/dist/lib/elements/Rect.cjs +6 -5
  71. package/dist/lib/elements/Rect.d.ts +3 -5
  72. package/dist/lib/elements/Text.cjs +8 -8
  73. package/dist/lib/elements/Text.d.ts +2 -3
  74. package/dist/lib/hooks/context/useCalculate.cjs +3 -3
  75. package/dist/lib/hooks/context/useNodes.cjs +3 -3
  76. package/dist/lib/hooks/context/usePath.cjs +3 -3
  77. package/dist/lib/hooks/context/useScope.cjs +3 -3
  78. package/dist/lib/hooks/useForceUpdate.cjs +2 -2
  79. package/dist/lib/hooks/useForceUpdate.d.ts +1 -1
  80. package/dist/lib/index.cjs +1 -1
  81. package/dist/lib/index.d.ts +4 -4
  82. package/dist/lib/test.d.ts +1 -0
  83. package/dist/lib/types/svg/stroke.d.ts +2 -2
  84. package/dist/lib/utils/style/stroke.cjs +4 -2
  85. package/dist/lib/utils/style/stroke.d.ts +4 -3
  86. package/package.json +9 -8
  87. package/dist/es/_virtual/jsx-runtime.js +0 -5
  88. package/dist/es/_virtual/jsx-runtime2.js +0 -4
  89. package/dist/es/_virtual/react-jsx-runtime.development.js +0 -4
  90. package/dist/es/_virtual/react-jsx-runtime.production.js +0 -4
  91. package/dist/es/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.development.js +0 -20
  92. package/dist/es/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.production.js +0 -41
  93. package/dist/es/node_modules/.pnpm/react@19.0.0/node_modules/react/jsx-runtime.js +0 -17
  94. package/dist/lib/_virtual/jsx-runtime.cjs +0 -5
  95. package/dist/lib/_virtual/jsx-runtime2.cjs +0 -4
  96. package/dist/lib/_virtual/react-jsx-runtime.development.cjs +0 -4
  97. package/dist/lib/_virtual/react-jsx-runtime.production.cjs +0 -4
  98. package/dist/lib/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.development.cjs +0 -20
  99. package/dist/lib/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.production.cjs +0 -41
  100. package/dist/lib/node_modules/.pnpm/react@19.0.0/node_modules/react/jsx-runtime.cjs +0 -17
  101. /package/dist/es/components/{pathNode → path-node}/index.d.ts +0 -0
  102. /package/dist/es/components/{pathNode → path-node}/index.js +0 -0
  103. /package/dist/es/components/{pathNode → path-node}/useAnchor.d.ts +0 -0
  104. /package/dist/es/components/{pathNode → path-node}/useAnchor.js +0 -0
  105. /package/dist/lib/components/{pathNode → path-node}/index.cjs +0 -0
  106. /package/dist/lib/components/{pathNode → path-node}/index.d.ts +0 -0
  107. /package/dist/lib/components/{pathNode → path-node}/useAnchor.d.ts +0 -0
@@ -1,6 +1,6 @@
1
- import { FC, PropsWithChildren } from 'react';
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: FC<PropsWithChildren<ScopeProps>>;
5
+ declare const Scope: import('react').ForwardRefExoticComponent<Omit<PropsWithChildren<ScopeProps>, "ref"> & import('react').RefAttributes<SVGGElement>>;
6
6
  export default Scope;
@@ -1,10 +1,11 @@
1
- import { j as jsxRuntimeExports } from "../_virtual/jsx-runtime.js";
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from "react";
2
3
  import { ScopeContext } from "../hooks/context/useScope.js";
3
4
  import Group from "../container/Group.js";
4
- const Scope = (props) => {
5
- const { children, ref, ...resProps } = props;
6
- return /* @__PURE__ */ jsxRuntimeExports.jsx(ScopeContext, { value: resProps, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Group, { ref, children }) });
7
- };
5
+ const Scope = forwardRef((props, ref) => {
6
+ const { children, ...resProps } = props;
7
+ return /* @__PURE__ */ jsx(ScopeContext.Provider, { value: resProps, children: /* @__PURE__ */ jsx(Group, { ref, children }) });
8
+ });
8
9
  export {
9
10
  Scope as default
10
11
  };
@@ -1,11 +1,11 @@
1
- import { j as jsxRuntimeExports } from "../_virtual/jsx-runtime.js";
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__ */ jsxRuntimeExports.jsx(NodesContext, { value: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ jsxRuntimeExports.jsx(CalculateContext, { value: { precision }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ScopeContext, { value: { offset, node, draw }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Surface, { ...resProps }) }) }) });
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 { FC, ReactElement, Ref } from 'react';
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: FC<DrawProps>;
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 { j as jsxRuntimeExports } from "../../_virtual/jsx-runtime.js";
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, ...drawProps } = realProps;
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 = () => drawProps.strokeType ? convertStrokeType(drawProps.strokeType, strokeWidth || 1) : convertStrokeShortcut(drawProps, strokeWidth || 1);
17
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
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 { FC, ReactNode, Ref } from 'react';
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: FC<InnerDrawProps>;
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 { j as jsxRuntimeExports } from "../../_virtual/jsx-runtime.js";
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, ref, offset, startArrow, startArrows, endArrow, endArrows, children, ...strokeProps } = props;
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__ */ jsxRuntimeExports.jsx(PathContext, { value: new PathModel(new Array(waySegments.length).fill([]), strokeProps.strokeWidth || 1, false), children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Group, { ref, transform: `translate(${offset[0]}, ${offset[1]})`, children: [
30
- waySegments.map((segment, index) => /* @__PURE__ */ jsxRuntimeExports.jsx(
31
- DrawSegment,
32
- {
33
- index,
34
- isLastSegment: index === waySegments.length - 1,
35
- way: segment,
36
- ...strokeProps,
37
- endArrow: index === waySegments.length - 1 ? endArrow || endArrows : endArrows,
38
- startArrow: index === waySegments.length - 1 ? startArrow || startArrows : startArrows
39
- },
40
- JSON.stringify(segment)
41
- )),
42
- children
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,4 @@
1
+ import Draw from "./Draw.js";
2
+ export {
3
+ Draw as default
4
+ };
@@ -1,4 +1,4 @@
1
- import { j as jsxRuntimeExports } from "../../../_virtual/jsx-runtime.js";
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__ */ jsxRuntimeExports.jsxs(Group, { children: [
34
- /* @__PURE__ */ jsxRuntimeExports.jsx(Path, { d: d ?? "", ...strokeProps }),
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__ */ jsxRuntimeExports.jsx(Path, { d: d ?? "", ...strokeProps });
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 { j as jsxRuntimeExports } from "../../../_virtual/jsx-runtime.js";
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, color, startArrow, endArrow, isLastSegment, ...resProps } = props;
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 == null ? void 0 : model.ways];
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__ */ jsxRuntimeExports.jsx(
27
+ return /* @__PURE__ */ jsx(
28
28
  InnerDrawSegment,
29
29
  {
30
30
  way: pointWay,
@@ -1,4 +1,4 @@
1
- import { j as jsxRuntimeExports } from "../../../_virtual/jsx-runtime.js";
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__ */ jsxRuntimeExports.jsx(
34
+ arrowPath: /* @__PURE__ */ jsx(
35
35
  Path,
36
36
  {
37
37
  d,
@@ -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 (point.hasOwnProperty("x") && point.hasOwnProperty("y")) {
9
+ if ("x" in point && "y" in point) {
10
10
  const p = point;
11
11
  return [p.x, p.y];
12
12
  }
@@ -18,7 +18,7 @@ const getVerticalPoint = (point1, point2, type) => {
18
18
  return type === "-|" ? [p2[0], p1[1]] : [p1[0], p2[1]];
19
19
  };
20
20
  const convertOffsetAndMovePoint = (point) => {
21
- const filterPoint = point.replace(/[+()\[\]\s]/g, "");
21
+ const filterPoint = point.replace(/[+()[\]\s]/g, "");
22
22
  return filterPoint.split(",").map((item) => parseFloat(item));
23
23
  };
24
24
  const useConvertWay = (way) => {
@@ -40,11 +40,12 @@ const useConvertWay = (way) => {
40
40
  () => way.map((item, index) => {
41
41
  const type = getDrawPointType(item);
42
42
  switch (type) {
43
- case "coordinate":
43
+ case "coordinate": {
44
44
  const corPosition = formatPointPosition(item);
45
45
  cursor = corPosition;
46
46
  return corPosition;
47
- case "node":
47
+ }
48
+ case "node": {
48
49
  if (![0, way.length - 1].includes(index)) {
49
50
  throw new Error(
50
51
  "Node can only be the first or last point on DrawSegment component, this may be a retikz bug, please report it."
@@ -59,7 +60,8 @@ const useConvertWay = (way) => {
59
60
  if (cb) subscribeCbs.push(cb);
60
61
  cursor = nodeModel.center;
61
62
  return nodeModel;
62
- case "vertical":
63
+ }
64
+ case "vertical": {
63
65
  if ([0, way.length - 1].includes(index)) {
64
66
  throw new Error("Vertical point can not be the first point on path.");
65
67
  }
@@ -73,12 +75,14 @@ const useConvertWay = (way) => {
73
75
  const verPosition = getVerticalPoint(beforePosition, afterPosition, item);
74
76
  cursor = verPosition;
75
77
  return cursor;
76
- default:
78
+ }
79
+ default: {
77
80
  if (index === 0) throw new Error("offset/move point can not be the first point on path.");
78
81
  const convertedPos = convertOffsetAndMovePoint(item);
79
82
  const curPos = DescartesPoint.plus(convertedPos, cursor);
80
83
  if (type === "move") cursor = curPos;
81
84
  return curPos;
85
+ }
82
86
  }
83
87
  }),
84
88
  [way, nodeUpdateCount.current]
@@ -1,4 +1,4 @@
1
- import { FC, ReactNode } from 'react';
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: FC<InnerNodeProps>;
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 { j as jsxRuntimeExports } from "../../_virtual/jsx-runtime.js";
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, ref, position, width, height, innerSep, outerSep, rotate } = props;
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__ */ jsxRuntimeExports.jsxs(
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 { FC, ReactNode, Ref } from 'react';
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: FC<NodeProps>;
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 { j as jsxRuntimeExports } from "../../_virtual/jsx-runtime.js";
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, fontStyle, fontFamily, style, ...otherProps } = res2Props;
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__ */ jsxRuntimeExports.jsx(
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
  };
@@ -1,3 +1,3 @@
1
1
  import { NodeConfig } from '../../../model/component/node';
2
- declare const useNodeConfig: () => import('react').RefObject<NodeConfig>;
2
+ declare const useNodeConfig: () => import('react').MutableRefObject<NodeConfig>;
3
3
  export default useNodeConfig;
@@ -1,11 +1,11 @@
1
- import { j as jsxRuntimeExports } from "../../../_virtual/jsx-runtime.js";
1
+ import { jsx } from "react/jsx-runtime";
2
2
  import { isValidElement, useMemo, cloneElement } from "react";
3
3
  import Text from "../../../elements/Text.js";
4
4
  const useNodeContent = (props, ref) => {
5
5
  const { color, size, opacity, fontWeight, fontStyle, fontFamily, fontStretch, children } = props;
6
6
  const isTextNode = children !== null && !isValidElement(children);
7
7
  return useMemo(
8
- () => isTextNode ? /* @__PURE__ */ jsxRuntimeExports.jsx(
8
+ () => isTextNode ? /* @__PURE__ */ jsx(
9
9
  Text,
10
10
  {
11
11
  fill: color,
@@ -18,7 +18,10 @@ const useNodeContent = (props, ref) => {
18
18
  ref,
19
19
  children
20
20
  }
21
- ) : isValidElement(children) ? cloneElement(children, { ref }) : children,
21
+ ) : isValidElement(children) ? (
22
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
+ cloneElement(children, { ref })
24
+ ) : children,
22
25
  isTextNode ? [color, size, children] : [children]
23
26
  );
24
27
  };
@@ -1,4 +1,4 @@
1
- import { j as jsxRuntimeExports } from "../../../_virtual/jsx-runtime.js";
1
+ import { jsx } from "react/jsx-runtime";
2
2
  import { useMemo } from "react";
3
3
  import Rect from "../../../elements/Rect.js";
4
4
  const getShapeProps = (nodeProps) => {
@@ -27,7 +27,7 @@ const useNodeShape = (props, ref) => {
27
27
  return Rect;
28
28
  }
29
29
  }, [props.shape, ...Object.values(shapeProps)]);
30
- return /* @__PURE__ */ jsxRuntimeExports.jsx(Shape, { ref, ...shapeProps });
30
+ return /* @__PURE__ */ jsx(Shape, { ref, ...shapeProps });
31
31
  };
32
32
  export {
33
33
  useNodeShape as default
@@ -1,4 +1,3 @@
1
- import { FC } from 'react';
2
1
  import { Direction } from '../../types/coordinate';
3
2
  import { Position } from '../../types/coordinate/descartes';
4
3
  import { NodeProps } from '../node/Node';
@@ -35,5 +34,15 @@ export type PathNodeProps = {
35
34
  /** 跟随箭头位置 */
36
35
  sloped?: boolean;
37
36
  } & PathNodePositionProps & PosShortcutProps & Omit<NodeProps, 'position'>;
38
- declare const PathNode: FC<PathNodeProps>;
37
+ declare const PathNode: import('react').ForwardRefExoticComponent<{
38
+ segmentIndex?: number;
39
+ /** path 片段的下标 */
40
+ pos?: number;
41
+ /** 相对于路径的位置 */
42
+ anchor?: Direction | "center";
43
+ /** 偏移位置 */
44
+ offset?: Position;
45
+ /** 跟随箭头位置 */
46
+ sloped?: boolean;
47
+ } & PathNodePositionProps & PosShortcutProps & Omit<NodeProps, "position"> & import('react').RefAttributes<SVGGElement>>;
39
48
  export default PathNode;
@@ -1,5 +1,5 @@
1
- import { j as jsxRuntimeExports } from "../../_virtual/jsx-runtime.js";
2
- import { useId, useMemo, useState, useLayoutEffect } from "react";
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { forwardRef, useId, useMemo, useState, useLayoutEffect } from "react";
3
3
  import useCalculate from "../../hooks/context/useCalculate.js";
4
4
  import useNodes from "../../hooks/context/useNodes.js";
5
5
  import useScope, { ScopeContext } from "../../hooks/context/useScope.js";
@@ -8,8 +8,8 @@ import { convertCssToPx } from "../../utils/css.js";
8
8
  import { convertPrecision } from "../../utils/math.js";
9
9
  import Node from "../node/Node.js";
10
10
  import useAnchor from "./useAnchor.js";
11
- const PathNode = (props) => {
12
- const { segmentIndex = -1, offset = [0, 0], anchor, ref, left, right, above, below, name, ...resProps } = props;
11
+ const PathNode = forwardRef((props, ref) => {
12
+ const { segmentIndex = -1, offset = [0, 0], anchor, left, right, above, below, name, ...resProps } = props;
13
13
  const { pos, veryNearStart, veryNearEnd, start, nearStart, midway, nearEnd, end, sloped, ...nodeProps } = resProps;
14
14
  const id = useId();
15
15
  const realName = name ?? id;
@@ -60,7 +60,7 @@ const PathNode = (props) => {
60
60
  setAdjustOffset(DescartesPoint.plus(anchorPosition, directionPosition, offset));
61
61
  }, [anchorPosition, directionPos]);
62
62
  const scope = useScope();
63
- return /* @__PURE__ */ jsxRuntimeExports.jsx(ScopeContext, { value: { ...scope, offset: [0, 0] }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
63
+ return /* @__PURE__ */ jsx(ScopeContext.Provider, { value: { ...scope, offset: [0, 0] }, children: /* @__PURE__ */ jsx(
64
64
  Node,
65
65
  {
66
66
  name: realName,
@@ -70,7 +70,7 @@ const PathNode = (props) => {
70
70
  ...nodeProps
71
71
  }
72
72
  ) });
73
- };
73
+ });
74
74
  export {
75
75
  PathNode as default
76
76
  };