@aiaiai-pt/design-system 0.59.0 → 0.60.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.
@@ -7,6 +7,13 @@
7
7
  // renderer dispatches on this kind and falls back to the param `type`, so
8
8
  // legacy action-lane params (no widget key) render byte-identically.
9
9
 
10
+ import {
11
+ decomposeGeometry,
12
+ modeForGeometryType,
13
+ type GeoJsonGeometry,
14
+ type MapPickerMode,
15
+ } from "./map-geometry";
16
+
10
17
  type Entity = Record<string, unknown>;
11
18
 
12
19
  /** The render intent for a param: `widget` → `ui_schema.widget` → `type`. */
@@ -95,6 +102,82 @@ export function lonLatToGeoJsonPoint(coords: [number, number]): GeoJsonPoint {
95
102
  return { type: "Point", coordinates: [coords[0], coords[1]] };
96
103
  }
97
104
 
105
+ /** atelier#2838 — what the `geometry` widget renders, from the parameter's
106
+ * DECLARED geometry type (`geometry_type`, a GeoJSON type name):
107
+ * - absent (undefined / null / "") or "Point" → the #39 point picker over a
108
+ * GeoJSON Point (`coords` + `error` from `geoJsonPointToLonLat`);
109
+ * - a drawable type → that MapPicker shape mode over a GeoJSON value of
110
+ * EXACTLY that type (`geometry` + `error` from `decomposeGeometry`);
111
+ * - anything else (GeometryCollection, unknown names, wrong case) →
112
+ * `mode: null` + `unsupportedType`: the field renders a loud unsupported
113
+ * state and no picker — never a silent point. */
114
+ export type GeometryFieldPlan =
115
+ | {
116
+ mode: "point";
117
+ coords: [number, number] | null;
118
+ geometry: null;
119
+ error: string | null;
120
+ unsupportedType: null;
121
+ }
122
+ | {
123
+ mode: Exclude<MapPickerMode, "point">;
124
+ coords: null;
125
+ geometry: GeoJsonGeometry | null;
126
+ error: string | null;
127
+ unsupportedType: null;
128
+ }
129
+ | {
130
+ mode: null;
131
+ coords: null;
132
+ geometry: null;
133
+ error: null;
134
+ unsupportedType: string;
135
+ };
136
+
137
+ export function geometryFieldPlan(
138
+ parameter: Entity,
139
+ value: unknown,
140
+ ): GeometryFieldPlan {
141
+ const declared = parameter.geometry_type;
142
+ if (
143
+ declared === undefined ||
144
+ declared === null ||
145
+ declared === "" ||
146
+ declared === "Point"
147
+ ) {
148
+ const { coords, error } = geoJsonPointToLonLat(value);
149
+ return {
150
+ mode: "point",
151
+ coords,
152
+ geometry: null,
153
+ error,
154
+ unsupportedType: null,
155
+ };
156
+ }
157
+ const mode = modeForGeometryType(declared);
158
+ if (mode === null || mode === "point") {
159
+ return {
160
+ mode: null,
161
+ coords: null,
162
+ geometry: null,
163
+ error: null,
164
+ unsupportedType:
165
+ typeof declared === "string" ? declared : JSON.stringify(declared),
166
+ };
167
+ }
168
+ const { error } = decomposeGeometry(mode, value);
169
+ return {
170
+ mode,
171
+ coords: null,
172
+ geometry:
173
+ error || value === "" || value == null
174
+ ? null
175
+ : (value as GeoJsonGeometry),
176
+ error,
177
+ unsupportedType: null,
178
+ };
179
+ }
180
+
98
181
  /** #46 — the map picker's INITIAL CENTRE, from its declared home:
99
182
  * `ui_schema.map.initial_center` ([lon, lat]). A viewport hint is
100
183
  * presentation, not a value — it lives in ui_schema so `default_value`
@@ -0,0 +1,46 @@
1
+ export type MapPickerMode = "point" | "multipoint" | "linestring" | "multilinestring" | "polygon" | "multipolygon";
2
+ export type DrawType = "Point" | "LineString" | "Polygon";
3
+ export type GeoJsonGeometryType = "Point" | "MultiPoint" | "LineString" | "MultiLineString" | "Polygon" | "MultiPolygon";
4
+ export type GeoJsonGeometry = {
5
+ type: GeoJsonGeometryType;
6
+ coordinates: unknown[];
7
+ };
8
+ export type MapPickerModeSpec = {
9
+ geometryType: GeoJsonGeometryType;
10
+ drawType: DrawType;
11
+ multi: boolean;
12
+ };
13
+ export declare const MAP_PICKER_MODES: Readonly<Record<MapPickerMode, MapPickerModeSpec>>;
14
+ /** Nesting depth of a draw type's coordinates down to a position
15
+ * (Point 0, LineString 1, Polygon 2). */
16
+ export declare const POSITION_DEPTH: Readonly<Record<DrawType, number>>;
17
+ /** The picker mode that draws a GeoJSON type, or null when it cannot be
18
+ * drawn (GeometryCollection, unknown names, wrong case — the contract is
19
+ * GeoJSON's own spelling). */
20
+ export declare function modeForGeometryType(type: unknown): MapPickerMode | null;
21
+ /** Map `fn` over every position of a coordinates array of the given depth. */
22
+ export declare function mapPositions<T>(coords: unknown, depth: number, fn: (p: number[]) => T): unknown;
23
+ /** Compose drawn parts into EXACTLY the mode's GeoJSON type. No parts → null
24
+ * (a clear — never an empty geometry). */
25
+ export declare function composeGeometry(mode: string, parts: unknown[]): GeoJsonGeometry | null;
26
+ /** Decompose an existing value into drawable parts for `mode`. Empty → no
27
+ * parts. A non-geometry, a geometry of another type, or malformed
28
+ * coordinates → no parts and a named error the field renders. */
29
+ export declare function decomposeGeometry(mode: string, value: unknown): {
30
+ parts: unknown[];
31
+ error: string | null;
32
+ };
33
+ /** Any GeoJSON geometry, incl. a (recursive) GeometryCollection. */
34
+ export type AnyGeoJsonGeometry = GeoJsonGeometry | {
35
+ type: "GeometryCollection";
36
+ geometries: AnyGeoJsonGeometry[];
37
+ };
38
+ /** True when `value` is a drawable GeoJSON geometry (RFC 7946 §3.1): one of
39
+ * the six simple types with well-formed coordinates (finite positions, ≥2
40
+ * positions per line, closed rings of ≥4 positions; multi types non-empty),
41
+ * or a GeometryCollection whose members are all valid and which has at least
42
+ * one member. A Feature/FeatureCollection is not a geometry. */
43
+ export declare function isGeoJsonGeometry(value: unknown): value is AnyGeoJsonGeometry;
44
+ /** The simple (non-collection) geometries of a valid geometry, depth-first
45
+ * in document order — a GeometryCollection is flattened recursively. */
46
+ export declare function geometryLeaves(geometry: AnyGeoJsonGeometry): GeoJsonGeometry[];
@@ -0,0 +1,253 @@
1
+ // atelier#2838 — MapPicker's shape modes, as pure functions.
2
+ //
3
+ // A mode draws ONE kind of OpenLayers feature (Point, LineString or Polygon)
4
+ // and emits EXACTLY one GeoJSON geometry type: the single modes emit the
5
+ // last drawn feature, the multi modes emit one member per drawn feature.
6
+ // Drawn "parts" are the WGS84 [lon, lat] coordinates of each drawn feature,
7
+ // shaped like that draw type's GeoJSON `coordinates`. An existing geometry
8
+ // decomposes back into parts only when its type is the mode's type —
9
+ // anything else is a named, loud error, never a silent re-type.
10
+
11
+ export type MapPickerMode =
12
+ | "point"
13
+ | "multipoint"
14
+ | "linestring"
15
+ | "multilinestring"
16
+ | "polygon"
17
+ | "multipolygon";
18
+
19
+ export type DrawType = "Point" | "LineString" | "Polygon";
20
+
21
+ export type GeoJsonGeometryType =
22
+ | "Point"
23
+ | "MultiPoint"
24
+ | "LineString"
25
+ | "MultiLineString"
26
+ | "Polygon"
27
+ | "MultiPolygon";
28
+
29
+ export type GeoJsonGeometry = {
30
+ type: GeoJsonGeometryType;
31
+ coordinates: unknown[];
32
+ };
33
+
34
+ export type MapPickerModeSpec = {
35
+ geometryType: GeoJsonGeometryType;
36
+ drawType: DrawType;
37
+ multi: boolean;
38
+ };
39
+
40
+ export const MAP_PICKER_MODES: Readonly<
41
+ Record<MapPickerMode, MapPickerModeSpec>
42
+ > = Object.freeze({
43
+ point: { geometryType: "Point", drawType: "Point", multi: false },
44
+ multipoint: { geometryType: "MultiPoint", drawType: "Point", multi: true },
45
+ linestring: {
46
+ geometryType: "LineString",
47
+ drawType: "LineString",
48
+ multi: false,
49
+ },
50
+ multilinestring: {
51
+ geometryType: "MultiLineString",
52
+ drawType: "LineString",
53
+ multi: true,
54
+ },
55
+ polygon: { geometryType: "Polygon", drawType: "Polygon", multi: false },
56
+ multipolygon: {
57
+ geometryType: "MultiPolygon",
58
+ drawType: "Polygon",
59
+ multi: true,
60
+ },
61
+ });
62
+
63
+ /** Nesting depth of a draw type's coordinates down to a position
64
+ * (Point 0, LineString 1, Polygon 2). */
65
+ export const POSITION_DEPTH: Readonly<Record<DrawType, number>> = Object.freeze(
66
+ {
67
+ Point: 0,
68
+ LineString: 1,
69
+ Polygon: 2,
70
+ },
71
+ );
72
+
73
+ /** The picker mode that draws a GeoJSON type, or null when it cannot be
74
+ * drawn (GeometryCollection, unknown names, wrong case — the contract is
75
+ * GeoJSON's own spelling). */
76
+ export function modeForGeometryType(type: unknown): MapPickerMode | null {
77
+ if (typeof type !== "string") return null;
78
+ for (const [mode, spec] of Object.entries(MAP_PICKER_MODES)) {
79
+ if (spec.geometryType === type) return mode as MapPickerMode;
80
+ }
81
+ return null;
82
+ }
83
+
84
+ function specFor(mode: string): MapPickerModeSpec {
85
+ const spec = (MAP_PICKER_MODES as Record<string, MapPickerModeSpec>)[mode];
86
+ if (!spec) throw new Error(`Unknown MapPicker mode: ${mode}`);
87
+ return spec;
88
+ }
89
+
90
+ /** Map `fn` over every position of a coordinates array of the given depth. */
91
+ export function mapPositions<T>(
92
+ coords: unknown,
93
+ depth: number,
94
+ fn: (p: number[]) => T,
95
+ ): unknown {
96
+ if (depth === 0) return fn(coords as number[]);
97
+ return (coords as unknown[]).map((c) => mapPositions(c, depth - 1, fn));
98
+ }
99
+
100
+ function clone(coords: unknown, depth: number): unknown {
101
+ return mapPositions(coords, depth, (p) => [...p]);
102
+ }
103
+
104
+ /** Twice the signed area of a ring (shoelace); > 0 means counter-clockwise. */
105
+ function ringArea(ring: number[][]): number {
106
+ let sum = 0;
107
+ for (let i = 0; i < ring.length - 1; i++) {
108
+ sum += ring[i][0] * ring[i + 1][1] - ring[i + 1][0] * ring[i][1];
109
+ }
110
+ return sum;
111
+ }
112
+
113
+ /** RFC 7946 §3.1.6 winding: exterior ring counter-clockwise, holes clockwise. */
114
+ function rightHanded(rings: number[][][]): number[][][] {
115
+ return rings.map((ring, i) => {
116
+ const ccw = ringArea(ring) > 0;
117
+ const wantCcw = i === 0;
118
+ return ccw === wantCcw ? ring : [...ring].reverse();
119
+ });
120
+ }
121
+
122
+ /** Compose drawn parts into EXACTLY the mode's GeoJSON type. No parts → null
123
+ * (a clear — never an empty geometry). */
124
+ export function composeGeometry(
125
+ mode: string,
126
+ parts: unknown[],
127
+ ): GeoJsonGeometry | null {
128
+ const spec = specFor(mode);
129
+ if (!parts.length) return null;
130
+ const depth = POSITION_DEPTH[spec.drawType];
131
+ const shape = (part: unknown) => {
132
+ const copy = clone(part, depth);
133
+ return spec.drawType === "Polygon"
134
+ ? rightHanded(copy as number[][][])
135
+ : copy;
136
+ };
137
+ if (spec.multi) {
138
+ return { type: spec.geometryType, coordinates: parts.map(shape) };
139
+ }
140
+ return {
141
+ type: spec.geometryType,
142
+ coordinates: shape(parts[parts.length - 1]) as unknown[],
143
+ };
144
+ }
145
+
146
+ function isPosition(p: unknown): boolean {
147
+ return (
148
+ Array.isArray(p) &&
149
+ p.length >= 2 &&
150
+ p.every((n) => typeof n === "number" && Number.isFinite(n))
151
+ );
152
+ }
153
+
154
+ function isLine(l: unknown): boolean {
155
+ return Array.isArray(l) && l.length >= 2 && l.every(isPosition);
156
+ }
157
+
158
+ function isRing(r: unknown): boolean {
159
+ if (!Array.isArray(r) || r.length < 4 || !r.every(isPosition)) return false;
160
+ const first = r[0] as number[];
161
+ const last = r[r.length - 1] as number[];
162
+ return first[0] === last[0] && first[1] === last[1];
163
+ }
164
+
165
+ const PART_VALID: Record<DrawType, (part: unknown) => boolean> = {
166
+ Point: isPosition,
167
+ LineString: isLine,
168
+ Polygon: (p) => Array.isArray(p) && p.length >= 1 && p.every(isRing),
169
+ };
170
+
171
+ /** Decompose an existing value into drawable parts for `mode`. Empty → no
172
+ * parts. A non-geometry, a geometry of another type, or malformed
173
+ * coordinates → no parts and a named error the field renders. */
174
+ export function decomposeGeometry(
175
+ mode: string,
176
+ value: unknown,
177
+ ): { parts: unknown[]; error: string | null } {
178
+ const spec = specFor(mode);
179
+ if (value === null || value === undefined || value === "") {
180
+ return { parts: [], error: null };
181
+ }
182
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
183
+ return {
184
+ parts: [],
185
+ error: `Unsupported geometry: expected a GeoJSON ${spec.geometryType}`,
186
+ };
187
+ }
188
+ const row = value as Record<string, unknown>;
189
+ if (row.type !== spec.geometryType) {
190
+ return {
191
+ parts: [],
192
+ error: `Unsupported geometry: expected a GeoJSON ${spec.geometryType}, got ${String(row.type ?? "unknown")}`,
193
+ };
194
+ }
195
+ const malformed = {
196
+ parts: [],
197
+ error: `Unsupported geometry: malformed ${spec.geometryType} coordinates`,
198
+ };
199
+ const valid = PART_VALID[spec.drawType];
200
+ const coords = row.coordinates;
201
+ const depth = POSITION_DEPTH[spec.drawType];
202
+ if (spec.multi) {
203
+ if (!Array.isArray(coords) || !coords.every(valid)) return malformed;
204
+ return { parts: coords.map((c) => clone(c, depth)), error: null };
205
+ }
206
+ if (!valid(coords)) return malformed;
207
+ return { parts: [clone(coords, depth)], error: null };
208
+ }
209
+
210
+ // ─── Read-only display: ANY GeoJSON geometry ────────────────────────────────
211
+
212
+ const SIMPLE_TYPES: Readonly<Record<string, { drawType: DrawType; multi: boolean }>> = {
213
+ Point: { drawType: "Point", multi: false },
214
+ MultiPoint: { drawType: "Point", multi: true },
215
+ LineString: { drawType: "LineString", multi: false },
216
+ MultiLineString: { drawType: "LineString", multi: true },
217
+ Polygon: { drawType: "Polygon", multi: false },
218
+ MultiPolygon: { drawType: "Polygon", multi: true },
219
+ };
220
+
221
+ /** Any GeoJSON geometry, incl. a (recursive) GeometryCollection. */
222
+ export type AnyGeoJsonGeometry =
223
+ | GeoJsonGeometry
224
+ | { type: "GeometryCollection"; geometries: AnyGeoJsonGeometry[] };
225
+
226
+ /** True when `value` is a drawable GeoJSON geometry (RFC 7946 §3.1): one of
227
+ * the six simple types with well-formed coordinates (finite positions, ≥2
228
+ * positions per line, closed rings of ≥4 positions; multi types non-empty),
229
+ * or a GeometryCollection whose members are all valid and which has at least
230
+ * one member. A Feature/FeatureCollection is not a geometry. */
231
+ export function isGeoJsonGeometry(value: unknown): value is AnyGeoJsonGeometry {
232
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
233
+ const row = value as Record<string, unknown>;
234
+ if (row.type === "GeometryCollection") {
235
+ const members = row.geometries;
236
+ return Array.isArray(members) && members.length > 0 && members.every(isGeoJsonGeometry);
237
+ }
238
+ const spec = typeof row.type === "string" ? SIMPLE_TYPES[row.type] : undefined;
239
+ if (!spec) return false;
240
+ const valid = PART_VALID[spec.drawType];
241
+ const coords = row.coordinates;
242
+ if (!spec.multi) return valid(coords);
243
+ return Array.isArray(coords) && coords.length > 0 && coords.every(valid);
244
+ }
245
+
246
+ /** The simple (non-collection) geometries of a valid geometry, depth-first
247
+ * in document order — a GeometryCollection is flattened recursively. */
248
+ export function geometryLeaves(geometry: AnyGeoJsonGeometry): GeoJsonGeometry[] {
249
+ if (geometry.type === "GeometryCollection") {
250
+ return geometry.geometries.flatMap(geometryLeaves);
251
+ }
252
+ return [geometry];
253
+ }
@@ -1,7 +1,3 @@
1
- /**
2
- * Shared utilities for map components.
3
- * Not exported from index.js — internal to map components only.
4
- */
5
1
  /**
6
2
  * @typedef {{ tone?: 'muted' }} TileTone — `tone: 'muted'` greys the
7
3
  * basemap (and darkens it in the dark scheme) through
@@ -48,6 +44,21 @@ export function createTileLayer(config: TileSourceConfig): Promise<import("ol/la
48
44
  * @returns {Promise<MapStyles>}
49
45
  */
