cursedbelt 6.32.0 → 6.35.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.
Files changed (46) hide show
  1. package/dist/react/components/DataTable/useTableViewMode.d.ts +8 -8
  2. package/dist/react/components/DataTable/useTableViewMode.d.ts.map +1 -1
  3. package/dist/react/components/DataTable/useTableViewMode.js +8 -8
  4. package/dist/react/components/DataTable/useTableViewMode.js.map +1 -1
  5. package/dist/react/deep-link/index.d.ts +1 -1
  6. package/dist/react/deep-link/index.d.ts.map +1 -1
  7. package/dist/react/deep-link/index.js +1 -1
  8. package/dist/react/deep-link/index.js.map +1 -1
  9. package/dist/react/deep-link/links.d.ts +2 -3
  10. package/dist/react/deep-link/links.d.ts.map +1 -1
  11. package/dist/react/deep-link/links.js +4 -7
  12. package/dist/react/deep-link/links.js.map +1 -1
  13. package/dist/react/deep-link/resume.d.ts +17 -24
  14. package/dist/react/deep-link/resume.d.ts.map +1 -1
  15. package/dist/react/deep-link/resume.js +0 -127
  16. package/dist/react/deep-link/resume.js.map +1 -1
  17. package/dist/react/deep-link/useDeepLink.d.ts +4 -3
  18. package/dist/react/deep-link/useDeepLink.d.ts.map +1 -1
  19. package/dist/react/deep-link/useDeepLink.js +1 -1
  20. package/dist/react/deep-link/useDeepLink.js.map +1 -1
  21. package/dist/react/map-frame/MapFrame.d.ts +58 -8
  22. package/dist/react/map-frame/MapFrame.d.ts.map +1 -1
  23. package/dist/react/map-frame/MapFrame.js +132 -20
  24. package/dist/react/map-frame/MapFrame.js.map +1 -1
  25. package/dist/react/map-frame/geo.d.ts +66 -1
  26. package/dist/react/map-frame/geo.d.ts.map +1 -1
  27. package/dist/react/map-frame/geo.js +99 -1
  28. package/dist/react/map-frame/geo.js.map +1 -1
  29. package/dist/react/map-frame/index.d.ts +3 -3
  30. package/dist/react/map-frame/index.d.ts.map +1 -1
  31. package/dist/react/map-frame/index.js +2 -2
  32. package/dist/react/map-frame/index.js.map +1 -1
  33. package/package.json +2 -2
  34. package/src/react/components/DataTable/useTableViewMode.ts +9 -10
  35. package/src/react/deep-link/index.ts +0 -4
  36. package/src/react/deep-link/links.ts +5 -8
  37. package/src/react/deep-link/resume.spec.tsx +9 -215
  38. package/src/react/deep-link/resume.ts +13 -154
  39. package/src/react/deep-link/useDeepLink.tsx +5 -4
  40. package/src/react/map-frame/MapFrame.box.spec.tsx +73 -0
  41. package/src/react/map-frame/MapFrame.cover.spec.tsx +67 -0
  42. package/src/react/map-frame/MapFrame.tsx +168 -31
  43. package/src/react/map-frame/clusterFold.spec.ts +54 -0
  44. package/src/react/map-frame/fit.spec.ts +116 -0
  45. package/src/react/map-frame/geo.ts +132 -0
  46. package/src/react/map-frame/index.ts +12 -3
