@graphty/graph-io 0.3.44 → 0.3.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist/chunks/{approximations-3Q4TsdTh.js → approximations-DJMHdDvv.js} +2 -2
  2. package/dist/chunks/{approximations-3Q4TsdTh.js.map → approximations-DJMHdDvv.js.map} +1 -1
  3. package/dist/chunks/{block-JQiwViEt.js → block-CPCHkX42.js} +42 -42
  4. package/dist/chunks/{block-JQiwViEt.js.map → block-CPCHkX42.js.map} +1 -1
  5. package/dist/chunks/{choose-BemygfH8.js → choose--jM0yYCo.js} +3 -3
  6. package/dist/chunks/{choose-BemygfH8.js.map → choose--jM0yYCo.js.map} +1 -1
  7. package/dist/chunks/{constants-BFUR_CtU.js → constants-BKwqelYD.js} +2 -2
  8. package/dist/chunks/{constants-BFUR_CtU.js.map → constants-BKwqelYD.js.map} +1 -1
  9. package/dist/chunks/{emit-DCwFLts5.js → emit-DZy6JgdA.js} +3 -3
  10. package/dist/chunks/{emit-DCwFLts5.js.map → emit-DZy6JgdA.js.map} +1 -1
  11. package/dist/chunks/{escape-B1rMftd9.js → escape-CgzxiYPg.js} +6 -6
  12. package/dist/chunks/{escape-B1rMftd9.js.map → escape-CgzxiYPg.js.map} +1 -1
  13. package/dist/chunks/{export-D7IGzTG4.js → export-BvqAXCKh.js} +4 -4
  14. package/dist/chunks/{export-D7IGzTG4.js.map → export-BvqAXCKh.js.map} +1 -1
  15. package/dist/chunks/{exporter-ChPyhBOv.js → exporter--Mk9gXCJ.js} +4 -4
  16. package/dist/chunks/{exporter-ChPyhBOv.js.map → exporter--Mk9gXCJ.js.map} +1 -1
  17. package/dist/chunks/{exporter-quPUCBiC.js → exporter-C-9cgZKa.js} +9 -9
  18. package/dist/chunks/{exporter-quPUCBiC.js.map → exporter-C-9cgZKa.js.map} +1 -1
  19. package/dist/chunks/{exporter-KEPxYUXD.js → exporter-DFqJhBnj.js} +7 -7
  20. package/dist/chunks/{exporter-KEPxYUXD.js.map → exporter-DFqJhBnj.js.map} +1 -1
  21. package/dist/chunks/{exporter-BtnqYuuj.js → exporter-DteVeJki.js} +6 -6
  22. package/dist/chunks/{exporter-BtnqYuuj.js.map → exporter-DteVeJki.js.map} +1 -1
  23. package/dist/chunks/{format-GDmO6m6Q.js → format-BpQBx8MZ.js} +35 -35
  24. package/dist/chunks/{format-GDmO6m6Q.js.map → format-BpQBx8MZ.js.map} +1 -1
  25. package/dist/chunks/{generic-BL06jrJf.js → generic-BGO71QBv.js} +4 -4
  26. package/dist/chunks/{generic-BL06jrJf.js.map → generic-BGO71QBv.js.map} +1 -1
  27. package/dist/chunks/{importer-dwoYpSqb.js → importer-B-9Rc1zO.js} +7 -7
  28. package/dist/chunks/{importer-dwoYpSqb.js.map → importer-B-9Rc1zO.js.map} +1 -1
  29. package/dist/chunks/{importer-CdzeN6X4.js → importer-BVVR740x.js} +6 -6
  30. package/dist/chunks/{importer-CdzeN6X4.js.map → importer-BVVR740x.js.map} +1 -1
  31. package/dist/chunks/{importer-B7r2owVf.js → importer-C0AjA3Ax.js} +9 -9
  32. package/dist/chunks/{importer-B7r2owVf.js.map → importer-C0AjA3Ax.js.map} +1 -1
  33. package/dist/chunks/{importer-C2nzGhdV.js → importer-C7pvJe1L.js} +17 -9
  34. package/dist/chunks/importer-C7pvJe1L.js.map +1 -0
  35. package/dist/chunks/{importer-ChKNC_GN.js → importer-ClwoVx3O.js} +8 -8
  36. package/dist/chunks/{importer-ChKNC_GN.js.map → importer-ClwoVx3O.js.map} +1 -1
  37. package/dist/chunks/{importer-BFmOP96W.js → importer-D0sC_6bO.js} +6 -6
  38. package/dist/chunks/{importer-BFmOP96W.js.map → importer-D0sC_6bO.js.map} +1 -1
  39. package/dist/chunks/{importer-CbX2_rNF.js → importer-EHQk1jbM.js} +9 -9
  40. package/dist/chunks/{importer-CbX2_rNF.js.map → importer-EHQk1jbM.js.map} +1 -1
  41. package/dist/chunks/{json-elements-C4FwgnH5.js → json-elements-DJZRZ6jd.js} +4 -4
  42. package/dist/chunks/{json-elements-C4FwgnH5.js.map → json-elements-DJZRZ6jd.js.map} +1 -1
  43. package/dist/chunks/{lexicon-B-knUi-l.js → lexicon-WMsNddyU.js} +5 -4
  44. package/dist/chunks/{lexicon-B-knUi-l.js.map → lexicon-WMsNddyU.js.map} +1 -1
  45. package/dist/chunks/{ontology-export-BSpbY5FL.js → ontology-export-G4MqRdux.js} +3 -3
  46. package/dist/chunks/{ontology-export-BSpbY5FL.js.map → ontology-export-G4MqRdux.js.map} +1 -1
  47. package/dist/chunks/{records-Nwz_rbNt.js → records-CiaWZrFH.js} +2 -2
  48. package/dist/chunks/{records-Nwz_rbNt.js.map → records-CiaWZrFH.js.map} +1 -1
  49. package/dist/chunks/{styles-Brt9JMfs.js → styles-DvoFBKCK.js} +4 -4
  50. package/dist/chunks/{styles-Brt9JMfs.js.map → styles-DvoFBKCK.js.map} +1 -1
  51. package/dist/chunks/{styles-yed-DAfcIkf7.js → styles-yed-Cz9rLBCP.js} +17 -17
  52. package/dist/chunks/{styles-yed-DAfcIkf7.js.map → styles-yed-Cz9rLBCP.js.map} +1 -1
  53. package/dist/chunks/{styles-_N-C8S-U.js → styles-zNTmz5R7.js} +5 -5
  54. package/dist/chunks/{styles-_N-C8S-U.js.map → styles-zNTmz5R7.js.map} +1 -1
  55. package/dist/chunks/{text-CgzMqHQb.js → text-CzJNFOS9.js} +2 -2
  56. package/dist/chunks/{text-CgzMqHQb.js.map → text-CzJNFOS9.js.map} +1 -1
  57. package/dist/chunks/writer-gQ8kx99H.js +448 -0
  58. package/dist/chunks/writer-gQ8kx99H.js.map +1 -0
  59. package/dist/csv.js +5 -5
  60. package/dist/cx.js +1 -1
  61. package/dist/cx2.js +2 -2
  62. package/dist/cys.js +1 -1
  63. package/dist/dot.js +2 -2
  64. package/dist/gexf.js +5 -5
  65. package/dist/gml.js +3884 -8
  66. package/dist/gml.js.map +1 -1
  67. package/dist/graph-io.js +90 -89
  68. package/dist/graph-io.js.map +1 -1
  69. package/dist/graphml.js +3 -3
  70. package/dist/json.js +1 -1
  71. package/dist/neo4j.js +4 -4
  72. package/dist/obo.js +1 -1
  73. package/dist/pajek.js +1 -1
  74. package/dist/src/formats/dot/styles.d.ts +1 -1
  75. package/dist/src/formats/dot/styles.d.ts.map +1 -1
  76. package/dist/src/formats/dot/styles.js +12 -0
  77. package/dist/src/formats/dot/styles.js.map +1 -1
  78. package/dist/src/styles/cyjs/emit.d.ts.map +1 -1
  79. package/dist/src/styles/cyjs/emit.js +2 -1
  80. package/dist/src/styles/cyjs/emit.js.map +1 -1
  81. package/dist/src/styles/cytoscape/lexicon.d.ts.map +1 -1
  82. package/dist/src/styles/cytoscape/lexicon.js +3 -1
  83. package/dist/src/styles/cytoscape/lexicon.js.map +1 -1
  84. package/dist/src/styles/io/writer.d.ts +9 -0
  85. package/dist/src/styles/io/writer.d.ts.map +1 -1
  86. package/dist/src/styles/io/writer.js +31 -1
  87. package/dist/src/styles/io/writer.js.map +1 -1
  88. package/dist/styles.js +21 -21
  89. package/dist/styles.js.map +1 -1
  90. package/dist/xgmml.js +3 -3
  91. package/package.json +1 -1
  92. package/src/formats/dot/styles.ts +15 -1
  93. package/src/styles/cyjs/emit.ts +2 -1
  94. package/src/styles/cytoscape/lexicon.ts +3 -1
  95. package/src/styles/io/writer.ts +36 -1
  96. package/dist/chunks/importer-C2nzGhdV.js.map +0 -1
  97. package/dist/chunks/index-B9fdNpTA.js +0 -4310
  98. package/dist/chunks/index-B9fdNpTA.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { INVALID_INDEX, GraphFormatError } from "@graphty/graph-format";
2
- import { P as PRECISION_CODE } from "./format-GDmO6m6Q.js";
2
+ import { P as PRECISION_CODE } from "./format-BpQBx8MZ.js";
3
3
  const I32_TEXT = /^-?(0|[1-9]\d*)$/;
4
4
  const F64_TEXT = /^[+-]?((0|[1-9]\d*)(\.\d*)?|\.\d+)([eE][+-]?\d+)?$/;
5
5
  const I32_MIN = -2147483648;
@@ -213,4 +213,4 @@ export {
213
213
  parseTextCell as p,
214
214
  trimTrailingZeros as t
215
215
  };
