@defra/interactive-map 0.0.59-alpha → 0.0.60-alpha

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 (87) hide show
  1. package/assets/templates/add-polygons.njk +2 -2
  2. package/assets/templates/add-symbols.njk +2 -2
  3. package/dist/css/index.css +1 -1
  4. package/dist/esm/im-core.js +1 -1
  5. package/dist/esm/im-shell.js +1 -1
  6. package/dist/umd/im-core.js +1 -1
  7. package/dist/umd/index.js +1 -1
  8. package/docs/api/panel-definition.md +30 -0
  9. package/docs/api/symbol-config.md +12 -0
  10. package/docs/api.md +21 -2
  11. package/docs/assets/images/slot-map.svg +3 -3
  12. package/docs/plugins/datasets.md +11 -1
  13. package/package.json +1 -1
  14. package/plugins/datasets/dist/esm/index.js +1 -1
  15. package/plugins/datasets/dist/esm/layerAdapter.js +1 -1
  16. package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
  17. package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
  18. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  19. package/plugins/datasets/dist/umd/index.js +1 -1
  20. package/plugins/datasets/src/index.js +0 -1
  21. package/plugins/datasets/src/index.test.js +2 -8
  22. package/plugins/datasets/src/registry/dataset.test.js +9 -0
  23. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
  24. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  25. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  26. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  27. package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
  28. package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
  29. package/plugins/search/dist/css/index.css +1 -1
  30. package/plugins/search/src/components/Form/Form.module.scss +1 -0
  31. package/providers/esri/dist/esm/im-esri-provider.js +1 -1
  32. package/providers/esri/src/esriProvider.js +10 -21
  33. package/providers/esri/src/utils/coords.js +37 -7
  34. package/providers/esri/src/utils/coords.test.js +22 -1
  35. package/providers/esri/src/utils/spatial.js +1 -47
  36. package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
  37. package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
  38. package/providers/maplibre/src/maplibreProvider.js +5 -14
  39. package/providers/maplibre/src/maplibreProvider.test.js +143 -146
  40. package/providers/maplibre/src/utils/spatial.js +0 -40
  41. package/providers/maplibre/src/utils/spatial.test.js +0 -35
  42. package/providers/openlayers/dist/esm/im-openlayers-provider.js +1 -1
  43. package/providers/openlayers/dist/umd/im-openlayers-provider.js +1 -1
  44. package/providers/openlayers/src/openlayersProvider.js +5 -14
  45. package/providers/openlayers/src/openlayersProvider.test.js +12 -10
  46. package/providers/openlayers/src/utils/spatial.js +0 -39
  47. package/providers/openlayers/src/utils/spatial.test.js +1 -26
  48. package/src/App/components/Hints/Hints.jsx +9 -21
  49. package/src/App/components/Hints/Hints.test.jsx +20 -33
  50. package/src/App/components/Panel/Panel.jsx +16 -1
  51. package/src/App/components/Panel/Panel.test.jsx +44 -0
  52. package/src/App/hooks/useCrossHairAPI.js +27 -28
  53. package/src/App/hooks/useCrossHairAPI.test.js +64 -7
  54. package/src/App/hooks/useLayoutMeasurements.js +175 -131
  55. package/src/App/hooks/useLayoutMeasurements.test.js +227 -122
  56. package/src/App/hooks/useMapProviderOverrides.js +114 -35
  57. package/src/App/hooks/useMapProviderOverrides.test.js +188 -5
  58. package/src/App/hooks/useModalPanelBehaviour.js +18 -32
  59. package/src/App/hooks/useModalPanelBehaviour.test.js +45 -33
  60. package/src/App/hooks/useVisibleGeometry.js +35 -45
  61. package/src/App/hooks/useVisibleGeometry.test.js +149 -121
  62. package/src/App/layout/Layout.jsx +4 -4
  63. package/src/App/layout/layout.module.scss +124 -61
  64. package/src/App/store/AppProvider.jsx +3 -0
  65. package/src/App/store/appDispatchMiddleware.js +18 -10
  66. package/src/App/store/appDispatchMiddleware.test.js +42 -4
  67. package/src/InteractiveMap/InteractiveMap.js +3 -2
  68. package/src/InteractiveMap/InteractiveMap.test.js +2 -2
  69. package/src/config/events.js +1 -1
  70. package/src/config/mapPanelSlots.js +8 -0
  71. package/src/config/symbolConfig.js +1 -1
  72. package/src/services/symbolRegistry.js +1 -1
  73. package/src/services/symbolRegistry.test.js +19 -0
  74. package/src/types.js +29 -8
  75. package/src/utils/getFitMove.js +73 -0
  76. package/src/utils/getFitMove.test.js +114 -0
  77. package/src/utils/getSafeZoneInset.js +122 -77
  78. package/src/utils/getSafeZoneInset.test.js +241 -54
  79. package/src/utils/getValueForStyle.js +10 -5
  80. package/src/utils/getValueForStyle.test.js +13 -2
  81. package/src/utils/renderedBoxes.js +25 -0
  82. package/src/utils/renderedBoxes.test.js +61 -0
  83. package/src/utils/screenBox.js +70 -0
  84. package/src/utils/screenBox.test.js +69 -0
  85. package/src/utils/symbolUtils.js +9 -9
  86. package/src/utils/symbolUtils.test.js +21 -0
  87. package/providers/esri/src/utils/spatial.test.js +0 -58
