center-center 0.1.65 → 0.1.67

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "center-center",
3
- "version": "0.1.65",
3
+ "version": "0.1.67",
4
4
  "description": "Position an element at the center center of a container",
5
5
  "main": "./src/index.mjs",
6
6
  "type": "module",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "devDependencies": {
29
29
  "@sequencemedia/eslint-config-standard": "^0.2.43",
30
- "@sequencemedia/eslint-config-typescript": "^0.1.62",
30
+ "@sequencemedia/eslint-config-typescript": "^0.1.63",
31
31
  "@sequencemedia/process": "^0.0.15",
32
32
  "@types/chai": "^5.2.0",
33
33
  "@types/debug": "^4.1.12",
@@ -35,7 +35,7 @@
35
35
  "@types/mocha": "^10.0.10",
36
36
  "chai": "^5.2.0",
37
37
  "cross-env": "^7.0.3",
38
- "eslint": "^9.22.0",
38
+ "eslint": "^9.23.0",
39
39
  "express": "^4.21.2",
40
40
  "globals": "^16.0.0",
41
41
  "husky": "^9.1.7",
@@ -8,7 +8,7 @@ declare namespace CenterCenterTypes {
8
8
  }
9
9
 
10
10
  /**
11
- * A Center Center `Rect`
11
+ * A Center Center `Rect`
12
12
  */
13
13
  export interface CenterCenterRect {
14
14
  left: number
@@ -20,7 +20,7 @@ declare namespace CenterCenterTypes {
20
20
  }
21
21
 
22
22
  /**
23
- * Center Center `Rects`
23
+ * Center Center `Rects`
24
24
  */
25
25
  export interface CenterCenterRects {
26
26
  viewport: CenterCenterRect
@@ -1,13 +1,13 @@
1
1
  /**
2
- * @typedef {import('center-center/common').ScrollingElement} ScrollingElement
3
- * @typedef {import('center-center/common').CenterCenterRect} CenterCenterRect
4
- * @typedef {import('center-center/common').CenterCenterRects} CenterCenterRects
2
+ * @typedef {import('center-center/common').ScrollingElement} ScrollingElement
3
+ * @typedef {import('center-center/common').CenterCenterRect} CenterCenterRect
4
+ * @typedef {import('center-center/common').CenterCenterRects} CenterCenterRects
5
5
  */
6
6
 
7
7
  /**
8
- * Gets the document `scrollingElement` (or a valid alternative)
8
+ * Gets the document `scrollingElement` (or a valid alternative)
9
9
  *
10
- * @returns {ScrollingElement}
10
+ * @returns {ScrollingElement}
11
11
  */
12
12
  export function getScrollingElement () {
13
13
  if ('scrollingElement' in document) { // (Reflect.has(document, 'scrollingElement')) {
@@ -22,9 +22,9 @@ export function getScrollingElement () {
22
22
  }
23
23
 
24
24
  /**
25
- * Creates a `Rect` for the viewport
25
+ * Creates a `Rect` for the viewport
26
26
  *
27
- * @returns {CenterCenterRect}
27
+ * @returns {CenterCenterRect}
28
28
  */
29
29
  export function createViewportRect () {
30
30
  const {
@@ -48,10 +48,10 @@ export function createViewportRect () {
48
48
  }
49
49
 
50
50
  /**
51
- * Creates a `Rect` for a DOM element
51
+ * Creates a `Rect` for a DOM element
52
52
  *
53
- * @param {Element} element
54
- * @returns {CenterCenterRect}
53
+ * @param {Element} element
54
+ * @returns {CenterCenterRect}
55
55
  */
56
56
  export function createDOMElementRect (element) {
57
57
  const {
@@ -80,10 +80,10 @@ export function createDOMElementRect (element) {
80
80
  }
81
81
 
82
82
  /**
83
- * Creates a `Rect` for an SVG element
83
+ * Creates a `Rect` for an SVG element
84
84
  *
85
- * @param {SVGGraphicsElement} element
86
- * @returns {CenterCenterRect}
85
+ * @param {SVGGraphicsElement} element
86
+ * @returns {CenterCenterRect}
87
87
  */
88
88
  export function createSVGElementRect (element) {
89
89
  const {
@@ -104,14 +104,14 @@ export function createSVGElementRect (element) {
104
104
  }
105
105
 
106
106
  /**
107
- * Creates a collection of `Rects` describing
108
- * 1. The viewport
109
- * 2. The DOM container element
110
- * 3. The DOM target element
107
+ * Creates a collection of `Rects` describing
108
+ * 1. The viewport
109
+ * 2. The DOM container element
110
+ * 3. The DOM target element
111
111
  *
112
- * @param {Element} container
113
- * @param {Element} target
114
- * @returns {CenterCenterRects}
112
+ * @param {Element} container
113
+ * @param {Element} target
114
+ * @returns {CenterCenterRects}
115
115
  */
116
116
  export function createDOMRects (container, target) {
117
117
  return {
@@ -122,14 +122,14 @@ export function createDOMRects (container, target) {
122
122
  }
123
123
 
124
124
  /**
125
- * Creates a collection of `Rects` describing
126
- * 1. The viewport
127
- * 2. The DOM container element
128
- * 3. The SVG target element
125
+ * Creates a collection of `Rects` describing
126
+ * 1. The viewport
127
+ * 2. The DOM container element
128
+ * 3. The SVG target element
129
129
  *
130
- * @param {Element} container
131
- * @param {SVGGraphicsElement} target
132
- * @returns {CenterCenterRects}
130
+ * @param {Element} container
131
+ * @param {SVGGraphicsElement} target
132
+ * @returns {CenterCenterRects}
133
133
  */
134
134
  export function createSVGRects (container, target) {
135
135
  return {
@@ -140,102 +140,102 @@ export function createSVGRects (container, target) {
140
140
  }
141
141
 
142
142
  /**
143
- * Destructures the `left` field from a `Rect`
143
+ * Destructures the `left` field from a `Rect`
144
144
  *
145
- * @param {CenterCenterRect} rect
146
- * @returns {number}
145
+ * @param {CenterCenterRect} rect
146
+ * @returns {number}
147
147
  */
148
148
  export function getRectLeft ({ left }) {
149
149
  return left
150
150
  }
151
151
 
152
152
  /**
153
- * Destructures the `top` field from a `Rect`
153
+ * Destructures the `top` field from a `Rect`
154
154
  *
155
- * @param {CenterCenterRect} rect
156
- * @returns {number}
155
+ * @param {CenterCenterRect} rect
156
+ * @returns {number}
157
157
  */
158
158
  export function getRectTop ({ top }) {
159
159
  return top
160
160
  }
161
161
 
162
162
  /**
163
- * Destructures the `width` field from a `Rect`
163
+ * Destructures the `width` field from a `Rect`
164
164
  *
165
- * @param {CenterCenterRect} rect
166
- * @returns {number}
165
+ * @param {CenterCenterRect} rect
166
+ * @returns {number}
167
167
  */
168
168
  export function getRectWidth ({ width }) {
169
169
  return width
170
170
  }
171
171
 
172
172
  /**
173
- * Destructures the `height` field from a `Rect`
173
+ * Destructures the `height` field from a `Rect`
174
174
  *
175
- * @param {CenterCenterRect} rect
176
- * @returns {number}
175
+ * @param {CenterCenterRect} rect
176
+ * @returns {number}
177
177
  */
178
178
  export function getRectHeight ({ height }) {
179
179
  return height
180
180
  }
181
181
 
182
182
  /**
183
- * Destructures the viewport `Rect` from a collection of `Rects`
183
+ * Destructures the viewport `Rect` from a collection of `Rects`
184
184
  *
185
- * @param {CenterCenterRects} rects
186
- * @returns {CenterCenterRect}
185
+ * @param {CenterCenterRects} rects
186
+ * @returns {CenterCenterRect}
187
187
  */
188
188
  export function getViewportRect ({ viewport }) {
189
189
  return viewport
190
190
  }
191
191
 
192
192
  /**
193
- * Destructures the container `Rect` from a collection of `Rects`
193
+ * Destructures the container `Rect` from a collection of `Rects`
194
194
  *
195
- * @param {CenterCenterRects} rects
196
- * @returns {CenterCenterRect}
195
+ * @param {CenterCenterRects} rects
196
+ * @returns {CenterCenterRect}
197
197
  */
198
198
  export function getContainerRect ({ container }) {
199
199
  return container
200
200
  }
201
201
 
202
202
  /**
203
- * Destructures the target `Rect` from a collection of `Rects`
203
+ * Destructures the target `Rect` from a collection of `Rects`
204
204
  *
205
- * @param {CenterCenterRects} rects
206
- * @returns {CenterCenterRect}
205
+ * @param {CenterCenterRects} rects
206
+ * @returns {CenterCenterRect}
207
207
  */
208
208
  export function getTargetRect ({ target }) {
209
209
  return target
210
210
  }
211
211
 
212
212
  /**
213
- * Calculates the `x` coordinate of a `Rect`
213
+ * Calculates the `x` coordinate of a `Rect`
214
214
  *
215
- * @param {CenterCenterRect} rect
216
- * @returns {number}
215
+ * @param {CenterCenterRect} rect
216
+ * @returns {number}
217
217
  */
218
218
  export function calculateRectX ({ left: l, width: w }) {
219
219
  return (l + (w / 2))
220
220
  }
221
221
 
222
222
  /**
223
- * Calculates the `y` coordinate of a `Rect`
223
+ * Calculates the `y` coordinate of a `Rect`
224
224
  *
225
- * @param {CenterCenterRect} rect
226
- * @returns {number}
225
+ * @param {CenterCenterRect} rect
226
+ * @returns {number}
227
227
  */
228
228
  export function calculateRectY ({ top: t, height: h }) {
229
229
  return (t + (h / 2))
230
230
  }
231
231
 
232
232
  /**
233
- * Calculates the right-most boundary `x` coordinate of the target in the container
233
+ * Calculates the right-most boundary `x` coordinate of the target in the container
234
234
  *
235
- * The range is inclusive from left-most 0 to right-most boundary `x`
235
+ * The range is inclusive from left-most 0 to right-most boundary `x`
236
236
  *
237
- * @param {CenterCenterRects} rects
238
- * @returns {number}
237
+ * @param {CenterCenterRects} rects
238
+ * @returns {number}
239
239
  */
240
240
  export function calculateBoundaryX (rects) {
241
241
  const containerW = getRectWidth(getContainerRect(rects))
@@ -245,12 +245,12 @@ export function calculateBoundaryX (rects) {
245
245
  }
246
246
 
247
247
  /**
248
- * Calculates the bottom-most boundary `y` coordinate of the target in the container
248
+ * Calculates the bottom-most boundary `y` coordinate of the target in the container
249
249
  *
250
- * The range is inclusive from top-most 0 to bottom-most boundary `y`
250
+ * The range is inclusive from top-most 0 to bottom-most boundary `y`
251
251
  *
252
- * @param {CenterCenterRects} rects
253
- * @returns {number}
252
+ * @param {CenterCenterRects} rects
253
+ * @returns {number}
254
254
  */
255
255
  export function calculateBoundaryY (rects) {
256
256
  const containerH = getRectHeight(getContainerRect(rects))
@@ -260,10 +260,10 @@ export function calculateBoundaryY (rects) {
260
260
  }
261
261
 
262
262
  /**
263
- * Calculates the `x` coordinate of the container
263
+ * Calculates the `x` coordinate of the container
264
264
  *
265
- * @param {CenterCenterRects} rects
266
- * @returns {number}
265
+ * @param {CenterCenterRects} rects
266
+ * @returns {number}
267
267
  */
268
268
  export function calculateContainerX ({
269
269
  viewport: {
@@ -284,10 +284,10 @@ export function calculateContainerX ({
284
284
  }
285
285
 
286
286
  /**
287
- * Calculates the `y` coordinate of the container
287
+ * Calculates the `y` coordinate of the container
288
288
  *
289
- * @param {CenterCenterRects} rects
290
- * @returns {number}
289
+ * @param {CenterCenterRects} rects
290
+ * @returns {number}
291
291
  */
292
292
  export function calculateContainerY ({
293
293
  viewport: {
@@ -308,10 +308,10 @@ export function calculateContainerY ({
308
308
  }
309
309
 
310
310
  /**
311
- * Calculates the `x` coordinate of the target
311
+ * Calculates the `x` coordinate of the target
312
312
  *
313
- * @param {CenterCenterRects} rects
314
- * @returns {number}
313
+ * @param {CenterCenterRects} rects
314
+ * @returns {number}
315
315
  */
316
316
  export function calculateTargetX (rects) {
317
317
  const x = calculateContainerX(rects)
@@ -321,10 +321,10 @@ export function calculateTargetX (rects) {
321
321
  }
322
322
 
323
323
  /**
324
- * Calculates the `y` coordinate of the target
324
+ * Calculates the `y` coordinate of the target
325
325
  *
326
- * @param {CenterCenterRects} rects
327
- * @returns {number}
326
+ * @param {CenterCenterRects} rects
327
+ * @returns {number}
328
328
  */
329
329
  export function calculateTargetY (rects) {
330
330
  const y = calculateContainerY(rects)
package/src/dom/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @typedef {import('center-center/common').CenterCenterRects} CenterCenterRects
2
+ * @typedef {import('center-center/common').CenterCenterRects} CenterCenterRects
3
3
  */
4
4
 
5
5
  import {
@@ -14,10 +14,10 @@ export {
14
14
  } from '#center-center/common'
15
15
 
16
16
  /**
17
- * Calculates the target `left` position
17
+ * Calculates the target `left` position
18
18
  *
19
- * @param {CenterCenterRects} rects
20
- * @returns {number}
19
+ * @param {CenterCenterRects} rects
20
+ * @returns {number}
21
21
  */
22
22
  export function calculateLeft (rects) {
23
23
  const boundary = calculateBoundaryX(rects)
@@ -29,10 +29,10 @@ export function calculateLeft (rects) {
29
29
  }
30
30
 
31
31
  /**
32
- * Calculates the target `top` position
32
+ * Calculates the target `top` position
33
33
  *
34
- * @param {CenterCenterRects} rects
35
- * @returns {number}
34
+ * @param {CenterCenterRects} rects
35
+ * @returns {number}
36
36
  */
37
37
  export function calculateTop (rects) {
38
38
  const boundary = calculateBoundaryY(rects)
package/src/svg/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @typedef {import('center-center/common').CenterCenterRects} CenterCenterRects
2
+ * @typedef {import('center-center/common').CenterCenterRects} CenterCenterRects
3
3
  */
4
4
 
5
5
  import {
@@ -18,12 +18,12 @@ export {
18
18
  } from '#center-center/common'
19
19
 
20
20
  /**
21
- * Calculates the target `x` position
21
+ * Calculates the target `x` position
22
22
  *
23
- * @param {CenterCenterRects} rects
24
- * @param {number | undefined} viewBoxW
25
- * @param {number | undefined} scale
26
- * @returns {number}
23
+ * @param {CenterCenterRects} rects
24
+ * @param {number | undefined} viewBoxW
25
+ * @param {number | undefined} scale
26
+ * @returns {number}
27
27
  */
28
28
  export function calculateX (rects, viewBoxW = 0, scale = 1) {
29
29
  const w = getRectWidth(getContainerRect(rects))
@@ -36,12 +36,12 @@ export function calculateX (rects, viewBoxW = 0, scale = 1) {
36
36
  }
37
37
 
38
38
  /**
39
- * Calculates the target `y` position
39
+ * Calculates the target `y` position
40
40
  *
41
- * @param {CenterCenterRects} rects
42
- * @param {number | undefined} viewBoxH
43
- * @param {number | undefined} scale
44
- * @returns {number}
41
+ * @param {CenterCenterRects} rects
42
+ * @param {number | undefined} viewBoxH
43
+ * @param {number | undefined} scale
44
+ * @returns {number}
45
45
  */
46
46
  export function calculateY (rects, viewBoxH = 0, scale = 1) {
47
47
  const h = getRectHeight(getContainerRect(rects))
@@ -14,10 +14,10 @@ export const W = 2
14
14
  export const H = 3
15
15
 
16
16
  /**
17
- * Transforms a string to a round number
17
+ * Transforms a string to a round number
18
18
  *
19
- * @param {string} s
20
- * @returns {number}
19
+ * @param {string} s
20
+ * @returns {number}
21
21
  */
22
22
  function toRound (s) {
23
23
  return (
@@ -26,10 +26,10 @@ function toRound (s) {
26
26
  }
27
27
 
28
28
  /**
29
- * Get the number at position `H` for the SVG element `viewBox` attribute
29
+ * Get the number at position `H` for the SVG element `viewBox` attribute
30
30
  *
31
- * @param {Element} svg
32
- * @returns {number}
31
+ * @param {Element} svg
32
+ * @returns {number}
33
33
  */
34
34
  export function getXFor (svg) {
35
35
  return (
@@ -38,10 +38,10 @@ export function getXFor (svg) {
38
38
  }
39
39
 
40
40
  /**
41
- * Get the number at position `H` for the SVG element `viewBox` attribute
41
+ * Get the number at position `H` for the SVG element `viewBox` attribute
42
42
  *
43
- * @param {Element} svg
44
- * @returns {number}
43
+ * @param {Element} svg
44
+ * @returns {number}
45
45
  */
46
46
  export function getYFor (svg) {
47
47
  return (
@@ -50,10 +50,10 @@ export function getYFor (svg) {
50
50
  }
51
51
 
52
52
  /**
53
- * Get the number at position `H` for the SVG element `viewBox` attribute
53
+ * Get the number at position `H` for the SVG element `viewBox` attribute
54
54
  *
55
- * @param {Element} svg
56
- * @returns {number}
55
+ * @param {Element} svg
56
+ * @returns {number}
57
57
  */
58
58
  export function getWFor (svg) {
59
59
  return (
@@ -62,10 +62,10 @@ export function getWFor (svg) {
62
62
  }
63
63
 
64
64
  /**
65
- * Get the number at position `H` for the SVG element `viewBox` attribute
65
+ * Get the number at position `H` for the SVG element `viewBox` attribute
66
66
  *
67
- * @param {Element} svg
68
- * @returns {number}
67
+ * @param {Element} svg
68
+ * @returns {number}
69
69
  */
70
70
  export function getHFor (svg) {
71
71
  return (
@@ -74,50 +74,50 @@ export function getHFor (svg) {
74
74
  }
75
75
 
76
76
  /**
77
- * Get the number at position `X`
77
+ * Get the number at position `X`
78
78
  *
79
- * @param {number[]}
80
- * @returns {number}
79
+ * @param {number[]}
80
+ * @returns {number}
81
81
  */
82
82
  export function getX ({ [X]: x = 0 }) {
83
83
  return x
84
84
  }
85
85
 
86
86
  /**
87
- * Get the number at position `Y`
87
+ * Get the number at position `Y`
88
88
  *
89
- * @param {number[]}
90
- * @returns {number}
89
+ * @param {number[]}
90
+ * @returns {number}
91
91
  */
92
92
  export function getY ({ [Y]: y = 0 }) {
93
93
  return y
94
94
  }
95
95
 
96
96
  /**
97
- * Get the number at position `W`
97
+ * Get the number at position `W`
98
98
  *
99
- * @param {number[]}
100
- * @returns {number}
99
+ * @param {number[]}
100
+ * @returns {number}
101
101
  */
102
102
  export function getW ({ [W]: w = 0 }) {
103
103
  return w
104
104
  }
105
105
 
106
106
  /**
107
- * Get the number at position `H`
107
+ * Get the number at position `H`
108
108
  *
109
- * @param {number[]}
110
- * @returns {number}
109
+ * @param {number[]}
110
+ * @returns {number}
111
111
  */
112
112
  export function getH ({ [H]: h = 0 }) {
113
113
  return h
114
114
  }
115
115
 
116
116
  /**
117
- * Get an SVG element `viewBox` attribute as an array of numbers
117
+ * Get an SVG element `viewBox` attribute as an array of numbers
118
118
  *
119
- * @param {Element} svg
120
- * @returns {number[]}
119
+ * @param {Element} svg
120
+ * @returns {number[]}
121
121
  */
122
122
  export default function getViewBox (svg) {
123
123
  log('getViewBox')