UNPKG

svg-path-d

Version:

SVG path data (path[d] attribute content) manipulation library.

71 lines 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.applyHorizontalFlip = exports.applyVerticalFlip = exports.applyTranslate = void 0; var command_assertion_1 = require("./command-assertion"); /** * Implements simple in-place transformations of a `DrawTo` content. */ /** * Translates all points in the item * @param item `DrawTo` command * @param dx x offset * @param dy y offset */ function applyTranslate(item, dx, dy) { if (!command_assertion_1.isClosePath(item)) { if (!command_assertion_1.isVLineTo(item)) { item.x += dx; } if (!command_assertion_1.isHLineTo(item)) { item.y += dy; } if (command_assertion_1.hasControlPoint1(item)) { item.x1 += dx; item.y1 += dy; } if (command_assertion_1.hasControlPoint2(item)) { item.x2 += dx; item.y2 += dy; } } } exports.applyTranslate = applyTranslate; function applyVerticalFlip(item) { if (!command_assertion_1.isClosePath(item)) { if (!command_assertion_1.isHLineTo(item)) { item.y = -item.y; } if (command_assertion_1.isEllipticalArc(item)) { item.sweepFlag = !item.sweepFlag; } else { if (command_assertion_1.hasControlPoint1(item)) { item.y1 = -item.y1; } if (command_assertion_1.hasControlPoint2(item)) { item.y2 = -item.y2; } } } } exports.applyVerticalFlip = applyVerticalFlip; function applyHorizontalFlip(item) { if (!command_assertion_1.isClosePath(item)) { if (!command_assertion_1.isVLineTo(item)) { item.x = -item.x; } if (command_assertion_1.isEllipticalArc(item)) { item.sweepFlag = !item.sweepFlag; } else { if (command_assertion_1.hasControlPoint1(item)) { item.x1 = -item.x1; } if (command_assertion_1.hasControlPoint2(item)) { item.x2 = -item.x2; } } } } exports.applyHorizontalFlip = applyHorizontalFlip; //# sourceMappingURL=in-place-transform.js.map