heitu 1.0.2 → 1.0.3

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 (71) hide show
  1. package/dist/canvas/constant/index.d.ts +0 -12
  2. package/dist/canvas/constant/index.js +19 -2
  3. package/dist/canvas/element/circle.d.ts +15 -0
  4. package/dist/canvas/element/{Circle.js → circle.js} +16 -23
  5. package/dist/canvas/element/line.d.ts +14 -0
  6. package/dist/canvas/element/{Line.js → line.js} +19 -32
  7. package/dist/canvas/element/rect.d.ts +14 -0
  8. package/dist/canvas/element/{Rect.js → rect.js} +16 -21
  9. package/dist/canvas/element/{Stage.d.ts → stage/index.d.ts} +3 -3
  10. package/dist/canvas/element/stage/index.js +8 -0
  11. package/dist/canvas/element/stage/stage.d.ts +4 -0
  12. package/dist/canvas/element/{Stage.js → stage/stage.js} +8 -20
  13. package/dist/canvas/element/text.d.ts +11 -0
  14. package/dist/canvas/element/text.js +25 -0
  15. package/dist/canvas/index.d.ts +6 -7
  16. package/dist/canvas/index.js +6 -7
  17. package/dist/canvas/store/index.d.ts +21 -3
  18. package/dist/canvas/store/index.js +66 -2
  19. package/dist/canvas/type.d.ts +17 -4
  20. package/dist/canvas/utils/constant.d.ts +1 -0
  21. package/dist/canvas/utils/constant.js +1 -0
  22. package/dist/canvas/utils/{renderShape/renderCircle.d.ts → drawShape/circle.d.ts} +2 -3
  23. package/dist/canvas/utils/drawShape/circle.js +80 -0
  24. package/dist/canvas/utils/drawShape/index.d.ts +2 -0
  25. package/dist/canvas/utils/drawShape/index.js +28 -0
  26. package/dist/canvas/utils/drawShape/line.js +0 -0
  27. package/dist/canvas/utils/drawShape/rect.d.ts +3 -0
  28. package/dist/canvas/utils/drawShape/rect.js +68 -0
  29. package/dist/canvas/utils/drawShape/text.d.ts +2 -0
  30. package/dist/canvas/utils/drawShape/text.js +20 -0
  31. package/dist/canvas/utils/index.d.ts +0 -1
  32. package/dist/canvas/utils/index.js +0 -7
  33. package/dist/canvas/utils/stage.d.ts +6 -0
  34. package/dist/canvas/utils/stage.js +29 -0
  35. package/package.json +5 -2
  36. package/dist/canvas/element/Circle.d.ts +0 -2
  37. package/dist/canvas/element/Line.d.ts +0 -13
  38. package/dist/canvas/element/Rect.d.ts +0 -10
  39. package/dist/canvas/element/Sector.d.ts +0 -2
  40. package/dist/canvas/element/Sector.js +0 -41
  41. package/dist/canvas/element/Trapezoid.d.ts +0 -10
  42. package/dist/canvas/element/Trapezoid.js +0 -38
  43. package/dist/canvas/instance/api/api.d.ts +0 -13
  44. package/dist/canvas/instance/api/api.js +0 -66
  45. package/dist/canvas/instance/api/scheduler.d.ts +0 -6
  46. package/dist/canvas/instance/api/scheduler.js +0 -26
  47. package/dist/canvas/instance/circle.d.ts +0 -17
  48. package/dist/canvas/instance/circle.js +0 -42
  49. package/dist/canvas/instance/line.d.ts +0 -16
  50. package/dist/canvas/instance/line.js +0 -28
  51. package/dist/canvas/instance/rect.d.ts +0 -16
  52. package/dist/canvas/instance/rect.js +0 -28
  53. package/dist/canvas/instance/shape.d.ts +0 -42
  54. package/dist/canvas/instance/shape.js +0 -70
  55. package/dist/canvas/instance/stage.d.ts +0 -21
  56. package/dist/canvas/instance/stage.js +0 -88
  57. package/dist/canvas/instance/trapezoid.d.ts +0 -12
  58. package/dist/canvas/instance/trapezoid.js +0 -24
  59. package/dist/canvas/utils/hooks/usePropertyChange.d.ts +0 -1
  60. package/dist/canvas/utils/hooks/usePropertyChange.js +0 -23
  61. package/dist/canvas/utils/renderShape/common.d.ts +0 -3
  62. package/dist/canvas/utils/renderShape/common.js +0 -55
  63. package/dist/canvas/utils/renderShape/index.d.ts +0 -1
  64. package/dist/canvas/utils/renderShape/index.js +0 -47
  65. package/dist/canvas/utils/renderShape/renderCircle.js +0 -88
  66. package/dist/canvas/utils/renderShape/renderLine.js +0 -86
  67. package/dist/canvas/utils/renderShape/renderRect.d.ts +0 -2
  68. package/dist/canvas/utils/renderShape/renderRect.js +0 -28
  69. package/dist/canvas/utils/renderShape/renderTrapezoid.d.ts +0 -2
  70. package/dist/canvas/utils/renderShape/renderTrapezoid.js +0 -26
  71. /package/dist/canvas/utils/{renderShape/renderLine.d.ts → drawShape/line.d.ts} +0 -0
