@digitalculture/ochre-sdk 0.4.1 → 0.4.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 CHANGED
@@ -198,11 +198,13 @@ function parseWhitespace(contentString, whitespace) {
198
198
  console.warn(`Invalid whitespace string provided: \u201C${whitespace}\u201D`);
199
199
  return contentString;
200
200
  }
201
- for (const option of result.data) {
201
+ for (const [index, option] of result.data.entries()) {
202
202
  switch (option) {
203
203
  case "newline": {
204
- returnString = `${returnString}
205
- <br />`;
204
+ if (index !== 0) {
205
+ returnString = `<br />
206
+ ${returnString}`;
207
+ }
206
208
  break;
207
209
  }
208
210
  case "trailing": {
@@ -589,6 +591,7 @@ var componentSchema = import_zod3.z.enum(
589
591
  "blog",
590
592
  "button",
591
593
  "collection",
594
+ "empty-space",
592
595
  "iiif-viewer",
593
596
  "image",
594
597
  "image-gallery",
@@ -1510,6 +1513,19 @@ async function parseWebElementProperties(componentProperty, elementResource) {
1510
1513
  properties.collectionId = collectionLink.uuid;
1511
1514
  break;
1512
1515
  }
1516
+ case "empty-space": {
1517
+ const height = getPropertyValueByLabel(
1518
+ componentProperty.properties,
1519
+ "height"
1520
+ );
1521
+ const width = getPropertyValueByLabel(
1522
+ componentProperty.properties,
1523
+ "width"
1524
+ );
1525
+ properties.height = height;
1526
+ properties.width = width;
1527
+ break;
1528
+ }
1513
1529
  case "iiif-viewer": {
1514
1530
  const manifestLink = links.find((link) => link.type === "IIIF");
1515
1531
  if (!manifestLink) {
@@ -1890,7 +1906,7 @@ async function parseWebpage(webpageResource) {
1890
1906
  return null;
1891
1907
  }
1892
1908
  const identification = parseIdentification(webpageResource.identification);
1893
- const slug = webpageResource.slug === "/" ? "" : webpageResource.slug;
1909
+ const slug = webpageResource.slug;
1894
1910
  if (slug === void 0) {
1895
1911
  throw new Error(`Slug not found for page \u201C${identification.label}\u201D`);
1896
1912
  }
@@ -1900,16 +1916,55 @@ async function parseWebpage(webpageResource) {
1900
1916
  const imageLink = links.find(
1901
1917
  (link) => link.type === "image" || link.type === "IIIF"
1902
1918
  );
1903
- const blocks = webpageResource.resource ? await parseWebpageResources(
1904
- Array.isArray(webpageResource.resource) ? webpageResource.resource : [webpageResource.resource],
1905
- "block"
1906
- ) : [];
1907
- if (blocks.length === 0) {
1908
- const defaultBlock = {
1919
+ const webpageResources = webpageResource.resource ? Array.isArray(webpageResource.resource) ? webpageResource.resource : [webpageResource.resource] : [];
1920
+ const blocks = [];
1921
+ let elementsToHandle = [];
1922
+ for (const resource of webpageResources) {
1923
+ const resourceProperties = resource.properties ? parseProperties(
1924
+ Array.isArray(resource.properties.property) ? resource.properties.property : [resource.properties.property]
1925
+ ) : [];
1926
+ const resourceType = getPropertyValueByLabel(
1927
+ resourceProperties,
1928
+ "presentation"
1929
+ );
1930
+ if (!resourceType) {
1931
+ continue;
1932
+ }
1933
+ if (resourceType !== "block") {
1934
+ elementsToHandle.push(resource);
1935
+ } else {
1936
+ if (elementsToHandle.length > 0) {
1937
+ const elements = await parseWebpageResources(
1938
+ elementsToHandle,
1939
+ "element"
1940
+ );
1941
+ const block = {
1942
+ uuid: resource.uuid,
1943
+ layout: "vertical",
1944
+ blocks: [],
1945
+ elements,
1946
+ properties: {
1947
+ spacing: "auto",
1948
+ gap: "none",
1949
+ alignItems: "stretch",
1950
+ justifyContent: "stretch"
1951
+ },
1952
+ cssStyles: []
1953
+ };
1954
+ blocks.push(block);
1955
+ elementsToHandle = [];
1956
+ }
1957
+ const parsedBlocks = await parseWebpageResources([resource], "block");
1958
+ blocks.push(...parsedBlocks);
1959
+ }
1960
+ }
1961
+ if (elementsToHandle.length > 0) {
1962
+ const elements = await parseWebpageResources(elementsToHandle, "element");
1963
+ const block = {
1909
1964
  uuid: webpageResource.uuid,
1910
1965
  layout: "vertical",
1911
1966
  blocks: [],
1912
- elements: [],
1967
+ elements,
1913
1968
  properties: {
1914
1969
  spacing: "auto",
1915
1970
  gap: "none",
@@ -1918,14 +1973,7 @@ async function parseWebpage(webpageResource) {
1918
1973
  },
1919
1974
  cssStyles: []
1920
1975
  };
1921
- blocks.push(defaultBlock);
1922
- const elements = webpageResource.resource ? await parseWebpageResources(
1923
- Array.isArray(webpageResource.resource) ? webpageResource.resource : [webpageResource.resource],
1924
- "element"
1925
- ) : [];
1926
- if (elements.length > 0) {
1927
- defaultBlock.elements = elements;
1928
- }
1976
+ blocks.push(block);
1929
1977
  }
1930
1978
  const webpages = webpageResource.resource ? await parseWebpageResources(
1931
1979
  Array.isArray(webpageResource.resource) ? webpageResource.resource : [webpageResource.resource],
package/dist/index.d.cts CHANGED
@@ -499,6 +499,10 @@ type WebElementComponent = {
499
499
  variant: "full" | "highlights";
500
500
  layout: "image-top" | "image-bottom" | "image-start" | "image-end";
501
501
  isSearchable: boolean;
502
+ } | {
503
+ component: "empty-space";
504
+ height: string | null;
505
+ width: string | null;
502
506
  } | {
503
507
  component: "iiif-viewer";
504
508
  IIIFId: string;
package/dist/index.d.ts CHANGED
@@ -499,6 +499,10 @@ type WebElementComponent = {
499
499
  variant: "full" | "highlights";
500
500
  layout: "image-top" | "image-bottom" | "image-start" | "image-end";
501
501
  isSearchable: boolean;
502
+ } | {
503
+ component: "empty-space";
504
+ height: string | null;
505
+ width: string | null;
502
506
  } | {
503
507
  component: "iiif-viewer";
504
508
  IIIFId: string;
package/dist/index.js CHANGED
@@ -120,11 +120,13 @@ function parseWhitespace(contentString, whitespace) {
120
120
  console.warn(`Invalid whitespace string provided: \u201C${whitespace}\u201D`);
121
121
  return contentString;
122
122
  }
123
- for (const option of result.data) {
123
+ for (const [index, option] of result.data.entries()) {
124
124
  switch (option) {
125
125
  case "newline": {
126
- returnString = `${returnString}
127
- <br />`;
126
+ if (index !== 0) {
127
+ returnString = `<br />
128
+ ${returnString}`;
129
+ }
128
130
  break;
129
131
  }
130
132
  case "trailing": {
@@ -511,6 +513,7 @@ var componentSchema = z3.enum(
511
513
  "blog",
512
514
  "button",
513
515
  "collection",
516
+ "empty-space",
514
517
  "iiif-viewer",
515
518
  "image",
516
519
  "image-gallery",
@@ -1432,6 +1435,19 @@ async function parseWebElementProperties(componentProperty, elementResource) {
1432
1435
  properties.collectionId = collectionLink.uuid;
1433
1436
  break;
1434
1437
  }
1438
+ case "empty-space": {
1439
+ const height = getPropertyValueByLabel(
1440
+ componentProperty.properties,
1441
+ "height"
1442
+ );
1443
+ const width = getPropertyValueByLabel(
1444
+ componentProperty.properties,
1445
+ "width"
1446
+ );
1447
+ properties.height = height;
1448
+ properties.width = width;
1449
+ break;
1450
+ }
1435
1451
  case "iiif-viewer": {
1436
1452
  const manifestLink = links.find((link) => link.type === "IIIF");
1437
1453
  if (!manifestLink) {
@@ -1812,7 +1828,7 @@ async function parseWebpage(webpageResource) {
1812
1828
  return null;
1813
1829
  }
1814
1830
  const identification = parseIdentification(webpageResource.identification);
1815
- const slug = webpageResource.slug === "/" ? "" : webpageResource.slug;
1831
+ const slug = webpageResource.slug;
1816
1832
  if (slug === void 0) {
1817
1833
  throw new Error(`Slug not found for page \u201C${identification.label}\u201D`);
1818
1834
  }
@@ -1822,16 +1838,55 @@ async function parseWebpage(webpageResource) {
1822
1838
  const imageLink = links.find(
1823
1839
  (link) => link.type === "image" || link.type === "IIIF"
1824
1840
  );
1825
- const blocks = webpageResource.resource ? await parseWebpageResources(
1826
- Array.isArray(webpageResource.resource) ? webpageResource.resource : [webpageResource.resource],
1827
- "block"
1828
- ) : [];
1829
- if (blocks.length === 0) {
1830
- const defaultBlock = {
1841
+ const webpageResources = webpageResource.resource ? Array.isArray(webpageResource.resource) ? webpageResource.resource : [webpageResource.resource] : [];
1842
+ const blocks = [];
1843
+ let elementsToHandle = [];
1844
+ for (const resource of webpageResources) {
1845
+ const resourceProperties = resource.properties ? parseProperties(
1846
+ Array.isArray(resource.properties.property) ? resource.properties.property : [resource.properties.property]
1847
+ ) : [];
1848
+ const resourceType = getPropertyValueByLabel(
1849
+ resourceProperties,
1850
+ "presentation"
1851
+ );
1852
+ if (!resourceType) {
1853
+ continue;
1854
+ }
1855
+ if (resourceType !== "block") {
1856
+ elementsToHandle.push(resource);
1857
+ } else {
1858
+ if (elementsToHandle.length > 0) {
1859
+ const elements = await parseWebpageResources(
1860
+ elementsToHandle,
1861
+ "element"
1862
+ );
1863
+ const block = {
1864
+ uuid: resource.uuid,
1865
+ layout: "vertical",
1866
+ blocks: [],
1867
+ elements,
1868
+ properties: {
1869
+ spacing: "auto",
1870
+ gap: "none",
1871
+ alignItems: "stretch",
1872
+ justifyContent: "stretch"
1873
+ },
1874
+ cssStyles: []
1875
+ };
1876
+ blocks.push(block);
1877
+ elementsToHandle = [];
1878
+ }
1879
+ const parsedBlocks = await parseWebpageResources([resource], "block");
1880
+ blocks.push(...parsedBlocks);
1881
+ }
1882
+ }
1883
+ if (elementsToHandle.length > 0) {
1884
+ const elements = await parseWebpageResources(elementsToHandle, "element");
1885
+ const block = {
1831
1886
  uuid: webpageResource.uuid,
1832
1887
  layout: "vertical",
1833
1888
  blocks: [],
1834
- elements: [],
1889
+ elements,
1835
1890
  properties: {
1836
1891
  spacing: "auto",
1837
1892
  gap: "none",
@@ -1840,14 +1895,7 @@ async function parseWebpage(webpageResource) {
1840
1895
  },
1841
1896
  cssStyles: []
1842
1897
  };
1843
- blocks.push(defaultBlock);
1844
- const elements = webpageResource.resource ? await parseWebpageResources(
1845
- Array.isArray(webpageResource.resource) ? webpageResource.resource : [webpageResource.resource],
1846
- "element"
1847
- ) : [];
1848
- if (elements.length > 0) {
1849
- defaultBlock.elements = elements;
1850
- }
1898
+ blocks.push(block);
1851
1899
  }
1852
1900
  const webpages = webpageResource.resource ? await parseWebpageResources(
1853
1901
  Array.isArray(webpageResource.resource) ? webpageResource.resource : [webpageResource.resource],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalculture/ochre-sdk",
3
- "version": "0.4.1",
3
+ "version": "0.4.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",
@@ -52,9 +52,9 @@
52
52
  "eslint": "^9.21.0",
53
53
  "eslint-plugin-unused-imports": "^4.1.4",
54
54
  "prettier": "^3.5.2",
55
- "tsup": "^8.3.6",
55
+ "tsup": "^8.4.0",
56
56
  "typescript": "^5.7.3",
57
- "vitest": "^3.0.6"
57
+ "vitest": "^3.0.7"
58
58
  },
59
59
  "scripts": {
60
60
  "dev": "tsup src/index.ts --watch",