@graphty/graph-io 0.3.18 → 0.3.20

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 (235) hide show
  1. package/README.md +80 -2
  2. package/dist/chunks/{escape-D-gZWO26.js → escape-B-tkk_Cl.js} +74 -16
  3. package/dist/chunks/escape-B-tkk_Cl.js.map +1 -0
  4. package/dist/chunks/{writer-GAdltGmC.js → export-Bh60Dv-n.js} +7 -252
  5. package/dist/chunks/export-Bh60Dv-n.js.map +1 -0
  6. package/dist/chunks/exporter-BGrsWamJ.js +736 -0
  7. package/dist/chunks/exporter-BGrsWamJ.js.map +1 -0
  8. package/dist/chunks/exporter-DIeGJXAZ.js +834 -0
  9. package/dist/chunks/exporter-DIeGJXAZ.js.map +1 -0
  10. package/dist/chunks/{importer-Br_QeAeE.js → importer-BWY2FFc5.js} +28 -6
  11. package/dist/chunks/importer-BWY2FFc5.js.map +1 -0
  12. package/dist/chunks/importer-BaQpCEcJ.js +2194 -0
  13. package/dist/chunks/importer-BaQpCEcJ.js.map +1 -0
  14. package/dist/chunks/importer-DD-xv9_Y.js +1471 -0
  15. package/dist/chunks/importer-DD-xv9_Y.js.map +1 -0
  16. package/dist/chunks/{importer-aNJfe0qu.js → importer-DEcKhsmQ.js} +2 -2
  17. package/dist/chunks/{importer-aNJfe0qu.js.map → importer-DEcKhsmQ.js.map} +1 -1
  18. package/dist/chunks/{importer-DHagxvDD.js → importer-DIrbbnAf.js} +6 -4
  19. package/dist/chunks/{importer-DHagxvDD.js.map → importer-DIrbbnAf.js.map} +1 -1
  20. package/dist/chunks/importer-D_e7e7LX.js +3055 -0
  21. package/dist/chunks/importer-D_e7e7LX.js.map +1 -0
  22. package/dist/chunks/{importer-Du5crN9l.js → importer-Wv4C4gaF.js} +278 -82
  23. package/dist/chunks/importer-Wv4C4gaF.js.map +1 -0
  24. package/dist/chunks/importer-vi3bSdtw.js +1713 -0
  25. package/dist/chunks/importer-vi3bSdtw.js.map +1 -0
  26. package/dist/chunks/{importer-d0uQxFp6.js → importer-zGLo8Dg_.js} +6 -4
  27. package/dist/chunks/{importer-d0uQxFp6.js.map → importer-zGLo8Dg_.js.map} +1 -1
  28. package/dist/chunks/json-elements-DDS8N2Dd.js +779 -0
  29. package/dist/chunks/json-elements-DDS8N2Dd.js.map +1 -0
  30. package/dist/chunks/{records-Bk9jgodz.js → records-dbRkxwaq.js} +2 -2
  31. package/dist/chunks/{records-Bk9jgodz.js.map → records-dbRkxwaq.js.map} +1 -1
  32. package/dist/chunks/{report-BOk0p5y8.js → report-B1z4WT9e.js} +143 -111
  33. package/dist/chunks/{report-BOk0p5y8.js.map → report-B1z4WT9e.js.map} +1 -1
  34. package/dist/chunks/weights-Dzba96G3.js +176 -0
  35. package/dist/chunks/weights-Dzba96G3.js.map +1 -0
  36. package/dist/chunks/writer-C7flM-Ih.js +77 -0
  37. package/dist/chunks/writer-C7flM-Ih.js.map +1 -0
  38. package/dist/csv.js +6 -4
  39. package/dist/csv.js.map +1 -1
  40. package/dist/cx.d.ts +1 -0
  41. package/dist/cx.js +6 -0
  42. package/dist/cx.js.map +1 -0
  43. package/dist/cx2.d.ts +1 -0
  44. package/dist/cx2.js +10 -0
  45. package/dist/cx2.js.map +1 -0
  46. package/dist/cys.d.ts +1 -0
  47. package/dist/cys.js +6 -0
  48. package/dist/cys.js.map +1 -0
  49. package/dist/dot.js +1 -1
  50. package/dist/gexf.js +16 -4
  51. package/dist/gexf.js.map +1 -1
  52. package/dist/gml.js +13 -14
  53. package/dist/gml.js.map +1 -1
  54. package/dist/graph-io.js +302 -399
  55. package/dist/graph-io.js.map +1 -1
  56. package/dist/graphml.js +1 -1
  57. package/dist/json.js +1 -1
  58. package/dist/neo4j.js +6 -4
  59. package/dist/neo4j.js.map +1 -1
  60. package/dist/obo.js +1 -1
  61. package/dist/pajek.js +1 -1
  62. package/dist/src/common/cell-budget.d.ts +84 -0
  63. package/dist/src/common/cell-budget.d.ts.map +1 -0
  64. package/dist/src/common/cell-budget.js +138 -0
  65. package/dist/src/common/cell-budget.js.map +1 -0
  66. package/dist/src/common/input.d.ts +10 -0
  67. package/dist/src/common/input.d.ts.map +1 -1
  68. package/dist/src/common/input.js +39 -0
  69. package/dist/src/common/input.js.map +1 -1
  70. package/dist/src/common/json-elements.d.ts +286 -0
  71. package/dist/src/common/json-elements.d.ts.map +1 -0
  72. package/dist/src/common/json-elements.js +926 -0
  73. package/dist/src/common/json-elements.js.map +1 -0
  74. package/dist/src/common/options.d.ts +6 -0
  75. package/dist/src/common/options.d.ts.map +1 -1
  76. package/dist/src/common/options.js +1 -1
  77. package/dist/src/common/options.js.map +1 -1
  78. package/dist/src/common/xml.d.ts +37 -3
  79. package/dist/src/common/xml.d.ts.map +1 -1
  80. package/dist/src/common/xml.js +86 -6
  81. package/dist/src/common/xml.js.map +1 -1
  82. package/dist/src/common/zip.d.ts +92 -0
  83. package/dist/src/common/zip.d.ts.map +1 -0
  84. package/dist/src/common/zip.js +399 -0
  85. package/dist/src/common/zip.js.map +1 -0
  86. package/dist/src/formats/cx/importer.d.ts +133 -0
  87. package/dist/src/formats/cx/importer.d.ts.map +1 -0
  88. package/dist/src/formats/cx/importer.js +2220 -0
  89. package/dist/src/formats/cx/importer.js.map +1 -0
  90. package/dist/src/formats/cx/index.d.ts +7 -0
  91. package/dist/src/formats/cx/index.d.ts.map +1 -0
  92. package/dist/src/formats/cx/index.js +7 -0
  93. package/dist/src/formats/cx/index.js.map +1 -0
  94. package/dist/src/formats/cx2/exporter.d.ts +59 -0
  95. package/dist/src/formats/cx2/exporter.d.ts.map +1 -0
  96. package/dist/src/formats/cx2/exporter.js +864 -0
  97. package/dist/src/formats/cx2/exporter.js.map +1 -0
  98. package/dist/src/formats/cx2/importer.d.ts +169 -0
  99. package/dist/src/formats/cx2/importer.d.ts.map +1 -0
  100. package/dist/src/formats/cx2/importer.js +1652 -0
  101. package/dist/src/formats/cx2/importer.js.map +1 -0
  102. package/dist/src/formats/cx2/index.d.ts +7 -0
  103. package/dist/src/formats/cx2/index.d.ts.map +1 -0
  104. package/dist/src/formats/cx2/index.js +7 -0
  105. package/dist/src/formats/cx2/index.js.map +1 -0
  106. package/dist/src/formats/cys/constants.d.ts +68 -0
  107. package/dist/src/formats/cys/constants.d.ts.map +1 -0
  108. package/dist/src/formats/cys/constants.js +76 -0
  109. package/dist/src/formats/cys/constants.js.map +1 -0
  110. package/dist/src/formats/cys/importer.d.ts +38 -0
  111. package/dist/src/formats/cys/importer.d.ts.map +1 -0
  112. package/dist/src/formats/cys/importer.js +830 -0
  113. package/dist/src/formats/cys/importer.js.map +1 -0
  114. package/dist/src/formats/cys/index.d.ts +7 -0
  115. package/dist/src/formats/cys/index.d.ts.map +1 -0
  116. package/dist/src/formats/cys/index.js +7 -0
  117. package/dist/src/formats/cys/index.js.map +1 -0
  118. package/dist/src/formats/cys/session.d.ts +132 -0
  119. package/dist/src/formats/cys/session.d.ts.map +1 -0
  120. package/dist/src/formats/cys/session.js +315 -0
  121. package/dist/src/formats/cys/session.js.map +1 -0
  122. package/dist/src/formats/cys/tables.d.ts +90 -0
  123. package/dist/src/formats/cys/tables.d.ts.map +1 -0
  124. package/dist/src/formats/cys/tables.js +293 -0
  125. package/dist/src/formats/cys/tables.js.map +1 -0
  126. package/dist/src/formats/dot/exporter.d.ts +2 -0
  127. package/dist/src/formats/dot/exporter.d.ts.map +1 -1
  128. package/dist/src/formats/dot/exporter.js +12 -0
  129. package/dist/src/formats/dot/exporter.js.map +1 -1
  130. package/dist/src/formats/dot/importer.js +6 -2
  131. package/dist/src/formats/dot/importer.js.map +1 -1
  132. package/dist/src/formats/gexf/exporter.d.ts +2 -0
  133. package/dist/src/formats/gexf/exporter.d.ts.map +1 -1
  134. package/dist/src/formats/gexf/exporter.js +6 -0
  135. package/dist/src/formats/gexf/exporter.js.map +1 -1
  136. package/dist/src/formats/gexf/importer.d.ts +0 -2
  137. package/dist/src/formats/gexf/importer.d.ts.map +1 -1
  138. package/dist/src/formats/gexf/importer.js +1 -3
  139. package/dist/src/formats/gexf/importer.js.map +1 -1
  140. package/dist/src/formats/gexf/index.d.ts +1 -1
  141. package/dist/src/formats/gexf/index.js +2 -2
  142. package/dist/src/formats/gexf/index.js.map +1 -1
  143. package/dist/src/formats/gml/exporter.d.ts +0 -8
  144. package/dist/src/formats/gml/exporter.d.ts.map +1 -1
  145. package/dist/src/formats/gml/exporter.js +8 -18
  146. package/dist/src/formats/gml/exporter.js.map +1 -1
  147. package/dist/src/formats/json/importer.d.ts.map +1 -1
  148. package/dist/src/formats/json/importer.js +6 -104
  149. package/dist/src/formats/json/importer.js.map +1 -1
  150. package/dist/src/formats/xgmml/columns.d.ts +152 -0
  151. package/dist/src/formats/xgmml/columns.d.ts.map +1 -0
  152. package/dist/src/formats/xgmml/columns.js +593 -0
  153. package/dist/src/formats/xgmml/columns.js.map +1 -0
  154. package/dist/src/formats/xgmml/constants.d.ts +196 -0
  155. package/dist/src/formats/xgmml/constants.d.ts.map +1 -0
  156. package/dist/src/formats/xgmml/constants.js +197 -0
  157. package/dist/src/formats/xgmml/constants.js.map +1 -0
  158. package/dist/src/formats/xgmml/document.d.ts +361 -0
  159. package/dist/src/formats/xgmml/document.d.ts.map +1 -0
  160. package/dist/src/formats/xgmml/document.js +695 -0
  161. package/dist/src/formats/xgmml/document.js.map +1 -0
  162. package/dist/src/formats/xgmml/emit.d.ts +341 -0
  163. package/dist/src/formats/xgmml/emit.d.ts.map +1 -0
  164. package/dist/src/formats/xgmml/emit.js +1275 -0
  165. package/dist/src/formats/xgmml/emit.js.map +1 -0
  166. package/dist/src/formats/xgmml/exporter.d.ts +24 -0
  167. package/dist/src/formats/xgmml/exporter.d.ts.map +1 -0
  168. package/dist/src/formats/xgmml/exporter.js +999 -0
  169. package/dist/src/formats/xgmml/exporter.js.map +1 -0
  170. package/dist/src/formats/xgmml/importer.d.ts +58 -0
  171. package/dist/src/formats/xgmml/importer.d.ts.map +1 -0
  172. package/dist/src/formats/xgmml/importer.js +360 -0
  173. package/dist/src/formats/xgmml/importer.js.map +1 -0
  174. package/dist/src/formats/xgmml/index.d.ts +8 -0
  175. package/dist/src/formats/xgmml/index.d.ts.map +1 -0
  176. package/dist/src/formats/xgmml/index.js +8 -0
  177. package/dist/src/formats/xgmml/index.js.map +1 -0
  178. package/dist/src/formats/xgmml/values.d.ts +60 -0
  179. package/dist/src/formats/xgmml/values.d.ts.map +1 -0
  180. package/dist/src/formats/xgmml/values.js +148 -0
  181. package/dist/src/formats/xgmml/values.js.map +1 -0
  182. package/dist/src/index.d.ts +4 -0
  183. package/dist/src/index.d.ts.map +1 -1
  184. package/dist/src/index.js +4 -0
  185. package/dist/src/index.js.map +1 -1
  186. package/dist/src/registry.d.ts +7 -0
  187. package/dist/src/registry.d.ts.map +1 -1
  188. package/dist/src/registry.js +30 -10
  189. package/dist/src/registry.js.map +1 -1
  190. package/dist/src/sniff.d.ts +1 -1
  191. package/dist/src/sniff.d.ts.map +1 -1
  192. package/dist/src/sniff.js +4 -0
  193. package/dist/src/sniff.js.map +1 -1
  194. package/dist/xgmml.d.ts +1 -0
  195. package/dist/xgmml.js +9 -0
  196. package/dist/xgmml.js.map +1 -0
  197. package/package.json +25 -2
  198. package/src/common/cell-budget.ts +170 -0
  199. package/src/common/input.ts +40 -0
  200. package/src/common/json-elements.ts +1147 -0
  201. package/src/common/options.ts +1 -1
  202. package/src/common/xml.ts +127 -6
  203. package/src/common/zip.ts +472 -0
  204. package/src/formats/cx/importer.ts +2733 -0
  205. package/src/formats/cx/index.ts +7 -0
  206. package/src/formats/cx2/exporter.ts +1036 -0
  207. package/src/formats/cx2/importer.ts +2187 -0
  208. package/src/formats/cx2/index.ts +7 -0
  209. package/src/formats/cys/constants.ts +99 -0
  210. package/src/formats/cys/importer.ts +1100 -0
  211. package/src/formats/cys/index.ts +7 -0
  212. package/src/formats/cys/session.ts +428 -0
  213. package/src/formats/cys/tables.ts +400 -0
  214. package/src/formats/dot/exporter.ts +17 -0
  215. package/src/formats/dot/importer.ts +6 -2
  216. package/src/formats/gexf/exporter.ts +11 -0
  217. package/src/formats/gexf/importer.ts +1 -2
  218. package/src/formats/gexf/index.ts +1 -1
  219. package/src/formats/gml/exporter.ts +8 -19
  220. package/src/formats/json/importer.ts +6 -105
  221. package/src/formats/xgmml/columns.ts +747 -0
  222. package/src/formats/xgmml/constants.ts +265 -0
  223. package/src/formats/xgmml/document.ts +975 -0
  224. package/src/formats/xgmml/emit.ts +1563 -0
  225. package/src/formats/xgmml/exporter.ts +1215 -0
  226. package/src/formats/xgmml/importer.ts +491 -0
  227. package/src/formats/xgmml/index.ts +8 -0
  228. package/src/formats/xgmml/values.ts +183 -0
  229. package/src/index.ts +19 -0
  230. package/src/registry.ts +46 -15
  231. package/src/sniff.ts +18 -1
  232. package/dist/chunks/escape-D-gZWO26.js.map +0 -1
  233. package/dist/chunks/importer-Br_QeAeE.js.map +0 -1
  234. package/dist/chunks/importer-Du5crN9l.js.map +0 -1
  235. package/dist/chunks/writer-GAdltGmC.js.map +0 -1
