You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
2.0 KiB
51 lines
2.0 KiB
import { isNumber } from '@antv/util';
|
|
/**
|
|
* <zh/> 从 transform 字符串中替换 translate 部分
|
|
*
|
|
* <en/> replace the translate part from the transform string
|
|
* @param x - <zh/> x | <en/> x
|
|
* @param y - <zh/> y | <en/> y
|
|
* @param z - <zh/> z | <en/> z
|
|
* @param transform - <zh/> transform 字符串 | <en/> transform string
|
|
* @returns <zh/> 替换后的 transform 字符串,返回 null 表示无需替换 | <en/> the replaced transform string, return null means no need to replace
|
|
*/
|
|
export function replaceTranslateInTransform(x, y, z, transform = []) {
|
|
if (!transform && x === 0 && y === 0 && z === 0)
|
|
return null;
|
|
if (Array.isArray(transform)) {
|
|
let translateIndex = -1;
|
|
const newTransform = [];
|
|
for (let i = 0; i < transform.length; i++) {
|
|
const t = transform[i];
|
|
if (t[0] === 'translate') {
|
|
if (t[1] === x && t[2] === y)
|
|
return null;
|
|
translateIndex = i;
|
|
newTransform.push(['translate', x, y]);
|
|
}
|
|
else if (t[0] === 'translate3d') {
|
|
if (t[1] === x && t[2] === y && t[3] === z)
|
|
return null;
|
|
translateIndex = i;
|
|
newTransform.push(['translate3d', x, y, z !== null && z !== void 0 ? z : 0]);
|
|
}
|
|
else {
|
|
newTransform.push(t);
|
|
}
|
|
}
|
|
if (translateIndex === -1) {
|
|
newTransform.splice(0, 0, isNumber(z) ? ['translate3d', x, y, z !== null && z !== void 0 ? z : 0] : ['translate', x, y]);
|
|
}
|
|
if (newTransform.length === 0)
|
|
return null;
|
|
return newTransform;
|
|
}
|
|
const removedTranslate = transform ? transform.replace(/translate(3d)?\([^)]*\)/g, '') : '';
|
|
if (z === 0) {
|
|
return `translate(${x}, ${y})${removedTranslate}`;
|
|
}
|
|
else {
|
|
return `translate3d(${x}, ${y}, ${z})${removedTranslate}`;
|
|
}
|
|
}
|
|
//# sourceMappingURL=transform.js.map
|