@ruckc/truss-ol 1.48.1 → 1.49.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.
@@ -1,16 +1,30 @@
1
+ <script module lang="ts">
2
+ export type AttributionLabels = {
3
+ /** Accessible name of the attribution box. The attribution texts themselves (provider names such as "OpenStreetMap contributors") come from your layer sources and are not translated here. */
4
+ attribution: string;
5
+ };
6
+ const DEFAULTS: AttributionLabels = { attribution: 'Map attribution' };
7
+ </script>
8
+
1
9
  <script lang="ts">
10
+ import { useLabels } from './labels.js';
2
11
  import type OLMap from 'ol/Map.js';
3
12
  import type { ControlPosition } from './util.js';
4
13
 
5
14
  let {
6
15
  map,
7
- position = 'bottom-right'
16
+ position = 'bottom-right',
17
+ labels
8
18
  }: {
9
19
  /** The OpenLayers map whose visible layers' source attributions are listed (owned by your app). */
10
20
  map?: OLMap | null;
11
21
  position?: ControlPosition;
22
+ /** Replaces the built-in texts (translation). Missing keys keep the defaults. */
23
+ labels?: Partial<AttributionLabels>;
12
24
  } = $props();
13
25
 
26
+ const L = useLabels('Attribution', DEFAULTS, () => labels);
27
+
14
28
  let items = $state<string[]>([]);
15
29
 
