heitu 1.0.5 → 1.0.7

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 (97) hide show
  1. package/dist/canvas/core/constant.d.ts +2 -0
  2. package/dist/canvas/core/constant.js +2 -0
  3. package/dist/canvas/core/shapes/animate.d.ts +28 -0
  4. package/dist/canvas/core/shapes/animate.js +106 -0
  5. package/dist/canvas/core/shapes/circle.d.ts +48 -0
  6. package/dist/canvas/core/shapes/circle.js +162 -0
  7. package/dist/canvas/core/shapes/custom.d.ts +26 -0
  8. package/dist/canvas/core/shapes/custom.js +83 -0
  9. package/dist/canvas/core/shapes/line.d.ts +46 -0
  10. package/dist/canvas/core/shapes/line.js +146 -0
  11. package/dist/canvas/core/shapes/node.d.ts +44 -0
  12. package/dist/canvas/core/shapes/node.js +241 -0
  13. package/dist/canvas/core/shapes/rect.d.ts +27 -0
  14. package/dist/canvas/core/shapes/rect.js +86 -0
  15. package/dist/canvas/core/shapes/text.d.ts +43 -0
  16. package/dist/canvas/core/shapes/text.js +78 -0
  17. package/dist/canvas/core/stage/canvas.d.ts +15 -0
  18. package/dist/canvas/core/stage/canvas.js +82 -0
  19. package/dist/canvas/core/stage/container.d.ts +25 -0
  20. package/dist/canvas/core/stage/container.js +141 -0
  21. package/dist/canvas/core/stage/index.d.ts +50 -0
  22. package/dist/canvas/core/stage/index.js +285 -0
  23. package/dist/canvas/core/stage/utils.d.ts +2 -0
  24. package/dist/canvas/core/stage/utils.js +24 -0
  25. package/dist/canvas/core/type.d.ts +5 -0
  26. package/dist/canvas/index.d.ts +7 -6
  27. package/dist/canvas/index.js +7 -6
  28. package/dist/canvas/type.d.ts +0 -38
  29. package/dist/canvas/utils.d.ts +43 -0
  30. package/dist/canvas/utils.js +254 -0
  31. package/dist/hooks/index.d.ts +8 -1
  32. package/dist/hooks/index.js +9 -2
  33. package/dist/hooks/useAsyncFn/index.d.ts +23 -0
  34. package/dist/hooks/useAsyncFn/index.js +51 -0
  35. package/dist/hooks/useAsyncFn/interface.d.ts +2 -0
  36. package/dist/hooks/useAsyncFn/interface.js +1 -0
  37. package/dist/hooks/useCancelAsyncFn.d.ts +8 -0
  38. package/dist/hooks/useCancelAsyncFn.js +59 -0
  39. package/dist/hooks/useCustomCompareEffect/index.d.ts +2 -0
  40. package/dist/hooks/useCustomCompareEffect/index.js +16 -0
  41. package/dist/hooks/useCustomCompareEffect/interface.d.ts +21 -0
  42. package/dist/hooks/useCustomCompareEffect/interface.js +1 -0
  43. package/dist/hooks/useDeepCompareEffect/index.d.ts +3 -0
  44. package/dist/hooks/useDeepCompareEffect/index.js +11 -0
  45. package/dist/hooks/useDeepCompareEffect/interface.d.ts +15 -0
  46. package/dist/hooks/useDeepCompareEffect/interface.js +1 -0
  47. package/dist/hooks/useDevicePixelRatio/index.d.ts +3 -0
  48. package/dist/hooks/useDevicePixelRatio/index.js +35 -0
  49. package/dist/hooks/useDevicePixelRatio/interface.d.ts +14 -0
  50. package/dist/hooks/useDevicePixelRatio/interface.js +1 -0
  51. package/dist/hooks/useImageLoad/errImg.d.ts +1 -0
  52. package/dist/hooks/useImageLoad/errImg.js +1 -0
  53. package/dist/hooks/useImageLoad/index.d.ts +4 -0
  54. package/dist/hooks/useImageLoad/index.js +72 -0
  55. package/dist/hooks/useLocalStorage/index.d.ts +10 -0
  56. package/dist/hooks/useLocalStorage/index.js +84 -0
  57. package/dist/hooks/useMountedState.d.ts +1 -0
  58. package/dist/hooks/useMountedState.js +14 -0
  59. package/dist/hooks/useSessionStorage/index.d.ts +2 -0
  60. package/dist/hooks/useSessionStorage/index.js +41 -0
  61. package/dist/index.js +2 -1
  62. package/dist/type.d.ts +6 -0
  63. package/dist/utils/defaults.d.ts +1 -0
  64. package/dist/utils/defaults.js +4 -1
  65. package/package.json +2 -2
  66. package/dist/canvas/constant/index.js +0 -21
  67. package/dist/canvas/element/circle.d.ts +0 -15
  68. package/dist/canvas/element/circle.js +0 -31
  69. package/dist/canvas/element/line.d.ts +0 -14
  70. package/dist/canvas/element/line.js +0 -32
  71. package/dist/canvas/element/rect.d.ts +0 -14
  72. package/dist/canvas/element/rect.js +0 -32
  73. package/dist/canvas/element/stage/index.d.ts +0 -11
  74. package/dist/canvas/element/stage/index.js +0 -8
  75. package/dist/canvas/element/stage/stage.d.ts +0 -4
  76. package/dist/canvas/element/stage/stage.js +0 -28
  77. package/dist/canvas/element/text.d.ts +0 -11
  78. package/dist/canvas/element/text.js +0 -25
  79. package/dist/canvas/store/index.d.ts +0 -21
  80. package/dist/canvas/store/index.js +0 -66
  81. package/dist/canvas/utils/constant.d.ts +0 -1
  82. package/dist/canvas/utils/constant.js +0 -1
  83. package/dist/canvas/utils/drawShape/circle.d.ts +0 -7
  84. package/dist/canvas/utils/drawShape/circle.js +0 -80
  85. package/dist/canvas/utils/drawShape/index.d.ts +0 -2
  86. package/dist/canvas/utils/drawShape/index.js +0 -28
  87. package/dist/canvas/utils/drawShape/line.d.ts +0 -0
  88. package/dist/canvas/utils/drawShape/line.js +0 -0
  89. package/dist/canvas/utils/drawShape/rect.d.ts +0 -3
  90. package/dist/canvas/utils/drawShape/rect.js +0 -68
  91. package/dist/canvas/utils/drawShape/text.d.ts +0 -2
  92. package/dist/canvas/utils/drawShape/text.js +0 -20
  93. package/dist/canvas/utils/index.d.ts +0 -0
  94. package/dist/canvas/utils/stage.d.ts +0 -6
  95. package/dist/canvas/utils/stage.js +0 -29
  96. /package/dist/{canvas/constant → charts}/index.d.ts +0 -0
  97. /package/dist/{canvas/utils → charts}/index.js +0 -0
