@digitalculture/ochre-sdk 0.7.12 → 0.7.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +60 -60
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +62 -62
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{z as e}from"zod";const
|
|
1
|
+
import{z as e}from"zod";import{randomUUID as t}from"node:crypto";const n=e.string().uuid({message:`Invalid UUID provided`}),r=e.object({type:e.enum([`traditional`,`digital-collection`,`plum`,`cedar`,`elm`,`maple`,`oak`,`palm`],{message:`Invalid website type`}),status:e.enum([`development`,`preview`,`production`],{message:`Invalid website status`}),privacy:e.enum([`public`,`password`,`private`],{message:`Invalid website privacy`})}),i=e.enum([`annotated-document`,`annotated-image`,`bibliography`,`button`,`collection`,`empty-space`,`entries`,`filter-categories`,`iframe`,`iiif-viewer`,`image`,`image-gallery`,`n-columns`,`n-rows`,`network-graph`,`search-bar`,`table`,`text`,`timeline`,`video`],{message:`Invalid component`}),a=e.enum([`resource`,`spatialUnit`,`concept`,`period`,`bibliography`,`person`,`propertyValue`,`set`,`tree`]),o=e.enum([`string`,`integer`,`decimal`,`boolean`,`date`,`dateTime`,`time`,`coordinate`,`IDREF`]),s=e.object({uuid:e.string().uuid({message:`Invalid UUID`}),filter:e.string().optional(),page:e.number().positive({message:`Page must be positive`}),perPage:e.number().positive({message:`Per page must be positive`})}).strict(),c=e.string().transform(e=>e.split(` `)).pipe(e.array(e.enum([`bold`,`italic`,`underline`]))),l=e.string().transform(e=>e.split(` `)).pipe(e.array(e.enum([`newline`,`trailing`,`leading`]))),u=e.string().email({message:`Invalid email`}),d={includeNestedProperties:!1};
|
|
2
2
|
/**
|
|
3
3
|
* Finds a property by its label in an array of properties
|
|
4
4
|
*
|
|
@@ -15,7 +15,7 @@ import{z as e}from"zod";const t=e.string().uuid({message:`Invalid UUID provided`
|
|
|
15
15
|
* }
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
|
-
function
|
|
18
|
+
function f(e,t,n=d){let{includeNestedProperties:r}=n,i=e.find(e=>e.label===t);if(i)return i;if(r){for(let n of e)if(n.properties.length>0){let e=f(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}
|
|
19
19
|
/**
|
|
20
20
|
* Retrieves all values for a property with the given label
|
|
21
21
|
*
|
|
@@ -34,7 +34,7 @@ function d(e,t,n=u){let{includeNestedProperties:r}=n,i=e.find(e=>e.label===t);if
|
|
|
34
34
|
* }
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
|
-
function
|
|
37
|
+
function p(e,t,n=d){let{includeNestedProperties:r}=n,i=e.find(e=>e.label===t);if(i)return i.values.map(e=>e.content);if(r){for(let n of e)if(n.properties.length>0){let e=p(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}
|
|
38
38
|
/**
|
|
39
39
|
* Gets the first value of a property with the given label
|
|
40
40
|
*
|
|
@@ -51,7 +51,7 @@ function f(e,t,n=u){let{includeNestedProperties:r}=n,i=e.find(e=>e.label===t);if
|
|
|
51
51
|
* }
|
|
52
52
|
* ```
|
|
53
53
|
*/
|
|
54
|
-
function
|
|
54
|
+
function m(e,t,n=d){let{includeNestedProperties:r}=n,i=p(e,t,{includeNestedProperties:r});if(i!==null&&i.length>0)return i[0];if(r){for(let n of e)if(n.properties.length>0){let e=m(n.properties,t,{includeNestedProperties:r});if(e!==null)return e}}return null}
|
|
55
55
|
/**
|
|
56
56
|
* Gets all unique properties from an array of properties
|
|
57
57
|
*
|
|
@@ -65,7 +65,7 @@ function p(e,t,n=u){let{includeNestedProperties:r}=n,i=f(e,t,{includeNestedPrope
|
|
|
65
65
|
* console.log(`Available properties: ${properties.map((p) => p.label).join(", ")}`);
|
|
66
66
|
* ```
|
|
67
67
|
*/
|
|
68
|
-
function
|
|
68
|
+
function h(e,t=d){let{includeNestedProperties:n}=t,r=[];for(let t of e){if(r.some(e=>e.uuid===t.uuid))continue;if(r.push(t),t.properties.length>0&&n){let e=h(t.properties,{includeNestedProperties:!0});for(let t of e){if(r.some(e=>e.uuid===t.uuid))continue;r.push(t)}}}return r}
|
|
69
69
|
/**
|
|
70
70
|
* Filters a property based on a label and value criteria
|
|
71
71
|
*
|
|
@@ -87,7 +87,7 @@ function m(e,t=u){let{includeNestedProperties:n}=t,r=[];for(let t of e){if(r.som
|
|
|
87
87
|
* }
|
|
88
88
|
* ```
|
|
89
89
|
*/
|
|
90
|
-
function
|
|
90
|
+
function g(e,t,n=d){let{includeNestedProperties:r}=n,i=t.label.toLocaleLowerCase(`en-US`)===`all fields`;if(i||e.label.toLocaleLowerCase(`en-US`)===t.label.toLocaleLowerCase(`en-US`)){let n=e.values.some(e=>e.content===null?!1:typeof e.content==`string`?typeof t.value==`string`?e.content.toLocaleLowerCase(`en-US`).includes(t.value.toLocaleLowerCase(`en-US`)):!1:typeof e.content==`number`?typeof t.value==`number`?e.content===t.value:!1:typeof e.content==`boolean`?typeof t.value==`boolean`?e.booleanValue===t.value:!1:e.content instanceof Date&&t.value instanceof Date?e.content.getTime()===t.value.getTime():!1);return!n&&r&&(n=e.properties.some(e=>g(e,t,{includeNestedProperties:!0}))),n}return!1}
|
|
91
91
|
/**
|
|
92
92
|
* Finds a string item in an array by language code
|
|
93
93
|
*
|
|
@@ -96,7 +96,7 @@ function h(e,t,n=u){let{includeNestedProperties:r}=n,i=t.label.toLocaleLowerCase
|
|
|
96
96
|
* @returns Matching string item or null if not found
|
|
97
97
|
* @internal
|
|
98
98
|
*/
|
|
99
|
-
function
|
|
99
|
+
function _(e,t){let n=e.find(e=>e.lang===t);return n??null}
|
|
100
100
|
/**
|
|
101
101
|
* Parses email addresses in a string into HTML links
|
|
102
102
|
*
|
|
@@ -109,7 +109,7 @@ function g(e,t){let n=e.find(e=>e.lang===t);return n??null}
|
|
|
109
109
|
* // Returns: "Contact us at <ExternalLink href="mailto:info@example.com">info@example.com</ExternalLink>"
|
|
110
110
|
* ```
|
|
111
111
|
*/
|
|
112
|
-
function
|
|
112
|
+
function v(e){let t=e.split(` `),n=[];for(let e of t){let t=e.replaceAll(/(?<=\s|^)[([{]+|[)\]}]+(?=\s|$)/g,``).replace(/[!),.:;?\]]$/,``),r=e.indexOf(t),i=e.slice(0,r),a=e.slice(r+t.length),o=u.safeParse(t).success;if(o){n.push(i,`${i}<ExternalLink href="mailto:${t}">${t}</ExternalLink>${a}`);continue}n.push(e)}return n.join(` `)}
|
|
113
113
|
/**
|
|
114
114
|
* Applies text rendering options (bold, italic, underline) to a string
|
|
115
115
|
*
|
|
@@ -118,7 +118,7 @@ function _(e){let t=e.split(` `),n=[];for(let e of t){let t=e.replaceAll(/(?<=\s
|
|
|
118
118
|
* @returns String with markdown formatting applied
|
|
119
119
|
* @internal
|
|
120
120
|
*/
|
|
121
|
-
function
|
|
121
|
+
function y(e,t){let n=e,r=c.safeParse(t);if(!r.success)return console.warn(`Invalid render options string provided: “${t}”`),e;for(let e of r.data)switch(e){case`bold`:n=`**${n}**`;break;case`italic`:n=`*${n}*`;break;case`underline`:n=`_${n}_`;break}return n.replaceAll(`'`,`'`)}
|
|
122
122
|
/**
|
|
123
123
|
* Applies whitespace options to a string (newline, trailing, leading)
|
|
124
124
|
*
|
|
@@ -127,7 +127,7 @@ function v(e,t){let n=e,r=s.safeParse(t);if(!r.success)return console.warn(`Inva
|
|
|
127
127
|
* @returns String with whitespace modifications applied
|
|
128
128
|
* @internal
|
|
129
129
|
*/
|
|
130
|
-
function
|
|
130
|
+
function b(e,t){let n=e,r=l.safeParse(t);if(!r.success)return console.warn(`Invalid whitespace string provided: “${t}”`),e;for(let e of r.data)switch(e){case`newline`:n=`<br />\n${n}`;break;case`trailing`:n=`${n} `;break;case`leading`:n=` ${n}`;break}return n.replaceAll(`'`,`'`)}
|
|
131
131
|
/**
|
|
132
132
|
* Converts a FakeString (string|number|boolean) to a proper string
|
|
133
133
|
*
|
|
@@ -141,14 +141,14 @@ function y(e,t){let n=e,r=c.safeParse(t);if(!r.success)return console.warn(`Inva
|
|
|
141
141
|
* parseFakeString("test"); // Returns "test"
|
|
142
142
|
* ```
|
|
143
143
|
*/
|
|
144
|
-
function
|
|
144
|
+
function x(e){let t=``;return typeof e==`string`?t=e:typeof e==`number`?t=e.toString():typeof e==`boolean`&&(t=e?`Yes`:`No`),t.replaceAll(`'`,`'`).replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}
|
|
145
145
|
/**
|
|
146
146
|
* Parses an OchreStringItem into a formatted string
|
|
147
147
|
*
|
|
148
148
|
* @param item - OchreStringItem to parse
|
|
149
149
|
* @returns Formatted string with applied rendering and whitespace
|
|
150
150
|
*/
|
|
151
|
-
function
|
|
151
|
+
function S(e){let t=``;switch(typeof e.string){case`string`:t=e.string;break;case`number`:case`boolean`:t=x(e.string);break;case`object`:{let n=Array.isArray(e.string)?e.string:[e.string];for(let e of n)if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)t+=x(e);else{let n=e.rend==null?x(e.content):y(x(e.content),e.rend),r=e.whitespace==null?n:b(n,e.whitespace);t+=r}break}default:t=``;break}return t.replaceAll(`'`,`'`).replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}
|
|
152
152
|
/**
|
|
153
153
|
* Parses rich text content into a formatted string with links and annotations
|
|
154
154
|
*
|
|
@@ -156,8 +156,8 @@ function x(e){let t=``;switch(typeof e.string){case`string`:t=e.string;break;cas
|
|
|
156
156
|
* @param footnotes - Optional array to collect footnotes during parsing
|
|
157
157
|
* @returns Formatted string with HTML/markdown elements
|
|
158
158
|
*/
|
|
159
|
-
function
|
|
160
|
-
`:``;if(`links`in e){let n=``;n=typeof e.string==`object`?
|
|
159
|
+
function C(e,t){if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return v(x(e));if(`whitespace`in e&&!(`content`in e)&&!(`string`in e))return e.whitespace===`newline`?`
|
|
160
|
+
`:``;if(`links`in e){let n=``;n=typeof e.string==`object`?w(e.string):x(e.string).replaceAll(`<`,String.raw`\<`).replaceAll(`{`,String.raw`\{`);let r=Array.isArray(e.links)?e.links:[e.links];for(let e of r)if(`resource`in e){let r=Array.isArray(e.resource)?e.resource[0]:e.resource,i=null;switch(r.content!=null&&(i=x(r.content).replaceAll(`<`,String.raw`\<`).replaceAll(`{`,String.raw`\{`)),r.type){case`image`:return r.rend===`inline`?`<InlineImage uuid="${r.uuid}" ${i===null?``:`content="${i}"`} height={${r.height?.toString()??`null`}} width={${r.width?.toString()??`null`}} />`:r.publicationDateTime==null?`<TooltipSpan type="image" ${i===null?``:`content="${i}"`}>${n}</TooltipSpan>`:`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${r.uuid}" type="image"${i===null?``:` content="${i}"`}>${n}</ExternalLink>`;case`internalDocument`:{let e=i?.toLocaleLowerCase(`en-US`).includes(`footnote`);return e?(t&&t.push({uuid:r.uuid,label:n,content:``}),` <Footnote uuid="${r.uuid}"${n?` label="${n}"`:``}${i===null?``:` content="${i}"`} />`):`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${r.uuid}" type="internalDocument" ${i===null?``:`content="${i}"`}>${n}</ExternalLink>`}case`externalDocument`:return r.publicationDateTime==null?`<TooltipSpan type="externalDocument" ${i===null?``:`content="${i}"`}>${n}</TooltipSpan>`:`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${r.uuid}" type="externalDocument" ${i===null?``:`content="${i}"`}>${n}</ExternalLink>`;case`webpage`:return`<ExternalLink href="${r.href}" type="webpage" ${i===null?``:`content="${i}"`}>${n}</ExternalLink>`;default:return``}}else if(`concept`in e){let t=Array.isArray(e.concept)?e.concept[0]:e.concept;return t.publicationDateTime==null?`<TooltipSpan type="concept">${n}</TooltipSpan>`:`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${t.uuid}" type="concept">${n}</ExternalLink>`}else if(`set`in e){let t=Array.isArray(e.set)?e.set[0]:e.set;return t.publicationDateTime==null?`<TooltipSpan type="set">${n}</TooltipSpan>`:`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${t.uuid}" type="set">${n}</ExternalLink>`}else if(`person`in e){let t=Array.isArray(e.person)?e.person[0]:e.person,r=t.identification?[`string`,`number`,`boolean`].includes(typeof t.identification.label)?x(t.identification.label):w(t.identification.label):null;return t.publicationDateTime==null?`<TooltipSpan type="${t.type??`person`}" ${r===null?``:`content="${r}"`}>${n}</TooltipSpan>`:`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${t.uuid}" type="${t.type??`person`}" ${r===null?``:`content="${r}"`}>${n}</ExternalLink>`}else if(`bibliography`in e){let t=Array.isArray(e.bibliography)?e.bibliography[0]:e.bibliography;return t.publicationDateTime==null?`<TooltipSpan type="bibliography">${n}</TooltipSpan>`:`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${t.uuid}" type="${t.type??`bibliography`}">${n}</ExternalLink>`}}let n=``;if(`string`in e){let r=Array.isArray(e.string)?e.string:[e.string];for(let e of r)n+=C(e,t);return`whitespace`in e&&e.whitespace!=null&&(n=b(v(n),e.whitespace)),n.replaceAll(`'`,`'`).replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}else n=x(e.content),e.rend!=null&&(n=y(v(n),e.rend)),e.whitespace!=null&&(n=b(v(n),e.whitespace));return n.replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}
|
|
161
161
|
/**
|
|
162
162
|
* Parses raw string content into a formatted string
|
|
163
163
|
*
|
|
@@ -165,14 +165,14 @@ function S(e,t){if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)r
|
|
|
165
165
|
* @param language - Optional language code for content selection (defaults to "eng")
|
|
166
166
|
* @returns Parsed and formatted string
|
|
167
167
|
*/
|
|
168
|
-
function
|
|
168
|
+
function w(e,t=`eng`){switch(typeof e.content){case`string`:case`number`:case`boolean`:return x(e.content);case`object`:if(Array.isArray(e.content)){let n=_(e.content,t);if(n)return S(n);{let n=e.content[0];if(!n)throw Error(`No string item found for language “${t}” in the following content:\n${JSON.stringify(e.content)}.`);return S(n)}}else return S(e.content);default:return String(e.content).replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}}
|
|
169
169
|
/**
|
|
170
170
|
* Get the category of an item from the OCHRE API response
|
|
171
171
|
* @param keys - The keys of the OCHRE API response
|
|
172
172
|
* @returns The category of the item
|
|
173
173
|
* @internal
|
|
174
174
|
*/
|
|
175
|
-
function
|
|
175
|
+
function T(e){let t=e.find(e=>a.safeParse(e).success);if(!t){let t=e.find(e=>![`uuid`,`uuidBelongsTo`,`belongsTo`,`publicationDateTime`,`metadata`,`languages`].includes(e));throw Error(`Invalid OCHRE data; found unexpected "${t}" key`)}let n=a.parse(t);return n}
|
|
176
176
|
/**
|
|
177
177
|
* Fetches raw OCHRE data by UUID from the OCHRE API
|
|
178
178
|
*
|
|
@@ -191,7 +191,7 @@ function w(e){let t=e.find(e=>i.safeParse(e).success);if(!t){let t=e.find(e=>![`
|
|
|
191
191
|
*
|
|
192
192
|
* @internal
|
|
193
193
|
*/
|
|
194
|
-
async function
|
|
194
|
+
async function E(e){try{let t=n.parse(e),r=await fetch(`https://ochre.lib.uchicago.edu/ochre?uuid=${t}&format=json&lang="*"`);if(!r.ok)throw Error(`Failed to fetch OCHRE data`);let i=await r.json();if(!(`ochre`in i))throw Error(`Invalid OCHRE data: API response missing 'ochre' key`);return[null,i]}catch(e){return[e instanceof Error?e.message:`Unknown error`,null]}}
|
|
195
195
|
/**
|
|
196
196
|
* Fetches and parses an OCHRE item from the OCHRE API
|
|
197
197
|
*
|
|
@@ -225,77 +225,77 @@ async function T(e){try{let n=t.parse(e),r=await fetch(`https://ochre.lib.uchica
|
|
|
225
225
|
*
|
|
226
226
|
* If the fetch/parse fails, the returned object will have an `error` property.
|
|
227
227
|
*/
|
|
228
|
-
async function
|
|
228
|
+
async function D(e,t,n){try{let[r,i]=await E(e);if(r!==null)throw Error(r);let a=T(Object.keys(i.ochre)),o;switch(a){case`resource`:if(!(`resource`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'resource' key`);o=J(i.ochre.resource);break;case`spatialUnit`:if(!(`spatialUnit`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'spatialUnit' key`);o=X(i.ochre.spatialUnit);break;case`concept`:if(!(`concept`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'concept' key`);o=Q(i.ochre.concept);break;case`period`:if(!(`period`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'period' key`);o=H(i.ochre.period);break;case`bibliography`:if(!(`bibliography`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'bibliography' key`);o=W(i.ochre.bibliography);break;case`person`:if(!(`person`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'person' key`);o=M(i.ochre.person);break;case`propertyValue`:if(!(`propertyValue`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'propertyValue' key`);o=K(i.ochre.propertyValue);break;case`set`:if(!(`set`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'set' key`);o=ce(i.ochre.set,n);break;case`tree`:if(!(`tree`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'tree' key`);o=se(i.ochre.tree);break;default:throw Error(`Invalid category`)}let s=te(i.ochre.metadata),c={uuid:i.ochre.uuidBelongsTo,abbreviation:x(i.ochre.belongsTo)};return{error:null,metadata:s,belongsTo:c,item:o,category:t}}catch(e){return{error:e instanceof Error?e.message:`Unknown error`,metadata:void 0,belongsTo:void 0,item:void 0,category:void 0}}}
|
|
229
229
|
/**
|
|
230
230
|
* Parses raw identification data into the standardized Identification type
|
|
231
231
|
*
|
|
232
232
|
* @param identification - Raw identification data from OCHRE format
|
|
233
233
|
* @returns Parsed Identification object with label and abbreviation
|
|
234
234
|
*/
|
|
235
|
-
function
|
|
235
|
+
function O(e){try{let t={label:[`string`,`number`,`boolean`].includes(typeof e.label)?x(e.label):w(e.label),abbreviation:``};for(let n of Object.keys(e).filter(e=>e!==`label`))t[n]=w(e[n]);return t}catch(e){return console.error(e),{label:``,abbreviation:``}}}
|
|
236
236
|
/**
|
|
237
237
|
* Parses raw language data into an array of language codes
|
|
238
238
|
*
|
|
239
239
|
* @param language - Raw language data, either single or array
|
|
240
240
|
* @returns Array of language codes as strings
|
|
241
241
|
*/
|
|
242
|
-
function ee(e){return e==null?[`eng`]:Array.isArray(e)?e.map(e=>
|
|
242
|
+
function ee(e){return e==null?[`eng`]:Array.isArray(e)?e.map(e=>w(e)):[w(e)]}
|
|
243
243
|
/**
|
|
244
244
|
* Parses raw metadata into the standardized Metadata type
|
|
245
245
|
*
|
|
246
246
|
* @param metadata - Raw metadata from OCHRE format
|
|
247
247
|
* @returns Parsed Metadata object
|
|
248
248
|
*/
|
|
249
|
-
function te(e){let t={label:``,abbreviation:``};if(e.item)if(e.item.label||e.item.abbreviation){let n=``,r=``;e.item.label&&(n=
|
|
249
|
+
function te(e){let t={label:``,abbreviation:``};if(e.item)if(e.item.label||e.item.abbreviation){let n=``,r=``;e.item.label&&(n=w(e.item.label)),e.item.abbreviation&&(r=w(e.item.abbreviation)),t={label:n,abbreviation:r}}else t=O(e.item.identification);let n=null,r=e.project?.identification?O(e.project.identification):null;return r&&(n={...r,website:e.project?.identification.website??null}),{project:n?{identification:n}:null,item:e.item?{identification:t,category:e.item.category,type:e.item.type,maxLength:e.item.maxLength??null}:null,dataset:w(e.dataset),publisher:w(e.publisher),languages:ee(e.language),identifier:w(e.identifier),description:w(e.description)}}
|
|
250
250
|
/**
|
|
251
251
|
* Parses raw context item data into the standardized ContextItem type
|
|
252
252
|
*
|
|
253
253
|
* @param contextItem - Raw context item data from OCHRE format
|
|
254
254
|
* @returns Parsed ContextItem object
|
|
255
255
|
*/
|
|
256
|
-
function
|
|
256
|
+
function k(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),number:e.n,content:x(e.content)}}
|
|
257
257
|
/**
|
|
258
258
|
* Parses raw context data into the standardized Context type
|
|
259
259
|
*
|
|
260
260
|
* @param context - Raw context data from OCHRE format
|
|
261
261
|
* @returns Parsed Context object
|
|
262
262
|
*/
|
|
263
|
-
function
|
|
263
|
+
function A(e){let t=Array.isArray(e.context)?e.context:[e.context],n={nodes:t.map(e=>{let t=[];if(`spatialUnit`in e&&e.spatialUnit){let n=Array.isArray(e.spatialUnit)?e.spatialUnit:[e.spatialUnit];for(let e of n)t.push(k(e))}return{tree:k(e.tree),project:k(e.project),spatialUnit:t}}),displayPath:e.displayPath};return n}
|
|
264
264
|
/**
|
|
265
265
|
* Parses raw license data into the standardized License type
|
|
266
266
|
*
|
|
267
267
|
* @param license - Raw license data from OCHRE format
|
|
268
268
|
* @returns Parsed License object or null if invalid
|
|
269
269
|
*/
|
|
270
|
-
function
|
|
270
|
+
function j(e){return typeof e.license==`string`?null:{content:e.license.content,url:e.license.target}}
|
|
271
271
|
/**
|
|
272
272
|
* Parses raw person data into the standardized Person type
|
|
273
273
|
*
|
|
274
274
|
* @param person - Raw person data from OCHRE format
|
|
275
275
|
* @returns Parsed Person object
|
|
276
276
|
*/
|
|
277
|
-
function
|
|
277
|
+
function M(e){return{uuid:e.uuid,category:`person`,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),type:e.type??null,number:e.n??null,context:e.context?A(e.context):null,date:e.date==null?null:new Date(e.date),identification:e.identification?O(e.identification):null,availability:e.availability?j(e.availability):null,address:e.address?{country:e.address.country??null,city:e.address.city??null,state:e.address.state??null}:null,coordinates:e.coordinates?R(e.coordinates):null,content:e.content==null?null:x(e.content),events:e.events?B(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:e.properties?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}
|
|
278
278
|
/**
|
|
279
279
|
* Parses raw person data into the standardized Person type
|
|
280
280
|
*
|
|
281
281
|
* @param persons - Array of raw person data from OCHRE format
|
|
282
282
|
* @returns Array of parsed Person objects
|
|
283
283
|
*/
|
|
284
|
-
function
|
|
284
|
+
function N(e){let t=[];for(let n of e)t.push(M(n));return t}
|
|
285
285
|
/**
|
|
286
286
|
* Parses an array of raw links into standardized Link objects
|
|
287
287
|
*
|
|
288
288
|
* @param linkRaw - Raw OCHRE link
|
|
289
289
|
* @returns Parsed Link object
|
|
290
290
|
*/
|
|
291
|
-
function ne(e){let t=`resource`in e?e.resource:`spatialUnit`in e?e.spatialUnit:`concept`in e?e.concept:`set`in e?e.set:`tree`in e?e.tree:`person`in e?e.person:`bibliography`in e?e.bibliography:`epigraphicUnit`in e?e.epigraphicUnit:`propertyValue`in e?e.propertyValue:null;if(!t)throw Error(`Invalid link provided: ${JSON.stringify(e,null,2)}`);let n=Array.isArray(t)?t:[t],r=[];for(let t of n){let n={category:`resource`in e?`resource`:`spatialUnit`in e?`spatialUnit`:`concept`in e?`concept`:`set`in e?`set`:`person`in e?`person`:`tree`in e?`tree`:`bibliography`in e?`bibliography`:`epigraphicUnit`in e?`epigraphicUnit`:`propertyValue`in e?`propertyValue`:null,content:`content`in t?t.content==null?null:
|
|
291
|
+
function ne(e){let t=`resource`in e?e.resource:`spatialUnit`in e?e.spatialUnit:`concept`in e?e.concept:`set`in e?e.set:`tree`in e?e.tree:`person`in e?e.person:`bibliography`in e?e.bibliography:`epigraphicUnit`in e?e.epigraphicUnit:`propertyValue`in e?e.propertyValue:null;if(!t)throw Error(`Invalid link provided: ${JSON.stringify(e,null,2)}`);let n=Array.isArray(t)?t:[t],r=[];for(let t of n){let n={category:`resource`in e?`resource`:`spatialUnit`in e?`spatialUnit`:`concept`in e?`concept`:`set`in e?`set`:`person`in e?`person`:`tree`in e?`tree`:`bibliography`in e?`bibliography`:`epigraphicUnit`in e?`epigraphicUnit`:`propertyValue`in e?`propertyValue`:null,content:`content`in t?t.content==null?null:x(t.content):null,href:`href`in t&&t.href!=null?t.href:null,uuid:t.uuid,type:t.type??null,identification:t.identification?O(t.identification):null,image:null,bibliographies:`bibliography`in e?G(Array.isArray(e.bibliography)?e.bibliography:[e.bibliography]):null,publicationDateTime:t.publicationDateTime==null?null:new Date(t.publicationDateTime)};`height`in t&&t.height!=null&&t.width!=null&&t.heightPreview!=null&&t.widthPreview!=null&&(n.image={isInline:t.rend===`inline`,isPrimary:t.isPrimary??!1,heightPreview:t.heightPreview,widthPreview:t.widthPreview,height:t.height,width:t.width}),r.push(n)}return r}
|
|
292
292
|
/**
|
|
293
293
|
* Parses an array of raw links into standardized Link objects
|
|
294
294
|
*
|
|
295
295
|
* @param links - Array of raw OCHRE links
|
|
296
296
|
* @returns Array of parsed Link objects
|
|
297
297
|
*/
|
|
298
|
-
function
|
|
298
|
+
function P(e){let t=[];for(let n of e)t.push(...ne(n));return t}
|
|
299
299
|
/**
|
|
300
300
|
* Parses raw document content into a standardized Document structure
|
|
301
301
|
*
|
|
@@ -303,14 +303,14 @@ function N(e){let t=[];for(let n of e)t.push(...ne(n));return t}
|
|
|
303
303
|
* @param language - Language code to use for content selection (defaults to "eng")
|
|
304
304
|
* @returns Parsed Document object with content and footnotes
|
|
305
305
|
*/
|
|
306
|
-
function
|
|
306
|
+
function F(e,t=`eng`){let n=``,r=[],i=Array.isArray(e)?e.find(e=>e.lang===t):e;if(typeof i.string==`string`||typeof i.string==`number`||typeof i.string==`boolean`)n+=v(x(i.string));else{let e=Array.isArray(i.string)?i.string:[i.string];for(let t of e)n+=C(t,r)}return{content:n,footnotes:r}}
|
|
307
307
|
/**
|
|
308
308
|
* Parses raw image data into a standardized Image structure
|
|
309
309
|
*
|
|
310
310
|
* @param image - Raw image data in OCHRE format
|
|
311
311
|
* @returns Parsed Image object or null if invalid
|
|
312
312
|
*/
|
|
313
|
-
function
|
|
313
|
+
function I(e){return{publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),identification:e.identification?O(e.identification):null,url:e.href??(e.htmlImgSrcPrefix==null&&e.content!=null?x(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?x(e.content):null,widthPreview:e.widthPreview??null,heightPreview:e.heightPreview??null,width:e.width??null,height:e.height??null}}
|
|
314
314
|
/**
|
|
315
315
|
* Parses raw notes into standardized Note objects
|
|
316
316
|
*
|
|
@@ -318,35 +318,35 @@ function F(e){return{publicationDateTime:e.publicationDateTime==null?null:new Da
|
|
|
318
318
|
* @param language - Language code for content selection (defaults to "eng")
|
|
319
319
|
* @returns Array of parsed Note objects
|
|
320
320
|
*/
|
|
321
|
-
function
|
|
321
|
+
function L(e,t=`eng`){let n=[];for(let r of e){if(typeof r==`string`){if(r===``)continue;n.push({number:-1,title:null,content:r});continue}let e=``,i=Array.isArray(r.content)?r.content:[r.content],a=i.find(e=>e.lang===t);if(!a&&(a=i[0],!a))throw Error(`Note does not have a valid content item: ${JSON.stringify(r,null,2)}`);e=typeof a.string==`string`||typeof a.string==`number`||typeof a.string==`boolean`?v(x(a.string)):v(F(a).content),n.push({number:r.noteNo,title:a.title==null?null:x(a.title),content:e})}return n}
|
|
322
322
|
/**
|
|
323
323
|
* Parses raw coordinates data into a standardized Coordinates structure
|
|
324
324
|
*
|
|
325
325
|
* @param coordinates - Raw coordinates data in OCHRE format
|
|
326
326
|
* @returns Parsed Coordinates object
|
|
327
327
|
*/
|
|
328
|
-
function
|
|
328
|
+
function R(e){if(typeof e==`string`){let[t,n]=e.split(`, `);return{latitude:Number(t),longitude:Number(n),type:null,label:null}}return{latitude:e.latitude,longitude:e.longitude,type:e.coord?.coordType??null,label:e.coord?.coordLabel==null?null:x(e.coord.coordLabel)}}
|
|
329
329
|
/**
|
|
330
330
|
* Parses a raw observation into a standardized Observation structure
|
|
331
331
|
*
|
|
332
332
|
* @param observation - Raw observation data in OCHRE format
|
|
333
333
|
* @returns Parsed Observation object
|
|
334
334
|
*/
|
|
335
|
-
function
|
|
335
|
+
function z(e){return{number:e.observationNo,date:e.date==null?null:new Date(e.date),observers:e.observers==null?[]:x(e.observers).split(`;`).map(e=>e.trim()),notes:e.notes?L(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?P(Array.isArray(e.links)?e.links:[e.links]):[],properties:e.properties?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}
|
|
336
336
|
/**
|
|
337
337
|
* Parses an array of raw observations into standardized Observation objects
|
|
338
338
|
*
|
|
339
339
|
* @param observations - Array of raw observations in OCHRE format
|
|
340
340
|
* @returns Array of parsed Observation objects
|
|
341
341
|
*/
|
|
342
|
-
function re(e){let t=[];for(let n of e)t.push(
|
|
342
|
+
function re(e){let t=[];for(let n of e)t.push(z(n));return t}
|
|
343
343
|
/**
|
|
344
344
|
* Parses an array of raw events into standardized Event objects
|
|
345
345
|
*
|
|
346
346
|
* @param events - Array of raw events in OCHRE format
|
|
347
347
|
* @returns Array of parsed Event objects
|
|
348
348
|
*/
|
|
349
|
-
function
|
|
349
|
+
function B(e){let t=[];for(let n of e)t.push({date:n.dateTime==null?null:new Date(n.dateTime),label:w(n.label),agent:n.agent?{uuid:n.agent.uuid,content:x(n.agent.content)}:null});return t}function ie(e,t=`eng`){let n=`value`in e&&e.value?Array.isArray(e.value)?e.value:[e.value]:[],r=n.map(e=>{let t=null,n=null;if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`){t=x(e);let r={content:t,booleanValue:n,isUncertain:!1,type:`string`,category:`value`,uuid:null,publicationDateTime:null,unit:null};return r}else{switch(e.type){case`integer`:case`decimal`:t=Number(e.content);break;case`dateTime`:t=e.content?typeof e.content==`string`?new Date(e.content):new Date(w({content:e.content})):null;break;default:`slug`in e&&e.slug!=null?t=x(e.slug):e.content!=null&&(t=w({content:e.content})),e.type===`boolean`&&(n=e.booleanValue??null);break}let r=`string`;if(e.type!=null){let{data:t,error:n}=o.safeParse(e.type);if(n)throw Error(`Invalid property value content type: "${e.type}"`);r=t}let i={content:t,booleanValue:n,isUncertain:e.isUncertain??!1,type:r,category:e.category??`value`,uuid:e.uuid??null,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),unit:e.unit??null};return i}});return{uuid:e.label.uuid,label:w(e.label,t).replace(/\s*\.{3}$/,``).trim(),values:r,comment:e.comment==null?null:x(e.comment),properties:e.property?V(Array.isArray(e.property)?e.property:[e.property]):[]}}
|
|
350
350
|
/**
|
|
351
351
|
* Parses raw properties into standardized Property objects
|
|
352
352
|
*
|
|
@@ -354,112 +354,112 @@ function z(e){let t=[];for(let n of e)t.push({date:n.dateTime==null?null:new Dat
|
|
|
354
354
|
* @param language - Language code for content selection (defaults to "eng")
|
|
355
355
|
* @returns Array of parsed Property objects
|
|
356
356
|
*/
|
|
357
|
-
function
|
|
357
|
+
function V(e,t=`eng`){let n=[];for(let r of e)n.push(ie(r,t));return n}
|
|
358
358
|
/**
|
|
359
359
|
* Parses raw interpretations into standardized Interpretation objects
|
|
360
360
|
*
|
|
361
361
|
* @param interpretations - Array of raw interpretations in OCHRE format
|
|
362
362
|
* @returns Array of parsed Interpretation objects
|
|
363
363
|
*/
|
|
364
|
-
function ae(e){let t=[];for(let n of e)t.push({date:new Date(n.date),number:n.interpretationNo,properties:n.properties?
|
|
364
|
+
function ae(e){let t=[];for(let n of e)t.push({date:new Date(n.date),number:n.interpretationNo,properties:n.properties?V(Array.isArray(n.properties.property)?n.properties.property:[n.properties.property]):[]});return t}
|
|
365
365
|
/**
|
|
366
366
|
* Parses raw image map data into a standardized ImageMap structure
|
|
367
367
|
*
|
|
368
368
|
* @param imageMap - Raw image map data in OCHRE format
|
|
369
369
|
* @returns Parsed ImageMap object
|
|
370
370
|
*/
|
|
371
|
-
function oe(e){let
|
|
371
|
+
function oe(e){let n={area:[],width:e.width,height:e.height},r=Array.isArray(e.area)?e.area:[e.area];for(let e of r)n.area.push({uuid:t(),itemUuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),type:e.type,title:x(e.title),shape:e.shape===`rect`?`rectangle`:`polygon`,coords:e.coords.split(`,`).map(e=>Number.parseInt(e))});return n}
|
|
372
372
|
/**
|
|
373
373
|
* Parses raw period data into a standardized Period structure
|
|
374
374
|
*
|
|
375
375
|
* @param period - Raw period data in OCHRE format
|
|
376
376
|
* @returns Parsed Period object
|
|
377
377
|
*/
|
|
378
|
-
function
|
|
378
|
+
function H(e){return{uuid:e.uuid,category:`period`,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),type:e.type??null,number:e.n??null,identification:O(e.identification),description:e.description?w(e.description):null}}
|
|
379
379
|
/**
|
|
380
380
|
* Parses an array of raw periods into standardized Period objects
|
|
381
381
|
*
|
|
382
382
|
* @param periods - Array of raw periods in OCHRE format
|
|
383
383
|
* @returns Array of parsed Period objects
|
|
384
384
|
*/
|
|
385
|
-
function
|
|
385
|
+
function U(e){let t=[];for(let n of e)t.push(H(n));return t}
|
|
386
386
|
/**
|
|
387
387
|
* Parses raw bibliography data into a standardized Bibliography structure
|
|
388
388
|
*
|
|
389
389
|
* @param bibliography - Raw bibliography data in OCHRE format
|
|
390
390
|
* @returns Parsed Bibliography object
|
|
391
391
|
*/
|
|
392
|
-
function
|
|
392
|
+
function W(e){let t=null;return e.source?.resource&&(t={uuid:e.source.resource.uuid,publicationDateTime:e.source.resource.publicationDateTime?new Date(e.source.resource.publicationDateTime):null,type:e.source.resource.type,identification:O(e.source.resource.identification)}),{uuid:e.uuid,category:`bibliography`,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),type:e.type??null,number:e.n??null,identification:e.identification?O(e.identification):null,projectIdentification:e.project?.identification?O(e.project.identification):null,context:e.context?A(e.context):null,citation:{format:e.citationFormat??null,short:e.citationFormatSpan?x(`default:span`in e.citationFormatSpan?e.citationFormatSpan[`default:span`].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?x(`default:div`in e.referenceFormatDiv?e.referenceFormatDiv[`default:div`][`default:div`].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?N(Array.isArray(e.publicationInfo.publishers.publishers.person)?e.publicationInfo.publishers.publishers.person:[e.publicationInfo.publishers.publishers.person]):[],startDate:e.publicationInfo?.startDate?new Date(e.publicationInfo.startDate.year,e.publicationInfo.startDate.month,e.publicationInfo.startDate.day):null},entryInfo:e.entryInfo?{startIssue:x(e.entryInfo.startIssue),startVolume:x(e.entryInfo.startVolume)}:null,source:{resource:t,documentUrl:e.sourceDocument?`https://ochre.lib.uchicago.edu/ochre?uuid=${e.sourceDocument.uuid}&load`:null},periods:e.periods?U(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],authors:e.authors?N(Array.isArray(e.authors.person)?e.authors.person:[e.authors.person]):[],properties:e.properties?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}
|
|
393
393
|
/**
|
|
394
394
|
* Parses an array of raw bibliographies into standardized Bibliography objects
|
|
395
395
|
*
|
|
396
396
|
* @param bibliographies - Array of raw bibliographies in OCHRE format
|
|
397
397
|
* @returns Array of parsed Bibliography objects
|
|
398
398
|
*/
|
|
399
|
-
function
|
|
399
|
+
function G(e){let t=[];for(let n of e)t.push(W(n));return t}
|
|
400
400
|
/**
|
|
401
401
|
* Parses raw property value data into a standardized PropertyValue structure
|
|
402
402
|
*
|
|
403
403
|
* @param propertyValue - Raw property value data in OCHRE format
|
|
404
404
|
* @returns Parsed PropertyValue object
|
|
405
405
|
*/
|
|
406
|
-
function
|
|
406
|
+
function K(e){return{uuid:e.uuid,category:`propertyValue`,number:e.n,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,context:e.context?A(e.context):null,availability:e.availability?j(e.availability):null,identification:O(e.identification),date:e.date?new Date(e.date):null,creators:e.creators?N(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?x(e.description):w(e.description):``,notes:e.notes?L(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?P(Array.isArray(e.links)?e.links:[e.links]):[]}}
|
|
407
407
|
/**
|
|
408
408
|
* Parses an array of raw property values into standardized PropertyValue objects
|
|
409
409
|
*
|
|
410
410
|
* @param propertyValues - Array of raw property values in OCHRE format
|
|
411
411
|
* @returns Array of parsed PropertyValue objects
|
|
412
412
|
*/
|
|
413
|
-
function
|
|
413
|
+
function q(e){let t=[];for(let n of e)t.push(K(n));return t}
|
|
414
414
|
/**
|
|
415
415
|
* Parses a raw tree structure into a standardized Tree object
|
|
416
416
|
*
|
|
417
417
|
* @param tree - Raw tree data in OCHRE format
|
|
418
418
|
* @returns Parsed Tree object or null if invalid
|
|
419
419
|
*/
|
|
420
|
-
function se(e){let t=[];e.creators&&(t=
|
|
420
|
+
function se(e){let t=[];e.creators&&(t=N(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]));let n=null;e.date!=null&&(n=new Date(e.date));let r=[],i=[],a=[],o=[],s=[],c=[],l=[];typeof e.items!=`string`&&`resource`in e.items&&(r=Y(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource])),typeof e.items!=`string`&&`spatialUnit`in e.items&&(i=Z(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit])),typeof e.items!=`string`&&`concept`in e.items&&(a=ue(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept])),typeof e.items!=`string`&&`period`in e.items&&(o=U(Array.isArray(e.items.period)?e.items.period:[e.items.period])),typeof e.items!=`string`&&`bibliography`in e.items&&(s=G(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography])),typeof e.items!=`string`&&`person`in e.items&&(c=N(Array.isArray(e.items.person)?e.items.person:[e.items.person])),typeof e.items!=`string`&&`propertyValue`in e.items&&(l=q(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]));let u={uuid:e.uuid,category:`tree`,publicationDateTime:new Date(e.publicationDateTime),identification:O(e.identification),creators:t,license:j(e.availability),date:n,type:e.type,number:e.n,items:{resources:r,spatialUnits:i,concepts:a,periods:o,bibliographies:s,persons:c,propertyValues:l},properties:e.properties?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return u}
|
|
421
421
|
/**
|
|
422
422
|
* Parses raw set data into a standardized Set structure
|
|
423
423
|
*
|
|
424
424
|
* @param set - Raw set data in OCHRE format
|
|
425
425
|
* @returns Parsed Set object
|
|
426
426
|
*/
|
|
427
|
-
function ce(e,t){if(typeof e.items==`string`)throw TypeError(`Invalid OCHRE data: Set has no items`);let n=t??
|
|
427
|
+
function ce(e,t){if(typeof e.items==`string`)throw TypeError(`Invalid OCHRE data: Set has no items`);let n=t??T(Object.keys(e.items)),r=[];switch(n){case`resource`:if(!(`resource`in e.items))throw Error(`Invalid OCHRE data: Set has no resources`);r=Y(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource]);break;case`spatialUnit`:if(!(`spatialUnit`in e.items))throw Error(`Invalid OCHRE data: Set has no spatial units`);r=Z(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit]);break;case`concept`:if(!(`concept`in e.items))throw Error(`Invalid OCHRE data: Set has no concepts`);r=ue(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept]);break;case`period`:if(!(`period`in e.items))throw Error(`Invalid OCHRE data: Set has no periods`);r=U(Array.isArray(e.items.period)?e.items.period:[e.items.period]);break;case`bibliography`:if(!(`bibliography`in e.items))throw Error(`Invalid OCHRE data: Set has no bibliographies`);r=G(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography]);break;case`person`:if(!(`person`in e.items))throw Error(`Invalid OCHRE data: Set has no persons`);r=N(Array.isArray(e.items.person)?e.items.person:[e.items.person]);break;case`propertyValue`:if(!(`propertyValue`in e.items))throw Error(`Invalid OCHRE data: Set has no property values`);r=q(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]);break;default:throw Error(`Invalid OCHRE data: Set has no items or is malformed`)}return{uuid:e.uuid,category:`set`,itemCategory:t,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,date:e.date==null?null:new Date(e.date),license:j(e.availability),identification:O(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?x(e.description):w(e.description):``,creators:e.creators?N(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],type:e.type,number:e.n,items:r}}
|
|
428
428
|
/**
|
|
429
429
|
* Parses raw resource data into a standardized Resource structure
|
|
430
430
|
*
|
|
431
431
|
* @param resource - Raw resource data in OCHRE format
|
|
432
432
|
* @returns Parsed Resource object
|
|
433
433
|
*/
|
|
434
|
-
function
|
|
434
|
+
function J(e){let t={uuid:e.uuid,category:`resource`,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,type:e.type,number:e.n,format:e.format??null,context:`context`in e&&e.context?A(e.context):null,license:`availability`in e&&e.availability?j(e.availability):null,copyright:`copyright`in e&&e.copyright!=null?x(e.copyright):null,identification:O(e.identification),date:e.date==null?null:new Date(e.date),image:e.image?I(e.image):null,creators:e.creators?N(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],notes:e.notes?L(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?x(e.description):w(e.description):``,document:e.document&&`content`in e.document?F(e.document.content):null,href:e.href??null,imageMap:e.imagemap?oe(e.imagemap):null,periods:e.periods?U(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],links:e.links?P(Array.isArray(e.links)?e.links:[e.links]):[],reverseLinks:e.reverseLinks?P(Array.isArray(e.reverseLinks)?e.reverseLinks:[e.reverseLinks]):[],properties:e.properties?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],citedBibliographies:e.citedBibliography?G(Array.isArray(e.citedBibliography.reference)?e.citedBibliography.reference:[e.citedBibliography.reference]):[],resources:e.resource?Y(Array.isArray(e.resource)?e.resource:[e.resource]):[]};return t}
|
|
435
435
|
/**
|
|
436
436
|
* Parses raw resource data into a standardized Resource structure
|
|
437
437
|
*
|
|
438
438
|
* @param resources - Raw resource data in OCHRE format
|
|
439
439
|
* @returns Parsed Resource object
|
|
440
440
|
*/
|
|
441
|
-
function
|
|
441
|
+
function Y(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(J(e));return t}
|
|
442
442
|
/**
|
|
443
443
|
* Parses raw spatial units into standardized SpatialUnit objects
|
|
444
444
|
*
|
|
445
445
|
* @param spatialUnit - Raw spatial unit in OCHRE format
|
|
446
446
|
* @returns Parsed SpatialUnit object
|
|
447
447
|
*/
|
|
448
|
-
function
|
|
448
|
+
function X(e){let t={uuid:e.uuid,category:`spatialUnit`,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),type:e.type,number:e.n,context:`context`in e&&e.context?A(e.context):null,license:`availability`in e&&e.availability?j(e.availability):null,identification:O(e.identification),image:e.image?I(e.image):null,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?x(e.description):w(e.description):``,coordinates:e.coordinates?R(e.coordinates):e.coordinate?R(e.coordinate):null,observations:`observations`in e&&e.observations?re(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[z(e.observation)]:[],events:`events`in e&&e.events?B(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:`properties`in e&&e.properties?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return t}
|
|
449
449
|
/**
|
|
450
450
|
* Parses an array of raw spatial units into standardized SpatialUnit objects
|
|
451
451
|
*
|
|
452
452
|
* @param spatialUnits - Array of raw spatial units in OCHRE format
|
|
453
453
|
* @returns Array of parsed SpatialUnit objects
|
|
454
454
|
*/
|
|
455
|
-
function
|
|
455
|
+
function Z(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(X(e));return t}
|
|
456
456
|
/**
|
|
457
457
|
* Parses a raw concept into a standardized Concept object
|
|
458
458
|
*
|
|
459
459
|
* @param concept - Raw concept data in OCHRE format
|
|
460
460
|
* @returns Parsed Concept object
|
|
461
461
|
*/
|
|
462
|
-
function
|
|
462
|
+
function Q(e){let t={uuid:e.uuid,category:`concept`,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,number:e.n,license:`availability`in e&&e.availability?j(e.availability):null,context:`context`in e&&e.context?A(e.context):null,identification:O(e.identification),interpretations:ae(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation])};return t}
|
|
463
463
|
/**
|
|
464
464
|
* Parses raw webpage resources into standardized WebElement or Webpage objects
|
|
465
465
|
*
|
|
@@ -467,14 +467,14 @@ function Z(e){let t={uuid:e.uuid,category:`concept`,publicationDateTime:e.public
|
|
|
467
467
|
* @param type - Type of resource to parse ("element" or "page")
|
|
468
468
|
* @returns Array of parsed WebElement or Webpage objects
|
|
469
469
|
*/
|
|
470
|
-
const le=async(e,t)=>{let n=[];for(let r of e){let e=r.properties?
|
|
470
|
+
const le=async(e,t)=>{let n=[];for(let r of e){let e=r.properties?V(Array.isArray(r.properties.property)?r.properties.property:[r.properties.property]):[],i=e.find(e=>e.label===`presentation`&&e.values[0].content===t);if(!i)continue;switch(t){case`element`:{let e=await $(r);n.push(e);break}case`page`:{let e=await fe(r);e&&n.push(e);break}case`block`:{let e=await me(r);e&&n.push(e);break}}}return n};
|
|
471
471
|
/**
|
|
472
472
|
* Parses raw concept data into standardized Concept objects
|
|
473
473
|
*
|
|
474
474
|
* @param concepts - Array of raw concept data in OCHRE format
|
|
475
475
|
* @returns Array of parsed Concept objects
|
|
476
476
|
*/
|
|
477
|
-
function ue(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(
|
|
477
|
+
function ue(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(Q(e));return t}
|
|
478
478
|
/**
|
|
479
479
|
* Parses raw web element properties into a standardized WebElementComponent structure
|
|
480
480
|
*
|
|
@@ -482,21 +482,21 @@ function ue(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(Z(e));ret
|
|
|
482
482
|
* @param elementResource - Raw element resource data in OCHRE format
|
|
483
483
|
* @returns Parsed WebElementComponent object
|
|
484
484
|
*/
|
|
485
|
-
async function de(e,t){let n=
|
|
485
|
+
async function de(e,t){let n=i.parse(e.values[0].content),r={component:n},a=t.links?P(Array.isArray(t.links)?t.links:[t.links]):[],o=a.filter(e=>e.type===`image`||e.type===`IIIF`),s=t.document&&`content`in t.document?F(t.document.content):null;if(s===null){let e=a.find(e=>e.type===`internalDocument`);if(e){let{item:t,error:n}=await D(e.uuid,`resource`);if(n!==null)throw Error(`Failed to fetch OCHRE data`);s=t.document}}switch(n){case`annotated-document`:if(!s)throw Error(`Document not found for the following component: “${n}”`);r.document=s;break;case`annotated-image`:{if(o.length===0)throw Error(`Image link not found for the following component: “${n}”`);let t=m(e.properties,`is-searchable`)===`Yes`;r.imageUuid=o[0].uuid,r.isSearchable=t;break}case`bibliography`:{let t=a.find(e=>e.category===`bibliography`);if(!t)throw Error(`Bibliography link not found for the following component: “${n}”`);if(!t.bibliographies)throw Error(`Bibliography not found for the following component: “${n}”`);let i=m(e.properties,`layout`);i??=`long`,r.bibliographies=t.bibliographies,r.layout=i;break}case`button`:{let i=m(e.properties,`variant`);i??=`default`;let a=!1,o=m(e.properties,`navigate-to`);if(o===null){if(o=m(e.properties,`link-to`),o===null)throw Error(`Properties “navigate-to” or “link-to” not found for the following component: “${n}”`);a=!0}let s=null,c=m(e.properties,`icon`);c!==null&&(s=c),r.variant=i,r.href=o,r.isExternal=a,r.label=[`string`,`number`,`boolean`].includes(typeof t.identification.label)?x(t.identification.label):w(t.identification.label),r.icon=s;break}case`collection`:{let t=a.find(e=>e.category===`set`);if(!t)throw Error(`Collection link not found for the following component: “${n}”`);let i=m(e.properties,`variant`);i??=`full`;let o=m(e.properties,`item-variant`);o??=`default`;let s=!1,c=m(e.properties,`show-count`);c!==null&&(s=c===`Yes`);let l=!1,u=m(e.properties,`is-searchable`);u!==null&&(l=u===`Yes`);let d=m(e.properties,`layout`);d??=`image-start`,r.collectionId=t.uuid,r.variant=i,r.itemVariant=o,r.isSearchable=l,r.showCount=s,r.layout=d;break}case`empty-space`:{let t=m(e.properties,`height`),n=m(e.properties,`width`);r.height=t,r.width=n;break}case`entries`:{let t=a.find(e=>e.category===`tree`);if(!t)throw Error(`Entries link not found for the following component: “${n}”`);let i=m(e.properties,`variant`);i??=`entry`;let o=!1,s=m(e.properties,`is-searchable`);s!==null&&(o=s===`Yes`),r.entriesId=t.uuid,r.variant=i,r.isSearchable=o;break}case`filter-categories`:{let e=a.find(e=>e.category===`set`);if(!e)throw Error(`Filter link not found for the following component: “${n}”`);r.filterId=e.uuid;break}case`iframe`:{let t=a.find(e=>e.type===`webpage`)?.href;if(!t)throw Error(`URL not found for the following component: “${n}”`);let i=m(e.properties,`height`),o=m(e.properties,`width`);r.href=t,r.height=i,r.width=o;break}case`iiif-viewer`:{let e=a.find(e=>e.type===`IIIF`);if(!e)throw Error(`Manifest link not found for the following component: “${n}”`);r.IIIFId=e.uuid;break}case`image`:{if(o.length===0)throw Error(`Image link not found for the following component: “${n}”`);let t=[];for(let e of o)t.push({url:`https://ochre.lib.uchicago.edu/ochre?uuid=${e.uuid}&load`,label:e.identification?.label??null,width:e.image?.width??0,height:e.image?.height??0});let i=m(e.properties,`variant`);i??=`default`;let a=m(e.properties,`layout-caption`);a??=`bottom`;let s=null,c=m(e.properties,`width`);c!==null&&(typeof c==`number`?s=c:typeof c==`string`&&(s=Number.parseFloat(c)));let l=null,u=m(e.properties,`height`);u!==null&&(typeof u==`number`?l=u:typeof u==`string`&&(l=Number.parseFloat(u)));let d=!0,p=m(e.properties,`is-full-width`);p!==null&&(d=p===`Yes`);let h=!0,g=m(e.properties,`is-full-height`);g!==null&&(h=g===`Yes`);let _=m(e.properties,`image-quality`);_??=`high`;let v=m(e.properties,`caption-source`);v??=`name`;let y=m(e.properties,`alt-text-source`);y??=`name`;let b=!1,x=m(e.properties,`is-transparent`);x!==null&&(b=x===`Yes`);let S=!1,C=m(e.properties,`is-cover`);C!==null&&(S=C===`Yes`);let w=null;if(t.length>1){let t=f(e.properties,`variant`),n=5;if(t&&t.values[0].content===`carousel`){let e=m(t.properties,`seconds-per-image`);e!==null&&(typeof e==`number`?n=e:typeof e==`string`&&(n=Number.parseFloat(e)))}w={secondsPerImage:n}}r.images=t,r.variant=i,r.width=s,r.height=l,r.isFullWidth=d,r.isFullHeight=h,r.imageQuality=_,r.captionLayout=a,r.captionSource=v,r.altTextSource=y,r.isTransparentBackground=b,r.isCover=S,r.carouselOptions=w;break}case`image-gallery`:{let t=a.find(e=>e.category===`tree`||e.category===`set`);if(!t)throw Error(`Image gallery link not found for the following component: “${n}”`);let i=m(e.properties,`is-searchable`)===`Yes`;r.galleryId=t.uuid,r.isSearchable=i;break}case`n-columns`:{let e=t.resource?await le(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];r.columns=e;break}case`n-rows`:{let e=t.resource?await le(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];r.rows=e;break}case`network-graph`:break;case`table`:{let e=a.find(e=>e.category===`set`);if(!e)throw Error(`Table link not found for the following component: “${n}”`);r.tableId=e.uuid;break}case`search-bar`:{let t=m(e.properties,`variant`);t??=`default`,r.variant=t;break}case`text`:{if(!s)throw Error(`Document not found for the following component: “${n}”`);let t=m(e.properties,`variant`);t??=`block`;let i=m(e.properties,`heading`);r.variant=t,r.heading=i,r.content=s.content;break}case`timeline`:{let e=a.find(e=>e.category===`tree`);if(!e)throw Error(`Timeline link not found for the following component: “${n}”`);r.timelineId=e.uuid;break}case`video`:{let t=a.find(e=>e.type===`video`);if(!t)throw Error(`Video link not found for the following component: “${n}”`);let i=m(e.properties,`chapters-displayed`);i??=`Yes`,r.videoId=t.uuid,r.isChaptersDislayed=i===`Yes`;break}default:console.warn(`Invalid or non-implemented component name “${n}” for the following element: “${w(t.identification.label)}”`);break}return r}
|
|
486
486
|
/**
|
|
487
487
|
* Parses raw web element data into a standardized WebElement structure
|
|
488
488
|
*
|
|
489
489
|
* @param elementResource - Raw element resource data in OCHRE format
|
|
490
490
|
* @returns Parsed WebElement object
|
|
491
491
|
*/
|
|
492
|
-
async function
|
|
492
|
+
async function $(e){let t=O(e.identification),n=e.properties?.property?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],r=n.find(e=>e.label===`presentation`);if(!r)throw Error(`Presentation property not found for element “${t.label}”`);let i=r.properties.find(e=>e.label===`component`);if(!i)throw Error(`Component for element “${t.label}” not found`);let a=await de(i,e),o=r.properties.find(e=>e.label===`section-sidebar-displayed`),s=o?.values[0]?.booleanValue===!0,c=e.properties?.property?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],l=c.find(e=>e.label===`presentation`&&e.values[0].content===`css`)?.properties??[],u=[];for(let e of l){let t=e.values[0].content;u.push({label:e.label,value:t})}let d=c.find(e=>e.label===`presentation`&&e.values[0].content===`css-mobile`)?.properties??[],f=[];for(let e of d){let t=e.values[0].content;f.push({label:e.label,value:t})}let p=c.find(e=>e.label===`presentation`&&e.values[0].content===`title`)?.properties,h=`default`,g=!1,_=!1,v=!1,y=!1;if(p){let e=m(p,`variant`);e&&(h=e);let t=p.filter(e=>e.label===`display`);t.length>0&&(g=t.some(e=>e.values[0].content===`name`),_=t.some(e=>e.values[0].content===`description`),v=t.some(e=>e.values[0].content===`date`),y=t.some(e=>e.values[0].content===`creators`))}return{uuid:e.uuid,type:`element`,title:{label:t.label,variant:h,properties:{isNameDisplayed:g,isDescriptionDisplayed:_,isDateDisplayed:v,isCreatorsDisplayed:y}},isDisplayedInBlockSectionSidebar:s,cssStyles:u,cssStylesMobile:f,...a}}
|
|
493
493
|
/**
|
|
494
494
|
* Parses raw webpage data into a standardized Webpage structure
|
|
495
495
|
*
|
|
496
496
|
* @param webpageResource - Raw webpage resource data in OCHRE format
|
|
497
497
|
* @returns Parsed Webpage object
|
|
498
498
|
*/
|
|
499
|
-
async function fe(e){let t=e.properties?
|
|
499
|
+
async function fe(e){let t=e.properties?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];if(t.length===0||t.find(e=>e.label===`presentation`)?.values[0]?.content!==`page`)return null;let n=O(e.identification),r=e.slug;if(r===void 0)throw Error(`Slug not found for page “${n.label}”`);let i=e.links?P(Array.isArray(e.links)?e.links:[e.links]):[],a=i.find(e=>e.type===`image`||e.type===`IIIF`),o=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],s=[];for(let e of o){let t=e.properties?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=m(t,`presentation`);if(n==null)continue;switch(n){case`element`:{let t=await $(e);s.push(t);break}case`block`:{let t=await me(e);t&&s.push(t);break}}}let c=e.resource?await le(Array.isArray(e.resource)?e.resource:[e.resource],`page`):[],l=!0,u=`default`,d=`default`,f=!0,p=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`page`)?.properties;if(p){let e=p.find(e=>e.label===`header`)?.values[0];e&&(l=e.content===`Yes`);let t=p.find(e=>e.label===`width`)?.values[0];t&&(u=t.content);let n=p.find(e=>e.label===`variant`)?.values[0];n&&(d=n.content);let r=p.find(e=>e.label===`sidebar-visible`)?.values[0];r&&(f=r.content===`Yes`)}let h=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css`)?.properties,g=[];if(h)for(let e of h)g.push({label:e.label,value:e.values[0].content});let _=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css-mobile`)?.properties,v=[];if(_)for(let e of _)v.push({label:e.label,value:e.values[0].content});return{title:n.label,slug:r,items:s,properties:{displayedInHeader:l,width:u,variant:d,backgroundImageUrl:a?`https://ochre.lib.uchicago.edu/ochre?uuid=${a.uuid}&load`:null,isSidebarDisplayed:f,cssStyles:g,cssStylesMobile:v},webpages:c}}
|
|
500
500
|
/**
|
|
501
501
|
* Parses raw webpage resources into an array of Webpage objects
|
|
502
502
|
*
|
|
@@ -510,14 +510,14 @@ async function pe(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n){let n=awa
|
|
|
510
510
|
* @param blockResource - Raw block resource data in OCHRE format
|
|
511
511
|
* @returns Parsed Block object
|
|
512
512
|
*/
|
|
513
|
-
async function
|
|
513
|
+
async function me(e){let t={uuid:e.uuid,type:`block`,layout:`vertical`,items:[],properties:{spacing:void 0,gap:void 0,alignItems:`start`,justifyContent:`stretch`,sectionSidebarItems:null},propertiesMobile:null,cssStyles:[],cssStylesMobile:[]},n=e.properties?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],r=n.find(e=>e.label===`presentation`&&e.values[0]?.content===`block`)?.properties;if(r){let e=r.find(e=>e.label===`layout`)?.values[0];e&&(t.layout=e.content);let n=r.find(e=>e.label===`spacing`)?.values[0];n&&(t.properties.spacing=n.content);let i=r.find(e=>e.label===`gap`)?.values[0];i&&(t.properties.gap=i.content);let a=r.find(e=>e.label===`align-items`)?.values[0];a&&(t.properties.alignItems=a.content);let o=r.find(e=>e.label===`justify-content`)?.values[0];o&&(t.properties.justifyContent=o.content);let s=r.find(e=>e.label===`overwrite-mobile`);if(s){let e=s.properties,n={};for(let t of e)n[t.label]=t.values[0].content;t.propertiesMobile=n}}let i=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],a=[];for(let e of i){let t=e.properties?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=m(t,`presentation`);if(n==null)continue;switch(n){case`element`:{let t=await $(e);a.push(t);break}case`block`:{let t=await me(e);t&&a.push(t);break}}}t.items=a;let o=n.find(e=>e.label===`presentation`&&e.values[0]?.content===`css`)?.properties;if(o)for(let e of o)t.cssStyles.push({label:e.label,value:e.values[0].content});let s=n.find(e=>e.label===`presentation`&&e.values[0]?.content===`css-mobile`)?.properties;if(s)for(let e of s)t.cssStylesMobile.push({label:e.label,value:e.values[0].content});return t.properties.sectionSidebarItems=he(t),t}function he(e){let t=[];for(let n of e.items)switch(n.type){case`block`:{let e=he(n);e!==null&&t.push({uuid:n.uuid,type:`block`,name:null,items:e});break}case`element`:{let e=n.isDisplayedInBlockSectionSidebar;if(!e)continue;t.push({uuid:n.uuid,type:`element`,name:n.title.label,items:null});break}}return t.length>0?t:null}
|
|
514
514
|
/**
|
|
515
515
|
* Parses raw website properties into a standardized WebsiteProperties structure
|
|
516
516
|
*
|
|
517
517
|
* @param properties - Array of raw website properties in OCHRE format
|
|
518
518
|
* @returns Parsed WebsiteProperties object
|
|
519
519
|
*/
|
|
520
|
-
function
|
|
520
|
+
function ge(e){let t=V(e),n=t.find(e=>e.label===`presentation`)?.properties;if(!n)throw Error(`Presentation property not found`);let i=n.find(e=>e.label===`webUI`)?.values[0]?.content;if(i==null)throw Error(`Website type not found`);let a=n.find(e=>e.label===`status`)?.values[0]?.content;if(a==null)throw Error(`Website status not found`);let o=n.find(e=>e.label===`privacy`)?.values[0]?.content;o??=`public`;let s=r.safeParse({type:i,status:a,privacy:o});if(!s.success)throw Error(`Invalid website properties: ${s.error.message}`);let c=null,l=n.find(e=>e.label===`contact`);if(l){let[e,t]=(l.values[0]?.content).split(`;`);c={name:e,email:t??null}}let u=n.find(e=>e.label===`logo`)?.values[0]?.uuid??null,d=!0,f=`default`,p=`start`,m=!0,h=!0,g=!1,_=!0,v=n.find(e=>e.label===`navbar-visible`)?.values[0];v&&(d=v.content===`Yes`);let y=n.find(e=>e.label===`navbar-variant`)?.values[0];y&&(f=y.content);let b=n.find(e=>e.label===`navbar-alignment`)?.values[0];b&&(p=b.content);let x=n.find(e=>e.label===`navbar-project-visible`)?.values[0];x&&(m=x.content===`Yes`);let S=n.find(e=>e.label===`footer-visible`)?.values[0];S&&(h=S.content===`Yes`);let C=n.find(e=>e.label===`sidebar-visible`)?.values[0];C&&(g=C.content===`Yes`);let w=n.find(e=>e.label===`supports-theme-toggle`)?.values[0];w&&(_=w.content===`Yes`);let{type:T,status:E,privacy:D}=s.data;return{type:T,privacy:D,status:E,contact:c,isHeaderDisplayed:d,headerVariant:f,headerAlignment:p,isHeaderProjectDisplayed:m,isFooterDisplayed:h,isSidebarDisplayed:g,supportsThemeToggle:_,logoUrl:u===null?null:`https://ochre.lib.uchicago.edu/ochre?uuid=${u}&load`}}async function _e(e,t,n){if(!e.properties)throw Error(`Website properties not found`);let r=ge(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]);if(typeof e.items==`string`||!(`resource`in e.items))throw Error(`Website pages not found`);let i=Array.isArray(e.items.resource)?e.items.resource:[e.items.resource],a=await pe(i),o=null,s=[],c={label:``,variant:`default`,properties:{isNameDisplayed:!1,isDescriptionDisplayed:!1,isDateDisplayed:!1,isCreatorsDisplayed:!1}},l=`start`,u=`default`,d=[],f=[],p=i.find(e=>{let t=e.properties?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];return t.some(e=>e.label===`presentation`&&e.values[0]?.content===`element`&&e.properties[0]?.label===`component`&&e.properties[0].values[0]?.content===`sidebar`)});if(p){c.label=typeof p.identification.label==`string`||typeof p.identification.label==`number`||typeof p.identification.label==`boolean`?x(p.identification.label):w(p.identification.label);let e=p.properties?V(Array.isArray(p.properties.property)?p.properties.property:[p.properties.property]):[],t=e.find(e=>e.label===`presentation`&&e.values[0]?.content===`element`)?.properties.find(e=>e.label===`component`&&e.values[0]?.content===`sidebar`)?.properties??[],n=t.find(e=>e.label===`layout`);n&&(l=n.values[0].content);let r=t.find(e=>e.label===`layout-mobile`);r&&(u=r.values[0].content);let i=e.find(e=>e.label===`presentation`&&e.values[0].content===`css`)?.properties??[];for(let e of i){let t=e.values[0].content;d.push({label:e.label,value:t})}let a=e.find(e=>e.label===`presentation`&&e.values[0].content===`css-mobile`)?.properties??[];for(let e of a){let t=e.values[0].content;f.push({label:e.label,value:t})}let o=e.find(e=>e.label===`presentation`&&e.values[0].content===`title`)?.properties;if(o){let e=m(o,`variant`);e&&(c.variant=e);let t=o.filter(e=>e.label===`display`);t.length>0&&(c.properties.isNameDisplayed=t.some(e=>e.values[0].content===`name`),c.properties.isDescriptionDisplayed=t.some(e=>e.values[0].content===`description`),c.properties.isDateDisplayed=t.some(e=>e.values[0].content===`date`),c.properties.isCreatorsDisplayed=t.some(e=>e.values[0].content===`creators`))}let h=p.resource?Array.isArray(p.resource)?p.resource:[p.resource]:[];for(let e of h){let t=await $(e);s.push(t)}}s.length>0&&(o={elements:s,title:c,layout:l,mobileLayout:u,cssStyles:d,cssStylesMobile:f});let h=null;if(e.collectionOptions){let t=[];for(let e of a)for(let n of e.items)n.type===`element`&&n.component===`collection`&&t.push(n.collectionId);h={uuids:t,properties:{metadataUuids:e.collectionOptions.metadataUuids.uuid?(Array.isArray(e.collectionOptions.metadataUuids.uuid)?e.collectionOptions.metadataUuids.uuid:[e.collectionOptions.metadataUuids.uuid]).map(e=>e.content):[],searchUuids:e.collectionOptions.searchUuids.uuid?(Array.isArray(e.collectionOptions.searchUuids.uuid)?e.collectionOptions.searchUuids.uuid:[e.collectionOptions.searchUuids.uuid]).map(e=>e.content):[],labelUuids:e.collectionOptions.labelUuids.uuid?(Array.isArray(e.collectionOptions.labelUuids.uuid)?e.collectionOptions.labelUuids.uuid:[e.collectionOptions.labelUuids.uuid]).map(e=>e.content):[]}}}return{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:O(e.identification),project:{name:x(t),website:n===null?null:x(n)},creators:e.creators?N(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:j(e.availability),pages:a,sidebar:o,properties:r,collectionOptions:h}}
|
|
521
521
|
/**
|
|
522
522
|
* Fetches and parses a gallery from the OCHRE API
|
|
523
523
|
*
|
|
@@ -544,16 +544,16 @@ function he(e){let t=B(e),r=t.find(e=>e.label===`presentation`)?.properties;if(!
|
|
|
544
544
|
* - Project identification
|
|
545
545
|
* - Resources (gallery items)
|
|
546
546
|
*/
|
|
547
|
-
async function
|
|
547
|
+
async function ve(e,t,n,r){try{let{uuid:i,filter:a,page:o,perPage:c}=s.parse({uuid:e,filter:t,page:n,perPage:r}),l=await fetch(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
|
|
548
548
|
for $q in input()/ochre[@uuid='${i}']
|
|
549
549
|
let $filtered := $q//items/resource[contains(lower-case(identification/label), lower-case('${a}'))]
|
|
550
550
|
let $maxLength := count($filtered)
|
|
551
551
|
return <gallery maxLength='{$maxLength}'>
|
|
552
552
|
{$q/metadata/project}
|
|
553
553
|
{$q/metadata/item}
|
|
554
|
-
{$filtered[position() >= ${((
|
|
554
|
+
{$filtered[position() >= ${((o-1)*c+1).toString()} and position() < ${(o*c+1).toString()}]}
|
|
555
555
|
</gallery>
|
|
556
|
-
`)}&format=json`);if(!l.ok)throw Error(`Error fetching gallery items, please try again later.`);let u=await l.json();if(!(`gallery`in u.result))throw Error(`Failed to fetch gallery`);let d=
|
|
556
|
+
`)}&format=json`);if(!l.ok)throw Error(`Error fetching gallery items, please try again later.`);let u=await l.json();if(!(`gallery`in u.result))throw Error(`Failed to fetch gallery`);let d=O(u.result.gallery.item.identification),f=O(u.result.gallery.project.identification),p={identification:d,projectIdentification:f,resources:Y(u.result.gallery.resource?Array.isArray(u.result.gallery.resource)?u.result.gallery.resource:[u.result.gallery.resource]:[]),maxLength:u.result.gallery.maxLength};return{item:p,error:null}}catch(e){return console.error(e),{item:null,error:e instanceof Error?e.message:`Failed to fetch gallery`}}}
|
|
557
557
|
/**
|
|
558
558
|
* Fetches and parses a website configuration from the OCHRE API
|
|
559
559
|
*
|
|
@@ -583,4 +583,4 @@ async function _e(e,t,n,r){try{let{uuid:i,filter:a,page:s,perPage:c}=o.parse({uu
|
|
|
583
583
|
*
|
|
584
584
|
* The abbreviation is case-insensitive and should match the website's configured abbreviation in OCHRE.
|
|
585
585
|
*/
|
|
586
|
-
async function
|
|
586
|
+
async function ye(e){try{let t=await fetch(`https://ochre.lib.uchicago.edu/ochre?xquery=for $q in input()/ochre[tree[@type='lesson'][identification/abbreviation='${e.toLocaleLowerCase(`en-US`)}']] return $q&format=json`);if(!t.ok)throw Error(`Failed to fetch website`);let n=await t.json();if(!(`ochre`in n.result)||!(`tree`in n.result.ochre))throw Error(`Failed to fetch website`);let r=n.result.ochre.metadata.project?.identification?O(n.result.ochre.metadata.project.identification):null,i=await _e(n.result.ochre.tree,r?.label??``,n.result.ochre.metadata.project?.identification.website??null);return i}catch(e){return console.error(e),null}}export{E as fetchByUuid,ve as fetchGallery,D as fetchItem,ye as fetchWebsite,g as filterProperties,f as getPropertyByLabel,m as getPropertyValueByLabel,p as getPropertyValuesByLabel,h as getUniqueProperties,G as parseBibliographies,W as parseBibliography,Q as parseConcept,ue as parseConcepts,A as parseContext,R as parseCoordinates,F as parseDocument,v as parseEmail,B as parseEvents,x as parseFakeString,O as parseIdentification,I as parseImage,oe as parseImageMap,ae as parseInterpretations,ee as parseLanguages,j as parseLicense,ne as parseLink,P as parseLinks,te as parseMetadata,L as parseNotes,z as parseObservation,re as parseObservations,H as parsePeriod,U as parsePeriods,M as parsePerson,N as parsePersons,V as parseProperties,ie as parseProperty,K as parsePropertyValue,q as parsePropertyValues,J as parseResource,Y as parseResources,ce as parseSet,X as parseSpatialUnit,Z as parseSpatialUnits,w as parseStringContent,C as parseStringDocumentItem,S as parseStringItem,se as parseTree,_e as parseWebsite};
|