@cloud-app-dev/vidc 4.0.1 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/es/AppContext/index.js +20 -61
  2. package/es/AutoExit/index.js +5 -9
  3. package/es/Config/index.js +0 -5
  4. package/es/Config/utils.js +7 -27
  5. package/es/ConfigContext/index.d.ts +1 -1
  6. package/es/ConfigContext/index.js +1 -3
  7. package/es/CustomRenderSelect/index.js +19 -39
  8. package/es/DynamicGridList/index.js +16 -28
  9. package/es/FullScreen/index.js +10 -21
  10. package/es/GridList/hook.js +36 -67
  11. package/es/GridList/index.d.ts +1 -1
  12. package/es/GridList/index.js +1 -1
  13. package/es/ImageView/index.js +16 -31
  14. package/es/LabelValue/index.d.ts +0 -8
  15. package/es/LabelValue/index.js +11 -16
  16. package/es/List/index.js +5 -7
  17. package/es/ListWithSizeAnimate/demo.js +3 -15
  18. package/es/LoaderScript/utils.js +100 -153
  19. package/es/Map/Config/index.d.ts +4 -2
  20. package/es/Map/Config/index.js +17 -32
  21. package/es/Map/Config/utils.d.ts +2 -2
  22. package/es/Map/Config/utils.js +40 -51
  23. package/es/Map/InfoWindow/MakerLikeWindow.js +35 -29
  24. package/es/Map/InfoWindow/demo.js +17 -29
  25. package/es/Map/interface.d.ts +14 -0
  26. package/es/Picture/component/Tools/index.js +5 -7
  27. package/es/Picture/demo.js +15 -19
  28. package/es/Picture/index.js +70 -104
  29. package/es/Picture/utils.js +14 -28
  30. package/es/Player/api/index.js +26 -94
  31. package/es/Player/contraller_bar/right_bar.js +12 -23
  32. package/es/Player/demo.js +47 -62
  33. package/es/Player/event/errorEvent.js +15 -40
  34. package/es/Player/fps_play.js +12 -28
  35. package/es/Player/frontend_timeline.js +28 -48
  36. package/es/Player/player.d.ts +2 -1
  37. package/es/Player/segment_timeline.js +45 -69
  38. package/es/Player/single_player.js +101 -109
  39. package/es/Player/util.js +8 -27
  40. package/es/Progress/index.js +5 -16
  41. package/es/ROI/index.d.ts +0 -6
  42. package/es/ROI/index.js +17 -26
  43. package/es/RefDrawer/Footer.js +3 -5
  44. package/es/RefDrawer/demo.js +0 -3
  45. package/es/RefDrawer/index.js +17 -27
  46. package/es/RefModal/demo.js +0 -3
  47. package/es/RefModal/index.js +27 -27
  48. package/es/ScreenPlayer/Live.d.ts +1 -1
  49. package/es/ScreenPlayer/Live.js +36 -70
  50. package/es/ScreenPlayer/LiveTools.js +20 -39
  51. package/es/ScreenPlayer/PlayerWithExt.js +48 -85
  52. package/es/ScreenPlayer/RecordTools.d.ts +1 -1
  53. package/es/ScreenPlayer/RecordTools.js +27 -53
  54. package/es/ScreenPlayer/SegmentTimeLine.js +8 -13
  55. package/es/ScreenPlayer/TimeSelect.js +9 -24
  56. package/es/ScreenPlayer/demo.js +1 -1
  57. package/es/ScreenPlayer/demo2.js +76 -108
  58. package/es/ScreenPlayer/useTimeSlider.js +63 -141
  59. package/es/Service/http.js +14 -34
  60. package/es/TableLayout/index.js +6 -10
  61. package/es/ThemeAntd/index.js +0 -1
  62. package/es/Timeout/index.js +16 -31
  63. package/es/VList/index.d.ts +1 -9
  64. package/es/VList/index.js +18 -30
  65. package/es/typings.d.ts +1 -0
  66. package/es/useDrawROI/index.js +61 -115
  67. package/es/useInfiniteScroll/index.js +24 -45
  68. package/es/utils.js +18 -42
  69. package/package.json +4 -5
  70. package/es/ROI/utils.d.ts +0 -1
  71. package/es/ROI/utils.js +0 -1
  72. package/es/ThemeAntd/demo.html +0 -32
