UNPKG

fabric

Version:

Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.

1 lines 1.29 kB
{"version":3,"file":"parsePointsAttribute.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,qBAAqB,QAA6B;AAEhE,KAAI,CAAC,OACH,QAAO,EAAE;CAIX,MAAM,cAAwB,OAAO,QAAQ,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,MAAM;CAE3E,MAAM,eAAe,EAAE;AAEvB,MAAK,IAAI,IAAI,GAAG,IAAI,YAAY,QAAQ,KAAK,EAC3C,cAAa,KAAK;EAChB,GAAG,WAAW,YAAY,GAAG;EAC7B,GAAG,WAAW,YAAY,IAAI,GAAG;EAClC,CAAC;AAOJ,QAAO"}