@@ -1,6 +1,9 @@
1
1
  import { GraphFormatError, INVALID_INDEX } from "@graphty/graph-format";
2
- import { aC as resolveExportOptions, ay as pairFolding, as as declareResolved, ag as UNKNOWN_ENCODING_CODE, s as ENCODING_FALLBACK_CODE, z as INVALID_ENCODING_CODE, F as INVALID_UTF8_CODE, V as OPTION_IGNORED_CODE, a3 as SINK_OPTION_CODE, H as HYPEREDGE_CODE, ad as TOO_LARGE_CODE, D as DANGLING_REFERENCE_CODE, A as AMBIGUOUS_GRAPH_NAME_CODE, G as GRAPH_NOT_FOUND_CODE, P as MULTIPLE_GRAPHS_CODE, v as ID_MERGED_CODE, n as DUPLICATE_EDGE_ID_CODE, p as DUPLICATE_NODE_CODE, ah as UNKNOWN_PARENT_CODE, e as BAD_VALUE_CODE, M as MISSING_ENDPOINT_CODE, N as MISSING_ID_CODE, a9 as SYNTAX_CODE, r as EMPTY_INPUT_CODE, aD as resolveImportOptions, I as ImportReportBuilder, az as readText, t as textChunks, aA as reportSinkOptions, aB as reportUnusedOptions, a as throwIfAborted, J as IdCoercer, q as DirectionResolver, aE as uniqueColumnName, ao as chooseGraph } from "./report-BOk0p5y8.js";
3
- import { c as capabilities, L as LOSS, n as joinText, e as encodeChunks, a as checkCapabilities, r as countMixedEdges, f as explicitWeights, h as formatF32, i as formatF64, w as weightFromValue } from "./writer-GAdltGmC.js";
2
+ import { V as resolveExportOptions, X as pairFolding, L as declareResolved, q as UNKNOWN_ENCODING_CODE, E as ENCODING_FALLBACK_CODE, r as INVALID_ENCODING_CODE, s as INVALID_UTF8_CODE, O as OPTION_IGNORED_CODE, S as SINK_OPTION_CODE, an as HYPEREDGE_CODE, T as TOO_LARGE_CODE, j as DANGLING_REFERENCE_CODE, A as AMBIGUOUS_GRAPH_NAME_CODE, G as GRAPH_NOT_FOUND_CODE, M as MULTIPLE_GRAPHS_CODE, I as ID_MERGED_CODE, c as DUPLICATE_EDGE_ID_CODE, d as DUPLICATE_NODE_CODE, U as UNKNOWN_PARENT_CODE, B as BAD_VALUE_CODE, e as MISSING_ENDPOINT_CODE, f as MISSING_ID_CODE, t as SYNTAX_CODE, u as EMPTY_INPUT_CODE, v as resolveImportOptions, w as ImportReportBuilder, aG as readText, x as textChunks, F as reportSinkOptions, z as reportUnusedOptions, y as throwIfAborted, K as IdCoercer, J as DirectionResolver, Q as uniqueColumnName, H as chooseGraph } from "./report-B1z4WT9e.js";
3
+ import { c as capabilities, L as LOSS, a as checkCapabilities, d as countMixedEdges } from "./export-Bh60Dv-n.js";
4
+ import { e as explicitWeights, f as formatF32, a as formatF64, w as weightFromValue } from "./weights-Dzba96G3.js";
5
+ import { j as joinText, e as encodeChunks } from "./writer-C7flM-Ih.js";
6
+ import { M as MAYBE_UNSAFE_INTEGER, e as rewriteNumbers, g as reviveNonstandard } from "./json-elements-DDS8N2Dd.js";
4
7
  import { a as OBOGRAPHS_PREDICATE_TAGS, c as compactOboIri, o as oboColumnDecl, P as PLACEHOLDER_COLUMN, s as synonymScopeOf, O as OBO_NODE_COLUMNS } from "./ontology-BnrJ4I98.js";
