transform.js 953 B

123456789101112131415161718192021222324252627
  1. import { __read } from "tslib";
  2. export function getTranslate(node, x, y) {
  3. var _a = node.getBBox(), width = _a.width, height = _a.height;
  4. var _b = __read([x, y].map(function (v, i) {
  5. var _a;
  6. return v.includes('%')
  7. ? (parseFloat(((_a = v.match(/[+-]?([0-9]*[.])?[0-9]+/)) === null || _a === void 0 ? void 0 : _a[0]) || '0') / 100) * (i === 0 ? width : height)
  8. : v;
  9. }), 2), tx = _b[0], ty = _b[1];
  10. return [tx, ty];
  11. }
  12. /**
  13. * transform that support translate percent value
  14. */
  15. export function percentTransform(node, val) {
  16. if (!val)
  17. return;
  18. try {
  19. var reg = /translate\(([+-]*[\d]+[%]*),[ ]*([+-]*[\d]+[%]*)\)/g;
  20. var computedVal = val.replace(reg, function (match, x, y) { return "translate(".concat(getTranslate(node, x, y), ")"); });
  21. node.attr('transform', computedVal);
  22. }
  23. catch (e) {
  24. // do nothing
  25. }
  26. }
  27. //# sourceMappingURL=transform.js.map