ochre-sdk 1.0.3 → 1.0.5
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 +1 -0
- package/dist/index.mjs +21 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1788,6 +1788,7 @@ function parseImageMapArea(area) {
|
|
|
1788
1788
|
publicationDateTime: area.publicationDateTime,
|
|
1789
1789
|
type: area.type,
|
|
1790
1790
|
title: area.title,
|
|
1791
|
+
slug: area.slug ?? null,
|
|
1791
1792
|
items: shape === "rectangle" ? [{
|
|
1792
1793
|
shape,
|
|
1793
1794
|
coords: [
|
|
@@ -2909,6 +2910,7 @@ const XMLImageMapArea = v.object({
|
|
|
2909
2910
|
publicationDateTime: customDateTime("XMLImageMapArea: publicationDateTime is not a valid datetime"),
|
|
2910
2911
|
type: v.string("XMLImageMapArea: type is string and required"),
|
|
2911
2912
|
title: v.string("XMLImageMapArea: title is string and required"),
|
|
2913
|
+
slug: v.optional(v.string("XMLImageMapArea: slug is string and optional")),
|
|
2912
2914
|
shape: v.picklist([
|
|
2913
2915
|
"rect",
|
|
2914
2916
|
"circle",
|
|
@@ -5939,10 +5941,23 @@ function parseResponsiveCssStyles(properties) {
|
|
|
5939
5941
|
* @returns Parsed bounds object
|
|
5940
5942
|
*/
|
|
5941
5943
|
function parseBounds(bounds) {
|
|
5942
|
-
const [southWest, northEast] = bounds.split(";").map((pair) => pair.split(",").map((coordinate) => Number.parseFloat(coordinate.trim())));
|
|
5944
|
+
const [southWest, northEast] = bounds.trim().startsWith("[") ? parseJsonBounds(bounds) : bounds.split(";").map((pair) => pair.split(",").map((coordinate) => Number.parseFloat(coordinate.trim())));
|
|
5943
5945
|
if (southWest?.length !== 2 || northEast?.length !== 2 || southWest.some((coordinate) => Number.isNaN(coordinate)) || northEast.some((coordinate) => Number.isNaN(coordinate))) throw new Error(`Invalid bounds: ${bounds}`);
|
|
5944
5946
|
return [[southWest[0], southWest[1]], [northEast[0], northEast[1]]];
|
|
5945
5947
|
}
|
|
5948
|
+
function parseJsonBounds(bounds) {
|
|
5949
|
+
let parsed;
|
|
5950
|
+
try {
|
|
5951
|
+
parsed = JSON.parse(bounds);
|
|
5952
|
+
} catch {
|
|
5953
|
+
throw new Error(`Invalid bounds: ${bounds}`);
|
|
5954
|
+
}
|
|
5955
|
+
if (!isNumberPairArray(parsed)) throw new Error(`Invalid bounds: ${bounds}`);
|
|
5956
|
+
return parsed;
|
|
5957
|
+
}
|
|
5958
|
+
function isNumberPairArray(value) {
|
|
5959
|
+
return Array.isArray(value) && value.every((pair) => Array.isArray(pair) && pair.every((coordinate) => typeof coordinate === "number"));
|
|
5960
|
+
}
|
|
5946
5961
|
/**
|
|
5947
5962
|
* Parses all context option arrays from an options object.
|
|
5948
5963
|
*
|
|
@@ -6656,7 +6671,11 @@ function parseWebsiteSegments(resources, context, options, slugPrefix) {
|
|
|
6656
6671
|
const segments = [];
|
|
6657
6672
|
for (const resource of resources ?? []) {
|
|
6658
6673
|
if (!("segments" in resource)) continue;
|
|
6659
|
-
for (const tree of resource.segments.tree)
|
|
6674
|
+
for (const tree of resource.segments.tree) {
|
|
6675
|
+
const segmentSlug = tree.identification.abbreviation == null ? null : parseStringContent(tree.identification.abbreviation, options);
|
|
6676
|
+
if (segmentSlug == null) throw new Error(`Slug not found for segment website (website uuid “${tree.uuid}”)`);
|
|
6677
|
+
segments.push(parseWebsiteTree(tree, context, "segment", options, prefixSlug(segmentSlug, slugPrefix)));
|
|
6678
|
+
}
|
|
6660
6679
|
}
|
|
6661
6680
|
return segments;
|
|
6662
6681
|
}
|