@digitalculture/ochre-sdk 0.7.12 → 0.7.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -141,14 +141,14 @@ function y(e,t){let n=e,r=c.safeParse(t);if(!r.success)return console.warn(`Inva
141
141
  * parseFakeString("test"); // Returns "test"
142
142
  * ```
143
143
  */
144
- function b(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\.`)}
144
+ function b(e){return String(e).replaceAll(`'`,`'`)}
145
145
  /**
146
146
  * Parses an OchreStringItem into a formatted string
147
147
  *
148
148
  * @param item - OchreStringItem to parse
149
149
  * @returns Formatted string with applied rendering and whitespace
150
150
  */
151
- function x(e){let t=``;switch(typeof e.string){case`string`:t=e.string;break;case`number`:case`boolean`:t=b(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+=b(e);else{let n=e.rend==null?b(e.content):v(b(e.content),e.rend),r=e.whitespace==null?n:y(n,e.whitespace);t+=r}break}default:t=``;break}return t.replaceAll(`'`,`'`).replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}
151
+ function x(e){let t=``;switch(typeof e.string){case`string`:case`number`:case`boolean`:t=b(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+=b(e);else{let n=e.rend==null?b(e.content):v(b(e.content),e.rend),r=e.whitespace==null?n:y(n,e.whitespace);t+=r}break}default:t=``;break}return t}
152
152
  /**
153
153
  * Parses rich text content into a formatted string with links and annotations
154
154
  *
@@ -157,7 +157,7 @@ function x(e){let t=``;switch(typeof e.string){case`string`:t=e.string;break;cas
157
157
  * @returns Formatted string with HTML/markdown elements
158
158
  */
159
159
  function S(e,t){if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return _(b(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`?C(e.string):b(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=b(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)?b(t.identification.label):C(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+=S(e,t);return`whitespace`in e&&e.whitespace!=null&&(n=y(_(n),e.whitespace)),n.replaceAll(`&#39;`,`'`).replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}else n=b(e.content),e.rend!=null&&(n=v(_(n),e.rend)),e.whitespace!=null&&(n=y(_(n),e.whitespace));return n.replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}
160
+ `:``;if(`links`in e){let n=``;n=typeof e.string==`object`?C(e.string):b(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=b(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)?b(t.identification.label):C(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+=S(e,t);return`whitespace`in e&&e.whitespace!=null&&(n=y(_(n),e.whitespace)),n.replaceAll(`&#39;`,`'`)}else n=b(e.content),e.rend!=null&&(n=v(_(n),e.rend)),e.whitespace!=null&&(n=y(_(n),e.whitespace));return n}
161
161
  /**
162
162
  * Parses raw string content into a formatted string
163
163
  *
@@ -165,7 +165,7 @@ function S(e,t){if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)r
165
165
  * @param language - Optional language code for content selection (defaults to "eng")
166
166
  * @returns Parsed and formatted string
167
167
  */
168
- function C(e,t=`eng`){switch(typeof e.content){case`string`:case`number`:case`boolean`:return b(e.content);case`object`:if(Array.isArray(e.content)){let n=g(e.content,t);if(n)return x(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 x(n)}}else return x(e.content);default:return String(e.content).replaceAll(/^(\d+)\./gm,String.raw`$1\.`)}}
168
+ function C(e,t=`eng`){switch(typeof e.content){case`string`:case`number`:case`boolean`:return b(e.content);case`object`:if(Array.isArray(e.content)){let n=g(e.content,t);if(n)return x(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 x(n)}}else return x(e.content);default:return String(e.content)}}
169
169
  /**
170
170
  * Get the category of an item from the OCHRE API response
171
171
  * @param keys - The keys of the OCHRE API response
@@ -225,7 +225,7 @@ async function T(e){try{let n=t.parse(e),r=await fetch(`https://ochre.lib.uchica
225
225
  *
226
226
  * If the fetch/parse fails, the returned object will have an `error` property.
227
227
  */
228
- async function E(e,t,n){try{let[r,i]=await T(e);if(r!==null)throw Error(r);let a=w(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=q(i.ochre.resource);break;case`spatialUnit`:if(!(`spatialUnit`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'spatialUnit' key`);o=Y(i.ochre.spatialUnit);break;case`concept`:if(!(`concept`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'concept' key`);o=Z(i.ochre.concept);break;case`period`:if(!(`period`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'period' key`);o=V(i.ochre.period);break;case`bibliography`:if(!(`bibliography`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'bibliography' key`);o=U(i.ochre.bibliography);break;case`person`:if(!(`person`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'person' key`);o=j(i.ochre.person);break;case`propertyValue`:if(!(`propertyValue`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'propertyValue' key`);o=G(i.ochre.propertyValue);break;case`set`:if(!(`set`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'set' key`);o=ce(i.ochre.set,n);break;case`tree`:if(!(`tree`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'tree' key`);o=se(i.ochre.tree);break;default:throw Error(`Invalid category`)}let s=te(i.ochre.metadata),c={uuid:i.ochre.uuidBelongsTo,abbreviation:b(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}}}
228
+ async function E(e,t,n){try{let[r,i]=await T(e);if(r!==null)throw Error(r);let a=w(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=q(i.ochre.resource);break;case`spatialUnit`:if(!(`spatialUnit`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'spatialUnit' key`);o=Y(i.ochre.spatialUnit);break;case`concept`:if(!(`concept`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'concept' key`);o=le(i.ochre.concept);break;case`period`:if(!(`period`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'period' key`);o=V(i.ochre.period);break;case`bibliography`:if(!(`bibliography`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'bibliography' key`);o=U(i.ochre.bibliography);break;case`person`:if(!(`person`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'person' key`);o=j(i.ochre.person);break;case`propertyValue`:if(!(`propertyValue`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'propertyValue' key`);o=G(i.ochre.propertyValue);break;case`set`:if(!(`set`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'set' key`);o=ce(i.ochre.set,n);break;case`tree`:if(!(`tree`in i.ochre))throw Error(`Invalid OCHRE data: API response missing 'tree' key`);o=se(i.ochre.tree);break;default:throw Error(`Invalid category`)}let s=te(i.ochre.metadata),c={uuid:i.ochre.uuidBelongsTo,abbreviation:b(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
229
  /**
230
230
  * Parses raw identification data into the standardized Identification type
231
231
  *
@@ -325,7 +325,7 @@ function I(e,t=`eng`){let n=[];for(let r of e){if(typeof r==`string`){if(r===``)
325
325
  * @param coordinates - Raw coordinates data in OCHRE format
326
326
  * @returns Parsed Coordinates object
327
327
  */
328
- function L(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:b(e.coord.coordLabel)}}
328
+ function L(e){if(typeof e==`string`){let[t,n]=e.split(`, `);return{latitude:Number(t),longitude:Number(n),type:null,label:null}}return e.coord==null?null:{latitude:e.coord.coordLatitude,longitude:e.coord.coordLongitude,type:e.coord.coordType,label:b(e.coord.coordLabel)}}
329
329
  /**
330
330
  * Parses a raw observation into a standardized Observation structure
331
331
  *
@@ -459,7 +459,7 @@ function X(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(Y(e));retu
459
459
  * @param concept - Raw concept data in OCHRE format
460
460
  * @returns Parsed Concept object
461
461
  */
462
- function Z(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?A(e.availability):null,context:`context`in e&&e.context?k(e.context):null,identification:D(e.identification),interpretations:ae(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation])};return t}
462
+ function le(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?A(e.availability):null,context:`context`in e&&e.context?k(e.context):null,identification:D(e.identification),interpretations:ae(Array.isArray(e.interpretations.interpretation)?e.interpretations.interpretation:[e.interpretations.interpretation])};return t}
463
463
  /**
464
464
  * Parses raw webpage resources into standardized WebElement or Webpage objects
465
465
  *
@@ -467,14 +467,14 @@ function Z(e){let t={uuid:e.uuid,category:`concept`,publicationDateTime:e.public
467
467
  * @param type - Type of resource to parse ("element" or "page")
468
468
  * @returns Array of parsed WebElement or Webpage objects
469
469
  */
470
- const le=async(e,t)=>{let n=[];for(let r of e){let e=r.properties?B(Array.isArray(r.properties.property)?r.properties.property:[r.properties.property]):[],i=e.find(e=>e.label===`presentation`&&e.values[0].content===t);if(!i)continue;switch(t){case`element`:{let e=await Q(r);n.push(e);break}case`page`:{let e=await fe(r);e&&n.push(e);break}case`block`:{let e=await $(r);e&&n.push(e);break}}}return n};
470
+ const Z=async(e,t)=>{let n=[];for(let r of e){let e=r.properties?B(Array.isArray(r.properties.property)?r.properties.property:[r.properties.property]):[],i=e.find(e=>e.label===`presentation`&&e.values[0].content===t);if(!i)continue;switch(t){case`element`:{let e=await Q(r);n.push(e);break}case`page`:{let e=await fe(r);e&&n.push(e);break}case`block`:{let e=await $(r);e&&n.push(e);break}}}return n};
471
471
  /**
472
472
  * Parses raw concept data into standardized Concept objects
473
473
  *
474
474
  * @param concepts - Array of raw concept data in OCHRE format
475
475
  * @returns Array of parsed Concept objects
476
476
  */
477
- function ue(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(Z(e));return t}
477
+ function ue(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(le(e));return t}
478
478
  /**
479
479
  * Parses raw web element properties into a standardized WebElementComponent structure
480
480
  *
@@ -482,7 +482,7 @@ function ue(e){let t=[],n=Array.isArray(e)?e:[e];for(let e of n)t.push(Z(e));ret
482
482
  * @param elementResource - Raw element resource data in OCHRE format
483
483
  * @returns Parsed WebElementComponent object
484
484
  */
485
- async function de(e,t){let n=r.parse(e.values[0].content),i={component:n},a=t.links?N(Array.isArray(t.links)?t.links:[t.links]):[],o=a.filter(e=>e.type===`image`||e.type===`IIIF`),s=t.document&&`content`in t.document?P(t.document.content):null;if(s===null){let e=a.find(e=>e.type===`internalDocument`);if(e){let{item:t,error:n}=await E(e.uuid,`resource`);if(n!==null)throw Error(`Failed to fetch OCHRE data`);s=t.document}}switch(n){case`annotated-document`:if(!s)throw Error(`Document not found for the following component: “${n}”`);i.document=s;break;case`annotated-image`:{if(o.length===0)throw Error(`Image link not found for the following component: “${n}”`);let t=p(e.properties,`is-searchable`)===`Yes`;i.imageUuid=o[0].uuid,i.isSearchable=t;break}case`bibliography`:{let t=a.find(e=>e.category===`bibliography`);if(!t)throw Error(`Bibliography link not found for the following component: “${n}”`);if(!t.bibliographies)throw Error(`Bibliography not found for the following component: “${n}”`);let r=p(e.properties,`layout`);r??=`long`,i.bibliographies=t.bibliographies,i.layout=r;break}case`button`:{let r=p(e.properties,`variant`);r??=`default`;let a=!1,o=p(e.properties,`navigate-to`);if(o===null){if(o=p(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=p(e.properties,`icon`);c!==null&&(s=c),i.variant=r,i.href=o,i.isExternal=a,i.label=[`string`,`number`,`boolean`].includes(typeof t.identification.label)?b(t.identification.label):C(t.identification.label),i.icon=s;break}case`collection`:{let t=a.find(e=>e.category===`set`);if(!t)throw Error(`Collection link not found for the following component: “${n}”`);let r=p(e.properties,`variant`);r??=`full`;let o=p(e.properties,`item-variant`);o??=`default`;let s=!1,c=p(e.properties,`show-count`);c!==null&&(s=c===`Yes`);let l=!1,u=p(e.properties,`is-searchable`);u!==null&&(l=u===`Yes`);let d=p(e.properties,`layout`);d??=`image-start`,i.collectionId=t.uuid,i.variant=r,i.itemVariant=o,i.isSearchable=l,i.showCount=s,i.layout=d;break}case`empty-space`:{let t=p(e.properties,`height`),n=p(e.properties,`width`);i.height=t,i.width=n;break}case`entries`:{let t=a.find(e=>e.category===`tree`);if(!t)throw Error(`Entries link not found for the following component: “${n}”`);let r=p(e.properties,`variant`);r??=`entry`;let o=!1,s=p(e.properties,`is-searchable`);s!==null&&(o=s===`Yes`),i.entriesId=t.uuid,i.variant=r,i.isSearchable=o;break}case`filter-categories`:{let e=a.find(e=>e.category===`set`);if(!e)throw Error(`Filter link not found for the following component: “${n}”`);i.filterId=e.uuid;break}case`iframe`:{let t=a.find(e=>e.type===`webpage`)?.href;if(!t)throw Error(`URL not found for the following component: “${n}”`);let r=p(e.properties,`height`),o=p(e.properties,`width`);i.href=t,i.height=r,i.width=o;break}case`iiif-viewer`:{let e=a.find(e=>e.type===`IIIF`);if(!e)throw Error(`Manifest link not found for the following component: “${n}”`);i.IIIFId=e.uuid;break}case`image`:{if(o.length===0)throw Error(`Image link not found for the following component: “${n}”`);let t=[];for(let e of o)t.push({url:`https://ochre.lib.uchicago.edu/ochre?uuid=${e.uuid}&load`,label:e.identification?.label??null,width:e.image?.width??0,height:e.image?.height??0});let r=p(e.properties,`variant`);r??=`default`;let a=p(e.properties,`layout-caption`);a??=`bottom`;let s=null,c=p(e.properties,`width`);c!==null&&(typeof c==`number`?s=c:typeof c==`string`&&(s=Number.parseFloat(c)));let l=null,u=p(e.properties,`height`);u!==null&&(typeof u==`number`?l=u:typeof u==`string`&&(l=Number.parseFloat(u)));let f=!0,m=p(e.properties,`is-full-width`);m!==null&&(f=m===`Yes`);let h=!0,g=p(e.properties,`is-full-height`);g!==null&&(h=g===`Yes`);let _=p(e.properties,`image-quality`);_??=`high`;let v=p(e.properties,`caption-source`);v??=`name`;let y=p(e.properties,`alt-text-source`);y??=`name`;let b=!1,x=p(e.properties,`is-transparent`);x!==null&&(b=x===`Yes`);let S=!1,C=p(e.properties,`is-cover`);C!==null&&(S=C===`Yes`);let w=null;if(t.length>1){let t=d(e.properties,`variant`),n=5;if(t&&t.values[0].content===`carousel`){let e=p(t.properties,`seconds-per-image`);e!==null&&(typeof e==`number`?n=e:typeof e==`string`&&(n=Number.parseFloat(e)))}w={secondsPerImage:n}}i.images=t,i.variant=r,i.width=s,i.height=l,i.isFullWidth=f,i.isFullHeight=h,i.imageQuality=_,i.captionLayout=a,i.captionSource=v,i.altTextSource=y,i.isTransparentBackground=b,i.isCover=S,i.carouselOptions=w;break}case`image-gallery`:{let t=a.find(e=>e.category===`tree`||e.category===`set`);if(!t)throw Error(`Image gallery link not found for the following component: “${n}”`);let r=p(e.properties,`is-searchable`)===`Yes`;i.galleryId=t.uuid,i.isSearchable=r;break}case`n-columns`:{let e=t.resource?await le(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];i.columns=e;break}case`n-rows`:{let e=t.resource?await le(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];i.rows=e;break}case`network-graph`:break;case`table`:{let e=a.find(e=>e.category===`set`);if(!e)throw Error(`Table link not found for the following component: “${n}”`);i.tableId=e.uuid;break}case`search-bar`:{let t=p(e.properties,`variant`);t??=`default`,i.variant=t;break}case`text`:{if(!s)throw Error(`Document not found for the following component: “${n}”`);let t=p(e.properties,`variant`);t??=`block`;let r=p(e.properties,`heading`);i.variant=t,i.heading=r,i.content=s.content;break}case`timeline`:{let e=a.find(e=>e.category===`tree`);if(!e)throw Error(`Timeline link not found for the following component: “${n}”`);i.timelineId=e.uuid;break}case`video`:{let t=a.find(e=>e.type===`video`);if(!t)throw Error(`Video link not found for the following component: “${n}”`);let r=p(e.properties,`chapters-displayed`);r??=`Yes`,i.videoId=t.uuid,i.isChaptersDislayed=r===`Yes`;break}default:console.warn(`Invalid or non-implemented component name “${n}” for the following element: “${C(t.identification.label)}”`);break}return i}
485
+ async function de(e,t){let n=r.parse(e.values[0].content),i={component:n},a=t.links?N(Array.isArray(t.links)?t.links:[t.links]):[],o=a.filter(e=>e.type===`image`||e.type===`IIIF`),s=t.document&&`content`in t.document?P(t.document.content):null;if(s===null){let e=a.find(e=>e.type===`internalDocument`);if(e){let{item:t,error:n}=await E(e.uuid,`resource`);if(n!==null)throw Error(`Failed to fetch OCHRE data`);s=t.document}}switch(n){case`annotated-document`:if(!s)throw Error(`Document not found for the following component: “${n}”`);i.document=s;break;case`annotated-image`:{if(o.length===0)throw Error(`Image link not found for the following component: “${n}”`);let t=p(e.properties,`is-searchable`)===`Yes`;i.imageUuid=o[0].uuid,i.isSearchable=t;break}case`bibliography`:{let t=a.find(e=>e.category===`bibliography`);if(!t)throw Error(`Bibliography link not found for the following component: “${n}”`);if(!t.bibliographies)throw Error(`Bibliography not found for the following component: “${n}”`);let r=p(e.properties,`layout`);r??=`long`,i.bibliographies=t.bibliographies,i.layout=r;break}case`button`:{let r=p(e.properties,`variant`);r??=`default`;let a=!1,o=p(e.properties,`navigate-to`);if(o===null){if(o=p(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=p(e.properties,`icon`);c!==null&&(s=c),i.variant=r,i.href=o,i.isExternal=a,i.label=[`string`,`number`,`boolean`].includes(typeof t.identification.label)?b(t.identification.label):C(t.identification.label),i.icon=s;break}case`collection`:{let t=a.find(e=>e.category===`set`);if(!t)throw Error(`Collection link not found for the following component: “${n}”`);let r=p(e.properties,`variant`);r??=`full`;let o=p(e.properties,`item-variant`);o??=`default`;let s=!1,c=p(e.properties,`show-count`);c!==null&&(s=c===`Yes`);let l=!1,u=p(e.properties,`is-searchable`);u!==null&&(l=u===`Yes`);let d=p(e.properties,`layout`);d??=`image-start`,i.collectionId=t.uuid,i.variant=r,i.itemVariant=o,i.isSearchable=l,i.showCount=s,i.layout=d;break}case`empty-space`:{let t=p(e.properties,`height`),n=p(e.properties,`width`);i.height=t,i.width=n;break}case`entries`:{let t=a.find(e=>e.category===`tree`);if(!t)throw Error(`Entries link not found for the following component: “${n}”`);let r=p(e.properties,`variant`);r??=`entry`;let o=!1,s=p(e.properties,`is-searchable`);s!==null&&(o=s===`Yes`),i.entriesId=t.uuid,i.variant=r,i.isSearchable=o;break}case`filter-categories`:{let e=a.find(e=>e.category===`set`);if(!e)throw Error(`Filter link not found for the following component: “${n}”`);i.filterId=e.uuid;break}case`iframe`:{let t=a.find(e=>e.type===`webpage`)?.href;if(!t)throw Error(`URL not found for the following component: “${n}”`);let r=p(e.properties,`height`),o=p(e.properties,`width`);i.href=t,i.height=r,i.width=o;break}case`iiif-viewer`:{let e=a.find(e=>e.type===`IIIF`);if(!e)throw Error(`Manifest link not found for the following component: “${n}”`);i.IIIFId=e.uuid;break}case`image`:{if(o.length===0)throw Error(`Image link not found for the following component: “${n}”`);let t=[];for(let e of o)t.push({url:`https://ochre.lib.uchicago.edu/ochre?uuid=${e.uuid}&load`,label:e.identification?.label??null,width:e.image?.width??0,height:e.image?.height??0});let r=p(e.properties,`variant`);r??=`default`;let a=p(e.properties,`layout-caption`);a??=`bottom`;let s=null,c=p(e.properties,`width`);c!==null&&(typeof c==`number`?s=c:typeof c==`string`&&(s=Number.parseFloat(c)));let l=null,u=p(e.properties,`height`);u!==null&&(typeof u==`number`?l=u:typeof u==`string`&&(l=Number.parseFloat(u)));let f=!0,m=p(e.properties,`is-full-width`);m!==null&&(f=m===`Yes`);let h=!0,g=p(e.properties,`is-full-height`);g!==null&&(h=g===`Yes`);let _=p(e.properties,`image-quality`);_??=`high`;let v=p(e.properties,`caption-source`);v??=`name`;let y=p(e.properties,`alt-text-source`);y??=`name`;let b=!1,x=p(e.properties,`is-transparent`);x!==null&&(b=x===`Yes`);let S=!1,C=p(e.properties,`is-cover`);C!==null&&(S=C===`Yes`);let w=null;if(t.length>1){let t=d(e.properties,`variant`),n=5;if(t&&t.values[0].content===`carousel`){let e=p(t.properties,`seconds-per-image`);e!==null&&(typeof e==`number`?n=e:typeof e==`string`&&(n=Number.parseFloat(e)))}w={secondsPerImage:n}}i.images=t,i.variant=r,i.width=s,i.height=l,i.isFullWidth=f,i.isFullHeight=h,i.imageQuality=_,i.captionLayout=a,i.captionSource=v,i.altTextSource=y,i.isTransparentBackground=b,i.isCover=S,i.carouselOptions=w;break}case`image-gallery`:{let t=a.find(e=>e.category===`tree`||e.category===`set`);if(!t)throw Error(`Image gallery link not found for the following component: “${n}”`);let r=p(e.properties,`is-searchable`)===`Yes`;i.galleryId=t.uuid,i.isSearchable=r;break}case`n-columns`:{let e=t.resource?await Z(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];i.columns=e;break}case`n-rows`:{let e=t.resource?await Z(Array.isArray(t.resource)?t.resource:[t.resource],`element`):[];i.rows=e;break}case`network-graph`:break;case`table`:{let e=a.find(e=>e.category===`set`);if(!e)throw Error(`Table link not found for the following component: “${n}”`);i.tableId=e.uuid;break}case`search-bar`:{let t=p(e.properties,`variant`);t??=`default`,i.variant=t;break}case`text`:{if(!s)throw Error(`Document not found for the following component: “${n}”`);let t=p(e.properties,`variant`);t??=`block`;let r=p(e.properties,`heading`);i.variant=t,i.heading=r,i.content=s.content;break}case`timeline`:{let e=a.find(e=>e.category===`tree`);if(!e)throw Error(`Timeline link not found for the following component: “${n}”`);i.timelineId=e.uuid;break}case`video`:{let t=a.find(e=>e.type===`video`);if(!t)throw Error(`Video link not found for the following component: “${n}”`);let r=p(e.properties,`chapters-displayed`);r??=`Yes`,i.videoId=t.uuid,i.isChaptersDislayed=r===`Yes`;break}default:console.warn(`Invalid or non-implemented component name “${n}” for the following element: “${C(t.identification.label)}”`);break}return i}
486
486
  /**
487
487
  * Parses raw web element data into a standardized WebElement structure
488
488
  *
@@ -496,7 +496,7 @@ async function Q(e){let t=D(e.identification),n=e.properties?.property?B(Array.i
496
496
  * @param webpageResource - Raw webpage resource data in OCHRE format
497
497
  * @returns Parsed Webpage object
498
498
  */
499
- async function fe(e){let t=e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];if(t.length===0||t.find(e=>e.label===`presentation`)?.values[0]?.content!==`page`)return null;let n=D(e.identification),r=e.slug;if(r===void 0)throw Error(`Slug not found for page “${n.label}”`);let i=e.links?N(Array.isArray(e.links)?e.links:[e.links]):[],a=i.find(e=>e.type===`image`||e.type===`IIIF`),o=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],s=[];for(let e of o){let t=e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=p(t,`presentation`);if(n==null)continue;switch(n){case`element`:{let t=await Q(e);s.push(t);break}case`block`:{let t=await $(e);t&&s.push(t);break}}}let c=e.resource?await le(Array.isArray(e.resource)?e.resource:[e.resource],`page`):[],l=!0,u=`default`,d=`default`,f=!0,m=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`page`)?.properties;if(m){let e=m.find(e=>e.label===`header`)?.values[0];e&&(l=e.content===`Yes`);let t=m.find(e=>e.label===`width`)?.values[0];t&&(u=t.content);let n=m.find(e=>e.label===`variant`)?.values[0];n&&(d=n.content);let r=m.find(e=>e.label===`sidebar-visible`)?.values[0];r&&(f=r.content===`Yes`)}let h=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css`)?.properties,g=[];if(h)for(let e of h)g.push({label:e.label,value:e.values[0].content});let _=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css-mobile`)?.properties,v=[];if(_)for(let e of _)v.push({label:e.label,value:e.values[0].content});return{title:n.label,slug:r,items:s,properties:{displayedInHeader:l,width:u,variant:d,backgroundImageUrl:a?`https://ochre.lib.uchicago.edu/ochre?uuid=${a.uuid}&load`:null,isSidebarDisplayed:f,cssStyles:g,cssStylesMobile:v},webpages:c}}
499
+ async function fe(e){let t=e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[];if(t.length===0||t.find(e=>e.label===`presentation`)?.values[0]?.content!==`page`)return null;let n=D(e.identification),r=e.slug;if(r===void 0)throw Error(`Slug not found for page “${n.label}”`);let i=e.links?N(Array.isArray(e.links)?e.links:[e.links]):[],a=i.find(e=>e.type===`image`||e.type===`IIIF`),o=e.resource?Array.isArray(e.resource)?e.resource:[e.resource]:[],s=[];for(let e of o){let t=e.properties?B(Array.isArray(e.properties.property)?e.properties.property:[e.properties.property]):[],n=p(t,`presentation`);if(n==null)continue;switch(n){case`element`:{let t=await Q(e);s.push(t);break}case`block`:{let t=await $(e);t&&s.push(t);break}}}let c=e.resource?await Z(Array.isArray(e.resource)?e.resource:[e.resource],`page`):[],l=!0,u=`default`,d=`default`,f=!0,m=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`page`)?.properties;if(m){let e=m.find(e=>e.label===`header`)?.values[0];e&&(l=e.content===`Yes`);let t=m.find(e=>e.label===`width`)?.values[0];t&&(u=t.content);let n=m.find(e=>e.label===`variant`)?.values[0];n&&(d=n.content);let r=m.find(e=>e.label===`sidebar-visible`)?.values[0];r&&(f=r.content===`Yes`)}let h=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css`)?.properties,g=[];if(h)for(let e of h)g.push({label:e.label,value:e.values[0].content});let _=t.find(e=>e.label===`presentation`&&e.values[0]?.content===`css-mobile`)?.properties,v=[];if(_)for(let e of _)v.push({label:e.label,value:e.values[0].content});return{title:n.label,slug:r,items:s,properties:{displayedInHeader:l,width:u,variant:d,backgroundImageUrl:a?`https://ochre.lib.uchicago.edu/ochre?uuid=${a.uuid}&load`:null,isSidebarDisplayed:f,cssStyles:g,cssStylesMobile:v},webpages:c}}
500
500
  /**
501
501
  * Parses raw webpage resources into an array of Webpage objects
502
502
  *
@@ -583,4 +583,4 @@ async function _e(e,t,n,r){try{let{uuid:i,filter:a,page:s,perPage:c}=o.parse({uu
583
583
  *
584
584
  * The abbreviation is case-insensitive and should match the website's configured abbreviation in OCHRE.
585
585
  */
586
- async function ve(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?D(n.result.ochre.metadata.project.identification):null,i=await ge(n.result.ochre.tree,r?.label??``,n.result.ochre.metadata.project?.identification.website??null);return i}catch(e){return console.error(e),null}}export{T as fetchByUuid,_e as fetchGallery,E as fetchItem,ve as fetchWebsite,h as filterProperties,d as getPropertyByLabel,p as getPropertyValueByLabel,f as getPropertyValuesByLabel,m as getUniqueProperties,W as parseBibliographies,U as parseBibliography,Z as parseConcept,ue as parseConcepts,k as parseContext,L as parseCoordinates,P as parseDocument,_ as parseEmail,z as parseEvents,b as parseFakeString,D as parseIdentification,F as parseImage,oe as parseImageMap,ae as parseInterpretations,ee as parseLanguages,A as parseLicense,ne as parseLink,N as parseLinks,te as parseMetadata,I as parseNotes,R as parseObservation,re as parseObservations,V as parsePeriod,H as parsePeriods,j as parsePerson,M as parsePersons,B as parseProperties,ie as parseProperty,G as parsePropertyValue,K as parsePropertyValues,q as parseResource,J as parseResources,ce as parseSet,Y as parseSpatialUnit,X as parseSpatialUnits,C as parseStringContent,S as parseStringDocumentItem,x as parseStringItem,se as parseTree,ge as parseWebsite};
586
+ async function ve(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?D(n.result.ochre.metadata.project.identification):null,i=await ge(n.result.ochre.tree,r?.label??``,n.result.ochre.metadata.project?.identification.website??null);return i}catch(e){return console.error(e),null}}export{_e as fetchGallery,E as fetchItem,ve as fetchWebsite,h as filterProperties,d as getPropertyByLabel,p as getPropertyValueByLabel,f as getPropertyValuesByLabel,m as getUniqueProperties};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalculture/ochre-sdk",
3
- "version": "0.7.12",
3
+ "version": "0.7.14",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Node.js library for working with OCHRE (Online Cultural and Historical Research Environment) data",
@@ -44,16 +44,16 @@
44
44
  "zod": "^3.24.4"
45
45
  },
46
46
  "devDependencies": {
47
- "@antfu/eslint-config": "^4.13.0",
47
+ "@antfu/eslint-config": "^4.13.1",
48
48
  "@arethetypeswrong/cli": "^0.18.1",
49
49
  "@changesets/cli": "^2.29.4",
50
50
  "@total-typescript/ts-reset": "^0.6.1",
51
- "@types/node": "^22.15.17",
52
- "eslint": "^9.26.0",
51
+ "@types/node": "^22.15.18",
52
+ "eslint": "^9.27.0",
53
53
  "eslint-plugin-unused-imports": "^4.1.4",
54
54
  "prettier": "^3.5.3",
55
- "terser": "^5.39.1",
56
- "tsdown": "^0.11.9",
55
+ "terser": "^5.39.2",
56
+ "tsdown": "^0.11.10",
57
57
  "typescript": "^5.8.3",
58
58
  "vitest": "^3.1.3"
59
59
  },