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.
Files changed (97) hide show
  1. package/dist/categories.d.mts +56 -56
  2. package/dist/categories.mjs +39 -39
  3. package/dist/constants.d.mts +8 -8
  4. package/dist/constants.mjs +6 -6
  5. package/dist/errors.d.mts +12 -12
  6. package/dist/errors.mjs +22 -23
  7. package/dist/fetchers/container-items.d.mts +28 -28
  8. package/dist/fetchers/container-items.mjs +27 -27
  9. package/dist/fetchers/gallery.d.mts +13 -13
  10. package/dist/fetchers/gallery.mjs +2 -2
  11. package/dist/fetchers/item-children.d.mts +12 -12
  12. package/dist/fetchers/item-children.mjs +2 -2
  13. package/dist/fetchers/item-links.d.mts +10 -10
  14. package/dist/fetchers/item-links.mjs +6 -6
  15. package/dist/fetchers/item-locations.d.mts +20 -20
  16. package/dist/fetchers/item-locations.mjs +3 -3
  17. package/dist/fetchers/item-ocr-data.d.mts +23 -23
  18. package/dist/fetchers/item-ocr-data.mjs +44 -44
  19. package/dist/fetchers/item.d.mts +23 -18
  20. package/dist/fetchers/item.mjs +15 -15
  21. package/dist/fetchers/map-layers.d.mts +15 -15
  22. package/dist/fetchers/map-layers.mjs +12 -11
  23. package/dist/fetchers/request.d.mts +40 -40
  24. package/dist/fetchers/request.mjs +37 -37
  25. package/dist/fetchers/set/items.d.mts +15 -15
  26. package/dist/fetchers/set/items.mjs +1 -1
  27. package/dist/fetchers/set/property-values.d.mts +16 -16
  28. package/dist/fetchers/set/property-values.mjs +43 -43
  29. package/dist/fetchers/tree/items.d.mts +27 -27
  30. package/dist/fetchers/tree/items.mjs +1 -1
  31. package/dist/fetchers/website-metadata.d.mts +4 -4
  32. package/dist/fetchers/website-metadata.mjs +9 -9
  33. package/dist/fetchers/website.d.mts +10 -10
  34. package/dist/fetchers/website.mjs +12 -12
  35. package/dist/getters.d.mts +83 -83
  36. package/dist/getters.mjs +74 -74
  37. package/dist/helpers.d.mts +4 -4
  38. package/dist/helpers.mjs +7 -7
  39. package/dist/index.d.mts +3 -3
  40. package/dist/index.mjs +5 -5
  41. package/dist/languages.d.mts +58 -58
  42. package/dist/languages.mjs +21 -21
  43. package/dist/ocr.d.mts +27 -27
  44. package/dist/ocr.mjs +29 -29
  45. package/dist/parsers/helpers.d.mts +23 -23
  46. package/dist/parsers/helpers.mjs +8 -8
  47. package/dist/parsers/index.d.mts +2 -2
  48. package/dist/parsers/index.mjs +15 -15
  49. package/dist/parsers/languages.d.mts +49 -49
  50. package/dist/parsers/languages.mjs +49 -49
  51. package/dist/parsers/multilingual.d.mts +174 -174
  52. package/dist/parsers/multilingual.mjs +146 -146
  53. package/dist/parsers/partial-date.d.mts +12 -12
  54. package/dist/parsers/partial-date.mjs +11 -11
  55. package/dist/parsers/property-token.d.mts +20 -20
  56. package/dist/parsers/property-token.mjs +16 -16
  57. package/dist/parsers/string.d.mts +33 -33
  58. package/dist/parsers/string.mjs +62 -64
  59. package/dist/parsers/website/bounds.d.mts +6 -6
  60. package/dist/parsers/website/bounds.mjs +5 -5
  61. package/dist/parsers/website/components.d.mts +46 -31
  62. package/dist/parsers/website/components.mjs +84 -51
  63. package/dist/parsers/website/index.d.mts +2 -2
  64. package/dist/parsers/website/index.mjs +45 -48
  65. package/dist/parsers/website/links.d.mts +24 -24
  66. package/dist/parsers/website/links.mjs +18 -18
  67. package/dist/parsers/website/messages.d.mts +16 -16
  68. package/dist/parsers/website/messages.mjs +14 -14
  69. package/dist/parsers/website/options.d.mts +1 -1
  70. package/dist/parsers/website/properties.d.mts +17 -8
  71. package/dist/parsers/website/properties.mjs +31 -10
  72. package/dist/parsers/website/reader.d.mts +55 -47
  73. package/dist/parsers/website/reader.mjs +66 -51
  74. package/dist/parsers/website/slug.d.mts +50 -50
  75. package/dist/parsers/website/slug.mjs +36 -36
  76. package/dist/parsers/website/styles.d.mts +18 -18
  77. package/dist/parsers/website/styles.mjs +19 -19
  78. package/dist/parsers/website/walk.d.mts +46 -46
  79. package/dist/parsers/website/walk.mjs +34 -34
  80. package/dist/query.d.mts +63 -63
  81. package/dist/query.mjs +137 -140
  82. package/dist/reflection.d.mts +51 -51
  83. package/dist/reflection.mjs +45 -45
  84. package/dist/schemas.d.mts +44 -44
  85. package/dist/schemas.mjs +50 -50
  86. package/dist/types/index.d.mts +192 -192
  87. package/dist/types/utilities.d.mts +5 -5
  88. package/dist/types/website.d.mts +74 -62
  89. package/dist/xml/dates.d.mts +9 -9
  90. package/dist/xml/dates.mjs +9 -9
  91. package/dist/xml/metadata.d.mts +14 -14
  92. package/dist/xml/metadata.mjs +18 -18
  93. package/dist/xml/schemas.mjs +24 -24
  94. package/dist/xml/types.d.mts +9 -9
  95. package/dist/xquery.d.mts +49 -49
  96. package/dist/xquery.mjs +50 -50
  97. 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
