@graphty/graph-io 0.3.47 → 0.3.48
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.
- package/dist/chunks/{approximations-wWjCRzKj.js → approximations-C2riR4NT.js} +2 -2
- package/dist/chunks/{approximations-wWjCRzKj.js.map → approximations-C2riR4NT.js.map} +1 -1
- package/dist/chunks/{block-DiGq58c3.js → block-Cu22ewuS.js} +92 -21
- package/dist/chunks/block-Cu22ewuS.js.map +1 -0
- package/dist/chunks/{choose--jM0yYCo.js → choose-Cdx6Enl2.js} +3 -3
- package/dist/chunks/{choose--jM0yYCo.js.map → choose-Cdx6Enl2.js.map} +1 -1
- package/dist/chunks/codes-CV_Bhcyi.js +153 -0
- package/dist/chunks/codes-CV_Bhcyi.js.map +1 -0
- package/dist/chunks/{constants-BKwqelYD.js → constants-D0LqcsLJ.js} +2 -2
- package/dist/chunks/{constants-BKwqelYD.js.map → constants-D0LqcsLJ.js.map} +1 -1
- package/dist/chunks/context-cgmmOxZ2.js +663 -0
- package/dist/chunks/context-cgmmOxZ2.js.map +1 -0
- package/dist/chunks/credentials-BiQsnMTb.js +347 -0
- package/dist/chunks/credentials-BiQsnMTb.js.map +1 -0
- package/dist/chunks/cx-export-BEeF6ymo.js +259 -0
- package/dist/chunks/cx-export-BEeF6ymo.js.map +1 -0
- package/dist/chunks/descriptor-BJ-W0Jd-.js +137 -0
- package/dist/chunks/descriptor-BJ-W0Jd-.js.map +1 -0
- package/dist/chunks/descriptor-C-YDhtsn.js +48 -0
- package/dist/chunks/descriptor-C-YDhtsn.js.map +1 -0
- package/dist/chunks/{emit-CwU8cUmG.js → emit-CD8xnY8s.js} +70 -10
- package/dist/chunks/emit-CD8xnY8s.js.map +1 -0
- package/dist/chunks/{escape-CgzxiYPg.js → escape-DH2Egt-l.js} +12 -12
- package/dist/chunks/{escape-CgzxiYPg.js.map → escape-DH2Egt-l.js.map} +1 -1
- package/dist/chunks/{export-BvqAXCKh.js → export-CZ7VRm4I.js} +53 -1443
- package/dist/chunks/export-CZ7VRm4I.js.map +1 -0
- package/dist/chunks/{exporter-DndFlGSa.js → exporter-BIdaoIgh.js} +7 -6
- package/dist/chunks/{exporter-DndFlGSa.js.map → exporter-BIdaoIgh.js.map} +1 -1
- package/dist/chunks/{exporter-CJgfhF-l.js → exporter-ChjL5fmP.js} +8 -7
- package/dist/chunks/{exporter-CJgfhF-l.js.map → exporter-ChjL5fmP.js.map} +1 -1
- package/dist/chunks/{exporter--Mk9gXCJ.js → exporter-Dcw7Ldtq.js} +6 -4
- package/dist/chunks/{exporter--Mk9gXCJ.js.map → exporter-Dcw7Ldtq.js.map} +1 -1
- package/dist/chunks/exporter-DtVU80Fa.js +1008 -0
- package/dist/chunks/exporter-DtVU80Fa.js.map +1 -0
- package/dist/chunks/{exporter-CrDWIyiq.js → exporter-bxxjOrDZ.js} +11 -9
- package/dist/chunks/{exporter-CrDWIyiq.js.map → exporter-bxxjOrDZ.js.map} +1 -1
- package/dist/chunks/format-BMS-1Nxb.js +64 -0
- package/dist/chunks/format-BMS-1Nxb.js.map +1 -0
- package/dist/chunks/{generic-Dq1ntt9q.js → generic-CP6YD34u.js} +4 -4
- package/dist/chunks/{generic-Dq1ntt9q.js.map → generic-CP6YD34u.js.map} +1 -1
- package/dist/chunks/{importer-DiZRmOQG.js → importer-B87_fmVx.js} +13 -17
- package/dist/chunks/importer-B87_fmVx.js.map +1 -0
- package/dist/chunks/{importer-BSvfrX_h.js → importer-Bji2MeWr.js} +18 -1014
- package/dist/chunks/importer-Bji2MeWr.js.map +1 -0
- package/dist/chunks/{importer-COTK9Tsl.js → importer-CB_zV5_L.js} +14 -11
- package/dist/chunks/importer-CB_zV5_L.js.map +1 -0
- package/dist/chunks/{importer-e6LGpqHB.js → importer-CVT-JyDE.js} +12 -9
- package/dist/chunks/importer-CVT-JyDE.js.map +1 -0
- package/dist/chunks/{importer-yh_aBCU6.js → importer-Cyy6UseH.js} +7 -6
- package/dist/chunks/{importer-yh_aBCU6.js.map → importer-Cyy6UseH.js.map} +1 -1
- package/dist/chunks/{importer-iFYPEKaJ.js → importer-DPZDN40-.js} +14 -10
- package/dist/chunks/{importer-iFYPEKaJ.js.map → importer-DPZDN40-.js.map} +1 -1
- package/dist/chunks/{importer-CMmeMWlC.js → importer-e3huMZbm.js} +8 -260
- package/dist/chunks/importer-e3huMZbm.js.map +1 -0
- package/dist/chunks/input-Ccg9I22A.js +1397 -0
- package/dist/chunks/input-Ccg9I22A.js.map +1 -0
- package/dist/chunks/{json-elements-DJZRZ6jd.js → json-elements-By172SVq.js} +4 -4
- package/dist/chunks/{json-elements-DJZRZ6jd.js.map → json-elements-By172SVq.js.map} +1 -1
- package/dist/chunks/{lexicon-CT69Kd87.js → lexicon-u2SI5xcx.js} +19 -5
- package/dist/chunks/lexicon-u2SI5xcx.js.map +1 -0
- package/dist/chunks/{ontology-export-G4MqRdux.js → ontology-export-BwgMyuF0.js} +4 -3
- package/dist/chunks/{ontology-export-G4MqRdux.js.map → ontology-export-BwgMyuF0.js.map} +1 -1
- package/dist/chunks/{records-CiaWZrFH.js → records-Cgvxz-Vx.js} +2 -2
- package/dist/chunks/{records-CiaWZrFH.js.map → records-Cgvxz-Vx.js.map} +1 -1
- package/dist/chunks/{format-BpQBx8MZ.js → report-CgdsL9Hb.js} +72 -129
- package/dist/chunks/report-CgdsL9Hb.js.map +1 -0
- package/dist/chunks/sigv4-LkAzsLAu.js +247 -0
- package/dist/chunks/sigv4-LkAzsLAu.js.map +1 -0
- package/dist/chunks/{styles-BQnsga7p.js → styles-CaABMoO1.js} +76 -43
- package/dist/chunks/styles-CaABMoO1.js.map +1 -0
- package/dist/chunks/{styles-D3fRphrO.js → styles-P_gmFAOi.js} +101 -21
- package/dist/chunks/styles-P_gmFAOi.js.map +1 -0
- package/dist/chunks/{styles-yed-BF5x3_Y5.js → styles-yed-Cs1nmrjn.js} +60 -20
- package/dist/chunks/styles-yed-Cs1nmrjn.js.map +1 -0
- package/dist/chunks/{text-CzJNFOS9.js → text-BuKQVMz2.js} +2 -2
- package/dist/chunks/{text-CzJNFOS9.js.map → text-BuKQVMz2.js.map} +1 -1
- package/dist/chunks/{writer-DMKvthQE.js → writer-DvHTl36J.js} +5 -4
- package/dist/chunks/writer-DvHTl36J.js.map +1 -0
- package/dist/csv.js +7 -5
- package/dist/csv.js.map +1 -1
- package/dist/cx.js +5 -4
- package/dist/cx.js.map +1 -1
- package/dist/cx2.js +2 -2
- package/dist/cys.js +1 -1
- package/dist/dot.js +2 -2
- package/dist/gexf.js +7 -5
- package/dist/gexf.js.map +1 -1
- package/dist/gml.js +16 -13
- package/dist/gml.js.map +1 -1
- package/dist/graph-io.js +1181 -224
- package/dist/graph-io.js.map +1 -1
- package/dist/graphml.js +3 -3
- package/dist/json.js +1 -1
- package/dist/neo4j.js +6 -4
- package/dist/neo4j.js.map +1 -1
- package/dist/obo.js +1 -1
- package/dist/pajek.js +1 -1
- package/dist/sources-cypher.d.ts +1 -0
- package/dist/sources-cypher.js +1236 -0
- package/dist/sources-cypher.js.map +1 -0
- package/dist/sources-ndex.d.ts +1 -0
- package/dist/sources-ndex.js +278 -0
- package/dist/sources-ndex.js.map +1 -0
- package/dist/sources-rest.d.ts +1 -0
- package/dist/sources-rest.js +1367 -0
- package/dist/sources-rest.js.map +1 -0
- package/dist/src/common/report.d.ts +6 -3
- package/dist/src/common/report.d.ts.map +1 -1
- package/dist/src/common/report.js +15 -9
- package/dist/src/common/report.js.map +1 -1
- package/dist/src/formats/cx/styles.d.ts.map +1 -1
- package/dist/src/formats/cx/styles.js +1 -0
- package/dist/src/formats/cx/styles.js.map +1 -1
- package/dist/src/formats/dot/styles.d.ts.map +1 -1
- package/dist/src/formats/dot/styles.js +3 -1
- package/dist/src/formats/dot/styles.js.map +1 -1
- package/dist/src/formats/gexf/styles.d.ts +29 -12
- package/dist/src/formats/gexf/styles.d.ts.map +1 -1
- package/dist/src/formats/gexf/styles.js +160 -31
- package/dist/src/formats/gexf/styles.js.map +1 -1
- package/dist/src/formats/gml/styles.d.ts.map +1 -1
- package/dist/src/formats/gml/styles.js +5 -4
- package/dist/src/formats/gml/styles.js.map +1 -1
- package/dist/src/formats/graphml/styles-plain.d.ts.map +1 -1
- package/dist/src/formats/graphml/styles-plain.js +3 -3
- package/dist/src/formats/graphml/styles-plain.js.map +1 -1
- package/dist/src/formats/graphml/styles-yed.d.ts.map +1 -1
- package/dist/src/formats/graphml/styles-yed.js +89 -19
- package/dist/src/formats/graphml/styles-yed.js.map +1 -1
- package/dist/src/formats/pajek/styles.d.ts.map +1 -1
- package/dist/src/formats/pajek/styles.js +1 -0
- package/dist/src/formats/pajek/styles.js.map +1 -1
- package/dist/src/formats/xgmml/styles.d.ts.map +1 -1
- package/dist/src/formats/xgmml/styles.js +1 -0
- package/dist/src/formats/xgmml/styles.js.map +1 -1
- package/dist/src/index.d.ts +8 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +9 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/registry.d.ts +173 -1
- package/dist/src/registry.d.ts.map +1 -1
- package/dist/src/registry.js +196 -1
- package/dist/src/registry.js.map +1 -1
- package/dist/src/sources/builtins.d.ts +11 -0
- package/dist/src/sources/builtins.d.ts.map +1 -0
- package/dist/src/sources/builtins.js +47 -0
- package/dist/src/sources/builtins.js.map +1 -0
- package/dist/src/sources/codes.d.ts +230 -0
- package/dist/src/sources/codes.d.ts.map +1 -0
- package/dist/src/sources/codes.js +58 -0
- package/dist/src/sources/codes.js.map +1 -0
- package/dist/src/sources/context.d.ts +112 -0
- package/dist/src/sources/context.d.ts.map +1 -0
- package/dist/src/sources/context.js +739 -0
- package/dist/src/sources/context.js.map +1 -0
- package/dist/src/sources/credentials.d.ts +179 -0
- package/dist/src/sources/credentials.d.ts.map +1 -0
- package/dist/src/sources/credentials.js +301 -0
- package/dist/src/sources/credentials.js.map +1 -0
- package/dist/src/sources/cypher/descriptor.d.ts +21 -0
- package/dist/src/sources/cypher/descriptor.d.ts.map +1 -0
- package/dist/src/sources/cypher/descriptor.js +119 -0
- package/dist/src/sources/cypher/descriptor.js.map +1 -0
- package/dist/src/sources/cypher/flatten.d.ts +72 -0
- package/dist/src/sources/cypher/flatten.d.ts.map +1 -0
- package/dist/src/sources/cypher/flatten.js +279 -0
- package/dist/src/sources/cypher/flatten.js.map +1 -0
- package/dist/src/sources/cypher/index.d.ts +33 -0
- package/dist/src/sources/cypher/index.d.ts.map +1 -0
- package/dist/src/sources/cypher/index.js +405 -0
- package/dist/src/sources/cypher/index.js.map +1 -0
- package/dist/src/sources/cypher/params.d.ts +40 -0
- package/dist/src/sources/cypher/params.d.ts.map +1 -0
- package/dist/src/sources/cypher/params.js +6 -0
- package/dist/src/sources/cypher/params.js.map +1 -0
- package/dist/src/sources/cypher/profiles.d.ts +44 -0
- package/dist/src/sources/cypher/profiles.d.ts.map +1 -0
- package/dist/src/sources/cypher/profiles.js +61 -0
- package/dist/src/sources/cypher/profiles.js.map +1 -0
- package/dist/src/sources/cypher/query-builder.d.ts +106 -0
- package/dist/src/sources/cypher/query-builder.d.ts.map +1 -0
- package/dist/src/sources/cypher/query-builder.js +236 -0
- package/dist/src/sources/cypher/query-builder.js.map +1 -0
- package/dist/src/sources/cypher/transports/bolt.d.ts +21 -0
- package/dist/src/sources/cypher/transports/bolt.d.ts.map +1 -0
- package/dist/src/sources/cypher/transports/bolt.js +185 -0
- package/dist/src/sources/cypher/transports/bolt.js.map +1 -0
- package/dist/src/sources/cypher/transports/neptune-analytics.d.ts +15 -0
- package/dist/src/sources/cypher/transports/neptune-analytics.d.ts.map +1 -0
- package/dist/src/sources/cypher/transports/neptune-analytics.js +38 -0
- package/dist/src/sources/cypher/transports/neptune-analytics.js.map +1 -0
- package/dist/src/sources/cypher/transports/neptune-https.d.ts +31 -0
- package/dist/src/sources/cypher/transports/neptune-https.d.ts.map +1 -0
- package/dist/src/sources/cypher/transports/neptune-https.js +104 -0
- package/dist/src/sources/cypher/transports/neptune-https.js.map +1 -0
- package/dist/src/sources/cypher/transports/query-api.d.ts +14 -0
- package/dist/src/sources/cypher/transports/query-api.d.ts.map +1 -0
- package/dist/src/sources/cypher/transports/query-api.js +80 -0
- package/dist/src/sources/cypher/transports/query-api.js.map +1 -0
- package/dist/src/sources/cypher/transports/transport.d.ts +78 -0
- package/dist/src/sources/cypher/transports/transport.d.ts.map +1 -0
- package/dist/src/sources/cypher/transports/transport.js +77 -0
- package/dist/src/sources/cypher/transports/transport.js.map +1 -0
- package/dist/src/sources/cypher/types-map.d.ts +91 -0
- package/dist/src/sources/cypher/types-map.d.ts.map +1 -0
- package/dist/src/sources/cypher/types-map.js +306 -0
- package/dist/src/sources/cypher/types-map.js.map +1 -0
- package/dist/src/sources/define.d.ts +47 -0
- package/dist/src/sources/define.d.ts.map +1 -0
- package/dist/src/sources/define.js +173 -0
- package/dist/src/sources/define.js.map +1 -0
- package/dist/src/sources/fail.d.ts +33 -0
- package/dist/src/sources/fail.d.ts.map +1 -0
- package/dist/src/sources/fail.js +49 -0
- package/dist/src/sources/fail.js.map +1 -0
- package/dist/src/sources/ids.d.ts +64 -0
- package/dist/src/sources/ids.d.ts.map +1 -0
- package/dist/src/sources/ids.js +64 -0
- package/dist/src/sources/ids.js.map +1 -0
- package/dist/src/sources/ndex/client.d.ts +31 -0
- package/dist/src/sources/ndex/client.d.ts.map +1 -0
- package/dist/src/sources/ndex/client.js +90 -0
- package/dist/src/sources/ndex/client.js.map +1 -0
- package/dist/src/sources/ndex/descriptor.d.ts +10 -0
- package/dist/src/sources/ndex/descriptor.d.ts.map +1 -0
- package/dist/src/sources/ndex/descriptor.js +55 -0
- package/dist/src/sources/ndex/descriptor.js.map +1 -0
- package/dist/src/sources/ndex/expand.d.ts +20 -0
- package/dist/src/sources/ndex/expand.d.ts.map +1 -0
- package/dist/src/sources/ndex/expand.js +87 -0
- package/dist/src/sources/ndex/expand.js.map +1 -0
- package/dist/src/sources/ndex/index.d.ts +25 -0
- package/dist/src/sources/ndex/index.d.ts.map +1 -0
- package/dist/src/sources/ndex/index.js +191 -0
- package/dist/src/sources/ndex/index.js.map +1 -0
- package/dist/src/sources/ndex/params.d.ts +17 -0
- package/dist/src/sources/ndex/params.d.ts.map +1 -0
- package/dist/src/sources/ndex/params.js +6 -0
- package/dist/src/sources/ndex/params.js.map +1 -0
- package/dist/src/sources/ndex/share-url.d.ts +40 -0
- package/dist/src/sources/ndex/share-url.d.ts.map +1 -0
- package/dist/src/sources/ndex/share-url.js +64 -0
- package/dist/src/sources/ndex/share-url.js.map +1 -0
- package/dist/src/sources/params.d.ts +28 -0
- package/dist/src/sources/params.d.ts.map +1 -0
- package/dist/src/sources/params.js +6 -0
- package/dist/src/sources/params.js.map +1 -0
- package/dist/src/sources/registry.d.ts +118 -0
- package/dist/src/sources/registry.d.ts.map +1 -0
- package/dist/src/sources/registry.js +193 -0
- package/dist/src/sources/registry.js.map +1 -0
- package/dist/src/sources/rest/descriptor.d.ts +16 -0
- package/dist/src/sources/rest/descriptor.d.ts.map +1 -0
- package/dist/src/sources/rest/descriptor.js +71 -0
- package/dist/src/sources/rest/descriptor.js.map +1 -0
- package/dist/src/sources/rest/index.d.ts +14 -0
- package/dist/src/sources/rest/index.d.ts.map +1 -0
- package/dist/src/sources/rest/index.js +13 -0
- package/dist/src/sources/rest/index.js.map +1 -0
- package/dist/src/sources/rest/mapping.d.ts +30 -0
- package/dist/src/sources/rest/mapping.d.ts.map +1 -0
- package/dist/src/sources/rest/mapping.js +362 -0
- package/dist/src/sources/rest/mapping.js.map +1 -0
- package/dist/src/sources/rest/openalex.d.ts +27 -0
- package/dist/src/sources/rest/openalex.d.ts.map +1 -0
- package/dist/src/sources/rest/openalex.js +269 -0
- package/dist/src/sources/rest/openalex.js.map +1 -0
- package/dist/src/sources/rest/paging.d.ts +53 -0
- package/dist/src/sources/rest/paging.d.ts.map +1 -0
- package/dist/src/sources/rest/paging.js +138 -0
- package/dist/src/sources/rest/paging.js.map +1 -0
- package/dist/src/sources/rest/params.d.ts +216 -0
- package/dist/src/sources/rest/params.d.ts.map +1 -0
- package/dist/src/sources/rest/params.js +7 -0
- package/dist/src/sources/rest/params.js.map +1 -0
- package/dist/src/sources/rest/records.d.ts +41 -0
- package/dist/src/sources/rest/records.d.ts.map +1 -0
- package/dist/src/sources/rest/records.js +240 -0
- package/dist/src/sources/rest/records.js.map +1 -0
- package/dist/src/sources/rest/samples/deps-dev.d.ts +10 -0
- package/dist/src/sources/rest/samples/deps-dev.d.ts.map +1 -0
- package/dist/src/sources/rest/samples/deps-dev.js +47 -0
- package/dist/src/sources/rest/samples/deps-dev.js.map +1 -0
- package/dist/src/sources/rest/samples/string.d.ts +9 -0
- package/dist/src/sources/rest/samples/string.d.ts.map +1 -0
- package/dist/src/sources/rest/samples/string.js +42 -0
- package/dist/src/sources/rest/samples/string.js.map +1 -0
- package/dist/src/sources/rest/selectors.d.ts +41 -0
- package/dist/src/sources/rest/selectors.d.ts.map +1 -0
- package/dist/src/sources/rest/selectors.js +81 -0
- package/dist/src/sources/rest/selectors.js.map +1 -0
- package/dist/src/sources/rest/source.d.ts +67 -0
- package/dist/src/sources/rest/source.d.ts.map +1 -0
- package/dist/src/sources/rest/source.js +635 -0
- package/dist/src/sources/rest/source.js.map +1 -0
- package/dist/src/sources/rest/templates.d.ts +38 -0
- package/dist/src/sources/rest/templates.d.ts.map +1 -0
- package/dist/src/sources/rest/templates.js +125 -0
- package/dist/src/sources/rest/templates.js.map +1 -0
- package/dist/src/sources/run.d.ts +93 -0
- package/dist/src/sources/run.d.ts.map +1 -0
- package/dist/src/sources/run.js +673 -0
- package/dist/src/sources/run.js.map +1 -0
- package/dist/src/sources/sha256.d.ts +12 -0
- package/dist/src/sources/sha256.d.ts.map +1 -0
- package/dist/src/sources/sha256.js +95 -0
- package/dist/src/sources/sha256.js.map +1 -0
- package/dist/src/sources/sigv4.d.ts +24 -0
- package/dist/src/sources/sigv4.d.ts.map +1 -0
- package/dist/src/sources/sigv4.js +182 -0
- package/dist/src/sources/sigv4.js.map +1 -0
- package/dist/src/sources/testing.d.ts +96 -0
- package/dist/src/sources/testing.d.ts.map +1 -0
- package/dist/src/sources/testing.js +138 -0
- package/dist/src/sources/testing.js.map +1 -0
- package/dist/src/sources/types.d.ts +665 -0
- package/dist/src/sources/types.d.ts.map +1 -0
- package/dist/src/sources/types.js +10 -0
- package/dist/src/sources/types.js.map +1 -0
- package/dist/src/styles/canon/enums.d.ts.map +1 -1
- package/dist/src/styles/canon/enums.js +1 -0
- package/dist/src/styles/canon/enums.js.map +1 -1
- package/dist/src/styles/cyjs/cascade.d.ts.map +1 -1
- package/dist/src/styles/cyjs/cascade.js +68 -2
- package/dist/src/styles/cyjs/cascade.js.map +1 -1
- package/dist/src/styles/cyjs/defaults-table.d.ts.map +1 -1
- package/dist/src/styles/cyjs/defaults-table.js +2 -0
- package/dist/src/styles/cyjs/defaults-table.js.map +1 -1
- package/dist/src/styles/cyjs/emit.d.ts.map +1 -1
- package/dist/src/styles/cyjs/emit.js +18 -7
- package/dist/src/styles/cyjs/emit.js.map +1 -1
- package/dist/src/styles/cyjs/mappers.d.ts +4 -1
- package/dist/src/styles/cyjs/mappers.d.ts.map +1 -1
- package/dist/src/styles/cyjs/mappers.js +2 -0
- package/dist/src/styles/cyjs/mappers.js.map +1 -1
- package/dist/src/styles/cytoscape/emit.d.ts.map +1 -1
- package/dist/src/styles/cytoscape/emit.js +59 -7
- package/dist/src/styles/cytoscape/emit.js.map +1 -1
- package/dist/src/styles/cytoscape/lexicon.d.ts +6 -0
- package/dist/src/styles/cytoscape/lexicon.d.ts.map +1 -1
- package/dist/src/styles/cytoscape/lexicon.js +26 -2
- package/dist/src/styles/cytoscape/lexicon.js.map +1 -1
- package/dist/src/styles/cytoscape/resolve.d.ts +4 -1
- package/dist/src/styles/cytoscape/resolve.d.ts.map +1 -1
- package/dist/src/styles/cytoscape/resolve.js +10 -6
- package/dist/src/styles/cytoscape/resolve.js.map +1 -1
- package/dist/src/styles/cytoscape/translate.d.ts.map +1 -1
- package/dist/src/styles/cytoscape/translate.js +10 -10
- package/dist/src/styles/cytoscape/translate.js.map +1 -1
- package/dist/src/styles/defaults.d.ts +30 -0
- package/dist/src/styles/defaults.d.ts.map +1 -1
- package/dist/src/styles/defaults.js +45 -4
- package/dist/src/styles/defaults.js.map +1 -1
- package/dist/src/styles/io/block.d.ts.map +1 -1
- package/dist/src/styles/io/block.js +9 -0
- package/dist/src/styles/io/block.js.map +1 -1
- package/dist/src/styles/io/writer.d.ts.map +1 -1
- package/dist/src/styles/io/writer.js +7 -3
- package/dist/src/styles/io/writer.js.map +1 -1
- package/dist/src/styles/plan/resolve.d.ts +2 -1
- package/dist/src/styles/plan/resolve.d.ts.map +1 -1
- package/dist/src/styles/plan/resolve.js +13 -2
- package/dist/src/styles/plan/resolve.js.map +1 -1
- package/dist/src/styles/types.d.ts +19 -2
- package/dist/src/styles/types.d.ts.map +1 -1
- package/dist/src/styles/vocabulary.d.ts.map +1 -1
- package/dist/src/styles/vocabulary.js +15 -1
- package/dist/src/styles/vocabulary.js.map +1 -1
- package/dist/src/types.d.ts +19 -5
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js.map +1 -1
- package/dist/styles.js +11 -11
- package/dist/xgmml.js +3 -3
- package/docs/samples/people.json +6 -0
- package/package.json +29 -4
- package/src/common/report.ts +27 -7
- package/src/formats/cx/styles.ts +1 -0
- package/src/formats/dot/styles.ts +3 -1
- package/src/formats/gexf/styles.ts +185 -37
- package/src/formats/gml/styles.ts +5 -4
- package/src/formats/graphml/styles-plain.ts +3 -9
- package/src/formats/graphml/styles-yed.ts +93 -20
- package/src/formats/pajek/styles.ts +1 -0
- package/src/formats/xgmml/styles.ts +1 -0
- package/src/index.ts +90 -0
- package/src/registry.ts +326 -1
- package/src/sources/builtins.ts +56 -0
- package/src/sources/codes.ts +235 -0
- package/src/sources/context.ts +893 -0
- package/src/sources/credentials.ts +409 -0
- package/src/sources/cypher/descriptor.ts +125 -0
- package/src/sources/cypher/flatten.ts +323 -0
- package/src/sources/cypher/index.ts +498 -0
- package/src/sources/cypher/params.ts +41 -0
- package/src/sources/cypher/profiles.ts +78 -0
- package/src/sources/cypher/query-builder.ts +294 -0
- package/src/sources/cypher/transports/bolt.ts +228 -0
- package/src/sources/cypher/transports/neptune-analytics.ts +41 -0
- package/src/sources/cypher/transports/neptune-https.ts +122 -0
- package/src/sources/cypher/transports/query-api.ts +100 -0
- package/src/sources/cypher/transports/transport.ts +139 -0
- package/src/sources/cypher/types-map.ts +418 -0
- package/src/sources/define.ts +195 -0
- package/src/sources/fail.ts +70 -0
- package/src/sources/ids.ts +74 -0
- package/src/sources/ndex/client.ts +102 -0
- package/src/sources/ndex/descriptor.ts +64 -0
- package/src/sources/ndex/expand.ts +100 -0
- package/src/sources/ndex/index.ts +235 -0
- package/src/sources/ndex/params.ts +17 -0
- package/src/sources/ndex/share-url.ts +84 -0
- package/src/sources/params.ts +29 -0
- package/src/sources/registry.ts +325 -0
- package/src/sources/rest/descriptor.ts +74 -0
- package/src/sources/rest/index.ts +22 -0
- package/src/sources/rest/mapping.ts +401 -0
- package/src/sources/rest/openalex.ts +288 -0
- package/src/sources/rest/paging.ts +180 -0
- package/src/sources/rest/params.ts +243 -0
- package/src/sources/rest/records.ts +289 -0
- package/src/sources/rest/samples/deps-dev.ts +49 -0
- package/src/sources/rest/samples/string.ts +44 -0
- package/src/sources/rest/selectors.ts +91 -0
- package/src/sources/rest/source.ts +760 -0
- package/src/sources/rest/templates.ts +151 -0
- package/src/sources/run.ts +793 -0
- package/src/sources/sha256.ts +99 -0
- package/src/sources/sigv4.ts +207 -0
- package/src/sources/testing.ts +210 -0
- package/src/sources/types.ts +741 -0
- package/src/styles/canon/enums.ts +1 -0
- package/src/styles/cyjs/cascade.ts +81 -2
- package/src/styles/cyjs/defaults-table.ts +2 -0
- package/src/styles/cyjs/emit.ts +18 -7
- package/src/styles/cyjs/mappers.ts +6 -1
- package/src/styles/cytoscape/emit.ts +61 -7
- package/src/styles/cytoscape/lexicon.ts +28 -2
- package/src/styles/cytoscape/resolve.ts +22 -6
- package/src/styles/cytoscape/translate.ts +11 -11
- package/src/styles/defaults.ts +93 -4
- package/src/styles/io/block.ts +10 -0
- package/src/styles/io/writer.ts +8 -3
- package/src/styles/plan/resolve.ts +14 -2
- package/src/styles/types.ts +28 -2
- package/src/styles/vocabulary.ts +15 -1
- package/src/types.ts +19 -5
- package/dist/chunks/block-DiGq58c3.js.map +0 -1
- package/dist/chunks/emit-CwU8cUmG.js.map +0 -1
- package/dist/chunks/export-BvqAXCKh.js.map +0 -1
- package/dist/chunks/format-BpQBx8MZ.js.map +0 -1
- package/dist/chunks/importer-BSvfrX_h.js.map +0 -1
- package/dist/chunks/importer-CMmeMWlC.js.map +0 -1
- package/dist/chunks/importer-COTK9Tsl.js.map +0 -1
- package/dist/chunks/importer-DiZRmOQG.js.map +0 -1
- package/dist/chunks/importer-e6LGpqHB.js.map +0 -1
- package/dist/chunks/lexicon-CT69Kd87.js.map +0 -1
- package/dist/chunks/styles-BQnsga7p.js.map +0 -1
- package/dist/chunks/styles-D3fRphrO.js.map +0 -1
- package/dist/chunks/styles-yed-BF5x3_Y5.js.map +0 -1
- package/dist/chunks/writer-DMKvthQE.js.map +0 -1
package/dist/gml.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gml.js","sources":["../src/formats/gml/syntax.ts","../src/formats/gml/styles.ts","../src/formats/gml/exporter.ts","../src/formats/gml/positions.ts","../src/formats/gml/importer.ts","../src/formats/gml/index.ts"],"sourcesContent":["/**\n * The GML lexical layer shared by the importer and the exporter (research note 07 section 2.2,\n * NetworkX readwrite/gml.py as the reference reader): the token list a whole GML text lexes into,\n * the structural validation that guarantees every later walk sees balanced `key value` pairs, the\n * value grammar (int, real, quoted string with `&#NN;` character references, `[ ... ]` record),\n * the NetworkX list conventions (`_networkx_list_start`, `\"[]\"`) and the key charset.\n *\n * Tokens are kept in typed arrays (kind, start, end, line, matching bracket) rather than objects:\n * the token list is the one intermediate structure of the GML importer, and it costs 17 bytes per\n * token instead of an object per node.\n */\n\nimport { SYNTAX_CODE } from \"../../common/codes.js\";\nimport { decodeGmlString } from \"../../common/escape.js\";\nimport { plural } from \"../../common/plural.js\";\n\n/**\n * A bare word: a key, or `INF` / `NAN` at a value position.\n * @category Plugin helpers\n */\nexport const TOKEN_WORD = 0;\n/**\n * An integer literal.\n * @category Plugin helpers\n */\nexport const TOKEN_INT = 1;\n/**\n * A real literal, including the non-finite spellings.\n * @category Plugin helpers\n */\nexport const TOKEN_REAL = 2;\n/**\n * A double-quoted string; start / end delimit the body between the quotes.\n * @category Plugin helpers\n */\nexport const TOKEN_STRING = 3;\n/**\n * `[`.\n * @category Plugin helpers\n */\nexport const TOKEN_OPEN = 4;\n/**\n * `]`.\n * @category Plugin helpers\n */\nexport const TOKEN_CLOSE = 5;\n\n/** The kind of one token. */\ntype TokenKind = 0 | 1 | 2 | 3 | 4 | 5;\n\n/**\n * The NetworkX marker that starts a one-element list written as repeated keys.\n * @category Plugin helpers\n */\nexport const LIST_START_MARKER = \"_networkx_list_start\";\n\n/**\n * The string NetworkX writes for an empty list.\n * @category Plugin helpers\n */\nexport const EMPTY_LIST_TEXT = \"[]\";\n\n/**\n * The string NetworkX writes for an empty tuple, read as an empty list too.\n * @category Plugin helpers\n */\nexport const EMPTY_TUPLE_TEXT = \"()\";\n\n/**\n * The node key the exporter writes a mangled node's original id into (design section 8.5).\n * @category Plugin helpers\n */\nexport const ORIGINAL_ID_KEY = \"graphty_originalId\";\n\n/**\n * The text breaks the format's syntax: a word that is not a key or a number, an unclosed string or `[`, a `]` with no\n * open `[`, or a key without a value. The message says where. The import stops.\n * @category Issue and loss codes\n */\nexport const SYNTAX_STRUCTURE_CODE = SYNTAX_CODE;\n/**\n * The code of an untokenizable bare token (E_SYNTAX).\n * @category Issue and loss codes\n */\nexport const SYNTAX_TOKEN_CODE = SYNTAX_CODE;\n/**\n * The code of an unclosed string (E_SYNTAX).\n * @category Issue and loss codes\n */\nexport const SYNTAX_STRING_CODE = SYNTAX_CODE;\n/**\n * The code of an unclosed `[` (E_SYNTAX).\n * @category Issue and loss codes\n */\nexport const SYNTAX_BRACKET_CODE = SYNTAX_CODE;\n\nconst KEY_TEXT = /^[A-Za-z_]\\w*$/;\nconst STRICT_KEY_TEXT = /^[A-Za-z]\\w*$/;\nconst INT_TEXT = /^[+-]?\\d+$/;\nconst REAL_TEXT = /^[+-]?(?:(?:\\d+\\.\\d*|\\.\\d+)(?:[eE][+-]?\\d+)?|\\d+[eE][+-]?\\d+)$/;\nconst NON_FINITE_TEXT = /^[+-]?(?:inf|infinity|nan)$/i;\nconst NON_FINITE_WORD = /^(?:inf|infinity|nan)$/i;\n\n/**\n * A lexical or structural error of a GML text, with the 1-based line it was found on. The importer\n * turns it into a fatal parse-error issue.\n * @category Plugin helpers\n */\nexport class GmlSyntaxError extends Error {\n /** The issue code. */\n readonly code: string;\n\n /** The 1-based line. */\n readonly line: number;\n\n /**\n * Create a syntax error.\n * @param code - the issue code\n * @param message - a plain-ASCII message\n * @param line - the 1-based line\n */\n constructor(code: string, message: string, line: number) {\n super(message);\n this.name = \"GmlSyntaxError\";\n this.code = code;\n this.line = line;\n }\n}\n\n/**\n * The tokens of one GML text, structurally validated: every `[` has its matching `]` recorded and\n * every key is followed by a value, so walkers need no error paths.\n * @category Plugin helpers\n */\nexport class GmlTokens {\n /** The source text the offsets index into. */\n readonly text: string;\n\n /** The kind of every token. */\n kind: Uint8Array;\n\n /** The start offset of every token (a string's body start). */\n start: Uint32Array;\n\n /** The end offset (exclusive) of every token (a string's body end). */\n end: Uint32Array;\n\n /** The 1-based line of every token. */\n line: Uint32Array;\n\n /** For an open bracket, the index of its matching close bracket; 0 elsewhere. */\n match: Uint32Array;\n\n /** The number of tokens. */\n count = 0;\n\n /**\n * Whether a backslash escapes the next character inside a string (`\\\"`, `\\\\`): set for files OGDF wrote, whose\n * writer escapes quotes that way. Plain GML has no escape mechanism.\n */\n backslashEscapes = false;\n\n /** Called by stringOf() with each named entity it cannot decode and the token's line, when set. */\n onUnknownEntity: ((entity: string, line: number) => void) | null = null;\n\n /**\n * Create an empty token list over a text.\n * @param text - the source text\n * @param capacity - the initial capacity\n */\n constructor(text: string, capacity = 1024) {\n this.text = text;\n this.kind = new Uint8Array(capacity);\n this.start = new Uint32Array(capacity);\n this.end = new Uint32Array(capacity);\n this.line = new Uint32Array(capacity);\n this.match = new Uint32Array(0);\n }\n\n /**\n * Append a token.\n * @param kind - the kind\n * @param start - the start offset\n * @param end - the end offset\n * @param line - the 1-based line\n */\n push(kind: TokenKind, start: number, end: number, line: number): void {\n if (this.count === this.kind.length) {\n this.grow();\n }\n const i = this.count++;\n this.kind[i] = kind;\n this.start[i] = start;\n this.end[i] = end;\n this.line[i] = line;\n }\n\n /**\n * The raw text of a token (a string's body without the quotes, entities undecoded).\n * @param i - the token index\n * @returns the text\n */\n textOf(i: number): string {\n return this.text.slice(this.start[i], this.end[i]);\n }\n\n /**\n * The decoded value of a string token.\n * @param i - the token index\n * @returns the body with character references decoded\n */\n stringOf(i: number): string {\n let text = this.textOf(i);\n if (text.includes(\"\\r\")) {\n // a line break inside a string is part of it, as LF whatever the file's line ends\n text = text.replaceAll(/\\r\\n?/g, \"\\n\");\n }\n if (this.backslashEscapes && text.includes(\"\\\\\")) {\n text = text.replaceAll(/\\\\([\\s\\S])/g, \"$1\");\n }\n if (!text.includes(\"&\")) {\n return text;\n }\n const report = this.onUnknownEntity;\n return decodeGmlString(\n text,\n report === null\n ? undefined\n : (entity) => {\n report(entity, this.line[i]);\n },\n );\n }\n\n /**\n * Whether a token is a `[` or `]`.\n * @param i - the token index\n * @returns true for a bracket\n */\n isBracket(i: number): boolean {\n return this.kind[i] >= TOKEN_OPEN;\n }\n\n /**\n * The index of the pair following the pair whose key is at `key`.\n * @param key - the index of a key token\n * @returns the index after the pair's value (after the matching `]` for a record)\n */\n nextPair(key: number): number {\n const value = key + 1;\n return this.kind[value] === TOKEN_OPEN ? this.match[value] + 1 : value + 1;\n }\n\n /** Double every array. */\n private grow(): void {\n const capacity = this.kind.length * 2;\n const kind = new Uint8Array(capacity);\n kind.set(this.kind);\n this.kind = kind;\n const start = new Uint32Array(capacity);\n start.set(this.start);\n this.start = start;\n const end = new Uint32Array(capacity);\n end.set(this.end);\n this.end = end;\n const line = new Uint32Array(capacity);\n line.set(this.line);\n this.line = line;\n }\n}\n\n/**\n * Lex and structurally validate a whole GML text.\n *\n * Lexical rules (NetworkX): whitespace separates tokens; `#` outside a string starts a comment\n * that runs to the end of the line; a string is delimited by double quotes and may span lines (a\n * line break inside is part of it, GML draft 3.2.5; there is no escape mechanism; `&#NN;`\n * references are decoded later); a U+FEFF between tokens is whitespace; `[` and `]` are\n * single-character tokens; every other run of characters is a key (`[A-Za-z_][0-9A-Za-z_]*`),\n * an integer (`[+-]?[0-9]+`), a real (with a decimal point or an exponent, or `INF` / `NAN` in\n * any case with an optional sign) or an error.\n *\n * Structural rules: the text is a sequence of `key value` pairs where a value is a number, a\n * string, `INF` / `NAN`, or a bracketed sequence of pairs; every `[` has a `]`.\n * @param text - the GML text\n * @returns the validated tokens; GmlSyntaxError with the line of the first problem\n * @category Plugin helpers\n */\nexport function tokenizeGml(text: string): GmlTokens {\n const tokens = new GmlTokens(text, Math.max(1024, text.length >>> 3));\n tokens.backslashEscapes = writtenByOgdf(text);\n const lex: GmlLex = { text, tokens, i: 0, line: 1, spanningLine: 0 };\n while (lex.i < text.length) {\n const c = text.codePointAt(lex.i) ?? 0;\n if (c === 34) {\n lexString(lex);\n } else if (c === 91 || c === 93) {\n tokens.push(c === 91 ? TOKEN_OPEN : TOKEN_CLOSE, lex.i, lex.i + 1, lex.line);\n lex.i++;\n } else if (!skipSpace(lex, c)) {\n lexBare(lex);\n }\n }\n validateStructure(tokens);\n return tokens;\n}\n\n/** Where tokenizeGml() is. */\ninterface GmlLex {\n readonly text: string;\n readonly tokens: GmlTokens;\n /** The offset of the next character. */\n i: number;\n /** The line of the next character. */\n line: number;\n /** The opening line of the first string that spans lines: where a missing quote most likely is; 0 for none. */\n spanningLine: number;\n}\n\n/**\n * Skips one line break, space or comment.\n * @param lex - the lexer\n * @param c - the char code at the offset\n * @returns false when the character starts a token\n */\nfunction skipSpace(lex: GmlLex, c: number): boolean {\n const { text } = lex;\n if (c === 10 || c === 13) {\n lex.line++;\n lex.i++;\n if (c === 13 && lex.i < text.length && text.codePointAt(lex.i) === 10) {\n lex.i++;\n }\n } else if (c === 32 || c === 9 || c === 11 || c === 12 || c === 0xfeff) {\n // a BOM left inside by concatenated files is whitespace; the shared text check reports it\n lex.i++;\n } else if (c === 35) {\n lex.i = endOfLine(text, lex.i);\n } else {\n return false;\n }\n return true;\n}\n\n/**\n * Lexes a string starting at the offset (its opening quote).\n * @param lex - the lexer\n */\nfunction lexString(lex: GmlLex): void {\n const { text, tokens, i } = lex;\n const close = tokens.backslashEscapes ? escapedClose(text, i + 1) : text.indexOf('\"', i + 1);\n if (close < 0) {\n const hint =\n lex.spanningLine === 0\n ? \"\"\n : `; the string opened at line ${lex.spanningLine} spans lines, so a quote may be missing there`;\n throw new GmlSyntaxError(SYNTAX_STRING_CODE, `unclosed string opened at line ${lex.line}${hint}`, lex.line);\n }\n tokens.push(TOKEN_STRING, i + 1, close, lex.line);\n const opened = lex.line;\n for (let k = i + 1; k < close; k++) {\n const d = text.codePointAt(k);\n if (d === 10 || (d === 13 && text.codePointAt(k + 1) !== 10)) {\n lex.line++;\n }\n }\n if (lex.line !== opened && lex.spanningLine === 0) {\n lex.spanningLine = opened;\n }\n lex.i = close + 1;\n}\n\n/**\n * Lexes a bare token (a key, a number) starting at the offset.\n * @param lex - the lexer\n */\nfunction lexBare(lex: GmlLex): void {\n const { text, i } = lex;\n let j = i + 1;\n while (j < text.length && !isDelimiter(text.codePointAt(j) ?? 0)) {\n j++;\n }\n lex.tokens.push(classifyBare(text, i, j, lex.line), i, j, lex.line);\n lex.i = j;\n}\n\n/**\n * Whether OGDF wrote the file: its first key is `Creator \"ogdf::...\"`, after any whitespace and\n * comment lines. A plain scan, so a banner of `#` characters costs time linear in its length.\n * @param text - the GML text\n * @returns true when the file opens with an OGDF creator line\n */\nfunction writtenByOgdf(text: string): boolean {\n const end = Math.min(text.length, 512);\n let i = 0;\n while (i < end) {\n const c = text.codePointAt(i);\n if (c === 35) {\n // '#': a comment runs to the next line break\n while (i < end && text.codePointAt(i) !== 10 && text.codePointAt(i) !== 13) {\n i++;\n }\n } else if (c === 32 || c === 9 || c === 10 || c === 13 || c === 12 || c === 11) {\n i++;\n } else {\n break;\n }\n }\n return /^Creator\\s+\"ogdf::/.test(text.slice(i, i + 64));\n}\n\n/**\n * The offset of the quote closing a string whose backslashes escape the next character, or -1.\n * @param text - the text\n * @param from - the offset after the opening quote\n * @returns the offset of the closing quote\n */\nfunction escapedClose(text: string, from: number): number {\n let k = from;\n while (k < text.length) {\n const c = text.codePointAt(k);\n if (c === 34) {\n return k;\n }\n // a backslash escapes the next character\n k += c === 92 ? 2 : 1;\n }\n return -1;\n}\n\n/**\n * The offset of the line terminator at or after `from`, or the text length.\n * @param text - the text\n * @param from - the offset to search from\n * @returns the offset of the next `\\n` or `\\r`\n */\nfunction endOfLine(text: string, from: number): number {\n const n = text.length;\n for (let i = from; i < n; i++) {\n const c = text.charCodeAt(i);\n if (c === 10 || c === 13) {\n return i;\n }\n }\n return n;\n}\n\n/**\n * Whether a character ends a bare token.\n * @param c - the char code\n * @returns true for whitespace, brackets, a quote or `#`\n */\nfunction isDelimiter(c: number): boolean {\n return (\n c === 32 ||\n c === 9 ||\n c === 10 ||\n c === 13 ||\n c === 11 ||\n c === 12 ||\n c === 91 ||\n c === 93 ||\n c === 34 ||\n c === 35\n );\n}\n\n/**\n * Classify a bare token.\n * @param text - the text\n * @param start - the token start\n * @param end - the token end\n * @param line - the token line, for the error\n * @returns WORD, INT or REAL; GmlSyntaxError for anything else\n */\nfunction classifyBare(text: string, start: number, end: number, line: number): TokenKind {\n const token = text.slice(start, end);\n if (KEY_TEXT.test(token)) {\n return TOKEN_WORD;\n }\n if (INT_TEXT.test(token)) {\n return TOKEN_INT;\n }\n if (REAL_TEXT.test(token) || NON_FINITE_TEXT.test(token)) {\n return TOKEN_REAL;\n }\n // the message is ASCII: a character outside it is shown as \\uXXXX and named, since it may look\n // like something else (a no-break space pasted from a web page looks like a space)\n const hex = (c: string): string => (c.codePointAt(0) ?? 0).toString(16).toUpperCase().padStart(4, \"0\");\n const head = token.length > 20 ? `${token.slice(0, 20)}...` : token;\n const shown = head.replaceAll(/[^\\x20-\\x7e]/gu, (c) => String.raw`\\u` + hex(c));\n const odd = /[^\\x21-\\x7e]/u.exec(token);\n const note = odd === null ? \"\" : ` (it holds U+${hex(odd[0])}, which GML allows only inside a string)`;\n throw new GmlSyntaxError(SYNTAX_TOKEN_CODE, `cannot tokenize \"${shown}\" at line ${line}${note}`, line);\n}\n\n/**\n * Check the `key value` structure and record the matching bracket of every `[`.\n * @param tokens - the lexed tokens\n */\nfunction validateStructure(tokens: GmlTokens): void {\n const { count, kind } = tokens;\n const match = new Uint32Array(count);\n const stack: number[] = [];\n let i = 0;\n while (i < count) {\n const k = kind[i];\n if (k === TOKEN_CLOSE) {\n const open = stack.pop();\n if (open === undefined) {\n throw new GmlSyntaxError(\n SYNTAX_STRUCTURE_CODE,\n `unexpected \"]\" at line ${tokens.line[i]}: no open \"[\"`,\n tokens.line[i],\n );\n }\n match[open] = i;\n i++;\n continue;\n }\n if (k !== TOKEN_WORD) {\n throw new GmlSyntaxError(\n SYNTAX_STRUCTURE_CODE,\n `expected a key at line ${tokens.line[i]}, found ${describeToken(tokens, i)}`,\n tokens.line[i],\n );\n }\n const value = i + 1;\n if (value >= count) {\n throw new GmlSyntaxError(\n SYNTAX_STRUCTURE_CODE,\n `key \"${tokens.textOf(i)}\" at line ${tokens.line[i]} has no value`,\n tokens.line[i],\n );\n }\n if (checkValue(tokens, i) === TOKEN_OPEN) {\n stack.push(value);\n }\n i = value + 1;\n }\n if (stack.length > 0) {\n const open = stack[stack.length - 1];\n throw new GmlSyntaxError(\n SYNTAX_BRACKET_CODE,\n `unexpected end of input: ${stack.length} bracket${plural(stack.length)} still open, the last opened at line ${tokens.line[open]}`,\n tokens.line[open],\n );\n }\n tokens.match = match;\n}\n\n/**\n * Checks the value of a key: a number, a string, `INF` / `NAN` or an opening bracket. Gephi writes its name\n * unquoted (`Creator Gephi`): the word is read as the string it means.\n * @param tokens - the lexed tokens\n * @param key - the key's token index (its value follows it)\n * @returns the value's kind\n */\nfunction checkValue(tokens: GmlTokens, key: number): TokenKind {\n const { kind } = tokens;\n const value = key + 1;\n const word = kind[value] === TOKEN_WORD && !NON_FINITE_WORD.test(tokens.textOf(value));\n if (word && tokens.textOf(key) === \"Creator\") {\n kind[value] = TOKEN_STRING;\n return TOKEN_STRING;\n }\n if (kind[value] === TOKEN_CLOSE || word) {\n throw new GmlSyntaxError(\n SYNTAX_STRUCTURE_CODE,\n `expected a value for key \"${tokens.textOf(key)}\" at line ${tokens.line[key]}, found ${describeToken(tokens, value)}`,\n tokens.line[value],\n );\n }\n return kind[value] as TokenKind;\n}\n\n/**\n * A short description of a token for messages.\n * @param tokens - the tokens\n * @param i - the token index\n * @returns the quoted text or the bracket\n */\nfunction describeToken(tokens: GmlTokens, i: number): string {\n switch (tokens.kind[i]) {\n case TOKEN_OPEN:\n return '\"[\"';\n case TOKEN_CLOSE:\n return '\"]\"';\n case TOKEN_STRING:\n return `the string \"${tokens.textOf(i)}\"`;\n default:\n return `\"${tokens.textOf(i)}\"`;\n }\n}\n\n/**\n * The numeric value of an INT or REAL token (or a WORD that is `INF` / `NAN` at a value position).\n * @param text - the token text\n * @returns the number; Infinity / -Infinity / NaN for the non-finite spellings\n * @category Plugin helpers\n */\nexport function numberOfText(text: string): number {\n if (NON_FINITE_TEXT.test(text)) {\n const lower = text.toLowerCase();\n if (lower.endsWith(\"nan\")) {\n return Number.NaN;\n }\n return lower.startsWith(\"-\") ? -Infinity : Infinity;\n }\n return Number(text);\n}\n\n/**\n * Whether a value token is one of the non-finite bare words (`INF`, `NAN`), which lex as words.\n * @param tokens - the tokens\n * @param i - the value token index\n * @returns true when the word is a real\n * @category Plugin helpers\n */\nexport function isNonFiniteWord(tokens: GmlTokens, i: number): boolean {\n return tokens.kind[i] === TOKEN_WORD && NON_FINITE_WORD.test(tokens.textOf(i));\n}\n\n/**\n * Whether a text is a GML key the strict grammar accepts (`[A-Za-z][0-9A-Za-z_]*`, what NetworkX\n * writes and reads).\n * @param text - the candidate key\n * @returns true when it can be written as a key\n * @category Plugin helpers\n */\nexport function isGmlKey(text: string): boolean {\n return STRICT_KEY_TEXT.test(text);\n}\n\n/**\n * Keys rewritten under sanitizeKeys \"mangle\", or a data column renamed because its key would read back as one of\n * graphty's style values.\n * @category Issue and loss codes\n */\nexport const KEY_MANGLED_CODE = \"W_GML_KEY_MANGLED\";\n\n/**\n * Rewrite a text as a GML key: every character outside `[0-9A-Za-z_]` becomes `_` and a leading\n * non-letter is prefixed with `x` (the exporter's `sanitizeKeys: \"mangle\"`).\n * @param text - the text\n * @returns a valid key\n * @category Plugin helpers\n */\nexport function mangleGmlKey(text: string): string {\n const body = text.replaceAll(/\\W/g, \"_\");\n return /^[A-Za-z]/.test(body) ? body : `x${body}`;\n}\n\n/** One open record while parseRecord() walks the tokens without recursion. */\ninterface RecordFrame {\n readonly record: Record<string, unknown>;\n listKeys: Set<string> | null;\n /** The index of the record's `]`. */\n readonly close: number;\n /** The next key token to read. */\n next: number;\n /** The key the record is stored under in its parent, or null for the root. */\n readonly key: string | null;\n}\n\n/**\n * Parse a bracketed record into a JSON object (design section 8.5: nested GML records map to\n * `json`). Values follow the value grammar; repeated keys become arrays with the NetworkX\n * conventions: the `_networkx_list_start` marker starts a list so a one-element list survives,\n * `\"[]\"` and `\"()\"` are empty lists, and a key seen twice without the marker becomes a\n * two-element array. Nested records are walked with an explicit stack, so the nesting depth is\n * bounded by memory, not by the call stack.\n * @param tokens - the validated tokens\n * @param open - the index of the record's `[`\n * @returns a null-prototype object\n * @category Plugin helpers\n */\nexport function parseRecord(tokens: GmlTokens, open: number): Record<string, unknown> {\n const root = Object.create(null) as Record<string, unknown>;\n const stack: RecordFrame[] = [\n { record: root, listKeys: null, close: tokens.match[open], next: open + 1, key: null },\n ];\n while (stack.length > 0) {\n const frame = stack[stack.length - 1];\n if (frame.next >= frame.close) {\n stack.pop();\n if (frame.key !== null) {\n storeValue(stack[stack.length - 1], frame.key, frame.record);\n }\n continue;\n }\n const p = frame.next;\n frame.next = tokens.nextPair(p);\n const key = tokens.textOf(p);\n const v = p + 1;\n if (tokens.kind[v] === TOKEN_STRING) {\n storeString(frame, key, tokens.stringOf(v));\n } else if (tokens.kind[v] === TOKEN_OPEN) {\n stack.push({\n record: Object.create(null) as Record<string, unknown>,\n listKeys: null,\n close: tokens.match[v],\n next: v + 1,\n key,\n });\n } else {\n storeValue(frame, key, numberOfText(tokens.textOf(v)));\n }\n }\n return root;\n}\n\n/**\n * Store a string value: the list-start marker opens an empty list for the key, the empty list and\n * tuple texts store an empty list, anything else stores the text.\n * @param frame - the open record\n * @param key - the key\n * @param text - the string\n */\nfunction storeString(frame: RecordFrame, key: string, text: string): void {\n if (text === LIST_START_MARKER) {\n frame.record[key] = [];\n frame.listKeys ??= new Set();\n frame.listKeys.add(key);\n return;\n }\n storeValue(frame, key, text === EMPTY_LIST_TEXT || text === EMPTY_TUPLE_TEXT ? [] : text);\n}\n\n/**\n * Store one value under a key: appended to the key's list when the key is a list, paired with the\n * earlier value when the key repeats, set otherwise.\n * @param frame - the open record\n * @param key - the key\n * @param value - the value\n */\nfunction storeValue(frame: RecordFrame, key: string, value: unknown): void {\n const { record } = frame;\n if (frame.listKeys?.has(key)) {\n (record[key] as unknown[]).push(value);\n } else if (key in record) {\n record[key] = [record[key], value];\n frame.listKeys ??= new Set();\n frame.listKeys.add(key);\n } else {\n record[key] = value;\n }\n}\n\n/**\n * The JSON value of a non-string value token: a number, or a record.\n * @param tokens - the tokens\n * @param v - the value token index (INT, REAL, non-finite WORD or OPEN)\n * @returns the value\n * @category Plugin helpers\n */\nexport function scalarOrRecord(tokens: GmlTokens, v: number): unknown {\n return tokens.kind[v] === TOKEN_OPEN ? parseRecord(tokens, v) : numberOfText(tokens.textOf(v));\n}\n","/**\n * GML styles: each node's and edge's `graphics [ ... ]` and `LabelGraphics [ ... ]` records read the way the program\n * that wrote the file draws them, and a graph's styles written back as yEd GML graphics.\n *\n * GML has one syntax and many vocabularies. The `Creator` line (top level, or inside the graph as Gephi writes it,\n * quoted or not) names the writer: yEd and yFiles, Cytoscape, Gephi, OGDF and igraph are recognized; every other file\n * (NetworkX writes no `Creator`) is read with the keys of the GML draft (Graphlet). A recognized drawing program's\n * defaults go beneath the file's own values; igraph and unknown writers get none.\n *\n * Writing: the yEd keys (`fill`, `outline`, `outlineWidth`, `outlineStyle`, `w`, `h`, `type`; edge `fill`, `width`,\n * `style`, `sourceArrow`, `targetArrow`, `smoothBends`; `LabelGraphics` `text`, `color`, `fontSize`, `fontName`,\n * `fontStyle`) replace every style key any reader here reads, inside the records the graph already has, so positions,\n * bends and other keys stay. The `graphty.styles` block and the per-element values its rules read are keys too,\n * named by the GML writer's rule for names that are not GML keys (`graphty_styles`, `graphty_style_node_<key>`).\n */\n\nimport type { GraphSnapshot } from \"@graphty/graph-format\";\n\nimport { type BendPoint, bendsToPoints, canonBends } from \"../../styles/canon/bends.js\";\nimport { canonColor, colorOpacity } from \"../../styles/canon/color.js\";\nimport { canonEnum } from \"../../styles/canon/enums.js\";\nimport { canonNumber } from \"../../styles/canon/number.js\";\nimport { type CanonSite, MAX_STYLE_VALUE_LENGTH, noteAt, scalarText } from \"../../styles/canon/site.js\";\nimport { canonText } from \"../../styles/canon/text.js\";\nimport { STYLE_ISSUE } from \"../../styles/codes.js\";\nimport { CYTOSCAPE_LEXICON } from \"../../styles/cytoscape/lexicon.js\";\nimport { StyleApproximations } from \"../../styles/io/approximations.js\";\nimport {\n blockStyles,\n parseStyleBlock,\n STYLE_BLOCK_NAME,\n styleBlockLosses,\n styleTag,\n writeStyleBlock,\n} from \"../../styles/io/block.js\";\nimport { dataRead, type ExporterStyleInput } from \"../../styles/io/writer.js\";\nimport { StyleNotes } from \"../../styles/notes.js\";\nimport { styleFingerprint } from \"../../styles/plan/features.js\";\nimport { plainCell, resolveStyles } from \"../../styles/plan/resolve.js\";\nimport type {\n ImporterStyles,\n StyleColumn,\n StyleDialect,\n StyleReadContext,\n StyleTarget,\n StyleTool,\n StyleValue,\n StyleWriteCapabilities,\n} from \"../../styles/types.js\";\nimport type { LossNote } from \"../../types.js\";\nimport { gephiRules } from \"../gexf/styles.js\";\nimport {\n flowchartShape,\n FONT_STYLES,\n type ValueColumns,\n valueColumns,\n YED_ARROWS,\n YED_LINES,\n YED_SHAPES,\n yedColor,\n yedSpelled,\n yedValue,\n} from \"../graphml/styles-yed.js\";\nimport { KEY_MANGLED_CODE, mangleGmlKey } from \"./syntax.js\";\n\n/** A GML record as the importer keeps it (a json cell). */\ntype Rec = Record<string, unknown>;\n\n/** The key vocabulary a file's graphics are read with. */\ntype Vocabulary = \"yed\" | \"cytoscape\" | \"ogdf\" | \"graphlet\";\n\n/** Who wrote a GML file, as far as its styles go. */\ninterface GmlWriter {\n /** The dialect recorded in the styles. */\n readonly dialect: StyleDialect;\n /** The program whose defaults apply, or null. */\n readonly tool: StyleTool | null;\n /** The keys its graphics are read with. */\n readonly vocabulary: Vocabulary;\n /** How its colors and names are spelled. */\n readonly spelling: StyleDialect;\n /** The unit of its lengths. */\n readonly units: \"px\" | \"relative\";\n /** Whether it draws the `label` key of an element that has graphics (the GML draft does; yEd and Gephi do not). */\n readonly labelKey: boolean;\n}\n\n/** The writers recognized by their `Creator` text, first match wins. */\nconst WRITERS: readonly (readonly [RegExp, GmlWriter])[] = [\n [\n /^\\s*(yfiles|yed)\\b/i,\n { dialect: \"yed\", tool: \"yed\", vocabulary: \"yed\", spelling: \"yed\", units: \"px\", labelKey: false },\n ],\n [\n /^\\s*cytoscape\\b/i,\n {\n dialect: \"cytoscape\",\n tool: \"cytoscape\",\n vocabulary: \"cytoscape\",\n spelling: \"cytoscape\",\n units: \"px\",\n labelKey: true,\n },\n ],\n [\n /^\\s*gephi\\b/i,\n {\n dialect: \"gephi\",\n tool: \"gephi\",\n vocabulary: \"graphlet\",\n spelling: \"css\",\n units: \"relative\",\n labelKey: false,\n },\n ],\n [\n /^\\s*ogdf::/i,\n { dialect: \"ogdf\", tool: \"ogdf\", vocabulary: \"ogdf\", spelling: \"css\", units: \"px\", labelKey: true },\n ],\n // igraph writes a Creator line, but no drawing defaults of igraph's are stated by a primary source\n [\n /^\\s*igraph\\b/i,\n { dialect: \"igraph\", tool: null, vocabulary: \"graphlet\", spelling: \"css\", units: \"px\", labelKey: true },\n ],\n];\n\n/** Any other writer (NetworkX, SNDlib, hand-written files): the GML draft's keys, no defaults. */\nconst UNKNOWN_WRITER: GmlWriter = {\n dialect: \"gml\",\n tool: null,\n vocabulary: \"graphlet\",\n spelling: \"css\",\n units: \"px\",\n labelKey: true,\n};\n\n/** A file graphty wrote: yEd keys, and the `graphty.styles` block gives the rules. */\nconst GRAPHTY_WRITER: GmlWriter = { ...WRITERS[0][1], tool: null };\n\n/**\n * The graph key holding the `graphty.styles` block: the block's name under the GML writer's rule for names that are\n * not GML keys.\n * @category Built-in formats\n */\nexport const GML_STYLE_BLOCK_KEY = mangleGmlKey(STYLE_BLOCK_NAME);\n\n/** The key prefix of the per-element style values (`graphty.style.` under the same rule). */\nconst TAG_PREFIX = mangleGmlKey(\"graphty.style.\");\n\n/**\n * The GML key of one style column's per-element values.\n * @param target - nodes or edges\n * @param key - the style column's key\n * @returns the key\n */\nfunction tagKey(target: StyleTarget, key: string): string {\n return mangleGmlKey(styleTag(target, key));\n}\n\n/**\n * A graph value as text, or null.\n * @param snapshot - the graph\n * @param name - the graph column\n * @returns the text\n */\nfunction graphText(snapshot: GraphSnapshot, name: string): string | null {\n if (!snapshot.graph.has(name)) {\n return null;\n }\n const v = plainCell(snapshot.graph.value(name, 0));\n if (typeof v === \"string\") {\n return v;\n }\n return typeof v === \"number\" ? String(v) : null;\n}\n\n/**\n * Who wrote a GML file: the `Creator` line (top level, or a key of the graph block as Gephi writes it), or graphty when\n * the file holds a `graphty.styles` block.\n * @param snapshot - the graph\n * @returns the writer\n */\nfunction writerOf(snapshot: GraphSnapshot): GmlWriter {\n if (snapshot.graph.has(GML_STYLE_BLOCK_KEY)) {\n return GRAPHTY_WRITER;\n }\n const creator = snapshot.meta.creator ?? graphText(snapshot, \"Creator\") ?? \"\";\n for (const [pattern, writer] of WRITERS) {\n if (pattern.test(creator)) {\n return writer;\n }\n }\n return UNKNOWN_WRITER;\n}\n\n// ============================================================ reading\n\n/** One element's canonical value of a property; null leaves it unset. */\ntype Put = (property: string, value: StyleValue | null) => void;\n\n/** Where a value of an element was read, by property. */\ntype At = (property: string) => CanonSite;\n\n/** The edge's `arrow` key of the GML draft: which ends have an arrow. */\nconst ARROW_ENDS: ReadonlyMap<string, readonly [string, string]> = new Map([\n [\"none\", [\"none\", \"none\"]],\n [\"last\", [\"none\", \"triangle\"]],\n [\"first\", [\"triangle\", \"none\"]],\n [\"both\", [\"triangle\", \"triangle\"]],\n]);\n\n/** OGDF's stroke types (`stipple`), by number. */\nconst OGDF_STROKES: readonly string[] = [\"none\", \"solid\", \"dashed\", \"dotted\", \"dash-dot\", \"dash-dot\"];\n\n/** OGDF's shape names the common table does not know. */\nconst OGDF_SHAPES: ReadonlyMap<string, string> = new Map([\n [\"rect\", \"rectangle\"],\n [\"rhomb\", \"diamond\"],\n [\"trapeze\", \"trapezoid\"],\n [\"invtrapeze\", \"trapezoid\"],\n [\"invtriangle\", \"triangle\"],\n [\"invparallelogram\", \"parallelogram\"],\n]);\n\n/** Keys only yEd writes in a label record: its `fill` is the label's background, not the text color. */\nconst YED_LABEL_KEYS: readonly string[] = [\n \"outline\",\n \"autoSizePolicy\",\n \"model\",\n \"configuration\",\n \"borderDistance\",\n \"modelName\",\n \"modelPosition\",\n];\n\n/** Cytoscape's legacy numbered arrows (`source_arrow 3`), read as Cytoscape reads them. */\nconst cytoscapeArrow = CYTOSCAPE_LEXICON.edge.get(\"targetArrow\")?.[0]?.[1];\n\n/**\n * A short sample of a value for a note.\n * @param raw - the value\n * @returns its text, or \"a record\" for a record\n */\nfunction sampleOf(raw: unknown): string {\n return typeof raw === \"string\" || typeof raw === \"number\"\n ? String(raw).slice(0, MAX_STYLE_VALUE_LENGTH)\n : \"a record\";\n}\n\n/**\n * Whether a value is a GML record.\n * @param v - the value\n * @returns true for a non-array object\n */\nfunction isRec(v: unknown): v is Rec {\n return typeof v === \"object\" && v !== null && !Array.isArray(v);\n}\n\n/**\n * The first defined value of some keys of a record.\n * @param r - the record\n * @param keys - the keys, in order of preference\n * @returns the value, or undefined\n */\nfunction first(r: Rec, ...keys: string[]): unknown {\n for (const k of keys) {\n if (Object.hasOwn(r, k) && r[k] !== undefined) {\n return r[k];\n }\n }\n return undefined;\n}\n\n/**\n * Reads a color and its alpha.\n * @param raw - the value\n * @param property - the color property\n * @param opacity - its opacity property, or null\n * @param writer - the writer\n * @param put - receives the values\n * @param at - the sites\n */\nfunction readColor(raw: unknown, property: string, opacity: string | null, writer: GmlWriter, put: Put, at: At): void {\n if (raw === undefined) {\n return;\n }\n const c = canonColor(raw, writer.spelling, at(property));\n if (c === null) {\n return;\n }\n put(property, c.color);\n const alpha = colorOpacity(c, null, at(property), opacity !== null);\n if (opacity !== null) {\n put(opacity, alpha);\n }\n}\n\n/**\n * A stroke style: OGDF's numbered `stipple`, or a line type name.\n * @param raw - the value\n * @param kind - border or line style\n * @param writer - the writer\n * @param at - the site\n * @returns the style, or null\n */\nfunction strokeStyle(raw: unknown, kind: \"borderStyle\" | \"lineStyle\", writer: GmlWriter, at: CanonSite): string | null {\n if (raw === undefined) {\n return null;\n }\n if (writer.vocabulary === \"ogdf\") {\n const stroke = OGDF_STROKES[Number(raw)] as string | undefined;\n if (stroke === undefined || stroke === \"none\") {\n noteAt(at, STYLE_ISSUE.UNKNOWN_VALUE, sampleOf(raw));\n return null;\n }\n return stroke;\n }\n return canonEnum(kind, raw, writer.spelling, at);\n}\n\n/**\n * Reads one node's `graphics` record.\n * @param g - the record\n * @param writer - the writer\n * @param put - receives the values\n * @param at - the sites\n */\nfunction readNodeGraphics(g: Rec, writer: GmlWriter, put: Put, at: At): void {\n const v = writer.vocabulary;\n readNodeFill(g, writer, put, at);\n readNodeOutline(g, writer, put, at);\n put(\n \"borderStyle\",\n strokeStyle(v === \"ogdf\" ? g.stipple : g.outlineStyle, \"borderStyle\", writer, at(\"borderStyle\")),\n );\n put(\"width\", g.w === undefined ? null : canonNumber(g.w, at(\"width\")));\n put(\"height\", g.h === undefined ? null : canonNumber(g.h, at(\"height\")));\n if (g.type !== undefined) {\n const raw =\n v === \"ogdf\" && typeof g.type === \"string\" ? (OGDF_SHAPES.get(g.type.toLowerCase()) ?? g.type) : g.type;\n put(\"shape\", canonEnum(\"shape\", raw, writer.spelling, at(\"shape\")));\n } else if (v === \"yed\" && typeof g.customconfiguration === \"string\") {\n // yEd's flowchart palette keeps a node's shape as a configuration, not a `type`.\n put(\"shape\", flowchartShape(g.customconfiguration));\n }\n}\n\n/**\n * Reads the fill of one node's `graphics` record.\n * @param g - the record\n * @param writer - the writer\n * @param put - receives the values\n * @param at - the sites\n */\nfunction readNodeFill(g: Rec, writer: GmlWriter, put: Put, at: At): void {\n if (writer.vocabulary === \"yed\" && Number(g.hasFill) === 0) {\n noteAt(at(\"fill\"), STYLE_ISSUE.NO_FILL, \"hasFill 0\");\n put(\"fillOpacity\", 0);\n return;\n }\n readColor(g.fill, \"fill\", \"fillOpacity\", writer, put, at);\n if (g.fill2 !== undefined) {\n noteAt(at(\"fill\"), STYLE_ISSUE.GRADIENT, sampleOf(g.fill2));\n }\n}\n\n/**\n * Reads the outline color and width of one node's `graphics` record.\n * @param g - the record\n * @param writer - the writer\n * @param put - receives the values\n * @param at - the sites\n */\nfunction readNodeOutline(g: Rec, writer: GmlWriter, put: Put, at: At): void {\n const v = writer.vocabulary;\n if (v === \"yed\" && Number(g.hasOutline) === 0) {\n put(\"borderWidth\", 0);\n return;\n }\n readColor(v === \"ogdf\" ? g.line : g.outline, \"borderColor\", null, writer, put, at);\n const width = outlineWidthOf(g, v);\n put(\"borderWidth\", width === undefined ? null : canonNumber(width, at(\"borderWidth\")));\n}\n\n/**\n * The outline width of a node's `graphics` record, under the key its writer uses.\n * @param g - the record\n * @param v - the writer's vocabulary\n * @returns the raw width, or undefined\n */\nfunction outlineWidthOf(g: Rec, v: GmlWriter[\"vocabulary\"]): unknown {\n switch (v) {\n case \"yed\":\n return g.outlineWidth;\n case \"cytoscape\":\n return first(g, \"outline_width\", \"width\");\n case \"ogdf\":\n return g.lineWidth;\n default:\n return first(g, \"width\", \"outlineWidth\");\n }\n}\n\n/**\n * Reads one edge's `graphics` record.\n * @param g - the record\n * @param writer - the writer\n * @param put - receives the values\n * @param at - the sites\n */\nfunction readEdgeGraphics(g: Rec, writer: GmlWriter, put: Put, at: At): void {\n const v = writer.vocabulary;\n readColor(g.fill, \"color\", \"opacity\", writer, put, at);\n const width = v === \"ogdf\" ? first(g, \"lineWidth\", \"width\") : g.width;\n put(\"width\", width === undefined ? null : canonNumber(width, at(\"width\")));\n put(\"lineStyle\", strokeStyle(v === \"ogdf\" ? g.stipple : g.style, \"lineStyle\", writer, at(\"lineStyle\")));\n if (typeof g.arrow === \"string\") {\n const ends = ARROW_ENDS.get(g.arrow.trim().toLowerCase());\n if (ends === undefined) {\n noteAt(at(\"targetArrow\"), STYLE_ISSUE.UNKNOWN_VALUE, g.arrow.slice(0, MAX_STYLE_VALUE_LENGTH));\n } else {\n put(\"sourceArrow\", ends[0]);\n put(\"targetArrow\", ends[1]);\n }\n }\n for (const [keys, property] of [\n [[\"sourceArrow\", \"source_arrow\"], \"sourceArrow\"],\n [[\"targetArrow\", \"target_arrow\"], \"targetArrow\"],\n ] as const) {\n const raw = first(g, ...keys);\n if (raw === undefined) {\n continue;\n }\n put(\n property,\n v === \"cytoscape\" && cytoscapeArrow !== undefined\n ? cytoscapeArrow(raw, at(property))\n : canonEnum(\"arrow\", raw, writer.spelling, at(property)),\n );\n }\n if (v === \"yed\") {\n readYedCurve(g, put);\n }\n}\n\n/**\n * Reads whether yEd draws an edge curved: `smoothBends` rounds the bends of its `Line`, whose points run from the\n * source through the bends to the target, so a line of two points (or none) stays straight.\n * @param g - the edge's `graphics` record\n * @param put - receives the value\n */\nfunction readYedCurve(g: Rec, put: Put): void {\n if (g.smoothBends !== undefined) {\n const points = isRec(g.Line) ? g.Line.point : undefined;\n put(\"curved\", Number(g.smoothBends) === 1 && Array.isArray(points) && points.length > 2);\n }\n}\n\n/**\n * Reads an element's label records: the first visible one with text; further visible ones are noted.\n * @param raw - the `LabelGraphics` value (one record or several)\n * @param writer - the writer\n * @param put - receives the values\n * @param at - the sites\n */\nfunction readLabelGraphics(raw: unknown, writer: GmlWriter, put: Put, at: At): void {\n const visible = (Array.isArray(raw) ? raw : [raw]).filter((l): l is Rec => isRec(l) && Number(l.visible) !== 0);\n const lg = visible.at(0);\n if (lg === undefined) {\n return;\n }\n const extra = visible.slice(1).filter((l) => l.text !== undefined).length;\n if (extra > 0) {\n noteAt(at(\"label\"), STYLE_ISSUE.EXTRA_LABELS, `${String(extra + 1)} labels`);\n }\n if (lg.text !== undefined) {\n put(\"label\", canonText(lg.text, at(\"label\")));\n }\n // the GML draft's `fill` is the text color; yEd's is the label's background box, its `color` the text color\n const yedLabel = writer.vocabulary === \"yed\" || YED_LABEL_KEYS.some((k) => Object.hasOwn(lg, k));\n if (lg.color !== undefined) {\n readColor(lg.color, \"labelColor\", null, writer, put, at);\n } else if (lg.fill !== undefined && !yedLabel) {\n readColor(lg.fill, \"labelColor\", null, writer, put, at);\n }\n if (lg.fill !== undefined && yedLabel) {\n noteAt(at(\"label\"), STYLE_ISSUE.NOT_CARRIED, \"label background\");\n }\n readLabelFont(lg, put, at);\n}\n\n/**\n * Reads a label record's font: its size, name, weight and slant.\n * @param lg - the record\n * @param put - receives the values\n * @param at - the sites\n */\nfunction readLabelFont(lg: Rec, put: Put, at: At): void {\n put(\"labelSize\", lg.fontSize === undefined ? null : canonNumber(lg.fontSize, at(\"labelSize\")));\n put(\"labelFont\", lg.fontName === undefined ? null : canonText(lg.fontName, at(\"labelFont\")));\n const style = scalarText(lg.fontStyle, at(\"labelWeight\"))?.trim().toLowerCase();\n if (style !== undefined) {\n const known = FONT_STYLES.get(style);\n if (known === undefined) {\n noteAt(at(\"labelWeight\"), STYLE_ISSUE.UNKNOWN_VALUE, style.slice(0, MAX_STYLE_VALUE_LENGTH));\n } else {\n put(\"labelWeight\", known[0]);\n put(\"labelItalic\", known[1]);\n }\n }\n}\n\n/**\n * Reads one element: its `graphics` and `LabelGraphics`, and the `label` key where the writer draws it.\n * @param target - nodes or edges\n * @param g - the graphics value\n * @param lg - the LabelGraphics value\n * @param label - the `label` key's value\n * @param writer - the writer\n * @param put - receives the values\n * @param at - the sites\n */\nfunction readElement(\n target: StyleTarget,\n g: unknown,\n lg: unknown,\n label: unknown,\n writer: GmlWriter,\n put: Put,\n at: At,\n): void {\n let text = false;\n const putLabel: Put = (property, value) => {\n text ||= property === \"label\" && value !== null;\n put(property, value);\n };\n if (isRec(g)) {\n (target === \"node\" ? readNodeGraphics : readEdgeGraphics)(g, writer, put, at);\n }\n if (lg !== null && lg !== undefined) {\n readLabelGraphics(lg, writer, putLabel, at);\n }\n // the GML draft draws the label key; Cytoscape reads it as the node's name, which its default style shows\n const drawn =\n writer.vocabulary === \"cytoscape\" ? target === \"node\" : writer.labelKey && (isRec(g) || lg !== undefined);\n if (!text && drawn && label !== null && label !== undefined) {\n put(\"label\", canonText(label, at(\"label\")));\n }\n}\n\n/**\n * The value of a column, or undefined when the table has no such column.\n * @param table - the node or edge table\n * @param name - the column\n * @param i - the row\n * @returns the value\n */\nfunction cellOf(table: GraphSnapshot[\"nodes\"], name: string, i: number): unknown {\n if (!table.has(name)) {\n return undefined;\n }\n const v = plainCell(table.value(name, i));\n return v ?? undefined;\n}\n\n/**\n * A node's center: the `graphics` `x` and `y` the importer moved into the position column.\n * @param snapshot - the graph\n * @param i - the node's index\n * @returns the center; NaN where the node has none\n */\nfunction centerOf(snapshot: GraphSnapshot, i: number): BendPoint {\n const column = snapshot.nodes.byRole(\"position\");\n const v = column?.isSet(i) === true ? (column.value(i) as ArrayLike<number>) : null;\n return v === null ? [Number.NaN, Number.NaN] : [v[0], v[1]];\n}\n\n/**\n * An edge's bends: the points of its `graphics` `Line` between the first and the last, which are where it leaves\n * the source and meets the target.\n * @param snapshot - the graph\n * @param g - the edge's `graphics` value\n * @param e - the edge's row\n * @returns the `bends` value, or null without bends\n */\nfunction lineBends(snapshot: GraphSnapshot, g: unknown, e: number): string | null {\n const raw = isRec(g) && isRec(g.Line) ? g.Line.point : undefined;\n if (!Array.isArray(raw) || raw.length < 3) {\n return null;\n }\n const points = raw.slice(1, -1).map((p): BendPoint => (isRec(p) ? [Number(p.x), Number(p.y)] : [Number.NaN, 0]));\n return canonBends(\n centerOf(snapshot, snapshot.edgeSource(e)),\n centerOf(snapshot, snapshot.edgeTarget(e)),\n points,\n true,\n );\n}\n\n/**\n * Every element's values, read with a writer's vocabulary.\n * @param snapshot - the graph\n * @param writer - the writer\n * @param notes - where problems are noted\n * @param context - the work budget\n * @returns the values per target, and whether anything was read\n */\nfunction readValues(\n snapshot: GraphSnapshot,\n writer: GmlWriter,\n notes: StyleNotes,\n context: Pick<StyleReadContext, \"budget\">,\n): { readonly node: ValueColumns; readonly edge: ValueColumns; readonly found: boolean } {\n let found = false;\n const read = (target: StyleTarget): ValueColumns => {\n const table = target === \"node\" ? snapshot.nodes : snapshot.edges;\n const n = target === \"node\" ? snapshot.nodeCount : snapshot.edgeCount;\n const out = valueColumns(n);\n if (!table.has(\"graphics\") && !table.has(\"LabelGraphics\") && writer.vocabulary !== \"cytoscape\") {\n return out.values;\n }\n for (let i = 0; i < n; i++) {\n context.budget.spend(target, 1);\n const at: At = (property) => ({ notes, target, property, element: i, budget: context.budget });\n readElement(\n target,\n cellOf(table, \"graphics\", i),\n cellOf(table, \"LabelGraphics\", i),\n cellOf(table, \"label\", i),\n writer,\n (property, value) => {\n if (value !== null) {\n found = true;\n out.put(i, property, value);\n }\n },\n at,\n );\n if (target === \"edge\") {\n const bends = lineBends(snapshot, cellOf(table, \"graphics\", i), i);\n if (bends !== null) {\n found = true;\n out.put(i, \"bends\", bends);\n }\n }\n }\n return out.values;\n };\n const node = read(\"node\");\n const edge = read(\"edge\");\n return { node, edge, found };\n}\n\n/**\n * The `graphty.styles` block of a file graphty wrote, with the per-element values its rules read moved inside it from\n * their `graphty_style_*` keys; the block as written when it is ignored anyway (graph-io then says why).\n * @param snapshot - the graph\n * @param text - the block's text\n * @returns the block's text for graph-io to read\n */\nfunction blockWithValues(snapshot: GraphSnapshot, text: string): string {\n const parsed = parseStyleBlock(text, styleFingerprint(snapshot));\n if (!parsed.ok || parsed.block.values !== undefined) {\n return text;\n }\n const node = tagValues(snapshot, \"node\", parsed.block.columns.node);\n const edge = tagValues(snapshot, \"edge\", parsed.block.columns.edge);\n if (node === null || edge === null) {\n // a style column is missing: graph-io ignores the block with a note\n return text;\n }\n const raw = JSON.parse(text) as Record<string, unknown>;\n return JSON.stringify({ ...raw, values: { node, edge } });\n}\n\n/**\n * The per-element values of a target's style columns, read from their `graphty_style_*` keys.\n * @param snapshot - the graph\n * @param target - nodes or edges\n * @param keys - the style columns the block names\n * @returns the values by key, or null when a key is missing\n */\nfunction tagValues(\n snapshot: GraphSnapshot,\n target: StyleTarget,\n keys: readonly string[],\n): Record<string, StyleColumn> | null {\n const table = target === \"node\" ? snapshot.nodes : snapshot.edges;\n const n = target === \"node\" ? snapshot.nodeCount : snapshot.edgeCount;\n const values: Record<string, StyleColumn> = {};\n for (const key of keys) {\n const name = tagKey(target, key);\n if (!table.has(name)) {\n return null;\n }\n values[key] = Array.from({ length: n }, (_, i) => {\n const v = plainCell(table.value(name, i));\n return typeof v === \"string\" || typeof v === \"number\" || typeof v === \"boolean\" ? v : null;\n });\n }\n return values;\n}\n\n/**\n * The columns of a table that hold styles: the graphics records and graphty's per-element style values.\n * @param table - the node or edge table\n * @returns the column names\n */\nfunction styleColumns(table: GraphSnapshot[\"nodes\"]): string[] {\n return [...table.names()].filter((c) => c === \"graphics\" || c === \"LabelGraphics\" || c.startsWith(TAG_PREFIX));\n}\n\n/**\n * The styles of a GML file, read the way the program that wrote it draws them, with that program's defaults beneath:\n * yEd, Cytoscape, Gephi and OGDF are recognized by the `Creator` line; igraph and every other writer get the GML\n * draft's keys and no defaults. A file graphty wrote gives back its `graphty.styles` block.\n * @param snapshot - the graph the import built\n * @param context - the work budget\n * @returns the styles, or null when the file has none\n */\nexport function gmlStyles(snapshot: GraphSnapshot, context: StyleReadContext): ImporterStyles | null {\n const notes = new StyleNotes();\n const writer = writerOf(snapshot);\n const values = readValues(snapshot, writer, notes, context);\n const blockText = graphText(snapshot, GML_STYLE_BLOCK_KEY);\n const block = blockText === null ? null : blockWithValues(snapshot, blockText);\n if (block !== null) {\n exactFromBlock(snapshot, block, values);\n }\n if (writer.tool === null && !values.found && block === null) {\n return null;\n }\n const gephi =\n writer.tool === \"gephi\"\n ? gephiRules(snapshot, values.node.fill, values.edge.color, context.budget, values.edge.width)\n : { rules: [], columns: new Map<string, StyleColumn>() };\n return {\n canonical: true,\n dialect: writer.dialect,\n tool: writer.tool,\n units: writer.units,\n node: { values: values.node },\n edge: { values: values.edge, rules: gephi.rules, columns: gephi.columns },\n notes: notes.list(),\n opacityInColor: true,\n block,\n // the graphics records and the per-element style values of a file graphty wrote hold styles, not data\n readFrom: { node: styleColumns(snapshot.nodes), edge: styleColumns(snapshot.edges) },\n };\n}\n\n// ============================================================ writing\n\n/**\n * What the GML writer holds natively: yEd GML `graphics` and `LabelGraphics`. The `graphty.styles` block and the\n * per-element values its rules read are keys of the graph and of each element.\n * @category Built-in formats\n */\nexport const GML_STYLE_CAPABILITIES: StyleWriteCapabilities = Object.freeze({\n node: Object.freeze([\n \"fill\",\n \"fillOpacity\",\n \"borderColor\",\n \"borderWidth\",\n \"borderStyle\",\n \"shape\",\n \"width\",\n \"height\",\n \"label\",\n \"labelColor\",\n \"labelSize\",\n \"labelFont\",\n \"labelWeight\",\n \"labelItalic\",\n ] as const),\n edge: Object.freeze([\n \"color\",\n \"opacity\",\n \"width\",\n \"lineStyle\",\n \"sourceArrow\",\n \"targetArrow\",\n \"curved\",\n \"bends\",\n \"label\",\n \"labelColor\",\n \"labelSize\",\n \"labelFont\",\n \"labelWeight\",\n \"labelItalic\",\n ] as const),\n block: \"native\",\n});\n\n/** Every style key a reader here reads, per record: the writer replaces them all. */\nconst OWNED: Readonly<Record<\"node\" | \"edge\" | \"label\", ReadonlySet<string>>> = {\n node: new Set([\n \"fill\",\n \"fill2\",\n \"hasFill\",\n \"outline\",\n \"hasOutline\",\n \"outlineWidth\",\n \"outline_width\",\n \"outlineStyle\",\n \"width\",\n \"line\",\n \"lineWidth\",\n \"stipple\",\n \"w\",\n \"h\",\n \"type\",\n ]),\n edge: new Set([\n \"fill\",\n \"width\",\n \"lineWidth\",\n \"style\",\n \"stipple\",\n \"arrow\",\n \"sourceArrow\",\n \"targetArrow\",\n \"source_arrow\",\n \"target_arrow\",\n \"smoothBends\",\n ]),\n label: new Set([\"text\", \"color\", \"fill\", \"fontSize\", \"fontName\", \"fontStyle\", \"visible\"]),\n};\n\n/** One element's value of a property. */\ntype Get = (property: string) => StyleValue | null;\n\n/** Records a value written as the nearest one yEd has. */\ntype Approximate = (property: string, value: StyleValue) => void;\n\n/**\n * A node's yEd `graphics` keys from its values.\n * @param get - the node's values\n * @param approximate - records approximations\n * @returns the keys\n */\nfunction nodeGraphics(get: Get, approximate: Approximate): Rec {\n const g: Rec = {};\n const width = get(\"width\");\n const height = get(\"height\");\n if (typeof width === \"number\") {\n g.w = width;\n }\n if (typeof height === \"number\") {\n g.h = height;\n }\n const shape = get(\"shape\");\n if (typeof shape === \"string\") {\n const w = yedValue(YED_SHAPES, shape, shape === \"vee\" ? \"triangle\" : \"rectangle\");\n if (!w.exact) {\n approximate(\"shape\", shape);\n }\n g.type = w.value;\n }\n const fill = get(\"fill\");\n const fillOpacity = get(\"fillOpacity\");\n if (typeof fill === \"string\") {\n g.fill = yedColor(fill, fillOpacity);\n } else if (fillOpacity === 0) {\n g.hasFill = 0;\n }\n const borderColor = get(\"borderColor\");\n const borderWidth = get(\"borderWidth\");\n const borderStyle = get(\"borderStyle\");\n if (typeof borderColor === \"string\") {\n g.outline = borderColor.toUpperCase();\n }\n if (typeof borderStyle === \"string\") {\n const w = yedValue(YED_LINES, borderStyle, \"line\");\n if (!w.exact) {\n approximate(\"borderStyle\", borderStyle);\n }\n g.outlineStyle = w.value;\n }\n if (borderWidth === 0) {\n g.hasOutline = 0;\n } else if (typeof borderWidth === \"number\") {\n g.outlineWidth = borderWidth;\n }\n return g;\n}\n\n/**\n * An edge's yEd `graphics` keys from its values.\n * @param get - the edge's values\n * @param approximate - records approximations\n * @returns the keys\n */\nfunction edgeGraphics(get: Get, approximate: Approximate): Rec {\n const g: Rec = {};\n const color = get(\"color\");\n if (typeof color === \"string\") {\n g.fill = yedColor(color, get(\"opacity\"));\n }\n const width = get(\"width\");\n if (typeof width === \"number\") {\n g.width = width;\n }\n const lineStyle = get(\"lineStyle\");\n if (typeof lineStyle === \"string\") {\n g.style = yedSpelled(\n YED_LINES,\n lineStyle,\n lineStyle === \"long-dash\" ? \"dashed\" : \"line\",\n \"lineStyle\",\n approximate,\n );\n }\n for (const property of [\"sourceArrow\", \"targetArrow\"]) {\n const arrow = get(property);\n if (typeof arrow === \"string\") {\n g[property] = yedSpelled(YED_ARROWS, arrow, \"standard\", property, approximate);\n }\n }\n const curved = get(\"curved\");\n if (typeof curved === \"boolean\") {\n g.smoothBends = curved ? 1 : 0;\n }\n return g;\n}\n\n/**\n * An element's yEd `LabelGraphics` keys from its values, or null when it has no label text.\n * @param get - the element's values\n * @returns the keys\n */\nfunction labelGraphics(get: Get): Rec | null {\n const text = get(\"label\");\n if (typeof text !== \"string\" || text.trim().length === 0) {\n return null;\n }\n const lg: Rec = { text };\n const color = get(\"labelColor\");\n if (typeof color === \"string\") {\n lg.color = color.toUpperCase();\n }\n const size = get(\"labelSize\");\n if (typeof size === \"number\") {\n lg.fontSize = size;\n }\n const font = get(\"labelFont\");\n if (typeof font === \"string\") {\n lg.fontName = font;\n }\n const weight = get(\"labelWeight\");\n const italic = get(\"labelItalic\");\n if (weight !== null || italic !== null) {\n const style = (weight === \"bold\" ? \"bold\" : \"\") + (italic === true ? \"italic\" : \"\");\n lg.fontStyle = style.length === 0 ? \"plain\" : style;\n }\n return lg;\n}\n\n/**\n * A record with the style keys replaced: the kept keys of the old record, then the written ones.\n * @param old - the record the element had, or anything else\n * @param owned - the style keys\n * @param written - the new style keys\n * @returns the record, or undefined (an unset cell) when it is empty\n */\nfunction merged(old: unknown, owned: ReadonlySet<string>, written: Rec): Rec | undefined {\n const out: Rec = {};\n if (isRec(old)) {\n for (const [k, v] of Object.entries(old)) {\n if (!owned.has(k)) {\n out[k] = v;\n }\n }\n }\n Object.assign(out, written);\n return Object.keys(out).length === 0 ? undefined : out;\n}\n\n/**\n * An element's `LabelGraphics` value with its first label's style keys replaced; further labels are kept.\n * @param old - the value the element had\n * @param written - the new label keys, or null for no label\n * @returns the value, or undefined (an unset cell)\n */\nfunction mergedLabels(old: unknown, written: Rec | null): unknown {\n const labels = Array.isArray(old) ? old : [old];\n const head = merged(labels[0], OWNED.label, written ?? {});\n const rest = labels.slice(1).filter((l) => l !== null && l !== undefined);\n if (rest.length === 0) {\n return head;\n }\n return head === undefined ? rest : [head, ...rest];\n}\n\n/**\n * Each element's values of the properties the writer writes, as a getter per element.\n * @param picture - each element's value of a property\n * @param target - nodes or edges\n * @returns the getter\n */\nfunction getter(\n picture: (target: StyleTarget, property: string) => readonly (StyleValue | null)[],\n target: StyleTarget,\n): (i: number) => Get {\n const columns = new Map<string, readonly (StyleValue | null)[]>();\n for (const p of GML_STYLE_CAPABILITIES[target]) {\n columns.set(p, picture(target, p));\n }\n return (i) => (property) => columns.get(property)?.[i] ?? null;\n}\n\n/**\n * For a file graphty wrote: where a value read from the graphics is what the writer writes for the block's own value\n * (a pentagon written as a rectangle, an opacity rounded to 255 steps), the block's exact value is the truth, so a\n * re-import gives back the same rules; a value another program changed since stays the truth.\n * @param snapshot - the graph\n * @param text - the block's text\n * @param read - the values read, changed in place\n * @param read.node - the node values\n * @param read.edge - the edge values\n */\nfunction exactFromBlock(\n snapshot: GraphSnapshot,\n text: string,\n read: { readonly node: ValueColumns; readonly edge: ValueColumns },\n): void {\n const parsed = parseStyleBlock(text, styleFingerprint(snapshot));\n const ex = parsed.ok ? blockStyles(parsed.block, snapshot, \"gml\") : null;\n if (ex === null) {\n return;\n }\n const notes = new StyleNotes();\n for (const target of [\"node\", \"edge\"] as const) {\n const n = target === \"node\" ? snapshot.nodeCount : snapshot.edgeCount;\n const get = getter((t, p) => resolveStyles(ex, t, p as never, snapshot), target);\n const values = read[target];\n for (let i = 0; i < n; i++) {\n const want = get(i);\n const back = writtenAndReadBack(target, want, notes);\n for (const property of GML_STYLE_CAPABILITIES[target]) {\n const native = values[property]?.[i] ?? null;\n const w = want(property);\n if (native !== w && native === (back.get(property) ?? null)) {\n values[property] ??= new Array<StyleValue | null>(n).fill(null);\n values[property][i] = w;\n }\n }\n }\n }\n}\n\n/**\n * An element's values written as the writer writes them and read back as the reader reads them.\n * @param target - nodes or edges\n * @param want - its values\n * @param notes - a scratch for the notes the round trip makes\n * @returns the values read back, by property\n */\nfunction writtenAndReadBack(target: StyleTarget, want: Get, notes: StyleNotes): Map<string, StyleValue> {\n const ignore: Approximate = () => undefined;\n const g = target === \"node\" ? nodeGraphics(want, ignore) : edgeGraphics(want, ignore);\n const back = new Map<string, StyleValue>();\n readElement(\n target,\n g,\n labelGraphics(want) ?? undefined,\n undefined,\n GRAPHTY_WRITER,\n (property, value) => {\n if (value !== null) {\n back.set(property, value);\n }\n },\n (property) => ({ notes, target, property }),\n );\n return back;\n}\n\n/** A GML export with styles worked out. */\ninterface GmlStyledExport {\n /** The graph to write: yEd graphics written from the styles, the block and the per-element style values added. */\n readonly snapshot: GraphSnapshot;\n /** W_STYLE_APPROXIMATED for every value written as the nearest one yEd has. */\n readonly notes: readonly LossNote[];\n}\n\n/**\n * Works out a GML export with styles: every node's and edge's `graphics` and `LabelGraphics` records get yEd's keys\n * for what graphty draws in place of every style key they had (positions, bends and other keys stay), the\n * `graphty.styles` block becomes the graph key `graphty_styles` and the per-element values its rules read become\n * element keys. Should two style columns map to one key, the values go inside the block instead.\n * @param snapshot - the graph handed to the exporter\n * @param input - the styles, or undefined when none are written\n * @returns the styled export, or null without styles\n */\nexport function gmlStyledExport(\n snapshot: GraphSnapshot,\n input: ExporterStyleInput | undefined,\n): GmlStyledExport | null {\n if (input === undefined) {\n return null;\n }\n const approximated = new StyleApproximations();\n const out = snapshot.withColumns();\n const renames: LossNote[] = [];\n for (const target of [\"node\", \"edge\"] as const) {\n const table = target === \"node\" ? out.nodes : out.edges;\n writeGraphicsColumns(snapshot, input, target, table, approximated);\n // the per-element style values of an earlier write go; a data column the rules read, or any other whose key\n // would read back as a style value, is renamed out of the keys the style values take\n const read = dataRead(input.rules.styles.rules, target);\n for (const name of table.names().filter((c) => mangleGmlKey(c).startsWith(TAG_PREFIX))) {\n const col = table.get(name);\n table.remove(name);\n if (col !== null && !(name.startsWith(TAG_PREFIX) && !read.has(name))) {\n renames.push(renameDataColumn(table, target, name, col));\n }\n }\n }\n let { block } = input;\n const keys = [...input.rules.columns.node.keys()].map((k) => tagKey(\"node\", k));\n const edgeKeys = [...input.rules.columns.edge.keys()].map((k) => tagKey(\"edge\", k));\n if (new Set(keys).size !== keys.length || new Set(edgeKeys).size !== edgeKeys.length) {\n block = writeStyleBlock(input.rules, { inlineColumns: true, snapshot });\n } else {\n setTagColumns(out, input);\n }\n out.graph.set(GML_STYLE_BLOCK_KEY, [block], { dtype: \"string\" });\n const notes: LossNote[] = [\n ...renames,\n ...(block === input.block ? [] : styleBlockLosses(block, input.rules.styles.rules.length, \"size\")),\n ...approximated.notes(\"yEd's GML\"),\n ];\n return { snapshot: out, notes };\n}\n\n/**\n * Writes every element's `graphics` and `LabelGraphics` records of a target with yEd's keys for what graphty draws,\n * keeping the keys that are not style keys.\n * @param snapshot - the graph handed to the exporter\n * @param input - the styles\n * @param target - nodes or edges\n * @param table - the target's table being written, changed in place\n * @param approximated - where approximations are counted\n */\nfunction writeGraphicsColumns(\n snapshot: GraphSnapshot,\n input: ExporterStyleInput,\n target: StyleTarget,\n table: GraphSnapshot[\"nodes\"],\n approximated: StyleApproximations,\n): void {\n const n = target === \"node\" ? snapshot.nodeCount : snapshot.edgeCount;\n const approximate: Approximate = (property, value) => {\n approximated.add(target, property, value);\n };\n const get = getter((t, p) => input.picture(t, p as never), target);\n const graphics: unknown[] = [];\n const labels: unknown[] = [];\n for (let i = 0; i < n; i++) {\n const g = target === \"node\" ? nodeGraphics(get(i), approximate) : edgeGraphics(get(i), approximate);\n if (target === \"edge\") {\n const line = bendsLine(snapshot, get(i)(\"bends\"), i);\n if (line !== null) {\n g.Line = line;\n }\n }\n graphics.push(merged(cellOf(table, \"graphics\", i), OWNED[target], g));\n labels.push(mergedLabels(cellOf(table, \"LabelGraphics\", i), labelGraphics(get(i))));\n }\n for (const [name, cells] of [\n [\"graphics\", graphics],\n [\"LabelGraphics\", labels],\n ] as const) {\n if (cells.some((c) => c !== undefined)) {\n table.set(name, cells, { dtype: \"json\", nullable: true });\n } else if (table.has(name)) {\n table.remove(name);\n }\n }\n}\n\n/**\n * An edge's `Line` from its `bends` value: the node centers it is written between, with the bends placed between them,\n * so the bends read back as written.\n * @param snapshot - the graph handed to the exporter\n * @param bends - the edge's `bends` value\n * @param e - the edge's row\n * @returns the `Line` record, or null without a value or without both centers\n */\nfunction bendsLine(snapshot: GraphSnapshot, bends: StyleValue | null, e: number): Rec | null {\n const source = centerOf(snapshot, snapshot.edgeSource(e));\n const target = centerOf(snapshot, snapshot.edgeTarget(e));\n const points = typeof bends === \"string\" ? bendsToPoints(source, target, bends, true) : null;\n if (points === null || ![...source, ...target].every(Number.isFinite)) {\n return null;\n }\n return { point: [source, ...points, target].map(([x, y]) => ({ x, y })) };\n}\n\n/**\n * Writes a data column under a name out of the keys the style values take.\n * @param table - the table, changed in place\n * @param target - nodes or edges\n * @param name - the column's name\n * @param col - the column\n * @returns the note saying so\n */\nfunction renameDataColumn(\n table: GraphSnapshot[\"nodes\"],\n target: StyleTarget,\n name: string,\n col: NonNullable<ReturnType<GraphSnapshot[\"nodes\"][\"get\"]>>,\n): LossNote {\n let renamed = `data_${name}`;\n let k = 2;\n while (table.has(renamed)) {\n renamed = `data_${name}_${String(k)}`;\n k++;\n }\n table.set(renamed, col);\n return Object.freeze({\n code: KEY_MANGLED_CODE,\n message: `${target} column \"${name}\" is written as \"${renamed}\": keys starting with ${TAG_PREFIX} hold graphty's style values`,\n column: name,\n count: null,\n });\n}\n\n/**\n * Sets the per-element values the rules read as element keys.\n * @param out - the graph, changed in place\n * @param input - the styles\n */\nfunction setTagColumns(out: GraphSnapshot, input: ExporterStyleInput): void {\n for (const target of [\"node\", \"edge\"] as const) {\n const table = target === \"node\" ? out.nodes : out.edges;\n for (const [key, col] of input.rules.columns[target]) {\n const kinds = new Set(col.filter((v) => v !== null).map((v) => typeof v));\n const text = kinds.size > 1 || kinds.has(\"string\");\n let dtype: \"string\" | \"bool\" | \"f64\" = kinds.has(\"boolean\") ? \"bool\" : \"f64\";\n if (text) {\n dtype = \"string\";\n }\n table.set(tagKey(target, key), text ? col.map((v) => (v === null ? null : String(v))) : col, { dtype });\n }\n }\n}\n","/**\n * The GML exporter (design section 8.5, research note 07 sections 2.2 and 9): writes a snapshot in\n * the NetworkX dialect of GML. Node ids must be integers (`idCharset: \"integer\"`; `sanitizeIds:\n * \"mangle\"` renumbers the others and keeps the original in a `graphty_originalId` key the importer\n * restores); columns are written per dtype (`int` for the integer dtypes, `real` with a decimal\n * point guaranteed for f32 / f64 so the dtype survives a re-import, quoted strings with `&#NN;`\n * references, repeated keys for lists with the `_networkx_list_start` marker for one-element\n * lists and `\"[]\"` for empty ones, nested records for json objects); the position role becomes\n * `graphics [ x y z ]` merged with the node's `graphics` json record; graph columns are written\n * inside `graph [ ]` (or at the top level when the importer found them there); `Creator` and\n * `Version` come from the metadata.\n *\n * check() reports, before anything is written, the capability gaps of the common check plus the\n * GML-specific ones: json columns holding numbers (JSON cannot keep the int / real distinction:\n * `W_GML_RECORD_NUMBER_TYPE`), booleans (written 1 / 0) or nulls (omitted), arrays nested in\n * arrays (no GML spelling; export() throws), column names and record keys that are not GML keys\n * or collide with the structural keys (`E_GML_INVALID_KEY` / `E_GML_RESERVED_KEY`, or\n * `W_GML_KEY_MANGLED` under `sanitizeKeys: \"mangle\"`), and graphics / position overlaps.\n */\n\nimport {\n type Column,\n type ColumnMeta,\n GraphFormatError,\n type GraphSnapshot,\n type JsonColumn,\n type NodeId,\n} from \"@graphty/graph-format\";\n\nimport { DICT_SAMPLE_ROWS, DictHeuristic } from \"../../common/attributes.js\";\nimport { type PairFolding, pairFolding } from \"../../common/direction.js\";\nimport { quoteGmlString } from \"../../common/escape.js\";\nimport {\n capabilities,\n checkCapabilities,\n countMixedEdges,\n LOSS,\n type SanitizedIds,\n sanitizeIds,\n} from \"../../common/export.js\";\nimport { formatGmlReal, formatInteger } from \"../../common/format.js\";\nimport { type ResolvedExportOptions, resolveExportOptions } from \"../../common/options.js\";\nimport { agree, plural } from \"../../common/plural.js\";\nimport { type ExplicitWeights, explicitWeights } from \"../../common/weights.js\";\nimport { encodeChunks, joinText } from \"../../common/writer.js\";\nimport type { ExporterStyleOptions } from \"../../styles/io/writer.js\";\nimport { type CommonExportOptions, type ExportCapabilities, type GraphExporter, type LossNote } from \"../../types.js\";\nimport { GML_STYLE_CAPABILITIES, gmlStyledExport } from \"./styles.js\";\nimport {\n EMPTY_LIST_TEXT,\n isGmlKey,\n KEY_MANGLED_CODE,\n LIST_START_MARKER,\n mangleGmlKey,\n ORIGINAL_ID_KEY,\n} from \"./syntax.js\";\n\n/** What the writer takes: the format's options, the common ones and the styles. */\ntype GmlWriteOptions = GmlExportOptions & CommonExportOptions & ExporterStyleOptions;\n\n/**\n * The format-specific options of the GML exporter.\n * @category Built-in formats\n */\nexport interface GmlExportOptions extends CommonExportOptions {\n /**\n * The edge key the weights are written under. The default is the key a GML import read them\n * from, else `value`.\n * @defaultValue as read, else \"value\"\n */\n weightKey?: string | undefined;\n /**\n * What to do with an attribute name or record key that GML cannot write: one that is not a GML\n * key (letters, digits and `_`, starting with a letter, so `Edge Label` is not one), or one that\n * GML uses itself in that record: `id` for a node attribute; `source`, `target` and `directed`\n * for an edge attribute; `node`, `edge`, `directed` and `multigraph` for a graph attribute. A node\n * attribute named `source` is fine. \"error\" makes the save fail, \"mangle\" rewrites the name (`.`\n * and other characters become `_`, a clash gets a `_2` suffix) and checkExport() lists each\n * rename. An options object shared by saves to several formats that include GML should set it.\n * @defaultValue \"error\"\n */\n sanitizeKeys?: \"error\" | \"mangle\" | undefined;\n}\n\n/**\n * A nested (json) attribute holds numbers; GML records do not keep the difference between integers and decimals.\n * @category Issue and loss codes\n */\nexport const RECORD_NUMBER_TYPE_CODE = \"W_GML_RECORD_NUMBER_TYPE\";\n/**\n * A json column holds booleans, written as 1 / 0.\n * @category Issue and loss codes\n */\nexport const RECORD_BOOLEAN_CODE = \"W_GML_RECORD_BOOLEAN\";\n/**\n * A json column holds nulls, which GML cannot write; the key (or the row) is omitted.\n * @category Issue and loss codes\n */\nexport const RECORD_NULL_CODE = \"W_GML_RECORD_NULL\";\n/**\n * An attribute holds an array inside an array, which GML cannot write; the save fails.\n * @category Issue and loss codes\n */\nexport const NESTED_ARRAY_CODE = \"E_GML_NESTED_ARRAY\";\n/**\n * A nested (json) attribute holds arrays; they are written as repeated keys and read back as a list attribute.\n * @category Issue and loss codes\n */\nexport const JSON_ARRAY_CODE = \"W_GML_JSON_ARRAY\";\n/**\n * A column name or record key is not a GML key; export() throws unless sanitizeKeys is \"mangle\".\n * @category Issue and loss codes\n */\nexport const INVALID_KEY_CODE = \"E_GML_INVALID_KEY\";\n/**\n * A column name collides with a structural GML key; export() throws unless sanitizeKeys is \"mangle\".\n * @category Issue and loss codes\n */\nexport const RESERVED_KEY_CODE = \"E_GML_RESERVED_KEY\";\nexport { KEY_MANGLED_CODE } from \"./syntax.js\";\n/**\n * A position column with more than three components; x, y and z are written.\n * @category Issue and loss codes\n */\nexport const POSITION_COMPONENTS_CODE = \"W_GML_POSITION_COMPONENTS\";\n/**\n * A node's graphics record has x / y / z keys the position column replaces.\n * @category Issue and loss codes\n */\nexport const GRAPHICS_OVERRIDDEN_CODE = \"W_GML_GRAPHICS_OVERRIDDEN\";\n/**\n * A node's graphics value is not a record and cannot hold the position; export() throws.\n * @category Issue and loss codes\n */\nexport const GRAPHICS_CONFLICT_CODE = \"E_GML_GRAPHICS_CONFLICT\";\n\n/**\n * The default weight key (design section 8.4: GML weights are read from `value` by default).\n * @category Plugin helpers\n */\nexport const DEFAULT_WEIGHT_KEY = \"value\";\n\n/** The roles GML has a key for (`label`, the edge `id` and `key`); every other role is reported. */\nconst KEPT_ROLES: ReadonlySet<string> = new Set([\"label\", \"id\", \"key\"]);\n\n/** The key the importer maps each kept role back from (the column name after re-import). */\nconst ROLE_NAMES: Readonly<Record<string, string>> = Object.freeze({\n label: \"label\",\n id: \"id\",\n key: \"key\",\n});\n\nconst GML_CAPABILITIES: ExportCapabilities = capabilities({\n mixedDirection: false,\n multiEdges: true,\n selfLoops: true,\n edgeIds: \"optional\",\n idCharset: \"integer\",\n dtypes: [\"i32\", \"f64\", \"string\", \"dict\", \"json\"],\n components: false,\n lists: true,\n json: true,\n defaults: false,\n options: false,\n hierarchy: false,\n temporal: \"none\",\n graphAttributes: true,\n positions: true,\n viz: false,\n});\n\n/** Roles whose columns are never written as attributes (structural, or dropped per the capabilities). */\nconst SKIPPED_ROLES: ReadonlySet<string> = new Set([\n \"directed\",\n \"pair\",\n \"mutual\",\n \"weight\",\n \"timeText\",\n \"originalId\",\n \"position\",\n \"color\",\n \"size\",\n \"shape\",\n \"thickness\",\n \"parent\",\n \"parents\",\n \"start\",\n \"end\",\n \"timestamp\",\n \"timestamps\",\n \"spells\",\n \"open\",\n \"spellsOpen\",\n]);\n\nconst NODE_RESERVED: ReadonlySet<string> = new Set([\"id\"]);\nconst EDGE_RESERVED: ReadonlySet<string> = new Set([\"source\", \"target\", \"directed\"]);\nconst GRAPH_RESERVED: ReadonlySet<string> = new Set([\"node\", \"edge\", \"directed\", \"multigraph\"]);\nconst TOP_RESERVED: ReadonlySet<string> = new Set([\"graph\"]);\nconst NUMBER_TEXT = /^[+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?$/;\n\n/** The resolved options of one export. */\ninterface GmlExportPlan {\n readonly common: ResolvedExportOptions;\n readonly weightKey: string;\n readonly mangle: boolean;\n}\n\n/** What one json column holds that GML cannot write exactly. */\ninterface JsonStats {\n numbers: number;\n booleans: number;\n nulls: number;\n nestedArrays: number;\n arrays: number;\n invalidKeys: number;\n}\n\n/** The kinds of value already counted for one row while inspecting a json value. */\ninterface SeenFlags {\n numbers: boolean;\n booleans: boolean;\n nulls: boolean;\n nested: boolean;\n}\n\n/** The columns of one table selected for writing, with their keys. */\ninterface WrittenColumn {\n readonly column: Column;\n readonly key: string;\n}\n\n/**\n * Resolve the options of one export call.\n * @param snapshot - the snapshot\n * @param options - the caller's options\n * @returns the plan\n */\nfunction planOf(snapshot: GraphSnapshot, options: (GmlExportOptions & CommonExportOptions) | undefined): GmlExportPlan {\n const common = resolveExportOptions(options);\n const mode = options?.sanitizeKeys ?? \"error\";\n if (mode !== \"error\" && mode !== \"mangle\") {\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n `option sanitizeKeys: ${JSON.stringify(mode)} is not \"error\" or \"mangle\"`,\n {\n option: \"sanitizeKeys\",\n found: mode,\n },\n );\n }\n let weightKey = options?.weightKey;\n if (weightKey === undefined) {\n const origin = snapshot.meta.weightOrigin;\n weightKey = origin !== null && origin.format === \"gml\" && origin.id !== null ? origin.id : DEFAULT_WEIGHT_KEY;\n } else if (typeof weightKey !== \"string\" || !isGmlKey(weightKey)) {\n throw new GraphFormatError(\"E_UNSUPPORTED\", `option weightKey: ${JSON.stringify(weightKey)} is not a GML key`, {\n option: \"weightKey\",\n found: weightKey,\n });\n }\n return { common, weightKey, mangle: mode === \"mangle\" };\n}\n\n/**\n * Whether a column is written as an attribute (its role is neither structural nor dropped).\n * @param column - the column\n * @returns true when written\n */\nfunction isWritten(column: Column): boolean {\n const { role } = column.meta;\n return role === null || !SKIPPED_ROLES.has(role);\n}\n\n/**\n * The key a column is written under.\n * @param meta - the column metadata\n * @returns origin.id when the column came from GML under that key (its name is the key, or the importer's\n * `<key>#...` rename of it), else the name: a column renamed since it was read is written under its new name\n */\nfunction preferredKey(meta: ColumnMeta): string {\n const { origin, name } = meta;\n if (origin?.format !== \"gml\" || origin.id === null) {\n return name;\n }\n return name === origin.id || name.startsWith(`${origin.id}#`) ? origin.id : name;\n}\n\n/**\n * Whether a snapshot has explicit weights to write.\n * @param snapshot - the snapshot\n * @returns true when weighted\n */\nfunction hasWeights(snapshot: GraphSnapshot): boolean {\n return snapshot.flags.weighted;\n}\n\n/**\n * Whether the graph column is a top-level key (the importer's `extra.gmlTopLevel`).\n * @param column - the column\n * @returns true for a top-level key\n */\nfunction isTopLevel(column: Column): boolean {\n return column.meta.extra.gmlTopLevel === true;\n}\n\n/**\n * The text of a `Version` value: bare when it is a number text, quoted otherwise.\n * @param text - the version text\n * @returns the GML value\n */\nfunction versionText(text: string): string {\n return NUMBER_TEXT.test(text) ? text : quoteGmlString(text);\n}\n\n/**\n * A node or edge table's label role column, which is written under \"label\" (the key the importer\n * gives the role back to): the key is marked used so a plain column of that name cannot have it.\n * @param columns - the written columns\n * @param label - the table name\n * @param used - the keys already taken, gaining \"label\" when there is a label role column\n * @returns the label role column, or undefined\n */\nfunction labelRoleColumn(columns: readonly Column[], label: string, used: Set<string>): Column | undefined {\n if (label !== \"node\" && label !== \"edge\") {\n return undefined;\n }\n const column = columns.find((c) => c.meta.role === \"label\");\n if (column !== undefined) {\n used.add(\"label\");\n }\n return column;\n}\n\n/**\n * Select the written columns of a table and assign their keys, recording invalid and reserved\n * keys as notes (or rewriting them under mangle).\n * @param table - the columns\n * @param reserved - the structural keys of the table\n * @param label - the table name for messages\n * @param plan - the export plan\n * @param notes - where to record\n * @param filter - an extra selection predicate\n * @returns the written columns with their keys\n */\nfunction selectColumns(\n table: Iterable<Column>,\n reserved: ReadonlySet<string>,\n label: string,\n plan: GmlExportPlan,\n notes: LossNote[] | null,\n filter: (column: Column) => boolean = (): boolean => true,\n): WrittenColumn[] {\n const used = new Set<string>(reserved);\n const out: WrittenColumn[] = [];\n const columns = [...table].filter((c) => isWritten(c) && filter(c));\n const labelRole = labelRoleColumn(columns, label, used);\n for (const column of columns) {\n const preferred = column === labelRole ? \"label\" : preferredKey(column.meta);\n let key = preferred;\n const valid = isGmlKey(preferred);\n const taken = column !== labelRole && used.has(preferred);\n if (!valid || taken) {\n const code = valid ? RESERVED_KEY_CODE : INVALID_KEY_CODE;\n let why = \"is not a GML key\";\n if (valid) {\n why = reserved.has(preferred) ? \"collides with a structural GML key\" : \"repeats another column's key\";\n }\n if (!plan.mangle) {\n if (notes === null) {\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n `${label} column \"${column.meta.name}\" ${why}; pass sanitizeKeys: \"mangle\" to rewrite it`,\n {\n reason: \"gml key\",\n column: column.meta.name,\n key: preferred,\n },\n );\n }\n notes.push(\n note(\n code,\n `${label} column \"${column.meta.name}\" ${why}; the save fails unless sanitizeKeys is \"mangle\"`,\n column.meta.name,\n ),\n );\n continue;\n }\n key = uniqueKey(valid ? preferred : mangleGmlKey(preferred), used);\n notes?.push(\n note(\n KEY_MANGLED_CODE,\n `${label} column \"${column.meta.name}\" is written as \"${key}\"`,\n column.meta.name,\n ),\n );\n }\n used.add(key);\n out.push({ column, key });\n }\n return out;\n}\n\n/**\n * A key not yet used: the base, else base_2, base_3...\n * @param base - a valid key\n * @param used - the keys taken\n * @returns a free key\n */\nfunction uniqueKey(base: string, used: ReadonlySet<string>): string {\n let candidate = base;\n for (let k = 2; used.has(candidate); k++) {\n candidate = `${base}_${k}`;\n }\n return candidate;\n}\n\n/**\n * Build a frozen note.\n * @param code - the code\n * @param message - the message\n * @param column - the column, or null\n * @param count - the count, or null\n * @returns the note\n */\nfunction note(code: string, message: string, column: string | null = null, count: number | null = null): LossNote {\n return Object.freeze({ code, message, column, count });\n}\n\n/**\n * Count a kind of json value once per row.\n * @param seen - the flags already counted for this row\n * @param flag - the flag of the kind\n * @param stats - the counters\n * @param counter - the counter of the kind\n */\nfunction countOnce(seen: SeenFlags, flag: keyof SeenFlags, stats: JsonStats, counter: keyof JsonStats): void {\n if (!seen[flag]) {\n seen[flag] = true;\n stats[counter]++;\n }\n}\n\n/**\n * Inspect a JSON value for what GML cannot write exactly.\n * @param value - the value\n * @param stats - the counters to update (each counted at most once per call for numbers / booleans / nulls)\n * @param inArray - whether the value is an array item\n * @param seen - the flags already counted for this row\n */\nfunction inspectJson(value: unknown, stats: JsonStats, inArray: boolean, seen: SeenFlags): void {\n if (value === null) {\n countOnce(seen, \"nulls\", stats, \"nulls\");\n return;\n }\n switch (typeof value) {\n case \"number\":\n countOnce(seen, \"numbers\", stats, \"numbers\");\n return;\n case \"boolean\":\n countOnce(seen, \"booleans\", stats, \"booleans\");\n return;\n case \"string\":\n return;\n default:\n break;\n }\n if (Array.isArray(value)) {\n if (inArray) {\n countOnce(seen, \"nested\", stats, \"nestedArrays\");\n }\n for (const item of value) {\n inspectJson(item, stats, true, seen);\n }\n return;\n }\n const record = value as Record<string, unknown>;\n for (const key of Object.keys(record)) {\n if (!isGmlKey(key)) {\n stats.invalidKeys++;\n }\n inspectJson(record[key], stats, false, seen);\n }\n}\n\n/**\n * A row count in words.\n * @param count - the count\n * @returns the count and the word row, pluralised\n */\nfunction rowCount(count: number): string {\n return `${count} row${plural(count)}`;\n}\n\n/**\n * Record a note for a counter that is not zero.\n * @param notes - where to record\n * @param count - the counter\n * @param code - the note code\n * @param text - the note message\n * @param column - the column name\n */\nfunction pushCounted(notes: LossNote[], count: number, code: string, text: string, column: string): void {\n if (count > 0) {\n notes.push(note(code, text, column, count));\n }\n}\n\n/**\n * The GML-specific notes of one table's json columns.\n * @param columns - the written columns\n * @param label - the table name\n * @param plan - the export plan\n * @param notes - where to record\n */\nfunction jsonNotes(columns: readonly WrittenColumn[], label: string, plan: GmlExportPlan, notes: LossNote[]): void {\n for (const { column } of columns) {\n const stats = jsonStatsOf(column);\n if (stats === null) {\n continue;\n }\n const { name } = column.meta;\n const where = `${label} column \"${name}\"`;\n const counted = (count: number, code: string, text: string): void => {\n pushCounted(notes, count, code, text, name);\n };\n counted(\n stats.numbers,\n RECORD_NUMBER_TYPE_CODE,\n `${where} holds numbers in ${rowCount(stats.numbers)}; GML records cannot keep the int / real distinction`,\n );\n counted(\n stats.booleans,\n RECORD_BOOLEAN_CODE,\n `${where} holds booleans in ${rowCount(stats.booleans)}; written as 1 / 0`,\n );\n counted(\n stats.nulls,\n RECORD_NULL_CODE,\n `${where} holds nulls in ${rowCount(stats.nulls)}; GML has no null, the key is omitted`,\n );\n counted(\n stats.arrays,\n JSON_ARRAY_CODE,\n `${where} holds arrays as values in ${rowCount(stats.arrays)}; written as repeated keys, they re-import as a list`,\n );\n counted(\n stats.nestedArrays,\n NESTED_ARRAY_CODE,\n `${where} holds arrays nested in arrays in ${rowCount(stats.nestedArrays)}; GML cannot write them and the save fails`,\n );\n const keys = `${stats.invalidKeys} record key${plural(stats.invalidKeys)} ${agree(stats.invalidKeys, \"is\", \"are\")} not GML keys`;\n counted(\n stats.invalidKeys,\n plan.mangle ? KEY_MANGLED_CODE : INVALID_KEY_CODE,\n plan.mangle\n ? `${where}: ${keys} and are rewritten`\n : `${where}: ${keys}; the save fails unless sanitizeKeys is \"mangle\"`,\n );\n }\n}\n\n/**\n * The json statistics of a json column, or of a list column with json items; null for other dtypes.\n * @param column - the column\n * @returns the stats, or null\n */\nfunction jsonStatsOf(column: Column): JsonStats | null {\n const stats: JsonStats = { numbers: 0, booleans: 0, nulls: 0, nestedArrays: 0, arrays: 0, invalidKeys: 0 };\n if (column.dtype === \"json\") {\n for (let r = 0; r < column.length; r++) {\n if (!column.isSet(r)) {\n continue;\n }\n const value = column.values[r];\n const seen: SeenFlags = { numbers: false, booleans: false, nulls: false, nested: false };\n if (Array.isArray(value)) {\n stats.arrays++;\n for (const item of value) {\n inspectJson(item, stats, true, seen);\n }\n } else {\n inspectJson(value, stats, false, seen);\n }\n }\n return stats;\n }\n if (column.dtype === \"list\" && column.meta.itemDtype === \"json\") {\n for (let r = 0; r < column.length; r++) {\n if (!column.isSet(r)) {\n continue;\n }\n const seen: SeenFlags = { numbers: false, booleans: false, nulls: false, nested: false };\n for (const item of column.sliceOf(r)) {\n inspectJson(item, stats, true, seen);\n }\n }\n return stats;\n }\n return null;\n}\n\n/**\n * The node position column when it can be mapped to graphics x / y / z: a numeric scalar column\n * with the position role.\n * @param snapshot - the snapshot\n * @returns the column, or null\n */\nfunction positionColumn(snapshot: GraphSnapshot): Column | null {\n const column = snapshot.nodes.byRole(\"position\");\n if (column === null) {\n return null;\n }\n switch (column.dtype) {\n case \"f32\":\n case \"f64\":\n case \"i32\":\n case \"u32\":\n case \"u8\":\n return column;\n default:\n return null;\n }\n}\n\n/**\n * The node `graphics` json column, when present.\n * @param snapshot - the snapshot\n * @returns the column, or null\n */\nfunction graphicsColumn(snapshot: GraphSnapshot): JsonColumn | null {\n return snapshot.nodes.typed(\"graphics\", \"json\");\n}\n\n/**\n * The GML-specific notes about the position / graphics mapping.\n * @param snapshot - the snapshot\n * @param notes - where to record\n */\nfunction graphicsNotes(snapshot: GraphSnapshot, notes: LossNote[]): void {\n const position = positionColumn(snapshot);\n if (position === null) {\n return;\n }\n if (position.meta.components > 3) {\n notes.push(\n note(\n POSITION_COMPONENTS_CODE,\n `node column \"${position.meta.name}\" has ${position.meta.components} components; only x, y and z are written`,\n position.meta.name,\n position.length - position.nullCount,\n ),\n );\n }\n const graphics = graphicsColumn(snapshot);\n if (graphics === null) {\n return;\n }\n let overridden = 0;\n let conflicts = 0;\n for (let r = 0; r < snapshot.nodeCount; r++) {\n if (!position.isSet(r) || !graphics.isSet(r)) {\n continue;\n }\n const value = graphics.values[r];\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n conflicts++;\n } else if (\"x\" in value || \"y\" in value || \"z\" in value) {\n overridden++;\n }\n }\n if (overridden > 0) {\n notes.push(\n note(\n GRAPHICS_OVERRIDDEN_CODE,\n `${overridden} node graphics record${plural(overridden)} ${agree(overridden, \"has\", \"have\")} x / y / z keys the position column replaces`,\n \"graphics\",\n overridden,\n ),\n );\n }\n if (conflicts > 0) {\n notes.push(\n note(\n GRAPHICS_CONFLICT_CODE,\n `${conflicts} node graphics value${plural(conflicts)} ${agree(conflicts, \"is\", \"are\")} not records and cannot hold the position; the save fails`,\n \"graphics\",\n conflicts,\n ),\n );\n }\n}\n\n/**\n * What the importer's own rules change on re-import of the written columns: an all-unset column\n * vanishes (GML writes cells, never declarations), a role-less column named like a role key\n * gains the role, and the dictionary heuristic of design section 5.4 turns a low-cardinality\n * string column into a dict (or a wide dict into a string).\n * @param columns - the written columns\n * @param domain - node or edge\n * @param notes - where to record\n */\nfunction reimportNotes(columns: readonly WrittenColumn[], domain: \"node\" | \"edge\", notes: LossNote[]): void {\n for (const { column, key } of columns) {\n const { meta } = column;\n const set = column.length - column.nullCount;\n if (set === 0) {\n notes.push(\n note(\n LOSS.EMPTY_COLUMN,\n `${domain} column \"${meta.name}\" has no set cell and is not written: GML writes cells, never declarations`,\n meta.name,\n 0,\n ),\n );\n continue;\n }\n if (meta.role === null && (key === \"label\" || (domain === \"edge\" && (key === \"id\" || key === \"key\")))) {\n notes.push(\n note(\n LOSS.ROLE_ASSUMED,\n `${domain} column \"${meta.name}\" is written under \"${key}\" and reads back with the ${key === \"label\" ? \"label\" : key} role`,\n meta.name,\n set,\n ),\n );\n continue;\n }\n if (column.dtype === \"list\" || !(column.dtype === \"string\" || column.dtype === \"dict\")) {\n continue;\n }\n const heuristic = new DictHeuristic(DICT_SAMPLE_ROWS);\n for (let r = 0; r < column.length && !heuristic.decided; r++) {\n if (column.isSet(r)) {\n heuristic.observe(column.value(r) as string);\n }\n }\n const readsAsDict = heuristic.decide() === \"dict\";\n if (column.dtype === \"string\" && readsAsDict) {\n notes.push(\n note(\n LOSS.STORAGE_CLASS,\n `${domain} column \"${meta.name}\" reads back as dict (low cardinality)`,\n meta.name,\n null,\n ),\n );\n } else if (column.dtype === \"dict\" && !readsAsDict) {\n notes.push(\n note(\n LOSS.STORAGE_CLASS,\n `${domain} column \"${meta.name}\" reads back as string (cardinality too high for a dict)`,\n meta.name,\n null,\n ),\n );\n }\n }\n}\n\n/**\n * The importer names the graphics-derived position column `position`, or `position#graphics`\n * when a plain `position` key is written next to it (design section 5.6); a position column\n * named otherwise reads back under that name.\n * @param snapshot - the snapshot\n * @param nodeColumns - the written node columns\n * @param notes - where to record\n */\nfunction positionNameNote(snapshot: GraphSnapshot, nodeColumns: readonly WrittenColumn[], notes: LossNote[]): void {\n const position = positionColumn(snapshot);\n if (position === null) {\n return;\n }\n const { name } = position.meta;\n const plainPosition = nodeColumns.some((c) => c.key === \"position\");\n const reimportName = plainPosition ? \"position#graphics\" : \"position\";\n if (name !== reimportName) {\n notes.push(\n note(\n LOSS.COLUMN_NAME_CHANGED,\n `node column \"${name}\" (position) is written as the graphics x / y / z keys and reads back as \"${reimportName}\"`,\n name,\n position.length - position.nullCount,\n ),\n );\n }\n}\n\n/**\n * Pre-flight: the common capability notes plus the GML-specific ones.\n * @param snapshot - the snapshot\n * @param options - the options\n * @returns the notes, empty when the export is exact\n */\nfunction check(snapshot: GraphSnapshot, options?: GmlExportOptions & CommonExportOptions): readonly LossNote[] {\n const plan = planOf(snapshot, options);\n const notes = checkCapabilities(snapshot, GML_CAPABILITIES, plan.common, {\n positionDtype: \"f64\",\n roles: KEPT_ROLES,\n roleNames: ROLE_NAMES,\n });\n const nodeReserved = new Set(NODE_RESERVED);\n if (\n (plan.common.sanitizeIds === \"mangle\" && countMangled(snapshot) > 0) ||\n snapshot.nodes.byRole(\"originalId\") !== null\n ) {\n nodeReserved.add(ORIGINAL_ID_KEY);\n }\n const edgeIds = snapshot.edges.byRole(\"id\");\n const edgeReserved = edgeReservedKeys(snapshot, plan, edgeIds);\n const topReserved = topReservedKeys(snapshot);\n const nodeColumns = selectColumns(snapshot.nodes, nodeReserved, \"node\", plan, notes);\n const edgeColumns = selectColumns(snapshot.edges, edgeReserved, \"edge\", plan, notes, (c) => c !== edgeIds);\n const graphColumns = selectColumns(snapshot.graph, GRAPH_RESERVED, \"graph\", plan, notes, (c) => !isTopLevel(c));\n const topColumns = selectColumns(snapshot.graph, topReserved, \"top-level\", plan, notes, isTopLevel);\n jsonNotes(nodeColumns, \"node\", plan, notes);\n jsonNotes(edgeColumns, \"edge\", plan, notes);\n jsonNotes(graphColumns, \"graph\", plan, notes);\n jsonNotes(topColumns, \"top-level\", plan, notes);\n graphicsNotes(snapshot, notes);\n positionNameNote(snapshot, nodeColumns, notes);\n reimportNotes(nodeColumns, \"node\", notes);\n reimportNotes(edgeColumns, \"edge\", notes);\n if (!hasWeights(snapshot)) {\n const clash = edgeColumns.find((c) => c.key === plan.weightKey);\n if (clash !== undefined) {\n notes.push(\n note(\n LOSS.WEIGHT_KEY_CLASH,\n `edge column \"${clash.column.meta.name}\" is written under \"${plan.weightKey}\", the key the importer reads edge weights from; it reads back as the weight, not as a column`,\n clash.column.meta.name,\n clash.column.length - clash.column.nullCount,\n ),\n );\n }\n }\n const folding = pairFolding(snapshot);\n if (folding.mutualCount > 0) {\n notes.push(\n note(\n LOSS.MUTUAL_EXPANDED,\n `${folding.mutualCount} mutual pair${plural(folding.mutualCount)} ${agree(folding.mutualCount, \"is\", \"are\")} written as two directed edges; the mutual mark is lost`,\n null,\n folding.mutualCount,\n ),\n );\n }\n return Object.freeze(notes);\n}\n\n/**\n * The structural keys of the edge table: source, target, the weight key when weights are written,\n * and `id` when a role-id column is written as the edge id.\n * @param snapshot - the snapshot\n * @param plan - the export plan\n * @param edgeIds - the role-id edge column, or null\n * @returns the reserved keys\n */\nfunction edgeReservedKeys(snapshot: GraphSnapshot, plan: GmlExportPlan, edgeIds: Column | null): Set<string> {\n const reserved = new Set(EDGE_RESERVED);\n if (hasWeights(snapshot)) {\n reserved.add(plan.weightKey);\n }\n if (edgeIds !== null) {\n reserved.add(\"id\");\n }\n return reserved;\n}\n\n/**\n * The structural keys of the top level: graph, plus Creator and Version when the metadata writes them.\n * @param snapshot - the snapshot\n * @returns the reserved keys\n */\nfunction topReservedKeys(snapshot: GraphSnapshot): Set<string> {\n const reserved = new Set(TOP_RESERVED);\n if (snapshot.meta.creator !== null) {\n reserved.add(\"Creator\");\n }\n if (snapshot.meta.sourceFormat === \"gml\" && snapshot.meta.sourceVersion !== null) {\n reserved.add(\"Version\");\n }\n return reserved;\n}\n\n/**\n * How many node ids are not safe integers (what sanitizeIds \"mangle\" rewrites).\n * @param snapshot - the snapshot\n * @returns the count\n */\nfunction countMangled(snapshot: GraphSnapshot): number {\n let count = 0;\n for (let i = 0; i < snapshot.nodeCount; i++) {\n const id = snapshot.ids.idOf(i);\n if (typeof id !== \"number\" || !Number.isSafeInteger(id)) {\n count++;\n }\n }\n return count;\n}\n\n// ============================================================ writing\n\n/**\n * The GML text of a number by the dtype and origin of its column: an integer text for the integer\n * dtypes and for an f64 column that came from GML `int` values, a real text otherwise.\n * @param value - the value\n * @param meta - the column metadata\n * @returns the text\n */\nfunction numberText(value: number, meta: ColumnMeta): string {\n switch (meta.dtype) {\n case \"i32\":\n case \"u32\":\n case \"u8\":\n return formatInteger(value);\n case \"f32\":\n return formatGmlReal(value, \"f32\");\n default:\n if (meta.origin?.type === \"int\" && Number.isInteger(value)) {\n return formatInteger(value);\n }\n return formatGmlReal(value, \"f64\");\n }\n}\n\n/**\n * The GML text of a JSON scalar inside a record: integers as int, other numbers as real, strings\n * quoted, booleans as 1 / 0.\n * @param value - the scalar\n * @returns the text\n */\nfunction jsonScalarText(value: number | string | boolean): string {\n switch (typeof value) {\n case \"number\":\n return Number.isInteger(value) ? formatInteger(value) : formatGmlReal(value, \"f64\");\n case \"boolean\":\n return value ? \"1\" : \"0\";\n default:\n return quoteGmlString(value);\n }\n}\n\n/**\n * The GML text of a list item or components lane by the item dtype.\n * @param item - the item\n * @param itemDtype - the list's item dtype\n * @param meta - the list column metadata\n * @returns the text\n */\nfunction itemText(item: unknown, itemDtype: string, meta: ColumnMeta): string {\n switch (typeof item) {\n case \"number\":\n switch (itemDtype) {\n case \"i32\":\n case \"u32\":\n case \"u8\":\n return formatInteger(item);\n case \"f32\":\n return formatGmlReal(item, \"f32\");\n case \"json\":\n return jsonScalarText(item);\n default:\n return meta.origin?.type === \"int\" && Number.isInteger(item)\n ? formatInteger(item)\n : formatGmlReal(item, \"f64\");\n }\n case \"boolean\":\n return item ? \"1\" : \"0\";\n case \"string\":\n return quoteGmlString(item);\n default:\n throw new GraphFormatError(\n \"E_COLUMN_TYPE\",\n `column \"${meta.name}\": a ${typeof item} list item cannot be written as GML`,\n {\n column: meta.name,\n found: typeof item,\n },\n );\n }\n}\n\n/** Writes lines with indentation into an array of parts. */\nclass GmlWriter {\n private readonly lines: string[] = [];\n\n private readonly mangle: boolean;\n\n /**\n * Create a writer.\n * @param mangle - whether record keys are rewritten rather than refused\n */\n constructor(mangle: boolean) {\n this.mangle = mangle;\n }\n\n /**\n * Take the lines written so far as one string.\n * @returns the text; the writer is empty afterwards\n */\n take(): string {\n const text = this.lines.join(\"\");\n this.lines.length = 0;\n return text;\n }\n\n /**\n * Write one `key value` line.\n * @param indent - the indentation\n * @param key - the key\n * @param value - the value text\n */\n line(indent: string, key: string, value: string): void {\n this.lines.push(`${indent}${key} ${value}\\n`);\n }\n\n /**\n * Write a raw line.\n * @param text - the line without its terminator\n */\n raw(text: string): void {\n this.lines.push(`${text}\\n`);\n }\n\n /**\n * Write one column cell of a row.\n * @param indent - the indentation\n * @param key - the key\n * @param column - the column\n * @param row - the row\n */\n cell(indent: string, key: string, column: Column, row: number): void {\n const { meta, dtype } = column;\n switch (dtype) {\n case \"f32\":\n case \"f64\":\n case \"i32\":\n case \"u32\":\n case \"u8\": {\n const { components } = meta;\n if (components === 1) {\n this.line(indent, key, numberText(column.data[row], meta));\n } else {\n for (let k = 0; k < components; k++) {\n this.line(indent, key, numberText(column.data[row * components + k], meta));\n }\n }\n return;\n }\n case \"bool\":\n this.line(indent, key, column.value(row) === true ? \"1\" : \"0\");\n return;\n case \"dict\":\n case \"string\":\n this.line(indent, key, quoteGmlString(column.value(row) ?? \"\"));\n return;\n case \"list\":\n this.list(indent, key, column.sliceOf(row), meta.itemDtype ?? \"string\", meta);\n return;\n case \"json\":\n this.json(indent, key, column.values[row], meta.name);\n return;\n default: {\n const name: string = dtype;\n throw new GraphFormatError(\"E_COLUMN_TYPE\", `unknown dtype ${name}`, { dtype: name });\n }\n }\n }\n\n /**\n * Write a list as repeated keys with the NetworkX conventions.\n * @param indent - the indentation\n * @param key - the key\n * @param items - the items\n * @param itemDtype - the item dtype\n * @param meta - the column metadata\n */\n private list(indent: string, key: string, items: readonly unknown[], itemDtype: string, meta: ColumnMeta): void {\n if (items.length === 0) {\n this.line(indent, key, quoteGmlString(EMPTY_LIST_TEXT));\n return;\n }\n if (items.length === 1) {\n this.line(indent, key, quoteGmlString(LIST_START_MARKER));\n }\n for (const item of items) {\n if (itemDtype === \"json\" && typeof item === \"object\") {\n this.json(indent, key, item, meta.name, true);\n } else {\n this.line(indent, key, itemText(item, itemDtype, meta));\n }\n }\n }\n\n /**\n * Write a JSON value: a record for an object, repeated keys for an array, a scalar otherwise;\n * null writes nothing.\n * @param indent - the indentation\n * @param key - the key\n * @param value - the value\n * @param column - the column name, for errors\n * @param inArray - whether the value is an array item (an array here has no GML spelling)\n */\n private json(indent: string, key: string, value: unknown, column: string, inArray = false): void {\n if (value === null || value === undefined) {\n return;\n }\n if (Array.isArray(value)) {\n if (inArray) {\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n `column \"${column}\": an array nested in an array cannot be written as GML`,\n {\n reason: \"nested array\",\n column,\n },\n );\n }\n if (value.length === 0) {\n this.line(indent, key, quoteGmlString(EMPTY_LIST_TEXT));\n return;\n }\n if (value.length === 1) {\n this.line(indent, key, quoteGmlString(LIST_START_MARKER));\n }\n for (const item of value) {\n this.json(indent, key, item, column, true);\n }\n return;\n }\n if (typeof value === \"object\") {\n this.record(indent, key, value as Record<string, unknown>, column);\n return;\n }\n if (typeof value === \"number\" || typeof value === \"string\" || typeof value === \"boolean\") {\n this.line(indent, key, jsonScalarText(value));\n return;\n }\n throw new GraphFormatError(\"E_COLUMN_TYPE\", `column \"${column}\": a ${typeof value} cannot be written as GML`, {\n column,\n found: typeof value,\n });\n }\n\n /**\n * Write a record `key [ ... ]`.\n * @param indent - the indentation\n * @param key - the key\n * @param record - the object\n * @param column - the column name, for errors\n * @param extra - lines to write first (the position of a graphics record), or null\n */\n record(\n indent: string,\n key: string,\n record: Record<string, unknown>,\n column: string,\n extra: readonly [string, string][] | null = null,\n ): void {\n this.raw(`${indent}${key} [`);\n const inner = `${indent} `;\n const used = new Set<string>();\n if (extra !== null) {\n for (const [k, v] of extra) {\n this.line(inner, k, v);\n used.add(k);\n }\n }\n for (const name of Object.keys(record)) {\n if (used.has(name) && extra !== null && (name === \"x\" || name === \"y\" || name === \"z\")) {\n continue;\n }\n const written = this.recordKey(name, used, column);\n used.add(written);\n this.json(inner, written, record[name], column);\n }\n this.raw(`${indent}]`);\n }\n\n /**\n * The key a record field is written under.\n * @param name - the field name\n * @param used - the keys already written in the record\n * @param column - the column name, for errors\n * @returns a valid, unused key; E_UNSUPPORTED for an invalid key unless mangling\n */\n private recordKey(name: string, used: ReadonlySet<string>, column: string): string {\n if (isGmlKey(name) && !used.has(name)) {\n return name;\n }\n if (!this.mangle) {\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n `column \"${column}\": record key \"${name}\" ${isGmlKey(name) ? \"repeats a key\" : \"is not a GML key\"}; pass sanitizeKeys: \"mangle\" to rewrite it`,\n {\n reason: \"gml key\",\n column,\n key: name,\n },\n );\n }\n return uniqueKey(isGmlKey(name) ? name : mangleGmlKey(name), used);\n }\n}\n\n/** Everything the writer needs, resolved once before the first line. */\ninterface WriteContext {\n readonly snapshot: GraphSnapshot;\n readonly plan: GmlExportPlan;\n readonly ids: SanitizedIds;\n readonly writeDirected: boolean;\n readonly foldPairs: boolean;\n readonly nodeColumns: readonly WrittenColumn[];\n readonly edgeColumns: readonly WrittenColumn[];\n readonly graphColumns: readonly WrittenColumn[];\n readonly topColumns: readonly WrittenColumn[];\n readonly position: Column | null;\n readonly graphics: JsonColumn | null;\n readonly originalIds: Column | null;\n readonly edgeIds: Column | null;\n readonly weights: ExplicitWeights;\n readonly folding: PairFolding;\n}\n\n/**\n * Resolve everything export() needs, throwing for what check() reported as an error.\n * @param snapshot - the snapshot\n * @param options - the options\n * @returns the context\n */\nfunction contextOf(\n snapshot: GraphSnapshot,\n options: (GmlExportOptions & CommonExportOptions) | undefined,\n): WriteContext {\n const plan = planOf(snapshot, options);\n const ids = sanitizeIds(snapshot, \"integer\", plan.common.sanitizeIds);\n const mixed = countMixedEdges(snapshot);\n if (mixed > 0 && plan.common.onMixedDirection === \"error\") {\n throw new GraphFormatError(\n \"E_DIRECTED\",\n `${mixed} undirected edge${plural(mixed)} in a directed graph, and GML holds one direction per file, so the save fails unless onMixedDirection is \"directed\" or \"undirected\"`,\n {\n reason: \"mixed direction\",\n count: mixed,\n },\n );\n }\n // design 8.5: exporters fold expanded pairs back; under \"directed\" the folded edge is written\n // once, as one directed edge, under \"undirected\" the whole graph is written undirected\n const foldPairs = mixed > 0;\n const writeDirected = snapshot.directed && plan.common.onMixedDirection !== \"undirected\";\n const originalIds = snapshot.nodes.byRole(\"originalId\");\n const nodeReserved = new Set(NODE_RESERVED);\n if (ids.changed > 0 || originalIds !== null) {\n nodeReserved.add(ORIGINAL_ID_KEY);\n }\n const edgeIds = snapshot.edges.byRole(\"id\");\n const edgeReserved = edgeReservedKeys(snapshot, plan, edgeIds);\n const topReserved = topReservedKeys(snapshot);\n return {\n snapshot,\n plan,\n ids,\n writeDirected,\n foldPairs,\n nodeColumns: selectColumns(\n snapshot.nodes,\n nodeReserved,\n \"node\",\n plan,\n null,\n (c) => !(c.meta.name === \"graphics\" && c.dtype === \"json\"),\n ),\n edgeColumns: selectColumns(snapshot.edges, edgeReserved, \"edge\", plan, null, (c) => c !== edgeIds),\n graphColumns: selectColumns(snapshot.graph, GRAPH_RESERVED, \"graph\", plan, null, (c) => !isTopLevel(c)),\n topColumns: selectColumns(snapshot.graph, topReserved, \"top-level\", plan, null, isTopLevel),\n position: positionColumn(snapshot),\n graphics: graphicsColumn(snapshot),\n originalIds,\n edgeIds,\n weights: explicitWeights(snapshot),\n folding: pairFolding(snapshot),\n };\n}\n\n/**\n * The GML text of an id written into `graphty_originalId`: quoted for a string, a number text\n * otherwise (an integer as int, else real, so the importer restores the same typed value).\n * @param id - the original id\n * @returns the text\n */\nfunction originalIdText(id: NodeId): string {\n if (typeof id === \"string\") {\n return quoteGmlString(id);\n }\n return Number.isSafeInteger(id) ? formatInteger(id) : formatGmlReal(id, \"f64\");\n}\n\n/**\n * The parts of the document.\n * @param context - the resolved context\n * @yields one string per header line, node or edge\n * @returns nothing\n */\nfunction* gmlParts(context: WriteContext): Generator<string, void, undefined> {\n const { snapshot, plan, ids } = context;\n const w = new GmlWriter(plan.mangle);\n const { meta } = snapshot;\n if (meta.creator !== null) {\n w.line(\"\", \"Creator\", quoteGmlString(meta.creator));\n }\n if (meta.sourceFormat === \"gml\" && meta.sourceVersion !== null) {\n w.line(\"\", \"Version\", versionText(meta.sourceVersion));\n }\n for (const { column, key } of context.topColumns) {\n if (column.isSet(0)) {\n w.cell(\"\", key, column, 0);\n }\n }\n w.raw(\"graph [\");\n w.line(\" \", \"directed\", context.writeDirected ? \"1\" : \"0\");\n const multigraph = meta.declaredMultigraph ?? (snapshot.flags.multigraph ? true : null);\n if (multigraph !== null) {\n w.line(\" \", \"multigraph\", multigraph ? \"1\" : \"0\");\n }\n for (const { column, key } of context.graphColumns) {\n if (column.isSet(0)) {\n w.cell(\" \", key, column, 0);\n }\n }\n yield w.take();\n for (let i = 0; i < snapshot.nodeCount; i++) {\n w.raw(\" node [\");\n w.line(\" \", \"id\", formatInteger(ids.idAt(i) as number));\n if (ids.isChanged(i)) {\n w.line(\" \", ORIGINAL_ID_KEY, originalIdText(ids.originalAt(i)));\n } else if (context.originalIds?.isSet(i)) {\n const original = context.originalIds.value(i);\n if (typeof original === \"string\" || typeof original === \"number\") {\n w.line(\" \", ORIGINAL_ID_KEY, originalIdText(original));\n }\n }\n for (const { column, key } of context.nodeColumns) {\n if (column.isSet(i)) {\n w.cell(\" \", key, column, i);\n }\n }\n writeGraphics(w, context, i);\n w.raw(\" ]\");\n yield w.take();\n }\n const el = snapshot.edgeList();\n const origin = meta.weightOrigin;\n const integerWeights = origin !== null && origin.type === \"int\";\n for (let e = 0; e < snapshot.edgeCount; e++) {\n if (context.foldPairs && context.folding.folded(e)) {\n continue;\n }\n w.raw(\" edge [\");\n w.line(\" \", \"source\", formatInteger(ids.idAt(el.src[e]) as number));\n w.line(\" \", \"target\", formatInteger(ids.idAt(el.dst[e]) as number));\n if (context.edgeIds?.isSet(e)) {\n w.cell(\" \", \"id\", context.edgeIds, e);\n }\n if (context.weights.isExplicit(e)) {\n const weight = context.weights.value(e);\n const text =\n integerWeights && Number.isInteger(weight)\n ? formatInteger(weight)\n : formatGmlReal(weight, context.weights.dtype);\n w.line(\" \", plan.weightKey, text);\n }\n for (const { column, key } of context.edgeColumns) {\n if (column.isSet(e)) {\n w.cell(\" \", key, column, e);\n }\n }\n w.raw(\" ]\");\n yield w.take();\n }\n w.raw(\"]\");\n yield w.take();\n}\n\n/**\n * Write a node's `graphics [ ... ]` record from the position column and the graphics json column.\n * @param w - the writer\n * @param context - the context\n * @param i - the node\n */\nfunction writeGraphics(w: GmlWriter, context: WriteContext, i: number): void {\n const { position, graphics } = context;\n const hasPosition = position?.isSet(i) === true;\n const graphicsValue = graphics?.isSet(i) ? graphics.values[i] : undefined;\n if (!hasPosition) {\n if (graphics !== null && graphicsValue !== undefined) {\n w.cell(\" \", \"graphics\", graphics, i);\n }\n return;\n }\n const numeric = position as Column & { readonly data: ArrayLike<number> };\n const { components } = numeric.meta;\n const lanes = Math.min(components, 3);\n const extra: [string, string][] = [];\n const names = [\"x\", \"y\", \"z\"];\n for (let k = 0; k < lanes; k++) {\n extra.push([names[k], numberText(numeric.data[i * components + k], numeric.meta)]);\n }\n let record: Record<string, unknown> = {};\n if (graphicsValue !== undefined) {\n if (typeof graphicsValue !== \"object\" || graphicsValue === null || Array.isArray(graphicsValue)) {\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n `node ${i}: the graphics value is not a record and cannot hold the position`,\n {\n reason: \"graphics conflict\",\n node: i,\n },\n );\n }\n record = graphicsValue as Record<string, unknown>;\n }\n w.record(\" \", \"graphics\", record, \"graphics\", extra);\n}\n\n/**\n * The GML exporter plugin.\n * @category Built-in formats\n */\nexport const gmlExporter: GraphExporter<GmlExportOptions> = Object.freeze({\n format: \"gml\",\n options: Object.freeze([\"sanitizeKeys\", \"weightKey\"]),\n capabilities: GML_CAPABILITIES,\n styles: Object.freeze({ capabilities: GML_STYLE_CAPABILITIES }),\n /**\n * Pre-flight: the common capability notes, the GML-specific ones and, with styles, the values written as the\n * nearest ones yEd's GML has.\n * @param snapshot - the snapshot\n * @param options - the options\n * @returns the notes, empty when the export is exact\n */\n check(snapshot: GraphSnapshot, options?: GmlWriteOptions): readonly LossNote[] {\n const styled = gmlStyledExport(snapshot, options?.styles);\n if (styled === null) {\n return check(snapshot, options);\n }\n return Object.freeze([...check(styled.snapshot, options), ...styled.notes]);\n },\n /**\n * Write the snapshot as UTF-8 chunks; the context is resolved on the first pull, so the\n * errors check() announced surface from the iteration.\n * @param snapshot - the snapshot\n * @param options - the options\n * @returns the chunks\n */\n export(snapshot: GraphSnapshot, options?: GmlWriteOptions): AsyncIterable<Uint8Array> {\n return encodeChunks(lazyParts(snapshot, options));\n },\n /**\n * Write the snapshot as one string.\n * @param snapshot - the snapshot\n * @param options - the options\n * @returns the document\n */\n exportToString(snapshot: GraphSnapshot, options?: GmlWriteOptions): Promise<string> {\n return joinText(lazyParts(snapshot, options));\n },\n});\n\n/**\n * The document parts, with the context resolved when iteration starts.\n * @param snapshot - the snapshot\n * @param options - the options\n * @yields the parts\n * @returns nothing\n */\nfunction* lazyParts(snapshot: GraphSnapshot, options: GmlWriteOptions | undefined): Generator<string, void, undefined> {\n yield* gmlParts(contextOf(gmlStyledExport(snapshot, options?.styles)?.snapshot ?? snapshot, options));\n}\n","/**\n * How a GML file's `graphics [ x y z ]` positions are spelled, for `extractPositions()`: the node's\n * center in pixels, y growing downward (the GML specification, yFiles and Cytoscape) unless the\n * `Creator` names a y-up tool (Gephi, Tulip).\n */\n\nimport type { GraphSnapshot } from \"@graphty/graph-format\";\n\nimport { toolOf } from \"../../common/units.js\";\nimport { median } from \"../../positions/convert.js\";\nimport type { ImporterPositions } from \"../../positions/types.js\";\n\n/** The json column the importer keeps the rest of each node's graphics record in. */\nconst GRAPHICS_COLUMN = \"graphics\";\n\n/**\n * The spelling of a GML file's positions.\n * @param snapshot - the graph the GML importer read\n * @returns the spelling, or null when no node has a position\n */\nexport function gmlPositions(snapshot: GraphSnapshot): ImporterPositions | null {\n if (snapshot.nodes.byRole(\"position\") === null) {\n return null;\n }\n const tool = toolOf(snapshot.meta.creator);\n return {\n units: \"px\",\n // a z that is the same on every node collapses to 2D\n sourceDims: 3,\n yAxis: tool === \"gephi\" || tool === \"tulip\" ? \"up\" : \"down\",\n tool,\n medianNodeSize: graphicsMedian(snapshot),\n };\n}\n\n/**\n * The median node diameter from the graphics records' `w` and `h`.\n * @param snapshot - the graph\n * @returns the median of each node's mean of w and h, or null when no node has both\n */\nfunction graphicsMedian(snapshot: GraphSnapshot): number | null {\n const graphics = snapshot.nodes.get(GRAPHICS_COLUMN);\n const sizes: number[] = [];\n for (let row = 0; graphics !== null && row < graphics.length; row++) {\n const g = graphics.isSet(row) ? graphics.value(row) : undefined;\n const { w, h } = typeof g === \"object\" && g !== null ? (g as Record<string, unknown>) : {};\n if (typeof w === \"number\" && typeof h === \"number\") {\n sizes.push((w + h) / 2);\n }\n }\n return median(sizes);\n}\n","/**\n * The GML importer (design sections 8.4 and 8.5, research note 07 section 2.2): reads a whole GML\n * text (GML awaits the whole text, 8.4), lexes it once into a typed token list, derives the column\n * schema of every node, edge and graph key in a first walk (GML types are lexical per value, so\n * the column dtype is the union of the value classes seen: `int` -> i32, `real` -> f64, `string`\n * -> string, a nested `[ ]` record -> json, a repeated key -> list; the class is recorded in\n * `origin.type` per column as 8.5 requires), then pushes scalars into the sink in a second walk:\n * every node block first, then every edge block, so node indices follow the file's node order\n * and forward edge references resolve.\n *\n * Conventions honored: NetworkX's `_networkx_list_start` marker and `\"[]\"` empty lists, `&#NN;`\n * character references in strings, `Creator` / `Version` top-level metadata, `directed 0|1` and\n * `multigraph 0|1` graph flags, comments, keys and values on one line or split across lines, and\n * a `graphics [ x y z ]` node record mapped to the `position` role (note 07 section 9) with the\n * remaining graphics keys kept as a json column.\n *\n * Node ids are the `id` keys under `nodeIdFrom: \"id\"`, the `label` under `\"label\"`, and the node's\n * ordinal under `\"index\"`; `source` / `target` always resolve through the `id` keys. The GML spec\n * types ids as integers; a string id (written by NetworkX and Gephi) is accepted under the `ids`\n * rule with one warning per file, and a real or record id is a validation error. A node's\n * `graphty_originalId` key written by the exporter's `sanitizeIds: \"mangle\"` restores the\n * original id under `restoreMangledIds` (the default).\n */\n\nimport {\n type ColumnDecl,\n type ColumnHandle,\n type ColumnRole,\n type Dtype,\n GraphFormatError,\n type GraphSink,\n INVALID_INDEX,\n type NodeId,\n type ScalarDtype,\n} from \"@graphty/graph-format\";\n\nimport { declareResolved, DictHeuristic, uniqueColumnName } from \"../../common/attributes.js\";\nimport { importChosenGraph } from \"../../common/choose.js\";\nimport {\n COLUMN_RENAMED_CODE,\n DUPLICATE_NODE_CODE as SHARED_DUPLICATE_NODE_CODE,\n MISSING_ENDPOINT_CODE as SHARED_MISSING_ENDPOINT_CODE,\n MISSING_ID_CODE as SHARED_MISSING_ID_CODE,\n MULTIPLE_GRAPHS_CODE,\n NO_GRAPH_CODE as SHARED_NO_GRAPH_CODE,\n PRECISION_CODE as SHARED_PRECISION_CODE,\n ROLE_TAKEN_CODE as SHARED_ROLE_TAKEN_CODE,\n WIDENED_CODE as SHARED_WIDENED_CODE,\n} from \"../../common/codes.js\";\nimport { DirectionResolver } from \"../../common/direction.js\";\nimport { IdCoercer } from \"../../common/ids.js\";\nimport { readText, throwIfAborted } from \"../../common/input.js\";\nimport {\n graphChosen,\n type ImportFormatDefaults,\n reportSinkOptions,\n reportUnusedOptions,\n type ResolvedImportOptions,\n resolveImportOptions,\n} from \"../../common/options.js\";\nimport { plural } from \"../../common/plural.js\";\nimport { ImportReportBuilder } from \"../../common/report.js\";\nimport { parseWeightText, reportWeightPrecision, weightFromValue } from \"../../common/weights.js\";\nimport {\n type CommonImportOptions,\n type GraphChoiceOptions,\n type GraphImporter,\n type ImportInput,\n type ImportReport,\n} from \"../../types.js\";\nimport { gmlPositions } from \"./positions.js\";\nimport { gmlStyles } from \"./styles.js\";\nimport {\n EMPTY_LIST_TEXT,\n EMPTY_TUPLE_TEXT,\n GmlSyntaxError,\n type GmlTokens,\n LIST_START_MARKER,\n numberOfText,\n ORIGINAL_ID_KEY,\n parseRecord,\n scalarOrRecord,\n TOKEN_INT,\n TOKEN_OPEN,\n TOKEN_REAL,\n TOKEN_STRING,\n TOKEN_WORD,\n tokenizeGml,\n} from \"./syntax.js\";\n\n/**\n * The format-specific options of the GML importer.\n * @category Built-in formats\n */\nexport interface GmlImportOptions extends GraphChoiceOptions, CommonImportOptions {\n /**\n * Read a node's `graphics [ x y z ]` record as its position; false keeps the whole record as a\n * JSON attribute named `graphics`.\n * @defaultValue true\n */\n positions?: boolean | undefined;\n /**\n * With `positions`, also keep the whole `graphics` record, x / y / z included, as the JSON\n * attribute named `graphics`, so a reader gets both the position and the record as written.\n * @defaultValue false\n */\n keepPositionSource?: boolean | undefined;\n /**\n * Store a text attribute whose values repeat a lot (fewer distinct values than half the rows)\n * as a dictionary column, which uses less memory and reads the same. Such a column reports\n * `meta.dtype` \"dict\" instead of \"string\". A column with a role, such as the `label` column,\n * always stays \"string\".\n * @defaultValue true\n */\n dictionaries?: boolean | undefined;\n}\n\n/**\n * The text holds no `graph [ ... ]` block.\n * @category Issue and loss codes\n */\nexport const NO_GRAPH_CODE = SHARED_NO_GRAPH_CODE;\n/**\n * The text holds more than one `graph [ ... ]` block; import() reads the first, importAll() every one.\n * @category Issue and loss codes\n */\nexport const SECOND_GRAPH_CODE = MULTIPLE_GRAPHS_CODE;\n/**\n * A node block has no `id` key.\n * @category Issue and loss codes\n */\nexport const MISSING_ID_CODE = SHARED_MISSING_ID_CODE;\n/**\n * A node block has no `label` key under `nodeIdFrom: \"label\"`.\n * @category Issue and loss codes\n */\nexport const MISSING_LABEL_CODE = \"E_GML_MISSING_LABEL\";\n/**\n * An edge block has no `source` or no `target` key.\n * @category Issue and loss codes\n */\nexport const MISSING_ENDPOINT_CODE = SHARED_MISSING_ENDPOINT_CODE;\n/**\n * An `id`, `source` or `target` value is neither an integer nor a string.\n * @category Issue and loss codes\n */\nexport const ID_TYPE_CODE = \"E_GML_ID_TYPE\";\n/**\n * Node ids, sources or targets are text, where GML expects integers. They are read under the `ids` option. Reported\n * once per file.\n * @category Issue and loss codes\n */\nexport const STRING_ID_CODE = \"W_GML_STRING_ID\";\n/**\n * A node id (or label under `nodeIdFrom: \"label\"`) is declared twice; later keys overwrite.\n * @category Issue and loss codes\n */\nexport const DUPLICATE_NODE_CODE = SHARED_DUPLICATE_NODE_CODE;\n/**\n * A structural key (`id`, `source`, `target`) appears twice in one block.\n * @category Issue and loss codes\n */\nexport const REPEATED_KEY_CODE = \"E_GML_REPEATED_KEY\";\n/**\n * A `node` or `edge` key whose value is not a `[ ... ]` block.\n * @category Issue and loss codes\n */\nexport const ELEMENT_TYPE_CODE = \"E_GML_ELEMENT_TYPE\";\n/**\n * A `directed` or `multigraph` flag that is not an integer.\n * @category Issue and loss codes\n */\nexport const FLAG_TYPE_CODE = \"E_GML_FLAG_TYPE\";\n/**\n * A `directed` / `multigraph` flag that is not 0 or 1 (read as its truth value), one written as a quoted integer, or\n * one repeated.\n * @category Issue and loss codes\n */\nexport const FLAG_VALUE_CODE = \"W_GML_FLAG_VALUE\";\n\n/** A flag written as a quoted integer, surrounding spaces allowed. */\nconst QUOTED_INT = /^\\s*[+-]?\\d+\\s*$/;\n/**\n * A named entity in a string that is neither an XML nor an ISO-8859-1 HTML entity, or a numeric reference beyond\n * U+10FFFF; it is kept as written.\n * @category Issue and loss codes\n */\nexport const UNKNOWN_ENTITY_CODE = \"W_GML_UNKNOWN_ENTITY\";\n/**\n * A node's `graphics` value cannot give a position as written (not a record, repeated in the node, or with an x / y /\n * z that is not one number); the value is kept in the graphics json column. Warned once per kind of problem, naming\n * the first node.\n * @category Issue and loss codes\n */\nexport const GRAPHICS_CODE = \"W_GML_GRAPHICS\";\n/**\n * A `graph`, `node` or `edge` record inside a node or edge; kept as a json column, not read as structure.\n * @category Issue and loss codes\n */\nexport const NESTED_ELEMENT_CODE = \"W_GML_NESTED_ELEMENT\";\n/**\n * YEd's group keys (`isGroup`, `gid`); kept as plain node columns, the hierarchy is not read as containment.\n * @category Issue and loss codes\n */\nexport const GROUPS_CODE = \"W_GML_GROUPS\";\n/**\n * A key whose values mix numbers and strings; the column is string, the numbers kept as written.\n * @category Issue and loss codes\n */\nexport const WIDENED_CODE = SHARED_WIDENED_CODE;\n/**\n * An integer above 2^53 was stored as the nearest JavaScript number, so its last digits may differ. Pass `long:\n * \"string\"` to keep every digit as text.\n * @category Issue and loss codes\n */\nexport const PRECISION_CODE = SHARED_PRECISION_CODE;\n/**\n * Two attributes would have had the same name, so this one was renamed `<name>#<key>`.\n * @category Plugin helpers\n */\nexport const COLUMN_RENAMED_CODE_GML = COLUMN_RENAMED_CODE;\n/**\n * You read into a graph builder that already has an attribute with this role, so this file's attribute is kept without\n * the role.\n * @category Issue and loss codes\n */\nexport const ROLE_TAKEN_CODE = SHARED_ROLE_TAKEN_CODE;\n/**\n * Under `nodeIdFrom` \"label\" / \"index\" the integer `id` keys are not kept.\n * @category Issue and loss codes\n */\nexport const ID_DROPPED_CODE = \"W_GML_ID_DROPPED\";\n\nconst FORMAT_DEFAULTS: ImportFormatDefaults = { ids: \"canonical\", defaultDirected: false, weightFrom: \"value\" };\n\nconst KIND_INT = 1;\nconst KIND_REAL = 2;\nconst KIND_STRING = 4;\nconst KIND_RECORD = 8;\n\nconst I32_MIN = -2147483648;\nconst I32_MAX = 2147483647;\n\n/** How many elements are pushed between abort-signal checks. */\nconst ABORT_CHECK_INTERVAL = 64;\n\n/** The common options the GML importer reads (the rest is reported by reportUnusedOptions). */\nconst USED_OPTIONS: ReadonlySet<keyof CommonImportOptions> = new Set<keyof CommonImportOptions>([\n \"ids\",\n \"nodeIdFrom\",\n \"addMissingNodes\",\n \"duplicateEdges\",\n \"selfLoops\",\n \"onMixedDirection\",\n \"defaultDirected\",\n \"weightFrom\",\n \"weightDtype\",\n \"restoreMangledIds\",\n \"long\",\n \"errorLimit\",\n \"signal\",\n \"onProgress\",\n]);\n\n/** The element sequence number of the graph block's own keys. */\nconst GRAPH_SEQ = -1;\n/** The element sequence number of the top-level keys. */\nconst TOP_SEQ = -2;\n\n/** The GML value class a column stores. */\ntype GmlKind = \"int\" | \"real\" | \"string\" | \"record\";\n\n/** What the first walk learns about one key of one table. */\ninterface KeySchema {\n /** The key as written. */\n readonly key: string;\n /** The union of value classes seen (KIND_* bits). */\n kinds: number;\n /** Whether the key repeats within one element, or uses a list marker. */\n list: boolean;\n /** The element sequence the key was last seen in. */\n lastSeq: number;\n /** Whether an integer outside the i32 range was seen. */\n wide: boolean;\n /** Whether an integer beyond 2^53 was seen. */\n unsafe: boolean;\n /** The dictionary heuristic while every value is a string, else null. */\n dict: DictHeuristic | null;\n /** Node `graphics` only: some row has numeric x and y. */\n position: boolean;\n /** Node `graphics` only: some row keeps keys besides the position. */\n rest: boolean;\n}\n\n/** The column a key maps to in the second walk. */\ninterface ColumnPlan {\n /** The key as written. */\n readonly key: string;\n /** The column name (renamed `<name>#<key>` when the sink held the name with another shape). */\n name: string;\n /** The column dtype. */\n readonly dtype: Dtype;\n /** The list item dtype, or null. */\n readonly itemDtype: ScalarDtype | null;\n /** How scalar values (or list items) are converted. */\n readonly kind: GmlKind;\n /** Whether the column is a list. */\n readonly list: boolean;\n /** The role, or null. */\n readonly role: ColumnRole | null;\n /** Whether the values come from the top level of the file (graph table only). */\n readonly top: boolean;\n /** Node `graphics` with the position mapping: the position column plan, or null. */\n readonly position: ColumnPlan | null;\n /** Node `graphics` with the position mapping: the json column of the remaining keys, or null. */\n readonly rest: ColumnPlan | null;\n /** The handle once declared. */\n handle: ColumnHandle;\n /** Whether the declaration was attempted (a failed one reuses the sink's column or is null). */\n declared: boolean;\n /** The list items of the current element. */\n items: unknown[] | null;\n /** The element sequence the items belong to. */\n seq: number;\n}\n\n/** A table's plans by key. */\ntype PlanMap = Map<string, ColumnPlan>;\n\n/** Where a node issue is recorded. */\ninterface IssueWhere {\n readonly line: number;\n readonly element: string;\n}\n\n/** The table a GML key belongs to. */\ntype GmlDomain = \"node\" | \"edge\" | \"graph\";\n\n/**\n * Whether a key is the label of a node or edge (text, never a NetworkX list marker).\n * @param domain - the table\n * @param key - the key\n * @returns true for a node or edge label\n */\nfunction isLabel(domain: GmlDomain, key: string): boolean {\n return roleOf(domain, key) === \"label\";\n}\n\n/**\n * Whether a parsed value is a GML record.\n * @param value - the value\n * @returns true for a record object\n */\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * Whether a key gets a role in its table (design section 5.6 applied to GML keys).\n * @param domain - the table\n * @param key - the key\n * @returns the role, or null\n */\nfunction roleOf(domain: GmlDomain, key: string): ColumnRole | null {\n if (key === \"label\" && domain !== \"graph\") {\n return \"label\";\n }\n if (domain === \"edge\") {\n if (key === \"id\") {\n return \"id\";\n }\n if (key === \"key\") {\n return \"key\";\n }\n }\n return null;\n}\n\n/** One import call. */\nclass GmlImport {\n private readonly sink: GraphSink;\n\n private readonly report: ImportReportBuilder;\n\n private readonly options: ResolvedImportOptions;\n\n private readonly positions: boolean;\n\n private readonly keepPositionSource: boolean;\n\n private readonly dictionaries: boolean;\n\n private readonly coercer: IdCoercer;\n\n private tokens: GmlTokens | null = null;\n\n /** How many `graph [ ... ]` blocks the text holds (known after the scan). */\n graphCount = 0;\n\n private resolver: DirectionResolver | null = null;\n\n private readonly nodeSchema = new Map<string, KeySchema>();\n\n private readonly edgeSchema = new Map<string, KeySchema>();\n\n private readonly graphSchema = new Map<string, KeySchema>();\n\n private readonly topSchema = new Map<string, KeySchema>();\n\n private readonly nodePlans: PlanMap = new Map();\n\n private readonly edgePlans: PlanMap = new Map();\n\n private readonly graphPlans: PlanMap = new Map();\n\n private readonly topPlans: PlanMap = new Map();\n\n private readonly graphNames = new Set<string>();\n\n private graphOpen = -1;\n\n private directedToken = -1;\n\n private multigraphToken = -1;\n\n private creatorToken = -1;\n\n private versionToken = -1;\n\n private nodeCount = 0;\n\n private edgeCount = 0;\n\n private weightKinds = 0;\n\n private hasOriginalId = false;\n\n private headerDirected = false;\n\n private seq = 0;\n\n private nodeOrdinal = 0;\n\n private elementsSinceCheck = 0;\n\n /** The sink id every file id maps to when they differ (label / index / restored ids), else null. */\n private idMap: Map<NodeId, NodeId> | null = null;\n\n /** The file ids of node blocks that were skipped: an edge naming one is skipped too, never given a new node. */\n private readonly skippedIds = new Set<NodeId>();\n\n /** Node indices declared by a node block of this import, for duplicate detection. */\n private declared = new Uint32Array(64);\n\n /** The list plans touched by the current node or edge. */\n private readonly touched: ColumnPlan[] = [];\n\n /** The list plans touched by the graph table's keys. */\n private readonly graphTouched: ColumnPlan[] = [];\n\n /** The sequence number of the current node or edge, which its list items belong to. */\n private seqNow = 0;\n\n /**\n * Create one import.\n * @param sink - the sink\n * @param report - the report\n * @param options - the resolved common options\n * @param format - the format-specific options\n * @param which - which `graph [ ... ]` block to read (0: the first)\n */\n constructor(\n sink: GraphSink,\n report: ImportReportBuilder,\n options: ResolvedImportOptions,\n format: GmlImportOptions | undefined,\n private readonly which = 0,\n ) {\n this.sink = sink;\n this.report = report;\n this.options = options;\n this.positions = format?.positions ?? true;\n this.keepPositionSource = format?.keepPositionSource ?? false;\n this.dictionaries = format?.dictionaries ?? true;\n this.coercer = new IdCoercer(options.ids);\n }\n\n /**\n * Run the import over the tokens of a text.\n * @param tokens - the whole text, tokenized (tokenize())\n */\n run(tokens: GmlTokens): void {\n this.tokens = tokens;\n tokens.onUnknownEntity = (entity, line) => {\n this.report.warnOnce(\n \"parse-error\",\n UNKNOWN_ENTITY_CODE,\n `character entity ${entity} cannot be decoded; it is kept as written`,\n { line, element: entity },\n `${UNKNOWN_ENTITY_CODE}:${entity}`,\n );\n };\n this.scan();\n this.push();\n }\n\n // ============================================================ pass 1: the schema\n\n /**\n * Walk the top level: find the graph block, the metadata keys and the top-level attributes,\n * and derive every table's schema.\n */\n private scan(): void {\n const t = this.requireTokens();\n let scalarGraph = -1;\n for (let p = 0; p < t.count; p = t.nextPair(p)) {\n const key = t.textOf(p);\n const v = p + 1;\n const record = t.kind[v] === TOKEN_OPEN;\n if (key === \"graph\" && !record && scalarGraph < 0) {\n scalarGraph = v;\n }\n this.scanTopPair(key, record, v);\n }\n if (this.graphOpen < 0) {\n this.failNoGraph(t, scalarGraph);\n }\n }\n\n /**\n * Handle one top-level pair other than a scalar `graph`.\n * @param key - the key\n * @param record - whether the value is a `[ ... ]` block\n * @param v - the value token\n */\n private scanTopPair(key: string, record: boolean, v: number): void {\n if (key === \"graph\" && record) {\n if (this.graphCount++ === this.which) {\n this.graphOpen = v;\n this.scanGraph(v);\n }\n } else if (key === \"Creator\" && !record && this.creatorToken < 0) {\n this.creatorToken = v;\n } else if (key === \"Version\" && !record && this.versionToken < 0) {\n this.versionToken = v;\n } else {\n this.observe(this.topSchema, \"graph\", key, v, TOP_SEQ);\n }\n }\n\n /**\n * Fail because the input holds no graph block.\n * @param t - the tokens\n * @param scalarGraph - the token of a scalar `graph` key, or -1\n */\n private failNoGraph(t: ReturnType<GmlImport[\"requireTokens\"]>, scalarGraph: number): void {\n if (scalarGraph >= 0) {\n this.report.fail(\n NO_GRAPH_CODE,\n `the graph key at line ${t.line[scalarGraph]} holds ${describeValue(t, scalarGraph)}, not a [ ... ] block; the input contains no graph block`,\n { line: t.line[scalarGraph] },\n );\n }\n this.report.fail(NO_GRAPH_CODE, \"the input contains no graph [ ... ] block\", { line: null });\n }\n\n /**\n * Walk the graph block for the schema.\n * @param open - the index of the block's `[`\n */\n private scanGraph(open: number): void {\n const t = this.requireTokens();\n const close = t.match[open];\n for (let p = open + 1; p < close; p = t.nextPair(p)) {\n const key = t.textOf(p);\n const v = p + 1;\n switch (key) {\n case \"node\":\n if (t.kind[v] === TOKEN_OPEN) {\n this.nodeCount++;\n this.scanElement(\"node\", v);\n }\n break;\n case \"edge\":\n if (t.kind[v] === TOKEN_OPEN) {\n this.edgeCount++;\n this.scanElement(\"edge\", v);\n }\n break;\n case \"directed\":\n if (this.directedToken < 0) {\n this.directedToken = v;\n }\n break;\n case \"multigraph\":\n if (this.multigraphToken < 0) {\n this.multigraphToken = v;\n }\n break;\n default:\n this.observe(this.graphSchema, \"graph\", key, v, GRAPH_SEQ);\n }\n }\n }\n\n /**\n * Walk one node or edge block for the schema.\n * @param domain - node or edge\n * @param open - the block's `[`\n */\n private scanElement(domain: \"node\" | \"edge\", open: number): void {\n const t = this.requireTokens();\n const close = t.match[open];\n const seq = this.seq++;\n const schema = domain === \"node\" ? this.nodeSchema : this.edgeSchema;\n for (let p = open + 1; p < close; p = t.nextPair(p)) {\n const key = t.textOf(p);\n const v = p + 1;\n if (this.skipsKey(domain, key, v)) {\n continue;\n }\n this.observe(schema, domain, key, v, seq);\n }\n }\n\n /**\n * Whether a key of a node or edge block is structural (id, endpoints, weight, original id), not\n * a column; notes the original id and the weight's kinds on the way.\n * @param domain - node or edge\n * @param key - the key\n * @param v - the value token\n * @returns true when the key is not a column\n */\n private skipsKey(domain: \"node\" | \"edge\", key: string, v: number): boolean {\n const { weightFrom, restoreMangledIds } = this.options;\n if (domain === \"node\") {\n if (key === ORIGINAL_ID_KEY && restoreMangledIds) {\n this.hasOriginalId = true;\n return true;\n }\n return key === \"id\";\n }\n if (key === \"source\" || key === \"target\" || key === \"directed\") {\n return true;\n }\n if (key === weightFrom) {\n this.weightKinds |= kindBit(this.requireTokens(), v);\n return true;\n }\n return false;\n }\n\n /**\n * Record one value of one key in a table's schema.\n * @param schema - the table's schema\n * @param domain - the table\n * @param key - the key\n * @param v - the value token\n * @param seq - the element sequence number\n */\n private observe(\n schema: Map<string, KeySchema>,\n domain: \"node\" | \"edge\" | \"graph\",\n key: string,\n v: number,\n seq: number,\n ): void {\n const t = this.requireTokens();\n this.noteStructure(domain, key, v);\n let entry = schema.get(key);\n const graphics = domain === \"node\" && key === \"graphics\" && this.positions;\n if (entry === undefined) {\n entry = {\n key,\n kinds: 0,\n list: false,\n lastSeq: seq,\n wide: false,\n unsafe: false,\n dict: this.dictionaries && roleOf(domain, key) === null ? new DictHeuristic() : null,\n position: false,\n rest: false,\n };\n schema.set(key, entry);\n } else if (entry.lastSeq === seq) {\n entry.list = true;\n // a repeated graphics record: the extra records go to the json column\n entry.rest ||= graphics;\n } else {\n entry.lastSeq = seq;\n }\n if (graphics && t.kind[v] !== TOKEN_OPEN) {\n entry.rest = true;\n }\n switch (t.kind[v]) {\n case TOKEN_STRING: {\n const raw = t.textOf(v);\n // a label is text: \"[]\" there is a label, never NetworkX's empty list\n if (\n raw === LIST_START_MARKER ||\n (!isLabel(domain, key) && (raw === EMPTY_LIST_TEXT || raw === EMPTY_TUPLE_TEXT))\n ) {\n entry.list = true;\n return;\n }\n entry.kinds |= KIND_STRING;\n if (entry.dict !== null && !entry.dict.decided) {\n entry.dict.observe(raw);\n }\n return;\n }\n case TOKEN_INT: {\n entry.kinds |= KIND_INT;\n const n = Number(t.textOf(v));\n if (n < I32_MIN || n > I32_MAX) {\n entry.wide = true;\n if (!Number.isSafeInteger(n)) {\n entry.unsafe = true;\n }\n }\n return;\n }\n case TOKEN_OPEN:\n entry.kinds |= KIND_RECORD;\n if (domain === \"node\" && key === \"graphics\" && this.positions) {\n this.inspectGraphics(entry, v);\n }\n return;\n default: {\n entry.kinds |= KIND_REAL;\n const text = t.textOf(v);\n if (/\\d/.test(text) && !Number.isFinite(Number(text))) {\n this.report.warnOnce(\n \"precision\",\n PRECISION_CODE,\n `${domain} key \"${key}\" holds the real ${text}, beyond the f64 range; it is stored as ${numberOfText(text) > 0 ? \"\" : \"-\"}Infinity`,\n { line: t.line[v], element: key },\n `${PRECISION_CODE}:overflow:${domain}:${key}`,\n );\n }\n }\n }\n }\n\n /**\n * Warn about keys of a node or edge whose meaning GML readers give but this import does not:\n * a nested graph / node / edge record, and yEd's group hierarchy.\n * @param domain - the table\n * @param key - the key\n * @param v - the value token\n */\n private noteStructure(domain: \"node\" | \"edge\" | \"graph\", key: string, v: number): void {\n const t = this.requireTokens();\n if (domain === \"graph\") {\n return;\n }\n if ((key === \"graph\" || key === \"node\" || key === \"edge\") && t.kind[v] === TOKEN_OPEN) {\n this.report.warnOnce(\n \"unsupported\",\n NESTED_ELEMENT_CODE,\n `a nested ${key} record inside a ${domain} is kept as the json column \"${key}\"; it is not read as structure`,\n { line: t.line[v], element: key },\n `${NESTED_ELEMENT_CODE}:${domain}:${key}`,\n );\n } else if (domain === \"node\" && (key === \"isGroup\" || key === \"gid\")) {\n this.report.warnOnce(\n \"unsupported\",\n GROUPS_CODE,\n \"yEd group keys (isGroup, gid) are kept as plain node columns; the group hierarchy is not read as containment\",\n { line: t.line[v], element: key },\n );\n }\n }\n\n /**\n * Note whether a node's graphics record carries a position (numeric x and y) and whether\n * anything besides the position remains.\n * @param entry - the graphics schema entry\n * @param open - the record's `[`\n */\n private inspectGraphics(entry: KeySchema, open: number): void {\n const t = this.requireTokens();\n const close = t.match[open];\n let x = false;\n let y = false;\n let other = false;\n for (let p = open + 1; p < close; p = t.nextPair(p)) {\n const key = t.textOf(p);\n const numeric = t.kind[p + 1] === TOKEN_INT || t.kind[p + 1] === TOKEN_REAL;\n if (key === \"x\" && numeric && !x) {\n x = true;\n } else if (key === \"y\" && numeric && !y) {\n y = true;\n } else if (!(key === \"z\" && numeric)) {\n other = true;\n }\n }\n const positioned = x && y;\n entry.position ||= positioned;\n // with keepPositionSource the whole record, x / y / z included, goes to the json column too\n entry.rest ||= positioned ? other || this.keepPositionSource : true;\n }\n\n // ============================================================ pass 2: the push\n\n /** Declare what the schema needs, set the header and push every element. */\n private push(): void {\n const { sink, report, options } = this;\n const t = this.requireTokens();\n sink.reserve(this.nodeCount, this.edgeCount);\n this.buildPlans();\n this.setMetadata();\n this.headerDirected = this.readFlag(this.directedToken, \"directed\") ?? options.defaultDirected;\n const resolver = new DirectionResolver(sink, report, options.onMixedDirection);\n resolver.setHeader(this.headerDirected, {\n line: this.directedToken >= 0 ? t.line[this.directedToken] : t.line[this.graphOpen],\n });\n this.resolver = resolver;\n if (options.nodeIdFrom !== \"id\" || this.hasOriginalId) {\n this.idMap = new Map();\n }\n if (options.nodeIdFrom !== \"id\") {\n report.loss(\n ID_DROPPED_CODE,\n `node ids taken from the ${options.nodeIdFrom}; the integer id keys are not kept as a column`,\n null,\n this.nodeCount,\n );\n }\n this.pushTopLevel();\n this.pushNodes();\n this.pushEdges();\n }\n\n /** Turn every schema entry into a column plan. */\n private buildPlans(): void {\n for (const [key, entry] of this.nodeSchema) {\n this.nodePlans.set(key, this.planOf(\"node\", entry));\n }\n for (const [key, entry] of this.edgeSchema) {\n this.edgePlans.set(key, this.planOf(\"edge\", entry));\n }\n for (const [key, entry] of this.graphSchema) {\n this.graphPlans.set(key, this.planOf(\"graph\", entry));\n }\n for (const [key, entry] of this.topSchema) {\n this.topPlans.set(key, this.planOf(\"graph\", entry, true));\n }\n }\n\n /**\n * Warn about a key that mixes numbers and strings, or holds integers beyond 2^53.\n * @param domain - the table\n * @param entry - the schema entry\n * @param asText - whether the integers are kept as text\n */\n private warnKinds(domain: \"node\" | \"edge\" | \"graph\", entry: KeySchema, asText: boolean): void {\n if (\n (entry.kinds & KIND_STRING) !== 0 &&\n (entry.kinds & (KIND_INT | KIND_REAL)) !== 0 &&\n (entry.kinds & KIND_RECORD) === 0\n ) {\n this.report.warnOnce(\n \"coercion\",\n WIDENED_CODE,\n `${domain} key \"${entry.key}\" mixes numbers and strings; the column is string and the numbers are kept as written`,\n { element: entry.key },\n `${WIDENED_CODE}:${domain}:${entry.key}`,\n );\n }\n if (entry.unsafe && !asText) {\n this.report.warnOnce(\n \"precision\",\n PRECISION_CODE,\n `${domain} key \"${entry.key}\" holds integers beyond 2^53; they are stored as the nearest f64 (pass long: \"string\" to keep every digit as text)`,\n { element: entry.key },\n `${PRECISION_CODE}:${domain}:${entry.key}`,\n );\n }\n }\n\n /**\n * The plan of a node `graphics` record: the plan plus its position and rest columns.\n * @param plan - the record's plan\n * @param entry - the schema entry\n * @returns the plan with its position (and rest) plans\n */\n private graphicsPlan(plan: ColumnPlan, entry: KeySchema): ColumnPlan {\n const taken = (candidate: string): boolean =>\n this.nodeSchema.has(candidate) || this.sink.nodeColumn(candidate) !== INVALID_INDEX;\n const position: ColumnPlan = {\n ...plan,\n name: uniqueColumnName(\"position\", \"graphics\", taken),\n dtype: \"f64\",\n itemDtype: null,\n kind: \"real\",\n list: false,\n role: \"position\",\n };\n const rest: ColumnPlan | null = entry.rest\n ? { ...plan, dtype: \"json\", itemDtype: null, kind: \"record\", list: false }\n : null;\n return { ...plan, position, rest };\n }\n\n /**\n * The plan of one schema entry.\n * @param domain - the table\n * @param entry - the schema entry\n * @param top - whether the key is a top-level one (graph table)\n * @returns the plan\n */\n private planOf(domain: \"node\" | \"edge\" | \"graph\", entry: KeySchema, top = false): ColumnPlan {\n // long: \"string\" keeps every digit of an integer key that holds values beyond 2^53, as text\n const asText = entry.unsafe && this.options.long === \"string\" && kindOf(entry) === \"int\";\n const kind = asText ? \"string\" : kindOf(entry);\n let scalar: ScalarDtype = dtypeOfKind(kind, entry);\n if (\n scalar === \"string\" &&\n !entry.list &&\n entry.dict !== null &&\n entry.kinds === KIND_STRING &&\n entry.dict.decide() === \"dict\"\n ) {\n scalar = \"dict\";\n }\n this.warnKinds(domain, entry, asText);\n const name = domain === \"graph\" ? this.uniqueGraphName(entry.key) : entry.key;\n let itemDtype: ScalarDtype | null = null;\n if (entry.list) {\n itemDtype = scalar === \"dict\" ? \"string\" : scalar;\n }\n const plan: ColumnPlan = {\n key: entry.key,\n name,\n dtype: entry.list ? \"list\" : scalar,\n itemDtype,\n kind,\n list: entry.list,\n role: roleOf(domain, entry.key),\n top,\n position: null,\n rest: null,\n handle: INVALID_INDEX as ColumnHandle,\n declared: false,\n items: null,\n seq: Number.NEGATIVE_INFINITY,\n };\n if (domain === \"node\" && entry.key === \"graphics\" && this.positions && (entry.kinds & KIND_RECORD) !== 0) {\n return this.graphicsPlan(plan, entry);\n }\n return plan;\n }\n\n /**\n * A graph column name not yet used by this import (top-level and in-graph keys share the table).\n * @param key - the key\n * @returns the name\n */\n private uniqueGraphName(key: string): string {\n const name = uniqueColumnName(key, key, (candidate) => this.graphNames.has(candidate));\n this.graphNames.add(name);\n if (name !== key) {\n this.report.warning(\n \"coercion\",\n COLUMN_RENAMED_CODE_GML,\n `the top-level key \"${key}\" and a key of the graph block share the graph column name; the top-level value is stored as \"${name}\"`,\n { element: key },\n );\n }\n return name;\n }\n\n /** Set the graph metadata: source format, creator, version, multigraph flag, weight origin. */\n private setMetadata(): void {\n const t = this.requireTokens();\n const { sink, options } = this;\n const textOf = (v: number): string => (t.kind[v] === TOKEN_STRING ? t.stringOf(v) : t.textOf(v));\n const multigraph = this.readFlag(this.multigraphToken, \"multigraph\");\n sink.setMeta({\n sourceFormat: \"gml\",\n creator: this.creatorToken >= 0 ? textOf(this.creatorToken) : undefined,\n sourceVersion: this.versionToken >= 0 ? textOf(this.versionToken) : undefined,\n declaredMultigraph: multigraph ?? undefined,\n weightOrigin:\n this.weightKinds !== 0 && options.weightFrom !== null\n ? {\n format: \"gml\",\n id: options.weightFrom,\n title: null,\n type: this.weightKinds === KIND_INT ? \"int\" : \"real\",\n namespace: null,\n }\n : undefined,\n // The header as written, so a reader can say which words set the direction and tell\n // `directed 0` from a file that relies on the specification's default.\n extra: this.directedToken >= 0 ? { gml: { directed: textOf(this.directedToken) } } : undefined,\n });\n }\n\n /**\n * Read a `directed` / `multigraph` flag token.\n * @param v - the value token, or -1 when absent\n * @param name - the flag name, for issues\n * @returns the flag, or null when absent or not an integer\n */\n private readFlag(v: number, name: string): boolean | null {\n if (v < 0) {\n return null;\n }\n const t = this.requireTokens();\n // Files in the wild write the flag as a quoted integer (`directed \"1\"`); read it, with a warning.\n const quoted = t.kind[v] === TOKEN_STRING && QUOTED_INT.test(t.stringOf(v));\n if (quoted) {\n this.report.warning(\n \"validation-error\",\n FLAG_VALUE_CODE,\n `flag \"${name}\" is written as the string ${describeValue(t, v)}; read as an integer`,\n { line: t.line[v], element: name },\n );\n } else if (t.kind[v] !== TOKEN_INT) {\n this.report.error(\n \"validation-error\",\n FLAG_TYPE_CODE,\n `flag \"${name}\" must be the integer 0 or 1, found ${describeValue(t, v)}`,\n { line: t.line[v], element: name },\n );\n return null;\n }\n const n = Number(quoted ? t.stringOf(v) : t.textOf(v));\n if (n !== 0 && n !== 1) {\n this.report.warning(\n \"validation-error\",\n FLAG_VALUE_CODE,\n `flag \"${name}\" is ${n}; read as ${n !== 0 ? \"1\" : \"0\"}`,\n { line: t.line[v], element: name },\n );\n }\n return n !== 0;\n }\n\n /** Push the top-level attributes (every top-level key but graph, Creator and Version). */\n private pushTopLevel(): void {\n const t = this.requireTokens();\n for (let p = 0; p < t.count; p = t.nextPair(p)) {\n const v = p + 1;\n if (v === this.graphOpen || v === this.creatorToken || v === this.versionToken) {\n continue;\n }\n const plan = this.topPlans.get(t.textOf(p));\n if (plan !== undefined) {\n this.writeGraph(plan, v, TOP_SEQ);\n }\n }\n this.flushGraphLists();\n }\n\n /** Push every node block and the graph block's own attributes, in file order. */\n private pushNodes(): void {\n const t = this.requireTokens();\n const close = t.match[this.graphOpen];\n for (let p = this.graphOpen + 1; p < close; p = t.nextPair(p)) {\n const key = t.textOf(p);\n const v = p + 1;\n switch (key) {\n case \"node\":\n if (t.kind[v] === TOKEN_OPEN) {\n this.importNode(v);\n } else {\n this.badElement(\"node\", p);\n this.report.counts.skippedNodes++;\n }\n break;\n case \"edge\":\n break;\n case \"directed\":\n case \"multigraph\":\n if (v !== this.directedToken && v !== this.multigraphToken) {\n this.report.warning(\n \"validation-error\",\n FLAG_VALUE_CODE,\n `graph flag \"${key}\" repeated; the first value stands`,\n { line: t.line[p], element: key },\n );\n }\n break;\n default: {\n const plan = this.graphPlans.get(key);\n if (plan !== undefined) {\n this.writeGraph(plan, v, GRAPH_SEQ);\n }\n }\n }\n }\n this.flushGraphLists();\n }\n\n /** Push every edge block, in file order. */\n private pushEdges(): void {\n const t = this.requireTokens();\n const close = t.match[this.graphOpen];\n let ordinal = 0;\n for (let p = this.graphOpen + 1; p < close; p = t.nextPair(p)) {\n if (t.textOf(p) !== \"edge\") {\n continue;\n }\n const v = p + 1;\n if (t.kind[v] === TOKEN_OPEN) {\n this.importEdge(v, ordinal);\n } else {\n this.badElement(\"edge\", p);\n this.report.counts.skippedEdges++;\n }\n ordinal++;\n }\n }\n\n /**\n * Record a `node` / `edge` key whose value is not a block.\n * @param what - node or edge\n * @param p - the key token\n */\n private badElement(what: string, p: number): void {\n const t = this.requireTokens();\n this.report.error(\n \"validation-error\",\n ELEMENT_TYPE_CODE,\n `${what} must be a [ ... ] block, found ${describeValue(t, p + 1)}`,\n { line: t.line[p], element: what },\n );\n }\n\n /**\n * Push one node block.\n * @param open - the block's `[`\n */\n private importNode(open: number): void {\n const t = this.requireTokens();\n const { sink, report, options } = this;\n const close = t.match[open];\n const line = t.line[open];\n const ordinal = this.nodeOrdinal++;\n this.checkAbort();\n let index: number;\n let sinkId: NodeId;\n let fileId: NodeId | undefined;\n try {\n let idTok = -1;\n let labelTok = -1;\n let originalTok = -1;\n for (let p = open + 1; p < close; p = t.nextPair(p)) {\n const key = t.textOf(p);\n if (key === \"id\") {\n idTok = this.structuralToken(idTok, p, \"id\");\n } else if (key === \"label\") {\n labelTok = labelTok < 0 ? p + 1 : labelTok;\n } else if (key === ORIGINAL_ID_KEY && options.restoreMangledIds) {\n originalTok = originalTok < 0 ? p + 1 : originalTok;\n }\n }\n if (idTok < 0) {\n throw new GraphFormatError(\"E_INVALID_ID\", \"node has no id\", { reason: \"missing id\" });\n }\n // the file id under the ids rule, so `id 1` and `source \"1\"` meet in idMap (except under\n // \"keep\", where the integer 1 and the string \"1\" are different ids by design)\n fileId = this.coerceFileId(idTok, this.fileIdOf(idTok, \"id\"));\n if (originalTok >= 0) {\n sinkId = this.restoredId(originalTok);\n } else {\n switch (options.nodeIdFrom) {\n case \"label\":\n if (labelTok < 0) {\n throw new GraphFormatError(\"E_INVALID_ID\", \"node has no label\", {\n reason: \"missing label\",\n });\n }\n sinkId = this.coerceValueToken(labelTok);\n break;\n case \"index\":\n sinkId = ordinal;\n break;\n default:\n sinkId = fileId;\n }\n }\n index = sink.addNode(sinkId);\n if (this.idMap !== null) {\n const before = this.idMap.get(fileId);\n if (before !== undefined && before !== sinkId) {\n report.warning(\n \"merged\",\n DUPLICATE_NODE_CODE,\n `file id ${JSON.stringify(fileId)} is declared twice (nodes ${JSON.stringify(before)} and ${JSON.stringify(sinkId)}); edges to it resolve to the later`,\n { line, element: String(fileId) },\n );\n }\n this.idMap.set(fileId, sinkId);\n }\n } catch (err) {\n this.recordNodeError(err, line);\n report.counts.skippedNodes++;\n if (fileId !== undefined) {\n this.skippedIds.add(fileId);\n }\n return;\n }\n if (this.isDeclared(index)) {\n report.warning(\n \"merged\",\n DUPLICATE_NODE_CODE,\n `node ${JSON.stringify(sinkId)} is declared twice; later keys overwrite`,\n { line, element: String(sinkId) },\n );\n } else {\n this.markDeclared(index);\n report.counts.nodes++;\n }\n this.beginElement(this.seq++);\n try {\n const graphics: number[] = [];\n let graphicsPlan: ColumnPlan | null = null;\n for (let p = open + 1; p < close; p = t.nextPair(p)) {\n const key = t.textOf(p);\n if (key === \"id\" || (key === ORIGINAL_ID_KEY && options.restoreMangledIds)) {\n continue;\n }\n const plan = this.nodePlans.get(key);\n if (plan !== undefined && plan.position !== null) {\n graphicsPlan = plan;\n graphics.push(p + 1);\n } else if (plan !== undefined) {\n this.writeNode(plan, index, p + 1);\n }\n }\n if (graphicsPlan !== null) {\n this.writeGraphics(graphicsPlan, index, graphics, {\n line: t.line[graphics[0]],\n element: String(sinkId),\n });\n }\n this.flushLists(\"node\", index);\n } catch (err) {\n this.touched.length = 0;\n report.recordError(err, { line, element: String(sinkId) });\n }\n }\n\n /**\n * Push one edge block.\n * @param open - the block's `[`\n * @param ordinal - the edge's ordinal among edge blocks, for messages\n */\n private importEdge(open: number, ordinal: number): void {\n const t = this.requireTokens();\n const { sink, report, options } = this;\n const close = t.match[open];\n const line = t.line[open];\n const element = `edge #${ordinal}`;\n this.checkAbort();\n let edge: number;\n try {\n let sourceTok = -1;\n let targetTok = -1;\n let weightTok = -1;\n let directedTok = -1;\n for (let p = open + 1; p < close; p = t.nextPair(p)) {\n const key = t.textOf(p);\n if (key === \"source\") {\n sourceTok = this.structuralToken(sourceTok, p, \"source\");\n } else if (key === \"target\") {\n targetTok = this.structuralToken(targetTok, p, \"target\");\n } else if (key === \"directed\") {\n directedTok = this.structuralToken(directedTok, p, \"directed\");\n } else if (key === options.weightFrom) {\n weightTok = p + 1;\n }\n }\n if (sourceTok < 0 || targetTok < 0) {\n throw new GraphFormatError(\"E_UNKNOWN_NODE\", `edge has no ${sourceTok < 0 ? \"source\" : \"target\"}`, {\n reason: \"missing endpoint\",\n });\n }\n const source = this.endpoint(sourceTok, \"source\");\n const target = this.endpoint(targetTok, \"target\");\n const weight = weightTok >= 0 ? this.weightOf(weightTok) : undefined;\n const before = sink.edgeCount;\n const sourceNew = sink.indexOf(source) === INVALID_INDEX;\n const targetNew = source !== target && sink.indexOf(target) === INVALID_INDEX;\n // an edge-level `directed` key overrides the graph's flag for that edge (mixed graphs)\n const directed = this.readFlag(directedTok, \"directed\") ?? this.headerDirected;\n edge = this.requireResolver().addEdge(source, target, directed ? \"directed\" : \"undirected\", weight, {\n line,\n element,\n });\n report.counts.edges += sink.edgeCount - before;\n // endpoints the file never declares (addMissingNodes) are nodes of the sink too\n report.counts.nodes += (sourceNew ? 1 : 0) + (targetNew ? 1 : 0);\n } catch (err) {\n this.recordEdgeError(err, line, element);\n report.counts.skippedEdges++;\n return;\n }\n this.beginElement(this.seq++);\n try {\n for (let p = open + 1; p < close; p = t.nextPair(p)) {\n const key = t.textOf(p);\n if (key === \"source\" || key === \"target\" || key === \"directed\" || key === options.weightFrom) {\n continue;\n }\n const plan = this.edgePlans.get(key);\n if (plan !== undefined) {\n this.writeEdge(plan, edge, p + 1);\n }\n }\n this.flushLists(\"edge\", edge);\n } catch (err) {\n this.touched.length = 0;\n report.recordError(err, { line, element });\n }\n }\n\n // ============================================================ ids and weights\n\n /**\n * Note a structural key token, refusing a repeat.\n * @param previous - the token seen before, or -1\n * @param p - the key token\n * @param key - the key name\n * @returns the value token\n */\n private structuralToken(previous: number, p: number, key: string): number {\n if (previous >= 0) {\n throw new GraphFormatError(\"E_INVALID_ID\", `key \"${key}\" appears twice in one block`, {\n reason: \"duplicate key\",\n key,\n });\n }\n return p + 1;\n }\n\n /**\n * The value of an id / source / target token: an integer (the GML spec's type) as a number, a\n * string (NetworkX and Gephi write them) as its text with one warning per file.\n * @param v - the value token\n * @param key - the key name, for the error\n * @returns the number or the string\n */\n private fileIdOf(v: number, key: string): number | string {\n const t = this.requireTokens();\n if (t.kind[v] === TOKEN_STRING) {\n this.report.warnOnce(\n \"validation-error\",\n STRING_ID_CODE,\n `${key} is the string \"${t.textOf(v)}\"; GML ids are integers, string ids are kept under the ids rule`,\n { line: t.line[v], element: t.stringOf(v) },\n );\n return t.stringOf(v);\n }\n if (t.kind[v] !== TOKEN_INT) {\n throw new GraphFormatError(\n \"E_INVALID_ID\",\n `${key} must be an integer or a string, found ${describeValue(t, v)}`,\n {\n reason: \"not an integer\",\n key,\n value: t.kind[v] === TOKEN_OPEN ? \"[...]\" : t.textOf(v),\n },\n );\n }\n return Number(t.textOf(v));\n }\n\n /**\n * Coerce an id / source / target value under the `ids` rule: a string by its text, an integer\n * through coerceInteger().\n * @param v - the value token\n * @param id - its value (fileIdOf())\n * @returns the id\n */\n private coerceFileId(v: number, id: number | string): NodeId {\n return typeof id === \"string\" ? this.coercer.text(id) : this.coerceInteger(v, id);\n }\n\n /**\n * Coerce an integer id token under the `ids` rule: a safe integer passes as a typed number\n * (so `01` is 1 and `-0` is 0), a larger one goes through the text rule (a string under\n * \"canonical\"), and \"string\" keeps the text as written.\n * @param v - the value token\n * @param n - its numeric value\n * @returns the id\n */\n private coerceInteger(v: number, n: number): NodeId {\n if (Number.isSafeInteger(n) && this.coercer.mode !== \"string\") {\n return this.coercer.value(n);\n }\n return this.coercer.text(this.requireTokens().textOf(v));\n }\n\n /**\n * Coerce a label token under the `ids` rule: a string by its text, a number as a typed value.\n * @param v - the value token\n * @returns the id\n */\n private coerceValueToken(v: number): NodeId {\n const t = this.requireTokens();\n switch (t.kind[v]) {\n case TOKEN_STRING:\n return this.coercer.text(t.stringOf(v));\n case TOKEN_INT:\n return this.coerceInteger(v, Number(t.textOf(v)));\n case TOKEN_OPEN:\n throw new GraphFormatError(\"E_INVALID_ID\", \"label must be a string or a number, found a record\", {\n reason: \"record label\",\n });\n default:\n return this.coercer.value(numberOfText(t.textOf(v)));\n }\n }\n\n /**\n * The id a `graphty_originalId` key restores: typed, never coerced (the exporter wrote it exactly).\n * @param v - the value token\n * @returns the original id\n */\n private restoredId(v: number): NodeId {\n const t = this.requireTokens();\n switch (t.kind[v]) {\n case TOKEN_STRING:\n return t.stringOf(v);\n case TOKEN_OPEN:\n throw new GraphFormatError(\"E_INVALID_ID\", `${ORIGINAL_ID_KEY} must be a string or a number`, {\n reason: \"record original id\",\n });\n default:\n return numberOfText(t.textOf(v));\n }\n }\n\n /**\n * Resolve a source / target token to a sink id.\n * @param v - the value token\n * @param key - source or target\n * @returns the id\n */\n private endpoint(v: number, key: string): NodeId {\n const id = this.coerceFileId(v, this.fileIdOf(v, key));\n const mapped = this.idMap?.get(id);\n if (mapped !== undefined) {\n return mapped;\n }\n if (this.skippedIds.has(id)) {\n // the node block was skipped: creating the endpoint would bring the node back under\n // its raw file id (beside label ids under nodeIdFrom \"label\")\n throw new GraphFormatError(\n \"E_UNKNOWN_NODE\",\n `${key} ${JSON.stringify(id)} names a node block that was skipped after an error`,\n { reason: \"skipped node\", id },\n );\n }\n return id;\n }\n\n /**\n * The weight of an edge from its weight token.\n * @param v - the value token\n * @returns the weight; E_INVALID_WEIGHT for a record or non-numeric text\n */\n private weightOf(v: number): number | undefined {\n const t = this.requireTokens();\n switch (t.kind[v]) {\n case TOKEN_STRING:\n return parseWeightText(t.stringOf(v), this.report);\n case TOKEN_OPEN:\n throw new GraphFormatError(\"E_INVALID_WEIGHT\", \"edge weight is a record\", { value: \"[...]\" });\n default: {\n const text = t.textOf(v);\n const weight = weightFromValue(numberOfText(text));\n if (weight !== undefined) {\n reportWeightPrecision(text, weight, this.report);\n }\n return weight;\n }\n }\n }\n\n /**\n * Record a node-level error under the GML code it implies.\n * @param err - the thrown value\n * @param line - the block's line\n */\n private recordNodeError(err: unknown, line: number): void {\n const { report } = this;\n if (err instanceof GraphFormatError && err.code === \"E_INVALID_ID\") {\n const { reason } = err.details;\n switch (reason) {\n case \"missing id\":\n report.error(\"missing-value\", MISSING_ID_CODE, err.message, { line, element: \"node\" });\n return;\n case \"missing label\":\n report.error(\"missing-value\", MISSING_LABEL_CODE, err.message, { line, element: \"node\" });\n return;\n case \"duplicate key\":\n report.error(\"validation-error\", REPEATED_KEY_CODE, err.message, { line, element: \"node\" });\n return;\n case \"not an integer\":\n report.error(\"validation-error\", ID_TYPE_CODE, err.message, { line, element: \"node\" });\n return;\n default:\n break;\n }\n }\n report.recordError(err, { line, element: \"node\" });\n }\n\n /**\n * Record an edge-level error under the GML code it implies.\n * @param err - the thrown value\n * @param line - the block's line\n * @param element - the edge description\n */\n private recordEdgeError(err: unknown, line: number, element: string): void {\n const { report } = this;\n if (err instanceof GraphFormatError) {\n const { reason } = err.details;\n if (err.code === \"E_UNKNOWN_NODE\" && reason === \"missing endpoint\") {\n report.error(\"missing-value\", MISSING_ENDPOINT_CODE, err.message, { line, element });\n return;\n }\n if (err.code === \"E_INVALID_ID\" && reason === \"duplicate key\") {\n report.error(\"validation-error\", REPEATED_KEY_CODE, err.message, { line, element });\n return;\n }\n if (err.code === \"E_INVALID_ID\" && reason === \"not an integer\") {\n report.error(\"validation-error\", ID_TYPE_CODE, err.message, { line, element });\n return;\n }\n }\n report.recordError(err, { line, element });\n }\n\n // ============================================================ values\n\n /**\n * Write one node value.\n * @param plan - the key's plan\n * @param index - the node index\n * @param v - the value token\n */\n private writeNode(plan: ColumnPlan, index: number, v: number): void {\n if (plan.list) {\n this.collectItem(plan, v, this.seqNow, this.touched);\n return;\n }\n this.sink.setNodeValue(this.handleOf(plan, \"node\"), index, this.scalarOf(plan, v));\n }\n\n /**\n * Write one edge value.\n * @param plan - the key's plan\n * @param edge - the edge index\n * @param v - the value token\n */\n private writeEdge(plan: ColumnPlan, edge: number, v: number): void {\n if (plan.list) {\n this.collectItem(plan, v, this.seqNow, this.touched);\n return;\n }\n this.sink.setEdgeValue(this.handleOf(plan, \"edge\"), edge, this.scalarOf(plan, v));\n }\n\n /**\n * Write one graph value.\n * @param plan - the key's plan\n * @param v - the value token\n * @param seq - TOP_SEQ or GRAPH_SEQ\n */\n private writeGraph(plan: ColumnPlan, v: number, seq: number): void {\n if (plan.list) {\n this.collectItem(plan, v, seq, this.graphTouched);\n return;\n }\n const value = this.scalarOf(plan, v);\n this.sink.setGraphValue(plan.name, value, graphDecl(plan));\n if (seq === GRAPH_SEQ && plan.key === \"name\" && typeof value === \"string\") {\n // the graph block's `name` is the graph's name too (snapshot.meta.name, and what graphName matches)\n this.sink.setMeta({ name: value });\n }\n }\n\n /**\n * Write a node's graphics values: the position column from the x / y / z of the first record,\n * everything else (the remaining keys, a value that is not a record, a repeated record) to the\n * json column, with a warning when the value cannot give a position as written.\n * @param plan - the graphics plan\n * @param index - the node index\n * @param vs - the value tokens of the node's graphics keys, in order\n * @param where - the line and the node, for issues\n */\n private writeGraphics(plan: ColumnPlan, index: number, vs: readonly number[], where: IssueWhere): void {\n const t = this.requireTokens();\n const { sink } = this;\n const values = vs.map((v) => (t.kind[v] === TOKEN_OPEN ? parseRecord(t, v) : this.scalarOf(plan, v)));\n const first = values[0];\n const positionPlan = plan.position;\n let rest: unknown = first;\n if (isRecord(first) && positionPlan !== null) {\n const left = this.writePosition(positionPlan, index, this.keepPositionSource ? { ...first } : first, where);\n rest = this.keepPositionSource ? first : left;\n } else if (!isRecord(first)) {\n this.graphicsWarning(\"scalar\", `node ${where.element}'s graphics is not a record`, where);\n }\n if (values.length > 1) {\n this.graphicsWarning(\n \"repeated\",\n `node ${where.element} has ${values.length} graphics records; the position comes from the first`,\n where,\n );\n rest = values;\n }\n if (rest !== undefined && plan.rest !== null) {\n sink.setNodeValue(this.handleOf(plan.rest, \"node\"), index, rest);\n }\n }\n\n /**\n * Write a node's position from the x / y / z of its graphics record, taking them out of it.\n * @param positionPlan - the position column's plan\n * @param index - the node index\n * @param record - the graphics record\n * @param where - the line and the node, for issues\n * @returns what is left of the record for the json column, or undefined when nothing is\n */\n private writePosition(\n positionPlan: ColumnPlan,\n index: number,\n record: Record<string, unknown>,\n where: IssueWhere,\n ): unknown {\n const { x, y, z } = record;\n let rest: unknown = record;\n if (typeof x === \"number\" && typeof y === \"number\") {\n const depth = typeof z === \"number\" ? z : 0;\n this.sink.setNodeValue(this.handleOf(positionPlan, \"node\"), index, [x, y, depth]);\n delete record.x;\n delete record.y;\n if (typeof z === \"number\") {\n delete record.z;\n }\n rest = Object.keys(record).length > 0 ? record : undefined;\n }\n if (\"x\" in record || \"y\" in record || \"z\" in record) {\n this.graphicsWarning(\n \"coordinate\",\n `node ${where.element}'s graphics x / y / z is not one number each`,\n where,\n );\n }\n return rest;\n }\n\n /**\n * Warn once per kind of graphics problem.\n * @param kind - the problem\n * @param what - the message start, naming the node\n * @param where - the line and the node\n */\n private graphicsWarning(kind: string, what: string, where: IssueWhere): void {\n this.report.warnOnce(\n \"validation-error\",\n GRAPHICS_CODE,\n `${what}; the value is kept in the graphics json column (warned once for every such node)`,\n where,\n `${GRAPHICS_CODE}:${kind}`,\n );\n }\n\n /**\n * Collect one list item.\n * @param plan - the list plan\n * @param v - the value token\n * @param seq - the sequence number of the element the item belongs to\n * @param touched - the plans touched by that element\n */\n private collectItem(plan: ColumnPlan, v: number, seq: number, touched: ColumnPlan[]): void {\n const t = this.requireTokens();\n if (plan.seq !== seq) {\n plan.seq = seq;\n plan.items = [];\n touched.push(plan);\n }\n if (t.kind[v] === TOKEN_STRING) {\n const raw = t.textOf(v);\n if (raw === LIST_START_MARKER || raw === EMPTY_LIST_TEXT || raw === EMPTY_TUPLE_TEXT) {\n return;\n }\n }\n (plan.items as unknown[]).push(this.scalarOf(plan, v));\n }\n\n /**\n * Start a node or edge: later list items belong to it.\n * @param seq - the element's sequence number\n */\n private beginElement(seq: number): void {\n this.seqNow = seq;\n this.touched.length = 0;\n }\n\n /**\n * Write the lists collected for the current node or edge.\n * @param domain - node or edge\n * @param row - the row\n */\n private flushLists(domain: \"node\" | \"edge\", row: number): void {\n const { sink, touched } = this;\n for (const plan of touched) {\n const handle = this.handleOf(plan, domain);\n if (domain === \"node\") {\n sink.setNodeValue(handle, row, plan.items);\n } else {\n sink.setEdgeValue(handle, row, plan.items);\n }\n plan.items = null;\n }\n touched.length = 0;\n }\n\n /** Write the lists collected for the graph table. */\n private flushGraphLists(): void {\n const { sink, graphTouched } = this;\n for (const plan of graphTouched) {\n sink.setGraphValue(plan.name, plan.items, graphDecl(plan));\n plan.items = null;\n }\n graphTouched.length = 0;\n }\n\n /**\n * The JS value of a scalar value token (or list item) under a plan's storage class.\n * @param plan - the plan\n * @param v - the value token\n * @returns the value to push\n */\n private scalarOf(plan: ColumnPlan, v: number): unknown {\n const t = this.requireTokens();\n const kind = t.kind[v];\n switch (plan.kind) {\n case \"int\":\n return Number(t.textOf(v));\n case \"real\":\n return numberOfText(t.textOf(v));\n case \"string\":\n return kind === TOKEN_STRING ? t.stringOf(v) : t.textOf(v);\n default:\n return kind === TOKEN_STRING ? t.stringOf(v) : scalarOrRecord(t, v);\n }\n }\n\n /**\n * The handle of a plan's column, declaring it on first use. A declaration the sink refuses\n * because a column of the name exists with another declaration falls back to that column\n * (reported once); a taken role is dropped (reported once).\n * @param plan - the plan\n * @param domain - node or edge\n * @returns the handle\n */\n private handleOf(plan: ColumnPlan, domain: \"node\" | \"edge\"): ColumnHandle {\n if (plan.declared) {\n return plan.handle;\n }\n plan.declared = true;\n const { sink, report } = this;\n const decl: ColumnDecl = {\n name: plan.name,\n dtype: plan.dtype,\n nullable: true,\n origin: { format: \"gml\", id: plan.key, title: null, type: originTypeOf(plan), namespace: null },\n };\n if (plan.list) {\n decl.itemDtype = plan.itemDtype ?? \"string\";\n }\n if (plan.role === \"position\") {\n decl.components = 3;\n }\n if (plan.role !== null) {\n decl.role = plan.role;\n }\n const resolved = declareResolved(sink, domain, decl, report, { element: plan.name });\n plan.handle = resolved.handle;\n if (resolved.renamed) {\n plan.name = resolved.decl.name;\n }\n return plan.handle;\n }\n\n // ============================================================ bookkeeping\n\n /**\n * Whether a node index was declared by a node block of this import.\n * @param index - the node index\n * @returns true when declared\n */\n private isDeclared(index: number): boolean {\n const word = index >>> 5;\n return word < this.declared.length && ((this.declared[word] >>> (index & 31)) & 1) === 1;\n }\n\n /**\n * Mark a node index as declared.\n * @param index - the node index\n */\n private markDeclared(index: number): void {\n const word = index >>> 5;\n if (word >= this.declared.length) {\n const grown = new Uint32Array(Math.max(word + 1, this.declared.length * 2));\n grown.set(this.declared);\n this.declared = grown;\n }\n this.declared[word] |= 1 << (index & 31);\n }\n\n /** Check the abort signal every ABORT_CHECK_INTERVAL elements. */\n private checkAbort(): void {\n if (++this.elementsSinceCheck >= ABORT_CHECK_INTERVAL) {\n this.elementsSinceCheck = 0;\n throwIfAborted(this.options.signal);\n }\n }\n\n /**\n * The tokens, which exist after run() lexed the text.\n * @returns the tokens\n */\n private requireTokens(): GmlTokens {\n if (this.tokens === null) {\n throw new GraphFormatError(\"E_UNSUPPORTED\", \"the GML text was not lexed\", { reason: \"no tokens\" });\n }\n return this.tokens;\n }\n\n /**\n * The direction resolver, which exists once the header was set.\n * @returns the resolver\n */\n private requireResolver(): DirectionResolver {\n if (this.resolver === null) {\n throw new GraphFormatError(\"E_DIRECTED\", \"the header was not set\", { reason: \"no resolver\" });\n }\n return this.resolver;\n }\n}\n\n/**\n * The KIND_* bit of a value token.\n * @param t - the tokens\n * @param v - the value token\n * @returns the bit\n */\nfunction kindBit(t: GmlTokens, v: number): number {\n switch (t.kind[v]) {\n case TOKEN_INT:\n return KIND_INT;\n case TOKEN_STRING:\n return KIND_STRING;\n case TOKEN_OPEN:\n return KIND_RECORD;\n default:\n return KIND_REAL;\n }\n}\n\n/**\n * The storage class of a schema entry: the widest value class seen.\n * @param entry - the entry\n * @returns the class\n */\nfunction kindOf(entry: KeySchema): GmlKind {\n if ((entry.kinds & KIND_RECORD) !== 0) {\n return \"record\";\n }\n if ((entry.kinds & KIND_STRING) !== 0) {\n return \"string\";\n }\n if ((entry.kinds & KIND_REAL) !== 0) {\n return \"real\";\n }\n return \"int\";\n}\n\n/**\n * The scalar dtype of a storage class.\n * @param kind - the class\n * @param entry - the entry (a wide int keeps origin int but stores f64)\n * @returns the dtype\n */\nfunction dtypeOfKind(kind: GmlKind, entry: KeySchema): ScalarDtype {\n switch (kind) {\n case \"int\":\n return entry.wide ? \"f64\" : \"i32\";\n case \"real\":\n return \"f64\";\n case \"string\":\n return \"string\";\n default:\n return \"json\";\n }\n}\n\n/**\n * The origin.type text of a plan: the GML value class of its values (`int` for wide integers\n * stored as f64 too, so the exporter writes them without a decimal point).\n * @param plan - the plan\n * @returns the type text\n */\nfunction originTypeOf(plan: ColumnPlan): string {\n return plan.kind;\n}\n\n/**\n * The declaration patch of a graph column.\n * @param plan - the plan\n * @returns the decl for setGraphValue\n */\nfunction graphDecl(plan: ColumnPlan): ColumnDecl {\n const decl: ColumnDecl = {\n name: plan.name,\n dtype: plan.dtype,\n nullable: true,\n origin: { format: \"gml\", id: plan.key, title: null, type: originTypeOf(plan), namespace: null },\n };\n if (plan.list) {\n decl.itemDtype = plan.itemDtype ?? \"string\";\n }\n if (plan.top) {\n decl.extra = { gmlTopLevel: true };\n }\n return decl;\n}\n\n/**\n * A short description of a value token for messages.\n * @param t - the tokens\n * @param v - the value token\n * @returns the description\n */\nfunction describeValue(t: GmlTokens, v: number): string {\n switch (t.kind[v]) {\n case TOKEN_OPEN:\n return \"a record\";\n case TOKEN_STRING:\n return `the string \"${t.textOf(v)}\"`;\n case TOKEN_REAL:\n return `the real ${t.textOf(v)}`;\n case TOKEN_WORD:\n return `the word ${t.textOf(v)}`;\n default:\n return t.textOf(v);\n }\n}\n\nconst SNIFF_GRAPH_START = /^(?:\\s|#[^\\n]*\\n)*graph\\s*\\[/;\nconst SNIFF_GRAPH_ANYWHERE = /(?:^|\\s)graph\\s*\\[/;\nconst SNIFF_KEY_START = /^(?:\\s|#[^\\n]*\\n)*[A-Za-z_]\\w*\\s+(?:\"|[+-]?[0-9.]|\\[)/;\n\n/**\n * Confidence that a head of bytes is GML: a `graph [` opener, or key-value text with a `graph [`\n * somewhere in the head.\n * @param head - the first bytes of the input\n * @returns 0.95 for a leading `graph [`, 0.85 for key-value text containing one, 0.4 for key-value text, 0 otherwise\n */\nfunction sniffGml(head: Uint8Array): number {\n let text = new TextDecoder(\"utf-8\", { fatal: false }).decode(head);\n if (text.charCodeAt(0) === 0xfeff) {\n text = text.slice(1);\n }\n if (SNIFF_GRAPH_START.test(text)) {\n return 0.95;\n }\n if (SNIFF_KEY_START.test(text)) {\n return SNIFF_GRAPH_ANYWHERE.test(text) ? 0.85 : 0.4;\n }\n return 0;\n}\n\n/**\n * The GML importer plugin.\n * @category Built-in formats\n */\nexport const gmlImporter: GraphImporter<GmlImportOptions> = Object.freeze({\n format: \"gml\",\n options: Object.freeze([\"dictionaries\", \"keepPositionSource\", \"positions\"]),\n extensions: Object.freeze([\".gml\"]),\n mimeTypes: Object.freeze([\"text/x-gml\", \"text/plain\"]),\n sniff: sniffGml,\n styles: gmlStyles,\n positions: gmlPositions,\n /**\n * Read a GML text into a sink.\n * @param input - the text, bytes or stream\n * @param sink - the sink\n * @param options - format-specific and common options\n * @returns the report\n */\n async import(\n input: ImportInput,\n sink: GraphSink,\n options?: GmlImportOptions & CommonImportOptions,\n ): Promise<ImportReport> {\n if (graphChosen(options)) {\n // the choice is honored here too, not only by the registry\n return importChosenGraph(gmlImporter, input, sink, options);\n }\n const resolved = resolveImportOptions(options, FORMAT_DEFAULTS);\n const report = new ImportReportBuilder(\"gml\", resolved.errorLimit);\n reportSinkOptions(sink, options, report);\n reportUnusedOptions(options, report, USED_OPTIONS);\n const tokens = tokenize(await readText(input, report, resolved), report);\n throwIfAborted(resolved.signal);\n const gml = new GmlImport(sink, report, resolved, options);\n gml.run(tokens);\n if (gml.graphCount > 1) {\n report.warning(\n \"unsupported\",\n SECOND_GRAPH_CODE,\n `the input holds ${gml.graphCount - 1} more graph block${plural(gml.graphCount - 1)} after the first; the first is read (graphIndex or graphName chooses another; importAllGraphs() reads every one)`,\n );\n }\n // an abort raised during the last few elements (after the last periodic check) still rejects\n throwIfAborted(resolved.signal);\n return report.finish();\n },\n\n /**\n * Read every `graph [ ... ]` block of a GML text, each into its own sink; the top-level keys\n * (Creator, Version, ...) apply to each.\n * @param input - the text, bytes or stream\n * @param sinkFor - the sink of the graph with this index, called before its first push\n * @param options - format-specific and common options\n * @returns one report per graph block\n */\n async importAll(\n input: ImportInput,\n sinkFor: (index: number) => GraphSink,\n options?: GmlImportOptions & CommonImportOptions,\n ): Promise<ImportReport[]> {\n const resolved = resolveImportOptions(options, FORMAT_DEFAULTS);\n const first = new ImportReportBuilder(\"gml\", resolved.errorLimit);\n reportUnusedOptions(options, first, USED_OPTIONS);\n const tokens = tokenize(await readText(input, first, resolved), first);\n const reports: ImportReport[] = [];\n let count = 1;\n for (let i = 0; i < count; i++) {\n throwIfAborted(resolved.signal);\n const report = i === 0 ? first : new ImportReportBuilder(\"gml\", resolved.errorLimit);\n const sink = sinkFor(i);\n reportSinkOptions(sink, options, report);\n const gml = new GmlImport(sink, report, resolved, options, i);\n gml.run(tokens);\n count = gml.graphCount;\n reports.push(report.finish());\n }\n throwIfAborted(resolved.signal);\n return reports;\n },\n});\n\n/**\n * Tokenize a GML text; a syntax error is fatal.\n * @param text - the whole text\n * @param report - where the syntax error is recorded\n * @returns the tokens\n */\nfunction tokenize(text: string, report: ImportReportBuilder): GmlTokens {\n try {\n return tokenizeGml(text);\n } catch (err) {\n if (err instanceof GmlSyntaxError) {\n report.fail(err.code, err.message, { line: err.line });\n }\n throw err;\n }\n}\n","/**\n * The `@graphty/graph-io/gml` subpath: the GML importer and exporter, their\n * option types, and their issue and loss-note codes grouped in two tables.\n * @module @graphty/graph-io/gml\n */\n\nimport {\n AMBIGUOUS_GRAPH_NAME_CODE,\n COLUMN_RENAMED_CODE,\n DIRECTION_FORCED_CODE,\n DIRECTION_REFUSED_CODE,\n ELEMENT_ISSUE,\n ENCODING_FALLBACK_CODE,\n GRAPH_NOT_FOUND_CODE,\n ID_MERGED_CODE,\n INPUT_ISSUE,\n INVALID_ENCODING_CODE,\n INVALID_UTF8_CODE,\n MIXED_DIRECTION_CODE,\n OPTION_IGNORED_CODE,\n SINK_OPTION_CODE,\n SYNTAX_CODE,\n UNKNOWN_ENCODING_CODE,\n} from \"../../common/codes.js\";\nimport {\n GRAPHICS_CONFLICT_CODE,\n GRAPHICS_OVERRIDDEN_CODE,\n INVALID_KEY_CODE,\n JSON_ARRAY_CODE,\n KEY_MANGLED_CODE,\n NESTED_ARRAY_CODE,\n POSITION_COMPONENTS_CODE,\n RECORD_BOOLEAN_CODE,\n RECORD_NULL_CODE,\n RECORD_NUMBER_TYPE_CODE,\n RESERVED_KEY_CODE,\n} from \"./exporter.js\";\nimport {\n DUPLICATE_NODE_CODE,\n ELEMENT_TYPE_CODE,\n FLAG_TYPE_CODE,\n FLAG_VALUE_CODE,\n GRAPHICS_CODE,\n GROUPS_CODE,\n ID_DROPPED_CODE,\n ID_TYPE_CODE,\n MISSING_ENDPOINT_CODE,\n MISSING_ID_CODE,\n MISSING_LABEL_CODE,\n NESTED_ELEMENT_CODE,\n NO_GRAPH_CODE,\n PRECISION_CODE,\n REPEATED_KEY_CODE,\n ROLE_TAKEN_CODE,\n SECOND_GRAPH_CODE,\n STRING_ID_CODE,\n UNKNOWN_ENTITY_CODE,\n WIDENED_CODE,\n} from \"./importer.js\";\n\nexport { gmlExporter, type GmlExportOptions } from \"./exporter.js\";\nexport { gmlImporter, type GmlImportOptions } from \"./importer.js\";\nexport { GML_STYLE_BLOCK_KEY, GML_STYLE_CAPABILITIES } from \"./styles.js\";\n\n/**\n * The issue codes the GML importer records, by name: the codes shared with\n * the other importers and the GML-specific ones. A key is the code without\n * its severity and format prefixes.\n * @category Built-in formats\n */\nexport const GML_ISSUE = Object.freeze({\n ...INPUT_ISSUE,\n ...ELEMENT_ISSUE,\n /**\n * The text breaks GML's syntax: a word that is not a key or a value, an unclosed string or `[`, a stray `]`, or a\n * key without a value. The import stops.\n */\n SYNTAX: SYNTAX_CODE,\n /** The input is not valid UTF-8. The import stops. */\n INVALID_UTF8: INVALID_UTF8_CODE,\n /**\n * Some bytes are not valid in the encoding that was chosen (by a byte order mark, the file's declaration or the\n * `encoding` option). The import stops.\n */\n INVALID_ENCODING: INVALID_ENCODING_CODE,\n /** Bytes that are not UTF-8 and declare no encoding were read as windows-1252. */\n ENCODING_FALLBACK: ENCODING_FALLBACK_CODE,\n /** A declared encoding the platform cannot decode was ignored. */\n UNKNOWN_ENCODING: UNKNOWN_ENCODING_CODE,\n /** There is no `graph [` block. The import stops. */\n NO_GRAPH: NO_GRAPH_CODE,\n /** The file holds more than one `graph` block and only the first was read. It is not added when `graphIndex` or `graphName` chose the graph. */\n MULTIPLE_GRAPHS: SECOND_GRAPH_CODE,\n /** `graphIndex` or `graphName` names no graph of the file; the message lists the graphs it holds. The import stops. */\n GRAPH_NOT_FOUND: GRAPH_NOT_FOUND_CODE,\n /** `graphName` matches more than one graph; pass `graphIndex`. The import stops. */\n AMBIGUOUS_GRAPH_NAME: AMBIGUOUS_GRAPH_NAME_CODE,\n /** A node without an `id`. */\n MISSING_ID: MISSING_ID_CODE,\n /** A node without a `label` under nodeIdFrom \"label\". */\n MISSING_LABEL: MISSING_LABEL_CODE,\n /** An edge without `source` or `target`. */\n MISSING_ENDPOINT: MISSING_ENDPOINT_CODE,\n /** A node id, source or target that is neither an integer nor a string. */\n ID_TYPE: ID_TYPE_CODE,\n /**\n * Node ids, sources or targets are text, where GML expects integers. They are read under the `ids` option.\n * Reported once per file.\n */\n STRING_ID: STRING_ID_CODE,\n /** A node id declared twice (later keys overwrite). */\n DUPLICATE_NODE: DUPLICATE_NODE_CODE,\n /** A structural key repeated in one element. */\n REPEATED_KEY: REPEATED_KEY_CODE,\n /** A `node` / `edge` key whose value is not a record. */\n ELEMENT_TYPE: ELEMENT_TYPE_CODE,\n /** A `directed` / `multigraph` flag that is not an integer. */\n FLAG_TYPE: FLAG_TYPE_CODE,\n /** A `directed` / `multigraph` flag outside 0 / 1, or repeated. */\n FLAG_VALUE: FLAG_VALUE_CODE,\n /** A named entity no table decodes, or a numeric reference beyond U+10FFFF; kept as written. */\n UNKNOWN_ENTITY: UNKNOWN_ENTITY_CODE,\n /** An integer beyond 2^53 was stored as the nearest 64-bit float; pass `long: \"string\"` to keep every digit. */\n PRECISION: PRECISION_CODE,\n /** A node's graphics value that cannot give a position as written; kept in the graphics json column. */\n GRAPHICS: GRAPHICS_CODE,\n /** A graph, node or edge record nested in a node or edge; kept as json, not read as structure. */\n NESTED_ELEMENT: NESTED_ELEMENT_CODE,\n /** YEd's isGroup / gid keys, kept as plain columns; the hierarchy is not read as containment. */\n GROUPS: GROUPS_CODE,\n /**\n * An attribute's type was widened because a later value did not fit: an integer above 2^31 in an integer column,\n * or two declared types for one attribute.\n */\n WIDENED: WIDENED_CODE,\n /**\n * An attribute was renamed `<name>#<suffix>` because another attribute already has its name, for example\n * two attributes declared with the same name.\n */\n COLUMN_RENAMED: COLUMN_RENAMED_CODE,\n /**\n * You read into a graph builder that already has an id, label or position attribute, so this file's one is kept as\n * a plain attribute.\n */\n ROLE_TAKEN: ROLE_TAKEN_CODE,\n /** Two different id texts became the same number because `ids` is \"number\", so their nodes were merged. */\n ID_MERGED: ID_MERGED_CODE,\n /** You set an option this format does not use; it had no effect. The message names the option. */\n OPTION_IGNORED: OPTION_IGNORED_CODE,\n /**\n * You read into your own graph builder, which was created with a different `addMissingNodes`, `duplicateEdges`,\n * `selfLoops` or `weightDtype` than the option you passed; the builder's setting applies.\n */\n SINK_OPTION: SINK_OPTION_CODE,\n /**\n * You read into a graph builder whose direction is already set, or which already holds edges, so the file is read\n * with the builder's direction instead of its own.\n */\n DIRECTION_REFUSED: DIRECTION_REFUSED_CODE,\n /** Edges of the other direction were read with the direction `onMixedDirection` chose. */\n DIRECTION_FORCED: DIRECTION_FORCED_CODE,\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: MIXED_DIRECTION_CODE,\n /**\n * Under `nodeIdFrom: \"label\"` or `\"index\"` the file's integer ids are not kept. It is listed in `report.lossy`, not\n * in `report.issues`.\n */\n ID_DROPPED: ID_DROPPED_CODE,\n});\n\n/**\n * The loss-note codes the GML exporter's check() reports beyond the shared LOSS table, by name.\n * @category Built-in formats\n */\nexport const GML_LOSS = Object.freeze({\n /** A json column holds numbers; GML records cannot keep int versus real. */\n RECORD_NUMBER_TYPE: RECORD_NUMBER_TYPE_CODE,\n /** A json column holds booleans, written 1 / 0. */\n RECORD_BOOLEAN: RECORD_BOOLEAN_CODE,\n /** A json column holds nulls, omitted. */\n RECORD_NULL: RECORD_NULL_CODE,\n /** An attribute holds an array inside an array, which GML cannot write; the save fails. */\n NESTED_ARRAY: NESTED_ARRAY_CODE,\n /** A json row that is an array, written as repeated keys. */\n JSON_ARRAY: JSON_ARRAY_CODE,\n /**\n * An attribute name GML cannot use as a key (keys are letters and digits, starting with a letter). The save fails\n * unless `sanitizeKeys` is \"mangle\".\n */\n INVALID_KEY: INVALID_KEY_CODE,\n /** A column named like a structural key. */\n RESERVED_KEY: RESERVED_KEY_CODE,\n /** A key rewritten under sanitizeKeys \"mangle\", or a column renamed because its key would read back as a style value. */\n KEY_MANGLED: KEY_MANGLED_CODE,\n /** A position column with more than three components. */\n POSITION_COMPONENTS: POSITION_COMPONENTS_CODE,\n /** A graphics record whose x / y / z the position column overrides. */\n GRAPHICS_OVERRIDDEN: GRAPHICS_OVERRIDDEN_CODE,\n /** A graphics record that cannot hold the position. */\n GRAPHICS_CONFLICT: GRAPHICS_CONFLICT_CODE,\n});\n"],"names":["note","SHARED_NO_GRAPH_CODE","SHARED_MISSING_ID_CODE","SHARED_MISSING_ENDPOINT_CODE","SHARED_DUPLICATE_NODE_CODE","SHARED_WIDENED_CODE","SHARED_PRECISION_CODE","SHARED_ROLE_TAKEN_CODE","first"],"mappings":";;;;;;;;;;;;;;AAoBO,MAAM,aAAa;AAKnB,MAAM,YAAY;AAKlB,MAAM,aAAa;AAKnB,MAAM,eAAe;AAKrB,MAAM,aAAa;AAKnB,MAAM,cAAc;AASpB,MAAM,oBAAoB;AAM1B,MAAM,kBAAkB;AAMxB,MAAM,mBAAmB;AAMzB,MAAM,kBAAkB;AAOxB,MAAM,wBAAwB;AAK9B,MAAM,oBAAoB;AAK1B,MAAM,qBAAqB;AAK3B,MAAM,sBAAsB;AAEnC,MAAM,WAAW;AACjB,MAAM,kBAAkB;AACxB,MAAM,WAAW;AACjB,MAAM,YAAY;AAClB,MAAM,kBAAkB;AACxB,MAAM,kBAAkB;AAOjB,MAAM,uBAAuB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAatC,YAAY,MAAc,SAAiB,MAAc;AACrD,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EAChB;AACJ;AAOO,MAAM,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoCnB,YAAY,MAAc,WAAW,MAAM;AAhB3C,SAAA,QAAQ;AAMR,SAAA,mBAAmB;AAGnB,SAAA,kBAAmE;AAQ/D,SAAK,OAAO;AACZ,SAAK,OAAO,IAAI,WAAW,QAAQ;AACnC,SAAK,QAAQ,IAAI,YAAY,QAAQ;AACrC,SAAK,MAAM,IAAI,YAAY,QAAQ;AACnC,SAAK,OA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AA;AAAA,EAKT,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA,EAKhB,YAAY;AAAA;AAAA,EAEZ,WAAW;AAAA;AAAA,EAEX,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA,EAKhB,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA,EAKb,mBAAmB;AAAA;AAAA,EAEnB,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMlB,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA,EAKjB,YAAY;AAChB,CAAC;AAMM,MAAM,WAAW,OAAO,OAAO;AAAA;AAAA,EAElC,oBAAoB;AAAA;AAAA,EAEpB,gBAAgB;AAAA;AAAA,EAEhB,aAAa;AAAA;AAAA,EAEb,cAAc;AAAA;AAAA,EAEd,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA,EAKZ,aAAa;AAAA;AAAA,EAEb,cAAc;AAAA;AAAA,EAEd,aAAa;AAAA;AAAA,EAEb,qBAAqB;AAAA;AAAA,EAErB,qBAAqB;AAAA;AAAA,EAErB,mBAAmB;AACvB,CAAC;"}
|
|
1
|
+
{"version":3,"file":"gml.js","sources":["../src/formats/gml/syntax.ts","../src/formats/gml/styles.ts","../src/formats/gml/exporter.ts","../src/formats/gml/positions.ts","../src/formats/gml/importer.ts","../src/formats/gml/index.ts"],"sourcesContent":["/**\n * The GML lexical layer shared by the importer and the exporter (research note 07 section 2.2,\n * NetworkX readwrite/gml.py as the reference reader): the token list a whole GML text lexes into,\n * the structural validation that guarantees every later walk sees balanced `key value` pairs, the\n * value grammar (int, real, quoted string with `&#NN;` character references, `[ ... ]` record),\n * the NetworkX list conventions (`_networkx_list_start`, `\"[]\"`) and the key charset.\n *\n * Tokens are kept in typed arrays (kind, start, end, line, matching bracket) rather than objects:\n * the token list is the one intermediate structure of the GML importer, and it costs 17 bytes per\n * token instead of an object per node.\n */\n\nimport { SYNTAX_CODE } from \"../../common/codes.js\";\nimport { decodeGmlString } from \"../../common/escape.js\";\nimport { plural } from \"../../common/plural.js\";\n\n/**\n * A bare word: a key, or `INF` / `NAN` at a value position.\n * @category Plugin helpers\n */\nexport const TOKEN_WORD = 0;\n/**\n * An integer literal.\n * @category Plugin helpers\n */\nexport const TOKEN_INT = 1;\n/**\n * A real literal, including the non-finite spellings.\n * @category Plugin helpers\n */\nexport const TOKEN_REAL = 2;\n/**\n * A double-quoted string; start / end delimit the body between the quotes.\n * @category Plugin helpers\n */\nexport const TOKEN_STRING = 3;\n/**\n * `[`.\n * @category Plugin helpers\n */\nexport const TOKEN_OPEN = 4;\n/**\n * `]`.\n * @category Plugin helpers\n */\nexport const TOKEN_CLOSE = 5;\n\n/** The kind of one token. */\ntype TokenKind = 0 | 1 | 2 | 3 | 4 | 5;\n\n/**\n * The NetworkX marker that starts a one-element list written as repeated keys.\n * @category Plugin helpers\n */\nexport const LIST_START_MARKER = \"_networkx_list_start\";\n\n/**\n * The string NetworkX writes for an empty list.\n * @category Plugin helpers\n */\nexport const EMPTY_LIST_TEXT = \"[]\";\n\n/**\n * The string NetworkX writes for an empty tuple, read as an empty list too.\n * @category Plugin helpers\n */\nexport const EMPTY_TUPLE_TEXT = \"()\";\n\n/**\n * The node key the exporter writes a mangled node's original id into (design section 8.5).\n * @category Plugin helpers\n */\nexport const ORIGINAL_ID_KEY = \"graphty_originalId\";\n\n/**\n * The text breaks the format's syntax: a word that is not a key or a number, an unclosed string or `[`, a `]` with no\n * open `[`, or a key without a value. The message says where. The import stops.\n * @category Issue and loss codes\n */\nexport const SYNTAX_STRUCTURE_CODE = SYNTAX_CODE;\n/**\n * The code of an untokenizable bare token (E_SYNTAX).\n * @category Issue and loss codes\n */\nexport const SYNTAX_TOKEN_CODE = SYNTAX_CODE;\n/**\n * The code of an unclosed string (E_SYNTAX).\n * @category Issue and loss codes\n */\nexport const SYNTAX_STRING_CODE = SYNTAX_CODE;\n/**\n * The code of an unclosed `[` (E_SYNTAX).\n * @category Issue and loss codes\n */\nexport const SYNTAX_BRACKET_CODE = SYNTAX_CODE;\n\nconst KEY_TEXT = /^[A-Za-z_]\\w*$/;\nconst STRICT_KEY_TEXT = /^[A-Za-z]\\w*$/;\nconst INT_TEXT = /^[+-]?\\d+$/;\nconst REAL_TEXT = /^[+-]?(?:(?:\\d+\\.\\d*|\\.\\d+)(?:[eE][+-]?\\d+)?|\\d+[eE][+-]?\\d+)$/;\nconst NON_FINITE_TEXT = /^[+-]?(?:inf|infinity|nan)$/i;\nconst NON_FINITE_WORD = /^(?:inf|infinity|nan)$/i;\n\n/**\n * A lexical or structural error of a GML text, with the 1-based line it was found on. The importer\n * turns it into a fatal parse-error issue.\n * @category Plugin helpers\n */\nexport class GmlSyntaxError extends Error {\n /** The issue code. */\n readonly code: string;\n\n /** The 1-based line. */\n readonly line: number;\n\n /**\n * Create a syntax error.\n * @param code - the issue code\n * @param message - a plain-ASCII message\n * @param line - the 1-based line\n */\n constructor(code: string, message: string, line: number) {\n super(message);\n this.name = \"GmlSyntaxError\";\n this.code = code;\n this.line = line;\n }\n}\n\n/**\n * The tokens of one GML text, structurally validated: every `[` has its matching `]` recorded and\n * every key is followed by a value, so walkers need no error paths.\n * @category Plugin helpers\n */\nexport class GmlTokens {\n /** The source text the offsets index into. */\n readonly text: string;\n\n /** The kind of every token. */\n kind: Uint8Array;\n\n /** The start offset of every token (a string's body start). */\n start: Uint32Array;\n\n /** The end offset (exclusive) of every token (a string's body end). */\n end: Uint32Array;\n\n /** The 1-based line of every token. */\n line: Uint32Array;\n\n /** For an open bracket, the index of its matching close bracket; 0 elsewhere. */\n match: Uint32Array;\n\n /** The number of tokens. */\n count = 0;\n\n /**\n * Whether a backslash escapes the next character inside a string (`\\\"`, `\\\\`): set for files OGDF wrote, whose\n * writer escapes quotes that way. Plain GML has no escape mechanism.\n */\n backslashEscapes = false;\n\n /** Called by stringOf() with each named entity it cannot decode and the token's line, when set. */\n onUnknownEntity: ((entity: string, line: number) => void) | null = null;\n\n /**\n * Create an empty token list over a text.\n * @param text - the source text\n * @param capacity - the initial capacity\n */\n constructor(text: string, capacity = 1024) {\n this.text = text;\n this.kind = new Uint8Array(capacity);\n this.start = new Uint32Array(capacity);\n this.end = new Uint32Array(capacity);\n this.line = new Uint32Array(capacity);\n this.match = new Uint32Array(0);\n }\n\n /**\n * Append a token.\n * @param kind - the kind\n * @param start - the start offset\n * @param end - the end offset\n * @param line - the 1-based line\n */\n push(kind: TokenKind, start: number, end: number, line: number): void {\n if (this.count === this.kind.length) {\n this.grow();\n }\n const i = this.count++;\n this.kind[i] = kind;\n this.start[i] = start;\n this.end[i] = end;\n this.line[i] = line;\n }\n\n /**\n * The raw text of a token (a string's body without the quotes, entities undecoded).\n * @param i - the token index\n * @returns the text\n */\n textOf(i: number): string {\n return this.text.slice(this.start[i], this.end[i]);\n }\n\n /**\n * The decoded value of a string token.\n * @param i - the token index\n * @returns the body with character references decoded\n */\n stringOf(i: number): string {\n let text = this.textOf(i);\n if (text.includes(\"\\r\")) {\n // a line break inside a string is part of it, as LF whatever the file's line ends\n text = text.replaceAll(/\\r\\n?/g, \"\\n\");\n }\n if (this.backslashEscapes && text.includes(\"\\\\\")) {\n text = text.replaceAll(/\\\\([\\s\\S])/g, \"$1\");\n }\n if (!text.includes(\"&\")) {\n return text;\n }\n const report = this.onUnknownEntity;\n return decodeGmlString(\n text,\n report === null\n ? undefined\n : (entity) => {\n report(entity, this.line[i]);\n },\n );\n }\n\n /**\n * Whether a token is a `[` or `]`.\n * @param i - the token index\n * @returns true for a bracket\n */\n isBracket(i: number): boolean {\n return this.kind[i] >= TOKEN_OPEN;\n }\n\n /**\n * The index of the pair following the pair whose key is at `key`.\n * @param key - the index of a key token\n * @returns the index after the pair's value (after the matching `]` for a record)\n */\n nextPair(key: number): number {\n const value = key + 1;\n return this.kind[value] === TOKEN_OPEN ? this.match[value] + 1 : value + 1;\n }\n\n /** Double every array. */\n private grow(): void {\n const capacity = this.kind.length * 2;\n const kind = new Uint8Array(capacity);\n kind.set(this.kind);\n this.kind = kind;\n const start = new Uint32Array(capacity);\n start.set(this.start);\n this.start = start;\n const end = new Uint32Array(capacity);\n end.set(this.end);\n this.end = end;\n const line = new Uint32Array(capacity);\n line.set(this.line);\n this.line = line;\n }\n}\n\n/**\n * Lex and structurally validate a whole GML text.\n *\n * Lexical rules (NetworkX): whitespace separates tokens; `#` outside a string starts a comment\n * that runs to the end of the line; a string is delimited by double quotes and may span lines (a\n * line break inside is part of it, GML draft 3.2.5; there is no escape mechanism; `&#NN;`\n * references are decoded later); a U+FEFF between tokens is whitespace; `[` and `]` are\n * single-character tokens; every other run of characters is a key (`[A-Za-z_][0-9A-Za-z_]*`),\n * an integer (`[+-]?[0-9]+`), a real (with a decimal point or an exponent, or `INF` / `NAN` in\n * any case with an optional sign) or an error.\n *\n * Structural rules: the text is a sequence of `key value` pairs where a value is a number, a\n * string, `INF` / `NAN`, or a bracketed sequence of pairs; every `[` has a `]`.\n * @param text - the GML text\n * @returns the validated tokens; GmlSyntaxError with the line of the first problem\n * @category Plugin helpers\n */\nexport function tokenizeGml(text: string): GmlTokens {\n const tokens = new GmlTokens(text, Math.max(1024, text.length >>> 3));\n tokens.backslashEscapes = writtenByOgdf(text);\n const lex: GmlLex = { text, tokens, i: 0, line: 1, spanningLine: 0 };\n while (lex.i < text.length) {\n const c = text.codePointAt(lex.i) ?? 0;\n if (c === 34) {\n lexString(lex);\n } else if (c === 91 || c === 93) {\n tokens.push(c === 91 ? TOKEN_OPEN : TOKEN_CLOSE, lex.i, lex.i + 1, lex.line);\n lex.i++;\n } else if (!skipSpace(lex, c)) {\n lexBare(lex);\n }\n }\n validateStructure(tokens);\n return tokens;\n}\n\n/** Where tokenizeGml() is. */\ninterface GmlLex {\n readonly text: string;\n readonly tokens: GmlTokens;\n /** The offset of the next character. */\n i: number;\n /** The line of the next character. */\n line: number;\n /** The opening line of the first string that spans lines: where a missing quote most likely is; 0 for none. */\n spanningLine: number;\n}\n\n/**\n * Skips one line break, space or comment.\n * @param lex - the lexer\n * @param c - the char code at the offset\n * @returns false when the character starts a token\n */\nfunction skipSpace(lex: GmlLex, c: number): boolean {\n const { text } = lex;\n if (c === 10 || c === 13) {\n lex.line++;\n lex.i++;\n if (c === 13 && lex.i < text.length && text.codePointAt(lex.i) === 10) {\n lex.i++;\n }\n } else if (c === 32 || c === 9 || c === 11 || c === 12 || c === 0xfeff) {\n // a BOM left inside by concatenated files is whitespace; the shared text check reports it\n lex.i++;\n } else if (c === 35) {\n lex.i = endOfLine(text, lex.i);\n } else {\n return false;\n }\n return true;\n}\n\n/**\n * Lexes a string starting at the offset (its opening quote).\n * @param lex - the lexer\n */\nfunction lexString(lex: GmlLex): void {\n const { text, tokens, i } = lex;\n const close = tokens.backslashEscapes ? escapedClose(text, i + 1) : text.indexOf('\"', i + 1);\n if (close < 0) {\n const hint =\n lex.spanningLine === 0\n ? \"\"\n : `; the string opened at line ${lex.spanningLine} spans lines, so a quote may be missing there`;\n throw new GmlSyntaxError(SYNTAX_STRING_CODE, `unclosed string opened at line ${lex.line}${hint}`, lex.line);\n }\n tokens.push(TOKEN_STRING, i + 1, close, lex.line);\n const opened = lex.line;\n for (let k = i + 1; k < close; k++) {\n const d = text.codePointAt(k);\n if (d === 10 || (d === 13 && text.codePointAt(k + 1) !== 10)) {\n lex.line++;\n }\n }\n if (lex.line !== opened && lex.spanningLine === 0) {\n lex.spanningLine = opened;\n }\n lex.i = close + 1;\n}\n\n/**\n * Lexes a bare token (a key, a number) starting at the offset.\n * @param lex - the lexer\n */\nfunction lexBare(lex: GmlLex): void {\n const { text, i } = lex;\n let j = i + 1;\n while (j < text.length && !isDelimiter(text.codePointAt(j) ?? 0)) {\n j++;\n }\n lex.tokens.push(classifyBare(text, i, j, lex.line), i, j, lex.line);\n lex.i = j;\n}\n\n/**\n * Whether OGDF wrote the file: its first key is `Creator \"ogdf::...\"`, after any whitespace and\n * comment lines. A plain scan, so a banner of `#` characters costs time linear in its length.\n * @param text - the GML text\n * @returns true when the file opens with an OGDF creator line\n */\nfunction writtenByOgdf(text: string): boolean {\n const end = Math.min(text.length, 512);\n let i = 0;\n while (i < end) {\n const c = text.codePointAt(i);\n if (c === 35) {\n // '#': a comment runs to the next line break\n while (i < end && text.codePointAt(i) !== 10 && text.codePointAt(i) !== 13) {\n i++;\n }\n } else if (c === 32 || c === 9 || c === 10 || c === 13 || c === 12 || c === 11) {\n i++;\n } else {\n break;\n }\n }\n return /^Creator\\s+\"ogdf::/.test(text.slice(i, i + 64));\n}\n\n/**\n * The offset of the quote closing a string whose backslashes escape the next character, or -1.\n * @param text - the text\n * @param from - the offset after the opening quote\n * @returns the offset of the closing quote\n */\nfunction escapedClose(text: string, from: number): number {\n let k = from;\n while (k < text.length) {\n const c = text.codePointAt(k);\n if (c === 34) {\n return k;\n }\n // a backslash escapes the next character\n k += c === 92 ? 2 : 1;\n }\n return -1;\n}\n\n/**\n * The offset of the line terminator at or after `from`, or the text length.\n * @param text - the text\n * @param from - the offset to search from\n * @returns the offset of the next `\\n` or `\\r`\n */\nfunction endOfLine(text: string, from: number): number {\n const n = text.length;\n for (let i = from; i < n; i++) {\n const c = text.charCodeAt(i);\n if (c === 10 || c === 13) {\n return i;\n }\n }\n return n;\n}\n\n/**\n * Whether a character ends a bare token.\n * @param c - the char code\n * @returns true for whitespace, brackets, a quote or `#`\n */\nfunction isDelimiter(c: number): boolean {\n return (\n c === 32 ||\n c === 9 ||\n c === 10 ||\n c === 13 ||\n c === 11 ||\n c === 12 ||\n c === 91 ||\n c === 93 ||\n c === 34 ||\n c === 35\n );\n}\n\n/**\n * Classify a bare token.\n * @param text - the text\n * @param start - the token start\n * @param end - the token end\n * @param line - the token line, for the error\n * @returns WORD, INT or REAL; GmlSyntaxError for anything else\n */\nfunction classifyBare(text: string, start: number, end: number, line: number): TokenKind {\n const token = text.slice(start, end);\n if (KEY_TEXT.test(token)) {\n return TOKEN_WORD;\n }\n if (INT_TEXT.test(token)) {\n return TOKEN_INT;\n }\n if (REAL_TEXT.test(token) || NON_FINITE_TEXT.test(token)) {\n return TOKEN_REAL;\n }\n // the message is ASCII: a character outside it is shown as \\uXXXX and named, since it may look\n // like something else (a no-break space pasted from a web page looks like a space)\n const hex = (c: string): string => (c.codePointAt(0) ?? 0).toString(16).toUpperCase().padStart(4, \"0\");\n const head = token.length > 20 ? `${token.slice(0, 20)}...` : token;\n const shown = head.replaceAll(/[^\\x20-\\x7e]/gu, (c) => String.raw`\\u` + hex(c));\n const odd = /[^\\x21-\\x7e]/u.exec(token);\n const note = odd === null ? \"\" : ` (it holds U+${hex(odd[0])}, which GML allows only inside a string)`;\n throw new GmlSyntaxError(SYNTAX_TOKEN_CODE, `cannot tokenize \"${shown}\" at line ${line}${note}`, line);\n}\n\n/**\n * Check the `key value` structure and record the matching bracket of every `[`.\n * @param tokens - the lexed tokens\n */\nfunction validateStructure(tokens: GmlTokens): void {\n const { count, kind } = tokens;\n const match = new Uint32Array(count);\n const stack: number[] = [];\n let i = 0;\n while (i < count) {\n const k = kind[i];\n if (k === TOKEN_CLOSE) {\n const open = stack.pop();\n if (open === undefined) {\n throw new GmlSyntaxError(\n SYNTAX_STRUCTURE_CODE,\n `unexpected \"]\" at line ${tokens.line[i]}: no open \"[\"`,\n tokens.line[i],\n );\n }\n match[open] = i;\n i++;\n continue;\n }\n if (k !== TOKEN_WORD) {\n throw new GmlSyntaxError(\n SYNTAX_STRUCTURE_CODE,\n `expected a key at line ${tokens.line[i]}, found ${describeToken(tokens, i)}`,\n tokens.line[i],\n );\n }\n const value = i + 1;\n if (value >= count) {\n throw new GmlSyntaxError(\n SYNTAX_STRUCTURE_CODE,\n `key \"${tokens.textOf(i)}\" at line ${tokens.line[i]} has no value`,\n tokens.line[i],\n );\n }\n if (checkValue(tokens, i) === TOKEN_OPEN) {\n stack.push(value);\n }\n i = value + 1;\n }\n if (stack.length > 0) {\n const open = stack[stack.length - 1];\n throw new GmlSyntaxError(\n SYNTAX_BRACKET_CODE,\n `unexpected end of input: ${stack.length} bracket${plural(stack.length)} still open, the last opened at line ${tokens.line[open]}`,\n tokens.line[open],\n );\n }\n tokens.match = match;\n}\n\n/**\n * Checks the value of a key: a number, a string, `INF` / `NAN` or an opening bracket. Gephi writes its name\n * unquoted (`Creator Gephi`): the word is read as the string it means.\n * @param tokens - the lexed tokens\n * @param key - the key's token index (its value follows it)\n * @returns the value's kind\n */\nfunction checkValue(tokens: GmlTokens, key: number): TokenKind {\n const { kind } = tokens;\n const value = key + 1;\n const word = kind[value] === TOKEN_WORD && !NON_FINITE_WORD.test(tokens.textOf(value));\n if (word && tokens.textOf(key) === \"Creator\") {\n kind[value] = TOKEN_STRING;\n return TOKEN_STRING;\n }\n if (kind[value] === TOKEN_CLOSE || word) {\n throw new GmlSyntaxError(\n SYNTAX_STRUCTURE_CODE,\n `expected a value for key \"${tokens.textOf(key)}\" at line ${tokens.line[key]}, found ${describeToken(tokens, value)}`,\n tokens.line[value],\n );\n }\n return kind[value] as TokenKind;\n}\n\n/**\n * A short description of a token for messages.\n * @param tokens - the tokens\n * @param i - the token index\n * @returns the quoted text or the bracket\n */\nfunction describeToken(tokens: GmlTokens, i: number): string {\n switch (tokens.kind[i]) {\n case TOKEN_OPEN:\n return '\"[\"';\n case TOKEN_CLOSE:\n return '\"]\"';\n case TOKEN_STRING:\n return `the string \"${tokens.textOf(i)}\"`;\n default:\n return `\"${tokens.textOf(i)}\"`;\n }\n}\n\n/**\n * The numeric value of an INT or REAL token (or a WORD that is `INF` / `NAN` at a value position).\n * @param text - the token text\n * @returns the number; Infinity / -Infinity / NaN for the non-finite spellings\n * @category Plugin helpers\n */\nexport function numberOfText(text: string): number {\n if (NON_FINITE_TEXT.test(text)) {\n const lower = text.toLowerCase();\n if (lower.endsWith(\"nan\")) {\n return Number.NaN;\n }\n return lower.startsWith(\"-\") ? -Infinity : Infinity;\n }\n return Number(text);\n}\n\n/**\n * Whether a value token is one of the non-finite bare words (`INF`, `NAN`), which lex as words.\n * @param tokens - the tokens\n * @param i - the value token index\n * @returns true when the word is a real\n * @category Plugin helpers\n */\nexport function isNonFiniteWord(tokens: GmlTokens, i: number): boolean {\n return tokens.kind[i] === TOKEN_WORD && NON_FINITE_WORD.test(tokens.textOf(i));\n}\n\n/**\n * Whether a text is a GML key the strict grammar accepts (`[A-Za-z][0-9A-Za-z_]*`, what NetworkX\n * writes and reads).\n * @param text - the candidate key\n * @returns true when it can be written as a key\n * @category Plugin helpers\n */\nexport function isGmlKey(text: string): boolean {\n return STRICT_KEY_TEXT.test(text);\n}\n\n/**\n * Keys rewritten under sanitizeKeys \"mangle\", or a data column renamed because its key would read back as one of\n * graphty's style values.\n * @category Issue and loss codes\n */\nexport const KEY_MANGLED_CODE = \"W_GML_KEY_MANGLED\";\n\n/**\n * Rewrite a text as a GML key: every character outside `[0-9A-Za-z_]` becomes `_` and a leading\n * non-letter is prefixed with `x` (the exporter's `sanitizeKeys: \"mangle\"`).\n * @param text - the text\n * @returns a valid key\n * @category Plugin helpers\n */\nexport function mangleGmlKey(text: string): string {\n const body = text.replaceAll(/\\W/g, \"_\");\n return /^[A-Za-z]/.test(body) ? body : `x${body}`;\n}\n\n/** One open record while parseRecord() walks the tokens without recursion. */\ninterface RecordFrame {\n readonly record: Record<string, unknown>;\n listKeys: Set<string> | null;\n /** The index of the record's `]`. */\n readonly close: number;\n /** The next key token to read. */\n next: number;\n /** The key the record is stored under in its parent, or null for the root. */\n readonly key: string | null;\n}\n\n/**\n * Parse a bracketed record into a JSON object (design section 8.5: nested GML records map to\n * `json`). Values follow the value grammar; repeated keys become arrays with the NetworkX\n * conventions: the `_networkx_list_start` marker starts a list so a one-element list survives,\n * `\"[]\"` and `\"()\"` are empty lists, and a key seen twice without the marker becomes a\n * two-element array. Nested records are walked with an explicit stack, so the nesting depth is\n * bounded by memory, not by the call stack.\n * @param tokens - the validated tokens\n * @param open - the index of the record's `[`\n * @returns a null-prototype object\n * @category Plugin helpers\n */\nexport function parseRecord(tokens: GmlTokens, open: number): Record<string, unknown> {\n const root = Object.create(null) as Record<string, unknown>;\n const stack: RecordFrame[] = [\n { record: root, listKeys: null, close: tokens.match[open], next: open + 1, key: null },\n ];\n while (stack.length > 0) {\n const frame = stack[stack.length - 1];\n if (frame.next >= frame.close) {\n stack.pop();\n if (frame.key !== null) {\n storeValue(stack[stack.length - 1], frame.key, frame.record);\n }\n continue;\n }\n const p = frame.next;\n frame.next = tokens.nextPair(p);\n const key = tokens.textOf(p);\n const v = p + 1;\n if (tokens.kind[v] === TOKEN_STRING) {\n storeString(frame, key, tokens.stringOf(v));\n } else if (tokens.kind[v] === TOKEN_OPEN) {\n stack.push({\n record: Object.create(null) as Record<string, unknown>,\n listKeys: null,\n close: tokens.match[v],\n next: v + 1,\n key,\n });\n } else {\n storeValue(frame, key, numberOfText(tokens.textOf(v)));\n }\n }\n return root;\n}\n\n/**\n * Store a string value: the list-start marker opens an empty list for the key, the empty list and\n * tuple texts store an empty list, anything else stores the text.\n * @param frame - the open record\n * @param key - the key\n * @param text - the string\n */\nfunction storeString(frame: RecordFrame, key: string, text: string): void {\n if (text === LIST_START_MARKER) {\n frame.record[key] = [];\n frame.listKeys ??= new Set();\n frame.listKeys.add(key);\n return;\n }\n storeValue(frame, key, text === EMPTY_LIST_TEXT || text === EMPTY_TUPLE_TEXT ? [] : text);\n}\n\n/**\n * Store one value under a key: appended to the key's list when the key is a list, paired with the\n * earlier value when the key repeats, set otherwise.\n * @param frame - the open record\n * @param key - the key\n * @param value - the value\n */\nfunction storeValue(frame: RecordFrame, key: string, value: unknown): void {\n const { record } = frame;\n if (frame.listKeys?.has(key)) {\n (record[key] as unknown[]).push(value);\n } else if (key in record) {\n record[key] = [record[key], value];\n frame.listKeys ??= new Set();\n frame.listKeys.add(key);\n } else {\n record[key] = value;\n }\n}\n\n/**\n * The JSON value of a non-string value token: a number, or a record.\n * @param tokens - the tokens\n * @param v - the value token index (INT, REAL, non-finite WORD or OPEN)\n * @returns the value\n * @category Plugin helpers\n */\nexport function scalarOrRecord(tokens: GmlTokens, v: number): unknown {\n return tokens.kind[v] === TOKEN_OPEN ? parseRecord(tokens, v) : numberOfText(tokens.textOf(v));\n}\n","/**\n * GML styles: each node's and edge's `graphics [ ... ]` and `LabelGraphics [ ... ]` records read the way the program\n * that wrote the file draws them, and a graph's styles written back as yEd GML graphics.\n *\n * GML has one syntax and many vocabularies. The `Creator` line (top level, or inside the graph as Gephi writes it,\n * quoted or not) names the writer: yEd and yFiles, Cytoscape, Gephi, OGDF and igraph are recognized; every other file\n * (NetworkX writes no `Creator`) is read with the keys of the GML draft (Graphlet). A recognized drawing program's\n * defaults go beneath the file's own values; igraph and unknown writers get none.\n *\n * Writing: the yEd keys (`fill`, `outline`, `outlineWidth`, `outlineStyle`, `w`, `h`, `type`; edge `fill`, `width`,\n * `style`, `sourceArrow`, `targetArrow`, `smoothBends`; `LabelGraphics` `text`, `color`, `fontSize`, `fontName`,\n * `fontStyle`) replace every style key any reader here reads, inside the records the graph already has, so positions,\n * bends and other keys stay. The `graphty.styles` block and the per-element values its rules read are keys too,\n * named by the GML writer's rule for names that are not GML keys (`graphty_styles`, `graphty_style_node_<key>`).\n */\n\nimport type { GraphSnapshot } from \"@graphty/graph-format\";\n\nimport { type BendPoint, bendsToPoints, canonBends } from \"../../styles/canon/bends.js\";\nimport { canonColor, colorOpacity } from \"../../styles/canon/color.js\";\nimport { canonEnum } from \"../../styles/canon/enums.js\";\nimport { canonNumber } from \"../../styles/canon/number.js\";\nimport { type CanonSite, MAX_STYLE_VALUE_LENGTH, noteAt, scalarText } from \"../../styles/canon/site.js\";\nimport { canonText } from \"../../styles/canon/text.js\";\nimport { STYLE_ISSUE } from \"../../styles/codes.js\";\nimport { CYTOSCAPE_LEXICON } from \"../../styles/cytoscape/lexicon.js\";\nimport { StyleApproximations } from \"../../styles/io/approximations.js\";\nimport {\n blockStyles,\n parseStyleBlock,\n STYLE_BLOCK_NAME,\n styleBlockLosses,\n styleTag,\n writeStyleBlock,\n} from \"../../styles/io/block.js\";\nimport { dataRead, type ExporterStyleInput } from \"../../styles/io/writer.js\";\nimport { StyleNotes } from \"../../styles/notes.js\";\nimport { styleFingerprint } from \"../../styles/plan/features.js\";\nimport { plainCell, resolveStyles } from \"../../styles/plan/resolve.js\";\nimport type {\n ImporterStyles,\n StyleColumn,\n StyleDialect,\n StyleReadContext,\n StyleTarget,\n StyleTool,\n StyleValue,\n StyleWriteCapabilities,\n} from \"../../styles/types.js\";\nimport type { LossNote } from \"../../types.js\";\nimport { gephiRules } from \"../gexf/styles.js\";\nimport {\n flowchartShape,\n FONT_STYLES,\n type ValueColumns,\n valueColumns,\n YED_ARROWS,\n YED_LINES,\n YED_SHAPES,\n yedColor,\n yedSpelled,\n yedValue,\n} from \"../graphml/styles-yed.js\";\nimport { KEY_MANGLED_CODE, mangleGmlKey } from \"./syntax.js\";\n\n/** A GML record as the importer keeps it (a json cell). */\ntype Rec = Record<string, unknown>;\n\n/** The key vocabulary a file's graphics are read with. */\ntype Vocabulary = \"yed\" | \"cytoscape\" | \"ogdf\" | \"graphlet\";\n\n/** Who wrote a GML file, as far as its styles go. */\ninterface GmlWriter {\n /** The dialect recorded in the styles. */\n readonly dialect: StyleDialect;\n /** The program whose defaults apply, or null. */\n readonly tool: StyleTool | null;\n /** The keys its graphics are read with. */\n readonly vocabulary: Vocabulary;\n /** How its colors and names are spelled. */\n readonly spelling: StyleDialect;\n /** The unit of its lengths. */\n readonly units: \"px\" | \"relative\";\n /** Whether it draws the `label` key of an element that has graphics (the GML draft does; yEd and Gephi do not). */\n readonly labelKey: boolean;\n}\n\n/** The writers recognized by their `Creator` text, first match wins. */\nconst WRITERS: readonly (readonly [RegExp, GmlWriter])[] = [\n [\n /^\\s*(yfiles|yed)\\b/i,\n { dialect: \"yed\", tool: \"yed\", vocabulary: \"yed\", spelling: \"yed\", units: \"px\", labelKey: false },\n ],\n [\n /^\\s*cytoscape\\b/i,\n {\n dialect: \"cytoscape\",\n tool: \"cytoscape\",\n vocabulary: \"cytoscape\",\n spelling: \"cytoscape\",\n units: \"px\",\n labelKey: true,\n },\n ],\n [\n /^\\s*gephi\\b/i,\n {\n dialect: \"gephi\",\n tool: \"gephi\",\n vocabulary: \"graphlet\",\n spelling: \"css\",\n units: \"relative\",\n labelKey: false,\n },\n ],\n [\n /^\\s*ogdf::/i,\n { dialect: \"ogdf\", tool: \"ogdf\", vocabulary: \"ogdf\", spelling: \"css\", units: \"px\", labelKey: true },\n ],\n // igraph writes a Creator line, but no drawing defaults of igraph's are stated by a primary source\n [\n /^\\s*igraph\\b/i,\n { dialect: \"igraph\", tool: null, vocabulary: \"graphlet\", spelling: \"css\", units: \"px\", labelKey: true },\n ],\n];\n\n/** Any other writer (NetworkX, SNDlib, hand-written files): the GML draft's keys, no defaults. */\nconst UNKNOWN_WRITER: GmlWriter = {\n dialect: \"gml\",\n tool: null,\n vocabulary: \"graphlet\",\n spelling: \"css\",\n units: \"px\",\n labelKey: true,\n};\n\n/** A file graphty wrote: yEd keys, and the `graphty.styles` block gives the rules. */\nconst GRAPHTY_WRITER: GmlWriter = { ...WRITERS[0][1], tool: null };\n\n/**\n * The graph key holding the `graphty.styles` block: the block's name under the GML writer's rule for names that are\n * not GML keys.\n * @category Built-in formats\n */\nexport const GML_STYLE_BLOCK_KEY = mangleGmlKey(STYLE_BLOCK_NAME);\n\n/** The key prefix of the per-element style values (`graphty.style.` under the same rule). */\nconst TAG_PREFIX = mangleGmlKey(\"graphty.style.\");\n\n/**\n * The GML key of one style column's per-element values.\n * @param target - nodes or edges\n * @param key - the style column's key\n * @returns the key\n */\nfunction tagKey(target: StyleTarget, key: string): string {\n return mangleGmlKey(styleTag(target, key));\n}\n\n/**\n * A graph value as text, or null.\n * @param snapshot - the graph\n * @param name - the graph column\n * @returns the text\n */\nfunction graphText(snapshot: GraphSnapshot, name: string): string | null {\n if (!snapshot.graph.has(name)) {\n return null;\n }\n const v = plainCell(snapshot.graph.value(name, 0));\n if (typeof v === \"string\") {\n return v;\n }\n return typeof v === \"number\" ? String(v) : null;\n}\n\n/**\n * Who wrote a GML file: the `Creator` line (top level, or a key of the graph block as Gephi writes it), or graphty when\n * the file holds a `graphty.styles` block.\n * @param snapshot - the graph\n * @returns the writer\n */\nfunction writerOf(snapshot: GraphSnapshot): GmlWriter {\n if (snapshot.graph.has(GML_STYLE_BLOCK_KEY)) {\n return GRAPHTY_WRITER;\n }\n const creator = snapshot.meta.creator ?? graphText(snapshot, \"Creator\") ?? \"\";\n for (const [pattern, writer] of WRITERS) {\n if (pattern.test(creator)) {\n return writer;\n }\n }\n return UNKNOWN_WRITER;\n}\n\n// ============================================================ reading\n\n/** One element's canonical value of a property; null leaves it unset. */\ntype Put = (property: string, value: StyleValue | null) => void;\n\n/** Where a value of an element was read, by property. */\ntype At = (property: string) => CanonSite;\n\n/** The edge's `arrow` key of the GML draft: which ends have an arrow. */\nconst ARROW_ENDS: ReadonlyMap<string, readonly [string, string]> = new Map([\n [\"none\", [\"none\", \"none\"]],\n [\"last\", [\"none\", \"triangle\"]],\n [\"first\", [\"triangle\", \"none\"]],\n [\"both\", [\"triangle\", \"triangle\"]],\n]);\n\n/** OGDF's stroke types (`stipple`), by number. */\nconst OGDF_STROKES: readonly string[] = [\"none\", \"solid\", \"dashed\", \"dotted\", \"dash-dot\", \"dash-dot\"];\n\n/** OGDF's shape names the common table does not know. */\nconst OGDF_SHAPES: ReadonlyMap<string, string> = new Map([\n [\"rect\", \"rectangle\"],\n [\"rhomb\", \"diamond\"],\n [\"trapeze\", \"trapezoid\"],\n [\"invtrapeze\", \"trapezoid\"],\n [\"invtriangle\", \"triangle\"],\n [\"invparallelogram\", \"parallelogram\"],\n]);\n\n/** Keys only yEd writes in a label record: its `fill` is the label's background, not the text color. */\nconst YED_LABEL_KEYS: readonly string[] = [\n \"outline\",\n \"autoSizePolicy\",\n \"model\",\n \"configuration\",\n \"borderDistance\",\n \"modelName\",\n \"modelPosition\",\n];\n\n/** Cytoscape's legacy numbered arrows (`source_arrow 3`), read as Cytoscape reads them. */\nconst cytoscapeArrow = CYTOSCAPE_LEXICON.edge.get(\"targetArrow\")?.[0]?.[1];\n\n/**\n * A short sample of a value for a note.\n * @param raw - the value\n * @returns its text, or \"a record\" for a record\n */\nfunction sampleOf(raw: unknown): string {\n return typeof raw === \"string\" || typeof raw === \"number\"\n ? String(raw).slice(0, MAX_STYLE_VALUE_LENGTH)\n : \"a record\";\n}\n\n/**\n * Whether a value is a GML record.\n * @param v - the value\n * @returns true for a non-array object\n */\nfunction isRec(v: unknown): v is Rec {\n return typeof v === \"object\" && v !== null && !Array.isArray(v);\n}\n\n/**\n * The first defined value of some keys of a record.\n * @param r - the record\n * @param keys - the keys, in order of preference\n * @returns the value, or undefined\n */\nfunction first(r: Rec, ...keys: string[]): unknown {\n for (const k of keys) {\n if (Object.hasOwn(r, k) && r[k] !== undefined) {\n return r[k];\n }\n }\n return undefined;\n}\n\n/**\n * Reads a color and its alpha.\n * @param raw - the value\n * @param property - the color property\n * @param opacity - its opacity property, or null\n * @param writer - the writer\n * @param put - receives the values\n * @param at - the sites\n */\nfunction readColor(raw: unknown, property: string, opacity: string | null, writer: GmlWriter, put: Put, at: At): void {\n if (raw === undefined) {\n return;\n }\n const c = canonColor(raw, writer.spelling, at(property));\n if (c === null) {\n return;\n }\n put(property, c.color);\n const alpha = colorOpacity(c, null, at(property), opacity !== null);\n if (opacity !== null) {\n put(opacity, alpha);\n }\n}\n\n/**\n * A stroke style: OGDF's numbered `stipple`, or a line type name.\n * @param raw - the value\n * @param kind - border or line style\n * @param writer - the writer\n * @param at - the site\n * @returns the style, or null\n */\nfunction strokeStyle(raw: unknown, kind: \"borderStyle\" | \"lineStyle\", writer: GmlWriter, at: CanonSite): string | null {\n if (raw === undefined) {\n return null;\n }\n if (writer.vocabulary === \"ogdf\") {\n const stroke = OGDF_STROKES[Number(raw)] as string | undefined;\n if (stroke === undefined || stroke === \"none\") {\n noteAt(at, STYLE_ISSUE.UNKNOWN_VALUE, sampleOf(raw));\n return null;\n }\n return stroke;\n }\n return canonEnum(kind, raw, writer.spelling, at);\n}\n\n/**\n * Reads one node's `graphics` record.\n * @param g - the record\n * @param writer - the writer\n * @param put - receives the values\n * @param at - the sites\n */\nfunction readNodeGraphics(g: Rec, writer: GmlWriter, put: Put, at: At): void {\n const v = writer.vocabulary;\n readNodeFill(g, writer, put, at);\n readNodeOutline(g, writer, put, at);\n put(\n \"borderStyle\",\n strokeStyle(v === \"ogdf\" ? g.stipple : g.outlineStyle, \"borderStyle\", writer, at(\"borderStyle\")),\n );\n put(\"width\", g.w === undefined ? null : canonNumber(g.w, at(\"width\")));\n put(\"height\", g.h === undefined ? null : canonNumber(g.h, at(\"height\")));\n if (g.type !== undefined) {\n const raw =\n v === \"ogdf\" && typeof g.type === \"string\" ? (OGDF_SHAPES.get(g.type.toLowerCase()) ?? g.type) : g.type;\n put(\"shape\", canonEnum(\"shape\", raw, writer.spelling, at(\"shape\")));\n } else if (v === \"yed\" && typeof g.customconfiguration === \"string\") {\n // yEd's flowchart palette keeps a node's shape as a configuration, not a `type`.\n put(\"shape\", flowchartShape(g.customconfiguration));\n }\n}\n\n/**\n * Reads the fill of one node's `graphics` record.\n * @param g - the record\n * @param writer - the writer\n * @param put - receives the values\n * @param at - the sites\n */\nfunction readNodeFill(g: Rec, writer: GmlWriter, put: Put, at: At): void {\n if (writer.vocabulary === \"yed\" && Number(g.hasFill) === 0) {\n noteAt(at(\"fill\"), STYLE_ISSUE.NO_FILL, \"hasFill 0\");\n put(\"fillOpacity\", 0);\n return;\n }\n readColor(g.fill, \"fill\", \"fillOpacity\", writer, put, at);\n if (g.fill2 !== undefined) {\n noteAt(at(\"fill\"), STYLE_ISSUE.GRADIENT, sampleOf(g.fill2));\n }\n}\n\n/**\n * Reads the outline color and width of one node's `graphics` record.\n * @param g - the record\n * @param writer - the writer\n * @param put - receives the values\n * @param at - the sites\n */\nfunction readNodeOutline(g: Rec, writer: GmlWriter, put: Put, at: At): void {\n const v = writer.vocabulary;\n if (v === \"yed\" && Number(g.hasOutline) === 0) {\n put(\"borderWidth\", 0);\n return;\n }\n readColor(v === \"ogdf\" ? g.line : g.outline, \"borderColor\", null, writer, put, at);\n const width = outlineWidthOf(g, v);\n put(\"borderWidth\", width === undefined ? null : canonNumber(width, at(\"borderWidth\")));\n}\n\n/**\n * The outline width of a node's `graphics` record, under the key its writer uses.\n * @param g - the record\n * @param v - the writer's vocabulary\n * @returns the raw width, or undefined\n */\nfunction outlineWidthOf(g: Rec, v: GmlWriter[\"vocabulary\"]): unknown {\n switch (v) {\n case \"yed\":\n return g.outlineWidth;\n case \"cytoscape\":\n return first(g, \"outline_width\", \"width\");\n case \"ogdf\":\n return g.lineWidth;\n default:\n return first(g, \"width\", \"outlineWidth\");\n }\n}\n\n/**\n * Reads one edge's `graphics` record.\n * @param g - the record\n * @param writer - the writer\n * @param put - receives the values\n * @param at - the sites\n */\nfunction readEdgeGraphics(g: Rec, writer: GmlWriter, put: Put, at: At): void {\n const v = writer.vocabulary;\n readColor(g.fill, \"color\", \"opacity\", writer, put, at);\n const width = v === \"ogdf\" ? first(g, \"lineWidth\", \"width\") : g.width;\n put(\"width\", width === undefined ? null : canonNumber(width, at(\"width\")));\n put(\"lineStyle\", strokeStyle(v === \"ogdf\" ? g.stipple : g.style, \"lineStyle\", writer, at(\"lineStyle\")));\n if (typeof g.arrow === \"string\") {\n const ends = ARROW_ENDS.get(g.arrow.trim().toLowerCase());\n if (ends === undefined) {\n noteAt(at(\"targetArrow\"), STYLE_ISSUE.UNKNOWN_VALUE, g.arrow.slice(0, MAX_STYLE_VALUE_LENGTH));\n } else {\n put(\"sourceArrow\", ends[0]);\n put(\"targetArrow\", ends[1]);\n }\n }\n for (const [keys, property] of [\n [[\"sourceArrow\", \"source_arrow\"], \"sourceArrow\"],\n [[\"targetArrow\", \"target_arrow\"], \"targetArrow\"],\n ] as const) {\n const raw = first(g, ...keys);\n if (raw === undefined) {\n continue;\n }\n put(\n property,\n v === \"cytoscape\" && cytoscapeArrow !== undefined\n ? cytoscapeArrow(raw, at(property))\n : canonEnum(\"arrow\", raw, writer.spelling, at(property)),\n );\n }\n if (v === \"yed\") {\n readYedCurve(g, put);\n }\n}\n\n/**\n * Reads whether yEd draws an edge curved: `smoothBends` rounds the bends of its `Line`, whose points run from the\n * source through the bends to the target, so a line of two points (or none) stays straight.\n * @param g - the edge's `graphics` record\n * @param put - receives the value\n */\nfunction readYedCurve(g: Rec, put: Put): void {\n if (g.smoothBends !== undefined) {\n const points = isRec(g.Line) ? g.Line.point : undefined;\n put(\"curved\", Number(g.smoothBends) === 1 && Array.isArray(points) && points.length > 2);\n }\n}\n\n/**\n * Reads an element's label records: the first visible one with text; further visible ones are noted.\n * @param raw - the `LabelGraphics` value (one record or several)\n * @param writer - the writer\n * @param put - receives the values\n * @param at - the sites\n */\nfunction readLabelGraphics(raw: unknown, writer: GmlWriter, put: Put, at: At): void {\n const visible = (Array.isArray(raw) ? raw : [raw]).filter((l): l is Rec => isRec(l) && Number(l.visible) !== 0);\n const lg = visible.at(0);\n if (lg === undefined) {\n return;\n }\n const extra = visible.slice(1).filter((l) => l.text !== undefined).length;\n if (extra > 0) {\n noteAt(at(\"label\"), STYLE_ISSUE.EXTRA_LABELS, `${String(extra + 1)} labels`);\n }\n if (lg.text !== undefined) {\n put(\"label\", canonText(lg.text, at(\"label\")));\n }\n // the GML draft's `fill` is the text color; yEd's is the label's background box, its `color` the text color\n const yedLabel = writer.vocabulary === \"yed\" || YED_LABEL_KEYS.some((k) => Object.hasOwn(lg, k));\n if (lg.color !== undefined) {\n readColor(lg.color, \"labelColor\", null, writer, put, at);\n } else if (lg.fill !== undefined && !yedLabel) {\n readColor(lg.fill, \"labelColor\", null, writer, put, at);\n }\n if (lg.fill !== undefined && yedLabel) {\n noteAt(at(\"label\"), STYLE_ISSUE.NOT_CARRIED, \"label background\");\n }\n readLabelFont(lg, put, at);\n}\n\n/**\n * Reads a label record's font: its size, name, weight and slant.\n * @param lg - the record\n * @param put - receives the values\n * @param at - the sites\n */\nfunction readLabelFont(lg: Rec, put: Put, at: At): void {\n put(\"labelSize\", lg.fontSize === undefined ? null : canonNumber(lg.fontSize, at(\"labelSize\")));\n put(\"labelFont\", lg.fontName === undefined ? null : canonText(lg.fontName, at(\"labelFont\")));\n const style = scalarText(lg.fontStyle, at(\"labelWeight\"))?.trim().toLowerCase();\n if (style !== undefined) {\n const known = FONT_STYLES.get(style);\n if (known === undefined) {\n noteAt(at(\"labelWeight\"), STYLE_ISSUE.UNKNOWN_VALUE, style.slice(0, MAX_STYLE_VALUE_LENGTH));\n } else {\n put(\"labelWeight\", known[0]);\n put(\"labelItalic\", known[1]);\n }\n }\n}\n\n/**\n * Reads one element: its `graphics` and `LabelGraphics`, and the `label` key where the writer draws it.\n * @param target - nodes or edges\n * @param g - the graphics value\n * @param lg - the LabelGraphics value\n * @param label - the `label` key's value\n * @param writer - the writer\n * @param put - receives the values\n * @param at - the sites\n */\nfunction readElement(\n target: StyleTarget,\n g: unknown,\n lg: unknown,\n label: unknown,\n writer: GmlWriter,\n put: Put,\n at: At,\n): void {\n let text = false;\n const putLabel: Put = (property, value) => {\n text ||= property === \"label\" && value !== null;\n put(property, value);\n };\n if (isRec(g)) {\n (target === \"node\" ? readNodeGraphics : readEdgeGraphics)(g, writer, put, at);\n }\n if (lg !== null && lg !== undefined) {\n readLabelGraphics(lg, writer, putLabel, at);\n }\n // the GML draft draws the label key; Cytoscape reads it as the node's name, which its default style shows\n const drawn =\n writer.vocabulary === \"cytoscape\" ? target === \"node\" : writer.labelKey && (isRec(g) || lg !== undefined);\n if (!text && drawn && label !== null && label !== undefined) {\n put(\"label\", canonText(label, at(\"label\")));\n }\n}\n\n/**\n * The value of a column, or undefined when the table has no such column.\n * @param table - the node or edge table\n * @param name - the column\n * @param i - the row\n * @returns the value\n */\nfunction cellOf(table: GraphSnapshot[\"nodes\"], name: string, i: number): unknown {\n if (!table.has(name)) {\n return undefined;\n }\n const v = plainCell(table.value(name, i));\n return v ?? undefined;\n}\n\n/**\n * A node's center: the `graphics` `x` and `y` the importer moved into the position column.\n * @param snapshot - the graph\n * @param i - the node's index\n * @returns the center; NaN where the node has none\n */\nfunction centerOf(snapshot: GraphSnapshot, i: number): BendPoint {\n const column = snapshot.nodes.byRole(\"position\");\n const v = column?.isSet(i) === true ? (column.value(i) as ArrayLike<number>) : null;\n return v === null ? [Number.NaN, Number.NaN] : [v[0], v[1]];\n}\n\n/**\n * An edge's bends: the points of its `graphics` `Line` between the first and the last, which are where it leaves\n * the source and meets the target.\n * @param snapshot - the graph\n * @param g - the edge's `graphics` value\n * @param e - the edge's row\n * @returns the `bends` value, or null without bends\n */\nfunction lineBends(snapshot: GraphSnapshot, g: unknown, e: number): string | null {\n const raw = isRec(g) && isRec(g.Line) ? g.Line.point : undefined;\n if (!Array.isArray(raw) || raw.length < 3) {\n return null;\n }\n const points = raw.slice(1, -1).map((p): BendPoint => (isRec(p) ? [Number(p.x), Number(p.y)] : [Number.NaN, 0]));\n return canonBends(\n centerOf(snapshot, snapshot.edgeSource(e)),\n centerOf(snapshot, snapshot.edgeTarget(e)),\n points,\n true,\n );\n}\n\n/**\n * Every element's values, read with a writer's vocabulary.\n * @param snapshot - the graph\n * @param writer - the writer\n * @param notes - where problems are noted\n * @param context - the work budget\n * @returns the values per target, and whether anything was read\n */\nfunction readValues(\n snapshot: GraphSnapshot,\n writer: GmlWriter,\n notes: StyleNotes,\n context: Pick<StyleReadContext, \"budget\">,\n): { readonly node: ValueColumns; readonly edge: ValueColumns; readonly found: boolean } {\n let found = false;\n const read = (target: StyleTarget): ValueColumns => {\n const table = target === \"node\" ? snapshot.nodes : snapshot.edges;\n const n = target === \"node\" ? snapshot.nodeCount : snapshot.edgeCount;\n const out = valueColumns(n);\n if (!table.has(\"graphics\") && !table.has(\"LabelGraphics\") && writer.vocabulary !== \"cytoscape\") {\n return out.values;\n }\n for (let i = 0; i < n; i++) {\n context.budget.spend(target, 1);\n const at: At = (property) => ({ notes, target, property, element: i, budget: context.budget });\n readElement(\n target,\n cellOf(table, \"graphics\", i),\n cellOf(table, \"LabelGraphics\", i),\n cellOf(table, \"label\", i),\n writer,\n (property, value) => {\n if (value !== null) {\n found = true;\n out.put(i, property, value);\n }\n },\n at,\n );\n if (target === \"edge\") {\n const bends = lineBends(snapshot, cellOf(table, \"graphics\", i), i);\n if (bends !== null) {\n found = true;\n out.put(i, \"bends\", bends);\n }\n }\n }\n return out.values;\n };\n const node = read(\"node\");\n const edge = read(\"edge\");\n return { node, edge, found };\n}\n\n/**\n * The `graphty.styles` block of a file graphty wrote, with the per-element values its rules read moved inside it from\n * their `graphty_style_*` keys; the block as written when it is ignored anyway (graph-io then says why).\n * @param snapshot - the graph\n * @param text - the block's text\n * @returns the block's text for graph-io to read\n */\nfunction blockWithValues(snapshot: GraphSnapshot, text: string): string {\n const parsed = parseStyleBlock(text, styleFingerprint(snapshot));\n if (!parsed.ok || parsed.block.values !== undefined) {\n return text;\n }\n const node = tagValues(snapshot, \"node\", parsed.block.columns.node);\n const edge = tagValues(snapshot, \"edge\", parsed.block.columns.edge);\n if (node === null || edge === null) {\n // a style column is missing: graph-io ignores the block with a note\n return text;\n }\n const raw = JSON.parse(text) as Record<string, unknown>;\n return JSON.stringify({ ...raw, values: { node, edge } });\n}\n\n/**\n * The per-element values of a target's style columns, read from their `graphty_style_*` keys.\n * @param snapshot - the graph\n * @param target - nodes or edges\n * @param keys - the style columns the block names\n * @returns the values by key, or null when a key is missing\n */\nfunction tagValues(\n snapshot: GraphSnapshot,\n target: StyleTarget,\n keys: readonly string[],\n): Record<string, StyleColumn> | null {\n const table = target === \"node\" ? snapshot.nodes : snapshot.edges;\n const n = target === \"node\" ? snapshot.nodeCount : snapshot.edgeCount;\n const values: Record<string, StyleColumn> = {};\n for (const key of keys) {\n const name = tagKey(target, key);\n if (!table.has(name)) {\n return null;\n }\n values[key] = Array.from({ length: n }, (_, i) => {\n const v = plainCell(table.value(name, i));\n return typeof v === \"string\" || typeof v === \"number\" || typeof v === \"boolean\" ? v : null;\n });\n }\n return values;\n}\n\n/**\n * The columns of a table that hold styles: the graphics records and graphty's per-element style values.\n * @param table - the node or edge table\n * @returns the column names\n */\nfunction styleColumns(table: GraphSnapshot[\"nodes\"]): string[] {\n return [...table.names()].filter((c) => c === \"graphics\" || c === \"LabelGraphics\" || c.startsWith(TAG_PREFIX));\n}\n\n/**\n * The styles of a GML file, read the way the program that wrote it draws them, with that program's defaults beneath:\n * yEd, Cytoscape, Gephi and OGDF are recognized by the `Creator` line; igraph and every other writer get the GML\n * draft's keys and no defaults. A file graphty wrote gives back its `graphty.styles` block.\n * @param snapshot - the graph the import built\n * @param context - the work budget\n * @returns the styles, or null when the file has none\n */\nexport function gmlStyles(snapshot: GraphSnapshot, context: StyleReadContext): ImporterStyles | null {\n const notes = new StyleNotes();\n const writer = writerOf(snapshot);\n const values = readValues(snapshot, writer, notes, context);\n const blockText = graphText(snapshot, GML_STYLE_BLOCK_KEY);\n const block = blockText === null ? null : blockWithValues(snapshot, blockText);\n if (block !== null) {\n exactFromBlock(snapshot, block, values);\n }\n if (writer.tool === null && !values.found && block === null) {\n return null;\n }\n const gephi =\n writer.tool === \"gephi\"\n ? gephiRules(snapshot, values.node, values.edge, context.budget)\n : { node: {}, edge: {} };\n return {\n canonical: true,\n dialect: writer.dialect,\n tool: writer.tool,\n units: writer.units,\n node: { values: values.node, ...gephi.node },\n edge: { values: values.edge, ...gephi.edge },\n notes: notes.list(),\n opacityInColor: true,\n block,\n // the graphics records and the per-element style values of a file graphty wrote hold styles, not data\n readFrom: { node: styleColumns(snapshot.nodes), edge: styleColumns(snapshot.edges) },\n };\n}\n\n// ============================================================ writing\n\n/**\n * What the GML writer holds natively: yEd GML `graphics` and `LabelGraphics`. The `graphty.styles` block and the\n * per-element values its rules read are keys of the graph and of each element.\n * @category Built-in formats\n */\nexport const GML_STYLE_CAPABILITIES: StyleWriteCapabilities = Object.freeze({\n tool: \"yed\",\n node: Object.freeze([\n \"fill\",\n \"fillOpacity\",\n \"borderColor\",\n \"borderWidth\",\n \"borderStyle\",\n \"shape\",\n \"width\",\n \"height\",\n \"label\",\n \"labelColor\",\n \"labelSize\",\n \"labelFont\",\n \"labelWeight\",\n \"labelItalic\",\n ] as const),\n edge: Object.freeze([\n \"color\",\n \"opacity\",\n \"width\",\n \"lineStyle\",\n \"sourceArrow\",\n \"targetArrow\",\n \"curved\",\n \"bends\",\n \"label\",\n \"labelColor\",\n \"labelSize\",\n \"labelFont\",\n \"labelWeight\",\n \"labelItalic\",\n ] as const),\n block: \"native\",\n});\n\n/** Every style key a reader here reads, per record: the writer replaces them all. */\nconst OWNED: Readonly<Record<\"node\" | \"edge\" | \"label\", ReadonlySet<string>>> = {\n node: new Set([\n \"fill\",\n \"fill2\",\n \"hasFill\",\n \"outline\",\n \"hasOutline\",\n \"outlineWidth\",\n \"outline_width\",\n \"outlineStyle\",\n \"width\",\n \"line\",\n \"lineWidth\",\n \"stipple\",\n \"w\",\n \"h\",\n \"type\",\n ]),\n edge: new Set([\n \"fill\",\n \"width\",\n \"lineWidth\",\n \"style\",\n \"stipple\",\n \"arrow\",\n \"sourceArrow\",\n \"targetArrow\",\n \"source_arrow\",\n \"target_arrow\",\n \"smoothBends\",\n ]),\n label: new Set([\"text\", \"color\", \"fill\", \"fontSize\", \"fontName\", \"fontStyle\", \"visible\"]),\n};\n\n/** One element's value of a property. */\ntype Get = (property: string) => StyleValue | null;\n\n/** Records a value written as the nearest one yEd has. */\ntype Approximate = (property: string, value: StyleValue) => void;\n\n/**\n * A node's yEd `graphics` keys from its values.\n * @param get - the node's values\n * @param approximate - records approximations\n * @returns the keys\n */\nfunction nodeGraphics(get: Get, approximate: Approximate): Rec {\n const g: Rec = {};\n const width = get(\"width\");\n const height = get(\"height\");\n if (typeof width === \"number\") {\n g.w = width;\n }\n if (typeof height === \"number\") {\n g.h = height;\n }\n const shape = get(\"shape\");\n if (typeof shape === \"string\") {\n const w = yedValue(YED_SHAPES, shape, shape === \"vee\" ? \"triangle\" : \"rectangle\");\n if (!w.exact) {\n approximate(\"shape\", shape);\n }\n g.type = w.value;\n }\n const fill = get(\"fill\");\n const fillOpacity = get(\"fillOpacity\");\n if (typeof fill === \"string\") {\n g.fill = yedColor(fill, fillOpacity);\n } else if (fillOpacity === 0) {\n g.hasFill = 0;\n }\n const borderColor = get(\"borderColor\");\n const borderWidth = get(\"borderWidth\");\n const borderStyle = get(\"borderStyle\");\n if (typeof borderColor === \"string\") {\n g.outline = borderColor.toUpperCase();\n }\n if (typeof borderStyle === \"string\") {\n const w = yedValue(YED_LINES, borderStyle, \"line\");\n if (!w.exact) {\n approximate(\"borderStyle\", borderStyle);\n }\n g.outlineStyle = w.value;\n }\n if (borderWidth === 0) {\n g.hasOutline = 0;\n } else if (typeof borderWidth === \"number\") {\n g.outlineWidth = borderWidth;\n }\n return g;\n}\n\n/**\n * An edge's yEd `graphics` keys from its values.\n * @param get - the edge's values\n * @param approximate - records approximations\n * @returns the keys\n */\nfunction edgeGraphics(get: Get, approximate: Approximate): Rec {\n const g: Rec = {};\n const color = get(\"color\");\n if (typeof color === \"string\") {\n g.fill = yedColor(color, get(\"opacity\"));\n }\n const width = get(\"width\");\n if (typeof width === \"number\") {\n g.width = width;\n }\n const lineStyle = get(\"lineStyle\");\n if (typeof lineStyle === \"string\") {\n g.style = yedSpelled(\n YED_LINES,\n lineStyle,\n lineStyle === \"long-dash\" ? \"dashed\" : \"line\",\n \"lineStyle\",\n approximate,\n );\n }\n for (const property of [\"sourceArrow\", \"targetArrow\"]) {\n const arrow = get(property);\n if (typeof arrow === \"string\") {\n g[property] = yedSpelled(YED_ARROWS, arrow, \"standard\", property, approximate);\n }\n }\n const curved = get(\"curved\");\n if (typeof curved === \"boolean\") {\n g.smoothBends = curved ? 1 : 0;\n }\n return g;\n}\n\n/**\n * An element's yEd `LabelGraphics` keys from its values, or null when it has no label text.\n * @param get - the element's values\n * @returns the keys\n */\nfunction labelGraphics(get: Get): Rec | null {\n const text = get(\"label\");\n if (typeof text !== \"string\" || text.trim().length === 0) {\n return null;\n }\n const lg: Rec = { text };\n const color = get(\"labelColor\");\n if (typeof color === \"string\") {\n lg.color = color.toUpperCase();\n }\n const size = get(\"labelSize\");\n if (typeof size === \"number\") {\n lg.fontSize = size;\n }\n const font = get(\"labelFont\");\n if (typeof font === \"string\") {\n lg.fontName = font;\n }\n const weight = get(\"labelWeight\");\n const italic = get(\"labelItalic\");\n if (weight !== null || italic !== null) {\n const style = (weight === \"bold\" ? \"bold\" : \"\") + (italic === true ? \"italic\" : \"\");\n lg.fontStyle = style.length === 0 ? \"plain\" : style;\n }\n return lg;\n}\n\n/**\n * A record with the style keys replaced: the kept keys of the old record, then the written ones.\n * @param old - the record the element had, or anything else\n * @param owned - the style keys\n * @param written - the new style keys\n * @returns the record, or undefined (an unset cell) when it is empty\n */\nfunction merged(old: unknown, owned: ReadonlySet<string>, written: Rec): Rec | undefined {\n const out: Rec = {};\n if (isRec(old)) {\n for (const [k, v] of Object.entries(old)) {\n if (!owned.has(k)) {\n out[k] = v;\n }\n }\n }\n Object.assign(out, written);\n return Object.keys(out).length === 0 ? undefined : out;\n}\n\n/**\n * An element's `LabelGraphics` value with its first label's style keys replaced; further labels are kept.\n * @param old - the value the element had\n * @param written - the new label keys, or null for no label\n * @returns the value, or undefined (an unset cell)\n */\nfunction mergedLabels(old: unknown, written: Rec | null): unknown {\n const labels = Array.isArray(old) ? old : [old];\n const head = merged(labels[0], OWNED.label, written ?? {});\n const rest = labels.slice(1).filter((l) => l !== null && l !== undefined);\n if (rest.length === 0) {\n return head;\n }\n return head === undefined ? rest : [head, ...rest];\n}\n\n/**\n * Each element's values of the properties the writer writes, as a getter per element.\n * @param picture - each element's value of a property\n * @param target - nodes or edges\n * @returns the getter\n */\nfunction getter(\n picture: (target: StyleTarget, property: string) => readonly (StyleValue | null)[],\n target: StyleTarget,\n): (i: number) => Get {\n const columns = new Map<string, readonly (StyleValue | null)[]>();\n for (const p of GML_STYLE_CAPABILITIES[target]) {\n columns.set(p, picture(target, p));\n }\n return (i) => (property) => columns.get(property)?.[i] ?? null;\n}\n\n/**\n * For a file graphty wrote: where a value read from the graphics is what the writer writes for the block's own value\n * (a pentagon written as a rectangle, an opacity rounded to 255 steps), the block's exact value is the truth, so a\n * re-import gives back the same rules; a value another program changed since stays the truth.\n * @param snapshot - the graph\n * @param text - the block's text\n * @param read - the values read, changed in place\n * @param read.node - the node values\n * @param read.edge - the edge values\n */\nfunction exactFromBlock(\n snapshot: GraphSnapshot,\n text: string,\n read: { readonly node: ValueColumns; readonly edge: ValueColumns },\n): void {\n const parsed = parseStyleBlock(text, styleFingerprint(snapshot));\n const ex = parsed.ok ? blockStyles(parsed.block, snapshot, \"gml\") : null;\n if (ex === null) {\n return;\n }\n const notes = new StyleNotes();\n for (const target of [\"node\", \"edge\"] as const) {\n const n = target === \"node\" ? snapshot.nodeCount : snapshot.edgeCount;\n const get = getter((t, p) => resolveStyles(ex, t, p as never, snapshot), target);\n const values = read[target];\n for (let i = 0; i < n; i++) {\n const want = get(i);\n const back = writtenAndReadBack(target, want, notes);\n for (const property of GML_STYLE_CAPABILITIES[target]) {\n const native = values[property]?.[i] ?? null;\n const w = want(property);\n if (native !== w && native === (back.get(property) ?? null)) {\n values[property] ??= new Array<StyleValue | null>(n).fill(null);\n values[property][i] = w;\n }\n }\n }\n }\n}\n\n/**\n * An element's values written as the writer writes them and read back as the reader reads them.\n * @param target - nodes or edges\n * @param want - its values\n * @param notes - a scratch for the notes the round trip makes\n * @returns the values read back, by property\n */\nfunction writtenAndReadBack(target: StyleTarget, want: Get, notes: StyleNotes): Map<string, StyleValue> {\n const ignore: Approximate = () => undefined;\n const g = target === \"node\" ? nodeGraphics(want, ignore) : edgeGraphics(want, ignore);\n const back = new Map<string, StyleValue>();\n readElement(\n target,\n g,\n labelGraphics(want) ?? undefined,\n undefined,\n GRAPHTY_WRITER,\n (property, value) => {\n if (value !== null) {\n back.set(property, value);\n }\n },\n (property) => ({ notes, target, property }),\n );\n return back;\n}\n\n/** A GML export with styles worked out. */\ninterface GmlStyledExport {\n /** The graph to write: yEd graphics written from the styles, the block and the per-element style values added. */\n readonly snapshot: GraphSnapshot;\n /** W_STYLE_APPROXIMATED for every value written as the nearest one yEd has. */\n readonly notes: readonly LossNote[];\n}\n\n/**\n * Works out a GML export with styles: every node's and edge's `graphics` and `LabelGraphics` records get yEd's keys\n * for what graphty draws in place of every style key they had (positions, bends and other keys stay), the\n * `graphty.styles` block becomes the graph key `graphty_styles` and the per-element values its rules read become\n * element keys. Should two style columns map to one key, the values go inside the block instead.\n * @param snapshot - the graph handed to the exporter\n * @param input - the styles, or undefined when none are written\n * @returns the styled export, or null without styles\n */\nexport function gmlStyledExport(\n snapshot: GraphSnapshot,\n input: ExporterStyleInput | undefined,\n): GmlStyledExport | null {\n if (input === undefined) {\n return null;\n }\n const approximated = new StyleApproximations();\n const out = snapshot.withColumns();\n const renames: LossNote[] = [];\n for (const target of [\"node\", \"edge\"] as const) {\n const table = target === \"node\" ? out.nodes : out.edges;\n writeGraphicsColumns(snapshot, input, target, table, approximated);\n // the per-element style values of an earlier write go; a data column the rules read, or any other whose key\n // would read back as a style value, is renamed out of the keys the style values take\n const read = dataRead(input.rules.styles.rules, target);\n for (const name of table.names().filter((c) => mangleGmlKey(c).startsWith(TAG_PREFIX))) {\n const col = table.get(name);\n table.remove(name);\n if (col !== null && !(name.startsWith(TAG_PREFIX) && !read.has(name))) {\n renames.push(renameDataColumn(table, target, name, col));\n }\n }\n }\n let { block } = input;\n const keys = [...input.rules.columns.node.keys()].map((k) => tagKey(\"node\", k));\n const edgeKeys = [...input.rules.columns.edge.keys()].map((k) => tagKey(\"edge\", k));\n if (new Set(keys).size !== keys.length || new Set(edgeKeys).size !== edgeKeys.length) {\n block = writeStyleBlock(input.rules, { inlineColumns: true, snapshot });\n } else {\n setTagColumns(out, input);\n }\n out.graph.set(GML_STYLE_BLOCK_KEY, [block], { dtype: \"string\" });\n const notes: LossNote[] = [\n ...renames,\n ...(block === input.block ? [] : styleBlockLosses(block, input.rules.styles.rules.length, \"size\")),\n ...approximated.notes(\"yEd's GML\"),\n ];\n return { snapshot: out, notes };\n}\n\n/**\n * Writes every element's `graphics` and `LabelGraphics` records of a target with yEd's keys for what graphty draws,\n * keeping the keys that are not style keys.\n * @param snapshot - the graph handed to the exporter\n * @param input - the styles\n * @param target - nodes or edges\n * @param table - the target's table being written, changed in place\n * @param approximated - where approximations are counted\n */\nfunction writeGraphicsColumns(\n snapshot: GraphSnapshot,\n input: ExporterStyleInput,\n target: StyleTarget,\n table: GraphSnapshot[\"nodes\"],\n approximated: StyleApproximations,\n): void {\n const n = target === \"node\" ? snapshot.nodeCount : snapshot.edgeCount;\n const approximate: Approximate = (property, value) => {\n approximated.add(target, property, value);\n };\n const get = getter((t, p) => input.picture(t, p as never), target);\n const graphics: unknown[] = [];\n const labels: unknown[] = [];\n for (let i = 0; i < n; i++) {\n const g = target === \"node\" ? nodeGraphics(get(i), approximate) : edgeGraphics(get(i), approximate);\n if (target === \"edge\") {\n const line = bendsLine(snapshot, get(i)(\"bends\"), i);\n if (line !== null) {\n g.Line = line;\n }\n }\n graphics.push(merged(cellOf(table, \"graphics\", i), OWNED[target], g));\n labels.push(mergedLabels(cellOf(table, \"LabelGraphics\", i), labelGraphics(get(i))));\n }\n for (const [name, cells] of [\n [\"graphics\", graphics],\n [\"LabelGraphics\", labels],\n ] as const) {\n if (cells.some((c) => c !== undefined)) {\n table.set(name, cells, { dtype: \"json\", nullable: true });\n } else if (table.has(name)) {\n table.remove(name);\n }\n }\n}\n\n/**\n * An edge's `Line` from its `bends` value: the node centers it is written between, with the bends placed between them,\n * so the bends read back as written.\n * @param snapshot - the graph handed to the exporter\n * @param bends - the edge's `bends` value\n * @param e - the edge's row\n * @returns the `Line` record, or null without a value or without both centers\n */\nfunction bendsLine(snapshot: GraphSnapshot, bends: StyleValue | null, e: number): Rec | null {\n const source = centerOf(snapshot, snapshot.edgeSource(e));\n const target = centerOf(snapshot, snapshot.edgeTarget(e));\n const points = typeof bends === \"string\" ? bendsToPoints(source, target, bends, true) : null;\n if (points === null || ![...source, ...target].every(Number.isFinite)) {\n return null;\n }\n return { point: [source, ...points, target].map(([x, y]) => ({ x, y })) };\n}\n\n/**\n * Writes a data column under a name out of the keys the style values take.\n * @param table - the table, changed in place\n * @param target - nodes or edges\n * @param name - the column's name\n * @param col - the column\n * @returns the note saying so\n */\nfunction renameDataColumn(\n table: GraphSnapshot[\"nodes\"],\n target: StyleTarget,\n name: string,\n col: NonNullable<ReturnType<GraphSnapshot[\"nodes\"][\"get\"]>>,\n): LossNote {\n let renamed = `data_${name}`;\n let k = 2;\n while (table.has(renamed)) {\n renamed = `data_${name}_${String(k)}`;\n k++;\n }\n table.set(renamed, col);\n return Object.freeze({\n code: KEY_MANGLED_CODE,\n message: `${target} column \"${name}\" is written as \"${renamed}\": keys starting with ${TAG_PREFIX} hold graphty's style values`,\n column: name,\n count: null,\n });\n}\n\n/**\n * Sets the per-element values the rules read as element keys.\n * @param out - the graph, changed in place\n * @param input - the styles\n */\nfunction setTagColumns(out: GraphSnapshot, input: ExporterStyleInput): void {\n for (const target of [\"node\", \"edge\"] as const) {\n const table = target === \"node\" ? out.nodes : out.edges;\n for (const [key, col] of input.rules.columns[target]) {\n const kinds = new Set(col.filter((v) => v !== null).map((v) => typeof v));\n const text = kinds.size > 1 || kinds.has(\"string\");\n let dtype: \"string\" | \"bool\" | \"f64\" = kinds.has(\"boolean\") ? \"bool\" : \"f64\";\n if (text) {\n dtype = \"string\";\n }\n table.set(tagKey(target, key), text ? col.map((v) => (v === null ? null : String(v))) : col, { dtype });\n }\n }\n}\n","/**\n * The GML exporter (design section 8.5, research note 07 sections 2.2 and 9): writes a snapshot in\n * the NetworkX dialect of GML. Node ids must be integers (`idCharset: \"integer\"`; `sanitizeIds:\n * \"mangle\"` renumbers the others and keeps the original in a `graphty_originalId` key the importer\n * restores); columns are written per dtype (`int` for the integer dtypes, `real` with a decimal\n * point guaranteed for f32 / f64 so the dtype survives a re-import, quoted strings with `&#NN;`\n * references, repeated keys for lists with the `_networkx_list_start` marker for one-element\n * lists and `\"[]\"` for empty ones, nested records for json objects); the position role becomes\n * `graphics [ x y z ]` merged with the node's `graphics` json record; graph columns are written\n * inside `graph [ ]` (or at the top level when the importer found them there); `Creator` and\n * `Version` come from the metadata.\n *\n * check() reports, before anything is written, the capability gaps of the common check plus the\n * GML-specific ones: json columns holding numbers (JSON cannot keep the int / real distinction:\n * `W_GML_RECORD_NUMBER_TYPE`), booleans (written 1 / 0) or nulls (omitted), arrays nested in\n * arrays (no GML spelling; export() throws), column names and record keys that are not GML keys\n * or collide with the structural keys (`E_GML_INVALID_KEY` / `E_GML_RESERVED_KEY`, or\n * `W_GML_KEY_MANGLED` under `sanitizeKeys: \"mangle\"`), and graphics / position overlaps.\n */\n\nimport {\n type Column,\n type ColumnMeta,\n GraphFormatError,\n type GraphSnapshot,\n type JsonColumn,\n type NodeId,\n} from \"@graphty/graph-format\";\n\nimport { DICT_SAMPLE_ROWS, DictHeuristic } from \"../../common/attributes.js\";\nimport { type PairFolding, pairFolding } from \"../../common/direction.js\";\nimport { quoteGmlString } from \"../../common/escape.js\";\nimport {\n capabilities,\n checkCapabilities,\n countMixedEdges,\n LOSS,\n type SanitizedIds,\n sanitizeIds,\n} from \"../../common/export.js\";\nimport { formatGmlReal, formatInteger } from \"../../common/format.js\";\nimport { type ResolvedExportOptions, resolveExportOptions } from \"../../common/options.js\";\nimport { agree, plural } from \"../../common/plural.js\";\nimport { type ExplicitWeights, explicitWeights } from \"../../common/weights.js\";\nimport { encodeChunks, joinText } from \"../../common/writer.js\";\nimport type { ExporterStyleOptions } from \"../../styles/io/writer.js\";\nimport { type CommonExportOptions, type ExportCapabilities, type GraphExporter, type LossNote } from \"../../types.js\";\nimport { GML_STYLE_CAPABILITIES, gmlStyledExport } from \"./styles.js\";\nimport {\n EMPTY_LIST_TEXT,\n isGmlKey,\n KEY_MANGLED_CODE,\n LIST_START_MARKER,\n mangleGmlKey,\n ORIGINAL_ID_KEY,\n} from \"./syntax.js\";\n\n/** What the writer takes: the format's options, the common ones and the styles. */\ntype GmlWriteOptions = GmlExportOptions & CommonExportOptions & ExporterStyleOptions;\n\n/**\n * The format-specific options of the GML exporter.\n * @category Built-in formats\n */\nexport interface GmlExportOptions extends CommonExportOptions {\n /**\n * The edge key the weights are written under. The default is the key a GML import read them\n * from, else `value`.\n * @defaultValue as read, else \"value\"\n */\n weightKey?: string | undefined;\n /**\n * What to do with an attribute name or record key that GML cannot write: one that is not a GML\n * key (letters, digits and `_`, starting with a letter, so `Edge Label` is not one), or one that\n * GML uses itself in that record: `id` for a node attribute; `source`, `target` and `directed`\n * for an edge attribute; `node`, `edge`, `directed` and `multigraph` for a graph attribute. A node\n * attribute named `source` is fine. \"error\" makes the save fail, \"mangle\" rewrites the name (`.`\n * and other characters become `_`, a clash gets a `_2` suffix) and checkExport() lists each\n * rename. An options object shared by saves to several formats that include GML should set it.\n * @defaultValue \"error\"\n */\n sanitizeKeys?: \"error\" | \"mangle\" | undefined;\n}\n\n/**\n * A nested (json) attribute holds numbers; GML records do not keep the difference between integers and decimals.\n * @category Issue and loss codes\n */\nexport const RECORD_NUMBER_TYPE_CODE = \"W_GML_RECORD_NUMBER_TYPE\";\n/**\n * A json column holds booleans, written as 1 / 0.\n * @category Issue and loss codes\n */\nexport const RECORD_BOOLEAN_CODE = \"W_GML_RECORD_BOOLEAN\";\n/**\n * A json column holds nulls, which GML cannot write; the key (or the row) is omitted.\n * @category Issue and loss codes\n */\nexport const RECORD_NULL_CODE = \"W_GML_RECORD_NULL\";\n/**\n * An attribute holds an array inside an array, which GML cannot write; the save fails.\n * @category Issue and loss codes\n */\nexport const NESTED_ARRAY_CODE = \"E_GML_NESTED_ARRAY\";\n/**\n * A nested (json) attribute holds arrays; they are written as repeated keys and read back as a list attribute.\n * @category Issue and loss codes\n */\nexport const JSON_ARRAY_CODE = \"W_GML_JSON_ARRAY\";\n/**\n * A column name or record key is not a GML key; export() throws unless sanitizeKeys is \"mangle\".\n * @category Issue and loss codes\n */\nexport const INVALID_KEY_CODE = \"E_GML_INVALID_KEY\";\n/**\n * A column name collides with a structural GML key; export() throws unless sanitizeKeys is \"mangle\".\n * @category Issue and loss codes\n */\nexport const RESERVED_KEY_CODE = \"E_GML_RESERVED_KEY\";\nexport { KEY_MANGLED_CODE } from \"./syntax.js\";\n/**\n * A position column with more than three components; x, y and z are written.\n * @category Issue and loss codes\n */\nexport const POSITION_COMPONENTS_CODE = \"W_GML_POSITION_COMPONENTS\";\n/**\n * A node's graphics record has x / y / z keys the position column replaces.\n * @category Issue and loss codes\n */\nexport const GRAPHICS_OVERRIDDEN_CODE = \"W_GML_GRAPHICS_OVERRIDDEN\";\n/**\n * A node's graphics value is not a record and cannot hold the position; export() throws.\n * @category Issue and loss codes\n */\nexport const GRAPHICS_CONFLICT_CODE = \"E_GML_GRAPHICS_CONFLICT\";\n\n/**\n * The default weight key (design section 8.4: GML weights are read from `value` by default).\n * @category Plugin helpers\n */\nexport const DEFAULT_WEIGHT_KEY = \"value\";\n\n/** The roles GML has a key for (`label`, the edge `id` and `key`); every other role is reported. */\nconst KEPT_ROLES: ReadonlySet<string> = new Set([\"label\", \"id\", \"key\"]);\n\n/** The key the importer maps each kept role back from (the column name after re-import). */\nconst ROLE_NAMES: Readonly<Record<string, string>> = Object.freeze({\n label: \"label\",\n id: \"id\",\n key: \"key\",\n});\n\nconst GML_CAPABILITIES: ExportCapabilities = capabilities({\n mixedDirection: false,\n multiEdges: true,\n selfLoops: true,\n edgeIds: \"optional\",\n idCharset: \"integer\",\n dtypes: [\"i32\", \"f64\", \"string\", \"dict\", \"json\"],\n components: false,\n lists: true,\n json: true,\n defaults: false,\n options: false,\n hierarchy: false,\n temporal: \"none\",\n graphAttributes: true,\n positions: true,\n viz: false,\n});\n\n/** Roles whose columns are never written as attributes (structural, or dropped per the capabilities). */\nconst SKIPPED_ROLES: ReadonlySet<string> = new Set([\n \"directed\",\n \"pair\",\n \"mutual\",\n \"weight\",\n \"timeText\",\n \"originalId\",\n \"position\",\n \"color\",\n \"size\",\n \"shape\",\n \"thickness\",\n \"parent\",\n \"parents\",\n \"start\",\n \"end\",\n \"timestamp\",\n \"timestamps\",\n \"spells\",\n \"open\",\n \"spellsOpen\",\n]);\n\nconst NODE_RESERVED: ReadonlySet<string> = new Set([\"id\"]);\nconst EDGE_RESERVED: ReadonlySet<string> = new Set([\"source\", \"target\", \"directed\"]);\nconst GRAPH_RESERVED: ReadonlySet<string> = new Set([\"node\", \"edge\", \"directed\", \"multigraph\"]);\nconst TOP_RESERVED: ReadonlySet<string> = new Set([\"graph\"]);\nconst NUMBER_TEXT = /^[+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?$/;\n\n/** The resolved options of one export. */\ninterface GmlExportPlan {\n readonly common: ResolvedExportOptions;\n readonly weightKey: string;\n readonly mangle: boolean;\n}\n\n/** What one json column holds that GML cannot write exactly. */\ninterface JsonStats {\n numbers: number;\n booleans: number;\n nulls: number;\n nestedArrays: number;\n arrays: number;\n invalidKeys: number;\n}\n\n/** The kinds of value already counted for one row while inspecting a json value. */\ninterface SeenFlags {\n numbers: boolean;\n booleans: boolean;\n nulls: boolean;\n nested: boolean;\n}\n\n/** The columns of one table selected for writing, with their keys. */\ninterface WrittenColumn {\n readonly column: Column;\n readonly key: string;\n}\n\n/**\n * Resolve the options of one export call.\n * @param snapshot - the snapshot\n * @param options - the caller's options\n * @returns the plan\n */\nfunction planOf(snapshot: GraphSnapshot, options: (GmlExportOptions & CommonExportOptions) | undefined): GmlExportPlan {\n const common = resolveExportOptions(options);\n const mode = options?.sanitizeKeys ?? \"error\";\n if (mode !== \"error\" && mode !== \"mangle\") {\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n `option sanitizeKeys: ${JSON.stringify(mode)} is not \"error\" or \"mangle\"`,\n {\n option: \"sanitizeKeys\",\n found: mode,\n },\n );\n }\n let weightKey = options?.weightKey;\n if (weightKey === undefined) {\n const origin = snapshot.meta.weightOrigin;\n weightKey = origin !== null && origin.format === \"gml\" && origin.id !== null ? origin.id : DEFAULT_WEIGHT_KEY;\n } else if (typeof weightKey !== \"string\" || !isGmlKey(weightKey)) {\n throw new GraphFormatError(\"E_UNSUPPORTED\", `option weightKey: ${JSON.stringify(weightKey)} is not a GML key`, {\n option: \"weightKey\",\n found: weightKey,\n });\n }\n return { common, weightKey, mangle: mode === \"mangle\" };\n}\n\n/**\n * Whether a column is written as an attribute (its role is neither structural nor dropped).\n * @param column - the column\n * @returns true when written\n */\nfunction isWritten(column: Column): boolean {\n const { role } = column.meta;\n return role === null || !SKIPPED_ROLES.has(role);\n}\n\n/**\n * The key a column is written under.\n * @param meta - the column metadata\n * @returns origin.id when the column came from GML under that key (its name is the key, or the importer's\n * `<key>#...` rename of it), else the name: a column renamed since it was read is written under its new name\n */\nfunction preferredKey(meta: ColumnMeta): string {\n const { origin, name } = meta;\n if (origin?.format !== \"gml\" || origin.id === null) {\n return name;\n }\n return name === origin.id || name.startsWith(`${origin.id}#`) ? origin.id : name;\n}\n\n/**\n * Whether a snapshot has explicit weights to write.\n * @param snapshot - the snapshot\n * @returns true when weighted\n */\nfunction hasWeights(snapshot: GraphSnapshot): boolean {\n return snapshot.flags.weighted;\n}\n\n/**\n * Whether the graph column is a top-level key (the importer's `extra.gmlTopLevel`).\n * @param column - the column\n * @returns true for a top-level key\n */\nfunction isTopLevel(column: Column): boolean {\n return column.meta.extra.gmlTopLevel === true;\n}\n\n/**\n * The text of a `Version` value: bare when it is a number text, quoted otherwise.\n * @param text - the version text\n * @returns the GML value\n */\nfunction versionText(text: string): string {\n return NUMBER_TEXT.test(text) ? text : quoteGmlString(text);\n}\n\n/**\n * A node or edge table's label role column, which is written under \"label\" (the key the importer\n * gives the role back to): the key is marked used so a plain column of that name cannot have it.\n * @param columns - the written columns\n * @param label - the table name\n * @param used - the keys already taken, gaining \"label\" when there is a label role column\n * @returns the label role column, or undefined\n */\nfunction labelRoleColumn(columns: readonly Column[], label: string, used: Set<string>): Column | undefined {\n if (label !== \"node\" && label !== \"edge\") {\n return undefined;\n }\n const column = columns.find((c) => c.meta.role === \"label\");\n if (column !== undefined) {\n used.add(\"label\");\n }\n return column;\n}\n\n/**\n * Select the written columns of a table and assign their keys, recording invalid and reserved\n * keys as notes (or rewriting them under mangle).\n * @param table - the columns\n * @param reserved - the structural keys of the table\n * @param label - the table name for messages\n * @param plan - the export plan\n * @param notes - where to record\n * @param filter - an extra selection predicate\n * @returns the written columns with their keys\n */\nfunction selectColumns(\n table: Iterable<Column>,\n reserved: ReadonlySet<string>,\n label: string,\n plan: GmlExportPlan,\n notes: LossNote[] | null,\n filter: (column: Column) => boolean = (): boolean => true,\n): WrittenColumn[] {\n const used = new Set<string>(reserved);\n const out: WrittenColumn[] = [];\n const columns = [...table].filter((c) => isWritten(c) && filter(c));\n const labelRole = labelRoleColumn(columns, label, used);\n for (const column of columns) {\n const preferred = column === labelRole ? \"label\" : preferredKey(column.meta);\n let key = preferred;\n const valid = isGmlKey(preferred);\n const taken = column !== labelRole && used.has(preferred);\n if (!valid || taken) {\n const code = valid ? RESERVED_KEY_CODE : INVALID_KEY_CODE;\n let why = \"is not a GML key\";\n if (valid) {\n why = reserved.has(preferred) ? \"collides with a structural GML key\" : \"repeats another column's key\";\n }\n if (!plan.mangle) {\n if (notes === null) {\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n `${label} column \"${column.meta.name}\" ${why}; pass sanitizeKeys: \"mangle\" to rewrite it`,\n {\n reason: \"gml key\",\n column: column.meta.name,\n key: preferred,\n },\n );\n }\n notes.push(\n note(\n code,\n `${label} column \"${column.meta.name}\" ${why}; the save fails unless sanitizeKeys is \"mangle\"`,\n column.meta.name,\n ),\n );\n continue;\n }\n key = uniqueKey(valid ? preferred : mangleGmlKey(preferred), used);\n notes?.push(\n note(\n KEY_MANGLED_CODE,\n `${label} column \"${column.meta.name}\" is written as \"${key}\"`,\n column.meta.name,\n ),\n );\n }\n used.add(key);\n out.push({ column, key });\n }\n return out;\n}\n\n/**\n * A key not yet used: the base, else base_2, base_3...\n * @param base - a valid key\n * @param used - the keys taken\n * @returns a free key\n */\nfunction uniqueKey(base: string, used: ReadonlySet<string>): string {\n let candidate = base;\n for (let k = 2; used.has(candidate); k++) {\n candidate = `${base}_${k}`;\n }\n return candidate;\n}\n\n/**\n * Build a frozen note.\n * @param code - the code\n * @param message - the message\n * @param column - the column, or null\n * @param count - the count, or null\n * @returns the note\n */\nfunction note(code: string, message: string, column: string | null = null, count: number | null = null): LossNote {\n return Object.freeze({ code, message, column, count });\n}\n\n/**\n * Count a kind of json value once per row.\n * @param seen - the flags already counted for this row\n * @param flag - the flag of the kind\n * @param stats - the counters\n * @param counter - the counter of the kind\n */\nfunction countOnce(seen: SeenFlags, flag: keyof SeenFlags, stats: JsonStats, counter: keyof JsonStats): void {\n if (!seen[flag]) {\n seen[flag] = true;\n stats[counter]++;\n }\n}\n\n/**\n * Inspect a JSON value for what GML cannot write exactly.\n * @param value - the value\n * @param stats - the counters to update (each counted at most once per call for numbers / booleans / nulls)\n * @param inArray - whether the value is an array item\n * @param seen - the flags already counted for this row\n */\nfunction inspectJson(value: unknown, stats: JsonStats, inArray: boolean, seen: SeenFlags): void {\n if (value === null) {\n countOnce(seen, \"nulls\", stats, \"nulls\");\n return;\n }\n switch (typeof value) {\n case \"number\":\n countOnce(seen, \"numbers\", stats, \"numbers\");\n return;\n case \"boolean\":\n countOnce(seen, \"booleans\", stats, \"booleans\");\n return;\n case \"string\":\n return;\n default:\n break;\n }\n if (Array.isArray(value)) {\n if (inArray) {\n countOnce(seen, \"nested\", stats, \"nestedArrays\");\n }\n for (const item of value) {\n inspectJson(item, stats, true, seen);\n }\n return;\n }\n const record = value as Record<string, unknown>;\n for (const key of Object.keys(record)) {\n if (!isGmlKey(key)) {\n stats.invalidKeys++;\n }\n inspectJson(record[key], stats, false, seen);\n }\n}\n\n/**\n * A row count in words.\n * @param count - the count\n * @returns the count and the word row, pluralised\n */\nfunction rowCount(count: number): string {\n return `${count} row${plural(count)}`;\n}\n\n/**\n * Record a note for a counter that is not zero.\n * @param notes - where to record\n * @param count - the counter\n * @param code - the note code\n * @param text - the note message\n * @param column - the column name\n */\nfunction pushCounted(notes: LossNote[], count: number, code: string, text: string, column: string): void {\n if (count > 0) {\n notes.push(note(code, text, column, count));\n }\n}\n\n/**\n * The GML-specific notes of one table's json columns.\n * @param columns - the written columns\n * @param label - the table name\n * @param plan - the export plan\n * @param notes - where to record\n */\nfunction jsonNotes(columns: readonly WrittenColumn[], label: string, plan: GmlExportPlan, notes: LossNote[]): void {\n for (const { column } of columns) {\n const stats = jsonStatsOf(column);\n if (stats === null) {\n continue;\n }\n const { name } = column.meta;\n const where = `${label} column \"${name}\"`;\n const counted = (count: number, code: string, text: string): void => {\n pushCounted(notes, count, code, text, name);\n };\n counted(\n stats.numbers,\n RECORD_NUMBER_TYPE_CODE,\n `${where} holds numbers in ${rowCount(stats.numbers)}; GML records cannot keep the int / real distinction`,\n );\n counted(\n stats.booleans,\n RECORD_BOOLEAN_CODE,\n `${where} holds booleans in ${rowCount(stats.booleans)}; written as 1 / 0`,\n );\n counted(\n stats.nulls,\n RECORD_NULL_CODE,\n `${where} holds nulls in ${rowCount(stats.nulls)}; GML has no null, the key is omitted`,\n );\n counted(\n stats.arrays,\n JSON_ARRAY_CODE,\n `${where} holds arrays as values in ${rowCount(stats.arrays)}; written as repeated keys, they re-import as a list`,\n );\n counted(\n stats.nestedArrays,\n NESTED_ARRAY_CODE,\n `${where} holds arrays nested in arrays in ${rowCount(stats.nestedArrays)}; GML cannot write them and the save fails`,\n );\n const keys = `${stats.invalidKeys} record key${plural(stats.invalidKeys)} ${agree(stats.invalidKeys, \"is\", \"are\")} not GML keys`;\n counted(\n stats.invalidKeys,\n plan.mangle ? KEY_MANGLED_CODE : INVALID_KEY_CODE,\n plan.mangle\n ? `${where}: ${keys} and are rewritten`\n : `${where}: ${keys}; the save fails unless sanitizeKeys is \"mangle\"`,\n );\n }\n}\n\n/**\n * The json statistics of a json column, or of a list column with json items; null for other dtypes.\n * @param column - the column\n * @returns the stats, or null\n */\nfunction jsonStatsOf(column: Column): JsonStats | null {\n const stats: JsonStats = { numbers: 0, booleans: 0, nulls: 0, nestedArrays: 0, arrays: 0, invalidKeys: 0 };\n if (column.dtype === \"json\") {\n for (let r = 0; r < column.length; r++) {\n if (!column.isSet(r)) {\n continue;\n }\n const value = column.values[r];\n const seen: SeenFlags = { numbers: false, booleans: false, nulls: false, nested: false };\n if (Array.isArray(value)) {\n stats.arrays++;\n for (const item of value) {\n inspectJson(item, stats, true, seen);\n }\n } else {\n inspectJson(value, stats, false, seen);\n }\n }\n return stats;\n }\n if (column.dtype === \"list\" && column.meta.itemDtype === \"json\") {\n for (let r = 0; r < column.length; r++) {\n if (!column.isSet(r)) {\n continue;\n }\n const seen: SeenFlags = { numbers: false, booleans: false, nulls: false, nested: false };\n for (const item of column.sliceOf(r)) {\n inspectJson(item, stats, true, seen);\n }\n }\n return stats;\n }\n return null;\n}\n\n/**\n * The node position column when it can be mapped to graphics x / y / z: a numeric scalar column\n * with the position role.\n * @param snapshot - the snapshot\n * @returns the column, or null\n */\nfunction positionColumn(snapshot: GraphSnapshot): Column | null {\n const column = snapshot.nodes.byRole(\"position\");\n if (column === null) {\n return null;\n }\n switch (column.dtype) {\n case \"f32\":\n case \"f64\":\n case \"i32\":\n case \"u32\":\n case \"u8\":\n return column;\n default:\n return null;\n }\n}\n\n/**\n * The node `graphics` json column, when present.\n * @param snapshot - the snapshot\n * @returns the column, or null\n */\nfunction graphicsColumn(snapshot: GraphSnapshot): JsonColumn | null {\n return snapshot.nodes.typed(\"graphics\", \"json\");\n}\n\n/**\n * The GML-specific notes about the position / graphics mapping.\n * @param snapshot - the snapshot\n * @param notes - where to record\n */\nfunction graphicsNotes(snapshot: GraphSnapshot, notes: LossNote[]): void {\n const position = positionColumn(snapshot);\n if (position === null) {\n return;\n }\n if (position.meta.components > 3) {\n notes.push(\n note(\n POSITION_COMPONENTS_CODE,\n `node column \"${position.meta.name}\" has ${position.meta.components} components; only x, y and z are written`,\n position.meta.name,\n position.length - position.nullCount,\n ),\n );\n }\n const graphics = graphicsColumn(snapshot);\n if (graphics === null) {\n return;\n }\n let overridden = 0;\n let conflicts = 0;\n for (let r = 0; r < snapshot.nodeCount; r++) {\n if (!position.isSet(r) || !graphics.isSet(r)) {\n continue;\n }\n const value = graphics.values[r];\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n conflicts++;\n } else if (\"x\" in value || \"y\" in value || \"z\" in value) {\n overridden++;\n }\n }\n if (overridden > 0) {\n notes.push(\n note(\n GRAPHICS_OVERRIDDEN_CODE,\n `${overridden} node graphics record${plural(overridden)} ${agree(overridden, \"has\", \"have\")} x / y / z keys the position column replaces`,\n \"graphics\",\n overridden,\n ),\n );\n }\n if (conflicts > 0) {\n notes.push(\n note(\n GRAPHICS_CONFLICT_CODE,\n `${conflicts} node graphics value${plural(conflicts)} ${agree(conflicts, \"is\", \"are\")} not records and cannot hold the position; the save fails`,\n \"graphics\",\n conflicts,\n ),\n );\n }\n}\n\n/**\n * What the importer's own rules change on re-import of the written columns: an all-unset column\n * vanishes (GML writes cells, never declarations), a role-less column named like a role key\n * gains the role, and the dictionary heuristic of design section 5.4 turns a low-cardinality\n * string column into a dict (or a wide dict into a string).\n * @param columns - the written columns\n * @param domain - node or edge\n * @param notes - where to record\n */\nfunction reimportNotes(columns: readonly WrittenColumn[], domain: \"node\" | \"edge\", notes: LossNote[]): void {\n for (const { column, key } of columns) {\n const { meta } = column;\n const set = column.length - column.nullCount;\n if (set === 0) {\n notes.push(\n note(\n LOSS.EMPTY_COLUMN,\n `${domain} column \"${meta.name}\" has no set cell and is not written: GML writes cells, never declarations`,\n meta.name,\n 0,\n ),\n );\n continue;\n }\n if (meta.role === null && (key === \"label\" || (domain === \"edge\" && (key === \"id\" || key === \"key\")))) {\n notes.push(\n note(\n LOSS.ROLE_ASSUMED,\n `${domain} column \"${meta.name}\" is written under \"${key}\" and reads back with the ${key === \"label\" ? \"label\" : key} role`,\n meta.name,\n set,\n ),\n );\n continue;\n }\n if (column.dtype === \"list\" || !(column.dtype === \"string\" || column.dtype === \"dict\")) {\n continue;\n }\n const heuristic = new DictHeuristic(DICT_SAMPLE_ROWS);\n for (let r = 0; r < column.length && !heuristic.decided; r++) {\n if (column.isSet(r)) {\n heuristic.observe(column.value(r) as string);\n }\n }\n const readsAsDict = heuristic.decide() === \"dict\";\n if (column.dtype === \"string\" && readsAsDict) {\n notes.push(\n note(\n LOSS.STORAGE_CLASS,\n `${domain} column \"${meta.name}\" reads back as dict (low cardinality)`,\n meta.name,\n null,\n ),\n );\n } else if (column.dtype === \"dict\" && !readsAsDict) {\n notes.push(\n note(\n LOSS.STORAGE_CLASS,\n `${domain} column \"${meta.name}\" reads back as string (cardinality too high for a dict)`,\n meta.name,\n null,\n ),\n );\n }\n }\n}\n\n/**\n * The importer names the graphics-derived position column `position`, or `position#graphics`\n * when a plain `position` key is written next to it (design section 5.6); a position column\n * named otherwise reads back under that name.\n * @param snapshot - the snapshot\n * @param nodeColumns - the written node columns\n * @param notes - where to record\n */\nfunction positionNameNote(snapshot: GraphSnapshot, nodeColumns: readonly WrittenColumn[], notes: LossNote[]): void {\n const position = positionColumn(snapshot);\n if (position === null) {\n return;\n }\n const { name } = position.meta;\n const plainPosition = nodeColumns.some((c) => c.key === \"position\");\n const reimportName = plainPosition ? \"position#graphics\" : \"position\";\n if (name !== reimportName) {\n notes.push(\n note(\n LOSS.COLUMN_NAME_CHANGED,\n `node column \"${name}\" (position) is written as the graphics x / y / z keys and reads back as \"${reimportName}\"`,\n name,\n position.length - position.nullCount,\n ),\n );\n }\n}\n\n/**\n * Pre-flight: the common capability notes plus the GML-specific ones.\n * @param snapshot - the snapshot\n * @param options - the options\n * @returns the notes, empty when the export is exact\n */\nfunction check(snapshot: GraphSnapshot, options?: GmlExportOptions & CommonExportOptions): readonly LossNote[] {\n const plan = planOf(snapshot, options);\n const notes = checkCapabilities(snapshot, GML_CAPABILITIES, plan.common, {\n positionDtype: \"f64\",\n roles: KEPT_ROLES,\n roleNames: ROLE_NAMES,\n });\n const nodeReserved = new Set(NODE_RESERVED);\n if (\n (plan.common.sanitizeIds === \"mangle\" && countMangled(snapshot) > 0) ||\n snapshot.nodes.byRole(\"originalId\") !== null\n ) {\n nodeReserved.add(ORIGINAL_ID_KEY);\n }\n const edgeIds = snapshot.edges.byRole(\"id\");\n const edgeReserved = edgeReservedKeys(snapshot, plan, edgeIds);\n const topReserved = topReservedKeys(snapshot);\n const nodeColumns = selectColumns(snapshot.nodes, nodeReserved, \"node\", plan, notes);\n const edgeColumns = selectColumns(snapshot.edges, edgeReserved, \"edge\", plan, notes, (c) => c !== edgeIds);\n const graphColumns = selectColumns(snapshot.graph, GRAPH_RESERVED, \"graph\", plan, notes, (c) => !isTopLevel(c));\n const topColumns = selectColumns(snapshot.graph, topReserved, \"top-level\", plan, notes, isTopLevel);\n jsonNotes(nodeColumns, \"node\", plan, notes);\n jsonNotes(edgeColumns, \"edge\", plan, notes);\n jsonNotes(graphColumns, \"graph\", plan, notes);\n jsonNotes(topColumns, \"top-level\", plan, notes);\n graphicsNotes(snapshot, notes);\n positionNameNote(snapshot, nodeColumns, notes);\n reimportNotes(nodeColumns, \"node\", notes);\n reimportNotes(edgeColumns, \"edge\", notes);\n if (!hasWeights(snapshot)) {\n const clash = edgeColumns.find((c) => c.key === plan.weightKey);\n if (clash !== undefined) {\n notes.push(\n note(\n LOSS.WEIGHT_KEY_CLASH,\n `edge column \"${clash.column.meta.name}\" is written under \"${plan.weightKey}\", the key the importer reads edge weights from; it reads back as the weight, not as a column`,\n clash.column.meta.name,\n clash.column.length - clash.column.nullCount,\n ),\n );\n }\n }\n const folding = pairFolding(snapshot);\n if (folding.mutualCount > 0) {\n notes.push(\n note(\n LOSS.MUTUAL_EXPANDED,\n `${folding.mutualCount} mutual pair${plural(folding.mutualCount)} ${agree(folding.mutualCount, \"is\", \"are\")} written as two directed edges; the mutual mark is lost`,\n null,\n folding.mutualCount,\n ),\n );\n }\n return Object.freeze(notes);\n}\n\n/**\n * The structural keys of the edge table: source, target, the weight key when weights are written,\n * and `id` when a role-id column is written as the edge id.\n * @param snapshot - the snapshot\n * @param plan - the export plan\n * @param edgeIds - the role-id edge column, or null\n * @returns the reserved keys\n */\nfunction edgeReservedKeys(snapshot: GraphSnapshot, plan: GmlExportPlan, edgeIds: Column | null): Set<string> {\n const reserved = new Set(EDGE_RESERVED);\n if (hasWeights(snapshot)) {\n reserved.add(plan.weightKey);\n }\n if (edgeIds !== null) {\n reserved.add(\"id\");\n }\n return reserved;\n}\n\n/**\n * The structural keys of the top level: graph, plus Creator and Version when the metadata writes them.\n * @param snapshot - the snapshot\n * @returns the reserved keys\n */\nfunction topReservedKeys(snapshot: GraphSnapshot): Set<string> {\n const reserved = new Set(TOP_RESERVED);\n if (snapshot.meta.creator !== null) {\n reserved.add(\"Creator\");\n }\n if (snapshot.meta.sourceFormat === \"gml\" && snapshot.meta.sourceVersion !== null) {\n reserved.add(\"Version\");\n }\n return reserved;\n}\n\n/**\n * How many node ids are not safe integers (what sanitizeIds \"mangle\" rewrites).\n * @param snapshot - the snapshot\n * @returns the count\n */\nfunction countMangled(snapshot: GraphSnapshot): number {\n let count = 0;\n for (let i = 0; i < snapshot.nodeCount; i++) {\n const id = snapshot.ids.idOf(i);\n if (typeof id !== \"number\" || !Number.isSafeInteger(id)) {\n count++;\n }\n }\n return count;\n}\n\n// ============================================================ writing\n\n/**\n * The GML text of a number by the dtype and origin of its column: an integer text for the integer\n * dtypes and for an f64 column that came from GML `int` values, a real text otherwise.\n * @param value - the value\n * @param meta - the column metadata\n * @returns the text\n */\nfunction numberText(value: number, meta: ColumnMeta): string {\n switch (meta.dtype) {\n case \"i32\":\n case \"u32\":\n case \"u8\":\n return formatInteger(value);\n case \"f32\":\n return formatGmlReal(value, \"f32\");\n default:\n if (meta.origin?.type === \"int\" && Number.isInteger(value)) {\n return formatInteger(value);\n }\n return formatGmlReal(value, \"f64\");\n }\n}\n\n/**\n * The GML text of a JSON scalar inside a record: integers as int, other numbers as real, strings\n * quoted, booleans as 1 / 0.\n * @param value - the scalar\n * @returns the text\n */\nfunction jsonScalarText(value: number | string | boolean): string {\n switch (typeof value) {\n case \"number\":\n return Number.isInteger(value) ? formatInteger(value) : formatGmlReal(value, \"f64\");\n case \"boolean\":\n return value ? \"1\" : \"0\";\n default:\n return quoteGmlString(value);\n }\n}\n\n/**\n * The GML text of a list item or components lane by the item dtype.\n * @param item - the item\n * @param itemDtype - the list's item dtype\n * @param meta - the list column metadata\n * @returns the text\n */\nfunction itemText(item: unknown, itemDtype: string, meta: ColumnMeta): string {\n switch (typeof item) {\n case \"number\":\n switch (itemDtype) {\n case \"i32\":\n case \"u32\":\n case \"u8\":\n return formatInteger(item);\n case \"f32\":\n return formatGmlReal(item, \"f32\");\n case \"json\":\n return jsonScalarText(item);\n default:\n return meta.origin?.type === \"int\" && Number.isInteger(item)\n ? formatInteger(item)\n : formatGmlReal(item, \"f64\");\n }\n case \"boolean\":\n return item ? \"1\" : \"0\";\n case \"string\":\n return quoteGmlString(item);\n default:\n throw new GraphFormatError(\n \"E_COLUMN_TYPE\",\n `column \"${meta.name}\": a ${typeof item} list item cannot be written as GML`,\n {\n column: meta.name,\n found: typeof item,\n },\n );\n }\n}\n\n/** Writes lines with indentation into an array of parts. */\nclass GmlWriter {\n private readonly lines: string[] = [];\n\n private readonly mangle: boolean;\n\n /**\n * Create a writer.\n * @param mangle - whether record keys are rewritten rather than refused\n */\n constructor(mangle: boolean) {\n this.mangle = mangle;\n }\n\n /**\n * Take the lines written so far as one string.\n * @returns the text; the writer is empty afterwards\n */\n take(): string {\n const text = this.lines.join(\"\");\n this.lines.length = 0;\n return text;\n }\n\n /**\n * Write one `key value` line.\n * @param indent - the indentation\n * @param key - the key\n * @param value - the value text\n */\n line(indent: string, key: string, value: string): void {\n this.lines.push(`${indent}${key} ${value}\\n`);\n }\n\n /**\n * Write a raw line.\n * @param text - the line without its terminator\n */\n raw(text: string): void {\n this.lines.push(`${text}\\n`);\n }\n\n /**\n * Write one column cell of a row.\n * @param indent - the indentation\n * @param key - the key\n * @param column - the column\n * @param row - the row\n */\n cell(indent: string, key: string, column: Column, row: number): void {\n const { meta, dtype } = column;\n switch (dtype) {\n case \"f32\":\n case \"f64\":\n case \"i32\":\n case \"u32\":\n case \"u8\": {\n const { components } = meta;\n if (components === 1) {\n this.line(indent, key, numberText(column.data[row], meta));\n } else {\n for (let k = 0; k < components; k++) {\n this.line(indent, key, numberText(column.data[row * components + k], meta));\n }\n }\n return;\n }\n case \"bool\":\n this.line(indent, key, column.value(row) === true ? \"1\" : \"0\");\n return;\n case \"dict\":\n case \"string\":\n this.line(indent, key, quoteGmlString(column.value(row) ?? \"\"));\n return;\n case \"list\":\n this.list(indent, key, column.sliceOf(row), meta.itemDtype ?? \"string\", meta);\n return;\n case \"json\":\n this.json(indent, key, column.values[row], meta.name);\n return;\n default: {\n const name: string = dtype;\n throw new GraphFormatError(\"E_COLUMN_TYPE\", `unknown dtype ${name}`, { dtype: name });\n }\n }\n }\n\n /**\n * Write a list as repeated keys with the NetworkX conventions.\n * @param indent - the indentation\n * @param key - the key\n * @param items - the items\n * @param itemDtype - the item dtype\n * @param meta - the column metadata\n */\n private list(indent: string, key: string, items: readonly unknown[], itemDtype: string, meta: ColumnMeta): void {\n if (items.length === 0) {\n this.line(indent, key, quoteGmlString(EMPTY_LIST_TEXT));\n return;\n }\n if (items.length === 1) {\n this.line(indent, key, quoteGmlString(LIST_START_MARKER));\n }\n for (const item of items) {\n if (itemDtype === \"json\" && typeof item === \"object\") {\n this.json(indent, key, item, meta.name, true);\n } else {\n this.line(indent, key, itemText(item, itemDtype, meta));\n }\n }\n }\n\n /**\n * Write a JSON value: a record for an object, repeated keys for an array, a scalar otherwise;\n * null writes nothing.\n * @param indent - the indentation\n * @param key - the key\n * @param value - the value\n * @param column - the column name, for errors\n * @param inArray - whether the value is an array item (an array here has no GML spelling)\n */\n private json(indent: string, key: string, value: unknown, column: string, inArray = false): void {\n if (value === null || value === undefined) {\n return;\n }\n if (Array.isArray(value)) {\n if (inArray) {\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n `column \"${column}\": an array nested in an array cannot be written as GML`,\n {\n reason: \"nested array\",\n column,\n },\n );\n }\n if (value.length === 0) {\n this.line(indent, key, quoteGmlString(EMPTY_LIST_TEXT));\n return;\n }\n if (value.length === 1) {\n this.line(indent, key, quoteGmlString(LIST_START_MARKER));\n }\n for (const item of value) {\n this.json(indent, key, item, column, true);\n }\n return;\n }\n if (typeof value === \"object\") {\n this.record(indent, key, value as Record<string, unknown>, column);\n return;\n }\n if (typeof value === \"number\" || typeof value === \"string\" || typeof value === \"boolean\") {\n this.line(indent, key, jsonScalarText(value));\n return;\n }\n throw new GraphFormatError(\"E_COLUMN_TYPE\", `column \"${column}\": a ${typeof value} cannot be written as GML`, {\n column,\n found: typeof value,\n });\n }\n\n /**\n * Write a record `key [ ... ]`.\n * @param indent - the indentation\n * @param key - the key\n * @param record - the object\n * @param column - the column name, for errors\n * @param extra - lines to write first (the position of a graphics record), or null\n */\n record(\n indent: string,\n key: string,\n record: Record<string, unknown>,\n column: string,\n extra: readonly [string, string][] | null = null,\n ): void {\n this.raw(`${indent}${key} [`);\n const inner = `${indent} `;\n const used = new Set<string>();\n if (extra !== null) {\n for (const [k, v] of extra) {\n this.line(inner, k, v);\n used.add(k);\n }\n }\n for (const name of Object.keys(record)) {\n if (used.has(name) && extra !== null && (name === \"x\" || name === \"y\" || name === \"z\")) {\n continue;\n }\n const written = this.recordKey(name, used, column);\n used.add(written);\n this.json(inner, written, record[name], column);\n }\n this.raw(`${indent}]`);\n }\n\n /**\n * The key a record field is written under.\n * @param name - the field name\n * @param used - the keys already written in the record\n * @param column - the column name, for errors\n * @returns a valid, unused key; E_UNSUPPORTED for an invalid key unless mangling\n */\n private recordKey(name: string, used: ReadonlySet<string>, column: string): string {\n if (isGmlKey(name) && !used.has(name)) {\n return name;\n }\n if (!this.mangle) {\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n `column \"${column}\": record key \"${name}\" ${isGmlKey(name) ? \"repeats a key\" : \"is not a GML key\"}; pass sanitizeKeys: \"mangle\" to rewrite it`,\n {\n reason: \"gml key\",\n column,\n key: name,\n },\n );\n }\n return uniqueKey(isGmlKey(name) ? name : mangleGmlKey(name), used);\n }\n}\n\n/** Everything the writer needs, resolved once before the first line. */\ninterface WriteContext {\n readonly snapshot: GraphSnapshot;\n readonly plan: GmlExportPlan;\n readonly ids: SanitizedIds;\n readonly writeDirected: boolean;\n readonly foldPairs: boolean;\n readonly nodeColumns: readonly WrittenColumn[];\n readonly edgeColumns: readonly WrittenColumn[];\n readonly graphColumns: readonly WrittenColumn[];\n readonly topColumns: readonly WrittenColumn[];\n readonly position: Column | null;\n readonly graphics: JsonColumn | null;\n readonly originalIds: Column | null;\n readonly edgeIds: Column | null;\n readonly weights: ExplicitWeights;\n readonly folding: PairFolding;\n}\n\n/**\n * Resolve everything export() needs, throwing for what check() reported as an error.\n * @param snapshot - the snapshot\n * @param options - the options\n * @returns the context\n */\nfunction contextOf(\n snapshot: GraphSnapshot,\n options: (GmlExportOptions & CommonExportOptions) | undefined,\n): WriteContext {\n const plan = planOf(snapshot, options);\n const ids = sanitizeIds(snapshot, \"integer\", plan.common.sanitizeIds);\n const mixed = countMixedEdges(snapshot);\n if (mixed > 0 && plan.common.onMixedDirection === \"error\") {\n throw new GraphFormatError(\n \"E_DIRECTED\",\n `${mixed} undirected edge${plural(mixed)} in a directed graph, and GML holds one direction per file, so the save fails unless onMixedDirection is \"directed\" or \"undirected\"`,\n {\n reason: \"mixed direction\",\n count: mixed,\n },\n );\n }\n // design 8.5: exporters fold expanded pairs back; under \"directed\" the folded edge is written\n // once, as one directed edge, under \"undirected\" the whole graph is written undirected\n const foldPairs = mixed > 0;\n const writeDirected = snapshot.directed && plan.common.onMixedDirection !== \"undirected\";\n const originalIds = snapshot.nodes.byRole(\"originalId\");\n const nodeReserved = new Set(NODE_RESERVED);\n if (ids.changed > 0 || originalIds !== null) {\n nodeReserved.add(ORIGINAL_ID_KEY);\n }\n const edgeIds = snapshot.edges.byRole(\"id\");\n const edgeReserved = edgeReservedKeys(snapshot, plan, edgeIds);\n const topReserved = topReservedKeys(snapshot);\n return {\n snapshot,\n plan,\n ids,\n writeDirected,\n foldPairs,\n nodeColumns: selectColumns(\n snapshot.nodes,\n nodeReserved,\n \"node\",\n plan,\n null,\n (c) => !(c.meta.name === \"graphics\" && c.dtype === \"json\"),\n ),\n edgeColumns: selectColumns(snapshot.edges, edgeReserved, \"edge\", plan, null, (c) => c !== edgeIds),\n graphColumns: selectColumns(snapshot.graph, GRAPH_RESERVED, \"graph\", plan, null, (c) => !isTopLevel(c)),\n topColumns: selectColumns(snapshot.graph, topReserved, \"top-level\", plan, null, isTopLevel),\n position: positionColumn(snapshot),\n graphics: graphicsColumn(snapshot),\n originalIds,\n edgeIds,\n weights: explicitWeights(snapshot),\n folding: pairFolding(snapshot),\n };\n}\n\n/**\n * The GML text of an id written into `graphty_originalId`: quoted for a string, a number text\n * otherwise (an integer as int, else real, so the importer restores the same typed value).\n * @param id - the original id\n * @returns the text\n */\nfunction originalIdText(id: NodeId): string {\n if (typeof id === \"string\") {\n return quoteGmlString(id);\n }\n return Number.isSafeInteger(id) ? formatInteger(id) : formatGmlReal(id, \"f64\");\n}\n\n/**\n * The parts of the document.\n * @param context - the resolved context\n * @yields one string per header line, node or edge\n * @returns nothing\n */\nfunction* gmlParts(context: WriteContext): Generator<string, void, undefined> {\n const { snapshot, plan, ids } = context;\n const w = new GmlWriter(plan.mangle);\n const { meta } = snapshot;\n if (meta.creator !== null) {\n w.line(\"\", \"Creator\", quoteGmlString(meta.creator));\n }\n if (meta.sourceFormat === \"gml\" && meta.sourceVersion !== null) {\n w.line(\"\", \"Version\", versionText(meta.sourceVersion));\n }\n for (const { column, key } of context.topColumns) {\n if (column.isSet(0)) {\n w.cell(\"\", key, column, 0);\n }\n }\n w.raw(\"graph [\");\n w.line(\" \", \"directed\", context.writeDirected ? \"1\" : \"0\");\n const multigraph = meta.declaredMultigraph ?? (snapshot.flags.multigraph ? true : null);\n if (multigraph !== null) {\n w.line(\" \", \"multigraph\", multigraph ? \"1\" : \"0\");\n }\n for (const { column, key } of context.graphColumns) {\n if (column.isSet(0)) {\n w.cell(\" \", key, column, 0);\n }\n }\n yield w.take();\n for (let i = 0; i < snapshot.nodeCount; i++) {\n w.raw(\" node [\");\n w.line(\" \", \"id\", formatInteger(ids.idAt(i) as number));\n if (ids.isChanged(i)) {\n w.line(\" \", ORIGINAL_ID_KEY, originalIdText(ids.originalAt(i)));\n } else if (context.originalIds?.isSet(i)) {\n const original = context.originalIds.value(i);\n if (typeof original === \"string\" || typeof original === \"number\") {\n w.line(\" \", ORIGINAL_ID_KEY, originalIdText(original));\n }\n }\n for (const { column, key } of context.nodeColumns) {\n if (column.isSet(i)) {\n w.cell(\" \", key, column, i);\n }\n }\n writeGraphics(w, context, i);\n w.raw(\" ]\");\n yield w.take();\n }\n const el = snapshot.edgeList();\n const origin = meta.weightOrigin;\n const integerWeights = origin !== null && origin.type === \"int\";\n for (let e = 0; e < snapshot.edgeCount; e++) {\n if (context.foldPairs && context.folding.folded(e)) {\n continue;\n }\n w.raw(\" edge [\");\n w.line(\" \", \"source\", formatInteger(ids.idAt(el.src[e]) as number));\n w.line(\" \", \"target\", formatInteger(ids.idAt(el.dst[e]) as number));\n if (context.edgeIds?.isSet(e)) {\n w.cell(\" \", \"id\", context.edgeIds, e);\n }\n if (context.weights.isExplicit(e)) {\n const weight = context.weights.value(e);\n const text =\n integerWeights && Number.isInteger(weight)\n ? formatInteger(weight)\n : formatGmlReal(weight, context.weights.dtype);\n w.line(\" \", plan.weightKey, text);\n }\n for (const { column, key } of context.edgeColumns) {\n if (column.isSet(e)) {\n w.cell(\" \", key, column, e);\n }\n }\n w.raw(\" ]\");\n yield w.take();\n }\n w.raw(\"]\");\n yield w.take();\n}\n\n/**\n * Write a node's `graphics [ ... ]` record from the position column and the graphics json column.\n * @param w - the writer\n * @param context - the context\n * @param i - the node\n */\nfunction writeGraphics(w: GmlWriter, context: WriteContext, i: number): void {\n const { position, graphics } = context;\n const hasPosition = position?.isSet(i) === true;\n const graphicsValue = graphics?.isSet(i) ? graphics.values[i] : undefined;\n if (!hasPosition) {\n if (graphics !== null && graphicsValue !== undefined) {\n w.cell(\" \", \"graphics\", graphics, i);\n }\n return;\n }\n const numeric = position as Column & { readonly data: ArrayLike<number> };\n const { components } = numeric.meta;\n const lanes = Math.min(components, 3);\n const extra: [string, string][] = [];\n const names = [\"x\", \"y\", \"z\"];\n for (let k = 0; k < lanes; k++) {\n extra.push([names[k], numberText(numeric.data[i * components + k], numeric.meta)]);\n }\n let record: Record<string, unknown> = {};\n if (graphicsValue !== undefined) {\n if (typeof graphicsValue !== \"object\" || graphicsValue === null || Array.isArray(graphicsValue)) {\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n `node ${i}: the graphics value is not a record and cannot hold the position`,\n {\n reason: \"graphics conflict\",\n node: i,\n },\n );\n }\n record = graphicsValue as Record<string, unknown>;\n }\n w.record(\" \", \"graphics\", record, \"graphics\", extra);\n}\n\n/**\n * The GML exporter plugin.\n * @category Built-in formats\n */\nexport const gmlExporter: GraphExporter<GmlExportOptions> = Object.freeze({\n format: \"gml\",\n options: Object.freeze([\"sanitizeKeys\", \"weightKey\"]),\n capabilities: GML_CAPABILITIES,\n styles: Object.freeze({ capabilities: GML_STYLE_CAPABILITIES }),\n /**\n * Pre-flight: the common capability notes, the GML-specific ones and, with styles, the values written as the\n * nearest ones yEd's GML has.\n * @param snapshot - the snapshot\n * @param options - the options\n * @returns the notes, empty when the export is exact\n */\n check(snapshot: GraphSnapshot, options?: GmlWriteOptions): readonly LossNote[] {\n const styled = gmlStyledExport(snapshot, options?.styles);\n if (styled === null) {\n return check(snapshot, options);\n }\n return Object.freeze([...check(styled.snapshot, options), ...styled.notes]);\n },\n /**\n * Write the snapshot as UTF-8 chunks; the context is resolved on the first pull, so the\n * errors check() announced surface from the iteration.\n * @param snapshot - the snapshot\n * @param options - the options\n * @returns the chunks\n */\n export(snapshot: GraphSnapshot, options?: GmlWriteOptions): AsyncIterable<Uint8Array> {\n return encodeChunks(lazyParts(snapshot, options));\n },\n /**\n * Write the snapshot as one string.\n * @param snapshot - the snapshot\n * @param options - the options\n * @returns the document\n */\n exportToString(snapshot: GraphSnapshot, options?: GmlWriteOptions): Promise<string> {\n return joinText(lazyParts(snapshot, options));\n },\n});\n\n/**\n * The document parts, with the context resolved when iteration starts.\n * @param snapshot - the snapshot\n * @param options - the options\n * @yields the parts\n * @returns nothing\n */\nfunction* lazyParts(snapshot: GraphSnapshot, options: GmlWriteOptions | undefined): Generator<string, void, undefined> {\n yield* gmlParts(contextOf(gmlStyledExport(snapshot, options?.styles)?.snapshot ?? snapshot, options));\n}\n","/**\n * How a GML file's `graphics [ x y z ]` positions are spelled, for `extractPositions()`: the node's\n * center in pixels, y growing downward (the GML specification, yFiles and Cytoscape) unless the\n * `Creator` names a y-up tool (Gephi, Tulip).\n */\n\nimport type { GraphSnapshot } from \"@graphty/graph-format\";\n\nimport { toolOf } from \"../../common/units.js\";\nimport { median } from \"../../positions/convert.js\";\nimport type { ImporterPositions } from \"../../positions/types.js\";\n\n/** The json column the importer keeps the rest of each node's graphics record in. */\nconst GRAPHICS_COLUMN = \"graphics\";\n\n/**\n * The spelling of a GML file's positions.\n * @param snapshot - the graph the GML importer read\n * @returns the spelling, or null when no node has a position\n */\nexport function gmlPositions(snapshot: GraphSnapshot): ImporterPositions | null {\n if (snapshot.nodes.byRole(\"position\") === null) {\n return null;\n }\n const tool = toolOf(snapshot.meta.creator);\n return {\n units: \"px\",\n // a z that is the same on every node collapses to 2D\n sourceDims: 3,\n yAxis: tool === \"gephi\" || tool === \"tulip\" ? \"up\" : \"down\",\n tool,\n medianNodeSize: graphicsMedian(snapshot),\n };\n}\n\n/**\n * The median node diameter from the graphics records' `w` and `h`.\n * @param snapshot - the graph\n * @returns the median of each node's mean of w and h, or null when no node has both\n */\nfunction graphicsMedian(snapshot: GraphSnapshot): number | null {\n const graphics = snapshot.nodes.get(GRAPHICS_COLUMN);\n const sizes: number[] = [];\n for (let row = 0; graphics !== null && row < graphics.length; row++) {\n const g = graphics.isSet(row) ? graphics.value(row) : undefined;\n const { w, h } = typeof g === \"object\" && g !== null ? (g as Record<string, unknown>) : {};\n if (typeof w === \"number\" && typeof h === \"number\") {\n sizes.push((w + h) / 2);\n }\n }\n return median(sizes);\n}\n","/**\n * The GML importer (design sections 8.4 and 8.5, research note 07 section 2.2): reads a whole GML\n * text (GML awaits the whole text, 8.4), lexes it once into a typed token list, derives the column\n * schema of every node, edge and graph key in a first walk (GML types are lexical per value, so\n * the column dtype is the union of the value classes seen: `int` -> i32, `real` -> f64, `string`\n * -> string, a nested `[ ]` record -> json, a repeated key -> list; the class is recorded in\n * `origin.type` per column as 8.5 requires), then pushes scalars into the sink in a second walk:\n * every node block first, then every edge block, so node indices follow the file's node order\n * and forward edge references resolve.\n *\n * Conventions honored: NetworkX's `_networkx_list_start` marker and `\"[]\"` empty lists, `&#NN;`\n * character references in strings, `Creator` / `Version` top-level metadata, `directed 0|1` and\n * `multigraph 0|1` graph flags, comments, keys and values on one line or split across lines, and\n * a `graphics [ x y z ]` node record mapped to the `position` role (note 07 section 9) with the\n * remaining graphics keys kept as a json column.\n *\n * Node ids are the `id` keys under `nodeIdFrom: \"id\"`, the `label` under `\"label\"`, and the node's\n * ordinal under `\"index\"`; `source` / `target` always resolve through the `id` keys. The GML spec\n * types ids as integers; a string id (written by NetworkX and Gephi) is accepted under the `ids`\n * rule with one warning per file, and a real or record id is a validation error. A node's\n * `graphty_originalId` key written by the exporter's `sanitizeIds: \"mangle\"` restores the\n * original id under `restoreMangledIds` (the default).\n */\n\nimport {\n type ColumnDecl,\n type ColumnHandle,\n type ColumnRole,\n type Dtype,\n GraphFormatError,\n type GraphSink,\n INVALID_INDEX,\n type NodeId,\n type ScalarDtype,\n} from \"@graphty/graph-format\";\n\nimport { declareResolved, DictHeuristic, uniqueColumnName } from \"../../common/attributes.js\";\nimport { importChosenGraph } from \"../../common/choose.js\";\nimport {\n COLUMN_RENAMED_CODE,\n DUPLICATE_NODE_CODE as SHARED_DUPLICATE_NODE_CODE,\n MISSING_ENDPOINT_CODE as SHARED_MISSING_ENDPOINT_CODE,\n MISSING_ID_CODE as SHARED_MISSING_ID_CODE,\n MULTIPLE_GRAPHS_CODE,\n NO_GRAPH_CODE as SHARED_NO_GRAPH_CODE,\n PRECISION_CODE as SHARED_PRECISION_CODE,\n ROLE_TAKEN_CODE as SHARED_ROLE_TAKEN_CODE,\n WIDENED_CODE as SHARED_WIDENED_CODE,\n} from \"../../common/codes.js\";\nimport { DirectionResolver } from \"../../common/direction.js\";\nimport { IdCoercer } from \"../../common/ids.js\";\nimport { readText, throwIfAborted } from \"../../common/input.js\";\nimport {\n graphChosen,\n type ImportFormatDefaults,\n reportSinkOptions,\n reportUnusedOptions,\n type ResolvedImportOptions,\n resolveImportOptions,\n} from \"../../common/options.js\";\nimport { plural } from \"../../common/plural.js\";\nimport { ImportReportBuilder } from \"../../common/report.js\";\nimport { parseWeightText, reportWeightPrecision, weightFromValue } from \"../../common/weights.js\";\nimport {\n type CommonImportOptions,\n type GraphChoiceOptions,\n type GraphImporter,\n type ImportInput,\n type ImportReport,\n} from \"../../types.js\";\nimport { gmlPositions } from \"./positions.js\";\nimport { gmlStyles } from \"./styles.js\";\nimport {\n EMPTY_LIST_TEXT,\n EMPTY_TUPLE_TEXT,\n GmlSyntaxError,\n type GmlTokens,\n LIST_START_MARKER,\n numberOfText,\n ORIGINAL_ID_KEY,\n parseRecord,\n scalarOrRecord,\n TOKEN_INT,\n TOKEN_OPEN,\n TOKEN_REAL,\n TOKEN_STRING,\n TOKEN_WORD,\n tokenizeGml,\n} from \"./syntax.js\";\n\n/**\n * The format-specific options of the GML importer.\n * @category Built-in formats\n */\nexport interface GmlImportOptions extends GraphChoiceOptions, CommonImportOptions {\n /**\n * Read a node's `graphics [ x y z ]` record as its position; false keeps the whole record as a\n * JSON attribute named `graphics`.\n * @defaultValue true\n */\n positions?: boolean | undefined;\n /**\n * With `positions`, also keep the whole `graphics` record, x / y / z included, as the JSON\n * attribute named `graphics`, so a reader gets both the position and the record as written.\n * @defaultValue false\n */\n keepPositionSource?: boolean | undefined;\n /**\n * Store a text attribute whose values repeat a lot (fewer distinct values than half the rows)\n * as a dictionary column, which uses less memory and reads the same. Such a column reports\n * `meta.dtype` \"dict\" instead of \"string\". A column with a role, such as the `label` column,\n * always stays \"string\".\n * @defaultValue true\n */\n dictionaries?: boolean | undefined;\n}\n\n/**\n * The text holds no `graph [ ... ]` block.\n * @category Issue and loss codes\n */\nexport const NO_GRAPH_CODE = SHARED_NO_GRAPH_CODE;\n/**\n * The text holds more than one `graph [ ... ]` block; import() reads the first, importAll() every one.\n * @category Issue and loss codes\n */\nexport const SECOND_GRAPH_CODE = MULTIPLE_GRAPHS_CODE;\n/**\n * A node block has no `id` key.\n * @category Issue and loss codes\n */\nexport const MISSING_ID_CODE = SHARED_MISSING_ID_CODE;\n/**\n * A node block has no `label` key under `nodeIdFrom: \"label\"`.\n * @category Issue and loss codes\n */\nexport const MISSING_LABEL_CODE = \"E_GML_MISSING_LABEL\";\n/**\n * An edge block has no `source` or no `target` key.\n * @category Issue and loss codes\n */\nexport const MISSING_ENDPOINT_CODE = SHARED_MISSING_ENDPOINT_CODE;\n/**\n * An `id`, `source` or `target` value is neither an integer nor a string.\n * @category Issue and loss codes\n */\nexport const ID_TYPE_CODE = \"E_GML_ID_TYPE\";\n/**\n * Node ids, sources or targets are text, where GML expects integers. They are read under the `ids` option. Reported\n * once per file.\n * @category Issue and loss codes\n */\nexport const STRING_ID_CODE = \"W_GML_STRING_ID\";\n/**\n * A node id (or label under `nodeIdFrom: \"label\"`) is declared twice; later keys overwrite.\n * @category Issue and loss codes\n */\nexport const DUPLICATE_NODE_CODE = SHARED_DUPLICATE_NODE_CODE;\n/**\n * A structural key (`id`, `source`, `target`) appears twice in one block.\n * @category Issue and loss codes\n */\nexport const REPEATED_KEY_CODE = \"E_GML_REPEATED_KEY\";\n/**\n * A `node` or `edge` key whose value is not a `[ ... ]` block.\n * @category Issue and loss codes\n */\nexport const ELEMENT_TYPE_CODE = \"E_GML_ELEMENT_TYPE\";\n/**\n * A `directed` or `multigraph` flag that is not an integer.\n * @category Issue and loss codes\n */\nexport const FLAG_TYPE_CODE = \"E_GML_FLAG_TYPE\";\n/**\n * A `directed` / `multigraph` flag that is not 0 or 1 (read as its truth value), one written as a quoted integer, or\n * one repeated.\n * @category Issue and loss codes\n */\nexport const FLAG_VALUE_CODE = \"W_GML_FLAG_VALUE\";\n\n/** A flag written as a quoted integer, surrounding spaces allowed. */\nconst QUOTED_INT = /^\\s*[+-]?\\d+\\s*$/;\n/**\n * A named entity in a string that is neither an XML nor an ISO-8859-1 HTML entity, or a numeric reference beyond\n * U+10FFFF; it is kept as written.\n * @category Issue and loss codes\n */\nexport const UNKNOWN_ENTITY_CODE = \"W_GML_UNKNOWN_ENTITY\";\n/**\n * A node's `graphics` value cannot give a position as written (not a record, repeated in the node, or with an x / y /\n * z that is not one number); the value is kept in the graphics json column. Warned once per kind of problem, naming\n * the first node.\n * @category Issue and loss codes\n */\nexport const GRAPHICS_CODE = \"W_GML_GRAPHICS\";\n/**\n * A `graph`, `node` or `edge` record inside a node or edge; kept as a json column, not read as structure.\n * @category Issue and loss codes\n */\nexport const NESTED_ELEMENT_CODE = \"W_GML_NESTED_ELEMENT\";\n/**\n * YEd's group keys (`isGroup`, `gid`); kept as plain node columns, the hierarchy is not read as containment.\n * @category Issue and loss codes\n */\nexport const GROUPS_CODE = \"W_GML_GROUPS\";\n/**\n * A key whose values mix numbers and strings; the column is string, the numbers kept as written.\n * @category Issue and loss codes\n */\nexport const WIDENED_CODE = SHARED_WIDENED_CODE;\n/**\n * An integer above 2^53 was stored as the nearest JavaScript number, so its last digits may differ. Pass `long:\n * \"string\"` to keep every digit as text.\n * @category Issue and loss codes\n */\nexport const PRECISION_CODE = SHARED_PRECISION_CODE;\n/**\n * Two attributes would have had the same name, so this one was renamed `<name>#<key>`.\n * @category Plugin helpers\n */\nexport const COLUMN_RENAMED_CODE_GML = COLUMN_RENAMED_CODE;\n/**\n * You read into a graph builder that already has an attribute with this role, so this file's attribute is kept without\n * the role.\n * @category Issue and loss codes\n */\nexport const ROLE_TAKEN_CODE = SHARED_ROLE_TAKEN_CODE;\n/**\n * Under `nodeIdFrom` \"label\" / \"index\" the integer `id` keys are not kept.\n * @category Issue and loss codes\n */\nexport const ID_DROPPED_CODE = \"W_GML_ID_DROPPED\";\n\nconst FORMAT_DEFAULTS: ImportFormatDefaults = { ids: \"canonical\", defaultDirected: false, weightFrom: \"value\" };\n\nconst KIND_INT = 1;\nconst KIND_REAL = 2;\nconst KIND_STRING = 4;\nconst KIND_RECORD = 8;\n\nconst I32_MIN = -2147483648;\nconst I32_MAX = 2147483647;\n\n/** How many elements are pushed between abort-signal checks. */\nconst ABORT_CHECK_INTERVAL = 64;\n\n/** The common options the GML importer reads (the rest is reported by reportUnusedOptions). */\nconst USED_OPTIONS: ReadonlySet<keyof CommonImportOptions> = new Set<keyof CommonImportOptions>([\n \"ids\",\n \"nodeIdFrom\",\n \"addMissingNodes\",\n \"duplicateEdges\",\n \"selfLoops\",\n \"onMixedDirection\",\n \"defaultDirected\",\n \"weightFrom\",\n \"weightDtype\",\n \"restoreMangledIds\",\n \"long\",\n \"errorLimit\",\n \"signal\",\n \"onProgress\",\n]);\n\n/** The element sequence number of the graph block's own keys. */\nconst GRAPH_SEQ = -1;\n/** The element sequence number of the top-level keys. */\nconst TOP_SEQ = -2;\n\n/** The GML value class a column stores. */\ntype GmlKind = \"int\" | \"real\" | \"string\" | \"record\";\n\n/** What the first walk learns about one key of one table. */\ninterface KeySchema {\n /** The key as written. */\n readonly key: string;\n /** The union of value classes seen (KIND_* bits). */\n kinds: number;\n /** Whether the key repeats within one element, or uses a list marker. */\n list: boolean;\n /** The element sequence the key was last seen in. */\n lastSeq: number;\n /** Whether an integer outside the i32 range was seen. */\n wide: boolean;\n /** Whether an integer beyond 2^53 was seen. */\n unsafe: boolean;\n /** The dictionary heuristic while every value is a string, else null. */\n dict: DictHeuristic | null;\n /** Node `graphics` only: some row has numeric x and y. */\n position: boolean;\n /** Node `graphics` only: some row keeps keys besides the position. */\n rest: boolean;\n}\n\n/** The column a key maps to in the second walk. */\ninterface ColumnPlan {\n /** The key as written. */\n readonly key: string;\n /** The column name (renamed `<name>#<key>` when the sink held the name with another shape). */\n name: string;\n /** The column dtype. */\n readonly dtype: Dtype;\n /** The list item dtype, or null. */\n readonly itemDtype: ScalarDtype | null;\n /** How scalar values (or list items) are converted. */\n readonly kind: GmlKind;\n /** Whether the column is a list. */\n readonly list: boolean;\n /** The role, or null. */\n readonly role: ColumnRole | null;\n /** Whether the values come from the top level of the file (graph table only). */\n readonly top: boolean;\n /** Node `graphics` with the position mapping: the position column plan, or null. */\n readonly position: ColumnPlan | null;\n /** Node `graphics` with the position mapping: the json column of the remaining keys, or null. */\n readonly rest: ColumnPlan | null;\n /** The handle once declared. */\n handle: ColumnHandle;\n /** Whether the declaration was attempted (a failed one reuses the sink's column or is null). */\n declared: boolean;\n /** The list items of the current element. */\n items: unknown[] | null;\n /** The element sequence the items belong to. */\n seq: number;\n}\n\n/** A table's plans by key. */\ntype PlanMap = Map<string, ColumnPlan>;\n\n/** Where a node issue is recorded. */\ninterface IssueWhere {\n readonly line: number;\n readonly element: string;\n}\n\n/** The table a GML key belongs to. */\ntype GmlDomain = \"node\" | \"edge\" | \"graph\";\n\n/**\n * Whether a key is the label of a node or edge (text, never a NetworkX list marker).\n * @param domain - the table\n * @param key - the key\n * @returns true for a node or edge label\n */\nfunction isLabel(domain: GmlDomain, key: string): boolean {\n return roleOf(domain, key) === \"label\";\n}\n\n/**\n * Whether a parsed value is a GML record.\n * @param value - the value\n * @returns true for a record object\n */\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * Whether a key gets a role in its table (design section 5.6 applied to GML keys).\n * @param domain - the table\n * @param key - the key\n * @returns the role, or null\n */\nfunction roleOf(domain: GmlDomain, key: string): ColumnRole | null {\n if (key === \"label\" && domain !== \"graph\") {\n return \"label\";\n }\n if (domain === \"edge\") {\n if (key === \"id\") {\n return \"id\";\n }\n if (key === \"key\") {\n return \"key\";\n }\n }\n return null;\n}\n\n/** One import call. */\nclass GmlImport {\n private readonly sink: GraphSink;\n\n private readonly report: ImportReportBuilder;\n\n private readonly options: ResolvedImportOptions;\n\n private readonly positions: boolean;\n\n private readonly keepPositionSource: boolean;\n\n private readonly dictionaries: boolean;\n\n private readonly coercer: IdCoercer;\n\n private tokens: GmlTokens | null = null;\n\n /** How many `graph [ ... ]` blocks the text holds (known after the scan). */\n graphCount = 0;\n\n private resolver: DirectionResolver | null = null;\n\n private readonly nodeSchema = new Map<string, KeySchema>();\n\n private readonly edgeSchema = new Map<string, KeySchema>();\n\n private readonly graphSchema = new Map<string, KeySchema>();\n\n private readonly topSchema = new Map<string, KeySchema>();\n\n private readonly nodePlans: PlanMap = new Map();\n\n private readonly edgePlans: PlanMap = new Map();\n\n private readonly graphPlans: PlanMap = new Map();\n\n private readonly topPlans: PlanMap = new Map();\n\n private readonly graphNames = new Set<string>();\n\n private graphOpen = -1;\n\n private directedToken = -1;\n\n private multigraphToken = -1;\n\n private creatorToken = -1;\n\n private versionToken = -1;\n\n private nodeCount = 0;\n\n private edgeCount = 0;\n\n private weightKinds = 0;\n\n private hasOriginalId = false;\n\n private headerDirected = false;\n\n private seq = 0;\n\n private nodeOrdinal = 0;\n\n private elementsSinceCheck = 0;\n\n /** The sink id every file id maps to when they differ (label / index / restored ids), else null. */\n private idMap: Map<NodeId, NodeId> | null = null;\n\n /** The file ids of node blocks that were skipped: an edge naming one is skipped too, never given a new node. */\n private readonly skippedIds = new Set<NodeId>();\n\n /** Node indices declared by a node block of this import, for duplicate detection. */\n private declared = new Uint32Array(64);\n\n /** The list plans touched by the current node or edge. */\n private readonly touched: ColumnPlan[] = [];\n\n /** The list plans touched by the graph table's keys. */\n private readonly graphTouched: ColumnPlan[] = [];\n\n /** The sequence number of the current node or edge, which its list items belong to. */\n private seqNow = 0;\n\n /**\n * Create one import.\n * @param sink - the sink\n * @param report - the report\n * @param options - the resolved common options\n * @param format - the format-specific options\n * @param which - which `graph [ ... ]` block to read (0: the first)\n */\n constructor(\n sink: GraphSink,\n report: ImportReportBuilder,\n options: ResolvedImportOptions,\n format: GmlImportOptions | undefined,\n private readonly which = 0,\n ) {\n this.sink = sink;\n this.report = report;\n this.options = options;\n this.positions = format?.positions ?? true;\n this.keepPositionSource = format?.keepPositionSource ?? false;\n this.dictionaries = format?.dictionaries ?? true;\n this.coercer = new IdCoercer(options.ids);\n }\n\n /**\n * Run the import over the tokens of a text.\n * @param tokens - the whole text, tokenized (tokenize())\n */\n run(tokens: GmlTokens): void {\n this.tokens = tokens;\n tokens.onUnknownEntity = (entity, line) => {\n this.report.warnOnce(\n \"parse-error\",\n UNKNOWN_ENTITY_CODE,\n `character entity ${entity} cannot be decoded; it is kept as written`,\n { line, element: entity },\n `${UNKNOWN_ENTITY_CODE}:${entity}`,\n );\n };\n this.scan();\n this.push();\n }\n\n // ============================================================ pass 1: the schema\n\n /**\n * Walk the top level: find the graph block, the metadata keys and the top-level attributes,\n * and derive every table's schema.\n */\n private scan(): void {\n const t = this.requireTokens();\n let scalarGraph = -1;\n for (let p = 0; p < t.count; p = t.nextPair(p)) {\n const key = t.textOf(p);\n const v = p + 1;\n const record = t.kind[v] === TOKEN_OPEN;\n if (key === \"graph\" && !record && scalarGraph < 0) {\n scalarGraph = v;\n }\n this.scanTopPair(key, record, v);\n }\n if (this.graphOpen < 0) {\n this.failNoGraph(t, scalarGraph);\n }\n }\n\n /**\n * Handle one top-level pair other than a scalar `graph`.\n * @param key - the key\n * @param record - whether the value is a `[ ... ]` block\n * @param v - the value token\n */\n private scanTopPair(key: string, record: boolean, v: number): void {\n if (key === \"graph\" && record) {\n if (this.graphCount++ === this.which) {\n this.graphOpen = v;\n this.scanGraph(v);\n }\n } else if (key === \"Creator\" && !record && this.creatorToken < 0) {\n this.creatorToken = v;\n } else if (key === \"Version\" && !record && this.versionToken < 0) {\n this.versionToken = v;\n } else {\n this.observe(this.topSchema, \"graph\", key, v, TOP_SEQ);\n }\n }\n\n /**\n * Fail because the input holds no graph block.\n * @param t - the tokens\n * @param scalarGraph - the token of a scalar `graph` key, or -1\n */\n private failNoGraph(t: ReturnType<GmlImport[\"requireTokens\"]>, scalarGraph: number): void {\n if (scalarGraph >= 0) {\n this.report.fail(\n NO_GRAPH_CODE,\n `the graph key at line ${t.line[scalarGraph]} holds ${describeValue(t, scalarGraph)}, not a [ ... ] block; the input contains no graph block`,\n { line: t.line[scalarGraph] },\n );\n }\n this.report.fail(NO_GRAPH_CODE, \"the input contains no graph [ ... ] block\", { line: null });\n }\n\n /**\n * Walk the graph block for the schema.\n * @param open - the index of the block's `[`\n */\n private scanGraph(open: number): void {\n const t = this.requireTokens();\n const close = t.match[open];\n for (let p = open + 1; p < close; p = t.nextPair(p)) {\n const key = t.textOf(p);\n const v = p + 1;\n switch (key) {\n case \"node\":\n if (t.kind[v] === TOKEN_OPEN) {\n this.nodeCount++;\n this.scanElement(\"node\", v);\n }\n break;\n case \"edge\":\n if (t.kind[v] === TOKEN_OPEN) {\n this.edgeCount++;\n this.scanElement(\"edge\", v);\n }\n break;\n case \"directed\":\n if (this.directedToken < 0) {\n this.directedToken = v;\n }\n break;\n case \"multigraph\":\n if (this.multigraphToken < 0) {\n this.multigraphToken = v;\n }\n break;\n default:\n this.observe(this.graphSchema, \"graph\", key, v, GRAPH_SEQ);\n }\n }\n }\n\n /**\n * Walk one node or edge block for the schema.\n * @param domain - node or edge\n * @param open - the block's `[`\n */\n private scanElement(domain: \"node\" | \"edge\", open: number): void {\n const t = this.requireTokens();\n const close = t.match[open];\n const seq = this.seq++;\n const schema = domain === \"node\" ? this.nodeSchema : this.edgeSchema;\n for (let p = open + 1; p < close; p = t.nextPair(p)) {\n const key = t.textOf(p);\n const v = p + 1;\n if (this.skipsKey(domain, key, v)) {\n continue;\n }\n this.observe(schema, domain, key, v, seq);\n }\n }\n\n /**\n * Whether a key of a node or edge block is structural (id, endpoints, weight, original id), not\n * a column; notes the original id and the weight's kinds on the way.\n * @param domain - node or edge\n * @param key - the key\n * @param v - the value token\n * @returns true when the key is not a column\n */\n private skipsKey(domain: \"node\" | \"edge\", key: string, v: number): boolean {\n const { weightFrom, restoreMangledIds } = this.options;\n if (domain === \"node\") {\n if (key === ORIGINAL_ID_KEY && restoreMangledIds) {\n this.hasOriginalId = true;\n return true;\n }\n return key === \"id\";\n }\n if (key === \"source\" || key === \"target\" || key === \"directed\") {\n return true;\n }\n if (key === weightFrom) {\n this.weightKinds |= kindBit(this.requireTokens(), v);\n return true;\n }\n return false;\n }\n\n /**\n * Record one value of one key in a table's schema.\n * @param schema - the table's schema\n * @param domain - the table\n * @param key - the key\n * @param v - the value token\n * @param seq - the element sequence number\n */\n private observe(\n schema: Map<string, KeySchema>,\n domain: \"node\" | \"edge\" | \"graph\",\n key: string,\n v: number,\n seq: number,\n ): void {\n const t = this.requireTokens();\n this.noteStructure(domain, key, v);\n let entry = schema.get(key);\n const graphics = domain === \"node\" && key === \"graphics\" && this.positions;\n if (entry === undefined) {\n entry = {\n key,\n kinds: 0,\n list: false,\n lastSeq: seq,\n wide: false,\n unsafe: false,\n dict: this.dictionaries && roleOf(domain, key) === null ? new DictHeuristic() : null,\n position: false,\n rest: false,\n };\n schema.set(key, entry);\n } else if (entry.lastSeq === seq) {\n entry.list = true;\n // a repeated graphics record: the extra records go to the json column\n entry.rest ||= graphics;\n } else {\n entry.lastSeq = seq;\n }\n if (graphics && t.kind[v] !== TOKEN_OPEN) {\n entry.rest = true;\n }\n switch (t.kind[v]) {\n case TOKEN_STRING: {\n const raw = t.textOf(v);\n // a label is text: \"[]\" there is a label, never NetworkX's empty list\n if (\n raw === LIST_START_MARKER ||\n (!isLabel(domain, key) && (raw === EMPTY_LIST_TEXT || raw === EMPTY_TUPLE_TEXT))\n ) {\n entry.list = true;\n return;\n }\n entry.kinds |= KIND_STRING;\n if (entry.dict !== null && !entry.dict.decided) {\n entry.dict.observe(raw);\n }\n return;\n }\n case TOKEN_INT: {\n entry.kinds |= KIND_INT;\n const n = Number(t.textOf(v));\n if (n < I32_MIN || n > I32_MAX) {\n entry.wide = true;\n if (!Number.isSafeInteger(n)) {\n entry.unsafe = true;\n }\n }\n return;\n }\n case TOKEN_OPEN:\n entry.kinds |= KIND_RECORD;\n if (domain === \"node\" && key === \"graphics\" && this.positions) {\n this.inspectGraphics(entry, v);\n }\n return;\n default: {\n entry.kinds |= KIND_REAL;\n const text = t.textOf(v);\n if (/\\d/.test(text) && !Number.isFinite(Number(text))) {\n this.report.warnOnce(\n \"precision\",\n PRECISION_CODE,\n `${domain} key \"${key}\" holds the real ${text}, beyond the f64 range; it is stored as ${numberOfText(text) > 0 ? \"\" : \"-\"}Infinity`,\n { line: t.line[v], element: key },\n `${PRECISION_CODE}:overflow:${domain}:${key}`,\n );\n }\n }\n }\n }\n\n /**\n * Warn about keys of a node or edge whose meaning GML readers give but this import does not:\n * a nested graph / node / edge record, and yEd's group hierarchy.\n * @param domain - the table\n * @param key - the key\n * @param v - the value token\n */\n private noteStructure(domain: \"node\" | \"edge\" | \"graph\", key: string, v: number): void {\n const t = this.requireTokens();\n if (domain === \"graph\") {\n return;\n }\n if ((key === \"graph\" || key === \"node\" || key === \"edge\") && t.kind[v] === TOKEN_OPEN) {\n this.report.warnOnce(\n \"unsupported\",\n NESTED_ELEMENT_CODE,\n `a nested ${key} record inside a ${domain} is kept as the json column \"${key}\"; it is not read as structure`,\n { line: t.line[v], element: key },\n `${NESTED_ELEMENT_CODE}:${domain}:${key}`,\n );\n } else if (domain === \"node\" && (key === \"isGroup\" || key === \"gid\")) {\n this.report.warnOnce(\n \"unsupported\",\n GROUPS_CODE,\n \"yEd group keys (isGroup, gid) are kept as plain node columns; the group hierarchy is not read as containment\",\n { line: t.line[v], element: key },\n );\n }\n }\n\n /**\n * Note whether a node's graphics record carries a position (numeric x and y) and whether\n * anything besides the position remains.\n * @param entry - the graphics schema entry\n * @param open - the record's `[`\n */\n private inspectGraphics(entry: KeySchema, open: number): void {\n const t = this.requireTokens();\n const close = t.match[open];\n let x = false;\n let y = false;\n let other = false;\n for (let p = open + 1; p < close; p = t.nextPair(p)) {\n const key = t.textOf(p);\n const numeric = t.kind[p + 1] === TOKEN_INT || t.kind[p + 1] === TOKEN_REAL;\n if (key === \"x\" && numeric && !x) {\n x = true;\n } else if (key === \"y\" && numeric && !y) {\n y = true;\n } else if (!(key === \"z\" && numeric)) {\n other = true;\n }\n }\n const positioned = x && y;\n entry.position ||= positioned;\n // with keepPositionSource the whole record, x / y / z included, goes to the json column too\n entry.rest ||= positioned ? other || this.keepPositionSource : true;\n }\n\n // ============================================================ pass 2: the push\n\n /** Declare what the schema needs, set the header and push every element. */\n private push(): void {\n const { sink, report, options } = this;\n const t = this.requireTokens();\n sink.reserve(this.nodeCount, this.edgeCount);\n this.buildPlans();\n this.setMetadata();\n this.headerDirected = this.readFlag(this.directedToken, \"directed\") ?? options.defaultDirected;\n const resolver = new DirectionResolver(sink, report, options.onMixedDirection);\n resolver.setHeader(this.headerDirected, {\n line: this.directedToken >= 0 ? t.line[this.directedToken] : t.line[this.graphOpen],\n });\n this.resolver = resolver;\n if (options.nodeIdFrom !== \"id\" || this.hasOriginalId) {\n this.idMap = new Map();\n }\n if (options.nodeIdFrom !== \"id\") {\n report.loss(\n ID_DROPPED_CODE,\n `node ids taken from the ${options.nodeIdFrom}; the integer id keys are not kept as a column`,\n null,\n this.nodeCount,\n );\n }\n this.pushTopLevel();\n this.pushNodes();\n this.pushEdges();\n }\n\n /** Turn every schema entry into a column plan. */\n private buildPlans(): void {\n for (const [key, entry] of this.nodeSchema) {\n this.nodePlans.set(key, this.planOf(\"node\", entry));\n }\n for (const [key, entry] of this.edgeSchema) {\n this.edgePlans.set(key, this.planOf(\"edge\", entry));\n }\n for (const [key, entry] of this.graphSchema) {\n this.graphPlans.set(key, this.planOf(\"graph\", entry));\n }\n for (const [key, entry] of this.topSchema) {\n this.topPlans.set(key, this.planOf(\"graph\", entry, true));\n }\n }\n\n /**\n * Warn about a key that mixes numbers and strings, or holds integers beyond 2^53.\n * @param domain - the table\n * @param entry - the schema entry\n * @param asText - whether the integers are kept as text\n */\n private warnKinds(domain: \"node\" | \"edge\" | \"graph\", entry: KeySchema, asText: boolean): void {\n if (\n (entry.kinds & KIND_STRING) !== 0 &&\n (entry.kinds & (KIND_INT | KIND_REAL)) !== 0 &&\n (entry.kinds & KIND_RECORD) === 0\n ) {\n this.report.warnOnce(\n \"coercion\",\n WIDENED_CODE,\n `${domain} key \"${entry.key}\" mixes numbers and strings; the column is string and the numbers are kept as written`,\n { element: entry.key },\n `${WIDENED_CODE}:${domain}:${entry.key}`,\n );\n }\n if (entry.unsafe && !asText) {\n this.report.warnOnce(\n \"precision\",\n PRECISION_CODE,\n `${domain} key \"${entry.key}\" holds integers beyond 2^53; they are stored as the nearest f64 (pass long: \"string\" to keep every digit as text)`,\n { element: entry.key },\n `${PRECISION_CODE}:${domain}:${entry.key}`,\n );\n }\n }\n\n /**\n * The plan of a node `graphics` record: the plan plus its position and rest columns.\n * @param plan - the record's plan\n * @param entry - the schema entry\n * @returns the plan with its position (and rest) plans\n */\n private graphicsPlan(plan: ColumnPlan, entry: KeySchema): ColumnPlan {\n const taken = (candidate: string): boolean =>\n this.nodeSchema.has(candidate) || this.sink.nodeColumn(candidate) !== INVALID_INDEX;\n const position: ColumnPlan = {\n ...plan,\n name: uniqueColumnName(\"position\", \"graphics\", taken),\n dtype: \"f64\",\n itemDtype: null,\n kind: \"real\",\n list: false,\n role: \"position\",\n };\n const rest: ColumnPlan | null = entry.rest\n ? { ...plan, dtype: \"json\", itemDtype: null, kind: \"record\", list: false }\n : null;\n return { ...plan, position, rest };\n }\n\n /**\n * The plan of one schema entry.\n * @param domain - the table\n * @param entry - the schema entry\n * @param top - whether the key is a top-level one (graph table)\n * @returns the plan\n */\n private planOf(domain: \"node\" | \"edge\" | \"graph\", entry: KeySchema, top = false): ColumnPlan {\n // long: \"string\" keeps every digit of an integer key that holds values beyond 2^53, as text\n const asText = entry.unsafe && this.options.long === \"string\" && kindOf(entry) === \"int\";\n const kind = asText ? \"string\" : kindOf(entry);\n let scalar: ScalarDtype = dtypeOfKind(kind, entry);\n if (\n scalar === \"string\" &&\n !entry.list &&\n entry.dict !== null &&\n entry.kinds === KIND_STRING &&\n entry.dict.decide() === \"dict\"\n ) {\n scalar = \"dict\";\n }\n this.warnKinds(domain, entry, asText);\n const name = domain === \"graph\" ? this.uniqueGraphName(entry.key) : entry.key;\n let itemDtype: ScalarDtype | null = null;\n if (entry.list) {\n itemDtype = scalar === \"dict\" ? \"string\" : scalar;\n }\n const plan: ColumnPlan = {\n key: entry.key,\n name,\n dtype: entry.list ? \"list\" : scalar,\n itemDtype,\n kind,\n list: entry.list,\n role: roleOf(domain, entry.key),\n top,\n position: null,\n rest: null,\n handle: INVALID_INDEX as ColumnHandle,\n declared: false,\n items: null,\n seq: Number.NEGATIVE_INFINITY,\n };\n if (domain === \"node\" && entry.key === \"graphics\" && this.positions && (entry.kinds & KIND_RECORD) !== 0) {\n return this.graphicsPlan(plan, entry);\n }\n return plan;\n }\n\n /**\n * A graph column name not yet used by this import (top-level and in-graph keys share the table).\n * @param key - the key\n * @returns the name\n */\n private uniqueGraphName(key: string): string {\n const name = uniqueColumnName(key, key, (candidate) => this.graphNames.has(candidate));\n this.graphNames.add(name);\n if (name !== key) {\n this.report.warning(\n \"coercion\",\n COLUMN_RENAMED_CODE_GML,\n `the top-level key \"${key}\" and a key of the graph block share the graph column name; the top-level value is stored as \"${name}\"`,\n { element: key },\n );\n }\n return name;\n }\n\n /** Set the graph metadata: source format, creator, version, multigraph flag, weight origin. */\n private setMetadata(): void {\n const t = this.requireTokens();\n const { sink, options } = this;\n const textOf = (v: number): string => (t.kind[v] === TOKEN_STRING ? t.stringOf(v) : t.textOf(v));\n const multigraph = this.readFlag(this.multigraphToken, \"multigraph\");\n sink.setMeta({\n sourceFormat: \"gml\",\n creator: this.creatorToken >= 0 ? textOf(this.creatorToken) : undefined,\n sourceVersion: this.versionToken >= 0 ? textOf(this.versionToken) : undefined,\n declaredMultigraph: multigraph ?? undefined,\n weightOrigin:\n this.weightKinds !== 0 && options.weightFrom !== null\n ? {\n format: \"gml\",\n id: options.weightFrom,\n title: null,\n type: this.weightKinds === KIND_INT ? \"int\" : \"real\",\n namespace: null,\n }\n : undefined,\n // The header as written, so a reader can say which words set the direction and tell\n // `directed 0` from a file that relies on the specification's default.\n extra: this.directedToken >= 0 ? { gml: { directed: textOf(this.directedToken) } } : undefined,\n });\n }\n\n /**\n * Read a `directed` / `multigraph` flag token.\n * @param v - the value token, or -1 when absent\n * @param name - the flag name, for issues\n * @returns the flag, or null when absent or not an integer\n */\n private readFlag(v: number, name: string): boolean | null {\n if (v < 0) {\n return null;\n }\n const t = this.requireTokens();\n // Files in the wild write the flag as a quoted integer (`directed \"1\"`); read it, with a warning.\n const quoted = t.kind[v] === TOKEN_STRING && QUOTED_INT.test(t.stringOf(v));\n if (quoted) {\n this.report.warning(\n \"validation-error\",\n FLAG_VALUE_CODE,\n `flag \"${name}\" is written as the string ${describeValue(t, v)}; read as an integer`,\n { line: t.line[v], element: name },\n );\n } else if (t.kind[v] !== TOKEN_INT) {\n this.report.error(\n \"validation-error\",\n FLAG_TYPE_CODE,\n `flag \"${name}\" must be the integer 0 or 1, found ${describeValue(t, v)}`,\n { line: t.line[v], element: name },\n );\n return null;\n }\n const n = Number(quoted ? t.stringOf(v) : t.textOf(v));\n if (n !== 0 && n !== 1) {\n this.report.warning(\n \"validation-error\",\n FLAG_VALUE_CODE,\n `flag \"${name}\" is ${n}; read as ${n !== 0 ? \"1\" : \"0\"}`,\n { line: t.line[v], element: name },\n );\n }\n return n !== 0;\n }\n\n /** Push the top-level attributes (every top-level key but graph, Creator and Version). */\n private pushTopLevel(): void {\n const t = this.requireTokens();\n for (let p = 0; p < t.count; p = t.nextPair(p)) {\n const v = p + 1;\n if (v === this.graphOpen || v === this.creatorToken || v === this.versionToken) {\n continue;\n }\n const plan = this.topPlans.get(t.textOf(p));\n if (plan !== undefined) {\n this.writeGraph(plan, v, TOP_SEQ);\n }\n }\n this.flushGraphLists();\n }\n\n /** Push every node block and the graph block's own attributes, in file order. */\n private pushNodes(): void {\n const t = this.requireTokens();\n const close = t.match[this.graphOpen];\n for (let p = this.graphOpen + 1; p < close; p = t.nextPair(p)) {\n const key = t.textOf(p);\n const v = p + 1;\n switch (key) {\n case \"node\":\n if (t.kind[v] === TOKEN_OPEN) {\n this.importNode(v);\n } else {\n this.badElement(\"node\", p);\n this.report.counts.skippedNodes++;\n }\n break;\n case \"edge\":\n break;\n case \"directed\":\n case \"multigraph\":\n if (v !== this.directedToken && v !== this.multigraphToken) {\n this.report.warning(\n \"validation-error\",\n FLAG_VALUE_CODE,\n `graph flag \"${key}\" repeated; the first value stands`,\n { line: t.line[p], element: key },\n );\n }\n break;\n default: {\n const plan = this.graphPlans.get(key);\n if (plan !== undefined) {\n this.writeGraph(plan, v, GRAPH_SEQ);\n }\n }\n }\n }\n this.flushGraphLists();\n }\n\n /** Push every edge block, in file order. */\n private pushEdges(): void {\n const t = this.requireTokens();\n const close = t.match[this.graphOpen];\n let ordinal = 0;\n for (let p = this.graphOpen + 1; p < close; p = t.nextPair(p)) {\n if (t.textOf(p) !== \"edge\") {\n continue;\n }\n const v = p + 1;\n if (t.kind[v] === TOKEN_OPEN) {\n this.importEdge(v, ordinal);\n } else {\n this.badElement(\"edge\", p);\n this.report.counts.skippedEdges++;\n }\n ordinal++;\n }\n }\n\n /**\n * Record a `node` / `edge` key whose value is not a block.\n * @param what - node or edge\n * @param p - the key token\n */\n private badElement(what: string, p: number): void {\n const t = this.requireTokens();\n this.report.error(\n \"validation-error\",\n ELEMENT_TYPE_CODE,\n `${what} must be a [ ... ] block, found ${describeValue(t, p + 1)}`,\n { line: t.line[p], element: what },\n );\n }\n\n /**\n * Push one node block.\n * @param open - the block's `[`\n */\n private importNode(open: number): void {\n const t = this.requireTokens();\n const { sink, report, options } = this;\n const close = t.match[open];\n const line = t.line[open];\n const ordinal = this.nodeOrdinal++;\n this.checkAbort();\n let index: number;\n let sinkId: NodeId;\n let fileId: NodeId | undefined;\n try {\n let idTok = -1;\n let labelTok = -1;\n let originalTok = -1;\n for (let p = open + 1; p < close; p = t.nextPair(p)) {\n const key = t.textOf(p);\n if (key === \"id\") {\n idTok = this.structuralToken(idTok, p, \"id\");\n } else if (key === \"label\") {\n labelTok = labelTok < 0 ? p + 1 : labelTok;\n } else if (key === ORIGINAL_ID_KEY && options.restoreMangledIds) {\n originalTok = originalTok < 0 ? p + 1 : originalTok;\n }\n }\n if (idTok < 0) {\n throw new GraphFormatError(\"E_INVALID_ID\", \"node has no id\", { reason: \"missing id\" });\n }\n // the file id under the ids rule, so `id 1` and `source \"1\"` meet in idMap (except under\n // \"keep\", where the integer 1 and the string \"1\" are different ids by design)\n fileId = this.coerceFileId(idTok, this.fileIdOf(idTok, \"id\"));\n if (originalTok >= 0) {\n sinkId = this.restoredId(originalTok);\n } else {\n switch (options.nodeIdFrom) {\n case \"label\":\n if (labelTok < 0) {\n throw new GraphFormatError(\"E_INVALID_ID\", \"node has no label\", {\n reason: \"missing label\",\n });\n }\n sinkId = this.coerceValueToken(labelTok);\n break;\n case \"index\":\n sinkId = ordinal;\n break;\n default:\n sinkId = fileId;\n }\n }\n index = sink.addNode(sinkId);\n if (this.idMap !== null) {\n const before = this.idMap.get(fileId);\n if (before !== undefined && before !== sinkId) {\n report.warning(\n \"merged\",\n DUPLICATE_NODE_CODE,\n `file id ${JSON.stringify(fileId)} is declared twice (nodes ${JSON.stringify(before)} and ${JSON.stringify(sinkId)}); edges to it resolve to the later`,\n { line, element: String(fileId) },\n );\n }\n this.idMap.set(fileId, sinkId);\n }\n } catch (err) {\n this.recordNodeError(err, line);\n report.counts.skippedNodes++;\n if (fileId !== undefined) {\n this.skippedIds.add(fileId);\n }\n return;\n }\n if (this.isDeclared(index)) {\n report.warning(\n \"merged\",\n DUPLICATE_NODE_CODE,\n `node ${JSON.stringify(sinkId)} is declared twice; later keys overwrite`,\n { line, element: String(sinkId) },\n );\n } else {\n this.markDeclared(index);\n report.counts.nodes++;\n }\n this.beginElement(this.seq++);\n try {\n const graphics: number[] = [];\n let graphicsPlan: ColumnPlan | null = null;\n for (let p = open + 1; p < close; p = t.nextPair(p)) {\n const key = t.textOf(p);\n if (key === \"id\" || (key === ORIGINAL_ID_KEY && options.restoreMangledIds)) {\n continue;\n }\n const plan = this.nodePlans.get(key);\n if (plan !== undefined && plan.position !== null) {\n graphicsPlan = plan;\n graphics.push(p + 1);\n } else if (plan !== undefined) {\n this.writeNode(plan, index, p + 1);\n }\n }\n if (graphicsPlan !== null) {\n this.writeGraphics(graphicsPlan, index, graphics, {\n line: t.line[graphics[0]],\n element: String(sinkId),\n });\n }\n this.flushLists(\"node\", index);\n } catch (err) {\n this.touched.length = 0;\n report.recordError(err, { line, element: String(sinkId) });\n }\n }\n\n /**\n * Push one edge block.\n * @param open - the block's `[`\n * @param ordinal - the edge's ordinal among edge blocks, for messages\n */\n private importEdge(open: number, ordinal: number): void {\n const t = this.requireTokens();\n const { sink, report, options } = this;\n const close = t.match[open];\n const line = t.line[open];\n const element = `edge #${ordinal}`;\n this.checkAbort();\n let edge: number;\n try {\n let sourceTok = -1;\n let targetTok = -1;\n let weightTok = -1;\n let directedTok = -1;\n for (let p = open + 1; p < close; p = t.nextPair(p)) {\n const key = t.textOf(p);\n if (key === \"source\") {\n sourceTok = this.structuralToken(sourceTok, p, \"source\");\n } else if (key === \"target\") {\n targetTok = this.structuralToken(targetTok, p, \"target\");\n } else if (key === \"directed\") {\n directedTok = this.structuralToken(directedTok, p, \"directed\");\n } else if (key === options.weightFrom) {\n weightTok = p + 1;\n }\n }\n if (sourceTok < 0 || targetTok < 0) {\n throw new GraphFormatError(\"E_UNKNOWN_NODE\", `edge has no ${sourceTok < 0 ? \"source\" : \"target\"}`, {\n reason: \"missing endpoint\",\n });\n }\n const source = this.endpoint(sourceTok, \"source\");\n const target = this.endpoint(targetTok, \"target\");\n const weight = weightTok >= 0 ? this.weightOf(weightTok) : undefined;\n const before = sink.edgeCount;\n const sourceNew = sink.indexOf(source) === INVALID_INDEX;\n const targetNew = source !== target && sink.indexOf(target) === INVALID_INDEX;\n // an edge-level `directed` key overrides the graph's flag for that edge (mixed graphs)\n const directed = this.readFlag(directedTok, \"directed\") ?? this.headerDirected;\n edge = this.requireResolver().addEdge(source, target, directed ? \"directed\" : \"undirected\", weight, {\n line,\n element,\n });\n report.counts.edges += sink.edgeCount - before;\n // endpoints the file never declares (addMissingNodes) are nodes of the sink too\n report.counts.nodes += (sourceNew ? 1 : 0) + (targetNew ? 1 : 0);\n } catch (err) {\n this.recordEdgeError(err, line, element);\n report.counts.skippedEdges++;\n return;\n }\n this.beginElement(this.seq++);\n try {\n for (let p = open + 1; p < close; p = t.nextPair(p)) {\n const key = t.textOf(p);\n if (key === \"source\" || key === \"target\" || key === \"directed\" || key === options.weightFrom) {\n continue;\n }\n const plan = this.edgePlans.get(key);\n if (plan !== undefined) {\n this.writeEdge(plan, edge, p + 1);\n }\n }\n this.flushLists(\"edge\", edge);\n } catch (err) {\n this.touched.length = 0;\n report.recordError(err, { line, element });\n }\n }\n\n // ============================================================ ids and weights\n\n /**\n * Note a structural key token, refusing a repeat.\n * @param previous - the token seen before, or -1\n * @param p - the key token\n * @param key - the key name\n * @returns the value token\n */\n private structuralToken(previous: number, p: number, key: string): number {\n if (previous >= 0) {\n throw new GraphFormatError(\"E_INVALID_ID\", `key \"${key}\" appears twice in one block`, {\n reason: \"duplicate key\",\n key,\n });\n }\n return p + 1;\n }\n\n /**\n * The value of an id / source / target token: an integer (the GML spec's type) as a number, a\n * string (NetworkX and Gephi write them) as its text with one warning per file.\n * @param v - the value token\n * @param key - the key name, for the error\n * @returns the number or the string\n */\n private fileIdOf(v: number, key: string): number | string {\n const t = this.requireTokens();\n if (t.kind[v] === TOKEN_STRING) {\n this.report.warnOnce(\n \"validation-error\",\n STRING_ID_CODE,\n `${key} is the string \"${t.textOf(v)}\"; GML ids are integers, string ids are kept under the ids rule`,\n { line: t.line[v], element: t.stringOf(v) },\n );\n return t.stringOf(v);\n }\n if (t.kind[v] !== TOKEN_INT) {\n throw new GraphFormatError(\n \"E_INVALID_ID\",\n `${key} must be an integer or a string, found ${describeValue(t, v)}`,\n {\n reason: \"not an integer\",\n key,\n value: t.kind[v] === TOKEN_OPEN ? \"[...]\" : t.textOf(v),\n },\n );\n }\n return Number(t.textOf(v));\n }\n\n /**\n * Coerce an id / source / target value under the `ids` rule: a string by its text, an integer\n * through coerceInteger().\n * @param v - the value token\n * @param id - its value (fileIdOf())\n * @returns the id\n */\n private coerceFileId(v: number, id: number | string): NodeId {\n return typeof id === \"string\" ? this.coercer.text(id) : this.coerceInteger(v, id);\n }\n\n /**\n * Coerce an integer id token under the `ids` rule: a safe integer passes as a typed number\n * (so `01` is 1 and `-0` is 0), a larger one goes through the text rule (a string under\n * \"canonical\"), and \"string\" keeps the text as written.\n * @param v - the value token\n * @param n - its numeric value\n * @returns the id\n */\n private coerceInteger(v: number, n: number): NodeId {\n if (Number.isSafeInteger(n) && this.coercer.mode !== \"string\") {\n return this.coercer.value(n);\n }\n return this.coercer.text(this.requireTokens().textOf(v));\n }\n\n /**\n * Coerce a label token under the `ids` rule: a string by its text, a number as a typed value.\n * @param v - the value token\n * @returns the id\n */\n private coerceValueToken(v: number): NodeId {\n const t = this.requireTokens();\n switch (t.kind[v]) {\n case TOKEN_STRING:\n return this.coercer.text(t.stringOf(v));\n case TOKEN_INT:\n return this.coerceInteger(v, Number(t.textOf(v)));\n case TOKEN_OPEN:\n throw new GraphFormatError(\"E_INVALID_ID\", \"label must be a string or a number, found a record\", {\n reason: \"record label\",\n });\n default:\n return this.coercer.value(numberOfText(t.textOf(v)));\n }\n }\n\n /**\n * The id a `graphty_originalId` key restores: typed, never coerced (the exporter wrote it exactly).\n * @param v - the value token\n * @returns the original id\n */\n private restoredId(v: number): NodeId {\n const t = this.requireTokens();\n switch (t.kind[v]) {\n case TOKEN_STRING:\n return t.stringOf(v);\n case TOKEN_OPEN:\n throw new GraphFormatError(\"E_INVALID_ID\", `${ORIGINAL_ID_KEY} must be a string or a number`, {\n reason: \"record original id\",\n });\n default:\n return numberOfText(t.textOf(v));\n }\n }\n\n /**\n * Resolve a source / target token to a sink id.\n * @param v - the value token\n * @param key - source or target\n * @returns the id\n */\n private endpoint(v: number, key: string): NodeId {\n const id = this.coerceFileId(v, this.fileIdOf(v, key));\n const mapped = this.idMap?.get(id);\n if (mapped !== undefined) {\n return mapped;\n }\n if (this.skippedIds.has(id)) {\n // the node block was skipped: creating the endpoint would bring the node back under\n // its raw file id (beside label ids under nodeIdFrom \"label\")\n throw new GraphFormatError(\n \"E_UNKNOWN_NODE\",\n `${key} ${JSON.stringify(id)} names a node block that was skipped after an error`,\n { reason: \"skipped node\", id },\n );\n }\n return id;\n }\n\n /**\n * The weight of an edge from its weight token.\n * @param v - the value token\n * @returns the weight; E_INVALID_WEIGHT for a record or non-numeric text\n */\n private weightOf(v: number): number | undefined {\n const t = this.requireTokens();\n switch (t.kind[v]) {\n case TOKEN_STRING:\n return parseWeightText(t.stringOf(v), this.report);\n case TOKEN_OPEN:\n throw new GraphFormatError(\"E_INVALID_WEIGHT\", \"edge weight is a record\", { value: \"[...]\" });\n default: {\n const text = t.textOf(v);\n const weight = weightFromValue(numberOfText(text));\n if (weight !== undefined) {\n reportWeightPrecision(text, weight, this.report);\n }\n return weight;\n }\n }\n }\n\n /**\n * Record a node-level error under the GML code it implies.\n * @param err - the thrown value\n * @param line - the block's line\n */\n private recordNodeError(err: unknown, line: number): void {\n const { report } = this;\n if (err instanceof GraphFormatError && err.code === \"E_INVALID_ID\") {\n const { reason } = err.details;\n switch (reason) {\n case \"missing id\":\n report.error(\"missing-value\", MISSING_ID_CODE, err.message, { line, element: \"node\" });\n return;\n case \"missing label\":\n report.error(\"missing-value\", MISSING_LABEL_CODE, err.message, { line, element: \"node\" });\n return;\n case \"duplicate key\":\n report.error(\"validation-error\", REPEATED_KEY_CODE, err.message, { line, element: \"node\" });\n return;\n case \"not an integer\":\n report.error(\"validation-error\", ID_TYPE_CODE, err.message, { line, element: \"node\" });\n return;\n default:\n break;\n }\n }\n report.recordError(err, { line, element: \"node\" });\n }\n\n /**\n * Record an edge-level error under the GML code it implies.\n * @param err - the thrown value\n * @param line - the block's line\n * @param element - the edge description\n */\n private recordEdgeError(err: unknown, line: number, element: string): void {\n const { report } = this;\n if (err instanceof GraphFormatError) {\n const { reason } = err.details;\n if (err.code === \"E_UNKNOWN_NODE\" && reason === \"missing endpoint\") {\n report.error(\"missing-value\", MISSING_ENDPOINT_CODE, err.message, { line, element });\n return;\n }\n if (err.code === \"E_INVALID_ID\" && reason === \"duplicate key\") {\n report.error(\"validation-error\", REPEATED_KEY_CODE, err.message, { line, element });\n return;\n }\n if (err.code === \"E_INVALID_ID\" && reason === \"not an integer\") {\n report.error(\"validation-error\", ID_TYPE_CODE, err.message, { line, element });\n return;\n }\n }\n report.recordError(err, { line, element });\n }\n\n // ============================================================ values\n\n /**\n * Write one node value.\n * @param plan - the key's plan\n * @param index - the node index\n * @param v - the value token\n */\n private writeNode(plan: ColumnPlan, index: number, v: number): void {\n if (plan.list) {\n this.collectItem(plan, v, this.seqNow, this.touched);\n return;\n }\n this.sink.setNodeValue(this.handleOf(plan, \"node\"), index, this.scalarOf(plan, v));\n }\n\n /**\n * Write one edge value.\n * @param plan - the key's plan\n * @param edge - the edge index\n * @param v - the value token\n */\n private writeEdge(plan: ColumnPlan, edge: number, v: number): void {\n if (plan.list) {\n this.collectItem(plan, v, this.seqNow, this.touched);\n return;\n }\n this.sink.setEdgeValue(this.handleOf(plan, \"edge\"), edge, this.scalarOf(plan, v));\n }\n\n /**\n * Write one graph value.\n * @param plan - the key's plan\n * @param v - the value token\n * @param seq - TOP_SEQ or GRAPH_SEQ\n */\n private writeGraph(plan: ColumnPlan, v: number, seq: number): void {\n if (plan.list) {\n this.collectItem(plan, v, seq, this.graphTouched);\n return;\n }\n const value = this.scalarOf(plan, v);\n this.sink.setGraphValue(plan.name, value, graphDecl(plan));\n if (seq === GRAPH_SEQ && plan.key === \"name\" && typeof value === \"string\") {\n // the graph block's `name` is the graph's name too (snapshot.meta.name, and what graphName matches)\n this.sink.setMeta({ name: value });\n }\n }\n\n /**\n * Write a node's graphics values: the position column from the x / y / z of the first record,\n * everything else (the remaining keys, a value that is not a record, a repeated record) to the\n * json column, with a warning when the value cannot give a position as written.\n * @param plan - the graphics plan\n * @param index - the node index\n * @param vs - the value tokens of the node's graphics keys, in order\n * @param where - the line and the node, for issues\n */\n private writeGraphics(plan: ColumnPlan, index: number, vs: readonly number[], where: IssueWhere): void {\n const t = this.requireTokens();\n const { sink } = this;\n const values = vs.map((v) => (t.kind[v] === TOKEN_OPEN ? parseRecord(t, v) : this.scalarOf(plan, v)));\n const first = values[0];\n const positionPlan = plan.position;\n let rest: unknown = first;\n if (isRecord(first) && positionPlan !== null) {\n const left = this.writePosition(positionPlan, index, this.keepPositionSource ? { ...first } : first, where);\n rest = this.keepPositionSource ? first : left;\n } else if (!isRecord(first)) {\n this.graphicsWarning(\"scalar\", `node ${where.element}'s graphics is not a record`, where);\n }\n if (values.length > 1) {\n this.graphicsWarning(\n \"repeated\",\n `node ${where.element} has ${values.length} graphics records; the position comes from the first`,\n where,\n );\n rest = values;\n }\n if (rest !== undefined && plan.rest !== null) {\n sink.setNodeValue(this.handleOf(plan.rest, \"node\"), index, rest);\n }\n }\n\n /**\n * Write a node's position from the x / y / z of its graphics record, taking them out of it.\n * @param positionPlan - the position column's plan\n * @param index - the node index\n * @param record - the graphics record\n * @param where - the line and the node, for issues\n * @returns what is left of the record for the json column, or undefined when nothing is\n */\n private writePosition(\n positionPlan: ColumnPlan,\n index: number,\n record: Record<string, unknown>,\n where: IssueWhere,\n ): unknown {\n const { x, y, z } = record;\n let rest: unknown = record;\n if (typeof x === \"number\" && typeof y === \"number\") {\n const depth = typeof z === \"number\" ? z : 0;\n this.sink.setNodeValue(this.handleOf(positionPlan, \"node\"), index, [x, y, depth]);\n delete record.x;\n delete record.y;\n if (typeof z === \"number\") {\n delete record.z;\n }\n rest = Object.keys(record).length > 0 ? record : undefined;\n }\n if (\"x\" in record || \"y\" in record || \"z\" in record) {\n this.graphicsWarning(\n \"coordinate\",\n `node ${where.element}'s graphics x / y / z is not one number each`,\n where,\n );\n }\n return rest;\n }\n\n /**\n * Warn once per kind of graphics problem.\n * @param kind - the problem\n * @param what - the message start, naming the node\n * @param where - the line and the node\n */\n private graphicsWarning(kind: string, what: string, where: IssueWhere): void {\n this.report.warnOnce(\n \"validation-error\",\n GRAPHICS_CODE,\n `${what}; the value is kept in the graphics json column (warned once for every such node)`,\n where,\n `${GRAPHICS_CODE}:${kind}`,\n );\n }\n\n /**\n * Collect one list item.\n * @param plan - the list plan\n * @param v - the value token\n * @param seq - the sequence number of the element the item belongs to\n * @param touched - the plans touched by that element\n */\n private collectItem(plan: ColumnPlan, v: number, seq: number, touched: ColumnPlan[]): void {\n const t = this.requireTokens();\n if (plan.seq !== seq) {\n plan.seq = seq;\n plan.items = [];\n touched.push(plan);\n }\n if (t.kind[v] === TOKEN_STRING) {\n const raw = t.textOf(v);\n if (raw === LIST_START_MARKER || raw === EMPTY_LIST_TEXT || raw === EMPTY_TUPLE_TEXT) {\n return;\n }\n }\n (plan.items as unknown[]).push(this.scalarOf(plan, v));\n }\n\n /**\n * Start a node or edge: later list items belong to it.\n * @param seq - the element's sequence number\n */\n private beginElement(seq: number): void {\n this.seqNow = seq;\n this.touched.length = 0;\n }\n\n /**\n * Write the lists collected for the current node or edge.\n * @param domain - node or edge\n * @param row - the row\n */\n private flushLists(domain: \"node\" | \"edge\", row: number): void {\n const { sink, touched } = this;\n for (const plan of touched) {\n const handle = this.handleOf(plan, domain);\n if (domain === \"node\") {\n sink.setNodeValue(handle, row, plan.items);\n } else {\n sink.setEdgeValue(handle, row, plan.items);\n }\n plan.items = null;\n }\n touched.length = 0;\n }\n\n /** Write the lists collected for the graph table. */\n private flushGraphLists(): void {\n const { sink, graphTouched } = this;\n for (const plan of graphTouched) {\n sink.setGraphValue(plan.name, plan.items, graphDecl(plan));\n plan.items = null;\n }\n graphTouched.length = 0;\n }\n\n /**\n * The JS value of a scalar value token (or list item) under a plan's storage class.\n * @param plan - the plan\n * @param v - the value token\n * @returns the value to push\n */\n private scalarOf(plan: ColumnPlan, v: number): unknown {\n const t = this.requireTokens();\n const kind = t.kind[v];\n switch (plan.kind) {\n case \"int\":\n return Number(t.textOf(v));\n case \"real\":\n return numberOfText(t.textOf(v));\n case \"string\":\n return kind === TOKEN_STRING ? t.stringOf(v) : t.textOf(v);\n default:\n return kind === TOKEN_STRING ? t.stringOf(v) : scalarOrRecord(t, v);\n }\n }\n\n /**\n * The handle of a plan's column, declaring it on first use. A declaration the sink refuses\n * because a column of the name exists with another declaration falls back to that column\n * (reported once); a taken role is dropped (reported once).\n * @param plan - the plan\n * @param domain - node or edge\n * @returns the handle\n */\n private handleOf(plan: ColumnPlan, domain: \"node\" | \"edge\"): ColumnHandle {\n if (plan.declared) {\n return plan.handle;\n }\n plan.declared = true;\n const { sink, report } = this;\n const decl: ColumnDecl = {\n name: plan.name,\n dtype: plan.dtype,\n nullable: true,\n origin: { format: \"gml\", id: plan.key, title: null, type: originTypeOf(plan), namespace: null },\n };\n if (plan.list) {\n decl.itemDtype = plan.itemDtype ?? \"string\";\n }\n if (plan.role === \"position\") {\n decl.components = 3;\n }\n if (plan.role !== null) {\n decl.role = plan.role;\n }\n const resolved = declareResolved(sink, domain, decl, report, { element: plan.name });\n plan.handle = resolved.handle;\n if (resolved.renamed) {\n plan.name = resolved.decl.name;\n }\n return plan.handle;\n }\n\n // ============================================================ bookkeeping\n\n /**\n * Whether a node index was declared by a node block of this import.\n * @param index - the node index\n * @returns true when declared\n */\n private isDeclared(index: number): boolean {\n const word = index >>> 5;\n return word < this.declared.length && ((this.declared[word] >>> (index & 31)) & 1) === 1;\n }\n\n /**\n * Mark a node index as declared.\n * @param index - the node index\n */\n private markDeclared(index: number): void {\n const word = index >>> 5;\n if (word >= this.declared.length) {\n const grown = new Uint32Array(Math.max(word + 1, this.declared.length * 2));\n grown.set(this.declared);\n this.declared = grown;\n }\n this.declared[word] |= 1 << (index & 31);\n }\n\n /** Check the abort signal every ABORT_CHECK_INTERVAL elements. */\n private checkAbort(): void {\n if (++this.elementsSinceCheck >= ABORT_CHECK_INTERVAL) {\n this.elementsSinceCheck = 0;\n throwIfAborted(this.options.signal);\n }\n }\n\n /**\n * The tokens, which exist after run() lexed the text.\n * @returns the tokens\n */\n private requireTokens(): GmlTokens {\n if (this.tokens === null) {\n throw new GraphFormatError(\"E_UNSUPPORTED\", \"the GML text was not lexed\", { reason: \"no tokens\" });\n }\n return this.tokens;\n }\n\n /**\n * The direction resolver, which exists once the header was set.\n * @returns the resolver\n */\n private requireResolver(): DirectionResolver {\n if (this.resolver === null) {\n throw new GraphFormatError(\"E_DIRECTED\", \"the header was not set\", { reason: \"no resolver\" });\n }\n return this.resolver;\n }\n}\n\n/**\n * The KIND_* bit of a value token.\n * @param t - the tokens\n * @param v - the value token\n * @returns the bit\n */\nfunction kindBit(t: GmlTokens, v: number): number {\n switch (t.kind[v]) {\n case TOKEN_INT:\n return KIND_INT;\n case TOKEN_STRING:\n return KIND_STRING;\n case TOKEN_OPEN:\n return KIND_RECORD;\n default:\n return KIND_REAL;\n }\n}\n\n/**\n * The storage class of a schema entry: the widest value class seen.\n * @param entry - the entry\n * @returns the class\n */\nfunction kindOf(entry: KeySchema): GmlKind {\n if ((entry.kinds & KIND_RECORD) !== 0) {\n return \"record\";\n }\n if ((entry.kinds & KIND_STRING) !== 0) {\n return \"string\";\n }\n if ((entry.kinds & KIND_REAL) !== 0) {\n return \"real\";\n }\n return \"int\";\n}\n\n/**\n * The scalar dtype of a storage class.\n * @param kind - the class\n * @param entry - the entry (a wide int keeps origin int but stores f64)\n * @returns the dtype\n */\nfunction dtypeOfKind(kind: GmlKind, entry: KeySchema): ScalarDtype {\n switch (kind) {\n case \"int\":\n return entry.wide ? \"f64\" : \"i32\";\n case \"real\":\n return \"f64\";\n case \"string\":\n return \"string\";\n default:\n return \"json\";\n }\n}\n\n/**\n * The origin.type text of a plan: the GML value class of its values (`int` for wide integers\n * stored as f64 too, so the exporter writes them without a decimal point).\n * @param plan - the plan\n * @returns the type text\n */\nfunction originTypeOf(plan: ColumnPlan): string {\n return plan.kind;\n}\n\n/**\n * The declaration patch of a graph column.\n * @param plan - the plan\n * @returns the decl for setGraphValue\n */\nfunction graphDecl(plan: ColumnPlan): ColumnDecl {\n const decl: ColumnDecl = {\n name: plan.name,\n dtype: plan.dtype,\n nullable: true,\n origin: { format: \"gml\", id: plan.key, title: null, type: originTypeOf(plan), namespace: null },\n };\n if (plan.list) {\n decl.itemDtype = plan.itemDtype ?? \"string\";\n }\n if (plan.top) {\n decl.extra = { gmlTopLevel: true };\n }\n return decl;\n}\n\n/**\n * A short description of a value token for messages.\n * @param t - the tokens\n * @param v - the value token\n * @returns the description\n */\nfunction describeValue(t: GmlTokens, v: number): string {\n switch (t.kind[v]) {\n case TOKEN_OPEN:\n return \"a record\";\n case TOKEN_STRING:\n return `the string \"${t.textOf(v)}\"`;\n case TOKEN_REAL:\n return `the real ${t.textOf(v)}`;\n case TOKEN_WORD:\n return `the word ${t.textOf(v)}`;\n default:\n return t.textOf(v);\n }\n}\n\nconst SNIFF_GRAPH_START = /^(?:\\s|#[^\\n]*\\n)*graph\\s*\\[/;\nconst SNIFF_GRAPH_ANYWHERE = /(?:^|\\s)graph\\s*\\[/;\nconst SNIFF_KEY_START = /^(?:\\s|#[^\\n]*\\n)*[A-Za-z_]\\w*\\s+(?:\"|[+-]?[0-9.]|\\[)/;\n\n/**\n * Confidence that a head of bytes is GML: a `graph [` opener, or key-value text with a `graph [`\n * somewhere in the head.\n * @param head - the first bytes of the input\n * @returns 0.95 for a leading `graph [`, 0.85 for key-value text containing one, 0.4 for key-value text, 0 otherwise\n */\nfunction sniffGml(head: Uint8Array): number {\n let text = new TextDecoder(\"utf-8\", { fatal: false }).decode(head);\n if (text.charCodeAt(0) === 0xfeff) {\n text = text.slice(1);\n }\n if (SNIFF_GRAPH_START.test(text)) {\n return 0.95;\n }\n if (SNIFF_KEY_START.test(text)) {\n return SNIFF_GRAPH_ANYWHERE.test(text) ? 0.85 : 0.4;\n }\n return 0;\n}\n\n/**\n * The GML importer plugin.\n * @category Built-in formats\n */\nexport const gmlImporter: GraphImporter<GmlImportOptions> = Object.freeze({\n format: \"gml\",\n options: Object.freeze([\"dictionaries\", \"keepPositionSource\", \"positions\"]),\n extensions: Object.freeze([\".gml\"]),\n mimeTypes: Object.freeze([\"text/x-gml\", \"text/plain\"]),\n sniff: sniffGml,\n styles: gmlStyles,\n positions: gmlPositions,\n /**\n * Read a GML text into a sink.\n * @param input - the text, bytes or stream\n * @param sink - the sink\n * @param options - format-specific and common options\n * @returns the report\n */\n async import(\n input: ImportInput,\n sink: GraphSink,\n options?: GmlImportOptions & CommonImportOptions,\n ): Promise<ImportReport> {\n if (graphChosen(options)) {\n // the choice is honored here too, not only by the registry\n return importChosenGraph(gmlImporter, input, sink, options);\n }\n const resolved = resolveImportOptions(options, FORMAT_DEFAULTS);\n const report = new ImportReportBuilder(\"gml\", resolved.errorLimit);\n reportSinkOptions(sink, options, report);\n reportUnusedOptions(options, report, USED_OPTIONS);\n const tokens = tokenize(await readText(input, report, resolved), report);\n throwIfAborted(resolved.signal);\n const gml = new GmlImport(sink, report, resolved, options);\n gml.run(tokens);\n if (gml.graphCount > 1) {\n report.warning(\n \"unsupported\",\n SECOND_GRAPH_CODE,\n `the input holds ${gml.graphCount - 1} more graph block${plural(gml.graphCount - 1)} after the first; the first is read (graphIndex or graphName chooses another; importAllGraphs() reads every one)`,\n );\n }\n // an abort raised during the last few elements (after the last periodic check) still rejects\n throwIfAborted(resolved.signal);\n return report.finish();\n },\n\n /**\n * Read every `graph [ ... ]` block of a GML text, each into its own sink; the top-level keys\n * (Creator, Version, ...) apply to each.\n * @param input - the text, bytes or stream\n * @param sinkFor - the sink of the graph with this index, called before its first push\n * @param options - format-specific and common options\n * @returns one report per graph block\n */\n async importAll(\n input: ImportInput,\n sinkFor: (index: number) => GraphSink,\n options?: GmlImportOptions & CommonImportOptions,\n ): Promise<ImportReport[]> {\n const resolved = resolveImportOptions(options, FORMAT_DEFAULTS);\n const first = new ImportReportBuilder(\"gml\", resolved.errorLimit);\n reportUnusedOptions(options, first, USED_OPTIONS);\n const tokens = tokenize(await readText(input, first, resolved), first);\n const reports: ImportReport[] = [];\n let count = 1;\n for (let i = 0; i < count; i++) {\n throwIfAborted(resolved.signal);\n const report = i === 0 ? first : new ImportReportBuilder(\"gml\", resolved.errorLimit);\n const sink = sinkFor(i);\n reportSinkOptions(sink, options, report);\n const gml = new GmlImport(sink, report, resolved, options, i);\n gml.run(tokens);\n count = gml.graphCount;\n reports.push(report.finish());\n }\n throwIfAborted(resolved.signal);\n return reports;\n },\n});\n\n/**\n * Tokenize a GML text; a syntax error is fatal.\n * @param text - the whole text\n * @param report - where the syntax error is recorded\n * @returns the tokens\n */\nfunction tokenize(text: string, report: ImportReportBuilder): GmlTokens {\n try {\n return tokenizeGml(text);\n } catch (err) {\n if (err instanceof GmlSyntaxError) {\n report.fail(err.code, err.message, { line: err.line });\n }\n throw err;\n }\n}\n","/**\n * The `@graphty/graph-io/gml` subpath: the GML importer and exporter, their\n * option types, and their issue and loss-note codes grouped in two tables.\n * @module @graphty/graph-io/gml\n */\n\nimport {\n AMBIGUOUS_GRAPH_NAME_CODE,\n COLUMN_RENAMED_CODE,\n DIRECTION_FORCED_CODE,\n DIRECTION_REFUSED_CODE,\n ELEMENT_ISSUE,\n ENCODING_FALLBACK_CODE,\n GRAPH_NOT_FOUND_CODE,\n ID_MERGED_CODE,\n INPUT_ISSUE,\n INVALID_ENCODING_CODE,\n INVALID_UTF8_CODE,\n MIXED_DIRECTION_CODE,\n OPTION_IGNORED_CODE,\n SINK_OPTION_CODE,\n SYNTAX_CODE,\n UNKNOWN_ENCODING_CODE,\n} from \"../../common/codes.js\";\nimport {\n GRAPHICS_CONFLICT_CODE,\n GRAPHICS_OVERRIDDEN_CODE,\n INVALID_KEY_CODE,\n JSON_ARRAY_CODE,\n KEY_MANGLED_CODE,\n NESTED_ARRAY_CODE,\n POSITION_COMPONENTS_CODE,\n RECORD_BOOLEAN_CODE,\n RECORD_NULL_CODE,\n RECORD_NUMBER_TYPE_CODE,\n RESERVED_KEY_CODE,\n} from \"./exporter.js\";\nimport {\n DUPLICATE_NODE_CODE,\n ELEMENT_TYPE_CODE,\n FLAG_TYPE_CODE,\n FLAG_VALUE_CODE,\n GRAPHICS_CODE,\n GROUPS_CODE,\n ID_DROPPED_CODE,\n ID_TYPE_CODE,\n MISSING_ENDPOINT_CODE,\n MISSING_ID_CODE,\n MISSING_LABEL_CODE,\n NESTED_ELEMENT_CODE,\n NO_GRAPH_CODE,\n PRECISION_CODE,\n REPEATED_KEY_CODE,\n ROLE_TAKEN_CODE,\n SECOND_GRAPH_CODE,\n STRING_ID_CODE,\n UNKNOWN_ENTITY_CODE,\n WIDENED_CODE,\n} from \"./importer.js\";\n\nexport { gmlExporter, type GmlExportOptions } from \"./exporter.js\";\nexport { gmlImporter, type GmlImportOptions } from \"./importer.js\";\nexport { GML_STYLE_BLOCK_KEY, GML_STYLE_CAPABILITIES } from \"./styles.js\";\n\n/**\n * The issue codes the GML importer records, by name: the codes shared with\n * the other importers and the GML-specific ones. A key is the code without\n * its severity and format prefixes.\n * @category Built-in formats\n */\nexport const GML_ISSUE = Object.freeze({\n ...INPUT_ISSUE,\n ...ELEMENT_ISSUE,\n /**\n * The text breaks GML's syntax: a word that is not a key or a value, an unclosed string or `[`, a stray `]`, or a\n * key without a value. The import stops.\n */\n SYNTAX: SYNTAX_CODE,\n /** The input is not valid UTF-8. The import stops. */\n INVALID_UTF8: INVALID_UTF8_CODE,\n /**\n * Some bytes are not valid in the encoding that was chosen (by a byte order mark, the file's declaration or the\n * `encoding` option). The import stops.\n */\n INVALID_ENCODING: INVALID_ENCODING_CODE,\n /** Bytes that are not UTF-8 and declare no encoding were read as windows-1252. */\n ENCODING_FALLBACK: ENCODING_FALLBACK_CODE,\n /** A declared encoding the platform cannot decode was ignored. */\n UNKNOWN_ENCODING: UNKNOWN_ENCODING_CODE,\n /** There is no `graph [` block. The import stops. */\n NO_GRAPH: NO_GRAPH_CODE,\n /** The file holds more than one `graph` block and only the first was read. It is not added when `graphIndex` or `graphName` chose the graph. */\n MULTIPLE_GRAPHS: SECOND_GRAPH_CODE,\n /** `graphIndex` or `graphName` names no graph of the file; the message lists the graphs it holds. The import stops. */\n GRAPH_NOT_FOUND: GRAPH_NOT_FOUND_CODE,\n /** `graphName` matches more than one graph; pass `graphIndex`. The import stops. */\n AMBIGUOUS_GRAPH_NAME: AMBIGUOUS_GRAPH_NAME_CODE,\n /** A node without an `id`. */\n MISSING_ID: MISSING_ID_CODE,\n /** A node without a `label` under nodeIdFrom \"label\". */\n MISSING_LABEL: MISSING_LABEL_CODE,\n /** An edge without `source` or `target`. */\n MISSING_ENDPOINT: MISSING_ENDPOINT_CODE,\n /** A node id, source or target that is neither an integer nor a string. */\n ID_TYPE: ID_TYPE_CODE,\n /**\n * Node ids, sources or targets are text, where GML expects integers. They are read under the `ids` option.\n * Reported once per file.\n */\n STRING_ID: STRING_ID_CODE,\n /** A node id declared twice (later keys overwrite). */\n DUPLICATE_NODE: DUPLICATE_NODE_CODE,\n /** A structural key repeated in one element. */\n REPEATED_KEY: REPEATED_KEY_CODE,\n /** A `node` / `edge` key whose value is not a record. */\n ELEMENT_TYPE: ELEMENT_TYPE_CODE,\n /** A `directed` / `multigraph` flag that is not an integer. */\n FLAG_TYPE: FLAG_TYPE_CODE,\n /** A `directed` / `multigraph` flag outside 0 / 1, or repeated. */\n FLAG_VALUE: FLAG_VALUE_CODE,\n /** A named entity no table decodes, or a numeric reference beyond U+10FFFF; kept as written. */\n UNKNOWN_ENTITY: UNKNOWN_ENTITY_CODE,\n /** An integer beyond 2^53 was stored as the nearest 64-bit float; pass `long: \"string\"` to keep every digit. */\n PRECISION: PRECISION_CODE,\n /** A node's graphics value that cannot give a position as written; kept in the graphics json column. */\n GRAPHICS: GRAPHICS_CODE,\n /** A graph, node or edge record nested in a node or edge; kept as json, not read as structure. */\n NESTED_ELEMENT: NESTED_ELEMENT_CODE,\n /** YEd's isGroup / gid keys, kept as plain columns; the hierarchy is not read as containment. */\n GROUPS: GROUPS_CODE,\n /**\n * An attribute's type was widened because a later value did not fit: an integer above 2^31 in an integer column,\n * or two declared types for one attribute.\n */\n WIDENED: WIDENED_CODE,\n /**\n * An attribute was renamed `<name>#<suffix>` because another attribute already has its name, for example\n * two attributes declared with the same name.\n */\n COLUMN_RENAMED: COLUMN_RENAMED_CODE,\n /**\n * You read into a graph builder that already has an id, label or position attribute, so this file's one is kept as\n * a plain attribute.\n */\n ROLE_TAKEN: ROLE_TAKEN_CODE,\n /** Two different id texts became the same number because `ids` is \"number\", so their nodes were merged. */\n ID_MERGED: ID_MERGED_CODE,\n /** You set an option this format does not use; it had no effect. The message names the option. */\n OPTION_IGNORED: OPTION_IGNORED_CODE,\n /**\n * You read into your own graph builder, which was created with a different `addMissingNodes`, `duplicateEdges`,\n * `selfLoops` or `weightDtype` than the option you passed; the builder's setting applies.\n */\n SINK_OPTION: SINK_OPTION_CODE,\n /**\n * You read into a graph builder whose direction is already set, or which already holds edges, so the file is read\n * with the builder's direction instead of its own.\n */\n DIRECTION_REFUSED: DIRECTION_REFUSED_CODE,\n /** Edges of the other direction were read with the direction `onMixedDirection` chose. */\n DIRECTION_FORCED: DIRECTION_FORCED_CODE,\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: MIXED_DIRECTION_CODE,\n /**\n * Under `nodeIdFrom: \"label\"` or `\"index\"` the file's integer ids are not kept. It is listed in `report.lossy`, not\n * in `report.issues`.\n */\n ID_DROPPED: ID_DROPPED_CODE,\n});\n\n/**\n * The loss-note codes the GML exporter's check() reports beyond the shared LOSS table, by name.\n * @category Built-in formats\n */\nexport const GML_LOSS = Object.freeze({\n /** A json column holds numbers; GML records cannot keep int versus real. */\n RECORD_NUMBER_TYPE: RECORD_NUMBER_TYPE_CODE,\n /** A json column holds booleans, written 1 / 0. */\n RECORD_BOOLEAN: RECORD_BOOLEAN_CODE,\n /** A json column holds nulls, omitted. */\n RECORD_NULL: RECORD_NULL_CODE,\n /** An attribute holds an array inside an array, which GML cannot write; the save fails. */\n NESTED_ARRAY: NESTED_ARRAY_CODE,\n /** A json row that is an array, written as repeated keys. */\n JSON_ARRAY: JSON_ARRAY_CODE,\n /**\n * An attribute name GML cannot use as a key (keys are letters and digits, starting with a letter). The save fails\n * unless `sanitizeKeys` is \"mangle\".\n */\n INVALID_KEY: INVALID_KEY_CODE,\n /** A column named like a structural key. */\n RESERVED_KEY: RESERVED_KEY_CODE,\n /** A key rewritten under sanitizeKeys \"mangle\", or a column renamed because its key would read back as a style value. */\n KEY_MANGLED: KEY_MANGLED_CODE,\n /** A position column with more than three components. */\n POSITION_COMPONENTS: POSITION_COMPONENTS_CODE,\n /** A graphics record whose x / y / z the position column overrides. */\n GRAPHICS_OVERRIDDEN: GRAPHICS_OVERRIDDEN_CODE,\n /** A graphics record that cannot hold the position. */\n GRAPHICS_CONFLICT: GRAPHICS_CONFLICT_CODE,\n});\n"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