@@ -1,12 +0,0 @@
1
- export type EventType = 'mouseleave' | 'mouseenter' | 'mousemove' | 'mousedown' | 'mouseup' | 'click';
2
- export type OnEventType = `on${EventType}`;
3
- export declare const dpr: number;
4
- export type EventParameter = {
5
- target: any;
6
- x: number;
7
- y: number;
8
- dx?: number;
9
- dy?: number;
10
- nativeEvent?: MouseEvent;
11
- };
12
- export declare const eventStageList: OnEventType[];
@@ -1,4 +1,21 @@
1
1
  // import { IShape } from '../type';
2
+ // export type EventType = 'mouseleave' | 'mouseenter' | 'mousemove' | 'mousedown' | 'mouseup' | 'click'
3
+ // export type OnEventType = `on${EventType}`
2
4
 
3
- export var dpr = window.devicePixelRatio;
4
- export var eventStageList = ['onmouseleave', 'onmouseenter', 'onmousemove', 'onmousedown', 'onmouseup', 'onclick'];
5
+ // export const dpr = window.devicePixelRatio;
6
+ // export type EventParameter = {
7
+ // target: any;
8
+ // x: number;
9
+ // y: number;
10
+ // dx?: number;
11
+ // dy?: number;
12
+ // nativeEvent?: MouseEvent;
13
+ // };
14
+ // export const eventStageList: OnEventType[] = [
15
+ // 'onmouseleave',
16
+ // 'onmouseenter',
17
+ // 'onmousemove',
18
+ // 'onmousedown',
19
+ // 'onmouseup',
20
+ // 'onclick',
21
+ // ];
@@ -0,0 +1,15 @@
1
+ export interface ICircle {
2
+ x?: number;
3
+ y?: number;
4
+ radius?: number;
5
+ lineWidth?: number;
6
+ fillStyle?: string;
7
+ strokeStyle?: string;
8
+ arc?: boolean;
9
+ startAngle?: number;
10
+ endAngle?: number;
11
+ innerRadius?: number;
12
+ border: 0 | 1 | 2;
13
+ }
14
+ declare const Circle: (props: ICircle) => null;
15
+ export default Circle;
@@ -4,35 +4,28 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
4
4
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
6
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
- import { useContext, useLayoutEffect, useRef } from 'react';
8
- import { Circle as _Circle } from "../instance/circle";
9
- import { Context } from "../store";
10
- import { usePropertyChange } from "../utils/hooks/usePropertyChange";
11
- // import { usePropertyChange } from '../utils/hooks/usePropertyChange';
12
-
13
- var defaultProps = {
7
+ import { useLayoutEffect, useRef } from 'react';
8
+ import { v4 } from 'uuid';
9
+ import { Store } from "../store";
10
+ var defaultCircledata = {
14
11
  x: 10,
15
12
  y: 10,
16
13
  radius: 8,
17
- fillStyle: 'black'
14
+ fillStyle: 'black',
15
+ strokeStyle: '',
16
+ lineWidth: 1,
17
+ startAngle: 0,
18
+ endAngle: 360,
19
+ border: 0,
20
+ innerRadius: 0
18
21
  };
19
22
  var Circle = function Circle(props) {
20
- var mergeProps = _objectSpread(_objectSpread({}, defaultProps), props);
21
- var parent = useContext(Context);
22
- var circle = new _Circle(mergeProps);
23
- var circleRef = useRef(circle);
24
- usePropertyChange(mergeProps, 'radius', circleRef.current);
25
- usePropertyChange(mergeProps, 'x', circleRef.current);
26
- usePropertyChange(mergeProps, 'y', circleRef.current);
27
- usePropertyChange(mergeProps, 'fillStyle', circleRef.current);
28
- usePropertyChange(mergeProps, 'strokeStyle', circleRef.current);
29
- usePropertyChange(mergeProps, 'lineWidth', circleRef.current);
23
+ var _Store$useContainer = Store.useContainer(),
24
+ appendChild = _Store$useContainer.common.appendChild;
25
+ var ref = useRef(v4());
30
26
  useLayoutEffect(function () {
31
- parent.appendChild(circleRef.current);
32
- return function () {
33
- // rectRef.current.remove();
34
- };
35
- }, []);
27
+ appendChild('Circle', _objectSpread(_objectSpread({}, defaultCircledata), props), ref.current);
28
+ }, [props]);
36
29
  return null;
