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,74 @@
1
+ /* eslint-disable prefer-promise-reject-errors */
2
+ // 历史原因, 不修改
3
+
4
+ // @ts-ignore
5
+
6
+ export var responseInterceptorOnSuccess = function responseInterceptorOnSuccess(response) {
7
+ var _response$headers;
8
+ var data = response.data;
9
+ try {
10
+ if (data instanceof Blob) {
11
+ var contentD = response.headers['content-disposition'];
12
+ var realFileName = contentD.split('filename=')[1];
13
+ return {
14
+ success: true,
15
+ data: {
16
+ file: data,
17
+ fileName: realFileName
18
+ }
19
+ };
20
+ }
21
+ } catch (e) {
22
+ console.error(e);
23
+ }
24
+ if (((_response$headers = response.headers) === null || _response$headers === void 0 ? void 0 : _response$headers['content-type'].indexOf('application/json')) < 0) {
25
+ return data;
26
+ }
27
+ return data;
28
+ };
29
+ export var responseInterceptorOnError = function responseInterceptorOnError(error) {
30
+ var defaultMessage = '网络错误 稍后再试';
31
+ if (error.__CANCEL__) {
32
+ return;
33
+ }
34
+ if (error) {
35
+ if (error.response && error.response.data) {
36
+ var _error$response$data$ = error.response.data.errors,
37
+ errors = _error$response$data$ === void 0 ? [] : _error$response$data$;
38
+ var errorObj = errors && errors[0] || {};
39
+ return Promise.reject({
40
+ message: errorObj.message || error.message || defaultMessage,
41
+ arguments: errorObj.arguments || undefined,
42
+ code: errorObj.code || null
43
+ });
44
+ }
45
+ return Promise.reject({
46
+ message: error.message || defaultMessage,
47
+ arguments: undefined,
48
+ code: null
49
+ });
50
+ }
51
+ return Promise.reject({
52
+ message: defaultMessage,
53
+ arguments: undefined,
54
+ code: null
55
+ });
56
+ };
57
+ export var responseInterceptorUse = function responseInterceptorUse(axiosClient, responseInterceptorOnSuccessCallback, responseInterceptorOnErrorCallback) {
58
+ // 添加外部响应成功拦截器
59
+ if (responseInterceptorOnSuccessCallback) {
60
+ axiosClient.interceptors.response.use(function (response) {
61
+ return responseInterceptorOnSuccessCallback(response);
62
+ }, function (error) {
63
+ return Promise.reject(error);
64
+ });
65
+ }
66
+ // 添加外部响应失败拦截器
67
+ if (responseInterceptorOnSuccessCallback) {
68
+ axiosClient.interceptors.response.use(function (response) {
69
+ return response;
70
+ }, responseInterceptorOnErrorCallback);
71
+ }
72
+ // 添加响应拦截器
73
+ axiosClient.interceptors.response.use(responseInterceptorOnSuccess, responseInterceptorOnError);
74
+ };
@@ -0,0 +1,15 @@
1
+ interface Window {
2
+ skynet: any;
3
+ __debug__?: boolean;
4
+ __env__: {
5
+ debug?: boolean;
6
+ localDeploy: {
7
+ transformMethod: boolean;
8
+ };
9
+ request?: {
10
+ gzip?: boolean;
11
+ gzipThresholdSize?: number;
12
+ base64?: boolean;
13
+ };
14
+ };
15
+ }
@@ -0,0 +1,4 @@
1
+ export declare const deepTrimData: (data: any) => any;
2
+ export declare function isDebug(): boolean | undefined;
3
+ export declare function base64ToBytes(base64: string): Uint8Array;
4
+ export declare function bytesToBase64(bytes: Uint8Array): string;
@@ -0,0 +1,40 @@
1
+ import { isArray, isBoolean, isNull, isObject, isString, isUndefined } from 'lodash-es';
2
+ // 深度去除数据的空格
3
+ export var deepTrimData = function deepTrimData(data) {
4
+ if (isUndefined(data) || isNull(data) || isBoolean(data)) return data;
5
+ if (isArray(data)) {
6
+ return data.map(function (item) {
7
+ return deepTrimData(item);
8
+ });
9
+ } else if (isObject(data)) {
10
+ var obj = Object.create(null);
11
+ Object.keys(data).forEach(function (key) {
12
+ // @ts-ignore
13
+ obj[key] = deepTrimData(data[key]);
14
+ });
15
+ return obj;
16
+ } else if (isString(data)) {
17
+ return data.trim();
18
+ } else {
19
+ return data;
20
+ }
21
+ };
22
+ export function isDebug() {
23
+ if (typeof window === 'undefined') {
24
+ return false;
25
+ }
26
+ return window && window.__debug__;
27
+ }
28
+ export function base64ToBytes(base64) {
29
+ var binString = atob(base64);
30
+ // @ts-ignore
31
+ return Uint8Array.from(binString, function (m) {
32
+ return m.codePointAt(0);
33
+ });
34
+ }
35
+ export function bytesToBase64(bytes) {
36
+ var binString = Array.from(bytes, function (byte) {
37
+ return String.fromCodePoint(byte);
38
+ }).join('');
39
+ return btoa(binString);
40
+ }
@@ -0,0 +1,3 @@
1
+ import { TargetRef } from './interface';
2
+ declare const useInView: (options?: IntersectionObserverInit, triggerOnce?: boolean) => [TargetRef, boolean];
3
+ export default useInView;
@@ -0,0 +1,44 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
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."); }
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 _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(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { useEffect, useRef, useState } from 'react';
8
+ var useInView = function useInView() {
9
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
10
+ root: null,
11
+ rootMargin: '0px',
12
+ threshold: 1
13
+ };
14
+ var triggerOnce = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
15
+ var _useState = useState(false),
16
+ _useState2 = _slicedToArray(_useState, 2),
17
+ inView = _useState2[0],
18
+ setInView = _useState2[1];
19
+ var targetRef = useRef(null);
20
+ useEffect(function () {
21
+ var observer = new IntersectionObserver(function (entries) {
22
+ entries.forEach(function (entry) {
23
+ if (entry.isIntersecting) {
24
+ setInView(true);
25
+ if (triggerOnce) {
26
+ observer.unobserve(entry.target);
27
+ }
28
+ } else {
29
+ setInView(false);
30
+ }
31
+ });
32
+ }, options);
33
+ if (targetRef !== null && targetRef !== void 0 && targetRef.current) {
34
+ observer.observe(targetRef.current);
35
+ }
36
+ return function () {
37
+ if (targetRef !== null && targetRef !== void 0 && targetRef.current) {
38
+ observer.unobserve(targetRef.current);
39
+ }
40
+ };
41
+ }, [options, triggerOnce]);
42
+ return [targetRef, inView];
43
+ };
44
+ export default useInView;
@@ -0,0 +1,2 @@
1
+ import type { MutableRefObject } from 'react';
2
+ export type TargetRef = MutableRefObject<HTMLElement | null>;
@@ -0,0 +1,26 @@
1
+ /// <reference types="react" />
2
+ interface UseInfiniteScrollProps<T> {
3
+ dataSource?: T[];
4
+ delay?: number;
5
+ pageSize?: number;
6
+ fetchData?: (params: {
7
+ pageSize: number;
8
+ pageNum: number;
9
+ }) => Promise<{
10
+ total?: number;
11
+ list?: T[];
12
+ }>;
13
+ }
14
+ /**
15
+ * 无限滚动 Hook
16
+ * @param param
17
+ * @returns
18
+ */
19
+ export default function useInfiniteScroll<T = any>({ dataSource, delay, pageSize, fetchData, }: UseInfiniteScrollProps<T>): {
20
+ data: T[];
21
+ setData: import("react").Dispatch<import("react").SetStateAction<T[]>>;
22
+ loading: boolean;
23
+ hasMore: boolean;
24
+ loadMore: () => Promise<void>;
25
+ };
26
+ export {};
@@ -0,0 +1,111 @@
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 _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
+ 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."); }
7
+ 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); }
8
+ 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; }
9
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
+ import { useState } from 'react';
12
+ /**
13
+ * 无限滚动 Hook
14
+ * @param param
15
+ * @returns
16
+ */
17
+ export default function useInfiniteScroll(_ref) {
18
+ var dataSource = _ref.dataSource,
19
+ _ref$delay = _ref.delay,
20
+ delay = _ref$delay === void 0 ? 100 : _ref$delay,
21
+ _ref$pageSize = _ref.pageSize,
22
+ pageSize = _ref$pageSize === void 0 ? 10 : _ref$pageSize,
23
+ fetchData = _ref.fetchData;
24
+ var _useState = useState(false),
25
+ _useState2 = _slicedToArray(_useState, 2),
26
+ loading = _useState2[0],
27
+ setLoading = _useState2[1]; // 加载状态
28
+ var _useState3 = useState(true),
29
+ _useState4 = _slicedToArray(_useState3, 2),
30
+ hasMore = _useState4[0],
31
+ setHasMore = _useState4[1]; // 是否还有更多数据
32
+ var _useState5 = useState([]),
33
+ _useState6 = _slicedToArray(_useState5, 2),
34
+ data = _useState6[0],
35
+ setData = _useState6[1]; // 当前已加载的数据列表
36
+ function loadMore() {
37
+ return _loadMore.apply(this, arguments);
38
+ }
39
+ function _loadMore() {
40
+ _loadMore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
41
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
42
+ while (1) switch (_context.prev = _context.next) {
43
+ case 0:
44
+ if (!(!(dataSource !== null && dataSource !== void 0 && dataSource.length) && !fetchData)) {
45
+ _context.next = 2;
46
+ break;
47
+ }
48
+ return _context.abrupt("return");
49
+ case 2:
50
+ if (!(!hasMore || loading)) {
51
+ _context.next = 4;
52
+ break;
53
+ }
54
+ return _context.abrupt("return");
55
+ case 4:
56
+ setLoading(true);
57
+ if (!dataSource) {
58
+ _context.next = 10;
59
+ break;
60
+ }
61
+ _context.next = 8;
62
+ return new Promise(function (resolve) {
63
+ setTimeout(function () {
64
+ resolve(dataSource === null || dataSource === void 0 ? void 0 : dataSource.slice(data.length, data.length + pageSize));
65
+ }, delay);
66
+ }).then(function (list) {
67
+ setHasMore((data === null || data === void 0 ? void 0 : data.length) + (list === null || list === void 0 ? void 0 : list.length) < (dataSource === null || dataSource === void 0 ? void 0 : dataSource.length));
68
+ setData(function (value) {
69
+ return value === null || value === void 0 ? void 0 : value.concat(list);
70
+ });
71
+ });
72
+ case 8:
73
+ _context.next = 12;
74
+ break;
75
+ case 10:
76
+ _context.next = 12;
77
+ return fetchData === null || fetchData === void 0 ? void 0 : fetchData({
78
+ pageNum: data !== null && data !== void 0 && data.length ? Math.ceil((data === null || data === void 0 ? void 0 : data.length) / pageSize) + 1 : 1,
79
+ pageSize: pageSize
80
+ }).then(function (_ref2) {
81
+ var _ref2$list = _ref2.list,
82
+ list = _ref2$list === void 0 ? [] : _ref2$list,
83
+ _ref2$total = _ref2.total,
84
+ total = _ref2$total === void 0 ? 0 : _ref2$total;
85
+ setHasMore((data === null || data === void 0 ? void 0 : data.length) + (list === null || list === void 0 ? void 0 : list.length) < total && (list === null || list === void 0 ? void 0 : list.length) > 0);
86
+ setData(function (value) {
87
+ return value === null || value === void 0 ? void 0 : value.concat(list);
88
+ });
89
+ });
90
+ case 12:
91
+ setLoading(false);
92
+ case 13:
93
+ case "end":
94
+ return _context.stop();
95
+ }
96
+ }, _callee);
97
+ }));
98
+ return _loadMore.apply(this, arguments);
99
+ }
100
+ return {
101
+ data: data,
102
+ // 当前已加载的数据
103
+ setData: setData,
104
+ // 操作data
105
+ loading: loading,
106
+ // 加载状态
107
+ hasMore: hasMore,
108
+ // 是否还有更多数据
109
+ loadMore: loadMore // 加载更多数据的函数
110
+ };
111
+ }
@@ -0,0 +1,2 @@
1
+ declare const usePrevious: (value: any) => {};
2
+ export default usePrevious;
@@ -0,0 +1,14 @@
1
+ import { useLayoutEffect, useRef } from 'react';
2
+ var usePrevious = function usePrevious(value) {
3
+ var ref = useRef({});
4
+ useLayoutEffect(function () {
5
+ ref.current = value;
6
+ });
7
+ useLayoutEffect(function () {
8
+ return function () {
9
+ ref.current = {};
10
+ };
11
+ }, []);
12
+ return ref.current;
13
+ };
14
+ export default usePrevious;
@@ -0,0 +1,2 @@
1
+ declare const useResizeObserver: (containerRef: any, cb: ResizeObserverCallback, options?: ResizeObserverOptions) => void;
2
+ export default useResizeObserver;
@@ -0,0 +1,19 @@
1
+ import { defaultOptions } from "../../utils/defaults";
2
+ import { useEffect } from 'react';
3
+ var useResizeObserver = function useResizeObserver(containerRef, cb) {
4
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultOptions;
5
+ useEffect(function () {
6
+ var ob = new ResizeObserver(cb);
7
+ if (containerRef !== null && containerRef !== void 0 && containerRef.current) {
8
+ ob.observe(containerRef.current, options);
9
+ }
10
+ // 清除观察器
11
+ return function () {
12
+ if (containerRef !== null && containerRef !== void 0 && containerRef.current) {
13
+ ob.unobserve(containerRef.current);
14
+ }
15
+ ob.disconnect();
16
+ };
17
+ }, []);
18
+ };
19
+ export default useResizeObserver;
@@ -0,0 +1,2 @@
1
+ export * from './canvas';
2
+ export * from './hooks';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./canvas";
2
+ export * from "./hooks";
@@ -0,0 +1 @@
1
+ export declare const defaultOptions: {};
@@ -0,0 +1 @@
1
+ export var defaultOptions = {};
@@ -0,0 +1,14 @@
1
+ import type { Fn } from './types';
2
+ export declare function isFunction<T extends Fn>(val: any): val is T;
3
+ export declare const isDef: <T = any>(val?: T | undefined) => val is T;
4
+ export declare function isUndef(value: unknown): value is undefined;
5
+ export declare const isBoolean: (val: any) => val is boolean;
6
+ export declare const isNumber: (val: any) => val is number;
7
+ export declare function isString(val: unknown): val is string;
8
+ export declare function isObject(val: any): val is object;
9
+ export declare const isDev: boolean;
10
+ export declare const isBrowser: boolean;
11
+ export declare const isNavigator: boolean;
12
+ export declare function noop(): void;
13
+ export declare const isIOS: boolean | "";
14
+ export declare const isReactLegacy = false;
@@ -0,0 +1,31 @@
1
+ var _window;
2
+ import React from 'react';
3
+ var toString = Object.prototype.toString;
4
+ export function isFunction(val) {
5
+ return typeof val === 'function';
6
+ }
7
+ export var isDef = function isDef(val) {
8
+ return typeof val !== 'undefined';
9
+ };
10
+ export function isUndef(value) {
11
+ return typeof value === 'undefined';
12
+ }
13
+ export var isBoolean = function isBoolean(val) {
14
+ return typeof val === 'boolean';
15
+ };
16
+ export var isNumber = function isNumber(val) {
17
+ return typeof val === 'number';
18
+ };
19
+ export function isString(val) {
20
+ return typeof val === 'string';
21
+ }
22
+ export function isObject(val) {
23
+ return toString.call(val) === '[object Object]';
24
+ }
25
+ export var isDev = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test';
26
+ export var isBrowser = typeof window !== 'undefined';
27
+ export var isNavigator = typeof navigator !== 'undefined';
28
+ export function noop() {}
29
+ export var isIOS
30
+ /* #__PURE__ */ = isBrowser && ((_window = window) === null || _window === void 0 || (_window = _window.navigator) === null || _window === void 0 ? void 0 : _window.userAgent) && /iP(?:ad|hone|od)/.test(window.navigator.userAgent);
31
+ export var isReactLegacy = !React.useId;
@@ -0,0 +1 @@
1
+ export type Fn = (this: any, ...args: any[]) => any;
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,90 @@
1
+ {
2
+ "name": "heitu",
3
+ "version": "1.0.2",
4
+ "description": "diy hook canvas component",
5
+ "module": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "start": "npm run dev",
9
+ "dev": "dumi dev",
10
+ "build": "father build",
11
+ "build:watch": "father dev",
12
+ "docs:build": "dumi build",
13
+ "docs:preview": "dumi preview",
14
+ "deploy": "gh-pages -d dist",
15
+ "prepare": "husky install && dumi setup",
16
+ "doctor": "father doctor",
17
+ "lint": "npm run lint:es && npm run lint:css",
18
+ "lint:css": "stylelint \"{src,test}/**/*.{css,less}\"",
19
+ "lint:es": "eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
20
+ "prepublishOnly": "father doctor && npm run build"
21
+ },
22
+ "authors": [
23
+ "peco"
24
+ ],
25
+ "license": "MIT",
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "commitlint": {
30
+ "extends": [
31
+ "@commitlint/config-conventional"
32
+ ]
33
+ },
34
+ "lint-staged": {
35
+ "*.{md,json}": [
36
+ "prettier --write --no-error-on-unmatched-pattern"
37
+ ],
38
+ "*.{css,less}": [
39
+ "stylelint --fix",
40
+ "prettier --write"
41
+ ],
42
+ "*.{js,jsx}": [
43
+ "eslint --fix",
44
+ "prettier --write"
45
+ ],
46
+ "*.{ts,tsx}": [
47
+ "eslint --fix",
48
+ "prettier --parser=typescript --write"
49
+ ]
50
+ },
51
+ "publishConfig": {
52
+ "access": "public"
53
+ },
54
+ "peerDependencies": {
55
+ "react": ">=16.9.0",
56
+ "react-dom": ">=16.9.0"
57
+ },
58
+ "devDependencies": {
59
+ "@commitlint/cli": "^17.1.2",
60
+ "@commitlint/config-conventional": "^17.1.0",
61
+ "@types/react": "^18.0.0",
62
+ "@types/react-dom": "^18.0.0",
63
+ "@umijs/lint": "^4.0.0",
64
+ "dumi": "^2.3.0",
65
+ "eslint": "^8.23.0",
66
+ "father": "^4.1.0",
67
+ "gh-pages": "^6.1.1",
68
+ "husky": "^8.0.1",
69
+ "lint-staged": "^13.0.3",
70
+ "prettier": "^2.7.1",
71
+ "prettier-plugin-organize-imports": "^3.0.0",
72
+ "prettier-plugin-packagejson": "^2.2.18",
73
+ "react": "^18.0.0",
74
+ "react-dom": "^18.0.0",
75
+ "stylelint": "^14.9.1"
76
+ },
77
+ "dependencies": {
78
+ "@types/js-cookie": "^3.0.6",
79
+ "@types/lodash-es": "^4.17.12",
80
+ "@types/qs": "^6.9.15",
81
+ "@types/urijs": "^1.19.25",
82
+ "antd": "^5.20.1",
83
+ "axios": "^1.7.2",
84
+ "fflate": "^0.8.2",
85
+ "js-cookie": "^3.0.5",
86
+ "lodash-es": "^4.17.21",
87
+ "qs": "^6.13.0",
88
+ "urijs": "^1.19.11"
89
+ }
90
+ }