5
8
  const JSON_DIALECTS = Object.freeze([
6
9
  "node-link",
@@ -1370,6 +1373,268 @@ const jsonExporter = Object.freeze({
1370
1373
  function jsonCapabilities(dialect) {
1371
1374
  return dialectCapabilities(dialect);
1372
1375
  }
1376
+ const GRAPH_FORMATS = Object.freeze([
1377
+ "json",
1378
+ "graphml",
1379
+ "gexf",
1380
+ "csv",
1381
+ "gml",
1382
+ "dot",
1383
+ "pajek",
1384
+ "neo4j",
1385
+ "xgmml",
1386
+ "cx2",
1387
+ "cx",
1388
+ "obo",
1389
+ "cys"
1390
+ ]);
1391
+ const SNIFF_HEAD_BYTES = 8192;
1392
+ function extensionOf(filename) {
1393
+ const base = filename.slice(Math.max(filename.lastIndexOf("/"), filename.lastIndexOf("\\")) + 1);
1394
+ const dot = base.lastIndexOf(".");
1395
+ if (dot <= 0 || dot === base.length - 1) {
1396
+ return null;
1397
+ }
1398
+ return base.slice(dot).toLowerCase();
1399
+ }
1400
+ function normalizeMimeType(mimeType) {
1401
+ const semicolon = mimeType.indexOf(";");
1402
+ return (semicolon < 0 ? mimeType : mimeType.slice(0, semicolon)).trim().toLowerCase();
1403
+ }
1404
+ function headBytes(head) {
1405
+ if (typeof head === "string") {
1406
+ return new TextEncoder().encode(head.slice(0, SNIFF_HEAD_BYTES)).subarray(0, SNIFF_HEAD_BYTES);
1407
+ }
1408
+ if (head.byteLength >= 2 && (head[0] === 255 && head[1] === 254 || head[0] === 254 && head[1] === 255)) {
1409
+ const encoding = head[0] === 255 ? "utf-16le" : "utf-16be";
1410
+ return headBytes(new TextDecoder(encoding).decode(head.subarray(0, SNIFF_HEAD_BYTES)));
1411
+ }
1412
+ return head.byteLength > SNIFF_HEAD_BYTES ? head.subarray(0, SNIFF_HEAD_BYTES) : head;
1413
+ }
1414
+ function rankFormats(hints, importers) {
1415
+ const extension = typeof hints.filename === "string" ? extensionOf(hints.filename) : null;
1416
+ const mime = typeof hints.mimeType === "string" ? normalizeMimeType(hints.mimeType) : null;
1417
+ const head = hints.head === void 0 || hints.head === null ? null : headBytes(hints.head);
1418
+ const candidates = [];
1419
+ let rank = 0;
1420
+ for (const importer of importers) {
1421
+ const extensionMatch = extension !== null && importer.extensions.some((e) => e.toLowerCase() === extension);
1422
+ const mimeMatch = mime !== null && importer.mimeTypes.some((m) => m.toLowerCase() === mime);
1423
+ let content = 0;
1424
+ if (head !== null && head.byteLength > 0 && typeof importer.sniff === "function") {
1425
+ content = clamp(importer.sniff(head));
1426
+ }
1427
+ let confidence;
1428
+ if (content > 0) {
1429
+ confidence = 0.5 + 0.35 * content + (extensionMatch ? 0.1 : 0) + (mimeMatch ? 0.05 : 0);
1430
+ } else if (extensionMatch || mimeMatch) {
1431
+ confidence = (extensionMatch ? 0.3 : 0) + (mimeMatch ? 0.1 : 0);
1432
+ } else {
1433
+ continue;
1434
+ }
1435
+ const dialect = importer.format === "json" && head !== null ? sniffJsonDialectHead(head) : null;
1436
+ const result = Object.freeze({
1437
+ format: importer.format,
1438
+ confidence: Math.min(1, confidence),
1439
+ content,
1440
+ extension: extensionMatch,
1441
+ mimeType: mimeMatch,
1442
+ dialect
1443
+ });
1444
+ candidates.push({ result, rank: rank++ });
1445
+ }
1446
+ candidates.sort((a, b) => b.result.confidence - a.result.confidence || a.rank - b.rank);
1447
+ return candidates.map((c) => c.result);
1448
+ }
1449
+ function sniffFormat(hints, importers) {
1450
+ const ranked = rankFormats(hints, importers);
1451
+ return ranked.length > 0 ? ranked[0] : null;
1452
+ }
1453
+ function sniffJsonDialectHead(head) {
1454
+ const text = typeof head === "string" ? head : new TextDecoder("utf-8", { fatal: false }).decode(head);
1455
+ const body = text.charCodeAt(0) === 65279 ? text.slice(1) : text;
1456
+ const trimmed = body.trimStart();
1457
+ if (!trimmed.startsWith("{") && !trimmed.startsWith("[")) {
1458
+ return null;
1459
+ }
1460
+ let root;
1461
+ try {
1462
+ root = JSON.parse(trimmed);
1463
+ } catch {
1464
+ root = skeletonOf(trimmed);
1465
+ }
1466
+ return sniffJsonDialect(root);
1467
+ }
1468
+ function skeletonOf(text) {
1469
+ const keys = scanKeys(text);
1470
+ if (text.startsWith("[")) {
1471
+ const first = keys.get("nodes[0]");
1472
+ return first === void 0 ? null : [objectOf(first)];
1473
+ }
1474
+ const rootKeys = keys.get("");
1475
+ if (rootKeys === void 0) {
1476
+ return null;
1477
+ }
1478
+ const root = {};
1479
+ for (const key of rootKeys) {
1480
+ switch (key) {
1481
+ case "graph":
1482
+ case "options":
1483
+ root[key] = objectOf(keys.get(key));
1484
+ break;
1485
+ case "graphs": {
1486
+ const nodes = keys.get("graphs[0].nodes[]");
1487
+ const edges = keys.get("graphs[0].edges[]");
1488
+ const graph = {};
1489
+ if (nodes !== void 0) {
1490
+ graph.nodes = [objectOf(nodes)];
1491
+ }
1492
+ if (edges !== void 0) {
1493
+ graph.edges = [objectOf(edges)];
1494
+ }
1495
+ root[key] = nodes === void 0 && edges === void 0 ? [] : [graph];
1496
+ break;
1497
+ }
1498
+ case "nodes":
1499
+ case "edges":
1500
+ case "links": {
1501
+ const first = keys.get(`${key}[0]`);
1502
+ root[key] = first === void 0 ? [] : [objectOf(first)];
1503
+ break;
1504
+ }
1505
+ default:
1506
+ root[key] = true;
1507
+ break;
1508
+ }
1509
+ }
1510
+ return root;
1511
+ }
1512
+ function objectOf(names) {
1513
+ const out = {};
1514
+ if (names !== void 0) {
1515
+ for (const name of names) {
1516
+ out[name] = name === "attributes" || name === "data" ? {} : true;
1517
+ }
1518
+ }
1519
+ return out;
1520
+ }
1521
+ function scanKeys(text) {
1522
+ const found = /* @__PURE__ */ new Map();
1523
+ const kinds = [];
1524
+ const labels = [];
1525
+ const counts = [];
1526
+ let pendingKey = null;
1527
+ let expectingKey = false;
1528
+ const pathOf = () => {
1529
+ const depth = kinds.length;
1530
+ if (depth === 1) {
1531
+ return kinds[0] === "object" ? "" : null;
1532
+ }
1533
+ if (depth === 2 && kinds[0] === "array" && kinds[1] === "object" && labels[1] === "0") {
1534
+ return "nodes[0]";
1535
+ }
1536
+ if (depth === 2 && kinds[0] === "object" && kinds[1] === "object") {
1537
+ return labels[1] === "graph" || labels[1] === "options" ? labels[1] : null;
1538
+ }
1539
+ if (depth === 5 && kinds.join() === "object,array,object,array,object" && labels[1] === "graphs" && labels[2] === "0" && (labels[3] === "nodes" || labels[3] === "edges")) {
1540
+ return labels[3] === "nodes" ? "graphs[0].nodes[]" : "graphs[0].edges[]";
1541
+ }
1542
+ if (depth === 3 && kinds[0] === "object" && kinds[1] === "array" && kinds[2] === "object") {
1543
+ const section = labels[1];
1544
+ if ((section === "nodes" || section === "edges" || section === "links") && labels[2] === "0") {
1545
+ return `${section}[0]`;
1546
+ }
1547
+ }
1548
+ return null;
1549
+ };
1550
+ let i = 0;
1551
+ const n = text.length;
1552
+ while (i < n) {
1553
+ const ch = text[i];
1554
+ if (ch === '"') {
1555
+ const end = scanString(text, i + 1);
1556
+ if (end < 0) {
1557
+ break;
1558
+ }
1559
+ const literal = text.slice(i + 1, end);
1560
+ i = end + 1;
1561
+ if (expectingKey) {
1562
+ pendingKey = decodeKey(literal);
1563
+ expectingKey = false;
1564
+ }
1565
+ continue;
1566
+ }
1567
+ if (ch === "{" || ch === "[") {
1568
+ let label = "";
1569
+ if (kinds.length > 0) {
1570
+ label = kinds[kinds.length - 1] === "object" ? pendingKey ?? "" : String(counts[counts.length - 1]);
1571
+ }
1572
+ kinds.push(ch === "{" ? "object" : "array");
1573
+ labels.push(label);
1574
+ counts.push(0);
1575
+ expectingKey = ch === "{";
1576
+ pendingKey = null;
1577
+ } else if (ch === "}" || ch === "]") {
1578
+ kinds.pop();
1579
+ labels.pop();
1580
+ counts.pop();
1581
+ expectingKey = false;
1582
+ pendingKey = null;
1583
+ } else if (ch === ":") {
1584
+ if (pendingKey !== null) {
1585
+ const path = pathOf();
1586
+ if (path !== null) {
1587
+ let set = found.get(path);
1588
+ if (set === void 0) {
1589
+ set = /* @__PURE__ */ new Set();
1590
+ found.set(path, set);
1591
+ }
1592
+ set.add(pendingKey);
1593
+ }
1594
+ }
1595
+ } else if (ch === ",") {
1596
+ const top = kinds.length - 1;
1597
+ if (top >= 0) {
1598
+ counts[top]++;
1599
+ expectingKey = kinds[top] === "object";
1600
+ }
1601
+ pendingKey = null;
1602
+ }
1603
+ i++;
1604
+ }
1605
+ return found;
1606
+ }
1607
+ function scanString(text, from) {
1608
+ let i = from;
1609
+ while (i < text.length) {
1610
+ const ch = text[i];
1611
+ if (ch === "\\") {
1612
+ i += 2;
1613
+ continue;
1614
+ }
1615
+ if (ch === '"') {
1616
+ return i;
1617
+ }
1618
+ i++;
1619
+ }
1620
+ return -1;
1621
+ }
1622
+ function decodeKey(literal) {
1623
+ if (!literal.includes("\\")) {
1624
+ return literal;
1625
+ }
1626
+ try {
1627
+ return JSON.parse(`"${literal}"`);
1628
+ } catch {
1629
+ return literal;
1630
+ }
1631
+ }
1632
+ function clamp(value) {
1633
+ if (!(value > 0)) {
1634
+ return 0;
1635
+ }
1636
+ return value > 1 ? 1 : value;
1637
+ }
1373
1638
  const NODE_KEYS = /* @__PURE__ */ new Set(["id", "lbl", "type", "propertyType", "meta"]);
1374
1639
  const META_KEYS = /* @__PURE__ */ new Set([
1375
1640
  "definition",
@@ -2592,84 +2857,7 @@ function parseDocument(text, report) {
2592
2857
  }
2593
2858
  return root;
2594
2859
  }
2595
- const MAYBE_UNSAFE_INTEGER = new RegExp("(?<![0-9.])[0-9]{16}");
2596
2860
  const BIG_INTEGERS_SHOWN = 10;
2597
- const NONSTANDARD_SENTINEL = `${String.fromCharCode(0)}graph-io:`;
2598
- const NONSTANDARD_TOKENS = [
2599
- ["-Infinity", -Infinity],
2600
- ["Infinity", Infinity],
2601
- ["NaN", NaN]
2602
- ];
2603
- const INTEGER_LITERAL = /^-?(0|[1-9][0-9]*)$/;
2604
- function rewriteNumbers(text) {
2605
- const parts = [];
2606
- const tokens = /* @__PURE__ */ new Set();
2607
- const bigIntegers = [];
2608
- const arrays = [];
2609
- let expectValue = true;
2610
- let copied = 0;
2611
- let i = 0;
2612
- const n = text.length;
2613
- while (i < n) {
2614
- const ch = text[i];
2615
- if (ch === '"') {
2616
- i++;
2617
- while (i < n && text[i] !== '"') {
2618
- i += text[i] === "\\" ? 2 : 1;
2619
- }
2620
- i++;
2621
- expectValue = false;
2622
- continue;
2623
- }
2624
- if (ch === "{" || ch === "[") {
2625
- arrays.push(ch === "[");
2626
- expectValue = ch === "[";
2627
- } else if (ch === "}" || ch === "]") {
2628
- arrays.pop();
2629
- expectValue = false;
2630
- } else if (ch === ":") {
2631
- expectValue = true;
2632
- } else if (ch === ",") {
2633
- expectValue = arrays.length > 0 && arrays[arrays.length - 1];
2634
- } else if (expectValue && ch !== " " && ch !== " " && ch !== "\n" && ch !== "\r") {
2635
- expectValue = false;
2636
- const token = NONSTANDARD_TOKENS.find(([word]) => text.startsWith(word, i));
2637
- let end = i;
2638
- let replacement = null;
2639
- if (token !== void 0) {
2640
- end = i + token[0].length;
2641
- tokens.add(token[0]);
2642
- replacement = JSON.stringify(`${NONSTANDARD_SENTINEL}${token[0]}`);
2643
- } else if (ch === "-" || ch >= "0" && ch <= "9") {
2644
- end = i + 1;
2645
- while (end < n && "0123456789+-.eE".includes(text[end])) {
2646
- end++;
2647
- }
2648
- const literal = text.slice(i, end);
2649
- if (INTEGER_LITERAL.test(literal) && !Number.isSafeInteger(Number(literal))) {
2650
- bigIntegers.push(literal);
2651
- replacement = `"${literal}"`;
2652
- }
2653
- }
2654
- if (replacement !== null) {
2655
- parts.push(text.slice(copied, i), replacement);
2656
- copied = end;
2657
- }
2658
- i = Math.max(end, i + 1);
2659
- continue;
2660
- }
2661
- i++;
2662
- }
2663
- parts.push(text.slice(copied));
2664
- return { text: parts.join(""), tokens, bigIntegers };
2665
- }
2666
- function reviveNonstandard(_key, value) {
2667
- if (typeof value === "string" && value.startsWith(NONSTANDARD_SENTINEL)) {
2668
- const found = NONSTANDARD_TOKENS.find(([word]) => word === value.slice(NONSTANDARD_SENTINEL.length));
2669
- return found === void 0 ? value : found[1];
2670
- }
2671
- return value;
2672
- }
2673
2861
  function detectDialect(root, forced, report) {
2674
2862
  if (forced !== "auto") {
2675
2863
  return forced;
@@ -3860,7 +4048,8 @@ const jsonImporter = Object.freeze({
3860
4048
  if (!trimmed.startsWith("{") && !trimmed.startsWith("[")) {
3861
4049
  return 0;
3862
4050
  }
3863
- return SNIFF_KEYS.some((key) => trimmed.includes(key)) ? 0.9 : 0.5;
4051
+ const score = SNIFF_KEYS.some((key) => trimmed.includes(key)) ? 0.9 : 0.5;
4052
+ return trimmed.startsWith("[") && sniffJsonDialectHead(trimmed) !== "cytoscape" ? Math.min(score, 0.3) : score;
3864
4053
  },
3865
4054
  /**
3866
4055
  * Read a JSON graph document into the sink.
@@ -3962,13 +4151,20 @@ function readGraph(root, dialect, sink, report, resolved, json, options) {
3962
4151
  throwIfAborted(resolved.signal);
3963
4152
  }
3964
4153
  export {
4154
+ GRAPH_FORMATS as G,
3965
4155
  JSON_DIALECTS as J,
4156
+ SNIFF_HEAD_BYTES as S,
3966
4157
  JSON_ISSUE as a,
3967
4158
  JSON_LOSS as b,
3968
4159
  jsonExporter as c,
3969
4160
  dialectCapabilities as d,
3970
4161
  jsonImporter as e,
4162
+ extensionOf as f,
4163
+ sniffJsonDialectHead as g,
4164
+ headBytes as h,
3971
4165
  jsonCapabilities as j,
3972
- sniffJsonDialect as s
4166
+ normalizeMimeType as n,
4167
+ rankFormats as r,
4168
+ sniffFormat as s
3973
4169
  };
3974
- //# sourceMappingURL=importer-Du5crN9l.js.map
4170
+ //# sourceMappingURL=importer-Wv4C4gaF.js.map