@@ -2,19 +2,16 @@ import _useSize from "ahooks/es/useSize";
2
2
  import React, { useMemo, useRef } from 'react';
3
3
  import "./index.less";
4
4
  import { jsx as _jsx } from "react/jsx-runtime";
5
-
6
5
  function TableLayout(_ref) {
7
6
  var _ref$className = _ref.className,
8
- className = _ref$className === void 0 ? '' : _ref$className,
9
- children = _ref.children,
10
- _ref$cutNum = _ref.cutNum,
11
- cutNum = _ref$cutNum === void 0 ? 0 : _ref$cutNum,
12
- _ref$x = _ref.x,
13
- x = _ref$x === void 0 ? 1200 : _ref$x;
7
+ className = _ref$className === void 0 ? '' : _ref$className,
8
+ children = _ref.children,
9
+ _ref$cutNum = _ref.cutNum,
10
+ cutNum = _ref$cutNum === void 0 ? 0 : _ref$cutNum,
11
+ _ref$x = _ref.x,
12
+ x = _ref$x === void 0 ? 1200 : _ref$x;
14
13
  var domRef = useRef(null);
15
-
16
14
  var size = _useSize(domRef);
17
-
18
15
  var height = useMemo(function () {
19
16
  return size !== null && size !== void 0 && size.height ? size.height - cutNum : 0;
20
17
  }, [size === null || size === void 0 ? void 0 : size.height, cutNum]);
@@ -29,5 +26,4 @@ function TableLayout(_ref) {
29
26
  })
30
27
  });
31
28
  }
32
-
33
29
  export default TableLayout;
@@ -16,7 +16,6 @@ export default function ThemeAntd(_ref) {
16
16
  colorPrimary: 'orange',
17
17
  // 主色
18
18
  controlOutline: 'transparent' // 表单阴影
19
-
20
19
  }
21
20
  },
22
21
  children: children
@@ -1,46 +1,36 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
1
2
  import _useEventListener from "ahooks/es/useEventListener";
2
3
  import _useRafInterval from "ahooks/es/useRafInterval";
3
-
4
4
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
-
6
5
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
7
-
8
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
-
6
+ 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; }
7
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
8
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
10
9
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
11
-
12
10
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
13
-
14
11
  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); }
15
-
16
- 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; }
17
-
18
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
19
-
12
+ 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; }
13
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
20
14
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
21
-
22
15
  import React, { useEffect, useRef, useState } from 'react';
23
16
  import { Fragment as _Fragment } from "react/jsx-runtime";
24
17
  import { jsx as _jsx } from "react/jsx-runtime";
25
-
26
18
  /**
27
19
  * @desc 用户创建界面超时回调
28
20
  */
29
21
  function Timeout(_ref) {
30
22
  var contianer = _ref.contianer,
31
- time = _ref.time,
32
- onTimeout = _ref.onTimeout,
33
- ignore = _ref.ignore;
23
+ time = _ref.time,
24
+ onTimeout = _ref.onTimeout,
25
+ ignore = _ref.ignore;
34
26
  var cuurentTimeRef = useRef(Date.now());
35
27
  var lockstatusRef = useRef(false);
36
-
37
28
  var _useState = useState({
38
- timelock: Date.now()
39
- }),
40
- _useState2 = _slicedToArray(_useState, 2),
41
- state = _useState2[0],
42
- setState = _useState2[1];
43
-
29
+ timelock: Date.now()
30
+ }),
31
+ _useState2 = _slicedToArray(_useState, 2),
32
+ state = _useState2[0],
33
+ setState = _useState2[1];
44
34
  _useRafInterval(function () {
45
35
  var now = Date.now();
46
36
  setState(function (old) {
@@ -49,35 +39,30 @@ function Timeout(_ref) {
49
39
  });
50
40
  });
51
41
  var isIgnore = ignore ? ignore() : false;
52
-
53
42
  if (isIgnore) {
54
43
  // 如果当前需要忽略,那么重置时间
55
44
  cuurentTimeRef.current = now;
56
45
  }
57
46
  }, 1 * 1000);
