@loaders.gl/graphs 5.0.0-alpha.9 → 5.0.0-beta.1

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 (78) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +121 -4
  3. package/THIRD-PARTY-NOTICES.md +17 -0
  4. package/dist/dot-loader-types.d.ts +25 -8
  5. package/dist/dot-loader-types.d.ts.map +1 -1
  6. package/dist/dot-loader-types.js +2 -2
  7. package/dist/dot-loader-types.js.map +1 -1
  8. package/dist/dot-loader.cjs +638 -47
  9. package/dist/dot-loader.cjs.map +3 -3
  10. package/dist/dot-loader.d.ts +10 -6
  11. package/dist/dot-loader.d.ts.map +1 -1
  12. package/dist/dot-loader.js +3 -3
  13. package/dist/dot-loader.js.map +1 -1
  14. package/dist/dot-types.d.ts +6 -1
  15. package/dist/dot-types.d.ts.map +1 -1
  16. package/dist/gexf-loader-types.d.ts +53 -0
  17. package/dist/gexf-loader-types.d.ts.map +1 -0
  18. package/dist/gexf-loader-types.js +26 -0
  19. package/dist/gexf-loader-types.js.map +1 -0
  20. package/dist/gexf-loader.cjs +1304 -0
  21. package/dist/gexf-loader.cjs.map +6 -0
  22. package/dist/gexf-loader.d.ts +24 -0
  23. package/dist/gexf-loader.d.ts.map +1 -0
  24. package/dist/gexf-loader.js +13 -0
  25. package/dist/gexf-loader.js.map +1 -0
  26. package/dist/gexf-types.d.ts +16 -0
  27. package/dist/gexf-types.d.ts.map +1 -0
  28. package/dist/gexf-types.js +5 -0
  29. package/dist/gexf-types.js.map +1 -0
  30. package/dist/graph-types.d.ts +28 -0
  31. package/dist/graph-types.d.ts.map +1 -1
  32. package/dist/graphml-loader-types.d.ts +24 -8
  33. package/dist/graphml-loader-types.d.ts.map +1 -1
  34. package/dist/graphml-loader-types.js +2 -2
  35. package/dist/graphml-loader-types.js.map +1 -1
  36. package/dist/graphml-loader.cjs +670 -60
  37. package/dist/graphml-loader.cjs.map +3 -3
  38. package/dist/graphml-loader.d.ts +10 -6
  39. package/dist/graphml-loader.d.ts.map +1 -1
  40. package/dist/graphml-loader.js +3 -3
  41. package/dist/graphml-loader.js.map +1 -1
  42. package/dist/index.cjs +927 -59
  43. package/dist/index.cjs.map +3 -3
  44. package/dist/index.d.ts +7 -0
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +1 -0
  47. package/dist/index.js.map +1 -1
  48. package/dist/lib/build-graph-tables.d.ts +4 -0
  49. package/dist/lib/build-graph-tables.d.ts.map +1 -0
  50. package/dist/lib/build-graph-tables.js +143 -0
  51. package/dist/lib/build-graph-tables.js.map +1 -0
  52. package/dist/lib/parse-dot.d.ts +3 -1
  53. package/dist/lib/parse-dot.d.ts.map +1 -1
  54. package/dist/lib/parse-dot.js +38 -21
  55. package/dist/lib/parse-dot.js.map +1 -1
  56. package/dist/lib/parse-gexf.d.ts +5 -0
  57. package/dist/lib/parse-gexf.d.ts.map +1 -0
  58. package/dist/lib/parse-gexf.js +380 -0
  59. package/dist/lib/parse-gexf.js.map +1 -0
  60. package/dist/lib/parse-graphml.d.ts +2 -1
  61. package/dist/lib/parse-graphml.d.ts.map +1 -1
  62. package/dist/lib/parse-graphml.js +50 -27
  63. package/dist/lib/parse-graphml.js.map +1 -1
  64. package/package.json +13 -5
  65. package/src/dot-loader-types.ts +15 -5
  66. package/src/dot-loader.ts +7 -4
  67. package/src/dot-types.ts +7 -1
  68. package/src/gexf-loader-types.ts +41 -0
  69. package/src/gexf-loader.ts +17 -0
  70. package/src/gexf-types.ts +21 -0
  71. package/src/graph-types.ts +35 -0
  72. package/src/graphml-loader-types.ts +14 -5
  73. package/src/graphml-loader.ts +7 -4
  74. package/src/index.ts +9 -0
  75. package/src/lib/build-graph-tables.ts +208 -0
  76. package/src/lib/parse-dot.ts +44 -21
  77. package/src/lib/parse-gexf.ts +388 -0
  78. package/src/lib/parse-graphml.ts +86 -34
package/dist/index.cjs CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __esm = (fn, res, err) => function __init() {
7
9
  if (err) throw err[0];
@@ -23,6 +25,14 @@ var __copyProps = (to, from, except, desc) => {
23
25
  }
24
26
  return to;
25
27
  };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
26
36
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
37
 
28
38
  // src/graphml-loader-types.ts
@@ -46,14 +56,427 @@ var init_graphml_loader_types = __esm({
46
56
  worker: false,
47
57
  dataType: null,
48
58
  batchType: null,
49
- options: {},
59
+ options: { graphml: { shape: "arrow-table" } },
50
60
  preload
51
61
  };
52
62
  }
53
63
  });
54
64
 