50
46
  export function createMapStyles(el: Element): Promise<MapStyles>;
47
+ /**
48
+ * Build what MapDisplay draws for ANY GeoJSON geometry: one projected
49
+ * (EPSG:3857) OpenLayers feature per leaf geometry — a GeometryCollection is
50
+ * flattened recursively — plus the extent to fit the view to. A geometry
51
+ * whose extent is a single point (a Point, or a collection of one point)
52
+ * returns `center` instead, so the consumer's zoom is kept. Invalid → null.
53
+ *
54
+ * @param {unknown} geometry
55
+ * @returns {Promise<{ features: any[], extent: number[], center: number[] | null } | null>}
56
+ */
57
+ export function buildGeometryFeatures(geometry: unknown): Promise<{
58
+ features: any[];
59
+ extent: number[];
60
+ center: number[] | null;
61
+ } | null>;
51
62
  /**
52
63
  * Watches for theme changes (data-theme attribute, class changes on <html>,
53
64
  * OS prefers-color-scheme). Calls onchange when a theme switch is detected.
@@ -3,6 +3,8 @@
3
3
  * Not exported from index.js — internal to map components only.
4
4
  */
5
5
 
6
+ import { geometryLeaves, isGeoJsonGeometry } from "./map-geometry";
7
+
6
8
  /**
7
9
  * @typedef {{ tone?: 'muted' }} TileTone — `tone: 'muted'` greys the
8
10
  * basemap (and darkens it in the dark scheme) through
@@ -109,6 +111,8 @@ export async function createMapStyles(el) {
109
111
  const markerStrokeObj = new Stroke({ color: "", width: 0 });
110
112
  const polyFillObj = new Fill({ color: "" });
111
113
  const polyStrokeObj = new Stroke({ color: "", width: 0 });
114
+ const selFillObj = new Fill({ color: "" });
115
+ const selStrokeObj = new Stroke({ color: "", width: 0 });
112
116
 
113
117
  let markerRadiusVal = 8;
114
118
  let clusterBaseRadiusVal = 16;
@@ -129,6 +133,13 @@ export async function createMapStyles(el) {
129
133
  stroke: polyStrokeObj,
130
134
  });
131
135
 
136
+ // MapPicker shape modes: the selected drawn shape (and its vertices).
137
+ const selection = new Style({
138
+ fill: selFillObj,
139
+ stroke: selStrokeObj,
140
+ image: new CircleStyle({ radius: 8, fill: selFillObj, stroke: selStrokeObj }),
141
+ });
142
+
132
143
  /** @type {Map<string, import('ol/style/Style.js').default>} */
