@retikz/core 0.0.1-rc.0

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 (233) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2 -0
  3. package/dist/es/_virtual/jsx-runtime.js +5 -0
  4. package/dist/es/_virtual/jsx-runtime2.js +4 -0
  5. package/dist/es/_virtual/react-jsx-runtime.development.js +4 -0
  6. package/dist/es/_virtual/react-jsx-runtime.production.js +4 -0
  7. package/dist/es/components/Scope.d.ts +6 -0
  8. package/dist/es/components/Scope.js +10 -0
  9. package/dist/es/components/TikZ.d.ts +9 -0
  10. package/dist/es/components/TikZ.js +12 -0
  11. package/dist/es/components/draw/Draw.d.ts +18 -0
  12. package/dist/es/components/draw/Draw.js +34 -0
  13. package/dist/es/components/draw/InnerDraw.d.ts +13 -0
  14. package/dist/es/components/draw/InnerDraw.js +47 -0
  15. package/dist/es/components/draw/arrow/index.d.ts +9 -0
  16. package/dist/es/components/draw/arrow/index.js +10 -0
  17. package/dist/es/components/draw/arrow/stealth.d.ts +7 -0
  18. package/dist/es/components/draw/arrow/stealth.js +29 -0
  19. package/dist/es/components/draw/arrow/types.d.ts +21 -0
  20. package/dist/es/components/draw/common.d.ts +4 -0
  21. package/dist/es/components/draw/common.js +12 -0
  22. package/dist/es/components/draw/index.d.ts +3 -0
  23. package/dist/es/components/draw/segment/Segment.d.ts +12 -0
  24. package/dist/es/components/draw/segment/Segment.js +41 -0
  25. package/dist/es/components/draw/segment/index.d.ts +19 -0
  26. package/dist/es/components/draw/segment/index.js +41 -0
  27. package/dist/es/components/draw/segment/useArrow.d.ts +12 -0
  28. package/dist/es/components/draw/segment/useArrow.js +52 -0
  29. package/dist/es/components/draw/segment/useConvertWay.d.ts +14 -0
  30. package/dist/es/components/draw/segment/useConvertWay.js +95 -0
  31. package/dist/es/components/draw/types.d.ts +29 -0
  32. package/dist/es/components/node/InnerNode.d.ts +33 -0
  33. package/dist/es/components/node/InnerNode.js +88 -0
  34. package/dist/es/components/node/Node.d.ts +54 -0
  35. package/dist/es/components/node/Node.js +87 -0
  36. package/dist/es/components/node/_hooks/useNodeConfig.d.ts +3 -0
  37. package/dist/es/components/node/_hooks/useNodeConfig.js +13 -0
  38. package/dist/es/components/node/_hooks/useNodeContent.d.ts +4 -0
  39. package/dist/es/components/node/_hooks/useNodeContent.js +27 -0
  40. package/dist/es/components/node/_hooks/useNodeShape.d.ts +4 -0
  41. package/dist/es/components/node/_hooks/useNodeShape.js +34 -0
  42. package/dist/es/components/node/index.d.ts +3 -0
  43. package/dist/es/components/node/index.js +4 -0
  44. package/dist/es/components/pathNode/PathNode.d.ts +39 -0
  45. package/dist/es/components/pathNode/PathNode.js +76 -0
  46. package/dist/es/components/pathNode/index.d.ts +3 -0
  47. package/dist/es/components/pathNode/index.js +4 -0
  48. package/dist/es/components/pathNode/useAnchor.d.ts +6 -0
  49. package/dist/es/components/pathNode/useAnchor.js +49 -0
  50. package/dist/es/container/Group.d.ts +6 -0
  51. package/dist/es/container/Group.js +7 -0
  52. package/dist/es/container/Surface.d.ts +17 -0
  53. package/dist/es/container/Surface.js +23 -0
  54. package/dist/es/elements/Path.d.ts +4 -0
  55. package/dist/es/elements/Path.js +13 -0
  56. package/dist/es/elements/Rect.d.ts +6 -0
  57. package/dist/es/elements/Rect.js +8 -0
  58. package/dist/es/elements/Text.d.ts +19 -0
  59. package/dist/es/elements/Text.js +35 -0
  60. package/dist/es/hooks/context/useCalculate.d.ts +7 -0
  61. package/dist/es/hooks/context/useCalculate.js +9 -0
  62. package/dist/es/hooks/context/useNodes.d.ts +9 -0
  63. package/dist/es/hooks/context/useNodes.js +33 -0
  64. package/dist/es/hooks/context/usePath.d.ts +13 -0
  65. package/dist/es/hooks/context/usePath.js +20 -0
  66. package/dist/es/hooks/context/useScope.d.ts +11 -0
  67. package/dist/es/hooks/context/useScope.js +7 -0
  68. package/dist/es/hooks/useForceUpdate.d.ts +2 -0
  69. package/dist/es/hooks/useForceUpdate.js +8 -0
  70. package/dist/es/index.d.ts +10 -0
  71. package/dist/es/index.js +12 -0
  72. package/dist/es/model/component/node.d.ts +45 -0
  73. package/dist/es/model/component/node.js +164 -0
  74. package/dist/es/model/component/path.d.ts +19 -0
  75. package/dist/es/model/component/path.js +47 -0
  76. package/dist/es/model/equation/line.d.ts +21 -0
  77. package/dist/es/model/equation/line.js +75 -0
  78. package/dist/es/model/geometry/point/DescartesPoint.d.ts +21 -0
  79. package/dist/es/model/geometry/point/DescartesPoint.js +50 -0
  80. package/dist/es/model/geometry/point/PolarPoint.d.ts +14 -0
  81. package/dist/es/model/geometry/point/PolarPoint.js +27 -0
  82. package/dist/es/node_modules/.pnpm/d3-color@3.1.0/node_modules/d3-color/src/color.js +338 -0
  83. package/dist/es/node_modules/.pnpm/d3-color@3.1.0/node_modules/d3-color/src/define.js +13 -0
  84. package/dist/es/node_modules/.pnpm/d3-path@3.1.0/node_modules/d3-path/src/path.js +88 -0
  85. package/dist/es/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/array.js +6 -0
  86. package/dist/es/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/constant.js +8 -0
  87. package/dist/es/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/curve/linear.js +39 -0
  88. package/dist/es/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/line.js +41 -0
  89. package/dist/es/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/path.js +19 -0
  90. package/dist/es/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/point.js +10 -0
  91. package/dist/es/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.development.js +20 -0
  92. package/dist/es/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.production.js +41 -0
  93. package/dist/es/node_modules/.pnpm/react@19.0.0/node_modules/react/jsx-runtime.js +17 -0
  94. package/dist/es/types/coordinate/descartes.d.ts +23 -0
  95. package/dist/es/types/coordinate/index.d.ts +5 -0
  96. package/dist/es/types/coordinate/polar.d.ts +5 -0
  97. package/dist/es/types/distance/index.d.ts +8 -0
  98. package/dist/es/types/distance/sep.d.ts +9 -0
  99. package/dist/es/types/shape/index.d.ts +8 -0
  100. package/dist/es/types/shape/index.js +9 -0
  101. package/dist/es/types/shape/rect.d.ts +25 -0
  102. package/dist/es/types/shape/rect.js +30 -0
  103. package/dist/es/types/svg/font.d.ts +10 -0
  104. package/dist/es/types/svg/stroke.d.ts +10 -0
  105. package/dist/es/types/tikz/index.d.ts +6 -0
  106. package/dist/es/utils/compare.d.ts +4 -0
  107. package/dist/es/utils/compare.js +20 -0
  108. package/dist/es/utils/css.d.ts +6 -0
  109. package/dist/es/utils/css.js +26 -0
  110. package/dist/es/utils/math.d.ts +9 -0
  111. package/dist/es/utils/math.js +26 -0
  112. package/dist/es/utils/string.d.ts +7 -0
  113. package/dist/es/utils/string.js +7 -0
  114. package/dist/es/utils/style/font.d.ts +17 -0
  115. package/dist/es/utils/style/font.js +34 -0
  116. package/dist/es/utils/style/stroke.d.ts +19 -0
  117. package/dist/es/utils/style/stroke.js +40 -0
  118. package/dist/lib/_virtual/jsx-runtime.cjs +5 -0
  119. package/dist/lib/_virtual/jsx-runtime2.cjs +4 -0
  120. package/dist/lib/_virtual/react-jsx-runtime.development.cjs +4 -0
  121. package/dist/lib/_virtual/react-jsx-runtime.production.cjs +4 -0
  122. package/dist/lib/components/Scope.cjs +10 -0
  123. package/dist/lib/components/Scope.d.ts +6 -0
  124. package/dist/lib/components/TikZ.cjs +12 -0
  125. package/dist/lib/components/TikZ.d.ts +9 -0
  126. package/dist/lib/components/draw/Draw.cjs +34 -0
  127. package/dist/lib/components/draw/Draw.d.ts +18 -0
  128. package/dist/lib/components/draw/InnerDraw.cjs +47 -0
  129. package/dist/lib/components/draw/InnerDraw.d.ts +13 -0
  130. package/dist/lib/components/draw/arrow/index.cjs +10 -0
  131. package/dist/lib/components/draw/arrow/index.d.ts +9 -0
  132. package/dist/lib/components/draw/arrow/stealth.cjs +29 -0
  133. package/dist/lib/components/draw/arrow/stealth.d.ts +7 -0
  134. package/dist/lib/components/draw/arrow/types.d.ts +21 -0
  135. package/dist/lib/components/draw/common.cjs +12 -0
  136. package/dist/lib/components/draw/common.d.ts +4 -0
  137. package/dist/lib/components/draw/index.d.ts +3 -0
  138. package/dist/lib/components/draw/segment/Segment.cjs +41 -0
  139. package/dist/lib/components/draw/segment/Segment.d.ts +12 -0
  140. package/dist/lib/components/draw/segment/index.cjs +41 -0
  141. package/dist/lib/components/draw/segment/index.d.ts +19 -0
  142. package/dist/lib/components/draw/segment/useArrow.cjs +52 -0
  143. package/dist/lib/components/draw/segment/useArrow.d.ts +12 -0
  144. package/dist/lib/components/draw/segment/useConvertWay.cjs +95 -0
  145. package/dist/lib/components/draw/segment/useConvertWay.d.ts +14 -0
  146. package/dist/lib/components/draw/types.d.ts +29 -0
  147. package/dist/lib/components/node/InnerNode.cjs +88 -0
  148. package/dist/lib/components/node/InnerNode.d.ts +33 -0
  149. package/dist/lib/components/node/Node.cjs +87 -0
  150. package/dist/lib/components/node/Node.d.ts +54 -0
  151. package/dist/lib/components/node/_hooks/useNodeConfig.cjs +13 -0
  152. package/dist/lib/components/node/_hooks/useNodeConfig.d.ts +3 -0
  153. package/dist/lib/components/node/_hooks/useNodeContent.cjs +27 -0
  154. package/dist/lib/components/node/_hooks/useNodeContent.d.ts +4 -0
  155. package/dist/lib/components/node/_hooks/useNodeShape.cjs +34 -0
  156. package/dist/lib/components/node/_hooks/useNodeShape.d.ts +4 -0
  157. package/dist/lib/components/node/index.cjs +4 -0
  158. package/dist/lib/components/node/index.d.ts +3 -0
  159. package/dist/lib/components/pathNode/PathNode.cjs +76 -0
  160. package/dist/lib/components/pathNode/PathNode.d.ts +39 -0
  161. package/dist/lib/components/pathNode/index.cjs +4 -0
  162. package/dist/lib/components/pathNode/index.d.ts +3 -0
  163. package/dist/lib/components/pathNode/useAnchor.cjs +49 -0
  164. package/dist/lib/components/pathNode/useAnchor.d.ts +6 -0
  165. package/dist/lib/container/Group.cjs +7 -0
  166. package/dist/lib/container/Group.d.ts +6 -0
  167. package/dist/lib/container/Surface.cjs +23 -0
  168. package/dist/lib/container/Surface.d.ts +17 -0
  169. package/dist/lib/elements/Path.cjs +13 -0
  170. package/dist/lib/elements/Path.d.ts +4 -0
  171. package/dist/lib/elements/Rect.cjs +8 -0
  172. package/dist/lib/elements/Rect.d.ts +6 -0
  173. package/dist/lib/elements/Text.cjs +35 -0
  174. package/dist/lib/elements/Text.d.ts +19 -0
  175. package/dist/lib/hooks/context/useCalculate.cjs +9 -0
  176. package/dist/lib/hooks/context/useCalculate.d.ts +7 -0
  177. package/dist/lib/hooks/context/useNodes.cjs +33 -0
  178. package/dist/lib/hooks/context/useNodes.d.ts +9 -0
  179. package/dist/lib/hooks/context/usePath.cjs +20 -0
  180. package/dist/lib/hooks/context/usePath.d.ts +13 -0
  181. package/dist/lib/hooks/context/useScope.cjs +7 -0
  182. package/dist/lib/hooks/context/useScope.d.ts +11 -0
  183. package/dist/lib/hooks/useForceUpdate.cjs +8 -0
  184. package/dist/lib/hooks/useForceUpdate.d.ts +2 -0
  185. package/dist/lib/index.cjs +12 -0
  186. package/dist/lib/index.d.ts +10 -0
  187. package/dist/lib/model/component/node.cjs +164 -0
  188. package/dist/lib/model/component/node.d.ts +45 -0
  189. package/dist/lib/model/component/path.cjs +47 -0
  190. package/dist/lib/model/component/path.d.ts +19 -0
  191. package/dist/lib/model/equation/line.cjs +75 -0
  192. package/dist/lib/model/equation/line.d.ts +21 -0
  193. package/dist/lib/model/geometry/point/DescartesPoint.cjs +50 -0
  194. package/dist/lib/model/geometry/point/DescartesPoint.d.ts +21 -0
  195. package/dist/lib/model/geometry/point/PolarPoint.cjs +27 -0
  196. package/dist/lib/model/geometry/point/PolarPoint.d.ts +14 -0
  197. package/dist/lib/node_modules/.pnpm/d3-color@3.1.0/node_modules/d3-color/src/color.cjs +338 -0
  198. package/dist/lib/node_modules/.pnpm/d3-color@3.1.0/node_modules/d3-color/src/define.cjs +13 -0
  199. package/dist/lib/node_modules/.pnpm/d3-path@3.1.0/node_modules/d3-path/src/path.cjs +88 -0
  200. package/dist/lib/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/array.cjs +6 -0
  201. package/dist/lib/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/constant.cjs +8 -0
  202. package/dist/lib/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/curve/linear.cjs +39 -0
  203. package/dist/lib/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/line.cjs +41 -0
  204. package/dist/lib/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/path.cjs +19 -0
  205. package/dist/lib/node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/point.cjs +10 -0
  206. package/dist/lib/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.development.cjs +20 -0
  207. package/dist/lib/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.production.cjs +41 -0
  208. package/dist/lib/node_modules/.pnpm/react@19.0.0/node_modules/react/jsx-runtime.cjs +17 -0
  209. package/dist/lib/types/coordinate/descartes.d.ts +23 -0
  210. package/dist/lib/types/coordinate/index.d.ts +5 -0
  211. package/dist/lib/types/coordinate/polar.d.ts +5 -0
  212. package/dist/lib/types/distance/index.d.ts +8 -0
  213. package/dist/lib/types/distance/sep.d.ts +9 -0
  214. package/dist/lib/types/shape/index.cjs +9 -0
  215. package/dist/lib/types/shape/index.d.ts +8 -0
  216. package/dist/lib/types/shape/rect.cjs +30 -0
  217. package/dist/lib/types/shape/rect.d.ts +25 -0
  218. package/dist/lib/types/svg/font.d.ts +10 -0
  219. package/dist/lib/types/svg/stroke.d.ts +10 -0
  220. package/dist/lib/types/tikz/index.d.ts +6 -0
  221. package/dist/lib/utils/compare.cjs +20 -0
  222. package/dist/lib/utils/compare.d.ts +4 -0
  223. package/dist/lib/utils/css.cjs +26 -0
  224. package/dist/lib/utils/css.d.ts +6 -0
  225. package/dist/lib/utils/math.cjs +26 -0
  226. package/dist/lib/utils/math.d.ts +9 -0
  227. package/dist/lib/utils/string.cjs +7 -0
  228. package/dist/lib/utils/string.d.ts +7 -0
  229. package/dist/lib/utils/style/font.cjs +34 -0
  230. package/dist/lib/utils/style/font.d.ts +17 -0
  231. package/dist/lib/utils/style/stroke.cjs +40 -0
  232. package/dist/lib/utils/style/stroke.d.ts +19 -0
  233. package/package.json +57 -0
