@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,5 @@
1
+ /** 笛卡尔坐标(对象形式) */
2
+ export type PolarPosition = {
3
+ radius: number;
4
+ angle: number;
5
+ };
@@ -0,0 +1,8 @@
1
+ export type CssDistanceType = number | string | undefined;
2
+ /** 四个方向的距离 */
3
+ export type DirectionDistance<T = number> = {
4
+ left: T;
5
+ right: T;
6
+ top: T;
7
+ bottom: T;
8
+ };
@@ -0,0 +1,9 @@
1
+ import { CssDistanceType, DirectionDistance } from '.';
2
+ /** 快捷属性 */
3
+ export type SepShortcutProps<T = CssDistanceType> = {
4
+ defaultVal: T;
5
+ x: T;
6
+ y: T;
7
+ } & DirectionDistance<T>;
8
+ /** 距离的全部属性 */
9
+ export type SepProps<T = CssDistanceType> = T | SepShortcutProps<T>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ var Area = /* @__PURE__ */ ((Area2) => {
4
+ Area2["INSIDE"] = "inside";
5
+ Area2["OUTSIDE"] = "outside";
6
+ Area2["EDGE"] = "edge";
7
+ return Area2;
8
+ })(Area || {});
9
+ exports.Area = Area;
@@ -0,0 +1,8 @@
1
+ /** 几何体范围:内部,外部,边界线上 */
2
+ export declare enum Area {
3
+ INSIDE = "inside",
4
+ OUTSIDE = "outside",
5
+ EDGE = "edge"
6
+ }
7
+ /** 宽高 */
8
+ export type Size = [number, number];
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ var RectVertexPoint = /* @__PURE__ */ ((RectVertexPoint2) => {
4
+ RectVertexPoint2["TL"] = "top_left";
5
+ RectVertexPoint2["TR"] = "top_right";
6
+ RectVertexPoint2["BL"] = "bottom_left";
7
+ RectVertexPoint2["BR"] = "bottom_right";
8
+ return RectVertexPoint2;
9
+ })(RectVertexPoint || {});
10
+ var RectMidPoint = /* @__PURE__ */ ((RectMidPoint2) => {
11
+ RectMidPoint2["T"] = "top_mid";
12
+ RectMidPoint2["B"] = "bottom_mid";
13
+ RectMidPoint2["L"] = "left_mid";
14
+ RectMidPoint2["R"] = "right_mid";
15
+ return RectMidPoint2;
16
+ })(RectMidPoint || {});
17
+ var RectThirdPoint = /* @__PURE__ */ ((RectThirdPoint2) => {
18
+ RectThirdPoint2["TL"] = "third_top_left";
19
+ RectThirdPoint2["TR"] = "third_top_right";
20
+ RectThirdPoint2["BL"] = "third_bottom_left";
21
+ RectThirdPoint2["BR"] = "third_bottom_right";
22
+ RectThirdPoint2["LT"] = "third_left_top";
23
+ RectThirdPoint2["LB"] = "third_left_bottom";
24
+ RectThirdPoint2["RT"] = "third_right_top";
25
+ RectThirdPoint2["RB"] = "third_right_bottom";
26
+ return RectThirdPoint2;
27
+ })(RectThirdPoint || {});
28
+ exports.RectMidPoint = RectMidPoint;
29
+ exports.RectThirdPoint = RectThirdPoint;
30
+ exports.RectVertexPoint = RectVertexPoint;
@@ -0,0 +1,25 @@
1
+ /** 矩形四个顶点 */
2
+ export declare enum RectVertexPoint {
3
+ TL = "top_left",
4
+ TR = "top_right",
5
+ BL = "bottom_left",
6
+ BR = "bottom_right"
7
+ }
8
+ /** 矩形四个边的中点 */
9
+ export declare enum RectMidPoint {
10
+ T = "top_mid",
11
+ B = "bottom_mid",
12
+ L = "left_mid",
13
+ R = "right_mid"
14
+ }
15
+ /** 矩形四边的三等分点 */
16
+ export declare enum RectThirdPoint {
17
+ TL = "third_top_left",
18
+ TR = "third_top_right",
19
+ BL = "third_bottom_left",
20
+ BR = "third_bottom_right",
21
+ LT = "third_left_top",
22
+ LB = "third_left_bottom",
23
+ RT = "third_right_top",
24
+ RB = "third_right_bottom"
25
+ }
@@ -0,0 +1,10 @@
1
+ export type FontWeight = 'normal' | 'bold' | 'bolder' | 'lighter';
2
+ export type FontProps = {
3
+ fill?: 'currentColor' | string;
4
+ fillOpacity?: number;
5
+ fontSize?: string | number;
6
+ fontWeight?: FontWeight | number;
7
+ fontStyle?: 'normal' | 'italic' | 'oblique';
8
+ fontFamily?: string;
9
+ fontStretch?: 'normal' | 'condensed' | 'semi-condensed' | 'ultra-condensed' | 'extra-condensed' | 'expanded' | 'semi-expanded' | 'extra-expanded' | 'ultra-expanded' | 'inherit' | 'initial' | 'revert' | 'revert-layer' | 'unset' | string;
10
+ };
@@ -0,0 +1,10 @@
1
+ export type StrokeProps = {
2
+ stroke?: string;
3
+ strokeWidth?: number;
4
+ strokeDasharray?: string;
5
+ strokeDashoffset?: string;
6
+ strokeLinecap?: 'butt' | 'round' | 'square' | 'inherit';
7
+ strokeLinejoin?: "round" | "inherit" | "bevel" | "miter";
8
+ strokeMiterlimit?: number;
9
+ strokeOpacity?: number;
10
+ };
@@ -0,0 +1,6 @@
1
+ import { Ref } from 'react';
2
+ export type TikZKey = string;
3
+ export type TikZProps = {
4
+ name?: TikZKey;
5
+ ref?: Ref<SVGGElement>;
6
+ };
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const isSameArray = (arr1, arr2) => {
4
+ if (arr1.length !== arr2.length) return false;
5
+ const length = arr1.length;
6
+ for (let i = 0; i < length; i++) {
7
+ if (arr1[i] !== arr2[i]) return false;
8
+ }
9
+ return true;
10
+ };
11
+ const isSameObj = (obj1, obj2) => {
12
+ if (Object.keys(obj1).length !== Object.keys(obj2).length) return false;
13
+ const keys = Object.keys(obj1);
14
+ for (let i = 0; i < keys.length; i++) {
15
+ if (obj1[keys[i]] !== obj2[keys[i]]) return false;
16
+ }
17
+ return true;
18
+ };
19
+ exports.isSameArray = isSameArray;
20
+ exports.isSameObj = isSameObj;
@@ -0,0 +1,4 @@
1
+ /** 判断两个数组内容是否相同 */
2
+ export declare const isSameArray: (arr1: unknown[], arr2: unknown[]) => boolean;
3
+ /** 判断两个对象是否相同 */
4
+ export declare const isSameObj: (obj1: Record<string, unknown>, obj2: Record<string, unknown>) => boolean;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const convertCssToPx = (dimension, sizeConfig) => {
4
+ if (dimension === void 0) return 0;
5
+ if (typeof dimension === "number") return dimension;
6
+ const match = dimension.match(/^(\d+(?:\.\d+)?)(px|em|rem|%)$/);
7
+ const { remPx: remSize = 16, emPx: emSize = 16, parentPx: elementSize = 100 } = sizeConfig || {};
8
+ if (match) {
9
+ const value = parseFloat(match[1]);
10
+ const unit = match[2];
11
+ switch (unit) {
12
+ case "px":
13
+ return value;
14
+ case "em":
15
+ return value * (emSize || remSize || 16);
16
+ case "rem":
17
+ return value * (remSize || 16);
18
+ case "%":
19
+ return elementSize ? value / 100 * elementSize : value;
20
+ default:
21
+ return 0;
22
+ }
23
+ }
24
+ return parseInt(dimension);
25
+ };
26
+ exports.convertCssToPx = convertCssToPx;
@@ -0,0 +1,6 @@
1
+ /** 将 CSS 长度转换为像素 */
2
+ export declare const convertCssToPx: (dimension?: string | number, sizeConfig?: {
3
+ remPx?: number;
4
+ emPx?: number;
5
+ parentPx?: number;
6
+ }) => number;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const between = (value, range, equal) => {
4
+ return equal ? value >= range[0] && value <= range[1] : value > range[0] && value < range[1];
5
+ };
6
+ const convertPrecision = (value, precision, deep = true) => {
7
+ if (precision === false) return value;
8
+ const innerConvert = (value2) => {
9
+ if (precision === 0) return Math.round(value2);
10
+ const realPrecision = 10 ** precision;
11
+ return Math.round(value2 * realPrecision) / realPrecision;
12
+ };
13
+ if (typeof value === "number") return innerConvert(value);
14
+ if (Array.isArray(value))
15
+ return value.map((item) => deep ? innerConvert(item) : typeof item === "number" ? innerConvert(item) : item);
16
+ if (typeof value === "object" && value !== null) {
17
+ const result = {};
18
+ for (const [key, item] of Object.entries(value)) {
19
+ result[key] = deep ? convertPrecision(item, precision) : typeof item === "number" ? innerConvert(item) : item;
20
+ }
21
+ return result;
22
+ }
23
+ return value;
24
+ };
25
+ exports.between = between;
26
+ exports.convertPrecision = convertPrecision;
@@ -0,0 +1,9 @@
1
+ /** 判断值是否在范围内 */
2
+ export declare const between: (value: number, range: [number, number], equal?: boolean) => boolean;
3
+ /**
4
+ * 将数值进行精度调整(主要是为了内存优化)
5
+ * @value 要调整的值
6
+ * @precision 要调整的精度
7
+ * @deep 是否进行深度调整
8
+ * */
9
+ export declare const convertPrecision: <T>(value: T, precision: number | false, deep?: boolean) => T;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const textWrapParse = (text, breakMark = "\\n") => {
4
+ const textArray = text.split(breakMark);
5
+ return textArray;
6
+ };
7
+ exports.textWrapParse = textWrapParse;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 文本换行解析器,将文本根据特定字符分割成数组
3
+ * 默认的换行标识为:\n
4
+ * @param text 原始文本
5
+ * @param breakMark 换行标识
6
+ */
7
+ export declare const textWrapParse: (text: string, breakMark?: string) => string[];
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const TikZFontSizeMap = {
4
+ tiny: "5px",
5
+ script: "8px",
6
+ footnote: "10px",
7
+ small: "12px",
8
+ normal: "16px",
9
+ large: "18px",
10
+ Large: "22px",
11
+ LARGE: "26px",
12
+ huge: "30px",
13
+ Huge: "36px"
14
+ };
15
+ const convertFontSize = (fontSize) => {
16
+ return typeof fontSize === "string" && TikZFontSizeMap.hasOwnProperty(fontSize) ? TikZFontSizeMap[fontSize] : fontSize;
17
+ };
18
+ const convertFontStyle = (fontStyle) => {
19
+ switch (fontStyle) {
20
+ case "bold":
21
+ return { fontWeight: "bold" };
22
+ case "italic":
23
+ return { fontStyle: "italic" };
24
+ case "serif":
25
+ return { fontFamily: "serif" };
26
+ case "sans-serif":
27
+ return { fontFamily: "sans-serif" };
28
+ default:
29
+ return {};
30
+ }
31
+ };
32
+ exports.TikZFontSizeMap = TikZFontSizeMap;
33
+ exports.convertFontSize = convertFontSize;
34
+ exports.convertFontStyle = convertFontStyle;
@@ -0,0 +1,17 @@
1
+ import { FontProps } from '../../types/svg/font';
2
+ export declare const TikZFontSizeMap: {
3
+ tiny: string;
4
+ script: string;
5
+ footnote: string;
6
+ small: string;
7
+ normal: string;
8
+ large: string;
9
+ Large: string;
10
+ LARGE: string;
11
+ huge: string;
12
+ Huge: string;
13
+ };
14
+ export type TikZFontSize = keyof typeof TikZFontSizeMap;
15
+ export declare const convertFontSize: (fontSize?: string | TikZFontSize | number) => string | number | undefined;
16
+ export type FontStyle = 'bold' | 'italic' | 'serif' | 'sans-serif';
17
+ export declare const convertFontStyle: (fontStyle?: FontStyle) => Partial<FontProps>;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const convertStrokeType = (strokeType, strokeWidth = 1) => {
4
+ switch (strokeType) {
5
+ case "solid":
6
+ return {};
7
+ case "dashed":
8
+ return { strokeDasharray: `${strokeWidth * 4} ${strokeWidth * 4}` };
9
+ case "denselyDashed":
10
+ return { strokeDasharray: `${strokeWidth * 4} ${strokeWidth * 2}` };
11
+ case "looselyDashed":
12
+ return { strokeDasharray: `${strokeWidth * 4} ${strokeWidth * 6}` };
13
+ case "dotted":
14
+ return { strokeDasharray: `1 ${strokeWidth * 4}` };
15
+ case "denselyDotted":
16
+ return { strokeDasharray: `1 ${strokeWidth * 2}` };
17
+ case "looselyDotted":
18
+ return { strokeDasharray: `1 ${strokeWidth * 6}` };
19
+ case "dashDot":
20
+ return { strokeDasharray: `${strokeWidth * 4} ${strokeWidth * 4} 1 ${strokeWidth * 4}` };
21
+ case "denselyDashDot":
22
+ return { strokeDasharray: `${strokeWidth * 4} ${strokeWidth * 2} 1 ${strokeWidth * 2}` };
23
+ case "looselyDashDot":
24
+ return { strokeDasharray: `${strokeWidth * 4} ${strokeWidth * 6} 1 ${strokeWidth * 6}` };
25
+ case "dashDashDot":
26
+ return { strokeDasharray: `${strokeWidth * 4} ${strokeWidth * 4} 1 ${strokeWidth * 4} 1 ${strokeWidth * 4}` };
27
+ case "denselyDashDashDot":
28
+ return { strokeDasharray: `${strokeWidth * 4} ${strokeWidth * 2} 1 ${strokeWidth * 2} 1 ${strokeWidth * 2}` };
29
+ case "looselyDashDashDot":
30
+ return { strokeDasharray: `${strokeWidth * 4} ${strokeWidth * 6} 1 ${strokeWidth * 6} 1 ${strokeWidth * 6}` };
31
+ }
32
+ };
33
+ const convertStrokeShortcut = (shortcutProps, strokeWidth = 1) => {
34
+ return convertStrokeType(
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",
36
+ strokeWidth || 1
37
+ );
38
+ };
39
+ exports.convertStrokeShortcut = convertStrokeShortcut;
40
+ exports.convertStrokeType = convertStrokeType;
@@ -0,0 +1,19 @@
1
+ import { StrokeProps } from '../../types/svg/stroke';
2
+ export type StrokeType = 'solid' | 'dashed' | 'denselyDashed' | 'looselyDashed' | 'dotted' | 'denselyDotted' | 'looselyDotted' | 'dashDot' | 'denselyDashDot' | 'looselyDashDot' | 'dashDashDot' | 'denselyDashDashDot' | 'looselyDashDashDot';
3
+ export type StrokeShortcutProps = {
4
+ dashed?: boolean;
5
+ denselyDashed?: boolean;
6
+ looselyDashed?: boolean;
7
+ dotted?: boolean;
8
+ denselyDotted?: boolean;
9
+ looselyDotted?: boolean;
10
+ dashDot?: boolean;
11
+ denselyDashDot?: boolean;
12
+ looselyDashDot?: boolean;
13
+ dashDashDot?: boolean;
14
+ denselyDashDashDot?: boolean;
15
+ looselyDashDashDot?: boolean;
16
+ };
17
+ /** 将 StrokeType 转换为 svg 原生的属性 */
18
+ export declare const convertStrokeType: (strokeType: StrokeType, strokeWidth?: number) => Partial<StrokeProps>;
19
+ export declare const convertStrokeShortcut: (shortcutProps: StrokeShortcutProps, strokeWidth?: number) => Partial<StrokeProps>;
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@retikz/core",
3
+ "version": "0.0.1-rc.0",
4
+ "description": "atomic drawing library implemented using react and d3, inspired by tikz",
5
+ "type": "module",
6
+ "keywords": [
7
+ "react",
8
+ "tikz",
9
+ "chart"
10
+ ],
11
+ "license": "MIT",
12
+ "repository": "https://github.com/Pionpill/retikz",
13
+ "main": "dist/lib/index.js",
14
+ "module": "dist/es/index.js",
15
+ "types": "dist/lib/index.d.ts",
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "files": [
20
+ "LICENSE",
21
+ "README.md",
22
+ "dist/**/*"
23
+ ],
24
+ "scripts": {
25
+ "dev": "vite",
26
+ "build": "vite build",
27
+ "lint": "eslint .",
28
+ "preview": "vite preview"
29
+ },
30
+ "peerDependencies": {
31
+ "react": ">=19.0.0",
32
+ "react-dom": ">=19.0.0"
33
+ },
34
+ "dependencies": {
35
+ "d3-color": "^3.1.0",
36
+ "d3-shape": "^3.2.0",
37
+ "react": "^19",
38
+ "react-dom": "^19"
39
+ },
40
+ "devDependencies": {
41
+ "@eslint/js": "^9.15.0",
42
+ "@types/d3-color": "^3.1.3",
43
+ "@types/d3-shape": "^3.1.6",
44
+ "@types/node": "^22.10.7",
45
+ "@types/react": "^19",
46
+ "@types/react-dom": "^19",
47
+ "@vitejs/plugin-react": "^4.3.4",
48
+ "eslint": "^9.15.0",
49
+ "eslint-plugin-react-hooks": "^5.0.0",
50
+ "eslint-plugin-react-refresh": "^0.4.14",
51
+ "globals": "^15.12.0",
52
+ "typescript": "~5.6.2",
53
+ "typescript-eslint": "^8.15.0",
54
+ "vite": "^6.0.1",
55
+ "vite-plugin-dts": "^4.5.0"
56
+ }
57
+ }