58
-
59
47
  useEffect(function () {
60
48
  var isIgnore = ignore ? ignore() : false;
61
-
62
49
  if (!lockstatusRef.current && state.timelock - cuurentTimeRef.current > time * 1000 && !isIgnore) {
63
50
  lockstatusRef.current = true;
64
51
  onTimeout === null || onTimeout === void 0 ? void 0 : onTimeout();
65
52
  setTimeout(function () {
66
53
  lockstatusRef.current = false;
67
54
  }, 1000);
68
- } // eslint-disable-next-line react-hooks/exhaustive-deps
55
+ }
69
56
 
57
+ // eslint-disable-next-line react-hooks/exhaustive-deps
70
58
  }, [state.timelock, time]);
71
-
72
59
  _useEventListener('mousemove', function () {
73
60
  return cuurentTimeRef.current = Date.now();
74
61
  }, {
75
62
  target: contianer
76
63
  });
77
-
78
64
  return /*#__PURE__*/_jsx(_Fragment, {});
79
65
  }
80
-
81
66
  Timeout.defaultProps = {
82
67
  time: 15 * 60,
83
68
  contianer: document.body
@@ -7,13 +7,5 @@ interface IVListProps<T> {
7
7
  renderItem(item: T, index: number): JSX.Element;
8
8
  overscan?: number;
9
9
  }
10
- declare function VList<T>({ className, rowHeight, data, renderItem }: IVListProps<T>): JSX.Element;
11
- declare namespace VList {
12
- var defaultProps: {
13
- className: string;
14
- rowHeight: number;
15
- overscan: number;
16
- data: never[];
17
- };
18
- }
10
+ declare function VList<T>({ className, rowHeight, data, renderItem, overscan }: IVListProps<T>): JSX.Element;
19
11
  export default VList;
package/es/VList/index.js CHANGED
@@ -1,38 +1,33 @@
1
1
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
-
3
2
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
-
5
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); }
6
-
7
- 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; }
8
-
9
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
10
-
4
+ 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; }
5
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
11
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
-
13
7
  import React, { useRef } from 'react';
14
8
  import useVirtualList from "../useVirtualList";
15
9
  import "./index.less";
16
10
  import { jsx as _jsx } from "react/jsx-runtime";
17
-
18
11
  function VList(_ref) {
19
- var className = _ref.className,
20
- rowHeight = _ref.rowHeight,
21
- _ref$data = _ref.data,
22
- data = _ref$data === void 0 ? [] : _ref$data,
23
- renderItem = _ref.renderItem;
12
+ var _ref$className = _ref.className,
13
+ className = _ref$className === void 0 ? '' : _ref$className,
14
+ _ref$rowHeight = _ref.rowHeight,
15
+ rowHeight = _ref$rowHeight === void 0 ? 30 : _ref$rowHeight,
16
+ _ref$data = _ref.data,
17
+ data = _ref$data === void 0 ? [] : _ref$data,
18
+ renderItem = _ref.renderItem,
19
+ _ref$overscan = _ref.overscan,
20
+ overscan = _ref$overscan === void 0 ? 10 : _ref$overscan;
24
21
  var containerRef = useRef(null);
25
22
  var wrapperRef = useRef(null);
26
-
27
23
  var _useVirtualList = useVirtualList(data, {
28
- containerTarget: containerRef,
29
- wrapperTarget: wrapperRef,
30
- itemHeight: rowHeight,
31
- overscan: 10
32
- }),
33
- _useVirtualList2 = _slicedToArray(_useVirtualList, 1),
34
- list = _useVirtualList2[0];
35
-
24
+ containerTarget: containerRef,
25
+ wrapperTarget: wrapperRef,
26
+ itemHeight: rowHeight,
27
+ overscan: overscan
28
+ }),
29
+ _useVirtualList2 = _slicedToArray(_useVirtualList, 1),
30
+ list = _useVirtualList2[0];
36
31
  return /*#__PURE__*/_jsx("div", {
37
32
  className: "vidc-simple-list-layout ".concat(className),
38
33
  ref: containerRef,
@@ -44,11 +39,4 @@ function VList(_ref) {
44
39
  })
45
40
  });
46
41
  }
47
-
48
- VList.defaultProps = {
49
- className: '',
50
- rowHeight: 30,
51
- overscan: 10,
52
- data: []
53
- };
54
42
  export default VList;