216
- //# sourceMappingURL=text-CgzMqHQb.js.map
216
+ //# sourceMappingURL=text-CzJNFOS9.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"text-CgzMqHQb.js","sources":["../../src/common/text.ts"],"sourcesContent":["/**\n * The fixed lexical grammar of design section 5.1 for untyped text sources (CSV cells, GML\n * values, DOT strings, Pajek tokens), reproduced from the core's reference implementation so the\n * two agree (invariant I15). Text importers parse each cell with parseTextCell() and push the JS\n * value; the sink's per-column inference then widens `bool -> i32 -> f64 -> string` and never per\n * cell, so a column that saw `1` and then `\"01\"` becomes string for all rows.\n *\n * - `bool` is exactly `true` / `false` (case-sensitive);\n * - `i32` is `/^-?(0|[1-9][0-9]*)$/` within `[-2^31, 2^31)`; `0` / `1` are i32, never bool;\n * - `f64` is a decimal or exponent literal accepted by `Number()` that is not empty, not\n * whitespace, not `Infinity` / `NaN`, not a hex / octal / binary form, has no leading zeros in\n * its integer part, and whose value is finite (an integer literal outside i32 range is f64);\n * - everything else is `string`.\n */\n\nimport { type ColumnHandle, GraphFormatError, type GraphSink, INVALID_INDEX } from \"@graphty/graph-format\";\n\nimport { PRECISION_CODE } from \"./codes.js\";\nimport { type ImportReportBuilder } from \"./report.js\";\n\nconst I32_TEXT = /^-?(0|[1-9]\\d*)$/;\nconst F64_TEXT = /^[+-]?((0|[1-9]\\d*)(\\.\\d*)?|\\.\\d+)([eE][+-]?\\d+)?$/;\nconst I32_MIN = -2147483648;\nconst I32_MAX = 2147483647;\n\n/**\n * The dtype a text cell parses as under the fixed text grammar.\n * @public\n * @category Plugin helpers\n */\nexport type TextDtype = \"bool\" | \"i32\" | \"f64\" | \"string\";\n\n/**\n * A digit string without its trailing zeros (`\"1200\"` becomes `\"12\"`).\n * @param digits - the digits\n * @returns the digits up to the last one that is not 0\n */\nexport function trimTrailingZeros(digits: string): string {\n let end = digits.length;\n while (end > 0 && digits[end - 1] === \"0\") {\n end--;\n }\n return digits.slice(0, end);\n}\n\n/**\n * Classify one text cell by the fixed grammar.\n * @param text - the cell text, exactly as read (no trimming)\n * @returns bool, i32, f64 or string\n * @category Plugin helpers\n */\nexport function inferTextDtype(text: string): TextDtype {\n if (text === \"true\" || text === \"false\") {\n return \"bool\";\n }\n if (I32_TEXT.test(text)) {\n const n = Number(text);\n if (n >= I32_MIN && n <= I32_MAX) {\n return \"i32\";\n }\n return Number.isFinite(n) ? \"f64\" : \"string\";\n }\n if (F64_TEXT.test(text) && Number.isFinite(Number(text))) {\n return \"f64\";\n }\n return \"string\";\n}\n\n/**\n * Parse one text cell into the JS value its grammar class implies: a boolean for bool, a number for\n * i32 / f64, the text itself for string. The sink infers the column dtype from the value.\n * @param text - the cell text, exactly as read\n * @returns the value\n * @category Plugin helpers\n */\nexport function parseTextCell(text: string): boolean | number | string {\n switch (inferTextDtype(text)) {\n case \"bool\":\n return text === \"true\";\n case \"i32\":\n case \"f64\":\n return Number(text);\n case \"string\":\n return text;\n default:\n return text;\n }\n}\n\n/**\n * Whether a text cell is a number under the f64 grammar (an i32 or f64 literal).\n * @param text - the cell text\n * @returns true when parseTextCell(text) returns a number\n * @category Plugin helpers\n */\nexport function isNumericText(text: string): boolean {\n const dtype = inferTextDtype(text);\n return dtype === \"i32\" || dtype === \"f64\";\n}\n\n/**\n * Whether a numeric cell text is the canonical spelling of its value (`String(value) === text`),\n * so that the sink's own re-formatting of the value would reproduce it.\n * @param text - the cell text\n * @param value - the parsed value\n * @returns true when the lexical form survives a widening to string\n */\nfunction isCanonicalNumberText(text: string, value: number): boolean {\n return String(value) === text;\n}\n\n/**\n * The widening rank of a text dtype in the design section 5.1 order.\n * @param dtype - the text dtype\n * @returns 0 for bool, 1 for i32, 2 for f64, 3 for string\n */\nfunction textDtypeRank(dtype: TextDtype): number {\n switch (dtype) {\n case \"bool\":\n return 0;\n case \"i32\":\n return 1;\n case \"f64\":\n return 2;\n case \"string\":\n return 3;\n default: {\n const name: string = dtype;\n throw new GraphFormatError(\"E_UNSUPPORTED\", `unknown text dtype ${name}`, { dtype: name });\n }\n }\n}\n\n/**\n * Writes the cells of one attribute of a text format whose values carry no type (CSV, DOT, Pajek):\n * you hand it each cell's text and it stores a number, a boolean or text, choosing one type for the\n * whole attribute. A column of `2.0`, `3.5` stays a number column with decimals even though `2.0`\n * alone looks like an integer, and once one cell turns out to be text, earlier cells such as `1e5`\n * are kept as written instead of as `100000`. Create one writer per attribute name and per kind\n * (\"node\" or \"edge\"), and call `write(index, text)` with the node or edge index the sink gave you:\n *\n * ```ts\n * const color = new TextCellWriter(\"color\", \"node\", sink, report);\n * color.write(sink.addNode(\"a\"), \"red\");\n * ```\n *\n * A sink that cannot change a column's type after the fact (one of your own without\n * `widenNodeColumn` / `widenEdgeColumn`) keeps the type the first values implied, with one W_WIDENING_UNSUPPORTED warning\n * per attribute.\n * @public\n * @category Writing a format\n */\nexport class TextCellWriter {\n /** The column name in the sink. */\n readonly name: string;\n\n private readonly domain: \"node\" | \"edge\";\n\n private readonly sink: GraphSink;\n\n private readonly report: ImportReportBuilder;\n\n private handle: ColumnHandle = INVALID_INDEX as ColumnHandle;\n\n /** The widest text dtype seen (the column's dtype under the 5.1 grammar). */\n private textDtype: TextDtype | null = null;\n\n /** The widest dtype the pushed values imply (what the sink inferred on its own). */\n private valueDtype: TextDtype | null = null;\n\n private readonly keptRows: number[] = [];\n\n private readonly keptTexts: string[] = [];\n\n /**\n * Create a writer. The attribute is added to the sink on the first write.\n * @param name - the attribute name\n * @param domain - \"node\" for a node attribute, \"edge\" for an edge attribute\n * @param sink - the sink the importer fills\n * @param report - the import report, for warnings about the values\n */\n constructor(name: string, domain: \"node\" | \"edge\", sink: GraphSink, report: ImportReportBuilder) {\n this.name = name;\n this.domain = domain;\n this.sink = sink;\n this.report = report;\n }\n\n /**\n * The sink's handle of the attribute's column, for reading it back.\n * @returns the handle, or INVALID_INDEX before the first write\n */\n get column(): ColumnHandle {\n return this.handle;\n }\n\n /**\n * Write one cell.\n * @param row - the node or edge index, as the sink's addNode() or addEdge() returned it\n * @param text - the cell text, exactly as read from the file\n */\n write(row: number, text: string): void {\n const kind = inferTextDtype(text);\n const value = parseTextCell(text);\n this.warnIfImprecise(text, value);\n const wasString = this.textDtype === \"string\";\n const textDtype =\n this.textDtype === null || textDtypeRank(kind) > textDtypeRank(this.textDtype) ? kind : this.textDtype;\n // a string column keeps every cell's lexical form; a numeric text is never re-spelled. The\n // sink may refuse the value (a declared column of another dtype): the state advances only\n // once the cell is written, so a refused cell leaves the writer as it was.\n this.set(row, textDtype === \"string\" ? text : value);\n this.textDtype = textDtype;\n const valueKind = kindOfValue(value);\n if (this.valueDtype === null || textDtypeRank(valueKind) > textDtypeRank(this.valueDtype)) {\n this.valueDtype = valueKind;\n }\n if (this.textDtype === \"string\") {\n if (!wasString && this.keptRows.length > 0) {\n // the sink just widened the column to string from the values; restore the texts\n // whose lexical form the values did not carry\n for (let i = 0; i < this.keptRows.length; i++) {\n this.set(this.keptRows[i], this.keptTexts[i]);\n }\n this.keptRows.length = 0;\n this.keptTexts.length = 0;\n }\n return;\n }\n if (typeof value === \"number\" && !isCanonicalNumberText(text, value)) {\n this.keptRows.push(row);\n this.keptTexts.push(text);\n }\n if (this.textDtype === \"f64\" && this.valueDtype !== \"f64\") {\n this.widen(\"f64\");\n }\n }\n\n /**\n * Warn, once per column, when the cell is an integer beyond 2^53 that is stored as the nearest\n * double.\n * @param text - the cell text\n * @param value - the parsed value\n */\n private warnIfImprecise(text: string, value: unknown): void {\n if (\n typeof value === \"number\" &&\n !Number.isSafeInteger(value) &&\n I32_TEXT.test(text) &&\n BigInt(text) !== BigInt(value)\n ) {\n this.report.warnOnce(\n \"precision\",\n PRECISION_CODE,\n `${this.domain} column \"${this.name}\": integers beyond 2^53 are stored as the nearest double (first: ${text})`,\n { element: this.name },\n `${PRECISION_CODE}:${this.domain}:${this.name}`,\n );\n }\n }\n\n /**\n * Write a value (the parsed scalar, or a text into a widened column).\n * @param row - the row\n * @param value - the value\n */\n private set(row: number, value: unknown): void {\n if (this.handle === INVALID_INDEX) {\n if (this.domain === \"node\") {\n this.sink.setNodeValue(this.name, row, value);\n this.handle = this.sink.nodeColumn(this.name);\n } else {\n this.sink.setEdgeValue(this.name, row, value);\n this.handle = this.sink.edgeColumn(this.name);\n }\n return;\n }\n if (this.domain === \"node\") {\n this.sink.setNodeValue(this.handle, row, value);\n } else {\n this.sink.setEdgeValue(this.handle, row, value);\n }\n }\n\n /**\n * Widen the column to the dtype the text grammar implies, through the sink's optional call.\n * @param dtype - the dtype\n */\n private widen(dtype: \"f64\"): void {\n const { sink } = this;\n const supported =\n this.domain === \"node\" ? sink.widenNodeColumn !== undefined : sink.widenEdgeColumn !== undefined;\n if (!supported) {\n this.report.warnOnce(\n \"coercion\",\n WIDENING_UNSUPPORTED_CODE,\n `column \"${this.name}\" holds ${dtype} text but the sink cannot widen an inferred column; it keeps the value-inferred dtype`,\n { element: this.name },\n );\n this.valueDtype = dtype;\n return;\n }\n try {\n if (this.domain === \"node\") {\n sink.widenNodeColumn?.(this.handle, dtype);\n } else {\n sink.widenEdgeColumn?.(this.handle, dtype);\n }\n this.valueDtype = dtype;\n } catch (err) {\n if (!(err instanceof GraphFormatError) || err.code !== \"E_COLUMN_TYPE\") {\n throw err;\n }\n // a caller's declared column of the name: its dtype stands\n this.valueDtype = dtype;\n }\n }\n}\n\n/**\n * Your graph builder cannot change an attribute's type after its first value, so a text column keeps the type of its\n * first values.\n * @category Issue and loss codes\n */\nexport const WIDENING_UNSUPPORTED_CODE = \"W_WIDENING_UNSUPPORTED\";\n\n/**\n * The text dtype a parsed cell value implies on its own (what the sink's inference sees). It must\n * be graph-format's inference rule exactly: -0 is an integer there, so a column holding only\n * `-0.0` is inferred i32 and must be widened to f64, or the sign is lost.\n * @param value - the parsed value\n * @returns the dtype\n */\nfunction kindOfValue(value: boolean | number | string): TextDtype {\n if (typeof value === \"boolean\") {\n return \"bool\";\n }\n if (typeof value === \"string\") {\n return \"string\";\n }\n return Number.isInteger(value) && value >= -2147483648 && value <= 2147483647 ? \"i32\" : \"f64\";\n}\n"],"names":[],"mappings":";;AAoBA,MAAM,WAAW;AACjB,MAAM,WAAW;AACjB,MAAM,UAAU;AAChB,MAAM,UAAU;AAcT,SAAS,kBAAkB,QAAwB;AACtD,MAAI,MAAM,OAAO;AACjB,SAAO,MAAM,KAAK,OAAO,MAAM,CAAC,MAAM,KAAK;AACvC;AAAA,EACJ;AACA,SAAO,OAAO,MAAM,GAAG,GAAG;AAC9B;AAQO,SAAS,eAAe,MAAyB;AACpD,MAAI,SAAS,UAAU,SAAS,SAAS;AACrC,WAAO;AAAA,EACX;AACA,MAAI,SAAS,KAAK,IAAI,GAAG;AACrB,UAAM,IAAI,OAAO,IAAI;AACrB,QAAI,KAAK,WAAW,KAAK,SAAS;AAC9B,aAAO;AAAA,IACX;AACA,WAAO,OAAO,SAAS,CAAC,IAAI,QAAQ;AAAA,EACxC;AACA,MAAI,SAAS,KAAK,IAAI,KAAK,OAAO,SAAS,OAAO,IAAI,CAAC,GAAG;AACtD,WAAO;AAAA,EACX;AACA,SAAO;AACX;AASO,SAAS,cAAc,MAAyC;AACnE,UAAQ,eAAe,IAAI,GAAA;AAAA,IACvB,KAAK;AACD,aAAO,SAAS;AAAA,IACpB,KAAK;AAAA,IACL,KAAK;AACD,aAAO,OAAO,IAAI;AAAA,IACtB,KAAK;AACD,aAAO;AAAA,IACX;AACI,aAAO;AAAA,EAAA;AAEnB;AAQO,SAAS,cAAc,MAAuB;AACjD,QAAM,QAAQ,eAAe,IAAI;AACjC,SAAO,UAAU,SAAS,UAAU;AACxC;AASA,SAAS,sBAAsB,MAAc,OAAwB;AACjE,SAAO,OAAO,KAAK,MAAM;AAC7B;AAOA,SAAS,cAAc,OAA0B;AAC7C,UAAQ,OAAA;AAAA,IACJ,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAA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A,IAClD,OAAO;AACH,WAAK,KAAK,aAAa,KAAK,QAAQ,KAAK,KAAK;AAAA,IAClD;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA,EAMQ,MAAM,OAAoB;AAC9B,UAAM,EAAE,SAAS;AACjB,UAAM,YACF,KAAK,WAAW,SAAS,KAAK,oBAAoB,SAAY,KAAK,oBAAoB;AAC3F,QAAI,CAAC,WAAW;AACZ,WAAK,OAAO;AAAA,QACR;AAAA,QACA;AAAA,QACA,WAAW,KAAK,IAAI,WAAW,KAAK;AAAA,QACpC,EAAE,SAAS,KAAK,KAAA;AAAA,MAAK;AAEzB,WAAK,aAAa;AAClB;AAAA,IACJ;AACA,QAAI;AACA,UAAI,KAAK,WAAW,QAAQ;AACxB,aAAK,kBAAkB,KAAK,QAAQ,KAAK;AAAA,MAC7C,OAAO;AACH,aAAK,kBAAkB,KAAK,QAAQ,KAAK;AAAA,MAC7C;AACA,WAAK,aAAa;AAAA,IACtB,SAAS,KAAK;AACV,UAAI,EAAE,eAAe,qBAAqB,IAAI,SAAS,iBAAiB;AACpE,cAAM;AAAA,MACV;AAEA,WAAK,aAAa;AAAA,IACtB;AAAA,EACJ;AACJ;AAOO,MAAM,4BAA4B;AASzC,SAAS,YAAY,OAA6C;AAC9D,MAAI,OAAO,UAAU,WAAW;AAC5B,WAAO;AAAA,EACX;AACA,MAAI,OAAO,UAAU,UAAU;AAC3B,WAAO;AAAA,EACX;AACA,SAAO,OAAO,UAAU,KAAK,KAAK,SAAS,eAAe,SAAS,aAAa,QAAQ;AAC5F;"}
1
+ {"version":3,"file":"text-CzJNFOS9.js","sources":["../../src/common/text.ts"],"sourcesContent":["/**\n * The fixed lexical grammar of design section 5.1 for untyped text sources (CSV cells, GML\n * values, DOT strings, Pajek tokens), reproduced from the core's reference implementation so the\n * two agree (invariant I15). Text importers parse each cell with parseTextCell() and push the JS\n * value; the sink's per-column inference then widens `bool -> i32 -> f64 -> string` and never per\n * cell, so a column that saw `1` and then `\"01\"` becomes string for all rows.\n *\n * - `bool` is exactly `true` / `false` (case-sensitive);\n * - `i32` is `/^-?(0|[1-9][0-9]*)$/` within `[-2^31, 2^31)`; `0` / `1` are i32, never bool;\n * - `f64` is a decimal or exponent literal accepted by `Number()` that is not empty, not\n * whitespace, not `Infinity` / `NaN`, not a hex / octal / binary form, has no leading zeros in\n * its integer part, and whose value is finite (an integer literal outside i32 range is f64);\n * - everything else is `string`.\n */\n\nimport { type ColumnHandle, GraphFormatError, type GraphSink, INVALID_INDEX } from \"@graphty/graph-format\";\n\nimport { PRECISION_CODE } from \"./codes.js\";\nimport { type ImportReportBuilder } from \"./report.js\";\n\nconst I32_TEXT = /^-?(0|[1-9]\\d*)$/;\nconst F64_TEXT = /^[+-]?((0|[1-9]\\d*)(\\.\\d*)?|\\.\\d+)([eE][+-]?\\d+)?$/;\nconst I32_MIN = -2147483648;\nconst I32_MAX = 2147483647;\n\n/**\n * The dtype a text cell parses as under the fixed text grammar.\n * @public\n * @category Plugin helpers\n */\nexport type TextDtype = \"bool\" | \"i32\" | \"f64\" | \"string\";\n\n/**\n * A digit string without its trailing zeros (`\"1200\"` becomes `\"12\"`).\n * @param digits - the digits\n * @returns the digits up to the last one that is not 0\n */\nexport function trimTrailingZeros(digits: string): string {\n let end = digits.length;\n while (end > 0 && digits[end - 1] === \"0\") {\n end--;\n }\n return digits.slice(0, end);\n}\n\n/**\n * Classify one text cell by the fixed grammar.\n * @param text - the cell text, exactly as read (no trimming)\n * @returns bool, i32, f64 or string\n * @category Plugin helpers\n */\nexport function inferTextDtype(text: string): TextDtype {\n if (text === \"true\" || text === \"false\") {\n return \"bool\";\n }\n if (I32_TEXT.test(text)) {\n const n = Number(text);\n if (n >= I32_MIN && n <= I32_MAX) {\n return \"i32\";\n }\n return Number.isFinite(n) ? \"f64\" : \"string\";\n }\n if (F64_TEXT.test(text) && Number.isFinite(Number(text))) {\n return \"f64\";\n }\n return \"string\";\n}\n\n/**\n * Parse one text cell into the JS value its grammar class implies: a boolean for bool, a number for\n * i32 / f64, the text itself for string. The sink infers the column dtype from the value.\n * @param text - the cell text, exactly as read\n * @returns the value\n * @category Plugin helpers\n */\nexport function parseTextCell(text: string): boolean | number | string {\n switch (inferTextDtype(text)) {\n case \"bool\":\n return text === \"true\";\n case \"i32\":\n case \"f64\":\n return Number(text);\n case \"string\":\n return text;\n default:\n return text;\n }\n}\n\n/**\n * Whether a text cell is a number under the f64 grammar (an i32 or f64 literal).\n * @param text - the cell text\n * @returns true when parseTextCell(text) returns a number\n * @category Plugin helpers\n */\nexport function isNumericText(text: string): boolean {\n const dtype = inferTextDtype(text);\n return dtype === \"i32\" || dtype === \"f64\";\n}\n\n/**\n * Whether a numeric cell text is the canonical spelling of its value (`String(value) === text`),\n * so that the sink's own re-formatting of the value would reproduce it.\n * @param text - the cell text\n * @param value - the parsed value\n * @returns true when the lexical form survives a widening to string\n */\nfunction isCanonicalNumberText(text: string, value: number): boolean {\n return String(value) === text;\n}\n\n/**\n * The widening rank of a text dtype in the design section 5.1 order.\n * @param dtype - the text dtype\n * @returns 0 for bool, 1 for i32, 2 for f64, 3 for string\n */\nfunction textDtypeRank(dtype: TextDtype): number {\n switch (dtype) {\n case \"bool\":\n return 0;\n case \"i32\":\n return 1;\n case \"f64\":\n return 2;\n case \"string\":\n return 3;\n default: {\n const name: string = dtype;\n throw new GraphFormatError(\"E_UNSUPPORTED\", `unknown text dtype ${name}`, { dtype: name });\n }\n }\n}\n\n/**\n * Writes the cells of one attribute of a text format whose values carry no type (CSV, DOT, Pajek):\n * you hand it each cell's text and it stores a number, a boolean or text, choosing one type for the\n * whole attribute. A column of `2.0`, `3.5` stays a number column with decimals even though `2.0`\n * alone looks like an integer, and once one cell turns out to be text, earlier cells such as `1e5`\n * are kept as written instead of as `100000`. Create one writer per attribute name and per kind\n * (\"node\" or \"edge\"), and call `write(index, text)` with the node or edge index the sink gave you:\n *\n * ```ts\n * const color = new TextCellWriter(\"color\", \"node\", sink, report);\n * color.write(sink.addNode(\"a\"), \"red\");\n * ```\n *\n * A sink that cannot change a column's type after the fact (one of your own without\n * `widenNodeColumn` / `widenEdgeColumn`) keeps the type the first values implied, with one W_WIDENING_UNSUPPORTED warning\n * per attribute.\n * @public\n * @category Writing a format\n */\nexport class TextCellWriter {\n /** The column name in the sink. */\n readonly name: string;\n\n private readonly domain: \"node\" | \"edge\";\n\n private readonly sink: GraphSink;\n\n private readonly report: ImportReportBuilder;\n\n private handle: ColumnHandle = INVALID_INDEX as ColumnHandle;\n\n /** The widest text dtype seen (the column's dtype under the 5.1 grammar). */\n private textDtype: TextDtype | null = null;\n\n /** The widest dtype the pushed values imply (what the sink inferred on its own). */\n private valueDtype: TextDtype | null = null;\n\n private readonly keptRows: number[] = [];\n\n private readonly keptTexts: string[] = [];\n\n /**\n * Create a writer. The attribute is added to the sink on the first write.\n * @param name - the attribute name\n * @param domain - \"node\" for a node attribute, \"edge\" for an edge attribute\n * @param sink - the sink the importer fills\n * @param report - the import report, for warnings about the values\n */\n constructor(name: string, domain: \"node\" | \"edge\", sink: GraphSink, report: ImportReportBuilder) {\n this.name = name;\n this.domain = domain;\n this.sink = sink;\n this.report = report;\n }\n\n /**\n * The sink's handle of the attribute's column, for reading it back.\n * @returns the handle, or INVALID_INDEX before the first write\n */\n get column(): ColumnHandle {\n return this.handle;\n }\n\n /**\n * Write one cell.\n * @param row - the node or edge index, as the sink's addNode() or addEdge() returned it\n * @param text - the cell text, exactly as read from the file\n */\n write(row: number, text: string): void {\n const kind = inferTextDtype(text);\n const value = parseTextCell(text);\n this.warnIfImprecise(text, value);\n const wasString = this.textDtype === \"string\";\n const textDtype =\n this.textDtype === null || textDtypeRank(kind) > textDtypeRank(this.textDtype) ? kind : this.textDtype;\n // a string column keeps every cell's lexical form; a numeric text is never re-spelled. The\n // sink may refuse the value (a declared column of another dtype): the state advances only\n // once the cell is written, so a refused cell leaves the writer as it was.\n this.set(row, textDtype === \"string\" ? text : value);\n this.textDtype = textDtype;\n const valueKind = kindOfValue(value);\n if (this.valueDtype === null || textDtypeRank(valueKind) > textDtypeRank(this.valueDtype)) {\n this.valueDtype = valueKind;\n }\n if (this.textDtype === \"string\") {\n if (!wasString && this.keptRows.length > 0) {\n // the sink just widened the column to string from the values; restore the texts\n // whose lexical form the values did not carry\n for (let i = 0; i < this.keptRows.length; i++) {\n this.set(this.keptRows[i], this.keptTexts[i]);\n }\n this.keptRows.length = 0;\n this.keptTexts.length = 0;\n }\n return;\n }\n if (typeof value === \"number\" && !isCanonicalNumberText(text, value)) {\n this.keptRows.push(row);\n this.keptTexts.push(text);\n }\n if (this.textDtype === \"f64\" && this.valueDtype !== \"f64\") {\n this.widen(\"f64\");\n }\n }\n\n /**\n * Warn, once per column, when the cell is an integer beyond 2^53 that is stored as the nearest\n * double.\n * @param text - the cell text\n * @param value - the parsed value\n */\n private warnIfImprecise(text: string, value: unknown): void {\n if (\n typeof value === \"number\" &&\n !Number.isSafeInteger(value) &&\n I32_TEXT.test(text) &&\n BigInt(text) !== BigInt(value)\n ) {\n this.report.warnOnce(\n \"precision\",\n PRECISION_CODE,\n `${this.domain} column \"${this.name}\": integers beyond 2^53 are stored as the nearest double (first: ${text})`,\n { element: this.name },\n `${PRECISION_CODE}:${this.domain}:${this.name}`,\n );\n }\n }\n\n /**\n * Write a value (the parsed scalar, or a text into a widened column).\n * @param row - the row\n * @param value - the value\n */\n private set(row: number, value: unknown): void {\n if (this.handle === INVALID_INDEX) {\n if (this.domain === \"node\") {\n this.sink.setNodeValue(this.name, row, value);\n this.handle = this.sink.nodeColumn(this.name);\n } else {\n this.sink.setEdgeValue(this.name, row, value);\n this.handle = this.sink.edgeColumn(this.name);\n }\n return;\n }\n if (this.domain === \"node\") {\n this.sink.setNodeValue(this.handle, row, value);\n } else {\n this.sink.setEdgeValue(this.handle, row, value);\n }\n }\n\n /**\n * Widen the column to the dtype the text grammar implies, through the sink's optional call.\n * @param dtype - the dtype\n */\n private widen(dtype: \"f64\"): void {\n const { sink } = this;\n const supported =\n this.domain === \"node\" ? sink.widenNodeColumn !== undefined : sink.widenEdgeColumn !== undefined;\n if (!supported) {\n this.report.warnOnce(\n \"coercion\",\n WIDENING_UNSUPPORTED_CODE,\n `column \"${this.name}\" holds ${dtype} text but the sink cannot widen an inferred column; it keeps the value-inferred dtype`,\n { element: this.name },\n );\n this.valueDtype = dtype;\n return;\n }\n try {\n if (this.domain === \"node\") {\n sink.widenNodeColumn?.(this.handle, dtype);\n } else {\n sink.widenEdgeColumn?.(this.handle, dtype);\n }\n this.valueDtype = dtype;\n } catch (err) {\n if (!(err instanceof GraphFormatError) || err.code !== \"E_COLUMN_TYPE\") {\n throw err;\n }\n // a caller's declared column of the name: its dtype stands\n this.valueDtype = dtype;\n }\n }\n}\n\n/**\n * Your graph builder cannot change an attribute's type after its first value, so a text column keeps the type of its\n * first values.\n * @category Issue and loss codes\n */\nexport const WIDENING_UNSUPPORTED_CODE = \"W_WIDENING_UNSUPPORTED\";\n\n/**\n * The text dtype a parsed cell value implies on its own (what the sink's inference sees). It must\n * be graph-format's inference rule exactly: -0 is an integer there, so a column holding only\n * `-0.0` is inferred i32 and must be widened to f64, or the sign is lost.\n * @param value - the parsed value\n * @returns the dtype\n */\nfunction kindOfValue(value: boolean | number | string): TextDtype {\n if (typeof value === \"boolean\") {\n return \"bool\";\n }\n if (typeof value === \"string\") {\n return \"string\";\n }\n return Number.isInteger(value) && value >= -2147483648 && value <= 2147483647 ? \"i32\" : \"f64\";\n}\n"],"names":[],"mappings":";;AAoBA,MAAM,WAAW;AACjB,MAAM,WAAW;AACjB,MAAM,UAAU;AAChB,MAAM,UAAU;AAcT,SAAS,kBAAkB,QAAwB;AACtD,MAAI,MAAM,OAAO;AACjB,SAAO,MAAM,KAAK,OAAO,MAAM,CAAC,MAAM,KAAK;AACvC;AAAA,EACJ;AACA,SAAO,OAAO,MAAM,GAAG,GAAG;AAC9B;AAQO,SAAS,eAAe,MAAyB;AACpD,MAAI,SAAS,UAAU,SAAS,SAAS;AACrC,WAAO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WAAW,QAAQ;AACxB,aAAK,kBAAkB,KAAK,QAAQ,KAAK;AAAA,MAC7C,OAAO;AACH,aAAK,kBAAkB,KAAK,QAAQ,KAAK;AAAA,MAC7C;AACA,WAAK,aAAa;AAAA,IACtB,SAAS,KAAK;AACV,UAAI,EAAE,eAAe,qBAAqB,IAAI,SAAS,iBAAiB;AACpE,cAAM;AAAA,MACV;AAEA,WAAK,aAAa;AAAA,IACtB;AAAA,EACJ;AACJ;AAOO,MAAM,4BAA4B;AASzC,SAAS,YAAY,OAA6C;AAC9D,MAAI,OAAO,UAAU,WAAW;AAC5B,WAAO;AAAA,EACX;AACA,MAAI,OAAO,UAAU,UAAU;AAC3B,WAAO;AAAA,EACX;AACA,SAAO,OAAO,UAAU,KAAK,KAAK,SAAS,eAAe,SAAS,aAAa,QAAQ;AAC5F;"}
@@ -0,0 +1,448 @@
1
+ import { p as plural, a as agree } from "./format-BpQBx8MZ.js";
2
+ import { s as styleFingerprint, a as STYLE_ISSUE, b as styleTag, w as writeStyleBlock, c as styleBlockLosses, r as resolveStyles, S as STYLE_BLOCK_NAME, d as canonicalFor, e as degreeValues, f as dataCell, p as plainCell } from "./block-CPCHkX42.js";
3
+ const STYLE_ROLES = /* @__PURE__ */ new Set(["color", "size", "shape", "thickness", "hidden"]);
4
+ const TARGETS = ["node", "edge"];
5
+ function prepareStyleExport(snapshot, exporter, given, plain) {
6
+ const fp = styleFingerprint(snapshot);
7
+ const want = given.fingerprint;
8
+ if (fp.nodes !== want.nodes || fp.edges !== want.edges || fp.ids !== want.ids) {
9
+ return {
10
+ snapshot,
11
+ input: null,
12
+ notes: [],
13
+ refusal: Object.freeze({
14
+ code: STYLE_ISSUE.MISMATCH,
15
+ message: `the styles were read from or built for a different graph (${String(want.nodes)} nodes and ${String(want.edges)} edges, this graph has ${String(fp.nodes)} and ${String(fp.edges)}, or other node ids); nothing is written`,
16
+ column: null,
17
+ count: null
18
+ })
19
+ };
20
+ }
21
+ const caps = exporter.styles?.capabilities ?? null;
22
+ let plan = writePlan(snapshot, exporter, given);
23
+ if (keepsStyleBlock(exporter)) {
24
+ let checked;
25
+ try {
26
+ checked = exporter.check(plan.snapshot, plan.input === null ? plain : { ...plain, styles: plan.input });
27
+ } catch {
28
+ checked = [];
29
+ }
30
+ const carried = withLostInputsCarried(given, snapshot, checked);
31
+ if (carried !== given) {
32
+ plan = writePlan(snapshot, exporter, carried);
33
+ }
34
+ }
35
+ return {
36
+ snapshot: plan.snapshot,
37
+ input: plan.input,
38
+ notes: lossNotes(plan.extracted, exporter, caps, plan.picture, snapshot),
39
+ refusal: null
40
+ };
41
+ }
42
+ const CALL_WORK = /* @__PURE__ */ new WeakMap();
43
+ function sharedInExportCall(input, key, compute) {
44
+ if (!CALL_WORK.has(input)) {
45
+ return compute();
46
+ }
47
+ const done = CALL_WORK.get(input);
48
+ if (done?.key.length === key.length && done.key.every((k, i) => k === key[i])) {
49
+ return done.value;
50
+ }
51
+ const value = compute();
52
+ CALL_WORK.set(input, { key, value });
53
+ return value;
54
+ }
55
+ function writePlan(snapshot, exporter, extracted) {
56
+ const caps = exporter.styles?.capabilities ?? null;
57
+ const pictures = /* @__PURE__ */ new Map();
58
+ const picture = (target, property) => {
59
+ const key = `${target}\0${property}`;
60
+ let values = pictures.get(key);
61
+ if (values === void 0) {
62
+ values = resolveStyles(extracted, target, property, snapshot);
63
+ pictures.set(key, values);
64
+ }
65
+ return values;
66
+ };
67
+ const tags = { node: /* @__PURE__ */ new Map(), edge: /* @__PURE__ */ new Map() };
68
+ for (const target of TARGETS) {
69
+ for (const [key, col] of extracted.columns[target]) {
70
+ tags[target].set(styleTag(target, key), col);
71
+ }
72
+ }
73
+ const block = writeStyleBlock(extracted, { snapshot });
74
+ const input = exporter.styles === void 0 ? null : { picture, block, tags, rules: extracted };
75
+ if (input !== null) {
76
+ CALL_WORK.set(input, null);
77
+ }
78
+ return {
79
+ snapshot: styledSnapshot(snapshot, caps, tags, block, extracted.styles.rules),
80
+ input,
81
+ extracted,
82
+ picture
83
+ };
84
+ }
85
+ const VALUES_KEPT = /NODE_TABLE|NAME_CHANGED|ROLE_ASSUMED|STORAGE_CLASS|NUMBER_TYPE|INTEGRAL|WIDENED/;
86
+ function withLostInputsCarried(extracted, snapshot, notes) {
87
+ const lost = /* @__PURE__ */ new Set();
88
+ let direction = false;
89
+ for (const note of notes) {
90
+ if (!VALUES_KEPT.test(note.code)) {
91
+ for (const name of note.columns ?? (note.column === null ? [] : [note.column])) {
92
+ lost.add(name);
93
+ }
94
+ }
95
+ direction ||= /DIRECTION/.test(note.code);
96
+ }
97
+ const carrier = new LostInputs(snapshot, lost, direction, extracted.columns);
98
+ const rules = extracted.styles.rules.map((rule) => carrier.carry(rule));
99
+ const changed = rules.some((rule, i) => rule !== extracted.styles.rules[i]);
100
+ return changed ? { ...extracted, styles: { ...extracted.styles, rules }, columns: carrier.columns } : extracted;
101
+ }
102
+ class LostInputs {
103
+ /**
104
+ * A carrier for one export.
105
+ * @param snapshot - the graph
106
+ * @param lost - the data columns the export drops or changes
107
+ * @param direction - whether the file loses the edges' direction (and so the in and out degrees)
108
+ * @param columns - the styles' own style columns
109
+ * @param columns.node - the node columns
110
+ * @param columns.edge - the edge columns
111
+ */
112
+ constructor(snapshot, lost, direction, columns) {
113
+ this.snapshot = snapshot;
114
+ this.lost = lost;
115
+ this.direction = direction;
116
+ this.touched = false;
117
+ this.columns = { node: new Map(columns.node), edge: new Map(columns.edge) };
118
+ }
119
+ /**
120
+ * A rule with every lost input it reads replaced by a copy of its values.
121
+ * @param rule - the rule
122
+ * @returns the rule read from copies, or the rule itself when it reads no lost input
123
+ */
124
+ carry(rule) {
125
+ this.touched = false;
126
+ const { ext, ...given } = rule;
127
+ const map = this.carryMap(rule);
128
+ const where = this.walk(rule, given.where);
129
+ if (!this.touched) {
130
+ return rule;
131
+ }
132
+ const { map: _given, ...unmapped } = given;
133
+ const plain = Object.keys(map).length === 0 ? { ...unmapped, where } : { ...unmapped, where, map };
134
+ const moved = JSON.parse(JSON.stringify(plain));
135
+ return ext === void 0 ? moved : { ...moved, ext };
136
+ }
137
+ /**
138
+ * A rule's mappings with their lost inputs replaced. A passthrough reads a data column as the property's value: its
139
+ * copy holds those values; one that gives no element a value (a list, text that is not a color) is left out, so
140
+ * no other value the file reads back in the column (a list written as text) is given either.
141
+ * @param rule - the rule
142
+ * @returns the mappings
143
+ */
144
+ carryMap(rule) {
145
+ const map = /* @__PURE__ */ Object.create(null);
146
+ const { table } = this.tableOf(rule.target);
147
+ for (const [property, mapping] of Object.entries(rule.map ?? {})) {
148
+ if (mapping === void 0) {
149
+ continue;
150
+ }
151
+ if (mapping.kind !== "passthrough") {
152
+ map[property] = this.walk(rule, mapping);
153
+ continue;
154
+ }
155
+ const name = mapping.by.data;
156
+ const lostColumn = typeof name === "string" && this.lost.has(name) && table.has(name);
157
+ const values = lostColumn ? this.cells(rule.target, name, canonicalFor(rule.target, property)) : null;
158
+ if (values !== null && !values.some((v) => v !== null)) {
159
+ this.touched = true;
160
+ } else if (values !== null && this.isLost(rule.target, name)) {
161
+ this.touched = true;
162
+ map[property] = { ...mapping, by: this.copy(rule.target, `${property}.data.${name}`, () => values) };
163
+ } else {
164
+ map[property] = mapping;
165
+ }
166
+ }
167
+ return map;
168
+ }
169
+ /**
170
+ * A value with every other reference to a lost input reading a copy of its values as they are.
171
+ * @param rule - the rule it belongs to
172
+ * @param value - the value
173
+ * @returns the value, references replaced
174
+ */
175
+ walk(rule, value) {
176
+ return JSON.parse(JSON.stringify(value, (_k, v) => this.replaced(rule, v)));
177
+ }
178
+ /**
179
+ * One reference with a lost input replaced by its copy: a data column, or a degree the file does not keep.
180
+ * @param rule - the rule it belongs to
181
+ * @param v - a value of the rule
182
+ * @returns the value, or the reference to the copy
183
+ */
184
+ replaced(rule, v) {
185
+ if (typeof v !== "object" || v === null || Array.isArray(v) || Object.keys(v).length !== 1) {
186
+ return v;
187
+ }
188
+ const ref = v;
189
+ if (this.isLost(rule.target, ref.data)) {
190
+ const name = ref.data;
191
+ this.touched = true;
192
+ return this.copy(
193
+ rule.target,
194
+ `data.${name}`,
195
+ () => this.cells(rule.target, name, (raw) => isStyleScalar(raw) ? raw : null)
196
+ );
197
+ }
198
+ const which = ref.computed;
199
+ if ((which === "indegree" || which === "outdegree") && this.direction && rule.target === "node") {
200
+ this.touched = true;
201
+ return this.copy(rule.target, `computed.${which}`, () => degreeValues(this.snapshot, which));
202
+ }
203
+ return v;
204
+ }
205
+ /**
206
+ * The reference to a copy of an input, made on first use and shared by every rule that reads it.
207
+ * @param target - nodes or edges
208
+ * @param base - what is copied
209
+ * @param values - its values
210
+ * @returns the reference
211
+ */
212
+ copy(target, base, values) {
213
+ const key = `input.${base}`;
214
+ const held = this.columns[target];
215
+ if (!held.has(key)) {
216
+ held.set(key, values());
217
+ }
218
+ return { style: key };
219
+ }
220
+ /**
221
+ * Whether a name is a lost input that can be copied: only a column of plain values can, and a list, or a column with
222
+ * no value, stays as it is.
223
+ * @param target - nodes or edges
224
+ * @param name - the name
225
+ * @returns true for a lost input
226
+ */
227
+ isLost(target, name) {
228
+ const { table, n } = this.tableOf(target);
229
+ return typeof name === "string" && this.lost.has(name) && table.has(name) && carriable(table, n, name);
230
+ }
231
+ /**
232
+ * Every element's value of a data column.
233
+ * @param target - nodes or edges
234
+ * @param name - the column
235
+ * @param read - the value of a cell
236
+ * @returns the values
237
+ */
238
+ cells(target, name, read) {
239
+ const { table, n } = this.tableOf(target);
240
+ return Array.from({ length: n }, (_u, i) => read(dataCell(table, name, i)));
241
+ }
242
+ /**
243
+ * A target's table and row count.
244
+ * @param target - nodes or edges
245
+ * @returns the table and its row count
246
+ */
247
+ tableOf(target) {
248
+ const { snapshot } = this;
249
+ return target === "node" ? { table: snapshot.nodes, n: snapshot.nodeCount } : { table: snapshot.edges, n: snapshot.edgeCount };
250
+ }
251
+ }
252
+ function carriable(table, n, name) {
253
+ let some = false;
254
+ for (let i = 0; i < n; i++) {
255
+ const cell = plainCell(table.value(name, i));
256
+ if (cell !== null && cell !== void 0) {
257
+ if (!isStyleScalar(cell)) {
258
+ return false;
259
+ }
260
+ some = true;
261
+ }
262
+ }
263
+ return some;
264
+ }
265
+ function isStyleScalar(v) {
266
+ return typeof v === "string" || typeof v === "boolean" || typeof v === "number" && Number.isFinite(v);
267
+ }
268
+ function keepsStyleBlock(exporter) {
269
+ const caps = exporter.styles?.capabilities;
270
+ return caps !== void 0 && (caps.block === "native" || caps.block === "attributes" && exporter.capabilities.graphAttributes);
271
+ }
272
+ function isKeptGraphtyProperty(note, exporter) {
273
+ return note.style?.property.startsWith("graphty:") === true && keepsStyleBlock(exporter);
274
+ }
275
+ function lossNotes(extracted, exporter, caps, picture, snapshot) {
276
+ const notes = [];
277
+ const kept = keepsStyleBlock(exporter);
278
+ for (const target of TARGETS) {
279
+ const written = new Set(caps?.[target] ?? []);
280
+ for (const property of ruleProperties(extracted.styles.rules, target)) {
281
+ if (written.has(property) || kept && property.startsWith("graphty:")) {
282
+ if (target === "edge") {
283
+ notes.push(...pairNotes(snapshot, exporter, property, picture("edge", property)));
284
+ }
285
+ } else {
286
+ notes.push(notWrittenNote(target, property, exporter, picture));
287
+ }
288
+ }
289
+ }
290
+ notes.push(...graphLossNotes(extracted, exporter, caps));
291
+ if (kept) {
292
+ notes.push(...styleBlockLosses(writeStyleBlock(extracted, { snapshot }), extracted.styles.rules.length));
293
+ } else if (extracted.styles.rules.length > 0) {
294
+ notes.push(
295
+ Object.freeze({
296
+ code: STYLE_ISSUE.RULES_NOT_KEPT,
297
+ message: `the style rules are not kept: the ${exporter.format} format has no place for them; importing the file infers them again from what it holds`,
298
+ column: null,
299
+ count: extracted.styles.rules.length
300
+ })
301
+ );
302
+ }
303
+ return notes;
304
+ }
305
+ function graphLossNotes(extracted, exporter, caps) {
306
+ const graphWritten = new Set(caps?.graph ?? []);
307
+ return Object.keys(extracted.styles.graph).filter((property) => !graphWritten.has(property)).map(
308
+ (property) => Object.freeze({
309
+ code: STYLE_ISSUE.NOT_WRITTEN,
310
+ message: `the graph's ${property} is not written: the ${exporter.format} format has no place for it`,
311
+ column: null,
312
+ count: 1,
313
+ style: Object.freeze({ target: "graph", property })
314
+ })
315
+ );
316
+ }
317
+ function ruleProperties(rules, target) {
318
+ return new Set(
319
+ rules.filter((rule) => rule.target === target).flatMap((rule) => [...Object.keys(rule.set ?? {}), ...Object.keys(rule.map ?? {})])
320
+ );
321
+ }
322
+ function notWrittenNote(target, property, exporter, picture) {
323
+ const count = picture(target, property).filter((v) => v !== null).length;
324
+ return Object.freeze({
325
+ code: STYLE_ISSUE.NOT_WRITTEN,
326
+ message: `${target} ${property} is not written: the ${exporter.format} format has no place for it (${String(count)} ${target}${plural(count)} ${agree(count, "has", "have")} a value)`,
327
+ column: null,
328
+ count,
329
+ style: Object.freeze({ target, property })
330
+ });
331
+ }
332
+ function pairNotes(snapshot, exporter, property, values) {
333
+ const pair = snapshot.edges.byRole("pair");
334
+ let count = 0;
335
+ for (let i = 0; pair !== null && i < values.length; i++) {
336
+ const other = pair.isSet(i) ? pair.value(i) : i;
337
+ if (other < i && values[i] !== values[other]) {
338
+ count++;
339
+ }
340
+ }
341
+ if (count === 0) {
342
+ return [];
343
+ }
344
+ return [
345
+ Object.freeze({
346
+ code: STYLE_ISSUE.APPROXIMATED,
347
+ message: `edge ${property}: ${String(count)} undirected edge${plural(count)} in a directed graph ${agree(count, "has", "have")} another value on each half; the ${exporter.format} format writes the edge once, with the first half's value`,
348
+ column: null,
349
+ count,
350
+ style: Object.freeze({ target: "edge", property })
351
+ })
352
+ ];
353
+ }
354
+ function styledSnapshot(snapshot, caps, tags, block, rules) {
355
+ const attributes = caps?.block === "attributes";
356
+ const stale = { node: staleTags(snapshot.nodes, rules, "node"), edge: staleTags(snapshot.edges, rules, "edge") };
357
+ const roles = { node: roledNames(snapshot.nodes, caps, "node"), edge: roledNames(snapshot.edges, caps, "edge") };
358
+ const staleBlock = snapshot.graph.has(STYLE_BLOCK_NAME);
359
+ const changes = [stale.node, stale.edge, roles.node, roles.edge].some((names) => names.length > 0);
360
+ if (!attributes && !staleBlock && !changes) {
361
+ return snapshot;
362
+ }
363
+ const out = snapshot.withColumns();
364
+ if (staleBlock) {
365
+ out.graph.remove(STYLE_BLOCK_NAME);
366
+ }
367
+ for (const target of TARGETS) {
368
+ const table = target === "node" ? out.nodes : out.edges;
369
+ for (const name of stale[target]) {
370
+ table.remove(name);
371
+ }
372
+ for (const name of roles[target]) {
373
+ const col = table.get(name);
374
+ if (col !== null) {
375
+ table.set(name, col, { role: void 0 });
376
+ }
377
+ }
378
+ }
379
+ if (attributes) {
380
+ setTagAttributes(out, tags);
381
+ out.graph.set(STYLE_BLOCK_NAME, [block], { dtype: "string" });
382
+ }
383
+ return out;
384
+ }
385
+ function staleTags(table, rules, target) {
386
+ const read = dataRead(rules, target);
387
+ return table.names().filter((name) => isStyleTagName(name) && !read.has(name));
388
+ }
389
+ function roledNames(table, caps, target) {
390
+ const writesLabel = (caps?.[target] ?? []).includes("label");
391
+ return table.names().filter((name) => {
392
+ const role = table.get(name)?.meta.role ?? "";
393
+ return STYLE_ROLES.has(role) || role === "label" && writesLabel;
394
+ });
395
+ }
396
+ function setTagAttributes(out, tags) {
397
+ for (const target of TARGETS) {
398
+ const table = target === "node" ? out.nodes : out.edges;
399
+ const prefix = styleTag(target, "");
400
+ for (const name of table.names().filter((c) => c.startsWith(prefix))) {
401
+ table.remove(name);
402
+ }
403
+ for (const [name, col] of tags[target]) {
404
+ const dtype = tagDtype(col);
405
+ table.set(name, dtype === "string" ? col.map((v) => v === null ? null : String(v)) : col, { dtype });
406
+ }
407
+ }
408
+ }
409
+ function isStyleTagName(name) {
410
+ return name.startsWith("graphty.style.") || name.startsWith("graphty_style_");
411
+ }
412
+ function dataRead(rules, target) {
413
+ const out = /* @__PURE__ */ new Set();
414
+ for (const { ext: _ext, ...rule } of rules.filter((r) => r.target === target)) {
415
+ JSON.stringify(rule, (_k, v) => {
416
+ const data = typeof v === "object" && v !== null && !Array.isArray(v) ? v.data : null;
417
+ if (typeof data === "string" && Object.keys(v).length === 1) {
418
+ out.add(data);
419
+ }
420
+ return v;
421
+ });
422
+ }
423
+ return out;
424
+ }
425
+ function tagDtype(col) {
426
+ let kind = null;
427
+ for (const v of col) {
428
+ if (v === null) {
429
+ continue;
430
+ }
431
+ if (kind === null) {
432
+ kind = typeof v;
433
+ } else if (kind !== typeof v) {
434
+ return "string";
435
+ }
436
+ }
437
+ if (kind === "number") {
438
+ return "f64";
439
+ }
440
+ return kind === "boolean" ? "bool" : "string";
441
+ }
442
+ export {
443
+ dataRead as d,
444
+ isKeptGraphtyProperty as i,
445
+ prepareStyleExport as p,
446
+ sharedInExportCall as s
447
+ };
448
+ //# sourceMappingURL=writer-gQ8kx99H.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writer-gQ8kx99H.js","sources":["../../src/styles/io/writer.ts"],"sourcesContent":["/**\n * Writing a graph's styles: what `exportGraph(snapshot, format, { styles })` hands a format's exporter, the losses\n * reported before anything is written, and, for an exporter whose block goes into attributes, the snapshot with the\n * `graphty.styles` block and the tagged per-element values added as attributes.\n */\n\nimport type { GraphSnapshot } from \"@graphty/graph-format\";\n\nimport { agree, plural } from \"../../common/plural.js\";\nimport type { GraphExporter, LossNote } from \"../../types.js\";\nimport { STYLE_ISSUE } from \"../codes.js\";\nimport { styleFingerprint } from \"../plan/features.js\";\nimport { canonicalFor, dataCell, degreeValues, plainCell, resolveStyles } from \"../plan/resolve.js\";\nimport type {\n ExtractedStyles,\n Mapping,\n StyleColumn,\n StyleProperty,\n StyleRule,\n StyleTarget,\n StyleValue,\n StyleWriteCapabilities,\n} from \"../types.js\";\nimport { STYLE_BLOCK_NAME, styleBlockLosses, styleTag, writeStyleBlock } from \"./block.js\";\n\n/**\n * What an exporter with a `styles` member receives as `options.styles` when styles are being written.\n * @category Styles\n */\nexport interface ExporterStyleInput {\n /**\n * Each element's value of one property, by element index (null where no rule gives one): what graphty draws, to\n * write into the format's own style slots.\n * @param target - nodes or edges\n * @param property - the property\n * @returns the values\n */\n picture(target: StyleTarget, property: StyleProperty): readonly (StyleValue | null)[];\n /** The `graphty.styles` block (JSON text) to place where the format keeps extra data. */\n readonly block: string;\n /** The per-element style values the block's rules read, by attribute name (`graphty.style.<target>.<key>`). */\n readonly tags: {\n /** Node values. */\n readonly node: ReadonlyMap<string, StyleColumn>;\n /** Edge values. */\n readonly edge: ReadonlyMap<string, StyleColumn>;\n };\n /** The styles themselves, for a format with a style language of its own. */\n readonly rules: ExtractedStyles;\n}\n\n/**\n * The options an exporter with a `styles` member reads its styles from: type its options as `Opts &\n * ExporterStyleOptions`.\n * @category Styles\n */\nexport interface ExporterStyleOptions {\n /** Present when styles are being written. */\n readonly styles?: ExporterStyleInput | undefined;\n}\n\n/** What an export with styles writes and loses, worked out before writing. */\ninterface PreparedStyleExport {\n /** The snapshot to hand the exporter: style roles removed, and the block and tagged values added as attributes. */\n readonly snapshot: GraphSnapshot;\n /** The exporter's `options.styles`, or null for an exporter without a `styles` member. */\n readonly input: ExporterStyleInput | null;\n /** W_STYLE_ notes: every property not written natively, and the rules when they are not kept. */\n readonly notes: readonly LossNote[];\n /** E_STYLES_MISMATCH when the styles belong to a different graph; nothing is then written. */\n readonly refusal: LossNote | null;\n}\n\n/** The roles of columns that hold styles; with styles given they are data, never written into a style slot. */\nconst STYLE_ROLES: ReadonlySet<string> = new Set([\"color\", \"size\", \"shape\", \"thickness\", \"hidden\"]);\nconst TARGETS: readonly StyleTarget[] = [\"node\", \"edge\"];\n\n/**\n * Works out an export with styles: the refusal when the styles belong to another graph, the losses, the exporter's\n * `options.styles`, and the snapshot to write.\n * @param snapshot - the graph being written\n * @param exporter - the format's exporter\n * @param given - the styles\n * @param plain - the export's other options, which decide what the format loses of the graph's data\n * @returns what to write and what is lost\n */\nexport function prepareStyleExport(\n snapshot: GraphSnapshot,\n exporter: GraphExporter,\n given: ExtractedStyles,\n plain?: Readonly<Record<string, unknown>>,\n): PreparedStyleExport {\n const fp = styleFingerprint(snapshot);\n const want = given.fingerprint;\n if (fp.nodes !== want.nodes || fp.edges !== want.edges || fp.ids !== want.ids) {\n return {\n snapshot,\n input: null,\n notes: [],\n refusal: Object.freeze({\n code: STYLE_ISSUE.MISMATCH,\n message: `the styles were read from or built for a different graph (${String(want.nodes)} nodes and ${String(want.edges)} edges, this graph has ${String(fp.nodes)} and ${String(fp.edges)}, or other node ids); nothing is written`,\n column: null,\n count: null,\n }),\n };\n }\n const caps = exporter.styles?.capabilities ?? null;\n let plan = writePlan(snapshot, exporter, given);\n if (keepsStyleBlock(exporter)) {\n // what the export loses of the graph's data, styles written as they are: the rules' inputs among it are carried\n let checked: readonly LossNote[];\n try {\n checked = exporter.check(plan.snapshot, plan.input === null ? plain : { ...plain, styles: plan.input });\n } catch {\n checked = [];\n }\n const carried = withLostInputsCarried(given, snapshot, checked);\n if (carried !== given) {\n plan = writePlan(snapshot, exporter, carried);\n }\n }\n return {\n snapshot: plan.snapshot,\n input: plan.input,\n notes: lossNotes(plan.extracted, exporter, caps, plan.picture, snapshot),\n refusal: null,\n };\n}\n\n/**\n * The work an exporter shares between the check and the write of one export call, by the styles input made for that\n * call (null until the first exporter step does it). Only an input writePlan() made is here, so an input a caller\n * builds and changes in place is always worked out again.\n */\nconst CALL_WORK = new WeakMap<\n ExporterStyleInput,\n { readonly key: readonly unknown[]; readonly value: unknown } | null\n>();\n\n/**\n * Work an exporter does from its styles input once per export call: the registry checks before it writes, with the\n * same input, graph and options. Outside an export call (an input the caller made) it is done every time.\n * @param input - the exporter's `options.styles`\n * @param key - what else the work reads (the graph, options), compared by identity\n * @param compute - the work\n * @returns its result\n */\nexport function sharedInExportCall<T>(input: ExporterStyleInput, key: readonly unknown[], compute: () => T): T {\n if (!CALL_WORK.has(input)) {\n return compute();\n }\n const done = CALL_WORK.get(input);\n if (done?.key.length === key.length && done.key.every((k, i) => k === key[i])) {\n return done.value as T;\n }\n const value = compute();\n CALL_WORK.set(input, { key, value });\n return value;\n}\n\n/**\n * What an exporter is handed to write a graph's styles: the snapshot with the block and tagged values added where\n * the format keeps them, and its `options.styles`.\n * @param snapshot - the graph\n * @param exporter - the exporter\n * @param extracted - the styles\n * @returns the plan\n */\nfunction writePlan(\n snapshot: GraphSnapshot,\n exporter: GraphExporter,\n extracted: ExtractedStyles,\n): {\n readonly snapshot: GraphSnapshot;\n readonly input: ExporterStyleInput | null;\n readonly extracted: ExtractedStyles;\n readonly picture: (target: StyleTarget, property: StyleProperty) => readonly (StyleValue | null)[];\n} {\n const caps = exporter.styles?.capabilities ?? null;\n const pictures = new Map<string, readonly (StyleValue | null)[]>();\n const picture = (target: StyleTarget, property: StyleProperty): readonly (StyleValue | null)[] => {\n const key = `${target}\\u0000${property}`;\n let values = pictures.get(key);\n if (values === undefined) {\n values = resolveStyles(extracted, target, property, snapshot);\n pictures.set(key, values);\n }\n return values;\n };\n const tags = { node: new Map<string, StyleColumn>(), edge: new Map<string, StyleColumn>() };\n for (const target of TARGETS) {\n for (const [key, col] of extracted.columns[target]) {\n tags[target].set(styleTag(target, key), col);\n }\n }\n const block = writeStyleBlock(extracted, { snapshot });\n const input = exporter.styles === undefined ? null : { picture, block, tags, rules: extracted };\n if (input !== null) {\n CALL_WORK.set(input, null);\n }\n return {\n snapshot: styledSnapshot(snapshot, caps, tags, block, extracted.styles.rules),\n input,\n extracted,\n picture,\n };\n}\n\n/**\n * Loss notes about a column whose values read back the same: written elsewhere (CSV's node table), under another\n * name a block finds by its values, with another role, storage or number type, or as a wider type.\n */\nconst VALUES_KEPT = /NODE_TABLE|NAME_CHANGED|ROLE_ASSUMED|STORAGE_CLASS|NUMBER_TYPE|INTEGRAL|WIDENED/;\n\n/**\n * The styles with every input the format will not read back as it is given carried as a style column of its own: a\n * data column the export drops or changes (its loss notes name it), and the in and out degrees when the file does not\n * keep the edges' direction. The rules then read the copies, which the file keeps beside the block, and give back the\n * same values.\n * @param extracted - the styles\n * @param snapshot - the graph\n * @param notes - what the export, styles written as they are, loses\n * @returns the styles, the same object when nothing is lost\n */\nfunction withLostInputsCarried(\n extracted: ExtractedStyles,\n snapshot: GraphSnapshot,\n notes: readonly LossNote[],\n): ExtractedStyles {\n const lost = new Set<string>();\n let direction = false;\n for (const note of notes) {\n if (!VALUES_KEPT.test(note.code)) {\n for (const name of note.columns ?? (note.column === null ? [] : [note.column])) {\n lost.add(name);\n }\n }\n direction ||= /DIRECTION/.test(note.code);\n }\n const carrier = new LostInputs(snapshot, lost, direction, extracted.columns);\n const rules = extracted.styles.rules.map((rule) => carrier.carry(rule));\n const changed = rules.some((rule, i) => rule !== extracted.styles.rules[i]);\n return changed ? { ...extracted, styles: { ...extracted.styles, rules }, columns: carrier.columns } : extracted;\n}\n\n/** Carries the inputs of rules that the format will not read back into style columns of their own. */\nclass LostInputs {\n /** The style columns, the copies added. */\n readonly columns: { readonly node: Map<string, StyleColumn>; readonly edge: Map<string, StyleColumn> };\n\n /** Whether the rule being carried read a lost input. */\n private touched = false;\n\n /**\n * A carrier for one export.\n * @param snapshot - the graph\n * @param lost - the data columns the export drops or changes\n * @param direction - whether the file loses the edges' direction (and so the in and out degrees)\n * @param columns - the styles' own style columns\n * @param columns.node - the node columns\n * @param columns.edge - the edge columns\n */\n constructor(\n private readonly snapshot: GraphSnapshot,\n private readonly lost: ReadonlySet<string>,\n private readonly direction: boolean,\n columns: { readonly node: ReadonlyMap<string, StyleColumn>; readonly edge: ReadonlyMap<string, StyleColumn> },\n ) {\n this.columns = { node: new Map(columns.node), edge: new Map(columns.edge) };\n }\n\n /**\n * A rule with every lost input it reads replaced by a copy of its values.\n * @param rule - the rule\n * @returns the rule read from copies, or the rule itself when it reads no lost input\n */\n carry(rule: StyleRule): StyleRule {\n this.touched = false;\n const { ext, ...given } = rule;\n const map = this.carryMap(rule);\n const where = this.walk(rule, given.where);\n if (!this.touched) {\n return rule;\n }\n const { map: _given, ...unmapped } = given;\n const plain = Object.keys(map).length === 0 ? { ...unmapped, where } : { ...unmapped, where, map };\n // a JSON copy drops undefined members, as the written block does; structuredClone would keep them\n const moved = JSON.parse(JSON.stringify(plain)) as StyleRule; // NOSONAR(S7784): undefined members must go\n return ext === undefined ? moved : { ...moved, ext };\n }\n\n /**\n * A rule's mappings with their lost inputs replaced. A passthrough reads a data column as the property's value: its\n * copy holds those values; one that gives no element a value (a list, text that is not a color) is left out, so\n * no other value the file reads back in the column (a list written as text) is given either.\n * @param rule - the rule\n * @returns the mappings\n */\n private carryMap(rule: StyleRule): Record<string, Mapping> {\n const map = Object.create(null) as Record<string, Mapping>;\n const { table } = this.tableOf(rule.target);\n for (const [property, mapping] of Object.entries(rule.map ?? {})) {\n if (mapping === undefined) {\n continue;\n }\n if (mapping.kind !== \"passthrough\") {\n map[property] = this.walk(rule, mapping);\n continue;\n }\n const name = (mapping.by as { data?: unknown }).data;\n const lostColumn = typeof name === \"string\" && this.lost.has(name) && table.has(name);\n const values = lostColumn ? this.cells(rule.target, name, canonicalFor(rule.target, property)) : null;\n if (values !== null && !values.some((v) => v !== null)) {\n this.touched = true;\n } else if (values !== null && this.isLost(rule.target, name)) {\n this.touched = true;\n map[property] = { ...mapping, by: this.copy(rule.target, `${property}.data.${name}`, () => values) };\n } else {\n map[property] = mapping;\n }\n }\n return map;\n }\n\n /**\n * A value with every other reference to a lost input reading a copy of its values as they are.\n * @param rule - the rule it belongs to\n * @param value - the value\n * @returns the value, references replaced\n */\n private walk<T>(rule: StyleRule, value: T): T {\n return JSON.parse(JSON.stringify(value, (_k, v: unknown) => this.replaced(rule, v))) as T;\n }\n\n /**\n * One reference with a lost input replaced by its copy: a data column, or a degree the file does not keep.\n * @param rule - the rule it belongs to\n * @param v - a value of the rule\n * @returns the value, or the reference to the copy\n */\n private replaced(rule: StyleRule, v: unknown): unknown {\n if (typeof v !== \"object\" || v === null || Array.isArray(v) || Object.keys(v).length !== 1) {\n return v;\n }\n const ref = v as { data?: unknown; computed?: unknown };\n if (this.isLost(rule.target, ref.data)) {\n const name = ref.data;\n this.touched = true;\n return this.copy(rule.target, `data.${name}`, () =>\n this.cells(rule.target, name, (raw) => (isStyleScalar(raw) ? raw : null)),\n );\n }\n const which = ref.computed;\n if ((which === \"indegree\" || which === \"outdegree\") && this.direction && rule.target === \"node\") {\n this.touched = true;\n return this.copy(rule.target, `computed.${which}`, () => degreeValues(this.snapshot, which));\n }\n return v;\n }\n\n /**\n * The reference to a copy of an input, made on first use and shared by every rule that reads it.\n * @param target - nodes or edges\n * @param base - what is copied\n * @param values - its values\n * @returns the reference\n */\n private copy(target: StyleTarget, base: string, values: () => StyleColumn): { style: string } {\n const key = `input.${base}`;\n const held = this.columns[target];\n if (!held.has(key)) {\n held.set(key, values());\n }\n return { style: key };\n }\n\n /**\n * Whether a name is a lost input that can be copied: only a column of plain values can, and a list, or a column with\n * no value, stays as it is.\n * @param target - nodes or edges\n * @param name - the name\n * @returns true for a lost input\n */\n private isLost(target: StyleTarget, name: unknown): name is string {\n const { table, n } = this.tableOf(target);\n return typeof name === \"string\" && this.lost.has(name) && table.has(name) && carriable(table, n, name);\n }\n\n /**\n * Every element's value of a data column.\n * @param target - nodes or edges\n * @param name - the column\n * @param read - the value of a cell\n * @returns the values\n */\n private cells(target: StyleTarget, name: string, read: (raw: unknown) => StyleValue | null): StyleColumn {\n const { table, n } = this.tableOf(target);\n return Array.from({ length: n }, (_u, i) => read(dataCell(table, name, i)));\n }\n\n /**\n * A target's table and row count.\n * @param target - nodes or edges\n * @returns the table and its row count\n */\n private tableOf(target: StyleTarget): { table: GraphSnapshot[\"nodes\"]; n: number } {\n const { snapshot } = this;\n return target === \"node\"\n ? { table: snapshot.nodes, n: snapshot.nodeCount }\n : { table: snapshot.edges, n: snapshot.edgeCount };\n }\n}\n\n/**\n * Whether a data column can be copied into a style column: some value, and every value text, a finite number or a\n * boolean.\n * @param table - the table\n * @param n - its row count\n * @param name - the column\n * @returns true when it can\n */\nfunction carriable(table: GraphSnapshot[\"nodes\"], n: number, name: string): boolean {\n let some = false;\n for (let i = 0; i < n; i++) {\n const cell = plainCell(table.value(name, i));\n if (cell !== null && cell !== undefined) {\n if (!isStyleScalar(cell)) {\n return false;\n }\n some = true;\n }\n }\n return some;\n}\n\n/**\n * Whether a cell is a value a style column holds: text, a finite number or a boolean.\n * @param v - the cell\n * @returns true for a scalar\n */\nfunction isStyleScalar(v: unknown): v is StyleValue {\n return typeof v === \"string\" || typeof v === \"boolean\" || (typeof v === \"number\" && Number.isFinite(v));\n}\n\n/**\n * Whether an exporter keeps the `graphty.styles` block, natively or as a graph attribute.\n * @param exporter - the exporter\n * @returns true when the block is written\n */\nfunction keepsStyleBlock(exporter: GraphExporter): boolean {\n const caps = exporter.styles?.capabilities;\n return (\n caps !== undefined &&\n (caps.block === \"native\" || (caps.block === \"attributes\" && exporter.capabilities.graphAttributes))\n );\n}\n\n/**\n * Whether a loss note is about a property only graphty draws (`graphty:<channel>`) in a file that keeps the block:\n * the block carries it, and no other program would draw it, so nothing is lost.\n * @param note - the note\n * @param exporter - the exporter writing the file\n * @returns true when the note names nothing lost\n */\nexport function isKeptGraphtyProperty(note: LossNote, exporter: GraphExporter): boolean {\n return note.style?.property.startsWith(\"graphty:\") === true && keepsStyleBlock(exporter);\n}\n\n/**\n * The losses of an export with styles: W_STYLE_NOT_WRITTEN for every property the format does not write natively\n * (all of them for an exporter without a `styles` member), and W_STYLE_RULES_NOT_KEPT when the block is not kept.\n * @param extracted - the styles\n * @param exporter - the exporter\n * @param caps - its style capabilities, or null\n * @param picture - each element's value of a property\n * @param snapshot - the graph\n * @returns the notes\n */\nfunction lossNotes(\n extracted: ExtractedStyles,\n exporter: GraphExporter,\n caps: StyleWriteCapabilities | null,\n picture: (target: StyleTarget, property: StyleProperty) => readonly (StyleValue | null)[],\n snapshot: GraphSnapshot,\n): LossNote[] {\n const notes: LossNote[] = [];\n const kept = keepsStyleBlock(exporter);\n for (const target of TARGETS) {\n const written = new Set<string>(caps?.[target] ?? []);\n for (const property of ruleProperties(extracted.styles.rules, target)) {\n // a property only graphty draws is written into the block alone: lost only when the block is\n if (written.has(property) || (kept && property.startsWith(\"graphty:\"))) {\n if (target === \"edge\") {\n notes.push(...pairNotes(snapshot, exporter, property, picture(\"edge\", property as StyleProperty)));\n }\n } else {\n notes.push(notWrittenNote(target, property, exporter, picture));\n }\n }\n }\n notes.push(...graphLossNotes(extracted, exporter, caps));\n if (kept) {\n notes.push(...styleBlockLosses(writeStyleBlock(extracted, { snapshot }), extracted.styles.rules.length));\n } else if (extracted.styles.rules.length > 0) {\n notes.push(\n Object.freeze({\n code: STYLE_ISSUE.RULES_NOT_KEPT,\n message: `the style rules are not kept: the ${exporter.format} format has no place for them; importing the file infers them again from what it holds`,\n column: null,\n count: extracted.styles.rules.length,\n }),\n );\n }\n return notes;\n}\n\n/**\n * W_STYLE_NOT_WRITTEN for every graph property the format does not write.\n * @param extracted - the styles\n * @param exporter - the exporter\n * @param caps - its style capabilities, or null\n * @returns the notes\n */\nfunction graphLossNotes(\n extracted: ExtractedStyles,\n exporter: GraphExporter,\n caps: StyleWriteCapabilities | null,\n): LossNote[] {\n const graphWritten = new Set<string>(caps?.graph ?? []);\n return Object.keys(extracted.styles.graph)\n .filter((property) => !graphWritten.has(property))\n .map((property) =>\n Object.freeze({\n code: STYLE_ISSUE.NOT_WRITTEN,\n message: `the graph's ${property} is not written: the ${exporter.format} format has no place for it`,\n column: null,\n count: 1,\n style: Object.freeze({ target: \"graph\" as const, property: property as \"background\" }),\n }),\n );\n}\n\n/**\n * The properties the rules of a target write, in first-written order.\n * @param rules - the rules\n * @param target - nodes or edges\n * @returns the properties\n */\nfunction ruleProperties(rules: readonly StyleRule[], target: StyleTarget): Set<string> {\n return new Set(\n rules\n .filter((rule) => rule.target === target)\n .flatMap((rule) => [...Object.keys(rule.set ?? {}), ...Object.keys(rule.map ?? {})]),\n );\n}\n\n/**\n * W_STYLE_NOT_WRITTEN for a property the format has no place for.\n * @param target - nodes or edges\n * @param property - the property\n * @param exporter - the exporter\n * @param picture - each element's value of a property\n * @returns the note\n */\nfunction notWrittenNote(\n target: StyleTarget,\n property: string,\n exporter: GraphExporter,\n picture: (target: StyleTarget, property: StyleProperty) => readonly (StyleValue | null)[],\n): LossNote {\n const count = picture(target, property as StyleProperty).filter((v) => v !== null).length;\n return Object.freeze({\n code: STYLE_ISSUE.NOT_WRITTEN,\n message: `${target} ${property} is not written: the ${exporter.format} format has no place for it (${String(count)} ${target}${plural(count)} ${agree(count, \"has\", \"have\")} a value)`,\n column: null,\n count,\n style: Object.freeze({ target, property: property as StyleProperty }),\n });\n}\n\n/**\n * W_STYLE_APPROXIMATED for the second halves of undirected edges in a directed graph whose value of a property\n * differs from the first half's: every format writes such an edge once, so both halves read back with one value.\n * @param snapshot - the graph\n * @param exporter - the exporter\n * @param property - the edge property\n * @param values - each edge's value\n * @returns the note, or none\n */\nfunction pairNotes(\n snapshot: GraphSnapshot,\n exporter: GraphExporter,\n property: string,\n values: readonly (StyleValue | null)[],\n): LossNote[] {\n const pair = snapshot.edges.byRole(\"pair\");\n let count = 0;\n for (let i = 0; pair !== null && i < values.length; i++) {\n const other = pair.isSet(i) ? (pair.value(i) as number) : i;\n if (other < i && values[i] !== values[other]) {\n count++;\n }\n }\n if (count === 0) {\n return [];\n }\n return [\n Object.freeze({\n code: STYLE_ISSUE.APPROXIMATED,\n message: `edge ${property}: ${String(count)} undirected edge${plural(count)} in a directed graph ${agree(count, \"has\", \"have\")} another value on each half; the ${exporter.format} format writes the edge once, with the first half's value`,\n column: null,\n count,\n style: Object.freeze({ target: \"edge\" as const, property: property as StyleProperty }),\n }),\n ];\n}\n\n/**\n * The snapshot an exporter writes when styles are given: columns with a style role keep their data but lose the\n * role (the style writer is the only thing that writes the format's style slots), and for `block: \"attributes\"`\n * the block becomes a graph attribute and the tagged values element attributes.\n * @param snapshot - the graph\n * @param caps - the exporter's style capabilities, or null\n * @param tags - the tagged per-element values\n * @param tags.node - node values by attribute name\n * @param tags.edge - edge values by attribute name\n * @param block - the block's text\n * @param rules - the rules written, which keep a style value column of an earlier write they read as data\n * @returns the snapshot to write (the same object when nothing changes)\n */\nfunction styledSnapshot(\n snapshot: GraphSnapshot,\n caps: StyleWriteCapabilities | null,\n tags: { readonly node: ReadonlyMap<string, StyleColumn>; readonly edge: ReadonlyMap<string, StyleColumn> },\n block: string,\n rules: readonly StyleRule[],\n): GraphSnapshot {\n const attributes = caps?.block === \"attributes\";\n // the per-element style values of an earlier write whose block was set aside are data now; these styles write\n // their own under the same names, so the old ones go, unless these styles read them as data\n const stale = { node: staleTags(snapshot.nodes, rules, \"node\"), edge: staleTags(snapshot.edges, rules, \"edge\") };\n // a format that writes the label from the styles has its label slot taken: the label column is data there too\n const roles = { node: roledNames(snapshot.nodes, caps, \"node\"), edge: roledNames(snapshot.edges, caps, \"edge\") };\n // the block of an earlier import is replaced by the one these styles write, wherever the format puts that\n const staleBlock = snapshot.graph.has(STYLE_BLOCK_NAME);\n const changes = [stale.node, stale.edge, roles.node, roles.edge].some((names) => names.length > 0);\n if (!attributes && !staleBlock && !changes) {\n return snapshot;\n }\n const out = snapshot.withColumns();\n if (staleBlock) {\n out.graph.remove(STYLE_BLOCK_NAME);\n }\n for (const target of TARGETS) {\n const table = target === \"node\" ? out.nodes : out.edges;\n for (const name of stale[target]) {\n table.remove(name);\n }\n for (const name of roles[target]) {\n const col = table.get(name);\n if (col !== null) {\n // an explicit undefined role in the patch replaces the column's role with none\n table.set(name, col, { role: undefined });\n }\n }\n }\n if (attributes) {\n setTagAttributes(out, tags);\n out.graph.set(STYLE_BLOCK_NAME, [block], { dtype: \"string\" });\n }\n return out;\n}\n\n/**\n * The per-element style values of an earlier write that these rules do not read as data.\n * @param table - the node or edge table\n * @param rules - the rules written\n * @param target - nodes or edges\n * @returns the column names\n */\nfunction staleTags(table: GraphSnapshot[\"nodes\"], rules: readonly StyleRule[], target: StyleTarget): string[] {\n const read = dataRead(rules, target);\n return table.names().filter((name) => isStyleTagName(name) && !read.has(name));\n}\n\n/**\n * The columns whose style role the styles take: every style role, and the label where the format writes the label\n * from the styles.\n * @param table - the node or edge table\n * @param caps - the exporter's style capabilities, or null\n * @param target - nodes or edges\n * @returns the column names\n */\nfunction roledNames(table: GraphSnapshot[\"nodes\"], caps: StyleWriteCapabilities | null, target: StyleTarget): string[] {\n const writesLabel = (caps?.[target] ?? []).includes(\"label\");\n return table.names().filter((name) => {\n const role = table.get(name)?.meta.role ?? \"\";\n return STYLE_ROLES.has(role) || (role === \"label\" && writesLabel);\n });\n}\n\n/**\n * Sets the tagged per-element values as element attributes, replacing those of an earlier import in the order of\n * these styles' columns, so writing a file read back gives the same bytes whichever elements held a value first.\n * @param out - the graph, changed in place\n * @param tags - the tagged values\n * @param tags.node - node values by attribute name\n * @param tags.edge - edge values by attribute name\n */\nfunction setTagAttributes(\n out: GraphSnapshot,\n tags: { readonly node: ReadonlyMap<string, StyleColumn>; readonly edge: ReadonlyMap<string, StyleColumn> },\n): void {\n for (const target of TARGETS) {\n const table = target === \"node\" ? out.nodes : out.edges;\n const prefix = styleTag(target, \"\");\n for (const name of table.names().filter((c) => c.startsWith(prefix))) {\n table.remove(name);\n }\n for (const [name, col] of tags[target]) {\n const dtype = tagDtype(col);\n table.set(name, dtype === \"string\" ? col.map((v) => (v === null ? null : String(v))) : col, { dtype });\n }\n }\n}\n\n/**\n * Whether a column name is one graphty writes per-element style values under: `graphty.style.<target>.<key>`, or\n * `graphty_style_<...>` where the format allows no dots in a name (GML, Cytoscape.js).\n * @param name - the column name\n * @returns true for a style value name\n */\nfunction isStyleTagName(name: string): boolean {\n return name.startsWith(\"graphty.style.\") || name.startsWith(\"graphty_style_\");\n}\n\n/**\n * The data columns the rules of one target read.\n * @param rules - the rules\n * @param target - nodes or edges\n * @returns the column names\n */\nexport function dataRead(rules: readonly StyleRule[], target: StyleTarget): Set<string> {\n const out = new Set<string>();\n for (const { ext: _ext, ...rule } of rules.filter((r) => r.target === target)) {\n JSON.stringify(rule, (_k, v: unknown) => {\n const data =\n typeof v === \"object\" && v !== null && !Array.isArray(v) ? (v as { data?: unknown }).data : null;\n if (typeof data === \"string\" && Object.keys(v as object).length === 1) {\n out.add(data);\n }\n return v;\n });\n }\n return out;\n}\n\n/**\n * The dtype a tagged column is written with: numbers, booleans or text (a mixed column as text).\n * @param col - the values\n * @returns the dtype\n */\nfunction tagDtype(col: StyleColumn): \"f64\" | \"bool\" | \"string\" {\n let kind: string | null = null;\n for (const v of col) {\n if (v === null) {\n continue;\n }\n if (kind === null) {\n kind = typeof v;\n } else if (kind !== typeof v) {\n return \"string\";\n }\n }\n if (kind === \"number\") {\n return \"f64\";\n }\n return kind === \"boolean\" ? \"bool\" : \"string\";\n}\n"],"names":[],"mappings":";;AA0EA,MAAM,kCAAuC,IAAI,CAAC,SAAS,QAAQ,SAAS,aAAa,QAAQ,CAAC;AAClG,MAAM,UAAkC,CAAC,QAAQ,MAAM;AAWhD,SAAS,mBACZ,UACA,UACA,OACA,OACmB;AACnB,QAAM,KAAK,iBAAiB,QAAQ;AACpC,QAAM,OAAO,MAAM;AACnB,MAAI,GAAG,UAAU,KAAK,SAAS,GAAG,UAAU,KAAK,SAAS,GAAG,QAAQ,KAAK,KAAK;AAC3E,WAAO;AAAA,MACH;AAAA,MACA,OAAO;AAAA,MACP,OAAO,CAAA;AAAA,MACP,SAAS,OAAO,OAAO;AAAA,QACnB,MAAM,YAAY;AAAA,QAClB,SAAS,6DAA6D,OAAO,KAAK,KAAK,CAAC,cAAc,OAAO,KAAK,KAAK,CAAC,0BAA0B,OAAO,GAAG,KAAK,CAAC,QAAQ,OAAO,GAAG,KAAK,CAAC;AAAA,QAC1L,QAAQ;AAAA,QACR,OAAO;AAAA,MAAA,CACV;AAAA,IAAA;AAAA,EAET;AACA,QAAM,OAAO,SAAS,QAAQ,gBAAgB;AAC9C,MAAI,OAAO,UAAU,UAAU,UAAU,KAAK;AAC9C,MAAI,gBAAgB,QAAQ,GAAG;AAE3B,QAAI;AACJ,QAAI;AACA,gBAAU,SAAS,MAAM,KAAK,UAAU,KAAK,UAAU,OAAO,QAAQ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