{
  "version": 3,
  "sources": ["../../../../../src/lib/shapes/shared/freehand/svg.ts"],
  "sourcesContent": ["import { finishPath, resetPath, toCenti, writeCPair, writeStr } from './fmt'\nimport { StrokePoint } from './types'\n\n/**\n * Turn an array of stroke points into a path of quadratic curves.\n *\n * The path uses relative commands with coordinates rounded to hundredths of a pixel, which\n * renders identically to the absolute 4-decimal form but is much smaller and faster to build.\n *\n * @param points - The stroke points returned from perfect-freehand\n * @param closed - Whether the shape is closed\n *\n * @public\n */\nexport function getSvgPathFromStrokePoints(points: StrokePoint[], closed = false): string {\n\tconst len = points.length\n\n\tif (len < 2) {\n\t\treturn ''\n\t}\n\n\tresetPath()\n\n\tif (len === 2) {\n\t\tconst a = points[0].point\n\t\tconst b = points[1].point\n\t\tconst ax = toCenti(a.x)\n\t\tconst ay = toCenti(a.y)\n\t\twriteStr('M')\n\t\twriteCPair(ax, ay)\n\t\twriteStr('l')\n\t\twriteCPair(toCenti(b.x) - ax, toCenti(b.y) - ay)\n\t\treturn finishPath()\n\t}\n\n\tconst first = points[0].point\n\tconst second = points[1].point\n\tconst third = points[2].point\n\n\tconst secondX = toCenti(second.x)\n\tconst secondY = toCenti(second.y)\n\t// midpoint of the first and second points\n\tconst m01x = Math.round((first.x + second.x) * 50)\n\tconst m01y = Math.round((first.y + second.y) * 50)\n\t// midpoint of the second and third points\n\tconst m12x = Math.round((second.x + third.x) * 50)\n\tconst m12y = Math.round((second.y + third.y) * 50)\n\n\t// Current position in integer hundredths\n\tlet cx = m12x\n\tlet cy = m12y\n\n\tif (closed) {\n\t\t// If closed, start at the first midpoint and draw a curve through the second point\n\t\twriteStr('M')\n\t\twriteCPair(m01x, m01y)\n\t\twriteStr('q')\n\t\twriteCPair(secondX - m01x, secondY - m01y)\n\t\twriteCPair(m12x - m01x, m12y - m01y)\n\t\twriteStr('t')\n\t} else {\n\t\t// If not closed, draw a curve starting at the first point and\n\t\t// ending at the midpoint of the second and third points.\n\t\tconst firstX = toCenti(first.x)\n\t\tconst firstY = toCenti(first.y)\n\t\twriteStr('M')\n\t\twriteCPair(firstX, firstY)\n\t\twriteStr('q')\n\t\twriteCPair(secondX - firstX, secondY - firstY)\n\t\twriteCPair(m12x - firstX, m12y - firstY)\n\t\tif (len > 3) writeStr('t')\n\t}\n\n\t// Continue the smooth quadratic chain through the midpoints of the remaining points\n\tfor (let i = 2, max = len - 1; i < max; i++) {\n\t\tconst p = points[i].point\n\t\tconst q = points[i + 1].point\n\t\tconst mx = Math.round((p.x + q.x) * 50)\n\t\tconst my = Math.round((p.y + q.y) * 50)\n\t\twriteCPair(mx - cx, my - cy)\n\t\tcx = mx\n\t\tcy = my\n\t}\n\n\tconst last = points[len - 1].point\n\n\tif (closed) {\n\t\t// Draw a curve from the last-first midpoint back to the first-second midpoint\n\t\tconst mLastX = Math.round((last.x + first.x) * 50)\n\t\tconst mLastY = Math.round((last.y + first.y) * 50)\n\t\twriteCPair(mLastX - cx, mLastY - cy)\n\t\twriteCPair(m01x - mLastX, m01y - mLastY)\n\t\twriteStr('Z')\n\t} else {\n\t\t// Complete the curve with a line segment to the last point.\n\t\twriteStr('l')\n\t\twriteCPair(toCenti(last.x) - cx, toCenti(last.y) - cy)\n\t}\n\n\treturn finishPath()\n}\n"],
  "mappings": "AAAA,SAAS,YAAY,WAAW,SAAS,YAAY,gBAAgB;AAc9D,SAAS,2BAA2B,QAAuB,SAAS,OAAe;AACzF,QAAM,MAAM,OAAO;AAEnB,MAAI,MAAM,GAAG;AACZ,WAAO;AAAA,EACR;AAEA,YAAU;AAEV,MAAI,QAAQ,GAAG;AACd,UAAM,IAAI,OAAO,CAAC,EAAE;AACpB,UAAM,IAAI,OAAO,CAAC,EAAE;AACpB,UAAM,KAAK,QAAQ,EAAE,CAAC;AACtB,UAAM,KAAK,QAAQ,EAAE,CAAC;AACtB,aAAS,GAAG;AACZ,eAAW,IAAI,EAAE;AACjB,aAAS,GAAG;AACZ,eAAW,QAAQ,EAAE,CAAC,IAAI,IAAI,QAAQ,EAA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