@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.
Files changed (123) hide show
  1. package/dist/es/components/Scope.d.ts +2 -2
  2. package/dist/es/components/Scope.js +8 -6
  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/arrow/circle.d.ts +7 -0
  9. package/dist/es/components/draw/arrow/circle.js +20 -0
  10. package/dist/es/components/draw/arrow/index.d.ts +1 -1
  11. package/dist/es/components/draw/arrow/index.js +3 -0
  12. package/dist/es/components/draw/common.js +1 -1
  13. package/dist/es/components/draw/index.js +4 -0
  14. package/dist/es/components/draw/segment/Segment.js +5 -5
  15. package/dist/es/components/draw/segment/index.d.ts +0 -4
  16. package/dist/es/components/draw/segment/index.js +4 -4
  17. package/dist/es/components/draw/segment/useArrow.js +2 -2
  18. package/dist/es/components/draw/segment/useConvertWay.d.ts +1 -1
  19. package/dist/es/components/draw/segment/useConvertWay.js +28 -13
  20. package/dist/es/components/draw/types.d.ts +1 -1
  21. package/dist/es/components/node/InnerNode.d.ts +2 -2
  22. package/dist/es/components/node/InnerNode.js +6 -6
  23. package/dist/es/components/node/Node.d.ts +42 -3
  24. package/dist/es/components/node/Node.js +7 -6
  25. package/dist/es/components/node/_hooks/useNodeConfig.d.ts +1 -1
  26. package/dist/es/components/node/_hooks/useNodeContent.js +6 -3
  27. package/dist/es/components/node/_hooks/useNodeShape.js +2 -2
  28. package/dist/es/components/{pathNode → path-node}/PathNode.d.ts +11 -2
  29. package/dist/es/components/{pathNode → path-node}/PathNode.js +6 -6
  30. package/dist/es/container/Group.d.ts +2 -2
  31. package/dist/es/container/Group.js +5 -4
  32. package/dist/es/container/Surface.d.ts +4 -2
  33. package/dist/es/container/Surface.js +7 -7
  34. package/dist/es/elements/Path.d.ts +2 -2
  35. package/dist/es/elements/Path.js +5 -4
  36. package/dist/es/elements/Rect.d.ts +3 -5
  37. package/dist/es/elements/Rect.js +6 -5
  38. package/dist/es/elements/Text.d.ts +2 -3
  39. package/dist/es/elements/Text.js +7 -7
  40. package/dist/es/hooks/useForceUpdate.d.ts +1 -1
  41. package/dist/es/index.d.ts +4 -4
  42. package/dist/es/index.js +1 -1
  43. package/dist/es/model/equation/line.js +1 -0
  44. package/dist/es/test.d.ts +1 -0
  45. package/dist/es/types/svg/stroke.d.ts +2 -2
  46. package/dist/es/utils/style/stroke.d.ts +4 -3
  47. package/dist/es/utils/style/stroke.js +4 -2
  48. package/dist/lib/components/Scope.cjs +7 -5
  49. package/dist/lib/components/Scope.d.ts +2 -2
  50. package/dist/lib/components/TikZ.cjs +2 -2
  51. package/dist/lib/components/draw/Draw.cjs +31 -6
  52. package/dist/lib/components/draw/Draw.d.ts +11 -3
  53. package/dist/lib/components/draw/InnerDraw.cjs +26 -21
  54. package/dist/lib/components/draw/InnerDraw.d.ts +7 -3
  55. package/dist/lib/components/draw/arrow/circle.cjs +20 -0
  56. package/dist/lib/components/draw/arrow/circle.d.ts +7 -0
  57. package/dist/lib/components/draw/arrow/index.cjs +3 -0
  58. package/dist/lib/components/draw/arrow/index.d.ts +1 -1
  59. package/dist/lib/components/draw/common.cjs +1 -1
  60. package/dist/lib/components/draw/index.cjs +4 -0
  61. package/dist/lib/components/draw/segment/Segment.cjs +7 -7
  62. package/dist/lib/components/draw/segment/index.cjs +6 -6
  63. package/dist/lib/components/draw/segment/index.d.ts +0 -4
  64. package/dist/lib/components/draw/segment/useArrow.cjs +4 -4
  65. package/dist/lib/components/draw/segment/useConvertWay.cjs +32 -17
  66. package/dist/lib/components/draw/segment/useConvertWay.d.ts +1 -1
  67. package/dist/lib/components/draw/types.d.ts +1 -1
  68. package/dist/lib/components/node/InnerNode.cjs +15 -15
  69. package/dist/lib/components/node/InnerNode.d.ts +2 -2
  70. package/dist/lib/components/node/Node.cjs +12 -11
  71. package/dist/lib/components/node/Node.d.ts +42 -3
  72. package/dist/lib/components/node/_hooks/useNodeConfig.cjs +2 -2
  73. package/dist/lib/components/node/_hooks/useNodeConfig.d.ts +1 -1
  74. package/dist/lib/components/node/_hooks/useNodeContent.cjs +9 -6
  75. package/dist/lib/components/node/_hooks/useNodeShape.cjs +4 -4
  76. package/dist/lib/components/{pathNode → path-node}/PathNode.cjs +12 -12
  77. package/dist/lib/components/{pathNode → path-node}/PathNode.d.ts +11 -2
  78. package/dist/lib/components/{pathNode → path-node}/useAnchor.cjs +4 -4
  79. package/dist/lib/container/Group.cjs +5 -4
  80. package/dist/lib/container/Group.d.ts +2 -2
  81. package/dist/lib/container/Surface.cjs +8 -8
  82. package/dist/lib/container/Surface.d.ts +4 -2
  83. package/dist/lib/elements/Path.cjs +5 -4
  84. package/dist/lib/elements/Path.d.ts +2 -2
  85. package/dist/lib/elements/Rect.cjs +6 -5
  86. package/dist/lib/elements/Rect.d.ts +3 -5
  87. package/dist/lib/elements/Text.cjs +8 -8
  88. package/dist/lib/elements/Text.d.ts +2 -3
  89. package/dist/lib/hooks/context/useCalculate.cjs +3 -3
  90. package/dist/lib/hooks/context/useNodes.cjs +3 -3
  91. package/dist/lib/hooks/context/usePath.cjs +3 -3
  92. package/dist/lib/hooks/context/useScope.cjs +3 -3
  93. package/dist/lib/hooks/useForceUpdate.cjs +2 -2
  94. package/dist/lib/hooks/useForceUpdate.d.ts +1 -1
  95. package/dist/lib/index.cjs +1 -1
  96. package/dist/lib/index.d.ts +4 -4
  97. package/dist/lib/model/equation/line.cjs +1 -0
  98. package/dist/lib/test.d.ts +1 -0
  99. package/dist/lib/types/svg/stroke.d.ts +2 -2
  100. package/dist/lib/utils/style/stroke.cjs +4 -2
  101. package/dist/lib/utils/style/stroke.d.ts +4 -3
  102. package/package.json +16 -15
  103. package/dist/es/_virtual/jsx-runtime.js +0 -5
  104. package/dist/es/_virtual/jsx-runtime2.js +0 -4
  105. package/dist/es/_virtual/react-jsx-runtime.development.js +0 -4
  106. package/dist/es/_virtual/react-jsx-runtime.production.js +0 -4
  107. package/dist/es/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.development.js +0 -20
  108. package/dist/es/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.production.js +0 -41
  109. package/dist/es/node_modules/.pnpm/react@19.0.0/node_modules/react/jsx-runtime.js +0 -17
  110. package/dist/lib/_virtual/jsx-runtime.cjs +0 -5
  111. package/dist/lib/_virtual/jsx-runtime2.cjs +0 -4
  112. package/dist/lib/_virtual/react-jsx-runtime.development.cjs +0 -4
  113. package/dist/lib/_virtual/react-jsx-runtime.production.cjs +0 -4
  114. package/dist/lib/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.development.cjs +0 -20
  115. package/dist/lib/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.production.cjs +0 -41
  116. package/dist/lib/node_modules/.pnpm/react@19.0.0/node_modules/react/jsx-runtime.cjs +0 -17
  117. /package/dist/es/components/{pathNode → path-node}/index.d.ts +0 -0
  118. /package/dist/es/components/{pathNode → path-node}/index.js +0 -0
  119. /package/dist/es/components/{pathNode → path-node}/useAnchor.d.ts +0 -0
  120. /package/dist/es/components/{pathNode → path-node}/useAnchor.js +0 -0
  121. /package/dist/lib/components/{pathNode → path-node}/index.cjs +0 -0
  122. /package/dist/lib/components/{pathNode → path-node}/index.d.ts +0 -0
  123. /package/dist/lib/components/{pathNode → path-node}/useAnchor.d.ts +0 -0
