@digitalculture/ochre-sdk 0.7.10 → 0.7.11

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,7 +1,7 @@
1
- "use strict";var oe=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var qe=Object.getOwnPropertyNames;var Ge=Object.prototype.hasOwnProperty;var Ke=(e,r)=>{for(var n in r)oe(e,n,{get:r[n],enumerable:!0})},Je=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of qe(r))!Ge.call(e,i)&&i!==n&&oe(e,i,{get:()=>r[i],enumerable:!(t=Ye(r,i))||t.enumerable});return e};var _e=e=>Je(oe({},"__esModule",{value:!0}),e);var tt={};Ke(tt,{fetchByUuid:()=>ce,fetchGallery:()=>Ze,fetchItem:()=>pe,fetchWebsite:()=>et,filterProperties:()=>Le,getAllPropertyLabels:()=>$e,getPropertyByLabel:()=>q,getPropertyValueByLabel:()=>d,getPropertyValuesByLabel:()=>se,parseBibliographies:()=>Y,parseBibliography:()=>Q,parseConcept:()=>ee,parseConcepts:()=>we,parseContext:()=>V,parseCoordinates:()=>te,parseDocument:()=>re,parseEmail:()=>F,parseEvents:()=>ge,parseFakeString:()=>p,parseIdentification:()=>P,parseImage:()=>me,parseImageMap:()=>Ne,parseInterpretations:()=>Ve,parseLanguages:()=>Fe,parseLicense:()=>B,parseLink:()=>Be,parseLinks:()=>U,parseMetadata:()=>ue,parseNotes:()=>ne,parseObservation:()=>be,parseObservations:()=>je,parsePeriod:()=>z,parsePeriods:()=>M,parsePerson:()=>_,parsePersons:()=>W,parseProperties:()=>T,parseProperty:()=>Ue,parsePropertyValue:()=>R,parsePropertyValues:()=>Ae,parseResource:()=>X,parseResources:()=>N,parseSet:()=>fe,parseSpatialUnit:()=>Z,parseSpatialUnits:()=>ve,parseStringContent:()=>S,parseStringDocumentItem:()=>K,parseStringItem:()=>G,parseTree:()=>de,parseWebsite:()=>Pe});module.exports=_e(tt);var D=require("zod"),ke=D.z.string().uuid({message:"Invalid UUID provided"}),Ie=D.z.object({type:D.z.enum(["traditional","digital-collection","plum","cedar","elm","maple","oak","palm"],{message:"Invalid website type"}),status:D.z.enum(["development","preview","production"],{message:"Invalid website status"}),privacy:D.z.enum(["public","password","private"],{message:"Invalid website privacy"})}),xe=D.z.enum(["annotated-document","annotated-image","bibliography","button","collection","empty-space","entries","filter-categories","iframe","iiif-viewer","image","image-gallery","n-columns","n-rows","network-graph","search-bar","table","text","timeline","video"],{message:"Invalid component"}),ae=D.z.enum(["resource","spatialUnit","concept","period","bibliography","person","propertyValue","set","tree"]),De=D.z.enum(["string","integer","decimal","boolean","date","dateTime","time","coordinate","IDREF"]),Oe=D.z.object({uuid:D.z.string().uuid({message:"Invalid UUID"}),filter:D.z.string().optional(),page:D.z.number().positive({message:"Page must be positive"}),perPage:D.z.number().positive({message:"Per page must be positive"})}).strict(),Te=D.z.string().transform(e=>e.split(" ")).pipe(D.z.array(D.z.enum(["bold","italic","underline"]))),Ee=D.z.string().transform(e=>e.split(" ")).pipe(D.z.array(D.z.enum(["newline","trailing","leading"]))),Ce=D.z.string().email({message:"Invalid email"});var H={searchNestedProperties:!1};function q(e,r,n=H){let{searchNestedProperties:t}=n,i=e.find(s=>s.label===r);if(i)return i;if(t){for(let s of e)if(s.properties.length>0){let o=q(s.properties,r,{searchNestedProperties:t});if(o)return o}}return null}function se(e,r,n=H){let{searchNestedProperties:t}=n,i=e.find(s=>s.label===r);if(i)return i.values.map(s=>s.content);if(t){for(let s of e)if(s.properties.length>0){let o=se(s.properties,r,{searchNestedProperties:t});if(o)return o}}return null}function d(e,r,n=H){let{searchNestedProperties:t}=n,i=se(e,r,{searchNestedProperties:t});if(i!==null&&i.length>0)return i[0];if(t){for(let s of e)if(s.properties.length>0){let o=d(s.properties,r,{searchNestedProperties:t});if(o!==null)return o}}return null}function $e(e,r=H){let{searchNestedProperties:n}=r,t=new Set;for(let i of e)if(t.add(i.label),i.properties.length>0&&n){let s=$e(i.properties,{searchNestedProperties:!0});for(let o of s)t.add(o)}return[...t]}function Le(e,r,n=H){let{searchNestedProperties:t}=n;if(r.label.toLocaleLowerCase("en-US")==="all fields"||e.label.toLocaleLowerCase("en-US")===r.label.toLocaleLowerCase("en-US")){let s=e.values.some(o=>o.content===null?!1:typeof o.content=="string"?typeof r.value!="string"?!1:o.content.toLocaleLowerCase("en-US").includes(r.value.toLocaleLowerCase("en-US")):typeof o.content=="number"?typeof r.value!="number"?!1:o.content===r.value:typeof o.content=="boolean"?typeof r.value!="boolean"?!1:o.booleanValue===r.value:o.content instanceof Date&&r.value instanceof Date?o.content.getTime()===r.value.getTime():!1);return!s&&t&&(s=e.properties.some(o=>Le(o,r,{searchNestedProperties:!0}))),s}return!1}function ze(e,r){return e.find(t=>t.lang===r)??null}function F(e){let r=e.split(" "),n=[];for(let t of r){let i=t.replaceAll(/(?<=\s|^)[([{]+|[)\]}]+(?=\s|$)/g,"").replace(/[!),.:;?\]]$/,""),s=t.indexOf(i),o=t.slice(0,s),a=t.slice(s+i.length);if(Ce.safeParse(i).success){n.push(o,`${o}<ExternalLink href="mailto:${i}">${i}</ExternalLink>${a}`);continue}n.push(t)}return n.join(" ")}function We(e,r){let n=e,t=Te.safeParse(r);if(!t.success)return console.warn(`Invalid render options string provided: \u201C${r}\u201D`),e;for(let i of t.data)switch(i){case"bold":{n=`**${n}**`;break}case"italic":{n=`*${n}*`;break}case"underline":{n=`_${n}_`;break}}return n.replaceAll("&#39;","'")}function le(e,r){let n=e,t=Ee.safeParse(r);if(!t.success)return console.warn(`Invalid whitespace string provided: \u201C${r}\u201D`),e;for(let i of t.data)switch(i){case"newline":{n=`<br />
1
+ "use strict";var oe=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var qe=Object.getOwnPropertyNames;var Ge=Object.prototype.hasOwnProperty;var Ke=(e,r)=>{for(var n in r)oe(e,n,{get:r[n],enumerable:!0})},Je=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of qe(r))!Ge.call(e,i)&&i!==n&&oe(e,i,{get:()=>r[i],enumerable:!(t=Ye(r,i))||t.enumerable});return e};var _e=e=>Je(oe({},"__esModule",{value:!0}),e);var tt={};Ke(tt,{fetchByUuid:()=>ce,fetchGallery:()=>Ze,fetchItem:()=>pe,fetchWebsite:()=>et,filterProperties:()=>Le,getPropertyByLabel:()=>q,getPropertyValueByLabel:()=>d,getPropertyValuesByLabel:()=>se,getUniqueProperties:()=>$e,parseBibliographies:()=>Y,parseBibliography:()=>Q,parseConcept:()=>ee,parseConcepts:()=>we,parseContext:()=>V,parseCoordinates:()=>te,parseDocument:()=>re,parseEmail:()=>F,parseEvents:()=>ge,parseFakeString:()=>p,parseIdentification:()=>P,parseImage:()=>me,parseImageMap:()=>Ne,parseInterpretations:()=>Ve,parseLanguages:()=>Fe,parseLicense:()=>B,parseLink:()=>Be,parseLinks:()=>j,parseMetadata:()=>ue,parseNotes:()=>ne,parseObservation:()=>be,parseObservations:()=>Ue,parsePeriod:()=>z,parsePeriods:()=>M,parsePerson:()=>_,parsePersons:()=>W,parseProperties:()=>T,parseProperty:()=>je,parsePropertyValue:()=>R,parsePropertyValues:()=>Ae,parseResource:()=>X,parseResources:()=>N,parseSet:()=>fe,parseSpatialUnit:()=>Z,parseSpatialUnits:()=>ve,parseStringContent:()=>S,parseStringDocumentItem:()=>K,parseStringItem:()=>G,parseTree:()=>de,parseWebsite:()=>Pe});module.exports=_e(tt);var D=require("zod"),ke=D.z.string().uuid({message:"Invalid UUID provided"}),Ie=D.z.object({type:D.z.enum(["traditional","digital-collection","plum","cedar","elm","maple","oak","palm"],{message:"Invalid website type"}),status:D.z.enum(["development","preview","production"],{message:"Invalid website status"}),privacy:D.z.enum(["public","password","private"],{message:"Invalid website privacy"})}),xe=D.z.enum(["annotated-document","annotated-image","bibliography","button","collection","empty-space","entries","filter-categories","iframe","iiif-viewer","image","image-gallery","n-columns","n-rows","network-graph","search-bar","table","text","timeline","video"],{message:"Invalid component"}),ae=D.z.enum(["resource","spatialUnit","concept","period","bibliography","person","propertyValue","set","tree"]),De=D.z.enum(["string","integer","decimal","boolean","date","dateTime","time","coordinate","IDREF"]),Oe=D.z.object({uuid:D.z.string().uuid({message:"Invalid UUID"}),filter:D.z.string().optional(),page:D.z.number().positive({message:"Page must be positive"}),perPage:D.z.number().positive({message:"Per page must be positive"})}).strict(),Te=D.z.string().transform(e=>e.split(" ")).pipe(D.z.array(D.z.enum(["bold","italic","underline"]))),Ee=D.z.string().transform(e=>e.split(" ")).pipe(D.z.array(D.z.enum(["newline","trailing","leading"]))),Ce=D.z.string().email({message:"Invalid email"});var H={includeNestedProperties:!1};function q(e,r,n=H){let{includeNestedProperties:t}=n,i=e.find(s=>s.label===r);if(i)return i;if(t){for(let s of e)if(s.properties.length>0){let o=q(s.properties,r,{includeNestedProperties:t});if(o)return o}}return null}function se(e,r,n=H){let{includeNestedProperties:t}=n,i=e.find(s=>s.label===r);if(i)return i.values.map(s=>s.content);if(t){for(let s of e)if(s.properties.length>0){let o=se(s.properties,r,{includeNestedProperties:t});if(o)return o}}return null}function d(e,r,n=H){let{includeNestedProperties:t}=n,i=se(e,r,{includeNestedProperties:t});if(i!==null&&i.length>0)return i[0];if(t){for(let s of e)if(s.properties.length>0){let o=d(s.properties,r,{includeNestedProperties:t});if(o!==null)return o}}return null}function $e(e,r=H){let{includeNestedProperties:n}=r,t=new Array;for(let i of e)if(!t.some(s=>s.uuid===i.uuid)&&(t.push(i),i.properties.length>0&&n)){let s=$e(i.properties,{includeNestedProperties:!0});for(let o of s)t.some(a=>a.uuid===o.uuid)||t.push(o)}return t}function Le(e,r,n=H){let{includeNestedProperties:t}=n;if(r.label.toLocaleLowerCase("en-US")==="all fields"||e.label.toLocaleLowerCase("en-US")===r.label.toLocaleLowerCase("en-US")){let s=e.values.some(o=>o.content===null?!1:typeof o.content=="string"?typeof r.value!="string"?!1:o.content.toLocaleLowerCase("en-US").includes(r.value.toLocaleLowerCase("en-US")):typeof o.content=="number"?typeof r.value!="number"?!1:o.content===r.value:typeof o.content=="boolean"?typeof r.value!="boolean"?!1:o.booleanValue===r.value:o.content instanceof Date&&r.value instanceof Date?o.content.getTime()===r.value.getTime():!1);return!s&&t&&(s=e.properties.some(o=>Le(o,r,{includeNestedProperties:!0}))),s}return!1}function ze(e,r){return e.find(t=>t.lang===r)??null}function F(e){let r=e.split(" "),n=[];for(let t of r){let i=t.replaceAll(/(?<=\s|^)[([{]+|[)\]}]+(?=\s|$)/g,"").replace(/[!),.:;?\]]$/,""),s=t.indexOf(i),o=t.slice(0,s),a=t.slice(s+i.length);if(Ce.safeParse(i).success){n.push(o,`${o}<ExternalLink href="mailto:${i}">${i}</ExternalLink>${a}`);continue}n.push(t)}return n.join(" ")}function We(e,r){let n=e,t=Te.safeParse(r);if(!t.success)return console.warn(`Invalid render options string provided: \u201C${r}\u201D`),e;for(let i of t.data)switch(i){case"bold":{n=`**${n}**`;break}case"italic":{n=`*${n}*`;break}case"underline":{n=`_${n}_`;break}}return n.replaceAll("&#39;","'")}function le(e,r){let n=e,t=Ee.safeParse(r);if(!t.success)return console.warn(`Invalid whitespace string provided: \u201C${r}\u201D`),e;for(let i of t.data)switch(i){case"newline":{n=`<br />
2
2
  ${n}`;break}case"trailing":{n=`${n} `;break}case"leading":{n=` ${n}`;break}}return n.replaceAll("&#39;","'")}function p(e){let r="";return typeof e=="string"?r=e:typeof e=="number"?r=e.toString():typeof e=="boolean"&&(r=e?"Yes":"No"),r.replaceAll("&#39;","'").replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}function G(e){let r="";switch(typeof e.string){case"string":{r=e.string;break}case"number":case"boolean":{r=p(e.string);break}case"object":{let n=Array.isArray(e.string)?e.string:[e.string];for(let t of n)if(typeof t=="string"||typeof t=="number"||typeof t=="boolean")r+=p(t);else{let i=t.rend!=null?We(p(t.content),t.rend):p(t.content),s=t.whitespace!=null?le(i,t.whitespace):i;r+=s}break}default:{r="";break}}return r.replaceAll("&#39;","'").replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}function K(e,r){if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return F(p(e));if("whitespace"in e&&!("content"in e)&&!("string"in e))return e.whitespace==="newline"?`
3
3
  `:"";if("links"in e){let t="";typeof e.string=="object"?t=S(e.string):t=p(e.string).replaceAll("<",String.raw`\<`).replaceAll("{",String.raw`\{`);let i=Array.isArray(e.links)?e.links:[e.links];for(let s of i)if("resource"in s){let o=Array.isArray(s.resource)?s.resource[0]:s.resource,a=null;switch(o.content!=null&&(a=p(o.content).replaceAll("<",String.raw`\<`).replaceAll("{",String.raw`\{`)),o.type){case"image":return o.rend==="inline"?`<InlineImage uuid="${o.uuid}" ${a!==null?`content="${a}"`:""} height={${o.height?.toString()??"null"}} width={${o.width?.toString()??"null"}} />`:o.publicationDateTime!=null?`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${o.uuid}" type="image"${a!==null?` content="${a}"`:""}>${t}</ExternalLink>`:`<TooltipSpan type="image" ${a!==null?`content="${a}"`:""}>${t}</TooltipSpan>`;case"internalDocument":return a?.toLocaleLowerCase("en-US").includes("footnote")?(r&&r.push({uuid:o.uuid,label:t,content:""}),` <Footnote uuid="${o.uuid}"${t?` label="${t}"`:""}${a!==null?` content="${a}"`:""} />`):`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${o.uuid}" type="internalDocument" ${a!==null?`content="${a}"`:""}>${t}</ExternalLink>`;case"externalDocument":return o.publicationDateTime!=null?`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${o.uuid}" type="externalDocument" ${a!==null?`content="${a}"`:""}>${t}</ExternalLink>`:`<TooltipSpan type="externalDocument" ${a!==null?`content="${a}"`:""}>${t}</TooltipSpan>`;case"webpage":return`<ExternalLink href="${o.href}" type="webpage" ${a!==null?`content="${a}"`:""}>${t}</ExternalLink>`;default:return""}}else if("concept"in s){let o=Array.isArray(s.concept)?s.concept[0]:s.concept;return o.publicationDateTime!=null?`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${o.uuid}" type="concept">${t}</ExternalLink>`:`<TooltipSpan type="concept">${t}</TooltipSpan>`}else if("set"in s){let o=Array.isArray(s.set)?s.set[0]:s.set;return o.publicationDateTime!=null?`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${o.uuid}" type="set">${t}</ExternalLink>`:`<TooltipSpan type="set">${t}</TooltipSpan>`}else if("person"in s){let o=Array.isArray(s.person)?s.person[0]:s.person,a=o.identification?["string","number","boolean"].includes(typeof o.identification.label)?p(o.identification.label):S(o.identification.label):null;return o.publicationDateTime!=null?`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${o.uuid}" type="${o.type??"person"}" ${a!==null?`content="${a}"`:""}>${t}</ExternalLink>`:`<TooltipSpan type="${o.type??"person"}" ${a!==null?`content="${a}"`:""}>${t}</TooltipSpan>`}else if("bibliography"in s){let o=Array.isArray(s.bibliography)?s.bibliography[0]:s.bibliography;return o.publicationDateTime!=null?`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${o.uuid}" type="${o.type??"bibliography"}">${t}</ExternalLink>`:`<TooltipSpan type="bibliography">${t}</TooltipSpan>`}}let n="";if("string"in e){let t=Array.isArray(e.string)?e.string:[e.string];for(let i of t)n+=K(i,r);return"whitespace"in e&&e.whitespace!=null&&(n=le(F(n),e.whitespace)),n.replaceAll("&#39;","'").replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}else n=p(e.content),e.rend!=null&&(n=We(F(n),e.rend)),e.whitespace!=null&&(n=le(F(n),e.whitespace));return n.replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}function S(e,r="eng"){switch(typeof e.content){case"string":case"number":case"boolean":return p(e.content);case"object":if(Array.isArray(e.content)){let n=ze(e.content,r);if(n)return G(n);{let t=e.content[0];if(!t)throw new Error(`No string item found for language \u201C${r}\u201D in the following content:
4
- ${JSON.stringify(e.content)}.`);return G(t)}}else return G(e.content);default:return String(e.content).replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}}function J(e){let r=e.find(t=>ae.safeParse(t).success);if(!r){let t=e.find(i=>!["uuid","uuidBelongsTo","belongsTo","publicationDateTime","metadata","languages"].includes(i));throw new Error(`Invalid OCHRE data; found unexpected "${t}" key`)}return ae.parse(r)}async function ce(e){try{let r=ke.parse(e),n=await fetch(`https://ochre.lib.uchicago.edu/ochre?uuid=${r}&format=json&lang="*"`);if(!n.ok)throw new Error("Failed to fetch OCHRE data");let t=await n.json();if(!("ochre"in t))throw new Error("Invalid OCHRE data: API response missing 'ochre' key");return[null,t]}catch(r){return[r instanceof Error?r.message:"Unknown error",null]}}async function pe(e,r,n){try{let[t,i]=await ce(e);if(t!==null)throw new Error(t);let s=J(Object.keys(i.ochre)),o;switch(s){case"resource":{if(!("resource"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'resource' key");o=X(i.ochre.resource);break}case"spatialUnit":{if(!("spatialUnit"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'spatialUnit' key");o=Z(i.ochre.spatialUnit);break}case"concept":{if(!("concept"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'concept' key");o=ee(i.ochre.concept);break}case"period":{if(!("period"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'period' key");o=z(i.ochre.period);break}case"bibliography":{if(!("bibliography"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'bibliography' key");o=Q(i.ochre.bibliography);break}case"person":{if(!("person"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'person' key");o=_(i.ochre.person);break}case"propertyValue":{if(!("propertyValue"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'propertyValue' key");o=R(i.ochre.propertyValue);break}case"set":{if(!("set"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'set' key");o=fe(i.ochre.set,n);break}case"tree":{if(!("tree"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'tree' key");o=de(i.ochre.tree);break}default:throw new Error("Invalid category")}let a=ue(i.ochre.metadata),l={uuid:i.ochre.uuidBelongsTo,abbreviation:p(i.ochre.belongsTo)};return{error:null,metadata:a,belongsTo:l,item:o,category:r}}catch(t){return{error:t instanceof Error?t.message:"Unknown error",metadata:void 0,belongsTo:void 0,item:void 0,category:void 0}}}function P(e){try{let r={label:["string","number","boolean"].includes(typeof e.label)?p(e.label):S(e.label),abbreviation:""};for(let n of Object.keys(e).filter(t=>t!=="label"))r[n]=S(e[n]);return r}catch(r){return console.error(r),{label:"",abbreviation:""}}}function Fe(e){return e==null?["eng"]:Array.isArray(e)?e.map(r=>S(r)):[S(e)]}function ue(e){let r={label:"",abbreviation:""};if(e.item)if(e.item.label||e.item.abbreviation){let i="",s="";e.item.label&&(i=S(e.item.label)),e.item.abbreviation&&(s=S(e.item.abbreviation)),r={label:i,abbreviation:s}}else r=P(e.item.identification);let n=null,t=e.project?.identification?P(e.project.identification):null;return t&&(n={...t,website:e.project?.identification.website??null}),{project:n?{identification:n}:null,item:e.item?{identification:r,category:e.item.category,type:e.item.type,maxLength:e.item.maxLength??null}:null,dataset:S(e.dataset),publisher:S(e.publisher),languages:Fe(e.language),identifier:S(e.identifier),description:S(e.description)}}function ye(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,number:e.n,content:p(e.content)}}function V(e){return{nodes:(Array.isArray(e.context)?e.context:[e.context]).map(t=>{let i=[];if("spatialUnit"in t&&t.spatialUnit){let s=Array.isArray(t.spatialUnit)?t.spatialUnit:[t.spatialUnit];for(let o of s)i.push(ye(o))}return{tree:ye(t.tree),project:ye(t.project),spatialUnit:i}}),displayPath:e.displayPath}}function B(e){return typeof e.license=="string"?null:{content:e.license.content,url:e.license.target}}function _(e){return{uuid:e.uuid,category:"person",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type??null,number:e.n??null,context:e.context?V(e.context):null,date:e.date!=null?new Date(e.date):null,identification:e.identification?P(e.identification):null,availability:e.availability?B(e.availability):null,address:e.address?{country:e.address.country??null,city:e.address.city??null,state:e.address.state??null}:null,coordinates:e.coordinates?te(e.coordinates):null,content:e.content!=null?p(e.content):null,events:e.events?ge(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function W(e){let r=[];for(let n of e)r.push(_(n));return r}function Be(e){let r="resource"in e?e.resource:"spatialUnit"in e?e.spatialUnit:"concept"in e?e.concept:"set"in e?e.set:"tree"in e?e.tree:"person"in e?e.person:"bibliography"in e?e.bibliography:"epigraphicUnit"in e?e.epigraphicUnit:"propertyValue"in e?e.propertyValue:null;if(!r)throw new Error(`Invalid link provided: ${JSON.stringify(e,null,2)}`);let n=Array.isArray(r)?r:[r],t=[];for(let i of n){let s={category:"resource"in e?"resource":"spatialUnit"in e?"spatialUnit":"concept"in e?"concept":"set"in e?"set":"person"in e?"person":"tree"in e?"tree":"bibliography"in e?"bibliography":"epigraphicUnit"in e?"epigraphicUnit":"propertyValue"in e?"propertyValue":null,content:"content"in i&&i.content!=null?p(i.content):null,href:"href"in i&&i.href!=null?i.href:null,uuid:i.uuid,type:i.type??null,identification:i.identification?P(i.identification):null,image:null,bibliographies:"bibliography"in e?Y(Array.isArray(e.bibliography)?e.bibliography:[e.bibliography]):null,publicationDateTime:i.publicationDateTime!=null?new Date(i.publicationDateTime):null};"height"in i&&i.height!=null&&i.width!=null&&i.heightPreview!=null&&i.widthPreview!=null&&(s.image={isInline:i.rend==="inline",isPrimary:i.isPrimary??!1,heightPreview:i.heightPreview,widthPreview:i.widthPreview,height:i.height,width:i.width}),t.push(s)}return t}function U(e){let r=[];for(let n of e)r.push(...Be(n));return r}function re(e,r="eng"){let n="",t=[],i=Array.isArray(e)?e.find(s=>s.lang===r):e;if(typeof i.string=="string"||typeof i.string=="number"||typeof i.string=="boolean")n+=F(p(i.string));else{let s=Array.isArray(i.string)?i.string:[i.string];for(let o of s)n+=K(o,t)}return{content:n,footnotes:t}}function me(e){return{publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,identification:e.identification?P(e.identification):null,url:e.href??(e.htmlImgSrcPrefix==null&&e.content!=null?p(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?p(e.content):null,widthPreview:e.widthPreview??null,heightPreview:e.heightPreview??null,width:e.width??null,height:e.height??null}}function ne(e,r="eng"){let n=[];for(let t of e){if(typeof t=="string"){if(t==="")continue;n.push({number:-1,title:null,content:t});continue}let i="",s=Array.isArray(t.content)?t.content:[t.content],o=s.find(a=>a.lang===r);if(!o&&(o=s[0],!o))throw new Error(`Note does not have a valid content item: ${JSON.stringify(t,null,2)}`);typeof o.string=="string"||typeof o.string=="number"||typeof o.string=="boolean"?i=F(p(o.string)):i=F(re(o).content),n.push({number:t.noteNo,title:o.title!=null?p(o.title):null,content:i})}return n}function te(e){if(typeof e=="string"){let[r,n]=e.split(", ");return{latitude:Number(r),longitude:Number(n),type:null,label:null}}return{latitude:e.latitude,longitude:e.longitude,type:e.coord?.coordType??null,label:e.coord?.coordLabel!=null?p(e.coord.coordLabel):null}}function be(e){return{number:e.observationNo,date:e.date!=null?new Date(e.date):null,observers:e.observers!=null?p(e.observers).split(";").map(r=>r.trim()):[],notes:e.notes?ne(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?U(Array.isArray(e.links)?e.links:[e.links]):[],properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function je(e){let r=[];for(let n of e)r.push(be(n));return r}function ge(e){let r=[];for(let n of e)r.push({date:n.dateTime!=null?new Date(n.dateTime):null,label:S(n.label),agent:n.agent?{uuid:n.agent.uuid,content:p(n.agent.content)}:null});return r}function Ue(e,r="eng"){let t=("value"in e&&e.value?Array.isArray(e.value)?e.value:[e.value]:[]).map(i=>{let s=null,o=null;if(typeof i=="string"||typeof i=="number"||typeof i=="boolean")return s=p(i),{content:s,booleanValue:o,isUncertain:!1,type:"string",category:"value",uuid:null,publicationDateTime:null,unit:null};{switch(i.type){case"integer":case"decimal":{s=Number(i.content);break}case"dateTime":{s=i.content?typeof i.content=="string"?new Date(i.content):new Date(S({content:i.content})):null;break}default:{"slug"in i&&i.slug!=null?s=p(i.slug):i.content!=null&&(s=S({content:i.content})),i.type==="boolean"&&(o=i.booleanValue??null);break}}let a="string";if(i.type!=null){let{data:c,error:y}=De.safeParse(i.type);if(y)throw new Error(`Invalid property value content type: "${i.type}"`);a=c}return{content:s,booleanValue:o,isUncertain:i.isUncertain??!1,type:a,category:i.category??"value",uuid:i.uuid??null,publicationDateTime:i.publicationDateTime!=null?new Date(i.publicationDateTime):null,unit:i.unit??null}}});return{uuid:e.label.uuid,label:S(e.label,r).replace(/\s*\.{3}$/,"").trim(),values:t,comment:e.comment!=null?p(e.comment):null,properties:e.property?T(Array.isArray(e.property)?e.property:[e.property]):[]}}function T(e,r="eng"){let n=[];for(let t of e)n.push(Ue(t,r));return n}function Ve(e){let r=[];for(let n of e)r.push({date:new Date(n.date),number:n.interpretationNo,properties:n.properties?T(Array.isArray(n.properties.property)?n.properties.property:[n.properties.property]):[]});return r}function Ne(e){let r={area:[],width:e.width,height:e.height},n=Array.isArray(e.area)?e.area:[e.area];for(let t of n)r.area.push({uuid:t.uuid,publicationDateTime:t.publicationDateTime!=null?new Date(t.publicationDateTime):null,type:t.type,title:p(t.title),shape:t.shape==="rect"?"rectangle":"polygon",coords:t.coords.split(",").map(i=>Number.parseInt(i))});return r}function z(e){return{uuid:e.uuid,category:"period",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type??null,number:e.n??null,identification:P(e.identification),description:e.description?S(e.description):null}}function M(e){let r=[];for(let n of e)r.push(z(n));return r}function Q(e){let r=null;return e.source?.resource&&(r={uuid:e.source.resource.uuid,publicationDateTime:e.source.resource.publicationDateTime?new Date(e.source.resource.publicationDateTime):null,type:e.source.resource.type,identification:P(e.source.resource.identification)}),{uuid:e.uuid,category:"bibliography",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,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?V(e.context):null,citation:{format:e.citationFormat??null,short:e.citationFormatSpan?p("default:span"in e.citationFormatSpan?e.citationFormatSpan["default:span"].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?p("default:div"in e.referenceFormatDiv?e.referenceFormatDiv["default:div"]["default:div"].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?W(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:p(e.entryInfo.startIssue),startVolume:p(e.entryInfo.startVolume)}:null,source:{resource:r,documentUrl:e.sourceDocument?`https://ochre.lib.uchicago.edu/ochre?uuid=${e.sourceDocument.uuid}&load`:null},periods:e.periods?M(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],authors:e.authors?W(Array.isArray(e.authors.person)?e.authors.person:[e.authors.person]):[],properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function Y(e){let r=[];for(let n of e)r.push(Q(n));return r}function R(e){return{uuid:e.uuid,category:"propertyValue",number:e.n,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,context:e.context?V(e.context):null,availability:e.availability?B(e.availability):null,identification:P(e.identification),date:e.date?new Date(e.date):null,creators:e.creators?W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],description:e.description?["string","number","boolean"].includes(typeof e.description)?p(e.description):S(e.description):"",notes:e.notes?ne(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?U(Array.isArray(e.links)?e.links:[e.links]):[]}}function Ae(e){let r=[];for(let n of e)r.push(R(n));return r}function de(e){let r=[];e.creators&&(r=W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]));let n=null;e.date!=null&&(n=new Date(e.date));let t=[],i=[],s=[],o=[],a=[],l=[],c=[];return typeof e.items!="string"&&"resource"in e.items&&(t=N(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource])),typeof e.items!="string"&&"spatialUnit"in e.items&&(i=ve(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit])),typeof e.items!="string"&&"concept"in e.items&&(s=we(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept])),typeof e.items!="string"&&"period"in e.items&&(o=M(Array.isArray(e.items.period)?e.items.period:[e.items.period])),typeof e.items!="string"&&"bibliography"in e.items&&(a=Y(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography])),typeof e.items!="string"&&"person"in e.items&&(l=W(Array.isArray(e.items.person)?e.items.person:[e.items.person])),typeof e.items!="string"&&"propertyValue"in e.items&&(c=Ae(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue])),{uuid:e.uuid,category:"tree",publicationDateTime:new Date(e.publicationDateTime),identification:P(e.identification),creators:r,license:B(e.availability),date:n,type:e.type,number:e.n,items:{resources:t,spatialUnits:i,concepts:s,periods:o,bibliographies:a,persons:l,propertyValues:c},properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function fe(e,r){if(typeof e.items=="string")throw new TypeError("Invalid OCHRE data: Set has no items");let n=r??J(Object.keys(e.items)),t=[];switch(n){case"resource":{if(!("resource"in e.items))throw new Error("Invalid OCHRE data: Set has no resources");t=N(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource]);break}case"spatialUnit":{if(!("spatialUnit"in e.items))throw new Error("Invalid OCHRE data: Set has no spatial units");t=ve(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit]);break}case"concept":{if(!("concept"in e.items))throw new Error("Invalid OCHRE data: Set has no concepts");t=we(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept]);break}case"period":{if(!("period"in e.items))throw new Error("Invalid OCHRE data: Set has no periods");t=M(Array.isArray(e.items.period)?e.items.period:[e.items.period]);break}case"bibliography":{if(!("bibliography"in e.items))throw new Error("Invalid OCHRE data: Set has no bibliographies");t=Y(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography]);break}case"person":{if(!("person"in e.items))throw new Error("Invalid OCHRE data: Set has no persons");t=W(Array.isArray(e.items.person)?e.items.person:[e.items.person]);break}case"propertyValue":{if(!("propertyValue"in e.items))throw new Error("Invalid OCHRE data: Set has no property values");t=Ae(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]);break}default:throw new Error("Invalid OCHRE data: Set has no items or is malformed")}return{uuid:e.uuid,category:"set",itemCategory:r,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,date:e.date!=null?new Date(e.date):null,license:B(e.availability),identification:P(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?["string","number","boolean"].includes(typeof e.description)?p(e.description):S(e.description):"",creators:e.creators?W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],type:e.type,number:e.n,items:t}}function X(e){return{uuid:e.uuid,category:"resource",publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,type:e.type,number:e.n,format:e.format??null,context:"context"in e&&e.context?V(e.context):null,license:"availability"in e&&e.availability?B(e.availability):null,copyright:"copyright"in e&&e.copyright!=null?p(e.copyright):null,identification:P(e.identification),date:e.date!=null?new Date(e.date):null,image:e.image?me(e.image):null,creators:e.creators?W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],notes:e.notes?ne(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],description:e.description?["string","number","boolean"].includes(typeof e.description)?p(e.description):S(e.description):"",document:e.document&&"content"in e.document?re(e.document.content):null,href:e.href??null,imageMap:e.imagemap?Ne(e.imagemap):null,periods:e.periods?M(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],links:e.links?U(Array.isArray(e.links)?e.links:[e.links]):[],reverseLinks:e.reverseLinks?U(Array.isArray(e.reverseLinks)?e.reverseLinks:[e.reverseLinks]):[],properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],citedBibliographies:e.citedBibliography?Y(Array.isArray(e.citedBibliography.reference)?e.citedBibliography.reference:[e.citedBibliography.reference]):[],resources:e.resource?N(Array.isArray(e.resource)?e.resource:[e.resource]):[]}}function N(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(X(t));return r}function Z(e){return{uuid:e.uuid,category:"spatialUnit",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type,number:e.n,context:"context"in e&&e.context?V(e.context):null,license:"availability"in e&&e.availability?B(e.availability):null,identification:P(e.identification),image:e.image?me(e.image):null,description:e.description?["string","number","boolean"].includes(typeof e.description)?p(e.description):S(e.description):"",coordinates:e.coordinates?te(e.coordinates):e.coordinate?te(e.coordinate):null,observations:"observations"in e&&e.observations?je(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[be(e.observation)]:[],events:"events"in e&&e.events?ge(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:"properties"in e&&e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function ve(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(Z(t));return r}function ee(e){return{uuid:e.uuid,category:"concept",publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,number:e.n,license:"availability"in e&&e.availability?B(e.availability):null,context:"context"in e&&e.context?V(e.context):null,identification:P(e.identification),interpretations:Ve(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation])}}var he=async(e,r)=>{let n=[];for(let t of e)if((t.properties?T(Array.isArray(t.properties.property)?t.properties.property:[t.properties.property]):[]).find(o=>o.label==="presentation"&&o.values[0].content===r))switch(r){case"element":{let o=await ie(t);n.push(o);break}case"page":{let o=await He(t);o&&n.push(o);break}case"block":{let o=await Se(t);o&&n.push(o);break}}return n};function we(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(ee(t));return r}async function Qe(e,r){let n=xe.parse(e.values[0].content),t={component:n},i=r.links?U(Array.isArray(r.links)?r.links:[r.links]):[],s=i.filter(a=>a.type==="image"||a.type==="IIIF"),o=r.document&&"content"in r.document?re(r.document.content):null;if(o===null){let a=i.find(l=>l.type==="internalDocument");if(a){let{item:l,error:c}=await pe(a.uuid,"resource");if(c!==null)throw new Error("Failed to fetch OCHRE data");o=l.document}}switch(n){case"annotated-document":{if(!o)throw new Error(`Document not found for the following component: \u201C${n}\u201D`);t.document=o;break}case"annotated-image":{if(s.length===0)throw new Error(`Image link not found for the following component: \u201C${n}\u201D`);let a=d(e.properties,"is-searchable")==="Yes";t.imageUuid=s[0].uuid,t.isSearchable=a;break}case"bibliography":{let a=i.find(c=>c.category==="bibliography");if(!a)throw new Error(`Bibliography link not found for the following component: \u201C${n}\u201D`);if(!a.bibliographies)throw new Error(`Bibliography not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"layout");l??="long",t.bibliographies=a.bibliographies,t.layout=l;break}case"button":{let a=d(e.properties,"variant");a??="default";let l=!1,c=d(e.properties,"navigate-to");if(c===null){if(c=d(e.properties,"link-to"),c===null)throw new Error(`Properties \u201Cnavigate-to\u201D or \u201Clink-to\u201D not found for the following component: \u201C${n}\u201D`);l=!0}let y=null,b=d(e.properties,"icon");b!==null&&(y=b),t.variant=a,t.href=c,t.isExternal=l,t.label=["string","number","boolean"].includes(typeof r.identification.label)?p(r.identification.label):S(r.identification.label),t.icon=y;break}case"collection":{let a=i.find(v=>v.category==="set");if(!a)throw new Error(`Collection link not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"variant");l??="full";let c=d(e.properties,"item-variant");c??="default";let y=!1,b=d(e.properties,"show-count");b!==null&&(y=b==="Yes");let x=!1,f=d(e.properties,"is-searchable");f!==null&&(x=f==="Yes");let g=d(e.properties,"layout");g??="image-start",t.collectionId=a.uuid,t.variant=l,t.itemVariant=c,t.isSearchable=x,t.showCount=y,t.layout=g;break}case"empty-space":{let a=d(e.properties,"height"),l=d(e.properties,"width");t.height=a,t.width=l;break}case"entries":{let a=i.find(b=>b.category==="tree");if(!a)throw new Error(`Entries link not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"variant");l??="entry";let c=!1,y=d(e.properties,"is-searchable");y!==null&&(c=y==="Yes"),t.entriesId=a.uuid,t.variant=l,t.isSearchable=c;break}case"filter-categories":{let a=i.find(l=>l.category==="set");if(!a)throw new Error(`Filter link not found for the following component: \u201C${n}\u201D`);t.filterId=a.uuid;break}case"iframe":{let a=i.find(y=>y.type==="webpage")?.href;if(!a)throw new Error(`URL not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"height"),c=d(e.properties,"width");t.href=a,t.height=l,t.width=c;break}case"iiif-viewer":{let a=i.find(l=>l.type==="IIIF");if(!a)throw new Error(`Manifest link not found for the following component: \u201C${n}\u201D`);t.IIIFId=a.uuid;break}case"image":{if(s.length===0)throw new Error(`Image link not found for the following component: \u201C${n}\u201D`);let a=[];for(let L of s)a.push({url:`https://ochre.lib.uchicago.edu/ochre?uuid=${L.uuid}&load`,label:L.identification?.label??null,width:L.image?.width??0,height:L.image?.height??0});let l=d(e.properties,"variant");l??="default";let c=d(e.properties,"layout-caption");c??="bottom";let y=null,b=d(e.properties,"width");b!==null&&(typeof b=="number"?y=b:typeof b=="string"&&(y=Number.parseFloat(b)));let x=null,f=d(e.properties,"height");f!==null&&(typeof f=="number"?x=f:typeof f=="string"&&(x=Number.parseFloat(f)));let g=!0,v=d(e.properties,"is-full-width");v!==null&&(g=v==="Yes");let O=!0,k=d(e.properties,"is-full-height");k!==null&&(O=k==="Yes");let u=d(e.properties,"image-quality");u??="high";let h=d(e.properties,"caption-source");h??="name";let I=d(e.properties,"alt-text-source");I??="name";let w=!1,C=d(e.properties,"is-transparent");C!==null&&(w=C==="Yes");let m=!1,E=d(e.properties,"is-cover");E!==null&&(m=E==="Yes");let $=null;if(a.length>1){let L=q(e.properties,"variant"),A=5;if(L&&L.values[0].content==="carousel"){let j=d(L.properties,"seconds-per-image");j!==null&&(typeof j=="number"?A=j:typeof j=="string"&&(A=Number.parseFloat(j)))}$={secondsPerImage:A}}t.images=a,t.variant=l,t.width=y,t.height=x,t.isFullWidth=g,t.isFullHeight=O,t.imageQuality=u,t.captionLayout=c,t.captionSource=h,t.altTextSource=I,t.isTransparentBackground=w,t.isCover=m,t.carouselOptions=$;break}case"image-gallery":{let a=i.find(c=>c.category==="tree"||c.category==="set");if(!a)throw new Error(`Image gallery link not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"is-searchable")==="Yes";t.galleryId=a.uuid,t.isSearchable=l;break}case"n-columns":{let a=r.resource?await he(Array.isArray(r.resource)?r.resource:[r.resource],"element"):[];t.columns=a;break}case"n-rows":{let a=r.resource?await he(Array.isArray(r.resource)?r.resource:[r.resource],"element"):[];t.rows=a;break}case"network-graph":break;case"table":{let a=i.find(l=>l.category==="set");if(!a)throw new Error(`Table link not found for the following component: \u201C${n}\u201D`);t.tableId=a.uuid;break}case"search-bar":{let a=d(e.properties,"variant");a??="default",t.variant=a;break}case"text":{if(!o)throw new Error(`Document not found for the following component: \u201C${n}\u201D`);let a=d(e.properties,"variant");a??="block";let l=d(e.properties,"heading");t.variant=a,t.heading=l,t.content=o.content;break}case"timeline":{let a=i.find(l=>l.category==="tree");if(!a)throw new Error(`Timeline link not found for the following component: \u201C${n}\u201D`);t.timelineId=a.uuid;break}case"video":{let a=i.find(c=>c.type==="video");if(!a)throw new Error(`Video link not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"chapters-displayed");l??="Yes",t.videoId=a.uuid,t.isChaptersDislayed=l==="Yes";break}default:{console.warn(`Invalid or non-implemented component name \u201C${n}\u201D for the following element: \u201C${S(r.identification.label)}\u201D`);break}}return t}async function ie(e){let r=P(e.identification),t=(e.properties?.property?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]).find(h=>h.label==="presentation");if(!t)throw new Error(`Presentation property not found for element \u201C${r.label}\u201D`);let i=t.properties.find(h=>h.label==="component");if(!i)throw new Error(`Component for element \u201C${r.label}\u201D not found`);let s=await Qe(i,e),a=t.properties.find(h=>h.label==="section-sidebar-displayed")?.values[0]?.booleanValue===!0,l=e.properties?.property?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],c=l.find(h=>h.label==="presentation"&&h.values[0].content==="css")?.properties??[],y=[];for(let h of c){let I=h.values[0].content;y.push({label:h.label,value:I})}let b=l.find(h=>h.label==="presentation"&&h.values[0].content==="css-mobile")?.properties??[],x=[];for(let h of b){let I=h.values[0].content;x.push({label:h.label,value:I})}let f=l.find(h=>h.label==="presentation"&&h.values[0].content==="title")?.properties,g="default",v=!1,O=!1,k=!1,u=!1;if(f){let h=d(f,"variant");h&&(g=h);let I=f.filter(w=>w.label==="display");I.length>0&&(v=I.some(w=>w.values[0].content==="name"),O=I.some(w=>w.values[0].content==="description"),k=I.some(w=>w.values[0].content==="date"),u=I.some(w=>w.values[0].content==="creators"))}return{uuid:e.uuid,type:"element",title:{label:r.label,variant:g,properties:{isNameDisplayed:v,isDescriptionDisplayed:O,isDateDisplayed:k,isCreatorsDisplayed:u}},isDisplayedInBlockSectionSidebar:a,cssStyles:y,cssStylesMobile:x,...s}}async function He(e){let r=e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];if(r.length===0||r.find(u=>u.label==="presentation")?.values[0]?.content!=="page")return null;let n=P(e.identification),t=e.slug;if(t===void 0)throw new Error(`Slug not found for page \u201C${n.label}\u201D`);let s=(e.links?U(Array.isArray(e.links)?e.links:[e.links]):[]).find(u=>u.type==="image"||u.type==="IIIF"),o=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],a=[];for(let u of o){let h=u.properties?T(Array.isArray(u.properties.property)?u.properties.property:[u.properties.property]):[],I=d(h,"presentation");if(I!=null)switch(I){case"element":{let w=await ie(u);a.push(w);break}case"block":{let w=await Se(u);w&&a.push(w);break}}}let l=e.resource?await he(Array.isArray(e.resource)?e.resource:[e.resource],"page"):[],c=!0,y="default",b="default",x=!0,f=r.find(u=>u.label==="presentation"&&u.values[0]?.content==="page")?.properties;if(f){let u=f.find(C=>C.label==="header")?.values[0];u&&(c=u.content==="Yes");let h=f.find(C=>C.label==="width")?.values[0];h&&(y=h.content);let I=f.find(C=>C.label==="variant")?.values[0];I&&(b=I.content);let w=f.find(C=>C.label==="sidebar-visible")?.values[0];w&&(x=w.content==="Yes")}let g=r.find(u=>u.label==="presentation"&&u.values[0]?.content==="css")?.properties,v=[];if(g)for(let u of g)v.push({label:u.label,value:u.values[0].content});let O=r.find(u=>u.label==="presentation"&&u.values[0]?.content==="css-mobile")?.properties,k=[];if(O)for(let u of O)k.push({label:u.label,value:u.values[0].content});return{title:n.label,slug:t,items:a,properties:{displayedInHeader:c,width:y,variant:b,backgroundImageUrl:s?`https://ochre.lib.uchicago.edu/ochre?uuid=${s.uuid}&load`:null,isSidebarDisplayed:x,cssStyles:v,cssStylesMobile:k},webpages:l}}async function Re(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n){let i=await He(t);i&&r.push(i)}return r}async function Se(e){let r={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?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],t=n.find(l=>l.label==="presentation"&&l.values[0]?.content==="block")?.properties;if(t){let l=t.find(g=>g.label==="layout")?.values[0];l&&(r.layout=l.content);let c=t.find(g=>g.label==="spacing")?.values[0];c&&(r.properties.spacing=c.content);let y=t.find(g=>g.label==="gap")?.values[0];y&&(r.properties.gap=y.content);let b=t.find(g=>g.label==="align-items")?.values[0];b&&(r.properties.alignItems=b.content);let x=t.find(g=>g.label==="justify-content")?.values[0];x&&(r.properties.justifyContent=x.content);let f=t.find(g=>g.label==="overwrite-mobile");if(f){let g=f.properties,v={};for(let O of g)v[O.label]=O.values[0].content;r.propertiesMobile=v}}let i=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],s=[];for(let l of i){let c=l.properties?T(Array.isArray(l.properties.property)?l.properties.property:[l.properties.property]):[],y=d(c,"presentation");if(y!=null)switch(y){case"element":{let b=await ie(l);s.push(b);break}case"block":{let b=await Se(l);b&&s.push(b);break}}}r.items=s;let o=n.find(l=>l.label==="presentation"&&l.values[0]?.content==="css")?.properties;if(o)for(let l of o)r.cssStyles.push({label:l.label,value:l.values[0].content});let a=n.find(l=>l.label==="presentation"&&l.values[0]?.content==="css-mobile")?.properties;if(a)for(let l of a)r.cssStylesMobile.push({label:l.label,value:l.values[0].content});return r.properties.sectionSidebarItems=Me(r),r}function Me(e){let r=[];for(let n of e.items)switch(n.type){case"block":{let t=Me(n);t!==null&&r.push({uuid:n.uuid,type:"block",name:null,items:t});break}case"element":{if(!n.isDisplayedInBlockSectionSidebar)continue;r.push({uuid:n.uuid,type:"element",name:n.title.label,items:null});break}}return r.length>0?r:null}function Xe(e){let n=T(e).find(A=>A.label==="presentation")?.properties;if(!n)throw new Error("Presentation property not found");let t=n.find(A=>A.label==="webUI")?.values[0]?.content;if(t==null)throw new Error("Website type not found");let i=n.find(A=>A.label==="status")?.values[0]?.content;if(i==null)throw new Error("Website status not found");let s=n.find(A=>A.label==="privacy")?.values[0]?.content;s??="public";let o=Ie.safeParse({type:t,status:i,privacy:s});if(!o.success)throw new Error(`Invalid website properties: ${o.error.message}`);let a=null,l=n.find(A=>A.label==="contact");if(l){let[A,j]=(l.values[0]?.content).split(";");a={name:A,email:j??null}}let c=n.find(A=>A.label==="logo")?.values[0]?.uuid??null,y=!0,b="default",x="start",f=!0,g=!0,v=!1,O=!0,k=n.find(A=>A.label==="navbar-visible")?.values[0];k&&(y=k.content==="Yes");let u=n.find(A=>A.label==="navbar-variant")?.values[0];u&&(b=u.content);let h=n.find(A=>A.label==="navbar-alignment")?.values[0];h&&(x=h.content);let I=n.find(A=>A.label==="navbar-project-visible")?.values[0];I&&(f=I.content==="Yes");let w=n.find(A=>A.label==="footer-visible")?.values[0];w&&(g=w.content==="Yes");let C=n.find(A=>A.label==="sidebar-visible")?.values[0];C&&(v=C.content==="Yes");let m=n.find(A=>A.label==="supports-theme-toggle")?.values[0];m&&(O=m.content==="Yes");let{type:E,status:$,privacy:L}=o.data;return{type:E,privacy:L,status:$,contact:a,isHeaderDisplayed:y,headerVariant:b,headerAlignment:x,isHeaderProjectDisplayed:f,isFooterDisplayed:g,isSidebarDisplayed:v,supportsThemeToggle:O,logoUrl:c!==null?`https://ochre.lib.uchicago.edu/ochre?uuid=${c}&load`:null}}async function Pe(e,r,n){if(!e.properties)throw new Error("Website properties not found");let t=Xe(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]);if(typeof e.items=="string"||!("resource"in e.items))throw new Error("Website pages not found");let i=Array.isArray(e.items.resource)?e.items.resource:[e.items.resource],s=await Re(i),o=null,a=[],l={label:"",variant:"default",properties:{isNameDisplayed:!1,isDescriptionDisplayed:!1,isDateDisplayed:!1,isCreatorsDisplayed:!1}},c="start",y="default",b=[],x=[],f=i.find(v=>(v.properties?T(Array.isArray(v.properties.property)?v.properties.property:[v.properties.property]):[]).some(k=>k.label==="presentation"&&k.values[0]?.content==="element"&&k.properties[0]?.label==="component"&&k.properties[0].values[0]?.content==="sidebar"));if(f){l.label=typeof f.identification.label=="string"||typeof f.identification.label=="number"||typeof f.identification.label=="boolean"?p(f.identification.label):S(f.identification.label);let v=f.properties?T(Array.isArray(f.properties.property)?f.properties.property:[f.properties.property]):[],O=v.find(m=>m.label==="presentation"&&m.values[0]?.content==="element")?.properties.find(m=>m.label==="component"&&m.values[0]?.content==="sidebar")?.properties??[],k=O.find(m=>m.label==="layout");k&&(c=k.values[0].content);let u=O.find(m=>m.label==="layout-mobile");u&&(y=u.values[0].content);let h=v.find(m=>m.label==="presentation"&&m.values[0].content==="css")?.properties??[];for(let m of h){let E=m.values[0].content;b.push({label:m.label,value:E})}let I=v.find(m=>m.label==="presentation"&&m.values[0].content==="css-mobile")?.properties??[];for(let m of I){let E=m.values[0].content;x.push({label:m.label,value:E})}let w=v.find(m=>m.label==="presentation"&&m.values[0].content==="title")?.properties;if(w){let m=d(w,"variant");m&&(l.variant=m);let E=w.filter($=>$.label==="display");E.length>0&&(l.properties.isNameDisplayed=E.some($=>$.values[0].content==="name"),l.properties.isDescriptionDisplayed=E.some($=>$.values[0].content==="description"),l.properties.isDateDisplayed=E.some($=>$.values[0].content==="date"),l.properties.isCreatorsDisplayed=E.some($=>$.values[0].content==="creators"))}let C=f.resource?Array.isArray(f.resource)?f.resource:[f.resource]:[];for(let m of C){let E=await ie(m);a.push(E)}}a.length>0&&(o={elements:a,title:l,layout:c,mobileLayout:y,cssStyles:b,cssStylesMobile:x});let g=null;if(e.searchOptions){let v=[];for(let O of s)for(let k of O.items)k.type==="element"&&k.component==="collection"&&v.push(k.collectionId);g={uuids:v,properties:{metadataUuids:[...e.searchOptions.metadata?.option??[]],searchUuids:[...e.searchOptions.filters?.option??[]],labelUuids:[...e.searchOptions.labels?.option??[]]}}}return{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:P(e.identification),project:{name:p(r),website:n!==null?p(n):null},creators:e.creators?W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:B(e.availability),pages:s,sidebar:o,properties:t,collectionOptions:g}}async function Ze(e,r,n,t){try{let{uuid:i,filter:s,page:o,perPage:a}=Oe.parse({uuid:e,filter:r,page:n,perPage:t}),l=await fetch(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
4
+ ${JSON.stringify(e.content)}.`);return G(t)}}else return G(e.content);default:return String(e.content).replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}}function J(e){let r=e.find(t=>ae.safeParse(t).success);if(!r){let t=e.find(i=>!["uuid","uuidBelongsTo","belongsTo","publicationDateTime","metadata","languages"].includes(i));throw new Error(`Invalid OCHRE data; found unexpected "${t}" key`)}return ae.parse(r)}async function ce(e){try{let r=ke.parse(e),n=await fetch(`https://ochre.lib.uchicago.edu/ochre?uuid=${r}&format=json&lang="*"`);if(!n.ok)throw new Error("Failed to fetch OCHRE data");let t=await n.json();if(!("ochre"in t))throw new Error("Invalid OCHRE data: API response missing 'ochre' key");return[null,t]}catch(r){return[r instanceof Error?r.message:"Unknown error",null]}}async function pe(e,r,n){try{let[t,i]=await ce(e);if(t!==null)throw new Error(t);let s=J(Object.keys(i.ochre)),o;switch(s){case"resource":{if(!("resource"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'resource' key");o=X(i.ochre.resource);break}case"spatialUnit":{if(!("spatialUnit"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'spatialUnit' key");o=Z(i.ochre.spatialUnit);break}case"concept":{if(!("concept"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'concept' key");o=ee(i.ochre.concept);break}case"period":{if(!("period"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'period' key");o=z(i.ochre.period);break}case"bibliography":{if(!("bibliography"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'bibliography' key");o=Q(i.ochre.bibliography);break}case"person":{if(!("person"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'person' key");o=_(i.ochre.person);break}case"propertyValue":{if(!("propertyValue"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'propertyValue' key");o=R(i.ochre.propertyValue);break}case"set":{if(!("set"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'set' key");o=fe(i.ochre.set,n);break}case"tree":{if(!("tree"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'tree' key");o=de(i.ochre.tree);break}default:throw new Error("Invalid category")}let a=ue(i.ochre.metadata),l={uuid:i.ochre.uuidBelongsTo,abbreviation:p(i.ochre.belongsTo)};return{error:null,metadata:a,belongsTo:l,item:o,category:r}}catch(t){return{error:t instanceof Error?t.message:"Unknown error",metadata:void 0,belongsTo:void 0,item:void 0,category:void 0}}}function P(e){try{let r={label:["string","number","boolean"].includes(typeof e.label)?p(e.label):S(e.label),abbreviation:""};for(let n of Object.keys(e).filter(t=>t!=="label"))r[n]=S(e[n]);return r}catch(r){return console.error(r),{label:"",abbreviation:""}}}function Fe(e){return e==null?["eng"]:Array.isArray(e)?e.map(r=>S(r)):[S(e)]}function ue(e){let r={label:"",abbreviation:""};if(e.item)if(e.item.label||e.item.abbreviation){let i="",s="";e.item.label&&(i=S(e.item.label)),e.item.abbreviation&&(s=S(e.item.abbreviation)),r={label:i,abbreviation:s}}else r=P(e.item.identification);let n=null,t=e.project?.identification?P(e.project.identification):null;return t&&(n={...t,website:e.project?.identification.website??null}),{project:n?{identification:n}:null,item:e.item?{identification:r,category:e.item.category,type:e.item.type,maxLength:e.item.maxLength??null}:null,dataset:S(e.dataset),publisher:S(e.publisher),languages:Fe(e.language),identifier:S(e.identifier),description:S(e.description)}}function ye(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,number:e.n,content:p(e.content)}}function V(e){return{nodes:(Array.isArray(e.context)?e.context:[e.context]).map(t=>{let i=[];if("spatialUnit"in t&&t.spatialUnit){let s=Array.isArray(t.spatialUnit)?t.spatialUnit:[t.spatialUnit];for(let o of s)i.push(ye(o))}return{tree:ye(t.tree),project:ye(t.project),spatialUnit:i}}),displayPath:e.displayPath}}function B(e){return typeof e.license=="string"?null:{content:e.license.content,url:e.license.target}}function _(e){return{uuid:e.uuid,category:"person",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type??null,number:e.n??null,context:e.context?V(e.context):null,date:e.date!=null?new Date(e.date):null,identification:e.identification?P(e.identification):null,availability:e.availability?B(e.availability):null,address:e.address?{country:e.address.country??null,city:e.address.city??null,state:e.address.state??null}:null,coordinates:e.coordinates?te(e.coordinates):null,content:e.content!=null?p(e.content):null,events:e.events?ge(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function W(e){let r=[];for(let n of e)r.push(_(n));return r}function Be(e){let r="resource"in e?e.resource:"spatialUnit"in e?e.spatialUnit:"concept"in e?e.concept:"set"in e?e.set:"tree"in e?e.tree:"person"in e?e.person:"bibliography"in e?e.bibliography:"epigraphicUnit"in e?e.epigraphicUnit:"propertyValue"in e?e.propertyValue:null;if(!r)throw new Error(`Invalid link provided: ${JSON.stringify(e,null,2)}`);let n=Array.isArray(r)?r:[r],t=[];for(let i of n){let s={category:"resource"in e?"resource":"spatialUnit"in e?"spatialUnit":"concept"in e?"concept":"set"in e?"set":"person"in e?"person":"tree"in e?"tree":"bibliography"in e?"bibliography":"epigraphicUnit"in e?"epigraphicUnit":"propertyValue"in e?"propertyValue":null,content:"content"in i&&i.content!=null?p(i.content):null,href:"href"in i&&i.href!=null?i.href:null,uuid:i.uuid,type:i.type??null,identification:i.identification?P(i.identification):null,image:null,bibliographies:"bibliography"in e?Y(Array.isArray(e.bibliography)?e.bibliography:[e.bibliography]):null,publicationDateTime:i.publicationDateTime!=null?new Date(i.publicationDateTime):null};"height"in i&&i.height!=null&&i.width!=null&&i.heightPreview!=null&&i.widthPreview!=null&&(s.image={isInline:i.rend==="inline",isPrimary:i.isPrimary??!1,heightPreview:i.heightPreview,widthPreview:i.widthPreview,height:i.height,width:i.width}),t.push(s)}return t}function j(e){let r=[];for(let n of e)r.push(...Be(n));return r}function re(e,r="eng"){let n="",t=[],i=Array.isArray(e)?e.find(s=>s.lang===r):e;if(typeof i.string=="string"||typeof i.string=="number"||typeof i.string=="boolean")n+=F(p(i.string));else{let s=Array.isArray(i.string)?i.string:[i.string];for(let o of s)n+=K(o,t)}return{content:n,footnotes:t}}function me(e){return{publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,identification:e.identification?P(e.identification):null,url:e.href??(e.htmlImgSrcPrefix==null&&e.content!=null?p(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?p(e.content):null,widthPreview:e.widthPreview??null,heightPreview:e.heightPreview??null,width:e.width??null,height:e.height??null}}function ne(e,r="eng"){let n=[];for(let t of e){if(typeof t=="string"){if(t==="")continue;n.push({number:-1,title:null,content:t});continue}let i="",s=Array.isArray(t.content)?t.content:[t.content],o=s.find(a=>a.lang===r);if(!o&&(o=s[0],!o))throw new Error(`Note does not have a valid content item: ${JSON.stringify(t,null,2)}`);typeof o.string=="string"||typeof o.string=="number"||typeof o.string=="boolean"?i=F(p(o.string)):i=F(re(o).content),n.push({number:t.noteNo,title:o.title!=null?p(o.title):null,content:i})}return n}function te(e){if(typeof e=="string"){let[r,n]=e.split(", ");return{latitude:Number(r),longitude:Number(n),type:null,label:null}}return{latitude:e.latitude,longitude:e.longitude,type:e.coord?.coordType??null,label:e.coord?.coordLabel!=null?p(e.coord.coordLabel):null}}function be(e){return{number:e.observationNo,date:e.date!=null?new Date(e.date):null,observers:e.observers!=null?p(e.observers).split(";").map(r=>r.trim()):[],notes:e.notes?ne(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?j(Array.isArray(e.links)?e.links:[e.links]):[],properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function Ue(e){let r=[];for(let n of e)r.push(be(n));return r}function ge(e){let r=[];for(let n of e)r.push({date:n.dateTime!=null?new Date(n.dateTime):null,label:S(n.label),agent:n.agent?{uuid:n.agent.uuid,content:p(n.agent.content)}:null});return r}function je(e,r="eng"){let t=("value"in e&&e.value?Array.isArray(e.value)?e.value:[e.value]:[]).map(i=>{let s=null,o=null;if(typeof i=="string"||typeof i=="number"||typeof i=="boolean")return s=p(i),{content:s,booleanValue:o,isUncertain:!1,type:"string",category:"value",uuid:null,publicationDateTime:null,unit:null};{switch(i.type){case"integer":case"decimal":{s=Number(i.content);break}case"dateTime":{s=i.content?typeof i.content=="string"?new Date(i.content):new Date(S({content:i.content})):null;break}default:{"slug"in i&&i.slug!=null?s=p(i.slug):i.content!=null&&(s=S({content:i.content})),i.type==="boolean"&&(o=i.booleanValue??null);break}}let a="string";if(i.type!=null){let{data:c,error:y}=De.safeParse(i.type);if(y)throw new Error(`Invalid property value content type: "${i.type}"`);a=c}return{content:s,booleanValue:o,isUncertain:i.isUncertain??!1,type:a,category:i.category??"value",uuid:i.uuid??null,publicationDateTime:i.publicationDateTime!=null?new Date(i.publicationDateTime):null,unit:i.unit??null}}});return{uuid:e.label.uuid,label:S(e.label,r).replace(/\s*\.{3}$/,"").trim(),values:t,comment:e.comment!=null?p(e.comment):null,properties:e.property?T(Array.isArray(e.property)?e.property:[e.property]):[]}}function T(e,r="eng"){let n=[];for(let t of e)n.push(je(t,r));return n}function Ve(e){let r=[];for(let n of e)r.push({date:new Date(n.date),number:n.interpretationNo,properties:n.properties?T(Array.isArray(n.properties.property)?n.properties.property:[n.properties.property]):[]});return r}function Ne(e){let r={area:[],width:e.width,height:e.height},n=Array.isArray(e.area)?e.area:[e.area];for(let t of n)r.area.push({uuid:t.uuid,publicationDateTime:t.publicationDateTime!=null?new Date(t.publicationDateTime):null,type:t.type,title:p(t.title),shape:t.shape==="rect"?"rectangle":"polygon",coords:t.coords.split(",").map(i=>Number.parseInt(i))});return r}function z(e){return{uuid:e.uuid,category:"period",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type??null,number:e.n??null,identification:P(e.identification),description:e.description?S(e.description):null}}function M(e){let r=[];for(let n of e)r.push(z(n));return r}function Q(e){let r=null;return e.source?.resource&&(r={uuid:e.source.resource.uuid,publicationDateTime:e.source.resource.publicationDateTime?new Date(e.source.resource.publicationDateTime):null,type:e.source.resource.type,identification:P(e.source.resource.identification)}),{uuid:e.uuid,category:"bibliography",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,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?V(e.context):null,citation:{format:e.citationFormat??null,short:e.citationFormatSpan?p("default:span"in e.citationFormatSpan?e.citationFormatSpan["default:span"].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?p("default:div"in e.referenceFormatDiv?e.referenceFormatDiv["default:div"]["default:div"].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?W(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:p(e.entryInfo.startIssue),startVolume:p(e.entryInfo.startVolume)}:null,source:{resource:r,documentUrl:e.sourceDocument?`https://ochre.lib.uchicago.edu/ochre?uuid=${e.sourceDocument.uuid}&load`:null},periods:e.periods?M(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],authors:e.authors?W(Array.isArray(e.authors.person)?e.authors.person:[e.authors.person]):[],properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function Y(e){let r=[];for(let n of e)r.push(Q(n));return r}function R(e){return{uuid:e.uuid,category:"propertyValue",number:e.n,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,context:e.context?V(e.context):null,availability:e.availability?B(e.availability):null,identification:P(e.identification),date:e.date?new Date(e.date):null,creators:e.creators?W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],description:e.description?["string","number","boolean"].includes(typeof e.description)?p(e.description):S(e.description):"",notes:e.notes?ne(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?j(Array.isArray(e.links)?e.links:[e.links]):[]}}function Ae(e){let r=[];for(let n of e)r.push(R(n));return r}function de(e){let r=[];e.creators&&(r=W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]));let n=null;e.date!=null&&(n=new Date(e.date));let t=[],i=[],s=[],o=[],a=[],l=[],c=[];return typeof e.items!="string"&&"resource"in e.items&&(t=N(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource])),typeof e.items!="string"&&"spatialUnit"in e.items&&(i=ve(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit])),typeof e.items!="string"&&"concept"in e.items&&(s=we(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept])),typeof e.items!="string"&&"period"in e.items&&(o=M(Array.isArray(e.items.period)?e.items.period:[e.items.period])),typeof e.items!="string"&&"bibliography"in e.items&&(a=Y(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography])),typeof e.items!="string"&&"person"in e.items&&(l=W(Array.isArray(e.items.person)?e.items.person:[e.items.person])),typeof e.items!="string"&&"propertyValue"in e.items&&(c=Ae(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue])),{uuid:e.uuid,category:"tree",publicationDateTime:new Date(e.publicationDateTime),identification:P(e.identification),creators:r,license:B(e.availability),date:n,type:e.type,number:e.n,items:{resources:t,spatialUnits:i,concepts:s,periods:o,bibliographies:a,persons:l,propertyValues:c},properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function fe(e,r){if(typeof e.items=="string")throw new TypeError("Invalid OCHRE data: Set has no items");let n=r??J(Object.keys(e.items)),t=[];switch(n){case"resource":{if(!("resource"in e.items))throw new Error("Invalid OCHRE data: Set has no resources");t=N(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource]);break}case"spatialUnit":{if(!("spatialUnit"in e.items))throw new Error("Invalid OCHRE data: Set has no spatial units");t=ve(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit]);break}case"concept":{if(!("concept"in e.items))throw new Error("Invalid OCHRE data: Set has no concepts");t=we(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept]);break}case"period":{if(!("period"in e.items))throw new Error("Invalid OCHRE data: Set has no periods");t=M(Array.isArray(e.items.period)?e.items.period:[e.items.period]);break}case"bibliography":{if(!("bibliography"in e.items))throw new Error("Invalid OCHRE data: Set has no bibliographies");t=Y(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography]);break}case"person":{if(!("person"in e.items))throw new Error("Invalid OCHRE data: Set has no persons");t=W(Array.isArray(e.items.person)?e.items.person:[e.items.person]);break}case"propertyValue":{if(!("propertyValue"in e.items))throw new Error("Invalid OCHRE data: Set has no property values");t=Ae(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]);break}default:throw new Error("Invalid OCHRE data: Set has no items or is malformed")}return{uuid:e.uuid,category:"set",itemCategory:r,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,date:e.date!=null?new Date(e.date):null,license:B(e.availability),identification:P(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?["string","number","boolean"].includes(typeof e.description)?p(e.description):S(e.description):"",creators:e.creators?W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],type:e.type,number:e.n,items:t}}function X(e){return{uuid:e.uuid,category:"resource",publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,type:e.type,number:e.n,format:e.format??null,context:"context"in e&&e.context?V(e.context):null,license:"availability"in e&&e.availability?B(e.availability):null,copyright:"copyright"in e&&e.copyright!=null?p(e.copyright):null,identification:P(e.identification),date:e.date!=null?new Date(e.date):null,image:e.image?me(e.image):null,creators:e.creators?W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],notes:e.notes?ne(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],description:e.description?["string","number","boolean"].includes(typeof e.description)?p(e.description):S(e.description):"",document:e.document&&"content"in e.document?re(e.document.content):null,href:e.href??null,imageMap:e.imagemap?Ne(e.imagemap):null,periods:e.periods?M(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],links:e.links?j(Array.isArray(e.links)?e.links:[e.links]):[],reverseLinks:e.reverseLinks?j(Array.isArray(e.reverseLinks)?e.reverseLinks:[e.reverseLinks]):[],properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],citedBibliographies:e.citedBibliography?Y(Array.isArray(e.citedBibliography.reference)?e.citedBibliography.reference:[e.citedBibliography.reference]):[],resources:e.resource?N(Array.isArray(e.resource)?e.resource:[e.resource]):[]}}function N(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(X(t));return r}function Z(e){return{uuid:e.uuid,category:"spatialUnit",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type,number:e.n,context:"context"in e&&e.context?V(e.context):null,license:"availability"in e&&e.availability?B(e.availability):null,identification:P(e.identification),image:e.image?me(e.image):null,description:e.description?["string","number","boolean"].includes(typeof e.description)?p(e.description):S(e.description):"",coordinates:e.coordinates?te(e.coordinates):e.coordinate?te(e.coordinate):null,observations:"observations"in e&&e.observations?Ue(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[be(e.observation)]:[],events:"events"in e&&e.events?ge(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:"properties"in e&&e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function ve(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(Z(t));return r}function ee(e){return{uuid:e.uuid,category:"concept",publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,number:e.n,license:"availability"in e&&e.availability?B(e.availability):null,context:"context"in e&&e.context?V(e.context):null,identification:P(e.identification),interpretations:Ve(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation])}}var he=async(e,r)=>{let n=[];for(let t of e)if((t.properties?T(Array.isArray(t.properties.property)?t.properties.property:[t.properties.property]):[]).find(o=>o.label==="presentation"&&o.values[0].content===r))switch(r){case"element":{let o=await ie(t);n.push(o);break}case"page":{let o=await He(t);o&&n.push(o);break}case"block":{let o=await Se(t);o&&n.push(o);break}}return n};function we(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(ee(t));return r}async function Qe(e,r){let n=xe.parse(e.values[0].content),t={component:n},i=r.links?j(Array.isArray(r.links)?r.links:[r.links]):[],s=i.filter(a=>a.type==="image"||a.type==="IIIF"),o=r.document&&"content"in r.document?re(r.document.content):null;if(o===null){let a=i.find(l=>l.type==="internalDocument");if(a){let{item:l,error:c}=await pe(a.uuid,"resource");if(c!==null)throw new Error("Failed to fetch OCHRE data");o=l.document}}switch(n){case"annotated-document":{if(!o)throw new Error(`Document not found for the following component: \u201C${n}\u201D`);t.document=o;break}case"annotated-image":{if(s.length===0)throw new Error(`Image link not found for the following component: \u201C${n}\u201D`);let a=d(e.properties,"is-searchable")==="Yes";t.imageUuid=s[0].uuid,t.isSearchable=a;break}case"bibliography":{let a=i.find(c=>c.category==="bibliography");if(!a)throw new Error(`Bibliography link not found for the following component: \u201C${n}\u201D`);if(!a.bibliographies)throw new Error(`Bibliography not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"layout");l??="long",t.bibliographies=a.bibliographies,t.layout=l;break}case"button":{let a=d(e.properties,"variant");a??="default";let l=!1,c=d(e.properties,"navigate-to");if(c===null){if(c=d(e.properties,"link-to"),c===null)throw new Error(`Properties \u201Cnavigate-to\u201D or \u201Clink-to\u201D not found for the following component: \u201C${n}\u201D`);l=!0}let y=null,b=d(e.properties,"icon");b!==null&&(y=b),t.variant=a,t.href=c,t.isExternal=l,t.label=["string","number","boolean"].includes(typeof r.identification.label)?p(r.identification.label):S(r.identification.label),t.icon=y;break}case"collection":{let a=i.find(v=>v.category==="set");if(!a)throw new Error(`Collection link not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"variant");l??="full";let c=d(e.properties,"item-variant");c??="default";let y=!1,b=d(e.properties,"show-count");b!==null&&(y=b==="Yes");let x=!1,f=d(e.properties,"is-searchable");f!==null&&(x=f==="Yes");let g=d(e.properties,"layout");g??="image-start",t.collectionId=a.uuid,t.variant=l,t.itemVariant=c,t.isSearchable=x,t.showCount=y,t.layout=g;break}case"empty-space":{let a=d(e.properties,"height"),l=d(e.properties,"width");t.height=a,t.width=l;break}case"entries":{let a=i.find(b=>b.category==="tree");if(!a)throw new Error(`Entries link not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"variant");l??="entry";let c=!1,y=d(e.properties,"is-searchable");y!==null&&(c=y==="Yes"),t.entriesId=a.uuid,t.variant=l,t.isSearchable=c;break}case"filter-categories":{let a=i.find(l=>l.category==="set");if(!a)throw new Error(`Filter link not found for the following component: \u201C${n}\u201D`);t.filterId=a.uuid;break}case"iframe":{let a=i.find(y=>y.type==="webpage")?.href;if(!a)throw new Error(`URL not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"height"),c=d(e.properties,"width");t.href=a,t.height=l,t.width=c;break}case"iiif-viewer":{let a=i.find(l=>l.type==="IIIF");if(!a)throw new Error(`Manifest link not found for the following component: \u201C${n}\u201D`);t.IIIFId=a.uuid;break}case"image":{if(s.length===0)throw new Error(`Image link not found for the following component: \u201C${n}\u201D`);let a=[];for(let L of s)a.push({url:`https://ochre.lib.uchicago.edu/ochre?uuid=${L.uuid}&load`,label:L.identification?.label??null,width:L.image?.width??0,height:L.image?.height??0});let l=d(e.properties,"variant");l??="default";let c=d(e.properties,"layout-caption");c??="bottom";let y=null,b=d(e.properties,"width");b!==null&&(typeof b=="number"?y=b:typeof b=="string"&&(y=Number.parseFloat(b)));let x=null,f=d(e.properties,"height");f!==null&&(typeof f=="number"?x=f:typeof f=="string"&&(x=Number.parseFloat(f)));let g=!0,v=d(e.properties,"is-full-width");v!==null&&(g=v==="Yes");let O=!0,k=d(e.properties,"is-full-height");k!==null&&(O=k==="Yes");let u=d(e.properties,"image-quality");u??="high";let h=d(e.properties,"caption-source");h??="name";let I=d(e.properties,"alt-text-source");I??="name";let w=!1,C=d(e.properties,"is-transparent");C!==null&&(w=C==="Yes");let m=!1,E=d(e.properties,"is-cover");E!==null&&(m=E==="Yes");let $=null;if(a.length>1){let L=q(e.properties,"variant"),A=5;if(L&&L.values[0].content==="carousel"){let U=d(L.properties,"seconds-per-image");U!==null&&(typeof U=="number"?A=U:typeof U=="string"&&(A=Number.parseFloat(U)))}$={secondsPerImage:A}}t.images=a,t.variant=l,t.width=y,t.height=x,t.isFullWidth=g,t.isFullHeight=O,t.imageQuality=u,t.captionLayout=c,t.captionSource=h,t.altTextSource=I,t.isTransparentBackground=w,t.isCover=m,t.carouselOptions=$;break}case"image-gallery":{let a=i.find(c=>c.category==="tree"||c.category==="set");if(!a)throw new Error(`Image gallery link not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"is-searchable")==="Yes";t.galleryId=a.uuid,t.isSearchable=l;break}case"n-columns":{let a=r.resource?await he(Array.isArray(r.resource)?r.resource:[r.resource],"element"):[];t.columns=a;break}case"n-rows":{let a=r.resource?await he(Array.isArray(r.resource)?r.resource:[r.resource],"element"):[];t.rows=a;break}case"network-graph":break;case"table":{let a=i.find(l=>l.category==="set");if(!a)throw new Error(`Table link not found for the following component: \u201C${n}\u201D`);t.tableId=a.uuid;break}case"search-bar":{let a=d(e.properties,"variant");a??="default",t.variant=a;break}case"text":{if(!o)throw new Error(`Document not found for the following component: \u201C${n}\u201D`);let a=d(e.properties,"variant");a??="block";let l=d(e.properties,"heading");t.variant=a,t.heading=l,t.content=o.content;break}case"timeline":{let a=i.find(l=>l.category==="tree");if(!a)throw new Error(`Timeline link not found for the following component: \u201C${n}\u201D`);t.timelineId=a.uuid;break}case"video":{let a=i.find(c=>c.type==="video");if(!a)throw new Error(`Video link not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"chapters-displayed");l??="Yes",t.videoId=a.uuid,t.isChaptersDislayed=l==="Yes";break}default:{console.warn(`Invalid or non-implemented component name \u201C${n}\u201D for the following element: \u201C${S(r.identification.label)}\u201D`);break}}return t}async function ie(e){let r=P(e.identification),t=(e.properties?.property?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]).find(h=>h.label==="presentation");if(!t)throw new Error(`Presentation property not found for element \u201C${r.label}\u201D`);let i=t.properties.find(h=>h.label==="component");if(!i)throw new Error(`Component for element \u201C${r.label}\u201D not found`);let s=await Qe(i,e),a=t.properties.find(h=>h.label==="section-sidebar-displayed")?.values[0]?.booleanValue===!0,l=e.properties?.property?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],c=l.find(h=>h.label==="presentation"&&h.values[0].content==="css")?.properties??[],y=[];for(let h of c){let I=h.values[0].content;y.push({label:h.label,value:I})}let b=l.find(h=>h.label==="presentation"&&h.values[0].content==="css-mobile")?.properties??[],x=[];for(let h of b){let I=h.values[0].content;x.push({label:h.label,value:I})}let f=l.find(h=>h.label==="presentation"&&h.values[0].content==="title")?.properties,g="default",v=!1,O=!1,k=!1,u=!1;if(f){let h=d(f,"variant");h&&(g=h);let I=f.filter(w=>w.label==="display");I.length>0&&(v=I.some(w=>w.values[0].content==="name"),O=I.some(w=>w.values[0].content==="description"),k=I.some(w=>w.values[0].content==="date"),u=I.some(w=>w.values[0].content==="creators"))}return{uuid:e.uuid,type:"element",title:{label:r.label,variant:g,properties:{isNameDisplayed:v,isDescriptionDisplayed:O,isDateDisplayed:k,isCreatorsDisplayed:u}},isDisplayedInBlockSectionSidebar:a,cssStyles:y,cssStylesMobile:x,...s}}async function He(e){let r=e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];if(r.length===0||r.find(u=>u.label==="presentation")?.values[0]?.content!=="page")return null;let n=P(e.identification),t=e.slug;if(t===void 0)throw new Error(`Slug not found for page \u201C${n.label}\u201D`);let s=(e.links?j(Array.isArray(e.links)?e.links:[e.links]):[]).find(u=>u.type==="image"||u.type==="IIIF"),o=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],a=[];for(let u of o){let h=u.properties?T(Array.isArray(u.properties.property)?u.properties.property:[u.properties.property]):[],I=d(h,"presentation");if(I!=null)switch(I){case"element":{let w=await ie(u);a.push(w);break}case"block":{let w=await Se(u);w&&a.push(w);break}}}let l=e.resource?await he(Array.isArray(e.resource)?e.resource:[e.resource],"page"):[],c=!0,y="default",b="default",x=!0,f=r.find(u=>u.label==="presentation"&&u.values[0]?.content==="page")?.properties;if(f){let u=f.find(C=>C.label==="header")?.values[0];u&&(c=u.content==="Yes");let h=f.find(C=>C.label==="width")?.values[0];h&&(y=h.content);let I=f.find(C=>C.label==="variant")?.values[0];I&&(b=I.content);let w=f.find(C=>C.label==="sidebar-visible")?.values[0];w&&(x=w.content==="Yes")}let g=r.find(u=>u.label==="presentation"&&u.values[0]?.content==="css")?.properties,v=[];if(g)for(let u of g)v.push({label:u.label,value:u.values[0].content});let O=r.find(u=>u.label==="presentation"&&u.values[0]?.content==="css-mobile")?.properties,k=[];if(O)for(let u of O)k.push({label:u.label,value:u.values[0].content});return{title:n.label,slug:t,items:a,properties:{displayedInHeader:c,width:y,variant:b,backgroundImageUrl:s?`https://ochre.lib.uchicago.edu/ochre?uuid=${s.uuid}&load`:null,isSidebarDisplayed:x,cssStyles:v,cssStylesMobile:k},webpages:l}}async function Re(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n){let i=await He(t);i&&r.push(i)}return r}async function Se(e){let r={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?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],t=n.find(l=>l.label==="presentation"&&l.values[0]?.content==="block")?.properties;if(t){let l=t.find(g=>g.label==="layout")?.values[0];l&&(r.layout=l.content);let c=t.find(g=>g.label==="spacing")?.values[0];c&&(r.properties.spacing=c.content);let y=t.find(g=>g.label==="gap")?.values[0];y&&(r.properties.gap=y.content);let b=t.find(g=>g.label==="align-items")?.values[0];b&&(r.properties.alignItems=b.content);let x=t.find(g=>g.label==="justify-content")?.values[0];x&&(r.properties.justifyContent=x.content);let f=t.find(g=>g.label==="overwrite-mobile");if(f){let g=f.properties,v={};for(let O of g)v[O.label]=O.values[0].content;r.propertiesMobile=v}}let i=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],s=[];for(let l of i){let c=l.properties?T(Array.isArray(l.properties.property)?l.properties.property:[l.properties.property]):[],y=d(c,"presentation");if(y!=null)switch(y){case"element":{let b=await ie(l);s.push(b);break}case"block":{let b=await Se(l);b&&s.push(b);break}}}r.items=s;let o=n.find(l=>l.label==="presentation"&&l.values[0]?.content==="css")?.properties;if(o)for(let l of o)r.cssStyles.push({label:l.label,value:l.values[0].content});let a=n.find(l=>l.label==="presentation"&&l.values[0]?.content==="css-mobile")?.properties;if(a)for(let l of a)r.cssStylesMobile.push({label:l.label,value:l.values[0].content});return r.properties.sectionSidebarItems=Me(r),r}function Me(e){let r=[];for(let n of e.items)switch(n.type){case"block":{let t=Me(n);t!==null&&r.push({uuid:n.uuid,type:"block",name:null,items:t});break}case"element":{if(!n.isDisplayedInBlockSectionSidebar)continue;r.push({uuid:n.uuid,type:"element",name:n.title.label,items:null});break}}return r.length>0?r:null}function Xe(e){let n=T(e).find(A=>A.label==="presentation")?.properties;if(!n)throw new Error("Presentation property not found");let t=n.find(A=>A.label==="webUI")?.values[0]?.content;if(t==null)throw new Error("Website type not found");let i=n.find(A=>A.label==="status")?.values[0]?.content;if(i==null)throw new Error("Website status not found");let s=n.find(A=>A.label==="privacy")?.values[0]?.content;s??="public";let o=Ie.safeParse({type:t,status:i,privacy:s});if(!o.success)throw new Error(`Invalid website properties: ${o.error.message}`);let a=null,l=n.find(A=>A.label==="contact");if(l){let[A,U]=(l.values[0]?.content).split(";");a={name:A,email:U??null}}let c=n.find(A=>A.label==="logo")?.values[0]?.uuid??null,y=!0,b="default",x="start",f=!0,g=!0,v=!1,O=!0,k=n.find(A=>A.label==="navbar-visible")?.values[0];k&&(y=k.content==="Yes");let u=n.find(A=>A.label==="navbar-variant")?.values[0];u&&(b=u.content);let h=n.find(A=>A.label==="navbar-alignment")?.values[0];h&&(x=h.content);let I=n.find(A=>A.label==="navbar-project-visible")?.values[0];I&&(f=I.content==="Yes");let w=n.find(A=>A.label==="footer-visible")?.values[0];w&&(g=w.content==="Yes");let C=n.find(A=>A.label==="sidebar-visible")?.values[0];C&&(v=C.content==="Yes");let m=n.find(A=>A.label==="supports-theme-toggle")?.values[0];m&&(O=m.content==="Yes");let{type:E,status:$,privacy:L}=o.data;return{type:E,privacy:L,status:$,contact:a,isHeaderDisplayed:y,headerVariant:b,headerAlignment:x,isHeaderProjectDisplayed:f,isFooterDisplayed:g,isSidebarDisplayed:v,supportsThemeToggle:O,logoUrl:c!==null?`https://ochre.lib.uchicago.edu/ochre?uuid=${c}&load`:null}}async function Pe(e,r,n){if(!e.properties)throw new Error("Website properties not found");let t=Xe(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]);if(typeof e.items=="string"||!("resource"in e.items))throw new Error("Website pages not found");let i=Array.isArray(e.items.resource)?e.items.resource:[e.items.resource],s=await Re(i),o=null,a=[],l={label:"",variant:"default",properties:{isNameDisplayed:!1,isDescriptionDisplayed:!1,isDateDisplayed:!1,isCreatorsDisplayed:!1}},c="start",y="default",b=[],x=[],f=i.find(v=>(v.properties?T(Array.isArray(v.properties.property)?v.properties.property:[v.properties.property]):[]).some(k=>k.label==="presentation"&&k.values[0]?.content==="element"&&k.properties[0]?.label==="component"&&k.properties[0].values[0]?.content==="sidebar"));if(f){l.label=typeof f.identification.label=="string"||typeof f.identification.label=="number"||typeof f.identification.label=="boolean"?p(f.identification.label):S(f.identification.label);let v=f.properties?T(Array.isArray(f.properties.property)?f.properties.property:[f.properties.property]):[],O=v.find(m=>m.label==="presentation"&&m.values[0]?.content==="element")?.properties.find(m=>m.label==="component"&&m.values[0]?.content==="sidebar")?.properties??[],k=O.find(m=>m.label==="layout");k&&(c=k.values[0].content);let u=O.find(m=>m.label==="layout-mobile");u&&(y=u.values[0].content);let h=v.find(m=>m.label==="presentation"&&m.values[0].content==="css")?.properties??[];for(let m of h){let E=m.values[0].content;b.push({label:m.label,value:E})}let I=v.find(m=>m.label==="presentation"&&m.values[0].content==="css-mobile")?.properties??[];for(let m of I){let E=m.values[0].content;x.push({label:m.label,value:E})}let w=v.find(m=>m.label==="presentation"&&m.values[0].content==="title")?.properties;if(w){let m=d(w,"variant");m&&(l.variant=m);let E=w.filter($=>$.label==="display");E.length>0&&(l.properties.isNameDisplayed=E.some($=>$.values[0].content==="name"),l.properties.isDescriptionDisplayed=E.some($=>$.values[0].content==="description"),l.properties.isDateDisplayed=E.some($=>$.values[0].content==="date"),l.properties.isCreatorsDisplayed=E.some($=>$.values[0].content==="creators"))}let C=f.resource?Array.isArray(f.resource)?f.resource:[f.resource]:[];for(let m of C){let E=await ie(m);a.push(E)}}a.length>0&&(o={elements:a,title:l,layout:c,mobileLayout:y,cssStyles:b,cssStylesMobile:x});let g=null;if(e.searchOptions){let v=[];for(let O of s)for(let k of O.items)k.type==="element"&&k.component==="collection"&&v.push(k.collectionId);g={uuids:v,properties:{metadataUuids:[...e.searchOptions.metadata?.option??[]],searchUuids:[...e.searchOptions.filters?.option??[]],labelUuids:[...e.searchOptions.labels?.option??[]]}}}return{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:P(e.identification),project:{name:p(r),website:n!==null?p(n):null},creators:e.creators?W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:B(e.availability),pages:s,sidebar:o,properties:t,collectionOptions:g}}async function Ze(e,r,n,t){try{let{uuid:i,filter:s,page:o,perPage:a}=Oe.parse({uuid:e,filter:r,page:n,perPage:t}),l=await fetch(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
5
5
  for $q in input()/ochre[@uuid='${i}']
6
6
  let $filtered := $q//items/resource[contains(lower-case(identification/label), lower-case('${s}'))]
7
7
  let $maxLength := count($filtered)
@@ -10,4 +10,4 @@ ${JSON.stringify(e.content)}.`);return G(t)}}else return G(e.content);default:re
10
10
  {$q/metadata/item}
11
11
  {$filtered[position() >= ${((o-1)*a+1).toString()} and position() < ${(o*a+1).toString()}]}
12
12
  </gallery>
13
- `)}&format=json`);if(!l.ok)throw new Error("Error fetching gallery items, please try again later.");let c=await l.json();if(!("gallery"in c.result))throw new Error("Failed to fetch gallery");let y=P(c.result.gallery.item.identification),b=P(c.result.gallery.project.identification);return{item:{identification:y,projectIdentification:b,resources:N(c.result.gallery.resource?Array.isArray(c.result.gallery.resource)?c.result.gallery.resource:[c.result.gallery.resource]:[]),maxLength:c.result.gallery.maxLength},error:null}}catch(i){return console.error(i),{item:null,error:i instanceof Error?i.message:"Failed to fetch gallery"}}}async function et(e){try{let r=await fetch(`https://ochre.lib.uchicago.edu/ochre?xquery=for $q in input()/ochre[tree[@type='lesson'][identification/abbreviation='${e.toLocaleLowerCase("en-US")}']] return $q&format=json`);if(!r.ok)throw new Error("Failed to fetch website");let n=await r.json();if(!("ochre"in n.result)||!("tree"in n.result.ochre))throw new Error("Failed to fetch website");let t=n.result.ochre.metadata.project?.identification?P(n.result.ochre.metadata.project.identification):null;return await Pe(n.result.ochre.tree,t?.label??"",n.result.ochre.metadata.project?.identification.website??null)}catch(r){return console.error(r),null}}0&&(module.exports={fetchByUuid,fetchGallery,fetchItem,fetchWebsite,filterProperties,getAllPropertyLabels,getPropertyByLabel,getPropertyValueByLabel,getPropertyValuesByLabel,parseBibliographies,parseBibliography,parseConcept,parseConcepts,parseContext,parseCoordinates,parseDocument,parseEmail,parseEvents,parseFakeString,parseIdentification,parseImage,parseImageMap,parseInterpretations,parseLanguages,parseLicense,parseLink,parseLinks,parseMetadata,parseNotes,parseObservation,parseObservations,parsePeriod,parsePeriods,parsePerson,parsePersons,parseProperties,parseProperty,parsePropertyValue,parsePropertyValues,parseResource,parseResources,parseSet,parseSpatialUnit,parseSpatialUnits,parseStringContent,parseStringDocumentItem,parseStringItem,parseTree,parseWebsite});
13
+ `)}&format=json`);if(!l.ok)throw new Error("Error fetching gallery items, please try again later.");let c=await l.json();if(!("gallery"in c.result))throw new Error("Failed to fetch gallery");let y=P(c.result.gallery.item.identification),b=P(c.result.gallery.project.identification);return{item:{identification:y,projectIdentification:b,resources:N(c.result.gallery.resource?Array.isArray(c.result.gallery.resource)?c.result.gallery.resource:[c.result.gallery.resource]:[]),maxLength:c.result.gallery.maxLength},error:null}}catch(i){return console.error(i),{item:null,error:i instanceof Error?i.message:"Failed to fetch gallery"}}}async function et(e){try{let r=await fetch(`https://ochre.lib.uchicago.edu/ochre?xquery=for $q in input()/ochre[tree[@type='lesson'][identification/abbreviation='${e.toLocaleLowerCase("en-US")}']] return $q&format=json`);if(!r.ok)throw new Error("Failed to fetch website");let n=await r.json();if(!("ochre"in n.result)||!("tree"in n.result.ochre))throw new Error("Failed to fetch website");let t=n.result.ochre.metadata.project?.identification?P(n.result.ochre.metadata.project.identification):null;return await Pe(n.result.ochre.tree,t?.label??"",n.result.ochre.metadata.project?.identification.website??null)}catch(r){return console.error(r),null}}0&&(module.exports={fetchByUuid,fetchGallery,fetchItem,fetchWebsite,filterProperties,getPropertyByLabel,getPropertyValueByLabel,getPropertyValuesByLabel,getUniqueProperties,parseBibliographies,parseBibliography,parseConcept,parseConcepts,parseContext,parseCoordinates,parseDocument,parseEmail,parseEvents,parseFakeString,parseIdentification,parseImage,parseImageMap,parseInterpretations,parseLanguages,parseLicense,parseLink,parseLinks,parseMetadata,parseNotes,parseObservation,parseObservations,parsePeriod,parsePeriods,parsePerson,parsePersons,parseProperties,parseProperty,parsePropertyValue,parsePropertyValues,parseResource,parseResources,parseSet,parseSpatialUnit,parseSpatialUnits,parseStringContent,parseStringDocumentItem,parseStringItem,parseTree,parseWebsite});
package/dist/index.d.cts CHANGED
@@ -1387,19 +1387,19 @@ declare function fetchWebsite(abbreviation: string): Promise<Website | null>;
1387
1387
  */
