@conduction/nextcloud-vue 2.181.0 → 2.182.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.
- package/dist/esm/components/CnMapWidget/CnMapWidget.vue.js +1 -1
- package/dist/esm/components/CnMapWidget/CnMapWidget2.vue.js +7 -4
- package/dist/esm/components/CnMapWidget/CnMapWidget2.vue.js.map +1 -1
- package/dist/esm/components/CnMapWidget/CnMapWidget3.vue.js.map +1 -1
- package/dist/esm/components/CnMapWidget/basemapPresets.js +81 -0
- package/dist/esm/components/CnMapWidget/basemapPresets.js.map +1 -0
- package/dist/esm/components/CnMapWidgetForm/CnMapWidgetForm.vue.js +1 -1
- package/dist/esm/components/CnMapWidgetForm/CnMapWidgetForm2.vue.js +37 -12
- package/dist/esm/components/CnMapWidgetForm/CnMapWidgetForm2.vue.js.map +1 -1
- package/dist/esm/components/CnMapWidgetForm/CnMapWidgetForm3.vue.js +27 -9
- package/dist/esm/components/CnMapWidgetForm/CnMapWidgetForm3.vue.js.map +1 -1
- package/dist/esm/l10n/nl.json.js +5 -1
- package/dist/esm/l10n/nl.json.js.map +1 -1
- package/dist/esm/library-style.js +1 -1
- package/dist/esm/nextcloud-vue.css +23 -23
- package/dist/esm/utils/geo.js +49 -10
- package/dist/esm/utils/geo.js.map +1 -1
- package/dist/nextcloud-vue.cjs.js +203 -36
- package/dist/nextcloud-vue.cjs.js.map +2 -2
- package/dist/nextcloud-vue.css +23 -23
- package/l10n/nl.json +5 -1
- package/package.json +2 -2
- package/src/components/CnMapWidget/CnMapWidget.vue +7 -4
- package/src/components/CnMapWidget/basemapPresets.js +78 -0
- package/src/components/CnMapWidgetForm/CnMapWidgetForm.vue +53 -13
- package/src/utils/geo.js +48 -9
|
@@ -23945,12 +23945,12 @@ svg.leaflet-image-layer.leaflet-interactive path {
|
|
|
23945
23945
|
line-height: 30px;
|
|
23946
23946
|
}
|
|
23947
23947
|
|
|
23948
|
-
.cn-map-widget[data-v-
|
|
23948
|
+
.cn-map-widget[data-v-356bff56] {
|
|
23949
23949
|
position: relative;
|
|
23950
23950
|
width: 100%;
|
|
23951
23951
|
min-height: 200px;
|
|
23952
23952
|
}
|
|
23953
|
-
.cn-map-widget__leaflet[data-v-
|
|
23953
|
+
.cn-map-widget__leaflet[data-v-356bff56] {
|
|
23954
23954
|
width: 100%;
|
|
23955
23955
|
height: 100%;
|
|
23956
23956
|
/* Leaflet paints its container #ddd, which reads as a white flash before the
|
|
@@ -23959,16 +23959,16 @@ svg.leaflet-image-layer.leaflet-interactive path {
|
|
|
23959
23959
|
}
|
|
23960
23960
|
|
|
23961
23961
|
/* With a caption the map keeps its own height and the caption sits under it. */
|
|
23962
|
-
.cn-map-widget__leaflet--captioned[data-v-
|
|
23962
|
+
.cn-map-widget__leaflet--captioned[data-v-356bff56] {
|
|
23963
23963
|
min-height: 200px;
|
|
23964
23964
|
}
|
|
23965
|
-
.cn-map-widget__caption[data-v-
|
|
23965
|
+
.cn-map-widget__caption[data-v-356bff56] {
|
|
23966
23966
|
margin: 12px 0 0;
|
|
23967
23967
|
font-size: 15px;
|
|
23968
23968
|
line-height: 1.2;
|
|
23969
23969
|
color: var(--color-main-text);
|
|
23970
23970
|
}
|
|
23971
|
-
.cn-map-widget__toggles[data-v-
|
|
23971
|
+
.cn-map-widget__toggles[data-v-356bff56] {
|
|
23972
23972
|
display: flex;
|
|
23973
23973
|
flex-wrap: wrap;
|
|
23974
23974
|
gap: 6px 16px;
|
|
@@ -23977,31 +23977,31 @@ svg.leaflet-image-layer.leaflet-interactive path {
|
|
|
23977
23977
|
border: 0;
|
|
23978
23978
|
font-size: 14px;
|
|
23979
23979
|
}
|
|
23980
|
-
.cn-map-widget__toggles-title[data-v-
|
|
23980
|
+
.cn-map-widget__toggles-title[data-v-356bff56] {
|
|
23981
23981
|
width: 100%;
|
|
23982
23982
|
margin-bottom: 2px;
|
|
23983
23983
|
padding: 0;
|
|
23984
23984
|
font-weight: 600;
|
|
23985
23985
|
}
|
|
23986
|
-
.cn-map-widget__toggle[data-v-
|
|
23986
|
+
.cn-map-widget__toggle[data-v-356bff56] {
|
|
23987
23987
|
display: inline-flex;
|
|
23988
23988
|
align-items: center;
|
|
23989
23989
|
gap: 6px;
|
|
23990
23990
|
}
|
|
23991
|
-
.cn-map-widget__note[data-v-
|
|
23991
|
+
.cn-map-widget__note[data-v-356bff56] {
|
|
23992
23992
|
margin: 4px 0 0;
|
|
23993
23993
|
font-size: 13px;
|
|
23994
23994
|
color: var(--color-text-maxcontrast);
|
|
23995
23995
|
}
|
|
23996
23996
|
|
|
23997
23997
|
/* Why the map shows no markers: the card's own text size, on its inset. */
|
|
23998
|
-
.cn-map-widget__note--status[data-v-
|
|
23998
|
+
.cn-map-widget__note--status[data-v-356bff56] {
|
|
23999
23999
|
font-size: 14px;
|
|
24000
24000
|
}
|
|
24001
|
-
.cn-map-widget__note--error[data-v-
|
|
24001
|
+
.cn-map-widget__note--error[data-v-356bff56] {
|
|
24002
24002
|
color: var(--color-error-text, var(--color-error));
|
|
24003
24003
|
}
|
|
24004
|
-
.cn-map-widget__fallback[data-v-
|
|
24004
|
+
.cn-map-widget__fallback[data-v-356bff56] {
|
|
24005
24005
|
display: flex;
|
|
24006
24006
|
align-items: center;
|
|
24007
24007
|
justify-content: center;
|
|
@@ -24009,11 +24009,11 @@ svg.leaflet-image-layer.leaflet-interactive path {
|
|
|
24009
24009
|
min-height: 150px;
|
|
24010
24010
|
color: var(--color-text-maxcontrast);
|
|
24011
24011
|
}
|
|
24012
|
-
.cn-map-widget__error[data-v-
|
|
24012
|
+
.cn-map-widget__error[data-v-356bff56] {
|
|
24013
24013
|
font-size: 14px;
|
|
24014
24014
|
margin: 0;
|
|
24015
24015
|
}
|
|
24016
|
-
.cn-map-widget__legend[data-v-
|
|
24016
|
+
.cn-map-widget__legend[data-v-356bff56] {
|
|
24017
24017
|
position: absolute;
|
|
24018
24018
|
top: 12px;
|
|
24019
24019
|
right: 12px;
|
|
@@ -24026,7 +24026,7 @@ svg.leaflet-image-layer.leaflet-interactive path {
|
|
|
24026
24026
|
|
|
24027
24027
|
/* Fullscreen overlay. A CSS-fixed box rather than the Fullscreen API, so it needs
|
|
24028
24028
|
no permission prompt; the z-index clears the Nextcloud header. */
|
|
24029
|
-
.cn-map-widget--fullscreen[data-v-
|
|
24029
|
+
.cn-map-widget--fullscreen[data-v-356bff56] {
|
|
24030
24030
|
position: fixed;
|
|
24031
24031
|
top: 0;
|
|
24032
24032
|
left: 0;
|
|
@@ -24039,7 +24039,7 @@ svg.leaflet-image-layer.leaflet-interactive path {
|
|
|
24039
24039
|
Leaflet's default white-on-grey buttons.
|
|
24040
24040
|
::v-deep is required — Leaflet builds the control DOM via L.DomUtil.create, so
|
|
24041
24041
|
those nodes never receive this SFC's scoped data-v attribute. */
|
|
24042
|
-
.cn-map-widget[data-v-
|
|
24042
|
+
.cn-map-widget[data-v-356bff56] .cn-map-widget__control {
|
|
24043
24043
|
display: flex;
|
|
24044
24044
|
align-items: center;
|
|
24045
24045
|
justify-content: center;
|
|
@@ -24048,8 +24048,8 @@ svg.leaflet-image-layer.leaflet-interactive path {
|
|
|
24048
24048
|
color: var(--color-main-text);
|
|
24049
24049
|
background: var(--color-main-background);
|
|
24050
24050
|
}
|
|
24051
|
-
.cn-map-widget[data-v-
|
|
24052
|
-
.cn-map-widget[data-v-
|
|
24051
|
+
.cn-map-widget[data-v-356bff56] .cn-map-widget__control:hover,
|
|
24052
|
+
.cn-map-widget[data-v-356bff56] .cn-map-widget__control:focus-visible {
|
|
24053
24053
|
background: var(--color-background-hover);
|
|
24054
24054
|
}
|
|
24055
24055
|
|
|
@@ -24082,30 +24082,30 @@ svg.leaflet-image-layer.leaflet-interactive path {
|
|
|
24082
24082
|
}
|
|
24083
24083
|
|
|
24084
24084
|
|
|
24085
|
-
.cn-map-widget-form[data-v-
|
|
24085
|
+
.cn-map-widget-form[data-v-5ee2234a] {
|
|
24086
24086
|
display: flex;
|
|
24087
24087
|
flex-direction: column;
|
|
24088
24088
|
gap: 12px;
|
|
24089
24089
|
}
|
|
24090
|
-
.cn-map-widget-form__row[data-v-
|
|
24090
|
+
.cn-map-widget-form__row[data-v-5ee2234a] {
|
|
24091
24091
|
display: flex;
|
|
24092
24092
|
gap: 8px;
|
|
24093
24093
|
}
|
|
24094
|
-
.cn-map-widget-form__row[data-v-
|
|
24094
|
+
.cn-map-widget-form__row[data-v-5ee2234a] > * {
|
|
24095
24095
|
flex: 1;
|
|
24096
24096
|
min-width: 0;
|
|
24097
24097
|
}
|
|
24098
|
-
.cn-map-widget-form__hint[data-v-
|
|
24098
|
+
.cn-map-widget-form__hint[data-v-5ee2234a] {
|
|
24099
24099
|
color: var(--color-text-maxcontrast);
|
|
24100
24100
|
font-size: 90%;
|
|
24101
24101
|
margin: 0;
|
|
24102
24102
|
}
|
|
24103
|
-
.cn-map-widget-form__field[data-v-
|
|
24103
|
+
.cn-map-widget-form__field[data-v-5ee2234a] {
|
|
24104
24104
|
display: flex;
|
|
24105
24105
|
flex-direction: column;
|
|
24106
24106
|
gap: 4px;
|
|
24107
24107
|
}
|
|
24108
|
-
.cn-map-widget-form__range[data-v-
|
|
24108
|
+
.cn-map-widget-form__range[data-v-5ee2234a] {
|
|
24109
24109
|
width: 100%;
|
|
24110
24110
|
/* Native range inputs ship a default 2px margin on ALL sides. The left/right
|
|
24111
24111
|
2px pushes the width:100% track past the form and shows a phantom
|
package/dist/esm/utils/geo.js
CHANGED
|
@@ -93,16 +93,44 @@ function parseGeoPoint(geo) {
|
|
|
93
93
|
)
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
const GEOMETRY_TYPES = ['Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', 'MultiPolygon'];
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The GeoJSON geometry a property value holds: a geometry, or a Feature's
|
|
100
|
+
* geometry. Returns null for anything else, so a point-shaped value falls
|
|
101
|
+
* through to parseGeoPoint().
|
|
102
|
+
*
|
|
103
|
+
* @param {unknown} value The property value.
|
|
104
|
+
* @return {?object} The geometry, or null.
|
|
105
|
+
*/
|
|
106
|
+
function parseGeoGeometry(value) {
|
|
107
|
+
if (!value || typeof value !== 'object') {
|
|
108
|
+
return null
|
|
109
|
+
}
|
|
110
|
+
const geometry = value.type === 'Feature' ? value.geometry : value;
|
|
111
|
+
if (!geometry || !GEOMETRY_TYPES.includes(geometry.type) || !Array.isArray(geometry.coordinates)) {
|
|
112
|
+
return null
|
|
113
|
+
}
|
|
114
|
+
if (geometry.type === 'Point') {
|
|
115
|
+
const point = parseGeoPoint(geometry);
|
|
116
|
+
return point ? { type: 'Point', coordinates: [point.lng, point.lat] } : null
|
|
117
|
+
}
|
|
118
|
+
return geometry.coordinates.length > 0 ? geometry : null
|
|
119
|
+
}
|
|
120
|
+
|
|
96
121
|
/**
|
|
97
|
-
* Turn an OpenRegister object into a GeoJSON
|
|
122
|
+
* Turn an OpenRegister object into a GeoJSON Feature, or null when it has no
|
|
98
123
|
* usable location.
|
|
99
124
|
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
125
|
+
* With `geoProperty` set, that property is read first: a GeoJSON geometry of any
|
|
126
|
+
* type (point, line, polygon or a multi-geometry), a Feature, or a lat/lng value.
|
|
127
|
+
* Otherwise, or when it is empty, `@self.geo` is read (where the geo widget writes
|
|
128
|
+
* it), and then plain lat/lng fields on the object itself, so a schema that models
|
|
129
|
+
* coordinates as its own properties still plots.
|
|
103
130
|
*
|
|
104
131
|
* @param {object} obj The OpenRegister object.
|
|
105
132
|
* @param {object} [options] Options.
|
|
133
|
+
* @param {string} [options.geoProperty] Property holding the object's geometry.
|
|
106
134
|
* @param {string} [options.latField] Property holding latitude, for the fallback.
|
|
107
135
|
* @param {string} [options.lngField] Property holding longitude, for the fallback.
|
|
108
136
|
* @return {?object} A GeoJSON Feature whose `properties` is the object, or null.
|
|
@@ -112,14 +140,25 @@ function objectToGeoFeature(obj, options = {}) {
|
|
|
112
140
|
return null
|
|
113
141
|
}
|
|
114
142
|
|
|
143
|
+
const { geoProperty, latField, lngField } = options;
|
|
144
|
+
if (geoProperty) {
|
|
145
|
+
const value = obj[geoProperty];
|
|
146
|
+
const geometry = parseGeoGeometry(value);
|
|
147
|
+
const point = geometry ? null : parseGeoPoint(value);
|
|
148
|
+
if (geometry || point) {
|
|
149
|
+
return {
|
|
150
|
+
type: 'Feature',
|
|
151
|
+
geometry: geometry || { type: 'Point', coordinates: [point.lng, point.lat] },
|
|
152
|
+
properties: { ...obj },
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
115
157
|
const self = obj['@self'] || {};
|
|
116
158
|
let point = parseGeoPoint(self.geo);
|
|
117
159
|
|
|
118
|
-
if (!point) {
|
|
119
|
-
|
|
120
|
-
if (latField && lngField) {
|
|
121
|
-
point = finitePoint(obj[latField], obj[lngField]);
|
|
122
|
-
}
|
|
160
|
+
if (!point && latField && lngField) {
|
|
161
|
+
point = finitePoint(obj[latField], obj[lngField]);
|
|
123
162
|
}
|
|
124
163
|
if (!point) {
|
|
125
164
|
return null
|
|
@@ -132,5 +171,5 @@ function objectToGeoFeature(obj, options = {}) {
|
|
|
132
171
|
}
|
|
133
172
|
}
|
|
134
173
|
|
|
135
|
-
export { finitePoint, objectToGeoFeature, parseGeoPoint };
|
|
174
|
+
export { finitePoint, objectToGeoFeature, parseGeoGeometry, parseGeoPoint };
|
|
136
175
|
//# sourceMappingURL=geo.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geo.js","sources":["../../../src/utils/geo.js"],"sourcesContent":["/**\n * SPDX-FileCopyrightText: 2026 Conduction B.V.\n * SPDX-License-Identifier: EUPL-1.2\n *\n * Reading an OpenRegister object's location.\n *\n * Objects store their location on `@self.geo` as a GeoJSON **Point** geometry\n * (`{ type: 'Point', coordinates: [lng, lat] }` — note GeoJSON is lng-first).\n * Reading is deliberately tolerant, because the value can arrive in several shapes\n * depending on who wrote it: a bare Point geometry, a Feature, a FeatureCollection,\n * or a plain `{lat, lng}` / `{latitude, longitude}` object.\n *\n * This lives here rather than inside a component because two surfaces need it —\n * CnObjectGeoWidget (one object, editable) and CnMapWidget (many objects, plotted).\n * Duplicating the parser would let them disagree about what a valid location is.\n */\n\n/**\n * Build a `{ lat, lng }` when both values are finite numbers, else null.\n *\n * Guards the whole module: a NaN or a string sneaking through here would surface as\n * an invisible marker or a Leaflet exception far from the cause.\n *\n * @param {unknown} lat Candidate latitude.\n * @param {unknown} lng Candidate longitude.\n * @return {?{lat: number, lng: number}} The point, or null when either is not finite.\n */\nexport function finitePoint(lat, lng) {\n\t// `Number(null)` and `Number('')` are BOTH 0 — and 0 is finite. Passing them\n\t// through would plant a marker at (0, 0), in the Gulf of Guinea, for every object\n\t// whose coordinates are simply absent. Reject the empty shapes before coercing.\n\tif (!isNumeric(lat) || !isNumeric(lng)) {\n\t\treturn null\n\t}\n\n\tconst latNum = Number(lat)\n\tconst lngNum = Number(lng)\n\tif (!Number.isFinite(latNum) || !Number.isFinite(lngNum)) {\n\t\treturn null\n\t}\n\treturn { lat: latNum, lng: lngNum }\n}\n\n/**\n * Whether a value is a real number or a numeric string — excluding the empty shapes\n * (`null`, `undefined`, `''`, `[]`) that `Number()` silently turns into 0.\n *\n * @param {unknown} value The candidate.\n * @return {boolean} True when it can be safely coerced to a coordinate.\n */\nfunction isNumeric(value) {\n\tif (typeof value === 'number') {\n\t\treturn Number.isFinite(value)\n\t}\n\tif (typeof value !== 'string') {\n\t\treturn false\n\t}\n\treturn value.trim() !== '' && Number.isFinite(Number(value))\n}\n\n/**\n * Read a location out of whatever shape it was stored in.\n *\n * Accepts a Point geometry, a Feature, a FeatureCollection (first feature wins), or a\n * plain lat/lng object. Returns null for anything it cannot make sense of — callers\n * skip those rather than plotting a marker at (0, 0).\n *\n * @param {unknown} geo The raw value (typically `object['@self'].geo`).\n * @return {?{lat: number, lng: number}} The point, or null.\n */\nexport function parseGeoPoint(geo) {\n\tif (!geo || typeof geo !== 'object') {\n\t\treturn null\n\t}\n\n\t// FeatureCollection → first feature.\n\tif (geo.type === 'FeatureCollection' && Array.isArray(geo.features) && geo.features.length) {\n\t\treturn parseGeoPoint(geo.features[0])\n\t}\n\t// Feature → its geometry.\n\tif (geo.type === 'Feature' && geo.geometry) {\n\t\treturn parseGeoPoint(geo.geometry)\n\t}\n\t// Point geometry → coordinates are [lng, lat], NOT [lat, lng].\n\tif (geo.type === 'Point' && Array.isArray(geo.coordinates) && geo.coordinates.length >= 2) {\n\t\tconst [lng, lat] = geo.coordinates\n\t\treturn finitePoint(lat, lng)\n\t}\n\t// Plain lat/lng shapes.\n\treturn finitePoint(\n\t\tgeo.lat ?? geo.latitude,\n\t\tgeo.lng ?? geo.lon ?? geo.longitude,\n\t)\n}\n\n/**\n * Turn an OpenRegister object into a GeoJSON Point Feature, or null when it has no\n * usable location.\n *\n * Looks at `@self.geo` first (where the geo widget writes it). Falls back to plain\n * lat/lng fields on the object itself, so a schema that models coordinates as its own\n * properties still plots without having to migrate to `@self.geo`.\n *\n * @param {object} obj The OpenRegister object.\n * @param {object} [options] Options.\n * @param {string} [options.latField] Property holding latitude, for the fallback.\n * @param {string} [options.lngField] Property holding longitude, for the fallback.\n * @return {?object} A GeoJSON Feature whose `properties` is the object, or null.\n */\nexport function objectToGeoFeature(obj, options = {}) {\n\tif (!obj || typeof obj !== 'object') {\n\t\treturn null\n\t}\n\n\tconst self = obj['@self'] || {}\n\tlet point = parseGeoPoint(self.geo)\n\n\tif (!point) {\n\t\tconst { latField, lngField } = options\n\t\tif (latField && lngField) {\n\t\t\tpoint = finitePoint(obj[latField], obj[lngField])\n\t\t}\n\t}\n\tif (!point) {\n\t\treturn null\n\t}\n\n\treturn {\n\t\ttype: 'Feature',\n\t\tgeometry: { type: 'Point', coordinates: [point.lng, point.lat] },\n\t\tproperties: { ...obj },\n\t}\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA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,QAAQ,EAAE;AAC5B,GAAG,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,QAAQ,CAAC;AACnD,EAAE;AACF,CAAC;AACD,CAAC,IAAI,CAAC,KAAK,EAAE;AACb,EAAE,OAAO;AACT,CAAC;;AAED,CAAC,OAAO;AACR,EAAE,IAAI,EAAE,SAAS;AACjB,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE;AAClE,EAAE,UAAU,EAAE,EAAE,GAAG,GAAG,EAAE;AACxB;AACA;;"}
|
|
1
|
+
{"version":3,"file":"geo.js","sources":["../../../src/utils/geo.js"],"sourcesContent":["/**\n * SPDX-FileCopyrightText: 2026 Conduction B.V.\n * SPDX-License-Identifier: EUPL-1.2\n *\n * Reading an OpenRegister object's location.\n *\n * Objects store their location on `@self.geo` as a GeoJSON **Point** geometry\n * (`{ type: 'Point', coordinates: [lng, lat] }` — note GeoJSON is lng-first).\n * Reading is deliberately tolerant, because the value can arrive in several shapes\n * depending on who wrote it: a bare Point geometry, a Feature, a FeatureCollection,\n * or a plain `{lat, lng}` / `{latitude, longitude}` object.\n *\n * This lives here rather than inside a component because two surfaces need it —\n * CnObjectGeoWidget (one object, editable) and CnMapWidget (many objects, plotted).\n * Duplicating the parser would let them disagree about what a valid location is.\n */\n\n/**\n * Build a `{ lat, lng }` when both values are finite numbers, else null.\n *\n * Guards the whole module: a NaN or a string sneaking through here would surface as\n * an invisible marker or a Leaflet exception far from the cause.\n *\n * @param {unknown} lat Candidate latitude.\n * @param {unknown} lng Candidate longitude.\n * @return {?{lat: number, lng: number}} The point, or null when either is not finite.\n */\nexport function finitePoint(lat, lng) {\n\t// `Number(null)` and `Number('')` are BOTH 0 — and 0 is finite. Passing them\n\t// through would plant a marker at (0, 0), in the Gulf of Guinea, for every object\n\t// whose coordinates are simply absent. Reject the empty shapes before coercing.\n\tif (!isNumeric(lat) || !isNumeric(lng)) {\n\t\treturn null\n\t}\n\n\tconst latNum = Number(lat)\n\tconst lngNum = Number(lng)\n\tif (!Number.isFinite(latNum) || !Number.isFinite(lngNum)) {\n\t\treturn null\n\t}\n\treturn { lat: latNum, lng: lngNum }\n}\n\n/**\n * Whether a value is a real number or a numeric string — excluding the empty shapes\n * (`null`, `undefined`, `''`, `[]`) that `Number()` silently turns into 0.\n *\n * @param {unknown} value The candidate.\n * @return {boolean} True when it can be safely coerced to a coordinate.\n */\nfunction isNumeric(value) {\n\tif (typeof value === 'number') {\n\t\treturn Number.isFinite(value)\n\t}\n\tif (typeof value !== 'string') {\n\t\treturn false\n\t}\n\treturn value.trim() !== '' && Number.isFinite(Number(value))\n}\n\n/**\n * Read a location out of whatever shape it was stored in.\n *\n * Accepts a Point geometry, a Feature, a FeatureCollection (first feature wins), or a\n * plain lat/lng object. Returns null for anything it cannot make sense of — callers\n * skip those rather than plotting a marker at (0, 0).\n *\n * @param {unknown} geo The raw value (typically `object['@self'].geo`).\n * @return {?{lat: number, lng: number}} The point, or null.\n */\nexport function parseGeoPoint(geo) {\n\tif (!geo || typeof geo !== 'object') {\n\t\treturn null\n\t}\n\n\t// FeatureCollection → first feature.\n\tif (geo.type === 'FeatureCollection' && Array.isArray(geo.features) && geo.features.length) {\n\t\treturn parseGeoPoint(geo.features[0])\n\t}\n\t// Feature → its geometry.\n\tif (geo.type === 'Feature' && geo.geometry) {\n\t\treturn parseGeoPoint(geo.geometry)\n\t}\n\t// Point geometry → coordinates are [lng, lat], NOT [lat, lng].\n\tif (geo.type === 'Point' && Array.isArray(geo.coordinates) && geo.coordinates.length >= 2) {\n\t\tconst [lng, lat] = geo.coordinates\n\t\treturn finitePoint(lat, lng)\n\t}\n\t// Plain lat/lng shapes.\n\treturn finitePoint(\n\t\tgeo.lat ?? geo.latitude,\n\t\tgeo.lng ?? geo.lon ?? geo.longitude,\n\t)\n}\n\nconst GEOMETRY_TYPES = ['Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', 'MultiPolygon']\n\n/**\n * The GeoJSON geometry a property value holds: a geometry, or a Feature's\n * geometry. Returns null for anything else, so a point-shaped value falls\n * through to parseGeoPoint().\n *\n * @param {unknown} value The property value.\n * @return {?object} The geometry, or null.\n */\nexport function parseGeoGeometry(value) {\n\tif (!value || typeof value !== 'object') {\n\t\treturn null\n\t}\n\tconst geometry = value.type === 'Feature' ? value.geometry : value\n\tif (!geometry || !GEOMETRY_TYPES.includes(geometry.type) || !Array.isArray(geometry.coordinates)) {\n\t\treturn null\n\t}\n\tif (geometry.type === 'Point') {\n\t\tconst point = parseGeoPoint(geometry)\n\t\treturn point ? { type: 'Point', coordinates: [point.lng, point.lat] } : null\n\t}\n\treturn geometry.coordinates.length > 0 ? geometry : null\n}\n\n/**\n * Turn an OpenRegister object into a GeoJSON Feature, or null when it has no\n * usable location.\n *\n * With `geoProperty` set, that property is read first: a GeoJSON geometry of any\n * type (point, line, polygon or a multi-geometry), a Feature, or a lat/lng value.\n * Otherwise, or when it is empty, `@self.geo` is read (where the geo widget writes\n * it), and then plain lat/lng fields on the object itself, so a schema that models\n * coordinates as its own properties still plots.\n *\n * @param {object} obj The OpenRegister object.\n * @param {object} [options] Options.\n * @param {string} [options.geoProperty] Property holding the object's geometry.\n * @param {string} [options.latField] Property holding latitude, for the fallback.\n * @param {string} [options.lngField] Property holding longitude, for the fallback.\n * @return {?object} A GeoJSON Feature whose `properties` is the object, or null.\n */\nexport function objectToGeoFeature(obj, options = {}) {\n\tif (!obj || typeof obj !== 'object') {\n\t\treturn null\n\t}\n\n\tconst { geoProperty, latField, lngField } = options\n\tif (geoProperty) {\n\t\tconst value = obj[geoProperty]\n\t\tconst geometry = parseGeoGeometry(value)\n\t\tconst point = geometry ? null : parseGeoPoint(value)\n\t\tif (geometry || point) {\n\t\t\treturn {\n\t\t\t\ttype: 'Feature',\n\t\t\t\tgeometry: geometry || { type: 'Point', coordinates: [point.lng, point.lat] },\n\t\t\t\tproperties: { ...obj },\n\t\t\t}\n\t\t}\n\t}\n\n\tconst self = obj['@self'] || {}\n\tlet point = parseGeoPoint(self.geo)\n\n\tif (!point && latField && lngField) {\n\t\tpoint = finitePoint(obj[latField], obj[lngField])\n\t}\n\tif (!point) {\n\t\treturn null\n\t}\n\n\treturn {\n\t\ttype: 'Feature',\n\t\tgeometry: { type: 'Point', coordinates: [point.lng, point.lat] },\n\t\tproperties: { ...obj },\n\t}\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE;AACtC;AACA;AACA;AACA,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE;AACzC,EAAE,OAAO;AACT,CAAC;;AAED,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG;AAC1B,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG;AAC1B,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;AAC3D,EAAE,OAAO;AACT,CAAC;AACD,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;AAClC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,SAAS,CAAC,KAAK,EAAE;AAC1B,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AAChC,EAAE,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK;AAC9B,CAAC;AACD,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AAChC,EAAE,OAAO;AACT,CAAC;AACD,CAAC,OAAO,KAA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