@graphty/graph-io 0.3.42 → 0.3.44

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 (674) hide show
  1. package/dist/chunks/approximations-3Q4TsdTh.js +40 -0
  2. package/dist/chunks/approximations-3Q4TsdTh.js.map +1 -0
  3. package/dist/chunks/block-JQiwViEt.js +2777 -0
  4. package/dist/chunks/block-JQiwViEt.js.map +1 -0
  5. package/dist/chunks/{choose-DvpbdRuz.js → choose-BemygfH8.js} +3 -2
  6. package/dist/chunks/{choose-DvpbdRuz.js.map → choose-BemygfH8.js.map} +1 -1
  7. package/dist/chunks/{constants-fT3E8JYY.js → constants-BFUR_CtU.js} +6 -2
  8. package/dist/chunks/constants-BFUR_CtU.js.map +1 -0
  9. package/dist/chunks/convert-BcQ8_jMo.js +59 -0
  10. package/dist/chunks/convert-BcQ8_jMo.js.map +1 -0
  11. package/dist/chunks/emit-DCwFLts5.js +3456 -0
  12. package/dist/chunks/emit-DCwFLts5.js.map +1 -0
  13. package/dist/chunks/{escape-B62ZGM_a.js → escape-B1rMftd9.js} +43 -20
  14. package/dist/chunks/escape-B1rMftd9.js.map +1 -0
  15. package/dist/chunks/{export-rKLeGQMo.js → export-D7IGzTG4.js} +196 -792
  16. package/dist/chunks/export-D7IGzTG4.js.map +1 -0
  17. package/dist/chunks/{exporter-BWwEuOPT.js → exporter-BtnqYuuj.js} +22 -12
  18. package/dist/chunks/exporter-BtnqYuuj.js.map +1 -0
  19. package/dist/chunks/{exporter-yLxKBvLE.js → exporter-ChPyhBOv.js} +4 -3
  20. package/dist/chunks/{exporter-yLxKBvLE.js.map → exporter-ChPyhBOv.js.map} +1 -1
  21. package/dist/chunks/{exporter-8hLNemFk.js → exporter-KEPxYUXD.js} +133 -74
  22. package/dist/chunks/exporter-KEPxYUXD.js.map +1 -0
  23. package/dist/chunks/{exporter-CpRyHZ3H.js → exporter-quPUCBiC.js} +1807 -288
  24. package/dist/chunks/exporter-quPUCBiC.js.map +1 -0
  25. package/dist/chunks/format-GDmO6m6Q.js +676 -0
  26. package/dist/chunks/format-GDmO6m6Q.js.map +1 -0
  27. package/dist/chunks/generic-BL06jrJf.js +1347 -0
  28. package/dist/chunks/generic-BL06jrJf.js.map +1 -0
  29. package/dist/chunks/{importer-WrGRZb0N.js → importer-B7r2owVf.js} +449 -102
  30. package/dist/chunks/importer-B7r2owVf.js.map +1 -0
  31. package/dist/chunks/{importer-Ht7LNg8L.js → importer-BFmOP96W.js} +116 -296
  32. package/dist/chunks/importer-BFmOP96W.js.map +1 -0
  33. package/dist/chunks/{importer-BbNb7eNg.js → importer-C2nzGhdV.js} +1390 -129
  34. package/dist/chunks/importer-C2nzGhdV.js.map +1 -0
  35. package/dist/chunks/{importer-Dz7tI8Sa.js → importer-CbX2_rNF.js} +617 -115
  36. package/dist/chunks/importer-CbX2_rNF.js.map +1 -0
  37. package/dist/chunks/{importer-D794XUTe.js → importer-CdzeN6X4.js} +31 -8
  38. package/dist/chunks/importer-CdzeN6X4.js.map +1 -0
  39. package/dist/chunks/{importer-xZ-3suY1.js → importer-ChKNC_GN.js} +791 -135
  40. package/dist/chunks/importer-ChKNC_GN.js.map +1 -0
  41. package/dist/chunks/{importer-C98dpSH4.js → importer-dwoYpSqb.js} +141 -82
  42. package/dist/chunks/importer-dwoYpSqb.js.map +1 -0
  43. package/dist/chunks/index-B9fdNpTA.js +4310 -0
  44. package/dist/chunks/index-B9fdNpTA.js.map +1 -0
  45. package/dist/chunks/{json-elements-DKSqpNW1.js → json-elements-C4FwgnH5.js} +123 -32
  46. package/dist/chunks/json-elements-C4FwgnH5.js.map +1 -0
  47. package/dist/chunks/lexicon-B-knUi-l.js +508 -0
  48. package/dist/chunks/lexicon-B-knUi-l.js.map +1 -0
  49. package/dist/chunks/{ontology-export-CtRXjg_i.js → ontology-export-BSpbY5FL.js} +3 -2
  50. package/dist/chunks/{ontology-export-CtRXjg_i.js.map → ontology-export-BSpbY5FL.js.map} +1 -1
  51. package/dist/chunks/{records-Cu4bxYOm.js → records-Nwz_rbNt.js} +2 -2
  52. package/dist/chunks/{records-Cu4bxYOm.js.map → records-Nwz_rbNt.js.map} +1 -1
  53. package/dist/chunks/styles-Brt9JMfs.js +690 -0
  54. package/dist/chunks/styles-Brt9JMfs.js.map +1 -0
  55. package/dist/chunks/styles-_N-C8S-U.js +2102 -0
  56. package/dist/chunks/styles-_N-C8S-U.js.map +1 -0
  57. package/dist/chunks/styles-yed-DAfcIkf7.js +842 -0
  58. package/dist/chunks/styles-yed-DAfcIkf7.js.map +1 -0
  59. package/dist/chunks/{text-DHOJXnED.js → text-CgzMqHQb.js} +2 -2
  60. package/dist/chunks/{text-DHOJXnED.js.map → text-CgzMqHQb.js.map} +1 -1
  61. package/dist/chunks/units-XMZFIFe1.js +19 -0
  62. package/dist/chunks/units-XMZFIFe1.js.map +1 -0
  63. package/dist/csv.js +5 -4
  64. package/dist/csv.js.map +1 -1
  65. package/dist/cx.js +1 -1
  66. package/dist/cx2.js +2 -2
  67. package/dist/cys.js +1 -1
  68. package/dist/dot.js +5 -2
  69. package/dist/dot.js.map +1 -1
  70. package/dist/gexf.js +295 -414
  71. package/dist/gexf.js.map +1 -1
  72. package/dist/gml.js +8 -3031
  73. package/dist/gml.js.map +1 -1
  74. package/dist/graph-io.js +354 -240
  75. package/dist/graph-io.js.map +1 -1
  76. package/dist/graphml.js +4 -2
  77. package/dist/graphml.js.map +1 -1
  78. package/dist/json.js +1 -1
  79. package/dist/neo4j.js +4 -3
  80. package/dist/neo4j.js.map +1 -1
  81. package/dist/obo.js +1 -1
  82. package/dist/pajek.js +4 -2
  83. package/dist/positions.d.ts +1 -0
  84. package/dist/positions.js +427 -0
  85. package/dist/positions.js.map +1 -0
  86. package/dist/src/common/codes.d.ts +6 -0
  87. package/dist/src/common/codes.d.ts.map +1 -1
  88. package/dist/src/common/codes.js +6 -0
  89. package/dist/src/common/codes.js.map +1 -1
  90. package/dist/src/common/escape.d.ts.map +1 -1
  91. package/dist/src/common/escape.js +4 -2
  92. package/dist/src/common/escape.js.map +1 -1
  93. package/dist/src/common/export.d.ts +10 -0
  94. package/dist/src/common/export.d.ts.map +1 -1
  95. package/dist/src/common/export.js +123 -100
  96. package/dist/src/common/export.js.map +1 -1
  97. package/dist/src/common/input.d.ts.map +1 -1
  98. package/dist/src/common/input.js +8 -1
  99. package/dist/src/common/input.js.map +1 -1
  100. package/dist/src/common/json-elements.d.ts +12 -9
  101. package/dist/src/common/json-elements.d.ts.map +1 -1
  102. package/dist/src/common/json-elements.js +160 -37
  103. package/dist/src/common/json-elements.js.map +1 -1
  104. package/dist/src/common/notes.d.ts +42 -0
  105. package/dist/src/common/notes.d.ts.map +1 -0
  106. package/dist/src/common/notes.js +72 -0
  107. package/dist/src/common/notes.js.map +1 -0
  108. package/dist/src/common/report.d.ts +18 -0
  109. package/dist/src/common/report.d.ts.map +1 -1
  110. package/dist/src/common/report.js +36 -1
  111. package/dist/src/common/report.js.map +1 -1
  112. package/dist/src/common/units.d.ts +24 -0
  113. package/dist/src/common/units.d.ts.map +1 -0
  114. package/dist/src/common/units.js +26 -0
  115. package/dist/src/common/units.js.map +1 -0
  116. package/dist/src/common/xml.d.ts +18 -0
  117. package/dist/src/common/xml.d.ts.map +1 -1
  118. package/dist/src/common/xml.js +42 -5
  119. package/dist/src/common/xml.js.map +1 -1
  120. package/dist/src/formats/cx/exporter.d.ts +6 -0
  121. package/dist/src/formats/cx/exporter.d.ts.map +1 -1
  122. package/dist/src/formats/cx/exporter.js +71 -8
  123. package/dist/src/formats/cx/exporter.js.map +1 -1
  124. package/dist/src/formats/cx/importer.d.ts +5 -2
  125. package/dist/src/formats/cx/importer.d.ts.map +1 -1
  126. package/dist/src/formats/cx/importer.js +102 -72
  127. package/dist/src/formats/cx/importer.js.map +1 -1
  128. package/dist/src/formats/cx/styles.d.ts +102 -0
  129. package/dist/src/formats/cx/styles.d.ts.map +1 -0
  130. package/dist/src/formats/cx/styles.js +225 -0
  131. package/dist/src/formats/cx/styles.js.map +1 -0
  132. package/dist/src/formats/cx2/exporter.d.ts +5 -0
  133. package/dist/src/formats/cx2/exporter.d.ts.map +1 -1
  134. package/dist/src/formats/cx2/exporter.js +181 -71
  135. package/dist/src/formats/cx2/exporter.js.map +1 -1
  136. package/dist/src/formats/cx2/importer.d.ts +4 -1
  137. package/dist/src/formats/cx2/importer.d.ts.map +1 -1
  138. package/dist/src/formats/cx2/importer.js +19 -1
  139. package/dist/src/formats/cx2/importer.js.map +1 -1
  140. package/dist/src/formats/cx2/styles.d.ts +18 -0
  141. package/dist/src/formats/cx2/styles.d.ts.map +1 -0
  142. package/dist/src/formats/cx2/styles.js +24 -0
  143. package/dist/src/formats/cx2/styles.js.map +1 -0
  144. package/dist/src/formats/cys/constants.d.ts +2 -0
  145. package/dist/src/formats/cys/constants.d.ts.map +1 -1
  146. package/dist/src/formats/cys/constants.js +2 -0
  147. package/dist/src/formats/cys/constants.js.map +1 -1
  148. package/dist/src/formats/cys/exporter.d.ts +6 -2
  149. package/dist/src/formats/cys/exporter.d.ts.map +1 -1
  150. package/dist/src/formats/cys/exporter.js +215 -53
  151. package/dist/src/formats/cys/exporter.js.map +1 -1
  152. package/dist/src/formats/cys/importer.d.ts +2 -1
  153. package/dist/src/formats/cys/importer.d.ts.map +1 -1
  154. package/dist/src/formats/cys/importer.js +119 -6
  155. package/dist/src/formats/cys/importer.js.map +1 -1
  156. package/dist/src/formats/cys/session.d.ts +2 -0
  157. package/dist/src/formats/cys/session.d.ts.map +1 -1
  158. package/dist/src/formats/cys/session.js +5 -0
  159. package/dist/src/formats/cys/session.js.map +1 -1
  160. package/dist/src/formats/cys/styles.d.ts +38 -0
  161. package/dist/src/formats/cys/styles.d.ts.map +1 -0
  162. package/dist/src/formats/cys/styles.js +213 -0
  163. package/dist/src/formats/cys/styles.js.map +1 -0
  164. package/dist/src/formats/cys/tables.d.ts +8 -3
  165. package/dist/src/formats/cys/tables.d.ts.map +1 -1
  166. package/dist/src/formats/cys/tables.js +88 -34
  167. package/dist/src/formats/cys/tables.js.map +1 -1
  168. package/dist/src/formats/dot/exporter.d.ts +2 -0
  169. package/dist/src/formats/dot/exporter.d.ts.map +1 -1
  170. package/dist/src/formats/dot/exporter.js +195 -81
  171. package/dist/src/formats/dot/exporter.js.map +1 -1
  172. package/dist/src/formats/dot/importer.d.ts.map +1 -1
  173. package/dist/src/formats/dot/importer.js +100 -20
  174. package/dist/src/formats/dot/importer.js.map +1 -1
  175. package/dist/src/formats/dot/index.d.ts +1 -0
  176. package/dist/src/formats/dot/index.d.ts.map +1 -1
  177. package/dist/src/formats/dot/index.js +1 -0
  178. package/dist/src/formats/dot/index.js.map +1 -1
  179. package/dist/src/formats/dot/positions.d.ts +14 -0
  180. package/dist/src/formats/dot/positions.d.ts.map +1 -0
  181. package/dist/src/formats/dot/positions.js +70 -0
  182. package/dist/src/formats/dot/positions.js.map +1 -0
  183. package/dist/src/formats/dot/styles.d.ts +82 -0
  184. package/dist/src/formats/dot/styles.d.ts.map +1 -0
  185. package/dist/src/formats/dot/styles.js +1484 -0
  186. package/dist/src/formats/dot/styles.js.map +1 -0
  187. package/dist/src/formats/gexf/exporter.d.ts.map +1 -1
  188. package/dist/src/formats/gexf/exporter.js +23 -7
  189. package/dist/src/formats/gexf/exporter.js.map +1 -1
  190. package/dist/src/formats/gexf/importer.d.ts +8 -1
  191. package/dist/src/formats/gexf/importer.d.ts.map +1 -1
  192. package/dist/src/formats/gexf/importer.js +251 -131
  193. package/dist/src/formats/gexf/importer.js.map +1 -1
  194. package/dist/src/formats/gexf/index.d.ts +8 -0
  195. package/dist/src/formats/gexf/index.d.ts.map +1 -1
  196. package/dist/src/formats/gexf/index.js +10 -2
  197. package/dist/src/formats/gexf/index.js.map +1 -1
  198. package/dist/src/formats/gexf/schema.d.ts +5 -0
  199. package/dist/src/formats/gexf/schema.d.ts.map +1 -1
  200. package/dist/src/formats/gexf/schema.js +5 -0
  201. package/dist/src/formats/gexf/schema.js.map +1 -1
  202. package/dist/src/formats/gexf/styles.d.ts +74 -0
  203. package/dist/src/formats/gexf/styles.d.ts.map +1 -0
  204. package/dist/src/formats/gexf/styles.js +604 -0
  205. package/dist/src/formats/gexf/styles.js.map +1 -0
  206. package/dist/src/formats/gml/exporter.d.ts +1 -5
  207. package/dist/src/formats/gml/exporter.d.ts.map +1 -1
  208. package/dist/src/formats/gml/exporter.js +19 -8
  209. package/dist/src/formats/gml/exporter.js.map +1 -1
  210. package/dist/src/formats/gml/importer.d.ts.map +1 -1
  211. package/dist/src/formats/gml/importer.js +4 -0
  212. package/dist/src/formats/gml/importer.js.map +1 -1
  213. package/dist/src/formats/gml/index.d.ts +2 -1
  214. package/dist/src/formats/gml/index.d.ts.map +1 -1
  215. package/dist/src/formats/gml/index.js +2 -1
  216. package/dist/src/formats/gml/index.js.map +1 -1
  217. package/dist/src/formats/gml/positions.d.ts +14 -0
  218. package/dist/src/formats/gml/positions.d.ts.map +1 -0
  219. package/dist/src/formats/gml/positions.js +46 -0
  220. package/dist/src/formats/gml/positions.js.map +1 -0
  221. package/dist/src/formats/gml/styles.d.ts +59 -0
  222. package/dist/src/formats/gml/styles.d.ts.map +1 -0
  223. package/dist/src/formats/gml/styles.js +1056 -0
  224. package/dist/src/formats/gml/styles.js.map +1 -0
  225. package/dist/src/formats/gml/syntax.d.ts +11 -0
  226. package/dist/src/formats/gml/syntax.d.ts.map +1 -1
  227. package/dist/src/formats/gml/syntax.js +151 -62
  228. package/dist/src/formats/gml/syntax.js.map +1 -1
  229. package/dist/src/formats/graphml/constants.d.ts +4 -0
  230. package/dist/src/formats/graphml/constants.d.ts.map +1 -1
  231. package/dist/src/formats/graphml/constants.js +5 -1
  232. package/dist/src/formats/graphml/constants.js.map +1 -1
  233. package/dist/src/formats/graphml/exporter.d.ts.map +1 -1
  234. package/dist/src/formats/graphml/exporter.js +133 -65
  235. package/dist/src/formats/graphml/exporter.js.map +1 -1
  236. package/dist/src/formats/graphml/importer.d.ts +4 -1
  237. package/dist/src/formats/graphml/importer.d.ts.map +1 -1
  238. package/dist/src/formats/graphml/importer.js +100 -44
  239. package/dist/src/formats/graphml/importer.js.map +1 -1
  240. package/dist/src/formats/graphml/index.d.ts +1 -0
  241. package/dist/src/formats/graphml/index.d.ts.map +1 -1
  242. package/dist/src/formats/graphml/index.js +1 -0
  243. package/dist/src/formats/graphml/index.js.map +1 -1
  244. package/dist/src/formats/graphml/styles-plain.d.ts +19 -0
  245. package/dist/src/formats/graphml/styles-plain.d.ts.map +1 -0
  246. package/dist/src/formats/graphml/styles-plain.js +187 -0
  247. package/dist/src/formats/graphml/styles-plain.js.map +1 -0
  248. package/dist/src/formats/graphml/styles-yed.d.ts +179 -0
  249. package/dist/src/formats/graphml/styles-yed.d.ts.map +1 -0
  250. package/dist/src/formats/graphml/styles-yed.js +1086 -0
  251. package/dist/src/formats/graphml/styles-yed.js.map +1 -0
  252. package/dist/src/formats/graphml/styles-yfiles3.d.ts +19 -0
  253. package/dist/src/formats/graphml/styles-yfiles3.d.ts.map +1 -0
  254. package/dist/src/formats/graphml/styles-yfiles3.js +508 -0
  255. package/dist/src/formats/graphml/styles-yfiles3.js.map +1 -0
  256. package/dist/src/formats/graphml/tree.d.ts.map +1 -1
  257. package/dist/src/formats/graphml/tree.js +34 -19
  258. package/dist/src/formats/graphml/tree.js.map +1 -1
  259. package/dist/src/formats/graphml/yfiles.d.ts +16 -2
  260. package/dist/src/formats/graphml/yfiles.d.ts.map +1 -1
  261. package/dist/src/formats/graphml/yfiles.js +83 -12
  262. package/dist/src/formats/graphml/yfiles.js.map +1 -1
  263. package/dist/src/formats/json/exporter.d.ts +5 -0
  264. package/dist/src/formats/json/exporter.d.ts.map +1 -1
  265. package/dist/src/formats/json/exporter.js +68 -25
  266. package/dist/src/formats/json/exporter.js.map +1 -1
  267. package/dist/src/formats/json/importer.d.ts +22 -3
  268. package/dist/src/formats/json/importer.d.ts.map +1 -1
  269. package/dist/src/formats/json/importer.js +441 -265
  270. package/dist/src/formats/json/importer.js.map +1 -1
  271. package/dist/src/formats/json/positions.d.ts +16 -0
  272. package/dist/src/formats/json/positions.d.ts.map +1 -0
  273. package/dist/src/formats/json/positions.js +44 -0
  274. package/dist/src/formats/json/positions.js.map +1 -0
  275. package/dist/src/formats/json/styles.d.ts +102 -0
  276. package/dist/src/formats/json/styles.d.ts.map +1 -0
  277. package/dist/src/formats/json/styles.js +1753 -0
  278. package/dist/src/formats/json/styles.js.map +1 -0
  279. package/dist/src/formats/neo4j/exporter.d.ts.map +1 -1
  280. package/dist/src/formats/neo4j/exporter.js +2 -1
  281. package/dist/src/formats/neo4j/exporter.js.map +1 -1
  282. package/dist/src/formats/pajek/exporter.d.ts +2 -0
  283. package/dist/src/formats/pajek/exporter.d.ts.map +1 -1
  284. package/dist/src/formats/pajek/exporter.js +142 -76
  285. package/dist/src/formats/pajek/exporter.js.map +1 -1
  286. package/dist/src/formats/pajek/importer.d.ts +4 -0
  287. package/dist/src/formats/pajek/importer.d.ts.map +1 -1
  288. package/dist/src/formats/pajek/importer.js +60 -6
  289. package/dist/src/formats/pajek/importer.js.map +1 -1
  290. package/dist/src/formats/pajek/index.d.ts +2 -0
  291. package/dist/src/formats/pajek/index.d.ts.map +1 -1
  292. package/dist/src/formats/pajek/index.js +2 -0
  293. package/dist/src/formats/pajek/index.js.map +1 -1
  294. package/dist/src/formats/pajek/styles.d.ts +50 -0
  295. package/dist/src/formats/pajek/styles.d.ts.map +1 -0
  296. package/dist/src/formats/pajek/styles.js +569 -0
  297. package/dist/src/formats/pajek/styles.js.map +1 -0
  298. package/dist/src/formats/pajek/syntax.d.ts +6 -0
  299. package/dist/src/formats/pajek/syntax.d.ts.map +1 -1
  300. package/dist/src/formats/pajek/syntax.js +6 -0
  301. package/dist/src/formats/pajek/syntax.js.map +1 -1
  302. package/dist/src/formats/xgmml/columns.d.ts.map +1 -1
  303. package/dist/src/formats/xgmml/columns.js +34 -9
  304. package/dist/src/formats/xgmml/columns.js.map +1 -1
  305. package/dist/src/formats/xgmml/constants.d.ts +2 -0
  306. package/dist/src/formats/xgmml/constants.d.ts.map +1 -1
  307. package/dist/src/formats/xgmml/constants.js +3 -1
  308. package/dist/src/formats/xgmml/constants.js.map +1 -1
  309. package/dist/src/formats/xgmml/document.d.ts +12 -8
  310. package/dist/src/formats/xgmml/document.d.ts.map +1 -1
  311. package/dist/src/formats/xgmml/document.js +56 -13
  312. package/dist/src/formats/xgmml/document.js.map +1 -1
  313. package/dist/src/formats/xgmml/emit.d.ts.map +1 -1
  314. package/dist/src/formats/xgmml/emit.js +12 -6
  315. package/dist/src/formats/xgmml/emit.js.map +1 -1
  316. package/dist/src/formats/xgmml/exporter.d.ts +3 -1
  317. package/dist/src/formats/xgmml/exporter.d.ts.map +1 -1
  318. package/dist/src/formats/xgmml/exporter.js +22 -9
  319. package/dist/src/formats/xgmml/exporter.js.map +1 -1
  320. package/dist/src/formats/xgmml/importer.d.ts +2 -1
  321. package/dist/src/formats/xgmml/importer.d.ts.map +1 -1
  322. package/dist/src/formats/xgmml/importer.js +31 -24
  323. package/dist/src/formats/xgmml/importer.js.map +1 -1
  324. package/dist/src/formats/xgmml/styles.d.ts +104 -0
  325. package/dist/src/formats/xgmml/styles.d.ts.map +1 -0
  326. package/dist/src/formats/xgmml/styles.js +310 -0
  327. package/dist/src/formats/xgmml/styles.js.map +1 -0
  328. package/dist/src/index.d.ts +9 -7
  329. package/dist/src/index.d.ts.map +1 -1
  330. package/dist/src/index.js +7 -7
  331. package/dist/src/index.js.map +1 -1
  332. package/dist/src/positions/codes.d.ts +31 -0
  333. package/dist/src/positions/codes.d.ts.map +1 -0
  334. package/dist/src/positions/codes.js +26 -0
  335. package/dist/src/positions/codes.js.map +1 -0
  336. package/dist/src/positions/convert.d.ts +58 -0
  337. package/dist/src/positions/convert.d.ts.map +1 -0
  338. package/dist/src/positions/convert.js +107 -0
  339. package/dist/src/positions/convert.js.map +1 -0
  340. package/dist/src/positions/extract.d.ts +27 -0
  341. package/dist/src/positions/extract.d.ts.map +1 -0
  342. package/dist/src/positions/extract.js +526 -0
  343. package/dist/src/positions/extract.js.map +1 -0
  344. package/dist/src/positions/index.d.ts +10 -0
  345. package/dist/src/positions/index.d.ts.map +1 -0
  346. package/dist/src/positions/index.js +9 -0
  347. package/dist/src/positions/index.js.map +1 -0
  348. package/dist/src/positions/types.d.ts +208 -0
  349. package/dist/src/positions/types.d.ts.map +1 -0
  350. package/dist/src/positions/types.js +10 -0
  351. package/dist/src/positions/types.js.map +1 -0
  352. package/dist/src/registry.d.ts +30 -0
  353. package/dist/src/registry.d.ts.map +1 -1
  354. package/dist/src/registry.js +130 -9
  355. package/dist/src/registry.js.map +1 -1
  356. package/dist/src/styles/annotations.d.ts +132 -0
  357. package/dist/src/styles/annotations.d.ts.map +1 -0
  358. package/dist/src/styles/annotations.js +320 -0
  359. package/dist/src/styles/annotations.js.map +1 -0
  360. package/dist/src/styles/budget.d.ts +45 -0
  361. package/dist/src/styles/budget.d.ts.map +1 -0
  362. package/dist/src/styles/budget.js +58 -0
  363. package/dist/src/styles/budget.js.map +1 -0
  364. package/dist/src/styles/canon/bends.d.ts +32 -0
  365. package/dist/src/styles/canon/bends.d.ts.map +1 -0
  366. package/dist/src/styles/canon/bends.js +74 -0
  367. package/dist/src/styles/canon/bends.js.map +1 -0
  368. package/dist/src/styles/canon/color-tables.d.ts +22 -0
  369. package/dist/src/styles/canon/color-tables.d.ts.map +1 -0
  370. package/dist/src/styles/canon/color-tables.js +369 -0
  371. package/dist/src/styles/canon/color-tables.js.map +1 -0
  372. package/dist/src/styles/canon/color.d.ts +66 -0
  373. package/dist/src/styles/canon/color.d.ts.map +1 -0
  374. package/dist/src/styles/canon/color.js +548 -0
  375. package/dist/src/styles/canon/color.js.map +1 -0
  376. package/dist/src/styles/canon/enums.d.ts +25 -0
  377. package/dist/src/styles/canon/enums.d.ts.map +1 -0
  378. package/dist/src/styles/canon/enums.js +187 -0
  379. package/dist/src/styles/canon/enums.js.map +1 -0
  380. package/dist/src/styles/canon/graphviz.d.ts +48 -0
  381. package/dist/src/styles/canon/graphviz.d.ts.map +1 -0
  382. package/dist/src/styles/canon/graphviz.js +160 -0
  383. package/dist/src/styles/canon/graphviz.js.map +1 -0
  384. package/dist/src/styles/canon/index.d.ts +13 -0
  385. package/dist/src/styles/canon/index.d.ts.map +1 -0
  386. package/dist/src/styles/canon/index.js +13 -0
  387. package/dist/src/styles/canon/index.js.map +1 -0
  388. package/dist/src/styles/canon/number.d.ts +59 -0
  389. package/dist/src/styles/canon/number.d.ts.map +1 -0
  390. package/dist/src/styles/canon/number.js +142 -0
  391. package/dist/src/styles/canon/number.js.map +1 -0
  392. package/dist/src/styles/canon/site.d.ts +51 -0
  393. package/dist/src/styles/canon/site.d.ts.map +1 -0
  394. package/dist/src/styles/canon/site.js +63 -0
  395. package/dist/src/styles/canon/site.js.map +1 -0
  396. package/dist/src/styles/canon/text.d.ts +61 -0
  397. package/dist/src/styles/canon/text.d.ts.map +1 -0
  398. package/dist/src/styles/canon/text.js +199 -0
  399. package/dist/src/styles/canon/text.js.map +1 -0
  400. package/dist/src/styles/codes.d.ts +95 -0
  401. package/dist/src/styles/codes.d.ts.map +1 -0
  402. package/dist/src/styles/codes.js +97 -0
  403. package/dist/src/styles/codes.js.map +1 -0
  404. package/dist/src/styles/cyjs/cascade.d.ts +134 -0
  405. package/dist/src/styles/cyjs/cascade.d.ts.map +1 -0
  406. package/dist/src/styles/cyjs/cascade.js +2252 -0
  407. package/dist/src/styles/cyjs/cascade.js.map +1 -0
  408. package/dist/src/styles/cyjs/defaults-table.d.ts +25 -0
  409. package/dist/src/styles/cyjs/defaults-table.d.ts.map +1 -0
  410. package/dist/src/styles/cyjs/defaults-table.js +76 -0
  411. package/dist/src/styles/cyjs/defaults-table.js.map +1 -0
  412. package/dist/src/styles/cyjs/emit.d.ts +82 -0
  413. package/dist/src/styles/cyjs/emit.d.ts.map +1 -0
  414. package/dist/src/styles/cyjs/emit.js +790 -0
  415. package/dist/src/styles/cyjs/emit.js.map +1 -0
  416. package/dist/src/styles/cyjs/index.d.ts +13 -0
  417. package/dist/src/styles/cyjs/index.d.ts.map +1 -0
  418. package/dist/src/styles/cyjs/index.js +13 -0
  419. package/dist/src/styles/cyjs/index.js.map +1 -0
  420. package/dist/src/styles/cyjs/live.d.ts +46 -0
  421. package/dist/src/styles/cyjs/live.d.ts.map +1 -0
  422. package/dist/src/styles/cyjs/live.js +108 -0
  423. package/dist/src/styles/cyjs/live.js.map +1 -0
  424. package/dist/src/styles/cyjs/mappers.d.ts +147 -0
  425. package/dist/src/styles/cyjs/mappers.d.ts.map +1 -0
  426. package/dist/src/styles/cyjs/mappers.js +744 -0
  427. package/dist/src/styles/cyjs/mappers.js.map +1 -0
  428. package/dist/src/styles/cyjs/selector.d.ts +113 -0
  429. package/dist/src/styles/cyjs/selector.d.ts.map +1 -0
  430. package/dist/src/styles/cyjs/selector.js +611 -0
  431. package/dist/src/styles/cyjs/selector.js.map +1 -0
  432. package/dist/src/styles/cyjs/stylesheet-text.d.ts +37 -0
  433. package/dist/src/styles/cyjs/stylesheet-text.d.ts.map +1 -0
  434. package/dist/src/styles/cyjs/stylesheet-text.js +181 -0
  435. package/dist/src/styles/cyjs/stylesheet-text.js.map +1 -0
  436. package/dist/src/styles/cytoscape/emit.d.ts +125 -0
  437. package/dist/src/styles/cytoscape/emit.d.ts.map +1 -0
  438. package/dist/src/styles/cytoscape/emit.js +1025 -0
  439. package/dist/src/styles/cytoscape/emit.js.map +1 -0
  440. package/dist/src/styles/cytoscape/index.d.ts +10 -0
  441. package/dist/src/styles/cytoscape/index.d.ts.map +1 -0
  442. package/dist/src/styles/cytoscape/index.js +10 -0
  443. package/dist/src/styles/cytoscape/index.js.map +1 -0
  444. package/dist/src/styles/cytoscape/lexicon.d.ts +49 -0
  445. package/dist/src/styles/cytoscape/lexicon.d.ts.map +1 -0
  446. package/dist/src/styles/cytoscape/lexicon.js +603 -0
  447. package/dist/src/styles/cytoscape/lexicon.js.map +1 -0
  448. package/dist/src/styles/cytoscape/mappings.d.ts +171 -0
  449. package/dist/src/styles/cytoscape/mappings.d.ts.map +1 -0
  450. package/dist/src/styles/cytoscape/mappings.js +460 -0
  451. package/dist/src/styles/cytoscape/mappings.js.map +1 -0
  452. package/dist/src/styles/cytoscape/resolve.d.ts +137 -0
  453. package/dist/src/styles/cytoscape/resolve.d.ts.map +1 -0
  454. package/dist/src/styles/cytoscape/resolve.js +381 -0
  455. package/dist/src/styles/cytoscape/resolve.js.map +1 -0
  456. package/dist/src/styles/cytoscape/translate.d.ts +50 -0
  457. package/dist/src/styles/cytoscape/translate.d.ts.map +1 -0
  458. package/dist/src/styles/cytoscape/translate.js +156 -0
  459. package/dist/src/styles/cytoscape/translate.js.map +1 -0
  460. package/dist/src/styles/defaults.d.ts +90 -0
  461. package/dist/src/styles/defaults.d.ts.map +1 -0
  462. package/dist/src/styles/defaults.js +414 -0
  463. package/dist/src/styles/defaults.js.map +1 -0
  464. package/dist/src/styles/index.d.ts +15 -0
  465. package/dist/src/styles/index.d.ts.map +1 -0
  466. package/dist/src/styles/index.js +14 -0
  467. package/dist/src/styles/index.js.map +1 -0
  468. package/dist/src/styles/internal.d.ts +17 -0
  469. package/dist/src/styles/internal.d.ts.map +1 -0
  470. package/dist/src/styles/internal.js +16 -0
  471. package/dist/src/styles/internal.js.map +1 -0
  472. package/dist/src/styles/io/approximations.d.ts +24 -0
  473. package/dist/src/styles/io/approximations.d.ts.map +1 -0
  474. package/dist/src/styles/io/approximations.js +51 -0
  475. package/dist/src/styles/io/approximations.js.map +1 -0
  476. package/dist/src/styles/io/block.d.ts +166 -0
  477. package/dist/src/styles/io/block.d.ts.map +1 -0
  478. package/dist/src/styles/io/block.js +930 -0
  479. package/dist/src/styles/io/block.js.map +1 -0
  480. package/dist/src/styles/io/generic.d.ts +88 -0
  481. package/dist/src/styles/io/generic.d.ts.map +1 -0
  482. package/dist/src/styles/io/generic.js +516 -0
  483. package/dist/src/styles/io/generic.js.map +1 -0
  484. package/dist/src/styles/io/index.d.ts +8 -0
  485. package/dist/src/styles/io/index.d.ts.map +1 -0
  486. package/dist/src/styles/io/index.js +7 -0
  487. package/dist/src/styles/io/index.js.map +1 -0
  488. package/dist/src/styles/io/writer.d.ts +80 -0
  489. package/dist/src/styles/io/writer.d.ts.map +1 -0
  490. package/dist/src/styles/io/writer.js +596 -0
  491. package/dist/src/styles/io/writer.js.map +1 -0
  492. package/dist/src/styles/notes.d.ts +47 -0
  493. package/dist/src/styles/notes.d.ts.map +1 -0
  494. package/dist/src/styles/notes.js +140 -0
  495. package/dist/src/styles/notes.js.map +1 -0
  496. package/dist/src/styles/plan/classes.d.ts +31 -0
  497. package/dist/src/styles/plan/classes.d.ts.map +1 -0
  498. package/dist/src/styles/plan/classes.js +139 -0
  499. package/dist/src/styles/plan/classes.js.map +1 -0
  500. package/dist/src/styles/plan/continuous.d.ts +32 -0
  501. package/dist/src/styles/plan/continuous.d.ts.map +1 -0
  502. package/dist/src/styles/plan/continuous.js +165 -0
  503. package/dist/src/styles/plan/continuous.js.map +1 -0
  504. package/dist/src/styles/plan/discrete.d.ts +39 -0
  505. package/dist/src/styles/plan/discrete.d.ts.map +1 -0
  506. package/dist/src/styles/plan/discrete.js +127 -0
  507. package/dist/src/styles/plan/discrete.js.map +1 -0
  508. package/dist/src/styles/plan/families.d.ts +31 -0
  509. package/dist/src/styles/plan/families.d.ts.map +1 -0
  510. package/dist/src/styles/plan/families.js +95 -0
  511. package/dist/src/styles/plan/families.js.map +1 -0
  512. package/dist/src/styles/plan/features.d.ts +58 -0
  513. package/dist/src/styles/plan/features.d.ts.map +1 -0
  514. package/dist/src/styles/plan/features.js +185 -0
  515. package/dist/src/styles/plan/features.js.map +1 -0
  516. package/dist/src/styles/plan/index.d.ts +7 -0
  517. package/dist/src/styles/plan/index.d.ts.map +1 -0
  518. package/dist/src/styles/plan/index.js +7 -0
  519. package/dist/src/styles/plan/index.js.map +1 -0
  520. package/dist/src/styles/plan/plan.d.ts +71 -0
  521. package/dist/src/styles/plan/plan.d.ts.map +1 -0
  522. package/dist/src/styles/plan/plan.js +893 -0
  523. package/dist/src/styles/plan/plan.js.map +1 -0
  524. package/dist/src/styles/plan/resolve.d.ts +137 -0
  525. package/dist/src/styles/plan/resolve.d.ts.map +1 -0
  526. package/dist/src/styles/plan/resolve.js +587 -0
  527. package/dist/src/styles/plan/resolve.js.map +1 -0
  528. package/dist/src/styles/types.d.ts +702 -0
  529. package/dist/src/styles/types.d.ts.map +1 -0
  530. package/dist/src/styles/types.js +10 -0
  531. package/dist/src/styles/types.js.map +1 -0
  532. package/dist/src/styles/vocabulary.d.ts +41 -0
  533. package/dist/src/styles/vocabulary.d.ts.map +1 -0
  534. package/dist/src/styles/vocabulary.js +140 -0
  535. package/dist/src/styles/vocabulary.js.map +1 -0
  536. package/dist/src/types.d.ts +64 -1
  537. package/dist/src/types.d.ts.map +1 -1
  538. package/dist/src/types.js.map +1 -1
  539. package/dist/styles.d.ts +1 -0
  540. package/dist/styles.js +322 -0
  541. package/dist/styles.js.map +1 -0
  542. package/dist/xgmml.js +5 -4
  543. package/dist/xgmml.js.map +1 -1
  544. package/package.json +13 -2
  545. package/src/common/codes.ts +7 -0
  546. package/src/common/escape.ts +5 -2
  547. package/src/common/export.ts +179 -140
  548. package/src/common/input.ts +8 -4
  549. package/src/common/json-elements.ts +169 -38
  550. package/src/common/notes.ts +94 -0
  551. package/src/common/report.ts +41 -1
  552. package/src/common/units.ts +42 -0
  553. package/src/common/xml.ts +45 -5
  554. package/src/formats/cx/exporter.ts +95 -11
  555. package/src/formats/cx/importer.ts +126 -90
  556. package/src/formats/cx/styles.ts +304 -0
  557. package/src/formats/cx2/exporter.ts +234 -77
  558. package/src/formats/cx2/importer.ts +19 -1
  559. package/src/formats/cx2/styles.ts +29 -0
  560. package/src/formats/cys/constants.ts +3 -0
  561. package/src/formats/cys/exporter.ts +246 -60
  562. package/src/formats/cys/importer.ts +125 -9
  563. package/src/formats/cys/session.ts +6 -0
  564. package/src/formats/cys/styles.ts +254 -0
  565. package/src/formats/cys/tables.ts +117 -48
  566. package/src/formats/dot/exporter.ts +262 -126
  567. package/src/formats/dot/importer.ts +111 -20
  568. package/src/formats/dot/index.ts +1 -0
  569. package/src/formats/dot/positions.ts +77 -0
  570. package/src/formats/dot/styles.ts +1741 -0
  571. package/src/formats/gexf/exporter.ts +30 -13
  572. package/src/formats/gexf/importer.ts +308 -158
  573. package/src/formats/gexf/index.ts +10 -0
  574. package/src/formats/gexf/schema.ts +5 -0
  575. package/src/formats/gexf/styles.ts +719 -0
  576. package/src/formats/gml/exporter.ts +33 -14
  577. package/src/formats/gml/importer.ts +4 -0
  578. package/src/formats/gml/index.ts +2 -1
  579. package/src/formats/gml/positions.ts +52 -0
  580. package/src/formats/gml/styles.ts +1248 -0
  581. package/src/formats/gml/syntax.ts +173 -62
  582. package/src/formats/graphml/constants.ts +5 -0
  583. package/src/formats/graphml/exporter.ts +163 -71
  584. package/src/formats/graphml/importer.ts +119 -45
  585. package/src/formats/graphml/index.ts +1 -0
  586. package/src/formats/graphml/styles-plain.ts +236 -0
  587. package/src/formats/graphml/styles-yed.ts +1221 -0
  588. package/src/formats/graphml/styles-yfiles3.ts +573 -0
  589. package/src/formats/graphml/tree.ts +36 -20
  590. package/src/formats/graphml/yfiles.ts +89 -13
  591. package/src/formats/json/exporter.ts +76 -26
  592. package/src/formats/json/importer.ts +543 -323
  593. package/src/formats/json/positions.ts +50 -0
  594. package/src/formats/json/styles.ts +2082 -0
  595. package/src/formats/neo4j/exporter.ts +2 -1
  596. package/src/formats/pajek/exporter.ts +195 -106
  597. package/src/formats/pajek/importer.ts +78 -9
  598. package/src/formats/pajek/index.ts +2 -0
  599. package/src/formats/pajek/styles.ts +685 -0
  600. package/src/formats/pajek/syntax.ts +7 -0
  601. package/src/formats/xgmml/columns.ts +39 -9
  602. package/src/formats/xgmml/constants.ts +3 -0
  603. package/src/formats/xgmml/document.ts +54 -12
  604. package/src/formats/xgmml/emit.ts +11 -6
  605. package/src/formats/xgmml/exporter.ts +32 -13
  606. package/src/formats/xgmml/importer.ts +43 -29
  607. package/src/formats/xgmml/styles.ts +400 -0
  608. package/src/index.ts +16 -0
  609. package/src/positions/codes.ts +32 -0
  610. package/src/positions/convert.ts +123 -0
  611. package/src/positions/extract.ts +619 -0
  612. package/src/positions/index.ts +23 -0
  613. package/src/positions/types.ts +221 -0
  614. package/src/registry.ts +179 -8
  615. package/src/styles/annotations.ts +478 -0
  616. package/src/styles/budget.ts +60 -0
  617. package/src/styles/canon/bends.ts +84 -0
  618. package/src/styles/canon/color-tables.ts +386 -0
  619. package/src/styles/canon/color.ts +624 -0
  620. package/src/styles/canon/enums.ts +211 -0
  621. package/src/styles/canon/graphviz.ts +189 -0
  622. package/src/styles/canon/index.ts +13 -0
  623. package/src/styles/canon/number.ts +152 -0
  624. package/src/styles/canon/site.ts +87 -0
  625. package/src/styles/canon/text.ts +221 -0
  626. package/src/styles/codes.ts +104 -0
  627. package/src/styles/cyjs/cascade.ts +2670 -0
  628. package/src/styles/cyjs/defaults-table.ts +82 -0
  629. package/src/styles/cyjs/emit.ts +951 -0
  630. package/src/styles/cyjs/index.ts +37 -0
  631. package/src/styles/cyjs/live.ts +147 -0
  632. package/src/styles/cyjs/mappers.ts +879 -0
  633. package/src/styles/cyjs/selector.ts +778 -0
  634. package/src/styles/cyjs/stylesheet-text.ts +214 -0
  635. package/src/styles/cytoscape/emit.ts +1264 -0
  636. package/src/styles/cytoscape/index.ts +40 -0
  637. package/src/styles/cytoscape/lexicon.ts +656 -0
  638. package/src/styles/cytoscape/mappings.ts +603 -0
  639. package/src/styles/cytoscape/resolve.ts +521 -0
  640. package/src/styles/cytoscape/translate.ts +237 -0
  641. package/src/styles/defaults.ts +504 -0
  642. package/src/styles/index.ts +57 -0
  643. package/src/styles/internal.ts +17 -0
  644. package/src/styles/io/approximations.ts +47 -0
  645. package/src/styles/io/block.ts +1138 -0
  646. package/src/styles/io/generic.ts +687 -0
  647. package/src/styles/io/index.ts +18 -0
  648. package/src/styles/io/writer.ts +745 -0
  649. package/src/styles/notes.ts +165 -0
  650. package/src/styles/plan/classes.ts +166 -0
  651. package/src/styles/plan/continuous.ts +218 -0
  652. package/src/styles/plan/discrete.ts +165 -0
  653. package/src/styles/plan/families.ts +115 -0
  654. package/src/styles/plan/features.ts +234 -0
  655. package/src/styles/plan/index.ts +7 -0
  656. package/src/styles/plan/plan.ts +1129 -0
  657. package/src/styles/plan/resolve.ts +685 -0
  658. package/src/styles/types.ts +814 -0
  659. package/src/styles/vocabulary.ts +172 -0
  660. package/src/types.ts +76 -1
  661. package/dist/chunks/constants-fT3E8JYY.js.map +0 -1
  662. package/dist/chunks/escape-B62ZGM_a.js.map +0 -1
  663. package/dist/chunks/export-rKLeGQMo.js.map +0 -1
  664. package/dist/chunks/exporter-8hLNemFk.js.map +0 -1
  665. package/dist/chunks/exporter-BWwEuOPT.js.map +0 -1
  666. package/dist/chunks/exporter-CpRyHZ3H.js.map +0 -1
  667. package/dist/chunks/importer-BbNb7eNg.js.map +0 -1
  668. package/dist/chunks/importer-C98dpSH4.js.map +0 -1
  669. package/dist/chunks/importer-D794XUTe.js.map +0 -1
  670. package/dist/chunks/importer-Dz7tI8Sa.js.map +0 -1
  671. package/dist/chunks/importer-Ht7LNg8L.js.map +0 -1
  672. package/dist/chunks/importer-WrGRZb0N.js.map +0 -1
  673. package/dist/chunks/importer-xZ-3suY1.js.map +0 -1
  674. package/dist/chunks/json-elements-DKSqpNW1.js.map +0 -1
