{"version":3,"file":"parsePointsAttribute.min.mjs","sources":["../../../src/parser/parsePointsAttribute.ts"],"sourcesContent":["import type { XY } from '../Point';\n\n/**\n * Parses \"points\" attribute, returning an array of values\n * @param {String} points points attribute string\n * @return {Array} array of points\n */\nexport function parsePointsAttribute(points: string | null): XY[] {\n  // points attribute is required and must not be empty\n  if (!points) {\n    return [];\n  }\n\n  // replace commas with whitespace and remove bookending whitespace\n  const pointsSplit: string[] = points.replace(/,/g, ' ').trim().split(/\\s+/);\n\n  const parsedPoints = [];\n\n  for (let i = 0; i < pointsSplit.length; i += 2) {\n    parsedPoints.push({\n      x: parseFloat(pointsSplit[i]),\n      y: parseFloat(pointsSplit[i + 1]),\n    });\n  }\n\n  // odd number of points is an error\n  // if (parsedPoints.length % 2 !== 0) {\n  //   return null;\n  // }\n  return parsedPoints;\n}\n"],"names":["parsePointsAttribute","points","pointsSplit","replace","trim","split","parsedPoints","i","length","push","x","parseFloat","y"],"mappings":"AAOO,SAASA,EAAqBC,GAEnC,IAAKA,EACH,MAAO,GAIT,MAAMC,EAAwBD,EAAOE,QAAQ,KAAM,KAAKC,OAAOC,MAAM,OAE/DC,EAAe,GAErB,IAAK,IAAIC,EAAI,EAAGA,EAAIL,EAAYM,OAAQD,GAAK,EAC3CD,EAAaG,KAAK,CAChBC,EAAGC,WAAWT,EAAYK,IAC1BK,EAAGD,WAAWT,EAAYK,EAAI,MAQlC,OAAOD,CACT"}