37
30
  };
38
31
  export default Circle;
@@ -0,0 +1,14 @@
1
+ export interface ILine {
2
+ x?: number;
3
+ y?: number;
4
+ width?: number;
5
+ height?: number;
6
+ cornerRadius?: number;
7
+ fillStyle?: string;
8
+ lineWidth?: number;
9
+ strokeStyle?: string;
10
+ border: 0 | 1 | 2;
11
+ shortLength?: number;
12
+ }
13
+ declare const Line: (props: ILine) => null;
14
+ export default Line;
@@ -4,42 +4,29 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
4
4
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
6
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
- import { useContext, useLayoutEffect, useRef } from 'react';
8
- import { Line as _Line } from "../instance/line";
9
- import { Context } from "../store";
10
- // import { usePropertyChange } from '../utils/hooks/usePropertyChange';
11
-
12
- var defaultProps = {
13
- // @ts-ignore
14
- points: [10, 10, 100, 100],
7
+ import { useLayoutEffect, useRef } from 'react';
8
+ import { v4 } from 'uuid';
9
+ import { Store } from "../store";
10
+ var defaultLinedata = {
11
+ x: 0,
12
+ y: 0,
13
+ width: 100,
14
+ height: 100,
15
+ fillStyle: 'black',
15
16
  strokeStyle: 'black',
16
- start: {
17
- x: 0,
18
- y: 0
19
- },
20
- end: {
21
- x: 100,
22
- y: 100
23
- }
17
+ cornerRadius: 0,
18
+ lineWidth: 1,
19
+ border: 0
24
20
  };
25
21
  var Line = function Line(props) {
26
- var mergeProps = _objectSpread(_objectSpread({}, defaultProps), props);
27
- var parent = useContext(Context);
28
- var line = new _Line(mergeProps);
29
- var lineRef = useRef(line);
30
-
31
- // usePropertyChange(mergeProps, 'width', rectRef.current);
32
- // usePropertyChange(mergeProps, 'height', rectRef.current);
33
- // usePropertyChange(mergeProps, 'x', rectRef.current);
34
- // usePropertyChange(mergeProps, 'y', rectRef.current);
35
- // usePropertyChange(mergeProps, 'fillStyle', rectRef.current);
36
-
22
+ var _Store$useContainer = Store.useContainer(),
23
+ appendChild = _Store$useContainer.common.appendChild;
24
+ var ref = useRef(v4());
37
25
  useLayoutEffect(function () {
38
- parent.appendChild(lineRef.current);
39
- return function () {
40
- // rectRef.current.remove();
41
- };
42
- }, []);
26
+ appendChild('Line', _objectSpread(_objectSpread(_objectSpread({}, defaultLinedata), props), {}, {
27
+ shortLength: props.shortLength ? props.shortLength : props.width
28
+ }), ref.current);
29
+ }, [props]);
43
30
  return null;
