ochre-sdk 1.3.25 → 1.3.27
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/categories.d.mts +56 -56
- package/dist/categories.mjs +39 -39
- package/dist/constants.d.mts +8 -8
- package/dist/constants.mjs +6 -6
- package/dist/errors.d.mts +12 -12
- package/dist/errors.mjs +22 -23
- package/dist/fetchers/container-items.d.mts +28 -28
- package/dist/fetchers/container-items.mjs +27 -27
- package/dist/fetchers/gallery.d.mts +13 -13
- package/dist/fetchers/gallery.mjs +2 -2
- package/dist/fetchers/item-children.d.mts +12 -12
- package/dist/fetchers/item-children.mjs +2 -2
- package/dist/fetchers/item-links.d.mts +10 -10
- package/dist/fetchers/item-links.mjs +6 -6
- package/dist/fetchers/item-locations.d.mts +20 -20
- package/dist/fetchers/item-locations.mjs +3 -3
- package/dist/fetchers/item-ocr-data.d.mts +23 -23
- package/dist/fetchers/item-ocr-data.mjs +44 -44
- package/dist/fetchers/item.d.mts +23 -18
- package/dist/fetchers/item.mjs +15 -15
- package/dist/fetchers/map-layers.d.mts +15 -15
- package/dist/fetchers/map-layers.mjs +12 -11
- package/dist/fetchers/request.d.mts +40 -40
- package/dist/fetchers/request.mjs +37 -37
- package/dist/fetchers/set/items.d.mts +15 -15
- package/dist/fetchers/set/items.mjs +1 -1
- package/dist/fetchers/set/property-values.d.mts +16 -16
- package/dist/fetchers/set/property-values.mjs +43 -43
- package/dist/fetchers/tree/items.d.mts +27 -27
- package/dist/fetchers/tree/items.mjs +1 -1
- package/dist/fetchers/website-metadata.d.mts +4 -4
- package/dist/fetchers/website-metadata.mjs +9 -9
- package/dist/fetchers/website.d.mts +10 -10
- package/dist/fetchers/website.mjs +12 -12
- package/dist/getters.d.mts +83 -83
- package/dist/getters.mjs +74 -74
- package/dist/helpers.d.mts +4 -4
- package/dist/helpers.mjs +7 -7
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +5 -5
- package/dist/languages.d.mts +58 -58
- package/dist/languages.mjs +21 -21
- package/dist/ocr.d.mts +27 -27
- package/dist/ocr.mjs +29 -29
- package/dist/parsers/helpers.d.mts +23 -23
- package/dist/parsers/helpers.mjs +8 -8
- package/dist/parsers/index.d.mts +2 -2
- package/dist/parsers/index.mjs +15 -15
- package/dist/parsers/languages.d.mts +49 -49
- package/dist/parsers/languages.mjs +49 -49
- package/dist/parsers/multilingual.d.mts +174 -174
- package/dist/parsers/multilingual.mjs +146 -146
- package/dist/parsers/partial-date.d.mts +12 -12
- package/dist/parsers/partial-date.mjs +11 -11
- package/dist/parsers/property-token.d.mts +20 -20
- package/dist/parsers/property-token.mjs +16 -16
- package/dist/parsers/string.d.mts +33 -33
- package/dist/parsers/string.mjs +62 -64
- package/dist/parsers/website/bounds.d.mts +6 -6
- package/dist/parsers/website/bounds.mjs +5 -5
- package/dist/parsers/website/components.d.mts +46 -31
- package/dist/parsers/website/components.mjs +84 -51
- package/dist/parsers/website/index.d.mts +2 -2
- package/dist/parsers/website/index.mjs +45 -48
- package/dist/parsers/website/links.d.mts +24 -24
- package/dist/parsers/website/links.mjs +18 -18
- package/dist/parsers/website/messages.d.mts +16 -16
- package/dist/parsers/website/messages.mjs +14 -14
- package/dist/parsers/website/options.d.mts +1 -1
- package/dist/parsers/website/properties.d.mts +17 -8
- package/dist/parsers/website/properties.mjs +31 -10
- package/dist/parsers/website/reader.d.mts +55 -47
- package/dist/parsers/website/reader.mjs +66 -51
- package/dist/parsers/website/slug.d.mts +50 -50
- package/dist/parsers/website/slug.mjs +36 -36
- package/dist/parsers/website/styles.d.mts +18 -18
- package/dist/parsers/website/styles.mjs +19 -19
- package/dist/parsers/website/walk.d.mts +46 -46
- package/dist/parsers/website/walk.mjs +34 -34
- package/dist/query.d.mts +63 -63
- package/dist/query.mjs +137 -140
- package/dist/reflection.d.mts +51 -51
- package/dist/reflection.mjs +45 -45
- package/dist/schemas.d.mts +44 -44
- package/dist/schemas.mjs +50 -50
- package/dist/types/index.d.mts +192 -192
- package/dist/types/utilities.d.mts +5 -5
- package/dist/types/website.d.mts +74 -62
- package/dist/xml/dates.d.mts +9 -9
- package/dist/xml/dates.mjs +9 -9
- package/dist/xml/metadata.d.mts +14 -14
- package/dist/xml/metadata.mjs +18 -18
- package/dist/xml/schemas.mjs +24 -24
- package/dist/xml/types.d.mts +9 -9
- package/dist/xquery.d.mts +49 -49
- package/dist/xquery.mjs +50 -50
- package/package.json +10 -10
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { normalizeItemCategory } from "../../categories.mjs";
|
|
2
|
-
import { collectionVariantSchema, componentSchema } from "../../schemas.mjs";
|
|
3
|
-
import { parseXMLContent, transformPermanentIdentificationUrlToItemLink } from "../string.mjs";
|
|
4
2
|
import { parseStringContent } from "../helpers.mjs";
|
|
5
3
|
import { parseBibliographyList, parseIdentification, parseLinks, parseSimplifiedProperties } from "../index.mjs";
|
|
4
|
+
import { parseXMLContent, transformPermanentIdentificationUrlToItemLink } from "../string.mjs";
|
|
6
5
|
import { parseBounds } from "./bounds.mjs";
|
|
7
6
|
import { findWebsiteLink, findWebsiteLinkByCategories, getWebsiteLinks, parseWebsiteLinkTarget, webImageFromLink } from "./links.mjs";
|
|
8
7
|
import { formatComponentError, formatXMLWebsiteResourceMetadata } from "./messages.mjs";
|
|
@@ -10,11 +9,12 @@ import { parseWebsiteOptions } from "./options.mjs";
|
|
|
10
9
|
import { websitePresentationReader } from "./reader.mjs";
|
|
11
10
|
import { parseResponsiveCssStyles } from "./styles.mjs";
|
|
12
11
|
import { normalizeWebsiteResources } from "./walk.mjs";
|
|
12
|
+
import { collectionVariantSchema, componentSchema } from "../../schemas.mjs";
|
|
13
13
|
import * as v from "valibot";
|
|
14
14
|
// src/parsers/website/components.ts
|
|
15
15
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
Default values for a collection's display properties, shared between the
|
|
17
|
+
"collection" component and the "query" component's collection overrides.
|
|
18
18
|
*/
|
|
19
19
|
const COLLECTION_PROPERTY_DEFAULTS = {
|
|
20
20
|
variants: ["slide"],
|
|
@@ -28,9 +28,9 @@ const COLLECTION_PROPERTY_DEFAULTS = {
|
|
|
28
28
|
isInteractive: true
|
|
29
29
|
};
|
|
30
30
|
/**
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
Default values for a collection's image display properties, merged separately
|
|
32
|
+
from {@link COLLECTION_PROPERTY_DEFAULTS} because overrides of the nested
|
|
33
|
+
"image" object are themselves partial.
|
|
34
34
|
*/
|
|
35
35
|
const COLLECTION_IMAGE_DEFAULTS = {
|
|
36
36
|
layout: "start",
|
|
@@ -39,20 +39,20 @@ const COLLECTION_IMAGE_DEFAULTS = {
|
|
|
39
39
|
isPlaceholderDisplayed: true
|
|
40
40
|
};
|
|
41
41
|
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
Reads every "variant" value a collection accepts, in OCHRE order and without
|
|
43
|
+
duplicates, skipping values the SDK does not know, so the first entry is the
|
|
44
|
+
variant the collection opens with. Returns `null` when none are set.
|
|
45
45
|
*/
|
|
46
46
|
function parseCollectionVariants(reader) {
|
|
47
47
|
const [defaultVariant, ...otherVariants] = [...new Set(reader.stringValues("variant").filter((value) => v.is(collectionVariantSchema, value)))];
|
|
48
48
|
return defaultVariant == null ? null : [defaultVariant, ...otherVariants];
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
Reads the collection display properties explicitly set on a reader, omitting
|
|
52
|
+
any that are unset. The "collection" component merges these over
|
|
53
|
+
{@link COLLECTION_PROPERTY_DEFAULTS} and {@link COLLECTION_IMAGE_DEFAULTS},
|
|
54
|
+
while the "query" component uses them as partial overrides for its embedded
|
|
55
|
+
collection.
|
|
56
56
|
*/
|
|
57
57
|
function parseCollectionPropertyOverrides(reader) {
|
|
58
58
|
const overrides = {};
|
|
@@ -86,20 +86,22 @@ function parseCollectionPropertyOverrides(reader) {
|
|
|
86
86
|
} : overrides;
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
Parses the "use-property" values defining which item properties a collection
|
|
90
|
+
displays, returning `null` when none are set.
|
|
91
91
|
*/
|
|
92
92
|
function parseCollectionDisplayedProperties(reader) {
|
|
93
93
|
const property = reader.property("use-property");
|
|
94
94
|
if (property == null) return null;
|
|
95
|
-
|
|
95
|
+
const displayedProperties = [];
|
|
96
|
+
for (const value of property.values) if (value.uuid !== null) displayedProperties.push({
|
|
96
97
|
uuid: value.uuid,
|
|
97
98
|
label: value.label
|
|
98
|
-
}
|
|
99
|
+
});
|
|
100
|
+
return displayedProperties;
|
|
99
101
|
}
|
|
100
102
|
/**
|
|
101
|
-
|
|
102
|
-
|
|
103
|
+
Parses the "customize-special" "relations" properties, each pairing the
|
|
104
|
+
property variables it links with "use-property" with a display "variant".
|
|
103
105
|
*/
|
|
104
106
|
function parseCollectionRelations(reader) {
|
|
105
107
|
const relations = [];
|
|
@@ -114,6 +116,33 @@ function parseCollectionRelations(reader) {
|
|
|
114
116
|
}
|
|
115
117
|
return relations;
|
|
116
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
Reads the "customize-special" "element" properties of a website, each
|
|
121
|
+
holding "component" properties whose settings every element of that
|
|
122
|
+
component starts from
|
|
123
|
+
|
|
124
|
+
@param websiteReader - Reader over the website's "presentation" properties
|
|
125
|
+
@param parent - The defaults of the enclosing website, which these extend
|
|
126
|
+
@returns The component defaults in effect for the website's elements
|
|
127
|
+
*/
|
|
128
|
+
function parseComponentDefaults(websiteReader, parent) {
|
|
129
|
+
const elementReaders = websiteReader.nestedAllByValue("customize-special", "element");
|
|
130
|
+
if (elementReaders.length === 0) return parent;
|
|
131
|
+
const defaults = { ...parent };
|
|
132
|
+
for (const component of componentSchema.options) for (const elementReader of elementReaders) {
|
|
133
|
+
const componentProperties = elementReader.propertyByValue("component", component)?.properties;
|
|
134
|
+
if (componentProperties != null && componentProperties.length > 0) {
|
|
135
|
+
defaults[component] = [componentProperties, ...parent[component] ?? []];
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return defaults;
|
|
140
|
+
}
|
|
141
|
+
function componentDefaultsReader(layers) {
|
|
142
|
+
let reader = null;
|
|
143
|
+
for (const layer of layers.toReversed()) reader = websitePresentationReader(layer, reader);
|
|
144
|
+
return reader;
|
|
145
|
+
}
|
|
117
146
|
const THREE_D_VIEWER_COMPONENT_DEFAULTS = {
|
|
118
147
|
isInteractive: true,
|
|
119
148
|
isControlsDisplayed: true
|
|
@@ -238,7 +267,7 @@ function parseBibliographyComponent(parameters) {
|
|
|
238
267
|
};
|
|
239
268
|
}
|
|
240
269
|
function parseButtonComponent(parameters) {
|
|
241
|
-
const { componentProperty, componentReader, elementResource, websiteLinks, options, pageSlugs } = parameters;
|
|
270
|
+
const { componentProperty, componentReader, elementResource, websiteLinks, options, pageSlugs, componentDefaults } = parameters;
|
|
242
271
|
const variant = componentReader.valueOr("variant", "default");
|
|
243
272
|
let isExternal = false;
|
|
244
273
|
let isRelative = false;
|
|
@@ -259,7 +288,10 @@ function parseButtonComponent(parameters) {
|
|
|
259
288
|
const childReader = websitePresentationReader(parseSimplifiedProperties(childResource.properties, options));
|
|
260
289
|
if (childReader.value("presentation") !== "element") continue;
|
|
261
290
|
if (childReader.nestedByValue("presentation", "element").value("component") === "button") continue;
|
|
262
|
-
elements.push(parseWebElement(childResource, options,
|
|
291
|
+
elements.push(parseWebElement(childResource, options, {
|
|
292
|
+
pageSlugs,
|
|
293
|
+
componentDefaults
|
|
294
|
+
}));
|
|
263
295
|
}
|
|
264
296
|
return {
|
|
265
297
|
component: "button",
|
|
@@ -362,10 +394,10 @@ function parseIiifViewerComponent(parameters) {
|
|
|
362
394
|
};
|
|
363
395
|
}
|
|
364
396
|
/**
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
397
|
+
The defaults an image component falls back to
|
|
398
|
+
|
|
399
|
+
Annotated rather than `as const`, so each field keeps the full union its
|
|
400
|
+
type allows and the parser can still compare against the other members.
|
|
369
401
|
*/
|
|
370
402
|
const IMAGE_COMPONENT_DEFAULTS = {
|
|
371
403
|
imageQuality: "high",
|
|
@@ -642,19 +674,19 @@ function parseVideoComponent(parameters) {
|
|
|
642
674
|
};
|
|
643
675
|
}
|
|
644
676
|
/**
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
677
|
+
Parses raw web element properties into a standardized WebElementComponent structure
|
|
678
|
+
|
|
679
|
+
@param componentProperty - Raw component property data in OCHRE format
|
|
680
|
+
@param elementResource - Raw element resource data in OCHRE format
|
|
681
|
+
@returns Parsed WebElementComponent object
|
|
650
682
|
*/
|
|
651
683
|
/**
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
684
|
+
The parser for each web element component, keyed by its OCHRE component name
|
|
685
|
+
|
|
686
|
+
Every component parser takes the same {@link WebElementComponentParameters}
|
|
687
|
+
bag, so this is a table rather than a `switch`: a missing component is a type
|
|
688
|
+
error here instead of a runtime throw, and each parser can be exercised on
|
|
689
|
+
its own.
|
|
658
690
|
*/
|
|
659
691
|
const WEB_ELEMENT_COMPONENT_PARSERS = {
|
|
660
692
|
"3d-viewer": parse3dViewerComponent,
|
|
@@ -679,18 +711,19 @@ const WEB_ELEMENT_COMPONENT_PARSERS = {
|
|
|
679
711
|
timeline: parseTimelineComponent,
|
|
680
712
|
video: parseVideoComponent
|
|
681
713
|
};
|
|
682
|
-
function parseWebElementProperties(componentProperty, elementResource, options,
|
|
714
|
+
function parseWebElementProperties(componentProperty, elementResource, options, context) {
|
|
683
715
|
const unparsedComponentName = componentProperty.values[0].content;
|
|
684
716
|
const componentNameResult = v.safeParse(componentSchema, unparsedComponentName);
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
return
|
|
717
|
+
if (!componentNameResult.success) throw new Error(`Invalid or non-implemented component name \u{201C}${unparsedComponentName.toString()}\u{201D} for the following element: \u{201C}${parseStringContent(elementResource.identification.label, options)}\u{201D}`);
|
|
718
|
+
const component = componentNameResult.output;
|
|
719
|
+
return WEB_ELEMENT_COMPONENT_PARSERS[component]({
|
|
688
720
|
componentProperty,
|
|
689
|
-
componentReader: websitePresentationReader(componentProperty.properties),
|
|
721
|
+
componentReader: websitePresentationReader(componentProperty.properties, componentDefaultsReader(context.componentDefaults[component] ?? [])),
|
|
690
722
|
elementResource,
|
|
691
723
|
websiteLinks: parseLinks(elementResource.links, options),
|
|
692
724
|
options,
|
|
693
|
-
pageSlugs
|
|
725
|
+
pageSlugs: context.pageSlugs,
|
|
726
|
+
componentDefaults: context.componentDefaults
|
|
694
727
|
});
|
|
695
728
|
}
|
|
696
729
|
function parseWebTitle(properties, identification, overrides) {
|
|
@@ -719,16 +752,16 @@ function parseWebTitle(properties, identification, overrides) {
|
|
|
719
752
|
return title;
|
|
720
753
|
}
|
|
721
754
|
/**
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
755
|
+
Parses raw web element data into a standardized WebElement structure
|
|
756
|
+
|
|
757
|
+
@param elementResource - Raw element resource data in OCHRE format
|
|
758
|
+
@returns Parsed WebElement object
|
|
726
759
|
*/
|
|
727
|
-
function parseWebElement(elementResource, options,
|
|
760
|
+
function parseWebElement(elementResource, options, context) {
|
|
728
761
|
const identification = parseIdentification(elementResource.identification, options);
|
|
729
762
|
const elementProperties = parseSimplifiedProperties(elementResource.properties, options);
|
|
730
763
|
const presentationProperty = websitePresentationReader(elementProperties).requiredProperty("presentation", `Presentation property not found for element (${formatXMLWebsiteResourceMetadata(elementResource)})`);
|
|
731
|
-
const properties = parseWebElementProperties(websitePresentationReader(presentationProperty.properties).requiredProperty("component", `Component property not found for element (${formatXMLWebsiteResourceMetadata(elementResource)})`), elementResource, options,
|
|
764
|
+
const properties = parseWebElementProperties(websitePresentationReader(presentationProperty.properties).requiredProperty("component", `Component property not found for element (${formatXMLWebsiteResourceMetadata(elementResource)})`), elementResource, options, context);
|
|
732
765
|
const cssStyles = parseResponsiveCssStyles(elementProperties);
|
|
733
766
|
const title = parseWebTitle(elementProperties, identification, {
|
|
734
767
|
isNameDisplayed: [
|
|
@@ -747,4 +780,4 @@ function parseWebElement(elementResource, options, pageSlugs) {
|
|
|
747
780
|
...properties
|
|
748
781
|
};
|
|
749
782
|
}
|
|
750
|
-
export { WEB_ELEMENT_COMPONENT_PARSERS, parseWebElement, parseWebTitle };
|
|
783
|
+
export { WEB_ELEMENT_COMPONENT_PARSERS, parseComponentDefaults, parseWebElement, parseWebTitle };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { ParserOptions } from "../helpers.mjs";
|
|
1
2
|
import { Webpage, Website } from "../../types/website.mjs";
|
|
2
3
|
import { XMLWebsiteData, XMLWebsiteResource } from "../../xml/types.mjs";
|
|
3
|
-
import { ParserOptions } from "../helpers.mjs";
|
|
4
4
|
export declare function parseWebpageView<T extends ReadonlyArray<string>>(view: {
|
|
5
5
|
resource?: Array<XMLWebsiteResource>;
|
|
6
|
-
} | undefined, options: ParserOptions<T>, context: Pick<Website<T>, "belongsTo" | "metadata">): Webpage<T> | null;
|
|
6
|
+
} | undefined, options: ParserOptions<T>, context: Pick<Website<T>, "belongsTo" | "metadata">, website: Pick<Website<T>, "properties"> | null): Webpage<T> | null;
|
|
7
7
|
export declare function parseWebsite<const T extends ReadonlyArray<string> = ReadonlyArray<string>>(data: XMLWebsiteData, options?: {
|
|
8
8
|
languages?: T;
|
|
9
9
|
}): Website<T>;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { cleanObject, parseLicense, parseRequiredContentLike, parseStringContent } from "../helpers.mjs";
|
|
2
|
-
import { parseMetadataLanguages, resolveDefaultLanguage, resolveLanguages } from "../languages.mjs";
|
|
3
2
|
import { parseIdentification, parseLinks, parseMetadata, parsePersonList, parseSimplifiedProperties } from "../index.mjs";
|
|
3
|
+
import { parseMetadataLanguages, resolveDefaultLanguage, resolveLanguages } from "../languages.mjs";
|
|
4
|
+
import { parseComponentDefaults, parseWebElement, parseWebTitle } from "./components.mjs";
|
|
4
5
|
import { findWebsiteLink, parseWebsiteLinkTarget, webImageFromLink } from "./links.mjs";
|
|
5
6
|
import { formatXMLWebsiteResourceMetadata } from "./messages.mjs";
|
|
7
|
+
import { WEBPAGE_PROPERTY_LABELS, parseWebsiteProperties, resolveWebpageSettings } from "./properties.mjs";
|
|
6
8
|
import { websitePresentationReader } from "./reader.mjs";
|
|
7
|
-
import { emptyResponsiveStyles, parseResponsiveCssStyles } from "./styles.mjs";
|
|
8
9
|
import { cleanWebsitePageSlug } from "./slug.mjs";
|
|
10
|
+
import { emptyResponsiveStyles, parseResponsiveCssStyles } from "./styles.mjs";
|
|
9
11
|
import { collectWebsitePageSlugs, normalizeWebsiteResources, readWebsitePages } from "./walk.mjs";
|
|
10
|
-
import { parseWebElement, parseWebTitle } from "./components.mjs";
|
|
11
|
-
import { parseWebsiteProperties } from "./properties.mjs";
|
|
12
12
|
// src/parsers/website/index.ts
|
|
13
13
|
function isSidebarResource(resource, options) {
|
|
14
14
|
const resourceProperties = parseSimplifiedProperties(resource.properties, options);
|
|
@@ -23,7 +23,7 @@ function parseWebBlockItems(resources, options, context) {
|
|
|
23
23
|
if (resourceType === null) continue;
|
|
24
24
|
switch (resourceType) {
|
|
25
25
|
case "element":
|
|
26
|
-
items.push(parseWebElement(resource, options, context
|
|
26
|
+
items.push(parseWebElement(resource, options, context));
|
|
27
27
|
break;
|
|
28
28
|
case "block": {
|
|
29
29
|
const block = parseWebBlock(resource, options, context);
|
|
@@ -35,7 +35,7 @@ function parseWebBlockItems(resources, options, context) {
|
|
|
35
35
|
return items;
|
|
36
36
|
}
|
|
37
37
|
function parseWebpageRedirect(redirectValue, context) {
|
|
38
|
-
const redirectTarget = parseWebsiteLinkTarget(redirectValue, context.
|
|
38
|
+
const redirectTarget = parseWebsiteLinkTarget(redirectValue, context.pageSlugs);
|
|
39
39
|
if (redirectTarget != null) {
|
|
40
40
|
if (redirectValue?.href == null && redirectValue?.uuid != null) return {
|
|
41
41
|
type: "page",
|
|
@@ -55,7 +55,7 @@ function parseWebpageRedirect(redirectValue, context) {
|
|
|
55
55
|
};
|
|
56
56
|
return null;
|
|
57
57
|
}
|
|
58
|
-
function createWebpage(resource, slug, options) {
|
|
58
|
+
function createWebpage(resource, slug, options, context) {
|
|
59
59
|
return {
|
|
60
60
|
uuid: resource.uuid,
|
|
61
61
|
type: "page",
|
|
@@ -65,12 +65,8 @@ function createWebpage(resource, slug, options) {
|
|
|
65
65
|
items: [],
|
|
66
66
|
segments: [],
|
|
67
67
|
properties: {
|
|
68
|
-
|
|
69
|
-
variant: "default",
|
|
70
|
-
isBreadcrumbsDisplayed: false,
|
|
71
|
-
isSidebarDisplayed: true,
|
|
68
|
+
...resolveWebpageSettings(context.parentProperties?.page),
|
|
72
69
|
isDisplayedInNavbar: true,
|
|
73
|
-
isNavbarSearchBarDisplayed: true,
|
|
74
70
|
redirect: null,
|
|
75
71
|
backgroundImage: null,
|
|
76
72
|
sidebar: null,
|
|
@@ -80,16 +76,16 @@ function createWebpage(resource, slug, options) {
|
|
|
80
76
|
};
|
|
81
77
|
}
|
|
82
78
|
/**
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
79
|
+
Parses a walked page node into a standardized Webpage structure
|
|
80
|
+
|
|
81
|
+
@param page - The page node, with its slug and nesting already resolved
|
|
82
|
+
@returns Parsed Webpage object
|
|
87
83
|
*/
|
|
88
84
|
function parseWebpage(page, options, context) {
|
|
89
85
|
const webpageResource = page.resource;
|
|
90
86
|
const webpageProperties = parseSimplifiedProperties(webpageResource.properties, options);
|
|
91
87
|
const webpageReader = websitePresentationReader(webpageProperties);
|
|
92
|
-
const returnWebpage = createWebpage(webpageResource, page.slug, options);
|
|
88
|
+
const returnWebpage = createWebpage(webpageResource, page.slug, options, context);
|
|
93
89
|
const websiteLinks = parseLinks(webpageResource.links, options);
|
|
94
90
|
const imageLink = findWebsiteLink(websiteLinks, "resource", (link) => link.type === "image" || link.type === "IIIF");
|
|
95
91
|
const webpageResources = normalizeWebsiteResources(webpageResource.resource);
|
|
@@ -100,12 +96,8 @@ function parseWebpage(page, options, context) {
|
|
|
100
96
|
const pageReader = webpageReader.nestedByValue("presentation", "page");
|
|
101
97
|
if (pageReader.size > 0) {
|
|
102
98
|
pageReader.readAll(returnWebpage.properties, {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
variant: "variant",
|
|
106
|
-
isSidebarDisplayed: "sidebar-displayed",
|
|
107
|
-
isBreadcrumbsDisplayed: "breadcrumbs-displayed",
|
|
108
|
-
isNavbarSearchBarDisplayed: "navbar-search-bar-displayed"
|
|
99
|
+
...WEBPAGE_PROPERTY_LABELS,
|
|
100
|
+
isDisplayedInNavbar: "displayed-in-navbar"
|
|
109
101
|
});
|
|
110
102
|
returnWebpage.properties.redirect = parseWebpageRedirect(pageReader.valueNode("redirect-to"), context);
|
|
111
103
|
}
|
|
@@ -114,29 +106,31 @@ function parseWebpage(page, options, context) {
|
|
|
114
106
|
return returnWebpage;
|
|
115
107
|
}
|
|
116
108
|
/**
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
109
|
+
Parses walked page nodes into an array of Webpage objects
|
|
110
|
+
|
|
111
|
+
@param pages - The page nodes to parse
|
|
112
|
+
@returns Array of parsed Webpage objects
|
|
121
113
|
*/
|
|
122
114
|
function parseWebpages(pages, options, context) {
|
|
123
115
|
return Array.from(pages, (page) => parseWebpage(page, options, context));
|
|
124
116
|
}
|
|
125
|
-
function parseWebpageView(view, options, context) {
|
|
117
|
+
function parseWebpageView(view, options, context, website) {
|
|
126
118
|
const pages = readWebsitePages(view?.resource, options);
|
|
127
119
|
return parseWebpages(pages, options, {
|
|
128
120
|
...context,
|
|
129
|
-
|
|
121
|
+
pageSlugs: collectWebsitePageSlugs(pages, options),
|
|
122
|
+
parentProperties: website?.properties,
|
|
123
|
+
componentDefaults: website?.properties.componentDefaults ?? {}
|
|
130
124
|
})[0] ?? null;
|
|
131
125
|
}
|
|
132
126
|
function parseWebsiteSegments(segments, options, context) {
|
|
133
127
|
return Array.from(segments, (segment) => parseWebsiteTree(segment.tree, options, context, "segment", segment.slugPrefix));
|
|
134
128
|
}
|
|
135
129
|
/**
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
130
|
+
Parses raw sidebar data into a standardized Sidebar structure
|
|
131
|
+
|
|
132
|
+
@param resources - Array of raw sidebar resources in OCHRE format
|
|
133
|
+
@returns Parsed Sidebar object
|
|
140
134
|
*/
|
|
141
135
|
function parseSidebar(resources, options, context) {
|
|
142
136
|
const sidebarResource = resources.find((resource) => isSidebarResource(resource, options));
|
|
@@ -160,7 +154,7 @@ function parseSidebar(resources, options, context) {
|
|
|
160
154
|
return sidebar;
|
|
161
155
|
}
|
|
162
156
|
function parseWebAccordionItem(elementResource, childResources, options, context) {
|
|
163
|
-
const trigger = parseWebElement(elementResource, options, context
|
|
157
|
+
const trigger = parseWebElement(elementResource, options, context);
|
|
164
158
|
const items = parseWebBlockItems(childResources, options, context);
|
|
165
159
|
return {
|
|
166
160
|
uuid: trigger.uuid,
|
|
@@ -205,7 +199,7 @@ function parseAccordionAwareBlockItems(blockResources, options, context, isSuppo
|
|
|
205
199
|
case "element": {
|
|
206
200
|
const childResources = normalizeWebsiteResources(resource.resource);
|
|
207
201
|
const componentType = resourceReader.nestedByValue("presentation", "element").value("component");
|
|
208
|
-
blockItems.push(isSupportingAccordionItems && componentType === "text" && childResources.length > 0 ? parseWebAccordionItem(resource, childResources, options, context) : parseWebElement(resource, options, context
|
|
202
|
+
blockItems.push(isSupportingAccordionItems && componentType === "text" && childResources.length > 0 ? parseWebAccordionItem(resource, childResources, options, context) : parseWebElement(resource, options, context));
|
|
209
203
|
break;
|
|
210
204
|
}
|
|
211
205
|
case "block": {
|
|
@@ -218,10 +212,10 @@ function parseAccordionAwareBlockItems(blockResources, options, context, isSuppo
|
|
|
218
212
|
return blockItems;
|
|
219
213
|
}
|
|
220
214
|
/**
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
215
|
+
Parses raw block data into a standardized WebBlock structure
|
|
216
|
+
|
|
217
|
+
@param blockResource - Raw block resource data in OCHRE format
|
|
218
|
+
@returns Parsed WebBlock object
|
|
225
219
|
*/
|
|
226
220
|
function parseWebBlock(blockResource, options, context) {
|
|
227
221
|
const blockProperties = parseSimplifiedProperties(blockResource.properties, options);
|
|
@@ -281,7 +275,7 @@ function parseOakWebsite(resources, webpages, options, context) {
|
|
|
281
275
|
}
|
|
282
276
|
const component = websitePresentationReader(parseSimplifiedProperties(resource.properties, options)).nestedByValue("presentation", "element").value("component");
|
|
283
277
|
if (component !== "map" && component !== "collection") continue;
|
|
284
|
-
const element = parseWebElement(resource, options, context
|
|
278
|
+
const element = parseWebElement(resource, options, context);
|
|
285
279
|
if (element.component === "map") {
|
|
286
280
|
map ??= element;
|
|
287
281
|
continue;
|
|
@@ -289,7 +283,7 @@ function parseOakWebsite(resources, webpages, options, context) {
|
|
|
289
283
|
const resourceSlug = cleanWebsitePageSlug(resource.slug) ?? "";
|
|
290
284
|
const slug = resourceSlug === "" ? parseStringContent(resource.identification.abbreviation, options) : resourceSlug;
|
|
291
285
|
if (slug === "") throw new Error(`Slug not found for OAK collection (${formatXMLWebsiteResourceMetadata(resource)})`, { cause: resource });
|
|
292
|
-
const collectionPage = createWebpage(resource, slug, options);
|
|
286
|
+
const collectionPage = createWebpage(resource, slug, options, context);
|
|
293
287
|
collectionPage.items = [element];
|
|
294
288
|
collectionPage.properties.isDisplayedInNavbar = false;
|
|
295
289
|
items.push(collectionPage);
|
|
@@ -304,20 +298,22 @@ function parseWebsiteTree(websiteTree, options, context, type, slugPrefix) {
|
|
|
304
298
|
if (type === "website" && websiteTree.items?.resource == null) throw new Error(`Website pages not found (website uuid “${websiteTree.uuid}”)`, { cause: websiteTree });
|
|
305
299
|
const resources = normalizeWebsiteResources(websiteTree.items?.resource);
|
|
306
300
|
const pages = readWebsitePages(websiteTree.items?.resource, options, slugPrefix);
|
|
307
|
-
const
|
|
301
|
+
const websiteReader = websitePresentationReader(parseSimplifiedProperties(websiteTree.properties, options)).nested("presentation");
|
|
308
302
|
const treeContext = {
|
|
309
303
|
...context,
|
|
310
|
-
|
|
304
|
+
pageSlugs: context.pageSlugs ?? collectWebsitePageSlugs(pages, options),
|
|
305
|
+
componentDefaults: parseComponentDefaults(websiteReader, context.componentDefaults)
|
|
311
306
|
};
|
|
312
307
|
const sidebar = parseSidebar(resources, options, treeContext);
|
|
313
|
-
const properties = parseWebsiteProperties(
|
|
308
|
+
const properties = parseWebsiteProperties(websiteReader, websiteTree, sidebar, options, context.parentProperties ?? null, treeContext.componentDefaults);
|
|
314
309
|
const license = parseLicense(websiteTree.availability) ?? context.parentLicense ?? null;
|
|
315
|
-
const
|
|
310
|
+
const pageContext = {
|
|
316
311
|
...treeContext,
|
|
317
312
|
parentProperties: properties,
|
|
318
313
|
parentLicense: license
|
|
319
|
-
}
|
|
320
|
-
const
|
|
314
|
+
};
|
|
315
|
+
const webpages = parseWebpages(pages, options, pageContext);
|
|
316
|
+
const { items, oak } = type === "website" && properties.type === "oak" ? parseOakWebsite(resources, webpages, options, pageContext) : {
|
|
321
317
|
items: webpages,
|
|
322
318
|
oak: null
|
|
323
319
|
};
|
|
@@ -351,7 +347,8 @@ function parseWebsite(data, options) {
|
|
|
351
347
|
uuid: rawOchre.uuidBelongsTo,
|
|
352
348
|
abbreviation: rawOchre.belongsTo
|
|
353
349
|
},
|
|
354
|
-
metadata: parseMetadata(rawOchre, parserOptions, defaultLanguage)
|
|
350
|
+
metadata: parseMetadata(rawOchre, parserOptions, defaultLanguage),
|
|
351
|
+
componentDefaults: {}
|
|
355
352
|
}, "website");
|
|
356
353
|
const styleLabels = new Map((rawOchre.styleLabels?.styleLabel ?? []).map((styleLabel) => [styleLabel.valueUuid, parseRequiredContentLike(styleLabel, parserOptions)]));
|
|
357
354
|
for (const stylesheet of website.properties.options.stylesheets.properties) if (stylesheet.category === "propertyValue") stylesheet.label = styleLabels.get(stylesheet.uuid) ?? null;
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import { WebImage } from "../../types/website.mjs";
|
|
2
|
-
import { ItemLink, ItemLinkCategory, ItemLinks, PropertyValueContent } from "../../types/index.mjs";
|
|
3
1
|
import { WebsitePageSlugs } from "./slug.mjs";
|
|
2
|
+
import { ItemLink, ItemLinkCategory, ItemLinks, PropertyValueContent } from "../../types/index.mjs";
|
|
3
|
+
import { WebImage } from "../../types/website.mjs";
|
|
4
4
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
The link categories a website can point at
|
|
6
|
+
*/
|
|
7
7
|
export type WebsiteLinkCategory = Extract<ItemLinkCategory, "resource" | "set" | "tree">;
|
|
8
8
|
export declare function findWebsiteLink<U extends WebsiteLinkCategory, T extends ReadonlyArray<string>>(links: ItemLinks<T>, category: U, isMatch?: (link: ItemLink<U, T>) => boolean): ItemLink<U, T> | null;
|
|
9
9
|
export declare function findWebsiteLinkByCategories<U extends WebsiteLinkCategory, T extends ReadonlyArray<string>>(links: ItemLinks<T>, categories: ReadonlyArray<U>): ItemLink<U, T> | null;
|
|
10
10
|
export declare function getWebsiteLinks<U extends WebsiteLinkCategory, T extends ReadonlyArray<string>>(links: ItemLinks<T>, category: U): Array<ItemLink<U, T>>;
|
|
11
11
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
Where a "link-to", "navigate-to" or "redirect-to" property points
|
|
13
|
+
|
|
14
|
+
An external href is rewritten to an item route; anything else resolves
|
|
15
|
+
through the page slug map, so a link to a page inside a segment gets that
|
|
16
|
+
segment's full slug rather than the bare one OCHRE stores on the page.
|
|
17
|
+
@param value - The raw property value holding the target
|
|
18
|
+
@param pageSlugs - The website's resolved page slugs
|
|
19
|
+
@returns The target, or null when the property carries none
|
|
20
|
+
@internal
|
|
21
|
+
*/
|
|
22
22
|
export declare function parseWebsiteLinkTarget<T extends ReadonlyArray<string>>(value: PropertyValueContent<T> | null, pageSlugs: WebsitePageSlugs | undefined): string | null;
|
|
23
23
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
The image a link stands for
|
|
25
|
+
|
|
26
|
+
Built the same way wherever a website shows a linked image, so the six
|
|
27
|
+
fields and the fallbacks for a link OCHRE has no dimensions for are stated
|
|
28
|
+
once.
|
|
29
|
+
@param link - The resource link pointing at the image
|
|
30
|
+
@param quality - The quality the consumer should request
|
|
31
|
+
@returns The image
|
|
32
|
+
@internal
|
|
33
|
+
*/
|
|
34
34
|
export declare function webImageFromLink<T extends ReadonlyArray<string>>(link: ItemLinks<T>[number], quality: WebImage<T>["quality"]): WebImage<T>;
|
|
@@ -17,15 +17,15 @@ function getWebsiteLinks(links, category) {
|
|
|
17
17
|
return matchedLinks;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
Where a "link-to", "navigate-to" or "redirect-to" property points
|
|
21
|
+
|
|
22
|
+
An external href is rewritten to an item route; anything else resolves
|
|
23
|
+
through the page slug map, so a link to a page inside a segment gets that
|
|
24
|
+
segment's full slug rather than the bare one OCHRE stores on the page.
|
|
25
|
+
@param value - The raw property value holding the target
|
|
26
|
+
@param pageSlugs - The website's resolved page slugs
|
|
27
|
+
@returns The target, or null when the property carries none
|
|
28
|
+
@internal
|
|
29
29
|
*/
|
|
30
30
|
function parseWebsiteLinkTarget(value, pageSlugs) {
|
|
31
31
|
if (value == null) return null;
|
|
@@ -33,15 +33,15 @@ function parseWebsiteLinkTarget(value, pageSlugs) {
|
|
|
33
33
|
return (value.uuid == null ? void 0 : pageSlugs?.get(value.uuid)) ?? value.slug;
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
The image a link stands for
|
|
37
|
+
|
|
38
|
+
Built the same way wherever a website shows a linked image, so the six
|
|
39
|
+
fields and the fallbacks for a link OCHRE has no dimensions for are stated
|
|
40
|
+
once.
|
|
41
|
+
@param link - The resource link pointing at the image
|
|
42
|
+
@param quality - The quality the consumer should request
|
|
43
|
+
@returns The image
|
|
44
|
+
@internal
|
|
45
45
|
*/
|
|
46
46
|
function webImageFromLink(link, quality) {
|
|
47
47
|
const image = "image" in link ? link.image : null;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { WebElementComponent } from "../../types/website.mjs";
|
|
2
2
|
import { XMLWebsiteResource } from "../../xml/types.mjs";
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
Name a resource well enough to find it in OCHRE from an error message
|
|
5
|
+
|
|
6
|
+
Every throw in the website parser goes through here, because a UUID on its
|
|
7
|
+
own is not something anyone can look up quickly and a label on its own is
|
|
8
|
+
not unique.
|
|
9
|
+
@param resource - The resource the error is about
|
|
10
|
+
@returns A comma-separated description of the resource
|
|
11
|
+
@internal
|
|
12
|
+
*/
|
|
13
13
|
export declare function formatXMLWebsiteResourceMetadata(resource: XMLWebsiteResource): string;
|
|
14
14
|
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
Describe a component parser failure
|
|
16
|
+
@param message - What went wrong
|
|
17
|
+
@param componentName - The component being parsed
|
|
18
|
+
@param elementResource - The element the component belongs to
|
|
19
|
+
@returns The error message
|
|
20
|
+
@internal
|
|
21
|
+
*/
|
|
22
22
|
export declare function formatComponentError(message: string, componentName: WebElementComponent["component"] | undefined, elementResource: XMLWebsiteResource): string;
|