ochre-sdk 1.0.76 → 1.0.78
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/constants.d.mts +13 -14
- package/dist/fetchers/gallery.d.mts +2 -3
- package/dist/fetchers/gallery.mjs +2 -1
- package/dist/fetchers/item-children.d.mts +3 -4
- package/dist/fetchers/item-children.mjs +2 -1
- package/dist/fetchers/item-links.d.mts +2 -3
- package/dist/fetchers/item-links.mjs +2 -1
- package/dist/fetchers/item-ocr-data.d.mts +2 -3
- package/dist/fetchers/item.d.mts +7 -8
- package/dist/fetchers/item.mjs +2 -1
- package/dist/fetchers/set/items.d.mts +2 -3
- package/dist/fetchers/set/items.mjs +2 -1
- package/dist/fetchers/set/property-values.d.mts +2 -3
- package/dist/fetchers/set/property-values.mjs +56 -49
- package/dist/fetchers/website-metadata.d.mts +2 -3
- package/dist/fetchers/website.d.mts +2 -3
- package/dist/getters.d.mts +40 -41
- package/dist/getters.mjs +6 -31
- package/dist/helpers.d.mts +3 -4
- package/dist/parsers/helpers.d.mts +16 -17
- package/dist/parsers/index.d.mts +19 -19
- package/dist/parsers/index.mjs +65 -48
- package/dist/parsers/mdx.d.mts +3 -4
- package/dist/parsers/multilingual.d.mts +9 -10
- package/dist/parsers/string.d.mts +5 -6
- package/dist/parsers/string.mjs +124 -146
- package/dist/parsers/website/index.d.mts +4 -5
- package/dist/parsers/website/index.mjs +598 -637
- package/dist/parsers/website/reader.d.mts +3 -4
- package/dist/query.d.mts +3 -4
- package/dist/schemas.d.mts +9 -10
- package/dist/types/index.d.mts +118 -119
- package/dist/types/website.d.mts +36 -38
- package/dist/utilities.d.mts +9 -10
- package/dist/utilities.mjs +28 -25
- package/dist/xml/dates.d.mts +13 -0
- package/dist/xml/dates.mjs +49 -0
- package/dist/xml/metadata.d.mts +3 -4
- package/dist/xml/schemas.d.mts +8 -9
- package/dist/xml/schemas.mjs +20 -27
- package/dist/xml/types.d.mts +129 -131
- package/package.json +13 -12
|
@@ -3,29 +3,29 @@
|
|
|
3
3
|
* One text entry for a language. When OCHRE exposes multiple entries for the
|
|
4
4
|
* same language, the first one is primary.
|
|
5
5
|
*/
|
|
6
|
-
type MultilingualStringEntry = {
|
|
6
|
+
export type MultilingualStringEntry = {
|
|
7
7
|
text: string;
|
|
8
8
|
richText: string;
|
|
9
9
|
isPrimary: boolean;
|
|
10
10
|
};
|
|
11
|
-
type MultilingualStringText = {
|
|
11
|
+
export type MultilingualStringText = {
|
|
12
12
|
text: string;
|
|
13
13
|
richText: string;
|
|
14
14
|
};
|
|
15
|
-
type MultilingualStringInput = string | {
|
|
15
|
+
export type MultilingualStringInput = string | {
|
|
16
16
|
text: string;
|
|
17
17
|
richText?: string;
|
|
18
18
|
};
|
|
19
|
-
type MultilingualStringJSON<T extends ReadonlyArray<string> = ReadonlyArray<string>> = {
|
|
19
|
+
export type MultilingualStringJSON<T extends ReadonlyArray<string> = ReadonlyArray<string>> = {
|
|
20
20
|
content: Partial<Record<T[number], Array<MultilingualStringEntry>>>;
|
|
21
21
|
aliases: Array<string>;
|
|
22
22
|
};
|
|
23
|
-
type MultilingualStringObject<T extends ReadonlyArray<string> = ReadonlyArray<string>> = Partial<Record<T[number], MultilingualStringInput>>;
|
|
24
|
-
type MultilingualStringEntries<T extends ReadonlyArray<string> = ReadonlyArray<string>> = Partial<Record<T[number], ReadonlyArray<MultilingualStringInput>>>;
|
|
23
|
+
export type MultilingualStringObject<T extends ReadonlyArray<string> = ReadonlyArray<string>> = Partial<Record<T[number], MultilingualStringInput>>;
|
|
24
|
+
export type MultilingualStringEntries<T extends ReadonlyArray<string> = ReadonlyArray<string>> = Partial<Record<T[number], ReadonlyArray<MultilingualStringInput>>>;
|
|
25
25
|
/**
|
|
26
26
|
* Options for creating and working with multilingual strings
|
|
27
27
|
*/
|
|
28
|
-
type MultilingualOptions = {
|
|
28
|
+
export type MultilingualOptions = {
|
|
29
29
|
/**
|
|
30
30
|
Default language to use for fallbacks
|
|
31
31
|
*/
|
|
@@ -50,7 +50,7 @@ type MultilingualStringInternalInit<T extends ReadonlyArray<string>> = {
|
|
|
50
50
|
/**
|
|
51
51
|
* Multilingual string
|
|
52
52
|
*/
|
|
53
|
-
declare class MultilingualString<T extends ReadonlyArray<string> = ReadonlyArray<string>> {
|
|
53
|
+
export declare class MultilingualString<T extends ReadonlyArray<string> = ReadonlyArray<string>> {
|
|
54
54
|
private static fromNormalized;
|
|
55
55
|
/**
|
|
56
56
|
* Create a new multilingual string from an object of language codes to text
|
|
@@ -196,5 +196,4 @@ declare class MultilingualString<T extends ReadonlyArray<string> = ReadonlyArray
|
|
|
196
196
|
*/
|
|
197
197
|
toJSON(): MultilingualStringJSON<T>;
|
|
198
198
|
}
|
|
199
|
-
//#endregion
|
|
200
|
-
export { MultilingualOptions, MultilingualString, MultilingualStringEntries, MultilingualStringEntry, MultilingualStringInput, MultilingualStringJSON, MultilingualStringObject, MultilingualStringText };
|
|
199
|
+
//#endregion
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { MultilingualString, MultilingualStringText } from "./multilingual.mjs";
|
|
2
2
|
import { XMLContent, XMLString } from "../xml/types.mjs";
|
|
3
3
|
//#region src/parsers/string.d.ts
|
|
4
|
-
declare function transformPermanentIdentificationUrl(url: string): string;
|
|
5
|
-
declare function parseXMLString(string: XMLString): MultilingualStringText;
|
|
4
|
+
export declare function transformPermanentIdentificationUrl(url: string): string;
|
|
5
|
+
export declare function parseXMLString(string: XMLString): MultilingualStringText;
|
|
6
6
|
/**
|
|
7
7
|
* Parses rich text content into a formatted string with links and annotations
|
|
8
8
|
*
|
|
@@ -13,7 +13,7 @@ declare function parseXMLString(string: XMLString): MultilingualStringText;
|
|
|
13
13
|
*
|
|
14
14
|
* @internal
|
|
15
15
|
*/
|
|
16
|
-
declare function parseXMLContent<V extends ReadonlyArray<string>>(item: XMLContent, options: {
|
|
16
|
+
export declare function parseXMLContent<V extends ReadonlyArray<string>>(item: XMLContent, options: {
|
|
17
17
|
languages: V;
|
|
18
18
|
}): MultilingualString<V>;
|
|
19
19
|
/**
|
|
@@ -23,6 +23,5 @@ declare function parseXMLContent<V extends ReadonlyArray<string>>(item: XMLConte
|
|
|
23
23
|
*
|
|
24
24
|
* @internal
|
|
25
25
|
*/
|
|
26
|
-
declare function extractAliases(content: XMLContent | undefined): Array<string> | null;
|
|
27
|
-
//#endregion
|
|
28
|
-
export { extractAliases, parseXMLContent, parseXMLString, transformPermanentIdentificationUrl };
|
|
26
|
+
export declare function extractAliases(content: XMLContent | undefined): Array<string> | null;
|
|
27
|
+
//#endregion
|
package/dist/parsers/string.mjs
CHANGED
|
@@ -114,28 +114,24 @@ function parseXMLString(string) {
|
|
|
114
114
|
*/
|
|
115
115
|
function createMDXComponent(variant, properties) {
|
|
116
116
|
const { uuid, href, height, width, content, text } = properties;
|
|
117
|
-
const tooltipContent = getDistinctTooltipContent(content, text);
|
|
118
117
|
let returnString = "";
|
|
119
118
|
switch (variant) {
|
|
120
119
|
case "inlineImage":
|
|
121
120
|
returnString = `<InlineImage${createMDXStringAttribute("uuid", uuid ?? "null")}${createMDXStringAttribute("content", content)} height={${height ?? "null"}} width={${width ?? "null"}} />`;
|
|
122
121
|
break;
|
|
123
122
|
case "internalLink":
|
|
124
|
-
returnString = `<InternalLink${createMDXStringAttribute("uuid", uuid ?? "null")}
|
|
123
|
+
returnString = `<InternalLink${createMDXStringAttribute("uuid", uuid ?? "null")}>${text}</InternalLink>`;
|
|
125
124
|
break;
|
|
126
125
|
case "externalLink":
|
|
127
|
-
returnString = `<ExternalLink${createMDXStringAttribute("href", href == null ? "#" : transformPermanentIdentificationUrl(href))}
|
|
126
|
+
returnString = `<ExternalLink${createMDXStringAttribute("href", href == null ? "#" : transformPermanentIdentificationUrl(href))}>${text}</ExternalLink>`;
|
|
128
127
|
break;
|
|
129
128
|
case "documentLink":
|
|
130
|
-
returnString = `<ExternalLink${createMDXStringAttribute("href", `https://ochre.lib.uchicago.edu/ochre/v2/ochre.php?uuid=${uuid}&load`)}
|
|
129
|
+
returnString = `<ExternalLink${createMDXStringAttribute("href", `https://ochre.lib.uchicago.edu/ochre/v2/ochre.php?uuid=${uuid}&load`)}>${text}</ExternalLink>`;
|
|
131
130
|
break;
|
|
132
131
|
case "tooltipSpan": returnString = `<TooltipSpan${createMDXStringAttribute("content", content)}>${text}</TooltipSpan>`;
|
|
133
132
|
}
|
|
134
133
|
return returnString;
|
|
135
134
|
}
|
|
136
|
-
function getDistinctTooltipContent(content, textContent) {
|
|
137
|
-
return content === textContent ? void 0 : content;
|
|
138
|
-
}
|
|
139
135
|
function createMDXStringAttribute(name, value) {
|
|
140
136
|
if (value === "" || value == null) return "";
|
|
141
137
|
return ` ${name}=${MDX_QUOTED_ATTRIBUTE_ESCAPE_REGEX.test(value) ? `{${JSON.stringify(value)}}` : `"${value}"`}`;
|
|
@@ -182,6 +178,40 @@ function hasMatchingPropertyValue(property, uuid, tokens, options) {
|
|
|
182
178
|
const value = normalizePropertyToken(parsePropertyValueText(property, options));
|
|
183
179
|
return tokens.includes(value);
|
|
184
180
|
}
|
|
181
|
+
function parseTextStylingSize(textStylingProperty, options) {
|
|
182
|
+
let size = null;
|
|
183
|
+
const nestedProperties = textStylingProperty.property ?? [];
|
|
184
|
+
for (const nestedProperty of nestedProperties) if (hasMatchingPropertyLabel(nestedProperty, "", ["size"], options)) size = parsePropertyValueText(nestedProperty, options);
|
|
185
|
+
return size;
|
|
186
|
+
}
|
|
187
|
+
function parseTextStyling(textAnnotationProperty, options) {
|
|
188
|
+
let variant = "block";
|
|
189
|
+
let size = "md";
|
|
190
|
+
let headingLevel = null;
|
|
191
|
+
const cssStyles = [];
|
|
192
|
+
const textStylingProperties = textAnnotationProperty.property ?? [];
|
|
193
|
+
for (const textStylingProperty of textStylingProperties) {
|
|
194
|
+
if (hasMatchingPropertyLabel(textStylingProperty, "e1647bef-d801-4100-bdde-d081c422f763", [VARIANT_TOKEN], options)) {
|
|
195
|
+
variant = parsePropertyValueText(textStylingProperty, options);
|
|
196
|
+
size = parseTextStylingSize(textStylingProperty, options) ?? size;
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (hasMatchingPropertyLabel(textStylingProperty, "d4266f0b-3f8d-4b32-8c15-4b229c8bb11e", [HEADING_LEVEL_TOKEN], options)) {
|
|
200
|
+
headingLevel = parsePropertyValueText(textStylingProperty, options);
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
cssStyles.push({
|
|
204
|
+
label: parseContentLikeForLanguage(textStylingProperty.label, options),
|
|
205
|
+
value: parsePropertyValueText(textStylingProperty, options)
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
variant,
|
|
210
|
+
size,
|
|
211
|
+
headingLevel,
|
|
212
|
+
cssStyles
|
|
213
|
+
};
|
|
214
|
+
}
|
|
185
215
|
function extractAnnotationMetadata(item, options) {
|
|
186
216
|
const result = {
|
|
187
217
|
linkVariant: null,
|
|
@@ -204,50 +234,23 @@ function extractAnnotationMetadata(item, options) {
|
|
|
204
234
|
result.linkVariant = "entry-page";
|
|
205
235
|
continue;
|
|
206
236
|
}
|
|
207
|
-
if (hasMatchingPropertyValue(textAnnotationProperty, "3e6f86ab-df81-45ae-8257-e2867357df56", [TEXT_STYLING_TOKEN], options))
|
|
208
|
-
let variant = "block";
|
|
209
|
-
let size = "md";
|
|
210
|
-
let headingLevel = null;
|
|
211
|
-
const cssStyles = [];
|
|
212
|
-
const textStylingProperties = textAnnotationProperty.property ?? [];
|
|
213
|
-
for (const textStylingProperty of textStylingProperties) {
|
|
214
|
-
if (hasMatchingPropertyLabel(textStylingProperty, "e1647bef-d801-4100-bdde-d081c422f763", [VARIANT_TOKEN], options)) {
|
|
215
|
-
variant = parsePropertyValueText(textStylingProperty, options);
|
|
216
|
-
const nestedProperties = textStylingProperty.property ?? [];
|
|
217
|
-
for (const nestedProperty of nestedProperties) if (hasMatchingPropertyLabel(nestedProperty, "", ["size"], options)) size = parsePropertyValueText(nestedProperty, options);
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
if (hasMatchingPropertyLabel(textStylingProperty, "d4266f0b-3f8d-4b32-8c15-4b229c8bb11e", [HEADING_LEVEL_TOKEN], options)) {
|
|
221
|
-
headingLevel = parsePropertyValueText(textStylingProperty, options);
|
|
222
|
-
continue;
|
|
223
|
-
}
|
|
224
|
-
cssStyles.push({
|
|
225
|
-
label: parseContentLikeForLanguage(textStylingProperty.label, options),
|
|
226
|
-
value: parsePropertyValueText(textStylingProperty, options)
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
result.textStyling = {
|
|
230
|
-
variant,
|
|
231
|
-
size,
|
|
232
|
-
headingLevel,
|
|
233
|
-
cssStyles
|
|
234
|
-
};
|
|
235
|
-
}
|
|
237
|
+
if (hasMatchingPropertyValue(textAnnotationProperty, "3e6f86ab-df81-45ae-8257-e2867357df56", [TEXT_STYLING_TOKEN], options)) result.textStyling = parseTextStyling(textAnnotationProperty, options);
|
|
236
238
|
}
|
|
237
239
|
return result;
|
|
238
240
|
}
|
|
239
241
|
function hasRichTextEnvelope(item) {
|
|
240
242
|
return item.properties?.property[0] != null || getXMLRichTextLinks(item).length > 0;
|
|
241
243
|
}
|
|
244
|
+
function parseWhitespaceOnlyItem(item, options) {
|
|
245
|
+
const hasNewlineWhitespace = item.whitespace?.split(" ").includes("newline") === true;
|
|
246
|
+
const isNextContainingNewlineWhitespace = options.nextItem?.whitespace?.split(" ").includes("newline") === true;
|
|
247
|
+
if (hasNewlineWhitespace && options.rendering === "plain") return isNextContainingNewlineWhitespace ? "\n" : "\n\n";
|
|
248
|
+
if (hasNewlineWhitespace && options.rendering === "rawMDX") return isNextContainingNewlineWhitespace ? "\n<br />" : "\n<br />\n";
|
|
249
|
+
if (hasNewlineWhitespace && options.rendering === "rich") return isNextContainingNewlineWhitespace ? "<br />\n" : "<br />\n<br />\n";
|
|
250
|
+
return applyNewlineWhitespace("", item.whitespace, options.rendering);
|
|
251
|
+
}
|
|
242
252
|
function parseXMLStringItem(item, contentItem, options) {
|
|
243
|
-
if (!(item.payload != null && item.payload !== "" || item.string != null) && getXMLRichTextLinks(item).length === 0)
|
|
244
|
-
const hasNewlineWhitespace = item.whitespace?.split(" ").includes("newline") === true;
|
|
245
|
-
const isNextContainingNewlineWhitespace = options.nextItem?.whitespace?.split(" ").includes("newline") === true;
|
|
246
|
-
if (hasNewlineWhitespace && options.rendering === "plain") return isNextContainingNewlineWhitespace ? "\n" : "\n\n";
|
|
247
|
-
if (hasNewlineWhitespace && options.rendering === "rawMDX") return isNextContainingNewlineWhitespace ? "\n<br />" : "\n<br />\n";
|
|
248
|
-
if (hasNewlineWhitespace && options.rendering === "rich") return isNextContainingNewlineWhitespace ? "<br />\n" : "<br />\n<br />\n";
|
|
249
|
-
return applyNewlineWhitespace("", item.whitespace, options.rendering);
|
|
250
|
-
}
|
|
253
|
+
if (!(item.payload != null && item.payload !== "" || item.string != null) && getXMLRichTextLinks(item).length === 0) return parseWhitespaceOnlyItem(item, options);
|
|
251
254
|
if (hasRichTextEnvelope(item)) {
|
|
252
255
|
let linkString = item.payload != null ? parseXMLStringPayload(item, { rendering: options.rendering }) : parseNestedStringItems(item.string ?? [], contentItem, { ...options });
|
|
253
256
|
if (item.rend != null) linkString = parseRenderOptions(linkString, item.rend, options.rendering);
|
|
@@ -259,30 +262,44 @@ function parseXMLStringItem(item, contentItem, options) {
|
|
|
259
262
|
if (item.rend != null) result = parseRenderOptions(result, item.rend, options.rendering);
|
|
260
263
|
return applyNewlineWhitespace(result, item.whitespace, options.rendering);
|
|
261
264
|
}
|
|
265
|
+
function isRawMDXBlockDelimiter(item) {
|
|
266
|
+
return item.payload === RAW_MDX_BLOCK_DELIMITER && item.rend == null && item.links == null && item.properties == null && item.annotation == null && item.string == null;
|
|
267
|
+
}
|
|
268
|
+
function parseRawMDXBlock(items, contentItem, options, startIndex, endIndex) {
|
|
269
|
+
const rendering = options.rendering === "plain" ? "plain" : "rawMDX";
|
|
270
|
+
let rawMDXBlock = "";
|
|
271
|
+
for (let index = startIndex; index < endIndex; index += 1) {
|
|
272
|
+
const item = items[index];
|
|
273
|
+
if (item != null) rawMDXBlock += parseXMLStringItem(item, contentItem, {
|
|
274
|
+
languages: options.languages,
|
|
275
|
+
rendering,
|
|
276
|
+
rawMDXBlocks: options.rawMDXBlocks,
|
|
277
|
+
nextItem: index + 1 < endIndex ? items[index + 1] : void 0
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
return rawMDXBlock;
|
|
281
|
+
}
|
|
282
|
+
function parseUnterminatedRawMDXItems(items, contentItem, options, startIndex) {
|
|
283
|
+
let result = "";
|
|
284
|
+
for (let index = startIndex; index < items.length; index += 1) {
|
|
285
|
+
const item = items[index];
|
|
286
|
+
if (item != null) result += parseXMLStringItem(item, contentItem, options);
|
|
287
|
+
}
|
|
288
|
+
return result;
|
|
289
|
+
}
|
|
262
290
|
function parseNestedStringItems(items, contentItem, options) {
|
|
263
291
|
let result = "";
|
|
264
292
|
let rawMDXBlockStartIndex = null;
|
|
265
293
|
for (const [index, item] of items.entries()) {
|
|
266
|
-
if (item
|
|
294
|
+
if (isRawMDXBlockDelimiter(item)) {
|
|
267
295
|
if (rawMDXBlockStartIndex == null) {
|
|
268
296
|
rawMDXBlockStartIndex = index;
|
|
269
297
|
continue;
|
|
270
298
|
}
|
|
271
|
-
|
|
272
|
-
const rawMDXBlockRendering = options.rendering === "plain" ? "plain" : "rawMDX";
|
|
273
|
-
for (let rawIndex = rawMDXBlockStartIndex + 1; rawIndex < index; rawIndex += 1) {
|
|
274
|
-
const rawItem = items[rawIndex];
|
|
275
|
-
if (rawItem != null) rawMDXBlock += parseXMLStringItem(rawItem, contentItem, {
|
|
276
|
-
languages: options.languages,
|
|
277
|
-
rendering: rawMDXBlockRendering,
|
|
278
|
-
rawMDXBlocks: options.rawMDXBlocks,
|
|
279
|
-
nextItem: rawIndex + 1 < index ? items[rawIndex + 1] : void 0
|
|
280
|
-
});
|
|
281
|
-
}
|
|
299
|
+
const rawMDXBlock = parseRawMDXBlock(items, contentItem, options, rawMDXBlockStartIndex + 1, index);
|
|
282
300
|
if (options.rendering === "rich" && options.rawMDXBlocks != null) {
|
|
283
|
-
|
|
301
|
+
result += `${RAW_MDX_BLOCK_PLACEHOLDER_PREFIX}${options.rawMDXBlocks.length}${RAW_MDX_BLOCK_PLACEHOLDER_SUFFIX}`;
|
|
284
302
|
options.rawMDXBlocks.push(rawMDXBlock);
|
|
285
|
-
result += placeholder;
|
|
286
303
|
} else result += rawMDXBlock;
|
|
287
304
|
rawMDXBlockStartIndex = null;
|
|
288
305
|
continue;
|
|
@@ -293,10 +310,7 @@ function parseNestedStringItems(items, contentItem, options) {
|
|
|
293
310
|
nextItem: items[index + 1]
|
|
294
311
|
});
|
|
295
312
|
}
|
|
296
|
-
if (rawMDXBlockStartIndex != null)
|
|
297
|
-
const item = items[index];
|
|
298
|
-
if (item != null) result += parseXMLStringItem(item, contentItem, options);
|
|
299
|
-
}
|
|
313
|
+
if (rawMDXBlockStartIndex != null) result += parseUnterminatedRawMDXItems(items, contentItem, options, rawMDXBlockStartIndex);
|
|
300
314
|
return result;
|
|
301
315
|
}
|
|
302
316
|
function isTextAnnotationMarkerLink(link) {
|
|
@@ -312,7 +326,7 @@ function createInternalLinkComponent(properties) {
|
|
|
312
326
|
case "hover-card": return `<Annotation type="hover-card"${createMDXStringAttribute("uuid", properties.uuid ?? "null")}>${innerContent}</Annotation>`;
|
|
313
327
|
case "item-page": return `<InternalLink type="item"${createMDXStringAttribute("uuid", properties.uuid ?? "null")}>${innerContent}</InternalLink>`;
|
|
314
328
|
case "entry-page": return `<InternalLink type="entry"${createMDXStringAttribute("uuid", properties.uuid ?? "null")}>${innerContent}</InternalLink>`;
|
|
315
|
-
default: return `<InternalLink${createMDXStringAttribute("uuid", properties.uuid ?? "null")}${properties.propertyMetadata != null ? `${createMDXStringAttribute("properties", properties.propertyMetadata.labelUuid)}${createMDXStringAttribute("value", properties.propertyMetadata.valueUuid ?? void 0)}` : ""}
|
|
329
|
+
default: return `<InternalLink${createMDXStringAttribute("uuid", properties.uuid ?? "null")}${properties.propertyMetadata != null ? `${createMDXStringAttribute("properties", properties.propertyMetadata.labelUuid)}${createMDXStringAttribute("value", properties.propertyMetadata.valueUuid ?? void 0)}` : ""}>${innerContent}</InternalLink>`;
|
|
316
330
|
}
|
|
317
331
|
}
|
|
318
332
|
function getXMLRichTextLinks(item) {
|
|
@@ -340,6 +354,52 @@ function getXMLRichTextLinks(item) {
|
|
|
340
354
|
for (const { link } of links) sortedLinks.push(link);
|
|
341
355
|
return sortedLinks;
|
|
342
356
|
}
|
|
357
|
+
function renderLinkOrTooltip(link, linkString, contentText, annotationMetadata) {
|
|
358
|
+
return link.publicationDateTime != null ? createInternalLinkComponent({
|
|
359
|
+
uuid: getLinkStringProperty(link, "uuid"),
|
|
360
|
+
text: linkString,
|
|
361
|
+
annotationMetadata
|
|
362
|
+
}) : createMDXComponent("tooltipSpan", {
|
|
363
|
+
uuid: getLinkStringProperty(link, "uuid"),
|
|
364
|
+
text: linkString,
|
|
365
|
+
content: contentText
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
function renderImageLink(link, linkString, contentText, annotationMetadata) {
|
|
369
|
+
if ("rend" in link && link.rend === "inline") return createMDXComponent("inlineImage", {
|
|
370
|
+
uuid: getLinkStringProperty(link, "uuid"),
|
|
371
|
+
href: getLinkStringProperty(link, "href") ?? void 0,
|
|
372
|
+
height: getLinkStringProperty(link, "height") ?? void 0,
|
|
373
|
+
width: getLinkStringProperty(link, "width") ?? void 0,
|
|
374
|
+
content: contentText,
|
|
375
|
+
text: linkString
|
|
376
|
+
});
|
|
377
|
+
return renderLinkOrTooltip(link, linkString, contentText, annotationMetadata);
|
|
378
|
+
}
|
|
379
|
+
function renderRichTextLink(item, link, linkString, contentText, annotationMetadata) {
|
|
380
|
+
if (!("type" in link) || link.type == null) return renderLinkOrTooltip(link, linkString, contentText, annotationMetadata);
|
|
381
|
+
switch (link.type) {
|
|
382
|
+
case "IIIF":
|
|
383
|
+
case "image": return renderImageLink(link, linkString, contentText, annotationMetadata);
|
|
384
|
+
case "internalDocument": return createInternalLinkComponent({
|
|
385
|
+
uuid: getLinkStringProperty(link, "uuid"),
|
|
386
|
+
text: linkString,
|
|
387
|
+
annotationMetadata,
|
|
388
|
+
propertyMetadata: getFirstPropertyMetadata(item)
|
|
389
|
+
});
|
|
390
|
+
case "externalDocument": return createMDXComponent(link.publicationDateTime != null ? "documentLink" : "tooltipSpan", {
|
|
391
|
+
uuid: getLinkStringProperty(link, "uuid"),
|
|
392
|
+
text: linkString,
|
|
393
|
+
content: contentText
|
|
394
|
+
});
|
|
395
|
+
case "webpage": return createMDXComponent("externalLink", {
|
|
396
|
+
uuid: getLinkStringProperty(link, "uuid"),
|
|
397
|
+
href: getLinkStringProperty(link, "href") ?? "#",
|
|
398
|
+
text: linkString
|
|
399
|
+
});
|
|
400
|
+
default: return renderLinkOrTooltip(link, linkString, contentText, annotationMetadata);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
343
403
|
function renderRichTextItem(item, linkString, contentItem, options) {
|
|
344
404
|
const { languages, rendering } = options;
|
|
345
405
|
const annotationMetadata = extractAnnotationMetadata(item, { language: contentItem.lang });
|
|
@@ -349,89 +409,7 @@ function renderRichTextItem(item, linkString, contentItem, options) {
|
|
|
349
409
|
for (const link of links) {
|
|
350
410
|
const linkContent = link.identification != null ? "content" in link.identification.label ? parseXMLContent(link.identification.label, { languages }) : MultilingualString.create(contentItem.lang, parseXMLString(link.identification.label), languages) : MultilingualString.create(contentItem.lang, "", languages);
|
|
351
411
|
const contentText = (rendering === "plain" ? linkContent.getExactText(contentItem.lang) : linkContent.getExactRichText(contentItem.lang)) ?? "";
|
|
352
|
-
|
|
353
|
-
case "IIIF":
|
|
354
|
-
case "image": {
|
|
355
|
-
let component;
|
|
356
|
-
if ("rend" in link && link.rend === "inline") component = createMDXComponent("inlineImage", {
|
|
357
|
-
uuid: getLinkStringProperty(link, "uuid"),
|
|
358
|
-
href: getLinkStringProperty(link, "href") ?? void 0,
|
|
359
|
-
height: getLinkStringProperty(link, "height") ?? void 0,
|
|
360
|
-
width: getLinkStringProperty(link, "width") ?? void 0,
|
|
361
|
-
content: contentText,
|
|
362
|
-
text: linkString
|
|
363
|
-
});
|
|
364
|
-
else if (link.publicationDateTime != null) component = createInternalLinkComponent({
|
|
365
|
-
uuid: getLinkStringProperty(link, "uuid"),
|
|
366
|
-
text: linkString,
|
|
367
|
-
content: contentText,
|
|
368
|
-
annotationMetadata
|
|
369
|
-
});
|
|
370
|
-
else component = createMDXComponent("tooltipSpan", {
|
|
371
|
-
uuid: getLinkStringProperty(link, "uuid"),
|
|
372
|
-
text: linkString,
|
|
373
|
-
content: contentText
|
|
374
|
-
});
|
|
375
|
-
result += component;
|
|
376
|
-
break;
|
|
377
|
-
}
|
|
378
|
-
case "internalDocument": {
|
|
379
|
-
const component = createInternalLinkComponent({
|
|
380
|
-
uuid: getLinkStringProperty(link, "uuid"),
|
|
381
|
-
text: linkString,
|
|
382
|
-
content: contentText,
|
|
383
|
-
annotationMetadata,
|
|
384
|
-
propertyMetadata: getFirstPropertyMetadata(item)
|
|
385
|
-
});
|
|
386
|
-
result += component;
|
|
387
|
-
break;
|
|
388
|
-
}
|
|
389
|
-
case "externalDocument": {
|
|
390
|
-
const component = createMDXComponent(link.publicationDateTime != null ? "documentLink" : "tooltipSpan", {
|
|
391
|
-
uuid: getLinkStringProperty(link, "uuid"),
|
|
392
|
-
text: linkString,
|
|
393
|
-
content: contentText
|
|
394
|
-
});
|
|
395
|
-
result += component;
|
|
396
|
-
break;
|
|
397
|
-
}
|
|
398
|
-
case "webpage": {
|
|
399
|
-
const component = createMDXComponent("externalLink", {
|
|
400
|
-
uuid: getLinkStringProperty(link, "uuid"),
|
|
401
|
-
href: getLinkStringProperty(link, "href") ?? "#",
|
|
402
|
-
text: linkString,
|
|
403
|
-
content: contentText
|
|
404
|
-
});
|
|
405
|
-
result += component;
|
|
406
|
-
break;
|
|
407
|
-
}
|
|
408
|
-
default: result += link.publicationDateTime != null ? createInternalLinkComponent({
|
|
409
|
-
uuid: getLinkStringProperty(link, "uuid"),
|
|
410
|
-
text: linkString,
|
|
411
|
-
content: contentText,
|
|
412
|
-
annotationMetadata
|
|
413
|
-
}) : createMDXComponent("tooltipSpan", {
|
|
414
|
-
uuid: getLinkStringProperty(link, "uuid"),
|
|
415
|
-
text: linkString,
|
|
416
|
-
content: contentText
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
else if (link.publicationDateTime != null) {
|
|
420
|
-
const component = createInternalLinkComponent({
|
|
421
|
-
uuid: getLinkStringProperty(link, "uuid"),
|
|
422
|
-
text: linkString,
|
|
423
|
-
content: contentText,
|
|
424
|
-
annotationMetadata
|
|
425
|
-
});
|
|
426
|
-
result += component;
|
|
427
|
-
} else {
|
|
428
|
-
const component = createMDXComponent("tooltipSpan", {
|
|
429
|
-
uuid: getLinkStringProperty(link, "uuid"),
|
|
430
|
-
text: linkString,
|
|
431
|
-
content: contentText
|
|
432
|
-
});
|
|
433
|
-
result += component;
|
|
434
|
-
}
|
|
412
|
+
result += renderRichTextLink(item, link, linkString, contentText, annotationMetadata);
|
|
435
413
|
}
|
|
436
414
|
return applyNewlineWhitespace(result, item.whitespace, rendering);
|
|
437
415
|
}
|
|
@@ -8,12 +8,11 @@ import { ParserOptions } from "../helpers.mjs";
|
|
|
8
8
|
* @param bounds - Raw bounds data in OCHRE format
|
|
9
9
|
* @returns Parsed bounds object
|
|
10
10
|
*/
|
|
11
|
-
declare function parseBounds(bounds: string): [[number, number], [number, number]];
|
|
12
|
-
declare function parseWebpageView<T extends ReadonlyArray<string>>(view: {
|
|
11
|
+
export declare function parseBounds(bounds: string): [[number, number], [number, number]];
|
|
12
|
+
export declare function parseWebpageView<T extends ReadonlyArray<string>>(view: {
|
|
13
13
|
resource?: Array<XMLWebsiteResource>;
|
|
14
14
|
} | undefined, options: ParserOptions<T>, context: Pick<Website<T>, "belongsTo" | "metadata">): Webpage<T> | null;
|
|
15
|
-
declare function parseWebsite<const T extends ReadonlyArray<string> = ReadonlyArray<string>>(data: XMLWebsiteData, options?: {
|
|
15
|
+
export declare function parseWebsite<const T extends ReadonlyArray<string> = ReadonlyArray<string>>(data: XMLWebsiteData, options?: {
|
|
16
16
|
languages?: T;
|
|
17
17
|
}): Website<T>;
|
|
18
|
-
//#endregion
|
|
19
|
-
export { parseBounds, parseWebpageView, parseWebsite };
|
|
18
|
+
//#endregion
|