package/es/typings.d.ts CHANGED
@@ -1 +1,2 @@
1
+ // eslint-disable-next-line @typescript-eslint/triple-slash-reference
1
2
  /// <reference path="../typings/global.d.ts"/>
@@ -1,37 +1,25 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
1
2
  import _useEventListener from "ahooks/es/useEventListener";
2
3
  import _useUpdateEffect from "ahooks/es/useUpdateEffect";
3
4
  import _usePrevious from "ahooks/es/usePrevious";
4
5
  import _useSize from "ahooks/es/useSize";
5
6
  import _useLatest from "ahooks/es/useLatest";
6
-
7
7
  function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
8
-
9
8
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
10
-
11
9
  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."); }
12
-
13
10
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
14
-
15
11
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
16
-
17
12
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
18
-
19
13
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
20
-
21
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
22
-
14
+ 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; }
15
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
16
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
23
17
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
24
-
25
18
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
26
-
27
19
  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); }
28
-
29
- 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; }
30
-
31
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
32
-
20
+ 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; }
21
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
33
22
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
34
-
35
23
  import booleanDisjoint from '@turf/boolean-disjoint';
36
24
  import { lineString } from '@turf/helpers';
37
25
  import lineToPolygon from '@turf/line-to-polygon';
@@ -39,43 +27,34 @@ import { getTargetElement } from 'ahooks/lib/utils/domTarget';
39
27
  import { useEffect, useMemo } from 'react';
40
28
  import { useHotkeys } from 'react-hotkeys-hook';
41
29
  import useSimpleState from "../useSimpleState";
42
-
43
30
  function useDrawROI(target, _ref) {
44
31
  var row = _ref.row,
45
- rowItems = _ref.rowItems,
46
- defaultAreas = _ref.defaultAreas;
47
-
32
+ rowItems = _ref.rowItems,
33
+ defaultAreas = _ref.defaultAreas;
48
34
  var _useSimpleState = useSimpleState({
49
- pos: [],
50
- tempPos: [],
51
- saveArea: defaultAreas !== null && defaultAreas !== void 0 ? defaultAreas : [],
52
- isOpen: false
53
- }),
54
- _useSimpleState2 = _slicedToArray(_useSimpleState, 3),
55
- state = _useSimpleState2[0],
56
- updateState = _useSimpleState2[1],
57
- setState = _useSimpleState2[2];
58
-
35
+ pos: [],
36
+ tempPos: [],
37
+ saveArea: defaultAreas !== null && defaultAreas !== void 0 ? defaultAreas : [],
38
+ isOpen: false
39
+ }),
40
+ _useSimpleState2 = _slicedToArray(_useSimpleState, 3),
41
+ state = _useSimpleState2[0],
42
+ updateState = _useSimpleState2[1],
43
+ setState = _useSimpleState2[2];
59
44
  var isOpenRef = _useLatest(state.isOpen);
60
-
61
45
  var size = _useSize(target);
62
-
63
46
  var oldSize = _usePrevious(size);
64
-
65
47
  useEffect(function () {
66
48
  if (!(size !== null && size !== void 0 && size.width)) {
67
49
  return;
68
50
  }
69
-
70
51
  var canvas = getTargetElement(target);
71
52
  canvas.width = size === null || size === void 0 ? void 0 : size.width;
72
53
  canvas.height = size === null || size === void 0 ? void 0 : size.height;
73
54
  console.warn('canvas,size变化!');
74
-
75
55
  if (!(oldSize !== null && oldSize !== void 0 && oldSize.width)) {
76
56
  return;
77
57
  }
78
-
79
58
  var scale = size.width / oldSize.width;
80
59
  setState(function (old) {
81
60
  return _objectSpread(_objectSpread({}, old), {}, {
@@ -87,9 +66,9 @@ function useDrawROI(target, _ref) {
87
66
  });
88
67
  })
89
68
  });
90
- }); // eslint-disable-next-line react-hooks/exhaustive-deps
69
+ });
70
+ // eslint-disable-next-line react-hooks/exhaustive-deps
91
71
  }, [size === null || size === void 0 ? void 0 : size.height, size === null || size === void 0 ? void 0 : size.width]);