1388
1388
  type PropertyOptions = {
1389
1389
  /** Whether to recursively search through nested properties */
1390
- searchNestedProperties: boolean;
1390
+ includeNestedProperties: boolean;
1391
1391
  };
1392
1392
  /**
1393
1393
  * Finds a property by its label in an array of properties
1394
1394
  *
1395
1395
  * @param properties - Array of properties to search through
1396
1396
  * @param label - The label to search for
1397
- * @param options - Search options, including whether to search nested properties
1397
+ * @param options - Search options, including whether to include nested properties
1398
1398
  * @returns The matching Property object, or null if not found
1399
1399
  *
1400
1400
  * @example
1401
1401
  * ```ts
1402
- * const property = getPropertyByLabel(properties, "author", { searchNestedProperties: true });
1402
+ * const property = getPropertyByLabel(properties, "author", { includeNestedProperties: true });
1403
1403
  * if (property) {
1404
1404
  * console.log(property.values);
1405
1405
  * }
@@ -1411,7 +1411,7 @@ declare function getPropertyByLabel(properties: Array<Property>, label: string,
1411
1411
  *
1412
1412
  * @param properties - Array of properties to search through
1413
1413
  * @param label - The label to search for
1414
- * @param options - Search options, including whether to search nested properties
1414
+ * @param options - Search options, including whether to include nested properties
1415
1415
  * @returns Array of property values as strings, or null if property not found
1416
1416
  *
1417
1417
  * @example
@@ -1430,7 +1430,7 @@ declare function getPropertyValuesByLabel(properties: Array<Property>, label: st
1430
1430
  *
1431
1431
  * @param properties - Array of properties to search through
1432
1432
  * @param label - The label to search for
1433
- * @param options - Search options, including whether to search nested properties
1433
+ * @param options - Search options, including whether to include nested properties
1434
1434
  * @returns The first property value as string, or null if property not found
1435
1435
  *
1436
1436
  * @example
@@ -1443,19 +1443,19 @@ declare function getPropertyValuesByLabel(properties: Array<Property>, label: st
1443
1443
  */
