@oxyhq/bloom 0.6.21 → 0.6.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/lib/commonjs/scroll/index.js +39 -0
  2. package/lib/commonjs/scroll/index.js.map +1 -0
  3. package/lib/commonjs/scroll/index.web.js +226 -0
  4. package/lib/commonjs/scroll/index.web.js.map +1 -0
  5. package/lib/commonjs/scroll/scrollable.web.js +69 -0
  6. package/lib/commonjs/scroll/scrollable.web.js.map +1 -0
  7. package/lib/commonjs/scroll/store.js +90 -0
  8. package/lib/commonjs/scroll/store.js.map +1 -0
  9. package/lib/commonjs/scroll/types.js +6 -0
  10. package/lib/commonjs/scroll/types.js.map +1 -0
  11. package/lib/module/scroll/index.js +34 -0
  12. package/lib/module/scroll/index.js.map +1 -0
  13. package/lib/module/scroll/index.web.js +220 -0
  14. package/lib/module/scroll/index.web.js.map +1 -0
  15. package/lib/module/scroll/scrollable.web.js +65 -0
  16. package/lib/module/scroll/scrollable.web.js.map +1 -0
  17. package/lib/module/scroll/store.js +84 -0
  18. package/lib/module/scroll/store.js.map +1 -0
  19. package/lib/module/scroll/types.js +4 -0
  20. package/lib/module/scroll/types.js.map +1 -0
  21. package/lib/typescript/commonjs/scroll/index.d.ts +27 -0
  22. package/lib/typescript/commonjs/scroll/index.d.ts.map +1 -0
  23. package/lib/typescript/commonjs/scroll/index.web.d.ts +26 -0
  24. package/lib/typescript/commonjs/scroll/index.web.d.ts.map +1 -0
  25. package/lib/typescript/commonjs/scroll/scrollable.web.d.ts +29 -0
  26. package/lib/typescript/commonjs/scroll/scrollable.web.d.ts.map +1 -0
  27. package/lib/typescript/commonjs/scroll/store.d.ts +46 -0
  28. package/lib/typescript/commonjs/scroll/store.d.ts.map +1 -0
  29. package/lib/typescript/commonjs/scroll/types.d.ts +46 -0
  30. package/lib/typescript/commonjs/scroll/types.d.ts.map +1 -0
  31. package/lib/typescript/module/scroll/index.d.ts +27 -0
  32. package/lib/typescript/module/scroll/index.d.ts.map +1 -0
  33. package/lib/typescript/module/scroll/index.web.d.ts +26 -0
  34. package/lib/typescript/module/scroll/index.web.d.ts.map +1 -0
  35. package/lib/typescript/module/scroll/scrollable.web.d.ts +29 -0
  36. package/lib/typescript/module/scroll/scrollable.web.d.ts.map +1 -0
  37. package/lib/typescript/module/scroll/store.d.ts +46 -0
  38. package/lib/typescript/module/scroll/store.d.ts.map +1 -0
  39. package/lib/typescript/module/scroll/types.d.ts +46 -0
  40. package/lib/typescript/module/scroll/types.d.ts.map +1 -0
  41. package/package.json +22 -1
  42. package/src/__tests__/scroll-native.test.ts +25 -0
  43. package/src/__tests__/scroll-store.test.ts +85 -0
  44. package/src/__tests__/scroll-web.test.tsx +325 -0
  45. package/src/scroll/index.ts +47 -0
  46. package/src/scroll/index.web.tsx +253 -0
  47. package/src/scroll/scrollable.web.ts +92 -0
  48. package/src/scroll/store.ts +84 -0
  49. package/src/scroll/types.ts +48 -0
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ScrollRestorationProvider = ScrollRestorationProvider;
7
+ exports.useScrollRestoration = useScrollRestoration;
8
+ /**
9
+ * Native variant of the scroll-restoration primitive — a deliberate no-op.
10
+ *
11
+ * React Navigation's native-stack keeps every screen mounted while it is in the
12
+ * stack, so a list's scroll position survives a push/pop for free. There is
13
+ * nothing to save or restore. We still ship the full API surface (provider +
14
+ * hook) so consumers write one set of call sites that compile and run on every
15
+ * platform; on native the provider just renders its children and the hook does
16
+ * nothing.
17
+ *
18
+ * Web bundlers select `./index.web` via the `"browser"` export condition in
19
+ * `package.json`; native bundlers fall through to this file.
20
+ */
21
+
22
+ /**
23
+ * No-op provider. Renders children unchanged — native scroll persistence is
24
+ * handled by the navigator, so no per-route state is kept.
25
+ */
26
+ function ScrollRestorationProvider({
27
+ children
28
+ }) {
29
+ return children;
30
+ }
31
+
32
+ /**
33
+ * No-op hook. Accepts the same arguments as the web implementation so call
34
+ * sites are identical across platforms.
35
+ */
36
+ function useScrollRestoration(_target, _options) {
37
+ // Intentionally empty: native-stack already preserves scroll position.
38
+ }
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ScrollRestorationProvider","children","useScrollRestoration","_target","_options"],"sourceRoot":"../../../src","sources":["scroll/index.ts"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAeA;AACA;AACA;AACA;AACO,SAASA,yBAAyBA,CAAC;EACxCC;AAC8B,CAAC,EAAgB;EAC/C,OAAOA,QAAQ;AACjB;;AAEA;AACA;AACA;AACA;AACO,SAASC,oBAAoBA,CAClCC,OAAgC,EAChCC,QAAsC,EAChC;EACN;AAAA","ignoreList":[]}
@@ -0,0 +1,226 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ScrollRestorationProvider = ScrollRestorationProvider;
7
+ exports.useScrollRestoration = useScrollRestoration;
8
+ var _react = require("react");
9
+ var _native = require("@react-navigation/native");
10
+ var _scrollableWeb = require("./scrollable.web.js");
11
+ var _store = require("./store.js");
12
+ var _jsxRuntime = require("react/jsx-runtime");
13
+ /**
14
+ * Web variant of the scroll-restoration primitive.
15
+ *
16
+ * Mirrors the proven Bluesky pattern (`history.scrollRestoration = 'manual'`
17
+ * plus an in-memory `Map<routeKey, offset>`) with two deliberate differences
18
+ * forced by Oxy's layouts and the behaviour of React Navigation's web stack:
19
+ *
20
+ * 1. Bluesky restores the WINDOW scroller, whereas Oxy apps keep multi-column
21
+ * layouts whose feed scrolls an INNER container. So we restore the offset
22
+ * of a caller-registered scrollable (a ref to an element / RN scroll
23
+ * component, or the `'window'` sentinel), keyed by the active route.
24
+ *
25
+ * 2. React Navigation's web stack HIDES the background screen on push. While
26
+ * hidden, the previous screen's scroll container collapses
27
+ * (`scrollHeight === clientHeight`) and the navigator forces its
28
+ * `scrollTop` to 0. The screen is NOT unmounted, so a virtualized list
29
+ * (e.g. FlashList) keeps its rows but re-lays them out over SEVERAL frames
30
+ * once the screen is re-shown. Two problems follow, both handled here:
31
+ *
32
+ * (a) A blur-time read of `scrollTop` returns the navigator's forced 0,
33
+ * not the user's real offset — saving it would clobber the good
34
+ * value. We therefore persist the last offset OBSERVED by the live
35
+ * scroll listener, never a fresh read taken at blur time.
36
+ *
37
+ * (b) A single-frame restore writes `scrollTop` while the list is still
38
+ * collapsed; the write is clamped to 0 and never re-applied once the
39
+ * content grows. We therefore re-apply the target offset across a
40
+ * bounded run of animation frames, stopping as soon as the write
41
+ * sticks (the content has grown tall enough) or a small frame cap is
42
+ * reached.
43
+ *
44
+ * Native bundlers use `./index.ts` (a no-op); web bundlers select this file via
45
+ * the `"browser"` export condition in `package.json`.
46
+ */
47
+
48
+ const ScrollOffsetContext = /*#__PURE__*/(0, _react.createContext)(null);
49
+ ScrollOffsetContext.displayName = 'BloomScrollOffsetContext';
50
+
51
+ /**
52
+ * Maximum number of animation frames the focus restore will re-apply the saved
53
+ * offset before giving up. A virtualized list re-lays out its rows over a
54
+ * handful of frames after its screen is re-shown; ~30 frames (≈0.5s at 60fps)
55
+ * is comfortably longer than any observed relayout while staying short enough
56
+ * that the loop never lingers as a perceptible cost. The loop normally exits
57
+ * far earlier — as soon as the write sticks.
58
+ */
59
+ const RESTORE_FRAME_CAP = 30;
60
+
61
+ /**
62
+ * Tolerance (in CSS pixels) for considering a restore "stuck". After writing
63
+ * `element.scrollTop = target`, the browser may clamp it to the current
64
+ * `scrollHeight - clientHeight`; if the resulting offset is within this many
65
+ * pixels of the target we treat the restore as complete. Sub-pixel rounding and
66
+ * fractional device-pixel ratios make an exact equality check unreliable.
67
+ */
68
+ const RESTORE_STICK_TOLERANCE_PX = 2;
69
+
70
+ /**
71
+ * Switch the browser to manual scroll restoration exactly once per document.
72
+ *
73
+ * The browser's default `'auto'` restoration fights our manual restore on
74
+ * Back/Forward navigations. Doing this at module scope (guarded for SSR) means
75
+ * it is set before any provider mounts, matching Bluesky's module-level call.
76
+ */
77
+ if (typeof history !== 'undefined' && 'scrollRestoration' in history) {
78
+ history.scrollRestoration = 'manual';
79
+ }
80
+
81
+ /**
82
+ * Holds the per-route offset map for the subtree. One provider near the app
83
+ * root is enough; the store lives for the document's lifetime so offsets
84
+ * survive navigating away and back (including browser Back/Forward).
85
+ */
86
+ function ScrollRestorationProvider({
87
+ children
88
+ }) {
89
+ const store = (0, _react.useMemo)(() => new _store.ScrollOffsetStore(), []);
90
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(ScrollOffsetContext.Provider, {
91
+ value: store,
92
+ children: children
93
+ });
94
+ }
95
+ function useScrollOffsetStore() {
96
+ const store = (0, _react.useContext)(ScrollOffsetContext);
97
+ if (store === null) {
98
+ throw new Error('useScrollRestoration must be used within a <ScrollRestorationProvider>.');
99
+ }
100
+ return store;
101
+ }
102
+
103
+ /**
104
+ * Preserve and restore the scroll offset of `target` across navigation, keyed
105
+ * by the active route (plus an optional `options.key` for routes that host
106
+ * multiple scrollables).
107
+ *
108
+ * Behaviour (web):
109
+ * - On every scroll while the screen is focused, the current offset is recorded
110
+ * in memory and persisted. This live stream of saves is the source of truth.
111
+ * - On focus, the saved offset is re-applied across a bounded run of animation
112
+ * frames, stopping as soon as the write sticks (the list has re-rendered its
113
+ * rows and grown tall enough) or {@link RESTORE_FRAME_CAP} is reached. A
114
+ * saved offset of 0 is a no-op (nothing to restore).
115
+ * - On blur, the LAST OBSERVED offset is persisted as a final safety net — not
116
+ * a fresh `scrollTop` read, which the navigator may already have forced to 0
117
+ * while collapsing the hidden screen.
118
+ */
119
+ function useScrollRestoration(target, options) {
120
+ const store = useScrollOffsetStore();
121
+ const route = (0, _native.useRoute)();
122
+ const subKey = options?.key;
123
+ const enabled = options?.enabled ?? true;
124
+ const scrollKey = (0, _store.deriveScrollKey)(route.key, subKey);
125
+
126
+ // Keep the latest target/enabled/key in refs so the focus effect can read
127
+ // them without being re-subscribed on every render.
128
+ const targetRef = (0, _react.useRef)(target);
129
+ targetRef.current = target;
130
+ const enabledRef = (0, _react.useRef)(enabled);
131
+ enabledRef.current = enabled;
132
+ const scrollKeyRef = (0, _react.useRef)(scrollKey);
133
+ scrollKeyRef.current = scrollKey;
134
+ (0, _native.useFocusEffect)(
135
+ // The effect identity is intentionally stable across renders: it reads all
136
+ // varying inputs from refs. React Navigation re-runs it on each focus.
137
+ (0, _react.useCallback)(() => {
138
+ const key = scrollKeyRef.current;
139
+ if (!enabledRef.current || key === null) return undefined;
140
+ const scroller = (0, _scrollableWeb.createScroller)(targetRef.current);
141
+ const element = targetRef.current === 'window' ? typeof window !== 'undefined' ? window : null : resolveScrollEventTarget(targetRef.current);
142
+
143
+ // The last offset the live scroll listener observed for this focus
144
+ // session. This — not a blur-time `getOffset()` — is what we persist on
145
+ // blur, because by blur time the navigator may have collapsed the
146
+ // hidden screen and forced its `scrollTop` to 0 (bug A). `null` means
147
+ // the user never scrolled this session, so there is nothing newer to
148
+ // persist than what the scroll listener already saved live.
149
+ let lastObservedOffset = null;
150
+ const save = () => {
151
+ const currentKey = scrollKeyRef.current;
152
+ if (!enabledRef.current || currentKey === null) return;
153
+ const offset = scroller.getOffset();
154
+ // Ignore a spurious 0 produced by the navigator collapsing a hidden
155
+ // background screen: while collapsed the container cannot scroll, so
156
+ // its `scrollTop` is forced to 0. Persisting it would clobber the
157
+ // good offset recorded by earlier live saves (bug A). A genuine
158
+ // scroll-to-top keeps the container scrollable and is saved normally.
159
+ if (offset === 0 && !scroller.canScroll()) return;
160
+ lastObservedOffset = offset;
161
+ store.save(currentKey, offset);
162
+ };
163
+
164
+ // Restore across a bounded run of frames. A freshly re-shown
165
+ // virtualized list re-lays out its rows over several frames, so a
166
+ // single write while it is still collapsed would be clamped to 0 and
167
+ // never re-applied (bug B). We re-apply each frame until the write
168
+ // sticks or the frame cap is hit.
169
+ const targetOffset = store.read(key);
170
+ let rafId = null;
171
+ if (targetOffset > 0 && typeof requestAnimationFrame !== 'undefined') {
172
+ let framesLeft = RESTORE_FRAME_CAP;
173
+ const applyOffset = () => {
174
+ rafId = null;
175
+ scroller.setOffset(targetOffset);
176
+ framesLeft -= 1;
177
+ // Stop once the write took effect (content grew tall enough) or we
178
+ // exhaust the frame budget. `getOffset` re-reads the clamped value.
179
+ const reached = Math.abs(scroller.getOffset() - targetOffset) <= RESTORE_STICK_TOLERANCE_PX;
180
+ if (!reached && framesLeft > 0) {
181
+ rafId = requestAnimationFrame(applyOffset);
182
+ }
183
+ };
184
+ rafId = requestAnimationFrame(applyOffset);
185
+ }
186
+ element?.addEventListener('scroll', save, {
187
+ passive: true
188
+ });
189
+ return () => {
190
+ if (rafId !== null) cancelAnimationFrame(rafId);
191
+ element?.removeEventListener('scroll', save);
192
+ // Final capture on blur: persist the last offset the scroll listener
193
+ // OBSERVED, never a fresh read (which the navigator may have forced
194
+ // to 0 while collapsing the hidden screen). When the user never
195
+ // scrolled this session there is nothing newer to persist than the
196
+ // live saves already recorded.
197
+ if (lastObservedOffset !== null) {
198
+ const currentKey = scrollKeyRef.current;
199
+ if (enabledRef.current && currentKey !== null) {
200
+ store.save(currentKey, lastObservedOffset);
201
+ }
202
+ }
203
+ };
204
+ }, [store]));
205
+ }
206
+
207
+ /**
208
+ * Resolve the EventTarget to listen for `scroll` on. RNW scroll components
209
+ * expose `getScrollableNode()`; raw refs may hold the DOM node directly.
210
+ */
211
+ function resolveScrollEventTarget(target) {
212
+ const current = target.current;
213
+ if (current == null) return null;
214
+ if (typeof EventTarget !== 'undefined' && current instanceof EventTarget) {
215
+ return current;
216
+ }
217
+ const handle = current;
218
+ if (typeof handle.getScrollableNode === 'function') {
219
+ const node = handle.getScrollableNode();
220
+ if (typeof EventTarget !== 'undefined' && node instanceof EventTarget) {
221
+ return node;
222
+ }
223
+ }
224
+ return null;
225
+ }
226
+ //# sourceMappingURL=index.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_native","_scrollableWeb","_store","_jsxRuntime","ScrollOffsetContext","createContext","displayName","RESTORE_FRAME_CAP","RESTORE_STICK_TOLERANCE_PX","history","scrollRestoration","ScrollRestorationProvider","children","store","useMemo","ScrollOffsetStore","jsx","Provider","value","useScrollOffsetStore","useContext","Error","useScrollRestoration","target","options","route","useRoute","subKey","key","enabled","scrollKey","deriveScrollKey","targetRef","useRef","current","enabledRef","scrollKeyRef","useFocusEffect","useCallback","undefined","scroller","createScroller","element","window","resolveScrollEventTarget","lastObservedOffset","save","currentKey","offset","getOffset","canScroll","targetOffset","read","rafId","requestAnimationFrame","framesLeft","applyOffset","setOffset","reached","Math","abs","addEventListener","passive","cancelAnimationFrame","removeEventListener","EventTarget","handle","getScrollableNode","node"],"sourceRoot":"../../../src","sources":["scroll/index.web.tsx"],"mappings":";;;;;;;AAkCA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAEA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAA6D,IAAAI,WAAA,GAAAJ,OAAA;AAtC7D;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;;AAmBA,MAAMK,mBAAmB,gBAAG,IAAAC,oBAAa,EAA2B,IAAI,CAAC;AACzED,mBAAmB,CAACE,WAAW,GAAG,0BAA0B;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,iBAAiB,GAAG,EAAE;;AAE5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,0BAA0B,GAAG,CAAC;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,OAAOC,OAAO,KAAK,WAAW,IAAI,mBAAmB,IAAIA,OAAO,EAAE;EACpEA,O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,GAAGhC,OAAgD;EAC/D,IAAI,OAAOgC,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,69 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createScroller = createScroller;
7
+ /**
8
+ * A normalized read/write interface over whatever the caller registered, so
9
+ * the hook does not branch on target shape. All methods are safe no-ops when
10
+ * the underlying element is not yet (or no longer) attached.
11
+ */
12
+
13
+ function isElement(value) {
14
+ return typeof HTMLElement !== 'undefined' && value instanceof HTMLElement;
15
+ }
16
+ function hasGetScrollableNode(value) {
17
+ return typeof value === 'object' && value !== null && typeof value.getScrollableNode === 'function';
18
+ }
19
+
20
+ /**
21
+ * Resolve the live DOM element a target currently points at, or `null`.
22
+ *
23
+ * RNW scroll components expose `getScrollableNode()`; plain refs may hold the
24
+ * DOM node directly. We never cache the node because RNW can swap it across
25
+ * renders — we re-resolve on every read/write.
26
+ */
27
+ function resolveElement(target) {
28
+ if (target === 'window') return null;
29
+ const current = target.current;
30
+ if (current == null) return null;
31
+ if (isElement(current)) return current;
32
+ if (hasGetScrollableNode(current)) {
33
+ const node = current.getScrollableNode();
34
+ if (isElement(node)) return node;
35
+ }
36
+ return null;
37
+ }
38
+
39
+ /**
40
+ * Build a {@link ResolvedScroller} for a target. The window sentinel reads and
41
+ * writes the document scroller; everything else operates on the resolved
42
+ * element's `scrollTop`.
43
+ */
44
+ function createScroller(target) {
45
+ if (target === 'window') {
46
+ return {
47
+ getOffset: () => typeof window === 'undefined' ? 0 : window.scrollY,
48
+ setOffset: offset => {
49
+ if (typeof window !== 'undefined') window.scrollTo(0, offset);
50
+ },
51
+ canScroll: () => true
52
+ };
53
+ }
54
+ return {
55
+ getOffset: () => {
56
+ const element = resolveElement(target);
57
+ return element ? element.scrollTop : 0;
58
+ },
59
+ setOffset: offset => {
60
+ const element = resolveElement(target);
61
+ if (element) element.scrollTop = offset;
62
+ },
63
+ canScroll: () => {
64
+ const element = resolveElement(target);
65
+ return element ? element.scrollHeight > element.clientHeight : false;
66
+ }
67
+ };
68
+ }
69
+ //# sourceMappingURL=scrollable.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["isElement","value","HTMLElement","hasGetScrollableNode","getScrollableNode","resolveElement","target","current","node","createScroller","getOffset","window","scrollY","setOffset","offset","scrollTo","canScroll","element","scrollTop","scrollHeight","clientHeight"],"sourceRoot":"../../../src","sources":["scroll/scrollable.web.ts"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACA;;AAkBA,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,EAAEA,MAAM,CAACI,QAAQ,CAAC,CAAC,EAAED,MAAM,CAAC;MAC/D,CAAC;MACDE,SAAS,EAAEA,CAAA,KAAM;IACnB,CAAC;EACH;EAEA,OAAO;IACLN,SAAS,EAAEA,CAAA,KAAM;MACf,MAAMO,OAAO,GAAGZ,cAAc,CAACC,MAAM,CAAC;MACtC,OAAOW,OAAO,GAAGA,OAAO,CAACC,SAAS,GAAG,CAAC;IACxC,CAAC;IACDL,SAAS,EAAGC,MAAM,IAAK;MACrB,MAAMG,OAAO,GAAGZ,cAAc,CAACC,MAAM,CAAC;MACtC,IAAIW,OAAO,EAAEA,OAAO,CAACC,SAAS,GAAGJ,MAAM;IACzC,CAAC;IACDE,SAAS,EAAEA,CAAA,KAAM;MACf,MAAMC,OAAO,GAAGZ,cAAc,CAACC,MAAM,CAAC;MACtC,OAAOW,OAAO,GAAGA,OAAO,CAACE,YAAY,GAAGF,OAAO,CAACG,YAAY,GAAG,KAAK;IACtE;EACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ScrollOffsetStore = void 0;
7
+ exports.deriveScrollKey = deriveScrollKey;
8
+ /**
9
+ * Pure, platform-agnostic core of the scroll-restoration primitive.
10
+ *
11
+ * This file deliberately contains NO React and NO DOM/native imports so the
12
+ * logic can be unit-tested in isolation and shared verbatim by the web and
13
+ * native barrels. The web barrel drives it with real scroll offsets; the
14
+ * native barrel never instantiates it (native-stack already restores scroll).
15
+ */
16
+
17
+ /**
18
+ * Separator between the navigation route key and an optional caller-supplied
19
+ * sub-key. A route may host more than one independently-scrolling list (e.g.
20
+ * a tabbed profile screen), so each list contributes its own sub-key.
21
+ *
22
+ * `\0` (NUL) can never appear in a React Navigation route key or in a
23
+ * developer-authored sub-key, so it is collision-free as a delimiter. It is
24
+ * written as an escape sequence (not a literal byte) so the source stays
25
+ * text-diffable.
26
+ */
27
+ const COMPOSITE_KEY_SEPARATOR = '\0';
28
+
29
+ /**
30
+ * Derive the storage key for a scrollable from its owning route key and an
31
+ * optional caller sub-key.
32
+ *
33
+ * - `routeKey` is React Navigation's stable per-route `route.key`.
34
+ * - `subKey` distinguishes multiple scrollables that share a single route.
35
+ *
36
+ * Returns `null` when there is no route key to anchor against (the scrollable
37
+ * is not inside a navigator), which the caller treats as "do not persist".
38
+ */
39
+ function deriveScrollKey(routeKey, subKey) {
40
+ if (!routeKey) return null;
41
+ if (subKey === undefined || subKey === '') return routeKey;
42
+ return `${routeKey}${COMPOSITE_KEY_SEPARATOR}${subKey}`;
43
+ }
44
+
45
+ /**
46
+ * In-memory map of `scrollKey -> last-known scroll offset`.
47
+ *
48
+ * Mirrors the semantics of Bluesky's `Map<screenKey, scrollY>`: offsets live
49
+ * only for the lifetime of the document/session. We never persist them — a
50
+ * full reload should start at the top — and we never auto-evict, because a
51
+ * route can be revisited via browser Forward/Back long after it blurred.
52
+ */
53
+ class ScrollOffsetStore {
54
+ offsets = new Map();
55
+
56
+ /** Persist the offset for a key. A negative offset is clamped to 0. */
57
+ save(key, offset) {
58
+ this.offsets.set(key, offset > 0 ? offset : 0);
59
+ }
60
+
61
+ /**
62
+ * Read the saved offset for a key. Returns `0` when nothing was saved, so
63
+ * callers can restore unconditionally (an unseen list restores to the top).
64
+ */
65
+ read(key) {
66
+ return this.offsets.get(key) ?? 0;
67
+ }
68
+
69
+ /** Whether an offset was ever saved for this key. */
70
+ has(key) {
71
+ return this.offsets.has(key);
72
+ }
73
+
74
+ /** Drop a saved offset (e.g. when a route is permanently removed). */
75
+ forget(key) {
76
+ this.offsets.delete(key);
77
+ }
78
+
79
+ /** Clear every saved offset. Primarily for tests and full resets. */
80
+ clear() {
81
+ this.offsets.clear();
82
+ }
83
+
84
+ /** Number of distinct keys currently tracked. */
85
+ get size() {
86
+ return this.offsets.size;
87
+ }
88
+ }
89
+ exports.ScrollOffsetStore = ScrollOffsetStore;
90
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["COMPOSITE_KEY_SEPARATOR","deriveScrollKey","routeKey","subKey","undefined","ScrollOffsetStore","offsets","Map","save","key","offset","set","read","get","has","forget","delete","clear","size","exports"],"sourceRoot":"../../../src","sources":["scroll/store.ts"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,uBAAuB,GAAG,IAAI;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,eAAeA,CAC7BC,QAA4B,EAC5BC,MAAe,EACA;EACf,IAAI,CAACD,QAAQ,EAAE,OAAO,IAAI;EAC1B,IAAIC,MAAM,KAAKC,SAAS,IAAID,MAAM,KAAK,EAAE,EAAE,OAAOD,QAAQ;EAC1D,OAAO,GAAGA,QAAQ,GAAGF,uBAAuB,GAAGG,MAAM,EAAE;AACzD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAME,iBAAiB,CAAC;EACZC,OAAO,GAAG,IAAIC,GAAG,CAAiB,CAAC;;EAEpD;EACAC,IAAIA,CAACC,GAAW,EAAEC,MAAc,EAAQ;IACtC,IAAI,CAACJ,OAAO,CAACK,GAAG,CAACF,GAAG,EAAEC,MAAM,GAAG,CAAC,GAAGA,MAAM,GAAG,CAAC,CAAC;EAChD;;EAEA;AACF;AACA;AACA;EACEE,IAAIA,CAACH,GAAW,EAAU;IACxB,OAAO,IAAI,CAACH,OAAO,CAACO,GAAG,CAACJ,GAAG,CAAC,IAAI,CAAC;EACnC;;EAEA;EACAK,GAAGA,CAACL,GAAW,EAAW;IACxB,OAAO,IAAI,CAACH,OAAO,CAACQ,GAAG,CAACL,GAAG,CAAC;EAC9B;;EAEA;EACAM,MAAMA,CAACN,GAAW,EAAQ;IACxB,IAAI,CAACH,OAAO,CAACU,MAAM,CAACP,GAAG,CAAC;EAC1B;;EAEA;EACAQ,KAAKA,CAAA,EAAS;IACZ,IAAI,CAACX,OAAO,CAACW,KAAK,CAAC,CAAC;EACtB;;EAEA;EACA,IAAIC,IAAIA,CAAA,EAAW;IACjB,OAAO,IAAI,CAACZ,OAAO,CAACY,IAAI;EAC1B;AACF;AAACC,OAAA,CAAAd,iBAAA,GAAAA,iBAAA","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["scroll/types.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Native variant of the scroll-restoration primitive — a deliberate no-op.
5
+ *
6
+ * React Navigation's native-stack keeps every screen mounted while it is in the
7
+ * stack, so a list's scroll position survives a push/pop for free. There is
8
+ * nothing to save or restore. We still ship the full API surface (provider +
9
+ * hook) so consumers write one set of call sites that compile and run on every
10
+ * platform; on native the provider just renders its children and the hook does
11
+ * nothing.
12
+ *
13
+ * Web bundlers select `./index.web` via the `"browser"` export condition in
14
+ * `package.json`; native bundlers fall through to this file.
15
+ */
16
+
17
+ /**
18
+ * No-op provider. Renders children unchanged — native scroll persistence is
19
+ * handled by the navigator, so no per-route state is kept.
20
+ */
21
+ export function ScrollRestorationProvider({
22
+ children
23
+ }) {
24
+ return children;
25
+ }
26
+
27
+ /**
28
+ * No-op hook. Accepts the same arguments as the web implementation so call
29
+ * sites are identical across platforms.
30
+ */
31
+ export function useScrollRestoration(_target, _options) {
32
+ // Intentionally empty: native-stack already preserves scroll position.
33
+ }
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ScrollRestorationProvider","children","useScrollRestoration","_target","_options"],"sourceRoot":"../../../src","sources":["scroll/index.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAeA;AACA;AACA;AACA;AACA,OAAO,SAASA,yBAAyBA,CAAC;EACxCC;AAC8B,CAAC,EAAgB;EAC/C,OAAOA,QAAQ;AACjB;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASC,oBAAoBA,CAClCC,OAAgC,EAChCC,QAAsC,EAChC;EACN;AAAA","ignoreList":[]}