@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.
Files changed (61) hide show
  1. package/README.md +4 -2
  2. package/THIRD-PARTY-NOTICES.md +1 -1
  3. package/dist/dot-loader-types.cjs +60 -0
  4. package/dist/dot-loader-types.cjs.map +7 -0
  5. package/dist/dot-loader-types.d.ts +4 -2
  6. package/dist/dot-loader-types.d.ts.map +1 -1
  7. package/dist/dot-loader-types.js +3 -2
  8. package/dist/dot-loader-types.js.map +1 -1
  9. package/dist/dot-loader.cjs +15 -295
  10. package/dist/dot-loader.cjs.map +2 -2
  11. package/dist/dot-loader.d.ts +2 -1
  12. package/dist/dot-loader.d.ts.map +1 -1
  13. package/dist/dot-loader.js +3 -3
  14. package/dist/dot-loader.js.map +1 -1
  15. package/dist/gexf-loader-types.cjs +60 -0
  16. package/dist/gexf-loader-types.cjs.map +7 -0
  17. package/dist/gexf-loader-types.d.ts +4 -2
  18. package/dist/gexf-loader-types.d.ts.map +1 -1
  19. package/dist/gexf-loader-types.js +3 -2
  20. package/dist/gexf-loader-types.js.map +1 -1
  21. package/dist/gexf-loader.cjs +1652 -287
  22. package/dist/gexf-loader.cjs.map +3 -3
  23. package/dist/gexf-loader.d.ts +2 -1
  24. package/dist/gexf-loader.d.ts.map +1 -1
  25. package/dist/gexf-loader.js +3 -3
  26. package/dist/gexf-loader.js.map +1 -1
  27. package/dist/graph-types.d.ts +3 -2
  28. package/dist/graph-types.d.ts.map +1 -1
  29. package/dist/graphml-loader-types.cjs +60 -0
  30. package/dist/graphml-loader-types.cjs.map +7 -0
  31. package/dist/graphml-loader-types.d.ts +4 -2
  32. package/dist/graphml-loader-types.d.ts.map +1 -1
  33. package/dist/graphml-loader-types.js +3 -2
  34. package/dist/graphml-loader-types.js.map +1 -1
  35. package/dist/graphml-loader.cjs +1633 -280
  36. package/dist/graphml-loader.cjs.map +3 -3
  37. package/dist/graphml-loader.d.ts +2 -1
  38. package/dist/graphml-loader.d.ts.map +1 -1
  39. package/dist/graphml-loader.js +3 -3
  40. package/dist/graphml-loader.js.map +1 -1
  41. package/dist/index.cjs +36 -1930
  42. package/dist/index.cjs.map +4 -3
  43. package/dist/lib/build-graph-tables.d.ts.map +1 -1
  44. package/dist/lib/build-graph-tables.js +2 -4
  45. package/dist/lib/build-graph-tables.js.map +1 -1
  46. package/dist/lib/parse-gexf.d.ts.map +1 -1
  47. package/dist/lib/parse-gexf.js +10 -8
  48. package/dist/lib/parse-gexf.js.map +1 -1
  49. package/dist/lib/parse-graphml.js +4 -4
  50. package/dist/lib/parse-graphml.js.map +1 -1
  51. package/package.json +9 -7
  52. package/src/dot-loader-types.ts +2 -1
  53. package/src/dot-loader.ts +3 -3
  54. package/src/gexf-loader-types.ts +2 -1
  55. package/src/gexf-loader.ts +3 -3
  56. package/src/graph-types.ts +3 -2
  57. package/src/graphml-loader-types.ts +2 -1
  58. package/src/graphml-loader.ts +3 -3
  59. package/src/lib/build-graph-tables.ts +5 -7
  60. package/src/lib/parse-gexf.ts +10 -8
  61. package/src/lib/parse-graphml.ts +5 -5
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {XMLParser, XMLValidator} from 'fast-xml-parser';
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 parser = new XMLParser({
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-table'
45
+ shape: GraphShape = 'arrow'
44
46
  ): GEXFOutput {
45
47
  const text = typeof input === 'string' ? input : new TextDecoder().decode(input);
46
- const validation = XMLValidator.validate(text);
47
- if (validation !== true) throw new Error(`Invalid GEXF XML: ${validation.err.msg}`);
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(parser.parse(text) as XMLElement, {});
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)) {
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {XMLParser} from 'fast-xml-parser';
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 fast-xml-parser. */
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 graphmlParser = new XMLParser({
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 = graphmlParser.parse(xmlText) as GraphMLObject;
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.');