133
144
  const clusterCache = new Map();
134
145
  /** @type {Map<string, import('ol/style/Style.js').default>} */
@@ -146,6 +157,11 @@ export async function createMapStyles(el) {
146
157
  );
147
158
  polyStrokeObj.setColor(cssVar(el, "--map-polygon-stroke", "#ff6b35"));
148
159
  polyStrokeObj.setWidth(cssPx(el, "--map-polygon-stroke-width", 2));
160
+ selFillObj.setColor(
161
+ cssVar(el, "--map-selection-fill", "rgba(44,40,37,0.2)"),
162
+ );
163
+ selStrokeObj.setColor(cssVar(el, "--map-selection-stroke", "#2c2825"));
164
+ selStrokeObj.setWidth(cssPx(el, "--map-selection-stroke-width", 2));
149
165
  clusterBaseRadiusVal = cssPx(el, "--map-cluster-radius", 16);
150
166
  clusterFillColor = cssVar(el, "--map-cluster-fill", "#ff6b35");
151
167
  clusterTextColor = cssVar(el, "--map-cluster-text-fill", "#fff");
@@ -178,6 +194,13 @@ export async function createMapStyles(el) {
178
194
  stroke: markerStrokeObj,
179
195
  }),
180
196
  );
197
+ selection.setImage(
198
+ new CircleStyle({
199
+ radius: markerRadiusVal,
200
+ fill: selStrokeObj.getColor() ? new Fill({ color: selStrokeObj.getColor() }) : selFillObj,
201
+ stroke: markerStrokeObj,
202
+ }),
203
+ );
181
204
  }
