| 1234567891011121314151617181920212223242526272829303132 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.percentTransform = exports.getTranslate = void 0;
- var tslib_1 = require("tslib");
- function getTranslate(node, x, y) {
- var _a = node.getBBox(), width = _a.width, height = _a.height;
- var _b = tslib_1.__read([x, y].map(function (v, i) {
- var _a;
- return v.includes('%')
- ? (parseFloat(((_a = v.match(/[+-]?([0-9]*[.])?[0-9]+/)) === null || _a === void 0 ? void 0 : _a[0]) || '0') / 100) * (i === 0 ? width : height)
- : v;
- }), 2), tx = _b[0], ty = _b[1];
- return [tx, ty];
- }
- exports.getTranslate = getTranslate;
- /**
- * transform that support translate percent value
- */
- function percentTransform(node, val) {
- if (!val)
- return;
- try {
- var reg = /translate\(([+-]*[\d]+[%]*),[ ]*([+-]*[\d]+[%]*)\)/g;
- var computedVal = val.replace(reg, function (match, x, y) { return "translate(".concat(getTranslate(node, x, y), ")"); });
- node.attr('transform', computedVal);
- }
- catch (e) {
- // do nothing
- }
- }
- exports.percentTransform = percentTransform;
- //# sourceMappingURL=transform.js.map
|