@graphty/graph-io 0.3.18 → 0.3.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/README.md +80 -2
  2. package/dist/chunks/{escape-D-gZWO26.js → escape-B-tkk_Cl.js} +74 -16
  3. package/dist/chunks/escape-B-tkk_Cl.js.map +1 -0
  4. package/dist/chunks/{writer-GAdltGmC.js → export-Bh60Dv-n.js} +7 -252
  5. package/dist/chunks/export-Bh60Dv-n.js.map +1 -0
  6. package/dist/chunks/exporter-BGrsWamJ.js +736 -0
  7. package/dist/chunks/exporter-BGrsWamJ.js.map +1 -0
  8. package/dist/chunks/exporter-DIeGJXAZ.js +834 -0
  9. package/dist/chunks/exporter-DIeGJXAZ.js.map +1 -0
  10. package/dist/chunks/{importer-Br_QeAeE.js → importer-BWY2FFc5.js} +28 -6
  11. package/dist/chunks/importer-BWY2FFc5.js.map +1 -0
  12. package/dist/chunks/importer-BaQpCEcJ.js +2194 -0
  13. package/dist/chunks/importer-BaQpCEcJ.js.map +1 -0
  14. package/dist/chunks/importer-DD-xv9_Y.js +1471 -0
  15. package/dist/chunks/importer-DD-xv9_Y.js.map +1 -0
  16. package/dist/chunks/{importer-aNJfe0qu.js → importer-DEcKhsmQ.js} +2 -2
  17. package/dist/chunks/{importer-aNJfe0qu.js.map → importer-DEcKhsmQ.js.map} +1 -1
  18. package/dist/chunks/{importer-DHagxvDD.js → importer-DIrbbnAf.js} +6 -4
  19. package/dist/chunks/{importer-DHagxvDD.js.map → importer-DIrbbnAf.js.map} +1 -1
  20. package/dist/chunks/importer-D_e7e7LX.js +3055 -0
  21. package/dist/chunks/importer-D_e7e7LX.js.map +1 -0
  22. package/dist/chunks/{importer-Du5crN9l.js → importer-Wv4C4gaF.js} +278 -82
  23. package/dist/chunks/importer-Wv4C4gaF.js.map +1 -0
  24. package/dist/chunks/importer-vi3bSdtw.js +1713 -0
  25. package/dist/chunks/importer-vi3bSdtw.js.map +1 -0
  26. package/dist/chunks/{importer-d0uQxFp6.js → importer-zGLo8Dg_.js} +6 -4
  27. package/dist/chunks/{importer-d0uQxFp6.js.map → importer-zGLo8Dg_.js.map} +1 -1
  28. package/dist/chunks/json-elements-DDS8N2Dd.js +779 -0
  29. package/dist/chunks/json-elements-DDS8N2Dd.js.map +1 -0
  30. package/dist/chunks/{records-Bk9jgodz.js → records-dbRkxwaq.js} +2 -2
  31. package/dist/chunks/{records-Bk9jgodz.js.map → records-dbRkxwaq.js.map} +1 -1
  32. package/dist/chunks/{report-BOk0p5y8.js → report-B1z4WT9e.js} +143 -111
  33. package/dist/chunks/{report-BOk0p5y8.js.map → report-B1z4WT9e.js.map} +1 -1
  34. package/dist/chunks/weights-Dzba96G3.js +176 -0
  35. package/dist/chunks/weights-Dzba96G3.js.map +1 -0
  36. package/dist/chunks/writer-C7flM-Ih.js +77 -0
  37. package/dist/chunks/writer-C7flM-Ih.js.map +1 -0
  38. package/dist/csv.js +6 -4
  39. package/dist/csv.js.map +1 -1
  40. package/dist/cx.d.ts +1 -0
  41. package/dist/cx.js +6 -0
  42. package/dist/cx.js.map +1 -0
  43. package/dist/cx2.d.ts +1 -0
  44. package/dist/cx2.js +10 -0
  45. package/dist/cx2.js.map +1 -0
  46. package/dist/cys.d.ts +1 -0
  47. package/dist/cys.js +6 -0
  48. package/dist/cys.js.map +1 -0
  49. package/dist/dot.js +1 -1
  50. package/dist/gexf.js +16 -4
  51. package/dist/gexf.js.map +1 -1
  52. package/dist/gml.js +13 -14
  53. package/dist/gml.js.map +1 -1
  54. package/dist/graph-io.js +302 -399
  55. package/dist/graph-io.js.map +1 -1
  56. package/dist/graphml.js +1 -1
  57. package/dist/json.js +1 -1
  58. package/dist/neo4j.js +6 -4
  59. package/dist/neo4j.js.map +1 -1
  60. package/dist/obo.js +1 -1
  61. package/dist/pajek.js +1 -1
  62. package/dist/src/common/cell-budget.d.ts +84 -0
  63. package/dist/src/common/cell-budget.d.ts.map +1 -0
  64. package/dist/src/common/cell-budget.js +138 -0
  65. package/dist/src/common/cell-budget.js.map +1 -0
  66. package/dist/src/common/input.d.ts +10 -0
  67. package/dist/src/common/input.d.ts.map +1 -1
  68. package/dist/src/common/input.js +39 -0
  69. package/dist/src/common/input.js.map +1 -1
  70. package/dist/src/common/json-elements.d.ts +286 -0
  71. package/dist/src/common/json-elements.d.ts.map +1 -0
  72. package/dist/src/common/json-elements.js +926 -0
  73. package/dist/src/common/json-elements.js.map +1 -0
  74. package/dist/src/common/options.d.ts +6 -0
  75. package/dist/src/common/options.d.ts.map +1 -1
  76. package/dist/src/common/options.js +1 -1
  77. package/dist/src/common/options.js.map +1 -1
  78. package/dist/src/common/xml.d.ts +37 -3
  79. package/dist/src/common/xml.d.ts.map +1 -1
  80. package/dist/src/common/xml.js +86 -6
  81. package/dist/src/common/xml.js.map +1 -1
  82. package/dist/src/common/zip.d.ts +92 -0
  83. package/dist/src/common/zip.d.ts.map +1 -0
  84. package/dist/src/common/zip.js +399 -0
  85. package/dist/src/common/zip.js.map +1 -0
  86. package/dist/src/formats/cx/importer.d.ts +133 -0
  87. package/dist/src/formats/cx/importer.d.ts.map +1 -0
  88. package/dist/src/formats/cx/importer.js +2220 -0
  89. package/dist/src/formats/cx/importer.js.map +1 -0
  90. package/dist/src/formats/cx/index.d.ts +7 -0
  91. package/dist/src/formats/cx/index.d.ts.map +1 -0
  92. package/dist/src/formats/cx/index.js +7 -0
  93. package/dist/src/formats/cx/index.js.map +1 -0
  94. package/dist/src/formats/cx2/exporter.d.ts +59 -0
  95. package/dist/src/formats/cx2/exporter.d.ts.map +1 -0
  96. package/dist/src/formats/cx2/exporter.js +864 -0
  97. package/dist/src/formats/cx2/exporter.js.map +1 -0
  98. package/dist/src/formats/cx2/importer.d.ts +169 -0
  99. package/dist/src/formats/cx2/importer.d.ts.map +1 -0
  100. package/dist/src/formats/cx2/importer.js +1652 -0
  101. package/dist/src/formats/cx2/importer.js.map +1 -0
  102. package/dist/src/formats/cx2/index.d.ts +7 -0
  103. package/dist/src/formats/cx2/index.d.ts.map +1 -0
  104. package/dist/src/formats/cx2/index.js +7 -0
  105. package/dist/src/formats/cx2/index.js.map +1 -0
  106. package/dist/src/formats/cys/constants.d.ts +68 -0
  107. package/dist/src/formats/cys/constants.d.ts.map +1 -0
  108. package/dist/src/formats/cys/constants.js +76 -0
  109. package/dist/src/formats/cys/constants.js.map +1 -0
  110. package/dist/src/formats/cys/importer.d.ts +38 -0
  111. package/dist/src/formats/cys/importer.d.ts.map +1 -0
  112. package/dist/src/formats/cys/importer.js +830 -0
  113. package/dist/src/formats/cys/importer.js.map +1 -0
  114. package/dist/src/formats/cys/index.d.ts +7 -0
  115. package/dist/src/formats/cys/index.d.ts.map +1 -0
  116. package/dist/src/formats/cys/index.js +7 -0
  117. package/dist/src/formats/cys/index.js.map +1 -0
  118. package/dist/src/formats/cys/session.d.ts +132 -0
  119. package/dist/src/formats/cys/session.d.ts.map +1 -0
  120. package/dist/src/formats/cys/session.js +315 -0
  121. package/dist/src/formats/cys/session.js.map +1 -0
  122. package/dist/src/formats/cys/tables.d.ts +90 -0
  123. package/dist/src/formats/cys/tables.d.ts.map +1 -0
  124. package/dist/src/formats/cys/tables.js +293 -0
  125. package/dist/src/formats/cys/tables.js.map +1 -0
  126. package/dist/src/formats/dot/exporter.d.ts +2 -0
  127. package/dist/src/formats/dot/exporter.d.ts.map +1 -1
  128. package/dist/src/formats/dot/exporter.js +12 -0
  129. package/dist/src/formats/dot/exporter.js.map +1 -1
  130. package/dist/src/formats/dot/importer.js +6 -2
  131. package/dist/src/formats/dot/importer.js.map +1 -1
  132. package/dist/src/formats/gexf/exporter.d.ts +2 -0
  133. package/dist/src/formats/gexf/exporter.d.ts.map +1 -1
  134. package/dist/src/formats/gexf/exporter.js +6 -0
  135. package/dist/src/formats/gexf/exporter.js.map +1 -1
  136. package/dist/src/formats/gexf/importer.d.ts +0 -2
  137. package/dist/src/formats/gexf/importer.d.ts.map +1 -1
  138. package/dist/src/formats/gexf/importer.js +1 -3
  139. package/dist/src/formats/gexf/importer.js.map +1 -1
  140. package/dist/src/formats/gexf/index.d.ts +1 -1
  141. package/dist/src/formats/gexf/index.js +2 -2
  142. package/dist/src/formats/gexf/index.js.map +1 -1
  143. package/dist/src/formats/gml/exporter.d.ts +0 -8
  144. package/dist/src/formats/gml/exporter.d.ts.map +1 -1
  145. package/dist/src/formats/gml/exporter.js +8 -18
  146. package/dist/src/formats/gml/exporter.js.map +1 -1
  147. package/dist/src/formats/json/importer.d.ts.map +1 -1
  148. package/dist/src/formats/json/importer.js +6 -104
  149. package/dist/src/formats/json/importer.js.map +1 -1
  150. package/dist/src/formats/xgmml/columns.d.ts +152 -0
  151. package/dist/src/formats/xgmml/columns.d.ts.map +1 -0
  152. package/dist/src/formats/xgmml/columns.js +593 -0
  153. package/dist/src/formats/xgmml/columns.js.map +1 -0
  154. package/dist/src/formats/xgmml/constants.d.ts +196 -0
  155. package/dist/src/formats/xgmml/constants.d.ts.map +1 -0
  156. package/dist/src/formats/xgmml/constants.js +197 -0
  157. package/dist/src/formats/xgmml/constants.js.map +1 -0
  158. package/dist/src/formats/xgmml/document.d.ts +361 -0
  159. package/dist/src/formats/xgmml/document.d.ts.map +1 -0
  160. package/dist/src/formats/xgmml/document.js +695 -0
  161. package/dist/src/formats/xgmml/document.js.map +1 -0
  162. package/dist/src/formats/xgmml/emit.d.ts +341 -0
  163. package/dist/src/formats/xgmml/emit.d.ts.map +1 -0
  164. package/dist/src/formats/xgmml/emit.js +1275 -0
  165. package/dist/src/formats/xgmml/emit.js.map +1 -0
  166. package/dist/src/formats/xgmml/exporter.d.ts +24 -0
  167. package/dist/src/formats/xgmml/exporter.d.ts.map +1 -0
  168. package/dist/src/formats/xgmml/exporter.js +999 -0
  169. package/dist/src/formats/xgmml/exporter.js.map +1 -0
  170. package/dist/src/formats/xgmml/importer.d.ts +58 -0
  171. package/dist/src/formats/xgmml/importer.d.ts.map +1 -0
  172. package/dist/src/formats/xgmml/importer.js +360 -0
  173. package/dist/src/formats/xgmml/importer.js.map +1 -0
  174. package/dist/src/formats/xgmml/index.d.ts +8 -0
  175. package/dist/src/formats/xgmml/index.d.ts.map +1 -0
  176. package/dist/src/formats/xgmml/index.js +8 -0
  177. package/dist/src/formats/xgmml/index.js.map +1 -0
  178. package/dist/src/formats/xgmml/values.d.ts +60 -0
  179. package/dist/src/formats/xgmml/values.d.ts.map +1 -0
  180. package/dist/src/formats/xgmml/values.js +148 -0
  181. package/dist/src/formats/xgmml/values.js.map +1 -0
  182. package/dist/src/index.d.ts +4 -0
  183. package/dist/src/index.d.ts.map +1 -1
  184. package/dist/src/index.js +4 -0
  185. package/dist/src/index.js.map +1 -1
  186. package/dist/src/registry.d.ts +7 -0
  187. package/dist/src/registry.d.ts.map +1 -1
  188. package/dist/src/registry.js +30 -10
  189. package/dist/src/registry.js.map +1 -1
  190. package/dist/src/sniff.d.ts +1 -1
  191. package/dist/src/sniff.d.ts.map +1 -1
  192. package/dist/src/sniff.js +4 -0
  193. package/dist/src/sniff.js.map +1 -1
  194. package/dist/xgmml.d.ts +1 -0
  195. package/dist/xgmml.js +9 -0
  196. package/dist/xgmml.js.map +1 -0
  197. package/package.json +25 -2
  198. package/src/common/cell-budget.ts +170 -0
  199. package/src/common/input.ts +40 -0
  200. package/src/common/json-elements.ts +1147 -0
  201. package/src/common/options.ts +1 -1
  202. package/src/common/xml.ts +127 -6
  203. package/src/common/zip.ts +472 -0
  204. package/src/formats/cx/importer.ts +2733 -0
  205. package/src/formats/cx/index.ts +7 -0
  206. package/src/formats/cx2/exporter.ts +1036 -0
  207. package/src/formats/cx2/importer.ts +2187 -0
  208. package/src/formats/cx2/index.ts +7 -0
  209. package/src/formats/cys/constants.ts +99 -0
  210. package/src/formats/cys/importer.ts +1100 -0
  211. package/src/formats/cys/index.ts +7 -0
  212. package/src/formats/cys/session.ts +428 -0
  213. package/src/formats/cys/tables.ts +400 -0
  214. package/src/formats/dot/exporter.ts +17 -0
  215. package/src/formats/dot/importer.ts +6 -2
  216. package/src/formats/gexf/exporter.ts +11 -0
  217. package/src/formats/gexf/importer.ts +1 -2
  218. package/src/formats/gexf/index.ts +1 -1
  219. package/src/formats/gml/exporter.ts +8 -19
  220. package/src/formats/json/importer.ts +6 -105
  221. package/src/formats/xgmml/columns.ts +747 -0
  222. package/src/formats/xgmml/constants.ts +265 -0
  223. package/src/formats/xgmml/document.ts +975 -0
  224. package/src/formats/xgmml/emit.ts +1563 -0
  225. package/src/formats/xgmml/exporter.ts +1215 -0
  226. package/src/formats/xgmml/importer.ts +491 -0
  227. package/src/formats/xgmml/index.ts +8 -0
  228. package/src/formats/xgmml/values.ts +183 -0
  229. package/src/index.ts +19 -0
  230. package/src/registry.ts +46 -15
  231. package/src/sniff.ts +18 -1
  232. package/dist/chunks/escape-D-gZWO26.js.map +0 -1
  233. package/dist/chunks/importer-Br_QeAeE.js.map +0 -1
  234. package/dist/chunks/importer-Du5crN9l.js.map +0 -1
  235. package/dist/chunks/writer-GAdltGmC.js.map +0 -1
