MCPcopy
hub / github.com/greensock/GSAP / stringToRawPath

Function stringToRawPath

esm/utils/paths.js:832–1034  ·  view source on GitHub ↗
(d)

Source from the content-addressed store, hash-verified

830
831
832export function stringToRawPath(d) {
833 var a = (d + "").replace(_scientific, function (m) {
834 var n = +m;
835 return n < 0.0001 && n > -0.0001 ? 0 : n;
836 }).match(_svgPathExp) || [],
837 //some authoring programs spit out very small numbers in scientific notation like "1e-5", so make sure we round that down to 0 first.
838 path = [],
839 relativeX = 0,
840 relativeY = 0,
841 twoThirds = 2 / 3,
842 elements = a.length,
843 points = 0,
844 errorMessage = "ERROR: malformed path: " + d,
845 i,
846 j,
847 x,
848 y,
849 command,
850 isRelative,
851 segment,
852 startX,
853 startY,
854 difX,
855 difY,
856 beziers,
857 prevCommand,
858 flag1,
859 flag2,
860 line = function line(sx, sy, ex, ey) {
861 difX = (ex - sx) / 3;
862 difY = (ey - sy) / 3;
863 segment.push(sx + difX, sy + difY, ex - difX, ey - difY, ex, ey);
864 };
865
866 if (!d || !isNaN(a[0]) || isNaN(a[1])) {
867 console.log(errorMessage);
868 return path;
869 }
870
871 for (i = 0; i < elements; i++) {
872 prevCommand = command;
873
874 if (isNaN(a[i])) {
875 command = a[i].toUpperCase();
876 isRelative = command !== a[i]; //lower case means relative
877 } else {
878 //commands like "C" can be strung together without any new command characters between.
879 i--;
880 }
881
882 x = +a[i + 1];
883 y = +a[i + 2];
884
885 if (isRelative) {
886 x += relativeX;
887 y += relativeY;
888 }
889

Callers 6

_pathFilterFunction · 0.90
MorphSVGPlugin.jsFile · 0.90
CustomEase.jsFile · 0.90
PathEditor.jsFile · 0.90
getRawPathFunction · 0.70
convertToPathFunction · 0.70

Calls 3

_segmentIsClosedFunction · 0.70
lineFunction · 0.70
arcToSegmentFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…