@@ -1,35 +1,20 @@
1
1
  /**
2
- * Resume — the last place you were, restored when you come back with no link.
2
+ * The per-account place store's browser client — `/api/resume`, `cursedbelt-server/resume`.
3
3
  *
4
- * The owner (2026-08-15): *"I want music app to load to where I left off when I
5
- * come back to it so I don't have to manually go there. For instance if I was in
6
- * the Main 1 folder on track 75 … Every app is supposed to get this feature as
7
- * the new standard because not having it is painful for users in all apps, owner
8
- * only apps too."*
4
+ * ── 🔴 Nothing here redirects. The URL the reader ENTERED is the place ───────
5
+ * The owner, 2026-11-24: *"Since we have deep links available it should always go
6
+ * to the actual entered url instead of trying to force the browser to another
7
+ * url. I want all the apps … to switch to deep links and letting the user choose
8
+ * where they go without the forced redirecting anymore."* That reverses
9
+ * 2026-08-15's "land where you left off": this module's `useResume`, which sent a
10
+ * bare entry to the last stored href, was deleted with music, its one user. A
11
+ * bare entry opens the app's front screen, a bookmark or link opens its place,
12
+ * and no stored value is ever written into the location on load — in any app.
9
13
  *
10
- * ── It is the deep-link primitive seen twice, not a second store ─────────────
11
- * Deep links make a place ADDRESSABLE; resume makes the last address STICKY. So
12
- * what is persisted is exactly the href this module already produces — no
13
- * parallel record of "which folder, which tab, which track", which would be a
14
- * second source of truth that drifts the first time a view gains a control.
15
- *
16
- * ── 🔴 A bare entry restores. An explicit deep link ALWAYS wins ──────────────
17
- * Landing on `#/` or `/` with nothing after it is the only case that restores.
18
- * If a shared link could be redirected to wherever the reader was last, every
19
- * link in the fleet would silently bounce — a worse bug than the one being
20
- * fixed. A visible way back to the true root is required of the app too, and the
21
- * nav's own home item is it: `navItemProps` targets the view root, and resume
22
- * only ever runs once per mount, so pressing home stays at home.
23
- *
24
- * ── Per user, server-side, not localStorage ─────────────────────────────────
25
- * The owner comes BACK to an app, plausibly from another device — which is the
26
- * whole point of the feature and the one thing `localStorage` cannot do. The
27
- * store is `cursedbelt-server/resume`, keyed by the app's own user id.
14
+ * What remains is the small per-account key/value client it was built on, which
15
+ * a preference that is NOT a place still uses (`useTableViewMode`'s rows-or-cards).
16
+ * A preference may shape the screen at the URL; it may not change the URL.
28
17
  */
29
- import React from 'react';
30
- import type { DeepLinkLocation, DeepLinks } from './links.js';
31
- import { useDeepLink } from './useDeepLink.js';
32
-
33
18
  export interface ResumeClient {
34
19
  /** The stored href, or null when nothing is stored (or the read failed). */
35
20
  read(): Promise<string | null>;
@@ -98,129 +83,3 @@ export function createResumeClient(options: ResumeClientOptions = {}): ResumeCli
98
83
  },
99
84
  };
100
85
  }
