@c-rex/utils 0.3.0-build.24 → 0.3.0-build.26
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/directoryNodes.js.map +1 -1
- package/dist/directoryNodes.mjs.map +1 -1
- package/dist/index.d.mts +38 -4
- package/dist/index.d.ts +38 -4
- package/dist/index.js +167 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +163 -41
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AvailableVersionsInterface, TreeOfContent, RenditionModel, LanguageAndCountries, LiteralModel, ObjectRefModel } from '@c-rex/interfaces';
|
|
1
|
+
import { AvailableVersionsInterface, TreeOfContent, RenditionModel, LanguageAndCountries, LiteralModel, ObjectRefModel, CommonItemsModel } from '@c-rex/interfaces';
|
|
2
2
|
import { ClassValue } from 'clsx';
|
|
3
3
|
import { QueryParams, DocumentsType, articleInfoItemType, ResultTypes } from '@c-rex/types';
|
|
4
4
|
import { Metadata } from 'next';
|
|
@@ -52,6 +52,24 @@ declare const createParams: (fieldsList: string[], key?: string) => {
|
|
|
52
52
|
*/
|
|
53
53
|
declare const generateQueryParams: (params: QueryParams[]) => string;
|
|
54
54
|
|
|
55
|
+
type FileRenditionActionItem = {
|
|
56
|
+
label: string;
|
|
57
|
+
downloadUrl: string;
|
|
58
|
+
viewUrl?: string;
|
|
59
|
+
};
|
|
60
|
+
type FileRenditionActionGroup = {
|
|
61
|
+
format: string;
|
|
62
|
+
displayLabel: string;
|
|
63
|
+
iconFormat: string;
|
|
64
|
+
iconLabel: string;
|
|
65
|
+
items: FileRenditionActionItem[];
|
|
66
|
+
hasMultiple: boolean;
|
|
67
|
+
supportsOpen: boolean;
|
|
68
|
+
};
|
|
69
|
+
declare const getFileRenditionGroups: ({ renditions, ignoreFormats, }: {
|
|
70
|
+
renditions?: RenditionModel[] | null;
|
|
71
|
+
ignoreFormats?: string[];
|
|
72
|
+
}) => FileRenditionActionGroup[];
|
|
55
73
|
declare const getFileRenditions: ({ renditions }: {
|
|
56
74
|
renditions: RenditionModel[];
|
|
57
75
|
}) => DocumentsType;
|
|
@@ -60,9 +78,12 @@ declare const getFileRenditions: ({ renditions }: {
|
|
|
60
78
|
* Makes an asynchronous RPC API call to the server.
|
|
61
79
|
* @param method - The RPC method name to call
|
|
62
80
|
* @param params - Optional parameters to pass to the method
|
|
81
|
+
* @param options - Optional fetch controls (for example AbortSignal)
|
|
63
82
|
* @returns A Promise resolving to the response data of type T
|
|
64
83
|
*/
|
|
65
|
-
declare const call: <T>(method: string, params?: any
|
|
84
|
+
declare const call: <T>(method: string, params?: any, options?: {
|
|
85
|
+
signal?: AbortSignal;
|
|
86
|
+
}) => Promise<T>;
|
|
66
87
|
|
|
67
88
|
declare const normalizeLanguageCode: (value: string) => string;
|
|
68
89
|
declare const sortAndDeduplicateLanguages: (languages: Array<string | null | undefined>) => string[];
|
|
@@ -76,7 +97,8 @@ declare const transformLanguageData: (data: {
|
|
|
76
97
|
declare const isDate: (value: string) => boolean;
|
|
77
98
|
declare const isLanguage: (label: string) => boolean;
|
|
78
99
|
declare const filteredItems: (items: articleInfoItemType[]) => articleInfoItemType[];
|
|
79
|
-
declare const
|
|
100
|
+
declare const resolveLabelByLanguage: (labels?: LiteralModel[] | null, lang?: string) => string | undefined;
|
|
101
|
+
declare const getType: (classObj?: ObjectRefModel, lang?: string) => ResultTypes | undefined;
|
|
80
102
|
declare const getTitle: (titles?: LiteralModel[] | null, labels?: LiteralModel[] | null) => string;
|
|
81
103
|
declare const getLabelByLang: (labels?: LiteralModel[] | null, lang?: string) => string;
|
|
82
104
|
declare const getLanguage: (languages?: string[] | null) => string;
|
|
@@ -94,4 +116,16 @@ declare const parseHtmlContent: (html: string) => ParsedHtmlContent;
|
|
|
94
116
|
declare const getHtmlRenditionViewUrl: (renditions: RenditionModel[] | null | undefined, htmlFormats?: string[]) => string | undefined;
|
|
95
117
|
declare const metaTagsToMetadata: (metaTags: HtmlMetaTag[]) => Pick<Metadata, "description" | "keywords" | "other">;
|
|
96
118
|
|
|
97
|
-
|
|
119
|
+
type RelatedFragmentLike = ObjectRefModel & {
|
|
120
|
+
informationSubjects?: ObjectRefModel[] | null;
|
|
121
|
+
};
|
|
122
|
+
interface FindRelatedFragmentOptions {
|
|
123
|
+
item?: CommonItemsModel | {
|
|
124
|
+
informationUnits?: RelatedFragmentLike[] | null;
|
|
125
|
+
} | null;
|
|
126
|
+
informationSubjectIds?: string[];
|
|
127
|
+
}
|
|
128
|
+
declare const findRelatedFragment: ({ item, informationSubjectIds, }: FindRelatedFragmentOptions) => RelatedFragmentLike | undefined;
|
|
129
|
+
declare const findRelatedFragmentShortId: (options: FindRelatedFragmentOptions) => string | undefined;
|
|
130
|
+
|
|
131
|
+
export { type FileRenditionActionGroup, type FileRenditionActionItem, type HtmlMetaTag, type ParsedHtmlContent, call, cn, createAvailableVersionList, createParams, extractCountryCodeFromLanguage, filteredItems, findRelatedFragment, findRelatedFragmentShortId, formatDateToLocale, generateBreadcrumbItems, generateQueryParams, getCountryCodeByLang, getFileRenditionGroups, getFileRenditions, getHtmlRenditionViewUrl, getLabelByLang, getLanguage, getTitle, getType, getVersions, isDate, isLanguage, metaTagsToMetadata, normalizeLanguageCode, parseHtmlContent, processDataToLabelValuePairs, replacePathParams, resolveLabelByLanguage, resolvePreferredLanguage, sortAndDeduplicateLanguages, transformLanguageData };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AvailableVersionsInterface, TreeOfContent, RenditionModel, LanguageAndCountries, LiteralModel, ObjectRefModel } from '@c-rex/interfaces';
|
|
1
|
+
import { AvailableVersionsInterface, TreeOfContent, RenditionModel, LanguageAndCountries, LiteralModel, ObjectRefModel, CommonItemsModel } from '@c-rex/interfaces';
|
|
2
2
|
import { ClassValue } from 'clsx';
|
|
3
3
|
import { QueryParams, DocumentsType, articleInfoItemType, ResultTypes } from '@c-rex/types';
|
|
4
4
|
import { Metadata } from 'next';
|
|
@@ -52,6 +52,24 @@ declare const createParams: (fieldsList: string[], key?: string) => {
|
|
|
52
52
|
*/
|
|
53
53
|
declare const generateQueryParams: (params: QueryParams[]) => string;
|
|
54
54
|
|
|
55
|
+
type FileRenditionActionItem = {
|
|
56
|
+
label: string;
|
|
57
|
+
downloadUrl: string;
|
|
58
|
+
viewUrl?: string;
|
|
59
|
+
};
|
|
60
|
+
type FileRenditionActionGroup = {
|
|
61
|
+
format: string;
|
|
62
|
+
displayLabel: string;
|
|
63
|
+
iconFormat: string;
|
|
64
|
+
iconLabel: string;
|
|
65
|
+
items: FileRenditionActionItem[];
|
|
66
|
+
hasMultiple: boolean;
|
|
67
|
+
supportsOpen: boolean;
|
|
68
|
+
};
|
|
69
|
+
declare const getFileRenditionGroups: ({ renditions, ignoreFormats, }: {
|
|
70
|
+
renditions?: RenditionModel[] | null;
|
|
71
|
+
ignoreFormats?: string[];
|
|
72
|
+
}) => FileRenditionActionGroup[];
|
|
55
73
|
declare const getFileRenditions: ({ renditions }: {
|
|
56
74
|
renditions: RenditionModel[];
|
|
57
75
|
}) => DocumentsType;
|
|
@@ -60,9 +78,12 @@ declare const getFileRenditions: ({ renditions }: {
|
|
|
60
78
|
* Makes an asynchronous RPC API call to the server.
|
|
61
79
|
* @param method - The RPC method name to call
|
|
62
80
|
* @param params - Optional parameters to pass to the method
|
|
81
|
+
* @param options - Optional fetch controls (for example AbortSignal)
|
|
63
82
|
* @returns A Promise resolving to the response data of type T
|
|
64
83
|
*/
|
|
65
|
-
declare const call: <T>(method: string, params?: any
|
|
84
|
+
declare const call: <T>(method: string, params?: any, options?: {
|
|
85
|
+
signal?: AbortSignal;
|
|
86
|
+
}) => Promise<T>;
|
|
66
87
|
|
|
67
88
|
declare const normalizeLanguageCode: (value: string) => string;
|
|
68
89
|
declare const sortAndDeduplicateLanguages: (languages: Array<string | null | undefined>) => string[];
|
|
@@ -76,7 +97,8 @@ declare const transformLanguageData: (data: {
|
|
|
76
97
|
declare const isDate: (value: string) => boolean;
|
|
77
98
|
declare const isLanguage: (label: string) => boolean;
|
|
78
99
|
declare const filteredItems: (items: articleInfoItemType[]) => articleInfoItemType[];
|
|
79
|
-
declare const
|
|
100
|
+
declare const resolveLabelByLanguage: (labels?: LiteralModel[] | null, lang?: string) => string | undefined;
|
|
101
|
+
declare const getType: (classObj?: ObjectRefModel, lang?: string) => ResultTypes | undefined;
|
|
80
102
|
declare const getTitle: (titles?: LiteralModel[] | null, labels?: LiteralModel[] | null) => string;
|
|
81
103
|
declare const getLabelByLang: (labels?: LiteralModel[] | null, lang?: string) => string;
|
|
82
104
|
declare const getLanguage: (languages?: string[] | null) => string;
|
|
@@ -94,4 +116,16 @@ declare const parseHtmlContent: (html: string) => ParsedHtmlContent;
|
|
|
94
116
|
declare const getHtmlRenditionViewUrl: (renditions: RenditionModel[] | null | undefined, htmlFormats?: string[]) => string | undefined;
|
|
95
117
|
declare const metaTagsToMetadata: (metaTags: HtmlMetaTag[]) => Pick<Metadata, "description" | "keywords" | "other">;
|
|
96
118
|
|
|
97
|
-
|
|
119
|
+
type RelatedFragmentLike = ObjectRefModel & {
|
|
120
|
+
informationSubjects?: ObjectRefModel[] | null;
|
|
121
|
+
};
|
|
122
|
+
interface FindRelatedFragmentOptions {
|
|
123
|
+
item?: CommonItemsModel | {
|
|
124
|
+
informationUnits?: RelatedFragmentLike[] | null;
|
|
125
|
+
} | null;
|
|
126
|
+
informationSubjectIds?: string[];
|
|
127
|
+
}
|
|
128
|
+
declare const findRelatedFragment: ({ item, informationSubjectIds, }: FindRelatedFragmentOptions) => RelatedFragmentLike | undefined;
|
|
129
|
+
declare const findRelatedFragmentShortId: (options: FindRelatedFragmentOptions) => string | undefined;
|
|
130
|
+
|
|
131
|
+
export { type FileRenditionActionGroup, type FileRenditionActionItem, type HtmlMetaTag, type ParsedHtmlContent, call, cn, createAvailableVersionList, createParams, extractCountryCodeFromLanguage, filteredItems, findRelatedFragment, findRelatedFragmentShortId, formatDateToLocale, generateBreadcrumbItems, generateQueryParams, getCountryCodeByLang, getFileRenditionGroups, getFileRenditions, getHtmlRenditionViewUrl, getLabelByLang, getLanguage, getTitle, getType, getVersions, isDate, isLanguage, metaTagsToMetadata, normalizeLanguageCode, parseHtmlContent, processDataToLabelValuePairs, replacePathParams, resolveLabelByLanguage, resolvePreferredLanguage, sortAndDeduplicateLanguages, transformLanguageData };
|
package/dist/index.js
CHANGED
|
@@ -36,10 +36,13 @@ __export(index_exports, {
|
|
|
36
36
|
createParams: () => createParams,
|
|
37
37
|
extractCountryCodeFromLanguage: () => extractCountryCodeFromLanguage,
|
|
38
38
|
filteredItems: () => filteredItems,
|
|
39
|
+
findRelatedFragment: () => findRelatedFragment,
|
|
40
|
+
findRelatedFragmentShortId: () => findRelatedFragmentShortId,
|
|
39
41
|
formatDateToLocale: () => formatDateToLocale,
|
|
40
42
|
generateBreadcrumbItems: () => generateBreadcrumbItems,
|
|
41
43
|
generateQueryParams: () => generateQueryParams,
|
|
42
44
|
getCountryCodeByLang: () => getCountryCodeByLang,
|
|
45
|
+
getFileRenditionGroups: () => getFileRenditionGroups,
|
|
43
46
|
getFileRenditions: () => getFileRenditions,
|
|
44
47
|
getHtmlRenditionViewUrl: () => getHtmlRenditionViewUrl,
|
|
45
48
|
getLabelByLang: () => getLabelByLang,
|
|
@@ -54,6 +57,7 @@ __export(index_exports, {
|
|
|
54
57
|
parseHtmlContent: () => parseHtmlContent,
|
|
55
58
|
processDataToLabelValuePairs: () => processDataToLabelValuePairs,
|
|
56
59
|
replacePathParams: () => replacePathParams,
|
|
60
|
+
resolveLabelByLanguage: () => resolveLabelByLanguage,
|
|
57
61
|
resolvePreferredLanguage: () => resolvePreferredLanguage,
|
|
58
62
|
sortAndDeduplicateLanguages: () => sortAndDeduplicateLanguages,
|
|
59
63
|
transformLanguageData: () => transformLanguageData
|
|
@@ -1559,44 +1563,127 @@ var generateQueryParams = (params) => {
|
|
|
1559
1563
|
};
|
|
1560
1564
|
|
|
1561
1565
|
// src/renditions.ts
|
|
1562
|
-
var
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1566
|
+
var DEFAULT_IGNORED_FORMATS = [
|
|
1567
|
+
"application/xhtml+xml",
|
|
1568
|
+
"application/json",
|
|
1569
|
+
"application/llm+xml",
|
|
1570
|
+
"text/html"
|
|
1571
|
+
];
|
|
1572
|
+
var isZipLikeFormat = (format) => {
|
|
1573
|
+
const normalized = format.toLowerCase();
|
|
1574
|
+
return normalized === "application/zip" || normalized.startsWith("application/") && normalized.endsWith("+zip");
|
|
1575
|
+
};
|
|
1576
|
+
var getArchiveDisplayCode = (format) => {
|
|
1577
|
+
const normalized = format.toLowerCase();
|
|
1578
|
+
if (normalized === "application/zip") {
|
|
1579
|
+
return "ZIP";
|
|
1571
1580
|
}
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
const
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
};
|
|
1581
|
+
if (normalized.startsWith("application/") && normalized.endsWith("+zip")) {
|
|
1582
|
+
const subtype = normalized.slice("application/".length, -"+zip".length);
|
|
1583
|
+
const parts = subtype.split(".");
|
|
1584
|
+
const lastPart = parts[parts.length - 1]?.trim();
|
|
1585
|
+
const token = lastPart && lastPart.length > 0 ? lastPart : subtype.trim();
|
|
1586
|
+
if (token && token.length > 0 && token !== "vnd") {
|
|
1587
|
+
return token.replace(/[^a-z0-9]/gi, "").slice(0, 4).toUpperCase() || "ZIP";
|
|
1580
1588
|
}
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1589
|
+
}
|
|
1590
|
+
return null;
|
|
1591
|
+
};
|
|
1592
|
+
var getDisplayLabel = (format) => {
|
|
1593
|
+
if (format === "application/pdf") return "PDF";
|
|
1594
|
+
if (isZipLikeFormat(format)) return "ZIP";
|
|
1595
|
+
const subtype = format.split("/")[1] || format;
|
|
1596
|
+
return subtype.replace(/\+.*/, "").toUpperCase();
|
|
1597
|
+
};
|
|
1598
|
+
var getIconFormat = (format) => {
|
|
1599
|
+
if (format === "application/pdf") return "application/pdf";
|
|
1600
|
+
if (format === "application/zip") return "application/zip";
|
|
1601
|
+
if (isZipLikeFormat(format)) return format;
|
|
1602
|
+
return format;
|
|
1603
|
+
};
|
|
1604
|
+
var getIconLabel = (format) => {
|
|
1605
|
+
if (format === "application/pdf") return "PDF";
|
|
1606
|
+
const archiveCode = getArchiveDisplayCode(format);
|
|
1607
|
+
if (archiveCode) return archiveCode;
|
|
1608
|
+
return getDisplayLabel(format);
|
|
1609
|
+
};
|
|
1610
|
+
var getFirstLinkByRel = (item, rel) => item.links?.find((link) => link.rel === rel)?.href;
|
|
1611
|
+
var getRenditionFileName = (item, fallbackFormat) => {
|
|
1612
|
+
const rawSource = item.source?.split("/").pop();
|
|
1613
|
+
if (rawSource && rawSource.length > 0) {
|
|
1614
|
+
return decodeURIComponent(rawSource);
|
|
1615
|
+
}
|
|
1616
|
+
const urlCandidate = getFirstLinkByRel(item, "download") || getFirstLinkByRel(item, "view");
|
|
1617
|
+
if (urlCandidate) {
|
|
1618
|
+
try {
|
|
1619
|
+
const url = new URL(urlCandidate);
|
|
1620
|
+
const lastSegment = url.pathname.split("/").pop();
|
|
1621
|
+
if (lastSegment && lastSegment.length > 0) {
|
|
1622
|
+
return decodeURIComponent(lastSegment);
|
|
1623
|
+
}
|
|
1624
|
+
} catch {
|
|
1625
|
+
const lastSegment = urlCandidate.split("/").pop();
|
|
1626
|
+
if (lastSegment && lastSegment.length > 0) {
|
|
1627
|
+
return decodeURIComponent(lastSegment);
|
|
1628
|
+
}
|
|
1588
1629
|
}
|
|
1630
|
+
}
|
|
1631
|
+
return getDisplayLabel(fallbackFormat);
|
|
1632
|
+
};
|
|
1633
|
+
var getFileRenditionGroups = ({
|
|
1634
|
+
renditions,
|
|
1635
|
+
ignoreFormats = DEFAULT_IGNORED_FORMATS
|
|
1636
|
+
}) => {
|
|
1637
|
+
if (!renditions || renditions.length === 0) return [];
|
|
1638
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
1639
|
+
renditions.filter((item) => item.format && !ignoreFormats.includes(item.format)).forEach((item) => {
|
|
1640
|
+
const format = item.format;
|
|
1641
|
+
const downloadUrl = getFirstLinkByRel(item, "download");
|
|
1642
|
+
const viewUrl = getFirstLinkByRel(item, "view");
|
|
1643
|
+
if (!downloadUrl && !viewUrl) return;
|
|
1644
|
+
const current = grouped.get(format) || [];
|
|
1645
|
+
current.push({
|
|
1646
|
+
label: getRenditionFileName(item, format),
|
|
1647
|
+
downloadUrl: downloadUrl || viewUrl || "",
|
|
1648
|
+
viewUrl: viewUrl || void 0
|
|
1649
|
+
});
|
|
1650
|
+
grouped.set(format, current);
|
|
1589
1651
|
});
|
|
1590
|
-
return
|
|
1652
|
+
return Array.from(grouped.entries()).map(([format, items]) => {
|
|
1653
|
+
const deduplicatedItems = items.filter((item) => item.downloadUrl);
|
|
1654
|
+
const hasMultiple = deduplicatedItems.length > 1;
|
|
1655
|
+
const isPdf = format === "application/pdf";
|
|
1656
|
+
return {
|
|
1657
|
+
format,
|
|
1658
|
+
displayLabel: getDisplayLabel(format),
|
|
1659
|
+
iconFormat: getIconFormat(format),
|
|
1660
|
+
iconLabel: getIconLabel(format),
|
|
1661
|
+
items: deduplicatedItems,
|
|
1662
|
+
hasMultiple,
|
|
1663
|
+
supportsOpen: isPdf && !hasMultiple && !!deduplicatedItems[0]?.viewUrl
|
|
1664
|
+
};
|
|
1665
|
+
}).filter((group) => group.items.length > 0);
|
|
1666
|
+
};
|
|
1667
|
+
var getFileRenditions = ({ renditions }) => {
|
|
1668
|
+
return getFileRenditionGroups({ renditions }).reduce((acc, group) => {
|
|
1669
|
+
const first = group.items[0];
|
|
1670
|
+
if (!first) return acc;
|
|
1671
|
+
acc[group.format] = {
|
|
1672
|
+
view: first.viewUrl || "",
|
|
1673
|
+
download: first.downloadUrl || ""
|
|
1674
|
+
};
|
|
1675
|
+
return acc;
|
|
1676
|
+
}, {});
|
|
1591
1677
|
};
|
|
1592
1678
|
|
|
1593
1679
|
// src/call.ts
|
|
1594
|
-
var call = async (method, params) => {
|
|
1680
|
+
var call = async (method, params, options) => {
|
|
1595
1681
|
const res = await fetch(`/api/rpc`, {
|
|
1596
1682
|
method: "POST",
|
|
1597
1683
|
headers: { "Content-Type": "application/json" },
|
|
1598
1684
|
body: JSON.stringify({ method, params }),
|
|
1599
|
-
credentials: "include"
|
|
1685
|
+
credentials: "include",
|
|
1686
|
+
signal: options?.signal
|
|
1600
1687
|
});
|
|
1601
1688
|
const json = await res.json();
|
|
1602
1689
|
if (!res.ok) throw new Error(json.error || "Unknown error");
|
|
@@ -1665,8 +1752,31 @@ var filteredItems = (items) => {
|
|
|
1665
1752
|
const hasTitle = items.some((item) => item.label === "titles");
|
|
1666
1753
|
return items.filter((item) => hasTitle ? item.label !== "labels" : true);
|
|
1667
1754
|
};
|
|
1668
|
-
var
|
|
1669
|
-
|
|
1755
|
+
var resolveLabelByLanguage = (labels, lang = EN_LANG) => {
|
|
1756
|
+
if (!labels || labels.length === 0) {
|
|
1757
|
+
return void 0;
|
|
1758
|
+
}
|
|
1759
|
+
const normalizedLanguage = normalizeLanguageCode(lang || EN_LANG).toLowerCase();
|
|
1760
|
+
const baseLanguage = normalizedLanguage.split("-")[0];
|
|
1761
|
+
const normalizedLabels = labels.map((item) => ({
|
|
1762
|
+
language: normalizeLanguageCode(item.language || "").toLowerCase(),
|
|
1763
|
+
value: item.value?.trim() || ""
|
|
1764
|
+
})).filter((item) => item.value.length > 0);
|
|
1765
|
+
if (normalizedLabels.length === 0) {
|
|
1766
|
+
return void 0;
|
|
1767
|
+
}
|
|
1768
|
+
const exact = normalizedLabels.find((item) => item.language === normalizedLanguage)?.value;
|
|
1769
|
+
if (exact) return exact;
|
|
1770
|
+
const base = normalizedLabels.find((item) => item.language === baseLanguage)?.value || normalizedLabels.find((item) => item.language.startsWith(`${baseLanguage}-`))?.value;
|
|
1771
|
+
if (base) return base;
|
|
1772
|
+
const english = normalizedLabels.find((item) => item.language === "en-us")?.value || normalizedLabels.find((item) => item.language === "en")?.value || normalizedLabels.find((item) => item.language.startsWith("en-"))?.value;
|
|
1773
|
+
if (english) return english;
|
|
1774
|
+
const noLanguage = normalizedLabels.find((item) => item.language.length === 0)?.value;
|
|
1775
|
+
if (noLanguage) return noLanguage;
|
|
1776
|
+
return normalizedLabels[0]?.value;
|
|
1777
|
+
};
|
|
1778
|
+
var getType = (classObj, lang = EN_LANG) => {
|
|
1779
|
+
const type = resolveLabelByLanguage(classObj?.labels, lang)?.toUpperCase();
|
|
1670
1780
|
return type;
|
|
1671
1781
|
};
|
|
1672
1782
|
var getTitle = (titles, labels) => {
|
|
@@ -1679,18 +1789,7 @@ var getTitle = (titles, labels) => {
|
|
|
1679
1789
|
return "NO TITLE";
|
|
1680
1790
|
};
|
|
1681
1791
|
var getLabelByLang = (labels, lang = EN_LANG) => {
|
|
1682
|
-
|
|
1683
|
-
return "NO TITLE";
|
|
1684
|
-
}
|
|
1685
|
-
const preferred = labels.find((item) => item.language === lang);
|
|
1686
|
-
if (preferred) {
|
|
1687
|
-
return preferred.value;
|
|
1688
|
-
}
|
|
1689
|
-
const fallback = labels.find((item) => item.language === EN_LANG);
|
|
1690
|
-
if (fallback) {
|
|
1691
|
-
return fallback.value;
|
|
1692
|
-
}
|
|
1693
|
-
return "NO TITLE";
|
|
1792
|
+
return resolveLabelByLanguage(labels, lang) || "NO TITLE";
|
|
1694
1793
|
};
|
|
1695
1794
|
var getLanguage = (languages) => {
|
|
1696
1795
|
if (languages && languages.length > 0) {
|
|
@@ -1741,6 +1840,29 @@ var metaTagsToMetadata = (metaTags) => {
|
|
|
1741
1840
|
other: Object.keys(other).length > 0 ? other : void 0
|
|
1742
1841
|
};
|
|
1743
1842
|
};
|
|
1843
|
+
|
|
1844
|
+
// src/related-fragments.ts
|
|
1845
|
+
var matchesSubject = (fragment, informationSubjectIds) => {
|
|
1846
|
+
if (informationSubjectIds.length === 0) return true;
|
|
1847
|
+
const fragmentSubjects = fragment.informationSubjects || [];
|
|
1848
|
+
return fragmentSubjects.some((subject) => {
|
|
1849
|
+
const id = subject.id || subject.shortId;
|
|
1850
|
+
return !!id && informationSubjectIds.includes(id);
|
|
1851
|
+
});
|
|
1852
|
+
};
|
|
1853
|
+
var findRelatedFragment = ({
|
|
1854
|
+
item,
|
|
1855
|
+
informationSubjectIds = []
|
|
1856
|
+
}) => {
|
|
1857
|
+
const relatedItems = item?.informationUnits || [];
|
|
1858
|
+
return relatedItems.find((relatedItem) => {
|
|
1859
|
+
if (!relatedItem?.shortId) return false;
|
|
1860
|
+
return matchesSubject(relatedItem, informationSubjectIds);
|
|
1861
|
+
});
|
|
1862
|
+
};
|
|
1863
|
+
var findRelatedFragmentShortId = (options) => {
|
|
1864
|
+
return findRelatedFragment(options)?.shortId || void 0;
|
|
1865
|
+
};
|
|
1744
1866
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1745
1867
|
0 && (module.exports = {
|
|
1746
1868
|
call,
|
|
@@ -1749,10 +1871,13 @@ var metaTagsToMetadata = (metaTags) => {
|
|
|
1749
1871
|
createParams,
|
|
1750
1872
|
extractCountryCodeFromLanguage,
|
|
1751
1873
|
filteredItems,
|
|
1874
|
+
findRelatedFragment,
|
|
1875
|
+
findRelatedFragmentShortId,
|
|
1752
1876
|
formatDateToLocale,
|
|
1753
1877
|
generateBreadcrumbItems,
|
|
1754
1878
|
generateQueryParams,
|
|
1755
1879
|
getCountryCodeByLang,
|
|
1880
|
+
getFileRenditionGroups,
|
|
1756
1881
|
getFileRenditions,
|
|
1757
1882
|
getHtmlRenditionViewUrl,
|
|
1758
1883
|
getLabelByLang,
|
|
@@ -1767,6 +1892,7 @@ var metaTagsToMetadata = (metaTags) => {
|
|
|
1767
1892
|
parseHtmlContent,
|
|
1768
1893
|
processDataToLabelValuePairs,
|
|
1769
1894
|
replacePathParams,
|
|
1895
|
+
resolveLabelByLanguage,
|
|
1770
1896
|
resolvePreferredLanguage,
|
|
1771
1897
|
sortAndDeduplicateLanguages,
|
|
1772
1898
|
transformLanguageData
|