@digitalculture/ochre-sdk 0.7.1 → 0.7.2
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 +5 -5
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +5 -5
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";var oe=Object.defineProperty;var
|
|
2
|
-
${n}`;break}case"trailing":{n=`${n} `;break}case"leading":{n=` ${n}`;break}}return n.replaceAll("'","'")}function
|
|
3
|
-
`:"";if("links"in e){let t="";typeof e.string=="object"?t=w(e.string):t=
|
|
4
|
-
${JSON.stringify(e.content)}.`);return K(t)}}else return K(e.content);default:return String(e.content).replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}}function _(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){try{let[n,t]=await ce(e);if(n!==null)throw new Error(n);let i=_(Object.keys(t.ochre)),s;switch(i){case"resource":{if(!("resource"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'resource' key");s=Z(t.ochre.resource);break}case"spatialUnit":{if(!("spatialUnit"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'spatialUnit' key");s=ee(t.ochre.spatialUnit);break}case"concept":{if(!("concept"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'concept' key");s=te(t.ochre.concept);break}case"period":{if(!("period"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'period' key");s=Q(t.ochre.period);break}case"bibliography":{if(!("bibliography"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'bibliography' key");s=R(t.ochre.bibliography);break}case"person":{if(!("person"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'person' key");s=z(t.ochre.person);break}case"propertyValue":{if(!("propertyValue"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'propertyValue' key");s=X(t.ochre.propertyValue);break}case"set":{if(!("set"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'set' key");s=de(t.ochre.set);break}case"tree":{if(!("tree"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'tree' key");s=fe(t.ochre.tree);break}default:throw new Error("Invalid category")}let o=ue(t.ochre.metadata),a={uuid:t.ochre.uuidBelongsTo,abbreviation:f(t.ochre.belongsTo)};return{error:null,metadata:o,belongsTo:a,item:s,category:r}}catch(n){return{error:n instanceof Error?n.message:"Unknown error",metadata:void 0,belongsTo:void 0,item:void 0,category:void 0}}}function v(e){try{let r={label:["string","number","boolean"].includes(typeof e.label)?f(e.label):w(e.label),abbreviation:""};for(let n of Object.keys(e).filter(t=>t!=="label"))r[n]=w(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=>w(r)):[w(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=w(e.item.label)),e.item.abbreviation&&(s=w(e.item.abbreviation)),r={label:i,abbreviation:s}}else r=v(e.item.identification);let n=null,t=e.project?.identification?v(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:w(e.dataset),publisher:w(e.publisher),languages:Fe(e.language),identifier:w(e.identifier),description:w(e.description)}}function ye(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,number:e.n,content:f(e.content)}}function U(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 F(e){return typeof e.license=="string"?null:{content:e.license.content,url:e.license.target}}function z(e){return{uuid:e.uuid,category:"person",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type??null,date:e.date!=null?new Date(e.date):null,identification:e.identification?v(e.identification):null,content:e.content!=null?f(e.content):null}}function L(e){let r=[];for(let n of e)r.push(z(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?f(i.content):null,href:"href"in i&&i.href!=null?i.href:null,uuid:i.uuid,type:i.type??null,identification:i.identification?v(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(...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+=W(f(i.string));else{let s=Array.isArray(i.string)?i.string:[i.string];for(let o of s)n+=J(o,t)}return{content:n,footnotes:t}}function me(e){return{publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,identification:e.identification?v(e.identification):null,url:e.href??(e.htmlImgSrcPrefix==null&&e.content!=null?f(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?f(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=W(f(o.string)):i=W(re(o).content),n.push({number:t.noteNo,title:o.title!=null?f(o.title):null,content:i})}return n}function he(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?f(e.coord.coordLabel):null}}function be(e){return{number:e.observationNo,date:e.date!=null?new Date(e.date):null,observers:e.observers!=null?f(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 je(e){let r=[];for(let n of e)r.push(be(n));return r}function Ue(e){let r=[];for(let n of e)r.push({date:n.dateTime!=null?new Date(n.dateTime):null,label:w(n.label),agent:n.agent?{uuid:n.agent.uuid,content:f(n.agent.content)}:null});return r}function Ve(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=f(i),{content:s,booleanValue:o,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(w({content:i.content})):null;break}default:{"slug"in i&&i.slug!=null?s=f(i.slug):i.content!=null&&(s=w({content:i.content})),i.type==="boolean"&&(o=i.booleanValue??null);break}}let a="string";if(i.type!=null){let{data:c,error:g}=Te.safeParse(i.type);if(g)throw new Error(`Invalid property value content type: "${i.type}"`);a=c}return{content:s,booleanValue:o,type:a,category:i.category??"value",uuid:i.uuid??null,publicationDateTime:i.publicationDateTime!=null?new Date(i.publicationDateTime):null,unit:i.unit??null}}});return{label:w(e.label,r).replace(/\s*\.{3}$/,"").trim(),values:t,comment:e.comment!=null?f(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(Ve(t,r));return n}function Ne(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 He(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:f(t.title),shape:t.shape==="rect"?"rectangle":"polygon",coords:t.coords.split(",").map(i=>Number.parseInt(i))});return r}function Q(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:v(e.identification),description:e.description?w(e.description):null}}function Y(e){let r=[];for(let n of e)r.push(Q(n));return r}function R(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:v(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?v(e.identification):null,projectIdentification:e.project?.identification?v(e.project.identification):null,context:e.context?U(e.context):null,citation:{format:e.citationFormat??null,short:e.citationFormatSpan?f("default:span"in e.citationFormatSpan?e.citationFormatSpan["default:span"].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?f("default:div"in e.referenceFormatDiv?e.referenceFormatDiv["default:div"]["default:div"].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?L(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:f(e.entryInfo.startIssue),startVolume:f(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?L(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(R(n));return r}function X(e){return{uuid:e.uuid,category:"propertyValue",n:e.n,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,context:e.context?U(e.context):null,availability:e.availability?F(e.availability):null,identification:v(e.identification),date:e.date?new Date(e.date):null,creators:e.creators?L(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],description:e.description?["string","number","boolean"].includes(typeof e.description)?f(e.description):w(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(X(n));return r}function fe(e){let r=[];e.creators&&(r=L(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=V(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource])),typeof e.items!="string"&&"spatialUnit"in e.items&&(i=we(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit])),typeof e.items!="string"&&"concept"in e.items&&(s=ve(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=L(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:v(e.identification),creators:r,license:F(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 de(e){if(typeof e.items=="string")throw new TypeError("Invalid OCHRE data: Set has no items");let r=_(Object.keys(e.items)),n=[];switch(r){case"resource":{if(!("resource"in e.items))throw new Error("Invalid OCHRE data: Set has no resources");n=V(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");n=we(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");n=ve(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");n=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");n=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");n=L(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");n=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:F(e.availability),identification:v(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?["string","number","boolean"].includes(typeof e.description)?f(e.description):w(e.description):"",creators:e.creators?L(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],type:e.type,number:e.n,items:n}}function Z(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?U(e.context):null,license:"availability"in e&&e.availability?F(e.availability):null,copyright:"copyright"in e&&e.copyright!=null?f(e.copyright):null,identification:v(e.identification),date:e.date!=null?new Date(e.date):null,image:e.image?me(e.image):null,creators:e.creators?L(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)?f(e.description):w(e.description):"",document:e.document&&"content"in e.document?re(e.document.content):null,href:e.href??null,imageMap:e.imagemap?He(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?V(Array.isArray(e.resource)?e.resource:[e.resource]):[]}}function V(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:"spatialUnit",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type,number:e.n,context:"context"in e&&e.context?U(e.context):null,license:"availability"in e&&e.availability?F(e.availability):null,identification:v(e.identification),image:e.image?me(e.image):null,description:e.description?["string","number","boolean"].includes(typeof e.description)?f(e.description):w(e.description):"",coordinates:e.coordinates?he(e.coordinates):e.coordinate?he(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?Ue(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 we(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(ee(t));return r}function te(e){return{uuid:e.uuid,category:"concept",publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,number:e.n,license:"availability"in e&&e.availability?F(e.availability):null,context:"context"in e&&e.context?U(e.context):null,identification:v(e.identification),interpretations:Ne(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation])}}var ge=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 Me(t);o&&n.push(o);break}case"block":{let o=await Pe(t);o&&n.push(o);break}}return n};function ve(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(te(t));return r}async function Re(e,r){let n=Ie.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"blog":{let a=i.find(l=>l.category==="tree");if(!a)throw new Error(`Blog link not found for the following component: \u201C${n}\u201D`);t.blogId=a.uuid;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 g=null,m=d(e.properties,"icon");m!==null&&(g=m),t.variant=a,t.href=c,t.isExternal=l,t.label=["string","number","boolean"].includes(typeof r.identification.label)?f(r.identification.label):w(r.identification.label),t.icon=g;break}case"collection":{let a=i.find(I=>I.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 g=!1,m=d(e.properties,"show-count");m!==null&&(g=m==="Yes");let P=!1,y=d(e.properties,"is-searchable");y!==null&&(P=y==="Yes");let h=d(e.properties,"layout");h??="image-start",t.collectionId=a.uuid,t.variant=l,t.itemVariant=c,t.isSearchable=P,t.showCount=g,t.layout=h;break}case"empty-space":{let a=d(e.properties,"height"),l=d(e.properties,"width");t.height=a,t.width=l;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(g=>g.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 $ of s)a.push({url:`https://ochre.lib.uchicago.edu/ochre?uuid=${$.uuid}&load`,label:$.identification?.label??null,width:$.image?.width??0,height:$.image?.height??0});let l=d(e.properties,"variant");l??="default";let c=d(e.properties,"layout-caption");c??="bottom";let g=null,m=d(e.properties,"width");m!==null&&(typeof m=="number"?g=m:typeof m=="string"&&(g=Number.parseFloat(m)));let P=null,y=d(e.properties,"height");y!==null&&(typeof y=="number"?P=y:typeof y=="string"&&(P=Number.parseFloat(y)));let h=!0,I=d(e.properties,"is-full-width");I!==null&&(h=I==="Yes");let S=!0,b=d(e.properties,"is-full-height");b!==null&&(S=b==="Yes");let p=d(e.properties,"image-quality");p??="high";let k=d(e.properties,"caption-source");k??="name";let O=d(e.properties,"alt-text-source");O??="name";let C=!1,u=d(e.properties,"is-transparent");u!==null&&(C=u==="Yes");let D=!1,E=d(e.properties,"is-cover");E!==null&&(D=E==="Yes");let N=null;if(a.length>1){let $=G(e.properties,"variant"),H=5;if($&&$.values[0].content==="carousel"){let B=d($.properties,"seconds-per-image");B!==null&&(typeof B=="number"?H=B:typeof B=="string"&&(H=Number.parseFloat(B)))}N={secondsPerImage:H}}t.images=a,t.variant=l,t.width=g,t.height=P,t.isFullWidth=h,t.isFullHeight=S,t.imageQuality=p,t.captionLayout=c,t.captionSource=k,t.altTextSource=O,t.isTransparentBackground=C,t.isCover=D,t.carouselOptions=N;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 ge(Array.isArray(r.resource)?r.resource:[r.resource],"element"):[];t.columns=a;break}case"n-rows":{let a=r.resource?await ge(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${w(r.identification.label)}\u201D`);break}}return t}async function ie(e){let r=v(e.identification),t=(e.properties?.property?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]).find(b=>b.label==="presentation");if(!t)throw new Error(`Presentation property not found for element \u201C${r.label}\u201D`);let i=t.properties.find(b=>b.label==="component");if(!i)throw new Error(`Component for element \u201C${r.label}\u201D not found`);let s=await Re(i,e),o=e.properties?.property?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],a=o.find(b=>b.label==="presentation"&&b.values[0].content==="css")?.properties??[],l=[];for(let b of a){let p=b.values[0].content;l.push({label:b.label,value:p})}let c=o.find(b=>b.label==="presentation"&&b.values[0].content==="css-mobile")?.properties??[],g=[];for(let b of c){let p=b.values[0].content;g.push({label:b.label,value:p})}let m=o.find(b=>b.label==="presentation"&&b.values[0].content==="title")?.properties,P="default",y=!1,h=!1,I=!1,S=!1;if(m){let b=d(m,"variant");b&&(P=b);let p=m.filter(k=>k.label==="display");p.length>0&&(y=p.some(k=>k.values[0].content==="name"),h=p.some(k=>k.values[0].content==="description"),I=p.some(k=>k.values[0].content==="date"),S=p.some(k=>k.values[0].content==="creators"))}return{uuid:e.uuid,type:"element",title:{label:r.label,variant:P,properties:{isNameDisplayed:y,isDescriptionDisplayed:h,isDateDisplayed:I,isCreatorsDisplayed:S}},cssStyles:l,cssStylesMobile:g,...s}}async function Me(e){let r=e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];if(r.length===0||r.find(p=>p.label==="presentation")?.values[0]?.content!=="page")return null;let n=v(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(p=>p.type==="image"||p.type==="IIIF"),o=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],a=[];for(let p of o){let k=p.properties?T(Array.isArray(p.properties.property)?p.properties.property:[p.properties.property]):[],O=d(k,"presentation");if(O!=null)switch(O){case"element":{let C=await ie(p);a.push(C);break}case"block":{let C=await Pe(p);C&&a.push(C);break}}}let l=e.resource?await ge(Array.isArray(e.resource)?e.resource:[e.resource],"page"):[],c=!0,g="default",m="default",P=!0,y=r.find(p=>p.label==="presentation"&&p.values[0]?.content==="page")?.properties;if(y){let p=y.find(u=>u.label==="header")?.values[0];p&&(c=p.content==="Yes");let k=y.find(u=>u.label==="width")?.values[0];k&&(g=k.content);let O=y.find(u=>u.label==="variant")?.values[0];O&&(m=O.content);let C=y.find(u=>u.label==="sidebar-visible")?.values[0];C&&(P=C.content==="Yes")}let h=r.find(p=>p.label==="presentation"&&p.values[0]?.content==="css")?.properties,I=[];if(h)for(let p of h)I.push({label:p.label,value:p.values[0].content});let S=r.find(p=>p.label==="presentation"&&p.values[0]?.content==="css-mobile")?.properties,b=[];if(S)for(let p of S)b.push({label:p.label,value:p.values[0].content});return{title:n.label,slug:t,items:a,properties:{displayedInHeader:c,width:g,variant:m,backgroundImageUrl:s?`https://ochre.lib.uchicago.edu/ochre?uuid=${s.uuid}&load`:null,isSidebarDisplayed:P,cssStyles:I,cssStylesMobile:b},webpages:l}}async function Xe(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n){let i=await Me(t);i&&r.push(i)}return r}async function Pe(e){let r={uuid:e.uuid,type:"block",layout:"vertical",items:[],properties:{spacing:void 0,gap:void 0,alignItems:"start",justifyContent:"stretch"},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(h=>h.label==="layout")?.values[0];l&&(r.layout=l.content);let c=t.find(h=>h.label==="spacing")?.values[0];c&&(r.properties.spacing=c.content);let g=t.find(h=>h.label==="gap")?.values[0];g&&(r.properties.gap=g.content);let m=t.find(h=>h.label==="align-items")?.values[0];m&&(r.properties.alignItems=m.content);let P=t.find(h=>h.label==="justify-content")?.values[0];P&&(r.properties.justifyContent=P.content);let y=t.find(h=>h.label==="overwrite-mobile");if(y){let h=y.properties,I={};for(let S of h)I[S.label]=S.values[0].content;r.propertiesMobile=I}}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]):[],g=d(c,"presentation");if(g!=null)switch(g){case"element":{let m=await ie(l);s.push(m);break}case"block":{let m=await Pe(l);m&&s.push(m);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}function Ze(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=xe.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,Ye]=(l.values[0]?.content).split(";");a={name:A,email:Ye??null}}let c=n.find(A=>A.label==="logo")?.values[0]?.uuid??null,g=!0,m="default",P="start",y=!0,h=!0,I=!1,S=null,b=!0,p=n.find(A=>A.label==="navbar-visible")?.values[0];p&&(g=p.content==="Yes");let k=n.find(A=>A.label==="navbar-variant")?.values[0];k&&(m=k.content);let O=n.find(A=>A.label==="navbar-alignment")?.values[0];O&&(P=O.content);let C=n.find(A=>A.label==="navbar-project-visible")?.values[0];C&&(y=C.content==="Yes");let u=n.find(A=>A.label==="footer-visible")?.values[0];u&&(h=u.content==="Yes");let D=n.find(A=>A.label==="sidebar-visible")?.values[0];D&&(I=D.content==="Yes");let E=n.find(A=>A.label==="search-collection")?.values[0];E&&(S=E.uuid);let N=n.find(A=>A.label==="supports-theme-toggle")?.values[0];N&&(b=N.content==="Yes");let{type:$,status:H,privacy:B}=o.data;return{type:$,privacy:B,status:H,contact:a,isHeaderDisplayed:g,headerVariant:m,headerAlignment:P,isHeaderProjectDisplayed:y,isFooterDisplayed:h,isSidebarDisplayed:I,supportsThemeToggle:b,searchCollectionUuid:S,logoUrl:c!==null?`https://ochre.lib.uchicago.edu/ochre?uuid=${c}&load`:null}}async function Se(e,r,n){if(!e.properties)throw new Error("Website properties not found");let t=Ze(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 Xe(i),o=null,a=[],l={label:"",variant:"default",properties:{isNameDisplayed:!1,isDescriptionDisplayed:!1,isDateDisplayed:!1,isCreatorsDisplayed:!1}},c="start",g="default",m=[],P=[],y=i.find(h=>(h.properties?T(Array.isArray(h.properties.property)?h.properties.property:[h.properties.property]):[]).some(S=>S.label==="presentation"&&S.values[0]?.content==="element"&&S.properties[0]?.label==="component"&&S.properties[0].values[0]?.content==="sidebar"));if(y){l.label=typeof y.identification.label=="string"||typeof y.identification.label=="number"||typeof y.identification.label=="boolean"?f(y.identification.label):w(y.identification.label);let h=y.properties?T(Array.isArray(y.properties.property)?y.properties.property:[y.properties.property]):[],I=h.find(u=>u.label==="presentation"&&u.values[0]?.content==="element")?.properties.find(u=>u.label==="component"&&u.values[0]?.content==="sidebar")?.properties??[],S=I.find(u=>u.label==="layout");S&&(c=S.values[0].content);let b=I.find(u=>u.label==="layout-mobile");b&&(g=b.values[0].content);let p=h.find(u=>u.label==="presentation"&&u.values[0].content==="css")?.properties??[];for(let u of p){let D=u.values[0].content;m.push({label:u.label,value:D})}let k=h.find(u=>u.label==="presentation"&&u.values[0].content==="css-mobile")?.properties??[];for(let u of k){let D=u.values[0].content;P.push({label:u.label,value:D})}let O=h.find(u=>u.label==="presentation"&&u.values[0].content==="title")?.properties;if(O){let u=d(O,"variant");u&&(l.variant=u);let D=O.filter(E=>E.label==="display");D.length>0&&(l.properties.isNameDisplayed=D.some(E=>E.values[0].content==="name"),l.properties.isDescriptionDisplayed=D.some(E=>E.values[0].content==="description"),l.properties.isDateDisplayed=D.some(E=>E.values[0].content==="date"),l.properties.isCreatorsDisplayed=D.some(E=>E.values[0].content==="creators"))}let C=y.resource?Array.isArray(y.resource)?y.resource:[y.resource]:[];for(let u of C){let D=await ie(u);a.push(D)}}return a.length>0&&(o={elements:a,title:l,layout:c,mobileLayout:g,cssStyles:m,cssStylesMobile:P}),{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:v(e.identification),project:{name:f(r),website:n!==null?f(n):null},creators:e.creators?L(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:F(e.availability),pages:s,sidebar:o,properties:t}}async function et(e,r,n,t){try{let{uuid:i,filter:s,page:o,perPage:a}=De.parse({uuid:e,filter:r,page:n,perPage:t}),l=await fetch(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
|
|
1
|
+
"use strict";var oe=Object.defineProperty;var Ge=Object.getOwnPropertyDescriptor;var Ke=Object.getOwnPropertyNames;var Je=Object.prototype.hasOwnProperty;var _e=(e,r)=>{for(var n in r)oe(e,n,{get:r[n],enumerable:!0})},ze=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of Ke(r))!Je.call(e,i)&&i!==n&&oe(e,i,{get:()=>r[i],enumerable:!(t=Ge(r,i))||t.enumerable});return e};var Qe=e=>ze(oe({},"__esModule",{value:!0}),e);var nt={};_e(nt,{fetchByUuid:()=>ce,fetchGallery:()=>tt,fetchItem:()=>pe,fetchWebsite:()=>rt,filterProperties:()=>Le,getAllPropertyLabels:()=>$e,getPropertyByLabel:()=>G,getPropertyValueByLabel:()=>y,getPropertyValuesByLabel:()=>se,parseBibliographies:()=>q,parseBibliography:()=>R,parseConcept:()=>te,parseConcepts:()=>ve,parseContext:()=>U,parseCoordinates:()=>he,parseDocument:()=>re,parseEmail:()=>W,parseEvents:()=>Ue,parseFakeString:()=>u,parseIdentification:()=>P,parseImage:()=>me,parseImageMap:()=>He,parseInterpretations:()=>Ne,parseLanguages:()=>Fe,parseLicense:()=>F,parseLink:()=>Be,parseLinks:()=>j,parseMetadata:()=>ue,parseNotes:()=>ne,parseObservation:()=>ge,parseObservations:()=>je,parsePeriod:()=>Q,parsePeriods:()=>Y,parsePerson:()=>z,parsePersons:()=>L,parseProperties:()=>T,parseProperty:()=>Ve,parsePropertyValue:()=>X,parsePropertyValues:()=>Ae,parseResource:()=>Z,parseResources:()=>V,parseSet:()=>fe,parseSpatialUnit:()=>ee,parseSpatialUnits:()=>we,parseStringContent:()=>w,parseStringDocumentItem:()=>J,parseStringItem:()=>K,parseTree:()=>de,parseWebsite:()=>Pe});module.exports=Qe(nt);var x=require("zod"),ke=x.z.string().uuid({message:"Invalid UUID provided"}),Ie=x.z.object({type:x.z.enum(["traditional","digital-collection","plum","cedar","elm","maple","oak","palm"],{message:"Invalid website type"}),status:x.z.enum(["development","preview","production"],{message:"Invalid website status"}),privacy:x.z.enum(["public","password","private"],{message:"Invalid website privacy"})}),xe=x.z.enum(["annotated-document","annotated-image","bibliography","blog","button","collection","empty-space","filter-categories","iframe","iiif-viewer","image","image-gallery","n-columns","n-rows","network-graph","search-bar","table","text","timeline","video"],{message:"Invalid component"}),ae=x.z.enum(["resource","spatialUnit","concept","period","bibliography","person","propertyValue","set","tree"]),De=x.z.enum(["string","integer","decimal","boolean","date","dateTime","time","coordinate","IDREF"]),Te=x.z.object({uuid:x.z.string().uuid({message:"Invalid UUID"}),filter:x.z.string().optional(),page:x.z.number().positive({message:"Page must be positive"}),perPage:x.z.number().positive({message:"Per page must be positive"})}).strict(),Oe=x.z.string().transform(e=>e.split(" ")).pipe(x.z.array(x.z.enum(["bold","italic","underline"]))),Ce=x.z.string().transform(e=>e.split(" ")).pipe(x.z.array(x.z.enum(["newline","trailing","leading"]))),Ee=x.z.string().email({message:"Invalid email"});var M={searchNestedProperties:!1};function G(e,r,n=M){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=G(s.properties,r,{searchNestedProperties:t});if(o)return o}}return null}function se(e,r,n=M){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 y(e,r,n=M){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=y(s.properties,r,{searchNestedProperties:t});if(o!==null)return o}}return null}function $e(e,r=M){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=M){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 Re(e,r){return e.find(t=>t.lang===r)??null}function W(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(Ee.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=Oe.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("'","'")}function le(e,r){let n=e,t=Ce.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
|
+
${n}`;break}case"trailing":{n=`${n} `;break}case"leading":{n=` ${n}`;break}}return n.replaceAll("'","'")}function u(e){let r="";return typeof e=="string"?r=e:typeof e=="number"?r=e.toString():typeof e=="boolean"&&(r=e?"Yes":"No"),r.replaceAll("'","'").replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}function K(e){let r="";switch(typeof e.string){case"string":{r=e.string;break}case"number":case"boolean":{r=u(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+=u(t);else{let i=t.rend!=null?We(u(t.content),t.rend):u(t.content),s=t.whitespace!=null?le(i,t.whitespace):i;r+=s}break}default:{r="";break}}return r.replaceAll("'","'").replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}function J(e,r){if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return W(u(e));if("whitespace"in e&&!("content"in e)&&!("string"in e))return e.whitespace==="newline"?`
|
|
3
|
+
`:"";if("links"in e){let t="";typeof e.string=="object"?t=w(e.string):t=u(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=u(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)?u(o.identification.label):w(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+=J(i,r);return"whitespace"in e&&e.whitespace!=null&&(n=le(W(n),e.whitespace)),n.replaceAll("'","'").replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}else n=u(e.content),e.rend!=null&&(n=We(W(n),e.rend)),e.whitespace!=null&&(n=le(W(n),e.whitespace));return n.replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}function w(e,r="eng"){switch(typeof e.content){case"string":case"number":case"boolean":return u(e.content);case"object":if(Array.isArray(e.content)){let n=Re(e.content,r);if(n)return K(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 K(t)}}else return K(e.content);default:return String(e.content).replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}}function _(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){try{let[n,t]=await ce(e);if(n!==null)throw new Error(n);let i=_(Object.keys(t.ochre)),s;switch(i){case"resource":{if(!("resource"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'resource' key");s=Z(t.ochre.resource);break}case"spatialUnit":{if(!("spatialUnit"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'spatialUnit' key");s=ee(t.ochre.spatialUnit);break}case"concept":{if(!("concept"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'concept' key");s=te(t.ochre.concept);break}case"period":{if(!("period"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'period' key");s=Q(t.ochre.period);break}case"bibliography":{if(!("bibliography"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'bibliography' key");s=R(t.ochre.bibliography);break}case"person":{if(!("person"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'person' key");s=z(t.ochre.person);break}case"propertyValue":{if(!("propertyValue"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'propertyValue' key");s=X(t.ochre.propertyValue);break}case"set":{if(!("set"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'set' key");s=fe(t.ochre.set);break}case"tree":{if(!("tree"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'tree' key");s=de(t.ochre.tree);break}default:throw new Error("Invalid category")}let o=ue(t.ochre.metadata),a={uuid:t.ochre.uuidBelongsTo,abbreviation:u(t.ochre.belongsTo)};return{error:null,metadata:o,belongsTo:a,item:s,category:r}}catch(n){return{error:n instanceof Error?n.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)?u(e.label):w(e.label),abbreviation:""};for(let n of Object.keys(e).filter(t=>t!=="label"))r[n]=w(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=>w(r)):[w(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=w(e.item.label)),e.item.abbreviation&&(s=w(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:w(e.dataset),publisher:w(e.publisher),languages:Fe(e.language),identifier:w(e.identifier),description:w(e.description)}}function ye(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,number:e.n,content:u(e.content)}}function U(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 F(e){return typeof e.license=="string"?null:{content:e.license.content,url:e.license.target}}function z(e){return{uuid:e.uuid,category:"person",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type??null,date:e.date!=null?new Date(e.date):null,identification:e.identification?P(e.identification):null,content:e.content!=null?u(e.content):null}}function L(e){let r=[];for(let n of e)r.push(z(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?u(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?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(...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+=W(u(i.string));else{let s=Array.isArray(i.string)?i.string:[i.string];for(let o of s)n+=J(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?u(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?u(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=W(u(o.string)):i=W(re(o).content),n.push({number:t.noteNo,title:o.title!=null?u(o.title):null,content:i})}return n}function he(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?u(e.coord.coordLabel):null}}function ge(e){return{number:e.observationNo,date:e.date!=null?new Date(e.date):null,observers:e.observers!=null?u(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 je(e){let r=[];for(let n of e)r.push(ge(n));return r}function Ue(e){let r=[];for(let n of e)r.push({date:n.dateTime!=null?new Date(n.dateTime):null,label:w(n.label),agent:n.agent?{uuid:n.agent.uuid,content:u(n.agent.content)}:null});return r}function Ve(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=u(i),{content:s,booleanValue:o,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(w({content:i.content})):null;break}default:{"slug"in i&&i.slug!=null?s=u(i.slug):i.content!=null&&(s=w({content:i.content})),i.type==="boolean"&&(o=i.booleanValue??null);break}}let a="string";if(i.type!=null){let{data:c,error:m}=De.safeParse(i.type);if(m)throw new Error(`Invalid property value content type: "${i.type}"`);a=c}return{content:s,booleanValue:o,type:a,category:i.category??"value",uuid:i.uuid??null,publicationDateTime:i.publicationDateTime!=null?new Date(i.publicationDateTime):null,unit:i.unit??null}}});return{label:w(e.label,r).replace(/\s*\.{3}$/,"").trim(),values:t,comment:e.comment!=null?u(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(Ve(t,r));return n}function Ne(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 He(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:u(t.title),shape:t.shape==="rect"?"rectangle":"polygon",coords:t.coords.split(",").map(i=>Number.parseInt(i))});return r}function Q(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?w(e.description):null}}function Y(e){let r=[];for(let n of e)r.push(Q(n));return r}function R(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?U(e.context):null,citation:{format:e.citationFormat??null,short:e.citationFormatSpan?u("default:span"in e.citationFormatSpan?e.citationFormatSpan["default:span"].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?u("default:div"in e.referenceFormatDiv?e.referenceFormatDiv["default:div"]["default:div"].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?L(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:u(e.entryInfo.startIssue),startVolume:u(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?L(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(R(n));return r}function X(e){return{uuid:e.uuid,category:"propertyValue",n:e.n,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,context:e.context?U(e.context):null,availability:e.availability?F(e.availability):null,identification:P(e.identification),date:e.date?new Date(e.date):null,creators:e.creators?L(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],description:e.description?["string","number","boolean"].includes(typeof e.description)?u(e.description):w(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(X(n));return r}function de(e){let r=[];e.creators&&(r=L(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=V(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource])),typeof e.items!="string"&&"spatialUnit"in e.items&&(i=we(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit])),typeof e.items!="string"&&"concept"in e.items&&(s=ve(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=L(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:F(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){if(typeof e.items=="string")throw new TypeError("Invalid OCHRE data: Set has no items");let r=_(Object.keys(e.items)),n=[];switch(r){case"resource":{if(!("resource"in e.items))throw new Error("Invalid OCHRE data: Set has no resources");n=V(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");n=we(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");n=ve(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");n=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");n=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");n=L(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");n=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:F(e.availability),identification:P(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?["string","number","boolean"].includes(typeof e.description)?u(e.description):w(e.description):"",creators:e.creators?L(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],type:e.type,number:e.n,items:n}}function Z(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?U(e.context):null,license:"availability"in e&&e.availability?F(e.availability):null,copyright:"copyright"in e&&e.copyright!=null?u(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?L(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)?u(e.description):w(e.description):"",document:e.document&&"content"in e.document?re(e.document.content):null,href:e.href??null,imageMap:e.imagemap?He(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?V(Array.isArray(e.resource)?e.resource:[e.resource]):[]}}function V(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:"spatialUnit",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type,number:e.n,context:"context"in e&&e.context?U(e.context):null,license:"availability"in e&&e.availability?F(e.availability):null,identification:P(e.identification),image:e.image?me(e.image):null,description:e.description?["string","number","boolean"].includes(typeof e.description)?u(e.description):w(e.description):"",coordinates:e.coordinates?he(e.coordinates):e.coordinate?he(e.coordinate):null,observations:"observations"in e&&e.observations?je(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[ge(e.observation)]:[],events:"events"in e&&e.events?Ue(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:"properties"in e&&e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function we(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(ee(t));return r}function te(e){return{uuid:e.uuid,category:"concept",publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,number:e.n,license:"availability"in e&&e.availability?F(e.availability):null,context:"context"in e&&e.context?U(e.context):null,identification:P(e.identification),interpretations:Ne(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation])}}var be=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 Me(t);o&&n.push(o);break}case"block":{let o=await Se(t);o&&n.push(o);break}}return n};function ve(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(te(t));return r}async function Xe(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=y(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=y(e.properties,"layout");l??="long",t.bibliographies=a.bibliographies,t.layout=l;break}case"blog":{let a=i.find(l=>l.category==="tree");if(!a)throw new Error(`Blog link not found for the following component: \u201C${n}\u201D`);t.blogId=a.uuid;break}case"button":{let a=y(e.properties,"variant");a??="default";let l=!1,c=y(e.properties,"navigate-to");if(c===null){if(c=y(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 m=null,g=y(e.properties,"icon");g!==null&&(m=g),t.variant=a,t.href=c,t.isExternal=l,t.label=["string","number","boolean"].includes(typeof r.identification.label)?u(r.identification.label):w(r.identification.label),t.icon=m;break}case"collection":{let a=i.find(D=>D.category==="set");if(!a)throw new Error(`Collection link not found for the following component: \u201C${n}\u201D`);let l=y(e.properties,"variant");l??="full";let c=y(e.properties,"item-variant");c??="default";let m=!1,g=y(e.properties,"show-count");g!==null&&(m=g==="Yes");let k=!1,f=y(e.properties,"is-searchable");f!==null&&(k=f==="Yes");let h=y(e.properties,"layout");h??="image-start",t.collectionId=a.uuid,t.variant=l,t.itemVariant=c,t.isSearchable=k,t.showCount=m,t.layout=h;break}case"empty-space":{let a=y(e.properties,"height"),l=y(e.properties,"width");t.height=a,t.width=l;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(m=>m.type==="webpage")?.href;if(!a)throw new Error(`URL not found for the following component: \u201C${n}\u201D`);let l=y(e.properties,"height"),c=y(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 $ of s)a.push({url:`https://ochre.lib.uchicago.edu/ochre?uuid=${$.uuid}&load`,label:$.identification?.label??null,width:$.image?.width??0,height:$.image?.height??0});let l=y(e.properties,"variant");l??="default";let c=y(e.properties,"layout-caption");c??="bottom";let m=null,g=y(e.properties,"width");g!==null&&(typeof g=="number"?m=g:typeof g=="string"&&(m=Number.parseFloat(g)));let k=null,f=y(e.properties,"height");f!==null&&(typeof f=="number"?k=f:typeof f=="string"&&(k=Number.parseFloat(f)));let h=!0,D=y(e.properties,"is-full-width");D!==null&&(h=D==="Yes");let I=!0,E=y(e.properties,"is-full-height");E!==null&&(I=E==="Yes");let d=y(e.properties,"image-quality");d??="high";let b=y(e.properties,"caption-source");b??="name";let v=y(e.properties,"alt-text-source");v??="name";let S=!1,p=y(e.properties,"is-transparent");p!==null&&(S=p==="Yes");let O=!1,C=y(e.properties,"is-cover");C!==null&&(O=C==="Yes");let N=null;if(a.length>1){let $=G(e.properties,"variant"),H=5;if($&&$.values[0].content==="carousel"){let B=y($.properties,"seconds-per-image");B!==null&&(typeof B=="number"?H=B:typeof B=="string"&&(H=Number.parseFloat(B)))}N={secondsPerImage:H}}t.images=a,t.variant=l,t.width=m,t.height=k,t.isFullWidth=h,t.isFullHeight=I,t.imageQuality=d,t.captionLayout=c,t.captionSource=b,t.altTextSource=v,t.isTransparentBackground=S,t.isCover=O,t.carouselOptions=N;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=y(e.properties,"is-searchable")==="Yes";t.galleryId=a.uuid,t.isSearchable=l;break}case"n-columns":{let a=r.resource?await be(Array.isArray(r.resource)?r.resource:[r.resource],"element"):[];t.columns=a;break}case"n-rows":{let a=r.resource?await be(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=y(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=y(e.properties,"variant");a??="block";let l=y(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=y(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${w(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(b=>b.label==="presentation");if(!t)throw new Error(`Presentation property not found for element \u201C${r.label}\u201D`);let i=t.properties.find(b=>b.label==="component");if(!i)throw new Error(`Component for element \u201C${r.label}\u201D not found`);let s=await Xe(i,e),a=t.properties.find(b=>b.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(b=>b.label==="presentation"&&b.values[0].content==="css")?.properties??[],m=[];for(let b of c){let v=b.values[0].content;m.push({label:b.label,value:v})}let g=l.find(b=>b.label==="presentation"&&b.values[0].content==="css-mobile")?.properties??[],k=[];for(let b of g){let v=b.values[0].content;k.push({label:b.label,value:v})}let f=l.find(b=>b.label==="presentation"&&b.values[0].content==="title")?.properties,h="default",D=!1,I=!1,E=!1,d=!1;if(f){let b=y(f,"variant");b&&(h=b);let v=f.filter(S=>S.label==="display");v.length>0&&(D=v.some(S=>S.values[0].content==="name"),I=v.some(S=>S.values[0].content==="description"),E=v.some(S=>S.values[0].content==="date"),d=v.some(S=>S.values[0].content==="creators"))}return{uuid:e.uuid,type:"element",title:{label:r.label,variant:h,properties:{isNameDisplayed:D,isDescriptionDisplayed:I,isDateDisplayed:E,isCreatorsDisplayed:d}},isDisplayedInBlockSectionSidebar:a,cssStyles:m,cssStylesMobile:k,...s}}async function Me(e){let r=e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];if(r.length===0||r.find(d=>d.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(d=>d.type==="image"||d.type==="IIIF"),o=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],a=[];for(let d of o){let b=d.properties?T(Array.isArray(d.properties.property)?d.properties.property:[d.properties.property]):[],v=y(b,"presentation");if(v!=null)switch(v){case"element":{let S=await ie(d);a.push(S);break}case"block":{let S=await Se(d);S&&a.push(S);break}}}let l=e.resource?await be(Array.isArray(e.resource)?e.resource:[e.resource],"page"):[],c=!0,m="default",g="default",k=!0,f=r.find(d=>d.label==="presentation"&&d.values[0]?.content==="page")?.properties;if(f){let d=f.find(p=>p.label==="header")?.values[0];d&&(c=d.content==="Yes");let b=f.find(p=>p.label==="width")?.values[0];b&&(m=b.content);let v=f.find(p=>p.label==="variant")?.values[0];v&&(g=v.content);let S=f.find(p=>p.label==="sidebar-visible")?.values[0];S&&(k=S.content==="Yes")}let h=r.find(d=>d.label==="presentation"&&d.values[0]?.content==="css")?.properties,D=[];if(h)for(let d of h)D.push({label:d.label,value:d.values[0].content});let I=r.find(d=>d.label==="presentation"&&d.values[0]?.content==="css-mobile")?.properties,E=[];if(I)for(let d of I)E.push({label:d.label,value:d.values[0].content});return{title:n.label,slug:t,items:a,properties:{displayedInHeader:c,width:m,variant:g,backgroundImageUrl:s?`https://ochre.lib.uchicago.edu/ochre?uuid=${s.uuid}&load`:null,isSidebarDisplayed:k,cssStyles:D,cssStylesMobile:E},webpages:l}}async function Ze(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n){let i=await Me(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(h=>h.label==="layout")?.values[0];l&&(r.layout=l.content);let c=t.find(h=>h.label==="spacing")?.values[0];c&&(r.properties.spacing=c.content);let m=t.find(h=>h.label==="gap")?.values[0];m&&(r.properties.gap=m.content);let g=t.find(h=>h.label==="align-items")?.values[0];g&&(r.properties.alignItems=g.content);let k=t.find(h=>h.label==="justify-content")?.values[0];k&&(r.properties.justifyContent=k.content);let f=t.find(h=>h.label==="overwrite-mobile");if(f){let h=f.properties,D={};for(let I of h)D[I.label]=I.values[0].content;r.propertiesMobile=D}}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]):[],m=y(c,"presentation");if(m!=null)switch(m){case"element":{let g=await ie(l);s.push(g);break}case"block":{let g=await Se(l);g&&s.push(g);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=Ye(r),r}function Ye(e){let r=[];for(let n of e.items)switch(n.type){case"block":{let t=Ye(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 et(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,qe]=(l.values[0]?.content).split(";");a={name:A,email:qe??null}}let c=n.find(A=>A.label==="logo")?.values[0]?.uuid??null,m=!0,g="default",k="start",f=!0,h=!0,D=!1,I=null,E=!0,d=n.find(A=>A.label==="navbar-visible")?.values[0];d&&(m=d.content==="Yes");let b=n.find(A=>A.label==="navbar-variant")?.values[0];b&&(g=b.content);let v=n.find(A=>A.label==="navbar-alignment")?.values[0];v&&(k=v.content);let S=n.find(A=>A.label==="navbar-project-visible")?.values[0];S&&(f=S.content==="Yes");let p=n.find(A=>A.label==="footer-visible")?.values[0];p&&(h=p.content==="Yes");let O=n.find(A=>A.label==="sidebar-visible")?.values[0];O&&(D=O.content==="Yes");let C=n.find(A=>A.label==="search-collection")?.values[0];C&&(I=C.uuid);let N=n.find(A=>A.label==="supports-theme-toggle")?.values[0];N&&(E=N.content==="Yes");let{type:$,status:H,privacy:B}=o.data;return{type:$,privacy:B,status:H,contact:a,isHeaderDisplayed:m,headerVariant:g,headerAlignment:k,isHeaderProjectDisplayed:f,isFooterDisplayed:h,isSidebarDisplayed:D,supportsThemeToggle:E,searchCollectionUuid:I,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=et(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 Ze(i),o=null,a=[],l={label:"",variant:"default",properties:{isNameDisplayed:!1,isDescriptionDisplayed:!1,isDateDisplayed:!1,isCreatorsDisplayed:!1}},c="start",m="default",g=[],k=[],f=i.find(h=>(h.properties?T(Array.isArray(h.properties.property)?h.properties.property:[h.properties.property]):[]).some(I=>I.label==="presentation"&&I.values[0]?.content==="element"&&I.properties[0]?.label==="component"&&I.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"?u(f.identification.label):w(f.identification.label);let h=f.properties?T(Array.isArray(f.properties.property)?f.properties.property:[f.properties.property]):[],D=h.find(p=>p.label==="presentation"&&p.values[0]?.content==="element")?.properties.find(p=>p.label==="component"&&p.values[0]?.content==="sidebar")?.properties??[],I=D.find(p=>p.label==="layout");I&&(c=I.values[0].content);let E=D.find(p=>p.label==="layout-mobile");E&&(m=E.values[0].content);let d=h.find(p=>p.label==="presentation"&&p.values[0].content==="css")?.properties??[];for(let p of d){let O=p.values[0].content;g.push({label:p.label,value:O})}let b=h.find(p=>p.label==="presentation"&&p.values[0].content==="css-mobile")?.properties??[];for(let p of b){let O=p.values[0].content;k.push({label:p.label,value:O})}let v=h.find(p=>p.label==="presentation"&&p.values[0].content==="title")?.properties;if(v){let p=y(v,"variant");p&&(l.variant=p);let O=v.filter(C=>C.label==="display");O.length>0&&(l.properties.isNameDisplayed=O.some(C=>C.values[0].content==="name"),l.properties.isDescriptionDisplayed=O.some(C=>C.values[0].content==="description"),l.properties.isDateDisplayed=O.some(C=>C.values[0].content==="date"),l.properties.isCreatorsDisplayed=O.some(C=>C.values[0].content==="creators"))}let S=f.resource?Array.isArray(f.resource)?f.resource:[f.resource]:[];for(let p of S){let O=await ie(p);a.push(O)}}return a.length>0&&(o={elements:a,title:l,layout:c,mobileLayout:m,cssStyles:g,cssStylesMobile:k}),{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:P(e.identification),project:{name:u(r),website:n!==null?u(n):null},creators:e.creators?L(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:F(e.availability),pages:s,sidebar:o,properties:t}}async function tt(e,r,n,t){try{let{uuid:i,filter:s,page:o,perPage:a}=Te.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 K(t)}}else return K(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
|
|
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 m=P(c.result.gallery.item.identification),g=P(c.result.gallery.project.identification);return{item:{identification:m,projectIdentification:g,resources:V(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 rt(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});
|
package/dist/index.d.cts
CHANGED
|
@@ -477,6 +477,7 @@ type WebElement = {
|
|
|
477
477
|
isCreatorsDisplayed: boolean;
|
|
478
478
|
};
|
|
479
479
|
};
|
|
480
|
+
isDisplayedInBlockSectionSidebar: boolean;
|
|
480
481
|
cssStyles: Array<Style>;
|
|
481
482
|
cssStylesMobile: Array<Style>;
|
|
482
483
|
} & WebElementComponent;
|
|
@@ -615,11 +616,18 @@ type WebBlock = {
|
|
|
615
616
|
* `justify-content` CSS property value
|
|
616
617
|
*/
|
|
617
618
|
justifyContent: "stretch" | "start" | "center" | "end" | "space-between";
|
|
619
|
+
sectionSidebarItems: Array<WebSectionSidebarItem> | null;
|
|
618
620
|
};
|
|
619
621
|
propertiesMobile: Record<string, string> | null;
|
|
620
622
|
cssStyles: Array<Style>;
|
|
621
623
|
cssStylesMobile: Array<Style>;
|
|
622
624
|
};
|
|
625
|
+
type WebSectionSidebarItem = {
|
|
626
|
+
uuid: string;
|
|
627
|
+
type: "block" | "element";
|
|
628
|
+
name: string | null;
|
|
629
|
+
items: Array<WebSectionSidebarItem> | null;
|
|
630
|
+
};
|
|
623
631
|
|
|
624
632
|
/**
|
|
625
633
|
* Fetches and parses a gallery from the OCHRE API
|
|
@@ -1715,4 +1723,4 @@ declare function parseStringDocumentItem(item: OchreStringRichTextItem, footnote
|
|
|
1715
1723
|
*/
|
|
1716
1724
|
declare function parseStringContent(content: OchreStringContent, language?: string): string;
|
|
1717
1725
|
|
|
1718
|
-
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 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 };
|
|
1726
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -477,6 +477,7 @@ type WebElement = {
|
|
|
477
477
|
isCreatorsDisplayed: boolean;
|
|
478
478
|
};
|
|
479
479
|
};
|
|
480
|
+
isDisplayedInBlockSectionSidebar: boolean;
|
|
480
481
|
cssStyles: Array<Style>;
|
|
481
482
|
cssStylesMobile: Array<Style>;
|
|
482
483
|
} & WebElementComponent;
|
|
@@ -615,11 +616,18 @@ type WebBlock = {
|
|
|
615
616
|
* `justify-content` CSS property value
|
|
616
617
|
*/
|
|
617
618
|
justifyContent: "stretch" | "start" | "center" | "end" | "space-between";
|
|
619
|
+
sectionSidebarItems: Array<WebSectionSidebarItem> | null;
|
|
618
620
|
};
|
|
619
621
|
propertiesMobile: Record<string, string> | null;
|
|
620
622
|
cssStyles: Array<Style>;
|
|
621
623
|
cssStylesMobile: Array<Style>;
|
|
622
624
|
};
|
|
625
|
+
type WebSectionSidebarItem = {
|
|
626
|
+
uuid: string;
|
|
627
|
+
type: "block" | "element";
|
|
628
|
+
name: string | null;
|
|
629
|
+
items: Array<WebSectionSidebarItem> | null;
|
|
630
|
+
};
|
|
623
631
|
|
|
624
632
|
/**
|
|
625
633
|
* Fetches and parses a gallery from the OCHRE API
|
|
@@ -1715,4 +1723,4 @@ declare function parseStringDocumentItem(item: OchreStringRichTextItem, footnote
|
|
|
1715
1723
|
*/
|
|
1716
1724
|
declare function parseStringContent(content: OchreStringContent, language?: string): string;
|
|
1717
1725
|
|
|
1718
|
-
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 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 };
|
|
1726
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{z as
|
|
2
|
-
${n}`;break}case"trailing":{n=`${n} `;break}case"leading":{n=` ${n}`;break}}return n.replaceAll("'","'")}function
|
|
3
|
-
`:"";if("links"in e){let t="";typeof e.string=="object"?t=
|
|
4
|
-
${JSON.stringify(e.content)}.`);return z(t)}}else return z(e.content);default:return String(e.content).replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}}function Y(e){let r=e.find(t=>J.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 J.parse(r)}async function we(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 ve(e,r){try{let[n,t]=await we(e);if(n!==null)throw new Error(n);let i=Y(Object.keys(t.ochre)),s;switch(i){case"resource":{if(!("resource"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'resource' key");s=re(t.ochre.resource);break}case"spatialUnit":{if(!("spatialUnit"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'spatialUnit' key");s=ne(t.ochre.spatialUnit);break}case"concept":{if(!("concept"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'concept' key");s=ie(t.ochre.concept);break}case"period":{if(!("period"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'period' key");s=Z(t.ochre.period);break}case"bibliography":{if(!("bibliography"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'bibliography' key");s=ee(t.ochre.bibliography);break}case"person":{if(!("person"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'person' key");s=X(t.ochre.person);break}case"propertyValue":{if(!("propertyValue"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'propertyValue' key");s=te(t.ochre.propertyValue);break}case"set":{if(!("set"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'set' key");s=ke(t.ochre.set);break}case"tree":{if(!("tree"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'tree' key");s=Se(t.ochre.tree);break}default:throw new Error("Invalid category")}let o=Pe(t.ochre.metadata),a={uuid:t.ochre.uuidBelongsTo,abbreviation:f(t.ochre.belongsTo)};return{error:null,metadata:o,belongsTo:a,item:s,category:r}}catch(n){return{error:n instanceof Error?n.message:"Unknown error",metadata:void 0,belongsTo:void 0,item:void 0,category:void 0}}}function v(e){try{let r={label:["string","number","boolean"].includes(typeof e.label)?f(e.label):w(e.label),abbreviation:""};for(let n of Object.keys(e).filter(t=>t!=="label"))r[n]=w(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=>w(r)):[w(e)]}function Pe(e){let r={label:"",abbreviation:""};if(e.item)if(e.item.label||e.item.abbreviation){let i="",s="";e.item.label&&(i=w(e.item.label)),e.item.abbreviation&&(s=w(e.item.abbreviation)),r={label:i,abbreviation:s}}else r=v(e.item.identification);let n=null,t=e.project?.identification?v(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:w(e.dataset),publisher:w(e.publisher),languages:je(e.language),identifier:w(e.identifier),description:w(e.description)}}function oe(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,number:e.n,content:f(e.content)}}function H(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(oe(o))}return{tree:oe(t.tree),project:oe(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 X(e){return{uuid:e.uuid,category:"person",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type??null,date:e.date!=null?new Date(e.date):null,identification:e.identification?v(e.identification):null,content:e.content!=null?f(e.content):null}}function L(e){let r=[];for(let n of e)r.push(X(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?f(i.content):null,href:"href"in i&&i.href!=null?i.href:null,uuid:i.uuid,type:i.type??null,identification:i.identification?v(i.identification):null,image:null,bibliographies:"bibliography"in e?G(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(...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+=W(f(i.string));else{let s=Array.isArray(i.string)?i.string:[i.string];for(let o of s)n+=R(o,t)}return{content:n,footnotes:t}}function Ie(e){return{publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,identification:e.identification?v(e.identification):null,url:e.href??(e.htmlImgSrcPrefix==null&&e.content!=null?f(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?f(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=W(f(o.string)):i=W(se(o).content),n.push({number:t.noteNo,title:o.title!=null?f(o.title):null,content:i})}return n}function xe(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?f(e.coord.coordLabel):null}}function Te(e){return{number:e.observationNo,date:e.date!=null?new Date(e.date):null,observers:e.observers!=null?f(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?D(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function Ve(e){let r=[];for(let n of e)r.push(Te(n));return r}function Ne(e){let r=[];for(let n of e)r.push({date:n.dateTime!=null?new Date(n.dateTime):null,label:w(n.label),agent:n.agent?{uuid:n.agent.uuid,content:f(n.agent.content)}:null});return r}function He(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=f(i),{content:s,booleanValue:o,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(w({content:i.content})):null;break}default:{"slug"in i&&i.slug!=null?s=f(i.slug):i.content!=null&&(s=w({content:i.content})),i.type==="boolean"&&(o=i.booleanValue??null);break}}let a="string";if(i.type!=null){let{data:c,error:g}=de.safeParse(i.type);if(g)throw new Error(`Invalid property value content type: "${i.type}"`);a=c}return{content:s,booleanValue:o,type:a,category:i.category??"value",uuid:i.uuid??null,publicationDateTime:i.publicationDateTime!=null?new Date(i.publicationDateTime):null,unit:i.unit??null}}});return{label:w(e.label,r).replace(/\s*\.{3}$/,"").trim(),values:t,comment:e.comment!=null?f(e.comment):null,properties:e.property?D(Array.isArray(e.property)?e.property:[e.property]):[]}}function D(e,r="eng"){let n=[];for(let t of e)n.push(He(t,r));return n}function Me(e){let r=[];for(let n of e)r.push({date:new Date(n.date),number:n.interpretationNo,properties:n.properties?D(Array.isArray(n.properties.property)?n.properties.property:[n.properties.property]):[]});return r}function Ye(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:f(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:v(e.identification),description:e.description?w(e.description):null}}function q(e){let r=[];for(let n of e)r.push(Z(n));return r}function ee(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:v(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?v(e.identification):null,projectIdentification:e.project?.identification?v(e.project.identification):null,context:e.context?H(e.context):null,citation:{format:e.citationFormat??null,short:e.citationFormatSpan?f("default:span"in e.citationFormatSpan?e.citationFormatSpan["default:span"].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?f("default:div"in e.referenceFormatDiv?e.referenceFormatDiv["default:div"]["default:div"].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?L(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:f(e.entryInfo.startIssue),startVolume:f(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?q(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],authors:e.authors?L(Array.isArray(e.authors.person)?e.authors.person:[e.authors.person]):[],properties:e.properties?D(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function G(e){let r=[];for(let n of e)r.push(ee(n));return r}function te(e){return{uuid:e.uuid,category:"propertyValue",n:e.n,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,context:e.context?H(e.context):null,availability:e.availability?B(e.availability):null,identification:v(e.identification),date:e.date?new Date(e.date):null,creators:e.creators?L(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],description:e.description?["string","number","boolean"].includes(typeof e.description)?f(e.description):w(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 De(e){let r=[];for(let n of e)r.push(te(n));return r}function Se(e){let r=[];e.creators&&(r=L(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=M(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource])),typeof e.items!="string"&&"spatialUnit"in e.items&&(i=Oe(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit])),typeof e.items!="string"&&"concept"in e.items&&(s=Ce(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept])),typeof e.items!="string"&&"period"in e.items&&(o=q(Array.isArray(e.items.period)?e.items.period:[e.items.period])),typeof e.items!="string"&&"bibliography"in e.items&&(a=G(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography])),typeof e.items!="string"&&"person"in e.items&&(l=L(Array.isArray(e.items.person)?e.items.person:[e.items.person])),typeof e.items!="string"&&"propertyValue"in e.items&&(c=De(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue])),{uuid:e.uuid,category:"tree",publicationDateTime:new Date(e.publicationDateTime),identification:v(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?D(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function ke(e){if(typeof e.items=="string")throw new TypeError("Invalid OCHRE data: Set has no items");let r=Y(Object.keys(e.items)),n=[];switch(r){case"resource":{if(!("resource"in e.items))throw new Error("Invalid OCHRE data: Set has no resources");n=M(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");n=Oe(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");n=Ce(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");n=q(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");n=G(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");n=L(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");n=De(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:v(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?["string","number","boolean"].includes(typeof e.description)?f(e.description):w(e.description):"",creators:e.creators?L(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],type:e.type,number:e.n,items:n}}function re(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?H(e.context):null,license:"availability"in e&&e.availability?B(e.availability):null,copyright:"copyright"in e&&e.copyright!=null?f(e.copyright):null,identification:v(e.identification),date:e.date!=null?new Date(e.date):null,image:e.image?Ie(e.image):null,creators:e.creators?L(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)?f(e.description):w(e.description):"",document:e.document&&"content"in e.document?se(e.document.content):null,href:e.href??null,imageMap:e.imagemap?Ye(e.imagemap):null,periods:e.periods?q(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?D(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],citedBibliographies:e.citedBibliography?G(Array.isArray(e.citedBibliography.reference)?e.citedBibliography.reference:[e.citedBibliography.reference]):[],resources:e.resource?M(Array.isArray(e.resource)?e.resource:[e.resource]):[]}}function M(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:"spatialUnit",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type,number:e.n,context:"context"in e&&e.context?H(e.context):null,license:"availability"in e&&e.availability?B(e.availability):null,identification:v(e.identification),image:e.image?Ie(e.image):null,description:e.description?["string","number","boolean"].includes(typeof e.description)?f(e.description):w(e.description):"",coordinates:e.coordinates?xe(e.coordinates):e.coordinate?xe(e.coordinate):null,observations:"observations"in e&&e.observations?Ve(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[Te(e.observation)]:[],events:"events"in e&&e.events?Ne(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:"properties"in e&&e.properties?D(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function Oe(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(ne(t));return r}function ie(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?H(e.context):null,identification:v(e.identification),interpretations:Me(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?D(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 K(t);n.push(o);break}case"page":{let o=await Ee(t);o&&n.push(o);break}case"block":{let o=await ce(t);o&&n.push(o);break}}return n};function Ce(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(ie(t));return r}async function qe(e,r){let n=fe.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 ve(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=h(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=h(e.properties,"layout");l??="long",t.bibliographies=a.bibliographies,t.layout=l;break}case"blog":{let a=i.find(l=>l.category==="tree");if(!a)throw new Error(`Blog link not found for the following component: \u201C${n}\u201D`);t.blogId=a.uuid;break}case"button":{let a=h(e.properties,"variant");a??="default";let l=!1,c=h(e.properties,"navigate-to");if(c===null){if(c=h(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 g=null,m=h(e.properties,"icon");m!==null&&(g=m),t.variant=a,t.href=c,t.isExternal=l,t.label=["string","number","boolean"].includes(typeof r.identification.label)?f(r.identification.label):w(r.identification.label),t.icon=g;break}case"collection":{let a=i.find(x=>x.category==="set");if(!a)throw new Error(`Collection link not found for the following component: \u201C${n}\u201D`);let l=h(e.properties,"variant");l??="full";let c=h(e.properties,"item-variant");c??="default";let g=!1,m=h(e.properties,"show-count");m!==null&&(g=m==="Yes");let P=!1,d=h(e.properties,"is-searchable");d!==null&&(P=d==="Yes");let y=h(e.properties,"layout");y??="image-start",t.collectionId=a.uuid,t.variant=l,t.itemVariant=c,t.isSearchable=P,t.showCount=g,t.layout=y;break}case"empty-space":{let a=h(e.properties,"height"),l=h(e.properties,"width");t.height=a,t.width=l;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(g=>g.type==="webpage")?.href;if(!a)throw new Error(`URL not found for the following component: \u201C${n}\u201D`);let l=h(e.properties,"height"),c=h(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 $ of s)a.push({url:`https://ochre.lib.uchicago.edu/ochre?uuid=${$.uuid}&load`,label:$.identification?.label??null,width:$.image?.width??0,height:$.image?.height??0});let l=h(e.properties,"variant");l??="default";let c=h(e.properties,"layout-caption");c??="bottom";let g=null,m=h(e.properties,"width");m!==null&&(typeof m=="number"?g=m:typeof m=="string"&&(g=Number.parseFloat(m)));let P=null,d=h(e.properties,"height");d!==null&&(typeof d=="number"?P=d:typeof d=="string"&&(P=Number.parseFloat(d)));let y=!0,x=h(e.properties,"is-full-width");x!==null&&(y=x==="Yes");let S=!0,b=h(e.properties,"is-full-height");b!==null&&(S=b==="Yes");let p=h(e.properties,"image-quality");p??="high";let k=h(e.properties,"caption-source");k??="name";let O=h(e.properties,"alt-text-source");O??="name";let C=!1,u=h(e.properties,"is-transparent");u!==null&&(C=u==="Yes");let T=!1,E=h(e.properties,"is-cover");E!==null&&(T=E==="Yes");let U=null;if(a.length>1){let $=_(e.properties,"variant"),V=5;if($&&$.values[0].content==="carousel"){let F=h($.properties,"seconds-per-image");F!==null&&(typeof F=="number"?V=F:typeof F=="string"&&(V=Number.parseFloat(F)))}U={secondsPerImage:V}}t.images=a,t.variant=l,t.width=g,t.height=P,t.isFullWidth=y,t.isFullHeight=S,t.imageQuality=p,t.captionLayout=c,t.captionSource=k,t.altTextSource=O,t.isTransparentBackground=C,t.isCover=T,t.carouselOptions=U;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=h(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=h(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=h(e.properties,"variant");a??="block";let l=h(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=h(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${w(r.identification.label)}\u201D`);break}}return t}async function K(e){let r=v(e.identification),t=(e.properties?.property?D(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]).find(b=>b.label==="presentation");if(!t)throw new Error(`Presentation property not found for element \u201C${r.label}\u201D`);let i=t.properties.find(b=>b.label==="component");if(!i)throw new Error(`Component for element \u201C${r.label}\u201D not found`);let s=await qe(i,e),o=e.properties?.property?D(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],a=o.find(b=>b.label==="presentation"&&b.values[0].content==="css")?.properties??[],l=[];for(let b of a){let p=b.values[0].content;l.push({label:b.label,value:p})}let c=o.find(b=>b.label==="presentation"&&b.values[0].content==="css-mobile")?.properties??[],g=[];for(let b of c){let p=b.values[0].content;g.push({label:b.label,value:p})}let m=o.find(b=>b.label==="presentation"&&b.values[0].content==="title")?.properties,P="default",d=!1,y=!1,x=!1,S=!1;if(m){let b=h(m,"variant");b&&(P=b);let p=m.filter(k=>k.label==="display");p.length>0&&(d=p.some(k=>k.values[0].content==="name"),y=p.some(k=>k.values[0].content==="description"),x=p.some(k=>k.values[0].content==="date"),S=p.some(k=>k.values[0].content==="creators"))}return{uuid:e.uuid,type:"element",title:{label:r.label,variant:P,properties:{isNameDisplayed:d,isDescriptionDisplayed:y,isDateDisplayed:x,isCreatorsDisplayed:S}},cssStyles:l,cssStylesMobile:g,...s}}async function Ee(e){let r=e.properties?D(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];if(r.length===0||r.find(p=>p.label==="presentation")?.values[0]?.content!=="page")return null;let n=v(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(p=>p.type==="image"||p.type==="IIIF"),o=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],a=[];for(let p of o){let k=p.properties?D(Array.isArray(p.properties.property)?p.properties.property:[p.properties.property]):[],O=h(k,"presentation");if(O!=null)switch(O){case"element":{let C=await K(p);a.push(C);break}case"block":{let C=await ce(p);C&&a.push(C);break}}}let l=e.resource?await ae(Array.isArray(e.resource)?e.resource:[e.resource],"page"):[],c=!0,g="default",m="default",P=!0,d=r.find(p=>p.label==="presentation"&&p.values[0]?.content==="page")?.properties;if(d){let p=d.find(u=>u.label==="header")?.values[0];p&&(c=p.content==="Yes");let k=d.find(u=>u.label==="width")?.values[0];k&&(g=k.content);let O=d.find(u=>u.label==="variant")?.values[0];O&&(m=O.content);let C=d.find(u=>u.label==="sidebar-visible")?.values[0];C&&(P=C.content==="Yes")}let y=r.find(p=>p.label==="presentation"&&p.values[0]?.content==="css")?.properties,x=[];if(y)for(let p of y)x.push({label:p.label,value:p.values[0].content});let S=r.find(p=>p.label==="presentation"&&p.values[0]?.content==="css-mobile")?.properties,b=[];if(S)for(let p of S)b.push({label:p.label,value:p.values[0].content});return{title:n.label,slug:t,items:a,properties:{displayedInHeader:c,width:g,variant:m,backgroundImageUrl:s?`https://ochre.lib.uchicago.edu/ochre?uuid=${s.uuid}&load`:null,isSidebarDisplayed:P,cssStyles:x,cssStylesMobile:b},webpages:l}}async function Ge(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n){let i=await Ee(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"},propertiesMobile:null,cssStyles:[],cssStylesMobile:[]},n=e.properties?D(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(y=>y.label==="layout")?.values[0];l&&(r.layout=l.content);let c=t.find(y=>y.label==="spacing")?.values[0];c&&(r.properties.spacing=c.content);let g=t.find(y=>y.label==="gap")?.values[0];g&&(r.properties.gap=g.content);let m=t.find(y=>y.label==="align-items")?.values[0];m&&(r.properties.alignItems=m.content);let P=t.find(y=>y.label==="justify-content")?.values[0];P&&(r.properties.justifyContent=P.content);let d=t.find(y=>y.label==="overwrite-mobile");if(d){let y=d.properties,x={};for(let S of y)x[S.label]=S.values[0].content;r.propertiesMobile=x}}let i=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],s=[];for(let l of i){let c=l.properties?D(Array.isArray(l.properties.property)?l.properties.property:[l.properties.property]):[],g=h(c,"presentation");if(g!=null)switch(g){case"element":{let m=await K(l);s.push(m);break}case"block":{let m=await ce(l);m&&s.push(m);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}function Ke(e){let n=D(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,Le]=(l.values[0]?.content).split(";");a={name:A,email:Le??null}}let c=n.find(A=>A.label==="logo")?.values[0]?.uuid??null,g=!0,m="default",P="start",d=!0,y=!0,x=!1,S=null,b=!0,p=n.find(A=>A.label==="navbar-visible")?.values[0];p&&(g=p.content==="Yes");let k=n.find(A=>A.label==="navbar-variant")?.values[0];k&&(m=k.content);let O=n.find(A=>A.label==="navbar-alignment")?.values[0];O&&(P=O.content);let C=n.find(A=>A.label==="navbar-project-visible")?.values[0];C&&(d=C.content==="Yes");let u=n.find(A=>A.label==="footer-visible")?.values[0];u&&(y=u.content==="Yes");let T=n.find(A=>A.label==="sidebar-visible")?.values[0];T&&(x=T.content==="Yes");let E=n.find(A=>A.label==="search-collection")?.values[0];E&&(S=E.uuid);let U=n.find(A=>A.label==="supports-theme-toggle")?.values[0];U&&(b=U.content==="Yes");let{type:$,status:V,privacy:F}=o.data;return{type:$,privacy:F,status:V,contact:a,isHeaderDisplayed:g,headerVariant:m,headerAlignment:P,isHeaderProjectDisplayed:d,isFooterDisplayed:y,isSidebarDisplayed:x,supportsThemeToggle:b,searchCollectionUuid:S,logoUrl:c!==null?`https://ochre.lib.uchicago.edu/ochre?uuid=${c}&load`:null}}async function $e(e,r,n){if(!e.properties)throw new Error("Website properties not found");let t=Ke(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 Ge(i),o=null,a=[],l={label:"",variant:"default",properties:{isNameDisplayed:!1,isDescriptionDisplayed:!1,isDateDisplayed:!1,isCreatorsDisplayed:!1}},c="start",g="default",m=[],P=[],d=i.find(y=>(y.properties?D(Array.isArray(y.properties.property)?y.properties.property:[y.properties.property]):[]).some(S=>S.label==="presentation"&&S.values[0]?.content==="element"&&S.properties[0]?.label==="component"&&S.properties[0].values[0]?.content==="sidebar"));if(d){l.label=typeof d.identification.label=="string"||typeof d.identification.label=="number"||typeof d.identification.label=="boolean"?f(d.identification.label):w(d.identification.label);let y=d.properties?D(Array.isArray(d.properties.property)?d.properties.property:[d.properties.property]):[],x=y.find(u=>u.label==="presentation"&&u.values[0]?.content==="element")?.properties.find(u=>u.label==="component"&&u.values[0]?.content==="sidebar")?.properties??[],S=x.find(u=>u.label==="layout");S&&(c=S.values[0].content);let b=x.find(u=>u.label==="layout-mobile");b&&(g=b.values[0].content);let p=y.find(u=>u.label==="presentation"&&u.values[0].content==="css")?.properties??[];for(let u of p){let T=u.values[0].content;m.push({label:u.label,value:T})}let k=y.find(u=>u.label==="presentation"&&u.values[0].content==="css-mobile")?.properties??[];for(let u of k){let T=u.values[0].content;P.push({label:u.label,value:T})}let O=y.find(u=>u.label==="presentation"&&u.values[0].content==="title")?.properties;if(O){let u=h(O,"variant");u&&(l.variant=u);let T=O.filter(E=>E.label==="display");T.length>0&&(l.properties.isNameDisplayed=T.some(E=>E.values[0].content==="name"),l.properties.isDescriptionDisplayed=T.some(E=>E.values[0].content==="description"),l.properties.isDateDisplayed=T.some(E=>E.values[0].content==="date"),l.properties.isCreatorsDisplayed=T.some(E=>E.values[0].content==="creators"))}let C=d.resource?Array.isArray(d.resource)?d.resource:[d.resource]:[];for(let u of C){let T=await K(u);a.push(T)}}return a.length>0&&(o={elements:a,title:l,layout:c,mobileLayout:g,cssStyles:m,cssStylesMobile:P}),{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:v(e.identification),project:{name:f(r),website:n!==null?f(n):null},creators:e.creators?L(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:B(e.availability),pages:s,sidebar:o,properties:t}}async function ht(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(`
|
|
1
|
+
import{z as D}from"zod";var pe=D.string().uuid({message:"Invalid UUID provided"}),ue=D.object({type:D.enum(["traditional","digital-collection","plum","cedar","elm","maple","oak","palm"],{message:"Invalid website type"}),status:D.enum(["development","preview","production"],{message:"Invalid website status"}),privacy:D.enum(["public","password","private"],{message:"Invalid website privacy"})}),de=D.enum(["annotated-document","annotated-image","bibliography","blog","button","collection","empty-space","filter-categories","iframe","iiif-viewer","image","image-gallery","n-columns","n-rows","network-graph","search-bar","table","text","timeline","video"],{message:"Invalid component"}),J=D.enum(["resource","spatialUnit","concept","period","bibliography","person","propertyValue","set","tree"]),fe=D.enum(["string","integer","decimal","boolean","date","dateTime","time","coordinate","IDREF"]),ye=D.object({uuid:D.string().uuid({message:"Invalid UUID"}),filter:D.string().optional(),page:D.number().positive({message:"Page must be positive"}),perPage:D.number().positive({message:"Per page must be positive"})}).strict(),he=D.string().transform(e=>e.split(" ")).pipe(D.array(D.enum(["bold","italic","underline"]))),be=D.string().transform(e=>e.split(" ")).pipe(D.array(D.enum(["newline","trailing","leading"]))),me=D.string().email({message:"Invalid email"});var N={searchNestedProperties:!1};function _(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=_(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 h(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=h(s.properties,r,{searchNestedProperties:t});if(o!==null)return o}}return null}function Fe(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=Fe(i.properties,{searchNestedProperties:!0});for(let o of s)t.add(o)}return[...t]}function Be(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=>Be(o,r,{searchNestedProperties:!0}))),s}return!1}function je(e,r){return e.find(t=>t.lang===r)??null}function W(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(me.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("'","'")}function Q(e,r){let n=e,t=be.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
|
+
${n}`;break}case"trailing":{n=`${n} `;break}case"leading":{n=` ${n}`;break}}return n.replaceAll("'","'")}function u(e){let r="";return typeof e=="string"?r=e:typeof e=="number"?r=e.toString():typeof e=="boolean"&&(r=e?"Yes":"No"),r.replaceAll("'","'").replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}function z(e){let r="";switch(typeof e.string){case"string":{r=e.string;break}case"number":case"boolean":{r=u(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+=u(t);else{let i=t.rend!=null?Ae(u(t.content),t.rend):u(t.content),s=t.whitespace!=null?Q(i,t.whitespace):i;r+=s}break}default:{r="";break}}return r.replaceAll("'","'").replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}function R(e,r){if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return W(u(e));if("whitespace"in e&&!("content"in e)&&!("string"in e))return e.whitespace==="newline"?`
|
|
3
|
+
`:"";if("links"in e){let t="";typeof e.string=="object"?t=S(e.string):t=u(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=u(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)?u(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+=R(i,r);return"whitespace"in e&&e.whitespace!=null&&(n=Q(W(n),e.whitespace)),n.replaceAll("'","'").replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}else n=u(e.content),e.rend!=null&&(n=Ae(W(n),e.rend)),e.whitespace!=null&&(n=Q(W(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 u(e.content);case"object":if(Array.isArray(e.content)){let n=je(e.content,r);if(n)return z(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 z(t)}}else return z(e.content);default:return String(e.content).replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}}function Y(e){let r=e.find(t=>J.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 J.parse(r)}async function we(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 ve(e,r){try{let[n,t]=await we(e);if(n!==null)throw new Error(n);let i=Y(Object.keys(t.ochre)),s;switch(i){case"resource":{if(!("resource"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'resource' key");s=re(t.ochre.resource);break}case"spatialUnit":{if(!("spatialUnit"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'spatialUnit' key");s=ne(t.ochre.spatialUnit);break}case"concept":{if(!("concept"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'concept' key");s=ie(t.ochre.concept);break}case"period":{if(!("period"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'period' key");s=Z(t.ochre.period);break}case"bibliography":{if(!("bibliography"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'bibliography' key");s=ee(t.ochre.bibliography);break}case"person":{if(!("person"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'person' key");s=X(t.ochre.person);break}case"propertyValue":{if(!("propertyValue"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'propertyValue' key");s=te(t.ochre.propertyValue);break}case"set":{if(!("set"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'set' key");s=ke(t.ochre.set);break}case"tree":{if(!("tree"in t.ochre))throw new Error("Invalid OCHRE data: API response missing 'tree' key");s=Pe(t.ochre.tree);break}default:throw new Error("Invalid category")}let o=Se(t.ochre.metadata),a={uuid:t.ochre.uuidBelongsTo,abbreviation:u(t.ochre.belongsTo)};return{error:null,metadata:o,belongsTo:a,item:s,category:r}}catch(n){return{error:n instanceof Error?n.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)?u(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=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:Ue(e.language),identifier:S(e.identifier),description:S(e.description)}}function oe(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,number:e.n,content:u(e.content)}}function H(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(oe(o))}return{tree:oe(t.tree),project:oe(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 X(e){return{uuid:e.uuid,category:"person",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type??null,date:e.date!=null?new Date(e.date):null,identification:e.identification?P(e.identification):null,content:e.content!=null?u(e.content):null}}function L(e){let r=[];for(let n of e)r.push(X(n));return r}function Ve(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?u(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?G(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(...Ve(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+=W(u(i.string));else{let s=Array.isArray(i.string)?i.string:[i.string];for(let o of s)n+=R(o,t)}return{content:n,footnotes:t}}function xe(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?u(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?u(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=W(u(o.string)):i=W(se(o).content),n.push({number:t.noteNo,title:o.title!=null?u(o.title):null,content:i})}return n}function Ie(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?u(e.coord.coordLabel):null}}function De(e){return{number:e.observationNo,date:e.date!=null?new Date(e.date):null,observers:e.observers!=null?u(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?O(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function Ne(e){let r=[];for(let n of e)r.push(De(n));return r}function He(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:u(n.agent.content)}:null});return r}function Me(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=u(i),{content:s,booleanValue:o,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=u(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:m}=fe.safeParse(i.type);if(m)throw new Error(`Invalid property value content type: "${i.type}"`);a=c}return{content:s,booleanValue:o,type:a,category:i.category??"value",uuid:i.uuid??null,publicationDateTime:i.publicationDateTime!=null?new Date(i.publicationDateTime):null,unit:i.unit??null}}});return{label:S(e.label,r).replace(/\s*\.{3}$/,"").trim(),values:t,comment:e.comment!=null?u(e.comment):null,properties:e.property?O(Array.isArray(e.property)?e.property:[e.property]):[]}}function O(e,r="eng"){let n=[];for(let t of e)n.push(Me(t,r));return n}function Ye(e){let r=[];for(let n of e)r.push({date:new Date(n.date),number:n.interpretationNo,properties:n.properties?O(Array.isArray(n.properties.property)?n.properties.property:[n.properties.property]):[]});return r}function qe(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:u(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 q(e){let r=[];for(let n of e)r.push(Z(n));return r}function ee(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?H(e.context):null,citation:{format:e.citationFormat??null,short:e.citationFormatSpan?u("default:span"in e.citationFormatSpan?e.citationFormatSpan["default:span"].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?u("default:div"in e.referenceFormatDiv?e.referenceFormatDiv["default:div"]["default:div"].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?L(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:u(e.entryInfo.startIssue),startVolume:u(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?q(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],authors:e.authors?L(Array.isArray(e.authors.person)?e.authors.person:[e.authors.person]):[],properties:e.properties?O(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function G(e){let r=[];for(let n of e)r.push(ee(n));return r}function te(e){return{uuid:e.uuid,category:"propertyValue",n:e.n,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,context:e.context?H(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?L(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],description:e.description?["string","number","boolean"].includes(typeof e.description)?u(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 Te(e){let r=[];for(let n of e)r.push(te(n));return r}function Pe(e){let r=[];e.creators&&(r=L(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=M(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource])),typeof e.items!="string"&&"spatialUnit"in e.items&&(i=Oe(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit])),typeof e.items!="string"&&"concept"in e.items&&(s=Ce(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept])),typeof e.items!="string"&&"period"in e.items&&(o=q(Array.isArray(e.items.period)?e.items.period:[e.items.period])),typeof e.items!="string"&&"bibliography"in e.items&&(a=G(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography])),typeof e.items!="string"&&"person"in e.items&&(l=L(Array.isArray(e.items.person)?e.items.person:[e.items.person])),typeof e.items!="string"&&"propertyValue"in e.items&&(c=Te(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?O(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function ke(e){if(typeof e.items=="string")throw new TypeError("Invalid OCHRE data: Set has no items");let r=Y(Object.keys(e.items)),n=[];switch(r){case"resource":{if(!("resource"in e.items))throw new Error("Invalid OCHRE data: Set has no resources");n=M(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");n=Oe(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");n=Ce(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");n=q(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");n=G(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");n=L(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");n=Te(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)?u(e.description):S(e.description):"",creators:e.creators?L(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],type:e.type,number:e.n,items:n}}function re(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?H(e.context):null,license:"availability"in e&&e.availability?B(e.availability):null,copyright:"copyright"in e&&e.copyright!=null?u(e.copyright):null,identification:P(e.identification),date:e.date!=null?new Date(e.date):null,image:e.image?xe(e.image):null,creators:e.creators?L(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)?u(e.description):S(e.description):"",document:e.document&&"content"in e.document?se(e.document.content):null,href:e.href??null,imageMap:e.imagemap?qe(e.imagemap):null,periods:e.periods?q(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?O(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],citedBibliographies:e.citedBibliography?G(Array.isArray(e.citedBibliography.reference)?e.citedBibliography.reference:[e.citedBibliography.reference]):[],resources:e.resource?M(Array.isArray(e.resource)?e.resource:[e.resource]):[]}}function M(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:"spatialUnit",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type,number:e.n,context:"context"in e&&e.context?H(e.context):null,license:"availability"in e&&e.availability?B(e.availability):null,identification:P(e.identification),image:e.image?xe(e.image):null,description:e.description?["string","number","boolean"].includes(typeof e.description)?u(e.description):S(e.description):"",coordinates:e.coordinates?Ie(e.coordinates):e.coordinate?Ie(e.coordinate):null,observations:"observations"in e&&e.observations?Ne(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[De(e.observation)]:[],events:"events"in e&&e.events?He(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:"properties"in e&&e.properties?O(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function Oe(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(ne(t));return r}function ie(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?H(e.context):null,identification:P(e.identification),interpretations:Ye(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?O(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 K(t);n.push(o);break}case"page":{let o=await Ee(t);o&&n.push(o);break}case"block":{let o=await ce(t);o&&n.push(o);break}}return n};function Ce(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(ie(t));return r}async function Ge(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 ve(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=h(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=h(e.properties,"layout");l??="long",t.bibliographies=a.bibliographies,t.layout=l;break}case"blog":{let a=i.find(l=>l.category==="tree");if(!a)throw new Error(`Blog link not found for the following component: \u201C${n}\u201D`);t.blogId=a.uuid;break}case"button":{let a=h(e.properties,"variant");a??="default";let l=!1,c=h(e.properties,"navigate-to");if(c===null){if(c=h(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 m=null,g=h(e.properties,"icon");g!==null&&(m=g),t.variant=a,t.href=c,t.isExternal=l,t.label=["string","number","boolean"].includes(typeof r.identification.label)?u(r.identification.label):S(r.identification.label),t.icon=m;break}case"collection":{let a=i.find(x=>x.category==="set");if(!a)throw new Error(`Collection link not found for the following component: \u201C${n}\u201D`);let l=h(e.properties,"variant");l??="full";let c=h(e.properties,"item-variant");c??="default";let m=!1,g=h(e.properties,"show-count");g!==null&&(m=g==="Yes");let k=!1,f=h(e.properties,"is-searchable");f!==null&&(k=f==="Yes");let y=h(e.properties,"layout");y??="image-start",t.collectionId=a.uuid,t.variant=l,t.itemVariant=c,t.isSearchable=k,t.showCount=m,t.layout=y;break}case"empty-space":{let a=h(e.properties,"height"),l=h(e.properties,"width");t.height=a,t.width=l;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(m=>m.type==="webpage")?.href;if(!a)throw new Error(`URL not found for the following component: \u201C${n}\u201D`);let l=h(e.properties,"height"),c=h(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 $ of s)a.push({url:`https://ochre.lib.uchicago.edu/ochre?uuid=${$.uuid}&load`,label:$.identification?.label??null,width:$.image?.width??0,height:$.image?.height??0});let l=h(e.properties,"variant");l??="default";let c=h(e.properties,"layout-caption");c??="bottom";let m=null,g=h(e.properties,"width");g!==null&&(typeof g=="number"?m=g:typeof g=="string"&&(m=Number.parseFloat(g)));let k=null,f=h(e.properties,"height");f!==null&&(typeof f=="number"?k=f:typeof f=="string"&&(k=Number.parseFloat(f)));let y=!0,x=h(e.properties,"is-full-width");x!==null&&(y=x==="Yes");let I=!0,E=h(e.properties,"is-full-height");E!==null&&(I=E==="Yes");let d=h(e.properties,"image-quality");d??="high";let b=h(e.properties,"caption-source");b??="name";let w=h(e.properties,"alt-text-source");w??="name";let v=!1,p=h(e.properties,"is-transparent");p!==null&&(v=p==="Yes");let T=!1,C=h(e.properties,"is-cover");C!==null&&(T=C==="Yes");let U=null;if(a.length>1){let $=_(e.properties,"variant"),V=5;if($&&$.values[0].content==="carousel"){let F=h($.properties,"seconds-per-image");F!==null&&(typeof F=="number"?V=F:typeof F=="string"&&(V=Number.parseFloat(F)))}U={secondsPerImage:V}}t.images=a,t.variant=l,t.width=m,t.height=k,t.isFullWidth=y,t.isFullHeight=I,t.imageQuality=d,t.captionLayout=c,t.captionSource=b,t.altTextSource=w,t.isTransparentBackground=v,t.isCover=T,t.carouselOptions=U;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=h(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=h(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=h(e.properties,"variant");a??="block";let l=h(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=h(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 K(e){let r=P(e.identification),t=(e.properties?.property?O(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]).find(b=>b.label==="presentation");if(!t)throw new Error(`Presentation property not found for element \u201C${r.label}\u201D`);let i=t.properties.find(b=>b.label==="component");if(!i)throw new Error(`Component for element \u201C${r.label}\u201D not found`);let s=await Ge(i,e),a=t.properties.find(b=>b.label==="section-sidebar-displayed")?.values[0]?.booleanValue===!0,l=e.properties?.property?O(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],c=l.find(b=>b.label==="presentation"&&b.values[0].content==="css")?.properties??[],m=[];for(let b of c){let w=b.values[0].content;m.push({label:b.label,value:w})}let g=l.find(b=>b.label==="presentation"&&b.values[0].content==="css-mobile")?.properties??[],k=[];for(let b of g){let w=b.values[0].content;k.push({label:b.label,value:w})}let f=l.find(b=>b.label==="presentation"&&b.values[0].content==="title")?.properties,y="default",x=!1,I=!1,E=!1,d=!1;if(f){let b=h(f,"variant");b&&(y=b);let w=f.filter(v=>v.label==="display");w.length>0&&(x=w.some(v=>v.values[0].content==="name"),I=w.some(v=>v.values[0].content==="description"),E=w.some(v=>v.values[0].content==="date"),d=w.some(v=>v.values[0].content==="creators"))}return{uuid:e.uuid,type:"element",title:{label:r.label,variant:y,properties:{isNameDisplayed:x,isDescriptionDisplayed:I,isDateDisplayed:E,isCreatorsDisplayed:d}},isDisplayedInBlockSectionSidebar:a,cssStyles:m,cssStylesMobile:k,...s}}async function Ee(e){let r=e.properties?O(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];if(r.length===0||r.find(d=>d.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(d=>d.type==="image"||d.type==="IIIF"),o=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],a=[];for(let d of o){let b=d.properties?O(Array.isArray(d.properties.property)?d.properties.property:[d.properties.property]):[],w=h(b,"presentation");if(w!=null)switch(w){case"element":{let v=await K(d);a.push(v);break}case"block":{let v=await ce(d);v&&a.push(v);break}}}let l=e.resource?await ae(Array.isArray(e.resource)?e.resource:[e.resource],"page"):[],c=!0,m="default",g="default",k=!0,f=r.find(d=>d.label==="presentation"&&d.values[0]?.content==="page")?.properties;if(f){let d=f.find(p=>p.label==="header")?.values[0];d&&(c=d.content==="Yes");let b=f.find(p=>p.label==="width")?.values[0];b&&(m=b.content);let w=f.find(p=>p.label==="variant")?.values[0];w&&(g=w.content);let v=f.find(p=>p.label==="sidebar-visible")?.values[0];v&&(k=v.content==="Yes")}let y=r.find(d=>d.label==="presentation"&&d.values[0]?.content==="css")?.properties,x=[];if(y)for(let d of y)x.push({label:d.label,value:d.values[0].content});let I=r.find(d=>d.label==="presentation"&&d.values[0]?.content==="css-mobile")?.properties,E=[];if(I)for(let d of I)E.push({label:d.label,value:d.values[0].content});return{title:n.label,slug:t,items:a,properties:{displayedInHeader:c,width:m,variant:g,backgroundImageUrl:s?`https://ochre.lib.uchicago.edu/ochre?uuid=${s.uuid}&load`:null,isSidebarDisplayed:k,cssStyles:x,cssStylesMobile:E},webpages:l}}async function Ke(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n){let i=await Ee(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?O(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(y=>y.label==="layout")?.values[0];l&&(r.layout=l.content);let c=t.find(y=>y.label==="spacing")?.values[0];c&&(r.properties.spacing=c.content);let m=t.find(y=>y.label==="gap")?.values[0];m&&(r.properties.gap=m.content);let g=t.find(y=>y.label==="align-items")?.values[0];g&&(r.properties.alignItems=g.content);let k=t.find(y=>y.label==="justify-content")?.values[0];k&&(r.properties.justifyContent=k.content);let f=t.find(y=>y.label==="overwrite-mobile");if(f){let y=f.properties,x={};for(let I of y)x[I.label]=I.values[0].content;r.propertiesMobile=x}}let i=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],s=[];for(let l of i){let c=l.properties?O(Array.isArray(l.properties.property)?l.properties.property:[l.properties.property]):[],m=h(c,"presentation");if(m!=null)switch(m){case"element":{let g=await K(l);s.push(g);break}case"block":{let g=await ce(l);g&&s.push(g);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 Je(e){let n=O(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,We]=(l.values[0]?.content).split(";");a={name:A,email:We??null}}let c=n.find(A=>A.label==="logo")?.values[0]?.uuid??null,m=!0,g="default",k="start",f=!0,y=!0,x=!1,I=null,E=!0,d=n.find(A=>A.label==="navbar-visible")?.values[0];d&&(m=d.content==="Yes");let b=n.find(A=>A.label==="navbar-variant")?.values[0];b&&(g=b.content);let w=n.find(A=>A.label==="navbar-alignment")?.values[0];w&&(k=w.content);let v=n.find(A=>A.label==="navbar-project-visible")?.values[0];v&&(f=v.content==="Yes");let p=n.find(A=>A.label==="footer-visible")?.values[0];p&&(y=p.content==="Yes");let T=n.find(A=>A.label==="sidebar-visible")?.values[0];T&&(x=T.content==="Yes");let C=n.find(A=>A.label==="search-collection")?.values[0];C&&(I=C.uuid);let U=n.find(A=>A.label==="supports-theme-toggle")?.values[0];U&&(E=U.content==="Yes");let{type:$,status:V,privacy:F}=o.data;return{type:$,privacy:F,status:V,contact:a,isHeaderDisplayed:m,headerVariant:g,headerAlignment:k,isHeaderProjectDisplayed:f,isFooterDisplayed:y,isSidebarDisplayed:x,supportsThemeToggle:E,searchCollectionUuid:I,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=Je(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 Ke(i),o=null,a=[],l={label:"",variant:"default",properties:{isNameDisplayed:!1,isDescriptionDisplayed:!1,isDateDisplayed:!1,isCreatorsDisplayed:!1}},c="start",m="default",g=[],k=[],f=i.find(y=>(y.properties?O(Array.isArray(y.properties.property)?y.properties.property:[y.properties.property]):[]).some(I=>I.label==="presentation"&&I.values[0]?.content==="element"&&I.properties[0]?.label==="component"&&I.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"?u(f.identification.label):S(f.identification.label);let y=f.properties?O(Array.isArray(f.properties.property)?f.properties.property:[f.properties.property]):[],x=y.find(p=>p.label==="presentation"&&p.values[0]?.content==="element")?.properties.find(p=>p.label==="component"&&p.values[0]?.content==="sidebar")?.properties??[],I=x.find(p=>p.label==="layout");I&&(c=I.values[0].content);let E=x.find(p=>p.label==="layout-mobile");E&&(m=E.values[0].content);let d=y.find(p=>p.label==="presentation"&&p.values[0].content==="css")?.properties??[];for(let p of d){let T=p.values[0].content;g.push({label:p.label,value:T})}let b=y.find(p=>p.label==="presentation"&&p.values[0].content==="css-mobile")?.properties??[];for(let p of b){let T=p.values[0].content;k.push({label:p.label,value:T})}let w=y.find(p=>p.label==="presentation"&&p.values[0].content==="title")?.properties;if(w){let p=h(w,"variant");p&&(l.variant=p);let T=w.filter(C=>C.label==="display");T.length>0&&(l.properties.isNameDisplayed=T.some(C=>C.values[0].content==="name"),l.properties.isDescriptionDisplayed=T.some(C=>C.values[0].content==="description"),l.properties.isDateDisplayed=T.some(C=>C.values[0].content==="date"),l.properties.isCreatorsDisplayed=T.some(C=>C.values[0].content==="creators"))}let v=f.resource?Array.isArray(f.resource)?f.resource:[f.resource]:[];for(let p of v){let T=await K(p);a.push(T)}}return a.length>0&&(o={elements:a,title:l,layout:c,mobileLayout:m,cssStyles:g,cssStylesMobile:k}),{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:P(e.identification),project:{name:u(r),website:n!==null?u(n):null},creators:e.creators?L(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:B(e.availability),pages:s,sidebar:o,properties:t}}async function bt(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 z(t)}}else return z(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
|
|
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 m=P(c.result.gallery.item.identification),g=P(c.result.gallery.project.identification);return{item:{identification:m,projectIdentification:g,resources:M(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 At(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 Le(n.result.ochre.tree,t?.label??"",n.result.ochre.metadata.project?.identification.website??null)}catch(r){return console.error(r),null}}export{we as fetchByUuid,bt as fetchGallery,ve as fetchItem,At as fetchWebsite,Be as filterProperties,Fe as getAllPropertyLabels,_ as getPropertyByLabel,h as getPropertyValueByLabel,ge as getPropertyValuesByLabel,G as parseBibliographies,ee as parseBibliography,ie as parseConcept,Ce as parseConcepts,H as parseContext,Ie as parseCoordinates,se as parseDocument,W as parseEmail,He as parseEvents,u as parseFakeString,P as parseIdentification,xe as parseImage,qe as parseImageMap,Ye as parseInterpretations,Ue as parseLanguages,B as parseLicense,Ve as parseLink,j as parseLinks,Se as parseMetadata,le as parseNotes,De as parseObservation,Ne as parseObservations,Z as parsePeriod,q as parsePeriods,X as parsePerson,L as parsePersons,O as parseProperties,Me as parseProperty,te as parsePropertyValue,Te as parsePropertyValues,re as parseResource,M as parseResources,ke as parseSet,ne as parseSpatialUnit,Oe as parseSpatialUnits,S as parseStringContent,R as parseStringDocumentItem,z 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.
|
|
3
|
+
"version": "0.7.2",
|
|
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",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@antfu/eslint-config": "^4.13.0",
|
|
48
|
-
"@arethetypeswrong/cli": "^0.
|
|
48
|
+
"@arethetypeswrong/cli": "^0.18.0",
|
|
49
49
|
"@changesets/cli": "^2.29.3",
|
|
50
50
|
"@total-typescript/ts-reset": "^0.6.1",
|
|
51
|
-
"@types/node": "^22.15.
|
|
51
|
+
"@types/node": "^22.15.17",
|
|
52
52
|
"eslint": "^9.26.0",
|
|
53
53
|
"eslint-plugin-unused-imports": "^4.1.4",
|
|
54
54
|
"prettier": "^3.5.3",
|