{"version":3,"file":"parsePointsAttribute.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":"AAEA;AACA;AACA;AACA;AACA;AACO,SAASA,oBAAoBA,CAACC,MAAqB,EAAQ;AAChE;EACA,IAAI,CAACA,MAAM,EAAE;AACX,IAAA,OAAO,EAAE;AACX,EAAA;;AAEA;AACA,EAAA,MAAMC,WAAqB,GAAGD,MAAM,CAACE,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAACC,IAAI,EAAE,CAACC,KAAK,CAAC,KAAK,CAAC;EAE3E,MAAMC,YAAY,GAAG,EAAE;AAEvB,EAAA,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGL,WAAW,CAACM,MAAM,EAAED,CAAC,IAAI,CAAC,EAAE;IAC9CD,YAAY,CAACG,IAAI,CAAC;AAChBC,MAAAA,CAAC,EAAEC,UAAU,CAACT,WAAW,CAACK,CAAC,CAAC,CAAC;MAC7BK,CAAC,EAAED,UAAU,CAACT,WAAW,CAACK,CAAC,GAAG,CAAC,CAAC;AAClC,KAAC,CAAC;AACJ,EAAA;;AAEA;AACA;AACA;AACA;AACA,EAAA,OAAOD,YAAY;AACrB;;;;"}