65
+ // ../core/src/schema-utils/lib/schema/convert-arrow-schema.ts
66
+ function convertArrowToSchema(arrowSchema) {
67
+ return serializeArrowSchema(arrowSchema);
68
+ }
69
+ function serializeArrowSchema(arrowSchema) {
70
+ return {
71
+ fields: arrowSchema.fields.map((arrowField) => serializeArrowField(arrowField)),
72
+ metadata: serializeArrowMetadata(arrowSchema.metadata)
73
+ };
74
+ }
75
+ function serializeArrowMetadata(arrowMetadata) {
76
+ return Object.fromEntries(arrowMetadata);
77
+ }
78
+ function serializeArrowField(field) {
79
+ return {
80
+ name: field.name,
81
+ type: serializeArrowType(field.type),
82
+ nullable: field.nullable,
83
+ metadata: serializeArrowMetadata(field.metadata)
84
+ };
85
+ }
86
+ function serializeArrowType(arrowType) {
87
+ if (isArrowViewType(arrowType, "BinaryView")) {
88
+ return "binary-view";
89
+ }
90
+ if (isArrowViewType(arrowType, "Utf8View")) {
91
+ return "utf8-view";
92
+ }
93
+ if (isOptionalArrowType(arrowType, "LargeList")) {
94
+ const largeListType = arrowType;
95
+ return {
96
+ type: "large-list",
97
+ children: [serializeArrowField(largeListType.valueField)]
98
+ };
99
+ }
100
+ switch (arrowType.constructor) {
101
+ case arrow.Null:
102
+ return "null";
103
+ case arrow.Binary:
104
+ return "binary";
105
+ case arrow.FixedSizeBinary:
106
+ return {
107
+ type: "fixed-size-binary",
108
+ byteWidth: arrowType.byteWidth
109
+ };
110
+ case arrow.Bool:
111
+ return "bool";
112
+ case arrow.Int:
113
+ const intType = arrowType;
114
+ return `${intType.isSigned ? "" : "u"}int${intType.bitWidth}`;
115
+ case arrow.Int8:
116
+ return "int8";
117
+ case arrow.Int16:
118
+ return "int16";
119
+ case arrow.Int32:
120
+ return "int32";
121
+ case arrow.Int64:
122
+ return "int64";
123
+ case arrow.Uint8:
124
+ return "uint8";
125
+ case arrow.Uint16:
126
+ return "uint16";
127
+ case arrow.Uint32:
128
+ return "uint32";
129
+ case arrow.Uint64:
130
+ return "uint64";
131
+ case arrow.Float:
132
+ const precision = arrowType.precision;
133
+ switch (precision) {
134
+ case arrow.Precision.HALF:
135
+ return "float16";
136
+ case arrow.Precision.SINGLE:
137
+ return "float32";
138
+ case arrow.Precision.DOUBLE:
139
+ return "float64";
140
+ default:
141
+ return "float16";
142
+ }
143
+ case arrow.Float16:
144
+ return "float16";
145
+ case arrow.Float32:
146
+ return "float32";
147
+ case arrow.Float64:
148
+ return "float64";
149
+ case arrow.Utf8:
150
+ return "utf8";
151
+ case arrow.Decimal:
152
+ const decimal = arrowType;
153
+ return {
154
+ type: "decimal",
155
+ bitWidth: decimal.bitWidth,
156
+ precision: decimal.precision,
157
+ scale: decimal.scale
158
+ };
159
+ case arrow.Date_:
160
+ const dateUnit = arrowType.unit;
161
+ return dateUnit === arrow.DateUnit.DAY ? "date-day" : "date-millisecond";
162
+ case arrow.DateDay:
163
+ return "date-day";
164
+ case arrow.DateMillisecond:
165
+ return "date-millisecond";
166
+ case arrow.Time:
167
+ const timeUnit = arrowType.unit;
168
+ switch (timeUnit) {
169
+ case arrow.TimeUnit.SECOND:
170
+ return "time-second";
171
+ case arrow.TimeUnit.MILLISECOND:
172
+ return "time-millisecond";
173
+ case arrow.TimeUnit.MICROSECOND:
174
+ return "time-microsecond";
175
+ case arrow.TimeUnit.NANOSECOND:
176
+ return "time-nanosecond";
177
+ default:
178
+ return "time-second";
179
+ }
180
+ case arrow.TimeMillisecond:
181
+ return "time-millisecond";
182
+ case arrow.TimeSecond:
183
+ return "time-second";
184
+ case arrow.TimeMicrosecond:
185
+ return "time-microsecond";
186
+ case arrow.TimeNanosecond:
187
+ return "time-nanosecond";
188
+ case arrow.Timestamp:
189
+ const timeStampUnit = arrowType.unit;
190
+ switch (timeStampUnit) {
191
+ case arrow.TimeUnit.SECOND:
192
+ return "timestamp-second";
193
+ case arrow.TimeUnit.MILLISECOND:
194
+ return "timestamp-millisecond";
195
+ case arrow.TimeUnit.MICROSECOND:
196
+ return "timestamp-microsecond";
197
+ case arrow.TimeUnit.NANOSECOND:
198
+ return "timestamp-nanosecond";
199
+ default:
200
+ return "timestamp-second";
201
+ }
202
+ case arrow.TimestampSecond:
203
+ return "timestamp-second";
204
+ case arrow.TimestampMillisecond:
205
+ return "timestamp-millisecond";
206
+ case arrow.TimestampMicrosecond:
207
+ return "timestamp-microsecond";
208
+ case arrow.TimestampNanosecond:
209
+ return "timestamp-nanosecond";
210
+ case arrow.Interval:
211
+ const intervalUnit = arrowType.unit;
212
+ switch (intervalUnit) {
213
+ case arrow.IntervalUnit.DAY_TIME:
214
+ return "interval-daytime";
215
+ case arrow.IntervalUnit.YEAR_MONTH:
216
+ return "interval-yearmonth";
217
+ default:
218
+ return "interval-daytime";
219
+ }
220
+ case arrow.IntervalDayTime:
221
+ return "interval-daytime";
222
+ case arrow.IntervalYearMonth:
223
+ return "interval-yearmonth";
224
+ case arrow.Map_:
225
+ const mapType = arrowType;
226
+ return {
227
+ type: "map",
228
+ keysSorted: mapType.keysSorted,
229
+ children: mapType.children.map((arrowField) => serializeArrowField(arrowField))
230
+ };
231
+ case arrow.List:
232
+ const listType = arrowType;
233
+ const listField = listType.valueField;
234
+ return {
235
+ type: "list",
236
+ children: [serializeArrowField(listField)]
237
+ };
238
+ case arrow.FixedSizeList:
239
+ const fixedSizeList = arrowType;
240
+ return {
241
+ type: "fixed-size-list",
242
+ listSize: fixedSizeList.listSize,
243
+ children: [serializeArrowField(fixedSizeList.children[0])]
244
+ };
245
+ case arrow.Struct:
246
+ const structType = arrowType;
247
+ return {
248
+ type: "struct",
249
+ children: structType.children.map((arrowField) => serializeArrowField(arrowField))
250
+ };
251
+ case arrow.SparseUnion:
252
+ case arrow.DenseUnion:
253
+ const unionType = arrowType;
254
+ return {
255
+ type: unionType instanceof arrow.DenseUnion ? "dense-union" : "sparse-union",
256
+ typeIds: unionType.typeIds,
257
+ children: unionType.children.map((arrowField) => serializeArrowField(arrowField)),
258
+ typeIdToChildIndex: { ...unionType.typeIdToChildIndex }
259
+ };
260
+ case arrow.Dictionary:
261
+ const dictionaryType = arrowType;
262
+ return {
263
+ type: "dictionary",
264
+ id: dictionaryType.id,
265
+ indices: serializeArrowDictionaryKeyType(dictionaryType.indices),
266
+ dictionary: serializeArrowType(dictionaryType.dictionary),
267
+ isOrdered: dictionaryType.isOrdered
268
+ };
269
+ default:
270
+ throw new Error(`arrow type not supported: ${arrowType.constructor.name}`);
271
+ }
272
+ }
273
+ function getOptionalArrowConstructor(typeName) {
274
+ return arrow[typeName];
275
+ }
276
+ function isArrowViewType(arrowType, viewTypeName) {
277
+ const constructor = getOptionalArrowConstructor(viewTypeName);
278
+ if (constructor && arrowType instanceof constructor) {
279
+ return true;
280
+ }
281
+ const guards = arrow.DataType;
282
+ const guard = viewTypeName === "BinaryView" ? guards.isBinaryView : guards.isUtf8View;
283
+ return Boolean(guard == null ? void 0 : guard(arrowType));
284
+ }
285
+ function isOptionalArrowType(arrowType, typeName) {
286
+ const constructor = getOptionalArrowConstructor(typeName);
287
+ return Boolean(constructor && arrowType instanceof constructor);
288
+ }
289
+ function serializeArrowDictionaryKeyType(arrowType) {
290
+ if (arrowType instanceof arrow.Int) {
291
+ const prefix = arrowType.isSigned ? "int" : "uint";
292
+ const keyType = `${prefix}${arrowType.bitWidth}`;
293
+ if (isSchemaDictionaryKeyType(keyType)) {
294
+ return keyType;
295
+ }
296
+ }
297
+ switch (arrowType.constructor) {
298
+ case arrow.Int8:
299
+ return "int8";
300
+ case arrow.Int16:
301
+ return "int16";
302
+ case arrow.Int32:
303
+ return "int32";
304
+ case arrow.Uint8:
305
+ return "uint8";
306
+ case arrow.Uint16:
307
+ return "uint16";
308
+ case arrow.Uint32:
309
+ return "uint32";
310
+ default:
311
+ throw new Error(`arrow dictionary index type not supported: ${arrowType.constructor.name}`);
312
+ }
313
+ }
314
+ function isSchemaDictionaryKeyType(keyType) {
315
+ return ["int8", "int16", "int32", "uint8", "uint16", "uint32"].includes(keyType);
316
+ }
317
+ var arrow;
318
+ var init_convert_arrow_schema = __esm({
319
+ "../core/src/schema-utils/lib/schema/convert-arrow-schema.ts"() {
320
+ "use strict";
321
+ arrow = __toESM(require("apache-arrow"), 1);
322
+ }
323
+ });
324
+
325
+ // ../core/src/schema-utils/index.ts
326
+ var init_schema_utils = __esm({
327
+ "../core/src/schema-utils/index.ts"() {
328
+ "use strict";
329
+ init_convert_arrow_schema();
330
+ }
331
+ });
332
+
333
+ // src/lib/build-graph-tables.ts
334
+ function buildGraphTables(nodes, edges, shape, declarations) {
335
+ if (shape === "plain-graph-data") {
336
+ return { shape, nodes: Array.from(nodes), edges: Array.from(edges) };
337
+ }
338
+ if (shape !== "arrow-table" && shape !== "object-row-table") {
339
+ throw new Error(`Unsupported graph shape: ${shape}`);
340
+ }
341
+ const nodeTable = buildGraphTable(nodes, false, shape, declarations == null ? void 0 : declarations.nodes);
342
+ const edgeTable = buildGraphTable(edges, true, shape, declarations == null ? void 0 : declarations.edges);
343
+ return {
344
+ shape: "tables",
345
+ tables: [
346
+ { name: "nodes", table: nodeTable },
347
+ { name: "edges", table: edgeTable }
348
+ ]
349
+ };
350
+ }
351
+ function buildGraphTable(records, isEdge, shape, declarations) {
352
+ const columnNames = isEdge ? ["id", "sourceId", "targetId", "directed", "label", "attributes"] : ["id", "label", "attributes"];
353
+ const columns = new Map(columnNames.map((name) => [name, []]));
354
+ for (const record of records) {
355
+ for (const name of columnNames) {
356
+ const value = record[name];
357
+ columns.get(name).push(
358
+ name === "id" || name === "sourceId" || name === "targetId" ? String(value) : value ?? null
359
+ );
360
+ }
361
+ }
362
+ if (shape === "object-row-table") {
363
+ return {
364
+ shape,
365
+ data: columns.get("id").map(
366
+ (_, index) => Object.fromEntries(columnNames.map((name) => [name, columns.get(name)[index]]))
367
+ )
368
+ };
369
+ }
370
+ const vectors = /* @__PURE__ */ Object.create(null);
371
+ for (const [name, values] of columns) {
372
+ const type = name === "attributes" ? inferAttributeType(values, declarations) : name === "directed" ? new import_apache_arrow.Bool() : new import_apache_arrow.Utf8();
373
+ vectors[name] = (0, import_apache_arrow.vectorFromArray)(
374
+ values.map((value) => normalizeValue(value, type)),
375
+ type
376
+ );
377
+ }
378
+ const data = new import_apache_arrow.Table(vectors);
379
+ return { shape, schema: convertArrowToSchema(data.schema), data };
380
+ }
381
+ function inferAttributeType(values, declarations) {
382
+ const names = new Set(declarations == null ? void 0 : declarations.keys());
383
+ for (const value of values) {
384
+ if (value && typeof value === "object") {
385
+ for (const name of Object.keys(value)) {
386
+ names.add(name);
387
+ }
388
+ }
389
+ }
390
+ return new import_apache_arrow.Struct(
391
+ Array.from(names, (name) => {
392
+ const fieldValues = values.map(
393
+ (value) => (value == null ? void 0 : value[name]) ?? null
394
+ );
395
+ return new import_apache_arrow.Field(name, inferValueType(fieldValues, declarations == null ? void 0 : declarations.get(name)), true);
396
+ })
397
+ );
398
+ }
399
+ function inferValueType(values, declaration) {
400
+ const present = values.filter((value) => value !== null && value !== void 0);
401
+ if (declaration && typeof declaration === "object") {
402
+ if (!present.every((value) => Array.isArray(value))) return new import_apache_arrow.Utf8();
403
+ return new import_apache_arrow.List(
404
+ new import_apache_arrow.Field(
405
+ "item",
406
+ inferValueType(
407
+ present.flatMap((value) => value),
408
+ declaration.list
409
+ ),
410
+ true
411
+ )
412
+ );
413
+ }
414
+ if (declaration) {
415
+ const declaredTypes = {
416
+ boolean: new import_apache_arrow.Bool(),
417
+ int: new import_apache_arrow.Int32(),
418
+ long: new import_apache_arrow.Int64(),
419
+ float: new import_apache_arrow.Float32(),
420
+ double: new import_apache_arrow.Float64(),
421
+ string: new import_apache_arrow.Utf8()
422
+ };
423
+ const valid = present.every((value) => {
424
+ switch (declaration) {
425
+ case "boolean":
426
+ return typeof value === "boolean";
427
+ case "int":
428
+ return typeof value === "number" && Number.isInteger(value) && value >= -2147483648 && value <= 2147483647;
429
+ case "long":
430
+ return typeof value === "bigint" && value >= -(2n ** 63n) && value < 2n ** 63n;
431
+ case "float":
432
+ case "double":
433
+ return typeof value === "number";
434
+ case "string":
435
+ return typeof value === "string";
436
+ }
437
+ });
438
+ return valid ? declaredTypes[declaration] : new import_apache_arrow.Utf8();
439
+ }
440
+ if (present.length && present.every((value) => typeof value === "boolean")) return new import_apache_arrow.Bool();
441
+ if (present.length && present.every((value) => typeof value === "number")) return new import_apache_arrow.Float64();
442
+ if (present.length && present.every((value) => Array.isArray(value))) {
443
+ return new import_apache_arrow.List(
444
+ new import_apache_arrow.Field("item", inferValueType(present.flatMap((value) => value)), true)
445
+ );
446
+ }
447
+ if (present.length && present.every((value) => typeof value === "object" && !Array.isArray(value))) {
448
+ return inferAttributeType(present);
449
+ }
450
+ return new import_apache_arrow.Utf8();
451
+ }
452
+ function normalizeValue(value, type) {
453
+ if (value === null || value === void 0) return null;
454
+ if (type instanceof import_apache_arrow.Struct) {
455
+ return Object.fromEntries(
456
+ type.children.map((field) => [
457
+ field.name,
458
+ normalizeValue(value[field.name], field.type)
459
+ ])
460
+ );
461
+ }
462
+ if (type instanceof import_apache_arrow.List)
463
+ return value.map((item) => normalizeValue(item, type.valueType));
464
+ if (type instanceof import_apache_arrow.Utf8 && typeof value !== "string") {
465
+ return typeof value === "object" ? JSON.stringify(value) : String(value);
466
+ }
467
+ return value;
468
+ }
469
+ var import_apache_arrow;
470
+ var init_build_graph_tables = __esm({
471
+ "src/lib/build-graph-tables.ts"() {
472
+ "use strict";
473
+ import_apache_arrow = require("apache-arrow");
474
+ init_schema_utils();
475
+ }
476
+ });
477
+
55
478
  // src/lib/parse-graphml.ts