44
31
  };
45
32
  export default Line;
@@ -0,0 +1,14 @@
1
+ export interface IRect {
2
+ x?: number;
3
+ y?: number;
4
+ width?: number;
5
+ height?: number;
6
+ cornerRadius?: number;
7
+ fillStyle?: string;
8
+ lineWidth?: number;
9
+ strokeStyle?: string;
10
+ border: 0 | 1 | 2;
11
+ shortLength?: number;
12
+ }
13
+ declare const Rect: (props: IRect) => null;
14
+ export default Rect;
@@ -4,34 +4,29 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
4
4
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
6
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
- import { useContext, useLayoutEffect, useRef } from 'react';
8
- import { Rect as _Rect } from "../instance/rect";
9
- import { Context } from "../store";
10
- import { usePropertyChange } from "../utils/hooks/usePropertyChange";
11
- var defaultProps = {
7
+ import { useLayoutEffect, useRef } from 'react';
8
+ import { v4 } from 'uuid';
9
+ import { Store } from "../store";
10
+ var defaultRectdata = {
12
11
  x: 0,
13
12
  y: 0,
14
13
  width: 100,
15
14
  height: 100,
16
- fillStyle: 'black'
15
+ fillStyle: 'black',
16
+ strokeStyle: 'black',
17
+ cornerRadius: 0,
18
+ lineWidth: 1,
19
+ border: 0
17
20
  };
18
21
  var Rect = function Rect(props) {
19
- var mergeProps = _objectSpread(_objectSpread({}, defaultProps), props);
20
- var parent = useContext(Context);
21
- var rect = new _Rect(mergeProps);
22
- var rectRef = useRef(rect);
23
- console.log(mergeProps.fillStyle);
24
- usePropertyChange(mergeProps, 'width', rectRef.current);
25
- usePropertyChange(mergeProps, 'height', rectRef.current);
26
- usePropertyChange(mergeProps, 'x', rectRef.current);
27
- usePropertyChange(mergeProps, 'y', rectRef.current);
28
- usePropertyChange(mergeProps, 'fillStyle', rectRef.current);
22
+ var _Store$useContainer = Store.useContainer(),
23
+ appendChild = _Store$useContainer.common.appendChild;
24
+ var ref = useRef(v4());
29
25
  useLayoutEffect(function () {
30
- parent.appendChild(rectRef.current);
31
- return function () {
32
- // rectRef.current.remove();
33
- };
34
- }, []);
26
+ appendChild('Rect', _objectSpread(_objectSpread(_objectSpread({}, defaultRectdata), props), {}, {
27
+ shortLength: props.shortLength ? props.shortLength : props.width
28
+ }), ref.current);
29
+ }, [props]);
35
30
  return null;
36
31
  };
37
32
  export default Rect;
@@ -1,5 +1,5 @@
1
1
  import React, { CSSProperties } from 'react';
