@oxyhq/bloom 0.79.0 → 0.80.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 +3 -3
- package/lib/commonjs/provider/index.js +11 -7
- package/lib/commonjs/provider/index.js.map +1 -1
- package/lib/commonjs/scroll/context.js +96 -0
- package/lib/commonjs/scroll/context.js.map +1 -0
- package/lib/commonjs/scroll/expo-router/index.js +133 -0
- package/lib/commonjs/scroll/expo-router/index.js.map +1 -0
- package/lib/commonjs/scroll/index.js +85 -21
- package/lib/commonjs/scroll/index.js.map +1 -1
- package/lib/commonjs/scroll/index.web.js +221 -121
- package/lib/commonjs/scroll/index.web.js.map +1 -1
- package/lib/commonjs/scroll/scrollable.native.js +58 -0
- package/lib/commonjs/scroll/scrollable.native.js.map +1 -0
- package/lib/commonjs/scroll/scrollable.web.js +9 -3
- package/lib/commonjs/scroll/scrollable.web.js.map +1 -1
- package/lib/commonjs/scroll/store.js +47 -25
- package/lib/commonjs/scroll/store.js.map +1 -1
- package/lib/commonjs/tabs/Tabs.js +263 -63
- package/lib/commonjs/tabs/Tabs.js.map +1 -1
- package/lib/commonjs/tabs/expo-router/RouterTabs.js +215 -0
- package/lib/commonjs/tabs/expo-router/RouterTabs.js.map +1 -0
- package/lib/commonjs/tabs/expo-router/index.js +13 -0
- package/lib/commonjs/tabs/expo-router/index.js.map +1 -0
- package/lib/commonjs/theme/color-policy.js +11 -10
- package/lib/commonjs/theme/color-policy.js.map +1 -1
- package/lib/module/provider/index.js +10 -6
- package/lib/module/provider/index.js.map +1 -1
- package/lib/module/scroll/context.js +90 -0
- package/lib/module/scroll/context.js.map +1 -0
- package/lib/module/scroll/expo-router/index.js +128 -0
- package/lib/module/scroll/expo-router/index.js.map +1 -0
- package/lib/module/scroll/index.js +80 -21
- package/lib/module/scroll/index.js.map +1 -1
- package/lib/module/scroll/index.web.js +218 -122
- package/lib/module/scroll/index.web.js.map +1 -1
- package/lib/module/scroll/scrollable.native.js +54 -0
- package/lib/module/scroll/scrollable.native.js.map +1 -0
- package/lib/module/scroll/scrollable.web.js +9 -3
- package/lib/module/scroll/scrollable.web.js.map +1 -1
- package/lib/module/scroll/store.js +47 -25
- package/lib/module/scroll/store.js.map +1 -1
- package/lib/module/tabs/Tabs.js +271 -65
- package/lib/module/tabs/Tabs.js.map +1 -1
- package/lib/module/tabs/expo-router/RouterTabs.js +210 -0
- package/lib/module/tabs/expo-router/RouterTabs.js.map +1 -0
- package/lib/module/tabs/expo-router/index.js +10 -0
- package/lib/module/tabs/expo-router/index.js.map +1 -0
- package/lib/module/theme/color-policy.js +11 -10
- package/lib/module/theme/color-policy.js.map +1 -1
- package/lib/typescript/commonjs/provider/index.d.ts +7 -5
- package/lib/typescript/commonjs/provider/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/scroll/context.d.ts +14 -0
- package/lib/typescript/commonjs/scroll/context.d.ts.map +1 -0
- package/lib/typescript/commonjs/scroll/expo-router/index.d.ts +7 -0
- package/lib/typescript/commonjs/scroll/expo-router/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/scroll/index.d.ts +14 -23
- package/lib/typescript/commonjs/scroll/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/scroll/index.web.d.ts +17 -19
- package/lib/typescript/commonjs/scroll/index.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/scroll/scrollable.native.d.ts +23 -0
- package/lib/typescript/commonjs/scroll/scrollable.native.d.ts.map +1 -0
- package/lib/typescript/commonjs/scroll/scrollable.web.d.ts +18 -5
- package/lib/typescript/commonjs/scroll/scrollable.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/scroll/store.d.ts +41 -22
- package/lib/typescript/commonjs/scroll/store.d.ts.map +1 -1
- package/lib/typescript/commonjs/scroll/types.d.ts +82 -12
- package/lib/typescript/commonjs/scroll/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/tabs/Tabs.d.ts +41 -1
- package/lib/typescript/commonjs/tabs/Tabs.d.ts.map +1 -1
- package/lib/typescript/commonjs/tabs/expo-router/RouterTabs.d.ts +80 -0
- package/lib/typescript/commonjs/tabs/expo-router/RouterTabs.d.ts.map +1 -0
- package/lib/typescript/commonjs/tabs/expo-router/index.d.ts +9 -0
- package/lib/typescript/commonjs/tabs/expo-router/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/tabs/types.d.ts +48 -4
- package/lib/typescript/commonjs/tabs/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/color-policy.d.ts.map +1 -1
- package/lib/typescript/module/provider/index.d.ts +7 -5
- package/lib/typescript/module/provider/index.d.ts.map +1 -1
- package/lib/typescript/module/scroll/context.d.ts +14 -0
- package/lib/typescript/module/scroll/context.d.ts.map +1 -0
- package/lib/typescript/module/scroll/expo-router/index.d.ts +7 -0
- package/lib/typescript/module/scroll/expo-router/index.d.ts.map +1 -0
- package/lib/typescript/module/scroll/index.d.ts +14 -23
- package/lib/typescript/module/scroll/index.d.ts.map +1 -1
- package/lib/typescript/module/scroll/index.web.d.ts +17 -19
- package/lib/typescript/module/scroll/index.web.d.ts.map +1 -1
- package/lib/typescript/module/scroll/scrollable.native.d.ts +23 -0
- package/lib/typescript/module/scroll/scrollable.native.d.ts.map +1 -0
- package/lib/typescript/module/scroll/scrollable.web.d.ts +18 -5
- package/lib/typescript/module/scroll/scrollable.web.d.ts.map +1 -1
- package/lib/typescript/module/scroll/store.d.ts +41 -22
- package/lib/typescript/module/scroll/store.d.ts.map +1 -1
- package/lib/typescript/module/scroll/types.d.ts +82 -12
- package/lib/typescript/module/scroll/types.d.ts.map +1 -1
- package/lib/typescript/module/tabs/Tabs.d.ts +41 -1
- package/lib/typescript/module/tabs/Tabs.d.ts.map +1 -1
- package/lib/typescript/module/tabs/expo-router/RouterTabs.d.ts +80 -0
- package/lib/typescript/module/tabs/expo-router/RouterTabs.d.ts.map +1 -0
- package/lib/typescript/module/tabs/expo-router/index.d.ts +9 -0
- package/lib/typescript/module/tabs/expo-router/index.d.ts.map +1 -0
- package/lib/typescript/module/tabs/types.d.ts +48 -4
- package/lib/typescript/module/tabs/types.d.ts.map +1 -1
- package/lib/typescript/module/theme/color-policy.d.ts.map +1 -1
- package/package.json +29 -1
- package/src/__tests__/BloomProvider.web.test.tsx +8 -15
- package/src/__tests__/Tabs.test.tsx +187 -0
- package/src/__tests__/optional-peer-imports.test.ts +7 -2
- package/src/__tests__/scroll-expo-router-adapter.test.tsx +164 -0
- package/src/__tests__/scroll-native.test.tsx +465 -0
- package/src/__tests__/scroll-store.test.ts +41 -17
- package/src/__tests__/scroll-web.test.tsx +797 -108
- package/src/provider/index.tsx +10 -7
- package/src/scroll/context.tsx +107 -0
- package/src/scroll/expo-router/index.ts +140 -0
- package/src/scroll/index.ts +92 -25
- package/src/scroll/index.web.tsx +255 -162
- package/src/scroll/scrollable.native.ts +64 -0
- package/src/scroll/scrollable.web.ts +30 -8
- package/src/scroll/store.ts +47 -25
- package/src/scroll/types.ts +82 -12
- package/src/tabs/Tabs.tsx +352 -77
- package/src/tabs/expo-router/RouterTabs.tsx +268 -0
- package/src/tabs/expo-router/index.ts +8 -0
- package/src/tabs/types.ts +48 -4
- package/src/theme/__tests__/__fixtures__/golden-resolved-tokens.json +5 -5
- package/src/theme/__tests__/__snapshots__/visual-gallery.test.tsx.snap +11 -11
- package/src/theme/__tests__/policy-legibility.test.ts +10 -7
- package/src/theme/color-policy.ts +11 -10
- package/lib/commonjs/provider/scroll-provider.js +0 -13
- package/lib/commonjs/provider/scroll-provider.js.map +0 -1
- package/lib/commonjs/provider/scroll-provider.web.js +0 -13
- package/lib/commonjs/provider/scroll-provider.web.js.map +0 -1
- package/lib/module/provider/scroll-provider.js +0 -16
- package/lib/module/provider/scroll-provider.js.map +0 -1
- package/lib/module/provider/scroll-provider.web.js +0 -5
- package/lib/module/provider/scroll-provider.web.js.map +0 -1
- package/lib/typescript/commonjs/provider/scroll-provider.d.ts +0 -14
- package/lib/typescript/commonjs/provider/scroll-provider.d.ts.map +0 -1
- package/lib/typescript/commonjs/provider/scroll-provider.web.d.ts +0 -3
- package/lib/typescript/commonjs/provider/scroll-provider.web.d.ts.map +0 -1
- package/lib/typescript/module/provider/scroll-provider.d.ts +0 -14
- package/lib/typescript/module/provider/scroll-provider.d.ts.map +0 -1
- package/lib/typescript/module/provider/scroll-provider.web.d.ts +0 -3
- package/lib/typescript/module/provider/scroll-provider.web.d.ts.map +0 -1
- package/src/__tests__/scroll-native.test.ts +0 -25
- package/src/provider/scroll-provider.ts +0 -13
- package/src/provider/scroll-provider.web.ts +0 -2
|
@@ -3,32 +3,36 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
6
|
+
Object.defineProperty(exports, "ScrollRestorationProvider", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _context.ScrollRestorationProvider;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
7
12
|
exports.useScrollRestoration = useScrollRestoration;
|
|
8
13
|
var _react = require("react");
|
|
9
|
-
var
|
|
14
|
+
var _context = require("./context.js");
|
|
10
15
|
var _scrollableWeb = require("./scrollable.web.js");
|
|
11
16
|
var _store = require("./store.js");
|
|
12
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
17
|
/**
|
|
14
18
|
* Web variant of the scroll-restoration primitive.
|
|
15
19
|
*
|
|
16
|
-
* Mirrors the proven Bluesky pattern (`history.scrollRestoration
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
+
* Mirrors the proven Bluesky pattern (manual `history.scrollRestoration` plus
|
|
21
|
+
* an in-memory `Map<key, offset>`) with three deliberate differences forced by
|
|
22
|
+
* Oxy's layouts and by the behaviour of the (expo-router-wrapped) React
|
|
23
|
+
* Navigation web stack:
|
|
20
24
|
*
|
|
21
25
|
* 1. Bluesky restores the WINDOW scroller, whereas Oxy apps keep multi-column
|
|
22
26
|
* layouts whose feed scrolls an INNER container. So we restore the offset
|
|
23
27
|
* of a caller-registered scrollable (a ref to an element / RN scroll
|
|
24
|
-
* component, or the `'window'` sentinel)
|
|
28
|
+
* component, or the `'window'` sentinel).
|
|
25
29
|
*
|
|
26
|
-
* 2. The web stack HIDES the background screen on push. While
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
30
|
+
* 2. The web stack HIDES the background screen on push. While hidden, the
|
|
31
|
+
* previous screen's scroll container collapses (`scrollHeight ===
|
|
32
|
+
* clientHeight`) and the navigator forces its `scrollTop` to 0. The screen
|
|
33
|
+
* is NOT unmounted, so a virtualized list (e.g. FlashList) keeps its rows
|
|
34
|
+
* but re-lays them out over SEVERAL frames once the screen is re-shown. Two
|
|
35
|
+
* problems follow, both handled here:
|
|
32
36
|
*
|
|
33
37
|
* (a) A blur-time read of `scrollTop` returns the navigator's forced 0,
|
|
34
38
|
* not the user's real offset — saving it would clobber the good
|
|
@@ -42,28 +46,22 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
42
46
|
* sticks (the content has grown tall enough) or a small frame cap is
|
|
43
47
|
* reached.
|
|
44
48
|
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
49
|
+
* 3. A document-scrolled app (one window scroller shared by every route) has
|
|
50
|
+
* no per-screen container to reset, so an unrecognised key MUST be written
|
|
51
|
+
* to 0 explicitly. Doing nothing leaves the previous screen's offset in
|
|
52
|
+
* place and the new screen opens mid-page.
|
|
47
53
|
*
|
|
48
|
-
*
|
|
49
|
-
* `
|
|
50
|
-
* than from `@react-navigation/native` directly. Every Oxy app uses expo-router
|
|
51
|
-
* as its router, so it is always a DIRECT, top-level dependency that resolves
|
|
52
|
-
* cleanly under Bun's isolated linker — whereas `@react-navigation/native` is
|
|
53
|
-
* only a nested/transitive dependency of expo-router and would fail to resolve
|
|
54
|
-
* when bundling those apps.
|
|
54
|
+
* Native bundlers use `./index.ts`; web bundlers select this file via the
|
|
55
|
+
* `"browser"` export condition in `package.json`.
|
|
55
56
|
*/
|
|
56
57
|
|
|
57
|
-
const ScrollOffsetContext = /*#__PURE__*/(0, _react.createContext)(null);
|
|
58
|
-
ScrollOffsetContext.displayName = 'BloomScrollOffsetContext';
|
|
59
|
-
|
|
60
58
|
/**
|
|
61
|
-
* Maximum number of animation frames the
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
59
|
+
* Maximum number of animation frames the restore will re-apply the saved offset
|
|
60
|
+
* before giving up. A virtualized list re-lays out its rows over a handful of
|
|
61
|
+
* frames after its screen is re-shown; ~30 frames (≈0.5s at 60fps) is
|
|
62
|
+
* comfortably longer than any observed relayout while staying short enough that
|
|
63
|
+
* the loop never lingers as a perceptible cost. The loop normally exits far
|
|
64
|
+
* earlier — as soon as the write sticks.
|
|
67
65
|
*/
|
|
68
66
|
const RESTORE_FRAME_CAP = 30;
|
|
69
67
|
|
|
@@ -77,141 +75,243 @@ const RESTORE_FRAME_CAP = 30;
|
|
|
77
75
|
const RESTORE_STICK_TOLERANCE_PX = 2;
|
|
78
76
|
|
|
79
77
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* it is set before any provider mounts, matching Bluesky's module-level call.
|
|
78
|
+
* The web binding is a constant: this platform observes offsets by subscribing
|
|
79
|
+
* to the resolved DOM node's own `scroll` event, so it needs nothing from the
|
|
80
|
+
* caller. It is still returned — and still safe to spread onto a list — so a
|
|
81
|
+
* call site is written once and runs on both platforms.
|
|
85
82
|
*/
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
83
|
+
const WEB_BINDING = {
|
|
84
|
+
onScroll: () => undefined
|
|
85
|
+
};
|
|
89
86
|
|
|
90
87
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
88
|
+
* Events that mean the USER has taken over the scroller, and the restore must
|
|
89
|
+
* stop trying to put them back.
|
|
90
|
+
*
|
|
91
|
+
* The browser's own restoration is specified the same way: HTML §7.4.6.5 has
|
|
92
|
+
* the UA re-attempt the saved position and "may continue to attempt to do so
|
|
93
|
+
* periodically, until document's has been scrolled by the user becomes true".
|
|
94
|
+
* Without this the loop fights anyone who starts scrolling inside the frame
|
|
95
|
+
* budget, yanking them back once per frame for up to {@link RESTORE_FRAME_CAP}
|
|
96
|
+
* frames.
|
|
97
|
+
*
|
|
98
|
+
* Two designs were rejected, and the reasons are the point:
|
|
99
|
+
*
|
|
100
|
+
* - **"Any `scroll` event aborts"** — the obvious version, and it aborts on the
|
|
101
|
+
* FIRST frame every time: `setOffset` is itself a scroll, so the loop would
|
|
102
|
+
* cancel on the event its own write produced and no restore would ever
|
|
103
|
+
* complete.
|
|
104
|
+
* - **"Abort on an offset we did not write"** — tempting because it needs no
|
|
105
|
+
* listeners, but a virtualized list inserting rows ABOVE the viewport makes
|
|
106
|
+
* the browser's scroll anchoring move `scrollTop` on its own. That is
|
|
107
|
+
* precisely the situation the loop exists for, so the unexplained-delta test
|
|
108
|
+
* would abort exactly when it must not.
|
|
109
|
+
*
|
|
110
|
+
* What is being detected is user INPUT, so this detects user input. `pointerdown`
|
|
111
|
+
* covers a scrollbar drag and a touch-less press; `keydown` covers arrow/page
|
|
112
|
+
* keys, and reaches us whenever focus is inside the scroller it would scroll.
|
|
94
113
|
*/
|
|
95
|
-
|
|
96
|
-
children
|
|
97
|
-
}) {
|
|
98
|
-
const store = (0, _react.useMemo)(() => new _store.ScrollOffsetStore(), []);
|
|
99
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(ScrollOffsetContext.Provider, {
|
|
100
|
-
value: store,
|
|
101
|
-
children: children
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
function useScrollOffsetStore() {
|
|
105
|
-
const store = (0, _react.useContext)(ScrollOffsetContext);
|
|
106
|
-
if (store === null) {
|
|
107
|
-
throw new Error('useScrollRestoration must be used within a <ScrollRestorationProvider>.');
|
|
108
|
-
}
|
|
109
|
-
return store;
|
|
110
|
-
}
|
|
114
|
+
const USER_TAKEOVER_EVENTS = ['wheel', 'touchstart', 'pointerdown', 'keydown'];
|
|
111
115
|
|
|
112
116
|
/**
|
|
113
117
|
* Preserve and restore the scroll offset of `target` across navigation, keyed
|
|
114
|
-
* by the
|
|
115
|
-
* multiple scrollables).
|
|
118
|
+
* by the content its screen is showing plus an optional `options.key`.
|
|
116
119
|
*
|
|
117
120
|
* Behaviour (web):
|
|
118
121
|
* - On every scroll while the screen is focused, the current offset is recorded
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* saved
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
122
|
+
* under the key that was live when the listener was attached. This stream of
|
|
123
|
+
* saves is the source of truth.
|
|
124
|
+
* - On focus — and again whenever the key changes while the screen STAYS
|
|
125
|
+
* focused, which is how an in-screen tab or folder swap is seen at all — the
|
|
126
|
+
* offset saved for the new key is re-applied across a bounded run of
|
|
127
|
+
* animation frames, stopping as soon as the write sticks or
|
|
128
|
+
* {@link RESTORE_FRAME_CAP} is reached. Content never seen this session is
|
|
129
|
+
* written to 0 once instead; a write to 0 always sticks, so it needs no loop.
|
|
130
|
+
* - On blur (and on a key change), the LAST OBSERVED offset is persisted under
|
|
131
|
+
* the OUTGOING key as a final safety net — not a fresh `scrollTop` read,
|
|
132
|
+
* which the navigator may already have forced to 0 while collapsing the
|
|
133
|
+
* hidden screen.
|
|
127
134
|
*/
|
|
128
135
|
function useScrollRestoration(target, options) {
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
136
|
+
const {
|
|
137
|
+
store,
|
|
138
|
+
adapter
|
|
139
|
+
} = (0, _context.useScrollRestorationContext)();
|
|
140
|
+
const contentId = adapter.useScreenContentId();
|
|
132
141
|
const enabled = options?.enabled ?? true;
|
|
133
|
-
const scrollKey = (0, _store.deriveScrollKey)(
|
|
142
|
+
const scrollKey = (0, _store.deriveScrollKey)(contentId, options?.key);
|
|
134
143
|
|
|
135
|
-
//
|
|
136
|
-
//
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
//
|
|
145
|
-
//
|
|
146
|
-
// each focus.
|
|
144
|
+
// The key this hook instance has already sent to the top. Writing 0 is a
|
|
145
|
+
// one-time ARRIVAL action: a later re-run for the SAME key (`enabled` turning
|
|
146
|
+
// on once the rows exist, a screen regaining focus) must not repeat it,
|
|
147
|
+
// because by then the user may have scrolled somewhere the hook never got to
|
|
148
|
+
// record. Restoring twice is harmless; resetting twice is data loss.
|
|
149
|
+
const resetKeyRef = (0, _react.useRef)(null);
|
|
150
|
+
adapter.useScreenFocusEffect(
|
|
151
|
+
// Every varying input is a dependency rather than a ref read, so the
|
|
152
|
+
// session below CLOSES OVER the key it belongs to. That is what makes a
|
|
153
|
+
// key change mid-focus correct in both directions: the outgoing session's
|
|
154
|
+
// cleanup persists to the old key, and the incoming one restores the new.
|
|
147
155
|
(0, _react.useCallback)(() => {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
const element = targetRef.current === 'window' ? typeof window !== 'undefined' ? window : null : resolveScrollEventTarget(targetRef.current);
|
|
156
|
+
if (!enabled || scrollKey === null) return undefined;
|
|
157
|
+
const scroller = (0, _scrollableWeb.createScroller)(target);
|
|
158
|
+
const element = target === 'window' ? typeof window === 'undefined' ? null : window : resolveScrollEventTarget(target);
|
|
152
159
|
|
|
153
|
-
// The last offset the live scroll listener observed for this
|
|
154
|
-
//
|
|
155
|
-
//
|
|
156
|
-
//
|
|
157
|
-
//
|
|
158
|
-
//
|
|
160
|
+
// The last offset the live scroll listener observed for this session.
|
|
161
|
+
// This — not a cleanup-time `getOffset()` — is what we persist at the
|
|
162
|
+
// end, because by then the navigator may have collapsed the hidden
|
|
163
|
+
// screen and forced its `scrollTop` to 0 (problem A). `null` means the
|
|
164
|
+
// user never scrolled this session, so there is nothing newer to persist
|
|
165
|
+
// than what the scroll listener already saved live.
|
|
159
166
|
let lastObservedOffset = null;
|
|
167
|
+
|
|
168
|
+
// The offset WE last wrote, which a real browser dispatches back as a
|
|
169
|
+
// `scroll` event (jsdom does not, so the tests for this emit it
|
|
170
|
+
// explicitly). Both writers arm it: the reset, and every frame of the
|
|
171
|
+
// restore loop. Persisting either records an offset the user never
|
|
172
|
+
// chose — the reset's 0 under a key another LIVE screen may share (the
|
|
173
|
+
// two-live-entries trade content keying makes, see `deriveScrollKey`),
|
|
174
|
+
// and the loop's intermediate value as a PARTIAL that outlives an
|
|
175
|
+
// interrupted restore.
|
|
176
|
+
//
|
|
177
|
+
// A `restoring` FLAG covering the loop's duration is the obvious
|
|
178
|
+
// alternative and is wrong. It could only be cleared by a takeover
|
|
179
|
+
// event, so a session whose scroll came from a source that fires none —
|
|
180
|
+
// `scrollIntoView` from another component, a focus-driven scroll — would
|
|
181
|
+
// suppress saves indefinitely and never record the user's position at
|
|
182
|
+
// all: an unbounded corruption traded for a bounded one. Arming a VALUE
|
|
183
|
+
// is bounded to one event per write and covers every way the loop can
|
|
184
|
+
// end (stuck, capped, aborted), because each frame re-arms.
|
|
185
|
+
let echoOffset = null;
|
|
186
|
+
|
|
187
|
+
// The largest offset reachable when we last PERSISTED one. A browser
|
|
188
|
+
// clamp is recognised against this rather than against the previous
|
|
189
|
+
// OBSERVATION, and that distinction is the whole mechanism: Chrome
|
|
190
|
+
// dispatches TWO `scroll` events for one clamp, so an
|
|
191
|
+
// observation-relative test sees the shrink on the first and nothing on
|
|
192
|
+
// the second, which then saves the clamped value anyway. Measured.
|
|
193
|
+
let maxOffsetAtLastSave = scroller.getMaxOffset();
|
|
160
194
|
const save = () => {
|
|
161
|
-
const currentKey = scrollKeyRef.current;
|
|
162
|
-
if (!enabledRef.current || currentKey === null) return;
|
|
163
195
|
const offset = scroller.getOffset();
|
|
196
|
+
const maxOffset = scroller.getMaxOffset();
|
|
164
197
|
// Ignore a spurious 0 produced by the navigator collapsing a hidden
|
|
165
198
|
// background screen: while collapsed the container cannot scroll, so
|
|
166
|
-
// its `scrollTop` is forced to 0. Persisting it would clobber the
|
|
167
|
-
//
|
|
199
|
+
// its `scrollTop` is forced to 0. Persisting it would clobber the good
|
|
200
|
+
// offset recorded by earlier live saves (problem A). A genuine
|
|
168
201
|
// scroll-to-top keeps the container scrollable and is saved normally.
|
|
169
|
-
if (offset === 0 &&
|
|
202
|
+
if (offset === 0 && maxOffset <= 0) return;
|
|
203
|
+
// A partial clamp: the reachable range SHRANK and the offset is sitting
|
|
204
|
+
// exactly at the new bottom. That is what the browser does to a tab
|
|
205
|
+
// whose document has been taken over by a shorter sibling — the two
|
|
206
|
+
// together are a signature a genuine scroll does not have, because
|
|
207
|
+
// reaching the bottom on your own does not shrink the page in the same
|
|
208
|
+
// breath. Suppressing keeps the pre-clamp offset, which on return
|
|
209
|
+
// simply clamps to the same place if the content really did shrink.
|
|
210
|
+
if (maxOffset < maxOffsetAtLastSave && Math.abs(offset - maxOffset) <= RESTORE_STICK_TOLERANCE_PX) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (offset === echoOffset) {
|
|
214
|
+
// Our own write coming back. Consume the arming so a real scroll to
|
|
215
|
+
// the same offset later is saved normally.
|
|
216
|
+
echoOffset = null;
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
echoOffset = null;
|
|
170
220
|
lastObservedOffset = offset;
|
|
171
|
-
|
|
221
|
+
maxOffsetAtLastSave = maxOffset;
|
|
222
|
+
store.save(scrollKey, offset);
|
|
172
223
|
};
|
|
173
224
|
|
|
174
|
-
// Restore
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
//
|
|
178
|
-
|
|
179
|
-
|
|
225
|
+
// Restore and reset are ONE write. A miss reads 0, and 0 is exactly what
|
|
226
|
+
// an unseen screen must be written to — left alone it would show the
|
|
227
|
+
// previous screen's offset, since a document-scrolled app shares one
|
|
228
|
+
// scroller across every route.
|
|
229
|
+
const targetOffset = store.read(scrollKey);
|
|
230
|
+
|
|
231
|
+
// They remain two DECISIONS, though, and `read` cannot tell them apart:
|
|
232
|
+
// a key never seen and a key deliberately saved at the top both read 0.
|
|
233
|
+
// Only the first is a RESET, and a reset is a one-time ARRIVAL action
|
|
234
|
+
// gated on `resetKeyRef` — repeating it on a later re-run for the same
|
|
235
|
+
// key would send a user who has since scrolled back to the top, and the
|
|
236
|
+
// hook was inert while they did it so there is nothing to restore them
|
|
237
|
+
// to afterwards. A 0 the user deliberately saved is theirs, and always
|
|
238
|
+
// re-applies. `has` is the only thing that answers this.
|
|
239
|
+
const isReset = !store.has(scrollKey);
|
|
240
|
+
const alreadyReset = isReset && resetKeyRef.current === scrollKey;
|
|
241
|
+
if (isReset) resetKeyRef.current = scrollKey;
|
|
180
242
|
let rafId = null;
|
|
181
|
-
|
|
243
|
+
const stopRestore = () => {
|
|
244
|
+
if (rafId === null) return;
|
|
245
|
+
cancelAnimationFrame(rafId);
|
|
246
|
+
rafId = null;
|
|
247
|
+
};
|
|
248
|
+
if (alreadyReset) {
|
|
249
|
+
// Nothing to write: this content has already been sent to the top once
|
|
250
|
+
// and the user is wherever they have moved to since.
|
|
251
|
+
} else if (targetOffset === 0) {
|
|
252
|
+
// A write to 0 is never clamped away, so it needs no re-apply loop.
|
|
253
|
+
echoOffset = 0;
|
|
254
|
+
scroller.setOffset(0);
|
|
255
|
+
} else if (typeof requestAnimationFrame !== 'undefined') {
|
|
256
|
+
// Re-apply across a bounded run of frames. A freshly re-shown
|
|
257
|
+
// virtualized list re-lays out its rows over several frames, so a
|
|
258
|
+
// single write while it is still collapsed would be clamped to 0 and
|
|
259
|
+
// never re-applied (problem B).
|
|
260
|
+
//
|
|
261
|
+
// Every write the loop makes is suppressed from the save path (see
|
|
262
|
+
// `echoOffset` below), so an interrupted restore leaves the ORIGINAL
|
|
263
|
+
// target stored rather than a partial. Nothing is lost on the success
|
|
264
|
+
// path: `targetOffset` came out of the store, so persisting it again
|
|
265
|
+
// would write back the same number.
|
|
182
266
|
let framesLeft = RESTORE_FRAME_CAP;
|
|
183
267
|
const applyOffset = () => {
|
|
184
268
|
rafId = null;
|
|
185
269
|
scroller.setOffset(targetOffset);
|
|
186
270
|
framesLeft -= 1;
|
|
271
|
+
// `getOffset` re-reads the value the browser actually took, which is
|
|
272
|
+
// clamped to the content height it has reached so far. Arm it as the
|
|
273
|
+
// echo to swallow: this write is about to come back as a `scroll`
|
|
274
|
+
// event, and persisting a PARTIAL offset we wrote ourselves is how a
|
|
275
|
+
// restore that is aborted or capped corrupts the stored position.
|
|
276
|
+
const landed = scroller.getOffset();
|
|
277
|
+
echoOffset = landed;
|
|
187
278
|
// Stop once the write took effect (content grew tall enough) or we
|
|
188
|
-
// exhaust the frame budget.
|
|
189
|
-
const reached = Math.abs(
|
|
279
|
+
// exhaust the frame budget.
|
|
280
|
+
const reached = Math.abs(landed - targetOffset) <= RESTORE_STICK_TOLERANCE_PX;
|
|
190
281
|
if (!reached && framesLeft > 0) {
|
|
191
282
|
rafId = requestAnimationFrame(applyOffset);
|
|
192
283
|
}
|
|
193
284
|
};
|
|
194
285
|
rafId = requestAnimationFrame(applyOffset);
|
|
286
|
+
// Only while a loop is actually in flight — the reset path has nothing
|
|
287
|
+
// to abort, and the listeners would be idle on every screen.
|
|
288
|
+
for (const type of USER_TAKEOVER_EVENTS) {
|
|
289
|
+
element?.addEventListener(type, stopRestore, {
|
|
290
|
+
passive: true
|
|
291
|
+
});
|
|
292
|
+
}
|
|
195
293
|
}
|
|
196
294
|
element?.addEventListener('scroll', save, {
|
|
197
295
|
passive: true
|
|
198
296
|
});
|
|
199
297
|
return () => {
|
|
200
|
-
|
|
298
|
+
stopRestore();
|
|
201
299
|
element?.removeEventListener('scroll', save);
|
|
202
|
-
//
|
|
203
|
-
//
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
300
|
+
// Removing a listener that was never added is a no-op, so this needs no
|
|
301
|
+
// flag tracking whether the loop branch ran.
|
|
302
|
+
for (const type of USER_TAKEOVER_EVENTS) {
|
|
303
|
+
element?.removeEventListener(type, stopRestore);
|
|
304
|
+
}
|
|
305
|
+
// Final capture: persist the last offset the scroll listener OBSERVED,
|
|
306
|
+
// never a fresh read (which the navigator may have forced to 0 while
|
|
307
|
+
// collapsing the hidden screen). When the user never scrolled this
|
|
308
|
+
// session there is nothing newer than the live saves already recorded.
|
|
207
309
|
if (lastObservedOffset !== null) {
|
|
208
|
-
|
|
209
|
-
if (enabledRef.current && currentKey !== null) {
|
|
210
|
-
store.save(currentKey, lastObservedOffset);
|
|
211
|
-
}
|
|
310
|
+
store.save(scrollKey, lastObservedOffset);
|
|
212
311
|
}
|
|
213
312
|
};
|
|
214
|
-
}, [store]));
|
|
313
|
+
}, [store, scrollKey, enabled, target]));
|
|
314
|
+
return WEB_BINDING;
|
|
215
315
|
}
|
|
216
316
|
|
|
217
317
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","
|
|
1
|
+
{"version":3,"names":["_react","require","_context","_scrollableWeb","_store","RESTORE_FRAME_CAP","RESTORE_STICK_TOLERANCE_PX","WEB_BINDING","onScroll","undefined","USER_TAKEOVER_EVENTS","useScrollRestoration","target","options","store","adapter","useScrollRestorationContext","contentId","useScreenContentId","enabled","scrollKey","deriveScrollKey","key","resetKeyRef","useRef","useScreenFocusEffect","useCallback","scroller","createScroller","element","window","resolveScrollEventTarget","lastObservedOffset","echoOffset","maxOffsetAtLastSave","getMaxOffset","save","offset","getOffset","maxOffset","Math","abs","targetOffset","read","isReset","has","alreadyReset","current","rafId","stopRestore","cancelAnimationFrame","setOffset","requestAnimationFrame","framesLeft","applyOffset","landed","reached","type","addEventListener","passive","removeEventListener","EventTarget","handle","getScrollableNode","node"],"sourceRoot":"../../../src","sources":["scroll/index.web.tsx"],"mappings":";;;;;;;;;;;;AAwCA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AA5CA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAwBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMI,iBAAiB,GAAG,EAAE;;AAE5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,0BAA0B,GAAG,CAAC;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAqC,GAAG;EAAEC,QAAQ,EAAEA,CAAA,KAAMC;AAAU,CAAC;;AAE3E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,oBAAoB,GAAG,CAAC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,CAAC;;AAE9E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,oBAAoBA,CAClCC,MAA+B,EAC/BC,OAAqC,EACX;EAC1B,MAAM;IAAEC,KAAK;IAAEC;EAAQ,CAAC,GAAG,IAAAC,oCAA2B,EAAC,CAAC;EACxD,MAAMC,SAAS,GAAGF,OAAO,CAACG,kBAAkB,CAAC,CAAC;EAC9C,MAAMC,OAAO,GAAGN,OAAO,EAAEM,OAAO,IAAI,IAAI;EACxC,MAAMC,SAAS,GAAG,IAAAC,sBAAe,EAACJ,SAAS,EAAEJ,OAAO,EAAES,GAAG,CAAC;;EAE1D;EACA;EACA;EACA;EACA;EACA,MAAMC,WAAW,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AgD;EAC/D,IAAI,OAAOe,MAAM,CAACC,iBAAiB,KAAK,UAAU,EAAE;IAClD,MAAMC,IAAI,GAAGF,MAAM,CAACC,iBAAiB,CAAC,CAAC;IACvC,IAAI,OAAOF,WAAW,KAAK,WAAW,IAAIG,IAAI,YAAYH,WAAW,EAAE;MACrE,OAAOG,IAAI;IACb;EACF;EACA,OAAO,IAAI;AACb","ignoreList":[]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createScroller = createScroller;
|
|
7
|
+
/**
|
|
8
|
+
* The write half of a scrollable, on native. There is no read half: native
|
|
9
|
+
* offers no way to sample a list's offset from outside it, so offsets arrive
|
|
10
|
+
* through the `onScroll` binding the hook returns instead.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
function hasScrollToOffset(value) {
|
|
14
|
+
return typeof value === 'object' && value !== null && typeof value.scrollToOffset === 'function';
|
|
15
|
+
}
|
|
16
|
+
function hasScrollTo(value) {
|
|
17
|
+
return typeof value === 'object' && value !== null && typeof value.scrollTo === 'function';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Build a {@link NativeScroller} for a target.
|
|
22
|
+
*
|
|
23
|
+
* `scrollToOffset` (`FlatList`, `FlashList`) is preferred over `scrollTo`
|
|
24
|
+
* (`ScrollView`) because a list exposes both shapes on some versions and only
|
|
25
|
+
* the former accounts for the list's own header. The `'window'` sentinel has no
|
|
26
|
+
* native meaning — there is no document scroller — so it resolves to a no-op
|
|
27
|
+
* rather than an error: a call site shared with web legitimately passes it.
|
|
28
|
+
*
|
|
29
|
+
* The handle is re-resolved on every write; it is never cached, because a ref
|
|
30
|
+
* can be swapped or detached between the schedule and the write.
|
|
31
|
+
*/
|
|
32
|
+
function createScroller(target) {
|
|
33
|
+
if (target === 'window') {
|
|
34
|
+
return {
|
|
35
|
+
setOffset: () => undefined
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
setOffset: offset => {
|
|
40
|
+
const current = target.current;
|
|
41
|
+
if (current == null) return;
|
|
42
|
+
if (hasScrollToOffset(current)) {
|
|
43
|
+
current.scrollToOffset({
|
|
44
|
+
offset,
|
|
45
|
+
animated: false
|
|
46
|
+
});
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (hasScrollTo(current)) {
|
|
50
|
+
current.scrollTo({
|
|
51
|
+
y: offset,
|
|
52
|
+
animated: false
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=scrollable.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["hasScrollToOffset","value","scrollToOffset","hasScrollTo","scrollTo","createScroller","target","setOffset","undefined","offset","current","animated","y"],"sourceRoot":"../../../src","sources":["scroll/scrollable.native.ts"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACA;;AAKA,SAASA,iBAAiBA,CACxBC,KAAc,EAC+C;EAC7D,OACE,OAAOA,KAAK,KAAK,QAAQ,IACzBA,KAAK,KAAK,IAAI,IACd,OAAQA,KAAK,CAAsBC,cAAc,KAAK,UAAU;AAEpE;AAEA,SAASC,WAAWA,CAClBF,KAAc,EACyC;EACvD,OACE,OAAOA,KAAK,KAAK,QAAQ,IACzBA,KAAK,KAAK,IAAI,IACd,OAAQA,KAAK,CAAsBG,QAAQ,KAAK,UAAU;AAE9D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,cAAcA,CAC5BC,MAA+B,EACf;EAChB,IAAIA,MAAM,KAAK,QAAQ,EAAE;IACvB,OAAO;MAAEC,SAAS,EAAEA,CAAA,KAAMC;IAAU,CAAC;EACvC;EAEA,OAAO;IACLD,SAAS,EAAGE,MAAM,IAAK;MACrB,MAAMC,OAAO,GAAGJ,MAAM,CAACI,OAAO;MAC9B,IAAIA,OAAO,IAAI,IAAI,EAAE;MACrB,IAAIV,iBAAiB,CAACU,OAAO,CAAC,EAAE;QAC9BA,OAAO,CAACR,cAAc,CAAC;UAAEO,MAAM;UAAEE,QAAQ,EAAE;QAAM,CAAC,CAAC;QACnD;MACF;MACA,IAAIR,WAAW,CAACO,OAAO,CAAC,EAAE;QACxBA,OAAO,CAACN,QAAQ,CAAC;UAAEQ,CAAC,EAAEH,MAAM;UAAEE,QAAQ,EAAE;QAAM,CAAC,CAAC;MAClD;IACF;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -48,7 +48,12 @@ function createScroller(target) {
|
|
|
48
48
|
setOffset: offset => {
|
|
49
49
|
if (typeof window !== 'undefined') window.scrollTo(0, offset);
|
|
50
50
|
},
|
|
51
|
-
|
|
51
|
+
getMaxOffset: () => {
|
|
52
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
55
|
+
return Math.max(0, document.documentElement.scrollHeight - window.innerHeight);
|
|
56
|
+
}
|
|
52
57
|
};
|
|
53
58
|
}
|
|
54
59
|
return {
|
|
@@ -60,9 +65,10 @@ function createScroller(target) {
|
|
|
60
65
|
const element = resolveElement(target);
|
|
61
66
|
if (element) element.scrollTop = offset;
|
|
62
67
|
},
|
|
63
|
-
|
|
68
|
+
getMaxOffset: () => {
|
|
64
69
|
const element = resolveElement(target);
|
|
65
|
-
|
|
70
|
+
if (!element) return 0;
|
|
71
|
+
return Math.max(0, element.scrollHeight - element.clientHeight);
|
|
66
72
|
}
|
|
67
73
|
};
|
|
68
74
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["isElement","value","HTMLElement","hasGetScrollableNode","getScrollableNode","resolveElement","target","current","node","createScroller","getOffset","window","scrollY","setOffset","offset","scrollTo","
|
|
1
|
+
{"version":3,"names":["isElement","value","HTMLElement","hasGetScrollableNode","getScrollableNode","resolveElement","target","current","node","createScroller","getOffset","window","scrollY","setOffset","offset","scrollTo","getMaxOffset","document","Math","max","documentElement","scrollHeight","innerHeight","element","scrollTop","clientHeight"],"sourceRoot":"../../../src","sources":["scroll/scrollable.web.ts"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACA;;AA+BA,SAASA,SAASA,CAACC,KAAc,EAAwB;EACvD,OAAO,OAAOC,WAAW,KAAK,WAAW,IAAID,KAAK,YAAYC,WAAW;AAC3E;AAEA,SAASC,oBAAoBA,CAC3BF,KAAc,EACkD;EAChE,OACE,OAAOA,KAAK,KAAK,QAAQ,IACzBA,KAAK,KAAK,IAAI,IACd,OAAQA,KAAK,CAAsBG,iBAAiB,KAAK,UAAU;AAEvE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,cAAcA,CAACC,MAA+B,EAAsB;EAC3E,IAAIA,MAAM,KAAK,QAAQ,EAAE,OAAO,IAAI;EAEpC,MAAMC,OAAO,GAAID,MAAM,CAA0BC,OAAO;EACxD,IAAIA,OAAO,IAAI,IAAI,EAAE,OAAO,IAAI;EAEhC,IAAIP,SAAS,CAACO,OAAO,CAAC,EAAE,OAAOA,OAAO;EAEtC,IAAIJ,oBAAoB,CAACI,OAAO,CAAC,EAAE;IACjC,MAAMC,IAAI,GAAGD,OAAO,CAACH,iBAAiB,CAAC,CAAC;IACxC,IAAIJ,SAAS,CAACQ,IAAI,CAAC,EAAE,OAAOA,IAAI;EAClC;EAEA,OAAO,IAAI;AACb;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASC,cAAcA,CAACH,MAA+B,EAAoB;EAChF,IAAIA,MAAM,KAAK,QAAQ,EAAE;IACvB,OAAO;MACLI,SAAS,EAAEA,CAAA,KAAO,OAAOC,MAAM,KAAK,WAAW,GAAG,CAAC,GAAGA,MAAM,CAACC,OAAQ;MACrEC,SAAS,EAAGC,MAAM,IAAK;QACrB,IAAI,OAAOH,MAAM,KAAK,WAAW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