@straylightagency/utils 1.0.5 → 1.0.7

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": "@straylightagency/utils",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Some JavaScript utilities functions",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -11,8 +11,7 @@
11
11
  "./dom": "./src/dom/index.js",
12
12
  "./misc": "./src/misc/index.js",
13
13
  "./object": "./src/object/index.js",
14
- "./string": "./src/string/index.js",
15
- "./*": "./src/*"
14
+ "./string": "./src/string/index.js"
16
15
  },
17
16
  "files": [
18
17
  "src"
@@ -1,9 +1,3 @@
1
- import last from "./last.js";
2
- import initial from "./initial.js";
3
- import remove from "./remove.js";
4
-
5
- export default {
6
- initial,
7
- last,
8
- remove,
9
- }
1
+ export { default as last } from "./last.js";
2
+ export { default as initial } from "./initial.js";
3
+ export { default as remove } from "./remove.js";
package/src/date/index.js CHANGED
@@ -1,5 +1 @@
1
- import getWeekNumber from "./getWeekNumber.js";
2
-
3
- export default {
4
- getWeek: getWeekNumber,
5
- }
1
+ export { default as getWeekNumber } from "./getWeekNumber.js";
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @param element {HTMLElement}
3
+ * @returns {DOMRect}
4
+ */
5
+ export default function getElementSizing(element) {
6
+ const el_style = window.getComputedStyle( element );
7
+ const el_display = el_style.display;
8
+ const el_position = el_style.position;
9
+ const el_visibility = el_style.visibility;
10
+ const el_max_height = el_style.maxHeight.replace('px', '').replace('%', '');
11
+ let width, height;
12
+
13
+ /** if it's not hidden we just return normal height */
14
+ if ( el_display !== 'none' && el_max_height !== '0' ) {
15
+ width = element.offsetWidth + parseInt( el_style.marginLeft, 10 ) + parseInt( el_style.marginRight, 10 );
16
+ height = element.offsetHeight + parseInt( el_style.marginTop, 10 ) + parseInt( el_style.marginBottom, 10 );
17
+
18
+ const rect = element.getBoundingClientRect();
19
+
20
+ return Object.assign( rect, { width, height } );
21
+ }
22
+
23
+ /** the element is hidden, so we are making the element block, so we can measure its height but still be hidden */
24
+ element.style.position = 'absolute';
25
+ element.style.visibility = 'hidden';
26
+ element.style.display = 'block';
27
+
28
+ width = element.offsetWidth + parseInt( el_style.marginLeft, 10 ) + parseInt( el_style.marginRight, 10 );
29
+ height = element.offsetHeight + parseInt( el_style.marginTop, 10 ) + parseInt( el_style.marginBottom, 10 );
30
+
31
+ const rect = element.getBoundingClientRect();
32
+
33
+ /** reverting to the original values */
34
+ element.style.display = el_display;
35
+ element.style.position = el_position === 'static' ? null : el_position;
36
+ element.style.visibility = el_visibility === 'visible' ? null : el_visibility;
37
+
38
+ return Object.assign( rect, { width, height } );
39
+ }
package/src/dom/index.js CHANGED
@@ -1,19 +1,9 @@
1
- import addEventListeners from "./addEventListeners.js";
2
- import closestElement from "./closestElement.js";
3
- import delegate from "./delegate.js";
4
- import getFieldsValues from "./getFieldsValues.js";
5
- import onEachElements from "./onEachElements.js";
6
- import unlessElementExists from "./unlessElementExists.js";
7
- import whenReady from "./whenReady.js";
8
- import whenResize from "./whenResize.js";
9
-
10
- export default {
11
- addEventListeners,
12
- closestElement,
13
- delegate,
14
- getFieldsValues,
15
- onEachElements,
16
- unlessElementExists,
17
- whenReady,
18
- whenResize,
19
- };
1
+ export { default as addEventListeners } from "./addEventListeners.js";
2
+ export { default as closestElement } from "./closestElement.js";
3
+ export { default as delegate } from "./delegate.js";
4
+ export { default as getFieldsValues } from "./getFieldsValues.js";
5
+ export { default as getElementSizing } from "./getElementSizing.js";
6
+ export { default as onEachElements } from "./onEachElements.js";
7
+ export { default as unlessElementExists } from "./unlessElementExists.js";
8
+ export { default as whenReady } from "./whenReady.js";
9
+ export { default as whenResize } from "./whenResize.js";
package/src/index.js CHANGED
@@ -1,53 +1,33 @@
1
- import capitalize from "./string/capitalize.js";
2
- import serialize from "./string/serialize.js";
3
- import filter from "./object/filter.js";
4
- import map from "./object/map.js";
5
- import only from "./object/only.js";
6
- import clipboard from "./misc/clipboard.js";
7
- import debounce from "./misc/debounce.js";
8
- import nextTick from "./misc/nextTick.js";
9
- import throttle from "./misc/throttle.js";
1
+ export { default as capitalize } from "./string/capitalize.js";
2
+ export { default as serialize } from "./string/serialize.js";
3
+ export { default as filter } from "./object/filter.js";
4
+ export { default as map } from "./object/map.js";
5
+ export { default as only } from "./object/only.js";
6
+ export { default as clipboard } from "./misc/clipboard.js";
7
+ export { default as debounce } from "./misc/debounce.js";
8
+ export { default as nextTick } from "./misc/nextTick.js";
9
+ export { default as throttle } from "./misc/throttle.js";
10
+ export { default as addEventListeners } from "./dom/addEventListeners.js";
11
+ export { default as closestElement } from "./dom/closestElement.js";
12
+ export { default as delegate } from "./dom/delegate.js";
13
+ export { default as getFieldsValues } from "./dom/getFieldsValues.js";
14
+ export { default as onEachElements } from "./dom/onEachElements.js";
15
+ export { default as unlessElementExists } from "./dom/unlessElementExists.js";
16
+ export { default as whenReady } from "./dom/whenReady.js";
17
+ export { default as whenResize } from "./dom/whenResize.js";
18
+ export { default as getWeekNumber } from "./date/getWeekNumber.js";
19
+ export { default as initial } from "./array/initial.js";
20
+ export { default as last } from "./array/last.js";
21
+ export { default as remove } from "./array/remove.js";
22
+
10
23
  import {wait, seconds, milliseconds} from "./misc/wait.js";
11
24
  import {isClass, isObject, isPlainObject} from "./misc/is.js";
12
- import addEventListeners from "./dom/addEventListeners.js";
13
- import closestElement from "./dom/closestElement.js";
14
- import delegate from "./dom/delegate.js";
15
- import getFieldsValues from "./dom/getFieldsValues.js";
16
- import onEachElements from "./dom/onEachElements.js";
17
- import unlessElementExists from "./dom/unlessElementExists.js";
18
- import whenReady from "./dom/whenReady.js";
19
- import whenResize from "./dom/whenResize.js";
20
- import getWeekNumber from "./date/getWeekNumber.js";
21
- import initial from "./array/initial.js";
22
- import last from "./array/last.js";
23
- import remove from "./array/remove.js";
24
25
 
25
- export default {
26
- initial,
27
- last,
28
- remove,
29
- getWeekNumber,
30
- addEventListeners,
31
- closestElement,
32
- delegate,
33
- getFieldsValues,
34
- onEachElements,
35
- unlessElementExists,
36
- whenReady,
37
- whenResize,
38
- clipboard,
39
- debounce,
40
- nextTick,
41
- throttle,
26
+ export {
42
27
  wait,
43
28
  seconds,
44
29
  milliseconds,
45
30
  isClass,
46
31
  isObject,
47
32
  isPlainObject,
48
- filter,
49
- map,
50
- only,
51
- capitalize,
52
- serialize,
53
33
  };
package/src/misc/index.js CHANGED
@@ -1,15 +1,12 @@
1
- import clipboard from "./clipboard.js";
2
- import debounce from "./debounce.js";
3
- import nextTick from "./nextTick.js";
4
- import throttle from "./throttle.js";
1
+ export { default as clipboard } from "./clipboard.js";
2
+ export { default as debounce } from "./debounce.js";
3
+ export { default as nextTick } from "./nextTick.js";
4
+ export { default as throttle } from "./throttle.js";
5
+
5
6
  import {wait, seconds, milliseconds} from "./wait.js";
6
7
  import {isClass, isObject, isPlainObject} from "./is.js";
7
8
 
8
- export default {
9
- clipboard,
10
- debounce,
11
- nextTick,
12
- throttle,
9
+ export {
13
10
  wait,
14
11
  seconds,
15
12
  milliseconds,
@@ -1,9 +1,3 @@
1
- import filter from "./filter.js";
2
- import map from "./map.js";
3
- import only from "./only.js";
4
-
5
- export default {
6
- filter,
7
- map,
8
- only,
9
- };
1
+ export { default as filter } from "./filter.js";
2
+ export { default as map } from "./map.js";
3
+ export { default as only } from "./only.js";
@@ -1,7 +1,2 @@
1
- import capitalize from "./capitalize.js";
2
- import serialize from "./serialize.js";
3
-
4
- export default {
5
- capitalize,
6
- serialize,
7
- };
1
+ export { default as capitalize } from "./capitalize.js";
2
+ export { default as serialize } from "./serialize.js";