@digitalculture/ochre-sdk 0.8.18 → 0.8.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
- var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));const c=s(require(`zod/v4`)),l=c.z.uuid({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`,`filter-categories`,`iframe`,`iiif-viewer`,`image`,`image-gallery`,`map`,`n-columns`,`n-rows`,`network-graph`,`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}function O(e,t){let n=e.find(e=>e.lang===t);return n??null}function k(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 ee(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 A(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 j(e){return String(e).replaceAll(`&#39;`,`'`)}function M(e){let t=``;switch(typeof e.string){case`string`:case`number`:case`boolean`:t=j(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+=j(e);else{let n=e.rend==null?j(e.content):ee(j(e.content),e.rend),r=e.whitespace==null?n:A(n,e.whitespace);t+=r}break}default:t=``;break}return t}function te(e){if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return k(j(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`?N(e.string):j(e.string).replaceAll(`<`,String.raw`\<`).replaceAll(`{`,String.raw`\{`);let n=Array.isArray(e.links)?e.links:[e.links];for(let e of n)if(`resource`in e){let n=Array.isArray(e.resource)?e.resource[0]:e.resource,r=null;switch(n.content!=null&&(r=j(n.content).replaceAll(`<`,String.raw`\<`).replaceAll(`{`,String.raw`\{`)),n.type){case`image`:return n.rend===`inline`?`<InlineImage uuid="${n.uuid}" ${r===null?``:`content="${r}"`} height={${n.height?.toString()??`null`}} width={${n.width?.toString()??`null`}} />`:n.publicationDateTime==null?`<TooltipSpan${r===null?``:` content="${r}"`}>${t}</TooltipSpan>`:`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`;case`internalDocument`:return`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`;case`externalDocument`:return n.publicationDateTime==null?`<TooltipSpan${r===null?``:` content="${r}"`}>${t}</TooltipSpan>`:`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${n.uuid}&load" ${r===null?``:`content="${r}"`}>${t}</ExternalLink>`;case`webpage`:return`<ExternalLink href="${n.href}" ${r===null?``:`content="${r}"`}>${t}</ExternalLink>`;default:return``}}else if(`concept`in e){let n=Array.isArray(e.concept)?e.concept[0]:e.concept;return n.publicationDateTime==null?`<TooltipSpan>${t}</TooltipSpan>`:`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`}else if(`set`in e){let n=Array.isArray(e.set)?e.set[0]:e.set;return n.publicationDateTime==null?`<TooltipSpan>${t}</TooltipSpan>`:`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`}else if(`person`in e){let n=Array.isArray(e.person)?e.person[0]:e.person,r=n.identification?[`string`,`number`,`boolean`].includes(typeof n.identification.label)?j(n.identification.label):N(n.identification.label):null;return n.publicationDateTime==null?`<TooltipSpan${r===null?``:` content="${r}"`}>${t}</TooltipSpan>`:`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`}else if(`bibliography`in e){let n=Array.isArray(e.bibliography)?e.bibliography[0]:e.bibliography;return n.publicationDateTime==null?`<TooltipSpan>${t}</TooltipSpan>`:`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`}}let t=``;if(`string`in e){let n=Array.isArray(e.string)?e.string:[e.string];for(let e of n)t+=te(e);return`whitespace`in e&&e.whitespace!=null&&(t=A(k(t),e.whitespace)),t.replaceAll(`&#39;`,`'`)}else t=j(e.content),e.rend!=null&&(t=ee(k(t),e.rend)),e.whitespace!=null&&(t=A(k(t),e.whitespace));return t}function N(e,t=`eng`){switch(typeof e.content){case`string`:case`number`:case`boolean`:return j(e.content);case`object`:if(Array.isArray(e.content)){let n=O(e.content,t);if(n)return M(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 M(n)}}else return M(e.content);default:return String(e.content)}}function P(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 F(e){try{let t={label:[`string`,`number`,`boolean`].includes(typeof e.label)?j(e.label):N(e.label),abbreviation:``};for(let n of Object.keys(e).filter(e=>e!==`label`))t[n]=N(e[n]);return t}catch(e){return console.error(e),{label:``,abbreviation:``}}}function ne(e){return e==null?[`eng`]:Array.isArray(e)?e.map(e=>N(e)):[N(e)]}function re(e){let t={label:``,abbreviation:``};if(e.item)if(e.item.label||e.item.abbreviation){let n=``,r=``;e.item.label&&(n=N(e.item.label)),e.item.abbreviation&&(r=N(e.item.abbreviation)),t={label:n,abbreviation:r}}else t=F(e.item.identification);let n=null,r=e.project?.identification?F(e.project.identification):null;return r&&(n={...r,website:e.project?.identification.website??null}),{project:n?{identification:n}:null,item:e.item?{identification:t,category:e.item.category,type:e.item.type,maxLength:e.item.maxLength??null}:null,dataset:N(e.dataset),publisher:N(e.publisher),languages:ne(e.language),identifier:N(e.identifier),description:N(e.description)}}function I(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),number:e.n,content:j(e.content)}}function L(e){let t=Array.isArray(e.context)?e.context:[e.context],n={nodes:t.map(e=>{let t=[];if(`spatialUnit`in e&&e.spatialUnit){let n=Array.isArray(e.spatialUnit)?e.spatialUnit:[e.spatialUnit];for(let e of n)t.push(I(e))}return{tree:I(e.tree),project:I(e.project),spatialUnit:t}}),displayPath:e.displayPath};return n}function R(e){return typeof e.license==`string`?null:{content:e.license.content,url:e.license.target}}function ie(e){return{uuid:e.uuid,category:`person`,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),type:e.type??null,number:e.n??null,context:e.context?L(e.context):null,date:e.date==null?null:new Date(e.date),identification:e.identification?F(e.identification):null,availability:e.availability?R(e.availability):null,address:e.address?{country:e.address.country??null,city:e.address.city??null,state:e.address.state??null}:null,description:e.description?typeof e.description==`string`||typeof e.description==`number`||typeof e.description==`boolean`?j(e.description):N(e.description):null,coordinates:U(e.coordinates),content:e.content==null?null:j(e.content),notes:e.notes?H(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],events:e.events?W(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function z(e){let t=[];for(let n of e)t.push(ie(n));return t}function ae(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:j(t.content):null,href:`href`in t&&t.href!=null?t.href:null,fileFormat:`fileFormat`in t&&t.fileFormat!=null?t.fileFormat:null,uuid:t.uuid??null,type:t.type??null,identification:t.identification?F(t.identification):null,image:null,bibliographies:`bibliography`in e?q(Array.isArray(e.bibliography)?e.bibliography:[e.bibliography]):null,publicationDateTime:t.publicationDateTime==null?null:new Date(t.publicationDateTime)};`height`in t&&t.height!=null&&t.width!=null&&t.heightPreview!=null&&t.widthPreview!=null&&(n.image={isInline:t.rend===`inline`,isPrimary:t.isPrimary??!1,heightPreview:t.heightPreview,widthPreview:t.widthPreview,height:t.height,width:t.width}),r.push(n)}return r}function B(e){let t=[];for(let n of e)t.push(...ae(n));return t}function V(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+=k(j(r.string));else{let e=Array.isArray(r.string)?r.string:[r.string];for(let t of e)n+=te(t)}return n}function oe(e){return{publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),identification:e.identification?F(e.identification):null,url:e.href??(e.htmlImgSrcPrefix==null&&e.content!=null?j(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?j(e.content):null,widthPreview:e.widthPreview??null,heightPreview:e.heightPreview??null,width:e.width??null,height:e.height??null}}function H(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`?k(j(a.string)):k(V(a)),n.push({number:r.noteNo,title:a.title==null?null:j(a.title),content:e})}return n}function U(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:N(e.source.label)}:e.source.context===`related`?{context:`related`,uuid:e.source.label.uuid,label:N(e.source.label),value:N(e.source.value)}:{context:`inherited`,uuid:e.source.label.uuid,item:{uuid:e.source.item.label.uuid,label:N(e.source.item.label)},label:N(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 se(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`?j(e.observers).split(`;`).map(e=>e.trim()):z(Array.isArray(e.observers)?e.observers:[e.observers]),notes:e.notes?H(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?B(Array.isArray(e.links)?e.links:[e.links]):[],properties:e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function ce(e){let t=[];for(let n of e)t.push(se(n));return t}function W(e){let t=[];for(let n of e)t.push({date:n.dateTime==null?null:new Date(n.dateTime),label:N(n.label),agent:n.agent?{uuid:n.agent.uuid,content:j(n.agent.content)}:null});return t}function le(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=j(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`:e.rawValue==null?(t=Number(e.content),n=null):(t=Number(e.rawValue),n=e.content?N({content:e.content}):null);break;case`boolean`:e.rawValue==null?(t=e.content===!0,n=null):(t=e.rawValue===`true`,n=e.content?N({content:e.content}):null);break;default:`slug`in e&&e.slug!=null?t=j(e.slug):e.content!=null&&(e.rawValue==null?(t=N({content:e.content}),n=null):(t=j(e.rawValue),n=e.content?N({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:N(e.label,t).replace(/\s*\.{3}$/,``).trim(),values:r,comment:e.comment==null?null:j(e.comment),properties:e.property?G(Array.isArray(e.property)?e.property:[e.property]):[]}}function G(e,t=`eng`){let n=[];for(let r of e)n.push(le(r,t));return n}function ue(e){let t=[];for(let n of e)t.push({date:new Date(n.date),number:n.interpretationNo,properties:n.properties?G(Array.isArray(n.properties.property)?n.properties.property:[n.properties.property]):[]});return t}function de(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:j(e.title),shape:e.shape===`rect`?`rectangle`:`polygon`,coords:e.coords.split(`,`).map(e=>Number.parseInt(e))});return t}function fe(e){return{uuid:e.uuid,category:`period`,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),type:e.type??null,number:e.n??null,identification:F(e.identification),description:e.description?N(e.description):null}}function K(e){let t=[];for(let n of e)t.push(fe(n));return t}function pe(e){let t=null;return e.source?.resource&&(t={uuid:e.source.resource.uuid,publicationDateTime:e.source.resource.publicationDateTime?new Date(e.source.resource.publicationDateTime):null,type:e.source.resource.type,identification:F(e.source.resource.identification)}),{uuid:e.uuid??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?F(e.identification):null,projectIdentification:e.project?.identification?F(e.project.identification):null,context:e.context?L(e.context):null,citation:{details:e.citationDetails??null,format:e.citationFormat??null,short:e.citationFormatSpan?j(`default:span`in e.citationFormatSpan?e.citationFormatSpan[`default:span`].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?j(`default:div`in e.referenceFormatDiv?e.referenceFormatDiv[`default:div`][`default:div`].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?z(Array.isArray(e.publicationInfo.publishers.publishers.person)?e.publicationInfo.publishers.publishers.person:[e.publicationInfo.publishers.publishers.person]):[],startDate:e.publicationInfo?.startDate?new Date(e.publicationInfo.startDate.year,e.publicationInfo.startDate.month,e.publicationInfo.startDate.day):null},entryInfo:e.entryInfo?{startIssue:j(e.entryInfo.startIssue),startVolume:j(e.entryInfo.startVolume)}:null,source:{resource:t,documentUrl:e.sourceDocument?`https://ochre.lib.uchicago.edu/ochre?uuid=${e.sourceDocument.uuid}&load`:null},periods:e.periods?K(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],authors:e.authors?z(Array.isArray(e.authors.person)?e.authors.person:[e.authors.person]):[],properties:e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function q(e){let t=[];for(let n of e)t.push(pe(n));return t}function me(e){return{uuid:e.uuid,category:`propertyValue`,number:e.n,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,context:e.context?L(e.context):null,availability:e.availability?R(e.availability):null,identification:F(e.identification),date:e.date?new Date(e.date):null,creators:e.creators?z(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],description:e.description?typeof e.description==`string`||typeof e.description==`number`||typeof e.description==`boolean`?j(e.description):N(e.description):``,notes:e.notes?H(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?B(Array.isArray(e.links)?e.links:[e.links]):[]}}function J(e){let t=[];for(let n of e)t.push(me(n));return t}function he(e){let t=[];e.creators&&(t=z(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]));let n=null;e.date!=null&&(n=new Date(e.date));let r=[],i=[],a=[],o=[],s=[],c=[],l=[];typeof e.items!=`string`&&`resource`in e.items&&(r=Y(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource])),typeof e.items!=`string`&&`spatialUnit`in e.items&&(i=ye(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit])),typeof e.items!=`string`&&`concept`in e.items&&(a=xe(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept])),typeof e.items!=`string`&&`period`in e.items&&(o=K(Array.isArray(e.items.period)?e.items.period:[e.items.period])),typeof e.items!=`string`&&`bibliography`in e.items&&(s=q(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography])),typeof e.items!=`string`&&`person`in e.items&&(c=z(Array.isArray(e.items.person)?e.items.person:[e.items.person])),typeof e.items!=`string`&&`propertyValue`in e.items&&(l=J(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]));let u={uuid:e.uuid,category:`tree`,publicationDateTime:new Date(e.publicationDateTime),identification:F(e.identification),creators:t,license:R(e.availability),date:n,type:e.type,number:e.n,items:{resources:r,spatialUnits:i,concepts:a,periods:o,bibliographies:s,persons:c,propertyValues:l},properties:e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return u}function ge(e,t){if(typeof e.items==`string`)throw TypeError(`Invalid OCHRE data: Set has no items`);let n=t??P(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=ye(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=xe(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept]);break;case`period`:if(!(`period`in e.items))throw Error(`Invalid OCHRE data: Set has no periods`);r=K(Array.isArray(e.items.period)?e.items.period:[e.items.period]);break;case`bibliography`:if(!(`bibliography`in e.items))throw Error(`Invalid OCHRE data: Set has no bibliographies`);r=q(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography]);break;case`person`:if(!(`person`in e.items))throw Error(`Invalid OCHRE data: Set has no persons`);r=z(Array.isArray(e.items.person)?e.items.person:[e.items.person]);break;case`propertyValue`:if(!(`propertyValue`in e.items))throw Error(`Invalid OCHRE data: Set has no property values`);r=J(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]);break;default:throw Error(`Invalid OCHRE data: Set has no items or is malformed`)}return{uuid:e.uuid,category:`set`,itemCategory:t,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,date:e.date==null?null:new Date(e.date),license:R(e.availability),identification:F(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?j(e.description):N(e.description):``,creators:e.creators?z(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],type:e.type,number:e.n,items:r}}function _e(e){let t={uuid:e.uuid,category:`resource`,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,type:e.type,number:e.n,fileFormat:e.fileFormat??null,context:`context`in e&&e.context?L(e.context):null,license:`availability`in e&&e.availability?R(e.availability):null,copyright:`copyright`in e&&e.copyright!=null?j(e.copyright):null,identification:F(e.identification),date:e.date==null?null:new Date(e.date),image:e.image?oe(e.image):null,creators:e.creators?z(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],notes:e.notes?H(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?j(e.description):N(e.description):``,coordinates:e.coordinates?U(e.coordinates):[],document:e.document&&`content`in e.document?V(e.document.content):null,href:e.href??null,imageMap:e.imagemap?de(e.imagemap):null,periods:e.periods?K(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],links:e.links?B(Array.isArray(e.links)?e.links:[e.links]):[],reverseLinks:e.reverseLinks?B(Array.isArray(e.reverseLinks)?e.reverseLinks:[e.reverseLinks]):[],properties:e.properties?G(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?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(_e(e));return t}function ve(e){let t={uuid:e.uuid,category:`spatialUnit`,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),number:e.n,context:`context`in e&&e.context?L(e.context):null,license:`availability`in e&&e.availability?R(e.availability):null,identification:F(e.identification),image:e.image?oe(e.image):null,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?j(e.description):N(e.description):``,coordinates:U(e.coordinates),mapData:e.mapData??null,observations:`observations`in e&&e.observations?ce(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[se(e.observation)]:[],events:`events`in e&&e.events?W(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:`properties`in e&&e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return t}function ye(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(ve(e));return t}function be(e){let t={uuid:e.uuid,category:`concept`,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,number:e.n,license:`availability`in e&&e.availability?R(e.availability):null,context:`context`in e&&e.context?L(e.context):null,identification:F(e.identification),interpretations:ue(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation])};return t}const X=async(e,t)=>{let n=[];for(let r of e){let e=r.properties?G(Array.isArray(r.properties.property)?r.properties.property:[r.properties.property]):[],i=e.find(e=>e.label===`presentation`&&e.values[0].content===t);if(!i)continue;switch(t){case`element`:{let e=await Z(r);n.push(e);break}case`page`:{let e=await Ce(r);e&&n.push(e);break}case`block`:{let e=await Q(r);e&&n.push(e);break}}}return n};function xe(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(be(e));return t}async function Se(e,t){let n=d.parse(e.values[0].content),r={component:n},i=t.links?B(Array.isArray(t.links)?t.links:[t.links]):[],a=i.filter(e=>e.type===`image`||e.type===`IIIF`);switch(n){case`annotated-document`:{let e=i.find(e=>e.type===`internalDocument`);if(!e)throw Error(`Document link not found for the following component: “${n}”`);r.documentId=e.uuid;break}case`annotated-image`:{if(a.length===0)throw Error(`Image link not found for the following component: “${n}”`);let t=w(e.properties,`is-searchable`)===!0;r.imageUuid=a[0].uuid,r.isSearchable=t;break}case`audio-player`:{let t=i.find(e=>e.type===`audio`);if(!t)throw Error(`Audio link not found for the following component: “${n}”`);let a=!1,o=w(e.properties,`speed-controls-displayed`);o!==null&&(a=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);let d=!1,f=w(e.properties,`download-button-displayed`);f!==null&&(d=f===!0),r.audioUuid=t.uuid,r.isSpeedControlsDisplayed=a,r.isVolumeControlsDisplayed=s,r.isSeekBarDisplayed=l,r.isDownloadButtonDisplayed=d;break}case`bibliography`:{let t=i.find(e=>e.category===`bibliography`);if(!t)throw Error(`Bibliography link not found for the following component: “${n}”`);if(!t.bibliographies)throw Error(`Bibliography not found for the following component: “${n}”`);let a=w(e.properties,`layout`);a??=`long`,r.bibliographies=t.bibliographies,r.layout=a;break}case`button`:{let i=w(e.properties,`variant`);i??=`default`;let a=!1,o=w(e.properties,`navigate-to`);if(o===null){if(o=w(e.properties,`link-to`),o===null)throw Error(`Properties “navigate-to” or “link-to” not found for the following component: “${n}”`);a=!0}let s=null,c=w(e.properties,`icon`);c!==null&&(s=c),r.variant=i,r.href=o,r.isExternal=a,r.label=[`string`,`number`,`boolean`].includes(typeof t.identification.label)?j(t.identification.label):N(t.identification.label),r.icon=s;break}case`collection`:{let t=i.find(e=>e.category===`set`);if(!t)throw Error(`Collection link not found for the following component: “${n}”`);let a=w(e.properties,`variant`);a??=`full`;let o=w(e.properties,`item-variant`);o??=`default`;let s=w(e.properties,`pagination-variant`);s??=`default`;let c=!1,l=w(e.properties,`show-count`);l!==null&&(c=l===!0);let u=!1,d=w(e.properties,`is-searchable`);d!==null&&(u=d===!0);let f=w(e.properties,`layout`);f??=`image-start`,r.collectionId=t.uuid,r.variant=a,r.itemVariant=o,r.paginationVariant=s,r.isSearchable=u,r.showCount=c,r.layout=f;break}case`empty-space`:{let t=w(e.properties,`height`),n=w(e.properties,`width`);r.height=t,r.width=n;break}case`entries`:{let t=i.find(e=>e.category===`tree`);if(!t)throw Error(`Entries link not found for the following component: “${n}”`);let a=w(e.properties,`variant`);a??=`entry`;let o=!1,s=w(e.properties,`is-searchable`);s!==null&&(o=s===!0),r.entriesId=t.uuid,r.variant=a,r.isSearchable=o;break}case`filter-categories`:{let e=i.find(e=>e.category===`set`);if(!e)throw Error(`Filter link not found for the following component: “${n}”`);r.filterId=e.uuid;break}case`iframe`:{let t=i.find(e=>e.type===`webpage`)?.href;if(!t)throw Error(`URL not found for the following component: “${n}”`);let a=w(e.properties,`height`),o=w(e.properties,`width`);r.href=t,r.height=a,r.width=o;break}case`iiif-viewer`:{let e=i.find(e=>e.type===`IIIF`);if(!e)throw Error(`Manifest link not found for the following component: “${n}”`);r.IIIFId=e.uuid;break}case`image`:{if(a.length===0)throw Error(`Image link not found for the following component: “${n}”`);let t=[];for(let e of a)t.push({url:`https://ochre.lib.uchicago.edu/ochre?uuid=${e.uuid}&load`,label:e.identification?.label??null,width:e.image?.width??0,height:e.image?.height??0});let i=w(e.properties,`variant`);i??=`default`;let o=w(e.properties,`layout-caption`);o??=`bottom`;let s=null,c=w(e.properties,`width`);c!==null&&(typeof c==`number`?s=c:typeof c==`string`&&(s=Number.parseFloat(c)));let l=null,u=w(e.properties,`height`);u!==null&&(typeof u==`number`?l=u:typeof u==`string`&&(l=Number.parseFloat(u)));let d=!0,f=w(e.properties,`is-full-width`);f!==null&&(d=f===!0);let p=!0,m=w(e.properties,`is-full-height`);m!==null&&(p=m===!0);let h=w(e.properties,`image-quality`);h??=`high`;let g=w(e.properties,`caption-source`);g??=`name`;let _=w(e.properties,`alt-text-source`);_??=`name`;let v=!1,y=w(e.properties,`is-transparent`);y!==null&&(v=y===!0);let b=!1,x=w(e.properties,`is-cover`);x!==null&&(b=x===!0);let C=null;if(t.length>1){let t=S(e.properties,`variant`),n=5;if(t&&t.values[0].content===`carousel`){let e=w(t.properties,`seconds-per-image`);e!==null&&(typeof e==`number`?n=e:typeof e==`string`&&(n=Number.parseFloat(e)))}C={secondsPerImage:n}}r.images=t,r.variant=i,r.width=s,r.height=l,r.isFullWidth=d,r.isFullHeight=p,r.imageQuality=h,r.captionLayout=o,r.captionSource=g,r.altTextSource=_,r.isTransparentBackground=v,r.isCover=b,r.carouselOptions=C;break}case`image-gallery`:{let t=i.find(e=>e.category===`tree`||e.category===`set`);if(!t)throw Error(`Image gallery link not found for the following component: “${n}”`);let a=w(e.properties,`is-searchable`)===!0;r.galleryId=t.uuid,r.isSearchable=a;break}case`map`:{let t=i.find(e=>e.category===`set`||e.category===`tree`);if(!t)throw Error(`Map link not found for the following component: “${n}”`);let a=!0,o=w(e.properties,`is-interactive`);o!==null&&(a=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),r.mapId=t.uuid,r.isInteractive=a,r.isClustered=s,r.isUsingPins=l,r.customBasemap=d,r.isControlsDisplayed=p,r.isFullHeight=h;break}case`n-columns`:{let e=t.resource?await X(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];r.columns=e;break}case`n-rows`:{let e=t.resource?await X(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];r.rows=e;break}case`network-graph`:break;case`table`:{let e=i.find(e=>e.category===`set`);if(!e)throw Error(`Table link not found for the following component: “${n}”`);r.tableId=e.uuid;break}case`search-bar`:{let t=w(e.properties,`variant`);t??=`default`,r.variant=t;break}case`text`:{let i=t.document&&`content`in t.document?V(t.document.content):null;if(!i)throw Error(`Content not found for the following component: “${n}”`);let a=w(e.properties,`variant`);a??=`block`;let o=w(e.properties,`heading`);r.variant=a,r.heading=o,r.content=i;break}case`timeline`:{let e=i.find(e=>e.category===`tree`);if(!e)throw Error(`Timeline link not found for the following component: “${n}”`);r.timelineId=e.uuid;break}case`video`:{let t=i.find(e=>e.type===`video`);if(!t)throw Error(`Video link not found for the following component: “${n}”`);let a=w(e.properties,`chapters-displayed`);a??=!0,r.videoId=t.uuid,r.isChaptersDislayed=a===!0;break}default:console.warn(`Invalid or non-implemented component name “${n}” for the following element: “${N(t.identification.label)}”`);break}return r}async function Z(e){let t=F(e.identification),n=e.properties?.property?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],r=n.find(e=>e.label===`presentation`);if(!r)throw Error(`Presentation property not found for element “${t.label}”`);let i=r.properties.find(e=>e.label===`component`);if(!i)throw Error(`Component for element “${t.label}” not found`);let a=await Se(i,e),o=r.properties.find(e=>e.label===`section-sidebar-displayed`),s=o?.values[0]?.content===!0,c=e.properties?.property?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],l=c.find(e=>e.label===`presentation`&&e.values[0].content===`css`)?.properties??[],u=[];for(let e of l){let t=e.values[0].content;u.push({label:e.label,value:t})}let d=c.find(e=>e.label===`presentation`&&e.values[0].content===`css-mobile`)?.properties??[],f=[];for(let e of d){let t=e.values[0].content;f.push({label:e.label,value:t})}let p=c.find(e=>e.label===`presentation`&&e.values[0].content===`title`)?.properties,m=`default`,h=!1,g=!1,_=!1,v=!1;if(p){let e=w(p,`variant`);e&&(m=e);let t=p.filter(e=>e.label===`display`);t.length>0&&(h=t.some(e=>e.values[0].content===`name`),g=t.some(e=>e.values[0].content===`description`),_=t.some(e=>e.values[0].content===`date`),v=t.some(e=>e.values[0].content===`creators`))}return{uuid:e.uuid,type:`element`,title:{label:t.label,variant:m,properties:{isNameDisplayed:h,isDescriptionDisplayed:g,isDateDisplayed:_,isCreatorsDisplayed:v}},isDisplayedInBlockSectionSidebar:s,cssStyles:u,cssStylesMobile:f,...a}}async function Ce(e){let t=e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];if(t.length===0||t.find(e=>e.label===`presentation`)?.values[0]?.content!==`page`)return null;let n=F(e.identification),r=e.slug;if(r===void 0)throw Error(`Slug not found for page “${n.label}”`);let i=e.links?B(Array.isArray(e.links)?e.links:[e.links]):[],a=i.find(e=>e.type===`image`||e.type===`IIIF`),o=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],s=[];for(let e of o){let t=e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=w(t,`presentation`);if(n==null)continue;switch(n){case`element`:{let t=await Z(e);s.push(t);break}case`block`:{let t=await Q(e);t&&s.push(t);break}}}let c=e.resource?await X(Array.isArray(e.resource)?e.resource:[e.resource],`page`):[],l=!0,u=`default`,d=`default`,f=!0,p=!1,m=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`page`)?.properties;if(m){let e=m.find(e=>e.label===`header`)?.values[0];e&&(l=e.content===!0);let t=m.find(e=>e.label===`width`)?.values[0];t&&(u=t.content);let n=m.find(e=>e.label===`variant`)?.values[0];n&&(d=n.content);let r=m.find(e=>e.label===`sidebar-visible`)?.values[0];r&&(f=r.content===!0);let i=m.find(e=>e.label===`breadcrumbs-visible`)?.values[0];i&&(p=i.content===!0)}let h=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css`)?.properties,g=[];if(h)for(let e of h)g.push({label:e.label,value:e.values[0].content});let _=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css-mobile`)?.properties,v=[];if(_)for(let e of _)v.push({label:e.label,value:e.values[0].content});return{title:n.label,slug:r,items:s,properties:{displayedInHeader:l,width:u,variant:d,backgroundImageUrl:a?`https://ochre.lib.uchicago.edu/ochre?uuid=${a.uuid}&load`:null,isSidebarDisplayed:f,isBreadcrumbsDisplayed:p,cssStyles:g,cssStylesMobile:v},webpages:c}}async function we(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n){let n=await Ce(e);n&&t.push(n)}return t}async function Q(e){let t={uuid:e.uuid,type:`block`,layout:`vertical`,items:[],properties:{spacing:void 0,gap:void 0,alignItems:`start`,justifyContent:`stretch`,sectionSidebarItems:null},propertiesMobile:null,cssStyles:[],cssStylesMobile:[]},n=e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],r=n.find(e=>e.label===`presentation`&&e.values[0]?.content===`block`)?.properties;if(r){let e=r.find(e=>e.label===`layout`)?.values[0];e&&(t.layout=e.content);let n=r.find(e=>e.label===`spacing`)?.values[0];n&&(t.properties.spacing=n.content);let i=r.find(e=>e.label===`gap`)?.values[0];i&&(t.properties.gap=i.content);let a=r.find(e=>e.label===`align-items`)?.values[0];a&&(t.properties.alignItems=a.content);let o=r.find(e=>e.label===`justify-content`)?.values[0];o&&(t.properties.justifyContent=o.content);let s=r.find(e=>e.label===`overwrite-mobile`);if(s){let e=s.properties,n={};for(let t of e)n[t.label]=t.values[0].content;t.propertiesMobile=n}}let i=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],a=[];for(let e of i){let t=e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=w(t,`presentation`);if(n==null)continue;switch(n){case`element`:{let t=await Z(e);a.push(t);break}case`block`:{let t=await Q(e);t&&a.push(t);break}}}t.items=a;let o=n.find(e=>e.label===`presentation`&&e.values[0]?.content===`css`)?.properties;if(o)for(let e of o)t.cssStyles.push({label:e.label,value:e.values[0].content});let s=n.find(e=>e.label===`presentation`&&e.values[0]?.content===`css-mobile`)?.properties;if(s)for(let e of s)t.cssStylesMobile.push({label:e.label,value:e.values[0].content});return t.properties.sectionSidebarItems=Te(t),t}function Te(e){let t=[];for(let n of e.items)switch(n.type){case`block`:{let e=Te(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 Ee(e){let t=G(e),n=t.find(e=>e.label===`presentation`)?.properties;if(!n)throw Error(`Presentation property not found`);let r=n.find(e=>e.label===`webUI`)?.values[0]?.content;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 $(e){return e.map(e=>({context:Array.isArray(e.context)?e.context.flatMap(e=>Array.isArray(e.level)?e.level.map(e=>({variableUuid:e.split(`,`)[0]??``,valueUuid:e.split(`,`)[1]?.trim()===`null`?null:e.split(`,`)[1]?.trim()??null})):[{variableUuid:e.level.split(`,`)[0]??``,valueUuid:e.level.split(`,`)[1]?.trim()===`null`?null:e.level.split(`,`)[1]?.trim()??null}]):[...Array.isArray(e.context.level)?e.context.level.map(e=>({variableUuid:e.split(`,`)[0]??``,valueUuid:e.split(`,`)[1]?.trim()===`null`?null:e.split(`,`)[1]?.trim()??null})):[{variableUuid:e.context.level.split(`,`)[0]??``,valueUuid:e.context.level.split(`,`)[1]?.trim()===`null`?null:e.context.level.split(`,`)[1]?.trim()??null}]]}))}async function De(e,t,n){if(!e.properties)throw Error(`Website properties not found`);let r=Ee(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 we(i),o=null,s=[],c={label:``,variant:`default`,properties:{isNameDisplayed:!1,isDescriptionDisplayed:!1,isDateDisplayed:!1,isCreatorsDisplayed:!1}},l=`start`,u=`default`,d=[],f=[],p=i.find(e=>{let t=e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];return t.some(e=>e.label===`presentation`&&e.values[0]?.content===`element`&&e.properties[0]?.label===`component`&&e.properties[0].values[0]?.content===`sidebar`)});if(p){c.label=typeof p.identification.label==`string`||typeof p.identification.label==`number`||typeof p.identification.label==`boolean`?j(p.identification.label):N(p.identification.label);let e=p.properties?G(Array.isArray(p.properties.property)?p.properties.property:[p.properties.property]):[],t=e.find(e=>e.label===`presentation`&&e.values[0]?.content===`element`)?.properties.find(e=>e.label===`component`&&e.values[0]?.content===`sidebar`)?.properties??[],n=t.find(e=>e.label===`layout`);n&&(l=n.values[0].content);let r=t.find(e=>e.label===`layout-mobile`);r&&(u=r.values[0].content);let i=e.find(e=>e.label===`presentation`&&e.values[0].content===`css`)?.properties??[];for(let e of i){let t=e.values[0].content;d.push({label:e.label,value:t})}let a=e.find(e=>e.label===`presentation`&&e.values[0].content===`css-mobile`)?.properties??[];for(let e of a){let t=e.values[0].content;f.push({label:e.label,value:t})}let o=e.find(e=>e.label===`presentation`&&e.values[0].content===`title`)?.properties;if(o){let e=w(o,`variant`);e&&(c.variant=e);let t=o.filter(e=>e.label===`display`);t.length>0&&(c.properties.isNameDisplayed=t.some(e=>e.values[0].content===`name`),c.properties.isDescriptionDisplayed=t.some(e=>e.values[0].content===`description`),c.properties.isDateDisplayed=t.some(e=>e.values[0].content===`date`),c.properties.isCreatorsDisplayed=t.some(e=>e.values[0].content===`creators`))}let m=p.resource?Array.isArray(p.resource)?p.resource:[p.resource]:[];for(let e of m){let t=await Z(e);s.push(t)}}s.length>0&&(o={elements:s,title:c,layout:l,mobileLayout:u,cssStyles:d,cssStylesMobile:f});let m={collectionUuids:[],contexts:{flatten:[],search:[],active:[],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.searchContexts==null?[]:Array.isArray(e.websiteOptions.searchContexts)?e.websiteOptions.searchContexts:[e.websiteOptions.searchContexts],i=e.websiteOptions.activeContexts==null?[]:Array.isArray(e.websiteOptions.activeContexts)?e.websiteOptions.activeContexts:[e.websiteOptions.activeContexts],a=e.websiteOptions.labelContexts==null?[]:Array.isArray(e.websiteOptions.labelContexts)?e.websiteOptions.labelContexts:[e.websiteOptions.labelContexts];m={collectionUuids:e.websiteOptions.collectionUuids==null?[]:(Array.isArray(e.websiteOptions.collectionUuids.uuid)?e.websiteOptions.collectionUuids.uuid:[e.websiteOptions.collectionUuids.uuid]).map(e=>e.content),contexts:{flatten:$(t),search:$(r),active:$(i),label:$(a),suppress:$(n)}}}return{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:F(e.identification),project:{name:j(t),website:n===null?null:j(n)},creators:e.creators?z(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:R(e.availability),pages:a,sidebar:o,properties:r,globalOptions:m}}async function Oe(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(`
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));const c=s(require(`zod/v4`)),l=c.z.uuid({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`,`filter-categories`,`iframe`,`iiif-viewer`,`image`,`image-gallery`,`map`,`n-columns`,`n-rows`,`network-graph`,`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}function ee(e,t){let n=e.find(e=>e.lang===t);return n??null}function O(e){let t=e.split(` `),n=[];for(let e of t){let t=e.replaceAll(/(?<=\s|^)[([{]+|[)\]}]+(?=\s|$)/g,``).replace(/[!),.:;?\]]$/,``),r=e.indexOf(t),i=e.slice(0,r),a=e.slice(r+t.length),o=_.safeParse(t).success;if(o){n.push(i,`${i}<ExternalLink href="mailto:${t}">${t}</ExternalLink>${a}`);continue}n.push(e)}return n.join(` `)}function te(e,t){let n=e,r=h.safeParse(t);if(!r.success)return console.warn(`Invalid render options string provided: “${t}”`),e;for(let e of r.data)switch(e){case`bold`:n=`**${n}**`;break;case`italic`:n=`*${n}*`;break;case`underline`:n=`_${n}_`;break}return n.replaceAll(`&#39;`,`'`)}function k(e,t){let n=e,r=g.safeParse(t);if(!r.success)return console.warn(`Invalid whitespace string provided: “${t}”`),e;for(let e of r.data)switch(e){case`newline`:n=`<br />\n${n}`;break;case`trailing`:n=`${n} `;break;case`leading`:n=` ${n}`;break}return n.replaceAll(`&#39;`,`'`)}function A(e){return String(e).replaceAll(`&#39;`,`'`)}function j(e){let t=``;switch(typeof e.string){case`string`:case`number`:case`boolean`:t=A(e.string);break;case`object`:{let n=Array.isArray(e.string)?e.string:[e.string];for(let e of n)if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)t+=A(e);else{let n=e.rend==null?A(e.content):te(A(e.content),e.rend),r=e.whitespace==null?n:k(n,e.whitespace);t+=r}break}default:t=``;break}return t}function ne(e){if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return O(A(e));if(`whitespace`in e&&!(`content`in e)&&!(`string`in e))return e.whitespace===`newline`?`
2
+ `:``;if(`links`in e){let t=``;t=typeof e.string==`object`?M(e.string):A(e.string).replaceAll(`<`,String.raw`\<`).replaceAll(`{`,String.raw`\{`);let n=Array.isArray(e.links)?e.links:[e.links];for(let e of n)if(`resource`in e){let n=Array.isArray(e.resource)?e.resource[0]:e.resource,r=null;switch(n.content!=null&&(r=A(n.content).replaceAll(`<`,String.raw`\<`).replaceAll(`{`,String.raw`\{`)),n.type){case`image`:return n.rend===`inline`?`<InlineImage uuid="${n.uuid}" ${r===null?``:`content="${r}"`} height={${n.height?.toString()??`null`}} width={${n.width?.toString()??`null`}} />`:n.publicationDateTime==null?`<TooltipSpan${r===null?``:` content="${r}"`}>${t}</TooltipSpan>`:`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`;case`internalDocument`:return`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`;case`externalDocument`:return n.publicationDateTime==null?`<TooltipSpan${r===null?``:` content="${r}"`}>${t}</TooltipSpan>`:`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${n.uuid}&load" ${r===null?``:`content="${r}"`}>${t}</ExternalLink>`;case`webpage`:return`<ExternalLink href="${n.href}" ${r===null?``:`content="${r}"`}>${t}</ExternalLink>`;default:return``}}else if(`concept`in e){let n=Array.isArray(e.concept)?e.concept[0]:e.concept;return n.publicationDateTime==null?`<TooltipSpan>${t}</TooltipSpan>`:`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`}else if(`set`in e){let n=Array.isArray(e.set)?e.set[0]:e.set;return n.publicationDateTime==null?`<TooltipSpan>${t}</TooltipSpan>`:`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`}else if(`person`in e){let n=Array.isArray(e.person)?e.person[0]:e.person,r=n.identification?[`string`,`number`,`boolean`].includes(typeof n.identification.label)?A(n.identification.label):M(n.identification.label):null;return n.publicationDateTime==null?`<TooltipSpan${r===null?``:` content="${r}"`}>${t}</TooltipSpan>`:`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`}else if(`bibliography`in e){let n=Array.isArray(e.bibliography)?e.bibliography[0]:e.bibliography;return n.publicationDateTime==null?`<TooltipSpan>${t}</TooltipSpan>`:`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`}}let t=``;if(`string`in e){let n=Array.isArray(e.string)?e.string:[e.string];for(let e of n)t+=ne(e);return`whitespace`in e&&e.whitespace!=null&&(t=k(O(t),e.whitespace)),t.replaceAll(`&#39;`,`'`)}else t=A(e.content),e.rend!=null&&(t=te(O(t),e.rend)),e.whitespace!=null&&(t=k(O(t),e.whitespace));return t}function M(e,t=`eng`){switch(typeof e.content){case`string`:case`number`:case`boolean`:return A(e.content);case`object`:if(Array.isArray(e.content)){let n=ee(e.content,t);if(n)return j(n);{let n=e.content[0];if(!n)throw Error(`No string item found for language “${t}” in the following content:\n${JSON.stringify(e.content)}.`);return j(n)}}else return j(e.content);default:return String(e.content)}}function N(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 P(e){try{let t={label:[`string`,`number`,`boolean`].includes(typeof e.label)?A(e.label):M(e.label),abbreviation:``};for(let n of Object.keys(e).filter(e=>e!==`label`))t[n]=M(e[n]);return t}catch(e){return console.error(e),{label:``,abbreviation:``}}}function re(e){return e==null?[`eng`]:Array.isArray(e)?e.map(e=>M(e)):[M(e)]}function ie(e){let t={label:``,abbreviation:``};if(e.item)if(e.item.label||e.item.abbreviation){let n=``,r=``;e.item.label&&(n=M(e.item.label)),e.item.abbreviation&&(r=M(e.item.abbreviation)),t={label:n,abbreviation:r}}else t=P(e.item.identification);let n=null,r=e.project?.identification?P(e.project.identification):null;return r&&(n={...r,website:e.project?.identification.website??null}),{project:n?{identification:n}:null,item:e.item?{identification:t,category:e.item.category,type:e.item.type,maxLength:e.item.maxLength??null}:null,dataset:M(e.dataset),publisher:M(e.publisher),languages:re(e.language),identifier:M(e.identifier),description:M(e.description)}}function F(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),number:e.n,content:A(e.content)}}function I(e){let t=Array.isArray(e.context)?e.context:[e.context],n={nodes:t.map(e=>{let t=[];if(`spatialUnit`in e&&e.spatialUnit){let n=Array.isArray(e.spatialUnit)?e.spatialUnit:[e.spatialUnit];for(let e of n)t.push(F(e))}return{tree:F(e.tree),project:F(e.project),spatialUnit:t}}),displayPath:e.displayPath};return n}function L(e){return typeof e.license==`string`?null:{content:e.license.content,url:e.license.target}}function 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?I(e.context):null,date:e.date==null?null:new Date(e.date),identification:e.identification?P(e.identification):null,availability:e.availability?L(e.availability):null,address:e.address?{country:e.address.country??null,city:e.address.city??null,state:e.address.state??null}:null,description:e.description?typeof e.description==`string`||typeof e.description==`number`||typeof e.description==`boolean`?A(e.description):M(e.description):null,coordinates:U(e.coordinates),content:e.content==null?null:A(e.content),notes:e.notes?H(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],events:e.events?W(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function R(e){let t=[];for(let n of e)t.push(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:A(t.content):null,href:`href`in t&&t.href!=null?t.href:null,fileFormat:`fileFormat`in t&&t.fileFormat!=null?t.fileFormat:null,uuid:t.uuid??null,type:t.type??null,identification:t.identification?P(t.identification):null,image:null,bibliographies:`bibliography`in e?q(Array.isArray(e.bibliography)?e.bibliography:[e.bibliography]):null,publicationDateTime:t.publicationDateTime==null?null:new Date(t.publicationDateTime)};`height`in t&&t.height!=null&&t.width!=null&&t.heightPreview!=null&&t.widthPreview!=null&&(n.image={isInline:t.rend===`inline`,isPrimary:t.isPrimary??!1,heightPreview:t.heightPreview,widthPreview:t.widthPreview,height:t.height,width:t.width}),r.push(n)}return r}function z(e){let t=[];for(let n of e)t.push(...oe(n));return t}function B(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+=O(A(r.string));else{let e=Array.isArray(r.string)?r.string:[r.string];for(let t of e)n+=ne(t)}return n}function V(e){return{publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),identification:e.identification?P(e.identification):null,url:e.href??(e.htmlImgSrcPrefix==null&&e.content!=null?A(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?A(e.content):null,widthPreview:e.widthPreview??null,heightPreview:e.heightPreview??null,width:e.width??null,height:e.height??null}}function H(e,t=`eng`){let n=[];for(let r of e){if(typeof r==`string`){if(r===``)continue;n.push({number:-1,title:null,content:r});continue}let e=``,i=Array.isArray(r.content)?r.content:[r.content],a=i.find(e=>e.lang===t);if(!a&&(a=i[0],!a))throw Error(`Note does not have a valid content item: ${JSON.stringify(r,null,2)}`);e=typeof a.string==`string`||typeof a.string==`number`||typeof a.string==`boolean`?O(A(a.string)):O(B(a)),n.push({number:r.noteNo,title:a.title==null?null:A(a.title),content:e})}return n}function U(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:M(e.source.label)}:e.source.context===`related`?{context:`related`,uuid:e.source.label.uuid,label:M(e.source.label),value:M(e.source.value)}:{context:`inherited`,uuid:e.source.label.uuid,item:{uuid:e.source.item.label.uuid,label:M(e.source.item.label)},label:M(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 se(e){return{number:e.observationNo,date:e.date==null?null:new Date(e.date),observers:e.observers==null?[]:typeof e.observers==`string`||typeof e.observers==`number`||typeof e.observers==`boolean`?A(e.observers).split(`;`).map(e=>e.trim()):R(Array.isArray(e.observers)?e.observers:[e.observers]),notes:e.notes?H(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?z(Array.isArray(e.links)?e.links:[e.links]):[],properties:e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function ce(e){let t=[];for(let n of e)t.push(se(n));return t}function W(e){let t=[];for(let n of e)t.push({date:n.dateTime==null?null:new Date(n.dateTime),label:M(n.label),agent:n.agent?{uuid:n.agent.uuid,content:A(n.agent.content)}:null});return t}function le(e,t=`eng`){let n=`value`in e&&e.value?Array.isArray(e.value)?e.value:[e.value]:[],r=n.map(e=>{let t=null,n=null;if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`){t=A(e);let 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`:e.rawValue==null?(t=Number(e.content),n=null):(t=Number(e.rawValue),n=e.content?M({content:e.content}):null);break;case`boolean`:e.rawValue==null?(t=e.content===!0,n=null):(t=e.rawValue===`true`,n=e.content?M({content:e.content}):null);break;default:`slug`in e&&e.slug!=null?t=A(e.slug):e.content!=null&&(e.rawValue==null?(t=M({content:e.content}),n=null):(t=A(e.rawValue),n=e.content?M({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:M(e.label,t).replace(/\s*\.{3}$/,``).trim(),values:r,comment:e.comment==null?null:A(e.comment),properties:e.property?G(Array.isArray(e.property)?e.property:[e.property]):[]}}function G(e,t=`eng`){let n=[];for(let r of e)n.push(le(r,t));return n}function ue(e){let t=[];for(let n of e)t.push({date:new Date(n.date),number:n.interpretationNo,properties:n.properties?G(Array.isArray(n.properties.property)?n.properties.property:[n.properties.property]):[]});return t}function de(e){let t={area:[],width:e.width,height:e.height},n=Array.isArray(e.area)?e.area:[e.area];for(let e of n)t.area.push({uuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),type:e.type,title:A(e.title),shape:e.shape===`rect`?`rectangle`:`polygon`,coords:e.coords.split(`,`).map(e=>Number.parseInt(e))});return t}function fe(e){return{uuid:e.uuid,category:`period`,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),type:e.type??null,number:e.n??null,identification:P(e.identification),description:e.description?M(e.description):null}}function K(e){let t=[];for(let n of e)t.push(fe(n));return t}function pe(e){let t=null;return e.source?.resource&&(t={uuid:e.source.resource.uuid,publicationDateTime:e.source.resource.publicationDateTime?new Date(e.source.resource.publicationDateTime):null,type:e.source.resource.type,identification:P(e.source.resource.identification)}),{uuid:e.uuid??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?P(e.identification):null,projectIdentification:e.project?.identification?P(e.project.identification):null,context:e.context?I(e.context):null,citation:{details:e.citationDetails??null,format:e.citationFormat??null,short:e.citationFormatSpan?A(`default:span`in e.citationFormatSpan?e.citationFormatSpan[`default:span`].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?A(`default:div`in e.referenceFormatDiv?e.referenceFormatDiv[`default:div`][`default:div`].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?R(Array.isArray(e.publicationInfo.publishers.publishers.person)?e.publicationInfo.publishers.publishers.person:[e.publicationInfo.publishers.publishers.person]):[],startDate:e.publicationInfo?.startDate?new Date(e.publicationInfo.startDate.year,e.publicationInfo.startDate.month,e.publicationInfo.startDate.day):null},entryInfo:e.entryInfo?{startIssue:A(e.entryInfo.startIssue),startVolume:A(e.entryInfo.startVolume)}:null,source:{resource:t,documentUrl:e.sourceDocument?`https://ochre.lib.uchicago.edu/ochre?uuid=${e.sourceDocument.uuid}&load`:null},periods:e.periods?K(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],authors:e.authors?R(Array.isArray(e.authors.person)?e.authors.person:[e.authors.person]):[],properties:e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function q(e){let t=[];for(let n of e)t.push(pe(n));return t}function me(e){return{uuid:e.uuid,category:`propertyValue`,number:e.n,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,context:e.context?I(e.context):null,availability:e.availability?L(e.availability):null,identification:P(e.identification),date:e.date?new Date(e.date):null,creators:e.creators?R(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],description:e.description?typeof e.description==`string`||typeof e.description==`number`||typeof e.description==`boolean`?A(e.description):M(e.description):``,notes:e.notes?H(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?z(Array.isArray(e.links)?e.links:[e.links]):[]}}function J(e){let t=[];for(let n of e)t.push(me(n));return t}function he(e,t,n){if(typeof e.items==`string`)throw TypeError(`Invalid OCHRE data: Tree has no items`);let r=[];e.creators&&(r=R(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]));let i=null;e.date!=null&&(i=new Date(e.date));let a=t??N(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=ye(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=xe(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=K(Array.isArray(e.items.period)?e.items.period:[e.items.period]);break;case`bibliography`:if(!(`bibliography`in e.items))throw Error(`Invalid OCHRE data: 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=R(Array.isArray(e.items.person)?e.items.person:[e.items.person]);break;case`propertyValue`:if(!(`propertyValue`in e.items))throw Error(`Invalid OCHRE data: Tree has no property values`);o=J(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(ge(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:P(e.identification),creators:r,license:L(e.availability),date:i,type:e.type,number:e.n,items:o,properties:e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return s}function ge(e,t){if(typeof e.items==`string`)throw TypeError(`Invalid OCHRE data: Set has no items`);let n=t??N(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=ye(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=xe(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept]);break;case`period`:if(!(`period`in e.items))throw Error(`Invalid OCHRE data: Set has no periods`);r=K(Array.isArray(e.items.period)?e.items.period:[e.items.period]);break;case`bibliography`:if(!(`bibliography`in e.items))throw Error(`Invalid OCHRE data: Set has no bibliographies`);r=q(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography]);break;case`person`:if(!(`person`in e.items))throw Error(`Invalid OCHRE data: Set has no persons`);r=R(Array.isArray(e.items.person)?e.items.person:[e.items.person]);break;case`propertyValue`:if(!(`propertyValue`in e.items))throw Error(`Invalid OCHRE data: Set has no property values`);r=J(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]);break;default:throw Error(`Invalid OCHRE data: Set has no items or is malformed`)}return{uuid:e.uuid,category:`set`,itemCategory:t,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,date:e.date==null?null:new Date(e.date),license:L(e.availability),identification:P(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?A(e.description):M(e.description):``,creators:e.creators?R(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],type:e.type,number:e.n,items:r}}function _e(e){let t={uuid:e.uuid,category:`resource`,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,type:e.type,number:e.n,fileFormat:e.fileFormat??null,context:`context`in e&&e.context?I(e.context):null,license:`availability`in e&&e.availability?L(e.availability):null,copyright:`copyright`in e&&e.copyright!=null?A(e.copyright):null,identification:P(e.identification),date:e.date==null?null:new Date(e.date),image:e.image?V(e.image):null,creators:e.creators?R(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],notes:e.notes?H(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?A(e.description):M(e.description):``,coordinates:e.coordinates?U(e.coordinates):[],document:e.document&&`content`in e.document?B(e.document.content):null,href:e.href??null,imageMap:e.imagemap?de(e.imagemap):null,periods:e.periods?K(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],links:e.links?z(Array.isArray(e.links)?e.links:[e.links]):[],reverseLinks:e.reverseLinks?z(Array.isArray(e.reverseLinks)?e.reverseLinks:[e.reverseLinks]):[],properties:e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],bibliographies:e.bibliographies?q(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(_e(e));return t}function ve(e){let t={uuid:e.uuid,category:`spatialUnit`,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),number:e.n,context:`context`in e&&e.context?I(e.context):null,license:`availability`in e&&e.availability?L(e.availability):null,identification:P(e.identification),image:e.image?V(e.image):null,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?A(e.description):M(e.description):``,coordinates:U(e.coordinates),mapData:e.mapData??null,observations:`observations`in e&&e.observations?ce(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[se(e.observation)]:[],events:`events`in e&&e.events?W(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:`properties`in e&&e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return t}function ye(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(ve(e));return t}function be(e){let t={uuid:e.uuid,category:`concept`,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,number:e.n,license:`availability`in e&&e.availability?L(e.availability):null,context:`context`in e&&e.context?I(e.context):null,identification:P(e.identification),interpretations:ue(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation])};return t}const X=async(e,t)=>{let n=[];for(let r of e){let e=r.properties?G(Array.isArray(r.properties.property)?r.properties.property:[r.properties.property]):[],i=e.find(e=>e.label===`presentation`&&e.values[0].content===t);if(!i)continue;switch(t){case`element`:{let e=await Z(r);n.push(e);break}case`page`:{let e=await Ce(r);e&&n.push(e);break}case`block`:{let e=await Q(r);e&&n.push(e);break}}}return n};function xe(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(be(e));return t}async function Se(e,t){let n=d.parse(e.values[0].content),r={component:n},i=t.links?z(Array.isArray(t.links)?t.links:[t.links]):[],a=i.filter(e=>e.type===`image`||e.type===`IIIF`);switch(n){case`annotated-document`:{let e=i.find(e=>e.type===`internalDocument`);if(!e)throw Error(`Document link not found for the following component: “${n}”`);r.documentId=e.uuid;break}case`annotated-image`:{if(a.length===0)throw Error(`Image link not found for the following component: “${n}”`);let t=w(e.properties,`is-searchable`)===!0;r.imageUuid=a[0].uuid,r.isSearchable=t;break}case`audio-player`:{let t=i.find(e=>e.type===`audio`);if(!t)throw Error(`Audio link not found for the following component: “${n}”`);let a=!1,o=w(e.properties,`speed-controls-displayed`);o!==null&&(a=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);let d=!1,f=w(e.properties,`download-button-displayed`);f!==null&&(d=f===!0),r.audioId=t.uuid,r.isSpeedControlsDisplayed=a,r.isVolumeControlsDisplayed=s,r.isSeekBarDisplayed=l,r.isDownloadButtonDisplayed=d;break}case`bibliography`:{let t=i.find(e=>e.category===`bibliography`);if(!t)throw Error(`Bibliography link not found for the following component: “${n}”`);if(!t.bibliographies)throw Error(`Bibliography not found for the following component: “${n}”`);let a=w(e.properties,`layout`);a??=`long`,r.bibliographies=t.bibliographies,r.layout=a;break}case`button`:{let i=w(e.properties,`variant`);i??=`default`;let a=!1,o=w(e.properties,`navigate-to`);if(o===null){if(o=w(e.properties,`link-to`),o===null)throw Error(`Properties “navigate-to” or “link-to” not found for the following component: “${n}”`);a=!0}let s=null,c=w(e.properties,`icon`);c!==null&&(s=c),r.variant=i,r.href=o,r.isExternal=a,r.label=[`string`,`number`,`boolean`].includes(typeof t.identification.label)?A(t.identification.label):M(t.identification.label),r.icon=s;break}case`collection`:{let t=i.find(e=>e.category===`set`);if(!t)throw Error(`Collection link not found for the following component: “${n}”`);let a=w(e.properties,`variant`);a??=`full`;let o=w(e.properties,`item-variant`);o??=`default`;let s=w(e.properties,`pagination-variant`);s??=`default`;let c=!1,l=w(e.properties,`show-count`);l!==null&&(c=l===!0);let u=!1,d=w(e.properties,`is-searchable`);d!==null&&(u=d===!0);let f=w(e.properties,`layout`);f??=`image-start`,r.collectionId=t.uuid,r.variant=a,r.itemVariant=o,r.paginationVariant=s,r.isSearchable=u,r.showCount=c,r.layout=f;break}case`empty-space`:{let t=w(e.properties,`height`),n=w(e.properties,`width`);r.height=t,r.width=n;break}case`entries`:{let t=i.find(e=>e.category===`tree`);if(!t)throw Error(`Entries link not found for the following component: “${n}”`);let a=w(e.properties,`variant`);a??=`entry`;let o=!1,s=w(e.properties,`is-searchable`);s!==null&&(o=s===!0),r.entriesId=t.uuid,r.variant=a,r.isSearchable=o;break}case`filter-categories`:{let e=i.find(e=>e.category===`set`);if(!e)throw Error(`Filter link not found for the following component: “${n}”`);r.filterId=e.uuid;break}case`iframe`:{let t=i.find(e=>e.type===`webpage`)?.href;if(!t)throw Error(`URL not found for the following component: “${n}”`);let a=w(e.properties,`height`),o=w(e.properties,`width`);r.href=t,r.height=a,r.width=o;break}case`iiif-viewer`:{let e=i.find(e=>e.type===`IIIF`);if(!e)throw Error(`Manifest link not found for the following component: “${n}”`);r.IIIFId=e.uuid;break}case`image`:{if(a.length===0)throw Error(`Image link not found for the following component: “${n}”`);let t=[];for(let e of a)t.push({url:`https://ochre.lib.uchicago.edu/ochre?uuid=${e.uuid}&load`,label:e.identification?.label??null,width:e.image?.width??0,height:e.image?.height??0});let i=w(e.properties,`variant`);i??=`default`;let o=w(e.properties,`layout-caption`);o??=`bottom`;let s=null,c=w(e.properties,`width`);c!==null&&(typeof c==`number`?s=c:typeof c==`string`&&(s=Number.parseFloat(c)));let l=null,u=w(e.properties,`height`);u!==null&&(typeof u==`number`?l=u:typeof u==`string`&&(l=Number.parseFloat(u)));let d=!0,f=w(e.properties,`is-full-width`);f!==null&&(d=f===!0);let p=!0,m=w(e.properties,`is-full-height`);m!==null&&(p=m===!0);let h=w(e.properties,`image-quality`);h??=`high`;let g=w(e.properties,`caption-source`);g??=`name`;let _=w(e.properties,`alt-text-source`);_??=`name`;let v=!1,y=w(e.properties,`is-transparent`);y!==null&&(v=y===!0);let b=!1,x=w(e.properties,`is-cover`);x!==null&&(b=x===!0);let C=null;if(t.length>1){let t=S(e.properties,`variant`),n=5;if(t&&t.values[0].content===`carousel`){let e=w(t.properties,`seconds-per-image`);e!==null&&(typeof e==`number`?n=e:typeof e==`string`&&(n=Number.parseFloat(e)))}C={secondsPerImage:n}}r.images=t,r.variant=i,r.width=s,r.height=l,r.isFullWidth=d,r.isFullHeight=p,r.imageQuality=h,r.captionLayout=o,r.captionSource=g,r.altTextSource=_,r.isTransparentBackground=v,r.isCover=b,r.carouselOptions=C;break}case`image-gallery`:{let t=i.find(e=>e.category===`tree`||e.category===`set`);if(!t)throw Error(`Image gallery link not found for the following component: “${n}”`);let a=w(e.properties,`is-searchable`)===!0;r.galleryId=t.uuid,r.isSearchable=a;break}case`map`:{let t=i.find(e=>e.category===`set`||e.category===`tree`);if(!t)throw Error(`Map link not found for the following component: “${n}”`);let a=!0,o=w(e.properties,`is-interactive`);o!==null&&(a=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),r.mapId=t.uuid,r.isInteractive=a,r.isClustered=s,r.isUsingPins=l,r.customBasemap=d,r.isControlsDisplayed=p,r.isFullHeight=h;break}case`n-columns`:{let e=t.resource?await X(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];r.columns=e;break}case`n-rows`:{let e=t.resource?await X(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];r.rows=e;break}case`network-graph`:break;case`table`:{let e=i.find(e=>e.category===`set`);if(!e)throw Error(`Table link not found for the following component: “${n}”`);r.tableId=e.uuid;break}case`search-bar`:{let t=w(e.properties,`variant`);t??=`default`,r.variant=t;break}case`text`:{let i=t.document&&`content`in t.document?B(t.document.content):null;if(!i)throw Error(`Content not found for the following component: “${n}”`);let a=w(e.properties,`variant`);a??=`block`;let o=w(e.properties,`heading`);r.variant=a,r.heading=o,r.content=i;break}case`timeline`:{let e=i.find(e=>e.category===`tree`);if(!e)throw Error(`Timeline link not found for the following component: “${n}”`);r.timelineId=e.uuid;break}case`video`:{let t=i.find(e=>e.type===`video`);if(!t)throw Error(`Video link not found for the following component: “${n}”`);let a=w(e.properties,`chapters-displayed`);a??=!0,r.videoId=t.uuid,r.isChaptersDislayed=a===!0;break}default:console.warn(`Invalid or non-implemented component name “${n}” for the following element: “${M(t.identification.label)}”`);break}return r}async function Z(e){let t=P(e.identification),n=e.properties?.property?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],r=n.find(e=>e.label===`presentation`);if(!r)throw Error(`Presentation property not found for element “${t.label}”`);let i=r.properties.find(e=>e.label===`component`);if(!i)throw Error(`Component for element “${t.label}” not found`);let a=await Se(i,e),o=r.properties.find(e=>e.label===`section-sidebar-displayed`),s=o?.values[0]?.content===!0,c=e.properties?.property?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],l=c.find(e=>e.label===`presentation`&&e.values[0].content===`css`)?.properties??[],u=[];for(let e of l){let t=e.values[0].content;u.push({label:e.label,value:t})}let d=c.find(e=>e.label===`presentation`&&e.values[0].content===`css-mobile`)?.properties??[],f=[];for(let e of d){let t=e.values[0].content;f.push({label:e.label,value:t})}let p=c.find(e=>e.label===`presentation`&&e.values[0].content===`title`)?.properties,m=`default`,h=!1,g=!1,_=!1,v=!1;if(p){let e=w(p,`variant`);e&&(m=e);let t=p.filter(e=>e.label===`display`);t.length>0&&(h=t.some(e=>e.values[0].content===`name`),g=t.some(e=>e.values[0].content===`description`),_=t.some(e=>e.values[0].content===`date`),v=t.some(e=>e.values[0].content===`creators`))}return{uuid:e.uuid,type:`element`,title:{label:t.label,variant:m,properties:{isNameDisplayed:h,isDescriptionDisplayed:g,isDateDisplayed:_,isCreatorsDisplayed:v}},isDisplayedInBlockSectionSidebar:s,cssStyles:u,cssStylesMobile:f,...a}}async function Ce(e){let t=e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];if(t.length===0||t.find(e=>e.label===`presentation`)?.values[0]?.content!==`page`)return null;let n=P(e.identification),r=e.slug;if(r===void 0)throw Error(`Slug not found for page “${n.label}”`);let i=e.links?z(Array.isArray(e.links)?e.links:[e.links]):[],a=i.find(e=>e.type===`image`||e.type===`IIIF`),o=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],s=[];for(let e of o){let t=e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=w(t,`presentation`);if(n==null)continue;switch(n){case`element`:{let t=await Z(e);s.push(t);break}case`block`:{let t=await Q(e);t&&s.push(t);break}}}let c=e.resource?await X(Array.isArray(e.resource)?e.resource:[e.resource],`page`):[],l=!0,u=`default`,d=`default`,f=!0,p=!1,m=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`page`)?.properties;if(m){let e=m.find(e=>e.label===`header`)?.values[0];e&&(l=e.content===!0);let t=m.find(e=>e.label===`width`)?.values[0];t&&(u=t.content);let n=m.find(e=>e.label===`variant`)?.values[0];n&&(d=n.content);let r=m.find(e=>e.label===`sidebar-visible`)?.values[0];r&&(f=r.content===!0);let i=m.find(e=>e.label===`breadcrumbs-visible`)?.values[0];i&&(p=i.content===!0)}let h=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css`)?.properties,g=[];if(h)for(let e of h)g.push({label:e.label,value:e.values[0].content});let _=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css-mobile`)?.properties,v=[];if(_)for(let e of _)v.push({label:e.label,value:e.values[0].content});return{title:n.label,slug:r,items:s,properties:{displayedInHeader:l,width:u,variant:d,backgroundImageUrl:a?`https://ochre.lib.uchicago.edu/ochre?uuid=${a.uuid}&load`:null,isSidebarDisplayed:f,isBreadcrumbsDisplayed:p,cssStyles:g,cssStylesMobile:v},webpages:c}}async function we(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n){let n=await Ce(e);n&&t.push(n)}return t}async function Q(e){let t={uuid:e.uuid,type:`block`,layout:`vertical`,items:[],properties:{spacing:void 0,gap:void 0,alignItems:`start`,justifyContent:`stretch`,sectionSidebarItems:null},propertiesMobile:null,cssStyles:[],cssStylesMobile:[]},n=e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],r=n.find(e=>e.label===`presentation`&&e.values[0]?.content===`block`)?.properties;if(r){let e=r.find(e=>e.label===`layout`)?.values[0];e&&(t.layout=e.content);let n=r.find(e=>e.label===`spacing`)?.values[0];n&&(t.properties.spacing=n.content);let i=r.find(e=>e.label===`gap`)?.values[0];i&&(t.properties.gap=i.content);let a=r.find(e=>e.label===`align-items`)?.values[0];a&&(t.properties.alignItems=a.content);let o=r.find(e=>e.label===`justify-content`)?.values[0];o&&(t.properties.justifyContent=o.content);let s=r.find(e=>e.label===`overwrite-mobile`);if(s){let e=s.properties,n={};for(let t of e)n[t.label]=t.values[0].content;t.propertiesMobile=n}}let i=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],a=[];for(let e of i){let t=e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=w(t,`presentation`);if(n==null)continue;switch(n){case`element`:{let t=await Z(e);a.push(t);break}case`block`:{let t=await Q(e);t&&a.push(t);break}}}t.items=a;let o=n.find(e=>e.label===`presentation`&&e.values[0]?.content===`css`)?.properties;if(o)for(let e of o)t.cssStyles.push({label:e.label,value:e.values[0].content});let s=n.find(e=>e.label===`presentation`&&e.values[0]?.content===`css-mobile`)?.properties;if(s)for(let e of s)t.cssStylesMobile.push({label:e.label,value:e.values[0].content});return t.properties.sectionSidebarItems=Te(t),t}function Te(e){let t=[];for(let n of e.items)switch(n.type){case`block`:{let e=Te(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 Ee(e){let t=G(e),n=t.find(e=>e.label===`presentation`)?.properties;if(!n)throw Error(`Presentation property not found`);let r=n.find(e=>e.label===`webUI`)?.values[0]?.content;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:ee,privacy:O}=o.data;return{type:D,privacy:O,status:ee,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 $(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.level)?n.level:[n.level],r=e.map(e=>{let[t,n]=e.split(`, `);return{variableUuid:t,valueUuid:n===`null`?null:n}});t.push({context:r})}}return t}async function De(e,t,n){if(!e.properties)throw Error(`Website properties not found`);let r=Ee(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 we(i),o=null,s=[],c={label:``,variant:`default`,properties:{isNameDisplayed:!1,isDescriptionDisplayed:!1,isDateDisplayed:!1,isCreatorsDisplayed:!1}},l=`start`,u=`default`,d=[],f=[],p=i.find(e=>{let t=e.properties?G(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];return t.some(e=>e.label===`presentation`&&e.values[0]?.content===`element`&&e.properties[0]?.label===`component`&&e.properties[0].values[0]?.content===`sidebar`)});if(p){c.label=typeof p.identification.label==`string`||typeof p.identification.label==`number`||typeof p.identification.label==`boolean`?A(p.identification.label):M(p.identification.label);let e=p.properties?G(Array.isArray(p.properties.property)?p.properties.property:[p.properties.property]):[],t=e.find(e=>e.label===`presentation`&&e.values[0]?.content===`element`)?.properties.find(e=>e.label===`component`&&e.values[0]?.content===`sidebar`)?.properties??[],n=t.find(e=>e.label===`layout`);n&&(l=n.values[0].content);let r=t.find(e=>e.label===`layout-mobile`);r&&(u=r.values[0].content);let i=e.find(e=>e.label===`presentation`&&e.values[0].content===`css`)?.properties??[];for(let e of i){let t=e.values[0].content;d.push({label:e.label,value:t})}let a=e.find(e=>e.label===`presentation`&&e.values[0].content===`css-mobile`)?.properties??[];for(let e of a){let t=e.values[0].content;f.push({label:e.label,value:t})}let o=e.find(e=>e.label===`presentation`&&e.values[0].content===`title`)?.properties;if(o){let e=w(o,`variant`);e&&(c.variant=e);let t=o.filter(e=>e.label===`display`);t.length>0&&(c.properties.isNameDisplayed=t.some(e=>e.values[0].content===`name`),c.properties.isDescriptionDisplayed=t.some(e=>e.values[0].content===`description`),c.properties.isDateDisplayed=t.some(e=>e.values[0].content===`date`),c.properties.isCreatorsDisplayed=t.some(e=>e.values[0].content===`creators`))}let m=p.resource?Array.isArray(p.resource)?p.resource:[p.resource]:[];for(let e of m){let t=await Z(e);s.push(t)}}s.length>0&&(o={elements:s,title:c,layout:l,mobileLayout:u,cssStyles:d,cssStylesMobile:f});let m={collectionUuids:[],contexts:{flatten:[],search:[],active:[],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.searchContexts==null?[]:Array.isArray(e.websiteOptions.searchContexts)?e.websiteOptions.searchContexts:[e.websiteOptions.searchContexts],i=e.websiteOptions.activeContexts==null?[]:Array.isArray(e.websiteOptions.activeContexts)?e.websiteOptions.activeContexts:[e.websiteOptions.activeContexts],a=e.websiteOptions.labelContexts==null?[]:Array.isArray(e.websiteOptions.labelContexts)?e.websiteOptions.labelContexts:[e.websiteOptions.labelContexts];m={collectionUuids:e.websiteOptions.collectionUuids==null?[]:(Array.isArray(e.websiteOptions.collectionUuids.uuid)?e.websiteOptions.collectionUuids.uuid:[e.websiteOptions.collectionUuids.uuid]).map(e=>e.content),contexts:{flatten:$(t),search:$(r),active:$(i),label:$(a),suppress:$(n)}}}return{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:P(e.identification),project:{name:A(t),website:n===null?null:A(n)},creators:e.creators?R(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:L(e.availability),pages:a,sidebar:o,properties:r,globalOptions:m}}async function Oe(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,4 +8,4 @@ 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=F(u.result.gallery.item.identification),f=F(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 ke(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 Ae(e,t,n,r){try{let[i,a]=await ke(e,r);if(i!==null)throw Error(i);let o=P(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=_e(a.ochre.resource);break;case`spatialUnit`:if(!(`spatialUnit`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'spatialUnit' key`);s=ve(a.ochre.spatialUnit);break;case`concept`:if(!(`concept`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'concept' key`);s=be(a.ochre.concept);break;case`period`:if(!(`period`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'period' key`);s=fe(a.ochre.period);break;case`bibliography`:if(!(`bibliography`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'bibliography' key`);s=pe(a.ochre.bibliography);break;case`person`:if(!(`person`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'person' key`);s=ie(a.ochre.person);break;case`propertyValue`:if(!(`propertyValue`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'propertyValue' key`);s=me(a.ochre.propertyValue);break;case`set`:if(!(`set`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'set' key`);s=ge(a.ochre.set,n);break;case`tree`:if(!(`tree`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'tree' key`);s=he(a.ochre.tree);break;default:throw Error(`Invalid category`)}let c=re(a.ochre.metadata),l={uuid:a.ochre.uuidBelongsTo,abbreviation:j(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}}}async function je(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=F(i.result.project.identification),o={...a,website:i.result.project.identification.website??null},s={item:{uuid:e,name:F(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 Me(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?F(r.result.ochre.metadata.project.identification):null,a=await De(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=je,exports.fetchGallery=Oe,exports.fetchItem=Ae,exports.fetchWebsite=Me,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;
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=P(u.result.gallery.item.identification),f=P(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 ke(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 Ae(e,t,n,r){try{let[i,a]=await ke(e,r);if(i!==null)throw Error(i);let o=N(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=_e(a.ochre.resource);break;case`spatialUnit`:if(!(`spatialUnit`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'spatialUnit' key`);s=ve(a.ochre.spatialUnit);break;case`concept`:if(!(`concept`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'concept' key`);s=be(a.ochre.concept);break;case`period`:if(!(`period`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'period' key`);s=fe(a.ochre.period);break;case`bibliography`:if(!(`bibliography`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'bibliography' key`);s=pe(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=me(a.ochre.propertyValue);break;case`set`:if(!(`set`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'set' key`);s=ge(a.ochre.set,n);break;case`tree`:if(!(`tree`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'tree' key`);s=he(a.ochre.tree,t,n);break;default:throw Error(`Invalid category`)}let c=ie(a.ochre.metadata),l={uuid:a.ochre.uuidBelongsTo,abbreviation:A(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}}}async function je(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=P(i.result.project.identification),o={...a,website:i.result.project.identification.website??null},s={item:{uuid:e,name:P(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 Me(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?P(r.result.ochre.metadata.project.identification):null,a=await De(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=je,exports.fetchGallery=Oe,exports.fetchItem=Ae,exports.fetchWebsite=Me,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
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * Represents the core data structure containing item information and metadata
4
4
  */
5
- type Data<T extends DataCategory> = {
5
+ type Data<T extends DataCategory, U extends DataCategory> = {
6
6
  uuid: string;
7
7
  belongsTo: {
8
8
  uuid: string;
@@ -10,7 +10,7 @@ type Data<T extends DataCategory> = {
10
10
  };
11
11
  publicationDateTime: Date;
12
12
  metadata: Metadata;
13
- item: Tree | Set<T> | Resource | SpatialUnit | Concept | Period | Bibliography | Person | PropertyValue;
13
+ item: Tree<T, U> | Set<T> | Resource | SpatialUnit | Concept | Period | Bibliography | Person | PropertyValue;
14
14
  };
15
15
  type DataCategory = "tree" | "set" | "resource" | "spatialUnit" | "concept" | "period" | "bibliography" | "person" | "propertyValue";
16
16
  /**
@@ -426,7 +426,7 @@ type Property<T extends PropertyValueContentType = PropertyValueContentType> = {
426
426
  /**
427
427
  * Represents a tree structure containing resources, spatial units and concepts
428
428
  */
429
- type Tree = {
429
+ type Tree<T extends DataCategory, U extends DataCategory> = {
430
430
  uuid: string;
431
431
  category: "tree";
432
432
  publicationDateTime: Date | null;
@@ -436,16 +436,8 @@ type Tree = {
436
436
  license: License | null;
437
437
  identification: Identification;
438
438
  creators: Array<Person>;
439
- items: {
440
- resources: Array<Resource>;
441
- spatialUnits: Array<SpatialUnit>;
442
- concepts: Array<Concept>;
443
- periods: Array<Period>;
444
- bibliographies: Array<Bibliography>;
445
- persons: Array<Person>;
446
- propertyValues: Array<PropertyValue>;
447
- };
448
439
  properties: Array<Property>;
440
+ items: T extends "resource" ? Array<Resource> : T extends "spatialUnit" ? Array<SpatialUnit> : T extends "concept" ? Array<Concept> : T extends "period" ? Array<Period> : T extends "bibliography" ? Array<Bibliography> : T extends "person" ? Array<Person> : T extends "propertyValue" ? Array<PropertyValue> : T extends "set" ? Array<Set<U>> : never;
449
441
  };
450
442
  /**
451
443
  * Represents a gallery with its identification, project identification, resources and max length
@@ -470,6 +462,19 @@ type UuidMetadata = {
470
462
  website: string | null;
471
463
  };
472
464
  } | null;
465
+ /**
466
+ * Represents a level context item with a variable and value
467
+ */
468
+ type LevelContextItem = {
469
+ variableUuid: string;
470
+ valueUuid: string | null;
471
+ };
472
+ /**
473
+ * Represents a level context with a context item
474
+ */
475
+ type LevelContext = {
476
+ context: Array<LevelContextItem>;
477
+ };
473
478
  /**
474
479
  * Represents a website with its properties and elements
475
480
  */
@@ -496,36 +501,11 @@ type Website = {
496
501
  globalOptions: {
497
502
  collectionUuids: Array<string>;
498
503
  contexts: {
499
- flatten: Array<{
500
- context: Array<{
501
- variableUuid: string;
502
- valueUuid: string | null;
503
- }>;
504
- }>;
505
- suppress: Array<{
506
- context: Array<{
507
- variableUuid: string;
508
- valueUuid: string | null;
509
- }>;
510
- }>;
511
- search: Array<{
512
- context: Array<{
513
- variableUuid: string;
514
- valueUuid: string | null;
515
- }>;
516
- }>;
517
- active: Array<{
518
- context: Array<{
519
- variableUuid: string;
520
- valueUuid: string | null;
521
- }>;
522
- }>;
523
- label: Array<{
524
- context: Array<{
525
- variableUuid: string;
526
- valueUuid: string | null;
527
- }>;
528
- }>;
504
+ flatten: Array<LevelContext>;
505
+ suppress: Array<LevelContext>;
506
+ search: Array<LevelContext>;
507
+ active: Array<LevelContext>;
508
+ label: Array<LevelContext>;
529
509
  };
530
510
  };
531
511
  };
@@ -602,7 +582,7 @@ type WebElementComponent = {
602
582
  isSearchable: boolean;
603
583
  } | {
604
584
  component: "audio-player";
605
- audioUuid: string;
585
+ audioId: string;
606
586
  isSpeedControlsDisplayed: boolean;
607
587
  isVolumeControlsDisplayed: boolean;
608
588
  isSeekBarDisplayed: boolean;
@@ -833,7 +813,7 @@ declare function fetchItem<T extends DataCategory, U extends DataCategory>(uuid:
833
813
  uuid: string;
834
814
  abbreviation: string;
835
815
  };
836
- item: T extends "resource" ? Resource : T extends "spatialUnit" ? SpatialUnit : T extends "concept" ? Concept : T extends "period" ? Period : T extends "bibliography" ? Bibliography : T extends "person" ? Person : T extends "propertyValue" ? PropertyValue : T extends "set" ? Set<U> : T extends "tree" ? Tree : never;
816
+ item: T extends "resource" ? Resource : T extends "spatialUnit" ? SpatialUnit : T extends "concept" ? Concept : T extends "period" ? Period : T extends "bibliography" ? Bibliography : T extends "person" ? Person : T extends "propertyValue" ? PropertyValue : T extends "set" ? Set<U> : T extends "tree" ? Tree<T, U> : never;
837
817
  category: T;
838
818
  } | {
839
819
  error: string;
@@ -1065,4 +1045,4 @@ declare function filterProperties(property: Property, filter: {
1065
1045
  value: string | number | boolean | Date;
1066
1046
  }, options?: PropertyOptions): boolean;
1067
1047
  //#endregion
1068
- export { Bibliography, Concept, Context, ContextItem, ContextNode, Coordinates, CoordinatesItem, Data, DataCategory, Event, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyValue, PropertyValueContent, PropertyValueContentType, Resource, Set, SpatialUnit, Style, Tree, UuidMetadata, WebBlock, WebElement, WebElementComponent, WebImage, WebSectionSidebarItem, Webpage, WebpageProperties, Website, WebsiteProperties, fetchByUuidMetadata, fetchGallery, fetchItem, fetchWebsite, filterProperties, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
1048
+ 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, PropertyValue, PropertyValueContent, PropertyValueContentType, Resource, Set, SpatialUnit, Style, Tree, UuidMetadata, WebBlock, WebElement, WebElementComponent, WebImage, WebSectionSidebarItem, Webpage, WebpageProperties, Website, WebsiteProperties, fetchByUuidMetadata, fetchGallery, fetchItem, fetchWebsite, filterProperties, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * Represents the core data structure containing item information and metadata
4
4
  */
5
- type Data<T extends DataCategory> = {
5
+ type Data<T extends DataCategory, U extends DataCategory> = {
6
6
  uuid: string;
7
7
  belongsTo: {
8
8
  uuid: string;
@@ -10,7 +10,7 @@ type Data<T extends DataCategory> = {
10
10
  };
11
11
  publicationDateTime: Date;
12
12
  metadata: Metadata;
13
- item: Tree | Set<T> | Resource | SpatialUnit | Concept | Period | Bibliography | Person | PropertyValue;
13
+ item: Tree<T, U> | Set<T> | Resource | SpatialUnit | Concept | Period | Bibliography | Person | PropertyValue;
14
14
  };
15
15
  type DataCategory = "tree" | "set" | "resource" | "spatialUnit" | "concept" | "period" | "bibliography" | "person" | "propertyValue";
16
16
  /**
@@ -426,7 +426,7 @@ type Property<T extends PropertyValueContentType = PropertyValueContentType> = {
426
426
  /**
427
427
  * Represents a tree structure containing resources, spatial units and concepts
428
428
  */
429
- type Tree = {
429
+ type Tree<T extends DataCategory, U extends DataCategory> = {
430
430
  uuid: string;
431
431
  category: "tree";
432
432
  publicationDateTime: Date | null;
@@ -436,16 +436,8 @@ type Tree = {
436
436
  license: License | null;
437
437
  identification: Identification;
438
438
  creators: Array<Person>;
439
- items: {
440
- resources: Array<Resource>;
441
- spatialUnits: Array<SpatialUnit>;
442
- concepts: Array<Concept>;
443
- periods: Array<Period>;
444
- bibliographies: Array<Bibliography>;
445
- persons: Array<Person>;
446
- propertyValues: Array<PropertyValue>;
447
- };
448
439
  properties: Array<Property>;
440
+ items: T extends "resource" ? Array<Resource> : T extends "spatialUnit" ? Array<SpatialUnit> : T extends "concept" ? Array<Concept> : T extends "period" ? Array<Period> : T extends "bibliography" ? Array<Bibliography> : T extends "person" ? Array<Person> : T extends "propertyValue" ? Array<PropertyValue> : T extends "set" ? Array<Set<U>> : never;
449
441
  };
450
442
  /**
451
443
  * Represents a gallery with its identification, project identification, resources and max length
@@ -470,6 +462,19 @@ type UuidMetadata = {
470
462
  website: string | null;
471
463
  };
472
464
  } | null;
465
+ /**
466
+ * Represents a level context item with a variable and value
467
+ */
468
+ type LevelContextItem = {
469
+ variableUuid: string;
470
+ valueUuid: string | null;
471
+ };
472
+ /**
473
+ * Represents a level context with a context item
474
+ */
475
+ type LevelContext = {
476
+ context: Array<LevelContextItem>;
477
+ };
473
478
  /**
474
479
  * Represents a website with its properties and elements
475
480
  */
@@ -496,36 +501,11 @@ type Website = {
496
501
  globalOptions: {
497
502
  collectionUuids: Array<string>;
498
503
  contexts: {
499
- flatten: Array<{
500
- context: Array<{
501
- variableUuid: string;
502
- valueUuid: string | null;
503
- }>;
504
- }>;
505
- suppress: Array<{
506
- context: Array<{
507
- variableUuid: string;
508
- valueUuid: string | null;
509
- }>;
510
- }>;
511
- search: Array<{
512
- context: Array<{
513
- variableUuid: string;
514
- valueUuid: string | null;
515
- }>;
516
- }>;
517
- active: Array<{
518
- context: Array<{
519
- variableUuid: string;
520
- valueUuid: string | null;
521
- }>;
522
- }>;
523
- label: Array<{
524
- context: Array<{
525
- variableUuid: string;
526
- valueUuid: string | null;
527
- }>;
528
- }>;
504
+ flatten: Array<LevelContext>;
505
+ suppress: Array<LevelContext>;
506
+ search: Array<LevelContext>;
507
+ active: Array<LevelContext>;
508
+ label: Array<LevelContext>;
529
509
  };
530
510
  };
531
511
  };
@@ -602,7 +582,7 @@ type WebElementComponent = {
602
582
  isSearchable: boolean;
603
583
  } | {
604
584
  component: "audio-player";
605
- audioUuid: string;
585
+ audioId: string;
606
586
  isSpeedControlsDisplayed: boolean;
607
587
  isVolumeControlsDisplayed: boolean;
608
588
  isSeekBarDisplayed: boolean;
@@ -833,7 +813,7 @@ declare function fetchItem<T extends DataCategory, U extends DataCategory>(uuid:
833
813
  uuid: string;
834
814
  abbreviation: string;
835
815
  };
836
- item: T extends "resource" ? Resource : T extends "spatialUnit" ? SpatialUnit : T extends "concept" ? Concept : T extends "period" ? Period : T extends "bibliography" ? Bibliography : T extends "person" ? Person : T extends "propertyValue" ? PropertyValue : T extends "set" ? Set<U> : T extends "tree" ? Tree : never;
816
+ item: T extends "resource" ? Resource : T extends "spatialUnit" ? SpatialUnit : T extends "concept" ? Concept : T extends "period" ? Period : T extends "bibliography" ? Bibliography : T extends "person" ? Person : T extends "propertyValue" ? PropertyValue : T extends "set" ? Set<U> : T extends "tree" ? Tree<T, U> : never;
837
817
  category: T;
838
818
  } | {
839
819
  error: string;
@@ -1065,4 +1045,4 @@ declare function filterProperties(property: Property, filter: {
1065
1045
  value: string | number | boolean | Date;
1066
1046
  }, options?: PropertyOptions): boolean;
1067
1047
  //#endregion
1068
- export { Bibliography, Concept, Context, ContextItem, ContextNode, Coordinates, CoordinatesItem, Data, DataCategory, Event, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyValue, PropertyValueContent, PropertyValueContentType, Resource, Set, SpatialUnit, Style, Tree, UuidMetadata, WebBlock, WebElement, WebElementComponent, WebImage, WebSectionSidebarItem, Webpage, WebpageProperties, Website, WebsiteProperties, fetchByUuidMetadata, fetchGallery, fetchItem, fetchWebsite, filterProperties, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
1048
+ 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, PropertyValue, PropertyValueContent, PropertyValueContentType, Resource, Set, SpatialUnit, Style, Tree, UuidMetadata, WebBlock, WebElement, WebElementComponent, WebImage, WebSectionSidebarItem, Webpage, WebpageProperties, Website, WebsiteProperties, fetchByUuidMetadata, fetchGallery, fetchItem, 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/v4";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`,`filter-categories`,`iframe`,`iiif-viewer`,`image`,`image-gallery`,`map`,`n-columns`,`n-rows`,`network-graph`,`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}function b(e,t){let n=e.find(e=>e.lang===t);return n??null}function x(e){let t=e.split(` `),n=[];for(let e of t){let t=e.replaceAll(/(?<=\s|^)[([{]+|[)\]}]+(?=\s|$)/g,``).replace(/[!),.:;?\]]$/,``),r=e.indexOf(t),i=e.slice(0,r),a=e.slice(r+t.length),o=l.safeParse(t).success;if(o){n.push(i,`${i}<ExternalLink href="mailto:${t}">${t}</ExternalLink>${a}`);continue}n.push(e)}return n.join(` `)}function S(e,t){let n=e,r=s.safeParse(t);if(!r.success)return console.warn(`Invalid render options string provided: “${t}”`),e;for(let e of r.data)switch(e){case`bold`:n=`**${n}**`;break;case`italic`:n=`*${n}*`;break;case`underline`:n=`_${n}_`;break}return n.replaceAll(`&#39;`,`'`)}function C(e,t){let n=e,r=c.safeParse(t);if(!r.success)return console.warn(`Invalid whitespace string provided: “${t}”`),e;for(let e of r.data)switch(e){case`newline`:n=`<br />\n${n}`;break;case`trailing`:n=`${n} `;break;case`leading`:n=` ${n}`;break}return n.replaceAll(`&#39;`,`'`)}function w(e){return String(e).replaceAll(`&#39;`,`'`)}function T(e){let t=``;switch(typeof e.string){case`string`:case`number`:case`boolean`:t=w(e.string);break;case`object`:{let n=Array.isArray(e.string)?e.string:[e.string];for(let e of n)if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)t+=w(e);else{let n=e.rend==null?w(e.content):S(w(e.content),e.rend),r=e.whitespace==null?n:C(n,e.whitespace);t+=r}break}default:t=``;break}return t}function E(e){if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return x(w(e));if(`whitespace`in e&&!(`content`in e)&&!(`string`in e))return e.whitespace===`newline`?`
2
- `:``;if(`links`in e){let t=``;t=typeof e.string==`object`?D(e.string):w(e.string).replaceAll(`<`,String.raw`\<`).replaceAll(`{`,String.raw`\{`);let n=Array.isArray(e.links)?e.links:[e.links];for(let e of n)if(`resource`in e){let n=Array.isArray(e.resource)?e.resource[0]:e.resource,r=null;switch(n.content!=null&&(r=w(n.content).replaceAll(`<`,String.raw`\<`).replaceAll(`{`,String.raw`\{`)),n.type){case`image`:return n.rend===`inline`?`<InlineImage uuid="${n.uuid}" ${r===null?``:`content="${r}"`} height={${n.height?.toString()??`null`}} width={${n.width?.toString()??`null`}} />`:n.publicationDateTime==null?`<TooltipSpan${r===null?``:` content="${r}"`}>${t}</TooltipSpan>`:`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`;case`internalDocument`:return`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`;case`externalDocument`:return n.publicationDateTime==null?`<TooltipSpan${r===null?``:` content="${r}"`}>${t}</TooltipSpan>`:`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${n.uuid}&load" ${r===null?``:`content="${r}"`}>${t}</ExternalLink>`;case`webpage`:return`<ExternalLink href="${n.href}" ${r===null?``:`content="${r}"`}>${t}</ExternalLink>`;default:return``}}else if(`concept`in e){let n=Array.isArray(e.concept)?e.concept[0]:e.concept;return n.publicationDateTime==null?`<TooltipSpan>${t}</TooltipSpan>`:`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`}else if(`set`in e){let n=Array.isArray(e.set)?e.set[0]:e.set;return n.publicationDateTime==null?`<TooltipSpan>${t}</TooltipSpan>`:`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`}else if(`person`in e){let n=Array.isArray(e.person)?e.person[0]:e.person,r=n.identification?[`string`,`number`,`boolean`].includes(typeof n.identification.label)?w(n.identification.label):D(n.identification.label):null;return n.publicationDateTime==null?`<TooltipSpan${r===null?``:` content="${r}"`}>${t}</TooltipSpan>`:`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`}else if(`bibliography`in e){let n=Array.isArray(e.bibliography)?e.bibliography[0]:e.bibliography;return n.publicationDateTime==null?`<TooltipSpan>${t}</TooltipSpan>`:`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`}}let t=``;if(`string`in e){let n=Array.isArray(e.string)?e.string:[e.string];for(let e of n)t+=E(e);return`whitespace`in e&&e.whitespace!=null&&(t=C(x(t),e.whitespace)),t.replaceAll(`&#39;`,`'`)}else t=w(e.content),e.rend!=null&&(t=S(x(t),e.rend)),e.whitespace!=null&&(t=C(x(t),e.whitespace));return t}function D(e,t=`eng`){switch(typeof e.content){case`string`:case`number`:case`boolean`:return w(e.content);case`object`:if(Array.isArray(e.content)){let n=b(e.content,t);if(n)return T(n);{let n=e.content[0];if(!n)throw Error(`No string item found for language “${t}” in the following content:\n${JSON.stringify(e.content)}.`);return T(n)}}else return T(e.content);default:return String(e.content)}}function O(e){let t=e.find(e=>i.safeParse(e).success);if(!t){let t=e.find(e=>![`uuid`,`uuidBelongsTo`,`belongsTo`,`publicationDateTime`,`metadata`,`languages`].includes(e));throw Error(`Invalid OCHRE data; found unexpected "${t}" key`)}let n=i.parse(t);return n}function k(e){try{let t={label:[`string`,`number`,`boolean`].includes(typeof e.label)?w(e.label):D(e.label),abbreviation:``};for(let n of Object.keys(e).filter(e=>e!==`label`))t[n]=D(e[n]);return t}catch(e){return console.error(e),{label:``,abbreviation:``}}}function ee(e){return e==null?[`eng`]:Array.isArray(e)?e.map(e=>D(e)):[D(e)]}function te(e){let t={label:``,abbreviation:``};if(e.item)if(e.item.label||e.item.abbreviation){let n=``,r=``;e.item.label&&(n=D(e.item.label)),e.item.abbreviation&&(r=D(e.item.abbreviation)),t={label:n,abbreviation:r}}else t=k(e.item.identification);let n=null,r=e.project?.identification?k(e.project.identification):null;return r&&(n={...r,website:e.project?.identification.website??null}),{project:n?{identification:n}:null,item:e.item?{identification:t,category:e.item.category,type:e.item.type,maxLength:e.item.maxLength??null}:null,dataset:D(e.dataset),publisher:D(e.publisher),languages:ee(e.language),identifier:D(e.identifier),description:D(e.description)}}function A(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),number:e.n,content:w(e.content)}}function j(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(A(e))}return{tree:A(e.tree),project:A(e.project),spatialUnit:t}}),displayPath:e.displayPath};return n}function M(e){return typeof e.license==`string`?null:{content:e.license.content,url:e.license.target}}function N(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?j(e.context):null,date:e.date==null?null:new Date(e.date),identification:e.identification?k(e.identification):null,availability:e.availability?M(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`?w(e.description):D(e.description):null,coordinates:z(e.coordinates),content:e.content==null?null:w(e.content),notes:e.notes?R(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],events:e.events?ae(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function P(e){let t=[];for(let n of e)t.push(N(n));return t}function ne(e){let t=`resource`in e?e.resource:`spatialUnit`in e?e.spatialUnit:`concept`in e?e.concept:`set`in e?e.set:`tree`in e?e.tree:`person`in e?e.person:`bibliography`in e?e.bibliography:`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:w(t.content):null,href:`href`in t&&t.href!=null?t.href:null,fileFormat:`fileFormat`in t&&t.fileFormat!=null?t.fileFormat:null,uuid:t.uuid??null,type:t.type??null,identification:t.identification?k(t.identification):null,image:null,bibliographies:`bibliography`in e?W(Array.isArray(e.bibliography)?e.bibliography:[e.bibliography]):null,publicationDateTime:t.publicationDateTime==null?null:new Date(t.publicationDateTime)};`height`in t&&t.height!=null&&t.width!=null&&t.heightPreview!=null&&t.widthPreview!=null&&(n.image={isInline:t.rend===`inline`,isPrimary:t.isPrimary??!1,heightPreview:t.heightPreview,widthPreview:t.widthPreview,height:t.height,width:t.width}),r.push(n)}return r}function F(e){let t=[];for(let n of e)t.push(...ne(n));return t}function I(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+=x(w(r.string));else{let e=Array.isArray(r.string)?r.string:[r.string];for(let t of e)n+=E(t)}return n}function L(e){return{publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),identification:e.identification?k(e.identification):null,url:e.href??(e.htmlImgSrcPrefix==null&&e.content!=null?w(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?w(e.content):null,widthPreview:e.widthPreview??null,heightPreview:e.heightPreview??null,width:e.width??null,height:e.height??null}}function R(e,t=`eng`){let n=[];for(let r of e){if(typeof r==`string`){if(r===``)continue;n.push({number:-1,title:null,content:r});continue}let e=``,i=Array.isArray(r.content)?r.content:[r.content],a=i.find(e=>e.lang===t);if(!a&&(a=i[0],!a))throw Error(`Note does not have a valid content item: ${JSON.stringify(r,null,2)}`);e=typeof a.string==`string`||typeof a.string==`number`||typeof a.string==`boolean`?x(w(a.string)):x(I(a)),n.push({number:r.noteNo,title:a.title==null?null:w(a.title),content:e})}return n}function z(e){if(e==null)return[];let t=[],n=Array.isArray(e.coord)?e.coord:[e.coord];for(let e of n){let n=`source`in e&&e.source?e.source.context===`self`?{context:`self`,uuid:e.source.label.uuid,label:D(e.source.label)}:e.source.context===`related`?{context:`related`,uuid:e.source.label.uuid,label:D(e.source.label),value:D(e.source.value)}:{context:`inherited`,uuid:e.source.label.uuid,item:{uuid:e.source.item.label.uuid,label:D(e.source.item.label)},label:D(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 re(e){return{number:e.observationNo,date:e.date==null?null:new Date(e.date),observers:e.observers==null?[]:typeof e.observers==`string`||typeof e.observers==`number`||typeof e.observers==`boolean`?w(e.observers).split(`;`).map(e=>e.trim()):P(Array.isArray(e.observers)?e.observers:[e.observers]),notes:e.notes?R(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?F(Array.isArray(e.links)?e.links:[e.links]):[],properties:e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function ie(e){let t=[];for(let n of e)t.push(re(n));return t}function ae(e){let t=[];for(let n of e)t.push({date:n.dateTime==null?null:new Date(n.dateTime),label:D(n.label),agent:n.agent?{uuid:n.agent.uuid,content:w(n.agent.content)}:null});return t}function 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=w(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`:e.rawValue==null?(t=Number(e.content),n=null):(t=Number(e.rawValue),n=e.content?D({content:e.content}):null);break;case`boolean`:e.rawValue==null?(t=e.content===!0,n=null):(t=e.rawValue===`true`,n=e.content?D({content:e.content}):null);break;default:`slug`in e&&e.slug!=null?t=w(e.slug):e.content!=null&&(e.rawValue==null?(t=D({content:e.content}),n=null):(t=w(e.rawValue),n=e.content?D({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:D(e.label,t).replace(/\s*\.{3}$/,``).trim(),values:r,comment:e.comment==null?null:w(e.comment),properties:e.property?B(Array.isArray(e.property)?e.property:[e.property]):[]}}function B(e,t=`eng`){let n=[];for(let r of e)n.push(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?B(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:w(e.title),shape:e.shape===`rect`?`rectangle`:`polygon`,coords:e.coords.split(`,`).map(e=>Number.parseInt(e))});return t}function V(e){return{uuid:e.uuid,category:`period`,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),type:e.type??null,number:e.n??null,identification:k(e.identification),description:e.description?D(e.description):null}}function H(e){let t=[];for(let n of e)t.push(V(n));return t}function U(e){let t=null;return e.source?.resource&&(t={uuid:e.source.resource.uuid,publicationDateTime:e.source.resource.publicationDateTime?new Date(e.source.resource.publicationDateTime):null,type:e.source.resource.type,identification:k(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?k(e.identification):null,projectIdentification:e.project?.identification?k(e.project.identification):null,context:e.context?j(e.context):null,citation:{details:e.citationDetails??null,format:e.citationFormat??null,short:e.citationFormatSpan?w(`default:span`in e.citationFormatSpan?e.citationFormatSpan[`default:span`].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?w(`default:div`in e.referenceFormatDiv?e.referenceFormatDiv[`default:div`][`default:div`].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?P(Array.isArray(e.publicationInfo.publishers.publishers.person)?e.publicationInfo.publishers.publishers.person:[e.publicationInfo.publishers.publishers.person]):[],startDate:e.publicationInfo?.startDate?new Date(e.publicationInfo.startDate.year,e.publicationInfo.startDate.month,e.publicationInfo.startDate.day):null},entryInfo:e.entryInfo?{startIssue:w(e.entryInfo.startIssue),startVolume:w(e.entryInfo.startVolume)}:null,source:{resource:t,documentUrl:e.sourceDocument?`https://ochre.lib.uchicago.edu/ochre?uuid=${e.sourceDocument.uuid}&load`:null},periods:e.periods?H(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],authors:e.authors?P(Array.isArray(e.authors.person)?e.authors.person:[e.authors.person]):[],properties:e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function W(e){let t=[];for(let n of e)t.push(U(n));return t}function G(e){return{uuid:e.uuid,category:`propertyValue`,number:e.n,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,context:e.context?j(e.context):null,availability:e.availability?M(e.availability):null,identification:k(e.identification),date:e.date?new Date(e.date):null,creators:e.creators?P(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`?w(e.description):D(e.description):``,notes:e.notes?R(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?F(Array.isArray(e.links)?e.links:[e.links]):[]}}function K(e){let t=[];for(let n of e)t.push(G(n));return t}function le(e){let t=[];e.creators&&(t=P(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]));let n=null;e.date!=null&&(n=new Date(e.date));let r=[],i=[],a=[],o=[],s=[],c=[],l=[];typeof e.items!=`string`&&`resource`in e.items&&(r=J(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource])),typeof e.items!=`string`&&`spatialUnit`in e.items&&(i=fe(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit])),typeof e.items!=`string`&&`concept`in e.items&&(a=me(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept])),typeof e.items!=`string`&&`period`in e.items&&(o=H(Array.isArray(e.items.period)?e.items.period:[e.items.period])),typeof e.items!=`string`&&`bibliography`in e.items&&(s=W(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography])),typeof e.items!=`string`&&`person`in e.items&&(c=P(Array.isArray(e.items.person)?e.items.person:[e.items.person])),typeof e.items!=`string`&&`propertyValue`in e.items&&(l=K(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]));let u={uuid:e.uuid,category:`tree`,publicationDateTime:new Date(e.publicationDateTime),identification:k(e.identification),creators:t,license:M(e.availability),date:n,type:e.type,number:e.n,items:{resources:r,spatialUnits:i,concepts:a,periods:o,bibliographies:s,persons:c,propertyValues:l},properties:e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return u}function ue(e,t){if(typeof e.items==`string`)throw TypeError(`Invalid OCHRE data: Set has no items`);let n=t??O(Object.keys(e.items)),r=[];switch(n){case`resource`:if(!(`resource`in e.items))throw Error(`Invalid OCHRE data: Set has no resources`);r=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=fe(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit]);break;case`concept`:if(!(`concept`in e.items))throw Error(`Invalid OCHRE data: Set has no concepts`);r=me(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept]);break;case`period`:if(!(`period`in e.items))throw Error(`Invalid OCHRE data: Set has no periods`);r=H(Array.isArray(e.items.period)?e.items.period:[e.items.period]);break;case`bibliography`:if(!(`bibliography`in e.items))throw Error(`Invalid OCHRE data: Set has no bibliographies`);r=W(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography]);break;case`person`:if(!(`person`in e.items))throw Error(`Invalid OCHRE data: Set has no persons`);r=P(Array.isArray(e.items.person)?e.items.person:[e.items.person]);break;case`propertyValue`:if(!(`propertyValue`in e.items))throw Error(`Invalid OCHRE data: Set has no property values`);r=K(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]);break;default:throw Error(`Invalid OCHRE data: Set has no items or is malformed`)}return{uuid:e.uuid,category:`set`,itemCategory:t,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,date:e.date==null?null:new Date(e.date),license:M(e.availability),identification:k(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?w(e.description):D(e.description):``,creators:e.creators?P(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],type:e.type,number:e.n,items:r}}function q(e){let t={uuid:e.uuid,category:`resource`,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,type:e.type,number:e.n,fileFormat:e.fileFormat??null,context:`context`in e&&e.context?j(e.context):null,license:`availability`in e&&e.availability?M(e.availability):null,copyright:`copyright`in e&&e.copyright!=null?w(e.copyright):null,identification:k(e.identification),date:e.date==null?null:new Date(e.date),image:e.image?L(e.image):null,creators:e.creators?P(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],notes:e.notes?R(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?w(e.description):D(e.description):``,coordinates:e.coordinates?z(e.coordinates):[],document:e.document&&`content`in e.document?I(e.document.content):null,href:e.href??null,imageMap:e.imagemap?ce(e.imagemap):null,periods:e.periods?H(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],links:e.links?F(Array.isArray(e.links)?e.links:[e.links]):[],reverseLinks:e.reverseLinks?F(Array.isArray(e.reverseLinks)?e.reverseLinks:[e.reverseLinks]):[],properties:e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],bibliographies:e.bibliographies?W(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(q(e));return t}function de(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?j(e.context):null,license:`availability`in e&&e.availability?M(e.availability):null,identification:k(e.identification),image:e.image?L(e.image):null,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?w(e.description):D(e.description):``,coordinates:z(e.coordinates),mapData:e.mapData??null,observations:`observations`in e&&e.observations?ie(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[re(e.observation)]:[],events:`events`in e&&e.events?ae(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:`properties`in e&&e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return t}function fe(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(de(e));return t}function pe(e){let t={uuid:e.uuid,category:`concept`,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,number:e.n,license:`availability`in e&&e.availability?M(e.availability):null,context:`context`in e&&e.context?j(e.context):null,identification:k(e.identification),interpretations:se(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation])};return t}const Y=async(e,t)=>{let n=[];for(let r of e){let e=r.properties?B(Array.isArray(r.properties.property)?r.properties.property:[r.properties.property]):[],i=e.find(e=>e.label===`presentation`&&e.values[0].content===t);if(!i)continue;switch(t){case`element`:{let e=await X(r);n.push(e);break}case`page`:{let e=await ge(r);e&&n.push(e);break}case`block`:{let e=await Z(r);e&&n.push(e);break}}}return n};function me(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(pe(e));return t}async function he(e,t){let n=r.parse(e.values[0].content),i={component:n},a=t.links?F(Array.isArray(t.links)?t.links:[t.links]):[],o=a.filter(e=>e.type===`image`||e.type===`IIIF`);switch(n){case`annotated-document`:{let e=a.find(e=>e.type===`internalDocument`);if(!e)throw Error(`Document link not found for the following component: “${n}”`);i.documentId=e.uuid;break}case`annotated-image`:{if(o.length===0)throw Error(`Image link not found for the following component: “${n}”`);let t=g(e.properties,`is-searchable`)===!0;i.imageUuid=o[0].uuid,i.isSearchable=t;break}case`audio-player`:{let t=a.find(e=>e.type===`audio`);if(!t)throw Error(`Audio link not found for the following component: “${n}”`);let r=!1,o=g(e.properties,`speed-controls-displayed`);o!==null&&(r=o===!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);let d=!1,f=g(e.properties,`download-button-displayed`);f!==null&&(d=f===!0),i.audioUuid=t.uuid,i.isSpeedControlsDisplayed=r,i.isVolumeControlsDisplayed=s,i.isSeekBarDisplayed=l,i.isDownloadButtonDisplayed=d;break}case`bibliography`:{let t=a.find(e=>e.category===`bibliography`);if(!t)throw Error(`Bibliography link not found for the following component: “${n}”`);if(!t.bibliographies)throw Error(`Bibliography not found for the following component: “${n}”`);let r=g(e.properties,`layout`);r??=`long`,i.bibliographies=t.bibliographies,i.layout=r;break}case`button`:{let r=g(e.properties,`variant`);r??=`default`;let a=!1,o=g(e.properties,`navigate-to`);if(o===null){if(o=g(e.properties,`link-to`),o===null)throw Error(`Properties “navigate-to” or “link-to” not found for the following component: “${n}”`);a=!0}let s=null,c=g(e.properties,`icon`);c!==null&&(s=c),i.variant=r,i.href=o,i.isExternal=a,i.label=[`string`,`number`,`boolean`].includes(typeof t.identification.label)?w(t.identification.label):D(t.identification.label),i.icon=s;break}case`collection`:{let t=a.find(e=>e.category===`set`);if(!t)throw Error(`Collection link not found for the following component: “${n}”`);let r=g(e.properties,`variant`);r??=`full`;let o=g(e.properties,`item-variant`);o??=`default`;let s=g(e.properties,`pagination-variant`);s??=`default`;let c=!1,l=g(e.properties,`show-count`);l!==null&&(c=l===!0);let u=!1,d=g(e.properties,`is-searchable`);d!==null&&(u=d===!0);let f=g(e.properties,`layout`);f??=`image-start`,i.collectionId=t.uuid,i.variant=r,i.itemVariant=o,i.paginationVariant=s,i.isSearchable=u,i.showCount=c,i.layout=f;break}case`empty-space`:{let t=g(e.properties,`height`),n=g(e.properties,`width`);i.height=t,i.width=n;break}case`entries`:{let t=a.find(e=>e.category===`tree`);if(!t)throw Error(`Entries link not found for the following component: “${n}”`);let r=g(e.properties,`variant`);r??=`entry`;let o=!1,s=g(e.properties,`is-searchable`);s!==null&&(o=s===!0),i.entriesId=t.uuid,i.variant=r,i.isSearchable=o;break}case`filter-categories`:{let e=a.find(e=>e.category===`set`);if(!e)throw Error(`Filter link not found for the following component: “${n}”`);i.filterId=e.uuid;break}case`iframe`:{let t=a.find(e=>e.type===`webpage`)?.href;if(!t)throw Error(`URL not found for the following component: “${n}”`);let r=g(e.properties,`height`),o=g(e.properties,`width`);i.href=t,i.height=r,i.width=o;break}case`iiif-viewer`:{let e=a.find(e=>e.type===`IIIF`);if(!e)throw Error(`Manifest link not found for the following component: “${n}”`);i.IIIFId=e.uuid;break}case`image`:{if(o.length===0)throw Error(`Image link not found for the following component: “${n}”`);let t=[];for(let e of o)t.push({url:`https://ochre.lib.uchicago.edu/ochre?uuid=${e.uuid}&load`,label:e.identification?.label??null,width:e.image?.width??0,height:e.image?.height??0});let r=g(e.properties,`variant`);r??=`default`;let a=g(e.properties,`layout-caption`);a??=`bottom`;let s=null,c=g(e.properties,`width`);c!==null&&(typeof c==`number`?s=c:typeof c==`string`&&(s=Number.parseFloat(c)));let l=null,u=g(e.properties,`height`);u!==null&&(typeof u==`number`?l=u:typeof u==`string`&&(l=Number.parseFloat(u)));let d=!0,f=g(e.properties,`is-full-width`);f!==null&&(d=f===!0);let p=!0,h=g(e.properties,`is-full-height`);h!==null&&(p=h===!0);let _=g(e.properties,`image-quality`);_??=`high`;let v=g(e.properties,`caption-source`);v??=`name`;let y=g(e.properties,`alt-text-source`);y??=`name`;let b=!1,x=g(e.properties,`is-transparent`);x!==null&&(b=x===!0);let S=!1,C=g(e.properties,`is-cover`);C!==null&&(S=C===!0);let w=null;if(t.length>1){let t=m(e.properties,`variant`),n=5;if(t&&t.values[0].content===`carousel`){let e=g(t.properties,`seconds-per-image`);e!==null&&(typeof e==`number`?n=e:typeof e==`string`&&(n=Number.parseFloat(e)))}w={secondsPerImage:n}}i.images=t,i.variant=r,i.width=s,i.height=l,i.isFullWidth=d,i.isFullHeight=p,i.imageQuality=_,i.captionLayout=a,i.captionSource=v,i.altTextSource=y,i.isTransparentBackground=b,i.isCover=S,i.carouselOptions=w;break}case`image-gallery`:{let t=a.find(e=>e.category===`tree`||e.category===`set`);if(!t)throw Error(`Image gallery link not found for the following component: “${n}”`);let r=g(e.properties,`is-searchable`)===!0;i.galleryId=t.uuid,i.isSearchable=r;break}case`map`:{let t=a.find(e=>e.category===`set`||e.category===`tree`);if(!t)throw Error(`Map link not found for the following component: “${n}”`);let r=!0,o=g(e.properties,`is-interactive`);o!==null&&(r=o===!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),i.mapId=t.uuid,i.isInteractive=r,i.isClustered=s,i.isUsingPins=l,i.customBasemap=d,i.isControlsDisplayed=p,i.isFullHeight=h;break}case`n-columns`:{let e=t.resource?await Y(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];i.columns=e;break}case`n-rows`:{let e=t.resource?await Y(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];i.rows=e;break}case`network-graph`:break;case`table`:{let e=a.find(e=>e.category===`set`);if(!e)throw Error(`Table link not found for the following component: “${n}”`);i.tableId=e.uuid;break}case`search-bar`:{let t=g(e.properties,`variant`);t??=`default`,i.variant=t;break}case`text`:{let r=t.document&&`content`in t.document?I(t.document.content):null;if(!r)throw Error(`Content not found for the following component: “${n}”`);let a=g(e.properties,`variant`);a??=`block`;let o=g(e.properties,`heading`);i.variant=a,i.heading=o,i.content=r;break}case`timeline`:{let e=a.find(e=>e.category===`tree`);if(!e)throw Error(`Timeline link not found for the following component: “${n}”`);i.timelineId=e.uuid;break}case`video`:{let t=a.find(e=>e.type===`video`);if(!t)throw Error(`Video link not found for the following component: “${n}”`);let r=g(e.properties,`chapters-displayed`);r??=!0,i.videoId=t.uuid,i.isChaptersDislayed=r===!0;break}default:console.warn(`Invalid or non-implemented component name “${n}” for the following element: “${D(t.identification.label)}”`);break}return i}async function X(e){let t=k(e.identification),n=e.properties?.property?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],r=n.find(e=>e.label===`presentation`);if(!r)throw Error(`Presentation property not found for element “${t.label}”`);let i=r.properties.find(e=>e.label===`component`);if(!i)throw Error(`Component for element “${t.label}” not found`);let a=await he(i,e),o=r.properties.find(e=>e.label===`section-sidebar-displayed`),s=o?.values[0]?.content===!0,c=e.properties?.property?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],l=c.find(e=>e.label===`presentation`&&e.values[0].content===`css`)?.properties??[],u=[];for(let e of l){let t=e.values[0].content;u.push({label:e.label,value:t})}let d=c.find(e=>e.label===`presentation`&&e.values[0].content===`css-mobile`)?.properties??[],f=[];for(let e of d){let t=e.values[0].content;f.push({label:e.label,value:t})}let p=c.find(e=>e.label===`presentation`&&e.values[0].content===`title`)?.properties,m=`default`,h=!1,_=!1,v=!1,y=!1;if(p){let e=g(p,`variant`);e&&(m=e);let t=p.filter(e=>e.label===`display`);t.length>0&&(h=t.some(e=>e.values[0].content===`name`),_=t.some(e=>e.values[0].content===`description`),v=t.some(e=>e.values[0].content===`date`),y=t.some(e=>e.values[0].content===`creators`))}return{uuid:e.uuid,type:`element`,title:{label:t.label,variant:m,properties:{isNameDisplayed:h,isDescriptionDisplayed:_,isDateDisplayed:v,isCreatorsDisplayed:y}},isDisplayedInBlockSectionSidebar:s,cssStyles:u,cssStylesMobile:f,...a}}async function ge(e){let t=e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];if(t.length===0||t.find(e=>e.label===`presentation`)?.values[0]?.content!==`page`)return null;let n=k(e.identification),r=e.slug;if(r===void 0)throw Error(`Slug not found for page “${n.label}”`);let i=e.links?F(Array.isArray(e.links)?e.links:[e.links]):[],a=i.find(e=>e.type===`image`||e.type===`IIIF`),o=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],s=[];for(let e of o){let t=e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=g(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 Y(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 _e(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n){let n=await ge(e);n&&t.push(n)}return t}async function 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?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],r=n.find(e=>e.label===`presentation`&&e.values[0]?.content===`block`)?.properties;if(r){let e=r.find(e=>e.label===`layout`)?.values[0];e&&(t.layout=e.content);let n=r.find(e=>e.label===`spacing`)?.values[0];n&&(t.properties.spacing=n.content);let i=r.find(e=>e.label===`gap`)?.values[0];i&&(t.properties.gap=i.content);let a=r.find(e=>e.label===`align-items`)?.values[0];a&&(t.properties.alignItems=a.content);let o=r.find(e=>e.label===`justify-content`)?.values[0];o&&(t.properties.justifyContent=o.content);let s=r.find(e=>e.label===`overwrite-mobile`);if(s){let e=s.properties,n={};for(let t of e)n[t.label]=t.values[0].content;t.propertiesMobile=n}}let i=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],a=[];for(let e of i){let t=e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=g(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=Q(t),t}function Q(e){let t=[];for(let n of e.items)switch(n.type){case`block`:{let e=Q(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 ve(e){let t=B(e),r=t.find(e=>e.label===`presentation`)?.properties;if(!r)throw Error(`Presentation property not found`);let i=r.find(e=>e.label===`webUI`)?.values[0]?.content;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 $(e){return e.map(e=>({context:Array.isArray(e.context)?e.context.flatMap(e=>Array.isArray(e.level)?e.level.map(e=>({variableUuid:e.split(`,`)[0]??``,valueUuid:e.split(`,`)[1]?.trim()===`null`?null:e.split(`,`)[1]?.trim()??null})):[{variableUuid:e.level.split(`,`)[0]??``,valueUuid:e.level.split(`,`)[1]?.trim()===`null`?null:e.level.split(`,`)[1]?.trim()??null}]):[...Array.isArray(e.context.level)?e.context.level.map(e=>({variableUuid:e.split(`,`)[0]??``,valueUuid:e.split(`,`)[1]?.trim()===`null`?null:e.split(`,`)[1]?.trim()??null})):[{variableUuid:e.context.level.split(`,`)[0]??``,valueUuid:e.context.level.split(`,`)[1]?.trim()===`null`?null:e.context.level.split(`,`)[1]?.trim()??null}]]}))}async function ye(e,t,n){if(!e.properties)throw Error(`Website properties not found`);let r=ve(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]);if(typeof e.items==`string`||!(`resource`in e.items))throw Error(`Website pages not found`);let i=Array.isArray(e.items.resource)?e.items.resource:[e.items.resource],a=await _e(i),o=null,s=[],c={label:``,variant:`default`,properties:{isNameDisplayed:!1,isDescriptionDisplayed:!1,isDateDisplayed:!1,isCreatorsDisplayed:!1}},l=`start`,u=`default`,d=[],f=[],p=i.find(e=>{let t=e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];return t.some(e=>e.label===`presentation`&&e.values[0]?.content===`element`&&e.properties[0]?.label===`component`&&e.properties[0].values[0]?.content===`sidebar`)});if(p){c.label=typeof p.identification.label==`string`||typeof p.identification.label==`number`||typeof p.identification.label==`boolean`?w(p.identification.label):D(p.identification.label);let e=p.properties?B(Array.isArray(p.properties.property)?p.properties.property:[p.properties.property]):[],t=e.find(e=>e.label===`presentation`&&e.values[0]?.content===`element`)?.properties.find(e=>e.label===`component`&&e.values[0]?.content===`sidebar`)?.properties??[],n=t.find(e=>e.label===`layout`);n&&(l=n.values[0].content);let r=t.find(e=>e.label===`layout-mobile`);r&&(u=r.values[0].content);let i=e.find(e=>e.label===`presentation`&&e.values[0].content===`css`)?.properties??[];for(let e of i){let t=e.values[0].content;d.push({label:e.label,value:t})}let a=e.find(e=>e.label===`presentation`&&e.values[0].content===`css-mobile`)?.properties??[];for(let e of a){let t=e.values[0].content;f.push({label:e.label,value:t})}let o=e.find(e=>e.label===`presentation`&&e.values[0].content===`title`)?.properties;if(o){let e=g(o,`variant`);e&&(c.variant=e);let t=o.filter(e=>e.label===`display`);t.length>0&&(c.properties.isNameDisplayed=t.some(e=>e.values[0].content===`name`),c.properties.isDescriptionDisplayed=t.some(e=>e.values[0].content===`description`),c.properties.isDateDisplayed=t.some(e=>e.values[0].content===`date`),c.properties.isCreatorsDisplayed=t.some(e=>e.values[0].content===`creators`))}let m=p.resource?Array.isArray(p.resource)?p.resource:[p.resource]:[];for(let e of m){let t=await X(e);s.push(t)}}s.length>0&&(o={elements:s,title:c,layout:l,mobileLayout:u,cssStyles:d,cssStylesMobile:f});let m={collectionUuids:[],contexts:{flatten:[],search:[],active:[],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.searchContexts==null?[]:Array.isArray(e.websiteOptions.searchContexts)?e.websiteOptions.searchContexts:[e.websiteOptions.searchContexts],i=e.websiteOptions.activeContexts==null?[]:Array.isArray(e.websiteOptions.activeContexts)?e.websiteOptions.activeContexts:[e.websiteOptions.activeContexts],a=e.websiteOptions.labelContexts==null?[]:Array.isArray(e.websiteOptions.labelContexts)?e.websiteOptions.labelContexts:[e.websiteOptions.labelContexts];m={collectionUuids:e.websiteOptions.collectionUuids==null?[]:(Array.isArray(e.websiteOptions.collectionUuids.uuid)?e.websiteOptions.collectionUuids.uuid:[e.websiteOptions.collectionUuids.uuid]).map(e=>e.content),contexts:{flatten:$(t),search:$(r),active:$(i),label:$(a),suppress:$(n)}}}return{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:k(e.identification),project:{name:w(t),website:n===null?null:w(n)},creators:e.creators?P(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:M(e.availability),pages:a,sidebar:o,properties:r,globalOptions:m}}async function be(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`?D(e.string):w(e.string).replaceAll(`<`,String.raw`\<`).replaceAll(`{`,String.raw`\{`);let n=Array.isArray(e.links)?e.links:[e.links];for(let e of n)if(`resource`in e){let n=Array.isArray(e.resource)?e.resource[0]:e.resource,r=null;switch(n.content!=null&&(r=w(n.content).replaceAll(`<`,String.raw`\<`).replaceAll(`{`,String.raw`\{`)),n.type){case`image`:return n.rend===`inline`?`<InlineImage uuid="${n.uuid}" ${r===null?``:`content="${r}"`} height={${n.height?.toString()??`null`}} width={${n.width?.toString()??`null`}} />`:n.publicationDateTime==null?`<TooltipSpan${r===null?``:` content="${r}"`}>${t}</TooltipSpan>`:`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`;case`internalDocument`:return`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`;case`externalDocument`:return n.publicationDateTime==null?`<TooltipSpan${r===null?``:` content="${r}"`}>${t}</TooltipSpan>`:`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${n.uuid}&load" ${r===null?``:`content="${r}"`}>${t}</ExternalLink>`;case`webpage`:return`<ExternalLink href="${n.href}" ${r===null?``:`content="${r}"`}>${t}</ExternalLink>`;default:return``}}else if(`concept`in e){let n=Array.isArray(e.concept)?e.concept[0]:e.concept;return n.publicationDateTime==null?`<TooltipSpan>${t}</TooltipSpan>`:`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`}else if(`set`in e){let n=Array.isArray(e.set)?e.set[0]:e.set;return n.publicationDateTime==null?`<TooltipSpan>${t}</TooltipSpan>`:`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`}else if(`person`in e){let n=Array.isArray(e.person)?e.person[0]:e.person,r=n.identification?[`string`,`number`,`boolean`].includes(typeof n.identification.label)?w(n.identification.label):D(n.identification.label):null;return n.publicationDateTime==null?`<TooltipSpan${r===null?``:` content="${r}"`}>${t}</TooltipSpan>`:`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`}else if(`bibliography`in e){let n=Array.isArray(e.bibliography)?e.bibliography[0]:e.bibliography;return n.publicationDateTime==null?`<TooltipSpan>${t}</TooltipSpan>`:`<InternalLink uuid="${n.uuid}">${t}</InternalLink>`}}let t=``;if(`string`in e){let n=Array.isArray(e.string)?e.string:[e.string];for(let e of n)t+=E(e);return`whitespace`in e&&e.whitespace!=null&&(t=C(x(t),e.whitespace)),t.replaceAll(`&#39;`,`'`)}else t=w(e.content),e.rend!=null&&(t=S(x(t),e.rend)),e.whitespace!=null&&(t=C(x(t),e.whitespace));return t}function D(e,t=`eng`){switch(typeof e.content){case`string`:case`number`:case`boolean`:return w(e.content);case`object`:if(Array.isArray(e.content)){let n=b(e.content,t);if(n)return T(n);{let n=e.content[0];if(!n)throw Error(`No string item found for language “${t}” in the following content:\n${JSON.stringify(e.content)}.`);return T(n)}}else return T(e.content);default:return String(e.content)}}function O(e){let t=e.find(e=>i.safeParse(e).success);if(!t){let t=e.find(e=>![`uuid`,`uuidBelongsTo`,`belongsTo`,`publicationDateTime`,`metadata`,`languages`].includes(e));throw Error(`Invalid OCHRE data; found unexpected "${t}" key`)}let n=i.parse(t);return n}function k(e){try{let t={label:[`string`,`number`,`boolean`].includes(typeof e.label)?w(e.label):D(e.label),abbreviation:``};for(let n of Object.keys(e).filter(e=>e!==`label`))t[n]=D(e[n]);return t}catch(e){return console.error(e),{label:``,abbreviation:``}}}function ee(e){return e==null?[`eng`]:Array.isArray(e)?e.map(e=>D(e)):[D(e)]}function te(e){let t={label:``,abbreviation:``};if(e.item)if(e.item.label||e.item.abbreviation){let n=``,r=``;e.item.label&&(n=D(e.item.label)),e.item.abbreviation&&(r=D(e.item.abbreviation)),t={label:n,abbreviation:r}}else t=k(e.item.identification);let n=null,r=e.project?.identification?k(e.project.identification):null;return r&&(n={...r,website:e.project?.identification.website??null}),{project:n?{identification:n}:null,item:e.item?{identification:t,category:e.item.category,type:e.item.type,maxLength:e.item.maxLength??null}:null,dataset:D(e.dataset),publisher:D(e.publisher),languages:ee(e.language),identifier:D(e.identifier),description:D(e.description)}}function A(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),number:e.n,content:w(e.content)}}function j(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(A(e))}return{tree:A(e.tree),project:A(e.project),spatialUnit:t}}),displayPath:e.displayPath};return n}function M(e){return typeof e.license==`string`?null:{content:e.license.content,url:e.license.target}}function N(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?j(e.context):null,date:e.date==null?null:new Date(e.date),identification:e.identification?k(e.identification):null,availability:e.availability?M(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`?w(e.description):D(e.description):null,coordinates:z(e.coordinates),content:e.content==null?null:w(e.content),notes:e.notes?R(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],events:e.events?ae(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function P(e){let t=[];for(let n of e)t.push(N(n));return t}function ne(e){let t=`resource`in e?e.resource:`spatialUnit`in e?e.spatialUnit:`concept`in e?e.concept:`set`in e?e.set:`tree`in e?e.tree:`person`in e?e.person:`bibliography`in e?e.bibliography:`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:w(t.content):null,href:`href`in t&&t.href!=null?t.href:null,fileFormat:`fileFormat`in t&&t.fileFormat!=null?t.fileFormat:null,uuid:t.uuid??null,type:t.type??null,identification:t.identification?k(t.identification):null,image:null,bibliographies:`bibliography`in e?W(Array.isArray(e.bibliography)?e.bibliography:[e.bibliography]):null,publicationDateTime:t.publicationDateTime==null?null:new Date(t.publicationDateTime)};`height`in t&&t.height!=null&&t.width!=null&&t.heightPreview!=null&&t.widthPreview!=null&&(n.image={isInline:t.rend===`inline`,isPrimary:t.isPrimary??!1,heightPreview:t.heightPreview,widthPreview:t.widthPreview,height:t.height,width:t.width}),r.push(n)}return r}function F(e){let t=[];for(let n of e)t.push(...ne(n));return t}function I(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+=x(w(r.string));else{let e=Array.isArray(r.string)?r.string:[r.string];for(let t of e)n+=E(t)}return n}function L(e){return{publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),identification:e.identification?k(e.identification):null,url:e.href??(e.htmlImgSrcPrefix==null&&e.content!=null?w(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?w(e.content):null,widthPreview:e.widthPreview??null,heightPreview:e.heightPreview??null,width:e.width??null,height:e.height??null}}function R(e,t=`eng`){let n=[];for(let r of e){if(typeof r==`string`){if(r===``)continue;n.push({number:-1,title:null,content:r});continue}let e=``,i=Array.isArray(r.content)?r.content:[r.content],a=i.find(e=>e.lang===t);if(!a&&(a=i[0],!a))throw Error(`Note does not have a valid content item: ${JSON.stringify(r,null,2)}`);e=typeof a.string==`string`||typeof a.string==`number`||typeof a.string==`boolean`?x(w(a.string)):x(I(a)),n.push({number:r.noteNo,title:a.title==null?null:w(a.title),content:e})}return n}function z(e){if(e==null)return[];let t=[],n=Array.isArray(e.coord)?e.coord:[e.coord];for(let e of n){let n=`source`in e&&e.source?e.source.context===`self`?{context:`self`,uuid:e.source.label.uuid,label:D(e.source.label)}:e.source.context===`related`?{context:`related`,uuid:e.source.label.uuid,label:D(e.source.label),value:D(e.source.value)}:{context:`inherited`,uuid:e.source.label.uuid,item:{uuid:e.source.item.label.uuid,label:D(e.source.item.label)},label:D(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 re(e){return{number:e.observationNo,date:e.date==null?null:new Date(e.date),observers:e.observers==null?[]:typeof e.observers==`string`||typeof e.observers==`number`||typeof e.observers==`boolean`?w(e.observers).split(`;`).map(e=>e.trim()):P(Array.isArray(e.observers)?e.observers:[e.observers]),notes:e.notes?R(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?F(Array.isArray(e.links)?e.links:[e.links]):[],properties:e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function ie(e){let t=[];for(let n of e)t.push(re(n));return t}function ae(e){let t=[];for(let n of e)t.push({date:n.dateTime==null?null:new Date(n.dateTime),label:D(n.label),agent:n.agent?{uuid:n.agent.uuid,content:w(n.agent.content)}:null});return t}function 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=w(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`:e.rawValue==null?(t=Number(e.content),n=null):(t=Number(e.rawValue),n=e.content?D({content:e.content}):null);break;case`boolean`:e.rawValue==null?(t=e.content===!0,n=null):(t=e.rawValue===`true`,n=e.content?D({content:e.content}):null);break;default:`slug`in e&&e.slug!=null?t=w(e.slug):e.content!=null&&(e.rawValue==null?(t=D({content:e.content}),n=null):(t=w(e.rawValue),n=e.content?D({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:D(e.label,t).replace(/\s*\.{3}$/,``).trim(),values:r,comment:e.comment==null?null:w(e.comment),properties:e.property?B(Array.isArray(e.property)?e.property:[e.property]):[]}}function B(e,t=`eng`){let n=[];for(let r of e)n.push(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?B(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:w(e.title),shape:e.shape===`rect`?`rectangle`:`polygon`,coords:e.coords.split(`,`).map(e=>Number.parseInt(e))});return t}function V(e){return{uuid:e.uuid,category:`period`,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),type:e.type??null,number:e.n??null,identification:k(e.identification),description:e.description?D(e.description):null}}function H(e){let t=[];for(let n of e)t.push(V(n));return t}function U(e){let t=null;return e.source?.resource&&(t={uuid:e.source.resource.uuid,publicationDateTime:e.source.resource.publicationDateTime?new Date(e.source.resource.publicationDateTime):null,type:e.source.resource.type,identification:k(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?k(e.identification):null,projectIdentification:e.project?.identification?k(e.project.identification):null,context:e.context?j(e.context):null,citation:{details:e.citationDetails??null,format:e.citationFormat??null,short:e.citationFormatSpan?w(`default:span`in e.citationFormatSpan?e.citationFormatSpan[`default:span`].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?w(`default:div`in e.referenceFormatDiv?e.referenceFormatDiv[`default:div`][`default:div`].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?P(Array.isArray(e.publicationInfo.publishers.publishers.person)?e.publicationInfo.publishers.publishers.person:[e.publicationInfo.publishers.publishers.person]):[],startDate:e.publicationInfo?.startDate?new Date(e.publicationInfo.startDate.year,e.publicationInfo.startDate.month,e.publicationInfo.startDate.day):null},entryInfo:e.entryInfo?{startIssue:w(e.entryInfo.startIssue),startVolume:w(e.entryInfo.startVolume)}:null,source:{resource:t,documentUrl:e.sourceDocument?`https://ochre.lib.uchicago.edu/ochre?uuid=${e.sourceDocument.uuid}&load`:null},periods:e.periods?H(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],authors:e.authors?P(Array.isArray(e.authors.person)?e.authors.person:[e.authors.person]):[],properties:e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function W(e){let t=[];for(let n of e)t.push(U(n));return t}function G(e){return{uuid:e.uuid,category:`propertyValue`,number:e.n,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,context:e.context?j(e.context):null,availability:e.availability?M(e.availability):null,identification:k(e.identification),date:e.date?new Date(e.date):null,creators:e.creators?P(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`?w(e.description):D(e.description):``,notes:e.notes?R(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?F(Array.isArray(e.links)?e.links:[e.links]):[]}}function K(e){let t=[];for(let n of e)t.push(G(n));return t}function le(e,t,n){if(typeof e.items==`string`)throw TypeError(`Invalid OCHRE data: Tree has no items`);let r=[];e.creators&&(r=P(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]));let i=null;e.date!=null&&(i=new Date(e.date));let a=t??O(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=fe(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit]);break;case`concept`:if(!(`concept`in e.items))throw Error(`Invalid OCHRE data: Tree has no concepts`);o=me(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept]);break;case`period`:if(!(`period`in e.items))throw Error(`Invalid OCHRE data: Tree has no periods`);o=H(Array.isArray(e.items.period)?e.items.period:[e.items.period]);break;case`bibliography`:if(!(`bibliography`in e.items))throw Error(`Invalid OCHRE data: Tree has no bibliographies`);o=W(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography]);break;case`person`:if(!(`person`in e.items))throw Error(`Invalid OCHRE data: Tree has no persons`);o=P(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=K(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(q(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:k(e.identification),creators:r,license:M(e.availability),date:i,type:e.type,number:e.n,items:o,properties:e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return s}function q(e,t){if(typeof e.items==`string`)throw TypeError(`Invalid OCHRE data: Set has no items`);let n=t??O(Object.keys(e.items)),r=[];switch(n){case`resource`:if(!(`resource`in e.items))throw Error(`Invalid OCHRE data: Set has no resources`);r=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=fe(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit]);break;case`concept`:if(!(`concept`in e.items))throw Error(`Invalid OCHRE data: Set has no concepts`);r=me(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept]);break;case`period`:if(!(`period`in e.items))throw Error(`Invalid OCHRE data: Set has no periods`);r=H(Array.isArray(e.items.period)?e.items.period:[e.items.period]);break;case`bibliography`:if(!(`bibliography`in e.items))throw Error(`Invalid OCHRE data: Set has no bibliographies`);r=W(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography]);break;case`person`:if(!(`person`in e.items))throw Error(`Invalid OCHRE data: Set has no persons`);r=P(Array.isArray(e.items.person)?e.items.person:[e.items.person]);break;case`propertyValue`:if(!(`propertyValue`in e.items))throw Error(`Invalid OCHRE data: Set has no property values`);r=K(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]);break;default:throw Error(`Invalid OCHRE data: Set has no items or is malformed`)}return{uuid:e.uuid,category:`set`,itemCategory:t,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,date:e.date==null?null:new Date(e.date),license:M(e.availability),identification:k(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?w(e.description):D(e.description):``,creators:e.creators?P(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],type:e.type,number:e.n,items:r}}function ue(e){let t={uuid:e.uuid,category:`resource`,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,type:e.type,number:e.n,fileFormat:e.fileFormat??null,context:`context`in e&&e.context?j(e.context):null,license:`availability`in e&&e.availability?M(e.availability):null,copyright:`copyright`in e&&e.copyright!=null?w(e.copyright):null,identification:k(e.identification),date:e.date==null?null:new Date(e.date),image:e.image?L(e.image):null,creators:e.creators?P(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],notes:e.notes?R(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?w(e.description):D(e.description):``,coordinates:e.coordinates?z(e.coordinates):[],document:e.document&&`content`in e.document?I(e.document.content):null,href:e.href??null,imageMap:e.imagemap?ce(e.imagemap):null,periods:e.periods?H(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],links:e.links?F(Array.isArray(e.links)?e.links:[e.links]):[],reverseLinks:e.reverseLinks?F(Array.isArray(e.reverseLinks)?e.reverseLinks:[e.reverseLinks]):[],properties:e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],bibliographies:e.bibliographies?W(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(ue(e));return t}function de(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?j(e.context):null,license:`availability`in e&&e.availability?M(e.availability):null,identification:k(e.identification),image:e.image?L(e.image):null,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?w(e.description):D(e.description):``,coordinates:z(e.coordinates),mapData:e.mapData??null,observations:`observations`in e&&e.observations?ie(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[re(e.observation)]:[],events:`events`in e&&e.events?ae(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:`properties`in e&&e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return t}function fe(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(de(e));return t}function pe(e){let t={uuid:e.uuid,category:`concept`,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,number:e.n,license:`availability`in e&&e.availability?M(e.availability):null,context:`context`in e&&e.context?j(e.context):null,identification:k(e.identification),interpretations:se(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation])};return t}const Y=async(e,t)=>{let n=[];for(let r of e){let e=r.properties?B(Array.isArray(r.properties.property)?r.properties.property:[r.properties.property]):[],i=e.find(e=>e.label===`presentation`&&e.values[0].content===t);if(!i)continue;switch(t){case`element`:{let e=await X(r);n.push(e);break}case`page`:{let e=await ge(r);e&&n.push(e);break}case`block`:{let e=await Z(r);e&&n.push(e);break}}}return n};function me(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(pe(e));return t}async function he(e,t){let n=r.parse(e.values[0].content),i={component:n},a=t.links?F(Array.isArray(t.links)?t.links:[t.links]):[],o=a.filter(e=>e.type===`image`||e.type===`IIIF`);switch(n){case`annotated-document`:{let e=a.find(e=>e.type===`internalDocument`);if(!e)throw Error(`Document link not found for the following component: “${n}”`);i.documentId=e.uuid;break}case`annotated-image`:{if(o.length===0)throw Error(`Image link not found for the following component: “${n}”`);let t=g(e.properties,`is-searchable`)===!0;i.imageUuid=o[0].uuid,i.isSearchable=t;break}case`audio-player`:{let t=a.find(e=>e.type===`audio`);if(!t)throw Error(`Audio link not found for the following component: “${n}”`);let r=!1,o=g(e.properties,`speed-controls-displayed`);o!==null&&(r=o===!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);let d=!1,f=g(e.properties,`download-button-displayed`);f!==null&&(d=f===!0),i.audioId=t.uuid,i.isSpeedControlsDisplayed=r,i.isVolumeControlsDisplayed=s,i.isSeekBarDisplayed=l,i.isDownloadButtonDisplayed=d;break}case`bibliography`:{let t=a.find(e=>e.category===`bibliography`);if(!t)throw Error(`Bibliography link not found for the following component: “${n}”`);if(!t.bibliographies)throw Error(`Bibliography not found for the following component: “${n}”`);let r=g(e.properties,`layout`);r??=`long`,i.bibliographies=t.bibliographies,i.layout=r;break}case`button`:{let r=g(e.properties,`variant`);r??=`default`;let a=!1,o=g(e.properties,`navigate-to`);if(o===null){if(o=g(e.properties,`link-to`),o===null)throw Error(`Properties “navigate-to” or “link-to” not found for the following component: “${n}”`);a=!0}let s=null,c=g(e.properties,`icon`);c!==null&&(s=c),i.variant=r,i.href=o,i.isExternal=a,i.label=[`string`,`number`,`boolean`].includes(typeof t.identification.label)?w(t.identification.label):D(t.identification.label),i.icon=s;break}case`collection`:{let t=a.find(e=>e.category===`set`);if(!t)throw Error(`Collection link not found for the following component: “${n}”`);let r=g(e.properties,`variant`);r??=`full`;let o=g(e.properties,`item-variant`);o??=`default`;let s=g(e.properties,`pagination-variant`);s??=`default`;let c=!1,l=g(e.properties,`show-count`);l!==null&&(c=l===!0);let u=!1,d=g(e.properties,`is-searchable`);d!==null&&(u=d===!0);let f=g(e.properties,`layout`);f??=`image-start`,i.collectionId=t.uuid,i.variant=r,i.itemVariant=o,i.paginationVariant=s,i.isSearchable=u,i.showCount=c,i.layout=f;break}case`empty-space`:{let t=g(e.properties,`height`),n=g(e.properties,`width`);i.height=t,i.width=n;break}case`entries`:{let t=a.find(e=>e.category===`tree`);if(!t)throw Error(`Entries link not found for the following component: “${n}”`);let r=g(e.properties,`variant`);r??=`entry`;let o=!1,s=g(e.properties,`is-searchable`);s!==null&&(o=s===!0),i.entriesId=t.uuid,i.variant=r,i.isSearchable=o;break}case`filter-categories`:{let e=a.find(e=>e.category===`set`);if(!e)throw Error(`Filter link not found for the following component: “${n}”`);i.filterId=e.uuid;break}case`iframe`:{let t=a.find(e=>e.type===`webpage`)?.href;if(!t)throw Error(`URL not found for the following component: “${n}”`);let r=g(e.properties,`height`),o=g(e.properties,`width`);i.href=t,i.height=r,i.width=o;break}case`iiif-viewer`:{let e=a.find(e=>e.type===`IIIF`);if(!e)throw Error(`Manifest link not found for the following component: “${n}”`);i.IIIFId=e.uuid;break}case`image`:{if(o.length===0)throw Error(`Image link not found for the following component: “${n}”`);let t=[];for(let e of o)t.push({url:`https://ochre.lib.uchicago.edu/ochre?uuid=${e.uuid}&load`,label:e.identification?.label??null,width:e.image?.width??0,height:e.image?.height??0});let r=g(e.properties,`variant`);r??=`default`;let a=g(e.properties,`layout-caption`);a??=`bottom`;let s=null,c=g(e.properties,`width`);c!==null&&(typeof c==`number`?s=c:typeof c==`string`&&(s=Number.parseFloat(c)));let l=null,u=g(e.properties,`height`);u!==null&&(typeof u==`number`?l=u:typeof u==`string`&&(l=Number.parseFloat(u)));let d=!0,f=g(e.properties,`is-full-width`);f!==null&&(d=f===!0);let p=!0,h=g(e.properties,`is-full-height`);h!==null&&(p=h===!0);let _=g(e.properties,`image-quality`);_??=`high`;let v=g(e.properties,`caption-source`);v??=`name`;let y=g(e.properties,`alt-text-source`);y??=`name`;let b=!1,x=g(e.properties,`is-transparent`);x!==null&&(b=x===!0);let S=!1,C=g(e.properties,`is-cover`);C!==null&&(S=C===!0);let w=null;if(t.length>1){let t=m(e.properties,`variant`),n=5;if(t&&t.values[0].content===`carousel`){let e=g(t.properties,`seconds-per-image`);e!==null&&(typeof e==`number`?n=e:typeof e==`string`&&(n=Number.parseFloat(e)))}w={secondsPerImage:n}}i.images=t,i.variant=r,i.width=s,i.height=l,i.isFullWidth=d,i.isFullHeight=p,i.imageQuality=_,i.captionLayout=a,i.captionSource=v,i.altTextSource=y,i.isTransparentBackground=b,i.isCover=S,i.carouselOptions=w;break}case`image-gallery`:{let t=a.find(e=>e.category===`tree`||e.category===`set`);if(!t)throw Error(`Image gallery link not found for the following component: “${n}”`);let r=g(e.properties,`is-searchable`)===!0;i.galleryId=t.uuid,i.isSearchable=r;break}case`map`:{let t=a.find(e=>e.category===`set`||e.category===`tree`);if(!t)throw Error(`Map link not found for the following component: “${n}”`);let r=!0,o=g(e.properties,`is-interactive`);o!==null&&(r=o===!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),i.mapId=t.uuid,i.isInteractive=r,i.isClustered=s,i.isUsingPins=l,i.customBasemap=d,i.isControlsDisplayed=p,i.isFullHeight=h;break}case`n-columns`:{let e=t.resource?await Y(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];i.columns=e;break}case`n-rows`:{let e=t.resource?await Y(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];i.rows=e;break}case`network-graph`:break;case`table`:{let e=a.find(e=>e.category===`set`);if(!e)throw Error(`Table link not found for the following component: “${n}”`);i.tableId=e.uuid;break}case`search-bar`:{let t=g(e.properties,`variant`);t??=`default`,i.variant=t;break}case`text`:{let r=t.document&&`content`in t.document?I(t.document.content):null;if(!r)throw Error(`Content not found for the following component: “${n}”`);let a=g(e.properties,`variant`);a??=`block`;let o=g(e.properties,`heading`);i.variant=a,i.heading=o,i.content=r;break}case`timeline`:{let e=a.find(e=>e.category===`tree`);if(!e)throw Error(`Timeline link not found for the following component: “${n}”`);i.timelineId=e.uuid;break}case`video`:{let t=a.find(e=>e.type===`video`);if(!t)throw Error(`Video link not found for the following component: “${n}”`);let r=g(e.properties,`chapters-displayed`);r??=!0,i.videoId=t.uuid,i.isChaptersDislayed=r===!0;break}default:console.warn(`Invalid or non-implemented component name “${n}” for the following element: “${D(t.identification.label)}”`);break}return i}async function X(e){let t=k(e.identification),n=e.properties?.property?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],r=n.find(e=>e.label===`presentation`);if(!r)throw Error(`Presentation property not found for element “${t.label}”`);let i=r.properties.find(e=>e.label===`component`);if(!i)throw Error(`Component for element “${t.label}” not found`);let a=await he(i,e),o=r.properties.find(e=>e.label===`section-sidebar-displayed`),s=o?.values[0]?.content===!0,c=e.properties?.property?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],l=c.find(e=>e.label===`presentation`&&e.values[0].content===`css`)?.properties??[],u=[];for(let e of l){let t=e.values[0].content;u.push({label:e.label,value:t})}let d=c.find(e=>e.label===`presentation`&&e.values[0].content===`css-mobile`)?.properties??[],f=[];for(let e of d){let t=e.values[0].content;f.push({label:e.label,value:t})}let p=c.find(e=>e.label===`presentation`&&e.values[0].content===`title`)?.properties,m=`default`,h=!1,_=!1,v=!1,y=!1;if(p){let e=g(p,`variant`);e&&(m=e);let t=p.filter(e=>e.label===`display`);t.length>0&&(h=t.some(e=>e.values[0].content===`name`),_=t.some(e=>e.values[0].content===`description`),v=t.some(e=>e.values[0].content===`date`),y=t.some(e=>e.values[0].content===`creators`))}return{uuid:e.uuid,type:`element`,title:{label:t.label,variant:m,properties:{isNameDisplayed:h,isDescriptionDisplayed:_,isDateDisplayed:v,isCreatorsDisplayed:y}},isDisplayedInBlockSectionSidebar:s,cssStyles:u,cssStylesMobile:f,...a}}async function ge(e){let t=e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];if(t.length===0||t.find(e=>e.label===`presentation`)?.values[0]?.content!==`page`)return null;let n=k(e.identification),r=e.slug;if(r===void 0)throw Error(`Slug not found for page “${n.label}”`);let i=e.links?F(Array.isArray(e.links)?e.links:[e.links]):[],a=i.find(e=>e.type===`image`||e.type===`IIIF`),o=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],s=[];for(let e of o){let t=e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=g(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 Y(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 _e(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n){let n=await ge(e);n&&t.push(n)}return t}async function 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?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],r=n.find(e=>e.label===`presentation`&&e.values[0]?.content===`block`)?.properties;if(r){let e=r.find(e=>e.label===`layout`)?.values[0];e&&(t.layout=e.content);let n=r.find(e=>e.label===`spacing`)?.values[0];n&&(t.properties.spacing=n.content);let i=r.find(e=>e.label===`gap`)?.values[0];i&&(t.properties.gap=i.content);let a=r.find(e=>e.label===`align-items`)?.values[0];a&&(t.properties.alignItems=a.content);let o=r.find(e=>e.label===`justify-content`)?.values[0];o&&(t.properties.justifyContent=o.content);let s=r.find(e=>e.label===`overwrite-mobile`);if(s){let e=s.properties,n={};for(let t of e)n[t.label]=t.values[0].content;t.propertiesMobile=n}}let i=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],a=[];for(let e of i){let t=e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=g(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=Q(t),t}function Q(e){let t=[];for(let n of e.items)switch(n.type){case`block`:{let e=Q(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 ve(e){let t=B(e),r=t.find(e=>e.label===`presentation`)?.properties;if(!r)throw Error(`Presentation property not found`);let i=r.find(e=>e.label===`webUI`)?.values[0]?.content;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 $(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.level)?n.level:[n.level],r=e.map(e=>{let[t,n]=e.split(`, `);return{variableUuid:t,valueUuid:n===`null`?null:n}});t.push({context:r})}}return t}async function ye(e,t,n){if(!e.properties)throw Error(`Website properties not found`);let r=ve(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]);if(typeof e.items==`string`||!(`resource`in e.items))throw Error(`Website pages not found`);let i=Array.isArray(e.items.resource)?e.items.resource:[e.items.resource],a=await _e(i),o=null,s=[],c={label:``,variant:`default`,properties:{isNameDisplayed:!1,isDescriptionDisplayed:!1,isDateDisplayed:!1,isCreatorsDisplayed:!1}},l=`start`,u=`default`,d=[],f=[],p=i.find(e=>{let t=e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];return t.some(e=>e.label===`presentation`&&e.values[0]?.content===`element`&&e.properties[0]?.label===`component`&&e.properties[0].values[0]?.content===`sidebar`)});if(p){c.label=typeof p.identification.label==`string`||typeof p.identification.label==`number`||typeof p.identification.label==`boolean`?w(p.identification.label):D(p.identification.label);let e=p.properties?B(Array.isArray(p.properties.property)?p.properties.property:[p.properties.property]):[],t=e.find(e=>e.label===`presentation`&&e.values[0]?.content===`element`)?.properties.find(e=>e.label===`component`&&e.values[0]?.content===`sidebar`)?.properties??[],n=t.find(e=>e.label===`layout`);n&&(l=n.values[0].content);let r=t.find(e=>e.label===`layout-mobile`);r&&(u=r.values[0].content);let i=e.find(e=>e.label===`presentation`&&e.values[0].content===`css`)?.properties??[];for(let e of i){let t=e.values[0].content;d.push({label:e.label,value:t})}let a=e.find(e=>e.label===`presentation`&&e.values[0].content===`css-mobile`)?.properties??[];for(let e of a){let t=e.values[0].content;f.push({label:e.label,value:t})}let o=e.find(e=>e.label===`presentation`&&e.values[0].content===`title`)?.properties;if(o){let e=g(o,`variant`);e&&(c.variant=e);let t=o.filter(e=>e.label===`display`);t.length>0&&(c.properties.isNameDisplayed=t.some(e=>e.values[0].content===`name`),c.properties.isDescriptionDisplayed=t.some(e=>e.values[0].content===`description`),c.properties.isDateDisplayed=t.some(e=>e.values[0].content===`date`),c.properties.isCreatorsDisplayed=t.some(e=>e.values[0].content===`creators`))}let m=p.resource?Array.isArray(p.resource)?p.resource:[p.resource]:[];for(let e of m){let t=await X(e);s.push(t)}}s.length>0&&(o={elements:s,title:c,layout:l,mobileLayout:u,cssStyles:d,cssStylesMobile:f});let m={collectionUuids:[],contexts:{flatten:[],search:[],active:[],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.searchContexts==null?[]:Array.isArray(e.websiteOptions.searchContexts)?e.websiteOptions.searchContexts:[e.websiteOptions.searchContexts],i=e.websiteOptions.activeContexts==null?[]:Array.isArray(e.websiteOptions.activeContexts)?e.websiteOptions.activeContexts:[e.websiteOptions.activeContexts],a=e.websiteOptions.labelContexts==null?[]:Array.isArray(e.websiteOptions.labelContexts)?e.websiteOptions.labelContexts:[e.websiteOptions.labelContexts];m={collectionUuids:e.websiteOptions.collectionUuids==null?[]:(Array.isArray(e.websiteOptions.collectionUuids.uuid)?e.websiteOptions.collectionUuids.uuid:[e.websiteOptions.collectionUuids.uuid]).map(e=>e.content),contexts:{flatten:$(t),search:$(r),active:$(i),label:$(a),suppress:$(n)}}}return{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:k(e.identification),project:{name:w(t),website:n===null?null:w(n)},creators:e.creators?P(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:M(e.availability),pages:a,sidebar:o,properties:r,globalOptions:m}}async function be(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,4 +8,4 @@ import{z as e}from"zod/v4";const t=e.uuid({error:`Invalid UUID provided`}),n=e.o
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=k(d.result.gallery.item.identification),p=k(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 xe(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 Se(e,t,n,r){try{let[i,a]=await xe(e,r);if(i!==null)throw Error(i);let o=O(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=q(a.ochre.resource);break;case`spatialUnit`:if(!(`spatialUnit`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'spatialUnit' key`);s=de(a.ochre.spatialUnit);break;case`concept`:if(!(`concept`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'concept' key`);s=pe(a.ochre.concept);break;case`period`:if(!(`period`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'period' key`);s=V(a.ochre.period);break;case`bibliography`:if(!(`bibliography`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'bibliography' key`);s=U(a.ochre.bibliography);break;case`person`:if(!(`person`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'person' key`);s=N(a.ochre.person);break;case`propertyValue`:if(!(`propertyValue`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'propertyValue' key`);s=G(a.ochre.propertyValue);break;case`set`:if(!(`set`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'set' key`);s=ue(a.ochre.set,n);break;case`tree`:if(!(`tree`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'tree' key`);s=le(a.ochre.tree);break;default:throw Error(`Invalid category`)}let c=te(a.ochre.metadata),l={uuid:a.ochre.uuidBelongsTo,abbreviation:w(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}}}async function Ce(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=k(a.result.project.identification),s={...o,website:a.result.project.identification.website??null},c={item:{uuid:e,name:k(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 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?k(r.result.ochre.metadata.project.identification):null,a=await ye(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{Ce as fetchByUuidMetadata,be as fetchGallery,Se as fetchItem,we 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};
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=k(d.result.gallery.item.identification),p=k(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 xe(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 Se(e,t,n,r){try{let[i,a]=await xe(e,r);if(i!==null)throw Error(i);let o=O(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=ue(a.ochre.resource);break;case`spatialUnit`:if(!(`spatialUnit`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'spatialUnit' key`);s=de(a.ochre.spatialUnit);break;case`concept`:if(!(`concept`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'concept' key`);s=pe(a.ochre.concept);break;case`period`:if(!(`period`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'period' key`);s=V(a.ochre.period);break;case`bibliography`:if(!(`bibliography`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'bibliography' key`);s=U(a.ochre.bibliography);break;case`person`:if(!(`person`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'person' key`);s=N(a.ochre.person);break;case`propertyValue`:if(!(`propertyValue`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'propertyValue' key`);s=G(a.ochre.propertyValue);break;case`set`:if(!(`set`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'set' key`);s=q(a.ochre.set,n);break;case`tree`:if(!(`tree`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'tree' key`);s=le(a.ochre.tree,t,n);break;default:throw Error(`Invalid category`)}let c=te(a.ochre.metadata),l={uuid:a.ochre.uuidBelongsTo,abbreviation:w(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}}}async function Ce(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=k(a.result.project.identification),s={...o,website:a.result.project.identification.website??null},c={item:{uuid:e,name:k(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 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?k(r.result.ochre.metadata.project.identification):null,a=await ye(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{Ce as fetchByUuidMetadata,be as fetchGallery,Se as fetchItem,we 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.8.18",
3
+ "version": "0.8.20",
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",