transform.js 1.1 KB

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