center-center 0.0.9 → 0.0.10
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/index.d.mts +19 -79
- package/index.mjs +8 -30
- package/package.json +1 -1
- package/index.d.mts.map +0 -1
- package/tsconfig.json +0 -10
package/index.d.mts
CHANGED
|
@@ -1,86 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
* A Center Center `Rect`
|
|
3
|
-
*
|
|
4
|
-
* @typedef {{
|
|
5
|
-
* width: number,
|
|
6
|
-
* height: number,
|
|
7
|
-
* left: number,
|
|
8
|
-
* top: number,
|
|
9
|
-
* right: number,
|
|
10
|
-
* bottom: number
|
|
11
|
-
* }} CenterCenterRect
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* Gets the scroll position of the document `scrollingElement`
|
|
15
|
-
*
|
|
16
|
-
* @returns {{
|
|
17
|
-
* scrollLeft: number,
|
|
18
|
-
* scrollTop: number
|
|
19
|
-
* }}
|
|
20
|
-
*/
|
|
21
|
-
export function getScrollingElement (): {
|
|
22
|
-
scrollLeft: number
|
|
23
|
-
scrollTop: number
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Gets a `Rect` for the viewport
|
|
27
|
-
*
|
|
28
|
-
* @returns {CenterCenterRect}
|
|
29
|
-
*/
|
|
1
|
+
export function getScrollingElement (): ScrollingElement
|
|
30
2
|
export function getViewportRect (): CenterCenterRect
|
|
31
|
-
/**
|
|
32
|
-
* Gets a `Rect` for a DOM element
|
|
33
|
-
*
|
|
34
|
-
* @param {Element} element
|
|
35
|
-
* @returns {CenterCenterRect}
|
|
36
|
-
*/
|
|
37
3
|
export function getElementRect (element: Element): CenterCenterRect
|
|
4
|
+
export function getRects (container: Element, target: Element): CenterCenterRects
|
|
5
|
+
export function calculateLeft ({ viewport: { left: viewportL, right: viewportR }, container: { width: containerW, left: containerL, right: containerR }, target: { width: targetW } }: CenterCenterRects): number
|
|
6
|
+
export function calculateTop ({ viewport: { top: viewportT, bottom: viewportB }, container: { height: containerH, top: containerT, bottom: containerB }, target: { height: targetH } }: CenterCenterRects): number
|
|
7
|
+
|
|
38
8
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* @param {Element} container
|
|
42
|
-
* @param {Element} target
|
|
43
|
-
* @returns {{
|
|
44
|
-
* viewport: CenterCenterRect,
|
|
45
|
-
* container: CenterCenterRect,
|
|
46
|
-
* target: CenterCenterRect
|
|
47
|
-
* }}
|
|
9
|
+
* The document `scrollingElement`
|
|
48
10
|
*/
|
|
49
|
-
export
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
target: CenterCenterRect
|
|
11
|
+
export interface ScrollingElement {
|
|
12
|
+
scrollLeft: number
|
|
13
|
+
scrollTop: number
|
|
53
14
|
}
|
|
54
|
-
|
|
55
|
-
* Calculates the target `left` position
|
|
56
|
-
*
|
|
57
|
-
* @param {{
|
|
58
|
-
* viewport: CenterCenterRect,
|
|
59
|
-
* container: CenterCenterRect,
|
|
60
|
-
* target: CenterCenterRect
|
|
61
|
-
* }}
|
|
62
|
-
* @returns {number}
|
|
63
|
-
*/
|
|
64
|
-
export function calculateLeft ({ viewport: { left: viewportL, right: viewportR }, container: { width: containerW, left: containerL, right: containerR }, target: { width: targetW } }: {
|
|
65
|
-
viewport: CenterCenterRect
|
|
66
|
-
container: CenterCenterRect
|
|
67
|
-
target: CenterCenterRect
|
|
68
|
-
}): number
|
|
69
|
-
/**
|
|
70
|
-
* Calculates the target `top` position
|
|
71
|
-
*
|
|
72
|
-
* @param {{
|
|
73
|
-
* viewport: CenterCenterRect,
|
|
74
|
-
* container: CenterCenterRect,
|
|
75
|
-
* target: CenterCenterRect
|
|
76
|
-
* }}
|
|
77
|
-
* @returns {number}
|
|
78
|
-
*/
|
|
79
|
-
export function calculateTop ({ viewport: { top: viewportT, bottom: viewportB }, container: { height: containerH, top: containerT, bottom: containerB }, target: { height: targetH } }: {
|
|
80
|
-
viewport: CenterCenterRect
|
|
81
|
-
container: CenterCenterRect
|
|
82
|
-
target: CenterCenterRect
|
|
83
|
-
}): number
|
|
15
|
+
|
|
84
16
|
/**
|
|
85
17
|
* A Center Center `Rect`
|
|
86
18
|
*/
|
|
@@ -92,4 +24,12 @@ export interface CenterCenterRect {
|
|
|
92
24
|
right: number
|
|
93
25
|
bottom: number
|
|
94
26
|
}
|
|
95
|
-
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Center Center `Rects`
|
|
30
|
+
*/
|
|
31
|
+
export interface CenterCenterRects {
|
|
32
|
+
viewport: CenterCenterRect
|
|
33
|
+
container: CenterCenterRect
|
|
34
|
+
target: CenterCenterRect
|
|
35
|
+
}
|
package/index.mjs
CHANGED
|
@@ -1,23 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* @typedef {
|
|
5
|
-
* width: number,
|
|
6
|
-
* height: number,
|
|
7
|
-
* left: number,
|
|
8
|
-
* top: number,
|
|
9
|
-
* right: number,
|
|
10
|
-
* bottom: number
|
|
11
|
-
* }} CenterCenterRect
|
|
2
|
+
* @typedef {import('.').ScrollingElement} ScrollingElement
|
|
3
|
+
* @typedef {import('.').CenterCenterRect} CenterCenterRect
|
|
4
|
+
* @typedef {import('.').CenterCenterRects} CenterCenterRects
|
|
12
5
|
*/
|
|
13
6
|
|
|
14
7
|
/**
|
|
15
|
-
* Gets the
|
|
8
|
+
* Gets the document `scrollingElement` (or a valid alternative)
|
|
16
9
|
*
|
|
17
|
-
* @returns {
|
|
18
|
-
* scrollLeft: number,
|
|
19
|
-
* scrollTop: number
|
|
20
|
-
* }}
|
|
10
|
+
* @returns {ScrollingElement}
|
|
21
11
|
*/
|
|
22
12
|
export function getScrollingElement () {
|
|
23
13
|
if (Reflect.has(document, 'scrollingElement')) {
|
|
@@ -86,11 +76,7 @@ export function getElementRect (element) {
|
|
|
86
76
|
*
|
|
87
77
|
* @param {Element} container
|
|
88
78
|
* @param {Element} target
|
|
89
|
-
* @returns {
|
|
90
|
-
* viewport: CenterCenterRect,
|
|
91
|
-
* container: CenterCenterRect,
|
|
92
|
-
* target: CenterCenterRect
|
|
93
|
-
* }}
|
|
79
|
+
* @returns {CenterCenterRects}
|
|
94
80
|
*/
|
|
95
81
|
export function getRects (container, target) {
|
|
96
82
|
return {
|
|
@@ -103,11 +89,7 @@ export function getRects (container, target) {
|
|
|
103
89
|
/**
|
|
104
90
|
* Calculates the target `left` position
|
|
105
91
|
*
|
|
106
|
-
* @param {
|
|
107
|
-
* viewport: CenterCenterRect,
|
|
108
|
-
* container: CenterCenterRect,
|
|
109
|
-
* target: CenterCenterRect
|
|
110
|
-
* }}
|
|
92
|
+
* @param {CenterCenterRects}
|
|
111
93
|
* @returns {number}
|
|
112
94
|
*/
|
|
113
95
|
export function calculateLeft ({
|
|
@@ -138,11 +120,7 @@ export function calculateLeft ({
|
|
|
138
120
|
/**
|
|
139
121
|
* Calculates the target `top` position
|
|
140
122
|
*
|
|
141
|
-
* @param {
|
|
142
|
-
* viewport: CenterCenterRect,
|
|
143
|
-
* container: CenterCenterRect,
|
|
144
|
-
* target: CenterCenterRect
|
|
145
|
-
* }}
|
|
123
|
+
* @param {CenterCenterRects}
|
|
146
124
|
* @returns {number}
|
|
147
125
|
*/
|
|
148
126
|
export function calculateTop ({
|
package/package.json
CHANGED
package/index.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["index.mjs"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;;;;GAOG;AACH,uCALa;IACZ,UAAa,EAAE,MAAM,CAAC;IACtB,SAAY,EAAE,MAAM,CAAA;CACjB,CAYH;AAED;;;;GAIG;AACH,mCAFa,gBAAgB,CAqB5B;AAED;;;;;EAKE;AACF,wCAHW,OAAO,GACL,gBAAgB,CAkB5B;AAED;;;;;;;;;;GAUG;AACH,oCARW,OAAO,UACP,OAAO,GACL;IACZ,QAAW,EAAE,gBAAgB,CAAC;IAC9B,SAAY,EAAE,gBAAgB,CAAC;IAC/B,MAAS,EAAE,gBAAgB,CAAA;CACxB,CAQH;AAED;;;;;;;;;GASG;AACH,sLAPW;IACV,QAAW,EAAE,gBAAgB,CAAC;IAC9B,SAAY,EAAE,gBAAgB,CAAC;IAC/B,MAAS,EAAE,gBAAgB,CAAA;CACxB,GACS,MAAM,CAyBlB;AAED;;;;;;;;;GASG;AACH,uLAPW;IACV,QAAW,EAAE,gBAAgB,CAAC;IAC9B,SAAY,EAAE,gBAAgB,CAAC;IAC/B,MAAS,EAAE,gBAAgB,CAAA;CACxB,GACS,MAAM,CAyBlB;;;;+BAvKY;IACZ,KAAU,EAAE,MAAM,CAAC;IACnB,MAAW,EAAE,MAAM,CAAC;IACpB,IAAS,EAAE,MAAM,CAAC;IAClB,KAAU,MAAM,CAAC;IACjB,KAAU,EAAE,MAAM,CAAC;IACnB,MAAW,EAAE,MAAM,CAAA;CACf"}
|