56
- function parseGraphML(graphml) {
479
+ function parseGraphML(graphml, shape = "plain-graph-data") {
57
480
  const xmlText = decodeGraphML(graphml);
58
481
  const document = graphmlParser.parse(xmlText);
59
482
  const graphmlRoot = getGraphMLRoot(document);
@@ -64,19 +487,38 @@ function parseGraphML(graphml) {
64
487
  if (!graphElement) {
65
488
  throw new Error("GraphML document does not contain a <graph> element.");
66
489
  }
67
- const keyDefinitions = collectKeyDefinitions(graphmlRoot, graphElement);
490
+ const keyDefinitions = collectKeyDefinitions(
491
+ graphmlRoot,
492
+ graphElement,
493
+ shape !== "plain-graph-data"
494
+ );
68
495
  const defaultDirected = parseEdgeDefault(graphElement[`${XML_ATTRIBUTE_PREFIX}edgedefault`]);
69
- const nodes = normalizeArray(graphElement.node).map((node) => parseNode(node, keyDefinitions));
70
- const edges = normalizeArray(graphElement.edge).map(
71
- (edge, index) => parseEdge(edge, index, keyDefinitions, defaultDirected)
496
+ const declarations = { nodes: /* @__PURE__ */ new Map(), edges: /* @__PURE__ */ new Map() };
497
+ for (const definition of keyDefinitions.values()) {
498
+ if (definition.domain === "all" || definition.domain === "node")
499
+ declarations.nodes.set(definition.name, definition.type);
500
+ if (definition.domain === "all" || definition.domain === "edge")
501
+ declarations.edges.set(definition.name, definition.type);
502
+ }
503
+ return buildGraphTables(
504
+ iterateNodes(graphElement.node, keyDefinitions),
505
+ iterateEdges(graphElement.edge, keyDefinitions, defaultDirected),
506
+ shape,
507
+ declarations
72
508
  );
73
- const filteredNodes = nodes.filter((node) => Boolean(node));
74
- const filteredEdges = edges.filter((edge) => Boolean(edge));
75
- return {
76
- shape: "plain-graph-data",
77
- nodes: filteredNodes,
78
- edges: filteredEdges
79
- };
509
+ }
510
+ function* iterateNodes(nodes, definitions) {
511
+ for (const node of normalizeArray(nodes)) {
512
+ const record = parseNode(node, definitions);
513
+ if (record) yield record;
514
+ }
515
+ }
516
+ function* iterateEdges(edges, definitions, directed) {
517
+ let index = 0;
518
+ for (const edge of normalizeArray(edges)) {
519
+ const record = parseEdge(edge, index++, definitions, directed);
520
+ if (record) yield record;
521
+ }
80
522
  }
81
523
  function decodeGraphML(graphml) {
82
524
  if (typeof graphml === "string") {
@@ -99,16 +541,21 @@ function getGraphMLRoot(document) {
99
541
  }
100
542
  function getGraphElement(graphmlRoot) {
101
543
  const graph = graphmlRoot.graph;
544
+ if (typeof graph === "string" && !graph.trim()) {
545
+ return {};
546
+ }
102
547
  if (!graph) {
103
548
  return null;
104
549
  }
105
550
  if (Array.isArray(graph)) {
106
- const firstGraph = graph.find((entry) => isObject(entry));
107
- return isObject(firstGraph) ? firstGraph : null;
551
+ const firstGraph = graph.find(
552
+ (entry) => isObject(entry) || typeof entry === "string" && !entry.trim()
553
+ );
554
+ return isObject(firstGraph) ? firstGraph : typeof firstGraph === "string" ? {} : null;
108
555
  }
109
556
  return isObject(graph) ? graph : null;
110
557
  }
111
- function collectKeyDefinitions(graphmlRoot, graphElement) {
558
+ function collectKeyDefinitions(graphmlRoot, graphElement, lossless) {
112
559
  const keys = /* @__PURE__ */ new Map();
113
560
  for (const candidate of [
114
561
  ...normalizeArray(graphmlRoot.key),
@@ -121,8 +568,8 @@ function collectKeyDefinitions(graphmlRoot, graphElement) {
121
568
  const name = String(candidate[`${XML_ATTRIBUTE_PREFIX}attr.name`] ?? id).trim();
122
569
  const type = normalizeType(candidate[`${XML_ATTRIBUTE_PREFIX}attr.type`]);
123
570
  const defaultNode = candidate.default ?? null;
124
- const defaultValue = defaultNode !== null ? castDataValue(defaultNode, type) : void 0;
125
- keys.set(id, { id, domain, name, type, defaultValue });
571
+ const defaultValue = defaultNode !== null ? castDataValue(defaultNode, type, lossless) : void 0;
572
+ keys.set(id, { id, domain, name, type, defaultValue, lossless });
126
573
  }
127
574
  }
128
575
  }
@@ -200,12 +647,12 @@ function assignAttributeFromDataEntry(entry, keyDefinitions, attributes) {
200
647
  }
201
648
  const definition = keyDefinitions.get(keyId);
202
649
  const attributeName = (definition == null ? void 0 : definition.name) ?? keyId;
203
- const value = castDataValue(entry, (definition == null ? void 0 : definition.type) ?? "string");
650
+ const value = (definition == null ? void 0 : definition.type) === "boolean" && extractTextContent(entry) === void 0 ? false : castDataValue(entry, (definition == null ? void 0 : definition.type) ?? "string", definition == null ? void 0 : definition.lossless);
204
651
  if (value !== void 0) {
205
652
  attributes[attributeName] = value;
206
653
  }
207
654
  }
208
- function castDataValue(value, type) {
655
+ function castDataValue(value, type, lossless = false) {
209
656
  if (value === null || typeof value === "undefined") {
210
657
  return void 0;
211
658
  }
@@ -216,6 +663,9 @@ function castDataValue(value, type) {
216
663
  if (type === "boolean") {
217
664
  return parseBoolean(text);
218
665
  }
666
+ if (type === "long" && lossless) {
667
+ return /^[+-]?\d+$/.test(text.trim()) ? BigInt(text.trim()) : text;
668
+ }
219
669
  if (type === "int" || type === "long") {
220
670
  const parsed = Number.parseInt(text, 10);
221
671
  return Number.isNaN(parsed) ? text : parsed;
@@ -238,14 +688,14 @@ function extractTextContent(value) {
238
688
  }
239
689
  if (isObject(value)) {
240
690
  const text = value[XML_TEXT_KEY];
241
- if (typeof text === "string") {
242
- return text;
243
- }
244
691
  const nonAttributeEntries = Object.entries(value).filter(
245
- ([key]) => !key.startsWith(XML_ATTRIBUTE_PREFIX)
692
+ ([key]) => !key.startsWith(XML_ATTRIBUTE_PREFIX) && key !== XML_TEXT_KEY
246
693
  );
247
694
  if (nonAttributeEntries.length === 0) {
248
- return void 0;
695
+ return typeof text === "string" ? text : void 0;
696
+ }
697
+ if (typeof text === "string" && text.trim()) {
698
+ nonAttributeEntries.push([XML_TEXT_KEY, text]);
249
699
  }
250
700
  return JSON.stringify(Object.fromEntries(nonAttributeEntries));
251
701
  }
@@ -306,20 +756,21 @@ function parseBoolean(value) {
306
756
  if (normalized === "false" || normalized === "0" || normalized === "no" || normalized === "n") {
307
757
  return false;
308
758
  }
309
- return Boolean(value);
759
+ return Boolean(normalized);
310
760
  }
311
761
  var import_fast_xml_parser, XML_ATTRIBUTE_PREFIX, XML_TEXT_KEY, graphmlParser;
312
762
  var init_parse_graphml = __esm({
313
763
  "src/lib/parse-graphml.ts"() {
314
764
  "use strict";
315
765
  import_fast_xml_parser = require("fast-xml-parser");
766
+ init_build_graph_tables();
316
767
  XML_ATTRIBUTE_PREFIX = "@_";
317
768
  XML_TEXT_KEY = "#text";
318
769
  graphmlParser = new import_fast_xml_parser.XMLParser({
319
770
  ignoreAttributes: false,
320
771
  attributeNamePrefix: XML_ATTRIBUTE_PREFIX,
321
772
  textNodeName: XML_TEXT_KEY,
322
- trimValues: true,
773
+ trimValues: false,
323
774
  parseAttributeValue: false,
324
775
  parseTagValue: false,
325
776
  removeNSPrefix: true
@@ -340,9 +791,18 @@ var init_graphml_loader = __esm({
340
791
  init_parse_graphml();
341
792
  GraphMLLoaderWithParser = {
342
793
  ...GraphMLLoader,
343
- parse: async (data) => parseGraphML(data),
344
- parseSync: parseGraphML,
345
- parseTextSync: parseGraphML
794
+ parse: async (data, options) => {
795
+ var _a;
796
+ return parseGraphML(data, ((_a = options == null ? void 0 : options.graphml) == null ? void 0 : _a.shape) ?? "arrow-table");
797
+ },
798
+ parseSync: (data, options) => {
799
+ var _a;
800
+ return parseGraphML(data, ((_a = options == null ? void 0 : options.graphml) == null ? void 0 : _a.shape) ?? "arrow-table");
801
+ },
802
+ parseTextSync: (data, options) => {
803
+ var _a;
804
+ return parseGraphML(data, ((_a = options == null ? void 0 : options.graphml) == null ? void 0 : _a.shape) ?? "arrow-table");
805
+ }
346
806
  };
347
807
  }
348
808
  });
@@ -368,30 +828,44 @@ var init_dot_loader_types = __esm({
368
828
  worker: false,
369
829
  dataType: null,
370
830
  batchType: null,
371
- options: {},
831
+ options: { dot: { shape: "arrow-table" } },
372
832
  preload: preload3
373
833
  };
374
834
  }
375
835
  });
376
836
 
377
837
  // src/lib/parse-dot.ts
378
- function parseDOT(input) {
838
+ function parseDOT(input, shape = "plain-graph-data") {
379
839
  const parsed = parseDOTDocument(input);
380
- const subgraphs = Array.from(parsed.subgraphs.values(), (subgraph) => ({
381
- ...subgraph,
382
- attributes: { ...subgraph.attributes }
383
- }));
384
840
  return {
385
- shape: "plain-graph-data",
386
- nodes: Array.from(parsed.nodes.values(), (node) => ({
841
+ ...buildGraphTables(iterateNodes2(parsed), iterateEdges2(parsed), shape),
842
+ metadata: {
843
+ id: parsed.id,
844
+ directed: parsed.directed,
845
+ strict: parsed.strict,
846
+ attributes: { ...parsed.graphAttributes },
847
+ subgraphs: Array.from(parsed.subgraphs.values(), (subgraph) => ({
848
+ ...subgraph,
849
+ attributes: { ...subgraph.attributes }
850
+ }))
851
+ }
852
+ };
853
+ }
854
+ function* iterateNodes2(parsed) {
855
+ for (const node of parsed.nodes.values()) {
856
+ yield {
387
857
  id: node.id,
388
858
  ...typeof node.attributes.label === "string" ? { label: node.attributes.label } : {},
389
859
  attributes: {
390
860
  ...node.attributes,
391
861
  ...node.subgraphs.size ? { subgraphs: Array.from(node.subgraphs, (id) => describeSubgraph(id, parsed.subgraphs)) } : {}
392
862
  }
393
- })),
394
- edges: parsed.edges.map((edge) => ({
863
+ };
864
+ }
865
+ }
866
+ function* iterateEdges2(parsed) {
867
+ for (const edge of parsed.edges) {
868
+ yield {
395
869
  id: edge.id,
396
870
  sourceId: edge.sourceId,
397
871
  targetId: edge.targetId,
@@ -401,15 +875,8 @@ function parseDOT(input) {
401
875
  ...edge.attributes,
402
876
  ...edge.subgraphs.length ? { subgraphs: edge.subgraphs.map((id) => describeSubgraph(id, parsed.subgraphs)) } : {}
403
877
  }
404
- })),
405
- metadata: {
406
- id: parsed.id,
407
- directed: parsed.directed,
408
- strict: parsed.strict,
409
- attributes: { ...parsed.graphAttributes },
410
- subgraphs
411
- }
412
- };
878
+ };
879
+ }
413
880
  }
414
881
  function describeSubgraph(id, descriptors) {
415
882
  const subgraph = descriptors.get(id);
@@ -420,8 +887,8 @@ function describeSubgraph(id, descriptors) {
420
887
  };
421
888
  }
422
889
  function parseDOTDocument(input) {
423
- const parser = new DOTParser(tokenize(input));
424
- return parser.parse();
890
+ const parser2 = new DOTParser(tokenize(input));
891
+ return parser2.parse();
425
892
  }
426
893
  function tokenize(input) {
427
894
  const tokens = [];
@@ -561,6 +1028,10 @@ function readQuotedString(input, startIndex) {
561
1028
  function readEscapedCharacter(input, startIndex) {
562
1029
  const next = input[startIndex];
563
1030
  switch (next) {
1031
+ case "\n":
1032
+ return { value: "", nextIndex: startIndex + 1 };
1033
+ case "\r":
1034
+ return { value: "", nextIndex: startIndex + (input[startIndex + 1] === "\n" ? 2 : 1) };
564
1035
  case "n":
565
1036
  case "l":
566
1037
  case "L":
@@ -577,7 +1048,7 @@ function readEscapedCharacter(input, startIndex) {
577
1048
  if (typeof next === "undefined") {
578
1049
  throw new Error("Unterminated escape sequence in DOT source.");
579
1050
  }
580
- return { value: next, nextIndex: startIndex + 1 };
1051
+ return { value: `\\${next}`, nextIndex: startIndex + 1 };
581
1052
  }
582
1053
  }
583
1054
  }
@@ -696,6 +1167,7 @@ var DOTParser, IDENTIFIER_TERMINATORS;
696
1167
  var init_parse_dot = __esm({
697
1168
  "src/lib/parse-dot.ts"() {
698
1169
  "use strict";
1170
+ init_build_graph_tables();
699
1171
  DOTParser = class {
700
1172
  /** Tokens for DOT parsing. */
701
1173
  tokens;
@@ -899,6 +1371,10 @@ var init_parse_dot = __esm({
899
1371
  const existingEdge = this.result.strict ? this.strictEdges.get(strictKey) : void 0;
900
1372
  if (existingEdge) {
901
1373
  existingEdge.attributes = { ...existingEdge.attributes, ...explicitAttributes };
1374
+ const explicitId = explicitAttributes.id ?? explicitAttributes.Id ?? explicitAttributes.ID;
1375
+ if (typeof explicitId === "string" || typeof explicitId === "number") {
1376
+ existingEdge.id = String(explicitId);
1377
+ }
902
1378
  existingEdge.directed = deriveDirectedFlag(existingEdge.attributes, directed);
903
1379
  existingEdge.subgraphs = Array.from(/* @__PURE__ */ new Set([...existingEdge.subgraphs, ...membership]));
904
1380
  continue;
@@ -1077,9 +1553,379 @@ var init_dot_loader = __esm({
1077
1553
  init_parse_dot();
1078
1554
  DOTLoaderWithParser = {
1079
1555
  ...DOTLoader,
1080
- parse: async (data) => parseDOT(new TextDecoder().decode(data)),
1081
- parseSync: (data) => parseDOT(new TextDecoder().decode(data)),
1082
- parseTextSync: parseDOT
1556
+ parse: async (data, options) => {
1557
+ var _a;
1558
+ return parseDOT(new TextDecoder().decode(data), ((_a = options == null ? void 0 : options.dot) == null ? void 0 : _a.shape) ?? "arrow-table");
1559
+ },
1560
+ parseSync: (data, options) => {
1561
+ var _a;
1562
+ return parseDOT(new TextDecoder().decode(data), ((_a = options == null ? void 0 : options.dot) == null ? void 0 : _a.shape) ?? "arrow-table");
1563
+ },
1564
+ parseTextSync: (data, options) => {
1565
+ var _a;
1566
+ return parseDOT(data, ((_a = options == null ? void 0 : options.dot) == null ? void 0 : _a.shape) ?? "arrow-table");
1567
+ }
1568
+ };
1569
+ }
1570
+ });
1571
+
1572
+ // src/gexf-loader-types.ts
1573
+ async function preload5() {
1574
+ const { GEXFLoaderWithParser: GEXFLoaderWithParser2 } = await Promise.resolve().then(() => (init_gexf_loader(), gexf_loader_exports));
1575
+ return GEXFLoaderWithParser2;
1576
+ }
1577
+ var VERSION5, GEXFLoader;
1578
+ var init_gexf_loader_types = __esm({
1579
+ "src/gexf-loader-types.ts"() {
1580
+ "use strict";
1581
+ VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1582
+ GEXFLoader = {
1583
+ name: "GEXF",
1584
+ id: "gexf",
1585
+ module: "graphs",
1586
+ version: VERSION5,
1587
+ extensions: ["gexf"],
1588
+ mimeTypes: ["application/gexf+xml"],
1589
+ text: true,
1590
+ worker: false,
1591
+ dataType: null,
1592
+ batchType: null,
1593
+ options: { gexf: { shape: "arrow-table" } },
1594
+ preload: preload5
1595
+ };
1596
+ }
1597
+ });
1598
+
1599
+ // src/lib/parse-gexf.ts
1600
+ function parseGEXF(input, shape = "arrow-table") {
1601
+ const text = typeof input === "string" ? input : new TextDecoder().decode(input);
1602
+ const validation = import_fast_xml_parser2.XMLValidator.validate(text);
1603
+ if (validation !== true) throw new Error(`Invalid GEXF XML: ${validation.err.msg}`);
1604
+ if (/<!DOCTYPE\s/i.test(text)) throw new Error("GEXF document types are unsupported.");
1605
+ const document = normalizeNamespaces(parser.parse(text), {});
1606
+ const root = getElement(document.gexf, "gexf");
1607
+ const version = root["@_version"];
1608
+ if (version && !["1.2", "1.2draft", "1.3"].includes(version)) {
1609
+ throw new Error(`Unsupported GEXF version: ${version}`);
1610
+ }
1611
+ const graph = getElement(root.graph, "graph");
1612
+ const directed = parseDirection(graph["@_defaultedgetype"] ?? "undirected");
1613
+ const definitions = {
1614
+ nodes: /* @__PURE__ */ new Map(),
1615
+ edges: /* @__PURE__ */ new Map()
1616
+ };
1617
+ for (const attributes of getElements(graph.attributes)) {
1618
+ const domain = attributes["@_class"];
1619
+ if (domain !== "node" && domain !== "edge")
1620
+ throw new Error("GEXF attributes require a node or edge class.");
1621
+ const scoped = domain === "node" ? definitions.nodes : definitions.edges;
1622
+ const names = new Set(Array.from(scoped.values(), (definition) => definition.name));
1623
+ for (const attribute of getElements(attributes.attribute)) {
1624
+ const identifier = requireAttribute(attribute, "id");
1625
+ const name = requireAttribute(attribute, "title");
1626
+ if (name === "gexf" || names.has(name) || scoped.has(identifier)) {
1627
+ throw new Error(`Duplicate or reserved GEXF attribute: ${name}`);
1628
+ }
1629
+ names.add(name);
1630
+ const type = parseAttributeType(requireAttribute(attribute, "type"));
1631
+ scoped.set(identifier, {
1632
+ name,
1633
+ type,
1634
+ defaultValue: attribute.default === void 0 ? void 0 : castValue(readTextContent(attribute.default), type)
1635
+ });
1636
+ }
1637
+ }
1638
+ const nodeElements = getElements(getContainer(graph.nodes).node);
1639
+ const edgeElements = getElements(getContainer(graph.edges).edge);
1640
+ const nodeIdentifiers = /* @__PURE__ */ new Set();
1641
+ for (const node of nodeElements) {
1642
+ const identifier = requireAttribute(node, "id");
1643
+ if (nodeIdentifiers.has(identifier)) throw new Error(`Duplicate GEXF node ID: ${identifier}`);
1644
+ nodeIdentifiers.add(identifier);
1645
+ }
1646
+ const edgeIdentifiers = new Set(
1647
+ edgeElements.map((edge) => edge["@_id"]).filter((identifier) => typeof identifier === "string")
1648
+ );
1649
+ const seenEdges = /* @__PURE__ */ new Set();
1650
+ function* iterateNodes3() {
1651
+ for (const node of nodeElements) yield parseRecord(node, definitions.nodes);
1652
+ }
1653
+ function* iterateEdges3() {
1654
+ for (const [index, edge] of edgeElements.entries()) {
1655
+ const sourceId = requireAttribute(edge, "source");
1656
+ const targetId = requireAttribute(edge, "target");
1657
+ if (!nodeIdentifiers.has(sourceId) || !nodeIdentifiers.has(targetId)) {
1658
+ throw new Error("GEXF edge references an undeclared node.");
1659
+ }
1660
+ let identifier = edge["@_id"] === void 0 ? void 0 : requireAttribute(edge, "id");
1661
+ if (identifier === void 0) {
1662
+ identifier = `edge-${index}`;
1663
+ while (edgeIdentifiers.has(identifier)) identifier = `_${identifier}`;
1664
+ edgeIdentifiers.add(identifier);
1665
+ }
1666
+ if (seenEdges.has(identifier)) throw new Error(`Duplicate GEXF edge ID: ${identifier}`);
1667
+ seenEdges.add(identifier);
1668
+ yield {
1669
+ ...parseRecord(edge, definitions.edges, identifier),
1670
+ sourceId,
1671
+ targetId,
1672
+ directed: edge["@_type"] === void 0 ? directed : parseDirection(edge["@_type"])
1673
+ };
1674
+ }
1675
+ }
1676
+ const metadataAttributes = /* @__PURE__ */ Object.create(null);
1677
+ const meta = getContainer(root.meta);
1678
+ for (const name of ["creator", "description", "keywords"]) {
1679
+ if (meta[name] !== void 0) metadataAttributes[name] = readTextContent(meta[name]);
1680
+ }
1681
+ if (typeof meta["@_lastmodifieddate"] === "string")
1682
+ metadataAttributes.lastmodifieddate = meta["@_lastmodifieddate"];
1683
+ const declarations = {
1684
+ nodes: new Map(
1685
+ Array.from(definitions.nodes.values(), (definition) => [definition.name, definition.type])
1686
+ ),
1687
+ edges: new Map(
1688
+ Array.from(definitions.edges.values(), (definition) => [definition.name, definition.type])
1689
+ )
1690
+ };
1691
+ return {
1692
+ ...buildGraphTables(iterateNodes3(), iterateEdges3(), shape, declarations),
1693
+ metadata: { version, directed, attributes: metadataAttributes }
1694
+ };
1695
+ }
1696
+ function normalizeNamespaces(element, inherited) {
1697
+ const namespaces = Object.assign(/* @__PURE__ */ Object.create(null), inherited);
1698
+ for (const [name, value] of Object.entries(element)) {
1699
+ if (name === "@_xmlns") namespaces[""] = String(value);
1700
+ else if (name.startsWith("@_xmlns:")) namespaces[name.slice(8)] = String(value);
1701
+ }
1702
+ const normalized = /* @__PURE__ */ Object.create(null);
1703
+ for (const [name, value] of Object.entries(element)) {
1704
+ if (name.startsWith("@_") || name === "#text" || name.startsWith("?")) {
1705
+ normalized[name] = value;
1706
+ continue;
1707
+ }
1708
+ const separator = name.indexOf(":");
1709
+ const prefix = separator < 0 ? "" : name.slice(0, separator);
1710
+ const localName = name.slice(separator + 1);
1711
+ const children = Array.isArray(value) ? value : [value];
1712
+ for (const child of children) {
1713
+ const object = typeof child === "object" && child !== null ? child : {};
1714
+ const namespace = object[prefix ? `@_xmlns:${prefix}` : "@_xmlns"] ?? namespaces[prefix];
1715
+ const match = typeof namespace === "string" ? GEXF_NAMESPACE.exec(namespace) : null;
1716
+ const key = match ? `${match[1] ? "viz:" : ""}${localName}` : namespace || prefix ? `foreign:${name}` : localName;
1717
+ const childValue = typeof child === "object" && child !== null ? match || !namespace && !prefix ? normalizeNamespaces(object, namespaces) : object : child;
1718
+ if (normalized[key] === void 0) normalized[key] = childValue;
1719
+ else
1720
+ normalized[key] = [
1721
+ ...Array.isArray(normalized[key]) ? normalized[key] : [normalized[key]],
1722
+ childValue
1723
+ ];
1724
+ }
1725
+ }
1726
+ assertStaticElement(normalized);
1727
+ return normalized;
1728
+ }
1729
+ function assertStaticElement(element) {
1730
+ if (element["@_mode"] !== void 0 && element["@_mode"] !== "static" || TEMPORAL_ATTRIBUTES.some((name) => element[`@_${name}`] !== void 0) || element.spells !== void 0) {
1731
+ throw new Error("Dynamic GEXF graphs and temporal values are unsupported.");
1732
+ }
1733
+ if (element["@_pid"] !== void 0 || element.parents !== void 0 || element["@_id"] !== void 0 && (element.nodes !== void 0 || element.edges !== void 0)) {
1734
+ throw new Error("Hierarchical GEXF graphs are unsupported.");
1735
+ }
1736
+ }
1737
+ function getElement(value, name) {
1738
+ if (value === "") return {};
1739
+ if (value && typeof value === "object" && !Array.isArray(value)) return value;
1740
+ throw new Error(`GEXF requires one <${name}> element.`);
1741
+ }
1742
+ function readTextContent(value) {
1743
+ if (typeof value === "string") return value;
1744
+ const text = getElement(value, "text")["#text"];
1745
+ return typeof text === "string" ? text : "";
1746
+ }
1747
+ function getContainer(value) {
1748
+ return value === void 0 ? {} : getElement(value, "container");
1749
+ }
1750
+ function getElements(value) {
1751
+ if (value === void 0) return [];
1752
+ return (Array.isArray(value) ? value : [value]).map((entry) => getElement(entry, "record"));
1753
+ }
1754
+ function requireAttribute(element, name) {
1755
+ const value = element[`@_${name}`];
1756
+ if (typeof value !== "string" || value === "")
1757
+ throw new Error(`GEXF requires a ${name} attribute.`);
1758
+ return value;
1759
+ }
1760
+ function parseDirection(value) {
1761
+ if (value !== "directed" && value !== "undirected")
1762
+ throw new Error(`Unsupported GEXF edge type: ${String(value)}`);
1763
+ return value === "directed";
1764
+ }
1765
+ function parseAttributeType(value) {
1766
+ if (value.startsWith("list") && !value.slice(4).startsWith("list")) {
1767
+ return { list: parseAttributeType(value.slice(4)) };
1768
+ }
1769
+ if (value === "integer" || value === "byte" || value === "short") return "int";
1770
+ if (value === "boolean" || value === "long" || value === "float" || value === "double")
1771
+ return value;
1772
+ if (["string", "anyURI", "date", "char", "bigdecimal", "biginteger"].includes(value))
1773
+ return "string";
1774
+ throw new Error(`Unsupported GEXF attribute type: ${value}`);
1775
+ }
1776
+ function castValue(text, type) {
1777
+ if (typeof type === "object") {
1778
+ return parseListValues(text).map((value) => castValue(value, type.list));
1779
+ }
1780
+ if (type === "string") return text;
1781
+ const trimmed = text.trim();
1782
+ if (type === "boolean") {
1783
+ if (trimmed === "true" || trimmed === "1") return true;
1784
+ if (trimmed === "false" || trimmed === "0") return false;
1785
+ return text;
1786
+ }
1787
+ if (type === "int" || type === "long") {
1788
+ if (!/^[+-]?\d+$/.test(trimmed)) return text;
1789
+ return type === "long" ? BigInt(trimmed) : Number.isSafeInteger(Number(trimmed)) ? Number(trimmed) : text;
1790
+ }
1791
+ if (trimmed === "INF") return Infinity;
1792
+ if (trimmed === "-INF") return -Infinity;
1793
+ if (trimmed === "NaN") return NaN;
1794
+ if (!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(trimmed)) return text;
1795
+ const number = Number(trimmed);
1796
+ const represented = type === "float" ? Math.fround(number) : number;
1797
+ const nonzero = /[1-9]/.test(trimmed.split(/[eE]/)[0]);
1798
+ return Number.isFinite(represented) && (represented !== 0 || !nonzero) ? number : text;
1799
+ }
1800
+ function parseListValues(text) {
1801
+ const trimmed = text.trim();
1802
+ const bracketed = trimmed.startsWith("[");
1803
+ if (bracketed !== trimmed.endsWith("]")) throw new Error("Invalid GEXF list brackets.");
1804
+ const contents = bracketed ? trimmed.slice(1, -1) : trimmed;
1805
+ if (!contents.trim()) return [];
1806
+ const values = [];
1807
+ let value = "";
1808
+ let quote = "";
1809
+ let quoted = false;
1810
+ let closed = false;
1811
+ for (let index = 0; index < contents.length; index++) {
1812
+ const character = contents[index];
1813
+ if (quote) {
1814
+ if (character === "\\" && (contents[index + 1] === quote || contents[index + 1] === "\\")) {
1815
+ value += contents[++index];
1816
+ } else if (character === quote) {
1817
+ quote = "";
1818
+ closed = true;
1819
+ } else value += character;
1820
+ } else if (character === "," || !bracketed && (character === "|" || character === ";")) {
1821
+ values.push(quoted ? value : value.trim());
1822
+ value = "";
1823
+ quoted = false;
1824
+ closed = false;
1825
+ } else if (closed) {
1826
+ if (character.trim()) throw new Error("Invalid GEXF list text after a quote.");
1827
+ } else if ((character === "'" || character === '"') && !value.trim()) {
1828
+ quote = character;
1829
+ quoted = true;
1830
+ value = "";
1831
+ } else value += character;
1832
+ }
1833
+ if (quote) throw new Error("Unterminated GEXF list quote.");
1834
+ values.push(quoted ? value : value.trim());
1835
+ return values;
1836
+ }
1837
+ function parseRecord(element, definitions, identifier) {
1838
+ const attributes = /* @__PURE__ */ Object.create(null);
1839
+ for (const definition of definitions.values()) {
1840
+ if (definition.defaultValue !== void 0)
1841
+ attributes[definition.name] = Array.isArray(definition.defaultValue) ? [...definition.defaultValue] : definition.defaultValue;
1842
+ }
1843
+ for (const attvalue of getElements(getContainer(element.attvalues).attvalue)) {
1844
+ const key = requireAttribute(attvalue, "for");
1845
+ const definition = definitions.get(key);
1846
+ if (!definition) throw new Error(`Undeclared GEXF attribute: ${key}`);
1847
+ attributes[definition.name] = castValue(requireValue(attvalue), definition.type);
1848
+ }
1849
+ const native = /* @__PURE__ */ Object.create(null);
1850
+ if (element["@_weight"] !== void 0)
1851
+ native.weight = castValue(String(element["@_weight"]), "double");
1852
+ if (element["@_kind"] !== void 0) native.kind = element["@_kind"];
1853
+ const visualization = /* @__PURE__ */ Object.create(null);
1854
+ for (const name of ["color", "position", "size", "shape", "thickness"]) {
1855
+ const value = element[`viz:${name}`];
1856
+ if (value === void 0) continue;
1857
+ const properties = /* @__PURE__ */ Object.create(null);
1858
+ for (const [key, property] of Object.entries(getElement(value, `viz:${name}`))) {
1859
+ if (key.startsWith("@_") && !key.startsWith("@_xmlns")) {
1860
+ const propertyName = key.slice(2);
1861
+ properties[propertyName] = ["r", "g", "b", "a", "x", "y", "z"].includes(propertyName) || propertyName === "value" && (name === "size" || name === "thickness") ? castValue(String(property), "double") : property;
1862
+ }
1863
+ }
1864
+ visualization[name] = properties;
1865
+ }
1866
+ if (Object.keys(visualization).length) native.viz = visualization;
1867
+ if (Object.keys(native).length) attributes.gexf = native;
1868
+ return {
1869
+ id: identifier ?? requireAttribute(element, "id"),
1870
+ label: element["@_label"],
1871
+ attributes
1872
+ };
1873
+ }
1874
+ function requireValue(element) {
1875
+ const value = element["@_value"];
1876
+ if (typeof value !== "string") throw new Error("GEXF attvalue requires a value attribute.");
1877
+ return value;
1878
+ }
1879
+ var import_fast_xml_parser2, parser, GEXF_NAMESPACE, TEMPORAL_ATTRIBUTES;
1880
+ var init_parse_gexf = __esm({
1881
+ "src/lib/parse-gexf.ts"() {
1882
+ "use strict";
1883
+ import_fast_xml_parser2 = require("fast-xml-parser");
1884
+ init_build_graph_tables();
1885
+ parser = new import_fast_xml_parser2.XMLParser({
1886
+ ignoreAttributes: false,
1887
+ parseAttributeValue: false,
1888
+ parseTagValue: false,
1889
+ trimValues: false
1890
+ });
1891
+ GEXF_NAMESPACE = /^https?:\/\/(?:www\.)?gexf.net\/1\.(?:2(?:draft)?|3)(\/viz)?$/;
1892
+ TEMPORAL_ATTRIBUTES = [
1893
+ "start",
1894
+ "end",
1895
+ "startopen",
1896
+ "endopen",
1897
+ "timestamp",
1898
+ "timestamps",
1899
+ "intervals"
1900
+ ];
1901
+ }
1902
+ });
1903
+
1904
+ // src/gexf-loader.ts
1905
+ var gexf_loader_exports = {};
1906
+ __export(gexf_loader_exports, {
1907
+ GEXFLoaderWithParser: () => GEXFLoaderWithParser
1908
+ });
1909
+ var GEXFLoaderWithParser;
1910
+ var init_gexf_loader = __esm({
1911
+ "src/gexf-loader.ts"() {
1912
+ "use strict";
1913
+ init_gexf_loader_types();
1914
+ init_parse_gexf();
1915
+ GEXFLoaderWithParser = {
1916
+ ...GEXFLoader,
1917
+ parse: async (data, options) => {
1918
+ var _a;
1919
+ return parseGEXF(data, ((_a = options == null ? void 0 : options.gexf) == null ? void 0 : _a.shape) ?? "arrow-table");
1920
+ },
1921
+ parseSync: (data, options) => {
1922
+ var _a;
1923
+ return parseGEXF(data, ((_a = options == null ? void 0 : options.gexf) == null ? void 0 : _a.shape) ?? "arrow-table");
1924
+ },
1925
+ parseTextSync: (data, options) => {
1926
+ var _a;
1927
+ return parseGEXF(data, ((_a = options == null ? void 0 : options.gexf) == null ? void 0 : _a.shape) ?? "arrow-table");
1928
+ }
1083
1929
  };
1084
1930
  }
1085
1931
  });
@@ -1088,12 +1934,13 @@ var init_dot_loader = __esm({
1088
1934
  var index_exports = {};
1089
1935
  __export(index_exports, {
1090
1936
  DOTLoader: () => DOTLoader2,
1937
+ GEXFLoader: () => GEXFLoader2,
1091
1938
  GraphMLLoader: () => GraphMLLoader2
1092
1939
  });
1093
1940
  module.exports = __toCommonJS(index_exports);
1094
1941
 
1095
1942
  // dist/graphml-loader-types.js
1096
- var VERSION2 = true ? "5.0.0-alpha.9" : "latest";
1943
+ var VERSION2 = true ? "5.0.0-beta.1" : "latest";
1097
1944
  async function preload2() {
1098
1945
  const { GraphMLLoaderWithParser: GraphMLLoaderWithParser2 } = await Promise.resolve().then(() => (init_graphml_loader(), graphml_loader_exports));
1099
1946
  return GraphMLLoaderWithParser2;
@@ -1109,12 +1956,12 @@ var GraphMLLoader2 = {
1109
1956
  worker: false,
1110
1957
  dataType: null,
1111
1958
  batchType: null,
1112
- options: {},
1959
+ options: { graphml: { shape: "arrow-table" } },
1113
1960
  preload: preload2
1114
1961
  };
1115
1962
 
1116
1963
  // dist/dot-loader-types.js
1117
- var VERSION4 = true ? "5.0.0-alpha.9" : "latest";
1964
+ var VERSION4 = true ? "5.0.0-beta.1" : "latest";
1118
1965
  async function preload4() {
1119
1966
  const { DOTLoaderWithParser: DOTLoaderWithParser2 } = await Promise.resolve().then(() => (init_dot_loader(), dot_loader_exports));
1120
1967
  return DOTLoaderWithParser2;
@@ -1130,7 +1977,28 @@ var DOTLoader2 = {
1130
1977
  worker: false,
1131
1978
  dataType: null,
1132
1979
  batchType: null,
1133
- options: {},
1980
+ options: { dot: { shape: "arrow-table" } },
1134
1981
  preload: preload4
1135
1982
  };
1983
+
1984
+ // dist/gexf-loader-types.js
1985
+ var VERSION6 = true ? "5.0.0-beta.1" : "latest";
1986
+ async function preload6() {
1987
+ const { GEXFLoaderWithParser: GEXFLoaderWithParser2 } = await Promise.resolve().then(() => (init_gexf_loader(), gexf_loader_exports));
1988
+ return GEXFLoaderWithParser2;
1989
+ }
1990
+ var GEXFLoader2 = {
1991
+ name: "GEXF",
1992
+ id: "gexf",
1993
+ module: "graphs",
1994
+ version: VERSION6,
1995
+ extensions: ["gexf"],
1996
+ mimeTypes: ["application/gexf+xml"],
1997
+ text: true,
1998
+ worker: false,
1999
+ dataType: null,
2000
+ batchType: null,
2001
+ options: { gexf: { shape: "arrow-table" } },
2002
+ preload: preload6
2003
+ };
1136
2004
  //# sourceMappingURL=index.cjs.map