101
-
102
- export interface UseResumeOptions<V extends string> {
103
- client: ResumeClient;
104
- /** Off until the session is known — a signed-out read is a wasted 401. */
105
- enabled?: boolean;
106
- /** How long a location must hold still before it is recorded. Default 800ms. */
107
- debounceMs?: number;
108
- /**
109
- * Veto a restore. Called with the parsed stored location; return false and the
110
- * reader stays at the root (a deleted album, a tenant that no longer exists).
111
- */
112
- canRestore?(location: DeepLinkLocation<V>): boolean;
113
- }
114
-
115
- /**
116
- * The RAW entry URL, exactly as `useDeepLink`'s provider reads it.
117
- *
118
- * 🔴 Not `href`. `href` is the FORMATTED location, and formatting collapses the
119
- * one distinction the stale-restore guard below depends on: a bare `/` and an
120
- * explicit `#/` both format to `#/`, so "has the reader moved?" answered NO for
121
- * the single most common way of moving — opening the bookmark and then pressing
122
- * the app's own home/library item while the resume read is still in flight. The
123
- * restore then landed on top of a place the reader had just asked for.
124
- *
125
- * Measured 2026-08-20 as a red `bun run verify`: `apps/music`'s phone specs sign
126
- * in (entering bare), `goto("/#/")`, and wait for `.track-row`; under the full
127
- * gate the read is slow enough to lose the race and the page was yanked to the
128
- * visualizer. Green in isolation, red under load — which is what a race looks
129
- * like from outside, and why it survived several sessions as "pre-existing".
130
- */
131
- const rawEntryUrl = (): string =>
132
- typeof window === 'undefined'
133
- ? ''
134
- : `${window.location.pathname}${window.location.search}${window.location.hash}`;
135
-
136
- export interface UseResumeResult {
137
- /** False until the restore attempt has finished — render a spinner, not the root. */
138
- ready: boolean;
139
- /** True when this entry was restored rather than asked for. */
140
- restored: boolean;
141
- /** Forget the stored place — for a "start me at the top" control. */
142
- forget(): void;
143
- }
144
-
145
- export function useResume<V extends string = string>(options: UseResumeOptions<V>): UseResumeResult {
146
- const { client, enabled = true, debounceMs = 800, canRestore } = options;
147
- const { links, href, navigateTo, isBareEntry } = useDeepLink<V>();
148
- const [ready, setReady] = React.useState(!enabled);
149
- const [restored, setRestored] = React.useState(false);
150
- const attempted = React.useRef(false);
151
- const bareOnEntry = React.useRef(isBareEntry);
152
-
153
- /**
154
- * 🔴 The restore reads its collaborators through a ref, and the effect below
155
- * depends on `enabled` ALONE.
156
- *
157
- * Every one of them — `navigateTo`, `client`, `canRestore` — has an identity
158
- * that changes when the location changes, so a dependency list naming them
159
- * re-runs the effect mid-read. The re-run bailed on `attempted`, its cleanup
160
- * canceled the read in flight, `ready` never became true, and NOTHING WAS
161
- * EVER RECORDED. It was invisible in a hook test (the read resolved before
162
- * anything re-rendered) and reproduced every time in a browser, which is why
163
- * `apps/music/__smoke/deepLinks.spec.ts` exists.
164
- */
165
- const latest = React.useRef({ canRestore, client, links, navigateTo });
166
- latest.current = { canRestore, client, links, navigateTo };
167
- const hrefRef = React.useRef(href);
168
- hrefRef.current = href;
169
-
170
- React.useEffect(() => {
171
- if (!enabled || attempted.current) return;
172
- attempted.current = true;
173
- // 🔴 The explicit-link case, and it is checked BEFORE the read so a slow
174
- // endpoint can never race a reader who arrived with a real link.
175
- if (!bareOnEntry.current) {
176
- setReady(true);
177
- return;
178
- }
179
- let unmounted = false;
180
- // Where the reader was when the read STARTED. If they have moved by the time it
181
- // answers — pressed a nav item, followed a link, been redirected by a sign-in — the
182
- // restore is stale and must not drag them back. Same rule as "an explicit deep link
183
- // wins", applied to a link that arrived a moment later.
184
- const entryHref = hrefRef.current;
185
- const entryUrl = rawEntryUrl();
186
- void latest.current.client.read().then((stored) => {
187
- // Both, because they catch different moves: `href` catches a navigation to
188
- // a genuinely different place, and the raw URL catches the bare-to-`#/`
189
- // move that formatting makes invisible. Either one means the reader has
190
- // said where they want to be, and a stored place must never overrule that.
191
- if (unmounted || hrefRef.current !== entryHref || rawEntryUrl() !== entryUrl) {
192
- setReady(true);
193
- return;
194
- }
195
- const { canRestore: veto, links: table, navigateTo: go } = latest.current;
196
- if (stored) {
197
- const parsed = (table as DeepLinks<V>).parse(stored);
198
- if (!veto || veto(parsed)) {
199
- // `replace`, so Back leaves the app rather than bouncing between the
200
- // root and the restored place.
201
- go(parsed, { replace: true });
202
- setRestored(true);
203
- }
204
- }
205
- setReady(true);
206
- });
207
- return () => {
208
- unmounted = true;
209
- };
210
- }, [enabled]);
211
-
212
- // Record where the reader is, once they have stopped moving. Recording the
213
- // ROOT is deliberate and is how "take me back to the top" sticks.
214
- React.useEffect(() => {
215
- if (!enabled || !ready) return;
216
- const timer = setTimeout(() => void client.write(href), debounceMs);
217
- return () => clearTimeout(timer);
218
- }, [client, debounceMs, enabled, href, ready]);
219
-
220
- const forget = React.useCallback(() => void client.clear(), [client]);
221
- return { ready, restored, forget };
222
- }
223
-
224
- /** Exported for apps that want to record a place without the hook (a player). */
225
- export const resumeHrefOf = <V extends string>(links: DeepLinks<V>, location: DeepLinkLocation<V>): string =>
226
- links.format(location);
@@ -47,12 +47,13 @@ export interface DeepLinkContextValue<V extends string = string> {
47
47
  *
48
48
  * 🔴 It cannot be derived from `href`, which is the formatted location: parsing
49
49
  * and formatting a bookmark (`https://music…/`) produces `#/`, which is a real
50
- * link to the front screen and deliberately not bare. Computing it from `href`
51
- * made resume a no-op on the one entry it exists for.
50
+ * link to the front screen and deliberately not bare. A bare entry opens the
51
+ * front screen like `#/` does — nothing may redirect it to a remembered place
52
+ * (the owner, 2026-11-24; `resume.ts`).
52
53
  */
53
54
  entryWasBare: boolean;
54
55
  navigate(patch: DeepLinkPatch<V>, options?: DeepLinkNavigateOptions): void;
55
- /** Navigate to a whole location (what resume restores). */
56
+ /** Navigate to a whole location. */
56
57
  navigateTo(location: DeepLinkLocation<V>, options?: DeepLinkNavigateOptions): void;
57
58
  hrefFor(patch: DeepLinkPatch<V>): string;
58
59
  }
