heitu 1.0.6 → 1.0.8

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 (64) hide show
  1. package/dist/canvas/core/shapes/animate.d.ts +10 -2
  2. package/dist/canvas/core/shapes/animate.js +75 -2
  3. package/dist/canvas/core/shapes/circle.d.ts +4 -0
  4. package/dist/canvas/core/shapes/circle.js +16 -2
  5. package/dist/canvas/core/shapes/custom.d.ts +4 -0
  6. package/dist/canvas/core/shapes/custom.js +14 -0
  7. package/dist/canvas/core/shapes/group.d.ts +12 -0
  8. package/dist/canvas/core/shapes/group.js +65 -0
  9. package/dist/canvas/core/shapes/line.d.ts +11 -5
  10. package/dist/canvas/core/shapes/line.js +20 -0
  11. package/dist/canvas/core/shapes/node.d.ts +1 -6
  12. package/dist/canvas/core/shapes/node.js +86 -34
  13. package/dist/canvas/core/shapes/rect.d.ts +7 -1
  14. package/dist/canvas/core/shapes/rect.js +32 -5
  15. package/dist/canvas/core/shapes/text.d.ts +4 -0
  16. package/dist/canvas/core/shapes/text.js +14 -0
  17. package/dist/canvas/core/stage/container.d.ts +1 -1
  18. package/dist/canvas/core/stage/index.d.ts +3 -3
  19. package/dist/canvas/core/stage/index.js +2 -0
  20. package/dist/canvas/index.d.ts +6 -4
  21. package/dist/canvas/index.js +6 -4
  22. package/dist/canvas/utils.d.ts +34 -0
  23. package/dist/canvas/utils.js +222 -0
  24. package/dist/hooks/index.d.ts +11 -2
  25. package/dist/hooks/index.js +12 -3
  26. package/dist/hooks/useAsyncFn/index.d.ts +23 -0
  27. package/dist/hooks/useAsyncFn/index.js +51 -0
  28. package/dist/hooks/useAsyncFn/interface.d.ts +2 -0
  29. package/dist/hooks/useAsyncFn/interface.js +1 -0
  30. package/dist/hooks/useCancelAsyncFn.d.ts +8 -0
  31. package/dist/hooks/useCancelAsyncFn.js +58 -0
  32. package/dist/hooks/useContainer/index.d.ts +13 -0
  33. package/dist/hooks/useContainer/index.js +62 -0
  34. package/dist/hooks/useCustomCompareEffect/index.d.ts +2 -0
  35. package/dist/hooks/useCustomCompareEffect/index.js +16 -0
  36. package/dist/hooks/useCustomCompareEffect/interface.d.ts +21 -0
  37. package/dist/hooks/useCustomCompareEffect/interface.js +1 -0
  38. package/dist/hooks/useDeepCompareEffect/index.d.ts +3 -0
  39. package/dist/hooks/useDeepCompareEffect/index.js +11 -0
  40. package/dist/hooks/useDeepCompareEffect/interface.d.ts +15 -0
  41. package/dist/hooks/useDeepCompareEffect/interface.js +1 -0
  42. package/dist/hooks/useDevicePixelRatio/index.d.ts +3 -0
  43. package/dist/hooks/useDevicePixelRatio/index.js +35 -0
  44. package/dist/hooks/useDevicePixelRatio/interface.d.ts +14 -0
  45. package/dist/hooks/useDevicePixelRatio/interface.js +1 -0
  46. package/dist/hooks/useImageLoad/index.d.ts +1 -1
  47. package/dist/hooks/useImageLoad/index.js +29 -15
  48. package/dist/hooks/useLocalStorage/index.d.ts +10 -0
  49. package/dist/hooks/useLocalStorage/index.js +84 -0
  50. package/dist/hooks/useMountedState.d.ts +1 -0
  51. package/dist/hooks/useMountedState.js +14 -0
  52. package/dist/hooks/usePolling/index.d.ts +21 -0
  53. package/dist/hooks/usePolling/index.js +136 -0
  54. package/dist/hooks/useSessionStorage/index.d.ts +2 -0
  55. package/dist/hooks/useSessionStorage/index.js +41 -0
  56. package/dist/hooks/useWebSocket/index.d.ts +20 -0
  57. package/dist/hooks/useWebSocket/index.js +105 -0
  58. package/dist/index.js +1 -2
  59. package/dist/type.d.ts +6 -0
  60. package/dist/utils/defaults.d.ts +1 -0
  61. package/dist/utils/defaults.js +4 -1
  62. package/package.json +4 -3
  63. package/dist/charts/index.d.ts +0 -0
  64. package/dist/charts/index.js +0 -0