1444
1444
  declare function getPropertyValueByLabel(properties: Array<Property>, label: string, options?: PropertyOptions): string | number | boolean | Date | null;
1445
1445
  /**
1446
- * Gets all unique property labels from an array of properties
1446
+ * Gets all unique properties from an array of properties
1447
1447
  *
1448
- * @param properties - Array of properties to get labels from
1449
- * @param options - Search options, including whether to include nested property labels
1450
- * @returns Array of unique property labels
1448
+ * @param properties - Array of properties to get unique properties from
1449
+ * @param options - Search options, including whether to include nested properties
1450
+ * @returns Array of unique properties
1451
1451
  *
1452
1452
  * @example
1453
1453
  * ```ts
1454
- * const labels = getAllPropertyLabels(properties, { searchNestedProperties: true });
1455
- * console.log(`Available properties: ${labels.join(", ")}`);
1454
+ * const properties = getAllUniqueProperties(properties, { includeNestedProperties: true });
1455
+ * console.log(`Available properties: ${properties.map((p) => p.label).join(", ")}`);
1456
1456
  * ```
1457
1457
  */
1458
- declare function getAllPropertyLabels(properties: Array<Property>, options?: PropertyOptions): Array<string>;
1458
+ declare function getUniqueProperties(properties: Array<Property>, options?: PropertyOptions): Array<Property>;
1459
1459
  /**
1460
1460
  * Filters a property based on a label and value criteria
1461
1461
  *
@@ -1463,7 +1463,7 @@ declare function getAllPropertyLabels(properties: Array<Property>, options?: Pro
1463
1463
  * @param filter - Filter criteria containing label and value to match
1464
1464
  * @param filter.label - The label to filter by
1465
1465
  * @param filter.value - The value to filter by
1466
- * @param options - Search options, including whether to search nested properties
1466
+ * @param options - Search options, including whether to include nested properties
1467
1467
  * @returns True if the property matches the filter criteria, false otherwise
1468
1468
  *
1469
1469
  * @example
@@ -1770,4 +1770,4 @@ declare function parseStringDocumentItem(item: OchreStringRichTextItem, footnote
1770
1770
  */
