ochre-sdk 1.3.24 → 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.
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 +14 -14
  20. package/dist/fetchers/item.mjs +14 -14
  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 +50 -31
  62. package/dist/parsers/website/components.mjs +79 -51
  63. package/dist/parsers/website/index.d.mts +1 -1
  64. package/dist/parsers/website/index.mjs +43 -47
  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 +23 -11
  72. package/dist/parsers/website/reader.d.mts +55 -46
  73. package/dist/parsers/website/reader.mjs +64 -46
  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 +67 -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,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, pageSlugs));
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
- * 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.
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
- * 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
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
- * 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.
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, pageSlugs) {
709
+ function parseWebElementProperties(componentProperty, elementResource, options, context) {
683
710
  const unparsedComponentName = componentProperty.values[0].content;
684
711
  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({
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
- * 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
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, pageSlugs) {
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, pageSlugs);
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.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
+ ...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
- * 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,10 +106,10 @@ 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));
@@ -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
- pageSlugsByUuid: collectWebsitePageSlugs(pages, options)
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
- * 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
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.pageSlugsByUuid);
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.pageSlugsByUuid));
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
- * 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
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.pageSlugsByUuid);
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 pageSlugsByUuid = context.pageSlugsByUuid ?? collectWebsitePageSlugs(pages, options);
300
+ const websiteReader = websitePresentationReader(parseSimplifiedProperties(websiteTree.properties, options)).nested("presentation");
308
301
  const treeContext = {
309
302
  ...context,
310
- pageSlugsByUuid
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(websiteTree.properties.property, websiteTree, sidebar, options, context.parentProperties ?? null);
307
+ const properties = parseWebsiteProperties(websiteReader, websiteTree, sidebar, options, context.parentProperties ?? null);
314
308
  const license = parseLicense(websiteTree.availability) ?? context.parentLicense ?? null;
315
- const webpages = parseWebpages(pages, options, {
309
+ const pageContext = {
316
310
  ...treeContext,
317
311
  parentProperties: properties,
318
312
  parentLicense: license
319
- });
320
- const { items, oak } = type === "website" && properties.type === "oak" ? parseOakWebsite(resources, webpages, options, treeContext) : {
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
- * 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;