@graphty/graph-io 0.3.43 → 0.3.45

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-DJMHdDvv.js +40 -0
  2. package/dist/chunks/approximations-DJMHdDvv.js.map +1 -0
  3. package/dist/chunks/block-CPCHkX42.js +2777 -0
  4. package/dist/chunks/block-CPCHkX42.js.map +1 -0
  5. package/dist/chunks/{choose-DvpbdRuz.js → choose--jM0yYCo.js} +3 -2
  6. package/dist/chunks/{choose-DvpbdRuz.js.map → choose--jM0yYCo.js.map} +1 -1
  7. package/dist/chunks/{constants-fT3E8JYY.js → constants-BKwqelYD.js} +6 -2
  8. package/dist/chunks/constants-BKwqelYD.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-DZy6JgdA.js +3456 -0
  12. package/dist/chunks/emit-DZy6JgdA.js.map +1 -0
  13. package/dist/chunks/{escape-B62ZGM_a.js → escape-CgzxiYPg.js} +44 -21
  14. package/dist/chunks/escape-CgzxiYPg.js.map +1 -0
  15. package/dist/chunks/{export-rKLeGQMo.js → export-BvqAXCKh.js} +196 -792
  16. package/dist/chunks/export-BvqAXCKh.js.map +1 -0
  17. package/dist/chunks/{exporter-yLxKBvLE.js → exporter--Mk9gXCJ.js} +4 -3
  18. package/dist/chunks/{exporter-yLxKBvLE.js.map → exporter--Mk9gXCJ.js.map} +1 -1
  19. package/dist/chunks/{exporter-RVtXVetw.js → exporter-C-9cgZKa.js} +1805 -287
  20. package/dist/chunks/exporter-C-9cgZKa.js.map +1 -0
  21. package/dist/chunks/{exporter-8hLNemFk.js → exporter-DFqJhBnj.js} +133 -74
  22. package/dist/chunks/exporter-DFqJhBnj.js.map +1 -0
  23. package/dist/chunks/{exporter-BWwEuOPT.js → exporter-DteVeJki.js} +22 -12
  24. package/dist/chunks/exporter-DteVeJki.js.map +1 -0
  25. package/dist/chunks/format-BpQBx8MZ.js +676 -0
  26. package/dist/chunks/format-BpQBx8MZ.js.map +1 -0
  27. package/dist/chunks/generic-BGO71QBv.js +1347 -0
  28. package/dist/chunks/generic-BGO71QBv.js.map +1 -0
  29. package/dist/chunks/{importer-C98dpSH4.js → importer-B-9Rc1zO.js} +141 -82
  30. package/dist/chunks/importer-B-9Rc1zO.js.map +1 -0
  31. package/dist/chunks/{importer-D794XUTe.js → importer-BVVR740x.js} +31 -8
  32. package/dist/chunks/importer-BVVR740x.js.map +1 -0
  33. package/dist/chunks/{importer-WrGRZb0N.js → importer-C0AjA3Ax.js} +449 -102
  34. package/dist/chunks/importer-C0AjA3Ax.js.map +1 -0
  35. package/dist/chunks/{importer-BbNb7eNg.js → importer-C7pvJe1L.js} +1398 -129
  36. package/dist/chunks/importer-C7pvJe1L.js.map +1 -0
  37. package/dist/chunks/{importer-xZ-3suY1.js → importer-ClwoVx3O.js} +791 -135
  38. package/dist/chunks/importer-ClwoVx3O.js.map +1 -0
  39. package/dist/chunks/{importer-Ht7LNg8L.js → importer-D0sC_6bO.js} +116 -296
  40. package/dist/chunks/importer-D0sC_6bO.js.map +1 -0
  41. package/dist/chunks/{importer-Dz7tI8Sa.js → importer-EHQk1jbM.js} +617 -115
  42. package/dist/chunks/importer-EHQk1jbM.js.map +1 -0
  43. package/dist/chunks/{json-elements-DKSqpNW1.js → json-elements-DJZRZ6jd.js} +123 -32
  44. package/dist/chunks/json-elements-DJZRZ6jd.js.map +1 -0
  45. package/dist/chunks/lexicon-WMsNddyU.js +509 -0
  46. package/dist/chunks/lexicon-WMsNddyU.js.map +1 -0
  47. package/dist/chunks/{ontology-export-CtRXjg_i.js → ontology-export-G4MqRdux.js} +3 -2
  48. package/dist/chunks/{ontology-export-CtRXjg_i.js.map → ontology-export-G4MqRdux.js.map} +1 -1
  49. package/dist/chunks/{records-Cu4bxYOm.js → records-CiaWZrFH.js} +2 -2
  50. package/dist/chunks/{records-Cu4bxYOm.js.map → records-CiaWZrFH.js.map} +1 -1
  51. package/dist/chunks/styles-DvoFBKCK.js +690 -0
  52. package/dist/chunks/styles-DvoFBKCK.js.map +1 -0
  53. package/dist/chunks/styles-yed-Cz9rLBCP.js +842 -0
  54. package/dist/chunks/styles-yed-Cz9rLBCP.js.map +1 -0
  55. package/dist/chunks/styles-zNTmz5R7.js +2102 -0
  56. package/dist/chunks/styles-zNTmz5R7.js.map +1 -0
  57. package/dist/chunks/{text-DHOJXnED.js → text-CzJNFOS9.js} +2 -2
  58. package/dist/chunks/{text-DHOJXnED.js.map → text-CzJNFOS9.js.map} +1 -1
  59. package/dist/chunks/units-XMZFIFe1.js +19 -0
  60. package/dist/chunks/units-XMZFIFe1.js.map +1 -0
  61. package/dist/chunks/writer-gQ8kx99H.js +448 -0
  62. package/dist/chunks/writer-gQ8kx99H.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 +292 -412
  71. package/dist/gexf.js.map +1 -1
  72. package/dist/gml.js +927 -74
  73. package/dist/gml.js.map +1 -1
  74. package/dist/graph-io.js +351 -236
  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 +1496 -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 +20 -5
  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 +439 -264
  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 +791 -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 +605 -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 +89 -0
  489. package/dist/src/styles/io/writer.d.ts.map +1 -0
  490. package/dist/src/styles/io/writer.js +626 -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 +1755 -0
  571. package/src/formats/gexf/exporter.ts +27 -11
  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 +541 -322
  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 +952 -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 +658 -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 +780 -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-RVtXVetw.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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export-BvqAXCKh.js","sources":["../../src/common/temporal.ts","../../src/common/declared-types.ts","../../src/common/lists.ts","../../src/common/attributes.ts","../../src/common/direction.ts","../../src/common/ids.ts","../../src/common/input.ts","../../src/common/options.ts","../../src/common/weights.ts","../../src/common/export.ts"],"sourcesContent":["/**\n * Temporal values (design section 5.1): `date` / `dateTime` attributes, GEXF time bounds and Neo4j\n * temporal types become f64 epoch milliseconds (or the raw numeric time when the file's timeformat\n * is integer / double). When a value's canonical re-formatting would differ from the source text (a\n * UTC offset, fractional seconds beyond milliseconds, a date without a time in a dateTime column)\n * the importer also keeps the lexical form in a companion `<column>.text` column with role\n * `timeText`; the exporter emits the text when present and formats the number otherwise.\n *\n * Only ISO-8601 forms are parsed (XSD date / dateTime / time and Neo4j's literals), by a fixed\n * grammar rather than Date.parse, so two hosts agree on every value.\n */\n\nimport { type ColumnDecl, type ColumnRole, GraphFormatError } from \"@graphty/graph-format\";\n\n/**\n * The temporal kinds a declared type can map to; each fixes the parse grammar and the canonical text.\n * @category Plugin helpers\n */\nexport type TemporalKind = \"date\" | \"dateTime\" | \"localDateTime\" | \"time\" | \"localTime\";\n\n/**\n * The GEXF `timeformat` values (design section 5.9).\n * @public\n * @category Plugin helpers\n */\nexport type TimeFormat = \"integer\" | \"double\" | \"date\" | \"dateTime\";\n\n/**\n * A parsed temporal value: the number stored in the column and the source text when it must be kept.\n * @category Plugin helpers\n */\nexport interface TemporalValue {\n /** Epoch milliseconds (date, dateTime, localDateTime), milliseconds since midnight (time, localTime), or the raw number. */\n readonly value: number;\n /** The source text when formatTemporal(value) would not reproduce it; null otherwise. */\n readonly text: string | null;\n}\n\n/**\n * The role of a companion text column.\n * @category Plugin helpers\n */\nexport const TIME_TEXT_ROLE: ColumnRole = \"timeText\";\n\n/**\n * The suffix of a companion text column's name.\n * @category Plugin helpers\n */\nexport const TIME_TEXT_SUFFIX = \".text\";\n\nconst DATE_TIME =\n /^(-?\\d{4,})-(\\d{2})-(\\d{2})(?:[T ](\\d{2}):(\\d{2})(?::(\\d{2})(?:\\.(\\d{1,9}))?)?)?(Z|z|[+-]\\d{2}(?::?\\d{2})?)?$/;\nconst TIME = /^(\\d{2}):(\\d{2})(?::(\\d{2})(?:\\.(\\d{1,9}))?)?(Z|z|[+-]\\d{2}(?::?\\d{2})?)?$/;\nconst NUMERIC = /^[+-]?(\\d+(\\.\\d*)?|\\.\\d+)([eE][+-]?\\d+)?$/;\n\nconst MS_PER_MINUTE = 60_000;\nconst MS_PER_DAY = 86_400_000;\n\n/**\n * Parse an ISO-8601 temporal text of one kind.\n * @param text - the source text (already trimmed)\n * @param kind - the temporal kind\n * @returns the value and, when the canonical form differs, the source text; E_COLUMN_TYPE when the text is not of the kind\n * @category Plugin helpers\n */\nexport function parseTemporal(text: string, kind: TemporalKind): TemporalValue {\n let value: number;\n switch (kind) {\n case \"date\":\n case \"dateTime\":\n case \"localDateTime\":\n value = parseDateTime(text, kind);\n break;\n case \"time\":\n case \"localTime\":\n value = parseTime(text, kind);\n break;\n default: {\n const name: string = kind;\n throw new GraphFormatError(\"E_COLUMN_TYPE\", `unknown temporal kind ${name}`, { kind: name });\n }\n }\n const canonical = formatTemporal(value, kind);\n return { value, text: canonical === text ? null : text };\n}\n\n/**\n * Parse a GEXF time bound (`start`, `end`, `timestamp`, a spell or an attvalue time) under the\n * graph's timeformat: integer / double values are numbers as written; date / dateTime values are\n * ISO text; when the format is unknown (absent header) numeric text is a number and anything else\n * is tried as dateTime.\n * @param text - the source text\n * @param timeFormat - the graph's timeformat, or null when the file declares none\n * @returns the value and the source text when it must be kept\n * @category Plugin helpers\n */\nexport function parseTimeText(text: string, timeFormat: TimeFormat | null): TemporalValue {\n const trimmed = text.trim();\n switch (timeFormat) {\n case \"integer\":\n case \"double\":\n return parseNumericTime(trimmed);\n case \"date\":\n return parseTemporal(trimmed, \"date\");\n case \"dateTime\":\n return parseTemporal(trimmed, \"dateTime\");\n case null:\n return NUMERIC.test(trimmed) ? parseNumericTime(trimmed) : parseTemporal(trimmed, \"dateTime\");\n default: {\n const name: string = timeFormat;\n throw new GraphFormatError(\"E_COLUMN_TYPE\", `unknown timeformat ${name}`, { timeFormat: name });\n }\n }\n}\n\n/**\n * Format a temporal value in its canonical ISO-8601 form.\n * @param value - the number as stored\n * @param kind - the temporal kind\n * @returns the canonical text: `YYYY-MM-DD`, `YYYY-MM-DDTHH:MM:SS[.mmm]Z`, `YYYY-MM-DDTHH:MM:SS[.mmm]`,\n * `HH:MM:SS[.mmm]Z` or `HH:MM:SS[.mmm]`\n * @category Plugin helpers\n */\nexport function formatTemporal(value: number, kind: TemporalKind): string {\n switch (kind) {\n case \"date\": {\n const d = new Date(value);\n return `${year(d)}-${pad2(d.getUTCMonth() + 1)}-${pad2(d.getUTCDate())}`;\n }\n case \"dateTime\":\n case \"localDateTime\": {\n const d = new Date(value);\n const date = `${year(d)}-${pad2(d.getUTCMonth() + 1)}-${pad2(d.getUTCDate())}`;\n const time = clock(d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds());\n return kind === \"dateTime\" ? `${date}T${time}Z` : `${date}T${time}`;\n }\n case \"time\":\n case \"localTime\": {\n const ms = ((value % MS_PER_DAY) + MS_PER_DAY) % MS_PER_DAY;\n const h = Math.floor(ms / 3_600_000);\n const m = Math.floor((ms % 3_600_000) / MS_PER_MINUTE);\n const s = Math.floor((ms % MS_PER_MINUTE) / 1000);\n const text = clock(h, m, s, ms % 1000);\n return kind === \"time\" ? `${text}Z` : text;\n }\n default: {\n const name: string = kind;\n throw new GraphFormatError(\"E_COLUMN_TYPE\", `unknown temporal kind ${name}`, { kind: name });\n }\n }\n}\n\n/**\n * Format a GEXF time bound under the graph's timeformat: the number's shortest text for integer /\n * double, the canonical ISO form otherwise.\n * @param value - the value as stored\n * @param timeFormat - the graph's timeformat, or null for a file that declares none (double)\n * @returns the text\n * @category Plugin helpers\n */\nexport function formatTimeValue(value: number, timeFormat: TimeFormat | null): string {\n switch (timeFormat) {\n case \"date\":\n return formatTemporal(value, \"date\");\n case \"dateTime\":\n return formatTemporal(value, \"dateTime\");\n case \"integer\":\n case \"double\":\n case null:\n return String(value);\n default: {\n const name: string = timeFormat;\n throw new GraphFormatError(\"E_COLUMN_TYPE\", `unknown timeformat ${name}`, { timeFormat: name });\n }\n }\n}\n\n/**\n * The declaration of the companion text column of a temporal column (design section 5.1).\n * @param column - the temporal column's name\n * @returns a string column named `<column>.text` with role timeText and `extra.for` naming the column\n * @category Plugin helpers\n */\nexport function timeTextCompanion(column: string): ColumnDecl {\n return {\n name: column + TIME_TEXT_SUFFIX,\n dtype: \"string\",\n role: TIME_TEXT_ROLE,\n nullable: true,\n extra: { for: column },\n };\n}\n\n/**\n * Parse a numeric time bound.\n * @param text - the trimmed source text\n * @returns the number; the text is kept when String(value) differs from it\n */\nfunction parseNumericTime(text: string): TemporalValue {\n if (!NUMERIC.test(text)) {\n throw new GraphFormatError(\"E_COLUMN_TYPE\", `\"${text}\" is not a numeric time`, { value: text });\n }\n const value = Number(text);\n return { value, text: String(value) === text ? null : text };\n}\n\n/**\n * Parse a date or date-time text into epoch milliseconds.\n * @param text - the source text\n * @param kind - date (a time part is accepted and kept in the companion), dateTime or localDateTime\n * @returns epoch milliseconds\n */\nfunction parseDateTime(text: string, kind: \"date\" | \"dateTime\" | \"localDateTime\"): number {\n const m = DATE_TIME.exec(text);\n if (m === null) {\n throw new GraphFormatError(\"E_COLUMN_TYPE\", `\"${text}\" is not an ISO-8601 ${kind}`, { value: text, kind });\n }\n const y = Number(m[1]);\n const month = Number(m[2]);\n const day = Number(m[3]);\n const hour = m[4] === undefined ? 0 : Number(m[4]);\n const minute = m[5] === undefined ? 0 : Number(m[5]);\n const second = m[6] === undefined ? 0 : Number(m[6]);\n const ms = m[7] === undefined ? 0 : fractionMs(m[7]);\n if (month < 1 || month > 12 || day < 1 || day > 31 || hour > 24 || minute > 59 || second > 60) {\n throw new GraphFormatError(\"E_COLUMN_TYPE\", `\"${text}\" is out of range for a ${kind}`, { value: text, kind });\n }\n // Date.UTC maps years 0..99 to 1900..1999; the setters do not\n const d = new Date(0);\n d.setUTCFullYear(y, month - 1, day);\n d.setUTCHours(hour, minute, second, ms);\n if (d.getUTCDate() !== day && hour !== 24) {\n throw new GraphFormatError(\"E_COLUMN_TYPE\", `\"${text}\" is not a calendar date`, { value: text, kind });\n }\n const offset = m[8] === undefined ? 0 : offsetMinutes(m[8]);\n return d.getTime() - offset * MS_PER_MINUTE;\n}\n\n/**\n * Parse a time-of-day text into milliseconds since midnight (UTC for `time` with a zone).\n * @param text - the source text\n * @param kind - time or localTime\n * @returns milliseconds since midnight in 0..86400000\n */\nfunction parseTime(text: string, kind: \"time\" | \"localTime\"): number {\n const m = TIME.exec(text);\n if (m === null) {\n throw new GraphFormatError(\"E_COLUMN_TYPE\", `\"${text}\" is not an ISO-8601 ${kind}`, { value: text, kind });\n }\n const hour = Number(m[1]);\n const minute = Number(m[2]);\n const second = m[3] === undefined ? 0 : Number(m[3]);\n const ms = m[4] === undefined ? 0 : fractionMs(m[4]);\n if (hour > 24 || minute > 59 || second > 60) {\n throw new GraphFormatError(\"E_COLUMN_TYPE\", `\"${text}\" is out of range for a ${kind}`, { value: text, kind });\n }\n const local = ((hour * 60 + minute) * 60 + second) * 1000 + ms;\n const offset = m[5] === undefined ? 0 : offsetMinutes(m[5]);\n const utc = local - offset * MS_PER_MINUTE;\n return ((utc % MS_PER_DAY) + MS_PER_DAY) % MS_PER_DAY;\n}\n\n/**\n * Milliseconds of a fractional-second text (1 to 9 digits), truncated to whole milliseconds.\n * @param digits - the digits after the decimal point\n * @returns 0..999\n */\nfunction fractionMs(digits: string): number {\n return Math.floor(Number(`0.${digits}`) * 1000);\n}\n\n/**\n * The minutes of a zone designator.\n * @param zone - \"Z\", \"+HH:MM\", \"+HHMM\" or \"+HH\"\n * @returns signed minutes east of UTC\n */\nfunction offsetMinutes(zone: string): number {\n if (zone === \"Z\" || zone === \"z\") {\n return 0;\n }\n const sign = zone.startsWith(\"-\") ? -1 : 1;\n const digits = zone.slice(1).replace(\":\", \"\");\n const hours = Number(digits.slice(0, 2));\n const minutes = digits.length > 2 ? Number(digits.slice(2, 4)) : 0;\n return sign * (hours * 60 + minutes);\n}\n\n/**\n * Two-digit zero-padded text.\n * @param n - 0..99\n * @returns the text\n */\nfunction pad2(n: number): string {\n return n < 10 ? `0${n}` : String(n);\n}\n\n/**\n * The year of a UTC date as at least four digits (negative years keep their sign).\n * @param d - the date\n * @returns the text\n */\nfunction year(d: Date): string {\n const y = d.getUTCFullYear();\n const abs = String(Math.abs(y)).padStart(4, \"0\");\n return y < 0 ? `-${abs}` : abs;\n}\n\n/**\n * `HH:MM:SS` with `.mmm` appended when the milliseconds are not zero.\n * @param h - hours\n * @param m - minutes\n * @param s - seconds\n * @param ms - milliseconds\n * @returns the text\n */\nfunction clock(h: number, m: number, s: number, ms: number): string {\n const base = `${pad2(h)}:${pad2(m)}:${pad2(s)}`;\n return ms === 0 ? base : `${base}.${String(ms).padStart(3, \"0\")}`;\n}\n","/**\n * The declared-type table of design section 5.1: what the type text of a GEXF `<attribute>`, a\n * GraphML `<key>`, a GML value class or a Neo4j CSV header maps to, and how a value's text is\n * parsed once the column dtype is known.\n *\n * Declared types map exactly: `double` and `long` -> f64, `float` -> f32, `int` / `integer` /\n * `short` / `byte` -> i32, `boolean` -> bool, `string` / `anyURI` / `char` -> string, `bigdecimal`\n * / `biginteger` -> string, `date` / `dateTime` and the Neo4j temporal types -> f64 (epoch or\n * time-of-day milliseconds, design section 5.1), `list*` and `[]` -> list of the item type, GML\n * `record` and Neo4j `point` -> json. A declared `long` is stored as f64 with a precision flag\n * (values beyond 2^53 are a `precision` issue) unless the importer option `long: \"string\"` keeps the\n * whole column as text. Neo4j `duration` has no epoch and is kept as text. The declared type text is\n * recorded in `origin.type` in every case so the exporter can restore the declaration.\n */\n\nimport { type Dtype, GraphFormatError, type ScalarDtype } from \"@graphty/graph-format\";\n\nimport { withArticle } from \"./plural.js\";\nimport { parseTemporal, type TemporalKind } from \"./temporal.js\";\n\n/**\n * The formats whose declarations this table covers.\n * @category Plugin helpers\n */\nexport type DeclaringFormat = \"gexf\" | \"graphml\" | \"gml\" | \"neo4j\";\n\n/** How the text of one scalar value (or one list item) is parsed. */\ntype ValueKind =\n \"boolean\" | \"integer\" | \"long\" | \"float\" | \"double\" | \"string\" | \"temporal\" | \"duration\" | \"point\" | \"json\";\n\n/**\n * The resolved storage of a declared type.\n * @category Plugin helpers\n */\nexport interface DeclaredTypeSpec {\n /** The declared type text as given by the file (origin.type). */\n readonly declared: string;\n /** The column dtype. */\n readonly dtype: Dtype;\n /** The item dtype of a list column, null otherwise. */\n readonly itemDtype: ScalarDtype | null;\n /** How each scalar value or list item text is parsed. */\n readonly kind: ValueKind;\n /** Whether the column is a list. */\n readonly list: boolean;\n /** The temporal kind of a temporal value, null otherwise. */\n readonly temporal: TemporalKind | null;\n /** Whether values may exceed 2^53 (a long stored as f64), so the importer checks Number.isSafeInteger. */\n readonly precision: boolean;\n}\n\n/** A scalar entry of the table before the list flag and the long mode are applied. */\ninterface ScalarEntry {\n readonly dtype: ScalarDtype;\n readonly kind: ValueKind;\n readonly temporal?: TemporalKind;\n readonly precision?: boolean;\n}\n\nconst BOOLEAN: ScalarEntry = { dtype: \"bool\", kind: \"boolean\" };\nconst INTEGER: ScalarEntry = { dtype: \"i32\", kind: \"integer\" };\nconst LONG: ScalarEntry = { dtype: \"f64\", kind: \"long\", precision: true };\nconst FLOAT: ScalarEntry = { dtype: \"f32\", kind: \"float\" };\nconst DOUBLE: ScalarEntry = { dtype: \"f64\", kind: \"double\" };\nconst STRING: ScalarEntry = { dtype: \"string\", kind: \"string\" };\nconst DATE: ScalarEntry = { dtype: \"f64\", kind: \"temporal\", temporal: \"date\" };\nconst DATE_TIME: ScalarEntry = { dtype: \"f64\", kind: \"temporal\", temporal: \"dateTime\" };\nconst LOCAL_DATE_TIME: ScalarEntry = { dtype: \"f64\", kind: \"temporal\", temporal: \"localDateTime\" };\nconst TIME: ScalarEntry = { dtype: \"f64\", kind: \"temporal\", temporal: \"time\" };\nconst LOCAL_TIME: ScalarEntry = { dtype: \"f64\", kind: \"temporal\", temporal: \"localTime\" };\nconst DURATION: ScalarEntry = { dtype: \"string\", kind: \"duration\" };\nconst POINT: ScalarEntry = { dtype: \"json\", kind: \"point\" };\nconst RECORD: ScalarEntry = { dtype: \"json\", kind: \"json\" };\n\n/** GEXF 1.2 / 1.3 scalar types (the `list*` variants are derived). */\nconst GEXF_SCALARS: Readonly<Record<string, ScalarEntry>> = {\n integer: INTEGER,\n long: LONG,\n double: DOUBLE,\n float: FLOAT,\n boolean: BOOLEAN,\n string: STRING,\n anyuri: STRING,\n char: STRING,\n byte: INTEGER,\n short: INTEGER,\n bigdecimal: STRING,\n biginteger: STRING,\n date: DATE,\n datetime: DATE_TIME,\n};\n\n/** GraphML `attr.type` values. */\nconst GRAPHML_SCALARS: Readonly<Record<string, ScalarEntry>> = {\n boolean: BOOLEAN,\n int: INTEGER,\n long: LONG,\n float: FLOAT,\n double: DOUBLE,\n string: STRING,\n};\n\n/** GML value classes (per value in the file; the GML importer names them per column). */\nconst GML_SCALARS: Readonly<Record<string, ScalarEntry>> = {\n int: INTEGER,\n real: DOUBLE,\n string: STRING,\n record: RECORD,\n};\n\n/** Neo4j CSV header types and Cypher property type names. */\nconst NEO4J_SCALARS: Readonly<Record<string, ScalarEntry>> = {\n int: INTEGER,\n integer: LONG,\n long: LONG,\n float: FLOAT,\n double: DOUBLE,\n boolean: BOOLEAN,\n byte: INTEGER,\n short: INTEGER,\n char: STRING,\n string: STRING,\n point: POINT,\n date: DATE,\n localtime: LOCAL_TIME,\n time: TIME,\n localdatetime: LOCAL_DATE_TIME,\n datetime: DATE_TIME,\n duration: DURATION,\n};\n\nconst TABLES: Readonly<Record<DeclaringFormat, Readonly<Record<string, ScalarEntry>>>> = {\n gexf: GEXF_SCALARS,\n graphml: GRAPHML_SCALARS,\n gml: GML_SCALARS,\n neo4j: NEO4J_SCALARS,\n};\n\nconst INTEGER_TEXT = /^[+-]?\\d+$/;\nconst DECIMAL_TEXT = /^[+-]?(\\d+(\\.\\d*)?|\\.\\d+)([eE][+-]?\\d+)?$/;\nconst I32_MIN = -2147483648;\nconst I32_MAX = 2147483647;\n\n/**\n * Resolve a declared type text of one format to its storage.\n * @param format - the declaring format\n * @param type - the type text as written (matched case-insensitively; GEXF `list*` and Neo4j `[]` denote lists)\n * @param long - how declared long / integer-64 columns are stored (the importer option)\n * @returns the spec, or null when the format does not define the type (the importer reports it and keeps the text)\n * @category Plugin helpers\n */\nexport function mapDeclaredType(\n format: DeclaringFormat,\n type: string,\n long: \"f64\" | \"string\",\n): DeclaredTypeSpec | null {\n const table = TABLES[format];\n let key = type.trim().toLowerCase();\n let list = false;\n if (format === \"gexf\" && key.startsWith(\"list\") && key.length > 4) {\n list = true;\n key = key.slice(4);\n } else if (format === \"neo4j\" && key.endsWith(\"[]\")) {\n list = true;\n key = key.slice(0, -2);\n } else if (format === \"gml\" && key === \"list\") {\n return {\n declared: type,\n dtype: \"list\",\n itemDtype: \"json\",\n kind: \"json\",\n list: true,\n temporal: null,\n precision: false,\n };\n }\n let entry = table[key];\n if (entry === undefined) {\n return null;\n }\n if (entry.kind === \"long\" && long === \"string\") {\n entry = STRING;\n }\n return {\n declared: type,\n dtype: list ? \"list\" : entry.dtype,\n itemDtype: list ? entry.dtype : null,\n kind: entry.kind,\n list,\n temporal: entry.temporal ?? null,\n precision: entry.precision ?? false,\n };\n}\n\n/**\n * The spec of an untyped attribute: a string column with the given (or absent) type text.\n * @param declared - the type text to record in origin.type, or null\n * @returns a string spec\n * @category Plugin helpers\n */\nexport function stringSpec(declared: string | null): DeclaredTypeSpec {\n return {\n declared: declared ?? \"\",\n dtype: \"string\",\n itemDtype: null,\n kind: \"string\",\n list: false,\n temporal: null,\n precision: false,\n };\n}\n\n/**\n * Parse the text of one scalar value (or list item) by its kind. Numeric and boolean kinds trim\n * surrounding whitespace (pretty-printed XML puts newlines around `<data>` text); string kinds keep\n * the text exactly.\n * @param text - the value text\n * @param kind - the value kind\n * @param temporal - the temporal kind when `kind` is \"temporal\"\n * @returns a boolean, a number, a string or (point / json) a JSON value; E_COLUMN_TYPE when the text is not of the kind\n * @category Plugin helpers\n */\nexport function parseScalarText(text: string, kind: ValueKind, temporal: TemporalKind | null = null): unknown {\n switch (kind) {\n case \"boolean\": {\n const value = parseBooleanText(text);\n if (value === null) {\n throw typeError(text, kind);\n }\n return value;\n }\n case \"integer\": {\n const trimmed = text.trim();\n if (!INTEGER_TEXT.test(trimmed)) {\n throw typeError(text, kind);\n }\n const value = Number(trimmed);\n if (value < I32_MIN || value > I32_MAX) {\n throw new GraphFormatError(\"E_COLUMN_TYPE\", `\"${trimmed}\" is outside the 32-bit integer range`, {\n value: trimmed,\n kind,\n });\n }\n return value;\n }\n case \"long\": {\n const trimmed = text.trim();\n if (!INTEGER_TEXT.test(trimmed)) {\n throw typeError(text, kind);\n }\n return Number(trimmed);\n }\n case \"float\":\n case \"double\":\n return parseDecimalText(text, kind);\n case \"string\":\n case \"duration\":\n return text;\n case \"temporal\": {\n if (temporal === null) {\n throw new GraphFormatError(\"E_COLUMN_TYPE\", \"a temporal value needs its temporal kind\", { kind });\n }\n return parseTemporal(text.trim(), temporal).value;\n }\n case \"point\":\n return parsePointText(text);\n case \"json\":\n return parseJsonText(text);\n default: {\n const name: string = kind;\n throw new GraphFormatError(\"E_COLUMN_TYPE\", `unknown value kind ${name}`, { kind: name });\n }\n }\n}\n\n/**\n * Parse a boolean text the way the formats write it: `true` / `false` in any case, or `1` / `0`.\n * @param text - the value text\n * @returns the boolean, or null when the text is neither\n * @category Plugin helpers\n */\nexport function parseBooleanText(text: string): boolean | null {\n switch (text.trim().toLowerCase()) {\n case \"true\":\n case \"1\":\n return true;\n case \"false\":\n case \"0\":\n return false;\n default:\n return null;\n }\n}\n\n/**\n * Parse a float / double text: a decimal or exponent literal, or the XSD / JSON spellings of the\n * non-finite values (`INF`, `-INF`, `Infinity`, `-Infinity`, `NaN`).\n * @param text - the value text\n * @param kind - float or double, for the error\n * @returns the number\n * @category Plugin helpers\n */\nexport function parseDecimalText(text: string, kind: ValueKind = \"double\"): number {\n const trimmed = text.trim();\n if (DECIMAL_TEXT.test(trimmed)) {\n return Number(trimmed);\n }\n switch (trimmed) {\n case \"INF\":\n case \"+INF\":\n case \"Infinity\":\n case \"+Infinity\":\n return Infinity;\n case \"-INF\":\n case \"-Infinity\":\n return -Infinity;\n case \"NaN\":\n return Number.NaN;\n default:\n throw typeError(text, kind);\n }\n}\n\n/**\n * Whether a number text is finite as written but too large for a double (`1e400`, a 400-digit\n * integer), so it parses as Infinity: a value the importer should report, unlike `INF`.\n * @param text - the value text\n * @returns true when the text overflows\n * @category Plugin helpers\n */\nexport function overflowsToInfinity(text: string): boolean {\n const trimmed = text.trim();\n return /^[+-]?[0-9.]/.test(trimmed) && Number(trimmed) === (trimmed.startsWith(\"-\") ? -Infinity : Infinity);\n}\n\n/**\n * Parse a Neo4j point literal `{x:1.0, y:2.0, crs:'cartesian'}` (also `latitude` / `longitude` /\n * `height` / `z` / `srid`) into a JSON object; a JSON object text is accepted as well.\n * @param text - the value text\n * @returns an object with numeric coordinates and string crs\n * @category Plugin helpers\n */\nexport function parsePointText(text: string): Readonly<Record<string, number | string>> {\n const trimmed = text.trim();\n if (!trimmed.startsWith(\"{\") || !trimmed.endsWith(\"}\")) {\n throw typeError(text, \"point\");\n }\n const out: Record<string, number | string> = {};\n const inner = trimmed.slice(1, -1).trim();\n if (inner.length === 0) {\n return out;\n }\n for (const part of inner.split(\",\")) {\n const colon = part.indexOf(\":\");\n if (colon < 0) {\n throw typeError(text, \"point\");\n }\n const key = part\n .slice(0, colon)\n .trim()\n .replaceAll(/(?:^[\"'])|(?:[\"']$)/g, \"\");\n const raw = part.slice(colon + 1).trim();\n if (key.length === 0) {\n throw typeError(text, \"point\");\n }\n if (DECIMAL_TEXT.test(raw)) {\n out[key] = Number(raw);\n } else if ((raw.startsWith(\"'\") && raw.endsWith(\"'\")) || (raw.startsWith('\"') && raw.endsWith('\"'))) {\n out[key] = raw.slice(1, -1);\n } else {\n throw typeError(text, \"point\");\n }\n }\n return out;\n}\n\n/**\n * Parse JSON text into a value.\n * @param text - the JSON text\n * @returns the parsed value\n */\nfunction parseJsonText(text: string): unknown {\n try {\n return JSON.parse(text) as unknown;\n } catch {\n throw typeError(text, \"json\");\n }\n}\n\n/**\n * The E_COLUMN_TYPE error of a text that is not of a kind.\n * @param text - the text\n * @param kind - the kind\n * @returns the error\n */\nfunction typeError(text: string, kind: ValueKind): GraphFormatError {\n const shown = text.length > 40 ? `${text.slice(0, 40)}...` : text;\n return new GraphFormatError(\"E_COLUMN_TYPE\", `\"${shown}\" is not ${withArticle(kind)}`, { value: text, kind });\n}\n","/**\n * List value syntaxes of the text formats (design section 5.1, research note 07 section 2.1):\n * GEXF 1.3 bracket lists `[1, 2, 3]` / `[foo, 'bar baz']`, GEXF 1.2 `liststring` values separated\n * by `|`, `,` or `;` (\"an unsafe type\"), Gephi and Neo4j `;`-separated arrays. The importer splits\n * the text into item texts with splitListText() and parses each item by the declared item type.\n */\n\nimport { GraphFormatError } from \"@graphty/graph-format\";\n\n/**\n * The list syntaxes an importer or exporter names.\n * @category Plugin helpers\n */\nexport type ListSyntax = \"gexf\" | \"brackets\" | \"pipe\" | \"comma\" | \"semicolon\";\n\n/**\n * Split a list value into its item texts.\n *\n * - \"gexf\": a bracketed text `[a, b]` is parsed with single or double quotes around items that\n * contain commas; otherwise the 1.2 rule applies: the text is split on `|` when it contains one,\n * else on `,` when it contains one, else on `;` when it contains one, else it is one item.\n * - \"brackets\": bracketed only; an unbracketed text is one item.\n * - \"pipe\" / \"comma\" / \"semicolon\": split on that separator.\n *\n * Items are trimmed; an empty text (or `[]`) is an empty list; an empty item between separators\n * is kept as an empty string.\n * @param text - the value text\n * @param syntax - the syntax\n * @returns the item texts\n * @category Plugin helpers\n */\nexport function splitListText(text: string, syntax: ListSyntax): string[] {\n const trimmed = text.trim();\n if (trimmed.length === 0) {\n return [];\n }\n switch (syntax) {\n case \"gexf\": {\n if (isBracketed(trimmed)) {\n return splitBracketed(trimmed);\n }\n const separator = firstSeparator(trimmed, [\"|\", \",\", \";\"]);\n return separator === null ? [trimmed] : splitOn(trimmed, separator);\n }\n case \"brackets\":\n return isBracketed(trimmed) ? splitBracketed(trimmed) : [trimmed];\n case \"pipe\":\n return splitOn(trimmed, \"|\");\n case \"comma\":\n return splitOn(trimmed, \",\");\n case \"semicolon\":\n return splitOn(trimmed, \";\");\n default: {\n const name: string = syntax;\n throw new GraphFormatError(\"E_UNSUPPORTED\", `unknown list syntax ${name}`, {\n option: \"listSyntax\",\n found: name,\n });\n }\n }\n}\n\n/**\n * Join item texts into a list value of one syntax, the inverse of splitListText() for the exporters.\n * Bracket syntaxes quote an item that contains a comma, a bracket or a quote (with double quotes,\n * a double quote inside doubled); separator syntaxes cannot escape and leave items as they are.\n * @param items - the item texts\n * @param syntax - the syntax; \"gexf\" writes the 1.3 bracket form\n * @returns the list text\n * @category Plugin helpers\n */\nexport function joinListText(items: readonly string[], syntax: ListSyntax): string {\n switch (syntax) {\n case \"gexf\":\n case \"brackets\":\n return `[${items.map(quoteBracketItem).join(\", \")}]`;\n case \"pipe\":\n return items.join(\"|\");\n case \"comma\":\n return items.join(\",\");\n case \"semicolon\":\n return items.join(\";\");\n default: {\n const name: string = syntax;\n throw new GraphFormatError(\"E_UNSUPPORTED\", `unknown list syntax ${name}`, {\n option: \"listSyntax\",\n found: name,\n });\n }\n }\n}\n\n/**\n * Whether a trimmed text is `[...]`.\n * @param text - the trimmed text\n * @returns true when bracketed\n */\nfunction isBracketed(text: string): boolean {\n return text.length >= 2 && text.startsWith(\"[\") && text.endsWith(\"]\");\n}\n\n/**\n * The first of several separators that occurs in a text.\n * @param text - the text\n * @param candidates - separators in priority order\n * @returns the first candidate found, or null\n */\nfunction firstSeparator(text: string, candidates: readonly string[]): string | null {\n for (const candidate of candidates) {\n if (text.includes(candidate)) {\n return candidate;\n }\n }\n return null;\n}\n\n/**\n * Split on a separator and trim every item.\n * @param text - the text\n * @param separator - the separator\n * @returns the trimmed items\n */\nfunction splitOn(text: string, separator: string): string[] {\n return text.split(separator).map((item) => item.trim());\n}\n\n/**\n * Parse the inside of a bracketed list: comma-separated items, each optionally wrapped in single\n * or double quotes (a doubled quote inside a quoted item is one quote).\n * @param text - the bracketed text\n * @returns the items\n */\nfunction splitBracketed(text: string): string[] {\n const inner = text.slice(1, -1);\n const items: string[] = [];\n const n = inner.length;\n if (inner.trim().length === 0) {\n return items;\n }\n let i = 0;\n for (;;) {\n while (i < n && isSpace(inner.charCodeAt(i))) {\n i++;\n }\n let item = \"\";\n if (i < n && (inner[i] === '\"' || inner[i] === \"'\")) {\n const quoted = readQuoted(inner, i);\n item = quoted.text;\n i = quoted.end;\n }\n // unquoted text, or text after a closing quote that is not a separator, runs to the next comma\n let end = inner.indexOf(\",\", i);\n if (end < 0) {\n end = n;\n }\n item += inner.slice(i, end).trim();\n items.push(item);\n i = end;\n if (i >= n) {\n return items;\n }\n i++;\n if (inner.slice(i).trim().length === 0) {\n items.push(\"\");\n return items;\n }\n }\n}\n\n/**\n * Read a quoted item of a bracketed list: a doubled quote inside it is one quote, and a missing\n * closing quote ends it at the end of the text.\n * @param inner - the inside of the brackets\n * @param open - the index of the opening quote\n * @returns the unquoted text and the index just past the closing quote\n */\nfunction readQuoted(inner: string, open: number): { text: string; end: number } {\n const quote = inner[open];\n const n = inner.length;\n let text = \"\";\n let i = open + 1;\n while (i < n) {\n if (inner[i] !== quote) {\n text += inner[i];\n i++;\n } else if (inner[i + 1] === quote) {\n text += quote;\n i += 2;\n } else {\n return { text, end: i + 1 };\n }\n }\n return { text, end: i };\n}\n\n/**\n * Whether a char code is ASCII whitespace.\n * @param c - the char code\n * @returns true for space, tab, CR, LF\n */\nfunction isSpace(c: number): boolean {\n return c === 32 || c === 9 || c === 13 || c === 10;\n}\n\n/**\n * Quote one item for a bracket list when it needs it.\n * @param item - the item text\n * @returns the item, quoted when it contains a comma, a bracket, a quote or surrounding whitespace\n */\nfunction quoteBracketItem(item: string): string {\n if (item.length === 0 || /[,[\\]\"']/.test(item) || item !== item.trim()) {\n return `\"${item.replaceAll('\"', '\"\"')}\"`;\n }\n return item;\n}\n","/**\n * Attribute declaration shared by the typed importers (design sections 5.1, 5.5 and 5.6): turn a\n * GEXF `<attribute>`, a GraphML `<key>` or a Neo4j header column into a ColumnDecl with the right\n * dtype, default, options and origin metadata; parse values (scalars and lists) by the declaration;\n * derive the deterministic `<name>#<origin.id>` name when a declared name collides; and the dict\n * heuristic of design section 5.4.\n *\n * Naming rule (design section 5.6): a column's name is the GEXF `title` / GraphML `attr.name`,\n * falling back to the attribute `id` when the title is absent; `origin.id` always keeps the source\n * id and `origin.title` the title when it differs from the resolved name.\n */\n\nimport {\n type ColumnDecl,\n type ColumnHandle,\n type ColumnRole,\n GraphFormatError,\n type GraphSink,\n INVALID_INDEX,\n} from \"@graphty/graph-format\";\n\nimport { type IssueCategory } from \"../types.js\";\nimport {\n BAD_DEFAULT_CODE,\n BAD_OPTIONS_CODE,\n COLUMN_RENAMED_CODE,\n ROLE_TAKEN_CODE,\n UNKNOWN_ATTR_TYPE_CODE,\n} from \"./codes.js\";\nimport {\n type DeclaredTypeSpec,\n type DeclaringFormat,\n mapDeclaredType,\n parseScalarText,\n stringSpec,\n} from \"./declared-types.js\";\nimport { type ListSyntax, splitListText } from \"./lists.js\";\nimport { type ImportReportBuilder, type IssueLocation } from \"./report.js\";\nimport { parseTemporal, type TemporalValue, timeTextCompanion } from \"./temporal.js\";\n\n/**\n * What an importer knows about a declared attribute.\n * @public\n * @category Plugin helpers\n */\nexport interface AttributeDeclarationInput {\n /** The declaring format. */\n readonly format: DeclaringFormat;\n /** The attribute id (GEXF `id`, GraphML key `id`, Neo4j header name); null when the format has none. */\n readonly id: string | null;\n /** The GEXF `title` / GraphML `attr.name`; null when absent (yFiles keys omit it). */\n readonly title: string | null;\n /** The declared type text; null for an untyped declaration (stored as string). */\n readonly type: string | null;\n /** The declaring namespace (\"viz\", \"yfiles\", \"neo4j\"), or null. */\n readonly namespace?: string | null | undefined;\n /** The `<default>` text, or null. */\n readonly defaultText?: string | null | undefined;\n /** The GEXF `<options>` text, or null. */\n readonly optionsText?: string | null | undefined;\n /** The list syntax of defaults, options and values; \"gexf\" by default. */\n readonly listSyntax?: ListSyntax | undefined;\n /** A role to give the column, or null. */\n readonly role?: ColumnRole | null | undefined;\n /** Whether the attribute is dynamic (GEXF mode=\"dynamic\"). */\n readonly dynamic?: boolean | undefined;\n /** The importer's `long` option. */\n readonly long: \"f64\" | \"string\";\n /** Whether a column name is already taken in the target table; drives the `#id` rename. */\n readonly taken?: ((name: string) => boolean) | undefined;\n}\n\n/**\n * A non-fatal problem with a declaration, for the importer to record as a warning.\n * @public\n * @category Plugin helpers\n */\nexport interface DeclarationIssue {\n /** The issue category. */\n readonly category: IssueCategory;\n /** The stable code. */\n readonly code: string;\n /** A plain-ASCII message. */\n readonly message: string;\n}\n\n/**\n * A declared attribute: the ColumnDecl to push, the spec to parse values with, and what to report.\n * @public\n * @category Plugin helpers\n */\nexport interface DeclaredAttribute {\n /** The declaration for declareNodeColumn / declareEdgeColumn. */\n readonly decl: ColumnDecl;\n /** How values are parsed. */\n readonly spec: DeclaredTypeSpec;\n /** The list syntax values are split with. */\n readonly listSyntax: ListSyntax;\n /** The companion text column of a temporal attribute (design section 5.1), or null. */\n readonly companion: ColumnDecl | null;\n /** Whether the name received the `#id` suffix. */\n readonly renamed: boolean;\n /** Problems the importer records as warnings (unknown type, unparsable default or options). */\n readonly issues: readonly DeclarationIssue[];\n}\n\n/**\n * The declared type is not one the format defines; the column is kept as string.\n * @category Issue and loss codes\n */\nexport const UNKNOWN_TYPE_CODE = UNKNOWN_ATTR_TYPE_CODE;\n/**\n * The column was renamed `<name>#<id>` because the name was taken.\n * @category Issue and loss codes\n */\nexport const RENAMED_CODE = COLUMN_RENAMED_CODE;\n\nexport { BAD_DEFAULT_CODE, BAD_OPTIONS_CODE, PRECISION_CODE, ROLE_TAKEN_CODE } from \"./codes.js\";\n\n/**\n * Rows sampled before the dict heuristic decides (design section 5.4).\n * @category Plugin helpers\n */\nexport const DICT_SAMPLE_ROWS = 1024;\n\n/**\n * Build the column declaration of a declared attribute.\n * @param input - what the file declares\n * @returns the declaration, the value spec and any warnings to record\n * @category Plugin helpers\n */\nexport function declareAttribute(input: AttributeDeclarationInput): DeclaredAttribute {\n const issues: DeclarationIssue[] = [];\n const listSyntax = input.listSyntax ?? \"gexf\";\n let spec = declaredSpec(input, issues);\n const { name, renamed } = resolveName(input);\n if (renamed) {\n issues.push({\n category: \"coercion\",\n code: RENAMED_CODE,\n message: `attribute \"${input.title ?? input.id ?? \"\"}\" renamed to \"${name}\": the name was taken`,\n });\n }\n const decl: ColumnDecl = {\n name,\n dtype: spec.dtype,\n nullable: true,\n origin: {\n format: input.format,\n id: input.id,\n title: input.title !== null && input.title !== name ? input.title : null,\n type: input.type,\n namespace: input.namespace ?? null,\n },\n };\n if (spec.list) {\n decl.itemDtype = spec.itemDtype ?? \"string\";\n }\n if (input.role !== undefined && input.role !== null) {\n decl.role = input.role;\n }\n if (input.dynamic === true) {\n decl.dynamic = true;\n }\n const optionsText = input.optionsText ?? null;\n if (optionsText !== null) {\n spec = declareOptions(decl, spec, optionsText, listSyntax, issues);\n }\n const defaultText = input.defaultText ?? null;\n if (defaultText !== null) {\n try {\n decl.default = parseDeclaredValue(defaultText, spec, listSyntax);\n } catch (err) {\n issues.push({\n category: \"validation-error\",\n code: BAD_DEFAULT_CODE,\n message: `default \"${defaultText}\" of attribute \"${name}\" does not parse as ${spec.declared}: ${messageOf(err)}`,\n });\n }\n }\n const companion = spec.temporal !== null && !spec.list ? timeTextCompanion(name) : null;\n return { decl, spec, listSyntax, companion, renamed, issues };\n}\n\n/**\n * The value spec of a declared type: string for no type, string with UNKNOWN_TYPE_CODE for a type\n * the format does not define.\n * @param input - what the file declares\n * @param issues - receives the unknown-type warning\n * @returns the spec\n */\nfunction declaredSpec(input: AttributeDeclarationInput, issues: DeclarationIssue[]): DeclaredTypeSpec {\n if (input.type === null) {\n return stringSpec(null);\n }\n const mapped = mapDeclaredType(input.format, input.type, input.long);\n if (mapped !== null) {\n return mapped;\n }\n issues.push({\n category: \"unsupported\",\n code: UNKNOWN_TYPE_CODE,\n message: `${input.format} type \"${input.type}\" is not supported; values kept as text`,\n });\n return stringSpec(input.type);\n}\n\n/**\n * Put the parsed options of an attribute on its declaration; a plain string attribute whose\n * options are all strings becomes a dict column.\n * @param decl - the declaration to complete\n * @param spec - the value spec\n * @param optionsText - the options text\n * @param listSyntax - the list syntax the options are split with\n * @param issues - receives BAD_OPTIONS_CODE when the options do not parse\n * @returns the spec, with dtype dict when the column became a dict\n */\nfunction declareOptions(\n decl: ColumnDecl,\n spec: DeclaredTypeSpec,\n optionsText: string,\n listSyntax: ListSyntax,\n issues: DeclarationIssue[],\n): DeclaredTypeSpec {\n try {\n const options = splitListText(optionsText, listSyntax).map((item) => parseItem(item, spec));\n decl.options = options;\n if (spec.dtype === \"string\" && !spec.list && options.every((o) => typeof o === \"string\")) {\n decl.dtype = \"dict\";\n return { ...spec, dtype: \"dict\" };\n }\n } catch (err) {\n issues.push({\n category: \"validation-error\",\n code: BAD_OPTIONS_CODE,\n message: `options \"${optionsText}\" of attribute \"${decl.name}\" do not parse as ${spec.declared}: ${messageOf(err)}`,\n });\n }\n return spec;\n}\n\n/**\n * Parse a value text by a declaration: a scalar, or a list split by the syntax with each item\n * parsed by the item kind.\n * @param text - the value text\n * @param spec - the declared type\n * @param listSyntax - the list syntax\n * @returns the value to push (a boolean, a number, a string, a JSON value or an array)\n * @category Plugin helpers\n */\nexport function parseDeclaredValue(text: string, spec: DeclaredTypeSpec, listSyntax: ListSyntax): unknown {\n if (spec.list) {\n return splitListText(text, listSyntax).map((item) => parseItem(item, spec));\n }\n return parseItem(text, spec);\n}\n\n/**\n * Parse a temporal value text by a declaration, keeping the source text when its canonical form\n * differs (for the companion column).\n * @param text - the value text\n * @param spec - a scalar temporal spec\n * @returns the value and the text to keep, or null text\n * @category Plugin helpers\n */\nexport function parseDeclaredTemporal(text: string, spec: DeclaredTypeSpec): TemporalValue {\n if (spec.temporal === null || spec.list) {\n throw new GraphFormatError(\"E_COLUMN_TYPE\", `\"${spec.declared}\" is not a scalar temporal type`, {\n declared: spec.declared,\n });\n }\n return parseTemporal(text.trim(), spec.temporal);\n}\n\nconst INTEGER_TEXT = /^[+-]?\\d+$/;\n\n/**\n * Whether a long value's text lost precision when parsed to f64 (design section 5.1: a value with\n * |v| > 2^53 is stored as the nearest f64 and recorded as a `precision` issue). Decided from the\n * text, since the parsed number alone cannot tell 2^53 from 2^53 + 1.\n * @param spec - the declared type\n * @param text - the value text (trimmed or not)\n * @returns true when the importer should record a `precision` issue\n * @category Plugin helpers\n */\nexport function losesPrecision(spec: DeclaredTypeSpec, text: string): boolean {\n if (!spec.precision) {\n return false;\n }\n const trimmed = text.trim();\n if (!INTEGER_TEXT.test(trimmed)) {\n return false;\n }\n const n = Number(trimmed);\n return !Number.isFinite(n) || BigInt(trimmed) !== BigInt(n);\n}\n\n/**\n * Declare a column on the sink for one domain.\n * @param sink - the sink\n * @param domain - node or edge\n * @param decl - the declaration\n * @returns the column handle\n * @category Plugin helpers\n */\nexport function declareOn(sink: GraphSink, domain: \"node\" | \"edge\", decl: ColumnDecl): ColumnHandle {\n return domain === \"node\" ? sink.declareNodeColumn(decl) : sink.declareEdgeColumn(decl);\n}\n\n/**\n * The outcome of declareResolved(): the handle and the declaration as it was applied.\n * @public\n * @category Plugin helpers\n */\nexport interface ResolvedDeclaration {\n /** The column handle. */\n readonly handle: ColumnHandle;\n /** The declaration as applied (its name and role may differ from the request). */\n readonly decl: ColumnDecl;\n /** Whether the column was renamed `<name>#<id>` (W_COLUMN_RENAMED recorded). */\n readonly renamed: boolean;\n /** Whether the role was dropped because the table already holds it (W_ROLE_TAKEN recorded). */\n readonly roleDropped: boolean;\n}\n\n/**\n * The column naming rule in one place, so every importer agrees: declare a column on\n * the sink and, when the sink already holds the name with another shape (an earlier import, a\n * caller's column), rename it `<name>#<origin.id>` (a counter when the source has no id) and\n * record W_COLUMN_RENAMED (coercion); when the table already holds the role, declare without the role and record W_ROLE_TAKEN (coercion). The\n * same shape under the same name returns the existing handle, as the sink does.\n * @param sink - the sink\n * @param domain - node or edge\n * @param decl - the wanted declaration\n * @param report - the report the coercion issues are recorded in\n * @param where - the line and element, when known\n * @returns the handle and the declaration as applied\n * @category Plugin helpers\n */\nexport function declareResolved(\n sink: GraphSink,\n domain: \"node\" | \"edge\",\n decl: ColumnDecl,\n report: ImportReportBuilder,\n where?: IssueLocation,\n): ResolvedDeclaration {\n let current = decl;\n let renamed = false;\n let roleDropped = false;\n for (;;) {\n try {\n return { handle: declareOn(sink, domain, current), decl: current, renamed, roleDropped };\n } catch (err) {\n if (!(err instanceof GraphFormatError)) {\n throw err;\n }\n if (err.code === \"E_COLUMN_EXISTS\" && !renamed) {\n current = renameColumn(sink, domain, current, report, where);\n renamed = true;\n continue;\n }\n if (err.code === \"E_DUPLICATE_ROLE\" && current.role !== undefined && !roleDropped) {\n current = dropRole(err, domain, current, current.role, report, where);\n roleDropped = true;\n continue;\n }\n throw err;\n }\n }\n}\n\n/**\n * The declaration under a name the sink does not hold yet, recording W_COLUMN_RENAMED.\n * @param sink - the sink\n * @param domain - node or edge\n * @param decl - the declaration whose name clashed\n * @param report - the report\n * @param where - the line and element, when known\n * @returns the renamed declaration\n */\nfunction renameColumn(\n sink: GraphSink,\n domain: \"node\" | \"edge\",\n decl: ColumnDecl,\n report: ImportReportBuilder,\n where: IssueLocation | undefined,\n): ColumnDecl {\n const taken = takenIn(sink, domain);\n const id = decl.origin?.id ?? null;\n const name = uniqueColumnName(decl.name, id, taken);\n report.warning(\n \"coercion\",\n COLUMN_RENAMED_CODE,\n `${domain} column \"${decl.name}\" renamed to \"${name}\": the sink already holds that name with another shape`,\n { ...where, element: where?.element ?? decl.name },\n );\n return { ...decl, name };\n}\n\n/**\n * The declaration without the role another column holds, recording W_ROLE_TAKEN.\n * @param err - the sink's E_DUPLICATE_ROLE error\n * @param domain - node or edge\n * @param decl - the declaration whose role clashed\n * @param role - its role\n * @param report - the report\n * @param where - the line and element, when known\n * @returns the declaration without its role\n */\nfunction dropRole(\n err: GraphFormatError,\n domain: \"node\" | \"edge\",\n decl: ColumnDecl,\n role: ColumnRole,\n report: ImportReportBuilder,\n where: IssueLocation | undefined,\n): ColumnDecl {\n const holder = typeof err.details.holder === \"string\" ? err.details.holder : \"another column\";\n report.warning(\n \"coercion\",\n ROLE_TAKEN_CODE,\n `${domain} column \"${decl.name}\" loses the ${role} role: \"${holder}\" already holds it`,\n { ...where, element: where?.element ?? decl.name },\n );\n const { role: _role, ...withoutRole } = decl;\n return withoutRole;\n}\n\n/**\n * Declare the companion text column of a temporal column. A table holds at\n * most one column per role, so when another companion already carries `timeText` this one is\n * declared without the role (reported once per table); exporters find every companion through\n * `extra.for`.\n * @param sink - the sink\n * @param domain - node or edge\n * @param companion - the declaration from declareAttribute()\n * @param report - the report the role loss is recorded in; when omitted the loss is silent\n * @returns the column handle\n * @category Plugin helpers\n */\nexport function declareCompanion(\n sink: GraphSink,\n domain: \"node\" | \"edge\",\n companion: ColumnDecl,\n report?: ImportReportBuilder,\n): ColumnHandle {\n try {\n return declareOn(sink, domain, companion);\n } catch (err) {\n if (err instanceof GraphFormatError && err.code === \"E_DUPLICATE_ROLE\") {\n report?.warnOnce(\n \"coercion\",\n ROLE_TAKEN_CODE,\n `${domain} column \"${companion.name}\" is declared without the timeText role: another companion holds it (exporters use extra.for)`,\n { element: companion.name },\n );\n const { role: _role, ...withoutRole } = companion;\n return declareOn(sink, domain, withoutRole);\n }\n throw err;\n }\n}\n\n/**\n * Whether a column name is taken in a sink's table, the usual `taken` callback.\n * @param sink - the sink\n * @param domain - node or edge\n * @returns a predicate over column names\n * @category Plugin helpers\n */\nexport function takenIn(sink: GraphSink, domain: \"node\" | \"edge\"): (name: string) => boolean {\n return (name: string): boolean =>\n (domain === \"node\" ? sink.nodeColumn(name) : sink.edgeColumn(name)) !== INVALID_INDEX;\n}\n\n/**\n * The deterministic name of a declared attribute whose preferred name is taken (design section\n * 5.6): `<name>#<origin.id>`, and `<name>#<origin.id>#2`, `#3`... should that be taken as well.\n * @param name - the preferred name\n * @param id - the source id (the attribute id or key id); null falls back to a counter\n * @param taken - whether a name is already used in the table\n * @returns a free name\n * @category Plugin helpers\n */\nexport function uniqueColumnName(name: string, id: string | null, taken: (name: string) => boolean): string {\n if (!taken(name)) {\n return name;\n }\n const base = id === null ? name : `${name}#${id}`;\n if (id !== null && !taken(base)) {\n return base;\n }\n for (let n = 2; ; n++) {\n const candidate = `${base}#${n}`;\n if (!taken(candidate)) {\n return candidate;\n }\n }\n}\n\n/**\n * The dict heuristic of design section 5.4 for an untyped string column: observe values until the\n * sample is full; the column is a dict when the distinct count stays below half the rows, a string\n * otherwise. The importer buffers the sampled values and declares the column on the decision.\n * @category Plugin helpers\n */\nexport class DictHeuristic {\n private readonly distinct = new Set<string>();\n\n private rowsSeen = 0;\n\n private readonly sampleRows: number;\n\n /**\n * Create a heuristic.\n * @param sampleRows - rows observed before deciding; DICT_SAMPLE_ROWS by default\n */\n constructor(sampleRows: number = DICT_SAMPLE_ROWS) {\n this.sampleRows = sampleRows;\n }\n\n /**\n * Rows observed so far.\n * @returns the count\n */\n get rows(): number {\n return this.rowsSeen;\n }\n\n /**\n * Distinct values observed so far.\n * @returns the count\n */\n get distinctCount(): number {\n return this.distinct.size;\n }\n\n /**\n * Whether the sample is full.\n * @returns true once sampleRows values were observed\n */\n get decided(): boolean {\n return this.rowsSeen >= this.sampleRows;\n }\n\n /**\n * Observe one value.\n * @param value - the value text\n * @returns true when this observation completed the sample\n */\n observe(value: string): boolean {\n this.rowsSeen++;\n if (this.distinct.size < this.rowsSeen) {\n this.distinct.add(value);\n }\n return this.rowsSeen === this.sampleRows;\n }\n\n /**\n * The dtype the sample suggests: dict when the distinct count is below rows / 2 (and at least\n * one row was seen), string otherwise. Valid before the sample is full (end of input).\n * @returns \"dict\" or \"string\"\n */\n decide(): \"dict\" | \"string\" {\n return this.rowsSeen > 0 && this.distinct.size * 2 < this.rowsSeen ? \"dict\" : \"string\";\n }\n}\n\n/**\n * The resolved name of a declaration and whether it was renamed.\n * @param input - the declaration input\n * @returns the name and the rename flag; E_COLUMN_TYPE when neither a title nor an id exists\n */\nfunction resolveName(input: AttributeDeclarationInput): { name: string; renamed: boolean } {\n const preferred = input.title !== null && input.title.length > 0 ? input.title : input.id;\n if (preferred === null || preferred.length === 0) {\n throw new GraphFormatError(\"E_COLUMN_TYPE\", \"an attribute declaration needs a title or an id\", {\n field: \"name\",\n format: input.format,\n });\n }\n if (input.taken === undefined) {\n return { name: preferred, renamed: false };\n }\n const name = uniqueColumnName(preferred, input.id, input.taken);\n return { name, renamed: name !== preferred };\n}\n\n/**\n * Parse one scalar value or list item by a spec.\n * @param text - the item text\n * @param spec - the declared type\n * @returns the parsed value\n */\nfunction parseItem(text: string, spec: DeclaredTypeSpec): unknown {\n return parseScalarText(text, spec.kind, spec.temporal);\n}\n\n/**\n * The message of a caught value.\n * @param err - the thrown value\n * @returns the message\n */\nfunction messageOf(err: unknown): string {\n return err instanceof Error ? err.message : String(err);\n}\n","/**\n * Direction resolution through the sink (design sections 3.6 and 8.4, decision D-DIR): the\n * importer reads the file's header direction, calls `sink.setDirected()` once before the first\n * edge, then pushes every edge as it is read. Mixed files are handled per `onMixedDirection`:\n *\n * - \"expand\" (default): an undirected edge into a directed sink becomes two logical edges linked\n * by the `graphty.pair` column with `graphty.directed` = false on both halves; a directed edge\n * into an undirected sink triggers ONE `setDirected(true, { expand: true })`, after which the\n * builder has expanded everything pushed so far and the importer continues in directed mode.\n * - \"directed\" / \"undirected\": every edge is treated that way (the distinction is dropped and\n * reported once, with the count).\n * - \"error\": the first edge whose direction differs from the sink's aborts the import.\n *\n * A locked or non-empty sink wins over the file (design section 8.4 precedence): a refused\n * `setDirected` is recorded as a coercion issue and the importer continues with `sink.directed`,\n * expanding every edge that differs. A GEXF `mutual` edge expands like an undirected one with the\n * additional `graphty.mutual` role column set on its primary half.\n *\n * The reserved columns are declared with exactly the builder's own declarations so that a sink the\n * builder already expanded hands back the existing handles.\n */\n\nimport {\n type Column,\n type ColumnDecl,\n type ColumnHandle,\n GraphFormatError,\n type GraphSink,\n type GraphSnapshot,\n INVALID_INDEX,\n type NodeId,\n} from \"@graphty/graph-format\";\n\nimport { DIRECTION_FORCED_CODE, DIRECTION_REFUSED_CODE, MIXED_DIRECTION_CODE } from \"./codes.js\";\nimport { type ImportReportBuilder } from \"./report.js\";\n\n/**\n * The direction of one source edge.\n * @public\n * @category Plugin helpers\n */\nexport type EdgeKind = \"directed\" | \"undirected\" | \"mutual\";\n\n/**\n * Where an edge or header was read, for issues.\n * @public\n * @category Plugin helpers\n */\nexport interface EdgeLocation {\n /** The 1-based line, when known. */\n readonly line?: number | null | undefined;\n /** The edge id or another element name, when known. */\n readonly element?: string | null | undefined;\n}\n\n/**\n * The name of the bool edge column that, in a graph with both directed and undirected edges, says\n * which edges were directed in the file (true) and which were undirected (false).\n * @category Plugin helpers\n */\nexport const DIRECTED_COLUMN = \"graphty.directed\";\n\n/**\n * The name of the edge column that links the two edges an undirected edge is stored as, in a graph\n * with both directed and undirected edges: each holds the index of the other.\n * @category Plugin helpers\n */\nexport const PAIR_COLUMN = \"graphty.pair\";\n\n/**\n * The name of the bool edge column that marks a GEXF `mutual` edge.\n * @category Plugin helpers\n */\nexport const MUTUAL_COLUMN = \"graphty.mutual\";\n\nexport { DIRECTION_FORCED_CODE, DIRECTION_REFUSED_CODE, MIXED_DIRECTION_CODE } from \"./codes.js\";\n\nconst DIRECTED_DECL: ColumnDecl = { name: DIRECTED_COLUMN, dtype: \"bool\", role: \"directed\" };\nconst PAIR_DECL: ColumnDecl = { name: PAIR_COLUMN, dtype: \"u32\", role: \"pair\", refersTo: \"edge\" };\nconst MUTUAL_DECL: ColumnDecl = { name: MUTUAL_COLUMN, dtype: \"bool\", role: \"mutual\" };\n\n/**\n * Adds edges to the sink and handles files whose edges have different directions, the way\n * `onMixedDirection` asks. Make one per import call, call `setHeader()` once with the direction the\n * file declares, then `addEdge()` for each edge. In a directed graph an undirected edge is stored as\n * two edges, one each way, linked so an exporter writes them back as one.\n * @category Writing a format\n */\nexport class DirectionResolver {\n private readonly sink: GraphSink;\n\n private readonly report: ImportReportBuilder;\n\n private readonly policy: \"expand\" | \"directed\" | \"undirected\" | \"error\";\n\n private directedHandle: ColumnHandle = INVALID_INDEX as ColumnHandle;\n\n private pairHandle: ColumnHandle = INVALID_INDEX as ColumnHandle;\n\n private mutualHandle: ColumnHandle = INVALID_INDEX as ColumnHandle;\n\n /** The first edge index this resolver pushed, for the backfill of graphty.directed; -1 before the first. */\n private firstEdge = -1;\n\n /** The next edge index this resolver expects to receive (contiguity between compactions, I16). */\n private nextEdge = -1;\n\n private forcedCount = 0;\n\n private headerSet = false;\n\n private mirrorOfLast: number = INVALID_INDEX;\n\n /**\n * Create a resolver.\n * @param sink - the sink edges are pushed into\n * @param report - the report issues are recorded in\n * @param policy - the resolved onMixedDirection option\n */\n constructor(sink: GraphSink, report: ImportReportBuilder, policy: \"expand\" | \"directed\" | \"undirected\" | \"error\") {\n this.sink = sink;\n this.report = report;\n this.policy = policy;\n }\n\n /**\n * The sink's current direction.\n * @returns true when directed\n */\n get directed(): boolean {\n return this.sink.directed;\n }\n\n /**\n * Whether the graph holds undirected edges stored as two edges.\n * @returns true once the first such edge was added\n */\n get expanded(): boolean {\n return this.pairHandle !== INVALID_INDEX;\n }\n\n /**\n * Set the graph's direction before the first edge: the direction the file declares, or the\n * `defaultDirected` option for a file that declares none. Under `onMixedDirection` \"directed\" or\n * \"undirected\" that direction is used instead, with a warning when it differs. When the sink\n * cannot change direction (a caller's builder that already holds edges or was locked), the\n * sink's direction stands and a warning is recorded.\n * @param headerDirected - the direction the file declares (or the default)\n * @param where - the line of the header, when known\n */\n setHeader(headerDirected: boolean, where?: EdgeLocation): void {\n this.headerSet = true;\n let wanted = headerDirected;\n if (this.policy === \"directed\" || this.policy === \"undirected\") {\n wanted = this.policy === \"directed\";\n if (wanted !== headerDirected) {\n // once: this says it for every edge, so no edge repeats it\n this.report.warnOnce(\n \"coercion\",\n DIRECTION_FORCED_CODE,\n `the file declares ${direction(headerDirected)} edges; read as ${direction(wanted)} per onMixedDirection`,\n { line: where?.line ?? null },\n `${DIRECTION_FORCED_CODE}:${direction(headerDirected)}`,\n );\n }\n }\n const { sink } = this;\n if (sink.directed === wanted) {\n this.adoptExisting();\n return;\n }\n try {\n if (wanted && sink.edgeCount > 0 && !sink.directedLocked) {\n const before = sink.edgeCount;\n sink.setDirected(true, { expand: true });\n this.adoptExpansionColumns();\n this.report.counts.expandedMixed += before;\n } else {\n sink.setDirected(wanted);\n }\n } catch (err) {\n if (!(err instanceof GraphFormatError) || err.code !== \"E_DIRECTED\") {\n throw err;\n }\n this.report.warning(\n \"coercion\",\n DIRECTION_REFUSED_CODE,\n `the file is ${direction(wanted)} but the sink is ${direction(sink.directed)} (${reasonOf(err)}); read as ${direction(sink.directed)}`,\n { line: where?.line ?? null },\n );\n }\n this.adoptExisting();\n }\n\n /**\n * Pick up reserved columns a caller's sink already holds (an earlier expansion), so every edge\n * pushed from now on gets its graphty.directed value.\n */\n private adoptExisting(): void {\n if (this.pairHandle === INVALID_INDEX && this.sink.edgeColumn(PAIR_COLUMN) !== INVALID_INDEX) {\n this.adoptExpansionColumns();\n }\n }\n\n /**\n * The second edge of the edge the last addEdge() call added, when that edge was stored as two;\n * otherwise INVALID_INDEX (4294967295). An edge attribute or weight you set after addEdge()\n * belongs on both: set it on the index addEdge() returned and, when this is not INVALID_INDEX,\n * on this index too.\n * @returns the second edge's index, or INVALID_INDEX\n */\n get lastMirror(): number {\n return this.mirrorOfLast;\n }\n\n /**\n * Add one edge. An edge with the graph's direction is added as it is; one with the other\n * direction is stored as two edges, given the graph's direction, or refused, as\n * `onMixedDirection` says. When it is stored as two, the return value is the first and\n * `lastMirror` the second.\n * @param source - the source id\n * @param target - the target id\n * @param kind - the edge's direction in the file\n * @param weight - the weight, or undefined when the file gives none\n * @param where - the line and element, for issues\n * @returns the index of the edge added (the first one, when it was stored as two)\n */\n addEdge(source: NodeId, target: NodeId, kind: EdgeKind, weight?: number, where?: EdgeLocation): number {\n if (!this.headerSet) {\n throw new GraphFormatError(\"E_DIRECTED\", \"DirectionResolver.setHeader() must run before the first edge\", {\n reason: \"header not set\",\n });\n }\n const { sink } = this;\n this.mirrorOfLast = INVALID_INDEX;\n const edgeDirected = kind !== \"undirected\";\n if (edgeDirected === sink.directed && kind !== \"mutual\") {\n const e = sink.addEdge(source, target, weight);\n this.track(e);\n if (this.directedHandle !== INVALID_INDEX) {\n sink.setEdgeValue(this.directedHandle, e, edgeDirected);\n }\n return e;\n }\n switch (this.policy) {\n case \"directed\":\n case \"undirected\": {\n // the sink's direction is the policy's (or a locked sink's); the edge is pushed as the sink's kind\n this.forcedCount++;\n this.report.warnOnce(\n \"coercion\",\n DIRECTION_FORCED_CODE,\n `${kind} edges read as ${direction(sink.directed)} per onMixedDirection`,\n where,\n `${DIRECTION_FORCED_CODE}:${kind}`,\n );\n const e = sink.addEdge(source, target, weight);\n this.track(e);\n if (this.directedHandle !== INVALID_INDEX) {\n sink.setEdgeValue(this.directedHandle, e, sink.directed);\n }\n return e;\n }\n case \"error\":\n this.report.error(\n \"validation-error\",\n MIXED_DIRECTION_CODE,\n `${kind} edge in a ${direction(sink.directed)} graph (onMixedDirection: \"error\")`,\n where,\n );\n throw this.report.abort(\"mixed direction refused\", { code: MIXED_DIRECTION_CODE });\n case \"expand\":\n return this.expand(source, target, kind, weight, where);\n default: {\n const name: string = this.policy;\n throw new GraphFormatError(\"E_UNSUPPORTED\", `unknown onMixedDirection ${name}`, {\n option: \"onMixedDirection\",\n found: name,\n });\n }\n }\n }\n\n /**\n * How many edges were given a direction other than their own, under `onMixedDirection`\n * \"directed\" or \"undirected\".\n * @returns the count\n */\n get forced(): number {\n return this.forcedCount;\n }\n\n /**\n * Expand one edge that differs from the sink's direction.\n * @param source - the source id\n * @param target - the target id\n * @param kind - the edge's direction in the file\n * @param weight - the weight, or undefined\n * @param where - the line and element, for issues\n * @returns the primary edge index\n */\n private expand(\n source: NodeId,\n target: NodeId,\n kind: EdgeKind,\n weight: number | undefined,\n where: EdgeLocation | undefined,\n ): number {\n const { sink } = this;\n if (!sink.directed) {\n // a directed (or mutual) edge into an undirected sink: expand the sink once\n try {\n const before = sink.edgeCount;\n sink.setDirected(true, { expand: true });\n this.adoptExpansionColumns();\n this.report.counts.expandedMixed += before;\n } catch (err) {\n if (!(err instanceof GraphFormatError) || err.code !== \"E_DIRECTED\") {\n throw err;\n }\n this.report.error(\n \"coercion\",\n DIRECTION_REFUSED_CODE,\n `${direction(true)} edge in a locked ${direction(false)} sink cannot be expanded`,\n where,\n );\n throw this.report.abort(\"the sink refused the expansion to directed\", {\n code: DIRECTION_REFUSED_CODE,\n reason: err.details.reason,\n });\n }\n if (kind === \"directed\") {\n const e = sink.addEdge(source, target, weight);\n this.track(e);\n sink.setEdgeValue(this.directedHandle, e, true);\n return e;\n }\n }\n this.ensureExpansionColumns();\n const first = sink.addEdge(source, target, weight);\n this.track(first);\n const mutual = kind === \"mutual\";\n sink.setEdgeValue(this.directedHandle, first, mutual);\n this.report.counts.expandedMixed++;\n if (mutual) {\n this.ensureMutualColumn();\n sink.setEdgeValue(this.mutualHandle, first, true);\n }\n const u = sink.indexOf(source);\n const v = sink.indexOf(target);\n if (u === v) {\n // an undirected self-loop is one arc (I7); the builder does not mirror it either\n return first;\n }\n const mirror = sink.addEdge(target, source, weight); // NOSONAR(S2234): the mirror arc runs the other way on purpose\n this.track(mirror);\n this.mirrorOfLast = mirror;\n sink.setEdgeValue(this.directedHandle, mirror, mutual);\n sink.setEdgeValue(this.pairHandle, first, mirror);\n sink.setEdgeValue(this.pairHandle, mirror, first);\n return first;\n }\n\n /**\n * Note an edge index this resolver pushed, for the backfill of graphty.directed.\n * @param e - the edge index\n */\n private track(e: number): void {\n if (this.firstEdge < 0) {\n this.firstEdge = e;\n }\n this.nextEdge = e + 1;\n }\n\n /**\n * Pick up the reserved columns the builder wrote during its own expansion.\n */\n private adoptExpansionColumns(): void {\n this.directedHandle = this.sink.declareEdgeColumn(DIRECTED_DECL);\n this.pairHandle = this.sink.declareEdgeColumn(PAIR_DECL);\n }\n\n /**\n * Declare the reserved columns on first use in a directed sink and backfill graphty.directed\n * = true for every edge this resolver pushed so far (they were directed in the source).\n */\n private ensureExpansionColumns(): void {\n if (this.pairHandle !== INVALID_INDEX) {\n return;\n }\n this.directedHandle = this.sink.declareEdgeColumn(DIRECTED_DECL);\n this.pairHandle = this.sink.declareEdgeColumn(PAIR_DECL);\n if (this.firstEdge >= 0) {\n for (let e = this.firstEdge; e < this.nextEdge; e++) {\n this.sink.setEdgeValue(this.directedHandle, e, true);\n }\n }\n }\n\n /** Declare graphty.mutual on first use. */\n private ensureMutualColumn(): void {\n if (this.mutualHandle === INVALID_INDEX) {\n this.mutualHandle = this.sink.declareEdgeColumn(MUTUAL_DECL);\n }\n }\n}\n\n/**\n * The reason of a refused setDirected(), for messages.\n * @param err - the E_DIRECTED error\n * @returns details.reason when it is a string, \"refused\" otherwise\n */\nfunction reasonOf(err: GraphFormatError): string {\n const { reason } = err.details;\n return typeof reason === \"string\" ? reason : \"refused\";\n}\n\n/**\n * The word for a direction, for messages.\n * @param directed - the direction\n * @returns \"directed\" or \"undirected\"\n */\nfunction direction(directed: boolean): string {\n return directed ? \"directed\" : \"undirected\";\n}\n\n// ============================================================ the exporter side\n\n/**\n * What an exporter needs to know about edge direction, from `pairFolding(snapshot)`. In a graph\n * with both directed and undirected edges, each undirected edge is stored as two edges, one each\n * way. `folded(e)` tells you which of the two to skip, so the edge is written once, and\n * `sourceDirected(e)` whether an edge was directed. A GEXF `mutual` edge is also stored as two\n * edges; it is written as two directed edges unless you pass `foldMutual: true`.\n * @public\n * @category Plugin helpers\n */\nexport interface PairFolding {\n /** Whether the graph holds any edge stored as two edges. When false, every method answers as for a plain edge. */\n readonly expanded: boolean;\n /** How many GEXF mutual edges the graph holds, each counted once. */\n readonly mutualCount: number;\n /**\n * Whether to skip an edge: true for the second of the two edges an undirected edge (or, with\n * `foldMutual`, a mutual edge) is stored as. Write the first and skip this one.\n * @param e - the edge index\n * @returns true when the edge must be skipped\n */\n folded(e: number): boolean;\n /**\n * The other of the two edges an undirected or mutual edge is stored as.\n * @param e - the edge index\n * @returns the other edge's index, or INVALID_INDEX (4294967295) for an edge stored once\n */\n mateOf(e: number): number;\n /**\n * Whether an edge was directed in the file it was read from: false for an undirected edge of a\n * graph with both kinds. It is true for every edge of a graph without mixed direction, an\n * undirected graph included, so the direction to write for edge `e` is\n * `snapshot.directed && sourceDirected(e)`.\n * @param e - the edge index\n * @returns whether the edge is directed\n */\n sourceDirected(e: number): boolean;\n /**\n * Whether an edge is either of the two edges a GEXF `mutual` edge is stored as.\n * @param e - the edge index\n * @returns true for a mutual edge\n */\n isMutual(e: number): boolean;\n}\n\n/**\n * The per-format choice of pairFolding().\n * @category Plugin helpers\n */\nexport interface PairFoldingOptions {\n /**\n * Write a GEXF mutual edge once, for a format that can say an edge goes both ways. When false\n * (the default), `folded()` keeps both of its edges, so it is written as two directed edges.\n */\n readonly foldMutual?: boolean | undefined;\n}\n\n/**\n * Read how a snapshot stores edge direction, for an exporter: which edges to skip so each\n * undirected edge is written once, and which edges were directed.\n * @param snapshot - the graph to write\n * @param options - whether a GEXF mutual edge is written once\n * @returns the answers, per edge\n * @category Writing a format\n */\nexport function pairFolding(snapshot: GraphSnapshot, options: PairFoldingOptions = {}): PairFolding {\n const foldMutual = options.foldMutual ?? false;\n const directedColumn = roleColumn(snapshot.edges.byRole(\"directed\"), \"bool\");\n const pairColumn = roleColumn(snapshot.edges.byRole(\"pair\"), \"u32\");\n const mutualColumn = roleColumn(snapshot.edges.byRole(\"mutual\"), \"bool\");\n const { edgeCount } = snapshot;\n const mateOf = (e: number): number => {\n if (!pairColumn?.isSet(e)) {\n return INVALID_INDEX;\n }\n const mate = pairColumn.value(e);\n return typeof mate === \"number\" && mate !== INVALID_INDEX ? mate : INVALID_INDEX;\n };\n const sourceDirected = (e: number): boolean =>\n directedColumn === null || !directedColumn.isSet(e) || directedColumn.value(e) === true;\n const isMutual = (e: number): boolean => {\n if (mutualColumn === null) {\n return false;\n }\n if (mutualColumn.isSet(e) && mutualColumn.value(e) === true) {\n return true;\n }\n const mate = mateOf(e);\n return mate !== INVALID_INDEX && mutualColumn.isSet(mate) && mutualColumn.value(mate) === true;\n };\n const folded = (e: number): boolean => {\n const mate = mateOf(e);\n if (mate === INVALID_INDEX || mate >= e) {\n return false;\n }\n // an undirected pair always folds; a mutual pair (directed on both halves) folds on request\n return !sourceDirected(e) || (foldMutual && isMutual(e));\n };\n let mutualCount = 0;\n if (mutualColumn !== null) {\n for (let e = 0; e < edgeCount; e++) {\n if (mutualColumn.isSet(e) && mutualColumn.value(e) === true && mateOf(e) > e) {\n mutualCount++;\n }\n }\n }\n return { expanded: pairColumn !== null, mutualCount, folded, mateOf, sourceDirected, isMutual };\n}\n\n/**\n * A role column when it has the dtype the role requires, else null.\n * @param column - the column, or null\n * @param dtype - the required dtype\n * @returns the column or null\n */\nfunction roleColumn(column: Column | null, dtype: \"bool\" | \"u32\"): Column | null {\n return column !== null && column.dtype === dtype ? column : null;\n}\n","/**\n * Id coercion (design section 4.1): the importer-side rule that turns a text cell or a JSON value\n * into a NodeId before it reaches the sink. The core never coerces.\n *\n * - \"keep\": typed values pass through; anything that is not a string or a number is E_INVALID_ID.\n * - \"canonical\": text becomes a number iff it is canonical integer text (`/^-?(0|[1-9][0-9]*)$/`\n * and a safe integer, excluding \"-0\" which would collide with \"0\"); every other text stays a\n * string. Injective on text, so `String(id)` on export reproduces the cell exactly: \"01\", \"1.0\"\n * and \"+1\" stay strings, \"1\" becomes 1. Typed values pass through as under \"keep\".\n * - \"string\": `String(v)` for strings, numbers, booleans, bigints and null; anything else is\n * E_INVALID_ID.\n * - \"number\": `Number(text)` for text (empty or whitespace-only text, NaN and non-finite results\n * are E_INVALID_ID); numbers pass through; anything else is E_INVALID_ID. This rule can merge\n * distinct cells (\"01\" and \"1\"); IdCoercer counts such merges so the importer can report them as\n * coercion issues.\n */\n\nimport { GraphFormatError, type IdCoercion, type NodeId } from \"@graphty/graph-format\";\n\nconst CANONICAL_INTEGER = /^-?(0|[1-9]\\d*)$/;\n\nexport { ID_MERGED_CODE } from \"./codes.js\";\n\n/**\n * The \"canonical\" rule on one text cell.\n * @param text - the cell text, exactly as read\n * @returns the number for canonical safe-integer text (never for \"-0\"), the text itself otherwise\n * @category Plugin helpers\n */\nexport function canonicalId(text: string): NodeId {\n if (text !== \"-0\" && CANONICAL_INTEGER.test(text)) {\n const n = Number(text);\n if (Number.isSafeInteger(n)) {\n return n;\n }\n }\n return text;\n}\n\n/**\n * Whether a text cell is canonical integer text under the \"canonical\" rule (a number after import).\n * @param text - the cell text\n * @returns true when canonicalId(text) returns a number\n * @category Plugin helpers\n */\nexport function isCanonicalIntegerText(text: string): boolean {\n return typeof canonicalId(text) === \"number\";\n}\n\n/**\n * Coerce a text cell under a rule.\n * @param text - the cell text, exactly as read\n * @param mode - the coercion rule\n * @returns the id; E_INVALID_ID when the rule rejects the text\n * @category Plugin helpers\n */\nexport function coerceIdText(text: string, mode: IdCoercion): NodeId {\n switch (mode) {\n case \"keep\":\n case \"string\":\n return text;\n case \"canonical\":\n return canonicalId(text);\n case \"number\": {\n if (text.trim().length === 0) {\n throw invalidId(text, \"empty text is not a number\");\n }\n const n = Number(text);\n if (!Number.isFinite(n)) {\n throw invalidId(text, \"not a finite number\");\n }\n return n;\n }\n default: {\n const name: string = mode;\n throw new GraphFormatError(\"E_UNSUPPORTED\", `unknown id coercion ${name}`, { option: \"ids\", found: name });\n }\n }\n}\n\n/**\n * Coerce a typed value (a JSON scalar, a record field) under a rule.\n * @param value - the value\n * @param mode - the coercion rule\n * @returns the id; E_INVALID_ID when the rule rejects the value\n * @category Plugin helpers\n */\nexport function coerceId(value: unknown, mode: IdCoercion): NodeId {\n if (typeof value === \"string\") {\n return coerceIdText(value, mode);\n }\n if (typeof value === \"number\") {\n if (!Number.isFinite(value)) {\n throw invalidId(value, \"not a finite number\");\n }\n return mode === \"string\" ? String(value) : value;\n }\n if (mode === \"string\" && (typeof value === \"boolean\" || typeof value === \"bigint\" || value === null)) {\n return String(value);\n }\n throw invalidId(value, `a ${value === null ? \"null\" : typeof value} is not an id under ids: \"${mode}\"`);\n}\n\n/**\n * The E_INVALID_ID error of a rejected value.\n * @param value - the rejected value\n * @param reason - why\n * @returns the error\n */\nfunction invalidId(value: unknown, reason: string): GraphFormatError {\n const shown = typeof value === \"string\" || typeof value === \"number\" ? value : typeof value;\n return new GraphFormatError(\"E_INVALID_ID\", `invalid node id ${JSON.stringify(shown)}: ${reason}`, {\n reason,\n value: typeof value === \"bigint\" ? value.toString() : value,\n });\n}\n\n/**\n * A stateful coercer for one import call: applies the rule and, under \"number\", detects merges\n * (two distinct texts mapping to one number) so the importer can report them as coercion issues.\n * @category Writing a format\n */\nexport class IdCoercer {\n /** The rule. */\n readonly mode: IdCoercion;\n\n /** Texts merged into an id another text already produced. */\n mergeCount = 0;\n\n /** The text that first produced each numeric id, kept only under \"number\". */\n private readonly firstText: Map<number, string> | null;\n\n /** The merge detected by the most recent text() call, or null. */\n lastMerge: {\n /** The number both texts became. */\n readonly id: number;\n /** The text just read. */\n readonly text: string;\n /** The first text that became the same number. */\n readonly previousText: string;\n } | null = null;\n\n /**\n * Create a coercer.\n * @param mode - the rule\n */\n constructor(mode: IdCoercion) {\n this.mode = mode;\n this.firstText = mode === \"number\" ? new Map() : null;\n }\n\n /**\n * Coerce a text cell, recording a merge under \"number\" when a different text already produced\n * the same number.\n * @param text - the cell text\n * @returns the id\n */\n text(text: string): NodeId {\n const id = coerceIdText(text, this.mode);\n this.lastMerge = null;\n if (this.firstText !== null && typeof id === \"number\") {\n const previous = this.firstText.get(id);\n if (previous === undefined) {\n this.firstText.set(id, text);\n } else if (previous !== text) {\n this.mergeCount++;\n this.lastMerge = { id, text, previousText: previous };\n }\n }\n return id;\n }\n\n /**\n * Coerce a typed value.\n * @param value - the value\n * @returns the id\n */\n value(value: unknown): NodeId {\n if (typeof value === \"string\") {\n return this.text(value);\n }\n this.lastMerge = null;\n return coerceId(value, this.mode);\n }\n}\n","/**\n * Input handling shared by every importer (design section 8.4): the ImportInput union (whole\n * text, whole bytes, a byte stream, an async iterable of text or byte chunks) read as a sequence of\n * text chunks, as lines, or as one string, with BOM handling, cancellation through an AbortSignal\n * and byte progress.\n *\n * Bytes are decoded ONCE, here, for every importer. The encoding is, in order of precedence: a\n * byte order mark (UTF-8, UTF-16LE, UTF-16BE; a UTF-32 one is E_INVALID_ENCODING); the caller's\n * `encoding` option; the encoding the file declares (the importer's `declaredEncoding` reader: the\n * XML prolog for GEXF and GraphML, the `charset` attribute for DOT); else UTF-8. Whenever two of\n * them disagree the one that applies is named in a W_ENCODING_CONFLICT warning. BOM-less UTF-16\n * (every other byte 0) is E_INVALID_ENCODING asking for the option, and a known non-graph file (an\n * HTML page, a PDF, gzip or zip data, a PNG) is E_FOREIGN_FORMAT. Decoding is strict (`fatal: true`): an invalid sequence\n * is never a silent U+FFFD that could alias two ids. Only in the last case, when bytes that are not\n * valid UTF-8 appear while everything before them was ASCII, is the rest of the input read as\n * windows-1252 (the superset of ISO 8859-1 that Excel, Pajek and older tools write), with the\n * warning W_ENCODING_FALLBACK; invalid UTF-8 after valid non-ASCII UTF-8, in data holding control\n * bytes (binary data), or cut at the end of the input is E_INVALID_UTF8.\n *\n * The decoded text, whatever the input shape, is then checked once: leading U+FEFFs are stripped, a\n * trailing Ctrl-Z (the DOS end-of-file marker) is dropped, the first control character or stray\n * U+FEFF is reported W_CONTROL_CHARACTER, and a text that is empty or only whitespace is the fatal\n * E_EMPTY_INPUT.\n */\n\nimport { GraphFormatError } from \"@graphty/graph-format\";\n\nimport { type ImportInput } from \"../types.js\";\nimport {\n CONTROL_CHARACTER_CODE,\n EMPTY_INPUT_CODE,\n ENCODING_CONFLICT_CODE,\n ENCODING_FALLBACK_CODE,\n FOREIGN_FORMAT_CODE,\n INVALID_ENCODING_CODE,\n INVALID_UTF8_CODE,\n OPTION_IGNORED_CODE,\n TOO_LARGE_CODE,\n UNKNOWN_ENCODING_CODE,\n} from \"./codes.js\";\nimport { type ImportReportBuilder } from \"./report.js\";\n\nexport { INVALID_UTF8_CODE } from \"./codes.js\";\n\n/**\n * Cancellation and progress hooks of the reader; the resolved importer options satisfy this shape.\n * @public\n * @category Plugin helpers\n */\nexport interface ReadOptions {\n /** The cancellation signal, or null / undefined for none. */\n readonly signal?: AbortSignal | null | undefined;\n /** The progress callback, or null / undefined for none. */\n readonly onProgress?: ((bytesDone: number, bytesTotal?: number) => void) | null | undefined;\n /** The caller's `encoding` option (a label TextDecoder knows), or null / undefined for detection. */\n readonly encoding?: string | null | undefined;\n /**\n * The format's reader of a declared encoding: given the head of the input decoded as\n * windows-1252 (ASCII-compatible), the encoding label it declares, or null.\n */\n readonly declaredEncoding?: ((head: string) => string | null) | undefined;\n /** How many leading bytes the declaration reader sees (default 1024). */\n readonly declarationBytes?: number | undefined;\n /**\n * Whether BOM-less UTF-16 that the NUL pattern of its head shows is read in that encoding (JSON:\n * RFC 8259 section 8.1, RFC 4627 section 3) instead of failing with E_INVALID_ENCODING.\n */\n readonly bomlessUtf16?: boolean | undefined;\n /** Whether an input with no text but whitespace is valid (else E_EMPTY_INPUT). */\n readonly allowEmpty?: boolean | undefined;\n /**\n * Whether the format is XML: an (X)HTML document is then left to the format's own root-element\n * check (an XHTML page may embed the format's elements) instead of being E_FOREIGN_FORMAT.\n */\n readonly xml?: boolean | undefined;\n /**\n * Whether a NUL byte in undeclared input fails the import as binary data (or BOM-less UTF-16)\n * even where the bytes are valid UTF-8: for formats whose grammar never reports a NUL itself\n * (CSV). False by default, so a format's own syntax error names it.\n */\n readonly nulIsBinary?: boolean | undefined;\n}\n\n/** How many leading bytes the declaration check sees (an XML prolog, a DOT `charset` near the top). */\nconst HEAD_BYTES = 1024;\n\n/** How many leading bytes the BOM check needs (a UTF-32 mark is four). */\nconst BOM_BYTES = 4;\n\n/**\n * The canonical name of an encoding label, or null when the platform's TextDecoder does not know it.\n * @param label - a WHATWG encoding label (\"latin1\", \"UTF-16LE\", \"cp1252\", ...)\n * @returns the canonical name (\"windows-1252\", \"utf-16le\", ...) or null\n * @category Plugin helpers\n */\nexport function canonicalEncoding(label: string): string | null {\n try {\n return new TextDecoder(label.trim()).encoding;\n } catch {\n return null;\n }\n}\n\n/**\n * The encoding a byte order mark announces. The UTF-32 marks are checked first: FF FE 00 00 is the\n * UTF-32LE mark, not a UTF-16LE one.\n * @param head - the first bytes\n * @returns \"utf-8\", \"utf-16le\", \"utf-16be\", \"utf-32le\", \"utf-32be\" or null\n */\nfunction bomEncoding(head: Uint8Array): string | null {\n if (startsWithBytes(head, [0xff, 0xfe, 0x00, 0x00])) {\n return \"utf-32le\";\n }\n if (startsWithBytes(head, [0x00, 0x00, 0xfe, 0xff])) {\n return \"utf-32be\";\n }\n if (startsWithBytes(head, [0xef, 0xbb, 0xbf])) {\n return \"utf-8\";\n }\n if (startsWithBytes(head, [0xff, 0xfe])) {\n return \"utf-16le\";\n }\n if (startsWithBytes(head, [0xfe, 0xff])) {\n return \"utf-16be\";\n }\n return null;\n}\n\n/**\n * Whether bytes start with a signature.\n * @param bytes - the bytes\n * @param signature - the leading bytes to look for\n * @returns true when every signature byte matches\n */\nfunction startsWithBytes(bytes: Uint8Array, signature: readonly number[]): boolean {\n return bytes.byteLength >= signature.length && signature.every((b, i) => bytes[i] === b);\n}\n\n/**\n * The UTF-16 byte order of a head without a BOM whose every other byte is 0 (ASCII text in UTF-16),\n * or null. At least 90% of the first 512 code units must follow the pattern.\n * @param head - the first bytes\n * @returns \"utf-16le\", \"utf-16be\" or null\n */\nfunction bomlessUtf16(head: Uint8Array): string | null {\n const pairs = Math.min(head.byteLength >> 1, 512);\n if (pairs < 2) {\n return null;\n }\n let le = 0;\n let be = 0;\n for (let i = 0; i < pairs; i++) {\n const even = head[2 * i];\n const odd = head[2 * i + 1];\n if (even !== 0 && odd === 0) {\n le++;\n } else if (even === 0 && odd !== 0) {\n be++;\n }\n }\n if (le >= pairs * 0.9) {\n return \"utf-16le\";\n }\n return be >= pairs * 0.9 ? \"utf-16be\" : null;\n}\n\n/**\n * The UTF-16 byte order of BOM-less UTF-16 input that starts with an XML declaration (XML 1.0\n * Appendix F: `<?` as 3C 00 3F 00 or 00 3C 00 3F).\n * @param head - the first bytes\n * @returns \"utf-16le\", \"utf-16be\" or null\n */\nfunction xmlDeclarationUtf16(head: Uint8Array): string | null {\n if (startsWithBytes(head, [0x3c, 0x00, 0x3f, 0x00])) {\n return \"utf-16le\";\n }\n return startsWithBytes(head, [0x00, 0x3c, 0x00, 0x3f]) ? \"utf-16be\" : null;\n}\n\n/**\n * What a head is when it is a known file type that is no graph format: compressed or archived data,\n * an image, a PDF, an HTML page. Graph formats are text (or, for a Cytoscape session, a zip the\n * registry hands to its own importer), so such an input is never read as text.\n * @param head - the first bytes or characters of the input\n * @returns a description such as \"gzip-compressed data (decompress it first)\", or null\n * @category Plugin helpers\n */\nexport function foreignKind(head: Uint8Array | string): string | null {\n if (typeof head !== \"string\") {\n if (startsWithBytes(head, [0x1f, 0x8b])) {\n return \"gzip-compressed data (decompress it first)\";\n }\n if (startsWithBytes(head, [0x50, 0x4b, 0x03, 0x04]) || startsWithBytes(head, [0x50, 0x4b, 0x05, 0x06])) {\n return \"a zip archive (a Cytoscape session (.cys) is read by the cys importer; extract any other graph file from it first)\";\n }\n if (startsWithBytes(head, [0x89, 0x50, 0x4e, 0x47])) {\n return \"a PNG image\";\n }\n }\n const text = typeof head === \"string\" ? head.slice(0, 64) : String.fromCodePoint(...head.subarray(0, 64));\n const utf8Bom = String.fromCodePoint(0xef, 0xbb, 0xbf);\n let body = text.startsWith(utf8Bom) ? text.slice(3) : text;\n body = body.startsWith(BOM) ? body.slice(1) : body;\n if (body.startsWith(\"%PDF-\")) {\n return \"a PDF document\";\n }\n if (/^\\s*(<!doctype\\s+html[\\s>]|<html[\\s>])/i.test(body)) {\n return \"an HTML document (likely an error page saved in place of the file)\";\n }\n return null;\n}\n\n/**\n * Fail the import with E_FOREIGN_FORMAT when its head is a known non-graph file; an (X)HTML page\n * is left to an XML format's own root-element check.\n * @param head - the first bytes or the first text\n * @param report - the report\n * @param options - whether the format is XML\n */\nfunction refuseForeign(head: Uint8Array | string, report: ImportReportBuilder, options: ReadOptions): void {\n const foreign = foreignKind(head);\n if (foreign !== null && !(options.xml === true && foreign.startsWith(\"an HTML\"))) {\n report.fail(FOREIGN_FORMAT_CODE, `the input is ${foreign}, not ${report.format} text`);\n }\n}\n\n/**\n * Whether two encodings name the same family for a declaration check: equal, or both UTF-16 (a\n * prolog's \"UTF-16\" says nothing about the byte order the BOM gives).\n * @param a - a canonical encoding name\n * @param b - another\n * @returns true when they agree\n */\nfunction sameFamily(a: string, b: string): boolean {\n return a === b || (a.startsWith(\"utf-16\") && b.startsWith(\"utf-16\"));\n}\n\n/**\n * The one byte decoder of an import: picks the encoding from the head (option, BOM, declaration,\n * UTF-8) and decodes strictly, switching to windows-1252 with a warning when undeclared input\n * turns out not to be UTF-8 while everything decoded so far was ASCII.\n */\nclass ByteDecoder {\n private decoder: TextDecoder | null = null;\n\n private encoding = \"utf-8\";\n\n /** Whether a failed UTF-8 decode may switch to windows-1252 (nothing chose UTF-8 explicitly). */\n private mayFallBack = false;\n\n /** Whether every character decoded so far was ASCII (so switching encodings changes no earlier text). */\n private asciiSoFar = true;\n\n /** While asciiSoFar: the bytes the UTF-8 decoder holds back (a sequence split across chunks). */\n private carry: Uint8Array = new Uint8Array(0);\n\n /** Bytes decoded so far, for error positions. */\n private offset = 0;\n\n /** Whether the decoder switched to windows-1252 because undeclared input was not UTF-8. */\n private fellBack = false;\n\n /**\n * The first control byte (other than TAB, LF, FF, CR and a final Ctrl-Z) of undeclared input\n * that may still turn out not to be UTF-8: its offset and value, or null. Tracked from the\n * start of the input, so the binary-data verdict never depends on how the input was chunked.\n */\n private control: { readonly at: number; readonly byte: number } | null = null;\n\n /** The offset of a Ctrl-Z that ended the previous chunk: control data if more bytes follow. */\n private subAt = -1;\n\n /** Set while flushing because a text chunk follows: a sequence cut there is not windows-1252. */\n private textFollows = false;\n\n /** Whether the file declares UTF-8 (read like an undeclared file, but the fallback warning says so). */\n private declaredUtf8 = false;\n\n /** After the windows-1252 fallback: whether later bytes holding valid UTF-8 are still to be reported (once). */\n private mixedPending = false;\n\n /**\n * Create the decoder of one import.\n * @param report - where warnings and the fatal decode error go\n * @param options - the encoding option and the format's declaration reader\n */\n constructor(\n private readonly report: ImportReportBuilder,\n private readonly options: ReadOptions,\n ) {}\n\n /**\n * Whether start() ran.\n * @returns true once the encoding is chosen\n */\n get started(): boolean {\n return this.decoder !== null;\n }\n\n /**\n * Choose the encoding from the first bytes of the input: a BOM, else the option, else the\n * declaration, else UTF-8 (see the module comment), warning where two of them disagree.\n * @param head - the first bytes (up to the declaration size; fewer when the input is shorter)\n */\n start(head: Uint8Array): void {\n refuseForeign(head, this.report, this.options);\n const explicit = this.options.encoding ?? null;\n const bom = bomEncoding(head);\n if (bom === \"utf-32le\" || bom === \"utf-32be\") {\n this.report.fail(\n INVALID_ENCODING_CODE,\n `the input starts with a ${bom.toUpperCase()} byte order mark; UTF-32 is not supported (convert the file to UTF-8)`,\n undefined,\n { byteOffset: 0 },\n );\n }\n if (bom !== null) {\n const option = explicit === null ? null : canonicalEncoding(explicit);\n if (option !== null && option !== bom) {\n this.conflict(`the encoding option says ${option} but the byte order mark says ${bom}; read as ${bom}`);\n }\n this.checkDeclaration(head, bom, \"its byte order mark says\");\n this.use(bom, false);\n return;\n }\n if (explicit !== null) {\n this.use(explicit, false);\n this.checkDeclaration(head, this.encoding, \"the encoding option says\");\n return;\n }\n const xmlUtf16 = xmlDeclarationUtf16(head);\n if (xmlUtf16 !== null) {\n this.checkDeclaration(head, xmlUtf16, \"its XML declaration's byte pattern says\");\n this.use(xmlUtf16, false);\n return;\n }\n const utf16 = bomlessUtf16(head);\n if (utf16 !== null && this.options.bomlessUtf16 === true) {\n this.use(utf16, false);\n return;\n }\n if (utf16 !== null) {\n this.report.fail(\n INVALID_ENCODING_CODE,\n `the input looks like ${utf16} text without a byte order mark (every other byte is 0); pass the encoding option ${JSON.stringify(utf16)} to read it`,\n undefined,\n { byteOffset: 0 },\n );\n }\n const declared = this.declared(head, \"windows-1252\");\n if (declared !== null) {\n const canonical = canonicalEncoding(declared);\n if (canonical === null) {\n this.report.warning(\n \"unsupported\",\n UNKNOWN_ENCODING_CODE,\n `the input declares the encoding ${JSON.stringify(declared)}, which this platform cannot decode; reading it as UTF-8`,\n { element: declared },\n );\n } else if (canonical.startsWith(\"utf-16\")) {\n // a declared UTF-16 over bytes that are not UTF-16 (no BOM, no NUL pattern): the\n // declaration itself was readable as ASCII\n this.conflict(\n `the input declares ${JSON.stringify(declared)} but has no byte order mark and its bytes are not UTF-16; read as UTF-8`,\n );\n } else if (canonical === \"utf-8\") {\n this.declaredUtf8 = true;\n } else {\n // a declared UTF-8 gets the undeclared treatment: tools often write the default\n // prolog over Latin-1 bytes\n this.use(canonical, false);\n return;\n }\n }\n this.use(\"utf-8\", true);\n }\n\n /**\n * The encoding the head declares, read through the format's declaration reader.\n * @param head - the first bytes\n * @param encoding - the encoding to read the head in for the reader\n * @returns the declared label, or null (also for a format without declarations)\n */\n private declared(head: Uint8Array, encoding: string): string | null {\n const reader = this.options.declaredEncoding;\n return reader === undefined ? null : reader(new TextDecoder(encoding).decode(head));\n }\n\n /**\n * Warn when the file declares an encoding other than the one a BOM or the option chose.\n * @param head - the first bytes\n * @param chosen - the encoding the input is read in\n * @param why - what chose it, for the message\n */\n private checkDeclaration(head: Uint8Array, chosen: string, why: string): void {\n const declared = this.declared(head, chosen);\n const canonical = declared === null ? null : canonicalEncoding(declared);\n if (canonical !== null && !sameFamily(canonical, chosen)) {\n this.conflict(\n `the input declares the encoding ${JSON.stringify(declared)} but ${why} ${chosen}; read as ${chosen}`,\n );\n }\n }\n\n /**\n * Record a W_ENCODING_CONFLICT warning.\n * @param message - which sources disagree and which applies\n */\n private conflict(message: string): void {\n this.report.warning(\"coercion\", ENCODING_CONFLICT_CODE, message);\n }\n\n /**\n * Decode the next bytes.\n * @param input - the bytes\n * @param stream - whether more bytes follow\n * @returns the text\n */\n decode(input: Uint8Array, stream: boolean): string {\n // a browser TextDecoder refuses a view of shared memory: decode a private copy\n const bytes =\n typeof SharedArrayBuffer === \"function\" && input.buffer instanceof SharedArrayBuffer\n ? input.slice()\n : input;\n const decoder = this.decoder as TextDecoder;\n if (this.fellBack || (this.mayFallBack && this.asciiSoFar)) {\n this.watch(bytes, !stream);\n if (this.fellBack && this.control !== null) {\n this.binary(this.control);\n }\n }\n const text = this.decodeOrRecover(decoder, bytes, stream);\n if (this.mixedPending) {\n this.reportUtf8After(bytes, this.offset);\n }\n if (this.asciiSoFar && this.mayFallBack) {\n this.trackAscii(bytes, text);\n }\n if (this.mayFallBack && this.options.nulIsBinary === true && text.includes(\"\\0\")) {\n // a NUL never occurs in a text file: undeclared bytes holding one are binary or BOM-less UTF-16\n this.binary({ at: this.offset + bytes.indexOf(0), byte: 0 });\n }\n this.offset += bytes.byteLength;\n return text;\n }\n\n /**\n * Decode bytes, recovering from bytes that are not valid in the encoding.\n * @param decoder - the decoder\n * @param bytes - the bytes\n * @param stream - whether more bytes follow\n * @returns the text\n */\n private decodeOrRecover(decoder: TextDecoder, bytes: Uint8Array, stream: boolean): string {\n try {\n return decoder.decode(bytes, { stream });\n } catch (err) {\n if (!(err instanceof TypeError)) {\n throw err;\n }\n return this.recover(bytes, stream);\n }\n }\n\n /**\n * Track whether the input is ASCII so far. While it is, every character is one byte, so the\n * bytes not yet emitted are held back for a fallback.\n * @param bytes - the bytes just decoded\n * @param text - their text\n */\n private trackAscii(bytes: Uint8Array, text: string): void {\n if (/[\\u0080-\\uffff]/.test(text)) {\n this.asciiSoFar = false;\n this.carry = new Uint8Array(0);\n return;\n }\n const all = this.carry.byteLength === 0 ? bytes : concatBytes([this.carry, bytes]);\n this.carry = all.slice(text.length);\n }\n\n /**\n * Flush the bytes held back because a text chunk follows (the input switches from bytes to\n * strings): a multi-byte sequence cut there is invalid UTF-8, never windows-1252 text.\n * @param flush - the flush to run (the decoder's own, or the head's)\n * @returns the text of the held-back bytes\n */\n flushBeforeText(flush: () => string): string {\n this.textFollows = true;\n try {\n return flush();\n } finally {\n this.textFollows = false;\n }\n }\n\n /**\n * A decode failed: switch to windows-1252 when allowed, else fail the import with the position\n * of the first byte that is not valid.\n * @param bytes - the bytes that failed\n * @param stream - whether more bytes follow\n * @returns the bytes decoded as windows-1252\n */\n private recover(bytes: Uint8Array, stream: boolean): string {\n const all = this.carry.byteLength === 0 ? bytes : concatBytes([this.carry, bytes]);\n const base = this.offset - this.carry.byteLength;\n const bad = this.encoding === \"utf-8\" ? invalidUtf8(all) : null;\n const at = base + (bad === null ? 0 : bad.index);\n if (this.mayFallBack && this.asciiSoFar) {\n const text = this.fallBack(all, bad, at, base, stream);\n if (text !== null) {\n return text;\n }\n }\n return this.failDecode(bytes, at, base, stream);\n }\n\n /**\n * Undeclared input that was ASCII so far failed to decode: fail on binary data or a cut\n * sequence, else switch to windows-1252 with a warning unless the bytes start with valid\n * non-ASCII UTF-8.\n * @param all - the held-back bytes followed by the bytes that failed\n * @param bad - the first invalid UTF-8 sequence, or null when the encoding is not UTF-8\n * @param at - the byte offset of the first invalid byte\n * @param base - the byte offset of `all`\n * @param stream - whether more bytes follow\n * @returns the bytes decoded as windows-1252, or null when they do not fall back\n */\n private fallBack(\n all: Uint8Array,\n bad: Utf8Problem | null,\n at: number,\n base: number,\n stream: boolean,\n ): string | null {\n // windows-1252 text holds no control bytes but TAB, LF, FF and CR: one anywhere in\n // undeclared input that is not UTF-8 marks binary data (watch() saw every byte so far)\n if (this.control !== null) {\n return this.binary(this.control);\n }\n if (this.textFollows && bad?.cut === true) {\n return this.report.fail(\n INVALID_UTF8_CODE,\n `invalid UTF-8 at byte ${at}: a byte chunk ends inside a multi-byte sequence and a text chunk follows`,\n undefined,\n { byteOffset: at },\n );\n }\n if (!stream && bad?.truncated === true) {\n return this.report.fail(\n INVALID_UTF8_CODE,\n `the input ends in the middle of a UTF-8 sequence at byte ${at} (it may be truncated)`,\n undefined,\n { byteOffset: at },\n );\n }\n if (startsWithUtf8(all)) {\n return null;\n }\n const cutNote =\n !stream && bad?.cut === true ? \": it ends inside a multi-byte UTF-8 sequence, so it may be truncated\" : \"\";\n this.report.warning(\n \"coercion\",\n ENCODING_FALLBACK_CODE,\n this.declaredUtf8\n ? `the input declares UTF-8 but is not valid UTF-8 (at byte ${at}); everything before was ASCII, so it is read as windows-1252 (pass the encoding option to choose another)`\n : `the input is not valid UTF-8 (at byte ${at}${cutNote}) and declares no encoding; read as windows-1252 (pass the encoding option to choose another)`,\n );\n this.use(\"windows-1252\", false);\n this.fellBack = true;\n this.mixedPending = true;\n this.reportUtf8After(all, base);\n return (this.decoder as TextDecoder).decode(all, { stream });\n }\n\n /**\n * Fail the import on bytes that are not valid in the encoding.\n * @param bytes - the bytes that failed\n * @param at - the byte offset of the first invalid UTF-8 byte\n * @param base - the byte offset of the held-back bytes and these\n * @param stream - whether more bytes follow\n * @returns never: it throws\n */\n private failDecode(bytes: Uint8Array, at: number, base: number, stream: boolean): never {\n if (this.encoding === \"utf-8\") {\n const after = this.mayFallBack ? \" after valid non-ASCII UTF-8 text; pass the encoding option\" : \"\";\n return this.report.fail(INVALID_UTF8_CODE, `invalid UTF-8 at byte ${at}${after}`, undefined, {\n byteOffset: at,\n });\n }\n const end = this.offset + bytes.byteLength;\n const odd = !stream && this.encoding.startsWith(\"utf-16\") && end % 2 === 1;\n return this.report.fail(\n INVALID_ENCODING_CODE,\n odd\n ? `the input ends with half a ${this.encoding} code unit at byte ${end - 1} (it may be truncated)`\n : `the bytes near byte ${base} are not valid ${this.encoding}`,\n undefined,\n { byteOffset: odd ? end - 1 : base },\n );\n }\n\n /**\n * After the windows-1252 fallback, report once that later bytes hold a valid multi-byte UTF-8\n * sequence: the input mixes encodings, and those characters are read as two or three\n * windows-1252 characters each.\n * @param bytes - bytes being decoded as windows-1252\n * @param start - the byte offset of the first of them\n */\n private reportUtf8After(bytes: Uint8Array, start: number): void {\n const at = utf8SequenceIndex(bytes);\n if (at < 0) {\n return;\n }\n this.mixedPending = false;\n this.report.warning(\n \"coercion\",\n ENCODING_FALLBACK_CODE,\n `bytes read as windows-1252 hold valid UTF-8 (at byte ${start + at}): the input mixes encodings, and its UTF-8 characters are read as windows-1252 (pass the encoding option to choose one)`,\n );\n }\n\n /**\n * Note the first control byte of the next bytes (see `control`).\n * @param bytes - the bytes, starting at `offset`\n * @param final - whether they end the input\n */\n private watch(bytes: Uint8Array, final: boolean): void {\n if (this.control !== null || bytes.byteLength === 0) {\n return;\n }\n if (this.subAt >= 0) {\n this.control = { at: this.subAt, byte: 0x1a };\n return;\n }\n // a Ctrl-Z at the end of a chunk is held until it is known whether more bytes follow\n const index = controlByte(bytes, true);\n if (index >= 0) {\n this.control = { at: this.offset + index, byte: bytes[index] };\n } else if (!final && bytes[bytes.byteLength - 1] === 0x1a) {\n this.subAt = this.offset + bytes.byteLength - 1;\n }\n }\n\n /**\n * Fail the import as binary data.\n * @param control - the control byte that shows it\n * @param control.at - its offset\n * @param control.byte - its value\n * @returns never\n */\n private binary(control: { readonly at: number; readonly byte: number }): never {\n const hex = control.byte.toString(16).padStart(2, \"0\");\n return this.report.fail(\n INVALID_UTF8_CODE,\n `the input is binary data, not text: control byte 0x${hex} at byte ${control.at}`,\n undefined,\n { byteOffset: control.at },\n );\n }\n\n /**\n * Switch to an encoding.\n * @param label - the encoding label\n * @param mayFallBack - whether a UTF-8 failure may switch to windows-1252\n */\n private use(label: string, mayFallBack: boolean): void {\n this.decoder = new TextDecoder(label, { fatal: true, ignoreBOM: true });\n this.encoding = this.decoder.encoding;\n this.mayFallBack = mayFallBack;\n }\n}\n\n/**\n * Where the first complete, valid multi-byte UTF-8 sequence of some bytes starts.\n * @param bytes - the bytes\n * @returns its index, or -1\n */\nfunction utf8SequenceIndex(bytes: Uint8Array): number {\n for (let i = 0; i < bytes.byteLength; i++) {\n if (bytes[i] >= 0xc2 && isUtf8SequenceAt(bytes, i)) {\n return i;\n }\n }\n return -1;\n}\n\n/**\n * Whether the first non-ASCII byte of a chunk starts a valid UTF-8 sequence: then the chunk holds\n * valid non-ASCII UTF-8 before whatever made it fail, and the input is not windows-1252.\n * @param bytes - a chunk that failed to decode as UTF-8\n * @returns true when its first non-ASCII sequence is valid UTF-8\n */\nfunction startsWithUtf8(bytes: Uint8Array): boolean {\n const i = bytes.findIndex((b) => b >= 0x80);\n return i >= 0 && isUtf8SequenceAt(bytes, i);\n}\n\n/** A strict UTF-8 decoder for checking single sequences (decode() without stream keeps no state). */\nconst STRICT_UTF8 = new TextDecoder(\"utf-8\", { fatal: true });\n\n/**\n * Whether a complete, valid multi-byte UTF-8 sequence starts at an index.\n * @param bytes - the bytes\n * @param i - the index of the lead byte\n * @returns true when the sequence is complete and valid\n */\nfunction isUtf8SequenceAt(bytes: Uint8Array, i: number): boolean {\n const lead = bytes[i];\n let length = 0;\n if (lead >= 0xc2 && lead <= 0xdf) {\n length = 2;\n } else if (lead >= 0xe0 && lead <= 0xef) {\n length = 3;\n } else if (lead >= 0xf0 && lead <= 0xf4) {\n length = 4;\n }\n if (length === 0 || i + length > bytes.byteLength) {\n return false;\n }\n try {\n STRICT_UTF8.decode(bytes.subarray(i, i + length));\n return true;\n } catch {\n return false;\n }\n}\n\n/** The upper half (0x80-0xFF) of code page 437, the zip format's legacy name encoding (APPNOTE appendix D). */\nconst CP437_HIGH: readonly number[] = [\n 0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0, 0x00e5, 0x00e7, 0x00ea, 0x00eb, 0x00e8, 0x00ef, 0x00ee, 0x00ec,\n 0x00c4, 0x00c5, 0x00c9, 0x00e6, 0x00c6, 0x00f4, 0x00f6, 0x00f2, 0x00fb, 0x00f9, 0x00ff, 0x00d6, 0x00dc, 0x00a2,\n 0x00a3, 0x00a5, 0x20a7, 0x0192, 0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x00f1, 0x00d1, 0x00aa, 0x00ba, 0x00bf, 0x2310,\n 0x00ac, 0x00bd, 0x00bc, 0x00a1, 0x00ab, 0x00bb, 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,\n 0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510, 0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c,\n 0x255e, 0x255f, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567, 0x2568, 0x2564, 0x2565, 0x2559,\n 0x2558, 0x2552, 0x2553, 0x256b, 0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580, 0x03b1, 0x00df,\n 0x0393, 0x03c0, 0x03a3, 0x03c3, 0x00b5, 0x03c4, 0x03a6, 0x0398, 0x03a9, 0x03b4, 0x221e, 0x03c6, 0x03b5, 0x2229,\n 0x2261, 0x00b1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00f7, 0x2248, 0x00b0, 0x2219, 0x00b7, 0x221a, 0x207f, 0x00b2,\n 0x25a0, 0x00a0,\n];\n\n/**\n * The first invalid UTF-8 sequence of a chunk (the WHATWG decoder's rules: no overlong forms, no\n * surrogates, nothing above U+10FFFF).\n * @param bytes - the bytes\n * @returns its index, whether it is a valid sequence cut by the end of the bytes (`cut`), and whether\n * that cut sequence holds at least one continuation byte (truncation rather than a stray windows-1252\n * byte); index 0 when none is found\n */\nfunction invalidUtf8(bytes: Uint8Array): Utf8Problem {\n let i = 0;\n while (i < bytes.byteLength) {\n const lead = bytes[i];\n const sequence = lead < 0x80 ? ASCII_SEQUENCE : utf8Sequence(lead);\n if (sequence === null) {\n return { index: i, truncated: false, cut: false };\n }\n const problem = checkContinuation(bytes, i, sequence);\n if (problem !== null) {\n return problem;\n }\n i += sequence.need + 1;\n }\n return { index: 0, truncated: false, cut: false };\n}\n\n/** Where a UTF-8 check stopped, and why. */\ninterface Utf8Problem {\n readonly index: number;\n readonly truncated: boolean;\n readonly cut: boolean;\n}\n\n/** The continuation bytes a UTF-8 lead byte needs, and the range of the first one. */\ninterface Utf8Sequence {\n readonly need: number;\n readonly low: number;\n readonly high: number;\n}\n\nconst ASCII_SEQUENCE: Utf8Sequence = { need: 0, low: 0x80, high: 0xbf };\n\n/**\n * What a UTF-8 lead byte needs after it (no overlong forms, no surrogates, nothing above U+10FFFF).\n * @param lead - the lead byte, 0x80 or above\n * @returns the sequence, or null when the byte cannot lead one\n */\nfunction utf8Sequence(lead: number): Utf8Sequence | null {\n if (lead >= 0xc2 && lead <= 0xdf) {\n return { need: 1, low: 0x80, high: 0xbf };\n }\n if (lead >= 0xe0 && lead <= 0xef) {\n return { need: 2, low: lead === 0xe0 ? 0xa0 : 0x80, high: lead === 0xed ? 0x9f : 0xbf };\n }\n if (lead >= 0xf0 && lead <= 0xf4) {\n return { need: 3, low: lead === 0xf0 ? 0x90 : 0x80, high: lead === 0xf4 ? 0x8f : 0xbf };\n }\n return null;\n}\n\n/**\n * Check the continuation bytes of the sequence led at `i`.\n * @param bytes - the bytes\n * @param i - the lead byte's index\n * @param sequence - what the lead byte needs\n * @returns the problem, or null when the sequence is valid\n */\nfunction checkContinuation(bytes: Uint8Array, i: number, sequence: Utf8Sequence): Utf8Problem | null {\n for (let k = 1; k <= sequence.need; k++) {\n if (i + k >= bytes.byteLength) {\n return { index: i, truncated: k > 1, cut: true };\n }\n const next = bytes[i + k];\n const low = k === 1 ? sequence.low : 0x80;\n const high = k === 1 ? sequence.high : 0xbf;\n if (next < low || next > high) {\n return { index: i, truncated: false, cut: false };\n }\n }\n return null;\n}\n\n/**\n * The first control byte of a chunk that text never holds: below 0x20 but TAB, LF, FF and CR, and\n * not a Ctrl-Z that ends the input (the DOS end-of-file marker).\n * @param bytes - the bytes\n * @param final - whether the bytes end the input\n * @returns its index, or -1\n */\nfunction controlByte(bytes: Uint8Array, final: boolean): number {\n const last = bytes.byteLength - 1;\n // a plain loop: findIndex() with a callback per byte was a measurable share of reading a large file\n for (let i = 0; i <= last; i++) {\n const b = bytes[i];\n if (b < 0x20 && b !== 0x09 && b !== 0x0a && b !== 0x0c && b !== 0x0d && !(b === 0x1a && final && i === last)) {\n return i;\n }\n }\n return -1;\n}\n\n/**\n * A zip entry name as text (APPNOTE 4.4.17 and appendix D): UTF-8 when the bytes are valid UTF-8,\n * whether or not the entry sets the language-encoding flag (bit 11); otherwise code page 437 when\n * the flag is clear (what Windows and older tools write), and windows-1252 when the entry claims\n * UTF-8 (or no flags are known). Never throws: a name is a matching key, never a path, so an\n * undecodable one still has to name its entry.\n * @param bytes - the name bytes from the central directory or a local header\n * @param cp437 - the entry's bit 11 is clear: decode a non-UTF-8 name as code page 437\n * @returns the name\n * @category Plugin helpers\n */\nexport function decodeEntryName(bytes: Uint8Array, cp437 = false): string {\n try {\n return new TextDecoder(\"utf-8\", { fatal: true, ignoreBOM: true }).decode(bytes);\n } catch {\n if (!cp437) {\n return new TextDecoder(\"windows-1252\").decode(bytes);\n }\n let out = \"\";\n for (const byte of bytes) {\n out += String.fromCodePoint(byte < 0x80 ? byte : CP437_HIGH[byte - 0x80]);\n }\n return out;\n }\n}\n\n/**\n * Join byte chunks.\n * @param chunks - the chunks\n * @returns one array holding them in order\n */\nfunction concatBytes(chunks: readonly Uint8Array[]): Uint8Array {\n if (chunks.length === 1) {\n return chunks[0];\n }\n const out = new Uint8Array(chunks.reduce((sum, c) => sum + c.byteLength, 0));\n let offset = 0;\n for (const chunk of chunks) {\n out.set(chunk, offset);\n offset += chunk.byteLength;\n }\n return out;\n}\n\n/**\n * Bytes decoded per call when the input is one in-memory Uint8Array, and characters per chunk of a\n * string input: every consumer of textChunks() then sees bounded chunks whatever the input shape (a\n * line reader or a record reader that holds one parse result per chunk never holds more than this\n * much text at once), and progress stays granular.\n */\nconst DECODE_SLICE = 256 * 1024;\n\nconst BOM = String.fromCharCode(0xfeff);\n\n/** The DOS end-of-file marker, Ctrl-Z. */\nconst SUB = String.fromCodePoint(0x1a);\n\n/**\n * The longest string V8 makes (2^29 - 24 UTF-16 code units); longer text cannot be one string.\n * @category Plugin helpers\n */\nexport const MAX_TEXT_LENGTH = 2 ** 29 - 24;\n\n/**\n * A character text keeps only by accident: a C0 control but TAB, LF, FF and CR, DEL, a C1 control\n * (also what windows-1252 bytes it leaves undefined decode to), and U+FEFF inside the text.\n */\nconst CONTROL_CHARACTER = new RegExp(\n `[${String.fromCodePoint(0x00)}-${String.fromCodePoint(0x08, 0x0b, 0x0e)}-${String.fromCodePoint(0x1f, 0x7f)}-${String.fromCodePoint(0x9f)}${BOM}]`,\n);\n\n/**\n * Whether a value is an ImportInput this module can read.\n * @param input - any value\n * @returns true for a string, a Uint8Array, a ReadableStream or an async iterable\n * @category Plugin helpers\n */\nexport function isImportInput(input: unknown): input is ImportInput {\n if (typeof input === \"string\" || asBytes(input) !== null) {\n return true;\n }\n if (typeof input !== \"object\" || input === null) {\n return false;\n }\n return typeof (input as { getReader?: unknown }).getReader === \"function\" || Symbol.asyncIterator in input;\n}\n\n/**\n * A Uint8Array, also one from another realm (a vm context, an iframe), as a Uint8Array of this one.\n * @param value - any value\n * @returns the bytes, or null when the value is not a Uint8Array\n */\nfunction asBytes(value: unknown): Uint8Array | null {\n if (value instanceof Uint8Array) {\n return value;\n }\n if (ArrayBuffer.isView(value) && Object.prototype.toString.call(value) === \"[object Uint8Array]\") {\n return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);\n }\n return null;\n}\n\n/**\n * The input as one of the ImportInput shapes, or E_UNSUPPORTED naming what was passed and how to\n * pass it instead (an ArrayBuffer, a Blob, a fetch Response, null from a failed read).\n * @param input - what the caller passed\n * @returns the input (a Uint8Array from another realm re-viewed in this one)\n * @category Plugin helpers\n */\nexport function normalizeInput(input: unknown): ImportInput {\n if (typeof input === \"string\") {\n return input;\n }\n const bytes = asBytes(input);\n if (bytes !== null) {\n return bytes;\n }\n if (isImportInput(input)) {\n return input;\n }\n const tag = Object.prototype.toString.call(input).slice(8, -1);\n let found: string = input === null ? \"null\" : typeof input;\n let fix = \"\";\n if (tag === \"ArrayBuffer\" || tag === \"SharedArrayBuffer\") {\n found = `an ${tag}`;\n fix = \"; wrap it as new Uint8Array(buffer)\";\n } else if (ArrayBuffer.isView(input)) {\n found = `a ${tag}`;\n fix = \"; pass new Uint8Array(view.buffer, view.byteOffset, view.byteLength)\";\n } else if (typeof input === \"object\" && input !== null) {\n const object = input as { stream?: unknown; size?: unknown; body?: unknown; arrayBuffer?: unknown };\n if (typeof object.stream === \"function\" && typeof object.size === \"number\") {\n found = \"a Blob or File\";\n fix = \"; pass blob.stream()\";\n } else if (\"body\" in object && typeof object.arrayBuffer === \"function\") {\n found = \"a fetch Response\";\n fix = \"; pass response.body\";\n } else {\n found = `an object (${tag})`;\n }\n }\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n `the input is ${found}; an importer reads a string, a Uint8Array, a ReadableStream or an async iterable of strings and Uint8Arrays${fix}`,\n { reason: \"input type\", found },\n );\n}\n\n/**\n * The total size of an in-memory input (bytes for a Uint8Array, UTF-16 code units for a string),\n * null for a stream or an iterable.\n * @param input - the input\n * @returns the size, or null when unknown up front\n * @category Plugin helpers\n */\nexport function inputLength(input: ImportInput): number | null {\n if (typeof input === \"string\") {\n return input.length;\n }\n if (input instanceof Uint8Array) {\n return input.byteLength;\n }\n return null;\n}\n\n/**\n * The UTF-8 length of a text, the unit onProgress counts text in (a lone surrogate counts as the\n * three bytes of U+FFFD).\n * @param text - the text\n * @returns its length in UTF-8 bytes\n */\nfunction utf8Length(text: string): number {\n let bytes = 0;\n let i = 0;\n while (i < text.length) {\n const c = text.charCodeAt(i); // NOSONAR(S7758): reads UTF-16 code units on purpose\n const pair = c >= 0xd800 && c <= 0xdbff && (text.charCodeAt(i + 1) & 0xfc00) === 0xdc00; // NOSONAR(S7758): reads UTF-16 code units on purpose\n if (c < 0x80) {\n bytes++;\n } else if (c < 0x800) {\n bytes += 2;\n } else {\n bytes += pair ? 4 : 3;\n }\n i += pair ? 2 : 1;\n }\n return bytes;\n}\n\n/**\n * Throw the signal's reason when it is aborted, exactly as the platform's\n * `AbortSignal.throwIfAborted()` does: the reason as it is (the DOMException named \"AbortError\"\n * of a reason-less abort, or whatever the caller passed to `abort(reason)`, an Error or not), so a\n * caller can compare the rejection with `signal.reason`. Only a runtime that stores no reason at\n * all gets a synthesized AbortError.\n * @param signal - the signal, or null\n * @category Writing a format\n */\nexport function throwIfAborted(signal: AbortSignal | null | undefined): void {\n if (!signal?.aborted) {\n return;\n }\n const { reason }: { reason: unknown } = signal;\n if (reason === undefined) {\n throw abortError();\n }\n // the platform contract: the reason itself, whatever its type\n throw reason as Error; // NOSONAR(S3696): rethrows the abort signal's reason, as the platform does\n}\n\n/**\n * An abort error for a signal that carries no reason.\n * @returns a DOMException named \"AbortError\" where DOMException exists, else an Error with that name\n */\nfunction abortError(): Error {\n const message = \"The import was aborted\";\n if (typeof DOMException === \"function\") {\n return new DOMException(message, \"AbortError\");\n }\n const err = new Error(message);\n err.name = \"AbortError\";\n return err;\n}\n\n/**\n * A promise that also settles when the signal fires, rejecting with its reason: a read that stalls\n * (a network body that never delivers) cannot keep an aborted import pending. The caller checks\n * the signal before calling.\n * @param promise - the pending operation\n * @param signal - the cancellation signal, or null\n * @returns the operation's result, or the abort reason as a rejection\n * @category Plugin helpers\n */\nexport function abortable<T>(promise: Promise<T>, signal: AbortSignal | null): Promise<T> {\n if (signal === null || typeof signal.addEventListener !== \"function\") {\n return promise;\n }\n return new Promise<T>((resolve, reject) => {\n const onAbort = (): void => {\n try {\n throwIfAborted(signal);\n } catch (err) {\n reject(err);\n }\n };\n signal.addEventListener(\"abort\", onAbort, { once: true });\n promise.then(\n (value) => {\n signal.removeEventListener(\"abort\", onAbort);\n resolve(value);\n },\n (err: unknown) => {\n signal.removeEventListener(\"abort\", onAbort);\n reject(err);\n },\n );\n });\n}\n\n/**\n * A reader of a stream, or E_UNSUPPORTED when another reader holds the stream already.\n * @param stream - the stream\n * @returns the reader\n * @category Plugin helpers\n */\nexport function lockReader(stream: ReadableStream<Uint8Array>): ReadableStreamDefaultReader<Uint8Array> {\n if (stream.locked) {\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n \"the input ReadableStream is locked: another reader holds it (release it, or pass a fresh stream)\",\n { reason: \"stream locked\" },\n );\n }\n return stream.getReader();\n}\n\n/**\n * The checks every decoded text passes once, whatever the input shape: leading U+FEFFs stripped,\n * a known non-graph document (HTML, PDF) refused, a trailing Ctrl-Z held back and dropped at the\n * end, the first control character reported, and an input with no text but whitespace refused.\n */\nclass TextFilter {\n private first = true;\n\n private content = false;\n\n private heldSub = false;\n\n private warned = false;\n\n private strayBom = false;\n\n /**\n * Create the filter of one import.\n * @param report - where the warnings and the fatal errors go\n * @param options - whether an empty input is valid, whether the format is XML\n */\n constructor(\n private readonly report: ImportReportBuilder,\n private readonly options: ReadOptions,\n ) {}\n\n /**\n * Filter the next decoded text.\n * @param chunk - the text\n * @returns the text to hand on\n */\n push(chunk: string): string {\n let text = this.heldSub ? SUB + chunk : chunk;\n this.heldSub = false;\n if (text.length === 0) {\n return text;\n }\n if (this.first) {\n text = this.skipByteOrderMarks(text);\n if (text.length === 0) {\n return text;\n }\n this.first = false;\n // ponytail: only the first non-empty chunk is checked, so a document arriving one\n // character per chunk is not recognized; the parser then fails on it instead\n refuseForeign(text, this.report, this.options);\n }\n if (text.endsWith(SUB)) {\n this.heldSub = true;\n text = text.slice(0, -1);\n }\n if (!this.content && /\\S/.test(text)) {\n this.content = true;\n }\n if (!this.warned) {\n this.warnControl(text);\n }\n return text;\n }\n\n /**\n * Drop the byte order marks the input starts with, warning when there is more than one.\n * @param text - the first text\n * @returns the text without them\n */\n private skipByteOrderMarks(text: string): string {\n let start = 0;\n while (text.codePointAt(start) === 0xfeff) {\n start++;\n }\n if (start > 1 && !this.strayBom) {\n // the first U+FEFF is the byte order mark; another one is a stray character\n this.strayBom = true;\n this.report.warning(\n \"validation-error\",\n CONTROL_CHARACTER_CODE,\n `the input starts with ${start} byte order marks (U+FEFF); the extra ones were ignored`,\n { element: \"U+FEFF\" },\n );\n }\n return text.slice(start);\n }\n\n /**\n * Warn, once, about the first control character the text holds.\n * @param text - the text\n */\n private warnControl(text: string): void {\n const match = CONTROL_CHARACTER.exec(text);\n if (match === null) {\n return;\n }\n this.warned = true;\n const code = (match[0].codePointAt(0) ?? 0).toString(16).toUpperCase().padStart(4, \"0\");\n const around = JSON.stringify(text.slice(Math.max(0, match.index - 20), match.index + 20));\n this.report.warning(\n \"validation-error\",\n CONTROL_CHARACTER_CODE,\n `the input holds the control character U+${code} (in ${around}); it is kept in the id or value it is part of`,\n { element: `U+${code}` },\n );\n }\n\n /** The input ended: drop a held Ctrl-Z with a warning, and refuse an input without content. */\n end(): void {\n if (this.heldSub) {\n this.report.warning(\n \"validation-error\",\n CONTROL_CHARACTER_CODE,\n \"the input ends with a Ctrl-Z (0x1A), the DOS end-of-file marker; it was ignored\",\n { element: \"U+001A\" },\n );\n }\n if (!this.content && this.options.allowEmpty !== true) {\n this.report.fail(EMPTY_INPUT_CODE, this.first ? \"the input is empty\" : \"the input holds only whitespace\");\n }\n }\n}\n\n/**\n * Record W_OPTION_IGNORED for an encoding option given with text input, which is already decoded.\n * @param report - the report\n * @param encoding - the option, or null / undefined\n */\nfunction reportTextEncoding(report: ImportReportBuilder, encoding: string | null | undefined): void {\n if (encoding !== null && encoding !== undefined) {\n report.warning(\n \"unsupported\",\n OPTION_IGNORED_CODE,\n \"option encoding has no effect on text input, which is already decoded\",\n { element: \"encoding\" },\n );\n }\n}\n\n/**\n * Read an ImportInput as a sequence of decoded text chunks. Chunk boundaries carry no meaning:\n * a caller that needs lines uses LineReader, one that needs the whole document uses readText().\n * The signal is checked before every chunk and while a stream read is pending; a stream is\n * canceled when the consumer stops early or the signal fires. Progress is reported after every\n * chunk, in bytes (text counted as UTF-8).\n * @param rawInput - the input\n * @param report - the report decode errors and the text checks are recorded in (E_INVALID_UTF8,\n * E_EMPTY_INPUT, ... then ImportError)\n * @param options - cancellation, progress and the encoding\n * @yields decoded text; leading BOMs and a trailing Ctrl-Z removed\n * @returns nothing\n * @category Writing a format\n */\nexport async function* textChunks(\n rawInput: ImportInput,\n report: ImportReportBuilder,\n options: ReadOptions = {},\n): AsyncGenerator<string, void, undefined> {\n const input = normalizeInput(rawInput);\n const signal = options.signal ?? null;\n const filter = new TextFilter(report, options);\n throwIfAborted(signal);\n if (typeof input === \"string\") {\n reportTextEncoding(report, options.encoding);\n yield* stringTextChunks(input, filter, options);\n return;\n }\n const decoder = new ByteDecoder(report, options);\n if (input instanceof Uint8Array) {\n yield* byteTextChunks(input, filter, decoder, options);\n return;\n }\n // the stream's loop stays here rather than in a delegated generator: a yield* layer costs\n // time on every chunk, and a stream may arrive in many small ones\n const stream = new StreamText(filter, decoder, options);\n for await (const chunk of isReadableStream(input) ? streamChunks(input, signal) : input) {\n throwIfAborted(signal);\n const text = stream.push(chunk);\n if (text.length > 0) {\n yield text;\n }\n options.onProgress?.(stream.done);\n }\n const tail = stream.end();\n if (tail.length > 0) {\n yield tail;\n }\n filter.end();\n options.onProgress?.(stream.done, stream.done);\n}\n\n/**\n * The end of the slice of a string input that starts at start: DECODE_SLICE code units, one more\n * when the slice would end between the two halves of a surrogate pair.\n * @param input - the string\n * @param start - where the slice starts\n * @returns where it ends\n */\nfunction stringSliceEnd(input: string, start: number): number {\n const end = Math.min(start + DECODE_SLICE, input.length);\n const highSurrogate = (input.charCodeAt(end - 1) & 0xfc00) === 0xd800; // NOSONAR(S7758): reads UTF-16 code units on purpose\n return end < input.length && highSurrogate ? end + 1 : end;\n}\n\n/**\n * textChunks() of a string input: slices of it, through the text filter.\n * @param input - the string\n * @param filter - the text checks\n * @param options - cancellation and progress\n * @yields the filtered slices\n * @returns nothing\n */\nfunction* stringTextChunks(\n input: string,\n filter: TextFilter,\n options: ReadOptions,\n): Generator<string, void, undefined> {\n const signal = options.signal ?? null;\n const onProgress = options.onProgress ?? null;\n const total = onProgress === null ? 0 : utf8Length(input);\n let done = 0;\n let start = 0;\n while (start < input.length) {\n throwIfAborted(signal);\n const end = stringSliceEnd(input, start);\n const piece = start === 0 && end === input.length ? input : input.slice(start, end);\n start = end;\n const text = filter.push(piece);\n if (text.length > 0) {\n yield text;\n }\n if (onProgress !== null) {\n done += utf8Length(piece);\n onProgress(done, total);\n }\n }\n if (input.length === 0) {\n onProgress?.(0, 0);\n }\n filter.end();\n}\n\n/**\n * textChunks() of a Uint8Array input: slices of it, decoded, through the text filter.\n * @param input - the bytes\n * @param filter - the text checks\n * @param decoder - the byte decoder\n * @param options - cancellation, progress and the declaration size\n * @yields the decoded, filtered slices\n * @returns nothing\n */\nfunction* byteTextChunks(\n input: Uint8Array,\n filter: TextFilter,\n decoder: ByteDecoder,\n options: ReadOptions,\n): Generator<string, void, undefined> {\n const signal = options.signal ?? null;\n const length = input.byteLength;\n decoder.start(input.subarray(0, headByteCount(options)));\n for (let offset = 0; offset < length; offset += DECODE_SLICE) {\n throwIfAborted(signal);\n if (input.byteLength !== length) {\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n \"the input's buffer was detached (transferred) or resized during the import\",\n { reason: \"detached\" },\n );\n }\n const slice = input.subarray(offset, Math.min(offset + DECODE_SLICE, length));\n const text = filter.push(decoder.decode(slice, offset + DECODE_SLICE < length));\n if (text.length > 0) {\n yield text;\n }\n options.onProgress?.(Math.min(offset + DECODE_SLICE, length), length);\n }\n if (length === 0) {\n options.onProgress?.(0, 0);\n }\n filter.end();\n}\n\n/**\n * How many leading bytes the encoding is chosen from: the format's declaration size, at least a BOM.\n * @param options - the declaration size\n * @returns the byte count\n */\nfunction headByteCount(options: ReadOptions): number {\n return Math.max(options.declarationBytes ?? HEAD_BYTES, BOM_BYTES);\n}\n\n/**\n * The chunks of a stream input (a ReadableStream or an async iterable of strings and bytes) turned\n * into filtered text. The first bytes are held back until the BOM check (and the declaration\n * check, when the format has one) can see enough of them, or the input ended, or text arrived, so\n * a BOM or a declaration split across small chunks is still seen.\n */\nclass StreamText {\n /** Bytes read so far (text counted as UTF-8 when progress is reported), for progress. */\n done = 0;\n\n private head: Uint8Array[] = [];\n\n private headLength = 0;\n\n private readonly headBytes: number;\n\n /** How many bytes to hold back before choosing the encoding. */\n private readonly needed: number;\n\n /** Whether progress is reported, so text chunks are measured. */\n private readonly counting: boolean;\n\n /**\n * Create the reader of one stream input.\n * @param filter - the text checks\n * @param decoder - the byte decoder\n * @param options - progress, the declaration reader and its size\n */\n constructor(\n private readonly filter: TextFilter,\n private readonly decoder: ByteDecoder,\n options: ReadOptions,\n ) {\n this.headBytes = headByteCount(options);\n this.needed = options.declaredEncoding === undefined ? BOM_BYTES : this.headBytes;\n this.counting = (options.onProgress ?? null) !== null;\n }\n\n /**\n * Read the next chunk.\n * @param chunk - a string or a Uint8Array (anything else is E_UNSUPPORTED)\n * @returns its filtered text; empty while bytes are held back\n */\n push(chunk: unknown): string {\n if (typeof chunk === \"string\") {\n this.done += this.counting ? utf8Length(chunk) : 0;\n return this.filter.push(this.beforeText() + chunk);\n }\n const bytes = asBytes(chunk);\n if (bytes === null) {\n throw new GraphFormatError(\"E_UNSUPPORTED\", \"an input chunk must be a string or a Uint8Array\", {\n reason: \"chunk type\",\n found: typeof chunk,\n });\n }\n this.done += bytes.byteLength;\n if (this.decoder.started) {\n return this.filter.push(this.decoder.decode(bytes, true));\n }\n this.head.push(bytes);\n this.headLength += bytes.byteLength;\n return this.headLength >= this.needed ? this.filter.push(this.flushHead(true)) : \"\";\n }\n\n /**\n * The input ended: the filtered text of whatever is still held or pending.\n * @returns the text\n */\n end(): string {\n let tail = \"\";\n if (this.headLength > 0) {\n tail = this.flushHead(false);\n } else if (this.decoder.started) {\n tail = this.decoder.decode(new Uint8Array(0), false);\n }\n return this.filter.push(tail);\n }\n\n /**\n * Start the decoder on the held bytes and decode them.\n * @param stream - whether more bytes follow\n * @returns their text\n */\n private flushHead(stream: boolean): string {\n const bytes = concatBytes(this.head);\n this.head = [];\n this.headLength = 0;\n this.decoder.start(bytes.subarray(0, this.headBytes));\n return this.decoder.decode(bytes, stream);\n }\n\n /**\n * A text chunk follows: finish any byte sequence still pending in the decoder before switching\n * to text. The BOM and declaration checks apply to the start of the input only, so bytes after\n * text are never taken for a BOM.\n * @returns the text of the pending bytes\n */\n private beforeText(): string {\n if (this.headLength > 0) {\n return this.decoder.flushBeforeText(() => this.flushHead(false));\n }\n if (this.decoder.started) {\n return this.decoder.flushBeforeText(() => this.decoder.decode(new Uint8Array(0), false));\n }\n this.decoder.start(new Uint8Array(0));\n return \"\";\n }\n}\n\n/**\n * Whether an input is a ReadableStream (by duck type, so a stream from another realm qualifies).\n * @param input - a non-string, non-Uint8Array input\n * @returns true for a ReadableStream\n */\nfunction isReadableStream(\n input: ReadableStream<Uint8Array> | AsyncIterable<string | Uint8Array>,\n): input is ReadableStream<Uint8Array> {\n return typeof (input as { getReader?: unknown }).getReader === \"function\";\n}\n\n/**\n * Iterate a ReadableStream through a reader, cancelling the stream (with the signal's reason) when\n * iteration stops early or the signal fires, also while a read is pending.\n * @param stream - the stream\n * @param signal - the cancellation signal, or null\n * @yields the stream's chunks\n * @returns nothing\n */\nasync function* streamChunks(\n stream: ReadableStream<Uint8Array>,\n signal: AbortSignal | null,\n): AsyncGenerator<Uint8Array, void, undefined> {\n const reader = lockReader(stream);\n let finished = false;\n try {\n for (;;) {\n throwIfAborted(signal);\n const { done, value } = await abortable(reader.read(), signal);\n if (done) {\n finished = true;\n return;\n }\n yield value;\n }\n } finally {\n if (!finished) {\n await reader.cancel(signal?.reason).catch(() => undefined);\n }\n reader.releaseLock();\n }\n}\n\n/**\n * Read the whole input as bytes, for a binary format (a zip): nothing is decoded. The signal is\n * checked before every chunk and progress reported after it; a stream is canceled when the read\n * stops early.\n * @param rawInput - the input\n * @param options - cancellation and progress (the encoding is ignored)\n * @returns the bytes, or null when the input is text (a string, or a chunk that is a string),\n * which a binary format cannot read\n */\nexport async function readBytes(rawInput: ImportInput, options: ReadOptions = {}): Promise<Uint8Array | null> {\n const input = normalizeInput(rawInput);\n const signal = options.signal ?? null;\n throwIfAborted(signal);\n if (typeof input === \"string\") {\n return null;\n }\n if (input instanceof Uint8Array) {\n options.onProgress?.(input.byteLength, input.byteLength);\n return input;\n }\n const parts: Uint8Array[] = [];\n let done = 0;\n for await (const chunk of isReadableStream(input) ? streamChunks(input, signal) : input) {\n throwIfAborted(signal);\n if (typeof chunk === \"string\") {\n return null;\n }\n const bytes = asBytes(chunk);\n if (bytes === null) {\n throw new GraphFormatError(\"E_UNSUPPORTED\", \"an input chunk must be a string or a Uint8Array\", {\n reason: \"chunk type\",\n found: typeof chunk,\n });\n }\n parts.push(bytes);\n done += bytes.byteLength;\n options.onProgress?.(done);\n }\n options.onProgress?.(done, done);\n return parts.length === 0 ? new Uint8Array(0) : concatBytes(parts);\n}\n\n/**\n * Fail an import whose text is longer than one JavaScript string can hold.\n * @param report - the report\n * @param message - what is too long\n * @param line - the line, when known\n * @category Plugin helpers\n */\nexport function tooLarge(report: ImportReportBuilder, message: string, line?: number): never {\n report.failWith(\"unsupported\", TOO_LARGE_CODE, message, line === undefined ? undefined : { line });\n}\n\n/**\n * Read the whole input as one string (what the GML, DOT and JSON importers do), failing with\n * E_TOO_LARGE (category unsupported) before the join when it is longer than one JavaScript string\n * can hold. A string input is used as it is (one progress call), after the same text checks.\n * @param rawInput - the input\n * @param report - the report the decode error is recorded in\n * @param options - cancellation and progress\n * @returns the decoded text without a leading BOM or a trailing Ctrl-Z\n * @category Writing a format\n */\nexport async function readText(\n rawInput: ImportInput,\n report: ImportReportBuilder,\n options: ReadOptions = {},\n): Promise<string> {\n const input = normalizeInput(rawInput);\n if (typeof input === \"string\") {\n throwIfAborted(options.signal);\n reportTextEncoding(report, options.encoding);\n const filter = new TextFilter(report, options);\n const text = filter.push(input);\n filter.end();\n if (options.onProgress !== null && options.onProgress !== undefined) {\n const total = utf8Length(input);\n options.onProgress(total, total);\n }\n return text;\n }\n const parts: string[] = [];\n let length = 0;\n for await (const chunk of textChunks(input, report, options)) {\n length += chunk.length;\n if (length > MAX_TEXT_LENGTH) {\n tooLarge(\n report,\n `the document is longer than ${MAX_TEXT_LENGTH} characters, the most one JavaScript string holds`,\n );\n }\n parts.push(chunk);\n }\n return parts.length === 1 ? parts[0] : parts.join(\"\");\n}\n\n/**\n * Lines of an ImportInput without allocating anything per line but the string itself: iterate with\n * `for await (const text of reader)` and read `reader.line` (1-based) for the line just yielded.\n * `\\n`, `\\r\\n` and lone `\\r` all end a line; the terminator is not part of the text; a final\n * line without a terminator is yielded when non-empty, and every line in between is yielded even\n * when empty (the importer decides what a blank line means).\n * @category Writing a format\n */\nexport class LineReader implements AsyncIterable<string> {\n private readonly input: ImportInput;\n\n private readonly report: ImportReportBuilder;\n\n private readonly options: ReadOptions;\n\n private lineNumber = 0;\n\n /**\n * Create a reader over an input; nothing is read until iteration starts.\n * @param input - the input\n * @param report - the report decode errors are recorded in\n * @param options - cancellation and progress\n */\n constructor(input: ImportInput, report: ImportReportBuilder, options: ReadOptions = {}) {\n this.input = input;\n this.report = report;\n this.options = options;\n }\n\n /**\n * The 1-based number of the line most recently yielded.\n * @returns the line number; 0 before the first line\n */\n get line(): number {\n return this.lineNumber;\n }\n\n /**\n * The E_TOO_LARGE message of a line longer than one string.\n * @returns the message\n */\n private lineTooLong(): string {\n return `a line is longer than ${MAX_TEXT_LENGTH} characters, the most one JavaScript string holds`;\n }\n\n /**\n * Iterate the lines.\n * @yields one line at a time, terminator removed\n * @returns nothing\n */\n async *[Symbol.asyncIterator](): AsyncGenerator<string, void, undefined> {\n // The pieces of the line in progress, joined once when the line ends, so a line spanning\n // many chunks costs its length, not its length times the chunk count.\n const pending = new PendingLine((line) => tooLarge(this.report, this.lineTooLong(), line));\n let trailingCr = false;\n for await (const chunk of textChunks(this.input, this.report, this.options)) {\n let start = 0;\n if (trailingCr) {\n // the previous chunk ended with `\\r`: that ended a line, and a leading `\\n` here is\n // the second half of the same terminator\n trailingCr = false;\n this.lineNumber++;\n yield pending.take().slice(0, -1);\n if (chunk.charCodeAt(0) === 10) {\n start = 1;\n }\n }\n const breaks = new LineBreaks(chunk, start);\n while (breaks.advance()) {\n this.lineNumber++;\n yield pending.finish(chunk.slice(start, breaks.cut), this.lineNumber);\n start = breaks.next;\n }\n if (start < chunk.length) {\n pending.appendRest(chunk, start, this.lineNumber + 1);\n trailingCr = chunk.codePointAt(chunk.length - 1) === 13;\n }\n }\n if (!pending.empty) {\n this.lineNumber++;\n const joined = pending.take();\n yield joined.endsWith(\"\\r\") ? joined.slice(0, -1) : joined;\n }\n }\n}\n\n/**\n * The pieces of a line that spans chunks. None of them holds a line break, except that the last\n * may end with a `\\r` whose meaning the next chunk decides.\n */\nclass PendingLine {\n private readonly pieces: string[] = [];\n\n private length = 0;\n\n private readonly tooLong: (line: number) => never;\n\n /**\n * Start an empty line.\n * @param tooLong - fails the import when the line grows longer than one string can hold\n */\n constructor(tooLong: (line: number) => never) {\n this.tooLong = tooLong;\n }\n\n /**\n * Whether no piece is held.\n * @returns true when the line in progress is empty\n */\n get empty(): boolean {\n return this.pieces.length === 0;\n }\n\n /**\n * Hold the rest of a chunk from `start`: the line goes on in the next chunk.\n * @param chunk - the chunk\n * @param start - where the unfinished line starts in it\n * @param line - the 1-based number of the line, for the too-long error\n */\n appendRest(chunk: string, start: number, line: number): void {\n this.append(start === 0 ? chunk : chunk.slice(start), line);\n }\n\n /**\n * End the line with its last piece.\n * @param piece - the text from the start of the chunk (or the last break) to the line break\n * @param line - the 1-based number of the line, for the too-long error\n * @returns the whole line\n */\n finish(piece: string, line: number): string {\n if (this.pieces.length === 0) {\n return piece;\n }\n this.append(piece, line);\n return this.take();\n }\n\n /**\n * Join the held pieces and start a new line.\n * @returns the joined text\n */\n take(): string {\n const joined = this.pieces.join(\"\");\n this.pieces.length = 0;\n this.length = 0;\n return joined;\n }\n\n /**\n * Hold one more piece.\n * @param piece - the piece\n * @param line - the 1-based number of the line, for the too-long error\n */\n private append(piece: string, line: number): void {\n this.length += piece.length;\n if (this.length > MAX_TEXT_LENGTH) {\n this.tooLong(line);\n }\n this.pieces.push(piece);\n }\n}\n\n/**\n * The line breaks of one chunk, in order: `\\n`, `\\r\\n` and a lone `\\r`. Each of `\\n` and `\\r` is\n * searched for once per chunk and again only after it was consumed, so a chunk is scanned once\n * whatever its line count.\n */\nclass LineBreaks {\n /** Where the line just found ends (its terminator starts there). */\n cut = 0;\n\n /** Where the next line starts. */\n next: number;\n\n private readonly chunk: string;\n\n private nl: number;\n\n private cr: number;\n\n /**\n * Scan a chunk from a position.\n * @param chunk - the chunk\n * @param start - where scanning starts\n */\n constructor(chunk: string, start: number) {\n this.chunk = chunk;\n this.next = start;\n this.nl = chunk.indexOf(\"\\n\", start);\n this.cr = chunk.indexOf(\"\\r\", start);\n }\n\n /**\n * Find the next line break.\n * @returns false when none is left, or the only one left is a trailing `\\r` (it may be the first\n * half of a `\\r\\n` split across chunks)\n */\n advance(): boolean {\n const { chunk, next } = this;\n if (this.nl >= 0 && this.nl < next) {\n this.nl = chunk.indexOf(\"\\n\", next);\n }\n if (this.cr >= 0 && this.cr < next) {\n this.cr = chunk.indexOf(\"\\r\", next);\n }\n const { nl, cr } = this;\n if (cr >= 0 && (nl < 0 || cr < nl)) {\n if (cr === chunk.length - 1) {\n return false;\n }\n this.cut = cr;\n this.next = chunk.codePointAt(cr + 1) === 10 ? cr + 2 : cr + 1;\n return true;\n }\n if (nl < 0) {\n return false;\n }\n this.cut = nl;\n this.next = nl + 1;\n return true;\n }\n}\n","/**\n * Option normalization for importers and exporters (design sections 8.4 and 8.5): every common\n * option resolved to its documented default, enum values checked (E_UNSUPPORTED, the core's\n * convention for an option outside its set), and the per-format defaults (`ids`, `defaultDirected`,\n * `weightFrom`, `addMissingNodes`) supplied by the importer that calls resolveImportOptions().\n */\n\nimport { type DuplicatePolicy, GraphFormatError, type GraphSink, type IdCoercion } from \"@graphty/graph-format\";\n\nimport { type CommonExportOptions, type CommonImportOptions, type GraphChoiceOptions } from \"../types.js\";\nimport {\n AMBIGUOUS_GRAPH_NAME_CODE,\n GRAPH_NOT_FOUND_CODE,\n NO_GRAPH_CODE,\n OPTION_IGNORED_CODE,\n SINK_OPTION_CODE,\n} from \"./codes.js\";\nimport { canonicalEncoding } from \"./input.js\";\nimport { plural } from \"./plural.js\";\nimport { type ImportReportBuilder } from \"./report.js\";\n\n/**\n * The defaults an importer supplies for the options whose default is per format.\n * @category Plugin helpers\n */\nexport interface ImportFormatDefaults {\n /** \"canonical\" for text-cell formats, \"keep\" for JSON. */\n readonly ids: IdCoercion;\n /** The direction assumed when the file declares none. */\n readonly defaultDirected: boolean;\n /** The attribute that becomes the weight (\"weight\", GML \"value\"), or null for an unweighted format. */\n readonly weightFrom: string | null;\n /** Whether edges may reference undeclared nodes; true unless the format says otherwise (GEXF: false). */\n readonly addMissingNodes?: boolean | undefined;\n}\n\n/**\n * CommonImportOptions with every field present.\n * @public\n * @category Plugin helpers\n */\nexport interface ResolvedImportOptions {\n /** The id coercion rule. */\n readonly ids: IdCoercion;\n /** Which field becomes the node id. */\n readonly nodeIdFrom: \"id\" | \"label\" | \"index\";\n /** Whether an edge may reference an undeclared node. */\n readonly addMissingNodes: boolean;\n /** The builder's duplicate-edge policy seed. */\n readonly duplicateEdges: DuplicatePolicy;\n /** The builder's self-loop policy seed. */\n readonly selfLoops: \"keep\" | \"drop\" | \"error\";\n /** The mixed-direction policy. */\n readonly onMixedDirection: \"expand\" | \"directed\" | \"undirected\" | \"error\";\n /** The direction assumed when the file declares none. */\n readonly defaultDirected: boolean;\n /** The weight attribute, or null for unweighted. */\n readonly weightFrom: string | null;\n /** The weight staging precision. */\n readonly weightDtype: \"f32\" | \"f64\";\n /** How declared long columns are stored. */\n readonly long: \"f64\" | \"string\";\n /** Whether mangled ids are restored. */\n readonly restoreMangledIds: boolean;\n /** The hyperedge policy. */\n readonly hyperedges: \"error\" | \"skip\" | \"star\" | \"clique\";\n /** Errors tolerated before aborting. */\n readonly errorLimit: number;\n /** The cancellation signal, or null. */\n readonly signal: AbortSignal | null;\n /** The progress callback, or null. */\n readonly onProgress: ((bytesDone: number, bytesTotal?: number) => void) | null;\n /** The caller's byte encoding (canonical name), or null to detect it. */\n readonly encoding: string | null;\n}\n\n/**\n * CommonExportOptions with every field present.\n * @category Plugin helpers\n */\nexport interface ResolvedExportOptions {\n /** \"error\" never renames a node; \"mangle\" rewrites and keeps the original. */\n readonly sanitizeIds: \"error\" | \"mangle\";\n /** What a format without mixed-direction support does with a mixed snapshot. */\n readonly onMixedDirection: \"error\" | \"directed\" | \"undirected\";\n}\n\nconst ID_COERCIONS: ReadonlySet<string> = new Set([\"keep\", \"canonical\", \"string\", \"number\"]);\nconst NODE_ID_SOURCES: ReadonlySet<string> = new Set([\"id\", \"label\", \"index\"]);\nconst DUPLICATE_POLICIES: ReadonlySet<string> = new Set([\"keep\", \"error\", \"first\", \"last\", \"sum\", \"min\", \"max\"]);\nconst SELF_LOOP_POLICIES: ReadonlySet<string> = new Set([\"keep\", \"drop\", \"error\"]);\nconst IMPORT_MIXED_POLICIES: ReadonlySet<string> = new Set([\"expand\", \"directed\", \"undirected\", \"error\"]);\nconst EXPORT_MIXED_POLICIES: ReadonlySet<string> = new Set([\"error\", \"directed\", \"undirected\"]);\nconst WEIGHT_DTYPES: ReadonlySet<string> = new Set([\"f32\", \"f64\"]);\nconst LONG_MODES: ReadonlySet<string> = new Set([\"f64\", \"string\"]);\nconst HYPEREDGE_POLICIES: ReadonlySet<string> = new Set([\"error\", \"skip\", \"star\", \"clique\"]);\nconst SANITIZE_MODES: ReadonlySet<string> = new Set([\"error\", \"mangle\"]);\n\n/**\n * The default error limit: errors tolerated before an import aborts.\n * @category Reports and errors\n */\nexport const DEFAULT_ERROR_LIMIT = 100;\n\nexport { SINK_OPTION_CODE } from \"./codes.js\";\n\n/** The builder-policy options a sink exposes read-only as `sink.options` (design section 8.4). */\nconst SINK_OPTION_NAMES = [\"addMissingNodes\", \"duplicateEdges\", \"selfLoops\", \"weightDtype\"] as const;\n\n/**\n * Report every builder-policy option the caller explicitly requested that the sink does not use,\n * one `W_SINK_OPTION` warning per option with the option name as\n * the element. Options left undefined are never reported: they are defaults, not requests. On the\n * registry's builder, which is seeded from the same options, nothing is ever reported.\n * @param sink - the sink the importer pushes into\n * @param options - the caller's raw options, possibly undefined\n * @param report - the report to record into\n * @param enforcesMissingNodes - true when the importer applies `addMissingNodes: false` itself (it\n * refuses unknown endpoints before the sink sees them), so that request is honored on any sink and\n * only `addMissingNodes: true` against a refusing sink is reported\n * @returns the number of warnings recorded\n * @category Writing a format\n */\nexport function reportSinkOptions(\n sink: GraphSink,\n options: CommonImportOptions | undefined,\n report: ImportReportBuilder,\n enforcesMissingNodes = false,\n): number {\n if (options === undefined) {\n return 0;\n }\n let recorded = 0;\n for (const name of SINK_OPTION_NAMES) {\n const wanted: unknown = options[name];\n const actual: unknown = sink.options[name];\n if (wanted === undefined || wanted === actual) {\n continue;\n }\n if (name === \"addMissingNodes\" && enforcesMissingNodes && wanted === false) {\n continue;\n }\n report.warning(\n \"coercion\",\n SINK_OPTION_CODE,\n `option ${name}: ${JSON.stringify(wanted)} requested but the sink uses ${JSON.stringify(actual)}; the sink's setting applies`,\n { element: name },\n );\n recorded++;\n }\n return recorded;\n}\n\n/** The common options a format may leave unused; `signal`, `onProgress` and `errorLimit` apply everywhere. */\nconst IGNORABLE_OPTION_NAMES = [\n \"ids\",\n \"nodeIdFrom\",\n \"addMissingNodes\",\n \"duplicateEdges\",\n \"selfLoops\",\n \"onMixedDirection\",\n \"defaultDirected\",\n \"weightFrom\",\n \"weightDtype\",\n \"long\",\n \"restoreMangledIds\",\n \"hyperedges\",\n] as const;\n\n/** The defaults that are the same in every format (the others, such as `defaultDirected`, differ by format). */\nconst FIXED_DEFAULTS: Readonly<Partial<Record<(typeof IGNORABLE_OPTION_NAMES)[number], unknown>>> = {\n nodeIdFrom: \"id\",\n duplicateEdges: \"keep\",\n selfLoops: \"keep\",\n onMixedDirection: \"expand\",\n weightDtype: \"f64\",\n long: \"f64\",\n restoreMangledIds: true,\n hyperedges: \"skip\",\n};\n\n/**\n * Report every common option the caller set to a non-default value that the format has no use\n * for: one\n * `W_OPTION_IGNORED` warning (category `unsupported`) per option, the option name as the element.\n * The builder-policy options are reportSinkOptions()'s and are skipped here.\n * @param options - the caller's raw options, possibly undefined\n * @param report - the report to record into\n * @param used - the common option names the importer reads\n * @returns the number of warnings recorded\n * @category Writing a format\n */\nexport function reportUnusedOptions(\n options: CommonImportOptions | undefined,\n report: ImportReportBuilder,\n used: ReadonlySet<keyof CommonImportOptions>,\n): number {\n if (options === undefined) {\n return 0;\n }\n let recorded = 0;\n for (const name of IGNORABLE_OPTION_NAMES) {\n if (used.has(name) || (SINK_OPTION_NAMES as readonly string[]).includes(name)) {\n continue;\n }\n const value: unknown = options[name];\n if (value === undefined || value === FIXED_DEFAULTS[name]) {\n // an option spelled out at its default changes nothing, whether or not the format reads it\n continue;\n }\n report.warning(\n \"unsupported\",\n OPTION_IGNORED_CODE,\n `option ${name}: ${JSON.stringify(value)} has no effect on the ${report.format} importer`,\n { element: name },\n );\n recorded++;\n }\n return recorded;\n}\n\n/**\n * Whether the caller chose a graph with `graphIndex` or `graphName`. An importer warns\n * W_MULTIPLE_GRAPHS about the graphs it skipped only when it read the first by default.\n * @param options - the caller's graphIndex / graphName\n * @returns true when either option is set\n * @category Writing a format\n */\nexport function graphChosen(options: GraphChoiceOptions | undefined): boolean {\n return options?.graphIndex !== undefined || options?.graphName !== undefined;\n}\n\n/**\n * The graphs of an input as an E_GRAPH_NOT_FOUND message lists them: their indexes and names, so the\n * caller can choose without a second call.\n * @param names - each graph's name, null for an unnamed graph\n * @returns the text to append, starting with \"; \"\n */\nfunction graphNamesText(names: readonly (string | null)[]): string {\n const shown = names.slice(0, 10).map((n, i) => `${i} ${n === null ? \"(unnamed)\" : JSON.stringify(n)}`);\n const more = names.length > shown.length ? `, and ${names.length - shown.length} more` : \"\";\n return `; the file holds ${shown.join(\", \")}${more}`;\n}\n\n/**\n * The graph an importer reads from an input that holds several: the one `graphIndex` or\n * `graphName` names, else the first. A choice that names no graph is E_GRAPH_NOT_FOUND, a name two\n * graphs share is E_AMBIGUOUS_GRAPH_NAME, and an input with no graph at all is E_NO_GRAPH, each\n * fatal (the report fails with ImportError).\n * @param names - each graph's name (null for an unnamed graph), in document order\n * @param options - the caller's graphIndex / graphName\n * @param report - the report a failure is recorded in\n * @returns the index of the graph to read; E_UNSUPPORTED for an option of the wrong type, or both\n * @category Writing a format\n */\nexport function chooseGraph(\n names: readonly (string | null)[],\n options: GraphChoiceOptions | undefined,\n report: ImportReportBuilder,\n): number {\n const { graphIndex, graphName } = options ?? {};\n if (\n graphIndex !== undefined &&\n (typeof graphIndex !== \"number\" || !Number.isInteger(graphIndex) || graphIndex < 0)\n ) {\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n `option graphIndex: ${describe(graphIndex)} is not a non-negative integer`,\n {\n option: \"graphIndex\",\n found: graphIndex,\n },\n );\n }\n if (graphName !== undefined && typeof graphName !== \"string\") {\n throw new GraphFormatError(\"E_UNSUPPORTED\", `option graphName: ${describe(graphName)} is not a string`, {\n option: \"graphName\",\n found: graphName,\n });\n }\n if (graphIndex !== undefined && graphName !== undefined) {\n throw new GraphFormatError(\"E_UNSUPPORTED\", \"options graphIndex and graphName both choose a graph; pass one\", {\n option: \"graphName\",\n found: graphName,\n });\n }\n if (names.length === 0) {\n return report.fail(NO_GRAPH_CODE, \"the input holds no graph\");\n }\n if (graphName !== undefined) {\n const matches = names.flatMap((name, i) => (name === graphName ? [i] : []));\n if (matches.length > 1) {\n return report.fail(\n AMBIGUOUS_GRAPH_NAME_CODE,\n `graphName ${JSON.stringify(graphName)} names the graphs at indexes ${matches.join(\", \")}; pass graphIndex`,\n { element: graphName },\n );\n }\n if (matches.length === 0) {\n return report.fail(\n GRAPH_NOT_FOUND_CODE,\n `graphName ${JSON.stringify(graphName)} names none of the ${names.length} graph${plural(names.length)}${graphNamesText(names)}`,\n { element: graphName },\n { names: [...names] },\n );\n }\n return matches[0];\n }\n const index = graphIndex ?? 0;\n if (index >= names.length) {\n return report.fail(\n GRAPH_NOT_FOUND_CODE,\n `graphIndex ${index} is beyond the ${names.length} graph${plural(names.length)}${graphNamesText(names)}`,\n );\n }\n return index;\n}\n\n/**\n * Apply the documented defaults to an importer's common options and check every enum\n * value. Format-specific options in the same object are ignored here.\n * @param options - the caller's options, possibly undefined\n * @param defaults - the importer's per-format defaults\n * @returns the resolved options; E_UNSUPPORTED for a value outside its set\n * @category Writing a format\n */\nexport function resolveImportOptions(\n options: CommonImportOptions | undefined,\n defaults: ImportFormatDefaults,\n): ResolvedImportOptions {\n const o: CommonImportOptions = options ?? {};\n return Object.freeze({\n ids: enumOption(\"ids\", o.ids, defaults.ids, ID_COERCIONS),\n nodeIdFrom: enumOption(\"nodeIdFrom\", o.nodeIdFrom, \"id\", NODE_ID_SOURCES),\n addMissingNodes: booleanOption(\"addMissingNodes\", o.addMissingNodes, defaults.addMissingNodes ?? true),\n duplicateEdges: enumOption(\"duplicateEdges\", o.duplicateEdges, \"keep\", DUPLICATE_POLICIES),\n selfLoops: enumOption(\"selfLoops\", o.selfLoops, \"keep\", SELF_LOOP_POLICIES),\n onMixedDirection: enumOption(\"onMixedDirection\", o.onMixedDirection, \"expand\", IMPORT_MIXED_POLICIES),\n defaultDirected: booleanOption(\"defaultDirected\", o.defaultDirected, defaults.defaultDirected),\n weightFrom: weightFromOption(o.weightFrom, defaults.weightFrom),\n weightDtype: enumOption(\"weightDtype\", o.weightDtype, \"f64\", WEIGHT_DTYPES),\n long: enumOption(\"long\", o.long, \"f64\", LONG_MODES),\n restoreMangledIds: booleanOption(\"restoreMangledIds\", o.restoreMangledIds, true),\n hyperedges: enumOption(\"hyperedges\", o.hyperedges, \"skip\", HYPEREDGE_POLICIES),\n errorLimit: errorLimitOption(o.errorLimit),\n signal: signalOption(o.signal),\n onProgress: progressOption(o.onProgress),\n encoding: encodingOption(o.encoding),\n });\n}\n\n/**\n * Apply the documented defaults to an exporter's common options and check the enum values.\n * @param options - the caller's options, possibly undefined\n * @returns the resolved options; E_UNSUPPORTED for a value outside its set\n * @category Writing a format\n */\nexport function resolveExportOptions(options: CommonExportOptions | undefined): ResolvedExportOptions {\n const o: CommonExportOptions = options ?? {};\n return Object.freeze({\n sanitizeIds: enumOption(\"sanitizeIds\", o.sanitizeIds, \"error\", SANITIZE_MODES),\n onMixedDirection: enumOption(\"onMixedDirection\", o.onMixedDirection, \"error\", EXPORT_MIXED_POLICIES),\n });\n}\n\n/**\n * Resolve one enum-valued option.\n * @param name - the option name, for the error\n * @param value - the caller's value\n * @param fallback - the default\n * @param allowed - the accepted values\n * @returns the value or the default; E_UNSUPPORTED when outside the set\n */\nfunction enumOption<T extends string>(name: string, value: unknown, fallback: T, allowed: ReadonlySet<string>): T {\n if (value === undefined) {\n return fallback;\n }\n if (typeof value !== \"string\" || !allowed.has(value)) {\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n `option ${name}: ${describe(value)} is not one of ${list(allowed)}`,\n {\n option: name,\n found: value,\n supported: [...allowed],\n },\n );\n }\n return value as T;\n}\n\n/**\n * Resolve one boolean option.\n * @param name - the option name, for the error\n * @param value - the caller's value\n * @param fallback - the default\n * @returns the value or the default; E_UNSUPPORTED when not a boolean\n */\nfunction booleanOption(name: string, value: unknown, fallback: boolean): boolean {\n if (value === undefined) {\n return fallback;\n }\n if (typeof value !== \"boolean\") {\n throw new GraphFormatError(\"E_UNSUPPORTED\", `option ${name}: ${describe(value)} is not a boolean`, {\n option: name,\n found: value,\n });\n }\n return value;\n}\n\n/**\n * Resolve the weightFrom option: a non-empty attribute name, null for unweighted, or the format default.\n * @param value - the caller's value\n * @param fallback - the format default\n * @returns the resolved value; E_UNSUPPORTED for anything else\n */\nfunction weightFromOption(value: unknown, fallback: string | null): string | null {\n if (value === undefined) {\n return fallback;\n }\n if (value === null || (typeof value === \"string\" && value.length > 0)) {\n return value;\n }\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n `option weightFrom: ${describe(value)} is not an attribute name or null`,\n { option: \"weightFrom\", found: value },\n );\n}\n\n/**\n * Resolve the error limit: a non-negative integer or Infinity.\n * @param value - the caller's value\n * @returns the limit or the default\n */\nfunction errorLimitOption(value: unknown): number {\n if (value === undefined) {\n return DEFAULT_ERROR_LIMIT;\n }\n if (typeof value === \"number\" && value >= 0 && (Number.isInteger(value) || value === Infinity)) {\n return value;\n }\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n `option errorLimit: ${describe(value)} is not a non-negative integer or Infinity`,\n { option: \"errorLimit\", found: value },\n );\n}\n\n/**\n * Resolve the signal option by duck type, so a signal from another realm is accepted.\n * @param value - the caller's value\n * @returns the signal or null\n */\nfunction signalOption(value: unknown): AbortSignal | null {\n if (value === undefined || value === null) {\n return null;\n }\n if (typeof value === \"object\" && typeof (value as { aborted?: unknown }).aborted === \"boolean\") {\n return value as AbortSignal;\n }\n throw new GraphFormatError(\"E_UNSUPPORTED\", `option signal: ${describe(value)} is not an AbortSignal`, {\n option: \"signal\",\n found: typeof value,\n });\n}\n\n/**\n * Resolve the progress callback option.\n * @param value - the caller's value\n * @returns the callback or null\n */\nfunction progressOption(value: unknown): ((bytesDone: number, bytesTotal?: number) => void) | null {\n if (value === undefined || value === null) {\n return null;\n }\n if (typeof value === \"function\") {\n return value as (bytesDone: number, bytesTotal?: number) => void;\n }\n throw new GraphFormatError(\"E_UNSUPPORTED\", `option onProgress: ${describe(value)} is not a function`, {\n option: \"onProgress\",\n found: typeof value,\n });\n}\n\n/**\n * Resolve the encoding option: a label the platform's TextDecoder knows.\n * @param value - the caller's value\n * @returns the canonical encoding name, or null for detection\n */\nfunction encodingOption(value: unknown): string | null {\n if (value === undefined || value === null) {\n return null;\n }\n const canonical = typeof value === \"string\" ? canonicalEncoding(value) : null;\n if (canonical === null) {\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n `option encoding: ${describe(value)} is not an encoding this platform's TextDecoder knows`,\n { option: \"encoding\", found: value },\n );\n }\n return canonical;\n}\n\n/**\n * The options to pass to another importer that you hand text you already decoded with readText():\n * the caller's options without `encoding` and `onProgress`, which that text no longer needs. Without\n * this, the other importer would warn that `encoding` has no effect on text, and report progress a\n * second time.\n * @example\n * ```ts\n * const text = await readText(input, report, opts);\n * report.include(await csvImporter.import(text, sink, forDecodedText(options)));\n * ```\n * @param options - the caller's import options\n * @returns a copy without `encoding` and `onProgress`\n * @category Writing a format\n */\nexport function forDecodedText<O extends CommonImportOptions>(options: O | undefined): O {\n return { ...options, encoding: undefined, onProgress: undefined } as O;\n}\n\n/**\n * The dialect names of the built-in formats with a `dialect` save option. One options object shared between formats\n * can hold one format's dialect, and the other formats ignore it, as they ignore any option they do not have.\n */\nexport const FORMAT_DIALECTS: Readonly<Record<string, readonly string[]>> = Object.freeze({\n csv: Object.freeze([\"gephi\", \"generic\"]),\n json: Object.freeze([\"node-link\", \"d3\", \"jgf\", \"cytoscape\", \"graphology\", \"vis\", \"obographs\"]),\n});\n\n/**\n * Whether a `dialect` value names another format's dialect, which this format ignores rather than refuses.\n * @param format - this format\n * @param value - the caller's `dialect` option\n * @returns true for another built-in format's dialect name\n */\nexport function otherFormatDialect(format: string, value: unknown): boolean {\n return (\n typeof value === \"string\" &&\n Object.entries(FORMAT_DIALECTS).some(([f, names]) => f !== format && names.includes(value))\n );\n}\n\n/**\n * A short description of an option value for an error message.\n * @param value - the value\n * @returns the JSON text of a primitive, or the type name otherwise\n * @category Plugin helpers\n */\nexport function describe(value: unknown): string {\n switch (typeof value) {\n case \"string\":\n return JSON.stringify(value);\n case \"number\":\n case \"boolean\":\n return String(value);\n default:\n return value === null ? \"null\" : typeof value;\n }\n}\n\n/**\n * The accepted values of an enum option, for an error message.\n * @param allowed - the set\n * @returns the quoted values joined by commas\n */\nfunction list(allowed: ReadonlySet<string>): string {\n return [...allowed].map((v) => JSON.stringify(v)).join(\", \");\n}\n","/**\n * Weight resolution shared by every importer (design sections 3.7 and 8.4): which source field is\n * THE weight (`weightFrom`, per-format default, null = unweighted), how its text or JSON value\n * becomes the number passed to `addEdge`, and the E_INVALID_WEIGHT boundary.\n *\n * An edge whose weight field is absent or blank is pushed WITHOUT a weight argument, never with an\n * explicit 1: the builder's weightSet bitmap then records that the weight was defaulted, and the\n * exporter re-emits no weight for it (decision D-WSET). NaN and non-numeric text are\n * E_INVALID_WEIGHT before the sink is touched, so the importer records the issue and skips the edge\n * with the sink unchanged; Infinity and negative values are legal weights (design section 3.7).\n */\n\nimport { type Column, GraphFormatError, type GraphSnapshot } from \"@graphty/graph-format\";\n\nimport { PRECISION_CODE } from \"./codes.js\";\nimport { parseDecimalText } from \"./declared-types.js\";\nimport { formatF32, formatF64, formatInteger } from \"./format.js\";\nimport { type ImportReportBuilder } from \"./report.js\";\n\n/**\n * The weight of an edge added without one (design section 3.7).\n * @category Plugin helpers\n */\nexport const DEFAULT_WEIGHT = 1;\n\n/**\n * Whether a source field is the weight field under the resolved `weightFrom` option.\n * @param name - the field name (attribute title, CSV header, JSON key)\n * @param weightFrom - the resolved option; null means unweighted\n * @returns true when the field is THE weight\n * @category Plugin helpers\n */\nexport function isWeightField(name: string, weightFrom: string | null): boolean {\n return weightFrom !== null && name === weightFrom;\n}\n\n/**\n * The weight argument of addEdge from a text cell: undefined for a blank cell (the weight is\n * omitted), the number otherwise.\n * @param text - the cell text\n * @param report - the import report; when given, an integer beyond 2^53 that the nearest double\n * changes is reported once as W_PRECISION\n * @returns the weight, or undefined when blank; E_INVALID_WEIGHT for NaN or non-numeric text\n * @category Writing a format\n */\nexport function parseWeightText(text: string, report?: ImportReportBuilder): number | undefined {\n const trimmed = text.trim();\n if (trimmed.length === 0) {\n return undefined;\n }\n let value: number;\n try {\n value = parseDecimalText(trimmed);\n } catch (err) {\n throw invalidWeight(text, err);\n }\n if (Number.isNaN(value)) {\n throw invalidWeight(text, null);\n }\n if (report !== undefined) {\n reportWeightPrecision(trimmed, value, report);\n }\n return value;\n}\n\n/**\n * Report once (W_PRECISION) an integer weight beyond 2^53 that the nearest double changes, which\n * the weights and the exact `graphty.weight` column would otherwise hold silently.\n * @param text - the weight as written in the file\n * @param value - the number it was read as\n * @param report - the import report\n */\nexport function reportWeightPrecision(text: string, value: number, report: ImportReportBuilder): void {\n if (\n !Number.isSafeInteger(value) &&\n Number.isFinite(value) &&\n /^[+-]?\\d+$/.test(text) &&\n BigInt(text) !== BigInt(value)\n ) {\n report.warnOnce(\n \"precision\",\n PRECISION_CODE,\n `edge weights: integers beyond 2^53 are stored as the nearest double (first: ${text})`,\n undefined,\n `${PRECISION_CODE}:edge weight`,\n );\n }\n}\n\n/**\n * The weight argument of addEdge from a typed value (JSON, a record field): undefined for null /\n * undefined, the number for a finite or infinite number, the parsed number for numeric text.\n * @param value - the field value\n * @returns the weight, or undefined when absent; E_INVALID_WEIGHT for NaN, a boolean, an object or non-numeric text\n * @category Plugin helpers\n */\nexport function weightFromValue(value: unknown): number | undefined {\n if (value === undefined || value === null) {\n return undefined;\n }\n if (typeof value === \"number\") {\n if (Number.isNaN(value)) {\n throw invalidWeight(value, null);\n }\n return value;\n }\n if (typeof value === \"string\") {\n return parseWeightText(value);\n }\n throw invalidWeight(value, null);\n}\n\n/**\n * The E_INVALID_WEIGHT error of a rejected value.\n * @param value - the rejected value\n * @param cause - the parse error, or null\n * @returns the error\n */\nfunction invalidWeight(value: unknown, cause: unknown): GraphFormatError {\n let shown: string;\n switch (typeof value) {\n case \"string\":\n shown = JSON.stringify(value);\n break;\n case \"number\":\n shown = String(value);\n break;\n default:\n shown = typeof value;\n }\n return new GraphFormatError(\"E_INVALID_WEIGHT\", `invalid edge weight ${shown}`, {\n value: typeof value === \"object\" ? typeof value : value,\n cause: cause instanceof Error ? cause.message : null,\n });\n}\n\n// ============================================================ the exporter side\n\n/**\n * The explicit weights of a snapshot for exporters: the weight\n * role column when present (its validity says which edges had an explicit weight, its dtype how\n * the value is written), else `edgeList().weights` as f32 for every edge of a weighted snapshot;\n * nothing for an unweighted one. One implementation for every exporter.\n * @public\n * @category Plugin helpers\n */\nexport interface ExplicitWeights {\n /** Whether any edge can have an explicit weight (the snapshot is weighted). */\n readonly weighted: boolean;\n /** The dtype the values are read from: the shadow column's, or f32 for the arc array. */\n readonly dtype: \"f32\" | \"f64\";\n /**\n * Whether an edge's weight was explicit in the source.\n * @param e - the logical edge index\n * @returns true when the exporter must write it\n */\n isExplicit(e: number): boolean;\n /**\n * The weight value of an edge (meaningful when explicit).\n * @param e - the logical edge index\n * @returns the value\n */\n value(e: number): number;\n /**\n * The weight text of an edge: the shortest round-tripping decimal for its dtype, or the\n * integer digits when `integral` is requested and the value is an integer; null when the\n * weight was defaulted.\n * @param e - the logical edge index\n * @param integral - write an integral value without a decimal part (formats declaring an int weight)\n * @returns the text, or null\n */\n text(e: number, integral?: boolean): string | null;\n}\n\n/** A weight of -0 keeps its sign: every importer's weight grammar reads \"-0\" back as -0. */\nconst NEGATIVE_ZERO_TEXT = \"-0\";\n\n/** The dtypes a weight role column may have (an integer column declared by a caller included). */\nconst NUMERIC_DTYPES: ReadonlySet<string> = new Set([\"f32\", \"f64\", \"i32\", \"u32\", \"u8\"]);\n\n/**\n * The shortest round-tripping text of a weight by the shadow column's dtype.\n * @param dtype - the shadow column's dtype\n * @returns the formatter\n */\nfunction weightFormatter(dtype: string): (value: number) => string {\n switch (dtype) {\n case \"f32\":\n return formatF32;\n case \"f64\":\n return formatF64;\n default:\n return formatInteger;\n }\n}\n\n/**\n * Build the explicit-weight view of a snapshot.\n * @param snapshot - the snapshot\n * @returns the view\n * @category Writing a format\n */\nexport function explicitWeights(snapshot: GraphSnapshot): ExplicitWeights {\n const shadowColumn = snapshot.edges.byRole(\"weight\");\n const shadow: Column | null = shadowColumn !== null && NUMERIC_DTYPES.has(shadowColumn.dtype) ? shadowColumn : null;\n if (shadow !== null) {\n const dtype = shadow.dtype === \"f32\" ? \"f32\" : \"f64\";\n const format = weightFormatter(shadow.dtype);\n return {\n weighted: true,\n dtype,\n isExplicit: (e: number): boolean => shadow.isSet(e),\n value: (e: number): number => shadow.value(e) as number,\n text: (e: number, integral = false): string | null => {\n if (!shadow.isSet(e)) {\n return null;\n }\n const value = shadow.value(e) as number;\n if (Object.is(value, -0)) {\n return NEGATIVE_ZERO_TEXT;\n }\n return integral && Number.isInteger(value) ? formatInteger(value) : format(value);\n },\n };\n }\n const { weights } = snapshot.edgeList();\n if (weights === null || !snapshot.flags.weighted) {\n return {\n weighted: false,\n dtype: \"f32\",\n isExplicit: (): boolean => false,\n value: (): number => DEFAULT_WEIGHT,\n text: (): string | null => null,\n };\n }\n return {\n weighted: true,\n dtype: \"f32\",\n isExplicit: (): boolean => true,\n value: (e: number): number => weights[e],\n text: (e: number, integral = false): string => {\n const value = weights[e];\n if (Object.is(value, -0)) {\n return NEGATIVE_ZERO_TEXT;\n }\n return integral && Number.isInteger(value) ? formatInteger(value) : formatF32(value);\n },\n };\n}\n\n/**\n * The weight of every edge, in edge order (`weights[e]` is edge `e`'s weight), exactly as the file\n * wrote it, or null for a graph without weights. `snapshot.edgeList().weights` holds the same\n * weights as 32-bit floats, in which 0.1 reads back as 0.10000000149011612; this reads the exact\n * values the import also kept. An edge without a weight of its own has the weight 1.\n * @example\n * ```ts\n * const { snapshot } = await importGraph(\"source,target,weight\\na,b,0.1\\n\", { format: \"csv\" });\n * edgeWeights(snapshot); // Float64Array [ 0.1 ]\n * ```\n * @param snapshot - the graph\n * @returns one weight per edge, or null when the graph has no weights\n * @category Loading\n */\nexport function edgeWeights(snapshot: GraphSnapshot): Float64Array | null {\n const { weights } = snapshot.edgeList();\n if (weights === null) {\n return null;\n }\n const out = Float64Array.from(weights);\n const exact = snapshot.edges.byRole(\"weight\");\n if (exact !== null) {\n for (let e = 0; e < out.length; e++) {\n const v = exact.value(e);\n if (typeof v === \"number\") {\n out[e] = v;\n }\n }\n }\n return out;\n}\n","/**\n * The exporter-side machinery of design section 8.5: the ExportCapabilities table helper, the\n * generic check() that turns capability gaps into LossNotes with shared codes, and id sanitising\n * (`sanitizeIds: \"error\"` by default; an exporter never silently renames a node; \"mangle\" rewrites\n * the ids the format cannot hold and hands the exporter the originals to write into its\n * `graphty:originalId` attribute).\n *\n * Every exporter's check() calls checkCapabilities() first and appends its format-specific notes;\n * export() calls\n * sanitizeIds() before writing anything.\n */\n\nimport {\n type Column,\n type Dtype,\n GraphFormatError,\n type GraphSnapshot,\n type IdCoercion,\n INVALID_INDEX,\n type NodeId,\n} from \"@graphty/graph-format\";\n\nimport { type ExportCapabilities, type LossNote } from \"../types.js\";\nimport {\n COLUMN_DROPPED_CODE,\n COLUMN_RENAMED_LOSS_CODE,\n EMPTY_COLUMN_DROPPED_CODE,\n ID_TEXT_COLLISION_CODE,\n ID_TEXT_TYPE_CODE,\n INTEGRAL_F64_CODE,\n MIXED_DIRECTION_CODE,\n MUTUAL_AS_UNDIRECTED_CODE,\n MUTUAL_EXPANDED_CODE,\n NONFINITE_AS_NULL_CODE,\n OPTIONS_GAINED_CODE,\n PARENTS_DROPPED_CODE,\n ROLE_ASSUMED_CODE,\n ROLE_DROPPED_CODE,\n STORAGE_CLASS_CODE,\n TEMPORAL_DROPPED_CODE,\n TEMPORAL_TEXT_DROPPED_CODE,\n TEXT_INFERRED_CODE,\n WEIGHT_KEY_CLASH_CODE,\n WEIGHTS_DROPPED_CODE,\n XML_ILLEGAL_CHAR_CODE,\n} from \"./codes.js\";\nimport { coerceIdText } from \"./ids.js\";\nimport { type ResolvedExportOptions } from \"./options.js\";\nimport { agree, plural } from \"./plural.js\";\nimport { explicitWeights } from \"./weights.js\";\n\n/** The code of node ids the format cannot write under `sanitizeIds: \"error\"`. */\nconst ID_CHARSET_REFUSAL = \"E_ID_CHARSET\";\n\n/**\n * The shared LossNote codes of checkCapabilities().\n * @category Issue and loss codes\n */\nexport const LOSS = Object.freeze({\n /**\n * A node or edge attribute is not written: the format has no attributes, or none of this kind\n * (`CheckExtras.attributes` false).\n */\n COLUMN_DROPPED: COLUMN_DROPPED_CODE,\n /**\n * The graph has both directed and undirected edges, the format holds one direction per file, and\n * `onMixedDirection` is \"directed\" or \"undirected\": every edge is written with that direction.\n */\n MIXED_DIRECTION: \"W_MIXED_DIRECTION\",\n /**\n * The graph has both directed and undirected edges and `onMixedDirection` is \"error\". An import stops; a save to a\n * format that holds one direction per file fails with E_DIRECTED. Pass \"directed\" or \"undirected\" to read or write\n * it anyway.\n */\n MIXED_DIRECTION_ERROR: MIXED_DIRECTION_CODE,\n /** Parallel edges in a format without them. */\n MULTI_EDGES: \"W_MULTI_EDGES\",\n /** Self-loops in a format without them. */\n SELF_LOOPS: \"W_SELF_LOOPS\",\n /**\n * The format needs an id on every edge and the graph has none, so the file gets ids e0, e1, e2 and so on, which\n * read back as edge ids.\n */\n EDGE_IDS_GENERATED: \"W_EDGE_IDS_GENERATED\",\n /** The graph has edge ids and the format has no place for them, so they are not written. */\n EDGE_IDS_DROPPED: \"W_EDGE_IDS_DROPPED\",\n /** Ids outside the format's charset are rewritten (sanitizeIds \"mangle\"). */\n ID_MANGLED: \"W_ID_MANGLED\",\n /**\n * Node ids the format cannot write, under `sanitizeIds: \"error\"`; the save fails with E_INVALID_ID. Pass\n * `sanitizeIds: \"mangle\"` to rewrite them.\n */\n ID_CHARSET: ID_CHARSET_REFUSAL,\n /** The format numbers nodes 1..N; ids that are not their 1-based index are kept as labels only. */\n ID_RENUMBERED: \"W_ID_RENUMBERED\",\n /**\n * An attribute's type is one the format cannot store as it is (for example, a 32-bit float in a format that has only 64-bit\n * numbers), so it reads back with the nearest type the format has.\n */\n DTYPE: \"W_DTYPE_UNSUPPORTED\",\n /**\n * An attribute with several numbers per element (other than a position) is written as separate values or a list,\n * and does not read back as one attribute.\n */\n COMPONENTS: \"W_COMPONENTS_FLATTENED\",\n /** A list column in a format without lists. */\n LIST: \"W_LIST_UNSUPPORTED\",\n /** A json column in a format without nested values. */\n JSON: \"W_JSON_UNSUPPORTED\",\n /** A declared default in a format without defaults. */\n DEFAULT: \"W_DEFAULT_DROPPED\",\n /** Declared options in a format without enumerations. */\n OPTIONS: \"W_OPTIONS_DROPPED\",\n /** A parent / parents column in a format without containment. */\n HIERARCHY: \"W_HIERARCHY_DROPPED\",\n /** A start / end / timestamp column in a format without temporal support. */\n TEMPORAL: TEMPORAL_DROPPED_CODE,\n /** A `<column>.text` companion the format cannot carry. */\n TEMPORAL_TEXT: TEMPORAL_TEXT_DROPPED_CODE,\n /** An attribute with a role the format has no place for is written as a plain attribute; the role is lost. */\n ROLE: ROLE_DROPPED_CODE,\n /** A parents (multi-parent) column in a format with single containment only. */\n PARENTS: PARENTS_DROPPED_CODE,\n /** A mutual pair written as two directed edges without the mutual mark. */\n MUTUAL_EXPANDED: MUTUAL_EXPANDED_CODE,\n /** A mutual pair written as one undirected edge; the mark is lost and the pair reads back undirected. */\n MUTUAL_AS_UNDIRECTED: MUTUAL_AS_UNDIRECTED_CODE,\n /** Node ids whose written text reads back as the other type under the importer's id rule. */\n ID_TEXT_TYPE: ID_TEXT_TYPE_CODE,\n /**\n * Two node ids would be written as the same text (the number 5 and the text \"5\"); the save fails with\n * E_INVALID_ID.\n */\n ID_TEXT_COLLISION: ID_TEXT_COLLISION_CODE,\n /**\n * An attribute without the weight role is named like the attribute graph-io reads weights from (for example, `weight`), so\n * it reads back as the edge weight.\n */\n WEIGHT_KEY_CLASH: WEIGHT_KEY_CLASH_CODE,\n /**\n * An attribute without a role is written where the format keeps a role (for example, a `name` column as the label), and\n * reads back with that role.\n */\n ROLE_ASSUMED: ROLE_ASSUMED_CODE,\n /**\n * An attribute with a role (for example, the label) is written where the format keeps that role, and reads back under the\n * name the format's importer gives it.\n */\n COLUMN_NAME_CHANGED: COLUMN_RENAMED_LOSS_CODE,\n /** A declared column whose every row is unset vanishes through a format without declarations. */\n EMPTY_COLUMN: EMPTY_COLUMN_DROPPED_CODE,\n /**\n * A text attribute reads back as a dictionary attribute, or the reverse, because the importer chooses by how often\n * its values repeat. The values are the same.\n */\n STORAGE_CLASS: STORAGE_CLASS_CODE,\n /**\n * A number attribute whose values are all whole numbers reads back as integers, because the format does not record\n * the type.\n */\n INTEGRAL_F64: INTEGRAL_F64_CODE,\n /**\n * A text value that reads back as a number or a boolean, because the format does not record that it was text (the\n * text \"42\" reads back as the number 42).\n */\n TEXT_INFERRED: TEXT_INFERRED_CODE,\n /** A text value holds a character XML 1.0 forbids (most control characters); the save fails with E_COLUMN_TYPE. */\n XML_ILLEGAL_CHAR: XML_ILLEGAL_CHAR_CODE,\n /**\n * A text attribute stored as a dictionary, without a declared list of allowed values, reads back with its distinct\n * values as that list.\n */\n OPTIONS_GAINED: OPTIONS_GAINED_CODE,\n /** A spells column in a format without spells. */\n SPELLS: \"W_SPELLS_DROPPED\",\n /** Dynamic attribute values (extension tables) in a format without them. */\n DYNAMIC_VALUES: \"W_DYNAMIC_VALUES_DROPPED\",\n /** An open-interval column in a format without open intervals. */\n OPEN_INTERVAL: \"W_OPEN_INTERVAL\",\n /** Graph-level attributes in a format without them. */\n GRAPH_ATTRIBUTES: \"W_GRAPH_ATTRIBUTES_DROPPED\",\n /** A position column in a format without positions. */\n POSITIONS: \"W_POSITIONS_DROPPED\",\n /** Visual columns in a format without them. */\n VIZ: \"W_VIZ_DROPPED\",\n /** An extension table the format cannot carry. */\n EXTENSION_TABLE: \"W_EXTENSION_TABLE_DROPPED\",\n /** A NaN or infinite number the format cannot spell; not written (or written as null), it reads back unset. */\n NONFINITE_AS_NULL: NONFINITE_AS_NULL_CODE,\n /**\n * The graph has edge weights and the file does not keep them (the format has no weights, or an option turned them\n * off): every edge reads back with the default weight 1.\n */\n WEIGHTS_DROPPED: WEIGHTS_DROPPED_CODE,\n});\n\n/**\n * The error a save throws for the first `E_` note of a check() result, or null when there is none.\n * An exporter calls it before it writes anything, so every format refuses a save the same way: an\n * id note (E_ID_CHARSET, E_ID_TEXT_COLLISION) throws E_INVALID_ID, E_MIXED_DIRECTION throws\n * E_DIRECTED, E_XML_ILLEGAL_CHAR throws E_COLUMN_TYPE, and any other note E_UNSUPPORTED. Map your\n * own note codes onto these with `codes`. The error's `details.code` is the note's code.\n * @param notes - what check() returned\n * @param codes - the error code for each of your own note codes, such as\n * `{ E_PAIRS_BAD_ID: \"E_INVALID_ID\" }`\n * @returns the error to throw, or null\n * @category Writing a format\n */\nexport function refusedSave(\n notes: readonly LossNote[],\n codes: Readonly<Record<string, \"E_INVALID_ID\" | \"E_DIRECTED\" | \"E_COLUMN_TYPE\" | \"E_UNSUPPORTED\">> = {},\n): GraphFormatError | null {\n const note = notes.find((n) => n.code.startsWith(\"E_\"));\n if (note === undefined) {\n return null;\n }\n const code = codes[note.code] ?? REFUSAL_CODES[note.code] ?? \"E_UNSUPPORTED\";\n return new GraphFormatError(code, note.message, { code: note.code, column: note.column, count: note.count });\n}\n\n/** The error codes a refused save throws. */\ntype RefusalCode = \"E_INVALID_ID\" | \"E_DIRECTED\" | \"E_COLUMN_TYPE\" | \"E_UNSUPPORTED\";\n\n/** The error code a save throws for each shared refusal note. */\nconst REFUSAL_CODES: Readonly<Record<string, RefusalCode>> = {\n [ID_CHARSET_REFUSAL]: \"E_INVALID_ID\",\n [ID_TEXT_COLLISION_CODE]: \"E_INVALID_ID\",\n [MIXED_DIRECTION_CODE]: \"E_DIRECTED\",\n [XML_ILLEGAL_CHAR_CODE]: \"E_COLUMN_TYPE\",\n};\n\n/**\n * The capabilities of a format that keeps nothing beyond plain topology; the base every exporter overrides.\n * @category Plugin helpers\n */\nexport const NO_CAPABILITIES: ExportCapabilities = Object.freeze({\n mixedDirection: false,\n multiEdges: false,\n selfLoops: false,\n edgeIds: \"none\",\n idCharset: \"any\",\n dtypes: Object.freeze([]),\n components: false,\n lists: false,\n json: false,\n defaults: false,\n options: false,\n hierarchy: false,\n temporal: \"none\",\n graphAttributes: false,\n positions: false,\n viz: false,\n});\n\n/**\n * Build a capabilities table from the fields a format supports; every field left out is the\n * conservative NO_CAPABILITIES value, so an exporter states what it keeps and nothing is assumed.\n * @param supported - the fields the format supports\n * @returns a frozen table\n * @category Writing a format\n */\nexport function capabilities(supported: Partial<ExportCapabilities>): ExportCapabilities {\n return Object.freeze({ ...NO_CAPABILITIES, ...supported, dtypes: Object.freeze([...(supported.dtypes ?? [])]) });\n}\n\n/**\n * Format facts checkCapabilities() needs that the capabilities table does not carry.\n * @public\n * @category Writing a format\n */\nexport interface CheckExtras {\n /** Whether the format can write open intervals (GEXF 1.2 startopen / endopen); default false. */\n readonly openIntervals?: boolean | undefined;\n /**\n * Whether the format carries the `<column>.text` companion columns (the lexical\n * form of a temporal value); default false, and every companion is then reported as\n * W_TEMPORAL_TEXT_DROPPED.\n */\n readonly temporalText?: boolean | undefined;\n /**\n * The dtype the format's importer gives a position column; an f32 / f64 position of the other\n * dtype is reported as W_DTYPE_UNSUPPORTED because its values differ at the other precision.\n * Undefined skips the check.\n */\n readonly positionDtype?: Dtype | undefined;\n /**\n * The roles beyond the structural, position, viz, hierarchy and temporal ones that the format\n * has a slot for (`label`, `kind`, `labels`, `idSpace`, `sourcePort`, `targetPort`, ...); a\n * column with any other role is written as a plain attribute and reported as W_ROLE_DROPPED.\n * Defaults to none.\n */\n readonly roles?: ReadonlySet<string> | undefined;\n /**\n * Roles the format writes into a fixed slot whose importer reads them back under a fixed name;\n * a role column named otherwise is reported as W_COLUMN_NAME_CHANGED (role -> the name the\n * importer gives it). Defaults to none. `nodeRoleNames` and `edgeRoleNames` override it for one\n * kind, for a format whose slot exists for nodes only (or edges only).\n */\n readonly roleNames?: Readonly<Record<string, string>> | undefined;\n /** Like `roleNames`, for node columns only. */\n readonly nodeRoleNames?: Readonly<Record<string, string>> | undefined;\n /** Like `roleNames`, for edge columns only: `{}` for a format with no edge slot for any role. */\n readonly edgeRoleNames?: Readonly<Record<string, string>> | undefined;\n /**\n * False for a format that writes no node or edge attributes except the ones whose role is in\n * `roles`: every other attribute column is reported once as W_COLUMN_DROPPED, instead of the\n * type and role notes a written column gets. Default true. `nodeAttributes` and\n * `edgeAttributes` override it for one kind.\n */\n readonly attributes?: boolean | undefined;\n /** Like `attributes`, for node attributes only: false for a format that writes no node attributes. */\n readonly nodeAttributes?: boolean | undefined;\n /** Like `attributes`, for edge attributes only: false for a format that writes no edge attributes. */\n readonly edgeAttributes?: boolean | undefined;\n /**\n * Columns the format writes although it writes no other attributes: a column a format option\n * names, such as an edge label column. Keyed by `node` or `edge`. They get no W_COLUMN_DROPPED\n * note; the type notes of a written column still apply.\n */\n readonly writtenColumns?: Readonly<Partial<Record<\"node\" | \"edge\", readonly string[]>>> | undefined;\n /**\n * False for a format (or an option) that writes no edge weights: a weighted graph gets one\n * W_WEIGHTS_DROPPED note. Default true.\n */\n readonly weights?: boolean | undefined;\n /**\n * The tables the export writes, of \"node\", \"edge\" and \"graph\"; a gap in a table it does not\n * write is not a loss of this export and gets no note. Default all three. A CSV node table is\n * `[\"node\"]`, so its notes are about node ids and node columns only.\n */\n readonly tables?: readonly (\"node\" | \"edge\" | \"graph\")[] | undefined;\n /**\n * How the format's importer turns id text back into ids (\"canonical\" for most text formats), so\n * an id that comes back with another type (the text \"7\" as the number 7) is reported as\n * W_ID_TEXT_TYPE. Omit it when the format records each id's type.\n */\n readonly idsReadBack?: IdCoercion | undefined;\n /**\n * True for a format that writes a column with the role `color`, `size`, `shape` or `thickness` as a plain\n * attribute when it has no slot for it: its W_VIZ_DROPPED note then says the value is kept and the role is lost.\n * Default false: the note says the column cannot be written.\n *\n * Deprecated behavior, kept unchanged until the next major version: a writer that stores a role column as a plain\n * attribute (JSON, Neo4j CSV) keeps writing it that way. Styles reach a file through the style writer\n * (`ExportOptions.styles`); in the next major version role columns are written only into a format's style slots.\n */\n readonly vizAsAttributes?: boolean | undefined;\n}\n\n/**\n * The deprecated `ExportCapabilities.viz` fact, read only by the deprecated role-column notes below, which are what it\n * describes.\n */\ninterface RoleSlots {\n readonly viz: boolean;\n}\n\n/** The roles checkCapabilities() treats structurally rather than as attribute columns. */\nconst STRUCTURAL_ROLES: ReadonlySet<string> = new Set([\"directed\", \"pair\", \"mutual\", \"weight\", \"originalId\"]);\nconst VIZ_ROLES: ReadonlySet<string> = new Set([\"color\", \"size\", \"shape\", \"thickness\"]);\nconst TEMPORAL_ROLES: ReadonlySet<string> = new Set([\"start\", \"end\", \"timestamp\", \"timestamps\"]);\nconst HIERARCHY_ROLES: ReadonlySet<string> = new Set([\"parent\", \"parents\"]);\n\n/**\n * The generic pre-flight check: compare a snapshot with a format's capabilities\n * and return one LossNote per gap, with the shared codes of LOSS. Format-specific notes are the\n * exporter's to append.\n * @param snapshot - the snapshot about to be exported\n * @param caps - the exporter's capabilities\n * @param options - the resolved common export options\n * @param extras - format facts the capabilities table does not carry\n * @returns the notes, empty when the export is exact\n * @category Writing a format\n */\nexport function checkCapabilities(\n snapshot: GraphSnapshot,\n caps: ExportCapabilities,\n options: ResolvedExportOptions,\n extras: CheckExtras = {},\n): LossNote[] {\n const notes: LossNote[] = [];\n const note = (code: string, message: string, column: string | null = null, count: number | null = null): void => {\n notes.push(Object.freeze({ code, message, column, count }));\n };\n const tables = extras.tables ?? [\"node\", \"edge\", \"graph\"];\n const edges = tables.includes(\"edge\");\n\n if (edges) {\n checkEdgeStructure(snapshot, caps, options, note);\n }\n\n const unrepresentable = countUnrepresentableIds(snapshot, caps.idCharset);\n if (unrepresentable > 0) {\n if (caps.idCharset === \"dense-1-based\") {\n note(\n LOSS.ID_RENUMBERED,\n options.sanitizeIds === \"mangle\"\n ? `${unrepresentable} node id${plural(unrepresentable)} ${agree(unrepresentable, \"is\", \"are\")} not their 1-based index; nodes are numbered 1..N, the original ids are written too, and an import with restoreMangledIds: true reads them back as the ids; they are also the labels of nodes without a label value`\n : `${unrepresentable} node id${plural(unrepresentable)} ${agree(unrepresentable, \"is\", \"are\")} not their 1-based index; nodes are numbered 1..N and ids kept as labels of the nodes without a label value (a node with one loses its id)`,\n null,\n unrepresentable,\n );\n } else if (options.sanitizeIds === \"mangle\") {\n note(\n LOSS.ID_MANGLED,\n `${unrepresentable} node id${plural(unrepresentable)} ${charsetText(caps.idCharset, unrepresentable)}, so they are rewritten; the original ids are written too, and an import with restoreMangledIds: true reads them back`,\n null,\n unrepresentable,\n );\n } else {\n note(\n LOSS.ID_CHARSET,\n `${unrepresentable} node id${plural(unrepresentable)} ${charsetText(caps.idCharset, unrepresentable)}, so the save fails unless sanitizeIds is \"mangle\"`,\n null,\n unrepresentable,\n );\n }\n }\n\n if (extras.idsReadBack !== undefined) {\n let retyped = 0;\n for (let i = 0; i < snapshot.nodeCount; i++) {\n const id = snapshot.ids.idOf(i);\n if (coerceIdText(String(id), extras.idsReadBack) !== id) {\n retyped++;\n }\n }\n if (retyped > 0) {\n note(\n LOSS.ID_TEXT_TYPE,\n `${retyped} node id${plural(retyped)} ${agree(retyped, \"reads\", \"read\")} back with another type (a number as text, or text as a number)`,\n null,\n retyped,\n );\n }\n }\n\n if (edges) {\n checkWeights(snapshot, extras, note);\n }\n if (tables.includes(\"node\")) {\n checkColumns(snapshot.nodes, \"node\", caps, extras, note);\n }\n if (edges) {\n checkColumns(snapshot.edges, \"edge\", caps, extras, note);\n }\n const graphColumns = tables.includes(\"graph\") ? snapshot.graph.names() : [];\n if (graphColumns.length > 0) {\n if (caps.graphAttributes) {\n checkColumns(snapshot.graph, \"graph\", caps, extras, note);\n } else {\n notes.push(\n Object.freeze({\n code: LOSS.GRAPH_ATTRIBUTES,\n message: `${graphColumns.length} graph attribute${plural(graphColumns.length)} cannot be written`,\n column: null,\n count: graphColumns.length,\n columns: Object.freeze([...graphColumns]),\n }),\n );\n }\n }\n\n for (const [name, table] of snapshot.extensions) {\n // \"temporal:node:<column>\" is the node table's, \"temporal:edge:<column>\" the edge table's;\n // any other extension table is the graph's.\n const [, kind] = name.split(\":\");\n const owner = name.startsWith(\"temporal:\") && (kind === \"node\" || kind === \"edge\") ? kind : \"graph\";\n if (!tables.includes(owner)) {\n continue;\n }\n if (name.startsWith(\"temporal:\")) {\n if (caps.temporal !== \"dynamic-values\") {\n note(\n LOSS.DYNAMIC_VALUES,\n `dynamic values of \"${name}\" (${table.rowCount} row${plural(table.rowCount)}) cannot be written`,\n name,\n table.rowCount,\n );\n }\n } else {\n note(\n LOSS.EXTENSION_TABLE,\n `extension table \"${name}\" (${table.rowCount} row${plural(table.rowCount)}) cannot be written`,\n name,\n table.rowCount,\n );\n }\n }\n return notes;\n}\n\n/**\n * The edge-structure checks of checkCapabilities(): direction, parallel edges, self-loops and\n * edge ids. Skipped for an export that writes no edge table.\n * @param snapshot - the snapshot about to be exported\n * @param caps - the exporter's capabilities\n * @param options - the resolved common export options\n * @param note - the recorder\n */\nfunction checkEdgeStructure(\n snapshot: GraphSnapshot,\n caps: ExportCapabilities,\n options: ResolvedExportOptions,\n note: NoteFn,\n): void {\n // mixed direction (design section 3.6): an expanded snapshot carries the pair / directed roles\n const mixed = countMixedEdges(snapshot);\n if (mixed > 0 && !caps.mixedDirection) {\n if (options.onMixedDirection === \"error\") {\n note(\n LOSS.MIXED_DIRECTION_ERROR,\n `${mixed} undirected edge${plural(mixed)} in a directed graph, and the format holds one direction per file, so the save fails unless onMixedDirection is \"directed\" or \"undirected\"`,\n null,\n mixed,\n );\n } else {\n note(\n LOSS.MIXED_DIRECTION,\n `${mixed} undirected edge${plural(mixed)} in a directed graph ${agree(mixed, \"is\", \"are\")} written as ${options.onMixedDirection} (onMixedDirection), and the format holds one direction per file`,\n null,\n mixed,\n );\n }\n }\n\n if (snapshot.flags.multigraph && !caps.multiEdges) {\n const parallel = countParallelArcs(snapshot);\n note(\n LOSS.MULTI_EDGES,\n `${parallel} parallel edge${plural(parallel)}; the format has no parallel edges`,\n null,\n parallel,\n );\n }\n if (snapshot.selfLoopCount > 0 && !caps.selfLoops) {\n note(\n LOSS.SELF_LOOPS,\n `${snapshot.selfLoopCount} self-loop${plural(snapshot.selfLoopCount)}; the format has no self-loops`,\n null,\n snapshot.selfLoopCount,\n );\n }\n\n const edgeIds = snapshot.edges.byRole(\"id\");\n if (caps.edgeIds === \"required\" && edgeIds === null && snapshot.edgeCount > 0) {\n note(\n LOSS.EDGE_IDS_GENERATED,\n \"the format requires edge ids, and the graph has none; the edges are written with generated ids, which read back as a new edge id column\",\n null,\n snapshot.edgeCount,\n );\n } else if (caps.edgeIds === \"none\" && edgeIds !== null) {\n note(\n LOSS.EDGE_IDS_DROPPED,\n `edge id column \"${edgeIds.meta.name}\" cannot be written`,\n edgeIds.meta.name,\n snapshot.edgeCount,\n );\n }\n}\n\n/**\n * The ids a charset cannot hold, as a message phrase.\n * @param charset - the format's id charset\n * @param n - how many ids, for the verb\n * @returns the phrase\n */\nfunction charsetText(charset: ExportCapabilities[\"idCharset\"], n: number): string {\n const are = agree(n, \"is\", \"are\");\n switch (charset) {\n case \"nmtoken\":\n return `${are} not XML name tokens (letters, digits and . - _ : only; no spaces)`;\n case \"integer\":\n return `${are} not integers`;\n default:\n return `cannot be written as ${charset} ids`;\n }\n}\n\n/**\n * The role names of one kind (CheckExtras.nodeRoleNames / edgeRoleNames, else roleNames).\n * @param domain - \"node\", \"edge\" or \"graph\"\n * @param extras - format extras\n * @returns the role names, or undefined when the extras name none\n */\nfunction roleNamesOf(domain: string, extras: CheckExtras): Readonly<Record<string, string>> | undefined {\n if (domain === \"node\") {\n return extras.nodeRoleNames ?? extras.roleNames;\n }\n if (domain === \"edge\") {\n return extras.edgeRoleNames ?? extras.roleNames;\n }\n return extras.roleNames;\n}\n\n/**\n * Whether a format writes the attributes of one kind (CheckExtras.nodeAttributes / edgeAttributes, else attributes).\n * @param domain - \"node\", \"edge\" or \"graph\"\n * @param extras - format extras\n * @returns false when it writes none, undefined when the extras do not say\n */\nfunction writesAttributes(domain: string, extras: CheckExtras): boolean | undefined {\n if (domain === \"node\") {\n return extras.nodeAttributes ?? extras.attributes;\n }\n if (domain === \"edge\") {\n return extras.edgeAttributes ?? extras.attributes;\n }\n return extras.attributes;\n}\n\n/**\n * The note of a format (or an option) that writes no weights, for a weighted graph.\n * @param snapshot - the snapshot\n * @param extras - format extras\n * @param note - the recorder\n */\nfunction checkWeights(snapshot: GraphSnapshot, extras: CheckExtras, note: NoteFn): void {\n if (extras.weights === false && explicitWeights(snapshot).weighted) {\n note(\n LOSS.WEIGHTS_DROPPED,\n `the edge weights are not written; ${snapshot.edgeCount} edge${plural(snapshot.edgeCount)} ${agree(snapshot.edgeCount, \"reads\", \"read\")} back with weight 1`,\n null,\n snapshot.edgeCount,\n );\n }\n}\n\n/** A note-recording callback. */\ntype NoteFn = (code: string, message: string, column?: string | null, count?: number | null) => void;\n\n/** How messages name what a column of a role holds. */\nconst ROLE_WORDS: Readonly<Record<string, string>> = {\n label: \"labels\",\n weight: \"weights\",\n id: \"ids\",\n position: \"positions\",\n originalId: \"original ids\",\n};\n\n/** What the per-column checks of checkCapabilities() read besides the column. */\ninterface ColumnCheck {\n /** The domain, for messages. */\n readonly domain: string;\n /** The capabilities. */\n readonly caps: ExportCapabilities;\n /** Format extras. */\n readonly extras: CheckExtras;\n /** The recorder. */\n readonly note: NoteFn;\n}\n\n/**\n * How many values a column holds.\n * @param column - the column\n * @returns the count of set cells\n */\nfunction setCount(column: Column): number {\n return column.length - column.nullCount;\n}\n\n/**\n * The per-column checks of checkCapabilities().\n * @param table - the table\n * @param domain - the domain, for messages\n * @param caps - the capabilities\n * @param extras - format extras\n * @param note - the recorder\n */\nfunction checkColumns(\n table: Iterable<Column>,\n domain: string,\n caps: ExportCapabilities,\n extras: CheckExtras,\n note: NoteFn,\n): void {\n const check: ColumnCheck = { domain, caps, extras, note };\n for (const column of table) {\n checkColumn(column, check);\n }\n}\n\n/**\n * The checks of one column.\n * @param column - the column\n * @param check - what the checks read\n */\nfunction checkColumn(column: Column, check: ColumnCheck): void {\n const { name, role } = column.meta;\n if (role !== null && STRUCTURAL_ROLES.has(role)) {\n return;\n }\n const label = `${check.domain} column \"${name}\"`;\n noteRoleRenamed(column, label, check);\n if (check.domain === \"edge\" && role === \"id\") {\n return;\n }\n if (isDropped(column, check)) {\n check.note(LOSS.COLUMN_DROPPED, `${label} is not written`, name, setCount(column));\n return;\n }\n const slot = role === null ? undefined : ROLE_SLOT_CHECKS.find(([holds]) => holds(role));\n if (slot !== undefined) {\n slot[1](column, label, check);\n return;\n }\n checkAttribute(column, label, check);\n}\n\n/**\n * COLUMN_NAME_CHANGED for a role column the format writes under a fixed name of its own.\n * @param column - the column\n * @param label - the column's label for messages\n * @param check - what the checks read\n */\nfunction noteRoleRenamed(column: Column, label: string, check: ColumnCheck): void {\n const { name, role } = column.meta;\n const fixed = role === null ? undefined : roleNamesOf(check.domain, check.extras)?.[role];\n if (role !== null && fixed !== undefined && fixed !== name) {\n check.note(\n LOSS.COLUMN_NAME_CHANGED,\n `${label} (the ${ROLE_WORDS[role] ?? role}) is written as the format's own ${role} and reads back as \"${fixed}\"`,\n name,\n setCount(column),\n );\n }\n}\n\n/**\n * Whether a column is not written at all: the format writes no attributes of its domain, and the column is neither\n * named as written nor of a role the format keeps.\n * @param column - the column\n * @param check - what the checks read\n * @returns true when it is dropped\n */\nfunction isDropped(column: Column, check: ColumnCheck): boolean {\n const { name, role } = column.meta;\n const { domain, extras } = check;\n const named = extras.writtenColumns?.[domain as \"node\" | \"edge\"]?.includes(name) ?? false;\n const kept = role !== null && (extras.roles?.has(role) ?? false);\n return writesAttributes(domain, extras) === false && !named && !kept;\n}\n\n/** The check of a column whose role has a slot of its own, or none: the column is not checked as an attribute. */\ntype RoleSlotCheck = (column: Column, label: string, check: ColumnCheck) => void;\n\n// The roles with slots of their own, each with its check: a role found here is not checked as an attribute.\nconst ROLE_SLOT_CHECKS: readonly (readonly [(role: string) => boolean, RoleSlotCheck])[] = [\n [\n (role) => role === \"timeText\",\n (column, label, check) => {\n if (check.extras.temporalText !== true) {\n check.note(\n LOSS.TEMPORAL_TEXT,\n `${label} (the original text of a date or time column) cannot be written`,\n column.meta.name,\n setCount(column),\n );\n }\n },\n ],\n [(role) => role === \"position\", checkPosition],\n // Deprecated path (removed in the next major version): the role columns as the old way styles reached a\n // file. With styles, the style writer is the only path and the caller leaves the role columns out.\n [(role) => VIZ_ROLES.has(role), checkViz],\n [\n (role) => HIERARCHY_ROLES.has(role),\n (column, label, check) => {\n if (!check.caps.hierarchy) {\n const { name, role } = column.meta;\n check.note(LOSS.HIERARCHY, `${label} (${String(role)}) cannot be written`, name, setCount(column));\n }\n },\n ],\n [\n (role) => TEMPORAL_ROLES.has(role),\n (column, label, check) => {\n if (check.caps.temporal === \"none\") {\n const { name, role } = column.meta;\n check.note(LOSS.TEMPORAL, `${label} (${String(role)}) cannot be written`, name, setCount(column));\n }\n },\n ],\n [\n (role) => role === \"spells\",\n (column, label, check) => {\n if (check.caps.temporal !== \"spells\" && check.caps.temporal !== \"dynamic-values\") {\n check.note(LOSS.SPELLS, `${label} (spells) cannot be written`, column.meta.name, setCount(column));\n }\n },\n ],\n [\n // The open bits are written by the format's own temporal syntax when it has one; the\n // column's u8 storage is never an attribute dtype, so no dtype note either way.\n (role) => role === \"open\" || role === \"spellsOpen\",\n (column, label, check) => {\n if (check.extras.openIntervals !== true) {\n check.note(\n LOSS.OPEN_INTERVAL,\n `${label} (open intervals) cannot be written`,\n column.meta.name,\n setCount(column),\n );\n }\n },\n ],\n];\n\n/**\n * The checks of a position column.\n * @param column - the column\n * @param label - the column's label for messages\n * @param check - what the checks read\n */\nfunction checkPosition(column: Column, label: string, check: ColumnCheck): void {\n const { caps, extras, note } = check;\n const { meta } = column;\n if (!caps.positions) {\n note(LOSS.POSITIONS, `${label} (positions) cannot be written`, meta.name, setCount(column));\n } else if (extras.positionDtype !== undefined && meta.dtype !== extras.positionDtype) {\n note(\n LOSS.DTYPE,\n `${label} (positions) is ${meta.dtype}; the format reads positions back as ${extras.positionDtype}`,\n meta.name,\n setCount(column),\n );\n }\n}\n\n/**\n * The checks of a deprecated style role column (color, size, shape, thickness).\n * @param column - the column\n * @param label - the column's label for messages\n * @param check - what the checks read\n */\nfunction checkViz(column: Column, label: string, check: ColumnCheck): void {\n const { caps, extras, note } = check;\n if ((caps as RoleSlots).viz) {\n return;\n }\n const { name } = column.meta;\n const role = String(column.meta.role);\n note(\n LOSS.VIZ,\n extras.vizAsAttributes === true\n ? `${label} (${role}) is written as a plain attribute; the format has no ${role} slot and the role is lost on re-import`\n : `${label} (${role}) cannot be written`,\n name,\n setCount(column),\n );\n}\n\n/**\n * The checks of a column written as a plain attribute.\n * @param column - the column\n * @param label - the column's label for messages\n * @param check - what the checks read\n */\nfunction checkAttribute(column: Column, label: string, check: ColumnCheck): void {\n const { caps, extras, note } = check;\n const { meta } = column;\n const { name, role } = meta;\n if (role !== null && !(extras.roles?.has(role) ?? false)) {\n note(\n LOSS.ROLE,\n `${label} (${role}) is written as a plain attribute; the format has no ${role} slot and the role is lost`,\n name,\n setCount(column),\n );\n }\n if (meta.dynamic && caps.temporal !== \"dynamic-values\") {\n note(LOSS.DYNAMIC_VALUES, `${label} is dynamic; only its static value can be written`, name, null);\n }\n checkDtype(column, label, caps, note);\n if (meta.default !== undefined && !caps.defaults) {\n note(LOSS.DEFAULT, `${label} declares a default; the format has no defaults`, name, null);\n }\n if (meta.options !== null && !caps.options) {\n note(LOSS.OPTIONS, `${label} declares options; the format has no enumerations`, name, null);\n }\n}\n\n/**\n * The dtype checks of one attribute column: lists, nested values, scalar dtypes and strides\n * against the capability table.\n * @param column - the column\n * @param label - the column's label for messages\n * @param caps - the capabilities\n * @param note - the recorder\n */\nfunction checkDtype(column: Column, label: string, caps: ExportCapabilities, note: NoteFn): void {\n const { meta } = column;\n const { name } = meta;\n const set = column.length - column.nullCount;\n switch (meta.dtype) {\n case \"list\":\n if (!caps.lists) {\n note(LOSS.LIST, `${label} is a list; the format has no lists`, name, set);\n } else if (meta.itemDtype !== null && !caps.dtypes.includes(meta.itemDtype)) {\n note(\n LOSS.DTYPE,\n `${label} holds ${meta.itemDtype} items; the format cannot keep that dtype`,\n name,\n set,\n );\n } else if (meta.itemDtype === \"dict\") {\n // no format declares an enumeration for list items: they read back as strings\n note(LOSS.DTYPE, `${label} holds dict items; list items read back as string`, name, set);\n }\n break;\n case \"json\":\n if (!caps.json) {\n note(LOSS.JSON, `${label} holds nested values; the format has no nested values`, name, set);\n }\n break;\n default:\n if (!caps.dtypes.includes(meta.dtype)) {\n note(LOSS.DTYPE, `${label} is ${meta.dtype}; the format cannot keep that dtype`, name, set);\n }\n if (meta.components > 1 && !caps.components) {\n note(\n LOSS.COMPONENTS,\n `${label} has ${meta.components} components; the format has no strides`,\n name,\n set,\n );\n }\n break;\n }\n}\n\n/**\n * The number of source edges that were undirected in a directed snapshot (the halves of an\n * expanded pair count once; an expanded self-loop has no mirror and counts once).\n * @param snapshot - the snapshot\n * @returns the count; 0 for an undirected snapshot or one without the directed role\n * @category Plugin helpers\n */\nexport function countMixedEdges(snapshot: GraphSnapshot): number {\n if (!snapshot.directed) {\n return 0;\n }\n const directed = snapshot.edges.byRole(\"directed\");\n if (directed?.dtype !== \"bool\") {\n return 0;\n }\n const pair = snapshot.edges.byRole(\"pair\");\n let undirectedRows = 0;\n let paired = 0;\n for (let e = 0; e < snapshot.edgeCount; e++) {\n if (directed.isSet(e) && directed.value(e) === false) {\n undirectedRows++;\n if (pair !== null && pair.dtype === \"u32\" && pair.isSet(e) && pair.data[e] !== INVALID_INDEX) {\n paired++;\n }\n }\n }\n return paired / 2 + (undirectedRows - paired);\n}\n\n/**\n * The number of arcs that repeat the previous arc's target within a row (parallel edges), counted\n * over the forward CSR; an undirected parallel edge is counted in both rows.\n * @param snapshot - the snapshot\n * @returns the count\n * @category Plugin helpers\n */\nexport function countParallelArcs(snapshot: GraphSnapshot): number {\n const { rowPtr, colIdx, nodeCount } = snapshot;\n let count = 0;\n for (let u = 0; u < nodeCount; u++) {\n for (let a = rowPtr[u] + 1; a < rowPtr[u + 1]; a++) {\n if (colIdx[a] === colIdx[a - 1]) {\n count++;\n }\n }\n }\n return snapshot.directed ? count : Math.ceil(count / 2);\n}\n\n// ============================================================ id sanitising\n\n/**\n * The id charsets of ExportCapabilities.\n * @public\n * @category Plugin helpers\n */\nexport type IdCharset = ExportCapabilities[\"idCharset\"];\n\n/**\n * The ids to write for every node after sanitising.\n * @public\n * @category Writing a format\n */\nexport interface SanitizedIds {\n /** The charset applied. */\n readonly charset: IdCharset;\n /** How many ids differ from the snapshot's. */\n readonly changed: number;\n /**\n * The id to write for a node.\n * @param index - the node index\n * @returns the id as the format will read it back\n */\n idAt(index: number): NodeId;\n /**\n * Whether a node's written id differs from its original.\n * @param index - the node index\n * @returns true when the exporter must record the original\n */\n isChanged(index: number): boolean;\n /**\n * The original id of a node.\n * @param index - the node index\n * @returns the snapshot's id\n */\n originalAt(index: number): NodeId;\n}\n\n/** XML NameChar ranges (XML 1.0 fifth edition), as inclusive code point pairs. */\nconst NAME_CHAR_RANGES: readonly (readonly [number, number])[] = [\n [0x2d, 0x2e],\n [0x30, 0x3a],\n [0x41, 0x5a],\n [0x5f, 0x5f],\n [0x61, 0x7a],\n [0xb7, 0xb7],\n [0xc0, 0xd6],\n [0xd8, 0xf6],\n [0xf8, 0x37d],\n [0x37f, 0x1fff],\n [0x200c, 0x200d],\n [0x203f, 0x2040],\n [0x2070, 0x218f],\n [0x2c00, 0x2fef],\n [0x3001, 0xd7ff],\n [0xf900, 0xfdcf],\n [0xfdf0, 0xfffd],\n [0x10000, 0xeffff],\n];\n\n/**\n * Whether a code point is an XML NameChar.\n * @param cp - the code point\n * @returns true when it may appear in an NMTOKEN\n * @category Plugin helpers\n */\nexport function isNameChar(cp: number): boolean {\n for (const [lo, hi] of NAME_CHAR_RANGES) {\n if (cp < lo) {\n return false;\n }\n if (cp <= hi) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Whether a text is an XML NMTOKEN (one or more NameChars; GraphML node and edge ids).\n * @param text - the text\n * @returns true for a non-empty text of NameChars\n * @category Plugin helpers\n */\nexport function isNmtoken(text: string): boolean {\n if (text.length === 0) {\n return false;\n }\n for (const ch of text) {\n const cp = ch.codePointAt(0);\n if (cp === undefined || !isNameChar(cp)) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * Whether an id can be written unchanged under a charset.\n * @param id - the id\n * @param charset - the charset\n * @returns true when the id needs no rewriting (\"dense-1-based\" is never true: see sanitizeIds)\n * @category Plugin helpers\n */\nexport function isRepresentableId(id: NodeId, charset: IdCharset): boolean {\n switch (charset) {\n case \"any\":\n return true;\n case \"nmtoken\":\n return isNmtoken(String(id));\n case \"integer\":\n return typeof id === \"number\" && Number.isSafeInteger(id);\n case \"dense-1-based\":\n return false;\n default: {\n const name: string = charset;\n throw new GraphFormatError(\"E_UNSUPPORTED\", `unknown id charset ${name}`, { charset: name });\n }\n }\n}\n\n/**\n * How many node ids a charset cannot hold as they are (for check()); under \"dense-1-based\" the\n * ids that are not their own 1-based index.\n * @param snapshot - the snapshot\n * @param charset - the charset\n * @returns the count\n * @category Plugin helpers\n */\nexport function countUnrepresentableIds(snapshot: GraphSnapshot, charset: IdCharset): number {\n const { ids } = snapshot;\n if (charset === \"any\") {\n return 0;\n }\n if (charset === \"dense-1-based\") {\n if (ids.kind === \"identity\" && ids.offset === 1) {\n return 0;\n }\n let changed = 0;\n for (let i = 0; i < ids.size; i++) {\n if (ids.idOf(i) !== i + 1) {\n changed++;\n }\n }\n return changed;\n }\n let count = 0;\n for (let i = 0; i < ids.size; i++) {\n if (!isRepresentableId(ids.idOf(i), charset)) {\n count++;\n }\n }\n return count;\n}\n\n/**\n * Sanitise the node ids for a charset. Under \"error\" any id the charset\n * cannot hold is E_INVALID_ID (details.reason \"charset\") and nothing is written; under \"mangle\"\n * such ids are rewritten deterministically and uniquely: NMTOKEN by replacing every other\n * character with `_` (an empty result becomes `_`) and suffixing `_2`, `_3`... on collision;\n * integer by the smallest unused non-negative integers in index order. \"dense-1-based\" always\n * writes the 1-based index (Pajek numbers vertices; the exporter writes the original id as the\n * label), which is a renumbering rather than a mangling, so it never throws under \"error\"; under\n * \"mangle\" the exporter also writes the original id under its originalId attribute.\n * @param snapshot - the snapshot\n * @param charset - the charset\n * @param mode - the resolved sanitizeIds option\n * @returns the ids to write\n * @category Writing a format\n */\nexport function sanitizeIds(snapshot: GraphSnapshot, charset: IdCharset, mode: \"error\" | \"mangle\"): SanitizedIds {\n const { ids } = snapshot;\n const n = ids.size;\n if (charset === \"dense-1-based\") {\n const changed = countUnrepresentableIds(snapshot, charset);\n return {\n charset,\n changed,\n idAt: (i: number): NodeId => i + 1,\n isChanged: (i: number): boolean => ids.idOf(i) !== i + 1,\n originalAt: (i: number): NodeId => ids.idOf(i),\n };\n }\n const unchanged: SanitizedIds = {\n charset,\n changed: 0,\n idAt: (i: number): NodeId => ids.idOf(i),\n isChanged: (): boolean => false,\n originalAt: (i: number): NodeId => ids.idOf(i),\n };\n if (charset === \"any\") {\n return unchanged;\n }\n const bad: number[] = [];\n for (let i = 0; i < n; i++) {\n if (!isRepresentableId(ids.idOf(i), charset)) {\n bad.push(i);\n }\n }\n if (bad.length === 0) {\n return unchanged;\n }\n if (mode === \"error\") {\n const first = ids.idOf(bad[0]);\n throw new GraphFormatError(\n \"E_INVALID_ID\",\n `${bad.length} node id${plural(bad.length)} ${charsetText(charset, bad.length)} (first: ${JSON.stringify(first)} at index ${bad[0]}); pass sanitizeIds: \"mangle\" to rewrite them`,\n { reason: \"charset\", charset, count: bad.length, id: first, index: bad[0] },\n );\n }\n const written = new Map<number, NodeId>();\n if (charset === \"nmtoken\") {\n const used = new Set<string>();\n for (let i = 0; i < n; i++) {\n const id = ids.idOf(i);\n if (isRepresentableId(id, charset)) {\n used.add(String(id));\n }\n }\n for (const i of bad) {\n const base = mangleNmtoken(String(ids.idOf(i)));\n let candidate = base;\n for (let k = 2; used.has(candidate); k++) {\n candidate = `${base}_${k}`;\n }\n used.add(candidate);\n written.set(i, candidate);\n }\n } else {\n const used = new Set<number>();\n for (let i = 0; i < n; i++) {\n const id = ids.idOf(i);\n if (typeof id === \"number\" && Number.isSafeInteger(id)) {\n used.add(id);\n }\n }\n let next = 0;\n for (const i of bad) {\n while (used.has(next)) {\n next++;\n }\n used.add(next);\n written.set(i, next);\n next++;\n }\n }\n return {\n charset,\n changed: bad.length,\n idAt: (i: number): NodeId => written.get(i) ?? ids.idOf(i),\n isChanged: (i: number): boolean => written.has(i),\n originalAt: (i: number): NodeId => ids.idOf(i),\n };\n}\n\n/**\n * Rewrite a text as an NMTOKEN: every character that is not a NameChar becomes `_`.\n * @param text - the text\n * @returns a non-empty NMTOKEN\n * @category Plugin helpers\n */\nexport function mangleNmtoken(text: string): string {\n let out = \"\";\n for (const ch of text) {\n const cp = ch.codePointAt(0);\n out += cp !== undefined && isNameChar(cp) ? ch : \"_\";\n }\n return out.length === 0 ? \"_\" : out;\n}\n"],"names":["DATE_TIME","TIME","INTEGER_TEXT","list"],"mappings":";;AA0CO,MAAM,iBAA6B;AAMnC,MAAM,mBAAmB;AAEhC,MAAMA,cACF;AACJ,MAAMC,SAAO;AACb,MAAM,UAAU;AAEhB,MAAM,gBAAgB;AACtB,MAAM,aAAa;AASZ,SAAS,cAAc,MAAc,MAAmC;AAC3E,MAAI;AACJ,UAAQ,MAAA;AAAA,IACJ,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACD,cAAQ,cAAc,MAAM,IAAI;AAChC;AAAA,IACJ,KAAK;AAAA,IACL,KAAK;AACD,cAAQ,UAAU,MAAM,IAAI;AAC5B;AAAA,IACJ,SAAS;AACL,YAAM,OAAe;AACrB,YAAM,IAAI,iBAAiB,iBAAiB,yBAAyB,IAAI,IAAI,EAAE,MAAM,MAAM;AAAA,IAC/F;AAAA,EAAA;AAEJ,QAAM,YAAY,eAAe,OAAO,IAAI;AAC5C,SAAO,EAAE,OAAO,MAAM,cAAc,OAAO,OAAO,KAAA;AACtD;AAYO,SAAS,cAAc,MAAc,YAA8C;AACtF,QAAM,UAAU,KAAK,KAAA;AACrB,UAAQ,YAAA;AAAA,IACJ,KAAK;AAAA,IACL,KAAK;AACD,aAAO,iBAAiB,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