package/README.md CHANGED
@@ -8,8 +8,8 @@
8
8
  Importers and exporters for the [@graphty/graph-format](https://www.npmjs.com/package/@graphty/graph-format)
9
9
  snapshot: GEXF, GraphML, GML, DOT (Graphviz), Pajek NET, CSV / TSV, JSON (NetworkX node-link, d3,
10
10
  JSON Graph Format, Cytoscape, graphology, vis.js; NetworkX adjacency_data and tree_data and OBO
11
- Graphs are read only), Neo4j (`neo4j-admin import` CSV) and OBO, the ontology format of the Gene
12
- Ontology (read only).
11
+ Graphs are read only), Neo4j (`neo4j-admin import` CSV), CX2 (the NDEx / Cytoscape exchange format;
12
+ its version 1, CX, is read only) and OBO, the ontology format of the Gene Ontology (read only).
13
13
 
14
14
  Every importer streams its input into a `GraphSink` (a `GraphBuilder` or your own sink) one scalar at
15
15
  a time and reports what it could not represent instead of dropping it; every exporter says what it
@@ -122,6 +122,14 @@ On a caller's builder the builder-policy options (`addMissingNodes`, `duplicateE
122
122
  `weightDtype`) are read from the sink; an explicit request the sink does not honour is reported once
123
123
  as a `W_SINK_OPTION` warning. `importGraph()` seeds its own builder from them.
124
124
 
125
+ Every attribute is stored as a column with one slot per node (or edge), so a file whose nodes each
126
+ carry a differently named attribute would need nodes x attributes memory: a few hundred kilobytes
127
+ could take gigabytes. `importGraph()` and `importAllGraphs()` therefore stop with an `ImportError`
128
+ (code `E_TOO_MANY_EMPTY_CELLS`) once the columns would hold more than `maxEmptyCells` slots without
129
+ a value (default 2^24, 16,777,216; `Infinity` turns the check off). A file where most elements have
130
+ most attributes is never stopped, however large. An importer used directly on a caller's builder
131
+ does not apply the limit.
132
+
125
133
  ### Common export options
126
134
 
127
135
  `sanitizeIds: "error" | "mangle"` (default `"error"`: an exporter never silently renames a node;
@@ -147,6 +155,9 @@ reports every column or feature outside it):
147
155
  | JSON | `@graphty/graph-io/json` | `.json` | per dialect | yes | per dialect | any | f64 i32 bool string (no declarations) | no | yes | no | Cytoscape | none | per dialect | Cytoscape | no |
148
156
  | Neo4j | `@graphty/graph-io/neo4j` | `.csv` `.tsv` | no | yes | none | any | f32 f64 i32 bool string | yes | no | no | no | none | no | no | no |
149
157
  | OBO | `@graphty/graph-io/obo` | `.obo` | read only | - | - | - | - | - | - | - | - | - | - | - | - |
158
+ | CX2 | `@graphty/graph-io/cx2` | `.cx2` | no | yes | required | integer | f64 i32 bool string | yes | no | yes | no | none | yes | yes | no |
159
+ | XGMML | `@graphty/graph-io/xgmml` | `.xgmml` `.xml` | yes | yes | optional | any | f64 i32 bool string (long as Long) | yes | no | no | yes | none | yes | yes | no |
160
+ | Session | `@graphty/graph-io/cys` | `.cys` | read only | read only | read only | read only | read only | - | - | - | - | - | - | - | - |
150
161
 
151
162
  Every importer reads the whole corpus of research note 07 with the manifest counts and every
152
163
  exporter round-trips it (import -> export -> import gives the same ids, topology, orientation,
@@ -296,6 +307,73 @@ losses and format rules, in addition to the table:
296
307
  written with a `W_NEO4J_UNDIRECTED_AS_DIRECTED` note); `.text` companions keep the source text of
297
308
  temporal values whose canonical form differs; a dict column reads back as string and a position
298
309
  or visual column as a plain property.