182
205
 
183
206
  // Initial read
@@ -277,7 +300,43 @@ export async function createMapStyles(el) {
277
300
  pinCache.clear();
278
301
  }
279
302
 
280
- return { marker, polygon, cluster, pin, refresh };
303
+ return { marker, polygon, selection, cluster, pin, refresh };
304
+ }
305
+
306
+ // ─── Read-only geometry (MapDisplay `geometry`, atelier#2838) ────
307
+
308
+ /**
309
+ * Build what MapDisplay draws for ANY GeoJSON geometry: one projected
310
+ * (EPSG:3857) OpenLayers feature per leaf geometry — a GeometryCollection is
311
+ * flattened recursively — plus the extent to fit the view to. A geometry
312
+ * whose extent is a single point (a Point, or a collection of one point)
313
+ * returns `center` instead, so the consumer's zoom is kept. Invalid → null.
314
+ *
315
+ * @param {unknown} geometry
316
+ * @returns {Promise<{ features: any[], extent: number[], center: number[] | null } | null>}
317
+ */
318
+ export async function buildGeometryFeatures(geometry) {
319
+ if (!isGeoJsonGeometry(geometry)) return null;
320
+ const [{ default: GeoJSON }, { default: Feature }, { createEmpty, extend, getWidth, getHeight, getCenter }] =
321
+ await Promise.all([
322
+ import("ol/format/GeoJSON.js"),
323
+ import("ol/Feature.js"),
324
+ import("ol/extent.js"),
325
+ ]);
326
+ const format = new GeoJSON();
327
+ const features = geometryLeaves(geometry).map(
328
+ (leaf) =>
329
+ new Feature({
330
+ geometry: format.readGeometry(leaf, {
331
+ dataProjection: "EPSG:4326",
332
+ featureProjection: "EPSG:3857",
333
+ }),
334
+ }),
335
+ );
336
+ const extent = createEmpty();
337
+ for (const f of features) extend(extent, f.getGeometry().getExtent());
338
+ const center = getWidth(extent) === 0 && getHeight(extent) === 0 ? getCenter(extent) : null;
339
+ return { features, extent, center };
281
340
  }
