@ruckc/truss-ol 1.50.1 → 1.51.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.
@@ -18,7 +18,7 @@
18
18
  import { useLabels } from './labels.js';
19
19
  import { cssvars } from './cssvars.js';
20
20
  import type OLMap from 'ol/Map.js';
21
- import { watchView, type ControlPosition, type HeadingStatus } from './util.js';
21
+ import { moveMs, watchView, type ControlPosition, type HeadingStatus } from './util.js';
22
22
 
23
23
  let {
24
24
  map,
@@ -97,7 +97,7 @@
97
97
  const reset = () => {
98
98
  const v = map!.getView();
99
99
  // the nearest multiple of a full turn, so it never spins the long way round
100
- v.animate({ rotation: Math.round(v.getRotation() / (2 * Math.PI)) * 2 * Math.PI, duration });
100
+ v.animate({ rotation: Math.round(v.getRotation() / (2 * Math.PI)) * 2 * Math.PI, duration: moveMs(duration) });
101
101
  headingUp = false;
102
102
  };
103
103
  </script>
@@ -129,6 +129,5 @@
129
129
  .b:focus-visible { outline: 2px solid var(--tr-primary); outline-offset: -2px; }
130
130
  .b:disabled { opacity: 0.5; cursor: default; }
131
131
  .b[aria-pressed='true'] { background: var(--tr-primary-container); color: var(--tr-on-primary-container); }
132
- svg { transition: transform 0.1s linear; }
133
- @media (prefers-reduced-motion: reduce) { svg { transition: none; } }
132
+ svg { transition: transform var(--tr-dur-move-fast) linear; }
134
133
  </style>
package/dist/Map.svelte CHANGED
@@ -61,7 +61,7 @@
61
61
  import type { Basemap, FitOptions, FitTarget, MapApi, MapFeatureInfo, MapMarker, MapSelection, MapViewChange, MapViewState } from './types.js';
62
62
  import {
63
63
  DEFAULT_PALETTES, EMPTY_STORE, NATIVE_CLUSTER_MAX, aggregate, drawPie, pieKey, pieStroke, addStat, autoMode, clusterProps, clusterRadius, compactCount, compileCluster, compileStyle, cssGradient, featureTitle,
64
- isLight, lonLatExtent, newStat, numbersOf, popupEntries, propertyStyle, storeExtent, toStore, validLonLat, weightsOf, withAlpha,
64
+ isLight, lonLatExtent, moveMs, newStat, numbersOf, popupEntries, propertyStyle, storeExtent, toStore, validLonLat, weightsOf, withAlpha,
65
65
  type ClusterInfo, type ClusterStyle, type Compiled, type CompiledCluster, type FeatureStyle, type HeatmapOptions, type LegendInfo, type MapStyle, type Palettes, type PointStore, type PointsInput, type PointsMode, type Props
66
66
  } from './util.js';
67
67
 
@@ -549,13 +549,13 @@
549
549
  view() {
550
550
  // apply only what the consumer changed since the last value we saw: the defaults never undo a fit, a pan or a zoom
551
551
  const c = toLonLat(view.getCenter()!);
552
- if ((center[0] !== seenC![0] || center[1] !== seenC![1]) && (Math.abs(c[0] - center[0]) > 1e-5 || Math.abs(c[1] - center[1]) > 1e-5)) view.animate({ center: fromLonLat(center), duration: 250 });
553
- if (zoom !== seenZ && Math.abs((view.getZoom() ?? 0) - zoom) > 0.01) view.animate({ zoom, duration: 250 });
552
+ if ((center[0] !== seenC![0] || center[1] !== seenC![1]) && (Math.abs(c[0] - center[0]) > 1e-5 || Math.abs(c[1] - center[1]) > 1e-5)) view.animate({ center: fromLonLat(center), duration: moveMs(250) });
553
+ if (zoom !== seenZ && Math.abs((view.getZoom() ?? 0) - zoom) > 0.01) view.animate({ zoom, duration: moveMs(250) });
554
554
  seenC = [center[0], center[1]]; seenZ = zoom;
555
555
  }
556
556
  };
