@loaders.gl/graphs 5.0.0-beta.1 → 5.0.0-beta.10
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/README.md +4 -2
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/dist/dot-loader-types.cjs +60 -0
- package/dist/dot-loader-types.cjs.map +7 -0
- package/dist/dot-loader-types.d.ts +4 -2
- package/dist/dot-loader-types.d.ts.map +1 -1
- package/dist/dot-loader-types.js +3 -2
- package/dist/dot-loader-types.js.map +1 -1
- package/dist/dot-loader.cjs +15 -295
- package/dist/dot-loader.cjs.map +2 -2
- package/dist/dot-loader.d.ts +2 -1
- package/dist/dot-loader.d.ts.map +1 -1
- package/dist/dot-loader.js +3 -3
- package/dist/dot-loader.js.map +1 -1
- package/dist/gexf-loader-types.cjs +60 -0
- package/dist/gexf-loader-types.cjs.map +7 -0
- package/dist/gexf-loader-types.d.ts +4 -2
- package/dist/gexf-loader-types.d.ts.map +1 -1
- package/dist/gexf-loader-types.js +3 -2
- package/dist/gexf-loader-types.js.map +1 -1
- package/dist/gexf-loader.cjs +1652 -287
- package/dist/gexf-loader.cjs.map +3 -3
- package/dist/gexf-loader.d.ts +2 -1
- package/dist/gexf-loader.d.ts.map +1 -1
- package/dist/gexf-loader.js +3 -3
- package/dist/gexf-loader.js.map +1 -1
- package/dist/graph-types.d.ts +3 -2
- package/dist/graph-types.d.ts.map +1 -1
- package/dist/graphml-loader-types.cjs +60 -0
- package/dist/graphml-loader-types.cjs.map +7 -0
- package/dist/graphml-loader-types.d.ts +4 -2
- package/dist/graphml-loader-types.d.ts.map +1 -1
- package/dist/graphml-loader-types.js +3 -2
- package/dist/graphml-loader-types.js.map +1 -1
- package/dist/graphml-loader.cjs +1633 -280
- package/dist/graphml-loader.cjs.map +3 -3
- package/dist/graphml-loader.d.ts +2 -1
- package/dist/graphml-loader.d.ts.map +1 -1
- package/dist/graphml-loader.js +3 -3
- package/dist/graphml-loader.js.map +1 -1
- package/dist/index.cjs +36 -1930
- package/dist/index.cjs.map +4 -3
- package/dist/lib/build-graph-tables.d.ts.map +1 -1
- package/dist/lib/build-graph-tables.js +2 -4
- package/dist/lib/build-graph-tables.js.map +1 -1
- package/dist/lib/parse-gexf.d.ts.map +1 -1
- package/dist/lib/parse-gexf.js +10 -8
- package/dist/lib/parse-gexf.js.map +1 -1
- package/dist/lib/parse-graphml.js +4 -4
- package/dist/lib/parse-graphml.js.map +1 -1
- package/package.json +9 -7
- package/src/dot-loader-types.ts +2 -1
- package/src/dot-loader.ts +3 -3
- package/src/gexf-loader-types.ts +2 -1
- package/src/gexf-loader.ts +3 -3
- package/src/graph-types.ts +3 -2
- package/src/graphml-loader-types.ts +2 -1
- package/src/graphml-loader.ts +3 -3
- package/src/lib/build-graph-tables.ts +5 -7
- package/src/lib/parse-gexf.ts +10 -8
- package/src/lib/parse-graphml.ts +5 -5
package/src/lib/parse-gexf.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {parseXMLSync, validateXML} from '@loaders.gl/documents/xml-parser';
|
|
6
6
|
import type {GraphNode, GraphEdge, GraphShape, GraphAttributeType} from '../graph-types';
|
|
7
7
|
import type {GEXFOutput} from '../gexf-types';
|
|
8
8
|
import {buildGraphTables} from './build-graph-tables';
|
|
@@ -20,12 +20,14 @@ type AttributeDefinition = {
|
|
|
20
20
|
defaultValue?: unknown;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
const
|
|
23
|
+
const XML_OPTIONS = {
|
|
24
24
|
ignoreAttributes: false,
|
|
25
25
|
parseAttributeValue: false,
|
|
26
26
|
parseTagValue: false,
|
|
27
|
-
trimValues: false
|
|
28
|
-
|
|
27
|
+
trimValues: false,
|
|
28
|
+
attributeNamePrefix: '@_',
|
|
29
|
+
textNodeName: '#text'
|
|
30
|
+
};
|
|
29
31
|
const GEXF_NAMESPACE = /^https?:\/\/(?:www\.)?gexf.net\/1\.(?:2(?:draft)?|3)(\/viz)?$/;
|
|
30
32
|
const TEMPORAL_ATTRIBUTES = [
|
|
31
33
|
'start',
|
|
@@ -40,14 +42,14 @@ const TEMPORAL_ATTRIBUTES = [
|
|
|
40
42
|
/** Parses a static GEXF document directly into the selected graph representation. */
|
|
41
43
|
export function parseGEXF(
|
|
42
44
|
input: string | ArrayBuffer | Uint8Array,
|
|
43
|
-
shape: GraphShape = 'arrow
|
|
45
|
+
shape: GraphShape = 'arrow'
|
|
44
46
|
): GEXFOutput {
|
|
45
47
|
const text = typeof input === 'string' ? input : new TextDecoder().decode(input);
|
|
46
|
-
const validation =
|
|
47
|
-
if (validation !== true) throw new Error(`Invalid GEXF XML: ${validation.
|
|
48
|
+
const validation = validateXML(text);
|
|
49
|
+
if (validation !== true) throw new Error(`Invalid GEXF XML: ${validation.message}`);
|
|
48
50
|
// External and custom entity declarations are outside the supported format subset.
|
|
49
51
|
if (/<!DOCTYPE\s/i.test(text)) throw new Error('GEXF document types are unsupported.');
|
|
50
|
-
const document = normalizeNamespaces(
|
|
52
|
+
const document = normalizeNamespaces(parseXMLSync(text, XML_OPTIONS) as XMLElement, {});
|
|
51
53
|
const root = getElement(document.gexf, 'gexf');
|
|
52
54
|
const version = root['@_version'] as string | undefined;
|
|
53
55
|
if (version && !['1.2', '1.2draft', '1.3'].includes(version)) {
|
package/src/lib/parse-graphml.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {parseXMLSync} from '@loaders.gl/documents/xml-parser';
|
|
6
6
|
|
|
7
7
|
import type {
|
|
8
8
|
GraphData,
|
|
@@ -37,13 +37,13 @@ type GraphMLKeyDefinition = {
|
|
|
37
37
|
lossless: boolean;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
/** XML element representation emitted by
|
|
40
|
+
/** XML element representation emitted by the documents XML parser. */
|
|
41
41
|
type GraphMLObject = Record<string, unknown> & {
|
|
42
42
|
/** Element text content. */
|
|
43
43
|
[XML_TEXT_KEY]?: string;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
const
|
|
46
|
+
const GRAPHML_XML_OPTIONS = {
|
|
47
47
|
ignoreAttributes: false,
|
|
48
48
|
attributeNamePrefix: XML_ATTRIBUTE_PREFIX,
|
|
49
49
|
textNodeName: XML_TEXT_KEY,
|
|
@@ -51,7 +51,7 @@ const graphmlParser = new XMLParser({
|
|
|
51
51
|
parseAttributeValue: false,
|
|
52
52
|
parseTagValue: false,
|
|
53
53
|
removeNSPrefix: true
|
|
54
|
-
}
|
|
54
|
+
};
|
|
55
55
|
|
|
56
56
|
/** Accepted GraphML document inputs. */
|
|
57
57
|
export type GraphMLInput = string | ArrayBuffer | Uint8Array;
|
|
@@ -64,7 +64,7 @@ export function parseGraphML(
|
|
|
64
64
|
shape: GraphShape = 'plain-graph-data'
|
|
65
65
|
): GraphOutput {
|
|
66
66
|
const xmlText = decodeGraphML(graphml);
|
|
67
|
-
const document =
|
|
67
|
+
const document = parseXMLSync(xmlText, GRAPHML_XML_OPTIONS) as GraphMLObject;
|
|
68
68
|
const graphmlRoot = getGraphMLRoot(document);
|
|
69
69
|
if (!graphmlRoot) {
|
|
70
70
|
throw new Error('GraphML document does not contain a <graphml> element.');
|