@ray-js/framework-shared 1.4.1 → 1.4.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 (58) hide show
  1. package/lib/emitter/index.android.js +1 -0
  2. package/lib/emitter/index.ios.js +1 -0
  3. package/lib/emitter/index.tuya.js +57 -0
  4. package/lib/emitter/index.web.js +57 -0
  5. package/lib/emitter/index.wechat.js +57 -0
  6. package/lib/filterProps/index.android.js +1 -0
  7. package/lib/filterProps/index.ios.js +1 -0
  8. package/lib/filterProps/index.tuya.js +30 -0
  9. package/lib/filterProps/index.web.js +30 -0
  10. package/lib/filterProps/index.wechat.js +30 -0
  11. package/lib/index.android.js +1 -0
  12. package/lib/index.ios.js +1 -0
  13. package/lib/index.tuya.js +9 -0
  14. package/lib/index.web.js +9 -0
  15. package/lib/index.wechat.js +9 -0
  16. package/lib/inlineStyle/CSSProperty.android.js +1 -0
  17. package/lib/inlineStyle/CSSProperty.ios.js +1 -0
  18. package/lib/inlineStyle/CSSProperty.tuya.js +78 -0
  19. package/lib/inlineStyle/CSSProperty.web.js +78 -0
  20. package/lib/inlineStyle/CSSProperty.wechat.js +78 -0
  21. package/lib/inlineStyle/index.android.js +1 -0
  22. package/lib/inlineStyle/index.ios.js +1 -0
  23. package/lib/inlineStyle/index.tuya.js +49 -0
  24. package/lib/inlineStyle/index.web.js +49 -0
  25. package/lib/inlineStyle/index.wechat.js +49 -0
  26. package/lib/plainStyle/index.android.js +1 -0
  27. package/lib/plainStyle/index.ios.js +1 -0
  28. package/lib/plainStyle/index.tuya.js +52 -0
  29. package/lib/plainStyle/index.web.js +52 -0
  30. package/lib/plainStyle/index.wechat.js +52 -0
  31. package/lib/useInterval/index.android.js +1 -0
  32. package/lib/useInterval/index.ios.js +1 -0
  33. package/lib/useInterval/index.tuya.js +24 -0
  34. package/lib/useInterval/index.web.js +24 -0
  35. package/lib/useInterval/index.wechat.js +24 -0
  36. package/lib/useStylesheet/index.android.js +1 -0
  37. package/lib/useStylesheet/index.ios.js +1 -0
  38. package/lib/useStylesheet/index.tuya.js +24 -0
  39. package/lib/useStylesheet/index.web.js +24 -0
  40. package/lib/useStylesheet/index.wechat.js +24 -0
  41. package/lib/useThrottle/index.android.js +1 -0
  42. package/lib/useThrottle/index.ios.js +1 -0
  43. package/lib/useThrottle/index.tuya.js +36 -0
  44. package/lib/useThrottle/index.web.js +36 -0
  45. package/lib/useThrottle/index.wechat.js +36 -0
  46. package/lib/useTouch/index.android.js +1 -0
  47. package/lib/useTouch/index.d.ts +43 -0
  48. package/lib/useTouch/index.ios.js +1 -0
  49. package/lib/useTouch/index.tuya.js +125 -0
  50. package/lib/useTouch/index.web.js +137 -0
  51. package/lib/useTouch/index.wechat.js +125 -0
  52. package/lib/useTransition/index.android.js +1 -0
  53. package/lib/useTransition/index.ios.js +1 -0
  54. package/lib/useTransition/index.tuya.js +53 -0
  55. package/lib/useTransition/index.web.js +53 -0
  56. package/lib/useTransition/index.wechat.js +53 -0
  57. package/package.json +5 -5
  58. package/LICENSE.md +0 -9
