cursedbelt 6.29.0 → 6.30.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 (68) hide show
  1. package/dist/react/canvas-hud/HudControls.d.ts +2 -0
  2. package/dist/react/canvas-hud/HudControls.d.ts.map +1 -1
  3. package/dist/react/canvas-hud/HudControls.js +3 -1
  4. package/dist/react/canvas-hud/HudControls.js.map +1 -1
  5. package/dist/react/components/ColorSwatches.d.ts.map +1 -1
  6. package/dist/react/components/ColorSwatches.js +1 -1
  7. package/dist/react/components/ColorSwatches.js.map +1 -1
  8. package/dist/react/components/DataTable/serverWindowWatch.d.ts +5 -4
  9. package/dist/react/components/DataTable/serverWindowWatch.d.ts.map +1 -1
  10. package/dist/react/components/DataTable/serverWindowWatch.js +7 -9
  11. package/dist/react/components/DataTable/serverWindowWatch.js.map +1 -1
  12. package/dist/react/components/ScrollArea.d.ts +9 -1
  13. package/dist/react/components/ScrollArea.d.ts.map +1 -1
  14. package/dist/react/components/ScrollArea.js +9 -3
  15. package/dist/react/components/ScrollArea.js.map +1 -1
  16. package/dist/react/components/TagsEditor.d.ts +12 -2
  17. package/dist/react/components/TagsEditor.d.ts.map +1 -1
  18. package/dist/react/components/TagsEditor.js +23 -8
  19. package/dist/react/components/TagsEditor.js.map +1 -1
  20. package/dist/react/lib/keepAsking.d.ts +30 -0
  21. package/dist/react/lib/keepAsking.d.ts.map +1 -0
  22. package/dist/react/lib/keepAsking.js +57 -0
  23. package/dist/react/lib/keepAsking.js.map +1 -0
  24. package/dist/react/lib/tagList.d.ts +15 -0
  25. package/dist/react/lib/tagList.d.ts.map +1 -1
  26. package/dist/react/lib/tagList.js +29 -0
  27. package/dist/react/lib/tagList.js.map +1 -1
  28. package/dist/react/map-frame/MapFrame.d.ts +11 -1
  29. package/dist/react/map-frame/MapFrame.d.ts.map +1 -1
  30. package/dist/react/map-frame/MapFrame.js +25 -2
  31. package/dist/react/map-frame/MapFrame.js.map +1 -1
  32. package/dist/react/map-frame/geo.d.ts +27 -0
  33. package/dist/react/map-frame/geo.d.ts.map +1 -1
  34. package/dist/react/map-frame/geo.js +38 -0
  35. package/dist/react/map-frame/geo.js.map +1 -1
  36. package/dist/react/map-frame/index.d.ts +4 -4
  37. package/dist/react/map-frame/index.d.ts.map +1 -1
  38. package/dist/react/map-frame/index.js +2 -2
  39. package/dist/react/map-frame/index.js.map +1 -1
  40. package/dist/styles-areas/core.css +8 -4
  41. package/dist/styles-utilities.css +18 -0
  42. package/package.json +9 -3
  43. package/scripts/build.spec.ts +39 -0
  44. package/scripts/build.ts +131 -0
  45. package/src/buildIsStaged.spec.ts +57 -47
  46. package/src/react/canvas-hud/HudControls.spec.tsx +13 -1
  47. package/src/react/canvas-hud/HudControls.tsx +3 -1
  48. package/src/react/components/ColorSwatches.tsx +5 -1
  49. package/src/react/components/DataTable/serverWindowWatch.ts +8 -9
  50. package/src/react/components/ScrollArea.spec.tsx +25 -0
  51. package/src/react/components/ScrollArea.tsx +18 -1
  52. package/src/react/components/TagsEditor.spec.tsx +66 -0
  53. package/src/react/components/TagsEditor.tsx +31 -7
  54. package/src/react/lib/keepAsking.spec.ts +89 -0
  55. package/src/react/lib/keepAsking.ts +63 -0
  56. package/src/react/lib/tagList.spec.ts +23 -1
  57. package/src/react/lib/tagList.ts +33 -0
  58. package/src/react/map-frame/MapFrame.tsx +33 -0
  59. package/src/react/map-frame/MapFrame.wheel.spec.tsx +69 -0
  60. package/src/react/map-frame/geo.spec.ts +32 -0
  61. package/src/react/map-frame/geo.ts +54 -0
  62. package/src/react/map-frame/index.ts +5 -2
  63. package/src/styles-areas/core.css +8 -4
  64. package/src/styles-utilities.css +18 -0
  65. package/src/stylesAreas.spec.ts +2 -1
  66. package/src/stylesStaticMatches.spec.ts +2 -3
  67. package/src/stylesUtilitiesMatches.spec.ts +2 -3
  68. package/src/verifyGraph.spec.ts +22 -6
