@ruckc/truss-ol 1.52.0 → 1.54.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 (2) hide show
  1. package/dist/Map.svelte +12 -9
  2. package/package.json +1 -1
package/dist/Map.svelte CHANGED
@@ -55,7 +55,7 @@
55
55
  import { cssvars } from './cssvars.js';
56
56
  import SsrStyle from './SsrStyle.svelte';
57
57
  import { onMount, type Snippet } from 'svelte';
58
- import { Button } from '@ruckc/truss-ui';
58
+ import { Button, readColorTokens, onThemeChange } from '@ruckc/truss-ui';
59
59
  import 'ol/ol.css';
60
60
  import type OLMap from 'ol/Map.js';
61
61
  import type { Basemap, FitOptions, FitTarget, MapApi, MapFeatureInfo, MapMarker, MapSelection, MapViewChange, MapViewState } from './types.js';
@@ -245,9 +245,15 @@
245
245
  // ---- design tokens → concrete colors for canvas styles
246
246
  let T: Record<string, string> = {};
247
247
  const P: Palettes = { ...DEFAULT_PALETTES };
248
+ // read at the map, so a data-truss-theme / data-theme subtree reaches it; any CSS colour syntax resolves to sRGB for the canvas
249
+ const TOKENS = [
250
+ ...['primary', 'success', 'warning', 'danger', 'outline', 'surface', 'on-surface', 'surface-container-high', 'outline-variant', 'on-primary'].map((n) => `--tr-${n}`),
251
+ ...DEFAULT_PALETTES.sequential.map((_, i) => `--trc-seq-${i + 1}`), ...DEFAULT_PALETTES.diverging.map((_, i) => `--trc-div-${i + 1}`),
252
+ ...DEFAULT_PALETTES.categorical.map((_, i) => `--trc-s${i + 1}`)
253
+ ];
248
254
  const read = () => {
249
- const cs = getComputedStyle(document.documentElement);
250
- const tok = (name: string, fallback: string) => cs.getPropertyValue(name).trim() || fallback;
255
+ const C = readColorTokens(el, TOKENS);
256
+ const tok = (name: string, fallback: string) => C[name] ?? fallback;
251
257
  for (const n of ['primary', 'success', 'warning', 'danger', 'outline', 'surface', 'on-surface', 'surface-container-high', 'outline-variant'])
252
258
  T[n] = tok(`--tr-${n}`, '#888888');
253
259
  T['on-primary'] = tok('--tr-on-primary', '#ffffff');
@@ -651,12 +657,9 @@
651
657
  el.addEventListener('pointerleave', hideTip);
652
658
  map.on('movestart', hideTip);
653
659
 
654
- // ---- follow theme (data-theme toggle, a data-truss-theme theme, or OS preference)
660
+ // ---- follow theme (data-theme or data-truss-theme on the map or any ancestor, or the OS preference)
655
661
  const restyle = () => sync?.style();
656
- const mo = new MutationObserver(restyle);
657
- mo.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme', 'data-truss-theme'] });
658
- const mq = matchMedia('(prefers-color-scheme: dark)');
659
- mq.addEventListener('change', restyle);
662
+ const unwatch = onThemeChange(el, restyle);
660
663
 
661
664
  // the container may not be laid out yet (a pane that is still sizing): fit once it has a size, and keep the map measured
662
665
  let fitPending = fitOnLoad;
@@ -674,7 +677,7 @@
674
677
  onready?.({ map, fit: ctl.fit, setView: ctl.setView, getView: ctl.getView, updateSize: ctl.updateSize });
675
678
 
676
679
  dispose = () => {
677
- mo.disconnect(); mq.removeEventListener('change', restyle); el.removeEventListener('keydown', onkey); ro.disconnect();
680
+ unwatch(); el.removeEventListener('keydown', onkey); ro.disconnect();
678
681
  map.setTarget(undefined);
679
682
  };
680
683
  })().catch((e) => (failed = e instanceof Error ? e.message : String(e)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruckc/truss-ol",
3
- "version": "1.52.0",
3
+ "version": "1.54.0",
4
4
  "description": "OpenLayers map styled with Truss UI",
5
5
  "type": "module",
6
6
  "license": "MIT",