@loidolt/theme-maps 0.8.1 → 0.9.1

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.
@@ -150,6 +150,8 @@
150
150
  let styleVersion = $state(0);
151
151
  let failure = $state<string | null>(null);
152
152
  let layers = $state.raw<LayerEntry[]>([]);
153
+ /** The last `bounds` box fitted, as JSON; `null` when none has been. Not reactive. */
154
+ let fittedBounds: string | null = null;
153
155
  /** A style chosen through `setBasemap` with a document of its own. */
154
156
  let customBasemap = $state.raw<string | StyleSpecification | null>(null);
155
157
 
@@ -315,7 +317,10 @@
315
317
  styleVersion += 1;
316
318
  if (loaded) return;
317
319
  loaded = true;
320
+ // Record the box only when one was fitted, so a first `bounds` that arrives after
321
+ // load is still fitted by the effect below.
318
322
  const box = untrack(() => bounds);
323
+ fittedBounds = box ? JSON.stringify(box) : null;
319
324
  if (box) created.fitBounds(box, { padding: boundsPadding, animate: false });
320
325
  untrack(() => onLoad?.(created));
321
326
  });
@@ -396,6 +401,8 @@
396
401
  });
397
402
 
398
403
  // Props into the map. A move the map made itself comes back equal, so it is a no-op.
404
+ // Declared before the bounds effect on purpose: when `center`/`zoom` and `bounds` change in
405
+ // the same tick, the ease starts first and the fit then replaces it, so `bounds` wins.
399
406
  $effect(() => {
400
407
  const target = instance;
401
408
  if (!target || !loaded) return;
@@ -412,16 +419,16 @@
412
419
  else target.easeTo(next);
413
420
  });
414
421
 
415
- let fittedBounds: string | null = null;
422
+ // `bounds` into the map: fit whenever the box differs from the last one fitted, including
423
+ // the first box to arrive after load. Clearing `bounds` forgets it, so the same box fits again.
416
424
  $effect(() => {
417
425
  const target = instance;
418
- const key = bounds ? JSON.stringify(bounds) : null;
419
- if (!target || !loaded || !bounds) return;
420
- if (fittedBounds === null) {
421
- // The load handler made the first fit.
422
- fittedBounds = key;
426
+ if (!bounds) {
427
+ fittedBounds = null;
423
428
  return;
424
429
  }
430
+ if (!target || !loaded) return;
431
+ const key = JSON.stringify(bounds);
425
432
  if (key === fittedBounds) return;
426
433
  fittedBounds = key;
427
434
  target.fitBounds(bounds, {
@@ -71,6 +71,6 @@ interface Props extends Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'oncli
71
71
  class?: string;
72
72
  ref?: HTMLDivElement | null;
73
73
  }
74
- declare const MapView: import("svelte").Component<Props, {}, "map" | "ref" | "zoom" | "center" | "basemap">;
74
+ declare const MapView: import("svelte").Component<Props, {}, "ref" | "map" | "zoom" | "center" | "basemap">;
75
75
  type MapView = ReturnType<typeof MapView>;
76
76
  export default MapView;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loidolt/theme-maps",
3
- "version": "0.8.1",
3
+ "version": "0.9.1",
4
4
  "description": "Accessible, themed MapLibre maps for Loidolt applications",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -38,8 +38,8 @@
38
38
  "clean": "rimraf dist"
39
39
  },
40
40
  "dependencies": {
41
- "@loidolt/theme-svelte": "^0.8.1",
42
- "@loidolt/theme-tokens": "^0.8.1",
41
+ "@loidolt/theme-svelte": "^0.9.1",
42
+ "@loidolt/theme-tokens": "^0.9.1",
43
43
  "rbush": "^4.0.1"
44
44
  },
45
45
  "peerDependencies": {