@@ -0,0 +1,89 @@
1
+ /**
2
+ * keepAsking (forge task 5643, moved from music): the owner's music library
3
+ * went stale mid-session because a failed load was dropped and nothing asked twice.
4
+ */
5
+ import { afterEach, beforeEach, describe, expect, jest, test } from "bun:test";
6
+ import { keepAsking, retryDelayMs } from "./keepAsking.js";
7
+
8
+ beforeEach(() => {
9
+ jest.useFakeTimers();
10
+ });
11
+ afterEach(() => {
12
+ jest.useRealTimers();
13
+ });
14
+
15
+ /** Let a settled promise's handlers run. */
16
+ const tick = async (): Promise<void> => {
17
+ for (let i = 0; i < 5; i++) await Promise.resolve();
18
+ };
19
+
20
+ describe("keepAsking", () => {
21
+ test("🔴 a failed ask is asked again on the pause, and stops once one answers", async () => {
22
+ const outcomes = [false, false, true];
23
+ let asks = 0;
24
+ keepAsking(async () => {
25
+ const ok = outcomes[asks++];
26
+ if (!ok) throw new Error("ERR_HTTP2_PROTOCOL_ERROR");
27
+ }, new EventTarget());
28
+ await tick();
29
+ expect(asks).toBe(1);
30
+ jest.advanceTimersByTime(retryDelayMs(1));
31
+ await tick();
32
+ expect(asks).toBe(2);
33
+ jest.advanceTimersByTime(retryDelayMs(2));
34
+ await tick();
35
+ expect(asks).toBe(3);
36
+ jest.advanceTimersByTime(60_000);
37
+ await tick();
38
+ expect(asks, "an answered ask was asked again").toBe(3);
39
+ });
40
+
41
+ test("the network coming back asks at once", async () => {
42
+ const target = new EventTarget();
43
+ let asks = 0;
44
+ keepAsking(async () => {
45
+ asks += 1;
46
+ if (asks === 1) throw new Error("offline");
47
+ }, target);
48
+ await tick();
49
+ target.dispatchEvent(new Event("online"));
50
+ await tick();
51
+ expect(asks).toBe(2);
52
+ });
53
+
54
+ test("canceled, it asks no more and tells the ask out to throw its answer away", async () => {
55
+ let asks = 0;
56
+ let seenCanceled: (() => boolean) | null = null;
57
+ const stop = keepAsking(async (canceled) => {
58
+ asks += 1;
59
+ seenCanceled = canceled;
60
+ throw new Error("down");
61
+ }, new EventTarget());
62
+ await tick();
63
+ stop();
64
+ jest.advanceTimersByTime(60_000);
65
+ await tick();
66
+ expect(asks).toBe(1);
67
+ expect((seenCanceled as (() => boolean) | null)?.()).toBe(true);
68
+ });
69
+
70
+ test("the pause doubles from 2 s and holds at 30 s", () => {
71
+ expect([1, 2, 3, 4, 5, 9].map(retryDelayMs)).toEqual([2_000, 4_000, 8_000, 16_000, 30_000, 30_000]);
72
+ expect(retryDelayMs(Number.NaN)).toBe(2_000);
73
+ });
74
+ });
75
+
76
+ test("a resolved answer — even an empty one — ends the asking and stops listening for the network", async () => {
77
+ jest.useFakeTimers();
78
+ const target = new EventTarget();
79
+ let asks = 0;
80
+ keepAsking(async () => {
81
+ asks += 1;
82
+ return null;
83
+ }, target);
84
+ await tick();
85
+ target.dispatchEvent(new Event("online"));
86
+ jest.advanceTimersByTime(60_000);
87
+ await tick();
88
+ expect(asks).toBe(1);
89
+ });
@@ -0,0 +1,63 @@
1
+ /**
2
+ * `cursedbelt/react/keep-asking` — ask until it answers: a request that failed is asked again on a
3
+ * doubling pause, and at once when the network comes back (forge task 5643; moved here from music so
4
+ * collections and the next app share one copy).
5
+ *
6
+ * 2026-11-19, the owner: music's library *"all of a sudden"* stale or empty mid-session after a
7
+ * burst of `ERR_HTTP2_PROTOCOL_ERROR`, because page one of the view was asked for ONCE and a failure
8
+ * was dropped. The same mistake read a reset stream as "this item has no media" in collections'
9
+ * compare panel. A rejection is a dropped connection, not an answer: ask again. A RESOLVED answer —
10
+ * even an empty one — is the truth, and ends the asking.
11
+ *
12
+ * DataTable's server window re-asks rows on the same pacing (`windowRetryDelayMs` is this
13
+ * `retryDelayMs`).
14
+ */
15
+
16
+ /** The first re-ask waits this long — longer than a healthy request takes, so one still on its way is not asked twice. */
17
+ export const RETRY_FIRST_MS = 2_000;
18
+ /** …doubling to this, and holding there for good. */
19
+ export const RETRY_CEILING_MS = 30_000;
20
+
21
+ /** The pause before the `attempt`-th re-ask (1-based): 2 s, 4 s, 8 s, 16 s, then 30 s for good. */
22
+ export function retryDelayMs(attempt: number): number {
23
+ const n = Number.isFinite(attempt) ? Math.max(1, Math.floor(attempt)) : 1;
24
+ return Math.min(RETRY_CEILING_MS, RETRY_FIRST_MS * 2 ** (n - 1));
25
+ }
26
+
27
+ /** What `keepAsking` listens on for the network coming back — `window` in a page, anything with the two methods in a test. */
28
+ export type OnlineTarget = Pick<EventTarget, 'addEventListener' | 'removeEventListener'>;
29
+
30
+ /**
31
+ * Run `ask` now, and again after each rejection until one resolves or the returned canceler runs.
32
+ * `ask` gets whether it has been canceled, so a late answer can be thrown away rather than shown.
33
+ * A retry that is WAITING is brought forward when the network comes back; one already out is left
34
+ * to answer. Cancel on unmount and whenever what is being asked for changes.
35
+ */
36
+ export function keepAsking(ask: (canceled: () => boolean) => Promise<unknown>, target: OnlineTarget = window): () => void {
37
+ let canceled = false;
38
+ let attempt = 0;
39
+ let timer: ReturnType<typeof setTimeout> | undefined;
40
+ const isCanceled = (): boolean => canceled;
41
+ const run = (): void => {
42
+ clearTimeout(timer);
43
+ timer = undefined;
44
+ ask(isCanceled).then(
45
+ () => target.removeEventListener('online', onOnline),
46
+ () => {
47
+ if (canceled) return;
48
+ attempt += 1;
49
+ timer = setTimeout(run, retryDelayMs(attempt));
50
+ },
51
+ );
52
+ };
53
+ const onOnline = (): void => {
54
+ if (timer !== undefined) run();
55
+ };
56
+ target.addEventListener('online', onOnline);
57
+ run();
58
+ return () => {
59
+ canceled = true;
60
+ clearTimeout(timer);
61
+ target.removeEventListener('online', onOnline);
62
+ };
63
+ }
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, test } from 'bun:test';
2
- import { mergeTagLists, parseTagList, tagListText } from './tagList.js';
2
+ import { acceptTagList, cantBeATag, mergeTagLists, parseTagList, tagListText } from './tagList.js';
3
3
 