@@ -0,0 +1,2 @@
1
+ export declare const dpr: number;
2
+ export declare const Noop: () => void;
@@ -0,0 +1,2 @@
1
+ export var dpr = window.devicePixelRatio;
2
+ export var Noop = function Noop() {};
@@ -0,0 +1,28 @@
1
+ export type AnimateCartoonConfig = {
2
+ duration: number;
3
+ delay?: number;
4
+ during?: (percent: number, newState: Record<string, string | number>) => void;
5
+ done?: () => void;
6
+ aborted?: () => void;
7
+ scope?: string;
8
+ force?: boolean;
9
+ additive?: boolean;
10
+ setToFinal?: boolean;
11
+ easing?: any;
12
+ iterationCount?: number;
13
+ };
14
+ declare class Animate {
15
+ rafTimer: number | null;
16
+ startTime: number | null;
17
+ startProp: Record<string, any>;
18
+ targetProp: Record<string, any>;
19
+ cfg: AnimateCartoonConfig;
20
+ constructor(startProp?: Record<string, any>, targetProp?: Record<string, any>, cfg?: Partial<AnimateCartoonConfig>);
21
+ forward: boolean;
22
+ queue: any;
23
+ start(): void;
24
+ checkEdge(): void;
25
+ stop(): void;
26
+ pushQueue(callback: any): void;
27
+ }
28
+ export default Animate;
@@ -0,0 +1,106 @@
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
+ 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); } }
6
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
7
+ 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; }
8
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
9
+ 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); }
10
+ import { calcTargetValue, easingFuncs } from "../../utils";
11
+ var defaultCfg = {
12
+ duration: 1000,
13
+ easing: 'linear',
14
+ iterationCount: 1
15
+ };
16
+ var Animate = /*#__PURE__*/function () {
17
+ function Animate() {
18
+ var startProp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
19
+ var targetProp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
20
+ var cfg = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
21
+ _classCallCheck(this, Animate);
22
+ _defineProperty(this, "rafTimer", null);
23
+ _defineProperty(this, "startTime", null);
24
+ _defineProperty(this, "startProp", void 0);
25
+ _defineProperty(this, "targetProp", void 0);
26
+ _defineProperty(this, "cfg", void 0);
27
+ _defineProperty(this, "forward", true);
28
+ // 正向动画
29
+ _defineProperty(this, "queue", []);
30
+ this.startProp = startProp;
31
+ this.targetProp = targetProp;
32
+ this.cfg = _objectSpread(_objectSpread({}, defaultCfg), cfg);
33
+ }
34
+ _createClass(Animate, [{
35
+ key: "start",
36
+ value:
37
+ // 开始
38
+ function start() {
39
+ var _this = this;
40
+ var _this$cfg = this.cfg,
41
+ duration = _this$cfg.duration,
42
+ easing = _this$cfg.easing,
43
+ during = _this$cfg.during,
44
+ iterationCount = _this$cfg.iterationCount;
45
+ var keys = Object.keys(this.targetProp);
46
+ var rafCb = function rafCb(timestamp) {
47
+ if (!_this.startTime) {
48
+ _this.startTime = timestamp;
49
+ }
50
+ var elapsedTimeRatio = easingFuncs[easing](Math.min((timestamp - _this.startTime) / duration, 1));
51
+ if (_this.forward === false) {
52
+ elapsedTimeRatio = 1 - elapsedTimeRatio;
53
+ }
54
+ var currentProp = {};
55
+ keys.forEach(function (propKey) {
56
+ var targetValue = calcTargetValue(_this.startProp[propKey], _this.targetProp[propKey], elapsedTimeRatio);
57
+ currentProp[propKey] = targetValue;
58
+ });
59
+ if (during) {
60
+ during(elapsedTimeRatio, currentProp);
61
+ }
62
+ var nextCondition = _this.forward ? elapsedTimeRatio < 1 : 0 < elapsedTimeRatio;
63
+ if (nextCondition) {
64
+ _this.rafTimer = requestAnimationFrame(rafCb);
65
+ } else {
66
+ _this.queue = [];
67
+ _this.stop();
68
+ }
69
+ if (_this.queue.length > 0) {
70
+ _this.queue.forEach(function (item) {
71
+ item(currentProp, elapsedTimeRatio);
72
+ });
73
+ }
74
+ var endCondition = _this.forward ? elapsedTimeRatio === 1 : elapsedTimeRatio === 0;
75
+ if (endCondition) {
76
+ if (iterationCount === Infinity) {
77
+ _this.forward = !_this.forward;
78
+ _this.startTime = null;
79
+ _this.start();
80
+ }
81
+ }
82
+ };
83
+ this.rafTimer = requestAnimationFrame(rafCb);
84
+ }
85
+ // 检查边缘
86
+ }, {
87
+ key: "checkEdge",
88
+ value: function checkEdge() {}
89
+ // 更新
90
+ // @ts-ignore
91
+ // onUpdate(currentProp, elapsedTimeRatio: number) {}
92
+ // 停止
93
+ }, {
94
+ key: "stop",
95
+ value: function stop() {
96
+ if (this.rafTimer) cancelAnimationFrame(this.rafTimer);
97
+ }
98
+ }, {
99
+ key: "pushQueue",
100
+ value: function pushQueue(callback) {
101
+ this.queue.push(callback);
102
+ }
103
+ }]);
104
+ return Animate;
105
+ }();
106
+ export default Animate;
@@ -0,0 +1,48 @@
1
+ import Node from './node';
2
+ export type ICoord = {
3
+ x: number;
4
+ y: number;
5
+ };
6
+ interface ICircle {
7
+ x?: number;
8
+ y?: number;
9
+ radius?: number;
10
+ lineWidth?: number;
11
+ fillStyle?: string;
12
+ strokeStyle?: string;
13
+ arc?: boolean;
14
+ startAngle?: number;
15
+ endAngle?: number;
16
+ innerRadius?: number;
17
+ border: 0 | 1 | 2;
18
+ index: number;
19
+ }
20
+ declare class Circle extends Node {
21
+ name: string;
22
+ parent: null;
23
+ x: number;
24
+ y: number;
25
+ radius: number;
26
+ lineWidth: number;
27
+ fillStyle: string;
28
+ strokeStyle: string;
29
+ arc: boolean;
30
+ startAngle: number;
31
+ endAngle: number;
32
+ innerRadius: number;
33
+ index: number;
34
+ path2D: Path2D | null;
35
+ border: 0 | 1 | 2;
36
+ constructor(config: ICircle);
37
+ deg2rad(deg: number): number;
38
+ getPointOnArc(x0: number, y0: number, r: number, deg: number): {
39
+ x: number;
40
+ y: number;
41
+ };
42
+ calcWholeRingD(): string;
43
+ calcRingSectorD(): string;
44
+ calcRingD(isWholeArc: boolean): string;
45
+ draw(ctx: CanvasRenderingContext2D): Path2D;
46
+ inScope(evt: MouseEvent, ctx: CanvasRenderingContext2D): boolean | undefined;
47
+ }
48
+ export default Circle;
@@ -0,0 +1,162 @@
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 _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); }
6
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
7
+ 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); }; }
8
+ 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); }
9
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
10
+ 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; } }
11
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
12
+ 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; }
13
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
14
+ 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); }
15
+ import { isInShape } from "../../utils";
16
+ import { forIn } from 'lodash-es';
17
+ import { dpr } from "../constant";
18
+ import Node from "./node";
19
+ var Circle = /*#__PURE__*/function (_Node) {
20
+ _inherits(Circle, _Node);
21
+ var _super = _createSuper(Circle);
22
+ // 0 填充 1 只有边框 2 边框和填充
23
+ function Circle(config) {
24
+ var _this;
25
+ _classCallCheck(this, Circle);
26
+ _this = _super.call(this);
27
+ _defineProperty(_assertThisInitialized(_this), "name", 'Circle');
28
+ _defineProperty(_assertThisInitialized(_this), "parent", null);
29
+ _defineProperty(_assertThisInitialized(_this), "x", void 0);
30
+ _defineProperty(_assertThisInitialized(_this), "y", void 0);
31
+ _defineProperty(_assertThisInitialized(_this), "radius", void 0);
32
+ _defineProperty(_assertThisInitialized(_this), "lineWidth", void 0);
33
+ _defineProperty(_assertThisInitialized(_this), "fillStyle", void 0);
34
+ _defineProperty(_assertThisInitialized(_this), "strokeStyle", void 0);
35
+ _defineProperty(_assertThisInitialized(_this), "arc", void 0);
36
+ _defineProperty(_assertThisInitialized(_this), "startAngle", void 0);
37
+ // 圆弧 饼图 角度 60 180 360
38
+ _defineProperty(_assertThisInitialized(_this), "endAngle", void 0);
39
+ // 圆弧 饼图
40
+ _defineProperty(_assertThisInitialized(_this), "innerRadius", void 0);
41
+ _defineProperty(_assertThisInitialized(_this), "index", void 0);
42
+ _defineProperty(_assertThisInitialized(_this), "path2D", void 0);
43
+ _defineProperty(_assertThisInitialized(_this), "border", void 0);
44
+ _this.x = 10;
45
+ _this.y = 10;
46
+ _this.radius = 8;
47
+ _this.fillStyle = '';
48
+ _this.strokeStyle = '';
49
+ _this.lineWidth = 1;
50
+ _this.startAngle = 0;
51
+ _this.endAngle = 360;
52
+ _this.border = 0;
53
+ _this.innerRadius = 0;
54
+ _this.arc = false;
55
+ _this.index = 0;
56
+ _this.path2D = null;
57
+ forIn(config, function (value, key) {
58
+ if (value) _assertThisInitialized(_this)[key] = value;
59
+ });
60
+ return _this;
61
+ }
62
+ // 角度转弧度
63
+ _createClass(Circle, [{
64
+ key: "deg2rad",
65
+ value: function deg2rad(deg) {
66
+ return deg * Math.PI / 180;
67
+ }
68
+ }, {
69
+ key: "getPointOnArc",
70
+ value: function getPointOnArc(x0, y0, r, deg) {
71
+ var alpha = this.deg2rad(deg);
72
+ var x = x0 + r * Math.cos(alpha); // Math.cos 传入弧度
73
+ var y = y0 + r * Math.sin(alpha);
74
+ return {
75
+ x: x,
76
+ y: y
77
+ };
78
+ }
79
+ }, {
80
+ key: "calcWholeRingD",
81
+ value: function calcWholeRingD() {
82
+ var outerM_y = this.y - this.radius;
83
+ var outerM = "M ".concat(this.x, " ").concat(outerM_y);
84
+ var outerA = "A ".concat(this.radius, " ").concat(this.radius, " 0 1 1 ").concat(this.x - 0.01, " ").concat(outerM_y);
85
+ var innerM_y = this.y - this.innerRadius;
86
+ var innerM = "M ".concat(this.x, " ").concat(innerM_y);
87
+ var innerA = "A ".concat(this.innerRadius, " ").concat(this.innerRadius, " 0 1 0 ").concat(this.x + 0.01, " ").concat(innerM_y);
88
+ return "".concat(outerM, " ").concat(outerA, " ").concat(innerM, " ").concat(innerA, " Z");
89
+ }
90
+ }, {
91
+ key: "calcRingSectorD",
92
+ value: function calcRingSectorD() {
93
+ var outerStart = this.getPointOnArc(this.x, this.y, this.radius, this.startAngle);
94
+ var outerEnd = this.getPointOnArc(this.x, this.y, this.radius, this.endAngle);
95
+ var largeArcFlag = this.endAngle - this.startAngle >= 180 ? 1 : 0;
96
+ var outerM = "M ".concat(outerStart.x, " ").concat(outerStart.y);
97
+ var outerA = "A ".concat(this.radius, " ").concat(this.radius, " 0 ").concat(largeArcFlag, " 1 ").concat(outerEnd.x, " ").concat(outerEnd.y);
98
+ var innerStart = this.getPointOnArc(this.x, this.y, this.innerRadius, this.startAngle);
99
+ var innerEnd = this.getPointOnArc(this.x, this.y, this.innerRadius, this.endAngle);
100
+ var moveL = "L".concat(innerEnd.x, " ").concat(innerEnd.y);
101
+ var innerA = "A ".concat(this.innerRadius, " ").concat(this.innerRadius, " 0 ").concat(largeArcFlag, " 0 ").concat(innerStart.x, " ").concat(innerStart.y);
102
+ return "".concat(outerM, " ").concat(outerA, " ").concat(moveL, " ").concat(innerA, " Z");
103
+ }
104
+ }, {
105
+ key: "calcRingD",
106
+ value: function calcRingD(isWholeArc) {
107
+ return isWholeArc ? this.calcWholeRingD() : this.calcRingSectorD();
108
+ }
109
+ }, {
110
+ key: "draw",
111
+ value: function draw(ctx) {
112
+ var isWholeArc = this.startAngle === 0 && this.endAngle === 360; // 是否是整圆
113
+ var circlePath;
114
+ switch (this.border) {
115
+ case 0:
116
+ circlePath = new Path2D(this.calcRingD(isWholeArc));
117
+ // 设置绘制样式
118
+ if (this.fillStyle) ctx.fillStyle = this.fillStyle; // 填充颜色
119
+ if (this.fillStyle) ctx.strokeStyle = this.fillStyle; // 描边颜色
120
+ if (this.lineWidth) ctx.lineWidth = this.lineWidth; // 描边宽度
121
+ ctx.stroke(circlePath);
122
+ ctx.fill(circlePath);
123
+ this.path2D = circlePath;
124
+ return circlePath;
125
+ case 1:
126
+ circlePath = new Path2D(this.calcRingD(isWholeArc));
127
+ ctx.lineWidth = this.lineWidth;
128
+ if (this.strokeStyle) ctx.strokeStyle = this.strokeStyle; // 描边颜色
129
+ ctx.stroke(circlePath);
130
+ this.path2D = circlePath;
131
+ return circlePath;
132
+ case 2:
133
+ circlePath = new Path2D(this.calcRingD(isWholeArc));
134
+ // 设置绘制样式
135
+ if (this.fillStyle) ctx.fillStyle = this.fillStyle; // 填充颜色
136
+ if (this.strokeStyle) ctx.strokeStyle = this.strokeStyle; // 描边颜色
137
+ if (this.lineWidth) ctx.lineWidth = this.lineWidth; // 描边宽度
138
+ ctx.stroke(circlePath);
139
+ ctx.fill(circlePath);
140
+ this.path2D = circlePath;
141
+ return circlePath;
142
+ }
143
+ }
144
+ }, {
145
+ key: "inScope",
146
+ value: function inScope(evt, ctx) {
147
+ var mouseX = evt.offsetX * dpr;
148
+ var mouseY = evt.offsetY * dpr;
149
+ if (this !== null && this !== void 0 && this.path2D) {
150
+ return isInShape({
151
+ mouseX: mouseX,
152
+ mouseY: mouseY,
153
+ path2D: this === null || this === void 0 ? void 0 : this.path2D,
154
+ ctx: ctx || undefined
155
+ });
156
+ }
157
+ return false;
158
+ }
159
+ }]);
160
+ return Circle;
161
+ }(Node);
162
+ export default Circle;
@@ -0,0 +1,26 @@
1
+ import Node from './node';
2
+ interface ICustom {
3
+ x?: number;
4
+ y?: number;
5
+ path2D: Path2D | null;
6
+ fillStyle?: string;
7
+ strokeStyle?: string;
8
+ lineWidth?: number;
9
+ }
10
+ declare class Custom extends Node {
11
+ name: string;
12
+ x: number;
13
+ y: number;
14
+ width: number;
15
+ height: number;
16
+ fillStyle: string | null;
17
+ strokeStyle: string | null;
18
+ lineWidth: number | null;
19
+ index: number;
20
+ path2D: Path2D | null;
21
+ parent: null;
22
+ constructor(config: ICustom);
23
+ draw(ctx: CanvasRenderingContext2D): this | undefined;
24
+ inScope(evt: MouseEvent, ctx: CanvasRenderingContext2D): boolean | undefined;
25
+ }
26
+ export default Custom;
@@ -0,0 +1,83 @@
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 _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); }
6
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
7
+ 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); }; }
8
+ 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); }
9
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
10
+ 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; } }
11
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
12
+ 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; }
13
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
14
+ 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); }
15
+ import { isInShape } from "../../utils";
16
+ import { forIn } from 'lodash-es';
17
+ import { dpr } from "../constant";
18
+ import Node from "./node";
19
+ var Custom = /*#__PURE__*/function (_Node) {
20
+ _inherits(Custom, _Node);
21
+ var _super = _createSuper(Custom);
22
+ function Custom(config) {
23
+ var _this;
24
+ _classCallCheck(this, Custom);
25
+ _this = _super.call(this);
26
+ _defineProperty(_assertThisInitialized(_this), "name", 'Custom');
27
+ _defineProperty(_assertThisInitialized(_this), "x", void 0);
28
+ _defineProperty(_assertThisInitialized(_this), "y", void 0);
29
+ _defineProperty(_assertThisInitialized(_this), "width", void 0);
30
+ _defineProperty(_assertThisInitialized(_this), "height", void 0);
31
+ _defineProperty(_assertThisInitialized(_this), "fillStyle", void 0);
32
+ _defineProperty(_assertThisInitialized(_this), "strokeStyle", void 0);
33
+ _defineProperty(_assertThisInitialized(_this), "lineWidth", void 0);
34
+ _defineProperty(_assertThisInitialized(_this), "index", void 0);
35
+ _defineProperty(_assertThisInitialized(_this), "path2D", void 0);
36
+ _defineProperty(_assertThisInitialized(_this), "parent", null);
37
+ if (!config.path2D) {
38
+ throw new Error('Mast has key of path2D');
39
+ }
40
+ _this.x = 100;
41
+ _this.y = 100;
42
+ _this.width = 0;
43
+ _this.height = 0;
44
+ _this.fillStyle = null;
45
+ _this.strokeStyle = null;
46
+ _this.lineWidth = 1;
47
+ _this.path2D = null;
48
+ _this.index = 0;
49
+ forIn(config, function (value, key) {
50
+ if (value) _assertThisInitialized(_this)[key] = value;
51
+ });
52
+ return _this;
53
+ }
54
+ _createClass(Custom, [{
55
+ key: "draw",
56
+ value: function draw(ctx) {
57
+ if (!this.path2D) return;
58
+ if (this.fillStyle) ctx.fillStyle = this.fillStyle;
59
+ if (this.strokeStyle) ctx.strokeStyle = this.strokeStyle;
60
+ if (this.lineWidth) ctx.lineWidth = this.lineWidth;
61
+ if (this.lineWidth) ctx.stroke(this.path2D);
62
+ if (this.fillStyle) ctx.fill(this.path2D);
63
+ return this;
64
+ }
65
+ }, {
66
+ key: "inScope",
67
+ value: function inScope(evt, ctx) {
68
+ var mouseX = evt.offsetX * dpr;
69
+ var mouseY = evt.offsetY * dpr;
70
+ if (this !== null && this !== void 0 && this.path2D) {
71
+ return isInShape({
72
+ mouseX: mouseX,
73
+ mouseY: mouseY,
74
+ path2D: this === null || this === void 0 ? void 0 : this.path2D,
75
+ ctx: ctx || undefined
76
+ });
77
+ }
78
+ return false;
79
+ }
80
+ }]);
81
+ return Custom;
82
+ }(Node);
83
+ export default Custom;
@@ -0,0 +1,46 @@
1
+ import { Vector2d } from '../type';
2
+ import Node from './node';
3
+ interface ILine {
4
+ start?: {
5
+ x: number;
6
+ y: number;
7
+ };
8
+ end?: {
9
+ x: number;
10
+ y: number;
11
+ };
12
+ points?: number[];
13
+ smooth?: boolean;
14
+ strokeStyle: string;
15
+ lineWidth: number;
16
+ lineCap: 'butt' | 'round' | 'square';
17
+ lineJoin: 'miter' | 'round' | 'miter';
18
+ index: number;
19
+ }
20
+ declare class Line extends Node {
21
+ name: string;
22
+ start: {
23
+ x: number;
24
+ y: number;
25
+ };
26
+ end: {
27
+ x: number;
28
+ y: number;
29
+ };
30
+ points: number[];
31
+ smooth: boolean;
32
+ strokeStyle: string;
33
+ lineWidth: number;
34
+ lineCap: 'butt' | 'round' | 'square';
35
+ lineJoin: 'miter' | 'round' | 'miter';
36
+ index: number;
37
+ path2D: Path2D | null;
38
+ parent: null;
39
+ constructor(config: ILine);
40
+ convertToNormalPoints(points: number[]): Vector2d[];
41
+ calcSmoothPath2D(): Path2D;
42
+ calcStraightPath2D(): Path2D;
43
+ draw(ctx: CanvasRenderingContext2D): this;
44
+ inScope(evt: MouseEvent, ctx: CanvasRenderingContext2D): boolean | undefined;
45
+ }
46
+ export default Line;