@niibase/bottom-sheet-manager 1.1.0 → 1.3.0
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/README.md +372 -38
- package/lib/commonjs/events.js +100 -15
- package/lib/commonjs/events.js.map +1 -1
- package/lib/commonjs/index.js +7 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/manager.js +107 -29
- package/lib/commonjs/manager.js.map +1 -1
- package/lib/commonjs/provider.js +69 -28
- package/lib/commonjs/provider.js.map +1 -1
- package/lib/commonjs/router/index.js +50 -21
- package/lib/commonjs/router/index.js.map +1 -1
- package/lib/commonjs/router/router.js +137 -12
- package/lib/commonjs/router/router.js.map +1 -1
- package/lib/commonjs/router/view.js +194 -84
- package/lib/commonjs/router/view.js.map +1 -1
- package/lib/commonjs/sheet.js +125 -76
- package/lib/commonjs/sheet.js.map +1 -1
- package/lib/module/events.js +100 -15
- package/lib/module/events.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/manager.js +108 -29
- package/lib/module/manager.js.map +1 -1
- package/lib/module/provider.js +65 -25
- package/lib/module/provider.js.map +1 -1
- package/lib/module/router/index.js +34 -18
- package/lib/module/router/index.js.map +1 -1
- package/lib/module/router/router.js +135 -11
- package/lib/module/router/router.js.map +1 -1
- package/lib/module/router/view.js +194 -84
- package/lib/module/router/view.js.map +1 -1
- package/lib/module/sheet.js +127 -78
- package/lib/module/sheet.js.map +1 -1
- package/lib/typescript/events.d.ts +46 -12
- package/lib/typescript/events.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/manager.d.ts +57 -7
- package/lib/typescript/manager.d.ts.map +1 -1
- package/lib/typescript/provider.d.ts +22 -3
- package/lib/typescript/provider.d.ts.map +1 -1
- package/lib/typescript/router/index.d.ts +33 -17
- package/lib/typescript/router/index.d.ts.map +1 -1
- package/lib/typescript/router/router.d.ts +44 -5
- package/lib/typescript/router/router.d.ts.map +1 -1
- package/lib/typescript/router/types.d.ts +113 -17
- package/lib/typescript/router/types.d.ts.map +1 -1
- package/lib/typescript/router/view.d.ts +1 -1
- package/lib/typescript/router/view.d.ts.map +1 -1
- package/lib/typescript/sheet.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +27 -12
- package/lib/typescript/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/events.ts +118 -27
- package/src/index.ts +6 -5
- package/src/manager.ts +156 -33
- package/src/provider.tsx +98 -44
- package/src/router/index.tsx +38 -31
- package/src/router/router.ts +184 -15
- package/src/router/types.ts +119 -22
- package/src/router/view.tsx +252 -132
- package/src/sheet.tsx +176 -95
- package/src/types.ts +144 -129
|
@@ -4,11 +4,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
var _exportNames = {
|
|
7
|
-
createBottomSheetNavigator: true
|
|
7
|
+
createBottomSheetNavigator: true,
|
|
8
|
+
BottomSheetActions: true,
|
|
9
|
+
useBottomSheetNavigation: true
|
|
8
10
|
};
|
|
11
|
+
Object.defineProperty(exports, "BottomSheetActions", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () {
|
|
14
|
+
return _router.BottomSheetActions;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
9
17
|
exports.createBottomSheetNavigator = createBottomSheetNavigator;
|
|
18
|
+
Object.defineProperty(exports, "useBottomSheetNavigation", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _router.useBottomSheetNavigation;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
10
24
|
var _native = require("@react-navigation/native");
|
|
11
|
-
var
|
|
25
|
+
var React = _interopRequireWildcard(require("react"));
|
|
12
26
|
var _router = require("./router");
|
|
13
27
|
var _view = require("./view");
|
|
14
28
|
var _types = require("./types");
|
|
@@ -23,13 +37,14 @@ Object.keys(_types).forEach(function (key) {
|
|
|
23
37
|
}
|
|
24
38
|
});
|
|
25
39
|
});
|
|
26
|
-
function
|
|
40
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
27
41
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
28
42
|
function BottomSheetNavigator({
|
|
29
43
|
id,
|
|
30
44
|
children,
|
|
31
45
|
screenListeners,
|
|
32
46
|
screenOptions,
|
|
47
|
+
initialRouteName,
|
|
33
48
|
...rest
|
|
34
49
|
}) {
|
|
35
50
|
const {
|
|
@@ -41,9 +56,10 @@ function BottomSheetNavigator({
|
|
|
41
56
|
id,
|
|
42
57
|
children,
|
|
43
58
|
screenListeners,
|
|
44
|
-
screenOptions
|
|
59
|
+
screenOptions,
|
|
60
|
+
initialRouteName
|
|
45
61
|
});
|
|
46
|
-
return /*#__PURE__*/
|
|
62
|
+
return /*#__PURE__*/React.createElement(NavigationContent, null, /*#__PURE__*/React.createElement(_view.BottomSheetView, _extends({}, rest, {
|
|
47
63
|
state: state,
|
|
48
64
|
navigation: navigation,
|
|
49
65
|
descriptors: descriptors
|
|
@@ -51,18 +67,40 @@ function BottomSheetNavigator({
|
|
|
51
67
|
}
|
|
52
68
|
|
|
53
69
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
70
|
+
* Creates a bottom sheet navigator that renders screens as bottom sheet modals.
|
|
71
|
+
*
|
|
72
|
+
* The first screen in the navigator is rendered as the main content,
|
|
73
|
+
* and subsequent screens are rendered as bottom sheet modals on top.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```tsx
|
|
77
|
+
* // With React Navigation
|
|
78
|
+
* const { Navigator, Screen } = createBottomSheetNavigator();
|
|
79
|
+
*
|
|
80
|
+
* function App() {
|
|
81
|
+
* return (
|
|
82
|
+
* <Navigator>
|
|
83
|
+
* <Screen name="Home" component={HomeScreen} />
|
|
84
|
+
* <Screen
|
|
85
|
+
* name="Details"
|
|
86
|
+
* component={DetailsSheet}
|
|
87
|
+
* options={{ snapPoints: ['50%', '100%'] }}
|
|
88
|
+
* />
|
|
89
|
+
* </Navigator>
|
|
90
|
+
* );
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
56
93
|
*
|
|
57
94
|
* @example
|
|
58
95
|
* ```tsx
|
|
96
|
+
* // With Expo Router
|
|
97
|
+
* import { Slot, withLayoutContext } from "expo-router";
|
|
59
98
|
* import {
|
|
60
99
|
* createBottomSheetNavigator,
|
|
61
100
|
* BottomSheetNavigationOptions,
|
|
62
101
|
* BottomSheetNavigationEventMap,
|
|
63
102
|
* BottomSheetNavigationState,
|
|
64
|
-
* } from "@
|
|
65
|
-
* import { Slot, withLayoutContext } from "expo-router";
|
|
103
|
+
* } from "@niibase/bottom-sheet-manager";
|
|
66
104
|
*
|
|
67
105
|
* const { Navigator } = createBottomSheetNavigator();
|
|
68
106
|
*
|
|
@@ -78,23 +116,14 @@ function BottomSheetNavigator({
|
|
|
78
116
|
* };
|
|
79
117
|
*
|
|
80
118
|
* export default function Layout() {
|
|
119
|
+
* // SSR guard - navigator doesn't work on server
|
|
81
120
|
* if (typeof window === "undefined") return <Slot />;
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* screenOptions={
|
|
85
|
-
* {
|
|
86
|
-
* // API Reference: `@repo/design/bottom-sheet/types.ts`
|
|
87
|
-
* // And: https://gorhom.github.io/react-native-bottom-sheet/modal/props/
|
|
88
|
-
* }
|
|
89
|
-
* }
|
|
90
|
-
*. />
|
|
91
|
-
* );
|
|
121
|
+
*
|
|
122
|
+
* return <BottomSheet />;
|
|
92
123
|
* }
|
|
93
124
|
* ```
|
|
94
125
|
*/
|
|
95
126
|
function createBottomSheetNavigator(config) {
|
|
96
|
-
// We call `createNavigatorFactory` with our un-typed navigator
|
|
97
|
-
// but pass in the config to get the typed container
|
|
98
127
|
return (0, _native.createNavigatorFactory)(BottomSheetNavigator)(config);
|
|
99
128
|
}
|
|
100
129
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_native","require","
|
|
1
|
+
{"version":3,"names":["_native","require","React","_interopRequireWildcard","_router","_view","_types","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","set","getOwnPropertyDescriptor","_extends","assign","bind","arguments","length","apply","BottomSheetNavigator","id","children","screenListeners","screenOptions","initialRouteName","rest","state","descriptors","navigation","NavigationContent","useNavigationBuilder","BottomSheetRouter","createElement","BottomSheetView","createBottomSheetNavigator","config","createNavigatorFactory"],"sourceRoot":"../../../src","sources":["router/index.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAQA,IAAAC,KAAA,GAAAC,uBAAA,CAAAF,OAAA;AAUA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AAoHA,IAAAK,MAAA,GAAAL,OAAA;AAAAM,MAAA,CAAAC,IAAA,CAAAF,MAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,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EAAmC;EAClD,OAAO,IAAAC,8BAAsB,EAACjB,oBAAoB,CAAC,CAACgB,MAAM,CAAC;AAC7D","ignoreList":[]}
|
|
@@ -3,28 +3,67 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.BottomSheetActions = void 0;
|
|
7
|
-
exports.BottomSheetRouter = BottomSheetRouter;
|
|
6
|
+
exports.useBottomSheetNavigation = exports.BottomSheetRouter = exports.BottomSheetActions = void 0;
|
|
8
7
|
var _native = require("@react-navigation/native");
|
|
9
8
|
var _nonSecure = require("nanoid/non-secure");
|
|
10
9
|
const BottomSheetActions = exports.BottomSheetActions = {
|
|
11
10
|
..._native.StackActions,
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Snap the bottom sheet to a specific index.
|
|
13
|
+
*/
|
|
14
|
+
snapTo: index => ({
|
|
15
|
+
type: "SNAP_TO",
|
|
16
|
+
index
|
|
17
|
+
}),
|
|
18
|
+
/**
|
|
19
|
+
* Dismiss the current bottom sheet.
|
|
20
|
+
*/
|
|
21
|
+
dismiss: () => ({
|
|
22
|
+
type: "DISMISS"
|
|
23
|
+
}),
|
|
24
|
+
/**
|
|
25
|
+
* Remove the sheet from navigation state after dismiss animation completes.
|
|
26
|
+
*/
|
|
27
|
+
remove: () => ({
|
|
28
|
+
type: "REMOVE"
|
|
29
|
+
})
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Ensures the base route (first screen) exists in the navigation state.
|
|
34
|
+
* This is important because the first screen is the main content,
|
|
35
|
+
* and subsequent screens are rendered as bottom sheets.
|
|
36
|
+
*/
|
|
37
|
+
const ensureBaseRoute = (state, baseRouteName, routeParamList) => {
|
|
38
|
+
if (!baseRouteName) {
|
|
39
|
+
return state;
|
|
40
|
+
}
|
|
41
|
+
const hasBaseRoute = state.routes.some(r => r.name === baseRouteName);
|
|
42
|
+
if (!hasBaseRoute) {
|
|
43
|
+
const baseRoute = {
|
|
44
|
+
key: `${baseRouteName}-${(0, _nonSecure.nanoid)()}`,
|
|
45
|
+
name: baseRouteName,
|
|
46
|
+
params: routeParamList?.[baseRouteName]
|
|
47
|
+
};
|
|
13
48
|
return {
|
|
14
|
-
|
|
15
|
-
index
|
|
49
|
+
...state,
|
|
50
|
+
index: state.routes.length,
|
|
51
|
+
routes: [baseRoute, ...state.routes]
|
|
16
52
|
};
|
|
17
53
|
}
|
|
54
|
+
return state;
|
|
18
55
|
};
|
|
19
|
-
|
|
56
|
+
const BottomSheetRouter = routerOptions => {
|
|
20
57
|
const baseRouter = (0, _native.StackRouter)(routerOptions);
|
|
21
58
|
return {
|
|
22
59
|
...baseRouter,
|
|
23
60
|
type: "bottom-sheet",
|
|
24
61
|
getInitialState(options) {
|
|
25
62
|
const state = baseRouter.getInitialState(options);
|
|
63
|
+
const baseRouteName = routerOptions.initialRouteName ?? options.routeNames[0];
|
|
64
|
+
const stateWithBaseRoute = ensureBaseRoute(state, baseRouteName, options.routeParamList);
|
|
26
65
|
return {
|
|
27
|
-
...
|
|
66
|
+
...stateWithBaseRoute,
|
|
28
67
|
stale: false,
|
|
29
68
|
type: "bottom-sheet",
|
|
30
69
|
key: `bottom-sheet-${(0, _nonSecure.nanoid)()}`
|
|
@@ -34,15 +73,76 @@ function BottomSheetRouter(routerOptions) {
|
|
|
34
73
|
switch (action.type) {
|
|
35
74
|
case "SNAP_TO":
|
|
36
75
|
{
|
|
37
|
-
const
|
|
76
|
+
const routeIndex = action.target === state.key && action.source ? state.routes.findIndex(r => r.key === action.source) : state.index;
|
|
38
77
|
return {
|
|
39
78
|
...state,
|
|
40
|
-
routes: state.routes.map((route, i) => i ===
|
|
79
|
+
routes: state.routes.map((route, i) => i === routeIndex ? {
|
|
41
80
|
...route,
|
|
42
|
-
snapToIndex: action.index
|
|
81
|
+
snapToIndex: action.index,
|
|
82
|
+
snapToKey: (route.snapToKey ?? 0) + 1
|
|
43
83
|
} : route)
|
|
44
84
|
};
|
|
45
85
|
}
|
|
86
|
+
case "GO_BACK":
|
|
87
|
+
case "DISMISS":
|
|
88
|
+
{
|
|
89
|
+
return this.getStateForAction(state, _native.StackActions.pop(1), options);
|
|
90
|
+
}
|
|
91
|
+
case "POP":
|
|
92
|
+
{
|
|
93
|
+
// Only base screen remains - let parent navigator handle it
|
|
94
|
+
if (state.routes.length <= 1) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
const count = "payload" in action && typeof action.payload?.count === "number" ? action.payload.count : 1;
|
|
98
|
+
|
|
99
|
+
// Calculate how many routes we can actually pop (don't pop base screen)
|
|
100
|
+
const maxPopCount = state.routes.length - 1;
|
|
101
|
+
const actualCount = Math.min(count, maxPopCount);
|
|
102
|
+
|
|
103
|
+
// Base screen - let parent navigator handle it
|
|
104
|
+
if (actualCount <= 0) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Target index is the route we want to stay on (land on after pop)
|
|
109
|
+
// closingIndex is the first route to be dismissed (the one after target)
|
|
110
|
+
const targetIndex = state.routes.length - 1 - actualCount;
|
|
111
|
+
const closingIndex = targetIndex + 1;
|
|
112
|
+
|
|
113
|
+
// Mark only the bottom-most route to pop as closing
|
|
114
|
+
// The sheet's dismiss() will handle dismissing sheets above it first
|
|
115
|
+
return {
|
|
116
|
+
...state,
|
|
117
|
+
index: closingIndex,
|
|
118
|
+
routes: state.routes.map((route, i) => i === closingIndex ? {
|
|
119
|
+
...route,
|
|
120
|
+
closing: true
|
|
121
|
+
} : route)
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
case "POP_TO_TOP":
|
|
125
|
+
{
|
|
126
|
+
const popCount = state.routes.length - 1;
|
|
127
|
+
return this.getStateForAction(state, _native.StackActions.pop(popCount), options);
|
|
128
|
+
}
|
|
129
|
+
case "REMOVE":
|
|
130
|
+
{
|
|
131
|
+
// Actually remove the closing route and all routes above it
|
|
132
|
+
const routeKey = action.source;
|
|
133
|
+
const routeIndex = routeKey ? state.routes.findIndex(r => r.key === routeKey) : state.routes.findIndex(r => r.closing);
|
|
134
|
+
if (routeIndex === -1) {
|
|
135
|
+
return state;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Remove the route and all routes above it (they were dismissed together)
|
|
139
|
+
const routes = state.routes.filter((_, i) => i < routeIndex);
|
|
140
|
+
return {
|
|
141
|
+
...state,
|
|
142
|
+
index: Math.min(state.index, routes.length - 1),
|
|
143
|
+
routes
|
|
144
|
+
};
|
|
145
|
+
}
|
|
46
146
|
default:
|
|
47
147
|
return baseRouter.getStateForAction(state, action, options);
|
|
48
148
|
}
|
|
@@ -60,13 +160,38 @@ function BottomSheetRouter(routerOptions) {
|
|
|
60
160
|
routeParamList,
|
|
61
161
|
routeGetIdList
|
|
62
162
|
});
|
|
163
|
+
const baseRouteName = routerOptions.initialRouteName ?? routeNames[0];
|
|
164
|
+
const stateWithBaseRoute = ensureBaseRoute(state, baseRouteName, routeParamList);
|
|
63
165
|
return {
|
|
64
|
-
...
|
|
166
|
+
...stateWithBaseRoute,
|
|
65
167
|
type: "bottom-sheet",
|
|
66
168
|
key: `bottom-sheet-${(0, _nonSecure.nanoid)()}`
|
|
67
169
|
};
|
|
68
170
|
},
|
|
69
171
|
actionCreators: BottomSheetActions
|
|
70
172
|
};
|
|
71
|
-
}
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Hook to access BottomSheet navigation with the snapTo helper.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```tsx
|
|
180
|
+
* function MySheet() {
|
|
181
|
+
* const navigation = useBottomSheetNavigation();
|
|
182
|
+
*
|
|
183
|
+
* // Snap to a specific index
|
|
184
|
+
* const handleExpand = () => {
|
|
185
|
+
* navigation.snapTo(1); // Snap to second index
|
|
186
|
+
* };
|
|
187
|
+
*
|
|
188
|
+
* return (
|
|
189
|
+
* <Button title="Expand" onPress={handleExpand} />
|
|
190
|
+
* );
|
|
191
|
+
* }
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
exports.BottomSheetRouter = BottomSheetRouter;
|
|
195
|
+
const useBottomSheetNavigation = () => (0, _native.useNavigation)();
|
|
196
|
+
exports.useBottomSheetNavigation = useBottomSheetNavigation;
|
|
72
197
|
//# sourceMappingURL=router.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_native","require","_nonSecure","BottomSheetActions","exports","StackActions","snapTo","index","type","BottomSheetRouter","routerOptions","baseRouter","StackRouter","getInitialState","options","
|
|
1
|
+
{"version":3,"names":["_native","require","_nonSecure","BottomSheetActions","exports","StackActions","snapTo","index","type","dismiss","remove","ensureBaseRoute","state","baseRouteName","routeParamList","hasBaseRoute","routes","some","r","name","baseRoute","key","nanoid","params","length","BottomSheetRouter","routerOptions","baseRouter","StackRouter","getInitialState","options","initialRouteName","routeNames","stateWithBaseRoute","stale","getStateForAction","action","routeIndex","target","source","findIndex","map","route","i","snapToIndex","snapToKey","pop","count","payload","maxPopCount","actualCount","Math","min","targetIndex","closingIndex","closing","popCount","routeKey","filter","_","getRehydratedState","partialState","routeGetIdList","actionCreators","useBottomSheetNavigation","useNavigation"],"sourceRoot":"../../../src","sources":["router/router.ts"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAUA,IAAAC,UAAA,GAAAD,OAAA;AA0BO,MAAME,kBAAkB,GAAAC,OAAA,CAAAD,kBAAA,GAAG;EAC9B,GAAGE,oBAAY;EACf;AACJ;AACA;EACIC,MAAM,EAAGC,KAAa,KAA6B;IAAEC,IAAI,EAAE,SAAS;IAAED;EAAM,CAAC,CAAC;EAC9E;AACJ;AACA;EACIE,OAAO,EAAEA,CAAA,MAA8B;IAAED,IAAI,EAAE;EAAU,CAAC,CAAC;EAC3D;AACJ;AACA;EACIE,MAAM,EAAEA,CAAA,MAA8B;IAAEF,IAAI,EAAE;EAAS,CAAC;AAC5D,CAAC;;AAED;AACA;AACA;AAC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