310
+ - **XGMML**: one reader for the 1.0 draft, the Cytoscape 2.x and 3.x exports and the Cytoscape 3
311
+ session network files. Direction follows the DTD (root `directed`, default 0), then `cy:directed`
312
+ per edge; ids stay strings (`"1"` and `"01"` are two nodes); atts are typed by `cy:type`, then
313
+ `type` (the XGMML `integer` is `i32`, widening to `f64` with `W_WIDENED` because pre-3.3
314
+ Cytoscape wrote Longs that way, while a value beyond i32 under `cy:type="Integer"` or in a
315
+ session's `java.lang.Integer` column is `E_BAD_VALUE`; Long `f64` or a string under
316
+ `long: "string"`, lists of their element type, record lists, lists of lists and RDF as `json`);
317
+ groups become `parent` / `parents`, other node-nested graphs the `cytoscape.nestedNetwork`
318
+ pointer; `graphics` x and y are the position, stored y-up (Cytoscape writes screen coordinates;
319
+ the exporter flips y back), z the separate `z` column (`zAs: "position"` makes it a coordinate),
320
+ every other graphics value a `json` column `graphics`. Cytoscape's `\n` / `\t` escapes, label
321
+ aliases (`a (pp) b`) and the two writer bugs Cytoscape repairs (`repairBareAmpersands`,
322
+ `pairSurrogateReferences`, both off by default) are options. A session network document lists
323
+ its registered networks through `listGraphs()`; `graphIndex` / `graphName` choose one. Dangling
324
+ endpoints are `E_UNKNOWN_NODE` unless `addMissingNodes: true`. The exporter writes the Cytoscape
325
+ 3 dialect (`type` plus `cy:type` on every att): f32, u8, u32 and dict are written as wider
326
+ Cytoscape types, json as text, and graphty's visual roles are not translated into graphics.
327
+ - **Cytoscape sessions (`.cys`)**: read only (Cytoscape opens the XGMML graph-io writes). A
328
+ session is a zip of every network of a Cytoscape desktop, read with no dependency (the central
329
+ directory, zip64, data descriptors, stored and deflate entries inflated through
330
+ `DecompressionStream`; encryption and other methods are refused by name). One snapshot per
331
+ registered network: `import()` reads the first (`graphIndex` / `graphName` choose another,
332
+ `listGraphs()` lists them with their counts), `importAll()` every one. 3.x: the network file's
333
+ topology, the network's CyCSV tables as columns (shared columns joined in by `cytables.xml`,
334
+ HIDDEN and app tables as hidden columns under their namespace), positions from its first view
335
+ (y-up; further views as `position@2`, ...) and the view's per-element values as the `graphics`
336
+ column; 2.x: one XGMML per network, with `cysession.xml`'s selection and hidden state as
337
+ `cytoscape.selected` / `cytoscape.hidden`. Expanded groups become `parent` / `parents`, a
338
+ collapsed group's members are listed in `meta.extra.cytoscape.groups`, nested-network pointers
339
+ name their network in `cytoscape.nestedNetwork`. Styles are not applied (`W_STYLES_NOT_IMPORTED`,
340
+ issue #706); apps, properties and images are skipped with `W_CYS_ENTRY_SKIPPED`. Text input is
341
+ refused (`E_CYS_NOT_ZIP`: pass the bytes). `maxUncompressedBytes` (default 2 GiB) and a 1000:1
342
+ ratio limit stop zip bombs (`E_TOO_LARGE`).
343
+
344
+ - **CX2**: the JSON exchange format of NDEx, Cytoscape 3.10+ and Cytoscape Web, read element by
345
+ element so a document longer than one JavaScript string still loads. Every edge is directed;
346
+ node ids are integers (an id beyond 2^53 keeps its digits as a string id, `W_PRECISION`; `"5"` and
347
+ `5.0` read as 5, `W_ID_TEXT_TYPE`). Declared attributes become typed columns under their full
348
+ names (the alias in `origin.id`, the default in `meta.default`); an undeclared attribute is typed
349
+ from its values (`W_CX2_UNDECLARED_ATTRIBUTE`), a value of the wrong type is `E_BAD_VALUE` and its
350
+ cell is unset. `name` is the label; `x` / `y` are the position, stored y-up (y negated, as for every
351
+ Cytoscape-family format) and negated back on export; `z` is a stacking order in the `z` column
352
+ (`zAs: "position"` puts it in the position). Per-element visual values (`nodeBypasses`,
353
+ `edgeBypasses`) are one column per visual property (origin namespace `cx2.bypass`); style rules
354
+ (`visualProperties`, `visualEditorProperties`) and opaque aspects are kept verbatim in
355
+ `meta.extra.cx2.opaque` and written back, but not applied (`W_STYLES_NOT_IMPORTED`). A missing
356
+ `status` is `E_CX2_NO_STATUS`, `success: false` is fatal (`E_STATUS_FAILED`), an edge to an unknown
357
+ node is `E_UNKNOWN_NODE` (`addMissingNodes: true` creates it, as Cytoscape does). The exporter
358
+ refuses non-integer node ids unless `sanitizeIds: "mangle"`, which keeps the original in a
359
+ `graphty:originalId` attribute the importer turns back into the id; NaN and the infinities are
360
+ written as null (`W_CX2_NONFINITE_AS_NULL`), nested values as JSON text (`W_CX2_JSON_AS_STRING`).
361
+
362
+ - **CX** (version 1, `@graphty/graph-io/cx`, `.cx`; read only -- CX2 is what NDEx and Cytoscape
363
+ write today): aspect fragments in any order, read element by element. Ids follow the CX2 rule;
364
+ `n` is the `name` label, `r` is `represents`, `i` is `interaction`; attributes are typed by their
365
+ `d` with Cytoscape's value rule (`""` and `"null"` are unset, `"NaN"` is NaN in a double), several
366
+ types for one name widen (`W_WIDENED`). A collection (several `cySubNetworks`) is one graph per
367
+ subnetwork: `listGraphs()` lists them, `import()` reads the one `graphIndex` / `graphName` picks
368
+ (the first by default, `W_MULTIPLE_GRAPHS`), `importAll()` reads them all; a subnetwork's own
369
+ values (`s`) beat the shared ones, and nodes or edges no subnetwork holds are not read
370
+ (`W_CX_ROOT_ONLY`). Positions come from the subnetwork's view (y negated to y-up,
371
+ other views as `position@2`, ...); `cyGroups` give `parent` or `parents` (a group whose id is
372
+ not a node gets one, `W_CX_GROUP_NODE_ADDED`); per-element `cyVisualProperties` of that view are
373
+ one column per property (origin namespace `cx.bypass`) and style rules are kept in `meta.extra.cx`
374
+ (`W_STYLES_NOT_IMPORTED`); citations and supports become the extension tables `cx:citations` /
375
+ `cx:supports`. Old aspect names (`visualProperties`, `subNetworks`, ...) are read with
376
+ `W_CX_OLD_ASPECT_NAME`; a CX2 document is refused naming the CX2 importer (`E_CX_NOT_CX`).
299
377
 
300
378
  ## Format detection
301
379
 
@@ -1,6 +1,6 @@
1
1
  import { GraphFormatError } from "@graphty/graph-format";
