@sybilion/uilib 1.4.37 → 1.4.40

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 (101) hide show
  1. package/dist/agent-glossary/workspace.generated.ts +1 -0
  2. package/dist/agent-glossary/workspace.index.md +1 -0
  3. package/dist/agent-glossary/workspace.md +1 -0
  4. package/dist/esm/src/components/ui/Banner/Banner.styl.js +1 -1
  5. package/dist/esm/src/components/ui/Chart/Chart.js +1 -2
  6. package/dist/esm/src/components/ui/Dialog/Dialog.styl.js +1 -1
  7. package/dist/esm/src/components/ui/Drawer/Drawer.styl.js +1 -1
  8. package/dist/esm/src/components/ui/DropdownMenu/DropdownMenu.styl.js +1 -1
  9. package/dist/esm/src/components/ui/MobileAdaptiveSelector/MobileAdaptiveSelector.styl.js +1 -1
  10. package/dist/esm/src/components/ui/Page/PageHeader/PageHeader.styl.js +1 -1
  11. package/dist/esm/src/components/ui/Select/Select.js +313 -5
  12. package/dist/esm/src/components/ui/Select/Select.styl.js +2 -2
  13. package/dist/esm/src/components/ui/Sheet/Sheet.styl.js +1 -1
  14. package/dist/esm/src/components/ui/SupplyChainMap/SupplyChainMap.js +384 -0
  15. package/dist/esm/src/components/ui/SupplyChainMap/SupplyChainMap.styl.js +7 -0
  16. package/dist/esm/src/components/ui/SupplyChainMap/map-colors.js +44 -0
  17. package/dist/esm/src/components/ui/SupplyChainMap/map-disclosure.js +142 -0
  18. package/dist/esm/src/components/ui/SupplyChainMap/map-labels.js +55 -0
  19. package/dist/esm/src/components/ui/SupplyChainMap/map-projection.js +186 -0
  20. package/dist/esm/src/components/ui/SupplyChainMap/supply-chain-map-clusters.js +96 -0
  21. package/dist/esm/src/components/ui/SupplyChainMap/supply-chain-map-draw.js +66 -0
  22. package/dist/esm/src/components/ui/SupplyChainMap/supply-chain-map-scene.js +59 -0
  23. package/dist/esm/src/components/ui/SupplyChainMap/supply-chain-map-types.js +10 -0
  24. package/dist/esm/src/components/ui/SupplyChainMap/use-map-base-renderer.js +122 -0
  25. package/dist/esm/src/components/ui/Table/Table.styl.js +1 -1
  26. package/dist/esm/src/components/ui/Tabs/Tabs.styl.js +1 -1
  27. package/dist/esm/src/components/ui/Tooltip/Tooltip.styl.js +1 -1
  28. package/dist/esm/src/components/widgets/DriverCard/DriverPerformanceChart.js +1 -2
  29. package/dist/esm/src/index.js +2 -0
  30. package/dist/esm/types/src/components/ui/Select/Select.d.ts +3 -3
  31. package/dist/esm/types/src/components/ui/Select/Select.types.d.ts +3 -1
  32. package/dist/esm/types/src/components/ui/SupplyChainMap/SupplyChainMap.contract.test.d.ts +1 -0
  33. package/dist/esm/types/src/components/ui/SupplyChainMap/SupplyChainMap.d.ts +2 -0
  34. package/dist/esm/types/src/components/ui/SupplyChainMap/SupplyChainMap.example.d.ts +1 -0
  35. package/dist/esm/types/src/components/ui/SupplyChainMap/SupplyChainMap.render.worker.d.ts +15 -0
  36. package/dist/esm/types/src/components/ui/SupplyChainMap/SupplyChainMap.types.d.ts +10 -0
  37. package/dist/esm/types/src/components/ui/SupplyChainMap/index.d.ts +3 -0
  38. package/dist/esm/types/src/components/ui/SupplyChainMap/map-colors.d.ts +43 -0
  39. package/dist/esm/types/src/components/ui/SupplyChainMap/map-disclosure.d.ts +35 -0
  40. package/dist/esm/types/src/components/ui/SupplyChainMap/map-disclosure.test.d.ts +1 -0
  41. package/dist/esm/types/src/components/ui/SupplyChainMap/map-labels.d.ts +14 -0
  42. package/dist/esm/types/src/components/ui/SupplyChainMap/map-labels.test.d.ts +1 -0
  43. package/dist/esm/types/src/components/ui/SupplyChainMap/map-projection.d.ts +83 -0
  44. package/dist/esm/types/src/components/ui/SupplyChainMap/map-projection.test.d.ts +1 -0
  45. package/dist/esm/types/src/components/ui/SupplyChainMap/supply-chain-map-clusters.d.ts +25 -0
  46. package/dist/esm/types/src/components/ui/SupplyChainMap/supply-chain-map-clusters.test.d.ts +1 -0
  47. package/dist/esm/types/src/components/ui/SupplyChainMap/supply-chain-map-draw.d.ts +30 -0
  48. package/dist/esm/types/src/components/ui/SupplyChainMap/supply-chain-map-scene.d.ts +28 -0
  49. package/dist/esm/types/src/components/ui/SupplyChainMap/supply-chain-map-scene.test.d.ts +1 -0
  50. package/dist/esm/types/src/components/ui/SupplyChainMap/supply-chain-map-types.d.ts +31 -0
  51. package/dist/esm/types/src/components/ui/SupplyChainMap/use-map-base-renderer.d.ts +14 -0
  52. package/dist/esm/types/src/docs/pages/BannerPage.d.ts +1 -0
  53. package/dist/esm/types/src/docs/pages/SupplyChainMapPage.d.ts +1 -0
  54. package/dist/esm/types/src/index.d.ts +1 -0
  55. package/dist/esm/types/src/lib/logger.d.ts +1 -0
  56. package/package.json +7 -1
  57. package/src/components/ui/Banner/Banner.styl +1 -1
  58. package/src/components/ui/Dialog/Dialog.styl +2 -2
  59. package/src/components/ui/Drawer/Drawer.styl +2 -2
  60. package/src/components/ui/DropdownMenu/DropdownMenu.styl +2 -2
  61. package/src/components/ui/MobileAdaptiveSelector/MobileAdaptiveSelector.styl +1 -1
  62. package/src/components/ui/Page/PageHeader/PageHeader.styl +1 -1
  63. package/src/components/ui/Select/AGENT.md +3 -1
  64. package/src/components/ui/Select/Select.styl +31 -0
  65. package/src/components/ui/Select/Select.styl.d.ts +28 -25
  66. package/src/components/ui/Select/Select.tsx +506 -4
  67. package/src/components/ui/Select/Select.types.ts +3 -1
  68. package/src/components/ui/Sheet/Sheet.styl +2 -2
  69. package/src/components/ui/SupplyChainMap/AGENT.md +45 -0
  70. package/src/components/ui/SupplyChainMap/SupplyChainMap.contract.test.ts +45 -0
  71. package/src/components/ui/SupplyChainMap/SupplyChainMap.example.tsx +176 -0
  72. package/src/components/ui/SupplyChainMap/SupplyChainMap.render.worker.ts +63 -0
  73. package/src/components/ui/SupplyChainMap/SupplyChainMap.styl +221 -0
  74. package/src/components/ui/SupplyChainMap/SupplyChainMap.styl.d.ts +25 -0
  75. package/src/components/ui/SupplyChainMap/SupplyChainMap.tsx +720 -0
  76. package/src/components/ui/SupplyChainMap/SupplyChainMap.types.ts +15 -0
  77. package/src/components/ui/SupplyChainMap/index.ts +11 -0
  78. package/src/components/ui/SupplyChainMap/map-colors.ts +66 -0
  79. package/src/components/ui/SupplyChainMap/map-disclosure.test.ts +237 -0
  80. package/src/components/ui/SupplyChainMap/map-disclosure.ts +226 -0
  81. package/src/components/ui/SupplyChainMap/map-labels.test.ts +102 -0
  82. package/src/components/ui/SupplyChainMap/map-labels.ts +85 -0
  83. package/src/components/ui/SupplyChainMap/map-projection.test.ts +172 -0
  84. package/src/components/ui/SupplyChainMap/map-projection.ts +281 -0
  85. package/src/components/ui/SupplyChainMap/supply-chain-map-clusters.test.ts +182 -0
  86. package/src/components/ui/SupplyChainMap/supply-chain-map-clusters.ts +127 -0
  87. package/src/components/ui/SupplyChainMap/supply-chain-map-draw.ts +114 -0
  88. package/src/components/ui/SupplyChainMap/supply-chain-map-scene.test.ts +196 -0
  89. package/src/components/ui/SupplyChainMap/supply-chain-map-scene.ts +118 -0
  90. package/src/components/ui/SupplyChainMap/supply-chain-map-types.ts +45 -0
  91. package/src/components/ui/SupplyChainMap/use-map-base-renderer.ts +145 -0
  92. package/src/components/ui/Table/Table.styl +3 -3
  93. package/src/components/ui/Tabs/Tabs.styl +1 -0
  94. package/src/components/ui/Tooltip/Tooltip.styl +7 -2
  95. package/src/declarations.d.ts +4 -0
  96. package/src/docs/pages/BannerPage.tsx +83 -0
  97. package/src/docs/pages/FeedbackOverviewPage.tsx +7 -1
  98. package/src/docs/pages/SelectPage.tsx +30 -1
  99. package/src/docs/pages/SupplyChainMapPage.tsx +21 -0
  100. package/src/docs/registry.ts +12 -0
  101. package/src/index.ts +1 -0