@@ -1,5 +1,5 @@
1
1
  export type AnimateCartoonConfig = {
2
- duration?: number;
2
+ duration: number;
3
3
  delay?: number;
4
4
  during?: (percent: number, newState: Record<string, string | number>) => void;
5
5
  done?: () => void;
@@ -11,10 +11,18 @@ export type AnimateCartoonConfig = {
11
11
  easing?: any;
12
12
  iterationCount?: number;
13
13
  };
14
- declare abstract class Animate {
14
+ declare class Animate {
15
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;
16
23
  start(): void;
17
24
  checkEdge(): void;
18
25
  stop(): void;
26
+ pushQueue(callback: any): void;
19
27
  }
20
28
  export default Animate;
@@ -1,31 +1,104 @@
1
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; }
2
4
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
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); } }
4
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; }
5
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; }
6
8
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
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
+ };
8
16
  var Animate = /*#__PURE__*/function () {
9
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] : {};
10
21
  _classCallCheck(this, Animate);
11
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);
12
33
  }
13
34
  _createClass(Animate, [{
14
35
  key: "start",
15
36
  value:
16
37
  // 开始
17
- function start() {}
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
+ }
18
85
  // 检查边缘
19
86
  }, {
20
87
  key: "checkEdge",
21
88
  value: function checkEdge() {}
22
89
  // 更新
90
+ // @ts-ignore
23
91
  // onUpdate(currentProp, elapsedTimeRatio: number) {}
24
92
  // 停止
25
93
  }, {
26
94
  key: "stop",
27
95
  value: function stop() {
28
- // cancelAnimationFrame(this.rafTimer);
96
+ if (this.rafTimer) cancelAnimationFrame(this.rafTimer);
97
+ }
98
+ }, {
99
+ key: "pushQueue",
100
+ value: function pushQueue(callback) {
101
+ this.queue.push(callback);
29
102
  }
30
103
  }]);
31
104
  return Animate;