2
- import { al as XML_ILLEGAL_CHAR_CODE } from "./report-BOk0p5y8.js";
3
- import { q as isNameChar } from "./writer-GAdltGmC.js";
2
+ import { a0 as XML_ILLEGAL_CHAR_CODE } from "./report-B1z4WT9e.js";
3
+ import { b as isNameChar } from "./export-Bh60Dv-n.js";
4
4
  class XmlSyntaxError extends Error {
5
5
  /**
6
6
  * Create the error.
@@ -13,6 +13,9 @@ class XmlSyntaxError extends Error {
13
13
  this.line = line;
14
14
  }
15
15
  }
16
+ const BARE_AMPERSAND_LOOKAHEAD = 7;
17
+ const CHAR_REFERENCE = /^&#(?:[xX]([0-9a-fA-F]{1,6})|([0-9]{1,7}));/;
18
+ const TRAILING_CHAR_REFERENCE = /&#(?:[xX]([0-9a-fA-F]{1,6})|([0-9]{1,7}));$/;
16
19
  const NAMED_ENTITIES = {
17
20
  lt: "<",
18
21
  gt: ">",
@@ -136,7 +139,7 @@ function isXmlName(text) {
136
139
  function isXmlChar(cp) {
137
140
  return cp === 9 || cp === 10 || cp === 13 || cp >= 32 && cp <= 55295 || cp >= 57344 && cp <= 65533 || cp >= 65536 && cp <= 1114111;
138
141
  }
139
- function decodeEntities(raw, line) {
142
+ function decodeEntities(raw, line, repairs) {
140
143
  let amp = raw.indexOf("&");
141
144
  if (amp < 0) {
142
145
  return raw;
@@ -146,6 +149,14 @@ function decodeEntities(raw, line) {
146
149
  while (amp >= 0) {
147
150
  out += raw.slice(start, amp);
148
151
  const semi = raw.indexOf(";", amp + 1);
152
+ if (repairs?.bareAmpersand !== void 0 && (semi < 0 || semi - amp > BARE_AMPERSAND_LOOKAHEAD) && // a well-formed character reference longer than the lookahead (&#128512;) is not bare
153
+ !CHAR_REFERENCE.test(raw.slice(amp, amp + 12))) {
154
+ repairs.bareAmpersand(lineAt(raw, amp, line));
155
+ out += "&";
156
+ start = amp + 1;
157
+ amp = raw.indexOf("&", start);
158
+ continue;
159
+ }
149
160
  if (semi < 0) {
150
161
  throw new XmlSyntaxError("unterminated entity reference", line);
151
162
  }
@@ -155,6 +166,14 @@ function decodeEntities(raw, line) {
155
166
  const digits = name.slice(hex ? 2 : 1);
156
167
  const ok = hex ? /^[0-9a-fA-F]{1,6}$/.test(digits) : /^[0-9]{1,7}$/.test(digits);
157
168
  const cp = ok ? Number.parseInt(digits, hex ? 16 : 10) : -1;
169
+ const low = cp >= 55296 && cp <= 56319 ? lowSurrogateAfter(raw, semi + 1, repairs) : null;
170
+ if (low !== null) {
171
+ repairs?.surrogatePair?.(lineAt(raw, amp, line));
172
+ out += String.fromCharCode(cp, low.unit);
173
+ start = low.end;
174
+ amp = raw.indexOf("&", start);
175
+ continue;
176
+ }
158
177
  if (cp < 0 || !isXmlChar(cp)) {
159
178
  throw new XmlSyntaxError(`invalid character reference &${name};`, line);
160
179
  }
@@ -171,6 +190,24 @@ function decodeEntities(raw, line) {
171
190
  }
172
191
  return out + raw.slice(start);
173
192
  }
193
+ function lineAt(raw, at, line) {
194
+ let n = line;
195
+ for (let i = raw.indexOf("\n"); i >= 0 && i < at; i = raw.indexOf("\n", i + 1)) {
196
+ n++;
197
+ }
198
+ return n;
199
+ }
200
+ function lowSurrogateAfter(raw, at, repairs) {
201
+ if (repairs?.surrogatePair === void 0 || raw.charCodeAt(at) !== 38) {
202
+ return null;
203
+ }
204
+ const match = CHAR_REFERENCE.exec(raw.slice(at, at + 12));
205
+ if (match === null) {
206
+ return null;
207
+ }
208
+ const unit = match[1] === void 0 ? Number.parseInt(match[2], 10) : Number.parseInt(match[1], 16);
209
+ return unit >= 56320 && unit <= 57343 ? { unit, end: at + match[0].length } : null;
210
+ }
174
211
  function isWhitespace(text) {
175
212
  for (let i = 0; i < text.length; i++) {
176
213
  if (!isSpace(text.charCodeAt(i))) {
@@ -183,8 +220,8 @@ function localName(name) {
183
220
  const colon = name.lastIndexOf(":");
184
221
  return colon < 0 ? name : name.slice(colon + 1);
185
222
  }
186
- async function tokenizeXml(chunks, handler) {
187
- const tokenizer = new XmlTokenizer(handler);
223
+ async function tokenizeXml(chunks, handler, repairs) {
224
+ const tokenizer = new XmlTokenizer(handler, repairs);
188
225
  for await (const chunk of chunks) {
189
226
  tokenizer.push(chunk);
190
227
  }
@@ -200,8 +237,9 @@ class XmlTokenizer {
200
237
  /**
201
238
  * Create a tokenizer.
202
239
  * @param handler - the event sink
240
+ * @param repairs - the opt-in repairs (XGMML only); none by default
203
241
  */
204
- constructor(handler) {
242
+ constructor(handler, repairs) {
205
243
  this.buffer = "";
206
244
  this.pending = null;
207
245
  this.line = 1;
@@ -214,6 +252,7 @@ class XmlTokenizer {
214
252
  this.rootSeen = false;
215
253
  this.rootClosed = false;
216
254
  this.handler = handler;
255
+ this.repairs = repairs;
217
256
  }
218
257
  /**
219
258
  * Feed one chunk and emit every complete token in it.
@@ -440,6 +479,9 @@ class XmlTokenizer {
440
479
  if (amp >= pos && amp >= length - MAX_ENTITY_LENGTH && buffer.indexOf(";", amp) < 0) {
441
480
  end = amp;
442
481
  }
482
+ if (this.repairs?.surrogatePair !== void 0) {
483
+ end = this.holdHighSurrogate(pos, end);
484
+ }
443
485
  }
444
486
  this.takeText(pos, end);
445
487
  pos = end;
@@ -685,7 +727,7 @@ class XmlTokenizer {
685
727
  this.line
686
728
  );
687
729
  }
688
- attrs.set(attrName, decodeEntities(normalizeAttributeValue(raw), this.line));
730
+ attrs.set(attrName, decodeEntities(normalizeAttributeValue(raw), this.line, this.repairs));
689
731
  i = close + 1;
690
732
  }
691
733
  }
@@ -717,6 +759,22 @@ class XmlTokenizer {
717
759
  }
718
760
  return j >= length && !this.final ? -1 : j;
719
761
  }
762
+ /**
763
+ * Under the surrogate-pair repair, hold back a high-surrogate character reference that ends
764
+ * the text taken so far, so it is decoded together with the low one the next chunk may start with.
765
+ * @param pos - the start of the text
766
+ * @param end - the end of the text that would be taken
767
+ * @returns the end to take up to
768
+ */
769
+ holdHighSurrogate(pos, end) {
770
+ const tail = this.buffer.slice(Math.max(pos, end - 12), end);
771
+ const match = TRAILING_CHAR_REFERENCE.exec(tail);
772
+ if (match === null) {
773
+ return end;
774
+ }
775
+ const unit = match[1] === void 0 ? Number.parseInt(match[2], 10) : Number.parseInt(match[1], 16);
776
+ return unit >= 55296 && unit <= 56319 ? end - match[0].length : end;
777
+ }
720
778
  /**
721
779
  * Move text from the buffer into the current run.
722
780
  * @param start - the start index
@@ -733,7 +791,7 @@ class XmlTokenizer {
733
791
  if (hasIllegalXmlChar(raw)) {
734
792
  throw new XmlSyntaxError("a character XML 1.0 forbids appears in character data", this.line);
735
793
  }
736
- this.text += decodeEntities(raw, this.line);
794
+ this.text += decodeEntities(raw, this.line, this.repairs);
737
795
  this.advanceLine(start, end);
738
796
  }
739
797
  /**
@@ -942,13 +1000,13 @@ function quotePajekLabel(text) {
942
1000
  }
943
1001
  export {
944
1002
  XmlSyntaxError as X,
945
- XmlTokenizer as a,
946
- quoteDotId as b,
947
- isWritableDotText as c,
948
- xmlDeclaredEncoding as d,
949
- isWhitespace as e,
950
- escapeXmlText as f,
951
- escapeXmlAttribute as g,
1003
+ escapeXmlText as a,
1004
+ XmlTokenizer as b,
1005
+ quoteDotId as c,
1006
+ isWritableDotText as d,
1007
+ escapeXmlAttribute as e,
1008
+ xmlDeclaredEncoding as f,
1009
+ isWhitespace as g,
952
1010
  hasIllegalXmlChar as h,
953
1011
  isPajekLabel as i,
954
1012
  decodeGmlString as j,
@@ -960,4 +1018,4 @@ export {
960
1018
  tokenizeXml as t,
961
1019
  xmlIllegalTextNotes as x
962
1020
  };
963
- //# sourceMappingURL=escape-D-gZWO26.js.map
1021
+ //# sourceMappingURL=escape-B-tkk_Cl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"escape-B-tkk_Cl.js","sources":["../../src/common/xml.ts","../../src/common/escape.ts"],"sourcesContent":["/**\n * The streaming XML tokenizer shared by the GEXF and GraphML importers (design sections 8.2 and\n * 8.4): SAX-style start / end / text events over the text chunks of the common reader, so both\n * importers run in one pass with bounded memory and every issue carries a line number.\n *\n * Cost model: every character of the input is scanned once. A token that spans many chunks (a\n * long attribute value, comment, CDATA section or name) resumes where the previous chunk left off\n * instead of re-reading the token from its `<`, and line numbers are counted from a cached next\n * line-break position, so a document without line breaks costs the same as one with them.\n *\n * What it handles: the XML declaration and processing instructions (skipped), comments (skipped),\n * CDATA sections (text), a DOCTYPE with an internal subset (skipped; entity declarations are not\n * expanded, so an unknown entity reference is a syntax error), the five predefined entities and\n * numeric character references (decimal and hexadecimal) in text and attribute values, attribute\n * value whitespace normalisation, end-of-line normalisation (CR LF and lone CR become LF), and\n * well-formedness: matching end tags, one root element, no text outside it, no duplicate\n * attributes, no unterminated markup at the end of the input. Namespaces are not resolved; element\n * and attribute names are reported as written (with their prefix).\n *\n * Why not fast-xml-parser: its XMLParser accepts mismatched and unclosed tags without error, does\n * not decode numeric character references unless the deprecated `htmlEntities` option is set, and\n * its validator (`XMLValidator`, the `parse(xml, true)` overload) and `XMLBuilder` are deprecated in\n * 5.x, which the root lint's `no-deprecated` rule forbids using; so the malformed corpus could not\n * be rejected and attribute values written by the common `escapeXmlAttribute` (`&#10;`) could not\n * be read back.\n */\n\nimport { type Column, type GraphSnapshot } from \"@graphty/graph-format\";\n\nimport { type LossNote } from \"../types.js\";\nimport { XML_ILLEGAL_CHAR_CODE } from \"./codes.js\";\nimport { isNameChar } from \"./export.js\";\n\n/** The events of the tokenizer; every callback is synchronous. */\nexport interface XmlHandler {\n /**\n * An element starts (a self-closing element produces start then end).\n * @param name - the element name as written, prefix included\n * @param attrs - the attributes, entities decoded, in document order\n * @param line - the 1-based line of the `<`\n */\n start(name: string, attrs: ReadonlyMap<string, string>, line: number): void;\n /**\n * An element ends.\n * @param name - the element name\n * @param line - the 1-based line of the end tag (or of the self-closing start tag)\n */\n end(name: string, line: number): void;\n /**\n * Character data between two tags (entities decoded, CDATA included), one call per run;\n * whitespace-only runs are delivered too.\n * @param text - the text\n * @param line - the 1-based line where the run starts\n */\n text(text: string, line: number): void;\n}\n\n/** A well-formedness or syntax error, with the line it was found on. */\nexport class XmlSyntaxError extends Error {\n /** The 1-based line. */\n readonly line: number;\n\n /**\n * Create the error.\n * @param message - a plain-ASCII message\n * @param line - the 1-based line\n */\n constructor(message: string, line: number) {\n super(message);\n this.name = \"XmlSyntaxError\";\n this.line = line;\n }\n}\n\n/**\n * Opt-in repairs of two defects the Cytoscape XGMML writer is known to produce (research note\n * `research-xgmml.md` 3.8 and 5). Each is off unless its callback is given; GEXF and GraphML never\n * pass them, so their documents stay strictly well-formed. The callback is told the line of each\n * repair, so the importer can warn per occurrence.\n */\nexport interface XmlRepairs {\n /**\n * Read an `&` that is not followed by a `;` within the next 7 characters as `&amp;` (Cytoscape's\n * `cytoscape.xgmml.repair.bare.ampersands` lookahead); an `&name;` that does end in time is\n * still decoded, and still fatal when the entity is unknown. A complete numeric character\n * reference is decoded whatever its length (`&#128512;`), where Cytoscape's byte lookahead\n * would turn it into text.\n */\n readonly bareAmpersand?: ((line: number) => void) | undefined;\n /**\n * Join a high-surrogate character reference immediately followed by a low-surrogate one\n * (`&#xd83d;&#xde00;`, which XML 1.0 forbids but Cytoscape writes for astral characters) into\n * the one character they encode; a lone surrogate stays fatal.\n */\n readonly surrogatePair?: ((line: number) => void) | undefined;\n}\n\n/** How far Cytoscape's bare-ampersand repair looks for the `;` that ends an entity reference. */\nconst BARE_AMPERSAND_LOOKAHEAD = 7;\n\n/** A numeric character reference at the start of a text: `&#123;` or `&#x1F;`. */\nconst CHAR_REFERENCE = /^&#(?:[xX]([0-9a-fA-F]{1,6})|([0-9]{1,7}));/;\n\n/** A numeric character reference at the end of a text. */\nconst TRAILING_CHAR_REFERENCE = /&#(?:[xX]([0-9a-fA-F]{1,6})|([0-9]{1,7}));$/;\n\nconst NAMED_ENTITIES: Readonly<Record<string, string>> = {\n lt: \"<\",\n gt: \">\",\n amp: \"&\",\n quot: '\"',\n apos: \"'\",\n};\n\nconst LT = 60;\nconst GT = 62;\nconst SLASH = 47;\nconst EQUALS = 61;\nconst QUOTE = 34;\nconst APOS = 39;\nconst OPEN_BRACKET = 91;\nconst CLOSE_BRACKET = 93;\nconst BANG = 33;\nconst DASH = 45;\n\n/** The longest entity reference held back at a chunk boundary (`&#x10FFFF;` is 10 characters). */\nconst MAX_ENTITY_LENGTH = 16;\n\n/** Markup shorter than this (`<![CDATA[` is 9 characters) cannot be classified yet. */\nconst MIN_DECIDABLE_MARKUP = 9;\n\n/**\n * Whether a char code is XML whitespace (space, tab, LF, CR).\n * @param c - the char code\n * @returns true for whitespace\n */\nfunction isSpace(c: number): boolean {\n return c === 32 || c === 9 || c === 10 || c === 13;\n}\n\n/**\n * Whether a code point may start an XML Name: a NameChar that is not a digit, `-`, `.`, U+00B7,\n * a combining character (U+0300..U+036F) or U+203F / U+2040.\n * @param cp - the code point\n * @returns true for a NameStartChar\n */\nfunction isNameStart(cp: number): boolean {\n if (!isNameChar(cp)) {\n return false;\n }\n if ((cp >= 0x30 && cp <= 0x39) || cp === 0x2d || cp === 0x2e || cp === 0xb7) {\n return false;\n }\n return !(cp >= 0x300 && cp <= 0x36f) && cp !== 0x203f && cp !== 0x2040;\n}\n\n/** ASCII code -> whether it is a NameStartChar / NameChar, for the fast path of readName(). */\nconst ASCII_NAME_START = new Uint8Array(128);\nconst ASCII_NAME_CHAR = new Uint8Array(128);\nfor (let c = 0; c < 128; c++) {\n ASCII_NAME_START[c] = isNameStart(c) ? 1 : 0;\n ASCII_NAME_CHAR[c] = isNameChar(c) ? 1 : 0;\n}\n\n/**\n * Characters XML 1.0 forbids in a document (the Char production): C0 controls other than tab, LF\n * and CR, U+FFFE / U+FFFF, and lone surrogates (the `u` flag makes the surrogate class match only\n * an unpaired one). Built from char codes so no control character appears in the source.\n */\nconst ILLEGAL_CHAR = new RegExp(\n `[${String.fromCharCode(0)}-${String.fromCharCode(8)}${String.fromCharCode(11)}${String.fromCharCode(12)}` +\n `${String.fromCharCode(14)}-${String.fromCharCode(31)}\\\\uFFFE\\\\uFFFF\\\\uD800-\\\\uDFFF]`,\n \"u\",\n);\n\n/**\n * Whether a text holds a character XML 1.0 forbids (see ILLEGAL_CHAR); such a character cannot be\n * written even as a character reference, so a conforming parser rejects the whole document.\n * @param text - the text\n * @returns true when the text cannot appear in an XML 1.0 document\n */\nexport function hasIllegalXmlChar(text: string): boolean {\n return ILLEGAL_CHAR.test(text);\n}\n\n/**\n * The loss notes of the texts a snapshot holds that no XML 1.0 document can carry (see\n * hasIllegalXmlChar): one E_XML_ILLEGAL_CHAR note per column (node, edge and graph string / dict /\n * list-of-text columns) and one for the ids, each counting the affected rows; export() throws on\n * the first such text. Shared by the GEXF and GraphML exporters' check().\n * @param snapshot - the snapshot\n * @returns the notes, empty when every text is writable\n */\nexport function xmlIllegalTextNotes(snapshot: GraphSnapshot): LossNote[] {\n const notes: LossNote[] = [];\n let ids = 0;\n for (let i = 0; i < snapshot.nodeCount; i++) {\n const id = snapshot.ids.idOf(i);\n if (typeof id === \"string\" && hasIllegalXmlChar(id)) {\n ids++;\n }\n }\n if (ids > 0) {\n notes.push(\n Object.freeze({\n code: XML_ILLEGAL_CHAR_CODE,\n message: `${ids} node id(s) hold a character XML 1.0 cannot carry; export() will throw`,\n column: null,\n count: ids,\n }),\n );\n }\n for (const [domain, table] of [\n [\"node\", snapshot.nodes],\n [\"edge\", snapshot.edges],\n [\"graph\", snapshot.graph],\n ] as const) {\n for (const column of table) {\n const bad = countIllegalRows(column);\n if (bad > 0) {\n notes.push(\n Object.freeze({\n code: XML_ILLEGAL_CHAR_CODE,\n message: `${domain} column \"${column.meta.name}\": ${bad} value(s) hold a character XML 1.0 cannot carry; export() will throw`,\n column: column.meta.name,\n count: bad,\n }),\n );\n }\n }\n }\n return notes;\n}\n\n/**\n * How many set rows of a text column hold an XML-illegal character.\n * @param column - the column\n * @returns the count; 0 for a non-text column\n */\nfunction countIllegalRows(column: Column): number {\n let bad = 0;\n if (column.dtype === \"string\" || column.dtype === \"dict\") {\n for (let r = 0; r < column.length; r++) {\n if (column.isSet(r) && hasIllegalXmlChar(column.value(r) as string)) {\n bad++;\n }\n }\n } else if (column.dtype === \"list\" && (column.meta.itemDtype === \"string\" || column.meta.itemDtype === \"dict\")) {\n for (let r = 0; r < column.length; r++) {\n if (\n column.isSet(r) &&\n column.sliceOf(r).some((item) => typeof item === \"string\" && hasIllegalXmlChar(item))\n ) {\n bad++;\n }\n }\n }\n return bad;\n}\n\n/** The encoding pseudo-attribute of an XML declaration at the very start of a document. */\nconst XML_DECLARED_ENCODING = /^<\\?xml\\s[^>]*?\\bencoding\\s*=\\s*[\"']([A-Za-z][A-Za-z0-9._-]*)[\"']/;\n\n/**\n * The encoding an XML document declares in its prolog (`<?xml version=\"1.0\" encoding=\"...\"?>`),\n * for the shared byte decoder (common/input.ts).\n * @param head - the start of the document, decoded as windows-1252\n * @returns the declared label, or null when there is no declaration or it names no encoding\n */\nexport function xmlDeclaredEncoding(head: string): string | null {\n const match = XML_DECLARED_ENCODING.exec(head);\n return match === null ? null : match[1];\n}\n\n/**\n * Whether a text is an XML Name.\n * @param text - the text\n * @returns true for a well-formed name\n */\nexport function isXmlName(text: string): boolean {\n if (text.length === 0) {\n return false;\n }\n let first = true;\n for (const ch of text) {\n const cp = ch.codePointAt(0);\n if (cp === undefined || (first ? !isNameStart(cp) : !isNameChar(cp))) {\n return false;\n }\n first = false;\n }\n return true;\n}\n\n/**\n * Whether a code point is a legal XML 1.0 character.\n * @param cp - the code point\n * @returns true when a character reference may produce it\n */\nfunction isXmlChar(cp: number): boolean {\n return (\n cp === 0x9 ||\n cp === 0xa ||\n cp === 0xd ||\n (cp >= 0x20 && cp <= 0xd7ff) ||\n (cp >= 0xe000 && cp <= 0xfffd) ||\n (cp >= 0x10000 && cp <= 0x10ffff)\n );\n}\n\n/**\n * Decode the predefined entities and character references of a text.\n * @param raw - the text as written\n * @param line - the line, for errors\n * @param repairs - the opt-in repairs (XGMML only); none by default\n * @returns the decoded text\n */\nexport function decodeEntities(raw: string, line: number, repairs?: XmlRepairs): string {\n let amp = raw.indexOf(\"&\");\n if (amp < 0) {\n return raw;\n }\n let out = \"\";\n let start = 0;\n while (amp >= 0) {\n out += raw.slice(start, amp);\n const semi = raw.indexOf(\";\", amp + 1);\n if (\n repairs?.bareAmpersand !== undefined &&\n (semi < 0 || semi - amp > BARE_AMPERSAND_LOOKAHEAD) &&\n // a well-formed character reference longer than the lookahead (&#128512;) is not bare\n !CHAR_REFERENCE.test(raw.slice(amp, amp + 12))\n ) {\n repairs.bareAmpersand(lineAt(raw, amp, line));\n out += \"&\";\n start = amp + 1;\n amp = raw.indexOf(\"&\", start);\n continue;\n }\n if (semi < 0) {\n throw new XmlSyntaxError(\"unterminated entity reference\", line);\n }\n const name = raw.slice(amp + 1, semi);\n if (name.startsWith(\"#\")) {\n const hex = name.startsWith(\"#x\") || name.startsWith(\"#X\");\n const digits = name.slice(hex ? 2 : 1);\n const ok = hex ? /^[0-9a-fA-F]{1,6}$/.test(digits) : /^[0-9]{1,7}$/.test(digits);\n const cp = ok ? Number.parseInt(digits, hex ? 16 : 10) : -1;\n const low = cp >= 0xd800 && cp <= 0xdbff ? lowSurrogateAfter(raw, semi + 1, repairs) : null;\n if (low !== null) {\n repairs?.surrogatePair?.(lineAt(raw, amp, line));\n out += String.fromCharCode(cp, low.unit);\n start = low.end;\n amp = raw.indexOf(\"&\", start);\n continue;\n }\n if (cp < 0 || !isXmlChar(cp)) {\n throw new XmlSyntaxError(`invalid character reference &${name};`, line);\n }\n out += String.fromCodePoint(cp);\n } else {\n const value = NAMED_ENTITIES[name];\n if (value === undefined) {\n throw new XmlSyntaxError(`unknown entity &${name};`, line);\n }\n out += value;\n }\n start = semi + 1;\n amp = raw.indexOf(\"&\", start);\n }\n return out + raw.slice(start);\n}\n\n/**\n * The line of a position inside a text that starts on a known line.\n * @param raw - the text\n * @param at - the position\n * @param line - the line the text starts on\n * @returns the line of the position\n */\nfunction lineAt(raw: string, at: number, line: number): number {\n let n = line;\n for (let i = raw.indexOf(\"\\n\"); i >= 0 && i < at; i = raw.indexOf(\"\\n\", i + 1)) {\n n++;\n }\n return n;\n}\n\n/**\n * The low-surrogate character reference that may follow a high-surrogate one, when the\n * surrogate-pair repair is on.\n * @param raw - the text\n * @param at - where the next reference would start\n * @param repairs - the repairs in force\n * @returns the low surrogate code unit and the index after its reference, or null\n */\nfunction lowSurrogateAfter(\n raw: string,\n at: number,\n repairs: XmlRepairs | undefined,\n): { readonly unit: number; readonly end: number } | null {\n if (repairs?.surrogatePair === undefined || raw.charCodeAt(at) !== 38) {\n return null;\n }\n const match = CHAR_REFERENCE.exec(raw.slice(at, at + 12));\n if (match === null) {\n return null;\n }\n const unit = match[1] === undefined ? Number.parseInt(match[2], 10) : Number.parseInt(match[1], 16);\n return unit >= 0xdc00 && unit <= 0xdfff ? { unit, end: at + match[0].length } : null;\n}\n\n/**\n * Whether a text is whitespace only.\n * @param text - the text\n * @returns true when every character is XML whitespace (also for an empty text)\n */\nexport function isWhitespace(text: string): boolean {\n for (let i = 0; i < text.length; i++) {\n if (!isSpace(text.charCodeAt(i))) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * The local part of a possibly prefixed XML name.\n * @param name - the name as written\n * @returns the text after the last colon, or the name itself\n */\nexport function localName(name: string): string {\n const colon = name.lastIndexOf(\":\");\n return colon < 0 ? name : name.slice(colon + 1);\n}\n\n/**\n * Tokenize XML text arriving in chunks and deliver events to a handler. Throws XmlSyntaxError on\n * malformed input; any error the handler throws propagates unchanged.\n * @param chunks - the text (already UTF-8 decoded, BOM removed)\n * @param handler - the event sink\n * @param repairs - the opt-in repairs (XGMML only); none by default\n */\nexport async function tokenizeXml(\n chunks: AsyncIterable<string>,\n handler: XmlHandler,\n repairs?: XmlRepairs,\n): Promise<void> {\n const tokenizer = new XmlTokenizer(handler, repairs);\n for await (const chunk of chunks) {\n tokenizer.push(chunk);\n }\n tokenizer.finish();\n}\n\n/** The result of parsing one start tag out of the buffer. */\ninterface StartTag {\n /** The element name. */\n readonly name: string;\n /** The attributes. */\n readonly attrs: Map<string, string>;\n /** Whether the tag ends with `/>`. */\n readonly selfClosing: boolean;\n /** The buffer index one past the `>`. */\n readonly end: number;\n}\n\n/** The kinds of markup whose end may lie in a later chunk. */\ntype PendingKind = \"decl\" | \"comment\" | \"cdata\" | \"pi\" | \"endtag\" | \"doctype\" | \"starttag\";\n\n/** The terminator of each fixed-terminator markup kind. */\nconst TERMINATORS: Readonly<Partial<Record<PendingKind, string>>> = {\n comment: \"-->\",\n cdata: \"]]>\",\n pi: \"?>\",\n endtag: \">\",\n};\n\n/**\n * An incomplete piece of markup at the end of the input so far: its text pieces (never joined\n * until the end is found, so a token spanning many chunks costs its length once) and the state\n * the terminator scan is in. `tail` holds the last characters of the pieces a fixed terminator\n * could straddle; `quote` is the open quote character (0 outside a value) of a start tag or a\n * DOCTYPE; `depth`, `comment` and `run` track a DOCTYPE's internal subset.\n */\ninterface Pending {\n kind: PendingKind;\n readonly pieces: string[];\n tail: string;\n quote: number;\n depth: number;\n comment: boolean;\n run: number;\n}\n\n/**\n * The tokenizer state: the unconsumed tail of the input, the current line, the open element\n * stack and the text run being accumulated. `push()` chunks, then `finish()`.\n */\nexport class XmlTokenizer {\n private readonly handler: XmlHandler;\n\n /** Unconsumed input that is not part of a pending token: at most a held-back entity or the last chunk. */\n private buffer = \"\";\n\n /** The markup whose end has not arrived yet, or null. */\n private pending: Pending | null = null;\n\n /** The line number at the start of `buffer` (or of the pending markup). */\n private line = 1;\n\n /**\n * The index of the next line break in `buffer` at or after the last counted position: -2\n * when not yet searched for the current buffer, -1 when the buffer holds no further break.\n */\n private nextBreak = -2;\n\n /** A CR held back from the end of the previous chunk (it may be the first half of CR LF). */\n private pendingCr = false;\n\n /** Whether the input has ended (an incomplete token is then an error, not a wait). */\n private final = false;\n\n /** The text run being accumulated (entities decoded), and the line it started on. */\n private text = \"\";\n\n private textLine = 1;\n\n private readonly stack: string[] = [];\n\n private rootSeen = false;\n\n private rootClosed = false;\n\n private readonly repairs: XmlRepairs | undefined;\n\n /**\n * Create a tokenizer.\n * @param handler - the event sink\n * @param repairs - the opt-in repairs (XGMML only); none by default\n */\n constructor(handler: XmlHandler, repairs?: XmlRepairs) {\n this.handler = handler;\n this.repairs = repairs;\n }\n\n /**\n * Feed one chunk and emit every complete token in it.\n * @param chunk - the text\n */\n push(chunk: string): void {\n let text = chunk;\n if (this.pendingCr) {\n text = `\\r${text}`;\n this.pendingCr = false;\n }\n if (text.endsWith(\"\\r\")) {\n this.pendingCr = true;\n text = text.slice(0, -1);\n }\n if (text.includes(\"\\r\")) {\n text = text.replace(/\\r\\n?/g, \"\\n\");\n }\n this.feed(text);\n }\n\n /** Signal the end of the input: flush the last text run and check well-formedness. */\n finish(): void {\n this.final = true;\n if (this.pendingCr) {\n this.pendingCr = false;\n this.feed(\"\\n\");\n } else {\n this.feed(\"\");\n }\n if (this.pending !== null || this.buffer.length > 0) {\n throw new XmlSyntaxError(\"unexpected end of input inside markup\", this.line);\n }\n this.flushText();\n if (this.stack.length > 0) {\n throw new XmlSyntaxError(`unclosed element <${this.stack[this.stack.length - 1]}>`, this.line);\n }\n if (!this.rootSeen) {\n throw new XmlSyntaxError(\"no root element\", this.line);\n }\n }\n\n /**\n * Append normalised text: continue a pending token's terminator scan over the new text alone,\n * and once the token is complete (or when none is pending) scan the buffer for tokens.\n * @param text - the text, line breaks normalised\n */\n private feed(text: string): void {\n const { pending } = this;\n if (pending === null) {\n this.buffer = this.buffer.length === 0 ? text : this.buffer + text;\n this.nextBreak = -2;\n this.scan();\n return;\n }\n if (pending.kind === \"decl\") {\n // fewer than MIN_DECIDABLE_MARKUP characters of markup: the kind is decided once enough arrived\n this.pending = null;\n this.buffer = pending.pieces.join(\"\") + text;\n this.nextBreak = -2;\n this.scan();\n return;\n }\n const end = this.scanPending(pending, text);\n if (end < 0) {\n if (text.length > 0) {\n pending.pieces.push(text);\n }\n if (this.final) {\n throw new XmlSyntaxError(\"unexpected end of input inside markup\", this.line);\n }\n return;\n }\n this.pending = null;\n pending.pieces.push(text.slice(0, end));\n this.buffer = pending.pieces.join(\"\") + text.slice(end);\n this.nextBreak = -2;\n this.scan();\n }\n\n /**\n * Continue the terminator scan of a pending token over new text.\n * @param pending - the pending token\n * @param text - the new text\n * @returns the index in `text` one past the token's end, or -1 when it does not end there\n */\n private scanPending(pending: Pending, text: string): number {\n switch (pending.kind) {\n case \"starttag\":\n return this.scanStartTag(pending, text, 0);\n case \"doctype\":\n return this.scanDoctype(pending, text, 0);\n case \"decl\":\n return -1;\n default: {\n const terminator = TERMINATORS[pending.kind] ?? \">\";\n const probe = pending.tail + text;\n const at = probe.indexOf(terminator);\n if (at < 0) {\n pending.tail = probe.slice(Math.max(0, probe.length - (terminator.length - 1)));\n return -1;\n }\n return at + terminator.length - pending.tail.length;\n }\n }\n }\n\n /**\n * Scan text for the `>` that ends a start tag, skipping quoted attribute values (the quote\n * state survives between calls).\n * @param pending - the pending token\n * @param text - the text\n * @param from - where to start\n * @returns the index one past the `>`, or -1\n */\n private scanStartTag(pending: Pending, text: string, from: number): number {\n let { quote } = pending;\n const n = text.length;\n let i = from;\n while (i < n) {\n if (quote !== 0) {\n // inside an attribute value: jump to its closing quote\n const close = text.indexOf(String.fromCharCode(quote), i);\n if (close < 0) {\n break;\n }\n quote = 0;\n i = close + 1;\n continue;\n }\n const c = text.charCodeAt(i);\n if (c === QUOTE || c === APOS) {\n quote = c;\n } else if (c === GT) {\n pending.quote = 0;\n return i + 1;\n }\n i++;\n }\n pending.quote = quote;\n return -1;\n }\n\n /**\n * Scan text for the `>` that ends a DOCTYPE declaration, skipping a bracketed internal subset,\n * quoted literals and comments inside the subset. A character state machine, so the state\n * (`depth`, `quote`, `comment`, and `run`, the progress through a `<!--` or the dashes before\n * a `-->`) survives between calls and nothing is re-read.\n * @param pending - the pending token\n * @param text - the text\n * @param from - where to start\n * @returns the index one past the `>`, or -1\n */\n private scanDoctype(pending: Pending, text: string, from: number): number {\n let { quote, depth, comment, run } = pending;\n for (let i = from; i < text.length; i++) {\n const c = text.charCodeAt(i);\n if (comment) {\n if (c === DASH) {\n run++;\n } else if (c === GT && run >= 2) {\n comment = false;\n run = 0;\n } else {\n run = 0;\n }\n continue;\n }\n if (quote !== 0) {\n if (c === quote) {\n quote = 0;\n }\n continue;\n }\n if (depth > 0) {\n if (run === 1 && c === BANG) {\n run = 2;\n continue;\n }\n if (run === 2 && c === DASH) {\n run = 3;\n continue;\n }\n if (run === 3 && c === DASH) {\n comment = true;\n run = 0;\n continue;\n }\n run = 0;\n if (c === LT) {\n run = 1;\n continue;\n }\n }\n if (c === QUOTE || c === APOS) {\n quote = c;\n } else if (c === OPEN_BRACKET) {\n depth++;\n } else if (c === CLOSE_BRACKET) {\n depth--;\n } else if (c === GT && depth <= 0) {\n pending.quote = 0;\n pending.depth = 0;\n pending.comment = false;\n pending.run = 0;\n return i + 1;\n }\n }\n pending.quote = quote;\n pending.depth = depth;\n pending.comment = comment;\n pending.run = run;\n return -1;\n }\n\n /**\n * Consume every complete token at the front of the buffer; an incomplete token at its end\n * becomes the pending token (its text moved out of the buffer), a possibly split entity\n * reference is held back in the buffer.\n */\n private scan(): void {\n const { buffer } = this;\n const { length } = buffer;\n let pos = 0;\n let incomplete = false;\n for (;;) {\n const lt = buffer.indexOf(\"<\", pos);\n if (lt < 0) {\n let end = length;\n if (!this.final) {\n // an entity reference may be split across chunks: hold back from its \"&\"\n const amp = buffer.lastIndexOf(\"&\");\n if (amp >= pos && amp >= length - MAX_ENTITY_LENGTH && buffer.indexOf(\";\", amp) < 0) {\n end = amp;\n }\n if (this.repairs?.surrogatePair !== undefined) {\n end = this.holdHighSurrogate(pos, end);\n }\n }\n this.takeText(pos, end);\n pos = end;\n break;\n }\n if (lt > pos) {\n this.takeText(pos, lt);\n pos = lt;\n }\n const next = this.consumeMarkup(pos);\n if (next < 0) {\n incomplete = true;\n break;\n }\n pos = next;\n }\n if (incomplete) {\n this.pending = this.startPending(buffer, pos);\n this.buffer = \"\";\n } else {\n this.buffer = pos === 0 ? buffer : buffer.slice(pos);\n }\n this.nextBreak = -2;\n }\n\n /**\n * Turn the incomplete markup at `pos` into a pending token, running the terminator scan over\n * the part already in the buffer so later chunks are scanned alone.\n * @param buffer - the buffer\n * @param pos - the index of the `<`\n * @returns the pending token\n */\n private startPending(buffer: string, pos: number): Pending {\n const piece = pos === 0 ? buffer : buffer.slice(pos);\n const pending: Pending = {\n kind: \"starttag\",\n pieces: [piece],\n tail: \"\",\n quote: 0,\n depth: 0,\n comment: false,\n run: 0,\n };\n if (piece.length < MIN_DECIDABLE_MARKUP) {\n // too short to tell a comment from a start tag: wait for more before choosing a scan\n pending.kind = \"decl\";\n return pending;\n }\n if (piece.startsWith(\"<!--\")) {\n pending.kind = \"comment\";\n } else if (piece.startsWith(\"<![CDATA[\")) {\n pending.kind = \"cdata\";\n } else if (piece.startsWith(\"<!DOCTYPE\")) {\n pending.kind = \"doctype\";\n } else if (piece.startsWith(\"<!\")) {\n pending.kind = \"decl\";\n return pending;\n } else if (piece.startsWith(\"<?\")) {\n pending.kind = \"pi\";\n } else if (piece.startsWith(\"</\")) {\n pending.kind = \"endtag\";\n }\n // the part in the buffer holds no terminator (consumeMarkup said so); record the scan state\n switch (pending.kind) {\n case \"starttag\":\n this.scanStartTag(pending, piece, 1);\n break;\n case \"doctype\":\n this.scanDoctype(pending, piece, 9);\n break;\n default: {\n const terminator = TERMINATORS[pending.kind] ?? \">\";\n pending.tail = piece.slice(Math.max(0, piece.length - (terminator.length - 1)));\n break;\n }\n }\n return pending;\n }\n\n /**\n * Consume the markup starting at `pos` (a `<`).\n * @param pos - the index of the `<`\n * @returns the index after the markup, or -1 when the buffer ends before the markup does\n */\n private consumeMarkup(pos: number): number {\n const { buffer } = this;\n if (buffer.startsWith(\"<!\", pos)) {\n if (buffer.length - pos < MIN_DECIDABLE_MARKUP && !this.final) {\n // \"<![CDATA[\" is 9 characters; wait until the kind of declaration is decidable\n return -1;\n }\n if (buffer.startsWith(\"<!--\", pos)) {\n const end = buffer.indexOf(\"-->\", pos + 4);\n if (end < 0) {\n return -1;\n }\n this.advanceLine(pos, end + 3);\n return end + 3;\n }\n if (buffer.startsWith(\"<![CDATA[\", pos)) {\n const end = buffer.indexOf(\"]]>\", pos + 9);\n if (end < 0) {\n return -1;\n }\n if (this.text.length === 0) {\n this.textLine = this.line;\n }\n const cdata = buffer.slice(pos + 9, end);\n if (hasIllegalXmlChar(cdata)) {\n throw new XmlSyntaxError(\"a character XML 1.0 forbids appears in a CDATA section\", this.line);\n }\n this.text += cdata;\n this.advanceLine(pos, end + 3);\n return end + 3;\n }\n if (!buffer.startsWith(\"<!DOCTYPE\", pos)) {\n throw new XmlSyntaxError(\"unexpected markup declaration\", this.line);\n }\n const state: Pending = {\n kind: \"doctype\",\n pieces: [],\n tail: \"\",\n quote: 0,\n depth: 0,\n comment: false,\n run: 0,\n };\n const end = this.scanDoctype(state, buffer, pos + 9);\n if (end < 0) {\n return -1;\n }\n this.advanceLine(pos, end);\n return end;\n }\n if (buffer.startsWith(\"<?\", pos)) {\n const end = buffer.indexOf(\"?>\", pos + 2);\n if (end < 0) {\n return -1;\n }\n this.advanceLine(pos, end + 2);\n return end + 2;\n }\n if (buffer.startsWith(\"</\", pos)) {\n const end = buffer.indexOf(\">\", pos + 2);\n if (end < 0) {\n return -1;\n }\n const name = buffer.slice(pos + 2, end).trim();\n if (!isXmlName(name)) {\n throw new XmlSyntaxError(`malformed end tag </${name}>`, this.line);\n }\n this.flushText();\n this.endElement(name);\n this.advanceLine(pos, end + 1);\n return end + 1;\n }\n const tag = this.parseStartTag(pos);\n if (tag === null) {\n return -1;\n }\n this.flushText();\n this.startElement(tag.name, tag.attrs);\n if (tag.selfClosing) {\n this.endElement(tag.name);\n }\n this.advanceLine(pos, tag.end);\n return tag.end;\n }\n\n /**\n * Parse a start tag at `pos`.\n * @param pos - the index of the `<`\n * @returns the tag, or null when the buffer ends inside it\n */\n private parseStartTag(pos: number): StartTag | null {\n const { buffer } = this;\n const { length } = buffer;\n let i = pos + 1;\n const nameEnd = this.readName(i);\n if (nameEnd < 0) {\n return null;\n }\n if (nameEnd === i) {\n throw new XmlSyntaxError(\"expected an element name after <\", this.line);\n }\n const name = buffer.slice(i, nameEnd);\n i = nameEnd;\n const attrs = new Map<string, string>();\n for (;;) {\n while (i < length && isSpace(buffer.charCodeAt(i))) {\n i++;\n }\n if (i >= length) {\n return null;\n }\n const c = buffer.charCodeAt(i);\n if (c === GT) {\n return { name, attrs, selfClosing: false, end: i + 1 };\n }\n if (c === SLASH) {\n if (i + 1 >= length) {\n return null;\n }\n if (buffer.charCodeAt(i + 1) !== GT) {\n throw new XmlSyntaxError(`unexpected \"/\" in <${name}>`, this.line);\n }\n return { name, attrs, selfClosing: true, end: i + 2 };\n }\n const attrEnd = this.readName(i);\n if (attrEnd < 0) {\n return null;\n }\n if (attrEnd === i) {\n throw new XmlSyntaxError(`malformed attribute in <${name}>`, this.line);\n }\n const attrName = buffer.slice(i, attrEnd);\n i = attrEnd;\n while (i < length && isSpace(buffer.charCodeAt(i))) {\n i++;\n }\n if (i >= length) {\n return null;\n }\n if (buffer.charCodeAt(i) !== EQUALS) {\n throw new XmlSyntaxError(`attribute ${attrName} of <${name}> has no value`, this.line);\n }\n i++;\n while (i < length && isSpace(buffer.charCodeAt(i))) {\n i++;\n }\n if (i >= length) {\n return null;\n }\n const quote = buffer.charCodeAt(i);\n if (quote !== QUOTE && quote !== APOS) {\n throw new XmlSyntaxError(`attribute ${attrName} of <${name}> is not quoted`, this.line);\n }\n const close = buffer.indexOf(quote === QUOTE ? '\"' : \"'\", i + 1);\n if (close < 0) {\n return null;\n }\n if (attrs.has(attrName)) {\n throw new XmlSyntaxError(`duplicate attribute ${attrName} in <${name}>`, this.line);\n }\n const raw = buffer.slice(i + 1, close);\n if (hasIllegalXmlChar(raw)) {\n throw new XmlSyntaxError(\n `a character XML 1.0 forbids appears in attribute ${attrName} of <${name}>`,\n this.line,\n );\n }\n attrs.set(attrName, decodeEntities(normalizeAttributeValue(raw), this.line, this.repairs));\n i = close + 1;\n }\n }\n\n /**\n * The end of the XML Name starting at `i` (an ASCII table for the common case, the code point\n * classes beyond it).\n * @param i - the start index\n * @returns the index after the name; `i` when no name starts there; -1 when the name may\n * continue past the end of the buffer\n */\n private readName(i: number): number {\n const { buffer } = this;\n const { length } = buffer;\n let j = i;\n while (j < length) {\n const c = buffer.charCodeAt(j);\n if (c < 0x80) {\n if ((j === i ? ASCII_NAME_START[c] : ASCII_NAME_CHAR[c]) === 0) {\n break;\n }\n j++;\n continue;\n }\n const cp = buffer.codePointAt(j);\n if (cp === undefined || (j === i ? !isNameStart(cp) : !isNameChar(cp))) {\n break;\n }\n j += cp > 0xffff ? 2 : 1;\n }\n return j >= length && !this.final ? -1 : j;\n }\n\n /**\n * Under the surrogate-pair repair, hold back a high-surrogate character reference that ends\n * the text taken so far, so it is decoded together with the low one the next chunk may start with.\n * @param pos - the start of the text\n * @param end - the end of the text that would be taken\n * @returns the end to take up to\n */\n private holdHighSurrogate(pos: number, end: number): number {\n const tail = this.buffer.slice(Math.max(pos, end - 12), end);\n const match = TRAILING_CHAR_REFERENCE.exec(tail);\n if (match === null) {\n return end;\n }\n const unit = match[1] === undefined ? Number.parseInt(match[2], 10) : Number.parseInt(match[1], 16);\n return unit >= 0xd800 && unit <= 0xdbff ? end - match[0].length : end;\n }\n\n /**\n * Move text from the buffer into the current run.\n * @param start - the start index\n * @param end - the end index (exclusive)\n */\n private takeText(start: number, end: number): void {\n if (end <= start) {\n return;\n }\n if (this.text.length === 0) {\n this.textLine = this.line;\n }\n const raw = this.buffer.slice(start, end);\n if (hasIllegalXmlChar(raw)) {\n throw new XmlSyntaxError(\"a character XML 1.0 forbids appears in character data\", this.line);\n }\n this.text += decodeEntities(raw, this.line, this.repairs);\n this.advanceLine(start, end);\n }\n\n /**\n * Count the newlines of a consumed range. Ranges are consumed in order, so the next line break\n * is searched for once per buffer and re-searched only after it was passed; a buffer without\n * a further break is searched once and remembered as such.\n * @param start - the start index\n * @param end - the end index (exclusive)\n */\n private advanceLine(start: number, end: number): void {\n let i = this.nextBreak;\n if (i === -1) {\n return;\n }\n if (i === -2 || i < start) {\n i = this.buffer.indexOf(\"\\n\", start);\n }\n while (i >= 0 && i < end) {\n this.line++;\n i = this.buffer.indexOf(\"\\n\", i + 1);\n }\n this.nextBreak = i;\n }\n\n /** Deliver the accumulated text run, if any. */\n private flushText(): void {\n if (this.text.length === 0) {\n return;\n }\n const { text } = this;\n this.text = \"\";\n if (this.stack.length === 0) {\n if (!isWhitespace(text)) {\n throw new XmlSyntaxError(\"text outside the root element\", this.textLine);\n }\n return;\n }\n this.handler.text(text, this.textLine);\n }\n\n /**\n * Open an element.\n * @param name - the element name\n * @param attrs - its attributes\n */\n private startElement(name: string, attrs: Map<string, string>): void {\n if (this.stack.length === 0) {\n if (this.rootClosed) {\n throw new XmlSyntaxError(`a second root element <${name}> follows the document element`, this.line);\n }\n this.rootSeen = true;\n }\n this.stack.push(name);\n this.handler.start(name, attrs, this.line);\n }\n\n /**\n * Close an element, checking that it matches the innermost open one.\n * @param name - the element name\n */\n private endElement(name: string): void {\n const open = this.stack.length > 0 ? this.stack[this.stack.length - 1] : null;\n if (open === null) {\n throw new XmlSyntaxError(`unexpected end tag </${name}>`, this.line);\n }\n if (open !== name) {\n throw new XmlSyntaxError(`end tag </${name}> does not match <${open}>`, this.line);\n }\n this.stack.pop();\n if (this.stack.length === 0) {\n this.rootClosed = true;\n }\n this.handler.end(name, this.line);\n }\n}\n\n/**\n * Attribute value normalisation (XML 1.0 section 3.3.3): a literal tab or line break becomes a\n * space; a character reference to one is kept, which is why this runs before entity decoding.\n * @param raw - the value between the quotes\n * @returns the normalised value\n */\nfunction normalizeAttributeValue(raw: string): string {\n return raw.includes(\"\\n\") || raw.includes(\"\\t\") ? raw.replace(/[\\n\\t]/g, \" \") : raw;\n}\n","/**\n * Id, label and value escaping for the text formats (design section 8.5), one function per\n * syntax, with the inverse where the importer needs it: XML attribute and element text (GEXF,\n * GraphML), GML quoted strings (`\"` and `&` and non-ASCII as `&#NN;` character entities, the\n * NetworkX convention), DOT ids (bare when the grammar allows, quoted with `\\\"` otherwise), RFC\n * 4180 CSV cells and Pajek labels.\n */\n\nimport { GraphFormatError } from \"@graphty/graph-format\";\n\nimport { hasIllegalXmlChar } from \"./xml.js\";\n\nconst XML_TEXT_SPECIAL = /[&<>\\r]/g;\nconst XML_ATTR_SPECIAL = /[&<>\"\\t\\n\\r]/g;\nconst XML_REPLACEMENTS: Readonly<Record<string, string>> = {\n \"&\": \"&amp;\",\n \"<\": \"&lt;\",\n \">\": \"&gt;\",\n '\"': \"&quot;\",\n \"\\t\": \"&#9;\",\n \"\\n\": \"&#10;\",\n \"\\r\": \"&#13;\",\n};\n\n/**\n * Escape text for an XML element body: `&`, `<`, `>` and a carriage return (which XML\n * end-of-line handling would turn into a line feed on every read) as character references. A\n * character XML 1.0 forbids (a C0 control other than tab / LF / CR, U+FFFE, U+FFFF, a lone\n * surrogate) has no XML spelling at all and is E_COLUMN_TYPE; the exporters' check() counts them.\n * @param text - the text\n * @returns the escaped text\n */\nexport function escapeXmlText(text: string): string {\n if (hasIllegalXmlChar(text)) {\n throw illegalXml(text);\n }\n return text.replace(XML_TEXT_SPECIAL, (c) => XML_REPLACEMENTS[c]);\n}\n\n/**\n * Escape text for a double-quoted XML attribute value: `&`, `<`, `>`, `\"` and the whitespace\n * characters attribute normalisation would fold; a character XML 1.0 forbids is E_COLUMN_TYPE.\n * @param text - the text\n * @returns the escaped text\n */\nexport function escapeXmlAttribute(text: string): string {\n if (hasIllegalXmlChar(text)) {\n throw illegalXml(text);\n }\n return text.replace(XML_ATTR_SPECIAL, (c) => XML_REPLACEMENTS[c]);\n}\n\n/**\n * The error of a text no XML 1.0 document can carry.\n * @param text - the text\n * @returns the error\n */\nfunction illegalXml(text: string): GraphFormatError {\n return new GraphFormatError(\"E_COLUMN_TYPE\", \"the text holds a character XML 1.0 cannot carry\", {\n reason: \"xml illegal char\",\n length: text.length,\n });\n}\n\nconst GML_SPECIAL = /[\"&]|[^ -~]/gu;\n\n/**\n * Quote a GML string value: double quotes around the text with `\"`, `&` and every character\n * outside printable ASCII written as `&#NN;` (NetworkX's writer convention, which its reader and\n * Gephi's decode).\n * A lone surrogate cannot be written and is E_COLUMN_TYPE.\n * @param text - the text\n * @returns the quoted GML string\n */\nexport function quoteGmlString(text: string): string {\n const escaped = text.replace(GML_SPECIAL, (c) => {\n const code = c.codePointAt(0);\n if (code === undefined) {\n return c;\n }\n if (code >= 0xd800 && code <= 0xdfff) {\n throw new GraphFormatError(\"E_COLUMN_TYPE\", \"a lone surrogate cannot be written as a GML string\", {\n reason: \"lone surrogate\",\n });\n }\n return `&#${code};`;\n });\n return `\"${escaped}\"`;\n}\n\nconst GML_ENTITY = /&(#[0-9]+|#x[0-9a-fA-F]+|[A-Za-z][A-Za-z0-9]*);/g;\n\n/** The XML entities and the ISO-8859-1 HTML entities (U+00A0..U+00FF), which GML uses for characters above 127. */\nconst GML_NAMED: ReadonlyMap<string, string> = (() => {\n const table = new Map<string, string>([\n [\"amp\", \"&\"],\n [\"quot\", '\"'],\n [\"lt\", \"<\"],\n [\"gt\", \">\"],\n [\"apos\", \"'\"],\n ]);\n const latin1 = (\n \"nbsp iexcl cent pound curren yen brvbar sect uml copy ordf laquo not shy reg macr deg plusmn sup2 \" +\n \"sup3 acute micro para middot cedil sup1 ordm raquo frac14 frac12 frac34 iquest Agrave Aacute Acirc \" +\n \"Atilde Auml Aring AElig Ccedil Egrave Eacute Ecirc Euml Igrave Iacute Icirc Iuml ETH Ntilde Ograve \" +\n \"Oacute Ocirc Otilde Ouml times Oslash Ugrave Uacute Ucirc Uuml Yacute THORN szlig agrave aacute \" +\n \"acirc atilde auml aring aelig ccedil egrave eacute ecirc euml igrave iacute icirc iuml eth ntilde \" +\n \"ograve oacute ocirc otilde ouml divide oslash ugrave uacute ucirc uuml yacute thorn yuml\"\n ).split(\" \");\n latin1.forEach((name, i) => {\n table.set(name, String.fromCharCode(0xa0 + i));\n });\n return table;\n})();\n\n/**\n * Decode the character entities of a GML string body (the inverse of quoteGmlString on the text\n * between the quotes): numeric references, the XML entities and the ISO-8859-1 HTML entities. An\n * unknown named entity is left as written and handed to `onUnknown`.\n * @param body - the text between the quotes\n * @param onUnknown - called with each unknown named entity (`&name;`), when given\n * @returns the decoded text\n */\nexport function decodeGmlString(body: string, onUnknown?: (entity: string) => void): string {\n return body.replace(GML_ENTITY, (whole, entity: string) => {\n if (entity.startsWith(\"#x\")) {\n return String.fromCodePoint(Number.parseInt(entity.slice(2), 16));\n }\n if (entity.startsWith(\"#\")) {\n return String.fromCodePoint(Number.parseInt(entity.slice(1), 10));\n }\n const known = GML_NAMED.get(entity);\n if (known === undefined) {\n onUnknown?.(whole);\n return whole;\n }\n return known;\n });\n}\n\nconst DOT_NUMERAL = /^-?(\\.[0-9]+|[0-9]+(\\.[0-9]*)?)$/;\nconst DOT_KEYWORDS: ReadonlySet<string> = new Set([\"node\", \"edge\", \"graph\", \"digraph\", \"subgraph\", \"strict\"]);\n\n/**\n * Whether a text is a DOT ID that needs no quotes: an alphanumeric identifier not starting with\n * a digit, or a numeral, and not a keyword (case-insensitive).\n * @param text - the text\n * @returns true when the text can be written bare\n */\nexport function isBareDotId(text: string): boolean {\n if (DOT_KEYWORDS.has(text.toLowerCase())) {\n return false;\n }\n return isDotIdentifier(text) || DOT_NUMERAL.test(text);\n}\n\n/**\n * Whether a text is a DOT identifier: a letter, underscore or any character of code 128 and\n * above, followed by letters, digits, underscores or such characters.\n * @param text - the text\n * @returns true for a bare identifier\n */\nfunction isDotIdentifier(text: string): boolean {\n if (text.length === 0) {\n return false;\n }\n for (let i = 0; i < text.length; i++) {\n const c = text.charCodeAt(i);\n const letter = (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || c === 95 || c >= 128;\n const digit = c >= 48 && c <= 57;\n if (!letter && (i === 0 || !digit)) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * Whether a text can be written as a DOT ID at all. Graphviz's scanner consumes a backslash pair\n * `\\\\` as one unit, `\\\"` as an escaped quote and a backslash before a line break as a line\n * continuation (both removed), left to right, so a backslash that precedes a double quote or a\n * line break, or ends the text, cannot be written: the written `\\\\\"` reads as a pair and a closing\n * quote, a backslash before a line break vanishes with the break, and a trailing backslash escapes\n * the closing quote. Every other text is writable; quoteDotId() writes it.\n * @param text - the id, name or value text\n * @returns true when quoteDotId(text) reads back as `text`\n */\nexport function isWritableDotText(text: string): boolean {\n return !text.endsWith(\"\\\\\") && !text.includes('\\\\\"') && !/\\\\[\\r\\n]/.test(text);\n}\n\n/**\n * Write a DOT ID: bare when the grammar allows, otherwise double-quoted with `\"` escaped as `\\\"`.\n * In DOT quoted strings the dyad `\\\"` is the only escape; every other character, a backslash and\n * a raw line break included, is kept as written, so nothing else is rewritten. A text ending in a\n * backslash has no DOT spelling (isWritableDotText); the caller refuses it before writing.\n * @param text - the id or label text\n * @returns the DOT ID\n */\nexport function quoteDotId(text: string): string {\n if (isBareDotId(text)) {\n return text;\n }\n return `\"${text.replace(/\"/g, '\\\\\"')}\"`;\n}\n\n/**\n * Write a set CSV cell per RFC 4180: quoted with `\"` doubled when the text contains the\n * delimiter, a quote, a CR or LF, or leading / trailing whitespace; bare otherwise. The empty\n * string is written as the quoted empty cell `\"\"`, so the importers can tell a set empty string\n * (and an empty-string node id, legal under design section 4.1) from an unset cell, which every\n * exporter writes as nothing between the delimiters.\n * @param text - the cell text of a set cell\n * @param delimiter - the field delimiter (default \",\")\n * @returns the cell as written\n */\nexport function quoteCsvCell(text: string, delimiter = \",\"): string {\n if (text.length === 0) {\n return '\"\"';\n }\n if (\n !text.includes(delimiter) &&\n !text.includes('\"') &&\n !text.includes(\"\\n\") &&\n !text.includes(\"\\r\") &&\n text === text.trim()\n ) {\n return text;\n }\n return `\"${text.replace(/\"/g, '\"\"')}\"`;\n}\n\n/**\n * Whether a text can be a Pajek label: Pajek has no escape mechanism inside its double-quoted\n * labels, so a text containing a double quote, a CR or an LF cannot be written.\n * @param text - the label text\n * @returns true when quotePajekLabel() can write it\n */\nexport function isPajekLabel(text: string): boolean {\n return !text.includes('\"') && !text.includes(\"\\n\") && !text.includes(\"\\r\");\n}\n\n/**\n * Write a Pajek label: bare when it is a single run of non-space, non-quote characters that does\n * not start with `[` (a bare `[` opens a time set, which the reader groups up to its `]`),\n * otherwise double-quoted. E_UNSUPPORTED (reason \"pajek label\") for a text isPajekLabel() rejects;\n * the exporter's check() counts those.\n * @param text - the label text\n * @returns the label as written\n */\nexport function quotePajekLabel(text: string): string {\n if (!isPajekLabel(text)) {\n throw new GraphFormatError(\"E_UNSUPPORTED\", \"a Pajek label cannot contain a double quote or a line break\", {\n reason: \"pajek label\",\n value: text,\n });\n }\n if (text.length > 0 && !/[\\s\"]/.test(text) && !text.startsWith(\"[\")) {\n return text;\n }\n return `\"${text}\"`;\n}\n"],"names":["end"],"mappings":";;;AA0DO,MAAM,uBAAuB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAStC,YAAY,SAAiB,MAAc;AACvC,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EAChB;AACJ;AA0BA,MAAM,2BAA2B;AAGjC,MAAM,iBAAiB;AAGvB,MAAM,0BAA0B;AAEhC,MAAM,iBAAmD;AAAA,EACrD,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,MAAM;AAAA,EACN,MAAM;AACV;AAEA,MAAM,KAAK;AACX,MAAM,KAAK;AACX,MAAM,QAAQ;AACd,MAAM,SAAS;AACf,MAAM,QAAQ;AACd,MAAM,OAAO;AACb,MAAM,eAAe;AACrB,MAAM,gBAAgB;AACtB,MAAM,OAAO;AACb,MAAM,OAAO;AAGb,MAAM,oBAAoB;AAG1B,MAAM,uBAAuB;AAO7B,SAAS,QAAQ,GAAoB;AACjC,SAAO,MAAM,MAAM,MAAM,KAAK,MAAM,MAAM,MAAM;AACpD;AAQA,SAAS,YAAY,IAAqB;AACtC,MAAI,CAAC,WAAW,EAAE,GAAG;AACjB,WAAO;AAAA,EACX;AACA,MAAK,MAAM,MAAQ,MAAM,MAAS,OAAO,MAAQ,OAAO,MAAQ,OAAO,KAAM;AACzE,WAAO;AAAA,EACX;AACA,SAAO,EAAE,MA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