282
341
 
283
342
  // ─── Theme Watcher ───────────────────────────────────────────────
@@ -19,8 +19,10 @@
19
19
  * date formatting (admin, from schema type); otherwise value-shape
20
20
  * detection (`isIsoTimestamp`) applies (portal).
21
21
  *
22
- * Everything here is PURE and dependency-free.
22
+ * Everything here is PURE; the only import is the DS's own pure GeoJSON
23
+ * validator (`map-geometry`), shared with MapPicker/MapDisplay.
23
24
  */
25
+ import { type AnyGeoJsonGeometry } from "../map-geometry";
24
26
  export type ObjectFallback = "redact" | "json";
25
27
  /** How a boolean renders: "raw" (default) → "true"/"false" (both hosts'
26
28
  * historical output); "yes-no" → "Yes"/"No" (the staff admin's cell copy —
@@ -91,3 +93,12 @@ export declare function resolveStatusBadge(value: unknown, opts?: {
91
93
  * usable point. Pure — the map widget decides how to render the result.
92
94
  */
93
95
  export declare function geoPoint(value: unknown): [number, number] | null;
96
+ /**
97
+ * atelier#2838 — validate ANY GeoJSON geometry for the read-only map: Point,
98
+ * MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon, or a
99
+ * (recursive, non-empty) GeometryCollection, with well-formed coordinates.
100
+ * Returns the value itself when it is drawable, otherwise null — the host
101
+ * keeps its own fallback for null. Feed the result to `MapDisplay`'s
102
+ * `geometry` prop. Pure.
103
+ */
104
+ export declare function geoGeometry(value: unknown): AnyGeoJsonGeometry | null;
@@ -19,9 +19,12 @@
19
19
  * date formatting (admin, from schema type); otherwise value-shape
