@digitalculture/ochre-sdk 0.9.5 → 0.9.7

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
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`)),l=c.z.uuid({error:`Invalid UUID provided`}),u=c.z.object({type:c.z.enum([`traditional`,`digital-collection`,`plum`,`cedar`,`elm`,`maple`,`oak`,`palm`],{error:`Invalid website type`}),status:c.z.enum([`development`,`preview`,`production`],{error:`Invalid website status`}),privacy:c.z.enum([`public`,`password`,`private`],{error:`Invalid website privacy`})}),d=c.z.enum([`annotated-document`,`annotated-image`,`audio-player`,`bibliography`,`button`,`collection`,`empty-space`,`entries`,`iframe`,`iiif-viewer`,`image`,`image-gallery`,`map`,`network-graph`,`query`,`search-bar`,`table`,`text`,`timeline`,`video`],{error:`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({error:`Invalid UUID`}),filter:c.z.string().optional(),page:c.z.number().positive({error:`Page must be positive`}),perPage:c.z.number().positive({error:`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({error:`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);return!n&&r&&(n=e.properties.some(e=>D(e,t,{includeNestedProperties:!0}))),n}return!1}const O=`f1c131b6-1498-48a4-95bf-a9edae9fd518`,k=`b9ca2732-78f4-416e-b77f-dae7647e68a9`,ee=`3e6f86ab-df81-45ae-8257-e2867357df56`;function te(e,t){let n=e.find(e=>e.lang===t);return n??null}function A(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 ne(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 j(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 M(e){return String(e).replaceAll(`&#39;`,`'`).replaceAll(`{`,String.raw`\{`).replaceAll(`}`,String.raw`\}`)}function N(e){let t=``;switch(typeof e.string){case`string`:case`number`:case`boolean`:t=M(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+=M(e);else if(`string`in e)t+=P(e);else{let n=e.content==null?``:e.rend==null?M(e.content):ne(M(e.content),e.rend),r=e.whitespace==null?n:j(n,e.whitespace);t+=r}break}default:t=``;break}return t}function P(e){if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return A(M(e));if(`whitespace`in e&&!(`content`in e)&&!(`string`in e))return e.whitespace===`newline`?`
2
- `:``;if(`links`in e){let t=``;t=typeof e.string==`object`?F(e.string):M(e.string).replaceAll(`<`,String.raw`\<`).replaceAll(`{`,String.raw`\{`);let n=Array.isArray(e.links)?e.links:[e.links];for(let r of n)if(`resource`in r){let n=Array.isArray(r.resource)?r.resource[0]:r.resource,i=null;switch(n.content!=null&&(i=M(n.content).replaceAll(`<`,String.raw`\<`).replaceAll(`{`,String.raw`\{`)),n.type){case`image`:return n.rend===`inline`?`<InlineImage uuid="${n.uuid}" ${i===null?``:`content="${i}"`} height={${n.height?.toString()??`null`}} width={${n.width?.toString()??`null`}} />`:n.publicationDateTime==null?`<TooltipSpan${i===null?``:` content="${i}"`}>${t}</TooltipSpan>`:`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`;case`internalDocument`:if(`properties`in e&&e.properties!=null){let r=Array.isArray(e.properties.property)?e.properties.property[0]:e.properties.property;if(r!=null){let e=r.label.uuid,i=typeof r.value==`object`&&`uuid`in r.value&&r.value.uuid!=null?r.value.uuid:null;if(e===O&&i===k){let e=r.property==null?null:Array.isArray(r.property)?r.property[0]:r.property;if(e!=null)return`<Annotation type="hover-card" uuid="${n.uuid}">${t}</Annotation>`}return`<InternalLink uuid="${n.uuid}" properties="${e}"${i===null?``:` value="${i}"`}>${t}</InternalLink>`}else return`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`}else return`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`;case`externalDocument`:return n.publicationDateTime==null?`<TooltipSpan${i===null?``:` content="${i}"`}>${t}</TooltipSpan>`:`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${n.uuid}&load" ${i===null?``:`content="${i}"`}>${t}</ExternalLink>`;case`webpage`:return`<ExternalLink href="${n.href}" ${i===null?``:`content="${i}"`}>${t}</ExternalLink>`;default:return``}}else if(`concept`in r){let e=Array.isArray(r.concept)?r.concept[0]:r.concept;return e.publicationDateTime==null?`<TooltipSpan>${t}</TooltipSpan>`:`<InternalLink uuid="${e.uuid}">${t}</InternalLink>`}else if(`set`in r){let e=Array.isArray(r.set)?r.set[0]:r.set;return e.publicationDateTime==null?`<TooltipSpan>${t}</TooltipSpan>`:`<InternalLink uuid="${e.uuid}">${t}</InternalLink>`}else if(`person`in r){let e=Array.isArray(r.person)?r.person[0]:r.person,n=e.identification?[`string`,`number`,`boolean`].includes(typeof e.identification.label)?M(e.identification.label):F(e.identification.label):null;return e.publicationDateTime==null?`<TooltipSpan${n===null?``:` content="${n}"`}>${t}</TooltipSpan>`:`<InternalLink uuid="${e.uuid}">${t}</InternalLink>`}else if(`bibliography`in r){let e=Array.isArray(r.bibliography)?r.bibliography[0]:r.bibliography;return e.publicationDateTime==null?`<TooltipSpan>${t}</TooltipSpan>`:`<InternalLink uuid="${e.uuid}">${t}</InternalLink>`}else if(`properties`in e&&e.properties!=null){let n=Array.isArray(e.properties.property)?e.properties.property[0]:e.properties.property;if(n!=null){let e=n.label.uuid,r=typeof n.value==`object`&&`uuid`in n.value&&n.value.uuid!=null?n.value.uuid:null;if(e===O&&r===k){let e=n.property==null?null:Array.isArray(n.property)?n.property[0]:n.property;if(e!=null){let n=typeof e.value==`object`&&`uuid`in e.value&&e.value.uuid!=null?e.value.uuid:null;if(n===ee)return`<Annotation type="heading">${t}</Annotation>`}}}}}let t=``;if(`string`in e){let n=Array.isArray(e.string)?e.string:[e.string];for(let e of n)t+=P(e);return`whitespace`in e&&e.whitespace!=null&&(t=j(A(t),e.whitespace)),t.replaceAll(`&#39;`,`'`)}else t=M(e.content),e.rend!=null&&(t=ne(A(t),e.rend)),e.whitespace!=null&&(t=j(A(t),e.whitespace));return t}function F(e,t=`eng`){switch(typeof e.content){case`string`:case`number`:case`boolean`:return M(e.content);case`object`:if(Array.isArray(e.content)){let n=te(e.content,t);if(n)return N(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 N(n)}}else return N(e.content);default:return String(e.content)}}function I(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}function L(e){try{let t={label:[`string`,`number`,`boolean`].includes(typeof e.label)?M(e.label):F(e.label),abbreviation:``,code:e.code??null};for(let n of Object.keys(e).filter(e=>e!==`label`&&e!==`code`))t[n]=F(e[n]);return t}catch(e){return console.error(e),{label:``,abbreviation:``,code:null}}}function re(e){return e==null?[`eng`]:Array.isArray(e)?e.map(e=>F(e)):[F(e)]}function ie(e){let t={label:``,abbreviation:``,code:null};if(e.item)if(e.item.label||e.item.abbreviation){let n=``,r=``,i=null;e.item.label&&(n=F(e.item.label)),e.item.abbreviation&&(r=F(e.item.abbreviation)),e.item.identification.code&&(i=e.item.identification.code),t={label:n,abbreviation:r,code:i}}else t=L(e.item.identification);let n=null,r=e.project?.identification?L(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:F(e.dataset),publisher:F(e.publisher),languages:re(e.language),identifier:F(e.identifier),description:F(e.description)}}function R(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),number:e.n,content:M(e.content)}}function z(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(R(e))}return{tree:R(e.tree),project:R(e.project),spatialUnit:t}}),displayPath:e.displayPath};return n}function B(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?z(e.context):null,date:e.date==null?null:new Date(e.date),identification:e.identification?L(e.identification):null,availability:e.availability?B(e.availability):null,address:e.address?{country:e.address.country??null,city:e.address.city??null,state:e.address.state??null}:null,description:e.description?typeof e.description==`string`||typeof e.description==`number`||typeof e.description==`boolean`?M(e.description):F(e.description):null,coordinates:G(e.coordinates),content:e.content==null?null:M(e.content),notes:e.notes?W(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],events:e.events?ue(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:e.properties?K(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function V(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:`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`:`propertyValue`in e?`propertyValue`:null,content:`content`in t?t.content==null?null:M(t.content):null,href:`href`in t&&t.href!=null?t.href:null,fileFormat:`fileFormat`in t&&t.fileFormat!=null?t.fileFormat:null,fileSize:`fileSize`in t&&t.fileSize!=null?t.fileSize:null,uuid:t.uuid??null,type:t.type??null,identification:t.identification?L(t.identification):null,description:`description`in t&&t.description!=null?F(t.description):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 H(e){let t=[];for(let n of e)t.push(...oe(n));return t}function U(e,t=`eng`){let n=``,r=Array.isArray(e)?e.find(e=>e.lang===t):e;if(typeof r.string==`string`||typeof r.string==`number`||typeof r.string==`boolean`)n+=A(M(r.string));else{let e=Array.isArray(r.string)?r.string:[r.string];for(let t of e)n+=P(t)}return n}function se(e){return{publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),identification:e.identification?L(e.identification):null,url:e.href??(e.htmlImgSrcPrefix==null&&e.content!=null?M(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?M(e.content):null,widthPreview:e.widthPreview??null,heightPreview:e.heightPreview??null,width:e.width??null,height:e.height??null}}function W(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`?A(M(a.string)):A(U(a)),n.push({number:r.noteNo,title:a.title==null?null:M(a.title),content:e})}return n}function G(e){if(e==null)return[];let t=[],n=Array.isArray(e.coord)?e.coord:[e.coord];for(let e of n){let n=`source`in e&&e.source?e.source.context===`self`?{context:`self`,uuid:e.source.label.uuid,label:F(e.source.label)}:e.source.context===`related`?{context:`related`,uuid:e.source.label.uuid,label:F(e.source.label),value:F(e.source.value)}:{context:`inherited`,uuid:e.source.label.uuid,item:{uuid:e.source.item.label.uuid,label:F(e.source.item.label)},label:F(e.source.label)}:null;switch(e.type){case`point`:t.push({type:e.type,latitude:e.latitude,longitude:e.longitude,altitude:e.altitude??null,source:n});break;case`plane`:t.push({type:e.type,minimum:{latitude:e.minimum.latitude,longitude:e.minimum.longitude},maximum:{latitude:e.maximum.latitude,longitude:e.maximum.longitude},source:n});break}}return t}function ce(e){return{number:e.observationNo,date:e.date==null?null:new Date(e.date),observers:e.observers==null?[]:typeof e.observers==`string`||typeof e.observers==`number`||typeof e.observers==`boolean`?M(e.observers).split(`;`).map(e=>e.trim()):V(Array.isArray(e.observers)?e.observers:[e.observers]),notes:e.notes?W(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?H(Array.isArray(e.links)?e.links:[e.links]):[],properties:e.properties?K(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function le(e){let t=[];for(let n of e)t.push(ce(n));return t}function ue(e){let t=[];for(let n of e)t.push({date:n.dateTime==null?null:new Date(n.dateTime),label:F(n.label),agent:n.agent?{uuid:n.agent.uuid,content:M(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=M(e);let n={content:t,label:null,dataType:`string`,isUncertain:!1,category:`value`,type:null,uuid:null,publicationDateTime:null,unit:null};return n}else{let r=`string`;if(e.dataType!=null){let{data:t,error:n}=p.safeParse(e.dataType);if(n)throw Error(`Invalid property value content type: "${e.dataType}"`);r=t}switch(r){case`integer`:case`decimal`:case`time`:e.rawValue==null?(t=Number(e.content),n=null):(t=Number(e.rawValue),n=e.content?F({content:e.content}):null);break;case`boolean`:e.rawValue==null?(t=e.content===!0,n=null):(t=e.rawValue===`true`,n=e.content?F({content:e.content}):null);break;default:`slug`in e&&e.slug!=null?t=M(e.slug):e.content!=null&&(e.rawValue==null?(t=F({content:e.content}),n=null):(t=M(e.rawValue),n=e.content?F({content:e.content}):null));break}let i={content:t,dataType:r,isUncertain:e.isUncertain??!1,label:n,category:e.category??null,type:e.type??null,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:F(e.label,t).replace(/\s*\.{3}$/,``).trim(),values:r,comment:e.comment==null?null:M(e.comment),properties:e.property?K(Array.isArray(e.property)?e.property:[e.property]):[]}}function K(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?K(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:M(e.title),shape:e.shape===`rect`?`rectangle`:e.shape===`circle`?`circle`:`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:L(e.identification),description:e.description?F(e.description):null}}function q(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:L(e.source.resource.identification)}),{uuid:e.uuid??null,zoteroId:e.zoteroId??null,category:`bibliography`,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),type:e.type??null,number:e.n??null,identification:e.identification?L(e.identification):null,projectIdentification:e.project?.identification?L(e.project.identification):null,context:e.context?z(e.context):null,citation:{details:e.citationDetails??null,format:e.citationFormat??null,short:e.citationFormatSpan?M(`default:span`in e.citationFormatSpan?e.citationFormatSpan[`default:span`].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?M(`default:div`in e.referenceFormatDiv?e.referenceFormatDiv[`default:div`][`default:div`].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?V(Array.isArray(e.publicationInfo.publishers.publishers.person)?e.publicationInfo.publishers.publishers.person:[e.publicationInfo.publishers.publishers.person]):[],startDate:e.publicationInfo?.startDate?new Date(e.publicationInfo.startDate.year,e.publicationInfo.startDate.month,e.publicationInfo.startDate.day):null},entryInfo:e.entryInfo?{startIssue:M(e.entryInfo.startIssue),startVolume:M(e.entryInfo.startVolume)}:null,source:{resource:t,documentUrl:e.sourceDocument?`https://ochre.lib.uchicago.edu/ochre?uuid=${e.sourceDocument.uuid}&load`:null},periods:e.periods?q(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],authors:e.authors?V(Array.isArray(e.authors.person)?e.authors.person:[e.authors.person]):[],properties:e.properties?K(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function J(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?z(e.context):null,availability:e.availability?B(e.availability):null,identification:L(e.identification),date:e.date?new Date(e.date):null,creators:e.creators?V(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],description:e.description?typeof e.description==`string`||typeof e.description==`number`||typeof e.description==`boolean`?M(e.description):F(e.description):``,notes:e.notes?W(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?H(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,t,n){if(typeof e.items==`string`)throw TypeError(`Invalid OCHRE data: Tree has no items`);let r=[];e.creators&&(r=V(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]));let i=null;e.date!=null&&(i=new Date(e.date));let a=n??I(Object.keys(e.items)),o=[];switch(a){case`resource`:if(!(`resource`in e.items))throw Error(`Invalid OCHRE data: Tree has no resources`);o=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: Tree has no spatial units`);o=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: Tree has no concepts`);o=Te(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept]);break;case`period`:if(!(`period`in e.items))throw Error(`Invalid OCHRE data: Tree has no periods`);o=q(Array.isArray(e.items.period)?e.items.period:[e.items.period]);break;case`bibliography`:if(!(`bibliography`in e.items))throw Error(`Invalid OCHRE data: Tree has no bibliographies`);o=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: Tree has no persons`);o=V(Array.isArray(e.items.person)?e.items.person:[e.items.person]);break;case`propertyValue`:if(!(`propertyValue`in e.items))throw Error(`Invalid OCHRE data: Tree has no property values`);o=_e(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]);break;case`set`:{if(!(`set`in e.items))throw Error(`Invalid OCHRE data: Tree has no sets`);let t=[];for(let r of Array.isArray(e.items.set)?e.items.set:[e.items.set])t.push(ye(r,n));o=t;break}default:throw Error(`Invalid OCHRE data: Tree has no items or is malformed`)}let s={uuid:e.uuid,category:`tree`,publicationDateTime:new Date(e.publicationDateTime),identification:L(e.identification),creators:r,license:B(e.availability),date:i,type:e.type,number:e.n,items:o,properties:e.properties?K(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return s}function ye(e,t){if(typeof e.items==`string`)throw TypeError(`Invalid OCHRE data: Set has no items`);let n=t??I(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=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=Te(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=q(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=V(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:B(e.availability),identification:L(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?M(e.description):F(e.description):``,creators:e.creators?V(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,fileFormat:e.fileFormat??null,fileSize:e.fileSize??null,context:`context`in e&&e.context?z(e.context):null,license:`availability`in e&&e.availability?B(e.availability):null,copyright:`copyright`in e&&e.copyright!=null?M(e.copyright):null,identification:L(e.identification),date:e.date==null?null:new Date(e.date),image:e.image?se(e.image):null,creators:e.creators?V(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],notes:e.notes?W(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?M(e.description):F(e.description):``,coordinates:e.coordinates?G(e.coordinates):[],document:e.document&&`content`in e.document?U(e.document.content):null,href:e.href??null,imageMap:e.imagemap?pe(e.imagemap):null,periods:e.periods?q(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],links:e.links?H(Array.isArray(e.links)?e.links:[e.links]):[],reverseLinks:e.reverseLinks?H(Array.isArray(e.reverseLinks)?e.reverseLinks:[e.reverseLinks]):[],properties:e.properties?K(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],bibliographies:e.bibliographies?J(Array.isArray(e.bibliographies.bibliography)?e.bibliographies.bibliography:[e.bibliographies.bibliography]):[],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(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?z(e.context):null,license:`availability`in e&&e.availability?B(e.availability):null,identification:L(e.identification),image:e.image?se(e.image):null,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?M(e.description):F(e.description):``,coordinates:G(e.coordinates),mapData:e.mapData??null,observations:`observations`in e&&e.observations?le(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[ce(e.observation)]:[],events:`events`in e&&e.events?ue(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:`properties`in e&&e.properties?K(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?B(e.availability):null,context:`context`in e&&e.context?z(e.context):null,identification:L(e.identification),interpretations:e.interpretations?fe(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation]):[],properties:e.properties?K(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return t}const we=async(e,t)=>{let n=[];for(let r of e){let e=r.properties?K(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 X(r);n.push(e);break}case`page`:{let e=await De(r);e&&n.push(e);break}case`block`:{let e=await Z(r);e&&n.push(e);break}}}return n};function Te(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(Ce(e));return t}async function Ee(e,t){let n=e.values[0].content,{data:r}=d.safeParse(n),i={component:r},a=t.links?H(Array.isArray(t.links)?t.links:[t.links]):[],o=a.filter(e=>e.type===`image`||e.type===`IIIF`);switch(r){case`annotated-document`:{let e=a.find(e=>e.type===`internalDocument`);if(!e)throw Error(`Document link not found for the following component: “${r}”`);i.documentId=e.uuid;break}case`annotated-image`:{if(o.length===0)throw Error(`Image link not found for the following component: “${r}”`);let t=w(e.properties,`filter-displayed`)===!0;i.imageUuid=o[0].uuid,i.isFilterDisplayed=t;break}case`audio-player`:{let t=a.find(e=>e.type===`audio`);if(!t)throw Error(`Audio link not found for the following component: “${r}”`);let n=!1,o=w(e.properties,`speed-controls-displayed`);o!==null&&(n=o===!0);let s=!1,c=w(e.properties,`volume-controls-displayed`);c!==null&&(s=c===!0);let l=!1,u=w(e.properties,`seek-bar-displayed`);u!==null&&(l=u===!0),i.audioId=t.uuid,i.isSpeedControlsDisplayed=n,i.isVolumeControlsDisplayed=s,i.isSeekBarDisplayed=l;break}case`bibliography`:{let t=a.find(e=>e.category===`bibliography`);if(!t)throw Error(`Bibliography link not found for the following component: “${r}”`);if(!t.bibliographies)throw Error(`Bibliography not found for the following component: “${r}”`);let n=w(e.properties,`layout`);n??=`long`,i.bibliographies=t.bibliographies,i.layout=n;break}case`button`:{let n=w(e.properties,`variant`);n??=`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: “${r}”`);a=!0}let s=null,c=w(e.properties,`start-icon`);c!==null&&(s=c);let l=null,u=w(e.properties,`end-icon`);u!==null&&(l=u),i.variant=n,i.href=o,i.isExternal=a,i.label=[`string`,`number`,`boolean`].includes(typeof t.identification.label)?M(t.identification.label):F(t.identification.label),i.startIcon=s,i.endIcon=l;break}case`collection`:{let t=a.find(e=>e.category===`set`);if(!t)throw Error(`Collection link not found for the following component: “${r}”`);let n=w(e.properties,`variant`);n??=`full`;let o=w(e.properties,`item-variant`);o??=`detailed`;let s=w(e.properties,`pagination-variant`);s??=`default`;let c=!1,l=w(e.properties,`filter-displayed`);l!==null&&(c=l===!0);let u=w(e.properties,`layout`);u??=`image-start`,i.collectionId=t.uuid,i.variant=n,i.itemVariant=o,i.paginationVariant=s,i.isFilterDisplayed=c,i.layout=u;break}case`empty-space`:{let t=w(e.properties,`height`),n=w(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: “${r}”`);let n=w(e.properties,`variant`);n??=`entry`;let o=!1,s=w(e.properties,`filter-displayed`);s!==null&&(o=s===!0),i.entriesId=t.uuid,i.variant=n,i.isFilterDisplayed=o;break}case`iframe`:{let t=a.find(e=>e.type===`webpage`)?.href;if(!t)throw Error(`URL not found for the following component: “${r}”`);let n=w(e.properties,`height`),o=w(e.properties,`width`);i.href=t,i.height=n,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: “${r}”`);i.IIIFId=e.uuid;break}case`image`:{if(o.length===0)throw Error(`Image link not found for the following component: “${r}”`);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,description:e.description??null});let n=w(e.properties,`variant`);n??=`default`;let a=w(e.properties,`layout-caption`);a??=`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}}i.images=t,i.variant=n,i.width=s,i.height=l,i.isFullWidth=d,i.isFullHeight=p,i.imageQuality=h,i.captionLayout=a,i.captionSource=g,i.altTextSource=_,i.isTransparentBackground=v,i.isCover=b,i.carouselOptions=C;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: “${r}”`);let n=w(e.properties,`filter-displayed`)===!0;i.galleryId=t.uuid,i.isFilterDisplayed=n;break}case`map`:{let t=a.find(e=>e.category===`set`||e.category===`tree`);if(!t)throw Error(`Map link not found for the following component: “${r}”`);let n=!0,o=w(e.properties,`is-interactive`);o!==null&&(n=o===!0);let s=!1,c=w(e.properties,`is-clustered`);c!==null&&(s=c===!0);let l=!1,u=w(e.properties,`is-using-pins`);u!==null&&(l=u===!0);let d=null,f=w(e.properties,`custom-basemap`);f!==null&&(d=f);let p=!1,m=w(e.properties,`controls-displayed`);m!==null&&(p=m===!0);let h=!1,g=w(e.properties,`is-full-height`);g!==null&&(h=g===!0),i.mapId=t.uuid,i.isInteractive=n,i.isClustered=s,i.isUsingPins=l,i.customBasemap=d,i.isControlsDisplayed=p,i.isFullHeight=h;break}case`network-graph`:break;case`query`:{let t=[],n=e.properties;if(n.length===0)throw Error(`Query properties not found for the following component: “${r}”`);for(let e of n){let n=e.properties,i=w(n,`query-prompt`);if(i===null)throw Error(`Query prompt not found for the following component: “${r}”`);let a=n.find(e=>e.label===`use-property`)?.values.map(e=>e.uuid).filter(e=>e!==null)??[],o=w(n,`start-icon`),s=w(n,`end-icon`);t.push({label:String(i),propertyUuids:a,startIcon:o===null?null:String(o),endIcon:s===null?null:String(s)})}i.queries=t;break}case`table`:{let e=a.find(e=>e.category===`set`);if(!e)throw Error(`Table link not found for the following component: “${r}”`);i.tableId=e.uuid;break}case`search-bar`:{let t=w(e.properties,`variant`);t??=`default`;let n=w(e.properties,`placeholder-text`);i.variant=t,i.placeholder=n===null?null:String(n);break}case`text`:{let n=t.document&&`content`in t.document?U(t.document.content):null;if(!n)throw Error(`Content not found for the following component: “${r}”`);let a=w(e.properties,`variant`);a??=`block`;let o=w(e.properties,`heading`);i.variant=a,i.heading=o,i.content=n;break}case`timeline`:{let e=a.find(e=>e.category===`tree`);if(!e)throw Error(`Timeline link not found for the following component: “${r}”`);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: “${r}”`);let n=w(e.properties,`chapters-displayed`);n??=!0,i.videoId=t.uuid,i.isChaptersDislayed=n===!0;break}default:console.warn(`Invalid or non-implemented component name “${String(n)}” for the following element: “${F(t.identification.label)}”`);break}return i}async function X(e){let t=L(e.identification),n=e.properties?.property?K(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 Ee(i,e),o=r.properties.find(e=>e.label===`section-sidebar-displayed`),s=o?.values[0]?.content===!0,c=e.properties?.property?K(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=a.component===`collection`,g=!1,_=!1,v=!1,y=a.component===`collection`&&a.variant===`full`;if(p){let e=w(p,`variant`);e&&(m=e),h=w(p,`name-displayed`)===!0,g=w(p,`description-displayed`)===!0,_=w(p,`date-displayed`)===!0,v=w(p,`creators-displayed`)===!0,y=w(p,`count-displayed`)===!0}return{uuid:e.uuid,type:`element`,title:{label:t.label,variant:m,properties:{isNameDisplayed:h,isDescriptionDisplayed:g,isDateDisplayed:_,isCreatorsDisplayed:v,isCountDisplayed:y}},isDisplayedInBlockSectionSidebar:s,cssStyles:u,cssStylesMobile:f,...a}}async function De(e){let t=e.properties?K(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=L(e.identification),r=e.slug;if(r===void 0)throw Error(`Slug not found for page “${n.label}”`);let i=e.links?H(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?K(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 X(e);s.push(t);break}case`block`:{let t=await Z(e);t&&s.push(t);break}}}let c=e.resource?await we(Array.isArray(e.resource)?e.resource:[e.resource],`page`):[],l=!0,u=`default`,d=`default`,f=!0,p=!1,m=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`page`)?.properties;if(m){let e=m.find(e=>e.label===`header`)?.values[0];e&&(l=e.content===!0);let t=m.find(e=>e.label===`width`)?.values[0];t&&(u=t.content);let n=m.find(e=>e.label===`variant`)?.values[0];n&&(d=n.content);let r=m.find(e=>e.label===`sidebar-visible`)?.values[0];r&&(f=r.content===!0);let i=m.find(e=>e.label===`breadcrumbs-visible`)?.values[0];i&&(p=i.content===!0)}let h=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css`)?.properties,g=[];if(h)for(let e of h)g.push({label:e.label,value:e.values[0].content});let _=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css-mobile`)?.properties,v=[];if(_)for(let e of _)v.push({label:e.label,value:e.values[0].content});return{title:n.label,slug:r,items:s,properties:{displayedInHeader:l,width:u,variant:d,backgroundImageUrl:a?`https://ochre.lib.uchicago.edu/ochre?uuid=${a.uuid}&load`:null,isSidebarDisplayed:f,isBreadcrumbsDisplayed:p,cssStyles:g,cssStylesMobile:v},webpages:c}}async function Oe(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n){let n=await De(e);n&&t.push(n)}return t}async function Z(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?K(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?K(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 X(e);a.push(t);break}case`block`:{let t=await Z(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=ke(t),t}function ke(e){let t=[];for(let n of e.items)switch(n.type){case`block`:{let e=ke(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 Ae(e){let t=K(e),n=t.find(e=>e.label===`presentation`)?.properties;if(!n)throw Error(`Presentation property not found`);let r=n.find(e=>e.label===`webUI`)?.values[0]?.content;r??=`traditional`;let i=n.find(e=>e.label===`status`)?.values[0]?.content;i??=`development`;let a=n.find(e=>e.label===`privacy`)?.values[0]?.content;a??=`public`;let o=u.safeParse({type:r,status:i,privacy:a});if(!o.success)throw Error(`Invalid website properties: ${o.error.message}`);let s=null,c=n.find(e=>e.label===`contact`);if(c){let[e,t]=(c.values[0]?.content).split(`;`);s={name:e,email:t??null}}let l=n.find(e=>e.label===`logo`)?.values[0]?.uuid??null,d=!0,f=`default`,p=`start`,m=!0,h=!0,g=!1,_=!0,v=null,y=n.find(e=>e.label===`navbar-visible`)?.values[0];y&&(d=y.content===!0);let b=n.find(e=>e.label===`navbar-variant`)?.values[0];b&&(f=b.content);let x=n.find(e=>e.label===`navbar-alignment`)?.values[0];x&&(p=x.content);let S=n.find(e=>e.label===`navbar-project-visible`)?.values[0];S&&(m=S.content===!0);let C=n.find(e=>e.label===`footer-visible`)?.values[0];C&&(h=C.content===!0);let w=n.find(e=>e.label===`sidebar-visible`)?.values[0];w&&(g=w.content===!0);let T=n.find(e=>e.label===`supports-theme-toggle`)?.values[0];T&&(_=T.content===!0);let E=n.find(e=>e.label===`default-theme`)?.values[0];E&&(v=E.content);let{type:D,status:O,privacy:k}=o.data;return{type:D,privacy:k,status:O,contact:s,isHeaderDisplayed:d,headerVariant:f,headerAlignment:p,isHeaderProjectDisplayed:m,isFooterDisplayed:h,isSidebarDisplayed:g,supportsThemeToggle:_,defaultTheme:v,logoUrl:l===null?null:`https://ochre.lib.uchicago.edu/ochre?uuid=${l}&load`}}function Q(e){let t=[];for(let n of e){let e=Array.isArray(n.context)?n.context:[n.context];for(let n of e){let e=Array.isArray(n.levels.level)?n.levels.level:[n.levels.level],r=``,i=e.map(e=>{let t=``,n=null;if(typeof e==`string`){let r=e.split(`, `);t=r[0],n=r[1]===`null`?null:r[1]}else{let i=e.content.split(`, `);r=e.dataType,t=i[0],n=i[1]===`null`?null:i[1]}return{variableUuid:t,valueUuid:n}});t.push({context:i,type:r,identification:L(n.identification)})}}return t}async function je(e,t,n){if(!e.properties)throw Error(`Website properties not found`);let r=Ae(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 Oe(i),o=null,s=[],c={label:``,variant:`default`,properties:{isNameDisplayed:!1,isDescriptionDisplayed:!1,isDateDisplayed:!1,isCreatorsDisplayed:!1,isCountDisplayed:!1}},l=`start`,u=`default`,d=[],f=[],p=i.find(e=>{let t=e.properties?K(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];return t.some(e=>e.label===`presentation`&&e.values[0]?.content===`element`&&e.properties[0]?.label===`component`&&e.properties[0].values[0]?.content===`sidebar`)});if(p){c.label=typeof p.identification.label==`string`||typeof p.identification.label==`number`||typeof p.identification.label==`boolean`?M(p.identification.label):F(p.identification.label);let e=p.properties?K(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),c.properties.isNameDisplayed=w(o,`name-displayed`)===!0,c.properties.isDescriptionDisplayed=w(o,`description-displayed`)===!0,c.properties.isDateDisplayed=w(o,`date-displayed`)===!0,c.properties.isCreatorsDisplayed=w(o,`creators-displayed`)===!0,c.properties.isCountDisplayed=w(o,`count-displayed`)===!0}let m=p.resource?Array.isArray(p.resource)?p.resource:[p.resource]:[];for(let e of m){let t=await X(e);s.push(t)}}s.length>0&&(o={elements:s,title:c,layout:l,mobileLayout:u,cssStyles:d,cssStylesMobile:f});let m={contexts:{flatten:[],filter:[],detail:[],download:[],label:[],suppress:[]}};if(e.websiteOptions){let t=e.websiteOptions.flattenContexts==null?[]:Array.isArray(e.websiteOptions.flattenContexts)?e.websiteOptions.flattenContexts:[e.websiteOptions.flattenContexts],n=e.websiteOptions.suppressContexts==null?[]:Array.isArray(e.websiteOptions.suppressContexts)?e.websiteOptions.suppressContexts:[e.websiteOptions.suppressContexts],r=e.websiteOptions.filterContexts==null?[]:Array.isArray(e.websiteOptions.filterContexts)?e.websiteOptions.filterContexts:[e.websiteOptions.filterContexts],i=e.websiteOptions.detailContexts==null?[]:Array.isArray(e.websiteOptions.detailContexts)?e.websiteOptions.detailContexts:[e.websiteOptions.detailContexts],a=e.websiteOptions.downloadContexts==null?[]:Array.isArray(e.websiteOptions.downloadContexts)?e.websiteOptions.downloadContexts:[e.websiteOptions.downloadContexts],o=e.websiteOptions.labelContexts==null?[]:Array.isArray(e.websiteOptions.labelContexts)?e.websiteOptions.labelContexts:[e.websiteOptions.labelContexts];m={contexts:{flatten:Q(t),filter:Q(r),detail:Q(i),download:Q(a),label:Q(o),suppress:Q(n)}}}return{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:L(e.identification),project:{name:M(t),website:n===null?null:M(n)},creators:e.creators?V(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:B(e.availability),pages:a,sidebar:o,properties:r,searchOptions:{filters:e.searchOptions?.filterUuids==null?[]:(Array.isArray(e.searchOptions.filterUuids.uuid)?e.searchOptions.filterUuids.uuid:[e.searchOptions.filterUuids.uuid]).map(e=>({uuid:e.content,type:e.type})),scopes:e.searchOptions?.scopes==null?[]:(Array.isArray(e.searchOptions.scopes.scope)?e.searchOptions.scopes.scope:[e.searchOptions.scopes.scope]).map(e=>({uuid:e.uuid.content,type:e.uuid.type,identification:L(e.identification)}))},globalOptions:m}}async function Me(e,t,n,r,i){try{let{uuid:a,filter:o,page:s,perPage:c}=m.parse({uuid:e,filter:t,page:n,perPage:r}),l=await(i??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
2
+ `:``;if(`links`in e){let t=``;t=typeof e.string==`object`?F(e.string):M(e.string).replaceAll(`<`,String.raw`\<`).replaceAll(`{`,String.raw`\{`);let n=Array.isArray(e.links)?e.links:[e.links];for(let r of n)if(`resource`in r){let n=Array.isArray(r.resource)?r.resource[0]:r.resource,i=null;switch(n.content!=null&&(i=M(n.content).replaceAll(`<`,String.raw`\<`).replaceAll(`{`,String.raw`\{`)),n.type){case`image`:return n.rend===`inline`?`<InlineImage uuid="${n.uuid}" ${i===null?``:`content="${i}"`} height={${n.height?.toString()??`null`}} width={${n.width?.toString()??`null`}} />`:n.publicationDateTime==null?`<TooltipSpan${i===null?``:` content="${i}"`}>${t}</TooltipSpan>`:`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`;case`internalDocument`:if(`properties`in e&&e.properties!=null){let r=Array.isArray(e.properties.property)?e.properties.property[0]:e.properties.property;if(r!=null){let e=r.label.uuid,i=typeof r.value==`object`&&`uuid`in r.value&&r.value.uuid!=null?r.value.uuid:null;if(e===O&&i===k){let e=r.property==null?null:Array.isArray(r.property)?r.property[0]:r.property;if(e!=null)return`<Annotation type="hover-card" uuid="${n.uuid}">${t}</Annotation>`}return`<InternalLink uuid="${n.uuid}" properties="${e}"${i===null?``:` value="${i}"`}>${t}</InternalLink>`}else return`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`}else return`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`;case`externalDocument`:return n.publicationDateTime==null?`<TooltipSpan${i===null?``:` content="${i}"`}>${t}</TooltipSpan>`:`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${n.uuid}&load" ${i===null?``:`content="${i}"`}>${t}</ExternalLink>`;case`webpage`:return`<ExternalLink href="${n.href}" ${i===null?``:`content="${i}"`}>${t}</ExternalLink>`;default:return``}}else if(`concept`in r){let e=Array.isArray(r.concept)?r.concept[0]:r.concept;return e.publicationDateTime==null?`<TooltipSpan>${t}</TooltipSpan>`:`<InternalLink uuid="${e.uuid}">${t}</InternalLink>`}else if(`set`in r){let e=Array.isArray(r.set)?r.set[0]:r.set;return e.publicationDateTime==null?`<TooltipSpan>${t}</TooltipSpan>`:`<InternalLink uuid="${e.uuid}">${t}</InternalLink>`}else if(`person`in r){let e=Array.isArray(r.person)?r.person[0]:r.person,n=e.identification?[`string`,`number`,`boolean`].includes(typeof e.identification.label)?M(e.identification.label):F(e.identification.label):null;return e.publicationDateTime==null?`<TooltipSpan${n===null?``:` content="${n}"`}>${t}</TooltipSpan>`:`<InternalLink uuid="${e.uuid}">${t}</InternalLink>`}else if(`bibliography`in r){let e=Array.isArray(r.bibliography)?r.bibliography[0]:r.bibliography;return e.publicationDateTime==null?`<TooltipSpan>${t}</TooltipSpan>`:`<InternalLink uuid="${e.uuid}">${t}</InternalLink>`}else if(`properties`in e&&e.properties!=null){let n=Array.isArray(e.properties.property)?e.properties.property[0]:e.properties.property;if(n!=null){let e=n.label.uuid,r=typeof n.value==`object`&&`uuid`in n.value&&n.value.uuid!=null?n.value.uuid:null;if(e===O&&r===k){let e=n.property==null?null:Array.isArray(n.property)?n.property[0]:n.property;if(e!=null){let n=typeof e.value==`object`&&`uuid`in e.value&&e.value.uuid!=null?e.value.uuid:null;if(n===ee)return`<Annotation type="heading">${t}</Annotation>`}}}}}let t=``;if(`string`in e){let n=Array.isArray(e.string)?e.string:[e.string];for(let e of n)t+=P(e);return`whitespace`in e&&e.whitespace!=null&&(t=j(A(t),e.whitespace)),t.replaceAll(`&#39;`,`'`)}else t=M(e.content),e.rend!=null&&(t=ne(A(t),e.rend)),e.whitespace!=null&&(t=j(A(t),e.whitespace));return t}function F(e,t=`eng`){switch(typeof e.content){case`string`:case`number`:case`boolean`:return M(e.content);case`object`:if(Array.isArray(e.content)){let n=te(e.content,t);if(n)return N(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 N(n)}}else return N(e.content);default:return String(e.content)}}function I(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}function L(e){try{let t={label:[`string`,`number`,`boolean`].includes(typeof e.label)?M(e.label):F(e.label),abbreviation:``,code:e.code??null};for(let n of Object.keys(e).filter(e=>e!==`label`&&e!==`code`))t[n]=F(e[n]);return t}catch(e){return console.error(e),{label:``,abbreviation:``,code:null}}}function re(e){return e==null?[`eng`]:Array.isArray(e)?e.map(e=>F(e)):[F(e)]}function ie(e){let t={label:``,abbreviation:``,code:null};if(e.item)if(e.item.label||e.item.abbreviation){let n=``,r=``,i=null;e.item.label&&(n=F(e.item.label)),e.item.abbreviation&&(r=F(e.item.abbreviation)),e.item.identification.code&&(i=e.item.identification.code),t={label:n,abbreviation:r,code:i}}else t=L(e.item.identification);let n=null,r=e.project?.identification?L(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:F(e.dataset),publisher:F(e.publisher),languages:re(e.language),identifier:F(e.identifier),description:F(e.description)}}function R(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),number:e.n,content:M(e.content)}}function z(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(R(e))}return{tree:R(e.tree),project:R(e.project),spatialUnit:t}}),displayPath:e.displayPath};return n}function B(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?z(e.context):null,date:e.date==null?null:new Date(e.date),identification:e.identification?L(e.identification):null,availability:e.availability?B(e.availability):null,address:e.address?{country:e.address.country??null,city:e.address.city??null,state:e.address.state??null}:null,description:e.description?typeof e.description==`string`||typeof e.description==`number`||typeof e.description==`boolean`?M(e.description):F(e.description):null,coordinates:G(e.coordinates),content:e.content==null?null:M(e.content),notes:e.notes?W(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],events:e.events?ue(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:e.properties?K(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function V(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:`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`:`propertyValue`in e?`propertyValue`:null,content:`content`in t?t.content==null?null:M(t.content):null,href:`href`in t&&t.href!=null?t.href:null,fileFormat:`fileFormat`in t&&t.fileFormat!=null?t.fileFormat:null,fileSize:`fileSize`in t&&t.fileSize!=null?t.fileSize:null,uuid:t.uuid??null,type:t.type??null,identification:t.identification?L(t.identification):null,description:`description`in t&&t.description!=null?F(t.description):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 H(e){let t=[];for(let n of e)t.push(...oe(n));return t}function U(e,t=`eng`){let n=``,r=Array.isArray(e)?e.find(e=>e.lang===t):e;if(typeof r.string==`string`||typeof r.string==`number`||typeof r.string==`boolean`)n+=A(M(r.string));else{let e=Array.isArray(r.string)?r.string:[r.string];for(let t of e)n+=P(t)}return n}function se(e){return{publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),identification:e.identification?L(e.identification):null,url:e.href??(e.htmlImgSrcPrefix==null&&e.content!=null?M(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?M(e.content):null,widthPreview:e.widthPreview??null,heightPreview:e.heightPreview??null,width:e.width??null,height:e.height??null}}function W(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`?A(M(a.string)):A(U(a)),n.push({number:r.noteNo,title:a.title==null?null:M(a.title),content:e})}return n}function G(e){if(e==null)return[];let t=[],n=Array.isArray(e.coord)?e.coord:[e.coord];for(let e of n){let n=`source`in e&&e.source?e.source.context===`self`?{context:`self`,uuid:e.source.label.uuid,label:F(e.source.label)}:e.source.context===`related`?{context:`related`,uuid:e.source.label.uuid,label:F(e.source.label),value:F(e.source.value)}:{context:`inherited`,uuid:e.source.label.uuid,item:{uuid:e.source.item.label.uuid,label:F(e.source.item.label)},label:F(e.source.label)}:null;switch(e.type){case`point`:t.push({type:e.type,latitude:e.latitude,longitude:e.longitude,altitude:e.altitude??null,source:n});break;case`plane`:t.push({type:e.type,minimum:{latitude:e.minimum.latitude,longitude:e.minimum.longitude},maximum:{latitude:e.maximum.latitude,longitude:e.maximum.longitude},source:n});break}}return t}function ce(e){return{number:e.observationNo,date:e.date==null?null:new Date(e.date),observers:e.observers==null?[]:typeof e.observers==`string`||typeof e.observers==`number`||typeof e.observers==`boolean`?M(e.observers).split(`;`).map(e=>e.trim()):V(Array.isArray(e.observers)?e.observers:[e.observers]),notes:e.notes?W(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?H(Array.isArray(e.links)?e.links:[e.links]):[],properties:e.properties?K(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function le(e){let t=[];for(let n of e)t.push(ce(n));return t}function ue(e){let t=[];for(let n of e)t.push({date:n.dateTime==null?null:new Date(n.dateTime),label:F(n.label),agent:n.agent?{uuid:n.agent.uuid,content:M(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=M(e);let n={content:t,label:null,dataType:`string`,isUncertain:!1,category:`value`,type:null,uuid:null,publicationDateTime:null,unit:null,href:null,slug:null};return n}else{let r=`string`;if(e.dataType!=null){let{data:t,error:n}=p.safeParse(e.dataType);if(n)throw Error(`Invalid property value content type: "${e.dataType}"`);r=t}switch(r){case`integer`:case`decimal`:case`time`:e.rawValue==null?(t=Number(e.content),n=null):(t=Number(e.rawValue),n=e.content?F({content:e.content}):null);break;case`boolean`:e.rawValue==null?(t=e.content===!0,n=null):(t=e.rawValue===`true`,n=e.content?F({content:e.content}):null);break;default:`slug`in e&&e.slug!=null?t=M(e.slug):e.content!=null&&(e.rawValue==null?(t=F({content:e.content}),n=null):(t=M(e.rawValue),n=e.content?F({content:e.content}):null));break}let i={content:t,dataType:r,isUncertain:e.isUncertain??!1,label:n,category:e.category??null,type:e.type??null,uuid:e.uuid??null,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),unit:e.unit??null,href:e.href??null,slug:e.slug??null};return i}});return{uuid:e.label.uuid,label:F(e.label,t).replace(/\s*\.{3}$/,``).trim(),values:r,comment:e.comment==null?null:M(e.comment),properties:e.property?K(Array.isArray(e.property)?e.property:[e.property]):[]}}function K(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?K(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:M(e.title),shape:e.shape===`rect`?`rectangle`:e.shape===`circle`?`circle`:`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:L(e.identification),description:e.description?F(e.description):null}}function q(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:L(e.source.resource.identification)}),{uuid:e.uuid??null,zoteroId:e.zoteroId??null,category:`bibliography`,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),type:e.type??null,number:e.n??null,identification:e.identification?L(e.identification):null,projectIdentification:e.project?.identification?L(e.project.identification):null,context:e.context?z(e.context):null,citation:{details:e.citationDetails??null,format:e.citationFormat??null,short:e.citationFormatSpan?M(`default:span`in e.citationFormatSpan?e.citationFormatSpan[`default:span`].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?M(`default:div`in e.referenceFormatDiv?e.referenceFormatDiv[`default:div`][`default:div`].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?V(Array.isArray(e.publicationInfo.publishers.publishers.person)?e.publicationInfo.publishers.publishers.person:[e.publicationInfo.publishers.publishers.person]):[],startDate:e.publicationInfo?.startDate?new Date(e.publicationInfo.startDate.year,e.publicationInfo.startDate.month,e.publicationInfo.startDate.day):null},entryInfo:e.entryInfo?{startIssue:M(e.entryInfo.startIssue),startVolume:M(e.entryInfo.startVolume)}:null,source:{resource:t,documentUrl:e.sourceDocument?`https://ochre.lib.uchicago.edu/ochre?uuid=${e.sourceDocument.uuid}&load`:null},periods:e.periods?q(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],authors:e.authors?V(Array.isArray(e.authors.person)?e.authors.person:[e.authors.person]):[],properties:e.properties?K(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function J(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?z(e.context):null,availability:e.availability?B(e.availability):null,identification:L(e.identification),date:e.date?new Date(e.date):null,creators:e.creators?V(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],description:e.description?typeof e.description==`string`||typeof e.description==`number`||typeof e.description==`boolean`?M(e.description):F(e.description):``,notes:e.notes?W(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?H(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,t,n){if(typeof e.items==`string`)throw TypeError(`Invalid OCHRE data: Tree has no items`);let r=[];e.creators&&(r=V(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]));let i=null;e.date!=null&&(i=new Date(e.date));let a=n??I(Object.keys(e.items)),o=[];switch(a){case`resource`:if(!(`resource`in e.items))throw Error(`Invalid OCHRE data: Tree has no resources`);o=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: Tree has no spatial units`);o=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: Tree has no concepts`);o=Te(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept]);break;case`period`:if(!(`period`in e.items))throw Error(`Invalid OCHRE data: Tree has no periods`);o=q(Array.isArray(e.items.period)?e.items.period:[e.items.period]);break;case`bibliography`:if(!(`bibliography`in e.items))throw Error(`Invalid OCHRE data: Tree has no bibliographies`);o=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: Tree has no persons`);o=V(Array.isArray(e.items.person)?e.items.person:[e.items.person]);break;case`propertyValue`:if(!(`propertyValue`in e.items))throw Error(`Invalid OCHRE data: Tree has no property values`);o=_e(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]);break;case`set`:{if(!(`set`in e.items))throw Error(`Invalid OCHRE data: Tree has no sets`);let t=[];for(let r of Array.isArray(e.items.set)?e.items.set:[e.items.set])t.push(ye(r,n));o=t;break}default:throw Error(`Invalid OCHRE data: Tree has no items or is malformed`)}let s={uuid:e.uuid,category:`tree`,publicationDateTime:new Date(e.publicationDateTime),identification:L(e.identification),creators:r,license:B(e.availability),date:i,type:e.type,number:e.n,items:o,properties:e.properties?K(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return s}function ye(e,t){if(typeof e.items==`string`)throw TypeError(`Invalid OCHRE data: Set has no items`);let n=t??I(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=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=Te(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=q(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=V(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:B(e.availability),identification:L(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?M(e.description):F(e.description):``,creators:e.creators?V(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,fileFormat:e.fileFormat??null,fileSize:e.fileSize??null,context:`context`in e&&e.context?z(e.context):null,license:`availability`in e&&e.availability?B(e.availability):null,copyright:`copyright`in e&&e.copyright!=null?M(e.copyright):null,identification:L(e.identification),date:e.date==null?null:new Date(e.date),image:e.image?se(e.image):null,creators:e.creators?V(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],notes:e.notes?W(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?M(e.description):F(e.description):``,coordinates:e.coordinates?G(e.coordinates):[],document:e.document&&`content`in e.document?U(e.document.content):null,href:e.href??null,imageMap:e.imagemap?pe(e.imagemap):null,periods:e.periods?q(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],links:e.links?H(Array.isArray(e.links)?e.links:[e.links]):[],reverseLinks:e.reverseLinks?H(Array.isArray(e.reverseLinks)?e.reverseLinks:[e.reverseLinks]):[],properties:e.properties?K(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],bibliographies:e.bibliographies?J(Array.isArray(e.bibliographies.bibliography)?e.bibliographies.bibliography:[e.bibliographies.bibliography]):[],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(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?z(e.context):null,license:`availability`in e&&e.availability?B(e.availability):null,identification:L(e.identification),image:e.image?se(e.image):null,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?M(e.description):F(e.description):``,coordinates:G(e.coordinates),mapData:e.mapData??null,observations:`observations`in e&&e.observations?le(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[ce(e.observation)]:[],events:`events`in e&&e.events?ue(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:`properties`in e&&e.properties?K(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?B(e.availability):null,context:`context`in e&&e.context?z(e.context):null,identification:L(e.identification),interpretations:e.interpretations?fe(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation]):[],properties:e.properties?K(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return t}const we=async(e,t)=>{let n=[];for(let r of e){let e=r.properties?K(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 X(r);n.push(e);break}case`page`:{let e=await Oe(r);e&&n.push(e);break}case`block`:{let e=await Z(r);e&&n.push(e);break}}}return n};function Te(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(Ce(e));return t}async function Ee(e,t){let n=e.values[0].content,{data:r}=d.safeParse(n),i={component:r},a=t.links?H(Array.isArray(t.links)?t.links:[t.links]):[],o=a.filter(e=>e.type===`image`||e.type===`IIIF`);switch(r){case`annotated-document`:{let e=a.find(e=>e.type===`internalDocument`);if(!e)throw Error(`Document link not found for the following component: “${r}”`);i.documentId=e.uuid;break}case`annotated-image`:{if(o.length===0)throw Error(`Image link not found for the following component: “${r}”`);let t=w(e.properties,`filter-displayed`)===!0;i.imageUuid=o[0].uuid,i.isFilterDisplayed=t;break}case`audio-player`:{let t=a.find(e=>e.type===`audio`);if(!t)throw Error(`Audio link not found for the following component: “${r}”`);let n=!1,o=w(e.properties,`speed-controls-displayed`);o!==null&&(n=o===!0);let s=!1,c=w(e.properties,`volume-controls-displayed`);c!==null&&(s=c===!0);let l=!1,u=w(e.properties,`seek-bar-displayed`);u!==null&&(l=u===!0),i.audioId=t.uuid,i.isSpeedControlsDisplayed=n,i.isVolumeControlsDisplayed=s,i.isSeekBarDisplayed=l;break}case`bibliography`:{let t=a.find(e=>e.category===`bibliography`);if(!t)throw Error(`Bibliography link not found for the following component: “${r}”`);if(!t.bibliographies)throw Error(`Bibliography not found for the following component: “${r}”`);let n=w(e.properties,`layout`);n??=`long`,i.bibliographies=t.bibliographies,i.layout=n;break}case`button`:{let n=w(e.properties,`variant`);n??=`default`;let a=!1,o=S(e.properties,`navigate-to`),s=o?.values[0]?.href??o?.values[0]?.slug??null;if(s===null){let t=S(e.properties,`link-to`);if(s=t?.values[0]?.href??t?.values[0]?.slug??null,s===null)throw Error(`Properties “navigate-to” or “link-to” not found for the following component: “${r}”`);a=!0}let c=null,l=w(e.properties,`start-icon`);l!==null&&(c=l);let u=null,d=w(e.properties,`end-icon`);d!==null&&(u=d),i.variant=n,i.href=s,i.isExternal=a,i.label=[`string`,`number`,`boolean`].includes(typeof t.identification.label)?M(t.identification.label):F(t.identification.label),i.startIcon=c,i.endIcon=u;break}case`collection`:{let t=a.find(e=>e.category===`set`);if(!t)throw Error(`Collection link not found for the following component: “${r}”`);let n=w(e.properties,`variant`);n??=`full`;let o=w(e.properties,`item-variant`);o??=`detailed`;let s=w(e.properties,`pagination-variant`);s??=`default`;let c=!1,l=w(e.properties,`filter-displayed`);l!==null&&(c=l===!0);let u=w(e.properties,`layout`);u??=`image-start`,i.collectionId=t.uuid,i.variant=n,i.itemVariant=o,i.paginationVariant=s,i.isFilterDisplayed=c,i.layout=u;break}case`empty-space`:{let t=w(e.properties,`height`),n=w(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: “${r}”`);let n=w(e.properties,`variant`);n??=`entry`;let o=!1,s=w(e.properties,`filter-displayed`);s!==null&&(o=s===!0),i.entriesId=t.uuid,i.variant=n,i.isFilterDisplayed=o;break}case`iframe`:{let t=a.find(e=>e.type===`webpage`)?.href;if(!t)throw Error(`URL not found for the following component: “${r}”`);let n=w(e.properties,`height`),o=w(e.properties,`width`);i.href=t,i.height=n,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: “${r}”`);i.IIIFId=e.uuid;break}case`image`:{if(o.length===0)throw Error(`Image link not found for the following component: “${r}”`);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,description:e.description??null});let n=w(e.properties,`variant`);n??=`default`;let a=w(e.properties,`layout-caption`);a??=`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}}i.images=t,i.variant=n,i.width=s,i.height=l,i.isFullWidth=d,i.isFullHeight=p,i.imageQuality=h,i.captionLayout=a,i.captionSource=g,i.altTextSource=_,i.isTransparentBackground=v,i.isCover=b,i.carouselOptions=C;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: “${r}”`);let n=w(e.properties,`filter-displayed`)===!0;i.galleryId=t.uuid,i.isFilterDisplayed=n;break}case`map`:{let t=a.find(e=>e.category===`set`||e.category===`tree`);if(!t)throw Error(`Map link not found for the following component: “${r}”`);let n=!0,o=w(e.properties,`is-interactive`);o!==null&&(n=o===!0);let s=!1,c=w(e.properties,`is-clustered`);c!==null&&(s=c===!0);let l=!1,u=w(e.properties,`is-using-pins`);u!==null&&(l=u===!0);let d=null,f=w(e.properties,`custom-basemap`);f!==null&&(d=f);let p=!1,m=w(e.properties,`controls-displayed`);m!==null&&(p=m===!0);let h=!1,g=w(e.properties,`is-full-height`);g!==null&&(h=g===!0),i.mapId=t.uuid,i.isInteractive=n,i.isClustered=s,i.isUsingPins=l,i.customBasemap=d,i.isControlsDisplayed=p,i.isFullHeight=h;break}case`network-graph`:break;case`query`:{let t=[],n=e.properties;if(n.length===0)throw Error(`Query properties not found for the following component: “${r}”`);for(let e of n){let n=e.properties,i=w(n,`query-prompt`);if(i===null)throw Error(`Query prompt not found for the following component: “${r}”`);let a=n.find(e=>e.label===`use-property`)?.values.map(e=>e.uuid).filter(e=>e!==null)??[],o=w(n,`start-icon`),s=w(n,`end-icon`);t.push({label:String(i),propertyUuids:a,startIcon:o===null?null:String(o),endIcon:s===null?null:String(s)})}i.queries=t;break}case`table`:{let e=a.find(e=>e.category===`set`);if(!e)throw Error(`Table link not found for the following component: “${r}”`);i.tableId=e.uuid;break}case`search-bar`:{let t=w(e.properties,`variant`);t??=`default`;let n=w(e.properties,`placeholder-text`);i.variant=t,i.placeholder=n===null?null:String(n);break}case`text`:{let n=t.document&&`content`in t.document?U(t.document.content):null;if(!n)throw Error(`Content not found for the following component: “${r}”`);let a=w(e.properties,`variant`);a??=`block`;let o=w(e.properties,`heading`);i.variant=a,i.heading=o,i.content=n;break}case`timeline`:{let e=a.find(e=>e.category===`tree`);if(!e)throw Error(`Timeline link not found for the following component: “${r}”`);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: “${r}”`);let n=w(e.properties,`chapters-displayed`);n??=!0,i.videoId=t.uuid,i.isChaptersDislayed=n===!0;break}default:console.warn(`Invalid or non-implemented component name “${String(n)}” for the following element: “${F(t.identification.label)}”`);break}return i}function De(e,t,n={}){let r=e.find(e=>e.label===`presentation`&&e.values[0].content===`title`)?.properties,i=`default`,a=n.isNameDisplayed??!1,o=!1,s=!1,c=!1,l=n.isCountDisplayed??!1;if(r){let e=w(r,`variant`);e&&(i=e),a=w(r,`name-displayed`)===!0,o=w(r,`description-displayed`)===!0,s=w(r,`date-displayed`)===!0,c=w(r,`creators-displayed`)===!0,l=w(r,`count-displayed`)===!0}return{label:t.label,variant:i,properties:{isNameDisplayed:a,isDescriptionDisplayed:o,isDateDisplayed:s,isCreatorsDisplayed:c,isCountDisplayed:l}}}async function X(e){let t=L(e.identification),n=e.properties?.property?K(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 Ee(i,e),o=r.properties.find(e=>e.label===`section-sidebar-displayed`),s=o?.values[0]?.content===!0,c=e.properties?.property?K(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=De(c,t,{isNameDisplayed:a.component===`collection`,isCountDisplayed:a.component===`collection`&&a.variant===`full`});return{uuid:e.uuid,type:`element`,title:p,isDisplayedInBlockSectionSidebar:s,cssStyles:u,cssStylesMobile:f,...a}}async function Oe(e){let t=e.properties?K(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=L(e.identification),r=e.slug;if(r===void 0)throw Error(`Slug not found for page “${n.label}”`);let i=e.links?H(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?K(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 X(e);s.push(t);break}case`block`:{let t=await Z(e);t&&s.push(t);break}}}let c=e.resource?await we(Array.isArray(e.resource)?e.resource:[e.resource],`page`):[],l=!0,u=`default`,d=`default`,f=!0,p=!1,m=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`page`)?.properties;if(m){let e=m.find(e=>e.label===`header`)?.values[0];e&&(l=e.content===!0);let t=m.find(e=>e.label===`width`)?.values[0];t&&(u=t.content);let n=m.find(e=>e.label===`variant`)?.values[0];n&&(d=n.content);let r=m.find(e=>e.label===`sidebar-visible`)?.values[0];r&&(f=r.content===!0);let i=m.find(e=>e.label===`breadcrumbs-visible`)?.values[0];i&&(p=i.content===!0)}let h=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css`)?.properties,g=[];if(h)for(let e of h)g.push({label:e.label,value:e.values[0].content});let _=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css-mobile`)?.properties,v=[];if(_)for(let e of _)v.push({label:e.label,value:e.values[0].content});return{title:n.label,slug:r,items:s,properties:{displayedInHeader:l,width:u,variant:d,backgroundImageUrl:a?`https://ochre.lib.uchicago.edu/ochre?uuid=${a.uuid}&load`:null,isSidebarDisplayed:f,isBreadcrumbsDisplayed:p,cssStyles:g,cssStylesMobile:v},webpages:c}}async function ke(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n){let n=await Oe(e);n&&t.push(n)}return t}async function Z(e){let t=e.properties?K(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n={uuid:e.uuid,type:`block`,layout:`vertical`,title:De(t,L(e.identification)),items:[],properties:{spacing:void 0,gap:void 0,alignItems:`start`,justifyContent:`stretch`,sectionSidebarItems:null},propertiesMobile:null,cssStyles:[],cssStylesMobile:[]},r=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`block`)?.properties;if(r){let e=r.find(e=>e.label===`layout`)?.values[0];e&&(n.layout=e.content);let t=r.find(e=>e.label===`spacing`)?.values[0];t&&(n.properties.spacing=t.content);let i=r.find(e=>e.label===`gap`)?.values[0];i&&(n.properties.gap=i.content);let a=r.find(e=>e.label===`align-items`)?.values[0];a&&(n.properties.alignItems=a.content);let o=r.find(e=>e.label===`justify-content`)?.values[0];o&&(n.properties.justifyContent=o.content);let s=r.find(e=>e.label===`overwrite-mobile`);if(s){let e=s.properties,t={};for(let n of e)t[n.label]=n.values[0].content;n.propertiesMobile=t}}let i=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],a=[];for(let e of i){let t=e.properties?K(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 X(e);a.push(t);break}case`block`:{let t=await Z(e);t&&a.push(t);break}}}n.items=a;let o=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css`)?.properties;if(o)for(let e of o)n.cssStyles.push({label:e.label,value:e.values[0].content});let s=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css-mobile`)?.properties;if(s)for(let e of s)n.cssStylesMobile.push({label:e.label,value:e.values[0].content});return n.properties.sectionSidebarItems=Ae(n),n}function Ae(e){let t=[];for(let n of e.items)switch(n.type){case`block`:{let e=Ae(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 je(e){let t=K(e),n=t.find(e=>e.label===`presentation`)?.properties;if(!n)throw Error(`Presentation property not found`);let r=n.find(e=>e.label===`webUI`)?.values[0]?.content;r??=`traditional`;let i=n.find(e=>e.label===`status`)?.values[0]?.content;i??=`development`;let a=n.find(e=>e.label===`privacy`)?.values[0]?.content;a??=`public`;let o=u.safeParse({type:r,status:i,privacy:a});if(!o.success)throw Error(`Invalid website properties: ${o.error.message}`);let s=null,c=n.find(e=>e.label===`contact`);if(c){let[e,t]=(c.values[0]?.content).split(`;`);s={name:e,email:t??null}}let l=n.find(e=>e.label===`logo`)?.values[0]?.uuid??null,d=!0,f=`default`,p=`start`,m=!0,h=!0,g=!1,_=!0,v=null,y=n.find(e=>e.label===`navbar-visible`)?.values[0];y&&(d=y.content===!0);let b=n.find(e=>e.label===`navbar-variant`)?.values[0];b&&(f=b.content);let x=n.find(e=>e.label===`navbar-alignment`)?.values[0];x&&(p=x.content);let S=n.find(e=>e.label===`navbar-project-visible`)?.values[0];S&&(m=S.content===!0);let C=n.find(e=>e.label===`footer-visible`)?.values[0];C&&(h=C.content===!0);let w=n.find(e=>e.label===`sidebar-visible`)?.values[0];w&&(g=w.content===!0);let T=n.find(e=>e.label===`supports-theme-toggle`)?.values[0];T&&(_=T.content===!0);let E=n.find(e=>e.label===`default-theme`)?.values[0];E&&(v=E.content);let{type:D,status:O,privacy:k}=o.data;return{type:D,privacy:k,status:O,contact:s,isHeaderDisplayed:d,headerVariant:f,headerAlignment:p,isHeaderProjectDisplayed:m,isFooterDisplayed:h,isSidebarDisplayed:g,supportsThemeToggle:_,defaultTheme:v,logoUrl:l===null?null:`https://ochre.lib.uchicago.edu/ochre?uuid=${l}&load`}}function Q(e){let t=[];for(let n of e){let e=Array.isArray(n.context)?n.context:[n.context];for(let n of e){let e=Array.isArray(n.levels.level)?n.levels.level:[n.levels.level],r=``,i=e.map(e=>{let t=``,n=null;if(typeof e==`string`){let r=e.split(`, `);t=r[0],n=r[1]===`null`?null:r[1]}else{let i=e.content.split(`, `);r=e.dataType,t=i[0],n=i[1]===`null`?null:i[1]}return{variableUuid:t,valueUuid:n}});t.push({context:i,type:r,identification:L(n.identification)})}}return t}async function Me(e,t,n){if(!e.properties)throw Error(`Website properties not found`);let r=je(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 ke(i),o=null,s=[],c={label:``,variant:`default`,properties:{isNameDisplayed:!1,isDescriptionDisplayed:!1,isDateDisplayed:!1,isCreatorsDisplayed:!1,isCountDisplayed:!1}},l=`start`,u=`default`,d=[],f=[],p=i.find(e=>{let t=e.properties?K(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];return t.some(e=>e.label===`presentation`&&e.values[0]?.content===`element`&&e.properties[0]?.label===`component`&&e.properties[0].values[0]?.content===`sidebar`)});if(p){c.label=typeof p.identification.label==`string`||typeof p.identification.label==`number`||typeof p.identification.label==`boolean`?M(p.identification.label):F(p.identification.label);let e=p.properties?K(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),c.properties.isNameDisplayed=w(o,`name-displayed`)===!0,c.properties.isDescriptionDisplayed=w(o,`description-displayed`)===!0,c.properties.isDateDisplayed=w(o,`date-displayed`)===!0,c.properties.isCreatorsDisplayed=w(o,`creators-displayed`)===!0,c.properties.isCountDisplayed=w(o,`count-displayed`)===!0}let m=p.resource?Array.isArray(p.resource)?p.resource:[p.resource]:[];for(let e of m){let t=await X(e);s.push(t)}}s.length>0&&(o={elements:s,title:c,layout:l,mobileLayout:u,cssStyles:d,cssStylesMobile:f});let m={contexts:{flatten:[],filter:[],detail:[],download:[],label:[],suppress:[]}};if(e.websiteOptions){let t=e.websiteOptions.flattenContexts==null?[]:Array.isArray(e.websiteOptions.flattenContexts)?e.websiteOptions.flattenContexts:[e.websiteOptions.flattenContexts],n=e.websiteOptions.suppressContexts==null?[]:Array.isArray(e.websiteOptions.suppressContexts)?e.websiteOptions.suppressContexts:[e.websiteOptions.suppressContexts],r=e.websiteOptions.filterContexts==null?[]:Array.isArray(e.websiteOptions.filterContexts)?e.websiteOptions.filterContexts:[e.websiteOptions.filterContexts],i=e.websiteOptions.detailContexts==null?[]:Array.isArray(e.websiteOptions.detailContexts)?e.websiteOptions.detailContexts:[e.websiteOptions.detailContexts],a=e.websiteOptions.downloadContexts==null?[]:Array.isArray(e.websiteOptions.downloadContexts)?e.websiteOptions.downloadContexts:[e.websiteOptions.downloadContexts],o=e.websiteOptions.labelContexts==null?[]:Array.isArray(e.websiteOptions.labelContexts)?e.websiteOptions.labelContexts:[e.websiteOptions.labelContexts];m={contexts:{flatten:Q(t),filter:Q(r),detail:Q(i),download:Q(a),label:Q(o),suppress:Q(n)}}}return{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:L(e.identification),project:{name:M(t),website:n===null?null:M(n)},creators:e.creators?V(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:B(e.availability),pages:a,sidebar:o,properties:r,searchOptions:{filters:e.searchOptions?.filterUuids==null?[]:(Array.isArray(e.searchOptions.filterUuids.uuid)?e.searchOptions.filterUuids.uuid:[e.searchOptions.filterUuids.uuid]).map(e=>({uuid:e.content,type:e.type})),scopes:e.searchOptions?.scopes==null?[]:(Array.isArray(e.searchOptions.scopes.scope)?e.searchOptions.scopes.scope:[e.searchOptions.scopes.scope]).map(e=>({uuid:e.uuid.content,type:e.uuid.type,identification:L(e.identification)}))},globalOptions:m}}async function Ne(e,t,n,r,i){try{let{uuid:a,filter:o,page:s,perPage:c}=m.parse({uuid:e,filter:t,page:n,perPage:r}),l=await(i??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
3
3
  for $q in input()/ochre[@uuid='${a}']
4
4
  let $filtered := $q//items/resource[contains(lower-case(identification/label), lower-case('${o}'))]
5
5
  let $maxLength := count($filtered)
@@ -8,9 +8,9 @@ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=
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=L(u.result.gallery.item.identification),f=L(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 Ne(e,t){try{let n=l.parse(e),r=await(t??fetch)(`https://ochre.lib.uchicago.edu/ochre?uuid=${n}&format=json&lang="*"`);if(!r.ok)throw Error(`Failed to fetch OCHRE data`);let i=await r.json();if(!(`ochre`in i))throw Error(`Invalid OCHRE data: API response missing 'ochre' key`);return[null,i]}catch(e){return[e instanceof Error?e.message:`Unknown error`,null]}}async function Pe(e,t,n,r){try{let[i,a]=await Ne(e,r);if(i!==null)throw Error(i);let o=I(Object.keys(a.ochre)),s;switch(o){case`resource`:if(!(`resource`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'resource' key`);s=be(a.ochre.resource);break;case`spatialUnit`:if(!(`spatialUnit`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'spatialUnit' key`);s=xe(a.ochre.spatialUnit);break;case`concept`:if(!(`concept`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'concept' key`);s=Ce(a.ochre.concept);break;case`period`:if(!(`period`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'period' key`);s=me(a.ochre.period);break;case`bibliography`:if(!(`bibliography`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'bibliography' key`);s=he(a.ochre.bibliography);break;case`person`:if(!(`person`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'person' key`);s=ae(a.ochre.person);break;case`propertyValue`:if(!(`propertyValue`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'propertyValue' key`);s=ge(a.ochre.propertyValue);break;case`set`:if(!(`set`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'set' key`);s=ye(a.ochre.set,n);break;case`tree`:if(!(`tree`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'tree' key`);s=ve(a.ochre.tree,t,n);break;default:throw Error(`Invalid category`)}let c=ie(a.ochre.metadata),l={uuid:a.ochre.uuidBelongsTo,abbreviation:M(a.ochre.belongsTo)};return{error:null,metadata:c,belongsTo:l,item:s,category:t}}catch(e){return{error:e instanceof Error?e.message:`Unknown error`,metadata:void 0,belongsTo:void 0,item:void 0,category:void 0}}}const Fe=`0c0aae37-7246-495b-9547-e25dbf5b99a3`,Ie=`30054cb2-909a-4f34-8db9-8fe7369d691d`,Le=`e28e29af-b663-c0ac-ceb6-11a688fca0dd`;function $(e){let t=/^[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}$/i;return t.test(e)}const Re=c.z.object({property:c.z.string().refine($),category:c.z.object({uuid:c.z.string().refine($),content:c.z.string()}),value:c.z.object({uuid:c.z.string().refine($).optional(),category:c.z.string().optional(),type:c.z.string().optional(),dataType:c.z.string(),publicationDateTime:c.z.iso.datetime().optional(),content:c.z.string().optional(),rawValue:c.z.string().optional()})}),ze=c.z.object({result:c.z.object({item:c.z.union([Re,c.z.array(Re)])})});function Be(e,t){let n=``;if(e.length>0){let t=e.map(e=>`@uuid="${e}"`).join(` or `);n=`[properties/property[label/@uuid="${Ie}"][value[${t}]]]`}let r=t.map(e=>`@uuid="${e}"`).join(` or `),i=`for $q in input()/ochre[@uuidBelongsTo="${Fe}"]/*${n}/properties//property[label[${r}]]
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=L(u.result.gallery.item.identification),f=L(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 Pe(e,t){try{let n=l.parse(e),r=await(t??fetch)(`https://ochre.lib.uchicago.edu/ochre?uuid=${n}&format=json&lang="*"`);if(!r.ok)throw Error(`Failed to fetch OCHRE data`);let i=await r.json();if(!(`ochre`in i))throw Error(`Invalid OCHRE data: API response missing 'ochre' key`);return[null,i]}catch(e){return[e instanceof Error?e.message:`Unknown error`,null]}}async function Fe(e,t,n,r){try{let[i,a]=await Pe(e,r);if(i!==null)throw Error(i);let o=I(Object.keys(a.ochre)),s;switch(o){case`resource`:if(!(`resource`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'resource' key`);s=be(a.ochre.resource);break;case`spatialUnit`:if(!(`spatialUnit`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'spatialUnit' key`);s=xe(a.ochre.spatialUnit);break;case`concept`:if(!(`concept`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'concept' key`);s=Ce(a.ochre.concept);break;case`period`:if(!(`period`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'period' key`);s=me(a.ochre.period);break;case`bibliography`:if(!(`bibliography`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'bibliography' key`);s=he(a.ochre.bibliography);break;case`person`:if(!(`person`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'person' key`);s=ae(a.ochre.person);break;case`propertyValue`:if(!(`propertyValue`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'propertyValue' key`);s=ge(a.ochre.propertyValue);break;case`set`:if(!(`set`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'set' key`);s=ye(a.ochre.set,n);break;case`tree`:if(!(`tree`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'tree' key`);s=ve(a.ochre.tree,t,n);break;default:throw Error(`Invalid category`)}let c=ie(a.ochre.metadata),l={uuid:a.ochre.uuidBelongsTo,abbreviation:M(a.ochre.belongsTo)};return{error:null,metadata:c,belongsTo:l,item:s,category:t}}catch(e){return{error:e instanceof Error?e.message:`Unknown error`,metadata:void 0,belongsTo:void 0,item:void 0,category:void 0}}}const Ie=`0c0aae37-7246-495b-9547-e25dbf5b99a3`,Le=`30054cb2-909a-4f34-8db9-8fe7369d691d`,Re=`e28e29af-b663-c0ac-ceb6-11a688fca0dd`;function $(e){let t=/^[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}$/i;return t.test(e)}const ze=c.z.object({property:c.z.string().refine($),category:c.z.object({uuid:c.z.string().refine($),content:c.z.string()}),value:c.z.object({uuid:c.z.string().refine($).optional(),category:c.z.string().optional(),type:c.z.string().optional(),dataType:c.z.string(),publicationDateTime:c.z.iso.datetime().optional(),content:c.z.string().optional(),rawValue:c.z.string().optional()})}),Be=c.z.object({result:c.z.object({item:c.z.union([ze,c.z.array(ze)])})});function Ve(e,t){let n=``;if(e.length>0){let t=e.map(e=>`@uuid="${e}"`).join(` or `);n=`[properties/property[label/@uuid="${Le}"][value[${t}]]]`}let r=t.map(e=>`@uuid="${e}"`).join(` or `),i=`for $q in input()/ochre[@uuidBelongsTo="${Ie}"]/*${n}/properties//property[label[${r}]]
12
12
  return <item>
13
13
  <property>{xs:string($q/label/@uuid)}</property> {$q/*[2]}
14
14
  <value>{$q/*[2]/@*} {$q/*[2]/content[1]/string/text()}</value>
15
15
  <category> {$q/ancestor::node()[local-name(.)="properties"]/../@uuid} {local-name($q/ancestor::node()[local-name(.)="properties"]/../self::node())} </category>
16
- </item>`;return i}async function Ve(e,t,n){try{let r=Be(e,t),i=await(n??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(r)}&format=json`);if(!i.ok)throw Error(`OCHRE API responded with status: ${i.status}`);let a=await i.json(),o=ze.parse(a),s=Array.isArray(o.result.item)?o.result.item:[o.result.item],c={};for(let e of s){let t=e.category.uuid,n=e.value.uuid,r=e.value.content??e.value.rawValue??``;r in c?c[r].resultUuids.push(t):c[r]={value:{uuid:n??Le,category:e.value.category??null,type:e.value.type??null,dataType:e.value.dataType,publicationDateTime:e.value.publicationDateTime??null,content:e.value.content??e.value.rawValue??``,label:e.value.rawValue!=null&&e.value.content!=null?e.value.content:null},resultUuids:[t]}}let l=Object.values(c).filter(e=>e.value.uuid!==Le).toSorted((e,t)=>{let n=e.value.label??e.value.content,r=t.value.label??t.value.content;return n.localeCompare(r,`en-US`)});return{items:l,error:null}}catch(e){return console.error(e),{items:null,error:e instanceof Error?e.message:`Failed to fetch property query`}}}async function He(e,t){try{let n=l.parse(e),r=await(t??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`for $q in input()/ochre[@uuid='${n}']/metadata return ($q/item, $q/project)`)}&format=json`);if(!r.ok)throw Error(`Failed to fetch metadata`);let i=await r.json(),a=L(i.result.project.identification),o={...a,website:i.result.project.identification.website??null},s={item:{uuid:e,name:L(i.result.item.identification).label,type:i.result.item.type},project:{name:o.label,website:o.website??null}};return{item:s,error:null}}catch(e){return{item:null,error:e instanceof Error?e.message:`Unknown error`}}}async function Ue(e,t){try{let n=await(t??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(!n.ok)throw Error(`Failed to fetch website`);let r=await n.json();if(!(`ochre`in r.result)||!(`tree`in r.result.ochre))throw Error(`Failed to fetch website`);let i=r.result.ochre.metadata.project?.identification?L(r.result.ochre.metadata.project.identification):null,a=await je(r.result.ochre.tree,i?.label??``,r.result.ochre.metadata.project?.identification.website??null);return[null,a]}catch(e){return console.error(e),[e instanceof Error?e.message:`Unknown error`,null]}}exports.fetchByUuidMetadata=He,exports.fetchGallery=Me,exports.fetchItem=Pe,exports.fetchPropertyQuery=Ve,exports.fetchWebsite=Ue,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;
16
+ </item>`;return i}async function He(e,t,n){try{let r=Ve(e,t),i=await(n??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(r)}&format=json`);if(!i.ok)throw Error(`OCHRE API responded with status: ${i.status}`);let a=await i.json(),o=Be.parse(a),s=Array.isArray(o.result.item)?o.result.item:[o.result.item],c={};for(let e of s){let t=e.category.uuid,n=e.value.uuid,r=e.value.content??e.value.rawValue??``;r in c?c[r].resultUuids.push(t):c[r]={value:{uuid:n??Re,category:e.value.category??null,type:e.value.type??null,dataType:e.value.dataType,publicationDateTime:e.value.publicationDateTime??null,content:e.value.content??e.value.rawValue??``,label:e.value.rawValue!=null&&e.value.content!=null?e.value.content:null},resultUuids:[t]}}let l=Object.values(c).filter(e=>e.value.uuid!==Re).toSorted((e,t)=>{let n=e.value.label??e.value.content,r=t.value.label??t.value.content;return n.localeCompare(r,`en-US`)});return{items:l,error:null}}catch(e){return console.error(e),{items:null,error:e instanceof Error?e.message:`Failed to fetch property query`}}}async function Ue(e,t){try{let n=l.parse(e),r=await(t??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`for $q in input()/ochre[@uuid='${n}']/metadata return ($q/item, $q/project)`)}&format=json`);if(!r.ok)throw Error(`Failed to fetch metadata`);let i=await r.json(),a=L(i.result.project.identification),o={...a,website:i.result.project.identification.website??null},s={item:{uuid:e,name:L(i.result.item.identification).label,type:i.result.item.type},project:{name:o.label,website:o.website??null}};return{item:s,error:null}}catch(e){return{item:null,error:e instanceof Error?e.message:`Unknown error`}}}async function We(e,t){try{let n=await(t??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(!n.ok)throw Error(`Failed to fetch website`);let r=await n.json();if(!(`ochre`in r.result)||!(`tree`in r.result.ochre))throw Error(`Failed to fetch website`);let i=r.result.ochre.metadata.project?.identification?L(r.result.ochre.metadata.project.identification):null,a=await Me(r.result.ochre.tree,i?.label??``,r.result.ochre.metadata.project?.identification.website??null);return[null,a]}catch(e){return console.error(e),[e instanceof Error?e.message:`Unknown error`,null]}}exports.fetchByUuidMetadata=Ue,exports.fetchGallery=Ne,exports.fetchItem=Fe,exports.fetchPropertyQuery=He,exports.fetchWebsite=We,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
@@ -417,6 +417,8 @@ type PropertyValueContent<T extends PropertyValueContentType> = {
417
417
  type: string | null;
418
418
  uuid: string | null;
419
419
  publicationDateTime: Date | null;
420
+ href: string | null;
421
+ slug: string | null;
420
422
  };
421
423
  /**
422
424
  * Represents a property with label, values and nested properties
@@ -583,23 +585,24 @@ type WebpageProperties = {
583
585
  cssStyles: Array<Style>;
584
586
  cssStylesMobile: Array<Style>;
585
587
  };
588
+ type WebTitle = {
589
+ label: string;
590
+ variant: "default" | "simple";
591
+ properties: {
592
+ isNameDisplayed: boolean;
593
+ isDescriptionDisplayed: boolean;
594
+ isDateDisplayed: boolean;
595
+ isCreatorsDisplayed: boolean;
596
+ isCountDisplayed: boolean;
597
+ };
598
+ };
586
599
  /**
587
600
  * Base properties for web elements
588
601
  */
589
602
  type WebElement = {
590
603
  uuid: string;
591
604
  type: "element";
592
- title: {
593
- label: string;
594
- variant: "default" | "simple";
595
- properties: {
596
- isNameDisplayed: boolean;
597
- isDescriptionDisplayed: boolean;
598
- isDateDisplayed: boolean;
599
- isCreatorsDisplayed: boolean;
600
- isCountDisplayed: boolean;
601
- };
602
- };
605
+ title: WebTitle;
603
606
  isDisplayedInBlockSectionSidebar: boolean;
604
607
  cssStyles: Array<Style>;
605
608
  cssStylesMobile: Array<Style>;
@@ -740,6 +743,7 @@ type WebBlock = {
740
743
  uuid: string;
741
744
  type: "block";
742
745
  layout: "vertical" | "horizontal" | "grid";
746
+ title: WebTitle;
743
747
  items: Array<WebElement | WebBlock>;
744
748
  properties: {
745
749
  /**
@@ -1110,4 +1114,4 @@ declare function filterProperties(property: Property, filter: {
1110
1114
  value: string | number | boolean | Date;
1111
1115
  }, options?: PropertyOptions): boolean;
1112
1116
  //#endregion
1113
- export { Bibliography, Concept, Context, ContextItem, ContextNode, Coordinates, CoordinatesItem, Data, DataCategory, Event, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, LevelContext, LevelContextItem, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyQueryItem, PropertyValue, PropertyValueContent, PropertyValueContentType, Resource, Set, SpatialUnit, Style, Tree, UuidMetadata, WebBlock, WebElement, WebElementComponent, WebImage, WebSectionSidebarItem, Webpage, WebpageProperties, Website, WebsiteProperties, fetchByUuidMetadata, fetchGallery, fetchItem, fetchPropertyQuery, fetchWebsite, filterProperties, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
1117
+ export { Bibliography, Concept, Context, ContextItem, ContextNode, Coordinates, CoordinatesItem, Data, DataCategory, Event, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, LevelContext, LevelContextItem, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyQueryItem, PropertyValue, PropertyValueContent, PropertyValueContentType, Resource, Set, SpatialUnit, Style, Tree, UuidMetadata, WebBlock, WebElement, WebElementComponent, WebImage, WebSectionSidebarItem, WebTitle, Webpage, WebpageProperties, Website, WebsiteProperties, fetchByUuidMetadata, fetchGallery, fetchItem, fetchPropertyQuery, fetchWebsite, filterProperties, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
package/dist/index.d.ts CHANGED
@@ -417,6 +417,8 @@ type PropertyValueContent<T extends PropertyValueContentType> = {
417
417
  type: string | null;
418
418
  uuid: string | null;
419
419
  publicationDateTime: Date | null;
420
+ href: string | null;
421
+ slug: string | null;
420
422
  };
421
423
  /**
422
424
  * Represents a property with label, values and nested properties
@@ -583,23 +585,24 @@ type WebpageProperties = {
583
585
  cssStyles: Array<Style>;
584
586
  cssStylesMobile: Array<Style>;
585
587
  };
588
+ type WebTitle = {
589
+ label: string;
590
+ variant: "default" | "simple";
591
+ properties: {
592
+ isNameDisplayed: boolean;
593
+ isDescriptionDisplayed: boolean;
594
+ isDateDisplayed: boolean;
595
+ isCreatorsDisplayed: boolean;
596
+ isCountDisplayed: boolean;
597
+ };
598
+ };
586
599
  /**
587
600
  * Base properties for web elements
588
601
  */
589
602
  type WebElement = {
590
603
  uuid: string;
591
604
  type: "element";
592
- title: {
593
- label: string;
594
- variant: "default" | "simple";
595
- properties: {
596
- isNameDisplayed: boolean;
597
- isDescriptionDisplayed: boolean;
598
- isDateDisplayed: boolean;
599
- isCreatorsDisplayed: boolean;
600
- isCountDisplayed: boolean;
601
- };
602
- };
605
+ title: WebTitle;
603
606
  isDisplayedInBlockSectionSidebar: boolean;
604
607
  cssStyles: Array<Style>;
605
608
  cssStylesMobile: Array<Style>;
@@ -740,6 +743,7 @@ type WebBlock = {
740
743
  uuid: string;
741
744
  type: "block";
742
745
  layout: "vertical" | "horizontal" | "grid";
746
+ title: WebTitle;
743
747
  items: Array<WebElement | WebBlock>;
744
748
  properties: {
745
749
  /**
@@ -1110,4 +1114,4 @@ declare function filterProperties(property: Property, filter: {
1110
1114
  value: string | number | boolean | Date;
1111
1115
  }, options?: PropertyOptions): boolean;
1112
1116
  //#endregion
1113
- export { Bibliography, Concept, Context, ContextItem, ContextNode, Coordinates, CoordinatesItem, Data, DataCategory, Event, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, LevelContext, LevelContextItem, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyQueryItem, PropertyValue, PropertyValueContent, PropertyValueContentType, Resource, Set, SpatialUnit, Style, Tree, UuidMetadata, WebBlock, WebElement, WebElementComponent, WebImage, WebSectionSidebarItem, Webpage, WebpageProperties, Website, WebsiteProperties, fetchByUuidMetadata, fetchGallery, fetchItem, fetchPropertyQuery, fetchWebsite, filterProperties, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
1117
+ export { Bibliography, Concept, Context, ContextItem, ContextNode, Coordinates, CoordinatesItem, Data, DataCategory, Event, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, LevelContext, LevelContextItem, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyQueryItem, PropertyValue, PropertyValueContent, PropertyValueContentType, Resource, Set, SpatialUnit, Style, Tree, UuidMetadata, WebBlock, WebElement, WebElementComponent, WebImage, WebSectionSidebarItem, WebTitle, Webpage, WebpageProperties, Website, WebsiteProperties, fetchByUuidMetadata, fetchGallery, fetchItem, fetchPropertyQuery, fetchWebsite, filterProperties, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import{z as e}from"zod";const t=e.uuid({error:`Invalid UUID provided`}),n=e.object({type:e.enum([`traditional`,`digital-collection`,`plum`,`cedar`,`elm`,`maple`,`oak`,`palm`],{error:`Invalid website type`}),status:e.enum([`development`,`preview`,`production`],{error:`Invalid website status`}),privacy:e.enum([`public`,`password`,`private`],{error:`Invalid website privacy`})}),r=e.enum([`annotated-document`,`annotated-image`,`audio-player`,`bibliography`,`button`,`collection`,`empty-space`,`entries`,`iframe`,`iiif-viewer`,`image`,`image-gallery`,`map`,`network-graph`,`query`,`search-bar`,`table`,`text`,`timeline`,`video`],{error:`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({error:`Invalid UUID`}),filter:e.string().optional(),page:e.number().positive({error:`Page must be positive`}),perPage:e.number().positive({error:`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({error:`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);return!n&&r&&(n=e.properties.some(e=>y(e,t,{includeNestedProperties:!0}))),n}return!1}const b=`f1c131b6-1498-48a4-95bf-a9edae9fd518`,x=`b9ca2732-78f4-416e-b77f-dae7647e68a9`,S=`3e6f86ab-df81-45ae-8257-e2867357df56`;function C(e,t){let n=e.find(e=>e.lang===t);return n??null}function w(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 T(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 E(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 D(e){return String(e).replaceAll(`&#39;`,`'`).replaceAll(`{`,String.raw`\{`).replaceAll(`}`,String.raw`\}`)}function O(e){let t=``;switch(typeof e.string){case`string`:case`number`:case`boolean`:t=D(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+=D(e);else if(`string`in e)t+=k(e);else{let n=e.content==null?``:e.rend==null?D(e.content):T(D(e.content),e.rend),r=e.whitespace==null?n:E(n,e.whitespace);t+=r}break}default:t=``;break}return t}function k(e){if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return w(D(e));if(`whitespace`in e&&!(`content`in e)&&!(`string`in e))return e.whitespace===`newline`?`
2
- `:``;if(`links`in e){let t=``;t=typeof e.string==`object`?A(e.string):D(e.string).replaceAll(`<`,String.raw`\<`).replaceAll(`{`,String.raw`\{`);let n=Array.isArray(e.links)?e.links:[e.links];for(let r of n)if(`resource`in r){let n=Array.isArray(r.resource)?r.resource[0]:r.resource,i=null;switch(n.content!=null&&(i=D(n.content).replaceAll(`<`,String.raw`\<`).replaceAll(`{`,String.raw`\{`)),n.type){case`image`:return n.rend===`inline`?`<InlineImage uuid="${n.uuid}" ${i===null?``:`content="${i}"`} height={${n.height?.toString()??`null`}} width={${n.width?.toString()??`null`}} />`:n.publicationDateTime==null?`<TooltipSpan${i===null?``:` content="${i}"`}>${t}</TooltipSpan>`:`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`;case`internalDocument`:if(`properties`in e&&e.properties!=null){let r=Array.isArray(e.properties.property)?e.properties.property[0]:e.properties.property;if(r!=null){let e=r.label.uuid,i=typeof r.value==`object`&&`uuid`in r.value&&r.value.uuid!=null?r.value.uuid:null;if(e===b&&i===x){let e=r.property==null?null:Array.isArray(r.property)?r.property[0]:r.property;if(e!=null)return`<Annotation type="hover-card" uuid="${n.uuid}">${t}</Annotation>`}return`<InternalLink uuid="${n.uuid}" properties="${e}"${i===null?``:` value="${i}"`}>${t}</InternalLink>`}else return`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`}else return`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`;case`externalDocument`:return n.publicationDateTime==null?`<TooltipSpan${i===null?``:` content="${i}"`}>${t}</TooltipSpan>`:`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${n.uuid}&load" ${i===null?``:`content="${i}"`}>${t}</ExternalLink>`;case`webpage`:return`<ExternalLink href="${n.href}" ${i===null?``:`content="${i}"`}>${t}</ExternalLink>`;default:return``}}else if(`concept`in r){let e=Array.isArray(r.concept)?r.concept[0]:r.concept;return e.publicationDateTime==null?`<TooltipSpan>${t}</TooltipSpan>`:`<InternalLink uuid="${e.uuid}">${t}</InternalLink>`}else if(`set`in r){let e=Array.isArray(r.set)?r.set[0]:r.set;return e.publicationDateTime==null?`<TooltipSpan>${t}</TooltipSpan>`:`<InternalLink uuid="${e.uuid}">${t}</InternalLink>`}else if(`person`in r){let e=Array.isArray(r.person)?r.person[0]:r.person,n=e.identification?[`string`,`number`,`boolean`].includes(typeof e.identification.label)?D(e.identification.label):A(e.identification.label):null;return e.publicationDateTime==null?`<TooltipSpan${n===null?``:` content="${n}"`}>${t}</TooltipSpan>`:`<InternalLink uuid="${e.uuid}">${t}</InternalLink>`}else if(`bibliography`in r){let e=Array.isArray(r.bibliography)?r.bibliography[0]:r.bibliography;return e.publicationDateTime==null?`<TooltipSpan>${t}</TooltipSpan>`:`<InternalLink uuid="${e.uuid}">${t}</InternalLink>`}else if(`properties`in e&&e.properties!=null){let n=Array.isArray(e.properties.property)?e.properties.property[0]:e.properties.property;if(n!=null){let e=n.label.uuid,r=typeof n.value==`object`&&`uuid`in n.value&&n.value.uuid!=null?n.value.uuid:null;if(e===b&&r===x){let e=n.property==null?null:Array.isArray(n.property)?n.property[0]:n.property;if(e!=null){let n=typeof e.value==`object`&&`uuid`in e.value&&e.value.uuid!=null?e.value.uuid:null;if(n===S)return`<Annotation type="heading">${t}</Annotation>`}}}}}let t=``;if(`string`in e){let n=Array.isArray(e.string)?e.string:[e.string];for(let e of n)t+=k(e);return`whitespace`in e&&e.whitespace!=null&&(t=E(w(t),e.whitespace)),t.replaceAll(`&#39;`,`'`)}else t=D(e.content),e.rend!=null&&(t=T(w(t),e.rend)),e.whitespace!=null&&(t=E(w(t),e.whitespace));return t}function A(e,t=`eng`){switch(typeof e.content){case`string`:case`number`:case`boolean`:return D(e.content);case`object`:if(Array.isArray(e.content)){let n=C(e.content,t);if(n)return O(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 O(n)}}else return O(e.content);default:return String(e.content)}}function j(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}function M(e){try{let t={label:[`string`,`number`,`boolean`].includes(typeof e.label)?D(e.label):A(e.label),abbreviation:``,code:e.code??null};for(let n of Object.keys(e).filter(e=>e!==`label`&&e!==`code`))t[n]=A(e[n]);return t}catch(e){return console.error(e),{label:``,abbreviation:``,code:null}}}function ee(e){return e==null?[`eng`]:Array.isArray(e)?e.map(e=>A(e)):[A(e)]}function te(e){let t={label:``,abbreviation:``,code:null};if(e.item)if(e.item.label||e.item.abbreviation){let n=``,r=``,i=null;e.item.label&&(n=A(e.item.label)),e.item.abbreviation&&(r=A(e.item.abbreviation)),e.item.identification.code&&(i=e.item.identification.code),t={label:n,abbreviation:r,code:i}}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:A(e.dataset),publisher:A(e.publisher),languages:ee(e.language),identifier:A(e.identifier),description:A(e.description)}}function N(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),number:e.n,content:D(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 ne(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,description:e.description?typeof e.description==`string`||typeof e.description==`number`||typeof e.description==`boolean`?D(e.description):A(e.description):null,coordinates:V(e.coordinates),content:e.content==null?null:D(e.content),notes:e.notes?B(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],events:e.events?H(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:e.properties?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function I(e){let t=[];for(let n of e)t.push(ne(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:`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`:`propertyValue`in e?`propertyValue`:null,content:`content`in t?t.content==null?null:D(t.content):null,href:`href`in t&&t.href!=null?t.href:null,fileFormat:`fileFormat`in t&&t.fileFormat!=null?t.fileFormat:null,fileSize:`fileSize`in t&&t.fileSize!=null?t.fileSize:null,uuid:t.uuid??null,type:t.type??null,identification:t.identification?M(t.identification):null,description:`description`in t&&t.description!=null?A(t.description):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 L(e){let t=[];for(let n of e)t.push(...re(n));return t}function R(e,t=`eng`){let n=``,r=Array.isArray(e)?e.find(e=>e.lang===t):e;if(typeof r.string==`string`||typeof r.string==`number`||typeof r.string==`boolean`)n+=w(D(r.string));else{let e=Array.isArray(r.string)?r.string:[r.string];for(let t of e)n+=k(t)}return n}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?D(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?D(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`?w(D(a.string)):w(R(a)),n.push({number:r.noteNo,title:a.title==null?null:D(a.title),content:e})}return n}function V(e){if(e==null)return[];let t=[],n=Array.isArray(e.coord)?e.coord:[e.coord];for(let e of n){let n=`source`in e&&e.source?e.source.context===`self`?{context:`self`,uuid:e.source.label.uuid,label:A(e.source.label)}:e.source.context===`related`?{context:`related`,uuid:e.source.label.uuid,label:A(e.source.label),value:A(e.source.value)}:{context:`inherited`,uuid:e.source.label.uuid,item:{uuid:e.source.item.label.uuid,label:A(e.source.item.label)},label:A(e.source.label)}:null;switch(e.type){case`point`:t.push({type:e.type,latitude:e.latitude,longitude:e.longitude,altitude:e.altitude??null,source:n});break;case`plane`:t.push({type:e.type,minimum:{latitude:e.minimum.latitude,longitude:e.minimum.longitude},maximum:{latitude:e.maximum.latitude,longitude:e.maximum.longitude},source:n});break}}return t}function ie(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`?D(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?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function ae(e){let t=[];for(let n of e)t.push(ie(n));return t}function H(e){let t=[];for(let n of e)t.push({date:n.dateTime==null?null:new Date(n.dateTime),label:A(n.label),agent:n.agent?{uuid:n.agent.uuid,content:D(n.agent.content)}:null});return t}function oe(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=D(e);let n={content:t,label:null,dataType:`string`,isUncertain:!1,category:`value`,type:null,uuid:null,publicationDateTime:null,unit:null};return n}else{let r=`string`;if(e.dataType!=null){let{data:t,error:n}=a.safeParse(e.dataType);if(n)throw Error(`Invalid property value content type: "${e.dataType}"`);r=t}switch(r){case`integer`:case`decimal`:case`time`:e.rawValue==null?(t=Number(e.content),n=null):(t=Number(e.rawValue),n=e.content?A({content:e.content}):null);break;case`boolean`:e.rawValue==null?(t=e.content===!0,n=null):(t=e.rawValue===`true`,n=e.content?A({content:e.content}):null);break;default:`slug`in e&&e.slug!=null?t=D(e.slug):e.content!=null&&(e.rawValue==null?(t=A({content:e.content}),n=null):(t=D(e.rawValue),n=e.content?A({content:e.content}):null));break}let i={content:t,dataType:r,isUncertain:e.isUncertain??!1,label:n,category:e.category??null,type:e.type??null,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:A(e.label,t).replace(/\s*\.{3}$/,``).trim(),values:r,comment:e.comment==null?null:D(e.comment),properties:e.property?U(Array.isArray(e.property)?e.property:[e.property]):[]}}function U(e,t=`eng`){let n=[];for(let r of e)n.push(oe(r,t));return n}function se(e){let t=[];for(let n of e)t.push({date:new Date(n.date),number:n.interpretationNo,properties:n.properties?U(Array.isArray(n.properties.property)?n.properties.property:[n.properties.property]):[]});return t}function ce(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:D(e.title),shape:e.shape===`rect`?`rectangle`:e.shape===`circle`?`circle`:`polygon`,coords:e.coords.split(`,`).map(e=>Number.parseInt(e))});return t}function W(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?A(e.description):null}}function G(e){let t=[];for(let n of e)t.push(W(n));return t}function K(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??null,zoteroId:e.zoteroId??null,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:{details:e.citationDetails??null,format:e.citationFormat??null,short:e.citationFormatSpan?D(`default:span`in e.citationFormatSpan?e.citationFormatSpan[`default:span`].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?D(`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:D(e.entryInfo.startIssue),startVolume:D(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?G(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?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function q(e){let t=[];for(let n of e)t.push(K(n));return t}function le(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?typeof e.description==`string`||typeof e.description==`number`||typeof e.description==`boolean`?D(e.description):A(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 ue(e){let t=[];for(let n of e)t.push(le(n));return t}function de(e,t,n){if(typeof e.items==`string`)throw TypeError(`Invalid OCHRE data: Tree has no items`);let r=[];e.creators&&(r=I(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]));let i=null;e.date!=null&&(i=new Date(e.date));let a=n??j(Object.keys(e.items)),o=[];switch(a){case`resource`:if(!(`resource`in e.items))throw Error(`Invalid OCHRE data: Tree has no resources`);o=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: Tree has no spatial units`);o=he(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit]);break;case`concept`:if(!(`concept`in e.items))throw Error(`Invalid OCHRE data: Tree has no concepts`);o=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: Tree has no periods`);o=G(Array.isArray(e.items.period)?e.items.period:[e.items.period]);break;case`bibliography`:if(!(`bibliography`in e.items))throw Error(`Invalid OCHRE data: Tree has no bibliographies`);o=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: Tree has no persons`);o=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: Tree has no property values`);o=ue(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]);break;case`set`:{if(!(`set`in e.items))throw Error(`Invalid OCHRE data: Tree has no sets`);let t=[];for(let r of Array.isArray(e.items.set)?e.items.set:[e.items.set])t.push(fe(r,n));o=t;break}default:throw Error(`Invalid OCHRE data: Tree has no items or is malformed`)}let s={uuid:e.uuid,category:`tree`,publicationDateTime:new Date(e.publicationDateTime),identification:M(e.identification),creators:r,license:F(e.availability),date:i,type:e.type,number:e.n,items:o,properties:e.properties?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return s}function fe(e,t){if(typeof e.items==`string`)throw TypeError(`Invalid OCHRE data: Set has no items`);let n=t??j(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=he(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=G(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=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=ue(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)?D(e.description):A(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 pe(e){let t={uuid:e.uuid,category:`resource`,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,type:e.type,number:e.n,fileFormat:e.fileFormat??null,fileSize:e.fileSize??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?D(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)?D(e.description):A(e.description):``,coordinates:e.coordinates?V(e.coordinates):[],document:e.document&&`content`in e.document?R(e.document.content):null,href:e.href??null,imageMap:e.imagemap?ce(e.imagemap):null,periods:e.periods?G(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?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],bibliographies:e.bibliographies?q(Array.isArray(e.bibliographies.bibliography)?e.bibliographies.bibliography:[e.bibliographies.bibliography]):[],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(pe(e));return t}function me(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)?D(e.description):A(e.description):``,coordinates:V(e.coordinates),mapData:e.mapData??null,observations:`observations`in e&&e.observations?ae(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[ie(e.observation)]:[],events:`events`in e&&e.events?H(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:`properties`in e&&e.properties?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return t}function he(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(me(e));return t}function ge(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:e.interpretations?se(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation]):[],properties:e.properties?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return t}const _e=async(e,t)=>{let n=[];for(let r of e){let e=r.properties?U(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 Y(r);n.push(e);break}case`page`:{let e=await be(r);e&&n.push(e);break}case`block`:{let e=await X(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(ge(e));return t}async function ye(e,t){let n=e.values[0].content,{data:i}=r.safeParse(n),a={component:i},o=t.links?L(Array.isArray(t.links)?t.links:[t.links]):[],s=o.filter(e=>e.type===`image`||e.type===`IIIF`);switch(i){case`annotated-document`:{let e=o.find(e=>e.type===`internalDocument`);if(!e)throw Error(`Document link not found for the following component: “${i}”`);a.documentId=e.uuid;break}case`annotated-image`:{if(s.length===0)throw Error(`Image link not found for the following component: “${i}”`);let t=g(e.properties,`filter-displayed`)===!0;a.imageUuid=s[0].uuid,a.isFilterDisplayed=t;break}case`audio-player`:{let t=o.find(e=>e.type===`audio`);if(!t)throw Error(`Audio link not found for the following component: “${i}”`);let n=!1,r=g(e.properties,`speed-controls-displayed`);r!==null&&(n=r===!0);let s=!1,c=g(e.properties,`volume-controls-displayed`);c!==null&&(s=c===!0);let l=!1,u=g(e.properties,`seek-bar-displayed`);u!==null&&(l=u===!0),a.audioId=t.uuid,a.isSpeedControlsDisplayed=n,a.isVolumeControlsDisplayed=s,a.isSeekBarDisplayed=l;break}case`bibliography`:{let t=o.find(e=>e.category===`bibliography`);if(!t)throw Error(`Bibliography link not found for the following component: “${i}”`);if(!t.bibliographies)throw Error(`Bibliography not found for the following component: “${i}”`);let n=g(e.properties,`layout`);n??=`long`,a.bibliographies=t.bibliographies,a.layout=n;break}case`button`:{let n=g(e.properties,`variant`);n??=`default`;let r=!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: “${i}”`);r=!0}let s=null,c=g(e.properties,`start-icon`);c!==null&&(s=c);let l=null,u=g(e.properties,`end-icon`);u!==null&&(l=u),a.variant=n,a.href=o,a.isExternal=r,a.label=[`string`,`number`,`boolean`].includes(typeof t.identification.label)?D(t.identification.label):A(t.identification.label),a.startIcon=s,a.endIcon=l;break}case`collection`:{let t=o.find(e=>e.category===`set`);if(!t)throw Error(`Collection link not found for the following component: “${i}”`);let n=g(e.properties,`variant`);n??=`full`;let r=g(e.properties,`item-variant`);r??=`detailed`;let s=g(e.properties,`pagination-variant`);s??=`default`;let c=!1,l=g(e.properties,`filter-displayed`);l!==null&&(c=l===!0);let u=g(e.properties,`layout`);u??=`image-start`,a.collectionId=t.uuid,a.variant=n,a.itemVariant=r,a.paginationVariant=s,a.isFilterDisplayed=c,a.layout=u;break}case`empty-space`:{let t=g(e.properties,`height`),n=g(e.properties,`width`);a.height=t,a.width=n;break}case`entries`:{let t=o.find(e=>e.category===`tree`);if(!t)throw Error(`Entries link not found for the following component: “${i}”`);let n=g(e.properties,`variant`);n??=`entry`;let r=!1,s=g(e.properties,`filter-displayed`);s!==null&&(r=s===!0),a.entriesId=t.uuid,a.variant=n,a.isFilterDisplayed=r;break}case`iframe`:{let t=o.find(e=>e.type===`webpage`)?.href;if(!t)throw Error(`URL not found for the following component: “${i}”`);let n=g(e.properties,`height`),r=g(e.properties,`width`);a.href=t,a.height=n,a.width=r;break}case`iiif-viewer`:{let e=o.find(e=>e.type===`IIIF`);if(!e)throw Error(`Manifest link not found for the following component: “${i}”`);a.IIIFId=e.uuid;break}case`image`:{if(s.length===0)throw Error(`Image link not found for the following component: “${i}”`);let t=[];for(let e of s)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,description:e.description??null});let n=g(e.properties,`variant`);n??=`default`;let r=g(e.properties,`layout-caption`);r??=`bottom`;let o=null,c=g(e.properties,`width`);c!==null&&(typeof c==`number`?o=c:typeof c==`string`&&(o=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}}a.images=t,a.variant=n,a.width=o,a.height=l,a.isFullWidth=d,a.isFullHeight=p,a.imageQuality=_,a.captionLayout=r,a.captionSource=v,a.altTextSource=y,a.isTransparentBackground=b,a.isCover=S,a.carouselOptions=w;break}case`image-gallery`:{let t=o.find(e=>e.category===`tree`||e.category===`set`);if(!t)throw Error(`Image gallery link not found for the following component: “${i}”`);let n=g(e.properties,`filter-displayed`)===!0;a.galleryId=t.uuid,a.isFilterDisplayed=n;break}case`map`:{let t=o.find(e=>e.category===`set`||e.category===`tree`);if(!t)throw Error(`Map link not found for the following component: “${i}”`);let n=!0,r=g(e.properties,`is-interactive`);r!==null&&(n=r===!0);let s=!1,c=g(e.properties,`is-clustered`);c!==null&&(s=c===!0);let l=!1,u=g(e.properties,`is-using-pins`);u!==null&&(l=u===!0);let d=null,f=g(e.properties,`custom-basemap`);f!==null&&(d=f);let p=!1,m=g(e.properties,`controls-displayed`);m!==null&&(p=m===!0);let h=!1,_=g(e.properties,`is-full-height`);_!==null&&(h=_===!0),a.mapId=t.uuid,a.isInteractive=n,a.isClustered=s,a.isUsingPins=l,a.customBasemap=d,a.isControlsDisplayed=p,a.isFullHeight=h;break}case`network-graph`:break;case`query`:{let t=[],n=e.properties;if(n.length===0)throw Error(`Query properties not found for the following component: “${i}”`);for(let e of n){let n=e.properties,r=g(n,`query-prompt`);if(r===null)throw Error(`Query prompt not found for the following component: “${i}”`);let a=n.find(e=>e.label===`use-property`)?.values.map(e=>e.uuid).filter(e=>e!==null)??[],o=g(n,`start-icon`),s=g(n,`end-icon`);t.push({label:String(r),propertyUuids:a,startIcon:o===null?null:String(o),endIcon:s===null?null:String(s)})}a.queries=t;break}case`table`:{let e=o.find(e=>e.category===`set`);if(!e)throw Error(`Table link not found for the following component: “${i}”`);a.tableId=e.uuid;break}case`search-bar`:{let t=g(e.properties,`variant`);t??=`default`;let n=g(e.properties,`placeholder-text`);a.variant=t,a.placeholder=n===null?null:String(n);break}case`text`:{let n=t.document&&`content`in t.document?R(t.document.content):null;if(!n)throw Error(`Content not found for the following component: “${i}”`);let r=g(e.properties,`variant`);r??=`block`;let o=g(e.properties,`heading`);a.variant=r,a.heading=o,a.content=n;break}case`timeline`:{let e=o.find(e=>e.category===`tree`);if(!e)throw Error(`Timeline link not found for the following component: “${i}”`);a.timelineId=e.uuid;break}case`video`:{let t=o.find(e=>e.type===`video`);if(!t)throw Error(`Video link not found for the following component: “${i}”`);let n=g(e.properties,`chapters-displayed`);n??=!0,a.videoId=t.uuid,a.isChaptersDislayed=n===!0;break}default:console.warn(`Invalid or non-implemented component name “${String(n)}” for the following element: “${A(t.identification.label)}”`);break}return a}async function Y(e){let t=M(e.identification),n=e.properties?.property?U(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?U(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=a.component===`collection`,_=!1,v=!1,y=!1,b=a.component===`collection`&&a.variant===`full`;if(p){let e=g(p,`variant`);e&&(m=e),h=g(p,`name-displayed`)===!0,_=g(p,`description-displayed`)===!0,v=g(p,`date-displayed`)===!0,y=g(p,`creators-displayed`)===!0,b=g(p,`count-displayed`)===!0}return{uuid:e.uuid,type:`element`,title:{label:t.label,variant:m,properties:{isNameDisplayed:h,isDescriptionDisplayed:_,isDateDisplayed:v,isCreatorsDisplayed:y,isCountDisplayed:b}},isDisplayedInBlockSectionSidebar:s,cssStyles:u,cssStylesMobile:f,...a}}async function be(e){let t=e.properties?U(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?U(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 Y(e);s.push(t);break}case`block`:{let t=await X(e);t&&s.push(t);break}}}let c=e.resource?await _e(Array.isArray(e.resource)?e.resource:[e.resource],`page`):[],l=!0,u=`default`,d=`default`,f=!0,p=!1,m=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`page`)?.properties;if(m){let e=m.find(e=>e.label===`header`)?.values[0];e&&(l=e.content===!0);let t=m.find(e=>e.label===`width`)?.values[0];t&&(u=t.content);let n=m.find(e=>e.label===`variant`)?.values[0];n&&(d=n.content);let r=m.find(e=>e.label===`sidebar-visible`)?.values[0];r&&(f=r.content===!0);let i=m.find(e=>e.label===`breadcrumbs-visible`)?.values[0];i&&(p=i.content===!0)}let h=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css`)?.properties,_=[];if(h)for(let e of h)_.push({label:e.label,value:e.values[0].content});let v=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css-mobile`)?.properties,y=[];if(v)for(let e of v)y.push({label:e.label,value:e.values[0].content});return{title:n.label,slug:r,items:s,properties:{displayedInHeader:l,width:u,variant:d,backgroundImageUrl:a?`https://ochre.lib.uchicago.edu/ochre?uuid=${a.uuid}&load`:null,isSidebarDisplayed:f,isBreadcrumbsDisplayed:p,cssStyles:_,cssStylesMobile:y},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 X(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?U(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?U(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 Y(e);a.push(t);break}case`block`:{let t=await X(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=U(e),r=t.find(e=>e.label===`presentation`)?.properties;if(!r)throw Error(`Presentation property not found`);let i=r.find(e=>e.label===`webUI`)?.values[0]?.content;i??=`traditional`;let a=r.find(e=>e.label===`status`)?.values[0]?.content;a??=`development`;let o=r.find(e=>e.label===`privacy`)?.values[0]?.content;o??=`public`;let s=n.safeParse({type:i,status:a,privacy:o});if(!s.success)throw Error(`Invalid website properties: ${s.error.message}`);let c=null,l=r.find(e=>e.label===`contact`);if(l){let[e,t]=(l.values[0]?.content).split(`;`);c={name:e,email:t??null}}let u=r.find(e=>e.label===`logo`)?.values[0]?.uuid??null,d=!0,f=`default`,p=`start`,m=!0,h=!0,g=!1,_=!0,v=null,y=r.find(e=>e.label===`navbar-visible`)?.values[0];y&&(d=y.content===!0);let b=r.find(e=>e.label===`navbar-variant`)?.values[0];b&&(f=b.content);let x=r.find(e=>e.label===`navbar-alignment`)?.values[0];x&&(p=x.content);let S=r.find(e=>e.label===`navbar-project-visible`)?.values[0];S&&(m=S.content===!0);let C=r.find(e=>e.label===`footer-visible`)?.values[0];C&&(h=C.content===!0);let w=r.find(e=>e.label===`sidebar-visible`)?.values[0];w&&(g=w.content===!0);let T=r.find(e=>e.label===`supports-theme-toggle`)?.values[0];T&&(_=T.content===!0);let E=r.find(e=>e.label===`default-theme`)?.values[0];E&&(v=E.content);let{type:D,status:O,privacy:k}=s.data;return{type:D,privacy:k,status:O,contact:c,isHeaderDisplayed:d,headerVariant:f,headerAlignment:p,isHeaderProjectDisplayed:m,isFooterDisplayed:h,isSidebarDisplayed:g,supportsThemeToggle:_,defaultTheme:v,logoUrl:u===null?null:`https://ochre.lib.uchicago.edu/ochre?uuid=${u}&load`}}function Z(e){let t=[];for(let n of e){let e=Array.isArray(n.context)?n.context:[n.context];for(let n of e){let e=Array.isArray(n.levels.level)?n.levels.level:[n.levels.level],r=``,i=e.map(e=>{let t=``,n=null;if(typeof e==`string`){let r=e.split(`, `);t=r[0],n=r[1]===`null`?null:r[1]}else{let i=e.content.split(`, `);r=e.dataType,t=i[0],n=i[1]===`null`?null:i[1]}return{variableUuid:t,valueUuid:n}});t.push({context:i,type:r,identification:M(n.identification)})}}return t}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,isCountDisplayed:!1}},l=`start`,u=`default`,d=[],f=[],p=i.find(e=>{let t=e.properties?U(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`?D(p.identification.label):A(p.identification.label);let e=p.properties?U(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),c.properties.isNameDisplayed=g(o,`name-displayed`)===!0,c.properties.isDescriptionDisplayed=g(o,`description-displayed`)===!0,c.properties.isDateDisplayed=g(o,`date-displayed`)===!0,c.properties.isCreatorsDisplayed=g(o,`creators-displayed`)===!0,c.properties.isCountDisplayed=g(o,`count-displayed`)===!0}let m=p.resource?Array.isArray(p.resource)?p.resource:[p.resource]:[];for(let e of m){let t=await Y(e);s.push(t)}}s.length>0&&(o={elements:s,title:c,layout:l,mobileLayout:u,cssStyles:d,cssStylesMobile:f});let m={contexts:{flatten:[],filter:[],detail:[],download:[],label:[],suppress:[]}};if(e.websiteOptions){let t=e.websiteOptions.flattenContexts==null?[]:Array.isArray(e.websiteOptions.flattenContexts)?e.websiteOptions.flattenContexts:[e.websiteOptions.flattenContexts],n=e.websiteOptions.suppressContexts==null?[]:Array.isArray(e.websiteOptions.suppressContexts)?e.websiteOptions.suppressContexts:[e.websiteOptions.suppressContexts],r=e.websiteOptions.filterContexts==null?[]:Array.isArray(e.websiteOptions.filterContexts)?e.websiteOptions.filterContexts:[e.websiteOptions.filterContexts],i=e.websiteOptions.detailContexts==null?[]:Array.isArray(e.websiteOptions.detailContexts)?e.websiteOptions.detailContexts:[e.websiteOptions.detailContexts],a=e.websiteOptions.downloadContexts==null?[]:Array.isArray(e.websiteOptions.downloadContexts)?e.websiteOptions.downloadContexts:[e.websiteOptions.downloadContexts],o=e.websiteOptions.labelContexts==null?[]:Array.isArray(e.websiteOptions.labelContexts)?e.websiteOptions.labelContexts:[e.websiteOptions.labelContexts];m={contexts:{flatten:Z(t),filter:Z(r),detail:Z(i),download:Z(a),label:Z(o),suppress:Z(n)}}}return{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:M(e.identification),project:{name:D(t),website:n===null?null:D(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,searchOptions:{filters:e.searchOptions?.filterUuids==null?[]:(Array.isArray(e.searchOptions.filterUuids.uuid)?e.searchOptions.filterUuids.uuid:[e.searchOptions.filterUuids.uuid]).map(e=>({uuid:e.content,type:e.type})),scopes:e.searchOptions?.scopes==null?[]:(Array.isArray(e.searchOptions.scopes.scope)?e.searchOptions.scopes.scope:[e.searchOptions.scopes.scope]).map(e=>({uuid:e.uuid.content,type:e.uuid.type,identification:M(e.identification)}))},globalOptions:m}}async function Te(e,t,n,r,i){try{let{uuid:a,filter:s,page:c,perPage:l}=o.parse({uuid:e,filter:t,page:n,perPage:r}),u=await(i??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
2
+ `:``;if(`links`in e){let t=``;t=typeof e.string==`object`?A(e.string):D(e.string).replaceAll(`<`,String.raw`\<`).replaceAll(`{`,String.raw`\{`);let n=Array.isArray(e.links)?e.links:[e.links];for(let r of n)if(`resource`in r){let n=Array.isArray(r.resource)?r.resource[0]:r.resource,i=null;switch(n.content!=null&&(i=D(n.content).replaceAll(`<`,String.raw`\<`).replaceAll(`{`,String.raw`\{`)),n.type){case`image`:return n.rend===`inline`?`<InlineImage uuid="${n.uuid}" ${i===null?``:`content="${i}"`} height={${n.height?.toString()??`null`}} width={${n.width?.toString()??`null`}} />`:n.publicationDateTime==null?`<TooltipSpan${i===null?``:` content="${i}"`}>${t}</TooltipSpan>`:`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`;case`internalDocument`:if(`properties`in e&&e.properties!=null){let r=Array.isArray(e.properties.property)?e.properties.property[0]:e.properties.property;if(r!=null){let e=r.label.uuid,i=typeof r.value==`object`&&`uuid`in r.value&&r.value.uuid!=null?r.value.uuid:null;if(e===b&&i===x){let e=r.property==null?null:Array.isArray(r.property)?r.property[0]:r.property;if(e!=null)return`<Annotation type="hover-card" uuid="${n.uuid}">${t}</Annotation>`}return`<InternalLink uuid="${n.uuid}" properties="${e}"${i===null?``:` value="${i}"`}>${t}</InternalLink>`}else return`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`}else return`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`;case`externalDocument`:return n.publicationDateTime==null?`<TooltipSpan${i===null?``:` content="${i}"`}>${t}</TooltipSpan>`:`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${n.uuid}&load" ${i===null?``:`content="${i}"`}>${t}</ExternalLink>`;case`webpage`:return`<ExternalLink href="${n.href}" ${i===null?``:`content="${i}"`}>${t}</ExternalLink>`;default:return``}}else if(`concept`in r){let e=Array.isArray(r.concept)?r.concept[0]:r.concept;return e.publicationDateTime==null?`<TooltipSpan>${t}</TooltipSpan>`:`<InternalLink uuid="${e.uuid}">${t}</InternalLink>`}else if(`set`in r){let e=Array.isArray(r.set)?r.set[0]:r.set;return e.publicationDateTime==null?`<TooltipSpan>${t}</TooltipSpan>`:`<InternalLink uuid="${e.uuid}">${t}</InternalLink>`}else if(`person`in r){let e=Array.isArray(r.person)?r.person[0]:r.person,n=e.identification?[`string`,`number`,`boolean`].includes(typeof e.identification.label)?D(e.identification.label):A(e.identification.label):null;return e.publicationDateTime==null?`<TooltipSpan${n===null?``:` content="${n}"`}>${t}</TooltipSpan>`:`<InternalLink uuid="${e.uuid}">${t}</InternalLink>`}else if(`bibliography`in r){let e=Array.isArray(r.bibliography)?r.bibliography[0]:r.bibliography;return e.publicationDateTime==null?`<TooltipSpan>${t}</TooltipSpan>`:`<InternalLink uuid="${e.uuid}">${t}</InternalLink>`}else if(`properties`in e&&e.properties!=null){let n=Array.isArray(e.properties.property)?e.properties.property[0]:e.properties.property;if(n!=null){let e=n.label.uuid,r=typeof n.value==`object`&&`uuid`in n.value&&n.value.uuid!=null?n.value.uuid:null;if(e===b&&r===x){let e=n.property==null?null:Array.isArray(n.property)?n.property[0]:n.property;if(e!=null){let n=typeof e.value==`object`&&`uuid`in e.value&&e.value.uuid!=null?e.value.uuid:null;if(n===S)return`<Annotation type="heading">${t}</Annotation>`}}}}}let t=``;if(`string`in e){let n=Array.isArray(e.string)?e.string:[e.string];for(let e of n)t+=k(e);return`whitespace`in e&&e.whitespace!=null&&(t=E(w(t),e.whitespace)),t.replaceAll(`&#39;`,`'`)}else t=D(e.content),e.rend!=null&&(t=T(w(t),e.rend)),e.whitespace!=null&&(t=E(w(t),e.whitespace));return t}function A(e,t=`eng`){switch(typeof e.content){case`string`:case`number`:case`boolean`:return D(e.content);case`object`:if(Array.isArray(e.content)){let n=C(e.content,t);if(n)return O(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 O(n)}}else return O(e.content);default:return String(e.content)}}function j(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}function M(e){try{let t={label:[`string`,`number`,`boolean`].includes(typeof e.label)?D(e.label):A(e.label),abbreviation:``,code:e.code??null};for(let n of Object.keys(e).filter(e=>e!==`label`&&e!==`code`))t[n]=A(e[n]);return t}catch(e){return console.error(e),{label:``,abbreviation:``,code:null}}}function ee(e){return e==null?[`eng`]:Array.isArray(e)?e.map(e=>A(e)):[A(e)]}function te(e){let t={label:``,abbreviation:``,code:null};if(e.item)if(e.item.label||e.item.abbreviation){let n=``,r=``,i=null;e.item.label&&(n=A(e.item.label)),e.item.abbreviation&&(r=A(e.item.abbreviation)),e.item.identification.code&&(i=e.item.identification.code),t={label:n,abbreviation:r,code:i}}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:A(e.dataset),publisher:A(e.publisher),languages:ee(e.language),identifier:A(e.identifier),description:A(e.description)}}function N(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),number:e.n,content:D(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 ne(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,description:e.description?typeof e.description==`string`||typeof e.description==`number`||typeof e.description==`boolean`?D(e.description):A(e.description):null,coordinates:V(e.coordinates),content:e.content==null?null:D(e.content),notes:e.notes?B(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],events:e.events?H(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:e.properties?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function I(e){let t=[];for(let n of e)t.push(ne(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:`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`:`propertyValue`in e?`propertyValue`:null,content:`content`in t?t.content==null?null:D(t.content):null,href:`href`in t&&t.href!=null?t.href:null,fileFormat:`fileFormat`in t&&t.fileFormat!=null?t.fileFormat:null,fileSize:`fileSize`in t&&t.fileSize!=null?t.fileSize:null,uuid:t.uuid??null,type:t.type??null,identification:t.identification?M(t.identification):null,description:`description`in t&&t.description!=null?A(t.description):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 L(e){let t=[];for(let n of e)t.push(...re(n));return t}function R(e,t=`eng`){let n=``,r=Array.isArray(e)?e.find(e=>e.lang===t):e;if(typeof r.string==`string`||typeof r.string==`number`||typeof r.string==`boolean`)n+=w(D(r.string));else{let e=Array.isArray(r.string)?r.string:[r.string];for(let t of e)n+=k(t)}return n}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?D(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?D(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`?w(D(a.string)):w(R(a)),n.push({number:r.noteNo,title:a.title==null?null:D(a.title),content:e})}return n}function V(e){if(e==null)return[];let t=[],n=Array.isArray(e.coord)?e.coord:[e.coord];for(let e of n){let n=`source`in e&&e.source?e.source.context===`self`?{context:`self`,uuid:e.source.label.uuid,label:A(e.source.label)}:e.source.context===`related`?{context:`related`,uuid:e.source.label.uuid,label:A(e.source.label),value:A(e.source.value)}:{context:`inherited`,uuid:e.source.label.uuid,item:{uuid:e.source.item.label.uuid,label:A(e.source.item.label)},label:A(e.source.label)}:null;switch(e.type){case`point`:t.push({type:e.type,latitude:e.latitude,longitude:e.longitude,altitude:e.altitude??null,source:n});break;case`plane`:t.push({type:e.type,minimum:{latitude:e.minimum.latitude,longitude:e.minimum.longitude},maximum:{latitude:e.maximum.latitude,longitude:e.maximum.longitude},source:n});break}}return t}function ie(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`?D(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?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function ae(e){let t=[];for(let n of e)t.push(ie(n));return t}function H(e){let t=[];for(let n of e)t.push({date:n.dateTime==null?null:new Date(n.dateTime),label:A(n.label),agent:n.agent?{uuid:n.agent.uuid,content:D(n.agent.content)}:null});return t}function oe(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=D(e);let n={content:t,label:null,dataType:`string`,isUncertain:!1,category:`value`,type:null,uuid:null,publicationDateTime:null,unit:null,href:null,slug:null};return n}else{let r=`string`;if(e.dataType!=null){let{data:t,error:n}=a.safeParse(e.dataType);if(n)throw Error(`Invalid property value content type: "${e.dataType}"`);r=t}switch(r){case`integer`:case`decimal`:case`time`:e.rawValue==null?(t=Number(e.content),n=null):(t=Number(e.rawValue),n=e.content?A({content:e.content}):null);break;case`boolean`:e.rawValue==null?(t=e.content===!0,n=null):(t=e.rawValue===`true`,n=e.content?A({content:e.content}):null);break;default:`slug`in e&&e.slug!=null?t=D(e.slug):e.content!=null&&(e.rawValue==null?(t=A({content:e.content}),n=null):(t=D(e.rawValue),n=e.content?A({content:e.content}):null));break}let i={content:t,dataType:r,isUncertain:e.isUncertain??!1,label:n,category:e.category??null,type:e.type??null,uuid:e.uuid??null,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),unit:e.unit??null,href:e.href??null,slug:e.slug??null};return i}});return{uuid:e.label.uuid,label:A(e.label,t).replace(/\s*\.{3}$/,``).trim(),values:r,comment:e.comment==null?null:D(e.comment),properties:e.property?U(Array.isArray(e.property)?e.property:[e.property]):[]}}function U(e,t=`eng`){let n=[];for(let r of e)n.push(oe(r,t));return n}function se(e){let t=[];for(let n of e)t.push({date:new Date(n.date),number:n.interpretationNo,properties:n.properties?U(Array.isArray(n.properties.property)?n.properties.property:[n.properties.property]):[]});return t}function ce(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:D(e.title),shape:e.shape===`rect`?`rectangle`:e.shape===`circle`?`circle`:`polygon`,coords:e.coords.split(`,`).map(e=>Number.parseInt(e))});return t}function W(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?A(e.description):null}}function G(e){let t=[];for(let n of e)t.push(W(n));return t}function K(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??null,zoteroId:e.zoteroId??null,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:{details:e.citationDetails??null,format:e.citationFormat??null,short:e.citationFormatSpan?D(`default:span`in e.citationFormatSpan?e.citationFormatSpan[`default:span`].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?D(`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:D(e.entryInfo.startIssue),startVolume:D(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?G(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?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function q(e){let t=[];for(let n of e)t.push(K(n));return t}function le(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?typeof e.description==`string`||typeof e.description==`number`||typeof e.description==`boolean`?D(e.description):A(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 ue(e){let t=[];for(let n of e)t.push(le(n));return t}function de(e,t,n){if(typeof e.items==`string`)throw TypeError(`Invalid OCHRE data: Tree has no items`);let r=[];e.creators&&(r=I(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]));let i=null;e.date!=null&&(i=new Date(e.date));let a=n??j(Object.keys(e.items)),o=[];switch(a){case`resource`:if(!(`resource`in e.items))throw Error(`Invalid OCHRE data: Tree has no resources`);o=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: Tree has no spatial units`);o=he(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit]);break;case`concept`:if(!(`concept`in e.items))throw Error(`Invalid OCHRE data: Tree has no concepts`);o=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: Tree has no periods`);o=G(Array.isArray(e.items.period)?e.items.period:[e.items.period]);break;case`bibliography`:if(!(`bibliography`in e.items))throw Error(`Invalid OCHRE data: Tree has no bibliographies`);o=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: Tree has no persons`);o=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: Tree has no property values`);o=ue(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]);break;case`set`:{if(!(`set`in e.items))throw Error(`Invalid OCHRE data: Tree has no sets`);let t=[];for(let r of Array.isArray(e.items.set)?e.items.set:[e.items.set])t.push(fe(r,n));o=t;break}default:throw Error(`Invalid OCHRE data: Tree has no items or is malformed`)}let s={uuid:e.uuid,category:`tree`,publicationDateTime:new Date(e.publicationDateTime),identification:M(e.identification),creators:r,license:F(e.availability),date:i,type:e.type,number:e.n,items:o,properties:e.properties?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return s}function fe(e,t){if(typeof e.items==`string`)throw TypeError(`Invalid OCHRE data: Set has no items`);let n=t??j(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=he(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=G(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=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=ue(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)?D(e.description):A(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 pe(e){let t={uuid:e.uuid,category:`resource`,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,type:e.type,number:e.n,fileFormat:e.fileFormat??null,fileSize:e.fileSize??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?D(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)?D(e.description):A(e.description):``,coordinates:e.coordinates?V(e.coordinates):[],document:e.document&&`content`in e.document?R(e.document.content):null,href:e.href??null,imageMap:e.imagemap?ce(e.imagemap):null,periods:e.periods?G(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?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],bibliographies:e.bibliographies?q(Array.isArray(e.bibliographies.bibliography)?e.bibliographies.bibliography:[e.bibliographies.bibliography]):[],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(pe(e));return t}function me(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)?D(e.description):A(e.description):``,coordinates:V(e.coordinates),mapData:e.mapData??null,observations:`observations`in e&&e.observations?ae(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[ie(e.observation)]:[],events:`events`in e&&e.events?H(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:`properties`in e&&e.properties?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return t}function he(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(me(e));return t}function ge(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:e.interpretations?se(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation]):[],properties:e.properties?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return t}const _e=async(e,t)=>{let n=[];for(let r of e){let e=r.properties?U(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 Y(r);n.push(e);break}case`page`:{let e=await xe(r);e&&n.push(e);break}case`block`:{let e=await X(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(ge(e));return t}async function ye(e,t){let n=e.values[0].content,{data:i}=r.safeParse(n),a={component:i},o=t.links?L(Array.isArray(t.links)?t.links:[t.links]):[],s=o.filter(e=>e.type===`image`||e.type===`IIIF`);switch(i){case`annotated-document`:{let e=o.find(e=>e.type===`internalDocument`);if(!e)throw Error(`Document link not found for the following component: “${i}”`);a.documentId=e.uuid;break}case`annotated-image`:{if(s.length===0)throw Error(`Image link not found for the following component: “${i}”`);let t=g(e.properties,`filter-displayed`)===!0;a.imageUuid=s[0].uuid,a.isFilterDisplayed=t;break}case`audio-player`:{let t=o.find(e=>e.type===`audio`);if(!t)throw Error(`Audio link not found for the following component: “${i}”`);let n=!1,r=g(e.properties,`speed-controls-displayed`);r!==null&&(n=r===!0);let s=!1,c=g(e.properties,`volume-controls-displayed`);c!==null&&(s=c===!0);let l=!1,u=g(e.properties,`seek-bar-displayed`);u!==null&&(l=u===!0),a.audioId=t.uuid,a.isSpeedControlsDisplayed=n,a.isVolumeControlsDisplayed=s,a.isSeekBarDisplayed=l;break}case`bibliography`:{let t=o.find(e=>e.category===`bibliography`);if(!t)throw Error(`Bibliography link not found for the following component: “${i}”`);if(!t.bibliographies)throw Error(`Bibliography not found for the following component: “${i}”`);let n=g(e.properties,`layout`);n??=`long`,a.bibliographies=t.bibliographies,a.layout=n;break}case`button`:{let n=g(e.properties,`variant`);n??=`default`;let r=!1,o=m(e.properties,`navigate-to`),s=o?.values[0]?.href??o?.values[0]?.slug??null;if(s===null){let t=m(e.properties,`link-to`);if(s=t?.values[0]?.href??t?.values[0]?.slug??null,s===null)throw Error(`Properties “navigate-to” or “link-to” not found for the following component: “${i}”`);r=!0}let c=null,l=g(e.properties,`start-icon`);l!==null&&(c=l);let u=null,d=g(e.properties,`end-icon`);d!==null&&(u=d),a.variant=n,a.href=s,a.isExternal=r,a.label=[`string`,`number`,`boolean`].includes(typeof t.identification.label)?D(t.identification.label):A(t.identification.label),a.startIcon=c,a.endIcon=u;break}case`collection`:{let t=o.find(e=>e.category===`set`);if(!t)throw Error(`Collection link not found for the following component: “${i}”`);let n=g(e.properties,`variant`);n??=`full`;let r=g(e.properties,`item-variant`);r??=`detailed`;let s=g(e.properties,`pagination-variant`);s??=`default`;let c=!1,l=g(e.properties,`filter-displayed`);l!==null&&(c=l===!0);let u=g(e.properties,`layout`);u??=`image-start`,a.collectionId=t.uuid,a.variant=n,a.itemVariant=r,a.paginationVariant=s,a.isFilterDisplayed=c,a.layout=u;break}case`empty-space`:{let t=g(e.properties,`height`),n=g(e.properties,`width`);a.height=t,a.width=n;break}case`entries`:{let t=o.find(e=>e.category===`tree`);if(!t)throw Error(`Entries link not found for the following component: “${i}”`);let n=g(e.properties,`variant`);n??=`entry`;let r=!1,s=g(e.properties,`filter-displayed`);s!==null&&(r=s===!0),a.entriesId=t.uuid,a.variant=n,a.isFilterDisplayed=r;break}case`iframe`:{let t=o.find(e=>e.type===`webpage`)?.href;if(!t)throw Error(`URL not found for the following component: “${i}”`);let n=g(e.properties,`height`),r=g(e.properties,`width`);a.href=t,a.height=n,a.width=r;break}case`iiif-viewer`:{let e=o.find(e=>e.type===`IIIF`);if(!e)throw Error(`Manifest link not found for the following component: “${i}”`);a.IIIFId=e.uuid;break}case`image`:{if(s.length===0)throw Error(`Image link not found for the following component: “${i}”`);let t=[];for(let e of s)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,description:e.description??null});let n=g(e.properties,`variant`);n??=`default`;let r=g(e.properties,`layout-caption`);r??=`bottom`;let o=null,c=g(e.properties,`width`);c!==null&&(typeof c==`number`?o=c:typeof c==`string`&&(o=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}}a.images=t,a.variant=n,a.width=o,a.height=l,a.isFullWidth=d,a.isFullHeight=p,a.imageQuality=_,a.captionLayout=r,a.captionSource=v,a.altTextSource=y,a.isTransparentBackground=b,a.isCover=S,a.carouselOptions=w;break}case`image-gallery`:{let t=o.find(e=>e.category===`tree`||e.category===`set`);if(!t)throw Error(`Image gallery link not found for the following component: “${i}”`);let n=g(e.properties,`filter-displayed`)===!0;a.galleryId=t.uuid,a.isFilterDisplayed=n;break}case`map`:{let t=o.find(e=>e.category===`set`||e.category===`tree`);if(!t)throw Error(`Map link not found for the following component: “${i}”`);let n=!0,r=g(e.properties,`is-interactive`);r!==null&&(n=r===!0);let s=!1,c=g(e.properties,`is-clustered`);c!==null&&(s=c===!0);let l=!1,u=g(e.properties,`is-using-pins`);u!==null&&(l=u===!0);let d=null,f=g(e.properties,`custom-basemap`);f!==null&&(d=f);let p=!1,m=g(e.properties,`controls-displayed`);m!==null&&(p=m===!0);let h=!1,_=g(e.properties,`is-full-height`);_!==null&&(h=_===!0),a.mapId=t.uuid,a.isInteractive=n,a.isClustered=s,a.isUsingPins=l,a.customBasemap=d,a.isControlsDisplayed=p,a.isFullHeight=h;break}case`network-graph`:break;case`query`:{let t=[],n=e.properties;if(n.length===0)throw Error(`Query properties not found for the following component: “${i}”`);for(let e of n){let n=e.properties,r=g(n,`query-prompt`);if(r===null)throw Error(`Query prompt not found for the following component: “${i}”`);let a=n.find(e=>e.label===`use-property`)?.values.map(e=>e.uuid).filter(e=>e!==null)??[],o=g(n,`start-icon`),s=g(n,`end-icon`);t.push({label:String(r),propertyUuids:a,startIcon:o===null?null:String(o),endIcon:s===null?null:String(s)})}a.queries=t;break}case`table`:{let e=o.find(e=>e.category===`set`);if(!e)throw Error(`Table link not found for the following component: “${i}”`);a.tableId=e.uuid;break}case`search-bar`:{let t=g(e.properties,`variant`);t??=`default`;let n=g(e.properties,`placeholder-text`);a.variant=t,a.placeholder=n===null?null:String(n);break}case`text`:{let n=t.document&&`content`in t.document?R(t.document.content):null;if(!n)throw Error(`Content not found for the following component: “${i}”`);let r=g(e.properties,`variant`);r??=`block`;let o=g(e.properties,`heading`);a.variant=r,a.heading=o,a.content=n;break}case`timeline`:{let e=o.find(e=>e.category===`tree`);if(!e)throw Error(`Timeline link not found for the following component: “${i}”`);a.timelineId=e.uuid;break}case`video`:{let t=o.find(e=>e.type===`video`);if(!t)throw Error(`Video link not found for the following component: “${i}”`);let n=g(e.properties,`chapters-displayed`);n??=!0,a.videoId=t.uuid,a.isChaptersDislayed=n===!0;break}default:console.warn(`Invalid or non-implemented component name “${String(n)}” for the following element: “${A(t.identification.label)}”`);break}return a}function be(e,t,n={}){let r=e.find(e=>e.label===`presentation`&&e.values[0].content===`title`)?.properties,i=`default`,a=n.isNameDisplayed??!1,o=!1,s=!1,c=!1,l=n.isCountDisplayed??!1;if(r){let e=g(r,`variant`);e&&(i=e),a=g(r,`name-displayed`)===!0,o=g(r,`description-displayed`)===!0,s=g(r,`date-displayed`)===!0,c=g(r,`creators-displayed`)===!0,l=g(r,`count-displayed`)===!0}return{label:t.label,variant:i,properties:{isNameDisplayed:a,isDescriptionDisplayed:o,isDateDisplayed:s,isCreatorsDisplayed:c,isCountDisplayed:l}}}async function Y(e){let t=M(e.identification),n=e.properties?.property?U(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?U(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=be(c,t,{isNameDisplayed:a.component===`collection`,isCountDisplayed:a.component===`collection`&&a.variant===`full`});return{uuid:e.uuid,type:`element`,title:p,isDisplayedInBlockSectionSidebar:s,cssStyles:u,cssStylesMobile:f,...a}}async function xe(e){let t=e.properties?U(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?U(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 Y(e);s.push(t);break}case`block`:{let t=await X(e);t&&s.push(t);break}}}let c=e.resource?await _e(Array.isArray(e.resource)?e.resource:[e.resource],`page`):[],l=!0,u=`default`,d=`default`,f=!0,p=!1,m=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`page`)?.properties;if(m){let e=m.find(e=>e.label===`header`)?.values[0];e&&(l=e.content===!0);let t=m.find(e=>e.label===`width`)?.values[0];t&&(u=t.content);let n=m.find(e=>e.label===`variant`)?.values[0];n&&(d=n.content);let r=m.find(e=>e.label===`sidebar-visible`)?.values[0];r&&(f=r.content===!0);let i=m.find(e=>e.label===`breadcrumbs-visible`)?.values[0];i&&(p=i.content===!0)}let h=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css`)?.properties,_=[];if(h)for(let e of h)_.push({label:e.label,value:e.values[0].content});let v=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css-mobile`)?.properties,y=[];if(v)for(let e of v)y.push({label:e.label,value:e.values[0].content});return{title:n.label,slug:r,items:s,properties:{displayedInHeader:l,width:u,variant:d,backgroundImageUrl:a?`https://ochre.lib.uchicago.edu/ochre?uuid=${a.uuid}&load`:null,isSidebarDisplayed:f,isBreadcrumbsDisplayed:p,cssStyles:_,cssStylesMobile:y},webpages:c}}async function Se(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n){let n=await xe(e);n&&t.push(n)}return t}async function X(e){let t=e.properties?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n={uuid:e.uuid,type:`block`,layout:`vertical`,title:be(t,M(e.identification)),items:[],properties:{spacing:void 0,gap:void 0,alignItems:`start`,justifyContent:`stretch`,sectionSidebarItems:null},propertiesMobile:null,cssStyles:[],cssStylesMobile:[]},r=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`block`)?.properties;if(r){let e=r.find(e=>e.label===`layout`)?.values[0];e&&(n.layout=e.content);let t=r.find(e=>e.label===`spacing`)?.values[0];t&&(n.properties.spacing=t.content);let i=r.find(e=>e.label===`gap`)?.values[0];i&&(n.properties.gap=i.content);let a=r.find(e=>e.label===`align-items`)?.values[0];a&&(n.properties.alignItems=a.content);let o=r.find(e=>e.label===`justify-content`)?.values[0];o&&(n.properties.justifyContent=o.content);let s=r.find(e=>e.label===`overwrite-mobile`);if(s){let e=s.properties,t={};for(let n of e)t[n.label]=n.values[0].content;n.propertiesMobile=t}}let i=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],a=[];for(let e of i){let t=e.properties?U(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 Y(e);a.push(t);break}case`block`:{let t=await X(e);t&&a.push(t);break}}}n.items=a;let o=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css`)?.properties;if(o)for(let e of o)n.cssStyles.push({label:e.label,value:e.values[0].content});let s=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css-mobile`)?.properties;if(s)for(let e of s)n.cssStylesMobile.push({label:e.label,value:e.values[0].content});return n.properties.sectionSidebarItems=Ce(n),n}function Ce(e){let t=[];for(let n of e.items)switch(n.type){case`block`:{let e=Ce(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 we(e){let t=U(e),r=t.find(e=>e.label===`presentation`)?.properties;if(!r)throw Error(`Presentation property not found`);let i=r.find(e=>e.label===`webUI`)?.values[0]?.content;i??=`traditional`;let a=r.find(e=>e.label===`status`)?.values[0]?.content;a??=`development`;let o=r.find(e=>e.label===`privacy`)?.values[0]?.content;o??=`public`;let s=n.safeParse({type:i,status:a,privacy:o});if(!s.success)throw Error(`Invalid website properties: ${s.error.message}`);let c=null,l=r.find(e=>e.label===`contact`);if(l){let[e,t]=(l.values[0]?.content).split(`;`);c={name:e,email:t??null}}let u=r.find(e=>e.label===`logo`)?.values[0]?.uuid??null,d=!0,f=`default`,p=`start`,m=!0,h=!0,g=!1,_=!0,v=null,y=r.find(e=>e.label===`navbar-visible`)?.values[0];y&&(d=y.content===!0);let b=r.find(e=>e.label===`navbar-variant`)?.values[0];b&&(f=b.content);let x=r.find(e=>e.label===`navbar-alignment`)?.values[0];x&&(p=x.content);let S=r.find(e=>e.label===`navbar-project-visible`)?.values[0];S&&(m=S.content===!0);let C=r.find(e=>e.label===`footer-visible`)?.values[0];C&&(h=C.content===!0);let w=r.find(e=>e.label===`sidebar-visible`)?.values[0];w&&(g=w.content===!0);let T=r.find(e=>e.label===`supports-theme-toggle`)?.values[0];T&&(_=T.content===!0);let E=r.find(e=>e.label===`default-theme`)?.values[0];E&&(v=E.content);let{type:D,status:O,privacy:k}=s.data;return{type:D,privacy:k,status:O,contact:c,isHeaderDisplayed:d,headerVariant:f,headerAlignment:p,isHeaderProjectDisplayed:m,isFooterDisplayed:h,isSidebarDisplayed:g,supportsThemeToggle:_,defaultTheme:v,logoUrl:u===null?null:`https://ochre.lib.uchicago.edu/ochre?uuid=${u}&load`}}function Z(e){let t=[];for(let n of e){let e=Array.isArray(n.context)?n.context:[n.context];for(let n of e){let e=Array.isArray(n.levels.level)?n.levels.level:[n.levels.level],r=``,i=e.map(e=>{let t=``,n=null;if(typeof e==`string`){let r=e.split(`, `);t=r[0],n=r[1]===`null`?null:r[1]}else{let i=e.content.split(`, `);r=e.dataType,t=i[0],n=i[1]===`null`?null:i[1]}return{variableUuid:t,valueUuid:n}});t.push({context:i,type:r,identification:M(n.identification)})}}return t}async function Te(e,t,n){if(!e.properties)throw Error(`Website properties not found`);let r=we(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 Se(i),o=null,s=[],c={label:``,variant:`default`,properties:{isNameDisplayed:!1,isDescriptionDisplayed:!1,isDateDisplayed:!1,isCreatorsDisplayed:!1,isCountDisplayed:!1}},l=`start`,u=`default`,d=[],f=[],p=i.find(e=>{let t=e.properties?U(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`?D(p.identification.label):A(p.identification.label);let e=p.properties?U(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),c.properties.isNameDisplayed=g(o,`name-displayed`)===!0,c.properties.isDescriptionDisplayed=g(o,`description-displayed`)===!0,c.properties.isDateDisplayed=g(o,`date-displayed`)===!0,c.properties.isCreatorsDisplayed=g(o,`creators-displayed`)===!0,c.properties.isCountDisplayed=g(o,`count-displayed`)===!0}let m=p.resource?Array.isArray(p.resource)?p.resource:[p.resource]:[];for(let e of m){let t=await Y(e);s.push(t)}}s.length>0&&(o={elements:s,title:c,layout:l,mobileLayout:u,cssStyles:d,cssStylesMobile:f});let m={contexts:{flatten:[],filter:[],detail:[],download:[],label:[],suppress:[]}};if(e.websiteOptions){let t=e.websiteOptions.flattenContexts==null?[]:Array.isArray(e.websiteOptions.flattenContexts)?e.websiteOptions.flattenContexts:[e.websiteOptions.flattenContexts],n=e.websiteOptions.suppressContexts==null?[]:Array.isArray(e.websiteOptions.suppressContexts)?e.websiteOptions.suppressContexts:[e.websiteOptions.suppressContexts],r=e.websiteOptions.filterContexts==null?[]:Array.isArray(e.websiteOptions.filterContexts)?e.websiteOptions.filterContexts:[e.websiteOptions.filterContexts],i=e.websiteOptions.detailContexts==null?[]:Array.isArray(e.websiteOptions.detailContexts)?e.websiteOptions.detailContexts:[e.websiteOptions.detailContexts],a=e.websiteOptions.downloadContexts==null?[]:Array.isArray(e.websiteOptions.downloadContexts)?e.websiteOptions.downloadContexts:[e.websiteOptions.downloadContexts],o=e.websiteOptions.labelContexts==null?[]:Array.isArray(e.websiteOptions.labelContexts)?e.websiteOptions.labelContexts:[e.websiteOptions.labelContexts];m={contexts:{flatten:Z(t),filter:Z(r),detail:Z(i),download:Z(a),label:Z(o),suppress:Z(n)}}}return{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:M(e.identification),project:{name:D(t),website:n===null?null:D(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,searchOptions:{filters:e.searchOptions?.filterUuids==null?[]:(Array.isArray(e.searchOptions.filterUuids.uuid)?e.searchOptions.filterUuids.uuid:[e.searchOptions.filterUuids.uuid]).map(e=>({uuid:e.content,type:e.type})),scopes:e.searchOptions?.scopes==null?[]:(Array.isArray(e.searchOptions.scopes.scope)?e.searchOptions.scopes.scope:[e.searchOptions.scopes.scope]).map(e=>({uuid:e.uuid.content,type:e.uuid.type,identification:M(e.identification)}))},globalOptions:m}}async function Ee(e,t,n,r,i){try{let{uuid:a,filter:s,page:c,perPage:l}=o.parse({uuid:e,filter:t,page:n,perPage:r}),u=await(i??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
3
3
  for $q in input()/ochre[@uuid='${a}']
4
4
  let $filtered := $q//items/resource[contains(lower-case(identification/label), lower-case('${s}'))]
5
5
  let $maxLength := count($filtered)
@@ -8,9 +8,9 @@ import{z as e}from"zod";const t=e.uuid({error:`Invalid UUID provided`}),n=e.obje
8
8
  {$q/metadata/item}
9
9
  {$filtered[position() >= ${((c-1)*l+1).toString()} and position() < ${(c*l+1).toString()}]}
10
10
  </gallery>
11
- `)}&format=json`);if(!u.ok)throw Error(`Error fetching gallery items, please try again later.`);let d=await u.json();if(!(`gallery`in d.result))throw Error(`Failed to fetch gallery`);let f=M(d.result.gallery.item.identification),p=M(d.result.gallery.project.identification),m={identification:f,projectIdentification:p,resources:J(d.result.gallery.resource?Array.isArray(d.result.gallery.resource)?d.result.gallery.resource:[d.result.gallery.resource]:[]),maxLength:d.result.gallery.maxLength};return{item:m,error:null}}catch(e){return console.error(e),{item:null,error:e instanceof Error?e.message:`Failed to fetch gallery`}}}async function Ee(e,n){try{let r=t.parse(e),i=await(n??fetch)(`https://ochre.lib.uchicago.edu/ochre?uuid=${r}&format=json&lang="*"`);if(!i.ok)throw Error(`Failed to fetch OCHRE data`);let a=await i.json();if(!(`ochre`in a))throw Error(`Invalid OCHRE data: API response missing 'ochre' key`);return[null,a]}catch(e){return[e instanceof Error?e.message:`Unknown error`,null]}}async function De(e,t,n,r){try{let[i,a]=await Ee(e,r);if(i!==null)throw Error(i);let o=j(Object.keys(a.ochre)),s;switch(o){case`resource`:if(!(`resource`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'resource' key`);s=pe(a.ochre.resource);break;case`spatialUnit`:if(!(`spatialUnit`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'spatialUnit' key`);s=me(a.ochre.spatialUnit);break;case`concept`:if(!(`concept`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'concept' key`);s=ge(a.ochre.concept);break;case`period`:if(!(`period`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'period' key`);s=W(a.ochre.period);break;case`bibliography`:if(!(`bibliography`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'bibliography' key`);s=K(a.ochre.bibliography);break;case`person`:if(!(`person`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'person' key`);s=ne(a.ochre.person);break;case`propertyValue`:if(!(`propertyValue`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'propertyValue' key`);s=le(a.ochre.propertyValue);break;case`set`:if(!(`set`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'set' key`);s=fe(a.ochre.set,n);break;case`tree`:if(!(`tree`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'tree' key`);s=de(a.ochre.tree,t,n);break;default:throw Error(`Invalid category`)}let c=te(a.ochre.metadata),l={uuid:a.ochre.uuidBelongsTo,abbreviation:D(a.ochre.belongsTo)};return{error:null,metadata:c,belongsTo:l,item:s,category:t}}catch(e){return{error:e instanceof Error?e.message:`Unknown error`,metadata:void 0,belongsTo:void 0,item:void 0,category:void 0}}}const Oe=`0c0aae37-7246-495b-9547-e25dbf5b99a3`,ke=`30054cb2-909a-4f34-8db9-8fe7369d691d`,Ae=`e28e29af-b663-c0ac-ceb6-11a688fca0dd`;function Q(e){let t=/^[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}$/i;return t.test(e)}const $=e.object({property:e.string().refine(Q),category:e.object({uuid:e.string().refine(Q),content:e.string()}),value:e.object({uuid:e.string().refine(Q).optional(),category:e.string().optional(),type:e.string().optional(),dataType:e.string(),publicationDateTime:e.iso.datetime().optional(),content:e.string().optional(),rawValue:e.string().optional()})}),je=e.object({result:e.object({item:e.union([$,e.array($)])})});function Me(e,t){let n=``;if(e.length>0){let t=e.map(e=>`@uuid="${e}"`).join(` or `);n=`[properties/property[label/@uuid="${ke}"][value[${t}]]]`}let r=t.map(e=>`@uuid="${e}"`).join(` or `),i=`for $q in input()/ochre[@uuidBelongsTo="${Oe}"]/*${n}/properties//property[label[${r}]]
11
+ `)}&format=json`);if(!u.ok)throw Error(`Error fetching gallery items, please try again later.`);let d=await u.json();if(!(`gallery`in d.result))throw Error(`Failed to fetch gallery`);let f=M(d.result.gallery.item.identification),p=M(d.result.gallery.project.identification),m={identification:f,projectIdentification:p,resources:J(d.result.gallery.resource?Array.isArray(d.result.gallery.resource)?d.result.gallery.resource:[d.result.gallery.resource]:[]),maxLength:d.result.gallery.maxLength};return{item:m,error:null}}catch(e){return console.error(e),{item:null,error:e instanceof Error?e.message:`Failed to fetch gallery`}}}async function De(e,n){try{let r=t.parse(e),i=await(n??fetch)(`https://ochre.lib.uchicago.edu/ochre?uuid=${r}&format=json&lang="*"`);if(!i.ok)throw Error(`Failed to fetch OCHRE data`);let a=await i.json();if(!(`ochre`in a))throw Error(`Invalid OCHRE data: API response missing 'ochre' key`);return[null,a]}catch(e){return[e instanceof Error?e.message:`Unknown error`,null]}}async function Oe(e,t,n,r){try{let[i,a]=await De(e,r);if(i!==null)throw Error(i);let o=j(Object.keys(a.ochre)),s;switch(o){case`resource`:if(!(`resource`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'resource' key`);s=pe(a.ochre.resource);break;case`spatialUnit`:if(!(`spatialUnit`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'spatialUnit' key`);s=me(a.ochre.spatialUnit);break;case`concept`:if(!(`concept`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'concept' key`);s=ge(a.ochre.concept);break;case`period`:if(!(`period`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'period' key`);s=W(a.ochre.period);break;case`bibliography`:if(!(`bibliography`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'bibliography' key`);s=K(a.ochre.bibliography);break;case`person`:if(!(`person`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'person' key`);s=ne(a.ochre.person);break;case`propertyValue`:if(!(`propertyValue`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'propertyValue' key`);s=le(a.ochre.propertyValue);break;case`set`:if(!(`set`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'set' key`);s=fe(a.ochre.set,n);break;case`tree`:if(!(`tree`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'tree' key`);s=de(a.ochre.tree,t,n);break;default:throw Error(`Invalid category`)}let c=te(a.ochre.metadata),l={uuid:a.ochre.uuidBelongsTo,abbreviation:D(a.ochre.belongsTo)};return{error:null,metadata:c,belongsTo:l,item:s,category:t}}catch(e){return{error:e instanceof Error?e.message:`Unknown error`,metadata:void 0,belongsTo:void 0,item:void 0,category:void 0}}}const ke=`0c0aae37-7246-495b-9547-e25dbf5b99a3`,Ae=`30054cb2-909a-4f34-8db9-8fe7369d691d`,je=`e28e29af-b663-c0ac-ceb6-11a688fca0dd`;function Q(e){let t=/^[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}$/i;return t.test(e)}const $=e.object({property:e.string().refine(Q),category:e.object({uuid:e.string().refine(Q),content:e.string()}),value:e.object({uuid:e.string().refine(Q).optional(),category:e.string().optional(),type:e.string().optional(),dataType:e.string(),publicationDateTime:e.iso.datetime().optional(),content:e.string().optional(),rawValue:e.string().optional()})}),Me=e.object({result:e.object({item:e.union([$,e.array($)])})});function Ne(e,t){let n=``;if(e.length>0){let t=e.map(e=>`@uuid="${e}"`).join(` or `);n=`[properties/property[label/@uuid="${Ae}"][value[${t}]]]`}let r=t.map(e=>`@uuid="${e}"`).join(` or `),i=`for $q in input()/ochre[@uuidBelongsTo="${ke}"]/*${n}/properties//property[label[${r}]]
12
12
  return <item>
13
13
  <property>{xs:string($q/label/@uuid)}</property> {$q/*[2]}
14
14
  <value>{$q/*[2]/@*} {$q/*[2]/content[1]/string/text()}</value>
15
15
  <category> {$q/ancestor::node()[local-name(.)="properties"]/../@uuid} {local-name($q/ancestor::node()[local-name(.)="properties"]/../self::node())} </category>
16
- </item>`;return i}async function Ne(e,t,n){try{let r=Me(e,t),i=await(n??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(r)}&format=json`);if(!i.ok)throw Error(`OCHRE API responded with status: ${i.status}`);let a=await i.json(),o=je.parse(a),s=Array.isArray(o.result.item)?o.result.item:[o.result.item],c={};for(let e of s){let t=e.category.uuid,n=e.value.uuid,r=e.value.content??e.value.rawValue??``;r in c?c[r].resultUuids.push(t):c[r]={value:{uuid:n??Ae,category:e.value.category??null,type:e.value.type??null,dataType:e.value.dataType,publicationDateTime:e.value.publicationDateTime??null,content:e.value.content??e.value.rawValue??``,label:e.value.rawValue!=null&&e.value.content!=null?e.value.content:null},resultUuids:[t]}}let l=Object.values(c).filter(e=>e.value.uuid!==Ae).toSorted((e,t)=>{let n=e.value.label??e.value.content,r=t.value.label??t.value.content;return n.localeCompare(r,`en-US`)});return{items:l,error:null}}catch(e){return console.error(e),{items:null,error:e instanceof Error?e.message:`Failed to fetch property query`}}}async function Pe(e,n){try{let r=t.parse(e),i=await(n??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`for $q in input()/ochre[@uuid='${r}']/metadata return ($q/item, $q/project)`)}&format=json`);if(!i.ok)throw Error(`Failed to fetch metadata`);let a=await i.json(),o=M(a.result.project.identification),s={...o,website:a.result.project.identification.website??null},c={item:{uuid:e,name:M(a.result.item.identification).label,type:a.result.item.type},project:{name:s.label,website:s.website??null}};return{item:c,error:null}}catch(e){return{item:null,error:e instanceof Error?e.message:`Unknown error`}}}async function Fe(e,t){try{let n=await(t??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(!n.ok)throw Error(`Failed to fetch website`);let r=await n.json();if(!(`ochre`in r.result)||!(`tree`in r.result.ochre))throw Error(`Failed to fetch website`);let i=r.result.ochre.metadata.project?.identification?M(r.result.ochre.metadata.project.identification):null,a=await we(r.result.ochre.tree,i?.label??``,r.result.ochre.metadata.project?.identification.website??null);return[null,a]}catch(e){return console.error(e),[e instanceof Error?e.message:`Unknown error`,null]}}export{Pe as fetchByUuidMetadata,Te as fetchGallery,De as fetchItem,Ne as fetchPropertyQuery,Fe 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};
16
+ </item>`;return i}async function Pe(e,t,n){try{let r=Ne(e,t),i=await(n??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(r)}&format=json`);if(!i.ok)throw Error(`OCHRE API responded with status: ${i.status}`);let a=await i.json(),o=Me.parse(a),s=Array.isArray(o.result.item)?o.result.item:[o.result.item],c={};for(let e of s){let t=e.category.uuid,n=e.value.uuid,r=e.value.content??e.value.rawValue??``;r in c?c[r].resultUuids.push(t):c[r]={value:{uuid:n??je,category:e.value.category??null,type:e.value.type??null,dataType:e.value.dataType,publicationDateTime:e.value.publicationDateTime??null,content:e.value.content??e.value.rawValue??``,label:e.value.rawValue!=null&&e.value.content!=null?e.value.content:null},resultUuids:[t]}}let l=Object.values(c).filter(e=>e.value.uuid!==je).toSorted((e,t)=>{let n=e.value.label??e.value.content,r=t.value.label??t.value.content;return n.localeCompare(r,`en-US`)});return{items:l,error:null}}catch(e){return console.error(e),{items:null,error:e instanceof Error?e.message:`Failed to fetch property query`}}}async function Fe(e,n){try{let r=t.parse(e),i=await(n??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`for $q in input()/ochre[@uuid='${r}']/metadata return ($q/item, $q/project)`)}&format=json`);if(!i.ok)throw Error(`Failed to fetch metadata`);let a=await i.json(),o=M(a.result.project.identification),s={...o,website:a.result.project.identification.website??null},c={item:{uuid:e,name:M(a.result.item.identification).label,type:a.result.item.type},project:{name:s.label,website:s.website??null}};return{item:c,error:null}}catch(e){return{item:null,error:e instanceof Error?e.message:`Unknown error`}}}async function Ie(e,t){try{let n=await(t??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(!n.ok)throw Error(`Failed to fetch website`);let r=await n.json();if(!(`ochre`in r.result)||!(`tree`in r.result.ochre))throw Error(`Failed to fetch website`);let i=r.result.ochre.metadata.project?.identification?M(r.result.ochre.metadata.project.identification):null,a=await Te(r.result.ochre.tree,i?.label??``,r.result.ochre.metadata.project?.identification.website??null);return[null,a]}catch(e){return console.error(e),[e instanceof Error?e.message:`Unknown error`,null]}}export{Fe as fetchByUuidMetadata,Ee as fetchGallery,Oe as fetchItem,Pe as fetchPropertyQuery,Ie 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.9.5",
3
+ "version": "0.9.7",
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",