ochre-sdk 1.3.25 → 1.3.26
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 +14 -14
- package/dist/fetchers/item.mjs +14 -14
- 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 +50 -31
- package/dist/parsers/website/components.mjs +79 -51
- package/dist/parsers/website/index.d.mts +1 -1
- package/dist/parsers/website/index.mjs +43 -47
- 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 +22 -10
- package/dist/parsers/website/reader.d.mts +55 -46
- package/dist/parsers/website/reader.mjs +64 -46
- 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 +67 -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,28 @@ 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 = new Map(parent);
|
|
132
|
+
for (const component of componentSchema.options) for (const elementReader of elementReaders) {
|
|
133
|
+
const componentReader = elementReader.nestedByValue("component", component);
|
|
134
|
+
if (componentReader.size > 0) {
|
|
135
|
+
defaults.set(component, componentReader.withFallback(parent.get(component) ?? null));
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return defaults;
|
|
140
|
+
}
|
|
117
141
|
const THREE_D_VIEWER_COMPONENT_DEFAULTS = {
|
|
118
142
|
isInteractive: true,
|
|
119
143
|
isControlsDisplayed: true
|
|
@@ -238,7 +262,7 @@ function parseBibliographyComponent(parameters) {
|
|
|
238
262
|
};
|
|
239
263
|
}
|
|
240
264
|
function parseButtonComponent(parameters) {
|
|
241
|
-
const { componentProperty, componentReader, elementResource, websiteLinks, options, pageSlugs } = parameters;
|
|
265
|
+
const { componentProperty, componentReader, elementResource, websiteLinks, options, pageSlugs, componentDefaults } = parameters;
|
|
242
266
|
const variant = componentReader.valueOr("variant", "default");
|
|
243
267
|
let isExternal = false;
|
|
244
268
|
let isRelative = false;
|
|
@@ -259,7 +283,10 @@ function parseButtonComponent(parameters) {
|
|
|
259
283
|
const childReader = websitePresentationReader(parseSimplifiedProperties(childResource.properties, options));
|
|
260
284
|
if (childReader.value("presentation") !== "element") continue;
|
|
261
285
|
if (childReader.nestedByValue("presentation", "element").value("component") === "button") continue;
|
|
262
|
-
elements.push(parseWebElement(childResource, options,
|
|
286
|
+
elements.push(parseWebElement(childResource, options, {
|
|
287
|
+
pageSlugs,
|
|
288
|
+
componentDefaults
|
|
289
|
+
}));
|
|
263
290
|
}
|
|
264
291
|
return {
|
|
265
292
|
component: "button",
|
|
@@ -362,10 +389,10 @@ function parseIiifViewerComponent(parameters) {
|
|
|
362
389
|
};
|
|
363
390
|
}
|
|
364
391
|
/**
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
392
|
+
The defaults an image component falls back to
|
|
393
|
+
|
|
394
|
+
Annotated rather than `as const`, so each field keeps the full union its
|
|
395
|
+
type allows and the parser can still compare against the other members.
|
|
369
396
|
*/
|
|
370
397
|
const IMAGE_COMPONENT_DEFAULTS = {
|
|
371
398
|
imageQuality: "high",
|
|
@@ -642,19 +669,19 @@ function parseVideoComponent(parameters) {
|
|
|
642
669
|
};
|
|
643
670
|
}
|
|
644
671
|
/**
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
672
|
+
Parses raw web element properties into a standardized WebElementComponent structure
|
|
673
|
+
|
|
674
|
+
@param componentProperty - Raw component property data in OCHRE format
|
|
675
|
+
@param elementResource - Raw element resource data in OCHRE format
|
|
676
|
+
@returns Parsed WebElementComponent object
|
|
650
677
|
*/
|
|
651
678
|
/**
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
679
|
+
The parser for each web element component, keyed by its OCHRE component name
|
|
680
|
+
|
|
681
|
+
Every component parser takes the same {@link WebElementComponentParameters}
|
|
682
|
+
bag, so this is a table rather than a `switch`: a missing component is a type
|
|
683
|
+
error here instead of a runtime throw, and each parser can be exercised on
|
|
684
|
+
its own.
|
|
658
685
|
*/
|
|
659
686
|
const WEB_ELEMENT_COMPONENT_PARSERS = {
|
|
660
687
|
"3d-viewer": parse3dViewerComponent,
|
|
@@ -679,18 +706,19 @@ const WEB_ELEMENT_COMPONENT_PARSERS = {
|
|
|
679
706
|
timeline: parseTimelineComponent,
|
|
680
707
|
video: parseVideoComponent
|
|
681
708
|
};
|
|
682
|
-
function parseWebElementProperties(componentProperty, elementResource, options,
|
|
709
|
+
function parseWebElementProperties(componentProperty, elementResource, options, context) {
|
|
683
710
|
const unparsedComponentName = componentProperty.values[0].content;
|
|
684
711
|
const componentNameResult = v.safeParse(componentSchema, unparsedComponentName);
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
return
|
|
712
|
+
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}`);
|
|
713
|
+
const component = componentNameResult.output;
|
|
714
|
+
return WEB_ELEMENT_COMPONENT_PARSERS[component]({
|
|
688
715
|
componentProperty,
|
|
689
|
-
componentReader: websitePresentationReader(componentProperty.properties),
|
|
716
|
+
componentReader: websitePresentationReader(componentProperty.properties, context.componentDefaults.get(component) ?? null),
|
|
690
717
|
elementResource,
|
|
691
718
|
websiteLinks: parseLinks(elementResource.links, options),
|
|
692
719
|
options,
|
|
693
|
-
pageSlugs
|
|
720
|
+
pageSlugs: context.pageSlugs,
|
|
721
|
+
componentDefaults: context.componentDefaults
|
|
694
722
|
});
|
|
695
723
|
}
|
|
696
724
|
function parseWebTitle(properties, identification, overrides) {
|
|
@@ -719,16 +747,16 @@ function parseWebTitle(properties, identification, overrides) {
|
|
|
719
747
|
return title;
|
|
720
748
|
}
|
|
721
749
|
/**
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
750
|
+
Parses raw web element data into a standardized WebElement structure
|
|
751
|
+
|
|
752
|
+
@param elementResource - Raw element resource data in OCHRE format
|
|
753
|
+
@returns Parsed WebElement object
|
|
726
754
|
*/
|
|
727
|
-
function parseWebElement(elementResource, options,
|
|
755
|
+
function parseWebElement(elementResource, options, context) {
|
|
728
756
|
const identification = parseIdentification(elementResource.identification, options);
|
|
729
757
|
const elementProperties = parseSimplifiedProperties(elementResource.properties, options);
|
|
730
758
|
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,
|
|
759
|
+
const properties = parseWebElementProperties(websitePresentationReader(presentationProperty.properties).requiredProperty("component", `Component property not found for element (${formatXMLWebsiteResourceMetadata(elementResource)})`), elementResource, options, context);
|
|
732
760
|
const cssStyles = parseResponsiveCssStyles(elementProperties);
|
|
733
761
|
const title = parseWebTitle(elementProperties, identification, {
|
|
734
762
|
isNameDisplayed: [
|
|
@@ -747,4 +775,4 @@ function parseWebElement(elementResource, options, pageSlugs) {
|
|
|
747
775
|
...properties
|
|
748
776
|
};
|
|
749
777
|
}
|
|
750
|
-
export { WEB_ELEMENT_COMPONENT_PARSERS, parseWebElement, parseWebTitle };
|
|
778
|
+
export { WEB_ELEMENT_COMPONENT_PARSERS, parseComponentDefaults, parseWebElement, parseWebTitle };
|
|
@@ -1,6 +1,6 @@
|
|
|
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
6
|
} | undefined, options: ParserOptions<T>, context: Pick<Website<T>, "belongsTo" | "metadata">): Webpage<T> | null;
|
|
@@ -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_DEFAULTS, WEBPAGE_PROPERTY_LABELS, parseWebsiteProperties } 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
|
+
...context.parentProperties?.page ?? WEBPAGE_PROPERTY_DEFAULTS,
|
|
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,10 +106,10 @@ 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));
|
|
@@ -126,17 +118,18 @@ function parseWebpageView(view, options, context) {
|
|
|
126
118
|
const pages = readWebsitePages(view?.resource, options);
|
|
127
119
|
return parseWebpages(pages, options, {
|
|
128
120
|
...context,
|
|
129
|
-
|
|
121
|
+
pageSlugs: collectWebsitePageSlugs(pages, options),
|
|
122
|
+
componentDefaults: /* @__PURE__ */ new Map()
|
|
130
123
|
})[0] ?? null;
|
|
131
124
|
}
|
|
132
125
|
function parseWebsiteSegments(segments, options, context) {
|
|
133
126
|
return Array.from(segments, (segment) => parseWebsiteTree(segment.tree, options, context, "segment", segment.slugPrefix));
|
|
134
127
|
}
|
|
135
128
|
/**
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
129
|
+
Parses raw sidebar data into a standardized Sidebar structure
|
|
130
|
+
|
|
131
|
+
@param resources - Array of raw sidebar resources in OCHRE format
|
|
132
|
+
@returns Parsed Sidebar object
|
|
140
133
|
*/
|
|
141
134
|
function parseSidebar(resources, options, context) {
|
|
142
135
|
const sidebarResource = resources.find((resource) => isSidebarResource(resource, options));
|
|
@@ -160,7 +153,7 @@ function parseSidebar(resources, options, context) {
|
|
|
160
153
|
return sidebar;
|
|
161
154
|
}
|
|
162
155
|
function parseWebAccordionItem(elementResource, childResources, options, context) {
|
|
163
|
-
const trigger = parseWebElement(elementResource, options, context
|
|
156
|
+
const trigger = parseWebElement(elementResource, options, context);
|
|
164
157
|
const items = parseWebBlockItems(childResources, options, context);
|
|
165
158
|
return {
|
|
166
159
|
uuid: trigger.uuid,
|
|
@@ -205,7 +198,7 @@ function parseAccordionAwareBlockItems(blockResources, options, context, isSuppo
|
|
|
205
198
|
case "element": {
|
|
206
199
|
const childResources = normalizeWebsiteResources(resource.resource);
|
|
207
200
|
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
|
|
201
|
+
blockItems.push(isSupportingAccordionItems && componentType === "text" && childResources.length > 0 ? parseWebAccordionItem(resource, childResources, options, context) : parseWebElement(resource, options, context));
|
|
209
202
|
break;
|
|
210
203
|
}
|
|
211
204
|
case "block": {
|
|
@@ -218,10 +211,10 @@ function parseAccordionAwareBlockItems(blockResources, options, context, isSuppo
|
|
|
218
211
|
return blockItems;
|
|
219
212
|
}
|
|
220
213
|
/**
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
214
|
+
Parses raw block data into a standardized WebBlock structure
|
|
215
|
+
|
|
216
|
+
@param blockResource - Raw block resource data in OCHRE format
|
|
217
|
+
@returns Parsed WebBlock object
|
|
225
218
|
*/
|
|
226
219
|
function parseWebBlock(blockResource, options, context) {
|
|
227
220
|
const blockProperties = parseSimplifiedProperties(blockResource.properties, options);
|
|
@@ -281,7 +274,7 @@ function parseOakWebsite(resources, webpages, options, context) {
|
|
|
281
274
|
}
|
|
282
275
|
const component = websitePresentationReader(parseSimplifiedProperties(resource.properties, options)).nestedByValue("presentation", "element").value("component");
|
|
283
276
|
if (component !== "map" && component !== "collection") continue;
|
|
284
|
-
const element = parseWebElement(resource, options, context
|
|
277
|
+
const element = parseWebElement(resource, options, context);
|
|
285
278
|
if (element.component === "map") {
|
|
286
279
|
map ??= element;
|
|
287
280
|
continue;
|
|
@@ -289,7 +282,7 @@ function parseOakWebsite(resources, webpages, options, context) {
|
|
|
289
282
|
const resourceSlug = cleanWebsitePageSlug(resource.slug) ?? "";
|
|
290
283
|
const slug = resourceSlug === "" ? parseStringContent(resource.identification.abbreviation, options) : resourceSlug;
|
|
291
284
|
if (slug === "") throw new Error(`Slug not found for OAK collection (${formatXMLWebsiteResourceMetadata(resource)})`, { cause: resource });
|
|
292
|
-
const collectionPage = createWebpage(resource, slug, options);
|
|
285
|
+
const collectionPage = createWebpage(resource, slug, options, context);
|
|
293
286
|
collectionPage.items = [element];
|
|
294
287
|
collectionPage.properties.isDisplayedInNavbar = false;
|
|
295
288
|
items.push(collectionPage);
|
|
@@ -304,20 +297,22 @@ function parseWebsiteTree(websiteTree, options, context, type, slugPrefix) {
|
|
|
304
297
|
if (type === "website" && websiteTree.items?.resource == null) throw new Error(`Website pages not found (website uuid “${websiteTree.uuid}”)`, { cause: websiteTree });
|
|
305
298
|
const resources = normalizeWebsiteResources(websiteTree.items?.resource);
|
|
306
299
|
const pages = readWebsitePages(websiteTree.items?.resource, options, slugPrefix);
|
|
307
|
-
const
|
|
300
|
+
const websiteReader = websitePresentationReader(parseSimplifiedProperties(websiteTree.properties, options)).nested("presentation");
|
|
308
301
|
const treeContext = {
|
|
309
302
|
...context,
|
|
310
|
-
|
|
303
|
+
pageSlugs: context.pageSlugs ?? collectWebsitePageSlugs(pages, options),
|
|
304
|
+
componentDefaults: parseComponentDefaults(websiteReader, context.componentDefaults)
|
|
311
305
|
};
|
|
312
306
|
const sidebar = parseSidebar(resources, options, treeContext);
|
|
313
|
-
const properties = parseWebsiteProperties(
|
|
307
|
+
const properties = parseWebsiteProperties(websiteReader, websiteTree, sidebar, options, context.parentProperties ?? null);
|
|
314
308
|
const license = parseLicense(websiteTree.availability) ?? context.parentLicense ?? null;
|
|
315
|
-
const
|
|
309
|
+
const pageContext = {
|
|
316
310
|
...treeContext,
|
|
317
311
|
parentProperties: properties,
|
|
318
312
|
parentLicense: license
|
|
319
|
-
}
|
|
320
|
-
const
|
|
313
|
+
};
|
|
314
|
+
const webpages = parseWebpages(pages, options, pageContext);
|
|
315
|
+
const { items, oak } = type === "website" && properties.type === "oak" ? parseOakWebsite(resources, webpages, options, pageContext) : {
|
|
321
316
|
items: webpages,
|
|
322
317
|
oak: null
|
|
323
318
|
};
|
|
@@ -351,7 +346,8 @@ function parseWebsite(data, options) {
|
|
|
351
346
|
uuid: rawOchre.uuidBelongsTo,
|
|
352
347
|
abbreviation: rawOchre.belongsTo
|
|
353
348
|
},
|
|
354
|
-
metadata: parseMetadata(rawOchre, parserOptions, defaultLanguage)
|
|
349
|
+
metadata: parseMetadata(rawOchre, parserOptions, defaultLanguage),
|
|
350
|
+
componentDefaults: /* @__PURE__ */ new Map()
|
|
355
351
|
}, "website");
|
|
356
352
|
const styleLabels = new Map((rawOchre.styleLabels?.styleLabel ?? []).map((styleLabel) => [styleLabel.valueUuid, parseRequiredContentLike(styleLabel, parserOptions)]));
|
|
357
353
|
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;
|