1771
1771
  declare function parseStringContent(content: OchreStringContent, language?: string): string;
1772
1772
 
1773
- export { type Bibliography, type Concept, type Context, type ContextItem, type ContextNode, type Coordinates, type Data, type DataCategory, type Document, type Event, type Footnote, type Gallery, type Identification, type Image, type ImageMap, type ImageMapArea, type Interpretation, type License, type Link, type Metadata, type Note, type Observation, type Period, type Person, type Property, type PropertyValue, type PropertyValueContent, type PropertyValueContentType, type Resource, type Set, type SpatialUnit, type Style, type Tree, type WebBlock, type WebElement, type WebElementComponent, type WebImage, type WebSectionSidebarItem, type Webpage, type WebpageProperties, type Website, type WebsiteProperties, fetchByUuid, fetchGallery, fetchItem, fetchWebsite, filterProperties, getAllPropertyLabels, getPropertyByLabel, getPropertyValueByLabel, getPropertyValuesByLabel, parseBibliographies, parseBibliography, parseConcept, parseConcepts, parseContext, parseCoordinates, parseDocument, parseEmail, parseEvents, parseFakeString, parseIdentification, parseImage, parseImageMap, parseInterpretations, parseLanguages, parseLicense, parseLink, parseLinks, parseMetadata, parseNotes, parseObservation, parseObservations, parsePeriod, parsePeriods, parsePerson, parsePersons, parseProperties, parseProperty, parsePropertyValue, parsePropertyValues, parseResource, parseResources, parseSet, parseSpatialUnit, parseSpatialUnits, parseStringContent, parseStringDocumentItem, parseStringItem, parseTree, parseWebsite };
1773
+ export { type Bibliography, type Concept, type Context, type ContextItem, type ContextNode, type Coordinates, type Data, type DataCategory, type Document, type Event, type Footnote, type Gallery, type Identification, type Image, type ImageMap, type ImageMapArea, type Interpretation, type License, type Link, type Metadata, type Note, type Observation, type Period, type Person, type Property, type PropertyValue, type PropertyValueContent, type PropertyValueContentType, type Resource, type Set, type SpatialUnit, type Style, type Tree, type WebBlock, type WebElement, type WebElementComponent, type WebImage, type WebSectionSidebarItem, type Webpage, type WebpageProperties, type Website, type WebsiteProperties, fetchByUuid, fetchGallery, fetchItem, fetchWebsite, filterProperties, getPropertyByLabel, getPropertyValueByLabel, getPropertyValuesByLabel, getUniqueProperties, parseBibliographies, parseBibliography, parseConcept, parseConcepts, parseContext, parseCoordinates, parseDocument, parseEmail, parseEvents, parseFakeString, parseIdentification, parseImage, parseImageMap, parseInterpretations, parseLanguages, parseLicense, parseLink, parseLinks, parseMetadata, parseNotes, parseObservation, parseObservations, parsePeriod, parsePeriods, parsePerson, parsePersons, parseProperties, parseProperty, parsePropertyValue, parsePropertyValues, parseResource, parseResources, parseSet, parseSpatialUnit, parseSpatialUnits, parseStringContent, parseStringDocumentItem, parseStringItem, parseTree, parseWebsite };
package/dist/index.d.ts CHANGED
@@ -1387,19 +1387,19 @@ declare function fetchWebsite(abbreviation: string): Promise<Website | null>;
1387
1387
  */
