@digitalculture/ochre-sdk 0.8.10 → 0.8.12
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 +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2,7 +2,7 @@ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=
|
|
|
2
2
|
`:``;if(`links`in e){let n=``;n=typeof e.string==`object`?T(e.string):S(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=S(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)?S(t.identification.label):T(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+=w(e,t);return`whitespace`in e&&e.whitespace!=null&&(n=x(y(n),e.whitespace)),n.replaceAll(`'`,`'`)}else n=S(e.content),e.rend!=null&&(n=b(y(n),e.rend)),e.whitespace!=null&&(n=x(y(n),e.whitespace));return n}function T(e,t=`eng`){switch(typeof e.content){case`string`:case`number`:case`boolean`:return S(e.content);case`object`:if(Array.isArray(e.content)){let n=v(e.content,t);if(n)return C(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 C(n)}}else return C(e.content);default:return String(e.content)}}async function E(e,t){try{let n=await(t??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
|
|
3
3
|
for $q in input()/ochre[@uuid='${e}']/resource/document/content//string[@annotation][links][properties/property/value/@uuid="b254b5a4-d91f-4954-8bbc-658faefc626c"]/links/child::node(), $r in input()/ochre[@uuid=$q/@uuid]
|
|
4
4
|
return <footnote> {$r/resource/document} { $r/@uuid} </footnote>`)}
|
|
5
|
-
&format=json&lang="*"`);if(!n.ok)throw Error(`Error fetching footnote, please try again later.`);let r=await n.json();if(!(`footnote`in r.result))throw Error(`Failed to fetch footnote`);let i=Array.isArray(r.result.footnote)?r.result.footnote:[r.result.footnote],a=i.map(e=>{let t=``,n=Array.isArray(e.document.string)?e.document.string:[e.document.string];for(let e of n)t+=w(e);return{uuid:e.uuid,label:``,content:t}});return{items:a,error:null}}catch(e){return console.error(e),{items:null,error:e instanceof Error?e.message:`Failed to fetch footnote`}}}const D={includeNestedProperties:!1};function O(e,t,n=D){let{includeNestedProperties:r}=n,i=e.find(e=>e.uuid===t);if(i)return i;if(r){for(let n of e)if(n.properties.length>0){let e=O(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function k(e,t,n=D){let{includeNestedProperties:r}=n,i=e.find(e=>e.uuid===t);if(i)return i.values.map(e=>e.content);if(r){for(let n of e)if(n.properties.length>0){let e=k(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function ee(e,t,n=D){let{includeNestedProperties:r}=n,i=k(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=ee(n.properties,t,{includeNestedProperties:r});if(e!==null)return e}}return null}function A(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=A(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function j(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=j(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function M(e,t,n=D){let{includeNestedProperties:r}=n,i=j(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}function N(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=N(t.properties,{includeNestedProperties:!0});for(let t of e){if(r.some(e=>e.uuid===t.uuid))continue;r.push(t)}}}return r}function P(e,t=D){let{includeNestedProperties:n}=t,r=[];for(let t of e){if(r.includes(t.label))continue;if(r.push(t.label),t.properties.length>0&&n){let e=P(t.properties,{includeNestedProperties:!0});for(let t of e){if(r.includes(t))continue;r.push(t)}}}return r}function te(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.content===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=>te(e,t,{includeNestedProperties:!0}))),n}return!1}function ne(e){let t=e.find(e=>f.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=f.parse(t);return n}async function re(e,t){try{let n=l.parse(e),r=await(t??fetch)(`https://ochre.lib.uchicago.edu/ochre?uuid=${n}&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]}}async function ie(e,t,n,r){try{let[i,a]=await re(e,r);if(i!==null)throw Error(i);let o=ne(Object.keys(a.ochre)),s;switch(o){case`resource`:if(!(`resource`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'resource' key`);s=ye(a.ochre.resource);break;case`spatialUnit`:if(!(`spatialUnit`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'spatialUnit' key`);s=be(a.ochre.spatialUnit);break;case`concept`:if(!(`concept`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'concept' key`);s=Se(a.ochre.concept);break;case`period`:if(!(`period`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'period' key`);s=pe(a.ochre.period);break;case`bibliography`:if(!(`bibliography`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'bibliography' key`);s=me(a.ochre.bibliography);break;case`person`:if(!(`person`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'person' key`);s=se(a.ochre.person);break;case`propertyValue`:if(!(`propertyValue`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'propertyValue' key`);s=he(a.ochre.propertyValue);break;case`set`:if(!(`set`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'set' key`);s=ve(a.ochre.set,n);break;case`tree`:if(!(`tree`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'tree' key`);s=_e(a.ochre.tree);break;default:throw Error(`Invalid category`)}let c=oe(a.ochre.metadata),l={uuid:a.ochre.uuidBelongsTo,abbreviation:S(a.ochre.belongsTo)};return{error:null,metadata:c,belongsTo:l,item:s,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}}}function F(e){try{let t={label:[`string`,`number`,`boolean`].includes(typeof e.label)?S(e.label):T(e.label),abbreviation:``};for(let n of Object.keys(e).filter(e=>e!==`label`))t[n]=T(e[n]);return t}catch(e){return console.error(e),{label:``,abbreviation:``}}}function ae(e){return e==null?[`eng`]:Array.isArray(e)?e.map(e=>T(e)):[T(e)]}function oe(e){let t={label:``,abbreviation:``};if(e.item)if(e.item.label||e.item.abbreviation){let n=``,r=``;e.item.label&&(n=T(e.item.label)),e.item.abbreviation&&(r=T(e.item.abbreviation)),t={label:n,abbreviation:r}}else t=F(e.item.identification);let n=null,r=e.project?.identification?F(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:T(e.dataset),publisher:T(e.publisher),languages:ae(e.language),identifier:T(e.identifier),description:T(e.description)}}function I(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),number:e.n,content:S(e.content)}}function L(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(I(e))}return{tree:I(e.tree),project:I(e.project),spatialUnit:t}}),displayPath:e.displayPath};return n}function R(e){return typeof e.license==`string`?null:{content:e.license.content,url:e.license.target}}function se(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?L(e.context):null,date:e.date==null?null:new Date(e.date),identification:e.identification?F(e.identification):null,availability:e.availability?R(e.availability):null,address:e.address?{country:e.address.country??null,city:e.address.city??null,state:e.address.state??null}:null,description:e.description?typeof e.description==`string`||typeof e.description==`number`||typeof e.description==`boolean`?S(e.description):T(e.description):null,coordinates:W(e.coordinates),content:e.content==null?null:S(e.content),notes:e.notes?U(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],events:e.events?K(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:e.properties?q(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function z(e){let t=[];for(let n of e)t.push(se(n));return t}function ce(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:S(t.content):null,href:`href`in t&&t.href!=null?t.href:null,fileFormat:`fileFormat`in t&&t.fileFormat!=null?t.fileFormat:null,uuid:t.uuid,type:t.type??null,identification:t.identification?F(t.identification):null,image:null,bibliographies:`bibliography`in e?Y(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}function B(e){let t=[];for(let n of e)t.push(...ce(n));return t}function V(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+=y(S(i.string));else{let e=Array.isArray(i.string)?i.string:[i.string];for(let t of e)n+=w(t,r)}return{content:n,footnotes:r}}function H(e){return{publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),identification:e.identification?F(e.identification):null,url:e.href??(e.htmlImgSrcPrefix==null&&e.content!=null?S(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?S(e.content):null,widthPreview:e.widthPreview??null,heightPreview:e.heightPreview??null,width:e.width??null,height:e.height??null}}function U(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`?y(S(a.string)):y(V(a).content),n.push({number:r.noteNo,title:a.title==null?null:S(a.title),content:e})}return n}function W(e){if(e==null)return[];let t=[],n=Array.isArray(e.coord)?e.coord:[e.coord];for(let e of n){let n=`source`in e&&e.source?e.source.context===`self`?{context:`self`,uuid:e.source.label.uuid,label:T(e.source.label)}:e.source.context===`related`?{context:`related`,uuid:e.source.label.uuid,label:T(e.source.label),value:T(e.source.value)}:{context:`inherited`,uuid:e.source.label.uuid,item:{uuid:e.source.item.label.uuid,label:T(e.source.item.label)},label:T(e.source.label)}:null;switch(e.type){case`point`:t.push({type:e.type,latitude:e.latitude,longitude:e.longitude,altitude:e.altitude??null,source:n});break;case`plane`:t.push({type:e.type,minimum:{latitude:e.minimum.latitude,longitude:e.minimum.longitude},maximum:{latitude:e.maximum.latitude,longitude:e.maximum.longitude},source:n});break}}return t}function G(e){return{number:e.observationNo,date:e.date==null?null:new Date(e.date),observers:e.observers==null?[]:typeof e.observers==`string`||typeof e.observers==`number`||typeof e.observers==`boolean`?S(e.observers).split(`;`).map(e=>e.trim()):z(Array.isArray(e.observers)?e.observers:[e.observers]),notes:e.notes?U(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?B(Array.isArray(e.links)?e.links:[e.links]):[],properties:e.properties?q(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function le(e){let t=[];for(let n of e)t.push(G(n));return t}function K(e){let t=[];for(let n of e)t.push({date:n.dateTime==null?null:new Date(n.dateTime),label:T(n.label),agent:n.agent?{uuid:n.agent.uuid,content:S(n.agent.content)}:null});return t}function ue(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=S(e);let r={content:t,booleanLabel:n,isUncertain:!1,type:`string`,category:`value`,uuid:null,publicationDateTime:null,unit:null};return r}else{let r=`string`;if(e.type!=null){let{data:t,error:n}=p.safeParse(e.type);if(n)throw Error(`Invalid property value content type: "${e.type}"`);r=t}switch(r){case`integer`:case`decimal`:t=Number(e.content);break;case`date`:case`dateTime`:t=e.content?typeof e.content==`string`?new Date(e.content):new Date(T({content:e.content})):null;break;case`coordinate`:t=null;break;case`boolean`:e.content!=null&&(n=T({content:e.content})),t=e.booleanValue??null;break;default:`slug`in e&&e.slug!=null?t=S(e.slug):e.content!=null&&(t=T({content:e.content}));break}let i={content:t,booleanLabel: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:T(e.label,t).replace(/\s*\.{3}$/,``).trim(),values:r,comment:e.comment==null?null:S(e.comment),properties:e.property?q(Array.isArray(e.property)?e.property:[e.property]):[]}}function q(e,t=`eng`){let n=[];for(let r of e)n.push(ue(r,t));return n}function de(e){let t=[];for(let n of e)t.push({date:new Date(n.date),number:n.interpretationNo,properties:n.properties?q(Array.isArray(n.properties.property)?n.properties.property:[n.properties.property]):[]});return t}function fe(e){let t={area:[],width:e.width,height:e.height},n=Array.isArray(e.area)?e.area:[e.area];for(let e of n)t.area.push({uuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),type:e.type,title:S(e.title),shape:e.shape===`rect`?`rectangle`:`polygon`,coords:e.coords.split(`,`).map(e=>Number.parseInt(e))});return t}function pe(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:F(e.identification),description:e.description?T(e.description):null}}function J(e){let t=[];for(let n of e)t.push(pe(n));return t}function me(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:F(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?F(e.identification):null,projectIdentification:e.project?.identification?F(e.project.identification):null,context:e.context?L(e.context):null,citation:{format:e.citationFormat??null,short:e.citationFormatSpan?S(`default:span`in e.citationFormatSpan?e.citationFormatSpan[`default:span`].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?S(`default:div`in e.referenceFormatDiv?e.referenceFormatDiv[`default:div`][`default:div`].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?z(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:S(e.entryInfo.startIssue),startVolume:S(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?J(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],authors:e.authors?z(Array.isArray(e.authors.person)?e.authors.person:[e.authors.person]):[],properties:e.properties?q(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function Y(e){let t=[];for(let n of e)t.push(me(n));return t}function he(e){return{uuid:e.uuid,category:`propertyValue`,number:e.n,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,context:e.context?L(e.context):null,availability:e.availability?R(e.availability):null,identification:F(e.identification),date:e.date?new Date(e.date):null,creators:e.creators?z(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],description:e.description?typeof e.description==`string`||typeof e.description==`number`||typeof e.description==`boolean`?S(e.description):T(e.description):``,notes:e.notes?U(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?B(Array.isArray(e.links)?e.links:[e.links]):[]}}function ge(e){let t=[];for(let n of e)t.push(he(n));return t}function _e(e){let t=[];e.creators&&(t=z(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=X(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource])),typeof e.items!=`string`&&`spatialUnit`in e.items&&(i=xe(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit])),typeof e.items!=`string`&&`concept`in e.items&&(a=Ce(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept])),typeof e.items!=`string`&&`period`in e.items&&(o=J(Array.isArray(e.items.period)?e.items.period:[e.items.period])),typeof e.items!=`string`&&`bibliography`in e.items&&(s=Y(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography])),typeof e.items!=`string`&&`person`in e.items&&(c=z(Array.isArray(e.items.person)?e.items.person:[e.items.person])),typeof e.items!=`string`&&`propertyValue`in e.items&&(l=ge(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]));let u={uuid:e.uuid,category:`tree`,publicationDateTime:new Date(e.publicationDateTime),identification:F(e.identification),creators:t,license:R(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?q(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return u}function ve(e,t){if(typeof e.items==`string`)throw TypeError(`Invalid OCHRE data: Set has no items`);let n=t??ne(Object.keys(e.items)),r=[];switch(n){case`resource`:if(!(`resource`in e.items))throw Error(`Invalid OCHRE data: Set has no resources`);r=X(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=xe(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=Ce(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=J(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=Y(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=z(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=ge(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:R(e.availability),identification:F(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?S(e.description):T(e.description):``,creators:e.creators?z(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],type:e.type,number:e.n,items:r}}function ye(e){let t={uuid:e.uuid,category:`resource`,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,type:e.type,number:e.n,fileFormat:e.fileFormat??null,context:`context`in e&&e.context?L(e.context):null,license:`availability`in e&&e.availability?R(e.availability):null,copyright:`copyright`in e&&e.copyright!=null?S(e.copyright):null,identification:F(e.identification),date:e.date==null?null:new Date(e.date),image:e.image?H(e.image):null,creators:e.creators?z(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],notes:e.notes?U(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?S(e.description):T(e.description):``,coordinates:e.coordinates?W(e.coordinates):[],document:e.document&&`content`in e.document?V(e.document.content):null,href:e.href??null,imageMap:e.imagemap?fe(e.imagemap):null,periods:e.periods?J(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],links:e.links?B(Array.isArray(e.links)?e.links:[e.links]):[],reverseLinks:e.reverseLinks?B(Array.isArray(e.reverseLinks)?e.reverseLinks:[e.reverseLinks]):[],properties:e.properties?q(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],citedBibliographies:e.citedBibliography?Y(Array.isArray(e.citedBibliography.reference)?e.citedBibliography.reference:[e.citedBibliography.reference]):[],resources:e.resource?X(Array.isArray(e.resource)?e.resource:[e.resource]):[]};return t}function X(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(ye(e));return t}function be(e){let t={uuid:e.uuid,category:`spatialUnit`,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),number:e.n,context:`context`in e&&e.context?L(e.context):null,license:`availability`in e&&e.availability?R(e.availability):null,identification:F(e.identification),image:e.image?H(e.image):null,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?S(e.description):T(e.description):``,coordinates:W(e.coordinates),mapData:e.mapData??null,observations:`observations`in e&&e.observations?le(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[G(e.observation)]:[],events:`events`in e&&e.events?K(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:`properties`in e&&e.properties?q(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return t}function xe(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(be(e));return t}function Se(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?R(e.availability):null,context:`context`in e&&e.context?L(e.context):null,identification:F(e.identification),interpretations:de(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation])};return t}const Z=async(e,t)=>{let n=[];for(let r of e){let e=r.properties?q(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 Q(r);n.push(e);break}case`page`:{let e=await Te(r);e&&n.push(e);break}case`block`:{let e=await $(r);e&&n.push(e);break}}}return n};function Ce(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(Se(e));return t}async function we(e,t){let n=d.parse(e.values[0].content),r={component:n},i=t.links?B(Array.isArray(t.links)?t.links:[t.links]):[],a=i.filter(e=>e.type===`image`||e.type===`IIIF`),o=t.document&&`content`in t.document?V(t.document.content):null;if(o===null){let e=i.find(e=>e.type===`internalDocument`);if(e){let{item:t,error:n}=await ie(e.uuid,`resource`);if(n!==null)throw Error(`Failed to fetch OCHRE data`);o=t.document}}switch(n){case`annotated-document`:if(!o)throw Error(`Document not found for the following component: “${n}”`);r.document=o;break;case`annotated-image`:{if(a.length===0)throw Error(`Image link not found for the following component: “${n}”`);let t=M(e.properties,`is-searchable`)===!0;r.imageUuid=a[0].uuid,r.isSearchable=t;break}case`bibliography`:{let t=i.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 a=M(e.properties,`layout`);a??=`long`,r.bibliographies=t.bibliographies,r.layout=a;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)?S(t.identification.label):T(t.identification.label),r.icon=s;break}case`collection`:{let t=i.find(e=>e.category===`set`);if(!t)throw Error(`Collection link not found for the following component: “${n}”`);let a=M(e.properties,`variant`);a??=`full`;let o=M(e.properties,`item-variant`);o??=`default`;let s=!1,c=M(e.properties,`show-count`);c!==null&&(s=c===!0);let l=!1,u=M(e.properties,`is-searchable`);u!==null&&(l=u===!0);let d=M(e.properties,`layout`);d??=`image-start`,r.collectionId=t.uuid,r.variant=a,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=i.find(e=>e.category===`tree`);if(!t)throw Error(`Entries link not found for the following component: “${n}”`);let a=M(e.properties,`variant`);a??=`entry`;let o=!1,s=M(e.properties,`is-searchable`);s!==null&&(o=s===!0),r.entriesId=t.uuid,r.variant=a,r.isSearchable=o;break}case`filter-categories`:{let e=i.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=i.find(e=>e.type===`webpage`)?.href;if(!t)throw Error(`URL not found for the following component: “${n}”`);let a=M(e.properties,`height`),o=M(e.properties,`width`);r.href=t,r.height=a,r.width=o;break}case`iiif-viewer`:{let e=i.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(a.length===0)throw Error(`Image link not found for the following component: “${n}”`);let t=[];for(let e of a)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 o=M(e.properties,`layout-caption`);o??=`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,f=M(e.properties,`is-full-width`);f!==null&&(d=f===!0);let p=!0,m=M(e.properties,`is-full-height`);m!==null&&(p=m===!0);let h=M(e.properties,`image-quality`);h??=`high`;let g=M(e.properties,`caption-source`);g??=`name`;let _=M(e.properties,`alt-text-source`);_??=`name`;let v=!1,y=M(e.properties,`is-transparent`);y!==null&&(v=y===!0);let b=!1,x=M(e.properties,`is-cover`);x!==null&&(b=x===!0);let S=null;if(t.length>1){let t=A(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)))}S={secondsPerImage:n}}r.images=t,r.variant=i,r.width=s,r.height=l,r.isFullWidth=d,r.isFullHeight=p,r.imageQuality=h,r.captionLayout=o,r.captionSource=g,r.altTextSource=_,r.isTransparentBackground=v,r.isCover=b,r.carouselOptions=S;break}case`image-gallery`:{let t=i.find(e=>e.category===`tree`||e.category===`set`);if(!t)throw Error(`Image gallery link not found for the following component: “${n}”`);let a=M(e.properties,`is-searchable`)===!0;r.galleryId=t.uuid,r.isSearchable=a;break}case`map`:{let t=i.find(e=>e.category===`set`||e.category===`tree`);if(!t)throw Error(`Map link not found for the following component: “${n}”`);let a=!0,o=M(e.properties,`is-interactive`);o!==null&&(a=o===!0);let s=!1,c=M(e.properties,`is-clustered`);c!==null&&(s=c===!0);let l=!1,u=M(e.properties,`is-using-pins`);u!==null&&(l=u===!0);let d=null,f=M(e.properties,`custom-basemap`);f!==null&&(d=f);let p=!1,m=M(e.properties,`controls-displayed`);m!==null&&(p=m===!0);let h=!1,g=M(e.properties,`is-full-height`);g!==null&&(h=g===!0),r.mapId=t.uuid,r.isInteractive=a,r.isClustered=s,r.isUsingPins=l,r.customBasemap=d,r.isControlsDisplayed=p,r.isFullHeight=h;break}case`n-columns`:{let e=t.resource?await Z(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];r.columns=e;break}case`n-rows`:{let e=t.resource?await Z(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];r.rows=e;break}case`network-graph`:break;case`table`:{let e=i.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(!o)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=o.content;break}case`timeline`:{let e=i.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=i.find(e=>e.type===`video`);if(!t)throw Error(`Video link not found for the following component: “${n}”`);let a=M(e.properties,`chapters-displayed`);a??=!0,r.videoId=t.uuid,r.isChaptersDislayed=a===!0;break}default:console.warn(`Invalid or non-implemented component name “${n}” for the following element: “${T(t.identification.label)}”`);break}return r}async function Q(e){let t=F(e.identification),n=e.properties?.property?q(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 we(i,e),o=r.properties.find(e=>e.label===`section-sidebar-displayed`),s=o?.values[0]?.content===!0,c=e.properties?.property?q(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,m=`default`,h=!1,g=!1,_=!1,v=!1;if(p){let e=M(p,`variant`);e&&(m=e);let t=p.filter(e=>e.label===`display`);t.length>0&&(h=t.some(e=>e.values[0].content===`name`),g=t.some(e=>e.values[0].content===`description`),_=t.some(e=>e.values[0].content===`date`),v=t.some(e=>e.values[0].content===`creators`))}return{uuid:e.uuid,type:`element`,title:{label:t.label,variant:m,properties:{isNameDisplayed:h,isDescriptionDisplayed:g,isDateDisplayed:_,isCreatorsDisplayed:v}},isDisplayedInBlockSectionSidebar:s,cssStyles:u,cssStylesMobile:f,...a}}async function Te(e){let t=e.properties?q(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=F(e.identification),r=e.slug;if(r===void 0)throw Error(`Slug not found for page “${n.label}”`);let i=e.links?B(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?q(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 Q(e);s.push(t);break}case`block`:{let t=await $(e);t&&s.push(t);break}}}let c=e.resource?await Z(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===!0);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===!0)}let m=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css`)?.properties,h=[];if(m)for(let e of m)h.push({label:e.label,value:e.values[0].content});let g=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css-mobile`)?.properties,_=[];if(g)for(let e of g)_.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:h,cssStylesMobile:_},webpages:c}}async function Ee(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n){let n=await Te(e);n&&t.push(n)}return t}async function $(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?q(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?q(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 Q(e);a.push(t);break}case`block`:{let t=await $(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=De(t),t}function De(e){let t=[];for(let n of e.items)switch(n.type){case`block`:{let e=De(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}function Oe(e){let t=q(e),n=t.find(e=>e.label===`presentation`)?.properties;if(!n)throw Error(`Presentation property not found`);let r=n.find(e=>e.label===`webUI`)?.values[0]?.content;r??=`traditional`;let i=n.find(e=>e.label===`status`)?.values[0]?.content;i??=`development`;let a=n.find(e=>e.label===`privacy`)?.values[0]?.content;a??=`public`;let o=u.safeParse({type:r,status:i,privacy:a});if(!o.success)throw Error(`Invalid website properties: ${o.error.message}`);let s=null,c=n.find(e=>e.label===`contact`);if(c){let[e,t]=(c.values[0]?.content).split(`;`);s={name:e,email:t??null}}let l=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===!0);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===!0);let S=n.find(e=>e.label===`footer-visible`)?.values[0];S&&(h=S.content===!0);let C=n.find(e=>e.label===`sidebar-visible`)?.values[0];C&&(g=C.content===!0);let w=n.find(e=>e.label===`supports-theme-toggle`)?.values[0];w&&(_=w.content===!0);let{type:T,status:E,privacy:D}=o.data;return{type:T,privacy:D,status:E,contact:s,isHeaderDisplayed:d,headerVariant:f,headerAlignment:p,isHeaderProjectDisplayed:m,isFooterDisplayed:h,isSidebarDisplayed:g,supportsThemeToggle:_,logoUrl:l===null?null:`https://ochre.lib.uchicago.edu/ochre?uuid=${l}&load`}}async function ke(e,t,n){if(!e.properties)throw Error(`Website properties not found`);let r=Oe(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 Ee(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?q(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`?S(p.identification.label):T(p.identification.label);let e=p.properties?q(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 m=p.resource?Array.isArray(p.resource)?p.resource:[p.resource]:[];for(let e of m){let t=await Q(e);s.push(t)}}s.length>0&&(o={elements:s,title:c,layout:l,mobileLayout:u,cssStyles:d,cssStylesMobile:f});let m=null;if(e.websiteOptions){let t=`context`in e.websiteOptions.flattenContexts?[e.websiteOptions.flattenContexts]:Array.isArray(e.websiteOptions.flattenContexts)?e.websiteOptions.flattenContexts:[],n=t.map(e=>({context:Array.isArray(e.context)?e.context.flatMap(e=>Array.isArray(e.level)?e.level.map(e=>({variableUuid:e.split(`,`)[0],valueUuid:e.split(`,`)[1]})):[{variableUuid:e.level.split(`,`)[0],valueUuid:e.level.split(`,`)[1]}]):[...Array.isArray(e.context.level)?e.context.level.map(e=>({variableUuid:e.split(`,`)[0],valueUuid:e.split(`,`)[1]})):[{variableUuid:e.context.level.split(`,`)[0],valueUuid:e.context.level.split(`,`)[1]}]]}));m={collectionUuids:`uuid`in e.websiteOptions.collectionUuids?(Array.isArray(e.websiteOptions.collectionUuids.uuid)?e.websiteOptions.collectionUuids.uuid:[e.websiteOptions.collectionUuids.uuid]).map(e=>e.content):[],properties:{metadataUuids:`uuid`in e.websiteOptions.metadataUuids?(Array.isArray(e.websiteOptions.metadataUuids.uuid)?e.websiteOptions.metadataUuids.uuid:[e.websiteOptions.metadataUuids.uuid]).map(e=>e.content):[],searchUuids:`uuid`in e.websiteOptions.searchUuids?(Array.isArray(e.websiteOptions.searchUuids.uuid)?e.websiteOptions.searchUuids.uuid:[e.websiteOptions.searchUuids.uuid]).map(e=>e.content):[],labelUuids:`uuid`in e.websiteOptions.labelUuids?(Array.isArray(e.websiteOptions.labelUuids.uuid)?e.websiteOptions.labelUuids.uuid:[e.websiteOptions.labelUuids.uuid]).map(e=>e.content):[]},flattenContexts:n}}return{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:F(e.identification),project:{name:S(t),website:n===null?null:S(n)},creators:e.creators?z(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:R(e.availability),pages:a,sidebar:o,properties:r,globalOptions:m}}async function Ae(e,t,n,r,i){try{let{uuid:a,filter:o,page:s,perPage:c}=m.parse({uuid:e,filter:t,page:n,perPage:r}),l=await(i??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
|
|
5
|
+
&format=json&lang="*"`);if(!n.ok)throw Error(`Error fetching footnote, please try again later.`);let r=await n.json();if(!(`footnote`in r.result))throw Error(`Failed to fetch footnote`);let i=Array.isArray(r.result.footnote)?r.result.footnote:[r.result.footnote],a=i.map(e=>{let t=``,n=Array.isArray(e.document.string)?e.document.string:[e.document.string];for(let e of n)t+=w(e);return{uuid:e.uuid,label:``,content:t}});return{items:a,error:null}}catch(e){return console.error(e),{items:null,error:e instanceof Error?e.message:`Failed to fetch footnote`}}}const D={includeNestedProperties:!1};function O(e,t,n=D){let{includeNestedProperties:r}=n,i=e.find(e=>e.uuid===t);if(i)return i;if(r){for(let n of e)if(n.properties.length>0){let e=O(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function k(e,t,n=D){let{includeNestedProperties:r}=n,i=e.find(e=>e.uuid===t);if(i)return i.values.map(e=>e.content);if(r){for(let n of e)if(n.properties.length>0){let e=k(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function ee(e,t,n=D){let{includeNestedProperties:r}=n,i=k(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=ee(n.properties,t,{includeNestedProperties:r});if(e!==null)return e}}return null}function A(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=A(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function j(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=j(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function M(e,t,n=D){let{includeNestedProperties:r}=n,i=j(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}function N(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=N(t.properties,{includeNestedProperties:!0});for(let t of e){if(r.some(e=>e.uuid===t.uuid))continue;r.push(t)}}}return r}function P(e,t=D){let{includeNestedProperties:n}=t,r=[];for(let t of e){if(r.includes(t.label))continue;if(r.push(t.label),t.properties.length>0&&n){let e=P(t.properties,{includeNestedProperties:!0});for(let t of e){if(r.includes(t))continue;r.push(t)}}}return r}function te(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.content===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=>te(e,t,{includeNestedProperties:!0}))),n}return!1}function ne(e){let t=e.find(e=>f.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=f.parse(t);return n}async function re(e,t){try{let n=l.parse(e),r=await(t??fetch)(`https://ochre.lib.uchicago.edu/ochre?uuid=${n}&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]}}async function ie(e,t,n,r){try{let[i,a]=await re(e,r);if(i!==null)throw Error(i);let o=ne(Object.keys(a.ochre)),s;switch(o){case`resource`:if(!(`resource`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'resource' key`);s=ye(a.ochre.resource);break;case`spatialUnit`:if(!(`spatialUnit`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'spatialUnit' key`);s=be(a.ochre.spatialUnit);break;case`concept`:if(!(`concept`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'concept' key`);s=Se(a.ochre.concept);break;case`period`:if(!(`period`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'period' key`);s=pe(a.ochre.period);break;case`bibliography`:if(!(`bibliography`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'bibliography' key`);s=me(a.ochre.bibliography);break;case`person`:if(!(`person`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'person' key`);s=se(a.ochre.person);break;case`propertyValue`:if(!(`propertyValue`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'propertyValue' key`);s=he(a.ochre.propertyValue);break;case`set`:if(!(`set`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'set' key`);s=ve(a.ochre.set,n);break;case`tree`:if(!(`tree`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'tree' key`);s=_e(a.ochre.tree);break;default:throw Error(`Invalid category`)}let c=oe(a.ochre.metadata),l={uuid:a.ochre.uuidBelongsTo,abbreviation:S(a.ochre.belongsTo)};return{error:null,metadata:c,belongsTo:l,item:s,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}}}function F(e){try{let t={label:[`string`,`number`,`boolean`].includes(typeof e.label)?S(e.label):T(e.label),abbreviation:``};for(let n of Object.keys(e).filter(e=>e!==`label`))t[n]=T(e[n]);return t}catch(e){return console.error(e),{label:``,abbreviation:``}}}function ae(e){return e==null?[`eng`]:Array.isArray(e)?e.map(e=>T(e)):[T(e)]}function oe(e){let t={label:``,abbreviation:``};if(e.item)if(e.item.label||e.item.abbreviation){let n=``,r=``;e.item.label&&(n=T(e.item.label)),e.item.abbreviation&&(r=T(e.item.abbreviation)),t={label:n,abbreviation:r}}else t=F(e.item.identification);let n=null,r=e.project?.identification?F(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:T(e.dataset),publisher:T(e.publisher),languages:ae(e.language),identifier:T(e.identifier),description:T(e.description)}}function I(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),number:e.n,content:S(e.content)}}function L(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(I(e))}return{tree:I(e.tree),project:I(e.project),spatialUnit:t}}),displayPath:e.displayPath};return n}function R(e){return typeof e.license==`string`?null:{content:e.license.content,url:e.license.target}}function se(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?L(e.context):null,date:e.date==null?null:new Date(e.date),identification:e.identification?F(e.identification):null,availability:e.availability?R(e.availability):null,address:e.address?{country:e.address.country??null,city:e.address.city??null,state:e.address.state??null}:null,description:e.description?typeof e.description==`string`||typeof e.description==`number`||typeof e.description==`boolean`?S(e.description):T(e.description):null,coordinates:W(e.coordinates),content:e.content==null?null:S(e.content),notes:e.notes?U(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],events:e.events?K(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:e.properties?q(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function z(e){let t=[];for(let n of e)t.push(se(n));return t}function ce(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:S(t.content):null,href:`href`in t&&t.href!=null?t.href:null,fileFormat:`fileFormat`in t&&t.fileFormat!=null?t.fileFormat:null,uuid:t.uuid,type:t.type??null,identification:t.identification?F(t.identification):null,image:null,bibliographies:`bibliography`in e?Y(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}function B(e){let t=[];for(let n of e)t.push(...ce(n));return t}function V(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+=y(S(i.string));else{let e=Array.isArray(i.string)?i.string:[i.string];for(let t of e)n+=w(t,r)}return{content:n,footnotes:r}}function H(e){return{publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),identification:e.identification?F(e.identification):null,url:e.href??(e.htmlImgSrcPrefix==null&&e.content!=null?S(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?S(e.content):null,widthPreview:e.widthPreview??null,heightPreview:e.heightPreview??null,width:e.width??null,height:e.height??null}}function U(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`?y(S(a.string)):y(V(a).content),n.push({number:r.noteNo,title:a.title==null?null:S(a.title),content:e})}return n}function W(e){if(e==null)return[];let t=[],n=Array.isArray(e.coord)?e.coord:[e.coord];for(let e of n){let n=`source`in e&&e.source?e.source.context===`self`?{context:`self`,uuid:e.source.label.uuid,label:T(e.source.label)}:e.source.context===`related`?{context:`related`,uuid:e.source.label.uuid,label:T(e.source.label),value:T(e.source.value)}:{context:`inherited`,uuid:e.source.label.uuid,item:{uuid:e.source.item.label.uuid,label:T(e.source.item.label)},label:T(e.source.label)}:null;switch(e.type){case`point`:t.push({type:e.type,latitude:e.latitude,longitude:e.longitude,altitude:e.altitude??null,source:n});break;case`plane`:t.push({type:e.type,minimum:{latitude:e.minimum.latitude,longitude:e.minimum.longitude},maximum:{latitude:e.maximum.latitude,longitude:e.maximum.longitude},source:n});break}}return t}function G(e){return{number:e.observationNo,date:e.date==null?null:new Date(e.date),observers:e.observers==null?[]:typeof e.observers==`string`||typeof e.observers==`number`||typeof e.observers==`boolean`?S(e.observers).split(`;`).map(e=>e.trim()):z(Array.isArray(e.observers)?e.observers:[e.observers]),notes:e.notes?U(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?B(Array.isArray(e.links)?e.links:[e.links]):[],properties:e.properties?q(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function le(e){let t=[];for(let n of e)t.push(G(n));return t}function K(e){let t=[];for(let n of e)t.push({date:n.dateTime==null?null:new Date(n.dateTime),label:T(n.label),agent:n.agent?{uuid:n.agent.uuid,content:S(n.agent.content)}:null});return t}function ue(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=S(e);let r={content:t,booleanLabel:n,isUncertain:!1,type:`string`,category:`value`,uuid:null,publicationDateTime:null,unit:null};return r}else{let r=`string`;if(e.type!=null){let{data:t,error:n}=p.safeParse(e.type);if(n)throw Error(`Invalid property value content type: "${e.type}"`);r=t}switch(r){case`integer`:case`decimal`:t=Number(e.content);break;case`date`:case`dateTime`:t=e.content?typeof e.content==`string`?new Date(e.content):new Date(T({content:e.content})):null;break;case`coordinate`:t=null;break;case`boolean`:e.content!=null&&(n=T({content:e.content})),t=e.booleanValue??null;break;default:`slug`in e&&e.slug!=null?t=S(e.slug):e.content!=null&&(t=T({content:e.content}));break}let i={content:t,booleanLabel: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:T(e.label,t).replace(/\s*\.{3}$/,``).trim(),values:r,comment:e.comment==null?null:S(e.comment),properties:e.property?q(Array.isArray(e.property)?e.property:[e.property]):[]}}function q(e,t=`eng`){let n=[];for(let r of e)n.push(ue(r,t));return n}function de(e){let t=[];for(let n of e)t.push({date:new Date(n.date),number:n.interpretationNo,properties:n.properties?q(Array.isArray(n.properties.property)?n.properties.property:[n.properties.property]):[]});return t}function fe(e){let t={area:[],width:e.width,height:e.height},n=Array.isArray(e.area)?e.area:[e.area];for(let e of n)t.area.push({uuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),type:e.type,title:S(e.title),shape:e.shape===`rect`?`rectangle`:`polygon`,coords:e.coords.split(`,`).map(e=>Number.parseInt(e))});return t}function pe(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:F(e.identification),description:e.description?T(e.description):null}}function J(e){let t=[];for(let n of e)t.push(pe(n));return t}function me(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:F(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?F(e.identification):null,projectIdentification:e.project?.identification?F(e.project.identification):null,context:e.context?L(e.context):null,citation:{format:e.citationFormat??null,short:e.citationFormatSpan?S(`default:span`in e.citationFormatSpan?e.citationFormatSpan[`default:span`].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?S(`default:div`in e.referenceFormatDiv?e.referenceFormatDiv[`default:div`][`default:div`].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?z(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:S(e.entryInfo.startIssue),startVolume:S(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?J(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],authors:e.authors?z(Array.isArray(e.authors.person)?e.authors.person:[e.authors.person]):[],properties:e.properties?q(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function Y(e){let t=[];for(let n of e)t.push(me(n));return t}function he(e){return{uuid:e.uuid,category:`propertyValue`,number:e.n,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,context:e.context?L(e.context):null,availability:e.availability?R(e.availability):null,identification:F(e.identification),date:e.date?new Date(e.date):null,creators:e.creators?z(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],description:e.description?typeof e.description==`string`||typeof e.description==`number`||typeof e.description==`boolean`?S(e.description):T(e.description):``,notes:e.notes?U(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?B(Array.isArray(e.links)?e.links:[e.links]):[]}}function ge(e){let t=[];for(let n of e)t.push(he(n));return t}function _e(e){let t=[];e.creators&&(t=z(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=X(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource])),typeof e.items!=`string`&&`spatialUnit`in e.items&&(i=xe(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit])),typeof e.items!=`string`&&`concept`in e.items&&(a=Ce(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept])),typeof e.items!=`string`&&`period`in e.items&&(o=J(Array.isArray(e.items.period)?e.items.period:[e.items.period])),typeof e.items!=`string`&&`bibliography`in e.items&&(s=Y(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography])),typeof e.items!=`string`&&`person`in e.items&&(c=z(Array.isArray(e.items.person)?e.items.person:[e.items.person])),typeof e.items!=`string`&&`propertyValue`in e.items&&(l=ge(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]));let u={uuid:e.uuid,category:`tree`,publicationDateTime:new Date(e.publicationDateTime),identification:F(e.identification),creators:t,license:R(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?q(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return u}function ve(e,t){if(typeof e.items==`string`)throw TypeError(`Invalid OCHRE data: Set has no items`);let n=t??ne(Object.keys(e.items)),r=[];switch(n){case`resource`:if(!(`resource`in e.items))throw Error(`Invalid OCHRE data: Set has no resources`);r=X(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=xe(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=Ce(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=J(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=Y(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=z(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=ge(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:R(e.availability),identification:F(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?S(e.description):T(e.description):``,creators:e.creators?z(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],type:e.type,number:e.n,items:r}}function ye(e){let t={uuid:e.uuid,category:`resource`,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,type:e.type,number:e.n,fileFormat:e.fileFormat??null,context:`context`in e&&e.context?L(e.context):null,license:`availability`in e&&e.availability?R(e.availability):null,copyright:`copyright`in e&&e.copyright!=null?S(e.copyright):null,identification:F(e.identification),date:e.date==null?null:new Date(e.date),image:e.image?H(e.image):null,creators:e.creators?z(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],notes:e.notes?U(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?S(e.description):T(e.description):``,coordinates:e.coordinates?W(e.coordinates):[],document:e.document&&`content`in e.document?V(e.document.content):null,href:e.href??null,imageMap:e.imagemap?fe(e.imagemap):null,periods:e.periods?J(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],links:e.links?B(Array.isArray(e.links)?e.links:[e.links]):[],reverseLinks:e.reverseLinks?B(Array.isArray(e.reverseLinks)?e.reverseLinks:[e.reverseLinks]):[],properties:e.properties?q(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],citedBibliographies:e.citedBibliography?Y(Array.isArray(e.citedBibliography.reference)?e.citedBibliography.reference:[e.citedBibliography.reference]):[],resources:e.resource?X(Array.isArray(e.resource)?e.resource:[e.resource]):[]};return t}function X(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(ye(e));return t}function be(e){let t={uuid:e.uuid,category:`spatialUnit`,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),number:e.n,context:`context`in e&&e.context?L(e.context):null,license:`availability`in e&&e.availability?R(e.availability):null,identification:F(e.identification),image:e.image?H(e.image):null,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?S(e.description):T(e.description):``,coordinates:W(e.coordinates),mapData:e.mapData??null,observations:`observations`in e&&e.observations?le(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[G(e.observation)]:[],events:`events`in e&&e.events?K(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:`properties`in e&&e.properties?q(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return t}function xe(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(be(e));return t}function Se(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?R(e.availability):null,context:`context`in e&&e.context?L(e.context):null,identification:F(e.identification),interpretations:de(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation])};return t}const Z=async(e,t)=>{let n=[];for(let r of e){let e=r.properties?q(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 Q(r);n.push(e);break}case`page`:{let e=await Te(r);e&&n.push(e);break}case`block`:{let e=await $(r);e&&n.push(e);break}}}return n};function Ce(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(Se(e));return t}async function we(e,t){let n=d.parse(e.values[0].content),r={component:n},i=t.links?B(Array.isArray(t.links)?t.links:[t.links]):[],a=i.filter(e=>e.type===`image`||e.type===`IIIF`),o=t.document&&`content`in t.document?V(t.document.content):null;if(o===null){let e=i.find(e=>e.type===`internalDocument`);if(e){let{item:t,error:n}=await ie(e.uuid,`resource`);if(n!==null)throw Error(`Failed to fetch OCHRE data`);o=t.document}}switch(n){case`annotated-document`:if(!o)throw Error(`Document not found for the following component: “${n}”`);r.document=o;break;case`annotated-image`:{if(a.length===0)throw Error(`Image link not found for the following component: “${n}”`);let t=M(e.properties,`is-searchable`)===!0;r.imageUuid=a[0].uuid,r.isSearchable=t;break}case`bibliography`:{let t=i.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 a=M(e.properties,`layout`);a??=`long`,r.bibliographies=t.bibliographies,r.layout=a;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)?S(t.identification.label):T(t.identification.label),r.icon=s;break}case`collection`:{let t=i.find(e=>e.category===`set`);if(!t)throw Error(`Collection link not found for the following component: “${n}”`);let a=M(e.properties,`variant`);a??=`full`;let o=M(e.properties,`item-variant`);o??=`default`;let s=M(e.properties,`pagination-variant`);s??=`default`;let c=!1,l=M(e.properties,`show-count`);l!==null&&(c=l===!0);let u=!1,d=M(e.properties,`is-searchable`);d!==null&&(u=d===!0);let f=M(e.properties,`layout`);f??=`image-start`,r.collectionId=t.uuid,r.variant=a,r.itemVariant=o,r.paginationVariant=s,r.isSearchable=u,r.showCount=c,r.layout=f;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=i.find(e=>e.category===`tree`);if(!t)throw Error(`Entries link not found for the following component: “${n}”`);let a=M(e.properties,`variant`);a??=`entry`;let o=!1,s=M(e.properties,`is-searchable`);s!==null&&(o=s===!0),r.entriesId=t.uuid,r.variant=a,r.isSearchable=o;break}case`filter-categories`:{let e=i.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=i.find(e=>e.type===`webpage`)?.href;if(!t)throw Error(`URL not found for the following component: “${n}”`);let a=M(e.properties,`height`),o=M(e.properties,`width`);r.href=t,r.height=a,r.width=o;break}case`iiif-viewer`:{let e=i.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(a.length===0)throw Error(`Image link not found for the following component: “${n}”`);let t=[];for(let e of a)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 o=M(e.properties,`layout-caption`);o??=`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,f=M(e.properties,`is-full-width`);f!==null&&(d=f===!0);let p=!0,m=M(e.properties,`is-full-height`);m!==null&&(p=m===!0);let h=M(e.properties,`image-quality`);h??=`high`;let g=M(e.properties,`caption-source`);g??=`name`;let _=M(e.properties,`alt-text-source`);_??=`name`;let v=!1,y=M(e.properties,`is-transparent`);y!==null&&(v=y===!0);let b=!1,x=M(e.properties,`is-cover`);x!==null&&(b=x===!0);let S=null;if(t.length>1){let t=A(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)))}S={secondsPerImage:n}}r.images=t,r.variant=i,r.width=s,r.height=l,r.isFullWidth=d,r.isFullHeight=p,r.imageQuality=h,r.captionLayout=o,r.captionSource=g,r.altTextSource=_,r.isTransparentBackground=v,r.isCover=b,r.carouselOptions=S;break}case`image-gallery`:{let t=i.find(e=>e.category===`tree`||e.category===`set`);if(!t)throw Error(`Image gallery link not found for the following component: “${n}”`);let a=M(e.properties,`is-searchable`)===!0;r.galleryId=t.uuid,r.isSearchable=a;break}case`map`:{let t=i.find(e=>e.category===`set`||e.category===`tree`);if(!t)throw Error(`Map link not found for the following component: “${n}”`);let a=!0,o=M(e.properties,`is-interactive`);o!==null&&(a=o===!0);let s=!1,c=M(e.properties,`is-clustered`);c!==null&&(s=c===!0);let l=!1,u=M(e.properties,`is-using-pins`);u!==null&&(l=u===!0);let d=null,f=M(e.properties,`custom-basemap`);f!==null&&(d=f);let p=!1,m=M(e.properties,`controls-displayed`);m!==null&&(p=m===!0);let h=!1,g=M(e.properties,`is-full-height`);g!==null&&(h=g===!0),r.mapId=t.uuid,r.isInteractive=a,r.isClustered=s,r.isUsingPins=l,r.customBasemap=d,r.isControlsDisplayed=p,r.isFullHeight=h;break}case`n-columns`:{let e=t.resource?await Z(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];r.columns=e;break}case`n-rows`:{let e=t.resource?await Z(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];r.rows=e;break}case`network-graph`:break;case`table`:{let e=i.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(!o)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=o.content;break}case`timeline`:{let e=i.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=i.find(e=>e.type===`video`);if(!t)throw Error(`Video link not found for the following component: “${n}”`);let a=M(e.properties,`chapters-displayed`);a??=!0,r.videoId=t.uuid,r.isChaptersDislayed=a===!0;break}default:console.warn(`Invalid or non-implemented component name “${n}” for the following element: “${T(t.identification.label)}”`);break}return r}async function Q(e){let t=F(e.identification),n=e.properties?.property?q(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 we(i,e),o=r.properties.find(e=>e.label===`section-sidebar-displayed`),s=o?.values[0]?.content===!0,c=e.properties?.property?q(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,m=`default`,h=!1,g=!1,_=!1,v=!1;if(p){let e=M(p,`variant`);e&&(m=e);let t=p.filter(e=>e.label===`display`);t.length>0&&(h=t.some(e=>e.values[0].content===`name`),g=t.some(e=>e.values[0].content===`description`),_=t.some(e=>e.values[0].content===`date`),v=t.some(e=>e.values[0].content===`creators`))}return{uuid:e.uuid,type:`element`,title:{label:t.label,variant:m,properties:{isNameDisplayed:h,isDescriptionDisplayed:g,isDateDisplayed:_,isCreatorsDisplayed:v}},isDisplayedInBlockSectionSidebar:s,cssStyles:u,cssStylesMobile:f,...a}}async function Te(e){let t=e.properties?q(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=F(e.identification),r=e.slug;if(r===void 0)throw Error(`Slug not found for page “${n.label}”`);let i=e.links?B(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?q(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 Q(e);s.push(t);break}case`block`:{let t=await $(e);t&&s.push(t);break}}}let c=e.resource?await Z(Array.isArray(e.resource)?e.resource:[e.resource],`page`):[],l=!0,u=`default`,d=`default`,f=!0,p=!1,m=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`page`)?.properties;if(m){let e=m.find(e=>e.label===`header`)?.values[0];e&&(l=e.content===!0);let t=m.find(e=>e.label===`width`)?.values[0];t&&(u=t.content);let n=m.find(e=>e.label===`variant`)?.values[0];n&&(d=n.content);let r=m.find(e=>e.label===`sidebar-visible`)?.values[0];r&&(f=r.content===!0);let i=m.find(e=>e.label===`breadcrumbs-visible`)?.values[0];i&&(p=i.content===!0)}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,isBreadcrumbsDisplayed:p,cssStyles:g,cssStylesMobile:v},webpages:c}}async function Ee(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n){let n=await Te(e);n&&t.push(n)}return t}async function $(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?q(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?q(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 Q(e);a.push(t);break}case`block`:{let t=await $(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=De(t),t}function De(e){let t=[];for(let n of e.items)switch(n.type){case`block`:{let e=De(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}function Oe(e){let t=q(e),n=t.find(e=>e.label===`presentation`)?.properties;if(!n)throw Error(`Presentation property not found`);let r=n.find(e=>e.label===`webUI`)?.values[0]?.content;r??=`traditional`;let i=n.find(e=>e.label===`status`)?.values[0]?.content;i??=`development`;let a=n.find(e=>e.label===`privacy`)?.values[0]?.content;a??=`public`;let o=u.safeParse({type:r,status:i,privacy:a});if(!o.success)throw Error(`Invalid website properties: ${o.error.message}`);let s=null,c=n.find(e=>e.label===`contact`);if(c){let[e,t]=(c.values[0]?.content).split(`;`);s={name:e,email:t??null}}let l=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===!0);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===!0);let S=n.find(e=>e.label===`footer-visible`)?.values[0];S&&(h=S.content===!0);let C=n.find(e=>e.label===`sidebar-visible`)?.values[0];C&&(g=C.content===!0);let w=n.find(e=>e.label===`supports-theme-toggle`)?.values[0];w&&(_=w.content===!0);let{type:T,status:E,privacy:D}=o.data;return{type:T,privacy:D,status:E,contact:s,isHeaderDisplayed:d,headerVariant:f,headerAlignment:p,isHeaderProjectDisplayed:m,isFooterDisplayed:h,isSidebarDisplayed:g,supportsThemeToggle:_,logoUrl:l===null?null:`https://ochre.lib.uchicago.edu/ochre?uuid=${l}&load`}}async function ke(e,t,n){if(!e.properties)throw Error(`Website properties not found`);let r=Oe(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 Ee(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?q(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`?S(p.identification.label):T(p.identification.label);let e=p.properties?q(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 m=p.resource?Array.isArray(p.resource)?p.resource:[p.resource]:[];for(let e of m){let t=await Q(e);s.push(t)}}s.length>0&&(o={elements:s,title:c,layout:l,mobileLayout:u,cssStyles:d,cssStylesMobile:f});let m=null;if(e.websiteOptions){let t=`context`in e.websiteOptions.flattenContexts?[e.websiteOptions.flattenContexts]:Array.isArray(e.websiteOptions.flattenContexts)?e.websiteOptions.flattenContexts:[],n=t.map(e=>({context:Array.isArray(e.context)?e.context.flatMap(e=>Array.isArray(e.level)?e.level.map(e=>({variableUuid:e.split(`,`)[0],valueUuid:e.split(`,`)[1]})):[{variableUuid:e.level.split(`,`)[0],valueUuid:e.level.split(`,`)[1]}]):[...Array.isArray(e.context.level)?e.context.level.map(e=>({variableUuid:e.split(`,`)[0],valueUuid:e.split(`,`)[1]})):[{variableUuid:e.context.level.split(`,`)[0],valueUuid:e.context.level.split(`,`)[1]}]]}));m={collectionUuids:`uuid`in e.websiteOptions.collectionUuids?(Array.isArray(e.websiteOptions.collectionUuids.uuid)?e.websiteOptions.collectionUuids.uuid:[e.websiteOptions.collectionUuids.uuid]).map(e=>e.content):[],properties:{metadataUuids:`uuid`in e.websiteOptions.metadataUuids?(Array.isArray(e.websiteOptions.metadataUuids.uuid)?e.websiteOptions.metadataUuids.uuid:[e.websiteOptions.metadataUuids.uuid]).map(e=>e.content):[],searchUuids:`uuid`in e.websiteOptions.searchUuids?(Array.isArray(e.websiteOptions.searchUuids.uuid)?e.websiteOptions.searchUuids.uuid:[e.websiteOptions.searchUuids.uuid]).map(e=>e.content):[],labelUuids:`uuid`in e.websiteOptions.labelUuids?(Array.isArray(e.websiteOptions.labelUuids.uuid)?e.websiteOptions.labelUuids.uuid:[e.websiteOptions.labelUuids.uuid]).map(e=>e.content):[]},flattenContexts:n}}return{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:F(e.identification),project:{name:S(t),website:n===null?null:S(n)},creators:e.creators?z(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:R(e.availability),pages:a,sidebar:o,properties:r,globalOptions:m}}async function Ae(e,t,n,r,i){try{let{uuid:a,filter:o,page:s,perPage:c}=m.parse({uuid:e,filter:t,page:n,perPage:r}),l=await(i??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
|
|
6
6
|
for $q in input()/ochre[@uuid='${a}']
|
|
7
7
|
let $filtered := $q//items/resource[contains(lower-case(identification/label), lower-case('${o}'))]
|
|
8
8
|
let $maxLength := count($filtered)
|
package/dist/index.d.cts
CHANGED
|
@@ -556,6 +556,7 @@ type WebpageProperties = {
|
|
|
556
556
|
variant: "default" | "no-background";
|
|
557
557
|
backgroundImageUrl: string | null;
|
|
558
558
|
isSidebarDisplayed: boolean;
|
|
559
|
+
isBreadcrumbsDisplayed: boolean;
|
|
559
560
|
cssStyles: Array<Style>;
|
|
560
561
|
cssStylesMobile: Array<Style>;
|
|
561
562
|
};
|
|
@@ -610,6 +611,7 @@ type WebElementComponent = {
|
|
|
610
611
|
collectionId: string;
|
|
611
612
|
variant: "full" | "highlights";
|
|
612
613
|
itemVariant: "default" | "card";
|
|
614
|
+
paginationVariant: "default" | "numeric";
|
|
613
615
|
isSearchable: boolean;
|
|
614
616
|
showCount: boolean;
|
|
615
617
|
layout: "image-top" | "image-bottom" | "image-start" | "image-end";
|
package/dist/index.d.ts
CHANGED
|
@@ -556,6 +556,7 @@ type WebpageProperties = {
|
|
|
556
556
|
variant: "default" | "no-background";
|
|
557
557
|
backgroundImageUrl: string | null;
|
|
558
558
|
isSidebarDisplayed: boolean;
|
|
559
|
+
isBreadcrumbsDisplayed: boolean;
|
|
559
560
|
cssStyles: Array<Style>;
|
|
560
561
|
cssStylesMobile: Array<Style>;
|
|
561
562
|
};
|
|
@@ -610,6 +611,7 @@ type WebElementComponent = {
|
|
|
610
611
|
collectionId: string;
|
|
611
612
|
variant: "full" | "highlights";
|
|
612
613
|
itemVariant: "default" | "card";
|
|
614
|
+
paginationVariant: "default" | "numeric";
|
|
613
615
|
isSearchable: boolean;
|
|
614
616
|
showCount: boolean;
|
|
615
617
|
layout: "image-top" | "image-bottom" | "image-start" | "image-end";
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import{z as e}from"zod/v4";const t=e.uuid({error:`Invalid UUID provided`}),n=e.o
|
|
|
2
2
|
`:``;if(`links`in e){let n=``;n=typeof e.string==`object`?_(e.string):m(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=m(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)?m(t.identification.label):_(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+=g(e,t);return`whitespace`in e&&e.whitespace!=null&&(n=p(d(n),e.whitespace)),n.replaceAll(`'`,`'`)}else n=m(e.content),e.rend!=null&&(n=f(d(n),e.rend)),e.whitespace!=null&&(n=p(d(n),e.whitespace));return n}function _(e,t=`eng`){switch(typeof e.content){case`string`:case`number`:case`boolean`:return m(e.content);case`object`:if(Array.isArray(e.content)){let n=u(e.content,t);if(n)return h(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 h(n)}}else return h(e.content);default:return String(e.content)}}async function v(e,t){try{let n=await(t??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
|
|
3
3
|
for $q in input()/ochre[@uuid='${e}']/resource/document/content//string[@annotation][links][properties/property/value/@uuid="b254b5a4-d91f-4954-8bbc-658faefc626c"]/links/child::node(), $r in input()/ochre[@uuid=$q/@uuid]
|
|
4
4
|
return <footnote> {$r/resource/document} { $r/@uuid} </footnote>`)}
|
|
5
|
-
&format=json&lang="*"`);if(!n.ok)throw Error(`Error fetching footnote, please try again later.`);let r=await n.json();if(!(`footnote`in r.result))throw Error(`Failed to fetch footnote`);let i=Array.isArray(r.result.footnote)?r.result.footnote:[r.result.footnote],a=i.map(e=>{let t=``,n=Array.isArray(e.document.string)?e.document.string:[e.document.string];for(let e of n)t+=g(e);return{uuid:e.uuid,label:``,content:t}});return{items:a,error:null}}catch(e){return console.error(e),{items:null,error:e instanceof Error?e.message:`Failed to fetch footnote`}}}const y={includeNestedProperties:!1};function b(e,t,n=y){let{includeNestedProperties:r}=n,i=e.find(e=>e.uuid===t);if(i)return i;if(r){for(let n of e)if(n.properties.length>0){let e=b(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function x(e,t,n=y){let{includeNestedProperties:r}=n,i=e.find(e=>e.uuid===t);if(i)return i.values.map(e=>e.content);if(r){for(let n of e)if(n.properties.length>0){let e=x(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function S(e,t,n=y){let{includeNestedProperties:r}=n,i=x(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=S(n.properties,t,{includeNestedProperties:r});if(e!==null)return e}}return null}function C(e,t,n=y){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=C(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function w(e,t,n=y){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=w(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function T(e,t,n=y){let{includeNestedProperties:r}=n,i=w(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=T(n.properties,t,{includeNestedProperties:r});if(e!==null)return e}}return null}function E(e,t=y){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=E(t.properties,{includeNestedProperties:!0});for(let t of e){if(r.some(e=>e.uuid===t.uuid))continue;r.push(t)}}}return r}function D(e,t=y){let{includeNestedProperties:n}=t,r=[];for(let t of e){if(r.includes(t.label))continue;if(r.push(t.label),t.properties.length>0&&n){let e=D(t.properties,{includeNestedProperties:!0});for(let t of e){if(r.includes(t))continue;r.push(t)}}}return r}function O(e,t,n=y){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.content===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=>O(e,t,{includeNestedProperties:!0}))),n}return!1}function ee(e){let t=e.find(e=>i.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=i.parse(t);return n}async function te(e,n){try{let r=t.parse(e),i=await(n??fetch)(`https://ochre.lib.uchicago.edu/ochre?uuid=${r}&format=json&lang="*"`);if(!i.ok)throw Error(`Failed to fetch OCHRE data`);let a=await i.json();if(!(`ochre`in a))throw Error(`Invalid OCHRE data: API response missing 'ochre' key`);return[null,a]}catch(e){return[e instanceof Error?e.message:`Unknown error`,null]}}async function k(e,t,n,r){try{let[i,a]=await te(e,r);if(i!==null)throw Error(i);let o=ee(Object.keys(a.ochre)),s;switch(o){case`resource`:if(!(`resource`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'resource' key`);s=fe(a.ochre.resource);break;case`spatialUnit`:if(!(`spatialUnit`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'spatialUnit' key`);s=pe(a.ochre.spatialUnit);break;case`concept`:if(!(`concept`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'concept' key`);s=he(a.ochre.concept);break;case`period`:if(!(`period`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'period' key`);s=U(a.ochre.period);break;case`bibliography`:if(!(`bibliography`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'bibliography' key`);s=G(a.ochre.bibliography);break;case`person`:if(!(`person`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'person' key`);s=P(a.ochre.person);break;case`propertyValue`:if(!(`propertyValue`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'propertyValue' key`);s=q(a.ochre.propertyValue);break;case`set`:if(!(`set`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'set' key`);s=de(a.ochre.set,n);break;case`tree`:if(!(`tree`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'tree' key`);s=ue(a.ochre.tree);break;default:throw Error(`Invalid category`)}let c=re(a.ochre.metadata),l={uuid:a.ochre.uuidBelongsTo,abbreviation:m(a.ochre.belongsTo)};return{error:null,metadata:c,belongsTo:l,item:s,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}}}function A(e){try{let t={label:[`string`,`number`,`boolean`].includes(typeof e.label)?m(e.label):_(e.label),abbreviation:``};for(let n of Object.keys(e).filter(e=>e!==`label`))t[n]=_(e[n]);return t}catch(e){return console.error(e),{label:``,abbreviation:``}}}function ne(e){return e==null?[`eng`]:Array.isArray(e)?e.map(e=>_(e)):[_(e)]}function re(e){let t={label:``,abbreviation:``};if(e.item)if(e.item.label||e.item.abbreviation){let n=``,r=``;e.item.label&&(n=_(e.item.label)),e.item.abbreviation&&(r=_(e.item.abbreviation)),t={label:n,abbreviation:r}}else t=A(e.item.identification);let n=null,r=e.project?.identification?A(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:_(e.dataset),publisher:_(e.publisher),languages:ne(e.language),identifier:_(e.identifier),description:_(e.description)}}function j(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),number:e.n,content:m(e.content)}}function M(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(j(e))}return{tree:j(e.tree),project:j(e.project),spatialUnit:t}}),displayPath:e.displayPath};return n}function N(e){return typeof e.license==`string`?null:{content:e.license.content,url:e.license.target}}function P(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?M(e.context):null,date:e.date==null?null:new Date(e.date),identification:e.identification?A(e.identification):null,availability:e.availability?N(e.availability):null,address:e.address?{country:e.address.country??null,city:e.address.city??null,state:e.address.state??null}:null,description:e.description?typeof e.description==`string`||typeof e.description==`number`||typeof e.description==`boolean`?m(e.description):_(e.description):null,coordinates:z(e.coordinates),content:e.content==null?null:m(e.content),notes:e.notes?R(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],events:e.events?V(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:e.properties?H(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function F(e){let t=[];for(let n of e)t.push(P(n));return t}function ie(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:m(t.content):null,href:`href`in t&&t.href!=null?t.href:null,fileFormat:`fileFormat`in t&&t.fileFormat!=null?t.fileFormat:null,uuid:t.uuid,type:t.type??null,identification:t.identification?A(t.identification):null,image:null,bibliographies:`bibliography`in e?K(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}function I(e){let t=[];for(let n of e)t.push(...ie(n));return t}function L(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+=d(m(i.string));else{let e=Array.isArray(i.string)?i.string:[i.string];for(let t of e)n+=g(t,r)}return{content:n,footnotes:r}}function ae(e){return{publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),identification:e.identification?A(e.identification):null,url:e.href??(e.htmlImgSrcPrefix==null&&e.content!=null?m(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?m(e.content):null,widthPreview:e.widthPreview??null,heightPreview:e.heightPreview??null,width:e.width??null,height:e.height??null}}function R(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`?d(m(a.string)):d(L(a).content),n.push({number:r.noteNo,title:a.title==null?null:m(a.title),content:e})}return n}function z(e){if(e==null)return[];let t=[],n=Array.isArray(e.coord)?e.coord:[e.coord];for(let e of n){let n=`source`in e&&e.source?e.source.context===`self`?{context:`self`,uuid:e.source.label.uuid,label:_(e.source.label)}:e.source.context===`related`?{context:`related`,uuid:e.source.label.uuid,label:_(e.source.label),value:_(e.source.value)}:{context:`inherited`,uuid:e.source.label.uuid,item:{uuid:e.source.item.label.uuid,label:_(e.source.item.label)},label:_(e.source.label)}:null;switch(e.type){case`point`:t.push({type:e.type,latitude:e.latitude,longitude:e.longitude,altitude:e.altitude??null,source:n});break;case`plane`:t.push({type:e.type,minimum:{latitude:e.minimum.latitude,longitude:e.minimum.longitude},maximum:{latitude:e.maximum.latitude,longitude:e.maximum.longitude},source:n});break}}return t}function B(e){return{number:e.observationNo,date:e.date==null?null:new Date(e.date),observers:e.observers==null?[]:typeof e.observers==`string`||typeof e.observers==`number`||typeof e.observers==`boolean`?m(e.observers).split(`;`).map(e=>e.trim()):F(Array.isArray(e.observers)?e.observers:[e.observers]),notes:e.notes?R(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?I(Array.isArray(e.links)?e.links:[e.links]):[],properties:e.properties?H(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function oe(e){let t=[];for(let n of e)t.push(B(n));return t}function V(e){let t=[];for(let n of e)t.push({date:n.dateTime==null?null:new Date(n.dateTime),label:_(n.label),agent:n.agent?{uuid:n.agent.uuid,content:m(n.agent.content)}:null});return t}function se(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=m(e);let r={content:t,booleanLabel:n,isUncertain:!1,type:`string`,category:`value`,uuid:null,publicationDateTime:null,unit:null};return r}else{let r=`string`;if(e.type!=null){let{data:t,error:n}=a.safeParse(e.type);if(n)throw Error(`Invalid property value content type: "${e.type}"`);r=t}switch(r){case`integer`:case`decimal`:t=Number(e.content);break;case`date`:case`dateTime`:t=e.content?typeof e.content==`string`?new Date(e.content):new Date(_({content:e.content})):null;break;case`coordinate`:t=null;break;case`boolean`:e.content!=null&&(n=_({content:e.content})),t=e.booleanValue??null;break;default:`slug`in e&&e.slug!=null?t=m(e.slug):e.content!=null&&(t=_({content:e.content}));break}let i={content:t,booleanLabel: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:_(e.label,t).replace(/\s*\.{3}$/,``).trim(),values:r,comment:e.comment==null?null:m(e.comment),properties:e.property?H(Array.isArray(e.property)?e.property:[e.property]):[]}}function H(e,t=`eng`){let n=[];for(let r of e)n.push(se(r,t));return n}function ce(e){let t=[];for(let n of e)t.push({date:new Date(n.date),number:n.interpretationNo,properties:n.properties?H(Array.isArray(n.properties.property)?n.properties.property:[n.properties.property]):[]});return t}function le(e){let t={area:[],width:e.width,height:e.height},n=Array.isArray(e.area)?e.area:[e.area];for(let e of n)t.area.push({uuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),type:e.type,title:m(e.title),shape:e.shape===`rect`?`rectangle`:`polygon`,coords:e.coords.split(`,`).map(e=>Number.parseInt(e))});return t}function U(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:A(e.identification),description:e.description?_(e.description):null}}function W(e){let t=[];for(let n of e)t.push(U(n));return t}function G(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:A(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?A(e.identification):null,projectIdentification:e.project?.identification?A(e.project.identification):null,context:e.context?M(e.context):null,citation:{format:e.citationFormat??null,short:e.citationFormatSpan?m(`default:span`in e.citationFormatSpan?e.citationFormatSpan[`default:span`].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?m(`default:div`in e.referenceFormatDiv?e.referenceFormatDiv[`default:div`][`default:div`].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?F(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:m(e.entryInfo.startIssue),startVolume:m(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?W(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],authors:e.authors?F(Array.isArray(e.authors.person)?e.authors.person:[e.authors.person]):[],properties:e.properties?H(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function K(e){let t=[];for(let n of e)t.push(G(n));return t}function q(e){return{uuid:e.uuid,category:`propertyValue`,number:e.n,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,context:e.context?M(e.context):null,availability:e.availability?N(e.availability):null,identification:A(e.identification),date:e.date?new Date(e.date):null,creators:e.creators?F(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],description:e.description?typeof e.description==`string`||typeof e.description==`number`||typeof e.description==`boolean`?m(e.description):_(e.description):``,notes:e.notes?R(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?I(Array.isArray(e.links)?e.links:[e.links]):[]}}function J(e){let t=[];for(let n of e)t.push(q(n));return t}function ue(e){let t=[];e.creators&&(t=F(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=me(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit])),typeof e.items!=`string`&&`concept`in e.items&&(a=Z(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept])),typeof e.items!=`string`&&`period`in e.items&&(o=W(Array.isArray(e.items.period)?e.items.period:[e.items.period])),typeof e.items!=`string`&&`bibliography`in e.items&&(s=K(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography])),typeof e.items!=`string`&&`person`in e.items&&(c=F(Array.isArray(e.items.person)?e.items.person:[e.items.person])),typeof e.items!=`string`&&`propertyValue`in e.items&&(l=J(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]));let u={uuid:e.uuid,category:`tree`,publicationDateTime:new Date(e.publicationDateTime),identification:A(e.identification),creators:t,license:N(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?H(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return u}function de(e,t){if(typeof e.items==`string`)throw TypeError(`Invalid OCHRE data: Set has no items`);let n=t??ee(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=me(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=Z(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=W(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=K(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=F(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=J(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:N(e.availability),identification:A(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?m(e.description):_(e.description):``,creators:e.creators?F(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],type:e.type,number:e.n,items:r}}function fe(e){let t={uuid:e.uuid,category:`resource`,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,type:e.type,number:e.n,fileFormat:e.fileFormat??null,context:`context`in e&&e.context?M(e.context):null,license:`availability`in e&&e.availability?N(e.availability):null,copyright:`copyright`in e&&e.copyright!=null?m(e.copyright):null,identification:A(e.identification),date:e.date==null?null:new Date(e.date),image:e.image?ae(e.image):null,creators:e.creators?F(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],notes:e.notes?R(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?m(e.description):_(e.description):``,coordinates:e.coordinates?z(e.coordinates):[],document:e.document&&`content`in e.document?L(e.document.content):null,href:e.href??null,imageMap:e.imagemap?le(e.imagemap):null,periods:e.periods?W(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],links:e.links?I(Array.isArray(e.links)?e.links:[e.links]):[],reverseLinks:e.reverseLinks?I(Array.isArray(e.reverseLinks)?e.reverseLinks:[e.reverseLinks]):[],properties:e.properties?H(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],citedBibliographies:e.citedBibliography?K(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}function Y(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(fe(e));return t}function pe(e){let t={uuid:e.uuid,category:`spatialUnit`,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),number:e.n,context:`context`in e&&e.context?M(e.context):null,license:`availability`in e&&e.availability?N(e.availability):null,identification:A(e.identification),image:e.image?ae(e.image):null,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?m(e.description):_(e.description):``,coordinates:z(e.coordinates),mapData:e.mapData??null,observations:`observations`in e&&e.observations?oe(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[B(e.observation)]:[],events:`events`in e&&e.events?V(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:`properties`in e&&e.properties?H(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return t}function me(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(pe(e));return t}function he(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?N(e.availability):null,context:`context`in e&&e.context?M(e.context):null,identification:A(e.identification),interpretations:ce(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation])};return t}const X=async(e,t)=>{let n=[];for(let r of e){let e=r.properties?H(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 Q(r);n.push(e);break}case`page`:{let e=await _e(r);e&&n.push(e);break}case`block`:{let e=await $(r);e&&n.push(e);break}}}return n};function Z(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(he(e));return t}async function ge(e,t){let n=r.parse(e.values[0].content),i={component:n},a=t.links?I(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?L(t.document.content):null;if(s===null){let e=a.find(e=>e.type===`internalDocument`);if(e){let{item:t,error:n}=await k(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}”`);i.document=s;break;case`annotated-image`:{if(o.length===0)throw Error(`Image link not found for the following component: “${n}”`);let t=T(e.properties,`is-searchable`)===!0;i.imageUuid=o[0].uuid,i.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 r=T(e.properties,`layout`);r??=`long`,i.bibliographies=t.bibliographies,i.layout=r;break}case`button`:{let r=T(e.properties,`variant`);r??=`default`;let a=!1,o=T(e.properties,`navigate-to`);if(o===null){if(o=T(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=T(e.properties,`icon`);c!==null&&(s=c),i.variant=r,i.href=o,i.isExternal=a,i.label=[`string`,`number`,`boolean`].includes(typeof t.identification.label)?m(t.identification.label):_(t.identification.label),i.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 r=T(e.properties,`variant`);r??=`full`;let o=T(e.properties,`item-variant`);o??=`default`;let s=!1,c=T(e.properties,`show-count`);c!==null&&(s=c===!0);let l=!1,u=T(e.properties,`is-searchable`);u!==null&&(l=u===!0);let d=T(e.properties,`layout`);d??=`image-start`,i.collectionId=t.uuid,i.variant=r,i.itemVariant=o,i.isSearchable=l,i.showCount=s,i.layout=d;break}case`empty-space`:{let t=T(e.properties,`height`),n=T(e.properties,`width`);i.height=t,i.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 r=T(e.properties,`variant`);r??=`entry`;let o=!1,s=T(e.properties,`is-searchable`);s!==null&&(o=s===!0),i.entriesId=t.uuid,i.variant=r,i.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}”`);i.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 r=T(e.properties,`height`),o=T(e.properties,`width`);i.href=t,i.height=r,i.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}”`);i.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 r=T(e.properties,`variant`);r??=`default`;let a=T(e.properties,`layout-caption`);a??=`bottom`;let s=null,c=T(e.properties,`width`);c!==null&&(typeof c==`number`?s=c:typeof c==`string`&&(s=Number.parseFloat(c)));let l=null,u=T(e.properties,`height`);u!==null&&(typeof u==`number`?l=u:typeof u==`string`&&(l=Number.parseFloat(u)));let d=!0,f=T(e.properties,`is-full-width`);f!==null&&(d=f===!0);let p=!0,m=T(e.properties,`is-full-height`);m!==null&&(p=m===!0);let h=T(e.properties,`image-quality`);h??=`high`;let g=T(e.properties,`caption-source`);g??=`name`;let _=T(e.properties,`alt-text-source`);_??=`name`;let v=!1,y=T(e.properties,`is-transparent`);y!==null&&(v=y===!0);let b=!1,x=T(e.properties,`is-cover`);x!==null&&(b=x===!0);let S=null;if(t.length>1){let t=C(e.properties,`variant`),n=5;if(t&&t.values[0].content===`carousel`){let e=T(t.properties,`seconds-per-image`);e!==null&&(typeof e==`number`?n=e:typeof e==`string`&&(n=Number.parseFloat(e)))}S={secondsPerImage:n}}i.images=t,i.variant=r,i.width=s,i.height=l,i.isFullWidth=d,i.isFullHeight=p,i.imageQuality=h,i.captionLayout=a,i.captionSource=g,i.altTextSource=_,i.isTransparentBackground=v,i.isCover=b,i.carouselOptions=S;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 r=T(e.properties,`is-searchable`)===!0;i.galleryId=t.uuid,i.isSearchable=r;break}case`map`:{let t=a.find(e=>e.category===`set`||e.category===`tree`);if(!t)throw Error(`Map link not found for the following component: “${n}”`);let r=!0,o=T(e.properties,`is-interactive`);o!==null&&(r=o===!0);let s=!1,c=T(e.properties,`is-clustered`);c!==null&&(s=c===!0);let l=!1,u=T(e.properties,`is-using-pins`);u!==null&&(l=u===!0);let d=null,f=T(e.properties,`custom-basemap`);f!==null&&(d=f);let p=!1,m=T(e.properties,`controls-displayed`);m!==null&&(p=m===!0);let h=!1,g=T(e.properties,`is-full-height`);g!==null&&(h=g===!0),i.mapId=t.uuid,i.isInteractive=r,i.isClustered=s,i.isUsingPins=l,i.customBasemap=d,i.isControlsDisplayed=p,i.isFullHeight=h;break}case`n-columns`:{let e=t.resource?await X(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];i.columns=e;break}case`n-rows`:{let e=t.resource?await X(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];i.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}”`);i.tableId=e.uuid;break}case`search-bar`:{let t=T(e.properties,`variant`);t??=`default`,i.variant=t;break}case`text`:{if(!s)throw Error(`Document not found for the following component: “${n}”`);let t=T(e.properties,`variant`);t??=`block`;let r=T(e.properties,`heading`);i.variant=t,i.heading=r,i.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}”`);i.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 r=T(e.properties,`chapters-displayed`);r??=!0,i.videoId=t.uuid,i.isChaptersDislayed=r===!0;break}default:console.warn(`Invalid or non-implemented component name “${n}” for the following element: “${_(t.identification.label)}”`);break}return i}async function Q(e){let t=A(e.identification),n=e.properties?.property?H(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 ge(i,e),o=r.properties.find(e=>e.label===`section-sidebar-displayed`),s=o?.values[0]?.content===!0,c=e.properties?.property?H(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,m=`default`,h=!1,g=!1,_=!1,v=!1;if(p){let e=T(p,`variant`);e&&(m=e);let t=p.filter(e=>e.label===`display`);t.length>0&&(h=t.some(e=>e.values[0].content===`name`),g=t.some(e=>e.values[0].content===`description`),_=t.some(e=>e.values[0].content===`date`),v=t.some(e=>e.values[0].content===`creators`))}return{uuid:e.uuid,type:`element`,title:{label:t.label,variant:m,properties:{isNameDisplayed:h,isDescriptionDisplayed:g,isDateDisplayed:_,isCreatorsDisplayed:v}},isDisplayedInBlockSectionSidebar:s,cssStyles:u,cssStylesMobile:f,...a}}async function _e(e){let t=e.properties?H(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=A(e.identification),r=e.slug;if(r===void 0)throw Error(`Slug not found for page “${n.label}”`);let i=e.links?I(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?H(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=T(t,`presentation`);if(n==null)continue;switch(n){case`element`:{let t=await Q(e);s.push(t);break}case`block`:{let t=await $(e);t&&s.push(t);break}}}let c=e.resource?await X(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===!0);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===!0)}let m=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css`)?.properties,h=[];if(m)for(let e of m)h.push({label:e.label,value:e.values[0].content});let g=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css-mobile`)?.properties,_=[];if(g)for(let e of g)_.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:h,cssStylesMobile:_},webpages:c}}async function ve(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n){let n=await _e(e);n&&t.push(n)}return t}async function $(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?H(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?H(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=T(t,`presentation`);if(n==null)continue;switch(n){case`element`:{let t=await Q(e);a.push(t);break}case`block`:{let t=await $(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=ye(t),t}function ye(e){let t=[];for(let n of e.items)switch(n.type){case`block`:{let e=ye(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}function be(e){let t=H(e),r=t.find(e=>e.label===`presentation`)?.properties;if(!r)throw Error(`Presentation property not found`);let i=r.find(e=>e.label===`webUI`)?.values[0]?.content;i??=`traditional`;let a=r.find(e=>e.label===`status`)?.values[0]?.content;a??=`development`;let o=r.find(e=>e.label===`privacy`)?.values[0]?.content;o??=`public`;let s=n.safeParse({type:i,status:a,privacy:o});if(!s.success)throw Error(`Invalid website properties: ${s.error.message}`);let c=null,l=r.find(e=>e.label===`contact`);if(l){let[e,t]=(l.values[0]?.content).split(`;`);c={name:e,email:t??null}}let u=r.find(e=>e.label===`logo`)?.values[0]?.uuid??null,d=!0,f=`default`,p=`start`,m=!0,h=!0,g=!1,_=!0,v=r.find(e=>e.label===`navbar-visible`)?.values[0];v&&(d=v.content===!0);let y=r.find(e=>e.label===`navbar-variant`)?.values[0];y&&(f=y.content);let b=r.find(e=>e.label===`navbar-alignment`)?.values[0];b&&(p=b.content);let x=r.find(e=>e.label===`navbar-project-visible`)?.values[0];x&&(m=x.content===!0);let S=r.find(e=>e.label===`footer-visible`)?.values[0];S&&(h=S.content===!0);let C=r.find(e=>e.label===`sidebar-visible`)?.values[0];C&&(g=C.content===!0);let w=r.find(e=>e.label===`supports-theme-toggle`)?.values[0];w&&(_=w.content===!0);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 xe(e,t,n){if(!e.properties)throw Error(`Website properties not found`);let r=be(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 ve(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?H(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`?m(p.identification.label):_(p.identification.label);let e=p.properties?H(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=T(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 Q(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.websiteOptions){let t=`context`in e.websiteOptions.flattenContexts?[e.websiteOptions.flattenContexts]:Array.isArray(e.websiteOptions.flattenContexts)?e.websiteOptions.flattenContexts:[],n=t.map(e=>({context:Array.isArray(e.context)?e.context.flatMap(e=>Array.isArray(e.level)?e.level.map(e=>({variableUuid:e.split(`,`)[0],valueUuid:e.split(`,`)[1]})):[{variableUuid:e.level.split(`,`)[0],valueUuid:e.level.split(`,`)[1]}]):[...Array.isArray(e.context.level)?e.context.level.map(e=>({variableUuid:e.split(`,`)[0],valueUuid:e.split(`,`)[1]})):[{variableUuid:e.context.level.split(`,`)[0],valueUuid:e.context.level.split(`,`)[1]}]]}));h={collectionUuids:`uuid`in e.websiteOptions.collectionUuids?(Array.isArray(e.websiteOptions.collectionUuids.uuid)?e.websiteOptions.collectionUuids.uuid:[e.websiteOptions.collectionUuids.uuid]).map(e=>e.content):[],properties:{metadataUuids:`uuid`in e.websiteOptions.metadataUuids?(Array.isArray(e.websiteOptions.metadataUuids.uuid)?e.websiteOptions.metadataUuids.uuid:[e.websiteOptions.metadataUuids.uuid]).map(e=>e.content):[],searchUuids:`uuid`in e.websiteOptions.searchUuids?(Array.isArray(e.websiteOptions.searchUuids.uuid)?e.websiteOptions.searchUuids.uuid:[e.websiteOptions.searchUuids.uuid]).map(e=>e.content):[],labelUuids:`uuid`in e.websiteOptions.labelUuids?(Array.isArray(e.websiteOptions.labelUuids.uuid)?e.websiteOptions.labelUuids.uuid:[e.websiteOptions.labelUuids.uuid]).map(e=>e.content):[]},flattenContexts:n}}return{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:A(e.identification),project:{name:m(t),website:n===null?null:m(n)},creators:e.creators?F(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:N(e.availability),pages:a,sidebar:o,properties:r,globalOptions:h}}async function Se(e,t,n,r,i){try{let{uuid:a,filter:s,page:c,perPage:l}=o.parse({uuid:e,filter:t,page:n,perPage:r}),u=await(i??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
|
|
5
|
+
&format=json&lang="*"`);if(!n.ok)throw Error(`Error fetching footnote, please try again later.`);let r=await n.json();if(!(`footnote`in r.result))throw Error(`Failed to fetch footnote`);let i=Array.isArray(r.result.footnote)?r.result.footnote:[r.result.footnote],a=i.map(e=>{let t=``,n=Array.isArray(e.document.string)?e.document.string:[e.document.string];for(let e of n)t+=g(e);return{uuid:e.uuid,label:``,content:t}});return{items:a,error:null}}catch(e){return console.error(e),{items:null,error:e instanceof Error?e.message:`Failed to fetch footnote`}}}const y={includeNestedProperties:!1};function b(e,t,n=y){let{includeNestedProperties:r}=n,i=e.find(e=>e.uuid===t);if(i)return i;if(r){for(let n of e)if(n.properties.length>0){let e=b(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function x(e,t,n=y){let{includeNestedProperties:r}=n,i=e.find(e=>e.uuid===t);if(i)return i.values.map(e=>e.content);if(r){for(let n of e)if(n.properties.length>0){let e=x(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function S(e,t,n=y){let{includeNestedProperties:r}=n,i=x(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=S(n.properties,t,{includeNestedProperties:r});if(e!==null)return e}}return null}function C(e,t,n=y){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=C(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function w(e,t,n=y){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=w(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function T(e,t,n=y){let{includeNestedProperties:r}=n,i=w(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=T(n.properties,t,{includeNestedProperties:r});if(e!==null)return e}}return null}function E(e,t=y){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=E(t.properties,{includeNestedProperties:!0});for(let t of e){if(r.some(e=>e.uuid===t.uuid))continue;r.push(t)}}}return r}function D(e,t=y){let{includeNestedProperties:n}=t,r=[];for(let t of e){if(r.includes(t.label))continue;if(r.push(t.label),t.properties.length>0&&n){let e=D(t.properties,{includeNestedProperties:!0});for(let t of e){if(r.includes(t))continue;r.push(t)}}}return r}function O(e,t,n=y){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.content===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=>O(e,t,{includeNestedProperties:!0}))),n}return!1}function ee(e){let t=e.find(e=>i.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=i.parse(t);return n}async function te(e,n){try{let r=t.parse(e),i=await(n??fetch)(`https://ochre.lib.uchicago.edu/ochre?uuid=${r}&format=json&lang="*"`);if(!i.ok)throw Error(`Failed to fetch OCHRE data`);let a=await i.json();if(!(`ochre`in a))throw Error(`Invalid OCHRE data: API response missing 'ochre' key`);return[null,a]}catch(e){return[e instanceof Error?e.message:`Unknown error`,null]}}async function k(e,t,n,r){try{let[i,a]=await te(e,r);if(i!==null)throw Error(i);let o=ee(Object.keys(a.ochre)),s;switch(o){case`resource`:if(!(`resource`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'resource' key`);s=fe(a.ochre.resource);break;case`spatialUnit`:if(!(`spatialUnit`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'spatialUnit' key`);s=pe(a.ochre.spatialUnit);break;case`concept`:if(!(`concept`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'concept' key`);s=he(a.ochre.concept);break;case`period`:if(!(`period`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'period' key`);s=U(a.ochre.period);break;case`bibliography`:if(!(`bibliography`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'bibliography' key`);s=G(a.ochre.bibliography);break;case`person`:if(!(`person`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'person' key`);s=P(a.ochre.person);break;case`propertyValue`:if(!(`propertyValue`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'propertyValue' key`);s=q(a.ochre.propertyValue);break;case`set`:if(!(`set`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'set' key`);s=de(a.ochre.set,n);break;case`tree`:if(!(`tree`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'tree' key`);s=ue(a.ochre.tree);break;default:throw Error(`Invalid category`)}let c=re(a.ochre.metadata),l={uuid:a.ochre.uuidBelongsTo,abbreviation:m(a.ochre.belongsTo)};return{error:null,metadata:c,belongsTo:l,item:s,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}}}function A(e){try{let t={label:[`string`,`number`,`boolean`].includes(typeof e.label)?m(e.label):_(e.label),abbreviation:``};for(let n of Object.keys(e).filter(e=>e!==`label`))t[n]=_(e[n]);return t}catch(e){return console.error(e),{label:``,abbreviation:``}}}function ne(e){return e==null?[`eng`]:Array.isArray(e)?e.map(e=>_(e)):[_(e)]}function re(e){let t={label:``,abbreviation:``};if(e.item)if(e.item.label||e.item.abbreviation){let n=``,r=``;e.item.label&&(n=_(e.item.label)),e.item.abbreviation&&(r=_(e.item.abbreviation)),t={label:n,abbreviation:r}}else t=A(e.item.identification);let n=null,r=e.project?.identification?A(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:_(e.dataset),publisher:_(e.publisher),languages:ne(e.language),identifier:_(e.identifier),description:_(e.description)}}function j(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),number:e.n,content:m(e.content)}}function M(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(j(e))}return{tree:j(e.tree),project:j(e.project),spatialUnit:t}}),displayPath:e.displayPath};return n}function N(e){return typeof e.license==`string`?null:{content:e.license.content,url:e.license.target}}function P(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?M(e.context):null,date:e.date==null?null:new Date(e.date),identification:e.identification?A(e.identification):null,availability:e.availability?N(e.availability):null,address:e.address?{country:e.address.country??null,city:e.address.city??null,state:e.address.state??null}:null,description:e.description?typeof e.description==`string`||typeof e.description==`number`||typeof e.description==`boolean`?m(e.description):_(e.description):null,coordinates:z(e.coordinates),content:e.content==null?null:m(e.content),notes:e.notes?R(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],events:e.events?V(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:e.properties?H(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function F(e){let t=[];for(let n of e)t.push(P(n));return t}function ie(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:m(t.content):null,href:`href`in t&&t.href!=null?t.href:null,fileFormat:`fileFormat`in t&&t.fileFormat!=null?t.fileFormat:null,uuid:t.uuid,type:t.type??null,identification:t.identification?A(t.identification):null,image:null,bibliographies:`bibliography`in e?K(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}function I(e){let t=[];for(let n of e)t.push(...ie(n));return t}function L(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+=d(m(i.string));else{let e=Array.isArray(i.string)?i.string:[i.string];for(let t of e)n+=g(t,r)}return{content:n,footnotes:r}}function ae(e){return{publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),identification:e.identification?A(e.identification):null,url:e.href??(e.htmlImgSrcPrefix==null&&e.content!=null?m(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?m(e.content):null,widthPreview:e.widthPreview??null,heightPreview:e.heightPreview??null,width:e.width??null,height:e.height??null}}function R(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`?d(m(a.string)):d(L(a).content),n.push({number:r.noteNo,title:a.title==null?null:m(a.title),content:e})}return n}function z(e){if(e==null)return[];let t=[],n=Array.isArray(e.coord)?e.coord:[e.coord];for(let e of n){let n=`source`in e&&e.source?e.source.context===`self`?{context:`self`,uuid:e.source.label.uuid,label:_(e.source.label)}:e.source.context===`related`?{context:`related`,uuid:e.source.label.uuid,label:_(e.source.label),value:_(e.source.value)}:{context:`inherited`,uuid:e.source.label.uuid,item:{uuid:e.source.item.label.uuid,label:_(e.source.item.label)},label:_(e.source.label)}:null;switch(e.type){case`point`:t.push({type:e.type,latitude:e.latitude,longitude:e.longitude,altitude:e.altitude??null,source:n});break;case`plane`:t.push({type:e.type,minimum:{latitude:e.minimum.latitude,longitude:e.minimum.longitude},maximum:{latitude:e.maximum.latitude,longitude:e.maximum.longitude},source:n});break}}return t}function B(e){return{number:e.observationNo,date:e.date==null?null:new Date(e.date),observers:e.observers==null?[]:typeof e.observers==`string`||typeof e.observers==`number`||typeof e.observers==`boolean`?m(e.observers).split(`;`).map(e=>e.trim()):F(Array.isArray(e.observers)?e.observers:[e.observers]),notes:e.notes?R(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?I(Array.isArray(e.links)?e.links:[e.links]):[],properties:e.properties?H(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function oe(e){let t=[];for(let n of e)t.push(B(n));return t}function V(e){let t=[];for(let n of e)t.push({date:n.dateTime==null?null:new Date(n.dateTime),label:_(n.label),agent:n.agent?{uuid:n.agent.uuid,content:m(n.agent.content)}:null});return t}function se(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=m(e);let r={content:t,booleanLabel:n,isUncertain:!1,type:`string`,category:`value`,uuid:null,publicationDateTime:null,unit:null};return r}else{let r=`string`;if(e.type!=null){let{data:t,error:n}=a.safeParse(e.type);if(n)throw Error(`Invalid property value content type: "${e.type}"`);r=t}switch(r){case`integer`:case`decimal`:t=Number(e.content);break;case`date`:case`dateTime`:t=e.content?typeof e.content==`string`?new Date(e.content):new Date(_({content:e.content})):null;break;case`coordinate`:t=null;break;case`boolean`:e.content!=null&&(n=_({content:e.content})),t=e.booleanValue??null;break;default:`slug`in e&&e.slug!=null?t=m(e.slug):e.content!=null&&(t=_({content:e.content}));break}let i={content:t,booleanLabel: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:_(e.label,t).replace(/\s*\.{3}$/,``).trim(),values:r,comment:e.comment==null?null:m(e.comment),properties:e.property?H(Array.isArray(e.property)?e.property:[e.property]):[]}}function H(e,t=`eng`){let n=[];for(let r of e)n.push(se(r,t));return n}function ce(e){let t=[];for(let n of e)t.push({date:new Date(n.date),number:n.interpretationNo,properties:n.properties?H(Array.isArray(n.properties.property)?n.properties.property:[n.properties.property]):[]});return t}function le(e){let t={area:[],width:e.width,height:e.height},n=Array.isArray(e.area)?e.area:[e.area];for(let e of n)t.area.push({uuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),type:e.type,title:m(e.title),shape:e.shape===`rect`?`rectangle`:`polygon`,coords:e.coords.split(`,`).map(e=>Number.parseInt(e))});return t}function U(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:A(e.identification),description:e.description?_(e.description):null}}function W(e){let t=[];for(let n of e)t.push(U(n));return t}function G(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:A(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?A(e.identification):null,projectIdentification:e.project?.identification?A(e.project.identification):null,context:e.context?M(e.context):null,citation:{format:e.citationFormat??null,short:e.citationFormatSpan?m(`default:span`in e.citationFormatSpan?e.citationFormatSpan[`default:span`].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?m(`default:div`in e.referenceFormatDiv?e.referenceFormatDiv[`default:div`][`default:div`].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?F(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:m(e.entryInfo.startIssue),startVolume:m(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?W(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],authors:e.authors?F(Array.isArray(e.authors.person)?e.authors.person:[e.authors.person]):[],properties:e.properties?H(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function K(e){let t=[];for(let n of e)t.push(G(n));return t}function q(e){return{uuid:e.uuid,category:`propertyValue`,number:e.n,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,context:e.context?M(e.context):null,availability:e.availability?N(e.availability):null,identification:A(e.identification),date:e.date?new Date(e.date):null,creators:e.creators?F(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],description:e.description?typeof e.description==`string`||typeof e.description==`number`||typeof e.description==`boolean`?m(e.description):_(e.description):``,notes:e.notes?R(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?I(Array.isArray(e.links)?e.links:[e.links]):[]}}function J(e){let t=[];for(let n of e)t.push(q(n));return t}function ue(e){let t=[];e.creators&&(t=F(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=me(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit])),typeof e.items!=`string`&&`concept`in e.items&&(a=Z(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept])),typeof e.items!=`string`&&`period`in e.items&&(o=W(Array.isArray(e.items.period)?e.items.period:[e.items.period])),typeof e.items!=`string`&&`bibliography`in e.items&&(s=K(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography])),typeof e.items!=`string`&&`person`in e.items&&(c=F(Array.isArray(e.items.person)?e.items.person:[e.items.person])),typeof e.items!=`string`&&`propertyValue`in e.items&&(l=J(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]));let u={uuid:e.uuid,category:`tree`,publicationDateTime:new Date(e.publicationDateTime),identification:A(e.identification),creators:t,license:N(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?H(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return u}function de(e,t){if(typeof e.items==`string`)throw TypeError(`Invalid OCHRE data: Set has no items`);let n=t??ee(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=me(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=Z(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=W(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=K(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=F(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=J(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:N(e.availability),identification:A(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?m(e.description):_(e.description):``,creators:e.creators?F(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],type:e.type,number:e.n,items:r}}function fe(e){let t={uuid:e.uuid,category:`resource`,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,type:e.type,number:e.n,fileFormat:e.fileFormat??null,context:`context`in e&&e.context?M(e.context):null,license:`availability`in e&&e.availability?N(e.availability):null,copyright:`copyright`in e&&e.copyright!=null?m(e.copyright):null,identification:A(e.identification),date:e.date==null?null:new Date(e.date),image:e.image?ae(e.image):null,creators:e.creators?F(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],notes:e.notes?R(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?m(e.description):_(e.description):``,coordinates:e.coordinates?z(e.coordinates):[],document:e.document&&`content`in e.document?L(e.document.content):null,href:e.href??null,imageMap:e.imagemap?le(e.imagemap):null,periods:e.periods?W(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],links:e.links?I(Array.isArray(e.links)?e.links:[e.links]):[],reverseLinks:e.reverseLinks?I(Array.isArray(e.reverseLinks)?e.reverseLinks:[e.reverseLinks]):[],properties:e.properties?H(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],citedBibliographies:e.citedBibliography?K(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}function Y(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(fe(e));return t}function pe(e){let t={uuid:e.uuid,category:`spatialUnit`,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),number:e.n,context:`context`in e&&e.context?M(e.context):null,license:`availability`in e&&e.availability?N(e.availability):null,identification:A(e.identification),image:e.image?ae(e.image):null,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?m(e.description):_(e.description):``,coordinates:z(e.coordinates),mapData:e.mapData??null,observations:`observations`in e&&e.observations?oe(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[B(e.observation)]:[],events:`events`in e&&e.events?V(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:`properties`in e&&e.properties?H(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return t}function me(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(pe(e));return t}function he(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?N(e.availability):null,context:`context`in e&&e.context?M(e.context):null,identification:A(e.identification),interpretations:ce(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation])};return t}const X=async(e,t)=>{let n=[];for(let r of e){let e=r.properties?H(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 Q(r);n.push(e);break}case`page`:{let e=await _e(r);e&&n.push(e);break}case`block`:{let e=await $(r);e&&n.push(e);break}}}return n};function Z(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(he(e));return t}async function ge(e,t){let n=r.parse(e.values[0].content),i={component:n},a=t.links?I(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?L(t.document.content):null;if(s===null){let e=a.find(e=>e.type===`internalDocument`);if(e){let{item:t,error:n}=await k(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}”`);i.document=s;break;case`annotated-image`:{if(o.length===0)throw Error(`Image link not found for the following component: “${n}”`);let t=T(e.properties,`is-searchable`)===!0;i.imageUuid=o[0].uuid,i.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 r=T(e.properties,`layout`);r??=`long`,i.bibliographies=t.bibliographies,i.layout=r;break}case`button`:{let r=T(e.properties,`variant`);r??=`default`;let a=!1,o=T(e.properties,`navigate-to`);if(o===null){if(o=T(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=T(e.properties,`icon`);c!==null&&(s=c),i.variant=r,i.href=o,i.isExternal=a,i.label=[`string`,`number`,`boolean`].includes(typeof t.identification.label)?m(t.identification.label):_(t.identification.label),i.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 r=T(e.properties,`variant`);r??=`full`;let o=T(e.properties,`item-variant`);o??=`default`;let s=T(e.properties,`pagination-variant`);s??=`default`;let c=!1,l=T(e.properties,`show-count`);l!==null&&(c=l===!0);let u=!1,d=T(e.properties,`is-searchable`);d!==null&&(u=d===!0);let f=T(e.properties,`layout`);f??=`image-start`,i.collectionId=t.uuid,i.variant=r,i.itemVariant=o,i.paginationVariant=s,i.isSearchable=u,i.showCount=c,i.layout=f;break}case`empty-space`:{let t=T(e.properties,`height`),n=T(e.properties,`width`);i.height=t,i.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 r=T(e.properties,`variant`);r??=`entry`;let o=!1,s=T(e.properties,`is-searchable`);s!==null&&(o=s===!0),i.entriesId=t.uuid,i.variant=r,i.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}”`);i.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 r=T(e.properties,`height`),o=T(e.properties,`width`);i.href=t,i.height=r,i.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}”`);i.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 r=T(e.properties,`variant`);r??=`default`;let a=T(e.properties,`layout-caption`);a??=`bottom`;let s=null,c=T(e.properties,`width`);c!==null&&(typeof c==`number`?s=c:typeof c==`string`&&(s=Number.parseFloat(c)));let l=null,u=T(e.properties,`height`);u!==null&&(typeof u==`number`?l=u:typeof u==`string`&&(l=Number.parseFloat(u)));let d=!0,f=T(e.properties,`is-full-width`);f!==null&&(d=f===!0);let p=!0,m=T(e.properties,`is-full-height`);m!==null&&(p=m===!0);let h=T(e.properties,`image-quality`);h??=`high`;let g=T(e.properties,`caption-source`);g??=`name`;let _=T(e.properties,`alt-text-source`);_??=`name`;let v=!1,y=T(e.properties,`is-transparent`);y!==null&&(v=y===!0);let b=!1,x=T(e.properties,`is-cover`);x!==null&&(b=x===!0);let S=null;if(t.length>1){let t=C(e.properties,`variant`),n=5;if(t&&t.values[0].content===`carousel`){let e=T(t.properties,`seconds-per-image`);e!==null&&(typeof e==`number`?n=e:typeof e==`string`&&(n=Number.parseFloat(e)))}S={secondsPerImage:n}}i.images=t,i.variant=r,i.width=s,i.height=l,i.isFullWidth=d,i.isFullHeight=p,i.imageQuality=h,i.captionLayout=a,i.captionSource=g,i.altTextSource=_,i.isTransparentBackground=v,i.isCover=b,i.carouselOptions=S;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 r=T(e.properties,`is-searchable`)===!0;i.galleryId=t.uuid,i.isSearchable=r;break}case`map`:{let t=a.find(e=>e.category===`set`||e.category===`tree`);if(!t)throw Error(`Map link not found for the following component: “${n}”`);let r=!0,o=T(e.properties,`is-interactive`);o!==null&&(r=o===!0);let s=!1,c=T(e.properties,`is-clustered`);c!==null&&(s=c===!0);let l=!1,u=T(e.properties,`is-using-pins`);u!==null&&(l=u===!0);let d=null,f=T(e.properties,`custom-basemap`);f!==null&&(d=f);let p=!1,m=T(e.properties,`controls-displayed`);m!==null&&(p=m===!0);let h=!1,g=T(e.properties,`is-full-height`);g!==null&&(h=g===!0),i.mapId=t.uuid,i.isInteractive=r,i.isClustered=s,i.isUsingPins=l,i.customBasemap=d,i.isControlsDisplayed=p,i.isFullHeight=h;break}case`n-columns`:{let e=t.resource?await X(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];i.columns=e;break}case`n-rows`:{let e=t.resource?await X(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];i.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}”`);i.tableId=e.uuid;break}case`search-bar`:{let t=T(e.properties,`variant`);t??=`default`,i.variant=t;break}case`text`:{if(!s)throw Error(`Document not found for the following component: “${n}”`);let t=T(e.properties,`variant`);t??=`block`;let r=T(e.properties,`heading`);i.variant=t,i.heading=r,i.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}”`);i.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 r=T(e.properties,`chapters-displayed`);r??=!0,i.videoId=t.uuid,i.isChaptersDislayed=r===!0;break}default:console.warn(`Invalid or non-implemented component name “${n}” for the following element: “${_(t.identification.label)}”`);break}return i}async function Q(e){let t=A(e.identification),n=e.properties?.property?H(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 ge(i,e),o=r.properties.find(e=>e.label===`section-sidebar-displayed`),s=o?.values[0]?.content===!0,c=e.properties?.property?H(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,m=`default`,h=!1,g=!1,_=!1,v=!1;if(p){let e=T(p,`variant`);e&&(m=e);let t=p.filter(e=>e.label===`display`);t.length>0&&(h=t.some(e=>e.values[0].content===`name`),g=t.some(e=>e.values[0].content===`description`),_=t.some(e=>e.values[0].content===`date`),v=t.some(e=>e.values[0].content===`creators`))}return{uuid:e.uuid,type:`element`,title:{label:t.label,variant:m,properties:{isNameDisplayed:h,isDescriptionDisplayed:g,isDateDisplayed:_,isCreatorsDisplayed:v}},isDisplayedInBlockSectionSidebar:s,cssStyles:u,cssStylesMobile:f,...a}}async function _e(e){let t=e.properties?H(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=A(e.identification),r=e.slug;if(r===void 0)throw Error(`Slug not found for page “${n.label}”`);let i=e.links?I(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?H(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=T(t,`presentation`);if(n==null)continue;switch(n){case`element`:{let t=await Q(e);s.push(t);break}case`block`:{let t=await $(e);t&&s.push(t);break}}}let c=e.resource?await X(Array.isArray(e.resource)?e.resource:[e.resource],`page`):[],l=!0,u=`default`,d=`default`,f=!0,p=!1,m=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`page`)?.properties;if(m){let e=m.find(e=>e.label===`header`)?.values[0];e&&(l=e.content===!0);let t=m.find(e=>e.label===`width`)?.values[0];t&&(u=t.content);let n=m.find(e=>e.label===`variant`)?.values[0];n&&(d=n.content);let r=m.find(e=>e.label===`sidebar-visible`)?.values[0];r&&(f=r.content===!0);let i=m.find(e=>e.label===`breadcrumbs-visible`)?.values[0];i&&(p=i.content===!0)}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,isBreadcrumbsDisplayed:p,cssStyles:g,cssStylesMobile:v},webpages:c}}async function ve(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n){let n=await _e(e);n&&t.push(n)}return t}async function $(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?H(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?H(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=T(t,`presentation`);if(n==null)continue;switch(n){case`element`:{let t=await Q(e);a.push(t);break}case`block`:{let t=await $(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=ye(t),t}function ye(e){let t=[];for(let n of e.items)switch(n.type){case`block`:{let e=ye(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}function be(e){let t=H(e),r=t.find(e=>e.label===`presentation`)?.properties;if(!r)throw Error(`Presentation property not found`);let i=r.find(e=>e.label===`webUI`)?.values[0]?.content;i??=`traditional`;let a=r.find(e=>e.label===`status`)?.values[0]?.content;a??=`development`;let o=r.find(e=>e.label===`privacy`)?.values[0]?.content;o??=`public`;let s=n.safeParse({type:i,status:a,privacy:o});if(!s.success)throw Error(`Invalid website properties: ${s.error.message}`);let c=null,l=r.find(e=>e.label===`contact`);if(l){let[e,t]=(l.values[0]?.content).split(`;`);c={name:e,email:t??null}}let u=r.find(e=>e.label===`logo`)?.values[0]?.uuid??null,d=!0,f=`default`,p=`start`,m=!0,h=!0,g=!1,_=!0,v=r.find(e=>e.label===`navbar-visible`)?.values[0];v&&(d=v.content===!0);let y=r.find(e=>e.label===`navbar-variant`)?.values[0];y&&(f=y.content);let b=r.find(e=>e.label===`navbar-alignment`)?.values[0];b&&(p=b.content);let x=r.find(e=>e.label===`navbar-project-visible`)?.values[0];x&&(m=x.content===!0);let S=r.find(e=>e.label===`footer-visible`)?.values[0];S&&(h=S.content===!0);let C=r.find(e=>e.label===`sidebar-visible`)?.values[0];C&&(g=C.content===!0);let w=r.find(e=>e.label===`supports-theme-toggle`)?.values[0];w&&(_=w.content===!0);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 xe(e,t,n){if(!e.properties)throw Error(`Website properties not found`);let r=be(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 ve(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?H(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`?m(p.identification.label):_(p.identification.label);let e=p.properties?H(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=T(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 Q(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.websiteOptions){let t=`context`in e.websiteOptions.flattenContexts?[e.websiteOptions.flattenContexts]:Array.isArray(e.websiteOptions.flattenContexts)?e.websiteOptions.flattenContexts:[],n=t.map(e=>({context:Array.isArray(e.context)?e.context.flatMap(e=>Array.isArray(e.level)?e.level.map(e=>({variableUuid:e.split(`,`)[0],valueUuid:e.split(`,`)[1]})):[{variableUuid:e.level.split(`,`)[0],valueUuid:e.level.split(`,`)[1]}]):[...Array.isArray(e.context.level)?e.context.level.map(e=>({variableUuid:e.split(`,`)[0],valueUuid:e.split(`,`)[1]})):[{variableUuid:e.context.level.split(`,`)[0],valueUuid:e.context.level.split(`,`)[1]}]]}));h={collectionUuids:`uuid`in e.websiteOptions.collectionUuids?(Array.isArray(e.websiteOptions.collectionUuids.uuid)?e.websiteOptions.collectionUuids.uuid:[e.websiteOptions.collectionUuids.uuid]).map(e=>e.content):[],properties:{metadataUuids:`uuid`in e.websiteOptions.metadataUuids?(Array.isArray(e.websiteOptions.metadataUuids.uuid)?e.websiteOptions.metadataUuids.uuid:[e.websiteOptions.metadataUuids.uuid]).map(e=>e.content):[],searchUuids:`uuid`in e.websiteOptions.searchUuids?(Array.isArray(e.websiteOptions.searchUuids.uuid)?e.websiteOptions.searchUuids.uuid:[e.websiteOptions.searchUuids.uuid]).map(e=>e.content):[],labelUuids:`uuid`in e.websiteOptions.labelUuids?(Array.isArray(e.websiteOptions.labelUuids.uuid)?e.websiteOptions.labelUuids.uuid:[e.websiteOptions.labelUuids.uuid]).map(e=>e.content):[]},flattenContexts:n}}return{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:A(e.identification),project:{name:m(t),website:n===null?null:m(n)},creators:e.creators?F(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:N(e.availability),pages:a,sidebar:o,properties:r,globalOptions:h}}async function Se(e,t,n,r,i){try{let{uuid:a,filter:s,page:c,perPage:l}=o.parse({uuid:e,filter:t,page:n,perPage:r}),u=await(i??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
|
|
6
6
|
for $q in input()/ochre[@uuid='${a}']
|
|
7
7
|
let $filtered := $q//items/resource[contains(lower-case(identification/label), lower-case('${s}'))]
|
|
8
8
|
let $maxLength := count($filtered)
|
package/package.json
CHANGED