@digitalculture/ochre-sdk 0.7.11 → 0.7.12
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/README.md +0 -53
- package/dist/index.cjs +580 -7
- package/dist/index.d.cts +686 -596
- package/dist/index.d.ts +686 -596
- package/dist/index.js +580 -7
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -1,13 +1,586 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
${JSON.stringify(e.content)}.`);return G(t)}}else return G(e.content);default:return String(e.content).replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}}function J(e){let r=e.find(t=>ae.safeParse(t).success);if(!r){let t=e.find(i=>!["uuid","uuidBelongsTo","belongsTo","publicationDateTime","metadata","languages"].includes(i));throw new Error(`Invalid OCHRE data; found unexpected "${t}" key`)}return ae.parse(r)}async function ce(e){try{let r=ke.parse(e),n=await fetch(`https://ochre.lib.uchicago.edu/ochre?uuid=${r}&format=json&lang="*"`);if(!n.ok)throw new Error("Failed to fetch OCHRE data");let t=await n.json();if(!("ochre"in t))throw new Error("Invalid OCHRE data: API response missing 'ochre' key");return[null,t]}catch(r){return[r instanceof Error?r.message:"Unknown error",null]}}async function pe(e,r,n){try{let[t,i]=await ce(e);if(t!==null)throw new Error(t);let s=J(Object.keys(i.ochre)),o;switch(s){case"resource":{if(!("resource"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'resource' key");o=X(i.ochre.resource);break}case"spatialUnit":{if(!("spatialUnit"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'spatialUnit' key");o=Z(i.ochre.spatialUnit);break}case"concept":{if(!("concept"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'concept' key");o=ee(i.ochre.concept);break}case"period":{if(!("period"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'period' key");o=z(i.ochre.period);break}case"bibliography":{if(!("bibliography"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'bibliography' key");o=Q(i.ochre.bibliography);break}case"person":{if(!("person"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'person' key");o=_(i.ochre.person);break}case"propertyValue":{if(!("propertyValue"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'propertyValue' key");o=R(i.ochre.propertyValue);break}case"set":{if(!("set"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'set' key");o=fe(i.ochre.set,n);break}case"tree":{if(!("tree"in i.ochre))throw new Error("Invalid OCHRE data: API response missing 'tree' key");o=de(i.ochre.tree);break}default:throw new Error("Invalid category")}let a=ue(i.ochre.metadata),l={uuid:i.ochre.uuidBelongsTo,abbreviation:p(i.ochre.belongsTo)};return{error:null,metadata:a,belongsTo:l,item:o,category:r}}catch(t){return{error:t instanceof Error?t.message:"Unknown error",metadata:void 0,belongsTo:void 0,item:void 0,category:void 0}}}function P(e){try{let r={label:["string","number","boolean"].includes(typeof e.label)?p(e.label):S(e.label),abbreviation:""};for(let n of Object.keys(e).filter(t=>t!=="label"))r[n]=S(e[n]);return r}catch(r){return console.error(r),{label:"",abbreviation:""}}}function Fe(e){return e==null?["eng"]:Array.isArray(e)?e.map(r=>S(r)):[S(e)]}function ue(e){let r={label:"",abbreviation:""};if(e.item)if(e.item.label||e.item.abbreviation){let i="",s="";e.item.label&&(i=S(e.item.label)),e.item.abbreviation&&(s=S(e.item.abbreviation)),r={label:i,abbreviation:s}}else r=P(e.item.identification);let n=null,t=e.project?.identification?P(e.project.identification):null;return t&&(n={...t,website:e.project?.identification.website??null}),{project:n?{identification:n}:null,item:e.item?{identification:r,category:e.item.category,type:e.item.type,maxLength:e.item.maxLength??null}:null,dataset:S(e.dataset),publisher:S(e.publisher),languages:Fe(e.language),identifier:S(e.identifier),description:S(e.description)}}function ye(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,number:e.n,content:p(e.content)}}function V(e){return{nodes:(Array.isArray(e.context)?e.context:[e.context]).map(t=>{let i=[];if("spatialUnit"in t&&t.spatialUnit){let s=Array.isArray(t.spatialUnit)?t.spatialUnit:[t.spatialUnit];for(let o of s)i.push(ye(o))}return{tree:ye(t.tree),project:ye(t.project),spatialUnit:i}}),displayPath:e.displayPath}}function B(e){return typeof e.license=="string"?null:{content:e.license.content,url:e.license.target}}function _(e){return{uuid:e.uuid,category:"person",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type??null,number:e.n??null,context:e.context?V(e.context):null,date:e.date!=null?new Date(e.date):null,identification:e.identification?P(e.identification):null,availability:e.availability?B(e.availability):null,address:e.address?{country:e.address.country??null,city:e.address.city??null,state:e.address.state??null}:null,coordinates:e.coordinates?te(e.coordinates):null,content:e.content!=null?p(e.content):null,events:e.events?ge(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function W(e){let r=[];for(let n of e)r.push(_(n));return r}function Be(e){let r="resource"in e?e.resource:"spatialUnit"in e?e.spatialUnit:"concept"in e?e.concept:"set"in e?e.set:"tree"in e?e.tree:"person"in e?e.person:"bibliography"in e?e.bibliography:"epigraphicUnit"in e?e.epigraphicUnit:"propertyValue"in e?e.propertyValue:null;if(!r)throw new Error(`Invalid link provided: ${JSON.stringify(e,null,2)}`);let n=Array.isArray(r)?r:[r],t=[];for(let i of n){let s={category:"resource"in e?"resource":"spatialUnit"in e?"spatialUnit":"concept"in e?"concept":"set"in e?"set":"person"in e?"person":"tree"in e?"tree":"bibliography"in e?"bibliography":"epigraphicUnit"in e?"epigraphicUnit":"propertyValue"in e?"propertyValue":null,content:"content"in i&&i.content!=null?p(i.content):null,href:"href"in i&&i.href!=null?i.href:null,uuid:i.uuid,type:i.type??null,identification:i.identification?P(i.identification):null,image:null,bibliographies:"bibliography"in e?Y(Array.isArray(e.bibliography)?e.bibliography:[e.bibliography]):null,publicationDateTime:i.publicationDateTime!=null?new Date(i.publicationDateTime):null};"height"in i&&i.height!=null&&i.width!=null&&i.heightPreview!=null&&i.widthPreview!=null&&(s.image={isInline:i.rend==="inline",isPrimary:i.isPrimary??!1,heightPreview:i.heightPreview,widthPreview:i.widthPreview,height:i.height,width:i.width}),t.push(s)}return t}function j(e){let r=[];for(let n of e)r.push(...Be(n));return r}function re(e,r="eng"){let n="",t=[],i=Array.isArray(e)?e.find(s=>s.lang===r):e;if(typeof i.string=="string"||typeof i.string=="number"||typeof i.string=="boolean")n+=F(p(i.string));else{let s=Array.isArray(i.string)?i.string:[i.string];for(let o of s)n+=K(o,t)}return{content:n,footnotes:t}}function me(e){return{publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,identification:e.identification?P(e.identification):null,url:e.href??(e.htmlImgSrcPrefix==null&&e.content!=null?p(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?p(e.content):null,widthPreview:e.widthPreview??null,heightPreview:e.heightPreview??null,width:e.width??null,height:e.height??null}}function ne(e,r="eng"){let n=[];for(let t of e){if(typeof t=="string"){if(t==="")continue;n.push({number:-1,title:null,content:t});continue}let i="",s=Array.isArray(t.content)?t.content:[t.content],o=s.find(a=>a.lang===r);if(!o&&(o=s[0],!o))throw new Error(`Note does not have a valid content item: ${JSON.stringify(t,null,2)}`);typeof o.string=="string"||typeof o.string=="number"||typeof o.string=="boolean"?i=F(p(o.string)):i=F(re(o).content),n.push({number:t.noteNo,title:o.title!=null?p(o.title):null,content:i})}return n}function te(e){if(typeof e=="string"){let[r,n]=e.split(", ");return{latitude:Number(r),longitude:Number(n),type:null,label:null}}return{latitude:e.latitude,longitude:e.longitude,type:e.coord?.coordType??null,label:e.coord?.coordLabel!=null?p(e.coord.coordLabel):null}}function be(e){return{number:e.observationNo,date:e.date!=null?new Date(e.date):null,observers:e.observers!=null?p(e.observers).split(";").map(r=>r.trim()):[],notes:e.notes?ne(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?j(Array.isArray(e.links)?e.links:[e.links]):[],properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function Ue(e){let r=[];for(let n of e)r.push(be(n));return r}function ge(e){let r=[];for(let n of e)r.push({date:n.dateTime!=null?new Date(n.dateTime):null,label:S(n.label),agent:n.agent?{uuid:n.agent.uuid,content:p(n.agent.content)}:null});return r}function je(e,r="eng"){let t=("value"in e&&e.value?Array.isArray(e.value)?e.value:[e.value]:[]).map(i=>{let s=null,o=null;if(typeof i=="string"||typeof i=="number"||typeof i=="boolean")return s=p(i),{content:s,booleanValue:o,isUncertain:!1,type:"string",category:"value",uuid:null,publicationDateTime:null,unit:null};{switch(i.type){case"integer":case"decimal":{s=Number(i.content);break}case"dateTime":{s=i.content?typeof i.content=="string"?new Date(i.content):new Date(S({content:i.content})):null;break}default:{"slug"in i&&i.slug!=null?s=p(i.slug):i.content!=null&&(s=S({content:i.content})),i.type==="boolean"&&(o=i.booleanValue??null);break}}let a="string";if(i.type!=null){let{data:c,error:y}=De.safeParse(i.type);if(y)throw new Error(`Invalid property value content type: "${i.type}"`);a=c}return{content:s,booleanValue:o,isUncertain:i.isUncertain??!1,type:a,category:i.category??"value",uuid:i.uuid??null,publicationDateTime:i.publicationDateTime!=null?new Date(i.publicationDateTime):null,unit:i.unit??null}}});return{uuid:e.label.uuid,label:S(e.label,r).replace(/\s*\.{3}$/,"").trim(),values:t,comment:e.comment!=null?p(e.comment):null,properties:e.property?T(Array.isArray(e.property)?e.property:[e.property]):[]}}function T(e,r="eng"){let n=[];for(let t of e)n.push(je(t,r));return n}function Ve(e){let r=[];for(let n of e)r.push({date:new Date(n.date),number:n.interpretationNo,properties:n.properties?T(Array.isArray(n.properties.property)?n.properties.property:[n.properties.property]):[]});return r}function Ne(e){let r={area:[],width:e.width,height:e.height},n=Array.isArray(e.area)?e.area:[e.area];for(let t of n)r.area.push({uuid:t.uuid,publicationDateTime:t.publicationDateTime!=null?new Date(t.publicationDateTime):null,type:t.type,title:p(t.title),shape:t.shape==="rect"?"rectangle":"polygon",coords:t.coords.split(",").map(i=>Number.parseInt(i))});return r}function z(e){return{uuid:e.uuid,category:"period",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type??null,number:e.n??null,identification:P(e.identification),description:e.description?S(e.description):null}}function M(e){let r=[];for(let n of e)r.push(z(n));return r}function Q(e){let r=null;return e.source?.resource&&(r={uuid:e.source.resource.uuid,publicationDateTime:e.source.resource.publicationDateTime?new Date(e.source.resource.publicationDateTime):null,type:e.source.resource.type,identification:P(e.source.resource.identification)}),{uuid:e.uuid,category:"bibliography",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type??null,number:e.n??null,identification:e.identification?P(e.identification):null,projectIdentification:e.project?.identification?P(e.project.identification):null,context:e.context?V(e.context):null,citation:{format:e.citationFormat??null,short:e.citationFormatSpan?p("default:span"in e.citationFormatSpan?e.citationFormatSpan["default:span"].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?p("default:div"in e.referenceFormatDiv?e.referenceFormatDiv["default:div"]["default:div"].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?W(Array.isArray(e.publicationInfo.publishers.publishers.person)?e.publicationInfo.publishers.publishers.person:[e.publicationInfo.publishers.publishers.person]):[],startDate:e.publicationInfo?.startDate?new Date(e.publicationInfo.startDate.year,e.publicationInfo.startDate.month,e.publicationInfo.startDate.day):null},entryInfo:e.entryInfo?{startIssue:p(e.entryInfo.startIssue),startVolume:p(e.entryInfo.startVolume)}:null,source:{resource:r,documentUrl:e.sourceDocument?`https://ochre.lib.uchicago.edu/ochre?uuid=${e.sourceDocument.uuid}&load`:null},periods:e.periods?M(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],authors:e.authors?W(Array.isArray(e.authors.person)?e.authors.person:[e.authors.person]):[],properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function Y(e){let r=[];for(let n of e)r.push(Q(n));return r}function R(e){return{uuid:e.uuid,category:"propertyValue",number:e.n,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,context:e.context?V(e.context):null,availability:e.availability?B(e.availability):null,identification:P(e.identification),date:e.date?new Date(e.date):null,creators:e.creators?W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],description:e.description?["string","number","boolean"].includes(typeof e.description)?p(e.description):S(e.description):"",notes:e.notes?ne(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?j(Array.isArray(e.links)?e.links:[e.links]):[]}}function Ae(e){let r=[];for(let n of e)r.push(R(n));return r}function de(e){let r=[];e.creators&&(r=W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]));let n=null;e.date!=null&&(n=new Date(e.date));let t=[],i=[],s=[],o=[],a=[],l=[],c=[];return typeof e.items!="string"&&"resource"in e.items&&(t=N(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource])),typeof e.items!="string"&&"spatialUnit"in e.items&&(i=ve(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit])),typeof e.items!="string"&&"concept"in e.items&&(s=we(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept])),typeof e.items!="string"&&"period"in e.items&&(o=M(Array.isArray(e.items.period)?e.items.period:[e.items.period])),typeof e.items!="string"&&"bibliography"in e.items&&(a=Y(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography])),typeof e.items!="string"&&"person"in e.items&&(l=W(Array.isArray(e.items.person)?e.items.person:[e.items.person])),typeof e.items!="string"&&"propertyValue"in e.items&&(c=Ae(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue])),{uuid:e.uuid,category:"tree",publicationDateTime:new Date(e.publicationDateTime),identification:P(e.identification),creators:r,license:B(e.availability),date:n,type:e.type,number:e.n,items:{resources:t,spatialUnits:i,concepts:s,periods:o,bibliographies:a,persons:l,propertyValues:c},properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function fe(e,r){if(typeof e.items=="string")throw new TypeError("Invalid OCHRE data: Set has no items");let n=r??J(Object.keys(e.items)),t=[];switch(n){case"resource":{if(!("resource"in e.items))throw new Error("Invalid OCHRE data: Set has no resources");t=N(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource]);break}case"spatialUnit":{if(!("spatialUnit"in e.items))throw new Error("Invalid OCHRE data: Set has no spatial units");t=ve(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit]);break}case"concept":{if(!("concept"in e.items))throw new Error("Invalid OCHRE data: Set has no concepts");t=we(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept]);break}case"period":{if(!("period"in e.items))throw new Error("Invalid OCHRE data: Set has no periods");t=M(Array.isArray(e.items.period)?e.items.period:[e.items.period]);break}case"bibliography":{if(!("bibliography"in e.items))throw new Error("Invalid OCHRE data: Set has no bibliographies");t=Y(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography]);break}case"person":{if(!("person"in e.items))throw new Error("Invalid OCHRE data: Set has no persons");t=W(Array.isArray(e.items.person)?e.items.person:[e.items.person]);break}case"propertyValue":{if(!("propertyValue"in e.items))throw new Error("Invalid OCHRE data: Set has no property values");t=Ae(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]);break}default:throw new Error("Invalid OCHRE data: Set has no items or is malformed")}return{uuid:e.uuid,category:"set",itemCategory:r,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,date:e.date!=null?new Date(e.date):null,license:B(e.availability),identification:P(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?["string","number","boolean"].includes(typeof e.description)?p(e.description):S(e.description):"",creators:e.creators?W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],type:e.type,number:e.n,items:t}}function X(e){return{uuid:e.uuid,category:"resource",publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,type:e.type,number:e.n,format:e.format??null,context:"context"in e&&e.context?V(e.context):null,license:"availability"in e&&e.availability?B(e.availability):null,copyright:"copyright"in e&&e.copyright!=null?p(e.copyright):null,identification:P(e.identification),date:e.date!=null?new Date(e.date):null,image:e.image?me(e.image):null,creators:e.creators?W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],notes:e.notes?ne(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],description:e.description?["string","number","boolean"].includes(typeof e.description)?p(e.description):S(e.description):"",document:e.document&&"content"in e.document?re(e.document.content):null,href:e.href??null,imageMap:e.imagemap?Ne(e.imagemap):null,periods:e.periods?M(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],links:e.links?j(Array.isArray(e.links)?e.links:[e.links]):[],reverseLinks:e.reverseLinks?j(Array.isArray(e.reverseLinks)?e.reverseLinks:[e.reverseLinks]):[],properties:e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],citedBibliographies:e.citedBibliography?Y(Array.isArray(e.citedBibliography.reference)?e.citedBibliography.reference:[e.citedBibliography.reference]):[],resources:e.resource?N(Array.isArray(e.resource)?e.resource:[e.resource]):[]}}function N(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(X(t));return r}function Z(e){return{uuid:e.uuid,category:"spatialUnit",publicationDateTime:e.publicationDateTime!=null?new Date(e.publicationDateTime):null,type:e.type,number:e.n,context:"context"in e&&e.context?V(e.context):null,license:"availability"in e&&e.availability?B(e.availability):null,identification:P(e.identification),image:e.image?me(e.image):null,description:e.description?["string","number","boolean"].includes(typeof e.description)?p(e.description):S(e.description):"",coordinates:e.coordinates?te(e.coordinates):e.coordinate?te(e.coordinate):null,observations:"observations"in e&&e.observations?Ue(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[be(e.observation)]:[],events:"events"in e&&e.events?ge(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:"properties"in e&&e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}function ve(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(Z(t));return r}function ee(e){return{uuid:e.uuid,category:"concept",publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,number:e.n,license:"availability"in e&&e.availability?B(e.availability):null,context:"context"in e&&e.context?V(e.context):null,identification:P(e.identification),interpretations:Ve(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation])}}var he=async(e,r)=>{let n=[];for(let t of e)if((t.properties?T(Array.isArray(t.properties.property)?t.properties.property:[t.properties.property]):[]).find(o=>o.label==="presentation"&&o.values[0].content===r))switch(r){case"element":{let o=await ie(t);n.push(o);break}case"page":{let o=await He(t);o&&n.push(o);break}case"block":{let o=await Se(t);o&&n.push(o);break}}return n};function we(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n)r.push(ee(t));return r}async function Qe(e,r){let n=xe.parse(e.values[0].content),t={component:n},i=r.links?j(Array.isArray(r.links)?r.links:[r.links]):[],s=i.filter(a=>a.type==="image"||a.type==="IIIF"),o=r.document&&"content"in r.document?re(r.document.content):null;if(o===null){let a=i.find(l=>l.type==="internalDocument");if(a){let{item:l,error:c}=await pe(a.uuid,"resource");if(c!==null)throw new Error("Failed to fetch OCHRE data");o=l.document}}switch(n){case"annotated-document":{if(!o)throw new Error(`Document not found for the following component: \u201C${n}\u201D`);t.document=o;break}case"annotated-image":{if(s.length===0)throw new Error(`Image link not found for the following component: \u201C${n}\u201D`);let a=d(e.properties,"is-searchable")==="Yes";t.imageUuid=s[0].uuid,t.isSearchable=a;break}case"bibliography":{let a=i.find(c=>c.category==="bibliography");if(!a)throw new Error(`Bibliography link not found for the following component: \u201C${n}\u201D`);if(!a.bibliographies)throw new Error(`Bibliography not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"layout");l??="long",t.bibliographies=a.bibliographies,t.layout=l;break}case"button":{let a=d(e.properties,"variant");a??="default";let l=!1,c=d(e.properties,"navigate-to");if(c===null){if(c=d(e.properties,"link-to"),c===null)throw new Error(`Properties \u201Cnavigate-to\u201D or \u201Clink-to\u201D not found for the following component: \u201C${n}\u201D`);l=!0}let y=null,b=d(e.properties,"icon");b!==null&&(y=b),t.variant=a,t.href=c,t.isExternal=l,t.label=["string","number","boolean"].includes(typeof r.identification.label)?p(r.identification.label):S(r.identification.label),t.icon=y;break}case"collection":{let a=i.find(v=>v.category==="set");if(!a)throw new Error(`Collection link not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"variant");l??="full";let c=d(e.properties,"item-variant");c??="default";let y=!1,b=d(e.properties,"show-count");b!==null&&(y=b==="Yes");let x=!1,f=d(e.properties,"is-searchable");f!==null&&(x=f==="Yes");let g=d(e.properties,"layout");g??="image-start",t.collectionId=a.uuid,t.variant=l,t.itemVariant=c,t.isSearchable=x,t.showCount=y,t.layout=g;break}case"empty-space":{let a=d(e.properties,"height"),l=d(e.properties,"width");t.height=a,t.width=l;break}case"entries":{let a=i.find(b=>b.category==="tree");if(!a)throw new Error(`Entries link not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"variant");l??="entry";let c=!1,y=d(e.properties,"is-searchable");y!==null&&(c=y==="Yes"),t.entriesId=a.uuid,t.variant=l,t.isSearchable=c;break}case"filter-categories":{let a=i.find(l=>l.category==="set");if(!a)throw new Error(`Filter link not found for the following component: \u201C${n}\u201D`);t.filterId=a.uuid;break}case"iframe":{let a=i.find(y=>y.type==="webpage")?.href;if(!a)throw new Error(`URL not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"height"),c=d(e.properties,"width");t.href=a,t.height=l,t.width=c;break}case"iiif-viewer":{let a=i.find(l=>l.type==="IIIF");if(!a)throw new Error(`Manifest link not found for the following component: \u201C${n}\u201D`);t.IIIFId=a.uuid;break}case"image":{if(s.length===0)throw new Error(`Image link not found for the following component: \u201C${n}\u201D`);let a=[];for(let L of s)a.push({url:`https://ochre.lib.uchicago.edu/ochre?uuid=${L.uuid}&load`,label:L.identification?.label??null,width:L.image?.width??0,height:L.image?.height??0});let l=d(e.properties,"variant");l??="default";let c=d(e.properties,"layout-caption");c??="bottom";let y=null,b=d(e.properties,"width");b!==null&&(typeof b=="number"?y=b:typeof b=="string"&&(y=Number.parseFloat(b)));let x=null,f=d(e.properties,"height");f!==null&&(typeof f=="number"?x=f:typeof f=="string"&&(x=Number.parseFloat(f)));let g=!0,v=d(e.properties,"is-full-width");v!==null&&(g=v==="Yes");let O=!0,k=d(e.properties,"is-full-height");k!==null&&(O=k==="Yes");let u=d(e.properties,"image-quality");u??="high";let h=d(e.properties,"caption-source");h??="name";let I=d(e.properties,"alt-text-source");I??="name";let w=!1,C=d(e.properties,"is-transparent");C!==null&&(w=C==="Yes");let m=!1,E=d(e.properties,"is-cover");E!==null&&(m=E==="Yes");let $=null;if(a.length>1){let L=q(e.properties,"variant"),A=5;if(L&&L.values[0].content==="carousel"){let U=d(L.properties,"seconds-per-image");U!==null&&(typeof U=="number"?A=U:typeof U=="string"&&(A=Number.parseFloat(U)))}$={secondsPerImage:A}}t.images=a,t.variant=l,t.width=y,t.height=x,t.isFullWidth=g,t.isFullHeight=O,t.imageQuality=u,t.captionLayout=c,t.captionSource=h,t.altTextSource=I,t.isTransparentBackground=w,t.isCover=m,t.carouselOptions=$;break}case"image-gallery":{let a=i.find(c=>c.category==="tree"||c.category==="set");if(!a)throw new Error(`Image gallery link not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"is-searchable")==="Yes";t.galleryId=a.uuid,t.isSearchable=l;break}case"n-columns":{let a=r.resource?await he(Array.isArray(r.resource)?r.resource:[r.resource],"element"):[];t.columns=a;break}case"n-rows":{let a=r.resource?await he(Array.isArray(r.resource)?r.resource:[r.resource],"element"):[];t.rows=a;break}case"network-graph":break;case"table":{let a=i.find(l=>l.category==="set");if(!a)throw new Error(`Table link not found for the following component: \u201C${n}\u201D`);t.tableId=a.uuid;break}case"search-bar":{let a=d(e.properties,"variant");a??="default",t.variant=a;break}case"text":{if(!o)throw new Error(`Document not found for the following component: \u201C${n}\u201D`);let a=d(e.properties,"variant");a??="block";let l=d(e.properties,"heading");t.variant=a,t.heading=l,t.content=o.content;break}case"timeline":{let a=i.find(l=>l.category==="tree");if(!a)throw new Error(`Timeline link not found for the following component: \u201C${n}\u201D`);t.timelineId=a.uuid;break}case"video":{let a=i.find(c=>c.type==="video");if(!a)throw new Error(`Video link not found for the following component: \u201C${n}\u201D`);let l=d(e.properties,"chapters-displayed");l??="Yes",t.videoId=a.uuid,t.isChaptersDislayed=l==="Yes";break}default:{console.warn(`Invalid or non-implemented component name \u201C${n}\u201D for the following element: \u201C${S(r.identification.label)}\u201D`);break}}return t}async function ie(e){let r=P(e.identification),t=(e.properties?.property?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]).find(h=>h.label==="presentation");if(!t)throw new Error(`Presentation property not found for element \u201C${r.label}\u201D`);let i=t.properties.find(h=>h.label==="component");if(!i)throw new Error(`Component for element \u201C${r.label}\u201D not found`);let s=await Qe(i,e),a=t.properties.find(h=>h.label==="section-sidebar-displayed")?.values[0]?.booleanValue===!0,l=e.properties?.property?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],c=l.find(h=>h.label==="presentation"&&h.values[0].content==="css")?.properties??[],y=[];for(let h of c){let I=h.values[0].content;y.push({label:h.label,value:I})}let b=l.find(h=>h.label==="presentation"&&h.values[0].content==="css-mobile")?.properties??[],x=[];for(let h of b){let I=h.values[0].content;x.push({label:h.label,value:I})}let f=l.find(h=>h.label==="presentation"&&h.values[0].content==="title")?.properties,g="default",v=!1,O=!1,k=!1,u=!1;if(f){let h=d(f,"variant");h&&(g=h);let I=f.filter(w=>w.label==="display");I.length>0&&(v=I.some(w=>w.values[0].content==="name"),O=I.some(w=>w.values[0].content==="description"),k=I.some(w=>w.values[0].content==="date"),u=I.some(w=>w.values[0].content==="creators"))}return{uuid:e.uuid,type:"element",title:{label:r.label,variant:g,properties:{isNameDisplayed:v,isDescriptionDisplayed:O,isDateDisplayed:k,isCreatorsDisplayed:u}},isDisplayedInBlockSectionSidebar:a,cssStyles:y,cssStylesMobile:x,...s}}async function He(e){let r=e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];if(r.length===0||r.find(u=>u.label==="presentation")?.values[0]?.content!=="page")return null;let n=P(e.identification),t=e.slug;if(t===void 0)throw new Error(`Slug not found for page \u201C${n.label}\u201D`);let s=(e.links?j(Array.isArray(e.links)?e.links:[e.links]):[]).find(u=>u.type==="image"||u.type==="IIIF"),o=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],a=[];for(let u of o){let h=u.properties?T(Array.isArray(u.properties.property)?u.properties.property:[u.properties.property]):[],I=d(h,"presentation");if(I!=null)switch(I){case"element":{let w=await ie(u);a.push(w);break}case"block":{let w=await Se(u);w&&a.push(w);break}}}let l=e.resource?await he(Array.isArray(e.resource)?e.resource:[e.resource],"page"):[],c=!0,y="default",b="default",x=!0,f=r.find(u=>u.label==="presentation"&&u.values[0]?.content==="page")?.properties;if(f){let u=f.find(C=>C.label==="header")?.values[0];u&&(c=u.content==="Yes");let h=f.find(C=>C.label==="width")?.values[0];h&&(y=h.content);let I=f.find(C=>C.label==="variant")?.values[0];I&&(b=I.content);let w=f.find(C=>C.label==="sidebar-visible")?.values[0];w&&(x=w.content==="Yes")}let g=r.find(u=>u.label==="presentation"&&u.values[0]?.content==="css")?.properties,v=[];if(g)for(let u of g)v.push({label:u.label,value:u.values[0].content});let O=r.find(u=>u.label==="presentation"&&u.values[0]?.content==="css-mobile")?.properties,k=[];if(O)for(let u of O)k.push({label:u.label,value:u.values[0].content});return{title:n.label,slug:t,items:a,properties:{displayedInHeader:c,width:y,variant:b,backgroundImageUrl:s?`https://ochre.lib.uchicago.edu/ochre?uuid=${s.uuid}&load`:null,isSidebarDisplayed:x,cssStyles:v,cssStylesMobile:k},webpages:l}}async function Re(e){let r=[],n=Array.isArray(e)?e:[e];for(let t of n){let i=await He(t);i&&r.push(i)}return r}async function Se(e){let r={uuid:e.uuid,type:"block",layout:"vertical",items:[],properties:{spacing:void 0,gap:void 0,alignItems:"start",justifyContent:"stretch",sectionSidebarItems:null},propertiesMobile:null,cssStyles:[],cssStylesMobile:[]},n=e.properties?T(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],t=n.find(l=>l.label==="presentation"&&l.values[0]?.content==="block")?.properties;if(t){let l=t.find(g=>g.label==="layout")?.values[0];l&&(r.layout=l.content);let c=t.find(g=>g.label==="spacing")?.values[0];c&&(r.properties.spacing=c.content);let y=t.find(g=>g.label==="gap")?.values[0];y&&(r.properties.gap=y.content);let b=t.find(g=>g.label==="align-items")?.values[0];b&&(r.properties.alignItems=b.content);let x=t.find(g=>g.label==="justify-content")?.values[0];x&&(r.properties.justifyContent=x.content);let f=t.find(g=>g.label==="overwrite-mobile");if(f){let g=f.properties,v={};for(let O of g)v[O.label]=O.values[0].content;r.propertiesMobile=v}}let i=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],s=[];for(let l of i){let c=l.properties?T(Array.isArray(l.properties.property)?l.properties.property:[l.properties.property]):[],y=d(c,"presentation");if(y!=null)switch(y){case"element":{let b=await ie(l);s.push(b);break}case"block":{let b=await Se(l);b&&s.push(b);break}}}r.items=s;let o=n.find(l=>l.label==="presentation"&&l.values[0]?.content==="css")?.properties;if(o)for(let l of o)r.cssStyles.push({label:l.label,value:l.values[0].content});let a=n.find(l=>l.label==="presentation"&&l.values[0]?.content==="css-mobile")?.properties;if(a)for(let l of a)r.cssStylesMobile.push({label:l.label,value:l.values[0].content});return r.properties.sectionSidebarItems=Me(r),r}function Me(e){let r=[];for(let n of e.items)switch(n.type){case"block":{let t=Me(n);t!==null&&r.push({uuid:n.uuid,type:"block",name:null,items:t});break}case"element":{if(!n.isDisplayedInBlockSectionSidebar)continue;r.push({uuid:n.uuid,type:"element",name:n.title.label,items:null});break}}return r.length>0?r:null}function Xe(e){let n=T(e).find(A=>A.label==="presentation")?.properties;if(!n)throw new Error("Presentation property not found");let t=n.find(A=>A.label==="webUI")?.values[0]?.content;if(t==null)throw new Error("Website type not found");let i=n.find(A=>A.label==="status")?.values[0]?.content;if(i==null)throw new Error("Website status not found");let s=n.find(A=>A.label==="privacy")?.values[0]?.content;s??="public";let o=Ie.safeParse({type:t,status:i,privacy:s});if(!o.success)throw new Error(`Invalid website properties: ${o.error.message}`);let a=null,l=n.find(A=>A.label==="contact");if(l){let[A,U]=(l.values[0]?.content).split(";");a={name:A,email:U??null}}let c=n.find(A=>A.label==="logo")?.values[0]?.uuid??null,y=!0,b="default",x="start",f=!0,g=!0,v=!1,O=!0,k=n.find(A=>A.label==="navbar-visible")?.values[0];k&&(y=k.content==="Yes");let u=n.find(A=>A.label==="navbar-variant")?.values[0];u&&(b=u.content);let h=n.find(A=>A.label==="navbar-alignment")?.values[0];h&&(x=h.content);let I=n.find(A=>A.label==="navbar-project-visible")?.values[0];I&&(f=I.content==="Yes");let w=n.find(A=>A.label==="footer-visible")?.values[0];w&&(g=w.content==="Yes");let C=n.find(A=>A.label==="sidebar-visible")?.values[0];C&&(v=C.content==="Yes");let m=n.find(A=>A.label==="supports-theme-toggle")?.values[0];m&&(O=m.content==="Yes");let{type:E,status:$,privacy:L}=o.data;return{type:E,privacy:L,status:$,contact:a,isHeaderDisplayed:y,headerVariant:b,headerAlignment:x,isHeaderProjectDisplayed:f,isFooterDisplayed:g,isSidebarDisplayed:v,supportsThemeToggle:O,logoUrl:c!==null?`https://ochre.lib.uchicago.edu/ochre?uuid=${c}&load`:null}}async function Pe(e,r,n){if(!e.properties)throw new Error("Website properties not found");let t=Xe(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]);if(typeof e.items=="string"||!("resource"in e.items))throw new Error("Website pages not found");let i=Array.isArray(e.items.resource)?e.items.resource:[e.items.resource],s=await Re(i),o=null,a=[],l={label:"",variant:"default",properties:{isNameDisplayed:!1,isDescriptionDisplayed:!1,isDateDisplayed:!1,isCreatorsDisplayed:!1}},c="start",y="default",b=[],x=[],f=i.find(v=>(v.properties?T(Array.isArray(v.properties.property)?v.properties.property:[v.properties.property]):[]).some(k=>k.label==="presentation"&&k.values[0]?.content==="element"&&k.properties[0]?.label==="component"&&k.properties[0].values[0]?.content==="sidebar"));if(f){l.label=typeof f.identification.label=="string"||typeof f.identification.label=="number"||typeof f.identification.label=="boolean"?p(f.identification.label):S(f.identification.label);let v=f.properties?T(Array.isArray(f.properties.property)?f.properties.property:[f.properties.property]):[],O=v.find(m=>m.label==="presentation"&&m.values[0]?.content==="element")?.properties.find(m=>m.label==="component"&&m.values[0]?.content==="sidebar")?.properties??[],k=O.find(m=>m.label==="layout");k&&(c=k.values[0].content);let u=O.find(m=>m.label==="layout-mobile");u&&(y=u.values[0].content);let h=v.find(m=>m.label==="presentation"&&m.values[0].content==="css")?.properties??[];for(let m of h){let E=m.values[0].content;b.push({label:m.label,value:E})}let I=v.find(m=>m.label==="presentation"&&m.values[0].content==="css-mobile")?.properties??[];for(let m of I){let E=m.values[0].content;x.push({label:m.label,value:E})}let w=v.find(m=>m.label==="presentation"&&m.values[0].content==="title")?.properties;if(w){let m=d(w,"variant");m&&(l.variant=m);let E=w.filter($=>$.label==="display");E.length>0&&(l.properties.isNameDisplayed=E.some($=>$.values[0].content==="name"),l.properties.isDescriptionDisplayed=E.some($=>$.values[0].content==="description"),l.properties.isDateDisplayed=E.some($=>$.values[0].content==="date"),l.properties.isCreatorsDisplayed=E.some($=>$.values[0].content==="creators"))}let C=f.resource?Array.isArray(f.resource)?f.resource:[f.resource]:[];for(let m of C){let E=await ie(m);a.push(E)}}a.length>0&&(o={elements:a,title:l,layout:c,mobileLayout:y,cssStyles:b,cssStylesMobile:x});let g=null;if(e.searchOptions){let v=[];for(let O of s)for(let k of O.items)k.type==="element"&&k.component==="collection"&&v.push(k.collectionId);g={uuids:v,properties:{metadataUuids:[...e.searchOptions.metadata?.option??[]],searchUuids:[...e.searchOptions.filters?.option??[]],labelUuids:[...e.searchOptions.labels?.option??[]]}}}return{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:P(e.identification),project:{name:p(r),website:n!==null?p(n):null},creators:e.creators?W(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:B(e.availability),pages:s,sidebar:o,properties:t,collectionOptions:g}}async function Ze(e,r,n,t){try{let{uuid:i,filter:s,page:o,perPage:a}=Oe.parse({uuid:e,filter:r,page:n,perPage:t}),l=await fetch(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
|
|
1
|
+
"use strict";var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));const c=s(require(`zod`)),l=c.z.string().uuid({message:`Invalid UUID provided`}),u=c.z.object({type:c.z.enum([`traditional`,`digital-collection`,`plum`,`cedar`,`elm`,`maple`,`oak`,`palm`],{message:`Invalid website type`}),status:c.z.enum([`development`,`preview`,`production`],{message:`Invalid website status`}),privacy:c.z.enum([`public`,`password`,`private`],{message:`Invalid website privacy`})}),d=c.z.enum([`annotated-document`,`annotated-image`,`bibliography`,`button`,`collection`,`empty-space`,`entries`,`filter-categories`,`iframe`,`iiif-viewer`,`image`,`image-gallery`,`n-columns`,`n-rows`,`network-graph`,`search-bar`,`table`,`text`,`timeline`,`video`],{message:`Invalid component`}),f=c.z.enum([`resource`,`spatialUnit`,`concept`,`period`,`bibliography`,`person`,`propertyValue`,`set`,`tree`]),p=c.z.enum([`string`,`integer`,`decimal`,`boolean`,`date`,`dateTime`,`time`,`coordinate`,`IDREF`]),m=c.z.object({uuid:c.z.string().uuid({message:`Invalid UUID`}),filter:c.z.string().optional(),page:c.z.number().positive({message:`Page must be positive`}),perPage:c.z.number().positive({message:`Per page must be positive`})}).strict(),h=c.z.string().transform(e=>e.split(` `)).pipe(c.z.array(c.z.enum([`bold`,`italic`,`underline`]))),g=c.z.string().transform(e=>e.split(` `)).pipe(c.z.array(c.z.enum([`newline`,`trailing`,`leading`]))),_=c.z.string().email({message:`Invalid email`}),v={includeNestedProperties:!1};
|
|
2
|
+
/**
|
|
3
|
+
* Finds a property by its label in an array of properties
|
|
4
|
+
*
|
|
5
|
+
* @param properties - Array of properties to search through
|
|
6
|
+
* @param label - The label to search for
|
|
7
|
+
* @param options - Search options, including whether to include nested properties
|
|
8
|
+
* @returns The matching Property object, or null if not found
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const property = getPropertyByLabel(properties, "author", { includeNestedProperties: true });
|
|
13
|
+
* if (property) {
|
|
14
|
+
* console.log(property.values);
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
function y(e,t,n=v){let{includeNestedProperties:r}=n,i=e.find(e=>e.label===t);if(i)return i;if(r){for(let n of e)if(n.properties.length>0){let e=y(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves all values for a property with the given label
|
|
21
|
+
*
|
|
22
|
+
* @param properties - Array of properties to search through
|
|
23
|
+
* @param label - The label to search for
|
|
24
|
+
* @param options - Search options, including whether to include nested properties
|
|
25
|
+
* @returns Array of property values as strings, or null if property not found
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const values = getPropertyValuesByLabel(properties, "keywords");
|
|
30
|
+
* if (values) {
|
|
31
|
+
* for (const value of values) {
|
|
32
|
+
* console.log(value);
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
function b(e,t,n=v){let{includeNestedProperties:r}=n,i=e.find(e=>e.label===t);if(i)return i.values.map(e=>e.content);if(r){for(let n of e)if(n.properties.length>0){let e=b(n.properties,t,{includeNestedProperties:r});if(e)return e}}return null}
|
|
38
|
+
/**
|
|
39
|
+
* Gets the first value of a property with the given label
|
|
40
|
+
*
|
|
41
|
+
* @param properties - Array of properties to search through
|
|
42
|
+
* @param label - The label to search for
|
|
43
|
+
* @param options - Search options, including whether to include nested properties
|
|
44
|
+
* @returns The first property value as string, or null if property not found
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const title = getPropertyValueByLabel(properties, "title");
|
|
49
|
+
* if (title) {
|
|
50
|
+
* console.log(`Document title: ${title}`);
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
function x(e,t,n=v){let{includeNestedProperties:r}=n,i=b(e,t,{includeNestedProperties:r});if(i!==null&&i.length>0)return i[0];if(r){for(let n of e)if(n.properties.length>0){let e=x(n.properties,t,{includeNestedProperties:r});if(e!==null)return e}}return null}
|
|
55
|
+
/**
|
|
56
|
+
* Gets all unique properties from an array of properties
|
|
57
|
+
*
|
|
58
|
+
* @param properties - Array of properties to get unique properties from
|
|
59
|
+
* @param options - Search options, including whether to include nested properties
|
|
60
|
+
* @returns Array of unique properties
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const properties = getAllUniqueProperties(properties, { includeNestedProperties: true });
|
|
65
|
+
* console.log(`Available properties: ${properties.map((p) => p.label).join(", ")}`);
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
function S(e,t=v){let{includeNestedProperties:n}=t,r=[];for(let t of e){if(r.some(e=>e.uuid===t.uuid))continue;if(r.push(t),t.properties.length>0&&n){let e=S(t.properties,{includeNestedProperties:!0});for(let t of e){if(r.some(e=>e.uuid===t.uuid))continue;r.push(t)}}}return r}
|
|
69
|
+
/**
|
|
70
|
+
* Filters a property based on a label and value criteria
|
|
71
|
+
*
|
|
72
|
+
* @param property - The property to filter
|
|
73
|
+
* @param filter - Filter criteria containing label and value to match
|
|
74
|
+
* @param filter.label - The label to filter by
|
|
75
|
+
* @param filter.value - The value to filter by
|
|
76
|
+
* @param options - Search options, including whether to include nested properties
|
|
77
|
+
* @returns True if the property matches the filter criteria, false otherwise
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* const matches = filterProperties(property, {
|
|
82
|
+
* label: "category",
|
|
83
|
+
* value: "book"
|
|
84
|
+
* });
|
|
85
|
+
* if (matches) {
|
|
86
|
+
* console.log("Property matches filter criteria");
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
function C(e,t,n=v){let{includeNestedProperties:r}=n,i=t.label.toLocaleLowerCase(`en-US`)===`all fields`;if(i||e.label.toLocaleLowerCase(`en-US`)===t.label.toLocaleLowerCase(`en-US`)){let n=e.values.some(e=>e.content===null?!1:typeof e.content==`string`?typeof t.value==`string`?e.content.toLocaleLowerCase(`en-US`).includes(t.value.toLocaleLowerCase(`en-US`)):!1:typeof e.content==`number`?typeof t.value==`number`?e.content===t.value:!1:typeof e.content==`boolean`?typeof t.value==`boolean`?e.booleanValue===t.value:!1:e.content instanceof Date&&t.value instanceof Date?e.content.getTime()===t.value.getTime():!1);return!n&&r&&(n=e.properties.some(e=>C(e,t,{includeNestedProperties:!0}))),n}return!1}
|
|
91
|
+
/**
|
|
92
|
+
* Finds a string item in an array by language code
|
|
93
|
+
*
|
|
94
|
+
* @param content - Array of string items to search
|
|
95
|
+
* @param language - Language code to search for
|
|
96
|
+
* @returns Matching string item or null if not found
|
|
97
|
+
* @internal
|
|
98
|
+
*/
|
|
99
|
+
function w(e,t){let n=e.find(e=>e.lang===t);return n??null}
|
|
100
|
+
/**
|
|
101
|
+
* Parses email addresses in a string into HTML links
|
|
102
|
+
*
|
|
103
|
+
* @param string - Input string to parse
|
|
104
|
+
* @returns String with emails converted to HTML links
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* const parsed = parseEmail("Contact us at info@example.com");
|
|
109
|
+
* // Returns: "Contact us at <ExternalLink href="mailto:info@example.com">info@example.com</ExternalLink>"
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
function T(e){let t=e.split(` `),n=[];for(let e of t){let t=e.replaceAll(/(?<=\s|^)[([{]+|[)\]}]+(?=\s|$)/g,``).replace(/[!),.:;?\]]$/,``),r=e.indexOf(t),i=e.slice(0,r),a=e.slice(r+t.length),o=_.safeParse(t).success;if(o){n.push(i,`${i}<ExternalLink href="mailto:${t}">${t}</ExternalLink>${a}`);continue}n.push(e)}return n.join(` `)}
|
|
113
|
+
/**
|
|
114
|
+
* Applies text rendering options (bold, italic, underline) to a string
|
|
115
|
+
*
|
|
116
|
+
* @param contentString - The string content to render
|
|
117
|
+
* @param renderString - Space-separated string of render options
|
|
118
|
+
* @returns String with markdown formatting applied
|
|
119
|
+
* @internal
|
|
120
|
+
*/
|
|
121
|
+
function ee(e,t){let n=e,r=h.safeParse(t);if(!r.success)return console.warn(`Invalid render options string provided: “${t}”`),e;for(let e of r.data)switch(e){case`bold`:n=`**${n}**`;break;case`italic`:n=`*${n}*`;break;case`underline`:n=`_${n}_`;break}return n.replaceAll(`'`,`'`)}
|
|
122
|
+
/**
|
|
123
|
+
* Applies whitespace options to a string (newline, trailing, leading)
|
|
124
|
+
*
|
|
125
|
+
* @param contentString - The string content to modify
|
|
126
|
+
* @param whitespace - Space-separated string of whitespace options
|
|
127
|
+
* @returns String with whitespace modifications applied
|
|
128
|
+
* @internal
|
|
129
|
+
*/
|
|
130
|
+
function E(e,t){let n=e,r=g.safeParse(t);if(!r.success)return console.warn(`Invalid whitespace string provided: “${t}”`),e;for(let e of r.data)switch(e){case`newline`:n=`<br />\n${n}`;break;case`trailing`:n=`${n} `;break;case`leading`:n=` ${n}`;break}return n.replaceAll(`'`,`'`)}
|
|
131
|
+
/**
|
|
132
|
+
* Converts a FakeString (string|number|boolean) to a proper string
|
|
133
|
+
*
|
|
134
|
+
* @param string - FakeString value to convert
|
|
135
|
+
* @returns Converted string value
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* parseFakeString(true); // Returns "Yes"
|
|
140
|
+
* parseFakeString(123); // Returns "123"
|
|
141
|
+
* parseFakeString("test"); // Returns "test"
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
function D(e){let t=``;return typeof e==`string`?t=e:typeof e==`number`?t=e.toString():typeof e==`boolean`&&(t=e?`Yes`:`No`),t.replaceAll(`'`,`'`).replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}
|
|
145
|
+
/**
|
|
146
|
+
* Parses an OchreStringItem into a formatted string
|
|
147
|
+
*
|
|
148
|
+
* @param item - OchreStringItem to parse
|
|
149
|
+
* @returns Formatted string with applied rendering and whitespace
|
|
150
|
+
*/
|
|
151
|
+
function O(e){let t=``;switch(typeof e.string){case`string`:t=e.string;break;case`number`:case`boolean`:t=D(e.string);break;case`object`:{let n=Array.isArray(e.string)?e.string:[e.string];for(let e of n)if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)t+=D(e);else{let n=e.rend==null?D(e.content):ee(D(e.content),e.rend),r=e.whitespace==null?n:E(n,e.whitespace);t+=r}break}default:t=``;break}return t.replaceAll(`'`,`'`).replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}
|
|
152
|
+
/**
|
|
153
|
+
* Parses rich text content into a formatted string with links and annotations
|
|
154
|
+
*
|
|
155
|
+
* @param item - Rich text item to parse
|
|
156
|
+
* @param footnotes - Optional array to collect footnotes during parsing
|
|
157
|
+
* @returns Formatted string with HTML/markdown elements
|
|
158
|
+
*/
|
|
159
|
+
function k(e,t){if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return T(D(e));if(`whitespace`in e&&!(`content`in e)&&!(`string`in e))return e.whitespace===`newline`?`
|
|
160
|
+
`:``;if(`links`in e){let n=``;n=typeof e.string==`object`?A(e.string):D(e.string).replaceAll(`<`,String.raw`\<`).replaceAll(`{`,String.raw`\{`);let r=Array.isArray(e.links)?e.links:[e.links];for(let e of r)if(`resource`in e){let r=Array.isArray(e.resource)?e.resource[0]:e.resource,i=null;switch(r.content!=null&&(i=D(r.content).replaceAll(`<`,String.raw`\<`).replaceAll(`{`,String.raw`\{`)),r.type){case`image`:return r.rend===`inline`?`<InlineImage uuid="${r.uuid}" ${i===null?``:`content="${i}"`} height={${r.height?.toString()??`null`}} width={${r.width?.toString()??`null`}} />`:r.publicationDateTime==null?`<TooltipSpan type="image" ${i===null?``:`content="${i}"`}>${n}</TooltipSpan>`:`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${r.uuid}" type="image"${i===null?``:` content="${i}"`}>${n}</ExternalLink>`;case`internalDocument`:{let e=i?.toLocaleLowerCase(`en-US`).includes(`footnote`);return e?(t&&t.push({uuid:r.uuid,label:n,content:``}),` <Footnote uuid="${r.uuid}"${n?` label="${n}"`:``}${i===null?``:` content="${i}"`} />`):`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${r.uuid}" type="internalDocument" ${i===null?``:`content="${i}"`}>${n}</ExternalLink>`}case`externalDocument`:return r.publicationDateTime==null?`<TooltipSpan type="externalDocument" ${i===null?``:`content="${i}"`}>${n}</TooltipSpan>`:`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${r.uuid}" type="externalDocument" ${i===null?``:`content="${i}"`}>${n}</ExternalLink>`;case`webpage`:return`<ExternalLink href="${r.href}" type="webpage" ${i===null?``:`content="${i}"`}>${n}</ExternalLink>`;default:return``}}else if(`concept`in e){let t=Array.isArray(e.concept)?e.concept[0]:e.concept;return t.publicationDateTime==null?`<TooltipSpan type="concept">${n}</TooltipSpan>`:`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${t.uuid}" type="concept">${n}</ExternalLink>`}else if(`set`in e){let t=Array.isArray(e.set)?e.set[0]:e.set;return t.publicationDateTime==null?`<TooltipSpan type="set">${n}</TooltipSpan>`:`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${t.uuid}" type="set">${n}</ExternalLink>`}else if(`person`in e){let t=Array.isArray(e.person)?e.person[0]:e.person,r=t.identification?[`string`,`number`,`boolean`].includes(typeof t.identification.label)?D(t.identification.label):A(t.identification.label):null;return t.publicationDateTime==null?`<TooltipSpan type="${t.type??`person`}" ${r===null?``:`content="${r}"`}>${n}</TooltipSpan>`:`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${t.uuid}" type="${t.type??`person`}" ${r===null?``:`content="${r}"`}>${n}</ExternalLink>`}else if(`bibliography`in e){let t=Array.isArray(e.bibliography)?e.bibliography[0]:e.bibliography;return t.publicationDateTime==null?`<TooltipSpan type="bibliography">${n}</TooltipSpan>`:`<ExternalLink href="https:\\/\\/ochre.lib.uchicago.edu/ochre?uuid=${t.uuid}" type="${t.type??`bibliography`}">${n}</ExternalLink>`}}let n=``;if(`string`in e){let r=Array.isArray(e.string)?e.string:[e.string];for(let e of r)n+=k(e,t);return`whitespace`in e&&e.whitespace!=null&&(n=E(T(n),e.whitespace)),n.replaceAll(`'`,`'`).replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}else n=D(e.content),e.rend!=null&&(n=ee(T(n),e.rend)),e.whitespace!=null&&(n=E(T(n),e.whitespace));return n.replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}
|
|
161
|
+
/**
|
|
162
|
+
* Parses raw string content into a formatted string
|
|
163
|
+
*
|
|
164
|
+
* @param content - Raw string content to parse
|
|
165
|
+
* @param language - Optional language code for content selection (defaults to "eng")
|
|
166
|
+
* @returns Parsed and formatted string
|
|
167
|
+
*/
|
|
168
|
+
function A(e,t=`eng`){switch(typeof e.content){case`string`:case`number`:case`boolean`:return D(e.content);case`object`:if(Array.isArray(e.content)){let n=w(e.content,t);if(n)return O(n);{let n=e.content[0];if(!n)throw Error(`No string item found for language “${t}” in the following content:\n${JSON.stringify(e.content)}.`);return O(n)}}else return O(e.content);default:return String(e.content).replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}}
|
|
169
|
+
/**
|
|
170
|
+
* Get the category of an item from the OCHRE API response
|
|
171
|
+
* @param keys - The keys of the OCHRE API response
|
|
172
|
+
* @returns The category of the item
|
|
173
|
+
* @internal
|
|
174
|
+
*/
|
|
175
|
+
function te(e){let t=e.find(e=>f.safeParse(e).success);if(!t){let t=e.find(e=>![`uuid`,`uuidBelongsTo`,`belongsTo`,`publicationDateTime`,`metadata`,`languages`].includes(e));throw Error(`Invalid OCHRE data; found unexpected "${t}" key`)}let n=f.parse(t);return n}
|
|
176
|
+
/**
|
|
177
|
+
* Fetches raw OCHRE data by UUID from the OCHRE API
|
|
178
|
+
*
|
|
179
|
+
* @param uuid - The UUID of the OCHRE item to fetch
|
|
180
|
+
* @returns A tuple containing either [null, OchreData] on success or [error message, null] on failure
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```ts
|
|
184
|
+
* const [error, data] = await fetchByUuid("123e4567-e89b-12d3-a456-426614174000");
|
|
185
|
+
* if (error !== null) {
|
|
186
|
+
* console.error(`Failed to fetch: ${error}`);
|
|
187
|
+
* return;
|
|
188
|
+
* }
|
|
189
|
+
* // Process data...
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* @internal
|
|
193
|
+
*/
|
|
194
|
+
async function ne(e){try{let t=l.parse(e),n=await fetch(`https://ochre.lib.uchicago.edu/ochre?uuid=${t}&format=json&lang="*"`);if(!n.ok)throw Error(`Failed to fetch OCHRE data`);let r=await n.json();if(!(`ochre`in r))throw Error(`Invalid OCHRE data: API response missing 'ochre' key`);return[null,r]}catch(e){return[e instanceof Error?e.message:`Unknown error`,null]}}
|
|
195
|
+
/**
|
|
196
|
+
* Fetches and parses an OCHRE item from the OCHRE API
|
|
197
|
+
*
|
|
198
|
+
* @param uuid - The UUID of the OCHRE item to fetch
|
|
199
|
+
* @returns Object containing the parsed OCHRE item and its metadata, or null if the fetch/parse fails
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```ts
|
|
203
|
+
* const result = await fetchItem("123e4567-e89b-12d3-a456-426614174000");
|
|
204
|
+
* if (result === null) {
|
|
205
|
+
* console.error("Failed to fetch OCHRE item");
|
|
206
|
+
* return;
|
|
207
|
+
* }
|
|
208
|
+
* const { metadata, belongsTo, item, category } = result;
|
|
209
|
+
* console.log(`Fetched OCHRE item: ${item.identification.label} with category ${category}`);
|
|
210
|
+
* ```
|
|
211
|
+
*
|
|
212
|
+
* Or, if you want to fetch a specific category, you can do so by passing the category as an argument:
|
|
213
|
+
* ```ts
|
|
214
|
+
* const result = await fetchItem("123e4567-e89b-12d3-a456-426614174000", "resource");
|
|
215
|
+
* const { metadata, belongsTo, item, category } = result;
|
|
216
|
+
* console.log(item.category); // "resource"
|
|
217
|
+
* ```
|
|
218
|
+
*
|
|
219
|
+
* @remarks
|
|
220
|
+
* The returned OCHRE item includes:
|
|
221
|
+
* - Item metadata
|
|
222
|
+
* - Item belongsTo information
|
|
223
|
+
* - Item content
|
|
224
|
+
* - Item category
|
|
225
|
+
*
|
|
226
|
+
* If the fetch/parse fails, the returned object will have an `error` property.
|
|
227
|
+
*/
|
|
228
|
+
async function re(e,t,n){try{let[r,i]=await ne(e);if(r!==null)throw Error(r);let a=te(Object.keys(i.ochre)),o;switch(a){case`resource`:if(!(`resource`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'resource' key`);o=X(i.ochre.resource);break;case`spatialUnit`:if(!(`spatialUnit`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'spatialUnit' key`);o=me(i.ochre.spatialUnit);break;case`concept`:if(!(`concept`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'concept' key`);o=ge(i.ochre.concept);break;case`period`:if(!(`period`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'period' key`);o=W(i.ochre.period);break;case`bibliography`:if(!(`bibliography`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'bibliography' key`);o=K(i.ochre.bibliography);break;case`person`:if(!(`person`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'person' key`);o=oe(i.ochre.person);break;case`propertyValue`:if(!(`propertyValue`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'propertyValue' key`);o=J(i.ochre.propertyValue);break;case`set`:if(!(`set`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'set' key`);o=pe(i.ochre.set,n);break;case`tree`:if(!(`tree`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'tree' key`);o=fe(i.ochre.tree);break;default:throw Error(`Invalid category`)}let s=ae(i.ochre.metadata),c={uuid:i.ochre.uuidBelongsTo,abbreviation:D(i.ochre.belongsTo)};return{error:null,metadata:s,belongsTo:c,item:o,category:t}}catch(e){return{error:e instanceof Error?e.message:`Unknown error`,metadata:void 0,belongsTo:void 0,item:void 0,category:void 0}}}
|
|
229
|
+
/**
|
|
230
|
+
* Parses raw identification data into the standardized Identification type
|
|
231
|
+
*
|
|
232
|
+
* @param identification - Raw identification data from OCHRE format
|
|
233
|
+
* @returns Parsed Identification object with label and abbreviation
|
|
234
|
+
*/
|
|
235
|
+
function j(e){try{let t={label:[`string`,`number`,`boolean`].includes(typeof e.label)?D(e.label):A(e.label),abbreviation:``};for(let n of Object.keys(e).filter(e=>e!==`label`))t[n]=A(e[n]);return t}catch(e){return console.error(e),{label:``,abbreviation:``}}}
|
|
236
|
+
/**
|
|
237
|
+
* Parses raw language data into an array of language codes
|
|
238
|
+
*
|
|
239
|
+
* @param language - Raw language data, either single or array
|
|
240
|
+
* @returns Array of language codes as strings
|
|
241
|
+
*/
|
|
242
|
+
function ie(e){return e==null?[`eng`]:Array.isArray(e)?e.map(e=>A(e)):[A(e)]}
|
|
243
|
+
/**
|
|
244
|
+
* Parses raw metadata into the standardized Metadata type
|
|
245
|
+
*
|
|
246
|
+
* @param metadata - Raw metadata from OCHRE format
|
|
247
|
+
* @returns Parsed Metadata object
|
|
248
|
+
*/
|
|
249
|
+
function ae(e){let t={label:``,abbreviation:``};if(e.item)if(e.item.label||e.item.abbreviation){let n=``,r=``;e.item.label&&(n=A(e.item.label)),e.item.abbreviation&&(r=A(e.item.abbreviation)),t={label:n,abbreviation:r}}else t=j(e.item.identification);let n=null,r=e.project?.identification?j(e.project.identification):null;return r&&(n={...r,website:e.project?.identification.website??null}),{project:n?{identification:n}:null,item:e.item?{identification:t,category:e.item.category,type:e.item.type,maxLength:e.item.maxLength??null}:null,dataset:A(e.dataset),publisher:A(e.publisher),languages:ie(e.language),identifier:A(e.identifier),description:A(e.description)}}
|
|
250
|
+
/**
|
|
251
|
+
* Parses raw context item data into the standardized ContextItem type
|
|
252
|
+
*
|
|
253
|
+
* @param contextItem - Raw context item data from OCHRE format
|
|
254
|
+
* @returns Parsed ContextItem object
|
|
255
|
+
*/
|
|
256
|
+
function M(e){return{uuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),number:e.n,content:D(e.content)}}
|
|
257
|
+
/**
|
|
258
|
+
* Parses raw context data into the standardized Context type
|
|
259
|
+
*
|
|
260
|
+
* @param context - Raw context data from OCHRE format
|
|
261
|
+
* @returns Parsed Context object
|
|
262
|
+
*/
|
|
263
|
+
function N(e){let t=Array.isArray(e.context)?e.context:[e.context],n={nodes:t.map(e=>{let t=[];if(`spatialUnit`in e&&e.spatialUnit){let n=Array.isArray(e.spatialUnit)?e.spatialUnit:[e.spatialUnit];for(let e of n)t.push(M(e))}return{tree:M(e.tree),project:M(e.project),spatialUnit:t}}),displayPath:e.displayPath};return n}
|
|
264
|
+
/**
|
|
265
|
+
* Parses raw license data into the standardized License type
|
|
266
|
+
*
|
|
267
|
+
* @param license - Raw license data from OCHRE format
|
|
268
|
+
* @returns Parsed License object or null if invalid
|
|
269
|
+
*/
|
|
270
|
+
function P(e){return typeof e.license==`string`?null:{content:e.license.content,url:e.license.target}}
|
|
271
|
+
/**
|
|
272
|
+
* Parses raw person data into the standardized Person type
|
|
273
|
+
*
|
|
274
|
+
* @param person - Raw person data from OCHRE format
|
|
275
|
+
* @returns Parsed Person object
|
|
276
|
+
*/
|
|
277
|
+
function oe(e){return{uuid:e.uuid,category:`person`,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),type:e.type??null,number:e.n??null,context:e.context?N(e.context):null,date:e.date==null?null:new Date(e.date),identification:e.identification?j(e.identification):null,availability:e.availability?P(e.availability):null,address:e.address?{country:e.address.country??null,city:e.address.city??null,state:e.address.state??null}:null,coordinates:e.coordinates?B(e.coordinates):null,content:e.content==null?null:D(e.content),events:e.events?H(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:e.properties?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}
|
|
278
|
+
/**
|
|
279
|
+
* Parses raw person data into the standardized Person type
|
|
280
|
+
*
|
|
281
|
+
* @param persons - Array of raw person data from OCHRE format
|
|
282
|
+
* @returns Array of parsed Person objects
|
|
283
|
+
*/
|
|
284
|
+
function F(e){let t=[];for(let n of e)t.push(oe(n));return t}
|
|
285
|
+
/**
|
|
286
|
+
* Parses an array of raw links into standardized Link objects
|
|
287
|
+
*
|
|
288
|
+
* @param linkRaw - Raw OCHRE link
|
|
289
|
+
* @returns Parsed Link object
|
|
290
|
+
*/
|
|
291
|
+
function se(e){let t=`resource`in e?e.resource:`spatialUnit`in e?e.spatialUnit:`concept`in e?e.concept:`set`in e?e.set:`tree`in e?e.tree:`person`in e?e.person:`bibliography`in e?e.bibliography:`epigraphicUnit`in e?e.epigraphicUnit:`propertyValue`in e?e.propertyValue:null;if(!t)throw Error(`Invalid link provided: ${JSON.stringify(e,null,2)}`);let n=Array.isArray(t)?t:[t],r=[];for(let t of n){let n={category:`resource`in e?`resource`:`spatialUnit`in e?`spatialUnit`:`concept`in e?`concept`:`set`in e?`set`:`person`in e?`person`:`tree`in e?`tree`:`bibliography`in e?`bibliography`:`epigraphicUnit`in e?`epigraphicUnit`:`propertyValue`in e?`propertyValue`:null,content:`content`in t?t.content==null?null:D(t.content):null,href:`href`in t&&t.href!=null?t.href:null,uuid:t.uuid,type:t.type??null,identification:t.identification?j(t.identification):null,image:null,bibliographies:`bibliography`in e?q(Array.isArray(e.bibliography)?e.bibliography:[e.bibliography]):null,publicationDateTime:t.publicationDateTime==null?null:new Date(t.publicationDateTime)};`height`in t&&t.height!=null&&t.width!=null&&t.heightPreview!=null&&t.widthPreview!=null&&(n.image={isInline:t.rend===`inline`,isPrimary:t.isPrimary??!1,heightPreview:t.heightPreview,widthPreview:t.widthPreview,height:t.height,width:t.width}),r.push(n)}return r}
|
|
292
|
+
/**
|
|
293
|
+
* Parses an array of raw links into standardized Link objects
|
|
294
|
+
*
|
|
295
|
+
* @param links - Array of raw OCHRE links
|
|
296
|
+
* @returns Array of parsed Link objects
|
|
297
|
+
*/
|
|
298
|
+
function I(e){let t=[];for(let n of e)t.push(...se(n));return t}
|
|
299
|
+
/**
|
|
300
|
+
* Parses raw document content into a standardized Document structure
|
|
301
|
+
*
|
|
302
|
+
* @param document - Raw document content in OCHRE format
|
|
303
|
+
* @param language - Language code to use for content selection (defaults to "eng")
|
|
304
|
+
* @returns Parsed Document object with content and footnotes
|
|
305
|
+
*/
|
|
306
|
+
function L(e,t=`eng`){let n=``,r=[],i=Array.isArray(e)?e.find(e=>e.lang===t):e;if(typeof i.string==`string`||typeof i.string==`number`||typeof i.string==`boolean`)n+=T(D(i.string));else{let e=Array.isArray(i.string)?i.string:[i.string];for(let t of e)n+=k(t,r)}return{content:n,footnotes:r}}
|
|
307
|
+
/**
|
|
308
|
+
* Parses raw image data into a standardized Image structure
|
|
309
|
+
*
|
|
310
|
+
* @param image - Raw image data in OCHRE format
|
|
311
|
+
* @returns Parsed Image object or null if invalid
|
|
312
|
+
*/
|
|
313
|
+
function R(e){return{publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),identification:e.identification?j(e.identification):null,url:e.href??(e.htmlImgSrcPrefix==null&&e.content!=null?D(e.content):null),htmlPrefix:e.htmlImgSrcPrefix??null,content:e.htmlImgSrcPrefix!=null&&e.content!=null?D(e.content):null,widthPreview:e.widthPreview??null,heightPreview:e.heightPreview??null,width:e.width??null,height:e.height??null}}
|
|
314
|
+
/**
|
|
315
|
+
* Parses raw notes into standardized Note objects
|
|
316
|
+
*
|
|
317
|
+
* @param notes - Array of raw notes in OCHRE format
|
|
318
|
+
* @param language - Language code for content selection (defaults to "eng")
|
|
319
|
+
* @returns Array of parsed Note objects
|
|
320
|
+
*/
|
|
321
|
+
function z(e,t=`eng`){let n=[];for(let r of e){if(typeof r==`string`){if(r===``)continue;n.push({number:-1,title:null,content:r});continue}let e=``,i=Array.isArray(r.content)?r.content:[r.content],a=i.find(e=>e.lang===t);if(!a&&(a=i[0],!a))throw Error(`Note does not have a valid content item: ${JSON.stringify(r,null,2)}`);e=typeof a.string==`string`||typeof a.string==`number`||typeof a.string==`boolean`?T(D(a.string)):T(L(a).content),n.push({number:r.noteNo,title:a.title==null?null:D(a.title),content:e})}return n}
|
|
322
|
+
/**
|
|
323
|
+
* Parses raw coordinates data into a standardized Coordinates structure
|
|
324
|
+
*
|
|
325
|
+
* @param coordinates - Raw coordinates data in OCHRE format
|
|
326
|
+
* @returns Parsed Coordinates object
|
|
327
|
+
*/
|
|
328
|
+
function B(e){if(typeof e==`string`){let[t,n]=e.split(`, `);return{latitude:Number(t),longitude:Number(n),type:null,label:null}}return{latitude:e.latitude,longitude:e.longitude,type:e.coord?.coordType??null,label:e.coord?.coordLabel==null?null:D(e.coord.coordLabel)}}
|
|
329
|
+
/**
|
|
330
|
+
* Parses a raw observation into a standardized Observation structure
|
|
331
|
+
*
|
|
332
|
+
* @param observation - Raw observation data in OCHRE format
|
|
333
|
+
* @returns Parsed Observation object
|
|
334
|
+
*/
|
|
335
|
+
function V(e){return{number:e.observationNo,date:e.date==null?null:new Date(e.date),observers:e.observers==null?[]:D(e.observers).split(`;`).map(e=>e.trim()),notes:e.notes?z(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?I(Array.isArray(e.links)?e.links:[e.links]):[],properties:e.properties?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}
|
|
336
|
+
/**
|
|
337
|
+
* Parses an array of raw observations into standardized Observation objects
|
|
338
|
+
*
|
|
339
|
+
* @param observations - Array of raw observations in OCHRE format
|
|
340
|
+
* @returns Array of parsed Observation objects
|
|
341
|
+
*/
|
|
342
|
+
function ce(e){let t=[];for(let n of e)t.push(V(n));return t}
|
|
343
|
+
/**
|
|
344
|
+
* Parses an array of raw events into standardized Event objects
|
|
345
|
+
*
|
|
346
|
+
* @param events - Array of raw events in OCHRE format
|
|
347
|
+
* @returns Array of parsed Event objects
|
|
348
|
+
*/
|
|
349
|
+
function H(e){let t=[];for(let n of e)t.push({date:n.dateTime==null?null:new Date(n.dateTime),label:A(n.label),agent:n.agent?{uuid:n.agent.uuid,content:D(n.agent.content)}:null});return t}function le(e,t=`eng`){let n=`value`in e&&e.value?Array.isArray(e.value)?e.value:[e.value]:[],r=n.map(e=>{let t=null,n=null;if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`){t=D(e);let r={content:t,booleanValue:n,isUncertain:!1,type:`string`,category:`value`,uuid:null,publicationDateTime:null,unit:null};return r}else{switch(e.type){case`integer`:case`decimal`:t=Number(e.content);break;case`dateTime`:t=e.content?typeof e.content==`string`?new Date(e.content):new Date(A({content:e.content})):null;break;default:`slug`in e&&e.slug!=null?t=D(e.slug):e.content!=null&&(t=A({content:e.content})),e.type===`boolean`&&(n=e.booleanValue??null);break}let r=`string`;if(e.type!=null){let{data:t,error:n}=p.safeParse(e.type);if(n)throw Error(`Invalid property value content type: "${e.type}"`);r=t}let i={content:t,booleanValue:n,isUncertain:e.isUncertain??!1,type:r,category:e.category??`value`,uuid:e.uuid??null,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),unit:e.unit??null};return i}});return{uuid:e.label.uuid,label:A(e.label,t).replace(/\s*\.{3}$/,``).trim(),values:r,comment:e.comment==null?null:D(e.comment),properties:e.property?U(Array.isArray(e.property)?e.property:[e.property]):[]}}
|
|
350
|
+
/**
|
|
351
|
+
* Parses raw properties into standardized Property objects
|
|
352
|
+
*
|
|
353
|
+
* @param properties - Array of raw properties in OCHRE format
|
|
354
|
+
* @param language - Language code for content selection (defaults to "eng")
|
|
355
|
+
* @returns Array of parsed Property objects
|
|
356
|
+
*/
|
|
357
|
+
function U(e,t=`eng`){let n=[];for(let r of e)n.push(le(r,t));return n}
|
|
358
|
+
/**
|
|
359
|
+
* Parses raw interpretations into standardized Interpretation objects
|
|
360
|
+
*
|
|
361
|
+
* @param interpretations - Array of raw interpretations in OCHRE format
|
|
362
|
+
* @returns Array of parsed Interpretation objects
|
|
363
|
+
*/
|
|
364
|
+
function ue(e){let t=[];for(let n of e)t.push({date:new Date(n.date),number:n.interpretationNo,properties:n.properties?U(Array.isArray(n.properties.property)?n.properties.property:[n.properties.property]):[]});return t}
|
|
365
|
+
/**
|
|
366
|
+
* Parses raw image map data into a standardized ImageMap structure
|
|
367
|
+
*
|
|
368
|
+
* @param imageMap - Raw image map data in OCHRE format
|
|
369
|
+
* @returns Parsed ImageMap object
|
|
370
|
+
*/
|
|
371
|
+
function de(e){let t={area:[],width:e.width,height:e.height},n=Array.isArray(e.area)?e.area:[e.area];for(let e of n)t.area.push({uuid:e.uuid,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),type:e.type,title:D(e.title),shape:e.shape===`rect`?`rectangle`:`polygon`,coords:e.coords.split(`,`).map(e=>Number.parseInt(e))});return t}
|
|
372
|
+
/**
|
|
373
|
+
* Parses raw period data into a standardized Period structure
|
|
374
|
+
*
|
|
375
|
+
* @param period - Raw period data in OCHRE format
|
|
376
|
+
* @returns Parsed Period object
|
|
377
|
+
*/
|
|
378
|
+
function W(e){return{uuid:e.uuid,category:`period`,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),type:e.type??null,number:e.n??null,identification:j(e.identification),description:e.description?A(e.description):null}}
|
|
379
|
+
/**
|
|
380
|
+
* Parses an array of raw periods into standardized Period objects
|
|
381
|
+
*
|
|
382
|
+
* @param periods - Array of raw periods in OCHRE format
|
|
383
|
+
* @returns Array of parsed Period objects
|
|
384
|
+
*/
|
|
385
|
+
function G(e){let t=[];for(let n of e)t.push(W(n));return t}
|
|
386
|
+
/**
|
|
387
|
+
* Parses raw bibliography data into a standardized Bibliography structure
|
|
388
|
+
*
|
|
389
|
+
* @param bibliography - Raw bibliography data in OCHRE format
|
|
390
|
+
* @returns Parsed Bibliography object
|
|
391
|
+
*/
|
|
392
|
+
function K(e){let t=null;return e.source?.resource&&(t={uuid:e.source.resource.uuid,publicationDateTime:e.source.resource.publicationDateTime?new Date(e.source.resource.publicationDateTime):null,type:e.source.resource.type,identification:j(e.source.resource.identification)}),{uuid:e.uuid,category:`bibliography`,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),type:e.type??null,number:e.n??null,identification:e.identification?j(e.identification):null,projectIdentification:e.project?.identification?j(e.project.identification):null,context:e.context?N(e.context):null,citation:{format:e.citationFormat??null,short:e.citationFormatSpan?D(`default:span`in e.citationFormatSpan?e.citationFormatSpan[`default:span`].content:e.citationFormatSpan.span.content):null,long:e.referenceFormatDiv?D(`default:div`in e.referenceFormatDiv?e.referenceFormatDiv[`default:div`][`default:div`].content:e.referenceFormatDiv.div.div.content):null},publicationInfo:{publishers:e.publicationInfo?.publishers?F(Array.isArray(e.publicationInfo.publishers.publishers.person)?e.publicationInfo.publishers.publishers.person:[e.publicationInfo.publishers.publishers.person]):[],startDate:e.publicationInfo?.startDate?new Date(e.publicationInfo.startDate.year,e.publicationInfo.startDate.month,e.publicationInfo.startDate.day):null},entryInfo:e.entryInfo?{startIssue:D(e.entryInfo.startIssue),startVolume:D(e.entryInfo.startVolume)}:null,source:{resource:t,documentUrl:e.sourceDocument?`https://ochre.lib.uchicago.edu/ochre?uuid=${e.sourceDocument.uuid}&load`:null},periods:e.periods?G(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],authors:e.authors?F(Array.isArray(e.authors.person)?e.authors.person:[e.authors.person]):[],properties:e.properties?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]}}
|
|
393
|
+
/**
|
|
394
|
+
* Parses an array of raw bibliographies into standardized Bibliography objects
|
|
395
|
+
*
|
|
396
|
+
* @param bibliographies - Array of raw bibliographies in OCHRE format
|
|
397
|
+
* @returns Array of parsed Bibliography objects
|
|
398
|
+
*/
|
|
399
|
+
function q(e){let t=[];for(let n of e)t.push(K(n));return t}
|
|
400
|
+
/**
|
|
401
|
+
* Parses raw property value data into a standardized PropertyValue structure
|
|
402
|
+
*
|
|
403
|
+
* @param propertyValue - Raw property value data in OCHRE format
|
|
404
|
+
* @returns Parsed PropertyValue object
|
|
405
|
+
*/
|
|
406
|
+
function J(e){return{uuid:e.uuid,category:`propertyValue`,number:e.n,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,context:e.context?N(e.context):null,availability:e.availability?P(e.availability):null,identification:j(e.identification),date:e.date?new Date(e.date):null,creators:e.creators?F(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?D(e.description):A(e.description):``,notes:e.notes?z(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],links:e.links?I(Array.isArray(e.links)?e.links:[e.links]):[]}}
|
|
407
|
+
/**
|
|
408
|
+
* Parses an array of raw property values into standardized PropertyValue objects
|
|
409
|
+
*
|
|
410
|
+
* @param propertyValues - Array of raw property values in OCHRE format
|
|
411
|
+
* @returns Array of parsed PropertyValue objects
|
|
412
|
+
*/
|
|
413
|
+
function Y(e){let t=[];for(let n of e)t.push(J(n));return t}
|
|
414
|
+
/**
|
|
415
|
+
* Parses a raw tree structure into a standardized Tree object
|
|
416
|
+
*
|
|
417
|
+
* @param tree - Raw tree data in OCHRE format
|
|
418
|
+
* @returns Parsed Tree object or null if invalid
|
|
419
|
+
*/
|
|
420
|
+
function fe(e){let t=[];e.creators&&(t=F(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]));let n=null;e.date!=null&&(n=new Date(e.date));let r=[],i=[],a=[],o=[],s=[],c=[],l=[];typeof e.items!=`string`&&`resource`in e.items&&(r=Z(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource])),typeof e.items!=`string`&&`spatialUnit`in e.items&&(i=he(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit])),typeof e.items!=`string`&&`concept`in e.items&&(a=Q(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept])),typeof e.items!=`string`&&`period`in e.items&&(o=G(Array.isArray(e.items.period)?e.items.period:[e.items.period])),typeof e.items!=`string`&&`bibliography`in e.items&&(s=q(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography])),typeof e.items!=`string`&&`person`in e.items&&(c=F(Array.isArray(e.items.person)?e.items.person:[e.items.person])),typeof e.items!=`string`&&`propertyValue`in e.items&&(l=Y(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]));let u={uuid:e.uuid,category:`tree`,publicationDateTime:new Date(e.publicationDateTime),identification:j(e.identification),creators:t,license:P(e.availability),date:n,type:e.type,number:e.n,items:{resources:r,spatialUnits:i,concepts:a,periods:o,bibliographies:s,persons:c,propertyValues:l},properties:e.properties?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return u}
|
|
421
|
+
/**
|
|
422
|
+
* Parses raw set data into a standardized Set structure
|
|
423
|
+
*
|
|
424
|
+
* @param set - Raw set data in OCHRE format
|
|
425
|
+
* @returns Parsed Set object
|
|
426
|
+
*/
|
|
427
|
+
function pe(e,t){if(typeof e.items==`string`)throw TypeError(`Invalid OCHRE data: Set has no items`);let n=t??te(Object.keys(e.items)),r=[];switch(n){case`resource`:if(!(`resource`in e.items))throw Error(`Invalid OCHRE data: Set has no resources`);r=Z(Array.isArray(e.items.resource)?e.items.resource:[e.items.resource]);break;case`spatialUnit`:if(!(`spatialUnit`in e.items))throw Error(`Invalid OCHRE data: Set has no spatial units`);r=he(Array.isArray(e.items.spatialUnit)?e.items.spatialUnit:[e.items.spatialUnit]);break;case`concept`:if(!(`concept`in e.items))throw Error(`Invalid OCHRE data: Set has no concepts`);r=Q(Array.isArray(e.items.concept)?e.items.concept:[e.items.concept]);break;case`period`:if(!(`period`in e.items))throw Error(`Invalid OCHRE data: Set has no periods`);r=G(Array.isArray(e.items.period)?e.items.period:[e.items.period]);break;case`bibliography`:if(!(`bibliography`in e.items))throw Error(`Invalid OCHRE data: Set has no bibliographies`);r=q(Array.isArray(e.items.bibliography)?e.items.bibliography:[e.items.bibliography]);break;case`person`:if(!(`person`in e.items))throw Error(`Invalid OCHRE data: Set has no persons`);r=F(Array.isArray(e.items.person)?e.items.person:[e.items.person]);break;case`propertyValue`:if(!(`propertyValue`in e.items))throw Error(`Invalid OCHRE data: Set has no property values`);r=Y(Array.isArray(e.items.propertyValue)?e.items.propertyValue:[e.items.propertyValue]);break;default:throw Error(`Invalid OCHRE data: Set has no items or is malformed`)}return{uuid:e.uuid,category:`set`,itemCategory:t,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,date:e.date==null?null:new Date(e.date),license:P(e.availability),identification:j(e.identification),isSuppressingBlanks:e.suppressBlanks??!1,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?D(e.description):A(e.description):``,creators:e.creators?F(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],type:e.type,number:e.n,items:r}}
|
|
428
|
+
/**
|
|
429
|
+
* Parses raw resource data into a standardized Resource structure
|
|
430
|
+
*
|
|
431
|
+
* @param resource - Raw resource data in OCHRE format
|
|
432
|
+
* @returns Parsed Resource object
|
|
433
|
+
*/
|
|
434
|
+
function X(e){let t={uuid:e.uuid,category:`resource`,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,type:e.type,number:e.n,format:e.format??null,context:`context`in e&&e.context?N(e.context):null,license:`availability`in e&&e.availability?P(e.availability):null,copyright:`copyright`in e&&e.copyright!=null?D(e.copyright):null,identification:j(e.identification),date:e.date==null?null:new Date(e.date),image:e.image?R(e.image):null,creators:e.creators?F(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],notes:e.notes?z(Array.isArray(e.notes.note)?e.notes.note:[e.notes.note]):[],description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?D(e.description):A(e.description):``,document:e.document&&`content`in e.document?L(e.document.content):null,href:e.href??null,imageMap:e.imagemap?de(e.imagemap):null,periods:e.periods?G(Array.isArray(e.periods.period)?e.periods.period:[e.periods.period]):[],links:e.links?I(Array.isArray(e.links)?e.links:[e.links]):[],reverseLinks:e.reverseLinks?I(Array.isArray(e.reverseLinks)?e.reverseLinks:[e.reverseLinks]):[],properties:e.properties?U(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?Z(Array.isArray(e.resource)?e.resource:[e.resource]):[]};return t}
|
|
435
|
+
/**
|
|
436
|
+
* Parses raw resource data into a standardized Resource structure
|
|
437
|
+
*
|
|
438
|
+
* @param resources - Raw resource data in OCHRE format
|
|
439
|
+
* @returns Parsed Resource object
|
|
440
|
+
*/
|
|
441
|
+
function Z(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(X(e));return t}
|
|
442
|
+
/**
|
|
443
|
+
* Parses raw spatial units into standardized SpatialUnit objects
|
|
444
|
+
*
|
|
445
|
+
* @param spatialUnit - Raw spatial unit in OCHRE format
|
|
446
|
+
* @returns Parsed SpatialUnit object
|
|
447
|
+
*/
|
|
448
|
+
function me(e){let t={uuid:e.uuid,category:`spatialUnit`,publicationDateTime:e.publicationDateTime==null?null:new Date(e.publicationDateTime),type:e.type,number:e.n,context:`context`in e&&e.context?N(e.context):null,license:`availability`in e&&e.availability?P(e.availability):null,identification:j(e.identification),image:e.image?R(e.image):null,description:e.description?[`string`,`number`,`boolean`].includes(typeof e.description)?D(e.description):A(e.description):``,coordinates:e.coordinates?B(e.coordinates):e.coordinate?B(e.coordinate):null,observations:`observations`in e&&e.observations?ce(Array.isArray(e.observations.observation)?e.observations.observation:[e.observations.observation]):e.observation?[V(e.observation)]:[],events:`events`in e&&e.events?H(Array.isArray(e.events.event)?e.events.event:[e.events.event]):[],properties:`properties`in e&&e.properties?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[]};return t}
|
|
449
|
+
/**
|
|
450
|
+
* Parses an array of raw spatial units into standardized SpatialUnit objects
|
|
451
|
+
*
|
|
452
|
+
* @param spatialUnits - Array of raw spatial units in OCHRE format
|
|
453
|
+
* @returns Array of parsed SpatialUnit objects
|
|
454
|
+
*/
|
|
455
|
+
function he(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(me(e));return t}
|
|
456
|
+
/**
|
|
457
|
+
* Parses a raw concept into a standardized Concept object
|
|
458
|
+
*
|
|
459
|
+
* @param concept - Raw concept data in OCHRE format
|
|
460
|
+
* @returns Parsed Concept object
|
|
461
|
+
*/
|
|
462
|
+
function ge(e){let t={uuid:e.uuid,category:`concept`,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,number:e.n,license:`availability`in e&&e.availability?P(e.availability):null,context:`context`in e&&e.context?N(e.context):null,identification:j(e.identification),interpretations:ue(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation])};return t}
|
|
463
|
+
/**
|
|
464
|
+
* Parses raw webpage resources into standardized WebElement or Webpage objects
|
|
465
|
+
*
|
|
466
|
+
* @param webpageResources - Array of raw webpage resources in OCHRE format
|
|
467
|
+
* @param type - Type of resource to parse ("element" or "page")
|
|
468
|
+
* @returns Array of parsed WebElement or Webpage objects
|
|
469
|
+
*/
|
|
470
|
+
const _e=async(e,t)=>{let n=[];for(let r of e){let e=r.properties?U(Array.isArray(r.properties.property)?r.properties.property:[r.properties.property]):[],i=e.find(e=>e.label===`presentation`&&e.values[0].content===t);if(!i)continue;switch(t){case`element`:{let e=await $(r);n.push(e);break}case`page`:{let e=await ye(r);e&&n.push(e);break}case`block`:{let e=await xe(r);e&&n.push(e);break}}}return n};
|
|
471
|
+
/**
|
|
472
|
+
* Parses raw concept data into standardized Concept objects
|
|
473
|
+
*
|
|
474
|
+
* @param concepts - Array of raw concept data in OCHRE format
|
|
475
|
+
* @returns Array of parsed Concept objects
|
|
476
|
+
*/
|
|
477
|
+
function Q(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(ge(e));return t}
|
|
478
|
+
/**
|
|
479
|
+
* Parses raw web element properties into a standardized WebElementComponent structure
|
|
480
|
+
*
|
|
481
|
+
* @param componentProperty - Raw component property data in OCHRE format
|
|
482
|
+
* @param elementResource - Raw element resource data in OCHRE format
|
|
483
|
+
* @returns Parsed WebElementComponent object
|
|
484
|
+
*/
|
|
485
|
+
async function ve(e,t){let n=d.parse(e.values[0].content),r={component:n},i=t.links?I(Array.isArray(t.links)?t.links:[t.links]):[],a=i.filter(e=>e.type===`image`||e.type===`IIIF`),o=t.document&&`content`in t.document?L(t.document.content):null;if(o===null){let e=i.find(e=>e.type===`internalDocument`);if(e){let{item:t,error:n}=await re(e.uuid,`resource`);if(n!==null)throw Error(`Failed to fetch OCHRE data`);o=t.document}}switch(n){case`annotated-document`:if(!o)throw Error(`Document not found for the following component: “${n}”`);r.document=o;break;case`annotated-image`:{if(a.length===0)throw Error(`Image link not found for the following component: “${n}”`);let t=x(e.properties,`is-searchable`)===`Yes`;r.imageUuid=a[0].uuid,r.isSearchable=t;break}case`bibliography`:{let t=i.find(e=>e.category===`bibliography`);if(!t)throw Error(`Bibliography link not found for the following component: “${n}”`);if(!t.bibliographies)throw Error(`Bibliography not found for the following component: “${n}”`);let a=x(e.properties,`layout`);a??=`long`,r.bibliographies=t.bibliographies,r.layout=a;break}case`button`:{let i=x(e.properties,`variant`);i??=`default`;let a=!1,o=x(e.properties,`navigate-to`);if(o===null){if(o=x(e.properties,`link-to`),o===null)throw Error(`Properties “navigate-to” or “link-to” not found for the following component: “${n}”`);a=!0}let s=null,c=x(e.properties,`icon`);c!==null&&(s=c),r.variant=i,r.href=o,r.isExternal=a,r.label=[`string`,`number`,`boolean`].includes(typeof t.identification.label)?D(t.identification.label):A(t.identification.label),r.icon=s;break}case`collection`:{let t=i.find(e=>e.category===`set`);if(!t)throw Error(`Collection link not found for the following component: “${n}”`);let a=x(e.properties,`variant`);a??=`full`;let o=x(e.properties,`item-variant`);o??=`default`;let s=!1,c=x(e.properties,`show-count`);c!==null&&(s=c===`Yes`);let l=!1,u=x(e.properties,`is-searchable`);u!==null&&(l=u===`Yes`);let d=x(e.properties,`layout`);d??=`image-start`,r.collectionId=t.uuid,r.variant=a,r.itemVariant=o,r.isSearchable=l,r.showCount=s,r.layout=d;break}case`empty-space`:{let t=x(e.properties,`height`),n=x(e.properties,`width`);r.height=t,r.width=n;break}case`entries`:{let t=i.find(e=>e.category===`tree`);if(!t)throw Error(`Entries link not found for the following component: “${n}”`);let a=x(e.properties,`variant`);a??=`entry`;let o=!1,s=x(e.properties,`is-searchable`);s!==null&&(o=s===`Yes`),r.entriesId=t.uuid,r.variant=a,r.isSearchable=o;break}case`filter-categories`:{let e=i.find(e=>e.category===`set`);if(!e)throw Error(`Filter link not found for the following component: “${n}”`);r.filterId=e.uuid;break}case`iframe`:{let t=i.find(e=>e.type===`webpage`)?.href;if(!t)throw Error(`URL not found for the following component: “${n}”`);let a=x(e.properties,`height`),o=x(e.properties,`width`);r.href=t,r.height=a,r.width=o;break}case`iiif-viewer`:{let e=i.find(e=>e.type===`IIIF`);if(!e)throw Error(`Manifest link not found for the following component: “${n}”`);r.IIIFId=e.uuid;break}case`image`:{if(a.length===0)throw Error(`Image link not found for the following component: “${n}”`);let t=[];for(let e of a)t.push({url:`https://ochre.lib.uchicago.edu/ochre?uuid=${e.uuid}&load`,label:e.identification?.label??null,width:e.image?.width??0,height:e.image?.height??0});let i=x(e.properties,`variant`);i??=`default`;let o=x(e.properties,`layout-caption`);o??=`bottom`;let s=null,c=x(e.properties,`width`);c!==null&&(typeof c==`number`?s=c:typeof c==`string`&&(s=Number.parseFloat(c)));let l=null,u=x(e.properties,`height`);u!==null&&(typeof u==`number`?l=u:typeof u==`string`&&(l=Number.parseFloat(u)));let d=!0,f=x(e.properties,`is-full-width`);f!==null&&(d=f===`Yes`);let p=!0,m=x(e.properties,`is-full-height`);m!==null&&(p=m===`Yes`);let h=x(e.properties,`image-quality`);h??=`high`;let g=x(e.properties,`caption-source`);g??=`name`;let _=x(e.properties,`alt-text-source`);_??=`name`;let v=!1,b=x(e.properties,`is-transparent`);b!==null&&(v=b===`Yes`);let S=!1,C=x(e.properties,`is-cover`);C!==null&&(S=C===`Yes`);let w=null;if(t.length>1){let t=y(e.properties,`variant`),n=5;if(t&&t.values[0].content===`carousel`){let e=x(t.properties,`seconds-per-image`);e!==null&&(typeof e==`number`?n=e:typeof e==`string`&&(n=Number.parseFloat(e)))}w={secondsPerImage:n}}r.images=t,r.variant=i,r.width=s,r.height=l,r.isFullWidth=d,r.isFullHeight=p,r.imageQuality=h,r.captionLayout=o,r.captionSource=g,r.altTextSource=_,r.isTransparentBackground=v,r.isCover=S,r.carouselOptions=w;break}case`image-gallery`:{let t=i.find(e=>e.category===`tree`||e.category===`set`);if(!t)throw Error(`Image gallery link not found for the following component: “${n}”`);let a=x(e.properties,`is-searchable`)===`Yes`;r.galleryId=t.uuid,r.isSearchable=a;break}case`n-columns`:{let e=t.resource?await _e(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];r.columns=e;break}case`n-rows`:{let e=t.resource?await _e(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];r.rows=e;break}case`network-graph`:break;case`table`:{let e=i.find(e=>e.category===`set`);if(!e)throw Error(`Table link not found for the following component: “${n}”`);r.tableId=e.uuid;break}case`search-bar`:{let t=x(e.properties,`variant`);t??=`default`,r.variant=t;break}case`text`:{if(!o)throw Error(`Document not found for the following component: “${n}”`);let t=x(e.properties,`variant`);t??=`block`;let i=x(e.properties,`heading`);r.variant=t,r.heading=i,r.content=o.content;break}case`timeline`:{let e=i.find(e=>e.category===`tree`);if(!e)throw Error(`Timeline link not found for the following component: “${n}”`);r.timelineId=e.uuid;break}case`video`:{let t=i.find(e=>e.type===`video`);if(!t)throw Error(`Video link not found for the following component: “${n}”`);let a=x(e.properties,`chapters-displayed`);a??=`Yes`,r.videoId=t.uuid,r.isChaptersDislayed=a===`Yes`;break}default:console.warn(`Invalid or non-implemented component name “${n}” for the following element: “${A(t.identification.label)}”`);break}return r}
|
|
486
|
+
/**
|
|
487
|
+
* Parses raw web element data into a standardized WebElement structure
|
|
488
|
+
*
|
|
489
|
+
* @param elementResource - Raw element resource data in OCHRE format
|
|
490
|
+
* @returns Parsed WebElement object
|
|
491
|
+
*/
|
|
492
|
+
async function $(e){let t=j(e.identification),n=e.properties?.property?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],r=n.find(e=>e.label===`presentation`);if(!r)throw Error(`Presentation property not found for element “${t.label}”`);let i=r.properties.find(e=>e.label===`component`);if(!i)throw Error(`Component for element “${t.label}” not found`);let a=await ve(i,e),o=r.properties.find(e=>e.label===`section-sidebar-displayed`),s=o?.values[0]?.booleanValue===!0,c=e.properties?.property?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],l=c.find(e=>e.label===`presentation`&&e.values[0].content===`css`)?.properties??[],u=[];for(let e of l){let t=e.values[0].content;u.push({label:e.label,value:t})}let d=c.find(e=>e.label===`presentation`&&e.values[0].content===`css-mobile`)?.properties??[],f=[];for(let e of d){let t=e.values[0].content;f.push({label:e.label,value:t})}let p=c.find(e=>e.label===`presentation`&&e.values[0].content===`title`)?.properties,m=`default`,h=!1,g=!1,_=!1,v=!1;if(p){let e=x(p,`variant`);e&&(m=e);let t=p.filter(e=>e.label===`display`);t.length>0&&(h=t.some(e=>e.values[0].content===`name`),g=t.some(e=>e.values[0].content===`description`),_=t.some(e=>e.values[0].content===`date`),v=t.some(e=>e.values[0].content===`creators`))}return{uuid:e.uuid,type:`element`,title:{label:t.label,variant:m,properties:{isNameDisplayed:h,isDescriptionDisplayed:g,isDateDisplayed:_,isCreatorsDisplayed:v}},isDisplayedInBlockSectionSidebar:s,cssStyles:u,cssStylesMobile:f,...a}}
|
|
493
|
+
/**
|
|
494
|
+
* Parses raw webpage data into a standardized Webpage structure
|
|
495
|
+
*
|
|
496
|
+
* @param webpageResource - Raw webpage resource data in OCHRE format
|
|
497
|
+
* @returns Parsed Webpage object
|
|
498
|
+
*/
|
|
499
|
+
async function ye(e){let t=e.properties?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];if(t.length===0||t.find(e=>e.label===`presentation`)?.values[0]?.content!==`page`)return null;let n=j(e.identification),r=e.slug;if(r===void 0)throw Error(`Slug not found for page “${n.label}”`);let i=e.links?I(Array.isArray(e.links)?e.links:[e.links]):[],a=i.find(e=>e.type===`image`||e.type===`IIIF`),o=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],s=[];for(let e of o){let t=e.properties?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=x(t,`presentation`);if(n==null)continue;switch(n){case`element`:{let t=await $(e);s.push(t);break}case`block`:{let t=await xe(e);t&&s.push(t);break}}}let c=e.resource?await _e(Array.isArray(e.resource)?e.resource:[e.resource],`page`):[],l=!0,u=`default`,d=`default`,f=!0,p=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`page`)?.properties;if(p){let e=p.find(e=>e.label===`header`)?.values[0];e&&(l=e.content===`Yes`);let t=p.find(e=>e.label===`width`)?.values[0];t&&(u=t.content);let n=p.find(e=>e.label===`variant`)?.values[0];n&&(d=n.content);let r=p.find(e=>e.label===`sidebar-visible`)?.values[0];r&&(f=r.content===`Yes`)}let m=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css`)?.properties,h=[];if(m)for(let e of m)h.push({label:e.label,value:e.values[0].content});let g=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css-mobile`)?.properties,_=[];if(g)for(let e of g)_.push({label:e.label,value:e.values[0].content});return{title:n.label,slug:r,items:s,properties:{displayedInHeader:l,width:u,variant:d,backgroundImageUrl:a?`https://ochre.lib.uchicago.edu/ochre?uuid=${a.uuid}&load`:null,isSidebarDisplayed:f,cssStyles:h,cssStylesMobile:_},webpages:c}}
|
|
500
|
+
/**
|
|
501
|
+
* Parses raw webpage resources into an array of Webpage objects
|
|
502
|
+
*
|
|
503
|
+
* @param webpageResources - Array of raw webpage resources in OCHRE format
|
|
504
|
+
* @returns Array of parsed Webpage objects
|
|
505
|
+
*/
|
|
506
|
+
async function be(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n){let n=await ye(e);n&&t.push(n)}return t}
|
|
507
|
+
/**
|
|
508
|
+
* Parses raw block data into a standardized Block structure
|
|
509
|
+
*
|
|
510
|
+
* @param blockResource - Raw block resource data in OCHRE format
|
|
511
|
+
* @returns Parsed Block object
|
|
512
|
+
*/
|
|
513
|
+
async function xe(e){let t={uuid:e.uuid,type:`block`,layout:`vertical`,items:[],properties:{spacing:void 0,gap:void 0,alignItems:`start`,justifyContent:`stretch`,sectionSidebarItems:null},propertiesMobile:null,cssStyles:[],cssStylesMobile:[]},n=e.properties?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],r=n.find(e=>e.label===`presentation`&&e.values[0]?.content===`block`)?.properties;if(r){let e=r.find(e=>e.label===`layout`)?.values[0];e&&(t.layout=e.content);let n=r.find(e=>e.label===`spacing`)?.values[0];n&&(t.properties.spacing=n.content);let i=r.find(e=>e.label===`gap`)?.values[0];i&&(t.properties.gap=i.content);let a=r.find(e=>e.label===`align-items`)?.values[0];a&&(t.properties.alignItems=a.content);let o=r.find(e=>e.label===`justify-content`)?.values[0];o&&(t.properties.justifyContent=o.content);let s=r.find(e=>e.label===`overwrite-mobile`);if(s){let e=s.properties,n={};for(let t of e)n[t.label]=t.values[0].content;t.propertiesMobile=n}}let i=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],a=[];for(let e of i){let t=e.properties?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=x(t,`presentation`);if(n==null)continue;switch(n){case`element`:{let t=await $(e);a.push(t);break}case`block`:{let t=await xe(e);t&&a.push(t);break}}}t.items=a;let o=n.find(e=>e.label===`presentation`&&e.values[0]?.content===`css`)?.properties;if(o)for(let e of o)t.cssStyles.push({label:e.label,value:e.values[0].content});let s=n.find(e=>e.label===`presentation`&&e.values[0]?.content===`css-mobile`)?.properties;if(s)for(let e of s)t.cssStylesMobile.push({label:e.label,value:e.values[0].content});return t.properties.sectionSidebarItems=Se(t),t}function Se(e){let t=[];for(let n of e.items)switch(n.type){case`block`:{let e=Se(n);e!==null&&t.push({uuid:n.uuid,type:`block`,name:null,items:e});break}case`element`:{let e=n.isDisplayedInBlockSectionSidebar;if(!e)continue;t.push({uuid:n.uuid,type:`element`,name:n.title.label,items:null});break}}return t.length>0?t:null}
|
|
514
|
+
/**
|
|
515
|
+
* Parses raw website properties into a standardized WebsiteProperties structure
|
|
516
|
+
*
|
|
517
|
+
* @param properties - Array of raw website properties in OCHRE format
|
|
518
|
+
* @returns Parsed WebsiteProperties object
|
|
519
|
+
*/
|
|
520
|
+
function Ce(e){let t=U(e),n=t.find(e=>e.label===`presentation`)?.properties;if(!n)throw Error(`Presentation property not found`);let r=n.find(e=>e.label===`webUI`)?.values[0]?.content;if(r==null)throw Error(`Website type not found`);let i=n.find(e=>e.label===`status`)?.values[0]?.content;if(i==null)throw Error(`Website status not found`);let a=n.find(e=>e.label===`privacy`)?.values[0]?.content;a??=`public`;let o=u.safeParse({type:r,status:i,privacy:a});if(!o.success)throw Error(`Invalid website properties: ${o.error.message}`);let s=null,c=n.find(e=>e.label===`contact`);if(c){let[e,t]=(c.values[0]?.content).split(`;`);s={name:e,email:t??null}}let l=n.find(e=>e.label===`logo`)?.values[0]?.uuid??null,d=!0,f=`default`,p=`start`,m=!0,h=!0,g=!1,_=!0,v=n.find(e=>e.label===`navbar-visible`)?.values[0];v&&(d=v.content===`Yes`);let y=n.find(e=>e.label===`navbar-variant`)?.values[0];y&&(f=y.content);let b=n.find(e=>e.label===`navbar-alignment`)?.values[0];b&&(p=b.content);let x=n.find(e=>e.label===`navbar-project-visible`)?.values[0];x&&(m=x.content===`Yes`);let S=n.find(e=>e.label===`footer-visible`)?.values[0];S&&(h=S.content===`Yes`);let C=n.find(e=>e.label===`sidebar-visible`)?.values[0];C&&(g=C.content===`Yes`);let w=n.find(e=>e.label===`supports-theme-toggle`)?.values[0];w&&(_=w.content===`Yes`);let{type:T,status:ee,privacy:E}=o.data;return{type:T,privacy:E,status:ee,contact:s,isHeaderDisplayed:d,headerVariant:f,headerAlignment:p,isHeaderProjectDisplayed:m,isFooterDisplayed:h,isSidebarDisplayed:g,supportsThemeToggle:_,logoUrl:l===null?null:`https://ochre.lib.uchicago.edu/ochre?uuid=${l}&load`}}async function we(e,t,n){if(!e.properties)throw Error(`Website properties not found`);let r=Ce(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]);if(typeof e.items==`string`||!(`resource`in e.items))throw Error(`Website pages not found`);let i=Array.isArray(e.items.resource)?e.items.resource:[e.items.resource],a=await be(i),o=null,s=[],c={label:``,variant:`default`,properties:{isNameDisplayed:!1,isDescriptionDisplayed:!1,isDateDisplayed:!1,isCreatorsDisplayed:!1}},l=`start`,u=`default`,d=[],f=[],p=i.find(e=>{let t=e.properties?U(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];return t.some(e=>e.label===`presentation`&&e.values[0]?.content===`element`&&e.properties[0]?.label===`component`&&e.properties[0].values[0]?.content===`sidebar`)});if(p){c.label=typeof p.identification.label==`string`||typeof p.identification.label==`number`||typeof p.identification.label==`boolean`?D(p.identification.label):A(p.identification.label);let e=p.properties?U(Array.isArray(p.properties.property)?p.properties.property:[p.properties.property]):[],t=e.find(e=>e.label===`presentation`&&e.values[0]?.content===`element`)?.properties.find(e=>e.label===`component`&&e.values[0]?.content===`sidebar`)?.properties??[],n=t.find(e=>e.label===`layout`);n&&(l=n.values[0].content);let r=t.find(e=>e.label===`layout-mobile`);r&&(u=r.values[0].content);let i=e.find(e=>e.label===`presentation`&&e.values[0].content===`css`)?.properties??[];for(let e of i){let t=e.values[0].content;d.push({label:e.label,value:t})}let a=e.find(e=>e.label===`presentation`&&e.values[0].content===`css-mobile`)?.properties??[];for(let e of a){let t=e.values[0].content;f.push({label:e.label,value:t})}let o=e.find(e=>e.label===`presentation`&&e.values[0].content===`title`)?.properties;if(o){let e=x(o,`variant`);e&&(c.variant=e);let t=o.filter(e=>e.label===`display`);t.length>0&&(c.properties.isNameDisplayed=t.some(e=>e.values[0].content===`name`),c.properties.isDescriptionDisplayed=t.some(e=>e.values[0].content===`description`),c.properties.isDateDisplayed=t.some(e=>e.values[0].content===`date`),c.properties.isCreatorsDisplayed=t.some(e=>e.values[0].content===`creators`))}let m=p.resource?Array.isArray(p.resource)?p.resource:[p.resource]:[];for(let e of m){let t=await $(e);s.push(t)}}s.length>0&&(o={elements:s,title:c,layout:l,mobileLayout:u,cssStyles:d,cssStylesMobile:f});let m=null;if(e.collectionOptions){let t=[];for(let e of a)for(let n of e.items)n.type===`element`&&n.component===`collection`&&t.push(n.collectionId);m={uuids:t,properties:{metadataUuids:e.collectionOptions.metadataUuids.uuid?(Array.isArray(e.collectionOptions.metadataUuids.uuid)?e.collectionOptions.metadataUuids.uuid:[e.collectionOptions.metadataUuids.uuid]).map(e=>e.content):[],searchUuids:e.collectionOptions.searchUuids.uuid?(Array.isArray(e.collectionOptions.searchUuids.uuid)?e.collectionOptions.searchUuids.uuid:[e.collectionOptions.searchUuids.uuid]).map(e=>e.content):[],labelUuids:e.collectionOptions.labelUuids.uuid?(Array.isArray(e.collectionOptions.labelUuids.uuid)?e.collectionOptions.labelUuids.uuid:[e.collectionOptions.labelUuids.uuid]).map(e=>e.content):[]}}}return{uuid:e.uuid,publicationDateTime:e.publicationDateTime?new Date(e.publicationDateTime):null,identification:j(e.identification),project:{name:D(t),website:n===null?null:D(n)},creators:e.creators?F(Array.isArray(e.creators.creator)?e.creators.creator:[e.creators.creator]):[],license:P(e.availability),pages:a,sidebar:o,properties:r,collectionOptions:m}}
|
|
521
|
+
/**
|
|
522
|
+
* Fetches and parses a gallery from the OCHRE API
|
|
523
|
+
*
|
|
524
|
+
* @param uuid - The UUID of the gallery
|
|
525
|
+
* @param filter - The filter to apply to the gallery
|
|
526
|
+
* @param page - The page number to fetch
|
|
527
|
+
* @param perPage - The number of items per page
|
|
528
|
+
* @returns The parsed gallery or null if the fetch/parse fails
|
|
529
|
+
*
|
|
530
|
+
* @example
|
|
531
|
+
* ```ts
|
|
532
|
+
* const gallery = await fetchGallery("9c4da06b-f15e-40af-a747-0933eaf3587e", "1978", 1, 12);
|
|
533
|
+
* if (gallery === null) {
|
|
534
|
+
* console.error("Failed to fetch gallery");
|
|
535
|
+
* return;
|
|
536
|
+
* }
|
|
537
|
+
* console.log(`Fetched gallery: ${gallery.identification.label}`);
|
|
538
|
+
* console.log(`Contains ${gallery.resources.length.toLocaleString()} resources`);
|
|
539
|
+
* ```
|
|
540
|
+
*
|
|
541
|
+
* @remarks
|
|
542
|
+
* The returned gallery includes:
|
|
543
|
+
* - Gallery metadata and identification
|
|
544
|
+
* - Project identification
|
|
545
|
+
* - Resources (gallery items)
|
|
546
|
+
*/
|
|
547
|
+
async function Te(e,t,n,r){try{let{uuid:i,filter:a,page:o,perPage:s}=m.parse({uuid:e,filter:t,page:n,perPage:r}),c=await fetch(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
|
|
5
548
|
for $q in input()/ochre[@uuid='${i}']
|
|
6
|
-
let $filtered := $q//items/resource[contains(lower-case(identification/label), lower-case('${
|
|
549
|
+
let $filtered := $q//items/resource[contains(lower-case(identification/label), lower-case('${a}'))]
|
|
7
550
|
let $maxLength := count($filtered)
|
|
8
551
|
return <gallery maxLength='{$maxLength}'>
|
|
9
552
|
{$q/metadata/project}
|
|
10
553
|
{$q/metadata/item}
|
|
11
|
-
{$filtered[position() >= ${((o-1)*
|
|
554
|
+
{$filtered[position() >= ${((o-1)*s+1).toString()} and position() < ${(o*s+1).toString()}]}
|
|
12
555
|
</gallery>
|
|
13
|
-
`)}&format=json`);if(!
|
|
556
|
+
`)}&format=json`);if(!c.ok)throw Error(`Error fetching gallery items, please try again later.`);let l=await c.json();if(!(`gallery`in l.result))throw Error(`Failed to fetch gallery`);let u=j(l.result.gallery.item.identification),d=j(l.result.gallery.project.identification),f={identification:u,projectIdentification:d,resources:Z(l.result.gallery.resource?Array.isArray(l.result.gallery.resource)?l.result.gallery.resource:[l.result.gallery.resource]:[]),maxLength:l.result.gallery.maxLength};return{item:f,error:null}}catch(e){return console.error(e),{item:null,error:e instanceof Error?e.message:`Failed to fetch gallery`}}}
|
|
557
|
+
/**
|
|
558
|
+
* Fetches and parses a website configuration from the OCHRE API
|
|
559
|
+
*
|
|
560
|
+
* @param abbreviation - The abbreviation identifier for the website
|
|
561
|
+
* @returns The parsed website configuration or null if the fetch/parse fails
|
|
562
|
+
*
|
|
563
|
+
* @example
|
|
564
|
+
* ```ts
|
|
565
|
+
* const website = await fetchWebsite("guerrilla-television");
|
|
566
|
+
* if (website === null) {
|
|
567
|
+
* console.error("Failed to fetch website");
|
|
568
|
+
* return;
|
|
569
|
+
* }
|
|
570
|
+
* console.log(`Fetched website: ${website.identification.label}`);
|
|
571
|
+
* console.log(`Contains ${website.pages.length.toLocaleString()} pages`);
|
|
572
|
+
* ```
|
|
573
|
+
*
|
|
574
|
+
* @remarks
|
|
575
|
+
* The returned website configuration includes:
|
|
576
|
+
* - Website metadata and identification
|
|
577
|
+
* - Page structure and content
|
|
578
|
+
* - Layout and styling properties
|
|
579
|
+
* - Navigation configuration
|
|
580
|
+
* - Sidebar elements
|
|
581
|
+
* - Project information
|
|
582
|
+
* - Creator details
|
|
583
|
+
*
|
|
584
|
+
* The abbreviation is case-insensitive and should match the website's configured abbreviation in OCHRE.
|
|
585
|
+
*/
|
|
586
|
+
async function Ee(e){try{let t=await fetch(`https://ochre.lib.uchicago.edu/ochre?xquery=for $q in input()/ochre[tree[@type='lesson'][identification/abbreviation='${e.toLocaleLowerCase(`en-US`)}']] return $q&format=json`);if(!t.ok)throw Error(`Failed to fetch website`);let n=await t.json();if(!(`ochre`in n.result)||!(`tree`in n.result.ochre))throw Error(`Failed to fetch website`);let r=n.result.ochre.metadata.project?.identification?j(n.result.ochre.metadata.project.identification):null,i=await we(n.result.ochre.tree,r?.label??``,n.result.ochre.metadata.project?.identification.website??null);return i}catch(e){return console.error(e),null}}exports.fetchByUuid=ne,exports.fetchGallery=Te,exports.fetchItem=re,exports.fetchWebsite=Ee,exports.filterProperties=C,exports.getPropertyByLabel=y,exports.getPropertyValueByLabel=x,exports.getPropertyValuesByLabel=b,exports.getUniqueProperties=S,exports.parseBibliographies=q,exports.parseBibliography=K,exports.parseConcept=ge,exports.parseConcepts=Q,exports.parseContext=N,exports.parseCoordinates=B,exports.parseDocument=L,exports.parseEmail=T,exports.parseEvents=H,exports.parseFakeString=D,exports.parseIdentification=j,exports.parseImage=R,exports.parseImageMap=de,exports.parseInterpretations=ue,exports.parseLanguages=ie,exports.parseLicense=P,exports.parseLink=se,exports.parseLinks=I,exports.parseMetadata=ae,exports.parseNotes=z,exports.parseObservation=V,exports.parseObservations=ce,exports.parsePeriod=W,exports.parsePeriods=G,exports.parsePerson=oe,exports.parsePersons=F,exports.parseProperties=U,exports.parseProperty=le,exports.parsePropertyValue=J,exports.parsePropertyValues=Y,exports.parseResource=X,exports.parseResources=Z,exports.parseSet=pe,exports.parseSpatialUnit=me,exports.parseSpatialUnits=he,exports.parseStringContent=A,exports.parseStringDocumentItem=k,exports.parseStringItem=O,exports.parseTree=fe,exports.parseWebsite=we;
|