@@ -0,0 +1,125 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import "core-js/modules/es.array.filter.js";
4
+ import "core-js/modules/es.object.to-string.js";
5
+ import "core-js/modules/es.array.map.js";
6
+ import "core-js/modules/web.dom-collections.for-each.js";
7
+ import * as React from 'react';
8
+ var isMiniProgram = true;
9
+ var isWechat = false;
10
+ var isWeb = false;
11
+ var LONG_TAP_DURATION = 350;
12
+ export function useTouch(_ref) {
13
+ var hoverDuration = _ref.hoverDuration,
14
+ hoverDelay = _ref.hoverDelay,
15
+ onLongClick = _ref.onLongClick,
16
+ onTouchCancel = _ref.onTouchCancel,
17
+ onTouchEnd = _ref.onTouchEnd,
18
+ onTouchMove = _ref.onTouchMove,
19
+ onTouchStart = _ref.onTouchStart,
20
+ onClick = _ref.onClick;
21
+
22
+ var _React$useState = React.useState(false),
23
+ _React$useState2 = _slicedToArray(_React$useState, 2),
24
+ touching = _React$useState2[0],
25
+ setTouching = _React$useState2[1];
26
+
27
+ var hoveringRef = React.useRef(false);
28
+ var timers = React.useRef([]);
29
+
30
+ function executeTimeout(callback, time) {
31
+ var timer = setTimeout(function () {
32
+ callback();
33
+ timers.current.filter(function (t) {
34
+ return t !== timer;
35
+ });
36
+ }, time);
37
+ timers.current.push(timer);
38
+ }
39
+
40
+ function formatTouches(touchs) {
41
+ if (Array.isArray(touchs)) {
42
+ return touchs && touchs.map(function (item) {
43
+ return {
44
+ identifier: item.identifier,
45
+ pageX: item.pageX,
46
+ pageY: item.pageY
47
+ };
48
+ });
49
+ } else {
50
+ return [_objectSpread({}, touchs)];
51
+ }
52
+ }
53
+
54
+ function formatRayEvent(e, touchType) {
55
+ return {
56
+ type: (e === null || e === void 0 ? void 0 : e.type) || touchType || '',
57
+ touches: formatTouches(e.touches),
58
+ changedTouches: formatTouches(e.changedTouches),
59
+ timeStamp: e.timeStamp || e.timestamp,
60
+ origin: e
61
+ };
62
+ }
63
+
64
+ function formatRayClickEvent(e, clickType) {
65
+ return {
66
+ type: (e === null || e === void 0 ? void 0 : e.type) || clickType || '',
67
+ timeStamp: e.timeStamp,
68
+ pageX: e.pageX,
69
+ pageY: e.pageY,
70
+ origin: e
71
+ };
72
+ }
73
+
74
+ React.useEffect(function () {
75
+ return function () {
76
+ timers.current.forEach(function (t) {
77
+ return clearTimeout(t);
78
+ });
79
+ };
80
+ }, []);
81
+ return [touching, {
82
+ onTouchStart: function (e) {
83
+ hoveringRef.current = true;
84
+ executeTimeout(function () {
85
+ if (hoveringRef.current) {
86
+ setTouching(true);
87
+ }
88
+ }, hoverDelay);
89
+ return onTouchStart === null || onTouchStart === void 0 ? void 0 : onTouchStart(formatRayEvent(e, 'touchstart'));
90
+ },
91
+ onTouchMove: function (e) {
92
+ hoveringRef.current = false;
93
+ executeTimeout(function () {
94
+ if (touching) {
95
+ setTouching(false);
96
+ }
97
+ }, hoverDuration);
98
+ return onTouchMove === null || onTouchMove === void 0 ? void 0 : onTouchMove(formatRayEvent(e, 'touchmove'));
99
+ },
100
+ onTouchEnd: function (e) {
101
+ hoveringRef.current = false;
102
+ executeTimeout(function () {
103
+ if (touching) {
104
+ setTouching(false);
105
+ }
106
+ }, hoverDuration);
107
+ return onTouchEnd === null || onTouchEnd === void 0 ? void 0 : onTouchEnd(formatRayEvent(e, 'touchend'));
108
+ },
109
+ onTouchCancel: function (e) {
110
+ hoveringRef.current = false;
111
+ executeTimeout(function () {
112
+ if (touching) {
113
+ setTouching(false);
114
+ }
115
+ }, hoverDuration);
116
+ return onTouchCancel === null || onTouchCancel === void 0 ? void 0 : onTouchCancel(formatRayEvent(e, 'touchcancel'));
117
+ },
118
+ onClick: function (e) {
119
+ return onClick === null || onClick === void 0 ? void 0 : onClick(formatRayClickEvent(e, 'click'));
120
+ },
121
+ onLongClick: function (e) {
122
+ return onLongClick === null || onLongClick === void 0 ? void 0 : onLongClick(formatRayClickEvent(e, 'longclick'));
123
+ }
124
+ }];
125
+ }
@@ -0,0 +1,137 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import "core-js/modules/es.array.filter.js";
4
+ import "core-js/modules/es.object.to-string.js";
5
+ import "core-js/modules/es.array.map.js";
6
+ import "core-js/modules/web.dom-collections.for-each.js";
7
+ import * as React from 'react';
8
+ var isMiniProgram = false;
9
+ var isWechat = false;
10
+ var isWeb = true;
11
+ var LONG_TAP_DURATION = 350;
12
+ export function useTouch(_ref) {
13
+ var hoverDuration = _ref.hoverDuration,
14
+ hoverDelay = _ref.hoverDelay,
15
+ onLongClick = _ref.onLongClick,
16
+ onTouchCancel = _ref.onTouchCancel,
17
+ onTouchEnd = _ref.onTouchEnd,
18
+ onTouchMove = _ref.onTouchMove,
19
+ onTouchStart = _ref.onTouchStart,
20
+ onClick = _ref.onClick;
21
+
22
+ var _React$useState = React.useState(false),
23
+ _React$useState2 = _slicedToArray(_React$useState, 2),
24
+ touching = _React$useState2[0],
25
+ setTouching = _React$useState2[1];
26
+
27
+ var hoveringRef = React.useRef(false);
28
+ var timers = React.useRef([]);
29
+
30
+ function executeTimeout(callback, time) {
31
+ var timer = setTimeout(function () {
32
+ callback();
33
+ timers.current.filter(function (t) {
34
+ return t !== timer;
35
+ });
36
+ }, time);
37
+ timers.current.push(timer);
38
+ }
39
+
40
+ function formatTouches(touchs) {
41
+ if (Array.isArray(touchs)) {
42
+ return touchs && touchs.map(function (item) {
43
+ return {
44
+ identifier: item.identifier,
45
+ pageX: item.pageX,
46
+ pageY: item.pageY
47
+ };
48
+ });
49
+ } else {
50
+ return [_objectSpread({}, touchs)];
51
+ }
52
+ }
53
+
54
+ function formatRayEvent(e, touchType) {
55
+ return {
56
+ type: (e === null || e === void 0 ? void 0 : e.type) || touchType || '',
57
+ touches: formatTouches(e.touches),
58
+ changedTouches: formatTouches(e.changedTouches),
59
+ timeStamp: e.timeStamp || e.timestamp,
60
+ origin: e
61
+ };
62
+ }
63
+
64
+ function formatRayClickEvent(e, clickType) {
65
+ return {
66
+ type: (e === null || e === void 0 ? void 0 : e.type) || clickType || '',
67
+ timeStamp: e.timeStamp,
68
+ pageX: e.pageX,
69
+ pageY: e.pageY,
70
+ origin: e
71
+ };
72
+ }
73
+
74
+ React.useEffect(function () {
75
+ return function () {
76
+ timers.current.forEach(function (t) {
77
+ return clearTimeout(t);
78
+ });
79
+ };
80
+ }, []);
81
+
82
+ function handleLongClick(e) {
83
+ return onLongClick === null || onLongClick === void 0 ? void 0 : onLongClick(formatRayClickEvent(e, 'longclick'));
84
+ }
85
+
86
+ return [touching, {
87
+ onTouchStart: function (e) {
88
+ hoveringRef.current = true;
89
+ executeTimeout(function () {
90
+ if (hoveringRef.current) {
91
+ setTouching(true);
92
+ }
93
+ }, hoverDelay);
94
+
95
+ if (typeof onLongClick === 'function') {
96
+ executeTimeout(function () {
97
+ if (hoveringRef.current) {
98
+ handleLongClick(e);
99
+ }
100
+ }, LONG_TAP_DURATION);
101
+ }
102
+
103
+ return onTouchStart === null || onTouchStart === void 0 ? void 0 : onTouchStart(formatRayEvent(e, 'touchstart'));
104
+ },
105
+ onTouchMove: function (e) {
106
+ hoveringRef.current = false;
107
+ executeTimeout(function () {
108
+ if (touching) {
109
+ setTouching(false);
110
+ }
111
+ }, hoverDuration);
112
+ return onTouchMove === null || onTouchMove === void 0 ? void 0 : onTouchMove(formatRayEvent(e, 'touchmove'));
113
+ },
114
+ onTouchEnd: function (e) {
115
+ hoveringRef.current = false;
116
+ executeTimeout(function () {
117
+ if (touching) {
118
+ setTouching(false);
119
+ }
120
+ }, hoverDuration);
121
+ return onTouchEnd === null || onTouchEnd === void 0 ? void 0 : onTouchEnd(formatRayEvent(e, 'touchend'));
122
+ },
123
+ onTouchCancel: function (e) {
124
+ hoveringRef.current = false;
125
+ executeTimeout(function () {
126
+ if (touching) {
127
+ setTouching(false);
128
+ }
129
+ }, hoverDuration);
130
+ return onTouchCancel === null || onTouchCancel === void 0 ? void 0 : onTouchCancel(formatRayEvent(e, 'touchcancel'));
131
+ },
132
+ onClick: function (e) {
133
+ return onClick === null || onClick === void 0 ? void 0 : onClick(formatRayClickEvent(e, 'click'));
134
+ },
135
+ onLongClick: handleLongClick
136
+ }];
137
+ }
@@ -0,0 +1,125 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import "core-js/modules/es.array.filter.js";
4
+ import "core-js/modules/es.object.to-string.js";
5
+ import "core-js/modules/es.array.map.js";
6
+ import "core-js/modules/web.dom-collections.for-each.js";
7
+ import * as React from 'react';
8
+ var isMiniProgram = true;
9
+ var isWechat = true;
10
+ var isWeb = false;
11
+ var LONG_TAP_DURATION = 350;
12
+ export function useTouch(_ref) {
13
+ var hoverDuration = _ref.hoverDuration,
14
+ hoverDelay = _ref.hoverDelay,
15
+ onLongClick = _ref.onLongClick,
16
+ onTouchCancel = _ref.onTouchCancel,
17
+ onTouchEnd = _ref.onTouchEnd,
18
+ onTouchMove = _ref.onTouchMove,
19
+ onTouchStart = _ref.onTouchStart,
20
+ onClick = _ref.onClick;
21
+
22
+ var _React$useState = React.useState(false),
23
+ _React$useState2 = _slicedToArray(_React$useState, 2),
24
+ touching = _React$useState2[0],
25
+ setTouching = _React$useState2[1];
26
+
27
+ var hoveringRef = React.useRef(false);
28
+ var timers = React.useRef([]);
29
+
30
+ function executeTimeout(callback, time) {
31
+ var timer = setTimeout(function () {
32
+ callback();
33
+ timers.current.filter(function (t) {
34
+ return t !== timer;
35
+ });
36
+ }, time);
37
+ timers.current.push(timer);
38
+ }
39
+
40
+ function formatTouches(touchs) {
41
+ if (Array.isArray(touchs)) {
42
+ return touchs && touchs.map(function (item) {
43
+ return {
44
+ identifier: item.identifier,
45
+ pageX: item.pageX,
46
+ pageY: item.pageY
47
+ };
48
+ });
49
+ } else {
50
+ return [_objectSpread({}, touchs)];
51
+ }
52
+ }
53
+
54
+ function formatRayEvent(e, touchType) {
55
+ return {
56
+ type: (e === null || e === void 0 ? void 0 : e.type) || touchType || '',
57
+ touches: formatTouches(e.touches),
58
+ changedTouches: formatTouches(e.changedTouches),
59
+ timeStamp: e.timeStamp || e.timestamp,
60
+ origin: e
61
+ };
62
+ }
63
+
64
+ function formatRayClickEvent(e, clickType) {
65
+ return {
66
+ type: (e === null || e === void 0 ? void 0 : e.type) || clickType || '',
67
+ timeStamp: e.timeStamp,
68
+ pageX: e.pageX,
69
+ pageY: e.pageY,
70
+ origin: e
71
+ };
72
+ }
73
+
74
+ React.useEffect(function () {
75
+ return function () {
76
+ timers.current.forEach(function (t) {
77
+ return clearTimeout(t);
78
+ });
79
+ };
80
+ }, []);
81
+ return [touching, {
82
+ onTouchStart: function (e) {
83
+ hoveringRef.current = true;
84
+ executeTimeout(function () {
85
+ if (hoveringRef.current) {
86
+ setTouching(true);
87
+ }
88
+ }, hoverDelay);
89
+ return onTouchStart === null || onTouchStart === void 0 ? void 0 : onTouchStart(formatRayEvent(e, 'touchstart'));
90
+ },
91
+ onTouchMove: function (e) {
92
+ hoveringRef.current = false;
93
+ executeTimeout(function () {
94
+ if (touching) {
95
+ setTouching(false);
96
+ }
97
+ }, hoverDuration);
98
+ return onTouchMove === null || onTouchMove === void 0 ? void 0 : onTouchMove(formatRayEvent(e, 'touchmove'));
99
+ },
100
+ onTouchEnd: function (e) {
101
+ hoveringRef.current = false;
102
+ executeTimeout(function () {
103
+ if (touching) {
104
+ setTouching(false);
105
+ }
106
+ }, hoverDuration);
107
+ return onTouchEnd === null || onTouchEnd === void 0 ? void 0 : onTouchEnd(formatRayEvent(e, 'touchend'));
108
+ },
109
+ onTouchCancel: function (e) {
110
+ hoveringRef.current = false;
111
+ executeTimeout(function () {
112
+ if (touching) {
113
+ setTouching(false);
114
+ }
115
+ }, hoverDuration);
116
+ return onTouchCancel === null || onTouchCancel === void 0 ? void 0 : onTouchCancel(formatRayEvent(e, 'touchcancel'));
117
+ },
118
+ onClick: function (e) {
119
+ return onClick === null || onClick === void 0 ? void 0 : onClick(formatRayClickEvent(e, 'click'));
120
+ },
121
+ onLongClick: function (e) {
122
+ return onLongClick === null || onLongClick === void 0 ? void 0 : onLongClick(formatRayClickEvent(e, 'longclick'));
123
+ }
124
+ }];
125
+ }
@@ -0,0 +1 @@
1
+ var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.useTransition=useTransition;var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _react=require("react");var nextFrame=function(){var duration=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1000/30;return new Promise(function(resolve){return setTimeout(resolve,duration);});};function useTransition(options,deps){var _options$duration=options.duration,duration=_options$duration===void 0?200:_options$duration,onFinish=options.onFinish,onStart=options.onStart;var _deps=(0,_slicedToArray2.default)(deps,1),_deps$=_deps[0],visible=_deps$===void 0?false:_deps$;var showRef=(0,_react.useRef)(visible);var _useState=(0,_react.useState)(visible?'showComplete':'hideComplete'),_useState2=(0,_slicedToArray2.default)(_useState,2),status=_useState2[0],setStatus=_useState2[1];function updateShow(show){if(showRef.current===show)return false;showRef.current=show;onStart===null||onStart===void 0?void 0:onStart(showRef.current);setStatus(showRef.current?'showStart':'hideStart');nextFrame(duration).then(function(){setStatus(showRef.current?'showComplete':'hideComplete');onFinish===null||onFinish===void 0?void 0:onFinish(showRef.current);});}(0,_react.useEffect)(function(){updateShow(visible);},[visible]);return[status,{animationDuration:duration/1000+"s"},updateShow];}
@@ -0,0 +1 @@
1
+ var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.useTransition=useTransition;var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _react=require("react");var nextFrame=function(){var duration=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1000/30;return new Promise(function(resolve){return setTimeout(resolve,duration);});};function useTransition(options,deps){var _options$duration=options.duration,duration=_options$duration===void 0?200:_options$duration,onFinish=options.onFinish,onStart=options.onStart;var _deps=(0,_slicedToArray2.default)(deps,1),_deps$=_deps[0],visible=_deps$===void 0?false:_deps$;var showRef=(0,_react.useRef)(visible);var _useState=(0,_react.useState)(visible?'showComplete':'hideComplete'),_useState2=(0,_slicedToArray2.default)(_useState,2),status=_useState2[0],setStatus=_useState2[1];function updateShow(show){if(showRef.current===show)return false;showRef.current=show;onStart===null||onStart===void 0?void 0:onStart(showRef.current);setStatus(showRef.current?'showStart':'hideStart');nextFrame(duration).then(function(){setStatus(showRef.current?'showComplete':'hideComplete');onFinish===null||onFinish===void 0?void 0:onFinish(showRef.current);});}(0,_react.useEffect)(function(){updateShow(visible);},[visible]);return[status,{animationDuration:duration/1000+"s"},updateShow];}
@@ -0,0 +1,53 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import "core-js/modules/es.object.to-string.js";
3
+ import "core-js/modules/es.promise.js";
4
+ import { useEffect, useRef, useState } from 'react';
5
+
6
+ var nextFrame = function () {
7
+ var duration = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000 / 30;
8
+ return new Promise(function (resolve) {
9
+ return setTimeout(resolve, duration);
10
+ });
11
+ };
12
+ /**
13
+ * 用于执行动画的时序管理
14
+ * @param options transition 选项
15
+ * @param visible 是否可见
16
+ */
17
+
18
+
19
+ export function useTransition(options, deps) {
20
+ var _options$duration = options.duration,
21
+ duration = _options$duration === void 0 ? 200 : _options$duration,
22
+ onFinish = options.onFinish,
23
+ onStart = options.onStart;
24
+
25
+ var _deps = _slicedToArray(deps, 1),
26
+ _deps$ = _deps[0],
27
+ visible = _deps$ === void 0 ? false : _deps$;
28
+
29
+ var showRef = useRef(visible);
30
+
31
+ var _useState = useState(visible ? 'showComplete' : 'hideComplete'),
32
+ _useState2 = _slicedToArray(_useState, 2),
33
+ status = _useState2[0],
34
+ setStatus = _useState2[1];
35
+
36
+ function updateShow(show) {
37
+ if (showRef.current === show) return false;
38
+ showRef.current = show;
39
+ onStart === null || onStart === void 0 ? void 0 : onStart(showRef.current);
40
+ setStatus(showRef.current ? 'showStart' : 'hideStart');
41
+ nextFrame(duration).then(function () {
42
+ setStatus(showRef.current ? 'showComplete' : 'hideComplete');
43
+ onFinish === null || onFinish === void 0 ? void 0 : onFinish(showRef.current);
44
+ });
45
+ }
46
+
47
+ useEffect(function () {
48
+ updateShow(visible);
49
+ }, [visible]);
50
+ return [status, {
51
+ animationDuration: "".concat(duration / 1000, "s")
52
+ }, updateShow];
53
+ }
@@ -0,0 +1,53 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import "core-js/modules/es.object.to-string.js";
3
+ import "core-js/modules/es.promise.js";
4
+ import { useEffect, useRef, useState } from 'react';
5
+
6
+ var nextFrame = function () {
7
+ var duration = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000 / 30;
8
+ return new Promise(function (resolve) {
9
+ return setTimeout(resolve, duration);
10
+ });
11
+ };
12
+ /**
13
+ * 用于执行动画的时序管理
14
+ * @param options transition 选项
15
+ * @param visible 是否可见
16
+ */
17
+
18
+
19
+ export function useTransition(options, deps) {
20
+ var _options$duration = options.duration,
21
+ duration = _options$duration === void 0 ? 200 : _options$duration,
22
+ onFinish = options.onFinish,
23
+ onStart = options.onStart;
24
+
25
+ var _deps = _slicedToArray(deps, 1),
26
+ _deps$ = _deps[0],
27
+ visible = _deps$ === void 0 ? false : _deps$;
28
+
29
+ var showRef = useRef(visible);
30
+
31
+ var _useState = useState(visible ? 'showComplete' : 'hideComplete'),
32
+ _useState2 = _slicedToArray(_useState, 2),
33
+ status = _useState2[0],
34
+ setStatus = _useState2[1];
35
+
36
+ function updateShow(show) {
37
+ if (showRef.current === show) return false;
38
+ showRef.current = show;
39
+ onStart === null || onStart === void 0 ? void 0 : onStart(showRef.current);
40
+ setStatus(showRef.current ? 'showStart' : 'hideStart');
41
+ nextFrame(duration).then(function () {
42
+ setStatus(showRef.current ? 'showComplete' : 'hideComplete');
43
+ onFinish === null || onFinish === void 0 ? void 0 : onFinish(showRef.current);
44
+ });
45
+ }
46
+
47
+ useEffect(function () {
48
+ updateShow(visible);
49
+ }, [visible]);
50
+ return [status, {
51
+ animationDuration: "".concat(duration / 1000, "s")
52
+ }, updateShow];
53
+ }
@@ -0,0 +1,53 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import "core-js/modules/es.object.to-string.js";
3
+ import "core-js/modules/es.promise.js";
4
+ import { useEffect, useRef, useState } from 'react';
5
+
6
+ var nextFrame = function () {
7
+ var duration = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000 / 30;
8
+ return new Promise(function (resolve) {
9
+ return setTimeout(resolve, duration);
10
+ });
11
+ };
12
+ /**
13
+ * 用于执行动画的时序管理
14
+ * @param options transition 选项
15
+ * @param visible 是否可见
16
+ */
17
+
18
+
19
+ export function useTransition(options, deps) {
20
+ var _options$duration = options.duration,
21
+ duration = _options$duration === void 0 ? 200 : _options$duration,
22
+ onFinish = options.onFinish,
23
+ onStart = options.onStart;
24
+
25
+ var _deps = _slicedToArray(deps, 1),
26
+ _deps$ = _deps[0],
27
+ visible = _deps$ === void 0 ? false : _deps$;
28
+
29
+ var showRef = useRef(visible);
30
+
31
+ var _useState = useState(visible ? 'showComplete' : 'hideComplete'),
32
+ _useState2 = _slicedToArray(_useState, 2),
33
+ status = _useState2[0],
34
+ setStatus = _useState2[1];
35
+
36
+ function updateShow(show) {
37
+ if (showRef.current === show) return false;
38
+ showRef.current = show;
39
+ onStart === null || onStart === void 0 ? void 0 : onStart(showRef.current);
40
+ setStatus(showRef.current ? 'showStart' : 'hideStart');
41
+ nextFrame(duration).then(function () {
42
+ setStatus(showRef.current ? 'showComplete' : 'hideComplete');
43
+ onFinish === null || onFinish === void 0 ? void 0 : onFinish(showRef.current);
44
+ });
45
+ }
46
+
47
+ useEffect(function () {
48
+ updateShow(visible);
49
+ }, [visible]);
50
+ return [status, {
51
+ animationDuration: "".concat(duration / 1000, "s")
52
+ }, updateShow];
53
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/framework-shared",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
4
4
  "description": "Ray shared for framework",
5
5
  "keywords": [
6
6
  "ray"
@@ -24,16 +24,16 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@ray-core/wechat": "^0.3.6",
27
- "@ray-js/env": "^1.4.1",
28
- "@ray-js/types": "^1.4.1",
27
+ "@ray-js/env": "^1.4.3",
28
+ "@ray-js/types": "^1.4.3",
29
29
  "path-to-regexp": "^6.2.1"
30
30
  },
31
31
  "devDependencies": {
32
- "@ray-js/cli": "^1.4.1"
32
+ "@ray-js/cli": "^1.4.3"
33
33
  },
34
34
  "publishConfig": {
35
35
  "access": "public",
36
36
  "registry": "https://registry.npmjs.org"
37
37
  },
38
- "gitHead": "7c45027c91f744019b2b0f9ca76f2b65f6a2c857"
38
+ "gitHead": "14cb935df10f020e714b44bb41d4899646db751c"
39
39
  }
package/LICENSE.md DELETED
@@ -1,9 +0,0 @@
1
- Copyright © 2014-2022 Tuya.inc
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
-
7
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.