16
30
  $effect(() => {
@@ -35,7 +49,7 @@
35
49
 
36
50
  {#if items.length}
37
51
  <!-- Attribution strings come from your layer sources and may contain links, exactly as in OpenLayers' own control -->
38
- <div class="at" data-pos={position} aria-label="Map attribution">
52
+ <div class="at" data-pos={position} aria-label={L.attribution}>
39
53
  {#each items as s (s)}<span>{@html s}</span>{/each}
40
54
  </div>
41
55
  {/if}
@@ -1,9 +1,15 @@
1
+ export type AttributionLabels = {
2
+ /** Accessible name of the attribution box. The attribution texts themselves (provider names such as "OpenStreetMap contributors") come from your layer sources and are not translated here. */
3
+ attribution: string;
4
+ };
1
5
  import type OLMap from 'ol/Map.js';
2
6
  import type { ControlPosition } from './util.js';
3
7
  type $$ComponentProps = {
4
8
  /** The OpenLayers map whose visible layers' source attributions are listed (owned by your app). */
5
9
  map?: OLMap | null;
6
10
  position?: ControlPosition;
11
+ /** Replaces the built-in texts (translation). Missing keys keep the defaults. */
12
+ labels?: Partial<AttributionLabels>;
7
13
  };
8
14
  declare const Attribution: import("svelte").Component<$$ComponentProps, {}, "">;
9
15
  type Attribution = ReturnType<typeof Attribution>;
@@ -1,4 +1,21 @@
1
+ <script module lang="ts">
2
+ export type CompassLabels = {
3
+ /** Accessible name of the compass button: the bearing in whole degrees, and what a press does. */
4
+ compass: (bearing: number) => string;
5
+ /** Tooltip of the compass button. */
6
+ resetToNorth: string;
7
+ /** Accessible name and tooltip of the heading-up toggle. */
8
+ followHeading: string;
9
+ };
10
+ const DEFAULTS: CompassLabels = {
11
+ compass: (bearing) => `Compass: bearing ${bearing} degrees. Reset to north`,
12
+ resetToNorth: 'Reset to north',
13
+ followHeading: 'Follow device heading'
14
+ };
15
+ </script>
16
+
1
17
  <script lang="ts">
18
+ import { useLabels } from './labels.js';
2
19
  import { cssvars } from './cssvars.js';
3
20
  import type OLMap from 'ol/Map.js';
4
21
  import { watchView, type ControlPosition, type HeadingStatus } from './util.js';
@@ -9,7 +26,8 @@
9
26
  headingControl = false,
10
27
  duration = 250,
11
28
  position = 'top-right',
12
- onstatus
29
+ onstatus,
30
+ labels
13
31
  }: {
14
32
  /** The OpenLayers map this control drives (owned by your app). */
15
33
  map?: OLMap | null;
@@ -24,8 +42,12 @@
24
42
  duration?: number;
25
43
  position?: ControlPosition;
26
44
  onstatus?: (status: HeadingStatus) => void;
45
+ /** Replaces the built-in texts (translation). Missing keys keep the defaults. */
46
+ labels?: Partial<CompassLabels>;
27
47
  } = $props();
28
48
 
49
+ const L = useLabels('Compass', DEFAULTS, () => labels);
50
+
29
51
  let rotation = $state(0);
30
52
  let status = $state<HeadingStatus>('off');
31
53
  const bearing = $derived((((Math.round((-rotation * 180) / Math.PI) % 360) + 360) % 360));
@@ -81,7 +103,7 @@
81
103
  </script>
82
104
 
83
105
  <div class="cp" data-pos={position} data-heading={status} data-bearing={bearing}>
84
- <button type="button" class="b" aria-label={`Compass: bearing ${bearing} degrees. Reset to north`} title="Reset to north" disabled={!map} onclick={reset}>
106
+ <button type="button" class="b" aria-label={L.compass(bearing)} title={L.resetToNorth} disabled={!map} onclick={reset}>
85
107
  <svg viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" {@attach cssvars(() => ({ 'transform': `rotate(${rotation}rad)` }))}>
86
108
  <polygon points="12,2 16,12 8,12" fill="var(--tr-danger)" />
87
109
  <polygon points="12,22 16,12 8,12" fill="var(--tr-on-surface-variant)" />
@@ -89,7 +111,7 @@
89
111
  </svg>
90
112
  </button>
91
113
  {#if headingControl}
92
- <button type="button" class="b sm" aria-label="Follow device heading" aria-pressed={headingUp} title="Follow device heading" disabled={!map} onclick={() => (headingUp = !headingUp)}>
114
+ <button type="button" class="b sm" aria-label={L.followHeading} aria-pressed={headingUp} title={L.followHeading} disabled={!map} onclick={() => (headingUp = !headingUp)}>
93
115
  <svg viewBox="0 0 24 24" width="16" height="16" aria-hidden="true"><path d="M12 3 19 20 12 16 5 20Z" fill="currentColor" /></svg>
94
116
  </button>
95
117
  {/if}
@@ -1,3 +1,11 @@
1
+ export type CompassLabels = {
2
+ /** Accessible name of the compass button: the bearing in whole degrees, and what a press does. */
3
+ compass: (bearing: number) => string;
4
+ /** Tooltip of the compass button. */
5
+ resetToNorth: string;
6
+ /** Accessible name and tooltip of the heading-up toggle. */
7
+ followHeading: string;
8
+ };
1
9
  import type OLMap from 'ol/Map.js';
2
10
  import { type ControlPosition, type HeadingStatus } from './util.js';
3
11
  type $$ComponentProps = {
@@ -14,6 +22,8 @@ type $$ComponentProps = {
14
22
  duration?: number;
15
23
  position?: ControlPosition;
16
24
  onstatus?: (status: HeadingStatus) => void;
25
+ /** Replaces the built-in texts (translation). Missing keys keep the defaults. */
26
+ labels?: Partial<CompassLabels>;
17
27
  };
18
28
  declare const Compass: import("svelte").Component<$$ComponentProps, {}, "headingUp">;
19
29
  type Compass = ReturnType<typeof Compass>;
package/dist/Map.svelte CHANGED
@@ -1,4 +1,57 @@
1
+ <script module lang="ts">
2
+ export type MapLabels = {
3
+ /** Accessible name of the map (keyboard hint included). */
4
+ map: string;
5
+ /** Accessible name of the zoom and fit toolbar. */
6
+ controls: string;
7
+ /** Accessible name of the zoom-in button. */
8
+ zoomIn: string;
9
+ /** Accessible name of the zoom-out button. */
10
+ zoomOut: string;
11
+ /** Accessible name of the fit button. */
12
+ fitToData: string;
13
+ /** Accessible name of the popup's close button. */
14
+ close: string;
15
+ /** Title and accessible name of a marker's popup when the marker has no `label`. */
16
+ location: string;
17
+ /** Accessible name of the legend. */
18
+ legend: string;
19
+ /** Title of the heatmap legend when `heatmap.title` and `heatmap.weightBy` are not set. */
20
+ density: string;
21
+ /** A popup heading for a feature with no name, title, label or id. */
22
+ feature: string;
23
+ /** The cluster legend's title when clusters are sized or coloured by their point count. */
24
+ count: string;
25
+ /** Low end of the heatmap legend. */
26
+ low: string;
27
+ /** High end of the heatmap legend. */
28
+ high: string;
29
+ /** Accessible name of a continuous colour bar in the legend: its title and the two ends. */
30
+ legendRange: (title: string, from: string, to: string) => string;
31
+ /** Shown when the map could not be created; `reason` is the error message. */
32
+ loadFailed: (reason: string) => string;
33
+ };
34
+ const DEFAULTS: MapLabels = {
35
+ map: 'Map. Arrow keys pan, plus and minus zoom.',
36
+ controls: 'Map controls',
37
+ zoomIn: 'Zoom in',
38
+ zoomOut: 'Zoom out',
39
+ fitToData: 'Fit to data',
40
+ close: 'Close',
41
+ location: 'Location',
42
+ legend: 'Legend',
43
+ density: 'Density',
44
+ feature: 'Feature',
45
+ count: 'Count',
46
+ low: 'Low',
47
+ high: 'High',
48
+ legendRange: (title, from, to) => `${title}: ${from} to ${to}`,
49
+ loadFailed: (reason) => `Map failed to load: ${reason}`
50
+ };
51
+ </script>
52
+
1
53
  <script lang="ts">
54
+ import { useLabels } from './labels.js';
2
55
  import { cssvars } from './cssvars.js';
3
56
  import SsrStyle from './SsrStyle.svelte';
4
57
  import { onMount, type Snippet } from 'svelte';
@@ -44,7 +97,8 @@
44
97
  toolbar,
45
98
  onselect,
46
99
  onviewchange,
47
- onready
100
+ onready,
101
+ labels
48
102
  }: {
49
103
  /** [lon, lat] */
50
104
  center?: [number, number];
@@ -135,8 +189,12 @@
135
189
  onviewchange?: (v: MapViewChange) => void;
136
190
  /** Called once the map exists, with the imperative API (`map`, `fit`, `setView`, `getView`, `updateSize`). */
137
191
  onready?: (api: MapApi) => void;
192
+ /** Replaces the built-in texts (translation). Missing keys keep the defaults. */
193
+ labels?: Partial<MapLabels>;
138
194
  } = $props();
139
195
 
196
+ const L = useLabels('Map', DEFAULTS, () => labels);
197
+
140
198
  let el: HTMLDivElement;
141
199
  let popupEl: HTMLDivElement;
142
200
  let ready = $state(false);
@@ -216,7 +274,7 @@
216
274
  let colValues: Record<string, Float64Array> = {};
217
275
  const heatLegend = () => {
218
276
  const g = heatGradient().slice(1);
219
- return { by: heatmap?.weightBy ?? 'Density', title: heatmap?.title ?? heatmap?.weightBy ?? 'Density', scale: 'sequential' as const, labels: ['Low', 'High'] as [string, string], gradient: cssGradient(g) };
277
+ return { by: heatmap?.weightBy ?? L.density, title: heatmap?.title ?? heatmap?.weightBy ?? L.density, scale: 'sequential' as const, labels: [L.low, L.high] as [string, string], gradient: cssGradient(g) };
220
278
  };
221
279
  const recompile = () => {
222
280
  compiled = compileStyle(style, [...geoSrc.getFeatures().map((f: any) => f.getProperties()), ...store.props], P);
@@ -645,21 +703,21 @@
645
703
  <SsrStyle {uid} rules={{ '': `height:${typeof height === 'number' ? `${height}px` : height}` }} />
646
704
  <div class="trm" data-sv={uid} {@attach cssvars(() => ({ 'height': typeof height === 'number' ? `${height}px` : height }))}>
647
705
  <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
648
- <div class="map" bind:this={el} tabindex="0" role="application" aria-label="Map. Arrow keys pan, plus and minus zoom."></div>
706
+ <div class="map" bind:this={el} tabindex="0" role="application" aria-label={L.map}></div>
649
707
 
650
708
  <div class="popup" bind:this={popupEl} hidden={!sel && !fsel}>
651
709
  {#if sel}
652
- <div class="card" role="dialog" aria-label={sel.label ?? 'Location'}>
653
- <button type="button" class="x" aria-label="Close" onclick={() => { selected = undefined; onselect?.(null); }}>×</button>
710
+ <div class="card" role="dialog" aria-label={sel.label ?? L.location}>
711
+ <button type="button" class="x" aria-label={L.close} onclick={() => { selected = undefined; onselect?.(null); }}>×</button>
654
712
  {#if popup}{@render popup(sel)}{:else}
655
- <div class="t">{sel.label ?? 'Location'}</div>
713
+ <div class="t">{sel.label ?? L.location}</div>
656
714
  {#if sel.description}<div class="d">{sel.description}</div>{/if}
657
715
  <div class="c">{sel.lat.toFixed(4)}, {sel.lon.toFixed(4)}</div>
658
716
  {/if}
659
717
  </div>
660
718
  {:else if fsel}
661
719
  <div class="card" role="dialog" aria-label={featureTitle(fsel.properties)}>
662
- <button type="button" class="x" aria-label="Close" onclick={() => { selected = undefined; onselect?.(null); }}>×</button>
720
+ <button type="button" class="x" aria-label={L.close} onclick={() => { selected = undefined; onselect?.(null); }}>×</button>
663
721
  {#if featurePopup}{@render featurePopup(fsel)}{:else}
664
722
  <div class="t">{featureTitle(fsel.properties)}</div>
665
723
  <dl class="kv">
@@ -674,14 +732,14 @@
674
732
  </div>
675
733
  <div class="sr" aria-live="polite">{announce}</div>
676
734
 
677
- <div class="controls" role="toolbar" aria-label="Map controls">
678
- <Button variant="minimal" intent="neutral" size="sm" icon="plus" aria-label="Zoom in" onclick={() => ctl?.zoomBy(1)} />
679
- <Button variant="minimal" intent="neutral" size="sm" icon="minus" aria-label="Zoom out" onclick={() => ctl?.zoomBy(-1)} />
680
- <Button variant="minimal" intent="neutral" size="sm" icon="expand" aria-label="Fit to data" onclick={() => ctl?.fit()} />
735
+ <div class="controls" role="toolbar" aria-label={L.controls}>
736
+ <Button variant="minimal" intent="neutral" size="sm" icon="plus" aria-label={L.zoomIn} onclick={() => ctl?.zoomBy(1)} />
737
+ <Button variant="minimal" intent="neutral" size="sm" icon="minus" aria-label={L.zoomOut} onclick={() => ctl?.zoomBy(-1)} />
738
+ <Button variant="minimal" intent="neutral" size="sm" icon="expand" aria-label={L.fitToData} onclick={() => ctl?.fit()} />
681
739
  {#if toolbar}{@render toolbar()}{/if}
682
740
  </div>
683
741
  {#if legend && (legendInfo.size || legendInfo.color || legendInfo.clusterSize || legendInfo.clusterColor || legendInfo.heatmap)}
684
- <div class="legend" role="group" aria-label="Legend">
742
+ <div class="legend" role="group" aria-label={L.legend}>
685
743
  {#each [legendInfo.size, legendInfo.clusterSize] as lg, i (i)}
686
744
  {#if lg}
687
745
  <div class="lt">{lg.title}</div>
@@ -696,7 +754,7 @@
696
754
  {#if lg}
697
755
  <div class="lt">{lg.title}</div>
698
756
  {#if lg.gradient}
699
- <div class="lbar" {@attach cssvars(() => ({ 'background': lg.gradient! }))} role="img" aria-label="{lg.title}: {lg.labels![0]} to {lg.labels![1]}"></div>
757
+ <div class="lbar" {@attach cssvars(() => ({ 'background': lg.gradient! }))} role="img" aria-label={L.legendRange(lg.title, lg.labels![0], lg.labels![1])}></div>
700
758
  <div class="lends"><span>{lg.labels![0]}</span><span>{lg.labels![1]}</span></div>
701
759
  {:else}
702
760
  <ul class="lcat">{#each lg.categories! as c (c.label)}<li><i {@attach cssvars(() => ({ 'background': c.color }))}></i>{c.label}</li>{/each}</ul>
@@ -705,7 +763,7 @@
705
763
  {/each}
706
764
  </div>
707
765
  {/if}
708
- {#if failed}<div class="err" role="alert">Map failed to load: {failed}</div>{/if}
766
+ {#if failed}<div class="err" role="alert">{L.loadFailed(failed)}</div>{/if}
709
767
  </div>
710
768
 
711
769
  <style>
@@ -1,3 +1,35 @@
1
+ export type MapLabels = {
2
+ /** Accessible name of the map (keyboard hint included). */
3
+ map: string;
4
+ /** Accessible name of the zoom and fit toolbar. */
5
+ controls: string;
6
+ /** Accessible name of the zoom-in button. */
7
+ zoomIn: string;
8
+ /** Accessible name of the zoom-out button. */
9
+ zoomOut: string;
10
+ /** Accessible name of the fit button. */
11
+ fitToData: string;
12
+ /** Accessible name of the popup's close button. */
13
+ close: string;
14
+ /** Title and accessible name of a marker's popup when the marker has no `label`. */
15
+ location: string;
16
+ /** Accessible name of the legend. */
17
+ legend: string;
18
+ /** Title of the heatmap legend when `heatmap.title` and `heatmap.weightBy` are not set. */
19
+ density: string;
20
+ /** A popup heading for a feature with no name, title, label or id. */
21
+ feature: string;
22
+ /** The cluster legend's title when clusters are sized or coloured by their point count. */
23
+ count: string;
24
+ /** Low end of the heatmap legend. */
25
+ low: string;
26
+ /** High end of the heatmap legend. */
27
+ high: string;
28
+ /** Accessible name of a continuous colour bar in the legend: its title and the two ends. */
29
+ legendRange: (title: string, from: string, to: string) => string;
30
+ /** Shown when the map could not be created; `reason` is the error message. */
31
+ loadFailed: (reason: string) => string;
32
+ };
1
33
  import { type Snippet } from 'svelte';
2
34
  import 'ol/ol.css';
3
35
  import type { Basemap, FitOptions, FitTarget, MapApi, MapFeatureInfo, MapMarker, MapSelection, MapViewChange, MapViewState } from './types.js';
@@ -95,6 +127,8 @@ type $$ComponentProps = {
95
127
  onviewchange?: (v: MapViewChange) => void;
96
128
  /** Called once the map exists, with the imperative API (`map`, `fit`, `setView`, `getView`, `updateSize`). */
97
129
  onready?: (api: MapApi) => void;
130
+ /** Replaces the built-in texts (translation). Missing keys keep the defaults. */
131
+ labels?: Partial<MapLabels>;
98
132
  };
99
133
  declare const Map: import("svelte").Component<$$ComponentProps, {
100
134
  fit: (target?: FitTarget, options?: FitOptions) => void;
@@ -1,4 +1,25 @@
1
+ <script module lang="ts">
2
+ import { SCALE_DEFAULTS } from './util.js';
3
+
4
+ export type ScaleBarLabels = {
5
+ /** Accessible name of the scale: the description of its bars (see `description`). */
6
+ scale: (description: string) => string;
7
+ /** A bar's length in words, e.g. "1 mile", "2 kilometres". `unit` is the symbol (km, m, cm, mi, ft, in): the visible bars keep the symbols, only the spoken words are translated. */
8
+ unit: (unit: string, value: number) => string;
9
+ /** The representative fraction in words, e.g. "1 to 24,000"; `denominator` is already formatted. */
10
+ ratio: (denominator: string) => string;
11
+ /** The bars (each described by `unit`) and the ratio (described by `ratio`, when shown) as one sentence. */
12
+ description: (bars: string[], ratio: string | undefined) => string;
13
+ };
14
+ const DEFAULTS: ScaleBarLabels = {
15
+ scale: (description) => `Scale: ${description}`,
16
+ ...SCALE_DEFAULTS,
17
+ description: (bars, ratio) => bars.join(', ') + (ratio ? `; ${ratio}` : '')
18
+ };
19
+ </script>
20
+
1
21
  <script lang="ts">
22
+ import { useLabels } from './labels.js';
2
23
  import { cssvars } from './cssvars.js';
3
24
  import type OLMap from 'ol/Map.js';
4
25
  import type { getPointResolution } from 'ol/proj.js';
@@ -10,7 +31,8 @@
10
31
  maxWidth = 120,
11
32
  position = 'bottom-left',
12
33
  variant = 'bar',
13
- showRatio = false
34
+ showRatio = false,
35
+ labels
14
36
  }: {
15
37
  /** The OpenLayers map this control reads (owned by your app). */
16
38
  map?: OLMap | null;
@@ -23,11 +45,15 @@
23
45
  variant?: 'bar' | 'segmented';
24
46
  /** Add a representative fraction line (`1 : 24,000`) above the bars. Computed from the view resolution at the map centre, assuming the OGC standard 0.28 mm CSS pixel, to 2 significant figures. */
25
47
  showRatio?: boolean;
48
+ /** Replaces the built-in texts (translation). Missing keys keep the defaults. */
49
+ labels?: Partial<ScaleBarLabels>;
26
50
  } = $props();
27
51
 
52
+ const L = useLabels('ScaleBar', DEFAULTS, () => labels);
53
+
28
54
  let segments = $state<ScaleSegment[]>([]);
29
55
  let ratio = $state<number>();
30
- const text = $derived(segments.map(describeSegment).join(', ') + (showRatio && ratio ? `; ${describeRatio(ratio)}` : ''));
56
+ const text = $derived(L.description(segments.map((s) => describeSegment(s, L.unit)), showRatio && ratio ? describeRatio(ratio, L.ratio) : undefined));
31
57
 
32
58
  $effect(() => {
33
59
  if (!map) { segments = []; return; }
@@ -50,7 +76,7 @@
50
76
  </script>
51
77
 
52
78
  {#if segments.length}
53
- <div class="sb" class:segmented={variant === 'segmented'} data-pos={position} role="img" aria-label={`Scale: ${text}`}>
79
+ <div class="sb" class:segmented={variant === 'segmented'} data-pos={position} role="img" aria-label={L.scale(text)}>
54
80
  {#if showRatio && ratio}<div class="ratio">{formatRatio(ratio)}</div>{/if}
55
81
  {#each segments as s (s.unit)}
56
82
  {#if variant === 'segmented'}
@@ -1,3 +1,13 @@
1
+ export type ScaleBarLabels = {
2
+ /** Accessible name of the scale: the description of its bars (see `description`). */
3
+ scale: (description: string) => string;
4
+ /** A bar's length in words, e.g. "1 mile", "2 kilometres". `unit` is the symbol (km, m, cm, mi, ft, in): the visible bars keep the symbols, only the spoken words are translated. */
5
+ unit: (unit: string, value: number) => string;
6
+ /** The representative fraction in words, e.g. "1 to 24,000"; `denominator` is already formatted. */
7
+ ratio: (denominator: string) => string;
8
+ /** The bars (each described by `unit`) and the ratio (described by `ratio`, when shown) as one sentence. */
9
+ description: (bars: string[], ratio: string | undefined) => string;
10
+ };
1
11
  import type OLMap from 'ol/Map.js';
2
12
  import { type ControlPosition, type ScaleUnit } from './util.js';
3
13
  type $$ComponentProps = {
@@ -12,6 +22,8 @@ type $$ComponentProps = {
12
22
  variant?: 'bar' | 'segmented';
13
23
  /** Add a representative fraction line (`1 : 24,000`) above the bars. Computed from the view resolution at the map centre, assuming the OGC standard 0.28 mm CSS pixel, to 2 significant figures. */
14
24
  showRatio?: boolean;
25
+ /** Replaces the built-in texts (translation). Missing keys keep the defaults. */
26
+ labels?: Partial<ScaleBarLabels>;
15
27
  };
16
28
  declare const ScaleBar: import("svelte").Component<$$ComponentProps, {}, "">;
17
29
  type ScaleBar = ReturnType<typeof ScaleBar>;
@@ -1,4 +1,19 @@
1
+ <script module lang="ts">
2
+ export type ZoomControlLabels = {
3
+ /** Accessible name of the control (the `label` prop replaces it). */
4
+ mapZoom: string;
5
+ /** Accessible name of the zoom-in button. */
6
+ zoomIn: string;
7
+ /** Accessible name of the zoom-out button. */
8
+ zoomOut: string;
9
+ /** Accessible name of the fit button (`showFit`). */
10
+ fitToExtent: string;
11
+ };
12
+ const DEFAULTS: ZoomControlLabels = { mapZoom: 'Map zoom', zoomIn: 'Zoom in', zoomOut: 'Zoom out', fitToExtent: 'Fit to extent' };
13
+ </script>
14
+
1
15
  <script lang="ts">
16
+ import { useLabels } from './labels.js';
2
17
  import { Button } from '@ruckc/truss-ui';
3
18
  import type OLMap from 'ol/Map.js';
4
19
  import { watchView, watchCoarse, cornerZone, rectDistance, type ControlPosition } from './util.js';
@@ -12,7 +27,8 @@
12
27
  delta = 1,
13
28
  duration = 200,
14
29
  position = 'top-left',
15
- label = 'Map zoom'
30
+ label,
31
+ labels
16
32
  }: {
17
33
  /** The OpenLayers map this control drives (owned by your app). */
18
34
  map?: OLMap | null;
@@ -27,9 +43,14 @@
27
43
  delta?: number;
28
44
  duration?: number;
29
45
  position?: ControlPosition;
46
+ /** Accessible name of the control (default: "Map zoom"). */
30
47
  label?: string;
48
+ /** Replaces the built-in texts (translation). Missing keys keep the defaults. */
49
+ labels?: Partial<ZoomControlLabels>;
31
50
  } = $props();
32
51
 
52
+ const L = useLabels('ZoomControl', DEFAULTS, () => labels);
53
+
33
54
  let root = $state<HTMLElement>();
34
55
  let zoom = $state(0);
35
56
  let canIn = $state(false);
@@ -87,14 +108,14 @@
87
108
  bind:this={root}
88
109
  hidden={proximity && coarse}
89
110
  role="toolbar"
90
- aria-label={label}
111
+ aria-label={label ?? L.mapZoom}
91
112
  tabindex="-1"
92
113
  onfocusin={() => (focused = true)}
93
114
  onfocusout={() => (focused = false)}
94
115
  >
95
- <Button variant="minimal" intent="neutral" size="sm" icon="plus" aria-label="Zoom in" disabled={!map || !canIn} onclick={() => zoomBy(delta)} />
96
- <Button variant="minimal" intent="neutral" size="sm" icon="minus" aria-label="Zoom out" disabled={!map || !canOut} onclick={() => zoomBy(-delta)} />
97
- {#if showFit}<Button variant="minimal" intent="neutral" size="sm" icon="expand" aria-label="Fit to extent" disabled={!map} onclick={fit} />{/if}
116
+ <Button variant="minimal" intent="neutral" size="sm" icon="plus" aria-label={L.zoomIn} disabled={!map || !canIn} onclick={() => zoomBy(delta)} />
117
+ <Button variant="minimal" intent="neutral" size="sm" icon="minus" aria-label={L.zoomOut} disabled={!map || !canOut} onclick={() => zoomBy(-delta)} />
118
+ {#if showFit}<Button variant="minimal" intent="neutral" size="sm" icon="expand" aria-label={L.fitToExtent} disabled={!map} onclick={fit} />{/if}
98
119
  </div>
99
120
 
100
121
  <style>
@@ -1,3 +1,13 @@
1
+ export type ZoomControlLabels = {
2
+ /** Accessible name of the control (the `label` prop replaces it). */
3
+ mapZoom: string;
4
+ /** Accessible name of the zoom-in button. */
5
+ zoomIn: string;
6
+ /** Accessible name of the zoom-out button. */
7
+ zoomOut: string;
8
+ /** Accessible name of the fit button (`showFit`). */
9
+ fitToExtent: string;
10
+ };
1
11
  import type OLMap from 'ol/Map.js';
2
12
  import { type ControlPosition } from './util.js';
3
13
  type $$ComponentProps = {
@@ -14,7 +24,10 @@ type $$ComponentProps = {
14
24
  delta?: number;
15
25
  duration?: number;
16
26
  position?: ControlPosition;
27
+ /** Accessible name of the control (default: "Map zoom"). */
17
28
  label?: string;
29
+ /** Replaces the built-in texts (translation). Missing keys keep the defaults. */
30
+ labels?: Partial<ZoomControlLabels>;
18
31
  };
19
32
  declare const ZoomControl: import("svelte").Component<$$ComponentProps, {}, "">;
20
33
  type ZoomControl = ReturnType<typeof ZoomControl>;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,13 @@
1
1
  export { default as Map } from './Map.svelte';
2
+ export type { MapLabels } from './Map.svelte';
2
3
  export { default as ZoomControl } from './ZoomControl.svelte';
4
+ export type { ZoomControlLabels } from './ZoomControl.svelte';
3
5
  export { default as Compass } from './Compass.svelte';
6
+ export type { CompassLabels } from './Compass.svelte';
4
7
  export { default as ScaleBar } from './ScaleBar.svelte';
8
+ export type { ScaleBarLabels } from './ScaleBar.svelte';
5
9
  export { default as Attribution } from './Attribution.svelte';
10
+ export type { AttributionLabels } from './Attribution.svelte';
6
11
  export type { MapMarker, MarkerKind, Basemap, MapSelection, MapFeatureInfo, MapViewState, MapViewChange, FitOptions, FitTarget, MapApi } from './types.js';
7
12
  export type { MapStyle, SizeSpec, ColorSpec, FeatureStyle, PieStroke, LegendInfo, ClusterStyle, ClusterSizeSpec, ClusterColorSpec, ClusterBy, ClusterAgg, ClusterInfo } from './style.js';
8
13
  export type { PointsInput, PointInput, PointsMode, HeatmapOptions } from './points.js';
@@ -0,0 +1,6 @@
1
+ /** One label: a string, or a function for a string with values (`(n: number) => \`${n} selected\``). That covers plurals and word order without an ICU dependency. */
2
+ export type LabelValue = string | ((...args: never[]) => string);
3
+ /** @internal The labels of a component: `prop` over the context over `configureLabels` over `defaults`, read at the moment a key is used. Call during component initialisation (it reads context). */
4
+ export declare function useLabels<T extends object>(component: string, defaults: T, prop: () => Partial<T> | undefined): T;
5
+ /** @internal One app-wide label for code outside a component (no context there): `configureLabels` over `fallback`. */
6
+ export declare function labelFor<T extends LabelValue>(component: string, key: string, fallback: T): T;
package/dist/labels.js ADDED
@@ -0,0 +1,23 @@
1
+ import { getContext } from 'svelte';
2
+ const KEY = Symbol.for('@ruckc/truss-ui:labels');
3
+ const STATE = Symbol.for('@ruckc/truss-ui:labels-config');
4
+ // What `configureLabels` set for a component. Read-only here (no copy of this file has to create the state), and `Object(undefined)` is `{}`.
5
+ const config = (component) => Object(Object(globalThis[STATE])[component]);
6
+ // The strongest defined value wins (layers run from the weakest to the strongest). This reader is written without branches on purpose
7
+ // (`filter`, `Object(x)`, no `?.` / `??` / `if`): it is copied into every package, and V8 coverage counts each short-circuit as a branch,
8
+ // so a copy would need a test under every combination of context and config to reach the per-file coverage floor.
9
+ const none = () => undefined;
10
+ const pick = (...layers) => layers.filter((v) => v !== undefined).at(-1);
11
+ /** @internal The labels of a component: `prop` over the context over `configureLabels` over `defaults`, read at the moment a key is used. Call during component initialisation (it reads context). */
12
+ export function useLabels(component, defaults, prop) {
13
+ const lookup = [getContext(KEY), none].filter(Boolean)[0];
14
+ const out = {};
15
+ for (const k of Object.keys(defaults))
16
+ Object.defineProperty(out, k, { enumerable: true, get: () => pick(labelFor(component, k, defaults[k]), Object(lookup(component))[k], Object(prop())[k]) });
17
+ return out;
18
+ }
19
+ /** @internal One app-wide label for code outside a component (no context there): `configureLabels` over `fallback`. */
20
+ export function labelFor(component, key, fallback) {
21
+ return pick(fallback, config(component)[key]);
22
+ }
23
+ // </reader>
package/dist/style.js CHANGED
@@ -1,4 +1,7 @@
1
1
  /** Pure helpers for data-driven map styling: colour maths, scales, domains and the compiled style a layer calls per feature. */
2
+ import { labelFor } from './labels.js';
3
+ /** English defaults for the texts this module builds; `configureLabels({ Map: { feature, count } })` translates them. */
4
+ const STYLE_DEFAULTS = { feature: 'Feature', count: 'Count' };
2
5
  /** The ramps used when the chart tokens are not defined; they match `charts.css` in light mode. */
3
6
  export const DEFAULT_PALETTES = {
4
7
  sequential: ['#eaf3fe', '#c5ddfc', '#97c1f7', '#64a1ee', '#3a81d7', '#1d60ad', '#10427b'],
@@ -198,7 +201,7 @@ export function featureTitle(p) {
198
201
  for (const k of ['name', 'title', 'label', 'id'])
199
202
  if (p[k] !== undefined && p[k] !== null && p[k] !== '')
200
203
  return String(p[k]);
201
- return 'Feature';
204
+ return labelFor('Map', 'feature', STYLE_DEFAULTS.feature);
202
205
  }
203
206
  /** The properties a default popup lists: at most `max` entries, without styling keys, empty values and internals; objects as JSON. */
204
207
  export function popupEntries(p, max = 8) {
@@ -224,7 +227,7 @@ export function clusterValue(by, c) {
224
227
  return agg === 'sum' ? st.sum : agg === 'mean' ? st.sum / st.n : agg === 'min' ? st.min : st.max;
225
228
  }
226
229
  const byProp = (by) => (by === 'count' ? undefined : by.agg === 'count' ? undefined : by.prop);
227
- const byLabel = (by) => (by === 'count' || by.agg === 'count' ? 'Count' : `${by.agg[0].toUpperCase()}${by.agg.slice(1)} ${by.prop}`);
230
+ const byLabel = (by) => (by === 'count' || by.agg === 'count' ? labelFor('Map', 'count', STYLE_DEFAULTS.count) : `${by.agg[0].toUpperCase()}${by.agg.slice(1)} ${by.prop}`);
228
231
  /** Properties whose stats a cluster style needs (so clusters collect only those). */
229
232
  export function clusterProps(cs) {
230
233
  const out = new Set();
package/dist/util.d.ts CHANGED
@@ -18,8 +18,15 @@ export declare function niceLength(max: number): number;
18
18
  export declare function formatNice(n: number): string;
19
19
  /** One scale bar for a unit system: picks the unit (km/m/cm or mi/ft/in) and a nice length that fits `maxPx`. */
20
20
  export declare function scaleSegment(metersPerPx: number, maxPx: number, system: ScaleUnit): ScaleSegment;
21
- /** A scale bar's length in words for assistive technology, e.g. `1 mile`, `2 kilometres`. */
22
- export declare function describeSegment(s: ScaleSegment): string;
21
+ /** The scale's spoken texts, in English: `ScaleBar` carries them as keys of its own labels (the component name is `ScaleBar`). */
22
+ export declare const SCALE_DEFAULTS: {
23
+ /** A length with its unit's name (`unit` is the symbol: km, m, cm, mi, ft, in), singular for 1. */
24
+ unit: (unit: string, value: number) => string;
25
+ /** The representative fraction (`denominator` formatted): `1 to 24,000`. */
26
+ ratio: (denominator: string) => string;
27
+ };
28
+ /** A scale bar's length in words for assistive technology, e.g. `1 mile`, `2 kilometres`. `unit` is the component's resolved text; without it the app-wide one (`configureLabels`) or the English one applies. */
29
+ export declare function describeSegment(s: ScaleSegment, unit?: (unit: string, value: number) => string): string;
23
30
  /** OGC standard rendering pixel: 0.28 mm. OpenLayers resolutions are per CSS pixel, so devicePixelRatio does not change the ratio. */
24
31
  export declare const PIXEL_MM = 0.28;
25
32
  /** `n` rounded to `sig` significant figures. */
@@ -27,7 +34,8 @@ export declare function roundSig(n: number, sig: number): number;
27
34
  /** The representative fraction's denominator (`24000` for 1 : 24,000) for a view resolution in metres per CSS pixel, to 2 significant figures. */
28
35
  export declare function scaleRatio(metersPerPx: number): number;
29
36
  export declare function formatRatio(denominator: number): string;
30
- export declare function describeRatio(denominator: number): string;
37
+ /** The representative fraction in words, e.g. `1 to 24,000`; `ratio` is the component's resolved text (see `describeSegment`). */
38
+ export declare function describeRatio(denominator: number, ratio?: (denominator: string) => string): string;
31
39
  export type ScaleTick = {
32
40
  label: string;
33
41
  pos: number;
package/dist/util.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { labelFor } from './labels.js';
1
2
  export * from './style.js';
2
3
  export * from './points.js';
3
4
  const LADDER = {
@@ -28,9 +29,16 @@ const UNIT_NAMES = {
28
29
  km: ['kilometre', 'kilometres'], m: ['metre', 'metres'], cm: ['centimetre', 'centimetres'],
29
30
  mi: ['mile', 'miles'], ft: ['foot', 'feet'], in: ['inch', 'inches']
30
31
  };
31
- /** A scale bar's length in words for assistive technology, e.g. `1 mile`, `2 kilometres`. */
32
- export function describeSegment(s) {
33
- return `${s.value} ${UNIT_NAMES[s.unit][s.value === 1 ? 0 : 1]}`;
32
+ /** The scale's spoken texts, in English: `ScaleBar` carries them as keys of its own labels (the component name is `ScaleBar`). */
33
+ export const SCALE_DEFAULTS = {
34
+ /** A length with its unit's name (`unit` is the symbol: km, m, cm, mi, ft, in), singular for 1. */
35
+ unit: (unit, value) => `${value} ${UNIT_NAMES[unit][value === 1 ? 0 : 1]}`,
36
+ /** The representative fraction (`denominator` formatted): `1 to 24,000`. */
37
+ ratio: (denominator) => `1 to ${denominator}`
38
+ };
39
+ /** A scale bar's length in words for assistive technology, e.g. `1 mile`, `2 kilometres`. `unit` is the component's resolved text; without it the app-wide one (`configureLabels`) or the English one applies. */
40
+ export function describeSegment(s, unit = labelFor('ScaleBar', 'unit', SCALE_DEFAULTS.unit)) {
41
+ return unit(s.unit, s.value);
34
42
  }
35
43
  /** OGC standard rendering pixel: 0.28 mm. OpenLayers resolutions are per CSS pixel, so devicePixelRatio does not change the ratio. */
36
44
  export const PIXEL_MM = 0.28;
@@ -46,8 +54,9 @@ export function scaleRatio(metersPerPx) {
46
54
  export function formatRatio(denominator) {
47
55
  return `1 : ${denominator.toLocaleString('en-US')}`;
48
56
  }
49
- export function describeRatio(denominator) {
50
- return `1 to ${denominator.toLocaleString('en-US')}`;
57
+ /** The representative fraction in words, e.g. `1 to 24,000`; `ratio` is the component's resolved text (see `describeSegment`). */
58
+ export function describeRatio(denominator, ratio = labelFor('ScaleBar', 'ratio', SCALE_DEFAULTS.ratio)) {
59
+ return ratio(denominator.toLocaleString('en-US'));
51
60
  }
52
61
  /** A tick value as text: quarters and halves as fractions, otherwise a plain number. */
53
62
  export function tickLabel(v) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruckc/truss-ol",
3
- "version": "1.48.1",
3
+ "version": "1.49.0",
4
4
  "description": "OpenLayers map styled with Truss UI",
5
5
  "type": "module",
6
6
  "license": "MIT",