fabric
Version:
Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.
1 lines • 1.3 kB
Source Map (JSON)
{"version":3,"file":"parsePointsAttribute.min.mjs","names":[],"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"],"mappings":"AAOA,SAAgB,EAAqB,EAAA,CAEnC,GAAA,CAAK,EACH,MAAO,EAAA,CAIT,IAAM,EAAwB,EAAO,QAAQ,KAAM,IAAA,CAAK,MAAA,CAAO,MAAM,MAAA,CAE/D,EAAe,EAAA,CAErB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAY,OAAQ,GAAK,EAC3C,EAAa,KAAK,CAChB,EAAG,WAAW,EAAY,GAAA,CAC1B,EAAG,WAAW,EAAY,EAAI,GAAA,CAAA,CAAA,CAQlC,OAAO,EAAA,OAAA,KAAA"}