{
  "version": 3,
  "sources": ["../../../../../src/lib/shapes/shared/freehand/fmt.ts"],
  "sourcesContent": ["// Fast SVG path data building.\n//\n// Browsers don't render differences below a hundredth of a pixel, so we emit at most 2 decimal\n// places. Stringifying doubles rounded to 2 decimals is slow (they routinely miss V8's fast\n// float-to-string path), and concatenating many small strings costs more than the math itself.\n// Instead we round every coordinate to an integer number of hundredths (\"centi-pixels\") and\n// write decimal digits straight into a byte buffer, decoding to a string once per path.\n//\n// Paths use relative commands (t/q/a/l) wherever possible: deltas between consecutive points\n// are small numbers, which keeps the path data compact. Because deltas are differences of the\n// rounded integers, they sum back to the rounded absolute positions exactly: no drift.\n\nlet buf = new Uint8Array(65536)\nlet pos = 0\nconst decoder = new TextDecoder()\n\nfunction ensure(n: number) {\n\tif (pos + n > buf.length) {\n\t\tconst next = new Uint8Array(buf.length * 2)\n\t\tnext.set(buf)\n\t\tbuf = next\n\t}\n}\n\n/** Start a new path. Builders must call this before writing. */\nexport function resetPath() {\n\tpos = 0\n}\n\n/** Append a string of ASCII characters (command letters, arc flags) to the path. */\nexport function writeStr(s: string) {\n\tensure(s.length)\n\tfor (let i = 0; i < s.length; i++) {\n\t\tbuf[pos++] = s.charCodeAt(i)\n\t}\n}\n\n/**\n * Append a value given in integer hundredths, e.g. 255 as `2.55`, -30 as `-.3`, 0 as `0`.\n * Assumes |n| < 2^31, which holds for canvas coordinates (|v| < ~21 million px).\n */\nexport function writeC(n: number) {\n\tensure(16)\n\tif (n < 0) {\n\t\tbuf[pos++] = 45 // '-'\n\t\tn = -n\n\t}\n\tconst i = (n / 100) | 0\n\tconst f = n - i * 100\n\tif (i === 0) {\n\t\tif (f === 0) {\n\t\t\tbuf[pos++] = 48 // '0'\n\t\t\treturn\n\t\t}\n\t} else if (i < 10) {\n\t\tbuf[pos++] = 48 + i\n\t} else if (i < 100) {\n\t\tbuf[pos++] = 48 + ((i / 10) | 0)\n\t\tbuf[pos++] = 48 + (i % 10)\n\t} else {\n\t\tconst start = pos\n\t\tlet m = i\n\t\twhile (m > 0) {\n\t\t\tbuf[pos++] = 48 + (m % 10)\n\t\t\tm = (m / 10) | 0\n\t\t}\n\t\t// digits came out least-significant first; reverse them\n\t\tlet lo = start\n\t\tlet hi = pos - 1\n\t\twhile (lo < hi) {\n\t\t\tconst t = buf[lo]\n\t\t\tbuf[lo] = buf[hi]\n\t\t\tbuf[hi] = t\n\t\t\tlo++\n\t\t\thi--\n\t\t}\n\t}\n\tif (f !== 0) {\n\t\tbuf[pos++] = 46 // '.'\n\t\tconst d2 = f % 10\n\t\tbuf[pos++] = 48 + ((f / 10) | 0)\n\t\tif (d2 !== 0) {\n\t\t\tbuf[pos++] = 48 + d2\n\t\t}\n\t}\n}\n\n/** Append a coordinate pair given in integer hundredths as `x,y `. */\nexport function writeCPair(nx: number, ny: number) {\n\twriteC(nx)\n\tbuf[pos++] = 44 // ','\n\twriteC(ny)\n\tbuf[pos++] = 32 // ' '\n}\n\n/** Finish the path: decode everything written since `resetPath` and reset the writer. */\nexport function finishPath(): string {\n\tconst s = decoder.decode(buf.subarray(0, pos))\n\tpos = 0\n\treturn s\n}\n\n/** Round a coordinate to integer hundredths. */\nexport function toCenti(v: number): number {\n\treturn Math.round(v * 100)\n}\n"],
  "mappings": "AAYA,IAAI,MAAM,IAAI,WAAW,KAAK;AAC9B,IAAI,MAAM;AACV,MAAM,UAAU,IAAI,YAAY;AAEhC,SAAS,OAAO,GAAW;AAC1B,MAAI,MAAM,IAAI,IAAI,QAAQ;AACzB,UAAM,OAAO,IAAI,WAAW,IAAI,SAAS,CAAC;AAC1C,SAAK,IAAI,GAAG;AACZ,UAAM;AAAA,EACP;AACD;AAGO,SAAS,YAAY;AAC3B,QAAM;AACP;AAGO,SAAS,SAAS,GAAW;AACnC,SAAO,EAAE,MAAM;AACf,WAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK;AAClC,QAAI,KAAK,IAAI,EAAE,WAAW,CAAC;AAAA,EAC5B;AACD;AAMO,SAAS,OA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