@@ -0,0 +1,19 @@
1
+ import { FC, PropsWithChildren, Ref, SVGProps } from 'react';
2
+ import { FontProps } from '../types/svg/font';
3
+ type TextVerticalAlign = 'top' | 'center' | 'bottom';
4
+ export type DominantBaseline = 'auto' | 'text-bottom' | 'alphabetic' | 'ideographic' | 'middle' | 'central' | 'mathematical' | 'hanging' | 'text-top';
5
+ export type TextProps = {
6
+ x?: SVGProps<SVGTextElement>['x'];
7
+ y?: SVGProps<SVGTextElement>['y'];
8
+ align?: 'start' | 'middle' | 'end' | 'inherit';
9
+ verticalAlign?: TextVerticalAlign | DominantBaseline;
10
+ fontSize?: SVGProps<SVGTextElement>['fontSize'];
11
+ fill?: SVGProps<SVGTextElement>['fill'];
12
+ ref?: Ref<SVGTextElement>;
13
+ } & FontProps & SVGProps<SVGTextElement>;
14
+ /**
15
+ * 文本节点
16
+ * @tikz node
17
+ */
18
+ declare const Text: FC<PropsWithChildren<TextProps>>;
19
+ export default Text;
@@ -0,0 +1,35 @@
1
+ import { j as jsxRuntimeExports } from "../_virtual/jsx-runtime.js";
2
+ import { useMemo } from "react";
3
+ import { textWrapParse } from "../utils/string.js";
4
+ const Text = (props) => {
5
+ const { children, ref, align, verticalAlign, fontSize, fill, ...otherProps } = props;
6
+ const dominantBaseline = useMemo(() => {
7
+ switch (verticalAlign) {
8
+ case "top":
9
+ return "text-top";
10
+ case "bottom":
11
+ return "text-bottom";
12
+ case "center":
13
+ return "central";
14
+ default:
15
+ return verticalAlign;
16
+ }
17
+ }, [verticalAlign]);
18
+ const textProps = {
19
+ textAnchor: align || "middle",
20
+ dominantBaseline: dominantBaseline || "central",
21
+ fontSize: fontSize || "1em",
22
+ fill: fill || "currentColor",
23
+ ...otherProps
24
+ };
25
+ const parseChildren = (children2) => {
26
+ if (typeof children2 === "string") {
27
+ return textWrapParse(children2).map((child, index) => /* @__PURE__ */ jsxRuntimeExports.jsx("tspan", { children: child }, index));
28
+ }
29
+ return children2;
30
+ };
31
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("text", { ref, ...textProps, children: parseChildren(children) });
32
+ };
33
+ export {
34
+ Text as default
35
+ };
@@ -0,0 +1,7 @@
1
+ export type CalculateProps = {
2
+ precision: number | false;
3
+ };
4
+ export declare const CalculateContext: import('react').Context<CalculateProps>;
5
+ declare const useCalculate: () => CalculateProps;
6
+ export declare const useCalculateValue: (value: number, deep?: boolean) => number;
7
+ export default useCalculate;
@@ -0,0 +1,9 @@
1
+ import { createContext, useContext } from "react";
2
+ const CalculateContext = createContext({ precision: 2 });
3
+ const useCalculate = () => {
4
+ return useContext(CalculateContext);
5
+ };
6
+ export {
7
+ CalculateContext,
8
+ useCalculate as default
9
+ };
@@ -0,0 +1,9 @@
1
+ import { default as NodeModel, NodeConfig, StateListener } from '../../model/component/node';
2
+ export declare const NodesContext: import('react').Context<Map<string, NodeModel>>;
3
+ declare const useNodes: () => {
4
+ subscribeModel: (name: string, listener: StateListener) => false | (() => boolean);
5
+ getModel: (name: string) => NodeModel | undefined;
6
+ updateModel: (name: string, config: NodeConfig, init?: boolean) => void;
7
+ deleteModel: (name: string) => void;
8
+ };
9
+ export default useNodes;
@@ -0,0 +1,33 @@
1
+ import { createContext, useContext } from "react";
2
+ import NodeModel from "../../model/component/node.js";
3
+ const NodesContext = createContext(/* @__PURE__ */ new Map());
4
+ const useNodes = () => {
5
+ const nodes = useContext(NodesContext);
6
+ return {
7
+ subscribeModel: (name, listener) => {
8
+ const model = nodes.get(name);
9
+ if (!model) return false;
10
+ return model.subscribe(listener);
11
+ },
12
+ getModel: (name) => nodes.get(name),
13
+ updateModel: (name, config, init = true) => {
14
+ const model = nodes.get(name);
15
+ if (model) {
16
+ model.update(config, init);
17
+ } else {
18
+ nodes.set(name, new NodeModel(config, init));
19
+ }
20
+ },
21
+ deleteModel: (name) => {
22
+ const model = nodes.get(name);
23
+ if (!model) return;
24
+ model.dispose();
25
+ model.notify();
26
+ nodes.delete(name);
27
+ }
28
+ };
29
+ };
30
+ export {
31
+ NodesContext,
32
+ useNodes as default
33
+ };
@@ -0,0 +1,13 @@
1
+ import { default as PathModel, StateListener } from '../../model/component/path';
2
+ import { Position } from '../../types/coordinate/descartes';
3
+ export declare const PathContext: import('react').Context<PathModel | null>;
4
+ declare const usePath: () => {
5
+ model: PathModel;
6
+ subscribeModel: (listener: StateListener) => (() => boolean) | undefined;
7
+ updateModel: (config: {
8
+ ways?: Array<Position[]>;
9
+ lineWidth?: number;
10
+ init?: boolean;
11
+ }) => void;
12
+ };
13
+ export default usePath;
@@ -0,0 +1,20 @@
1
+ import { createContext, useContext } from "react";
2
+ const PathContext = createContext(null);
3
+ const usePath = () => {
4
+ const pathModel = useContext(PathContext);
5
+ if (!pathModel) throw new Error("usePath must be used within a PathProvider");
6
+ return {
7
+ model: pathModel,
8
+ subscribeModel: (listener) => {
9
+ if (!pathModel) return;
10
+ return pathModel.subscribe(listener);
11
+ },
12
+ updateModel: (config) => {
13
+ pathModel == null ? void 0 : pathModel.update(config);
14
+ }
15
+ };
16
+ };
17
+ export {
18
+ PathContext,
19
+ usePath as default
20
+ };
@@ -0,0 +1,11 @@
1
+ import { DrawProps } from '../../components/draw/Draw';
2
+ import { NodeProps } from '../../components/node';
3
+ import { Position } from '../../types/coordinate/descartes';
4
+ export type ScopeProps = {
5
+ offset?: Position;
6
+ node?: Omit<NodeProps, 'name' | 'ref' | 'position' | 'offset'>;
7
+ draw?: Omit<DrawProps, 'ref' | 'way' | 'offset'>;
8
+ };
9
+ export declare const ScopeContext: import('react').Context<ScopeProps>;
10
+ declare const useScope: () => ScopeProps;
11
+ export default useScope;
@@ -0,0 +1,7 @@
1
+ import { createContext, useContext } from "react";
2
+ const ScopeContext = createContext({});
3
+ const useScope = () => useContext(ScopeContext);
4
+ export {
5
+ ScopeContext,
6
+ useScope as default
7
+ };
@@ -0,0 +1,2 @@
1
+ declare const useForceUpdate: () => import('react').ActionDispatch<[]>;
2
+ export default useForceUpdate;
@@ -0,0 +1,8 @@
1
+ import { useReducer } from "react";
2
+ const useForceUpdate = () => {
3
+ const [_, forceUpdate] = useReducer(() => ({}), {});
4
+ return forceUpdate;
5
+ };
6
+ export {
7
+ useForceUpdate as default
8
+ };
@@ -0,0 +1,10 @@
1
+ export { default as Draw } from './components/draw/Draw';
2
+ export type { DrawProps } from './components/draw/Draw';
3
+ export { default as Node } from './components/node';
4
+ export type { NodeProps } from './components/node';
5
+ export { default as PathNode } from './components/pathNode';
6
+ export type { PathNodeProps } from './components/pathNode';
7
+ export { default as Scope } from './components/Scope';
8
+ export type { ScopeProps } from './components/Scope';
9
+ export { default as TikZ } from './components/TikZ';
10
+ export type { TikZProps } from './components/TikZ';
@@ -0,0 +1,12 @@
1
+ import { default as default2 } from "./components/draw/Draw.js";
2
+ import { default as default3 } from "./components/node/Node.js";
3
+ import { default as default4 } from "./components/pathNode/PathNode.js";
4
+ import { default as default5 } from "./components/Scope.js";
5
+ import { default as default6 } from "./components/TikZ.js";
6
+ export {
7
+ default2 as Draw,
8
+ default3 as Node,
9
+ default4 as PathNode,
10
+ default5 as Scope,
11
+ default6 as TikZ
12
+ };
@@ -0,0 +1,45 @@
1
+ import { Direction } from '../../types/coordinate';
2
+ import { Position } from '../../types/coordinate/descartes';
3
+ import { DirectionDistance } from '../../types/distance';
4
+ import { Area, Size } from '../../types/shape';
5
+ import { RectMidPoint, RectThirdPoint, RectVertexPoint } from '../../types/shape/rect';
6
+ export type StateListener = (state?: NodeModel, prevState?: NodeModel) => void;
7
+ export type NodeConfig = {
8
+ /** 内容中心位置 */
9
+ position: Position;
10
+ /** 内容(文本)尺寸 */
11
+ contentSize: Size;
12
+ /** 内边框距离 */
13
+ innerSep: DirectionDistance;
14
+ /** 外边框距离 */
15
+ outerSep: DirectionDistance;
16
+ };
17
+ export type NodeAttribute = keyof NodeConfig;
18
+ export default class NodeModel {
19
+ type: string[];
20
+ /** 是否初始化节点数据, 很多节点在 layout 阶段才能初始化全部数据 */
21
+ init: boolean;
22
+ /** 节点是否已经被销毁,如果已近销毁,其他地方应该删除对节点对象的引用 */
23
+ disposed: boolean;
24
+ center: Position;
25
+ size: Size;
26
+ innerSep: DirectionDistance;
27
+ outerSep: DirectionDistance;
28
+ listeners: Set<StateListener>;
29
+ constructor(config: NodeConfig, init?: boolean);
30
+ update(config: Partial<NodeConfig>, init?: boolean): void;
31
+ notify(preSelf?: NodeModel): void;
32
+ subscribe(listener: StateListener): () => boolean;
33
+ dispose(): void;
34
+ /** 获取某个点相对于节点外边界的区域 */
35
+ getPointArea(point: Position): Area;
36
+ /** 获取外边界特殊点(中点,顶点,三等分点) */
37
+ getOuterPoint(point: RectVertexPoint | RectMidPoint | RectThirdPoint): Position | undefined;
38
+ /** 获取外部点与 node 中心连线与外边缘的交点 */
39
+ getCrossPoint(point: Position): Position;
40
+ /** 获取到边界的距离 */
41
+ getOuterDistance(direction: Direction): number;
42
+ /** 判断某个变量是否为初始化完成的节点 */
43
+ static isInitializedNode: (node: unknown) => boolean;
44
+ static isNode: (node: unknown) => boolean;
45
+ }
@@ -0,0 +1,164 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ import { Area } from "../../types/shape/index.js";
5
+ import { RectThirdPoint, RectMidPoint, RectVertexPoint } from "../../types/shape/rect.js";
6
+ import { isSameArray, isSameObj } from "../../utils/compare.js";
7
+ import { between } from "../../utils/math.js";
8
+ import Line from "../equation/line.js";
9
+ const _NodeModel = class _NodeModel {
10
+ constructor(config, init = true) {
11
+ __publicField(this, "type", ["node"]);
12
+ /** 是否初始化节点数据, 很多节点在 layout 阶段才能初始化全部数据 */
13
+ __publicField(this, "init", false);
14
+ /** 节点是否已经被销毁,如果已近销毁,其他地方应该删除对节点对象的引用 */
15
+ __publicField(this, "disposed", false);
16
+ __publicField(this, "center", [0, 0]);
17
+ __publicField(this, "size", [0, 0]);
18
+ __publicField(this, "innerSep", { left: 0, right: 0, top: 0, bottom: 0 });
19
+ __publicField(this, "outerSep", { left: 0, right: 0, top: 0, bottom: 0 });
20
+ __publicField(this, "listeners", /* @__PURE__ */ new Set());
21
+ this.update(config, init);
22
+ }
23
+ update(config, init = true) {
24
+ const preSelf = { ...this };
25
+ const { position, contentSize, innerSep, outerSep } = config;
26
+ let needUpdate = false;
27
+ if (!this.init && init) {
28
+ this.init = init;
29
+ needUpdate = true;
30
+ }
31
+ if (position && !isSameArray(position, this.center)) {
32
+ this.center = position;
33
+ needUpdate = true;
34
+ }
35
+ if (contentSize && !isSameArray(contentSize, this.size)) {
36
+ this.size = contentSize;
37
+ needUpdate = true;
38
+ }
39
+ if (innerSep && !isSameObj(innerSep, this.innerSep)) {
40
+ this.innerSep = innerSep;
41
+ needUpdate = true;
42
+ }
43
+ if (outerSep && !isSameObj(outerSep, this.outerSep)) {
44
+ this.outerSep = outerSep;
45
+ needUpdate = true;
46
+ }
47
+ if (this.init && needUpdate) {
48
+ this.notify(preSelf);
49
+ }
50
+ }
51
+ notify(preSelf) {
52
+ this.listeners.forEach((listener) => listener({ ...this }, preSelf));
53
+ }
54
+ subscribe(listener) {
55
+ this.listeners.add(listener);
56
+ return () => this.listeners.delete(listener);
57
+ }
58
+ dispose() {
59
+ this.listeners.clear();
60
+ this.disposed = true;
61
+ this.notify(this);
62
+ }
63
+ /** 获取某个点相对于节点外边界的区域 */
64
+ getPointArea(point) {
65
+ const [pX, pY] = point;
66
+ const [x, y] = this.center;
67
+ const edgeX = [x - this.getOuterDistance("left"), x + this.getOuterDistance("right")];
68
+ const edgeY = [y - this.getOuterDistance("top"), y + this.getOuterDistance("bottom")];
69
+ if (between(pX, edgeX) && between(pY, edgeY)) return Area.INSIDE;
70
+ if (between(pX, edgeX, true) && between(pY, edgeY, true)) return Area.EDGE;
71
+ return Area.OUTSIDE;
72
+ }
73
+ /** 获取外边界特殊点(中点,顶点,三等分点) */
74
+ getOuterPoint(point) {
75
+ if (!this.init) return void 0;
76
+ const [x, y] = this.center;
77
+ const [width, height] = this.size;
78
+ const { left: innerLeft, right: innerRight, top: innerTop, bottom: innerBottom } = this.innerSep;
79
+ const { left: outerLeft, right: outerRight, top: outerTop, bottom: outerBottom } = this.outerSep;
80
+ switch (point) {
81
+ case RectVertexPoint.TL:
82
+ return [x - width / 2 - innerLeft - outerLeft, y - height / 2 - innerTop - outerTop];
83
+ case RectVertexPoint.TR:
84
+ return [x + width / 2 + innerRight + outerRight, y - height / 2 - innerTop - outerTop];
85
+ case RectVertexPoint.BL:
86
+ return [x - width / 2 - innerLeft - outerLeft, y + height / 2 + innerBottom + outerBottom];
87
+ case RectVertexPoint.BR:
88
+ return [x + width / 2 + innerRight + outerRight, y + height / 2 + innerBottom + outerBottom];
89
+ case RectMidPoint.T:
90
+ return [x, y - height / 2 - innerTop - outerTop];
91
+ case RectMidPoint.B:
92
+ return [x, y + height / 2 + innerBottom + outerBottom];
93
+ case RectMidPoint.L:
94
+ return [x - width / 2 - innerLeft - outerLeft, y];
95
+ case RectMidPoint.R:
96
+ return [x + width / 2 + innerRight + outerRight, y];
97
+ case RectThirdPoint.TL:
98
+ return [x - (width / 2 + innerLeft + outerLeft) / 3, y - (height / 2 + innerTop + outerTop) / 3];
99
+ case RectThirdPoint.TR:
100
+ return [x + (width / 2 + innerRight + outerRight) / 3, y - (height / 2 + innerTop + outerTop) / 3];
101
+ case RectThirdPoint.BL:
102
+ return [x - (width / 2 + innerLeft + outerLeft) / 3, y + (height / 2 + innerBottom + outerBottom) / 3];
103
+ case RectThirdPoint.BR:
104
+ return [x + (width / 2 + innerRight + outerRight) / 3, y + (height / 2 + innerBottom + outerBottom) / 3];
105
+ case RectThirdPoint.LT:
106
+ return [x - (width / 2 + innerLeft + outerLeft) / 3, y - (height / 2 + innerTop + outerTop) / 3];
107
+ case RectThirdPoint.LB:
108
+ return [x - (width / 2 + innerLeft + outerLeft) / 3, y + (height / 2 + innerBottom + outerBottom) / 3];
109
+ case RectThirdPoint.RT:
110
+ return [x + (width / 2 + innerRight + outerRight) / 3, y - (height / 2 + innerTop + outerTop) / 3];
111
+ case RectThirdPoint.RB:
112
+ return [x + (width / 2 + innerRight + outerRight) / 3, y + (height / 2 + innerBottom + outerBottom) / 3];
113
+ }
114
+ }
115
+ /** 获取外部点与 node 中心连线与外边缘的交点 */
116
+ getCrossPoint(point) {
117
+ if (!this.init) return this.center;
118
+ const pointArea = this.getPointArea(point);
119
+ if (pointArea === Area.EDGE) return point;
120
+ const line = Line.fromPoints(point, this.center);
121
+ const PointTL = this.getOuterPoint(RectVertexPoint.TL);
122
+ const PointTR = this.getOuterPoint(RectVertexPoint.TR);
123
+ const topCrossPoint = line.getIntersection(Line.fromPoints(PointTL, PointTR));
124
+ if (topCrossPoint && point[1] < this.center[1] && between(topCrossPoint[0], [PointTL[0], PointTR[0]], true)) {
125
+ return topCrossPoint;
126
+ }
127
+ const PointBL = this.getOuterPoint(RectVertexPoint.BL);
128
+ const PointBR = this.getOuterPoint(RectVertexPoint.BR);
129
+ const belowCrossPoint = line.getIntersection(Line.fromPoints(PointBL, PointBR));
130
+ if (belowCrossPoint && point[1] > this.center[1] && between(belowCrossPoint[0], [PointBL[0], PointBR[0]], true))
131
+ return belowCrossPoint;
132
+ const leftCrossPoint = line.getIntersection(Line.fromPoints(PointTL, PointBL));
133
+ if (leftCrossPoint && point[0] < this.center[0] && between(leftCrossPoint[1], [PointTL[1], PointBL[1]], true))
134
+ return leftCrossPoint;
135
+ const rightCrossPoint = line.getIntersection(Line.fromPoints(PointTR, PointBR));
136
+ return rightCrossPoint;
137
+ }
138
+ /** 获取到边界的距离 */
139
+ getOuterDistance(direction) {
140
+ switch (direction) {
141
+ case "top":
142
+ return this.size[1] / 2 + this.innerSep.top + this.outerSep.top;
143
+ case "bottom":
144
+ return this.size[1] / 2 + this.innerSep.bottom + this.outerSep.bottom;
145
+ case "left":
146
+ return this.size[0] / 2 + this.innerSep.left + this.outerSep.left;
147
+ case "right":
148
+ return this.size[0] / 2 + this.innerSep.right + this.outerSep.right;
149
+ }
150
+ }
151
+ };
152
+ /** 判断某个变量是否为初始化完成的节点 */
153
+ __publicField(_NodeModel, "isInitializedNode", (node) => {
154
+ return _NodeModel.isNode(node) && node.init;
155
+ });
156
+ __publicField(_NodeModel, "isNode", (node) => {
157
+ if (typeof node !== "object" || node === null) return false;
158
+ if (!("type" in node) || !Array.isArray(node.type)) return false;
159
+ return node.type.includes("node");
160
+ });
161
+ let NodeModel = _NodeModel;
162
+ export {
163
+ NodeModel as default
164
+ };
@@ -0,0 +1,19 @@
1
+ import { Position } from '../../types/coordinate/descartes';
2
+ export type StateListener = (state?: PathModel, prevState?: PathModel) => void;
3
+ export default class PathModel {
4
+ type: string[];
5
+ init: boolean;
6
+ disposed: boolean;
7
+ ways: Array<Position[]>;
8
+ lineWidth: number;
9
+ listeners: Set<StateListener>;
10
+ constructor(ways: Array<Position[]>, lineWidth: number, init?: boolean);
11
+ update(config: {
12
+ ways?: Array<Position[]>;
13
+ lineWidth?: number;
14
+ init?: boolean;
15
+ }): void;
16
+ notify(preSelf?: PathModel): void;
17
+ subscribe(listener: StateListener): () => boolean;
18
+ dispose(): void;
19
+ }
@@ -0,0 +1,47 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ class PathModel {
5
+ constructor(ways, lineWidth, init = true) {
6
+ __publicField(this, "type", ["path"]);
7
+ __publicField(this, "init", false);
8
+ __publicField(this, "disposed", false);
9
+ __publicField(this, "ways", []);
10
+ __publicField(this, "lineWidth", 1);
11
+ __publicField(this, "listeners", /* @__PURE__ */ new Set());
12
+ this.update({ ways, lineWidth, init });
13
+ }
14
+ update(config) {
15
+ const { ways, lineWidth, init } = config;
16
+ const preSelf = { ...this };
17
+ let needUpdate = false;
18
+ if (!this.init && init) {
19
+ this.init = init;
20
+ needUpdate = true;
21
+ }
22
+ if (ways && ways !== this.ways) {
23
+ this.ways = ways;
24
+ needUpdate = true;
25
+ }
26
+ if (lineWidth && lineWidth !== this.lineWidth) {
27
+ this.lineWidth = lineWidth;
28
+ needUpdate = true;
29
+ }
30
+ if (this.init && needUpdate) this.notify(preSelf);
31
+ }
32
+ notify(preSelf) {
33
+ this.listeners.forEach((listener) => listener({ ...this }, preSelf));
34
+ }
35
+ subscribe(listener) {
36
+ this.listeners.add(listener);
37
+ return () => this.listeners.delete(listener);
38
+ }
39
+ dispose() {
40
+ this.listeners.clear();
41
+ this.disposed = true;
42
+ this.notify(this);
43
+ }
44
+ }
45
+ export {
46
+ PathModel as default
47
+ };
@@ -0,0 +1,21 @@
1
+ import { Position } from '../../types/coordinate/descartes';
2
+ export default class Line {
3
+ private a;
4
+ private b;
5
+ private c;
6
+ constructor(a: number, b: number, c: number);
7
+ getY(x: number): number | undefined;
8
+ getX(y: number): number | undefined;
9
+ /** 判断点是否在线上 */
10
+ isPointOn(point: Position, epsilon?: number): boolean;
11
+ /** 两点获取直线方程 */
12
+ static fromPoints: (point1: Position, point2: Position) => Line;
13
+ /** 获取两点的夹角(弧度制) */
14
+ static getDegree: (point1: Position, point2: Position) => number;
15
+ /** 根据百分比获取点位置 */
16
+ static getPositionByPercent: (startPoint: Position, endPoint: Position, percent: number) => Position;
17
+ /** 获取两条直线交点 */
18
+ getIntersection(line: Line, epsilon?: number): Position | undefined;
19
+ /** 点到直线距离 */
20
+ getPointDistance(point: Position): number;
21
+ }
@@ -0,0 +1,75 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ const _Line = class _Line {
5
+ constructor(a, b, c) {
6
+ // 一般式系数 Ax + By + C = 0,A >= 0
7
+ __publicField(this, "a", 0);
8
+ __publicField(this, "b", 0);
9
+ __publicField(this, "c", 0);
10
+ if (a === 0 && b === 0) {
11
+ return;
12
+ }
13
+ this.a = a;
14
+ this.b = b;
15
+ this.c = c;
16
+ }
17
+ getY(x) {
18
+ if (this.b === 0) return;
19
+ return -(this.a * x + this.c) / this.b;
20
+ }
21
+ getX(y) {
22
+ if (this.a === 0) return;
23
+ return -(this.b * y + this.c) / this.a;
24
+ }
25
+ /** 判断点是否在线上 */
26
+ isPointOn(point, epsilon = 1e-9) {
27
+ const value = this.a * point[0] + this.b * point[1] + this.c;
28
+ return Math.abs(value) <= epsilon;
29
+ }
30
+ /** 获取两条直线交点 */
31
+ getIntersection(line, epsilon = 1e-9) {
32
+ const A1 = this.a;
33
+ const B1 = this.b;
34
+ const C1 = this.c;
35
+ const A2 = line.a;
36
+ const B2 = line.b;
37
+ const C2 = line.c;
38
+ const D = A1 * B2 - A2 * B1;
39
+ if (Math.abs(D) <= epsilon) return;
40
+ const x = (C2 * B1 - C1 * B2) / D;
41
+ const y = (A2 * C1 - A1 * C2) / D;
42
+ return [x, y];
43
+ }
44
+ /** 点到直线距离 */
45
+ getPointDistance(point) {
46
+ return Math.abs(this.a * point[0] + this.b * point[1] + this.c) / Math.sqrt(this.a * this.a + this.b * this.b);
47
+ }
48
+ };
49
+ /** 两点获取直线方程 */
50
+ __publicField(_Line, "fromPoints", (point1, point2) => {
51
+ const [x1, y1] = point1;
52
+ const [x2, y2] = point2;
53
+ const A = y2 - y1;
54
+ const B = x1 - x2;
55
+ const C = x2 * y1 - x1 * y2;
56
+ return new _Line(A, B, C);
57
+ });
58
+ /** 获取两点的夹角(弧度制) */
59
+ __publicField(_Line, "getDegree", (point1, point2) => {
60
+ const [x1, y1] = point1;
61
+ const [x2, y2] = point2;
62
+ return Math.atan2(y2 - y1, x2 - x1);
63
+ });
64
+ /** 根据百分比获取点位置 */
65
+ __publicField(_Line, "getPositionByPercent", (startPoint, endPoint, percent) => {
66
+ const [x1, y1] = startPoint;
67
+ const [x2, y2] = endPoint;
68
+ const dirX = x2 - x1;
69
+ const dirY = y2 - y1;
70
+ return [x1 + dirX * percent, y1 + dirY * percent];
71
+ });
72
+ let Line = _Line;
73
+ export {
74
+ Line as default
75
+ };
@@ -0,0 +1,21 @@
1
+ import { PointPosition } from '../../../types/coordinate';
2
+ import { DescartesPosition, Position } from '../../../types/coordinate/descartes';
3
+ import { PolarPosition } from '../../../types/coordinate/polar';
4
+ import { default as PolarPoint } from './PolarPoint';
5
+ /** 笛卡尔坐标点 */
6
+ export default class DescartesPoint {
7
+ readonly position: Position;
8
+ constructor(point: Position | DescartesPosition);
9
+ /** 获取极坐标 */
10
+ getPolarPosition(): PolarPosition;
11
+ /** 获取极点 */
12
+ getPolarPoint(): PolarPoint;
13
+ /** 将笛卡尔坐标点转换为极坐标点 */
14
+ static convertPolarToDescartesPosition: (position: Position) => PolarPosition;
15
+ /** 对象形式转换为数组形式 */
16
+ static covertToPosition: (position: DescartesPosition) => number[];
17
+ /** 将坐标格式转换为笛卡尔坐标数组形式 */
18
+ static formatPosition: (point: PointPosition) => Position;
19
+ /** 多个点相加 */
20
+ static plus: (...positions: Array<PointPosition>) => Position;
21
+ }
@@ -0,0 +1,50 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ import PolarPoint from "./PolarPoint.js";
5
+ const _DescartesPoint = class _DescartesPoint {
6
+ constructor(point) {
7
+ __publicField(this, "position");
8
+ this.position = Array.isArray(point) ? [...point] : [point.x, point.y];
9
+ }
10
+ /** 获取极坐标 */
11
+ getPolarPosition() {
12
+ return _DescartesPoint.convertPolarToDescartesPosition(this.position);
13
+ }
14
+ /** 获取极点 */
15
+ getPolarPoint() {
16
+ return new PolarPoint(this.getPolarPosition());
17
+ }
18
+ };
19
+ /** 将笛卡尔坐标点转换为极坐标点 */
20
+ __publicField(_DescartesPoint, "convertPolarToDescartesPosition", (position) => {
21
+ const [x, y] = position;
22
+ return { radius: Math.sqrt(x * x + y * y), angle: Math.atan2(y, x) };
23
+ });
24
+ /** 对象形式转换为数组形式 */
25
+ __publicField(_DescartesPoint, "covertToPosition", (position) => {
26
+ return [position.x, position.y];
27
+ });
28
+ /** 将坐标格式转换为笛卡尔坐标数组形式 */
29
+ __publicField(_DescartesPoint, "formatPosition", (point) => {
30
+ if (Array.isArray(point)) return point;
31
+ if (point.hasOwnProperty("x") && point.hasOwnProperty("y")) {
32
+ const p = point;
33
+ return [p.x, p.y];
34
+ }
35
+ return PolarPoint.convertPolarToDescartesPosition(point);
36
+ });
37
+ /** 多个点相加 */
38
+ __publicField(_DescartesPoint, "plus", (...positions) => {
39
+ return positions.reduce(
40
+ (acc, cur) => {
41
+ const formatCur = _DescartesPoint.formatPosition(cur);
42
+ return [acc[0] + formatCur[0], acc[1] + formatCur[1]];
43
+ },
44
+ [0, 0]
45
+ );
46
+ });
47
+ let DescartesPoint = _DescartesPoint;
48
+ export {
49
+ DescartesPoint as default
50
+ };