4
4
  describe('tags on the clipboard', () => {
5
5
  test('out as a comma line, back from commas, semicolons or lines — trimmed, each once', () => {
@@ -17,3 +17,25 @@ describe('tags on the clipboard', () => {
17
17
  expect(mergeTagLists(['dog'], ['beach', 'dog', 'sunset'])).toEqual(['dog', 'beach', 'sunset']);
18
18
  });
19
19
  });
20
+
21
+ describe('acceptTagList — a typed or pasted tag is spelled and checked like the app keeps it (forge task 5798)', () => {
22
+ const lower = (raw: string) => raw.trim().toLowerCase().replace(/[^a-z0-9 ]/g, '');
23
+ const whyNot = (raw: string) => (lower(raw).length < 2 ? `“${raw.trim()}” is too short` : null);
24
+
25
+ test('an added tag is respelled; the ones already there are kept exactly', () => {
26
+ expect(acceptTagList(['Kept As Is'], ['Kept As Is', ' Boats! '], lower)).toEqual({ tags: ['Kept As Is', 'boats'], refused: [] });
27
+ });
28
+
29
+ test('a tag whyNot refuses is left out with its reason', () => {
30
+ expect(acceptTagList(['a'], ['a', 'x'], lower, whyNot)).toEqual({ tags: ['a'], refused: ['“x” is too short'] });
31
+ });
32
+
33
+ test('a tag normalize turns into "" is refused with the default reason when there is no whyNot', () => {
34
+ expect(acceptTagList([], ['!!!'], lower)).toEqual({ tags: [], refused: [cantBeATag('!!!')] });
35
+ });
36
+
37
+ test('two spellings of one tag land once; a removal passes through', () => {
38
+ expect(acceptTagList([], ['Boat', 'boat'], lower).tags).toEqual(['boat']);
39
+ expect(acceptTagList(['a', 'b'], ['b']).tags).toEqual(['b']);
40
+ });
41
+ });
@@ -27,3 +27,36 @@ export function mergeTagLists(current: readonly string[], pasted: readonly strin
27
27
  for (const tag of pasted) if (!next.includes(tag)) next.push(tag);
28
28
  return next;
29
29
  }
30
+
31
+ /** The default refusal, when the app gives no `whyNot`. */
32
+ export const cantBeATag = (raw: string): string => `“${raw.trim()}” can't be a tag`;
33
+
34
+ /**
35
+ * A tag list as the tag field hands it over, checked (forge task 5798): every tag `next` ADDS over
36
+ * `current` asked `whyNot` (the app's reason a tag is refused, or null) and then spelled by
37
+ * `normalize`; one refused, or normalized to "", is left out with its reason. Tags already in
38
+ * `current` are kept exactly as they are, in `next`'s order, each once.
39
+ *
40
+ * Before this only a PASTE was normalized, so a TYPED chip showed text the app would refuse or
41
+ * respell — photos' "007" chip that the server answered with a bare "bad tag" (task 5797).
42
+ */
43
+ export function acceptTagList(
44
+ current: readonly string[],
45
+ next: readonly string[],
46
+ normalize: (raw: string) => string = (raw) => raw.trim(),
47
+ whyNot?: (raw: string) => string | null,
48
+ ): { tags: string[]; refused: string[] } {
49
+ const tags: string[] = [];
50
+ const refused: string[] = [];
51
+ for (const raw of next) {
52
+ if (current.includes(raw)) {
53
+ if (!tags.includes(raw)) tags.push(raw);
54
+ continue;
55
+ }
56
+ const problem = whyNot?.(raw) ?? null;
57
+ const tag = problem ? '' : normalize(raw);
58
+ if (!tag) refused.push(problem ?? cantBeATag(raw));
59
+ else if (!tags.includes(tag)) tags.push(tag);
60
+ }
61
+ return { tags, refused };
62
+ }
@@ -119,6 +119,8 @@
119
119
  * who went where; refusing to draw would be worse.
120
120
  */
121
121
  import React from "react";
122
+ import { CanvasZoomHint } from "../canvas-hud/HudControls.js";
123
+ import { readWheel } from "../canvas-hud/useCanvasWheel.js";
122
124
  import {
123
125
  type LatLng,
124
126
  MAX_ZOOM,
@@ -282,8 +284,20 @@ export interface MapFrameProps extends Omit<React.HTMLAttributes<HTMLDivElement>
282
284
  /** The URL of one rendered viewport. Defaults to {@link mapImageSource} — the app's own
283
285
  * `/api/map` proxy, which `cursedbelt-server/maps-static` serves the shared half of. */
284
286
  imageSource?: (center: LatLng, zoom: number, theme: "light" | "dark") => string;
287
+ /**
288
+ * What a plain wheel means (DESIGN CNV-1, forge task 5761). `"fullscreen"` (the default) —
289
+ * a map that IS the page, like family's atlas — zooms on every wheel. `"embedded"` — a map
290
+ * inside a scrolling page — zooms only on a pinch or with ⌘/Ctrl held; a plain wheel is left
291
+ * to scroll the page (no `preventDefault`) and the frame shows "Hold ⌘ to zoom" over itself.
292
+ */
293
+ wheel?: MapWheelMode;
285
294
  }
286
295
 
296
+ export type MapWheelMode = "embedded" | "fullscreen";
297
+
298
+ /** How long the embedded "Hold ⌘ to zoom" hint stays up after the last plain wheel. */
299
+ export const WHEEL_HINT_MS = 1200;
300
+
287
301
  /*
288
302
  * 🔴 Every style is INLINE, so an app mounts the frame with no stylesheet to import and no
289
303
  * class to keep in step (family's `.ft-map*` rules were the frame's whole CSS). A consumer
@@ -312,11 +326,17 @@ export function MapFrame({
312
326
  className,
313
327
  style,
314
328
  imageSource = mapImageSource,
329
+ wheel = "fullscreen",
315
330
  ...rest
316
331
  }: MapFrameProps) {
317
332
  /** Per instance: two frames on one page must not share one `<pattern>` id. */
318
333
  const graticuleId = `cb-map-graticule-${React.useId().replace(/:/g, "")}`;
319
334
  const svgRef = React.useRef<SVGSVGElement | null>(null);
335
+ // Read through a ref by the once-bound wheel listener, so a changed mode never re-binds it.
336
+ const wheelModeRef = React.useRef(wheel);
337
+ wheelModeRef.current = wheel;
338
+ const [wheelHint, setWheelHint] = React.useState(false);
339
+ const hintTimer = React.useRef<ReturnType<typeof setTimeout> | null>(null);
320
340
 
321
341
  /**
322
342
  * The viewport the reader is manipulating right now, fractional zoom and all.
@@ -514,6 +534,17 @@ export function MapFrame({
514
534
  if (!svg) return;
515
535
  const onWheel = (event: WheelEvent): void => {
516
536
  if (!committedRef.current.onViewChange) return;
537
+ // CNV-1: embedded, a plain wheel belongs to the page. Return BEFORE preventDefault so
538
+ // it scrolls, and say how to zoom instead.
539
+ if (wheelModeRef.current === "embedded" && readWheel("embedded", event) === "page") {
540
+ setWheelHint(true);
541
+ if (hintTimer.current) clearTimeout(hintTimer.current);
542
+ hintTimer.current = setTimeout(() => {
543
+ hintTimer.current = null;
544
+ setWheelHint(false);
545
+ }, WHEEL_HINT_MS);
546
+ return;
547
+ }
517
548
  event.preventDefault();
518
549
  stopGlide();
519
550
  const point = toViewportUnits(event);
@@ -556,6 +587,7 @@ export function MapFrame({
556
587
  React.useEffect(
557
588
  () => () => {
558
589
  if (wheelTimer.current) clearTimeout(wheelTimer.current);
590
+ if (hintTimer.current) clearTimeout(hintTimer.current);
559
591
  if (glide.current !== null) cancelAnimationFrame(glide.current);
560
592
  },
561
593
  [],
@@ -882,6 +914,7 @@ export function MapFrame({
882
914
  </g>
883
915
  <ScaleKey view={view} />
884
916
  </svg>
917
+ {wheel === "embedded" && onViewChange ? <CanvasZoomHint show={wheelHint} /> : null}
885
918
  </div>
886
919
  );
887
920
  }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * What a wheel over the map MEANS, per mode (DESIGN CNV-1, forge task 5761).
3
+ *
4
+ * An embedded map (trivia's Learn more, photos' Places) sits in a scrolling page: a plain wheel
5
+ * must scroll the page — no `preventDefault`, no committed view (a commit is a billable render)
6
+ * — and the frame says "Hold ⌘ to zoom". A pinch (ctrlKey) or ⌘ still zooms. A fullscreen map
7
+ * (family's atlas, the default) zooms on every wheel, as before.
8
+ */
9
+ import { afterEach, describe, expect, jest, test } from 'bun:test';
10
+ import { act, cleanup, render } from '@testing-library/react';
11
+ import { MapFrame, type MapWheelMode, VIEW_HEIGHT, VIEW_WIDTH, WHEEL_SETTLE_MS } from './MapFrame.js';
12
+
13
+ afterEach(() => {
14
+ cleanup();
15
+ jest.useRealTimers();
16
+ });
17
+
18
+ function mount(wheel: MapWheelMode | undefined) {
19
+ const onViewChange = jest.fn();
20
+ const { container } = render(
21
+ <MapFrame center={{ lat: 52.5, lng: -2.1 }} zoom={5} theme='light' label='A map' onViewChange={onViewChange} wheel={wheel}>
22
+ {() => null}
23
+ </MapFrame>,
24
+ );
25
+ const svg = container.querySelector('svg') as SVGSVGElement;
26
+ // happy-dom lays nothing out; the frame reads its box to anchor the zoom.
27
+ svg.getBoundingClientRect = () => ({ left: 0, top: 0, width: VIEW_WIDTH, height: VIEW_HEIGHT }) as DOMRect;
28
+ const spin = (init: WheelEventInit) => {
29
+ const event = new WheelEvent('wheel', { bubbles: true, cancelable: true, clientX: 320, clientY: 200, deltaY: -100, ...init });
30
+ // happy-dom's WheelEvent drops the modifier keys from its init; a browser keeps them.
31
+ for (const key of ['ctrlKey', 'metaKey', 'shiftKey'] as const) Object.defineProperty(event, key, { value: Boolean(init[key]) });
32
+ act(() => {
33
+ svg.dispatchEvent(event);
34
+ });
35
+ act(() => {
36
+ jest.advanceTimersByTime(WHEEL_SETTLE_MS + 10);
37
+ });
38
+ return event;
39
+ };
40
+ return { container, onViewChange, spin };
41
+ }
42
+
43
+ describe('MapFrame wheel modes', () => {
44
+ test('embedded: a plain wheel scrolls the page — no preventDefault, no committed view — and shows the hint', () => {
45
+ jest.useFakeTimers();
46
+ const { container, onViewChange, spin } = mount('embedded');
47
+ const event = spin({});
48
+ expect(event.defaultPrevented).toBe(false);
49
+ expect(onViewChange).not.toHaveBeenCalled();
50
+ expect(container.querySelector('[data-testid="canvas-zoom-hint"]')?.getAttribute('aria-hidden')).toBe('false');
51
+ });
52
+
53
+ test('embedded: a pinch (ctrlKey) zooms and commits ONE view', () => {
54
+ jest.useFakeTimers();
55
+ const { onViewChange, spin } = mount('embedded');
56
+ const event = spin({ ctrlKey: true });
57
+ expect(event.defaultPrevented).toBe(true);
58
+ expect(onViewChange).toHaveBeenCalledTimes(1);
59
+ });
60
+
61
+ test('fullscreen (the default): a plain wheel zooms, and no hint is drawn', () => {
62
+ jest.useFakeTimers();
63
+ const { container, onViewChange, spin } = mount(undefined);
64
+ const event = spin({});
65
+ expect(event.defaultPrevented).toBe(true);
66
+ expect(onViewChange).toHaveBeenCalledTimes(1);
67
+ expect(container.querySelector('[data-testid="canvas-zoom-hint"]')).toBeNull();
68
+ });
69
+ });
@@ -9,6 +9,7 @@
9
9
  */
10
10
  import { describe, expect, test } from "bun:test";
11
11
  import {
12
+ labelSides,
12
13
  boundsOf,
13
14
  centerOf,
14
15
  type Clusterable,
@@ -391,3 +392,34 @@ describe("clusterByScreen — the answer to forty pins on one degree", () => {
391
392
  });
392
393
  });
393
394
 
395
+
396
+ describe("labelSides — a pin's name stays inside what the box shows and off every other (forge task 5761)", () => {
397
+ // What a 358×448 phone box shows of the 640×400 viewport (visibleArea's slice).
398
+ const phone = { x: 160, width: 320 };
399
+ const mark = (name: string, x: number, y: number, rank = 0) => ({ x, y, r: 8, name: `${name} place`, rank });
400
+
401
+ test("reads to the right with room, to the left near the visible right edge", () => {
402
+ expect(labelSides([mark("green", 200, 100), mark("bellevue", 460, 300)], phone)).toEqual(["right", "left"]);
403
+ });
404
+
405
+ test("two names on one line: the lower rank chooses first, the other takes the free side", () => {
406
+ expect(labelSides([mark("pike", 200, 300, 0), mark("bellevue", 330, 300, 1)], phone)).toEqual(["right", "right"]);
407
+ expect(labelSides([mark("pike", 260, 300, 0), mark("bellevue", 300, 300, 1)], phone)).toEqual(["left", "right"]);
408
+ // Rank, not position, decides: the same two listed the other way round answer the same, by position.
409
+ expect(labelSides([mark("bellevue", 300, 300, 1), mark("pike", 260, 300, 0)], phone)).toEqual(["right", "left"]);
410
+ });
411
+
412
+ test("a name with no free side is left off, and a mark with no name is skipped", () => {
413
+ expect(labelSides([{ ...mark("long", 320, 300), name: "The house on the hill above the river where everyone stayed" }], phone)).toEqual([null]);
414
+ expect(labelSides([mark("west", 250, 300, 0), mark("east", 330, 300, 0), mark("mid", 265, 300, 1)], phone)).toEqual(["left", "right", null]);
415
+ expect(labelSides([{ x: 200, y: 100, r: 8, name: null }], phone)).toEqual([null]);
416
+ });
417
+
418
+ test("two pins on one spot: the first-ranked takes the right, the other the left", () => {
419
+ const marks = [
420
+ { name: "Sagrada Família", x: 500, y: 100, r: 7, rank: 3 },
421
+ { name: "Barcelona", x: 500, y: 100, r: 7, rank: 0 },
422
+ ];
423
+ expect(labelSides(marks, { x: 0, width: 640 })).toEqual(["left", "right"]);
424
+ });
425
+ });
@@ -419,3 +419,57 @@ function formatScaleNumber(value: number): string {
419
419
  * Mercator's ground resolution is defined against. */
420
420
  const EQUATOR_METRES = 40075016.686;
421
421
  const METRES_PER_MILE = 1609.344;
422
+
423
+ /** One pin a name may be printed beside, in viewport units. */
424
+ export interface LabelMark {
425
+ x: number;
426
+ y: number;
427
+ /** The pin's radius — the name starts just past it. */
428
+ r: number;
429
+ /** The name to print, or null for a pin with no name to place. */
430
+ name: string | null;
431
+ /** Who chooses first: the LOWER rank picks its side before the higher. Ties keep their order. Default 0. */
432
+ rank?: number;
433
+ }
434
+
435
+ /** A name's width per character at the overlay's 12-unit type — an estimate, kept on the generous side. */
436
+ export const LABEL_EM = 6.6;
437
+
438
+ /**
439
+ * Pure: which side of its pin each name reads on — right, else left, else not printed (null).
440
+ * Marks choose by `rank` (lowest first, so the right answer or the heaviest place gets its
441
+ * side before the rest); a name may not cover another name, any other pin, or run past
442
+ * `area` — the part of the frame the box actually shows (`visibleArea`). A name left off is
443
+ * still the pin's `<title>` and whatever list the app draws under the map.
444
+ *
445
+ * Returned BY POSITION, matching `marks` (forge task 5761 lifted it from photos' PlacesMap,
446
+ * which keyed by id, and trivia's LearnMap, which ranked by role).
447
+ */
448
+ export function labelSides(marks: readonly LabelMark[], area: { x: number; width: number }): ("right" | "left" | null)[] {
449
+ type Rect = { left: number; top: number; right: number; bottom: number };
450
+ const overlaps = (a: Rect, b: Rect): boolean => a.left < b.right && b.left < a.right && a.top < b.bottom && b.top < a.bottom;
451
+ const pins: Rect[] = marks.map((m) => ({ left: m.x - m.r, top: m.y - m.r, right: m.x + m.r, bottom: m.y + m.r }));
452
+ const taken: Rect[] = [];
453
+ const sides: ("right" | "left" | null)[] = marks.map(() => null);
454
+ const byRank = marks.map((m, i) => ({ m, i })).sort((a, b) => (a.m.rank ?? 0) - (b.m.rank ?? 0) || a.i - b.i);
455
+ for (const { m, i } of byRank) {
456
+ if (m.name === null) continue;
457
+ const width = m.name.length * LABEL_EM;
458
+ const top = m.y - 8;
459
+ const bottom = m.y + 6;
460
+ const candidates = [
461
+ { side: "right" as const, rect: { left: m.x + m.r + 4, top, right: m.x + m.r + 6 + width, bottom } },
462
+ { side: "left" as const, rect: { left: m.x - m.r - 6 - width, top, right: m.x - m.r - 4, bottom } },
463
+ ];
464
+ const fits = candidates.find(
465
+ ({ rect }) =>
466
+ rect.left >= area.x + 2 &&
467
+ rect.right <= area.x + area.width - 2 &&
468
+ !taken.some((t) => overlaps(t, rect)) &&
469
+ !pins.some((p, j) => j !== i && overlaps(p, rect)),
470
+ );
471
+ sides[i] = fits?.side ?? null;
472
+ if (fits) taken.push(fits.rect);
473
+ }
474
+ return sides;
475
+ }
@@ -2,7 +2,7 @@
2
2
  // overlay on top that projects with the same Web Mercator math, one billable render per
3
3
  // gesture (forge task 3700, lifted from apps/family). Its own subpath, so a page with no map
4
4
  // never pulls it in; the pure math is also its own leaf, `cursedbelt/react/map-frame/geo`.
5
- export type { Bounds, Cluster, Clusterable, LatLng, Viewport } from './geo.js';
5
+ export type { Bounds, Cluster, Clusterable, LabelMark, LatLng, Viewport } from './geo.js';
6
6
  export {
7
7
  boundsOf,
8
8
  centerOf,
@@ -10,6 +10,8 @@ export {
10
10
  formatDistance,
11
11
  fromWorldFraction,
12
12
  haversineKm,
13
+ LABEL_EM,
14
+ labelSides,
13
15
  MAX_ZOOM,
14
16
  MERCATOR_MAX_LAT,
15
17
  MIN_ZOOM,
@@ -21,7 +23,7 @@ export {
21
23
  zoomAnchoredAt,
22
24
  zoomToFit,
23
25
  } from './geo.js';
24
- export type { MapFrameProps } from './MapFrame.js';
26
+ export type { MapFrameProps, MapWheelMode } from './MapFrame.js';
25
27
  export {
26
28
  imagePlacement,
27
29
  MapFrame,
@@ -30,5 +32,6 @@ export {
30
32
  VIEW_HEIGHT,
31
33
  VIEW_WIDTH,
32
34
  visibleArea,
35
+ WHEEL_HINT_MS,
33
36
  WHEEL_SETTLE_MS,
34
37
  } from './MapFrame.js';
@@ -15,7 +15,7 @@
15
15
  * after an app's responsive variant (task 2124). An app that imports every area gets exactly
16
16
  * what `cursedbelt/styles-utilities.css` emits — proved rule by rule in
17
17
  * src/stylesAreas.spec.ts, which is also what fails when this file is stale.
18
- * 1027 candidate(s).
18
+ * 1033 candidate(s).
19
19
  *
20
20
  * Written by scripts/generateAreaStyles.ts (`bun run styles:areas`), which
21
21
  * `bun run build` runs. The map of what is in which area, and why the areas are
@@ -153,9 +153,12 @@
153
153
  @source inline("lead leading leading-4 leading-5 leading-none leading-relaxed leading-snug leading-tight left");
154
154
  @source inline("left-0 left-1/2 left-2 left-3 lg lg:px-8 line line-clamp-2 lo low lower lowercase m m-0 max");
155
155
  @source inline("max-h max-h-64 max-h-[80vh] max-h-[calc(var(--radix-popper-available-height,100dvh)-1rem)]");
156
- @source inline("max-h-[var(--guide-popover-max-h)] max-h-[var(--radix-select-content-available-height)]");
157
- @source inline("max-h-[var(--sheet-h-lg)] max-h-[var(--sheet-h-md)] max-h-[var(--sheet-h-sm)] max-sm:border-b-0");
158
- @source inline("max-sm:border-x-0 max-sm:bottom-0 max-sm:data-[state=closed]:slide-out-to-bottom");
156
+ @source inline("max-h-[min(var(--region-h-lg),var(--region-h-phone))]");
157
+ @source inline("max-h-[min(var(--region-h-md),var(--region-h-phone))]");
158
+ @source inline("max-h-[min(var(--region-h-sm),var(--region-h-phone))] max-h-[var(--guide-popover-max-h)]");
159
+ @source inline("max-h-[var(--radix-select-content-available-height)] max-h-[var(--sheet-h-lg)]");
160
+ @source inline("max-h-[var(--sheet-h-md)] max-h-[var(--sheet-h-sm)] max-sm:border-b-0 max-sm:border-x-0");
161
+ @source inline("max-sm:bottom-0 max-sm:data-[state=closed]:slide-out-to-bottom");
159
162
  @source inline("max-sm:data-[state=open]:slide-in-from-bottom max-sm:h-dvh max-sm:hidden max-sm:inset-x-0");
160
163
  @source inline("max-sm:max-h-[var(--sheet-h-phone)] max-sm:max-h-dvh max-sm:max-w-none max-sm:pt-6");
161
164
  @source inline("max-sm:rounded-b-none max-sm:rounded-none max-sm:rounded-t-2xl max-sm:sr-only max-sm:touch-none");
@@ -193,6 +196,7 @@
193
196
  @source inline("sm:-translate-x-1/2 sm:-translate-y-1/2 sm:basis-auto sm:block sm:flex-nowrap");
194
197
  @source inline("sm:h-[var(--region-h-lg)] sm:h-[var(--region-h-md)] sm:h-[var(--region-h-sm)] sm:hidden");
195
198
  @source inline("sm:left-1/2 sm:max-h-[calc(100dvh-2rem)] sm:max-h-[min(90dvh,calc(100dvh-2rem))]");
199
+ @source inline("sm:max-h-[var(--region-h-lg)] sm:max-h-[var(--region-h-md)] sm:max-h-[var(--region-h-sm)]");
196
200
  @source inline("sm:max-w-[calc(100vw-2rem)] sm:max-w-[var(--modal-w-lg)] sm:max-w-[var(--modal-w-md)]");
197
201
  @source inline("sm:max-w-[var(--modal-w-sm)] sm:order-2 sm:order-4 sm:p-4 sm:p-5 sm:p-8 sm:pointer-fine:text-sm");
198
202
  @source inline("sm:px-6 sm:rounded-xl sm:text-sm sm:top-1/2 sm:w-[calc(100vw-2rem)] space space-y-1 space-y-3");
@@ -875,6 +875,15 @@
875
875
  .max-h-\[inherit\] {
876
876
  max-height: inherit;
877
877
  }
878
+ .max-h-\[min\(var\(--region-h-lg\)\,var\(--region-h-phone\)\)\] {
879
+ max-height: min(var(--region-h-lg), var(--region-h-phone));
880
+ }
881
+ .max-h-\[min\(var\(--region-h-md\)\,var\(--region-h-phone\)\)\] {
882
+ max-height: min(var(--region-h-md), var(--region-h-phone));
883
+ }
884
+ .max-h-\[min\(var\(--region-h-sm\)\,var\(--region-h-phone\)\)\] {
885
+ max-height: min(var(--region-h-sm), var(--region-h-phone));
886
+ }
878
887
  .max-h-\[var\(--guide-popover-max-h\)\] {
879
888
  max-height: var(--guide-popover-max-h);
880
889
  }
@@ -5028,6 +5037,15 @@
5028
5037
  .sm\:max-h-\[min\(90dvh\,calc\(100dvh-2rem\)\)\] {
5029
5038
  max-height: min(90dvh, calc(100dvh - 2rem));
5030
5039
  }
5040
+ .sm\:max-h-\[var\(--region-h-lg\)\] {
5041
+ max-height: var(--region-h-lg);
5042
+ }
5043
+ .sm\:max-h-\[var\(--region-h-md\)\] {
5044
+ max-height: var(--region-h-md);
5045
+ }
5046
+ .sm\:max-h-\[var\(--region-h-sm\)\] {
5047
+ max-height: var(--region-h-sm);
5048
+ }
5031
5049
  .sm\:min-h-0 {
5032
5050
  min-height: 0px;
5033
5051
  }
@@ -59,6 +59,7 @@ import {
59
59
  nonModuleFiles,
60
60
  transitiveNeeds,
61
61
  } from '../scripts/styleAreas.js';
62
+ import { BUILD_STEPS } from '../scripts/build.js';
62
63
 
63
64
  const areas = await readAreaStyles();
64
65
  const { closures } = await areaClosures();
@@ -263,7 +264,7 @@ describe('the per-area stylesheets are generated and gated', () => {
263
264
  it('is regenerated by the build, so a stale area cannot be published', () => {
264
265
  // `prepublishOnly` → `verify` → `build`, so the tarball's copies are always the
265
266
  // ones this repo's current src/react produces.
266
- expect((pkg as { scripts: Record<string, string> }).scripts.build).toContain('scripts/generateAreaStyles.ts');
267
+ expect(BUILD_STEPS.some((step) => step.cmd.includes('scripts/generateAreaStyles.ts'))).toBe(true);
267
268
  expect((pkg as { scripts: Record<string, string> }).scripts.styles).toContain('styles:areas');
268
269
  });
269
270
  });
@@ -43,6 +43,7 @@ import {
43
43
  readStylesheets,
44
44
  staticStylesFrom,
45
45
  } from '../scripts/generateStaticStyles.js';
46
+ import { BUILD_STEPS } from '../scripts/build.js';
46
47
 
47
48
  const { source, expected, onDisk } = await readStylesheets();
48
49
 
@@ -121,9 +122,7 @@ describe('styles-static.css is a generated, gated copy of styles.css', () => {
121
122
  // one this repo's current styles.css produces. Without this step in `build`,
122
123
  // the only thing standing between a drifted copy and a publish is a person
123
124
  // remembering to run a script.
124
- expect((pkg as { scripts: Record<string, string> }).scripts.build).toContain(
125
- 'scripts/generateStaticStyles.ts',
126
- );
125
+ expect(BUILD_STEPS.some((step) => step.cmd.includes('scripts/generateStaticStyles.ts'))).toBe(true);
127
126
  });
128
127
 
129
128
  it('exposes the transform as a pure function', () => {
@@ -55,6 +55,7 @@ import {
55
55
  compileStylesheet,
56
56
  readUtilityStylesheet,
57
57
  } from '../scripts/generateUtilityStyles.js';
58
+ import { BUILD_STEPS } from '../scripts/build.js';
58
59
 
59
60
  const { expected, onDisk, candidates } = await readUtilityStylesheet();
60
61
 
@@ -240,8 +241,6 @@ describe('styles-utilities.css is a generated, gated precompile of src/react', (
240
241
  it('is regenerated by the build, so a stale artifact cannot be published', () => {
241
242
  // `prepublishOnly` → `verify` → `build`, so the tarball's copy is always the
242
243
  // one this repo's current src/react produces.
243
- expect((pkg as { scripts: Record<string, string> }).scripts.build).toContain(
244
- 'scripts/generateUtilityStyles.ts',
245
- );
244
+ expect(BUILD_STEPS.some((step) => step.cmd.includes('scripts/generateUtilityStyles.ts'))).toBe(true);
246
245
  });
247
246
  });