@@ -0,0 +1,384 @@
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
+ import cn from 'classnames';
3
+ import { useRef, useState, useMemo, useEffect, useCallback } from 'react';
4
+ import { useTheme } from '../../../contexts/theme-context.js';
5
+ import S from './SupplyChainMap.styl.js';
6
+ import { mapBasemapPalette, MAP_COLORS_DARK, MAP_COLORS } from './map-colors.js';
7
+ import { resolveMapDisclosureAnchors, discloseMapScene } from './map-disclosure.js';
8
+ import { placeMapLabels } from './map-labels.js';
9
+ import { syntheticAltitude, clampCamera, HOME_CAMERA, cameraFitPoints, zoomCamera, ZOOM_STEP, panCamera, mapProjection, MIN_ZOOM, projectPoint, cameraCenteredOn } from './map-projection.js';
10
+ import { forceOpenExpired, clusterMapNodes, remapArcsToClusters, CLUSTER_RADIUS_PX } from './supply-chain-map-clusters.js';
11
+ import { buildConfirmedMapScene, resolveMapSelection } from './supply-chain-map-scene.js';
12
+ import { activeMapCascade } from './supply-chain-map-types.js';
13
+ import { useMapBaseRenderer } from './use-map-base-renderer.js';
14
+
15
+ const DRAG_THRESHOLD_PX = 4;
16
+ const LANE_HIT_PX = 7;
17
+ const FLY_MS = 700;
18
+ function labelTier(altitude) {
19
+ if (altitude > 1.6)
20
+ return 'far';
21
+ if (altitude > 0.9)
22
+ return 'mid';
23
+ return 'near';
24
+ }
25
+ function easeInOutCubic(t) {
26
+ return t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2;
27
+ }
28
+ function segmentDistance(px, py, ax, ay, bx, by) {
29
+ const dx = bx - ax;
30
+ const dy = by - ay;
31
+ const lenSq = dx * dx + dy * dy;
32
+ const t = lenSq === 0
33
+ ? 0
34
+ : Math.max(0, Math.min(1, ((px - ax) * dx + (py - ay) * dy) / lenSq));
35
+ return Math.hypot(px - (ax + t * dx), py - (ay + t * dy));
36
+ }
37
+ function inspectionLocation(node) {
38
+ return ([node.place, node.country, node.precision].filter(Boolean).join(' · ') ||
39
+ null);
40
+ }
41
+ function orgNodeId(entities) {
42
+ return entities.find(entity => entity.type === 'company' && entity.status === 'confirmed')?.id;
43
+ }
44
+ function SupplyChainMap({ entities, edges, onEdgeSelect, onNodeClick, cascade, fill, className, }) {
45
+ const { isDarkMode } = useTheme();
46
+ const marks = isDarkMode ? MAP_COLORS_DARK : MAP_COLORS;
47
+ const wrapRef = useRef(null);
48
+ const canvasRef = useRef(null);
49
+ const [size, setSize] = useState({ w: 0, h: 0 });
50
+ const [camera, setCamera] = useState(null);
51
+ const [showAll, setShowAll] = useState(false);
52
+ const [selected, setSelected] = useState(null);
53
+ const [expandedIds, setExpandedIds] = useState(() => new Set());
54
+ const forceOpenKRef = useRef(null);
55
+ const scene = useMemo(() => buildConfirmedMapScene(entities, edges), [entities, edges]);
56
+ const liveCascade = useMemo(() => activeMapCascade(cascade), [cascade]);
57
+ const orgId = useMemo(() => orgNodeId(entities), [entities]);
58
+ const sceneNodes = useMemo(() => scene.nodes.map(node => ({
59
+ ...node,
60
+ impacted: liveCascade?.onPathIds.has(node.id) ?? false,
61
+ })), [scene.nodes, liveCascade]);
62
+ const sceneArcs = useMemo(() => scene.arcs.map(arc => ({
63
+ ...arc,
64
+ fromId: arc.fromEntity,
65
+ toId: arc.toEntity,
66
+ onSpine: liveCascade?.pathIds.includes(arc.fromEntity) ?? false,
67
+ })), [scene.arcs, liveCascade]);
68
+ const byId = useMemo(() => new Map(sceneNodes.map(node => [node.id, node])), [sceneNodes]);
69
+ const inspected = resolveMapSelection(selected, sceneNodes);
70
+ const disclosureAnchors = useMemo(() => resolveMapDisclosureAnchors(byId, {
71
+ selectedId: inspected?.id ?? null,
72
+ }), [byId, inspected]);
73
+ const altitude = syntheticAltitude(camera?.k ?? 1);
74
+ const tier = labelTier(altitude);
75
+ const disclosedScene = useMemo(() => discloseMapScene(sceneNodes, sceneArcs, {
76
+ tier,
77
+ orgId,
78
+ ...disclosureAnchors,
79
+ expanded: showAll,
80
+ }), [sceneNodes, sceneArcs, tier, orgId, disclosureAnchors, showAll]);
81
+ useEffect(() => {
82
+ const el = wrapRef.current;
83
+ if (!el)
84
+ return;
85
+ const apply = (w, h) => {
86
+ if (w > 0 && h > 0)
87
+ setSize({ w: Math.round(w), h: Math.round(h) });
88
+ };
89
+ apply(el.clientWidth, el.clientHeight);
90
+ const ro = new ResizeObserver(entries => {
91
+ const r = entries[0]?.contentRect;
92
+ if (r)
93
+ apply(r.width, r.height);
94
+ });
95
+ ro.observe(el);
96
+ return () => ro.disconnect();
97
+ }, [scene.nodes.length > 0]);
98
+ useEffect(() => {
99
+ if (size.w === 0 || size.h === 0)
100
+ return;
101
+ setCamera(cam => (cam ? clampCamera(cam, size.w, size.h) : cam));
102
+ }, [size.w, size.h]);
103
+ useEffect(() => {
104
+ if (selected && !inspected)
105
+ setSelected(null);
106
+ }, [selected, inspected]);
107
+ useEffect(() => {
108
+ const openedAt = forceOpenKRef.current;
109
+ const k = camera?.k;
110
+ if (openedAt == null || k == null || expandedIds.size === 0)
111
+ return;
112
+ if (!forceOpenExpired(openedAt, k))
113
+ return;
114
+ forceOpenKRef.current = null;
115
+ setExpandedIds(new Set());
116
+ }, [camera?.k, expandedIds.size]);
117
+ const cameraRef = useRef(null);
118
+ cameraRef.current = camera;
119
+ const flyRaf = useRef(0);
120
+ const stopFlying = useCallback(() => {
121
+ if (flyRaf.current)
122
+ cancelAnimationFrame(flyRaf.current);
123
+ flyRaf.current = 0;
124
+ }, []);
125
+ useEffect(() => stopFlying, [stopFlying]);
126
+ const flyTo = useCallback((target) => {
127
+ stopFlying();
128
+ const from = cameraRef.current ?? HOME_CAMERA;
129
+ const start = performance.now();
130
+ const step = (now) => {
131
+ const t = Math.min(1, (now - start) / FLY_MS);
132
+ const e = easeInOutCubic(t);
133
+ setCamera(clampCamera({
134
+ k: from.k + (target.k - from.k) * e,
135
+ x: from.x + (target.x - from.x) * e,
136
+ y: from.y + (target.y - from.y) * e,
137
+ }, size.w, size.h));
138
+ if (t < 1)
139
+ flyRaf.current = requestAnimationFrame(step);
140
+ };
141
+ flyRaf.current = requestAnimationFrame(step);
142
+ }, [size.w, size.h, stopFlying]);
143
+ const openedRef = useRef(false);
144
+ useEffect(() => {
145
+ if (openedRef.current || size.w === 0 || size.h === 0)
146
+ return;
147
+ openedRef.current = true;
148
+ setCamera(cameraFitPoints(scene.nodes.map(n => ({ lat: n.lat, lng: n.lng })), size.w, size.h));
149
+ }, [size.w, size.h, scene.nodes]);
150
+ const resetView = useCallback(() => {
151
+ forceOpenKRef.current = null;
152
+ setExpandedIds(new Set());
153
+ flyTo(cameraFitPoints(scene.nodes.map(n => ({ lat: n.lat, lng: n.lng })), size.w, size.h));
154
+ }, [flyTo, scene.nodes, size.w, size.h]);
155
+ const zoomBy = useCallback((dir) => {
156
+ const cam = cameraRef.current ?? HOME_CAMERA;
157
+ flyTo(zoomCamera(cam, dir > 0 ? ZOOM_STEP : 1 / ZOOM_STEP, { x: size.w / 2, y: size.h / 2 }, size.w, size.h));
158
+ }, [flyTo, size.w, size.h]);
159
+ const dragRef = useRef(null);
160
+ const hitLanesRef = useRef([]);
161
+ const onPointerDown = useCallback((ev) => {
162
+ if (ev.button !== 0)
163
+ return;
164
+ dragRef.current = { x: ev.clientX, y: ev.clientY, moved: false };
165
+ ev.currentTarget.setPointerCapture(ev.pointerId);
166
+ }, []);
167
+ const onPointerMove = useCallback((ev) => {
168
+ const drag = dragRef.current;
169
+ if (!drag)
170
+ return;
171
+ const dx = ev.clientX - drag.x;
172
+ const dy = ev.clientY - drag.y;
173
+ if (!drag.moved && Math.hypot(dx, dy) < DRAG_THRESHOLD_PX)
174
+ return;
175
+ drag.moved = true;
176
+ drag.x = ev.clientX;
177
+ drag.y = ev.clientY;
178
+ stopFlying();
179
+ setCamera(cam => (cam ? panCamera(cam, dx, dy, size.w, size.h) : cam));
180
+ }, [size.w, size.h, stopFlying]);
181
+ const closeInspector = useCallback(() => setSelected(null), []);
182
+ const onPointerUp = useCallback((ev) => {
183
+ const drag = dragRef.current;
184
+ dragRef.current = null;
185
+ if (!drag || drag.moved)
186
+ return;
187
+ const rect = wrapRef.current?.getBoundingClientRect();
188
+ if (!rect)
189
+ return;
190
+ const x = ev.clientX - rect.left;
191
+ const y = ev.clientY - rect.top;
192
+ let bestId = null;
193
+ let bestD = LANE_HIT_PX;
194
+ for (const lane of hitLanesRef.current) {
195
+ const pts = lane.points;
196
+ for (let i = 1; i < pts.length; i++) {
197
+ const d = segmentDistance(x, y, pts[i - 1][0], pts[i - 1][1], pts[i][0], pts[i][1]);
198
+ if (d < bestD) {
199
+ bestD = d;
200
+ bestId = lane.id;
201
+ }
202
+ }
203
+ }
204
+ if (bestId) {
205
+ setSelected(null);
206
+ onEdgeSelect?.(bestId);
207
+ return;
208
+ }
209
+ closeInspector();
210
+ }, [closeInspector, onEdgeSelect]);
211
+ useEffect(() => {
212
+ const el = wrapRef.current;
213
+ if (!el)
214
+ return;
215
+ const onWheel = (ev) => {
216
+ ev.preventDefault();
217
+ const rect = el.getBoundingClientRect();
218
+ stopFlying();
219
+ const at = { x: ev.clientX - rect.left, y: ev.clientY - rect.top };
220
+ setCamera(cam => cam
221
+ ? zoomCamera(cam, Math.exp(-ev.deltaY * 0.0022), at, size.w, size.h)
222
+ : cam);
223
+ };
224
+ el.addEventListener('wheel', onWheel, { passive: false });
225
+ return () => el.removeEventListener('wheel', onWheel);
226
+ }, [size.w, size.h, stopFlying]);
227
+ const onKeyDown = useCallback((ev) => {
228
+ if (ev.target !== ev.currentTarget)
229
+ return;
230
+ const pan = 60;
231
+ if (ev.key === '+' || ev.key === '=')
232
+ zoomBy(1);
233
+ else if (ev.key === '-' || ev.key === '_')
234
+ zoomBy(-1);
235
+ else if (ev.key === '0')
236
+ resetView();
237
+ else if (ev.key === 'ArrowLeft')
238
+ setCamera(c => (c ? panCamera(c, pan, 0, size.w, size.h) : c));
239
+ else if (ev.key === 'ArrowRight')
240
+ setCamera(c => (c ? panCamera(c, -pan, 0, size.w, size.h) : c));
241
+ else if (ev.key === 'ArrowUp')
242
+ setCamera(c => (c ? panCamera(c, 0, pan, size.w, size.h) : c));
243
+ else if (ev.key === 'ArrowDown')
244
+ setCamera(c => (c ? panCamera(c, 0, -pan, size.w, size.h) : c));
245
+ else if (ev.key === 'Escape')
246
+ closeInspector();
247
+ else
248
+ return;
249
+ ev.preventDefault();
250
+ }, [zoomBy, resetView, size.w, size.h, closeInspector]);
251
+ const proj = useMemo(() => camera && size.w > 0
252
+ ? mapProjection(size.w, size.h, camera).clipAngle(null)
253
+ : null, [camera, size]);
254
+ const worldView = (camera?.k ?? MIN_ZOOM) <= MIN_ZOOM + 1e-6;
255
+ const project = useCallback((lat, lng) => proj ? projectPoint(proj, lat, lng) : null, [proj]);
256
+ const onScreen = useCallback((p, margin = 40) => p !== null &&
257
+ p[0] > -margin &&
258
+ p[0] < size.w + margin &&
259
+ p[1] > -margin &&
260
+ p[1] < size.h + margin, [size]);
261
+ const clusters = useMemo(() => proj
262
+ ? clusterMapNodes(sceneNodes, project, CLUSTER_RADIUS_PX, expandedIds)
263
+ : [], [proj, sceneNodes, project, expandedIds]);
264
+ const clusteredArcs = useMemo(() => remapArcsToClusters(disclosedScene.arcs, clusters), [disclosedScene.arcs, clusters]);
265
+ const drawArcs = useMemo(() => clusteredArcs.map(a => {
266
+ const dim = Boolean(liveCascade &&
267
+ !liveCascade.laneIds.has(a.id) &&
268
+ !liveCascade.onPathIds.has(a.fromEntity) &&
269
+ !liveCascade.onPathIds.has(a.toEntity));
270
+ return {
271
+ id: a.id,
272
+ from: a.from,
273
+ to: a.to,
274
+ color: a.onSpine || liveCascade?.laneIds.has(a.id)
275
+ ? marks.spine
276
+ : marks.arcDefault,
277
+ alpha: dim ? 0.22 : 1,
278
+ };
279
+ }), [clusteredArcs, liveCascade, marks]);
280
+ const drawCommand = useMemo(() => {
281
+ if (!camera || size.w === 0 || size.h === 0)
282
+ return null;
283
+ return {
284
+ width: size.w,
285
+ height: size.h,
286
+ dpr: typeof window === 'undefined' ? 1 : window.devicePixelRatio || 1,
287
+ camera,
288
+ arcs: drawArcs,
289
+ palette: mapBasemapPalette(isDarkMode),
290
+ };
291
+ }, [camera, size, drawArcs, isDarkMode]);
292
+ const { mode: rendererMode, canvasKey } = useMapBaseRenderer(canvasRef, drawCommand, lanes => {
293
+ hitLanesRef.current = lanes;
294
+ }, scene.nodes.length > 0);
295
+ const labels = useMemo(() => clusters
296
+ .filter(c => c.nodeId)
297
+ .map(c => {
298
+ const n = byId.get(c.nodeId);
299
+ return {
300
+ id: c.id,
301
+ lat: c.lat,
302
+ lng: c.lng,
303
+ text: n?.name ?? c.id,
304
+ primary: c.id === orgId || c.id === inspected?.id,
305
+ };
306
+ }), [clusters, byId, orgId, inspected]);
307
+ const placedLabels = useMemo(() => (proj ? placeMapLabels(labels, project, size.w, size.h) : []), [proj, labels, project, size]);
308
+ const placedLabelById = useMemo(() => new Map(placedLabels.map(l => [l.id, l])), [placedLabels]);
309
+ const flyToPlace = useCallback((lat, lng) => {
310
+ const k = cameraRef.current?.k ?? HOME_CAMERA.k;
311
+ flyTo(cameraCenteredOn(lat, lng, k, size.w, size.h));
312
+ }, [flyTo, size.w, size.h]);
313
+ const activateCluster = useCallback((cluster) => {
314
+ if (cluster.nodeId) {
315
+ const node = byId.get(cluster.nodeId);
316
+ if (!node)
317
+ return;
318
+ setSelected(node);
319
+ onNodeClick?.(node.id);
320
+ flyToPlace(node.lat, node.lng);
321
+ return;
322
+ }
323
+ setSelected(null);
324
+ if (forceOpenKRef.current == null) {
325
+ forceOpenKRef.current = cameraRef.current?.k ?? HOME_CAMERA.k;
326
+ }
327
+ setExpandedIds(prev => {
328
+ const next = new Set(prev);
329
+ for (const id of cluster.memberIds)
330
+ next.add(id);
331
+ return next;
332
+ });
333
+ }, [byId, flyToPlace, onNodeClick]);
334
+ const at = (p) => ({
335
+ left: `${p[0]}px`,
336
+ top: `${p[1]}px`,
337
+ });
338
+ const ready = camera !== null && size.w > 0;
339
+ const shownRouteCount = disclosedScene.arcs.length;
340
+ const totalRouteCount = scene.arcs.length;
341
+ if (scene.nodes.length === 0) {
342
+ return (jsx("div", { className: cn(S.root, fill && S.fill, className), children: jsx("div", { className: S.empty, role: "status", children: "No confirmed locations yet \u2014 confirm a placed node to show it on the map." }) }));
343
+ }
344
+ return (jsxs("div", { className: cn(S.root, fill && S.fill, className), children: [jsxs("div", { ref: wrapRef, className: S.canvas, role: "application", "aria-label": `Supply chain map, ${scene.nodes.length} located ${scene.nodes.length === 1 ? 'site' : 'sites'}, ${shownRouteCount} of ${totalRouteCount} routes. Drag to pan, arrow keys pan, plus and minus zoom, 0 resets the view.`, "data-map-renderer": rendererMode, "data-camera-k": camera?.k ?? '', "data-map-force-open": expandedIds.size, "data-map-places": scene.nodes.length, "data-map-glyphs": clusters.filter(c => {
345
+ const p = project(c.lat, c.lng);
346
+ return p != null && (worldView || onScreen(p));
347
+ }).length, "data-map-clustered": clusters.reduce((sum, c) => sum + c.count, 0), tabIndex: 0, onPointerDown: onPointerDown, onPointerMove: onPointerMove, onPointerUp: onPointerUp, onPointerCancel: () => {
348
+ dragRef.current = null;
349
+ }, onKeyDown: onKeyDown, children: [jsx("canvas", { ref: canvasRef, className: S.baseCanvas, "aria-hidden": true }, canvasKey), ready ? (jsx("div", { className: S.overlay, children: clusters.map(cluster => {
350
+ const p = project(cluster.lat, cluster.lng);
351
+ if (!p || (!worldView && !onScreen(p)))
352
+ return null;
353
+ const node = cluster.nodeId
354
+ ? byId.get(cluster.nodeId)
355
+ : undefined;
356
+ const dim = Boolean(liveCascade &&
357
+ !cluster.memberIds.some(id => liveCascade.onPathIds.has(id)));
358
+ const selectedNode = Boolean(inspected && cluster.memberIds.includes(inspected.id));
359
+ const isOrg = Boolean(orgId && cluster.memberIds.includes(orgId));
360
+ const label = cluster.nodeId
361
+ ? placedLabelById.get(cluster.id)
362
+ : undefined;
363
+ const names = cluster.memberIds
364
+ .map(id => byId.get(id)?.name)
365
+ .filter((name) => Boolean(name));
366
+ const title = node?.name ??
367
+ (names.length > 3
368
+ ? `${names.slice(0, 3).join(', ')} +${names.length - 3}`
369
+ : names.join(', '));
370
+ return (jsxs("div", { className: cn(S.marker, cluster.count > 1 && S.cluster, selectedNode && S.selected, dim && S.dimmed), style: at(p), children: [jsx("button", { type: "button", className: cn(S.node, cluster.count > 1 && S.cluster), style: {
371
+ background: isOrg ? marks.org : marks.chain,
372
+ }, title: title, "aria-label": node
373
+ ? `Inspect ${node.name}`
374
+ : `Show ${cluster.count} nearby sites`, onPointerDown: e => e.stopPropagation(), onPointerUp: e => e.stopPropagation(), onClick: e => {
375
+ e.stopPropagation();
376
+ activateCluster(cluster);
377
+ }, children: cluster.count > 1 ? cluster.count : null }), label ? (jsx("button", { type: "button", className: cn(S.label, label.primary && S.primary), title: label.text, "aria-label": `Inspect ${label.text}`, onPointerDown: e => e.stopPropagation(), onPointerUp: e => e.stopPropagation(), onClick: e => {
378
+ e.stopPropagation();
379
+ activateCluster(cluster);
380
+ }, children: label.text })) : null] }, cluster.id));
381
+ }) })) : null, jsxs("div", { className: S.disclosure, role: "region", "aria-label": "Map disclosure", children: [jsxs("span", { role: "status", "aria-live": "polite", children: [jsx("strong", { children: showAll ? 'All routes' : 'Overview' }), ' · ', jsxs("span", { children: [shownRouteCount, " of ", totalRouteCount, " routes"] }), disclosedScene.canRevealByZoom ? (jsx("span", { children: " \u00B7 Zoom in to reveal more" })) : null] }), jsx("button", { type: "button", className: S.action, "aria-pressed": showAll, onClick: () => setShowAll(expanded => !expanded), children: showAll ? 'Return to overview' : 'Show all' }), jsxs("div", { className: S.zoom, children: [jsx("button", { type: "button", className: S.action, onClick: () => zoomBy(1), children: "+" }), jsx("button", { type: "button", className: S.action, onClick: () => zoomBy(-1), children: "\u2212" }), jsx("button", { type: "button", className: S.action, onClick: resetView, children: "0" })] })] })] }), inspected ? (jsxs("div", { className: S.inspection, "aria-live": "polite", children: [jsx("div", { className: S.kicker, children: inspected.type }), jsx("strong", { children: inspected.name }), inspectionLocation(inspected) ? (jsx("p", { children: inspectionLocation(inspected) })) : null] })) : (jsx("p", { className: S.hint, children: "Select a confirmed location to inspect its stored details." }))] }));
382
+ }
383
+
384
+ export { SupplyChainMap };
@@ -0,0 +1,7 @@
1
+ import styleInject from 'style-inject';
2
+
3
+ var css_248z = "@media (max-width:768px){:root{--page-x-padding:var(--p-6);--page-y-padding:var(--p-6)}}.SupplyChainMap_root__3fNZf{background:radial-gradient(120% 100% at 50% 0,#fff 0,var(--card) 58%,#eceff0 100%);border:1px solid var(--border);border-radius:var(--radius-card);color:var(--card-foreground);display:flex;flex-direction:column;height:clamp(440px,54vh,720px);overflow:hidden;position:relative}.dark .SupplyChainMap_root__3fNZf{background:radial-gradient(120% 100% at 50% 0,var(--card) 0,var(--background) 58%,#12181c 100%)}.SupplyChainMap_root__3fNZf.SupplyChainMap_fill__71jPd{flex:1;height:auto;min-height:0}.SupplyChainMap_canvas__NwwiX{cursor:grab;flex:1;min-height:320px;position:relative;touch-action:none}.SupplyChainMap_canvas__NwwiX:active{cursor:grabbing}.SupplyChainMap_baseCanvas__wb-Tc{height:100%;inset:0;position:absolute;width:100%}.SupplyChainMap_overlay__NplP-{inset:0;pointer-events:none;position:absolute;z-index:3}.SupplyChainMap_overlay__NplP->*{position:absolute;transform:translate(-50%,-50%)}.SupplyChainMap_marker__FUN03{height:12px;pointer-events:none;width:12px}.SupplyChainMap_marker__FUN03.SupplyChainMap_cluster__Hi9Ku{height:22px;width:22px}.SupplyChainMap_marker__FUN03.SupplyChainMap_dimmed__1fN1T{opacity:.28}.SupplyChainMap_node__2APtm{align-items:center;-webkit-appearance:none;-moz-appearance:none;appearance:none;border:1.5px solid #fff;border-radius:50%;box-shadow:0 0 0 2px hsla(0,0%,100%,.35);color:#fff;cursor:pointer;display:flex;font-size:10px;font-weight:600;height:12px;justify-content:center;line-height:1;padding:0;pointer-events:auto;transition:box-shadow .12s ease,transform .12s ease,border-color .12s ease;width:12px}.dark .SupplyChainMap_node__2APtm{border-color:#1a2226;box-shadow:0 0 0 2px rgba(26,34,38,.45);color:#0f1416}.SupplyChainMap_node__2APtm.SupplyChainMap_cluster__Hi9Ku{height:22px;width:22px}.SupplyChainMap_marker__FUN03.SupplyChainMap_selected__F0XHC .SupplyChainMap_node__2APtm,.SupplyChainMap_node__2APtm.SupplyChainMap_selected__F0XHC{border-color:#242829;box-shadow:0 0 0 2.5px rgba(36,40,41,.28)}.dark .SupplyChainMap_marker__FUN03.SupplyChainMap_selected__F0XHC .SupplyChainMap_node__2APtm,.dark .SupplyChainMap_node__2APtm.SupplyChainMap_selected__F0XHC{border-color:#e8eef0;box-shadow:0 0 0 2.5px rgba(232,238,240,.35)}.SupplyChainMap_marker__FUN03:focus-within .SupplyChainMap_node__2APtm,.SupplyChainMap_marker__FUN03:hover .SupplyChainMap_node__2APtm{box-shadow:0 0 0 3px rgba(15,158,192,.38);transform:scale(1.18)}.SupplyChainMap_label__A1XvY{-webkit-appearance:none;-moz-appearance:none;appearance:none;background:color-mix(in srgb,var(--card) 92%,transparent);border:1px solid var(--border);border-radius:6px;color:var(--card-foreground);cursor:pointer;font-family:inherit;font-size:11px;left:calc(100% + 6px);line-height:1.2;padding:2px 6px;pointer-events:auto;position:absolute;top:50%;transform:translateY(-50%);transition:border-color .12s ease,box-shadow .12s ease,background .12s ease;white-space:nowrap}.SupplyChainMap_label__A1XvY.SupplyChainMap_primary__uMmGO{font-weight:600}.SupplyChainMap_label__A1XvY:focus-visible,.SupplyChainMap_label__A1XvY:hover,.SupplyChainMap_marker__FUN03:focus-within .SupplyChainMap_label__A1XvY,.SupplyChainMap_marker__FUN03:hover .SupplyChainMap_label__A1XvY{background:var(--card);border-color:#0f9ec0;box-shadow:0 1px 4px rgba(36,40,41,.12)}.dark .SupplyChainMap_label__A1XvY:focus-visible,.dark .SupplyChainMap_label__A1XvY:hover,.dark .SupplyChainMap_marker__FUN03:focus-within .SupplyChainMap_label__A1XvY,.dark .SupplyChainMap_marker__FUN03:hover .SupplyChainMap_label__A1XvY{border-color:#2ec4e0;box-shadow:0 1px 4px rgba(0,0,0,.45)}.SupplyChainMap_empty__fywCQ{align-items:center;color:#54646a;color:var(--muted-foreground,#54646a);display:flex;justify-content:center;min-height:320px;padding:24px;text-align:center}.SupplyChainMap_disclosure__hwl6H{align-items:center;background:color-mix(in srgb,var(--card) 88%,transparent);border:1px solid var(--border);border-radius:8px;bottom:12px;color:var(--card-foreground);display:flex;flex-wrap:wrap;font-size:12px;gap:8px;left:12px;padding:8px 10px;position:absolute;right:12px;z-index:4}.dark .SupplyChainMap_disclosure__hwl6H{background:color-mix(in srgb,var(--background) 72%,transparent);box-shadow:0 1px 8px rgba(0,0,0,.35)}.SupplyChainMap_action__YPEe-{background:var(--card);border:1px solid var(--border);border-radius:6px;color:inherit;cursor:pointer;padding:4px 8px}.dark .SupplyChainMap_action__YPEe-{background:var(--secondary,var(--card))}.SupplyChainMap_zoom__dGXos{display:flex;gap:4px;margin-left:auto}.SupplyChainMap_inspection__e5QFj{background:color-mix(in srgb,var(--card) 92%,transparent);border:1px solid var(--border);border-radius:8px;color:var(--card-foreground);left:12px;margin:0;padding:10px 12px;position:absolute;right:12px;top:12px;z-index:2}.dark .SupplyChainMap_inspection__e5QFj{background:color-mix(in srgb,var(--background) 78%,transparent)}.SupplyChainMap_kicker__uO2WP{color:#54646a;color:var(--muted-foreground,#54646a);font-size:11px;letter-spacing:.04em;text-transform:uppercase}.SupplyChainMap_hint__NXDuY{color:#54646a;color:var(--muted-foreground,#54646a);font-size:12px;left:12px;margin:0;position:absolute;right:12px;top:12px;z-index:2}@media (max-width:420px){.SupplyChainMap_disclosure__hwl6H{align-items:stretch;flex-direction:column}.SupplyChainMap_zoom__dGXos{justify-content:center;margin-left:0}}";
4
+ var S = {"root":"SupplyChainMap_root__3fNZf","fill":"SupplyChainMap_fill__71jPd","canvas":"SupplyChainMap_canvas__NwwiX","baseCanvas":"SupplyChainMap_baseCanvas__wb-Tc","overlay":"SupplyChainMap_overlay__NplP-","marker":"SupplyChainMap_marker__FUN03","cluster":"SupplyChainMap_cluster__Hi9Ku","dimmed":"SupplyChainMap_dimmed__1fN1T","node":"SupplyChainMap_node__2APtm","selected":"SupplyChainMap_selected__F0XHC","label":"SupplyChainMap_label__A1XvY","primary":"SupplyChainMap_primary__uMmGO","empty":"SupplyChainMap_empty__fywCQ","disclosure":"SupplyChainMap_disclosure__hwl6H","action":"SupplyChainMap_action__YPEe-","zoom":"SupplyChainMap_zoom__dGXos","inspection":"SupplyChainMap_inspection__e5QFj","kicker":"SupplyChainMap_kicker__uO2WP","hint":"SupplyChainMap_hint__NXDuY"};
5
+ styleInject(css_248z);
6
+
7
+ export { S as default };
@@ -0,0 +1,44 @@
1
+ /** Basemap and mark colours from Team-Merged globe-colors — inlined so this
2
+ * map does not import the globe stack. Dark tones follow the same globe
3
+ * night land/ocean family so canvas paint matches `html.dark`. */
4
+ const OCEAN_TONE = '#4b88b1';
5
+ const OCEAN_TONE_DARK = '#3a5f78';
6
+ const MAP_COLORS = {
7
+ land: '#fbfcfc',
8
+ landStroke: 'rgba(103,119,126,0.38)',
9
+ graticule: 'rgba(226,240,250,0.22)',
10
+ org: '#0f9ec0',
11
+ chain: '#54646a',
12
+ rim: '#ffffff',
13
+ rimSelected: '#242829',
14
+ arcDefault: 'rgba(222,236,246,0.88)',
15
+ spine: '#d93a2f',
16
+ };
17
+ const MAP_COLORS_DARK = {
18
+ land: '#c3cdd5',
19
+ landStroke: 'rgba(36,40,41,0.42)',
20
+ graticule: 'rgba(226,240,250,0.10)',
21
+ org: '#2ec4e0',
22
+ chain: '#8a9aa0',
23
+ rim: '#1a2226',
24
+ rimSelected: '#e8eef0',
25
+ arcDefault: 'rgba(46,80,96,0.82)',
26
+ spine: '#ff6b5a',
27
+ };
28
+ function mapBasemapPalette(dark) {
29
+ return dark
30
+ ? {
31
+ ocean: OCEAN_TONE_DARK,
32
+ land: MAP_COLORS_DARK.land,
33
+ landStroke: MAP_COLORS_DARK.landStroke,
34
+ graticule: MAP_COLORS_DARK.graticule,
35
+ }
36
+ : {
37
+ ocean: OCEAN_TONE,
38
+ land: MAP_COLORS.land,
39
+ landStroke: MAP_COLORS.landStroke,
40
+ graticule: MAP_COLORS.graticule,
41
+ };
42
+ }
43
+
44
+ export { MAP_COLORS, MAP_COLORS_DARK, OCEAN_TONE, OCEAN_TONE_DARK, mapBasemapPalette };
@@ -0,0 +1,142 @@
1
+ function resolveMapDisclosureAnchors(lookup, anchors) {
2
+ const resolve = (id) => (id == null ? id : (lookup.get(id)?.id ?? id));
3
+ return {
4
+ selectedId: resolve(anchors.selectedId),
5
+ focusId: resolve(anchors.focusId),
6
+ signalIds: anchors.signalIds == null
7
+ ? undefined
8
+ : new Set([...anchors.signalIds].map(id => resolve(id))),
9
+ };
10
+ }
11
+ function tierBudget(options) {
12
+ if (options.expanded || options.tier === 'near')
13
+ return null;
14
+ return options.tier === 'far' ? 18 : 48;
15
+ }
16
+ function isCascadeRoute(arc) {
17
+ return Boolean(arc.onSpine || arc.impacted || arc.reach != null);
18
+ }
19
+ function compareIds(left, right) {
20
+ return left < right ? -1 : left > right ? 1 : 0;
21
+ }
22
+ function buildAdjacency(arcs) {
23
+ const adjacency = new Map();
24
+ const add = (nodeId, entry) => {
25
+ const entries = adjacency.get(nodeId);
26
+ if (entries)
27
+ entries.push(entry);
28
+ else
29
+ adjacency.set(nodeId, [entry]);
30
+ };
31
+ for (const arc of arcs) {
32
+ add(arc.fromId, { arc, nextId: arc.toId });
33
+ add(arc.toId, { arc, nextId: arc.fromId });
34
+ }
35
+ for (const entries of adjacency.values()) {
36
+ entries.sort((left, right) => compareIds(left.arc.id, right.arc.id) ||
37
+ compareIds(left.nextId, right.nextId));
38
+ }
39
+ return adjacency;
40
+ }
41
+ function addShortestPath(startId, targetId, adjacency, mandatory) {
42
+ if (startId === targetId)
43
+ return;
44
+ const queue = [startId];
45
+ const visited = new Set(queue);
46
+ const parent = new Map();
47
+ let cursor = 0;
48
+ while (cursor < queue.length && !visited.has(targetId)) {
49
+ const nodeId = queue[cursor++];
50
+ for (const { arc, nextId } of adjacency.get(nodeId) ?? []) {
51
+ if (visited.has(nextId))
52
+ continue;
53
+ visited.add(nextId);
54
+ parent.set(nextId, { previousId: nodeId, arc });
55
+ queue.push(nextId);
56
+ if (nextId === targetId)
57
+ break;
58
+ }
59
+ }
60
+ if (!visited.has(targetId))
61
+ return;
62
+ for (let nodeId = targetId; nodeId !== startId;) {
63
+ const step = parent.get(nodeId);
64
+ if (!step)
65
+ return;
66
+ mandatory.add(step.arc);
67
+ nodeId = step.previousId;
68
+ }
69
+ }
70
+ function discloseMapScene(nodes, arcs, options) {
71
+ const routeBudget = tierBudget(options);
72
+ if (routeBudget === null) {
73
+ return {
74
+ nodes: [...nodes],
75
+ arcs: [...arcs],
76
+ hiddenNodeCount: 0,
77
+ hiddenArcCount: 0,
78
+ routeBudget,
79
+ canRevealByZoom: false,
80
+ };
81
+ }
82
+ const degrees = new Map();
83
+ for (const arc of arcs) {
84
+ degrees.set(arc.fromId, (degrees.get(arc.fromId) ?? 0) + 1);
85
+ degrees.set(arc.toId, (degrees.get(arc.toId) ?? 0) + 1);
86
+ }
87
+ const nodeIds = new Set(nodes.map(node => node.id));
88
+ const orgExists = options.orgId != null && nodeIds.has(options.orgId);
89
+ const adjacency = buildAdjacency(arcs);
90
+ const mandatory = new Set();
91
+ for (const arc of arcs) {
92
+ if (isCascadeRoute(arc) ||
93
+ (options.selectedId != null &&
94
+ (arc.fromId === options.selectedId || arc.toId === options.selectedId))) {
95
+ mandatory.add(arc);
96
+ }
97
+ }
98
+ if (orgExists) {
99
+ const anchorIds = [
100
+ options.selectedId,
101
+ options.focusId,
102
+ ...(options.signalIds ?? []),
103
+ ].filter((id) => id != null && nodeIds.has(id));
104
+ for (const anchorId of anchorIds) {
105
+ addShortestPath(anchorId, options.orgId, adjacency, mandatory);
106
+ }
107
+ }
108
+ const compareArcs = (left, right) => {
109
+ const leftOrgAdjacent = orgExists &&
110
+ (left.fromId === options.orgId || left.toId === options.orgId);
111
+ const rightOrgAdjacent = orgExists &&
112
+ (right.fromId === options.orgId || right.toId === options.orgId);
113
+ const orgRank = Number(rightOrgAdjacent) - Number(leftOrgAdjacent);
114
+ if (orgRank !== 0)
115
+ return orgRank;
116
+ const leftDegree = Math.max(degrees.get(left.fromId) ?? 0, degrees.get(left.toId) ?? 0);
117
+ const rightDegree = Math.max(degrees.get(right.fromId) ?? 0, degrees.get(right.toId) ?? 0);
118
+ return rightDegree - leftDegree || compareIds(left.id, right.id);
119
+ };
120
+ const mandatoryArcs = [...mandatory].sort(compareArcs);
121
+ const ordinaryArcs = arcs
122
+ .filter(arc => !mandatory.has(arc))
123
+ .sort(compareArcs);
124
+ const ordinarySlots = Math.max(0, routeBudget - mandatoryArcs.length);
125
+ const disclosedArcs = [
126
+ ...mandatoryArcs,
127
+ ...ordinaryArcs.slice(0, ordinarySlots),
128
+ ];
129
+ // Places always stay on the map (as markers or clusters). The budget only
130
+ // hides routes — otherwise world view drops isolated / low-degree sites.
131
+ const hiddenArcCount = Math.max(0, arcs.length - disclosedArcs.length);
132
+ return {
133
+ nodes: [...nodes],
134
+ arcs: disclosedArcs,
135
+ hiddenNodeCount: 0,
136
+ hiddenArcCount,
137
+ routeBudget,
138
+ canRevealByZoom: hiddenArcCount > 0,
139
+ };
140
+ }
141
+
142
+ export { discloseMapScene, resolveMapDisclosureAnchors };
@@ -0,0 +1,55 @@
1
+ const CHAR_PX = 6.2;
2
+ const PAD_PX = 14;
3
+ const LABEL_H = 18;
4
+ const LABEL_OFFSET_X = 12;
5
+ const LABEL_OFFSET_Y = 0;
6
+ const OFFSCREEN_MARGIN = 60;
7
+ function overlaps(a, b, padding) {
8
+ return (a.x < b.x + b.w + padding &&
9
+ a.x + a.w + padding > b.x &&
10
+ a.y < b.y + b.h + padding &&
11
+ a.y + a.h + padding > b.y);
12
+ }
13
+ function declutter(boxes, padding = 2) {
14
+ const ordered = [...boxes].sort((a, b) => b.priority - a.priority || (a.id < b.id ? -1 : 1));
15
+ const placed = [];
16
+ const kept = new Set();
17
+ for (const box of ordered) {
18
+ if (box.w <= 0 || box.h <= 0)
19
+ continue;
20
+ if (placed.some(p => overlaps(p, box, padding)))
21
+ continue;
22
+ placed.push(box);
23
+ kept.add(box.id);
24
+ }
25
+ return kept;
26
+ }
27
+ function placeMapLabels(labels, project, width, height) {
28
+ const placed = [];
29
+ const boxes = [];
30
+ for (const [i, label] of labels.entries()) {
31
+ const p = project(label.lat, label.lng);
32
+ if (!p)
33
+ continue;
34
+ const [x, y] = p;
35
+ if (x < -OFFSCREEN_MARGIN ||
36
+ x > width + OFFSCREEN_MARGIN ||
37
+ y < -OFFSCREEN_MARGIN ||
38
+ y > height + OFFSCREEN_MARGIN) {
39
+ continue;
40
+ }
41
+ placed.push({ ...label, x, y });
42
+ boxes.push({
43
+ id: label.id,
44
+ x: x + LABEL_OFFSET_X,
45
+ y: y + LABEL_OFFSET_Y - LABEL_H / 2,
46
+ w: PAD_PX + label.text.length * CHAR_PX,
47
+ h: LABEL_H,
48
+ priority: labels.length - i,
49
+ });
50
+ }
51
+ const kept = declutter(boxes);
52
+ return placed.filter(l => kept.has(l.id));
53
+ }
54
+
55
+ export { LABEL_OFFSET_X, LABEL_OFFSET_Y, placeMapLabels };