"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
require("./src-graphlib-graph.cjs");
const isUndefined = require("../lodash-es/isUndefined.cjs");
const clone = require("../lodash-es/clone.cjs");
const map = require("../lodash-es/map.cjs");
function write(g) {
  var json = {
    options: {
      directed: g.isDirected(),
      multigraph: g.isMultigraph(),
      compound: g.isCompound()
    },
    nodes: writeNodes(g),
    edges: writeEdges(g)
  };
  if (!isUndefined.default(g.graph())) {
    json.value = clone.default(g.graph());
  }
  return json;
}
function writeNodes(g) {
  return map.default(g.nodes(), function(v) {
    var nodeValue = g.node(v);
    var parent = g.parent(v);
    var node = { v };
    if (!isUndefined.default(nodeValue)) {
      node.value = nodeValue;
    }
    if (!isUndefined.default(parent)) {
      node.parent = parent;
    }
    return node;
  });
}
function writeEdges(g) {
  return map.default(g.edges(), function(e) {
    var edgeValue = g.edge(e);
    var edge = { v: e.v, w: e.w };
    if (!isUndefined.default(e.name)) {
      edge.name = e.name;
    }
    if (!isUndefined.default(edgeValue)) {
      edge.value = edgeValue;
    }
    return edge;
  });
}
exports.write = write;
//# sourceMappingURL=src-graphlib-json.cjs.map
