{"version":3,"sources":["jsdelivr-header.js","/npm/geojson-linestring-dissolve@0.0.1/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACHA,SAAS,QAAS,GAChB,OAAO,EAAM,GAAG,WAAa,IAAM,EAAM,GAAG,UAC9C,CAGA,SAAS,iBAAkB,EAAG,GAC5B,IAOI,EAPA,EAAK,QAAQ,EAAE,YAAY,IAC3B,EAAK,QAAQ,EAAE,YAAY,EAAE,YAAY,OAAS,IAClD,EAAK,QAAQ,EAAE,YAAY,IAC3B,EAAK,QAAQ,EAAE,YAAY,EAAE,YAAY,OAAS,IAKtD,GAAI,IAAO,EACT,EAAS,EAAE,YAAY,OAAO,EAAE,YAAY,MAAM,SAC7C,GAAI,IAAO,EAChB,EAAS,EAAE,YAAY,OAAO,EAAE,YAAY,MAAM,SAC7C,GAAI,IAAO,EAChB,EAAS,EAAE,YAAY,MAAM,GAAG,UAAU,OAAO,EAAE,iBAC9C,IAAI,IAAO,EAGhB,OAAO,KAFP,EAAS,EAAE,YAAY,OAAO,EAAE,YAAY,UAAU,MAAM,GAG9D,CAEA,MAAO,CACL,KAAM,aACN,YAAa,EAEjB,CAKA,SAAS,uBAAwB,GAK/B,IAFA,IAAI,EAAc,EAAM,QACpB,EAAS,GACN,EAAY,OAAS,GAAG,CAC7B,IAAI,EAAK,EAAY,QAIrB,EAAc,EAAY,QAAO,SAAU,EAAO,GAChD,IAAI,EAAS,iBAAiB,EAAI,GAQlC,OAPI,EAEF,EAAK,EAGL,EAAM,KAAK,GAEN,CACT,GAAG,IAEH,EAAO,KAAK,EACd,CAUA,OAPE,EADoB,IAAlB,EAAO,OACA,EAAO,GAEP,CACP,KAAM,kBACN,YAAa,EAAO,KAAI,SAAU,GAAM,OAAO,EAAG,WAAY,KAG3D,CACT,CAxEA,OAAO,QAAU","file":"/npm/geojson-linestring-dissolve@0.0.1/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/geojson-linestring-dissolve@0.0.1/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","module.exports = mergeViableLineStrings\n\n// [Number, Number] -> String\nfunction coordId (coord) {\n  return coord[0].toString() + ',' + coord[1].toString()\n}\n\n// LineString, LineString -> LineString\nfunction mergeLineStrings (a, b) {\n  var s1 = coordId(a.coordinates[0])\n  var e1 = coordId(a.coordinates[a.coordinates.length - 1])\n  var s2 = coordId(b.coordinates[0])\n  var e2 = coordId(b.coordinates[b.coordinates.length - 1])\n\n  // TODO: handle case where more than one of these is true!\n\n  var coords\n  if (s1 === e2) {\n    coords = b.coordinates.concat(a.coordinates.slice(1))\n  } else if (s2 === e1) {\n    coords = a.coordinates.concat(b.coordinates.slice(1))\n  } else if (s1 === s2) {\n    coords = a.coordinates.slice(1).reverse().concat(b.coordinates)\n  } else if (e1 === e2) {\n    coords = a.coordinates.concat(b.coordinates.reverse().slice(1))\n  } else {\n    return null\n  }\n\n  return {\n    type: 'LineString',\n    coordinates: coords\n  }\n}\n\n// Merges all connected (non-forking, non-junctioning) line strings into single\n// line strings.\n// [LineString] -> LineString|MultiLineString\nfunction mergeViableLineStrings (geoms) {\n  // TODO: assert all are linestrings\n\n  var lineStrings = geoms.slice()\n  var result = []\n  while (lineStrings.length > 0) {\n    var ls = lineStrings.shift()\n\n    // Attempt to merge this LineString with the other LineStrings, updating\n    // the reference as it is merged with others and grows.\n    lineStrings = lineStrings.reduce(function (accum, cur) {\n      var merged = mergeLineStrings(ls, cur)\n      if (merged) {\n        // Accumulate the merged LineString\n        ls = merged\n      } else {\n        // Put the unmerged LineString back into the list\n        accum.push(cur)\n      }\n      return accum\n    }, [])\n\n    result.push(ls)\n  }\n\n  if (result.length === 1) {\n    result = result[0]\n  } else {\n    result = {\n      type: 'MultiLineString',\n      coordinates: result.map(function (ls) { return ls.coordinates })\n    }\n  }\n  return result\n}\n\n"]}