1 |
/**
|
|
2 |
* 获取 node 上的 align 对齐点 相对于页面的坐标 |
|
3 |
*/ |
|
4 |
|
|
5 |
function getAlignOffset(region, align) { |
|
6 |
const V = align.charAt(0);
|
18✔ |
7 |
const H = align.charAt(1);
|
18✔ |
8 |
const w = region.width; |
18✔ |
9 |
const h = region.height; |
18✔ |
10 |
|
|
11 |
let x = region.left; |
18✔ |
12 |
let y = region.top; |
18✔ |
13 |
|
|
14 |
if (V === 'c') { |
18✔ |
15 |
y += h / 2;
|
6✔ |
16 |
} else if (V === 'b') { |
12✔ |
17 |
y += h; |
× |
18 |
} |
|
19 |
|
|
20 |
if (H === 'c') { |
18✔ |
21 |
x += w / 2;
|
6✔ |
22 |
} else if (H === 'r') { |
12✔ |
23 |
x += w; |
2✔ |
24 |
} |
|
25 |
|
|
26 |
return {
|
18✔ |
27 |
left: x,
|
|
28 |
top: y,
|
|
29 |
}; |
|
30 |
} |
|
31 |
|
|
32 |
export default getAlignOffset; |