@digitalculture/ochre-sdk 0.7.16 → 0.7.17

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 CHANGED
@@ -1,5 +1,5 @@
1
- var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));const c=s(require(`zod/v4`)),l=c.z.uuid({message:`Invalid UUID provided`}),u=c.z.object({type:c.z.enum([`traditional`,`digital-collection`,`plum`,`cedar`,`elm`,`maple`,`oak`,`palm`],{message:`Invalid website type`}),status:c.z.enum([`development`,`preview`,`production`],{message:`Invalid website status`}),privacy:c.z.enum([`public`,`password`,`private`],{message:`Invalid website privacy`})}),d=c.z.enum([`annotated-document`,`annotated-image`,`bibliography`,`button`,`collection`,`empty-space`,`entries`,`filter-categories`,`iframe`,`iiif-viewer`,`image`,`image-gallery`,`n-columns`,`n-rows`,`network-graph`,`search-bar`,`table`,`text`,`timeline`,`video`],{message:`Invalid component`}),f=c.z.enum([`resource`,`spatialUnit`,`concept`,`period`,`bibliography`,`person`,`propertyValue`,`set`,`tree`]),p=c.z.enum([`string`,`integer`,`decimal`,`boolean`,`date`,`dateTime`,`time`,`coordinate`,`IDREF`]),m=c.z.object({uuid:c.z.uuid({message:`Invalid UUID`}),filter:c.z.string().optional(),page:c.z.number().positive({message:`Page must be positive`}),perPage:c.z.number().positive({message:`Per page must be positive`})}).strict(),h=c.z.string().transform(e=>e.split(` `)).pipe(c.z.array(c.z.enum([`bold`,`italic`,`underline`]))),g=c.z.string().transform(e=>e.split(` `)).pipe(c.z.array(c.z.enum([`newline`,`trailing`,`leading`]))),_=c.z.email({message:`Invalid email`}),v={includeNestedProperties:!1};function y(e,t,n=v){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=y(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function b(e,t,n=v){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=b(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function x(e,t,n=v){let{includeNestedProperties:r}=n,i=b(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=x(n.properties,t,{includeNestedProperties:r});if(e!==null)return e}}return null}function S(e,t=v){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=S(t.properties,{includeNestedProperties:!0});for(let t of e){if(r.some(e=>e.uuid===t.uuid))continue;r.push(t)}}}return r}function C(e,t,n=v){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=>C(e,t,{includeNestedProperties:!0}))),n}return!1}function w(e,t){let n=e.find(e=>e.lang===t);return n??null}function T(e){let t=e.split(` `),n=[];for(let e of t){let t=e.replaceAll(/(?<=\s|^)[([{]+|[)\]}]+(?=\s|$)/g,``).replace(/[!),.:;?\]]$/,``),r=e.indexOf(t),i=e.slice(0,r),a=e.slice(r+t.length),o=_.safeParse(t).success;if(o){n.push(i,`${i}<ExternalLink href="mailto:${t}">${t}</ExternalLink>${a}`);continue}n.push(e)}return n.join(` `)}function E(e,t){let n=e,r=h.safeParse(t);if(!r.success)return console.warn(`Invalid render options string provided: “${t}”`),e;for(let e of r.data)switch(e){case`bold`:n=`**${n}**`;break;case`italic`:n=`*${n}*`;break;case`underline`:n=`_${n}_`;break}return n.replaceAll(`&#39;`,`'`)}function D(e,t){let n=e,r=g.safeParse(t);if(!r.success)return console.warn(`Invalid whitespace string provided: “${t}”`),e;for(let e of r.data)switch(e){case`newline`:n=`<br />\n${n}`;break;case`trailing`:n=`${n} `;break;case`leading`:n=` ${n}`;break}return n.replaceAll(`&#39;`,`'`)}function O(e){return String(e).replaceAll(`&#39;`,`'`)}function k(e){let t=``;switch(typeof e.string){case`string`:case`number`:case`boolean`:t=O(e.string);break;case`object`:{let n=Array.isArray(e.string)?e.string:[e.string];for(let e of n)if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)t+=O(e);else{let n=e.rend==null?O(e.content):E(O(e.content),e.rend),r=e.whitespace==null?n:D(n,e.whitespace);t+=r}break}default:t=``;break}return t}function A(e,t){if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return T(O(e));if(`whitespace`in e&&!(`content`in e)&&!(`string`in e))return e.whitespace===`newline`?`
2
- `:``;if(`links`in e){let n=``;n=typeof e.string==`object`?j(e.string):O(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=O(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)?O(t.identification.label):j(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+=A(e,t);return`whitespace`in e&&e.whitespace!=null&&(n=D(T(n),e.whitespace)),n.replaceAll(`&#39;`,`'`)}else n=O(e.content),e.rend!=null&&(n=E(T(n),e.rend)),e.whitespace!=null&&(n=D(T(n),e.whitespace));return n}function j(e,t=`eng`){switch(typeof e.content){case`string`:case`number`:case`boolean`:return O(e.content);case`object`:if(Array.isArray(e.content)){let n=w(e.content,t);if(n)return k(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 k(n)}}else return k(e.content);default:return String(e.content)}}function ee(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 te(e){try{let t=l.parse(e),n=await fetch(`https://ochre.lib.uchicago.edu/ochre?uuid=${t}&format=json&lang="*"`);if(!n.ok)throw Error(`Failed to fetch OCHRE data`);let r=await n.json();if(!(`ochre`in r))throw Error(`Invalid OCHRE data: API response missing 'ochre' key`);return[null,r]}catch(e){return[e instanceof Error?e.message:`Unknown error`,null]}}async function ne(e,t,n){try{let[r,i]=await te(e);if(r!==null)throw Error(r);let a=ee(Object.keys(i.ochre)),o;switch(a){case`resource`:if(!(`resource`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'resource' key`);o=me(i.ochre.resource);break;case`spatialUnit`:if(!(`spatialUnit`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'spatialUnit' key`);o=he(i.ochre.spatialUnit);break;case`concept`:if(!(`concept`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'concept' key`);o=_e(i.ochre.concept);break;case`period`:if(!(`period`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'period' key`);o=G(i.ochre.period);break;case`bibliography`:if(!(`bibliography`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'bibliography' key`);o=q(i.ochre.bibliography);break;case`person`:if(!(`person`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'person' key`);o=ae(i.ochre.person);break;case`propertyValue`:if(!(`propertyValue`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'propertyValue' key`);o=Y(i.ochre.propertyValue);break;case`set`:if(!(`set`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'set' key`);o=pe(i.ochre.set,n);break;case`tree`:if(!(`tree`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'tree' key`);o=fe(i.ochre.tree);break;default:throw Error(`Invalid category`)}let s=ie(i.ochre.metadata),c={uuid:i.ochre.uuidBelongsTo,abbreviation:O(i.ochre.belongsTo)};return{error:null,metadata:s,belongsTo:c,item:o,category:t}}catch(e){return{error:e instanceof Error?e.message:`Unknown error`,metadata:void 0,belongsTo:void 0,item:void 0,category:void 0}}}function M(e){try{let t={label:[`string`,`number`,`boolean`].includes(typeof e.label)?O(e.label):j(e.label),abbreviation:``};for(let n of Object.keys(e).filter(e=>e!==`label`))t[n]=j(e[n]);return t}catch(e){return console.error(e),{label:``,abbreviation:``}}}function re(e){return e==null?[`eng`]:Array.isArray(e)?e.map(e=>j(e)):[j(e)]}function ie(e){let t={label:``,abbreviation:``};if(e.item)if(e.item.label||e.item.abbreviation){let n=``,r=``;e.item.label&&(n=j(e.item.label)),e.item.abbreviation&&(r=j(e.item.abbreviation)),t={label:n,abbreviation:r}}else t=M(e.item.identification);let n=null,r=e.project?.identification?M(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:j(e.dataset),publisher:j(e.publisher),languages:re(e.language),identifier:j(e.identifier),description:j(e.description)}}function N(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),number:e.n,content:O(e.content)}}function P(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(N(e))}return{tree:N(e.tree),project:N(e.project),spatialUnit:t}}),displayPath:e.displayPath};return n}function F(e){return typeof e.license==`string`?null:{content:e.license.content,url:e.license.target}}function ae(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?P(e.context):null,date:e.date==null?null:new Date(e.date),identification:e.identification?M(e.identification):null,availability:e.availability?F(e.availability):null,address:e.address?{country:e.address.country??null,city:e.address.city??null,state:e.address.state??null}:null,coordinates:e.coordinates?V(e.coordinates):null,content:e.content==null?null:O(e.content),events:e.events?U(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:e.properties?W(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function I(e){let t=[];for(let n of e)t.push(ae(n));return t}function oe(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:O(t.content):null,href:`href`in t&&t.href!=null?t.href:null,uuid:t.uuid,type:t.type??null,identification:t.identification?M(t.identification):null,image:null,bibliographies:`bibliography`in e?J(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 L(e){let t=[];for(let n of e)t.push(...oe(n));return t}function R(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+=T(O(i.string));else{let e=Array.isArray(i.string)?i.string:[i.string];for(let t of e)n+=A(t,r)}return{content:n,footnotes:r}}function z(e){return{publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),identification:e.identification?M(e.identification):null,url:e.href??(e.htmlImgSrcPrefix==null&&e.content!=null?O(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?O(e.content):null,widthPreview:e.widthPreview??null,heightPreview:e.heightPreview??null,width:e.width??null,height:e.height??null}}function B(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`?T(O(a.string)):T(R(a).content),n.push({number:r.noteNo,title:a.title==null?null:O(a.title),content:e})}return n}function V(e){if(typeof e==`string`){let[t,n]=e.split(`, `);return{latitude:Number(t),longitude:Number(n),type:null,label:null}}return e.coord==null?null:{latitude:e.coord.coordLatitude,longitude:e.coord.coordLongitude,type:e.coord.coordType,label:O(e.coord.coordLabel)}}function H(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`?O(e.observers).split(`;`).map(e=>e.trim()):I(Array.isArray(e.observers)?e.observers:[e.observers]),notes:e.notes?B(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?L(Array.isArray(e.links)?e.links:[e.links]):[],properties:e.properties?W(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function se(e){let t=[];for(let n of e)t.push(H(n));return t}function U(e){let t=[];for(let n of e)t.push({date:n.dateTime==null?null:new Date(n.dateTime),label:j(n.label),agent:n.agent?{uuid:n.agent.uuid,content:O(n.agent.content)}:null});return t}function ce(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=O(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(j({content:e.content})):null;break;case`coordinate`:t=null;break;case`boolean`:e.content!=null&&(n=j({content:e.content})),t=e.booleanValue??null;break;default:`slug`in e&&e.slug!=null?t=O(e.slug):e.content!=null&&(t=j({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:j(e.label,t).replace(/\s*\.{3}$/,``).trim(),values:r,comment:e.comment==null?null:O(e.comment),properties:e.property?W(Array.isArray(e.property)?e.property:[e.property]):[]}}function W(e,t=`eng`){let n=[];for(let r of e)n.push(ce(r,t));return n}function le(e){let t=[];for(let n of e)t.push({date:new Date(n.date),number:n.interpretationNo,properties:n.properties?W(Array.isArray(n.properties.property)?n.properties.property:[n.properties.property]):[]});return t}function ue(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:O(e.title),shape:e.shape===`rect`?`rectangle`:`polygon`,coords:e.coords.split(`,`).map(e=>Number.parseInt(e))});return t}function G(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:M(e.identification),description:e.description?j(e.description):null}}function K(e){let t=[];for(let n of e)t.push(G(n));return t}function q(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:M(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?M(e.identification):null,projectIdentification:e.project?.identification?M(e.project.identification):null,context:e.context?P(e.context):null,citation:{format:e.citationFormat??null,short:e.citationFormatSpan?O(`default:span`in e.citationFormatSpan?e.citationFormatSpan[`default:span`].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?O(`default:div`in e.referenceFormatDiv?e.referenceFormatDiv[`default:div`][`default:div`].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?I(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:O(e.entryInfo.startIssue),startVolume:O(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?K(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],authors:e.authors?I(Array.isArray(e.authors.person)?e.authors.person:[e.authors.person]):[],properties:e.properties?W(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function J(e){let t=[];for(let n of e)t.push(q(n));return t}function Y(e){return{uuid:e.uuid,category:`propertyValue`,number:e.n,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,context:e.context?P(e.context):null,availability:e.availability?F(e.availability):null,identification:M(e.identification),date:e.date?new Date(e.date):null,creators:e.creators?I(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?O(e.description):j(e.description):``,notes:e.notes?B(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?L(Array.isArray(e.links)?e.links:[e.links]):[]}}function de(e){let t=[];for(let n of e)t.push(Y(n));return t}function fe(e){let t=[];e.creators&&(t=I(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=ge(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit])),typeof e.items!=`string`&&`concept`in e.items&&(a=ve(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept])),typeof e.items!=`string`&&`period`in e.items&&(o=K(Array.isArray(e.items.period)?e.items.period:[e.items.period])),typeof e.items!=`string`&&`bibliography`in e.items&&(s=J(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography])),typeof e.items!=`string`&&`person`in e.items&&(c=I(Array.isArray(e.items.person)?e.items.person:[e.items.person])),typeof e.items!=`string`&&`propertyValue`in e.items&&(l=de(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]));let u={uuid:e.uuid,category:`tree`,publicationDateTime:new Date(e.publicationDateTime),identification:M(e.identification),creators:t,license:F(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?W(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return u}function pe(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=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=ge(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=ve(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=K(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=J(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=I(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=de(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:F(e.availability),identification:M(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?O(e.description):j(e.description):``,creators:e.creators?I(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],type:e.type,number:e.n,items:r}}function me(e){let t={uuid:e.uuid,category:`resource`,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,type:e.type,number:e.n,format:e.format??null,context:`context`in e&&e.context?P(e.context):null,license:`availability`in e&&e.availability?F(e.availability):null,copyright:`copyright`in e&&e.copyright!=null?O(e.copyright):null,identification:M(e.identification),date:e.date==null?null:new Date(e.date),image:e.image?z(e.image):null,creators:e.creators?I(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],notes:e.notes?B(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?O(e.description):j(e.description):``,document:e.document&&`content`in e.document?R(e.document.content):null,href:e.href??null,imageMap:e.imagemap?ue(e.imagemap):null,periods:e.periods?K(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],links:e.links?L(Array.isArray(e.links)?e.links:[e.links]):[],reverseLinks:e.reverseLinks?L(Array.isArray(e.reverseLinks)?e.reverseLinks:[e.reverseLinks]):[],properties:e.properties?W(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],citedBibliographies:e.citedBibliography?J(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(me(e));return t}function he(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?P(e.context):null,license:`availability`in e&&e.availability?F(e.availability):null,identification:M(e.identification),image:e.image?z(e.image):null,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?O(e.description):j(e.description):``,coordinates:e.coordinates?V(e.coordinates):e.coordinate?V(e.coordinate):null,observations:`observations`in e&&e.observations?se(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[H(e.observation)]:[],events:`events`in e&&e.events?U(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:`properties`in e&&e.properties?W(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return t}function ge(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(he(e));return t}function _e(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?F(e.availability):null,context:`context`in e&&e.context?P(e.context):null,identification:M(e.identification),interpretations:le(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?W(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 be(r);e&&n.push(e);break}case`block`:{let e=await $(r);e&&n.push(e);break}}}return n};function ve(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(_e(e));return t}async function ye(e,t){let n=d.parse(e.values[0].content),r={component:n},i=t.links?L(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?R(t.document.content):null;if(o===null){let e=i.find(e=>e.type===`internalDocument`);if(e){let{item:t,error:n}=await ne(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=x(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=x(e.properties,`layout`);a??=`long`,r.bibliographies=t.bibliographies,r.layout=a;break}case`button`:{let i=x(e.properties,`variant`);i??=`default`;let a=!1,o=x(e.properties,`navigate-to`);if(o===null){if(o=x(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=x(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)?O(t.identification.label):j(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=x(e.properties,`variant`);a??=`full`;let o=x(e.properties,`item-variant`);o??=`default`;let s=!1,c=x(e.properties,`show-count`);c!==null&&(s=c===!0);let l=!1,u=x(e.properties,`is-searchable`);u!==null&&(l=u===!0);let d=x(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=x(e.properties,`height`),n=x(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=x(e.properties,`variant`);a??=`entry`;let o=!1,s=x(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=x(e.properties,`height`),o=x(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=x(e.properties,`variant`);i??=`default`;let o=x(e.properties,`layout-caption`);o??=`bottom`;let s=null,c=x(e.properties,`width`);c!==null&&(typeof c==`number`?s=c:typeof c==`string`&&(s=Number.parseFloat(c)));let l=null,u=x(e.properties,`height`);u!==null&&(typeof u==`number`?l=u:typeof u==`string`&&(l=Number.parseFloat(u)));let d=!0,f=x(e.properties,`is-full-width`);f!==null&&(d=f===!0);let p=!0,m=x(e.properties,`is-full-height`);m!==null&&(p=m===!0);let h=x(e.properties,`image-quality`);h??=`high`;let g=x(e.properties,`caption-source`);g??=`name`;let _=x(e.properties,`alt-text-source`);_??=`name`;let v=!1,b=x(e.properties,`is-transparent`);b!==null&&(v=b===!0);let S=!1,C=x(e.properties,`is-cover`);C!==null&&(S=C===!0);let w=null;if(t.length>1){let t=y(e.properties,`variant`),n=5;if(t&&t.values[0].content===`carousel`){let e=x(t.properties,`seconds-per-image`);e!==null&&(typeof e==`number`?n=e:typeof e==`string`&&(n=Number.parseFloat(e)))}w={secondsPerImage:n}}r.images=t,r.variant=i,r.width=s,r.height=l,r.isFullWidth=d,r.isFullHeight=p,r.imageQuality=h,r.captionLayout=o,r.captionSource=g,r.altTextSource=_,r.isTransparentBackground=v,r.isCover=S,r.carouselOptions=w;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=x(e.properties,`is-searchable`)===!0;r.galleryId=t.uuid,r.isSearchable=a;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=x(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=x(e.properties,`variant`);t??=`block`;let i=x(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=x(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: “${j(t.identification.label)}”`);break}return r}async function Q(e){let t=M(e.identification),n=e.properties?.property?W(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 ye(i,e),o=r.properties.find(e=>e.label===`section-sidebar-displayed`),s=o?.values[0]?.content===!0,c=e.properties?.property?W(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=x(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 be(e){let t=e.properties?W(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=M(e.identification),r=e.slug;if(r===void 0)throw Error(`Slug not found for page “${n.label}”`);let i=e.links?L(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?W(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=x(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 xe(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n){let n=await be(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?W(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?W(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=x(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=Se(t),t}function Se(e){let t=[];for(let n of e.items)switch(n.type){case`block`:{let e=Se(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 Ce(e){let t=W(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;if(r==null)throw Error(`Website type not found`);let i=n.find(e=>e.label===`status`)?.values[0]?.content;if(i==null)throw Error(`Website status not found`);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 we(e,t,n){if(!e.properties)throw Error(`Website properties not found`);let r=Ce(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 xe(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?W(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`?O(p.identification.label):j(p.identification.label);let e=p.properties?W(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=x(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.collectionOptions){let t=[];for(let e of a)for(let n of e.items)n.type===`element`&&n.component===`collection`&&t.push(n.collectionId);m={uuids:t,properties:{metadataUuids:e.collectionOptions.metadataUuids.uuid?(Array.isArray(e.collectionOptions.metadataUuids.uuid)?e.collectionOptions.metadataUuids.uuid:[e.collectionOptions.metadataUuids.uuid]).map(e=>e.content):[],searchUuids:e.collectionOptions.searchUuids.uuid?(Array.isArray(e.collectionOptions.searchUuids.uuid)?e.collectionOptions.searchUuids.uuid:[e.collectionOptions.searchUuids.uuid]).map(e=>e.content):[],labelUuids:e.collectionOptions.labelUuids.uuid?(Array.isArray(e.collectionOptions.labelUuids.uuid)?e.collectionOptions.labelUuids.uuid:[e.collectionOptions.labelUuids.uuid]).map(e=>e.content):[]}}}return{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:M(e.identification),project:{name:O(t),website:n===null?null:O(n)},creators:e.creators?I(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:F(e.availability),pages:a,sidebar:o,properties:r,collectionOptions:m}}async function Te(e,t,n,r){try{let{uuid:i,filter:a,page:o,perPage:s}=m.parse({uuid:e,filter:t,page:n,perPage:r}),c=await fetch(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));const c=s(require(`zod/v4`)),l=c.z.uuid({message:`Invalid UUID provided`}),u=c.z.object({type:c.z.enum([`traditional`,`digital-collection`,`plum`,`cedar`,`elm`,`maple`,`oak`,`palm`],{message:`Invalid website type`}),status:c.z.enum([`development`,`preview`,`production`],{message:`Invalid website status`}),privacy:c.z.enum([`public`,`password`,`private`],{message:`Invalid website privacy`})}),d=c.z.enum([`annotated-document`,`annotated-image`,`bibliography`,`button`,`collection`,`empty-space`,`entries`,`filter-categories`,`iframe`,`iiif-viewer`,`image`,`image-gallery`,`n-columns`,`n-rows`,`network-graph`,`search-bar`,`table`,`text`,`timeline`,`video`],{message:`Invalid component`}),f=c.z.enum([`resource`,`spatialUnit`,`concept`,`period`,`bibliography`,`person`,`propertyValue`,`set`,`tree`]),p=c.z.enum([`string`,`integer`,`decimal`,`boolean`,`date`,`dateTime`,`time`,`coordinate`,`IDREF`]),m=c.z.object({uuid:c.z.uuid({message:`Invalid UUID`}),filter:c.z.string().optional(),page:c.z.number().positive({message:`Page must be positive`}),perPage:c.z.number().positive({message:`Per page must be positive`})}).strict(),h=c.z.string().transform(e=>e.split(` `)).pipe(c.z.array(c.z.enum([`bold`,`italic`,`underline`]))),g=c.z.string().transform(e=>e.split(` `)).pipe(c.z.array(c.z.enum([`newline`,`trailing`,`leading`]))),_=c.z.email({message:`Invalid email`}),v={includeNestedProperties:!1};function y(e,t,n=v){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=y(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function b(e,t,n=v){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=b(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function x(e,t,n=v){let{includeNestedProperties:r}=n,i=b(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=x(n.properties,t,{includeNestedProperties:r});if(e!==null)return e}}return null}function S(e,t,n=v){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=S(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function C(e,t,n=v){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=C(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function w(e,t,n=v){let{includeNestedProperties:r}=n,i=C(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=w(n.properties,t,{includeNestedProperties:r});if(e!==null)return e}}return null}function T(e,t=v){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=T(t.properties,{includeNestedProperties:!0});for(let t of e){if(r.some(e=>e.uuid===t.uuid))continue;r.push(t)}}}return r}function E(e,t=v){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=E(t.properties,{includeNestedProperties:!0});for(let t of e){if(r.includes(t))continue;r.push(t)}}}return r}function D(e,t,n=v){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=>D(e,t,{includeNestedProperties:!0}))),n}return!1}function ee(e,t){let n=e.find(e=>e.lang===t);return n??null}function O(e){let t=e.split(` `),n=[];for(let e of t){let t=e.replaceAll(/(?<=\s|^)[([{]+|[)\]}]+(?=\s|$)/g,``).replace(/[!),.:;?\]]$/,``),r=e.indexOf(t),i=e.slice(0,r),a=e.slice(r+t.length),o=_.safeParse(t).success;if(o){n.push(i,`${i}<ExternalLink href="mailto:${t}">${t}</ExternalLink>${a}`);continue}n.push(e)}return n.join(` `)}function te(e,t){let n=e,r=h.safeParse(t);if(!r.success)return console.warn(`Invalid render options string provided: “${t}”`),e;for(let e of r.data)switch(e){case`bold`:n=`**${n}**`;break;case`italic`:n=`*${n}*`;break;case`underline`:n=`_${n}_`;break}return n.replaceAll(`&#39;`,`'`)}function k(e,t){let n=e,r=g.safeParse(t);if(!r.success)return console.warn(`Invalid whitespace string provided: “${t}”`),e;for(let e of r.data)switch(e){case`newline`:n=`<br />\n${n}`;break;case`trailing`:n=`${n} `;break;case`leading`:n=` ${n}`;break}return n.replaceAll(`&#39;`,`'`)}function A(e){return String(e).replaceAll(`&#39;`,`'`)}function j(e){let t=``;switch(typeof e.string){case`string`:case`number`:case`boolean`:t=A(e.string);break;case`object`:{let n=Array.isArray(e.string)?e.string:[e.string];for(let e of n)if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)t+=A(e);else{let n=e.rend==null?A(e.content):te(A(e.content),e.rend),r=e.whitespace==null?n:k(n,e.whitespace);t+=r}break}default:t=``;break}return t}function M(e,t){if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return O(A(e));if(`whitespace`in e&&!(`content`in e)&&!(`string`in e))return e.whitespace===`newline`?`
2
+ `:``;if(`links`in e){let n=``;n=typeof e.string==`object`?N(e.string):A(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=A(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)?A(t.identification.label):N(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+=M(e,t);return`whitespace`in e&&e.whitespace!=null&&(n=k(O(n),e.whitespace)),n.replaceAll(`&#39;`,`'`)}else n=A(e.content),e.rend!=null&&(n=te(O(n),e.rend)),e.whitespace!=null&&(n=k(O(n),e.whitespace));return n}function N(e,t=`eng`){switch(typeof e.content){case`string`:case`number`:case`boolean`:return A(e.content);case`object`:if(Array.isArray(e.content)){let n=ee(e.content,t);if(n)return j(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 j(n)}}else return j(e.content);default:return String(e.content)}}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){try{let t=l.parse(e),n=await fetch(`https://ochre.lib.uchicago.edu/ochre?uuid=${t}&format=json&lang="*"`);if(!n.ok)throw Error(`Failed to fetch OCHRE data`);let r=await n.json();if(!(`ochre`in r))throw Error(`Invalid OCHRE data: API response missing 'ochre' key`);return[null,r]}catch(e){return[e instanceof Error?e.message:`Unknown error`,null]}}async function ie(e,t,n){try{let[r,i]=await re(e);if(r!==null)throw Error(r);let a=ne(Object.keys(i.ochre)),o;switch(a){case`resource`:if(!(`resource`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'resource' key`);o=be(i.ochre.resource);break;case`spatialUnit`:if(!(`spatialUnit`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'spatialUnit' key`);o=xe(i.ochre.spatialUnit);break;case`concept`:if(!(`concept`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'concept' key`);o=Ce(i.ochre.concept);break;case`period`:if(!(`period`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'period' key`);o=me(i.ochre.period);break;case`bibliography`:if(!(`bibliography`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'bibliography' key`);o=he(i.ochre.bibliography);break;case`person`:if(!(`person`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'person' key`);o=se(i.ochre.person);break;case`propertyValue`:if(!(`propertyValue`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'propertyValue' key`);o=ge(i.ochre.propertyValue);break;case`set`:if(!(`set`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'set' key`);o=ye(i.ochre.set,n);break;case`tree`:if(!(`tree`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'tree' key`);o=ve(i.ochre.tree);break;default:throw Error(`Invalid category`)}let s=oe(i.ochre.metadata),c={uuid:i.ochre.uuidBelongsTo,abbreviation:A(i.ochre.belongsTo)};return{error:null,metadata:s,belongsTo:c,item:o,category:t}}catch(e){return{error:e instanceof Error?e.message:`Unknown error`,metadata:void 0,belongsTo:void 0,item:void 0,category:void 0}}}function P(e){try{let t={label:[`string`,`number`,`boolean`].includes(typeof e.label)?A(e.label):N(e.label),abbreviation:``};for(let n of Object.keys(e).filter(e=>e!==`label`))t[n]=N(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=>N(e)):[N(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=N(e.item.label)),e.item.abbreviation&&(r=N(e.item.abbreviation)),t={label:n,abbreviation:r}}else t=P(e.item.identification);let n=null,r=e.project?.identification?P(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:N(e.dataset),publisher:N(e.publisher),languages:ae(e.language),identifier:N(e.identifier),description:N(e.description)}}function F(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),number:e.n,content:A(e.content)}}function I(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(F(e))}return{tree:F(e.tree),project:F(e.project),spatialUnit:t}}),displayPath:e.displayPath};return n}function L(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?I(e.context):null,date:e.date==null?null:new Date(e.date),identification:e.identification?P(e.identification):null,availability:e.availability?L(e.availability):null,address:e.address?{country:e.address.country??null,city:e.address.city??null,state:e.address.state??null}:null,coordinates:e.coordinates?H(e.coordinates):null,content:e.content==null?null:A(e.content),events:e.events?W(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function R(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:A(t.content):null,href:`href`in t&&t.href!=null?t.href:null,uuid:t.uuid,type:t.type??null,identification:t.identification?P(t.identification):null,image:null,bibliographies:`bibliography`in e?q(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 z(e){let t=[];for(let n of e)t.push(...ce(n));return t}function B(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+=O(A(i.string));else{let e=Array.isArray(i.string)?i.string:[i.string];for(let t of e)n+=M(t,r)}return{content:n,footnotes:r}}function le(e){return{publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),identification:e.identification?P(e.identification):null,url:e.href??(e.htmlImgSrcPrefix==null&&e.content!=null?A(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?A(e.content):null,widthPreview:e.widthPreview??null,heightPreview:e.heightPreview??null,width:e.width??null,height:e.height??null}}function V(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`?O(A(a.string)):O(B(a).content),n.push({number:r.noteNo,title:a.title==null?null:A(a.title),content:e})}return n}function H(e){if(typeof e==`string`){let[t,n]=e.split(`, `);return{latitude:Number(t),longitude:Number(n),type:null,label:null}}return e.coord==null?null:{latitude:e.coord.coordLatitude,longitude:e.coord.coordLongitude,type:e.coord.coordType,label:A(e.coord.coordLabel)}}function U(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`?A(e.observers).split(`;`).map(e=>e.trim()):R(Array.isArray(e.observers)?e.observers:[e.observers]),notes:e.notes?V(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?z(Array.isArray(e.links)?e.links:[e.links]):[],properties:e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function ue(e){let t=[];for(let n of e)t.push(U(n));return t}function W(e){let t=[];for(let n of e)t.push({date:n.dateTime==null?null:new Date(n.dateTime),label:N(n.label),agent:n.agent?{uuid:n.agent.uuid,content:A(n.agent.content)}:null});return t}function de(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=A(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(N({content:e.content})):null;break;case`coordinate`:t=null;break;case`boolean`:e.content!=null&&(n=N({content:e.content})),t=e.booleanValue??null;break;default:`slug`in e&&e.slug!=null?t=A(e.slug):e.content!=null&&(t=N({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:N(e.label,t).replace(/\s*\.{3}$/,``).trim(),values:r,comment:e.comment==null?null:A(e.comment),properties:e.property?G(Array.isArray(e.property)?e.property:[e.property]):[]}}function G(e,t=`eng`){let n=[];for(let r of e)n.push(de(r,t));return n}function fe(e){let t=[];for(let n of e)t.push({date:new Date(n.date),number:n.interpretationNo,properties:n.properties?G(Array.isArray(n.properties.property)?n.properties.property:[n.properties.property]):[]});return t}function pe(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:A(e.title),shape:e.shape===`rect`?`rectangle`:`polygon`,coords:e.coords.split(`,`).map(e=>Number.parseInt(e))});return t}function me(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:P(e.identification),description:e.description?N(e.description):null}}function K(e){let t=[];for(let n of e)t.push(me(n));return t}function he(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:P(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?P(e.identification):null,projectIdentification:e.project?.identification?P(e.project.identification):null,context:e.context?I(e.context):null,citation:{format:e.citationFormat??null,short:e.citationFormatSpan?A(`default:span`in e.citationFormatSpan?e.citationFormatSpan[`default:span`].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?A(`default:div`in e.referenceFormatDiv?e.referenceFormatDiv[`default:div`][`default:div`].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?R(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:A(e.entryInfo.startIssue),startVolume:A(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?K(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],authors:e.authors?R(Array.isArray(e.authors.person)?e.authors.person:[e.authors.person]):[],properties:e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function q(e){let t=[];for(let n of e)t.push(he(n));return t}function ge(e){return{uuid:e.uuid,category:`propertyValue`,number:e.n,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,context:e.context?I(e.context):null,availability:e.availability?L(e.availability):null,identification:P(e.identification),date:e.date?new Date(e.date):null,creators:e.creators?R(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?A(e.description):N(e.description):``,notes:e.notes?V(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?z(Array.isArray(e.links)?e.links:[e.links]):[]}}function _e(e){let t=[];for(let n of e)t.push(ge(n));return t}function ve(e){let t=[];e.creators&&(t=R(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=J(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource])),typeof e.items!=`string`&&`spatialUnit`in e.items&&(i=Se(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit])),typeof e.items!=`string`&&`concept`in e.items&&(a=X(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept])),typeof e.items!=`string`&&`period`in e.items&&(o=K(Array.isArray(e.items.period)?e.items.period:[e.items.period])),typeof e.items!=`string`&&`bibliography`in e.items&&(s=q(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography])),typeof e.items!=`string`&&`person`in e.items&&(c=R(Array.isArray(e.items.person)?e.items.person:[e.items.person])),typeof e.items!=`string`&&`propertyValue`in e.items&&(l=_e(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]));let u={uuid:e.uuid,category:`tree`,publicationDateTime:new Date(e.publicationDateTime),identification:P(e.identification),creators:t,license:L(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?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return u}function ye(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=J(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=Se(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=X(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=K(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=q(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=R(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=_e(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:L(e.availability),identification:P(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?A(e.description):N(e.description):``,creators:e.creators?R(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],type:e.type,number:e.n,items:r}}function be(e){let t={uuid:e.uuid,category:`resource`,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,type:e.type,number:e.n,format:e.format??null,context:`context`in e&&e.context?I(e.context):null,license:`availability`in e&&e.availability?L(e.availability):null,copyright:`copyright`in e&&e.copyright!=null?A(e.copyright):null,identification:P(e.identification),date:e.date==null?null:new Date(e.date),image:e.image?le(e.image):null,creators:e.creators?R(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],notes:e.notes?V(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?A(e.description):N(e.description):``,document:e.document&&`content`in e.document?B(e.document.content):null,href:e.href??null,imageMap:e.imagemap?pe(e.imagemap):null,periods:e.periods?K(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],links:e.links?z(Array.isArray(e.links)?e.links:[e.links]):[],reverseLinks:e.reverseLinks?z(Array.isArray(e.reverseLinks)?e.reverseLinks:[e.reverseLinks]):[],properties:e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],citedBibliographies:e.citedBibliography?q(Array.isArray(e.citedBibliography.reference)?e.citedBibliography.reference:[e.citedBibliography.reference]):[],resources:e.resource?J(Array.isArray(e.resource)?e.resource:[e.resource]):[]};return t}function J(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(be(e));return t}function xe(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?I(e.context):null,license:`availability`in e&&e.availability?L(e.availability):null,identification:P(e.identification),image:e.image?le(e.image):null,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?A(e.description):N(e.description):``,coordinates:e.coordinates?H(e.coordinates):e.coordinate?H(e.coordinate):null,observations:`observations`in e&&e.observations?ue(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[U(e.observation)]:[],events:`events`in e&&e.events?W(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:`properties`in e&&e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return t}function Se(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(xe(e));return t}function Ce(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?L(e.availability):null,context:`context`in e&&e.context?I(e.context):null,identification:P(e.identification),interpretations:fe(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation])};return t}const Y=async(e,t)=>{let n=[];for(let r of e){let e=r.properties?G(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 Z(r);n.push(e);break}case`page`:{let e=await Te(r);e&&n.push(e);break}case`block`:{let e=await Q(r);e&&n.push(e);break}}}return n};function X(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(Ce(e));return t}async function we(e,t){let n=d.parse(e.values[0].content),r={component:n},i=t.links?z(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?B(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=w(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=w(e.properties,`layout`);a??=`long`,r.bibliographies=t.bibliographies,r.layout=a;break}case`button`:{let i=w(e.properties,`variant`);i??=`default`;let a=!1,o=w(e.properties,`navigate-to`);if(o===null){if(o=w(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=w(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)?A(t.identification.label):N(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=w(e.properties,`variant`);a??=`full`;let o=w(e.properties,`item-variant`);o??=`default`;let s=!1,c=w(e.properties,`show-count`);c!==null&&(s=c===!0);let l=!1,u=w(e.properties,`is-searchable`);u!==null&&(l=u===!0);let d=w(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=w(e.properties,`height`),n=w(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=w(e.properties,`variant`);a??=`entry`;let o=!1,s=w(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=w(e.properties,`height`),o=w(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=w(e.properties,`variant`);i??=`default`;let o=w(e.properties,`layout-caption`);o??=`bottom`;let s=null,c=w(e.properties,`width`);c!==null&&(typeof c==`number`?s=c:typeof c==`string`&&(s=Number.parseFloat(c)));let l=null,u=w(e.properties,`height`);u!==null&&(typeof u==`number`?l=u:typeof u==`string`&&(l=Number.parseFloat(u)));let d=!0,f=w(e.properties,`is-full-width`);f!==null&&(d=f===!0);let p=!0,m=w(e.properties,`is-full-height`);m!==null&&(p=m===!0);let h=w(e.properties,`image-quality`);h??=`high`;let g=w(e.properties,`caption-source`);g??=`name`;let _=w(e.properties,`alt-text-source`);_??=`name`;let v=!1,y=w(e.properties,`is-transparent`);y!==null&&(v=y===!0);let b=!1,x=w(e.properties,`is-cover`);x!==null&&(b=x===!0);let C=null;if(t.length>1){let t=S(e.properties,`variant`),n=5;if(t&&t.values[0].content===`carousel`){let e=w(t.properties,`seconds-per-image`);e!==null&&(typeof e==`number`?n=e:typeof e==`string`&&(n=Number.parseFloat(e)))}C={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=C;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=w(e.properties,`is-searchable`)===!0;r.galleryId=t.uuid,r.isSearchable=a;break}case`n-columns`:{let e=t.resource?await Y(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];r.columns=e;break}case`n-rows`:{let e=t.resource?await Y(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=w(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=w(e.properties,`variant`);t??=`block`;let i=w(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=w(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: “${N(t.identification.label)}”`);break}return r}async function Z(e){let t=P(e.identification),n=e.properties?.property?G(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?G(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=w(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?G(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=P(e.identification),r=e.slug;if(r===void 0)throw Error(`Slug not found for page “${n.label}”`);let i=e.links?z(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?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=w(t,`presentation`);if(n==null)continue;switch(n){case`element`:{let t=await Z(e);s.push(t);break}case`block`:{let t=await Q(e);t&&s.push(t);break}}}let c=e.resource?await Y(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 Q(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?G(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?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=w(t,`presentation`);if(n==null)continue;switch(n){case`element`:{let t=await Z(e);a.push(t);break}case`block`:{let t=await Q(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=$(t),t}function $(e){let t=[];for(let n of e.items)switch(n.type){case`block`:{let e=$(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 De(e){let t=G(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;if(r==null)throw Error(`Website type not found`);let i=n.find(e=>e.label===`status`)?.values[0]?.content;if(i==null)throw Error(`Website status not found`);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 Oe(e,t,n){if(!e.properties)throw Error(`Website properties not found`);let r=De(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?G(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`?A(p.identification.label):N(p.identification.label);let e=p.properties?G(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=w(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 Z(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.collectionOptions){let t=[];for(let e of a)for(let n of e.items)n.type===`element`&&n.component===`collection`&&t.push(n.collectionId);m={uuids:t,properties:{metadataUuids:e.collectionOptions.metadataUuids.uuid?(Array.isArray(e.collectionOptions.metadataUuids.uuid)?e.collectionOptions.metadataUuids.uuid:[e.collectionOptions.metadataUuids.uuid]).map(e=>e.content):[],searchUuids:e.collectionOptions.searchUuids.uuid?(Array.isArray(e.collectionOptions.searchUuids.uuid)?e.collectionOptions.searchUuids.uuid:[e.collectionOptions.searchUuids.uuid]).map(e=>e.content):[],labelUuids:e.collectionOptions.labelUuids.uuid?(Array.isArray(e.collectionOptions.labelUuids.uuid)?e.collectionOptions.labelUuids.uuid:[e.collectionOptions.labelUuids.uuid]).map(e=>e.content):[]}}}return{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:P(e.identification),project:{name:A(t),website:n===null?null:A(n)},creators:e.creators?R(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:L(e.availability),pages:a,sidebar:o,properties:r,collectionOptions:m}}async function ke(e,t,n,r){try{let{uuid:i,filter:a,page:o,perPage:s}=m.parse({uuid:e,filter:t,page:n,perPage:r}),c=await fetch(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
3
3
  for $q in input()/ochre[@uuid='${i}']
4
4
  let $filtered := $q//items/resource[contains(lower-case(identification/label), lower-case('${a}'))]
5
5
  let $maxLength := count($filtered)
@@ -8,4 +8,4 @@ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=
8
8
  {$q/metadata/item}
9
9
  {$filtered[position() >= ${((o-1)*s+1).toString()} and position() < ${(o*s+1).toString()}]}
10
10
  </gallery>
11
- `)}&format=json`);if(!c.ok)throw Error(`Error fetching gallery items, please try again later.`);let l=await c.json();if(!(`gallery`in l.result))throw Error(`Failed to fetch gallery`);let u=M(l.result.gallery.item.identification),d=M(l.result.gallery.project.identification),f={identification:u,projectIdentification:d,resources:X(l.result.gallery.resource?Array.isArray(l.result.gallery.resource)?l.result.gallery.resource:[l.result.gallery.resource]:[]),maxLength:l.result.gallery.maxLength};return{item:f,error:null}}catch(e){return console.error(e),{item:null,error:e instanceof Error?e.message:`Failed to fetch gallery`}}}async function Ee(e){try{let t=await fetch(`https://ochre.lib.uchicago.edu/ochre?xquery=for $q in input()/ochre[tree[@type='lesson'][identification/abbreviation='${e.toLocaleLowerCase(`en-US`)}']] return $q&format=json`);if(!t.ok)throw Error(`Failed to fetch website`);let n=await t.json();if(!(`ochre`in n.result)||!(`tree`in n.result.ochre))throw Error(`Failed to fetch website`);let r=n.result.ochre.metadata.project?.identification?M(n.result.ochre.metadata.project.identification):null,i=await we(n.result.ochre.tree,r?.label??``,n.result.ochre.metadata.project?.identification.website??null);return i}catch(e){return console.error(e),null}}exports.fetchGallery=Te,exports.fetchItem=ne,exports.fetchWebsite=Ee,exports.filterProperties=C,exports.getPropertyByLabel=y,exports.getPropertyValueByLabel=x,exports.getPropertyValuesByLabel=b,exports.getUniqueProperties=S;
11
+ `)}&format=json`);if(!c.ok)throw Error(`Error fetching gallery items, please try again later.`);let l=await c.json();if(!(`gallery`in l.result))throw Error(`Failed to fetch gallery`);let u=P(l.result.gallery.item.identification),d=P(l.result.gallery.project.identification),f={identification:u,projectIdentification:d,resources:J(l.result.gallery.resource?Array.isArray(l.result.gallery.resource)?l.result.gallery.resource:[l.result.gallery.resource]:[]),maxLength:l.result.gallery.maxLength};return{item:f,error:null}}catch(e){return console.error(e),{item:null,error:e instanceof Error?e.message:`Failed to fetch gallery`}}}async function Ae(e){try{let t=await fetch(`https://ochre.lib.uchicago.edu/ochre?xquery=for $q in input()/ochre[tree[@type='lesson'][identification/abbreviation='${e.toLocaleLowerCase(`en-US`)}']] return $q&format=json`);if(!t.ok)throw Error(`Failed to fetch website`);let n=await t.json();if(!(`ochre`in n.result)||!(`tree`in n.result.ochre))throw Error(`Failed to fetch website`);let r=n.result.ochre.metadata.project?.identification?P(n.result.ochre.metadata.project.identification):null,i=await Oe(n.result.ochre.tree,r?.label??``,n.result.ochre.metadata.project?.identification.website??null);return i}catch(e){return console.error(e),null}}exports.fetchGallery=ke,exports.fetchItem=ie,exports.fetchWebsite=Ae,exports.filterProperties=D,exports.getPropertyByLabel=S,exports.getPropertyByUuid=y,exports.getPropertyValueByLabel=w,exports.getPropertyValueByUuid=x,exports.getPropertyValuesByLabel=C,exports.getPropertyValuesByUuid=b,exports.getUniqueProperties=T,exports.getUniquePropertyLabels=E;
package/dist/index.d.cts CHANGED
@@ -777,6 +777,59 @@ type PropertyOptions = {
777
777
  /** Whether to recursively search through nested properties */
778
778
  includeNestedProperties: boolean;
779
779
  };
780
+ /**
781
+ * Finds a property by its UUID in an array of properties
782
+ *
783
+ * @param properties - Array of properties to search through
784
+ * @param uuid - The UUID to search for
785
+ * @param options - Search options, including whether to include nested properties
786
+ * @returns The matching Property object, or null if not found
787
+ *
788
+ * @example
789
+ * ```ts
790
+ * const property = getPropertyByUuid(properties, "123e4567-e89b-12d3-a456-426614174000", { includeNestedProperties: true });
791
+ * if (property) {
792
+ * console.log(property.values);
793
+ * }
794
+ * ```
795
+ */
796
+ declare function getPropertyByUuid(properties: Array<Property>, uuid: string, options?: PropertyOptions): Property | null;
797
+ /**
798
+ * Retrieves all values for a property with the given UUID
799
+ *
800
+ * @param properties - Array of properties to search through
801
+ * @param uuid - The UUID to search for
802
+ * @param options - Search options, including whether to include nested properties
803
+ * @returns Array of property values as strings, or null if property not found
804
+ *
805
+ * @example
806
+ * ```ts
807
+ * const values = getPropertyValuesByUuid(properties, "123e4567-e89b-12d3-a456-426614174000");
808
+ * if (values) {
809
+ * for (const value of values) {
810
+ * console.log(value);
811
+ * }
812
+ * }
813
+ * ```
814
+ */
815
+ declare function getPropertyValuesByUuid(properties: Array<Property>, uuid: string, options?: PropertyOptions): Array<string | number | boolean | Date | null> | null;
816
+ /**
817
+ * Gets the first value of a property with the given UUID
818
+ *
819
+ * @param properties - Array of properties to search through
820
+ * @param uuid - The UUID to search for
821
+ * @param options - Search options, including whether to include nested properties
822
+ * @returns The first property value as string, or null if property not found
823
+ *
824
+ * @example
825
+ * ```ts
826
+ * const title = getPropertyValueByUuid(properties, "123e4567-e89b-12d3-a456-426614174000");
827
+ * if (title) {
828
+ * console.log(`Document title: ${title}`);
829
+ * }
830
+ * ```
831
+ */
832
+ declare function getPropertyValueByUuid(properties: Array<Property>, uuid: string, options?: PropertyOptions): string | number | boolean | Date | null;
780
833
  /**
781
834
  * Finds a property by its label in an array of properties
782
835
  *
@@ -844,6 +897,20 @@ declare function getPropertyValueByLabel(properties: Array<Property>, label: str
844
897
  * ```
845
898
  */
846
899
  declare function getUniqueProperties(properties: Array<Property>, options?: PropertyOptions): Array<Property>;
900
+ /**
901
+ * Gets all unique property labels from an array of properties
902
+ *
903
+ * @param properties - Array of properties to get unique property labels from
904
+ * @param options - Search options, including whether to include nested properties
905
+ * @returns Array of unique property labels
906
+ *
907
+ * @example
908
+ * ```ts
909
+ * const properties = getAllUniquePropertyLabels(properties, { includeNestedProperties: true });
910
+ * console.log(`Available properties: ${properties.join(", ")}`);
911
+ * ```
912
+ */
913
+ declare function getUniquePropertyLabels(properties: Array<Property>, options?: PropertyOptions): Array<string>;
847
914
  /**
848
915
  * Filters a property based on a label and value criteria
849
916
  *
@@ -871,4 +938,4 @@ declare function filterProperties(property: Property, filter: {
871
938
  }, options?: PropertyOptions): boolean;
872
939
 
873
940
  //#endregion
874
- export { Bibliography, Concept, Context, ContextItem, ContextNode, Coordinates, Data, DataCategory, Document, Event, Footnote, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyValue, PropertyValueContent, PropertyValueContentType, Resource, Set, SpatialUnit, Style, Tree, WebBlock, WebElement, WebElementComponent, WebImage, WebSectionSidebarItem, Webpage, WebpageProperties, Website, WebsiteProperties, fetchGallery, fetchItem, fetchWebsite, filterProperties, getPropertyByLabel, getPropertyValueByLabel, getPropertyValuesByLabel, getUniqueProperties };
941
+ export { Bibliography, Concept, Context, ContextItem, ContextNode, Coordinates, Data, DataCategory, Document, Event, Footnote, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyValue, PropertyValueContent, PropertyValueContentType, Resource, Set, SpatialUnit, Style, Tree, WebBlock, WebElement, WebElementComponent, WebImage, WebSectionSidebarItem, Webpage, WebpageProperties, Website, WebsiteProperties, fetchGallery, fetchItem, fetchWebsite, filterProperties, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
package/dist/index.d.ts CHANGED
@@ -777,6 +777,59 @@ type PropertyOptions = {
777
777
  /** Whether to recursively search through nested properties */
778
778
  includeNestedProperties: boolean;
779
779
  };
780
+ /**
781
+ * Finds a property by its UUID in an array of properties
782
+ *
783
+ * @param properties - Array of properties to search through
784
+ * @param uuid - The UUID to search for
785
+ * @param options - Search options, including whether to include nested properties
786
+ * @returns The matching Property object, or null if not found
787
+ *
788
+ * @example
789
+ * ```ts
790
+ * const property = getPropertyByUuid(properties, "123e4567-e89b-12d3-a456-426614174000", { includeNestedProperties: true });
791
+ * if (property) {
792
+ * console.log(property.values);
793
+ * }
794
+ * ```
795
+ */
796
+ declare function getPropertyByUuid(properties: Array<Property>, uuid: string, options?: PropertyOptions): Property | null;
797
+ /**
798
+ * Retrieves all values for a property with the given UUID
799
+ *
800
+ * @param properties - Array of properties to search through
801
+ * @param uuid - The UUID to search for
802
+ * @param options - Search options, including whether to include nested properties
803
+ * @returns Array of property values as strings, or null if property not found
804
+ *
805
+ * @example
806
+ * ```ts
807
+ * const values = getPropertyValuesByUuid(properties, "123e4567-e89b-12d3-a456-426614174000");
808
+ * if (values) {
809
+ * for (const value of values) {
810
+ * console.log(value);
811
+ * }
812
+ * }
813
+ * ```
814
+ */
815
+ declare function getPropertyValuesByUuid(properties: Array<Property>, uuid: string, options?: PropertyOptions): Array<string | number | boolean | Date | null> | null;
816
+ /**
817
+ * Gets the first value of a property with the given UUID
818
+ *
819
+ * @param properties - Array of properties to search through
820
+ * @param uuid - The UUID to search for
821
+ * @param options - Search options, including whether to include nested properties
822
+ * @returns The first property value as string, or null if property not found
823
+ *
824
+ * @example
825
+ * ```ts
826
+ * const title = getPropertyValueByUuid(properties, "123e4567-e89b-12d3-a456-426614174000");
827
+ * if (title) {
828
+ * console.log(`Document title: ${title}`);
829
+ * }
830
+ * ```
831
+ */
832
+ declare function getPropertyValueByUuid(properties: Array<Property>, uuid: string, options?: PropertyOptions): string | number | boolean | Date | null;
780
833
  /**
781
834
  * Finds a property by its label in an array of properties
782
835
  *
@@ -844,6 +897,20 @@ declare function getPropertyValueByLabel(properties: Array<Property>, label: str
844
897
  * ```
845
898
  */
846
899
  declare function getUniqueProperties(properties: Array<Property>, options?: PropertyOptions): Array<Property>;
900
+ /**
901
+ * Gets all unique property labels from an array of properties
902
+ *
903
+ * @param properties - Array of properties to get unique property labels from
904
+ * @param options - Search options, including whether to include nested properties
905
+ * @returns Array of unique property labels
906
+ *
907
+ * @example
908
+ * ```ts
909
+ * const properties = getAllUniquePropertyLabels(properties, { includeNestedProperties: true });
910
+ * console.log(`Available properties: ${properties.join(", ")}`);
911
+ * ```
912
+ */
913
+ declare function getUniquePropertyLabels(properties: Array<Property>, options?: PropertyOptions): Array<string>;
847
914
  /**
848
915
  * Filters a property based on a label and value criteria
849
916
  *
@@ -871,4 +938,4 @@ declare function filterProperties(property: Property, filter: {
871
938
  }, options?: PropertyOptions): boolean;
872
939
 
873
940
  //#endregion
874
- export { Bibliography, Concept, Context, ContextItem, ContextNode, Coordinates, Data, DataCategory, Document, Event, Footnote, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyValue, PropertyValueContent, PropertyValueContentType, Resource, Set, SpatialUnit, Style, Tree, WebBlock, WebElement, WebElementComponent, WebImage, WebSectionSidebarItem, Webpage, WebpageProperties, Website, WebsiteProperties, fetchGallery, fetchItem, fetchWebsite, filterProperties, getPropertyByLabel, getPropertyValueByLabel, getPropertyValuesByLabel, getUniqueProperties };
941
+ export { Bibliography, Concept, Context, ContextItem, ContextNode, Coordinates, Data, DataCategory, Document, Event, Footnote, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyValue, PropertyValueContent, PropertyValueContentType, Resource, Set, SpatialUnit, Style, Tree, WebBlock, WebElement, WebElementComponent, WebImage, WebSectionSidebarItem, Webpage, WebpageProperties, Website, WebsiteProperties, fetchGallery, fetchItem, fetchWebsite, filterProperties, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import{z as e}from"zod/v4";const t=e.uuid({message:`Invalid UUID provided`}),n=e.object({type:e.enum([`traditional`,`digital-collection`,`plum`,`cedar`,`elm`,`maple`,`oak`,`palm`],{message:`Invalid website type`}),status:e.enum([`development`,`preview`,`production`],{message:`Invalid website status`}),privacy:e.enum([`public`,`password`,`private`],{message:`Invalid website privacy`})}),r=e.enum([`annotated-document`,`annotated-image`,`bibliography`,`button`,`collection`,`empty-space`,`entries`,`filter-categories`,`iframe`,`iiif-viewer`,`image`,`image-gallery`,`n-columns`,`n-rows`,`network-graph`,`search-bar`,`table`,`text`,`timeline`,`video`],{message:`Invalid component`}),i=e.enum([`resource`,`spatialUnit`,`concept`,`period`,`bibliography`,`person`,`propertyValue`,`set`,`tree`]),a=e.enum([`string`,`integer`,`decimal`,`boolean`,`date`,`dateTime`,`time`,`coordinate`,`IDREF`]),o=e.object({uuid:e.uuid({message:`Invalid UUID`}),filter:e.string().optional(),page:e.number().positive({message:`Page must be positive`}),perPage:e.number().positive({message:`Per page must be positive`})}).strict(),s=e.string().transform(e=>e.split(` `)).pipe(e.array(e.enum([`bold`,`italic`,`underline`]))),c=e.string().transform(e=>e.split(` `)).pipe(e.array(e.enum([`newline`,`trailing`,`leading`]))),l=e.email({message:`Invalid email`}),u={includeNestedProperties:!1};function d(e,t,n=u){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=d(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function f(e,t,n=u){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=f(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function p(e,t,n=u){let{includeNestedProperties:r}=n,i=f(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=p(n.properties,t,{includeNestedProperties:r});if(e!==null)return e}}return null}function m(e,t=u){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=m(t.properties,{includeNestedProperties:!0});for(let t of e){if(r.some(e=>e.uuid===t.uuid))continue;r.push(t)}}}return r}function h(e,t,n=u){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=>h(e,t,{includeNestedProperties:!0}))),n}return!1}function g(e,t){let n=e.find(e=>e.lang===t);return n??null}function _(e){let t=e.split(` `),n=[];for(let e of t){let t=e.replaceAll(/(?<=\s|^)[([{]+|[)\]}]+(?=\s|$)/g,``).replace(/[!),.:;?\]]$/,``),r=e.indexOf(t),i=e.slice(0,r),a=e.slice(r+t.length),o=l.safeParse(t).success;if(o){n.push(i,`${i}<ExternalLink href="mailto:${t}">${t}</ExternalLink>${a}`);continue}n.push(e)}return n.join(` `)}function v(e,t){let n=e,r=s.safeParse(t);if(!r.success)return console.warn(`Invalid render options string provided: “${t}”`),e;for(let e of r.data)switch(e){case`bold`:n=`**${n}**`;break;case`italic`:n=`*${n}*`;break;case`underline`:n=`_${n}_`;break}return n.replaceAll(`&#39;`,`'`)}function y(e,t){let n=e,r=c.safeParse(t);if(!r.success)return console.warn(`Invalid whitespace string provided: “${t}”`),e;for(let e of r.data)switch(e){case`newline`:n=`<br />\n${n}`;break;case`trailing`:n=`${n} `;break;case`leading`:n=` ${n}`;break}return n.replaceAll(`&#39;`,`'`)}function b(e){return String(e).replaceAll(`&#39;`,`'`)}function x(e){let t=``;switch(typeof e.string){case`string`:case`number`:case`boolean`:t=b(e.string);break;case`object`:{let n=Array.isArray(e.string)?e.string:[e.string];for(let e of n)if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)t+=b(e);else{let n=e.rend==null?b(e.content):v(b(e.content),e.rend),r=e.whitespace==null?n:y(n,e.whitespace);t+=r}break}default:t=``;break}return t}function S(e,t){if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return _(b(e));if(`whitespace`in e&&!(`content`in e)&&!(`string`in e))return e.whitespace===`newline`?`
2
- `:``;if(`links`in e){let n=``;n=typeof e.string==`object`?C(e.string):b(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=b(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)?b(t.identification.label):C(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+=S(e,t);return`whitespace`in e&&e.whitespace!=null&&(n=y(_(n),e.whitespace)),n.replaceAll(`&#39;`,`'`)}else n=b(e.content),e.rend!=null&&(n=v(_(n),e.rend)),e.whitespace!=null&&(n=y(_(n),e.whitespace));return n}function C(e,t=`eng`){switch(typeof e.content){case`string`:case`number`:case`boolean`:return b(e.content);case`object`:if(Array.isArray(e.content)){let n=g(e.content,t);if(n)return x(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 x(n)}}else return x(e.content);default:return String(e.content)}}function w(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 T(e){try{let n=t.parse(e),r=await 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 E(e,t,n){try{let[r,i]=await T(e);if(r!==null)throw Error(r);let a=w(Object.keys(i.ochre)),o;switch(a){case`resource`:if(!(`resource`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'resource' key`);o=q(i.ochre.resource);break;case`spatialUnit`:if(!(`spatialUnit`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'spatialUnit' key`);o=Y(i.ochre.spatialUnit);break;case`concept`:if(!(`concept`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'concept' key`);o=le(i.ochre.concept);break;case`period`:if(!(`period`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'period' key`);o=V(i.ochre.period);break;case`bibliography`:if(!(`bibliography`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'bibliography' key`);o=U(i.ochre.bibliography);break;case`person`:if(!(`person`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'person' key`);o=j(i.ochre.person);break;case`propertyValue`:if(!(`propertyValue`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'propertyValue' key`);o=G(i.ochre.propertyValue);break;case`set`:if(!(`set`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'set' key`);o=ce(i.ochre.set,n);break;case`tree`:if(!(`tree`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'tree' key`);o=se(i.ochre.tree);break;default:throw Error(`Invalid category`)}let s=te(i.ochre.metadata),c={uuid:i.ochre.uuidBelongsTo,abbreviation:b(i.ochre.belongsTo)};return{error:null,metadata:s,belongsTo:c,item:o,category:t}}catch(e){return{error:e instanceof Error?e.message:`Unknown error`,metadata:void 0,belongsTo:void 0,item:void 0,category:void 0}}}function D(e){try{let t={label:[`string`,`number`,`boolean`].includes(typeof e.label)?b(e.label):C(e.label),abbreviation:``};for(let n of Object.keys(e).filter(e=>e!==`label`))t[n]=C(e[n]);return t}catch(e){return console.error(e),{label:``,abbreviation:``}}}function ee(e){return e==null?[`eng`]:Array.isArray(e)?e.map(e=>C(e)):[C(e)]}function te(e){let t={label:``,abbreviation:``};if(e.item)if(e.item.label||e.item.abbreviation){let n=``,r=``;e.item.label&&(n=C(e.item.label)),e.item.abbreviation&&(r=C(e.item.abbreviation)),t={label:n,abbreviation:r}}else t=D(e.item.identification);let n=null,r=e.project?.identification?D(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:C(e.dataset),publisher:C(e.publisher),languages:ee(e.language),identifier:C(e.identifier),description:C(e.description)}}function O(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),number:e.n,content:b(e.content)}}function k(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(O(e))}return{tree:O(e.tree),project:O(e.project),spatialUnit:t}}),displayPath:e.displayPath};return n}function A(e){return typeof e.license==`string`?null:{content:e.license.content,url:e.license.target}}function j(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?k(e.context):null,date:e.date==null?null:new Date(e.date),identification:e.identification?D(e.identification):null,availability:e.availability?A(e.availability):null,address:e.address?{country:e.address.country??null,city:e.address.city??null,state:e.address.state??null}:null,coordinates:e.coordinates?L(e.coordinates):null,content:e.content==null?null:b(e.content),events:e.events?z(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function M(e){let t=[];for(let n of e)t.push(j(n));return t}function ne(e){let t=`resource`in e?e.resource:`spatialUnit`in e?e.spatialUnit:`concept`in e?e.concept:`set`in e?e.set:`tree`in e?e.tree:`person`in e?e.person:`bibliography`in e?e.bibliography:`epigraphicUnit`in e?e.epigraphicUnit:`propertyValue`in e?e.propertyValue:null;if(!t)throw Error(`Invalid link provided: ${JSON.stringify(e,null,2)}`);let n=Array.isArray(t)?t:[t],r=[];for(let t of n){let n={category:`resource`in e?`resource`:`spatialUnit`in e?`spatialUnit`:`concept`in e?`concept`:`set`in e?`set`:`person`in e?`person`:`tree`in e?`tree`:`bibliography`in e?`bibliography`:`epigraphicUnit`in e?`epigraphicUnit`:`propertyValue`in e?`propertyValue`:null,content:`content`in t?t.content==null?null:b(t.content):null,href:`href`in t&&t.href!=null?t.href:null,uuid:t.uuid,type:t.type??null,identification:t.identification?D(t.identification):null,image:null,bibliographies:`bibliography`in e?W(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 N(e){let t=[];for(let n of e)t.push(...ne(n));return t}function P(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+=_(b(i.string));else{let e=Array.isArray(i.string)?i.string:[i.string];for(let t of e)n+=S(t,r)}return{content:n,footnotes:r}}function F(e){return{publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),identification:e.identification?D(e.identification):null,url:e.href??(e.htmlImgSrcPrefix==null&&e.content!=null?b(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?b(e.content):null,widthPreview:e.widthPreview??null,heightPreview:e.heightPreview??null,width:e.width??null,height:e.height??null}}function I(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`?_(b(a.string)):_(P(a).content),n.push({number:r.noteNo,title:a.title==null?null:b(a.title),content:e})}return n}function L(e){if(typeof e==`string`){let[t,n]=e.split(`, `);return{latitude:Number(t),longitude:Number(n),type:null,label:null}}return e.coord==null?null:{latitude:e.coord.coordLatitude,longitude:e.coord.coordLongitude,type:e.coord.coordType,label:b(e.coord.coordLabel)}}function R(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`?b(e.observers).split(`;`).map(e=>e.trim()):M(Array.isArray(e.observers)?e.observers:[e.observers]),notes:e.notes?I(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?N(Array.isArray(e.links)?e.links:[e.links]):[],properties:e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function re(e){let t=[];for(let n of e)t.push(R(n));return t}function z(e){let t=[];for(let n of e)t.push({date:n.dateTime==null?null:new Date(n.dateTime),label:C(n.label),agent:n.agent?{uuid:n.agent.uuid,content:b(n.agent.content)}:null});return t}function ie(e,t=`eng`){let n=`value`in e&&e.value?Array.isArray(e.value)?e.value:[e.value]:[],r=n.map(e=>{let t=null,n=null;if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`){t=b(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(C({content:e.content})):null;break;case`coordinate`:t=null;break;case`boolean`:e.content!=null&&(n=C({content:e.content})),t=e.booleanValue??null;break;default:`slug`in e&&e.slug!=null?t=b(e.slug):e.content!=null&&(t=C({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:C(e.label,t).replace(/\s*\.{3}$/,``).trim(),values:r,comment:e.comment==null?null:b(e.comment),properties:e.property?B(Array.isArray(e.property)?e.property:[e.property]):[]}}function B(e,t=`eng`){let n=[];for(let r of e)n.push(ie(r,t));return n}function ae(e){let t=[];for(let n of e)t.push({date:new Date(n.date),number:n.interpretationNo,properties:n.properties?B(Array.isArray(n.properties.property)?n.properties.property:[n.properties.property]):[]});return t}function oe(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:b(e.title),shape:e.shape===`rect`?`rectangle`:`polygon`,coords:e.coords.split(`,`).map(e=>Number.parseInt(e))});return t}function V(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:D(e.identification),description:e.description?C(e.description):null}}function H(e){let t=[];for(let n of e)t.push(V(n));return t}function U(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:D(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?D(e.identification):null,projectIdentification:e.project?.identification?D(e.project.identification):null,context:e.context?k(e.context):null,citation:{format:e.citationFormat??null,short:e.citationFormatSpan?b(`default:span`in e.citationFormatSpan?e.citationFormatSpan[`default:span`].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?b(`default:div`in e.referenceFormatDiv?e.referenceFormatDiv[`default:div`][`default:div`].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?M(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:b(e.entryInfo.startIssue),startVolume:b(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?H(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],authors:e.authors?M(Array.isArray(e.authors.person)?e.authors.person:[e.authors.person]):[],properties:e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function W(e){let t=[];for(let n of e)t.push(U(n));return t}function G(e){return{uuid:e.uuid,category:`propertyValue`,number:e.n,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,context:e.context?k(e.context):null,availability:e.availability?A(e.availability):null,identification:D(e.identification),date:e.date?new Date(e.date):null,creators:e.creators?M(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?b(e.description):C(e.description):``,notes:e.notes?I(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?N(Array.isArray(e.links)?e.links:[e.links]):[]}}function K(e){let t=[];for(let n of e)t.push(G(n));return t}function se(e){let t=[];e.creators&&(t=M(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=J(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource])),typeof e.items!=`string`&&`spatialUnit`in e.items&&(i=X(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit])),typeof e.items!=`string`&&`concept`in e.items&&(a=ue(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept])),typeof e.items!=`string`&&`period`in e.items&&(o=H(Array.isArray(e.items.period)?e.items.period:[e.items.period])),typeof e.items!=`string`&&`bibliography`in e.items&&(s=W(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography])),typeof e.items!=`string`&&`person`in e.items&&(c=M(Array.isArray(e.items.person)?e.items.person:[e.items.person])),typeof e.items!=`string`&&`propertyValue`in e.items&&(l=K(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]));let u={uuid:e.uuid,category:`tree`,publicationDateTime:new Date(e.publicationDateTime),identification:D(e.identification),creators:t,license:A(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?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return u}function ce(e,t){if(typeof e.items==`string`)throw TypeError(`Invalid OCHRE data: Set has no items`);let n=t??w(Object.keys(e.items)),r=[];switch(n){case`resource`:if(!(`resource`in e.items))throw Error(`Invalid OCHRE data: Set has no resources`);r=J(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=X(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit]);break;case`concept`:if(!(`concept`in e.items))throw Error(`Invalid OCHRE data: Set has no concepts`);r=ue(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept]);break;case`period`:if(!(`period`in e.items))throw Error(`Invalid OCHRE data: Set has no periods`);r=H(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=W(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=M(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=K(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:A(e.availability),identification:D(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?b(e.description):C(e.description):``,creators:e.creators?M(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],type:e.type,number:e.n,items:r}}function q(e){let t={uuid:e.uuid,category:`resource`,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,type:e.type,number:e.n,format:e.format??null,context:`context`in e&&e.context?k(e.context):null,license:`availability`in e&&e.availability?A(e.availability):null,copyright:`copyright`in e&&e.copyright!=null?b(e.copyright):null,identification:D(e.identification),date:e.date==null?null:new Date(e.date),image:e.image?F(e.image):null,creators:e.creators?M(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],notes:e.notes?I(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?b(e.description):C(e.description):``,document:e.document&&`content`in e.document?P(e.document.content):null,href:e.href??null,imageMap:e.imagemap?oe(e.imagemap):null,periods:e.periods?H(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],links:e.links?N(Array.isArray(e.links)?e.links:[e.links]):[],reverseLinks:e.reverseLinks?N(Array.isArray(e.reverseLinks)?e.reverseLinks:[e.reverseLinks]):[],properties:e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],citedBibliographies:e.citedBibliography?W(Array.isArray(e.citedBibliography.reference)?e.citedBibliography.reference:[e.citedBibliography.reference]):[],resources:e.resource?J(Array.isArray(e.resource)?e.resource:[e.resource]):[]};return t}function J(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(q(e));return t}function Y(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?k(e.context):null,license:`availability`in e&&e.availability?A(e.availability):null,identification:D(e.identification),image:e.image?F(e.image):null,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?b(e.description):C(e.description):``,coordinates:e.coordinates?L(e.coordinates):e.coordinate?L(e.coordinate):null,observations:`observations`in e&&e.observations?re(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[R(e.observation)]:[],events:`events`in e&&e.events?z(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:`properties`in e&&e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return t}function X(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(Y(e));return t}function le(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?A(e.availability):null,context:`context`in e&&e.context?k(e.context):null,identification:D(e.identification),interpretations:ae(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?B(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 fe(r);e&&n.push(e);break}case`block`:{let e=await $(r);e&&n.push(e);break}}}return n};function ue(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(le(e));return t}async function de(e,t){let n=r.parse(e.values[0].content),i={component:n},a=t.links?N(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?P(t.document.content):null;if(s===null){let e=a.find(e=>e.type===`internalDocument`);if(e){let{item:t,error:n}=await E(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=p(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=p(e.properties,`layout`);r??=`long`,i.bibliographies=t.bibliographies,i.layout=r;break}case`button`:{let r=p(e.properties,`variant`);r??=`default`;let a=!1,o=p(e.properties,`navigate-to`);if(o===null){if(o=p(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=p(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)?b(t.identification.label):C(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=p(e.properties,`variant`);r??=`full`;let o=p(e.properties,`item-variant`);o??=`default`;let s=!1,c=p(e.properties,`show-count`);c!==null&&(s=c===!0);let l=!1,u=p(e.properties,`is-searchable`);u!==null&&(l=u===!0);let d=p(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=p(e.properties,`height`),n=p(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=p(e.properties,`variant`);r??=`entry`;let o=!1,s=p(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=p(e.properties,`height`),o=p(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=p(e.properties,`variant`);r??=`default`;let a=p(e.properties,`layout-caption`);a??=`bottom`;let s=null,c=p(e.properties,`width`);c!==null&&(typeof c==`number`?s=c:typeof c==`string`&&(s=Number.parseFloat(c)));let l=null,u=p(e.properties,`height`);u!==null&&(typeof u==`number`?l=u:typeof u==`string`&&(l=Number.parseFloat(u)));let f=!0,m=p(e.properties,`is-full-width`);m!==null&&(f=m===!0);let h=!0,g=p(e.properties,`is-full-height`);g!==null&&(h=g===!0);let _=p(e.properties,`image-quality`);_??=`high`;let v=p(e.properties,`caption-source`);v??=`name`;let y=p(e.properties,`alt-text-source`);y??=`name`;let b=!1,x=p(e.properties,`is-transparent`);x!==null&&(b=x===!0);let S=!1,C=p(e.properties,`is-cover`);C!==null&&(S=C===!0);let w=null;if(t.length>1){let t=d(e.properties,`variant`),n=5;if(t&&t.values[0].content===`carousel`){let e=p(t.properties,`seconds-per-image`);e!==null&&(typeof e==`number`?n=e:typeof e==`string`&&(n=Number.parseFloat(e)))}w={secondsPerImage:n}}i.images=t,i.variant=r,i.width=s,i.height=l,i.isFullWidth=f,i.isFullHeight=h,i.imageQuality=_,i.captionLayout=a,i.captionSource=v,i.altTextSource=y,i.isTransparentBackground=b,i.isCover=S,i.carouselOptions=w;break}case`image-gallery`:{let t=a.find(e=>e.category===`tree`||e.category===`set`);if(!t)throw Error(`Image gallery link not found for the following component: “${n}”`);let r=p(e.properties,`is-searchable`)===!0;i.galleryId=t.uuid,i.isSearchable=r;break}case`n-columns`:{let e=t.resource?await Z(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];i.columns=e;break}case`n-rows`:{let e=t.resource?await Z(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=p(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=p(e.properties,`variant`);t??=`block`;let r=p(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=p(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: “${C(t.identification.label)}”`);break}return i}async function Q(e){let t=D(e.identification),n=e.properties?.property?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],r=n.find(e=>e.label===`presentation`);if(!r)throw Error(`Presentation property not found for element “${t.label}”`);let i=r.properties.find(e=>e.label===`component`);if(!i)throw Error(`Component for element “${t.label}” not found`);let a=await de(i,e),o=r.properties.find(e=>e.label===`section-sidebar-displayed`),s=o?.values[0]?.content===!0,c=e.properties?.property?B(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 m=c.find(e=>e.label===`presentation`&&e.values[0].content===`title`)?.properties,h=`default`,g=!1,_=!1,v=!1,y=!1;if(m){let e=p(m,`variant`);e&&(h=e);let t=m.filter(e=>e.label===`display`);t.length>0&&(g=t.some(e=>e.values[0].content===`name`),_=t.some(e=>e.values[0].content===`description`),v=t.some(e=>e.values[0].content===`date`),y=t.some(e=>e.values[0].content===`creators`))}return{uuid:e.uuid,type:`element`,title:{label:t.label,variant:h,properties:{isNameDisplayed:g,isDescriptionDisplayed:_,isDateDisplayed:v,isCreatorsDisplayed:y}},isDisplayedInBlockSectionSidebar:s,cssStyles:u,cssStylesMobile:f,...a}}async function fe(e){let t=e.properties?B(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=D(e.identification),r=e.slug;if(r===void 0)throw Error(`Slug not found for page “${n.label}”`);let i=e.links?N(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?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=p(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,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 h=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css`)?.properties,g=[];if(h)for(let e of h)g.push({label:e.label,value:e.values[0].content});let _=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css-mobile`)?.properties,v=[];if(_)for(let e of _)v.push({label:e.label,value:e.values[0].content});return{title:n.label,slug:r,items:s,properties:{displayedInHeader:l,width:u,variant:d,backgroundImageUrl:a?`https://ochre.lib.uchicago.edu/ochre?uuid=${a.uuid}&load`:null,isSidebarDisplayed:f,cssStyles:g,cssStylesMobile:v},webpages:c}}async function pe(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n){let n=await fe(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?B(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?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=p(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=me(t),t}function me(e){let t=[];for(let n of e.items)switch(n.type){case`block`:{let e=me(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 he(e){let t=B(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;if(i==null)throw Error(`Website type not found`);let a=r.find(e=>e.label===`status`)?.values[0]?.content;if(a==null)throw Error(`Website status not found`);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 ge(e,t,n){if(!e.properties)throw Error(`Website properties not found`);let r=he(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]);if(typeof e.items==`string`||!(`resource`in e.items))throw Error(`Website pages not found`);let i=Array.isArray(e.items.resource)?e.items.resource:[e.items.resource],a=await pe(i),o=null,s=[],c={label:``,variant:`default`,properties:{isNameDisplayed:!1,isDescriptionDisplayed:!1,isDateDisplayed:!1,isCreatorsDisplayed:!1}},l=`start`,u=`default`,d=[],f=[],m=i.find(e=>{let t=e.properties?B(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(m){c.label=typeof m.identification.label==`string`||typeof m.identification.label==`number`||typeof m.identification.label==`boolean`?b(m.identification.label):C(m.identification.label);let e=m.properties?B(Array.isArray(m.properties.property)?m.properties.property:[m.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=p(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=m.resource?Array.isArray(m.resource)?m.resource:[m.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.collectionOptions){let t=[];for(let e of a)for(let n of e.items)n.type===`element`&&n.component===`collection`&&t.push(n.collectionId);h={uuids:t,properties:{metadataUuids:e.collectionOptions.metadataUuids.uuid?(Array.isArray(e.collectionOptions.metadataUuids.uuid)?e.collectionOptions.metadataUuids.uuid:[e.collectionOptions.metadataUuids.uuid]).map(e=>e.content):[],searchUuids:e.collectionOptions.searchUuids.uuid?(Array.isArray(e.collectionOptions.searchUuids.uuid)?e.collectionOptions.searchUuids.uuid:[e.collectionOptions.searchUuids.uuid]).map(e=>e.content):[],labelUuids:e.collectionOptions.labelUuids.uuid?(Array.isArray(e.collectionOptions.labelUuids.uuid)?e.collectionOptions.labelUuids.uuid:[e.collectionOptions.labelUuids.uuid]).map(e=>e.content):[]}}}return{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:D(e.identification),project:{name:b(t),website:n===null?null:b(n)},creators:e.creators?M(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:A(e.availability),pages:a,sidebar:o,properties:r,collectionOptions:h}}async function _e(e,t,n,r){try{let{uuid:i,filter:a,page:s,perPage:c}=o.parse({uuid:e,filter:t,page:n,perPage:r}),l=await fetch(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
1
+ import{z as e}from"zod/v4";const t=e.uuid({message:`Invalid UUID provided`}),n=e.object({type:e.enum([`traditional`,`digital-collection`,`plum`,`cedar`,`elm`,`maple`,`oak`,`palm`],{message:`Invalid website type`}),status:e.enum([`development`,`preview`,`production`],{message:`Invalid website status`}),privacy:e.enum([`public`,`password`,`private`],{message:`Invalid website privacy`})}),r=e.enum([`annotated-document`,`annotated-image`,`bibliography`,`button`,`collection`,`empty-space`,`entries`,`filter-categories`,`iframe`,`iiif-viewer`,`image`,`image-gallery`,`n-columns`,`n-rows`,`network-graph`,`search-bar`,`table`,`text`,`timeline`,`video`],{message:`Invalid component`}),i=e.enum([`resource`,`spatialUnit`,`concept`,`period`,`bibliography`,`person`,`propertyValue`,`set`,`tree`]),a=e.enum([`string`,`integer`,`decimal`,`boolean`,`date`,`dateTime`,`time`,`coordinate`,`IDREF`]),o=e.object({uuid:e.uuid({message:`Invalid UUID`}),filter:e.string().optional(),page:e.number().positive({message:`Page must be positive`}),perPage:e.number().positive({message:`Per page must be positive`})}).strict(),s=e.string().transform(e=>e.split(` `)).pipe(e.array(e.enum([`bold`,`italic`,`underline`]))),c=e.string().transform(e=>e.split(` `)).pipe(e.array(e.enum([`newline`,`trailing`,`leading`]))),l=e.email({message:`Invalid email`}),u={includeNestedProperties:!1};function d(e,t,n=u){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=d(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function f(e,t,n=u){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=f(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function p(e,t,n=u){let{includeNestedProperties:r}=n,i=f(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=p(n.properties,t,{includeNestedProperties:r});if(e!==null)return e}}return null}function m(e,t,n=u){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=m(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function h(e,t,n=u){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=h(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}function g(e,t,n=u){let{includeNestedProperties:r}=n,i=h(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=g(n.properties,t,{includeNestedProperties:r});if(e!==null)return e}}return null}function _(e,t=u){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=_(t.properties,{includeNestedProperties:!0});for(let t of e){if(r.some(e=>e.uuid===t.uuid))continue;r.push(t)}}}return r}function v(e,t=u){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=v(t.properties,{includeNestedProperties:!0});for(let t of e){if(r.includes(t))continue;r.push(t)}}}return r}function y(e,t,n=u){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=>y(e,t,{includeNestedProperties:!0}))),n}return!1}function b(e,t){let n=e.find(e=>e.lang===t);return n??null}function x(e){let t=e.split(` `),n=[];for(let e of t){let t=e.replaceAll(/(?<=\s|^)[([{]+|[)\]}]+(?=\s|$)/g,``).replace(/[!),.:;?\]]$/,``),r=e.indexOf(t),i=e.slice(0,r),a=e.slice(r+t.length),o=l.safeParse(t).success;if(o){n.push(i,`${i}<ExternalLink href="mailto:${t}">${t}</ExternalLink>${a}`);continue}n.push(e)}return n.join(` `)}function S(e,t){let n=e,r=s.safeParse(t);if(!r.success)return console.warn(`Invalid render options string provided: “${t}”`),e;for(let e of r.data)switch(e){case`bold`:n=`**${n}**`;break;case`italic`:n=`*${n}*`;break;case`underline`:n=`_${n}_`;break}return n.replaceAll(`&#39;`,`'`)}function C(e,t){let n=e,r=c.safeParse(t);if(!r.success)return console.warn(`Invalid whitespace string provided: “${t}”`),e;for(let e of r.data)switch(e){case`newline`:n=`<br />\n${n}`;break;case`trailing`:n=`${n} `;break;case`leading`:n=` ${n}`;break}return n.replaceAll(`&#39;`,`'`)}function w(e){return String(e).replaceAll(`&#39;`,`'`)}function T(e){let t=``;switch(typeof e.string){case`string`:case`number`:case`boolean`:t=w(e.string);break;case`object`:{let n=Array.isArray(e.string)?e.string:[e.string];for(let e of n)if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)t+=w(e);else{let n=e.rend==null?w(e.content):S(w(e.content),e.rend),r=e.whitespace==null?n:C(n,e.whitespace);t+=r}break}default:t=``;break}return t}function E(e,t){if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return x(w(e));if(`whitespace`in e&&!(`content`in e)&&!(`string`in e))return e.whitespace===`newline`?`
2
+ `:``;if(`links`in e){let n=``;n=typeof e.string==`object`?D(e.string):w(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=w(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)?w(t.identification.label):D(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+=E(e,t);return`whitespace`in e&&e.whitespace!=null&&(n=C(x(n),e.whitespace)),n.replaceAll(`&#39;`,`'`)}else n=w(e.content),e.rend!=null&&(n=S(x(n),e.rend)),e.whitespace!=null&&(n=C(x(n),e.whitespace));return n}function D(e,t=`eng`){switch(typeof e.content){case`string`:case`number`:case`boolean`:return w(e.content);case`object`:if(Array.isArray(e.content)){let n=b(e.content,t);if(n)return T(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 T(n)}}else return T(e.content);default:return String(e.content)}}function O(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 ee(e){try{let n=t.parse(e),r=await 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 k(e,t,n){try{let[r,i]=await ee(e);if(r!==null)throw Error(r);let a=O(Object.keys(i.ochre)),o;switch(a){case`resource`:if(!(`resource`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'resource' key`);o=J(i.ochre.resource);break;case`spatialUnit`:if(!(`spatialUnit`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'spatialUnit' key`);o=X(i.ochre.spatialUnit);break;case`concept`:if(!(`concept`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'concept' key`);o=pe(i.ochre.concept);break;case`period`:if(!(`period`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'period' key`);o=H(i.ochre.period);break;case`bibliography`:if(!(`bibliography`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'bibliography' key`);o=W(i.ochre.bibliography);break;case`person`:if(!(`person`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'person' key`);o=P(i.ochre.person);break;case`propertyValue`:if(!(`propertyValue`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'propertyValue' key`);o=K(i.ochre.propertyValue);break;case`set`:if(!(`set`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'set' key`);o=de(i.ochre.set,n);break;case`tree`:if(!(`tree`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'tree' key`);o=ue(i.ochre.tree);break;default:throw Error(`Invalid category`)}let s=ne(i.ochre.metadata),c={uuid:i.ochre.uuidBelongsTo,abbreviation:w(i.ochre.belongsTo)};return{error:null,metadata:s,belongsTo:c,item:o,category:t}}catch(e){return{error:e instanceof Error?e.message:`Unknown error`,metadata:void 0,belongsTo:void 0,item:void 0,category:void 0}}}function A(e){try{let t={label:[`string`,`number`,`boolean`].includes(typeof e.label)?w(e.label):D(e.label),abbreviation:``};for(let n of Object.keys(e).filter(e=>e!==`label`))t[n]=D(e[n]);return t}catch(e){return console.error(e),{label:``,abbreviation:``}}}function te(e){return e==null?[`eng`]:Array.isArray(e)?e.map(e=>D(e)):[D(e)]}function ne(e){let t={label:``,abbreviation:``};if(e.item)if(e.item.label||e.item.abbreviation){let n=``,r=``;e.item.label&&(n=D(e.item.label)),e.item.abbreviation&&(r=D(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:D(e.dataset),publisher:D(e.publisher),languages:te(e.language),identifier:D(e.identifier),description:D(e.description)}}function j(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),number:e.n,content:w(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,coordinates:e.coordinates?z(e.coordinates):null,content:e.content==null?null:w(e.content),events:e.events?B(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:e.properties?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function F(e){let t=[];for(let n of e)t.push(P(n));return t}function re(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:w(t.content):null,href:`href`in t&&t.href!=null?t.href:null,uuid:t.uuid,type:t.type??null,identification:t.identification?A(t.identification):null,image:null,bibliographies:`bibliography`in e?G(Array.isArray(e.bibliography)?e.bibliography:[e.bibliography]):null,publicationDateTime:t.publicationDateTime==null?null:new Date(t.publicationDateTime)};`height`in t&&t.height!=null&&t.width!=null&&t.heightPreview!=null&&t.widthPreview!=null&&(n.image={isInline:t.rend===`inline`,isPrimary:t.isPrimary??!1,heightPreview:t.heightPreview,widthPreview:t.widthPreview,height:t.height,width:t.width}),r.push(n)}return r}function I(e){let t=[];for(let n of e)t.push(...re(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+=x(w(i.string));else{let e=Array.isArray(i.string)?i.string:[i.string];for(let t of e)n+=E(t,r)}return{content:n,footnotes:r}}function ie(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?w(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?w(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`?x(w(a.string)):x(L(a).content),n.push({number:r.noteNo,title:a.title==null?null:w(a.title),content:e})}return n}function z(e){if(typeof e==`string`){let[t,n]=e.split(`, `);return{latitude:Number(t),longitude:Number(n),type:null,label:null}}return e.coord==null?null:{latitude:e.coord.coordLatitude,longitude:e.coord.coordLongitude,type:e.coord.coordType,label:w(e.coord.coordLabel)}}function ae(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`?w(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?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function oe(e){let t=[];for(let n of e)t.push(ae(n));return t}function B(e){let t=[];for(let n of e)t.push({date:n.dateTime==null?null:new Date(n.dateTime),label:D(n.label),agent:n.agent?{uuid:n.agent.uuid,content:w(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=w(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(D({content:e.content})):null;break;case`coordinate`:t=null;break;case`boolean`:e.content!=null&&(n=D({content:e.content})),t=e.booleanValue??null;break;default:`slug`in e&&e.slug!=null?t=w(e.slug):e.content!=null&&(t=D({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:D(e.label,t).replace(/\s*\.{3}$/,``).trim(),values:r,comment:e.comment==null?null:w(e.comment),properties:e.property?V(Array.isArray(e.property)?e.property:[e.property]):[]}}function V(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?V(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:w(e.title),shape:e.shape===`rect`?`rectangle`:`polygon`,coords:e.coords.split(`,`).map(e=>Number.parseInt(e))});return t}function H(e){return{uuid:e.uuid,category:`period`,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),type:e.type??null,number:e.n??null,identification:A(e.identification),description:e.description?D(e.description):null}}function U(e){let t=[];for(let n of e)t.push(H(n));return t}function W(e){let t=null;return e.source?.resource&&(t={uuid:e.source.resource.uuid,publicationDateTime:e.source.resource.publicationDateTime?new Date(e.source.resource.publicationDateTime):null,type:e.source.resource.type,identification: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?w(`default:span`in e.citationFormatSpan?e.citationFormatSpan[`default:span`].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?w(`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:w(e.entryInfo.startIssue),startVolume:w(e.entryInfo.startVolume)}:null,source:{resource:t,documentUrl:e.sourceDocument?`https://ochre.lib.uchicago.edu/ochre?uuid=${e.sourceDocument.uuid}&load`:null},periods:e.periods?U(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],authors:e.authors?F(Array.isArray(e.authors.person)?e.authors.person:[e.authors.person]):[],properties:e.properties?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function G(e){let t=[];for(let n of e)t.push(W(n));return t}function K(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?[`string`,`number`,`boolean`].includes(typeof e.description)?w(e.description):D(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 q(e){let t=[];for(let n of e)t.push(K(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=fe(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit])),typeof e.items!=`string`&&`concept`in e.items&&(a=me(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept])),typeof e.items!=`string`&&`period`in e.items&&(o=U(Array.isArray(e.items.period)?e.items.period:[e.items.period])),typeof e.items!=`string`&&`bibliography`in e.items&&(s=G(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography])),typeof e.items!=`string`&&`person`in e.items&&(c=F(Array.isArray(e.items.person)?e.items.person:[e.items.person])),typeof e.items!=`string`&&`propertyValue`in e.items&&(l=q(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]));let u={uuid:e.uuid,category:`tree`,publicationDateTime:new Date(e.publicationDateTime),identification: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?V(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??O(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=fe(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=me(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept]);break;case`period`:if(!(`period`in e.items))throw Error(`Invalid OCHRE data: Set has no periods`);r=U(Array.isArray(e.items.period)?e.items.period:[e.items.period]);break;case`bibliography`:if(!(`bibliography`in e.items))throw Error(`Invalid OCHRE data: Set has no bibliographies`);r=G(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography]);break;case`person`:if(!(`person`in e.items))throw Error(`Invalid OCHRE data: Set has no persons`);r=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=q(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]);break;default:throw Error(`Invalid OCHRE data: Set has no items or is malformed`)}return{uuid:e.uuid,category:`set`,itemCategory:t,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,date:e.date==null?null:new Date(e.date),license:N(e.availability),identification:A(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?w(e.description):D(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 J(e){let t={uuid:e.uuid,category:`resource`,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,type:e.type,number:e.n,format:e.format??null,context:`context`in e&&e.context?M(e.context):null,license:`availability`in e&&e.availability?N(e.availability):null,copyright:`copyright`in e&&e.copyright!=null?w(e.copyright):null,identification:A(e.identification),date:e.date==null?null:new Date(e.date),image:e.image?ie(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)?w(e.description):D(e.description):``,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?U(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?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],citedBibliographies:e.citedBibliography?G(Array.isArray(e.citedBibliography.reference)?e.citedBibliography.reference:[e.citedBibliography.reference]):[],resources:e.resource?Y(Array.isArray(e.resource)?e.resource:[e.resource]):[]};return t}function Y(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(J(e));return t}function X(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?ie(e.image):null,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?w(e.description):D(e.description):``,coordinates:e.coordinates?z(e.coordinates):e.coordinate?z(e.coordinate):null,observations:`observations`in e&&e.observations?oe(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[ae(e.observation)]:[],events:`events`in e&&e.events?B(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:`properties`in e&&e.properties?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return t}function fe(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(X(e));return t}function pe(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 Z=async(e,t)=>{let n=[];for(let r of e){let e=r.properties?V(Array.isArray(r.properties.property)?r.properties.property:[r.properties.property]):[],i=e.find(e=>e.label===`presentation`&&e.values[0].content===t);if(!i)continue;switch(t){case`element`:{let e=await Q(r);n.push(e);break}case`page`:{let e=await ge(r);e&&n.push(e);break}case`block`:{let e=await $(r);e&&n.push(e);break}}}return n};function me(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(pe(e));return t}async function he(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=g(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=g(e.properties,`layout`);r??=`long`,i.bibliographies=t.bibliographies,i.layout=r;break}case`button`:{let r=g(e.properties,`variant`);r??=`default`;let a=!1,o=g(e.properties,`navigate-to`);if(o===null){if(o=g(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=g(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)?w(t.identification.label):D(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=g(e.properties,`variant`);r??=`full`;let o=g(e.properties,`item-variant`);o??=`default`;let s=!1,c=g(e.properties,`show-count`);c!==null&&(s=c===!0);let l=!1,u=g(e.properties,`is-searchable`);u!==null&&(l=u===!0);let d=g(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=g(e.properties,`height`),n=g(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=g(e.properties,`variant`);r??=`entry`;let o=!1,s=g(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=g(e.properties,`height`),o=g(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=g(e.properties,`variant`);r??=`default`;let a=g(e.properties,`layout-caption`);a??=`bottom`;let s=null,c=g(e.properties,`width`);c!==null&&(typeof c==`number`?s=c:typeof c==`string`&&(s=Number.parseFloat(c)));let l=null,u=g(e.properties,`height`);u!==null&&(typeof u==`number`?l=u:typeof u==`string`&&(l=Number.parseFloat(u)));let d=!0,f=g(e.properties,`is-full-width`);f!==null&&(d=f===!0);let p=!0,h=g(e.properties,`is-full-height`);h!==null&&(p=h===!0);let _=g(e.properties,`image-quality`);_??=`high`;let v=g(e.properties,`caption-source`);v??=`name`;let y=g(e.properties,`alt-text-source`);y??=`name`;let b=!1,x=g(e.properties,`is-transparent`);x!==null&&(b=x===!0);let S=!1,C=g(e.properties,`is-cover`);C!==null&&(S=C===!0);let w=null;if(t.length>1){let t=m(e.properties,`variant`),n=5;if(t&&t.values[0].content===`carousel`){let e=g(t.properties,`seconds-per-image`);e!==null&&(typeof e==`number`?n=e:typeof e==`string`&&(n=Number.parseFloat(e)))}w={secondsPerImage:n}}i.images=t,i.variant=r,i.width=s,i.height=l,i.isFullWidth=d,i.isFullHeight=p,i.imageQuality=_,i.captionLayout=a,i.captionSource=v,i.altTextSource=y,i.isTransparentBackground=b,i.isCover=S,i.carouselOptions=w;break}case`image-gallery`:{let t=a.find(e=>e.category===`tree`||e.category===`set`);if(!t)throw Error(`Image gallery link not found for the following component: “${n}”`);let r=g(e.properties,`is-searchable`)===!0;i.galleryId=t.uuid,i.isSearchable=r;break}case`n-columns`:{let e=t.resource?await Z(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];i.columns=e;break}case`n-rows`:{let e=t.resource?await Z(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=g(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=g(e.properties,`variant`);t??=`block`;let r=g(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=g(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: “${D(t.identification.label)}”`);break}return i}async function Q(e){let t=A(e.identification),n=e.properties?.property?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],r=n.find(e=>e.label===`presentation`);if(!r)throw Error(`Presentation property not found for element “${t.label}”`);let i=r.properties.find(e=>e.label===`component`);if(!i)throw Error(`Component for element “${t.label}” not found`);let a=await he(i,e),o=r.properties.find(e=>e.label===`section-sidebar-displayed`),s=o?.values[0]?.content===!0,c=e.properties?.property?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],l=c.find(e=>e.label===`presentation`&&e.values[0].content===`css`)?.properties??[],u=[];for(let e of l){let t=e.values[0].content;u.push({label:e.label,value:t})}let d=c.find(e=>e.label===`presentation`&&e.values[0].content===`css-mobile`)?.properties??[],f=[];for(let e of d){let t=e.values[0].content;f.push({label:e.label,value:t})}let p=c.find(e=>e.label===`presentation`&&e.values[0].content===`title`)?.properties,m=`default`,h=!1,_=!1,v=!1,y=!1;if(p){let e=g(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`),_=t.some(e=>e.values[0].content===`description`),v=t.some(e=>e.values[0].content===`date`),y=t.some(e=>e.values[0].content===`creators`))}return{uuid:e.uuid,type:`element`,title:{label:t.label,variant:m,properties:{isNameDisplayed:h,isDescriptionDisplayed:_,isDateDisplayed:v,isCreatorsDisplayed:y}},isDisplayedInBlockSectionSidebar:s,cssStyles:u,cssStylesMobile:f,...a}}async function ge(e){let t=e.properties?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];if(t.length===0||t.find(e=>e.label===`presentation`)?.values[0]?.content!==`page`)return null;let n=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?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=g(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 _=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css-mobile`)?.properties,v=[];if(_)for(let e of _)v.push({label:e.label,value:e.values[0].content});return{title:n.label,slug:r,items:s,properties:{displayedInHeader:l,width:u,variant:d,backgroundImageUrl:a?`https://ochre.lib.uchicago.edu/ochre?uuid=${a.uuid}&load`:null,isSidebarDisplayed:f,cssStyles:h,cssStylesMobile:v},webpages:c}}async function _e(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n){let n=await ge(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?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],r=n.find(e=>e.label===`presentation`&&e.values[0]?.content===`block`)?.properties;if(r){let e=r.find(e=>e.label===`layout`)?.values[0];e&&(t.layout=e.content);let n=r.find(e=>e.label===`spacing`)?.values[0];n&&(t.properties.spacing=n.content);let i=r.find(e=>e.label===`gap`)?.values[0];i&&(t.properties.gap=i.content);let a=r.find(e=>e.label===`align-items`)?.values[0];a&&(t.properties.alignItems=a.content);let o=r.find(e=>e.label===`justify-content`)?.values[0];o&&(t.properties.justifyContent=o.content);let s=r.find(e=>e.label===`overwrite-mobile`);if(s){let e=s.properties,n={};for(let t of e)n[t.label]=t.values[0].content;t.propertiesMobile=n}}let i=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],a=[];for(let e of i){let t=e.properties?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=g(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=ve(t),t}function ve(e){let t=[];for(let n of e.items)switch(n.type){case`block`:{let e=ve(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 ye(e){let t=V(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;if(i==null)throw Error(`Website type not found`);let a=r.find(e=>e.label===`status`)?.values[0]?.content;if(a==null)throw Error(`Website status not found`);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 be(e,t,n){if(!e.properties)throw Error(`Website properties not found`);let r=ye(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 _e(i),o=null,s=[],c={label:``,variant:`default`,properties:{isNameDisplayed:!1,isDescriptionDisplayed:!1,isDateDisplayed:!1,isCreatorsDisplayed:!1}},l=`start`,u=`default`,d=[],f=[],p=i.find(e=>{let t=e.properties?V(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];return t.some(e=>e.label===`presentation`&&e.values[0]?.content===`element`&&e.properties[0]?.label===`component`&&e.properties[0].values[0]?.content===`sidebar`)});if(p){c.label=typeof p.identification.label==`string`||typeof p.identification.label==`number`||typeof p.identification.label==`boolean`?w(p.identification.label):D(p.identification.label);let e=p.properties?V(Array.isArray(p.properties.property)?p.properties.property:[p.properties.property]):[],t=e.find(e=>e.label===`presentation`&&e.values[0]?.content===`element`)?.properties.find(e=>e.label===`component`&&e.values[0]?.content===`sidebar`)?.properties??[],n=t.find(e=>e.label===`layout`);n&&(l=n.values[0].content);let r=t.find(e=>e.label===`layout-mobile`);r&&(u=r.values[0].content);let i=e.find(e=>e.label===`presentation`&&e.values[0].content===`css`)?.properties??[];for(let e of i){let t=e.values[0].content;d.push({label:e.label,value:t})}let a=e.find(e=>e.label===`presentation`&&e.values[0].content===`css-mobile`)?.properties??[];for(let e of a){let t=e.values[0].content;f.push({label:e.label,value:t})}let o=e.find(e=>e.label===`presentation`&&e.values[0].content===`title`)?.properties;if(o){let e=g(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.collectionOptions){let t=[];for(let e of a)for(let n of e.items)n.type===`element`&&n.component===`collection`&&t.push(n.collectionId);m={uuids:t,properties:{metadataUuids:e.collectionOptions.metadataUuids.uuid?(Array.isArray(e.collectionOptions.metadataUuids.uuid)?e.collectionOptions.metadataUuids.uuid:[e.collectionOptions.metadataUuids.uuid]).map(e=>e.content):[],searchUuids:e.collectionOptions.searchUuids.uuid?(Array.isArray(e.collectionOptions.searchUuids.uuid)?e.collectionOptions.searchUuids.uuid:[e.collectionOptions.searchUuids.uuid]).map(e=>e.content):[],labelUuids:e.collectionOptions.labelUuids.uuid?(Array.isArray(e.collectionOptions.labelUuids.uuid)?e.collectionOptions.labelUuids.uuid:[e.collectionOptions.labelUuids.uuid]).map(e=>e.content):[]}}}return{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:A(e.identification),project:{name:w(t),website:n===null?null:w(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,collectionOptions:m}}async function xe(e,t,n,r){try{let{uuid:i,filter:a,page:s,perPage:c}=o.parse({uuid:e,filter:t,page:n,perPage:r}),l=await fetch(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
3
3
  for $q in input()/ochre[@uuid='${i}']
4
4
  let $filtered := $q//items/resource[contains(lower-case(identification/label), lower-case('${a}'))]
5
5
  let $maxLength := count($filtered)
@@ -8,4 +8,4 @@ import{z as e}from"zod/v4";const t=e.uuid({message:`Invalid UUID provided`}),n=e
8
8
  {$q/metadata/item}
9
9
  {$filtered[position() >= ${((s-1)*c+1).toString()} and position() < ${(s*c+1).toString()}]}
10
10
  </gallery>
11
- `)}&format=json`);if(!l.ok)throw Error(`Error fetching gallery items, please try again later.`);let u=await l.json();if(!(`gallery`in u.result))throw Error(`Failed to fetch gallery`);let d=D(u.result.gallery.item.identification),f=D(u.result.gallery.project.identification),p={identification:d,projectIdentification:f,resources:J(u.result.gallery.resource?Array.isArray(u.result.gallery.resource)?u.result.gallery.resource:[u.result.gallery.resource]:[]),maxLength:u.result.gallery.maxLength};return{item:p,error:null}}catch(e){return console.error(e),{item:null,error:e instanceof Error?e.message:`Failed to fetch gallery`}}}async function ve(e){try{let t=await fetch(`https://ochre.lib.uchicago.edu/ochre?xquery=for $q in input()/ochre[tree[@type='lesson'][identification/abbreviation='${e.toLocaleLowerCase(`en-US`)}']] return $q&format=json`);if(!t.ok)throw Error(`Failed to fetch website`);let n=await t.json();if(!(`ochre`in n.result)||!(`tree`in n.result.ochre))throw Error(`Failed to fetch website`);let r=n.result.ochre.metadata.project?.identification?D(n.result.ochre.metadata.project.identification):null,i=await ge(n.result.ochre.tree,r?.label??``,n.result.ochre.metadata.project?.identification.website??null);return i}catch(e){return console.error(e),null}}export{_e as fetchGallery,E as fetchItem,ve as fetchWebsite,h as filterProperties,d as getPropertyByLabel,p as getPropertyValueByLabel,f as getPropertyValuesByLabel,m as getUniqueProperties};
11
+ `)}&format=json`);if(!l.ok)throw Error(`Error fetching gallery items, please try again later.`);let u=await l.json();if(!(`gallery`in u.result))throw Error(`Failed to fetch gallery`);let d=A(u.result.gallery.item.identification),f=A(u.result.gallery.project.identification),p={identification:d,projectIdentification:f,resources:Y(u.result.gallery.resource?Array.isArray(u.result.gallery.resource)?u.result.gallery.resource:[u.result.gallery.resource]:[]),maxLength:u.result.gallery.maxLength};return{item:p,error:null}}catch(e){return console.error(e),{item:null,error:e instanceof Error?e.message:`Failed to fetch gallery`}}}async function Se(e){try{let t=await fetch(`https://ochre.lib.uchicago.edu/ochre?xquery=for $q in input()/ochre[tree[@type='lesson'][identification/abbreviation='${e.toLocaleLowerCase(`en-US`)}']] return $q&format=json`);if(!t.ok)throw Error(`Failed to fetch website`);let n=await t.json();if(!(`ochre`in n.result)||!(`tree`in n.result.ochre))throw Error(`Failed to fetch website`);let r=n.result.ochre.metadata.project?.identification?A(n.result.ochre.metadata.project.identification):null,i=await be(n.result.ochre.tree,r?.label??``,n.result.ochre.metadata.project?.identification.website??null);return i}catch(e){return console.error(e),null}}export{xe as fetchGallery,k as fetchItem,Se as fetchWebsite,y as filterProperties,m as getPropertyByLabel,d as getPropertyByUuid,g as getPropertyValueByLabel,p as getPropertyValueByUuid,h as getPropertyValuesByLabel,f as getPropertyValuesByUuid,_ as getUniqueProperties,v as getUniquePropertyLabels};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalculture/ochre-sdk",
3
- "version": "0.7.16",
3
+ "version": "0.7.17",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Node.js library for working with OCHRE (Online Cultural and Historical Research Environment) data",