@@ -103,7 +104,7 @@ export function DeepLinkProvider<V extends string>({
103
104
  return { location, href: links.format(location), nonce: 0 };
104
105
  });
105
106
  // The entry URL, judged once, before anything normalizes it. See `entryWasBare`. A rescued
106
- // path link names a place, so it is never bare — resume must not bounce it elsewhere.
107
+ // path link names a place, so it is never bare.
107
108
  const [entryWasBare] = React.useState(() => links.isBare(entry));
108
109
  /** The raw URL the state initializer above actually read — the baseline for the
109
110
  * missed-event re-read in the listener effect. `null` when a caller passed
@@ -0,0 +1,73 @@
1
+ /**
2
+ * The mounted frame on a phone-shaped box (forge task 5916): it measures itself and asks for the
3
+ * ground the box shows, so Google's logo and attribution — in the render's corners — are in view, and
4
+ * its distance key sits in the visible corner above them. Reached through `MapFrame` alone, which
5
+ * exists on both sides of the fix.
6
+ */
7
+ import { afterEach, describe, expect, test } from 'bun:test';
8
+ import { cleanup, render } from '@testing-library/react';
9
+ import { MapFrame, VIEW_HEIGHT } from './MapFrame.js';
10
+
11
+ const LONDON = { lat: 51.5074, lng: -0.1278 };
12
+ /** A 390 phone's Places box, in CSS px: 4:5, so the slice shows the middle 320 of 640 units. */
13
+ const PHONE = { width: 357, height: 446 };
14
+ /** family's atlas at 1440 (forge task 5926): a unit draws max(1000/640, 775/400) ≈ 1.94 CSS px. */
15
+ const DESKTOP = { width: 1000, height: 775 };
16
+ const measure = (box: { width: number; height: number }) => {
17
+ Object.defineProperty(HTMLElement.prototype, 'clientWidth', { configurable: true, get: () => box.width });
18
+ Object.defineProperty(HTMLElement.prototype, 'clientHeight', { configurable: true, get: () => box.height });
19
+ };
20
+ /** The distance key's label size and bar length in CSS px, read off the drawn SVG. */
21
+ const keyInCss = (scale: Element, box: { width: number; height: number }) => {
22
+ const perUnit = box.width > 0 ? Math.max(box.width / 640, box.height / VIEW_HEIGHT) : 1;
23
+ const text = scale.querySelector('text') as SVGTextElement;
24
+ const bar = Number(/h([\d.]+)/.exec((scale.querySelector('path') as SVGPathElement).getAttribute('d') ?? '')?.[1]);
25
+ return { font: Number(text.getAttribute('font-size')) * perUnit, bar: bar * perUnit };
26
+ };
27
+ /** Google's foot in render px (`ATTRIBUTION_FOOT`), restated so this file needs nothing the fix added. */
28
+ const FOOT = 24;
29
+
30
+ afterEach(() => {
31
+ cleanup();
32
+ for (const key of ['clientWidth', 'clientHeight'] as const) delete (HTMLElement.prototype as unknown as Record<string, unknown>)[key];
33
+ });
34
+
35
+ describe('MapFrame — measures its box and asks for what it shows', () => {
36
+ test("on a phone-shaped box the render covers the middle 320 units, and the distance key sits inside them, above Google's foot", () => {
37
+ Object.defineProperty(HTMLElement.prototype, 'clientWidth', { configurable: true, get: () => PHONE.width });
38
+ Object.defineProperty(HTMLElement.prototype, 'clientHeight', { configurable: true, get: () => PHONE.height });
39
+ const { getByTestId } = render(
40
+ <MapFrame center={LONDON} zoom={6} theme='light' label='A map'>
41
+ {() => null}
42
+ </MapFrame>,
43
+ );
44
+ expect(getByTestId('map-preload').getAttribute('src')).toContain('&z=6&w=320&h=400&');
45
+ const plate = getByTestId('map-scale').querySelector('rect') as SVGRectElement;
46
+ expect(Number(plate.getAttribute('x'))).toBeGreaterThanOrEqual(160);
47
+ expect(Number(plate.getAttribute('y')) + Number(plate.getAttribute('height'))).toBeLessThanOrEqual(VIEW_HEIGHT - FOOT);
48
+ });
49
+
50
+ test('an unmeasured box (0×0) asks for the whole viewport, as before', () => {
51
+ const { getByTestId } = render(
52
+ <MapFrame center={LONDON} zoom={6} theme='light' label='A map'>
53
+ {() => null}
54
+ </MapFrame>,
55
+ );
56
+ expect(getByTestId('map-preload').getAttribute('src')).toContain('&z=6&w=640&h=400&');
57
+ });
58
+
59
+ test('the distance key is a 12-px caption at every box — a desktop box does not draw it twice its size', () => {
60
+ for (const box of [PHONE, DESKTOP, { width: 0, height: 0 }]) {
61
+ measure(box);
62
+ const { getByTestId, unmount } = render(
63
+ <MapFrame center={LONDON} zoom={3} theme='light' label='A map'>
64
+ {() => null}
65
+ </MapFrame>,
66
+ );
67
+ const key = keyInCss(getByTestId('map-scale'), box);
68
+ expect(key.font).toBeCloseTo(12, 5);
69
+ expect(key.bar).toBeLessThanOrEqual(110 + 1e-6);
70
+ unmount();
71
+ }
72
+ });
73
+ });
@@ -0,0 +1,67 @@
1
+ /**
2
+ * The picture covers what the box SHOWS (forge task 5916): Google's logo and "Map data ©" line sit in
3
+ * the render's corners, so a whole-viewport render sliced into a phone's 4:5 box cropped both away —
4
+ * and the zoom keys a consumer floats at the frame's foot sat on what was left. A narrow cover also
5
+ * lets a zoom past the middle of a step draw from the level above, crisp, under Google's 640.
6
+ */
7
+ import { describe, expect, test } from 'bun:test';
8
+ import { ATTRIBUTION_FOOT, attributionFoot, imagePlacement, mapImageSource, mapRender, VIEW_HEIGHT, VIEW_WIDTH } from './MapFrame.js';
9
+
10
+ const LONDON = { lat: 51.5074, lng: -0.1278 };
11
+ /** A 390 phone's Places box, in CSS px: 4:5, so the slice shows the middle 320 of 640 units. */
12
+ const PHONE = { width: 357, height: 446 };
13
+
14
+ describe('mapRender — one picture of the ground the box shows', () => {
15
+ test('the whole viewport at a whole level is the 640×400 it always was', () => {
16
+ expect(mapRender(6)).toEqual({ level: 6, width: 640, height: 400, cover: { width: 640, height: 400 } });
17
+ });
18
+
19
+ test("a phone's cover is half the width, at the same level", () => {
20
+ expect(mapRender(6, { width: 320, height: 400 })).toMatchObject({ level: 6, width: 320, height: 400 });
21
+ });
22
+
23
+ test('past the middle of a step, a narrow cover draws from the level ABOVE — shrunk, never stretched', () => {
24
+ const at = mapRender(4.6, { width: 320, height: 400 });
25
+ expect(at.level).toBe(5);
26
+ expect(at.width).toBe(Math.round(320 * 2 ** 0.4));
27
+ expect(at.width).toBeLessThanOrEqual(640);
28
+ });
29
+
30
+ test('short of the middle it stays on the level below, so labels are never shown under 1/√2', () => {
31
+ expect(mapRender(4.3, { width: 320, height: 400 }).level).toBe(4);
32
+ });
33
+
34
+ test("the whole viewport cannot go up (Google's 640 cap), so it stays on the level below", () => {
35
+ expect(mapRender(4.6)).toMatchObject({ level: 4, width: Math.round(640 / 2 ** 0.6) });
36
+ });
37
+
38
+ test('a sliver of a box grows to what /api/map draws at its own shape, and says what it covers', () => {
39
+ const at = mapRender(4.9, { width: 640, height: 60 });
40
+ expect(at.height).toBeGreaterThanOrEqual(80);
41
+ expect(at.cover.width / at.cover.height).toBeCloseTo(at.width / at.height, 6);
42
+ });
43
+
44
+ test("the URL names the render's level and size", () => {
45
+ expect(mapImageSource(LONDON, 4.6, 'dark', { width: 320, height: 400 })).toContain(`&z=5&w=${Math.round(320 * 2 ** 0.4)}&h=${Math.round(400 * 2 ** 0.4)}&`);
46
+ });
47
+ });
48
+
49
+ describe('imagePlacement — a cover is drawn over exactly that ground, centered', () => {
50
+ test('a 320×400 cover at the drawn zoom fills the middle of the viewport', () => {
51
+ const view = { center: LONDON, zoom: 6, width: VIEW_WIDTH, height: VIEW_HEIGHT };
52
+ const at = imagePlacement({ center: LONDON, zoom: 6, cover: { width: 320, height: 400 } }, view);
53
+ expect(at.x).toBeCloseTo(160, 6);
54
+ expect(at.y).toBeCloseTo(0, 6);
55
+ expect(at.width).toBeCloseTo(320, 6);
56
+ });
57
+ });
58
+
59
+ describe("attributionFoot — how high a control floats to clear Google's foot", () => {
60
+ test("a phone box at a whole level: Google's 24 render px at the box's 1.115 CSS px per unit", () => {
61
+ expect(attributionFoot(PHONE, 6)).toBe(Math.ceil(ATTRIBUTION_FOOT * (446 / 400)));
62
+ });
63
+
64
+ test('a picture from the level above is shrunk, and so is its foot', () => {
65
+ expect(attributionFoot(PHONE, 5.6)).toBeLessThan(attributionFoot(PHONE, 6));
66
+ });
67
+ });