{"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-union/dist/cjs/index.cjs","../../index.ts"],"names":["union"],"mappings":"AAAA;ACAA,8FAA0B;AAC1B,wCAAsC;AACtC,kCAAyB;AAyDzB,SAASA,MAAAA,CACP,QAAA,EACA,QAAA,EAA8B,CAAC,CAAA,EACY;AAC3C,EAAA,MAAM,MAAA,EAAyB,CAAC,CAAA;AAChC,EAAA,4BAAA,QAAS,EAAU,CAAC,IAAA,EAAA,GAAS;AAC3B,IAAA,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,WAA4B,CAAA;AAAA,EAC9C,CAAC,CAAA;AAED,EAAA,GAAA,CAAI,KAAA,CAAM,OAAA,EAAS,CAAA,EAAG;AACpB,IAAA,MAAM,IAAI,KAAA,CAAM,iCAAiC,CAAA;AAAA,EACnD;AAEA,EAAA,MAAM,QAAA,EAAmB,QAAA,CAAA,KAAA,CAAM,KAAA,CAAM,CAAC,CAAA,EAAG,GAAG,KAAA,CAAM,KAAA,CAAM,CAAC,CAAC,CAAA;AAC1D,EAAA,GAAA,CAAI,OAAA,CAAQ,OAAA,IAAW,CAAA,EAAG,OAAO,IAAA;AACjC,EAAA,GAAA,CAAI,OAAA,CAAQ,OAAA,IAAW,CAAA,EAAG,OAAO,8BAAA,OAAQ,CAAQ,CAAC,CAAA,EAAG,OAAA,CAAQ,UAAU,CAAA;AAAA,EAAA,KAClE,OAAO,mCAAA,OAAa,EAAS,OAAA,CAAQ,UAAU,CAAA;AACtD;AAGA,IAAO,mBAAA,EAAQA,MAAAA;AD7Df;AACE;AACA;AACF,6DAAC","file":"/home/runner/work/turf/turf/packages/turf-union/dist/cjs/index.cjs","sourcesContent":[null,"import * as polyclip from \"polyclip-ts\";\nimport { multiPolygon, polygon } from \"@turf/helpers\";\nimport { geomEach } from \"@turf/meta\";\nimport {\n FeatureCollection,\n Feature,\n Polygon,\n MultiPolygon,\n GeoJsonProperties,\n} from \"geojson\";\n\n/**\n * Takes a collection of input polygons and returns a combined polygon. If the\n * input polygons are not contiguous, this function returns a multi-polygon\n * feature.\n *\n * @function\n * @param {FeatureCollection} features input polygon features\n * @param {Object} [options={}] Optional Parameters\n * @param {GeoJsonProperties} [options.properties={}] properties to assign to output feature\n * @returns {Feature<(Polygon|MultiPolygon)>|null} a combined polygon or multi-polygon feature, or null if there were no input polygons to combine\n * @example\n *\n * const poly1 = turf.polygon(\n * [\n * [\n * [-82.574787, 35.594087],\n * [-82.574787, 35.615581],\n * [-82.545261, 35.615581],\n * [-82.545261, 35.594087],\n * [-82.574787, 35.594087],\n * ],\n * ],\n * { fill: \"#0f0\" }\n * );\n *\n * const poly2 = turf.polygon(\n * [\n * [\n * [-82.560024, 35.585153],\n * [-82.560024, 35.602602],\n * [-82.52964, 35.602602],\n * [-82.52964, 35.585153],\n * [-82.560024, 35.585153],\n * ],\n * ],\n * );\n *\n * const union = turf.union(turf.featureCollection([poly1, poly2]));\n *\n * //addToMap\n * const addToMap = { poly1, poly2, union };\n *\n * poly1.properties.fill = \"#0f0\";\n * poly2.properties.fill = \"#00f\";\n * union.properties.stroke = \"red\";\n * union.properties[\"stroke-width\"] = 4;\n * union.properties.fill = \"transparent\";\n */\nfunction union

(\n features: FeatureCollection,\n options: { properties?: P } = {}\n): Feature | null {\n const geoms: polyclip.Geom[] = [];\n geomEach(features, (geom) => {\n geoms.push(geom.coordinates as polyclip.Geom);\n });\n\n if (geoms.length < 2) {\n throw new Error(\"Must have at least 2 geometries\");\n }\n\n const unioned = polyclip.union(geoms[0], ...geoms.slice(1));\n if (unioned.length === 0) return null;\n if (unioned.length === 1) return polygon(unioned[0], options.properties);\n else return multiPolygon(unioned, options.properties);\n}\n\nexport { union };\nexport default union;\n"]}