1388
1388
  type PropertyOptions = {
1389
1389
  /** Whether to recursively search through nested properties */
1390
- searchNestedProperties: boolean;
1390
+ includeNestedProperties: boolean;
1391
1391
  };
1392
1392
  /**
1393
1393
  * Finds a property by its label in an array of properties
1394
1394
  *
1395
1395
  * @param properties - Array of properties to search through
1396
1396
  * @param label - The label to search for
1397
- * @param options - Search options, including whether to search nested properties
1397
+ * @param options - Search options, including whether to include nested properties
1398
1398
  * @returns The matching Property object, or null if not found
1399
1399
  *
1400
1400
  * @example
1401
1401
  * ```ts
1402
- * const property = getPropertyByLabel(properties, "author", { searchNestedProperties: true });
1402
+ * const property = getPropertyByLabel(properties, "author", { includeNestedProperties: true });
1403
1403
  * if (property) {
1404
1404
  * console.log(property.values);
1405
1405
  * }
@@ -1411,7 +1411,7 @@ declare function getPropertyByLabel(properties: Array<Property>, label: string,
1411
1411
  *
1412
1412
  * @param properties - Array of properties to search through
1413
1413
  * @param label - The label to search for
1414
- * @param options - Search options, including whether to search nested properties
1414
+ * @param options - Search options, including whether to include nested properties
1415
1415
  * @returns Array of property values as strings, or null if property not found
1416
1416
  *
1417
1417
  * @example
@@ -1430,7 +1430,7 @@ declare function getPropertyValuesByLabel(properties: Array<Property>, label: st
1430
1430
  *
1431
1431
  * @param properties - Array of properties to search through
1432
1432
  * @param label - The label to search for
1433
- * @param options - Search options, including whether to search nested properties
1433
+ * @param options - Search options, including whether to include nested properties
1434
1434
  * @returns The first property value as string, or null if property not found
1435
1435
  *
1436
1436
  * @example
@@ -1443,19 +1443,19 @@ declare function getPropertyValuesByLabel(properties: Array<Property>, label: st
1443
1443
  */
1444
1444
  declare function getPropertyValueByLabel(properties: Array<Property>, label: string, options?: PropertyOptions): string | number | boolean | Date | null;
1445
1445
  /**
1446
- * Gets all unique property labels from an array of properties
1446
+ * Gets all unique properties from an array of properties
1447
1447
  *
1448
- * @param properties - Array of properties to get labels from
1449
- * @param options - Search options, including whether to include nested property labels
1450
- * @returns Array of unique property labels
1448
+ * @param properties - Array of properties to get unique properties from
1449
+ * @param options - Search options, including whether to include nested properties
1450
+ * @returns Array of unique properties
1451
1451
  *
1452
1452
  * @example
1453
1453
  * ```ts
1454
- * const labels = getAllPropertyLabels(properties, { searchNestedProperties: true });
1455
- * console.log(`Available properties: ${labels.join(", ")}`);
1454
+ * const properties = getAllUniqueProperties(properties, { includeNestedProperties: true });
1455
+ * console.log(`Available properties: ${properties.map((p) => p.label).join(", ")}`);
1456
1456
  * ```
1457
1457
  */
1458
- declare function getAllPropertyLabels(properties: Array<Property>, options?: PropertyOptions): Array<string>;
1458
+ declare function getUniqueProperties(properties: Array<Property>, options?: PropertyOptions): Array<Property>;
1459
1459
  /**
1460
1460
  * Filters a property based on a label and value criteria
1461
1461
  *
@@ -1463,7 +1463,7 @@ declare function getAllPropertyLabels(properties: Array<Property>, options?: Pro
1463
1463
  * @param filter - Filter criteria containing label and value to match
1464
1464
  * @param filter.label - The label to filter by
1465
1465
  * @param filter.value - The value to filter by
1466
- * @param options - Search options, including whether to search nested properties
1466
+ * @param options - Search options, including whether to include nested properties
1467
1467
  * @returns True if the property matches the filter criteria, false otherwise
1468
1468
  *
1469
1469
  * @example
@@ -1770,4 +1770,4 @@ declare function parseStringDocumentItem(item: OchreStringRichTextItem, footnote
1770
1770
  */
1771
1771
  declare function parseStringContent(content: OchreStringContent, language?: string): string;
1772
1772
 
