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
@@ -0,0 +1,16 @@
1
+ import { Shape, ShapeData } from './shape';
2
+ export interface RectData extends ShapeData {
3
+ x?: number;
4
+ y?: number;
5
+ width?: number;
6
+ height?: number;
7
+ cornerRadius?: number;
8
+ }
9
+ export declare const defaultRectData: {
10
+ cornerRadius: number;
11
+ lineWidth: number;
12
+ };
13
+ export declare class Rect extends Shape<RectData> {
14
+ constructor(data: RectData);
15
+ data: RectData;
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 defaultRectData = {
16
+ cornerRadius: 0,
17
+ lineWidth: 1
18
+ };
19
+ // @
20
+ export var Rect = /*#__PURE__*/function (_Shape) {
21
+ _inherits(Rect, _Shape);
22
+ var _super = _createSuper(Rect);
23
+ function Rect(data) {
24
+ _classCallCheck(this, Rect);
25
+ return _super.call(this, 'Rect', data, defaultRectData);
26
+ }
27
+ return _createClass(Rect);
28
+ }(Shape);
@@ -0,0 +1,42 @@
1
+ import { ICursor, IShapeType } from '../type';
2
+ import { Stage } from './stage';
3
+ export interface ShapeData {
4
+ name?: string;
5
+ x?: number;
6
+ y?: number;
7
+ shadowColor?: string;
8
+ shadowBlur?: number;
9
+ shadowOffsetX?: number;
10
+ shadowOffsetY?: number;
11
+ lineWidth?: number;
12
+ opacity?: number;
13
+ zIndex?: number;
14
+ fillStyle?: CanvasFillStrokeStyles['fillStyle'];
15
+ strokeStyle?: CanvasFillStrokeStyles['strokeStyle'];
16
+ lineCap?: CanvasLineCap;
17
+ lineJoin?: CanvasLineJoin;
18
+ lineDash?: number[];
19
+ draggable?: boolean | 'horizontal' | 'vertical';
20
+ cursor?: ICursor;
21
+ pointerEvents?: 'none' | 'all';
22
+ transform?: number[];
23
+ scale?: {
24
+ x: number;
25
+ y: number;
26
+ };
27
+ translate?: {
28
+ x: number;
29
+ y: number;
30
+ };
31
+ extraData?: any;
32
+ }
33
+ export declare const defaultShapeData: ShapeData;
34
+ export declare abstract class Shape<T = object> {
35
+ type: IShapeType;
36
+ data: ShapeData;
37
+ path2D: Path2D;
38
+ stage: Stage;
39
+ constructor(type: IShapeType, shapeData: ShapeData, defaultShapeData?: ShapeData);
40
+ attr(...args: any): void;
41
+ remove(): void;
42
+ }
@@ -0,0 +1,70 @@
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
+ export var defaultShapeData = {
11
+ lineWidth: 1,
12
+ opacity: 1,
13
+ shadowBlur: 0,
14
+ shadowColor: 'orange',
15
+ shadowOffsetX: 0,
16
+ shadowOffsetY: 0,
17
+ lineCap: 'butt',
18
+ lineJoin: 'miter',
19
+ lineDash: [],
20
+ pointerEvents: 'all',
21
+ // transform: [1, 0, 0, 1, 0, 0],
22
+ zIndex: 0
23
+ };
24
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
25
+ export var Shape = /*#__PURE__*/function () {
26
+ // extraData;
27
+ function Shape(type, shapeData, defaultShapeData) {
28
+ _classCallCheck(this, Shape);
29
+ _defineProperty(this, "type", void 0);
30
+ // @ts-ignore
31
+ _defineProperty(this, "stage", void 0);
32
+ this.type = type;
33
+ this.data = _objectSpread(_objectSpread(_objectSpread({}, defaultShapeData), defaultShapeData), shapeData);
34
+ }
35
+ _createClass(Shape, [{
36
+ key: "attr",
37
+ value: function attr() {
38
+ if (this.stage) {
39
+ var _this$stage;
40
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
41
+ args[_key] = arguments[_key];
42
+ }
43
+ switch (args.length) {
44
+ case 1:
45
+ {
46
+ var data = args[0];
47
+ this.data = _objectSpread(_objectSpread({}, this.data), data);
48
+ break;
49
+ }
50
+ default:
51
+ console.log('未实现的参数数量');
52
+ break;
53
+ }
54
+ (_this$stage = this.stage) === null || _this$stage === void 0 || _this$stage.renderStage();
55
+ }
56
+ }
57
+ }, {
58
+ key: "remove",
59
+ value: function remove() {
60
+ // const parentChildren = this.parent.children as IShape[];
61
+ // const index = parentChildren.indexOf(this);
62
+ // if (index !== -1) {
63
+ // parentChildren.splice(index, 1);
64
+ // }
65
+
66
+ // this.stage.renderStage();
67
+ }
68
+ }]);
69
+ return Shape;
70
+ }();
@@ -0,0 +1,21 @@
1
+ export interface BoundingRect {
2
+ x: number;
3
+ y: number;
4
+ width: number;
5
+ height: number;
6
+ }
7
+ interface IOption {
8
+ container: HTMLElement;
9
+ }
10
+ export declare class Stage {
11
+ canvasElement: HTMLCanvasElement | null;
12
+ ctx: CanvasRenderingContext2D | null;
13
+ children: any[];
14
+ private isAsyncRenderTask;
15
+ constructor();
16
+ mount(option: IOption): void;
17
+ appendChild(...args: any[]): void;
18
+ renderStage(): void;
19
+ private addStageEventListener;
20
+ }
21
+ export {};
@@ -0,0 +1,88 @@
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 _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
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ 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); }
8
+ import { drawStageShapes, initStage, mountStage } from "./api/api";
9
+ import { resetSchedulerCount } from "./api/scheduler";
10
+ export var Stage = /*#__PURE__*/function () {
11
+ function Stage() {
12
+ _classCallCheck(this, Stage);
13
+ _defineProperty(this, "canvasElement", void 0);
14
+ _defineProperty(this, "ctx", void 0);
15
+ // todo Ts
16
+ _defineProperty(this, "children", []);
17
+ _defineProperty(this, "isAsyncRenderTask", false);
18
+ this.canvasElement = null;
19
+ this.ctx = null;
20
+ }
21
+ // 初始化 canvas
22
+ _createClass(Stage, [{
23
+ key: "mount",
24
+ value: function mount(option) {
25
+ var container = option.container;
26
+ var stage = initStage(container);
27
+ // 画布的 context 用于绘制等
28
+ this.ctx = stage === null || stage === void 0 ? void 0 : stage.ctx;
29
+ // 画布元素 用于操作 dom
30
+ this.canvasElement = stage === null || stage === void 0 ? void 0 : stage.canvasElement;
31
+ // 绘制 canvas 内部数据
32
+ this.renderStage();
33
+ // 添加事件监听
34
+ // this.addStageEventListener();
35
+ }
36
+ // 添加子元素
37
+ }, {
38
+ key: "appendChild",
39
+ value: function appendChild() {
40
+ var _this = this;
41
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
42
+ args[_key] = arguments[_key];
43
+ }
44
+ var elements = args.flat(1);
45
+ this.children = this.children.concat(elements);
46
+ this.children = this.children.map(function (item) {
47
+ return Object.assign(item, {
48
+ parent: _this
49
+ });
50
+ });
51
+ mountStage(this.children, this);
52
+ }
53
+ }, {
54
+ key: "renderStage",
55
+ value: function renderStage() {
56
+ var _this2 = this;
57
+ if (this.isAsyncRenderTask) {
58
+ return;
59
+ }
60
+ this.isAsyncRenderTask = true;
61
+ requestAnimationFrame(function () {
62
+ resetSchedulerCount();
63
+ drawStageShapes(_this2);
64
+ _this2.isAsyncRenderTask = false;
65
+ });
66
+ }
67
+ // canvas 添加时间监听
68
+ }, {
69
+ key: "addStageEventListener",
70
+ value: function addStageEventListener() {
71
+ if (!this.canvasElement) return;
72
+ // 鼠标移动
73
+ this.canvasElement.onmousemove = function (evt) {
74
+ {
75
+ // 触发舞台(canvas Element)的事件
76
+ var eventParameter = {
77
+ target: null,
78
+ x: evt.offsetX,
79
+ y: evt.offsetY,
80
+ nativeEvent: evt
81
+ };
82
+ console.log(eventParameter, 'onmousemove_eventParameter');
83
+ }
84
+ };
85
+ }
86
+ }]);
87
+ return Stage;
88
+ }();
@@ -0,0 +1,12 @@
1
+ import { Shape, ShapeData } from './shape';
2
+ export interface TrapezoidData extends ShapeData {
3
+ x?: number;
4
+ y?: number;
5
+ width?: number;
6
+ height?: number;
7
+ shortLength?: number | string;
8
+ }
9
+ export declare class Trapezoid extends Shape<TrapezoidData> {
10
+ constructor(data: TrapezoidData);
11
+ data: TrapezoidData;
12
+ }
@@ -0,0 +1,24 @@
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
+ // @
16
+ export var Trapezoid = /*#__PURE__*/function (_Shape) {
17
+ _inherits(Trapezoid, _Shape);
18
+ var _super = _createSuper(Trapezoid);
19
+ function Trapezoid(data) {
20
+ _classCallCheck(this, Trapezoid);
21
+ return _super.call(this, 'Trapezoid', data);
22
+ }
23
+ return _createClass(Trapezoid);
24
+ }(Shape);
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import { Stage as _Stage } from '../instance/stage';
3
+ export declare const Context: import("react").Context<_Stage>;
@@ -0,0 +1,2 @@
1
+ import { createContext } from 'react';
2
+ export var Context = /*#__PURE__*/createContext({});
@@ -0,0 +1,25 @@
1
+ // import { BoxHidden, Circle, Group, Line, Rect, Text } from './shape'
2
+
3
+ // export type IShape = Group | BoxHidden | Circle | Rect | Line | Text
4
+ export type IShapeType = 'Line' | 'Rect' | 'Trapezoid' | 'Circle' | 'Text' | 'Group' | 'BoxHidden' | 'Stage'
5
+
6
+ export type ICursor =
7
+ | 'url'
8
+ | 'default'
9
+ | 'auto'
10
+ | 'crosshair'
11
+ | 'pointer'
12
+ | 'move'
13
+ | 'e-resize'
14
+ | 'ne-resize'
15
+ | 'nw-resize'
16
+ | 'n-resize'
17
+ | 'se-resize'
18
+ | 'sw-resize'
19
+ | 's-resize'
20
+ | 'w-resize'
21
+ | 'text'
22
+ | 'wait'
23
+ | 'help'
24
+
25
+ export type ICoord = { x: number; y: number }
@@ -0,0 +1 @@
1
+ export declare const usePropertyChange: (props: any, property: any, shape: any) => void;
@@ -0,0 +1,23 @@
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 _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; }
3
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
4
+ 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); }
5
+ import { useLayoutEffect } from 'react';
6
+ export var usePropertyChange = function usePropertyChange(props, property, shape) {
7
+ useLayoutEffect(function () {
8
+ // if (props.animation?.duration > 16.7) {
9
+ // shape
10
+ // .animateCartoon({ [property]: props[property] }, { ...props.animation })
11
+ // .then(() => {
12
+ // props.animation.animationEnd?.();
13
+ // });
14
+ // } else {
15
+ // if (props[property] !== undefined) {
16
+ // shape.attr({ [property]: props[property] });
17
+ // }
18
+ // }
19
+ if (props[property] !== undefined) {
20
+ shape.attr(_defineProperty({}, property, props[property]));
21
+ }
22
+ }, [props[property]]);
23
+ };
@@ -0,0 +1 @@
1
+ export declare const sortChildren: (children: any) => any;
@@ -0,0 +1,7 @@
1
+ export var sortChildren = function sortChildren(children) {
2
+ return children.toSorted(function (a, b) {
3
+ var a_zIndex = a.data.zIndex;
4
+ var b_zIndex = b.data.zIndex;
5
+ return a_zIndex - b_zIndex;
6
+ });
7
+ };
@@ -0,0 +1,3 @@
1
+ export declare const hasStroke: (lineWidth: number, strokeStyle: CanvasFillStrokeStyles['strokeStyle']) => string | false | CanvasGradient | CanvasPattern;
2
+ export declare const fillOrStroke: (ctx: CanvasRenderingContext2D, elementItem: any) => void;
3
+ export declare function setCtxStyleProp(ctx: CanvasRenderingContext2D, elementItem: any): void;
@@ -0,0 +1,55 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
7
+ export var hasStroke = function hasStroke(lineWidth, strokeStyle) {
8
+ return lineWidth > 0 && lineWidth !== Infinity && strokeStyle;
9
+ };
10
+ export var fillOrStroke = function fillOrStroke(ctx, elementItem) {
11
+ if (elementItem.data.fillStyle) {
12
+ ctx.fill(elementItem.path2D);
13
+ }
14
+ if (hasStroke(elementItem.data.lineWidth, elementItem.data.strokeStyle)) {
15
+ ctx.stroke(elementItem.path2D);
16
+ }
17
+ };
18
+ export function setCtxStyleProp(ctx, elementItem) {
19
+ var data = elementItem.data;
20
+ var lineWidth = data.lineWidth,
21
+ lineCap = data.lineCap,
22
+ lineJoin = data.lineJoin,
23
+ strokeStyle = data.strokeStyle,
24
+ fillStyle = data.fillStyle,
25
+ opacity = data.opacity;
26
+ var shadowBlur = data.shadowBlur,
27
+ shadowColor = data.shadowColor,
28
+ shadowOffsetX = data.shadowOffsetX,
29
+ shadowOffsetY = data.shadowOffsetY;
30
+ var transform = elementItem.transform,
31
+ scale = elementItem.scale,
32
+ translate = elementItem.translate;
33
+ ctx.lineWidth = lineWidth;
34
+ ctx.lineCap = lineCap;
35
+ ctx.lineJoin = lineJoin;
36
+ ctx.strokeStyle = strokeStyle;
37
+ ctx.fillStyle = fillStyle;
38
+
39
+ // ctx.setLineDash(lineDash);
40
+
41
+ ctx.globalAlpha = opacity;
42
+ ctx.shadowOffsetX = shadowOffsetX;
43
+ ctx.shadowOffsetY = shadowOffsetY;
44
+ ctx.shadowColor = shadowColor;
45
+ ctx.shadowBlur = shadowBlur;
46
+ if (transform) {
47
+ ctx.setTransform.apply(ctx, _toConsumableArray(transform));
48
+ }
49
+ if (scale) {
50
+ ctx.scale(scale.x, scale.y);
51
+ }
52
+ if (translate) {
53
+ ctx.translate(translate.x, translate.y);
54
+ }
55
+ }
@@ -0,0 +1 @@
1
+ export declare function drawShapes(ctx: CanvasRenderingContext2D, list: any[]): void;
@@ -0,0 +1,47 @@
1
+ import { sortChildren } from "./..";
2
+ import { fillOrStroke, setCtxStyleProp } from "./common";
3
+ import { setRectPath2D } from "./renderRect";
4
+ import { setCirclePath2D } from "./renderCircle";
5
+ import { setTrapezoidPath2D } from "./renderTrapezoid";
6
+
7
+ // 根据不同的 类型绘制
8
+ export function drawShapes(ctx, list) {
9
+ var curlist = sortChildren(list);
10
+ curlist.forEach(function (elementItem) {
11
+ console.log(elementItem, 'elementItem');
12
+ // const { data } = elementItem;
13
+
14
+ ctx.beginPath();
15
+ setCtxStyleProp(ctx, elementItem);
16
+ switch (elementItem.type) {
17
+ case 'Trapezoid':
18
+ {
19
+ setTrapezoidPath2D(elementItem);
20
+ fillOrStroke(ctx, elementItem);
21
+ break;
22
+ }
23
+ case 'Rect':
24
+ {
25
+ setRectPath2D(elementItem);
26
+ fillOrStroke(ctx, elementItem);
27
+ break;
28
+ }
29
+ case 'Line':
30
+ {
31
+ console.log(elementItem, 'elementItem');
32
+ // const { closed, path2D } = data as Line['data'];
33
+
34
+ break;
35
+ }
36
+ case 'Circle':
37
+ {
38
+ setCirclePath2D(elementItem);
39
+ fillOrStroke(ctx, elementItem);
40
+ break;
41
+ }
42
+ default:
43
+ console.log(elementItem.type, '该图形 暂未实现');
44
+ break;
45
+ }
46
+ });
47
+ }
@@ -0,0 +1,8 @@
1
+ import { Circle } from "../../instance/circle";
2
+ export declare function deg2rad(deg: number): number;
3
+ export declare function rad2deg(radian: number): number;
4
+ export declare function getPointOnArc(x0: number, y0: number, r: number, deg: number): {
5
+ x: number;
6
+ y: number;
7
+ };
8
+ export declare function setCirclePath2D(elementItem: Circle): void;
@@ -0,0 +1,88 @@
1
+ // 角度转弧度
2
+ export function deg2rad(deg) {
3
+ return deg * Math.PI / 180;
4
+ }
5
+
6
+ // 弧度转角度
7
+ export function rad2deg(radian) {
8
+ return radian * 180 / Math.PI;
9
+ }
10
+
11
+ // 获取圆弧上的点 圆心 半径 角度: 60°
12
+ export function getPointOnArc(x0, y0, r, deg) {
13
+ var alpha = deg2rad(deg);
14
+ var x = x0 + r * Math.cos(alpha); // Math.cos 传入弧度
15
+ var y = y0 + r * Math.sin(alpha);
16
+ return {
17
+ x: x,
18
+ y: y
19
+ };
20
+ }
21
+ // 圆环/扇环
22
+ var calcRingD = function calcRingD(outerRadius, innerRadius, startAngle, endAngle, centerX, centerY, isWholeArc) {
23
+ function calcWholeRingD() {
24
+ var outerM_y = centerY - outerRadius;
25
+ var outerM = "M ".concat(centerX, " ").concat(outerM_y);
26
+ var outerA = "A ".concat(outerRadius, " ").concat(outerRadius, " 0 1 1 ").concat(centerX - 0.01, " ").concat(outerM_y);
27
+ var innerM_y = centerY - innerRadius;
28
+ var innerM = "M ".concat(centerX, " ").concat(innerM_y);
29
+ var innerA = "A ".concat(innerRadius, " ").concat(innerRadius, " 0 1 0 ").concat(centerX + 0.01, " ").concat(innerM_y);
30
+ return "".concat(outerM, " ").concat(outerA, " ").concat(innerM, " ").concat(innerA, " Z");
31
+ }
32
+ function calcRingSectorD() {
33
+ var outerStart = getPointOnArc(centerX, centerY, outerRadius, startAngle);
34
+ var outerEnd = getPointOnArc(centerX, centerY, outerRadius, endAngle);
35
+ var largeArcFlag = endAngle - startAngle >= 180 ? 1 : 0;
36
+ var outerM = "M ".concat(outerStart.x, " ").concat(outerStart.y);
37
+ var outerA = "A ".concat(outerRadius, " ").concat(outerRadius, " 0 ").concat(largeArcFlag, " 1 ").concat(outerEnd.x, " ").concat(outerEnd.y);
38
+ var innerStart = getPointOnArc(centerX, centerY, innerRadius, startAngle);
39
+ var innerEnd = getPointOnArc(centerX, centerY, innerRadius, endAngle);
40
+ var moveL = "L".concat(innerEnd.x, " ").concat(innerEnd.y);
41
+ var innerA = "A ".concat(innerRadius, " ").concat(innerRadius, " 0 ").concat(largeArcFlag, " 0 ").concat(innerStart.x, " ").concat(innerStart.y);
42
+ return "".concat(outerM, " ").concat(outerA, " ").concat(moveL, " ").concat(innerA, " Z");
43
+ }
44
+ return isWholeArc ? calcWholeRingD() : calcRingSectorD();
45
+ };
46
+
47
+ // 圆形/扇形 返回 path 的 d属性 返回的是 圆弧 -起始角度遵循数学上的平面直角坐标系
48
+ var calcD = function calcD(radius, startAngle, endAngle, centerX, centerY, isWholeArc, offsetAngle) {
49
+ startAngle = startAngle + offsetAngle;
50
+ endAngle = endAngle + offsetAngle;
51
+
52
+ // 将角度转换为弧度
53
+ var startAngleRad = startAngle * Math.PI / 180;
54
+ var endAngleRad = endAngle * Math.PI / 180;
55
+
56
+ // 计算圆弧的起点和终点坐标
57
+ var startX = centerX + radius * Math.cos(startAngleRad);
58
+ var startY = centerY + radius * Math.sin(startAngleRad);
59
+ var endX = centerX + radius * Math.cos(endAngleRad);
60
+ var endY = centerY + radius * Math.sin(endAngleRad);
61
+
62
+ // 计算扇形所需的路径命令
63
+ var largeArcFlag = endAngle - startAngle <= 180 ? 0 : 1;
64
+ var sweepFlag = 1;
65
+ var M_y = centerY - radius;
66
+ var d = isWholeArc ? "M".concat(centerX, ",").concat(M_y, " A").concat(radius, ",").concat(radius, " 0 1 1, ").concat(centerX - 0.01, ",").concat(centerY - radius, "Z") : "M".concat(centerX, ",").concat(centerY, " L").concat(startX, ",").concat(startY, " A").concat(radius, ",").concat(radius, " 0 ").concat(largeArcFlag, ",").concat(sweepFlag, " ").concat(endX, ",").concat(endY, " Z");
67
+ return d;
68
+ };
69
+ export function setCirclePath2D(elementItem) {
70
+ var _elementItem$data = elementItem.data,
71
+ _elementItem$data$x = _elementItem$data.x,
72
+ x = _elementItem$data$x === void 0 ? 0 : _elementItem$data$x,
73
+ _elementItem$data$y = _elementItem$data.y,
74
+ y = _elementItem$data$y === void 0 ? 0 : _elementItem$data$y,
75
+ _elementItem$data$rad = _elementItem$data.radius,
76
+ radius = _elementItem$data$rad === void 0 ? 0 : _elementItem$data$rad,
77
+ innerRadius = _elementItem$data.innerRadius,
78
+ _elementItem$data$sta = _elementItem$data.startAngle,
79
+ startAngle = _elementItem$data$sta === void 0 ? 0 : _elementItem$data$sta,
80
+ _elementItem$data$end = _elementItem$data.endAngle,
81
+ endAngle = _elementItem$data$end === void 0 ? 0 : _elementItem$data$end,
82
+ _elementItem$data$off = _elementItem$data.offsetAngle,
83
+ offsetAngle = _elementItem$data$off === void 0 ? 0 : _elementItem$data$off;
84
+ var isWholeArc = startAngle === 0 && endAngle === 360; // 是否是整圆
85
+
86
+ var d = innerRadius ? calcRingD(radius, innerRadius, startAngle, endAngle, x, y, isWholeArc) : calcD(radius, startAngle, endAngle, x, y, isWholeArc, offsetAngle);
87
+ elementItem.path2D = new Path2D(d);
88
+ }
File without changes