react-alp-loading-bar 3.1.3 → 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.
- package/.eslintrc.json +1 -1
- package/CHANGELOG.md +48 -0
- package/dist/index-browser.es.js +17 -31
- package/dist/index-browser.es.js.map +1 -1
- package/dist/index-browsermodern.es.js +23 -40
- package/dist/index-browsermodern.es.js.map +1 -1
- package/dist/{index-node12.mjs → index-node14.mjs} +24 -41
- package/dist/index-node14.mjs.map +1 -0
- package/dist/index.d.ts +6 -8
- package/dist/index.d.ts.map +1 -1
- package/package.json +28 -50
- package/rollup.config.mjs +5 -0
- package/src/.eslintrc.json +19 -2
- package/src/index.tsx +13 -15
- package/tsconfig.eslint.json +7 -0
- package/dist/index-browser-dev.cjs.js +0 -181
- package/dist/index-browser-dev.cjs.js.map +0 -1
- package/dist/index-browser-dev.es.js +0 -171
- package/dist/index-browser-dev.es.js.map +0 -1
- package/dist/index-browser.cjs.js +0 -181
- package/dist/index-browser.cjs.js.map +0 -1
- package/dist/index-browsermodern-dev.es.js +0 -147
- package/dist/index-browsermodern-dev.es.js.map +0 -1
- package/dist/index-node12-dev.cjs.js +0 -156
- package/dist/index-node12-dev.cjs.js.map +0 -1
- package/dist/index-node12-dev.mjs +0 -147
- package/dist/index-node12-dev.mjs.map +0 -1
- package/dist/index-node12.cjs.js +0 -156
- package/dist/index-node12.cjs.js.map +0 -1
- package/dist/index-node12.mjs.map +0 -1
- package/index.js +0 -6
package/.eslintrc.json
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,54 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [4.0.3](https://github.com/christophehurpeau/alp/compare/react-alp-loading-bar@4.0.2...react-alp-loading-bar@4.0.3) (2022-02-13)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* dont override react/react-in-jsx-scope ([5d21c9e](https://github.com/christophehurpeau/alp/commit/5d21c9ece092cd3397d1794211dae17cea6649f8))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [4.0.2](https://github.com/christophehurpeau/alp/compare/react-alp-loading-bar@4.0.1...react-alp-loading-bar@4.0.2) (2022-02-06)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package react-alp-loading-bar
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## [4.0.1](https://github.com/christophehurpeau/alp/compare/react-alp-loading-bar@4.0.0...react-alp-loading-bar@4.0.1) (2022-01-15)
|
|
26
|
+
|
|
27
|
+
**Note:** Version bump only for package react-alp-loading-bar
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# [4.0.0](https://github.com/christophehurpeau/alp/compare/react-alp-loading-bar@3.1.3...react-alp-loading-bar@4.0.0) (2022-01-02)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### Bug Fixes
|
|
37
|
+
|
|
38
|
+
* update nightingale and fix tests ([3691716](https://github.com/christophehurpeau/alp/commit/36917162d0ee3dccc07384caf018b7760d98b744))
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### Features
|
|
42
|
+
|
|
43
|
+
* use ESM and drop node 12 ([f45054e](https://github.com/christophehurpeau/alp/commit/f45054e931eea88451d183722797eba057511236))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
### BREAKING CHANGES
|
|
47
|
+
|
|
48
|
+
* requires node 14 and ESM
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
6
54
|
## [3.1.3](https://github.com/christophehurpeau/alp/compare/react-alp-loading-bar@3.1.2...react-alp-loading-bar@3.1.3) (2021-04-10)
|
|
7
55
|
|
|
8
56
|
**Note:** Version bump only for package react-alp-loading-bar
|
package/dist/index-browser.es.js
CHANGED
|
@@ -1,22 +1,7 @@
|
|
|
1
1
|
import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
|
|
2
|
-
import
|
|
2
|
+
import { PureComponent } from 'react';
|
|
3
3
|
import ReactAlpContext from 'react-alp-context';
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
Example with antd:
|
|
7
|
-
import { Progress } from 'antd';
|
|
8
|
-
|
|
9
|
-
const LoadingBarComponent = ({ progress }) => (
|
|
10
|
-
<Progress
|
|
11
|
-
type="line"
|
|
12
|
-
status="active"
|
|
13
|
-
percent={progress}
|
|
14
|
-
showInfo={false}
|
|
15
|
-
/>
|
|
16
|
-
);
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
/* number between 0 and 1 */
|
|
4
|
+
import { jsx } from 'react/jsx-runtime.js';
|
|
20
5
|
|
|
21
6
|
var random = function random() {
|
|
22
7
|
return Math.ceil(Math.random() * 100) / 100;
|
|
@@ -96,10 +81,10 @@ var LoadingBar = /*#__PURE__*/function (_PureComponent) {
|
|
|
96
81
|
};
|
|
97
82
|
|
|
98
83
|
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
99
|
-
clearTimeout(this.fadeOffTimeout);
|
|
100
|
-
clearTimeout(this.resetTimeout);
|
|
101
|
-
clearTimeout(this.first20Timeout);
|
|
102
|
-
clearInterval(this.progressTimer);
|
|
84
|
+
if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);
|
|
85
|
+
if (this.resetTimeout) clearTimeout(this.resetTimeout);
|
|
86
|
+
if (this.first20Timeout) clearTimeout(this.first20Timeout);
|
|
87
|
+
if (this.progressTimer) clearInterval(this.progressTimer);
|
|
103
88
|
};
|
|
104
89
|
|
|
105
90
|
_proto.getWebsocket = function getWebsocket() {
|
|
@@ -110,8 +95,8 @@ var LoadingBar = /*#__PURE__*/function (_PureComponent) {
|
|
|
110
95
|
_proto.showBar = function showBar() {
|
|
111
96
|
var _this3 = this;
|
|
112
97
|
|
|
113
|
-
clearTimeout(this.fadeOffTimeout);
|
|
114
|
-
clearTimeout(this.resetTimeout);
|
|
98
|
+
if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);
|
|
99
|
+
if (this.resetTimeout) clearTimeout(this.resetTimeout);
|
|
115
100
|
this.first20Timeout = setTimeout(function () {
|
|
116
101
|
_this3.setState({
|
|
117
102
|
progress: 20
|
|
@@ -130,8 +115,8 @@ var LoadingBar = /*#__PURE__*/function (_PureComponent) {
|
|
|
130
115
|
_proto.hideBar = function hideBar() {
|
|
131
116
|
var _this4 = this;
|
|
132
117
|
|
|
133
|
-
clearTimeout(this.first20Timeout);
|
|
134
|
-
clearInterval(this.progressTimer);
|
|
118
|
+
if (this.first20Timeout) clearTimeout(this.first20Timeout);
|
|
119
|
+
if (this.progressTimer) clearInterval(this.progressTimer);
|
|
135
120
|
this.fadeOffTimeout = setTimeout(function () {
|
|
136
121
|
_this4.setState({
|
|
137
122
|
progress: 100
|
|
@@ -147,7 +132,7 @@ var LoadingBar = /*#__PURE__*/function (_PureComponent) {
|
|
|
147
132
|
|
|
148
133
|
_proto.render = function render() {
|
|
149
134
|
var LoadingBarComponent = this.props.LoadingBarComponent;
|
|
150
|
-
return /*#__PURE__*/
|
|
135
|
+
return /*#__PURE__*/jsx("div", {
|
|
151
136
|
hidden: this.state.hidden,
|
|
152
137
|
style: {
|
|
153
138
|
position: 'fixed',
|
|
@@ -156,10 +141,11 @@ var LoadingBar = /*#__PURE__*/function (_PureComponent) {
|
|
|
156
141
|
right: 0,
|
|
157
142
|
zIndex: 4,
|
|
158
143
|
pointerEvents: 'none'
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
144
|
+
},
|
|
145
|
+
children: /*#__PURE__*/jsx(LoadingBarComponent, {
|
|
146
|
+
progress: this.state.progress
|
|
147
|
+
})
|
|
148
|
+
});
|
|
163
149
|
};
|
|
164
150
|
|
|
165
151
|
return LoadingBar;
|
|
@@ -167,5 +153,5 @@ var LoadingBar = /*#__PURE__*/function (_PureComponent) {
|
|
|
167
153
|
|
|
168
154
|
LoadingBar.contextType = ReactAlpContext;
|
|
169
155
|
|
|
170
|
-
export default
|
|
156
|
+
export { LoadingBar as default };
|
|
171
157
|
//# sourceMappingURL=index-browser.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-browser.es.js","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\nimport
|
|
1
|
+
{"version":3,"file":"index-browser.es.js","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\nimport { PureComponent } from 'react';\nimport ReactAlpContext from 'react-alp-context';\n\n/*\nExample with antd:\nimport { Progress } from 'antd';\n\nconst LoadingBarComponent = ({ progress }) => (\n <Progress\n type=\"line\"\n status=\"active\"\n percent={progress}\n showInfo={false}\n />\n);\n*/\n\n/* number between 0 and 1 */\nconst random = (): number => Math.ceil(Math.random() * 100) / 100;\n\n/**\n * around:\n * at 100ms 20%\n * at 1s 40%\n * at 2s 60%\n * at 3s 80%\n */\nconst calculatePercent = (percent: number): number => {\n if (percent < 60) return percent + random() * 10 + 5;\n if (percent < 70) return percent + random() * 10 + 3;\n else if (percent < 80) return percent + random() + 5;\n else if (percent < 90) return percent + random() + 1;\n else if (percent < 95) return percent + 0.1;\n else return percent;\n};\n\ninterface LoadingBarProps {\n LoadingBarComponent: React.ComponentType<{ progress: number }>;\n}\n\ninterface LoadingBarState {\n loading: boolean;\n hidden: boolean;\n progress: number;\n}\n\ninterface WebsocketInterface {\n isConnected: () => boolean;\n on: (event: 'connect' | 'disconnect', callback: () => unknown) => void;\n}\n\nexport default class LoadingBar extends PureComponent<\n LoadingBarProps,\n LoadingBarState\n> {\n static contextType = ReactAlpContext;\n\n state = {\n loading: true,\n hidden: true,\n progress: 1,\n };\n\n fadeOffTimeout?: ReturnType<typeof setTimeout>;\n\n resetTimeout?: ReturnType<typeof setTimeout>;\n\n first20Timeout?: ReturnType<typeof setTimeout>;\n\n progressTimer?: ReturnType<typeof setTimeout>;\n\n componentDidMount(): void {\n const websocket = this.getWebsocket();\n if (websocket.isConnected()) {\n this.setState((prevState) => ({\n loading: false,\n progress: 100,\n hidden: prevState.hidden || prevState.progress === 100,\n }));\n }\n websocket.on('connect', () => {\n this.setState({ loading: false });\n });\n websocket.on('disconnect', () => {\n this.setState({ loading: true, progress: 1, hidden: false });\n });\n }\n\n componentDidUpdate(\n prevProps: LoadingBarProps,\n prevState: LoadingBarState,\n ): void {\n if (this.state.loading !== prevState.loading) {\n if (this.state.loading) {\n this.showBar();\n } else {\n this.hideBar();\n }\n }\n }\n\n componentWillUnmount(): void {\n if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);\n if (this.resetTimeout) clearTimeout(this.resetTimeout);\n if (this.first20Timeout) clearTimeout(this.first20Timeout);\n if (this.progressTimer) clearInterval(this.progressTimer);\n }\n\n getWebsocket(): WebsocketInterface {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return\n return this.context.app.websocket;\n }\n\n private showBar(): void {\n if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);\n if (this.resetTimeout) clearTimeout(this.resetTimeout);\n\n this.first20Timeout = setTimeout(() => {\n this.setState({ progress: 20 });\n }, 100);\n\n this.progressTimer = setInterval(() => {\n this.setState((prevState) => {\n const newValue = calculatePercent(prevState.progress);\n return { progress: newValue };\n });\n }, 500);\n }\n\n private hideBar(): void {\n if (this.first20Timeout) clearTimeout(this.first20Timeout);\n if (this.progressTimer) clearInterval(this.progressTimer);\n\n this.fadeOffTimeout = setTimeout(() => {\n this.setState({\n progress: 100,\n });\n }, 500);\n\n this.resetTimeout = setTimeout(() => {\n this.setState({\n hidden: true,\n progress: 1,\n });\n }, 1000);\n }\n\n render(): ReactElement {\n const LoadingBarComponent = this.props.LoadingBarComponent;\n\n return (\n <div\n hidden={this.state.hidden}\n style={{\n position: 'fixed',\n top: 0,\n left: 0,\n right: 0,\n zIndex: 4,\n pointerEvents: 'none',\n }}\n >\n <LoadingBarComponent progress={this.state.progress} />\n </div>\n );\n }\n}\n"],"names":["random","Math","ceil","calculatePercent","percent","LoadingBar","state","loading","hidden","progress","componentDidMount","websocket","getWebsocket","isConnected","setState","prevState","on","componentDidUpdate","prevProps","showBar","hideBar","componentWillUnmount","fadeOffTimeout","clearTimeout","resetTimeout","first20Timeout","progressTimer","clearInterval","context","app","setTimeout","setInterval","newValue","render","LoadingBarComponent","props","_jsx","position","top","left","right","zIndex","pointerEvents","PureComponent","contextType","ReactAlpContext"],"mappings":";;;;;AAmBA,IAAMA,MAAM,GAAG,SAATA,MAAS;AAAA,SAAcC,IAAI,CAACC,IAAL,CAAUD,IAAI,CAACD,MAAL,KAAgB,GAA1B,IAAiC,GAA/C;AAAA,CAAf;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,IAAMG,gBAAgB,GAAG,SAAnBA,gBAAmB,CAACC,OAAD,EAA6B;AACpD,MAAIA,OAAO,GAAG,EAAd,EAAkB,OAAOA,OAAO,GAAGJ,MAAM,KAAK,EAArB,GAA0B,CAAjC;AAClB,MAAII,OAAO,GAAG,EAAd,EAAkB,OAAOA,OAAO,GAAGJ,MAAM,KAAK,EAArB,GAA0B,CAAjC,CAAlB,KACK,IAAII,OAAO,GAAG,EAAd,EAAkB,OAAOA,OAAO,GAAGJ,MAAM,EAAhB,GAAqB,CAA5B,CAAlB,KACA,IAAII,OAAO,GAAG,EAAd,EAAkB,OAAOA,OAAO,GAAGJ,MAAM,EAAhB,GAAqB,CAA5B,CAAlB,KACA,IAAII,OAAO,GAAG,EAAd,EAAkB,OAAOA,OAAO,GAAG,GAAjB,CAAlB,KACA,OAAOA,OAAP;AACN,CAPD;;IAwBqBC;;;;;;;;;;;UAMnBC,QAAQ;AACNC,MAAAA,OAAO,EAAE,IADH;AAENC,MAAAA,MAAM,EAAE,IAF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KAL6B,EAK3B,IAL2B,CAA9B;AAMD;;SAEDwB,SAAA,kBAAuB;AACrB,QAAMC,mBAAmB,GAAG,KAAKC,KAAL,CAAWD,mBAAvC;AAEA,wBACEE;AACE,MAAA,MAAM,EAAE,KAAK9B,KAAL,CAAWE,MADrB;AAEE,MAAA,KAAK,EAAE;AACL6B,QAAAA,QAAQ,EAAE,OADL;AAELC,QAAAA,GAAG,EAAE,CAFA;AAGLC,QAAAA,IAAI,EAAE,CAHD;AAILC,QAAAA,KAAK,EAAE,CAJF;AAKLC,QAAAA,MAAM,EAAE,CALH;AAMLC,QAAAA,aAAa,EAAE;AANV,OAFT;AAAA,6BAWEN,IAAC,mBAAD;AAAqB,QAAA,QAAQ,EAAE,KAAK9B,KAAL,CAAWG;AAA1C;AAXF,MADF;AAeD;;;EAlHqCkC;;AAAnBtC,WAIZuC,cAAcC;;;;"}
|
|
@@ -1,21 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PureComponent } from 'react';
|
|
2
2
|
import ReactAlpContext from 'react-alp-context';
|
|
3
|
-
|
|
4
|
-
/*
|
|
5
|
-
Example with antd:
|
|
6
|
-
import { Progress } from 'antd';
|
|
7
|
-
|
|
8
|
-
const LoadingBarComponent = ({ progress }) => (
|
|
9
|
-
<Progress
|
|
10
|
-
type="line"
|
|
11
|
-
status="active"
|
|
12
|
-
percent={progress}
|
|
13
|
-
showInfo={false}
|
|
14
|
-
/>
|
|
15
|
-
);
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/* number between 0 and 1 */
|
|
3
|
+
import { jsx } from 'react/jsx-runtime.js';
|
|
19
4
|
|
|
20
5
|
const random = () => Math.ceil(Math.random() * 100) / 100;
|
|
21
6
|
/**
|
|
@@ -33,14 +18,12 @@ const calculatePercent = percent => {
|
|
|
33
18
|
};
|
|
34
19
|
|
|
35
20
|
class LoadingBar extends PureComponent {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
};
|
|
43
|
-
}
|
|
21
|
+
static contextType = ReactAlpContext;
|
|
22
|
+
state = {
|
|
23
|
+
loading: true,
|
|
24
|
+
hidden: true,
|
|
25
|
+
progress: 1
|
|
26
|
+
};
|
|
44
27
|
|
|
45
28
|
componentDidMount() {
|
|
46
29
|
const websocket = this.getWebsocket();
|
|
@@ -78,10 +61,10 @@ class LoadingBar extends PureComponent {
|
|
|
78
61
|
}
|
|
79
62
|
|
|
80
63
|
componentWillUnmount() {
|
|
81
|
-
clearTimeout(this.fadeOffTimeout);
|
|
82
|
-
clearTimeout(this.resetTimeout);
|
|
83
|
-
clearTimeout(this.first20Timeout);
|
|
84
|
-
clearInterval(this.progressTimer);
|
|
64
|
+
if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);
|
|
65
|
+
if (this.resetTimeout) clearTimeout(this.resetTimeout);
|
|
66
|
+
if (this.first20Timeout) clearTimeout(this.first20Timeout);
|
|
67
|
+
if (this.progressTimer) clearInterval(this.progressTimer);
|
|
85
68
|
}
|
|
86
69
|
|
|
87
70
|
getWebsocket() {
|
|
@@ -90,8 +73,8 @@ class LoadingBar extends PureComponent {
|
|
|
90
73
|
}
|
|
91
74
|
|
|
92
75
|
showBar() {
|
|
93
|
-
clearTimeout(this.fadeOffTimeout);
|
|
94
|
-
clearTimeout(this.resetTimeout);
|
|
76
|
+
if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);
|
|
77
|
+
if (this.resetTimeout) clearTimeout(this.resetTimeout);
|
|
95
78
|
this.first20Timeout = setTimeout(() => {
|
|
96
79
|
this.setState({
|
|
97
80
|
progress: 20
|
|
@@ -108,8 +91,8 @@ class LoadingBar extends PureComponent {
|
|
|
108
91
|
}
|
|
109
92
|
|
|
110
93
|
hideBar() {
|
|
111
|
-
clearTimeout(this.first20Timeout);
|
|
112
|
-
clearInterval(this.progressTimer);
|
|
94
|
+
if (this.first20Timeout) clearTimeout(this.first20Timeout);
|
|
95
|
+
if (this.progressTimer) clearInterval(this.progressTimer);
|
|
113
96
|
this.fadeOffTimeout = setTimeout(() => {
|
|
114
97
|
this.setState({
|
|
115
98
|
progress: 100
|
|
@@ -125,7 +108,7 @@ class LoadingBar extends PureComponent {
|
|
|
125
108
|
|
|
126
109
|
render() {
|
|
127
110
|
const LoadingBarComponent = this.props.LoadingBarComponent;
|
|
128
|
-
return /*#__PURE__*/
|
|
111
|
+
return /*#__PURE__*/jsx("div", {
|
|
129
112
|
hidden: this.state.hidden,
|
|
130
113
|
style: {
|
|
131
114
|
position: 'fixed',
|
|
@@ -134,14 +117,14 @@ class LoadingBar extends PureComponent {
|
|
|
134
117
|
right: 0,
|
|
135
118
|
zIndex: 4,
|
|
136
119
|
pointerEvents: 'none'
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
120
|
+
},
|
|
121
|
+
children: /*#__PURE__*/jsx(LoadingBarComponent, {
|
|
122
|
+
progress: this.state.progress
|
|
123
|
+
})
|
|
124
|
+
});
|
|
141
125
|
}
|
|
142
126
|
|
|
143
127
|
}
|
|
144
|
-
LoadingBar.contextType = ReactAlpContext;
|
|
145
128
|
|
|
146
|
-
export default
|
|
129
|
+
export { LoadingBar as default };
|
|
147
130
|
//# sourceMappingURL=index-browsermodern.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-browsermodern.es.js","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\nimport
|
|
1
|
+
{"version":3,"file":"index-browsermodern.es.js","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\nimport { PureComponent } from 'react';\nimport ReactAlpContext from 'react-alp-context';\n\n/*\nExample with antd:\nimport { Progress } from 'antd';\n\nconst LoadingBarComponent = ({ progress }) => (\n <Progress\n type=\"line\"\n status=\"active\"\n percent={progress}\n showInfo={false}\n />\n);\n*/\n\n/* number between 0 and 1 */\nconst random = (): number => Math.ceil(Math.random() * 100) / 100;\n\n/**\n * around:\n * at 100ms 20%\n * at 1s 40%\n * at 2s 60%\n * at 3s 80%\n */\nconst calculatePercent = (percent: number): number => {\n if (percent < 60) return percent + random() * 10 + 5;\n if (percent < 70) return percent + random() * 10 + 3;\n else if (percent < 80) return percent + random() + 5;\n else if (percent < 90) return percent + random() + 1;\n else if (percent < 95) return percent + 0.1;\n else return percent;\n};\n\ninterface LoadingBarProps {\n LoadingBarComponent: React.ComponentType<{ progress: number }>;\n}\n\ninterface LoadingBarState {\n loading: boolean;\n hidden: boolean;\n progress: number;\n}\n\ninterface WebsocketInterface {\n isConnected: () => boolean;\n on: (event: 'connect' | 'disconnect', callback: () => unknown) => void;\n}\n\nexport default class LoadingBar extends PureComponent<\n LoadingBarProps,\n LoadingBarState\n> {\n static contextType = ReactAlpContext;\n\n state = {\n loading: true,\n hidden: true,\n progress: 1,\n };\n\n fadeOffTimeout?: ReturnType<typeof setTimeout>;\n\n resetTimeout?: ReturnType<typeof setTimeout>;\n\n first20Timeout?: ReturnType<typeof setTimeout>;\n\n progressTimer?: ReturnType<typeof setTimeout>;\n\n componentDidMount(): void {\n const websocket = this.getWebsocket();\n if (websocket.isConnected()) {\n this.setState((prevState) => ({\n loading: false,\n progress: 100,\n hidden: prevState.hidden || prevState.progress === 100,\n }));\n }\n websocket.on('connect', () => {\n this.setState({ loading: false });\n });\n websocket.on('disconnect', () => {\n this.setState({ loading: true, progress: 1, hidden: false });\n });\n }\n\n componentDidUpdate(\n prevProps: LoadingBarProps,\n prevState: LoadingBarState,\n ): void {\n if (this.state.loading !== prevState.loading) {\n if (this.state.loading) {\n this.showBar();\n } else {\n this.hideBar();\n }\n }\n }\n\n componentWillUnmount(): void {\n if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);\n if (this.resetTimeout) clearTimeout(this.resetTimeout);\n if (this.first20Timeout) clearTimeout(this.first20Timeout);\n if (this.progressTimer) clearInterval(this.progressTimer);\n }\n\n getWebsocket(): WebsocketInterface {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return\n return this.context.app.websocket;\n }\n\n private showBar(): void {\n if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);\n if (this.resetTimeout) clearTimeout(this.resetTimeout);\n\n this.first20Timeout = setTimeout(() => {\n this.setState({ progress: 20 });\n }, 100);\n\n this.progressTimer = setInterval(() => {\n this.setState((prevState) => {\n const newValue = calculatePercent(prevState.progress);\n return { progress: newValue };\n });\n }, 500);\n }\n\n private hideBar(): void {\n if (this.first20Timeout) clearTimeout(this.first20Timeout);\n if (this.progressTimer) clearInterval(this.progressTimer);\n\n this.fadeOffTimeout = setTimeout(() => {\n this.setState({\n progress: 100,\n });\n }, 500);\n\n this.resetTimeout = setTimeout(() => {\n this.setState({\n hidden: true,\n progress: 1,\n });\n }, 1000);\n }\n\n render(): ReactElement {\n const LoadingBarComponent = this.props.LoadingBarComponent;\n\n return (\n <div\n hidden={this.state.hidden}\n style={{\n position: 'fixed',\n top: 0,\n left: 0,\n right: 0,\n zIndex: 4,\n pointerEvents: 'none',\n }}\n >\n <LoadingBarComponent progress={this.state.progress} />\n </div>\n );\n }\n}\n"],"names":["random","Math","ceil","calculatePercent","percent","LoadingBar","PureComponent","contextType","ReactAlpContext","state","loading","hidden","progress","componentDidMount","websocket","getWebsocket","isConnected","setState","prevState","on","componentDidUpdate","prevProps","showBar","hideBar","componentWillUnmount","fadeOffTimeout","clearTimeout","resetTimeout","first20Timeout","progressTimer","clearInterval","context","app","setTimeout","setInterval","newValue","render","LoadingBarComponent","props","_jsx","position","top","left","right","zIndex","pointerEvents"],"mappings":";;;;AAmBA,MAAMA,MAAM,GAAG,MAAcC,IAAI,CAACC,IAAL,CAAUD,IAAI,CAACD,MAAL,KAAgB,GAA1B,IAAiC,GAA9D;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,MAAMG,gBAAgB,GAAIC,OAAD,IAA6B;AACpD,MAAIA,OAAO,GAAG,EAAd,EAAkB,OAAOA,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B;AAAZ,SAAP;AACD,OAHD;AAID,KAL+B,EAK7B,GAL6B,CAAhC;AAMD;;AAEOZ,EAAAA,OAAO,GAAS;AACtB,QAAI,KAAKK,cAAT,EAAyBF,YAAY,CAAC,KAAKE,cAAN,CAAZ;AACzB,QAAI,KAAKC,aAAT,EAAwBC,aAAa,CAAC,KAAKD,aAAN,CAAb;AAExB,SAAKJ,cAAL,GAAsBQ,UAAU,CAAC,MAAM;AACrC,WAAKhB,QAAL,CAAc;AACZL,QAAAA,QAAQ,EAAE;AADE,OAAd;AAGD,KAJ+B,EAI7B,GAJ6B,CAAhC;AAMA,SAAKe,YAAL,GAAoBM,UAAU,CAAC,MAAM;AACnC,WAAKhB,QAAL,CAAc;AACZN,QAAAA,MAAM,EAAE,IADI;AAEZC,QAAAA,QAAQ,EAAE;AAFE,OAAd;AAID,KAL6B,EAK3B,IAL2B,CAA9B;AAMD;;AAEDwB,EAAAA,MAAM,GAAiB;AACrB,UAAMC,mBAAmB,GAAG,KAAKC,KAAL,CAAWD,mBAAvC;AAEA,wBACEE;AACE,MAAA,MAAM,EAAE,KAAK9B,KAAL,CAAWE,MADrB;AAEE,MAAA,KAAK,EAAE;AACL6B,QAAAA,QAAQ,EAAE,OADL;AAELC,QAAAA,GAAG,EAAE,CAFA;AAGLC,QAAAA,IAAI,EAAE,CAHD;AAILC,QAAAA,KAAK,EAAE,CAJF;AAKLC,QAAAA,MAAM,EAAE,CALH;AAMLC,QAAAA,aAAa,EAAE;AANV,OAFT;AAAA,6BAWEN,IAAC,mBAAD;AAAqB,QAAA,QAAQ,EAAE,KAAK9B,KAAL,CAAWG;AAA1C;AAXF,MADF;AAeD;;AA/GD;;;;"}
|
|
@@ -1,21 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PureComponent } from 'react';
|
|
2
2
|
import ReactAlpContext from 'react-alp-context';
|
|
3
|
-
|
|
4
|
-
/*
|
|
5
|
-
Example with antd:
|
|
6
|
-
import { Progress } from 'antd';
|
|
7
|
-
|
|
8
|
-
const LoadingBarComponent = ({ progress }) => (
|
|
9
|
-
<Progress
|
|
10
|
-
type="line"
|
|
11
|
-
status="active"
|
|
12
|
-
percent={progress}
|
|
13
|
-
showInfo={false}
|
|
14
|
-
/>
|
|
15
|
-
);
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/* number between 0 and 1 */
|
|
3
|
+
import { jsx } from 'react/jsx-runtime.js';
|
|
19
4
|
|
|
20
5
|
const random = () => Math.ceil(Math.random() * 100) / 100;
|
|
21
6
|
/**
|
|
@@ -33,14 +18,12 @@ const calculatePercent = percent => {
|
|
|
33
18
|
};
|
|
34
19
|
|
|
35
20
|
class LoadingBar extends PureComponent {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
};
|
|
43
|
-
}
|
|
21
|
+
static contextType = ReactAlpContext;
|
|
22
|
+
state = {
|
|
23
|
+
loading: true,
|
|
24
|
+
hidden: true,
|
|
25
|
+
progress: 1
|
|
26
|
+
};
|
|
44
27
|
|
|
45
28
|
componentDidMount() {
|
|
46
29
|
const websocket = this.getWebsocket();
|
|
@@ -78,10 +61,10 @@ class LoadingBar extends PureComponent {
|
|
|
78
61
|
}
|
|
79
62
|
|
|
80
63
|
componentWillUnmount() {
|
|
81
|
-
clearTimeout(this.fadeOffTimeout);
|
|
82
|
-
clearTimeout(this.resetTimeout);
|
|
83
|
-
clearTimeout(this.first20Timeout);
|
|
84
|
-
clearInterval(this.progressTimer);
|
|
64
|
+
if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);
|
|
65
|
+
if (this.resetTimeout) clearTimeout(this.resetTimeout);
|
|
66
|
+
if (this.first20Timeout) clearTimeout(this.first20Timeout);
|
|
67
|
+
if (this.progressTimer) clearInterval(this.progressTimer);
|
|
85
68
|
}
|
|
86
69
|
|
|
87
70
|
getWebsocket() {
|
|
@@ -90,8 +73,8 @@ class LoadingBar extends PureComponent {
|
|
|
90
73
|
}
|
|
91
74
|
|
|
92
75
|
showBar() {
|
|
93
|
-
clearTimeout(this.fadeOffTimeout);
|
|
94
|
-
clearTimeout(this.resetTimeout);
|
|
76
|
+
if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);
|
|
77
|
+
if (this.resetTimeout) clearTimeout(this.resetTimeout);
|
|
95
78
|
this.first20Timeout = setTimeout(() => {
|
|
96
79
|
this.setState({
|
|
97
80
|
progress: 20
|
|
@@ -108,8 +91,8 @@ class LoadingBar extends PureComponent {
|
|
|
108
91
|
}
|
|
109
92
|
|
|
110
93
|
hideBar() {
|
|
111
|
-
clearTimeout(this.first20Timeout);
|
|
112
|
-
clearInterval(this.progressTimer);
|
|
94
|
+
if (this.first20Timeout) clearTimeout(this.first20Timeout);
|
|
95
|
+
if (this.progressTimer) clearInterval(this.progressTimer);
|
|
113
96
|
this.fadeOffTimeout = setTimeout(() => {
|
|
114
97
|
this.setState({
|
|
115
98
|
progress: 100
|
|
@@ -125,7 +108,7 @@ class LoadingBar extends PureComponent {
|
|
|
125
108
|
|
|
126
109
|
render() {
|
|
127
110
|
const LoadingBarComponent = this.props.LoadingBarComponent;
|
|
128
|
-
return /*#__PURE__*/
|
|
111
|
+
return /*#__PURE__*/jsx("div", {
|
|
129
112
|
hidden: this.state.hidden,
|
|
130
113
|
style: {
|
|
131
114
|
position: 'fixed',
|
|
@@ -134,14 +117,14 @@ class LoadingBar extends PureComponent {
|
|
|
134
117
|
right: 0,
|
|
135
118
|
zIndex: 4,
|
|
136
119
|
pointerEvents: 'none'
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
120
|
+
},
|
|
121
|
+
children: /*#__PURE__*/jsx(LoadingBarComponent, {
|
|
122
|
+
progress: this.state.progress
|
|
123
|
+
})
|
|
124
|
+
});
|
|
141
125
|
}
|
|
142
126
|
|
|
143
127
|
}
|
|
144
|
-
LoadingBar.contextType = ReactAlpContext;
|
|
145
128
|
|
|
146
|
-
export default
|
|
147
|
-
//# sourceMappingURL=index-
|
|
129
|
+
export { LoadingBar as default };
|
|
130
|
+
//# sourceMappingURL=index-node14.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-node14.mjs","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\nimport { PureComponent } from 'react';\nimport ReactAlpContext from 'react-alp-context';\n\n/*\nExample with antd:\nimport { Progress } from 'antd';\n\nconst LoadingBarComponent = ({ progress }) => (\n <Progress\n type=\"line\"\n status=\"active\"\n percent={progress}\n showInfo={false}\n />\n);\n*/\n\n/* number between 0 and 1 */\nconst random = (): number => Math.ceil(Math.random() * 100) / 100;\n\n/**\n * around:\n * at 100ms 20%\n * at 1s 40%\n * at 2s 60%\n * at 3s 80%\n */\nconst calculatePercent = (percent: number): number => {\n if (percent < 60) return percent + random() * 10 + 5;\n if (percent < 70) return percent + random() * 10 + 3;\n else if (percent < 80) return percent + random() + 5;\n else if (percent < 90) return percent + random() + 1;\n else if (percent < 95) return percent + 0.1;\n else return percent;\n};\n\ninterface LoadingBarProps {\n LoadingBarComponent: React.ComponentType<{ progress: number }>;\n}\n\ninterface LoadingBarState {\n loading: boolean;\n hidden: boolean;\n progress: number;\n}\n\ninterface WebsocketInterface {\n isConnected: () => boolean;\n on: (event: 'connect' | 'disconnect', callback: () => unknown) => void;\n}\n\nexport default class LoadingBar extends PureComponent<\n LoadingBarProps,\n LoadingBarState\n> {\n static contextType = ReactAlpContext;\n\n state = {\n loading: true,\n hidden: true,\n progress: 1,\n };\n\n fadeOffTimeout?: ReturnType<typeof setTimeout>;\n\n resetTimeout?: ReturnType<typeof setTimeout>;\n\n first20Timeout?: ReturnType<typeof setTimeout>;\n\n progressTimer?: ReturnType<typeof setTimeout>;\n\n componentDidMount(): void {\n const websocket = this.getWebsocket();\n if (websocket.isConnected()) {\n this.setState((prevState) => ({\n loading: false,\n progress: 100,\n hidden: prevState.hidden || prevState.progress === 100,\n }));\n }\n websocket.on('connect', () => {\n this.setState({ loading: false });\n });\n websocket.on('disconnect', () => {\n this.setState({ loading: true, progress: 1, hidden: false });\n });\n }\n\n componentDidUpdate(\n prevProps: LoadingBarProps,\n prevState: LoadingBarState,\n ): void {\n if (this.state.loading !== prevState.loading) {\n if (this.state.loading) {\n this.showBar();\n } else {\n this.hideBar();\n }\n }\n }\n\n componentWillUnmount(): void {\n if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);\n if (this.resetTimeout) clearTimeout(this.resetTimeout);\n if (this.first20Timeout) clearTimeout(this.first20Timeout);\n if (this.progressTimer) clearInterval(this.progressTimer);\n }\n\n getWebsocket(): WebsocketInterface {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return\n return this.context.app.websocket;\n }\n\n private showBar(): void {\n if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);\n if (this.resetTimeout) clearTimeout(this.resetTimeout);\n\n this.first20Timeout = setTimeout(() => {\n this.setState({ progress: 20 });\n }, 100);\n\n this.progressTimer = setInterval(() => {\n this.setState((prevState) => {\n const newValue = calculatePercent(prevState.progress);\n return { progress: newValue };\n });\n }, 500);\n }\n\n private hideBar(): void {\n if (this.first20Timeout) clearTimeout(this.first20Timeout);\n if (this.progressTimer) clearInterval(this.progressTimer);\n\n this.fadeOffTimeout = setTimeout(() => {\n this.setState({\n progress: 100,\n });\n }, 500);\n\n this.resetTimeout = setTimeout(() => {\n this.setState({\n hidden: true,\n progress: 1,\n });\n }, 1000);\n }\n\n render(): ReactElement {\n const LoadingBarComponent = this.props.LoadingBarComponent;\n\n return (\n <div\n hidden={this.state.hidden}\n style={{\n position: 'fixed',\n top: 0,\n left: 0,\n right: 0,\n zIndex: 4,\n pointerEvents: 'none',\n }}\n >\n <LoadingBarComponent progress={this.state.progress} />\n </div>\n );\n }\n}\n"],"names":["random","Math","ceil","calculatePercent","percent","LoadingBar","PureComponent","contextType","ReactAlpContext","state","loading","hidden","progress","componentDidMount","websocket","getWebsocket","isConnected","setState","prevState","on","componentDidUpdate","prevProps","showBar","hideBar","componentWillUnmount","fadeOffTimeout","clearTimeout","resetTimeout","first20Timeout","progressTimer","clearInterval","context","app","setTimeout","setInterval","newValue","render","LoadingBarComponent","props","_jsx","position","top","left","right","zIndex","pointerEvents"],"mappings":";;;;AAmBA,MAAMA,MAAM,GAAG,MAAcC,IAAI,CAACC,IAAL,CAAUD,IAAI,CAACD,MAAL,KAAgB,GAA1B,IAAiC,GAA9D;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,MAAMG,gBAAgB,GAAIC,OAAD,IAA6B;AACpD,MAAIA,OAAO,GAAG,EAAd,EAAkB,OAAOA,OAAO,GAAGJ,MAAM,KAAK,EAArB,GAA0B,CAAjC;AAClB,MAAII,OAAO,GAAG,EAAd,EAAkB,OAAOA,OAAO,GAAGJ,MAAM,KAAK,EAArB,GAA0B,CAAjC,CAAlB,KACK,IAAII,OAAO,GAAG,EAAd,EAAkB,OAAOA,OAAO,GAAGJ,MAAM,EAAhB,GAAqB,CAA5B,CAAlB,KACA,IAAII,OAAO,GAAG,EAAd,EAAkB,OAAOA,OAAO,GAAGJ,MAAM,EAAhB,GAAqB,CAA5B,CAAlB,KACA,IAAII,OAAO,GAAG,EAAd,EAAkB,OAAOA,OAAO,GAAG,GAAjB,CAAlB,KACA,OAAOA,OAAP;AACN,CAPD;;AAwBe,MAAMC,UAAN,SAAyBC,aAAzB,CAGb;AACkB,SAAXC,WAAW,GAAGC,eAAH;AAElBC,EAAAA,KAAK,GAAG;AACNC,IAAAA,OAAO,EAAE,IADH;AAENC,IAAAA,MAAM,EAAE,IAFF;AAGNC,IAAAA,QAAQ,EAAE;AAHJ,GAAH;;AAcLC,EAAAA,iBAAiB,GAAS;AACxB,UAAMC,SAAS,GAAG,KAAKC,YAAL,EAAlB;;AACA,QAAID,SAAS,CAACE,WAAV,EAAJ,EAA6B;AAC3B,WAAKC,QAAL,CAAeC,SAAD,KAAgB;AAC5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C,QAAAA,IAAI,EAAE,CAHD;AAILC,QAAAA,KAAK,EAAE,CAJF;AAKLC,QAAAA,MAAM,EAAE,CALH;AAMLC,QAAAA,aAAa,EAAE;AANV,OAFT;AAAA,6BAWEN,IAAC,mBAAD;AAAqB,QAAA,QAAQ,EAAE,KAAK9B,KAAL,CAAWG;AAA1C;AAXF,MADF;AAeD;;AA/GD;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { ReactElement } from 'react';
|
|
2
|
-
import
|
|
3
|
-
import ReactAlpContext from 'react-alp-context';
|
|
2
|
+
import { PureComponent } from 'react';
|
|
4
3
|
interface LoadingBarProps {
|
|
5
4
|
LoadingBarComponent: React.ComponentType<{
|
|
6
5
|
progress: number;
|
|
@@ -16,17 +15,16 @@ interface WebsocketInterface {
|
|
|
16
15
|
on: (event: 'connect' | 'disconnect', callback: () => unknown) => void;
|
|
17
16
|
}
|
|
18
17
|
export default class LoadingBar extends PureComponent<LoadingBarProps, LoadingBarState> {
|
|
19
|
-
static contextType:
|
|
20
|
-
context: React.ContextType<typeof ReactAlpContext>;
|
|
18
|
+
static contextType: import("react").Context<import("../../alp-types/lib").Context>;
|
|
21
19
|
state: {
|
|
22
20
|
loading: boolean;
|
|
23
21
|
hidden: boolean;
|
|
24
22
|
progress: number;
|
|
25
23
|
};
|
|
26
|
-
fadeOffTimeout?:
|
|
27
|
-
resetTimeout?:
|
|
28
|
-
first20Timeout?:
|
|
29
|
-
progressTimer?:
|
|
24
|
+
fadeOffTimeout?: ReturnType<typeof setTimeout>;
|
|
25
|
+
resetTimeout?: ReturnType<typeof setTimeout>;
|
|
26
|
+
first20Timeout?: ReturnType<typeof setTimeout>;
|
|
27
|
+
progressTimer?: ReturnType<typeof setTimeout>;
|
|
30
28
|
componentDidMount(): void;
|
|
31
29
|
componentDidUpdate(prevProps: LoadingBarProps, prevState: LoadingBarState): void;
|
|
32
30
|
componentWillUnmount(): void;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAoCtC,UAAU,eAAe;IACvB,mBAAmB,EAAE,KAAK,CAAC,aAAa,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChE;AAED,UAAU,eAAe;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,kBAAkB;IAC1B,WAAW,EAAE,MAAM,OAAO,CAAC;IAC3B,EAAE,EAAE,CAAC,KAAK,EAAE,SAAS,GAAG,YAAY,EAAE,QAAQ,EAAE,MAAM,OAAO,KAAK,IAAI,CAAC;CACxE;AAED,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,aAAa,CACnD,eAAe,EACf,eAAe,CAChB;IACC,MAAM,CAAC,WAAW,iEAAmB;IAErC,KAAK;;;;MAIH;IAEF,cAAc,CAAC,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;IAE/C,YAAY,CAAC,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;IAE7C,cAAc,CAAC,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;IAE/C,aAAa,CAAC,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;IAE9C,iBAAiB,IAAI,IAAI;IAiBzB,kBAAkB,CAChB,SAAS,EAAE,eAAe,EAC1B,SAAS,EAAE,eAAe,GACzB,IAAI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