center-center 0.0.36 → 0.0.38

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.
Files changed (2) hide show
  1. package/index.mjs +69 -5
  2. package/package.json +3 -3
package/index.mjs CHANGED
@@ -138,13 +138,37 @@ export function getViewportRect () {
138
138
  }
139
139
  }
140
140
 
141
+ /**
142
+ * Gets a `Rect` for an SVG element
143
+ *
144
+ * @param {Element} element
145
+ * @returns {CenterCenterRect}
146
+ */
147
+ export function getSVGElementRect (element) {
148
+ const {
149
+ x: left,
150
+ y: top,
151
+ width,
152
+ height
153
+ } = element.getBBox()
154
+
155
+ return {
156
+ left,
157
+ top,
158
+ width,
159
+ height,
160
+ right: (left + width),
161
+ bottom: (top + height)
162
+ }
163
+ }
164
+
141
165
  /**
142
166
  * Gets a `Rect` for a DOM element
143
167
  *
144
168
  * @param {Element} element
145
169
  * @returns {CenterCenterRect}
146
170
  */
147
- export function getElementRect (element) {
171
+ export function getDOMElementRect (element) {
148
172
  const {
149
173
  scrollLeft: l,
150
174
  scrollTop: t
@@ -171,20 +195,60 @@ export function getElementRect (element) {
171
195
  }
172
196
 
173
197
  /**
174
- * Gets `Rects` for the viewport as well as the container and target elements
198
+ * Gets a `Rect` for a DOM element
199
+ *
200
+ * @param {Element} element
201
+ * @returns {CenterCenterRect}
202
+ */
203
+ export function getElementRect (element) {
204
+ return (
205
+ getDOMElementRect(element)
206
+ )
207
+ }
208
+
209
+ /**
210
+ * Gets `Rects` for the viewport as well as the DOM container and DOM target elements
175
211
  *
176
212
  * @param {Element} container
177
213
  * @param {Element} target
178
214
  * @returns {CenterCenterRects}
179
215
  */
180
- export function getRects (container, target) {
216
+ export function getSVGRects (container, target) {
217
+ return {
218
+ viewport: getViewportRect(),
219
+ container: getDOMElementRect(container),
220
+ target: getSVGElementRect(target)
221
+ }
222
+ }
223
+
224
+ /**
225
+ * Gets `Rects` for the viewport as well as the DOM container and DOM target elements
226
+ *
227
+ * @param {Element} container
228
+ * @param {Element} target
229
+ * @returns {CenterCenterRects}
230
+ */
231
+ export function getDOMRects (container, target) {
181
232
  return {
182
233
  viewport: getViewportRect(),
183
- container: getElementRect(container),
184
- target: getElementRect(target)
234
+ container: getDOMElementRect(container),
235
+ target: getDOMElementRect(target)
185
236
  }
186
237
  }
187
238
 
239
+ /**
240
+ * Gets `Rects` for the viewport as well as the container and target elements
241
+ *
242
+ * @param {Element} container
243
+ * @param {Element} target
244
+ * @returns {CenterCenterRects}
245
+ */
246
+ export function getRects (container, target) {
247
+ return (
248
+ getDOMRects(container, target)
249
+ )
250
+ }
251
+
188
252
  /**
189
253
  * Calculates the target `left` position
190
254
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "center-center",
3
- "version": "0.0.36",
3
+ "version": "0.0.38",
4
4
  "description": "Position an element at the center center of a container",
5
5
  "main": "./index.mjs",
6
6
  "type": "module",
@@ -36,8 +36,8 @@
36
36
  "@babel/eslint-parser": "^7.23.10",
37
37
  "@babel/preset-env": "^7.24.0",
38
38
  "@sequencemedia/hooks": "^1.0.483",
39
- "@typescript-eslint/eslint-plugin": "^7.1.0",
40
- "@typescript-eslint/parser": "^7.1.0",
39
+ "@typescript-eslint/eslint-plugin": "^7.1.1",
40
+ "@typescript-eslint/parser": "^7.1.1",
41
41
  "chai": "^5.1.0",
42
42
  "core-js": "^3.36.0",
43
43
  "cross-env": "^7.0.3",