@@ -33,6 +33,10 @@ declare class Circle extends Node {
33
33
  index: number;
34
34
  path2D: Path2D | null;
35
35
  border: 0 | 1 | 2;
36
+ shadowColor: string;
37
+ shadowBlur: number;
38
+ shadowOffsetY: number;
39
+ shadowOffsetX: number;
36
40
  constructor(config: ICircle);
37
41
  deg2rad(deg: number): number;
38
42
  getPointOnArc(x0: number, y0: number, r: number, deg: number): {
@@ -19,7 +19,6 @@ import Node from "./node";
19
19
  var Circle = /*#__PURE__*/function (_Node) {
20
20
  _inherits(Circle, _Node);
21
21
  var _super = _createSuper(Circle);
22
- // 0 填充 1 只有边框 2 边框和填充
23
22
  function Circle(config) {
24
23
  var _this;
25
24
  _classCallCheck(this, Circle);
@@ -41,6 +40,11 @@ var Circle = /*#__PURE__*/function (_Node) {
41
40
  _defineProperty(_assertThisInitialized(_this), "index", void 0);
42
41
  _defineProperty(_assertThisInitialized(_this), "path2D", void 0);
43
42
  _defineProperty(_assertThisInitialized(_this), "border", void 0);
43
+ // 0 填充 1 只有边框 2 边框和填充
44
+ _defineProperty(_assertThisInitialized(_this), "shadowColor", void 0);
45
+ _defineProperty(_assertThisInitialized(_this), "shadowBlur", 0);
46
+ _defineProperty(_assertThisInitialized(_this), "shadowOffsetY", 0);
47
+ _defineProperty(_assertThisInitialized(_this), "shadowOffsetX", 0);
44
48
  _this.x = 10;
45
49
  _this.y = 10;
46
50
  _this.radius = 8;
@@ -54,6 +58,7 @@ var Circle = /*#__PURE__*/function (_Node) {
54
58
  _this.arc = false;
55
59
  _this.index = 0;
56
60
  _this.path2D = null;
61
+ _this.shadowColor = 'transparent';
57
62
  forIn(config, function (value, key) {
58
63
  if (value) _assertThisInitialized(_this)[key] = value;
59
64
  });
@@ -79,7 +84,7 @@ var Circle = /*#__PURE__*/function (_Node) {
79
84
  }, {
80
85
  key: "calcWholeRingD",
81
86
  value: function calcWholeRingD() {
82
- var outerM_y = this.x - this.radius;
87
+ var outerM_y = this.y - this.radius;
83
88
  var outerM = "M ".concat(this.x, " ").concat(outerM_y);
84
89
  var outerA = "A ".concat(this.radius, " ").concat(this.radius, " 0 1 1 ").concat(this.x - 0.01, " ").concat(outerM_y);
85
90
  var innerM_y = this.y - this.innerRadius;
@@ -111,6 +116,15 @@ var Circle = /*#__PURE__*/function (_Node) {
111
116
  value: function draw(ctx) {
112
117
  var isWholeArc = this.startAngle === 0 && this.endAngle === 360; // 是否是整圆
113
118
  var circlePath;
119
+ if (this.shadowColor) {
120
+ // 设置阴影属性
121
+ ctx.shadowColor = this.shadowColor; // 阴影颜色
122
+ ctx.shadowBlur = this.shadowBlur; // 阴影模糊程度
123
+ ctx.shadowOffsetX = this.shadowOffsetX; // 阴影的水平偏移
124
+ ctx.shadowOffsetY = this.shadowOffsetY; // 阴影的垂直偏移
125
+ } else {
126
+ ctx.shadowColor = 'transparent'; // 取消阴影效果
127
+ }
114
128
  switch (this.border) {
115
129
  case 0:
116
130
  circlePath = new Path2D(this.calcRingD(isWholeArc));
@@ -19,6 +19,10 @@ declare class Custom extends Node {
19
19
  index: number;
20
20
  path2D: Path2D | null;
21
21
  parent: null;
22
+ shadowColor: string;
23
+ shadowBlur: number;
24
+ shadowOffsetY: number;
25
+ shadowOffsetX: number;
22
26
  constructor(config: ICustom);
23
27
  draw(ctx: CanvasRenderingContext2D): this | undefined;
24
28
  inScope(evt: MouseEvent, ctx: CanvasRenderingContext2D): boolean | undefined;
@@ -34,6 +34,10 @@ var Custom = /*#__PURE__*/function (_Node) {
34
34
  _defineProperty(_assertThisInitialized(_this), "index", void 0);
35
35
  _defineProperty(_assertThisInitialized(_this), "path2D", void 0);
36
36
  _defineProperty(_assertThisInitialized(_this), "parent", null);
37
+ _defineProperty(_assertThisInitialized(_this), "shadowColor", void 0);
38
+ _defineProperty(_assertThisInitialized(_this), "shadowBlur", 0);
39
+ _defineProperty(_assertThisInitialized(_this), "shadowOffsetY", 0);
40
+ _defineProperty(_assertThisInitialized(_this), "shadowOffsetX", 0);
37
41
  if (!config.path2D) {
38
42
  throw new Error('Mast has key of path2D');
39
43
  }
@@ -46,6 +50,7 @@ var Custom = /*#__PURE__*/function (_Node) {
46
50
  _this.lineWidth = 1;
47
51
  _this.path2D = null;
48
52
  _this.index = 0;
53
+ _this.shadowColor = 'transparent';
49
54
  forIn(config, function (value, key) {
50
55
  if (value) _assertThisInitialized(_this)[key] = value;
51
56
  });
@@ -60,6 +65,15 @@ var Custom = /*#__PURE__*/function (_Node) {
60
65
  if (this.lineWidth) ctx.lineWidth = this.lineWidth;
61
66
  if (this.lineWidth) ctx.stroke(this.path2D);
62
67
  if (this.fillStyle) ctx.fill(this.path2D);
68
+ if (this.shadowColor) {
69
+ // 设置阴影属性
70
+ ctx.shadowColor = this.shadowColor; // 阴影颜色
71
+ ctx.shadowBlur = this.shadowBlur; // 阴影模糊程度
72
+ ctx.shadowOffsetX = this.shadowOffsetX; // 阴影的水平偏移
73
+ ctx.shadowOffsetY = this.shadowOffsetY; // 阴影的垂直偏移
74
+ } else {
75
+ ctx.shadowColor = 'transparent'; // 取消阴影效果
76
+ }
63
77
  return this;
64
78
  }
65
79
  }, {
@@ -0,0 +1,12 @@
1
+ import Container from '../stage/container';
2
+ declare class Group extends Container {
3
+ parent: any;
4
+ name: string;
5
+ draggable: boolean;
6
+ constructor(config: {
7
+ draggable: boolean;
8
+ });
9
+ draw(ctx: CanvasRenderingContext2D): this | undefined;
10
+ inScope(evt: MouseEvent, ctx: CanvasRenderingContext2D): boolean;
11
+ }
12
+ export default Group;
@@ -0,0 +1,65 @@
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 { forIn } from 'lodash-es';
16
+ import Container from "../stage/container";
17
+ var Group = /*#__PURE__*/function (_Container) {
18
+ _inherits(Group, _Container);
19
+ var _super = _createSuper(Group);
20
+ function Group(config) {
21
+ var _this;
22
+ _classCallCheck(this, Group);
23
+ _this = _super.call(this);
24
+ _defineProperty(_assertThisInitialized(_this), "parent", void 0);
25
+ _defineProperty(_assertThisInitialized(_this), "name", 'Group');
26
+ _defineProperty(_assertThisInitialized(_this), "draggable", false);
27
+ _this.parent = null;
28
+ forIn(config, function (value, key) {
29
+ if (value) _assertThisInitialized(_this)[key] = value;
30
+ });
31
+ return _this;
32
+ }
33
+ _createClass(Group, [{
34
+ key: "draw",
35
+ value: function draw(ctx) {
36
+ if (!ctx) return;
37
+ // 排序
38
+ this.sortChildren(function (a, b) {
39
+ return a.index - b.index;
40
+ });
41
+ // 去重 (后面覆盖前面的)
42
+ this.deduplication();
43
+ // 绘制
44
+ this.getChildren().forEach(function (child) {
45
+ if (ctx && 'draw' in child && typeof child.draw === 'function') {
46
+ child.draw(ctx);
47
+ }
48
+ });
49
+ return this;
50
+ }
51
+ }, {
52
+ key: "inScope",
53
+ value: function inScope(evt, ctx) {
54
+ // 绘制
55
+ return this.getChildren().some(function (child) {
56
+ if ('inScope' in child && typeof child.inScope === 'function') {
57
+ return child.inScope(evt, ctx);
58
+ }
59
+ return false;
60
+ });
61
+ }
62
+ }]);
63
+ return Group;
64
+ }(Container);
65
+ export default Group;
@@ -11,11 +11,12 @@ interface ILine {
11
11
  };
12
12
  points?: number[];
13
13
  smooth?: boolean;
14
- strokeStyle: string;
15
- lineWidth: number;
16
- lineCap: 'butt' | 'round' | 'square';
17
- lineJoin: 'miter' | 'round' | 'miter';
18
- index: number;
14
+ strokeStyle?: string;
15
+ lineWidth?: number;
16
+ lineCap?: 'butt' | 'round' | 'square';
17
+ lineJoin?: 'miter' | 'round' | 'miter';
18
+ index?: number;
19
+ lineDash?: [number, number] | [];
19
20
  }
20
21
  declare class Line extends Node {
21
22
  name: string;
@@ -36,6 +37,11 @@ declare class Line extends Node {
36
37
  index: number;
37
38
  path2D: Path2D | null;
38
39
  parent: null;
40
+ shadowColor: string;
41
+ shadowBlur: number;
42
+ shadowOffsetY: number;
43
+ shadowOffsetX: number;
44
+ lineDash: [number, number] | [];
39
45
  constructor(config: ILine);
40
46
  convertToNormalPoints(points: number[]): Vector2d[];
41
47
  calcSmoothPath2D(): Path2D;
@@ -45,6 +45,11 @@ var Line = /*#__PURE__*/function (_Node) {
45
45
  _defineProperty(_assertThisInitialized(_this), "index", void 0);
46
46
  _defineProperty(_assertThisInitialized(_this), "path2D", void 0);
47
47
  _defineProperty(_assertThisInitialized(_this), "parent", null);
48
+ _defineProperty(_assertThisInitialized(_this), "shadowColor", void 0);
49
+ _defineProperty(_assertThisInitialized(_this), "shadowBlur", 0);
50
+ _defineProperty(_assertThisInitialized(_this), "shadowOffsetY", 0);
51
+ _defineProperty(_assertThisInitialized(_this), "shadowOffsetX", 0);
52
+ _defineProperty(_assertThisInitialized(_this), "lineDash", []);
48
53
  _this.start = {
49
54
  x: 10,
50
55
  y: 10
@@ -61,6 +66,7 @@ var Line = /*#__PURE__*/function (_Node) {
61
66
  _this.smooth = false;
62
67
  _this.index = 0;
63
68
  _this.path2D = null;
69
+ _this.shadowColor = 'transparent';
64
70
  forIn(config, function (value, key) {
65
71
  if (value) _assertThisInitialized(_this)[key] = value;
66
72
  });
@@ -122,6 +128,20 @@ var Line = /*#__PURE__*/function (_Node) {
122
128
  var path2D = this.smooth ? this.calcSmoothPath2D() : this.calcStraightPath2D();
123
129
  if (this.strokeStyle) ctx.strokeStyle = this.strokeStyle;
124
130
  if (this.lineWidth) ctx.lineWidth = this.lineWidth;
131
+ if (this.shadowColor) {
132
+ // 设置阴影属性
133
+ ctx.shadowColor = this.shadowColor; // 阴影颜色
134
+ ctx.shadowBlur = this.shadowBlur; // 阴影模糊程度
135
+ ctx.shadowOffsetX = this.shadowOffsetX; // 阴影的水平偏移
136
+ ctx.shadowOffsetY = this.shadowOffsetY; // 阴影的垂直偏移
137
+ } else {
138
+ ctx.shadowColor = 'transparent'; // 取消阴影效果
139
+ }
140
+ if (this.lineDash.length <= 0) {
141
+ ctx.setLineDash([]);
142
+ } else {
143
+ ctx.setLineDash(this.lineDash);
144
+ }
125
145
  ctx.stroke(path2D);
126
146
  return this;
127
147
  }
@@ -23,12 +23,6 @@ declare abstract class Node {
23
23
  handler: any;
24
24
  }>;
25
25
  };
26
- shapeEventListeners: {
27
- [index: string]: Array<{
28
- name: string;
29
- handler: any;
30
- }>;
31
- };
32
26
  abstract parent?: Stage | null;
33
27
  on<K extends keyof NodeEventMap>(evtStr: K, handler: EventListener<this, NodeEventMap[K]>): this;
34
28
  _off(type: string, name?: string, callback?: (params: any) => void): void;
@@ -39,5 +33,6 @@ declare abstract class Node {
39
33
  target: Stage;
40
34
  currentTarget: any;
41
35
  }): void;
36
+ attr(props: any): void;
42
37
  }
43
38
  export default Node;
@@ -12,11 +12,12 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
12
12
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
13
13
  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); }
14
14
  import { isStage } from "../../utils";
15
+ import { isFunction } from "../../../utils/is";
16
+ import { forIn, isEmpty } from 'lodash-es';
15
17
  var Node = /*#__PURE__*/function () {
16
18
  function Node() {
17
19
  _classCallCheck(this, Node);
18
20
  _defineProperty(this, "eventListeners", {});
19
- _defineProperty(this, "shapeEventListeners", {});
20
21
  }
21
22
  _createClass(Node, [{
22
23
  key: "on",
@@ -35,18 +36,19 @@ var Node = /*#__PURE__*/function () {
35
36
  this.eventListeners[baseEvent] = [];
36
37
  }
37
38
  this.eventListeners[baseEvent].push({
38
- name: handler.name || '',
39
+ name: (handler === null || handler === void 0 ? void 0 : handler.name) || '',
39
40
  handler: handler
40
41
  });
41
- if (this !== null && this !== void 0 && this.parent && isStage(this === null || this === void 0 ? void 0 : this.parent)) {
42
- if (!(this !== null && this !== void 0 && this.parent.shapeEventListeners[baseEvent])) {
43
- this.parent.shapeEventListeners[baseEvent] = [];
44
- }
45
- this.parent.shapeEventListeners[baseEvent].push({
46
- name: handler.name || '',
47
- handler: handler
48
- });
49
- }
42
+ // if (this?.parent && isStage(this?.parent)) {
43
+ // if (!this?.parent.shapeEventListeners[baseEvent]) {
44
+ // this.parent.shapeEventListeners[baseEvent] = [];
45
+ // }
46
+
47
+ // this.parent.shapeEventListeners[baseEvent].push({
48
+ // name: handler.name || '',
49
+ // handler: handler,
50
+ // });
51
+ // }
50
52
  }
51
53
  return this;
52
54
  }
@@ -107,9 +109,19 @@ var Node = /*#__PURE__*/function () {
107
109
  item.handler(evt);
108
110
  });
109
111
  } else {
110
- this.shapeEventListeners[eventType].forEach(function (item) {
111
- item.handler(evt);
112
- });
112
+ var _currentTarget$eventL;
113
+ if ((currentTarget === null || currentTarget === void 0 || (_currentTarget$eventL = currentTarget.eventListeners) === null || _currentTarget$eventL === void 0 || (_currentTarget$eventL = _currentTarget$eventL[eventType]) === null || _currentTarget$eventL === void 0 ? void 0 : _currentTarget$eventL.length) > 0) {
114
+ currentTarget.eventListeners[eventType].forEach(function (item) {
115
+ item.handler(evt, currentTarget);
116
+ });
117
+ }
118
+ if (currentTarget !== null && currentTarget !== void 0 && currentTarget.draggable) {
119
+ var _currentTarget$eventL2;
120
+ if (isFunction(currentTarget === null || currentTarget === void 0 ? void 0 : currentTarget.draggable) && currentTarget.dragging) currentTarget === null || currentTarget === void 0 || currentTarget.draggable(evt, currentTarget);
121
+ (_currentTarget$eventL2 = currentTarget.eventListeners) === null || _currentTarget$eventL2 === void 0 || (_currentTarget$eventL2 = _currentTarget$eventL2[eventType]) === null || _currentTarget$eventL2 === void 0 || _currentTarget$eventL2.forEach(function (item) {
122
+ item.handler(evt, currentTarget);
123
+ });
124
+ }
113
125
  }
114
126
  }
115
127
  }, {
@@ -126,11 +138,7 @@ var Node = /*#__PURE__*/function () {
126
138
  // 将时间推送到最顶层中
127
139
  var children = target === null || target === void 0 ? void 0 : target.children;
128
140
  for (var i = 0; i < children.length; i++) {
129
- if (!this.shapeEventListeners[eventType] || this.shapeEventListeners[eventType].length < 1) {
130
- this.shapeEventListeners[eventType] = [];
131
- }
132
- // @ts-ignore
133
- var dragShapes = _toConsumableArray(this.children.filter(function (item) {
141
+ var dragShapes = _toConsumableArray(children.filter(function (item) {
134
142
  return item.draggable;
135
143
  }));
136
144
  // 拖拽 按下
@@ -143,16 +151,34 @@ var Node = /*#__PURE__*/function () {
143
151
  return b.index - a.index;
144
152
  })[0];
145
153
  if (topInScopeDragShape) {
146
- topInScopeDragShape.dragging = true;
147
- topInScopeDragShape.offsetX = topInScopeDragShape !== null && topInScopeDragShape !== void 0 && topInScopeDragShape.x ? evt.offsetX - (topInScopeDragShape === null || topInScopeDragShape === void 0 ? void 0 : topInScopeDragShape.x) : evt.offsetX;
148
- topInScopeDragShape.offsetY = topInScopeDragShape !== null && topInScopeDragShape !== void 0 && topInScopeDragShape.y ? evt.offsetY - (topInScopeDragShape === null || topInScopeDragShape === void 0 ? void 0 : topInScopeDragShape.y) : evt.offsetY;
154
+ if (topInScopeDragShape.name === 'Group') {
155
+ topInScopeDragShape.dragging = true;
156
+ topInScopeDragShape.children.forEach(function (child) {
157
+ // child.dragging = true;
158
+ child.offsetX = child !== null && child !== void 0 && child.x ? evt.offsetX - (child === null || child === void 0 ? void 0 : child.x) : evt.offsetX;
159
+ // @ts-ignore
160
+ child.offsetY = child !== null && child !== void 0 && child.y ?
161
+ // @ts-ignore
162
+ evt.offsetY - (child === null || child === void 0 ? void 0 : child.y) : evt.offsetY;
163
+ });
164
+ } else {
165
+ topInScopeDragShape.dragging = true;
166
+ topInScopeDragShape.offsetX = topInScopeDragShape !== null && topInScopeDragShape !== void 0 && topInScopeDragShape.x ? evt.offsetX - (topInScopeDragShape === null || topInScopeDragShape === void 0 ? void 0 : topInScopeDragShape.x) : evt.offsetX;
167
+ // @ts-ignore
168
+ topInScopeDragShape.offsetY = topInScopeDragShape !== null && topInScopeDragShape !== void 0 && topInScopeDragShape.y ?
169
+ // @ts-ignore
170
+ evt.offsetY - (topInScopeDragShape === null || topInScopeDragShape === void 0 ? void 0 : topInScopeDragShape.y) : evt.offsetY;
171
+ }
149
172
  }
150
173
  }
151
- this.fire(eventType, {
152
- evt: evt,
153
- target: target,
154
- currentTarget: children[i]
155
- });
174
+ var currentChild = children[i];
175
+ if (!isEmpty(currentChild === null || currentChild === void 0 ? void 0 : currentChild.eventListeners) || currentChild !== null && currentChild !== void 0 && currentChild.draggable) {
176
+ this.fire(eventType, {
177
+ evt: evt,
178
+ target: target,
179
+ currentTarget: currentChild
180
+ });
181
+ }
156
182
  }
157
183
  } else {
158
184
  var _target$canvas2;
@@ -171,11 +197,26 @@ var Node = /*#__PURE__*/function () {
171
197
  var y = rect !== null && rect !== void 0 && rect.top ? evt.clientY - (rect === null || rect === void 0 ? void 0 : rect.top) : evt.clientY;
172
198
  currentTarget.x = currentTarget !== null && currentTarget !== void 0 && currentTarget.offsetX ? x - (currentTarget === null || currentTarget === void 0 ? void 0 : currentTarget.offsetX) : x;
173
199
  currentTarget.y = currentTarget !== null && currentTarget !== void 0 && currentTarget.offsetY ? y - (currentTarget === null || currentTarget === void 0 ? void 0 : currentTarget.offsetY) : y;
174
- } else {
200
+ } else if (currentTarget.name === 'Group') {
175
201
  var _x = rect !== null && rect !== void 0 && rect.left ? evt.clientX - (rect === null || rect === void 0 ? void 0 : rect.left) : evt.clientX;
176
202
  var _y = rect !== null && rect !== void 0 && rect.top ? evt.clientY - (rect === null || rect === void 0 ? void 0 : rect.top) : evt.clientY;
177
- currentTarget.x = currentTarget !== null && currentTarget !== void 0 && currentTarget.offsetX ? _x - (currentTarget === null || currentTarget === void 0 ? void 0 : currentTarget.offsetX) : _x;
178
- currentTarget.y = currentTarget !== null && currentTarget !== void 0 && currentTarget.offsetY ? _y - (currentTarget === null || currentTarget === void 0 ? void 0 : currentTarget.offsetY) : _y;
203
+ currentTarget.children.forEach(function (child) {
204
+ if (child.name === 'Text') {
205
+ // @ts-ignore
206
+ var _x2 = rect !== null && rect !== void 0 && rect.left ? evt.clientX - (rect === null || rect === void 0 ? void 0 : rect.left) : evt.clientX;
207
+ var _y2 = rect !== null && rect !== void 0 && rect.top ? evt.clientY - (rect === null || rect === void 0 ? void 0 : rect.top) : evt.clientY;
208
+ child.x = child !== null && child !== void 0 && child.offsetX ? _x2 - (child === null || child === void 0 ? void 0 : child.offsetX) : _x2;
209
+ child.y = child !== null && child !== void 0 && child.offsetY ? _y2 - (child === null || child === void 0 ? void 0 : child.offsetY) : _y2;
210
+ } else {
211
+ child.x = child !== null && child !== void 0 && child.offsetX ? _x - (child === null || child === void 0 ? void 0 : child.offsetX) : _x;
212
+ child.y = child !== null && child !== void 0 && child.offsetY ? _y - (child === null || child === void 0 ? void 0 : child.offsetY) : _y;
213
+ }
214
+ });
215
+ } else {
216
+ var _x3 = rect !== null && rect !== void 0 && rect.left ? evt.clientX - (rect === null || rect === void 0 ? void 0 : rect.left) : evt.clientX;
217
+ var _y3 = rect !== null && rect !== void 0 && rect.top ? evt.clientY - (rect === null || rect === void 0 ? void 0 : rect.top) : evt.clientY;
218
+ currentTarget.x = currentTarget !== null && currentTarget !== void 0 && currentTarget.offsetX ? _x3 - (currentTarget === null || currentTarget === void 0 ? void 0 : currentTarget.offsetX) : _x3;
219
+ currentTarget.y = currentTarget !== null && currentTarget !== void 0 && currentTarget.offsetY ? _y3 - (currentTarget === null || currentTarget === void 0 ? void 0 : currentTarget.offsetY) : _y3;
179
220
  }
180
221
 
181
222
  // @ts-ignore
@@ -185,21 +226,21 @@ var Node = /*#__PURE__*/function () {
185
226
  if (currentTarget !== null && currentTarget !== void 0 && currentTarget.inScope && (_target$canvas2 = target.canvas) !== null && _target$canvas2 !== void 0 && _target$canvas2.context) {
186
227
  var _target$canvas3;
187
228
  if (currentTarget !== null && currentTarget !== void 0 && currentTarget.inScope(evt, (_target$canvas3 = target.canvas) === null || _target$canvas3 === void 0 ? void 0 : _target$canvas3.context)) {
188
- var _target$shapeEventLis;
229
+ var _currentTarget$eventL3;
189
230
  if (eventType !== 'mouseenter' && eventType !== 'mouseleave' && eventType !== 'mouseout' && eventType !== 'mouseover') {
190
231
  this._fire(eventType, evt, currentTarget);
191
232
  }
192
233
  // 首先判断 stage 是否是 move 事件中 处理图形的 mouseenter mouseleave
193
- if (eventType === 'mousemove' && !currentTarget.mouseInScope && ((_target$shapeEventLis = target.shapeEventListeners.mouseenter) === null || _target$shapeEventLis === void 0 ? void 0 : _target$shapeEventLis.length) > 0) {
234
+ if (eventType === 'mousemove' && !currentTarget.mouseInScope && ((_currentTarget$eventL3 = currentTarget.eventListeners.mouseenter) === null || _currentTarget$eventL3 === void 0 ? void 0 : _currentTarget$eventL3.length) > 0) {
194
235
  currentTarget.mouseInScope = true;
195
236
  target._fire('mouseenter', evt, currentTarget);
196
237
  }
197
238
  } else {
198
239
  // 处理 除了移出 鼠标事件
199
240
  if (eventType === 'mousemove') {
200
- var _target$shapeEventLis2;
241
+ var _target$eventListener;
201
242
  currentTarget.mouseInScope = false;
202
- if (((_target$shapeEventLis2 = target.shapeEventListeners['mouseleave']) === null || _target$shapeEventLis2 === void 0 ? void 0 : _target$shapeEventLis2.length) > 0) {
243
+ if (((_target$eventListener = target.eventListeners['mouseleave']) === null || _target$eventListener === void 0 ? void 0 : _target$eventListener.length) > 0) {
203
244
  target._fire('mouseleave', evt, currentTarget);
204
245
  }
205
246
  }
@@ -207,6 +248,17 @@ var Node = /*#__PURE__*/function () {
207
248
  }
208
249
  }
209
250
  }
251
+ }, {
252
+ key: "attr",
253
+ value: function attr(props) {
254
+ var _this = this,
255
+ _this$parent;
256
+ if (!this.parent) return;
257
+ forIn(props, function (value, key) {
258
+ if (value) _this[key] = value;
259
+ });
260
+ (_this$parent = this.parent) === null || _this$parent === void 0 || _this$parent.batchDraw(this.parent);
261
+ }
210
262
  }]);
211
263
  return Node;
212
264
  }();
@@ -7,6 +7,7 @@ interface IRect {
7
7
  fillStyle?: string;
8
8
  strokeStyle?: string;
9
9
  lineWidth?: number;
10
+ shadowColor?: string;
10
11
  }
11
12
  declare class Rect extends Node {
12
13
  name: string;
@@ -20,8 +21,13 @@ declare class Rect extends Node {
20
21
  index: number;
21
22
  path2D: Path2D | null;
22
23
  parent: null;
24
+ shadowColor: string;
25
+ shadowBlur: number;
26
+ shadowOffsetY: number;
27
+ shadowOffsetX: number;
28
+ radius: number;
23
29
  constructor(config: IRect);
24
- draw(ctx: CanvasRenderingContext2D): this;
30
+ draw(ctx: CanvasRenderingContext2D): void;
25
31
  inScope(evt: MouseEvent, ctx: CanvasRenderingContext2D): boolean | undefined;
26
32
  }
27
33
  export default Rect;