1773
- export { type Bibliography, type Concept, type Context, type ContextItem, type ContextNode, type Coordinates, type Data, type DataCategory, type Document, type Event, type Footnote, type Gallery, type Identification, type Image, type ImageMap, type ImageMapArea, type Interpretation, type License, type Link, type Metadata, type Note, type Observation, type Period, type Person, type Property, type PropertyValue, type PropertyValueContent, type PropertyValueContentType, type Resource, type Set, type SpatialUnit, type Style, type Tree, type WebBlock, type WebElement, type WebElementComponent, type WebImage, type WebSectionSidebarItem, type Webpage, type WebpageProperties, type Website, type WebsiteProperties, fetchByUuid, fetchGallery, fetchItem, fetchWebsite, filterProperties, getAllPropertyLabels, getPropertyByLabel, getPropertyValueByLabel, getPropertyValuesByLabel, parseBibliographies, parseBibliography, parseConcept, parseConcepts, parseContext, parseCoordinates, parseDocument, parseEmail, parseEvents, parseFakeString, parseIdentification, parseImage, parseImageMap, parseInterpretations, parseLanguages, parseLicense, parseLink, parseLinks, parseMetadata, parseNotes, parseObservation, parseObservations, parsePeriod, parsePeriods, parsePerson, parsePersons, parseProperties, parseProperty, parsePropertyValue, parsePropertyValues, parseResource, parseResources, parseSet, parseSpatialUnit, parseSpatialUnits, parseStringContent, parseStringDocumentItem, parseStringItem, parseTree, parseWebsite };
1773
+ export { type Bibliography, type Concept, type Context, type ContextItem, type ContextNode, type Coordinates, type Data, type DataCategory, type Document, type Event, type Footnote, type Gallery, type Identification, type Image, type ImageMap, type ImageMapArea, type Interpretation, type License, type Link, type Metadata, type Note, type Observation, type Period, type Person, type Property, type PropertyValue, type PropertyValueContent, type PropertyValueContentType, type Resource, type Set, type SpatialUnit, type Style, type Tree, type WebBlock, type WebElement, type WebElementComponent, type WebImage, type WebSectionSidebarItem, type Webpage, type WebpageProperties, type Website, type WebsiteProperties, fetchByUuid, fetchGallery, fetchItem, fetchWebsite, filterProperties, getPropertyByLabel, getPropertyValueByLabel, getPropertyValuesByLabel, getUniqueProperties, parseBibliographies, parseBibliography, parseConcept, parseConcepts, parseContext, parseCoordinates, parseDocument, parseEmail, parseEvents, parseFakeString, parseIdentification, parseImage, parseImageMap, parseInterpretations, parseLanguages, parseLicense, parseLink, parseLinks, parseMetadata, parseNotes, parseObservation, parseObservations, parsePeriod, parsePeriods, parsePerson, parsePersons, parseProperties, parseProperty, parsePropertyValue, parsePropertyValues, parseResource, parseResources, parseSet, parseSpatialUnit, parseSpatialUnits, parseStringContent, parseStringDocumentItem, parseStringItem, parseTree, parseWebsite };
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import{z as O}from"zod";var pe=O.string().uuid({message:"Invalid UUID provided"}),ue=O.object({type:O.enum(["traditional","digital-collection","plum","cedar","elm","maple","oak","palm"],{message:"Invalid website type"}),status:O.enum(["development","preview","production"],{message:"Invalid website status"}),privacy:O.enum(["public","password","private"],{message:"Invalid website privacy"})}),de=O.enum(["annotated-document","annotated-image","bibliography","button","collection","empty-space","entries","filter-categories","iframe","iiif-viewer","image","image-gallery","n-columns","n-rows","network-graph","search-bar","table","text","timeline","video"],{message:"Invalid component"}),K=O.enum(["resource","spatialUnit","concept","period","bibliography","person","propertyValue","set","tree"]),fe=O.enum(["string","integer","decimal","boolean","date","dateTime","time","coordinate","IDREF"]),ye=O.object({uuid:O.string().uuid({message:"Invalid UUID"}),filter:O.string().optional(),page:O.number().positive({message:"Page must be positive"}),perPage:O.number().positive({message:"Per page must be positive"})}).strict(),he=O.string().transform(e=>e.split(" ")).pipe(O.array(O.enum(["bold","italic","underline"]))),me=O.string().transform(e=>e.split(" ")).pipe(O.array(O.enum(["newline","trailing","leading"]))),be=O.string().email({message:"Invalid email"});var N={searchNestedProperties:!1};function J(e,r,n=N){let{searchNestedProperties:t}=n,i=e.find(s=>s.label===r);if(i)return i;if(t){for(let s of e)if(s.properties.length>0){let o=J(s.properties,r,{searchNestedProperties:t});if(o)return o}}return null}function ge(e,r,n=N){let{searchNestedProperties:t}=n,i=e.find(s=>s.label===r);if(i)return i.values.map(s=>s.content);if(t){for(let s of e)if(s.properties.length>0){let o=ge(s.properties,r,{searchNestedProperties:t});if(o)return o}}return null}function d(e,r,n=N){let{searchNestedProperties:t}=n,i=ge(e,r,{searchNestedProperties:t});if(i!==null&&i.length>0)return i[0];if(t){for(let s of e)if(s.properties.length>0){let o=d(s.properties,r,{searchNestedProperties:t});if(o!==null)return o}}return null}function We(e,r=N){let{searchNestedProperties:n}=r,t=new Set;for(let i of e)if(t.add(i.label),i.properties.length>0&&n){let s=We(i.properties,{searchNestedProperties:!0});for(let o of s)t.add(o)}return[...t]}function Fe(e,r,n=N){let{searchNestedProperties:t}=n;if(r.label.toLocaleLowerCase("en-US")==="all fields"||e.label.toLocaleLowerCase("en-US")===r.label.toLocaleLowerCase("en-US")){let s=e.values.some(o=>o.content===null?!1:typeof o.content=="string"?typeof r.value!="string"?!1:o.content.toLocaleLowerCase("en-US").includes(r.value.toLocaleLowerCase("en-US")):typeof o.content=="number"?typeof r.value!="number"?!1:o.content===r.value:typeof o.content=="boolean"?typeof r.value!="boolean"?!1:o.booleanValue===r.value:o.content instanceof Date&&r.value instanceof Date?o.content.getTime()===r.value.getTime():!1);return!s&&t&&(s=e.properties.some(o=>Fe(o,r,{searchNestedProperties:!0}))),s}return!1}function Be(e,r){return e.find(t=>t.lang===r)??null}function F(e){let r=e.split(" "),n=[];for(let t of r){let i=t.replaceAll(/(?<=\s|^)[([{]+|[)\]}]+(?=\s|$)/g,"").replace(/[!),.:;?\]]$/,""),s=t.indexOf(i),o=t.slice(0,s),a=t.slice(s+i.length);if(be.safeParse(i).success){n.push(o,`${o}<ExternalLink href="mailto:${i}">${i}</ExternalLink>${a}`);continue}n.push(t)}return n.join(" ")}function Ae(e,r){let n=e,t=he.safeParse(r);if(!t.success)return console.warn(`Invalid render options string provided: \u201C${r}\u201D`),e;for(let i of t.data)switch(i){case"bold":{n=`**${n}**`;break}case"italic":{n=`*${n}*`;break}case"underline":{n=`_${n}_`;break}}return n.replaceAll("&#39;","'")}function z(e,r){let n=e,t=me.safeParse(r);if(!t.success)return console.warn(`Invalid whitespace string provided: \u201C${r}\u201D`),e;for(let i of t.data)switch(i){case"newline":{n=`<br />
1
+ import{z as O}from"zod";var pe=O.string().uuid({message:"Invalid UUID provided"}),ue=O.object({type:O.enum(["traditional","digital-collection","plum","cedar","elm","maple","oak","palm"],{message:"Invalid website type"}),status:O.enum(["development","preview","production"],{message:"Invalid website status"}),privacy:O.enum(["public","password","private"],{message:"Invalid website privacy"})}),de=O.enum(["annotated-document","annotated-image","bibliography","button","collection","empty-space","entries","filter-categories","iframe","iiif-viewer","image","image-gallery","n-columns","n-rows","network-graph","search-bar","table","text","timeline","video"],{message:"Invalid component"}),K=O.enum(["resource","spatialUnit","concept","period","bibliography","person","propertyValue","set","tree"]),fe=O.enum(["string","integer","decimal","boolean","date","dateTime","time","coordinate","IDREF"]),ye=O.object({uuid:O.string().uuid({message:"Invalid UUID"}),filter:O.string().optional(),page:O.number().positive({message:"Page must be positive"}),perPage:O.number().positive({message:"Per page must be positive"})}).strict(),he=O.string().transform(e=>e.split(" ")).pipe(O.array(O.enum(["bold","italic","underline"]))),me=O.string().transform(e=>e.split(" ")).pipe(O.array(O.enum(["newline","trailing","leading"]))),be=O.string().email({message:"Invalid email"});var N={includeNestedProperties:!1};function J(e,r,n=N){let{includeNestedProperties:t}=n,i=e.find(s=>s.label===r);if(i)return i;if(t){for(let s of e)if(s.properties.length>0){let o=J(s.properties,r,{includeNestedProperties:t});if(o)return o}}return null}function ge(e,r,n=N){let{includeNestedProperties:t}=n,i=e.find(s=>s.label===r);if(i)return i.values.map(s=>s.content);if(t){for(let s of e)if(s.properties.length>0){let o=ge(s.properties,r,{includeNestedProperties:t});if(o)return o}}return null}function d(e,r,n=N){let{includeNestedProperties:t}=n,i=ge(e,r,{includeNestedProperties:t});if(i!==null&&i.length>0)return i[0];if(t){for(let s of e)if(s.properties.length>0){let o=d(s.properties,r,{includeNestedProperties:t});if(o!==null)return o}}return null}function We(e,r=N){let{includeNestedProperties:n}=r,t=new Array;for(let i of e)if(!t.some(s=>s.uuid===i.uuid)&&(t.push(i),i.properties.length>0&&n)){let s=We(i.properties,{includeNestedProperties:!0});for(let o of s)t.some(a=>a.uuid===o.uuid)||t.push(o)}return t}function Fe(e,r,n=N){let{includeNestedProperties:t}=n;if(r.label.toLocaleLowerCase("en-US")==="all fields"||e.label.toLocaleLowerCase("en-US")===r.label.toLocaleLowerCase("en-US")){let s=e.values.some(o=>o.content===null?!1:typeof o.content=="string"?typeof r.value!="string"?!1:o.content.toLocaleLowerCase("en-US").includes(r.value.toLocaleLowerCase("en-US")):typeof o.content=="number"?typeof r.value!="number"?!1:o.content===r.value:typeof o.content=="boolean"?typeof r.value!="boolean"?!1:o.booleanValue===r.value:o.content instanceof Date&&r.value instanceof Date?o.content.getTime()===r.value.getTime():!1);return!s&&t&&(s=e.properties.some(o=>Fe(o,r,{includeNestedProperties:!0}))),s}return!1}function Be(e,r){return e.find(t=>t.lang===r)??null}function F(e){let r=e.split(" "),n=[];for(let t of r){let i=t.replaceAll(/(?<=\s|^)[([{]+|[)\]}]+(?=\s|$)/g,"").replace(/[!),.:;?\]]$/,""),s=t.indexOf(i),o=t.slice(0,s),a=t.slice(s+i.length);if(be.safeParse(i).success){n.push(o,`${o}<ExternalLink href="mailto:${i}">${i}</ExternalLink>${a}`);continue}n.push(t)}return n.join(" ")}function Ae(e,r){let n=e,t=he.safeParse(r);if(!t.success)return console.warn(`Invalid render options string provided: \u201C${r}\u201D`),e;for(let i of t.data)switch(i){case"bold":{n=`**${n}**`;break}case"italic":{n=`*${n}*`;break}case"underline":{n=`_${n}_`;break}}return n.replaceAll("&#39;","'")}function z(e,r){let n=e,t=me.safeParse(r);if(!t.success)return console.warn(`Invalid whitespace string provided: \u201C${r}\u201D`),e;for(let i of t.data)switch(i){case"newline":{n=`<br />
2
2
  ${n}`;break}case"trailing":{n=`${n} `;break}case"leading":{n=` ${n}`;break}}return n.replaceAll("&#39;","'")}function p(e){let r="";return typeof e=="string"?r=e:typeof e=="number"?r=e.toString():typeof e=="boolean"&&(r=e?"Yes":"No"),r.replaceAll("&#39;","'").replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}function _(e){let r="";switch(typeof e.string){case"string":{r=e.string;break}case"number":case"boolean":{r=p(e.string);break}case"object":{let n=Array.isArray(e.string)?e.string:[e.string];for(let t of n)if(typeof t=="string"||typeof t=="number"||typeof t=="boolean")r+=p(t);else{let i=t.rend!=null?Ae(p(t.content),t.rend):p(t.content),s=t.whitespace!=null?z(i,t.whitespace):i;r+=s}break}default:{r="";break}}return r.replaceAll("&#39;","'").replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}function Q(e,r){if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return F(p(e));if("whitespace"in e&&!("content"in e)&&!("string"in e))return e.whitespace==="newline"?`
3
3
  `:"";if("links"in e){let t="";typeof e.string=="object"?t=S(e.string):t=p(e.string).replaceAll("<",String.raw`\<`).replaceAll("{",String.raw`\{`);let i=Array.isArray(e.links)?e.links:[e.links];for(let s of i)if("resource"in s){let o=Array.isArray(s.resource)?s.resource[0]:s.resource,a=null;switch(o.content!=null&&(a=p(o.content).replaceAll("<",String.raw`\<`).replaceAll("{",String.raw`\{`)),o.type){case"image":return o.rend==="inline"?`<InlineImage uuid="${o.uuid}" ${a!==null?`content="${a}"`:""} height={${o.height?.toString()??"null"}} width={${o.width?.toString()??"null"}} />`:o.publicationDateTime!=null?`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${o.uuid}" type="image"${a!==null?` content="${a}"`:""}>${t}</ExternalLink>`:`<TooltipSpan type="image" ${a!==null?`content="${a}"`:""}>${t}</TooltipSpan>`;case"internalDocument":return a?.toLocaleLowerCase("en-US").includes("footnote")?(r&&r.push({uuid:o.uuid,label:t,content:""}),` <Footnote uuid="${o.uuid}"${t?` label="${t}"`:""}${a!==null?` content="${a}"`:""} />`):`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${o.uuid}" type="internalDocument" ${a!==null?`content="${a}"`:""}>${t}</ExternalLink>`;case"externalDocument":return o.publicationDateTime!=null?`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${o.uuid}" type="externalDocument" ${a!==null?`content="${a}"`:""}>${t}</ExternalLink>`:`<TooltipSpan type="externalDocument" ${a!==null?`content="${a}"`:""}>${t}</TooltipSpan>`;case"webpage":return`<ExternalLink href="${o.href}" type="webpage" ${a!==null?`content="${a}"`:""}>${t}</ExternalLink>`;default:return""}}else if("concept"in s){let o=Array.isArray(s.concept)?s.concept[0]:s.concept;return o.publicationDateTime!=null?`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${o.uuid}" type="concept">${t}</ExternalLink>`:`<TooltipSpan type="concept">${t}</TooltipSpan>`}else if("set"in s){let o=Array.isArray(s.set)?s.set[0]:s.set;return o.publicationDateTime!=null?`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${o.uuid}" type="set">${t}</ExternalLink>`:`<TooltipSpan type="set">${t}</TooltipSpan>`}else if("person"in s){let o=Array.isArray(s.person)?s.person[0]:s.person,a=o.identification?["string","number","boolean"].includes(typeof o.identification.label)?p(o.identification.label):S(o.identification.label):null;return o.publicationDateTime!=null?`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${o.uuid}" type="${o.type??"person"}" ${a!==null?`content="${a}"`:""}>${t}</ExternalLink>`:`<TooltipSpan type="${o.type??"person"}" ${a!==null?`content="${a}"`:""}>${t}</TooltipSpan>`}else if("bibliography"in s){let o=Array.isArray(s.bibliography)?s.bibliography[0]:s.bibliography;return o.publicationDateTime!=null?`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${o.uuid}" type="${o.type??"bibliography"}">${t}</ExternalLink>`:`<TooltipSpan type="bibliography">${t}</TooltipSpan>`}}let n="";if("string"in e){let t=Array.isArray(e.string)?e.string:[e.string];for(let i of t)n+=Q(i,r);return"whitespace"in e&&e.whitespace!=null&&(n=z(F(n),e.whitespace)),n.replaceAll("&#39;","'").replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}else n=p(e.content),e.rend!=null&&(n=Ae(F(n),e.rend)),e.whitespace!=null&&(n=z(F(n),e.whitespace));return n.replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}function S(e,r="eng"){switch(typeof e.content){case"string":case"number":case"boolean":return p(e.content);case"object":if(Array.isArray(e.content)){let n=Be(e.content,r);if(n)return _(n);{let t=e.content[0];if(!t)throw new Error(`No string item found for language \u201C${r}\u201D in the following content:
4
- ${JSON.stringify(e.content)}.`);return _(t)}}else return _(e.content);default:return String(e.content).replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}}function M(e){let r=e.find(t=>K.safeParse(t).success);if(!r){let t=e.find(i=>!["uuid","uuidBelongsTo","belongsTo","publicationDateTime","metadata","languages"].includes(i));throw new Error(`Invalid OCHRE data; found unexpected "${t}" key`)}return K.parse(r)}async function ve(e){try{let r=pe.parse(e),n=await fetch(`https://ochre.lib.uchicago.edu/ochre?uuid=${r}&format=json&lang="*"`);if(!n.ok)throw new Error("Failed to fetch OCHRE data");let t=await n.json();if(!("ochre"in t))throw new Error("Invalid OCHRE data: API response missing 'ochre' key");return[null,t]}catch(r){return[r instanceof Error?r.message:"Unknown error",null]}}async function we(e,r,n){try{let[t,i]=await ve(e);if(t!==null)throw new Error(t);let s=M(Object.keys(i.ochre)),o;switch(s){case"resource":{if(!("resource"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'resource' key");o=te(i.ochre.resource);break}case"spatialUnit":{if(!("spatialUnit"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'spatialUnit' key");o=re(i.ochre.spatialUnit);break}case"concept":{if(!("concept"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'concept' key");o=ne(i.ochre.concept);break}case"period":{if(!("period"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'period' key");o=X(i.ochre.period);break}case"bibliography":{if(!("bibliography"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'bibliography' key");o=Z(i.ochre.bibliography);break}case"person":{if(!("person"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'person' key");o=R(i.ochre.person);break}case"propertyValue":{if(!("propertyValue"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'propertyValue' key");o=ee(i.ochre.propertyValue);break}case"set":{if(!("set"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'set' key");o=ke(i.ochre.set,n);break}case"tree":{if(!("tree"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'tree' key");o=Pe(i.ochre.tree);break}default:throw new Error("Invalid category")}let a=Se(i.ochre.metadata),l={uuid:i.ochre.uuidBelongsTo,abbreviation:p(i.ochre.belongsTo)};return{error:null,metadata:a,belongsTo:l,item:o,category:r}}catch(t){return{error:t instanceof Error?t.message:"Unknown error",metadata:void 0,belongsTo:void 0,item:void 0,category:void 0}}}function I(e){try{let r={label:["string","number","boolean"].includes(typeof e.label)?p(e.label):S(e.label),abbreviation:""};for(let n of Object.keys(e).filter(t=>t!=="label"))r[n]=S(e[n]);return r}catch(r){return console.error(r),{label:"",abbreviation:""}}}function je(e){return e==null?["eng"]:Array.isArray(e)?e.map(r=>S(r)):[S(e)]}function Se(e){let r={label:"",abbreviation:""};if(e.item)if(e.item.label||e.item.abbreviation){let i="",s="";e.item.label&&(i=S(e.item.label)),e.item.abbreviation&&(s=S(e.item.abbreviation)),r={label:i,abbreviation:s}}else r=I(e.item.identification);let n=null,t=e.project?.identification?I(e.project.identification):null;return t&&(n={...t,website:e.project?.identification.website??null}),{project:n?{identification:n}:null,item:e.item?{identification:r,category:e.item.category,type:e.item.type,maxLength:e.item.maxLength??null}:null,dataset:S(e.dataset),publisher:S(e.publisher),languages:je(e.language),identifier:S(e.identifier),description:S(e.description)}}function ie(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,number:e.n,content:p(e.content)}}function V(e){return{nodes:(Array.isArray(e.context)?e.context:[e.context]).map(t=>{let i=[];if("spatialUnit"in t&&t.spatialUnit){let s=Array.isArray(t.spatialUnit)?t.spatialUnit:[t.spatialUnit];for(let o of s)i.push(ie(o))}return{tree:ie(t.tree),project:ie(t.project),spatialUnit:i}}),displayPath:e.displayPath}}function B(e){return typeof e.license=="string"?null:{content:e.license.content,url:e.license.target}}function R(e){return{uuid:e.uuid,category:"person",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type??null,number:e.n??null,context:e.context?V(e.context):null,date:e.date!=null?new Date(e.date):null,identification:e.identification?I(e.identification):null,availability:e.availability?B(e.availability):null,address:e.address?{country:e.address.country??null,city:e.address.city??null,state:e.address.state??null}:null,coordinates:e.coordinates?oe(e.coordinates):null,content:e.content!=null?p(e.content):null,events:e.events?De(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function W(e){let r=[];for(let n of e)r.push(R(n));return r}function Ue(e){let r="resource"in e?e.resource:"spatialUnit"in e?e.spatialUnit:"concept"in e?e.concept:"set"in e?e.set:"tree"in e?e.tree:"person"in e?e.person:"bibliography"in e?e.bibliography:"epigraphicUnit"in e?e.epigraphicUnit:"propertyValue"in e?e.propertyValue:null;if(!r)throw new Error(`Invalid link provided: ${JSON.stringify(e,null,2)}`);let n=Array.isArray(r)?r:[r],t=[];for(let i of n){let s={category:"resource"in e?"resource":"spatialUnit"in e?"spatialUnit":"concept"in e?"concept":"set"in e?"set":"person"in e?"person":"tree"in e?"tree":"bibliography"in e?"bibliography":"epigraphicUnit"in e?"epigraphicUnit":"propertyValue"in e?"propertyValue":null,content:"content"in i&&i.content!=null?p(i.content):null,href:"href"in i&&i.href!=null?i.href:null,uuid:i.uuid,type:i.type??null,identification:i.identification?I(i.identification):null,image:null,bibliographies:"bibliography"in e?q(Array.isArray(e.bibliography)?e.bibliography:[e.bibliography]):null,publicationDateTime:i.publicationDateTime!=null?new Date(i.publicationDateTime):null};"height"in i&&i.height!=null&&i.width!=null&&i.heightPreview!=null&&i.widthPreview!=null&&(s.image={isInline:i.rend==="inline",isPrimary:i.isPrimary??!1,heightPreview:i.heightPreview,widthPreview:i.widthPreview,height:i.height,width:i.width}),t.push(s)}return t}function U(e){let r=[];for(let n of e)r.push(...Ue(n));return r}function se(e,r="eng"){let n="",t=[],i=Array.isArray(e)?e.find(s=>s.lang===r):e;if(typeof i.string=="string"||typeof i.string=="number"||typeof i.string=="boolean")n+=F(p(i.string));else{let s=Array.isArray(i.string)?i.string:[i.string];for(let o of s)n+=Q(o,t)}return{content:n,footnotes:t}}function Ie(e){return{publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,identification:e.identification?I(e.identification):null,url:e.href??(e.htmlImgSrcPrefix==null&&e.content!=null?p(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?p(e.content):null,widthPreview:e.widthPreview??null,heightPreview:e.heightPreview??null,width:e.width??null,height:e.height??null}}function le(e,r="eng"){let n=[];for(let t of e){if(typeof t=="string"){if(t==="")continue;n.push({number:-1,title:null,content:t});continue}let i="",s=Array.isArray(t.content)?t.content:[t.content],o=s.find(a=>a.lang===r);if(!o&&(o=s[0],!o))throw new Error(`Note does not have a valid content item: ${JSON.stringify(t,null,2)}`);typeof o.string=="string"||typeof o.string=="number"||typeof o.string=="boolean"?i=F(p(o.string)):i=F(se(o).content),n.push({number:t.noteNo,title:o.title!=null?p(o.title):null,content:i})}return n}function oe(e){if(typeof e=="string"){let[r,n]=e.split(", ");return{latitude:Number(r),longitude:Number(n),type:null,label:null}}return{latitude:e.latitude,longitude:e.longitude,type:e.coord?.coordType??null,label:e.coord?.coordLabel!=null?p(e.coord.coordLabel):null}}function xe(e){return{number:e.observationNo,date:e.date!=null?new Date(e.date):null,observers:e.observers!=null?p(e.observers).split(";").map(r=>r.trim()):[],notes:e.notes?le(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?U(Array.isArray(e.links)?e.links:[e.links]):[],properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function Ve(e){let r=[];for(let n of e)r.push(xe(n));return r}function De(e){let r=[];for(let n of e)r.push({date:n.dateTime!=null?new Date(n.dateTime):null,label:S(n.label),agent:n.agent?{uuid:n.agent.uuid,content:p(n.agent.content)}:null});return r}function Ne(e,r="eng"){let t=("value"in e&&e.value?Array.isArray(e.value)?e.value:[e.value]:[]).map(i=>{let s=null,o=null;if(typeof i=="string"||typeof i=="number"||typeof i=="boolean")return s=p(i),{content:s,booleanValue:o,isUncertain:!1,type:"string",category:"value",uuid:null,publicationDateTime:null,unit:null};{switch(i.type){case"integer":case"decimal":{s=Number(i.content);break}case"dateTime":{s=i.content?typeof i.content=="string"?new Date(i.content):new Date(S({content:i.content})):null;break}default:{"slug"in i&&i.slug!=null?s=p(i.slug):i.content!=null&&(s=S({content:i.content})),i.type==="boolean"&&(o=i.booleanValue??null);break}}let a="string";if(i.type!=null){let{data:c,error:y}=fe.safeParse(i.type);if(y)throw new Error(`Invalid property value content type: "${i.type}"`);a=c}return{content:s,booleanValue:o,isUncertain:i.isUncertain??!1,type:a,category:i.category??"value",uuid:i.uuid??null,publicationDateTime:i.publicationDateTime!=null?new Date(i.publicationDateTime):null,unit:i.unit??null}}});return{uuid:e.label.uuid,label:S(e.label,r).replace(/\s*\.{3}$/,"").trim(),values:t,comment:e.comment!=null?p(e.comment):null,properties:e.property?T(Array.isArray(e.property)?e.property:[e.property]):[]}}function T(e,r="eng"){let n=[];for(let t of e)n.push(Ne(t,r));return n}function He(e){let r=[];for(let n of e)r.push({date:new Date(n.date),number:n.interpretationNo,properties:n.properties?T(Array.isArray(n.properties.property)?n.properties.property:[n.properties.property]):[]});return r}function Me(e){let r={area:[],width:e.width,height:e.height},n=Array.isArray(e.area)?e.area:[e.area];for(let t of n)r.area.push({uuid:t.uuid,publicationDateTime:t.publicationDateTime!=null?new Date(t.publicationDateTime):null,type:t.type,title:p(t.title),shape:t.shape==="rect"?"rectangle":"polygon",coords:t.coords.split(",").map(i=>Number.parseInt(i))});return r}function X(e){return{uuid:e.uuid,category:"period",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type??null,number:e.n??null,identification:I(e.identification),description:e.description?S(e.description):null}}function Y(e){let r=[];for(let n of e)r.push(X(n));return r}function Z(e){let r=null;return e.source?.resource&&(r={uuid:e.source.resource.uuid,publicationDateTime:e.source.resource.publicationDateTime?new Date(e.source.resource.publicationDateTime):null,type:e.source.resource.type,identification:I(e.source.resource.identification)}),{uuid:e.uuid,category:"bibliography",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type??null,number:e.n??null,identification:e.identification?I(e.identification):null,projectIdentification:e.project?.identification?I(e.project.identification):null,context:e.context?V(e.context):null,citation:{format:e.citationFormat??null,short:e.citationFormatSpan?p("default:span"in e.citationFormatSpan?e.citationFormatSpan["default:span"].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?p("default:div"in e.referenceFormatDiv?e.referenceFormatDiv["default:div"]["default:div"].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?W(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:p(e.entryInfo.startIssue),startVolume:p(e.entryInfo.startVolume)}:null,source:{resource:r,documentUrl:e.sourceDocument?`https://ochre.lib.uchicago.edu/ochre?uuid=${e.sourceDocument.uuid}&load`:null},periods:e.periods?Y(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],authors:e.authors?W(Array.isArray(e.authors.person)?e.authors.person:[e.authors.person]):[],properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function q(e){let r=[];for(let n of e)r.push(Z(n));return r}function ee(e){return{uuid:e.uuid,category:"propertyValue",number:e.n,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,context:e.context?V(e.context):null,availability:e.availability?B(e.availability):null,identification:I(e.identification),date:e.date?new Date(e.date):null,creators:e.creators?W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],description:e.description?["string","number","boolean"].includes(typeof e.description)?p(e.description):S(e.description):"",notes:e.notes?le(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?U(Array.isArray(e.links)?e.links:[e.links]):[]}}function Oe(e){let r=[];for(let n of e)r.push(ee(n));return r}function Pe(e){let r=[];e.creators&&(r=W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]));let n=null;e.date!=null&&(n=new Date(e.date));let t=[],i=[],s=[],o=[],a=[],l=[],c=[];return typeof e.items!="string"&&"resource"in e.items&&(t=H(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource])),typeof e.items!="string"&&"spatialUnit"in e.items&&(i=Te(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit])),typeof e.items!="string"&&"concept"in e.items&&(s=Ee(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept])),typeof e.items!="string"&&"period"in e.items&&(o=Y(Array.isArray(e.items.period)?e.items.period:[e.items.period])),typeof e.items!="string"&&"bibliography"in e.items&&(a=q(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography])),typeof e.items!="string"&&"person"in e.items&&(l=W(Array.isArray(e.items.person)?e.items.person:[e.items.person])),typeof e.items!="string"&&"propertyValue"in e.items&&(c=Oe(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue])),{uuid:e.uuid,category:"tree",publicationDateTime:new Date(e.publicationDateTime),identification:I(e.identification),creators:r,license:B(e.availability),date:n,type:e.type,number:e.n,items:{resources:t,spatialUnits:i,concepts:s,periods:o,bibliographies:a,persons:l,propertyValues:c},properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function ke(e,r){if(typeof e.items=="string")throw new TypeError("Invalid OCHRE data: Set has no items");let n=r??M(Object.keys(e.items)),t=[];switch(n){case"resource":{if(!("resource"in e.items))throw new Error("Invalid OCHRE data: Set has no resources");t=H(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource]);break}case"spatialUnit":{if(!("spatialUnit"in e.items))throw new Error("Invalid OCHRE data: Set has no spatial units");t=Te(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit]);break}case"concept":{if(!("concept"in e.items))throw new Error("Invalid OCHRE data: Set has no concepts");t=Ee(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept]);break}case"period":{if(!("period"in e.items))throw new Error("Invalid OCHRE data: Set has no periods");t=Y(Array.isArray(e.items.period)?e.items.period:[e.items.period]);break}case"bibliography":{if(!("bibliography"in e.items))throw new Error("Invalid OCHRE data: Set has no bibliographies");t=q(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography]);break}case"person":{if(!("person"in e.items))throw new Error("Invalid OCHRE data: Set has no persons");t=W(Array.isArray(e.items.person)?e.items.person:[e.items.person]);break}case"propertyValue":{if(!("propertyValue"in e.items))throw new Error("Invalid OCHRE data: Set has no property values");t=Oe(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]);break}default:throw new Error("Invalid OCHRE data: Set has no items or is malformed")}return{uuid:e.uuid,category:"set",itemCategory:r,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,date:e.date!=null?new Date(e.date):null,license:B(e.availability),identification:I(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?["string","number","boolean"].includes(typeof e.description)?p(e.description):S(e.description):"",creators:e.creators?W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],type:e.type,number:e.n,items:t}}function te(e){return{uuid:e.uuid,category:"resource",publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,type:e.type,number:e.n,format:e.format??null,context:"context"in e&&e.context?V(e.context):null,license:"availability"in e&&e.availability?B(e.availability):null,copyright:"copyright"in e&&e.copyright!=null?p(e.copyright):null,identification:I(e.identification),date:e.date!=null?new Date(e.date):null,image:e.image?Ie(e.image):null,creators:e.creators?W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],notes:e.notes?le(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],description:e.description?["string","number","boolean"].includes(typeof e.description)?p(e.description):S(e.description):"",document:e.document&&"content"in e.document?se(e.document.content):null,href:e.href??null,imageMap:e.imagemap?Me(e.imagemap):null,periods:e.periods?Y(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],links:e.links?U(Array.isArray(e.links)?e.links:[e.links]):[],reverseLinks:e.reverseLinks?U(Array.isArray(e.reverseLinks)?e.reverseLinks:[e.reverseLinks]):[],properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],citedBibliographies:e.citedBibliography?q(Array.isArray(e.citedBibliography.reference)?e.citedBibliography.reference:[e.citedBibliography.reference]):[],resources:e.resource?H(Array.isArray(e.resource)?e.resource:[e.resource]):[]}}function H(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(te(t));return r}function re(e){return{uuid:e.uuid,category:"spatialUnit",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type,number:e.n,context:"context"in e&&e.context?V(e.context):null,license:"availability"in e&&e.availability?B(e.availability):null,identification:I(e.identification),image:e.image?Ie(e.image):null,description:e.description?["string","number","boolean"].includes(typeof e.description)?p(e.description):S(e.description):"",coordinates:e.coordinates?oe(e.coordinates):e.coordinate?oe(e.coordinate):null,observations:"observations"in e&&e.observations?Ve(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[xe(e.observation)]:[],events:"events"in e&&e.events?De(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:"properties"in e&&e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function Te(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(re(t));return r}function ne(e){return{uuid:e.uuid,category:"concept",publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,number:e.n,license:"availability"in e&&e.availability?B(e.availability):null,context:"context"in e&&e.context?V(e.context):null,identification:I(e.identification),interpretations:He(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation])}}var ae=async(e,r)=>{let n=[];for(let t of e)if((t.properties?T(Array.isArray(t.properties.property)?t.properties.property:[t.properties.property]):[]).find(o=>o.label==="presentation"&&o.values[0].content===r))switch(r){case"element":{let o=await G(t);n.push(o);break}case"page":{let o=await Ce(t);o&&n.push(o);break}case"block":{let o=await ce(t);o&&n.push(o);break}}return n};function Ee(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(ne(t));return r}async function Ye(e,r){let n=de.parse(e.values[0].content),t={component:n},i=r.links?U(Array.isArray(r.links)?r.links:[r.links]):[],s=i.filter(a=>a.type==="image"||a.type==="IIIF"),o=r.document&&"content"in r.document?se(r.document.content):null;if(o===null){let a=i.find(l=>l.type==="internalDocument");if(a){let{item:l,error:c}=await we(a.uuid,"resource");if(c!==null)throw new Error("Failed to fetch OCHRE data");o=l.document}}switch(n){case"annotated-document":{if(!o)throw new Error(`Document not found for the following component: \u201C${n}\u201D`);t.document=o;break}case"annotated-image":{if(s.length===0)throw new Error(`Image link not found for the following component: \u201C${n}\u201D`);let a=d(e.properties,"is-searchable")==="Yes";t.imageUuid=s[0].uuid,t.isSearchable=a;break}case"bibliography":{let a=i.find(c=>c.category==="bibliography");if(!a)throw new Error(`Bibliography link not found for the following component: \u201C${n}\u201D`);if(!a.bibliographies)throw new Error(`Bibliography not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"layout");l??="long",t.bibliographies=a.bibliographies,t.layout=l;break}case"button":{let a=d(e.properties,"variant");a??="default";let l=!1,c=d(e.properties,"navigate-to");if(c===null){if(c=d(e.properties,"link-to"),c===null)throw new Error(`Properties \u201Cnavigate-to\u201D or \u201Clink-to\u201D not found for the following component: \u201C${n}\u201D`);l=!0}let y=null,b=d(e.properties,"icon");b!==null&&(y=b),t.variant=a,t.href=c,t.isExternal=l,t.label=["string","number","boolean"].includes(typeof r.identification.label)?p(r.identification.label):S(r.identification.label),t.icon=y;break}case"collection":{let a=i.find(v=>v.category==="set");if(!a)throw new Error(`Collection link not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"variant");l??="full";let c=d(e.properties,"item-variant");c??="default";let y=!1,b=d(e.properties,"show-count");b!==null&&(y=b==="Yes");let x=!1,f=d(e.properties,"is-searchable");f!==null&&(x=f==="Yes");let g=d(e.properties,"layout");g??="image-start",t.collectionId=a.uuid,t.variant=l,t.itemVariant=c,t.isSearchable=x,t.showCount=y,t.layout=g;break}case"empty-space":{let a=d(e.properties,"height"),l=d(e.properties,"width");t.height=a,t.width=l;break}case"entries":{let a=i.find(b=>b.category==="tree");if(!a)throw new Error(`Entries link not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"variant");l??="entry";let c=!1,y=d(e.properties,"is-searchable");y!==null&&(c=y==="Yes"),t.entriesId=a.uuid,t.variant=l,t.isSearchable=c;break}case"filter-categories":{let a=i.find(l=>l.category==="set");if(!a)throw new Error(`Filter link not found for the following component: \u201C${n}\u201D`);t.filterId=a.uuid;break}case"iframe":{let a=i.find(y=>y.type==="webpage")?.href;if(!a)throw new Error(`URL not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"height"),c=d(e.properties,"width");t.href=a,t.height=l,t.width=c;break}case"iiif-viewer":{let a=i.find(l=>l.type==="IIIF");if(!a)throw new Error(`Manifest link not found for the following component: \u201C${n}\u201D`);t.IIIFId=a.uuid;break}case"image":{if(s.length===0)throw new Error(`Image link not found for the following component: \u201C${n}\u201D`);let a=[];for(let L of s)a.push({url:`https://ochre.lib.uchicago.edu/ochre?uuid=${L.uuid}&load`,label:L.identification?.label??null,width:L.image?.width??0,height:L.image?.height??0});let l=d(e.properties,"variant");l??="default";let c=d(e.properties,"layout-caption");c??="bottom";let y=null,b=d(e.properties,"width");b!==null&&(typeof b=="number"?y=b:typeof b=="string"&&(y=Number.parseFloat(b)));let x=null,f=d(e.properties,"height");f!==null&&(typeof f=="number"?x=f:typeof f=="string"&&(x=Number.parseFloat(f)));let g=!0,v=d(e.properties,"is-full-width");v!==null&&(g=v==="Yes");let D=!0,P=d(e.properties,"is-full-height");P!==null&&(D=P==="Yes");let u=d(e.properties,"image-quality");u??="high";let h=d(e.properties,"caption-source");h??="name";let k=d(e.properties,"alt-text-source");k??="name";let w=!1,C=d(e.properties,"is-transparent");C!==null&&(w=C==="Yes");let m=!1,E=d(e.properties,"is-cover");E!==null&&(m=E==="Yes");let $=null;if(a.length>1){let L=J(e.properties,"variant"),A=5;if(L&&L.values[0].content==="carousel"){let j=d(L.properties,"seconds-per-image");j!==null&&(typeof j=="number"?A=j:typeof j=="string"&&(A=Number.parseFloat(j)))}$={secondsPerImage:A}}t.images=a,t.variant=l,t.width=y,t.height=x,t.isFullWidth=g,t.isFullHeight=D,t.imageQuality=u,t.captionLayout=c,t.captionSource=h,t.altTextSource=k,t.isTransparentBackground=w,t.isCover=m,t.carouselOptions=$;break}case"image-gallery":{let a=i.find(c=>c.category==="tree"||c.category==="set");if(!a)throw new Error(`Image gallery link not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"is-searchable")==="Yes";t.galleryId=a.uuid,t.isSearchable=l;break}case"n-columns":{let a=r.resource?await ae(Array.isArray(r.resource)?r.resource:[r.resource],"element"):[];t.columns=a;break}case"n-rows":{let a=r.resource?await ae(Array.isArray(r.resource)?r.resource:[r.resource],"element"):[];t.rows=a;break}case"network-graph":break;case"table":{let a=i.find(l=>l.category==="set");if(!a)throw new Error(`Table link not found for the following component: \u201C${n}\u201D`);t.tableId=a.uuid;break}case"search-bar":{let a=d(e.properties,"variant");a??="default",t.variant=a;break}case"text":{if(!o)throw new Error(`Document not found for the following component: \u201C${n}\u201D`);let a=d(e.properties,"variant");a??="block";let l=d(e.properties,"heading");t.variant=a,t.heading=l,t.content=o.content;break}case"timeline":{let a=i.find(l=>l.category==="tree");if(!a)throw new Error(`Timeline link not found for the following component: \u201C${n}\u201D`);t.timelineId=a.uuid;break}case"video":{let a=i.find(c=>c.type==="video");if(!a)throw new Error(`Video link not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"chapters-displayed");l??="Yes",t.videoId=a.uuid,t.isChaptersDislayed=l==="Yes";break}default:{console.warn(`Invalid or non-implemented component name \u201C${n}\u201D for the following element: \u201C${S(r.identification.label)}\u201D`);break}}return t}async function G(e){let r=I(e.identification),t=(e.properties?.property?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]).find(h=>h.label==="presentation");if(!t)throw new Error(`Presentation property not found for element \u201C${r.label}\u201D`);let i=t.properties.find(h=>h.label==="component");if(!i)throw new Error(`Component for element \u201C${r.label}\u201D not found`);let s=await Ye(i,e),a=t.properties.find(h=>h.label==="section-sidebar-displayed")?.values[0]?.booleanValue===!0,l=e.properties?.property?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],c=l.find(h=>h.label==="presentation"&&h.values[0].content==="css")?.properties??[],y=[];for(let h of c){let k=h.values[0].content;y.push({label:h.label,value:k})}let b=l.find(h=>h.label==="presentation"&&h.values[0].content==="css-mobile")?.properties??[],x=[];for(let h of b){let k=h.values[0].content;x.push({label:h.label,value:k})}let f=l.find(h=>h.label==="presentation"&&h.values[0].content==="title")?.properties,g="default",v=!1,D=!1,P=!1,u=!1;if(f){let h=d(f,"variant");h&&(g=h);let k=f.filter(w=>w.label==="display");k.length>0&&(v=k.some(w=>w.values[0].content==="name"),D=k.some(w=>w.values[0].content==="description"),P=k.some(w=>w.values[0].content==="date"),u=k.some(w=>w.values[0].content==="creators"))}return{uuid:e.uuid,type:"element",title:{label:r.label,variant:g,properties:{isNameDisplayed:v,isDescriptionDisplayed:D,isDateDisplayed:P,isCreatorsDisplayed:u}},isDisplayedInBlockSectionSidebar:a,cssStyles:y,cssStylesMobile:x,...s}}async function Ce(e){let r=e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];if(r.length===0||r.find(u=>u.label==="presentation")?.values[0]?.content!=="page")return null;let n=I(e.identification),t=e.slug;if(t===void 0)throw new Error(`Slug not found for page \u201C${n.label}\u201D`);let s=(e.links?U(Array.isArray(e.links)?e.links:[e.links]):[]).find(u=>u.type==="image"||u.type==="IIIF"),o=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],a=[];for(let u of o){let h=u.properties?T(Array.isArray(u.properties.property)?u.properties.property:[u.properties.property]):[],k=d(h,"presentation");if(k!=null)switch(k){case"element":{let w=await G(u);a.push(w);break}case"block":{let w=await ce(u);w&&a.push(w);break}}}let l=e.resource?await ae(Array.isArray(e.resource)?e.resource:[e.resource],"page"):[],c=!0,y="default",b="default",x=!0,f=r.find(u=>u.label==="presentation"&&u.values[0]?.content==="page")?.properties;if(f){let u=f.find(C=>C.label==="header")?.values[0];u&&(c=u.content==="Yes");let h=f.find(C=>C.label==="width")?.values[0];h&&(y=h.content);let k=f.find(C=>C.label==="variant")?.values[0];k&&(b=k.content);let w=f.find(C=>C.label==="sidebar-visible")?.values[0];w&&(x=w.content==="Yes")}let g=r.find(u=>u.label==="presentation"&&u.values[0]?.content==="css")?.properties,v=[];if(g)for(let u of g)v.push({label:u.label,value:u.values[0].content});let D=r.find(u=>u.label==="presentation"&&u.values[0]?.content==="css-mobile")?.properties,P=[];if(D)for(let u of D)P.push({label:u.label,value:u.values[0].content});return{title:n.label,slug:t,items:a,properties:{displayedInHeader:c,width:y,variant:b,backgroundImageUrl:s?`https://ochre.lib.uchicago.edu/ochre?uuid=${s.uuid}&load`:null,isSidebarDisplayed:x,cssStyles:v,cssStylesMobile:P},webpages:l}}async function qe(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n){let i=await Ce(t);i&&r.push(i)}return r}async function ce(e){let r={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?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],t=n.find(l=>l.label==="presentation"&&l.values[0]?.content==="block")?.properties;if(t){let l=t.find(g=>g.label==="layout")?.values[0];l&&(r.layout=l.content);let c=t.find(g=>g.label==="spacing")?.values[0];c&&(r.properties.spacing=c.content);let y=t.find(g=>g.label==="gap")?.values[0];y&&(r.properties.gap=y.content);let b=t.find(g=>g.label==="align-items")?.values[0];b&&(r.properties.alignItems=b.content);let x=t.find(g=>g.label==="justify-content")?.values[0];x&&(r.properties.justifyContent=x.content);let f=t.find(g=>g.label==="overwrite-mobile");if(f){let g=f.properties,v={};for(let D of g)v[D.label]=D.values[0].content;r.propertiesMobile=v}}let i=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],s=[];for(let l of i){let c=l.properties?T(Array.isArray(l.properties.property)?l.properties.property:[l.properties.property]):[],y=d(c,"presentation");if(y!=null)switch(y){case"element":{let b=await G(l);s.push(b);break}case"block":{let b=await ce(l);b&&s.push(b);break}}}r.items=s;let o=n.find(l=>l.label==="presentation"&&l.values[0]?.content==="css")?.properties;if(o)for(let l of o)r.cssStyles.push({label:l.label,value:l.values[0].content});let a=n.find(l=>l.label==="presentation"&&l.values[0]?.content==="css-mobile")?.properties;if(a)for(let l of a)r.cssStylesMobile.push({label:l.label,value:l.values[0].content});return r.properties.sectionSidebarItems=$e(r),r}function $e(e){let r=[];for(let n of e.items)switch(n.type){case"block":{let t=$e(n);t!==null&&r.push({uuid:n.uuid,type:"block",name:null,items:t});break}case"element":{if(!n.isDisplayedInBlockSectionSidebar)continue;r.push({uuid:n.uuid,type:"element",name:n.title.label,items:null});break}}return r.length>0?r:null}function Ge(e){let n=T(e).find(A=>A.label==="presentation")?.properties;if(!n)throw new Error("Presentation property not found");let t=n.find(A=>A.label==="webUI")?.values[0]?.content;if(t==null)throw new Error("Website type not found");let i=n.find(A=>A.label==="status")?.values[0]?.content;if(i==null)throw new Error("Website status not found");let s=n.find(A=>A.label==="privacy")?.values[0]?.content;s??="public";let o=ue.safeParse({type:t,status:i,privacy:s});if(!o.success)throw new Error(`Invalid website properties: ${o.error.message}`);let a=null,l=n.find(A=>A.label==="contact");if(l){let[A,j]=(l.values[0]?.content).split(";");a={name:A,email:j??null}}let c=n.find(A=>A.label==="logo")?.values[0]?.uuid??null,y=!0,b="default",x="start",f=!0,g=!0,v=!1,D=!0,P=n.find(A=>A.label==="navbar-visible")?.values[0];P&&(y=P.content==="Yes");let u=n.find(A=>A.label==="navbar-variant")?.values[0];u&&(b=u.content);let h=n.find(A=>A.label==="navbar-alignment")?.values[0];h&&(x=h.content);let k=n.find(A=>A.label==="navbar-project-visible")?.values[0];k&&(f=k.content==="Yes");let w=n.find(A=>A.label==="footer-visible")?.values[0];w&&(g=w.content==="Yes");let C=n.find(A=>A.label==="sidebar-visible")?.values[0];C&&(v=C.content==="Yes");let m=n.find(A=>A.label==="supports-theme-toggle")?.values[0];m&&(D=m.content==="Yes");let{type:E,status:$,privacy:L}=o.data;return{type:E,privacy:L,status:$,contact:a,isHeaderDisplayed:y,headerVariant:b,headerAlignment:x,isHeaderProjectDisplayed:f,isFooterDisplayed:g,isSidebarDisplayed:v,supportsThemeToggle:D,logoUrl:c!==null?`https://ochre.lib.uchicago.edu/ochre?uuid=${c}&load`:null}}async function Le(e,r,n){if(!e.properties)throw new Error("Website properties not found");let t=Ge(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]);if(typeof e.items=="string"||!("resource"in e.items))throw new Error("Website pages not found");let i=Array.isArray(e.items.resource)?e.items.resource:[e.items.resource],s=await qe(i),o=null,a=[],l={label:"",variant:"default",properties:{isNameDisplayed:!1,isDescriptionDisplayed:!1,isDateDisplayed:!1,isCreatorsDisplayed:!1}},c="start",y="default",b=[],x=[],f=i.find(v=>(v.properties?T(Array.isArray(v.properties.property)?v.properties.property:[v.properties.property]):[]).some(P=>P.label==="presentation"&&P.values[0]?.content==="element"&&P.properties[0]?.label==="component"&&P.properties[0].values[0]?.content==="sidebar"));if(f){l.label=typeof f.identification.label=="string"||typeof f.identification.label=="number"||typeof f.identification.label=="boolean"?p(f.identification.label):S(f.identification.label);let v=f.properties?T(Array.isArray(f.properties.property)?f.properties.property:[f.properties.property]):[],D=v.find(m=>m.label==="presentation"&&m.values[0]?.content==="element")?.properties.find(m=>m.label==="component"&&m.values[0]?.content==="sidebar")?.properties??[],P=D.find(m=>m.label==="layout");P&&(c=P.values[0].content);let u=D.find(m=>m.label==="layout-mobile");u&&(y=u.values[0].content);let h=v.find(m=>m.label==="presentation"&&m.values[0].content==="css")?.properties??[];for(let m of h){let E=m.values[0].content;b.push({label:m.label,value:E})}let k=v.find(m=>m.label==="presentation"&&m.values[0].content==="css-mobile")?.properties??[];for(let m of k){let E=m.values[0].content;x.push({label:m.label,value:E})}let w=v.find(m=>m.label==="presentation"&&m.values[0].content==="title")?.properties;if(w){let m=d(w,"variant");m&&(l.variant=m);let E=w.filter($=>$.label==="display");E.length>0&&(l.properties.isNameDisplayed=E.some($=>$.values[0].content==="name"),l.properties.isDescriptionDisplayed=E.some($=>$.values[0].content==="description"),l.properties.isDateDisplayed=E.some($=>$.values[0].content==="date"),l.properties.isCreatorsDisplayed=E.some($=>$.values[0].content==="creators"))}let C=f.resource?Array.isArray(f.resource)?f.resource:[f.resource]:[];for(let m of C){let E=await G(m);a.push(E)}}a.length>0&&(o={elements:a,title:l,layout:c,mobileLayout:y,cssStyles:b,cssStylesMobile:x});let g=null;if(e.searchOptions){let v=[];for(let D of s)for(let P of D.items)P.type==="element"&&P.component==="collection"&&v.push(P.collectionId);g={uuids:v,properties:{metadataUuids:[...e.searchOptions.metadata?.option??[]],searchUuids:[...e.searchOptions.filters?.option??[]],labelUuids:[...e.searchOptions.labels?.option??[]]}}}return{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:I(e.identification),project:{name:p(r),website:n!==null?p(n):null},creators:e.creators?W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:B(e.availability),pages:s,sidebar:o,properties:t,collectionOptions:g}}async function yt(e,r,n,t){try{let{uuid:i,filter:s,page:o,perPage:a}=ye.parse({uuid:e,filter:r,page:n,perPage:t}),l=await fetch(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
4
+ ${JSON.stringify(e.content)}.`);return _(t)}}else return _(e.content);default:return String(e.content).replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}}function M(e){let r=e.find(t=>K.safeParse(t).success);if(!r){let t=e.find(i=>!["uuid","uuidBelongsTo","belongsTo","publicationDateTime","metadata","languages"].includes(i));throw new Error(`Invalid OCHRE data; found unexpected "${t}" key`)}return K.parse(r)}async function ve(e){try{let r=pe.parse(e),n=await fetch(`https://ochre.lib.uchicago.edu/ochre?uuid=${r}&format=json&lang="*"`);if(!n.ok)throw new Error("Failed to fetch OCHRE data");let t=await n.json();if(!("ochre"in t))throw new Error("Invalid OCHRE data: API response missing 'ochre' key");return[null,t]}catch(r){return[r instanceof Error?r.message:"Unknown error",null]}}async function we(e,r,n){try{let[t,i]=await ve(e);if(t!==null)throw new Error(t);let s=M(Object.keys(i.ochre)),o;switch(s){case"resource":{if(!("resource"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'resource' key");o=te(i.ochre.resource);break}case"spatialUnit":{if(!("spatialUnit"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'spatialUnit' key");o=re(i.ochre.spatialUnit);break}case"concept":{if(!("concept"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'concept' key");o=ne(i.ochre.concept);break}case"period":{if(!("period"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'period' key");o=X(i.ochre.period);break}case"bibliography":{if(!("bibliography"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'bibliography' key");o=Z(i.ochre.bibliography);break}case"person":{if(!("person"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'person' key");o=R(i.ochre.person);break}case"propertyValue":{if(!("propertyValue"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'propertyValue' key");o=ee(i.ochre.propertyValue);break}case"set":{if(!("set"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'set' key");o=ke(i.ochre.set,n);break}case"tree":{if(!("tree"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'tree' key");o=Pe(i.ochre.tree);break}default:throw new Error("Invalid category")}let a=Se(i.ochre.metadata),l={uuid:i.ochre.uuidBelongsTo,abbreviation:p(i.ochre.belongsTo)};return{error:null,metadata:a,belongsTo:l,item:o,category:r}}catch(t){return{error:t instanceof Error?t.message:"Unknown error",metadata:void 0,belongsTo:void 0,item:void 0,category:void 0}}}function I(e){try{let r={label:["string","number","boolean"].includes(typeof e.label)?p(e.label):S(e.label),abbreviation:""};for(let n of Object.keys(e).filter(t=>t!=="label"))r[n]=S(e[n]);return r}catch(r){return console.error(r),{label:"",abbreviation:""}}}function Ue(e){return e==null?["eng"]:Array.isArray(e)?e.map(r=>S(r)):[S(e)]}function Se(e){let r={label:"",abbreviation:""};if(e.item)if(e.item.label||e.item.abbreviation){let i="",s="";e.item.label&&(i=S(e.item.label)),e.item.abbreviation&&(s=S(e.item.abbreviation)),r={label:i,abbreviation:s}}else r=I(e.item.identification);let n=null,t=e.project?.identification?I(e.project.identification):null;return t&&(n={...t,website:e.project?.identification.website??null}),{project:n?{identification:n}:null,item:e.item?{identification:r,category:e.item.category,type:e.item.type,maxLength:e.item.maxLength??null}:null,dataset:S(e.dataset),publisher:S(e.publisher),languages:Ue(e.language),identifier:S(e.identifier),description:S(e.description)}}function ie(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,number:e.n,content:p(e.content)}}function V(e){return{nodes:(Array.isArray(e.context)?e.context:[e.context]).map(t=>{let i=[];if("spatialUnit"in t&&t.spatialUnit){let s=Array.isArray(t.spatialUnit)?t.spatialUnit:[t.spatialUnit];for(let o of s)i.push(ie(o))}return{tree:ie(t.tree),project:ie(t.project),spatialUnit:i}}),displayPath:e.displayPath}}function B(e){return typeof e.license=="string"?null:{content:e.license.content,url:e.license.target}}function R(e){return{uuid:e.uuid,category:"person",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type??null,number:e.n??null,context:e.context?V(e.context):null,date:e.date!=null?new Date(e.date):null,identification:e.identification?I(e.identification):null,availability:e.availability?B(e.availability):null,address:e.address?{country:e.address.country??null,city:e.address.city??null,state:e.address.state??null}:null,coordinates:e.coordinates?oe(e.coordinates):null,content:e.content!=null?p(e.content):null,events:e.events?De(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function W(e){let r=[];for(let n of e)r.push(R(n));return r}function je(e){let r="resource"in e?e.resource:"spatialUnit"in e?e.spatialUnit:"concept"in e?e.concept:"set"in e?e.set:"tree"in e?e.tree:"person"in e?e.person:"bibliography"in e?e.bibliography:"epigraphicUnit"in e?e.epigraphicUnit:"propertyValue"in e?e.propertyValue:null;if(!r)throw new Error(`Invalid link provided: ${JSON.stringify(e,null,2)}`);let n=Array.isArray(r)?r:[r],t=[];for(let i of n){let s={category:"resource"in e?"resource":"spatialUnit"in e?"spatialUnit":"concept"in e?"concept":"set"in e?"set":"person"in e?"person":"tree"in e?"tree":"bibliography"in e?"bibliography":"epigraphicUnit"in e?"epigraphicUnit":"propertyValue"in e?"propertyValue":null,content:"content"in i&&i.content!=null?p(i.content):null,href:"href"in i&&i.href!=null?i.href:null,uuid:i.uuid,type:i.type??null,identification:i.identification?I(i.identification):null,image:null,bibliographies:"bibliography"in e?q(Array.isArray(e.bibliography)?e.bibliography:[e.bibliography]):null,publicationDateTime:i.publicationDateTime!=null?new Date(i.publicationDateTime):null};"height"in i&&i.height!=null&&i.width!=null&&i.heightPreview!=null&&i.widthPreview!=null&&(s.image={isInline:i.rend==="inline",isPrimary:i.isPrimary??!1,heightPreview:i.heightPreview,widthPreview:i.widthPreview,height:i.height,width:i.width}),t.push(s)}return t}function j(e){let r=[];for(let n of e)r.push(...je(n));return r}function se(e,r="eng"){let n="",t=[],i=Array.isArray(e)?e.find(s=>s.lang===r):e;if(typeof i.string=="string"||typeof i.string=="number"||typeof i.string=="boolean")n+=F(p(i.string));else{let s=Array.isArray(i.string)?i.string:[i.string];for(let o of s)n+=Q(o,t)}return{content:n,footnotes:t}}function Ie(e){return{publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,identification:e.identification?I(e.identification):null,url:e.href??(e.htmlImgSrcPrefix==null&&e.content!=null?p(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?p(e.content):null,widthPreview:e.widthPreview??null,heightPreview:e.heightPreview??null,width:e.width??null,height:e.height??null}}function le(e,r="eng"){let n=[];for(let t of e){if(typeof t=="string"){if(t==="")continue;n.push({number:-1,title:null,content:t});continue}let i="",s=Array.isArray(t.content)?t.content:[t.content],o=s.find(a=>a.lang===r);if(!o&&(o=s[0],!o))throw new Error(`Note does not have a valid content item: ${JSON.stringify(t,null,2)}`);typeof o.string=="string"||typeof o.string=="number"||typeof o.string=="boolean"?i=F(p(o.string)):i=F(se(o).content),n.push({number:t.noteNo,title:o.title!=null?p(o.title):null,content:i})}return n}function oe(e){if(typeof e=="string"){let[r,n]=e.split(", ");return{latitude:Number(r),longitude:Number(n),type:null,label:null}}return{latitude:e.latitude,longitude:e.longitude,type:e.coord?.coordType??null,label:e.coord?.coordLabel!=null?p(e.coord.coordLabel):null}}function xe(e){return{number:e.observationNo,date:e.date!=null?new Date(e.date):null,observers:e.observers!=null?p(e.observers).split(";").map(r=>r.trim()):[],notes:e.notes?le(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?j(Array.isArray(e.links)?e.links:[e.links]):[],properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function Ve(e){let r=[];for(let n of e)r.push(xe(n));return r}function De(e){let r=[];for(let n of e)r.push({date:n.dateTime!=null?new Date(n.dateTime):null,label:S(n.label),agent:n.agent?{uuid:n.agent.uuid,content:p(n.agent.content)}:null});return r}function Ne(e,r="eng"){let t=("value"in e&&e.value?Array.isArray(e.value)?e.value:[e.value]:[]).map(i=>{let s=null,o=null;if(typeof i=="string"||typeof i=="number"||typeof i=="boolean")return s=p(i),{content:s,booleanValue:o,isUncertain:!1,type:"string",category:"value",uuid:null,publicationDateTime:null,unit:null};{switch(i.type){case"integer":case"decimal":{s=Number(i.content);break}case"dateTime":{s=i.content?typeof i.content=="string"?new Date(i.content):new Date(S({content:i.content})):null;break}default:{"slug"in i&&i.slug!=null?s=p(i.slug):i.content!=null&&(s=S({content:i.content})),i.type==="boolean"&&(o=i.booleanValue??null);break}}let a="string";if(i.type!=null){let{data:c,error:y}=fe.safeParse(i.type);if(y)throw new Error(`Invalid property value content type: "${i.type}"`);a=c}return{content:s,booleanValue:o,isUncertain:i.isUncertain??!1,type:a,category:i.category??"value",uuid:i.uuid??null,publicationDateTime:i.publicationDateTime!=null?new Date(i.publicationDateTime):null,unit:i.unit??null}}});return{uuid:e.label.uuid,label:S(e.label,r).replace(/\s*\.{3}$/,"").trim(),values:t,comment:e.comment!=null?p(e.comment):null,properties:e.property?T(Array.isArray(e.property)?e.property:[e.property]):[]}}function T(e,r="eng"){let n=[];for(let t of e)n.push(Ne(t,r));return n}function He(e){let r=[];for(let n of e)r.push({date:new Date(n.date),number:n.interpretationNo,properties:n.properties?T(Array.isArray(n.properties.property)?n.properties.property:[n.properties.property]):[]});return r}function Me(e){let r={area:[],width:e.width,height:e.height},n=Array.isArray(e.area)?e.area:[e.area];for(let t of n)r.area.push({uuid:t.uuid,publicationDateTime:t.publicationDateTime!=null?new Date(t.publicationDateTime):null,type:t.type,title:p(t.title),shape:t.shape==="rect"?"rectangle":"polygon",coords:t.coords.split(",").map(i=>Number.parseInt(i))});return r}function X(e){return{uuid:e.uuid,category:"period",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type??null,number:e.n??null,identification:I(e.identification),description:e.description?S(e.description):null}}function Y(e){let r=[];for(let n of e)r.push(X(n));return r}function Z(e){let r=null;return e.source?.resource&&(r={uuid:e.source.resource.uuid,publicationDateTime:e.source.resource.publicationDateTime?new Date(e.source.resource.publicationDateTime):null,type:e.source.resource.type,identification:I(e.source.resource.identification)}),{uuid:e.uuid,category:"bibliography",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type??null,number:e.n??null,identification:e.identification?I(e.identification):null,projectIdentification:e.project?.identification?I(e.project.identification):null,context:e.context?V(e.context):null,citation:{format:e.citationFormat??null,short:e.citationFormatSpan?p("default:span"in e.citationFormatSpan?e.citationFormatSpan["default:span"].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?p("default:div"in e.referenceFormatDiv?e.referenceFormatDiv["default:div"]["default:div"].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?W(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:p(e.entryInfo.startIssue),startVolume:p(e.entryInfo.startVolume)}:null,source:{resource:r,documentUrl:e.sourceDocument?`https://ochre.lib.uchicago.edu/ochre?uuid=${e.sourceDocument.uuid}&load`:null},periods:e.periods?Y(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],authors:e.authors?W(Array.isArray(e.authors.person)?e.authors.person:[e.authors.person]):[],properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function q(e){let r=[];for(let n of e)r.push(Z(n));return r}function ee(e){return{uuid:e.uuid,category:"propertyValue",number:e.n,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,context:e.context?V(e.context):null,availability:e.availability?B(e.availability):null,identification:I(e.identification),date:e.date?new Date(e.date):null,creators:e.creators?W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],description:e.description?["string","number","boolean"].includes(typeof e.description)?p(e.description):S(e.description):"",notes:e.notes?le(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?j(Array.isArray(e.links)?e.links:[e.links]):[]}}function Oe(e){let r=[];for(let n of e)r.push(ee(n));return r}function Pe(e){let r=[];e.creators&&(r=W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]));let n=null;e.date!=null&&(n=new Date(e.date));let t=[],i=[],s=[],o=[],a=[],l=[],c=[];return typeof e.items!="string"&&"resource"in e.items&&(t=H(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource])),typeof e.items!="string"&&"spatialUnit"in e.items&&(i=Te(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit])),typeof e.items!="string"&&"concept"in e.items&&(s=Ee(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept])),typeof e.items!="string"&&"period"in e.items&&(o=Y(Array.isArray(e.items.period)?e.items.period:[e.items.period])),typeof e.items!="string"&&"bibliography"in e.items&&(a=q(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography])),typeof e.items!="string"&&"person"in e.items&&(l=W(Array.isArray(e.items.person)?e.items.person:[e.items.person])),typeof e.items!="string"&&"propertyValue"in e.items&&(c=Oe(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue])),{uuid:e.uuid,category:"tree",publicationDateTime:new Date(e.publicationDateTime),identification:I(e.identification),creators:r,license:B(e.availability),date:n,type:e.type,number:e.n,items:{resources:t,spatialUnits:i,concepts:s,periods:o,bibliographies:a,persons:l,propertyValues:c},properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function ke(e,r){if(typeof e.items=="string")throw new TypeError("Invalid OCHRE data: Set has no items");let n=r??M(Object.keys(e.items)),t=[];switch(n){case"resource":{if(!("resource"in e.items))throw new Error("Invalid OCHRE data: Set has no resources");t=H(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource]);break}case"spatialUnit":{if(!("spatialUnit"in e.items))throw new Error("Invalid OCHRE data: Set has no spatial units");t=Te(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit]);break}case"concept":{if(!("concept"in e.items))throw new Error("Invalid OCHRE data: Set has no concepts");t=Ee(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept]);break}case"period":{if(!("period"in e.items))throw new Error("Invalid OCHRE data: Set has no periods");t=Y(Array.isArray(e.items.period)?e.items.period:[e.items.period]);break}case"bibliography":{if(!("bibliography"in e.items))throw new Error("Invalid OCHRE data: Set has no bibliographies");t=q(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography]);break}case"person":{if(!("person"in e.items))throw new Error("Invalid OCHRE data: Set has no persons");t=W(Array.isArray(e.items.person)?e.items.person:[e.items.person]);break}case"propertyValue":{if(!("propertyValue"in e.items))throw new Error("Invalid OCHRE data: Set has no property values");t=Oe(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]);break}default:throw new Error("Invalid OCHRE data: Set has no items or is malformed")}return{uuid:e.uuid,category:"set",itemCategory:r,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,date:e.date!=null?new Date(e.date):null,license:B(e.availability),identification:I(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?["string","number","boolean"].includes(typeof e.description)?p(e.description):S(e.description):"",creators:e.creators?W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],type:e.type,number:e.n,items:t}}function te(e){return{uuid:e.uuid,category:"resource",publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,type:e.type,number:e.n,format:e.format??null,context:"context"in e&&e.context?V(e.context):null,license:"availability"in e&&e.availability?B(e.availability):null,copyright:"copyright"in e&&e.copyright!=null?p(e.copyright):null,identification:I(e.identification),date:e.date!=null?new Date(e.date):null,image:e.image?Ie(e.image):null,creators:e.creators?W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],notes:e.notes?le(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],description:e.description?["string","number","boolean"].includes(typeof e.description)?p(e.description):S(e.description):"",document:e.document&&"content"in e.document?se(e.document.content):null,href:e.href??null,imageMap:e.imagemap?Me(e.imagemap):null,periods:e.periods?Y(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],links:e.links?j(Array.isArray(e.links)?e.links:[e.links]):[],reverseLinks:e.reverseLinks?j(Array.isArray(e.reverseLinks)?e.reverseLinks:[e.reverseLinks]):[],properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],citedBibliographies:e.citedBibliography?q(Array.isArray(e.citedBibliography.reference)?e.citedBibliography.reference:[e.citedBibliography.reference]):[],resources:e.resource?H(Array.isArray(e.resource)?e.resource:[e.resource]):[]}}function H(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(te(t));return r}function re(e){return{uuid:e.uuid,category:"spatialUnit",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type,number:e.n,context:"context"in e&&e.context?V(e.context):null,license:"availability"in e&&e.availability?B(e.availability):null,identification:I(e.identification),image:e.image?Ie(e.image):null,description:e.description?["string","number","boolean"].includes(typeof e.description)?p(e.description):S(e.description):"",coordinates:e.coordinates?oe(e.coordinates):e.coordinate?oe(e.coordinate):null,observations:"observations"in e&&e.observations?Ve(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[xe(e.observation)]:[],events:"events"in e&&e.events?De(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:"properties"in e&&e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function Te(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(re(t));return r}function ne(e){return{uuid:e.uuid,category:"concept",publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,number:e.n,license:"availability"in e&&e.availability?B(e.availability):null,context:"context"in e&&e.context?V(e.context):null,identification:I(e.identification),interpretations:He(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation])}}var ae=async(e,r)=>{let n=[];for(let t of e)if((t.properties?T(Array.isArray(t.properties.property)?t.properties.property:[t.properties.property]):[]).find(o=>o.label==="presentation"&&o.values[0].content===r))switch(r){case"element":{let o=await G(t);n.push(o);break}case"page":{let o=await Ce(t);o&&n.push(o);break}case"block":{let o=await ce(t);o&&n.push(o);break}}return n};function Ee(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(ne(t));return r}async function Ye(e,r){let n=de.parse(e.values[0].content),t={component:n},i=r.links?j(Array.isArray(r.links)?r.links:[r.links]):[],s=i.filter(a=>a.type==="image"||a.type==="IIIF"),o=r.document&&"content"in r.document?se(r.document.content):null;if(o===null){let a=i.find(l=>l.type==="internalDocument");if(a){let{item:l,error:c}=await we(a.uuid,"resource");if(c!==null)throw new Error("Failed to fetch OCHRE data");o=l.document}}switch(n){case"annotated-document":{if(!o)throw new Error(`Document not found for the following component: \u201C${n}\u201D`);t.document=o;break}case"annotated-image":{if(s.length===0)throw new Error(`Image link not found for the following component: \u201C${n}\u201D`);let a=d(e.properties,"is-searchable")==="Yes";t.imageUuid=s[0].uuid,t.isSearchable=a;break}case"bibliography":{let a=i.find(c=>c.category==="bibliography");if(!a)throw new Error(`Bibliography link not found for the following component: \u201C${n}\u201D`);if(!a.bibliographies)throw new Error(`Bibliography not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"layout");l??="long",t.bibliographies=a.bibliographies,t.layout=l;break}case"button":{let a=d(e.properties,"variant");a??="default";let l=!1,c=d(e.properties,"navigate-to");if(c===null){if(c=d(e.properties,"link-to"),c===null)throw new Error(`Properties \u201Cnavigate-to\u201D or \u201Clink-to\u201D not found for the following component: \u201C${n}\u201D`);l=!0}let y=null,b=d(e.properties,"icon");b!==null&&(y=b),t.variant=a,t.href=c,t.isExternal=l,t.label=["string","number","boolean"].includes(typeof r.identification.label)?p(r.identification.label):S(r.identification.label),t.icon=y;break}case"collection":{let a=i.find(v=>v.category==="set");if(!a)throw new Error(`Collection link not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"variant");l??="full";let c=d(e.properties,"item-variant");c??="default";let y=!1,b=d(e.properties,"show-count");b!==null&&(y=b==="Yes");let x=!1,f=d(e.properties,"is-searchable");f!==null&&(x=f==="Yes");let g=d(e.properties,"layout");g??="image-start",t.collectionId=a.uuid,t.variant=l,t.itemVariant=c,t.isSearchable=x,t.showCount=y,t.layout=g;break}case"empty-space":{let a=d(e.properties,"height"),l=d(e.properties,"width");t.height=a,t.width=l;break}case"entries":{let a=i.find(b=>b.category==="tree");if(!a)throw new Error(`Entries link not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"variant");l??="entry";let c=!1,y=d(e.properties,"is-searchable");y!==null&&(c=y==="Yes"),t.entriesId=a.uuid,t.variant=l,t.isSearchable=c;break}case"filter-categories":{let a=i.find(l=>l.category==="set");if(!a)throw new Error(`Filter link not found for the following component: \u201C${n}\u201D`);t.filterId=a.uuid;break}case"iframe":{let a=i.find(y=>y.type==="webpage")?.href;if(!a)throw new Error(`URL not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"height"),c=d(e.properties,"width");t.href=a,t.height=l,t.width=c;break}case"iiif-viewer":{let a=i.find(l=>l.type==="IIIF");if(!a)throw new Error(`Manifest link not found for the following component: \u201C${n}\u201D`);t.IIIFId=a.uuid;break}case"image":{if(s.length===0)throw new Error(`Image link not found for the following component: \u201C${n}\u201D`);let a=[];for(let L of s)a.push({url:`https://ochre.lib.uchicago.edu/ochre?uuid=${L.uuid}&load`,label:L.identification?.label??null,width:L.image?.width??0,height:L.image?.height??0});let l=d(e.properties,"variant");l??="default";let c=d(e.properties,"layout-caption");c??="bottom";let y=null,b=d(e.properties,"width");b!==null&&(typeof b=="number"?y=b:typeof b=="string"&&(y=Number.parseFloat(b)));let x=null,f=d(e.properties,"height");f!==null&&(typeof f=="number"?x=f:typeof f=="string"&&(x=Number.parseFloat(f)));let g=!0,v=d(e.properties,"is-full-width");v!==null&&(g=v==="Yes");let D=!0,P=d(e.properties,"is-full-height");P!==null&&(D=P==="Yes");let u=d(e.properties,"image-quality");u??="high";let h=d(e.properties,"caption-source");h??="name";let k=d(e.properties,"alt-text-source");k??="name";let w=!1,C=d(e.properties,"is-transparent");C!==null&&(w=C==="Yes");let m=!1,E=d(e.properties,"is-cover");E!==null&&(m=E==="Yes");let $=null;if(a.length>1){let L=J(e.properties,"variant"),A=5;if(L&&L.values[0].content==="carousel"){let U=d(L.properties,"seconds-per-image");U!==null&&(typeof U=="number"?A=U:typeof U=="string"&&(A=Number.parseFloat(U)))}$={secondsPerImage:A}}t.images=a,t.variant=l,t.width=y,t.height=x,t.isFullWidth=g,t.isFullHeight=D,t.imageQuality=u,t.captionLayout=c,t.captionSource=h,t.altTextSource=k,t.isTransparentBackground=w,t.isCover=m,t.carouselOptions=$;break}case"image-gallery":{let a=i.find(c=>c.category==="tree"||c.category==="set");if(!a)throw new Error(`Image gallery link not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"is-searchable")==="Yes";t.galleryId=a.uuid,t.isSearchable=l;break}case"n-columns":{let a=r.resource?await ae(Array.isArray(r.resource)?r.resource:[r.resource],"element"):[];t.columns=a;break}case"n-rows":{let a=r.resource?await ae(Array.isArray(r.resource)?r.resource:[r.resource],"element"):[];t.rows=a;break}case"network-graph":break;case"table":{let a=i.find(l=>l.category==="set");if(!a)throw new Error(`Table link not found for the following component: \u201C${n}\u201D`);t.tableId=a.uuid;break}case"search-bar":{let a=d(e.properties,"variant");a??="default",t.variant=a;break}case"text":{if(!o)throw new Error(`Document not found for the following component: \u201C${n}\u201D`);let a=d(e.properties,"variant");a??="block";let l=d(e.properties,"heading");t.variant=a,t.heading=l,t.content=o.content;break}case"timeline":{let a=i.find(l=>l.category==="tree");if(!a)throw new Error(`Timeline link not found for the following component: \u201C${n}\u201D`);t.timelineId=a.uuid;break}case"video":{let a=i.find(c=>c.type==="video");if(!a)throw new Error(`Video link not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"chapters-displayed");l??="Yes",t.videoId=a.uuid,t.isChaptersDislayed=l==="Yes";break}default:{console.warn(`Invalid or non-implemented component name \u201C${n}\u201D for the following element: \u201C${S(r.identification.label)}\u201D`);break}}return t}async function G(e){let r=I(e.identification),t=(e.properties?.property?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]).find(h=>h.label==="presentation");if(!t)throw new Error(`Presentation property not found for element \u201C${r.label}\u201D`);let i=t.properties.find(h=>h.label==="component");if(!i)throw new Error(`Component for element \u201C${r.label}\u201D not found`);let s=await Ye(i,e),a=t.properties.find(h=>h.label==="section-sidebar-displayed")?.values[0]?.booleanValue===!0,l=e.properties?.property?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],c=l.find(h=>h.label==="presentation"&&h.values[0].content==="css")?.properties??[],y=[];for(let h of c){let k=h.values[0].content;y.push({label:h.label,value:k})}let b=l.find(h=>h.label==="presentation"&&h.values[0].content==="css-mobile")?.properties??[],x=[];for(let h of b){let k=h.values[0].content;x.push({label:h.label,value:k})}let f=l.find(h=>h.label==="presentation"&&h.values[0].content==="title")?.properties,g="default",v=!1,D=!1,P=!1,u=!1;if(f){let h=d(f,"variant");h&&(g=h);let k=f.filter(w=>w.label==="display");k.length>0&&(v=k.some(w=>w.values[0].content==="name"),D=k.some(w=>w.values[0].content==="description"),P=k.some(w=>w.values[0].content==="date"),u=k.some(w=>w.values[0].content==="creators"))}return{uuid:e.uuid,type:"element",title:{label:r.label,variant:g,properties:{isNameDisplayed:v,isDescriptionDisplayed:D,isDateDisplayed:P,isCreatorsDisplayed:u}},isDisplayedInBlockSectionSidebar:a,cssStyles:y,cssStylesMobile:x,...s}}async function Ce(e){let r=e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];if(r.length===0||r.find(u=>u.label==="presentation")?.values[0]?.content!=="page")return null;let n=I(e.identification),t=e.slug;if(t===void 0)throw new Error(`Slug not found for page \u201C${n.label}\u201D`);let s=(e.links?j(Array.isArray(e.links)?e.links:[e.links]):[]).find(u=>u.type==="image"||u.type==="IIIF"),o=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],a=[];for(let u of o){let h=u.properties?T(Array.isArray(u.properties.property)?u.properties.property:[u.properties.property]):[],k=d(h,"presentation");if(k!=null)switch(k){case"element":{let w=await G(u);a.push(w);break}case"block":{let w=await ce(u);w&&a.push(w);break}}}let l=e.resource?await ae(Array.isArray(e.resource)?e.resource:[e.resource],"page"):[],c=!0,y="default",b="default",x=!0,f=r.find(u=>u.label==="presentation"&&u.values[0]?.content==="page")?.properties;if(f){let u=f.find(C=>C.label==="header")?.values[0];u&&(c=u.content==="Yes");let h=f.find(C=>C.label==="width")?.values[0];h&&(y=h.content);let k=f.find(C=>C.label==="variant")?.values[0];k&&(b=k.content);let w=f.find(C=>C.label==="sidebar-visible")?.values[0];w&&(x=w.content==="Yes")}let g=r.find(u=>u.label==="presentation"&&u.values[0]?.content==="css")?.properties,v=[];if(g)for(let u of g)v.push({label:u.label,value:u.values[0].content});let D=r.find(u=>u.label==="presentation"&&u.values[0]?.content==="css-mobile")?.properties,P=[];if(D)for(let u of D)P.push({label:u.label,value:u.values[0].content});return{title:n.label,slug:t,items:a,properties:{displayedInHeader:c,width:y,variant:b,backgroundImageUrl:s?`https://ochre.lib.uchicago.edu/ochre?uuid=${s.uuid}&load`:null,isSidebarDisplayed:x,cssStyles:v,cssStylesMobile:P},webpages:l}}async function qe(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n){let i=await Ce(t);i&&r.push(i)}return r}async function ce(e){let r={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?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],t=n.find(l=>l.label==="presentation"&&l.values[0]?.content==="block")?.properties;if(t){let l=t.find(g=>g.label==="layout")?.values[0];l&&(r.layout=l.content);let c=t.find(g=>g.label==="spacing")?.values[0];c&&(r.properties.spacing=c.content);let y=t.find(g=>g.label==="gap")?.values[0];y&&(r.properties.gap=y.content);let b=t.find(g=>g.label==="align-items")?.values[0];b&&(r.properties.alignItems=b.content);let x=t.find(g=>g.label==="justify-content")?.values[0];x&&(r.properties.justifyContent=x.content);let f=t.find(g=>g.label==="overwrite-mobile");if(f){let g=f.properties,v={};for(let D of g)v[D.label]=D.values[0].content;r.propertiesMobile=v}}let i=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],s=[];for(let l of i){let c=l.properties?T(Array.isArray(l.properties.property)?l.properties.property:[l.properties.property]):[],y=d(c,"presentation");if(y!=null)switch(y){case"element":{let b=await G(l);s.push(b);break}case"block":{let b=await ce(l);b&&s.push(b);break}}}r.items=s;let o=n.find(l=>l.label==="presentation"&&l.values[0]?.content==="css")?.properties;if(o)for(let l of o)r.cssStyles.push({label:l.label,value:l.values[0].content});let a=n.find(l=>l.label==="presentation"&&l.values[0]?.content==="css-mobile")?.properties;if(a)for(let l of a)r.cssStylesMobile.push({label:l.label,value:l.values[0].content});return r.properties.sectionSidebarItems=$e(r),r}function $e(e){let r=[];for(let n of e.items)switch(n.type){case"block":{let t=$e(n);t!==null&&r.push({uuid:n.uuid,type:"block",name:null,items:t});break}case"element":{if(!n.isDisplayedInBlockSectionSidebar)continue;r.push({uuid:n.uuid,type:"element",name:n.title.label,items:null});break}}return r.length>0?r:null}function Ge(e){let n=T(e).find(A=>A.label==="presentation")?.properties;if(!n)throw new Error("Presentation property not found");let t=n.find(A=>A.label==="webUI")?.values[0]?.content;if(t==null)throw new Error("Website type not found");let i=n.find(A=>A.label==="status")?.values[0]?.content;if(i==null)throw new Error("Website status not found");let s=n.find(A=>A.label==="privacy")?.values[0]?.content;s??="public";let o=ue.safeParse({type:t,status:i,privacy:s});if(!o.success)throw new Error(`Invalid website properties: ${o.error.message}`);let a=null,l=n.find(A=>A.label==="contact");if(l){let[A,U]=(l.values[0]?.content).split(";");a={name:A,email:U??null}}let c=n.find(A=>A.label==="logo")?.values[0]?.uuid??null,y=!0,b="default",x="start",f=!0,g=!0,v=!1,D=!0,P=n.find(A=>A.label==="navbar-visible")?.values[0];P&&(y=P.content==="Yes");let u=n.find(A=>A.label==="navbar-variant")?.values[0];u&&(b=u.content);let h=n.find(A=>A.label==="navbar-alignment")?.values[0];h&&(x=h.content);let k=n.find(A=>A.label==="navbar-project-visible")?.values[0];k&&(f=k.content==="Yes");let w=n.find(A=>A.label==="footer-visible")?.values[0];w&&(g=w.content==="Yes");let C=n.find(A=>A.label==="sidebar-visible")?.values[0];C&&(v=C.content==="Yes");let m=n.find(A=>A.label==="supports-theme-toggle")?.values[0];m&&(D=m.content==="Yes");let{type:E,status:$,privacy:L}=o.data;return{type:E,privacy:L,status:$,contact:a,isHeaderDisplayed:y,headerVariant:b,headerAlignment:x,isHeaderProjectDisplayed:f,isFooterDisplayed:g,isSidebarDisplayed:v,supportsThemeToggle:D,logoUrl:c!==null?`https://ochre.lib.uchicago.edu/ochre?uuid=${c}&load`:null}}async function Le(e,r,n){if(!e.properties)throw new Error("Website properties not found");let t=Ge(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]);if(typeof e.items=="string"||!("resource"in e.items))throw new Error("Website pages not found");let i=Array.isArray(e.items.resource)?e.items.resource:[e.items.resource],s=await qe(i),o=null,a=[],l={label:"",variant:"default",properties:{isNameDisplayed:!1,isDescriptionDisplayed:!1,isDateDisplayed:!1,isCreatorsDisplayed:!1}},c="start",y="default",b=[],x=[],f=i.find(v=>(v.properties?T(Array.isArray(v.properties.property)?v.properties.property:[v.properties.property]):[]).some(P=>P.label==="presentation"&&P.values[0]?.content==="element"&&P.properties[0]?.label==="component"&&P.properties[0].values[0]?.content==="sidebar"));if(f){l.label=typeof f.identification.label=="string"||typeof f.identification.label=="number"||typeof f.identification.label=="boolean"?p(f.identification.label):S(f.identification.label);let v=f.properties?T(Array.isArray(f.properties.property)?f.properties.property:[f.properties.property]):[],D=v.find(m=>m.label==="presentation"&&m.values[0]?.content==="element")?.properties.find(m=>m.label==="component"&&m.values[0]?.content==="sidebar")?.properties??[],P=D.find(m=>m.label==="layout");P&&(c=P.values[0].content);let u=D.find(m=>m.label==="layout-mobile");u&&(y=u.values[0].content);let h=v.find(m=>m.label==="presentation"&&m.values[0].content==="css")?.properties??[];for(let m of h){let E=m.values[0].content;b.push({label:m.label,value:E})}let k=v.find(m=>m.label==="presentation"&&m.values[0].content==="css-mobile")?.properties??[];for(let m of k){let E=m.values[0].content;x.push({label:m.label,value:E})}let w=v.find(m=>m.label==="presentation"&&m.values[0].content==="title")?.properties;if(w){let m=d(w,"variant");m&&(l.variant=m);let E=w.filter($=>$.label==="display");E.length>0&&(l.properties.isNameDisplayed=E.some($=>$.values[0].content==="name"),l.properties.isDescriptionDisplayed=E.some($=>$.values[0].content==="description"),l.properties.isDateDisplayed=E.some($=>$.values[0].content==="date"),l.properties.isCreatorsDisplayed=E.some($=>$.values[0].content==="creators"))}let C=f.resource?Array.isArray(f.resource)?f.resource:[f.resource]:[];for(let m of C){let E=await G(m);a.push(E)}}a.length>0&&(o={elements:a,title:l,layout:c,mobileLayout:y,cssStyles:b,cssStylesMobile:x});let g=null;if(e.searchOptions){let v=[];for(let D of s)for(let P of D.items)P.type==="element"&&P.component==="collection"&&v.push(P.collectionId);g={uuids:v,properties:{metadataUuids:[...e.searchOptions.metadata?.option??[]],searchUuids:[...e.searchOptions.filters?.option??[]],labelUuids:[...e.searchOptions.labels?.option??[]]}}}return{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:I(e.identification),project:{name:p(r),website:n!==null?p(n):null},creators:e.creators?W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:B(e.availability),pages:s,sidebar:o,properties:t,collectionOptions:g}}async function yt(e,r,n,t){try{let{uuid:i,filter:s,page:o,perPage:a}=ye.parse({uuid:e,filter:r,page:n,perPage:t}),l=await fetch(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
5
5
  for $q in input()/ochre[@uuid='${i}']
6
6
  let $filtered := $q//items/resource[contains(lower-case(identification/label), lower-case('${s}'))]
7
7
  let $maxLength := count($filtered)
@@ -10,4 +10,4 @@ ${JSON.stringify(e.content)}.`);return _(t)}}else return _(e.content);default:re
10
10
  {$q/metadata/item}
11
11
  {$filtered[position() >= ${((o-1)*a+1).toString()} and position() < ${(o*a+1).toString()}]}
12
12
  </gallery>
13
- `)}&format=json`);if(!l.ok)throw new Error("Error fetching gallery items, please try again later.");let c=await l.json();if(!("gallery"in c.result))throw new Error("Failed to fetch gallery");let y=I(c.result.gallery.item.identification),b=I(c.result.gallery.project.identification);return{item:{identification:y,projectIdentification:b,resources:H(c.result.gallery.resource?Array.isArray(c.result.gallery.resource)?c.result.gallery.resource:[c.result.gallery.resource]:[]),maxLength:c.result.gallery.maxLength},error:null}}catch(i){return console.error(i),{item:null,error:i instanceof Error?i.message:"Failed to fetch gallery"}}}async function bt(e){try{let r=await fetch(`https://ochre.lib.uchicago.edu/ochre?xquery=for $q in input()/ochre[tree[@type='lesson'][identification/abbreviation='${e.toLocaleLowerCase("en-US")}']] return $q&format=json`);if(!r.ok)throw new Error("Failed to fetch website");let n=await r.json();if(!("ochre"in n.result)||!("tree"in n.result.ochre))throw new Error("Failed to fetch website");let t=n.result.ochre.metadata.project?.identification?I(n.result.ochre.metadata.project.identification):null;return await Le(n.result.ochre.tree,t?.label??"",n.result.ochre.metadata.project?.identification.website??null)}catch(r){return console.error(r),null}}export{ve as fetchByUuid,yt as fetchGallery,we as fetchItem,bt as fetchWebsite,Fe as filterProperties,We as getAllPropertyLabels,J as getPropertyByLabel,d as getPropertyValueByLabel,ge as getPropertyValuesByLabel,q as parseBibliographies,Z as parseBibliography,ne as parseConcept,Ee as parseConcepts,V as parseContext,oe as parseCoordinates,se as parseDocument,F as parseEmail,De as parseEvents,p as parseFakeString,I as parseIdentification,Ie as parseImage,Me as parseImageMap,He as parseInterpretations,je as parseLanguages,B as parseLicense,Ue as parseLink,U as parseLinks,Se as parseMetadata,le as parseNotes,xe as parseObservation,Ve as parseObservations,X as parsePeriod,Y as parsePeriods,R as parsePerson,W as parsePersons,T as parseProperties,Ne as parseProperty,ee as parsePropertyValue,Oe as parsePropertyValues,te as parseResource,H as parseResources,ke as parseSet,re as parseSpatialUnit,Te as parseSpatialUnits,S as parseStringContent,Q as parseStringDocumentItem,_ as parseStringItem,Pe as parseTree,Le as parseWebsite};
13
+ `)}&format=json`);if(!l.ok)throw new Error("Error fetching gallery items, please try again later.");let c=await l.json();if(!("gallery"in c.result))throw new Error("Failed to fetch gallery");let y=I(c.result.gallery.item.identification),b=I(c.result.gallery.project.identification);return{item:{identification:y,projectIdentification:b,resources:H(c.result.gallery.resource?Array.isArray(c.result.gallery.resource)?c.result.gallery.resource:[c.result.gallery.resource]:[]),maxLength:c.result.gallery.maxLength},error:null}}catch(i){return console.error(i),{item:null,error:i instanceof Error?i.message:"Failed to fetch gallery"}}}async function bt(e){try{let r=await fetch(`https://ochre.lib.uchicago.edu/ochre?xquery=for $q in input()/ochre[tree[@type='lesson'][identification/abbreviation='${e.toLocaleLowerCase("en-US")}']] return $q&format=json`);if(!r.ok)throw new Error("Failed to fetch website");let n=await r.json();if(!("ochre"in n.result)||!("tree"in n.result.ochre))throw new Error("Failed to fetch website");let t=n.result.ochre.metadata.project?.identification?I(n.result.ochre.metadata.project.identification):null;return await Le(n.result.ochre.tree,t?.label??"",n.result.ochre.metadata.project?.identification.website??null)}catch(r){return console.error(r),null}}export{ve as fetchByUuid,yt as fetchGallery,we as fetchItem,bt as fetchWebsite,Fe as filterProperties,J as getPropertyByLabel,d as getPropertyValueByLabel,ge as getPropertyValuesByLabel,We as getUniqueProperties,q as parseBibliographies,Z as parseBibliography,ne as parseConcept,Ee as parseConcepts,V as parseContext,oe as parseCoordinates,se as parseDocument,F as parseEmail,De as parseEvents,p as parseFakeString,I as parseIdentification,Ie as parseImage,Me as parseImageMap,He as parseInterpretations,Ue as parseLanguages,B as parseLicense,je as parseLink,j as parseLinks,Se as parseMetadata,le as parseNotes,xe as parseObservation,Ve as parseObservations,X as parsePeriod,Y as parsePeriods,R as parsePerson,W as parsePersons,T as parseProperties,Ne as parseProperty,ee as parsePropertyValue,Oe as parsePropertyValues,te as parseResource,H as parseResources,ke as parseSet,re as parseSpatialUnit,Te as parseSpatialUnits,S as parseStringContent,Q as parseStringDocumentItem,_ as parseStringItem,Pe as parseTree,Le as parseWebsite};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalculture/ochre-sdk",
3
- "version": "0.7.10",
3
+ "version": "0.7.11",
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",
@@ -52,7 +52,7 @@
52
52
  "eslint": "^9.26.0",
53
53
  "eslint-plugin-unused-imports": "^4.1.4",
54
54
  "prettier": "^3.5.3",
55
- "terser": "^5.39.0",
55
+ "terser": "^5.39.1",
56
56
  "tsup": "^8.4.0",
57
57
  "typescript": "^5.8.3",
58
58
  "vitest": "^3.1.3"