20
20
  * detection (`isIsoTimestamp`) applies (portal).
21
21
  *
22
- * Everything here is PURE and dependency-free.
22
+ * Everything here is PURE; the only import is the DS's own pure GeoJSON
23
+ * validator (`map-geometry`), shared with MapPicker/MapDisplay.
23
24
  */
24
25
 
26
+ import { isGeoJsonGeometry, type AnyGeoJsonGeometry } from "../map-geometry";
27
+
25
28
  export type ObjectFallback = "redact" | "json";
26
29
 
27
30
  /** How a boolean renders: "raw" (default) → "true"/"false" (both hosts'
@@ -208,3 +211,15 @@ export function geoPoint(value: unknown): [number, number] | null {
208
211
  if (!Number.isFinite(lon) || !Number.isFinite(lat)) return null;
209
212
  return [lon, lat];
210
213
  }
214
+
215
+ /**
216
+ * atelier#2838 — validate ANY GeoJSON geometry for the read-only map: Point,
217
+ * MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon, or a
218
+ * (recursive, non-empty) GeometryCollection, with well-formed coordinates.
219
+ * Returns the value itself when it is drawable, otherwise null — the host
220
+ * keeps its own fallback for null. Feed the result to `MapDisplay`'s
221
+ * `geometry` prop. Pure.
222
+ */
223
+ export function geoGeometry(value: unknown): AnyGeoJsonGeometry | null {
224
+ return isGeoJsonGeometry(value) ? value : null;
225
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiaiai-pt/design-system",
3
- "version": "0.59.0",
3
+ "version": "0.60.0",
4
4
  "description": "Design system tokens and Svelte components for aiaiai products",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -44,6 +44,10 @@
44
44
  "types": "./components/action-form-renderer-widgets.d.ts",
45
45
  "default": "./components/action-form-renderer-widgets.ts"
46
46
  },
47
+ "./components/map-geometry": {
48
+ "types": "./components/map-geometry.d.ts",
49
+ "default": "./components/map-geometry.ts"
50
+ },
47
51
  "./components/json-editor-contract": {
48
52
  "types": "./components/json-editor-contract.d.ts",
49
53
  "default": "./components/json-editor-contract.ts"
@@ -894,6 +894,10 @@
894
894
  --map-polygon-fill: color-mix(in srgb, var(--color-accent) 20%, transparent);
895
895
  --map-polygon-stroke: var(--color-accent);
896
896
  --map-polygon-stroke-width: var(--border-width-thick);
897
+ /* Selected drawn shape (MapPicker shape modes — the one Delete removes) */
898
+ --map-selection-fill: color-mix(in srgb, var(--color-text) 20%, transparent);
899
+ --map-selection-stroke: var(--color-text);
900
+ --map-selection-stroke-width: var(--border-width-thick);
897
901
 
898
902
  /* Boundary overlay (#187 — tenant geofence context, not content) */
899
903
  --map-boundary-fill: color-mix(in srgb, var(--color-accent) 8%, transparent);