heitu 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +43 -0
  3. package/dist/canvas/constant/index.d.ts +12 -0
  4. package/dist/canvas/constant/index.js +4 -0
  5. package/dist/canvas/element/Circle.d.ts +2 -0
  6. package/dist/canvas/element/Circle.js +38 -0
  7. package/dist/canvas/element/Line.d.ts +13 -0
  8. package/dist/canvas/element/Line.js +45 -0
  9. package/dist/canvas/element/Rect.d.ts +10 -0
  10. package/dist/canvas/element/Rect.js +37 -0
  11. package/dist/canvas/element/Sector.d.ts +2 -0
  12. package/dist/canvas/element/Sector.js +41 -0
  13. package/dist/canvas/element/Stage.d.ts +11 -0
  14. package/dist/canvas/element/Stage.js +40 -0
  15. package/dist/canvas/element/Trapezoid.d.ts +10 -0
  16. package/dist/canvas/element/Trapezoid.js +38 -0
  17. package/dist/canvas/index.d.ts +7 -0
  18. package/dist/canvas/index.js +7 -0
  19. package/dist/canvas/instance/api/api.d.ts +13 -0
  20. package/dist/canvas/instance/api/api.js +66 -0
  21. package/dist/canvas/instance/api/scheduler.d.ts +6 -0
  22. package/dist/canvas/instance/api/scheduler.js +26 -0
  23. package/dist/canvas/instance/circle.d.ts +17 -0
  24. package/dist/canvas/instance/circle.js +42 -0
  25. package/dist/canvas/instance/line.d.ts +16 -0
  26. package/dist/canvas/instance/line.js +28 -0
  27. package/dist/canvas/instance/rect.d.ts +16 -0
  28. package/dist/canvas/instance/rect.js +28 -0
  29. package/dist/canvas/instance/shape.d.ts +42 -0
  30. package/dist/canvas/instance/shape.js +70 -0
  31. package/dist/canvas/instance/stage.d.ts +21 -0
  32. package/dist/canvas/instance/stage.js +88 -0
  33. package/dist/canvas/instance/trapezoid.d.ts +12 -0
  34. package/dist/canvas/instance/trapezoid.js +24 -0
  35. package/dist/canvas/store/index.d.ts +3 -0
  36. package/dist/canvas/store/index.js +2 -0
  37. package/dist/canvas/type.d.ts +25 -0
  38. package/dist/canvas/utils/hooks/usePropertyChange.d.ts +1 -0
  39. package/dist/canvas/utils/hooks/usePropertyChange.js +23 -0
  40. package/dist/canvas/utils/index.d.ts +1 -0
  41. package/dist/canvas/utils/index.js +7 -0
  42. package/dist/canvas/utils/renderShape/common.d.ts +3 -0
  43. package/dist/canvas/utils/renderShape/common.js +55 -0
  44. package/dist/canvas/utils/renderShape/index.d.ts +1 -0
  45. package/dist/canvas/utils/renderShape/index.js +47 -0
  46. package/dist/canvas/utils/renderShape/renderCircle.d.ts +8 -0
  47. package/dist/canvas/utils/renderShape/renderCircle.js +88 -0
  48. package/dist/canvas/utils/renderShape/renderLine.d.ts +0 -0
  49. package/dist/canvas/utils/renderShape/renderLine.js +86 -0
  50. package/dist/canvas/utils/renderShape/renderRect.d.ts +2 -0
  51. package/dist/canvas/utils/renderShape/renderRect.js +28 -0
  52. package/dist/canvas/utils/renderShape/renderTrapezoid.d.ts +2 -0
  53. package/dist/canvas/utils/renderShape/renderTrapezoid.js +26 -0
  54. package/dist/hooks/index.d.ts +8 -0
  55. package/dist/hooks/index.js +8 -0
  56. package/dist/hooks/useCookie/index.d.ts +4 -0
  57. package/dist/hooks/useCookie/index.js +52 -0
  58. package/dist/hooks/useCookie/interface.d.ts +41 -0
  59. package/dist/hooks/useCookie/utils.d.ts +2 -0
  60. package/dist/hooks/useCookie/utils.js +16 -0
  61. package/dist/hooks/useCountDown/index.d.ts +2 -0
  62. package/dist/hooks/useCountDown/index.js +43 -0
  63. package/dist/hooks/useElementSize/index.d.ts +5 -0
  64. package/dist/hooks/useElementSize/index.js +33 -0
  65. package/dist/hooks/useHtAxios/constants.d.ts +2 -0
  66. package/dist/hooks/useHtAxios/constants.js +2 -0
  67. package/dist/hooks/useHtAxios/defaultConfig.d.ts +49 -0
  68. package/dist/hooks/useHtAxios/defaultConfig.js +43 -0
  69. package/dist/hooks/useHtAxios/index.d.ts +13 -0
  70. package/dist/hooks/useHtAxios/index.js +60 -0
  71. package/dist/hooks/useHtAxios/interface.d.ts +0 -0
  72. package/dist/hooks/useHtAxios/request.interceptor.d.ts +8 -0
  73. package/dist/hooks/useHtAxios/request.interceptor.js +66 -0
  74. package/dist/hooks/useHtAxios/response.interceptor.d.ts +9 -0
  75. package/dist/hooks/useHtAxios/response.interceptor.js +74 -0
  76. package/dist/hooks/useHtAxios/typings.d.ts +15 -0
  77. package/dist/hooks/useHtAxios/utils.d.ts +4 -0
  78. package/dist/hooks/useHtAxios/utils.js +40 -0
  79. package/dist/hooks/useInView/index.d.ts +3 -0
  80. package/dist/hooks/useInView/index.js +44 -0
  81. package/dist/hooks/useInView/interface.d.ts +2 -0
  82. package/dist/hooks/useInfiniteScroll/index.d.ts +26 -0
  83. package/dist/hooks/useInfiniteScroll/index.js +111 -0
  84. package/dist/hooks/usePrevious/index.d.ts +2 -0
  85. package/dist/hooks/usePrevious/index.js +14 -0
  86. package/dist/hooks/useResizeObserver/index.d.ts +2 -0
  87. package/dist/hooks/useResizeObserver/index.js +19 -0
  88. package/dist/index.d.ts +2 -0
  89. package/dist/index.js +2 -0
  90. package/dist/utils/defaults.d.ts +1 -0
  91. package/dist/utils/defaults.js +1 -0
  92. package/dist/utils/is.d.ts +14 -0
  93. package/dist/utils/is.js +31 -0
  94. package/dist/utils/types.d.ts +1 -0
  95. package/dist/utils/types.js +1 -0
  96. package/package.json +90 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) peco
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # heitu
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/heitu.svg?style=flat)](https://npmjs.org/package/heitu)
4
+ [![NPM downloads](http://img.shields.io/npm/dm/heitu.svg?style=flat)](https://npmjs.org/package/heitu)
5
+
6
+ diy hook canvas component
7
+
8
+ ## Usage
9
+
10
+ TODO
11
+
12
+ ## Options
13
+
14
+ TODO
15
+
16
+ ## Development
17
+
18
+ ```bash
19
+ # install dependencies
20
+ $ yarn install
21
+
22
+ # develop library by docs demo
23
+ $ yarn start
24
+
25
+ # build library source code
26
+ $ yarn run build
27
+
28
+ # build library source code in watch mode
29
+ $ yarn run build:watch
30
+
31
+ # build docs
32
+ $ yarn run docs:build
33
+
34
+ # Locally preview the production build.
35
+ $ yarn run docs:preview
36
+
37
+ # check your project for potential problems
38
+ $ yarn run doctor
39
+ ```
40
+
41
+ ## LICENSE
42
+
43
+ MIT
@@ -0,0 +1,12 @@
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[];
@@ -0,0 +1,4 @@
1
+ // import { IShape } from '../type';
2
+
3
+ export var dpr = window.devicePixelRatio;
4
+ export var eventStageList = ['onmouseleave', 'onmouseenter', 'onmousemove', 'onmousedown', 'onmouseup', 'onclick'];
@@ -0,0 +1,2 @@
1
+ declare const Circle: (props: any) => null;
2
+ export default Circle;
@@ -0,0 +1,38 @@
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 { 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 = {
14
+ x: 10,
15
+ y: 10,
16
+ radius: 8,
17
+ fillStyle: 'black'
18
+ };
19
+ 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);
30
+ useLayoutEffect(function () {
31
+ parent.appendChild(circleRef.current);
32
+ return function () {
33
+ // rectRef.current.remove();
34
+ };
35
+ }, []);
36
+ return null;
37
+ };
38
+ export default Circle;
@@ -0,0 +1,13 @@
1
+ import { Line as _Line } from '../instance/line';
2
+ export type LineProps = _Line['data'] & {
3
+ start?: {
4
+ x: number;
5
+ y: number;
6
+ };
7
+ end?: {
8
+ x: number;
9
+ y: number;
10
+ };
11
+ };
12
+ declare const Line: (props: LineProps) => null;
13
+ export default Line;
@@ -0,0 +1,45 @@
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 { 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],
15
+ strokeStyle: 'black',
16
+ start: {
17
+ x: 0,
18
+ y: 0
19
+ },
20
+ end: {
21
+ x: 100,
22
+ y: 100
23
+ }
24
+ };
25
+ 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
+
37
+ useLayoutEffect(function () {
38
+ parent.appendChild(lineRef.current);
39
+ return function () {
40
+ // rectRef.current.remove();
41
+ };
42
+ }, []);
43
+ return null;
44
+ };
45
+ export default Line;
@@ -0,0 +1,10 @@
1
+ export interface RectProps {
2
+ width?: number;
3
+ height?: number;
4
+ x?: number;
5
+ y?: number;
6
+ fillStyle?: string;
7
+ cornerRadius?: number;
8
+ }
9
+ declare const Rect: (props: RectProps) => null;
10
+ export default Rect;
@@ -0,0 +1,37 @@
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 { 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 = {
12
+ x: 0,
13
+ y: 0,
14
+ width: 100,
15
+ height: 100,
16
+ fillStyle: 'black'
17
+ };
18
+ 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);
29
+ useLayoutEffect(function () {
30
+ parent.appendChild(rectRef.current);
31
+ return function () {
32
+ // rectRef.current.remove();
33
+ };
34
+ }, []);
35
+ return null;
36
+ };
37
+ export default Rect;
@@ -0,0 +1,2 @@
1
+ declare const Sector: (props: any) => null;
2
+ export default Sector;
@@ -0,0 +1,41 @@
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 { 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 = {
14
+ x: 10,
15
+ y: 10,
16
+ radius: 8,
17
+ fillStyle: 'black',
18
+ startAngle: 30,
19
+ endAngle: 90
20
+ };
21
+ var Sector = function Sector(props) {
22
+ var mergeProps = _objectSpread(_objectSpread({}, defaultProps), props);
23
+ var parent = useContext(Context);
24
+ console.log(mergeProps, 'mergeProps');
25
+ var circle = new _Circle(mergeProps);
26
+ var circleRef = useRef(circle);
27
+ usePropertyChange(mergeProps, 'radius', circleRef.current);
28
+ usePropertyChange(mergeProps, 'x', circleRef.current);
29
+ usePropertyChange(mergeProps, 'y', circleRef.current);
30
+ usePropertyChange(mergeProps, 'fillStyle', circleRef.current);
31
+ usePropertyChange(mergeProps, 'startAngle', circleRef.current);
32
+ usePropertyChange(mergeProps, 'endAngle', circleRef.current);
33
+ useLayoutEffect(function () {
34
+ parent.appendChild(circleRef.current);
35
+ return function () {
36
+ // rectRef.current.remove();
37
+ };
38
+ }, []);
39
+ return null;
40
+ };
41
+ export default Sector;
@@ -0,0 +1,11 @@
1
+ import React, { CSSProperties } from 'react';
2
+ interface StageProps extends CSSProperties {
3
+ children?: any;
4
+ width?: number | string;
5
+ height?: number;
6
+ border?: string;
7
+ background?: string;
8
+ margin?: string | number;
9
+ }
10
+ declare const Stage: (props: StageProps) => React.JSX.Element;
11
+ export default Stage;
@@ -0,0 +1,40 @@
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 React, { useLayoutEffect, useRef } from 'react';
8
+ import { Stage as _Stage } from "../instance/stage";
9
+ import { Context } from "../store";
10
+ var defaultProps = {
11
+ width: '100%',
12
+ height: 400,
13
+ background: '#fff',
14
+ margin: '0 auto'
15
+ };
16
+ var Stage = function Stage(props) {
17
+ var containerRef = useRef(null);
18
+ var stageRef = useRef(new _Stage());
19
+ var mergeProps = _objectSpread(_objectSpread({}, defaultProps), props);
20
+ useLayoutEffect(function () {
21
+ stageRef.current.mount({
22
+ container: containerRef.current
23
+ });
24
+ }, []);
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,
37
+ style: mergeProps
38
+ }), props.children);
39
+ };
40
+ export default Stage;
@@ -0,0 +1,10 @@
1
+ export interface RectProps {
2
+ width?: number;
3
+ height?: number;
4
+ x?: number;
5
+ y?: number;
6
+ fillStyle?: string;
7
+ cornerRadius?: number;
8
+ }
9
+ declare const Trapezoid: (props: RectProps) => null;
10
+ export default Trapezoid;
@@ -0,0 +1,38 @@
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 { useContext, useLayoutEffect, useRef } from 'react';
8
+ import { Trapezoid as _Trapezoid } from "../instance/trapezoid";
9
+ import { Context } from "../store";
10
+ import { usePropertyChange } from "../utils/hooks/usePropertyChange";
11
+ var defaultProps = {
12
+ x: 0,
13
+ y: 0,
14
+ width: 100,
15
+ height: 100,
16
+ fillStyle: 'black'
17
+ };
18
+ var Trapezoid = function Trapezoid(props) {
19
+ var mergeProps = _objectSpread(_objectSpread({}, defaultProps), props);
20
+ var parent = useContext(Context);
21
+ var trapezoid = new _Trapezoid(mergeProps);
22
+ var trapezoidRef = useRef(trapezoid);
23
+ console.log(mergeProps.fillStyle);
24
+ usePropertyChange(mergeProps, 'width', trapezoidRef.current);
25
+ usePropertyChange(mergeProps, 'height', trapezoidRef.current);
26
+ usePropertyChange(mergeProps, 'x', trapezoidRef.current);
27
+ usePropertyChange(mergeProps, 'y', trapezoidRef.current);
28
+ usePropertyChange(mergeProps, 'fillStyle', trapezoidRef.current);
29
+ usePropertyChange(mergeProps, 'shortLength', trapezoidRef.current);
30
+ useLayoutEffect(function () {
31
+ parent.appendChild(trapezoidRef.current);
32
+ return function () {
33
+ // trapezoidRef.current.remove();
34
+ };
35
+ }, []);
36
+ return null;
37
+ };
38
+ export default Trapezoid;
@@ -0,0 +1,7 @@
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 };
@@ -0,0 +1,7 @@
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 };
@@ -0,0 +1,13 @@
1
+ import { Stage } from '../stage';
2
+ export declare function mountStage(children: any[], stage: Stage): void;
3
+ export declare function drawStageShapes(stage: Stage): void;
4
+ export declare const setCanvasStyle: (canvasElement: HTMLCanvasElement, width: number, height: number) => void;
5
+ export declare const updateCanvas: (canvasElement: HTMLCanvasElement, width: number, height: number) => CanvasRenderingContext2D | null;
6
+ export declare const createCanvas: (width: number, height: number) => {
7
+ canvasElement: HTMLCanvasElement;
8
+ ctx: CanvasRenderingContext2D | null;
9
+ };
10
+ export declare const initStage: (canvasContainer: HTMLElement) => {
11
+ canvasElement: HTMLCanvasElement;
12
+ ctx: CanvasRenderingContext2D | null;
13
+ };
@@ -0,0 +1,66 @@
1
+ import { drawShapes } from "../../utils/renderShape";
2
+ import { dpr } from "../../constant";
3
+ // import { IShape } from '../../type';
4
+
5
+ // 添加子元素 绘制 画布
6
+ export function mountStage(children, stage) {
7
+ children.forEach(function (item) {
8
+ item.stage = stage;
9
+ if (item.children) {
10
+ mountStage(item.children, stage);
11
+ }
12
+ });
13
+ }
14
+
15
+ // 绘制前置工作
16
+ export function drawStageShapes(stage) {
17
+ var _stage$canvasElement, _stage$canvasElement2;
18
+ var ctx = stage.ctx;
19
+ // 先清空画布
20
+ ctx.clearRect(0, 0, (_stage$canvasElement = stage.canvasElement) === null || _stage$canvasElement === void 0 ? void 0 : _stage$canvasElement.width, (_stage$canvasElement2 = stage.canvasElement) === null || _stage$canvasElement2 === void 0 ? void 0 : _stage$canvasElement2.height);
21
+ // 开始绘制
22
+ drawShapes(ctx, stage.children);
23
+ }
24
+ // 更新canvas的style
25
+ export var setCanvasStyle = function setCanvasStyle(canvasElement, width, height) {
26
+ var canvasWidth = width * dpr;
27
+ var canvasHeight = height * dpr;
28
+ canvasElement.width = canvasWidth;
29
+ canvasElement.height = canvasHeight;
30
+ canvasElement.style.width = '100%';
31
+ canvasElement.style.height = '100%';
32
+ };
33
+ // 更新canvas的属性
34
+ export var updateCanvas = function updateCanvas(canvasElement, width, height) {
35
+ setCanvasStyle(canvasElement, width, height);
36
+ var ctx = canvasElement.getContext('2d');
37
+ if (!ctx) return null;
38
+ ctx.scale(dpr, dpr);
39
+ ctx.textBaseline = 'top';
40
+ ctx.font = "".concat(14, "px \u5FAE\u8F6F\u96C5\u9ED1");
41
+ return ctx;
42
+ };
43
+
44
+ // 创建canvas元素
45
+ export var createCanvas = function createCanvas(width, height) {
46
+ var canvasElement = document.createElement('canvas');
47
+ var ctx = updateCanvas(canvasElement, width, height);
48
+ return {
49
+ canvasElement: canvasElement,
50
+ ctx: ctx
51
+ };
52
+ };
53
+
54
+ // 初始化画布 将canvas添加到容器中
55
+ export var initStage = function initStage(canvasContainer) {
56
+ var offsetWidth = canvasContainer.offsetWidth,
57
+ offsetHeight = canvasContainer.offsetHeight;
58
+ var _createCanvas = createCanvas(offsetWidth, offsetHeight),
59
+ canvasElement = _createCanvas.canvasElement,
60
+ ctx = _createCanvas.ctx;
61
+ canvasContainer.append(canvasElement);
62
+ return {
63
+ canvasElement: canvasElement,
64
+ ctx: ctx
65
+ };
66
+ };
@@ -0,0 +1,6 @@
1
+ export declare const tasks: {
2
+ cb: () => void;
3
+ }[];
4
+ export declare const workLoop: () => void;
5
+ export declare const schedulerTask: (cb: () => void) => void;
6
+ export declare const resetSchedulerCount: () => void;
@@ -0,0 +1,26 @@
1
+ // 任务批处理
2
+
3
+ export var tasks = []; // 马上立即执行
4
+ // @ts-ignore
5
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
+ var timer = [];
7
+ export var workLoop = function workLoop() {
8
+ var job;
9
+ while (job = tasks.shift()) {
10
+ job.cb();
11
+ }
12
+ };
13
+ var schedulerCount = true;
14
+ export var schedulerTask = function schedulerTask(cb) {
15
+ var task = {
16
+ cb: cb
17
+ };
18
+ tasks.push(task);
19
+ if (schedulerCount) {
20
+ window.queueMicrotask(workLoop);
21
+ }
22
+ schedulerCount = false;
23
+ };
24
+ export var resetSchedulerCount = function resetSchedulerCount() {
25
+ schedulerCount = true;
26
+ };
@@ -0,0 +1,17 @@
1
+ import { Shape, ShapeData } from './shape';
2
+ import { BoundingRect } from './stage';
3
+ interface CircleData extends ShapeData {
4
+ x?: number;
5
+ y?: number;
6
+ radius?: number;
7
+ innerRadius?: number;
8
+ startAngle?: number;
9
+ endAngle?: number;
10
+ offsetAngle?: number;
11
+ }
12
+ export declare class Circle extends Shape<CircleData> {
13
+ constructor(data: CircleData);
14
+ data: CircleData;
15
+ getBoundingRect(): BoundingRect;
16
+ }
17
+ export {};
@@ -0,0 +1,42 @@
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
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
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
8
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
9
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
10
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
11
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
12
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
13
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
14
+ import { Shape } from "./shape";
15
+ var defaultData = {
16
+ lineWidth: 1,
17
+ startAngle: 0,
18
+ endAngle: 360,
19
+ offsetAngle: 0
20
+ };
21
+ export var Circle = /*#__PURE__*/function (_Shape) {
22
+ _inherits(Circle, _Shape);
23
+ var _super = _createSuper(Circle);
24
+ function Circle(data) {
25
+ _classCallCheck(this, Circle);
26
+ return _super.call(this, 'Circle', data, defaultData);
27
+ }
28
+ _createClass(Circle, [{
29
+ key: "getBoundingRect",
30
+ value: function getBoundingRect() {
31
+ var data = this.data;
32
+ var padding = 0;
33
+ return {
34
+ x: ((data === null || data === void 0 ? void 0 : data.x) || 0) - ((data === null || data === void 0 ? void 0 : data.radius) || 0) - padding,
35
+ y: ((data === null || data === void 0 ? void 0 : data.y) || 0) - ((data === null || data === void 0 ? void 0 : data.radius) || 0) - padding,
36
+ width: 2 * ((data === null || data === void 0 ? void 0 : data.radius) || 0) + padding * 2,
37
+ height: 2 * ((data === null || data === void 0 ? void 0 : data.radius) || 0) + padding * 2
38
+ };
39
+ }
40
+ }]);
41
+ return Circle;
42
+ }(Shape);
@@ -0,0 +1,16 @@
1
+ import { Shape, ShapeData } from './shape';
2
+ export interface LineData extends ShapeData {
3
+ x?: number;
4
+ y?: number;
5
+ width?: number;
6
+ height?: number;
7
+ cornerRadius?: number;
8
+ }
9
+ export declare const defaultLineData: {
10
+ cornerRadius: number;
11
+ lineWidth: number;
12
+ };
13
+ export declare class Line extends Shape<LineData> {
14
+ constructor(data: LineData);
15
+ data: LineData;
16
+ }
@@ -0,0 +1,28 @@
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 _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
3
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
4
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
5
+ 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); }
6
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
7
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
8
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
9
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
10
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
11
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
12
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
13
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
14
+ import { Shape } from "./shape";
15
+ export var defaultLineData = {
16
+ cornerRadius: 0,
17
+ lineWidth: 1
18
+ };
19
+ // @
20
+ export var Line = /*#__PURE__*/function (_Shape) {
21
+ _inherits(Line, _Shape);
22
+ var _super = _createSuper(Line);
23
+ function Line(data) {
24
+ _classCallCheck(this, Line);
25
+ return _super.call(this, 'Line', data, defaultLineData); // this.path2D = data.path2D ? data.path2D : createLinePath2D(this.data)
26
+ }
27
+ return _createClass(Line);
28
+ }(Shape);