center-center 0.0.16 → 0.0.18
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/docs/images/favicon.ico +0 -0
- package/docs/index.html +5 -6
- package/docs/index.mjs +95 -0
- package/index.mjs +45 -0
- package/package.json +7 -4
|
Binary file
|
package/docs/index.html
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
{
|
|
7
7
|
"imports": {
|
|
8
8
|
"debug": "https://esm.sh/debug",
|
|
9
|
-
"center-center": "
|
|
9
|
+
"center-center": "/assets/index.mjs"
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
</script>
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
import debug from 'debug'
|
|
15
15
|
|
|
16
16
|
import {
|
|
17
|
-
getElementRect,
|
|
18
17
|
getRects,
|
|
19
18
|
calculateLeft,
|
|
20
19
|
calculateTop
|
|
@@ -80,10 +79,10 @@
|
|
|
80
79
|
log('%d, %d', left, top)
|
|
81
80
|
|
|
82
81
|
const {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
target: {
|
|
83
|
+
left: currentLeft,
|
|
84
|
+
top: currentTop
|
|
85
|
+
}
|
|
87
86
|
} = rects
|
|
88
87
|
|
|
89
88
|
if (currentLeft !== left) target.style.left = left + 'px'
|
package/docs/index.mjs
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import debug from 'debug'
|
|
2
|
+
import express from 'express'
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
env: {
|
|
6
|
+
PORT = 3001
|
|
7
|
+
}
|
|
8
|
+
} = process
|
|
9
|
+
|
|
10
|
+
const log = debug('center-center/docs')
|
|
11
|
+
const info = debug('center-center/docs:info')
|
|
12
|
+
const app = express()
|
|
13
|
+
|
|
14
|
+
process
|
|
15
|
+
.on('SIGHUP', async (signal) => {
|
|
16
|
+
const {
|
|
17
|
+
stdout
|
|
18
|
+
} = process
|
|
19
|
+
|
|
20
|
+
if ('clearLine' in stdout) {
|
|
21
|
+
stdout.clearLine()
|
|
22
|
+
stdout.cursorTo(0)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
log(signal)
|
|
26
|
+
|
|
27
|
+
process.exit(0)
|
|
28
|
+
})
|
|
29
|
+
.on('SIGINT', async (signal) => {
|
|
30
|
+
const {
|
|
31
|
+
stdout
|
|
32
|
+
} = process
|
|
33
|
+
|
|
34
|
+
if ('clearLine' in stdout) {
|
|
35
|
+
stdout.clearLine()
|
|
36
|
+
stdout.cursorTo(0)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
log(signal)
|
|
40
|
+
|
|
41
|
+
process.exit(0)
|
|
42
|
+
})
|
|
43
|
+
.on('SIGBREAK', async (signal) => {
|
|
44
|
+
log(signal)
|
|
45
|
+
|
|
46
|
+
process.exit(0)
|
|
47
|
+
})
|
|
48
|
+
.on('SIGQUIT', async (signal) => {
|
|
49
|
+
log(signal)
|
|
50
|
+
|
|
51
|
+
process.exit(0)
|
|
52
|
+
})
|
|
53
|
+
.on('SIGTERM', async (signal) => {
|
|
54
|
+
log(signal)
|
|
55
|
+
|
|
56
|
+
process.exit(0)
|
|
57
|
+
})
|
|
58
|
+
.on('SIGPIPE', async (signal) => {
|
|
59
|
+
log(signal)
|
|
60
|
+
})
|
|
61
|
+
.on('beforeExit', async (code) => {
|
|
62
|
+
log('beforeExit', code)
|
|
63
|
+
})
|
|
64
|
+
.on('exit', async (code) => {
|
|
65
|
+
log('exit', code)
|
|
66
|
+
})
|
|
67
|
+
.on('uncaughtException', async ({ message }) => {
|
|
68
|
+
log('uncaughtException', message)
|
|
69
|
+
|
|
70
|
+
process.exit(1)
|
|
71
|
+
})
|
|
72
|
+
.on('unhandledRejection', async (reason, promise) => {
|
|
73
|
+
log('unhandledRejection', reason, promise)
|
|
74
|
+
|
|
75
|
+
process.exit(1)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
app
|
|
79
|
+
.get('/favicon.ico', (req, res) => {
|
|
80
|
+
res.sendFile('docs/images/favicon.ico', { root: '.' })
|
|
81
|
+
})
|
|
82
|
+
.get('/assets/index.mjs', (req, res) => {
|
|
83
|
+
res.sendFile('index.mjs', { root: '.' })
|
|
84
|
+
})
|
|
85
|
+
.get('/', (req, res) => {
|
|
86
|
+
res.sendFile('docs/index.html', { root: '.' })
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
app.listen(PORT, () => {
|
|
91
|
+
info(PORT)
|
|
92
|
+
})
|
|
93
|
+
} catch ({ message }) {
|
|
94
|
+
info(message)
|
|
95
|
+
}
|
package/index.mjs
CHANGED
|
@@ -4,6 +4,51 @@
|
|
|
4
4
|
* @typedef {import('.').CenterCenterRects} CenterCenterRects
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
const elementMap = new WeakMap()
|
|
8
|
+
|
|
9
|
+
export function getOffsetParentElement (element) {
|
|
10
|
+
let parentElement = element.parentElement
|
|
11
|
+
while (!Reflect.has(parentElement, 'offsetLeft') && !Reflect.has(parentElement, 'offsetTop')) {
|
|
12
|
+
parentElement = element.parentElement
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return parentElement
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function getOffsetLeft (element) {
|
|
19
|
+
if (Reflect.has(element, 'offsetLeft')) {
|
|
20
|
+
return Reflect.get(element, 'offsetLeft')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
left
|
|
25
|
+
} = element.getBoundingClientRect()
|
|
26
|
+
|
|
27
|
+
if (!elementMap.has(element)) elementMap.set(element, getOffsetParentElement(element))
|
|
28
|
+
const {
|
|
29
|
+
offsetLeft = 0
|
|
30
|
+
} = elementMap.get(element)
|
|
31
|
+
|
|
32
|
+
return offsetLeft + (offsetLeft - left)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function getOffsetTop (element) {
|
|
36
|
+
if (Reflect.has(element, 'offsetTop')) {
|
|
37
|
+
return Reflect.get(element, 'offsetTop')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const {
|
|
41
|
+
top
|
|
42
|
+
} = element.getBoundingClientRect()
|
|
43
|
+
|
|
44
|
+
if (!elementMap.has(element)) elementMap.set(element, getOffsetParentElement(element))
|
|
45
|
+
const {
|
|
46
|
+
offsetTop = 0
|
|
47
|
+
} = elementMap.get(element)
|
|
48
|
+
|
|
49
|
+
return offsetTop + (offsetTop - top)
|
|
50
|
+
}
|
|
51
|
+
|
|
7
52
|
/**
|
|
8
53
|
* Gets the document `scrollingElement` (or a valid alternative)
|
|
9
54
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "center-center",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "Position an element at the center center of a container",
|
|
5
5
|
"main": "./index.mjs",
|
|
6
6
|
"type": "module",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"lint:mts:fix": "npm run lint:mts -- --fix",
|
|
25
25
|
"test": "cross-env NODE_ENV=test mocha test --recursive",
|
|
26
26
|
"prepare": "husky install",
|
|
27
|
-
"types": "tsc"
|
|
27
|
+
"types": "tsc",
|
|
28
|
+
"start": "DEBUG=center-center* nodemon docs/index.mjs --watch ."
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
30
31
|
"debug": "^4.3.4"
|
|
@@ -34,7 +35,7 @@
|
|
|
34
35
|
"@babel/core": "^7.23.9",
|
|
35
36
|
"@babel/eslint-parser": "^7.23.10",
|
|
36
37
|
"@babel/preset-env": "^7.23.9",
|
|
37
|
-
"@sequencemedia/hooks": "^1.0.
|
|
38
|
+
"@sequencemedia/hooks": "^1.0.477",
|
|
38
39
|
"@typescript-eslint/eslint-plugin": "^6.20.0",
|
|
39
40
|
"@typescript-eslint/parser": "^6.20.0",
|
|
40
41
|
"chai": "^5.0.3",
|
|
@@ -43,8 +44,10 @@
|
|
|
43
44
|
"eslint": "^8.56.0",
|
|
44
45
|
"eslint-config-standard": "^17.1.0",
|
|
45
46
|
"eslint-config-standard-with-typescript": "^43.0.1",
|
|
46
|
-
"
|
|
47
|
+
"express": "^4.18.2",
|
|
48
|
+
"husky": "^9.0.10",
|
|
47
49
|
"mocha": "^10.2.0",
|
|
50
|
+
"nodemon": "^3.0.3",
|
|
48
51
|
"npm-run-all": "^4.1.5",
|
|
49
52
|
"typescript": "^5.3.3"
|
|
50
53
|
},
|