2
- interface StageProps extends CSSProperties {
2
+ export interface StageProps extends CSSProperties {
3
3
  children?: any;
4
4
  width?: number | string;
5
5
  height?: number;
@@ -7,5 +7,5 @@ interface StageProps extends CSSProperties {
7
7
  background?: string;
8
8
  margin?: string | number;
9
9
  }
10
- declare const Stage: (props: StageProps) => React.JSX.Element;
11
- export default Stage;
10
+ declare const ContextStage: (props: StageProps) => React.JSX.Element;
11
+ export default ContextStage;
@@ -0,0 +1,8 @@
1
+ import { Store } from "../../store";
2
+ import React, { useEffect } from 'react';
3
+ import Stage from "./stage";
4
+ var ContextStage = function ContextStage(props) {
5
+ useEffect(function () {}, []);
6
+ return /*#__PURE__*/React.createElement(Store.Provider, null, /*#__PURE__*/React.createElement(Stage, props), props.children);
7
+ };
8
+ export default ContextStage;
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { StageProps } from '.';
3
+ declare const Stage: (props: StageProps) => React.JSX.Element;
4
+ export default Stage;
@@ -5,8 +5,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
5
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
6
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
7
  import React, { useLayoutEffect, useRef } from 'react';
8
- import { Stage as _Stage } from "../instance/stage";
9
- import { Context } from "../store";
8
+ import { Store } from "../../store";
10
9
  var defaultProps = {
11
10
  width: '100%',
12
11
  height: 400,
@@ -14,27 +13,16 @@ var defaultProps = {
14
13
  margin: '0 auto'
15
14
  };
16
15
  var Stage = function Stage(props) {
17
- var containerRef = useRef(null);
18
- var stageRef = useRef(new _Stage());
16
+ var store = Store.useContainer();
17
+ var ref = useRef(null);
19
18
  var mergeProps = _objectSpread(_objectSpread({}, defaultProps), props);
19
+ var initStage = store.stage.initStage;
20
20
  useLayoutEffect(function () {
21
- stageRef.current.mount({
22
- container: containerRef.current
23
- });
21
+ if (ref.current) initStage(ref.current);
24
22
  }, []);
25
- // 递归 遍历子元素 获取 tag name
26
- // React.Children.forEach(props.children, (child) => {
27
- // if (React.isValidElement(child)) {
28
- // const tagName =
29
- // typeof child.type === 'string' ? child.type : child.type.name;
30
- // console.log('Child tag name:', tagName);
31
- // }
32
- // });
33
- return /*#__PURE__*/React.createElement(Context.Provider, {
34
- value: stageRef.current
35
- }, /*#__PURE__*/React.createElement("div", {
36
- ref: containerRef,
23
+ return /*#__PURE__*/React.createElement("div", {
24
+ ref: ref,
37
25
  style: mergeProps
38
- }), props.children);
26
+ });
39
27
  };
40
28
  export default Stage;
@@ -0,0 +1,11 @@
1
+ export interface IText {
2
+ x?: number;
3
+ y?: number;
4
+ content?: string;
5
+ fillStyle?: string;
6
+ fontSize?: number;
7
+ textAlign?: CanvasTextAlign;
8
+ textBaseline?: CanvasTextBaseline;
9
+ }
10
+ declare const Text: (props: IText) => null;
11
+ export default Text;
@@ -0,0 +1,25 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ import { useLayoutEffect, useRef } from 'react';
8
+ import { v4 } from 'uuid';
9
+ import { Store } from "../store";
10
+ var defaultTextdata = {
11
+ fillStyle: '#333',
12
+ fontSize: 14,
13
+ textAlign: 'left',
14
+ textBaseline: 'top'
15
+ };
16
+ var Text = function Text(props) {
17
+ var _Store$useContainer = Store.useContainer(),
18
+ appendChild = _Store$useContainer.common.appendChild;
19
+ var ref = useRef(v4());
20
+ useLayoutEffect(function () {
21
+ appendChild('Text', _objectSpread(_objectSpread({}, defaultTextdata), props), ref.current);
22
+ }, [props]);
23
+ return null;
24
+ };
25
+ export default Text;
@@ -1,7 +1,6 @@
1
- import Circle from './element/Circle';
2
- import Line from './element/Line';
3
- import Rect from './element/Rect';
4
- import Sector from './element/Sector';
5
- import Stage from './element/Stage';
6
- import Trapezoid from './element/Trapezoid';
7
- export { Circle, Line, Rect, Sector, Stage, Trapezoid };
1
+ import Circle from './element/circle';
2
+ import Line from './element/line';
3
+ import Rect from './element/rect';
4
+ import Stage from './element/stage';
5
+ import Text from './element/text';
6
+ export { Circle, Line, Rect, Stage, Text };
@@ -1,7 +1,6 @@
1
- import Circle from "./element/Circle";
2
- import Line from "./element/Line";
3
- import Rect from "./element/Rect";
4
- import Sector from "./element/Sector";
5
- import Stage from "./element/Stage";
6
- import Trapezoid from "./element/Trapezoid";
7
- export { Circle, Line, Rect, Sector, Stage, Trapezoid };
1
+ import Circle from "./element/circle";
2
+ import Line from "./element/line";
3
+ import Rect from "./element/rect";
4
+ import Stage from "./element/stage";
5
+ import Text from "./element/text";
6
+ export { Circle, Line, Rect, Stage, Text };
@@ -1,3 +1,21 @@
1
- /// <reference types="react" />
2
- import { Stage as _Stage } from '../instance/stage';
3
- export declare const Context: import("react").Context<_Stage>;
1
+ import { IShape, IShapeType } from '../type';
2
+ interface Child {
3
+ id: string;
4
+ data: IShape;
5
+ type: IShapeType;
6
+ }
7
+ export interface StageState {
8
+ ctx: CanvasRenderingContext2D | null;
9
+ children: Child[] | [];
10
+ element: HTMLCanvasElement | null;
11
+ }
12
+ export declare const Store: import("unstated-next").Container<{
13
+ stage: {
14
+ initStage: (canvasContainer: HTMLDivElement) => void;
15
+ refreshDraw: () => void;
16
+ };
17
+ common: {
18
+ appendChild: (type: IShapeType, data: IShape, id: string) => void;
19
+ };
20
+ }, void>;
21
+ export {};
@@ -1,2 +1,66 @@
1
- import { createContext } from 'react';
2
- export var Context = /*#__PURE__*/createContext({});
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
7
+ import { useRef } from 'react';
8
+ import { createContainer } from 'unstated-next';
9
+ import { drawShape } from "../utils/drawShape";
10
+ import { createCanvas } from "../utils/stage";
11
+ var useStore = function useStore() {
12
+ var stageRef = useRef({
13
+ children: [],
14
+ ctx: null,
15
+ element: null
16
+ });
17
+ var initStage = function initStage(canvasContainer) {
18
+ var offsetWidth = canvasContainer.offsetWidth,
19
+ offsetHeight = canvasContainer.offsetHeight;
20
+ var _createCanvas = createCanvas(offsetWidth, offsetHeight),
21
+ canvasElement = _createCanvas.canvasElement,
22
+ ctx = _createCanvas.ctx;
23
+ canvasContainer.append(canvasElement);
24
+ stageRef.current.ctx = ctx;
25
+ stageRef.current.element = canvasElement;
26
+ };
27
+ var appendChild = function appendChild(type, data, id) {
28
+ if (!stageRef.current.ctx || !stageRef.current.element) return;
29
+ var children = stageRef.current.children;
30
+ var curChildren = _toConsumableArray(children);
31
+ if (children.some(function (child) {
32
+ return child.id === id;
33
+ })) {
34
+ curChildren = children.map(function (child) {
35
+ if (child.id === id) {
36
+ return {
37
+ id: id,
38
+ data: data,
39
+ type: type
40
+ };
41
+ }
42
+ return child;
43
+ });
44
+ } else {
45
+ curChildren.push({
46
+ id: id,
47
+ data: data,
48
+ type: type
49
+ });
50
+ }
51
+ stageRef.current.children = curChildren;
52
+ drawShape(stageRef.current);
53
+ };
54
+ var refreshDraw = function refreshDraw() {};
55
+ return {
56
+ stage: {
57
+ initStage: initStage,
58
+ // clearStage,
59
+ refreshDraw: refreshDraw
60
+ },
61
+ common: {
62
+ appendChild: appendChild
63
+ }
64
+ };
65
+ };
66
+ export var Store = createContainer(useStore);
@@ -1,7 +1,20 @@
1
1
  // import { BoxHidden, Circle, Group, Line, Rect, Text } from './shape'
2
2
 
3
- // export type IShape = Group | BoxHidden | Circle | Rect | Line | Text
4
- export type IShapeType = 'Line' | 'Rect' | 'Trapezoid' | 'Circle' | 'Text' | 'Group' | 'BoxHidden' | 'Stage'
3
+ import { ICircle } from './element/circle';
4
+ import { IRect } from './element/rect';
5
+ import { IText } from './element/text';
6
+
7
+ export type IShape = IRect | ICircle | IText;
8
+ // |Group | BoxHidden | Circle | Line | Text;
9
+ export type IShapeType =
10
+ | 'Line'
11
+ | 'Rect'
12
+ | 'Trapezoid'
13
+ | 'Circle'
14
+ | 'Text'
15
+ | 'Group'
16
+ | 'BoxHidden'
17
+ | 'Stage';
5
18
 
6
19
  export type ICursor =
7
20
  | 'url'
@@ -20,6 +33,6 @@ export type ICursor =
20
33
  | 'w-resize'
21
34
  | 'text'
22
35
  | 'wait'
23
- | 'help'
36
+ | 'help';
24
37
 
25
- export type ICoord = { x: number; y: number }
38
+ export type ICoord = { x: number; y: number };
@@ -0,0 +1 @@
1
+ export declare const dpr: number;
@@ -0,0 +1 @@
1
+ export var dpr = window.devicePixelRatio;
@@ -1,8 +1,7 @@
1
- import { Circle } from "../../instance/circle";
1
+ import { ICircle } from "../../element/circle";
2
2
  export declare function deg2rad(deg: number): number;
3
- export declare function rad2deg(radian: number): number;
4
3
  export declare function getPointOnArc(x0: number, y0: number, r: number, deg: number): {
5
4
  x: number;
6
5
  y: number;
7
6
  };
8
- export declare function setCirclePath2D(elementItem: Circle): void;
7
+ export declare const drawCircle: (ctx: CanvasRenderingContext2D, props: ICircle) => void;
@@ -0,0 +1,80 @@
1
+ // 角度转弧度
2
+ export function deg2rad(deg) {
3
+ return deg * Math.PI / 180;
4
+ }
5
+ // 获取圆弧上的点 圆心 半径 角度: 60°
6
+ export function getPointOnArc(x0, y0, r, deg) {
7
+ var alpha = deg2rad(deg);
8
+ var x = x0 + r * Math.cos(alpha); // Math.cos 传入弧度
9
+ var y = y0 + r * Math.sin(alpha);
10
+ return {
11
+ x: x,
12
+ y: y
13
+ };
14
+ }
15
+ var calcRingD = function calcRingD(outerRadius, innerRadius, startAngle, endAngle, centerX, centerY, isWholeArc) {
16
+ function calcWholeRingD() {
17
+ var outerM_y = centerY - outerRadius;
18
+ var outerM = "M ".concat(centerX, " ").concat(outerM_y);
19
+ var outerA = "A ".concat(outerRadius, " ").concat(outerRadius, " 0 1 1 ").concat(centerX - 0.01, " ").concat(outerM_y);
20
+ var innerM_y = centerY - innerRadius;
21
+ var innerM = "M ".concat(centerX, " ").concat(innerM_y);
22
+ var innerA = "A ".concat(innerRadius, " ").concat(innerRadius, " 0 1 0 ").concat(centerX + 0.01, " ").concat(innerM_y);
23
+ return "".concat(outerM, " ").concat(outerA, " ").concat(innerM, " ").concat(innerA, " Z");
24
+ }
25
+ function calcRingSectorD() {
26
+ var outerStart = getPointOnArc(centerX, centerY, outerRadius, startAngle);
27
+ var outerEnd = getPointOnArc(centerX, centerY, outerRadius, endAngle);
28
+ var largeArcFlag = endAngle - startAngle >= 180 ? 1 : 0;
29
+ var outerM = "M ".concat(outerStart.x, " ").concat(outerStart.y);
30
+ var outerA = "A ".concat(outerRadius, " ").concat(outerRadius, " 0 ").concat(largeArcFlag, " 1 ").concat(outerEnd.x, " ").concat(outerEnd.y);
31
+ var innerStart = getPointOnArc(centerX, centerY, innerRadius, startAngle);
32
+ var innerEnd = getPointOnArc(centerX, centerY, innerRadius, endAngle);
33
+ var moveL = "L".concat(innerEnd.x, " ").concat(innerEnd.y);
34
+ var innerA = "A ".concat(innerRadius, " ").concat(innerRadius, " 0 ").concat(largeArcFlag, " 0 ").concat(innerStart.x, " ").concat(innerStart.y);
35
+ return "".concat(outerM, " ").concat(outerA, " ").concat(moveL, " ").concat(innerA, " Z");
36
+ }
37
+ return isWholeArc ? calcWholeRingD() : calcRingSectorD();
38
+ };
39
+ export var drawCircle = function drawCircle(ctx, props) {
40
+ var _props$x = props.x,
41
+ x = _props$x === void 0 ? 10 : _props$x,
42
+ _props$y = props.y,
43
+ y = _props$y === void 0 ? 10 : _props$y,
44
+ _props$radius = props.radius,
45
+ radius = _props$radius === void 0 ? 10 : _props$radius,
46
+ _props$startAngle = props.startAngle,
47
+ startAngle = _props$startAngle === void 0 ? 0 : _props$startAngle,
48
+ _props$endAngle = props.endAngle,
49
+ endAngle = _props$endAngle === void 0 ? 360 : _props$endAngle,
50
+ fillStyle = props.fillStyle,
51
+ strokeStyle = props.strokeStyle,
52
+ _props$lineWidth = props.lineWidth,
53
+ lineWidth = _props$lineWidth === void 0 ? 1 : _props$lineWidth,
54
+ _props$innerRadius = props.innerRadius,
55
+ innerRadius = _props$innerRadius === void 0 ? 0 : _props$innerRadius,
56
+ border = props.border;
57
+ var isWholeArc = startAngle === 0 && endAngle === 360; // 是否是整圆
58
+ if (border === 0) {
59
+ var circlePath = new Path2D();
60
+ circlePath.arc(x, y, radius, startAngle, endAngle);
61
+ // 设置绘制样式
62
+ if (fillStyle) ctx.fillStyle = fillStyle; // 填充颜色
63
+ if (lineWidth) ctx.lineWidth = lineWidth; // 描边宽度
64
+ ctx.fill(circlePath);
65
+ } else if (border === 1) {
66
+ var d = calcRingD(radius, innerRadius, startAngle, endAngle, x, y, isWholeArc);
67
+ var _circlePath = new Path2D(d);
68
+ ctx.lineWidth = lineWidth;
69
+ ctx.stroke(_circlePath);
70
+ } else if (border === 2) {
71
+ var _d = calcRingD(radius, innerRadius, startAngle, endAngle, x, y, isWholeArc);
72
+ var _circlePath2 = new Path2D(_d);
73
+ // 设置绘制样式
74
+ if (fillStyle) ctx.fillStyle = fillStyle; // 填充颜色
75
+ if (strokeStyle) ctx.strokeStyle = strokeStyle; // 描边颜色
76
+ if (lineWidth) ctx.lineWidth = lineWidth; // 描边宽度
77
+ ctx.stroke(_circlePath2);
78
+ ctx.fill(_circlePath2);
79
+ }
80
+ };
@@ -0,0 +1,2 @@
1
+ import { StageState } from "../../store";
2
+ export declare const drawShape: (stageState: StageState) => void;