center-center 0.0.45 → 0.0.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/svg/index.mjs +8 -10
- package/src/svg/view-box/index.d.mts +0 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "center-center",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.47",
|
|
4
4
|
"description": "Position an element at the center center of a container",
|
|
5
5
|
"main": "./src/index.mjs",
|
|
6
6
|
"type": "module",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"@babel/preset-env": "^7.24.0",
|
|
37
37
|
"@sequencemedia/hooks": "^1.0.483",
|
|
38
38
|
"@types/debug": "^4.1.12",
|
|
39
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
40
|
-
"@typescript-eslint/parser": "^7.
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "^7.2.0",
|
|
40
|
+
"@typescript-eslint/parser": "^7.2.0",
|
|
41
41
|
"chai": "^5.1.0",
|
|
42
42
|
"core-js": "^3.36.0",
|
|
43
43
|
"cross-env": "^7.0.3",
|
package/src/svg/index.mjs
CHANGED
|
@@ -26,14 +26,13 @@ export {
|
|
|
26
26
|
* @returns {number}
|
|
27
27
|
*/
|
|
28
28
|
export function calculateX (rects, viewBoxW = 0, scale = 1) {
|
|
29
|
-
const targetX = calculateRectX(getTargetRect(rects))
|
|
30
|
-
const containerX = calculateContainerX(rects)
|
|
31
29
|
const w = getRectWidth(getContainerRect(rects))
|
|
32
30
|
const ratio = (viewBoxW / w)
|
|
31
|
+
const containerX = calculateContainerX(rects)
|
|
32
|
+
const targetX = calculateRectX(getTargetRect(rects))
|
|
33
|
+
const x = (targetX - ((containerX * ratio) / scale))
|
|
33
34
|
|
|
34
|
-
return (
|
|
35
|
-
targetX - ((containerX * ratio) / scale)
|
|
36
|
-
)
|
|
35
|
+
return (-x)
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
/**
|
|
@@ -45,12 +44,11 @@ export function calculateX (rects, viewBoxW = 0, scale = 1) {
|
|
|
45
44
|
* @returns {number}
|
|
46
45
|
*/
|
|
47
46
|
export function calculateY (rects, viewBoxH = 0, scale = 1) {
|
|
48
|
-
const targetY = calculateRectY(getTargetRect(rects))
|
|
49
|
-
const containerY = calculateContainerY(rects)
|
|
50
47
|
const h = getRectHeight(getContainerRect(rects))
|
|
51
48
|
const ratio = (viewBoxH / h)
|
|
49
|
+
const containerY = calculateContainerY(rects)
|
|
50
|
+
const targetY = calculateRectY(getTargetRect(rects))
|
|
51
|
+
const y = (targetY - ((containerY * ratio) / scale))
|
|
52
52
|
|
|
53
|
-
return (
|
|
54
|
-
targetY - ((containerY * ratio) / scale)
|
|
55
|
-
)
|
|
53
|
+
return (-y)
|
|
56
54
|
}
|
|
@@ -4,22 +4,14 @@ declare module 'center-center/svg/view-box' {
|
|
|
4
4
|
export const W: number
|
|
5
5
|
export const H: number
|
|
6
6
|
|
|
7
|
-
function toRound (s: string): number
|
|
8
|
-
|
|
9
7
|
export function getXFor (svg: Element): number
|
|
10
|
-
|
|
11
8
|
export function getYFor (svg: Element): number
|
|
12
|
-
|
|
13
9
|
export function getWFor (svg: Element): number
|
|
14
|
-
|
|
15
10
|
export function getHFor (svg: Element): number
|
|
16
11
|
|
|
17
12
|
export function getX (viewBox: number[]): number
|
|
18
|
-
|
|
19
13
|
export function getY (viewBox: number[]): number
|
|
20
|
-
|
|
21
14
|
export function getW (viewBox: number[]): number
|
|
22
|
-
|
|
23
15
|
export function getH (viewBox: number[]): number
|
|
24
16
|
|
|
25
17
|
export default function getViewBox (svg: Element): number[]
|