92
-
93
72
  _useUpdateEffect(function () {
94
73
  if (state.saveArea.length === 0 && defaultAreas && defaultAreas.length > 0) {
95
74
  updateState({
@@ -97,27 +76,24 @@ function useDrawROI(target, _ref) {
97
76
  });
98
77
  }
99
78
  }, [defaultAreas, state.saveArea]);
100
-
101
79
  _useEventListener('click', function (event) {
102
80
  if (!isOpenRef.current) {
103
81
  return;
104
82
  }
105
-
106
83
  var p_x = event.offsetX;
107
84
  var p_y = event.offsetY;
108
85
  setState(function (old) {
109
- var pos = old.pos; // 去掉重复点位,dbclick导致重复触发
86
+ var pos = old.pos;
110
87
 
88
+ // 去掉重复点位,dbclick导致重复触发
111
89
  if (!pos.find(function (_ref2) {
112
90
  var _ref3 = _slicedToArray(_ref2, 2),
113
- x = _ref3[0],
114
- y = _ref3[1];
115
-
91
+ x = _ref3[0],
92
+ y = _ref3[1];
116
93
  return x === p_x && y === p_y;
117
94
  })) {
118
95
  pos = [].concat(_toConsumableArray(pos), [[p_x, p_y]]);
119
96
  }
120
-
121
97
  return _objectSpread(_objectSpread({}, old), {}, {
122
98
  pos: pos
123
99
  });
@@ -125,7 +101,6 @@ function useDrawROI(target, _ref) {
125
101
  }, {
126
102
  target: target
127
103
  });
128
-
129
104
  _useEventListener('dblclick', function (event) {
130
105
  var p_x = event.offsetX;
131
106
  var p_y = event.offsetY;
@@ -133,24 +108,20 @@ function useDrawROI(target, _ref) {
133
108
  var saveArea = old.saveArea;
134
109
  var pos = old.pos;
135
110
  var tempPos = old.tempPos;
136
-
137
111
  if (pos.length > 2) {
138
112
  // 去掉重复点位
139
113
  if (!pos.find(function (_ref4) {
140
114
  var _ref5 = _slicedToArray(_ref4, 2),
141
- x = _ref5[0],
142
- y = _ref5[1];
143
-
115
+ x = _ref5[0],
116
+ y = _ref5[1];
144
117
  return x === p_x && y === p_y;
145
118
  })) {
146
119
  pos = [].concat(_toConsumableArray(pos), [[p_x, p_y]]);
147
120
  }
148
-
149
121
  saveArea = [].concat(_toConsumableArray(saveArea), [pos]);
150
122
  pos = [];
151
123
  tempPos = [];
152
124
  }
153
-
154
125
  return _objectSpread(_objectSpread({}, old), {}, {
155
126
  pos: pos,
156
127
  saveArea: saveArea,
@@ -160,12 +131,10 @@ function useDrawROI(target, _ref) {
160
131
  }, {
161
132
  target: target
162
133
  });
163
-
164
134
  _useEventListener('mousemove', function (event) {
165
135
  if (!isOpenRef.current || state.pos.length === 0) {
166
136
  return;
167
137
  }
168
-
169
138
  var p_x = event.offsetX;
170
139
  var p_y = event.offsetY;
171
140
  setState(function (old) {
@@ -176,31 +145,27 @@ function useDrawROI(target, _ref) {
176
145
  }, {
177
146
  target: target
178
147
  });
179
-
180
148
  var clearCanvas = function clearCanvas() {
181
149
  var canvas = getTargetElement(target);
182
- var ctx = canvas.getContext('2d'); // 重置画布
183
-
150
+ var ctx = canvas.getContext('2d');
151
+ // 重置画布
184
152
  ctx.clearRect(0, 0, canvas.width, canvas.height);
185
153
  };
186
-
187
154
  var drawSavaArea = function drawSavaArea(area) {
188
155
  var canvas = getTargetElement(target);
189
- var ctx = canvas.getContext('2d'); // 绘制已完成的图形
190
-
156
+ var ctx = canvas.getContext('2d');
157
+ // 绘制已完成的图形
191
158
  area.forEach(function (item) {
192
159
  // 绘制坐标线
193
160
  var _item = _toArray(item),
194
- startPos = _item[0],
195
- pos = _item.slice(1);
196
-
161
+ startPos = _item[0],
162
+ pos = _item.slice(1);
197
163
  ctx.beginPath();
198
164
  ctx.moveTo.apply(ctx, _toConsumableArray(startPos));
199
165
  pos.forEach(function (_ref6) {
200
166
  var _ref7 = _slicedToArray(_ref6, 2),
201
- x = _ref7[0],
202
- y = _ref7[1];
203
-
167
+ x = _ref7[0],
168
+ y = _ref7[1];
204
169
  return ctx.lineTo(x, y);
205
170
  });
206
171
  ctx.lineTo.apply(ctx, _toConsumableArray(startPos));
@@ -211,66 +176,59 @@ function useDrawROI(target, _ref) {
211
176
  ctx.stroke();
212
177
  });
213
178
  };
214
-
215
179
  var canvasRendering = function canvasRendering(points, tempPos) {
216
180
  if (points.length === 0) {
217
181
  return;
218
182
  }
219
-
220
183
  var canvas = getTargetElement(target);
221
- var ctx = canvas.getContext('2d'); // 绘制坐标点
222
-
184
+ var ctx = canvas.getContext('2d');
185
+ // 绘制坐标点
223
186
  points.forEach(function (_ref8) {
224
187
  var _ref9 = _slicedToArray(_ref8, 2),
225
- x = _ref9[0],
226
- y = _ref9[1];
227
-
188
+ x = _ref9[0],
189
+ y = _ref9[1];
228
190
  ctx.beginPath();
229
191
  ctx.arc(x, y, 4, 0, 2 * Math.PI);
230
192
  ctx.fillStyle = 'red';
231
193
  ctx.fill();
232
- }); // 绘制坐标线
194
+ });
233
195
 
196
+ // 绘制坐标线
234
197
  var _points = _toArray(points),
235
- startPos = _points[0],
236
- pos = _points.slice(1);
237
-
198
+ startPos = _points[0],
199
+ pos = _points.slice(1);
238
200
  ctx.beginPath();
239
201
  ctx.moveTo.apply(ctx, _toConsumableArray(startPos));
240
202
  pos.forEach(function (_ref10) {
241
203
  var _ref11 = _slicedToArray(_ref10, 2),
242
- x = _ref11[0],
243
- y = _ref11[1];
244
-
204
+ x = _ref11[0],
205
+ y = _ref11[1];
245
206
  return ctx.lineTo(x, y);
246
207
  });
247
-
248
208
  var _tempPos = _slicedToArray(tempPos, 2),
249
- x = _tempPos[0],
250
- y = _tempPos[1];
251
-
209
+ x = _tempPos[0],
210
+ y = _tempPos[1];
252
211
  if (typeof x === 'number' && typeof y === 'number') {
253
212
  ctx.lineTo(x, y);
254
213
  }
255
-
256
214
  ctx.lineTo.apply(ctx, _toConsumableArray(startPos));
257
215
  ctx.strokeStyle = '#f32d37';
258
216
  ctx.lineWidth = 2;
259
217
  ctx.fillStyle = 'rgba(243,45,55,0.5)';
260
218
  ctx.fill();
261
219
  ctx.stroke();
262
- }; //绘制hook
263
-
220
+ };
264
221
 
222
+ //绘制hook
265
223
  useEffect(function () {
266
224
  clearCanvas();
267
225
  drawSavaArea(state.saveArea);
268
- canvasRendering(state.pos, state.tempPos); // eslint-disable-next-line react-hooks/exhaustive-deps
226
+ canvasRendering(state.pos, state.tempPos);
227
+ // eslint-disable-next-line react-hooks/exhaustive-deps
269
228
  }, [state.pos, state.saveArea, state.tempPos]);
270
229
  var status = useMemo(function () {
271
230
  return state.isOpen ? 'open' : 'close';
272
231
  }, [state.isOpen]);
273
-
274
232
  var open = function open() {
275
233
  return setState(function (old) {
276
234
  return _objectSpread(_objectSpread({}, old), {}, {
@@ -278,7 +236,6 @@ function useDrawROI(target, _ref) {
278
236
  });
279
237
  });
280
238
  };
281
-
282
239
  var close = function close() {
283
240
  return setState(function (old) {
284
241
  return _objectSpread(_objectSpread({}, old), {}, {
@@ -286,7 +243,6 @@ function useDrawROI(target, _ref) {
286
243
  });
287
244
  });
288
245
  };
289
-
290
246
  var clear = function clear() {
291
247
  return setState(function (old) {
292
248
  return _objectSpread(_objectSpread({}, old), {}, {
@@ -295,9 +251,9 @@ function useDrawROI(target, _ref) {
295
251
  tempPos: []
296
252
  });
297
253
  });
298
- }; //快捷键处理
299
-
254
+ };
300
255
 
256
+ //快捷键处理
301
257
  useHotkeys('esc', function () {
302
258
  return setState(function (old) {
303
259
  return _objectSpread(_objectSpread({}, old), {}, {
@@ -309,48 +265,40 @@ function useDrawROI(target, _ref) {
309
265
  var rio = useMemo(function () {
310
266
  var rioArr = [];
311
267
  var canvas = getTargetElement(target);
312
-
313
268
  if (!canvas) {
314
269
  rioArr = new Array(row).fill(new Array(rowItems).fill(0));
315
270
  return rioArr;
316
271
  }
317
-
318
272
  var _canvas$getBoundingCl = canvas.getBoundingClientRect(),
319
- width = _canvas$getBoundingCl.width,
320
- height = _canvas$getBoundingCl.height;
321
-
273
+ width = _canvas$getBoundingCl.width,
274
+ height = _canvas$getBoundingCl.height;
322
275
  var itemWidth = width / rowItems;
323
- var itemHeight = height / row; // 转换当前绘制完成的区域为多边形
276
+ var itemHeight = height / row;
324
277
 
278
+ // 转换当前绘制完成的区域为多边形
325
279
  var areas = state.saveArea.map(function (item) {
326
280
  return lineToPolygon(lineString(item));
327
281
  });
328
-
329
282
  for (var i = 0; i < row; i++) {
330
283
  var arr = [];
331
-
332
- var _loop = function _loop(k) {
284
+ var _loop = function _loop() {
333
285
  // x表示当地的纬度,y表示当地的经度
334
- var lines = lineString([[k * itemWidth, i * itemHeight], [(k + 1) * itemWidth, i * itemHeight], [(k + 1) * itemWidth, (i + 1) * itemHeight], [k * itemWidth, (i + 1) * itemHeight], [k * itemWidth, i * itemHeight]]); // 转换每格为多边形
335
-
336
- var rect = lineToPolygon(lines); //标记当前rect 是否与绘制的图形相交
337
-
286
+ var lines = lineString([[k * itemWidth, i * itemHeight], [(k + 1) * itemWidth, i * itemHeight], [(k + 1) * itemWidth, (i + 1) * itemHeight], [k * itemWidth, (i + 1) * itemHeight], [k * itemWidth, i * itemHeight]]);
287
+ // 转换每格为多边形
288
+ var rect = lineToPolygon(lines);
289
+ //标记当前rect 是否与绘制的图形相交
338
290
  var flag = areas.findIndex(function (area) {
339
291
  return !booleanDisjoint(rect, area);
340
292
  }) > -1;
341
293
  arr.push(flag ? 1 : 0);
342
294
  };
343
-
344
295
  for (var k = 0; k < rowItems; k++) {
345
- _loop(k);
296
+ _loop();
346
297
  }
347
-
348
298
  rioArr.push(arr);
349
299
  }
350
-
351
300
  return rioArr;
352
301
  }, [row, rowItems, state.saveArea, target]);
353
-
354
302
  var deleteArea = function deleteArea(area) {
355
303
  setState(function (old) {
356
304
  var newArea = old.saveArea.filter(function (v) {
@@ -361,7 +309,6 @@ function useDrawROI(target, _ref) {
361
309
  });
362
310
  });
363
311
  };
364
-
365
312
  return {
366
313
  open: open,
367
314
  close: close,
@@ -372,5 +319,4 @@ function useDrawROI(target, _ref) {
372
319
  deleteArea: deleteArea
373
320
  };
374
321
  }
375
-
376
322
  export default useDrawROI;