@digitalculture/ochre-sdk 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +23 -16
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +23 -16
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -622,6 +622,9 @@ function parseIdentification(identification) {
|
|
|
622
622
|
}
|
|
623
623
|
}
|
|
624
624
|
function parseLanguages(language) {
|
|
625
|
+
if (language == null) {
|
|
626
|
+
return ["eng"];
|
|
627
|
+
}
|
|
625
628
|
if (Array.isArray(language)) {
|
|
626
629
|
return language.map((lang) => parseStringContent(lang));
|
|
627
630
|
} else {
|
|
@@ -1327,7 +1330,7 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1327
1330
|
const links = elementResource.links ? parseLinks(
|
|
1328
1331
|
Array.isArray(elementResource.links) ? elementResource.links : [elementResource.links]
|
|
1329
1332
|
) : [];
|
|
1330
|
-
const
|
|
1333
|
+
const imageLinks = links.filter((link) => link.type === "image");
|
|
1331
1334
|
let document = elementResource.document ? parseDocument(elementResource.document.content) : null;
|
|
1332
1335
|
if (document === null) {
|
|
1333
1336
|
const documentLink = links.find((link) => link.type === "internalDocument");
|
|
@@ -1350,7 +1353,7 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1350
1353
|
break;
|
|
1351
1354
|
}
|
|
1352
1355
|
case "annotated-image": {
|
|
1353
|
-
if (
|
|
1356
|
+
if (imageLinks.length === 0) {
|
|
1354
1357
|
throw new Error(
|
|
1355
1358
|
`Image link not found for the following component: \u201C${componentName}\u201D`
|
|
1356
1359
|
);
|
|
@@ -1359,7 +1362,7 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1359
1362
|
componentProperty.properties,
|
|
1360
1363
|
"is-searchable"
|
|
1361
1364
|
) === "Yes";
|
|
1362
|
-
properties.imageUuid =
|
|
1365
|
+
properties.imageUuid = imageLinks[0].uuid;
|
|
1363
1366
|
properties.isSearchable = isSearchable;
|
|
1364
1367
|
break;
|
|
1365
1368
|
}
|
|
@@ -1458,7 +1461,7 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1458
1461
|
break;
|
|
1459
1462
|
}
|
|
1460
1463
|
case "image": {
|
|
1461
|
-
if (
|
|
1464
|
+
if (imageLinks.length === 0) {
|
|
1462
1465
|
throw new Error(
|
|
1463
1466
|
`Image link not found for the following component: \u201C${componentName}\u201D`
|
|
1464
1467
|
);
|
|
@@ -1491,12 +1494,16 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1491
1494
|
if (altTextSource === null) {
|
|
1492
1495
|
altTextSource = "name";
|
|
1493
1496
|
}
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1497
|
+
const images = [];
|
|
1498
|
+
for (const imageLink of imageLinks) {
|
|
1499
|
+
images.push({
|
|
1500
|
+
url: `https://ochre.lib.uchicago.edu/ochre?uuid=${imageLink.uuid}&load`,
|
|
1501
|
+
label: imageLink.identification?.label ?? null,
|
|
1502
|
+
width: imageLink.image?.width ?? 0,
|
|
1503
|
+
height: imageLink.image?.height ?? 0
|
|
1504
|
+
});
|
|
1505
|
+
}
|
|
1506
|
+
properties.images = images;
|
|
1500
1507
|
properties.imageQuality = imageQuality;
|
|
1501
1508
|
properties.captionLayout = captionLayout;
|
|
1502
1509
|
properties.captionSource = captionSource;
|
|
@@ -1606,10 +1613,10 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1606
1613
|
if (captionLayout === null) {
|
|
1607
1614
|
captionLayout = "bottom";
|
|
1608
1615
|
}
|
|
1609
|
-
const
|
|
1616
|
+
const imageLink = links.find(
|
|
1610
1617
|
(link) => link.type === "image" || link.type === "IIIF"
|
|
1611
1618
|
);
|
|
1612
|
-
if (!
|
|
1619
|
+
if (!imageLink) {
|
|
1613
1620
|
throw new Error(
|
|
1614
1621
|
`Image link not found for the following component: \u201C${componentName}\u201D: ${JSON.stringify(
|
|
1615
1622
|
links
|
|
@@ -1639,10 +1646,10 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1639
1646
|
}
|
|
1640
1647
|
properties.variant = variant;
|
|
1641
1648
|
properties.image = {
|
|
1642
|
-
url: `https://ochre.lib.uchicago.edu/ochre?uuid=${
|
|
1643
|
-
label:
|
|
1644
|
-
width:
|
|
1645
|
-
height:
|
|
1649
|
+
url: `https://ochre.lib.uchicago.edu/ochre?uuid=${imageLink.uuid}&preview`,
|
|
1650
|
+
label: imageLink.identification?.label ?? null,
|
|
1651
|
+
width: imageLink.image?.width ?? 0,
|
|
1652
|
+
height: imageLink.image?.height ?? 0
|
|
1646
1653
|
};
|
|
1647
1654
|
properties.imageQuality = imageQuality;
|
|
1648
1655
|
properties.layout = layout;
|
package/dist/index.d.cts
CHANGED
|
@@ -752,7 +752,7 @@ type OchreMetadata = {
|
|
|
752
752
|
publisher: OchreStringContent;
|
|
753
753
|
dataset: OchreStringContent;
|
|
754
754
|
project?: { identification: OchreIdentification };
|
|
755
|
-
language
|
|
755
|
+
language?: OchreLanguage | Array<OchreLanguage>;
|
|
756
756
|
description: OchreStringContent;
|
|
757
757
|
};
|
|
758
758
|
|
|
@@ -1506,7 +1506,7 @@ declare function parseIdentification(identification: OchreIdentification): Ident
|
|
|
1506
1506
|
* @param language - Raw language data, either single or array
|
|
1507
1507
|
* @returns Array of language codes as strings
|
|
1508
1508
|
*/
|
|
1509
|
-
declare function parseLanguages(language: OchreLanguage | Array<OchreLanguage>): Array<string>;
|
|
1509
|
+
declare function parseLanguages(language: OchreLanguage | Array<OchreLanguage> | undefined): Array<string>;
|
|
1510
1510
|
/**
|
|
1511
1511
|
* Parses raw metadata into the standardized Metadata type
|
|
1512
1512
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -752,7 +752,7 @@ type OchreMetadata = {
|
|
|
752
752
|
publisher: OchreStringContent;
|
|
753
753
|
dataset: OchreStringContent;
|
|
754
754
|
project?: { identification: OchreIdentification };
|
|
755
|
-
language
|
|
755
|
+
language?: OchreLanguage | Array<OchreLanguage>;
|
|
756
756
|
description: OchreStringContent;
|
|
757
757
|
};
|
|
758
758
|
|
|
@@ -1506,7 +1506,7 @@ declare function parseIdentification(identification: OchreIdentification): Ident
|
|
|
1506
1506
|
* @param language - Raw language data, either single or array
|
|
1507
1507
|
* @returns Array of language codes as strings
|
|
1508
1508
|
*/
|
|
1509
|
-
declare function parseLanguages(language: OchreLanguage | Array<OchreLanguage>): Array<string>;
|
|
1509
|
+
declare function parseLanguages(language: OchreLanguage | Array<OchreLanguage> | undefined): Array<string>;
|
|
1510
1510
|
/**
|
|
1511
1511
|
* Parses raw metadata into the standardized Metadata type
|
|
1512
1512
|
*
|
package/dist/index.js
CHANGED
|
@@ -545,6 +545,9 @@ function parseIdentification(identification) {
|
|
|
545
545
|
}
|
|
546
546
|
}
|
|
547
547
|
function parseLanguages(language) {
|
|
548
|
+
if (language == null) {
|
|
549
|
+
return ["eng"];
|
|
550
|
+
}
|
|
548
551
|
if (Array.isArray(language)) {
|
|
549
552
|
return language.map((lang) => parseStringContent(lang));
|
|
550
553
|
} else {
|
|
@@ -1250,7 +1253,7 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1250
1253
|
const links = elementResource.links ? parseLinks(
|
|
1251
1254
|
Array.isArray(elementResource.links) ? elementResource.links : [elementResource.links]
|
|
1252
1255
|
) : [];
|
|
1253
|
-
const
|
|
1256
|
+
const imageLinks = links.filter((link) => link.type === "image");
|
|
1254
1257
|
let document = elementResource.document ? parseDocument(elementResource.document.content) : null;
|
|
1255
1258
|
if (document === null) {
|
|
1256
1259
|
const documentLink = links.find((link) => link.type === "internalDocument");
|
|
@@ -1273,7 +1276,7 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1273
1276
|
break;
|
|
1274
1277
|
}
|
|
1275
1278
|
case "annotated-image": {
|
|
1276
|
-
if (
|
|
1279
|
+
if (imageLinks.length === 0) {
|
|
1277
1280
|
throw new Error(
|
|
1278
1281
|
`Image link not found for the following component: \u201C${componentName}\u201D`
|
|
1279
1282
|
);
|
|
@@ -1282,7 +1285,7 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1282
1285
|
componentProperty.properties,
|
|
1283
1286
|
"is-searchable"
|
|
1284
1287
|
) === "Yes";
|
|
1285
|
-
properties.imageUuid =
|
|
1288
|
+
properties.imageUuid = imageLinks[0].uuid;
|
|
1286
1289
|
properties.isSearchable = isSearchable;
|
|
1287
1290
|
break;
|
|
1288
1291
|
}
|
|
@@ -1381,7 +1384,7 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1381
1384
|
break;
|
|
1382
1385
|
}
|
|
1383
1386
|
case "image": {
|
|
1384
|
-
if (
|
|
1387
|
+
if (imageLinks.length === 0) {
|
|
1385
1388
|
throw new Error(
|
|
1386
1389
|
`Image link not found for the following component: \u201C${componentName}\u201D`
|
|
1387
1390
|
);
|
|
@@ -1414,12 +1417,16 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1414
1417
|
if (altTextSource === null) {
|
|
1415
1418
|
altTextSource = "name";
|
|
1416
1419
|
}
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1420
|
+
const images = [];
|
|
1421
|
+
for (const imageLink of imageLinks) {
|
|
1422
|
+
images.push({
|
|
1423
|
+
url: `https://ochre.lib.uchicago.edu/ochre?uuid=${imageLink.uuid}&load`,
|
|
1424
|
+
label: imageLink.identification?.label ?? null,
|
|
1425
|
+
width: imageLink.image?.width ?? 0,
|
|
1426
|
+
height: imageLink.image?.height ?? 0
|
|
1427
|
+
});
|
|
1428
|
+
}
|
|
1429
|
+
properties.images = images;
|
|
1423
1430
|
properties.imageQuality = imageQuality;
|
|
1424
1431
|
properties.captionLayout = captionLayout;
|
|
1425
1432
|
properties.captionSource = captionSource;
|
|
@@ -1529,10 +1536,10 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1529
1536
|
if (captionLayout === null) {
|
|
1530
1537
|
captionLayout = "bottom";
|
|
1531
1538
|
}
|
|
1532
|
-
const
|
|
1539
|
+
const imageLink = links.find(
|
|
1533
1540
|
(link) => link.type === "image" || link.type === "IIIF"
|
|
1534
1541
|
);
|
|
1535
|
-
if (!
|
|
1542
|
+
if (!imageLink) {
|
|
1536
1543
|
throw new Error(
|
|
1537
1544
|
`Image link not found for the following component: \u201C${componentName}\u201D: ${JSON.stringify(
|
|
1538
1545
|
links
|
|
@@ -1562,10 +1569,10 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1562
1569
|
}
|
|
1563
1570
|
properties.variant = variant;
|
|
1564
1571
|
properties.image = {
|
|
1565
|
-
url: `https://ochre.lib.uchicago.edu/ochre?uuid=${
|
|
1566
|
-
label:
|
|
1567
|
-
width:
|
|
1568
|
-
height:
|
|
1572
|
+
url: `https://ochre.lib.uchicago.edu/ochre?uuid=${imageLink.uuid}&preview`,
|
|
1573
|
+
label: imageLink.identification?.label ?? null,
|
|
1574
|
+
width: imageLink.image?.width ?? 0,
|
|
1575
|
+
height: imageLink.image?.height ?? 0
|
|
1569
1576
|
};
|
|
1570
1577
|
properties.imageQuality = imageQuality;
|
|
1571
1578
|
properties.layout = layout;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitalculture/ochre-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
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.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@antfu/eslint-config": "^4.1.
|
|
47
|
+
"@antfu/eslint-config": "^4.1.1",
|
|
48
48
|
"@arethetypeswrong/cli": "^0.17.3",
|
|
49
49
|
"@changesets/cli": "^2.27.12",
|
|
50
50
|
"@total-typescript/ts-reset": "^0.6.1",
|
|
51
|
-
"@types/node": "^22.
|
|
51
|
+
"@types/node": "^22.13.1",
|
|
52
52
|
"eslint-plugin-unused-imports": "^4.1.4",
|
|
53
53
|
"prettier": "^3.4.2",
|
|
54
54
|
"tsup": "^8.3.6",
|
|
55
55
|
"typescript": "^5.7.3",
|
|
56
|
-
"vitest": "^3.0.
|
|
56
|
+
"vitest": "^3.0.5"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"dev": "tsup src/index.ts --watch",
|