557
557
  ctl = {
558
- zoomBy: (d) => view.animate({ zoom: Math.min(Math.max((view.getZoom() ?? 0) + d, view.getMinZoom()), view.getMaxZoom()), duration: 200 }),
558
+ zoomBy: (d) => view.animate({ zoom: Math.min(Math.max((view.getZoom() ?? 0) + d, view.getMinZoom()), view.getMaxZoom()), duration: moveMs(200) }),
559
559
  fit: (target, o = {}) => {
560
560
  let ext = createEmpty();
561
561
  if (target === undefined) {
@@ -568,11 +568,11 @@
568
568
  }
569
569
  if (isEmpty(ext)) return;
570
570
  const pad = typeof o.padding === 'number' ? [o.padding, o.padding, o.padding, o.padding] : o.padding ?? [56, 56, 56, 56];
571
- view.fit(ext, { padding: pad, maxZoom: o.maxZoom ?? 12, duration: o.duration ?? 300 });
571
+ view.fit(ext, { padding: pad, maxZoom: o.maxZoom ?? 12, duration: moveMs(o.duration ?? 300) });
572
572
  },
573
573
  setView: (v) => {
574
574
  const to = { ...(v.center && { center: fromLonLat(v.center) }), ...(v.zoom !== undefined && { zoom: v.zoom }) };
575
- if (v.duration) view.animate({ ...to, duration: v.duration });
575
+ if (v.duration) view.animate({ ...to, duration: moveMs(v.duration) });
576
576
  else { if (to.center) view.setCenter(to.center); if (to.zoom !== undefined) view.setZoom(to.zoom); }
577
577
  },
578
578
  getView: () => ({
@@ -628,8 +628,8 @@
628
628
  if (cl) {
629
629
  // a cluster zooms in on its members (or two levels when they all sit on one spot)
630
630
  const [x0, y0, x1, y1] = cl.bbox;
631
- if (x1 - x0 < 1 && y1 - y0 < 1) view.animate({ center: [x0, y0], zoom: Math.min((view.getZoom() ?? 0) + 2, view.getMaxZoom()), duration: 300 });
632
- else view.fit(cl.bbox, { padding: [60, 60, 60, 60], duration: 300, maxZoom: view.getMaxZoom() });
631
+ if (x1 - x0 < 1 && y1 - y0 < 1) view.animate({ center: [x0, y0], zoom: Math.min((view.getZoom() ?? 0) + 2, view.getMaxZoom()), duration: moveMs(300) });
632
+ else view.fit(cl.bbox, { padding: [60, 60, 60, 60], duration: moveMs(300), maxZoom: view.getMaxZoom() });
633
633
  } else if (hit) choose(hit.f, e.coordinate);
634
634
  else clear();
635
635
  });
@@ -16,7 +16,7 @@
16
16
  import { useLabels } from './labels.js';
17
17
  import { Button } from '@ruckc/truss-ui';
18
18
  import type OLMap from 'ol/Map.js';
19
- import { watchView, watchCoarse, cornerZone, rectDistance, type ControlPosition } from './util.js';
19
+ import { moveMs, watchView, watchCoarse, cornerZone, rectDistance, type ControlPosition } from './util.js';
20
20
 
21
21
  let {
22
22
  map,
@@ -96,9 +96,9 @@
96
96
  const zoomBy = (d: number) => {
97
97
  const v = map!.getView();
98
98
  goal = (v.getAnimating() && goal !== undefined ? goal : zoom) + d;
99
- v.animate({ zoom: goal, duration });
99
+ v.animate({ zoom: goal, duration: moveMs(duration) });
100
100
  };
101
- const fit = () => map!.getView().fit(extent ?? map!.getView().getProjection().getExtent(), { duration });
101
+ const fit = () => map!.getView().fit(extent ?? map!.getView().getProjection().getExtent(), { duration: moveMs(duration) });
102
102
  </script>
103
103
 
104
104
  <div
@@ -126,5 +126,4 @@
126
126
  .zc[data-pos='top-right'] { position: absolute; top: 8px; right: 8px; }
127
127
  .zc[data-pos='bottom-left'] { position: absolute; bottom: 8px; left: 8px; }
128
128
  .zc[data-pos='bottom-right'] { position: absolute; bottom: 8px; right: 8px; }
129
- @media (prefers-reduced-motion: reduce) { .zc { transition: none; } }
130
129
  </style>
package/dist/util.d.ts CHANGED
@@ -61,5 +61,7 @@ export declare function cornerZone(area: Rect, box: Rect, position: ControlPosit
61
61
  export declare function rectDistance(r: Rect, x: number, y: number): number;
62
62
  /** Call `cb` now and whenever the map's view moves, zooms or rotates (also across `map.setView`). Returns the unsubscribe. */
63
63
  export declare function watchView(map: OLMap, cb: () => void): () => void;
64
+ /** A camera move's duration in ms: 0 under reduced motion (the view jumps instead of panning or zooming), else `ms`. */
65
+ export declare function moveMs(ms: number): number;
64
66
  /** Report whether the primary pointer is coarse (touch), now and when it changes. Returns the unsubscribe. */
65
67
  export declare function watchCoarse(cb: (coarse: boolean) => void): () => void;
package/dist/util.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { labelFor } from './labels.js';
2
+ import { prefersReducedMotion } from '@ruckc/truss-ui';
2
3
  export * from './style.js';
3
4
  export * from './points.js';
4
5
  const LADDER = {
@@ -103,6 +104,10 @@ export function watchView(map, cb) {
103
104
  cb();
104
105
  return () => { off(); map.un('change:view', swap); };
105
106
  }
107
+ /** A camera move's duration in ms: 0 under reduced motion (the view jumps instead of panning or zooming), else `ms`. */
108
+ export function moveMs(ms) {
109
+ return prefersReducedMotion() ? 0 : ms;
110
+ }
106
111
  /** Report whether the primary pointer is coarse (touch), now and when it changes. Returns the unsubscribe. */
107
112
  export function watchCoarse(cb) {
108
113
  const mq = matchMedia('(pointer: coarse)');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruckc/truss-ol",
3
- "version": "1.50.1",
3
+ "version": "1.51.1",
4
4
  "description": "OpenLayers map styled with Truss UI",
5
5
  "type": "module",
6
6
  "license": "MIT",