@@ -3,66 +3,101 @@ import { useResizeObserver } from './useResizeObserver.js'
3
3
  import { useApp } from '../store/appContext.js'
4
4
  import { useMap } from '../store/mapContext.js'
5
5
  import { getSafeZoneInset } from '../../utils/getSafeZoneInset.js'
6
+ import { renderedBoxes, topColHeight } from '../../utils/renderedBoxes.js'
6
7
 
7
8
  const BANNER_DOCKED_CLASS = 'im-o-app__banner--docked'
8
9
  const BANNER_PANEL_SELECTOR = '.im-c-panel--banner'
9
10
  const ATTRIBUTIONS_STACKED_CLASS = 'im-o-app__attributions--stacked'
11
+ const TOP_WRAPPED_CLASS = 'im-o-app__top--wrapped'
12
+ const SUBPIXEL_TOLERANCE = 1
10
13
 
11
14
  const buttonHeight = (ref) => ref?.current?.offsetHeight ?? 0
12
15
  const buttonWidth = (ref) => ref?.current?.offsetWidth ?? 0
13
16
 
14
- // Whether an element renders anything. The control wrapper core puts around each plugin control is
15
- // display: contents, with no box of its own, so it counts as rendered if any child is.
16
- const isRendered = (element) => {
17
- if (element.hidden) {
18
- return false
19
- }
20
- if (element.getClientRects().length > 0) {
21
- return true
22
- }
23
- return element.classList.contains('im-c-control-wrapper') && Array.from(element.children).some(isRendered)
17
+ // The wider of the two sides, so centred content stays in the middle.
18
+ const symmetricWidth = (left, right) => left || right ? Math.max(left, right) : 0
19
+
20
+ // The top of the highest of these bottom row elements that shows, relative to main, or null if none
21
+ // do. Measured from the page, as they're nested at different depths in the row.
22
+ const bottomRowTop = (mainRect, elements) => {
23
+ const tops = elements.filter(element => element?.offsetHeight).map(element => element.getBoundingClientRect().top - mainRect.top)
24
+ return tops.length ? Math.min(...tops) : null
24
25
  }
25
26
 
26
- // A top column whose children are all display:none (hiddenWhen buttons, or items an application mode
27
- // hides) isn't :empty, so it keeps its trailing padding-bottom — which would push the side column
28
- // below it down by a gap. Treat it as empty instead.
29
- const topColHeight = (col) => {
30
- const children = Array.from(col.children)
31
- const isAllHidden = children.length > 0 && !children.some(isRendered)
32
- return isAllHidden ? 0 : col.offsetHeight
27
+ // Keeps the keyboard hint just above the bottom-left column (the logo and bottom-left buttons) and
28
+ // attributions, ignoring the bottom-right slot so opening the map controls doesn't move it. It also
29
+ // clears the actions bar, and anything below the bottom row, such as the drawer on mobile.
30
+ const hintBottom = ({ main, mainRect, bottom, bottomLeftCol, attributions, actionsEl, gap }) => {
31
+ const rowTop = bottomRowTop(mainRect, [bottomLeftCol, attributions]) ?? bottom.offsetTop + bottom.offsetHeight
32
+ const actionsOffset = actionsEl?.offsetHeight ? main.offsetHeight - actionsEl.offsetTop : 0
33
+ return Math.max(main.offsetHeight - rowTop, actionsOffset) + gap
33
34
  }
34
35
 
35
- // Max of both sides, so centred content doesn't lean toward the emptier one.
36
- const symmetricWidth = (left, right) => left || right ? Math.max(left, right) : 0
36
+ const actionsBarRect = (actionsEl) => {
37
+ const bar = actionsEl?.querySelector('.im-c-actions')
38
+ return bar?.offsetHeight ? bar.getBoundingClientRect() : null
39
+ }
40
+
41
+ // A sub-slot with only hidden items still has a box, so the column would leave a gap next to it.
42
+ // Only add the gap when both sub-slots show something.
43
+ const slotHasContent = (ref) => renderedBoxes(ref?.current).length > 0
44
+
45
+ const subSlotGap = (topRef, bottomRef, gap) => slotHasContent(topRef) && slotHasContent(bottomRef) ? gap : 0
46
+
47
+ const columnContentHeight = (topRef, bottomRef, gap) => buttonHeight(topRef) + buttonHeight(bottomRef) + subSlotGap(topRef, bottomRef, gap)
48
+
49
+ // How far the actions bar's top is above the bottom of main, when anything in the sub-slot would
50
+ // overlap the bar, or come within margin of it: in line with it and reaching down to it. Otherwise 0.
51
+ // Measured with the side columns as they'd be without the bar (see applyColumnLayout). The sub-slot
52
+ // itself is as wide as the column, so what it shows is measured instead.
53
+ const actionsBarOverlap = (mainRect, barRect, slotRef, margin) => {
54
+ if (!barRect) {
55
+ return 0
56
+ }
57
+ const isInLine = (box) => barRect.left - margin < box.right && barRect.right + margin > box.left
58
+ const reachesBar = (box) => box.bottom > barRect.top - margin
59
+ const isOverlapping = renderedBoxes(slotRef?.current).some(box => isInLine(box) && reachesBar(box))
60
+ return isOverlapping ? mainRect.bottom - barRect.top : 0
61
+ }
62
+
63
+ // On tablet and desktop the actions bar floats over the middle of the map. Only what would
64
+ // overlap it moves: a bottom sub-slot lifts the whole column above the bar, and a top sub-slot
65
+ // is capped above the bar, so the bottom sub-slot stays where it is. On mobile the bar is below
66
+ // the bottom row, so it never moves a column.
67
+ const clearActionsBar = ({ mainRect, barRect, mainHeight, baseOffsetBottom, offsetTop, topRef, bottomRef, gap }) => {
68
+ const topOverlap = actionsBarOverlap(mainRect, barRect, topRef, gap)
69
+ const bottomOverlap = actionsBarOverlap(mainRect, barRect, bottomRef, gap)
70
+ return {
71
+ offsetBottom: bottomOverlap > 0 ? Math.max(baseOffsetBottom, bottomOverlap + gap) : baseOffsetBottom,
72
+ topSlotMaxHeight: topOverlap > 0 ? `${Math.max(0, mainHeight - topOverlap - gap - offsetTop)}px` : 'none'
73
+ }
74
+ }
37
75
 
38
- const subSlotMaxHeight = (columnHeight, siblingButtons, gap) => columnHeight - (siblingButtons ? siblingButtons + gap : 0)
39
-
40
- // bottomRightHeight is 0 when empty, falling back to the attributions' own height for spacing.
41
- // rise is how far attributions has lifted .im-o-app__bottom-right above .im-o-app__bottom's
42
- // own bottom edge (see attributionsRise below) — without adding it here, .im-o-app__right's
43
- // computed bottom offset stays at the box's un-lifted position and the floating right column
44
- // overlaps the now-raised bottom-right buttons.
45
- const rightOffsetBottom = (containerPad, bottomRightHeight, attributionsHeight, rise, gap) =>
46
- containerPad + (bottomRightHeight > 0 ? bottomRightHeight + rise + gap : attributionsHeight)
47
-
48
- // Clears the bottom row's own TOP edge (not just its trailing gap below), so the hint
49
- // never overlaps the logo/attribution row itself, plus a gap above it. That trivially
50
- // also clears anything after the row in flow — mobile's in-flow actions bar included.
51
- // Tablet/desktop's floating actions bar can sit independently higher than the row, so
52
- // still needs its own explicit clearance, hence the Math.max with actionsOffset below.
53
- const hintBottom = (main, bottom, actionsEl, gap) => {
54
- const clearsBottomRow = main.offsetHeight - bottom.offsetTop + gap
55
- const actionsHeight = actionsEl?.offsetHeight ?? 0
56
- const actionsOffset = actionsHeight > 0 ? main.offsetHeight - actionsEl.offsetTop : 0
57
- return Math.max(clearsBottomRow, actionsOffset + gap)
76
+ // How far the actions bar, the last thing in main, runs past the bottom of main.
77
+ const flowOverflow = (main, actions) => {
78
+ if (!actions) {
79
+ return 0
80
+ }
81
+ const mainRect = main.getBoundingClientRect()
82
+ const marginBottom = Number.parseFloat(getComputedStyle(actions).marginBottom) || 0
83
+ const paddingBottom = Number.parseFloat(getComputedStyle(main).paddingBottom) || 0
84
+ return Math.max(0, actions.getBoundingClientRect().bottom + marginBottom - (mainRect.bottom - paddingBottom))
58
85
  }
59
86
 
60
- // Space between .im-o-app__left/.im-o-app__right for the banner to dock in.
87
+ // On mobile the drawer sits below the map, but the side columns float over the map, so a tall
88
+ // drawer would squeeze them until their buttons sit under it, then run off the bottom. Its max
89
+ // height is its own height plus the space left in the fuller side column, less any overflow, so
90
+ // it stops just short of both, and grows again when there's room.
91
+ const drawerMaxHeight = (drawerRef, columnSlack, overflow) => slotHasContent(drawerRef)
92
+ ? `${Math.max(0, Math.floor(drawerRef.current.offsetHeight + columnSlack - overflow))}px`
93
+ : 'none'
94
+
95
+ // The space between the side columns, where a centred banner goes.
61
96
  const bannerGutterWidth = (mainWidth, sideColWidth, gap) => mainWidth - (sideColWidth * 2) - (gap * 2)
62
97
 
63
98
  const isBannerDocked = (gutterWidth, preferredWidth) => gutterWidth >= preferredWidth
64
99
 
65
- // Widest explicit width configured on a banner panel, if any, overriding the default.
100
+ // The widest width set on a banner panel, if any, used instead of the default.
66
101
  const bannerConfiguredWidth = (bannerEl) => {
67
102
  const widths = Array.from(bannerEl?.querySelectorAll(BANNER_PANEL_SELECTOR) ?? [])
68
103
  .map(el => Number.parseInt(el.style.width, 10))
@@ -70,19 +105,17 @@ const bannerConfiguredWidth = (bannerEl) => {
70
105
  return widths.length ? Math.max(...widths) : null
71
106
  }
72
107
 
73
- // Mobile always stacks full-width, so any inline width Panel.jsx applied is ignored.
108
+ // On mobile the banner is always full width, so remove any width set on its panels.
74
109
  const clearBannerPanelWidths = (bannerEl) => {
75
110
  bannerEl?.querySelectorAll(BANNER_PANEL_SELECTOR).forEach(el => { el.style.width = '' })
76
111
  }
77
112
 
78
- // Docked insets to the side-column width; stacked is full-bleed.
113
+ // A centred banner is inset by the side column width; a full-width one isn't.
79
114
  const bannerInset = (isDocked, primaryGap, sideColWidth, gap) =>
80
115
  isDocked ? primaryGap + sideColWidth + gap : primaryGap
81
116
 
82
- // Natural (unwrapped) width of the attribution text, measured by forcing nowrap just long
83
- // enough to read scrollWidth, then restoring — same "mutate, measure, restore" approach as
84
- // clearBannerPanelWidths/bannerConfiguredWidth above. Needed because once wrapping is
85
- // allowed, scrollWidth alone can't tell us how wide the text *would* be on one line.
117
+ // The width of the attribution text on one line. Turns wrapping off just long enough to measure
118
+ // it, then turns it back on.
86
119
  const attributionsNaturalWidth = (attributionsEl) => {
87
120
  const textEl = attributionsEl?.firstElementChild
88
121
  if (!textEl) {
@@ -95,30 +128,15 @@ const attributionsNaturalWidth = (attributionsEl) => {
95
128
  return width
96
129
  }
97
130
 
98
- // Stacks (drops to its own full-width row below the logo) once the attribution text no
99
- // longer fits, at its natural width, in the space beside the logo column.
100
- const isAttributionsStacked = (naturalWidth, availableWidth) => naturalWidth > availableWidth
101
-
102
- // How far attributions lifts .im-o-app__bottom-right above .im-o-app__bottom's own bottom
103
- // edge. The same figure covers both modes, because both bleed primaryGap past that edge and
104
- // then take attributionsHeight (plus a dividerGap) back up from there:
105
- // - docked: the box grows upward from the bleed into the row itself, where
106
- // .im-o-app__bottom-right shares the same horizontal space, so the row needs an explicit
107
- // margin-bottom (--bottom-right-clearance) to stay clear of it;
108
- // - stacked: the box is an extra flex line *below* the row, so it lifts the row by exactly
109
- // that much on its own — no margin needed, hence bottomRightClearance's isStacked branch.
110
- // Either way .im-o-app__right must clear the lift, so the offsets below use this, not the
111
- // clearance. Clamped at 0: a box shorter than its own bleed lifts nothing.
112
- const attributionsRise = (attributionsHeight, dividerGap, primaryGap) =>
113
- Math.max(0, attributionsHeight + dividerGap - primaryGap)
114
-
115
- // Stacked gets its lift from the extra flex line itself (see attributionsRise above), so only
116
- // docked needs the row pushed up by a margin.
117
- const bottomRightClearance = (isStacked, rise) => isStacked ? 0 : rise
118
-
119
- // Docks centred between the side columns when there's room, otherwise stacks full-width
120
- // (mobile always stacks). Sets the banner's own CSS vars and returns what the side-column
121
- // offset calc below needs.
131
+ // Lets the top row's columns wrap once they no longer fit on one line. Measured without the class,
132
+ // so the row's natural width decides, rather than how it's currently wrapped.
133
+ function applyTopRowLayout (top) {
134
+ top.classList.remove(TOP_WRAPPED_CLASS)
135
+ top.classList.toggle(TOP_WRAPPED_CLASS, top.scrollWidth > top.clientWidth + SUBPIXEL_TOLERANCE)
136
+ }
137
+
138
+ // Centres the banner between the side columns when there's room, otherwise puts it on its own
139
+ // full-width row (always on mobile). Returns what the side column offsets below need.
122
140
  function applyBannerLayout ({ appContainer, root, top, bannerRef, leftRef, rightRef, isMobile, dividerGap, primaryGap }) {
123
141
  const banner = bannerRef?.current
124
142
  if (isMobile) {
@@ -138,7 +156,7 @@ function applyBannerLayout ({ appContainer, root, top, bannerRef, leftRef, right
138
156
  appContainer.style.setProperty('--banner-left', bannerSideInset)
139
157
  appContainer.style.setProperty('--banner-right', bannerSideInset)
140
158
 
141
- // Sits at the top row's bottom edge; top.offsetHeight already includes a trailing gap.
159
+ // Sits just below the top row, which already includes a gap at the bottom.
142
160
  const isBannerStacked = hasBanner && !isDocked
143
161
  const bannerTop = hasBanner ? top.offsetTop + top.offsetHeight : 0
144
162
  appContainer.style.setProperty('--banner-top', `${bannerTop}px`)
@@ -146,41 +164,58 @@ function applyBannerLayout ({ appContainer, root, top, bannerRef, leftRef, right
146
164
  return { isBannerStacked, bannerTop, bannerHeight }
147
165
  }
148
166
 
149
- // Docks attributions beside the logo when its natural width fits there, otherwise stacks it
150
- // onto its own full-width row below (im-o-app__attributions--stacked, in layout.module.scss),
151
- // genuinely growing .im-o-app__bottom and pushing the logo and bottom-right buttons up. Must
152
- // run before the offsets below, since toggling the stacked class changes
153
- // bottom.offsetTop/offsetHeight that they read.
154
- function applyAttributionsLayout ({ appContainer, bottom, attributions, dividerGap, primaryGap }) {
155
- const attributionsCol = bottom.children[1] // the bottom-right column, a DOM sibling of attributions
156
- const isStacked = isAttributionsStacked(attributionsNaturalWidth(attributions), attributionsCol?.offsetWidth ?? 0)
167
+ // Puts the attributions beside the logo when they fit, otherwise on their own row below, which
168
+ // pushes the logo and bottom-right buttons up. Docked, they grow up beside the bottom-right buttons,
169
+ // so the buttons need a bottom margin to clear them. Stacked, they're a row below the buttons, which
170
+ // lifts them by the same amount without a margin.
171
+ function applyAttributionsLayout ({ appContainer, bottom, attributionsCol, attributions, dividerGap, primaryGap }) {
172
+ const isStacked = attributionsNaturalWidth(attributions) > (attributionsCol?.offsetWidth ?? 0)
157
173
  attributions.classList.toggle(ATTRIBUTIONS_STACKED_CLASS, isStacked)
158
- // getBoundingClientRect, not offset math, because .im-o-app__bottom's `justify-content:
159
- // space-between` gap between the two columns isn't a fixed value (unlike `gap`) to reconstruct.
174
+ // Measured from the page, because the space between the two bottom columns isn't a fixed gap.
160
175
  const left = attributionsCol ? Math.round(attributionsCol.getBoundingClientRect().left - bottom.getBoundingClientRect().left) : 0
161
176
  appContainer.style.setProperty('--attributions-left', `${left}px`)
162
- const rise = attributionsRise(attributions.offsetHeight, dividerGap, primaryGap)
163
- appContainer.style.setProperty('--bottom-right-clearance', `${bottomRightClearance(isStacked, rise)}px`)
164
- return { rise }
177
+ const clearance = isStacked ? 0 : Math.max(0, attributions.offsetHeight + dividerGap - primaryGap)
178
+ appContainer.style.setProperty('--bottom-right-clearance', `${clearance}px`)
179
+ }
180
+
181
+ // Places the side columns. Each runs from below the top row to a gap above what's shown on its own
182
+ // side of the bottom row, or to main's bottom padding when nothing is. They're put there without the
183
+ // actions bar's lift or cap before measuring what would overlap the bar. Otherwise moving something
184
+ // clear of the bar would change whether it needs to move, and the next measurement would undo it.
185
+ // The browser doesn't draw this in-between layout. Returns the room left below each column's content.
186
+ function applyColumnLayout ({ appContainer, main, actions, columns, gap }) {
187
+ const setColumn = (side, name, value) => appContainer.style.setProperty(`--${side}-${name}`, value)
188
+ Object.entries(columns).forEach(([side, { offsetTop, baseOffsetBottom, topRef, bottomRef }]) => {
189
+ setColumn(side, 'offset-top', `${offsetTop}px`)
190
+ setColumn(side, 'offset-bottom', `${baseOffsetBottom}px`)
191
+ setColumn(side, 'top-slot-max-height', 'none')
192
+ setColumn(side, 'slot-gap', `${subSlotGap(topRef, bottomRef, gap)}px`)
193
+ })
194
+
195
+ const mainRect = main.getBoundingClientRect()
196
+ const barRect = actionsBarRect(actions)
197
+ return Object.entries(columns).map(([side, { offsetTop, baseOffsetBottom, topRef, bottomRef }]) => {
198
+ const bar = clearActionsBar({ mainRect, barRect, mainHeight: main.offsetHeight, baseOffsetBottom, offsetTop, topRef, bottomRef, gap })
199
+ setColumn(side, 'offset-bottom', `${bar.offsetBottom}px`)
200
+ setColumn(side, 'top-slot-max-height', bar.topSlotMaxHeight)
201
+ return main.offsetHeight - bar.offsetBottom - offsetTop - columnContentHeight(topRef, bottomRef, gap)
202
+ })
165
203
  }
166
204
 
167
205
  /**
168
- * Computes layout CSS vars for the map overlay and dispatches the safe zone inset used
169
- * for `fitBounds`/`setView`. Waits for `arePluginsEvaluated` so the inset reflects final
170
- * button visibility rather than a mid-evaluation state, which would make the map jump.
206
+ * Sets the layout CSS variables for the map overlay and the safe zone used by `fitBounds` and
207
+ * `setView`. Waits until plugins are evaluated, so the map doesn't jump while buttons appear.
171
208
  */
172
209
  export function calculateLayout (layoutRefs, breakpoint) {
173
210
  const {
174
211
  appContainerRef, mainRef, topRef, topLeftColRef, topRightColRef,
175
- bottomRef, attributionsRef, bottomRightRef, leftTopRef, leftBottomRef,
176
- rightTopRef, rightBottomRef, actionsRef, bannerRef, leftRef, rightRef
212
+ bottomRef, bottomLeftColRef, bottomRightColRef, bottomRightRef, attributionsRef, leftTopRef, leftBottomRef,
213
+ rightTopRef, rightBottomRef, drawerRef, actionsRef, bannerRef, leftRef, rightRef
177
214
  } = layoutRefs
178
215
 
179
216
  const appContainer = appContainerRef.current
180
217
  const main = mainRef.current
181
218
  const top = topRef.current
182
- const topLeftCol = topLeftColRef.current
183
- const topRightCol = topRightColRef.current
184
219
  const bottom = bottomRef.current
185
220
  const attributions = attributionsRef.current
186
221
 
@@ -189,63 +224,72 @@ export function calculateLayout (layoutRefs, breakpoint) {
189
224
  }
190
225
 
191
226
  const root = document.documentElement
192
- const dividerGap = Number.parseInt(getComputedStyle(root).getPropertyValue('--divider-gap'), 10)
193
- const primaryGap = Number.parseInt(getComputedStyle(root).getPropertyValue('--primary-gap'), 10)
227
+ const rootStyle = getComputedStyle(root)
228
+ const dividerGap = Number.parseInt(rootStyle.getPropertyValue('--divider-gap'), 10)
229
+ const primaryGap = Number.parseInt(rootStyle.getPropertyValue('--primary-gap'), 10)
194
230
 
195
- // Banner: docks centred between the side columns when there's room, otherwise stacks
196
- // full-width. Mobile always stacks.
231
+ applyTopRowLayout(top)
232
+
233
+ // Banner: centred between the side columns when there's room, otherwise full width
197
234
  const isMobile = breakpoint === 'mobile'
198
235
  const { isBannerStacked, bannerTop, bannerHeight } = applyBannerLayout({
199
236
  appContainer, root, top, bannerRef, leftRef, rightRef, isMobile, dividerGap, primaryGap
200
237
  })
201
238
 
202
- // Stacked pushes the side columns below the banner plus a trailing gap — added here, not
203
- // via a CSS last-child margin, since closed consumer HTML panels stay in the DOM (display:none).
239
+ // A full-width banner pushes the side columns down below it. Done here rather than in CSS,
240
+ // because closed panels stay in the page, hidden.
204
241
  const sideOffsetTop = (colHeight) => isBannerStacked
205
242
  ? bannerTop + bannerHeight + dividerGap
206
243
  : colHeight + top.offsetTop
207
244
 
208
- const { rise: attributionsLift } = applyAttributionsLayout({ appContainer, bottom, attributions, dividerGap, primaryGap })
209
-
210
- // === Left container offsets ===
211
- const leftOffsetTop = sideOffsetTop(topColHeight(topLeftCol))
212
- const leftColumnHeight = bottom.offsetTop - leftOffsetTop - dividerGap
213
- appContainer.style.setProperty('--left-offset-top', `${leftOffsetTop}px`)
214
- appContainer.style.setProperty('--left-offset-bottom', `${main.offsetHeight - bottom.offsetTop + dividerGap}px`)
215
- appContainer.style.setProperty('--left-top-max-height', `${leftColumnHeight}px`)
216
-
217
- // === Right container offsets === (mirrors the left formula)
218
- const bottomRightHeight = buttonHeight(bottomRightRef)
219
- const bottomContainerPad = main.offsetHeight - bottom.offsetTop - bottom.offsetHeight
220
- const rightOffsetTop = sideOffsetTop(topColHeight(topRightCol))
221
- const rightEffectiveBottom = bottom.offsetTop + bottom.offsetHeight - bottomRightHeight - attributionsLift
222
- const rightColumnHeight = rightEffectiveBottom - rightOffsetTop - dividerGap
223
- appContainer.style.setProperty('--right-offset-top', `${rightOffsetTop}px`)
224
- appContainer.style.setProperty('--right-offset-bottom', `${rightOffsetBottom(bottomContainerPad, bottomRightHeight, attributions.offsetHeight, attributionsLift, dividerGap)}px`)
225
- appContainer.style.setProperty('--right-top-max-height', `${rightColumnHeight}px`)
245
+ applyAttributionsLayout({ appContainer, bottom, attributionsCol: bottomRightColRef?.current, attributions, dividerGap, primaryGap })
246
+
247
+ const actions = actionsRef?.current
248
+ const bottomLeftCol = bottomLeftColRef?.current
249
+ const mainRect = main.getBoundingClientRect()
250
+ // A gap above what's shown on that side of the bottom row, else main's bottom padding. Docked
251
+ // attributions sit on the right; stacked ones run the full width
252
+ const containerPad = main.offsetHeight - bottom.offsetTop - bottom.offsetHeight
253
+ const baseOffsetBottom = (rowElements) => {
254
+ const rowTop = bottomRowTop(mainRect, rowElements)
255
+ return rowTop === null ? containerPad : main.offsetHeight - rowTop + dividerGap
256
+ }
257
+ const isStacked = attributions.classList.contains(ATTRIBUTIONS_STACKED_CLASS)
258
+ const columns = {
259
+ left: {
260
+ offsetTop: sideOffsetTop(topColHeight(topLeftColRef.current)),
261
+ baseOffsetBottom: baseOffsetBottom([bottomLeftCol, isStacked && attributions]),
262
+ topRef: leftTopRef,
263
+ bottomRef: leftBottomRef
264
+ },
265
+ right: {
266
+ offsetTop: sideOffsetTop(topColHeight(topRightColRef.current)),
267
+ baseOffsetBottom: baseOffsetBottom([bottomRightRef?.current, attributions]),
268
+ topRef: rightTopRef,
269
+ bottomRef: rightBottomRef
270
+ }
271
+ }
272
+ const columnSlack = applyColumnLayout({ appContainer, main, actions, columns, gap: dividerGap })
273
+
274
+ // === Drawer max height ===
275
+ appContainer.style.setProperty('--drawer-max-height', drawerMaxHeight(drawerRef, Math.min(...columnSlack), flowOverflow(main, actions)))
226
276
 
227
277
  // === Keyboard hint bottom offset ===
228
- appContainer.style.setProperty('--hint-bottom', `${hintBottom(main, bottom, actionsRef?.current, dividerGap)}px`)
229
-
230
- // === Sub-slot panel max-heights ===
231
- appContainer.style.setProperty('--left-top-panel-max-height', `${subSlotMaxHeight(leftColumnHeight, buttonHeight(leftBottomRef), dividerGap)}px`)
232
- appContainer.style.setProperty('--left-bottom-panel-max-height', `${subSlotMaxHeight(leftColumnHeight, buttonHeight(leftTopRef), dividerGap)}px`)
233
- appContainer.style.setProperty('--right-top-panel-max-height', `${subSlotMaxHeight(rightColumnHeight, buttonHeight(rightBottomRef), dividerGap)}px`)
234
- appContainer.style.setProperty('--right-bottom-panel-max-height', `${subSlotMaxHeight(rightColumnHeight, buttonHeight(rightTopRef), dividerGap)}px`)
278
+ appContainer.style.setProperty('--hint-bottom', `${hintBottom({ main, mainRect, bottom, bottomLeftCol, attributions, actionsEl: actions, gap: dividerGap })}px`)
235
279
  }
236
280
 
237
281
  export function useLayoutMeasurements () {
238
282
  const { dispatch, breakpoint, layoutRefs, arePluginsEvaluated, appVisible, isFullscreen } = useApp()
239
283
  const { mapSize, isMapReady } = useMap()
240
284
 
241
- const { bannerRef, mainRef, headerRef, topRef, topLeftColRef, topRightColRef, bottomRef, bottomRightRef, attributionsRef, leftTopRef, leftBottomRef, rightTopRef, rightBottomRef, drawerRef, actionsRef, leftRef, rightRef } = layoutRefs
285
+ const { bannerRef, mainRef, headerRef, topRef, topLeftColRef, topMiddleColRef, topRightColRef, bottomRef, bottomLeftColRef, bottomRightRef, attributionsRef, leftTopRef, leftBottomRef, rightTopRef, rightBottomRef, drawerRef, actionsRef, leftRef, rightRef } = layoutRefs
242
286
 
243
- // 1. Clear the evaluated flag on structural changes, gating the safe zone until re-evaluated.
287
+ // 1. When the layout changes, wait for plugins to be evaluated again before setting the safe zone.
244
288
  useLayoutEffect(() => {
245
289
  dispatch({ type: 'CLEAR_PLUGINS_EVALUATED' })
246
290
  }, [breakpoint, mapSize, isMapReady, appVisible, isFullscreen])
247
291
 
248
- // 2. Once evaluated, recalculate layout and dispatch the safe zone (RAF waits for layout to commit).
292
+ // 2. Once they are, set the layout and the safe zone on the next frame, after the page has updated.
249
293
  useLayoutEffect(() => {
250
294
  if (!arePluginsEvaluated) {
251
295
  return
@@ -259,12 +303,12 @@ export function useLayoutMeasurements () {
259
303
  })
260
304
  }, [arePluginsEvaluated])
261
305
 
262
- // 3. Recalculate CSS vars on resize; safe zone dispatch stays Effect 2's job.
263
- // Memoized so useResizeObserver doesn't re-run (and cancel its RAF) on every render.
306
+ // 3. Set the layout again whenever any of these change size. The safe zone is left to step 2.
307
+ // Memoized so the observer isn't set up again on every render.
264
308
  const observedRefs = useMemo(
265
- // attributionsRef included so its height (now variable, since attribution text can wrap
266
- // onto multiple lines) recalculates --right-offset-bottom when the wrap changes.
267
- () => [bannerRef, mainRef, headerRef, topRef, topLeftColRef, topRightColRef, actionsRef, bottomRef, bottomRightRef, attributionsRef, leftTopRef, leftBottomRef, rightTopRef, rightBottomRef, drawerRef, leftRef, rightRef],
309
+ // Includes the attributions, which change height when their text wraps, and the bottom-left
310
+ // column, which changes size when the logo loads or its buttons change
311
+ () => [bannerRef, mainRef, headerRef, topRef, topLeftColRef, topMiddleColRef, topRightColRef, actionsRef, bottomRef, bottomLeftColRef, bottomRightRef, attributionsRef, leftTopRef, leftBottomRef, rightTopRef, rightBottomRef, drawerRef, leftRef, rightRef],
268
312
  []
269
313
  )
270
314