package/dist/gml.js CHANGED
@@ -1,3034 +1,11 @@
1
- import { ak as SYNTAX_CODE, b as plural, a as checkCapabilities, L as LOSS, p as pairFolding, $ as agree, c as capabilities, r as resolveExportOptions, ac as DictHeuristic, aG as formatInteger, bv as formatGmlReal, aE as sanitizeIds, bD as countMixedEdges, e as explicitWeights, bU as DICT_SAMPLE_ROWS, R as ROLE_TAKEN_CODE$1, aj as WIDENED_CODE$1, P as PRECISION_CODE$1, n as DUPLICATE_NODE_CODE$1, s as MISSING_ENDPOINT_CODE$1, t as MISSING_ID_CODE$1, l as MULTIPLE_GRAPHS_CODE, N as NO_GRAPH_CODE$1, al as resolveImportOptions, a8 as ImportReportBuilder, an as reportUnusedOptions, bB as readText, am as throwIfAborted, ao as reportSinkOptions, ap as graphChosen, ar as IdCoercer, aq as DirectionResolver, a0 as uniqueColumnName, C as COLUMN_RENAMED_CODE, as as weightFromValue, bV as reportWeightPrecision, aK as parseWeightText, a1 as declareResolved, M as MIXED_DIRECTION_CODE, D as DIRECTION_FORCED_CODE, d as DIRECTION_REFUSED_CODE, S as SINK_OPTION_CODE, O as OPTION_IGNORED_CODE, I as ID_MERGED_CODE, ae as AMBIGUOUS_GRAPH_NAME_CODE, af as GRAPH_NOT_FOUND_CODE, w as UNKNOWN_ENCODING_CODE, x as ENCODING_FALLBACK_CODE, y as INVALID_ENCODING_CODE, z as INVALID_UTF8_CODE, F as ELEMENT_ISSUE, G as INPUT_ISSUE } from "./chunks/export-rKLeGQMo.js";
2
- import { GraphFormatError, INVALID_INDEX } from "@graphty/graph-format";
3
- import { k as decodeGmlString, m as quoteGmlString } from "./chunks/escape-B62ZGM_a.js";
4
- import { j as joinText, e as encodeChunks } from "./chunks/writer-DxjgHwSe.js";
5
- import { i as importChosenGraph } from "./chunks/choose-DvpbdRuz.js";
6
- const TOKEN_WORD = 0;
7
- const TOKEN_INT = 1;
8
- const TOKEN_REAL = 2;
9
- const TOKEN_STRING = 3;
10
- const TOKEN_OPEN = 4;
11
- const TOKEN_CLOSE = 5;
12
- const LIST_START_MARKER = "_networkx_list_start";
13
- const EMPTY_LIST_TEXT = "[]";
14
- const EMPTY_TUPLE_TEXT = "()";
15
- const ORIGINAL_ID_KEY = "graphty_originalId";
16
- const SYNTAX_STRUCTURE_CODE = SYNTAX_CODE;
17
- const SYNTAX_TOKEN_CODE = SYNTAX_CODE;
18
- const SYNTAX_STRING_CODE = SYNTAX_CODE;
19
- const SYNTAX_BRACKET_CODE = SYNTAX_CODE;
20
- const KEY_TEXT = /^[A-Za-z_]\w*$/;
21
- const STRICT_KEY_TEXT = /^[A-Za-z]\w*$/;
22
- const INT_TEXT = /^[+-]?\d+$/;
23
- const REAL_TEXT = /^[+-]?(?:(?:\d+\.\d*|\.\d+)(?:[eE][+-]?\d+)?|\d+[eE][+-]?\d+)$/;
24
- const NON_FINITE_TEXT = /^[+-]?(?:inf|infinity|nan)$/i;
25
- const NON_FINITE_WORD = /^(?:inf|infinity|nan)$/i;
26
- class GmlSyntaxError extends Error {
27
- /**
28
- * Create a syntax error.
29
- * @param code - the issue code
30
- * @param message - a plain-ASCII message
31
- * @param line - the 1-based line
32
- */
33
- constructor(code, message, line) {
34
- super(message);
35
- this.name = "GmlSyntaxError";
36
- this.code = code;
37
- this.line = line;
38
- }
39
- }
40
- class GmlTokens {
41
- /**
42
- * Create an empty token list over a text.
43
- * @param text - the source text
44
- * @param capacity - the initial capacity
45
- */
46
- constructor(text, capacity = 1024) {
47
- this.count = 0;
48
- this.onUnknownEntity = null;
49
- this.text = text;
50
- this.kind = new Uint8Array(capacity);
51
- this.start = new Uint32Array(capacity);
52
- this.end = new Uint32Array(capacity);
53
- this.line = new Uint32Array(capacity);
54
- this.match = new Uint32Array(0);
55
- }
56
- /**
57
- * Append a token.
58
- * @param kind - the kind
59
- * @param start - the start offset
60
- * @param end - the end offset
61
- * @param line - the 1-based line
62
- */
63
- push(kind, start, end, line) {
64
- if (this.count === this.kind.length) {
65
- this.grow();
66
- }
67
- const i = this.count++;
68
- this.kind[i] = kind;
69
- this.start[i] = start;
70
- this.end[i] = end;
71
- this.line[i] = line;
72
- }
73
- /**
74
- * The raw text of a token (a string's body without the quotes, entities undecoded).
75
- * @param i - the token index
76
- * @returns the text
77
- */
78
- textOf(i) {
79
- return this.text.slice(this.start[i], this.end[i]);
80
- }
81
- /**
82
- * The decoded value of a string token.
83
- * @param i - the token index
84
- * @returns the body with character references decoded
85
- */
86
- stringOf(i) {
87
- let text = this.textOf(i);
88
- if (text.includes("\r")) {
89
- text = text.replaceAll(/\r\n?/g, "\n");
90
- }
91
- if (!text.includes("&")) {
92
- return text;
93
- }
94
- const report = this.onUnknownEntity;
95
- return decodeGmlString(
96
- text,
97
- report === null ? void 0 : (entity) => {
98
- report(entity, this.line[i]);
99
- }
100
- );
101
- }
102
- /**
103
- * Whether a token is a `[` or `]`.
104
- * @param i - the token index
105
- * @returns true for a bracket
106
- */
107
- isBracket(i) {
108
- return this.kind[i] >= TOKEN_OPEN;
109
- }
110
- /**
111
- * The index of the pair following the pair whose key is at `key`.
112
- * @param key - the index of a key token
113
- * @returns the index after the pair's value (after the matching `]` for a record)
114
- */
115
- nextPair(key) {
116
- const value = key + 1;
117
- return this.kind[value] === TOKEN_OPEN ? this.match[value] + 1 : value + 1;
118
- }
119
- /** Double every array. */
120
- grow() {
121
- const capacity = this.kind.length * 2;
122
- const kind = new Uint8Array(capacity);
123
- kind.set(this.kind);
124
- this.kind = kind;
125
- const start = new Uint32Array(capacity);
126
- start.set(this.start);
127
- this.start = start;
128
- const end = new Uint32Array(capacity);
129
- end.set(this.end);
130
- this.end = end;
131
- const line = new Uint32Array(capacity);
132
- line.set(this.line);
133
- this.line = line;
134
- }
135
- }
136
- function tokenizeGml(text) {
137
- const tokens = new GmlTokens(text, Math.max(1024, text.length >>> 3));
138
- const n = text.length;
139
- let i = 0;
140
- let line = 1;
141
- let spanningLine = 0;
142
- while (i < n) {
143
- const c = text.charCodeAt(i);
144
- if (c === 10) {
145
- line++;
146
- i++;
147
- } else if (c === 13) {
148
- line++;
149
- i++;
150
- if (i < n && text.charCodeAt(i) === 10) {
151
- i++;
152
- }
153
- } else if (c === 32 || c === 9 || c === 11 || c === 12) {
154
- i++;
155
- } else if (c === 65279) {
156
- i++;
157
- } else if (c === 35) {
158
- i = endOfLine(text, i);
159
- } else if (c === 91) {
160
- tokens.push(TOKEN_OPEN, i, i + 1, line);
161
- i++;
162
- } else if (c === 93) {
163
- tokens.push(TOKEN_CLOSE, i, i + 1, line);
164
- i++;
165
- } else if (c === 34) {
166
- const close = text.indexOf('"', i + 1);
167
- if (close < 0) {
168
- const hint = spanningLine === 0 ? "" : `; the string opened at line ${spanningLine} spans lines, so a quote may be missing there`;
169
- throw new GmlSyntaxError(SYNTAX_STRING_CODE, `unclosed string opened at line ${line}${hint}`, line);
170
- }
171
- tokens.push(TOKEN_STRING, i + 1, close, line);
172
- const opened = line;
173
- for (let k = i + 1; k < close; k++) {
174
- const d = text.codePointAt(k);
175
- if (d === 10 || d === 13 && text.codePointAt(k + 1) !== 10) {
176
- line++;
177
- }
178
- }
179
- if (line !== opened && spanningLine === 0) {
180
- spanningLine = opened;
181
- }
182
- i = close + 1;
183
- } else {
184
- let j = i + 1;
185
- while (j < n && !isDelimiter(text.charCodeAt(j))) {
186
- j++;
187
- }
188
- tokens.push(classifyBare(text, i, j, line), i, j, line);
189
- i = j;
190
- }
191
- }
192
- validateStructure(tokens);
193
- return tokens;
194
- }
195
- function endOfLine(text, from) {
196
- const n = text.length;
197
- for (let i = from; i < n; i++) {
198
- const c = text.charCodeAt(i);
199
- if (c === 10 || c === 13) {
200
- return i;
201
- }
202
- }
203
- return n;
204
- }
205
- function isDelimiter(c) {
206
- return c === 32 || c === 9 || c === 10 || c === 13 || c === 11 || c === 12 || c === 91 || c === 93 || c === 34 || c === 35;
207
- }
208
- function classifyBare(text, start, end, line) {
209
- const token = text.slice(start, end);
210
- if (KEY_TEXT.test(token)) {
211
- return TOKEN_WORD;
212
- }
213
- if (INT_TEXT.test(token)) {
214
- return TOKEN_INT;
215
- }
216
- if (REAL_TEXT.test(token) || NON_FINITE_TEXT.test(token)) {
217
- return TOKEN_REAL;
218
- }
219
- const hex = (c) => (c.codePointAt(0) ?? 0).toString(16).toUpperCase().padStart(4, "0");
220
- const head = token.length > 20 ? `${token.slice(0, 20)}...` : token;
221
- const shown = head.replaceAll(/[^\x20-\x7e]/gu, (c) => String.raw`\u` + hex(c));
222
- const odd = /[^\x21-\x7e]/u.exec(token);
223
- const note2 = odd === null ? "" : ` (it holds U+${hex(odd[0])}, which GML allows only inside a string)`;
224
- throw new GmlSyntaxError(SYNTAX_TOKEN_CODE, `cannot tokenize "${shown}" at line ${line}${note2}`, line);
225
- }
226
- function validateStructure(tokens) {
227
- const { count, kind } = tokens;
228
- const match = new Uint32Array(count);
229
- const stack = [];
230
- let i = 0;
231
- while (i < count) {
232
- const k = kind[i];
233
- if (k === TOKEN_CLOSE) {
234
- const open = stack.pop();
235
- if (open === void 0) {
236
- throw new GmlSyntaxError(
237
- SYNTAX_STRUCTURE_CODE,
238
- `unexpected "]" at line ${tokens.line[i]}: no open "["`,
239
- tokens.line[i]
240
- );
241
- }
242
- match[open] = i;
243
- i++;
244
- continue;
245
- }
246
- if (k !== TOKEN_WORD) {
247
- throw new GmlSyntaxError(
248
- SYNTAX_STRUCTURE_CODE,
249
- `expected a key at line ${tokens.line[i]}, found ${describeToken(tokens, i)}`,
250
- tokens.line[i]
251
- );
252
- }
253
- const value = i + 1;
254
- if (value >= count) {
255
- throw new GmlSyntaxError(
256
- SYNTAX_STRUCTURE_CODE,
257
- `key "${tokens.textOf(i)}" at line ${tokens.line[i]} has no value`,
258
- tokens.line[i]
259
- );
260
- }
261
- const vk = kind[value];
262
- if (vk === TOKEN_OPEN) {
263
- stack.push(value);
264
- } else if (vk === TOKEN_CLOSE || vk === TOKEN_WORD && !NON_FINITE_WORD.test(tokens.textOf(value))) {
265
- throw new GmlSyntaxError(
266
- SYNTAX_STRUCTURE_CODE,
267
- `expected a value for key "${tokens.textOf(i)}" at line ${tokens.line[i]}, found ${describeToken(tokens, value)}`,
268
- tokens.line[value]
269
- );
270
- }
271
- i = value + 1;
272
- }
273
- if (stack.length > 0) {
274
- const open = stack[stack.length - 1];
275
- throw new GmlSyntaxError(
276
- SYNTAX_BRACKET_CODE,
277
- `unexpected end of input: ${stack.length} bracket${plural(stack.length)} still open, the last opened at line ${tokens.line[open]}`,
278
- tokens.line[open]
279
- );
280
- }
281
- tokens.match = match;
282
- }
283
- function describeToken(tokens, i) {
284
- switch (tokens.kind[i]) {
285
- case TOKEN_OPEN:
286
- return '"["';
287
- case TOKEN_CLOSE:
288
- return '"]"';
289
- case TOKEN_STRING:
290
- return `the string "${tokens.textOf(i)}"`;
291
- default:
292
- return `"${tokens.textOf(i)}"`;
293
- }
294
- }
295
- function numberOfText(text) {
296
- if (NON_FINITE_TEXT.test(text)) {
297
- const lower = text.toLowerCase();
298
- if (lower.endsWith("nan")) {
299
- return Number.NaN;
300
- }
301
- return lower.startsWith("-") ? -Infinity : Infinity;
302
- }
303
- return Number(text);
304
- }
305
- function isGmlKey(text) {
306
- return STRICT_KEY_TEXT.test(text);
307
- }
308
- function mangleGmlKey(text) {
309
- const body = text.replaceAll(/\W/g, "_");
310
- return /^[A-Za-z]/.test(body) ? body : `x${body}`;
311
- }
312
- function parseRecord(tokens, open) {
313
- const root = /* @__PURE__ */ Object.create(null);
314
- const stack = [
315
- { record: root, listKeys: null, close: tokens.match[open], next: open + 1, key: null }
316
- ];
317
- while (stack.length > 0) {
318
- const frame = stack[stack.length - 1];
319
- if (frame.next >= frame.close) {
320
- stack.pop();
321
- if (frame.key !== null) {
322
- storeValue(stack[stack.length - 1], frame.key, frame.record);
323
- }
324
- continue;
325
- }
326
- const p = frame.next;
327
- frame.next = tokens.nextPair(p);
328
- const key = tokens.textOf(p);
329
- const v = p + 1;
330
- if (tokens.kind[v] === TOKEN_STRING) {
331
- storeString(frame, key, tokens.stringOf(v));
332
- } else if (tokens.kind[v] === TOKEN_OPEN) {
333
- stack.push({
334
- record: /* @__PURE__ */ Object.create(null),
335
- listKeys: null,
336
- close: tokens.match[v],
337
- next: v + 1,
338
- key
339
- });
340
- } else {
341
- storeValue(frame, key, numberOfText(tokens.textOf(v)));
342
- }
343
- }
344
- return root;
345
- }
346
- function storeString(frame, key, text) {
347
- if (text === LIST_START_MARKER) {
348
- frame.record[key] = [];
349
- frame.listKeys ??= /* @__PURE__ */ new Set();
350
- frame.listKeys.add(key);
351
- return;
352
- }
353
- storeValue(frame, key, text === EMPTY_LIST_TEXT || text === EMPTY_TUPLE_TEXT ? [] : text);
354
- }
355
- function storeValue(frame, key, value) {
356
- const { record } = frame;
357
- if (frame.listKeys?.has(key)) {
358
- record[key].push(value);
359
- } else if (key in record) {
360
- record[key] = [record[key], value];
361
- frame.listKeys ??= /* @__PURE__ */ new Set();
362
- frame.listKeys.add(key);
363
- } else {
364
- record[key] = value;
365
- }
366
- }
367
- function scalarOrRecord(tokens, v) {
368
- return tokens.kind[v] === TOKEN_OPEN ? parseRecord(tokens, v) : numberOfText(tokens.textOf(v));
369
- }
370
- const RECORD_NUMBER_TYPE_CODE = "W_GML_RECORD_NUMBER_TYPE";
371
- const RECORD_BOOLEAN_CODE = "W_GML_RECORD_BOOLEAN";
372
- const RECORD_NULL_CODE = "W_GML_RECORD_NULL";
373
- const NESTED_ARRAY_CODE = "E_GML_NESTED_ARRAY";
374
- const JSON_ARRAY_CODE = "W_GML_JSON_ARRAY";
375
- const INVALID_KEY_CODE = "E_GML_INVALID_KEY";
376
- const RESERVED_KEY_CODE = "E_GML_RESERVED_KEY";
377
- const KEY_MANGLED_CODE = "W_GML_KEY_MANGLED";
378
- const POSITION_COMPONENTS_CODE = "W_GML_POSITION_COMPONENTS";
379
- const GRAPHICS_OVERRIDDEN_CODE = "W_GML_GRAPHICS_OVERRIDDEN";
380
- const GRAPHICS_CONFLICT_CODE = "E_GML_GRAPHICS_CONFLICT";
381
- const DEFAULT_WEIGHT_KEY = "value";
382
- const KEPT_ROLES = /* @__PURE__ */ new Set(["label", "id", "key"]);
383
- const ROLE_NAMES = Object.freeze({
384
- label: "label",
385
- id: "id",
386
- key: "key"
387
- });
388
- const GML_CAPABILITIES = capabilities({
389
- mixedDirection: false,
390
- multiEdges: true,
391
- selfLoops: true,
392
- edgeIds: "optional",
393
- idCharset: "integer",
394
- dtypes: ["i32", "f64", "string", "dict", "json"],
395
- components: false,
396
- lists: true,
397
- json: true,
398
- defaults: false,
399
- options: false,
400
- hierarchy: false,
401
- temporal: "none",
402
- graphAttributes: true,
403
- positions: true,
404
- viz: false
405
- });
406
- const SKIPPED_ROLES = /* @__PURE__ */ new Set([
407
- "directed",
408
- "pair",
409
- "mutual",
410
- "weight",
411
- "timeText",
412
- "originalId",
413
- "position",
414
- "color",
415
- "size",
416
- "shape",
417
- "thickness",
418
- "parent",
419
- "parents",
420
- "start",
421
- "end",
422
- "timestamp",
423
- "timestamps",
424
- "spells",
425
- "open",
426
- "spellsOpen"
427
- ]);
428
- const NODE_RESERVED = /* @__PURE__ */ new Set(["id"]);
429
- const EDGE_RESERVED = /* @__PURE__ */ new Set(["source", "target", "directed"]);
430
- const GRAPH_RESERVED = /* @__PURE__ */ new Set(["node", "edge", "directed", "multigraph"]);
431
- const TOP_RESERVED = /* @__PURE__ */ new Set(["graph"]);
432
- const NUMBER_TEXT = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/;
433
- function planOf(snapshot, options) {
434
- const common = resolveExportOptions(options);
435
- const mode = options?.sanitizeKeys ?? "error";
436
- if (mode !== "error" && mode !== "mangle") {
437
- throw new GraphFormatError(
438
- "E_UNSUPPORTED",
439
- `option sanitizeKeys: ${JSON.stringify(mode)} is not "error" or "mangle"`,
440
- {
441
- option: "sanitizeKeys",
442
- found: mode
443
- }
444
- );
445
- }
446
- let weightKey = options?.weightKey;
447
- if (weightKey === void 0) {
448
- const origin = snapshot.meta.weightOrigin;
449
- weightKey = origin !== null && origin.format === "gml" && origin.id !== null ? origin.id : DEFAULT_WEIGHT_KEY;
450
- } else if (typeof weightKey !== "string" || !isGmlKey(weightKey)) {
451
- throw new GraphFormatError("E_UNSUPPORTED", `option weightKey: ${JSON.stringify(weightKey)} is not a GML key`, {
452
- option: "weightKey",
453
- found: weightKey
454
- });
455
- }
456
- return { common, weightKey, mangle: mode === "mangle" };
457
- }
458
- function isWritten(column) {
459
- const { role } = column.meta;
460
- return role === null || !SKIPPED_ROLES.has(role);
461
- }
462
- function preferredKey(meta) {
463
- const { origin, name } = meta;
464
- if (origin?.format !== "gml" || origin.id === null) {
465
- return name;
466
- }
467
- return name === origin.id || name.startsWith(`${origin.id}#`) ? origin.id : name;
468
- }
469
- function hasWeights(snapshot) {
470
- return snapshot.flags.weighted;
471
- }
472
- function isTopLevel(column) {
473
- return column.meta.extra.gmlTopLevel === true;
474
- }
475
- function versionText(text) {
476
- return NUMBER_TEXT.test(text) ? text : quoteGmlString(text);
477
- }
478
- function labelRoleColumn(columns, label, used) {
479
- if (label !== "node" && label !== "edge") {
480
- return void 0;
481
- }
482
- const column = columns.find((c) => c.meta.role === "label");
483
- if (column !== void 0) {
484
- used.add("label");
485
- }
486
- return column;
487
- }
488
- function selectColumns(table, reserved, label, plan, notes, filter = () => true) {
489
- const used = new Set(reserved);
490
- const out = [];
491
- const columns = [...table].filter((c) => isWritten(c) && filter(c));
492
- const labelRole = labelRoleColumn(columns, label, used);
493
- for (const column of columns) {
494
- const preferred = column === labelRole ? "label" : preferredKey(column.meta);
495
- let key = preferred;
496
- const valid = isGmlKey(preferred);
497
- const taken = column !== labelRole && used.has(preferred);
498
- if (!valid || taken) {
499
- const code = valid ? RESERVED_KEY_CODE : INVALID_KEY_CODE;
500
- let why = "is not a GML key";
501
- if (valid) {
502
- why = reserved.has(preferred) ? "collides with a structural GML key" : "repeats another column's key";
503
- }
504
- if (!plan.mangle) {
505
- if (notes === null) {
506
- throw new GraphFormatError(
507
- "E_UNSUPPORTED",
508
- `${label} column "${column.meta.name}" ${why}; pass sanitizeKeys: "mangle" to rewrite it`,
509
- {
510
- reason: "gml key",
511
- column: column.meta.name,
512
- key: preferred
513
- }
514
- );
515
- }
516
- notes.push(
517
- note(
518
- code,
519
- `${label} column "${column.meta.name}" ${why}; the save fails unless sanitizeKeys is "mangle"`,
520
- column.meta.name
521
- )
522
- );
523
- continue;
524
- }
525
- key = uniqueKey(valid ? preferred : mangleGmlKey(preferred), used);
526
- notes?.push(
527
- note(
528
- KEY_MANGLED_CODE,
529
- `${label} column "${column.meta.name}" is written as "${key}"`,
530
- column.meta.name
531
- )
532
- );
533
- }
534
- used.add(key);
535
- out.push({ column, key });
536
- }
537
- return out;
538
- }
539
- function uniqueKey(base, used) {
540
- let candidate = base;
541
- for (let k = 2; used.has(candidate); k++) {
542
- candidate = `${base}_${k}`;
543
- }
544
- return candidate;
545
- }
546
- function note(code, message, column = null, count = null) {
547
- return Object.freeze({ code, message, column, count });
548
- }
549
- function countOnce(seen, flag, stats, counter) {
550
- if (!seen[flag]) {
551
- seen[flag] = true;
552
- stats[counter]++;
553
- }
554
- }
555
- function inspectJson(value, stats, inArray, seen) {
556
- if (value === null) {
557
- countOnce(seen, "nulls", stats, "nulls");
558
- return;
559
- }
560
- switch (typeof value) {
561
- case "number":
562
- countOnce(seen, "numbers", stats, "numbers");
563
- return;
564
- case "boolean":
565
- countOnce(seen, "booleans", stats, "booleans");
566
- return;
567
- case "string":
568
- return;
569
- }
570
- if (Array.isArray(value)) {
571
- if (inArray) {
572
- countOnce(seen, "nested", stats, "nestedArrays");
573
- }
574
- for (const item of value) {
575
- inspectJson(item, stats, true, seen);
576
- }
577
- return;
578
- }
579
- const record = value;
580
- for (const key of Object.keys(record)) {
581
- if (!isGmlKey(key)) {
582
- stats.invalidKeys++;
583
- }
584
- inspectJson(record[key], stats, false, seen);
585
- }
586
- }
587
- function rowCount(count) {
588
- return `${count} row${plural(count)}`;
589
- }
590
- function pushCounted(notes, count, code, text, column) {
591
- if (count > 0) {
592
- notes.push(note(code, text, column, count));
593
- }
594
- }
595
- function jsonNotes(columns, label, plan, notes) {
596
- for (const { column } of columns) {
597
- const stats = jsonStatsOf(column);
598
- if (stats === null) {
599
- continue;
600
- }
601
- const { name } = column.meta;
602
- const where = `${label} column "${name}"`;
603
- const counted = (count, code, text) => {
604
- pushCounted(notes, count, code, text, name);
605
- };
606
- counted(
607
- stats.numbers,
608
- RECORD_NUMBER_TYPE_CODE,
609
- `${where} holds numbers in ${rowCount(stats.numbers)}; GML records cannot keep the int / real distinction`
610
- );
611
- counted(
612
- stats.booleans,
613
- RECORD_BOOLEAN_CODE,
614
- `${where} holds booleans in ${rowCount(stats.booleans)}; written as 1 / 0`
615
- );
616
- counted(
617
- stats.nulls,
618
- RECORD_NULL_CODE,
619
- `${where} holds nulls in ${rowCount(stats.nulls)}; GML has no null, the key is omitted`
620
- );
621
- counted(
622
- stats.arrays,
623
- JSON_ARRAY_CODE,
624
- `${where} holds arrays as values in ${rowCount(stats.arrays)}; written as repeated keys, they re-import as a list`
625
- );
626
- counted(
627
- stats.nestedArrays,
628
- NESTED_ARRAY_CODE,
629
- `${where} holds arrays nested in arrays in ${rowCount(stats.nestedArrays)}; GML cannot write them and the save fails`
630
- );
631
- const keys = `${stats.invalidKeys} record key${plural(stats.invalidKeys)} ${agree(stats.invalidKeys, "is", "are")} not GML keys`;
632
- counted(
633
- stats.invalidKeys,
634
- plan.mangle ? KEY_MANGLED_CODE : INVALID_KEY_CODE,
635
- plan.mangle ? `${where}: ${keys} and are rewritten` : `${where}: ${keys}; the save fails unless sanitizeKeys is "mangle"`
636
- );
637
- }
638
- }
639
- function jsonStatsOf(column) {
640
- const stats = { numbers: 0, booleans: 0, nulls: 0, nestedArrays: 0, arrays: 0, invalidKeys: 0 };
641
- if (column.dtype === "json") {
642
- for (let r = 0; r < column.length; r++) {
643
- if (!column.isSet(r)) {
644
- continue;
645
- }
646
- const value = column.values[r];
647
- const seen = { numbers: false, booleans: false, nulls: false, nested: false };
648
- if (Array.isArray(value)) {
649
- stats.arrays++;
650
- for (const item of value) {
651
- inspectJson(item, stats, true, seen);
652
- }
653
- } else {
654
- inspectJson(value, stats, false, seen);
655
- }
656
- }
657
- return stats;
658
- }
659
- if (column.dtype === "list" && column.meta.itemDtype === "json") {
660
- for (let r = 0; r < column.length; r++) {
661
- if (!column.isSet(r)) {
662
- continue;
663
- }
664
- const seen = { numbers: false, booleans: false, nulls: false, nested: false };
665
- for (const item of column.sliceOf(r)) {
666
- inspectJson(item, stats, true, seen);
667
- }
668
- }
669
- return stats;
670
- }
671
- return null;
672
- }
673
- function positionColumn(snapshot) {
674
- const column = snapshot.nodes.byRole("position");
675
- if (column === null) {
676
- return null;
677
- }
678
- switch (column.dtype) {
679
- case "f32":
680
- case "f64":
681
- case "i32":
682
- case "u32":
683
- case "u8":
684
- return column;
685
- default:
686
- return null;
687
- }
688
- }
689
- function graphicsColumn(snapshot) {
690
- return snapshot.nodes.typed("graphics", "json");
691
- }
692
- function graphicsNotes(snapshot, notes) {
693
- const position = positionColumn(snapshot);
694
- if (position === null) {
695
- return;
696
- }
697
- if (position.meta.components > 3) {
698
- notes.push(
699
- note(
700
- POSITION_COMPONENTS_CODE,
701
- `node column "${position.meta.name}" has ${position.meta.components} components; only x, y and z are written`,
702
- position.meta.name,
703
- position.length - position.nullCount
704
- )
705
- );
706
- }
707
- const graphics = graphicsColumn(snapshot);
708
- if (graphics === null) {
709
- return;
710
- }
711
- let overridden = 0;
712
- let conflicts = 0;
713
- for (let r = 0; r < snapshot.nodeCount; r++) {
714
- if (!position.isSet(r) || !graphics.isSet(r)) {
715
- continue;
716
- }
717
- const value = graphics.values[r];
718
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
719
- conflicts++;
720
- } else if ("x" in value || "y" in value || "z" in value) {
721
- overridden++;
722
- }
723
- }
724
- if (overridden > 0) {
725
- notes.push(
726
- note(
727
- GRAPHICS_OVERRIDDEN_CODE,
728
- `${overridden} node graphics record${plural(overridden)} ${agree(overridden, "has", "have")} x / y / z keys the position column replaces`,
729
- "graphics",
730
- overridden
731
- )
732
- );
733
- }
734
- if (conflicts > 0) {
735
- notes.push(
736
- note(
737
- GRAPHICS_CONFLICT_CODE,
738
- `${conflicts} node graphics value${plural(conflicts)} ${agree(conflicts, "is", "are")} not records and cannot hold the position; the save fails`,
739
- "graphics",
740
- conflicts
741
- )
742
- );
743
- }
744
- }
745
- function reimportNotes(columns, domain, notes) {
746
- for (const { column, key } of columns) {
747
- const { meta } = column;
748
- const set = column.length - column.nullCount;
749
- if (set === 0) {
750
- notes.push(
751
- note(
752
- LOSS.EMPTY_COLUMN,
753
- `${domain} column "${meta.name}" has no set cell and is not written: GML writes cells, never declarations`,
754
- meta.name,
755
- 0
756
- )
757
- );
758
- continue;
759
- }
760
- if (meta.role === null && (key === "label" || domain === "edge" && (key === "id" || key === "key"))) {
761
- notes.push(
762
- note(
763
- LOSS.ROLE_ASSUMED,
764
- `${domain} column "${meta.name}" is written under "${key}" and reads back with the ${key === "label" ? "label" : key} role`,
765
- meta.name,
766
- set
767
- )
768
- );
769
- continue;
770
- }
771
- if (column.dtype === "list" || !(column.dtype === "string" || column.dtype === "dict")) {
772
- continue;
773
- }
774
- const heuristic = new DictHeuristic(DICT_SAMPLE_ROWS);
775
- for (let r = 0; r < column.length && !heuristic.decided; r++) {
776
- if (column.isSet(r)) {
777
- heuristic.observe(column.value(r));
778
- }
779
- }
780
- const readsAsDict = heuristic.decide() === "dict";
781
- if (column.dtype === "string" && readsAsDict) {
782
- notes.push(
783
- note(
784
- LOSS.STORAGE_CLASS,
785
- `${domain} column "${meta.name}" reads back as dict (low cardinality)`,
786
- meta.name,
787
- null
788
- )
789
- );
790
- } else if (column.dtype === "dict" && !readsAsDict) {
791
- notes.push(
792
- note(
793
- LOSS.STORAGE_CLASS,
794
- `${domain} column "${meta.name}" reads back as string (cardinality too high for a dict)`,
795
- meta.name,
796
- null
797
- )
798
- );
799
- }
800
- }
801
- }
802
- function positionNameNote(snapshot, nodeColumns, notes) {
803
- const position = positionColumn(snapshot);
804
- if (position === null) {
805
- return;
806
- }
807
- const { name } = position.meta;
808
- const plainPosition = nodeColumns.some((c) => c.key === "position");
809
- const reimportName = plainPosition ? "position#graphics" : "position";
810
- if (name !== reimportName) {
811
- notes.push(
812
- note(
813
- LOSS.COLUMN_NAME_CHANGED,
814
- `node column "${name}" (position) is written as the graphics x / y / z keys and reads back as "${reimportName}"`,
815
- name,
816
- position.length - position.nullCount
817
- )
818
- );
819
- }
820
- }
821
- function check(snapshot, options) {
822
- const plan = planOf(snapshot, options);
823
- const notes = checkCapabilities(snapshot, GML_CAPABILITIES, plan.common, {
824
- positionDtype: "f64",
825
- roles: KEPT_ROLES,
826
- roleNames: ROLE_NAMES
827
- });
828
- const nodeReserved = new Set(NODE_RESERVED);
829
- if (plan.common.sanitizeIds === "mangle" && countMangled(snapshot) > 0 || snapshot.nodes.byRole("originalId") !== null) {
830
- nodeReserved.add(ORIGINAL_ID_KEY);
831
- }
832
- const edgeIds = snapshot.edges.byRole("id");
833
- const edgeReserved = edgeReservedKeys(snapshot, plan, edgeIds);
834
- const topReserved = topReservedKeys(snapshot);
835
- const nodeColumns = selectColumns(snapshot.nodes, nodeReserved, "node", plan, notes);
836
- const edgeColumns = selectColumns(snapshot.edges, edgeReserved, "edge", plan, notes, (c) => c !== edgeIds);
837
- const graphColumns = selectColumns(snapshot.graph, GRAPH_RESERVED, "graph", plan, notes, (c) => !isTopLevel(c));
838
- const topColumns = selectColumns(snapshot.graph, topReserved, "top-level", plan, notes, isTopLevel);
839
- jsonNotes(nodeColumns, "node", plan, notes);
840
- jsonNotes(edgeColumns, "edge", plan, notes);
841
- jsonNotes(graphColumns, "graph", plan, notes);
842
- jsonNotes(topColumns, "top-level", plan, notes);
843
- graphicsNotes(snapshot, notes);
844
- positionNameNote(snapshot, nodeColumns, notes);
845
- reimportNotes(nodeColumns, "node", notes);
846
- reimportNotes(edgeColumns, "edge", notes);
847
- if (!hasWeights(snapshot)) {
848
- const clash = edgeColumns.find((c) => c.key === plan.weightKey);
849
- if (clash !== void 0) {
850
- notes.push(
851
- note(
852
- LOSS.WEIGHT_KEY_CLASH,
853
- `edge column "${clash.column.meta.name}" is written under "${plan.weightKey}", the key the importer reads edge weights from; it reads back as the weight, not as a column`,
854
- clash.column.meta.name,
855
- clash.column.length - clash.column.nullCount
856
- )
857
- );
858
- }
859
- }
860
- const folding = pairFolding(snapshot);
861
- if (folding.mutualCount > 0) {
862
- notes.push(
863
- note(
864
- LOSS.MUTUAL_EXPANDED,
865
- `${folding.mutualCount} mutual pair${plural(folding.mutualCount)} ${agree(folding.mutualCount, "is", "are")} written as two directed edges; the mutual mark is lost`,
866
- null,
867
- folding.mutualCount
868
- )
869
- );
870
- }
871
- return Object.freeze(notes);
872
- }
873
- function edgeReservedKeys(snapshot, plan, edgeIds) {
874
- const reserved = new Set(EDGE_RESERVED);
875
- if (hasWeights(snapshot)) {
876
- reserved.add(plan.weightKey);
877
- }
878
- if (edgeIds !== null) {
879
- reserved.add("id");
880
- }
881
- return reserved;
882
- }
883
- function topReservedKeys(snapshot) {
884
- const reserved = new Set(TOP_RESERVED);
885
- if (snapshot.meta.creator !== null) {
886
- reserved.add("Creator");
887
- }
888
- if (snapshot.meta.sourceFormat === "gml" && snapshot.meta.sourceVersion !== null) {
889
- reserved.add("Version");
890
- }
891
- return reserved;
892
- }
893
- function countMangled(snapshot) {
894
- let count = 0;
895
- for (let i = 0; i < snapshot.nodeCount; i++) {
896
- const id = snapshot.ids.idOf(i);
897
- if (typeof id !== "number" || !Number.isSafeInteger(id)) {
898
- count++;
899
- }
900
- }
901
- return count;
902
- }
903
- function numberText(value, meta) {
904
- switch (meta.dtype) {
905
- case "i32":
906
- case "u32":
907
- case "u8":
908
- return formatInteger(value);
909
- case "f32":
910
- return formatGmlReal(value, "f32");
911
- default:
912
- if (meta.origin?.type === "int" && Number.isInteger(value)) {
913
- return formatInteger(value);
914
- }
915
- return formatGmlReal(value, "f64");
916
- }
917
- }
918
- function jsonScalarText(value) {
919
- switch (typeof value) {
920
- case "number":
921
- return Number.isInteger(value) ? formatInteger(value) : formatGmlReal(value, "f64");
922
- case "boolean":
923
- return value ? "1" : "0";
924
- default:
925
- return quoteGmlString(value);
926
- }
927
- }
928
- function itemText(item, itemDtype, meta) {
929
- switch (typeof item) {
930
- case "number":
931
- switch (itemDtype) {
932
- case "i32":
933
- case "u32":
934
- case "u8":
935
- return formatInteger(item);
936
- case "f32":
937
- return formatGmlReal(item, "f32");
938
- case "json":
939
- return jsonScalarText(item);
940
- default:
941
- return meta.origin?.type === "int" && Number.isInteger(item) ? formatInteger(item) : formatGmlReal(item, "f64");
942
- }
943
- case "boolean":
944
- return item ? "1" : "0";
945
- case "string":
946
- return quoteGmlString(item);
947
- default:
948
- throw new GraphFormatError(
949
- "E_COLUMN_TYPE",
950
- `column "${meta.name}": a ${typeof item} list item cannot be written as GML`,
951
- {
952
- column: meta.name,
953
- found: typeof item
954
- }
955
- );
956
- }
957
- }
958
- class GmlWriter {
959
- /**
960
- * Create a writer.
961
- * @param mangle - whether record keys are rewritten rather than refused
962
- */
963
- constructor(mangle) {
964
- this.lines = [];
965
- this.mangle = mangle;
966
- }
967
- /**
968
- * Take the lines written so far as one string.
969
- * @returns the text; the writer is empty afterwards
970
- */
971
- take() {
972
- const text = this.lines.join("");
973
- this.lines.length = 0;
974
- return text;
975
- }
976
- /**
977
- * Write one `key value` line.
978
- * @param indent - the indentation
979
- * @param key - the key
980
- * @param value - the value text
981
- */
982
- line(indent, key, value) {
983
- this.lines.push(`${indent}${key} ${value}
984
- `);
985
- }
986
- /**
987
- * Write a raw line.
988
- * @param text - the line without its terminator
989
- */
990
- raw(text) {
991
- this.lines.push(`${text}
992
- `);
993
- }
994
- /**
995
- * Write one column cell of a row.
996
- * @param indent - the indentation
997
- * @param key - the key
998
- * @param column - the column
999
- * @param row - the row
1000
- */
1001
- cell(indent, key, column, row) {
1002
- const { meta, dtype } = column;
1003
- switch (dtype) {
1004
- case "f32":
1005
- case "f64":
1006
- case "i32":
1007
- case "u32":
1008
- case "u8": {
1009
- const { components } = meta;
1010
- if (components === 1) {
1011
- this.line(indent, key, numberText(column.data[row], meta));
1012
- } else {
1013
- for (let k = 0; k < components; k++) {
1014
- this.line(indent, key, numberText(column.data[row * components + k], meta));
1015
- }
1016
- }
1017
- return;
1018
- }
1019
- case "bool":
1020
- this.line(indent, key, column.value(row) === true ? "1" : "0");
1021
- return;
1022
- case "dict":
1023
- case "string":
1024
- this.line(indent, key, quoteGmlString(column.value(row) ?? ""));
1025
- return;
1026
- case "list":
1027
- this.list(indent, key, column.sliceOf(row), meta.itemDtype ?? "string", meta);
1028
- return;
1029
- case "json":
1030
- this.json(indent, key, column.values[row], meta.name);
1031
- return;
1032
- default: {
1033
- const name = dtype;
1034
- throw new GraphFormatError("E_COLUMN_TYPE", `unknown dtype ${name}`, { dtype: name });
1035
- }
1036
- }
1037
- }
1038
- /**
1039
- * Write a list as repeated keys with the NetworkX conventions.
1040
- * @param indent - the indentation
1041
- * @param key - the key
1042
- * @param items - the items
1043
- * @param itemDtype - the item dtype
1044
- * @param meta - the column metadata
1045
- */
1046
- list(indent, key, items, itemDtype, meta) {
1047
- if (items.length === 0) {
1048
- this.line(indent, key, quoteGmlString(EMPTY_LIST_TEXT));
1049
- return;
1050
- }
1051
- if (items.length === 1) {
1052
- this.line(indent, key, quoteGmlString(LIST_START_MARKER));
1053
- }
1054
- for (const item of items) {
1055
- if (itemDtype === "json" && typeof item === "object") {
1056
- this.json(indent, key, item, meta.name, true);
1057
- } else {
1058
- this.line(indent, key, itemText(item, itemDtype, meta));
1059
- }
1060
- }
1061
- }
1062
- /**
1063
- * Write a JSON value: a record for an object, repeated keys for an array, a scalar otherwise;
1064
- * null writes nothing.
1065
- * @param indent - the indentation
1066
- * @param key - the key
1067
- * @param value - the value
1068
- * @param column - the column name, for errors
1069
- * @param inArray - whether the value is an array item (an array here has no GML spelling)
1070
- */
1071
- json(indent, key, value, column, inArray = false) {
1072
- if (value === null || value === void 0) {
1073
- return;
1074
- }
1075
- if (Array.isArray(value)) {
1076
- if (inArray) {
1077
- throw new GraphFormatError(
1078
- "E_UNSUPPORTED",
1079
- `column "${column}": an array nested in an array cannot be written as GML`,
1080
- {
1081
- reason: "nested array",
1082
- column
1083
- }
1084
- );
1085
- }
1086
- if (value.length === 0) {
1087
- this.line(indent, key, quoteGmlString(EMPTY_LIST_TEXT));
1088
- return;
1089
- }
1090
- if (value.length === 1) {
1091
- this.line(indent, key, quoteGmlString(LIST_START_MARKER));
1092
- }
1093
- for (const item of value) {
1094
- this.json(indent, key, item, column, true);
1095
- }
1096
- return;
1097
- }
1098
- if (typeof value === "object") {
1099
- this.record(indent, key, value, column);
1100
- return;
1101
- }
1102
- if (typeof value === "number" || typeof value === "string" || typeof value === "boolean") {
1103
- this.line(indent, key, jsonScalarText(value));
1104
- return;
1105
- }
1106
- throw new GraphFormatError("E_COLUMN_TYPE", `column "${column}": a ${typeof value} cannot be written as GML`, {
1107
- column,
1108
- found: typeof value
1109
- });
1110
- }
1111
- /**
1112
- * Write a record `key [ ... ]`.
1113
- * @param indent - the indentation
1114
- * @param key - the key
1115
- * @param record - the object
1116
- * @param column - the column name, for errors
1117
- * @param extra - lines to write first (the position of a graphics record), or null
1118
- */
1119
- record(indent, key, record, column, extra = null) {
1120
- this.raw(`${indent}${key} [`);
1121
- const inner = `${indent} `;
1122
- const used = /* @__PURE__ */ new Set();
1123
- if (extra !== null) {
1124
- for (const [k, v] of extra) {
1125
- this.line(inner, k, v);
1126
- used.add(k);
1127
- }
1128
- }
1129
- for (const name of Object.keys(record)) {
1130
- if (used.has(name) && extra !== null && (name === "x" || name === "y" || name === "z")) {
1131
- continue;
1132
- }
1133
- const written = this.recordKey(name, used, column);
1134
- used.add(written);
1135
- this.json(inner, written, record[name], column);
1136
- }
1137
- this.raw(`${indent}]`);
1138
- }
1139
- /**
1140
- * The key a record field is written under.
1141
- * @param name - the field name
1142
- * @param used - the keys already written in the record
1143
- * @param column - the column name, for errors
1144
- * @returns a valid, unused key; E_UNSUPPORTED for an invalid key unless mangling
1145
- */
1146
- recordKey(name, used, column) {
1147
- if (isGmlKey(name) && !used.has(name)) {
1148
- return name;
1149
- }
1150
- if (!this.mangle) {
1151
- throw new GraphFormatError(
1152
- "E_UNSUPPORTED",
1153
- `column "${column}": record key "${name}" ${isGmlKey(name) ? "repeats a key" : "is not a GML key"}; pass sanitizeKeys: "mangle" to rewrite it`,
1154
- {
1155
- reason: "gml key",
1156
- column,
1157
- key: name
1158
- }
1159
- );
1160
- }
1161
- return uniqueKey(isGmlKey(name) ? name : mangleGmlKey(name), used);
1162
- }
1163
- }
1164
- function contextOf(snapshot, options) {
1165
- const plan = planOf(snapshot, options);
1166
- const ids = sanitizeIds(snapshot, "integer", plan.common.sanitizeIds);
1167
- const mixed = countMixedEdges(snapshot);
1168
- if (mixed > 0 && plan.common.onMixedDirection === "error") {
1169
- throw new GraphFormatError(
1170
- "E_DIRECTED",
1171
- `${mixed} undirected edge${plural(mixed)} in a directed graph, and GML holds one direction per file, so the save fails unless onMixedDirection is "directed" or "undirected"`,
1172
- {
1173
- reason: "mixed direction",
1174
- count: mixed
1175
- }
1176
- );
1177
- }
1178
- const foldPairs = mixed > 0;
1179
- const writeDirected = snapshot.directed && plan.common.onMixedDirection !== "undirected";
1180
- const originalIds = snapshot.nodes.byRole("originalId");
1181
- const nodeReserved = new Set(NODE_RESERVED);
1182
- if (ids.changed > 0 || originalIds !== null) {
1183
- nodeReserved.add(ORIGINAL_ID_KEY);
1184
- }
1185
- const edgeIds = snapshot.edges.byRole("id");
1186
- const edgeReserved = edgeReservedKeys(snapshot, plan, edgeIds);
1187
- const topReserved = topReservedKeys(snapshot);
1188
- return {
1189
- snapshot,
1190
- plan,
1191
- ids,
1192
- writeDirected,
1193
- foldPairs,
1194
- nodeColumns: selectColumns(
1195
- snapshot.nodes,
1196
- nodeReserved,
1197
- "node",
1198
- plan,
1199
- null,
1200
- (c) => !(c.meta.name === "graphics" && c.dtype === "json")
1201
- ),
1202
- edgeColumns: selectColumns(snapshot.edges, edgeReserved, "edge", plan, null, (c) => c !== edgeIds),
1203
- graphColumns: selectColumns(snapshot.graph, GRAPH_RESERVED, "graph", plan, null, (c) => !isTopLevel(c)),
1204
- topColumns: selectColumns(snapshot.graph, topReserved, "top-level", plan, null, isTopLevel),
1205
- position: positionColumn(snapshot),
1206
- graphics: graphicsColumn(snapshot),
1207
- originalIds,
1208
- edgeIds,
1209
- weights: explicitWeights(snapshot),
1210
- folding: pairFolding(snapshot)
1211
- };
1212
- }
1213
- function originalIdText(id) {
1214
- if (typeof id === "string") {
1215
- return quoteGmlString(id);
1216
- }
1217
- return Number.isSafeInteger(id) ? formatInteger(id) : formatGmlReal(id, "f64");
1218
- }
1219
- function* gmlParts(context) {
1220
- const { snapshot, plan, ids } = context;
1221
- const w = new GmlWriter(plan.mangle);
1222
- const { meta } = snapshot;
1223
- if (meta.creator !== null) {
1224
- w.line("", "Creator", quoteGmlString(meta.creator));
1225
- }
1226
- if (meta.sourceFormat === "gml" && meta.sourceVersion !== null) {
1227
- w.line("", "Version", versionText(meta.sourceVersion));
1228
- }
1229
- for (const { column, key } of context.topColumns) {
1230
- if (column.isSet(0)) {
1231
- w.cell("", key, column, 0);
1232
- }
1233
- }
1234
- w.raw("graph [");
1235
- w.line(" ", "directed", context.writeDirected ? "1" : "0");
1236
- const multigraph = meta.declaredMultigraph ?? (snapshot.flags.multigraph ? true : null);
1237
- if (multigraph !== null) {
1238
- w.line(" ", "multigraph", multigraph ? "1" : "0");
1239
- }
1240
- for (const { column, key } of context.graphColumns) {
1241
- if (column.isSet(0)) {
1242
- w.cell(" ", key, column, 0);
1243
- }
1244
- }
1245
- yield w.take();
1246
- for (let i = 0; i < snapshot.nodeCount; i++) {
1247
- w.raw(" node [");
1248
- w.line(" ", "id", formatInteger(ids.idAt(i)));
1249
- if (ids.isChanged(i)) {
1250
- w.line(" ", ORIGINAL_ID_KEY, originalIdText(ids.originalAt(i)));
1251
- } else if (context.originalIds?.isSet(i)) {
1252
- const original = context.originalIds.value(i);
1253
- if (typeof original === "string" || typeof original === "number") {
1254
- w.line(" ", ORIGINAL_ID_KEY, originalIdText(original));
1255
- }
1256
- }
1257
- for (const { column, key } of context.nodeColumns) {
1258
- if (column.isSet(i)) {
1259
- w.cell(" ", key, column, i);
1260
- }
1261
- }
1262
- writeGraphics(w, context, i);
1263
- w.raw(" ]");
1264
- yield w.take();
1265
- }
1266
- const el = snapshot.edgeList();
1267
- const origin = meta.weightOrigin;
1268
- const integerWeights = origin !== null && origin.type === "int";
1269
- for (let e = 0; e < snapshot.edgeCount; e++) {
1270
- if (context.foldPairs && context.folding.folded(e)) {
1271
- continue;
1272
- }
1273
- w.raw(" edge [");
1274
- w.line(" ", "source", formatInteger(ids.idAt(el.src[e])));
1275
- w.line(" ", "target", formatInteger(ids.idAt(el.dst[e])));
1276
- if (context.edgeIds?.isSet(e)) {
1277
- w.cell(" ", "id", context.edgeIds, e);
1278
- }
1279
- if (context.weights.isExplicit(e)) {
1280
- const weight = context.weights.value(e);
1281
- const text = integerWeights && Number.isInteger(weight) ? formatInteger(weight) : formatGmlReal(weight, context.weights.dtype);
1282
- w.line(" ", plan.weightKey, text);
1283
- }
1284
- for (const { column, key } of context.edgeColumns) {
1285
- if (column.isSet(e)) {
1286
- w.cell(" ", key, column, e);
1287
- }
1288
- }
1289
- w.raw(" ]");
1290
- yield w.take();
1291
- }
1292
- w.raw("]");
1293
- yield w.take();
1294
- }
1295
- function writeGraphics(w, context, i) {
1296
- const { position, graphics } = context;
1297
- const hasPosition = position?.isSet(i) === true;
1298
- const graphicsValue = graphics?.isSet(i) ? graphics.values[i] : void 0;
1299
- if (!hasPosition) {
1300
- if (graphics !== null && graphicsValue !== void 0) {
1301
- w.cell(" ", "graphics", graphics, i);
1302
- }
1303
- return;
1304
- }
1305
- const numeric = position;
1306
- const { components } = numeric.meta;
1307
- const lanes = Math.min(components, 3);
1308
- const extra = [];
1309
- const names = ["x", "y", "z"];
1310
- for (let k = 0; k < lanes; k++) {
1311
- extra.push([names[k], numberText(numeric.data[i * components + k], numeric.meta)]);
1312
- }
1313
- let record = {};
1314
- if (graphicsValue !== void 0) {
1315
- if (typeof graphicsValue !== "object" || graphicsValue === null || Array.isArray(graphicsValue)) {
1316
- throw new GraphFormatError(
1317
- "E_UNSUPPORTED",
1318
- `node ${i}: the graphics value is not a record and cannot hold the position`,
1319
- {
1320
- reason: "graphics conflict",
1321
- node: i
1322
- }
1323
- );
1324
- }
1325
- record = graphicsValue;
1326
- }
1327
- w.record(" ", "graphics", record, "graphics", extra);
1328
- }
1329
- const gmlExporter = Object.freeze({
1330
- format: "gml",
1331
- options: Object.freeze(["sanitizeKeys", "weightKey"]),
1332
- capabilities: GML_CAPABILITIES,
1333
- check,
1334
- /**
1335
- * Write the snapshot as UTF-8 chunks; the context is resolved on the first pull, so the
1336
- * errors check() announced surface from the iteration.
1337
- * @param snapshot - the snapshot
1338
- * @param options - the options
1339
- * @returns the chunks
1340
- */
1341
- export(snapshot, options) {
1342
- return encodeChunks(lazyParts(snapshot, options));
1343
- },
1344
- /**
1345
- * Write the snapshot as one string.
1346
- * @param snapshot - the snapshot
1347
- * @param options - the options
1348
- * @returns the document
1349
- */
1350
- exportToString(snapshot, options) {
1351
- return joinText(lazyParts(snapshot, options));
1352
- }
1353
- });
1354
- function* lazyParts(snapshot, options) {
1355
- yield* gmlParts(contextOf(snapshot, options));
1356
- }
1357
- const NO_GRAPH_CODE = NO_GRAPH_CODE$1;
1358
- const SECOND_GRAPH_CODE = MULTIPLE_GRAPHS_CODE;
1359
- const MISSING_ID_CODE = MISSING_ID_CODE$1;
1360
- const MISSING_LABEL_CODE = "E_GML_MISSING_LABEL";
1361
- const MISSING_ENDPOINT_CODE = MISSING_ENDPOINT_CODE$1;
1362
- const ID_TYPE_CODE = "E_GML_ID_TYPE";
1363
- const STRING_ID_CODE = "W_GML_STRING_ID";
1364
- const DUPLICATE_NODE_CODE = DUPLICATE_NODE_CODE$1;
1365
- const REPEATED_KEY_CODE = "E_GML_REPEATED_KEY";
1366
- const ELEMENT_TYPE_CODE = "E_GML_ELEMENT_TYPE";
1367
- const FLAG_TYPE_CODE = "E_GML_FLAG_TYPE";
1368
- const FLAG_VALUE_CODE = "W_GML_FLAG_VALUE";
1369
- const QUOTED_INT = /^\s*[+-]?\d+\s*$/;
1370
- const UNKNOWN_ENTITY_CODE = "W_GML_UNKNOWN_ENTITY";
1371
- const GRAPHICS_CODE = "W_GML_GRAPHICS";
1372
- const NESTED_ELEMENT_CODE = "W_GML_NESTED_ELEMENT";
1373
- const GROUPS_CODE = "W_GML_GROUPS";
1374
- const WIDENED_CODE = WIDENED_CODE$1;
1375
- const PRECISION_CODE = PRECISION_CODE$1;
1376
- const COLUMN_RENAMED_CODE_GML = COLUMN_RENAMED_CODE;
1377
- const ROLE_TAKEN_CODE = ROLE_TAKEN_CODE$1;
1378
- const ID_DROPPED_CODE = "W_GML_ID_DROPPED";
1379
- const FORMAT_DEFAULTS = { ids: "canonical", defaultDirected: false, weightFrom: "value" };
1380
- const KIND_INT = 1;
1381
- const KIND_REAL = 2;
1382
- const KIND_STRING = 4;
1383
- const KIND_RECORD = 8;
1384
- const I32_MIN = -2147483648;
1385
- const I32_MAX = 2147483647;
1386
- const ABORT_CHECK_INTERVAL = 64;
1387
- const USED_OPTIONS = /* @__PURE__ */ new Set([
1388
- "ids",
1389
- "nodeIdFrom",
1390
- "addMissingNodes",
1391
- "duplicateEdges",
1392
- "selfLoops",
1393
- "onMixedDirection",
1394
- "defaultDirected",
1395
- "weightFrom",
1396
- "weightDtype",
1397
- "restoreMangledIds",
1398
- "long",
1399
- "errorLimit",
1400
- "signal",
1401
- "onProgress"
1402
- ]);
1403
- const GRAPH_SEQ = -1;
1404
- const TOP_SEQ = -2;
1405
- function isLabel(domain, key) {
1406
- return roleOf(domain, key) === "label";
1407
- }
1408
- function isRecord(value) {
1409
- return typeof value === "object" && value !== null && !Array.isArray(value);
1410
- }
1411
- function roleOf(domain, key) {
1412
- if (key === "label" && domain !== "graph") {
1413
- return "label";
1414
- }
1415
- if (domain === "edge") {
1416
- if (key === "id") {
1417
- return "id";
1418
- }
1419
- if (key === "key") {
1420
- return "key";
1421
- }
1422
- }
1423
- return null;
1424
- }
1425
- class GmlImport {
1426
- /**
1427
- * Create one import.
1428
- * @param sink - the sink
1429
- * @param report - the report
1430
- * @param options - the resolved common options
1431
- * @param format - the format-specific options
1432
- * @param which - which `graph [ ... ]` block to read (0: the first)
1433
- */
1434
- constructor(sink, report, options, format, which = 0) {
1435
- this.which = which;
1436
- this.tokens = null;
1437
- this.graphCount = 0;
1438
- this.resolver = null;
1439
- this.nodeSchema = /* @__PURE__ */ new Map();
1440
- this.edgeSchema = /* @__PURE__ */ new Map();
1441
- this.graphSchema = /* @__PURE__ */ new Map();
1442
- this.topSchema = /* @__PURE__ */ new Map();
1443
- this.nodePlans = /* @__PURE__ */ new Map();
1444
- this.edgePlans = /* @__PURE__ */ new Map();
1445
- this.graphPlans = /* @__PURE__ */ new Map();
1446
- this.topPlans = /* @__PURE__ */ new Map();
1447
- this.graphNames = /* @__PURE__ */ new Set();
1448
- this.graphOpen = -1;
1449
- this.directedToken = -1;
1450
- this.multigraphToken = -1;
1451
- this.creatorToken = -1;
1452
- this.versionToken = -1;
1453
- this.nodeCount = 0;
1454
- this.edgeCount = 0;
1455
- this.weightKinds = 0;
1456
- this.hasOriginalId = false;
1457
- this.headerDirected = false;
1458
- this.seq = 0;
1459
- this.nodeOrdinal = 0;
1460
- this.elementsSinceCheck = 0;
1461
- this.idMap = null;
1462
- this.skippedIds = /* @__PURE__ */ new Set();
1463
- this.declared = new Uint32Array(64);
1464
- this.touched = [];
1465
- this.graphTouched = [];
1466
- this.seqNow = 0;
1467
- this.sink = sink;
1468
- this.report = report;
1469
- this.options = options;
1470
- this.positions = format?.positions ?? true;
1471
- this.keepPositionSource = format?.keepPositionSource ?? false;
1472
- this.dictionaries = format?.dictionaries ?? true;
1473
- this.coercer = new IdCoercer(options.ids);
1474
- }
1475
- /**
1476
- * Run the import over the tokens of a text.
1477
- * @param tokens - the whole text, tokenized (tokenize())
1478
- */
1479
- run(tokens) {
1480
- this.tokens = tokens;
1481
- tokens.onUnknownEntity = (entity, line) => {
1482
- this.report.warnOnce(
1483
- "parse-error",
1484
- UNKNOWN_ENTITY_CODE,
1485
- `character entity ${entity} cannot be decoded; it is kept as written`,
1486
- { line, element: entity },
1487
- `${UNKNOWN_ENTITY_CODE}:${entity}`
1488
- );
1489
- };
1490
- this.scan();
1491
- this.push();
1492
- }
1493
- // ============================================================ pass 1: the schema
1494
- /**
1495
- * Walk the top level: find the graph block, the metadata keys and the top-level attributes,
1496
- * and derive every table's schema.
1497
- */
1498
- scan() {
1499
- const t = this.requireTokens();
1500
- let scalarGraph = -1;
1501
- for (let p = 0; p < t.count; p = t.nextPair(p)) {
1502
- const key = t.textOf(p);
1503
- const v = p + 1;
1504
- const record = t.kind[v] === TOKEN_OPEN;
1505
- if (key === "graph" && !record && scalarGraph < 0) {
1506
- scalarGraph = v;
1507
- }
1508
- this.scanTopPair(key, record, v);
1509
- }
1510
- if (this.graphOpen < 0) {
1511
- this.failNoGraph(t, scalarGraph);
1512
- }
1513
- }
1514
- /**
1515
- * Handle one top-level pair other than a scalar `graph`.
1516
- * @param key - the key
1517
- * @param record - whether the value is a `[ ... ]` block
1518
- * @param v - the value token
1519
- */
1520
- scanTopPair(key, record, v) {
1521
- if (key === "graph" && record) {
1522
- if (this.graphCount++ === this.which) {
1523
- this.graphOpen = v;
1524
- this.scanGraph(v);
1525
- }
1526
- } else if (key === "Creator" && !record && this.creatorToken < 0) {
1527
- this.creatorToken = v;
1528
- } else if (key === "Version" && !record && this.versionToken < 0) {
1529
- this.versionToken = v;
1530
- } else {
1531
- this.observe(this.topSchema, "graph", key, v, TOP_SEQ);
1532
- }
1533
- }
1534
- /**
1535
- * Fail because the input holds no graph block.
1536
- * @param t - the tokens
1537
- * @param scalarGraph - the token of a scalar `graph` key, or -1
1538
- */
1539
- failNoGraph(t, scalarGraph) {
1540
- if (scalarGraph >= 0) {
1541
- this.report.fail(
1542
- NO_GRAPH_CODE,
1543
- `the graph key at line ${t.line[scalarGraph]} holds ${describeValue(t, scalarGraph)}, not a [ ... ] block; the input contains no graph block`,
1544
- { line: t.line[scalarGraph] }
1545
- );
1546
- }
1547
- this.report.fail(NO_GRAPH_CODE, "the input contains no graph [ ... ] block", { line: null });
1548
- }
1549
- /**
1550
- * Walk the graph block for the schema.
1551
- * @param open - the index of the block's `[`
1552
- */
1553
- scanGraph(open) {
1554
- const t = this.requireTokens();
1555
- const close = t.match[open];
1556
- for (let p = open + 1; p < close; p = t.nextPair(p)) {
1557
- const key = t.textOf(p);
1558
- const v = p + 1;
1559
- switch (key) {
1560
- case "node":
1561
- if (t.kind[v] === TOKEN_OPEN) {
1562
- this.nodeCount++;
1563
- this.scanElement("node", v);
1564
- }
1565
- break;
1566
- case "edge":
1567
- if (t.kind[v] === TOKEN_OPEN) {
1568
- this.edgeCount++;
1569
- this.scanElement("edge", v);
1570
- }
1571
- break;
1572
- case "directed":
1573
- if (this.directedToken < 0) {
1574
- this.directedToken = v;
1575
- }
1576
- break;
1577
- case "multigraph":
1578
- if (this.multigraphToken < 0) {
1579
- this.multigraphToken = v;
1580
- }
1581
- break;
1582
- default:
1583
- this.observe(this.graphSchema, "graph", key, v, GRAPH_SEQ);
1584
- }
1585
- }
1586
- }
1587
- /**
1588
- * Walk one node or edge block for the schema.
1589
- * @param domain - node or edge
1590
- * @param open - the block's `[`
1591
- */
1592
- scanElement(domain, open) {
1593
- const t = this.requireTokens();
1594
- const close = t.match[open];
1595
- const seq = this.seq++;
1596
- const schema = domain === "node" ? this.nodeSchema : this.edgeSchema;
1597
- for (let p = open + 1; p < close; p = t.nextPair(p)) {
1598
- const key = t.textOf(p);
1599
- const v = p + 1;
1600
- if (this.skipsKey(domain, key, v)) {
1601
- continue;
1602
- }
1603
- this.observe(schema, domain, key, v, seq);
1604
- }
1605
- }
1606
- /**
1607
- * Whether a key of a node or edge block is structural (id, endpoints, weight, original id), not
1608
- * a column; notes the original id and the weight's kinds on the way.
1609
- * @param domain - node or edge
1610
- * @param key - the key
1611
- * @param v - the value token
1612
- * @returns true when the key is not a column
1613
- */
1614
- skipsKey(domain, key, v) {
1615
- const { weightFrom, restoreMangledIds } = this.options;
1616
- if (domain === "node") {
1617
- if (key === ORIGINAL_ID_KEY && restoreMangledIds) {
1618
- this.hasOriginalId = true;
1619
- return true;
1620
- }
1621
- return key === "id";
1622
- }
1623
- if (key === "source" || key === "target" || key === "directed") {
1624
- return true;
1625
- }
1626
- if (key === weightFrom) {
1627
- this.weightKinds |= kindBit(this.requireTokens(), v);
1628
- return true;
1629
- }
1630
- return false;
1631
- }
1632
- /**
1633
- * Record one value of one key in a table's schema.
1634
- * @param schema - the table's schema
1635
- * @param domain - the table
1636
- * @param key - the key
1637
- * @param v - the value token
1638
- * @param seq - the element sequence number
1639
- */
1640
- observe(schema, domain, key, v, seq) {
1641
- const t = this.requireTokens();
1642
- this.noteStructure(domain, key, v);
1643
- let entry = schema.get(key);
1644
- const graphics = domain === "node" && key === "graphics" && this.positions;
1645
- if (entry === void 0) {
1646
- entry = {
1647
- key,
1648
- kinds: 0,
1649
- list: false,
1650
- lastSeq: seq,
1651
- wide: false,
1652
- unsafe: false,
1653
- dict: this.dictionaries && roleOf(domain, key) === null ? new DictHeuristic() : null,
1654
- position: false,
1655
- rest: false
1656
- };
1657
- schema.set(key, entry);
1658
- } else if (entry.lastSeq === seq) {
1659
- entry.list = true;
1660
- entry.rest ||= graphics;
1661
- } else {
1662
- entry.lastSeq = seq;
1663
- }
1664
- if (graphics && t.kind[v] !== TOKEN_OPEN) {
1665
- entry.rest = true;
1666
- }
1667
- switch (t.kind[v]) {
1668
- case TOKEN_STRING: {
1669
- const raw = t.textOf(v);
1670
- if (raw === LIST_START_MARKER || !isLabel(domain, key) && (raw === EMPTY_LIST_TEXT || raw === EMPTY_TUPLE_TEXT)) {
1671
- entry.list = true;
1672
- return;
1673
- }
1674
- entry.kinds |= KIND_STRING;
1675
- if (entry.dict !== null && !entry.dict.decided) {
1676
- entry.dict.observe(raw);
1677
- }
1678
- return;
1679
- }
1680
- case TOKEN_INT: {
1681
- entry.kinds |= KIND_INT;
1682
- const n = Number(t.textOf(v));
1683
- if (n < I32_MIN || n > I32_MAX) {
1684
- entry.wide = true;
1685
- if (!Number.isSafeInteger(n)) {
1686
- entry.unsafe = true;
1687
- }
1688
- }
1689
- return;
1690
- }
1691
- case TOKEN_OPEN:
1692
- entry.kinds |= KIND_RECORD;
1693
- if (domain === "node" && key === "graphics" && this.positions) {
1694
- this.inspectGraphics(entry, v);
1695
- }
1696
- return;
1697
- default: {
1698
- entry.kinds |= KIND_REAL;
1699
- const text = t.textOf(v);
1700
- if (/\d/.test(text) && !Number.isFinite(Number(text))) {
1701
- this.report.warnOnce(
1702
- "precision",
1703
- PRECISION_CODE,
1704
- `${domain} key "${key}" holds the real ${text}, beyond the f64 range; it is stored as ${numberOfText(text) > 0 ? "" : "-"}Infinity`,
1705
- { line: t.line[v], element: key },
1706
- `${PRECISION_CODE}:overflow:${domain}:${key}`
1707
- );
1708
- }
1709
- }
1710
- }
1711
- }
1712
- /**
1713
- * Warn about keys of a node or edge whose meaning GML readers give but this import does not:
1714
- * a nested graph / node / edge record, and yEd's group hierarchy.
1715
- * @param domain - the table
1716
- * @param key - the key
1717
- * @param v - the value token
1718
- */
1719
- noteStructure(domain, key, v) {
1720
- const t = this.requireTokens();
1721
- if (domain === "graph") {
1722
- return;
1723
- }
1724
- if ((key === "graph" || key === "node" || key === "edge") && t.kind[v] === TOKEN_OPEN) {
1725
- this.report.warnOnce(
1726
- "unsupported",
1727
- NESTED_ELEMENT_CODE,
1728
- `a nested ${key} record inside a ${domain} is kept as the json column "${key}"; it is not read as structure`,
1729
- { line: t.line[v], element: key },
1730
- `${NESTED_ELEMENT_CODE}:${domain}:${key}`
1731
- );
1732
- } else if (domain === "node" && (key === "isGroup" || key === "gid")) {
1733
- this.report.warnOnce(
1734
- "unsupported",
1735
- GROUPS_CODE,
1736
- "yEd group keys (isGroup, gid) are kept as plain node columns; the group hierarchy is not read as containment",
1737
- { line: t.line[v], element: key }
1738
- );
1739
- }
1740
- }
1741
- /**
1742
- * Note whether a node's graphics record carries a position (numeric x and y) and whether
1743
- * anything besides the position remains.
1744
- * @param entry - the graphics schema entry
1745
- * @param open - the record's `[`
1746
- */
1747
- inspectGraphics(entry, open) {
1748
- const t = this.requireTokens();
1749
- const close = t.match[open];
1750
- let x = false;
1751
- let y = false;
1752
- let other = false;
1753
- for (let p = open + 1; p < close; p = t.nextPair(p)) {
1754
- const key = t.textOf(p);
1755
- const numeric = t.kind[p + 1] === TOKEN_INT || t.kind[p + 1] === TOKEN_REAL;
1756
- if (key === "x" && numeric && !x) {
1757
- x = true;
1758
- } else if (key === "y" && numeric && !y) {
1759
- y = true;
1760
- } else if (!(key === "z" && numeric)) {
1761
- other = true;
1762
- }
1763
- }
1764
- const positioned = x && y;
1765
- entry.position ||= positioned;
1766
- entry.rest ||= positioned ? other || this.keepPositionSource : true;
1767
- }
1768
- // ============================================================ pass 2: the push
1769
- /** Declare what the schema needs, set the header and push every element. */
1770
- push() {
1771
- const { sink, report, options } = this;
1772
- const t = this.requireTokens();
1773
- sink.reserve(this.nodeCount, this.edgeCount);
1774
- this.buildPlans();
1775
- this.setMetadata();
1776
- this.headerDirected = this.readFlag(this.directedToken, "directed") ?? options.defaultDirected;
1777
- const resolver = new DirectionResolver(sink, report, options.onMixedDirection);
1778
- resolver.setHeader(this.headerDirected, {
1779
- line: this.directedToken >= 0 ? t.line[this.directedToken] : t.line[this.graphOpen]
1780
- });
1781
- this.resolver = resolver;
1782
- if (options.nodeIdFrom !== "id" || this.hasOriginalId) {
1783
- this.idMap = /* @__PURE__ */ new Map();
1784
- }
1785
- if (options.nodeIdFrom !== "id") {
1786
- report.loss(
1787
- ID_DROPPED_CODE,
1788
- `node ids taken from the ${options.nodeIdFrom}; the integer id keys are not kept as a column`,
1789
- null,
1790
- this.nodeCount
1791
- );
1792
- }
1793
- this.pushTopLevel();
1794
- this.pushNodes();
1795
- this.pushEdges();
1796
- }
1797
- /** Turn every schema entry into a column plan. */
1798
- buildPlans() {
1799
- for (const [key, entry] of this.nodeSchema) {
1800
- this.nodePlans.set(key, this.planOf("node", entry));
1801
- }
1802
- for (const [key, entry] of this.edgeSchema) {
1803
- this.edgePlans.set(key, this.planOf("edge", entry));
1804
- }
1805
- for (const [key, entry] of this.graphSchema) {
1806
- this.graphPlans.set(key, this.planOf("graph", entry));
1807
- }
1808
- for (const [key, entry] of this.topSchema) {
1809
- this.topPlans.set(key, this.planOf("graph", entry, true));
1810
- }
1811
- }
1812
- /**
1813
- * Warn about a key that mixes numbers and strings, or holds integers beyond 2^53.
1814
- * @param domain - the table
1815
- * @param entry - the schema entry
1816
- * @param asText - whether the integers are kept as text
1817
- */
1818
- warnKinds(domain, entry, asText) {
1819
- if ((entry.kinds & KIND_STRING) !== 0 && (entry.kinds & (KIND_INT | KIND_REAL)) !== 0 && (entry.kinds & KIND_RECORD) === 0) {
1820
- this.report.warnOnce(
1821
- "coercion",
1822
- WIDENED_CODE,
1823
- `${domain} key "${entry.key}" mixes numbers and strings; the column is string and the numbers are kept as written`,
1824
- { element: entry.key },
1825
- `${WIDENED_CODE}:${domain}:${entry.key}`
1826
- );
1827
- }
1828
- if (entry.unsafe && !asText) {
1829
- this.report.warnOnce(
1830
- "precision",
1831
- PRECISION_CODE,
1832
- `${domain} key "${entry.key}" holds integers beyond 2^53; they are stored as the nearest f64 (pass long: "string" to keep every digit as text)`,
1833
- { element: entry.key },
1834
- `${PRECISION_CODE}:${domain}:${entry.key}`
1835
- );
1836
- }
1837
- }
1838
- /**
1839
- * The plan of a node `graphics` record: the plan plus its position and rest columns.
1840
- * @param plan - the record's plan
1841
- * @param entry - the schema entry
1842
- * @returns the plan with its position (and rest) plans
1843
- */
1844
- graphicsPlan(plan, entry) {
1845
- const taken = (candidate) => this.nodeSchema.has(candidate) || this.sink.nodeColumn(candidate) !== INVALID_INDEX;
1846
- const position = {
1847
- ...plan,
1848
- name: uniqueColumnName("position", "graphics", taken),
1849
- dtype: "f64",
1850
- itemDtype: null,
1851
- kind: "real",
1852
- list: false,
1853
- role: "position"
1854
- };
1855
- const rest = entry.rest ? { ...plan, dtype: "json", itemDtype: null, kind: "record", list: false } : null;
1856
- return { ...plan, position, rest };
1857
- }
1858
- /**
1859
- * The plan of one schema entry.
1860
- * @param domain - the table
1861
- * @param entry - the schema entry
1862
- * @param top - whether the key is a top-level one (graph table)
1863
- * @returns the plan
1864
- */
1865
- planOf(domain, entry, top = false) {
1866
- const asText = entry.unsafe && this.options.long === "string" && kindOf(entry) === "int";
1867
- const kind = asText ? "string" : kindOf(entry);
1868
- let scalar = dtypeOfKind(kind, entry);
1869
- if (scalar === "string" && !entry.list && entry.dict !== null && entry.kinds === KIND_STRING && entry.dict.decide() === "dict") {
1870
- scalar = "dict";
1871
- }
1872
- this.warnKinds(domain, entry, asText);
1873
- const name = domain === "graph" ? this.uniqueGraphName(entry.key) : entry.key;
1874
- let itemDtype = null;
1875
- if (entry.list) {
1876
- itemDtype = scalar === "dict" ? "string" : scalar;
1877
- }
1878
- const plan = {
1879
- key: entry.key,
1880
- name,
1881
- dtype: entry.list ? "list" : scalar,
1882
- itemDtype,
1883
- kind,
1884
- list: entry.list,
1885
- role: roleOf(domain, entry.key),
1886
- top,
1887
- position: null,
1888
- rest: null,
1889
- handle: INVALID_INDEX,
1890
- declared: false,
1891
- items: null,
1892
- seq: Number.NEGATIVE_INFINITY
1893
- };
1894
- if (domain === "node" && entry.key === "graphics" && this.positions && (entry.kinds & KIND_RECORD) !== 0) {
1895
- return this.graphicsPlan(plan, entry);
1896
- }
1897
- return plan;
1898
- }
1899
- /**
1900
- * A graph column name not yet used by this import (top-level and in-graph keys share the table).
1901
- * @param key - the key
1902
- * @returns the name
1903
- */
1904
- uniqueGraphName(key) {
1905
- const name = uniqueColumnName(key, key, (candidate) => this.graphNames.has(candidate));
1906
- this.graphNames.add(name);
1907
- if (name !== key) {
1908
- this.report.warning(
1909
- "coercion",
1910
- COLUMN_RENAMED_CODE_GML,
1911
- `the top-level key "${key}" and a key of the graph block share the graph column name; the top-level value is stored as "${name}"`,
1912
- { element: key }
1913
- );
1914
- }
1915
- return name;
1916
- }
1917
- /** Set the graph metadata: source format, creator, version, multigraph flag, weight origin. */
1918
- setMetadata() {
1919
- const t = this.requireTokens();
1920
- const { sink, options } = this;
1921
- const textOf = (v) => t.kind[v] === TOKEN_STRING ? t.stringOf(v) : t.textOf(v);
1922
- const multigraph = this.readFlag(this.multigraphToken, "multigraph");
1923
- sink.setMeta({
1924
- sourceFormat: "gml",
1925
- creator: this.creatorToken >= 0 ? textOf(this.creatorToken) : void 0,
1926
- sourceVersion: this.versionToken >= 0 ? textOf(this.versionToken) : void 0,
1927
- declaredMultigraph: multigraph ?? void 0,
1928
- weightOrigin: this.weightKinds !== 0 && options.weightFrom !== null ? {
1929
- format: "gml",
1930
- id: options.weightFrom,
1931
- title: null,
1932
- type: this.weightKinds === KIND_INT ? "int" : "real",
1933
- namespace: null
1934
- } : void 0,
1935
- // The header as written, so a reader can say which words set the direction and tell
1936
- // `directed 0` from a file that relies on the specification's default.
1937
- extra: this.directedToken >= 0 ? { gml: { directed: textOf(this.directedToken) } } : void 0
1938
- });
1939
- }
1940
- /**
1941
- * Read a `directed` / `multigraph` flag token.
1942
- * @param v - the value token, or -1 when absent
1943
- * @param name - the flag name, for issues
1944
- * @returns the flag, or null when absent or not an integer
1945
- */
1946
- readFlag(v, name) {
1947
- if (v < 0) {
1948
- return null;
1949
- }
1950
- const t = this.requireTokens();
1951
- const quoted = t.kind[v] === TOKEN_STRING && QUOTED_INT.test(t.stringOf(v));
1952
- if (quoted) {
1953
- this.report.warning(
1954
- "validation-error",
1955
- FLAG_VALUE_CODE,
1956
- `flag "${name}" is written as the string ${describeValue(t, v)}; read as an integer`,
1957
- { line: t.line[v], element: name }
1958
- );
1959
- } else if (t.kind[v] !== TOKEN_INT) {
1960
- this.report.error(
1961
- "validation-error",
1962
- FLAG_TYPE_CODE,
1963
- `flag "${name}" must be the integer 0 or 1, found ${describeValue(t, v)}`,
1964
- { line: t.line[v], element: name }
1965
- );
1966
- return null;
1967
- }
1968
- const n = Number(quoted ? t.stringOf(v) : t.textOf(v));
1969
- if (n !== 0 && n !== 1) {
1970
- this.report.warning(
1971
- "validation-error",
1972
- FLAG_VALUE_CODE,
1973
- `flag "${name}" is ${n}; read as ${n !== 0 ? "1" : "0"}`,
1974
- { line: t.line[v], element: name }
1975
- );
1976
- }
1977
- return n !== 0;
1978
- }
1979
- /** Push the top-level attributes (every top-level key but graph, Creator and Version). */
1980
- pushTopLevel() {
1981
- const t = this.requireTokens();
1982
- for (let p = 0; p < t.count; p = t.nextPair(p)) {
1983
- const v = p + 1;
1984
- if (v === this.graphOpen || v === this.creatorToken || v === this.versionToken) {
1985
- continue;
1986
- }
1987
- const plan = this.topPlans.get(t.textOf(p));
1988
- if (plan !== void 0) {
1989
- this.writeGraph(plan, v, TOP_SEQ);
1990
- }
1991
- }
1992
- this.flushGraphLists();
1993
- }
1994
- /** Push every node block and the graph block's own attributes, in file order. */
1995
- pushNodes() {
1996
- const t = this.requireTokens();
1997
- const close = t.match[this.graphOpen];
1998
- for (let p = this.graphOpen + 1; p < close; p = t.nextPair(p)) {
1999
- const key = t.textOf(p);
2000
- const v = p + 1;
2001
- switch (key) {
2002
- case "node":
2003
- if (t.kind[v] === TOKEN_OPEN) {
2004
- this.importNode(v);
2005
- } else {
2006
- this.badElement("node", p);
2007
- this.report.counts.skippedNodes++;
2008
- }
2009
- break;
2010
- case "edge":
2011
- break;
2012
- case "directed":
2013
- case "multigraph":
2014
- if (v !== this.directedToken && v !== this.multigraphToken) {
2015
- this.report.warning(
2016
- "validation-error",
2017
- FLAG_VALUE_CODE,
2018
- `graph flag "${key}" repeated; the first value stands`,
2019
- { line: t.line[p], element: key }
2020
- );
2021
- }
2022
- break;
2023
- default: {
2024
- const plan = this.graphPlans.get(key);
2025
- if (plan !== void 0) {
2026
- this.writeGraph(plan, v, GRAPH_SEQ);
2027
- }
2028
- }
2029
- }
2030
- }
2031
- this.flushGraphLists();
2032
- }
2033
- /** Push every edge block, in file order. */
2034
- pushEdges() {
2035
- const t = this.requireTokens();
2036
- const close = t.match[this.graphOpen];
2037
- let ordinal = 0;
2038
- for (let p = this.graphOpen + 1; p < close; p = t.nextPair(p)) {
2039
- if (t.textOf(p) !== "edge") {
2040
- continue;
2041
- }
2042
- const v = p + 1;
2043
- if (t.kind[v] === TOKEN_OPEN) {
2044
- this.importEdge(v, ordinal);
2045
- } else {
2046
- this.badElement("edge", p);
2047
- this.report.counts.skippedEdges++;
2048
- }
2049
- ordinal++;
2050
- }
2051
- }
2052
- /**
2053
- * Record a `node` / `edge` key whose value is not a block.
2054
- * @param what - node or edge
2055
- * @param p - the key token
2056
- */
2057
- badElement(what, p) {
2058
- const t = this.requireTokens();
2059
- this.report.error(
2060
- "validation-error",
2061
- ELEMENT_TYPE_CODE,
2062
- `${what} must be a [ ... ] block, found ${describeValue(t, p + 1)}`,
2063
- { line: t.line[p], element: what }
2064
- );
2065
- }
2066
- /**
2067
- * Push one node block.
2068
- * @param open - the block's `[`
2069
- */
2070
- importNode(open) {
2071
- const t = this.requireTokens();
2072
- const { sink, report, options } = this;
2073
- const close = t.match[open];
2074
- const line = t.line[open];
2075
- const ordinal = this.nodeOrdinal++;
2076
- this.checkAbort();
2077
- let index;
2078
- let sinkId;
2079
- let fileId;
2080
- try {
2081
- let idTok = -1;
2082
- let labelTok = -1;
2083
- let originalTok = -1;
2084
- for (let p = open + 1; p < close; p = t.nextPair(p)) {
2085
- const key = t.textOf(p);
2086
- if (key === "id") {
2087
- idTok = this.structuralToken(idTok, p, "id");
2088
- } else if (key === "label") {
2089
- labelTok = labelTok < 0 ? p + 1 : labelTok;
2090
- } else if (key === ORIGINAL_ID_KEY && options.restoreMangledIds) {
2091
- originalTok = originalTok < 0 ? p + 1 : originalTok;
2092
- }
2093
- }
2094
- if (idTok < 0) {
2095
- throw new GraphFormatError("E_INVALID_ID", "node has no id", { reason: "missing id" });
2096
- }
2097
- fileId = this.coerceFileId(idTok, this.fileIdOf(idTok, "id"));
2098
- if (originalTok >= 0) {
2099
- sinkId = this.restoredId(originalTok);
2100
- } else {
2101
- switch (options.nodeIdFrom) {
2102
- case "label":
2103
- if (labelTok < 0) {
2104
- throw new GraphFormatError("E_INVALID_ID", "node has no label", {
2105
- reason: "missing label"
2106
- });
2107
- }
2108
- sinkId = this.coerceValueToken(labelTok);
2109
- break;
2110
- case "index":
2111
- sinkId = ordinal;
2112
- break;
2113
- default:
2114
- sinkId = fileId;
2115
- }
2116
- }
2117
- index = sink.addNode(sinkId);
2118
- if (this.idMap !== null) {
2119
- const before = this.idMap.get(fileId);
2120
- if (before !== void 0 && before !== sinkId) {
2121
- report.warning(
2122
- "merged",
2123
- DUPLICATE_NODE_CODE,
2124
- `file id ${JSON.stringify(fileId)} is declared twice (nodes ${JSON.stringify(before)} and ${JSON.stringify(sinkId)}); edges to it resolve to the later`,
2125
- { line, element: String(fileId) }
2126
- );
2127
- }
2128
- this.idMap.set(fileId, sinkId);
2129
- }
2130
- } catch (err) {
2131
- this.recordNodeError(err, line);
2132
- report.counts.skippedNodes++;
2133
- if (fileId !== void 0) {
2134
- this.skippedIds.add(fileId);
2135
- }
2136
- return;
2137
- }
2138
- if (this.isDeclared(index)) {
2139
- report.warning(
2140
- "merged",
2141
- DUPLICATE_NODE_CODE,
2142
- `node ${JSON.stringify(sinkId)} is declared twice; later keys overwrite`,
2143
- { line, element: String(sinkId) }
2144
- );
2145
- } else {
2146
- this.markDeclared(index);
2147
- report.counts.nodes++;
2148
- }
2149
- this.beginElement(this.seq++);
2150
- try {
2151
- const graphics = [];
2152
- let graphicsPlan = null;
2153
- for (let p = open + 1; p < close; p = t.nextPair(p)) {
2154
- const key = t.textOf(p);
2155
- if (key === "id" || key === ORIGINAL_ID_KEY && options.restoreMangledIds) {
2156
- continue;
2157
- }
2158
- const plan = this.nodePlans.get(key);
2159
- if (plan !== void 0 && plan.position !== null) {
2160
- graphicsPlan = plan;
2161
- graphics.push(p + 1);
2162
- } else if (plan !== void 0) {
2163
- this.writeNode(plan, index, p + 1);
2164
- }
2165
- }
2166
- if (graphicsPlan !== null) {
2167
- this.writeGraphics(graphicsPlan, index, graphics, {
2168
- line: t.line[graphics[0]],
2169
- element: String(sinkId)
2170
- });
2171
- }
2172
- this.flushLists("node", index);
2173
- } catch (err) {
2174
- this.touched.length = 0;
2175
- report.recordError(err, { line, element: String(sinkId) });
2176
- }
2177
- }
2178
- /**
2179
- * Push one edge block.
2180
- * @param open - the block's `[`
2181
- * @param ordinal - the edge's ordinal among edge blocks, for messages
2182
- */
2183
- importEdge(open, ordinal) {
2184
- const t = this.requireTokens();
2185
- const { sink, report, options } = this;
2186
- const close = t.match[open];
2187
- const line = t.line[open];
2188
- const element = `edge #${ordinal}`;
2189
- this.checkAbort();
2190
- let edge;
2191
- try {
2192
- let sourceTok = -1;
2193
- let targetTok = -1;
2194
- let weightTok = -1;
2195
- let directedTok = -1;
2196
- for (let p = open + 1; p < close; p = t.nextPair(p)) {
2197
- const key = t.textOf(p);
2198
- if (key === "source") {
2199
- sourceTok = this.structuralToken(sourceTok, p, "source");
2200
- } else if (key === "target") {
2201
- targetTok = this.structuralToken(targetTok, p, "target");
2202
- } else if (key === "directed") {
2203
- directedTok = this.structuralToken(directedTok, p, "directed");
2204
- } else if (key === options.weightFrom) {
2205
- weightTok = p + 1;
2206
- }
2207
- }
2208
- if (sourceTok < 0 || targetTok < 0) {
2209
- throw new GraphFormatError("E_UNKNOWN_NODE", `edge has no ${sourceTok < 0 ? "source" : "target"}`, {
2210
- reason: "missing endpoint"
2211
- });
2212
- }
2213
- const source = this.endpoint(sourceTok, "source");
2214
- const target = this.endpoint(targetTok, "target");
2215
- const weight = weightTok >= 0 ? this.weightOf(weightTok) : void 0;
2216
- const before = sink.edgeCount;
2217
- const sourceNew = sink.indexOf(source) === INVALID_INDEX;
2218
- const targetNew = source !== target && sink.indexOf(target) === INVALID_INDEX;
2219
- const directed = this.readFlag(directedTok, "directed") ?? this.headerDirected;
2220
- edge = this.requireResolver().addEdge(source, target, directed ? "directed" : "undirected", weight, {
2221
- line,
2222
- element
2223
- });
2224
- report.counts.edges += sink.edgeCount - before;
2225
- report.counts.nodes += (sourceNew ? 1 : 0) + (targetNew ? 1 : 0);
2226
- } catch (err) {
2227
- this.recordEdgeError(err, line, element);
2228
- report.counts.skippedEdges++;
2229
- return;
2230
- }
2231
- this.beginElement(this.seq++);
2232
- try {
2233
- for (let p = open + 1; p < close; p = t.nextPair(p)) {
2234
- const key = t.textOf(p);
2235
- if (key === "source" || key === "target" || key === "directed" || key === options.weightFrom) {
2236
- continue;
2237
- }
2238
- const plan = this.edgePlans.get(key);
2239
- if (plan !== void 0) {
2240
- this.writeEdge(plan, edge, p + 1);
2241
- }
2242
- }
2243
- this.flushLists("edge", edge);
2244
- } catch (err) {
2245
- this.touched.length = 0;
2246
- report.recordError(err, { line, element });
2247
- }
2248
- }
2249
- // ============================================================ ids and weights
2250
- /**
2251
- * Note a structural key token, refusing a repeat.
2252
- * @param previous - the token seen before, or -1
2253
- * @param p - the key token
2254
- * @param key - the key name
2255
- * @returns the value token
2256
- */
2257
- structuralToken(previous, p, key) {
2258
- if (previous >= 0) {
2259
- throw new GraphFormatError("E_INVALID_ID", `key "${key}" appears twice in one block`, {
2260
- reason: "duplicate key",
2261
- key
2262
- });
2263
- }
2264
- return p + 1;
2265
- }
2266
- /**
2267
- * The value of an id / source / target token: an integer (the GML spec's type) as a number, a
2268
- * string (NetworkX and Gephi write them) as its text with one warning per file.
2269
- * @param v - the value token
2270
- * @param key - the key name, for the error
2271
- * @returns the number or the string
2272
- */
2273
- fileIdOf(v, key) {
2274
- const t = this.requireTokens();
2275
- if (t.kind[v] === TOKEN_STRING) {
2276
- this.report.warnOnce(
2277
- "validation-error",
2278
- STRING_ID_CODE,
2279
- `${key} is the string "${t.textOf(v)}"; GML ids are integers, string ids are kept under the ids rule`,
2280
- { line: t.line[v], element: t.stringOf(v) }
2281
- );
2282
- return t.stringOf(v);
2283
- }
2284
- if (t.kind[v] !== TOKEN_INT) {
2285
- throw new GraphFormatError(
2286
- "E_INVALID_ID",
2287
- `${key} must be an integer or a string, found ${describeValue(t, v)}`,
2288
- {
2289
- reason: "not an integer",
2290
- key,
2291
- value: t.kind[v] === TOKEN_OPEN ? "[...]" : t.textOf(v)
2292
- }
2293
- );
2294
- }
2295
- return Number(t.textOf(v));
2296
- }
2297
- /**
2298
- * Coerce an id / source / target value under the `ids` rule: a string by its text, an integer
2299
- * through coerceInteger().
2300
- * @param v - the value token
2301
- * @param id - its value (fileIdOf())
2302
- * @returns the id
2303
- */
2304
- coerceFileId(v, id) {
2305
- return typeof id === "string" ? this.coercer.text(id) : this.coerceInteger(v, id);
2306
- }
2307
- /**
2308
- * Coerce an integer id token under the `ids` rule: a safe integer passes as a typed number
2309
- * (so `01` is 1 and `-0` is 0), a larger one goes through the text rule (a string under
2310
- * "canonical"), and "string" keeps the text as written.
2311
- * @param v - the value token
2312
- * @param n - its numeric value
2313
- * @returns the id
2314
- */
2315
- coerceInteger(v, n) {
2316
- if (Number.isSafeInteger(n) && this.coercer.mode !== "string") {
2317
- return this.coercer.value(n);
2318
- }
2319
- return this.coercer.text(this.requireTokens().textOf(v));
2320
- }
2321
- /**
2322
- * Coerce a label token under the `ids` rule: a string by its text, a number as a typed value.
2323
- * @param v - the value token
2324
- * @returns the id
2325
- */
2326
- coerceValueToken(v) {
2327
- const t = this.requireTokens();
2328
- switch (t.kind[v]) {
2329
- case TOKEN_STRING:
2330
- return this.coercer.text(t.stringOf(v));
2331
- case TOKEN_INT:
2332
- return this.coerceInteger(v, Number(t.textOf(v)));
2333
- case TOKEN_OPEN:
2334
- throw new GraphFormatError("E_INVALID_ID", "label must be a string or a number, found a record", {
2335
- reason: "record label"
2336
- });
2337
- default:
2338
- return this.coercer.value(numberOfText(t.textOf(v)));
2339
- }
2340
- }
2341
- /**
2342
- * The id a `graphty_originalId` key restores: typed, never coerced (the exporter wrote it exactly).
2343
- * @param v - the value token
2344
- * @returns the original id
2345
- */
2346
- restoredId(v) {
2347
- const t = this.requireTokens();
2348
- switch (t.kind[v]) {
2349
- case TOKEN_STRING:
2350
- return t.stringOf(v);
2351
- case TOKEN_OPEN:
2352
- throw new GraphFormatError("E_INVALID_ID", `${ORIGINAL_ID_KEY} must be a string or a number`, {
2353
- reason: "record original id"
2354
- });
2355
- default:
2356
- return numberOfText(t.textOf(v));
2357
- }
2358
- }
2359
- /**
2360
- * Resolve a source / target token to a sink id.
2361
- * @param v - the value token
2362
- * @param key - source or target
2363
- * @returns the id
2364
- */
2365
- endpoint(v, key) {
2366
- const id = this.coerceFileId(v, this.fileIdOf(v, key));
2367
- const mapped = this.idMap?.get(id);
2368
- if (mapped !== void 0) {
2369
- return mapped;
2370
- }
2371
- if (this.skippedIds.has(id)) {
2372
- throw new GraphFormatError(
2373
- "E_UNKNOWN_NODE",
2374
- `${key} ${JSON.stringify(id)} names a node block that was skipped after an error`,
2375
- { reason: "skipped node", id }
2376
- );
2377
- }
2378
- return id;
2379
- }
2380
- /**
2381
- * The weight of an edge from its weight token.
2382
- * @param v - the value token
2383
- * @returns the weight; E_INVALID_WEIGHT for a record or non-numeric text
2384
- */
2385
- weightOf(v) {
2386
- const t = this.requireTokens();
2387
- switch (t.kind[v]) {
2388
- case TOKEN_STRING:
2389
- return parseWeightText(t.stringOf(v), this.report);
2390
- case TOKEN_OPEN:
2391
- throw new GraphFormatError("E_INVALID_WEIGHT", "edge weight is a record", { value: "[...]" });
2392
- default: {
2393
- const text = t.textOf(v);
2394
- const weight = weightFromValue(numberOfText(text));
2395
- if (weight !== void 0) {
2396
- reportWeightPrecision(text, weight, this.report);
2397
- }
2398
- return weight;
2399
- }
2400
- }
2401
- }
2402
- /**
2403
- * Record a node-level error under the GML code it implies.
2404
- * @param err - the thrown value
2405
- * @param line - the block's line
2406
- */
2407
- recordNodeError(err, line) {
2408
- const { report } = this;
2409
- if (err instanceof GraphFormatError && err.code === "E_INVALID_ID") {
2410
- const { reason } = err.details;
2411
- switch (reason) {
2412
- case "missing id":
2413
- report.error("missing-value", MISSING_ID_CODE, err.message, { line, element: "node" });
2414
- return;
2415
- case "missing label":
2416
- report.error("missing-value", MISSING_LABEL_CODE, err.message, { line, element: "node" });
2417
- return;
2418
- case "duplicate key":
2419
- report.error("validation-error", REPEATED_KEY_CODE, err.message, { line, element: "node" });
2420
- return;
2421
- case "not an integer":
2422
- report.error("validation-error", ID_TYPE_CODE, err.message, { line, element: "node" });
2423
- return;
2424
- }
2425
- }
2426
- report.recordError(err, { line, element: "node" });
2427
- }
2428
- /**
2429
- * Record an edge-level error under the GML code it implies.
2430
- * @param err - the thrown value
2431
- * @param line - the block's line
2432
- * @param element - the edge description
2433
- */
2434
- recordEdgeError(err, line, element) {
2435
- const { report } = this;
2436
- if (err instanceof GraphFormatError) {
2437
- const { reason } = err.details;
2438
- if (err.code === "E_UNKNOWN_NODE" && reason === "missing endpoint") {
2439
- report.error("missing-value", MISSING_ENDPOINT_CODE, err.message, { line, element });
2440
- return;
2441
- }
2442
- if (err.code === "E_INVALID_ID" && reason === "duplicate key") {
2443
- report.error("validation-error", REPEATED_KEY_CODE, err.message, { line, element });
2444
- return;
2445
- }
2446
- if (err.code === "E_INVALID_ID" && reason === "not an integer") {
2447
- report.error("validation-error", ID_TYPE_CODE, err.message, { line, element });
2448
- return;
2449
- }
2450
- }
2451
- report.recordError(err, { line, element });
2452
- }
2453
- // ============================================================ values
2454
- /**
2455
- * Write one node value.
2456
- * @param plan - the key's plan
2457
- * @param index - the node index
2458
- * @param v - the value token
2459
- */
2460
- writeNode(plan, index, v) {
2461
- if (plan.list) {
2462
- this.collectItem(plan, v, this.seqNow, this.touched);
2463
- return;
2464
- }
2465
- this.sink.setNodeValue(this.handleOf(plan, "node"), index, this.scalarOf(plan, v));
2466
- }
2467
- /**
2468
- * Write one edge value.
2469
- * @param plan - the key's plan
2470
- * @param edge - the edge index
2471
- * @param v - the value token
2472
- */
2473
- writeEdge(plan, edge, v) {
2474
- if (plan.list) {
2475
- this.collectItem(plan, v, this.seqNow, this.touched);
2476
- return;
2477
- }
2478
- this.sink.setEdgeValue(this.handleOf(plan, "edge"), edge, this.scalarOf(plan, v));
2479
- }
2480
- /**
2481
- * Write one graph value.
2482
- * @param plan - the key's plan
2483
- * @param v - the value token
2484
- * @param seq - TOP_SEQ or GRAPH_SEQ
2485
- */
2486
- writeGraph(plan, v, seq) {
2487
- if (plan.list) {
2488
- this.collectItem(plan, v, seq, this.graphTouched);
2489
- return;
2490
- }
2491
- const value = this.scalarOf(plan, v);
2492
- this.sink.setGraphValue(plan.name, value, graphDecl(plan));
2493
- if (seq === GRAPH_SEQ && plan.key === "name" && typeof value === "string") {
2494
- this.sink.setMeta({ name: value });
2495
- }
2496
- }
2497
- /**
2498
- * Write a node's graphics values: the position column from the x / y / z of the first record,
2499
- * everything else (the remaining keys, a value that is not a record, a repeated record) to the
2500
- * json column, with a warning when the value cannot give a position as written.
2501
- * @param plan - the graphics plan
2502
- * @param index - the node index
2503
- * @param vs - the value tokens of the node's graphics keys, in order
2504
- * @param where - the line and the node, for issues
2505
- */
2506
- writeGraphics(plan, index, vs, where) {
2507
- const t = this.requireTokens();
2508
- const { sink } = this;
2509
- const values = vs.map((v) => t.kind[v] === TOKEN_OPEN ? parseRecord(t, v) : this.scalarOf(plan, v));
2510
- const first = values[0];
2511
- const positionPlan = plan.position;
2512
- let rest = first;
2513
- if (isRecord(first) && positionPlan !== null) {
2514
- const left = this.writePosition(positionPlan, index, this.keepPositionSource ? { ...first } : first, where);
2515
- rest = this.keepPositionSource ? first : left;
2516
- } else if (!isRecord(first)) {
2517
- this.graphicsWarning("scalar", `node ${where.element}'s graphics is not a record`, where);
2518
- }
2519
- if (values.length > 1) {
2520
- this.graphicsWarning(
2521
- "repeated",
2522
- `node ${where.element} has ${values.length} graphics records; the position comes from the first`,
2523
- where
2524
- );
2525
- rest = values;
2526
- }
2527
- if (rest !== void 0 && plan.rest !== null) {
2528
- sink.setNodeValue(this.handleOf(plan.rest, "node"), index, rest);
2529
- }
2530
- }
2531
- /**
2532
- * Write a node's position from the x / y / z of its graphics record, taking them out of it.
2533
- * @param positionPlan - the position column's plan
2534
- * @param index - the node index
2535
- * @param record - the graphics record
2536
- * @param where - the line and the node, for issues
2537
- * @returns what is left of the record for the json column, or undefined when nothing is
2538
- */
2539
- writePosition(positionPlan, index, record, where) {
2540
- const { x, y, z } = record;
2541
- let rest = record;
2542
- if (typeof x === "number" && typeof y === "number") {
2543
- const depth = typeof z === "number" ? z : 0;
2544
- this.sink.setNodeValue(this.handleOf(positionPlan, "node"), index, [x, y, depth]);
2545
- delete record.x;
2546
- delete record.y;
2547
- if (typeof z === "number") {
2548
- delete record.z;
2549
- }
2550
- rest = Object.keys(record).length > 0 ? record : void 0;
2551
- }
2552
- if ("x" in record || "y" in record || "z" in record) {
2553
- this.graphicsWarning(
2554
- "coordinate",
2555
- `node ${where.element}'s graphics x / y / z is not one number each`,
2556
- where
2557
- );
2558
- }
2559
- return rest;
2560
- }
2561
- /**
2562
- * Warn once per kind of graphics problem.
2563
- * @param kind - the problem
2564
- * @param what - the message start, naming the node
2565
- * @param where - the line and the node
2566
- */
2567
- graphicsWarning(kind, what, where) {
2568
- this.report.warnOnce(
2569
- "validation-error",
2570
- GRAPHICS_CODE,
2571
- `${what}; the value is kept in the graphics json column (warned once for every such node)`,
2572
- where,
2573
- `${GRAPHICS_CODE}:${kind}`
2574
- );
2575
- }
2576
- /**
2577
- * Collect one list item.
2578
- * @param plan - the list plan
2579
- * @param v - the value token
2580
- * @param seq - the sequence number of the element the item belongs to
2581
- * @param touched - the plans touched by that element
2582
- */
2583
- collectItem(plan, v, seq, touched) {
2584
- const t = this.requireTokens();
2585
- if (plan.seq !== seq) {
2586
- plan.seq = seq;
2587
- plan.items = [];
2588
- touched.push(plan);
2589
- }
2590
- if (t.kind[v] === TOKEN_STRING) {
2591
- const raw = t.textOf(v);
2592
- if (raw === LIST_START_MARKER || raw === EMPTY_LIST_TEXT || raw === EMPTY_TUPLE_TEXT) {
2593
- return;
2594
- }
2595
- }
2596
- plan.items.push(this.scalarOf(plan, v));
2597
- }
2598
- /**
2599
- * Start a node or edge: later list items belong to it.
2600
- * @param seq - the element's sequence number
2601
- */
2602
- beginElement(seq) {
2603
- this.seqNow = seq;
2604
- this.touched.length = 0;
2605
- }
2606
- /**
2607
- * Write the lists collected for the current node or edge.
2608
- * @param domain - node or edge
2609
- * @param row - the row
2610
- */
2611
- flushLists(domain, row) {
2612
- const { sink, touched } = this;
2613
- for (const plan of touched) {
2614
- const handle = this.handleOf(plan, domain);
2615
- if (domain === "node") {
2616
- sink.setNodeValue(handle, row, plan.items);
2617
- } else {
2618
- sink.setEdgeValue(handle, row, plan.items);
2619
- }
2620
- plan.items = null;
2621
- }
2622
- touched.length = 0;
2623
- }
2624
- /** Write the lists collected for the graph table. */
2625
- flushGraphLists() {
2626
- const { sink, graphTouched } = this;
2627
- for (const plan of graphTouched) {
2628
- sink.setGraphValue(plan.name, plan.items, graphDecl(plan));
2629
- plan.items = null;
2630
- }
2631
- graphTouched.length = 0;
2632
- }
2633
- /**
2634
- * The JS value of a scalar value token (or list item) under a plan's storage class.
2635
- * @param plan - the plan
2636
- * @param v - the value token
2637
- * @returns the value to push
2638
- */
2639
- scalarOf(plan, v) {
2640
- const t = this.requireTokens();
2641
- const kind = t.kind[v];
2642
- switch (plan.kind) {
2643
- case "int":
2644
- return Number(t.textOf(v));
2645
- case "real":
2646
- return numberOfText(t.textOf(v));
2647
- case "string":
2648
- return kind === TOKEN_STRING ? t.stringOf(v) : t.textOf(v);
2649
- default:
2650
- return kind === TOKEN_STRING ? t.stringOf(v) : scalarOrRecord(t, v);
2651
- }
2652
- }
2653
- /**
2654
- * The handle of a plan's column, declaring it on first use. A declaration the sink refuses
2655
- * because a column of the name exists with another declaration falls back to that column
2656
- * (reported once); a taken role is dropped (reported once).
2657
- * @param plan - the plan
2658
- * @param domain - node or edge
2659
- * @returns the handle
2660
- */
2661
- handleOf(plan, domain) {
2662
- if (plan.declared) {
2663
- return plan.handle;
2664
- }
2665
- plan.declared = true;
2666
- const { sink, report } = this;
2667
- const decl = {
2668
- name: plan.name,
2669
- dtype: plan.dtype,
2670
- nullable: true,
2671
- origin: { format: "gml", id: plan.key, title: null, type: originTypeOf(plan), namespace: null }
2672
- };
2673
- if (plan.list) {
2674
- decl.itemDtype = plan.itemDtype ?? "string";
2675
- }
2676
- if (plan.role === "position") {
2677
- decl.components = 3;
2678
- }
2679
- if (plan.role !== null) {
2680
- decl.role = plan.role;
2681
- }
2682
- const resolved = declareResolved(sink, domain, decl, report, { element: plan.name });
2683
- plan.handle = resolved.handle;
2684
- if (resolved.renamed) {
2685
- plan.name = resolved.decl.name;
2686
- }
2687
- return plan.handle;
2688
- }
2689
- // ============================================================ bookkeeping
2690
- /**
2691
- * Whether a node index was declared by a node block of this import.
2692
- * @param index - the node index
2693
- * @returns true when declared
2694
- */
2695
- isDeclared(index) {
2696
- const word = index >>> 5;
2697
- return word < this.declared.length && (this.declared[word] >>> (index & 31) & 1) === 1;
2698
- }
2699
- /**
2700
- * Mark a node index as declared.
2701
- * @param index - the node index
2702
- */
2703
- markDeclared(index) {
2704
- const word = index >>> 5;
2705
- if (word >= this.declared.length) {
2706
- const grown = new Uint32Array(Math.max(word + 1, this.declared.length * 2));
2707
- grown.set(this.declared);
2708
- this.declared = grown;
2709
- }
2710
- this.declared[word] |= 1 << (index & 31);
2711
- }
2712
- /** Check the abort signal every ABORT_CHECK_INTERVAL elements. */
2713
- checkAbort() {
2714
- if (++this.elementsSinceCheck >= ABORT_CHECK_INTERVAL) {
2715
- this.elementsSinceCheck = 0;
2716
- throwIfAborted(this.options.signal);
2717
- }
2718
- }
2719
- /**
2720
- * The tokens, which exist after run() lexed the text.
2721
- * @returns the tokens
2722
- */
2723
- requireTokens() {
2724
- if (this.tokens === null) {
2725
- throw new GraphFormatError("E_UNSUPPORTED", "the GML text was not lexed", { reason: "no tokens" });
2726
- }
2727
- return this.tokens;
2728
- }
2729
- /**
2730
- * The direction resolver, which exists once the header was set.
2731
- * @returns the resolver
2732
- */
2733
- requireResolver() {
2734
- if (this.resolver === null) {
2735
- throw new GraphFormatError("E_DIRECTED", "the header was not set", { reason: "no resolver" });
2736
- }
2737
- return this.resolver;
2738
- }
2739
- }
2740
- function kindBit(t, v) {
2741
- switch (t.kind[v]) {
2742
- case TOKEN_INT:
2743
- return KIND_INT;
2744
- case TOKEN_STRING:
2745
- return KIND_STRING;
2746
- case TOKEN_OPEN:
2747
- return KIND_RECORD;
2748
- default:
2749
- return KIND_REAL;
2750
- }
2751
- }
2752
- function kindOf(entry) {
2753
- if ((entry.kinds & KIND_RECORD) !== 0) {
2754
- return "record";
2755
- }
2756
- if ((entry.kinds & KIND_STRING) !== 0) {
2757
- return "string";
2758
- }
2759
- if ((entry.kinds & KIND_REAL) !== 0) {
2760
- return "real";
2761
- }
2762
- return "int";
2763
- }
2764
- function dtypeOfKind(kind, entry) {
2765
- switch (kind) {
2766
- case "int":
2767
- return entry.wide ? "f64" : "i32";
2768
- case "real":
2769
- return "f64";
2770
- case "string":
2771
- return "string";
2772
- default:
2773
- return "json";
2774
- }
2775
- }
2776
- function originTypeOf(plan) {
2777
- return plan.kind;
2778
- }
2779
- function graphDecl(plan) {
2780
- const decl = {
2781
- name: plan.name,
2782
- dtype: plan.dtype,
2783
- nullable: true,
2784
- origin: { format: "gml", id: plan.key, title: null, type: originTypeOf(plan), namespace: null }
2785
- };
2786
- if (plan.list) {
2787
- decl.itemDtype = plan.itemDtype ?? "string";
2788
- }
2789
- if (plan.top) {
2790
- decl.extra = { gmlTopLevel: true };
2791
- }
2792
- return decl;
2793
- }
2794
- function describeValue(t, v) {
2795
- switch (t.kind[v]) {
2796
- case TOKEN_OPEN:
2797
- return "a record";
2798
- case TOKEN_STRING:
2799
- return `the string "${t.textOf(v)}"`;
2800
- case TOKEN_REAL:
2801
- return `the real ${t.textOf(v)}`;
2802
- case TOKEN_WORD:
2803
- return `the word ${t.textOf(v)}`;
2804
- default:
2805
- return t.textOf(v);
2806
- }
2807
- }
2808
- const SNIFF_GRAPH_START = /^(?:\s|#[^\n]*\n)*graph\s*\[/;
2809
- const SNIFF_GRAPH_ANYWHERE = /(?:^|\s)graph\s*\[/;
2810
- const SNIFF_KEY_START = /^(?:\s|#[^\n]*\n)*[A-Za-z_]\w*\s+(?:"|[+-]?[0-9.]|\[)/;
2811
- function sniffGml(head) {
2812
- let text = new TextDecoder("utf-8", { fatal: false }).decode(head);
2813
- if (text.charCodeAt(0) === 65279) {
2814
- text = text.slice(1);
2815
- }
2816
- if (SNIFF_GRAPH_START.test(text)) {
2817
- return 0.95;
2818
- }
2819
- if (SNIFF_KEY_START.test(text)) {
2820
- return SNIFF_GRAPH_ANYWHERE.test(text) ? 0.85 : 0.4;
2821
- }
2822
- return 0;
2823
- }
2824
- const gmlImporter = Object.freeze({
2825
- format: "gml",
2826
- options: Object.freeze(["dictionaries", "keepPositionSource", "positions"]),
2827
- extensions: Object.freeze([".gml"]),
2828
- mimeTypes: Object.freeze(["text/x-gml", "text/plain"]),
2829
- sniff: sniffGml,
2830
- /**
2831
- * Read a GML text into a sink.
2832
- * @param input - the text, bytes or stream
2833
- * @param sink - the sink
2834
- * @param options - format-specific and common options
2835
- * @returns the report
2836
- */
2837
- async import(input, sink, options) {
2838
- if (graphChosen(options)) {
2839
- return importChosenGraph(gmlImporter, input, sink, options);
2840
- }
2841
- const resolved = resolveImportOptions(options, FORMAT_DEFAULTS);
2842
- const report = new ImportReportBuilder("gml", resolved.errorLimit);
2843
- reportSinkOptions(sink, options, report);
2844
- reportUnusedOptions(options, report, USED_OPTIONS);
2845
- const tokens = tokenize(await readText(input, report, resolved), report);
2846
- throwIfAborted(resolved.signal);
2847
- const gml = new GmlImport(sink, report, resolved, options);
2848
- gml.run(tokens);
2849
- if (gml.graphCount > 1) {
2850
- report.warning(
2851
- "unsupported",
2852
- SECOND_GRAPH_CODE,
2853
- `the input holds ${gml.graphCount - 1} more graph block${plural(gml.graphCount - 1)} after the first; the first is read (graphIndex or graphName chooses another; importAllGraphs() reads every one)`
2854
- );
2855
- }
2856
- throwIfAborted(resolved.signal);
2857
- return report.finish();
2858
- },
2859
- /**
2860
- * Read every `graph [ ... ]` block of a GML text, each into its own sink; the top-level keys
2861
- * (Creator, Version, ...) apply to each.
2862
- * @param input - the text, bytes or stream
2863
- * @param sinkFor - the sink of the graph with this index, called before its first push
2864
- * @param options - format-specific and common options
2865
- * @returns one report per graph block
2866
- */
2867
- async importAll(input, sinkFor, options) {
2868
- const resolved = resolveImportOptions(options, FORMAT_DEFAULTS);
2869
- const first = new ImportReportBuilder("gml", resolved.errorLimit);
2870
- reportUnusedOptions(options, first, USED_OPTIONS);
2871
- const tokens = tokenize(await readText(input, first, resolved), first);
2872
- const reports = [];
2873
- let count = 1;
2874
- for (let i = 0; i < count; i++) {
2875
- throwIfAborted(resolved.signal);
2876
- const report = i === 0 ? first : new ImportReportBuilder("gml", resolved.errorLimit);
2877
- const sink = sinkFor(i);
2878
- reportSinkOptions(sink, options, report);
2879
- const gml = new GmlImport(sink, report, resolved, options, i);
2880
- gml.run(tokens);
2881
- count = gml.graphCount;
2882
- reports.push(report.finish());
2883
- }
2884
- throwIfAborted(resolved.signal);
2885
- return reports;
2886
- }
2887
- });
2888
- function tokenize(text, report) {
2889
- try {
2890
- return tokenizeGml(text);
2891
- } catch (err) {
2892
- if (err instanceof GmlSyntaxError) {
2893
- report.fail(err.code, err.message, { line: err.line });
2894
- }
2895
- throw err;
2896
- }
2897
- }
2898
- const GML_ISSUE = Object.freeze({
2899
- ...INPUT_ISSUE,
2900
- ...ELEMENT_ISSUE,
2901
- /**
2902
- * The text breaks GML's syntax: a word that is not a key or a value, an unclosed string or `[`, a stray `]`, or a
2903
- * key without a value. The import stops.
2904
- */
2905
- SYNTAX: SYNTAX_CODE,
2906
- /** The input is not valid UTF-8. The import stops. */
2907
- INVALID_UTF8: INVALID_UTF8_CODE,
2908
- /**
2909
- * Some bytes are not valid in the encoding that was chosen (by a byte order mark, the file's declaration or the
2910
- * `encoding` option). The import stops.
2911
- */
2912
- INVALID_ENCODING: INVALID_ENCODING_CODE,
2913
- /** Bytes that are not UTF-8 and declare no encoding were read as windows-1252. */
2914
- ENCODING_FALLBACK: ENCODING_FALLBACK_CODE,
2915
- /** A declared encoding the platform cannot decode was ignored. */
2916
- UNKNOWN_ENCODING: UNKNOWN_ENCODING_CODE,
2917
- /** There is no `graph [` block. The import stops. */
2918
- NO_GRAPH: NO_GRAPH_CODE,
2919
- /** The file holds more than one `graph` block and only the first was read. It is not added when `graphIndex` or `graphName` chose the graph. */
2920
- MULTIPLE_GRAPHS: SECOND_GRAPH_CODE,
2921
- /** `graphIndex` or `graphName` names no graph of the file; the message lists the graphs it holds. The import stops. */
2922
- GRAPH_NOT_FOUND: GRAPH_NOT_FOUND_CODE,
2923
- /** `graphName` matches more than one graph; pass `graphIndex`. The import stops. */
2924
- AMBIGUOUS_GRAPH_NAME: AMBIGUOUS_GRAPH_NAME_CODE,
2925
- /** A node without an `id`. */
2926
- MISSING_ID: MISSING_ID_CODE,
2927
- /** A node without a `label` under nodeIdFrom "label". */
2928
- MISSING_LABEL: MISSING_LABEL_CODE,
2929
- /** An edge without `source` or `target`. */
2930
- MISSING_ENDPOINT: MISSING_ENDPOINT_CODE,
2931
- /** A node id, source or target that is neither an integer nor a string. */
2932
- ID_TYPE: ID_TYPE_CODE,
2933
- /**
2934
- * Node ids, sources or targets are text, where GML expects integers. They are read under the `ids` option.
2935
- * Reported once per file.
2936
- */
2937
- STRING_ID: STRING_ID_CODE,
2938
- /** A node id declared twice (later keys overwrite). */
2939
- DUPLICATE_NODE: DUPLICATE_NODE_CODE,
2940
- /** A structural key repeated in one element. */
2941
- REPEATED_KEY: REPEATED_KEY_CODE,
2942
- /** A `node` / `edge` key whose value is not a record. */
2943
- ELEMENT_TYPE: ELEMENT_TYPE_CODE,
2944
- /** A `directed` / `multigraph` flag that is not an integer. */
2945
- FLAG_TYPE: FLAG_TYPE_CODE,
2946
- /** A `directed` / `multigraph` flag outside 0 / 1, or repeated. */
2947
- FLAG_VALUE: FLAG_VALUE_CODE,
2948
- /** A named entity no table decodes, or a numeric reference beyond U+10FFFF; kept as written. */
2949
- UNKNOWN_ENTITY: UNKNOWN_ENTITY_CODE,
2950
- /** An integer beyond 2^53 was stored as the nearest 64-bit float; pass `long: "string"` to keep every digit. */
2951
- PRECISION: PRECISION_CODE,
2952
- /** A node's graphics value that cannot give a position as written; kept in the graphics json column. */
2953
- GRAPHICS: GRAPHICS_CODE,
2954
- /** A graph, node or edge record nested in a node or edge; kept as json, not read as structure. */
2955
- NESTED_ELEMENT: NESTED_ELEMENT_CODE,
2956
- /** YEd's isGroup / gid keys, kept as plain columns; the hierarchy is not read as containment. */
2957
- GROUPS: GROUPS_CODE,
2958
- /**
2959
- * An attribute's type was widened because a later value did not fit: an integer above 2^31 in an integer column,
2960
- * or two declared types for one attribute.
2961
- */
2962
- WIDENED: WIDENED_CODE,
2963
- /**
2964
- * An attribute was renamed `<name>#<suffix>` because another attribute already has its name, for example
2965
- * two attributes declared with the same name.
2966
- */
2967
- COLUMN_RENAMED: COLUMN_RENAMED_CODE,
2968
- /**
2969
- * You read into a graph builder that already has an id, label or position attribute, so this file's one is kept as
2970
- * a plain attribute.
2971
- */
2972
- ROLE_TAKEN: ROLE_TAKEN_CODE,
2973
- /** Two different id texts became the same number because `ids` is "number", so their nodes were merged. */
2974
- ID_MERGED: ID_MERGED_CODE,
2975
- /** You set an option this format does not use; it had no effect. The message names the option. */
2976
- OPTION_IGNORED: OPTION_IGNORED_CODE,
2977
- /**
2978
- * You read into your own graph builder, which was created with a different `addMissingNodes`, `duplicateEdges`,
2979
- * `selfLoops` or `weightDtype` than the option you passed; the builder's setting applies.
2980
- */
2981
- SINK_OPTION: SINK_OPTION_CODE,
2982
- /**
2983
- * You read into a graph builder whose direction is already set, or which already holds edges, so the file is read
2984
- * with the builder's direction instead of its own.
2985
- */
2986
- DIRECTION_REFUSED: DIRECTION_REFUSED_CODE,
2987
- /** Edges of the other direction were read with the direction `onMixedDirection` chose. */
2988
- DIRECTION_FORCED: DIRECTION_FORCED_CODE,
2989
- /**
2990
- * The graph has both directed and undirected edges and `onMixedDirection` is "error". An import stops; a save to a
2991
- * format that holds one direction per file fails with E_DIRECTED. Pass "directed" or "undirected" to read or write
2992
- * it anyway.
2993
- */
2994
- MIXED_DIRECTION: MIXED_DIRECTION_CODE,
2995
- /**
2996
- * Under `nodeIdFrom: "label"` or `"index"` the file's integer ids are not kept. It is listed in `report.lossy`, not
2997
- * in `report.issues`.
2998
- */
2999
- ID_DROPPED: ID_DROPPED_CODE
3000
- });
3001
- const GML_LOSS = Object.freeze({
3002
- /** A json column holds numbers; GML records cannot keep int versus real. */
3003
- RECORD_NUMBER_TYPE: RECORD_NUMBER_TYPE_CODE,
3004
- /** A json column holds booleans, written 1 / 0. */
3005
- RECORD_BOOLEAN: RECORD_BOOLEAN_CODE,
3006
- /** A json column holds nulls, omitted. */
3007
- RECORD_NULL: RECORD_NULL_CODE,
3008
- /** An attribute holds an array inside an array, which GML cannot write; the save fails. */
3009
- NESTED_ARRAY: NESTED_ARRAY_CODE,
3010
- /** A json row that is an array, written as repeated keys. */
3011
- JSON_ARRAY: JSON_ARRAY_CODE,
3012
- /**
3013
- * An attribute name GML cannot use as a key (keys are letters and digits, starting with a letter). The save fails
3014
- * unless `sanitizeKeys` is "mangle".
3015
- */
3016
- INVALID_KEY: INVALID_KEY_CODE,
3017
- /** A column named like a structural key. */
3018
- RESERVED_KEY: RESERVED_KEY_CODE,
3019
- /** A key rewritten under sanitizeKeys "mangle". */
3020
- KEY_MANGLED: KEY_MANGLED_CODE,
3021
- /** A position column with more than three components. */
3022
- POSITION_COMPONENTS: POSITION_COMPONENTS_CODE,
3023
- /** A graphics record whose x / y / z the position column overrides. */
3024
- GRAPHICS_OVERRIDDEN: GRAPHICS_OVERRIDDEN_CODE,
3025
- /** A graphics record that cannot hold the position. */
3026
- GRAPHICS_CONFLICT: GRAPHICS_CONFLICT_CODE
3027
- });
1
+ import "./chunks/format-GDmO6m6Q.js";
2
+ import { G, b, c, d, a, g } from "./chunks/index-B9fdNpTA.js";
3028
3
  export {
3029
- GML_ISSUE,
3030
- GML_LOSS,
3031
- gmlExporter,
3032
- gmlImporter
4
+ G as GML_ISSUE,
5
+ b as GML_LOSS,
6
+ c as GML_STYLE_BLOCK_KEY,
7
+ d as GML_STYLE_CAPABILITIES,
8
+ a as gmlExporter,
9
+ g as gmlImporter
3033
10
  };
3034
11
  //# sourceMappingURL=gml.js.map