- * Default values for a collection's display properties, shared between the
17
- * "collection" component and the "query" component's collection overrides.
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
- * 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.
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
- * 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.
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
- * 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.
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
- * Parses the "use-property" values defining which item properties a collection
90
- * displays, returning `null` when none are set.
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
- return property.values.flatMap((value) => value.uuid === null ? [] : [{
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
- * Parses the "customize-special" "relations" properties, each pairing the
102
- * property variables it links with "use-property" with a display "variant".
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, pageSlugs));
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
- * The defaults an image component falls back to
366
- *
367
- * Annotated rather than `as const`, so each field keeps the full union its
368
- * type allows and the parser can still compare against the other members.
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
- * Parses raw web element properties into a standardized WebElementComponent structure
646
- *
647
- * @param componentProperty - Raw component property data in OCHRE format
648
- * @param elementResource - Raw element resource data in OCHRE format
649
- * @returns Parsed WebElementComponent object
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
- * The parser for each web element component, keyed by its OCHRE component name
653
- *
654
- * Every component parser takes the same {@link WebElementComponentParameters}
655
- * bag, so this is a table rather than a `switch`: a missing component is a type
656
- * error here instead of a runtime throw, and each parser can be exercised on
657
- * its own.
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, pageSlugs) {
714
+ function parseWebElementProperties(componentProperty, elementResource, options, context) {
683
715
  const unparsedComponentName = componentProperty.values[0].content;
684
716
  const componentNameResult = v.safeParse(componentSchema, unparsedComponentName);
685
- const parse = componentNameResult.success ? WEB_ELEMENT_COMPONENT_PARSERS[componentNameResult.output] : void 0;
686
- if (parse == null) 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}`);
687
- return parse({
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
- * Parses raw web element data into a standardized WebElement structure
723
- *
724
- * @param elementResource - Raw element resource data in OCHRE format
725
- * @returns Parsed WebElement object
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, pageSlugs) {
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, pageSlugs);
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.pageSlugsByUuid));
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.pageSlugsByUuid);
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
- width: "default",
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
- * Parses a walked page node into a standardized Webpage structure
84
- *
85
- * @param page - The page node, with its slug and nesting already resolved
86
- * @returns Parsed Webpage object
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
- isDisplayedInNavbar: "displayed-in-navbar",
104
- width: "width",
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
- * Parses walked page nodes into an array of Webpage objects
118
- *
119
- * @param pages - The page nodes to parse
120
- * @returns Array of parsed Webpage objects
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
- pageSlugsByUuid: collectWebsitePageSlugs(pages, options)
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
- * Parses raw sidebar data into a standardized Sidebar structure
137
- *
138
- * @param resources - Array of raw sidebar resources in OCHRE format
139
- * @returns Parsed Sidebar object
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.pageSlugsByUuid);
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.pageSlugsByUuid));
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
- * Parses raw block data into a standardized WebBlock structure
222
- *
223
- * @param blockResource - Raw block resource data in OCHRE format
224
- * @returns Parsed WebBlock object
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.pageSlugsByUuid);
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 pageSlugsByUuid = context.pageSlugsByUuid ?? collectWebsitePageSlugs(pages, options);
301
+ const websiteReader = websitePresentationReader(parseSimplifiedProperties(websiteTree.properties, options)).nested("presentation");
308
302
  const treeContext = {
309
303
  ...context,
310
- pageSlugsByUuid
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(websiteTree.properties.property, websiteTree, sidebar, options, context.parentProperties ?? null);
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 webpages = parseWebpages(pages, options, {
310
+ const pageContext = {
316
311
  ...treeContext,
317
312
  parentProperties: properties,
318
313
  parentLicense: license
319
- });
320
- const { items, oak } = type === "website" && properties.type === "oak" ? parseOakWebsite(resources, webpages, options, treeContext) : {
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
- * The link categories a website can point at
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
- * 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
- */
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
- * 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
- */
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
- * 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
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
- * 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
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
- * 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
- */
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
- * 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
- */
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;