@@ -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
  };
@@ -1,6 +1,6 @@
1
- import { FC, PropsWithChildren, Ref, SVGProps } from 'react';
1
+ import { PropsWithChildren, Ref, SVGProps } from 'react';
2
2
  export type GroupProps = {
3
3
  ref?: Ref<SVGGElement>;
4
4
  } & SVGProps<SVGGElement>;
5
- declare const Group: FC<PropsWithChildren<GroupProps>>;
5
+ declare const Group: import('react').ForwardRefExoticComponent<Omit<PropsWithChildren<SVGProps<SVGGElement>>, "ref"> & import('react').RefAttributes<SVGGElement>>;
6
6
  export default Group;
@@ -1,7 +1,8 @@
1
- import { j as jsxRuntimeExports } from "../_virtual/jsx-runtime.js";
2
- const Group = (props) => {
3
- return /* @__PURE__ */ jsxRuntimeExports.jsx("g", { ...props });
4
- };
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from "react";
3
+ const Group = forwardRef((props, ref) => {
4
+ return /* @__PURE__ */ jsx("g", { ref, ...props });
5
+ });
5
6
  export {
6
7
  Group as default
7
8
  };
@@ -1,4 +1,4 @@
1
- import { CSSProperties, FC, PropsWithChildren } from 'react';
1
+ import { CSSProperties } from 'react';
2
2
  export type SurfaceProps = {
3
3
  title?: string;
4
4
  desc?: string;
@@ -13,5 +13,7 @@ export type SurfaceProps = {
13
13
  className?: string;
14
14
  style?: CSSProperties;
15
15
  };
16
- declare const Surface: FC<PropsWithChildren<SurfaceProps>>;
16
+ declare const Surface: import('react').ForwardRefExoticComponent<SurfaceProps & {
17
+ children?: import('react').ReactNode | undefined;
18
+ } & import('react').RefAttributes<SVGSVGElement>>;
17
19
  export default Surface;
@@ -1,6 +1,6 @@
1
- import { j as jsxRuntimeExports } from "../_virtual/jsx-runtime.js";
2
- import { useMemo } from "react";
3
- const Surface = (props) => {
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { forwardRef, useMemo } from "react";
3
+ const Surface = forwardRef((props, ref) => {
4
4
  const { title, desc, viewBox, children, width, height, ...otherProps } = props;
5
5
  const svgViewBox = useMemo(() => {
6
6
  if (!(viewBox == null ? void 0 : viewBox.x) && !(viewBox == null ? void 0 : viewBox.y)) {
@@ -12,12 +12,12 @@ const Surface = (props) => {
12
12
  const viewHeight = (viewBox == null ? void 0 : viewBox.height) || height;
13
13
  return viewWidth === void 0 || viewHeight === void 0 ? [viewX, viewY].join(" ") : [viewX, viewY, viewWidth, viewHeight].join(" ");
14
14
  }, [width, height, viewBox]);
15
- return /* @__PURE__ */ jsxRuntimeExports.jsxs("svg", { viewBox: svgViewBox, width, height, ...otherProps, children: [
16
- title ? /* @__PURE__ */ jsxRuntimeExports.jsx("title", { children: title }) : null,
17
- desc ? /* @__PURE__ */ jsxRuntimeExports.jsx("desc", { children: desc }) : null,
15
+ return /* @__PURE__ */ jsxs("svg", { ref, viewBox: svgViewBox, width, height, ...otherProps, children: [
16
+ title ? /* @__PURE__ */ jsx("title", { children: title }) : null,
17
+ desc ? /* @__PURE__ */ jsx("desc", { children: desc }) : null,
18
18
  children
19
19
  ] });
20
- };
20
+ });
21
21
  export {
22
22
  Surface as default
23
23
  };
@@ -1,4 +1,4 @@
1
- import { FC, SVGProps } from 'react';
1
+ import { SVGProps } from 'react';
2
2
  export type PathProps = {} & SVGProps<SVGPathElement>;
3
- declare const Path: FC<PathProps>;
3
+ declare const Path: import('react').ForwardRefExoticComponent<Omit<SVGProps<SVGPathElement>, "ref"> & import('react').RefAttributes<SVGPathElement>>;
4
4
  export default Path;
@@ -1,13 +1,14 @@
1
- import { j as jsxRuntimeExports } from "../_virtual/jsx-runtime.js";
2
- const Path = (props) => {
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from "react";
3
+ const Path = forwardRef((props, ref) => {
3
4
  const { fill: propFill, strokeWidth: propStrokeWidth, stroke: propStroke, ...otherProps } = props;
4
5
  const defaultProps = {
5
6
  fill: propFill || "transparent",
6
7
  strokeWidth: propStrokeWidth ?? 1,
7
8
  stroke: propStroke || "currentColor"
8
9
  };
9
- return /* @__PURE__ */ jsxRuntimeExports.jsx("path", { ...defaultProps, ...otherProps });
10
- };
10
+ return /* @__PURE__ */ jsx("path", { ref, ...defaultProps, ...otherProps });
11
+ });
11
12
  export {
12
13
  Path as default
13
14
  };
@@ -1,6 +1,4 @@
1
- import { FC, PropsWithChildren, Ref, SVGProps } from 'react';
2
- export type RectProps = {
3
- ref?: Ref<SVGRectElement>;
4
- } & SVGProps<SVGRectElement>;
5
- declare const Rect: FC<PropsWithChildren<RectProps>>;
1
+ import { PropsWithChildren, SVGProps } from 'react';
2
+ export type RectProps = SVGProps<SVGRectElement>;
3
+ declare const Rect: import('react').ForwardRefExoticComponent<Omit<PropsWithChildren<RectProps>, "ref"> & import('react').RefAttributes<SVGRectElement>>;
6
4
  export default Rect;
@@ -1,8 +1,9 @@
1
- import { j as jsxRuntimeExports } from "../_virtual/jsx-runtime.js";
2
- const Rect = (props) => {
3
- const { ref, ...otherProps } = props;
4
- return /* @__PURE__ */ jsxRuntimeExports.jsx("rect", { ref, ...otherProps });
5
- };
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from "react";
3
+ const Rect = forwardRef((props, ref) => {
4
+ const { ...otherProps } = props;
5
+ return /* @__PURE__ */ jsx("rect", { ref, ...otherProps });
6
+ });
6
7
  export {
7
8
  Rect as default
8
9
  };
@@ -1,4 +1,4 @@
1
- import { FC, PropsWithChildren, Ref, SVGProps } from 'react';
1
+ import { PropsWithChildren, SVGProps } from 'react';
2
2
  import { FontProps } from '../types/svg/font';
3
3
  type TextVerticalAlign = 'top' | 'center' | 'bottom';
4
4
  export type DominantBaseline = 'auto' | 'text-bottom' | 'alphabetic' | 'ideographic' | 'middle' | 'central' | 'mathematical' | 'hanging' | 'text-top';
@@ -9,11 +9,10 @@ export type TextProps = {
9
9
  verticalAlign?: TextVerticalAlign | DominantBaseline;
10
10
  fontSize?: SVGProps<SVGTextElement>['fontSize'];
11
11
  fill?: SVGProps<SVGTextElement>['fill'];
12
- ref?: Ref<SVGTextElement>;
13
12
  } & FontProps & SVGProps<SVGTextElement>;
14
13
  /**
15
14
  * 文本节点
16
15
  * @tikz node
17
16
  */
18
- declare const Text: FC<PropsWithChildren<TextProps>>;
17
+ declare const Text: import('react').ForwardRefExoticComponent<Omit<PropsWithChildren<TextProps>, "ref"> & import('react').RefAttributes<SVGTextElement>>;
19
18
  export default Text;
@@ -1,8 +1,8 @@
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 { textWrapParse } from "../utils/string.js";
4
- const Text = (props) => {
5
- const { children, ref, align, verticalAlign, fontSize, fill, ...otherProps } = props;
4
+ const Text = forwardRef((props, ref) => {
5
+ const { children, align, verticalAlign, fontSize, fill, ...otherProps } = props;
6
6
  const dominantBaseline = useMemo(() => {
7
7
  switch (verticalAlign) {
8
8
  case "top":
@@ -24,12 +24,12 @@ const Text = (props) => {
24
24
  };
25
25
  const parseChildren = (children2) => {
26
26
  if (typeof children2 === "string") {
27
- return textWrapParse(children2).map((child, index) => /* @__PURE__ */ jsxRuntimeExports.jsx("tspan", { children: child }, index));
27
+ return textWrapParse(children2).map((child, index) => /* @__PURE__ */ jsx("tspan", { children: child }, index));
28
28
  }
29
29
  return children2;
30
30
  };
31
- return /* @__PURE__ */ jsxRuntimeExports.jsx("text", { ref, ...textProps, children: parseChildren(children) });
32
- };
31
+ return /* @__PURE__ */ jsx("text", { ref, ...textProps, children: parseChildren(children) });
32
+ });
33
33
  export {
34
34
  Text as default
35
35
  };
@@ -1,2 +1,2 @@
1
- declare const useForceUpdate: () => import('react').ActionDispatch<[]>;
1
+ declare const useForceUpdate: () => import('react').DispatchWithoutAction;
2
2
  export default useForceUpdate;
@@ -1,9 +1,9 @@
1
- export { default as Draw } from './components/draw/Draw';
2
- export type { DrawProps } from './components/draw/Draw';
1
+ export { default as Draw } from './components/draw';
2
+ export type { DrawProps } from './components/draw';
3
3
  export { default as Node } from './components/node';
4
4
  export type { NodeProps } from './components/node';
5
- export { default as PathNode } from './components/pathNode';
6
- export type { PathNodeProps } from './components/pathNode';
5
+ export { default as PathNode } from './components/path-node';
6
+ export type { PathNodeProps } from './components/path-node';
7
7
  export { default as Scope } from './components/Scope';
8
8
  export type { ScopeProps } from './components/Scope';
9
9
  export { default as TikZ } from './components/TikZ';
package/dist/es/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { default as default2 } from "./components/draw/Draw.js";
2
2
  import { default as default3 } from "./components/node/Node.js";
3
- import { default as default4 } from "./components/pathNode/PathNode.js";
3
+ import { default as default4 } from "./components/path-node/PathNode.js";
4
4
  import { default as default5 } from "./components/Scope.js";
5
5
  import { default as default6 } from "./components/TikZ.js";
6
6
  export {
@@ -8,6 +8,7 @@ const _Line = class _Line {
8
8
  __publicField(this, "b", 0);
9
9
  __publicField(this, "c", 0);
10
10
  if (a === 0 && b === 0) {
11
+ console.error("invalid line equation");
11
12
  return;
12
13
  }
13
14
  this.a = a;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,10 +1,10 @@
1
1
  export type StrokeProps = {
2
2
  stroke?: string;
3
- strokeWidth?: number;
3
+ strokeWidth?: number | string;
4
4
  strokeDasharray?: string;
5
5
  strokeDashoffset?: string;
6
6
  strokeLinecap?: 'butt' | 'round' | 'square' | 'inherit';
7
- strokeLinejoin?: "round" | "inherit" | "bevel" | "miter";
7
+ strokeLinejoin?: 'round' | 'inherit' | 'bevel' | 'miter';
8
8
  strokeMiterlimit?: number;
9
9
  strokeOpacity?: number;
10
10
  };
@@ -1,5 +1,6 @@
1
1
  import { StrokeProps } from '../../types/svg/stroke';
2
- export type StrokeType = 'solid' | 'dashed' | 'denselyDashed' | 'looselyDashed' | 'dotted' | 'denselyDotted' | 'looselyDotted' | 'dashDot' | 'denselyDashDot' | 'looselyDashDot' | 'dashDashDot' | 'denselyDashDashDot' | 'looselyDashDashDot';
2
+ export declare const strokeTypes: readonly ["solid", "dashed", "denselyDashed", "looselyDashed", "dotted", "denselyDotted", "looselyDotted", "dashDot", "denselyDashDot", "looselyDashDot", "dashDashDot", "denselyDashDashDot", "looselyDashDashDot"];
3
+ export type StrokeType = typeof strokeTypes[number];
3
4
  export type StrokeShortcutProps = {
4
5
  dashed?: boolean;
5
6
  denselyDashed?: boolean;
@@ -15,5 +16,5 @@ export type StrokeShortcutProps = {
15
16
  looselyDashDashDot?: boolean;
16
17
  };
17
18
  /** 将 StrokeType 转换为 svg 原生的属性 */
18
- export declare const convertStrokeType: (strokeType: StrokeType, strokeWidth?: number) => Partial<StrokeProps>;
19
- export declare const convertStrokeShortcut: (shortcutProps: StrokeShortcutProps, strokeWidth?: number) => Partial<StrokeProps>;
19
+ export declare const convertStrokeType: (strokeType: StrokeType, oriStrokeWidth?: string | number) => Partial<StrokeProps>;
20
+ export declare const convertStrokeShortcut: (shortcutProps: StrokeShortcutProps, oriStrokeWidth?: string | number) => Partial<StrokeProps>;
@@ -1,4 +1,5 @@
1
- const convertStrokeType = (strokeType, strokeWidth = 1) => {
1
+ const convertStrokeType = (strokeType, oriStrokeWidth = 1) => {
2
+ const strokeWidth = Number(oriStrokeWidth);
2
3
  switch (strokeType) {
3
4
  case "solid":
4
5
  return {};
@@ -28,7 +29,8 @@ const convertStrokeType = (strokeType, strokeWidth = 1) => {
28
29
  return { strokeDasharray: `${strokeWidth * 4} ${strokeWidth * 6} 1 ${strokeWidth * 6} 1 ${strokeWidth * 6}` };
29
30
  }
30
31
  };
31
- const convertStrokeShortcut = (shortcutProps, strokeWidth = 1) => {
32
+ const convertStrokeShortcut = (shortcutProps, oriStrokeWidth = 1) => {
33
+ const strokeWidth = Number(oriStrokeWidth);
32
34
  return convertStrokeType(
33
35
  shortcutProps.dashed ? "dashed" : shortcutProps.denselyDashed ? "denselyDashed" : shortcutProps.looselyDashed ? "looselyDashed" : shortcutProps.dotted ? "dotted" : shortcutProps.denselyDotted ? "denselyDotted" : shortcutProps.looselyDotted ? "looselyDotted" : shortcutProps.dashDot ? "dashDot" : shortcutProps.denselyDashDot ? "denselyDashDot" : shortcutProps.looselyDashDot ? "looselyDashDot" : shortcutProps.dashDashDot ? "dashDashDot" : shortcutProps.denselyDashDashDot ? "denselyDashDashDot" : shortcutProps.looselyDashDashDot ? "looselyDashDashDot" : "solid",
34
36
  strokeWidth || 1
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const jsxRuntime = require("../_virtual/jsx-runtime.cjs");
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const react = require("react");
4
5
  const useScope = require("../hooks/context/useScope.cjs");
5
6
  const Group = require("../container/Group.cjs");
6
- const Scope = (props) => {
7
- const { children, ref, ...resProps } = props;
8
- return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(useScope.ScopeContext, { value: resProps, children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Group.default, { ref, children }) });
9
- };
7
+ const Scope = react.forwardRef((props, ref) => {
8
+ const { children, ...resProps } = props;
9
+ const baseScopeValue = useScope.default();
10
+ return /* @__PURE__ */ jsxRuntime.jsx(useScope.ScopeContext.Provider, { value: { ...baseScopeValue, ...resProps }, children: /* @__PURE__ */ jsxRuntime.jsx(Group.default, { ref, children }) });
11
+ });
10
12
  exports.default = Scope;
@@ -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,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const jsxRuntime = require("../_virtual/jsx-runtime.cjs");
3
+ const jsxRuntime = require("react/jsx-runtime");
4
4
  const Surface = require("../container/Surface.cjs");
5
5
  const useCalculate = require("../hooks/context/useCalculate.cjs");
6
6
  const useNodes = require("../hooks/context/useNodes.cjs");
7
7
  const useScope = require("../hooks/context/useScope.cjs");
8
8
  const TikZ = (props) => {
9
9
  const { precision = 2, offset, node, draw, ...resProps } = props;
10
- return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(useNodes.NodesContext, { value: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(useCalculate.CalculateContext, { value: { precision }, children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(useScope.ScopeContext, { value: { offset, node, draw }, children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Surface.default, { ...resProps }) }) }) });
10
+ return /* @__PURE__ */ jsxRuntime.jsx(useNodes.NodesContext.Provider, { value: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ jsxRuntime.jsx(useCalculate.CalculateContext.Provider, { value: { precision }, children: /* @__PURE__ */ jsxRuntime.jsx(useScope.ScopeContext.Provider, { value: { offset, node, draw }, children: /* @__PURE__ */ jsxRuntime.jsx(Surface.default, { ...resProps }) }) }) });
11
11
  };
12
12
  exports.default = TikZ;
@@ -1,24 +1,49 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const jsxRuntime = require("../../_virtual/jsx-runtime.cjs");
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const react = require("react");
4
5
  const useScope = require("../../hooks/context/useScope.cjs");
5
6
  const DescartesPoint = require("../../model/geometry/point/DescartesPoint.cjs");
6
7
  const stroke = require("../../utils/style/stroke.cjs");
7
8
  const InnerDraw = require("./InnerDraw.cjs");
8
- const Draw = (props) => {
9
+ const Draw = react.forwardRef((props, ref) => {
9
10
  const { draw: scopeProps } = useScope.default();
10
11
  const realProps = { ...scopeProps, ...props };
11
- const { offset, color, stroke: stroke$1, strokeWidth, startArrow, startArrows, endArrow, endArrows, ...drawProps } = realProps;
12
+ const { offset, color, stroke: stroke$1, strokeWidth, startArrow, startArrows, endArrow, endArrows, ...resProps } = realProps;
12
13
  const realStroke = stroke$1 || color;
13
14
  const realStartArrow = typeof startArrow === "string" ? { type: startArrow } : startArrow;
14
15
  const realStartArrows = typeof startArrows === "string" ? { type: startArrows } : startArrows;
15
16
  const realEndArrow = typeof endArrow === "string" ? { type: endArrow } : endArrow;
16
17
  const realEndArrows = typeof endArrows === "string" ? { type: endArrows } : endArrows;
17
18
  const convertOffset = offset ? DescartesPoint.default.formatPosition(offset) : [0, 0];
18
- const getStrokeTypes = () => drawProps.strokeType ? stroke.convertStrokeType(drawProps.strokeType, strokeWidth || 1) : stroke.convertStrokeShortcut(drawProps, strokeWidth || 1);
19
- return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
19
+ const getStrokeTypes = () => resProps.strokeType ? stroke.convertStrokeType(resProps.strokeType, strokeWidth ?? 1) : stroke.convertStrokeShortcut(resProps, strokeWidth ?? 1);
20
+ const drawProps = react.useMemo(() => {
21
+ const props2 = { ...resProps };
22
+ [
23
+ "solid",
24
+ "dashed",
25
+ "denselyDashed",
26
+ "looselyDashed",
27
+ "dotted",
28
+ "denselyDotted",
29
+ "looselyDotted",
30
+ "dashDot",
31
+ "denselyDashDot",
32
+ "looselyDashDot",
33
+ "dashDashDot",
34
+ "denselyDashDashDot",
35
+ "looselyDashDashDot"
36
+ ].forEach((key) => {
37
+ if (key in props2) {
38
+ delete props2[key];
39
+ }
40
+ });
41
+ return props2;
42
+ }, [props]);
43
+ return /* @__PURE__ */ jsxRuntime.jsx(
20
44
  InnerDraw.default,
21
45
  {
46
+ ref,
22
47
  ...getStrokeTypes(),
23
48
  offset: convertOffset,
24
49
  stroke: realStroke,
@@ -30,5 +55,5 @@ const Draw = (props) => {
30
55
  ...drawProps
31
56
  }
32
57
  );
33
- };
58
+ });
34
59
  exports.default = Draw;
@@ -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,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const jsxRuntime = require("../../_virtual/jsx-runtime.cjs");
4
- const require$$0 = require("react");
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const react = require("react");
5
5
  const Group = require("../../container/Group.cjs");
6
6
  const usePath = require("../../hooks/context/usePath.cjs");
7
7
  const path = require("../../model/component/path.cjs");
8
8
  const common = require("./common.cjs");
9
9
  const index = require("./segment/index.cjs");
10
- const InnerDraw = (props) => {
11
- const { way, ref, offset, startArrow, startArrows, endArrow, endArrows, children, ...strokeProps } = props;
12
- const waySegments = require$$0.useMemo(() => {
10
+ const InnerDraw = react.forwardRef((props, ref) => {
11
+ const { way, offset, startArrow, startArrows, endArrow, endArrows, children, ...strokeProps } = props;
12
+ const waySegments = react.useMemo(() => {
13
13
  let preNodeType = "coordinate";
14
14
  const waySegments2 = [];
15
15
  let waySegment = [];
@@ -28,20 +28,25 @@ const InnerDraw = (props) => {
28
28
  }
29
29
  return waySegments2;
30
30
  }, [way]);
31
- return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(usePath.PathContext, { value: new path.default(new Array(waySegments.length).fill([]), strokeProps.strokeWidth || 1, false), children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Group.default, { ref, transform: `translate(${offset[0]}, ${offset[1]})`, children: [
32
- waySegments.map((segment, index$1) => /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
33
- index.default,
34
- {
35
- index: index$1,
36
- isLastSegment: index$1 === waySegments.length - 1,
37
- way: segment,
38
- ...strokeProps,
39
- endArrow: index$1 === waySegments.length - 1 ? endArrow || endArrows : endArrows,
40
- startArrow: index$1 === waySegments.length - 1 ? startArrow || startArrows : startArrows
41
- },
42
- JSON.stringify(segment)
43
- )),
44
- children
45
- ] }) });
46
- };
31
+ return /* @__PURE__ */ jsxRuntime.jsx(
32
+ usePath.PathContext.Provider,
33
+ {
34
+ value: new path.default(new Array(waySegments.length).fill([]), Number(strokeProps.strokeWidth) || 1, false),
35
+ children: /* @__PURE__ */ jsxRuntime.jsxs(Group.default, { ref, transform: `translate(${offset[0]}, ${offset[1]})`, children: [
36
+ waySegments.map((segment, index$1) => /* @__PURE__ */ jsxRuntime.jsx(
37
+ index.default,
38
+ {
39
+ index: index$1,
40
+ way: segment,
41
+ ...strokeProps,
42
+ endArrow: index$1 === waySegments.length - 1 ? endArrow || endArrows : endArrows,
43
+ startArrow: index$1 === waySegments.length - 1 ? startArrow || startArrows : startArrows
44
+ },
45
+ JSON.stringify(segment)
46
+ )),
47
+ children
48
+ ] })
49
+ }
50
+ );
51
+ });
47
52
  exports.default = InnerDraw;
@@ -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;
@@ -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;
@@ -0,0 +1,7 @@
1
+ import { ArrowAttributes } from './types';
2
+ declare const getCirclePath: (attributes: ArrowAttributes) => {
3
+ d: string;
4
+ offsetDistance: number;
5
+ insertDistance: number;
6
+ };
7
+ export default getCirclePath;