@digitalculture/ochre-sdk 0.14.7 → 0.14.8
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/index.d.mts +3 -1
- package/dist/index.mjs +41 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -162,7 +162,7 @@ type Link = {
|
|
|
162
162
|
type ImageMapArea = {
|
|
163
163
|
uuid: string;
|
|
164
164
|
publicationDateTime: Date | null;
|
|
165
|
-
|
|
165
|
+
category: string;
|
|
166
166
|
title: string;
|
|
167
167
|
shape: "rectangle" | "circle" | "polygon";
|
|
168
168
|
coords: Array<number>;
|
|
@@ -816,6 +816,8 @@ type WebElementComponent = {
|
|
|
816
816
|
component: "map";
|
|
817
817
|
mapId: string;
|
|
818
818
|
customBasemap: string | null;
|
|
819
|
+
initialBounds: [[number, number], [number, number]] | null;
|
|
820
|
+
maximumBounds: [[number, number], [number, number]] | null;
|
|
819
821
|
isControlsDisplayed: boolean;
|
|
820
822
|
isInteractive: boolean;
|
|
821
823
|
isClustered: boolean;
|
package/dist/index.mjs
CHANGED
|
@@ -151,6 +151,32 @@ const whitespaceSchema = z.string().transform((str) => str.split(" ")).pipe(z.ar
|
|
|
151
151
|
* @internal
|
|
152
152
|
*/
|
|
153
153
|
const emailSchema = z.email({ error: "Invalid email" });
|
|
154
|
+
/**
|
|
155
|
+
* Schema for parsing and validating a string in the format "[[number, number], [number, number]]"
|
|
156
|
+
* into an array with exactly two bounds
|
|
157
|
+
* @internal
|
|
158
|
+
*/
|
|
159
|
+
const boundsSchema = z.string().transform((str, ctx) => {
|
|
160
|
+
const trimmed = str.trim();
|
|
161
|
+
if (!trimmed.startsWith("[[") || !trimmed.endsWith("]]")) {
|
|
162
|
+
ctx.addIssue({
|
|
163
|
+
code: "invalid_format",
|
|
164
|
+
format: "string",
|
|
165
|
+
message: "String must start with '[[' and end with ']]'"
|
|
166
|
+
});
|
|
167
|
+
return z.NEVER;
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
return JSON.parse(trimmed);
|
|
171
|
+
} catch {
|
|
172
|
+
ctx.addIssue({
|
|
173
|
+
code: "invalid_format",
|
|
174
|
+
format: "string",
|
|
175
|
+
message: "Invalid JSON format"
|
|
176
|
+
});
|
|
177
|
+
return z.NEVER;
|
|
178
|
+
}
|
|
179
|
+
}).pipe(z.tuple([z.tuple([z.number(), z.number()]), z.tuple([z.number(), z.number()])], { message: "Must contain exactly 2 coordinate pairs" }));
|
|
154
180
|
|
|
155
181
|
//#endregion
|
|
156
182
|
//#region src/utils/getters.ts
|
|
@@ -1295,7 +1321,7 @@ function parseImageMap(imageMap) {
|
|
|
1295
1321
|
for (const area of imageMapAreasToParse) returnImageMap.area.push({
|
|
1296
1322
|
uuid: area.uuid,
|
|
1297
1323
|
publicationDateTime: area.publicationDateTime != null ? new Date(area.publicationDateTime) : null,
|
|
1298
|
-
|
|
1324
|
+
category: area.type,
|
|
1299
1325
|
title: parseFakeString(area.title),
|
|
1300
1326
|
shape: area.shape === "rect" ? "rectangle" : area.shape === "circle" ? "circle" : "polygon",
|
|
1301
1327
|
coords: area.coords.split(",").map((coord) => Number.parseInt(coord)),
|
|
@@ -1822,6 +1848,11 @@ function parseConcepts(concepts) {
|
|
|
1822
1848
|
for (const concept of conceptsToParse) returnConcepts.push(parseConcept(concept));
|
|
1823
1849
|
return returnConcepts;
|
|
1824
1850
|
}
|
|
1851
|
+
function parseBounds(bounds) {
|
|
1852
|
+
const result = boundsSchema.safeParse(bounds);
|
|
1853
|
+
if (!result.success) throw new Error(`Invalid bounds: ${result.error.message}`);
|
|
1854
|
+
return result.data;
|
|
1855
|
+
}
|
|
1825
1856
|
/**
|
|
1826
1857
|
* Parses raw web element properties into a standardized WebElementComponent structure
|
|
1827
1858
|
*
|
|
@@ -2193,6 +2224,12 @@ function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
2193
2224
|
let customBasemap = null;
|
|
2194
2225
|
const customBasemapProperty = getPropertyValueByLabel(componentProperty.properties, "custom-basemap");
|
|
2195
2226
|
if (customBasemapProperty !== null) customBasemap = customBasemapProperty;
|
|
2227
|
+
let initialBounds = null;
|
|
2228
|
+
const initialBoundsProperty = getPropertyValueByLabel(componentProperty.properties, "initial-bounds");
|
|
2229
|
+
if (initialBoundsProperty !== null) initialBounds = parseBounds(String(initialBoundsProperty));
|
|
2230
|
+
let maximumBounds = null;
|
|
2231
|
+
const maximumBoundsProperty = getPropertyValueByLabel(componentProperty.properties, "maximum-bounds");
|
|
2232
|
+
if (maximumBoundsProperty !== null) maximumBounds = parseBounds(String(maximumBoundsProperty));
|
|
2196
2233
|
let isControlsDisplayed = false;
|
|
2197
2234
|
const isControlsDisplayedProperty = getPropertyValueByLabel(componentProperty.properties, "controls-displayed");
|
|
2198
2235
|
if (isControlsDisplayedProperty !== null) isControlsDisplayed = isControlsDisplayedProperty === true;
|
|
@@ -2200,10 +2237,12 @@ function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
2200
2237
|
const isFullHeightProperty = getPropertyValueByLabel(componentProperty.properties, "is-full-height");
|
|
2201
2238
|
if (isFullHeightProperty !== null) isFullHeight = isFullHeightProperty === true;
|
|
2202
2239
|
properties.mapId = mapLink.uuid;
|
|
2240
|
+
properties.customBasemap = customBasemap;
|
|
2241
|
+
properties.initialBounds = initialBounds;
|
|
2242
|
+
properties.maximumBounds = maximumBounds;
|
|
2203
2243
|
properties.isInteractive = isInteractive;
|
|
2204
2244
|
properties.isClustered = isClustered;
|
|
2205
2245
|
properties.isUsingPins = isUsingPins;
|
|
2206
|
-
properties.customBasemap = customBasemap;
|
|
2207
2246
|
properties.isControlsDisplayed = isControlsDisplayed;
|
|
2208
2247
|
properties.isFullHeight = isFullHeight;
|
|
2209
2248
|
break;
|
package/package.json
CHANGED